SplitRunCardLotAction.java

package com.mycim.webapp.actions.splitruncardlot;

import com.fa.sesa.exception.Assert;
import com.fa.sesa.exception.Errors;
import com.fa.sesa.threadlocal.LocalContext;
import com.mycim.framework.jdbc.Page;
import com.mycim.framework.utils.beans.BeanUtils;
import com.mycim.framework.utils.lang.StringUtils;
import com.mycim.framework.utils.lang.collections.CollectionUtils;
import com.mycim.framework.utils.lang.collections.MapUtils;
import com.mycim.framework.utils.lang.time.DateUtils;
import com.mycim.valueobject.ObjectList;
import com.mycim.valueobject.bas.ErrorMsg;
import com.mycim.valueobject.bas.Relation;
import com.mycim.valueobject.consts.*;
import com.mycim.valueobject.ems.Entity;
import com.mycim.valueobject.ems.Equipment;
import com.mycim.valueobject.runcard.util.RunCardConstants;
import com.mycim.valueobject.runcard.util.RunCardStoreSubStatus;
import com.mycim.valueobject.spc.RunCardRawDataInfo;
import com.mycim.valueobject.sys.ReferenceFileDetail;
import com.mycim.valueobject.wip.*;
import com.mycim.webapp.TemplateLocation;
import com.mycim.webapp.WebUtils;
import com.mycim.webapp.actions.RunCardAction;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.*;

/**
 * @author pinyan.song
 * @version 6.0.0
 * @date 2020-1-7 10:56
 **/
public class SplitRunCardLotAction extends RunCardAction {
    private static final String AUTO="AUTO";

    /**
     * Action 方法: init
     */
    @Override
    public ActionForward init(ActionMapping mapping, ActionForm form, HttpServletRequest request,
                              HttpServletResponse response) throws Exception {
        long processRrn = getInstanceRrn(RunCardConstants.SRC_PROCESS_ID, LocalContext.getFacilityRrn(),
                                         ObjectList.WFL_KEY);
        if (processRrn <= 0) {
            Map<String, Object> returnMap = runCardExecService.buildSRCProcess();
            invokeProcessScheduler(MapUtils.getLongValue(returnMap, "routeEcnRrn"));
            invokeProcessScheduler(MapUtils.getLongValue(returnMap, "processEcnRrn"));
        }
        return showSRCLotInfo(mapping, form, request, response);
    }

    /**
     * Action 方法: repositionStep
     */
    public void repositionStep(Map<String, Object> params) throws Exception {
        String lotId = MapUtils.getString(params, "lotId");
        Lot lot = lotQueryService.getLot(lotId);
        Assert.isTrue(StringUtils.equals(LotStatus.WAITING, lot.getLotStatus()) ||
                              StringUtils.equals(LotStatus.RUNCARD_WAITSPLIT, lot.getLotStatus()),
                      Errors.create().content("Lot status is :{}").args(lot.getLotStatus()).build());
        lotRunCardService.outSplitRuncard(lot.getLotRrn(), null, LocalContext.getUserId());
        //  doCloseRunCard(lot);
    }

    /**
     * Action 方法: runcardHistoryPage
     **/
    public ActionForward runcardHistoryPage(ActionMapping mapping, ActionForm form, HttpServletRequest request,
                                            HttpServletResponse response) {
        String lotId = request.getParameter("lotId");
        if (StringUtils.isNotBlank(lotId)) {
            // Map<String, Object> lotInfoMap = lotRunCardQueryService.getRCLotInfoMap(lotId);
            // request.setAttribute("lotInfo", lotInfoMap);
            request.setAttribute("fromUrlFlag", "1");
            getRuncardHistory(mapping, form, request, response);
        } else {
            request.setAttribute("fromUrlFlag", "0");
        }

        return mapping.findForward("runcardhistory");
    }

