新增缺陷,编辑缺陷,缺陷列表,缺陷详情和删除缺陷

This commit is contained in:
gaoxiong 2025-04-27 22:40:40 +08:00
parent b68e4489fd
commit 44e0f6748d
20 changed files with 356 additions and 78 deletions

View File

@ -15,4 +15,5 @@ public class Message implements Serializable {
public static final String IMAGE_IS_EMPTY = "图像信息为空";
public static final String IMAGE_PATH_IS_NOT_EXIST = "图像地址不存在";
public static final String IMAGE_ID_IS_NOT_EXIST = "图像id不存在";
public static final String DEFECT_ID_IS_NOT_EXIST = "缺陷id不存在";
}

View File

@ -1,7 +1,10 @@
package com.dite.znpt.converts;
import com.dite.znpt.domain.entity.DefectEntity;
import com.dite.znpt.domain.entity.ImageCollectEntity;
import com.dite.znpt.domain.entity.ImageEntity;
import com.dite.znpt.domain.vo.DefectReq;
import com.dite.znpt.domain.vo.DefectResp;
import com.dite.znpt.domain.vo.ImageCollectReq;
import com.dite.znpt.domain.vo.ImageReq;
import org.mapstruct.Mapper;
@ -22,4 +25,8 @@ public interface Converts {
List<ImageEntity> toImageEntity(List<ImageReq> list);
ImageCollectEntity toImageCollectEntity(ImageCollectReq req);
DefectEntity toDefectEntity(DefectReq req);
DefectResp toDefectResp(DefectEntity entity);
}

View File

