Просмотр исходного кода

试验保存基础信息返回试验记录id

lvy 1 месяц назад
Родитель
Сommit
b5b26d6c04

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

@@ -65,6 +65,10 @@ public class TrialSeleInspectionRecordInfoDTO extends TrialSeleInspectionRecordB
 	@ApiModelProperty("设备信息和使用信息")
 	private List<TrailDeviceUseInfoDTO> trailDeviceUseInfoDTOS;
 
+
+	@ApiModelProperty("样品信息")
+	private List<TrialSampleInfo> trialSampleInfoList;
+
 	@Data
 	public static class StandardVo {
 		@ApiModelProperty("id")

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

@@ -664,8 +664,8 @@ public class TrialDetectionController extends BladeController {
     @PostMapping("/self/saveBaseInfo")
     @ApiOperationSupport(order = 30)
     @ApiOperation(value = "保存试验自检基础信息")
-    public R<Boolean> saveBaseInfo(@RequestBody TrialSeleInspectionRecordInfoDTO vo) {
-        return R.status(iTrialSelfInspectionRecordService.saveBaseInfo(vo));
+    public R<Long> saveBaseInfo(@RequestBody TrialSeleInspectionRecordInfoDTO vo) {
+        return R.data(iTrialSelfInspectionRecordService.saveBaseInfo(vo));
     }
 
     /**

+ 1 - 1
blade-service/blade-business/src/main/java/org/springblade/business/service/ITrialSelfInspectionRecordService.java

@@ -47,5 +47,5 @@ public interface ITrialSelfInspectionRecordService extends BaseService<TrialSelf
 
     R getSamplePdfUrl(String id,String contrctId);
 
-    Boolean saveBaseInfo(TrialSeleInspectionRecordInfoDTO vo);
+    Long saveBaseInfo(TrialSeleInspectionRecordInfoDTO vo);
 }

+ 49 - 23
blade-service/blade-business/src/main/java/org/springblade/business/service/impl/TrialSelfInspectionRecordServiceImpl.java

@@ -2087,40 +2087,66 @@ public class TrialSelfInspectionRecordServiceImpl extends BaseServiceImpl<TrialS
     }
 
     @Override
-    public Boolean saveBaseInfo(TrialSeleInspectionRecordInfoDTO dto) {
+    public Long saveBaseInfo(TrialSeleInspectionRecordInfoDTO dto) {
         TrialSelfInspectionRecord record = new TrialSelfInspectionRecord();
         BeanUtil.copyProperties(dto, record);
         TrialSeleInspectionRecordBaseInfoDTO baseInfo = new TrialSeleInspectionRecordBaseInfoDTO();
         BeanUtil.copyProperties(dto, baseInfo);
         record.setBaseInfo(JSON.toJSONString(baseInfo));
-        this.saveOrUpdate(record);
-        TrialSampleInfo trialSampleInfo = dto.getTrialSampleInfo();
-        if (trialSampleInfo != null) {
-            TrialSampleInfo sampleInfo = trialSampleInfoMapper.selectById(trialSampleInfo.getId());
-            if (sampleInfo != null) {
-                //------关联取样信息------
-                RecordSampleSubmitDTO sampleSubmitDTO = new RecordSampleSubmitDTO();
-                sampleSubmitDTO.setId(record.getId());
-                sampleSubmitDTO.setSampleIds(trialSampleInfo.getId() + "");
-                //删除关联
-                baseMapper.delSelfSample(record.getId());
-                baseMapper.saveSelfSample(SnowFlakeUtil.getId(), record.getId(), trialSampleInfo.getId() + "");
-                //更新
-                this.update(Wrappers.<TrialSelfInspectionRecord>lambdaUpdate()
-                        .set(sampleInfo.getSamplingLocation() != null && !sampleInfo.getSamplingLocation().isEmpty(),TrialSelfInspectionRecord::getSamplingLocation, sampleInfo.getSamplingLocation())
-                        .set(sampleInfo.getCalculationUnit() != null && !sampleInfo.getCalculationUnit().isEmpty(), TrialSelfInspectionRecord::getCompany, sampleInfo.getCalculationUnit())
-                        .set(trialSampleInfo.getSpecificationNumber() != null && !trialSampleInfo.getSpecificationNumber().isEmpty(), TrialSelfInspectionRecord::getSpecificationNumber, trialSampleInfo.getSpecificationNumber())
-                        .set(sampleInfo.getSpecificationModel() != null && !sampleInfo.getSpecificationModel().isEmpty(), TrialSelfInspectionRecord::getSpecificationModel, sampleInfo.getSpecificationModel())
-                        .eq(TrialSelfInspectionRecord::getId, sampleSubmitDTO.getId())
-                );
-            }
+        if (record.getId() == null) {
+            this.save(record);
+        } else {
+            this.updateById(record);
+        }
+        List<TrialSampleInfo> trialSampleInfoList = dto.getTrialSampleInfoList();
+        TrialSampleInfo info = dto.getTrialSampleInfo();
+        if (trialSampleInfoList == null) {
+            trialSampleInfoList = new ArrayList<>();
+        }
+        if (info != null) {
+            trialSampleInfoList.add(info);
+        }
+        if (!trialSampleInfoList.isEmpty()) {
+            List<TrialSampleInfo> trialSampleInfos = new ArrayList<>();
+            trialSampleInfoList.forEach(trialSampleInfo -> {
+                TrialSampleInfo sampleInfo = trialSampleInfoMapper.selectById(trialSampleInfo.getId());
+                if (sampleInfo != null) {
+                    //------关联取样信息------
+                    RecordSampleSubmitDTO sampleSubmitDTO = new RecordSampleSubmitDTO();
+                    sampleSubmitDTO.setId(record.getId());
+                    sampleSubmitDTO.setSampleIds(trialSampleInfo.getId() + "");
+                    //删除关联
+                    baseMapper.delSelfSample(record.getId());
+                    baseMapper.saveSelfSample(SnowFlakeUtil.getId(), record.getId(), trialSampleInfo.getId() + "");
+                    trialSampleInfos.add(sampleInfo);
+                }
+            });
+            List<String> samplingLocations = trialSampleInfos.stream().map(TrialSampleInfo::getSamplingLocation).filter(string -> string !=null && !string.isEmpty()).collect(Collectors.toList());
+            String samplingLocation = org.apache.commons.lang.StringUtils.join(samplingLocations, "、");
+
+            List<String> calculationUnits = trialSampleInfos.stream().map(TrialSampleInfo::getCalculationUnit).filter(string -> string !=null && !string.isEmpty()).collect(Collectors.toList());
+            String calculationUnit = org.apache.commons.lang.StringUtils.join(calculationUnits, "、");
+
+            List<String> specificationNumbers = trialSampleInfoList.stream().map(TrialSampleInfo::getSpecificationNumber).filter(string -> string !=null && !string.isEmpty()).collect(Collectors.toList());
+            String specificationNumber = org.apache.commons.lang.StringUtils.join(specificationNumbers, "、");
+
+            List<String> specificationModels = trialSampleInfos.stream().map(TrialSampleInfo::getSpecificationModel).filter(string -> string !=null && !string.isEmpty()).collect(Collectors.toList());
+            String specificationModel = org.apache.commons.lang.StringUtils.join(specificationModels, "、");
+
+            //更新
+            this.update(Wrappers.<TrialSelfInspectionRecord>lambdaUpdate()
+                    .set(samplingLocation != null && !samplingLocation.isEmpty(), TrialSelfInspectionRecord::getSamplingLocation, samplingLocation)
+                    .set(calculationUnit != null && !calculationUnit.isEmpty(),TrialSelfInspectionRecord::getCompany, calculationUnit)
+                    .set(specificationNumber != null && !specificationNumber.isEmpty(),TrialSelfInspectionRecord::getSpecificationNumber, specificationNumber)
+                    .set(specificationModel != null && !specificationModel.isEmpty(),TrialSelfInspectionRecord::getSpecificationModel, specificationModel)
+                    .eq(TrialSelfInspectionRecord::getId, dto.getId()));
         }
         // ---- 修改样品单号信息 --------
         if(Func.isNotEmpty(dto.getEntrustId())){
             //修改项目节点基础信息
             jdbcTemplate.update("update u_entrust_info set sample_status=4 where id ='"+dto.getEntrustId()+"'");
         }
-        return true;
+        return record.getId();
     }