Browse Source

添加功能

weijinhao 3 years ago
parent
commit
a4c1e9f759
27 changed files with 2243 additions and 284 deletions
  1. 33 187
      fm-sop/src/main/java/com/persagy/fm/sop/controller/GroupSopController.java
  2. 1 0
      fm-sop/src/main/java/com/persagy/fm/sop/dao/SopMapper.xml
  3. 11 0
      fm-sop/src/main/java/com/persagy/fm/sop/mapper/SopMapper.java
  4. 2 48
      fm-sop/src/main/java/com/persagy/fm/sop/model/SopDTO.java
  5. 59 0
      fm-sop/src/main/java/com/persagy/fm/sop/model/dto/Profile.java
  6. 1 0
      fm-sop/src/main/java/com/persagy/fm/sop/model/dto/Sop.java
  7. 21 1
      fm-sop/src/main/java/com/persagy/fm/sop/model/dto/SopHis.java
  8. 2 1
      fm-sop/src/main/java/com/persagy/fm/sop/model/dto/SopObjRel.java
  9. 29 0
      fm-sop/src/main/java/com/persagy/fm/sop/model/dto/SopStepsBean.java
  10. 39 0
      fm-sop/src/main/java/com/persagy/fm/sop/model/vo/QueryHistoryListVo.java
  11. 10 0
      fm-sop/src/main/java/com/persagy/fm/sop/service/EquipModelServiceI.java
  12. 46 0
      fm-sop/src/main/java/com/persagy/fm/sop/service/GroupSopService.java
  13. 7 0
      fm-sop/src/main/java/com/persagy/fm/sop/service/SopEquipModelRelService.java
  14. 4 0
      fm-sop/src/main/java/com/persagy/fm/sop/service/SopLabelRelService.java
  15. 7 1
      fm-sop/src/main/java/com/persagy/fm/sop/service/SopObjRelService.java
  16. 4 0
      fm-sop/src/main/java/com/persagy/fm/sop/service/SopOrderTypeRelService.java
  17. 2 0
      fm-sop/src/main/java/com/persagy/fm/sop/service/SopSopRelService.java
  18. 34 0
      fm-sop/src/main/java/com/persagy/fm/sop/service/SopState.java
  19. 41 0
      fm-sop/src/main/java/com/persagy/fm/sop/service/SopStateMachine.java
  20. 430 36
      fm-sop/src/main/java/com/persagy/fm/sop/service/impl/GroupSopServiceImpl.java
  21. 21 2
      fm-sop/src/main/java/com/persagy/fm/sop/service/impl/SopEquipModelRelServiceImpl.java
  22. 18 2
      fm-sop/src/main/java/com/persagy/fm/sop/service/impl/SopLabelRelServiceImpl.java
  23. 18 2
      fm-sop/src/main/java/com/persagy/fm/sop/service/impl/SopObjRelServiceImpl.java
  24. 19 2
      fm-sop/src/main/java/com/persagy/fm/sop/service/impl/SopOrderTypeRelServiceImpl.java
  25. 10 2
      fm-sop/src/main/java/com/persagy/fm/sop/service/impl/SopSopRelServiceImpl.java
  26. 24 0
      fm-sop/src/main/java/com/persagy/old/service/WoFlowPlanServiceI.java
  27. 1350 0
      fm-sop/src/main/java/com/persagy/old/service/impl/WoFlowPlanServiceImpl2.java

+ 33 - 187
fm-sop/src/main/java/com/persagy/fm/sop/controller/GroupSopController.java

@@ -6,6 +6,7 @@ import com.persagy.fm.common.response.FmResponseUtil;
 import com.persagy.fm.sop.model.dto.RefSopInfo;
 import com.persagy.fm.sop.model.vo.*;
 import com.persagy.fm.sop.service.GroupSopService;
