hfxc226 il y a 2 ans
Parent
commit
5c0011c4a3

+ 151 - 0
platform-dao/src/main/java/com/platform/dao/util/CustomExcelImportUtil.java

@@ -7,6 +7,7 @@ import com.platform.common.util.*;
 import com.platform.dao.dto.sqarepartmanage.SparePartInfoDTO;
 import com.platform.dao.entity.check.CheckJob;
 import com.platform.dao.entity.check.CheckStandard;
+import com.platform.dao.entity.part.PartInfo;
 import com.platform.dao.entity.purchase.*;
 import com.platform.dao.entity.sb.SbInfo;
 import com.platform.dao.entity.sb.SbModel;
@@ -954,6 +955,156 @@ public class CustomExcelImportUtil {
         return result;
     }
 
+    public static List<SbInfoVO> importSbInfoListStandard(InputStream inputstream) throws IOException, InvalidFormatException {
+        if (inputstream == null) {
+            return Collections.emptyList();
+        }
+        Workbook book = null;
+        if (!(inputstream.markSupported())) {
+            inputstream = new PushbackInputStream(inputstream, 8);
+        }
+        if (POIFSFileSystem.hasPOIFSHeader(inputstream)) {
+            book = new HSSFWorkbook(inputstream);
+        } else if (POIXMLDocument.hasOOXMLHeader(inputstream)) {
+            book = new XSSFWorkbook(OPCPackage.open(inputstream));
+        }
+        Sheet sheet = book.getSheetAt(0);
+        int rowCounts = sheet.getLastRowNum();
+        List<SbInfoVO> result = new ArrayList<>(rowCounts);
+        SbInfoVO record = null;
+
+        LocalDateTime now = LocalDateTime.now();
+        StringBuffer error = new StringBuffer();
+        for (int i = 1; i <= rowCounts; i++) {
+            record = new SbInfoVO();
+            Row row = sheet.getRow(i);
+            if(isRowEmpty(row)){
+                continue;
+            }
+            String index = row.getCell(1).getStringCellValue() + "";
+            try {
+                //i,j i:行 j:列
+                record.setId(IdGeneratorUtils.getObjectId());
+                record.setName(StringUtils.getExcelString(row.getCell(0)).replace("'", ""));
+                record.setNo(StringUtils.getExcelString(row.getCell(1)));
+                record.setPositionName(getCellValue(row.getCell(2)));
+                record.setModel(getCellValue(row.getCell(3)).trim());
+                String level = getCellValue(row.getCell(4));
+                if(StringUtils.isBlank(level)){
+                    record.setLevel(1);
+                }else{
+                    record.setLevel(getLevel(level));
+                }
+                record.setTypeName(StringUtils.getExcelString(row.getCell(5)));
+                record.setUseType(getUseType(StringUtils.getExcelString(row.getCell(6))));
+                record.setStatus(SbInfoStatusEnum.IN_USE.getValue());
+                record.setBuyDate(DateUtils.strToLocalDate((getCellValue(row.getCell(7))), DateUtils.PATTERN_YMD));
+                record.setStartDate(DateUtils.strToLocalDate((getCellValue(row.getCell(8))), DateUtils.PATTERN_YMD));
+                record.setWorkYear(Double.valueOf(getCellValue(row.getCell(9))));
+                record.setIsChild((getCellValue(row.getCell(10)).isEmpty()||getCellValue(row.getCell(10)).equals("否"))?0:1);
+                record.setParentSbNo(getCellValue(row.getCell(11)));
+                record.setCreatedTime(now);
+                record.setCreatedUserId("1");
+
+                PartInfo partInfo = new PartInfo();
+                partInfo.setId(IdGeneratorUtils.getObjectId());
+                partInfo.setSbId(record.getId());
+                partInfo.setTypeName(getCellValue(row.getCell(12)));
+                partInfo.setName(getCellValue(row.getCell(13)));
+                partInfo.setNo(getCellValue(row.getCell(14)));
+                String partInfoLevel = row.getCell(15).getStringCellValue();
+                if(partInfoLevel.equals("一级")){
+                    partInfo.setLevel(1);
+                }else  if(partInfoLevel.equals("二级")){
+                    partInfo.setLevel(2);
+                }else  if(partInfoLevel.equals("三级")){
+                    partInfo.setLevel(3);
+                }else {
+                    partInfo.setLevel(1);
+                }
+                partInfo.setCreatedTime(now);
+                partInfo.setCreatedUserId("1");
+                CheckStandard checkStandard = new CheckStandard();
+                checkStandard.setId(IdGeneratorUtils.getObjectId());
+                checkStandard.setSbId(record.getId());
+                checkStandard.setPart(partInfo.getId());
+                checkStandard.setNo(getCellValue(row.getCell(16)));
+                checkStandard.setName(getCellValue(row.getCell(17)));
+                checkStandard.setType(CheckStandardTypeEnum.SPOT.getValue());
+                String checkStandardLevel = row.getCell(18).getStringCellValue();
+                if(checkStandardLevel.equals("一级")){
+                    checkStandard.setLevel(1);
+                }else  if(checkStandardLevel.equals("二级")){
+                    checkStandard.setLevel(2);
+                }else  if(checkStandardLevel.equals("三级")){
+                    checkStandard.setLevel(3);
+                }else {
+                    checkStandard.setLevel(1);
+                }
+
+                String checkUserType = row.getCell(19).getStringCellValue();
+                if(checkUserType.equals("设备使用人")){
+                    checkStandard.setCheckUserType(1);
+                }else  if(checkUserType.equals("设备维修人")){
+                    checkStandard.setCheckUserType(2);
+                }else  if(checkUserType.equals("指定人员")){
+                    checkStandard.setCheckUserType(3);
+                }else {
+                    checkStandard.setCheckUserType(1);
+                }
+
+                checkStandard.setCheckUserId(getCellValue(row.getCell(20)));
+                checkStandard.setPeriod(Integer.valueOf(getCellValue(row.getCell(21))));
+                String periodType = row.getCell(22).getStringCellValue();
+                if(periodType.equals("天")){
+                    checkStandard.setPeriodType(CheckPlanPeriodTypeEnum.DAY.getValue());
+                }else  if(periodType.equals("周")){
+                    checkStandard.setPeriodType(CheckPlanPeriodTypeEnum.WEEK.getValue());
+                }else  if(periodType.equals("月")){
+                    checkStandard.setPeriodType(CheckPlanPeriodTypeEnum.MONTH.getValue());
+                }else  if(periodType.equals("季度")){
+                    checkStandard.setPeriodType(CheckPlanPeriodTypeEnum.SEASON.getValue());
+                }else  if(periodType.equals("年")){
+                    checkStandard.setPeriodType(CheckPlanPeriodTypeEnum.YEAR.getValue());
+                }else  if(periodType.equals("公里")){
+                    checkStandard.setPeriodType(CheckPlanPeriodTypeEnum.MILES.getValue());
+                }else  if(periodType.equals("台时")){
+                    checkStandard.setPeriodType(CheckPlanPeriodTypeEnum.TAISHI.getValue());
+                }
+                checkStandard.setStandardHours(getCellValue(row.getCell(23)));
+                String actionType = row.getCell(24).getStringCellValue();
+                if(actionType.equals("检查紧固")){
+                    checkStandard.setActionType(1);
+                }else  if(actionType.equals("清洁")){
+                    checkStandard.setActionType(2);
+                }else  if(actionType.equals("更换")){
+                    checkStandard.setActionType(3);
+                }else  if(actionType.equals("测量调整")){
+                    checkStandard.setActionType(4);
+                }else {
+                    checkStandard.setActionType(1);
+                }
+                checkStandard.setLastDate(DateUtils.strToLocalDate((getCellValue(row.getCell(25))), DateUtils.PATTERN_YMD));
+                checkStandard.setRequirement(getCellValue(row.getCell(26)));
+                checkStandard.setRemark(getCellValue(row.getCell(27)));
+                checkStandard.setCreatedTime(now);
+                checkStandard.setCreatedUserId("1");
+                record.setCheckStandard(checkStandard);
+                record.setPartInfo(partInfo);
+            } catch (Exception e) {
+                e.printStackTrace();
+                error.append(index).append("错误地址:第"+i+"行");
+            }
+            result.add(record);
+        }
+
+        String errorStr = error.toString();
+        if (StringUtils.isNotEmpty(errorStr)) {
+            throw new BusinessException(String.format("导入异常,以下行数据有问题:%s", errorStr.substring(0, errorStr.length())));
+        }
+        return result;
+    }
+
     public static List<SbInfoMeasureVO> importSbInfoMeasureList(InputStream inputstream) throws IOException, InvalidFormatException {
         if (inputstream == null) {
             return Collections.emptyList();

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

@@ -1,6 +1,8 @@
 package com.platform.dao.vo.sb;
 
 import com.platform.common.bean.BaseVO;
+import com.platform.dao.entity.check.CheckStandard;
+import com.platform.dao.entity.part.PartInfo;
 import com.platform.dao.entity.upms.SysFile;
 import lombok.Data;
 import lombok.EqualsAndHashCode;
@@ -491,4 +493,14 @@ public class SbInfoVO extends BaseVO implements Serializable {
      * 关联的维修部门ID
      */
     private String repairDeptId;
+
+    /**
+     *
+     */
+    private PartInfo PartInfo;
+
+    /**
+     *
+     */
+    private CheckStandard checkStandard;
 }

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

@@ -418,6 +418,8 @@ public class SbInfoController {
             result = sbInfoService.importListByAdd( file);
         }else if(type == 2){
             result = sbInfoService.importListByUpdateALl(file);
+        }else if(type == 3){
+            result = sbInfoService.importListByAddWithStandard(file);
         }
         return new R<>(result);
     }

+ 0 - 4
platform-service/src/main/java/com/platform/service/part/impl/PartTypeServiceImpl.java

@@ -66,10 +66,6 @@ public class PartTypeServiceImpl extends BaseServiceImpl<PartTypeMapper, PartTyp
 
     @Override
     public PartType saveModelByDTO(PartTypeDTO model) {
-        Weekend<PartType> weekend = new Weekend<>(PartType.class);
-        weekend.weekendCriteria().andIsNotNull(PartType::getId);
-        Integer count = mapper.selectCountByExample(weekend);
-        model.setNo(IdGeneratorUtils.getPartTypeNo(++count));
         return super.saveModelByDTO(model);
     }
 

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

@@ -6,6 +6,7 @@ import com.platform.dao.dto.sb.SbInfoDTO;
 import com.platform.dao.entity.sb.SbInfo;
 import com.platform.dao.vo.sb.*;
 import com.platform.service.base.IBaseService;
+import org.springframework.transaction.annotation.Transactional;
 import org.springframework.web.multipart.MultipartFile;
 
 import java.util.List;
@@ -270,6 +271,9 @@ public interface SbInfoService extends IBaseService<SbInfo, SbInfoDTO> {
      */
     void updateQrCode(SbInfoDTO model);
 
+    @Transactional(rollbackFor = Exception.class)
+    String importListByAddWithStandard(MultipartFile file);
+
     String importListByAdd(MultipartFile file);
     String importListByUpdateALl(MultipartFile file);
 

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

@@ -25,8 +25,10 @@ import com.platform.dao.dto.upms.SysDeptDTO;
 import com.platform.dao.dto.upms.SysUserDeptDTO;
 import com.platform.dao.dto.workplace.WorkplaceBacklogDTO;
 import com.platform.dao.dto.workplace.WorkplaceBacklogUserDTO;
+import com.platform.dao.entity.check.CheckStandard;
 import com.platform.dao.entity.firm.FirmProducer;
 import com.platform.dao.entity.part.PartInfo;
+import com.platform.dao.entity.part.PartType;
 import com.platform.dao.entity.repair.RepairApplicationForm;
 import com.platform.dao.entity.sb.*;
 import com.platform.dao.entity.upms.SysDept;
@@ -34,8 +36,10 @@ import com.platform.dao.entity.upms.SysFile;
 import com.platform.dao.entity.upms.SysUser;
 import com.platform.dao.entity.upms.SysUserDept;
 import com.platform.dao.enums.*;
+import com.platform.dao.mapper.check.CheckStandardMapper;
 import com.platform.dao.mapper.firm.FirmProducerMapper;
 import com.platform.dao.mapper.part.PartInfoMapper;
+import com.platform.dao.mapper.part.PartTypeMapper;
 import com.platform.dao.mapper.repair.RepairApplicationFormMapper;
 import com.platform.dao.mapper.sb.*;
 import com.platform.dao.mapper.upms.SysDeptMapper;
@@ -118,12 +122,14 @@ public class SbInfoServiceImpl extends BaseServiceImpl<SbInfoMapper, SbInfo, SbI
     private final PartInfoService partInfoService;
     private final SbModelSpareBomService sbModelSpareBomService;
     private final CheckStandardService checkStandardService;
+    private final CheckStandardMapper checkStandardMapper;
     private final WorkplaceBacklogUserMapper backlogUserMapper;
     private final ActivitiBusinessService activitiBusinessService;
     private final SbInfoMapper sbInfoMapper;
     private final SbModelSpareBomMapper sbModelSpareBomMapper;
     private final PartInfoMapper partInfoMapper;
 
+    private final PartTypeMapper partTypeMapper;
     private final String useArea = "5e64ac691c527828b2114da0";
     private final String useCompany = "6063f905eb190003685af6d4";
     private final String useProject = "6063f92ceb190003685af6d9";
@@ -1786,6 +1792,96 @@ public class SbInfoServiceImpl extends BaseServiceImpl<SbInfoMapper, SbInfo, SbI
         }
     }
 
