lyh
2025-06-30 0843d9fa608a6d319d9d1c37860a0f16ce263a19
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;
@@ -45,7 +48,7 @@
@Service
@Slf4j
public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> implements ISysUserService {
   @Autowired
   private SysUserMapper userMapper;
   @Autowired
@@ -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);
@@ -128,8 +141,8 @@
   public SysUser getUserByName(String username) {
      return userMapper.getUserByName(username);
   }
   @Override
   @Transactional(rollbackFor = Exception.class)
   public void addUserWithRole(SysUser user, String roles) {
@@ -190,7 +203,7 @@
            roleIndex = list.get(0);
         }
      }
      //如果componentUrl为空,则返回空
      if(oConvertUtils.isEmpty(roleIndex.getComponent())){
         return null;
@@ -256,7 +269,7 @@
         info.setSysUserName(sysUser.getRealname());
         info.setSysOrgCode(sysUser.getOrgCode());
      }
      //多部门支持in查询
      List<SysDepart> list = sysDepartMapper.queryUserDeparts(sysUser.getId());
      List<String> sysMultiOrgCode = new ArrayList<String>();
@@ -272,7 +285,7 @@
         }
      }
      info.setSysMultiOrgCode(sysMultiOrgCode);
      return info;
   }
@@ -342,6 +355,16 @@
   @Override
   public IPage<SysUser> getUserByRoleId(Page<SysUser> page, String roleId, String username) {
      return userMapper.getUserByRoleId(page,roleId,username);
   }
   /**
    * 根据设备车间管理Id查询
    * @param page
    * @param workShopDepartId 设备车间管理Id
    * @return
    */
   public IPage<SysUser> getUserByworkShopDepartId(Page<SysUser> page,String workShopDepartId){
      return userMapper.getUserByWorkShopDepartId(page,workShopDepartId);
   }
@@ -441,6 +464,32 @@
         baseCommonService.addLog("用户登录失败,用户名:" + sysUser.getUsername() + "已冻结!", CommonConstant.LOG_TYPE_1, null);
         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 +707,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);
   }
}