    /**
     * Action 方法: exportHistory
     **/
    public ActionForward exportHistory(ActionMapping mapping, ActionForm form, HttpServletRequest request,
                                       HttpServletResponse response) throws Exception {
        Map<String, Object> titles = WebUtils.getExportTitles(request);
        Lot lot = lotQueryService.getLot(request.getParameter("lotId"));
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("lotRrn", lot.getLotRrn());
        List<Map<String, Object>> list = lotRunCardQueryService.qryRuncardLotTransHistory(map, 1, 99999);
        for (Map<String, Object> m : list) {
            m.put("priority2", m.get("hotFlag") + "-" + m.get("priority"));
        }
        titles.put("title", "Lot Runcard Transaction History");
        titles.put("lot_value", "Lot Id:" + lot.getLotId());
        titles.put("qty_value", "Qty:" + lot.getQty1());
        titles.put("product_value", "Product Id:" + lot.getProductId());
        // 导出
        String exportDateTime = DateUtils.getNowTime(DateUtils.DATE_FORMAT4NOSPLICING);
        String fileName = "LotTransHist" + exportDateTime + ".xlsx";
        WebUtils.exportExcel(fileName, titles, list, TemplateLocation.LOT_RUNCARD_TRANS_HIST, response);

        return WebUtils.NULLActionForward;
    }

    public ActionForward outSplitRuncard(ActionMapping mapping, ActionForm form, HttpServletRequest request,
                                         HttpServletResponse response) {
        Long facilityRrn = LocalContext.getFacilityRrn();
        String lotId = request.getParameter("lotId");
        if (StringUtils.isBlank(lotId)) {
            lotId = (String) request.getAttribute("lotId");
        }

        Long lotRrn = lotInqService.getLotRrn(lotId);
        RunCardLotInfo lotInfo = runCardLotInqService.getRunCardLotInfo(lotRrn);
        // 卡控是否存在sort job
        this.checkWaitJobs(lotInfo.getCarrierRrn(), 0L, 0L, null);
        boolean noMergeStepFlag = false;
        if (lotRrn != null) {
            //check merge step 是否还存在于main lot 中
            if (lotRunCardService.checkLotNotHasMergeStep(lotRrn)) {
                String mainLotId = lotInfo.getMainLotId();
                Long mainLotRrn = lotInqService.getLotRrn(mainLotId);
                if (mainLotRrn != null) {
                    Lot mainLot = lotInqService.getLot(mainLotRrn);
                    noMergeStepFlag = true;
                    request.setAttribute("targetProductId", mainLot.getProductId());
                    request.setAttribute("targetProcessId", mainLot.getProcessId());
                    request.setAttribute("targetProcessVersion", mainLot.getProcessVersion());
                }
            }
        }
        request.setAttribute("noMergeStepFlag", noMergeStepFlag);
        request.setAttribute("lotInfo", lotInfo);

        return mapping.findForward("outruncard");
    }

    public Map<String, Object> getRptInfo(Map params) {
        String lotId = MapUtils.getString(params, "lotId");
        Long runCardRrn = MapUtils.getLong(params, "runCardRrn");
        Map lotStepInfo = lotRunCardQueryService.getRCLotStepInfo(lotId, runCardRrn);
        Assert.notNull(lotStepInfo, Errors.create().content("No lot information found!").build());
        //获取报表服务器地址
        //Facility facility = sysService.getFacility(LocalContext.getFacilityRrn());
        //String   rptServer = facility.getRptServer();
        String rpt = getRptUrl4PrintRCLotFlow();
        lotStepInfo.put("prtServer", rpt);
        lotStepInfo.put("lotId", lotId);//改用showLotId
        return lotStepInfo;
    }

    public void checkIfHasRCOutStep(Map<String, Object> params) {
        String lotId = MapUtils.getString(params, "lotId");

        String errorMsg = lotRunCardService.checkIfCanDoFinishRunCardAndReturnToSpecifiedStep(lotId);

        Assert.isFalse(StringUtils.isNotBlank(errorMsg), Errors.create().content(errorMsg).build());
    }

