weijinhao 3 年 前
コミット
2ffbc00009

+ 6 - 0
fm-sop/pom.xml

@@ -60,6 +60,12 @@
         </dependency>
 
         <dependency>
+            <groupId>com.google.code.gson</groupId>
+            <artifactId>gson</artifactId>
+            <version>2.8.6</version>
+        </dependency>
+
+        <dependency>
             <groupId>org.apache.hbase</groupId>
             <artifactId>hbase-server</artifactId>
             <version>${hbase.version}</version>

+ 25 - 0
fm-sop/src/main/java/com/persagy/fm/sop/config/MpJsonConfig.java

@@ -0,0 +1,25 @@
+package com.persagy.fm.sop.config;
+
+import com.baomidou.mybatisplus.extension.handlers.GsonTypeHandler;
+import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.google.gson.Gson;
+import org.springframework.boot.CommandLineRunner;
+import org.springframework.stereotype.Component;
+
+/**
+ * @author miemie
+ * @since 2019-11-28
+ */
+@Component
+public class MpJsonConfig implements CommandLineRunner {
+
+    /**
+     * 可以set进去自己的
+     */
+    @Override
+    public void run(String... args) throws Exception {
+        JacksonTypeHandler.setObjectMapper(new ObjectMapper());
+        GsonTypeHandler.setGson(new Gson());
+    }
+}

+ 24 - 1
fm-sop/src/main/java/com/persagy/fm/sop/controller/GroupSopController.java

@@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSONObject;
 import com.persagy.fm.common.response.FmResponseMsg;
 import com.persagy.fm.common.response.FmResponseUtil;
 import com.persagy.fm.sop.model.dto.RefSopInfo;
+import com.persagy.fm.sop.model.dto.Sop;
 import com.persagy.fm.sop.model.vo.*;
 import com.persagy.fm.sop.service.GroupSopService;
 import com.persagy.fm.sop.service.SopEditService;
@@ -204,4 +205,26 @@ public class GroupSopController {
         return ToolsUtil.successJsonMsg("发布成功");
     }
 
-}
+
+    @PostMapping("/destroySopById")
+    public boolean  destroySopById(@RequestBody DestorySopVo destorySopVo) throws Exception{
+        return groupSopService.destroySopById(destorySopVo);
+    }
+
+
+
+
+
+    /**
+     * 根据Id查询已发布的sop信息
+     * @param querySopVo
+     * @return
+     * @throws Exception
+     */
+    @PostMapping("/queryPublishedSopById")
+    public Sop queryPublishedSopById(@RequestBody QuerySopVo querySopVo) throws Exception{
+        String sopId = querySopVo.getSopId();
+        Sop sop = groupSopService.queryPublishedSopById(sopId);
+        return sop;
+    }
+}

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

@@ -11,7 +11,7 @@
         <result column="sop_name" property="sopName" />
         <result column="sop_type" property="sopType" />
         <result column="no_obj" property="noObj" />
-        <result column="domains" property="domains" typeHandler="com.baomidou.mybatisplus.extension.handlers.FastjsonTypeHandler"/>
+        <result column="domains" property="domains"  typeHandler="com.baomidou.mybatisplus.extension.handlers.FastjsonTypeHandler"/>
         <result column="order_type" property="orderType" typeHandler="com.baomidou.mybatisplus.extension.handlers.FastjsonTypeHandler"/>
         <result column="tools" property="tools" typeHandler="com.baomidou.mybatisplus.extension.handlers.FastjsonTypeHandler"/>
         <result column="fit_objs" property="fitObjs" typeHandler="com.baomidou.mybatisplus.extension.handlers.FastjsonTypeHandler"/>
@@ -36,5 +36,4 @@
         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>

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

@@ -1,9 +1,9 @@
 package com.persagy.fm.sop.mapper;
 
 import com.persagy.fm.sop.model.dto.Profile;
+import com.persagy.fm.sop.model.dto.RefedSopBean;
 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;
@@ -106,7 +106,7 @@ public interface SopMapper {
     @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);
+    RefedSopBean profileToRefedSopBean(Profile profile);
 
 
 

+ 77 - 0
fm-sop/src/main/java/com/persagy/fm/sop/model/dto/FitObjsBean.java

