DivideBoxAction.java

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

import com.fa.sesa.exception.Assert;
import com.fa.sesa.exception.Errors;
import com.fa.sesa.threadlocal.LocalContext;
import com.mycim.framework.utils.lang.collections.MapUtils;
import com.mycim.valueobject.MessageIdList;
import com.mycim.valueobject.consts.CompletedssConstants;
import com.mycim.webapp.WebUtils;
import com.mycim.webapp.actions.WipSetupAction;
import com.mycim.webapp.forms.lot.CompletedssLotForm;
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 kang.zhang
 * @date 2019年9月27日
 * @description 完成品 分盒管理
 */
public class DivideBoxAction extends WipSetupAction {

    @Override
    public ActionForward init(ActionMapping mapping, ActionForm form, HttpServletRequest request,
                              HttpServletResponse response) {

        return mapping.findForward("dividePage");
    }

    public ActionForward back(ActionMapping mapping, ActionForm form, HttpServletRequest request,
                              HttpServletResponse response) {

        return mapping.findForward("back");
    }

    public ActionForward getDividePage(ActionMapping mapping, ActionForm form, HttpServletRequest request,
                                       HttpServletResponse response) throws Exception {
        CompletedssLotForm themform = (CompletedssLotForm) form;
        // 初始进入页面
        String completedssType = themform.getCompletedssType();
        List<Map<String, Object>> usefulUnits = new ArrayList<Map<String, Object>>();
        Assert.isTrue(CompletedssConstants.COMPLETEDSS_TYPE_DIE.equalsIgnoreCase(completedssType),
                      Errors.create().key(MessageIdList.COMPLETEDSSLOT_STORAGE_TYPE_MUSTBE_DIE)
                            .content("The storage type is DIE for the box!").build());
        usefulUnits = wipQueryService.getUsefulUnits(themform.getLotRrn());
        themform.setCacheUnitLists(WebUtils.getCacheObj2String(usefulUnits));
        request.setAttribute("unitLists", usefulUnits);
        return mapping.findForward("dividePage");
    }

    public ActionForward saveDivideBox(ActionMapping mapping, CompletedssLotForm themform, HttpServletRequest request,
                                       HttpServletResponse response) throws Exception {
        Assert.isFalse(themform.getIsDivideBox() != null && themform.getIsDivideBox() == 1,
                       Errors.create().key(MessageIdList.COMPLETEDSSLOT_DIVIDE_BOX_FINISHED)
                             .content("The lot has been finished. Please do not repeat!").build());
        List<Map<String, Object>> usefulUnits = (List<Map<String, Object>>) WebUtils
                .getCacheString2Obj(themform.getCacheUnitLists());

        String user = LocalContext.getUserId();
        Long lotRrn = themform.getLotRrn();
        List<Map<String, Object>> unitBoxInfos = new ArrayList<Map<String, Object>>();
        // 将所有分盒信息装入容器 传入service进行处理
        for (Map<String, Object> map : usefulUnits) {
            Map<String, Object> unitBoxInfo = new HashMap<String, Object>();
            String unitId = MapUtils.getString(map, "UNIT_ID");
            Long unitRrn = MapUtils.getLong(map, "UNIT_RRN");
            unitBoxInfo.put("unitRrn", unitRrn);
            unitBoxInfo.put("lotRrn", lotRrn);
            String[] boxIds = request.getParameterValues(unitId + "boxIds");
            unitBoxInfo.put("boxIds", boxIds);
            String[] dieNums = request.getParameterValues(unitId + "dieNums");
            unitBoxInfo.put("dieNums", dieNums);
            unitBoxInfos.add(unitBoxInfo);
        }
        Map<String, Object> transInfos = new HashMap<String, Object>();
        transInfos.put("user", user);
        transInfos.put("comments", themform.getComments());
        lotService.saveDivideBoxInfos(unitBoxInfos, transInfos);// 执行
        themform.setCacheUnitLists("");
        request.removeAttribute("unitLists");
        return mapping.findForward("sucess");
    }

}