SplitRunCardFetchStepAction.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.utils.lang.StringUtils;
import com.mycim.framework.utils.lang.collections.MapUtils;
import com.mycim.valueobject.ObjectList;
import com.mycim.valueobject.ems.Equipment;
import com.mycim.valueobject.runcard.util.RunCardConstants;
import com.mycim.valueobject.runcard.util.RunCardUtils;
import com.mycim.valueobject.wip.Lot;
import com.mycim.valueobject.wip.LotRunCardStore;
import com.mycim.valueobject.wip.LotStatus;
import com.mycim.valueobject.wip.SRCLotSpecialStep;
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 finatice.yang
 * @date 2021/5/10
 **/
public class SplitRunCardFetchStepAction extends RunCardAction {

    /**
     * Action 方法: init
     */
    @Override
    public ActionForward init(ActionMapping mapping, ActionForm form, HttpServletRequest request,
                              HttpServletResponse response) throws Exception {

        String lotId = WebUtils.getParameter("lotId", request);

        request.setAttribute("lotId", lotId);
        registerOptionType(LocalContext.getFacilityRrn(), Arrays.asList(new String[]{"LOTFUTURESTEPS"}), request);
        return mapping.findForward("init");
    }

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

        Lot lot = lotQueryService.getLot(lotId);
        if (lot != null && StringUtils.equals(lot.getLotStatus(), LotStatus.RUNCARD_HOLD)) {
            lot = lotQueryService.getLot(RunCardUtils.buildMainRcLotId(lot.getLotId()));
        }
        Assert.isFalse(lot == null || lot.getLotRrn() <= 0,
                       Errors.create().content("Not querying the relevant information.").args(lot.getLotStatus())
                             .build());

        Map<String, Object> lotBaseInfo = MapUtils.newHashMap();

        lotBaseInfo.put("lotId", lot.getLotId());
        if (StringUtils.endsWith(lot.getLotId(), RunCardConstants.MAINLOT_ID_IN_MES)) {
            lotBaseInfo.put("showLotId", StringUtils.substringBeforeLast(lot.getLotId(), "."));
        } else {
            lotBaseInfo.put("showLotId", lot.getLotId());
        }
        lotBaseInfo.put("productId", lot.getProductId());
        lotBaseInfo.put("lotType", lot.getLotType());

        lotBaseInfo.put("priority", lot.getHotFlag() + "-" + lot.getPriority());
        lotBaseInfo.put("lotRrn", lot.getLotRrn());

