Bladeren bron

批量优化

guarantee-lsq 2 jaren geleden
bovenliggende
commit
355e79cab5

+ 1 - 0
platform-common/src/main/java/com/platform/common/constant/CommonConstants.java

@@ -296,4 +296,5 @@ public interface CommonConstants {
     String CHANGE_TYPE_SB_POSITION = "1"; // 设备位置变动
     String CHANGE_TYPE_SB_NO = "2"; // 设备位号变动
     String CHANGE_TYPE_SB_PARENT = "3"; // 父设备变动
+    String CHANGE_TYPE_SB_STATUS = "4"; // 设备状态变动
 }

+ 12 - 0
platform-dao/src/main/java/com/platform/dao/enums/SbInfoStatusEnum.java

@@ -83,4 +83,16 @@ public enum SbInfoStatusEnum {
         return list;
     }
 
+    //讲枚举转换成list格式,这样前台遍历的时候比较容易,列如 下拉框 后台调用toList方法,你就可以得到code 和name了
+    public static String getNameByValue(Integer value) {
+        String name = "";
+        for (SbInfoStatusEnum obj : SbInfoStatusEnum.values()) {
+            if(obj.getValue() == value){
+                name = obj.getName();
+                break;
+            }
+        }
+        return name;
+    }
+
 }

+ 62 - 44
platform-service/src/main/java/com/platform/service/sb/impl/SbChangeRecordServiceImpl.java

@@ -2,6 +2,7 @@ package com.platform.service.sb.impl;
 
 import com.github.pagehelper.PageHelper;
 import com.platform.common.bean.AbstractPageResultBean;
+import com.platform.common.constant.CommonConstants;
 import com.platform.common.util.IdGeneratorUtils;
 import com.platform.common.util.SecurityUtils;
 import com.platform.dao.bean.MyPage;
@@ -10,7 +11,6 @@ import com.platform.dao.dto.sb.SbChangeRecordDTO;
 import com.platform.dao.entity.sb.SbChangeRecord;
 import com.platform.dao.entity.sb.SbInfo;
 import com.platform.dao.entity.sb.SbLocation;
-import com.platform.dao.enums.SbChangeTypeEnum;
 import com.platform.dao.mapper.sb.SbChangeRecordMapper;
 import com.platform.dao.mapper.sb.SbInfoMapper;
 import com.platform.dao.mapper.sb.SbLocationMapper;
