瀏覽代碼

设备新增导入

xiongchao 3 年之前
父節點
當前提交
ddb9fcac74

+ 39 - 46
platform-dao/src/main/java/com/platform/dao/util/CustomExcelImportUtil.java

@@ -11,6 +11,7 @@ import com.platform.dao.entity.sqarepartmanage.SparePartInfo;
 import com.platform.dao.entity.store.SpareStore;
 import com.platform.dao.vo.export.sb.ExportSbInfoVO;
 import com.platform.dao.vo.query.sparepartmanage.SparePartInfoVO;
+import com.platform.dao.vo.sb.SbInfoVO;
 import com.platform.office.poi.excel.ExcelImportUtil;
 import com.platform.office.poi.excel.entity.ImportParams;
 import com.platform.office.poi.excel.imports.CellValueServer;
@@ -626,6 +627,8 @@ public class CustomExcelImportUtil {
             return 7;
         } else if ("维修中".equals(stringCellValue) || "待修".equals(stringCellValue)) {
             return 8;
+        } else if ("在库".equals(stringCellValue)) {
+            return 1;
         } else {
             return 2;
         }
@@ -822,7 +825,7 @@ public class CustomExcelImportUtil {
         return result;
     }
 
-    public static List<SbInfo> importSbInfoList(InputStream inputstream) throws IOException, InvalidFormatException {
+    public static List<SbInfoVO> importSbInfoList(InputStream inputstream) throws IOException, InvalidFormatException {
         if (inputstream == null) {
             return Collections.emptyList();
         }
@@ -837,56 +840,52 @@ public class CustomExcelImportUtil {
         }
         Sheet sheet = book.getSheetAt(0);
         int rowCounts = sheet.getLastRowNum();
-        List<SbInfo> result = new ArrayList<>(rowCounts);
-        SbInfo record = null;
+        List<SbInfoVO> result = new ArrayList<>(rowCounts);
+        SbInfoVO record = null;
 
         StringBuffer error = new StringBuffer();
-        for (int i = 1; i <= rowCounts; i++) {
-            record = new SbInfo();
+        for (int i = 2; i <= rowCounts; i++) {
+            record = new SbInfoVO();
             Row row = sheet.getRow(i);
             String index = row.getCell(0).getStringCellValue() + "";
             try {
                 //i,j i:行 j:列
-                record.setSaveUser(row.getCell(4).getStringCellValue());
-                record.setRepairUser(row.getCell(5).getStringCellValue());
-                record.setName(row.getCell(8).getStringCellValue().trim().replace("'", ""));
-                record.setModel(getCellValue(row.getCell(9)).trim());
-                record.setNo(row.getCell(11).getStringCellValue().trim());
-                record.setZbh(getCellValue(row.getCell(12)));
-                record.setCardNo(getCellValue(row.getCell(13)).trim());
-                record.setFinancingNo(row.getCell(14).getStringCellValue().trim());
-                record.setCph(getCellValue(row.getCell(15)));
-                record.setFdjxh(getCellValue(row.getCell(16)));
-                record.setFdjh(getCellValue(row.getCell(17)));
-                record.setDph(getCellValue(row.getCell(18)));
-                record.setZz(getCellValue(row.getCell(19)));
-                record.setZaiz(getCellValue(row.getCell(20)));
-                record.setInitialValue(new Double(getCellValue(row.getCell(21))));
-                record.setCurrentValue(new Double(getCellValue(row.getCell(22))));
-
-                if (StringUtils.isBlank(getCellValue(row.getCell(23)))) {
+                record.setNo(row.getCell(1).getStringCellValue().trim());
+                record.setZbh(getCellValue(row.getCell(2)));
+                record.setName(row.getCell(3).getStringCellValue().trim().replace("'", ""));
+                record.setModel(getCellValue(row.getCell(4)).trim());
+                record.setLevel(getLevel(row.getCell(5).getStringCellValue()));
+                record.setInitialValue(new Double(getCellValue(row.getCell(6))));
+                record.setTypeId(row.getCell(7).getStringCellValue().trim());
+                record.setUseType(getUseType(row.getCell(8).getStringCellValue().trim()));
+                record.setZz(getCellValue(row.getCell(9)));
+                record.setCph(getCellValue(row.getCell(10)));
+                record.setZzh(getCellValue(row.getCell(11)));
+                record.setProducerId(row.getCell(12).getStringCellValue().trim());
+                record.setSaveUserName(row.getCell(13).getStringCellValue().trim());
+                record.setRepairUserName(row.getCell(14).getStringCellValue().trim());
+                record.setRepairUserNameSecond(row.getCell(15).getStringCellValue().trim());
+                if (StringUtils.isBlank(getCellValue(row.getCell(16)))) {
                     record.setBuyDate(DateUtils.strToLocalDate("2014-01-01", DateUtils.PATTERN_YMD));
                 } else {
-                    record.setBuyDate(DateUtils.strToLocalDate((getCellValue(row.getCell(23)).substring(0, 4) + "-01-01"), DateUtils.PATTERN_YMD));
+                    record.setBuyDate(DateUtils.strToLocalDate((getCellValue(row.getCell(16)).substring(0, 4) + "-01-01"), DateUtils.PATTERN_YMD));
                 }
-
-                //record.setStartDate(DateUtils.strToLocalDate( "2019-01-01", DateUtils.PATTERN_YMD));
-                if (StringUtils.isBlank(getCellValue(row.getCell(24)))) {
+                if (StringUtils.isBlank(getCellValue(row.getCell(17)))) {
                     record.setStartDate(DateUtils.strToLocalDate("2019-01-01", DateUtils.PATTERN_YMD));
                 } else {
-                    if (getCellValue(row.getCell(24)).contains(".")) {
-                        if (getCellValue(row.getCell(24)).contains("E7")) {
-                            record.setStartDate(DateUtils.strToLocalDate(getCellValue(row.getCell(24)).replace(".", "").replace("E7", ""), DateUtils.PATTERNYMD));
-                        } else if (getCellValue(row.getCell(24)).endsWith(".0")) {
-                            record.setStartDate(DateUtils.strToLocalDate(ExcelDoubleToDate(getCellValue(row.getCell(24))), DateUtils.PATTERN_YMD));
+                    if (getCellValue(row.getCell(17)).contains(".")) {
+                        if (getCellValue(row.getCell(17)).contains("E7")) {
+                            record.setStartDate(DateUtils.strToLocalDate(getCellValue(row.getCell(17)).replace(".", "").replace("E7", ""), DateUtils.PATTERNYMD));
+                        } else if (getCellValue(row.getCell(17)).endsWith(".0")) {
+                            record.setStartDate(DateUtils.strToLocalDate(ExcelDoubleToDate(getCellValue(row.getCell(17))), DateUtils.PATTERN_YMD));
                         } else {
-                            record.setStartDate(DateUtils.strToLocalDate(getCellValue(row.getCell(24)), DateUtils.PATTERN_YMD_DOT));
+                            record.setStartDate(DateUtils.strToLocalDate(getCellValue(row.getCell(17)), DateUtils.PATTERN_YMD_DOT));
                         }
-                    } else if (getCellValue(row.getCell(24)).contains("-")) {
-                        record.setStartDate(DateUtils.strToLocalDate(getCellValue(row.getCell(24)), DateUtils.PATTERN_YMD));
+                    } else if (getCellValue(row.getCell(17)).contains("-")) {
+                        record.setStartDate(DateUtils.strToLocalDate(getCellValue(row.getCell(17)), DateUtils.PATTERN_YMD));
                     } else {
-                        if(getCellValue(row.getCell(24)).contains("/")){
-                            String[] strList = getCellValue(row.getCell(24)).split("/");
+                        if(getCellValue(row.getCell(17)).contains("/")){
+                            String[] strList = getCellValue(row.getCell(17)).split("/");
                             if(strList.length == 3){
                                 if(strList[1].length() == 1){
                                     strList[1] = "0" + strList[1];
@@ -898,18 +897,12 @@ public class CustomExcelImportUtil {
                             String newDate = strList[0] + "-" + strList[1] + "-" + strList[2];
                             record.setStartDate(DateUtils.strToLocalDate(newDate, DateUtils.PATTERN_YMD));
                         }else{
-                            record.setStartDate(DateUtils.strToLocalDate(getCellValue(row.getCell(24)), DateUtils.PATTERNYMD));
+                            record.setStartDate(DateUtils.strToLocalDate(getCellValue(row.getCell(17)), DateUtils.PATTERNYMD));
                         }
                     }
                 }
-                record.setStatus(getSbInfoStatus(row.getCell(26).getStringCellValue()));
-
-                //if(StringUtils.isBlank(getCellValue(row.getCell(27)))) {
-                //    throw new BusinessException("请在备注一栏填写分公司简码");
-                // }else{
-                //    record.setNo(row.getCell(27).getStringCellValue().trim() + '-' + row.getCell(11).getStringCellValue().trim());
-                //}
-                record.setUseArea("5e64ac691c527828b2114da0");
+                record.setStatus(getSbInfoStatus(row.getCell(18).getStringCellValue()));
+                record.setRemark(row.getCell(19).getStringCellValue().trim());
 
             } catch (Exception e) {
                 error.append(index).append(",");

+ 38 - 95
platform-dao/src/main/java/com/platform/dao/vo/export/sb/ExportSbInfoVO.java

@@ -28,155 +28,98 @@ public class ExportSbInfoVO implements Serializable {
     /**
      * 设备编号
      */
-    @Excel(name = "设备编号", orderNum = "2")
+    @Excel(name = "设备(新号)", orderNum = "2")
     private String no;
-
     /**
-     * 财务编码
+     * 设备编号
      */
-    @Excel(name = "财务编码", orderNum = "3")
-    private String financingNo;
-
+    @Excel(name = "设备(旧号)", orderNum = "3")
+    private String zbh;
     /**
      * 设备名称
      */
     @Excel(name = "设备名称", orderNum = "4")
     private String name;
-
     /**
-     * 设备类别
+     * 设备名称
      */
-    @Excel(name = "设备类别", orderNum = "5")
-    private String typeId;
-
+    @Excel(name = "设备型号", orderNum = "5")
+    private String model;
     /**
      * 设备等级
      */
     @Excel(name = "设备等级", orderNum = "6", dicCode="SBINFO_LEVEL")
     private Integer level;
-
     /**
-     * j
      * 设备原值
      */
     @Excel(name = "设备原值", orderNum = "7")
     private Double initialValue;
-
-    /**
-     * 当前价值
-     */
-    @Excel(name = "当前价值", orderNum = "8")
-    private Double currentValue;
-
-    /**
-     * 已折旧价值
-     */
-    @Excel(name = "已折旧价值", orderNum = "9")
-    private Double cutValue;
-
-    /**
-     * 生产商
-     */
-    @Excel(name = "生产商", orderNum = "10")
-    private String producerId;
-
-    /**
-     * 计量单位
-     */
-    @Excel(name = "计量单位", orderNum = "11")
-    private String unit;
     /**
-     * 使用区域
-     */
-    @Excel(name = "使用集团/区域", orderNum = "12")
-    private String useArea;
-    /**
-     * 使用集团/区域
+     * 设备类别
      */
-    @Excel(name = "使用集团/区域名称", orderNum = "13")
-    private String useAreaName;
+    @Excel(name = "设备类别", orderNum = "8")
+    private String typeName;
     /**
-     * 使用公司
+     * 自定义类型
      */
-    @Excel(name = "使用公司", orderNum = "14")
-    private String useCompany;
+    @Excel(name = "自定义类型", orderNum = "9", dicCode="SB_USE_TYPE")
+    private String useType;
     /**
-     * 使用公司
+     * 大小/尺寸
      */
-    @Excel(name = "使用公司名称", orderNum = "15")
-    private String useCompanyName;
+    @Excel(name = "大小/尺寸", orderNum = "10")
+    private String zz;
     /**
-     * 使用项目部
+     * 房间
      */
-    @Excel(name = "使用项目部", orderNum = "16")
-    private String useProject;
-
+    @Excel(name = "房间", orderNum = "11")
+    private String cph;
     /**
-     * 使用项目部
+     * 房间
      */
-    @Excel(name = "使用项目部名称", orderNum = "17")
-    private String useProjectName;
+    @Excel(name = "系列号(出厂编号)", orderNum = "12")
+    private String zzh;
     /**
-     * 使用部门
-     */
-    @Excel(name = "使用部门", orderNum = "18")
-    private String useDept;
-
-    /**
-     * 使用部门
+     * 生产商
      */
-    @Excel(name = "使用部门名称", orderNum = "19")
-    private String useDeptName;
-
+    @Excel(name = "生产商", orderNum = "13")
+    private String producerName;
     /**
-     * 使用施工组
-     */
-    @Excel(name = "使用施工组", orderNum = "20")
-    private String useGroup;
-
-    /**
-     * 使用施工组
+     * 使用施工组名称
      */
-    @Excel(name = "使用施工组名称", orderNum = "21")
-    private String useGroupName;
+    @Excel(name = "管理人名称", orderNum = "14")
+    private String saveUserName;
     /**
-     * 管理
+     * 维修人
      */
-    @Excel(name = "管理人", orderNum = "22")
-    private String saveUser;
+    @Excel(name = "维修人", orderNum = "15")
+    private String repairUserName;
     /**
-     * 使用施工组名称
+     * 第二维修人
      */
-    @Excel(name = "管理人名称", orderNum = "23")
-    private String saveUserName;
+    @Excel(name = "第二维修人", orderNum = "16")
+    private String repairUserNameSecond;
     /**
      * 购置日期
      */
-    @Excel(name = "购置日期", orderNum = "24")
+    @Excel(name = "购置日期", orderNum = "17")
     private LocalDate buyDate;
-
     /**
      * 投用日期
      */
-    @Excel(name = "投用日期", orderNum = "25")
+    @Excel(name = "投用日期", orderNum = "18")
     private LocalDate startDate;
 
     /**
      * 状态
      */
-    @Excel(name = "状态", orderNum = "26", dicCode="SB_INFO_STATUS")
+    @Excel(name = "状态", orderNum = "19", dicCode="SB_INFO_STATUS")
     private Integer status;
-    /**
-     * 设备型号id
-     */
-    @Excel(name = "设备型号id", orderNum = "27")
-    private String modelId;
     /**
      * 备注
      */
-    @Excel(name = "备注", orderNum = "28")
+    @Excel(name = "备注", orderNum = "20")
     private String remark;
 
-
-
 }

+ 8 - 0
platform-dao/src/main/java/com/platform/dao/vo/sb/SbInfoVO.java

@@ -200,6 +200,10 @@ public class SbInfoVO extends BaseVO implements Serializable {
      * 维修人
      */
     private String repairUserName;
+    /**
+     * 第二维修人
+     */
+    private String repairUserNameSecond;
     /**
      * 购置日期
      */
@@ -244,6 +248,10 @@ public class SbInfoVO extends BaseVO implements Serializable {
      * 设备图片
      */
     private String sbImage;
+    /**
+     * 自编号/设备(旧号)
+     */
+    private String zbh;
     /**
      * 二维码
      */

+ 37 - 74
platform-service/src/main/java/com/platform/service/sb/impl/SbInfoServiceImpl.java

@@ -524,7 +524,12 @@ public class SbInfoServiceImpl extends BaseServiceImpl<SbInfoMapper, SbInfo, SbI
             }
         }
 
-        List<String> saveUserIds = vos.stream().map(SbInfoVO::getSaveUser).collect(Collectors.toList());
+        List<String> saveUserIds = vos.stream().map(SbInfoVO::getSaveUser).distinct().collect(Collectors.toList());
+        List<String> repairUserIds = vos.stream().map(SbInfoVO::getRepairUser).collect(Collectors.toList());
+        List<String> repairUserSecondIds = vos.stream().map(SbInfoVO::getRepairUserSecond).collect(Collectors.toList());
+        saveUserIds.addAll(repairUserIds);
+        saveUserIds.addAll(repairUserSecondIds);
+        saveUserIds = saveUserIds.stream().distinct().collect(Collectors.toList());
         Weekend<SysUser> weekend = new Weekend<>(SysUser.class);
         weekend.weekendCriteria().andIn(SysUser::getUserId, saveUserIds);
         List<SysUser> userList = sysUserMapper.selectByExample(weekend);
@@ -532,7 +537,12 @@ public class SbInfoServiceImpl extends BaseServiceImpl<SbInfoMapper, SbInfo, SbI
             for(SysUser user:userList) {
                 if (sbInfo.getSaveUser() != null && sbInfo.getSaveUser().equals(user.getUserId())){
                     sbInfo.setSaveUserName(user.getRealName());
-                    break;
+                }
+                if (sbInfo.getRepairUser() != null && sbInfo.getRepairUser().equals(user.getUserId())){
+                    sbInfo.setRepairUserName(user.getRealName());
+                }
+                if (sbInfo.getRepairUserSecond() != null && sbInfo.getRepairUserSecond().equals(user.getUserId())){
+                    sbInfo.setRepairUserNameSecond(user.getRealName());
                 }
             }
         }
@@ -923,82 +933,24 @@ public class SbInfoServiceImpl extends BaseServiceImpl<SbInfoMapper, SbInfo, SbI
     @Override
     @Transactional(rollbackFor = Exception.class)
     public String importListByAdd(String useCompany, String useProject, MultipartFile file) {
-        // 先判断该区域是否已经有数据,如果有了,则不能导入,提示先删除该区域的设备
-        Weekend<SbInfo> weekend2 = new Weekend<>(SbInfo.class);
-        weekend2.weekendCriteria().andEqualTo(SbInfo::getUseCompany, useCompany).andEqualTo(SbInfo::getUseProject, useProject);
-        int count = mapper.selectCountByExample(weekend2);
-        if(count >0){
-            throw new BusinessException("该项目部下已经存在设备,请先清空");
-        }
         int addNum = 0;
         List<String> modelError = new ArrayList<String>();
         try {
-            List<SbInfo> items = CustomExcelImportUtil.importSbInfoList(file.getInputStream());
+            List<SbInfoVO> items = CustomExcelImportUtil.importSbInfoList(file.getInputStream());
             if (!CollectionUtils.isEmpty(items)) {
-                List<SbInfo> addItems = new ArrayList<SbInfo>();
-                List<SbModel> modelList = sbModelMapper.selectAll();
+                List<SbInfoVO> addItems = new ArrayList<SbInfoVO>();
                 List<SysUser> users = sysUserMapper.selectAll();
-
-                List<SbModel> addSbModelItems = new ArrayList<SbModel>();
                 LocalDateTime now = LocalDateTime.now();
-                for (SbInfo item : items) {
+                for (SbInfoVO item : items) {
+                    item.setUseArea(useArea);
                     item.setUseCompany(useCompany);
                     item.setUseProject(useProject);
+                    item.setUseDept(useDept);
+                    item.setUseGroup(useGroup);
                     item.setId(IdGeneratorUtils.getObjectId());
-                    boolean findModel = false;
-                    for (SbModel model : modelList) {
-                        if(model.getModel().equals(item.getModel())){
-                            item.setName(model.getName());
-                            item.setNameModel(model.getNameModel());
-                            item.setProducerId(model.getProducerId());
-                            item.setUnit(model.getUnit());
-                            item.setTypeId(model.getTypeId());
-                            item.setTotalHours(new BigDecimal(0));
-                            item.setTotalMiles(new BigDecimal(0));
-                            //item.setInitialValue(model.getValue());
-                            item.setModelId(model.getId());
-                            findModel = true;
-                            break;
-                        }
-                    }
-
-                    if(!findModel){
-                        if(!modelError.contains(item.getName() + ",型号" + item.getModel())){
-                            modelError.add(item.getName() + ",型号" + item.getModel());
-                        }
-                        SbModel model = new SbModel();
-                        model.setModel(item.getModel());
-                        model.setName(item.getName());
-                        model.setNameModel(item.getName() + item.getModel());
-                        model.setUnit("台");
-                        model.setValue(100000.00);
-                        model.setLevel(1);
-                        model.setProducerId("60004942159c0d5c6a472d6d");
-                        model.setUseType(1);
-                        model.setStatus(1);
-                        model.setTypeId("1");
-                        model.setCreatedTime(now);
-                        model.setCreatedUserId("1");
-                        model.setUpdateTime(now);
-                        model.setUpdateUserId("1");
-                        model.setRemark("备件导入新增,需要校准");
-                        model.setId(IdGeneratorUtils.getObjectId());
-                        boolean withModelBoms = false;
-                        for (SbModel modelIs : addSbModelItems) {
-                            if(modelIs.getName().equals(model.getName()) && modelIs.getModel().equals(model.getModel())){
-                                withModelBoms = true;
-                                item.setModelId(modelIs.getId());
-                                break;
-                            }
-                        }
-                        if(!withModelBoms){
-                            item.setModelId(model.getId());
-                            addSbModelItems.add(model);
-                        }
-                    }
                     boolean findSaveUser = false;
                     for (SysUser user : users) {
-                        if(user.getRealName().equals(item.getSaveUser())){
+                        if(user.getRealName().equals(item.getSaveUserName())){
                             item.setSaveUser(user.getUserId());
                             item.setUseUser(user.getUserId());
                             findSaveUser = true;
@@ -1008,10 +960,10 @@ public class SbInfoServiceImpl extends BaseServiceImpl<SbInfoMapper, SbInfo, SbI
                     if(!findSaveUser){
                         throw new BusinessException("找不到使用人员,请先添加, 名称" + item.getSaveUser());
                     }
-                    if(StringUtils.isNotBlank(item.getRepairUser())){
+                    if(StringUtils.isNotBlank(item.getRepairUserName())){
                         boolean findRepairUser = false;
                         for (SysUser user : users) {
-                            if(user.getRealName().equals(item.getRepairUser())){
+                            if(user.getRealName().equals(item.getRepairUserName())){
                                 item.setRepairUser(user.getUserId());
                                 findRepairUser = true;
                                 break;
@@ -1021,16 +973,27 @@ public class SbInfoServiceImpl extends BaseServiceImpl<SbInfoMapper, SbInfo, SbI
                             throw new BusinessException("找不到维修人员,请先添加, 名称" + item.getRepairUser());
                         }
                     }
+                    if(StringUtils.isNotBlank(item.getRepairUserNameSecond())){
+                        boolean findRepairUser = false;
+                        for (SysUser user : users) {
+                            if(user.getRealName().equals(item.getRepairUserNameSecond())){
+                                item.setRepairUserSecond(user.getUserId());
+                                findRepairUser = true;
+                                break;
+                            }
+                        }
+                        if(!findRepairUser){
+                            throw new BusinessException("找不到第二维修人员,请先添加, 名称" + item.getRepairUser());
+                        }
+                    }
                     addItems.add(item);
                 }
-                if(!CollectionUtils.isEmpty(addSbModelItems)){
-                    sbModelMapper.insertListforComplex(addSbModelItems);
-                }
                 if(!CollectionUtils.isEmpty(addItems)){
-                    mapper.insertListforComplex(addItems);
+                    List<SbInfo> itemsAdd = BeanConverterUtil.copyListProperties(addItems, SbInfo.class);
+                    mapper.insertListforComplex(itemsAdd);
                 }
             }
-            return "总计新增导入:"+ (items.size())  + ",找不到如下型号,已经添加:" + modelError.toString();
+            return "总计新增导入:"+ (items.size());
         } catch (Exception e) {
             throw new BusinessException(e.getMessage());
         }