@ -30,10 +30,10 @@ public class DefectEntity extends AuditableEntity implements Serializable {
@TableId(value = "defect_id", type = IdType.ASSIGN_UUID)
private String defectId;
@ExcelProperty("部件id")
@ApiModelProperty("部件id")
@TableField("part_id")
private String partId;
@ExcelProperty("图像id")
@ApiModelProperty("图像id")
@TableField("image_id")
private String imageId;
@ExcelProperty("缺陷编码")
@ApiModelProperty("缺陷编码")
@ -94,5 +94,11 @@ public class DefectEntity extends AuditableEntity implements Serializable {
@ApiModelProperty("说明")
@TableField("description")
private String description;
@ExcelProperty("维修建议")
@ApiModelProperty("维修建议")
@TableField("repair_idea")
private String repairIdea;
}

View File

@ -27,9 +27,6 @@ public class DefectListReq implements Serializable {
@ApiModelProperty("机组id")
private String turbineId;
@ApiModelProperty("部件id")
private String partId;
@ApiModelProperty("缺陷类型枚举DefectTypeEnum")
private String defectType;

View File

@ -0,0 +1,35 @@
package com.dite.znpt.domain.vo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
/**
* @Author: gaoxiong
* @Date: 2025/4/27 21:23
* @Description:
*/
@Data
@ApiModel("缺陷记录列表响应实体")
public class DefectListResp implements Serializable {
@ApiModelProperty("缺陷id")
private String defectId;
@ApiModelProperty("缺陷名称")
private String defectName;
@ApiModelProperty("缺陷编码")
private String defectCode;
@ApiModelProperty("部件名称")
private String partName;
@ApiModelProperty("缺陷未知")
private String defectPosition;
@ApiModelProperty("说明")
private String description;
}

View File

@ -0,0 +1,59 @@
package com.dite.znpt.domain.vo;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
import java.time.LocalDate;
/**
* @Author: gaoxiong
* @Date: 2025/4/27 21:16
* @Description:
*/
@Data
@ApiModel("缺陷记录请求实体")
public class DefectReq implements Serializable {
@ApiModelProperty("缺陷编码")
private String defectCode;
@ApiModelProperty("缺陷名称")
private String defectName;
@ApiModelProperty("缺陷部位")
private String defectPosition;
@ApiModelProperty("缺陷类型枚举DefectTypeEnum")
private String defectType;
@ApiModelProperty("危重等级枚举DefectLevelEnum")
private String defectLevel;
@ApiModelProperty("维修状态枚举RepairStatusEnum")
private String repairStatus;
@JsonFormat(pattern = "yyyy-MM-dd")
@ApiModelProperty("检测时间")
private LocalDate detectionDate;
@ApiModelProperty("来源枚举DefectSourceEnum")
private String source;
@ApiModelProperty("弦向")
private Integer chordwise;
@ApiModelProperty("轴向")
private Integer axial;
@ApiModelProperty("标注信息")
private String labelInfo;
@ApiModelProperty("说明")
private String description;
@ApiModelProperty("维修建议")
private String repairIdea;
}

View File

@ -1,9 +1,16 @@
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 lombok.EqualsAndHashCode;
import com.dite.znpt.domain.entity.DefectEntity;
import java.io.Serial;
import java.io.Serializable;
import java.time.LocalDate;
/**
* @author huise23
@ -11,8 +18,26 @@ import com.dite.znpt.domain.entity.DefectEntity;
* @Description: 缺陷记录响应实体
*/
@Data
@EqualsAndHashCode(callSuper = true)
@ApiModel("缺陷记录响应实体")
public class DefectResp extends DefectEntity {
public class DefectResp extends DefectReq implements Serializable {
@Serial
private static final long serialVersionUID = 7723957970600470768L;
@ApiModelProperty("缺陷id")
private String defectId;
@ApiModelProperty("缺陷类型描述")
private String defectTypeLabel;
@ApiModelProperty("危重等级描述")
private String defectLevelLabel;
@ApiModelProperty("维修状态描述")
private String repairStatusLabel;
@ApiModelProperty("来源描述")
private String sourceLabel;
}

View File

@ -21,6 +21,9 @@ public class ImageListReq implements Serializable {
@ApiModelProperty("关键字")
private String keyword;
@ApiModelProperty("机组id")
private String turbineId;
@ApiModelProperty("图像类型")
private String[] imageTypes;

View File

@ -1,6 +1,7 @@
package com.dite.znpt.enums;
import cn.hutool.json.JSONObject;
import lombok.Getter;
import java.util.ArrayList;
import java.util.List;
@ -10,6 +11,7 @@ import java.util.List;
* @Date: 2025/4/24 21:44
* @Description:
*/
@Getter
public enum DefectLevelEnum {
SLIGHT("SLIGHT", "轻微缺陷"),
GENERAL("GENERAL", "一般缺陷"),

View File

@ -0,0 +1,50 @@
package com.dite.znpt.enums;
import cn.hutool.json.JSONObject;
import lombok.Getter;
import java.util.ArrayList;
import java.util.List;
/**
* @Author: gaoxiong
* @Date: 2025/4/27 20:55
* @Description:
*/
@Getter
public enum DefectSourceEnum {
AI("AI", "智能识别"),
MANUAL("MANUAL", "人工标注");
private final String code;
private final String desc;
DefectSourceEnum(String code, String desc){
this.code = code;
this.desc = desc;
}
public static DefectSourceEnum getByCode(String code){
for (DefectSourceEnum e : DefectSourceEnum.values() ) {
if(e.code.equals(code)){
return e;
}
}
return null;
}
public static String getDescByCode(String code){
DefectSourceEnum e = getByCode(code);
return null == e ? null : e.desc;
}
public static List<JSONObject> listAll(){
List<JSONObject> list = new ArrayList<>(DefectSourceEnum.values().length);
for (DefectSourceEnum e : DefectSourceEnum.values() ) {
JSONObject jsonObject = new JSONObject();
jsonObject.set(e.code, e.desc);
list.add(jsonObject);
}
return list;
}
}

View File

@ -1,6 +1,7 @@
package com.dite.znpt.enums;
import cn.hutool.json.JSONObject;
import lombok.Getter;
import java.util.ArrayList;
import java.util.List;
@ -10,6 +11,7 @@ import java.util.List;
* @Date: 2025/4/24 21:43
* @Description:
*/
@Getter
public enum DefectTypeEnum {
CRAZE("CRAZE", "合缝开裂"),
ABRASION("ABRASION", "合缝磨损"),

View File

@ -1,6 +1,7 @@
package com.dite.znpt.enums;
import cn.hutool.json.JSONObject;
import lombok.Getter;
import java.util.ArrayList;
import java.util.List;
@ -10,6 +11,7 @@ import java.util.List;
* @Date: 2025/4/24 21:25
* @Description:
*/
@Getter
public enum ImageTypeEnum {
DEFECT("DEFECT", "缺陷影像"),
TYPICAL("TYPICAL", "典型影像"),

View File

@ -0,0 +1,51 @@
package com.dite.znpt.enums;
import cn.hutool.json.JSONObject;
import lombok.Getter;
import java.util.ArrayList;
import java.util.List;
/**
* @Author: gaoxiong
* @Date: 2025/4/27 20:55
* @Description:
*/
@Getter
public enum RepairStatusEnum {
INCOMPLETE("INCOMPLETE","未维修"),
COMPLETED("COMPLETED","已维修"),
UNKNOWN("UNKNOWN","未知");
private final String code;
private final String desc;
RepairStatusEnum(String code, String desc){
this.code = code;
this.desc = desc;
}
public static RepairStatusEnum getByCode(String code){
for (RepairStatusEnum e : RepairStatusEnum.values() ) {
if(e.code.equals(code)){
return e;
}
}
return null;
}
public static String getDescByCode(String code){
RepairStatusEnum e = getByCode(code);
return null == e ? null : e.desc;
}
public static List<JSONObject> listAll(){
List<JSONObject> list = new ArrayList<>(RepairStatusEnum.values().length);
for (RepairStatusEnum e : RepairStatusEnum.values() ) {
JSONObject jsonObject = new JSONObject();
jsonObject.set(e.code, e.desc);
list.add(jsonObject);
}
return list;
}
}

View File

@ -15,5 +15,6 @@ import java.util.List;
*/
public interface DefectMapper extends BaseMapper<DefectEntity> {
List<DefectResp> queryBySelective(DefectListReq defectReq);
DefectResp detail(String defectId);
}

View File

@ -3,6 +3,7 @@ package com.dite.znpt.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.dite.znpt.domain.entity.DefectEntity;
import com.dite.znpt.domain.vo.DefectListReq;
import com.dite.znpt.domain.vo.DefectReq;
import com.dite.znpt.domain.vo.DefectResp;
import java.util.List;
@ -17,12 +18,14 @@ public interface DefectService extends IService<DefectEntity> {
/**
* 功能描述查询缺陷记录列表
*
* @param defectReq 缺陷记录
* @param req 缺陷记录
* @return {@link List }<{@link DefectEntity }>
* @author huise23
* @date 2025/04/11 23:17
**/
List<DefectResp> selectList(DefectListReq defectReq);
List<DefectResp> page(DefectListReq req);
List<DefectResp> list(DefectListReq req);
/**
* 功能描述查询单条缺陷记录
@ -32,25 +35,27 @@ public interface DefectService extends IService<DefectEntity> {
* @author huise23
* @date 2025/04/11 23:17
**/
DefectResp selectById(String defectId);
DefectResp detail(String defectId);
/**
* 功能描述新增缺陷记录
*
* @param defect 缺陷记录
* @param imageId 缺陷记录
* @param req 缺陷记录
* @author huise23
* @date 2025/04/11 23:17
**/
void saveData(DefectEntity defect);
void save(String imageId, DefectReq req);
/**
* 功能描述更新缺陷记录
*
* @param defect 缺陷记录
* @param defectId 缺陷记录
* @param req 缺陷记录
* @author huise23
* @date 2025/04/11 23:17
**/
void updateData(DefectEntity defect);
void update(String defectId, DefectReq req);
/**
* 功能描述删除缺陷记录

View File

@ -1,16 +1,26 @@
package com.dite.znpt.service.impl;
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.entity.DefectEntity;
import com.dite.znpt.domain.vo.DefectListReq;
import com.dite.znpt.domain.vo.DefectReq;
import com.dite.znpt.domain.vo.DefectResp;
import com.dite.znpt.enums.DefectSourceEnum;
import com.dite.znpt.enums.DefectTypeEnum;
import com.dite.znpt.enums.RepairStatusEnum;
import com.dite.znpt.exception.ServiceException;
import com.dite.znpt.service.DefectService;
import com.dite.znpt.mapper.DefectMapper;
import com.dite.znpt.service.ImageService;
import org.springframework.stereotype.Service;
import cn.hutool.core.collection.CollUtil;
import lombok.RequiredArgsConstructor;
import com.dite.znpt.util.PageUtil;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.List;
/**
@ -21,22 +31,26 @@ import java.util.List;
@Service
@RequiredArgsConstructor
public class DefectServiceImpl extends ServiceImpl<DefectMapper, DefectEntity> implements DefectService {
@Resource
private ImageService imageService;
/**
* 功能描述查询缺陷记录列表
*
* @param defectReq 缺陷记录信息
* @param req 缺陷记录信息
* @return {@link List }<{@link DefectResp }>
* @author huise23
* @date 2025/04/11 23:17
**/
@Override
public List<DefectResp> selectList(DefectListReq defectReq) {
public List<DefectResp> page(DefectListReq req) {
PageUtil.startPage();
List<DefectResp> defectList= this.baseMapper.queryBySelective(defectReq);
defectList.forEach(resp -> {
return this.list(req);
}
});
@Override
public List<DefectResp> list(DefectListReq req) {
List<DefectResp> defectList= this.baseMapper.queryBySelective(req);
return defectList;
}
@ -49,37 +63,49 @@ public class DefectServiceImpl extends ServiceImpl<DefectMapper, DefectEntity> i
* @date 2025/04/11 23:17
**/
@Override
public DefectResp selectById(String defectId) {
DefectListReq defectReq = new DefectListReq();
defectReq.setDefectId(defectId);
List<DefectResp> list = selectList(defectReq);
return list.isEmpty() ? CollUtil.getFirst(list) : new DefectResp();
public DefectResp detail(String defectId) {
DefectResp defectResp = this.baseMapper.detail(defectId);
defectResp.setDefectTypeLabel(DefectTypeEnum.getDescByCode(defectResp.getDefectType()));
defectResp.setDefectLevel(DefectTypeEnum.getDescByCode(defectResp.getDefectLevel()));
defectResp.setRepairStatusLabel(RepairStatusEnum.getDescByCode(defectResp.getRepairStatus()));
defectResp.setSourceLabel(DefectSourceEnum.getDescByCode(defectResp.getSourceLabel()));
return defectResp;
}
/**
* 功能描述新增缺陷记录
*
* @param defect 缺陷记录
* @param imageId
* @param req
* @author huise23
* @date 2025/04/11 23:17
**/
@Transactional(rollbackFor = Exception.class)
@Override
public void saveData(DefectEntity defect) {
// todo 校验
save(defect);
public void save(String imageId, DefectReq req) {
if(null == imageService.getById(imageId)){
throw new ServiceException(Message.IMAGE_ID_IS_NOT_EXIST);
}
DefectEntity defectEntity = Converts.INSTANCE.toDefectEntity(req);
this.save(defectEntity);
}
/**
* 功能描述更新缺陷记录
*
* @param defect 缺陷记录
* @param defectId
* @param req
* @author huise23
* @date 2025/04/11 23:17
**/
@Transactional(rollbackFor = Exception.class)
@Override
public void updateData(DefectEntity defect) {
// todo 校验
updateById(defect);
public void update(String defectId, DefectReq req) {
if(null == this.getById(defectId)){
throw new ServiceException(Message.DEFECT_ID_IS_NOT_EXIST);
}
DefectEntity defectEntity = Converts.INSTANCE.toDefectEntity(req);
this.updateById(defectEntity);
}
/**
@ -89,10 +115,10 @@ public class DefectServiceImpl extends ServiceImpl<DefectMapper, DefectEntity> i
* @author huise23
* @date 2025/04/11 23:17
**/
@Transactional(rollbackFor = Exception.class)
@Override
public void deleteById(String defectId) {
// todo 校验
removeById(defectId);
this.removeById(defectId);
}
}

View File

@ -2,29 +2,35 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.dite.znpt.mapper.DefectMapper">
<sql id="Base_Column_List">
a.defect_id, a.turbine_id, a.part_id, a.defect_code, a.defect_name, a.defect_type, a.defect_level, a.defect_image_path, a.description
</sql>
<select id="queryBySelective" resultType="com.dite.znpt.domain.vo.DefectResp">
select
<include refid="Base_Column_List"/>
from defect a
<select id="queryBySelective" resultType="com.dite.znpt.domain.vo.DefectListResp">
SELECT
d.defect_id, d.defect_name, d.defect_code, p.part_name, d.defect_position, d.description
FROM defect d
LEFT JOIN image i ON d.image_id = i.image_id
LEFT JOIN image_collect ic ON ic.collect_id = i.collect_id
LEFT JOIN part p ON ic.part_id = p.part_id
<where>
<if test="keyword != null and keyword != ''">
# and (a.defect_name like concat('%', #{keyword,jdbcType=VARCHAR}, '%') or a.defect_code like concat('%', #{keyword,jdbcType=VARCHAR}, '%'))
# AND (d.defect_name LIKE concat('%', #{keyword,jdbcType=VARCHAR}, '%') OR d.defect_code LIKE concat('%', #{keyword,jdbcType=VARCHAR}, '%'))
</if>
<if test="partId != null and partId != ''">
and a.part_id = #{turbineCode}
<if test="turbineId != null and turbineId != ''">
AND p.turbine_id = #{turbineId}
</if>
<if test="defectType != null and defectType != ''">
and a.defect_type = #{defectType}
AND d.defect_type = #{defectType}
</if>
<if test="defectLevel != null and defectLevel != ''">
and a.defect_level = #{defectLevel}
AND d.defect_level = #{defectLevel}
</if>
</where>
</select>
<select id="detail" resultType="com.dite.znpt.domain.vo.DefectResp">
SELECT
d.defect_id, d.defect_code, d.defect_name, d.defect_position, d.defect_type, d.defect_level, d.repair_status, d.detection_date, d.source,
d.chordwise, d.axial, d.area, d.label_info, d.description, d.description
FROM defect d
WHERE d.defect_id = #{defectId}
</select>
</mapper>

View File

@ -2,15 +2,5 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.dite.znpt.mapper.ImageCollectMapper">
<sql id="Base_Column_List">
a.collect_id, a.shooting_time_begin, a.shooting_time_end, a.weather, a.humidness, a.temperature_min, a.temperature_max, a.wind_level, a.shooting_method,
a.shooting_distance, a.collector_name,
</sql>
<select id="queryBySelective" resultType="com.dite.znpt.domain.vo.ImageCollectInfo">
select
<include refid="Base_Column_List"/>
from image_collect_info a
</select>
</mapper>

View File

@ -13,6 +13,9 @@
<if test="keyword != null and keyword != ''">
AND i.image_name LIKE concat('%', #{keyword}, '%')
</if>
<if test="turbineId != null and turbineId != ''">
AND p.turbine_id = #{turbineId}
</if>
<if test="imageTypes != null and imageTypes.length > 0">
AND i.image_type in <foreach collection="imageTypes" item="imageType" open="(" close=")" separator=",">#{imageType}</foreach>
</if>

View File

@ -3,6 +3,7 @@ package com.dite.znpt.web.controller;
import com.dite.znpt.domain.Constants;
import com.dite.znpt.domain.vo.DefectListReq;
import com.dite.znpt.domain.vo.DefectReq;
import com.dite.znpt.domain.vo.DefectResp;
import com.dite.znpt.domain.entity.DefectEntity;
import com.dite.znpt.service.DefectService;
@ -30,35 +31,41 @@ public class DefectController {
@Resource
private DefectService defectService;
@ApiOperation(value = "获取缺陷记录列表", httpMethod = "GET")
@GetMapping("/list")
public PageResult<DefectResp> list(DefectListReq defectReq) {
return PageResult.ok(defectService.selectList(defectReq));
@ApiOperation(value = "分页查询缺陷记录列表", httpMethod = "GET")
@GetMapping("/page")
public PageResult<DefectResp> page(@RequestBody DefectListReq req) {
return PageResult.ok(defectService.page(req));
}
@ApiOperation(value = "根据缺陷记录Id获取详细信息", httpMethod = "GET")
@GetMapping("/{defectId}")
public Result<DefectResp> getInfo(@PathVariable String defectId) {
return Result.ok(defectService.selectById(defectId));
@ApiOperation(value = "查询缺陷记录列表", httpMethod = "GET")
@GetMapping("/page")
public Result<List<DefectResp>> list(@RequestBody DefectListReq req) {
return Result.ok(defectService.list(req));
}
@ApiOperation(value = "查询缺详细", httpMethod = "GET")
@GetMapping("/detail/{defectId}")
public Result<DefectResp> detail(@PathVariable String defectId) {
return Result.ok(defectService.detail(defectId));
}
@ApiOperation(value = "新增缺陷记录", httpMethod = "POST")
@PostMapping
public Result<Object> add(@RequestBody DefectEntity defect) {
defectService.saveData(defect);
@PostMapping("/{imageId}")
public Result save(@PathVariable String imageId, @RequestBody DefectReq req) {
defectService.save(imageId, req);
return Result.ok();
}
@ApiOperation(value = "修改缺陷记录", httpMethod = "PUT")
@PutMapping
public Result<Object> edit(@RequestBody DefectEntity defect) {
defectService.updateData(defect);
@PutMapping("/{defectId}")
public Result edit(@PathVariable String defectId, @RequestBody DefectReq req) {
defectService.update(defectId, req);
return Result.ok();
}
@ApiOperation(value = "删除缺陷记录", httpMethod = "DELETE")
@DeleteMapping("/{defectId}")
public Result<Object> remove(@PathVariable String defectId) {
public Result remove(@PathVariable String defectId) {
defectService.deleteById(defectId);
return Result.ok();
}
@ -67,7 +74,7 @@ public class DefectController {
@GetMapping("/export")
@ResponseExcel(name = "缺陷记录")
public List<DefectResp> export(DefectListReq defectReq) {
return defectService.selectList(defectReq);
return defectService.page(defectReq);
}
@ApiOperation(value = "导入缺陷记录", httpMethod = "POST")