+
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public String importListByAddWithStandard(MultipartFile file) {
+        try {
+            List<SbInfoVO> items = CustomExcelImportUtil.importSbInfoListStandard(file.getInputStream());
+            if (!CollectionUtils.isEmpty(items)) {
+                List<SbInfoVO> addItems = new ArrayList<SbInfoVO>();
+                List<CheckStandard> checkStandardList = new ArrayList<CheckStandard>();
+                List<PartInfo> partInfoList = new ArrayList<PartInfo>();
+                List<SbPosition> positionList = sbPositionMapper.selectAll();
+                List<SbType> typeList = sbTypeMapper.selectAll();
+                List<PartType> partTypeList = partTypeMapper.selectAll();
+                List<SysUser> users = sysUserMapper.selectAll();
+
+                for (SbInfoVO item : items) {
+                    // 设备位置
+                    boolean findPosition = false;
+                    for (SbPosition position : positionList) {
+                        if (position.getName().equals(item.getPositionName())) {
+                            item.setPositionId(position.getId());
+                            findPosition = true;
+                            break;
+                        }
+                    }
+                    if (!findPosition) {
+                        throw new BusinessException("找不到设备位置,请先添加,位置名称是:" + item.getPositionName());
+                    }
+
+                    // 设备类型
+                    boolean find = false;
+                    for (SbType type : typeList) {
+                        if (type.getName().equals(item.getTypeName())) {
+                            item.setTypeId(type.getId());
+                            find = true;
+                            break;
+                        }
+                    }
+                    if (!find) {
+                        throw new BusinessException("找不到设备类型,请先添加:" + item.getTypeName());
+                    }
+                    // 父设备
+                    // 部位类型
+                    PartInfo partInfo = item.getPartInfo();
+                    boolean findPartType = false;
+                    for (PartType type : partTypeList) {
+                        if (type.getName().equals(partInfo.getTypeName())) {
+                            partInfo.setTypeId(type.getId());
+                            findPartType = true;
+                            break;
+                        }
+                    }
+                    if (!findPartType) {
+                        throw new BusinessException("找不到部位类型,请先添加:" + partInfo.getTypeName());
+                    }
+                    // 点检标准;执行人
+                    CheckStandard checkStandard = item.getCheckStandard();
+                    boolean findSaveUser = false;
+                    for (SysUser user : users) {
+                        if (checkStandard.getCheckUserId().equals(user.getRealName())) {
+                            checkStandard.setCheckUserId(user.getUserId());
+                            findSaveUser = true;
+                            break;
+                        }
+                    }
+                    if (!findSaveUser) {
+                        throw new BusinessException("找不到点检执行人员,请先添加, 名称" + checkStandard.getCheckUserId());
+                    }
+                    checkStandardList.add(checkStandard);
+                    partInfoList.add(partInfo);
+                    addItems.add(item);
+                }
+                if (!CollectionUtils.isEmpty(addItems)) {
+                    List<SbInfo> itemsAdd = BeanConverterUtil.copyListProperties(addItems, SbInfo.class);
+                    mapper.insertListforComplex(itemsAdd);
+                }
+                if (!CollectionUtils.isEmpty(partInfoList)) {
+                    partInfoMapper.insertListforComplex(partInfoList);
+                }
+                if (!CollectionUtils.isEmpty(checkStandardList)) {
+                    checkStandardMapper.insertListforComplex(checkStandardList);
+                }
+            }
+            return "总计新增导入:" + (items.size());
+        } catch (Exception e) {
+            e.printStackTrace();
+            throw new BusinessException(e.getMessage());
+        }
+    }
+
     @Override
     @Transactional(rollbackFor = Exception.class)
     public String importListByAdd(MultipartFile file) {