lvy 1 місяць тому
батько
коміт
f008636b3f

+ 1 - 0
blade-service-api/blade-business-api/src/main/java/org/springblade/business/dto/TrialSeleInspectionRecordInfoDTO.java

@@ -78,5 +78,6 @@ public class TrialSeleInspectionRecordInfoDTO extends TrialSeleInspectionRecordB
 		private Long id;
 		@ApiModelProperty("name")
 		private String name;
+		private List<StandardVo> info;
 	}
 }

+ 28 - 13
blade-service/blade-business/src/main/java/org/springblade/business/controller/TrialDetectionController.java

@@ -600,7 +600,7 @@ public class TrialDetectionController extends BladeController {
                     List<TrialSelfSample> selfSampleList = jdbcTemplate.query("select * from u_trial_self_sample where self_id = " + id, new BeanPropertyRowMapper<>(TrialSelfSample.class));
                     if (!selfSampleList.isEmpty()) {
                         String samplingIds = selfSampleList.stream().map(TrialSelfSample::getSamplingId).map(String::valueOf).collect(Collectors.joining(","));
-                        if (samplingIds != null && !"".equals(samplingIds)) {
+                        if (!samplingIds.isEmpty()) {
                             List<TrialSampleInfo> trialSampleInfoList = jdbcTemplate.query("select * from u_trial_sample_info where id in (" + samplingIds + ")", new BeanPropertyRowMapper<>(TrialSampleInfo.class));
                             vo.setTrialSampleInfo(trialSampleInfoList.isEmpty() ? new TrialSampleInfo() : trialSampleInfoList.get(0));
                         }
@@ -612,21 +612,36 @@ public class TrialDetectionController extends BladeController {
                 vo.setStandardId(record.getStandardId());
                 vo.setStandardInfoIds(record.getStandardInfoIds());
                 if (record.getStandardInfoIds() != null && !record.getStandardInfoIds().isEmpty()) {
-                    List<StandardInfo> standardInfoList = jdbcTemplate.query("select * from u_standard_info where id in (" + record.getStandardInfoIds() + ")", new BeanPropertyRowMapper<>(StandardInfo.class));
+                    List<StandardInfo> standardInfoList = jdbcTemplate.query("select id,parent_id,name from u_standard_info where id in (" + record.getStandardInfoIds() + ")", new BeanPropertyRowMapper<>(StandardInfo.class));
                     if (!standardInfoList.isEmpty()) {
-                        Set<Long> ids = standardInfoList.stream().map(StandardInfo::getParentId).collect(Collectors.toSet());
-                        List<StandardInfo> parentStandardInfoList = jdbcTemplate.query("select * from u_standard_info where id in (" + org.apache.commons.lang.StringUtils.join(ids, ",") + ")", new BeanPropertyRowMapper<>(StandardInfo.class));
+                        String ids = standardInfoList.stream().map(info -> info.getParentId() + "").distinct().collect(Collectors.joining(","));
+                        List<StandardInfo> allStandardInfoList = jdbcTemplate.query("select id,parent_id,name from u_standard_info where id in (" + ids + ") UNION select id,parent_id,name from u_standard_info where parent_id in ( " + ids + " )", new BeanPropertyRowMapper<>(StandardInfo.class));
                         Map<Long, List<StandardInfo>> map = standardInfoList.stream().collect(Collectors.groupingBy(StandardInfo::getParentId));
-                        List<TrialSeleInspectionRecordInfoDTO.StandardVo> standardVos = new ArrayList<>();
-                        parentStandardInfoList.forEach(standardInfo -> {
-                            TrialSeleInspectionRecordInfoDTO.StandardVo standardVo = new TrialSeleInspectionRecordInfoDTO.StandardVo();
-                            List<StandardInfo> list = map.get(standardInfo.getId());
-                            if (list != null && !list.isEmpty()) {
-                                standardVo.setId(list.get(0).getId());
-                                standardVo.setName(standardInfo.getName());
-                                standardVos.add(standardVo);
+                        Map<Long, List<StandardInfo>> allStandardInfoMap = allStandardInfoList.stream().peek(standardInfo -> {
+                            if (standardInfo.getParentId() == null) {
+                                standardInfo.setParentId(0L);
                             }
-                        });
+                        }).collect(Collectors.groupingBy(StandardInfo::getParentId));
+                        List<TrialSeleInspectionRecordInfoDTO.StandardVo> standardVos = new ArrayList<>();
+                        List<StandardInfo> parentStandardInfos = allStandardInfoMap.get(0L);
+                        if (parentStandardInfos != null && !parentStandardInfos.isEmpty()) {
+                            parentStandardInfos.forEach(standardInfo -> {
+                                TrialSeleInspectionRecordInfoDTO.StandardVo standardVo = new TrialSeleInspectionRecordInfoDTO.StandardVo();
+                                List<StandardInfo> list = map.get(standardInfo.getId());
+                                if (list != null && !list.isEmpty()) {
+                                    standardVo.setId(list.get(0).getId());
+                                    standardVo.setName(standardInfo.getName());
+                                    List<StandardInfo> standardInfos = allStandardInfoMap.get(standardInfo.getId());
+                                    standardVo.setInfo(standardInfos.stream().map(info -> {
+                                        TrialSeleInspectionRecordInfoDTO.StandardVo standardVo1 = new TrialSeleInspectionRecordInfoDTO.StandardVo();
+                                        standardVo1.setId(info.getId());
+                                        standardVo1.setName(info.getName());
+                                        return standardVo1;
+                                    }).collect(Collectors.toList()));
+                                    standardVos.add(standardVo);
+                                }
+                            });
+                        }
                         vo.setStandardInfos(standardVos);
                     }
                 }

+ 81 - 7
blade-service/blade-business/src/main/java/org/springblade/business/service/impl/TrialSelfInspectionRecordServiceImpl.java

@@ -2124,16 +2124,37 @@ public class TrialSelfInspectionRecordServiceImpl extends BaseServiceImpl<TrialS
     public Long saveBaseInfo(TrialSeleInspectionRecordInfoDTO dto) {
         TrialSelfInspectionRecord record = new TrialSelfInspectionRecord();
         BeanUtil.copyProperties(dto, record);
+        if (record.getEntrustId() == null) {
+            record.setEntrustId(0L);
+        }
+        TrialSelfInspectionRecord oldRecord = null;
+        EntrustInfo oldEntrustInfo = null;
+        TrialSampleInfo oldTrialSampleInfo = null;
+        if (dto.getId() != null) {
+            oldRecord = baseMapper.selectById(dto.getId());
+            if (oldRecord != null) {
+                if (oldRecord.getTaskStatus() != null && !oldRecord.getTaskStatus().equals("未上报") && !oldRecord.getTaskStatus().isEmpty()) {
+                    throw new ServiceException("当前试验已上报,请勿修改");
+                }
+                if (oldRecord.getEntrustId() != null) {
+                    oldEntrustInfo = entrustInfoMapper.selectById(oldRecord.getEntrustId());
+                }
+                try {
+                    if (oldRecord.getBaseInfo() != null && !oldRecord.getBaseInfo().isEmpty()) {
+                        TrialSeleInspectionRecordBaseInfoDTO baseInfo = JSONObject.parseObject(oldRecord.getBaseInfo(), TrialSeleInspectionRecordBaseInfoDTO.class);
+                        if (baseInfo != null) {
+                            oldTrialSampleInfo = baseInfo.getTrialSampleInfo();
+                        }
+                    }
+                } catch (Exception e) {
+                    e.printStackTrace();
+                }
+            }
+        }
         TrialSeleInspectionRecordBaseInfoDTO baseInfo = new TrialSeleInspectionRecordBaseInfoDTO();
         BeanUtil.copyProperties(dto, baseInfo);
-        record.setBaseInfo(JSON.toJSONString(baseInfo));
-        if (record.getId() == null) {
-            this.save(record);
-        } else {
-            this.updateById(record);
-        }
         EntrustInfo entrustInfo = null;
-        if (record.getEntrustId() != null) {
+        if (record.getEntrustId() != null && record.getEntrustId() > 0) {
             entrustInfo = entrustInfoMapper.selectById(record.getEntrustId());
         }
         List<TrialSampleInfo> trialSampleInfoList = dto.getTrialSampleInfoList();
@@ -2151,6 +2172,46 @@ public class TrialSelfInspectionRecordServiceImpl extends BaseServiceImpl<TrialS
                 }
             }
         }
+        if ((entrustInfo == null && oldEntrustInfo != null) && info != null) {
+            // 判断是否关联,如果关联一起取消
+            if (oldEntrustInfo.getSampleId() != null && oldEntrustInfo.getSampleId().equals(info.getId())) {
+                //删除关联
+                baseMapper.delSelfSample(record.getId());
+                info = null;
+                baseInfo.setTrialSampleInfo(null);
+            }
+        }
+        if (entrustInfo != null && info == null && oldTrialSampleInfo != null) {
+            if (entrustInfo.getSampleId() != null && entrustInfo.getSampleId().equals(oldTrialSampleInfo.getId())) {
+                record.setEntrustId(null);
+                baseInfo.setEntrustId( null);
+                baseInfo.setEntrustNo(null);
+            }
+        }
+        boolean a=true;
+        boolean b=true;
+        record.setBaseInfo(JSON.toJSONString(baseInfo));
+        if (oldRecord == null) {
+            if(StringUtils.isNotEmpty(record.getRecordNo())){
+                if(StringUtils.isNotEmpty(record.getRecordNo())){
+                    a= trialNumberRuleService.checkTrialNumberIsExist(record.getRecordNo(), 4);
+                }
+            }
+            if(StringUtils.isNotEmpty(record.getRecordNo())){
+                if(StringUtils.isNotEmpty(record.getReportNo())){
+                    b= trialNumberRuleService.checkTrialNumberIsExist(record.getReportNo(), 5);
+                }
+            }
+            if(!a){
+                throw new ServiceException("记录编号已存在");
+            }
+            if(!b){
+                throw new ServiceException("报告编号已存在");
+            }
+            this.save(record);
+        } else {
+            this.updateById(record);
+        }
         if (info != null) {
             TrialSampleInfo sampleInfo = trialSampleInfoMapper.selectById(info.getId());
             if (sampleInfo != null) {
@@ -2227,6 +2288,19 @@ public class TrialSelfInspectionRecordServiceImpl extends BaseServiceImpl<TrialS
             recordDTO.setTrialUserName(AuthUtil.getUserName());
             this.trialDeviceUseService.addDeviceUseInfo(recordDTO, record.getId());
         }
+            if(dto.getOldRecordNumber()!=null&&dto.getOldRecordNumber().equals(dto.getRecordNo())){
+                if(StringUtils.isNotEmpty(dto.getRecordAutoNumber())){
+                    trialNumberRuleService.checkSave(dto.getContractId(),4,record.getId(),dto.getRecordAutoNumber());
+                    bladeRedis.del("trialAutoNumber:" + dto.getContractId() + ":" + 4 + ":" + record.getNodeId() + ":" + "lock:" + dto.getRecordAutoNumber());
+                }
+            }
+            if(dto.getOldReportNumber()!=null&&dto.getOldReportNumber().equals(dto.getReportNo())){
+                if(StringUtils.isNotEmpty(dto.getReportAutoNumber())){
+                    trialNumberRuleService.checkSave(dto.getContractId(),5,record.getId(),dto.getReportAutoNumber());
+                    bladeRedis.del("trialAutoNumber:" + dto.getContractId() + ":" + 5 + ":" + record.getNodeId() + ":" + "lock:" + dto.getReportAutoNumber());
+                }
+            }
+
         return record.getId();
     }