|
@@ -0,0 +1,186 @@
|
|
|
+package com.persagy.fm.sop.controller;
|
|
|
+
|
|
|
+import com.persagy.fm.common.response.FmResponseMsg;
|
|
|
+import com.persagy.fm.common.response.FmResponseUtil;
|
|
|
+import com.persagy.fm.sop.constant.CommonConst;
|
|
|
+import com.persagy.fm.sop.constant.DBConst;
|
|
|
+import com.persagy.fm.sop.model.dto.*;
|
|
|
+import com.persagy.fm.sop.model.vo.SaveSopVo;
|
|
|
+import com.persagy.fm.sop.utils.ToolsUtil;
|
|
|
+import org.apache.commons.beanutils.BeanUtils;
|
|
|
+import org.apache.commons.collections.CollectionUtils;
|
|
|
+import org.apache.commons.lang.BooleanUtils;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.web.bind.annotation.PostMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestBody;
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
+
|
|
|
+import java.lang.reflect.InvocationTargetException;
|
|
|
+import java.util.*;
|
|
|
+
|
|
|
+@RestController
|
|
|
+@RequestMapping("restGroupSopService")
|
|
|
+public class GroupSopController {
|
|
|
+ //添加参数逻辑校验工作
|
|
|
+ @PostMapping("addPublishedSop")
|
|
|
+ public FmResponseMsg addPublishedSop(@RequestBody SaveSopVo saveSopVo) throws Exception {
|
|
|
+
|
|
|
+ //设置查询的项目类型为集团类型的
|
|
|
+ saveSopVo.setProject_id(CommonConst.group_sop_id);
|
|
|
+ saveSopVo.setSop_id(ToolsUtil.getRecordId(DBConst.TABLE_SOP_ID_TAG));
|
|
|
+ //找到sop 与与对象、设备型号、工单类型、自定义标签、sop关系 并插入数据库中
|
|
|
+ addSopRelation(saveSopVo);
|
|
|
+ //落库本条sop*/
|
|
|
+
|
|
|
+ return FmResponseUtil.successMsg("保存成功");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Transactional
|
|
|
+ public boolean addSopRelation(SaveSopVo saveSopVo) throws Exception{
|
|
|
+
|
|
|
+ //添加sop与对象关系-sop_obj_rel
|
|
|
+ List<SaveSopVo.FitObjsBean> sopRelObjs = getSopRelObjs(saveSopVo);
|
|
|
+ if(CollectionUtils.isNotEmpty(sopRelObjs)) {
|
|
|
+ for (SaveSopVo.FitObjsBean sopRelObj : sopRelObjs) {
|
|
|
+ SopObjRel build = SopObjRel.builder()
|
|
|
+ .sopId(saveSopVo.getSop_id())
|
|
|
+ .objId(sopRelObj.getObj_id())
|
|
|
+ .objType(sopRelObj.getObj_type())
|
|
|
+ .valid(true)
|
|
|
+ .build();
|
|
|
+
|
|
|
+ build.insert();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //添加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();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //添加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
|
|
|
+ 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();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //添加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;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ public void distinctCollection(List<String> list) {
|
|
|
+ HashSet set = new HashSet(list);
|
|
|
+ list.clear();
|
|
|
+ list.addAll(set);
|
|
|
+ }
|
|
|
+
|
|
|
+ public List<SaveSopVo.FitObjsBean> getSopRelObjs(SaveSopVo sop) throws InvocationTargetException, IllegalAccessException {
|
|
|
+ List<SaveSopVo.FitObjsBean> sopRelObjs = new ArrayList<>();
|
|
|
+ Map<String,SaveSopVo.FitObjsBean> objectId_Object = new HashMap<>();
|
|
|
+
|
|
|
+ if(sop != null) {
|
|
|
+ //查询适用的对象
|
|
|
+ List<SaveSopVo.FitObjsBean> fit_objs = sop.getFit_objs();
|
|
|
+ if(CollectionUtils.isNotEmpty(fit_objs)) {
|
|
|
+ for (SaveSopVo.FitObjsBean fit_obj : fit_objs) {
|
|
|
+ objectId_Object.put(fit_obj.getObj_id(),fit_obj);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ List<SaveSopVo.StepsBean> steps = sop.getSteps();
|
|
|
+ if(CollectionUtils.isNotEmpty(steps)) {
|
|
|
+ for (SaveSopVo.StepsBean step : steps) {
|
|
|
+ //如果不是来自引用的对象
|
|
|
+ if(BooleanUtils.isFalse(step.isFrom_sop())) {
|
|
|
+ List<SaveSopVo.StepsBean.StepContentBean> step_content = step.getStep_content();
|
|
|
+ if(CollectionUtils.isNotEmpty(step_content)) {
|
|
|
+ for (SaveSopVo.StepsBean.StepContentBean stepContentBean : step_content) {
|
|
|
+ List<SaveSopVo.StepsBean.StepContentBean.ContentObjsBean> content_objs = stepContentBean.getContent_objs();
|
|
|
+ if(CollectionUtils.isNotEmpty(content_objs)) {
|
|
|
+ for (SaveSopVo.StepsBean.StepContentBean.ContentObjsBean content_obj : content_objs) {
|
|
|
+ //进行数值拷贝到一个对象中去
|
|
|
+ SaveSopVo.FitObjsBean fitObjsBean = new SaveSopVo.FitObjsBean();
|
|
|
+ BeanUtils.copyProperties(fitObjsBean,content_obj);
|
|
|
+ objectId_Object.put(content_obj.getObj_id(),fitObjsBean);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //sop中 适用对象和步骤中的对象
|
|
|
+ for (SaveSopVo.FitObjsBean value : objectId_Object.values()) {
|
|
|
+ sopRelObjs.add(value);
|
|
|
+ }
|
|
|
+ return sopRelObjs;
|
|
|
+ }
|
|
|
+
|
|
|
+ public Set<String> getSopRefSops(SaveSopVo sop){
|
|
|
+ LinkedHashSet<String> sopIds = new LinkedHashSet<>();
|
|
|
+ if(sop != null) {
|
|
|
+
|
|
|
+ List<SaveSopVo.StepsBean> steps = sop.getSteps();
|
|
|
+ if(CollectionUtils.isNotEmpty(steps)) {
|
|
|
+ for (SaveSopVo.StepsBean step : steps) {
|
|
|
+ if (BooleanUtils.isTrue(step.isFrom_sop())) {
|
|
|
+ sopIds.add(step.getSop_id());
|
|
|
+ } else {
|
|
|
+ List<SaveSopVo.StepsBean.StepContentBean> step_content = step.getStep_content();
|
|
|
+ if(CollectionUtils.isNotEmpty(step_content)) {
|
|
|
+ for (SaveSopVo.StepsBean.StepContentBean stepContentBean : step_content) {
|
|
|
+ if (BooleanUtils.isTrue(stepContentBean.isFrom_sop())) {
|
|
|
+ sopIds.add(stepContentBean.getSop_id());
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return sopIds;
|
|
|
+ }
|
|
|
+}
|