@@ -79,46 +79,61 @@ public class SbChangeRecordServiceImpl extends BaseServiceImpl<SbChangeRecordMap
      * @param model
      */
     private void handleSingle(SbChangeRecordDTO model){
-        StringBuilder remark = new StringBuilder();
+        StringBuilder remark1 = new StringBuilder();
+        StringBuilder remark2 = new StringBuilder();
         SbInfo sbInfo = sbInfoMapper.selectByPrimaryKey(model.getSbId());
         SbInfo tempInfo = new SbInfo();
         tempInfo.setId(sbInfo.getId());
         tempInfo.setPositionId(sbInfo.getPositionId());
-        boolean insetFlag = Boolean.FALSE;
-        if(model.getChangeType() == SbChangeTypeEnum.SB_CHANGE_SB_NO.getValue()){
-            String oldSbPositionNo = getPureString(sbInfo.getPositionNo()); // 原设备位号
-            String positionNo = getPureString(model.getSbNoId());
-            // 设备位号变动
-            if(!oldSbPositionNo.equals(positionNo)){
-                insetFlag = Boolean.TRUE;
-                remark.append("设备位号变动【"+oldSbPositionNo).append("】 ---> ");
-                remark.append("【"+positionNo+"】");
-                sbInfo.setPositionNo(positionNo); // 设备位号
-                // 位号变动,父设备也有可能变动
+        String oldSbPositionNo = getPureString(sbInfo.getPositionNo()); // 原设备位号
+        String positionNo = getPureString(model.getSbNoId()); // 设备位号
+        String oldPosition = StringUtils.isBlank(tempInfo.getPositionId()) ? "" : sbPositionMapper.selectNameById(tempInfo.getPositionId()); // 老设备位置
+        String position = StringUtils.isBlank(model.getPositionId()) ? "" : sbPositionMapper.selectNameById(model.getPositionId());  // 设备位置
+        // 设备位号变动
+        if(!oldSbPositionNo.equals(positionNo)){
+            remark1.append("设备位号变动【"+oldSbPositionNo).append("】 ---> ");
+            remark1.append("【"+positionNo+"】");
+            if(StringUtils.isNotBlank(sbInfo.getParentId())){
+                // 子设备判断,传输过来的位号,是否存在于sb_location
                 SbLocation location = new SbLocation();
                 location.setNo(positionNo);
-                List<SbLocation> locations = sbLocationMapper.select(location);
-                if(locations != null && locations.size() > 0){
-                    sbInfo.setParentId(locations.get(0).getSbId());
+                if(sbLocationMapper.selectCount(location) == 0){
+                    insertLocation(positionNo,sbInfo);
                 }
             }
-        }else if(model.getChangeType() == SbChangeTypeEnum.SB_CHANGE_SB_POSITION.getValue()){
-            String oldPosition = StringUtils.isBlank(tempInfo.getPositionId()) ? "" : sbPositionMapper.selectNameById(tempInfo.getPositionId());
-            String position = StringUtils.isBlank(model.getPositionId()) ? "" : sbPositionMapper.selectNameById(model.getPositionId());
-            // 设备位置变动
-            if(!oldPosition.equals(position)){
-                insetFlag = Boolean.TRUE;
-                sbInfo.setPositionId(model.getPositionId());
-                remark.append("设备位置变动【" + oldPosition).append("】 ---> ");
-                remark.append("【" + position + "】");
+            sbInfo.setPositionNo(positionNo); // 设备位号
+            // 位号变动,父设备也有可能变动
+            SbLocation location = new SbLocation();
+            location.setNo(positionNo);
+            List<SbLocation> locations = sbLocationMapper.select(location);
+            if(locations != null && locations.size() > 0){
+                sbInfo.setParentId(locations.get(0).getSbId());
             }
+            handleSbChangeRecord(remark1.toString(),model,tempInfo, CommonConstants.CHANGE_TYPE_SB_NO);
         }
-        if(insetFlag){
-            handleSbChangeRecord(remark.toString(),model,tempInfo,model.getChangeType());
+        // 设备位置变动
+        if(!oldPosition.equals(position)){
+            sbInfo.setPositionId(model.getPositionId());
+            remark2.append("设备位置变动【" + oldPosition).append("】 ---> ");
+            remark2.append("【" + position + "】");
+            handleSbChangeRecord(remark2.toString(),model,tempInfo,CommonConstants.CHANGE_TYPE_SB_POSITION);
         }
         sbInfoMapper.updateByPrimaryKey(sbInfo);
     }
 
+    private void insertLocation(String sbPositionNo,SbInfo sbInfo){
+        SbLocation location = new SbLocation();
+        location.setId(IdGeneratorUtils.getObjectId());
+        location.setNo(sbPositionNo);
+        location.setCreatedTime(LocalDateTime.now());
+        location.setCreatedUserId(SecurityUtils.getUserInfo().getUserId());
+        location.setCreatedUserName(SecurityUtils.getUserInfo().getUsername());
+        location.setLevel(sbInfo.getLevel());
+        location.setRepairDeptId(sbInfo.getRepairDeptId());
+        location.setSbId(sbInfo.getParentId());
+        sbLocationMapper.insert(location);
+    }
+
     /**
      * 存储变更记录
      * @param remark
@@ -126,30 +141,33 @@ public class SbChangeRecordServiceImpl extends BaseServiceImpl<SbChangeRecordMap
      * @param sb
      * @param type
      */
-    void handleSbChangeRecord(String remark, SbChangeRecordDTO model, SbInfo sb, Integer type){
+    void handleSbChangeRecord(String remark, SbChangeRecordDTO model, SbInfo sb, String type){
         SbChangeRecord record = new SbChangeRecord();
         record.setId(IdGeneratorUtils.getObjectId());
-        record.setChangeType(type);
+        record.setChangeType(Integer.parseInt(type));
         record.setContent(remark);
         record.setCreatedTime(LocalDateTime.now());
         record.setCreatedUserId(SecurityUtils.getUserInfo().getUserId());
         record.setCreatedUserName(SecurityUtils.getUserInfo().getUsername());
         record.setSbId(sb.getId());
-        if(type == SbChangeTypeEnum.SB_CHANGE_SB_NO.getValue()){
-            record.setSbNoId(model.getSbNoId());
-            record.setStartTime(LocalDateTime.now());
-            // 将之前位置编号的结束时间修正
-            SbChangeRecordDTO dto = new SbChangeRecordDTO();
-            dto.setChangeType(record.getChangeType());
-            dto.setSbNoId(model.getSbNoId());
-            SbChangeRecord oldRecord = mapper.getLastOne(dto);
-            if(oldRecord != null){
-                oldRecord.setEndTime(LocalDateTime.now());
-                mapper.updateByPrimaryKey(oldRecord);
-            }
-        }else if(type == SbChangeTypeEnum.SB_CHANGE_SB_POSITION.getValue()){
-            record.setOldPositionId(sb.getPositionId());
-            record.setPositionId(model.getPositionId());
+        switch (type){
+            case CommonConstants.CHANGE_TYPE_SB_NO:
+                record.setSbNoId(model.getSbNoId());
+                record.setStartTime(LocalDateTime.now());
+                // 将之前位置编号的结束时间修正
+                SbChangeRecordDTO dto = new SbChangeRecordDTO();
+                dto.setChangeType(record.getChangeType());
+                dto.setSbNoId(model.getSbNoId());
+                SbChangeRecord oldRecord = mapper.getLastOne(dto);
+                if(oldRecord != null){
+                    oldRecord.setEndTime(LocalDateTime.now());
+                    mapper.updateByPrimaryKey(oldRecord);
+                }
+                break;
+            case CommonConstants.CHANGE_TYPE_SB_POSITION:
+                record.setOldPositionId(sb.getPositionId());
+                record.setPositionId(model.getPositionId());
+                break;
         }
         mapper.insert(record);
     }

+ 112 - 79
platform-service/src/main/java/com/platform/service/sb/impl/SbMeasureLogServiceImpl.java

@@ -16,6 +16,7 @@ import com.platform.dao.entity.sb.SbInfo;
 import com.platform.dao.entity.sb.SbLocation;
 import com.platform.dao.entity.sb.SbMeasureLog;
 import com.platform.dao.entity.upms.SysFile;
+import com.platform.dao.enums.SbInfoStatusEnum;
 import com.platform.dao.enums.SbUseType;
 import com.platform.dao.enums.SysFileTypeEnum;
 import com.platform.dao.enums.YesNoEnum;
@@ -137,98 +138,128 @@ public class SbMeasureLogServiceImpl extends BaseServiceImpl<SbMeasureLogMapper,
     @Transactional(rollbackFor = Exception.class)
     @Override
     public SbMeasureLog saveModelByDTO(SbMeasureLogDTO model) {
-        model.setCheckUserId(SecurityUtils.getUserInfo().getUserId()); // 谁操作即是检定记录人
-        SbMeasureLog sbMeasureLog = super.saveModelByDTO(model);
-        model.setId(sbMeasureLog.getId());
         // 更新设备下次检定日期
         SbInfo sbInfo = sbInfoMapper.selectByPrimaryKey(model.getSbId());
         SbInfo tempInfo = new SbInfo();
         tempInfo.setId(sbInfo.getId());
-        tempInfo.setParentId(sbInfo.getParentId());
-        tempInfo.setPositionId(sbInfo.getPositionId());
-        if(sbInfo.getUseType().equals(SbUseType.BGCL.getValue())){
-            model.setType(1);
-        }else if(sbInfo.getUseType().equals(SbUseType.BGCL.getValue())){
-            model.setType(2);
-        }else{
-            throw new BusinessException("非计量和非特种的设备, 无需填报检定记录");
-        }
-        sbInfo.setCheckDate(model.getLastDate());
-        Integer checkPeriod = 0;// 默认12个月
-        if(model.getCheckPeriod() != null){
-            checkPeriod = model.getCheckPeriod();
+        // 判断设备状态,如果是在库,直接修改设备状态即可
+        if(model.getSbStatus() == 1){
+            sbInfo.setStatus(SbInfoStatusEnum.IN_STORE.getValue());
+            String remark = "设备状态由【"+SbInfoStatusEnum.getNameByValue(sbInfo.getStatus())+"】 ---> 【";
+            remark += "在库】";
+            handleSbChangeRecord(remark,model,tempInfo,CommonConstants.CHANGE_TYPE_SB_STATUS);
+            return null;
         }else{
-            throw new BusinessException("检定设备的检定周期未设置,无法计算下次检定日期,请先设置");
-        }
-        sbInfo.setNextCheckDate(model.getLastDate().minusMonths(-checkPeriod).minusDays(1));
-        sbInfo.setZaiz(model.getName());// 检定单位
-        sbInfo.setSbdh(model.getNo());// 检定编号
-        sbInfo.setRemark(model.getRemark());// 备注
-        sbInfo.setDph(model.getRequirement());// 检定人
-        sbInfo.setMeasureStatus(YesNoEnum.NO.getValue());// 每次检定后, 检定状态改为正常
-        sbInfo.setCheckPeriod(model.getCheckPeriod()); // 检定周期
-        // 设备位置变动
-        boolean insertAllocate = Boolean.FALSE; // 设备位置
-        boolean insertParent = Boolean.FALSE; // 父设备
-        boolean insertNo = Boolean.FALSE; // 设备位号
-        String oldPositionId = getPureString(sbInfo.getPositionId());
-        String oldParentId = getPureString(sbInfo.getParentId());
-        String positionId = getPureString(model.getSbPositionId());
-        String parentId = getPureString(model.getSbParentId());
-        String oldSbPositionNo = getPureString(sbInfo.getPositionNo()); // 设备位号
-        String positionNo = getPureString(model.getSbPositionNo());
-        StringBuilder remark1 = new StringBuilder();
-        StringBuilder remark2 = new StringBuilder();
-        StringBuilder remark3 = new StringBuilder();
-        if(!oldPositionId.equals(positionId)){
-            insertAllocate = Boolean.TRUE;
-            sbInfo.setPositionId(positionId);
-            String before = oldPositionId == "" ? oldPositionId : sbPositionMapper.selectNameById(oldPositionId);
-            remark1.append("设备位置变动【" + before).append("】 ---> ");
-            String after = positionId == "" ? positionId : sbPositionMapper.selectNameById(positionId);
-            remark1.append("【" + after + "】");
-        }
-        if(!oldParentId.equals(parentId)){
-            insertParent = Boolean.TRUE;
-            sbInfo.setParentId(parentId);
-            remark2.append("父设备变动【" + sbInfo.getName()).append("】 ---> ");
-            String after = parentId == "" ? parentId : sbInfoMapper.selectNameById(parentId);
-            remark2.append("【" + after + "】");
-        }
-        if(!oldSbPositionNo.equals(positionNo)){
-            insertNo = Boolean.TRUE;
-            remark3.append("设备位号变动【"+sbInfo.getPositionNo()).append("】 ---> ");
-            remark3.append("【"+positionNo+"】");
-            // 位号变动,父设备也有可能变动
-            SbLocation location = new SbLocation();
-            location.setNo(positionNo);
-            List<SbLocation> locations = sbLocationMapper.select(location);
-            if(locations != null && locations.size() > 0){
-                sbInfo.setParentId(locations.get(0).getSbId());
+            model.setCheckUserId(SecurityUtils.getUserInfo().getUserId()); // 谁操作即是检定记录人
+            SbMeasureLog sbMeasureLog = super.saveModelByDTO(model);
+            model.setId(sbMeasureLog.getId());
+            tempInfo.setParentId(sbInfo.getParentId());
+            tempInfo.setPositionId(sbInfo.getPositionId());
+            if(sbInfo.getUseType().equals(SbUseType.BGCL.getValue())){
+                model.setType(1);
+            }else if(sbInfo.getUseType().equals(SbUseType.BGCL.getValue())){
+                model.setType(2);
+            }else{
+                throw new BusinessException("非计量和非特种的设备, 无需填报检定记录");
             }
-            sbInfo.setPositionNo(model.getSbPositionNo()); // 设备位号
-        }
-        // 保存文件
-        sysFileService.saveFile(model.getId(), SysFileTypeEnum.Sb_MEASURE_IMGS.getValue(), model.getCheckImgList());
-        sysFileService.saveFile(model.getId(), SysFileTypeEnum.Sb_MEASURE_FILES.getValue(), model.getCheckFileList());
-        // 写入调拨记录
-        if(insertAllocate){
-            handleSbChangeRecord(remark1.toString(),model,tempInfo,CommonConstants.CHANGE_TYPE_SB_POSITION);
-        }
-        if(insertParent){
-            handleSbChangeRecord(remark2.toString(),model,tempInfo,CommonConstants.CHANGE_TYPE_SB_PARENT);
-        }
-        if(insertNo){
-            handleSbChangeRecord(remark3.toString(),model,tempInfo,CommonConstants.CHANGE_TYPE_SB_NO);
+            sbInfo.setCheckDate(model.getLastDate());
+            Integer checkPeriod = 0;// 默认12个月
+            if(model.getCheckPeriod() != null){
+                checkPeriod = model.getCheckPeriod();
+            }else{
+                throw new BusinessException("检定设备的检定周期未设置,无法计算下次检定日期,请先设置");
+            }
+            sbInfo.setNextCheckDate(model.getLastDate().minusMonths(-checkPeriod).minusDays(1));
+            sbInfo.setZaiz(model.getName());// 检定单位
+            sbInfo.setSbdh(model.getNo());// 检定编号
+            sbInfo.setRemark(model.getRemark());// 备注
+            sbInfo.setDph(model.getRequirement());// 检定人
+            sbInfo.setMeasureStatus(YesNoEnum.NO.getValue());// 每次检定后, 检定状态改为正常
+            sbInfo.setCheckPeriod(model.getCheckPeriod()); // 检定周期
+            // 设备位置变动
+            boolean insertAllocate = Boolean.FALSE; // 设备位置
+            boolean insertParent = Boolean.FALSE; // 父设备
+            boolean insertNo = Boolean.FALSE; // 设备位号
+            String oldPositionId = getPureString(sbInfo.getPositionId());
+            String oldParentId = getPureString(sbInfo.getParentId());
+            String positionId = getPureString(model.getSbPositionId());
+            String parentId = getPureString(model.getSbParentId());
+            String oldSbPositionNo = getPureString(sbInfo.getPositionNo()); // 设备位号
+            String positionNo = getPureString(model.getSbPositionNo());
+            StringBuilder remark1 = new StringBuilder();
+            StringBuilder remark2 = new StringBuilder();
+            StringBuilder remark3 = new StringBuilder();
+            if(!oldPositionId.equals(positionId)){
+                insertAllocate = Boolean.TRUE;
+                sbInfo.setPositionId(positionId);
+                String before = oldPositionId == "" ? oldPositionId : sbPositionMapper.selectNameById(oldPositionId);
+                remark1.append("设备位置变动【" + before).append("】 ---> ");
+                String after = positionId == "" ? positionId : sbPositionMapper.selectNameById(positionId);
+                remark1.append("【" + after + "】");
+            }
+            if(!oldParentId.equals(parentId)){
+                insertParent = Boolean.TRUE;
+                sbInfo.setParentId(parentId);
+                remark2.append("父设备变动【" + sbInfo.getName()).append("】 ---> ");
+                String after = parentId == "" ? parentId : sbInfoMapper.selectNameById(parentId);
+                remark2.append("【" + after + "】");
+            }
+            if(!oldSbPositionNo.equals(positionNo)){
+                if(StringUtils.isNotBlank(sbInfo.getParentId())){
+                    // 子设备判断,传输过来的位号,是否存在于sb_location
+                    SbLocation location = new SbLocation();
+                    location.setNo(positionNo);
+                    if(sbLocationMapper.selectCount(location) == 0){
+                        insertLocation(model.getSbPositionNo(),sbInfo);
+                    }
+                }
+                insertNo = Boolean.TRUE;
+                remark3.append("设备位号变动【"+sbInfo.getPositionNo()).append("】 ---> ");
+                remark3.append("【"+positionNo+"】");
+                // 位号变动,父设备也有可能变动
+                SbLocation location = new SbLocation();
+                location.setNo(positionNo);
+                List<SbLocation> locations = sbLocationMapper.select(location);
+                if(locations != null && locations.size() > 0){
+                    sbInfo.setParentId(locations.get(0).getSbId());
+                }
+                sbInfo.setPositionNo(model.getSbPositionNo()); // 设备位号
+            }
+            // 保存文件
+            sysFileService.saveFile(model.getId(), SysFileTypeEnum.Sb_MEASURE_IMGS.getValue(), model.getCheckImgList());
+            sysFileService.saveFile(model.getId(), SysFileTypeEnum.Sb_MEASURE_FILES.getValue(), model.getCheckFileList());
+            // 写入调拨记录
+            if(insertAllocate){
+                handleSbChangeRecord(remark1.toString(),model,tempInfo,CommonConstants.CHANGE_TYPE_SB_POSITION);
+            }
+            if(insertParent){
+                handleSbChangeRecord(remark2.toString(),model,tempInfo,CommonConstants.CHANGE_TYPE_SB_PARENT);
+            }
+            if(insertNo){
+                handleSbChangeRecord(remark3.toString(),model,tempInfo,CommonConstants.CHANGE_TYPE_SB_NO);
+            }
+            sbInfoMapper.updateByPrimaryKey(sbInfo);
+            return sbMeasureLog;
         }
-        sbInfoMapper.updateByPrimaryKey(sbInfo);
-        return sbMeasureLog;
     }
 
     private String getPureString(String info){
         return StringUtils.isBlank(info) ? "" : info;
     }
 
+    private void insertLocation(String sbPositionNo,SbInfo sbInfo){
+        SbLocation location = new SbLocation();
+        location.setId(IdGeneratorUtils.getObjectId());
+        location.setNo(sbPositionNo);
+        location.setCreatedTime(LocalDateTime.now());
+        location.setCreatedUserId(SecurityUtils.getUserInfo().getUserId());
+        location.setCreatedUserName(SecurityUtils.getUserInfo().getUsername());
+        location.setLevel(sbInfo.getLevel());
+        location.setRepairDeptId(sbInfo.getRepairDeptId());
+        location.setSbId(sbInfo.getParentId());
+        sbLocationMapper.insert(location);
+    }
+
     /**
      * 保存变更记录
      * @param remark
@@ -267,6 +298,8 @@ public class SbMeasureLogServiceImpl extends BaseServiceImpl<SbMeasureLogMapper,
                 record.setOldParentId(sb.getParentId());
                 record.setParentId(model.getSbParentId());
                 break;
+            case CommonConstants.CHANGE_TYPE_SB_STATUS:
+                break;
         }
         sbChangeRecordMapper.insert(record);
     }