SapphireValidateAction.java

package com.mycim.webapp.actions.lot.lotbondinginfo;

import com.fa.sesa.exception.Assert;
import com.fa.sesa.exception.Errors;
import com.fa.sesa.threadlocal.LocalContext;
import com.mycim.framework.utils.lang.collections.MapUtils;
import com.mycim.valueobject.consts.SessionNames;
import com.mycim.valueobject.wip.BondingMapping;
import com.mycim.valueobject.wip.Job;
import com.mycim.webapp.WebUtils;
import com.mycim.webapp.actions.WipSetupAction;
import com.mycim.webapp.forms.lot.LotInfoForm;
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.*;

/**
 * bonding标记后 wfl要走的Action
 *
 * @author yanbing.chen
 * @version 6.0.0
 * @date 2019/12/6
 **/
public class SapphireValidateAction extends WipSetupAction {

    @Override
    public ActionForward init(ActionMapping mapping, ActionForm form, HttpServletRequest request,
                              HttpServletResponse response) throws Exception {
        LotInfoForm theform = (LotInfoForm) form;
        //HashMap parameters = (HashMap) session.getAttribute(SessionNames.PARAMETERSINFO_KEY);
        HashMap parameters = (HashMap) request.getAttribute(SessionNames.PARAMETERSINFO_KEY);
        if (parameters == null && theform.getCacheParametersInfo() != null) {
            parameters = (HashMap) WebUtils.getCacheString2Obj(theform.getCacheParametersInfo());
            request.setAttribute(SessionNames.PARAMETERSINFO_KEY, parameters);
        }
        Job job = (Job) request.getAttribute(SessionNames.JOB_KEY);
        if (job == null && theform.getCacheJob() != null) {
            job = (Job) WebUtils.getCacheString2Obj(theform.getCacheJob());
            request.setAttribute(SessionNames.JOB_KEY, job);
        }
        Collection lots = (Collection) request.getAttribute(SessionNames.COLLECTION_KEY);
        if (lots == null && theform.getCacheCollection() != null) {
            lots = (Collection) WebUtils.getCacheString2Obj(theform.getCacheCollection());
            request.setAttribute(SessionNames.COLLECTION_KEY, lots);
        }

        if (parameters != null) {
            parameters.put(SessionNames.RUNSTEP_FLAG, "1");// 防止绕过此action
        }
        return buildBondingMapping(request, mapping, response, theform);
    }

