PrpSetupAction.java

package com.mycim.webapp.actions;

import com.fa.sesa.exception.Assert;
import com.fa.sesa.exception.Errors;
import com.fa.sesa.threadlocal.LocalContext;
import com.mycim.framework.context.spring.SpringContext;
import com.mycim.framework.utils.lang.StringUtils;
import com.mycim.framework.utils.lang.collections.CollectionUtils;
import com.mycim.framework.utils.lang.math.NumberUtils;
import com.mycim.quartz.service.QuartzOperateService;
import com.mycim.server.asm.service.AsmService;
import com.mycim.server.asm.service.WarehouseService;
import com.mycim.server.constrain.service.ConstrainService;
import com.mycim.server.ctx.exec.service.CtxExecService;
import com.mycim.server.ctx.service.CtxService;
import com.mycim.server.ecn.service.EcnService;
import com.mycim.server.ems.service.EmsService;
import com.mycim.server.erp.service.ErpService;
import com.mycim.server.prp.service.ProductService;
import com.mycim.server.prp.service.PrpService;
import com.mycim.server.rcp.service.RecipeService;
import com.mycim.server.spec.service.ProcessSpecService;
import com.mycim.server.spec.service.ProductAttributeService;
import com.mycim.server.spec.service.SpecService;
import com.mycim.server.wip.service.LotQueryService;
import com.mycim.server.wip.service.LotService;
import com.mycim.server.wip.service.WipQueryService;
import com.mycim.server.workorder.service.WorkOrderService;
import com.mycim.valueobject.MessageIdList;
import com.mycim.valueobject.ObjectList;
import com.mycim.valueobject.bas.NamedObject;
import com.mycim.valueobject.bas.ObjectVersion;
import com.mycim.valueobject.bas.Relation;
import com.mycim.valueobject.consts.AsmConst;
import com.mycim.valueobject.consts.LinkTypeList;
import com.mycim.valueobject.ems.EntityGroup;
import com.mycim.valueobject.inv.MaterialDO;
import com.mycim.valueobject.prp.*;
import com.mycim.webapp.Constants;
import com.mycim.webapp.WebUtils;
import com.mycim.webapp.forms.RecipeContextValueForm;
import com.mycim.webapp.forms.WflInfoForm;

import javax.servlet.http.HttpServletRequest;
import java.lang.Override;
import java.util.*;

/**
 * Prp基类
 *
 * @author Johnson.Wang
 * @version 6.0.0
 * @date 2019/8/21
 **/
public class PrpSetupAction extends AbstractAction {


    protected static final String PROCESS_RRN_KEY = "PROCESSRRN";

    protected static final String DATA_PERMISSION_KEY = "dataPermissionFlag";

    private static final String PROCESS_JOB_CLASS = "com.mycim.quartz.jobs" + ".ProcessScheduleJob";

    protected final String TRUE = "1";

    protected final String FALSE = "0";

    protected final String ON = "on";

    protected final String EMPTY = "";

    private final String FILTER_TYPE = "FILTERTYPE";

    private final String EXECUTIONRRN = "EXECUTIONRRN";

    protected PrpService prpService = SpringContext.getBean(PrpService.class);

    protected ProductService productService = SpringContext.getBean(ProductService.class);

    protected CtxService ctxService = SpringContext.getBean(CtxService.class);

    protected EmsService emsService = SpringContext.getBean(EmsService.class);

    protected RecipeService recipeService = SpringContext.getBean(RecipeService.class);

    protected EcnService ecnService = SpringContext.getBean(EcnService.class);

    protected CtxExecService ctxExecService = SpringContext.getBean(CtxExecService.class);

    protected ProcessSpecService processSpecService = SpringContext.getBean(ProcessSpecService.class);

    protected SpecService specService = SpringContext.getBean(SpecService.class);

    protected ProductAttributeService productAttributeService = SpringContext.getBean(ProductAttributeService.class);

    protected WipQueryService wipQueryService = SpringContext.getBean(WipQueryService.class);

    protected AsmService asmService = SpringContext.getBean(AsmService.class);

