From d14764d097691d35e7015c2d161c612aa7642a8e Mon Sep 17 00:00:00 2001
From: liyong <18434998025@163.com>
Date: 星期三, 27 五月 2026 17:23:56 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/dev_天津_阳光彩印' into dev_天津_阳光彩印
---
src/main/java/com/ruoyi/inspectiontask/service/impl/InspectionTaskServiceImpl.java | 209 +++++++++++++++++++++++++++++++++++++--------------
1 files changed, 150 insertions(+), 59 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..14501fd 100644
--- a/src/main/java/com/ruoyi/inspectiontask/service/impl/InspectionTaskServiceImpl.java
+++ b/src/main/java/com/ruoyi/inspectiontask/service/impl/InspectionTaskServiceImpl.java
@@ -11,20 +11,29 @@
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.inspectiontask.dto.InspectionTaskDto;
import com.ruoyi.inspectiontask.mapper.InspectionTaskMapper;
+import com.ruoyi.inspectiontask.mapper.TimingTaskMapper;
import com.ruoyi.inspectiontask.pojo.InspectionTask;
+import com.ruoyi.inspectiontask.pojo.TimingTask;
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.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.function.Function;
@@ -59,6 +68,15 @@
@Autowired
private SysUserMapper sysUserMapper;
+
+ @Autowired
+ private CommonFileMapper commonFileMapper;
+
+ @Autowired
+ private CommonFileServiceImpl commonFileService;
+
+ @Autowired
+ private TimingTaskMapper timingTaskMapper;
@Override
public IPage<InspectionTaskDto> selectInspectionTaskList(Page<InspectionTask> page, InspectionTaskDto inspectionTaskDto) {
@@ -114,21 +132,27 @@
(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<>();
+ }
+ List<CommonFile> finalCommonFiles = commonFiles;
+
+ // 鎵归噺鏌ヨ瀹氭椂浠诲姟鑾峰彇nextExecutionTime
+ List<Long> timingTaskIds = entityPage.getRecords().stream()
+ .map(InspectionTask::getTimingTaskId)
+ .filter(Objects::nonNull)
+ .collect(Collectors.toList());
+ Map<Long, TimingTask> timingTaskMap = new HashMap<>();
+ if (!timingTaskIds.isEmpty()) {
+ List<TimingTask> timingTasks = timingTaskMapper.selectBatchIds(timingTaskIds);
+ timingTaskMap = timingTasks.stream()
+ .collect(Collectors.toMap(TimingTask::getId, Function.identity()));
+ }
+ final Map<Long, TimingTask> finalTimingTaskMap = timingTaskMap;
+ final LocalDateTime now = LocalDateTime.now();
List<InspectionTaskDto> dtoList = entityPage.getRecords().stream().map(inspectionTask -> {
InspectionTaskDto dto = new InspectionTaskDto();
@@ -157,37 +181,29 @@
dto.setDateStr(inspectionTask.getCreateTime().format(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
- // 鍒濆鍖栦笁涓檮浠跺垪琛�
- dto.setBeforeProduction(new ArrayList<>());
- dto.setAfterProduction(new ArrayList<>());
- dto.setProductionIssues(new ArrayList<>());
+ // 鍒濆鍖栦笁涓檮浠跺垪琛紝鎸塩ommonId鍜宼ype杩囨护
+ Long taskId = inspectionTask.getId();
+ dto.setCommonFileList(finalCommonFiles.stream()
+ .filter(commonFile -> commonFile.getCommonId().equals(taskId) && commonFile.getType().equals(FileNameType.INSPECTION.getValue()))
+ .collect(Collectors.toList()));
+ dto.setCommonFileListAfter(finalCommonFiles.stream()
+ .filter(commonFile -> commonFile.getCommonId().equals(taskId) && commonFile.getType().equals(FileNameType.INSPECTION_PRODUCTION_AFTER.getValue()))
+ .collect(Collectors.toList()));
+ dto.setCommonFileListBefore(finalCommonFiles.stream()
+ .filter(commonFile -> commonFile.getCommonId().equals(taskId) && 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);
+ // 璁$畻鐘舵�侊細宸茶繃鏈� > 宸℃涓� > 寰呭贰妫�
+ String status = calculateStatus(inspectionTask, finalTimingTaskMap, now);
+ dto.setStatus(status);
- // 鏍规嵁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;
- }
- }
- });
+ // 璁剧疆nextExecutionTime鐢ㄤ簬鍓嶇灞曠ず
+ if (inspectionTask.getTimingTaskId() != null) {
+ TimingTask timingTask = finalTimingTaskMap.get(inspectionTask.getTimingTaskId());
+ if (timingTask != null) {
+ dto.setNextExecutionTime(timingTask.getNextExecutionTime());
+ }
+ }
return dto;
}).collect(Collectors.toList());
@@ -221,8 +237,41 @@
return dto;
}
+ /**
+ * 璁$畻宸℃浠诲姟鐘舵��
+ * 浼樺厛绾э細宸茶繃鏈� > 宸℃涓� > 寰呭贰妫�
+ * @param inspectionTask 宸℃浠诲姟
+ * @param timingTaskMap 瀹氭椂浠诲姟Map
+ * @param now 褰撳墠鏃堕棿
+ * @return 鐘舵�侊細EXPIRED-宸茶繃鏈燂紝IN_PROGRESS-宸℃涓紝PENDING-寰呭贰妫�
+ */
+ private String calculateStatus(InspectionTask inspectionTask, Map<Long, TimingTask> timingTaskMap, LocalDateTime now) {
+ // 1. 鍒ゆ柇鏄惁宸茶繃鏈�
+ if (inspectionTask.getTimingTaskId() != null) {
+ TimingTask timingTask = timingTaskMap.get(inspectionTask.getTimingTaskId());
+ if (timingTask != null && timingTask.getNextExecutionTime() != null) {
+ if (now.isAfter(timingTask.getNextExecutionTime())) {
+ return "EXPIRED";
+ }
+ }
+ }else {
+ return "EXPIRED";
+ }
+
+ // 2. 鍒ゆ柇鏄惁宸℃涓紙浠讳竴寮傚父瀛楁涓嶄负null锛�
+ if (inspectionTask.getHasExceptionBefore() != null
+ || inspectionTask.getHasExceptionAfter() != null
+ || inspectionTask.getHasExceptionIssue() != null) {
+ return "IN_PROGRESS";
+ }
+
+ // 3. 寰呭贰妫�
+ return "PENDING";
+ }
+
@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);
inspectionTask.setRegistrantId(SecurityUtils.getLoginUser().getUserId());
@@ -232,31 +281,73 @@
i = inspectionTaskMapper.insert(inspectionTask);
} else {
i = inspectionTaskMapper.updateById(inspectionTask);
+ // 缂栬緫鏃跺鐞嗛檮浠跺垹闄ら�昏緫
+ handleFileDeletion(inspectionTask.getId(), inspectionTaskDto);
}
- 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;
}
+ /**
+ * 澶勭悊闄勪欢鍒犻櫎閫昏緫锛氬姣斿師鏈夐檮浠跺拰浼犲叆鐨勯檮浠讹紝鍒犻櫎琚Щ闄ょ殑闄勪欢
+ */
+ private void handleFileDeletion(Long taskId, InspectionTaskDto inspectionTaskDto) {
+ // 鏌ヨ鍘熸湁鐨勪笁绉嶇被鍨嬮檮浠�
+ List<CommonFile> existingFiles = commonFileMapper.selectList(new LambdaQueryWrapper<CommonFile>()
+ .eq(CommonFile::getCommonId, taskId)
+ .in(CommonFile::getType, Arrays.asList(
+ FileNameType.INSPECTION.getValue(),
+ FileNameType.INSPECTION_PRODUCTION_BEFORE.getValue(),
+ FileNameType.INSPECTION_PRODUCTION_AFTER.getValue())));
+
+ if (CollectionUtils.isEmpty(existingFiles)) {
+ return;
+ }
+
+ // 鑾峰彇鍓嶇浼犲叆鐨勯檮浠禝D闆嗗悎
+ Set<Long> submittedFileIds = new HashSet<>();
+ if (inspectionTaskDto.getCommonFileList() != null) {
+ inspectionTaskDto.getCommonFileList().stream()
+ .map(CommonFile::getId)
+ .filter(Objects::nonNull)
+ .forEach(submittedFileIds::add);
+ }
+ if (inspectionTaskDto.getCommonFileListBefore() != null) {
+ inspectionTaskDto.getCommonFileListBefore().stream()
+ .map(CommonFile::getId)
+ .filter(Objects::nonNull)
+ .forEach(submittedFileIds::add);
+ }
+ if (inspectionTaskDto.getCommonFileListAfter() != null) {
+ inspectionTaskDto.getCommonFileListAfter().stream()
+ .map(CommonFile::getId)
+ .filter(Objects::nonNull)
+ .forEach(submittedFileIds::add);
+ }
+
+ // 鎵惧嚭闇�瑕佸垹闄ょ殑闄勪欢ID锛堝師鏈変絾鍓嶇娌′紶鐨勶級
+ List<Long> toDeleteIds = existingFiles.stream()
+ .map(CommonFile::getId)
+ .filter(id -> !submittedFileIds.contains(id))
+ .collect(Collectors.toList());
+
+ // 鍒犻櫎闄勪欢
+ if (!toDeleteIds.isEmpty()) {
+ commonFileService.delCommonFileByIds(toDeleteIds.toArray(new Long[0]));
+ }
+ }
+
@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