diff --git a/core/src/main/java/com/dite/znpt/domain/vo/DefectReq.java b/core/src/main/java/com/dite/znpt/domain/vo/DefectReq.java index c4a45cd..d07b6c0 100644 --- a/core/src/main/java/com/dite/znpt/domain/vo/DefectReq.java +++ b/core/src/main/java/com/dite/znpt/domain/vo/DefectReq.java @@ -60,4 +60,7 @@ public class DefectReq implements Serializable { @ApiModelProperty("维修建议") private String repairIdea; + + @ApiModelProperty("附件id") + private String attachId; } diff --git a/core/src/main/java/com/dite/znpt/domain/vo/DefectResp.java b/core/src/main/java/com/dite/znpt/domain/vo/DefectResp.java index 4ff545f..e2efbde 100644 --- a/core/src/main/java/com/dite/znpt/domain/vo/DefectResp.java +++ b/core/src/main/java/com/dite/znpt/domain/vo/DefectResp.java @@ -37,5 +37,8 @@ public class DefectResp extends DefectReq implements Serializable { @ApiModelProperty("来源描述") private String sourceLabel; + @ApiModelProperty("缺陷附件路径") + private String attachPath; + } diff --git a/core/src/main/java/com/dite/znpt/enums/AttachBusinessTypeEnum.java b/core/src/main/java/com/dite/znpt/enums/AttachBusinessTypeEnum.java index 502a022..096af63 100644 --- a/core/src/main/java/com/dite/znpt/enums/AttachBusinessTypeEnum.java +++ b/core/src/main/java/com/dite/znpt/enums/AttachBusinessTypeEnum.java @@ -16,6 +16,7 @@ public enum AttachBusinessTypeEnum { PROJECT_TASK("PROJECT_TASK", "项目任务"), INSURANCE_FILE("insurance", "保险文件"), MODEL_FILE("model", "模型文件"), + DEFECT_MARK_PIC("defect_mark_pic", "缺陷标注图片"), ; private final String code; private final String desc; diff --git a/core/src/main/java/com/dite/znpt/service/impl/DefectServiceImpl.java b/core/src/main/java/com/dite/znpt/service/impl/DefectServiceImpl.java index 8bc2ad5..c30661b 100644 --- a/core/src/main/java/com/dite/znpt/service/impl/DefectServiceImpl.java +++ b/core/src/main/java/com/dite/znpt/service/impl/DefectServiceImpl.java @@ -1,6 +1,7 @@ package com.dite.znpt.service.impl; import ai.onnxruntime.OrtException; +import cn.hutool.core.collection.ListUtil; import cn.hutool.core.io.FileUtil; import cn.hutool.core.util.StrUtil; import cn.hutool.json.JSONUtil; @@ -8,12 +9,14 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.dite.znpt.constant.Message; import com.dite.znpt.converts.Converts; import com.dite.znpt.domain.bo.Detection; +import com.dite.znpt.domain.entity.AttachInfoEntity; import com.dite.znpt.domain.entity.DefectEntity; import com.dite.znpt.domain.entity.ImageEntity; import com.dite.znpt.domain.vo.*; import com.dite.znpt.enums.*; import com.dite.znpt.exception.ServiceException; import com.dite.znpt.mapper.DefectMapper; +import com.dite.znpt.service.AttachInfoService; import com.dite.znpt.service.DefectService; import com.dite.znpt.service.ImageService; import com.dite.znpt.util.PageUtil; @@ -43,6 +46,8 @@ public class DefectServiceImpl extends ServiceImpl i private ImageService imageService; @Autowired private MultiModelYoloService multiModelYoloService; + @Autowired + private AttachInfoService attachInfoService; /** * 功能描述:查询缺陷记录列表 @@ -107,6 +112,7 @@ public class DefectServiceImpl extends ServiceImpl i DefectEntity defectEntity = Converts.INSTANCE.toDefectEntity(req); defectEntity.setImageId(imageId); defectEntity.setLabelInfo(JSONUtil.toJsonStr(req.getMarkInfo())); + attachInfoService.updateBusinessIdByAttachIds(defectEntity.getImageId(), ListUtil.of(req.getAttachId()), AttachBusinessTypeEnum.DEFECT_MARK_PIC); this.save(defectEntity); } @@ -153,6 +159,7 @@ public class DefectServiceImpl extends ServiceImpl i DefectEntity defectEntity = Converts.INSTANCE.toDefectEntity(req); defectEntity.setLabelInfo(JSONUtil.toJsonStr(req.getMarkInfo())); this.updateById(defectEntity); + attachInfoService.updateBusinessIdByAttachIds(defectEntity.getImageId(), ListUtil.of(req.getAttachId()), AttachBusinessTypeEnum.DEFECT_MARK_PIC); } /** @@ -177,6 +184,7 @@ public class DefectServiceImpl extends ServiceImpl i * @date 2025/07/04 10:55 **/ @Override + @Transactional(rollbackFor = Exception.class) public List detect(DefectMarkReq markReq) { ImageEntity image = imageService.getById(markReq.getImageId()); if (Objects.isNull(image)) { @@ -184,7 +192,16 @@ public class DefectServiceImpl extends ServiceImpl i } FilePathEnum pathEnum = image.getImagePath().contains("temp") ? FilePathEnum.IMAGE_TEMP : FilePathEnum.IMAGE; String inputPath = pathEnum.getFileAbsolutePath(image.getImagePath()); - String outputPath = FileUtil.getParent(inputPath, 1).concat(FileUtil.mainName(inputPath)+"_mark").concat(StrUtil.DOT).concat(FileUtil.extName(inputPath)); +// 写入attach同层级文件夹下 + String attachPath = FilePathEnum.ATTACH.getUrlPath() + StrUtil.removePrefix(image.getImagePath(), pathEnum.getUrlPath()); + String outputPath = FilePathEnum.ATTACH.getFileAbsolutePath(attachPath); + FileUtil.mkParentDirs(outputPath); + + AttachInfoEntity attachInfo = new AttachInfoEntity(); + attachInfo.setBusinessId(image.getImageId()); + attachInfo.setAttachPath(attachPath); + attachInfo.setBusinessType(AttachBusinessTypeEnum.DEFECT_MARK_PIC.getCode()); + attachInfoService.save(attachInfo); try { List detect = multiModelYoloService.detect(markReq.getModelId(), inputPath, outputPath, markReq.getConfThreshold()); List respList = new ArrayList<>(); @@ -199,6 +216,8 @@ public class DefectServiceImpl extends ServiceImpl i resp.setMarkInfo(detection); resp.setRepairStatus(RepairStatusEnum.INCOMPLETE.getCode()); resp.setRepairStatusLabel(RepairStatusEnum.INCOMPLETE.getDesc()); + resp.setAttachId(attachInfo.getAttachId()); + resp.setAttachPath(attachPath); respList.add(resp); } return respList;