liyong
10 天以前 8e89f95b9db4039f0cb8b4b8dc7974c247366c4c
Merge remote-tracking branch 'origin/dev_天津_阳光彩印' into dev_天津_阳光彩印
已修改2个文件
73 ■■■■■ 文件已修改
src/main/java/com/ruoyi/inspectiontask/service/impl/InspectionTaskServiceImpl.java 67 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ruoyi/sales/pojo/CommonFile.java 6 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ruoyi/inspectiontask/service/impl/InspectionTaskServiceImpl.java
@@ -161,10 +161,17 @@
            dto.setDateStr(inspectionTask.getCreateTime().format(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
            // 初始化三个附件列表
            dto.setCommonFileList(finalCommonFiles.stream().filter(commonFile -> commonFile.getType().equals(FileNameType.INSPECTION.getValue())).collect(Collectors.toList()));
            dto.setCommonFileListAfter(finalCommonFiles.stream().filter(commonFile -> commonFile.getType().equals(FileNameType.INSPECTION_PRODUCTION_AFTER.getValue())).collect(Collectors.toList()));
            dto.setCommonFileListBefore(finalCommonFiles.stream().filter(commonFile -> commonFile.getType().equals(FileNameType.INSPECTION_PRODUCTION_BEFORE.getValue())).collect(Collectors.toList()));
            // 初始化三个附件列表,按commonId和type过滤
            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()));
            return dto;
@@ -211,11 +218,63 @@
            i = inspectionTaskMapper.insert(inspectionTask);
        } else {
            i = inspectionTaskMapper.updateById(inspectionTask);
            // 编辑时处理附件删除逻辑
            handleFileDeletion(inspectionTask.getId(), inspectionTaskDto);
        }
        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;
        }
        // 获取前端传入的附件ID集合
        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) {
src/main/java/com/ruoyi/sales/pojo/CommonFile.java
@@ -1,8 +1,10 @@
package com.ruoyi.sales.pojo;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModelProperty;
import com.baomidou.mybatisplus.annotation.*;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;
import java.time.LocalDateTime;
@@ -33,10 +35,14 @@
    /** 创建时间 */
    @TableField(fill = FieldFill.INSERT)
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime createTime;
    /** 更新时间 */
    @TableField(fill = FieldFill.INSERT_UPDATE)
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime updateTime;
    @ApiModelProperty(value = "创建用户")
    @TableField(fill = FieldFill.INSERT)