|
@@ -31,6 +31,8 @@ import com.sckw.system.model.vo.req.*;
|
|
|
import com.sckw.system.model.vo.res.KwsUserResVo;
|
|
import com.sckw.system.model.vo.res.KwsUserResVo;
|
|
|
import com.sckw.system.model.vo.res.KwsUserSystemTypeVo;
|
|
import com.sckw.system.model.vo.res.KwsUserSystemTypeVo;
|
|
|
import com.sckw.system.model.vo.res.SalesResp;
|
|
import com.sckw.system.model.vo.res.SalesResp;
|
|
|
|
|
+import com.sckw.system.model.vo.res.SwitchAccountResVo;
|
|
|
|
|
+import com.sckw.system.model.vo.res.UserInfoResVo;
|
|
|
import com.sckw.system.repository.KwsRoleRepository;
|
|
import com.sckw.system.repository.KwsRoleRepository;
|
|
|
import com.sckw.system.repository.KwsUserRepository;
|
|
import com.sckw.system.repository.KwsUserRepository;
|
|
|
import com.sckw.system.repository.KwsUserRoleRepository;
|
|
import com.sckw.system.repository.KwsUserRoleRepository;
|
|
@@ -816,4 +818,150 @@ public class KwsUserService {
|
|
|
return kwsUserResVo;
|
|
return kwsUserResVo;
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 根据用户ID查询用户信息(头像、姓名、电话、角色、账号状态)
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param userId 用户ID
|
|
|
|
|
+ * @return UserInfoResVo
|
|
|
|
|
+ */
|
|
|
|
|
+ public UserInfoResVo getUserInfoById(Long userId) {
|
|
|
|
|
+ log.info("查询用户信息,用户ID: {}", userId);
|
|
|
|
|
+
|
|
|
|
|
+ // 1. 查询用户基本信息
|
|
|
|
|
+ KwsUser kwsUser = kwsUserRepository.getById(userId);
|
|
|
|
|
+ if (Objects.isNull(kwsUser) || kwsUser.getDelFlag() != Global.NO) {
|
|
|
|
|
+ throw new SystemException(HttpStatus.QUERY_FAIL_CODE, "用户不存在或已删除");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 2. 查询用户角色信息
|
|
|
|
|
+ List<RoleInfoDto> roleInfoList = kwsUserRoleDao.queryRoleList(userId);
|
|
|
|
|
+ String roleName = "";
|
|
|
|
|
+ if (CollUtil.isNotEmpty(roleInfoList)) {
|
|
|
|
|
+ // 获取第一个角色名称,如有多个角色可用逗号分隔
|
|
|
|
|
+ roleName = roleInfoList.stream()
|
|
|
|
|
+ .map(RoleInfoDto::getRoleName)
|
|
|
|
|
+ .collect(Collectors.joining(","));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 3. 组装返回结果
|
|
|
|
|
+ String statusDesc = kwsUser.getStatus() != null && kwsUser.getStatus() == Global.YES ? "锁定" : "正常";
|
|
|
|
|
+
|
|
|
|
|
+ return UserInfoResVo.builder()
|
|
|
|
|
+ .userId(kwsUser.getId())
|
|
|
|
|
+ .photo(kwsUser.getPhoto())
|
|
|
|
|
+ .name(kwsUser.getName())
|
|
|
|
|
+ .phone(kwsUser.getPhone())
|
|
|
|
|
+ .roleName(roleName)
|
|
|
|
|
+ .status(kwsUser.getStatus())
|
|
|
|
|
+ .statusDesc(statusDesc)
|
|
|
|
|
+ .build();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 修改密码(叉车APP)
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param userId 用户ID
|
|
|
|
|
+ * @param oldPassword 旧密码
|
|
|
|
|
+ * @param newPassword 新密码
|
|
|
|
|
+ */
|
|
|
|
|
+ public void updatePasswordForApp(Long userId, String oldPassword, String newPassword) {
|
|
|
|
|
+ log.info("修改密码,用户ID: {}", userId);
|
|
|
|
|
+
|
|
|
|
|
+ // 1. 查询用户信息
|
|
|
|
|
+ KwsUser kwsUser = checkUserBase(userId);
|
|
|
|
|
+
|
|
|
|
|
+ // 2. 校验旧密码
|
|
|
|
|
+ String account = kwsUser.getAccount();
|
|
|
|
|
+ String currentPwd = kwsUser.getPassword();
|
|
|
|
|
+ String salt = kwsUser.getSalt();
|
|
|
|
|
+ checkPassword(account, oldPassword, currentPwd, salt);
|
|
|
|
|
+
|
|
|
|
|
+ // 3. 校验新密码是否与旧密码相同
|
|
|
|
|
+ if (PasswordUtils.validatePassword(kwsUser.getAccount() + newPassword, currentPwd, kwsUser.getSalt())) {
|
|
|
|
|
+ throw new SystemException(HttpStatus.CODE_10301, "新密码不能与旧密码相同");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 4. 修改密码
|
|
|
|
|
+ updatePwd(newPassword, kwsUser);
|
|
|
|
|
+
|
|
|
|
|
+ log.info("密码修改成功,用户ID: {}", userId);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 切换账号(叉车APP)
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param account 账号
|
|
|
|
|
+ * @param password 密码
|
|
|
|
|
+ * @param systemType 系统类型
|
|
|
|
|
+ * @return SwitchAccountResVo
|
|
|
|
|
+ */
|
|
|
|
|
+ public SwitchAccountResVo switchAccount(String account, String password, Integer systemType) {
|
|
|
|
|
+ log.info("切换账号,账号: {}, 系统类型: {}", account, systemType);
|
|
|
|
|
+
|
|
|
|
|
+ // 1. 查询用户信息
|
|
|
|
|
+ KwsUser kwsUser = getUserByAccount(account, systemType);
|
|
|
|
|
+ if (Objects.isNull(kwsUser)) {
|
|
|
|
|
+ throw new SystemException(HttpStatus.QUERY_FAIL_CODE, "账号不存在");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 2. 检查用户状态
|
|
|
|
|
+ if (kwsUser.getDelFlag() != Global.NO) {
|
|
|
|
|
+ throw new SystemException(HttpStatus.QUERY_FAIL_CODE, "账号已删除");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (kwsUser.getStatus() != null && kwsUser.getStatus() == Global.YES) {
|
|
|
|
|
+ throw new SystemException(HttpStatus.CODE_10301, "账号已被锁定");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 3. 校验密码
|
|
|
|
|
+ checkPassword(account, password, kwsUser.getPassword(), kwsUser.getSalt());
|
|
|
|
|
+
|
|
|
|
|
+ // 4. 查询用户角色
|
|
|
|
|
+ List<RoleInfoDto> roleInfoList = kwsUserRoleDao.queryRoleList(kwsUser.getId());
|
|
|
|
|
+ String roleName = "";
|
|
|
|
|
+ if (CollUtil.isNotEmpty(roleInfoList)) {
|
|
|
|
|
+ roleName = roleInfoList.stream()
|
|
|
|
|
+ .map(RoleInfoDto::getRoleName)
|
|
|
|
|
+ .collect(Collectors.joining(","));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 5. 组装返回结果
|
|
|
|
|
+ log.info("切换账号成功,用户ID: {}", kwsUser.getId());
|
|
|
|
|
+ return SwitchAccountResVo.builder()
|
|
|
|
|
+ .userId(kwsUser.getId())
|
|
|
|
|
+ .name(kwsUser.getName())
|
|
|
|
|
+ .account(kwsUser.getAccount())
|
|
|
|
|
+ .phone(kwsUser.getPhone())
|
|
|
|
|
+ .photo(kwsUser.getPhoto())
|
|
|
|
|
+ .roleName(roleName)
|
|
|
|
|
+ .systemType(kwsUser.getSystemType())
|
|
|
|
|
+ .build();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 退出登录(叉车APP)
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param userId 用户ID
|
|
|
|
|
+ */
|
|
|
|
|
+ public void logout(Long userId) {
|
|
|
|
|
+ log.info("退出登录,用户ID: {}", userId);
|
|
|
|
|
+
|
|
|
|
|
+ // 1. 校验用户是否存在
|
|
|
|
|
+ KwsUser kwsUser = kwsUserRepository.getById(userId);
|
|
|
|
|
+ if (Objects.isNull(kwsUser)) {
|
|
|
|
|
+ throw new SystemException(HttpStatus.QUERY_FAIL_CODE, "用户不存在");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 2. 清除所有客户端类型的 Token
|
|
|
|
|
+ for (ClientTypeEnum value : ClientTypeEnum.values()) {
|
|
|
|
|
+ String fullUserTokenKey = Global.getFullUserTokenKey(value.getValue(), userId);
|
|
|
|
|
+ RedissonUtils.delete(fullUserTokenKey);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 3. 清除用户登录信息
|
|
|
|
|
+ String fullUserLoginKey = Global.getFullUserLoginKey(kwsUser.getSystemType(), userId);
|
|
|
|
|
+ RedissonUtils.remove(fullUserLoginKey);
|
|
|
|
|
+
|
|
|
|
|
+ log.info("退出登录成功,用户ID: {}", userId);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|