lijie 4 роки тому
батько
коміт
f8a22c1c30

+ 18 - 0
fm-sop/pom.xml

@@ -76,6 +76,12 @@
             <groupId>com.persagy</groupId>
             <artifactId>fm-mybatis</artifactId>
             <version>3.0.0</version>
+            <exclusions>
+                <exclusion>
+                    <groupId>com.baomidou</groupId>
+                    <artifactId>mybatis-plus-boot-starter</artifactId>
+                </exclusion>
+            </exclusions>
         </dependency>
         <dependency>
             <groupId>org.apache.velocity</groupId>
@@ -183,6 +189,18 @@
             <groupId>com.persagy</groupId>
             <artifactId>integrated-db-spring-boot-starter</artifactId>
             <version>1.0.0</version>
+            <exclusions>
+                <exclusion>
+                    <groupId>com.baomidou</groupId>
+                    <artifactId>mybatis-plus-boot-starter</artifactId>
+                </exclusion>
+            </exclusions>
+        </dependency>
+        <dependency>
+            <groupId>com.baomidou</groupId>
+            <artifactId>mybatis-plus-boot-starter</artifactId>
+            <version>3.4.2</version>
+            <optional>true</optional>
         </dependency>
     </dependencies>
 </project>

+ 3 - 2
fm-sop/src/main/java/com/persagy/fm/sop/client/SaasFallBackFactory.java

@@ -18,9 +18,10 @@ import java.util.Collections;
 @Slf4j
 @Component
 public class SaasFallBackFactory implements FallbackFactory<SaasClient> {
+
+
 	@Override
 	public SaasClient create(Throwable throwable) {
-		return queryGeneralDictVo -> JSONObject.toJSONString(OldResponseResultUtil
-				.successResult(Collections.singletonList(GeneralDictVo.builder().build())));
+		return null;
 	}
 }

+ 19 - 2
fm-sop/src/main/java/com/persagy/fm/sop/controller/BatchHandleSopController.java

@@ -25,6 +25,7 @@ import org.springframework.web.multipart.MultipartFile;
 
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
 import java.util.ArrayList;
 import java.util.List;
 
@@ -68,7 +69,7 @@ public class BatchHandleSopController {
      * @date :2021/4/30 12:08
      * Update By lijie 2021/4/30 12:08
      */
-    @ApiOperation("下载导入模板")
+    @ApiOperation("SOP批量导入")
     @PostMapping("uploadSop")
     @CrossOrigin
     @IgnoreLog
@@ -92,7 +93,23 @@ public class BatchHandleSopController {
             errorList.add(exr.getMessage());
             FileUtil.writeErrorContentToResponse(errorList,response,request,SopQueryConst.UPLOAD_SOP_ERR_FILE_NAME);
         }
-
+    }
+    /***
+     * Description: 导出SOP
+     * @param projectId : 项目id
+     * @param response : 响应体对象
+     * @return : void
+     * @author : lijie
+     * @date :2021/4/30 12:08
+     * Update By lijie 2021/4/30 12:08
+     */
+    @ApiOperation("导出SOP")
+    @PostMapping("exportSop")
+    @CrossOrigin
+    @IgnoreLog
+    public void exportSop(@RequestParam(value = SopQueryConst.PROJECT_ID_HUMP,required = false) String projectId,
+                          HttpServletResponse response) throws Exception {
+        batchHandleSopService.exportSop(projectId,response);
     }
 
 

+ 27 - 3
fm-sop/src/main/java/com/persagy/fm/sop/entity/CustomInfoPoint.java

@@ -1,15 +1,23 @@
 package com.persagy.fm.sop.entity;
 
+import com.alibaba.fastjson.annotation.JSONField;
 import com.baomidou.mybatisplus.annotation.FieldFill;
 import com.baomidou.mybatisplus.annotation.TableField;
 import com.baomidou.mybatisplus.annotation.TableId;
 import com.baomidou.mybatisplus.annotation.TableName;
 import com.baomidou.mybatisplus.extension.activerecord.Model;
+import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.persagy.fm.sop.handler.JsonTypeHandlerFactory;
+import com.persagy.fm.sop.model.dto.CustomInfoPointsBean;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
 import lombok.Data;
 import lombok.NoArgsConstructor;
 import lombok.experimental.Accessors;
 
 import java.io.Serializable;
+import java.util.List;
 
 /**
  * (custom_info_point)实体类
@@ -18,10 +26,12 @@ import java.io.Serializable;
  * @since 2021-03-31 18:08:21
  * @description 由 Mybatisplus Code Generator 创建
  */
+@Builder
 @Data
 @NoArgsConstructor
+@AllArgsConstructor
 @Accessors(chain = true)