+import com.persagy.fm.sop.service.SopEditService;
 import com.persagy.old.common.CommonConst;
 import com.persagy.old.common.ToolsUtil;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -134,6 +135,7 @@ public class GroupSopController {
     @PostMapping("/saveDraftSop")
     public String saveDraftSop(@RequestBody SaveDraftSopVo saveSopVo) throws Exception {
         saveSopVo.setProject_id(CommonConst.group_sop_id);
+        groupSopService.saveDraftSop(saveSopVo);
         return ToolsUtil.successJsonMsg("");
     }
 
@@ -163,199 +165,43 @@ public class GroupSopController {
         return ToolsUtil.successJsonMsg(item);
     }
 
-
-
-
- /*   @Autowired
-    private SopService sopService;
-
-    *//**
-     * 集团sop-编辑页-发布sop
-     *
-     * @param saveSopVo
+    /**
+     * 集团sop-列表页  查询已作废中的sop列表
+     * @param queryHistoryListVo
      * @return
      * @throws Exception
-     *//*
-    @PostMapping("/publishSop")
-    public String publishSop(@RequestBody SaveSopVo saveSopVo) throws Exception {
-        saveSopVo.setProject_id(CommonConst.group_sop_id);
-        //根据sopid 和valid
-
-        QueryWrapper<Sop> query = new QueryWrapper<>();
-        String sop_id = saveSopVo.getSop_id();
-        query.eq("sop_id", sop_id).eq("valid", true);
-        Sop one = sopService.getOne(query);
-
-        Integer versionCount = null;
-        boolean isUpdate = true;
-
-        //此处不是很明白,明明都是空了为啥还有获取
-        if (one == null) {
-            isUpdate = false;
-        } else {
-            versionCount = one.getVersionCount();
-        }
-
-
-        Map<String, Map<String, Object>> sopId_RefProfile = proccessSopIdRefProfile(one.getRefSopIds());
-        if(sopId_RefProfile != null) {
-            if(isUpdate) {
-                proccessSopItem(one,sopId_RefProfile,null);
-            }
-        }else {
-
-        }
-
-        return null;
+     */
+    @PostMapping("/queryDestroyedSopList")
+    public String queryDestroyedSopList(@RequestBody QueryHistoryListVo queryHistoryListVo) throws Exception{
+        queryHistoryListVo.setProjectId(CommonConst.group_sop_id);
+        return groupSopService.queryDestroyedSopList(queryHistoryListVo).toString();
     }
 
-
-    *//**
-     * 处理sop详情 补充引用sop简介,添加内容对象变化标识
-     * @param sop
-     * @param refSopProfile
-     * @Param changedObjIds     objId //对象变化数据key:objId value:{"objId":objId, "objName":objName, "objType":objType}
+    @Autowired
+    private SopEditService sopEditService;
+    /**
+     * 集团sop-列表页 查询编辑中的sop列表
+     * @param queryHistoryListVo
      * @return
-     *//*
-    public JSONObject proccessSopItem(Sop sop, Map<String, Map<String, Object>> refSopProfile, Set<String> changedObjIds) {
-        *//*
-         if(changedObjIds != null) {
-            fitObjs = (JSONArray)sop.getOrDefault("fit_objs", new JSONArray());
-            fitObjs = fitObjs == null ? new JSONArray() : fitObjs;
-            for (int i = 0; i < fitObjs.size(); i++) {
-                fitObj = fitObjs.getJSONObject(i);
-                if(changedObjIds.contains(fitObj.getString("obj_id"))){
-                    fitObj.put("is_revise", true);
-                }
-            }
-        }
-         *//*
-
-
-
-        //处理步骤
-        List<SopStepsBean> steps = sop.getSteps();
-        if(CollectionUtils.isNotEmpty(steps)) {
-            for (SopStepsBean step : steps) {
-                if(step.isFrom_sop()) {
-                    //大步为引用sop
-                    String refSopId = step.getSop_id();
-                    Map<String, Object> stringObjectMap = refSopProfile.get(refSopId);
-                   if(stringObjectMap != null) {
-                        *//**********************************//*
-                        //step.putAll(profile);
-                   }
-
-                }else {
-                    List<SopStepsBean.StepContentBean> step_content = step.getStep_content();
-                    if(CollectionUtils.isNotEmpty(step_content)) {
-                        for (SopStepsBean.StepContentBean stepContentBean : step_content) {
-                            if(stepContentBean.isFrom_sop()) {
-                                String refSopId = stepContentBean.getSop_id();
-                                Map<String, Object> stringObjectMap = refSopProfile.get(refSopId);
-                                if(stringObjectMap != null) {
-                                    *//**********************************//*
-                                    //step.putAll(profile);
-                                }
-                            }
-
-                            *//*
-                            {
-                        if(!stepContent.getBooleanValue("from_sop")){
-                            //非引用sop操作
-                            //操作内容
-                            contentObjs = (JSONArray)stepContent.getOrDefault("content_objs", new JSONArray());
-                            if(contentObjs != null){
-                                for(int k=0; k<contentObjs.size(); k++){
-                                    contentObj = contentObjs.getJSONObject(k);
-                                    if(changedObjIds.contains(contentObj.getString("obj_id"))){
-                                        //内容对象变化
-                                        contentObj.put("is_revise", true);
-                                    }else{
-                                        parents = (JSONArray)contentObj.getOrDefault("parents", new JSONArray());
-                                        if(parents != null){
-                                            for(int l=0; l<parents.size(); l++){
-                                                parent = parents.getJSONObject(l);
-                                                parentIds = (JSONArray)parent.getOrDefault("parent_ids", new JSONArray());
-                                                if(parentIds != null){
-                                                    for(int m=0; m<parentIds.size(); m++){
-                                                        parentId = parentIds.getString(m);
-                                                        if(changedObjIds.contains(parentId)){
-                                                            //内容对象所属大类变化
-                                                            contentObj.put("is_revise", true);
-                                                        }
-                                                    }
-                                                }
-                                            }
-                                        }
-                                    }
-                                }
-                            }
-                            //确认结果
-                            if(changedObjIds != null && changedObjIds.size() > 0){
-                                        confirmResults = (JSONArray)stepContent.getOrDefault("confirm_result", new JSONArray());
-                                        if(confirmResults != null){
-                                            for(int k=0; k<confirmResults.size(); k++){
-                                                confirmResult = confirmResults.getJSONObject(k);
-                                                if(changedObjIds.contains(confirmResult.getString("obj_id"))){
-                                                    //确认结果对象变化
-                                                    confirmResult.put("is_revise", true);
-                                                }else{
-                                                    parents = confirmResult.getJSONArray("parents");
-                                                    if(parents != null){
-                                                        for(int l=0; l<parents.size(); l++){
-                                                            parent = parents.getJSONObject(l);
-                                                            parentIds = parent.getJSONArray("parent_ids");
-                                                            if(parentIds != null){
-                                                                for(int m=0; m<parentIds.size(); m++){
-                                                                    parentId = parentIds.getString(m);
-                                                                    if(changedObjIds.contains(parentId)){
-                                                                        //确认结果所属大类变化
-                                                                        confirmResult.put("is_revise", true);
-                                                                    }
-                                                                }
-                                                            }
-                                                        }
-                                                    }
-                                                }
-                                                //信息点
-                                                infoPoints = (JSONArray)confirmResult.getOrDefault("info_points", new JSONArray());
-                                                infoPoints = infoPoints == null ? new JSONArray() : infoPoints;
-                                                for(int l=0; l<infoPoints.size(); l++){
-                                                    infoPoint = infoPoints.getJSONObject(l);
-                                                    if(changedObjIds.contains(infoPoint.getString("id"))){
-                                                        //信息点变化
-                                                        infoPoint.put("is_revise", true);
-                                                    }
-                                                }
-                                            }
-                                        }
-                                    }
-                                }
-                                }
-                             *//*
-
-
-                        }
-                    }
-                }
-            }
-        }
-
-
-        return null;
+     * @throws Exception
+     */
+    @PostMapping("/queryEditingSopList")
+    public String queryEditingSopList(@RequestBody QueryHistoryListVo queryHistoryListVo) throws Exception{
+        //根据
+        queryHistoryListVo.setProjectId(CommonConst.group_sop_id);
+        return groupSopService.queryEditingSopList(queryHistoryListVo).toJSONString();
     }
-*/
 
-        /**
-         * 处理引用的sop id与简介(sop_name,version,step_count,status_explain,update_time)
-         *
-         * @param refSopIds 被引用sopId集合
-         * @return map      key:sopId  value:sop对象
-         * @throws Exception
-         * @Param userId        调用者
-         */
-    public Map<String, Map<String, Object>> proccessSopIdRefProfile(List<String> refSopIds) throws Exception {
-        return null;
+    /**
+     * 集团sop-编辑页-发布sop
+     * @param jsonStr
+     * @return
+     * @throws Exception
+     */
+    @PostMapping("/publishSop")
+    public String publishSop(@RequestBody SaveSopVo saveSopVo) throws Exception{
+        groupSopService.publishSop(saveSopVo);
+        return ToolsUtil.successJsonMsg("发布成功");
     }
+
 }

+ 1 - 0
fm-sop/src/main/java/com/persagy/fm/sop/dao/SopMapper.xml

@@ -36,4 +36,5 @@
         sop_id, project_id, extend_field, operator, sop_name, sop_type, no_obj, domains, order_type, tools, fit_objs, equip_model_ids, labels, steps_version, steps, related_data, sop_status, publish_status, ref_sop_ids, version, version_count, version_explain, version_exp, valid, update_time
     </sql>
 
+
 </mapper>

+ 11 - 0
fm-sop/src/main/java/com/persagy/fm/sop/mapper/SopMapper.java

@@ -1,7 +1,9 @@
 package com.persagy.fm.sop.mapper;
 
+import com.persagy.fm.sop.model.dto.Profile;
 import com.persagy.fm.sop.model.dto.Sop;
 import com.persagy.fm.sop.model.dto.SopEdit;
+import com.persagy.fm.sop.model.dto.SopHis;
 import com.persagy.fm.sop.model.vo.SaveSopEditVo;
 import com.persagy.fm.sop.model.vo.SaveSopVo;
 import org.mapstruct.Mapper;
@@ -98,6 +100,15 @@ public interface SopMapper {
     SaveSopEditVo  SopEditToSaveSopEditVo(SopEdit sopEdit);
 
 
+    @Mapping(target = "ref_sop_id" ,source ="sop_id" )
+    @Mapping(target = "ref_sop_name" ,source ="sop_name" )
+    @Mapping(target = "version" ,source ="version" )
+    @Mapping(target = "stauts_explain" ,source ="stauts_explain" )
+    @Mapping(target = "update_time" ,source ="update_time" )
+    @Mapping(target = "step_count" ,source ="step_count" )
+    SopHis.RefedSopBean profileToRefedSopBean(Profile profile);
+
+
 
 
 }

+ 2 - 48
fm-sop/src/main/java/com/persagy/fm/sop/model/SopDTO.java

@@ -1,53 +1,7 @@
 package com.persagy.fm.sop.model;
 
-import com.persagy.fm.common.model.entity.AuditableEntity;
-import lombok.Data;
+import com.persagy.fm.sop.model.dto.Sop;
 
-/**
- * SOP实体
- * @author Charlie Yu
- * @date 2021-03-05
- */
-@Data
-public class SopDTO extends AuditableEntity {
-
-    /** 项目主键 */
-    private String projectId;
-    /** 项目类型 */
-    private String projectType;
-    /** 名称 */
-    private String sopName;
-    /** 类型 */
-    private String sopType;
-    /** 是否有无对象的步骤 */
-    private Boolean noneFlag;
-    /** 专业编码 */
-    private String domains;
-    /** 工单类型 */
-    private String orderType;
-    /** 所需工具 */
-    private String tools;
-    /** 适用对象 */
-    private String fitObjs;
-    /** 设备型号 */
-    private String deviceType;
-    /** 自定义标签 */
-    private String labels;
-    /** 步骤 */
-    private String steps;
-    /** 相关资料 */
-    private String relatedData;
-    /** 状态 1-已发布、2-已作废 */
-    private String sopStatus;
-    /** 发布状态 1-正常、2-待修订、3-修订中 */
-    private String publishStatus;
-    /** 引用的sop */
-    private String refSops;
-    /** 版本号 */
-    private String version;
-    /** 版本数量 */
-    private String versionCount;
-    /** 版本说明 */
-    private String versionExplain;
+public class SopDTO extends Sop {
 
 }

+ 59 - 0
fm-sop/src/main/java/com/persagy/fm/sop/model/dto/Profile.java

@@ -0,0 +1,59 @@
+package com.persagy.fm.sop.model.dto;
+
+public  class Profile {
+    private String sop_id;
+    private String sop_name;
+    private String version;
+    private Integer step_count;
+    private String stauts_explain;
+    private String update_time;
+
+
+    public String getSop_id() {
+        return sop_id;
+    }
+
+    public void setSop_id(String sop_id) {
+        this.sop_id = sop_id;
+    }
+
+    public String getSop_name() {
+        return sop_name;
+    }
+
+    public void setSop_name(String sop_name) {
+        this.sop_name = sop_name;
+    }
+
+    public String getVersion() {
+        return version;
+    }
+
+    public void setVersion(String version) {
+        this.version = version;
+    }
+
+    public Integer getStep_count() {
+        return step_count;
+    }
+
+    public void setStep_count(Integer step_count) {
+        this.step_count = step_count;
+    }
+
+    public String getStauts_explain() {
+        return stauts_explain;
+    }
+
+    public void setStauts_explain(String stauts_explain) {
+        this.stauts_explain = stauts_explain;
+    }
+
+    public String getUpdate_time() {
+        return update_time;
+    }
+
+    public void setUpdate_time(String update_time) {
+        this.update_time = update_time;
+    }
+}

+ 1 - 0
fm-sop/src/main/java/com/persagy/fm/sop/model/dto/Sop.java

@@ -353,6 +353,7 @@ public class Sop extends Model<Sop> {
         private String obj_source;
         private String obj_code;
 
+
         public String getObj_id() {
             return obj_id;
         }

+ 21 - 1
fm-sop/src/main/java/com/persagy/fm/sop/model/dto/SopHis.java

@@ -372,6 +372,17 @@ public class SopHis extends Model<SopHis> {
         private String obj_source;
         private String obj_code;
 
+        //该对象是否变化
+        private Boolean is_revise;
+
+        public Boolean getIs_revise() {
+            return is_revise;
+        }
+
+        public void setIs_revise(Boolean is_revise) {
+            this.is_revise = is_revise;
+        }
+
         public String getObj_id() {
             return obj_id;
         }
@@ -440,7 +451,7 @@ public class SopHis extends Model<SopHis> {
     }
 
 
-    private class RefedSopBean {
+    public static class RefedSopBean {
 
 
         /**
@@ -456,6 +467,15 @@ public class SopHis extends Model<SopHis> {
         private String version;
         private String stauts_explain;
         private String update_time;
+        private Integer step_count;
+
+        public Integer getStep_count() {
+            return step_count;
+        }
+
+        public void setStep_count(Integer step_count) {
+            this.step_count = step_count;
+        }
 
         public String getRef_sop_id() {
             return ref_sop_id;

+ 2 - 1
fm-sop/src/main/java/com/persagy/fm/sop/model/dto/SopObjRel.java

@@ -1,8 +1,9 @@
 package com.persagy.fm.sop.model.dto;
 
 import com.baomidou.mybatisplus.annotation.IdType;
-import com.baomidou.mybatisplus.extension.activerecord.Model;
 import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.extension.activerecord.Model;
+
 import java.io.Serializable;
 
 /**

+ 29 - 0
fm-sop/src/main/java/com/persagy/fm/sop/model/dto/SopStepsBean.java

@@ -20,6 +20,20 @@ public class SopStepsBean {
     private Boolean from_sop;
     private String sop_id;
     private List<@Valid StepContentBean> step_content;
+    private SopHis.RefedSopBean profile;
+
+    public SopHis.RefedSopBean getProfile() {
+        return profile;
+    }
+
+    public void setProfile(SopHis.RefedSopBean profile) {
+        this.profile = profile;
+    }
+
+    public Boolean getFrom_sop() {
+        return from_sop;
+    }
+
 
     public Boolean isFrom_sop() {
         return from_sop;
@@ -74,6 +88,21 @@ public class SopStepsBean {
         private List<String> obj_show_item;
         private List<@Valid ConfirmResultBean> confirm_result;
 
+        private SopHis.RefedSopBean profile;
+
+
+        public Boolean getFrom_sop() {
+            return from_sop;
+        }
+
+        public SopHis.RefedSopBean getProfile() {
+            return profile;
+        }
+
+        public void setProfile(SopHis.RefedSopBean profile) {
+            this.profile = profile;
+        }
+
         public Boolean isFrom_sop() {
             return from_sop;
         }

+ 39 - 0
fm-sop/src/main/java/com/persagy/fm/sop/model/vo/QueryHistoryListVo.java

@@ -0,0 +1,39 @@
+package com.persagy.fm.sop.model.vo;
+
+public class QueryHistoryListVo {
+
+
+    /**
+     * user_id : ***
+     * sop_name : ***
+     */
+
+    private String user_id;
+    private String sop_name;
+    private String projectId;
+
+
+    public String getProjectId() {
+        return projectId;
+    }
+
+    public void setProjectId(String projectId) {
+        this.projectId = projectId;
+    }
+
+    public String getUser_id() {
+        return user_id;
+    }
+
+    public void setUser_id(String user_id) {
+        this.user_id = user_id;
+    }
+
+    public String getSop_name() {
+        return sop_name;
+    }
+
+    public void setSop_name(String sop_name) {
+        this.sop_name = sop_name;
+    }
+}

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

@@ -0,0 +1,10 @@
+package com.persagy.fm.sop.service;
+
+public class EquipModelServiceI {
+
+    /**
+     * 根据设备id 查询设备类型
+     */
+
+
+}

+ 46 - 0
fm-sop/src/main/java/com/persagy/fm/sop/service/GroupSopService.java

@@ -1,6 +1,7 @@
 package com.persagy.fm.sop.service;
 
 import com.alibaba.fastjson.JSONObject;
+import com.persagy.fm.sop.model.SopDTO;
 import com.persagy.fm.sop.model.dto.RefSopInfo;
 import com.persagy.fm.sop.model.dto.SopEdit;
 import com.persagy.fm.sop.model.vo.*;
@@ -11,6 +12,40 @@ import java.util.Set;
 public interface GroupSopService {
 
     /**
+     * 查询编辑中的sop列表设置默认的项目ID, 调用RestSopService中queryEditingSopList接口
+     * @param queryHistoryListVo
+     * @return
+     * @throws Exception
+     */
+    public JSONObject queryEditingSopList(QueryHistoryListVo queryHistoryListVo ) throws Exception ;
+
+
+    public JSONObject queryDestroyedSopList(QueryHistoryListVo queryHistoryListVo) throws Exception ;
+
+
+    /**
+     *
+     * Description: 条件过滤
+     * @param sops
+     * @param destoryFlag
+     * @return
+     * @throws Exception JSONObject
+     * @author yuecaipu
+     * @since 2018年5月2日: 下午2:11:59
+     * Update By yuecaipu 2018年5月2日: 下午2:11:59
+     */
+    public JSONObject filterRemind(List<SopDTO> sops, boolean destoryFlag) throws Exception ;
+
+    /**
+     * 查询已作废的sop列表
+     * @param jsonStr
+     * @return
+     * @throws Exception
+     */
+    public String queryDestroyedSopList(JSONObject jsonObject) throws Exception;
+
+
+    /**
      * 查询已发布的sop列表
      *              设置默认的项目ID
      * @param jsonStr
@@ -80,4 +115,15 @@ public interface GroupSopService {
      */
     public JSONObject querySopListForSel(QuerySopListForSelVo sopListForSelVo)throws Exception;
 
+    /**
+     * 集团sop-新增页-添加发布状态sop
+     * @param saveSopVo
+     * @return
+     * @throws Exception
+     */
+    public boolean publishSop(SaveSopVo saveSopVo) throws Exception;
+
+
+
+
 }

+ 7 - 0
fm-sop/src/main/java/com/persagy/fm/sop/service/SopEquipModelRelService.java

@@ -3,6 +3,8 @@ package com.persagy.fm.sop.service;
 import com.persagy.fm.sop.model.dto.SopEquipModelRel;
 import com.baomidou.mybatisplus.extension.service.IService;
 
+import java.util.List;
+
 /**
  * <p>
  *  服务类
@@ -13,4 +15,9 @@ import com.baomidou.mybatisplus.extension.service.IService;
  */
 public interface SopEquipModelRelService extends IService<SopEquipModelRel> {
 
+    public boolean deleteBySopId(String sopId);
+
+    public List<SopEquipModelRel> selectByEquipModelIds(List<String> equip_model_ids) ;
+
+
 }

+ 4 - 0
fm-sop/src/main/java/com/persagy/fm/sop/service/SopLabelRelService.java

@@ -3,6 +3,8 @@ package com.persagy.fm.sop.service;
 import com.persagy.fm.sop.model.dto.SopLabelRel;
 import com.baomidou.mybatisplus.extension.service.IService;
 
+import java.util.List;
+
 /**
  * <p>
  *  服务类
@@ -12,5 +14,7 @@ import com.baomidou.mybatisplus.extension.service.IService;
  * @since 2021-03-17
  */
 public interface SopLabelRelService extends IService<SopLabelRel> {
+    public boolean deleteBySopId(String sopId);
 
+    public List<SopLabelRel> selectByLabels(List<String> labels) ;
 }

+ 7 - 1
fm-sop/src/main/java/com/persagy/fm/sop/service/SopObjRelService.java

@@ -1,7 +1,9 @@
 package com.persagy.fm.sop.service;
 
-import com.persagy.fm.sop.model.dto.SopObjRel;
 import com.baomidou.mybatisplus.extension.service.IService;
+import com.persagy.fm.sop.model.dto.SopObjRel;
+
+import java.util.List;
 
 /**
  * <p>
@@ -13,4 +15,8 @@ import com.baomidou.mybatisplus.extension.service.IService;
  */
 public interface SopObjRelService extends IService<SopObjRel> {
 
+    public boolean deleteBySopId(String sopId);
+    public List<SopObjRel> selectByObjectIds(List<String> objectIds) ;
+
+
 }

+ 4 - 0
fm-sop/src/main/java/com/persagy/fm/sop/service/SopOrderTypeRelService.java

@@ -3,6 +3,8 @@ package com.persagy.fm.sop.service;
 import com.persagy.fm.sop.model.dto.SopOrderTypeRel;
 import com.baomidou.mybatisplus.extension.service.IService;
 
+import java.util.List;
+
 /**
  * <p>
  *  服务类
@@ -12,5 +14,7 @@ import com.baomidou.mybatisplus.extension.service.IService;
  * @since 2021-03-17
  */
 public interface SopOrderTypeRelService extends IService<SopOrderTypeRel> {
+    public boolean deleteBySopId(String sopId);
 
+    public List<SopOrderTypeRel> selectByOrderTypes(List<String> orderTypes)  ;
 }

+ 2 - 0
fm-sop/src/main/java/com/persagy/fm/sop/service/SopSopRelService.java

@@ -13,4 +13,6 @@ import com.baomidou.mybatisplus.extension.service.IService;
  */
 public interface SopSopRelService extends IService<SopSopRel> {
 
+    public boolean deleteBySopId(String sopId);
+
 }

+ 34 - 0
fm-sop/src/main/java/com/persagy/fm/sop/service/SopState.java

@@ -0,0 +1,34 @@
+package com.persagy.fm.sop.service;
+
+import com.persagy.old.common.SopConst;
+
+public enum SopState {
+
+    NORMAL2DRAFT(SopConst.PUBLISH_STATUS_NORMAL,SopConst.SOP_STATUS_DRAFT),
+    NORMAL2PUBLISH (SopConst.PUBLISH_STATUS_NORMAL,SopConst.SOP_STATUS_PUBLISH),
+    NORMAL2DESTROYED(SopConst.PUBLISH_STATUS_NORMAL,SopConst.SOP_STATUS_DESTROYED),
+
+    REVISE2DRAFT(SopConst.PUBLISH_STATUS_REVISE,SopConst.SOP_STATUS_DRAFT),
+    REVISE2PUBLISH(SopConst.PUBLISH_STATUS_REVISE,SopConst.SOP_STATUS_PUBLISH),
+    REVISE2DESTROYED(SopConst.PUBLISH_STATUS_REVISE,SopConst.SOP_STATUS_DESTROYED),
+
+    REVISEING2DRAFT(SopConst.PUBLISH_STATUS_REVISEING,SopConst.SOP_STATUS_DRAFT),
+    REVISEING2PUBLISH(SopConst.PUBLISH_STATUS_REVISEING,SopConst.SOP_STATUS_PUBLISH),
+    REVISEING2DESTROYED(SopConst.PUBLISH_STATUS_REVISEING,SopConst.SOP_STATUS_DESTROYED);
+
+    private String publicStatus;
+    private String sopStatus;
+
+    SopState(String publicStatus, String sopStatus) {
+        this.publicStatus = publicStatus;
+        this.sopStatus = sopStatus;
+    }
+
+    public String getPublicStatus() {
+        return publicStatus;
+    }
+
+    public String getSopStatus() {
+        return sopStatus;
+    }
+}

+ 41 - 0
fm-sop/src/main/java/com/persagy/fm/sop/service/SopStateMachine.java

@@ -0,0 +1,41 @@
+package com.persagy.fm.sop.service;
+
+import org.springframework.stereotype.Service;
+
+@Service
+public class SopStateMachine {
+    //新建保存草稿
+    public SopState saveDraft() {
+        return SopState.NORMAL2DRAFT;
+    }
+    //未发布草稿到发布
+    public SopState newDraft2public() {
+        return SopState.NORMAL2PUBLISH;
+    }
+    //新建到直接发布
+    public SopState newPublic() {
+        return SopState.NORMAL2PUBLISH;
+    }
+
+    //未发布草稿  删除
+    public SopState newDraft2Delete() throws Exception {
+        throw new Exception("不支持该该方法");
+    }
+
+    //已发布编辑 草稿 到发布
+    public SopState publicDraft2Public() {
+        return SopState.NORMAL2PUBLISH;
+    }
+
+    //已发布 编辑 保存草稿
+    public SopState public2Draft() {
+        return SopState.REVISEING2PUBLISH;
+    }
+
+    //已发布点击作废
+    public SopState public2Distory() {
+        return SopState.NORMAL2DESTROYED;
+    }
+
+
+}

+ 430 - 36
fm-sop/src/main/java/com/persagy/fm/sop/service/impl/GroupSopServiceImpl.java

@@ -5,11 +5,15 @@ import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.persagy.fm.common.exception.BusinessValidatorException;
 import com.persagy.fm.sop.mapper.SopMapper;
+import com.persagy.fm.sop.model.SopDTO;
 import com.persagy.fm.sop.model.dto.*;
 import com.persagy.fm.sop.model.vo.*;
 import com.persagy.fm.sop.service.*;
 import com.persagy.old.cache.OrderTypeCache;
-import com.persagy.old.common.*;
+import com.persagy.old.common.CommonConst;
+import com.persagy.old.common.DateUtil;
+import com.persagy.old.common.SopConst;
+import com.persagy.old.common.StringUtil;
 import com.persagy.old.dao.DBConst;
 import com.persagy.old.dao.DBConst.Result;
 import com.persagy.old.service.EquipModelServiceI;
@@ -55,12 +59,21 @@ public class GroupSopServiceImpl implements GroupSopService {
     @Autowired
     private SopEquipModelRelService sopEquipModelRelService;
 
+   /* @Autowired
+    private WoFlowPlanServiceI woFlowPlanService;
+*/
+    @Autowired
+    private SopStateMachine sopStateMachine;
+
+    @Autowired
+    private SopHisService sopHisService;
+
 
     @Override
     public JSONObject queryPublishedSopList(QuerySopListForSelVo sopListForSelVo) throws Exception {
         String projectId = sopListForSelVo.getProjectId();
         //1.根据update和项目id查询
-        List<Sop> sops = queryPublishedSopsByProjectIdAndUpdatetime(sopListForSelVo, projectId);
+        List<Sop> sops = queryPublishedSopsByProjectIdAndUpdatetime(sopListForSelVo);
         /*
             //========2.移除待修订状态sop=======
             //如果不是集团的sop的查询
@@ -102,8 +115,11 @@ public class GroupSopServiceImpl implements GroupSopService {
         //将 请求体中的参数拷贝到我们里面
         //将对象映射到数据库实体上面去
         Sop sop = SopMapper.INSTANCE.SaveSopVoToSop(saveSopVo);
-        sop.setSopStatus(SopConst.SOP_STATUS_PUBLISH);
-        sop.setPublishStatus(SopConst.PUBLISH_STATUS_NORMAL);
+        /*sop.setSopStatus(SopConst.SOP_STATUS_PUBLISH);
+        sop.setPublishStatus(SopConst.PUBLISH_STATUS_NORMAL);*/
+        SopState sopState = sopStateMachine.newPublic();
+        //设置状态
+        setSopStatus(sop, sopState);
         sop.setVersionCount(1);
         sop.setVersion("V0.1");
         sop.setVersionExplain("[\""+ CommonConst.version_explain_create+"\"]");
@@ -112,6 +128,11 @@ public class GroupSopServiceImpl implements GroupSopService {
         return true;
     }
 
+    private void setSopStatus(Sop sop, SopState sopState) {
+        sop.setPublishStatus(sopState.getPublicStatus());
+        sop.setSopStatus(sopState.getSopStatus());
+    }
+
     @Override
     public boolean verifySopForPublish(SaveSopVo saveSopVo) throws Exception {
         String projectId = saveSopVo.getProject_id();
@@ -344,21 +365,45 @@ public class GroupSopServiceImpl implements GroupSopService {
     @Override
     public String addDraftSop(SaveSopEditVo saveSopEditVo) throws Exception {
         Set<String> sopRefSops = this.getSopRefSops(saveSopEditVo);
-        saveSopEditVo.setSop_id(UUID.randomUUID().toString().replaceAll("-",""));
+        saveSopEditVo.setSop_edit_id(UUID.randomUUID().toString().replaceAll("-",""));
 
         //将表单提交的值拷贝过来
         SopEdit sopEdit = SopMapper.INSTANCE.SaveSopEditVoToSopEdit(saveSopEditVo);
         sopEdit.setRefSopIds(new ArrayList<>(sopRefSops));
-        insertRecord(sopEdit);
+        if (StringUtils.isBlank(sopEdit.getSopId())) {
+            sopEdit.setSopId(UUID.randomUUID().toString().replaceAll("-", ""));
+        }
+        //sop类型 1 通用    2 项目专用
+        if(CommonConst.group_sop_id.equals(saveSopEditVo.getProject_id())) {
+            sopEdit.setSopType(SopConst.SOP_TYPE_GROUP);
+        }else {
+            sopEdit.setSopType(SopConst.SOP_TYPE_PROJECT);
+        }
+        if(StringUtils.isBlank(sopEdit.getSopStatus())) {
+            //sop状态 0 草稿  1 已发布   2 已作废
+            //则是新建的
+            SopState sopState = sopStateMachine.saveDraft();
+            setEditSopStatus(sopEdit, sopState);
+
+        }else {
+            SopState sopState = sopStateMachine.public2Draft();
+            setEditSopStatus(sopEdit,sopState);
+        }
+        sopEdit.insert();
         return sopEdit.getSopId();
     }
 
+    private void setEditSopStatus(SopEdit sopEdit, SopState sopState) {
+        sopEdit.setSopStatus(sopState.getSopStatus());
+        sopEdit.setPublishStatus(sopState.getPublicStatus());
+    }
+
     public boolean insertRecord(SopEdit sopEdit) throws Exception {
         if (StringUtils.isBlank(sopEdit.getSopId())) {
             sopEdit.setSopId(UUID.randomUUID().toString().replaceAll("-", ""));
         }
         //sop类型 1 通用    2 项目专用
-        sopEdit.setSopType("1");
+        sopEdit.setSopType(SopConst.SOP_TYPE_GROUP);
 
         if(StringUtils.isBlank(sopEdit.getSopStatus())) {
             //sop状态 0 草稿  1 已发布   2 已作废
@@ -411,7 +456,8 @@ public class GroupSopServiceImpl implements GroupSopService {
             update.setRefSopIds(new ArrayList<>(sopRefSops));
             if("1".equals(saveSopVo.getSop_status())) {
                 //将状态更新为3  publish_status
-                update.setPublishStatus("3");
+                SopState sopState = sopStateMachine.public2Draft();
+                setEditSopStatus(update,sopState);
             }
 
             if(sopEdit != null) {
@@ -430,10 +476,10 @@ public class GroupSopServiceImpl implements GroupSopService {
             //插入编辑状态sop
             this.insertRecord(data);
         }
-        //根据sopid 更新sop的状态为3
         Sop sop = new Sop();
         sop.setSopId(saveSopVo.getSop_id());
-        sop.setPublishStatus("3");
+        SopState sopState = sopStateMachine.public2Draft();
+        setSopStatus(sop,sopState);
         return sop.updateById();
     }
 
@@ -448,7 +494,7 @@ public class GroupSopServiceImpl implements GroupSopService {
             flag = false;
         }
         //1.根据update和项目id查询
-        List<Sop> sops = queryPublishedSopsByProjectIdAndUpdatetime(sopListForSelVo, projectId);
+        List<Sop> sops = queryPublishedSopsByProjectIdAndUpdatetime(sopListForSelVo);
         //2筛选sop
 
         /*
@@ -498,6 +544,253 @@ public class GroupSopServiceImpl implements GroupSopService {
         return item;
     }
 
+    @Override
+    public boolean publishSop(SaveSopVo saveSopVo) throws Exception {
+        //验证必填项
+        //根据id查询sop
+        String sop_id = saveSopVo.getSop_id();
+        Sop querySop = new Sop();
+        Sop oldSop = querySop.selectById(sop_id);
+
+        //转化为his sop  并填充必要的参数
+        SopHis sopHis = new SopHis();
+
+        org.springframework.beans.BeanUtils.copyProperties(oldSop, sopHis);
+        //获取sop的版本信息
+        Integer versionCount = oldSop.getVersionCount();
+        Map<String, SopHis.RefedSopBean> stringProfileMap = proccessSopIdRefProfile(oldSop.getRefSopIds());
+        //在每一步上追加该信息
+        proccessSopItem(sopHis, stringProfileMap, null);
+        //在refed中添加信息
+        sopHis.setRefedSops(getSopProfileOfRefCurrentSop(sopHis.getSopId()));
+
+        //将历史版本落库
+        sopHisService.save(sopHis);
+
+        //删除草稿
+        sopEditService.removeById(saveSopVo.getSop_id());
+
+
+        //更新sop
+        Sop sop = SopMapper.INSTANCE.SaveSopVoToSop(saveSopVo);
+
+        Set<String> sopRefSops = this.getSopRefSops(saveSopVo);
+
+        sop.setRefSopIds(new ArrayList<>(sopRefSops));
+
+        //首先更新相关的对象关系表
+        updateSopRelation(saveSopVo);
+
+        sop.setVersionExplain("[\"修订标准操作\"]");
+
+        return updateRecordByKeyAndUpVersion(sop);
+    }
+
+
+    public boolean updateRecordByKeyAndUpVersion(Sop sopUpdate) throws Exception {
+        Sop sop = new Sop();
+        Sop sop1 = sop.selectById(sop.getSopId());
+        Integer versionCount1 = sop1.getVersionCount();
+        int count = versionCount1 + 1;
+        sopUpdate.setVersion("V" + (double) count / 10);
+        sopUpdate.setVersionCount(count);
+        sopUpdate.updateById();
+        return true;
+    }
+
+
+
+
+
+    private boolean updateSopRelation(SaveSopVo saveSopVo) throws Exception{
+
+        //添加sop与对象关系-sop_obj_rel
+        List<SaveSopVo.FitObjsBean> sopRelObjs = getSopRelObjs(saveSopVo);
+
+        //查询数据库中的关联信息
+        //删除所有
+        sopObjRelService.deleteBySopId(saveSopVo.getSop_id());
+        if(CollectionUtils.isNotEmpty(sopRelObjs)) {
+            for (SaveSopVo.FitObjsBean sopRelObj : sopRelObjs) {
+                SopObjRel sopObjRel = new SopObjRel();
+                sopObjRel.setSopId(saveSopVo.getSop_id());
+                sopObjRel.setObjId(sopRelObj.getObj_id());
+                sopObjRel.setObjType(sopRelObj.getObj_type());
+                sopObjRel.setValid(true);
+
+                sopObjRel.insert();
+            }
+        }
+
+        sopEquipModelRelService.deleteBySopId(saveSopVo.getSop_id());
+
+
+        //添加sop与设备型号关系-sop_equip_model_rel
+        List<String> equip_model_ids = saveSopVo.getEquip_model_ids();
+        distinctCollection(equip_model_ids);
+        if(CollectionUtils.isNotEmpty(equip_model_ids)) {
+            for (String equip_model_id : equip_model_ids) {
+                SopEquipModelRel sopEquipModelRel = new SopEquipModelRel();
+                sopEquipModelRel.setEquipModelId(equip_model_id);
+                sopEquipModelRel.setSopId(saveSopVo.getSop_id());
+                sopEquipModelRel.setValid(true);
+                sopEquipModelRel.insert();
+            }
+        }
+
+        //删除所有
+
+        sopOrderTypeRelService.deleteBySopId(saveSopVo.getSop_id());
+
+
+        //添加sop与工单类型关系-sop_order_type_rel
+        List<String> order_types = saveSopVo.getOrder_type();
+        distinctCollection(order_types);
+        if(CollectionUtils.isNotEmpty(order_types)) {
+            for (String order_type : order_types) {
+                SopOrderTypeRel sopOrderTypeRel = new SopOrderTypeRel();
+                sopOrderTypeRel.setOrderType(order_type);
+                sopOrderTypeRel.setProjectId(saveSopVo.getProject_id());
+                sopOrderTypeRel.setValid(true);
+                sopOrderTypeRel.setSopId(saveSopVo.getSop_id());
+                sopOrderTypeRel.insert();
+            }
+        }
+        //添加sop与自定义标签关系-sop_label_rel
+
+
+        sopLabelRelService.deleteBySopId(saveSopVo.getSop_id());
+        List<String> labels = saveSopVo.getLabels();
+        distinctCollection(labels);
+        if(CollectionUtils.isNotEmpty(labels)) {
+            for (String label : labels) {
+                SopLabelRel sopLabelRel = new SopLabelRel();
+                sopLabelRel.setLabel(label);
+                sopLabelRel.setSopId(saveSopVo.getSop_id());
+                sopLabelRel.setValid(true);
+                sopLabelRel.insert();
+            }
+        }
+
+
+
+        sopSopRelService.deleteBySopId(saveSopVo.getSop_id());
+        //添加sop与sop关系-sop_sop_rel
+        Set<String> sopRefSops = getSopRefSops(saveSopVo);
+        if(CollectionUtils.isNotEmpty(sopRefSops)) {
+            for (String sopRefSop : sopRefSops) {
+                SopSopRel sopSopRel = new SopSopRel();
+                sopSopRel.setProjectId(saveSopVo.getProject_id());
+                sopSopRel.setRelSopId(sopRefSop);
+                sopSopRel.setSopId(saveSopVo.getSop_id());
+                sopSopRel.setValid(true);
+            }
+        }
+
+        return true;
+
+    }
+
+
+
+
+    /**
+     * 处理引用当前sop的所有sop简介
+     * @param sopId
+     * @param sopId
+     * @return
+     * @throws Exception
+     */
+    public  List< SopHis.RefedSopBean>  getSopProfileOfRefCurrentSop( String sopId) throws Exception{
+        //查询引用该sop的sopid
+        QueryWrapper<SopSopRel> sopSopRelQueryWrapper = new QueryWrapper<>();
+        sopSopRelQueryWrapper.eq("rel_sop_id",sopId);
+        List<SopSopRel> list = sopSopRelService.list(sopSopRelQueryWrapper);
+        List<String> refSopIds = new ArrayList<String>();
+        for (SopSopRel sopSopRel : list) {
+            refSopIds.add(sopSopRel.getSopId());
+        }
+
+        return  new ArrayList<>(proccessSopIdRefProfile(refSopIds).values());
+    }
+
+
+
+    /**
+     * 处理sop详情 补充引用sop简介,添加内容对象变化标识
+     * @param sop
+     * @param refSopProfile
+     * @Param changedObjIds     objId //对象变化数据key:objId value:{"objId":objId, "objName":objName, "objType":objType}
+     * @return
+     */
+    public void proccessSopItem(SopHis sop, Map<String, SopHis.RefedSopBean> refSopProfile, Set<String> changedObjIds){
+        if(CollectionUtils.isNotEmpty(changedObjIds)) {
+            List<SopHis.FitObjsBean> fitObjs = sop.getFitObjs();
+            if(CollectionUtils.isNotEmpty(fitObjs)) {
+                for (SopHis.FitObjsBean fitObj : fitObjs) {
+                    String obj_id = fitObj.getObj_id();
+                    if(changedObjIds.contains(obj_id)) {
+                        fitObj.setIs_revise(true);
+                    }
+                }
+            }
+            //處理步驟
+            List<SopStepsBean> steps = sop.getSteps();
+            for (SopStepsBean step : steps) {
+                Boolean from_sop = step.isFrom_sop();
+                if(BooleanUtils.isTrue(from_sop)) {
+                    //将引用的简洁填充上去
+                    String sop_id = step.getSop_id();
+                    SopHis.RefedSopBean profile = refSopProfile.get(sop_id);
+                    if(profile != null) {
+                        step.setProfile(profile);
+                    }
+                }else {
+                    List<SopStepsBean.StepContentBean> step_content = step.getStep_content();
+                    if(CollectionUtils.isNotEmpty(step_content)) {
+                        for (SopStepsBean.StepContentBean stepContentBean : step_content) {
+                            Boolean from_sop1 = stepContentBean.isFrom_sop();
+                            if(BooleanUtils.isTrue(from_sop1)) {
+                                String sop_id = stepContentBean.getSop_id();
+                                SopHis.RefedSopBean profile = refSopProfile.get(sop_id);
+                                if(profile != null) {
+                                    stepContentBean.setProfile(profile);
+                                }
+                            }
+                        }
+                    }
+                }
+            }
+        }
+
+    }
+
+    /**
+     * 处理引用的sop id与简介(sop_name,version,step_count,status_explain,update_time)
+     * @Param userId        调用者
+     * @param refSopIds    被引用sopId集合
+     * @return map      key:sopId  value:sop对象
+     * @throws Exception
+     */
+    public Map<String, SopHis.RefedSopBean> proccessSopIdRefProfile(List<String> refSopIds) throws Exception {
+        List<Sop> sops = sopService.listByIds(refSopIds);
+        Map<String, SopHis.RefedSopBean> sopId_Profile = new HashMap<>();
+        for (Sop sopItem : sops) {
+            SopHis.RefedSopBean profile = new SopHis.RefedSopBean();
+            profile.setRef_sop_id(sopItem.getSopId());
+            profile.setRef_sop_name(sopItem.getSopName());
+            profile.setVersion(sopItem.getVersion());
+            profile.setStep_count(sopItem.getSteps().size());
+            profile.setStauts_explain(getSopStatus(sopItem));
+            profile.setUpdate_time(DateUtil.transferDateFormat(sopItem.getUpdateTime(), CommonConst.date_format_save, CommonConst.date_format_show));
+            sopId_Profile.put(sopItem.getSopId(), profile);
+        }
+        return sopId_Profile;
+    }
+
+
+
+
 
     private Map<String, Object> getSopListCriteria(List<Sop> sops, List<SopInfoVo> sopInfoVos) throws Exception {
         //根据业务数据抽取条件
@@ -515,6 +808,8 @@ public class GroupSopServiceImpl implements GroupSopService {
         return criteria;
     }
 
+
+
     private List<Sop> filterSopByFitScope(QuerySopListForSelVo sopListForSelVo, List<Sop> sops) throws Exception {
         JSONObject param = JSONObject.parseObject(JSONObject.toJSONString(sopListForSelVo));
 
@@ -532,10 +827,8 @@ public class GroupSopServiceImpl implements GroupSopService {
             //1.根据适用返回查询sopid
             //1.1根据设备型号查询
             if(!StringUtil.isEmptyList(param, "equip_model_ids")){
-                QueryWrapper<SopEquipModelRel> sopEquipModelRelQueryWrapper = new QueryWrapper<>();
-                sopEquipModelRelQueryWrapper.in("equip_model_id",sopListForSelVo.getEquip_model_ids());
-                List<SopEquipModelRel> list = sopEquipModelRelService.list(sopEquipModelRelQueryWrapper);
 
+                List<SopEquipModelRel> list = sopEquipModelRelService.selectByEquipModelIds(sopListForSelVo.getEquip_model_ids());
                 Set<String> tmp = new HashSet<>();
                 for (SopEquipModelRel sopEquipModelRel : list) {
                     tmp.add(sopEquipModelRel.getSopId());
@@ -544,9 +837,7 @@ public class GroupSopServiceImpl implements GroupSopService {
             }
             //1.2根据自定义标签查询
             if( !StringUtil.isEmptyList(param, "labels")){
-                QueryWrapper<SopLabelRel> query = new QueryWrapper<>();
-                query.in("label",sopListForSelVo.getLabels());
-                List<SopLabelRel> list = sopLabelRelService.list(query);
+                List<SopLabelRel> list = sopLabelRelService.selectByLabels(sopListForSelVo.getLabels());
                 Set<String> tmp = new HashSet<>();
                 for (SopLabelRel sopLabelRel : list) {
                     tmp.add(sopLabelRel.getSopId());
@@ -555,22 +846,18 @@ public class GroupSopServiceImpl implements GroupSopService {
             }
             //1.3根据工单类型查询
             if(!StringUtil.isEmptyList(param, "order_type")){
-                QueryWrapper<SopOrderTypeRel> query = new QueryWrapper<>();
-                query.in("order_type",sopListForSelVo.getOrder_type());
-                List<SopOrderTypeRel> list = sopOrderTypeRelService.list(query);
+                List<SopOrderTypeRel> sopOrderTypeRels = sopOrderTypeRelService.selectByOrderTypes(sopListForSelVo.getOrder_type());
                 Set<String> tmp = new HashSet<>();
-                for (SopOrderTypeRel sopOrderTypeRel : list) {
+                for (SopOrderTypeRel sopOrderTypeRel : sopOrderTypeRels) {
                     tmp.add(sopOrderTypeRel.getSopId());
                 }
                 sopId.retainAll(tmp);
             }
             //1.4根据适用对象查询
             if( !StringUtil.isEmptyList(param, "fit_obj_ids")){
-                QueryWrapper<SopObjRel> query = new QueryWrapper<>();
-                query.in("obj_id",sopListForSelVo.getFit_obj_ids());
-                List<SopObjRel> list = sopObjRelService.list(query);
+                List<SopObjRel> sopObjRels = sopObjRelService.selectByObjectIds(sopListForSelVo.getFit_obj_ids());
                 Set<String> tmp = new HashSet<>();
-                for (SopObjRel sopObjRel : list) {
+                for (SopObjRel sopObjRel : sopObjRels) {
                     tmp.add(sopObjRel.getSopId());
                 }
                 sopId.retainAll(tmp);
@@ -722,6 +1009,116 @@ public class GroupSopServiceImpl implements GroupSopService {
     }
 
 
+    @Override
+    public JSONObject queryEditingSopList(QueryHistoryListVo queryHistoryListVo) throws Exception {
+        String sop_name = queryHistoryListVo.getSop_name();
+
+        //根据sop_status  valid  projectid  查询
+        QueryWrapper<SopEdit> query = new QueryWrapper<>();
+        query.eq("sop_status", SopConst.SOP_STATUS_DRAFT)
+                .eq("project_id",queryHistoryListVo.getProjectId())
+                .like("sop_name",sop_name)
+                .orderByDesc(DBConst.TABLE_FIELD_UPDATE_TIME);
+
+        List<SopEdit> list = sopEditService.list(query);
+        List<SopDTO> sopDTOS = new ArrayList<>();
+        //转化为业务数据
+        for (SopEdit sopEdit : list) {
+            SopDTO sopDTO = new SopDTO();
+            BeanUtils.copyProperties(sopEdit,sopDTO);
+            sopDTOS.add(sopDTO);
+        }
+
+        return this.filterRemind(sopDTOS, false);
+    }
+
+    @Override
+    public JSONObject queryDestroyedSopList(QueryHistoryListVo queryHistoryListVo) throws Exception {
+
+        String sop_name = queryHistoryListVo.getSop_name();
+
+        //根据sop_status  valid  projectid  查询
+        QueryWrapper<Sop> query = new QueryWrapper<>();
+        query.eq("sop_status", SopConst.SOP_STATUS_DESTROYED)
+                .eq("project_id",queryHistoryListVo.getProjectId())
+                .like("sop_name",sop_name)
+                .orderByDesc(DBConst.TABLE_FIELD_UPDATE_TIME);
+
+        List<Sop> list = sopService.list(query);
+        return  this.filterRemind((List)list, true);
+    }
+
+    /**
+     *
+     * Description: 条件过滤
+     * @param sops
+     * @param destoryFlag
+     * @return
+     * @throws Exception JSONObject
+     * @author yuecaipu
+     * @since 2018年5月2日: 下午2:11:59
+     * Update By yuecaipu 2018年5月2日: 下午2:11:59
+     */
+    public JSONObject filterRemind(List<SopDTO> sops, boolean destoryFlag) throws Exception {
+        JSONObject sopJson = new JSONObject();
+        JSONArray editSopArray = new JSONArray();
+        for (SopDTO sop : sops) {
+            JSONArray scopes = new JSONArray();
+
+            List<String> orderTypes = sop.getOrderType();
+
+            for (String orderType : orderTypes) {
+                String dictName ="tset";//= woFlowPlanService.getNameById(orderType);
+                //String dictName = DictionaryCache.getNameByTypeCode(DBConst.DICT_WORK_ORDER_TYPE, tempArray.getString(j), projectId);
+                if(dictName != null)
+                    scopes.add(dictName);
+            }
+
+            List<Sop.FitObjsBean> fitObjs = sop.getFitObjs();
+            for (Sop.FitObjsBean fitObj : fitObjs) {
+                scopes.add(fitObj.getObj_id());
+            }
+
+            JSONObject param = new JSONObject();
+            param.put("equip_model_ids", sop.getEquipModelIds());
+
+            String resultStr = equipModelService.queryBathchMergeRecordByequipModelIds(param.toJSONString(), "equip_model_ids", "equip_model_id");
+            JSONObject resultObj = JSONObject.parseObject(resultStr);
+            JSONArray resultContent = resultObj.getJSONArray(DBConst.Result.CONTENT);
+            if (Result.SUCCESS.equals(resultObj.getString(Result.RESULT)) && resultContent.size()>0) {
+                for (int j = 0; j < resultContent.size(); j++) {
+                    JSONObject content = resultContent.getJSONObject(j);
+                    scopes.add(content.getString("equip_model_name"));
+                }
+            }
+            List<String> labels = sop.getLabels();
+            if(labels != null) {
+                scopes.addAll(labels);
+            }
+
+            JSONObject editSop = new JSONObject();
+            editSop.put("sop_id", sop.getProjectId());
+            editSop.put("sop_name", sop.getSopName());
+            editSop.put("version", sop.getVersion());
+            if(!destoryFlag) {
+                editSop.put("sop_status", sop.getSopStatus());
+            }
+            editSop.put("scopes", scopes);
+            editSop.put("update_time", DateUtil.transferDateFormat(sop.getUpdateTime(), CommonConst.date_format_save, CommonConst.date_format_show));
+            editSop.put("operator",sop.getOperator());
+            editSopArray.add(editSop);
+        }
+        sopJson.put("Content", editSopArray);
+        sopJson.put("Count", editSopArray.size());
+        return sopJson;
+    }
+
+    @Override
+    public String queryDestroyedSopList(JSONObject jsonObject) throws Exception {
+        return null;
+    }
+
+
     /**
      *
      * Description: 获取到sop中所有设备型号
@@ -880,9 +1277,7 @@ public class GroupSopServiceImpl implements GroupSopService {
         if(CollectionUtils.isEmpty(signCodes)) {
             return sops;
         }
-//		if (signCodes.size() > 1) {
-//			return sops;
-//		}
+
         if (signCodes.contains("public")) {
             for (Sop object : sops) {
                 if (SopConst.SOP_TYPE_GROUP.equals(object.getSopType())) {
@@ -906,6 +1301,7 @@ public class GroupSopServiceImpl implements GroupSopService {
                 }
             }
         }
+
         return resultSops;
     }
 
@@ -913,6 +1309,7 @@ public class GroupSopServiceImpl implements GroupSopService {
 
 
     public boolean isContainsClassObj(Sop sop) throws Exception {
+
         List<SopStepsBean> steps = sop.getSteps();
         for (SopStepsBean step : steps) {
             Boolean from_sop = step.isFrom_sop();
@@ -1005,7 +1402,7 @@ public class GroupSopServiceImpl implements GroupSopService {
 
 
 
-    private List<Sop> queryPublishedSopsByProjectIdAndUpdatetime(QuerySopListForSelVo sopListForSelVo,String projectId) throws Exception {
+    private List<Sop> queryPublishedSopsByProjectIdAndUpdatetime(QuerySopListForSelVo sopListForSelVo) throws Exception {
         String sop_name = sopListForSelVo.getSop_name();
         /*
         //如果项目id 不是集团特有的id的话进入
@@ -1015,22 +1412,19 @@ public class GroupSopServiceImpl implements GroupSopService {
 				//设置为group_sop_id
 				projectIds.add(CommonConst.group_sop_id);
 			}
-		}
-
-         */
-        //查询条件为 projectIds valid sop_status SOP_STATUS_PUBLISH,
-        // 大于等于  小于等于   不包含待修订
+		}*/
 
         QueryWrapper<Sop> query = new QueryWrapper();
-        query.eq("project_id",projectId)
+        query.eq("project_id",sopListForSelVo.getProjectId())
                 .eq("valid",true)
                 .eq("sop_status", SopConst.SOP_STATUS_PUBLISH)
                 .ge("update_time",sopListForSelVo.getUpdate_time_from())
                 .le("update_time",sopListForSelVo.getUpdate_time_to())
-                .ne("publish_status",SopConst.PUBLISH_STATUS_REVISE)
+                //.ne("publish_status",SopConst.PUBLISH_STATUS_REVISE)
                 .like("sop_name",sop_name).orderByDesc("update_time");
 
 
+
         return  sopService.list(query);
     }
 

+ 21 - 2
fm-sop/src/main/java/com/persagy/fm/sop/service/impl/SopEquipModelRelServiceImpl.java

@@ -1,11 +1,14 @@
 package com.persagy.fm.sop.service.impl;
 
-import com.persagy.fm.sop.model.dto.SopEquipModelRel;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.persagy.fm.sop.dao.SopEquipModelRelMapper;
+import com.persagy.fm.sop.model.dto.SopEquipModelRel;
 import com.persagy.fm.sop.service.SopEquipModelRelService;
-import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import org.springframework.stereotype.Service;
 
+import java.util.List;
+
 /**
  * <p>
  *  服务实现类
@@ -17,4 +20,20 @@ import org.springframework.stereotype.Service;
 @Service
 public class SopEquipModelRelServiceImpl extends ServiceImpl<SopEquipModelRelMapper, SopEquipModelRel> implements SopEquipModelRelService {
 
+    @Override
+    public boolean deleteBySopId(String sopId) {
+        //删除所有
+        SopEquipModelRel sopEquipModelRel = new SopEquipModelRel();
+        QueryWrapper<SopEquipModelRel> SopEquipModelRelQuery = new QueryWrapper<SopEquipModelRel>();
+        SopEquipModelRelQuery.eq("sop_id",sopId);
+        return sopEquipModelRel.delete(SopEquipModelRelQuery);
+    }
+
+
+    public List<SopEquipModelRel> selectByEquipModelIds(List<String> equip_model_ids) {
+        QueryWrapper<SopEquipModelRel> sopEquipModelRelQueryWrapper = new QueryWrapper<>();
+        sopEquipModelRelQueryWrapper.in("equip_model_id",equip_model_ids);
+        List<SopEquipModelRel> list = this.list(sopEquipModelRelQueryWrapper);
+        return list;
+    }
 }

+ 18 - 2
fm-sop/src/main/java/com/persagy/fm/sop/service/impl/SopLabelRelServiceImpl.java

@@ -1,11 +1,14 @@
 package com.persagy.fm.sop.service.impl;
 
-import com.persagy.fm.sop.model.dto.SopLabelRel;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.persagy.fm.sop.dao.SopLabelRelMapper;
+import com.persagy.fm.sop.model.dto.SopLabelRel;
 import com.persagy.fm.sop.service.SopLabelRelService;
-import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import org.springframework.stereotype.Service;
 
+import java.util.List;
+
 /**
  * <p>
  *  服务实现类
@@ -17,4 +20,17 @@ import org.springframework.stereotype.Service;
 @Service
 public class SopLabelRelServiceImpl extends ServiceImpl<SopLabelRelMapper, SopLabelRel> implements SopLabelRelService {
 
+    @Override
+    public boolean deleteBySopId(String sopId) {
+        SopLabelRel  sopLabelRel = new SopLabelRel();
+        QueryWrapper<SopLabelRel> sopLabelRelQueryWrapper = new QueryWrapper<SopLabelRel>();
+        sopLabelRelQueryWrapper.eq("sop_id",sopId);
+        return sopLabelRel.delete(sopLabelRelQueryWrapper);
+    }
+
+    public List<SopLabelRel> selectByLabels(List<String> labels) {
+        QueryWrapper<SopLabelRel> query = new QueryWrapper<>();
+        query.in("label",labels);
+        return  this.list(query);
+    }
 }

+ 18 - 2
fm-sop/src/main/java/com/persagy/fm/sop/service/impl/SopObjRelServiceImpl.java

@@ -1,11 +1,14 @@
 package com.persagy.fm.sop.service.impl;
 
-import com.persagy.fm.sop.model.dto.SopObjRel;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.persagy.fm.sop.dao.SopObjRelMapper;
+import com.persagy.fm.sop.model.dto.SopObjRel;
 import com.persagy.fm.sop.service.SopObjRelService;
-import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import org.springframework.stereotype.Service;
 
+import java.util.List;
+
 /**
  * <p>
  *  服务实现类
@@ -17,4 +20,17 @@ import org.springframework.stereotype.Service;
 @Service
 public class SopObjRelServiceImpl extends ServiceImpl<SopObjRelMapper, SopObjRel> implements SopObjRelService {
 
+    public boolean deleteBySopId(String sopId) {
+        SopObjRel sopObjRel = new SopObjRel();
+        QueryWrapper<SopObjRel> query = new QueryWrapper<SopObjRel>();
+        query.eq("sop_id",sopId);
+        return sopObjRel.delete(query);
+    }
+    public List<SopObjRel> selectByObjectIds(List<String> objectIds) {
+        QueryWrapper<SopObjRel> query = new QueryWrapper<>();
+        query.in("obj_id",objectIds);
+        return this.list(query);
+    }
+
+
 }

+ 19 - 2
fm-sop/src/main/java/com/persagy/fm/sop/service/impl/SopOrderTypeRelServiceImpl.java

@@ -1,11 +1,14 @@
 package com.persagy.fm.sop.service.impl;
 
-import com.persagy.fm.sop.model.dto.SopOrderTypeRel;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.persagy.fm.sop.dao.SopOrderTypeRelMapper;
+import com.persagy.fm.sop.model.dto.SopOrderTypeRel;
 import com.persagy.fm.sop.service.SopOrderTypeRelService;
-import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import org.springframework.stereotype.Service;
 
+import java.util.List;
+
 /**
  * <p>
  *  服务实现类
@@ -17,4 +20,18 @@ import org.springframework.stereotype.Service;
 @Service
 public class SopOrderTypeRelServiceImpl extends ServiceImpl<SopOrderTypeRelMapper, SopOrderTypeRel> implements SopOrderTypeRelService {
 
+    @Override
+    public boolean deleteBySopId(String sopId) {
+        SopOrderTypeRel  sopOrderTypeRel = new SopOrderTypeRel();
+        QueryWrapper<SopOrderTypeRel> sopOrderTypeRelQueryWrapper = new QueryWrapper<SopOrderTypeRel>();
+        sopOrderTypeRelQueryWrapper.eq("sop_id",sopId);
+        return sopOrderTypeRel.delete(sopOrderTypeRelQueryWrapper);
+    }
+
+
+    public List<SopOrderTypeRel> selectByOrderTypes(List<String> orderTypes)  {
+        QueryWrapper<SopOrderTypeRel> query = new QueryWrapper<>();
+        query.in("order_type",orderTypes);
+        return this.list(query);
+    }
 }

+ 10 - 2
fm-sop/src/main/java/com/persagy/fm/sop/service/impl/SopSopRelServiceImpl.java

@@ -1,9 +1,10 @@
 package com.persagy.fm.sop.service.impl;
 
-import com.persagy.fm.sop.model.dto.SopSopRel;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.persagy.fm.sop.dao.SopSopRelMapper;
+import com.persagy.fm.sop.model.dto.SopSopRel;
 import com.persagy.fm.sop.service.SopSopRelService;
-import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import org.springframework.stereotype.Service;
 
 /**
@@ -17,4 +18,11 @@ import org.springframework.stereotype.Service;
 @Service
 public class SopSopRelServiceImpl extends ServiceImpl<SopSopRelMapper, SopSopRel> implements SopSopRelService {
 
+    @Override
+    public boolean deleteBySopId(String sopId) {
+        SopSopRel  sopSopRel = new SopSopRel();
+        QueryWrapper<SopSopRel> sopSopRelQueryWrapper = new QueryWrapper<SopSopRel>();
+        sopSopRelQueryWrapper.eq("sop_id",sopId);
+        return sopSopRel.delete(sopSopRelQueryWrapper);
+    }
 }

+ 24 - 0
fm-sop/src/main/java/com/persagy/old/service/WoFlowPlanServiceI.java

@@ -0,0 +1,24 @@
+package com.persagy.old.service;
+
+import com.alibaba.fastjson.JSONObject;
+
+/**
+ * 
+ * Description:   工单流转计划
+ * Company: Persagy 
+ * @author yuecaipu 
+ * @version 1.0
+ * @since: 2018年5月22日: 下午2:41:19
+ * Update By yuecaipu 2018年5月22日: 下午2:41:19
+ */
+public interface WoFlowPlanServiceI {
+
+	/*
+	 * 根据id获取name
+	 */
+	String getNameById(String id);
+
+	String autoInstantiateWoMatters(JSONObject jsonObject) throws Exception;
+	
+	
+}

File diff suppressed because it is too large
+ 1350 - 0
fm-sop/src/main/java/com/persagy/old/service/impl/WoFlowPlanServiceImpl2.java