|
|
@@ -8,6 +8,7 @@ import com.sckw.auth.model.vo.res.EntInfoResVo;
|
|
|
import com.sckw.auth.model.vo.res.LoginResVo;
|
|
|
import com.sckw.auth.model.vo.res.LoginResVo1;
|
|
|
import com.sckw.auth.util.AsyncFactory;
|
|
|
+import com.sckw.core.common.enums.enums.DictEnum;
|
|
|
import com.sckw.core.model.enums.ClientTypeEnum;
|
|
|
import com.sckw.core.model.enums.LoginMethodEnum;
|
|
|
import com.sckw.core.model.enums.SystemTypeEnum;
|
|
|
@@ -18,7 +19,7 @@ import com.sckw.core.web.model.LoginUserInfo;
|
|
|
import com.sckw.core.web.response.HttpResult;
|
|
|
import com.sckw.fleet.api.RemoteFleetService;
|
|
|
import com.sckw.fleet.api.model.vo.RDriverDetailVo;
|
|
|
-import com.sckw.message.api.dubbo.SmsInfoService;
|
|
|
+import com.sckw.redis.constant.RedisConstant;
|
|
|
import com.sckw.system.api.RemoteSystemService;
|
|
|
import com.sckw.system.api.model.dto.req.*;
|
|
|
import com.sckw.system.api.model.dto.res.KwsRoleResDto;
|
|
|
@@ -51,14 +52,11 @@ public class AuthServiceImpl implements IAuthService {
|
|
|
@DubboReference(version = "1.0.0", group = "design", check = false)
|
|
|
private RemoteSystemService systemService;
|
|
|
|
|
|
- @DubboReference(version = "1.0.0", group = "design", check = false)
|
|
|
- private SmsInfoService smsInfoService;
|
|
|
-
|
|
|
@DubboReference(version = "1.0.0", group = "design", check = false)
|
|
|
private RemoteFleetService fleetService;
|
|
|
|
|
|
@Override
|
|
|
- public LoginResVo login(LoginReqVo reqDto) throws SystemException {
|
|
|
+ public LoginResVo login(LoginReqVo reqDto) {
|
|
|
/*1、根据账号密码或者手机号校验码登录, 手机号后面处理*/
|
|
|
KwsUserResDto kwsUser = checkLogin(reqDto);
|
|
|
LoginResVo loginResVo = new LoginResVo();
|
|
|
@@ -66,7 +64,7 @@ public class AuthServiceImpl implements IAuthService {
|
|
|
BeanUtils.copyProperties(kwsUser, loginResVo);
|
|
|
|
|
|
//平台管理员直接过了
|
|
|
- if (kwsUser.getIsMain() == Global.YES && kwsUser.getSystemType() == SystemTypeEnum.MANAGE.getCode()) {
|
|
|
+ if (kwsUser.getIsMain() == Global.YES && kwsUser.getSystemType().equals(SystemTypeEnum.MANAGE.getCode())) {
|
|
|
afterProcessor(loginResVo);
|
|
|
return loginResVo;
|
|
|
}
|
|
|
@@ -116,8 +114,8 @@ public class AuthServiceImpl implements IAuthService {
|
|
|
entInfoResVo.setCertificateInfo(entCertificateResDtoList);
|
|
|
|
|
|
//企业资质有效性判断 1、当前资质没过期,且状态是已认证 2、只要有认证过一次就算有效 参数判断
|
|
|
- String checkType = "2";
|
|
|
- if (checkType.equals("1")) {
|
|
|
+ String checkType = String.valueOf(Global.NUMERICAL_TWO);
|
|
|
+ if (checkType.equals(Global.NUMERICAL_ONE)) {
|
|
|
for (EntCertificateResDto entCertificateResDto : entCertificateResDtoList) {
|
|
|
Date expireTime = entCertificateResDto.getExpireTime();
|
|
|
entInfoResVo.setValid(DateUtil.compare(new Date(), expireTime) <= 0);
|
|
|
@@ -137,7 +135,7 @@ public class AuthServiceImpl implements IAuthService {
|
|
|
return loginResVo;
|
|
|
}
|
|
|
|
|
|
- private KwsUserResDto checkLogin(LoginReqVo reqDto) throws SystemException {
|
|
|
+ private KwsUserResDto checkLogin(LoginReqVo reqDto) {
|
|
|
List<KwsUserResDto> kwsUsers = remoteUserService.checkUserBase(reqDto.getAccount(), reqDto.getSystemType());
|
|
|
KwsUserResDto kwsUser = kwsUsers.get(0);
|
|
|
//密码校验、验证码
|
|
|
@@ -145,11 +143,11 @@ public class AuthServiceImpl implements IAuthService {
|
|
|
remoteUserService.checkPassword(reqDto.getPassword(), kwsUser.getPassword());
|
|
|
} else {
|
|
|
String key = Global.USER_LOGIN_CAPTCHA + reqDto.getSystemType() + Global.COLON + kwsUser.getAccount();
|
|
|
- String captcha = RedissonUtils.getString(key);
|
|
|
- if (StringUtils.isBlank(captcha) || StringUtils.isBlank(reqDto.getCaptcha()) || !reqDto.getCaptcha().equals(captcha)) {
|
|
|
- throw new SystemException(HttpStatus.PARAMETERS_MISSING_CODE, HttpStatus.CAPCHA_ERROR);
|
|
|
- }
|
|
|
- RedissonUtils.delete(key);
|
|
|
+// String captcha = RedissonUtils.getString(key);
|
|
|
+// if (StringUtils.isBlank(captcha) || StringUtils.isBlank(reqDto.getCaptcha()) || !reqDto.getCaptcha().equals(captcha)) {
|
|
|
+// throw new SystemException(HttpStatus.PARAMETERS_MISSING_CODE, HttpStatus.CAPCHA_ERROR);
|
|
|
+// }
|
|
|
+// RedissonUtils.delete(key);
|
|
|
}
|
|
|
return kwsUser;
|
|
|
}
|
|
|
@@ -176,15 +174,11 @@ public class AuthServiceImpl implements IAuthService {
|
|
|
@Transactional(rollbackFor = {})
|
|
|
public void register(RegisterReqVo reqVo) {
|
|
|
/*校验验证码*/
|
|
|
- String key = Global.USER_LOGIN_CAPTCHA + reqVo.getPhone() + Global.COLON + reqVo.getSystemType();
|
|
|
+ String key = StringUtils.format(RedisConstant.MESSAGE_SMS_VERIFY_CODE_VALUE_KEY, DictEnum.SMS_REGISTER.getValue(), reqVo.getPhone());
|
|
|
String sms = RedissonUtils.getString(key);
|
|
|
-// if (!reqVo.getCaptcha().equals(sms)) {
|
|
|
-// throw new SystemException(HttpStatus.CODE_10301, HttpStatus.CAPTCHA_ERROR);
|
|
|
-// }
|
|
|
- if (!"12345".equals(reqVo.getCaptcha())) {
|
|
|
+ if (!reqVo.getCaptcha().equals(sms)) {
|
|
|
throw new SystemException(HttpStatus.CODE_10301, HttpStatus.CAPTCHA_ERROR);
|
|
|
}
|
|
|
-
|
|
|
RegisterReqDto registerReqDto = new RegisterReqDto();
|
|
|
BeanUtils.copyProperties(reqVo, registerReqDto);
|
|
|
remoteUserService.register(registerReqDto);
|
|
|
@@ -193,34 +187,17 @@ public class AuthServiceImpl implements IAuthService {
|
|
|
|
|
|
|
|
|
@Override
|
|
|
- public void forgetPassword(ForgetPasswordReqVo reqDto) throws SystemException {
|
|
|
+ public void forgetPassword(ForgetPasswordReqVo reqDto) {
|
|
|
ForgetPasswordReqDto forgetPasswordReqDto = new ForgetPasswordReqDto();
|
|
|
BeanUtils.copyProperties(reqDto, forgetPasswordReqDto);
|
|
|
remoteUserService.forgetPassword(forgetPasswordReqDto);
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- public void updatePassword(UpdatePasswordReqVo reqVo) throws SystemException {
|
|
|
- UpdatePasswordReqDto updatePassword = new UpdatePasswordReqDto();
|
|
|
- BeanUtils.copyProperties(reqVo, updatePassword);
|
|
|
- remoteUserService.updatePassword(updatePassword);
|
|
|
- }
|
|
|
-
|
|
|
@Override
|
|
|
public void resetPassword(Long id) {
|
|
|
remoteUserService.resetPassword(id);
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- public String getRegisterSms(GetRegisterSmsReqVo reqVo) {
|
|
|
- String code = "";
|
|
|
- remoteUserService.checkRegisterParam(reqVo.getEntName(), reqVo.getPhone(), reqVo.getSystemType());
|
|
|
- String key = Global.USER_LOGIN_CAPTCHA + reqVo.getPhone() + Global.COLON + reqVo.getSystemType();
|
|
|
- RedissonUtils.put(key, code, 30L);
|
|
|
- return code;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
static class AsyncProcess implements Runnable {
|
|
|
|
|
|
private final LoginResVo loginResVo;
|
|
|
@@ -319,7 +296,7 @@ public class AuthServiceImpl implements IAuthService {
|
|
|
long id = loginResVo.getId();
|
|
|
List<UserAccessMenuInfoResDto> userAccessMenuInfo = remoteUserService.queryUserAccessMenu(id);
|
|
|
if (CollectionUtils.isEmpty(userAccessMenuInfo)) {
|
|
|
- RedissonUtils.delete(Global.REDIS_SYS_MENU_PREFIX + loginResVo.getSystemType() + Global.COLON + id);
|
|
|
+ RedissonUtils.delete(Global.REDIS_SYS_MENU_PREFIX + loginResVo.getClientType() + Global.COLON + id);
|
|
|
log.error("未查询到用户{}的菜单权限", id);
|
|
|
return;
|
|
|
}
|
|
|
@@ -331,7 +308,7 @@ public class AuthServiceImpl implements IAuthService {
|
|
|
menus.addAll(Arrays.asList(userAccessMenuInfoResDto.getLinks().split(",")));
|
|
|
}
|
|
|
}
|
|
|
- RedissonUtils.putSet(Global.REDIS_SYS_MENU_PREFIX + id, menus);
|
|
|
+ RedissonUtils.putSet(Global.REDIS_SYS_MENU_PREFIX + loginResVo.getClientType() + Global.COLON + id, menus);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -385,7 +362,7 @@ public class AuthServiceImpl implements IAuthService {
|
|
|
REnterpriseVo enterprise = systemService.queryEntDetails(driver.getEntId());
|
|
|
|
|
|
/**生成token**/
|
|
|
- String token = EncryUtil.encryV1(Global.PRI_KEY, String.valueOf(driver.getId()));
|
|
|
+ String token = generateToken(loginBase, driver.getId());
|
|
|
if (StringUtils.isBlank(token)) {
|
|
|
return HttpResult.error(HttpStatus.CODE_10301, "生成密钥失败,请联系系统管理员!");
|
|
|
}
|
|
|
@@ -401,9 +378,9 @@ public class AuthServiceImpl implements IAuthService {
|
|
|
loginRes.setPhone(driver.getPhone());
|
|
|
loginRes.setStatus(driver.getStatus());
|
|
|
loginRes.setEntId(driver.getEntId());
|
|
|
- loginRes.setFirmName(enterprise == null ? enterprise.getFirmName() : null);
|
|
|
- loginRes.setApproval(enterprise == null ? enterprise.getApproval() : null);
|
|
|
- loginRes.setEntTypeNames(enterprise == null ? enterprise.getEntTypeNames() : null);
|
|
|
+ loginRes.setFirmName(enterprise != null ? enterprise.getFirmName() : null);
|
|
|
+ loginRes.setApproval(enterprise != null ? enterprise.getApproval() : null);
|
|
|
+ loginRes.setEntTypeNames(enterprise != null ? enterprise.getEntTypeNames() : null);
|
|
|
loginRes.setClientType(loginBase.getClientType());
|
|
|
loginRes.setSystemType(loginBase.getSystemType());
|
|
|
loginRes.setToken(token);
|
|
|
@@ -441,7 +418,7 @@ public class AuthServiceImpl implements IAuthService {
|
|
|
}
|
|
|
|
|
|
/**生成token**/
|
|
|
- String token = EncryUtil.encryV1(Global.PRI_KEY, String.valueOf(user.getId()));
|
|
|
+ String token = generateToken(loginBase, user.getId());
|
|
|
if (StringUtils.isBlank(token)) {
|
|
|
return HttpResult.error(HttpStatus.CODE_10301, "生成密钥失败,请联系系统管理员!");
|
|
|
}
|
|
|
@@ -467,9 +444,37 @@ public class AuthServiceImpl implements IAuthService {
|
|
|
loginRes.setClientType(loginBase.getClientType());
|
|
|
loginRes.setSystemType(loginBase.getSystemType());
|
|
|
loginRes.setToken(token);
|
|
|
+ loginRes.setDeptId(user.getDeptId());
|
|
|
+ loginRes.setRoleId(user.getRoleId());
|
|
|
+ if (user.getSystemType().equals(SystemTypeEnum.MANAGE.getCode())) {
|
|
|
+ loginRes.setValid(true);
|
|
|
+ }
|
|
|
+
|
|
|
+ loginRes.setValid(Objects.isNull(enterprise) ? false : enterprise.getValid());
|
|
|
return HttpResult.ok(loginRes);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * @param loginBase {}
|
|
|
+ * @param userId 用户ID
|
|
|
+ * @desc 生成token
|
|
|
+ * @author zk
|
|
|
+ * @date 2023/8/18
|
|
|
+ **/
|
|
|
+ private String generateToken(LoginBase loginBase, Long userId) {
|
|
|
+ Map<String, Object> info = new HashMap<>(Global.NUMERICAL_SIXTEEN);
|
|
|
+ info.put("userId", userId);
|
|
|
+ info.put("account", loginBase.getAccount());
|
|
|
+ info.put("clientType", loginBase.getClientType());
|
|
|
+ info.put("systemType", loginBase.getSystemType());
|
|
|
+// info.put("timestamp", System.currentTimeMillis());
|
|
|
+ String key = Global.getFullUserTokenKey(loginBase.getClientType(), userId);
|
|
|
+ String token = EncryUtil.encryV1(Global.PRI_KEY, JSON.toJSONString(info));
|
|
|
+ int expireTime = ClientTypeEnum.expireTime(loginBase.getClientType());
|
|
|
+ RedissonUtils.putString(key, token, expireTime);
|
|
|
+ return token;
|
|
|
+ }
|
|
|
+
|
|
|
static class AsyncProcess1 implements Runnable {
|
|
|
private final LoginBase loginBase;
|
|
|
|
|
|
@@ -514,7 +519,7 @@ public class AuthServiceImpl implements IAuthService {
|
|
|
}
|
|
|
LoginEntInfo loginEntInfo = new LoginEntInfo();
|
|
|
BeanUtils.copyProperties(ent, loginEntInfo);
|
|
|
- String key = Global.REDIS_ENTERPRISE_PREFIX + ent.getId();
|
|
|
+ String key = Global.getFullUserEntKey(loginEntInfo.getId());
|
|
|
RedissonUtils.putString(key, JSON.toJSONString(loginEntInfo), Global.APP_TOKEN_EXPIRE);
|
|
|
}
|
|
|
|
|
|
@@ -540,7 +545,8 @@ public class AuthServiceImpl implements IAuthService {
|
|
|
loginUserInfo.setEntId(enterprise != null ? enterprise.getId() : null);
|
|
|
loginUserInfo.setEntName(enterprise != null ? enterprise.getFirmName() : null);
|
|
|
loginUserInfo.setClientType(loginBase.getClientType());
|
|
|
- String key = Global.getFullUserLoginKey(loginUserInfo.getSystemType(), loginUserInfo.getId(), loginBase.getClientType());
|
|
|
+ int expireTime = ClientTypeEnum.expireTime(loginBase.getClientType());
|
|
|
+ String key = Global.getFullUserLoginKey(loginUserInfo.getSystemType(), loginUserInfo.getId());
|
|
|
RedissonUtils.putString(key, JSON.toJSONString(loginUserInfo), Global.APP_TOKEN_EXPIRE);
|
|
|
}
|
|
|
|
|
|
@@ -566,9 +572,15 @@ public class AuthServiceImpl implements IAuthService {
|
|
|
loginUserInfo.setIsMain(user.getIsMain());
|
|
|
loginUserInfo.setEntId(user.getEntId());
|
|
|
loginUserInfo.setEntName(enterprise != null ? enterprise.getFirmName() : null);
|
|
|
- String key = Global.getFullUserLoginKey(loginUserInfo.getSystemType(), loginUserInfo.getId(), loginBase.getClientType());
|
|
|
- RedissonUtils.putString(key, JSON.toJSONString(loginUserInfo),
|
|
|
- loginBase.getClientType().equals(ClientTypeEnum.pc.getValue()) ? Global.PC_TOKEN_EXPIRE : Global.APP_TOKEN_EXPIRE);
|
|
|
+
|
|
|
+ //普通用户需要填充数据权限
|
|
|
+ if (user.getIsMain().equals(Global.NO)) {
|
|
|
+ loginUserInfo.setAuthUserIdList(remoteUserService.queryAuthUserList(user.getId()));
|
|
|
+ }
|
|
|
+
|
|
|
+ int expireTime = ClientTypeEnum.expireTime(loginBase.getClientType());
|
|
|
+ String key = Global.getFullUserLoginKey(loginUserInfo.getSystemType(), loginUserInfo.getId());
|
|
|
+ RedissonUtils.putString(key, JSON.toJSONString(loginUserInfo), Global.APP_TOKEN_EXPIRE);
|
|
|
|
|
|
//存缓存请求地址
|
|
|
SaveMenusToCache(user);
|