xiongchao 3 жил өмнө
parent
commit
083f075058

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

@@ -29,6 +29,10 @@ public class CheckStandardDTO extends BaseDTO implements Serializable {
      */
     @NotNull(groups = {UpdateGroup.class}, message = "ID不能为空")
     private String id;
+    /**
+     * 排序
+     */
+    private Integer sort;
     /**
      * 设备id
      */
@@ -59,6 +63,10 @@ public class CheckStandardDTO extends BaseDTO implements Serializable {
      * 周期类型: 参考数据字典
      */
     private Integer periodType;
+    /**
+     * 负责人类型: 参考数据字典:1车间,2维修员,3厂商
+     */
+    private Integer checkUserType;
     /**
      * 上次生成时间
      */

+ 8 - 0
platform-dao/src/main/java/com/platform/dao/entity/check/CheckStandard.java

@@ -46,6 +46,10 @@ public class CheckStandard implements Serializable{
      * 检查类型: 1-点检 2-巡检
      */
     private Integer type;
+    /**
+     * 排序
+     */
+    private Integer sort;
     /**
      * 计划周期
      */
@@ -63,6 +67,10 @@ public class CheckStandard implements Serializable{
      * 周期类型: 参考数据字典
      */
     private Integer periodType;
+    /**
+     * 负责人类型: 参考数据字典:1车间,2维修员,3厂商
+     */
+    private Integer checkUserType;
     /**
      * 周期类型: 参考数据字典
      */

+ 6 - 3
platform-dao/src/main/java/com/platform/dao/enums/CheckStandardTypeEnum.java

@@ -18,10 +18,13 @@ public enum CheckStandardTypeEnum {
      */
     SPOT(1),
     /**
-     * 巡检
+     * 保养
      */
-    POLLING(2)
-    ;
+    POLLING(2),
+    /**
+     * 润滑
+     */
+    RUN(3);
     private final Integer value;
 
 }

+ 107 - 6
platform-dao/src/main/java/com/platform/dao/util/CustomExcelImportUtil.java

@@ -4,11 +4,13 @@ import com.platform.common.exception.BusinessException;
 import com.platform.common.model.UserInfo;
 import com.platform.common.util.*;
 import com.platform.dao.dto.sqarepartmanage.SparePartInfoDTO;
+import com.platform.dao.entity.check.CheckStandard;
 import com.platform.dao.entity.purchase.*;
 import com.platform.dao.entity.sb.SbInfo;
 import com.platform.dao.entity.sb.SbModel;
 import com.platform.dao.entity.sqarepartmanage.SparePartInfo;
 import com.platform.dao.entity.store.SpareStore;
+import com.platform.dao.enums.CheckStandardTypeEnum;
 import com.platform.dao.vo.export.sb.ExportSbInfoVO;
 import com.platform.dao.vo.query.sparepartmanage.SparePartInfoVO;
 import com.platform.dao.vo.sb.SbInfoVO;
@@ -478,15 +480,13 @@ public class CustomExcelImportUtil {
                 "C:\\Users\\cyz\\Desktop\\固定资产0207(1)\\固定资产折旧明细表-2020年12月-苏丹.xls",
                 "C:\\Users\\cyz\\Desktop\\固定资产0207(1)\\固定资产折旧明细表-2020年12月-坦桑尼亚.xls",
                 "C:\\Users\\cyz\\Desktop\\固定资产0207(1)\\固定资产折旧明细表-2020年12月-苏丹.xls"};*/
-        String[] files = {"C:\\Users\\cyz\\Desktop\\2021.5.31 注塑设备台账导入文件.xls"};
+        String[] files = {"C:\\Users\\cyz\\Desktop\\C-001 (OS-M235) - 副本.xls"};
         InputStream inputstream = new FileInputStream(files[0]);
         LocalDateTime now = LocalDateTime.now();
        //  List<SparePartInfoVO> list = importSparePartInfoList(now, inputstream);
-        List<SbInfoVO> list = importSbInfoList(inputstream);
-        // List<SbModel> list = importModelList(inputstream);
-        //List<SbInfo> list = importSbInfoListForUpdateValue(inputstream);
+        // List<SbInfoVO> list = importSbInfoList(inputstream);
+        List<CheckStandard> list = importCheckStandardList(inputstream);
 
-        //List<SparePartInfoVO> list = importSparePartInfoListForUpdate(LocalDateTime.now(), inputstream);
         list.forEach(item -> {
             System.out.println(item.toString());
         });
@@ -862,7 +862,7 @@ public class CustomExcelImportUtil {
                 }else{
                     record.setInitialValue(new Double(value));
                 }
-                record.setTypeId(row.getCell(7).getStringCellValue().trim());
+                record.setTypeName(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)));
@@ -923,6 +923,107 @@ public class CustomExcelImportUtil {
         return result;
     }
 
+    /**
+     * 导入点检标准
+     *
+     * @param inputstream
+     * @return
+     * @throws IOException
+     * @throws InvalidFormatException
+     */
+    public static List<CheckStandard> importCheckStandardList(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<CheckStandard> result = new ArrayList<>(rowCounts);
+        CheckStandard record = null;
+        String sbNo = sheet.getRow(4).getCell(13).getStringCellValue();
+        StringBuffer error = new StringBuffer();
+        for (int i = 12; i <= rowCounts; i++) {
+            record = new CheckStandard();
+            Row row = sheet.getRow(i);
+            if(isRowEmpty(row)){
+                continue;
+            }
+            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("20");
+                record.setEnable(1);
+                setRemark(row, record);
+            } catch (Exception e) {
+                throw new BusinessException("导入异常,行号:"+ i + ", 错误信息" + e.getMessage() +  ", 错误原因" + e.getCause());
+            }
+            result.add(record);
+        }
+        return result;
+    }
+
+    private static void setRemark(Row row, CheckStandard record) {
+        if(StringUtils.isNotEmpty(row.getCell(7).getStringCellValue())){
+            record.setCheckUserType(1);
+            record.setRemark("车间");
+        }else  if(StringUtils.isNotEmpty(row.getCell(7).getStringCellValue())){
+            record.setCheckUserType(2);
+            record.setRemark("维修");
+        }else  if(StringUtils.isNotEmpty(row.getCell(7).getStringCellValue())){
+            record.setCheckUserType(3);
+            record.setRemark("厂家");
+        }else{
+            record.setCheckUserType(1);
+            record.setRemark("车间");
+        }
+    }
+
+    private static void setPeriod(Row row, CheckStandard record) {
+     if(StringUtils.isNotBlank(row.getCell(0).getStringCellValue())){
+        record.setPeriod(1);
+        record.setPeriodType(1);
+     }else if(StringUtils.isNotBlank(row.getCell(1).getStringCellValue())){
+         record.setPeriod(1);
+         record.setPeriodType(2);
+     }else if(StringUtils.isNotBlank(row.getCell(2).getStringCellValue())){
+         record.setPeriod(1);
+         record.setPeriodType(3);
+     }else if(StringUtils.isNotBlank(row.getCell(3).getStringCellValue())){
+         record.setPeriod(1);
+         record.setPeriodType(4);
+     }else if(StringUtils.isNotBlank(row.getCell(4).getStringCellValue())){
+         record.setPeriod(2);
+         record.setPeriodType(4);
+     }else if(StringUtils.isNotBlank(row.getCell(5).getStringCellValue())){
+         record.setPeriod(1);
+         record.setPeriodType(5);
+     }else if(StringUtils.isNotBlank(row.getCell(6).getStringCellValue())){
+         record.setPeriod(3);
+         record.setPeriodType(5);
+     }else{
+         record.setPeriod(1);
+         record.setPeriodType(1);
+     }
+
+    }
+
     public static List<SbInfo> importSbInfoListForUpdateValue(InputStream inputstream) throws IOException, InvalidFormatException {
         if (inputstream == null) {
             return Collections.emptyList();

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

@@ -23,7 +23,10 @@ import java.util.List;
 @Accessors(chain = true)
 @EqualsAndHashCode(callSuper = true)
 public class CheckStandardVO extends BaseVO implements Serializable{
-
+    /**
+     * 排序
+     */
+    private Integer sort;
     /**
      * 主键
      */
@@ -60,6 +63,10 @@ public class CheckStandardVO extends BaseVO implements Serializable{
      * 周期类型: 参考数据字典
      */
     private Integer actionType;
+    /**
+     * 负责人类型: 参考数据字典:1车间,2维修员,3厂商
+     */
+    private Integer checkUserType;
     /**
      * 检查类型: 1-点检 2-巡检
      */

+ 11 - 4
platform-dao/src/main/resources/mapper/check/CheckStandardMapper.xml

@@ -11,10 +11,12 @@
                                      checkstandard.no,
                                      checkstandard.type,
                                      checkstandard.period,
-                                     checkstandard.periodType,
-                                     checkstandard.actionType,
+                                     checkstandard.period_type,
+                                     checkstandard.action_type,
+                                     checkstandard.check_user_type,
                                      checkstandard.enable,
                                      checkstandard.part,
+checkstandard.sort,
                                      checkstandard.requirement,
                                      checkstandard.remark,
                                      checkstandard.created_user_id,
@@ -30,12 +32,14 @@
                                      checkstandard.real_hours,
                                      checkstandard.check_user_id,
                                      checkstandard.name,
+checkstandard.sort,
                                      checkstandard.no,
                                      checkstandard.type,
                                      checkstandard.period,
                                      checkstandard.part,
-                                     checkstandard.periodType,
-                                     checkstandard.actionType,
+                                     checkstandard.period_type,
+                                     checkstandard.action_type,
+                                     checkstandard.check_user_type,
                                      checkstandard.enable,
                                      checkstandard.requirement,
                                      checkstandard.remark,
@@ -68,6 +72,9 @@
         <if test="periodType != null">
             and checkstandard.period_type = #{periodType}
         </if>
+        <if test="checkUserType != null">
+            and checkstandard.check_user_type = #{checkUserType}
+        </if>
         <if test="actionType != null">
             and checkstandard.action_type = #{actionType}
         </if>

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

@@ -16,6 +16,8 @@ import org.springframework.web.bind.annotation.*;
 import lombok.AllArgsConstructor;
 import com.platform.common.bean.AbstractPageResultBean;
 import com.platform.rest.log.annotation.SysLog;
+import org.springframework.web.multipart.MultipartFile;
+
 import java.util.List;
 import javax.servlet.http.HttpServletResponse;
 
@@ -183,4 +185,18 @@ public class CheckStandardController {
     ExcelUtil.exportResponseDict(response, ExportCheckStandardVO.class, BeanConverterUtil.copyListProperties(list, ExportCheckStandardVO.class), "点检标准");
   }
 
+    /**
+     * 导入保养标准
+     *
+     * @param file bom excel文件
+     *
+     * @return R
+     */
+    @SysLog("新增导入设备的保养标准")
+    @PostMapping("/import")
+    public R importExcelByUpdate(@RequestParam("file") MultipartFile file) throws Exception {
+        String result = "";
+        result = checkStandardService.importListByAdd( file);
+        return new R<>(result);
+    }
 }

+ 4 - 0
platform-service/src/main/java/com/platform/service/check/CheckStandardService.java

@@ -6,6 +6,8 @@ import com.platform.dao.entity.check.CheckStandard;
 import com.platform.dao.entity.sqarepartmanage.SparePartInfo;
 import com.platform.dao.vo.query.check.CheckStandardVO;
 import com.platform.service.base.IBaseService;
+import org.springframework.web.multipart.MultipartFile;
+
 import java.util.List;
 
 /**
@@ -45,4 +47,6 @@ public interface CheckStandardService extends IBaseService<CheckStandard, CheckS
     public void generate(CheckJobDTO checkJobDTO);
 
     String copyFormSb(CheckStandardDTO model);
+
+    String importListByAdd(MultipartFile file);
 }

+ 68 - 4
platform-service/src/main/java/com/platform/service/check/impl/CheckStandardServiceImpl.java

@@ -3,10 +3,7 @@ import cn.hutool.core.collection.CollectionUtil;
 import com.platform.common.bean.AbstractPageResultBean;
 import com.github.pagehelper.PageHelper;
 import com.platform.common.exception.BusinessException;
-import com.platform.common.util.BeanConverterUtil;
-import com.platform.common.util.DateUtils;
-import com.platform.common.util.IdGeneratorUtils;
-import com.platform.common.util.ListUtils;
+import com.platform.common.util.*;
 import com.platform.dao.bean.MyPage;
 import com.platform.dao.dto.check.CheckJobDTO;
 import com.platform.dao.dto.check.CheckStandardDTO;
@@ -20,9 +17,12 @@ import com.platform.dao.entity.check.CheckStandardParam;
 import com.platform.dao.entity.maintain.MaintainProjectStandardRelation;
 import com.platform.dao.entity.maintain.MaintainStandardParam;
 import com.platform.dao.entity.part.PartInfo;
+import com.platform.dao.entity.sb.SbInfo;
+import com.platform.dao.entity.sb.SbType;
 import com.platform.dao.entity.sqarepartmanage.SparePartInfo;
 import com.platform.dao.entity.store.InStoreDetail;
 import com.platform.dao.entity.upms.SysFile;
+import com.platform.dao.entity.upms.SysUser;
 import com.platform.dao.enums.CheckJobStatusEnum;
 import com.platform.dao.enums.CheckPlanPeriodTypeEnum;
 import com.platform.dao.enums.SysFileTypeEnum;
@@ -32,14 +32,20 @@ import com.platform.dao.mapper.check.CheckStandardMapper;
 import com.platform.dao.mapper.check.CheckStandardParamMapper;
 import com.platform.dao.mapper.maintain.MaintainProjectStandardRelationMapper;
 import com.platform.dao.mapper.part.PartInfoMapper;
+import com.platform.dao.mapper.sb.SbInfoMapper;
 import com.platform.dao.mapper.upms.SysFileMapper;
+import com.platform.dao.mapper.upms.SysUserMapper;
+import com.platform.dao.util.CustomExcelImportUtil;
 import com.platform.dao.vo.query.check.CheckStandardVO;
+import com.platform.dao.vo.sb.SbInfoVO;
 import com.platform.service.check.CheckStandardParamService;
 import com.platform.service.check.CheckStandardService;
 import com.platform.service.part.PartInfoService;
 import org.springframework.stereotype.Service;
 import com.platform.service.base.impl.BaseServiceImpl;
 import org.springframework.transaction.annotation.Transactional;
+import org.springframework.util.CollectionUtils;
+import org.springframework.web.multipart.MultipartFile;
 import tk.mybatis.mapper.weekend.Weekend;
 import tk.mybatis.mapper.weekend.WeekendCriteria;
 import lombok.AllArgsConstructor;
@@ -67,6 +73,10 @@ public class CheckStandardServiceImpl extends BaseServiceImpl<CheckStandardMappe
     private CheckJobMapper checkJobMapper;
     private PartInfoService partInfoService;
     private final SysFileMapper sysFileMapper;
+
+    private final SysUserMapper sysUserMapper;
+
+    private final SbInfoMapper sbInfoMapper;
     @Override
     public boolean cascadingDeleteByKey(String id) {
         int result = mapper.deleteByPrimaryKey(id);
@@ -332,6 +342,60 @@ public class CheckStandardServiceImpl extends BaseServiceImpl<CheckStandardMappe
         }
         endDate = DateUtils.plus(endDate, -1, ChronoUnit.DAYS);
         checkJob.setEndTime(endDate);
+    }
+
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public String importListByAdd(MultipartFile file) {
+        int addNum = 0;
+        List<String> modelError = new ArrayList<String>();
+        try {
+            List<CheckStandard> items = CustomExcelImportUtil.importCheckStandardList(file.getInputStream());
+            if (!CollectionUtils.isEmpty(items)) {
+                List<CheckStandard> addItems = new ArrayList<CheckStandard>();
+                List<SysUser> users = sysUserMapper.selectAll();
+                List<SbInfo> sbInfoList = sbInfoMapper.selectAll();
+                LocalDateTime now = LocalDateTime.now();
+                for (CheckStandard item : items) {
+                    item.setCreatedTime(now);
+                    item.setCheckUserId(SecurityUtils.getUserInfo().getUserId());
+                    item.setUpdateTime(now);
+                    item.setUpdateUserId(SecurityUtils.getUserInfo().getUserId());
+                    // 根据负责人类型查找用户,使用人员的名称查抄
+                    boolean findSaveUser = false;
+                    if(item.getCheckUserType() == 1){
+                        for (SbInfo info : sbInfoList) {
+                            if(info.getNo().equals(item.getSbId())){
+                                item.setSbId(info.getId());
+                                item.setCheckUserId(info.getSaveUser());
+                                findSaveUser = true;
+                                break;
+                            }
+                        }
+                    } else if(item.getCheckUserType() == 2){// 设备的维修员
+                        for (SbInfo info : sbInfoList) {
+                            if(info.getNo().equals(item.getSbId())){
+                                item.setSbId(info.getId());
+                                item.setCheckUserId(info.getRepairUser());
+                                findSaveUser = true;
+                                break;
+                            }
+                        }
+                    }else if(item.getCheckUserType() == 3){// 厂家:这个分配给谁?
 
+                    }
+                    if(!findSaveUser){
+                        throw new BusinessException("找不到设备,请先添加,设备新号:" + item.getSbId());
+                    }
+                    addItems.add(item);
+                }
+                if(!CollectionUtils.isEmpty(addItems)){
+                    mapper.insertListforComplex(addItems);
+                }
+            }
+            return "总计新增导入:"+ (items.size());
+        } catch (Exception e) {
+            throw new BusinessException(e.getMessage());
+        }
     }
 }

+ 14 - 1
platform-service/src/main/java/com/platform/service/sb/impl/SbInfoServiceImpl.java

@@ -91,7 +91,7 @@ public class SbInfoServiceImpl extends BaseServiceImpl<SbInfoMapper, SbInfo, SbI
     private final SbStopLogMapper sbStopLogMapper;
 
     private final SysUserMapper sysUserMapper;
-
+    private final SbTypeMapper sbTypeMapper;
     private final SbPositionMapper sbPositionMapper;
 
     private final SysFileMapper sysFileMapper;
@@ -986,6 +986,19 @@ public class SbInfoServiceImpl extends BaseServiceImpl<SbInfoMapper, SbInfo, SbI
                             throw new BusinessException("找不到第二维修人员,请先添加, 名称" + item.getRepairUser());
                         }
                     }
+
+                    List<SbType> typeList = sbTypeMapper.selectAll();
+                    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());
+                    }
                     addItems.add(item);
                 }
                 if(!CollectionUtils.isEmpty(addItems)){