    protected ConstrainService constrainService = SpringContext.getBean(ConstrainService.class);

    protected LotQueryService lotQueryService = SpringContext.getBean(LotQueryService.class);

    protected QuartzOperateService quartzOperateService = SpringContext.getBean(QuartzOperateService.class);

    protected LotService lotService = SpringContext.getBean(LotService.class);

    protected WarehouseService warehouseService = SpringContext.getBean(WarehouseService.class);

    protected WorkOrderService workOrderService = SpringContext.getBean(WorkOrderService.class);

    protected ErpService erpService = SpringContext.getBean(ErpService.class);

    public EntityGroup exisEntityGroup(String operationId) {
        EntityGroup entityGroup = new EntityGroup("EU_" + operationId, getNamedSpace(ObjectList.ENTITYGROUP_KEY,
                                                                                     LocalContext.getFacilityRrn()),
                                                  ObjectList.ENTITYGROUP_KEY);
        EntityGroup exisEtityGroup = emsService.getEntityGroup(entityGroup);
        entityGroup = exisEtityGroup != null ? exisEtityGroup : entityGroup;
        return entityGroup;
    }

    public void parseCondtionForWflInfo(WflInfoForm theform, HttpServletRequest request) {
        Map paramters = request.getParameterMap();
        Set paramterKeys = paramters.keySet();
        for (Iterator iterator = paramterKeys.iterator(); iterator.hasNext(); ) {
            String paramterKey = (String) iterator.next();
            String parameterValue = WebUtils.getParameter(paramterKey, request);
            if (StringUtils.indexOf(StringUtils.trimToUpperCase(paramterKey), ObjectList.PRODUCT_KEY) >= 0 &&
                    StringUtils.indexOf(StringUtils.trimToUpperCase(paramterKey), "VER") < 0) {
                if (StringUtils.isNotBlank(parameterValue)) {
                    theform.setProductId(parameterValue);
                }
            } else if (StringUtils.indexOf(StringUtils.trimToUpperCase(paramterKey), ObjectList.PRODUCT_KEY) >= 0 &&
                    StringUtils.indexOf(StringUtils.trimToUpperCase(paramterKey), "VER") >= 0) {
                if (StringUtils.isNotBlank(parameterValue)) {
                    theform.setProductVersion(Integer.valueOf(parameterValue));
                }
            } else if (StringUtils.indexOf(StringUtils.trimToUpperCase(paramterKey), ObjectList.PROCESS_KEY) >= 0 &&
                    StringUtils.indexOf(StringUtils.trimToUpperCase(paramterKey), "VER") < 0) {
                if (StringUtils.isNotBlank(parameterValue)) {
                    theform.setProcessId(parameterValue);
                }
            } else if (StringUtils.indexOf(StringUtils.trimToUpperCase(paramterKey), ObjectList.ROUTE_KEY) >= 0) {
                if (StringUtils.isNotBlank(parameterValue)) {
                    theform.setRouteId(parameterValue);
                }
            } else if (StringUtils.indexOf(StringUtils.trimToUpperCase(paramterKey), ObjectList.OPERATION_KEY) >= 0) {
                if (StringUtils.isNotBlank(parameterValue)) {
                    theform.setOperationId(parameterValue);
                }
            } else if (StringUtils.indexOf(StringUtils.trimToUpperCase(paramterKey), FILTER_TYPE) >= 0) {
                if (StringUtils.isNotBlank(parameterValue)) {
                    theform.setFilterType(parameterValue);
                }
            } else if (StringUtils.indexOf(StringUtils.trimToUpperCase(paramterKey), EXECUTIONRRN) >= 0) {
                if (StringUtils.isNotBlank(parameterValue)) {
                    theform.setExecutionRrn(NumberUtils.toLong(parameterValue));
                }
            }
        }
    }