    public void updateLotRunCardForFinish(Map params) {
        String lotId = MapUtils.getString(params, "lotId");

        LotRunCardStore store = lotRunCardQueryService.getSplitRunCardLotStore(lotQueryService.getLotRrn(lotId));
        runCardService.updateLotRunCardForMergeStep(store.getRuncardId(), LocalContext.getUserId(), params);
    }

    private void getRuncardHistory(ActionMapping mapping, ActionForm form, HttpServletRequest request,
                                   HttpServletResponse response) {
        String lotId = request.getParameter("lotId");
        long thisPage = WebUtils.getThisPage(request);
        long pageSize = WebUtils.getPageSize(request);

        Long lotRrn = lotInqService.getLotRrn(lotId);
        RunCardLotInfo lotInfo = runCardLotInqService.getRunCardLotInfo(lotRrn);
        // Map<String, Object> lotInfoMap = lotRunCardQueryService.getRCLotInfoMap(lotId);
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("lotRrn", lotRrn);

        Page page = new Page(thisPage,pageSize);
        page = lotRunCardQueryService.qryRuncardLotTransHistory(page, lotRrn);
        List<Map> results = (List<Map>) page.getResults();
        for (Map result : results) {
            String transModule=MapUtils.getString(result,"transModule");
            if (StringUtils.isNotBlank(transModule)&&AUTO.equals(transModule)){
                String transPerformedBy = MapUtils.getString(result, "trans_performed_by") + "(" + transModule + ")";
                result.put("trans_performed_by", transPerformedBy);
            }
        }

        request.setAttribute("thisPage", page.getPageNo());
        request.setAttribute("maxPage", page.getTotalPages());
        if(page.isFirstPage()) {
            request.setAttribute("isFirstPage", "1");
        }
        if(page.isLastPage()) {
            request.setAttribute("isLastPage", "1");
        }

        List<Map<String, Object>> list = (List<Map<String, Object>>) page.getResults();

        LotRunCardStore store = lotRunCardQueryService.getSplitRunCardLotStore(lotRrn);
        for (Map<String, Object> transHistory : list) {
            if (StringUtils
                    .equalsIgnoreCase(TransactionNames.MOVEOUT_KEY, MapUtils.getString(transHistory, "trans_id"))) {
                List<RunCardRawDataInfo> rawDatas = edcChartService
                        .getRunCardRawDataInfoList(lotRrn, MapUtils.getLong(transHistory, "stepSequence"));

                StringBuilder dataValues = new StringBuilder();
                for (RunCardRawDataInfo rawData : rawDatas) {
                    dataValues.append(rawData.getUnitId() + "[" + rawData.getParameterId() + "]" +
                                              rawData.getDataValues());
                    dataValues.append("<br>");
                }
                transHistory.put("edcPlan", dataValues.toString());
            }
            Long qty_1 = MapUtils.getLongValue(transHistory, "qty_1",0);
            if(qty_1!=null){
                transHistory.put("qty_1",qty_1);
            }
            Long qty_2 = MapUtils.getLongValue(transHistory, "qty_2",0);
            if(qty_2!=null){
                transHistory.put("qty_2",qty_2);
            }
            if (StringUtils.isBlank(MapUtils.getString(transHistory,"carrierId"))){
                transHistory.put("carrierId", store.getCarrierId());
            }
        }
        request.setAttribute("fromUrlFlag", request.getParameter("fromUrlFlag"));
        request.setAttribute("transHistoryList", list);
        request.setAttribute("lotInfoMap", lotInfo);
        request.setAttribute("lotInfo", lotInfo);
    }


