SorterManualConfirmAction.java

package com.mycim.webapp.actions.sort;
import com.mycim.framework.utils.lang.StringUtils;
import com.mycim.framework.utils.msg.JsonUtils;
import com.mycim.valueobject.SystemConstant;
import com.mycim.valueobject.consts.SessionNames;
import com.mycim.valueobject.consts.SorterEnum;
import com.mycim.valueobject.runcard.util.RunCardUtils;
import com.mycim.valueobject.sorter.SortJobBean;
import com.mycim.valueobject.sorter.SortJobCacheBean;
import com.mycim.valueobject.wip.Lot;
import com.mycim.valueobject.wip.Unit;
import com.mycim.webapp.WebUtils;
import com.mycim.webapp.forms.SortJobForm;
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.*;

/**
 * @Author: yibing.liu
 * @Date: 2022/3/17 14:49
 */
public class SorterManualConfirmAction  extends SortAbsAction  {

    @Override
    public ActionForward init(ActionMapping mapping, ActionForm form, HttpServletRequest request,
                              HttpServletResponse response) throws Exception {
        SortJobForm theform = getForm(form);
        Map parameters = (Map) request.getAttribute(SessionNames.PARAMETERSINFO_KEY);
        long jobRrn = com.mycim.framework.utils.lang.collections.MapUtils.getLongValue(parameters, "jobRrn");
        if (parameters == null) {
            parameters = (HashMap) WebUtils.getCacheString2Obj(theform.getCacheParametersInfo());
            request.setAttribute(SessionNames.PARAMETERSINFO_KEY, parameters);
        }
        List<Map> lots = (List<Map>) request.getAttribute(SessionNames.COLLECTION_KEY);
        Map lot = lots.get(0);
        Long carrierRrn = MapUtils.getLong(lot, "carrierRrn");
        Long lotRrn = MapUtils.getLong(lot, "lotRrn");
        Long entityRrn = MapUtils.getLong(parameters, "eqptRrn");
        // 通过Lot获取sorter job数据
        SortJobBean sortJobBean = sorterQueryService.getSortJobListByCarrierRrn(carrierRrn);
        if (sortJobBean.getMainJobRrn() == 0) {
            boolean holdFlag = lotService.checkMoveOutSorterJob(lotRrn, entityRrn);
            if (holdFlag) {
                return super.showRunningHoldInfoDetail(mapping, request, jobRrn);
            }
            return continueMoveOut(parameters, mapping, request, response);
        }
        Map<String, Object> lotInfo;
        request.setAttribute("readT7Code",false);

        //是否是读取来料T7code
        if(SorterEnum.Constant.READ_T7CODE.equals(sortJobBean.getJobType())){
            request.setAttribute("readT7Code",true);
            lotInfo = buildReadT7CodeSortJobDetail(sortJobBean);
        }else if (SorterEnum.Constant.EXCHANGE.equalsIgnoreCase(sortJobBean.getJobType())){
            lotInfo = buildExchangeSortJobDetail(sortJobBean);
        }else {
            lotInfo = buildSortJobDetail(sortJobBean);
        }

        lotInfo.put("allowManualConfirm", MARK);
        request.setAttribute("lotInfo", lotInfo);
        setCache4WFL(request, form);
        return mapping.getInputForward();
    }

    /**
     * 根据Sorter Job完成操作,继续执行 MoveOut 操作
     */
    public ActionForward confirmOperation(HttpServletRequest request, ActionForm form, HttpServletResponse response,
                                          ActionMapping mapping) throws Exception {
        Map parameters = (Map) request.getAttribute(SessionNames.PARAMETERSINFO_KEY);
        SortJobForm theform = (SortJobForm) form;
        if (parameters == null) {
            parameters = (Map) WebUtils.getCacheString2Obj(theform.getCacheParametersInfo());
            request.setAttribute(SessionNames.PARAMETERSINFO_KEY, parameters);
        }
        if (request.getAttribute(SessionNames.JOB_KEY) == null) {
            request.setAttribute(SessionNames.JOB_KEY, WebUtils.getCacheString2Obj(theform.getCacheJob()));
        }
        if (request.getAttribute(SessionNames.COLLECTION_KEY) == null) {
            request.setAttribute(SessionNames.COLLECTION_KEY,
                                 WebUtils.getCacheString2Obj(theform.getCacheCollection()));
        }
        List<Map> lots = (List<Map>) request.getAttribute(SessionNames.COLLECTION_KEY);
        Map lot = lots.get(0);
        Lot lotInfo = lotInqService.getLot(MapUtils.getLong(lot, "lotRrn"));
        Long carrierRrn = MapUtils.getLong(lot, "carrierRrn");
        // 通过Lot获取sorter job数据
        SortJobBean sortJobBean = sorterQueryService.getSortJobListByCarrierRrn(carrierRrn);
        SortJobCacheBean sjcb = new SortJobCacheBean();
        if (sortJobBean.getMainJobRrn() != 0) {
            if(StringUtils.equalsIgnoreCase(SorterEnum.Constant.READ_T7CODE,sortJobBean.getJobType())){
                List<Map> unitT7codeMapping = JsonUtils.toList(theform.getSourceListValues(), Map.class);
                List<Unit> units = new ArrayList<>();
                unitT7codeMapping.forEach(data ->{
                    String unitId = MapUtils.getString(data,"unitId");
                    long unitRrn = MapUtils.getLongValue(data,"unitRrn");
                    if (StringUtils.isNotBlank(unitId) && unitRrn > 0){
                        Unit unit = new Unit();
                        unit.setLotRrn(MapUtils.getLongValue(data,"lotRrn"));
                        unit.setLotId(MapUtils.getString(data,"lotId"));
                        unit.setUnitRrn(unitRrn);
                        unit.setUnitId(unitId);
                        unit.setCustomerT7Code(MapUtils.getString(data,"customerT7Code"));
                        unit.setPositionInCarrier(MapUtils.getInteger(data,"position"));
                        units.add(unit);
                    }
                });
                //校验customer t7code
                sorterService.checkCustomerT7Code(units);
                // sorterService.endReadT7Code(units);
                sjcb.setUnitList(units);
            }else if (StringUtils.equalsIgnoreCase(SorterEnum.Constant.EXCHANGE, sortJobBean.getJobType())) {
                sortJobBean.setTargetCarrierId(theform.getTargetCarrierId());
                // confirm 时 update sorter job
                sorterService.updateSorterJobForInLineExchange(sortJobBean, lotInfo);
            }
            // sorterService.endSortJob(sortJobBean);
            sjcb.setSortJobBean(sortJobBean);
            request.setAttribute(SessionNames.SORTER_JOB, sjcb);//将数据先保存至缓存中
        }
        if(RunCardUtils.checkLotIdIsRunCardLot(lotInfo.getLotId())){
            request.setAttribute(SystemConstant.Str.RC_SORT_OVER, SystemConstant.Str.NUM_TRUE);
            request.setAttribute("eqptId", lotInfo.getEqptID());
            return mapping.findForward("rcContinueMoveOut");
        }
        return continueMoveOut(parameters, mapping, request, response);
    }

    private ActionForward continueMoveOut(Map parameters, ActionMapping mapping, HttpServletRequest request,
                                          HttpServletResponse response) throws Exception {
        return mapping.findForward("continueMoveOut");
    }
}