    protected void process(NamedObject instance) {
        String action = instance.getTransId();

        instance.setTransPerformedby(LocalContext.getUserId());

        if (Constants.CREATE_KEY.equals(action)) {
            if (instance instanceof Operation) {
                prpService.insertOperation((Operation) instance);
            } else if (instance instanceof Recipe) {
                recipeService.insertRecipe(setDefaultParam(instance));
            } else if (instance instanceof Item) {
                productService.addProduct((Item) instance);
            } else if (instance instanceof BOR) {
                prpService.insertBor((BOR) instance);
            } else if (instance instanceof BORResource) {
                prpService.insertBORResource((BORResource) instance);
            }
        } else if (Constants.MODIFY_KEY.equals(action)) {
            if (instance instanceof Operation) {
                prpService.updateOperation((Operation) instance);
            } else if (instance instanceof Recipe) {
                recipeService.updateRecipe(setDefaultParam(instance));
            } else if (instance instanceof Item) {
                productService.updateProduct((Item) instance);
            } else if (instance instanceof BOR) {
                prpService.updateBor((BOR) instance);
            } else if (instance instanceof BORResource) {
                prpService.updateBORResource((BORResource) instance);
            }
        } else if (Constants.DELETE_KEY.equals(action)) {
            if (instance instanceof Operation) {
                prpService.deleteOperation((Operation) instance);
            } else if (instance instanceof Recipe) {
                recipeService.deleteRecipe(setDefaultParam(instance));
            } else if (instance instanceof Item) {
                productService.deleteProduct((Item) instance);
            } else if (instance instanceof BOR) {
                prpService.deleteBor((BOR) instance);
            } else if (instance instanceof BORResource) {
                prpService.deleteBORResource((BORResource) instance);
            }

        }

    }

    @Override
    protected NamedObject getInstance(NamedObject instance) {
        NamedObject qryInstance = null;

        if (instance instanceof Operation) {
            qryInstance = prpService.getOperation(instance.getInstanceId(), instance.getNamedSpace());
        } else if (instance instanceof Context) {
            qryInstance = ctxService.getContext((Context) instance);
        } else if (instance instanceof Recipe) {
            qryInstance = recipeService.getRecipe(instance.getInstanceId(), instance.getNamedSpace());
        } else if (instance instanceof Route) {
            instance.setObjectType(ObjectList.ROUTE_KEY);
            instance.setObjectSubtype(ObjectList.PROCEDURE_KEY);
            qryInstance = prpService.getRoute((Route) instance);
        } else if (instance instanceof ProcessPlanning) {
            qryInstance = prpService.getProcessPlanning((ProcessPlanning) instance);
        } else if (instance instanceof Item) {
            qryInstance = prpService.getItem((Item) instance);
        }
        if (qryInstance == null) {
            return instance;
        }
        return qryInstance;
    }

    protected boolean checkVersionEditEnable(List versionObjects) {
        if (CollectionUtils.isNotEmpty(versionObjects)) {
            for (Object version : versionObjects) {
                ObjectVersion versionObject = (ObjectVersion) version;
                if ((versionObject.getVersionStatus() == null) ||
                        versionObject.getVersionStatus().equalsIgnoreCase("UNFROZEN") ||
                        versionObject.getVersionStatus().equalsIgnoreCase("FROZEN")) {
                    return true;
                }
            }
        }
        return false;
    }

