From 7d096488e3622d92e398e9e38197ac9e632d2687 Mon Sep 17 00:00:00 2001
From: 云 <2163098428@qq.com>
Date: 星期一, 20 四月 2026 17:05:05 +0800
Subject: [PATCH] feat(inspectiontask): 添加巡检任务状态管理功能
---
src/main/java/com/ruoyi/inspectiontask/service/impl/InspectionTaskServiceImpl.java | 157 ++++++++++++++++++++++++++++++---------------------
1 files changed, 92 insertions(+), 65 deletions(-)
diff --git a/src/main/java/com/ruoyi/inspectiontask/service/impl/InspectionTaskServiceImpl.java b/src/main/java/com/ruoyi/inspectiontask/service/impl/InspectionTaskServiceImpl.java
index a84a70d..66bc2b8 100644
--- a/src/main/java/com/ruoyi/inspectiontask/service/impl/InspectionTaskServiceImpl.java
+++ b/src/main/java/com/ruoyi/inspectiontask/service/impl/InspectionTaskServiceImpl.java
@@ -8,30 +8,39 @@
import com.ruoyi.basic.dto.StorageBlobDTO;
import com.ruoyi.basic.mapper.StorageAttachmentMapper;
import com.ruoyi.basic.mapper.StorageBlobMapper;
-import com.ruoyi.basic.pojo.StorageAttachment;
import com.ruoyi.basic.pojo.StorageBlob;
import com.ruoyi.basic.service.StorageAttachmentService;
+import com.ruoyi.common.enums.FileNameType;
import com.ruoyi.common.utils.MinioUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.bean.BeanUtils;
+import com.ruoyi.device.mapper.DeviceAreaMapper;
+import com.ruoyi.device.mapper.DeviceLedgerMapper;
+import com.ruoyi.device.pojo.DeviceArea;
+import com.ruoyi.device.pojo.DeviceLedger;
import com.ruoyi.inspectiontask.dto.InspectionTaskDto;
import com.ruoyi.inspectiontask.mapper.InspectionTaskMapper;
import com.ruoyi.inspectiontask.pojo.InspectionTask;
import com.ruoyi.inspectiontask.service.InspectionTaskService;
import com.ruoyi.project.system.domain.SysUser;
import com.ruoyi.project.system.mapper.SysUserMapper;
+import com.ruoyi.sales.mapper.CommonFileMapper;
+import com.ruoyi.sales.pojo.CommonFile;
+import com.ruoyi.sales.service.impl.CommonFileServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+import java.io.IOException;
+import java.time.LocalDate;
+import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
+import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Function;
import java.util.stream.Collectors;
-
-import static com.ruoyi.common.constant.StorageAttachmentConstants.StorageAttachmentFile;
-import static com.ruoyi.common.enums.StorageAttachmentRecordType.InspectionTasks;
/**
* @author :yys
@@ -40,6 +49,9 @@
@Service
@Slf4j
public class InspectionTaskServiceImpl extends ServiceImpl<InspectionTaskMapper, InspectionTask> implements InspectionTaskService {
+
+ private static final int INSPECTION_STATUS_PENDING = 1;
+ private static final int INSPECTION_STATUS_COMPLETED = 2;
@Autowired
@@ -60,12 +72,41 @@
@Autowired
private SysUserMapper sysUserMapper;
+ @Autowired
+ private CommonFileMapper commonFileMapper;
+
+ @Autowired
+ private CommonFileServiceImpl commonFileService;
+
+ @Autowired
+ private DeviceLedgerMapper deviceLedgerMapper;
+
+ @Autowired
+ private DeviceAreaMapper deviceAreaMapper;
+
@Override
public IPage<InspectionTaskDto> selectInspectionTaskList(Page<InspectionTask> page, InspectionTaskDto inspectionTaskDto) {
LambdaQueryWrapper<InspectionTask> queryWrapper = new LambdaQueryWrapper<>();
+ queryWrapper.orderByAsc(InspectionTask::getTimingId);
queryWrapper.orderByDesc(InspectionTask::getCreateTime);
if (StringUtils.isNotBlank(inspectionTaskDto.getTaskName())) {
queryWrapper.like(InspectionTask::getTaskName, inspectionTaskDto.getTaskName());
+ }
+ if (inspectionTaskDto.getAreaId() != null) {
+ queryWrapper.eq(InspectionTask::getAreaId, inspectionTaskDto.getAreaId());
+ }
+ LocalDateTime createTimeStart = inspectionTaskDto.getCreateTimeStart();
+ LocalDateTime createTimeEnd = inspectionTaskDto.getCreateTimeEnd();
+ if (createTimeStart == null && createTimeEnd == null) {
+ LocalDate today = LocalDate.now();
+ createTimeStart = today.atStartOfDay();
+ createTimeEnd = today.atTime(23, 59, 59);
+ }
+ if (createTimeStart != null) {
+ queryWrapper.ge(InspectionTask::getCreateTime, createTimeStart);
+ }
+ if (createTimeEnd != null) {
+ queryWrapper.le(InspectionTask::getCreateTime, createTimeEnd);
}
IPage<InspectionTask> entityPage = inspectionTaskMapper.selectPage(page, queryWrapper);
@@ -75,6 +116,10 @@
}
// 鑾峰彇id闆嗗悎
List<Long> ids = entityPage.getRecords().stream().map(InspectionTask::getId).collect(Collectors.toList());
+ Map<Long, String> areaNameMap = buildAreaNameMap(entityPage.getRecords().stream()
+ .map(InspectionTask::getAreaId)
+ .filter(Objects::nonNull)
+ .collect(Collectors.toSet()));
//鐧昏浜篿ds
List<Long> registrantIds = entityPage.getRecords().stream().map(InspectionTask::getRegistrantId).collect(Collectors.toList());
// 鎵归噺鏌ヨ鐧昏浜�
@@ -114,21 +159,13 @@
(existing, replacement) -> existing));
//澶勭悊闄勪欢
- Map<Long, List<StorageAttachment>> attachmentsMap = storageAttachmentMapper.selectList(new LambdaQueryWrapper<StorageAttachment>().in(StorageAttachment::getRecordId, ids)
- .eq(StorageAttachment::getRecordType, InspectionTasks.ordinal()))
- .stream()
- .collect(Collectors.groupingBy(StorageAttachment::getRecordId));
- // 鎵归噺鏌ヨ鎵�鏈夐渶瑕佺殑鏂囦欢鏁版嵁
- Set<Long> blobIds = attachmentsMap.values()
- .stream()
- .flatMap(List::stream)
- .map(StorageAttachment::getStorageBlobId)
- .collect(Collectors.toSet());
- Map<Long, StorageBlob> blobMap = blobIds.isEmpty()
- ? Collections.emptyMap()
- : storageBlobMapper.selectList(new LambdaQueryWrapper<StorageBlob>().in(StorageBlob::getId, blobIds))
- .stream()
- .collect(Collectors.toMap(StorageBlob::getId, Function.identity()));
+ List<CommonFile> commonFiles = commonFileMapper.selectList(new LambdaQueryWrapper<CommonFile>()
+ .in(CommonFile::getCommonId, ids)
+ .in(CommonFile::getType, Arrays.asList(FileNameType.INSPECTION.getValue(), FileNameType.INSPECTION_PRODUCTION_BEFORE.getValue(), FileNameType.INSPECTION_PRODUCTION_AFTER.getValue())));
+ if(commonFiles == null){
+ commonFiles = new ArrayList<>();
+ }
+ AtomicReference<List<CommonFile>> finalCommonFiles = new AtomicReference<>(commonFiles);
List<InspectionTaskDto> dtoList = entityPage.getRecords().stream().map(inspectionTask -> {
InspectionTaskDto dto = new InspectionTaskDto();
@@ -139,6 +176,7 @@
if (sysUser != null) {
dto.setRegistrant(sysUser.getNickName());
}
+ dto.setAreaName(areaNameMap.get(inspectionTask.getAreaId()));
// 澶勭悊宸℃浜哄悕绉�
if (StringUtils.isNotBlank(inspectionTask.getInspectorId())) {
String inspectorNames = Arrays.stream(inspectionTask.getInspectorId().split(","))
@@ -156,38 +194,12 @@
}
dto.setDateStr(inspectionTask.getCreateTime().format(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
-
+ finalCommonFiles.set(finalCommonFiles.get().stream().filter(commonFile -> commonFile.getCommonId().equals(inspectionTask.getId())).collect(Collectors.toList()));
// 鍒濆鍖栦笁涓檮浠跺垪琛�
- dto.setBeforeProduction(new ArrayList<>());
- dto.setAfterProduction(new ArrayList<>());
- dto.setProductionIssues(new ArrayList<>());
+ dto.setCommonFileList(finalCommonFiles.get().stream().filter(commonFile -> commonFile.getType().equals(FileNameType.INSPECTION.getValue())).collect(Collectors.toList()));
+ dto.setCommonFileListAfter(finalCommonFiles.get().stream().filter(commonFile -> commonFile.getType().equals(FileNameType.INSPECTION_PRODUCTION_AFTER.getValue())).collect(Collectors.toList()));
+ dto.setCommonFileListBefore(finalCommonFiles.get().stream().filter(commonFile -> commonFile.getType().equals(FileNameType.INSPECTION_PRODUCTION_BEFORE.getValue())).collect(Collectors.toList()));
- // 澶勭悊闄勪欢鍒嗙被
- Optional.ofNullable(attachmentsMap.get(inspectionTask.getId()))
- .orElse(Collections.emptyList())
- .forEach(attachment -> {
- StorageBlob blob = blobMap.get(attachment.getStorageBlobId());
- if (blob != null) {
- // 鍒涘缓闄勪欢DTO
- StorageBlobDTO blobDto = createBlobDto(blob);
-
- // 鏍规嵁type鍒嗙被
- switch ((int) blob.getType().longValue()) {
- case 0:
- dto.getBeforeProduction().add(blobDto);
- break;
- case 1:
- dto.getAfterProduction().add(blobDto);
- break;
- case 2:
- dto.getProductionIssues().add(blobDto);
- break;
- default:
- // 鍙�夛細璁板綍鏈垎绫荤被鍨�
- break;
- }
- }
- });
return dto;
}).collect(Collectors.toList());
@@ -197,6 +209,14 @@
BeanUtils.copyProperties(entityPage, resultPage);
resultPage.setRecords(dtoList);
return resultPage;
+ }
+
+ private Map<Long, String> buildAreaNameMap(Set<Long> areaIds) {
+ if (areaIds == null || areaIds.isEmpty()) {
+ return Collections.emptyMap();
+ }
+ return deviceAreaMapper.selectBatchIds(new ArrayList<>(areaIds)).stream()
+ .collect(Collectors.toMap(DeviceArea::getId, DeviceArea::getAreaName, (left, right) -> left));
}
// 鎻愬彇鍒涘缓BlobDTO鐨勫叕鍏辨柟娉�
@@ -222,41 +242,48 @@
}
@Override
- public int addOrEditInspectionTask(InspectionTaskDto inspectionTaskDto) {
+ @Transactional(rollbackFor = Exception.class)
+ public int addOrEditInspectionTask(InspectionTaskDto inspectionTaskDto) throws IOException {
InspectionTask inspectionTask = new InspectionTask();
BeanUtils.copyProperties(inspectionTaskDto, inspectionTask);
+ boolean hasUploadedFiles = CollectionUtils.isNotEmpty(inspectionTaskDto.getTempFileIds());
+ if (inspectionTask.getAreaId() == null && inspectionTask.getTaskId() != null) {
+ DeviceLedger deviceLedger = deviceLedgerMapper.selectById(Long.valueOf(inspectionTask.getTaskId()));
+ if (deviceLedger != null) {
+ inspectionTask.setAreaId(deviceLedger.getAreaId());
+ }
+ }
inspectionTask.setRegistrantId(SecurityUtils.getLoginUser().getUserId());
inspectionTask.setRegistrant(SecurityUtils.getLoginUser().getUsername());
int i;
if (Objects.isNull(inspectionTaskDto.getId())) {
+ inspectionTask.setInspectionStatus(hasUploadedFiles ? INSPECTION_STATUS_COMPLETED : INSPECTION_STATUS_PENDING);
i = inspectionTaskMapper.insert(inspectionTask);
} else {
+ if (hasUploadedFiles) {
+ inspectionTask.setInspectionStatus(INSPECTION_STATUS_COMPLETED);
+ } else if (inspectionTask.getInspectionStatus() == null) {
+ InspectionTask existingTask = inspectionTaskMapper.selectById(inspectionTaskDto.getId());
+ if (existingTask != null) {
+ inspectionTask.setInspectionStatus(existingTask.getInspectionStatus());
+ }
+ }
i = inspectionTaskMapper.updateById(inspectionTask);
}
-
- if (inspectionTaskDto.getStorageBlobDTO() != null && !inspectionTaskDto.getStorageBlobDTO().isEmpty()) {
- List<StorageAttachment> attachments = new ArrayList<>();
-
- for (StorageBlobDTO storageBlobDTO : inspectionTaskDto.getStorageBlobDTO()) {
- StorageAttachment storageAttachment = new StorageAttachment(
- StorageAttachmentFile,
- (long) InspectionTasks.ordinal(),
- inspectionTask.getId()
- );
- storageAttachment.setStorageBlobDTO(storageBlobDTO);
- attachments.add(storageAttachment);
- }
- storageAttachmentService.saveStorageAttachment(attachments, inspectionTask.getId(), InspectionTasks, StorageAttachmentFile);
- }
+ commonFileService.migrateTempFilesToFormal(inspectionTask.getId(),inspectionTaskDto.getTempFileIds());
return i;
}
@Override
+ @Transactional(rollbackFor = Exception.class)
public int delByIds(Long[] ids) {
// 妫�鏌ュ弬鏁�
if (ids == null || ids.length == 0) {
return 0;
}
+ commonFileService.deleteByBusinessIds(Arrays.asList(ids),FileNameType.INSPECTION.getValue());
+ commonFileService.deleteByBusinessIds(Arrays.asList(ids),FileNameType.INSPECTION_PRODUCTION_BEFORE.getValue());
+ commonFileService.deleteByBusinessIds(Arrays.asList(ids),FileNameType.INSPECTION_PRODUCTION_AFTER.getValue());
return inspectionTaskMapper.deleteBatchIds(Arrays.asList(ids));
}
--
Gitblit v1.9.3