diff --git a/detection/src/main/java/com/njcn/gather/device/mapper/mapping/PqDevMapper.xml b/detection/src/main/java/com/njcn/gather/device/mapper/mapping/PqDevMapper.xml index 7508a3d0..9682ce49 100644 --- a/detection/src/main/java/com/njcn/gather/device/mapper/mapping/PqDevMapper.xml +++ b/detection/src/main/java/com/njcn/gather/device/mapper/mapping/PqDevMapper.xml @@ -116,6 +116,12 @@ dev.Inspect_Date, dev.Harm_Sys_Id, dev.Import_Flag, + dev.Appearance, + dev.FunctionTest, + dev.Insulation, + dev.Communication, + dev.Delegate_Address, + dev.Engineering, dev.State, dev.Create_By, dev.Create_Time, diff --git a/detection/src/main/java/com/njcn/gather/device/pojo/param/PqDevParam.java b/detection/src/main/java/com/njcn/gather/device/pojo/param/PqDevParam.java index c59f4763..7fb486e8 100644 --- a/detection/src/main/java/com/njcn/gather/device/pojo/param/PqDevParam.java +++ b/detection/src/main/java/com/njcn/gather/device/pojo/param/PqDevParam.java @@ -137,6 +137,27 @@ public class PqDevParam { @ApiModelProperty("是否为导入设备") private Integer importFlag; + @ApiModelProperty("外观检查") + private String appearance; + + @ApiModelProperty("功能测试") + private String functionTest; + + @ApiModelProperty("绝缘性实验") + private String insulation; + + @ApiModelProperty("通讯功能测试") + private String communication; + + @ApiModelProperty("委托方地址") + private String delegateAddress; + + @ApiModelProperty("工程名称") + private String engineering; + + @ApiModelProperty("检测人") + private String checkBy; + @ApiModelProperty("设备图片") private List images; diff --git a/detection/src/main/java/com/njcn/gather/device/pojo/po/PqDev.java b/detection/src/main/java/com/njcn/gather/device/pojo/po/PqDev.java index a2a7f21a..3e5cdf1c 100644 --- a/detection/src/main/java/com/njcn/gather/device/pojo/po/PqDev.java +++ b/detection/src/main/java/com/njcn/gather/device/pojo/po/PqDev.java @@ -184,6 +184,42 @@ public class PqDev extends BaseEntity implements Serializable { */ private Integer importFlag; + /** + * 外观检查 + */ + @TableField("Appearance") + private String appearance; + + /** + * 功能测试 + */ + @TableField("FunctionTest") + private String functionTest; + + /** + * 绝缘性实验 + */ + @TableField("Insulation") + private String insulation; + + /** + * 通讯功能测试 + */ + @TableField("Communication") + private String communication; + + /** + * 委托方地址 + */ + @TableField("Delegate_Address") + private String delegateAddress; + + /** + * 工程名称 + */ + @TableField("Engineering") + private String engineering; + /** * 状态:0-删除 1-正常 */ diff --git a/detection/src/main/java/com/njcn/gather/device/pojo/vo/PqDevImageVO.java b/detection/src/main/java/com/njcn/gather/device/pojo/vo/PqDevImageVO.java index 3038d5cf..ec2a71df 100644 --- a/detection/src/main/java/com/njcn/gather/device/pojo/vo/PqDevImageVO.java +++ b/detection/src/main/java/com/njcn/gather/device/pojo/vo/PqDevImageVO.java @@ -14,4 +14,6 @@ public class PqDevImageVO { private String previewUrl; private String downloadUrl; + + private String path; } diff --git a/detection/src/main/java/com/njcn/gather/device/service/PqDevImageFileService.java b/detection/src/main/java/com/njcn/gather/device/service/PqDevImageFileService.java index 11c32c08..4a9d66bc 100644 --- a/detection/src/main/java/com/njcn/gather/device/service/PqDevImageFileService.java +++ b/detection/src/main/java/com/njcn/gather/device/service/PqDevImageFileService.java @@ -32,7 +32,7 @@ public class PqDevImageFileService { public static final int MAX_IMAGE_COUNT = 5; private static final Pattern UUID_JPG_FILE_NAME = Pattern.compile( - "^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\\.jpg$" + "^([0-9a-f]{32}|[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})\\.jpg$" ); private static final Pattern DEVICE_ID_PATTERN = Pattern.compile("^[A-Za-z0-9_-]{1,64}$"); private static final String INVALID_IMAGE_NAME = "图片文件名无效"; @@ -114,7 +114,7 @@ public class PqDevImageFileService { if (image == null || image.isEmpty()) { continue; } - String fileName = UUID.randomUUID().toString().toLowerCase(Locale.ROOT) + ".jpg"; + String fileName = UUID.randomUUID().toString().replace("-", "").toLowerCase(Locale.ROOT) + ".jpg"; Path path = imagePath(devId, fileName); writeImage(path, PqDevImageSupport.processUploadToJpeg(image)); savedImages.add(buildImageVO(devId, fileName)); @@ -242,7 +242,8 @@ public class PqDevImageFileService { return new PqDevImageVO( fileName, String.format(PREVIEW_URL, devId, fileName), - String.format(DOWNLOAD_URL, devId, fileName) + String.format(DOWNLOAD_URL, devId, fileName), + imagePath(devId, fileName).toString() ); } diff --git a/detection/src/main/java/com/njcn/gather/device/service/impl/PqDevServiceImpl.java b/detection/src/main/java/com/njcn/gather/device/service/impl/PqDevServiceImpl.java index 351f058a..ebbb1d68 100644 --- a/detection/src/main/java/com/njcn/gather/device/service/impl/PqDevServiceImpl.java +++ b/detection/src/main/java/com/njcn/gather/device/service/impl/PqDevServiceImpl.java @@ -18,6 +18,9 @@ import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.baomidou.mybatisplus.extension.conditions.update.LambdaUpdateChainWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.ObjectMapper; import com.github.yulichang.wrapper.MPJLambdaWrapper; import com.njcn.common.pojo.constant.PatternRegex; import com.njcn.common.pojo.enums.common.DataStateEnum; @@ -101,6 +104,7 @@ public class PqDevServiceImpl extends ServiceImpl implements private final IPqDevCheckHistoryService pqDevCheckHistoryService; private final RestTemplateUtil restTemplateUtil; private final PqDevImageFileService pqDevImageFileService; + private final ObjectMapper objectMapper; @Override public Page listPqDevs(PqDevParam.QueryParam queryParam) { @@ -161,6 +165,7 @@ public class PqDevServiceImpl extends ServiceImpl implements pqDevSub.setCheckState(CheckStateEnum.UNCHECKED.getValue()); pqDevSub.setReportState(DevReportStateEnum.UNCHECKED.getValue()); pqDevSub.setCheckResult(CheckResultEnum.UNCHECKED.getValue()); + pqDevSub.setCheckBy(pqDevParam.getCheckBy()); // 比对式设备添加监测点 if (PatternEnum.CONTRAST.getValue().equals(dictDataService.getDictDataById(pqDevParam.getPattern()).getCode())) { @@ -174,10 +179,47 @@ public class PqDevServiceImpl extends ServiceImpl implements boolean saved = this.save(pqDev); if (saved) { saveAddImages(id, pqDevParam.getImages()); + syncAppearanceSamplePhotos(id, pqDev); } return saved; } + private String rebuildAppearanceSamplePhotos(String appearanceJson, List images) { + Map appearance = new LinkedHashMap<>(); + if (StrUtil.isNotBlank(appearanceJson)) { + try { + appearance.putAll(objectMapper.readValue(appearanceJson, new TypeReference>() { + })); + } catch (JsonProcessingException e) { + throw new BusinessException(CommonResponseEnum.FAIL, "Appearance JSON格式错误"); + } + } + if (!appearance.containsKey("rows")) { + appearance.put("rows", Collections.emptyList()); + } + List> samplePhotos = images.stream().map(image -> { + Map samplePhoto = new LinkedHashMap<>(); + samplePhoto.put("fileName", image.getFileName()); + samplePhoto.put("path", image.getPath()); + return samplePhoto; + }).collect(Collectors.toList()); + appearance.put("samplePhotos", samplePhotos); + try { + return objectMapper.writeValueAsString(appearance); + } catch (JsonProcessingException e) { + throw new BusinessException(CommonResponseEnum.FAIL, "Appearance JSON保存失败"); + } + } + + private void syncAppearanceSamplePhotos(String devId, PqDev pqDev) { + List images = pqDevImageFileService.listImages(devId); + pqDev.setAppearance(rebuildAppearanceSamplePhotos(pqDev.getAppearance(), images)); + this.lambdaUpdate() + .set(PqDev::getAppearance, pqDev.getAppearance()) + .eq(PqDev::getId, devId) + .update(); + } + private void validateAddImages(List images) { try { pqDevImageFileService.validateAddCount(images); @@ -270,7 +312,12 @@ public class PqDevServiceImpl extends ServiceImpl implements } boolean updated = this.updateById(pqDev); if (updated) { + pqDevSubService.lambdaUpdate() + .set(PqDevSub::getCheckBy, updateParam.getCheckBy()) + .eq(PqDevSub::getDevId, updateParam.getId()) + .update(); saveUpdateImages(updateParam); + syncAppearanceSamplePhotos(updateParam.getId(), pqDev); } return updated; } @@ -624,6 +671,8 @@ public class PqDevServiceImpl extends ServiceImpl implements if (CollUtil.isNotEmpty(ids)) { list.addAll(this.baseMapper.listByDevIds(ids)); } + SysUser user = StrUtil.isNotBlank(userId) ? userService.getById(userId) : null; + String checkByName = ObjectUtil.isNotNull(user) ? user.getName() : null; for (PqDevVO pqDevVo : list) { if (result.containsKey(pqDevVo.getId())) { @@ -631,7 +680,7 @@ public class PqDevServiceImpl extends ServiceImpl implements int i; LambdaUpdateWrapper wrapper = new LambdaUpdateWrapper() .set(PqDevSub::getCheckResult, result.get(pqDevVo.getId())) - .set(StrUtil.isNotBlank(userId), PqDevSub::getCheckBy, userId) + .set(StrUtil.isBlank(pqDevVo.getCheckBy()) && StrUtil.isNotBlank(checkByName), PqDevSub::getCheckBy, checkByName) .set(updateCheckNum && SourceOperateCodeEnum.ALL_TEST.getValue().equals(FormalTestManager.reCheckType), PqDevSub::getCheckEndTime, LocalDateTime.now()) .set(updateCheckNum && SourceOperateCodeEnum.ALL_TEST.getValue().equals(FormalTestManager.reCheckType) && ObjectUtil.isNotNull(FormalTestManager.checkStartTime), PqDevSub::getCheckStartTime, FormalTestManager.checkStartTime) .eq(PqDevSub::getDevId, pqDevVo.getId()); @@ -738,7 +787,7 @@ public class PqDevServiceImpl extends ServiceImpl implements w.set(ObjectUtil.isNotNull(FormalTestManager.checkStartTime), PqDevSub::getCheckStartTime, currentDevSub.getCheckStartTime()); } - if (ObjectUtil.isNotNull(user)) { + if (ObjectUtil.isNotNull(user) && (currentDevSub == null || StrUtil.isBlank(currentDevSub.getCheckBy()))) { w.set(PqDevSub::getCheckBy, user.getName()); } if (checkState.equals(CheckStateEnum.CHECKED.getValue())) {