    protected Map<String, Object> validateFormAndGetBaseInfo(RecipeContextValueForm theform) {
        long facilityRrn = LocalContext.getFacilityRrn();
        Map<String, Object> baseInfo = new HashMap<String, Object>();
        baseInfo.put("contextRrn", new Long(theform.getContextRrn()));

        String productId = StringUtils.trimToUpperCase(theform.getProductId());
        Assert.isFalse(StringUtils.isBlank(productId),
                       Errors.create().key(MessageIdList.PRODUCT_ID_CANNOT_EMPTY).content("Please select product id!")
                             .build());
        long productRrn = this.getInstanceRrn(productId, facilityRrn, ObjectList.PRODUCT_KEY);
        Assert.isFalse(productRrn <= 0, Errors.create().key(MessageIdList.PRODUCT_PRODUCT_MISSING)
                                              .content("The product id:{} does not exist!").args(productId).build());
        baseInfo.put("productId", productId);
        baseInfo.put("PRODUCT_RRN", productRrn);

        // check process id
        String processId = StringUtils.trimToUpperCase(theform.getProcessId());
        if (StringUtils.isBlank(processId)) {
            processId = StringUtils.trimToUpperCase(theform.getProcessIdByTechnology());
        }
        Assert.isFalse(StringUtils.isBlank(processId),
                       Errors.create().key(MessageIdList.PROCESS_EMPTY).content("Please select the process id!")
                             .build());
        long processRrn = this.getInstanceRrn(processId, facilityRrn, ObjectList.WFL_KEY);
        Assert.isFalse(processRrn <= 0, Errors.create().key(MessageIdList.PROCESS_PROCESS_MISSING)
                                              .content("The process id:{} does not exist!").args(processId).build());
        baseInfo.put("processId", processId);
        baseInfo.put("PROCESS_RRN", processRrn);

        // check if the process Id is bonded by the product
        List<Long> processRrnsByProductRrn = prpService.getProcessRrnsByProductRrn(productRrn);
        Assert.isFalse(processRrnsByProductRrn == null || (!processRrnsByProductRrn.contains(new Long(processRrn))),
                       Errors.create().key(MessageIdList.PRODUCT_PRODUCT_PROCESS_NOT_BOUND)
                             .content("Process isn't bonded to the product!").build());

        // check process version id
        String processVersionString = theform.getProcessVersionId();
        if (StringUtils.isBlank(processVersionString)) {
            processVersionString = theform.getProcessVersionByTechnology();
        }
        Integer processVersionId = parseProcessVersion(processVersionString);

        // get the processVersion based on the processVersionId

        ProcessVersion processVersion = prpService.getProcessVersion(processRrn, processVersionId);
        // check if the processVersion is existed
        Assert.isFalse(processVersion == null, Errors.create().key(MessageIdList.PROCESS_VERSION_NOT_EXIST)
                                                     .content("The processVersion isn't existed!").build());
        // 判断active的。因此可以直接从contextVlue表里面判断,不判断flow seq因为,flowseq不能导入,只能自动生成,而且新产品也有可能绑定此流程
        boolean isImportExcel = prpService.isContextValuesSetNullInVersion(processRrn, productRrn,
                                                                           processVersion.getInstanceVersion(),
                                                                           facilityRrn, true, true);

        baseInfo.put("processVersion", processVersion.getInstanceVersion());
        baseInfo.put("PROCESS_STATUS", processVersion.getVersionStatus());
        baseInfo.put("isImportExcel", (!isImportExcel));
        baseInfo.put("ecnRrn", processVersion.getEcnRrn());

        // 判断是否已经激活,从context_value表里面查询是否有active的值即可;
        boolean hasActiveFlag = prpService.hasActiveContext(productRrn, processRrn, processVersionId);
        baseInfo.put("hasActiveFlag", hasActiveFlag);

        return baseInfo;
    }


    protected boolean checkVersionEditEnable(ObjectVersion objectVersion) {
        boolean checked = false;

        if ((objectVersion.getVersionStatus() == null) ||
                objectVersion.getVersionStatus().equalsIgnoreCase("UNFROZEN")) {
            checked = true;
        }

        return checked;
    }

    protected String checkObjectDeleteEnable(List<? extends ObjectVersion> versionObjects) {
        String checked = "true";

        if (CollectionUtils.isNotEmpty(versionObjects)) {
            checked = "false";
        }

        return checked;
    }


    protected void validateProcessPlan(List list) {
        ObjectVersion objectVersions;
        for (Object o : list) {
            objectVersions = (ObjectVersion) o;
            long objectRrn = objectVersions.getInstanceRrn();
            int objectVersion = objectVersions.getInstanceVersion();
            String object = objectVersions.getObject();

            NamedObject wflObject = null;

            if ("WFL".equalsIgnoreCase(object)) {
                boolean validateFlag = false;
                wflObject = baseService.getNamedObject(objectRrn);
                Assert.isFalse(wflObject == null,
                               Errors.create().key(MessageIdList.NAMEDOBJECT_NOT_EXIST).content("{} Does not exist.")
                                     .args(objectVersions.getInstanceId()).build());
                validateFlag = prpService.validateWfl(objectRrn, objectVersion);

                Assert.isTrue(validateFlag, Errors.create().content("Please Save in ProcessEditor").build());
            }
        }
    }