-@TableName("custom_info_point")
+@TableName(value = "custom_info_point",autoResultMap = true)
 public class CustomInfoPoint extends Model<CustomInfoPoint> implements Serializable {
     private static final long serialVersionUID = 1L;
 
@@ -29,30 +39,44 @@ public class CustomInfoPoint extends Model<CustomInfoPoint> implements Serializa
      * 主键id
      */
     @TableId
+    @TableField("custom_info_point_id")
+    @JsonProperty("custom_info_point_id")
+    @JSONField(name = "custom_info_point_id")
 	private String customInfoPointId;
     /**
      * 信息点控件名
      */
+    @TableField("custom_info_point_name")
+    @JsonProperty("custom_info_point_name")
+    @JSONField(name = "custom_info_point_name")
     private String customInfoPointName;
     /**
      * 控件明细
      */
-    @TableField(value = "create_time", fill = FieldFill.INSERT)
-    private Object details;
+    @TableField(value = "details",typeHandler = JacksonTypeHandler.class)
+    @JsonProperty("details")
+    @JSONField(name = "details")
+    private CustomInfoPointsBean details;
     /**
      * 创建时间,格式为yyyyMMddHHmmss
      */
     @TableField(value = "create_time", fill = FieldFill.INSERT)
+    @JsonProperty("create_time")
+    @JSONField(name = "create_time")
     private String createTime;
     /**
      * 更新时间,格式为yyyyMMddHHmmss
      */
     @TableField(value = "update_time", fill = FieldFill.INSERT_UPDATE)
+    @JsonProperty("update_time")
+    @JSONField(name = "update_time")
     private String updateTime;
     /**
      * 1-有效 0-无效
      */
     @TableField(value = "valid")
+    @JsonProperty("valid")
+    @JSONField(name = "valid")
     private Boolean valid;
 
 }

+ 64 - 1
fm-sop/src/main/java/com/persagy/fm/sop/entity/SopCell.java

@@ -17,6 +17,7 @@ import com.persagy.fm.sop.model.dto.InfoPointsBean;
 import lombok.Data;
 import lombok.NoArgsConstructor;
 import lombok.experimental.Accessors;
+import org.apache.ibatis.type.JdbcType;
 import org.jetbrains.annotations.NotNull;
 
 import java.io.Serializable;
@@ -33,7 +34,7 @@ import java.util.List;
 @Data
 @NoArgsConstructor
 @Accessors(chain = true)
