CancelAutoSplitMergeAction.java

package com.mycim.webapp.actions.product;

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.wip.AutoSplitMergeLot;
import com.mycim.valueobject.wip.Lot;
import com.mycim.valueobject.wip.LotStatus;
import com.mycim.valueobject.wip.LotTransLock;
import com.mycim.webapp.WebUtils;
import com.mycim.webapp.actions.PrpSetupAction;
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.HashMap;
import java.util.List;
import java.util.Map;


/**
 * 取消自动合批
 *
 * @author chaoyu.song
 */
public class CancelAutoSplitMergeAction extends PrpSetupAction {

    @Override
    public ActionForward init(ActionMapping mapping, ActionForm form, HttpServletRequest request,
                              HttpServletResponse response) throws Exception {
        String lotId = WebUtils.getParameterUpperCase("lotId", request);
        long facilityRrn = LocalContext.getFacilityRrn();
        Lot moveNextLot = lotQueryService.getLot(lotId, facilityRrn);
        Assert.notNull(moveNextLot, Errors.create().content("lot is not exit!").build());
        long lotRrn = moveNextLot.getLotRrn();
        AutoSplitMergeLot thisAlot = prpService.getAutoSplitMergeLot4Split(lotRrn);
        Assert.notNull(thisAlot, Errors.create().content("This lot has not auto split merge!").build());
        List<AutoSplitMergeLot> autoSplitMergeLot4SplitList = prpService
                .getAutoSplitMergeLot4SplitList(thisAlot.getTransRrn());
        List<Map<String, Object>> lists = new ArrayList<>();
        int i = 0;
        //主lot
        //long cancelLotRrn=thisAlot.getParentLotRrn();
        //Lot lot=lotQueryService.getLot(cancelLotRrn);
        for (AutoSplitMergeLot autoSplitMergeLot : autoSplitMergeLot4SplitList) {
            Map<String, Object> map = new HashMap<>();
            long lId = autoSplitMergeLot.getLotRrn();
            Lot lLot = lotQueryService.getLot(lId);
            map.put("lotId", lLot.getLotId());
            map.put("lotStatus", lLot.getLotStatus());
            map.put("lotQty", lLot.getQty1());
            map.put("seq", i++);
            lists.add(map);
        }
        request.setAttribute("lotLists", lists);
        request.setAttribute("cancelLotId", lotId);
        return mapping.findForward("init");
    }

    /**
     * lot info界面取消自动合批
     *
     * @param mapping
     * @param form
     * @param request
     * @param response
     * @return
     * @throws Exception
     */
    public ActionForward doCancelAutoMerge(ActionMapping mapping, ActionForm form, HttpServletRequest request,
                                           HttpServletResponse response) throws Exception {
        String lotId = WebUtils.getParameterUpperCase("lotId", request);
        long facilityRrn = LocalContext.getFacilityRrn();
        Lot moveNextLot = lotQueryService.getLot(lotId, facilityRrn);
        String userId = LocalContext.getUserId();

        Assert.notNull(moveNextLot,
                       Errors.create().key(MessageIdList.LOT_LOTRRN_NOT_FOUND).content("Cannot Find Lot!").build());
        Assert.isFalse(StringUtils.equals(moveNextLot.getLotStatus(), LotStatus.TERMINATED),
                       Errors.create().key(MessageIdList.LOT_STATUS_NOT_ALLOW).content("Lot status not allow").build());
        long lotRrn = moveNextLot.getLotRrn();
        AutoSplitMergeLot thisAlot = prpService.getAutoSplitMergeLot4Split(lotRrn);
        Assert.notNull(thisAlot, Errors.create().content("This lot has not auto split merge!").build());
        //获取所有的Lot,thisAlotk可以是子批或者母批
        List<AutoSplitMergeLot> autoSplitMergeLot4SplitList = prpService
                .getAutoSplitMergeLot4SplitList(thisAlot.getTransRrn());
        lotService.cancleAutoMerge(autoSplitMergeLot4SplitList, thisAlot);
        request.setAttribute("cancelAutoMergeFlag", false);
        return new ActionForward("/lotLocation4CSECAction.do?action=lotLocation&lotId=" + lotId);
    }

    // protected void checkAndCreateLotsTransLock(Long userRrn, String transId, List<Lot> lots, String comments) {
    //     List<LotTransLock> locks = new ArrayList<LotTransLock>();
    //     if (lots != null && lots.size() > 0) {
    //         for (Lot lot : lots) {
    //             LotTransLock lock = new LotTransLock();
    //             lock.setLotRrn(lot.getLotRrn());
    //             lock.setUserRrn(userRrn);
    //             lock.setTransId(transId);
    //             lock.setLotStatus(lot.getLotStatus());
    //             locks.add(lock);
    //         }
    //         lotService.checkAndCreateLotsTransLock(locks, comments);
    //     }
    // }

}