@@ -0,0 +1,77 @@
+package com.persagy.fm.sop.model.dto;
+
+import javax.validation.constraints.NotEmpty;
+import javax.validation.constraints.NotNull;
+
+public class FitObjsBean {
+    /**
+     * obj_id : ***
+     * obj_name : 对象名称1
+     * obj_code : XXX
+     * obj_type : system
+     * obj_source : content_obj
+     */
+    //"obj_id", "obj_name", "obj_type"
+    @NotEmpty
+    @NotNull
+    private String obj_id;
+    @NotEmpty
+    @NotNull
+    private String obj_name;
+    @NotEmpty
+    @NotNull
+    private String obj_type;
+    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;
+    }
+
+    public void setObj_id(String obj_id) {
+        this.obj_id = obj_id;
+    }
+
+    public String getObj_name() {
+        return obj_name;
+    }
+
+    public void setObj_name(String obj_name) {
+        this.obj_name = obj_name;
+    }
+
+    public String getObj_code() {
+        return obj_code;
+    }
+
+    public void setObj_code(String obj_code) {
+        this.obj_code = obj_code;
+    }
+
+    public String getObj_type() {
+        return obj_type;
+    }
+
+    public void setObj_type(String obj_type) {
+        this.obj_type = obj_type;
+    }
+
+    public String getObj_source() {
+        return obj_source;
+    }
+
+    public void setObj_source(String obj_source) {
+        this.obj_source = obj_source;
+    }
+}

+ 69 - 0
fm-sop/src/main/java/com/persagy/fm/sop/model/dto/RefedSopBean.java

@@ -0,0 +1,69 @@
+package com.persagy.fm.sop.model.dto;
+
+public class RefedSopBean {
+
+
+    /**
+     * ref_sop_id : ***
+     * ref_sop_name : ***
+     * version : V0.3
+     * stauts_explain : 已发布,修订中
+     * update_time : 20170620093000
+     */
+
+    private String ref_sop_id;
+    private String ref_sop_name;
+    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;
+    }
+
+    public void setRef_sop_id(String ref_sop_id) {
+        this.ref_sop_id = ref_sop_id;
+    }
+
+    public String getRef_sop_name() {
+        return ref_sop_name;
+    }
+
+    public void setRef_sop_name(String ref_sop_name) {
+        this.ref_sop_name = ref_sop_name;
+    }
+
+    public String getVersion() {
+        return version;
+    }
+
+    public void setVersion(String version) {
+        this.version = version;
+    }
+
+    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;
+    }
+
+}

+ 14 - 9
fm-sop/src/main/java/com/persagy/fm/sop/model/dto/Sop.java

@@ -3,8 +3,10 @@ package com.persagy.fm.sop.model.dto;
 import com.baomidou.mybatisplus.annotation.IdType;
 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.FastjsonTypeHandler;
+import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
 
 import javax.validation.Valid;
 import javax.validation.constraints.NotEmpty;
@@ -15,35 +17,38 @@ import java.util.List;
  * sop表 落库协议
  * v1.0
  */