    private ActionForward showSRCLotInfo(ActionMapping mapping, ActionForm form, HttpServletRequest request,
                                         HttpServletResponse response) {

        String lotId = StringUtils.isEmpty(request.getParameter("lotId")) ? StringUtils
                .toString(request.getAttribute("lotId")) : request.getParameter("lotId");
        if (StringUtils.isBlank(lotId)) {
            lotId = (String) request.getAttribute("lotId");
        }
        Lot lot = lotInqService.getLot(lotId);

        RunCardLotInfo runCardLotInfo = runCardLotInqService.getRunCardLotInfo(lot.getLotRrn());
        Assert.state(Objects.nonNull(runCardLotInfo), Errors.create().content("LotRunCardStore is null!").build());

        LotRunCard lotRunCard = lotRunCardQueryService.getLotRunCard(runCardLotInfo.getRunCardRrn());

        String subStatus = runCardLotInfo.getSubStatus();

        if (StringUtils.equals(RunCardStoreSubStatus.BANKIN.toString(), subStatus)) {
            if (lot.getEqptRrn() != null && lot.getEqptRrn() > 0) {
                long eqptRrn = lot.getEqptRrn();
                List<Map<String, Object>> availableEquipmentInfos = new ArrayList<>();
                availableEquipmentInfos.add(getAvailableEquipmentInfo(eqptRrn, lot, runCardLotInfo.getRecipeId()));
                request.setAttribute("availableEquipmentInfos", availableEquipmentInfos);
            } else {
                request.setAttribute("canSplit", "1");

                List<Map<String, Object>> allSplitedList = lotRunCardQueryService
                        .getRunCardLotsByRuncardRrn(runCardLotInfo.getRunCardRrn());
                if (allSplitedList != null && allSplitedList.size() == 1) {
                    request.setAttribute("removeRuncard", "1");
                    request.setAttribute("disableFinish", "1");
                }
            }
        } else if (StringUtils.equalsIgnoreCase(RunCardStoreSubStatus.SPLIT.toString(), subStatus)) {
            LotRunCardStep lotRunCardStep = runCardLotInqService.getLotRunCardStep(lot.getLotRrn());
            if (lotRunCardStep != null) {
                List<Long> eqptRrns = new ArrayList<Long>();
                String recipeId = "";
                if (lot.getEqptRrn() != null && lot.getEqptRrn() > 0) {
                    eqptRrns.add(lot.getEqptRrn());
                    recipeId = lot.getRecipePhysicalId();
                    if (lot.getReticleRrn() != null && lot.getReticleRrn() > 0) {
                        List<Map<String, Object>> inuseReticleInfoList = wipService
                                .buildInuseReticleInfoList(lot.getReticleRrn());
                        if (CollectionUtils.isNotEmpty(inuseReticleInfoList)) {
                            request.setAttribute("availableReticleInfos", inuseReticleInfoList);
                        }
                    }
                } else if(LotStatus.isCanHold(lot.getLotStatus())) {
                    if (lotRunCardStep.getEquipmentRrn() != null && lotRunCardStep.getEquipmentRrn() > 0) {
                        eqptRrns.add(lotRunCardStep.getEquipmentRrn());
                    } else {
                        long eqptGroupRrn = lotRunCardStep.getEquipmentGroupRrn();
                        List<Entity> eqptList = emsService.getEntitiesFromEntityToEntityGroup(eqptGroupRrn);
                        for (Object obj : eqptList) {
                            Entity entity = (Entity) obj;
                            eqptRrns.add(entity.getInstanceRrn());
                        }
                    }
                    recipeId = lotRunCardStep.getRecipeId();
                }

                List<Map<String, Object>> availableEquipmentInfos = new ArrayList<>();
                for (Long eqptRrn : eqptRrns) {
                    availableEquipmentInfos.add(getAvailableEquipmentInfo(eqptRrn, lot, recipeId));
                }
                request.setAttribute("availableEquipmentInfos", availableEquipmentInfos);

                List<Map<String, Object>> reticelInfos = new ArrayList<Map<String, Object>>();
                if (lotRunCardStep.getReticleRrn() != null && lotRunCardStep.getReticleRrn() > 0) {
                    reticelInfos.addAll(wipService.buildInuseReticleInfoList(lotRunCardStep.getReticleRrn()));
                } else if (lotRunCardStep.getReticleGroupRrn() != null && lotRunCardStep.getReticleGroupRrn() > 0) {
                    List<Relation> reticles = wipService
                            .getReticlesForMovein(lotRunCardStep.getReticleGroupRrn(), 0, false);
                    for (Relation relation : reticles) {
                        reticelInfos.addAll(wipService.buildInuseReticleInfoList(relation.getInstanceRrn()));
                    }
                }
                if (CollectionUtils.isNotEmpty(reticelInfos)) {
                    request.setAttribute("availableReticleInfos", reticelInfos);
                }
            }

            if (runCardLotInfo.getStepSequence() != null && runCardLotInfo.getStepSequence().intValue() == 1) {
                if (LotStatus.isCanHold(lot.getLotStatus())) {
                    List<Map<String, Object>> allSplitedList = lotRunCardQueryService
                            .getRunCardLotsByRuncardRrn(runCardLotInfo.getRunCardRrn());
                    if (allSplitedList != null && allSplitedList.size() == 1) {
                        request.setAttribute("removeRuncard", "1");
                        request.setAttribute("disableFinish", "1");
                    }
                }
            }

            if (lotRunCard != null && !StringUtils.equals(VersionStatus.CLOSED_KEY, lotRunCard.getStatus())) {
                request.setAttribute("finishRuncard", "1");
            }
        } else if (StringUtils.equalsIgnoreCase(RunCardStoreSubStatus.FINISH.toString(), subStatus)) {
            LotRunCardStep lotRunCardStep = runCardLotInqService.getLotRunCardStep(lot.getLotRrn());

            List<Map<String, Object>> allSplitedList = lotRunCardQueryService
                    .getRunCardLotsByRuncardRrn(runCardLotInfo.getRunCardRrn());
            List<LotRunCardSplit> splitSet = lotRunCardQueryService.getLotRunCardSplit(runCardLotInfo.getRunCardRrn());

            if (LotStatus.isRunCardWaitMerge(lot.getLotStatus())) {
                request.setAttribute("canMerge", "1");
            }

            if (allSplitedList != null && allSplitedList.size() == 1) {
                if (StringUtils.equalsIgnoreCase(LotStatus.RUNCARD_FINISH, lot.getLotStatus()) &&
                        Objects.isNull(lotRunCardStep)) {
                    request.setAttribute("removeRuncard", "1");
                    request.setAttribute("disableFinish", "1");
                }
            }

            if (splitSet != null && splitSet.size() == 1) {
                List<LotRunCardStep> stepList = lotRunCardQueryService
                        .getLotRunCardStepList(runCardLotInfo.getRunCardRrn(), splitSet.get(0).getSplitSeq());

                for (int i = 0; i < stepList.size(); i++) {
                    LotRunCardStep step = stepList.get(i);
                    if (StringUtils.equalsIgnoreCase("DUMMY", step.getStepType())) {
                        request.setAttribute("removeRuncard", "1");
                    }
                }
            }

            // String canFinish = lotRuncardService.checkUserSpecialFinishRuncard(user, facilityRrn);
            if (!StringUtils.equals(VersionStatus.CLOSED_KEY, lotRunCard.getStatus()) ||
                    StringUtils.equals(LotStatus.RUNCARD_WAITFINISH, lot.getLotStatus())) {
                request.setAttribute("finishRuncard", "1");
            }
        } else if (StringUtils.equalsIgnoreCase(RunCardStoreSubStatus.AUTO.toString(), subStatus)) {
            LotRunCard runcard = lotRunCardQueryService.getOuterInfo(lot.getLotRrn());
            String repositionStepInfo = "Follow RC Set skip to " + runcard.getMergeFlowSeq();
            request.setAttribute("repositionStepInfo", repositionStepInfo);
            request.setAttribute("autoFinish", "1");
            request.setAttribute("removeRuncard", "1");
        } else if (StringUtils.equalsIgnoreCase(RunCardStoreSubStatus.BANKOUT.toString(), subStatus)) {
            request.setAttribute("onlyView", "1");
        } else {
            request.setAttribute("onlyView", "1");
        }

        if (StringUtils.equalsIgnoreCase(LotStatus.HOLD, lot.getLotStatus()) ||
                StringUtils.equalsIgnoreCase(LotStatus.RUNNINGHOLD, lot.getLotStatus())) {
            List<Map> holdReasons = lotQueryService.getHoldReasons(lot.getLotRrn());
            request.setAttribute("holdReasons", holdReasons);
        }

        Lot mainLot = lotInqService.getLot(runCardLotInfo.getMainLotId());

        if (mainLot != null && mainLot.getLotRrn() > 0) {
            List<Map> holdReasons = lotQueryService.getHoldReasons(mainLot.getLotRrn());
            for (Map reason : holdReasons) {
                String reasonCode = MapUtils.getString(reason, "reasonCode");
                if (!(StringUtils.containsIgnoreCase(reasonCode, "SRCHOLD") ||
                        StringUtils.containsIgnoreCase(reasonCode, "RRCHOLD"))) {
                    request.setAttribute("onlyView", "1");
                    break;
                }
            }
        }

        long runCardRrn = runCardLotInfo.getRunCardRrn();
        LotRecoveryRunCard recoveryRunCard = lotRunCardQueryService.getLotRecoveryRunCard(runCardRrn);
        if (recoveryRunCard != null &&
                !StringUtils.equalsIgnoreCase(RunCardStoreSubStatus.BANKOUT.toString(), subStatus)) {
            String runcardAction = recoveryRunCard.getRunCardAction();
            if (StringUtils.equalsIgnoreCase("CANCELTRACKIN", runcardAction)) {
                request.setAttribute("onlyCancelMoveIn", "1");
            } else if (StringUtils.equalsIgnoreCase("TRACKOUT", runcardAction)) {
                List<Map<String, Object>> moveOutEqptList = new ArrayList<Map<String, Object>>();

                Map<String, Object> equipmentInfo = buildEquipInfoForLot(mainLot);
                moveOutEqptList.add(equipmentInfo);

                request.setAttribute("moveOutEqptList", moveOutEqptList);
                request.setAttribute("onlyMoveOut", "1");
                request.setAttribute("removeRuncard", "1");
            }
        }

        if (recoveryRunCard != null) {
            request.setAttribute("portalType", "RECOVERYRUNCARD");
        } else {
            request.setAttribute("portalType", "SPLITRUNCARD");
        }


        request.setAttribute("lotInfo", runCardLotInfo);
        request.setAttribute("recipeId", runCardLotInfo.getRecipeId());
        if (StringUtils.isNotBlank(request.getParameter("lotPorTalFlag"))) {
            request.setAttribute("lotPorTalFlag", "1");
            request.setAttribute("availableEquipmentInfos", null);
        }
        // TimeLimitStatus And TimeLimitSetup Info List
        List<Map<String, String>> timelimits = wipCheckService.getLotTimeLimitInfo(lot.getLotRrn());
        request.setAttribute("TIMELIMITS", timelimits);
        return mapping.findForward("lotInfo");
    }