    protected Integer parseProcessVersion(String processVersionIdStr) {
        Assert.isFalse(StringUtils.isBlank(processVersionIdStr),
                       Errors.create().key(MessageIdList.TIME_LIMIT_MISSING_PROCESSVERSION)
                             .content("Please select the process " + "version id!").build());

        Integer processVersionId = 0;
        int index = processVersionIdStr.indexOf("(");
        if (index > 0) {
            String processVersionStr = StringUtils.substring(processVersionIdStr, 0, index);
            processVersionId = Integer.valueOf(processVersionStr);
        } else {
            Assert.isTrue(
                    StringUtils.isNumeric(processVersionIdStr.trim()) && Integer.valueOf(processVersionIdStr) != 0,
                    Errors.create().key(MessageIdList.PROCESS_INVALIDED_VERSION_ID)
                          .content("The process version id " + "must be Number and " + "can't be zero!").build());
            processVersionId = Integer.valueOf(processVersionIdStr);
        }
        return processVersionId;
    }

    protected List<ProductBin> getProductBinsByItem(Item item) {
        return prpService.getProductBinsByItem(item);
    }


    protected List<Map> getProductTechnologysByItem(Item item) {
        return prpService.getProductTechnologys(item.getInstanceRrn());
    }

    protected List<Map> getProductReticleGroupsByItem(Item item) {
        return prpService.getProductReticleGroupsByItem(item);
    }

    protected List<Map> getProductSapphireListByItem(Item item) {
        return prpService.getProductSapphireListByItem(item.getInstanceRrn());
    }

    protected List<Map<String, String>> getProductAndMaterialRelationForShowByProductRrn(Long productRrn) {
        List<Map<String, String>> list = new ArrayList<Map<String, String>>();
        if (productRrn != null && productRrn > 0) {
            list = prpService.getProductAndMaterialRelationForShowByProductRrn(productRrn);
        }
        return list;
    }

    protected List<Map<String, Object>> getSpecialSteps(Long productRrn) {
        List<Map<String, Object>> results = new ArrayList<Map<String, Object>>();
        if (productRrn != null && productRrn > 0) {
            List relations = sysService.getRelationsUseFromRrn(productRrn,
                                                               LinkTypeList.PRODUCT_TO_MATERIAL_MAPPING_KEY);

            for (Iterator iterator = relations.iterator(); iterator.hasNext(); ) {
                Relation relation = (Relation) iterator.next();

                Map<String, Object> result = new HashMap<String, Object>();
                Long processRrn = NumberUtils.toLong(relation.getAttributedata2());
                Long routeRrn = NumberUtils.toLong(relation.getAttributedata1());
                Integer processVersion = prpService.getLastProcessVersion(
                        NumberUtils.toLong(relation.getAttributedata2()));
                Long operationRrn = relation.getToRrn();
                result.put("productRrn", productRrn);
                result.put("routeRrn", routeRrn);
                result.put("processRrn", processRrn);
                result.put("processVersion", processVersion);
                result.put("operationRrn", relation.getToRrn());

                result.put("stepId", getInstanceId(relation.getToRrn()));
                result.put("materialMappingFlag", relation.getAttributedata3());

                String flowSeq = ctxExecService.getFlowSeqByProcessInfo(processRrn, processVersion, operationRrn,
                                                                        routeRrn);

                result.put("flowSeq", flowSeq);
                String operationDesc = ctxExecService.getOperationDescByProcessInfo(productRrn, processRrn,
                                                                                    processVersion, routeRrn,
                                                                                    operationRrn);
                result.put("operationDesc", operationDesc);
                results.add(result);
            }
        }

        return results;
    }

    protected void insertProductTechnology(Map<String, Object> map) {
        prpService.insertProductTechnology(map);
    }

    protected void deleteProductTechnology(Map<String, Object> map) {
        prpService.deleteProductTechnology(map);
    }

