|
@@ -1,5 +1,6 @@
|
|
|
package com.persagy.fm.sop.service.impl;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.persagy.fm.common.exception.BusinessValidatorException;
|
|
@@ -7,11 +8,14 @@ import com.persagy.fm.sop.mapper.SopMapper;
|
|
|
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.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;
|
|
|
import com.persagy.old.service.ObjectServiceI;
|
|
|
import org.apache.commons.beanutils.BeanUtils;
|
|
|
import org.apache.commons.collections.CollectionUtils;
|
|
@@ -41,6 +45,19 @@ public class GroupSopServiceImpl implements GroupSopService {
|
|
|
@Autowired
|
|
|
private SopReviseMsgService sopReviseMsgService;
|
|
|
|
|
|
+ //@Autowired
|
|
|
+ private EquipModelServiceI equipModelService;
|
|
|
+ //@Autowired
|
|
|
+ private OrderTypeCache orderTypeCache;
|
|
|
+ @Autowired
|
|
|
+ private SopLabelRelService sopLabelRelService;
|
|
|
+ @Autowired
|
|
|
+ private SopObjRelService sopObjRelService;
|
|
|
+ @Autowired
|
|
|
+ private SopOrderTypeRelService sopOrderTypeRelService;
|
|
|
+ @Autowired
|
|
|
+ private SopEquipModelRelService sopEquipModelRelService;
|
|
|
+
|
|
|
|
|
|
|
|
|
|
|
@@ -393,6 +410,607 @@ public class GroupSopServiceImpl implements GroupSopService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
+ public JSONObject querySopListForSel(QuerySopListForSelVo sopListForSelVo) throws Exception {
|
|
|
+ String projectId = sopListForSelVo.getProjectId();
|
|
|
+ String sopId = sopListForSelVo.getSop_id();
|
|
|
+ String sop_name = sopListForSelVo.getSop_name();
|
|
|
+ //是否返回包含大类对象的sop true:返回 false:不返回 (默认返回)
|
|
|
+ Boolean flag = true;
|
|
|
+ if(BooleanUtils.isFalse(sopListForSelVo.isIs_contains_classObj())) {
|
|
|
+ flag = false;
|
|
|
+ }
|
|
|
+ //1.根据update和项目id查询
|
|
|
+ List<Sop> sops = queryPublishedSopsByProjectIdAndUpdatetime(sopListForSelVo, projectId);
|
|
|
+ //2筛选sop
|
|
|
+
|
|
|
+ /*
|
|
|
+ removeReviseSop(sops);//已经直接放到sql 语句中查询了
|
|
|
+ if (!jsonObject.getString("project_id").equals(CommonConst.group_sop_id)) {
|
|
|
+ String rootProjFuncType = objectService.queryRootProjFuncTypeById(jsonObject.getString("project_id"));
|
|
|
+ removeWithoutProJFuncType(sops, rootProjFuncType);
|
|
|
+ }
|
|
|
+ */
|
|
|
+ removeRelSop(sops,projectId,sopId);
|
|
|
+
|
|
|
+ if (!flag) {
|
|
|
+ Iterator<Sop> iterator = sops.iterator();
|
|
|
+ while (iterator.hasNext()) {
|
|
|
+ Sop sopItem = iterator.next();
|
|
|
+ if (isContainsClassObj(sopItem)) {
|
|
|
+ iterator.remove();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //=========3.筛选SOP========
|
|
|
+ //根据 sign_codes 进行筛选
|
|
|
+ sops = filterSopBySignCodes(sopListForSelVo.getSign_codes(), sops, projectId);
|
|
|
+
|
|
|
+
|
|
|
+ //sops = filterSopByName(sop_name, sops); 直接在sql 中解决
|
|
|
+ sops = filterSopByFitScope(sopListForSelVo, sops);
|
|
|
+
|
|
|
+
|
|
|
+ //=========3设置返回字段======
|
|
|
+
|
|
|
+ List<SopInfoVo> sopInfoVos = additionalSopDetail(sops,projectId,"2");
|
|
|
+ JSONObject item = new JSONObject();
|
|
|
+ //------------设置过滤项-----
|
|
|
+ if (sopListForSelVo.isNeed_return_criteria()) {
|
|
|
+ Map<String, Object> criteria = getSopListCriteria(sops, sopInfoVos);
|
|
|
+ item.put("criteria", criteria);
|
|
|
+ }
|
|
|
+ //JSONArray content = new JSONArray();
|
|
|
+ /* for (Object object : sops) {
|
|
|
+ content.add(JSONUtil.getJsonObjectWithKeys((JSONObject)object, querySopListForSel_keys));
|
|
|
+ content.add(sopInfoVos
|
|
|
+ }*/
|
|
|
+ item.put("content", sopInfoVos);
|
|
|
+ item.put("count", sopInfoVos.size());
|
|
|
+ return item;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private Map<String, Object> getSopListCriteria(List<Sop> sops, List<SopInfoVo> sopInfoVos) throws Exception {
|
|
|
+ //根据业务数据抽取条件
|
|
|
+ Map<String,Object> criteria = getSopListCriteria(sops);
|
|
|
+
|
|
|
+ //根据视图数据抽取条件
|
|
|
+ //这个的我们使用视图对象进行抽取criteria.put("signs", signs);
|
|
|
+ Map<String, Map<String,String>> signMap = getBathchMergeRecordBySign(sopInfoVos);
|
|
|
+ List<Object> signs = new JSONArray();
|
|
|
+// signs.addAll(signMap.values());
|
|
|
+ for (String signCode : signMap.keySet()) {
|
|
|
+ signs.add(signMap.get(signCode));
|
|
|
+ }
|
|
|
+ criteria.put("signs", signs);
|
|
|
+ return criteria;
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<Sop> filterSopByFitScope(QuerySopListForSelVo sopListForSelVo, List<Sop> sops) throws Exception {
|
|
|
+ JSONObject param = JSONObject.parseObject(JSONObject.toJSONString(sopListForSelVo));
|
|
|
+
|
|
|
+ param.remove("project_id");
|
|
|
+ JSONObject epuipModelsResJson = null, labelsResJson = null, orderTypeResJson = null, fitObjResJson = null;
|
|
|
+ if (StringUtil.isEmptyList(param, "equip_model_ids")
|
|
|
+ && StringUtil.isEmptyList(param, "labels")
|
|
|
+ && StringUtil.isEmptyList(param, "order_type")
|
|
|
+ && StringUtil.isEmptyList(param, "fit_obj_ids")) {
|
|
|
+ return sops;
|
|
|
+ }else {
|
|
|
+ //查询条件后的交集
|
|
|
+ Set<String> sopId = new HashSet<>();
|
|
|
+ Map<String, Sop> sopMap = getSopMap(sops);
|
|
|
+ //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);
|
|
|
+
|
|
|
+ Set<String> tmp = new HashSet<>();
|
|
|
+ for (SopEquipModelRel sopEquipModelRel : list) {
|
|
|
+ tmp.add(sopEquipModelRel.getSopId());
|
|
|
+ }
|
|
|
+ sopId.addAll(tmp);
|
|
|
+ }
|
|
|
+ //1.2根据自定义标签查询
|
|
|
+ if( !StringUtil.isEmptyList(param, "labels")){
|
|
|
+ QueryWrapper<SopLabelRel> query = new QueryWrapper<>();
|
|
|
+ query.in("label",sopListForSelVo.getLabels());
|
|
|
+ List<SopLabelRel> list = sopLabelRelService.list(query);
|
|
|
+ Set<String> tmp = new HashSet<>();
|
|
|
+ for (SopLabelRel sopLabelRel : list) {
|
|
|
+ tmp.add(sopLabelRel.getSopId());
|
|
|
+ }
|
|
|
+ sopId.retainAll(tmp);
|
|
|
+ }
|
|
|
+ //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);
|
|
|
+ Set<String> tmp = new HashSet<>();
|
|
|
+ for (SopOrderTypeRel sopOrderTypeRel : list) {
|
|
|
+ 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);
|
|
|
+ Set<String> tmp = new HashSet<>();
|
|
|
+ for (SopObjRel sopObjRel : list) {
|
|
|
+ tmp.add(sopObjRel.getSopId());
|
|
|
+ }
|
|
|
+ sopId.retainAll(tmp);
|
|
|
+ }
|
|
|
+
|
|
|
+ //查询出每张表中的id 然后求出一个交集来
|
|
|
+
|
|
|
+ List<Sop> resultSops = new ArrayList<>();
|
|
|
+ for (String s : sopId) {
|
|
|
+ if (sopMap.containsKey(s)) {
|
|
|
+ resultSops.add(sopMap.get(sopId));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return resultSops;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ * Description:
|
|
|
+ * @param sops
|
|
|
+ * @return HashMap<String,Sop> key:sop_id ; value: sop
|
|
|
+ * @author yuecaipu
|
|
|
+ * @since 2018年7月10日: 下午5:50:41
|
|
|
+ * Update By yuecaipu 2018年7月10日: 下午5:50:41
|
|
|
+ */
|
|
|
+ private Map<String, Sop> getSopMap(List<Sop> sops) {
|
|
|
+ Map<String, Sop> resultMap = new HashMap<>();
|
|
|
+ for (Sop sop : sops) {
|
|
|
+ resultMap.put(sop.getSopId(),sop);
|
|
|
+ }
|
|
|
+ return resultMap;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ private JSONObject getSopListCriteria(List<Sop> content) throws Exception {
|
|
|
+ // 遍历结果过滤字段、组合返回查询参数
|
|
|
+ JSONObject sopItem, equipModel;
|
|
|
+ JSONObject criteria = new JSONObject();
|
|
|
+
|
|
|
+ if (content != null) {
|
|
|
+
|
|
|
+ HashMap<String, String> equipModelMap = collectEquipModeFromSops(content);
|
|
|
+ JSONArray equipModels = new JSONArray();
|
|
|
+ for (String equipModelId : equipModelMap.keySet()) {
|
|
|
+ equipModel = new JSONObject();
|
|
|
+ equipModel.put("equip_model_id", equipModelId);
|
|
|
+ equipModel.put("equip_model_name", equipModelMap.get(equipModelId));
|
|
|
+ equipModels.add(equipModel);
|
|
|
+ }
|
|
|
+
|
|
|
+ HashMap<String, Object> fitObjMap = collectFitObjsFromSops(content);
|
|
|
+ JSONArray fitObjs = new JSONArray();
|
|
|
+ for (String fitObjId : fitObjMap.keySet()) {
|
|
|
+ fitObjs.add(fitObjMap.get(fitObjId));
|
|
|
+ }
|
|
|
+
|
|
|
+ HashMap<String, Object> OrderTypeMap = collectOrderTypeFromSops(content);
|
|
|
+ JSONArray orderTypes = new JSONArray();
|
|
|
+ for (String OrderTypeId : OrderTypeMap.keySet()) {
|
|
|
+ orderTypes.add(OrderTypeMap.get(OrderTypeId));
|
|
|
+ }
|
|
|
+
|
|
|
+ JSONArray labels = new JSONArray();
|
|
|
+ for (Sop sop : content) {
|
|
|
+ List<String> labelsItem = sop.getLabels();
|
|
|
+ if(CollectionUtils.isNotEmpty(labelsItem)) {
|
|
|
+ for (String s : labelsItem) {
|
|
|
+ if (!labels.contains(s)) {
|
|
|
+ labels.add(s);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //HashMap<String, Object> signMap = getBathchMergeRecordBySign(content);
|
|
|
+ // JSONArray signs = new JSONArray();
|
|
|
+// signs.addAll(signMap.values());
|
|
|
+ // for (String signCode : signMap.keySet()) {
|
|
|
+ // signs.add(signMap.get(signCode));
|
|
|
+ //}
|
|
|
+ criteria.put("equip_models", equipModels);
|
|
|
+ criteria.put("labels", labels);
|
|
|
+ criteria.put("order_type", orderTypes);
|
|
|
+ criteria.put("fit_objs", fitObjs);
|
|
|
+ // criteria.put("signs", signs);
|
|
|
+ }
|
|
|
+
|
|
|
+ return criteria;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private Map<String, Map<String,String>> getBathchMergeRecordBySign(List<SopInfoVo> sops) {
|
|
|
+ Map<String, Map<String,String>> signMap = new HashMap<>();
|
|
|
+ if(CollectionUtils.isNotEmpty(sops)) {
|
|
|
+ for (SopInfoVo sop : sops) {
|
|
|
+ Map<String, String> sign = sop.getSign();
|
|
|
+ if (sign != null) {
|
|
|
+ String signCode = sign.get("code");
|
|
|
+ if (!signMap.containsKey(signCode)) {
|
|
|
+ Map<String, String> signTemp = new HashMap<>();
|
|
|
+ signTemp.put("code", signCode);
|
|
|
+ signTemp.put("name", sign.get("name"));
|
|
|
+ signMap.put(signCode, signTemp);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return signMap;
|
|
|
+ }
|
|
|
+
|
|
|
+ private HashMap<String, Object> collectFitObjsFromSops(List<Sop> sops) {
|
|
|
+ HashMap<String, Object> map = new HashMap<>();
|
|
|
+ if(CollectionUtils.isNotEmpty(sops)) {
|
|
|
+ for (Sop sop : sops) {
|
|
|
+
|
|
|
+ List<Sop.FitObjsBean> fitObjs = sop.getFitObjs();
|
|
|
+ if(CollectionUtils.isNotEmpty(fitObjs)) {
|
|
|
+ for (Sop.FitObjsBean fitObj : fitObjs) {
|
|
|
+ Map<String, String> fitObjTemp = new HashMap<>();
|
|
|
+ fitObjTemp.put("obj_id", fitObj.getObj_id());
|
|
|
+ fitObjTemp.put("obj_name", fitObj.getObj_name());
|
|
|
+ map.put(fitObj.getObj_id(), fitObjTemp);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+ private HashMap<String, Object> collectOrderTypeFromSops(List<Sop> sops) throws Exception {
|
|
|
+ HashMap<String, Object > map = new HashMap<>();
|
|
|
+ if(CollectionUtils.isNotEmpty(sops)) {
|
|
|
+ for (Sop sop : sops) {
|
|
|
+ List<String> orderTypes = sop.getOrderType();
|
|
|
+ if(CollectionUtils.isNotEmpty(orderTypes)) {
|
|
|
+ for (String orderTypeId : orderTypes) {
|
|
|
+ Map<String,String> orderTypeMap = new HashMap<>();
|
|
|
+ orderTypeMap.put("code", orderTypeId);
|
|
|
+ orderTypeMap.put("name", orderTypeCache.getOrderTypeNameById(orderTypeId));
|
|
|
+ map.put(orderTypeId, orderTypeMap);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ * Description: 获取到sop中所有设备型号
|
|
|
+ * @param sops 集合中的对象中包含equip_model_ids
|
|
|
+ * @return HashMap<String,String> key:equip_model_id ; value:equip_model_name
|
|
|
+ * @throws Exception
|
|
|
+ * @author yuecaipu
|
|
|
+ * @since 2018年7月12日: 上午11:11:17
|
|
|
+ * Update By yuecaipu 2018年7月12日: 上午11:11:17
|
|
|
+ */
|
|
|
+ private HashMap<String, String> collectEquipModeFromSops(List<Sop> sops) throws Exception {
|
|
|
+
|
|
|
+ HashMap<String, String> equipModelMap= new HashMap<>();
|
|
|
+ if(CollectionUtils.isNotEmpty(sops)) {
|
|
|
+ Set<String> equipModelIds = new HashSet<>();
|
|
|
+ for (Sop sop : sops) {
|
|
|
+ List<String> equipModelId = sop.getEquipModelIds();
|
|
|
+ if(CollectionUtils.isNotEmpty(equipModelIds)) {
|
|
|
+ equipModelIds.addAll(equipModelId);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(CollectionUtils.isNotEmpty(equipModelIds)) {
|
|
|
+ JSONObject param = new JSONObject();
|
|
|
+ param.put("equip_model_ids", equipModelIds);
|
|
|
+ String equipModelStrs = equipModelService.queryBathchMergeRecordByequipModelIds(param.toJSONString(),
|
|
|
+ "equip_model_ids", "equip_model_id");
|
|
|
+ JSONObject equipModelObjs = JSONObject.parseObject(equipModelStrs);
|
|
|
+ JSONArray equipModels = equipModelObjs.getJSONArray(DBConst.Result.CONTENT);
|
|
|
+ for (int j = 0, length = equipModels.size(); j < length; j++) {
|
|
|
+ JSONObject equipModel = equipModels.getJSONObject(j);
|
|
|
+ equipModelMap.put(equipModel.getString("equip_model_id"), equipModel.getString("equip_model_name"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return equipModelMap;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ * Description: 补全sop详情信息
|
|
|
+ * @param sops
|
|
|
+ * @param projectId
|
|
|
+ * @param queryType 1-查询发布 2-查询可复制引用
|
|
|
+ * @author yuecaipu
|
|
|
+ * @throws Exception
|
|
|
+ * @since 2018年7月12日: 下午12:23:55
|
|
|
+ * Update By yuecaipu 2018年7月12日: 下午12:23:55
|
|
|
+ */
|
|
|
+ private List<SopInfoVo> additionalSopDetail(List<Sop> sops, String projectId, String queryType) throws Exception {
|
|
|
+ List<SopInfoVo> sopInfoVos = new ArrayList<>();
|
|
|
+ if(CollectionUtils.isNotEmpty(sops)) {
|
|
|
+
|
|
|
+ HashMap<String, String> equipModelMap = collectEquipModeFromSops(sops);
|
|
|
+ for (Sop sop : sops) {
|
|
|
+ SopInfoVo sopInfoVo = new SopInfoVo();
|
|
|
+ org.springframework.beans.BeanUtils.copyProperties(sop,sopInfoVo);
|
|
|
+ if ("2".equals(queryType)) {
|
|
|
+ sopInfoVo.setStep_count(sop.getSteps().size());
|
|
|
+ }
|
|
|
+
|
|
|
+ /* if ("1".equals(queryType)) {
|
|
|
+ sop.put("sign", getSopSign(sop, projectId));
|
|
|
+ sop.put("status",projectId.equals(sop.getString("project_id")) ? sop.getString("publish_status") : "0");
|
|
|
+ JSONArray scopes = new JSONArray();
|
|
|
+ JSONArray fitObjs = sop.getJSONArray("fit_objs");
|
|
|
+ for (int j = 0, len = fitObjs.size(); j < len; j++) {
|
|
|
+ scopes.add(fitObjs.getJSONObject(j).getString("obj_name"));
|
|
|
+ }
|
|
|
+
|
|
|
+ JSONArray equipModelIds = sop.getJSONArray("equip_model_ids");
|
|
|
+ if (equipModelIds != null && equipModelIds.size() > 0) {
|
|
|
+ for (Object equipModelId : equipModelIds) {
|
|
|
+ scopes.add(equipModelMap.get((String) equipModelId));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ JSONArray orderTypes = sop.getJSONArray("order_type");
|
|
|
+ String orderTypeName ;
|
|
|
+ for (Object orderTypeId : orderTypes) {
|
|
|
+ orderTypeName = orderTypeCache.getOrderTypeNameById((String)orderTypeId);
|
|
|
+ scopes.add(orderTypeName);
|
|
|
+ }
|
|
|
+ sop.put("scopes", scopes);
|
|
|
+ }*/
|
|
|
+
|
|
|
+ if ("1".equals(queryType)) {
|
|
|
+ sopInfoVo.setSign(getSopSign(sop,projectId));
|
|
|
+ }
|
|
|
+
|
|
|
+ sopInfoVos.add(sopInfoVo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return sopInfoVos;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ * @param sop
|
|
|
+ * @param projectId
|
|
|
+ * @return code string
|
|
|
+ * name string
|
|
|
+ * @throws Exception
|
|
|
+ */
|
|
|
+ public Map<String, String> getSopSign(Sop sop, String projectId) throws Exception{
|
|
|
+ Map<String,String> sign = null;
|
|
|
+ if (CommonConst.group_sop_id.equals(projectId)) {
|
|
|
+ String publishStatus = sop.getPublishStatus();
|
|
|
+ if (SopConst.PUBLISH_STATUS_REVISE.equals(publishStatus)) {
|
|
|
+ sign.put("code", "revise");
|
|
|
+ sign.put("name", "待修订");
|
|
|
+ } else if (SopConst.PUBLISH_STATUS_REVISEING.equals(publishStatus)) {
|
|
|
+ sign.put("code", "revising");
|
|
|
+ sign.put("name", "编辑中");
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ if(SopConst.SOP_TYPE_GROUP.equals(sop.getSopType())){//sop_type:1 集团sop 2项目专用sop
|
|
|
+ sign.put("code", "public");
|
|
|
+ sign.put("name", "集团");
|
|
|
+ }else{
|
|
|
+ // String sopProjectId = sop.getString("project_id");
|
|
|
+ // if(projectId.equals(sopProjectId)){
|
|
|
+ String publishStatus = sop.getPublishStatus();
|
|
|
+ if (SopConst.PUBLISH_STATUS_REVISE.equals(publishStatus)) {
|
|
|
+ sign.put("code", "revise");
|
|
|
+ sign.put("name", "待修订");
|
|
|
+ } else if (SopConst.PUBLISH_STATUS_REVISEING.equals(publishStatus)) {
|
|
|
+ sign.put("code", "revising");
|
|
|
+ sign.put("name", "编辑中");
|
|
|
+ }
|
|
|
+ //}
|
|
|
+ /*else{
|
|
|
+ sign = new JSONObject();
|
|
|
+ sign.put("code", projectId);
|
|
|
+ sign.put("name", projectCache.getProjectNameById(projectId));
|
|
|
+ }*/
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return sign;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ * Description: 根据signCodes筛选sop(交集)
|
|
|
+ * @param signCodes
|
|
|
+ * @param sops
|
|
|
+ * @return JSONArray
|
|
|
+ * @author yuecaipu
|
|
|
+ * @since 2018年7月10日: 下午12:09:41
|
|
|
+ * Update By yuecaipu 2018年7月10日: 下午12:09:41
|
|
|
+ */
|
|
|
+ private List<Sop> filterSopBySignCodes(List<String> signCodes, List<Sop> sops, String projectId) {
|
|
|
+ List<Sop> resultSops = new ArrayList<>();
|
|
|
+ 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())) {
|
|
|
+ resultSops.add(object);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (signCodes.contains("revise")) {
|
|
|
+ for (Sop object : sops) {
|
|
|
+ if (projectId.equals(object.getProjectId()) && SopConst.PUBLISH_STATUS_REVISE.equals(object.getPublishStatus())) {
|
|
|
+ resultSops.add(object);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (signCodes.contains("revising")) {
|
|
|
+ for (Sop object : sops) {
|
|
|
+ if (projectId.equals(object.getProjectId()) && SopConst.PUBLISH_STATUS_REVISEING.equals(object.getPublishStatus())) {
|
|
|
+ resultSops.add(object);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return resultSops;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public boolean isContainsClassObj(Sop sop) throws Exception {
|
|
|
+ List<SopStepsBean> steps = sop.getSteps();
|
|
|
+ for (SopStepsBean step : steps) {
|
|
|
+ Boolean from_sop = step.isFrom_sop();
|
|
|
+ //非引用
|
|
|
+ if(!from_sop) {
|
|
|
+ List<SopStepsBean.StepContentBean> step_content = step.getStep_content();
|
|
|
+ for (SopStepsBean.StepContentBean stepContentBean : step_content) {
|
|
|
+ Boolean from_sop1 = stepContentBean.isFrom_sop();
|
|
|
+ //非引用
|
|
|
+ if(!from_sop1) {
|
|
|
+ List<SopStepsBean.StepContentBean.ContentObjsBean> content_objs = stepContentBean.getContent_objs();
|
|
|
+ for (SopStepsBean.StepContentBean.ContentObjsBean content_obj : content_objs) {
|
|
|
+ String obj_type = content_obj.getObj_type();
|
|
|
+ if (obj_type.contains("_")) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ //如果是引用的haul
|
|
|
+ String sop_id = stepContentBean.getSop_id();
|
|
|
+ Sop sop1 = new Sop();
|
|
|
+ Sop query = sop1.selectById(sop_id);
|
|
|
+ if(query != null) {
|
|
|
+ return isContainsClassObj(query);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }else {
|
|
|
+ //如果是引用的haul
|
|
|
+ String sop_id = step.getSop_id();
|
|
|
+ Sop sop1 = new Sop();
|
|
|
+ Sop query = sop1.selectById(sop_id);
|
|
|
+ if(query != null) {
|
|
|
+ return isContainsClassObj(query);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private void removeRelSop( List<Sop> sops, String projectId, String sopId) {
|
|
|
+ Set<String> relSopIds = querySopRel(projectId, sopId);
|
|
|
+ relSopIds.add(sopId);
|
|
|
+ Iterator<Sop> iterator = sops.iterator();
|
|
|
+ while (iterator.hasNext()) {
|
|
|
+ Sop next = iterator.next();
|
|
|
+ String nodeId = next.getSopId();
|
|
|
+ if (relSopIds.contains(nodeId)) {
|
|
|
+ iterator.remove();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private Set<String> querySopRel(String projectId,String sopId) {
|
|
|
+ //key:被引用SOP的主键id value:引用该SOP的SOP主键id
|
|
|
+ Map<String, Set<String>> relSopId2sopId = new HashMap<>();
|
|
|
+
|
|
|
+ QueryWrapper<SopSopRel> query = new QueryWrapper();
|
|
|
+ query.eq("'",projectId).eq("",sopId).eq("valid",true);
|
|
|
+
|
|
|
+ List<SopSopRel> list = sopSopRelService.list(query);
|
|
|
+ for (SopSopRel sopSopRel : list) {
|
|
|
+ String rel_sop_id = sopSopRel.getRelSopId();
|
|
|
+ String sop_id = sopSopRel.getSopId();
|
|
|
+ Set<String> sopIds = relSopId2sopId.getOrDefault(rel_sop_id, new HashSet<String>());
|
|
|
+ sopIds.add(sop_id);
|
|
|
+ relSopId2sopId.put(rel_sop_id, sopIds);
|
|
|
+ }
|
|
|
+ return getRelSopRecursively(relSopId2sopId,sopId);
|
|
|
+ }
|
|
|
+
|
|
|
+ private Set<String> getRelSopRecursively(Map<String, Set<String>> relSopId2sopId, String sopId) {
|
|
|
+ Set<String> relSopIds = new HashSet<>();
|
|
|
+ if (CollectionUtils.isEmpty(relSopId2sopId.get(sopId))) {
|
|
|
+ return relSopIds;
|
|
|
+ }
|
|
|
+ Set<String> set = relSopId2sopId.get(sopId);
|
|
|
+ relSopIds.addAll(set);
|
|
|
+ for (String string : set) {
|
|
|
+ relSopIds.addAll(getRelSopRecursively(relSopId2sopId, string));
|
|
|
+ }
|
|
|
+ return relSopIds;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ private List<Sop> queryPublishedSopsByProjectIdAndUpdatetime(QuerySopListForSelVo sopListForSelVo,String projectId) throws Exception {
|
|
|
+ String sop_name = sopListForSelVo.getSop_name();
|
|
|
+ /*
|
|
|
+ //如果项目id 不是集团特有的id的话进入
|
|
|
+ if (!CommonConst.group_sop_id.equals(requestJson.getString("project_id"))) {
|
|
|
+ //如果sign_codes 数时空的话 或者sign_codes 码中包含public 的话
|
|
|
+ if (StringUtil.isEmptyList(requestJson, "sign_codes") || requestJson.getJSONArray("sign_codes").contains("public")) {
|
|
|
+ //设置为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)
|
|
|
+ .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)
|
|
|
+ .like("sop_name",sop_name).orderByDesc("update_time");
|
|
|
+
|
|
|
+
|
|
|
+ return sopService.list(query);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
public boolean verifySopBeforePublish(VerifySopNameVo verifySopNameVo) throws Exception {
|
|
|
//查询sop 表中是否存在CommonConst.group_sop_id sop_name sopId 的数据
|
|
|
QueryWrapper<Sop> sopQueryWrapper = new QueryWrapper<>();
|