xiongchao преди 3 години
родител
ревизия
3e4c080168

+ 8 - 0
platform-dao/src/main/java/com/platform/dao/dto/check/CheckStandardDTO.java

@@ -37,6 +37,14 @@ public class CheckStandardDTO extends BaseDTO implements Serializable {
      * 设备id
      */
     private String sbId;
+    /**
+     * 设备名称
+     */
+    private String sbName;
+    /**
+     * 设备新号
+     */
+    private String sbNo;
     /**
      * 被复制设备id
      */

+ 51 - 19
platform-dao/src/main/java/com/platform/dao/util/CustomExcelImportUtil.java

@@ -460,12 +460,13 @@ public class CustomExcelImportUtil {
     }
 
     public static void main(String[] args) throws IOException, InvalidFormatException {
-        String[] files = {"C:\\Users\\cyz\\Downloads\\设备基础信息20210627125310010.xls"};
-        InputStream inputstream = new FileInputStream(files[0]);
+        String[] files = {"C:\\Users\\cyz\\Downloads\\维护计划和机台信息\\C-006 (OS-M240).xls",
+                "C:\\Users\\cyz\\Downloads\\维护计划和机台信息\\C-001 (OS-M235)-多列模板.xls"};
+        InputStream inputstream = new FileInputStream(files[1]);
         LocalDateTime now = LocalDateTime.now();
        //  List<SparePartInfoVO> list = importSparePartInfoList(now, inputstream);
-        List<SbInfoVO> list = importListByUpdateALl(inputstream);
-       // List<CheckStandard> list = importCheckStandardList(inputstream);
+        // List<SbInfoVO> list = importListByUpdateALl(inputstream);
+       List<CheckStandard> list = importCheckStandardList(inputstream);
 
         list.forEach(item -> {
             System.out.println(item.toString());
@@ -960,29 +961,30 @@ public class CustomExcelImportUtil {
         int rowCounts = sheet.getLastRowNum();
         List<CheckStandard> result = new ArrayList<>(rowCounts);
         CheckStandard record = null;
-        String sbNo = sheet.getRow(4).getCell(13).getStringCellValue();
+        String sbNo = "" ;
+        int type = 0;// 没有负责人的,1有
+        if(sheet.getRow(4).getCell(10) != null && StringUtils.isNotBlank(sheet.getRow(4).getCell(10) .getStringCellValue())){
+            type = 0;
+            sbNo = sheet.getRow(4).getCell(10).getStringCellValue();
+        }else{
+            type = 1;
+            sbNo = sheet.getRow(4).getCell(13).getStringCellValue();
+        }
         StringBuffer error = new StringBuffer();
+        LOGGER.info("文件行数:" + rowCounts);
         for (int i = 12; i <= rowCounts; i++) {
             record = new CheckStandard();
             Row row = sheet.getRow(i);
             if(isRowEmpty(row)){
-                continue;
+                break;
             }
             String index = row.getCell(1).getStringCellValue() + "";
             try {
-                //i,j i:行 j:列
-                setPeriod(row, record);
-                String sort = getCellValue(row.getCell(11)).trim();
-                System.out.println(sort.substring(0,sort.length()-2 ));
-                record.setSort(Integer.valueOf(sort.substring(0,sort.length()-2 )));
-                record.setRequirement(row.getCell(12).getStringCellValue().trim());
-                record.setName(record.getRequirement().substring(0,4));
-                record.setId(IdGeneratorUtils.getObjectId());
-                record.setType(CheckStandardTypeEnum.POLLING.getValue());
-                record.setSbId(sbNo);// 需要根据no来判断设备的id
-                record.setStandardHours("0");
-                record.setEnable(1);
-                setRemark(row, record);
+                if(type == 0){
+                    setNoPerson(sbNo, row, record);
+                }else{
+                    setPerson(sbNo, row, record);
+                }
             } catch (Exception e) {
                 throw new BusinessException("导入异常,行号:"+ i + ", 错误信息" + e.getMessage() +  ", 错误原因" + e.getCause());
             }
@@ -991,6 +993,36 @@ public class CustomExcelImportUtil {
         return result;
     }
 
+    private static void setPerson(String sbNo, Row row, CheckStandard record) {
+        //i,j i:行 j:列
+        setPeriod(row, record);
+        String sort = getCellValue(row.getCell(11)).trim();
+        record.setSort(Integer.valueOf(sort.substring(0,sort.length()-2 )));
+        record.setRequirement(row.getCell(12).getStringCellValue().trim());
+        record.setName(record.getRequirement().substring(0,4));
+        record.setId(IdGeneratorUtils.getObjectId());
+        record.setType(CheckStandardTypeEnum.POLLING.getValue());
+        record.setNo(sbNo);// 需要根据no来判断设备的id
+        record.setStandardHours("0");
+        record.setEnable(1);
+        setRemark(row, record);
+    }
+
+    private static void setNoPerson(String sbNo, Row row, CheckStandard record) {
+        //i,j i:行 j:列
+        setPeriod(row, record);
+        String sort = getCellValue(row.getCell(8)).trim();
+        record.setSort(Integer.valueOf(sort.substring(0,sort.length()-2 )));
+        record.setRequirement(row.getCell(9).getStringCellValue().trim());
+        record.setName(record.getRequirement().substring(0,4));
+        record.setId(IdGeneratorUtils.getObjectId());
+        record.setType(CheckStandardTypeEnum.POLLING.getValue());
+        record.setNo(sbNo);// 需要根据no来判断设备的id
+        record.setStandardHours("0");
+        record.setEnable(1);
+        setRemark(row, record);
+    }
+
     private static void setRemark(Row row, CheckStandard record) {
         if(StringUtils.isNotEmpty(row.getCell(7).getStringCellValue())){
             record.setCheckUserType(1);

+ 8 - 0
platform-dao/src/main/java/com/platform/dao/vo/query/check/CheckStandardVO.java

@@ -35,6 +35,14 @@ public class CheckStandardVO extends BaseVO implements Serializable{
      * 设备id
      */
     private String sbId;
+    /**
+     * 设备名称
+     */
+    private String sbName;
+    /**
+     * 设备新号
+     */
+    private String sbNo;
     /**
      * 项目id
      */

+ 8 - 1
platform-dao/src/main/resources/mapper/check/CheckStandardMapper.xml

@@ -123,11 +123,18 @@ checkstandard.sort,
     </sql>
     <select id="selectList" parameterType="com.platform.dao.dto.check.CheckStandardDTO"
             resultType="com.platform.dao.vo.query.check.CheckStandardVO">
-        select checkstandard.*, partInfo.name as partName
+        select checkstandard.*, sbInfo.name as sbName, sbInfo.no as sbNo, partInfo.name as partName
         from t_check_standard as checkstandard
+        LEFT JOIN t_sb_info sbInfo on checkstandard.sb_id = sbInfo.id
         LEFT JOIN t_part_info partInfo on checkstandard.part = partInfo.id
         <where>
             <include refid="List_Condition"/>
+            <if test="sbName != null and sbName != ''">
+                and sbInfo.name like concat('%',#{sbName},'%')
+            </if>
+            <if test="sbNo != null and sbNo != ''">
+                and sbInfo.no like concat('%',#{sbNo},'%')
+            </if>
         </where>
     </select>
     <select id="selectProjectStandardList" resultType="com.platform.dao.vo.query.check.CheckStandardVO">

+ 2 - 2
platform-rest/src/main/java/com/platform/rest/controller/check/CheckStandardController.java

@@ -194,9 +194,9 @@ public class CheckStandardController {
      */
     @SysLog("新增导入设备的保养标准")
     @PostMapping("/import")
-    public R importExcelByUpdate(@RequestParam("file") MultipartFile file) throws Exception {
+    public R importListByAdd( @RequestParam("file") MultipartFile file) throws Exception {
         String result = "";
-        result = checkStandardService.importListByAdd( file);
+        result = checkStandardService.importListByAdd(file);
         return new R<>(result);
     }
 }

+ 12 - 2
platform-service/src/main/java/com/platform/service/check/impl/CheckStandardServiceImpl.java

@@ -352,6 +352,16 @@ public class CheckStandardServiceImpl extends BaseServiceImpl<CheckStandardMappe
         try {
             List<CheckStandard> items = CustomExcelImportUtil.importCheckStandardList(file.getInputStream());
             if (!CollectionUtils.isEmpty(items)) {
+
+                // 设备编号,不确定是新号还是旧号,都要判断下
+                String fileSbNo = items.get(0).getNo();
+                Weekend<SbInfo> weekend = new Weekend<>(SbInfo.class);
+                WeekendCriteria<SbInfo, Object> weekendCriteria = weekend.weekendCriteria();
+                weekendCriteria.andEqualTo(SbInfo::getNo, fileSbNo);
+                SbInfo sbInfo = sbInfoMapper.selectOneByExample(weekend);
+                if(sbInfo == null){
+                    throw new BusinessException("新号查不到,请确保编号正确" + ", 导入文件中的设备新号:" + fileSbNo);
+                }
                 List<CheckStandard> addItems = new ArrayList<CheckStandard>();
                 List<SysUser> users = sysUserMapper.selectAll();
                 List<SbInfo> sbInfoList = sbInfoMapper.selectAll();
@@ -365,7 +375,7 @@ public class CheckStandardServiceImpl extends BaseServiceImpl<CheckStandardMappe
                     boolean findSaveUser = false;
                     if(item.getCheckUserType() == 1){
                         for (SbInfo info : sbInfoList) {
-                            if(info.getNo().equals(item.getSbId())){
+                            if(info.getNo().equals(item.getNo())){
                                 item.setSbId(info.getId());
                                 item.setCheckUserId(info.getSaveUser());
                                 findSaveUser = true;
@@ -383,7 +393,7 @@ public class CheckStandardServiceImpl extends BaseServiceImpl<CheckStandardMappe
                         }
                     }
                     if(!findSaveUser){
-                        throw new BusinessException("找不到设备,请先添加,设备新号:" + item.getSbId());
+                        throw new BusinessException("找不到设备,请先添加,设备新号:" + item.getNo());
                     }
                     addItems.add(item);
                 }

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

@@ -197,4 +197,8 @@ public interface SbInfoService extends IBaseService<SbInfo, SbInfoDTO> {
     void updateBatchChild(List<SbInfoDTO> sbInfoDTOList);
 
     void updateCancelChild(String id);
+
+    public SbInfo selectByNo(String zbh);
+
+    public SbInfo selectByZbh(String zbh);
 }

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

@@ -127,6 +127,34 @@ public class SbInfoServiceImpl extends BaseServiceImpl<SbInfoMapper, SbInfo, SbI
         return 1;
     }
 
+    /**
+     * 根据设备新号查询
+     * @param no
+     * @return
+     */
+    @Override
+    public SbInfo selectByNo(String no) {
+        Weekend<SbInfo> weekend = new Weekend<>(SbInfo.class);
+        WeekendCriteria<SbInfo, Object> weekendCriteria = weekend.weekendCriteria();
+        weekendCriteria.andEqualTo(SbInfo::getNo, no);
+        SbInfo sbInfo = mapper.selectOneByExample(weekend);
+        return sbInfo;
+    }
+
+    /**
+     * 根据设备旧号查询
+     * @param zbh
+     * @return
+     */
+    @Override
+    public SbInfo selectByZbh(String zbh) {
+        Weekend<SbInfo> weekend = new Weekend<>(SbInfo.class);
+        WeekendCriteria<SbInfo, Object> weekendCriteria = weekend.weekendCriteria();
+        weekendCriteria.andEqualTo(SbInfo::getZbh, zbh);
+        SbInfo sbInfo = mapper.selectOneByExample(weekend);
+        return sbInfo;
+    }
+
     @Override
     public void updateBatch(List<SbInfoVO> list) {
         mapper.updateBatch(list);