Browse Source

保养标准导出实现新增,删除,修改功能

2 years ago
parent
commit
f9ce0d7196

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

@@ -216,16 +216,31 @@ public class CheckStandardController {
     /**
      * 导入保养标准
      *
-     * @param files bom excel文件
+     * @param file bom excel文件
      *
      * @return R
      */
     @SysLog("新增导入设备的保养标准")
+    @PostMapping("/import/execute")
+    public R importList( @RequestParam("files") MultipartFile file) throws Exception {
+        checkStandardService.importList(file);
+        return new R();
+    }
+
+
+    /**
+     * 导入保养标准(包括修改,新增,删除)
+     *
+     * @param files bom excel文件
+     *
+     * @return R
+     */
+    @SysLog("导入设备的保养标准")
     @PostMapping(value="/import",headers = "content-type=multipart/form-data")
     public R importListByAdd( @RequestParam("files") MultipartFile[] files) throws Exception {
         String result ="";
         for(MultipartFile file: files){
-            result = result + checkStandardService.importListByAdd(file);
+            result = result + checkStandardService.importList(file);
         }
         return new R<>(result);
     }

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

@@ -11,8 +11,10 @@ import com.platform.dao.vo.query.check.CheckStandardSpareVO;
 import com.platform.dao.vo.query.check.CheckStandardVO;
 import com.platform.dao.vo.sb.SbInfoVO;
 import com.platform.service.base.IBaseService;
+import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
 import org.springframework.web.multipart.MultipartFile;
 
+import java.io.IOException;
 import java.util.List;
 
 /**
@@ -59,6 +61,8 @@ public interface CheckStandardService extends IBaseService<CheckStandard, CheckS
 
     String importListByAddOldVersion(MultipartFile file);
 
+    String importList(MultipartFile file) throws IOException, InvalidFormatException, Exception;
+
     void genSpareWarnTask(int month, int type);
     void updateBatch(List<CheckStandard> updateStandardList);
     /**

+ 93 - 0
platform-service/src/main/java/com/platform/service/check/impl/CheckStandardServiceImpl.java

@@ -20,6 +20,7 @@ import com.platform.dao.entity.maintain.MaintainStandardParam;
 import com.platform.dao.entity.part.PartInfo;
 import com.platform.dao.entity.repair.RepairApplicationForm;
 import com.platform.dao.entity.sb.SbInfo;
+import com.platform.dao.entity.sb.SbInspectionFill;
 import com.platform.dao.entity.sb.SbType;
 import com.platform.dao.entity.sqarepartmanage.SparePartInfo;
 import com.platform.dao.entity.store.InStoreDetail;
@@ -33,7 +34,9 @@ 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.util.ExcelUtil;
 import com.platform.dao.util.MessageTemplateUtil;
+import com.platform.dao.vo.export.check.ExportCheckStandardVO;
 import com.platform.dao.vo.query.check.CheckStandardSpareVO;
 import com.platform.dao.vo.query.check.CheckStandardVO;
 import com.platform.dao.vo.sb.SbInfoVO;
@@ -43,6 +46,7 @@ import com.platform.service.check.CheckStandardSpareService;
 import com.platform.service.event.WorkplaceBacklogEvent;
 import com.platform.service.part.PartInfoService;
 import com.platform.service.util.SysFileUtils;
+import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
 import org.springframework.stereotype.Service;
 import com.platform.service.base.impl.BaseServiceImpl;
 import org.springframework.transaction.annotation.Transactional;
@@ -52,6 +56,7 @@ import tk.mybatis.mapper.weekend.Weekend;
 import tk.mybatis.mapper.weekend.WeekendCriteria;
 import lombok.AllArgsConstructor;
 
+import java.io.IOException;
 import java.time.LocalDate;
 import java.time.LocalDateTime;
 import java.time.LocalTime;
@@ -588,6 +593,94 @@ public class CheckStandardServiceImpl extends BaseServiceImpl<CheckStandardMappe
         }
     }
 
+    private void packageSbInfoAndCheckStandard(SbInfo sbInfo,ExportCheckStandardVO vo,String sbId,CheckStandard checkStandard ) {
+        if (sbId == null) {
+            sbInfo.setNo(vo.getSbNo());
+            sbInfo = sbInfoMapper.selectOne(sbInfo);
+            if (sbInfo==null){
+                throw new BusinessException("未找到设备编号为"+vo.getSbNo()+"的编号!");
+            }
+        }
+//                    if (vo.getSbLevel().trim().equals("A级")){
+//                        sbInfo.setLevel(1);
+//                    }else if (vo.getSbLevel().trim().equals("B级")){
+//                        sbInfo.setLevel(2);
+//                    }else if (vo.getSbLevel().trim().equals("C级")){
+//                        sbInfo.setLevel(3);
+//                    }
+        sbInfo.setLevel(vo.getSbLevel());
+        SysUser user = new SysUser();
+        user.setRealName(vo.getRepairUserName());
+        user = sysUserMapper.selectOne(user);
+        if (user==null){
+            throw new BusinessException("未找到名为为"+vo.getRepairUserName()+"的维修负责人!");
+        }
+        sbInfo.setRepairUser(user.getUserId());
+
+        checkStandard.setCreatedTime(LocalDateTime.now());
+        checkStandard.setCheckUserId(SecurityUtils.getUserInfo().getUserId());
+        checkStandard.setUpdateTime(LocalDateTime.now());
+        checkStandard.setUpdateUserId(SecurityUtils.getUserInfo().getUserId());
+
+        checkStandard.setNo(vo.getNo());
+        checkStandard.setRequirement(vo.getRequirement());
+        checkStandard.setRemark(vo.getRemark());
+        checkStandard.setPeriod(vo.getPeriod());
+        checkStandard.setPeriodType(vo.getPeriodType());
+        checkStandard.setStandardHours(vo.getStandardHours());
+
+        if (checkStandard.getCheckUserType() == 1) {
+            checkStandard.setSbId(sbInfo.getId());
+            checkStandard.setCheckUserId(sbInfo.getSaveUser());
+        }
+        if (checkStandard.getCheckUserType() == 2 || checkStandard.getCheckUserType() == 3) {// 设备的维修员
+            checkStandard.setSbId(sbInfo.getId());
+            checkStandard.setCheckUserId(sbInfo.getRepairUser());
+        }
+    }
+
+    @Override
+    public String importList(MultipartFile file) throws Exception{
+        //查询所有的保养任务标准id
+        List<CheckStandard> standards = mapper.select(null);
+        StringBuffer sb = new StringBuffer();
+        for (CheckStandard standard:standards){
+            sb.append(standard.getId()).append(",");
+        }
+        String idStr = sb.toString();
+        List<ExportCheckStandardVO> list = ExcelUtil.importExcel(file.getInputStream(), ExportCheckStandardVO.class, 0);
+        String sbId=null;
+        SbInfo sbInfo = new SbInfo();
+        CheckStandard checkStandard = new CheckStandard();
+        for (ExportCheckStandardVO vo:list){
+            if (StringUtils.isNotBlank(vo.getId()) && idStr.contains(vo.getId())){
+                if (StringUtils.isNotBlank(vo.getNo())){
+                    //修改
+                    packageSbInfoAndCheckStandard(sbInfo,vo,sbId,checkStandard);
+                    sbInfoMapper.updateByPrimaryKey(sbInfo);
+                    mapper.updateByPrimaryKey(checkStandard);
+                    }
+                else{
+                    //no为空,删除
+                    CheckStandard standard = new CheckStandard();
+                    standard.setId(vo.getId());
+                    mapper.delete(standard);
+                }
+
+                }else if (StringUtils.isNotBlank(vo.getId()) && !idStr.contains(vo.getId())){
+                //新增
+                    packageSbInfoAndCheckStandard(sbInfo,vo,sbId,checkStandard);
+                    mapper.insert(checkStandard);
+            }
+
+
+            }
+            return null;
+        }
+
+
+
+
     /**
      * 查询备件预警
      * @param month 距离当前时间的几个月