|
@@ -1,11 +1,13 @@
|
|
|
package com.persagy.fm.sop.service.impl;
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
+import cn.hutool.core.map.MapUtil;
|
|
|
+import cn.hutool.core.text.CharSequenceUtil;
|
|
|
+import cn.hutool.core.util.EnumUtil;
|
|
|
+import cn.hutool.core.util.NumberUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
-import cn.hutool.poi.excel.ExcelUtil;
|
|
|
-import cn.hutool.poi.excel.ExcelWriter;
|
|
|
-import cn.hutool.poi.excel.RowUtil;
|
|
|
-import cn.hutool.poi.excel.StyleSet;
|
|
|
+import cn.hutool.poi.excel.*;
|
|
|
+import cn.hutool.poi.excel.cell.CellHandler;
|
|
|
import cn.hutool.poi.excel.cell.CellUtil;
|
|
|
import cn.hutool.poi.excel.cell.FormulaCellValue;
|
|
|
import com.alibaba.excel.util.SheetUtils;
|
|
@@ -18,17 +20,24 @@ import com.persagy.fm.common.constant.enums.ResultEnum;
|
|
|
import com.persagy.fm.common.model.vo.BaseVo;
|
|
|
import com.persagy.fm.common.model.vo.GeneralDictVo;
|
|
|
import com.persagy.fm.common.service.DownloadService;
|
|
|
+import com.persagy.fm.common.utils.FileUtil;
|
|
|
import com.persagy.fm.sop.client.SaasClient;
|
|
|
import com.persagy.fm.sop.constant.SopCommonConst;
|
|
|
-import com.persagy.fm.sop.enums.ClassTypeEnum;
|
|
|
-import com.persagy.fm.sop.enums.ObjTypeEnum;
|
|
|
-import com.persagy.fm.sop.enums.SheetNameEnum;
|
|
|
-import com.persagy.fm.sop.model.dto.InfoPointsBean;
|
|
|
-import com.persagy.fm.sop.model.dto.ObjBean;
|
|
|
+import com.persagy.fm.sop.constant.SopQueryConst;
|
|
|
+import com.persagy.fm.sop.entity.CustomInfoPoint;
|
|
|
+import com.persagy.fm.sop.entity.Sop;
|
|
|
+import com.persagy.fm.sop.enums.*;
|
|
|
+import com.persagy.fm.sop.model.dto.*;
|
|
|
+import com.persagy.fm.sop.model.vo.SaveSopVo;
|
|
|
import com.persagy.fm.sop.service.IBatchHandleSopService;
|
|
|
+import com.persagy.fm.sop.service.IProjectSopService;
|
|
|
+import com.persagy.fm.sop.service.ISopService;
|
|
|
import com.persagy.fm.sop.service.ObjService;
|
|
|
+import com.persagy.fm.sop.validator.ProjectInsert;
|
|
|
+import com.persagy.fm.sop.validator.ProjectUpdate;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
import org.apache.poi.ss.usermodel.*;
|
|
|
import org.apache.poi.ss.util.CellAddress;
|
|
|
import org.apache.poi.ss.util.CellRangeAddress;
|
|
@@ -37,17 +46,23 @@ import org.apache.poi.ss.util.SheetUtil;
|
|
|
import org.apache.poi.xssf.usermodel.*;
|
|
|
import org.apache.poi.xssf.usermodel.helpers.XSSFFormulaUtils;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
+import javax.validation.Valid;
|
|
|
+import javax.validation.constraints.NotEmpty;
|
|
|
import java.io.IOException;
|
|
|
import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
@Service
|
|
|
@RequiredArgsConstructor
|
|
|
@Slf4j
|
|
|
public class BatchHandleSopServiceImpl implements IBatchHandleSopService {
|
|
|
-
|
|
|
+ private final ISopService sopService;
|
|
|
private final SaasClient saasClient;
|
|
|
+ private final IProjectSopService projectSopService;
|
|
|
|
|
|
/**SOP批量导入模板的位置*/
|
|
|
private static final String TEMPLATE_FILE_PATH="/template/SOP导入模板.xlsx";
|
|
@@ -94,6 +109,373 @@ public class BatchHandleSopServiceImpl implements IBatchHandleSopService {
|
|
|
}.downloadFile();
|
|
|
}
|
|
|
/***
|
|
|
+ * Description: 批量上传SOP
|
|
|
+ * @param projectId : 项目id
|
|
|
+ * @param file : 文件流
|
|
|
+ * @param request : 请求体对象
|
|
|
+ * @param response : 响应体对象
|
|
|
+ * @return : void
|
|
|
+ * @author : lijie
|
|
|
+ * @date :2021/4/30 12:15
|
|
|
+ * Update By lijie 2021/4/30 12:15
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void uploadSop(String projectId, MultipartFile file, HttpServletRequest request, HttpServletResponse response) throws IOException {
|
|
|
+ if (StrUtil.isBlank(projectId)){
|
|
|
+ projectId = SopCommonConst.GROUP_SOP_ID;
|
|
|
+ }
|
|
|
+ ExcelReader firstSheet = ExcelUtil.getReader(file.getInputStream(),0);
|
|
|
+ ExcelReader classDataSheet = ExcelUtil.getReader(file.getInputStream(),1);
|
|
|
+ ExcelReader codeDataSheet = ExcelUtil.getReader(file.getInputStream(),2);
|
|
|
+ ExcelReader infoDataSheet = ExcelUtil.getReader(file.getInputStream(),3);
|
|
|
+ List<List<Object>> uploadData = firstSheet.read();
|
|
|
+ List<List<Object>> classListList = classDataSheet.read();
|
|
|
+ List<List<Object>> codeListList = codeDataSheet.read();
|
|
|
+ List<List<Object>> infoListList = infoDataSheet.read();
|
|
|
+ List<String> checkFileErrList = checkFileIsValid(uploadData);
|
|
|
+ if (CollUtil.isNotEmpty(checkFileErrList)){
|
|
|
+ FileUtil.writeErrorContentToResponse(checkFileErrList,response,request,SopQueryConst.UPLOAD_SOP_ERR_FILE_NAME);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ // 1.大类名称集合
|
|
|
+ Set<String> classNameSet = new HashSet<>();
|
|
|
+ for (int i = 0; i < classListList.size(); i++) {
|
|
|
+ List<Object> objects = classListList.get(i);
|
|
|
+ classNameSet.add(CharSequenceUtil.trimToEmpty(StrUtil.utf8Str(objects.get(0))));
|
|
|
+ }
|
|
|
+ // 2.分类映射
|
|
|
+ Map<String,String> codeMap = new HashMap<>();
|
|
|
+ Map<String,String> objTypeMap = new HashMap<>();
|
|
|
+ for (List<Object> objects : codeListList) {
|
|
|
+ String objName = CharSequenceUtil.trimToEmpty(StrUtil.utf8Str(objects.get(0)));
|
|
|
+ String objCode = CharSequenceUtil.trimToEmpty(StrUtil.utf8Str(objects.get(1)));
|
|
|
+ String objType = CharSequenceUtil.trimToEmpty(StrUtil.utf8Str(objects.get(2)));
|
|
|
+ codeMap.putIfAbsent(objName,objCode);
|
|
|
+ objTypeMap.putIfAbsent(objName,objType);
|
|
|
+ }
|
|
|
+ // 3.信息点映射
|
|
|
+ Map<String,InfoPointsBean> infoMap = new HashMap<>();
|
|
|
+ for (List<Object> objects : infoListList) {
|
|
|
+ String objName = CharSequenceUtil.trimToEmpty(StrUtil.utf8Str(objects.get(0)));
|
|
|
+ String objCode = CharSequenceUtil.trimToEmpty(StrUtil.utf8Str(objects.get(1)));
|
|
|
+ if (StrUtil.isBlank(objCode) || !objCode.startsWith("{")){
|
|
|
+ objCode = "{}";
|
|
|
+ }
|
|
|
+ infoMap.putIfAbsent(objName,JSONObject.parseObject(objCode,InfoPointsBean.class));
|
|
|
+ }
|
|
|
+ // 4.检验数据合法性
|
|
|
+ List<String> checkDataErrList = checkDataIsValid(uploadData, classNameSet, codeMap, infoMap,firstSheet);
|
|
|
+ if (CollUtil.isNotEmpty(checkDataErrList)){
|
|
|
+ FileUtil.writeErrorContentToResponse(checkDataErrList,response,request,SopQueryConst.UPLOAD_SOP_ERR_FILE_NAME);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ List<SaveSopVo> saveSopVos = generateSaveSopVo(uploadData,codeMap,infoMap,firstSheet,projectId,objTypeMap);
|
|
|
+ projectSopService.batchAddPublishedSop(saveSopVos);
|
|
|
+ }
|
|
|
+ /***
|
|
|
+ * Description: 生成需要保存的对象
|
|
|
+ * @param uploadData : 上传的数据
|
|
|
+ * @param codeMap : code映射
|
|
|
+ * @param infoMap : 信息点映射
|
|
|
+ * @param firstSheet : sheet对象
|
|
|
+ * @param objTypeMap
|
|
|
+ * @return : java.util.List<com.persagy.fm.sop.model.vo.SaveSopVo>
|
|
|
+ * @author : lijie
|
|
|
+ * @date :2021/4/30 17:04
|
|
|
+ * Update By lijie 2021/4/30 17:04
|
|
|
+ */
|
|
|
+ private List<SaveSopVo> generateSaveSopVo(List<List<Object>> uploadData, Map<String, String> codeMap,
|
|
|
+ Map<String, InfoPointsBean> infoMap, ExcelReader firstSheet, String projectId, Map<String, String> objTypeMap) {
|
|
|
+ int size = uploadData.size();
|
|
|
+ Map<String,SaveSopVo> resultMap = new HashMap<>();
|
|
|
+ Map<String,Set<String>> objNameMap = new HashMap<>();
|
|
|
+ Map<String,Set<String>> confirmResultMap = new HashMap<>();
|
|
|
+ for (int i = 2; i < size; i++) {
|
|
|
+ // 1.SOP的名称
|
|
|
+ String sopName = CharSequenceUtil.trimToEmpty(StrUtil.utf8Str(CellUtil.getCellValue(firstSheet.getOrCreateCell(0,i))));
|
|
|
+ SaveSopVo saveSopVo = resultMap.getOrDefault(sopName, new SaveSopVo());
|
|
|
+ saveSopVo.setSopName(sopName);
|
|
|
+ saveSopVo.setProjectId(projectId);
|
|
|
+ List<FitObjsBean> fitObjs = saveSopVo.getFitObjs();
|
|
|
+ if (CollUtil.isEmpty(fitObjs)){
|
|
|
+ fitObjs = new ArrayList<>();
|
|
|
+ saveSopVo.setFitObjs(fitObjs);
|
|
|
+ }
|
|
|
+ List<SopStepsBean> steps = saveSopVo.getSteps();
|
|
|
+ SopStepsBean sopStepsBean;
|
|
|
+ if (CollUtil.isEmpty(steps)){
|
|
|
+ steps = new ArrayList<>();
|
|
|
+ sopStepsBean = SopStepsBean.builder().fromSop(false).build();
|
|
|
+ steps.add(sopStepsBean);
|
|
|
+ saveSopVo.setSteps(steps);
|
|
|
+ }else {
|
|
|
+ sopStepsBean=steps.get(0);
|
|
|
+ }
|
|
|
+ Set<String> objNameSet = objNameMap.getOrDefault(sopName, new HashSet<>());
|
|
|
+ // 3.对象名称
|
|
|
+ String objName = CharSequenceUtil.trimToEmpty(StrUtil.utf8Str(CellUtil.getCellValue(firstSheet.getOrCreateCell(2,i))));
|
|
|
+ if (!objNameSet.contains(objName)){
|
|
|
+ objNameSet.add(objName);
|
|
|
+ objNameMap.putIfAbsent(sopName,objNameSet);
|
|
|
+ fitObjs.add(FitObjsBean.builder()
|
|
|
+ .objId(codeMap.getOrDefault(objName,"").substring(1))
|
|
|
+ .objName(objName.substring(objName.lastIndexOf(SopCommonConst.UNDER_LINE)))
|
|
|
+ .objCode(codeMap.getOrDefault(objName,"").substring(1))
|
|
|
+ .objType(objTypeMap.getOrDefault(objName,""))
|
|
|
+ .objSource(ObjOwnerEnum.CONTENT_OBJ.getType()).build());
|
|
|
+ List<StepContentBean> stepContents = sopStepsBean.getStepContent();
|
|
|
+ StepContentBean stepContentBean;
|
|
|
+ if (CollUtil.isEmpty(stepContents)){
|
|
|
+ stepContents = new ArrayList<>();
|
|
|
+ stepContentBean = StepContentBean.builder().fromSop(false).build();
|
|
|
+ stepContents.add(stepContentBean);
|
|
|
+ }else {
|
|
|
+ stepContentBean = stepContents.get(0);
|
|
|
+ }
|
|
|
+ List<ContentObjsBean> contentObjs = stepContentBean.getContentObjs();
|
|
|
+ if (CollUtil.isEmpty(contentObjs)){
|
|
|
+ contentObjs = new ArrayList<>();
|
|
|
+ }
|
|
|
+ contentObjs.add(ContentObjsBean.builder()
|
|
|
+ .objId(codeMap.getOrDefault(objName,"").substring(1))
|
|
|
+ .objName(objName.substring(objName.lastIndexOf(SopCommonConst.UNDER_LINE)+1))
|
|
|
+ .objCode(codeMap.getOrDefault(objName,"").substring(1))
|
|
|
+ .objType(objTypeMap.getOrDefault(objName,""))
|
|
|
+ .build());
|
|
|
+ stepContentBean.setContentObjs(contentObjs);
|
|
|
+ sopStepsBean.setStepContent(stepContents);
|
|
|
+ }
|
|
|
+ List<StepContentBean> stepContents = sopStepsBean.getStepContent();
|
|
|
+ StepContentBean stepContentBean;
|
|
|
+ if (CollUtil.isEmpty(stepContents)){
|
|
|
+ stepContents = new ArrayList<>();
|
|
|
+ stepContentBean = StepContentBean.builder().build();
|
|
|
+ stepContents.add(stepContentBean);
|
|
|
+ sopStepsBean.setStepContent(stepContents);
|
|
|
+ }else {
|
|
|
+ stepContentBean = stepContents.get(0);
|
|
|
+ }
|
|
|
+ String photo = CharSequenceUtil.trimToEmpty(StrUtil.utf8Str(CellUtil.getCellValue(firstSheet.getOrCreateCell(6, i))));
|
|
|
+ if (null == stepContentBean.getIsPhoto()){
|
|
|
+ if (StrUtil.isBlank(photo) || "否".equals(photo)){
|
|
|
+ stepContentBean.setIsPhoto(false);
|
|
|
+ }else {
|
|
|
+ stepContentBean.setIsPhoto(true);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ String scan = CharSequenceUtil.trimToEmpty(StrUtil.utf8Str(CellUtil.getCellValue(firstSheet.getOrCreateCell(7, i))));
|
|
|
+ if (null == stepContentBean.getIsScan()){
|
|
|
+ if (StrUtil.isBlank(scan) || "否".equals(scan)){
|
|
|
+ stepContentBean.setIsScan(false);
|
|
|
+ }else {
|
|
|
+ stepContentBean.setIsScan(true);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 处理时间
|
|
|
+ if (null==stepContentBean.getTimeLimit()){
|
|
|
+ Integer destMin = null;
|
|
|
+ String day = CharSequenceUtil.trimToEmpty(StrUtil.utf8Str(CellUtil.getCellValue(firstSheet.getOrCreateCell(8, i))));
|
|
|
+ if (StrUtil.isNotBlank(day)){
|
|
|
+ destMin = Integer.parseInt(day)*24*60;
|
|
|
+ }
|
|
|
+ String hour = CharSequenceUtil.trimToEmpty(StrUtil.utf8Str(CellUtil.getCellValue(firstSheet.getOrCreateCell(9, i))));
|
|
|
+ if (StrUtil.isNotBlank(hour)){
|
|
|
+ destMin = destMin + Integer.parseInt(hour)*60;
|
|
|
+ }
|
|
|
+ String min = CharSequenceUtil.trimToEmpty(StrUtil.utf8Str(CellUtil.getCellValue(firstSheet.getOrCreateCell(10, i))));
|
|
|
+ if (StrUtil.isNotBlank(min)){
|
|
|
+ destMin = destMin + Integer.parseInt(min);
|
|
|
+ }
|
|
|
+ if (null!=destMin){
|
|
|
+ stepContentBean.setTimeLimit(destMin);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ String preConform = CharSequenceUtil.trimToEmpty(StrUtil.utf8Str(CellUtil.getCellValue(firstSheet.getOrCreateCell(11, i))));
|
|
|
+ if (StrUtil.isBlank(stepContentBean.getPreConform()) && StrUtil.isNotBlank(preConform)){
|
|
|
+ stepContentBean.setPreConform(preConform);
|
|
|
+ }
|
|
|
+ String notice = CharSequenceUtil.trimToEmpty(StrUtil.utf8Str(CellUtil.getCellValue(firstSheet.getOrCreateCell(12, i))));
|
|
|
+ if (StrUtil.isBlank(stepContentBean.getNotice()) && StrUtil.isNotBlank(notice)){
|
|
|
+ stepContentBean.setPreConform(notice);
|
|
|
+ }
|
|
|
+ String confirmResultContent = CharSequenceUtil.trimToEmpty(StrUtil.utf8Str(CellUtil.getCellValue(firstSheet.getOrCreateCell(13, i))));
|
|
|
+ Set<String> confirmResultContents = confirmResultMap.getOrDefault(sopName,new HashSet<>());
|
|
|
+ if (!confirmResultContents.contains(confirmResultContent)){
|
|
|
+ confirmResultContents.add(confirmResultContent);
|
|
|
+ confirmResultMap.putIfAbsent(sopName,confirmResultContents);
|
|
|
+ List<ConfirmResultBean> confirmResults = stepContentBean.getConfirmResult();
|
|
|
+ if (CollUtil.isEmpty(confirmResults)){
|
|
|
+ confirmResults = new ArrayList<>();
|
|
|
+ }
|
|
|
+ List<CustomInfoPointsBean> customInfoPoints = new ArrayList<>();
|
|
|
+ String custom = CharSequenceUtil.trimToEmpty(StrUtil.utf8Str(CellUtil.getCellValue(firstSheet.getOrCreateCell(14, i))));
|
|
|
+ if (StrUtil.isNotBlank(custom) && "是".equals(custom)){
|
|
|
+ CustomInfoPointsBean customInfoPoint = new CustomInfoPointsBean();
|
|
|
+ customInfoPoint.setItems(Arrays.asList("正常","异常"));
|
|
|
+ customInfoPoint.setWrongs(Collections.singletonList("异常"));
|
|
|
+ customInfoPoint.setType("2");
|
|
|
+ customInfoPoint.setName("异常情况");
|
|
|
+ customInfoPoints.add(customInfoPoint);
|
|
|
+ }
|
|
|
+ List<InfoPointsBean> infoPointsBeans = new ArrayList<>();
|
|
|
+ String infoPointStr = CharSequenceUtil.trimToEmpty(StrUtil.utf8Str(CellUtil.getCellValue(firstSheet.getOrCreateCell(15, i))));
|
|
|
+ String downStr = CharSequenceUtil.trimToEmpty(StrUtil.utf8Str(CellUtil.getCellValue(firstSheet.getOrCreateCell(16, i))));
|
|
|
+ String upStr = CharSequenceUtil.trimToEmpty(StrUtil.utf8Str(CellUtil.getCellValue(firstSheet.getOrCreateCell(17, i))));
|
|
|
+ if (StrUtil.isNotBlank(infoPointStr)){
|
|
|
+ InfoPointsBean infoPointsBean = infoMap.get(objName+SopCommonConst.UNDER_LINE+infoPointStr);
|
|
|
+ if (null!=infoPointsBean){
|
|
|
+ List<WrongRangesBean> wrongRanges = infoPointsBean.getWrongRanges();
|
|
|
+ if (CollUtil.isEmpty(wrongRanges)){
|
|
|
+ wrongRanges = new ArrayList<>();
|
|
|
+ }
|
|
|
+ if (StrUtil.isNotBlank(downStr)){
|
|
|
+ wrongRanges.add(WrongRangesBean.builder().type("lt").values(downStr).build());
|
|
|
+ }
|
|
|
+ if (StrUtil.isNotBlank(upStr)){
|
|
|
+ wrongRanges.add(WrongRangesBean.builder().type("gt").values(upStr).build());
|
|
|
+ }
|
|
|
+ infoPointsBean.setWrongRanges(wrongRanges);
|
|
|
+ }
|
|
|
+ infoPointsBeans.add(infoPointsBean);
|
|
|
+ }
|
|
|
+ confirmResults.add(ConfirmResultBean.builder()
|
|
|
+ .description(confirmResultContent)
|
|
|
+ .infoPoints(infoPointsBeans)
|
|
|
+ .customs(customInfoPoints)
|
|
|
+ .build());
|
|
|
+ stepContentBean.setConfirmResult(confirmResults);
|
|
|
+ }
|
|
|
+ resultMap.putIfAbsent(sopName,saveSopVo);
|
|
|
+ }
|
|
|
+ return CollUtil.newArrayList(resultMap.values());
|
|
|
+ }
|
|
|
+
|
|
|
+ /***
|
|
|
+ * Description: 校验数据是否正确
|
|
|
+ * @param uploadData : 上传的SOP数据
|
|
|
+ * @param classNameSet : 分类名称集合
|
|
|
+ * @param codeMap : 对象类映射
|
|
|
+ * @param infoMap : 信息点映射
|
|
|
+ * @param firstSheet
|
|
|
+ * @return : java.util.List<java.lang.String>
|
|
|
+ * @author : lijie
|
|
|
+ * @date :2021/4/30 15:05
|
|
|
+ * Update By lijie 2021/4/30 15:05
|
|
|
+ */
|
|
|
+ private List<String> checkDataIsValid(List<List<Object>> uploadData, Set<String> classNameSet,
|
|
|
+ Map<String, String> codeMap, Map<String, InfoPointsBean> infoMap, ExcelReader firstSheet) {
|
|
|
+ List<Sop> sops = sopService.list();
|
|
|
+ Set<String> sopNameSet = sops.stream().map(Sop::getSopName).collect(Collectors.toSet());
|
|
|
+ Set<String> codeNameSet = codeMap.keySet();
|
|
|
+ Set<String> codeSet = CollUtil.newHashSet(codeMap.values());
|
|
|
+ Set<String> infoNameSet = infoMap.keySet();
|
|
|
+ List<String> errorList = new ArrayList<>();
|
|
|
+ for (int i = 2; i < uploadData.size(); i++) {
|
|
|
+ List<Object> objects = uploadData.get(i);
|
|
|
+ String realCol="第"+(i+1)+"行,";
|
|
|
+ // 1.SOP的名称
|
|
|
+ String sopName = CharSequenceUtil.trimToEmpty(StrUtil.utf8Str(CellUtil.getCellValue(firstSheet.getOrCreateCell(0,i))));
|
|
|
+ if (StrUtil.isBlank(sopName)){
|
|
|
+ errorList.add(realCol+SopColumnEnum.SOP_NAME.getName()+SopErrorEnum.CONTENT_BLANK_ERROR);
|
|
|
+ }
|
|
|
+ if (StrUtil.isNotBlank(sopName) && sopNameSet.contains(sopName)){
|
|
|
+ errorList.add(realCol+SopColumnEnum.SOP_NAME.getName()+SopErrorEnum.SOP_NAME_REPEAT_ERROR);
|
|
|
+ }
|
|
|
+ // 2.对象分类
|
|
|
+ String className = CharSequenceUtil.trimToEmpty(StrUtil.utf8Str(CellUtil.getCellValue(firstSheet.getOrCreateCell(1,i))));
|
|
|
+ if (StrUtil.isBlank(className)){
|
|
|
+ errorList.add(realCol+SopColumnEnum.OBJ_CLASSIFY.getName()+SopErrorEnum.CONTENT_BLANK_ERROR);
|
|
|
+ }
|
|
|
+ if (StrUtil.isNotBlank(className) && !classNameSet.contains(className)){
|
|
|
+ errorList.add(realCol+SopColumnEnum.OBJ_CLASSIFY.getName()+SopErrorEnum.CONTENT_ERROR);
|
|
|
+ }
|
|
|
+ // 3.对象选择
|
|
|
+ String objName = CharSequenceUtil.trimToEmpty(StrUtil.utf8Str(CellUtil.getCellValue(firstSheet.getOrCreateCell(2,i))));
|
|
|
+ if (StrUtil.isBlank(objName)){
|
|
|
+ errorList.add(realCol+SopColumnEnum.OBJ_CHOICE.getName()+SopErrorEnum.CONTENT_BLANK_ERROR);
|
|
|
+ }
|
|
|
+ if (StrUtil.isNotBlank(objName) && !codeNameSet.contains(objName)){
|
|
|
+ errorList.add(realCol+SopColumnEnum.OBJ_CHOICE.getName()+SopErrorEnum.CONTENT_ERROR);
|
|
|
+ }
|
|
|
+ // 4.对象编码
|
|
|
+ String objCode = CharSequenceUtil.trimToEmpty(StrUtil.utf8Str(CellUtil.getCellValue(firstSheet.getOrCreateCell(3,i))));
|
|
|
+ if (StrUtil.isBlank(objCode)){
|
|
|
+ errorList.add(realCol+SopColumnEnum.OBJ_CODE.getName()+SopErrorEnum.CONTENT_BLANK_ERROR);
|
|
|
+ }
|
|
|
+ if (StrUtil.isNotBlank(objCode) && !codeSet.contains(objCode)){
|
|
|
+ errorList.add(realCol+SopColumnEnum.OBJ_CODE.getName()+SopErrorEnum.CONTENT_ERROR);
|
|
|
+ }
|
|
|
+ // 5.工作时长(天)
|
|
|
+ String dayStr = CharSequenceUtil.trimToEmpty(StrUtil.utf8Str(CellUtil.getCellValue(firstSheet.getOrCreateCell(8,i))));
|
|
|
+ if (StrUtil.isNotBlank(dayStr) && !NumberUtil.isNumber(dayStr)){
|
|
|
+ errorList.add(realCol+SopColumnEnum.WORK_TIME_DAY+SopErrorEnum.NUMBER_ERROR);
|
|
|
+ }
|
|
|
+ // 6.工作时长(时)
|
|
|
+ String hourStr = CharSequenceUtil.trimToEmpty(StrUtil.utf8Str(CellUtil.getCellValue(firstSheet.getOrCreateCell(9,i))));
|
|
|
+ if (StrUtil.isNotBlank(hourStr) && !NumberUtil.isNumber(hourStr)){
|
|
|
+ errorList.add(realCol+SopColumnEnum.WORK_TIME_HOUR+SopErrorEnum.NUMBER_ERROR);
|
|
|
+ }
|
|
|
+ // 7.工作时长(分)
|
|
|
+ String minStr = CharSequenceUtil.trimToEmpty(StrUtil.utf8Str(CellUtil.getCellValue(firstSheet.getOrCreateCell(10,i))));
|
|
|
+ if (StrUtil.isNotBlank(minStr) && !NumberUtil.isNumber(minStr)){
|
|
|
+ errorList.add(realCol+SopColumnEnum.WORK_TIME_MIN+SopErrorEnum.NUMBER_ERROR);
|
|
|
+ }
|
|
|
+ // 8.标准作业操作内容
|
|
|
+ String describe = CharSequenceUtil.trimToEmpty(StrUtil.utf8Str(CellUtil.getCellValue(firstSheet.getOrCreateCell(13,i))));
|
|
|
+ if (StrUtil.isBlank(describe)){
|
|
|
+ errorList.add(realCol+SopColumnEnum.JOB_DESCRIPTION.getName()+SopErrorEnum.CONTENT_BLANK_ERROR);
|
|
|
+ }
|
|
|
+ // 9.添加信息点
|
|
|
+ String infoCode = CharSequenceUtil.trimToEmpty(StrUtil.utf8Str(CellUtil.getCellValue(firstSheet.getOrCreateCell(15,i))));
|
|
|
+ if (StrUtil.isNotBlank(infoCode) && !infoNameSet.contains(objName+SopCommonConst.UNDER_LINE+infoCode)){
|
|
|
+ errorList.add(realCol+SopErrorEnum.CONTENT_ERROR);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return errorList;
|
|
|
+ }
|
|
|
+
|
|
|
+ /***
|
|
|
+ * Description: 校验文件的正确性
|
|
|
+ * @param lists : 数据列表
|
|
|
+ * @return : java.util.List<java.lang.String>
|
|
|
+ * @author : lijie
|
|
|
+ * @date :2021/3/15 11:51
|
|
|
+ * Update By lijie 2021/3/15 11:51
|
|
|
+ */
|
|
|
+ private List<String> checkFileIsValid(List<List<Object>> lists) {
|
|
|
+ List<String> errorList = new ArrayList<>();
|
|
|
+ if (lists.size() < SopQueryConst.EXCEL_HEAD_INDEX){
|
|
|
+ errorList.add(SopErrorEnum.FILE_ERROR.getDesc());
|
|
|
+ return errorList;
|
|
|
+ }
|
|
|
+ List<Object> rows = lists.get(1);
|
|
|
+ if (CollUtil.isEmpty(rows)){
|
|
|
+ errorList.add(SopErrorEnum.FILE_ERROR.getDesc());
|
|
|
+ return errorList;
|
|
|
+ }
|
|
|
+ List<SopColumnEnum> list = CollUtil.list(false, EnumUtil.getEnumMap(SopColumnEnum.class).values());
|
|
|
+ Map<Integer, String> sopColumnMap = list.stream()
|
|
|
+ .collect(Collectors.toMap(SopColumnEnum::getIndex, SopColumnEnum::getName, (k1, k2) -> k1));
|
|
|
+ if (rows.size()<sopColumnMap.size()){
|
|
|
+ errorList.add(SopErrorEnum.FILE_ERROR.getDesc());
|
|
|
+ return errorList;
|
|
|
+ }
|
|
|
+ for (int i=0;i<sopColumnMap.size();i++){
|
|
|
+ String columnName = sopColumnMap.get(i);
|
|
|
+ if (StringUtils.isBlank(columnName)){
|
|
|
+ errorList.add(SopErrorEnum.FILE_ERROR.getDesc());
|
|
|
+ return errorList;
|
|
|
+ }
|
|
|
+ String realName = CharSequenceUtil.trimToEmpty(StrUtil.utf8Str(rows.get(i)));
|
|
|
+ if (StrUtil.isBlank(realName) || !realName.contains(columnName)){
|
|
|
+ errorList.add(SopErrorEnum.FILE_ERROR.getDesc());
|
|
|
+ return errorList;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return errorList;
|
|
|
+ }
|
|
|
+
|
|
|
+ /***
|
|
|
* Description: 填充对象类数据
|
|
|
* @param workbook : 工作簿
|
|
|
* @return : void
|
|
@@ -251,7 +633,7 @@ public class BatchHandleSopServiceImpl implements IBatchHandleSopService {
|
|
|
if (StrUtil.isBlank(firstBean.getObjId()) || StrUtil.isBlank(firstBean.getObjName())){
|
|
|
continue;
|
|
|
}
|
|
|
- setCellValue(firstBean.getObjName(),firstBean.getObjId(),5,listSheet,lookSheet,index);
|
|
|
+ setCellValue(firstBean.getObjName(),firstBean.getObjId(),5,listSheet,lookSheet,index,ObjTypeEnum.SHAFT_TYPE.getType());
|
|
|
setInfoValue(workbook,lookSheet,infoCodeMap,firstBean.getObjId(),firstBean.getObjName(),infoSheet,ObjTypeEnum.SHAFT.getType());
|
|
|
index++;
|
|
|
}
|
|
@@ -284,7 +666,7 @@ public class BatchHandleSopServiceImpl implements IBatchHandleSopService {
|
|
|
if (StrUtil.isBlank(firstBean.getObjId()) || StrUtil.isBlank(firstBean.getObjName())){
|
|
|
continue;
|
|
|
}
|
|
|
- setCellValue(firstBean.getObjName(),firstBean.getObjId(),4,listSheet,lookSheet,index);
|
|
|
+ setCellValue(firstBean.getObjName(),firstBean.getObjId(),4,listSheet,lookSheet,index,ObjTypeEnum.FLOOR_TYPE.getType());
|
|
|
setInfoValue(workbook,lookSheet,infoCodeMap,firstBean.getObjId(),firstBean.getObjName(),infoSheet,ObjTypeEnum.FLOOR.getType());
|
|
|
index++;
|
|
|
}
|
|
@@ -318,7 +700,7 @@ public class BatchHandleSopServiceImpl implements IBatchHandleSopService {
|
|
|
if (StrUtil.isBlank(firstBean.getObjId()) || StrUtil.isBlank(firstBean.getObjName())){
|
|
|
continue;
|
|
|
}
|
|
|
- setCellValue(firstBean.getObjName(),firstBean.getObjId(),3,listSheet,lookSheet,index);
|
|
|
+ setCellValue(firstBean.getObjName(),firstBean.getObjId(),3,listSheet,lookSheet,index,ObjTypeEnum.BUILD_FUNC_TYPE.getType());
|
|
|
setInfoValue(workbook,lookSheet,infoCodeMap,firstBean.getObjId(),firstBean.getObjName(),infoSheet,ObjTypeEnum.BUILDING.getType());
|
|
|
index++;
|
|
|
List<ObjBean> secondBeans = firstBean.getContent();
|
|
@@ -329,7 +711,7 @@ public class BatchHandleSopServiceImpl implements IBatchHandleSopService {
|
|
|
if (StrUtil.isBlank(firstBean.getObjId()) || StrUtil.isBlank(firstBean.getObjName())){
|
|
|
continue;
|
|
|
}
|
|
|
- setCellValue(firstBean.getObjName()+SopCommonConst.UNDER_LINE+secondBean.getObjName(),secondBean.getObjId(),3,listSheet,lookSheet,index);
|
|
|
+ setCellValue(firstBean.getObjName()+SopCommonConst.UNDER_LINE+secondBean.getObjName(),secondBean.getObjId(),3,listSheet,lookSheet,index,ObjTypeEnum.BUILD_FUNC_TYPE.getType());
|
|
|
setInfoValue(workbook,lookSheet,infoCodeMap,secondBean.getObjId(),firstBean.getObjName()+SopCommonConst.UNDER_LINE+secondBean.getObjName(),infoSheet,ObjTypeEnum.BUILDING.getType());
|
|
|
index++;
|
|
|
List<ObjBean> thirdBeans = secondBean.getContent();
|
|
@@ -340,7 +722,7 @@ public class BatchHandleSopServiceImpl implements IBatchHandleSopService {
|
|
|
if (StrUtil.isBlank(firstBean.getObjId()) || StrUtil.isBlank(firstBean.getObjName())){
|
|
|
continue;
|
|
|
}
|
|
|
- setCellValue(firstBean.getObjName()+SopCommonConst.UNDER_LINE+secondBean.getObjName()+SopCommonConst.UNDER_LINE+thirdBean.getObjName(),thirdBean.getObjId(),3,listSheet,lookSheet,index);
|
|
|
+ setCellValue(firstBean.getObjName()+SopCommonConst.UNDER_LINE+secondBean.getObjName()+SopCommonConst.UNDER_LINE+thirdBean.getObjName(),thirdBean.getObjId(),3,listSheet,lookSheet,index,ObjTypeEnum.BUILD_FUNC_TYPE.getType());
|
|
|
setInfoValue(workbook,lookSheet,infoCodeMap,thirdBean.getObjId(),firstBean.getObjName()+SopCommonConst.UNDER_LINE+secondBean.getObjName()+SopCommonConst.UNDER_LINE+thirdBean.getObjName(),infoSheet,ObjTypeEnum.BUILDING.getType());
|
|
|
index++;
|
|
|
}
|
|
@@ -375,7 +757,7 @@ public class BatchHandleSopServiceImpl implements IBatchHandleSopService {
|
|
|
if (StrUtil.isBlank(objBean.getObjId()) || StrUtil.isBlank(objBean.getObjName())){
|
|
|
continue;
|
|
|
}
|
|
|
- setCellValue(objBean.getObjName(),objBean.getObjId(),2,listSheet,lookSheet,index);
|
|
|
+ setCellValue(objBean.getObjName(),objBean.getObjId(),2,listSheet,lookSheet,index,ObjTypeEnum.SPACE_CLASS.getType());
|
|
|
setInfoValue(workbook, lookSheet,infoCodeMap,objBean.getObjId(),objBean.getObjName(),infoSheet, ObjTypeEnum.SPACE.getType());
|
|
|
index++;
|
|
|
}
|
|
@@ -425,7 +807,7 @@ public class BatchHandleSopServiceImpl implements IBatchHandleSopService {
|
|
|
if (StrUtil.isNotBlank(domainBean.getObjName())){
|
|
|
equipName = domainBean.getObjName()+SopCommonConst.UNDER_LINE+equipName;
|
|
|
}
|
|
|
- setCellValue(equipName,equipBean.getObjId(),1,listSheet,lookSheet,index);
|
|
|
+ setCellValue(equipName,equipBean.getObjId(),1,listSheet,lookSheet,index,ObjTypeEnum.EQUIP_CLASS.getType());
|
|
|
setInfoValue(workbook, lookSheet,infoCodeMap,equipBean.getObjId(),equipName,infoSheet,equipBean.getObjId());
|
|
|
index++;
|
|
|
}
|
|
@@ -469,13 +851,15 @@ public class BatchHandleSopServiceImpl implements IBatchHandleSopService {
|
|
|
* Update By lijie 2021/4/28 20:52
|
|
|
*/
|
|
|
private void setCellValue(String objName, String objId, Integer index, Sheet listSheet,
|
|
|
- Sheet lookSheet,Integer listCellIndex) {
|
|
|
+ Sheet lookSheet,Integer listCellIndex,String objType) {
|
|
|
CellUtil.setCellValue(CellUtil
|
|
|
.getOrCreateCell(RowUtil.getOrCreateRow(listSheet,index),listCellIndex), objName,null);
|
|
|
CellUtil.setCellValue(CellUtil
|
|
|
.getOrCreateCell(RowUtil.getOrCreateRow(lookSheet,LOOK_INDEX.get()),0), objName,null);
|
|
|
CellUtil.setCellValue(CellUtil
|
|
|
.getOrCreateCell(RowUtil.getOrCreateRow(lookSheet,LOOK_INDEX.get()),1), "_"+objId,null);
|
|
|
+ CellUtil.setCellValue(CellUtil
|
|
|
+ .getOrCreateCell(RowUtil.getOrCreateRow(lookSheet,LOOK_INDEX.get()),2), objType,null);
|
|
|
LOOK_INDEX.set(LOOK_INDEX.get()+1);
|
|
|
}
|
|
|
|
|
@@ -508,7 +892,7 @@ public class BatchHandleSopServiceImpl implements IBatchHandleSopService {
|
|
|
continue;
|
|
|
}
|
|
|
String objName = StrUtil.isBlank(objBean.getObjName()) ?subObjBean.getObjName():objBean.getObjName()+ SopCommonConst.UNDER_LINE +subObjBean.getObjName();
|
|
|
- setCellValue(objName,subObjBean.getObjId(),0,listSheet,lookSheet,index);
|
|
|
+ setCellValue(objName,subObjBean.getObjId(),0,listSheet,lookSheet,index,ObjTypeEnum.SYSTEM_CLASS.getType());
|
|
|
setInfoValue(workbook,lookSheet,infoCodeMap,subObjBean.getObjId(),objName,infoSheet,subObjBean.getObjId());
|
|
|
index++;
|
|
|
}
|
|
@@ -531,12 +915,12 @@ public class BatchHandleSopServiceImpl implements IBatchHandleSopService {
|
|
|
List<InfoPointsBean> infoPointsBeans = infoCodeMap.getOrDefault(objType, new ArrayList<>());
|
|
|
for (int i = 0; i < infoPointsBeans.size(); i++) {
|
|
|
InfoPointsBean infoPointsBean = infoPointsBeans.get(i);
|
|
|
- CellUtil.setCellValue(CellUtil.getOrCreateCell(RowUtil.getOrCreateRow(lookSheet, LOOK_INDEX.get()-1),i+2),infoPointsBean.getName(),null);
|
|
|
+ CellUtil.setCellValue(CellUtil.getOrCreateCell(RowUtil.getOrCreateRow(lookSheet, LOOK_INDEX.get()-1),i+3),infoPointsBean.getName(),null);
|
|
|
CellUtil.setCellValue(CellUtil.getOrCreateCell(RowUtil.getOrCreateRow(infoSheet, INFO_INDEX.get()),0),objName+SopCommonConst.UNDER_LINE+infoPointsBean.getName(),null);
|
|
|
CellUtil.setCellValue(CellUtil.getOrCreateCell(RowUtil.getOrCreateRow(infoSheet, INFO_INDEX.get()),1),JSONObject.toJSONString(infoPointsBean),null);
|
|
|
INFO_INDEX.set(INFO_INDEX.get()+1);
|
|
|
}
|
|
|
- setSheetRefersToFormula(workbook,2,LOOK_INDEX.get(),infoPointsBeans.size()+1, SheetNameEnum.CODE_DATA.getType(),"_"+objId);
|
|
|
+ setSheetRefersToFormula(workbook,3,LOOK_INDEX.get(),infoPointsBeans.size()+1, SheetNameEnum.CODE_DATA.getType(),"_"+objId);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -551,10 +935,10 @@ public class BatchHandleSopServiceImpl implements IBatchHandleSopService {
|
|
|
char start = (char)(colFlag + offset);
|
|
|
if (colCount <= 25) {
|
|
|
char end;
|
|
|
- if (colCount<2){
|
|
|
+ if ((colCount - offset)<0){
|
|
|
end = (char)(start + colCount - 1);
|
|
|
}else {
|
|
|
- end = (char)(start + colCount - 2);
|
|
|
+ end = (char)(start + colCount - offset);
|
|
|
}
|
|
|
return "$" + start + "$" + rowId + ":$" + end + "$" + rowId;
|
|
|
} else {
|
|
@@ -572,10 +956,10 @@ public class BatchHandleSopServiceImpl implements IBatchHandleSopService {
|
|
|
endSuffix = (char)(colFlag + 25);
|
|
|
endPrefix = (char)(endPrefix + (colCount - 25) / 26 - 1);
|
|
|
} else {
|
|
|
- if ((colCount - 25) % 26 < 2){
|
|
|
+ if (((colCount - 25) % 26 - offset)<0){
|
|
|
endSuffix = (char)(colFlag + (colCount - 25) % 26 - 1);
|
|
|
}else {
|
|
|
- endSuffix = (char)(colFlag + (colCount - 25) % 26 - 2);
|
|
|
+ endSuffix = (char)(colFlag + (colCount - 25) % 26 - offset);
|
|
|
}
|
|
|
endPrefix = (char)(endPrefix + (colCount - 25) / 26);
|
|
|
}
|