    public ActionForward next(HttpServletRequest request, ActionMapping mapping, ActionForm form,
                              HttpServletResponse response) throws Exception {
        LotInfoForm theform = (LotInfoForm) form;
        long facilityRrn = LocalContext.getFacilityRrn();
        HashMap parameters = (HashMap) WebUtils.getCacheString2Obj(theform.getCacheParametersInfo());

        Collection lots = (Collection) WebUtils.getCacheString2Obj(theform.getCacheCollection());
        int bondingUnitsSize = WebUtils.getParameterInt("bondingUnitsSize", request);
        String automovein = WebUtils.getParameter("automovein", request);
        // 页面获取晶圆bonding关系
        Map<Long, Long> targetUnitSourceUnitMapping = new HashMap<Long, Long>();
        for (int i = 0; i < bondingUnitsSize; i++) {
            Long targetUnitRrn = wipQueryService
                    .getUnit(facilityRrn, WebUtils.getParameter("targetUnitId" + i, request)).getUnitRrn();
            Long sourceUnitRrn = wipQueryService
                    .getUnit(facilityRrn, WebUtils.getParameter("sourceUnitId" + i, request)).getUnitRrn();
            Assert.isFalse(targetUnitRrn == null || targetUnitRrn < 1,
                           Errors.create().content("The Wafer {} does not " + "exist !")
                                 .args(WebUtils.getParameter("targetUnitId" + i, request)).build());

            Assert.isFalse(sourceUnitRrn == null || sourceUnitRrn < 1,
                           Errors.create().content("The Wafer {} does not " + "exist !")
                                 .args(WebUtils.getParameter("sourceUnitId" + i, request)).build());

            targetUnitSourceUnitMapping.put(targetUnitRrn, sourceUnitRrn);
        }

        List bondingUnits = wipService.validateLots4Bonding(lots);

        Map<Long, Long> sourceLotRrnValues = new HashMap<Long, Long>();
        for (Object object : bondingUnits) {
            Map bondingUnit = (Map) object;
            Long sourceUnitRrn = MapUtils.getLongValue(bondingUnit, "sourceUnitRrn");
            Long sourceLotRrn = MapUtils.getLongValue(bondingUnit, "sourceLotRrn");
            sourceLotRrnValues.put(sourceUnitRrn, sourceLotRrn);
        }
        List<BondingMapping> bondingMappings = new ArrayList<BondingMapping>();
        for (Object object : bondingUnits) {
            Map bondingUnit = (Map) object;
            BondingMapping bondingMapping = new BondingMapping();
            Long targetLotRrn = MapUtils.getLongValue(bondingUnit, "targetLotRrn");
            Long targetUnitRrn = MapUtils.getLongValue(bondingUnit, "targetUnitRrn");
            Long sourceUnitRrn = targetUnitSourceUnitMapping.get(targetUnitRrn);
            Assert.isFalse(sourceUnitRrn == null || sourceUnitRrn < 1,
                           Errors.create().content("Unable to find the " + "mapping" + " wafer of the " + "wafer {}")
                                 .args(MapUtils.getLongValue(bondingUnit, "targetUnitId")).build());
            Long sourceLotRrn = sourceLotRrnValues.get(sourceUnitRrn);

            bondingMapping.setTargetLotRrn(targetLotRrn);
            bondingMapping.setTargetUnitRrn(targetUnitRrn);
            bondingMapping.setSourceUnitRrn(sourceUnitRrn);
            bondingMapping.setSourceLotRrn(sourceLotRrn);
            bondingMappings.add(bondingMapping);
        }
        wipService.saveBondingMapping(bondingMappings);
        parameters.put(SessionNames.RUNSTEP_FLAG, "0");
        request.setAttribute("automovein", automovein);
        request.setAttribute("parametersInfo", parameters);
        request.getRequestDispatcher(mapping.findForward("workflow").getPath() + "?action=init")
               .forward(request, response);
        return null;
        //return mapping.findForward("workflow");
    }

    private ActionForward buildBondingMapping(HttpServletRequest request, ActionMapping mapping,
                                              HttpServletResponse response, LotInfoForm theform) throws Exception {
        //Collection lots = (Collection) session.getAttribute(SessionNames.COLLECTION_KEY);
        Collection lots = (Collection) request.getAttribute(SessionNames.COLLECTION_KEY);
        //HashMap parameters = (HashMap) session.getAttribute(SessionNames.PARAMETERSINFO_KEY);
        HashMap parameters = (HashMap) request.getAttribute(SessionNames.PARAMETERSINFO_KEY);

        List bondingUnits = wipService.validAndBuildBondingBeforeLock((List<Map>) lots, parameters);

        boolean isHSZonding = wipService.isConsume((List<Map>) lots);
        if (isHSZonding) {// hsz+bonding 不需要预先记录bonding信息,验证通过就可以进站了
            // 针对需要newLot 的die attach,增加绑定信息
            //lotBondingService.addNewLotLockInfo(user, lots);
            parameters.put(SessionNames.RUNSTEP_FLAG, "0");
            request.getRequestDispatcher(mapping.findForward("workflow").getPath() + "?action=init")
                   .forward(request, response);

            return null;
            //return mapping.findForward("workflow");
        } else {// 普通bonding 需要预先展示bonding 信息
            request.setAttribute("bondingUnits", bondingUnits);
            setCache4WFL(request, theform);
            request.getRequestDispatcher(mapping.getInputForward().getPath()).forward(request, response);
            return null;
            //return mapping.getInputForward();
        }
    }

}