hyingbo
2025-05-27 3a740faa161ec976986c0735ba18837f570a525f
lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/system/service/impl/SysUserServiceImpl.java
@@ -11,8 +11,10 @@
import org.jeecg.common.constant.CommonConstant;
import org.jeecg.common.constant.enums.RoleIndexConfigEnum;
import org.jeecg.common.desensitization.annotation.SensitiveEncode;
import org.jeecg.common.system.vo.DictModel;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.common.system.vo.SysUserCacheInfo;
import org.jeecg.common.util.DateUtils;
import org.jeecg.common.util.PasswordUtil;
import org.jeecg.common.util.UUIDGenerator;
import org.jeecg.common.util.oConvertUtils;
@@ -20,6 +22,7 @@
import org.jeecg.modules.system.entity.*;
import org.jeecg.modules.system.mapper.*;
import org.jeecg.modules.system.model.SysUserSysDepartModel;
import org.jeecg.modules.system.service.ISysDictService;
import org.jeecg.modules.system.service.ISysUserService;
import org.jeecg.modules.system.vo.MdcUserProVo;
import org.jeecg.modules.system.vo.SysUserDepVo;
@@ -74,6 +77,8 @@
   SysRoleIndexMapper sysRoleIndexMapper;
   @Resource
   MdcUserProductionMapper mdcUserProductionMapper;
   @Resource
   private ISysDictService sysDictService;
    @Override
    @CacheEvict(value = {CacheConstant.SYS_USERS_CACHE}, allEntries = true)
@@ -89,8 +94,12 @@
        if (!newpassword.equals(confirmpassword)) {
            return Result.error("两次输入密码不一致!");
        }
      //设置密码更新时间
      //sysUser.setPasswordTime(new Date());
      //设置密码首次登录失效
      //sysUser.setPasswordFlag(CommonConstant.DEL_FLAG_0);
        String password = PasswordUtil.encrypt(username, newpassword, user.getSalt());
        this.userMapper.update(new SysUser().setPassword(password), new LambdaQueryWrapper<SysUser>().eq(SysUser::getId, user.getId()));
        this.userMapper.update(new SysUser().setPassword(password).setPasswordTime(new Date()).setPasswordFlag(CommonConstant.DEL_FLAG_0), new LambdaQueryWrapper<SysUser>().eq(SysUser::getId, user.getId()));
        return Result.ok("密码重置成功!");
    }
@@ -99,6 +108,10 @@
    public Result<?> changePassword(SysUser sysUser) {
        String salt = oConvertUtils.randomGen(8);
        sysUser.setSalt(salt);
      //设置密码更新时间
      sysUser.setPasswordTime(new Date());
      //管理员修改密码,设置用户首次登录
      //sysUser.setPasswordFlag();
        String password = sysUser.getPassword();
        String passwordEncode = PasswordUtil.encrypt(sysUser.getUsername(), password, salt);
        sysUser.setPassword(passwordEncode);
@@ -442,6 +455,32 @@
         result.error500("该用户已冻结");
         return result;
      }
      //情况4:根据用户信息查询,该用户密码系首次使用,需修改密码
      List<DictModel> dictList = sysDictService.queryEnableDictItemsByCode(CommonConstant.DICT_USER_FIRST_LOGIN);
      if (dictList != null && !dictList.isEmpty()) {
         if (CommonConstant.DEL_FLAG_1.equals(Integer.valueOf(dictList.get(0).getValue())) && CommonConstant.DEL_FLAG_1.equals(sysUser.getPasswordFlag())) {
            baseCommonService.addLog("用户登录失败,用户名:" + sysUser.getUsername() + "系首次登录系统,请重置密码!", CommonConstant.LOG_TYPE_1, null);
            result.setCode(5001);
            result.setMessage("用户密码系默认密码,需重置密码后重新登录密码!");
            result.setSuccess(false);
            return result;
         }
      }
      //情况5:根据用户信息查询,该用户密码是否已过更改周期
      Date passwordTime = sysUser.getPasswordTime();
      //Integer passwordExpirationPeriod = CommonConstant.PASSWORD_EXPIRATION_PERIOD;
      List<DictModel> dictModelList = sysDictService.queryEnableDictItemsByCode(CommonConstant.DICT_PASSWORD_EXPIRATION);
      if (dictModelList != null && !dictModelList.isEmpty()) {
         Integer passwordExpirationPeriod = Integer.valueOf(dictModelList.get(0).getValue());
         Date dayAfter = DateUtils.getDayAfter(passwordTime, passwordExpirationPeriod);
         if (new Date().after(dayAfter)) {
            baseCommonService.addLog("用户登录失败,用户名:" + sysUser.getUsername() + "密码已过有效期,请重置密码!", CommonConstant.LOG_TYPE_1, null);
            result.setCode(5002);
            result.setMessage("用户密码已过有效期,请重置密码!");
            result.setSuccess(false);
            return result;
         }
      }
      return result;
   }
@@ -658,4 +697,28 @@
   public List<SysUser> getAllUsersByRoleId(String roleId) {
      return userMapper.getAllUsersByRoleId(roleId);
   }
   /**
    * 根据角色编码查询用户id集合
    */
   @Override
   public List<String> getUserByRoleCode(String roleCode) {
      return this.baseMapper.getUserByRoleCode(roleCode);
   }
   /**
    * 根据角色编码列表查询用户id集合
    */
   @Override
   public List<SysUser> getUserByRoleCodeList(List<String> roleCodeList) {
      return this.baseMapper.getUserByRoleCodeList(roleCodeList);
   }
   /**
    * 根据角色编码和设备编号查询用户
    */
   @Override
   public List<SysUser> getEquipmentAdmin(String roleCode, String equipmentId) {
      return this.baseMapper.getEquipmentAdmin(roleCode, equipmentId);
   }
}