只允许一个登录

This commit is contained in:
韩鹏辉 2024-07-12 09:38:51 +08:00 committed by 牛叉闪闪
parent a7206b4506
commit 36e8aeaaa0
2 changed files with 16 additions and 18 deletions

View File

@ -30,7 +30,7 @@ public class SignInterceptor implements HandlerInterceptor {
@Autowired @Autowired
RedisUtils redisUtil; RedisUtil redisUtil;
@Override @Override
@ -57,7 +57,7 @@ public class SignInterceptor implements HandlerInterceptor {
String key=RedisCst.ONLINE_USER.concat(":").concat(clientType).concat(":").concat(loginName); String key=RedisCst.ONLINE_USER.concat(":").concat(clientType).concat(":").concat(loginName);
String cacheToken= redisUtil.get(key)+""; String cacheToken= redisUtil.getMessage(key);
if(ObjectUtil.isEmpty(cacheToken)||!cacheToken.equals(token)){ if(ObjectUtil.isEmpty(cacheToken)||!cacheToken.equals(token)){
response.setContentType(CONTENT_TYPE); response.setContentType(CONTENT_TYPE);
response.getWriter().print(JSONUtil.toJsonStr(new Result(CodeEnum.TOENNOEXIST))); response.getWriter().print(JSONUtil.toJsonStr(new Result(CodeEnum.TOENNOEXIST)));

View File

@ -12,10 +12,7 @@ import com.chaozhanggui.system.cashierservice.model.LoginReq;
import com.chaozhanggui.system.cashierservice.rabbit.RabbitProducer; import com.chaozhanggui.system.cashierservice.rabbit.RabbitProducer;
import com.chaozhanggui.system.cashierservice.sign.CodeEnum; import com.chaozhanggui.system.cashierservice.sign.CodeEnum;
import com.chaozhanggui.system.cashierservice.sign.Result; import com.chaozhanggui.system.cashierservice.sign.Result;
import com.chaozhanggui.system.cashierservice.util.MD5Util; import com.chaozhanggui.system.cashierservice.util.*;
import com.chaozhanggui.system.cashierservice.util.RedisCst;
import com.chaozhanggui.system.cashierservice.util.RedisUtils;
import com.chaozhanggui.system.cashierservice.util.TokenUtil;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -46,7 +43,7 @@ public class LoginService {
TbPlussShopStaffMapper tbPlussShopStaffMapper; TbPlussShopStaffMapper tbPlussShopStaffMapper;
@Autowired @Autowired
RedisUtils redisUtil; RedisUtil redisUtil;
@Autowired @Autowired
TbTokenMapper tbTokenMapper; TbTokenMapper tbTokenMapper;
@ -77,11 +74,12 @@ public class LoginService {
} }
String key = RedisCst.ONLINE_USER.concat(":").concat(loginReq.getClientType()).concat(":").concat(loginReq.getLoginName()); String key = RedisCst.ONLINE_USER.concat(":").concat(loginReq.getClientType()).concat(":").concat(loginReq.getLoginName());
//
String data = ""+redisUtil.get(key); // String data = redisUtil.getMessage(key);
if(ObjectUtil.isNotEmpty(data)){ // log.info("key:{},data:{}",key,data);
return Result.fail(CodeEnum.USERHAVEDLOGIN); // if(ObjectUtil.isNotEmpty(data)){
} // return Result.fail(CodeEnum.USERHAVEDLOGIN);
// }
TbmerchantAccount account = tbmerchantAccountMapper.selectByAccount(loginReq.getMerchantName()); TbmerchantAccount account = tbmerchantAccountMapper.selectByAccount(loginReq.getMerchantName());
if (ObjectUtil.isEmpty(account)) { if (ObjectUtil.isEmpty(account)) {
@ -115,7 +113,7 @@ public class LoginService {
TbShopInfo shopInfo = tbShopInfoMapper.selectByPrimaryKey(Integer.valueOf(account.getShopId())); TbShopInfo shopInfo = tbShopInfoMapper.selectByPrimaryKey(Integer.valueOf(account.getShopId()));
redisUtil.set(key, token, 365 * 24 * 60 * 60); redisUtil.saveMessage(key, token, 365 * 24 * 60 * 60);
String uuid = UUID.randomUUID().toString().replaceAll("-", ""); String uuid = UUID.randomUUID().toString().replaceAll("-", "");
@ -133,7 +131,7 @@ public class LoginService {
accountMap.put("shopName", shopInfo.getShopName()); accountMap.put("shopName", shopInfo.getShopName());
} }
accountMap.put("uuid", uuid); accountMap.put("uuid", uuid);
redisUtil.set("CART:UUID:" + account.getShopId().concat(account.getId().toString()), uuid); redisUtil.saveMessage("CART:UUID:" + account.getShopId().concat(account.getId().toString()), uuid);
return Result.success(CodeEnum.SUCCESS, accountMap); return Result.success(CodeEnum.SUCCESS, accountMap);
} }
@ -143,17 +141,17 @@ public class LoginService {
String key = RedisCst.ONLINE_USER.concat(":").concat(clientType).concat(":").concat(loginName); String key = RedisCst.ONLINE_USER.concat(":").concat(clientType).concat(":").concat(loginName);
String cacheToken = redisUtil.get(key)+""; String cacheToken = redisUtil.getMessage(key)+"";
TbToken tbToken = tbTokenMapper.selectByToken(token); TbToken tbToken = tbTokenMapper.selectByToken(token);
if (ObjectUtil.isEmpty(tbToken)) { if (ObjectUtil.isEmpty(tbToken)) {
redisUtil.del(key); redisUtil.deleteByKey(key);
return Result.fail(USERNOLOGIN); return Result.fail(USERNOLOGIN);
} }
if (!"1".equals(tbToken.getStatus()) || "2".equals(tbToken.getStatus()) || "3".equals(tbToken.getStatus())) { if (!"1".equals(tbToken.getStatus()) || "2".equals(tbToken.getStatus()) || "3".equals(tbToken.getStatus())) {
redisUtil.del(key); redisUtil.deleteByKey(key);
return Result.fail(USERNOLOGIN); return Result.fail(USERNOLOGIN);
} }
@ -164,7 +162,7 @@ public class LoginService {
if (!cacheToken.equals(token)) { if (!cacheToken.equals(token)) {
return Result.fail(TOKENTERROR); return Result.fail(TOKENTERROR);
} }
redisUtil.del(key); redisUtil.deleteByKey(key);
tbToken.setStatus(status); tbToken.setStatus(status);
tbToken.setUpdateTime(new Date()); tbToken.setUpdateTime(new Date());
tbTokenMapper.updateByPrimaryKey(tbToken); tbTokenMapper.updateByPrimaryKey(tbToken);