1 rok temu
rodzic
commit
c15c57c60c

+ 6 - 0
platform-dao/src/main/java/com/platform/dao/vo/export/sb/ExportYiBiaoSbInfoVO.java

@@ -92,6 +92,12 @@ public class ExportYiBiaoSbInfoVO implements Serializable {
     @Excel(name = "是否强检1:强检,2:非强检")
     private Integer checkType;
 
+//    /**
+//     * 预警天数
+//     */
+//    @Excel(name = "预警天数")
+//    private Integer seatNumber;
+
     /**
      * 备注
      */

+ 2 - 2
platform-rest/src/main/java/com/platform/rest/controller/sb/SbInfoController.java

@@ -529,10 +529,10 @@ public class SbInfoController {
 
     @SysLog("新增导入设备")
     @PostMapping("/import2")
-    public R importExcelByUpdate2(@RequestParam("type") Integer type, @RequestParam("file") MultipartFile file) throws Exception {
+    public R importExcelByUpdate2(@RequestParam("type") Integer type, @RequestParam("file") MultipartFile file,@RequestParam("typeFlag") Integer typeFlag) throws Exception {
         String result = "";
         if(type == 1){
-            result = sbInfoService.importListByAdd(file);
+            result = sbInfoService.importListByAdd2(file,typeFlag);
         }else if(type == 2){
             result = sbInfoService.importYiBiaoListByUpdateALl(file);
         }else if(type == 3){// 废弃

+ 1 - 0
platform-service/src/main/java/com/platform/service/sb/SbInfoService.java

@@ -287,6 +287,7 @@ public interface SbInfoService extends IBaseService<SbInfo, SbInfoDTO> {
     String importListByAddWithStandard(MultipartFile file);
 
     String importListByAdd(MultipartFile file);
+    String importListByAdd2(MultipartFile file,Integer typeFlag);
     String importListByUpdateALl(MultipartFile file);
 
     String importYiBiaoListByUpdateALl(MultipartFile file);

+ 196 - 0
platform-service/src/main/java/com/platform/service/sb/impl/SbInfoServiceImpl.java

@@ -2613,6 +2613,202 @@ public class SbInfoServiceImpl extends BaseServiceImpl<SbInfoMapper, SbInfo, SbI
         }
     }
 
+    @Override
+    public String importListByAdd2(MultipartFile file,Integer typeFlag) {
+        List<FirmProducer> producerList = firmProducerMapper.selectAll(); // 生产厂商
+        List<SbPosition> positionList = sbPositionMapper.selectAll(); // 设备位置
+        List<SbType> typeList = sbTypeMapper.selectAll(); // 设备类型集合
+        List<SbInfo> addList = new ArrayList<>();  // 待导入集合
+        List<SysUser> users = sysUserMapper.selectAll(); // 用户集合
+        List<String> addTypeList = new ArrayList<>();
+        try {
+            List<ExportYiBiaoSbInfoVO> list = ExcelUtil.importExcel(file.getInputStream(), ExportYiBiaoSbInfoVO.class, 1);
+            if (CollectionUtil.isNotEmpty(list)) {
+                int i = 2;
+                for (ExportYiBiaoSbInfoVO vo : list) {
+                    i++;
+                    // 如果有检定周期,就是需要检定
+                    SbInfo tempInfo = BeanConverterUtil.copyObjectProperties(vo, SbInfo.class);
+//                    if (vo.getSeatNumber()==null){
+//                        tempInfo.setSeatNumber(30);
+//                    }
+                    // 对必填字段进行判断
+                    if (StringUtils.isBlank(vo.getPositionName())) {
+                        throw new BusinessException("第" + i + "行,车间为空,车间为必填项目,请填写;");// 编号为空,复制位号
+                    }
+
+                    if (StringUtils.isBlank(vo.getModel())) {
+                        throw new BusinessException("第" + i + "行,规格、型号为空,请填写;");// 编号为空,复制位号
+                    }
+                    if (StringUtils.isBlank(vo.getProducerId())) {
+                        throw new BusinessException("第" + i + "行,厂牌为空,请填写;");// 编号为空,复制位号
+                    }
+                    if (StringUtils.isBlank(vo.getZzh())) {
+                        throw new BusinessException("第" + i + "行,出厂编号为空,请填写;");// 编号为空,复制位号
+                    }
+
+//                    if (vo.getUseType() == 4) {
+//                        tempInfo.setIsChild(1);
+//                    }
+//                    if (vo.getUseType() != 4) {
+//                        tempInfo.setIsChild(0);
+//                    }
+//                    if (vo.getStatus() == null || (vo.getStatus() != 1 && vo.getStatus() != 2 && vo.getStatus() != 7)) {
+//                        throw new BusinessException("第" + i + "行,状态为空或者状态不对,在库请填1,使用中填2,停用中填7");// 编号为空,复制位号
+//                    }
+//                    if (StringUtils.isBlank(vo.getNo())) {
+//                        tempInfo.setNo(vo.getPositionNo());// 编号为空,复制位号
+//                    }
+//                    if (StringUtils.isNotEmpty(vo.getPpNo())) {
+//                        tempInfo.setIsChild(1);
+//                    }
+//                    if (StringUtils.isNotEmpty(vo.getFinancingNo())) {
+//                        tempInfo.setIsFinancing(1);
+//                    }
+//                    if (vo.getCheckPeriod() != null) {
+//                        tempInfo.setIsMeasure(1);
+//                    }
+//                    if (vo.getUseType() == 5) {// 特种设备全部需要检定
+//                        tempInfo.setIsMeasure(1);
+//                    }
+//                    if (tempInfo.getIsMeasure() != null && tempInfo.getIsMeasure() == 1) {
+//                        if (tempInfo.getNextCheckDate() == null) {
+//                            if (tempInfo.getCheckDate() != null) {
+//                                if (tempInfo.getCheckPeriod() != null) {
+//                                    tempInfo.setNextCheckDate(tempInfo.getCheckDate().plusMonths(tempInfo.getCheckPeriod()));
+//                                } else {
+//                                    throw new BusinessException("需要检定的设备,检定周期必填");
+//                                }
+//                            } else {
+//                                throw new BusinessException("需要检定的设备,检定日期必填");
+//                            }
+//                        }
+//
+//                        // 如果是仪表组,则是自检
+//                        if (StringUtils.isNotEmpty(vo.getDph()) && vo.getDph().equals("仪表组")) {
+//                            tempInfo.setIsSelf(YesNoEnum.YES.getValue());
+//                        } else {
+//                            tempInfo.setIsSelf(YesNoEnum.NO.getValue());
+//                        }
+//                    }
+//                    if (StringUtils.isNotBlank(vo.getTypeName())) { // 设备类型匹配
+//                        boolean findSbType = false;
+//                        for (SbType sbType : typeList) {
+//                            if (sbType.getName().equalsIgnoreCase(vo.getTypeName().trim())) {
+//                                tempInfo.setTypeId(sbType.getId());
+//                                findSbType = true;
+//                                break;
+//                            }
+//                        }
+//                        if (!findSbType) {
+//                            addTypeList.add(vo.getTypeName());
+//                            // throw new BusinessException("系统找不到该设备类型名称,请先添加设备类型, 设备类型名称" + vo.getTypeName());
+//                        }
+//                    }
+                    if (StringUtils.isNotBlank(vo.getPositionName())) { // 设备位置匹配
+                        boolean findPosition = false;
+                        for (SbPosition position : positionList) {
+                            if (position.getName().equalsIgnoreCase(vo.getPositionName().trim())) {
+                                tempInfo.setPositionId(position.getId());
+                                findPosition = true;
+                                break;
+                            }
+                        }
+                        if (!findPosition) {
+                            throw new BusinessException("系统找不到位置名称,请先在基础配置中添加位置, 位置名称" + vo.getPositionName());
+                        }
+                    }
+                    // tempInfo.setProducerId(vo.getProducerName());
+                    /*if(StringUtils.isNotBlank(vo.getProducerName())){ // 生产商匹配
+                        boolean findProducer = false;
+                        for (FirmProducer producer : producerList) {
+                            if (producer.getName().equalsIgnoreCase(vo.getProducerName().trim())) {
+                                tempInfo.setProducerId(producer.getId());
+                                findProducer = true;
+                                break;
+                            }
+                        }
+                        if (!findProducer) {
+                            throw new BusinessException("找不到生产商,请先添加:" + vo.getProducerName());
+                        }
+                    }*/
+                    /*if (StringUtils.isNotBlank(vo.getSaveUserName())) { // 使用人员
+                        boolean findSaveUser = false;
+                        for (SysUser user : users) {
+                            if (user.getRealName().equalsIgnoreCase(vo.getSaveUserName().trim())) {
+                                tempInfo.setSaveUser(user.getUserId());
+                                findSaveUser = true;
+                                break;
+                            }
+                        }
+                        if (!findSaveUser) {
+                            throw new BusinessException("找不到使用人员,请先添加, 名称" + vo.getSaveUserName());
+                        }
+                    }*/
+                    // 如果计量设备 且是需要检定
+//                    if (vo.getUseType() == SbUseType.BGCL.getValue() && vo.getIsMeasure() == YesNoEnum.YES.getValue()) {
+//                        if (vo.getCheckDate() == null && vo.getNextCheckDate() == null) {
+//                            throw new BusinessException("上次和下次检定日期,不能全部为空");
+//                        }
+//                        if (vo.getCheckPeriod() == null) {
+//                            throw new BusinessException("检定周期不能为空");
+//                        }
+//                    }
+                    // 初始化的默认数据
+                    if (typeFlag!=null&&typeFlag==2){
+                        tempInfo.setIsMeasure(1);
+                        tempInfo.setIsSelf(0);
+                    }else if (typeFlag!=null&&typeFlag==3){
+                        tempInfo.setIsMeasure(1);
+                        tempInfo.setIsSelf(1);
+                    }else if (typeFlag!=null&&typeFlag==4){
+                        tempInfo.setIsMeasure(0);
+//                        tempInfo.setIsSelf(1);
+                    }
+                    tempInfo.setUseType(4);
+                    tempInfo.setMeasureStatus(0);
+                    tempInfo.setIsShow(0);
+                    tempInfo.setId(IdGeneratorUtils.getObjectId());
+                    tempInfo.setCreatedUserName(SecurityUtils.getUserInfo().getUsername());
+                    tempInfo.setCreatedUserId(SecurityUtils.getUserInfo().getUserId());
+                    tempInfo.setCreatedTime(LocalDateTime.now());
+                    // 检索自定义字段值
+                    Class clazz = vo.getClass();
+                    Field[] fields = clazz.getDeclaredFields();
+                    StringBuilder paramList = new StringBuilder();
+                    paramList.append("[");
+                    for (Field field : fields) {
+                        Method requestMethod = clazz.getMethod(getGetMethod(field.getName()));
+                        Object requestVal = requestMethod.invoke(vo);
+                        Excel excel = field.getAnnotation(Excel.class);
+                        if (excel != null && excel.styleType() == 1 && requestVal != null) {
+                            // 拼接自定义字符串
+                            paramList.append("{\"name\":\"").append(excel.name()).append("\",");
+                            paramList.append("\"content\":\"").append(requestVal).append("\"},");
+                        }
+                    }
+                    String param = paramList.toString();
+                    if (param.length() > 1) {
+                        param = param.substring(0, param.length() - 1);
+                    }
+                    param += "]";
+                    tempInfo.setParamList(param);
+                    addList.add(tempInfo);
+                }
+            }
+
+            if (CollectionUtil.isNotEmpty(addTypeList)) {
+                throw new BusinessException(addTypeList.size() + "个设备类型名称找不到,请先添加:" + addTypeList);
+            }
+            // 导入数据
+            mapper.insertListforComplex(addList);
+            return "总计导入:" + (addList.size());
+        } catch (Exception e) {
+            e.printStackTrace();
+            throw new BusinessException(e.getMessage());
+        }
+    }
+
     public String getGetMethod(String fieldName) {
         char cha = fieldName.charAt(0);
         return "get" + Character.toUpperCase(cha) + fieldName.substring(1);