WetBatchAction.java

package com.mycim.webapp.actions.wetBatch;

import com.fa.sesa.exception.Assert;
import com.fa.sesa.exception.Errors;
import com.mycim.framework.context.spring.SpringContext;
import com.mycim.framework.jdbc.Page;
import com.mycim.framework.utils.lang.StringUtils;
import com.mycim.server.prp.service.PrpService;
import com.mycim.server.spec.service.SpecService;
import com.mycim.server.wetbatch.service.WetBatchQueryService;
import com.mycim.server.wetbatch.service.WetBatchService;
import com.mycim.valueobject.MessageIdList;
import com.mycim.valueobject.wetbatch.WetBatchBean;
import com.mycim.valueobject.wetbatch.dto.WetBatchQueryDto;
import com.mycim.webapp.Constants;
import com.mycim.webapp.WebUtils;
import com.mycim.webapp.actions.AbstractAction;
import com.mycim.webapp.actions.wetBatch.form.WetBatchForm;
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;

/**
 * @Author: yibing.liu
 * @Date: 2021/12/30 17:14
 */
public class WetBatchAction extends AbstractAction {

    WetBatchQueryService    wetBatchQueryService    = SpringContext.getBean(WetBatchQueryService.class);

    WetBatchService         wetBatchService         = SpringContext.getBean(WetBatchService.class);

    PrpService              prpService              = SpringContext.getBean(PrpService.class);

    SpecService             specService             = SpringContext.getBean(SpecService.class);

    @Override
    public ActionForward init(ActionMapping mapping, ActionForm form, HttpServletRequest request,
                              HttpServletResponse response) throws Exception {
        clearFormSearch(getForm(form));
        request.setAttribute("thisPage", 1);
        request.setAttribute("maxPage", 1);
        request.setAttribute("pageSize", 20);
        request.setAttribute("lastPageSize", 20);
        return mapping.getInputForward();
    }

    public ActionForward queryItemProdList(ActionMapping mapping, ActionForm form, HttpServletRequest request)  {
        WetBatchForm theForm = getForm(form);
        WetBatchQueryDto wetBatchQueryDto = new WetBatchQueryDto();
        if (request.getParameter("backPortal") != null){
            clearFormSearch(theForm);
        }
        wetBatchQueryDto.setPreEquipmentGroupId(theForm.getSearchPreEquipmentGroupId());
        wetBatchQueryDto.setPreRecipeId(theForm.getSearchPreRecipeId());
        wetBatchQueryDto.setPostEquipmentGroupId(theForm.getSearchPostEquipmentGroupId());
        wetBatchQueryDto.setPostRecipeId(theForm.getSearchPostRecipeId());
        wetBatchQueryDto.setProductId(theForm.getProductId());

        int thisPage = WebUtils.getThisPage(request);
        int pageSize = WebUtils.getPageSize(request);

        wetBatchQueryDto.setPage(thisPage);
        wetBatchQueryDto.setLimit(pageSize);
        Page page = wetBatchQueryService.queryItemProd4Page(wetBatchQueryDto);


        request.setAttribute("pageSize", 20);
        request.setAttribute("lastPageSize", 20);
        request.setAttribute("thisPage", page.getPageNo());
        request.setAttribute("maxPage", page.getTotalPages());
        request.setAttribute("wetBatchList", page.getResults());

        return mapping.findForward(Constants.VIEW_KEY);
    }

    public ActionForward queryItemProdDetailList(ActionMapping mapping, ActionForm form, HttpServletRequest request) {
        WetBatchForm theForm = getForm(form);
        WetBatchQueryDto wetBatchQueryDto = new WetBatchQueryDto();
        List<WetBatchBean> wetBatchBeanList = new ArrayList<>();
        if (StringUtils.isNotBlank(theForm.getSearchPreEquipmentGroupId()) && StringUtils.isNotBlank(theForm.getSearchPreRecipeId())
                && StringUtils.isNotBlank(theForm.getSearchPostEquipmentGroupId()) && StringUtils.isNotBlank(theForm.getSearchPostRecipeId()) ){
            Assert.isFalse(wetBatchQueryDto.setPreEquipmentGroupId(theForm.getSearchPreEquipmentGroupId()),
                           Errors.create().key(MessageIdList.CAN_NOT_EMPTY).content("{} cannot be empty!").args("Pre EqpGroup ID").build());
            Assert.isFalse(wetBatchQueryDto.setPreRecipeId(theForm.getSearchPreRecipeId()),
                           Errors.create().key(MessageIdList.CAN_NOT_EMPTY).content("{} cannot be empty!").args("Pre Recipe ID").build());
            Assert.isFalse(wetBatchQueryDto.setPostEquipmentGroupId(theForm.getSearchPostEquipmentGroupId()),
                           Errors.create().key(MessageIdList.CAN_NOT_EMPTY).content("{} cannot be empty!").args("Post EQPGroup ID").build());
            Assert.isFalse(wetBatchQueryDto.setPostRecipeId(theForm.getSearchPostRecipeId()),
                           Errors.create().key(MessageIdList.CAN_NOT_EMPTY).content("{} cannot be empty!").args("Post Recipe ID").build());

            wetBatchBeanList = wetBatchQueryService.queryItemProdList(wetBatchQueryDto);
        }
        request.setAttribute("wetBatchList", wetBatchBeanList);
        return mapping.findForward(Constants.DETAIL_KEY);
    }

    void clearFormParam(WetBatchForm theForm) {
        theForm.setProductId(StringUtils.EMPTY);
        theForm.setProcessId(StringUtils.EMPTY);
        theForm.setProcessVer(StringUtils.EMPTY);
        theForm.setPreEqptGroupId(StringUtils.EMPTY);
        theForm.setPreFlowSeq(StringUtils.EMPTY);
        theForm.setPreOperationDesc(StringUtils.EMPTY);
        theForm.setPreRecipeId(StringUtils.EMPTY);
        theForm.setPreStageId(StringUtils.EMPTY);
        theForm.setPostEqptGroupId(StringUtils.EMPTY);
        theForm.setPostFlowSeq(StringUtils.EMPTY);
        theForm.setPostOperationDesc(StringUtils.EMPTY);
        theForm.setPostRecipeId(StringUtils.EMPTY);
        theForm.setPostStageId(StringUtils.EMPTY);
    }

    void clearFormSearch(WetBatchForm theForm) {
        theForm.setProductId(StringUtils.EMPTY);
        theForm.setProcessId(StringUtils.EMPTY);
        theForm.setProcessVer(StringUtils.EMPTY);
        theForm.setSearchPostEquipmentGroupId(StringUtils.EMPTY);
        theForm.setSearchPostRecipeId(StringUtils.EMPTY);
        theForm.setSearchPreEquipmentGroupId(StringUtils.EMPTY);
        theForm.setSearchPreRecipeId(StringUtils.EMPTY);
    }
}