        Map<String, Object> returnMap = MapUtils.newHashMap();
        returnMap.put("lotBaseInfo", lotBaseInfo);
        return returnMap;
    }

    public Map<String, Object> queryDetail(Map<String, Object> params) {
        String lotId = MapUtils.getString(params, "lotId");
        Lot lot = lotQueryService.getLot(lotId);
        if (lot != null && StringUtils.equals(lot.getLotStatus(), LotStatus.RUNCARD_HOLD)) {
            lot = lotQueryService.getLot(RunCardUtils.buildMainRcLotId(lot.getLotId()));
        }
        Assert.isFalse(lot == null || lot.getLotRrn() <= 0,
                       Errors.create().content("Not querying the relevant information.").args(lot.getLotStatus())
                             .build());
        List<Map<String, Object>> fetchStepInfo = lotRunCardQueryService.queryFecthStepBySrc(lot.getLotRrn());

        Map<String, Object> returnMap = MapUtils.newHashMap();
        returnMap.put("rows", fetchStepInfo.size());
        returnMap.put("results", fetchStepInfo);
        return returnMap;
    }

    /*public ActionForward viewEqptList(ActionMapping mapping, ActionForm form, HttpServletRequest request,
                                      HttpServletResponse response) {


        HttpSession session = request.getSession(false);
        Long facilityRrn = (Long) session.getAttribute(SessionNames.FACILITY_KEY);

        Long lotRrn = WebUtils.getParameterLong("lotRrn", request);
        String operationId = handleStringNullOrUndefined(WebUtils.getParameter("operationId", request));
        int stepSequence = WebUtils.getParameterInt("stepSequence", request);
        String recipeId = handleStringNullOrUndefined(getParameter("recipeId", request));
        String entityId = handleStringNullOrUndefined(WebUtils.getParameter("entityId", request));
        String entityGroupId = handleStringNullOrUndefined(WebUtils.getParameter("entityGroupId", request));

            Lot lot = getLot(lotRrn);
            lot.setOperationId(operationId);
            lot.setRecipeId(recipeId);

            LotRunCardStore lotStore = lotService.getSplitRunCardLotStore(lotRrn);
            Long lotSpecialStepRrn = lotStore.getLotSpecialStepRrn();
            SRCLotSpecialStep lotSpecialStep = getLotManager().getLotSplitRunCardSpecialStep(lotSpecialStepRrn,
                                                                                             stepSequence);

            InputObject inputObject = new InputObject();
            inputObject.setFacilityRrn(facilityRrn);
            inputObject.setLot(lot);
            inputObject.setRecipeId(recipeId);

            List<Map<String, Object>> availableEquipmentInfos = new ArrayList<Map<String, Object>>();

            if (StringUtils.isNotEmpty(entityId)) {
                long equipmenRrn = getInstanceRrn(entityId, getNamedSpace(ObjectList.ENTITY_KEY, facilityRrn),
                                                  ObjectList.ENTITY_KEY);

                Equipment equipment = emsService.getEquipment(equipmenRrn);

                Map<String, Object> equipmentInfo = new HashMap<String, Object>();
                equipmentInfo.put("equipmentId", entityId);
                equipmentInfo.put("equipmentDesc", equipment.getInstanceDesc());
                equipmentInfo.put("equipmentRrn", equipmenRrn);
                // check equipment status
                String equipmenStatus = getEntityCurrentStatus(equipmenRrn);
                equipmentInfo.put("equipmentStatus", equipmenStatus);
                if (StringUtils.equalsIgnoreCase(equipmenStatus, EventName.IDLE)
                        || StringUtils.equalsIgnoreCase(equipmenStatus, EventName.RUN)) {
                    equipmentInfo.put("equipmentAvailable", "AVAILABLE");
                } else {
                    equipmentInfo.put("equipmentAvailable", "NOT_AVAILABLE");
                }

                // start: 检查批次在当前设备是否有constrain
                ErrorMsg errorMsg = getLotManager().checkLotConstrain(equipment, lot, facilityRrn);
                boolean overrideConstrain = isOverrideConstrain(lot);
                if (overrideConstrain) {
                    errorMsg.setError(false);
                    errorMsg.setErrorMsg("OK");
                } else {
                    equipmentInfo.put("equipmentConstrain", new Boolean(errorMsg.getError()));
                }
                // check recipe
                inputObject.setEquipment(equipment);
                String meg = recipeCheckService.checkHasAvailableDispatchRecipeByRuncard(inputObject, lotSpecialStep,
                                                                                         new LotDispatchQty(lot));
                equipmentInfo.put("checkEqptRecipeAvailable", StringUtils.isEmpty(meg));

                availableEquipmentInfos.add(equipmentInfo);
            } else if (StringUtils.isNotEmpty(entityGroupId)) {
                long entityGroupRrn = getInstanceRrn(entityGroupId, facilityRrn, ObjectList.ENTITYGROUP_KEY);
                Collection eqptRelations = getEmsManager().getEntities4CSEC(entityGroupRrn);

                for (Iterator it = eqptRelations.iterator(); it.hasNext();) {
                    Relation eqptRelation = (Relation) it.next();
                    String equipmentId = eqptRelation.getInstanceId();
                    String equipmentDesc = eqptRelation.getInstanceDesc();
                    long equipmenRrn = eqptRelation.getInstanceRrn();

                    Equipment equipment = emsService.getEquipment(equipmenRrn);

                    Map<String, Object> equipmentInfo = new HashMap<String, Object>();
                    equipmentInfo.put("equipmentId", equipmentId);
                    equipmentInfo.put("equipmentDesc", equipmentDesc);
                    equipmentInfo.put("equipmentRrn", equipmenRrn);
                    // check equipment status
                    String equipmenStatus = getEntityCurrentStatus(equipmenRrn);
                    equipmentInfo.put("equipmentStatus", equipmenStatus);
                    if (StringUtils.equalsIgnoreCase(equipmenStatus, EventName.IDLE)
                            || StringUtils.equalsIgnoreCase(equipmenStatus, EventName.RUN)) {
                        equipmentInfo.put("equipmentAvailable", "AVAILABLE");
                    } else {
                        equipmentInfo.put("equipmentAvailable", "NOT_AVAILABLE");
                    }

                    // start: 检查批次在当前设备是否有constrain
                    ErrorMsg errorMsg = getLotManager().checkLotConstrain(equipment, lot, facilityRrn);
                    boolean overrideConstrain = isOverrideConstrain(lot);
                    if (overrideConstrain) {
                        errorMsg.setError(false);
                        errorMsg.setErrorMsg("OK");
                    } else {
                        equipmentInfo.put("equipmentConstrain", new Boolean(errorMsg.getError()));
                    }
                    // check recipe
                    inputObject.setEquipment(equipment);
                    String meg = recipeCheckService.checkHasAvailableDispatchRecipeByRuncard(inputObject,
                                                                                             lotSpecialStep,
                                                                                             new LotDispatchQty(lot));
                    equipmentInfo.put("checkEqptRecipeAvailable", StringUtils.isEmpty(meg));

                    availableEquipmentInfos.add(equipmentInfo);
                }
            }
            request.setAttribute("lotRrn", WebUtils.getParameter("lotRrn", request));
            request.setAttribute("availableEquipmentInfos", availableEquipmentInfos);
            request.setAttribute("operationId", handleStringNullOrUndefined(operationId));
            request.setAttribute("recipeId", handleStringNullOrUndefined(recipeId));
            request.setAttribute("stageId", handleStringNullOrUndefined(getParameter("stageId", request)));
            request.setAttribute("entityGroupId", handleStringNullOrUndefined(entityGroupId));
            request.setAttribute("entityId", handleStringNullOrUndefined(getParameter("entityId", request)));
            request.setAttribute("rectileFamilyId",
                                 handleStringNullOrUndefined(getParameter("rectileFamilyId", request)));
            request.setAttribute("reticleId", handleStringNullOrUndefined(getParameter("reticleId", request)));
            request.setAttribute("pollutionLevel", handleStringNullOrUndefined(getParameter("pollutionLevel",
            request)));
            request.setAttribute("stepType", handleStringNullOrUndefined(getParameter("stepType", request)));
            request.setAttribute("rcFlag", "1");

            return mapping.findForward("eqptlist");
    }*/
}