-@TableName("sop_cell")
+@TableName(value = "sop_cell",autoResultMap = true)
 public class SopCell extends Model<SopCell> implements Serializable {
     private static final long serialVersionUID = 1L;
 
@@ -184,4 +185,66 @@ public class SopCell extends Model<SopCell> implements Serializable {
     @JsonProperty("domain_name")
     @TableField(exist = false)
     private String domainName;
+
+    /**
+     * 步骤内容中的content,兼容老数据产生
+     */
+    @TableField(value = "content")
+    private String content;
+    /**
+     * 在到达每个对象位置时拍照
+     */
+    @TableField(value = "is_photo")
+    private Boolean isPhoto;
+    /**
+     * 前端传递的参数
+     */
+    @TableField(value = "edit_content")
+    private Boolean editContent;
+    /**
+     * 前端传参,后端无用.兼容老数据产生
+     */
+    @TableField(value = "flag")
+    private String flag;
+    /**
+     * 临时的SOP的id,前端传的参,后端无用,兼容老数据产生
+     */
+    @TableField(value = "temp_sop_id")
+    private String tempSopId;
+    /**
+     * 在到达每个对象位置时扫码
+     */
+    @TableField(value = "is_scan")
+    private Boolean isScan;
+    /**
+     * 在到达每个指定对象时进行NFC识别
+     */
+    @TableField(value = "is_nfc")
+    private Boolean isNfc;
+    /**
+     * 对象运行时间
+     */
+    @TableField(value = "working_time")
+    private Boolean workingTime;
+    /**
+     * 前端传参,兼容老数据产生
+     */
+    @TableField(value = "pre_conform_focus")
+    private Boolean preConformFocus;
+    /**
+     * 前端传参,兼容老数据产生
+     */
+    @TableField(value = "notice_focus")
+    private Boolean noticeFocus;
+    /**
+     * 前端传参,兼容老数据产生
+     */
+    @TableField(value = "content_focus")
+    private Boolean contentFocus;
+    /**
+     * 前端传参,兼容老数据产生
+     */
+    @TableField(value = "verified")
+    private String verified;
+
 }

+ 0 - 2
fm-sop/src/main/java/com/persagy/fm/sop/entity/SopEdit.java

@@ -7,9 +7,7 @@ import java.io.Serializable;
 import java.util.List;
 
 import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
-import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
 import com.persagy.fm.sop.handler.JsonTypeHandlerFactory;
-import com.persagy.fm.sop.handler.ListTypeHandler;
 import com.persagy.fm.sop.model.dto.*;
 import lombok.Data;
 import lombok.EqualsAndHashCode;

+ 1 - 1
fm-sop/src/main/java/com/persagy/fm/sop/entity/SopHis.java

@@ -26,7 +26,7 @@ import lombok.experimental.Accessors;
 @Data
 @EqualsAndHashCode(callSuper = false)
 @Accessors(chain = true)
-@TableName("sop_his")
+@TableName(value = "sop_his",autoResultMap = true)
 @Builder
 public class SopHis extends Model<SopHis> {
 

+ 1 - 1
fm-sop/src/main/java/com/persagy/fm/sop/entity/SopObjRel.java

@@ -27,7 +27,7 @@ import java.util.List;
 @Data
 @NoArgsConstructor
 @Accessors(chain = true)
-@TableName("sop_obj_rel")
+@TableName(value = "sop_obj_rel",autoResultMap = true)
 @Builder
 @AllArgsConstructor
 public class SopObjRel extends Model<SopObjRel> implements Serializable {

+ 0 - 24
fm-sop/src/main/java/com/persagy/fm/sop/handler/ListTypeHandler.java

@@ -1,24 +0,0 @@
-package com.persagy.fm.sop.handler;
-
-import com.alibaba.fastjson.JSON;
-import com.baomidou.mybatisplus.extension.handlers.FastjsonTypeHandler;
-
-public class ListTypeHandler extends FastjsonTypeHandler {
-
-    private final Class<? extends Object> type;
-
-    public ListTypeHandler(Class<Object> type) {
-        super(type);
-        this.type = type;
-    }
-
-    @Override
-    protected Object parse(String json) {
-        return JSON.parseArray(json, this.type);
-    }
-
-    @Override
-    protected String toJson(Object obj) {
-        return super.toJson(obj);
-    }
-}

+ 10 - 0
fm-sop/src/main/java/com/persagy/fm/sop/service/IBatchHandleSopService.java

@@ -36,4 +36,14 @@ public interface IBatchHandleSopService {
      * Update By lijie 2021/4/30 12:15
      */
     void uploadSop(String projectId, MultipartFile file, HttpServletRequest request, HttpServletResponse response) throws IOException;
+    /***
+     * Description: 导出SOP
+     * @param projectId : 项目id
+     * @param response : 响应体对象
+     * @return : void
+     * @author : lijie
+     * @date :2021/5/6 12:09
+     * Update By lijie 2021/5/6 12:09
+     */
+    void exportSop(String projectId, HttpServletResponse response) throws Exception;
 }

+ 219 - 5
fm-sop/src/main/java/com/persagy/fm/sop/service/impl/BatchHandleSopServiceImpl.java

@@ -10,10 +10,12 @@ 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 cn.hutool.poi.excel.editors.TrimEditor;
 import com.alibaba.excel.util.SheetUtils;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.dynamic.datasource.annotation.DS;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.persagy.fm.common.constant.CommonConstant;
 import com.persagy.fm.common.constant.enums.ObjTagEnum;
 import com.persagy.fm.common.constant.enums.ResultEnum;
@@ -26,8 +28,12 @@ import com.persagy.fm.sop.constant.SopCommonConst;
 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.entity.SopCell;
+import com.persagy.fm.sop.entity.SopObjRel;
 import com.persagy.fm.sop.enums.*;
 import com.persagy.fm.sop.model.dto.*;
+import com.persagy.fm.sop.model.vo.PublishedListVo;
+import com.persagy.fm.sop.model.vo.QueryPublishedListVo;
 import com.persagy.fm.sop.model.vo.SaveSopVo;
 import com.persagy.fm.sop.service.IBatchHandleSopService;
 import com.persagy.fm.sop.service.IProjectSopService;
@@ -36,6 +42,7 @@ 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.SneakyThrows;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.poi.ss.usermodel.*;
@@ -66,6 +73,8 @@ public class BatchHandleSopServiceImpl implements IBatchHandleSopService {
 
     /**SOP批量导入模板的位置*/
     private static final String TEMPLATE_FILE_PATH="/template/SOP导入模板.xlsx";
+    /**SOP批量导入模板的位置*/
+    private static final String EXPORT_FILE_PATH="/template/SOP数据.xlsx";
     /**存储codeData的Sheet页的行数*/
     private static final ThreadLocal<Integer> LOOK_INDEX = new ThreadLocal<>();
     /**存储infoData的Sheet页的行数*/
@@ -108,6 +117,7 @@ public class BatchHandleSopServiceImpl implements IBatchHandleSopService {
             }
         }.downloadFile();
     }
+
     /***
      * Description: 批量上传SOP
      * @param projectId : 项目id
@@ -172,6 +182,182 @@ public class BatchHandleSopServiceImpl implements IBatchHandleSopService {
         List<SaveSopVo> saveSopVos = generateSaveSopVo(uploadData,codeMap,infoMap,firstSheet,projectId,objTypeMap);
         projectSopService.batchAddPublishedSop(saveSopVos);
     }
+
+    /***
+     * Description: 导出SOP
+     * @param projectId : 项目id
+     * @param response : 响应体对象
+     * @return : void
+     * @author : lijie
+     * @date :2021/5/6 12:09
+     * Update By lijie 2021/5/6 12:09
+     */
+    @Override
+    public void exportSop(String projectId, HttpServletResponse response) throws Exception {
+        // 下载Excel模板类
+        new DownloadService() {
+            @SneakyThrows
+            @Override
+            protected void handleWorkbook(Workbook workbook) {
+                try{
+                    // 1.填充对象类数据
+                    LOOK_INDEX.set(0);
+                    INFO_INDEX.set(0);
+                    fillObjClassDataToWorkbook(workbook);
+                    // 2.填充SOP的数据
+                    fillSopDataToWorkbook(projectId, workbook);
+                }finally {
+                    LOOK_INDEX.remove();
+                    INFO_INDEX.remove();
+                }
+            }
+
+            @Override
+            protected String getFilePath() {
+                return EXPORT_FILE_PATH;
+            }
+
+            @Override
+            protected HttpServletResponse getHttpServletResponse() {
+                return response;
+            }
+        }.downloadFile();
+    }
+
+    /***
+     * Description: 填充SOP数据
+     * @param workbook : 工作簿
+     * @return : void
+     * @author : lijie
+     * @date :2021/5/6 12:14
+     * Update By lijie 2021/5/6 12:14
+     */
+    private void fillSopDataToWorkbook(String projectId, Workbook workbook) throws Exception {
+        // 1.查询所有SOP数据
+        if (StrUtil.isBlank(projectId)){
+            projectId = SopCommonConst.GROUP_SOP_ID;
+        }
+        QueryPublishedListVo queryPublishedListVo = QueryPublishedListVo.builder().build();
+        queryPublishedListVo.setProjectId(projectId);
+        queryPublishedListVo.setNeedReturnCriteria(false);
+        PublishedListVo listVo = projectSopService.queryPublishedSopList(queryPublishedListVo);
+        // 2.写入数据到Excel里
+        List<SopBean> beans = listVo.getContent();
+        if (CollUtil.isEmpty(beans)){
+            return;
+        }
+        Sheet firstSheet = workbook.getSheetAt(0);
+        Sheet classDataSheet = workbook.getSheetAt(1);
+        Sheet codeDataSheet = workbook.getSheetAt(2);
+        Map<String,String> classMap = new HashMap<>();
+        for (int i=0;i<classDataSheet.getLastRowNum();i++){
+            List<Object> objectList = RowUtil.readRow(RowUtil.getOrCreateRow(classDataSheet, i), null);
+            if (CollUtil.isEmpty(objectList) || objectList.size()<2){
+                continue;
+            }
+            String firstName = CharSequenceUtil.trimToEmpty(StrUtil.utf8Str(objectList.get(0)));
+            for (int j = 1; j < objectList.size(); j++) {
+                String trimToEmpty = CharSequenceUtil.trimToEmpty(StrUtil.utf8Str(objectList.get(j)));
+                if (StrUtil.isBlank(trimToEmpty)){
+                    continue;
+                }
+                classMap.putIfAbsent(trimToEmpty,firstName);
+            }
+        }
+        List<List<Object>> codeListList = new ArrayList<>();
+        for (int i=0;i<codeDataSheet.getLastRowNum();i++){
+            codeListList.add(RowUtil.readRow(RowUtil.getOrCreateRow(codeDataSheet,i), null));
+        }
+        // 2.分类映射
+        Map<String,String> codeMap = 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)));
+            codeMap.putIfAbsent(objCode,objName);
+        }
+        // 从第三行开始写入
+        int sheetRowIndex = 2;
+        for (int i = 0; i < beans.size(); i++) {
+            SopBean sopBean = beans.get(i);
+            List<SopCell> steps = sopBean.getSteps();
+            if (CollUtil.isEmpty(steps)){
+                continue;
+            }
+            for (int j = 0; j < steps.size(); j++) {
+                SopCell stepCell = steps.get(j);
+                if (stepCell.getFromSop()){
+                    // 引用SOP不写入excel
+                    continue;
+                }
+                // 工作内容那一层
+                List<SopCell> stepContents = stepCell.getStepContent();
+                if (CollUtil.isEmpty(stepContents)){
+                    continue;
+                }
+                for (int m = 0; m < stepContents.size(); m++) {
+                    SopCell stepContent = stepContents.get(m);
+                    Row row = RowUtil.getOrCreateRow(firstSheet, sheetRowIndex);
+                    List<SopObjRel> contentObjs = stepContent.getContentObjs();
+                    if (CollUtil.isNotEmpty(contentObjs)){
+                        SopObjRel contentObj = contentObjs.get(0);
+                        String objName = codeMap.get(SopCommonConst.UNDER_LINE+contentObj.getObjId());
+                        if (StrUtil.isNotBlank(objName)){
+                            CellUtil.setCellValue(CellUtil.getOrCreateCell(row,1),classMap.getOrDefault(objName,""),null);
+                            CellUtil.setCellValue(CellUtil.getOrCreateCell(row,2),objName,null);
+                            CellUtil.setCellValue(CellUtil.getOrCreateCell(row,3),SopCommonConst.UNDER_LINE+contentObj.getObjId(),null);
+                        }
+                        List<SopObjRel> spaceScopes = stepContent.getSpaceScope();
+                        if (CollUtil.isNotEmpty(spaceScopes)){
+                            SopObjRel spaceScope = spaceScopes.get(0);
+                            CellUtil.setCellValue(CellUtil.getOrCreateCell(row,4),spaceScope.getObjId(),null);
+                            CellUtil.setCellValue(CellUtil.getOrCreateCell(row,5),spaceScope.getObjName(),null);
+                        }
+                    }
+                    List<SopCell> confirmResults = stepContent.getConfirmResult();
+                    if (CollUtil.isNotEmpty(confirmResults)){
+                        SopCell confirmResult = confirmResults.get(0);
+                        String description = confirmResult.getDescription();
+                        CellUtil.setCellValue(CellUtil.getOrCreateCell(row,13),description,null);
+                        List<CustomInfoPointsBean> customs = confirmResult.getCustoms();
+                        if (CollUtil.isNotEmpty(customs)){
+                            for (int n = 0; n < customs.size(); n++) {
+                                CustomInfoPointsBean customInfoPointsBean = customs.get(n);
+                                if ("异常情况".equals(customInfoPointsBean.getName())){
+                                    CellUtil.setCellValue(CellUtil.getOrCreateCell(row,14),"是",null);
+                                }else {
+                                    CellUtil.setCellValue(CellUtil.getOrCreateCell(row,14),"否",null);
+                                }
+                            }
+                        }
+                        List<InfoPointsBean> infoPoints = confirmResult.getInfoPoints();
+                        if (CollUtil.isNotEmpty(infoPoints)){
+                            InfoPointsBean infoPointsBean = infoPoints.get(0);
+                            CellUtil.setCellValue(CellUtil.getOrCreateCell(row,15),infoPointsBean.getName(),null);
+                            List<WrongRangesBean> wrongRanges = infoPointsBean.getWrongRanges();
+                            if (CollUtil.isNotEmpty(wrongRanges)){
+                                for (WrongRangesBean wrongRange : wrongRanges) {
+                                    if ("gt".equals(wrongRange.getType())){
+                                        CellUtil.setCellValue(CellUtil.getOrCreateCell(row,17),wrongRange.getValues(),null);
+                                    }
+                                    if ("lt".equals(wrongRange.getType())){
+                                        CellUtil.setCellValue(CellUtil.getOrCreateCell(row,16),wrongRange.getValues(),null);
+                                    }
+                                }
+                            }
+                        }
+                    }
+                    CellUtil.setCellValue(CellUtil.getOrCreateCell(row,0),sopBean.getSopName(),null);
+                    CellUtil.setCellValue(CellUtil.getOrCreateCell(row,6),(null!=stepContent.getIsPhoto() && stepContent.getIsPhoto())?"是":"否",null);
+                    CellUtil.setCellValue(CellUtil.getOrCreateCell(row,7),(null!=stepContent.getIsScan() && stepContent.getIsScan())?"是":"否",null);
+                    CellUtil.setCellValue(CellUtil.getOrCreateCell(row,10),stepContent.getTimeLimit(),null);
+                    CellUtil.setCellValue(CellUtil.getOrCreateCell(row,11),stepContent.getPreConform(),null);
+                    CellUtil.setCellValue(CellUtil.getOrCreateCell(row,12),stepContent.getNotice(),null);
+                    sheetRowIndex++;
+                }
+            }
+        }
+    }
+
     /***
      * Description: 生成需要保存的对象
      * @param uploadData : 上传的数据
@@ -195,12 +381,15 @@ public class BatchHandleSopServiceImpl implements IBatchHandleSopService {
             String sopName = CharSequenceUtil.trimToEmpty(StrUtil.utf8Str(CellUtil.getCellValue(firstSheet.getOrCreateCell(0,i))));
             SaveSopVo saveSopVo = resultMap.getOrDefault(sopName, new SaveSopVo());
             saveSopVo.setSopName(sopName);
+            // 2.项目id
             saveSopVo.setProjectId(projectId);
+            // 3.适用范围
             List<FitObjsBean> fitObjs = saveSopVo.getFitObjs();
             if (CollUtil.isEmpty(fitObjs)){
                 fitObjs = new ArrayList<>();
                 saveSopVo.setFitObjs(fitObjs);
             }
+            // 4.步骤,批量上传的根据SOP的名称有且仅有一步
             List<SopStepsBean> steps = saveSopVo.getSteps();
             SopStepsBean sopStepsBean;
             if (CollUtil.isEmpty(steps)){
@@ -212,14 +401,15 @@ public class BatchHandleSopServiceImpl implements IBatchHandleSopService {
                 sopStepsBean=steps.get(0);
             }
             Set<String> objNameSet = objNameMap.getOrDefault(sopName, new HashSet<>());
-            // 3.对象名称
+            // 5.对象名称
             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)))
+                        .objName(objName.substring(objName.lastIndexOf(SopCommonConst.UNDER_LINE)+1))
                         .objCode(codeMap.getOrDefault(objName,"").substring(1))
                         .objType(objTypeMap.getOrDefault(objName,""))
                         .objSource(ObjOwnerEnum.CONTENT_OBJ.getType()).build());
@@ -243,6 +433,20 @@ public class BatchHandleSopServiceImpl implements IBatchHandleSopService {
                         .objType(objTypeMap.getOrDefault(objName,""))
                         .build());
                 stepContentBean.setContentObjs(contentObjs);
+                // 空间范围
+                if (ObjTypeEnum.EQUIP_CLASS.getType().equals(objTypeMap.getOrDefault(objName,""))){
+                    String spaceObjName = CharSequenceUtil.trimToEmpty(StrUtil.utf8Str(CellUtil.getCellValue(firstSheet.getOrCreateCell(4,i))));
+                    if (StrUtil.isNotBlank(spaceObjName)){
+                        List<SpaceScopeBean> spaceScopeBeans = CollUtil.defaultIfEmpty(stepContentBean.getSpaceScope(), new ArrayList<>());
+                        spaceScopeBeans.add(SpaceScopeBean.builder()
+                                .objId(codeMap.getOrDefault(spaceObjName,"").substring(1))
+                                .objName(spaceObjName.substring(spaceObjName.lastIndexOf(SopCommonConst.UNDER_LINE)+1))
+                                .objCode(codeMap.getOrDefault(spaceObjName,"").substring(1))
+                                .objType(objTypeMap.getOrDefault(spaceObjName,""))
+                                .build());
+                        stepContentBean.setSpaceScope(spaceScopeBeans);
+                    }
+                }
                 sopStepsBean.setStepContent(stepContents);
             }
             List<StepContentBean> stepContents = sopStepsBean.getStepContent();
@@ -280,11 +484,11 @@ public class BatchHandleSopServiceImpl implements IBatchHandleSopService {
                 }
                 String hour = CharSequenceUtil.trimToEmpty(StrUtil.utf8Str(CellUtil.getCellValue(firstSheet.getOrCreateCell(9, i))));
                 if (StrUtil.isNotBlank(hour)){
-                    destMin = destMin + Integer.parseInt(hour)*60;
+                    destMin = null!=destMin ? (destMin + Integer.parseInt(hour)*60):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);
+                    destMin = null!=destMin ? (destMin + Integer.parseInt(min)):Integer.parseInt(min);
                 }
                 if (null!=destMin){
                     stepContentBean.setTimeLimit(destMin);
@@ -296,7 +500,7 @@ public class BatchHandleSopServiceImpl implements IBatchHandleSopService {
             }
             String notice = CharSequenceUtil.trimToEmpty(StrUtil.utf8Str(CellUtil.getCellValue(firstSheet.getOrCreateCell(12, i))));
             if (StrUtil.isBlank(stepContentBean.getNotice()) && StrUtil.isNotBlank(notice)){
-                stepContentBean.setPreConform(notice);
+                stepContentBean.setNotice(notice);
             }
             String confirmResultContent = CharSequenceUtil.trimToEmpty(StrUtil.utf8Str(CellUtil.getCellValue(firstSheet.getOrCreateCell(13, i))));
             Set<String> confirmResultContents = confirmResultMap.getOrDefault(sopName,new HashSet<>());
@@ -494,16 +698,22 @@ public class BatchHandleSopServiceImpl implements IBatchHandleSopService {
         Sheet infoSheet = workbook.getSheetAt(3);
         Map<String, List<InfoPointsBean>> infoCodeMap = queryAllInfoCodeData();
         writeObjClassDataToSheet(listSheet,lookSheet,workbook,infoSheet,infoCodeMap);
+
         // 3.设置第一个sheet的有效性:对象分类,第二列(1),第三行(2)开始
         Sheet firstSheet = workbook.getSheetAt(0);
         rewriteExcelTempAtEmp("=classData!$A$1:$A$6",firstSheet,2,65535,1,1);
         rewriteExcelTempAtEmp("=INDIRECT($B:$B)",firstSheet,2,65535,2,2);
+        rewriteExcelTempAtEmp("=IF(VLOOKUP($D:$D,codeData!B:C,2,FALSE)=\"equip_class\",空间功能类型,\"\")",firstSheet,2,65535,4,4);
         rewriteExcelTempAtEmp("=INDIRECT($D:$D)",firstSheet,2,65535,15,15);
+        rewriteExcelTempAtEmp("=classData!$A$7:$A$8",firstSheet,2,65535,6,6);
+        rewriteExcelTempAtEmp("=classData!$A$7:$A$8",firstSheet,2,65535,7,7);
+        rewriteExcelTempAtEmp("=classData!$A$7:$A$8",firstSheet,2,65535,14,14);
         //创建下拉框对象
         //CellUtil.setCellValue(CellUtil.getOrCreateCell(RowUtil.getOrCreateRow(firstSheet,2),1),"通用系统类",null);
         //CellUtil.setCellValue(CellUtil.getOrCreateCell(RowUtil.getOrCreateRow(firstSheet,2),2),"给排水专业-水景系统",null);
         for (int i=2;i<65535;i++){
             CellUtil.getOrCreateCell(RowUtil.getOrCreateRow(firstSheet,i),3).setCellFormula("IFERROR(VLOOKUP($C:$C,codeData!A:B,2,FALSE),\"\")");
+            CellUtil.getOrCreateCell(RowUtil.getOrCreateRow(firstSheet,i),5).setCellFormula("IFERROR(VLOOKUP($E:$E,codeData!A:B,2,FALSE),\"\")");
         }
         // 4.隐藏三个sheet页
         workbook.setSheetHidden(1,true);
@@ -594,6 +804,10 @@ public class BatchHandleSopServiceImpl implements IBatchHandleSopService {
                 .getOrCreateCell(RowUtil.getOrCreateRow(listSheet,4),0), ClassTypeEnum.FLOOR.getType(),null);
         CellUtil.setCellValue(CellUtil
                 .getOrCreateCell(RowUtil.getOrCreateRow(listSheet,5),0), ClassTypeEnum.SHAFT.getType(),null);
+        CellUtil.setCellValue(CellUtil
+                .getOrCreateCell(RowUtil.getOrCreateRow(listSheet,6),0), "是",null);
+        CellUtil.setCellValue(CellUtil
+                .getOrCreateCell(RowUtil.getOrCreateRow(listSheet,7),0), "否",null);
         // 2.填充"通用系统类"数据
         fillSystemClassData(listSheet, lookSheet,workbook,infoSheet,infoCodeMap);
         // 3.填充"通用设备类"数据

+ 54 - 61
fm-sop/src/main/java/com/persagy/fm/sop/service/impl/ObjectServiceImpl.java

@@ -1,12 +1,19 @@
 package com.persagy.fm.sop.service.impl;
 
+import cn.hutool.core.collection.CollUtil;
+import cn.hutool.core.util.StrUtil;
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.google.common.collect.Maps;
+import com.persagy.common.exception.BusinessException;
 import com.persagy.fm.common.old.utils.StringUtil;
 import com.persagy.fm.common.old.utils.ToolsUtil;
 import com.persagy.fm.sop.constant.SopCommonConst;
+import com.persagy.fm.sop.entity.CustomInfoPoint;
+import com.persagy.fm.sop.model.dto.CustomInfoPointsBean;
+import com.persagy.fm.sop.service.ICustomInfoPointService;
 import com.persagy.old.cache.ComponentRelationCache;
 import com.persagy.old.cache.DictionaryCache;
 import com.persagy.old.cache.GraphCache;
@@ -18,11 +25,13 @@ import com.persagy.old.dao.DBConst.Result;
 import com.persagy.fm.sop.service.BaseService;
 import com.persagy.fm.sop.service.IDictionaryService;
 import com.persagy.fm.sop.service.IObjectService;
+import lombok.RequiredArgsConstructor;
 import org.apache.commons.collections.CollectionUtils;
 import org.apache.commons.collections.MapUtils;
 import org.apache.log4j.Logger;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 
 import java.util.*;
 
@@ -33,22 +42,15 @@ import java.util.*;
  * Update By lijie 2021/4/19 12:07
  */
 @Service("objectService")
