CheckPCDInfoAction.java

package com.mycim.webapp.actions.operation.run;

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.valueobject.MessageIdList;
import com.mycim.valueobject.consts.SessionNames;
import com.mycim.valueobject.ems.Carrier;
import com.mycim.valueobject.wip.Lot;
import com.mycim.webapp.actions.WipSetupAction;
import org.apache.commons.collections.MapUtils;
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.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

/**
 * 进出站校验pcd type 是否正确
 *
 * @author NC00022
 */
public final class CheckPCDInfoAction extends WipSetupAction {

    @Override
    public ActionForward perform(ActionMapping mapping, ActionForm form, HttpServletRequest request,
                                 HttpServletResponse response) throws Exception {

        HashMap parameters = (HashMap) request.getAttribute(SessionNames.PARAMETERSINFO_KEY);
        Assert.isFalse(parameters == null, Errors.create().content("Parameters are not enough!").build());

        return validateCarrierType(mapping, request, response);

    }

    public ActionForward validateCarrierType(ActionMapping mapping, HttpServletRequest request,
                                             HttpServletResponse response) throws Exception {
        Collection lots = (Collection) request.getAttribute(SessionNames.COLLECTION_KEY);
        HashMap parameters = (HashMap) request.getAttribute(SessionNames.PARAMETERSINFO_KEY);
        String actionPoint = MapUtils.getString(parameters, "actionPoint");
        Iterator it = lots.iterator();
        String lotId;
        Lot lot;

        while (it.hasNext()) {
            Map lotMap = (Map) it.next();
            lotId = MapUtils.getString(lotMap, "lotId");
            lot = lotQueryService.getLot(lotId, LocalContext.getFacilityRrn());
            Carrier carrier;
            String targetCarrierType;
            carrier = carrierService.getCarrier(lot.getCarrierRrn());

            targetCarrierType = carrierService.getTargetCarrierTypeByActionPoint(actionPoint, lot);

            Assert.isFalse(StringUtils.isEmpty(targetCarrierType),
                           Errors.create().key(MessageIdList.PROCESS_CARRIER_MUST_EMPTY)
                                 .content("Process location for  {}   cannot " + "be empty!").args(lot.getLotId())
                                 .build());

            Assert.isFalse(!StringUtils.equalsIgnoreCase(carrier.getObjectSubtype(), targetCarrierType) &&
                                   lot.getAutoSplitMergFlag() != 1,
                           Errors.create().key(MessageIdList.PROCESS_NOT_MATCH_CASSETTE)
                                 .content("Cassette type for {} not match, Please exchange Cassette!")
                                 .args(lot.getLotId()).build());

            carrierService.checkPcdIsValid(carrier.getInstanceRrn(), LocalContext.getFacilityRrn());

        }
        parameters.put(SessionNames.RUNSTEP_FLAG, "0");

        request.getRequestDispatcher(mapping.findForward("workflow").getPath()).forward(request, response);
        return null;
    }


}