| | |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ruoyi.basic.entity.StorageAttachment; |
| | | import com.ruoyi.basic.entity.StorageBlob; |
| | | import com.ruoyi.basic.entity.Supply; |
| | | import com.ruoyi.basic.entity.dto.StorageBlobDTO; |
| | | import com.ruoyi.basic.mapper.StorageAttachmentMapper; |
| | | import com.ruoyi.basic.mapper.StorageBlobMapper; |
| | |
| | | import com.ruoyi.business.entity.InspectionTask; |
| | | import com.ruoyi.business.mapper.InspectionTaskMapper; |
| | | import com.ruoyi.business.service.InspectionTaskService; |
| | | import com.ruoyi.common.core.domain.entity.SysUser; |
| | | import com.ruoyi.common.utils.SecurityUtils; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.common.utils.bean.BeanUtils; |
| | | import com.ruoyi.common.utils.file.MinioUtils; |
| | | import com.ruoyi.system.mapper.SysUserMapper; |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | |
| | | |
| | | private final MinioUtils minioUtils; |
| | | |
| | | private final SysUserMapper sysUserMapper; |
| | | |
| | | @Override |
| | | public IPage<InspectionTaskDto> selectInspectionTaskList(Page page, InspectionTaskDto inspectionTaskDto) { |
| | | public IPage<InspectionTaskDto> selectInspectionTaskList(Page<InspectionTask> page, InspectionTaskDto inspectionTaskDto) { |
| | | LambdaQueryWrapper<InspectionTask> queryWrapper = new LambdaQueryWrapper<>(); |
| | | queryWrapper.orderByDesc(InspectionTask::getCreateTime); |
| | | IPage<InspectionTask> entityPage = inspectionTaskMapper.selectPage(page, queryWrapper); |
| | |
| | | return new Page<>(entityPage.getCurrent(), entityPage.getSize(), entityPage.getTotal()); |
| | | } |
| | | // 获取id集合 |
| | | List<Long> ids = entityPage.getRecords().stream().map(InspectionTask::getId).collect(Collectors.toList()); |
| | | List<Long> ids = entityPage.getRecords().stream().map(InspectionTask::getId).toList(); |
| | | //登记人ids |
| | | List<Long> registrantIds = entityPage.getRecords().stream().map(InspectionTask::getRegistrantId).toList(); |
| | | // 批量查询登记人 |
| | | Map<Long, SysUser> sysUserMap; |
| | | if (!registrantIds.isEmpty()) { |
| | | List<SysUser> sysUsers = sysUserMapper.selectList(registrantIds); |
| | | sysUserMap = sysUsers.stream().collect(Collectors.toMap(SysUser::getUserId, Function.identity())); |
| | | } else { |
| | | sysUserMap = new HashMap<>(); |
| | | } |
| | | //巡检人ids |
| | | List<String> inspectorIds = entityPage.getRecords().stream().map(InspectionTask::getInspectorId).toList(); |
| | | |
| | | //获取所有不重复的用户ID |
| | | Set<Long> allUserIds = entityPage.getRecords().stream() |
| | | .map(InspectionTask::getInspectorId) // 获取"2,3"这样的字符串 |
| | | .filter(StringUtils::isNotBlank) |
| | | .flatMap(idsStr -> Arrays.stream(idsStr.split(","))) |
| | | .map(idStr -> { |
| | | try { |
| | | return Long.parseLong(idStr.trim()); |
| | | } catch (NumberFormatException e) { |
| | | return null; |
| | | } |
| | | }) |
| | | .filter(Objects::nonNull) |
| | | .collect(Collectors.toSet()); |
| | | |
| | | // 使用SQL批量查询用户信息 |
| | | Map<Long, String> userIdToNameMap = allUserIds.isEmpty() |
| | | ? Collections.emptyMap() |
| | | : sysUserMapper.selectUsersByIds(new ArrayList<>(allUserIds)) |
| | | .stream() |
| | | .collect(Collectors.toMap( |
| | | SysUser::getUserId, |
| | | SysUser::getNickName, |
| | | (existing, replacement) -> existing)); |
| | | |
| | | //处理附件 |
| | | Map<Long, List<StorageAttachment>> attachmentsMap = storageAttachmentMapper.selectList(new LambdaQueryWrapper<StorageAttachment>().in(StorageAttachment::getRecordId, ids) |
| | | .eq(StorageAttachment::getRecordType, InspectionTasks.ordinal())) |
| | | .stream() |
| | |
| | | List<InspectionTaskDto> dtoList = entityPage.getRecords().stream().map(inspectionTask -> { |
| | | InspectionTaskDto dto = new InspectionTaskDto(); |
| | | BeanUtils.copyProperties(inspectionTask, dto); // 复制主对象属性 |
| | | |
| | | // 设置登记人 |
| | | SysUser sysUser = sysUserMap.get(inspectionTask.getRegistrantId()); |
| | | if (sysUser != null) { |
| | | dto.setRegistrant(sysUser.getNickName()); |
| | | } |
| | | // 处理巡检人名称 |
| | | if (StringUtils.isNotBlank(inspectionTask.getInspectorId())) { |
| | | String inspectorNames = Arrays.stream(inspectionTask.getInspectorId().split(",")) |
| | | .map(String::trim) |
| | | .map(idStr -> { |
| | | try { |
| | | Long userId = Long.parseLong(idStr); |
| | | return userIdToNameMap.getOrDefault(userId, "未知用户(" + idStr + ")"); |
| | | } catch (NumberFormatException e) { |
| | | return "无效ID(" + idStr + ")"; |
| | | } |
| | | }) |
| | | .collect(Collectors.joining(",")); |
| | | dto.setInspector(inspectorNames); |
| | | } |
| | | |
| | | // 初始化三个附件列表 |
| | | dto.setBeforeProduction(new ArrayList<>()); |
| | |
| | | |
| | | @Override |
| | | public int addOrEditInspectionTask(InspectionTaskDto inspectionTaskDto) { |
| | | SecurityUtils.getLoginUser().getUserId(); |
| | | InspectionTask inspectionTask = new InspectionTask(); |
| | | BeanUtils.copyProperties(inspectionTaskDto, inspectionTask); |
| | | inspectionTask.setRegistrantId(SecurityUtils.getLoginUser().getUserId()); |
| | |
| | | if (ids == null || ids.length == 0) { |
| | | return 0; |
| | | } |
| | | return inspectionTaskMapper.deleteByIds(Arrays.asList(ids)); |
| | | return inspectionTaskMapper.deleteByIds(Arrays.asList(ids)); |
| | | } |
| | | } |