EqpMonitorChangeLotRouteAction.java

package com.mycim.webapp.actions.dmmchangelotroute;

import com.fa.sesa.exception.Assert;
import com.fa.sesa.exception.Errors;
import com.fa.sesa.threadlocal.LocalContext;
import com.mycim.valueobject.MessageIdList;
import com.mycim.valueobject.prp.EqpMonitorLotSpecialStep;
import com.mycim.valueobject.security.User;
import com.mycim.valueobject.wip.Lot;
import com.mycim.valueobject.wip.LotStatus;
import com.mycim.valueobject.wip.TransReason;
import com.mycim.webapp.Constants;
import com.mycim.webapp.actions.NpwSetupAction;
import com.mycim.webapp.forms.RootForm;
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.Map;

/**
 * DmmChangeLotRouteAction
 *
 * @author chaoyu.song
 * @version 6.0.0
 * @date 2020/5/28
 **/
public class EqpMonitorChangeLotRouteAction extends NpwSetupAction {
    @Override
    public ActionForward init(ActionMapping mapping, ActionForm form, HttpServletRequest request,
                              HttpServletResponse response) throws Exception {
        String lotId = request.getParameter("lotId");
        Lot lot = lotQueryService.getLot(lotId, LocalContext.getFacilityRrn());

        Assert.isFalse((lot.getLotStatus() == null) || (!lot.getLotStatus().equals(LotStatus.HOLD)),
                       Errors.create().key(MessageIdList.SCRAPLOT_STATUS_NOT_ALLOW)
                             .content("Lot status must " + "be Hold!").build());

        EqpMonitorLotSpecialStep lotSpecialStep = dmmLotService
                .getDMMLotSpecialStepByOperation(lot.getOperationRrn(), lot.getLotRrn());

        Map<String, String> lotInfo = getLotInfo(lot, lotSpecialStep);

        request.setAttribute("lotInfo", lotInfo);

        return mapping.findForward(Constants.INIT_KEY);

    }

    public ActionForward saveDmmChangeRoute(ActionMapping mapping, RootForm theform,
                                            HttpServletRequest request) throws Exception {
        long facilityRrn = LocalContext.getFacilityRrn();
        String userId = LocalContext.getUserId();
        String stepNumber = request.getParameter("stepNumber");
        Integer targetStep = Integer.valueOf(request.getParameter("retModelSeq"));
        String changeFlow = "";

        String lotId = request.getParameter("lotId");
        Lot lot = lotQueryService.getLot(lotId, facilityRrn);

        EqpMonitorLotSpecialStep lotSpecialStep = dmmLotService
                .getDMMLotSpecialStepByOperation(lot.getOperationRrn(), lot.getLotRrn());
        if (lotSpecialStep.getStepSequence() > targetStep) {
            changeFlow = "before";
        } else {
            changeFlow = "after";
        }

        User userEntity = securityService.getUser(Long.parseLong(theform.getUserRrn()));
        String reason = theform.getReasonCode() + " " + theform.getDeptExt().trim().toUpperCase() + " " +
                userEntity.getUserName() + " " + theform.getReason();
        TransReason transReason = new TransReason();
        transReason.setReasonCode(theform.getReasonCode());
        transReason.setReason(reason);
        transReason.setTransQty1(lot.getQty1());
        transReason.setTransQty2(lot.getQty2());
        transReason.setResponsibility(userId);

        dmmLotService
                .dmmChangeLotProcess(lot, userId, lot.getProcessVersion(), lot.getProcessRrn(), stepNumber, changeFlow,
                                     transReason);

        return mapping.findForward("end");
    }

    /*
     *
     * 暂时空方法,不校验,方便以后添加
     */
    public String checkDmmTargetProcessInfo(Map<String, Object> theform) {
        return "";
    }

}