    private Map<String, Object> buildEquipInfoForLot(Lot lot) {
        Map<String, Object> equipmentInfo = new HashMap<String, Object>();
        if (lot.getEqptRrn() != null) {
            String lotStatus = lot.getLotStatus();

            long equipmenRrn = lot.getEqptRrn();

            Entity equipment = new Equipment();
            equipment.setInstanceRrn(equipmenRrn);
            equipment = emsService.getEntity(equipment);
            String equipmentId = equipment.getInstanceId();

            equipmentInfo.put("equipmentId", equipmentId);
            equipmentInfo.put("equipmentDesc", equipment.getInstanceDesc());
            equipmentInfo.put("operationMode", equipment.getOperationMode());

            // check equipment status
            String equipmenStatus = emsService.getEntityCurrentStatus(equipmenRrn);
            equipmentInfo.put("equipmentStatus", equipmenStatus);
            if (equipmenStatus != null &&
                    (equipmenStatus.equals(EventName.DOWN) || equipmenStatus.equals(EventName.OFF) ||
                            equipmenStatus.equals(EventName.FACD)) &&
                    !((StringUtils.equals(lotStatus, LotStatus.RUNNING) ||
                            StringUtils.equals(lotStatus, LotStatus.DISPATCH) ||
                            StringUtils.equals(lotStatus, LotStatus.PROCESSED)) &&
                            StringUtils.equalsIgnoreCase(equipmenStatus, EventName.DOWN))) {
                equipmentInfo.put("equipmentAvailable", "NOT_AVAILABLE");
            } else {
                equipmentInfo.put("equipmentAvailable", "AVAILABLE");
            }
            // start: 检查批次在当前设备是否有constrain
            equipmentInfo.put("equipmentConstrain", "USED");

            equipmentInfo.put("checkEqptAvailable", Boolean.TRUE);
        }
        return equipmentInfo;
    }

