LotReleaseAction.java

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

import com.fa.sesa.exception.Assert;
import com.fa.sesa.exception.Errors;
import com.fa.sesa.exception.SystemIllegalArgumentException;
import com.fa.sesa.threadlocal.LocalContext;
import com.mycim.framework.utils.lang.StringUtils;
import com.mycim.framework.utils.lang.collections.CollectionUtils;
import com.mycim.valueobject.MessageIdList;
import com.mycim.valueobject.consts.EenActionType;
import com.mycim.valueobject.prp.FutureHoldLot;
import com.mycim.valueobject.wip.Lot;
import com.mycim.valueobject.wip.LotRunCardStore;
import com.mycim.valueobject.wip.LotStatus;
import com.mycim.webapp.Constants;
import com.mycim.webapp.actions.WipSetupAction;
import com.mycim.webapp.forms.lot.HoldReleaseLotInfoForm;
import org.apache.commons.compress.utils.Sets;
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.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @author Luopeng.Wang
 * @version 6.0.0
 * @date 2019/9/16
 **/
public class LotReleaseAction extends WipSetupAction {
    @Override
    public ActionForward init(ActionMapping mapping, ActionForm form, HttpServletRequest request,
                              HttpServletResponse response) throws Exception {
        Lot lot = initLotBaseInfoForJsp(request, true, null, null);

        List<Map> holdInfos = new ArrayList<>();
        if (lot != null && lot.getLotRrn() > 0) {
            holdInfos = wipQueryService.getHoldReasons(lot.getLotRrn());
            request.setAttribute("lotId", lot.getLotId());
        }

        super.checkCstRemoved(Sets.newHashSet(lot.getLotRrn()));

        request.setAttribute("collection", holdInfos);

        if (StringUtils.equals(lot.getLotStatus(), LotStatus.HOLD)) {
            checkWaitJobs(lot.getCarrierRrn(), 0L, 0L,
                          Errors.create().key(MessageIdList.CARRIER_BE_OCCUPIED).args(lot.getCarrierId()).build());
            return mapping.findForward(Constants.RELEASE_KEY);
        } else if (StringUtils.equals(lot.getLotStatus(), LotStatus.RUNNINGHOLD)) {
            return mapping.findForward(Constants.RUNNING_RELEASE_KEY);
        } else {
            throw new SystemIllegalArgumentException(
                    Errors.create().key(MessageIdList.LOT_STATUS_NOT_ALLOW).content("Lot status not allow").build());
        }
    }

    public ActionForward release(ActionMapping mapping, ActionForm form, HttpServletRequest request,
                                 HttpServletResponse response) throws Exception {
        HoldReleaseLotInfoForm theform = (HoldReleaseLotInfoForm) form;
        long facilityRrn = LocalContext.getFacilityRrn();
        String lotId = theform.getLotId();
        Lot lot = lotQueryService.getLot(lotId, facilityRrn);
        //被hold的lot是否是post future hold
        List<FutureHoldLot> postFutureHoldLotList = wipService.getFutureHoldLotList(lot.getLotRrn(), EenActionType.POST_FUTURE_HOLD);
        if(CollectionUtils.isNotEmpty(postFutureHoldLotList)){
            //被hold的lot是否是辅产品
            if(CollectionUtils.isNotEmpty(wipService.getHoldDebondLotBySourceLotRrn(lot.getLotRrn()))){
                return bondedLotPostFHReleaseHandle(mapping, form, request, response);
            }
            request.setAttribute("postFutureHoldLotList",postFutureHoldLotList);
            return postFutureReleaseHandle(mapping, form, request, response);
        }
        return releaseHandle(mapping, form, request, response);
    }

    public ActionForward runningRelease(ActionMapping mapping, ActionForm form, HttpServletRequest request,
                                        HttpServletResponse response) throws Exception {
        return releaseRunningHandle(mapping, form, request, response);
    }

    @Override
    protected void checkRunCard(Lot lot) {
        LotRunCardStore lotStore = lotRunCardQueryService.getSplitRunCardLotStore(lot.getLotRrn());
        Assert.isFalse(lotStore != null, Errors.create().content("Lot in Split Runcard,can't release.").build());
    }
}