Merge remote-tracking branch 'origin/test' into test

This commit is contained in:
张松 2024-12-11 10:28:26 +08:00
commit 72ee726ccb
1 changed files with 38 additions and 20 deletions

View File

@ -1,5 +1,7 @@
package com.chaozhanggui.system.cashierservice.service;
import cn.hutool.core.date.DateUnit;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSONObject;
@ -11,7 +13,10 @@ import com.chaozhanggui.system.cashierservice.mybatis.TbVersionMapper;
import com.chaozhanggui.system.cashierservice.rabbit.RabbitProducer;
import com.chaozhanggui.system.cashierservice.sign.CodeEnum;
import com.chaozhanggui.system.cashierservice.sign.Result;
import com.chaozhanggui.system.cashierservice.util.*;
import com.chaozhanggui.system.cashierservice.util.MD5Util;
import com.chaozhanggui.system.cashierservice.util.RedisCst;
import com.chaozhanggui.system.cashierservice.util.RedisUtil;
import com.chaozhanggui.system.cashierservice.util.TokenUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@ -62,7 +67,6 @@ public class LoginService {
}
if (ObjectUtil.isEmpty(loginReq.getSerialNumber())) {
return Result.fail(CodeEnum.SERIALNUMBER);
}
@ -92,7 +96,7 @@ public class LoginService {
return Result.fail(CodeEnum.MERCHANTEIXST);
}
TbPlussShopStaff tbPlussShopStaff = tbPlussShopStaffMapper.selectByAccountAndShopId(loginReq.getLoginName(),account.getShopId());
TbPlussShopStaff tbPlussShopStaff = tbPlussShopStaffMapper.selectByAccountAndShopId(loginReq.getLoginName(), account.getShopId());
if (ObjectUtil.isEmpty(tbPlussShopStaff)) {
return Result.fail(CodeEnum.ACCOUNTEIXST);
} else if (!tbPlussShopStaff.getStatus()) {
@ -120,7 +124,14 @@ public class LoginService {
tbTokenMapper.insert(tbToken);
TbShopInfo shopInfo = tbShopInfoMapper.selectByPrimaryKey(Integer.valueOf(account.getShopId()));
if (shopInfo.getExpireAt() != null) {
Long expireAt = shopInfo.getExpireAt();
Date time = DateUtil.calendar(expireAt).getTime();
long expireDays = DateUtil.between(DateUtil.beginOfDay(new Date()), DateUtil.beginOfDay(time), DateUnit.DAY, false);
if (expireDays < 0) {
return Result.fail("店铺已到期,请联系区域经理续费");
}
}
redisUtil.saveMessage(key, token, 365 * 24 * 60 * 60);
String uuid = UUID.randomUUID().toString().replaceAll("-", "");
@ -129,15 +140,21 @@ public class LoginService {
accountMap.put("accountId", account.getId());
accountMap.put("merchantName", account.getAccount());
accountMap.put("loginName", tbPlussShopStaff.getAccount());
accountMap.put("loginAccount",tbPlussShopStaff.getName());
accountMap.put("loginAccount", tbPlussShopStaff.getName());
accountMap.put("clientType", loginReq.getClientType());
accountMap.put("shopId", account.getShopId());
accountMap.put("staffId", tbPlussShopStaff.getId());
accountMap.put("userCode", tbPlussShopStaff.getCode());
accountMap.put("token", token);
accountMap.put("loginTime", System.currentTimeMillis());
accountMap.put("expireDate", "");
if (Objects.nonNull(shopInfo)) {
accountMap.put("shopName", shopInfo.getShopName());
if(shopInfo.getExpireAt() != null) {
Long expireAt = shopInfo.getExpireAt();
Date time = DateUtil.calendar(expireAt).getTime();
accountMap.put("expireDate", DateUtil.formatDate(time));
}
}
accountMap.put("uuid", uuid);
accountMap.put("isStaff", "staff".equals(tbPlussShopStaff.getType()));
@ -153,8 +170,8 @@ public class LoginService {
public TbVersion getCurrentPcVersion() {
LambdaQueryWrapper<TbVersion> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(TbVersion::getSource,"PC");
queryWrapper.eq(TbVersion::getSel,1);
queryWrapper.eq(TbVersion::getSource, "PC");
queryWrapper.eq(TbVersion::getSel, 1);
return versionMapper.selectOne(queryWrapper);
}
@ -162,7 +179,7 @@ public class LoginService {
String key = RedisCst.ONLINE_USER.concat(":").concat(clientType).concat(":").concat(loginName);
String cacheToken = redisUtil.getMessage(key)+"";
String cacheToken = redisUtil.getMessage(key) + "";
TbToken tbToken = tbTokenMapper.selectByToken(token);
@ -199,32 +216,33 @@ public class LoginService {
}
public Result getShopInfo(String token){
JSONObject jsonObject= TokenUtil.parseParamFromToken(token);
if(Objects.isNull(jsonObject)){
public Result getShopInfo(String token) {
JSONObject jsonObject = TokenUtil.parseParamFromToken(token);
if (Objects.isNull(jsonObject)) {
return Result.fail(CodeEnum.TOKENTERROR);
}
TbShopInfo shopInfo= tbShopInfoMapper.selectByPrimaryKey(Integer.valueOf(jsonObject.getString("shopId")));
TbShopInfo shopInfo = tbShopInfoMapper.selectByPrimaryKey(Integer.valueOf(jsonObject.getString("shopId")));
return Result.success(SUCCESS,shopInfo);
return Result.success(SUCCESS, shopInfo);
}
public Result getStaffDiscount(String token){
public Result getStaffDiscount(String token) {
JSONObject jsonObject= TokenUtil.parseParamFromToken(token);
if(Objects.isNull(jsonObject)){
JSONObject jsonObject = TokenUtil.parseParamFromToken(token);
if (Objects.isNull(jsonObject)) {
return Result.fail(CodeEnum.TOKENTERROR);
}
Integer staffId=Integer.valueOf(jsonObject.getString("staffId"));
Integer staffId = Integer.valueOf(jsonObject.getString("staffId"));
TbPlussShopStaff staff= tbPlussShopStaffMapper.selectByPrimaryKey(staffId);
if(Objects.nonNull(staff)&&Objects.nonNull(staff.getMaxDiscountAmount())){
return Result.success(SUCCESS,staff.getMaxDiscountAmount());
TbPlussShopStaff staff = tbPlussShopStaffMapper.selectByPrimaryKey(staffId);
if (Objects.nonNull(staff) && Objects.nonNull(staff.getMaxDiscountAmount())) {
return Result.success(SUCCESS, staff.getMaxDiscountAmount());
}
return Result.success(SUCCESS, BigDecimal.ZERO);
}
}