    private Map<String, Object> getAvailableEquipmentInfo(long eqptRrn, Lot lot, String recipeId) {

        Entity entity = emsService.getEntity(new Entity(eqptRrn));
        String eqptId = entity.getInstanceId();
        String eqptDesc = entity.getInstanceDesc();

        Equipment eqpt = new Equipment();
        eqpt.setInstanceId(eqptId);
        eqpt.setInstanceRrn(eqptRrn);
        eqpt = emsService.getEquipment(eqpt);

        Map<String, Object> equipmentInfo = new HashMap<>();
        equipmentInfo.put("equipmentId", eqptId);
        equipmentInfo.put("equipmentDesc", eqptDesc);
        equipmentInfo.put("equipmentRrn", eqptRrn);

        String eqptStatus = emsService.getEntityCurrentStatus(eqptRrn);
        equipmentInfo.put("equipmentStatus", eqptStatus);

        if (wipCheckService.checkEqptStatusAvailable(lot, eqpt)) {
            equipmentInfo.put("equipmentAvailable", "AVAILABLE");
        } else {
            equipmentInfo.put("equipmentAvailable", "NOT_AVAILABLE");
        }

        // start: 检查批次在当前设备是否有constrain
        ErrorMsg errorMsg = constrainService.checkLotConstrain(eqpt, lot);
        boolean overrideConstrain = wipCheckService.isOverrideConstrain(lot);
        if (overrideConstrain) {
            errorMsg.setError(false);
            errorMsg.setErrorMsg("OK");
        }
        equipmentInfo.put("equipmentConstrain", errorMsg.getError());
        // check recipe
        List<Map<String, Object>> equipmentRecipes = recipeService.getRecipeList4Equipment(eqptRrn);
        boolean checkEqptRecipeAvailable = checkEqptRecipeAvailable(equipmentRecipes, recipeId);
        long recipeRrn = getInstanceRrn(recipeId, LocalContext.getFacilityRrn(), ObjectList.RECIPE_KEY);
        if (recipeRrn <= 0) {
            checkEqptRecipeAvailable = true;
        }
        equipmentInfo.put("checkEqptRecipeAvailable", checkEqptRecipeAvailable);
        return equipmentInfo;
    }

    private String getRptUrl4PrintRCLotFlow() {
        String rptUrl = "";
        String refId = ReferenceDetailNames.RPT_URL_4RC_FLOW;
        List<ReferenceFileDetail> details = sysService.getRefFileValues(refId, LocalContext.getFacilityRrn());
        if (CollectionUtils.isNotEmpty(details)) {
            rptUrl = StringUtils.trim(details.get(0).getData1Value());
        }
        Assert.isFalse(StringUtils.isEmpty(rptUrl),
                       Errors.create().content("Please configure the report url at the data1Value of ReferenceFile: {}")
                             .args(refId).build());
        return rptUrl;
    }

}