cuilei
2025-06-11 cd00884c3db8fa6808b3b5949ab1a2b1459d6bdc
lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/system/service/impl/SysUserServiceImpl.java
@@ -3,6 +3,7 @@
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
@@ -439,7 +440,7 @@
    * @return
    */
   @Override
   public Result<?> checkUserIsEffective(SysUser sysUser) {
   public Result<?> checkUserIsEffective(SysUser sysUser, String loginType) {
      Result<?> result = new Result<Object>();
      //情况1:根据用户信息查询,该用户不存在
      if (sysUser == null) {
@@ -463,7 +464,7 @@
      }
      //情况4:根据用户信息查询,该用户密码系首次使用,需修改密码
      List<DictModel> dictList = sysDictService.queryEnableDictItemsByCode(CommonConstant.DICT_USER_FIRST_LOGIN);
      if (dictList != null && !dictList.isEmpty()) {
      if (!"terminal".equals(loginType) && 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);
@@ -746,16 +747,14 @@
   }
   @Override
   public List<UserSelector> selectOperatorList(String equipmentId, String productionId, String positionCode) {
   public List<UserSelector> selectOperatorList(String equipmentCode, String productionId, String positionCode) {
      LambdaQueryWrapper<SysUser> queryWrapper = new LambdaQueryWrapper<>();
      queryWrapper.eq(SysUser::getPost, positionCode);
      if(StringUtils.isNotBlank(equipmentId)) {
         queryWrapper.isNull(SysUser::getEquipmentIds);
         queryWrapper.or().eq(SysUser::getEquipmentIds, "");
         queryWrapper.or().like(SysUser::getEquipmentIds, equipmentId);
      if(StringUtils.isNotBlank(equipmentCode)) {
         queryWrapper.and(q -> q.isNull(SysUser::getEquipmentIds).or().eq(SysUser::getEquipmentIds, "").or().like(SysUser::getEquipmentIds, equipmentCode));
      }
      if(StringUtils.isNotBlank(productionId)) {
         queryWrapper.exists("select 1 from mdc_user_production t where t.user_id=id and t.pro_id={0}", productionId);
         queryWrapper.exists("select 1 from mdc_user_production t where t.user_id=sys_user.id and t.pro_id={0}", productionId);
      }
      queryWrapper.eq(SysUser::getDelFlag, CommonConstant.DEL_FLAG_0);
      queryWrapper.eq(SysUser::getStatus, CommonConstant.DEL_FLAG_1);
@@ -764,4 +763,47 @@
      List<UserSelector> collect = sysUsers.stream().map(user -> new UserSelector(user.getId(), user.getUsername(), user.getRealname())).collect(Collectors.toList());
      return collect;
   }
   @Override
   public List<UserSelector> selectOperatorList(String positionCode) {
      LambdaQueryWrapper<SysUser> queryWrapper = new LambdaQueryWrapper<>();
      queryWrapper.eq(SysUser::getPost, positionCode);
      queryWrapper.eq(SysUser::getDelFlag, CommonConstant.DEL_FLAG_0);
      queryWrapper.eq(SysUser::getStatus, CommonConstant.DEL_FLAG_1);
      queryWrapper.orderByDesc(SysUser::getId);
      List<SysUser> sysUsers = userMapper.selectList(queryWrapper);
      List<UserSelector> collect = sysUsers.stream().map(user -> new UserSelector(user.getId(), user.getUsername(), user.getRealname())).collect(Collectors.toList());
      return collect;
   }
   /**
    * 根据用户名批量获取真实姓名映射
    * @param userNames 用户名列表
    * @return 用户名->真实姓名的映射(不存在时值为null)
    */
   @Override
   public Map<String, String> getUserRealNamesByUserNames(List<String> userNames) {
      if (CollectionUtils.isEmpty(userNames)) {
         return Collections.emptyMap();
      }
      // 去重并过滤空值
      Set<String> uniqueNames = userNames.stream()
            .filter(StringUtils::isNotBlank)
            .collect(Collectors.toSet());
      if (uniqueNames.isEmpty()) {
         return Collections.emptyMap();
      }
      // 批量查询(自动处理IN语句分片)
      List<SysUser> users = userMapper.selectUsersByNames(new ArrayList<>(uniqueNames));
      // 构建映射关系
      return users.stream()
            .collect(Collectors.toMap(
                  SysUser::getUsername,
                  SysUser::getRealname,
                  (existing, replacement) -> existing // 重复键处理
            ));
   }
}