| | |
| | | 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; |
| | |
| | | } |
| | | |
| | | @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); |
| | |
| | | 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 // 重复键处理 |
| | | )); |
| | | } |
| | | } |