diff --git a/core/src/main/java/com/dite/znpt/constant/Message.java b/core/src/main/java/com/dite/znpt/constant/Message.java index fdb9de4..e0e5adc 100644 --- a/core/src/main/java/com/dite/znpt/constant/Message.java +++ b/core/src/main/java/com/dite/znpt/constant/Message.java @@ -61,4 +61,5 @@ public class Message implements Serializable { public static final String WORK_SHIFT_NAME_EXIST = "班次名称已经存在"; public static final String WORK_SHIFT_NOT_EXIST = "班次不存在"; public static final String WORK_SHIFT_IS_NOT_UNPUBLISH = "班次的状态不是未发布"; + public static final String IMAGE_AUTO_MARK_ERROR = "自动标注出错:"; } diff --git a/core/src/main/java/com/dite/znpt/domain/vo/DefectMarkReq.java b/core/src/main/java/com/dite/znpt/domain/vo/DefectMarkReq.java index 358d979..0b2367c 100644 --- a/core/src/main/java/com/dite/znpt/domain/vo/DefectMarkReq.java +++ b/core/src/main/java/com/dite/znpt/domain/vo/DefectMarkReq.java @@ -23,9 +23,6 @@ public class DefectMarkReq implements Serializable { @ApiModelProperty("图片id") private String imageId; - @ApiModelProperty("图片集id") - private String collectId; - @NotBlank(groups = {ValidationGroup.Request.class}, message = "模型id不能为空") @ApiModelProperty("模型id") private String modelId; 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 f34d318..c4a45cd 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 @@ -1,5 +1,6 @@ package com.dite.znpt.domain.vo; +import com.dite.znpt.domain.bo.Detection; import com.fasterxml.jackson.annotation.JsonFormat; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; @@ -51,6 +52,9 @@ public class DefectReq implements Serializable { @ApiModelProperty("标注信息") private String labelInfo; + @ApiModelProperty("标注信息") + private Detection markInfo; + @ApiModelProperty("说明") private String description; 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 73f6444..4ff545f 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 @@ -1,16 +1,11 @@ package com.dite.znpt.domain.vo; -import com.alibaba.excel.annotation.ExcelProperty; -import com.baomidou.mybatisplus.annotation.IdType; -import com.baomidou.mybatisplus.annotation.TableField; -import com.baomidou.mybatisplus.annotation.TableId; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; import java.io.Serial; import java.io.Serializable; -import java.time.LocalDate; /** * @author huise23 @@ -27,6 +22,9 @@ public class DefectResp extends DefectReq implements Serializable { @ApiModelProperty("缺陷id") private String defectId; + @ApiModelProperty("图像id") + private String imageId; + @ApiModelProperty("缺陷类型描述") private String defectTypeLabel; diff --git a/core/src/main/java/com/dite/znpt/enums/DefectTypeEnum.java b/core/src/main/java/com/dite/znpt/enums/DefectTypeEnum.java index 68505b5..4ea3f4d 100644 --- a/core/src/main/java/com/dite/znpt/enums/DefectTypeEnum.java +++ b/core/src/main/java/com/dite/znpt/enums/DefectTypeEnum.java @@ -13,7 +13,7 @@ import java.util.List; */ @Getter public enum DefectTypeEnum { - CRAZE("BMLW", "合缝开裂"), + BMLW("bmlw", "表面裂纹"), ABRASION("ABRASION", "合缝磨损"), LEATHER_BREAKAGE("LEATHER_BREAKAGE", "蒙皮破损"), FABRIC_BREAKAGE("FABRIC_BREAKAGE", "布层破损"), diff --git a/core/src/main/java/com/dite/znpt/enums/FilePathEnum.java b/core/src/main/java/com/dite/znpt/enums/FilePathEnum.java index 702b30f..3c522a7 100644 --- a/core/src/main/java/com/dite/znpt/enums/FilePathEnum.java +++ b/core/src/main/java/com/dite/znpt/enums/FilePathEnum.java @@ -14,8 +14,7 @@ public enum FilePathEnum { IMAGE_TEMP("/static/image/temp/", "image-temp"), VIDEO("/static/video/", "video"), AUDIO("/static/audio/", "audio"), - ATTACH("/static/attach/", "attach"), - INSURANCE("/static/insurance/", "insurance"); + ATTACH("/static/attach/", "attach"); @Getter private final String urlPath; diff --git a/core/src/main/java/com/dite/znpt/enums/ImageSourceEnum.java b/core/src/main/java/com/dite/znpt/enums/ImageSourceEnum.java index 8919e04..c69ee63 100644 --- a/core/src/main/java/com/dite/znpt/enums/ImageSourceEnum.java +++ b/core/src/main/java/com/dite/znpt/enums/ImageSourceEnum.java @@ -13,19 +13,17 @@ import java.util.List; */ @Getter public enum ImageSourceEnum { - COLLECT("collect", "图像采集", Boolean.TRUE), - OUT_WORK("out-work", "外部工作", Boolean.TRUE), - IN_WORK("in-work", "内部工作", Boolean.TRUE), - LIGHTNING_PROTECTING_WORK("lightning-protection-work", "防雷工作", Boolean.FALSE); + COLLECT("collect", "图像采集"), + OUT_WORK("out-work", "外部工作"), + IN_WORK("in-work", "内部工作"), + LIGHTNING_PROTECTING_WORK("lightning-protection-work", "防雷工作"); private final String code; private final String desc; - private final boolean isDefectImage; - ImageSourceEnum(String code, String desc, boolean isDefectImage){ + ImageSourceEnum(String code, String desc){ this.code = code; this.desc = desc; - this.isDefectImage = isDefectImage; } public static ImageSourceEnum getByCode(String code){ @@ -42,14 +40,12 @@ public enum ImageSourceEnum { return null == e ? null : e.desc; } - public static List list(Boolean isDefectImage){ + public static List list(){ List list = new ArrayList<>(ImageSourceEnum.values().length); for (ImageSourceEnum e : ImageSourceEnum.values() ) { - if(isDefectImage.equals(e.isDefectImage)){ - JSONObject jsonObject = new JSONObject(); - jsonObject.set(e.code, e.desc); - list.add(jsonObject); - } + JSONObject jsonObject = new JSONObject(); + jsonObject.set(e.code, e.desc); + list.add(jsonObject); } return list; } diff --git a/core/src/main/java/com/dite/znpt/service/DefectService.java b/core/src/main/java/com/dite/znpt/service/DefectService.java index 573c5f1..4796f8c 100644 --- a/core/src/main/java/com/dite/znpt/service/DefectService.java +++ b/core/src/main/java/com/dite/znpt/service/DefectService.java @@ -77,10 +77,10 @@ public interface DefectService extends IService { * 功能描述:缺陷自动检测 * * @param markReq 马克请求类 - * @return {@link DefectResp } + * @return {@link List }<{@link DefectResp }> * @author cuizhibin - * @date 2025/07/04 10:55 + * @date 2025/07/04 14:53 **/ - DefectResp detect(DefectMarkReq markReq); + List detect(DefectMarkReq markReq); } 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 59b2093..8bc2ad5 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,15 +1,17 @@ package com.dite.znpt.service.impl; +import ai.onnxruntime.OrtException; +import cn.hutool.core.io.FileUtil; import cn.hutool.core.util.StrUtil; +import cn.hutool.json.JSONUtil; 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.DefectEntity; import com.dite.znpt.domain.entity.ImageEntity; import com.dite.znpt.domain.vo.*; -import com.dite.znpt.enums.DefectSourceEnum; -import com.dite.znpt.enums.DefectTypeEnum; -import com.dite.znpt.enums.RepairStatusEnum; +import com.dite.znpt.enums.*; import com.dite.znpt.exception.ServiceException; import com.dite.znpt.mapper.DefectMapper; import com.dite.znpt.service.DefectService; @@ -21,9 +23,11 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; +import java.time.LocalDate; import java.util.ArrayList; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.function.Function; import java.util.stream.Collectors; @@ -51,12 +55,19 @@ public class DefectServiceImpl extends ServiceImpl i @Override public List page(DefectListReq req) { PageUtil.startPage(); - return this.list(req); + List list = this.list(req); + list.forEach(defect -> { + defect.setMarkInfo(JSONUtil.toBean(defect.getLabelInfo(), Detection.class)); + }); + return list; } @Override public List list(DefectListReq req) { List defectList= this.baseMapper.queryBySelective(req); + defectList.forEach(defect -> { + defect.setMarkInfo(JSONUtil.toBean(defect.getLabelInfo(), Detection.class)); + }); return defectList; } @@ -72,9 +83,10 @@ public class DefectServiceImpl extends ServiceImpl i public DefectResp detail(String defectId) { DefectResp defectResp = this.baseMapper.detail(defectId); defectResp.setDefectTypeLabel(DefectTypeEnum.getDescByCode(defectResp.getDefectType())); - defectResp.setDefectLevel(DefectTypeEnum.getDescByCode(defectResp.getDefectLevel())); + defectResp.setDefectLevel(DefectLevelEnum.getDescByCode(defectResp.getDefectLevel())); defectResp.setRepairStatusLabel(RepairStatusEnum.getDescByCode(defectResp.getRepairStatus())); defectResp.setSourceLabel(DefectSourceEnum.getDescByCode(defectResp.getSourceLabel())); + defectResp.setMarkInfo(JSONUtil.toBean(defectResp.getLabelInfo(), Detection.class)); return defectResp; } @@ -94,6 +106,7 @@ public class DefectServiceImpl extends ServiceImpl i } DefectEntity defectEntity = Converts.INSTANCE.toDefectEntity(req); defectEntity.setImageId(imageId); + defectEntity.setLabelInfo(JSONUtil.toJsonStr(req.getMarkInfo())); this.save(defectEntity); } @@ -115,6 +128,7 @@ public class DefectServiceImpl extends ServiceImpl i if(imageMap.containsKey(key)){ DefectEntity defectEntity = Converts.INSTANCE.toDefectEntity(req); defectEntity.setImageId(imageMap.get(key).getImageId()); + defectEntity.setLabelInfo(JSONUtil.toJsonStr(req.getMarkInfo())); defectEntityList.add(defectEntity); } }); @@ -137,6 +151,7 @@ public class DefectServiceImpl extends ServiceImpl i throw new ServiceException(Message.DEFECT_ID_IS_NOT_EXIST); } DefectEntity defectEntity = Converts.INSTANCE.toDefectEntity(req); + defectEntity.setLabelInfo(JSONUtil.toJsonStr(req.getMarkInfo())); this.updateById(defectEntity); } @@ -157,13 +172,38 @@ public class DefectServiceImpl extends ServiceImpl i * 功能描述:缺陷自动检测 * * @param markReq 马克请求类 - * @return {@link DefectResp } + * @return {@link List }<{@link DefectResp }> * @author cuizhibin * @date 2025/07/04 10:55 **/ @Override - public DefectResp detect(DefectMarkReq markReq) { -// multiModelYoloService.runFolderDetection(); - return null; + public List detect(DefectMarkReq markReq) { + ImageEntity image = imageService.getById(markReq.getImageId()); + if (Objects.isNull(image)) { + throw new ServiceException(Message.IMAGE_ID_IS_NOT_EXIST); + } + 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)); + try { + List detect = multiModelYoloService.detect(markReq.getModelId(), inputPath, outputPath, markReq.getConfThreshold()); + List respList = new ArrayList<>(); + for (Detection detection : detect) { + DefectResp resp = new DefectResp(); + resp.setImageId(markReq.getImageId()); + resp.setDefectType(detection.getLabel()); + resp.setDefectTypeLabel(DefectTypeEnum.getDescByCode(detection.getLabel())); + resp.setDetectionDate(LocalDate.now()); + resp.setSource(DefectSourceEnum.AI.getCode()); + resp.setSourceLabel(DefectSourceEnum.AI.getDesc()); + resp.setMarkInfo(detection); + resp.setRepairStatus(RepairStatusEnum.INCOMPLETE.getCode()); + resp.setRepairStatusLabel(RepairStatusEnum.INCOMPLETE.getDesc()); + respList.add(resp); + } + return respList; + } catch (OrtException e) { + throw new ServiceException(Message.IMAGE_AUTO_MARK_ERROR + e.getMessage()); + } } } diff --git a/core/src/main/java/com/dite/znpt/service/impl/ImageServiceImpl.java b/core/src/main/java/com/dite/znpt/service/impl/ImageServiceImpl.java index 35a8728..95dca45 100644 --- a/core/src/main/java/com/dite/znpt/service/impl/ImageServiceImpl.java +++ b/core/src/main/java/com/dite/znpt/service/impl/ImageServiceImpl.java @@ -148,7 +148,7 @@ public class ImageServiceImpl extends ServiceImpl impl temCategory.mkdirs(); } String temPathPrefix = FilePathEnum.IMAGE_TEMP.getFileAbsolutePathPrefix().concat(imageSource).concat(FileUtil.FILE_SEPARATOR).concat(partId).concat(FileUtil.FILE_SEPARATOR); - ImageCollectEntity imageCollect = BeanUtil.copyProperties(collectReq, ImageCollectEntity.class); + ImageCollectEntity imageCollect = Optional.ofNullable(BeanUtil.copyProperties(collectReq, ImageCollectEntity.class)).orElse(new ImageCollectEntity()); imageCollect.setCollectId(IdUtil.simpleUUID()); List imageList = new ArrayList<>(); for (MultipartFile file : files) { diff --git a/web/src/main/java/com/dite/znpt/web/controller/CommonController.java b/web/src/main/java/com/dite/znpt/web/controller/CommonController.java index 94f0d86..4e96b3b 100644 --- a/web/src/main/java/com/dite/znpt/web/controller/CommonController.java +++ b/web/src/main/java/com/dite/znpt/web/controller/CommonController.java @@ -90,7 +90,7 @@ public class CommonController { @ApiOperation(value = "查询通用图片来源", httpMethod = "GET") @GetMapping("/list/common-image-source") public Result listCommonImageSource(){ - return Result.ok(ImageSourceEnum.list(Boolean.FALSE)); + return Result.ok(ImageSourceEnum.list()); } @ApiOperation(value = "查询学历", httpMethod = "GET") diff --git a/web/src/main/java/com/dite/znpt/web/controller/DefectController.java b/web/src/main/java/com/dite/znpt/web/controller/DefectController.java index 65a3d21..5634ea3 100644 --- a/web/src/main/java/com/dite/znpt/web/controller/DefectController.java +++ b/web/src/main/java/com/dite/znpt/web/controller/DefectController.java @@ -68,8 +68,8 @@ public class DefectController { } @ApiOperation(value = "单图自动标注缺陷", httpMethod = "POST") - @PostMapping("/run") - public Result runBatch(@Validated(ValidationGroup.Request.class) @RequestBody DefectMarkReq markReq) { + @PostMapping("/detect") + public Result> runBatch(@Validated(ValidationGroup.Request.class) @RequestBody DefectMarkReq markReq) { return Result.ok(defectService.detect(markReq)); } } diff --git a/web/src/main/java/com/dite/znpt/web/controller/ImageController.java b/web/src/main/java/com/dite/znpt/web/controller/ImageController.java index 9a9ce07..4c3ed4c 100644 --- a/web/src/main/java/com/dite/znpt/web/controller/ImageController.java +++ b/web/src/main/java/com/dite/znpt/web/controller/ImageController.java @@ -4,7 +4,6 @@ package com.dite.znpt.web.controller; import com.dite.znpt.domain.PageResult; import com.dite.znpt.domain.Result; import com.dite.znpt.domain.vo.*; -import com.dite.znpt.enums.ImageSourceEnum; import com.dite.znpt.service.ImageCollectService; import com.dite.znpt.service.ImageService; import io.swagger.annotations.Api; @@ -60,7 +59,7 @@ public class ImageController { @PostMapping("/{imageSource}/upload/{partId}") public Result uploadOutWork(@PathVariable String imageSource, @PathVariable String partId, ImageCollectReq collectReq, @RequestParam("file") MultipartFile file) { MultipartFile[] files = {file}; - return Result.ok(imageService.batchUploadDefectImage(partId, ImageSourceEnum.OUT_WORK.getCode(), collectReq, files).get(0).getImagePath()); + return Result.ok(imageService.batchUploadDefectImage(partId, imageSource, collectReq, files).get(0).getImagePath()); } @ApiOperation(value = "设置信息", httpMethod = "POST") diff --git a/web/src/main/resources/application-dev.yml b/web/src/main/resources/application-dev.yml index bbc969b..d2f6810 100644 --- a/web/src/main/resources/application-dev.yml +++ b/web/src/main/resources/application-dev.yml @@ -8,7 +8,7 @@ spring: datasource: type: com.alibaba.druid.pool.DruidDataSource driverClassName: com.mysql.cj.jdbc.Driver - url: jdbc:mysql://39.99.201.243:3306/test?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8 + url: jdbc:mysql://39.99.201.243:3306/znpt_dev?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8 username: root password: BUw8YW6%@^8q druid: