| | |
| | | EasyExcelCellListener readYearListener = new EasyExcelCellListener(2, 3); |
| | | EasyExcel.read(is.getInputStream(), readYearListener).headRowNumber(0).sheet().doReadSync(); |
| | | String yearStr = readYearListener.getCellValue(); |
| | | if (yearStr == null || yearStr.isEmpty()) { |
| | | yearStr = ""; |
| | | } |
| | | String year = yearStr.replaceAll("[^\\d]", ""); // 去除非数字字符 |
| | | |
| | | year = (year.length() == 4) ? year : DateUtils.getDate().substring(0,4); |
| | | |
| | | QueryWrapper<EimsEqu> queryWrapper = new QueryWrapper<>(); |
| | |
| | | failureNum++; |
| | | continue; |
| | | } |
| | | if (period.length() == 1) { |
| | | period = "1"+period; |
| | | } |
| | | |
| | | try { |
| | | if (period.length() > 1) { |
| | | String num = period.replaceAll("[^\\d]", ""); |
| | | maintPlanBo.setMaintCycle(Long.parseLong(num)); |
| | | String substring = period.replace(num, ""); |
| | | // 转换周期单位,M转换为3,D转换为1,Y转换为5,W转换为2,Q转换为4 |
| | | switch (substring) { |
| | | case "M": |
| | | substring = "3"; |
| | | break; |
| | | case "D": |
| | | substring = "1"; |
| | | break; |
| | | case "Y": |
| | | substring = "5"; |
| | | break; |
| | | case "W": |
| | | substring = "2"; |
| | | break; |
| | | case "Q": |
| | | substring = "4"; |
| | | break; |
| | | case "个月": |
| | | substring = "3"; |
| | | break; |
| | | case "天": |
| | | substring = "1"; |
| | | break; |
| | | case "年": |
| | | substring = "5"; |
| | | break; |
| | | case "周": |
| | | substring = "2"; |
| | | break; |
| | | case "季度": |
| | | substring = "4"; |
| | | break; |
| | | default: |
| | | if ("".equals(num)) { |
| | | switch (period) { |
| | | case "一个月": |
| | | maintPlanBo.setMaintCycle(1L); |
| | | maintPlanBo.setMaintCycleUnit("3"); |
| | | break; |
| | | case "两个月": |
| | | maintPlanBo.setMaintCycle(2L); |
| | | maintPlanBo.setMaintCycleUnit("3"); |
| | | break; |
| | | case "二个月": |
| | | maintPlanBo.setMaintCycle(2L); |
| | | maintPlanBo.setMaintCycleUnit("3"); |
| | | break; |
| | | case "三个月": |
| | | maintPlanBo.setMaintCycle(3L); |
| | | maintPlanBo.setMaintCycleUnit("3"); |
| | | break; |
| | | case "六个月": |
| | | maintPlanBo.setMaintCycle(6L); |
| | | maintPlanBo.setMaintCycleUnit("3"); |
| | | break; |
| | | default: |
| | | break; |
| | | } |
| | | }else { |
| | | |
| | | maintPlanBo.setMaintCycle(Long.parseLong(num)); |
| | | String substring = period.replace(num, ""); |
| | | // 转换周期单位,M转换为3,D转换为1,Y转换为5,W转换为2,Q转换为4 |
| | | switch (substring) { |
| | | case "M": |
| | | substring = "3"; |
| | | break; |
| | | case "D": |
| | | substring = "1"; |
| | | break; |
| | | case "Y": |
| | | substring = "5"; |
| | | break; |
| | | case "W": |
| | | substring = "2"; |
| | | break; |
| | | case "Q": |
| | | substring = "4"; |
| | | break; |
| | | case "个月": |
| | | substring = "3"; |
| | | break; |
| | | case "天": |
| | | substring = "1"; |
| | | break; |
| | | case "年": |
| | | substring = "5"; |
| | | break; |
| | | case "周": |
| | | substring = "2"; |
| | | break; |
| | | case "季度": |
| | | substring = "4"; |
| | | break; |
| | | default: |
| | | } |
| | | maintPlanBo.setMaintCycleUnit(substring); |
| | | } |
| | | maintPlanBo.setMaintCycleUnit(substring); |
| | | } else { |
| | | maintPlanBo.setMaintCycle(Long.parseLong(period)); |
| | | maintPlanBo.setMaintCycleUnit(""); |
| | |
| | | } |
| | | } |
| | | |
| | | return is.getOriginalFilename() + " 导入成功:" + successNum + "条,导入失败:" + failureNum + "条"; |
| | | // 如果失败条件小于1则不打印信息 |
| | | if (failureNum <= 0) { |
| | | return "成功!"; |
| | | } else { |
| | | return is.getOriginalFilename() + " 导入成功:" + successNum + "条,导入失败:" + failureNum + "条"; |
| | | } |
| | | |
| | | } catch (Exception e) { |
| | | return is.getOriginalFilename() + " 导入异常:" + e.getMessage(); |
| | | } |