    protected void insertProductSapphire(Map<String, Object> map) {
        prpService.insertProductSapphire(map);
    }

    protected void deleteProductSapphire(Map<String, Object> map) {
        prpService.deleteProductSapphire(map);
    }

    protected List<Map<String, Object>> parseWorkflowTree(List<?> wflTree) {
        List<Map<String, Object>> wflInfos = new ArrayList<>();

        String routeSeq = null;
        String routeId = null;
        String routeDesc = null;
        long routeRrn = 0;
        for (Object object : wflTree) {
            String[] treeNodes = (String[]) object;

            Map<String, Object> node = new HashMap<>();
            String nodeType = treeNodes[7];
            if ("0".equals(nodeType)) {
                routeSeq = StringUtils.substringBefore(treeNodes[2], "---");
                routeId = StringUtils.substringAfter(treeNodes[2], "---");
                routeDesc = treeNodes[5];
                routeRrn = NumberUtils.toLong(treeNodes[4], 0);
                node.put("routeSeq", routeSeq);
                node.put("routeProcessSeq", routeSeq);
                node.put("routeId", routeId);
                node.put("routeDesc", routeDesc);
                node.put("isRoute", new Boolean(true));
            } else if ("1".equals(nodeType)) {
                String wflStepPath = treeNodes[6];
                String[] wflStepArray = parseWflStepPath(wflStepPath);
                long processRrn = NumberUtils.toLong(wflStepArray[0]);
                if (processRrn <= 0) {
                    // Rework route has wflStepPath, but there is no process information
                    routeRrn = NumberUtils.toLong(wflStepArray[3]);
                    routeId = getInstanceId(routeRrn);
                    node.put("isRework", true);
                    // Rework routeVersion
                    node.put("routeVersion", NumberUtils.toInt(wflStepArray[4]));
                } else {
                    node.put("processRrn", processRrn);
                    node.put("processVersion", NumberUtils.toInt(wflStepArray[1]));
                }

                String operationSeq = StringUtils.substringBefore(treeNodes[2], "---");
                String operationId = StringUtils.substringAfter(treeNodes[2], "---");
                long operationRrn = NumberUtils.toLong(treeNodes[4], 0);

                node.put("stepPath", wflStepPath);
                node.put("routeSeq", routeSeq);
                node.put("operationSeq", operationSeq);
                node.put("operationRouteSeq", operationSeq);
                node.put("routeId", routeId);
                node.put("routeDesc", routeDesc);
                node.put("operationId", operationId);
                node.put("routeRrn", routeRrn);
                node.put("operationRrn", operationRrn);

                wflInfos.add(node);
            }
        }

        return wflInfos;
    }

    /**
     * 解析wflStepPath
     *
     * @param wflStepPath
     * @return String[] 0=processRrn,1=processVersion,2=routeStepRrn,3=routeRrn,4=routeVersion,
     * 5=operationStepRrn or 3=reworkRouteRrn, 4=reworkRouteVersion, 5=operationStepRrn
     */
    protected String[] parseWflStepPath(String wflStepPath) {
        /*
         * NORMAL: 5150602.8.5185744|5147265.3.5153854
         * (workFlowRrn.workFlowVersion.stepRrn|workFlowOrTaskRrn.workFlowVersion.stepRrn) ==
         * (processRrn.processVersion.routeStepRrn|routeRrn.routeVersion.operationStepRrn)
         */
        /*
         * REWORK: 5149828.1.5149836 (workFlowRrn.workFlowVersion.stepRrn) == (routeRrn.routeVersion
         * .operationStepRrn)
         */
        String[] result = new String[6];
        String[] wflInfo = StringUtils.split(wflStepPath, '|');

        if (wflInfo.length == 2) {
            String[] processInfo = StringUtils.split(wflInfo[0], '.');
            String[] routeInfo = StringUtils.split(wflInfo[1], '.');
            result = StringUtils.mergeStringArraysForNotCheckContains(processInfo, routeInfo);
        } else {
            String[] reworkWflInfo = StringUtils.split(wflInfo[0], '.');
            if (reworkWflInfo.length == 3) {
                result[3] = reworkWflInfo[0];
                result[4] = reworkWflInfo[1];
                result[5] = reworkWflInfo[2];
            }
        }

        return result;
    }