+@RequiredArgsConstructor
 public class ObjectServiceImpl extends BaseService implements IObjectService {
+    private final GraphCache graphCache;
+    private final DictionaryCache dictionaryCache;
+    private final IDictionaryService dictionaryService;
+    private final ComponentRelationCache componentRelationCache;
+    private final InfoPointCache infoPointCache;
+    private final ICustomInfoPointService customInfoPointService;
 
-    @Autowired
-    private GraphCache graphCache;
-
-    @Autowired
-    private DictionaryCache dictionaryCache;
-
-    @Autowired
-    private IDictionaryService dictionaryService;
-    
-    @Autowired
-    private ComponentRelationCache componentRelationCache;
-
-    @Autowired
-    private InfoPointCache infoPointCache;
     
     private static final Logger log = Logger.getLogger(ObjectServiceImpl.class);
     
@@ -3953,51 +3955,48 @@ public class ObjectServiceImpl extends BaseService implements IObjectService {
     }
 
     JSONArray queryCustomInfoPointList(JSONObject jsonObject){
-        jsonObject.put("valid",true);
-        String paramStr = JSONUtil.getCriteriaWithMajors(jsonObject, "valid","custom_info_point_id","custom_info_point_name").toJSONString();
-        String resultStr = DBCommonMethods.queryRecordByCriteria(DBConst.TABLE_CUSTOM_INFO_POINT, paramStr);
-        jsonObject = JSONObject.parseObject(resultStr);
-        JSONArray content = (JSONArray)jsonObject.getOrDefault(Result.CONTENT, new JSONArray());
-        for (int i = 0; i < content.size(); i++) {
-            JSONObject node = content.getJSONObject(i);
-            node.put("details", JSONObject.parseObject(node.getString("details")));
-        }
-        return (JSONArray)jsonObject.getOrDefault(Result.CONTENT,new JSONArray());
+		LambdaQueryWrapper<CustomInfoPoint> queryWrapper = new LambdaQueryWrapper<>();
+		queryWrapper.eq(CustomInfoPoint::getValid,true);
+		if (StrUtil.isNotBlank(jsonObject.getString("custom_info_point_id"))){
+			queryWrapper.eq(CustomInfoPoint::getCustomInfoPointId,jsonObject.getString("custom_info_point_id"));
+		}
+		if (StrUtil.isNotBlank(jsonObject.getString("custom_info_point_name"))){
+			queryWrapper.eq(CustomInfoPoint::getCustomInfoPointName,jsonObject.getString("custom_info_point_name"));
+		}
+		List<CustomInfoPoint> customInfoPoints = customInfoPointService.list(queryWrapper);
+		if (CollUtil.isEmpty(customInfoPoints)){
+			return new JSONArray();
+		}
+		return JSONArray.parseArray(JSON.toJSONString(customInfoPoints));
     }
 
     @Override
+	@Transactional(rollbackFor = BusinessException.class)
     public boolean addCustomInfoPoint(JSONObject jsonObject) {
-
 	    //=========验证custom_info_point_name 重复
         JSONObject param = new JSONObject();
         param.put("custom_info_point_name", jsonObject.getString("custom_info_point_name"));
         JSONArray jsonArray = queryCustomInfoPointList(param);
-        if (CollectionUtils.isNotEmpty(jsonArray)){
+        if (!jsonArray.isEmpty()){
             return false;
         }
-
-        //========添加数据
-        jsonObject.put("custom_info_point_id", ToolsUtil.getUuid());
-        jsonObject.put("valid", true);
-        String nowTimeStr = DateUtil.getNowTimeStr();
-        jsonObject.put("create_time", nowTimeStr);
-        jsonObject.put("update_time", nowTimeStr);
-        jsonObject = JSONUtil.getJsonObjectWithKeys(jsonObject,CommonMessage.table_column_custom_info_point);
-        jsonObject = JSONUtil.prossesParamToJsonString(jsonObject, "details");
-        String paramStr = JSONUtil.getAddParamJson(jsonObject).toJSONString();
-        String resultStr = DBCommonMethods.insertRecord(DBConst.TABLE_CUSTOM_INFO_POINT, paramStr);
-        jsonObject = JSONObject.parseObject(resultStr);
-
-        return Result.SUCCESS.equals(jsonObject.getString(Result.RESULT));
+		CustomInfoPoint customInfoPoint = CustomInfoPoint.builder()
+				.customInfoPointId(ToolsUtil.getUuid())
+				.customInfoPointName(jsonObject.getString("custom_info_point_name"))
+				.details(JSON.parseObject(jsonObject.getString("details"), CustomInfoPointsBean.class))
+				.build();
+        customInfoPointService.save(customInfoPoint);
+        return true;
     }
 
     @Override
+	@Transactional(rollbackFor = BusinessException.class)
     public boolean updateCustomInfoPoint(JSONObject jsonObject) {
         //======验证custom_info_point_name 重复
         JSONObject param = new JSONObject();
         param.put("custom_info_point_name", jsonObject.getString("custom_info_point_name"));
         JSONArray jsonArray = queryCustomInfoPointList(param);
-        if (CollectionUtils.isNotEmpty(jsonArray)){
+        if (!jsonArray.isEmpty()){
             String custom_info_point_id = jsonObject.getString("custom_info_point_id");
             for (int i = 0; i < jsonArray.size(); i++) {
                 if (!custom_info_point_id.equals(jsonArray.getJSONObject(i).getString("custom_info_point_id"))){
@@ -4005,30 +4004,24 @@ public class ObjectServiceImpl extends BaseService implements IObjectService {
                 }
             }
         }
-
-        //======更新数据
-        jsonObject.put("update_time", DateUtil.getNowTimeStr());
-        jsonObject = JSONUtil.getJsonObjectWithKeys(jsonObject,CommonMessage.table_column_custom_info_point);
-        jsonObject = JSONUtil.prossesParamToJsonString(jsonObject, "details");
-        String paramStr = JSONUtil.getUpdateParamJson(jsonObject,"custom_info_point_id").toJSONString();
-        String resultStr = DBCommonMethods.updateRecord(DBConst.TABLE_CUSTOM_INFO_POINT, paramStr);
-        jsonObject = JSONObject.parseObject(resultStr);
-
-        return Result.SUCCESS.equals(jsonObject.getString(Result.RESULT));
+		CustomInfoPoint customInfoPoint = CustomInfoPoint.builder()
+				.customInfoPointId(jsonObject.getString("custom_info_point_id"))
+				.customInfoPointName(jsonObject.getString("custom_info_point_name"))
+				.details(JSON.parseObject(jsonObject.getString("details"), CustomInfoPointsBean.class))
+				.build();
+		customInfoPointService.updateById(customInfoPoint);
+        return true;
     }
 
     @Override
+	@Transactional(rollbackFor = BusinessException.class)
     public boolean delelteCustomInfoPointById(JSONObject jsonObject) {
-
-        //=====逻辑移除数据
-        jsonObject.put("update_time", DateUtil.getNowTimeStr());
-        jsonObject.put("valid", false);
-        jsonObject = JSONUtil.getJsonObjectWithKeys(jsonObject,CommonMessage.table_column_custom_info_point);
-        String paramStr = JSONUtil.getUpdateParamJson(jsonObject,"custom_info_point_id").toJSONString();
-        String resultStr = DBCommonMethods.updateRecord(DBConst.TABLE_CUSTOM_INFO_POINT, paramStr);
-        jsonObject = JSONObject.parseObject(resultStr);
-
-        return Result.SUCCESS.equals(jsonObject.getString(Result.RESULT));
+		CustomInfoPoint customInfoPoint = CustomInfoPoint.builder()
+				.customInfoPointId(jsonObject.getString("custom_info_point_id"))
+				.valid(false)
+				.build();
+		customInfoPointService.updateById(customInfoPoint);
+		return true;
     }
 
 	@Override

BIN
fm-sop/src/main/resources/template/SOP导入模板.xlsx


BIN
fm-sop/src/main/resources/template/SOP数据.xlsx