+
+@TableName(autoResultMap = true)
 public class Sop extends Model<Sop> {
     @TableId(value = "sop_id", type = IdType.ASSIGN_UUID)
     private String sopId;
 
     private String projectId;
     private String extendField;
-    @TableField(typeHandler = FastjsonTypeHandler.class)
+    @TableField(typeHandler = JacksonTypeHandler.class)
+
     private OperatorBean operator;
 
     private String sopName;
     private String sopType;
 
     private String noObj;
-    @TableField(typeHandler = FastjsonTypeHandler.class)
+    @TableField(typeHandler = JacksonTypeHandler.class)
     private List<String> domains;
-    @TableField(typeHandler = FastjsonTypeHandler.class)
+    @TableField(typeHandler = JacksonTypeHandler.class)
     private List<String> orderType;
-    @TableField(typeHandler = FastjsonTypeHandler.class)
+    @TableField(typeHandler = JacksonTypeHandler.class)
     private List<ToolsBean> tools;
-    @TableField(typeHandler = FastjsonTypeHandler.class)
+    @TableField(typeHandler = JacksonTypeHandler.class)
     private List<@Valid FitObjsBean> fitObjs;
-    @TableField(typeHandler = FastjsonTypeHandler.class)
+    @TableField(typeHandler = JacksonTypeHandler.class)
     private List<String> equipModelIds;
-    @TableField(typeHandler = FastjsonTypeHandler.class)
+    @TableField(typeHandler = JacksonTypeHandler.class)
     private List<String> labels;
     private String stepsVersion;
-    @TableField(typeHandler = FastjsonTypeHandler.class)
+    @TableField(typeHandler = JacksonTypeHandler.class)
     private List<SopStepsBean> steps;
-    @TableField(typeHandler = FastjsonTypeHandler.class)
+    @TableField(typeHandler = JacksonTypeHandler.class)
     private List<RelatedDataBean> relatedData;
 
     /**

+ 0 - 140
fm-sop/src/main/java/com/persagy/fm/sop/model/dto/SopHis.java

@@ -7,8 +7,6 @@ import com.baomidou.mybatisplus.extension.activerecord.Model;
 import com.baomidou.mybatisplus.extension.handlers.FastjsonTypeHandler;
 
 import javax.validation.Valid;
-import javax.validation.constraints.NotEmpty;
-import javax.validation.constraints.NotNull;
 import java.util.List;
 
 /**
@@ -351,79 +349,6 @@ public class SopHis extends Model<SopHis> {
         }
     }
 
-    public static class FitObjsBean {
-        /**
-         * obj_id : ***
-         * obj_name : 对象名称1
-         * obj_code : XXX
-         * obj_type : system
-         * obj_source : content_obj
-         */
-        //"obj_id", "obj_name", "obj_type"
-        @NotEmpty
-        @NotNull
-        private String obj_id;
-        @NotEmpty
-        @NotNull
-        private String obj_name;
-        @NotEmpty
-        @NotNull
-        private String obj_type;
-        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;
-        }
-
-        public void setObj_id(String obj_id) {
-            this.obj_id = obj_id;
-        }
-
-        public String getObj_name() {
-            return obj_name;
-        }
-
-        public void setObj_name(String obj_name) {
-            this.obj_name = obj_name;
-        }
-
-        public String getObj_code() {
-            return obj_code;
-        }
-
-        public void setObj_code(String obj_code) {
-            this.obj_code = obj_code;
-        }
-
-        public String getObj_type() {
-            return obj_type;
-        }
-
-        public void setObj_type(String obj_type) {
-            this.obj_type = obj_type;
-        }
-
-        public String getObj_source() {
-            return obj_source;
-        }
-
-        public void setObj_source(String obj_source) {
-            this.obj_source = obj_source;
-        }
-    }
-
     public static class RelatedDataBean {
         /**
          * name : ***
@@ -451,70 +376,5 @@ public class SopHis extends Model<SopHis> {
     }
 
 
-    public static class RefedSopBean {
-
 
-        /**
-         * ref_sop_id : ***
-         * ref_sop_name : ***
-         * version : V0.3
-         * stauts_explain : 已发布,修订中
-         * update_time : 20170620093000
-         */
-
-        private String ref_sop_id;
-        private String ref_sop_name;
-        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;
-        }
-
-        public void setRef_sop_id(String ref_sop_id) {
-            this.ref_sop_id = ref_sop_id;
-        }
-
-        public String getRef_sop_name() {
-            return ref_sop_name;
-        }
-
-        public void setRef_sop_name(String ref_sop_name) {
-            this.ref_sop_name = ref_sop_name;
-        }
-
-        public String getVersion() {
-            return version;
-        }
-
-        public void setVersion(String version) {
-            this.version = version;
-        }
-
-        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;
-        }
-    }
 }

+ 33 - 6
fm-sop/src/main/java/com/persagy/fm/sop/model/dto/SopStepsBean.java