    /**
     * 获取页面显示的产品与物料的链接关系列表
     *
     * @param productRrn
     * @return
     */
    protected List<Map<String, String>> getProductAndMaterialRelationForShow(Long productRrn) {
        List<Relation> relations = baseService.getRelationsUseFromRrn(productRrn, LinkTypeList.PRODUCT_TO_MATERIAL_KEY);
        List<Map<String, String>> results = new ArrayList<>();
        Map<String, String> result;
        for (Relation relation : relations) {
            result = new HashMap<>();
            MaterialDO materialDO = new MaterialDO();
            materialDO.setInstanceRrn(relation.getToRrn());
            MaterialDO material = asmService.getMaterial(materialDO);
            result.put(AsmConst.MATERIAL_RRN, Long.toString(material.getInstanceRrn()));
            result.put(AsmConst.MATERIAL_ID, material.getInstanceId());
            result.put(AsmConst.MATERIAL_DESC, material.getInstanceDesc());
            result.put(AsmConst.DEFAULT_FLAG, relation.getAttributedata1());
            results.add(result);
        }
        return results;
    }

    protected void activateWithProcessScheduler(Long ecnRrn, boolean activateFlag) {
        String userId = LocalContext.getUserId();
        if (activateFlag) {
            //            ecnService.activateEcn(ecnRrn, userId);
            ProcessVersion pv = new ProcessVersion();
            pv.setEcnRrn(ecnRrn);
            prpService.activeteEcnByProcessVersion(pv, userId);
        }
        Date date = new Date();
        String jobName = "ECN" + date.getTime();
        Map jobData = new HashMap();
        jobData.put("ECN_RRN", ecnRrn + "");
        quartzOperateService.addJob(jobName, PROCESS_JOB_CLASS, "DEFAULT", new Date(date.getTime() + 1), 0, 0, jobData);
    }

    // protected void checkProcessPermission(String processId) {
    //     String dataPermissionFlag = LocalContext.get(DATA_PERMISSION_KEY);
    //     if (StringUtils.equals(dataPermissionFlag, "1") && StringUtils.isNotBlank(processId)) {
    //         ProcessPlanning processPlanning = new ProcessPlanning(processId, getNamedSpace(ObjectList.WFL_KEY,
    //                                                                                        LocalContext
    //                                                                                                .getFacilityRrn()),
    //                                                               ObjectList.WFL_KEY);
    //         ProcessPlanning newProcessPlanning = prpService.getProcessPlanning(processPlanning);
    //         if (null != newProcessPlanning) {
    //             String processRrnStr = LocalContext.get(PROCESS_RRN_KEY);
    //             Assert.isTrue(processRrnStr.contains(Long.toString(newProcessPlanning.getInstanceRrn())),
    //                           Errors.create().key(MessageIdList.PROCESS_NO_PERMISSION)
    //                                 .content("No permission to view the process!").build());
    //         }
    //     }
    // }


    /**
     * 检查当前用户是否有权限操作该流程
     *
     * @param processRrn 流程rrn
     */
    protected void checkPermissionForOperateProcess(long processRrn) {
        String processRrns = securityService.getProcessRrnWithPermission(LocalContext.getUserRrn());
        String dataPermissionFlag = LocalContext.get(DATA_PERMISSION_KEY);
        Assert.isFalse(StringUtils.equals(dataPermissionFlag, "1")
                               && !StringUtils.contains(processRrns, String.valueOf(processRrn)),
                Errors.create().key(MessageIdList.PROCESS_NO_PERMISSION_OPERATE)
                      .content("No permission to operate this process!").build());
    }

    /**
     * 验证流程是否被禁用
     **/
    protected void checkProcessDisabled(long processRrn) {
        Assert.isFalse(ON.equalsIgnoreCase(baseService.getNamedObjectDisableFlag(processRrn)),
                       Errors.create().key(MessageIdList.PROCESS_DISABLED).content("Process Disabled!").build());
    }

}