@@ -20,13 +20,13 @@ public class SopStepsBean {
     private Boolean from_sop;
     private String sop_id;
     private List<@Valid StepContentBean> step_content;
-    private SopHis.RefedSopBean profile;
+    private RefedSopBean profile;
 
-    public SopHis.RefedSopBean getProfile() {
+    public RefedSopBean getProfile() {
         return profile;
     }
 
-    public void setProfile(SopHis.RefedSopBean profile) {
+    public void setProfile(RefedSopBean profile) {
         this.profile = profile;
     }
 
@@ -87,19 +87,29 @@ public class SopStepsBean {
         private List<String> obj_required_control;
         private List<String> obj_show_item;
         private List<@Valid ConfirmResultBean> confirm_result;
+        //专业的名称
+        private String domain_name;
 
-        private SopHis.RefedSopBean profile;
+        public String getDomain_name() {
+            return domain_name;
+        }
+
+        public void setDomain_name(String domain_name) {
+            this.domain_name = domain_name;
+        }
+
+        private RefedSopBean profile;
 
 
         public Boolean getFrom_sop() {
             return from_sop;
         }
 
-        public SopHis.RefedSopBean getProfile() {
+        public RefedSopBean getProfile() {
             return profile;
         }
 
-        public void setProfile(SopHis.RefedSopBean profile) {
+        public void setProfile(RefedSopBean profile) {
             this.profile = profile;
         }
 
@@ -218,8 +228,25 @@ public class SopStepsBean {
             @NotEmpty
             private String obj_type;
             private String obj_code;
+            private Boolean is_revise;
             private List<ParentsBean> parents;
 
+            public String getObj_code() {
+                return obj_code;
+            }
+
+            public void setObj_code(String obj_code) {
+                this.obj_code = obj_code;
+            }
+
+            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;
             }

+ 65 - 0
fm-sop/src/main/java/com/persagy/fm/sop/model/vo/DestorySopVo.java

@@ -0,0 +1,65 @@
+package com.persagy.fm.sop.model.vo;
+
+public class DestorySopVo {
+
+
+    /**
+     * user_id : ****
+     * sop_id : ****
+     * operator : {"id":"","name":""}
+     */
+
+    private String user_id;
+    private String sop_id;
+    private OperatorBean operator;
+
+    public String getUser_id() {
+        return user_id;
+    }
+
+    public void setUser_id(String user_id) {
+        this.user_id = user_id;
+    }
+
+    public String getSop_id() {
+        return sop_id;
+    }
+
+    public void setSop_id(String sop_id) {
+        this.sop_id = sop_id;
+    }
+
+    public OperatorBean getOperator() {
+        return operator;
+    }
+
+    public void setOperator(OperatorBean operator) {
+        this.operator = operator;
+    }
+
+    public static class OperatorBean {
+        /**
+         * id :
+         * name :
+         */
+
+        private String id;
+        private String name;
+
+        public String getId() {
+            return id;
+        }
+
+        public void setId(String id) {
+            this.id = id;
+        }
+
+        public String getName() {
+            return name;
+        }
+
+        public void setName(String name) {
+            this.name = name;
+        }
+    }
+}

+ 14 - 0
fm-sop/src/main/java/com/persagy/fm/sop/model/vo/QuerySopVo.java

@@ -0,0 +1,14 @@
+package com.persagy.fm.sop.model.vo;
+
+public class QuerySopVo {
+    private String sopId;
+
+
+    public String getSopId() {
+        return sopId;
+    }
+
+    public void setSopId(String sopId) {
+        this.sopId = sopId;
+    }
+}

+ 35 - 2
fm-sop/src/main/java/com/persagy/fm/sop/service/GroupSopService.java

@@ -2,11 +2,12 @@ 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.dto.*;
 import com.persagy.fm.sop.model.vo.*;
+import org.springframework.web.bind.annotation.RequestBody;
 
 import java.util.List;
+import java.util.Map;
 import java.util.Set;
 
 public interface GroupSopService {
@@ -123,6 +124,38 @@ public interface GroupSopService {
      */
     public boolean publishSop(SaveSopVo saveSopVo) throws Exception;
 
+    /**
+     * 处理引用的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, RefedSopBean> proccessSopIdRefProfile(List<String> refSopIds) throws Exception ;
+
+
+    /**
+     * handl sop 的相关属性
+     * @param sop
+     * @param refSopProfile
+     * @param changedObjIds
+     */
+    public void proccessSopItem(List<SopStepsBean> sopStepsBean, Map<String, RefedSopBean> refSopProfile, List<FitObjsBean> fitObjs, Set<String> changedObjIds);
+
+
+    /**
+     * 删除指定sopid 的所有引用关系
+     * @param sopId
+     * @return
+     */
+    public boolean destoryAllSopRelation(String sopId) ;
+
+
+    public  boolean destroySopById(@RequestBody DestorySopVo destorySopVo) throws Exception;
+
+
+    public Sop queryPublishedSopById( String sopId) throws Exception;
+
 
 
 

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

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

+ 212 - 62
fm-sop/src/main/java/com/persagy/fm/sop/service/impl/GroupSopServiceImpl.java

@@ -25,6 +25,7 @@ import org.apache.commons.lang.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
+import org.springframework.web.bind.annotation.RequestBody;
 
 import java.lang.reflect.InvocationTargetException;
 import java.util.*;
@@ -106,24 +107,16 @@ public class GroupSopServiceImpl implements GroupSopService {
     @Override
     @Transactional
     public boolean addPublishedSop(SaveSopVo saveSopVo) throws Exception {
-
         //找到sop 与与对象、设备型号、工单类型、自定义标签、sop关系 并插入数据库中
         addSopRelation(saveSopVo);
-        //落库本条sop*/
-        //填充必要字段
-
-        //将 请求体中的参数拷贝到我们里面
-        //将对象映射到数据库实体上面去
+        Set<String> sopRefSops = this.getSopRefSops(saveSopVo);
         Sop sop = SopMapper.INSTANCE.SaveSopVoToSop(saveSopVo);
-        /*sop.setSopStatus(SopConst.SOP_STATUS_PUBLISH);
-        sop.setPublishStatus(SopConst.PUBLISH_STATUS_NORMAL);*/
         SopState sopState = sopStateMachine.newPublic();
-        //设置状态
         setSopStatus(sop, sopState);
+        sop.setRefSopIds(new ArrayList<>(sopRefSops));
         sop.setVersionCount(1);
         sop.setVersion("V0.1");
         sop.setVersionExplain("[\""+ CommonConst.version_explain_create+"\"]");
-        //将参数转化为指定的字段后进行存储
         sop.insert();
         return true;
     }
@@ -221,7 +214,6 @@ public class GroupSopServiceImpl implements GroupSopService {
         List<SaveSopVo.FitObjsBean> sopRelObjs = getSopRelObjs(saveSopVo);
         if(CollectionUtils.isNotEmpty(sopRelObjs)) {
             for (SaveSopVo.FitObjsBean sopRelObj : sopRelObjs) {
-
                 SopObjRel sopObjRel = new SopObjRel();
                 sopObjRel.setSopId(saveSopVo.getSop_id());
                 sopObjRel.setObjId(sopRelObj.getObj_id());
@@ -558,9 +550,9 @@ public class GroupSopServiceImpl implements GroupSopService {
         org.springframework.beans.BeanUtils.copyProperties(oldSop, sopHis);
         //获取sop的版本信息
         Integer versionCount = oldSop.getVersionCount();
-        Map<String, SopHis.RefedSopBean> stringProfileMap = proccessSopIdRefProfile(oldSop.getRefSopIds());
+        Map<String, RefedSopBean> stringProfileMap = proccessSopIdRefProfile(oldSop.getRefSopIds());
         //在每一步上追加该信息
-        proccessSopItem(sopHis, stringProfileMap, null);
+        proccessSopItem(sopHis.getSteps(), stringProfileMap, null,null);
         //在refed中添加信息
         sopHis.setRefedSops(getSopProfileOfRefCurrentSop(sopHis.getSopId()));
 
@@ -601,15 +593,24 @@ public class GroupSopServiceImpl implements GroupSopService {
 
 
 
-
+    public boolean destoryAllSopRelation(String sopId) {
+        sopObjRelService.deleteBySopId(sopId);
+        sopEquipModelRelService.deleteBySopId(sopId);
+        sopOrderTypeRelService.deleteBySopId(sopId);
+        sopLabelRelService.deleteBySopId(sopId);
+        sopSopRelService.deleteBySopId(sopId);
+        return true;
+    }
     private boolean updateSopRelation(SaveSopVo saveSopVo) throws Exception{
 
+        destoryAllSopRelation(saveSopVo.getSop_id());
+
         //添加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();
@@ -622,7 +623,6 @@ public class GroupSopServiceImpl implements GroupSopService {
             }
         }
 
-        sopEquipModelRelService.deleteBySopId(saveSopVo.getSop_id());
 
 
         //添加sop与设备型号关系-sop_equip_model_rel
@@ -640,7 +640,7 @@ public class GroupSopServiceImpl implements GroupSopService {
 
         //删除所有
 
-        sopOrderTypeRelService.deleteBySopId(saveSopVo.getSop_id());
+
 
 
         //添加sop与工单类型关系-sop_order_type_rel
@@ -659,7 +659,7 @@ public class GroupSopServiceImpl implements GroupSopService {
         //添加sop与自定义标签关系-sop_label_rel
 
 
-        sopLabelRelService.deleteBySopId(saveSopVo.getSop_id());
+
         List<String> labels = saveSopVo.getLabels();
         distinctCollection(labels);
         if(CollectionUtils.isNotEmpty(labels)) {
@@ -674,7 +674,7 @@ public class GroupSopServiceImpl implements GroupSopService {
 
 
 
-        sopSopRelService.deleteBySopId(saveSopVo.getSop_id());
+
         //添加sop与sop关系-sop_sop_rel
         Set<String> sopRefSops = getSopRefSops(saveSopVo);
         if(CollectionUtils.isNotEmpty(sopRefSops)) {
@@ -701,7 +701,7 @@ public class GroupSopServiceImpl implements GroupSopService {
      * @return
      * @throws Exception
      */
-    public  List< SopHis.RefedSopBean>  getSopProfileOfRefCurrentSop( String sopId) throws Exception{
+    public  List<RefedSopBean>  getSopProfileOfRefCurrentSop( String sopId) throws Exception{
         //查询引用该sop的sopid
         QueryWrapper<SopSopRel> sopSopRelQueryWrapper = new QueryWrapper<>();
         sopSopRelQueryWrapper.eq("rel_sop_id",sopId);
@@ -718,45 +718,78 @@ public class GroupSopServiceImpl implements GroupSopService {
 
     /**
      * 处理sop详情 补充引用sop简介,添加内容对象变化标识
-     * @param sop
+     * @param sopStepsBean
      * @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) {
+    public void proccessSopItem(List<SopStepsBean> sopStepsBean, Map<String, RefedSopBean> refSopProfile, List<FitObjsBean> fitObjs,Set<String> changedObjIds){
+       /* if(CollectionUtils.isNotEmpty(changedObjIds)) {
+            if (CollectionUtils.isNotEmpty(fitObjs)) {
+                for (FitObjsBean fitObj : fitObjs) {
                     String obj_id = fitObj.getObj_id();
-                    if(changedObjIds.contains(obj_id)) {
+                    if (changedObjIds.contains(obj_id)) {
                         fitObj.setIs_revise(true);
                     }
                 }
             }
-            //處理步驟
-            List<SopStepsBean> steps = sop.getSteps();
-            for (SopStepsBean step : steps) {
+        }*/
+        //填充属性
+        if(CollectionUtils.isNotEmpty(sopStepsBean)) {
+            for (SopStepsBean step : sopStepsBean) {
                 Boolean from_sop = step.isFrom_sop();
-                if(BooleanUtils.isTrue(from_sop)) {
+                if (BooleanUtils.isTrue(from_sop)) {
                     //将引用的简洁填充上去
                     String sop_id = step.getSop_id();
-                    SopHis.RefedSopBean profile = refSopProfile.get(sop_id);
-                    if(profile != null) {
+                    RefedSopBean profile = refSopProfile.get(sop_id);
+                    if (profile != null) {
                         step.setProfile(profile);
                     }
-                }else {
+                } else {
                     List<SopStepsBean.StepContentBean> step_content = step.getStep_content();
-                    if(CollectionUtils.isNotEmpty(step_content)) {
+                    if (CollectionUtils.isNotEmpty(step_content)) {
                         for (SopStepsBean.StepContentBean stepContentBean : step_content) {
+
+                            /*
+                             * 根据专业code返回专业名称    此处待完善
+                             */
+                            stepContentBean.setDomain_name("没有提供接口");
                             Boolean from_sop1 = stepContentBean.isFrom_sop();
-                            if(BooleanUtils.isTrue(from_sop1)) {
+                            if (BooleanUtils.isTrue(from_sop1)) {
                                 String sop_id = stepContentBean.getSop_id();
-                                SopHis.RefedSopBean profile = refSopProfile.get(sop_id);
-                                if(profile != null) {
+                                RefedSopBean profile = refSopProfile.get(sop_id);
+                                if (profile != null) {
                                     stepContentBean.setProfile(profile);
                                 }
                             }
+                        /*else {
+                            if (CollectionUtils.isNotEmpty(changedObjIds)) {
+                                List<SopStepsBean.StepContentBean.ContentObjsBean> content_objs = stepContentBean.getContent_objs();
+                                if(CollectionUtils.isNotEmpty(content_objs)) {
+                                    for (SopStepsBean.StepContentBean.ContentObjsBean content_obj : content_objs) {
+                                        String obj_id = content_obj.getObj_id();
+                                        if(changedObjIds.contains(obj_id)) {
+                                            content_obj.setIs_revise(true);
+                                        }else {
+                                            List<SopStepsBean.StepContentBean.ContentObjsBean.ParentsBean> parents = content_obj.getParents();
+                                            if(CollectionUtils.isNotEmpty(parents)) {
+                                                for (SopStepsBean.StepContentBean.ContentObjsBean.ParentsBean parent : parents) {
+                                                    List<String> parent_ids = parent.getParent_ids();
+                                                    if(CollectionUtils.isNotEmpty(parent_ids)) {
+                                                        for (String parent_id : parent_ids) {
+                                                            if(changedObjIds.contains(parent_id)){
+                                                                //内容对象所属大类变化
+                                                                content_obj.setIs_revise(true);
+                                                            }
+                                                        }
+                                                    }
+                                                }
+                                            }
+                                        }
+                                    }
+                                }
+                            }
+                        }*/
                         }
                     }
                 }
@@ -772,18 +805,20 @@ public class GroupSopServiceImpl implements GroupSopService {
      * @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);
+    public Map<String, RefedSopBean> proccessSopIdRefProfile(List<String> refSopIds) throws Exception {
+        Map<String, RefedSopBean> sopId_Profile = new HashMap<>();
+        if(CollectionUtils.isNotEmpty(refSopIds)) {
+            List<Sop> sops = sopService.listByIds(refSopIds);
+            for (Sop sopItem : sops) {
+                RefedSopBean profile = new 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;
     }
@@ -1463,18 +1498,7 @@ public class GroupSopServiceImpl implements GroupSopService {
         Sop one = sopService.getOne(sopQueryWrapper);
         // 1通过sop_sop_rel关系表查询到所有引用当前sop的sopID
 
-        QueryWrapper<SopSopRel> sopSopRelQueryWrapper = new QueryWrapper<>();
-        sopSopRelQueryWrapper.in("rel_sop_id",one.getSopId()).eq("valid",true);
-        List<SopSopRel> sopSopRels = sopSopRelService.list(sopSopRelQueryWrapper);
-        Set<String> ids = new HashSet<>();
-        for (SopSopRel sopSopRel : sopSopRels) {
-            ids.add(sopSopRel.getRelSopId());
-        }
-        // 2根据sopID 和有效状态 批量查询sop:name、status、update_time、version、stauts_explain
-
-        QueryWrapper<Sop> sopQueryWrapper2 = new QueryWrapper<>();
-        sopQueryWrapper2.in("sop_id",ids).eq("valid",true);
-        List<Sop> list = sopService.list(sopQueryWrapper2);
+        List<Sop> list = getReferencedSops(one.getSopId());
 
         List<RefSopInfo> refSopInfos = new ArrayList<>();
         if(CollectionUtils.isNotEmpty(list)) {
@@ -1526,6 +1550,21 @@ public class GroupSopServiceImpl implements GroupSopService {
         return refSopInfos;
     }
 
+    private List<Sop> getReferencedSops(String sopId) {
+        QueryWrapper<SopSopRel> sopSopRelQueryWrapper = new QueryWrapper<>();
+        sopSopRelQueryWrapper.in("rel_sop_id",sopId).eq("valid",true);
+        List<SopSopRel> sopSopRels = sopSopRelService.list(sopSopRelQueryWrapper);
+        Set<String> ids = new HashSet<>();
+        for (SopSopRel sopSopRel : sopSopRels) {
+            ids.add(sopSopRel.getRelSopId());
+        }
+        // 2根据sopID 和有效状态 批量查询sop:name、status、update_time、version、stauts_explain
+
+        QueryWrapper<Sop> sopQueryWrapper2 = new QueryWrapper<>();
+        sopQueryWrapper2.in("sop_id",ids).eq("valid",true);
+        return sopService.list(sopQueryWrapper2);
+    }
+
 
     /**
      * 转换sop状态为汉字
@@ -1547,4 +1586,115 @@ public class GroupSopServiceImpl implements GroupSopService {
         }
         return status;
     }
+
+    @Transactional
+    public  boolean destroySopById(@RequestBody DestorySopVo destorySopVo) throws Exception{
+        //如果编辑表中有进行删除
+        sopEditService.deleteBySopId(destorySopVo.getSop_id());
+        Sop sop = sopService.getById(destorySopVo.getSop_id());
+
+        Map<String, RefedSopBean> refSop_profile =
+                this.proccessSopIdRefProfile(sop.getRefSopIds());
+        this.proccessSopItem(sop.getSteps(),refSop_profile,null,null);
+
+        SopState sopState = sopStateMachine.public2Distory();
+        setSopStatus(sop,sopState);
+        Sop.OperatorBean operatorBean = new Sop.OperatorBean();
+        BeanUtils.copyProperties(destorySopVo.getOperator(),operatorBean);
+        sop.setOperator(operatorBean);
+        sop.setVersionExplain(CommonConst.distory_sop);
+        //跟新sop
+        sopService.updateById(sop);
+
+        //删除引用
+        this.destoryAllSopRelation(sop.getSopId());
+
+        //查询引用这个sop的sop
+        List<Sop> list = this.getReferencedSops(destorySopVo.getSop_id());
+        for (Sop sop1 : list) {
+            SopHis sopHis = new SopHis();
+            BeanUtils.copyProperties(sop1,sopHis);
+            removeRefFromStep(sop1,destorySopVo.getSop_id());
+            //rugo sopstep 是空  销毁该sop
+            if(CollectionUtils.isEmpty(sop1.getSteps())) {
+                String sopId = sop1.getSopId();
+                DestorySopVo destorySopVo1 = new DestorySopVo();
+                destorySopVo1.setSop_id(sopId);;
+                destorySopVo1.setOperator(destorySopVo.getOperator());
+                //递归删除
+                destroySopById(destorySopVo1);
+
+            }else {
+                //保存历史版本
+                sopHis.setRefedSops(getSopProfileOfRefCurrentSop(sopHis.getSopId()));
+                sopHisService.save(sopHis);
+                List<String> refSopIds = sop1.getRefSopIds();
+                refSopIds.remove(destorySopVo.getSop_id());
+                updateRecordByKeyAndUpVersion(sop1);
+            }
+        }
+
+        return true;
+    }
+
+    /**
+     * sop引用的sop作废或删除时更新sop步骤(移除删除sop的步骤)
+     * @param sop
+     * @param removedSopId
+     * @return
+     */
+    public void removeRefFromStep(Sop sop, String removedSopId) {
+
+        List<SopStepsBean> steps = sop.getSteps();
+        Iterator<SopStepsBean> iterator = steps.iterator();
+        while (iterator.hasNext()) {
+            SopStepsBean next = iterator.next();
+            if (BooleanUtils.isTrue(next.getFrom_sop())) {
+                if (StringUtils.equals(removedSopId, next.getSop_id())) {
+                    iterator.remove();
+                }
+            } else {
+                List<SopStepsBean.StepContentBean> step_content = next.getStep_content();
+                Iterator<SopStepsBean.StepContentBean> stepContentBeanIterator = step_content.iterator();
+                while (stepContentBeanIterator.hasNext()) {
+                    SopStepsBean.StepContentBean stepContentBean = stepContentBeanIterator.next();
+                    if (BooleanUtils.isTrue(stepContentBean.getFrom_sop())) {
+                        if (StringUtils.equals(removedSopId, stepContentBean.getSop_id())) {
+                            stepContentBeanIterator.remove();
+                        }
+                    }
+                }
+                if(CollectionUtils.isEmpty(step_content)) {
+                    iterator.remove();
+                }
+            }
+        }
+
+    }
+
+
+    public Sop queryPublishedSopById( String sopId) throws Exception{
+        Sop sop = sopService.getById(sopId);
+        List<String> equipModelIds = sop.getEquipModelIds();
+        if(CollectionUtils.isNotEmpty(equipModelIds)) {
+            //查询设备的名称
+        }
+
+        //设置 equip_models
+        String publishStatus = sop.getPublishStatus();
+        Set<String> objectIds = new HashSet<>();
+        if(SopConst.PUBLISH_STATUS_REVISE.equals(publishStatus) || SopConst.PUBLISH_STATUS_REVISEING.equals(publishStatus)) {
+            //查询哪些对象发生了改变
+            //"没有提供接口"
+        }
+        Map<String, RefedSopBean> stringRefedSopBeanMap = this.proccessSopIdRefProfile(sop.getRefSopIds());
+        this.proccessSopItem(sop.getSteps(),stringRefedSopBeanMap,null,null);
+        String extend_field = sop.getExtendField();
+        if (!StringUtil.isNull(extend_field)) {
+           sop.setExtendField("没有提供接口");
+        }
+
+        return sop;
+
+    }
 }

+ 9 - 2
fm-sop/src/main/java/com/persagy/fm/sop/service/impl/SopEditServiceImpl.java

@@ -1,9 +1,10 @@
 package com.persagy.fm.sop.service.impl;
 
-import com.persagy.fm.sop.model.dto.SopEdit;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.persagy.fm.sop.dao.SopEditMapper;
+import com.persagy.fm.sop.model.dto.SopEdit;
 import com.persagy.fm.sop.service.SopEditService;
-import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import org.springframework.stereotype.Service;
 
 /**
@@ -17,4 +18,10 @@ import org.springframework.stereotype.Service;
 @Service
 public class SopEditServiceImpl extends ServiceImpl<SopEditMapper, SopEdit> implements SopEditService {
 
+    @Override
+    public boolean deleteBySopId(String sopId) {
+        QueryWrapper<SopEdit> sopEditQueryWrapper = new QueryWrapper<>();
+        sopEditQueryWrapper.eq("sop_id",sopId);
+        return this.remove(sopEditQueryWrapper);
+    }
 }

+ 1 - 0
fm-sop/src/main/java/com/persagy/old/common/CommonConst.java

@@ -129,6 +129,7 @@ public class CommonConst {
     
     //SOP版本描述
     public final static String version_explain_create = "发布标准操作";
+    public final static String distory_sop = "[\"作废标准操作\"]";
     //
     public final static String remind_recovery_failed = "引用的sop已作废,请恢复后再操作";