MonitorLotPlanEditAction.java

package com.mycim.webapp.actions.dmmlotplan;

import com.fa.sesa.exception.Assert;
import com.fa.sesa.exception.Errors;
import com.fa.sesa.i18n.I18nUtils;
import com.fa.sesa.i18n.Languages;
import com.fa.sesa.threadlocal.LocalContext;
import com.mycim.framework.utils.lang.StringUtils;
import com.mycim.framework.utils.lang.collections.CollectionUtils;
import com.mycim.framework.utils.lang.collections.MapUtils;
import com.mycim.valueobject.consts.ReferenceDetailNames;
import com.mycim.valueobject.consts.ReferenceFileConst;
import com.mycim.valueobject.consts.SessionNames;
import com.mycim.valueobject.consts.TransactionNames;
import com.mycim.valueobject.sys.ObjectTransAttribute;
import com.mycim.valueobject.wip.PlanLot;
import com.mycim.webapp.Constants;
import com.mycim.webapp.WebUtils;
import com.mycim.webapp.actions.NpwSetupAction;
import com.mycim.webapp.forms.MonitorLotInfoForm;
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.*;

public class MonitorLotPlanEditAction extends NpwSetupAction {

    @Override
    public ActionForward init(ActionMapping mapping, ActionForm form, HttpServletRequest request,
                              HttpServletResponse response) throws Exception {
        MonitorLotInfoForm theform = (MonitorLotInfoForm) form;

        boolean createLotFlag = WebUtils.getParameter("createlot", request) != null;
        String screenStatus = createLotFlag == true ? "CREATE_PLAN_LOT" : "LOT_PLAN_START";
        if (WebUtils.getParameterBoolean(Constants.NAV_KEY, request)) {
            MonitorLotInfoForm emptyForm = new MonitorLotInfoForm();
            emptyForm.setScreenStatus(screenStatus);
            request.removeAttribute(SessionNames.RETICLE_GROUP);
            request.removeAttribute("create_lot_flag");
            request.removeAttribute("productRrn");
            request.removeAttribute(SessionNames.LOTS_LIST_KEY);
            request.removeAttribute(SessionNames.LOT_KEY);
            request.removeAttribute("lotIds");
            request.removeAttribute("lotTypeOptions");
            request.setAttribute("MonitorLotInfoForm", emptyForm);
            if (createLotFlag == true) {
                theform.setByPlanLotFlag("product");
            }
            return mapping.findForward(Constants.MODIFY_KEY);
        }

        String id = StringUtils.trimToUpperCase(theform.getCreatedPlanLotId());
        request.setAttribute("create_lot_flag", String.valueOf(""));
        theform.setScreenStatus("CREATE_PLAN_LOT");
        return mapping.findForward("modify");
    }

    public List<Map<String, String>> getLotTypeOptions(HttpServletRequest request) throws Exception {
        List<Map<String, String>> lotTypeOptions = lotService
                .getLotTypeOptions(LocalContext.getFacilityRrn(), I18nUtils.getCurrentLanguage().toString(),
                                   WebUtils.getParameter("categoryOwner", request));
        List<Map<String, String>> newLotTypeOptions = new ArrayList<>();
        //monitor投批的批次类型为M类型
        for (Map map : lotTypeOptions) {
            String value = MapUtils.getString(map, "value");
            if (StringUtils.equalsIgnoreCase("M", value)) {
                newLotTypeOptions.add(map);
            }

        }

        return newLotTypeOptions;
    }

    public Map getByPlanLotFlagProductResult(Map map, HttpServletRequest request) throws Exception {
        request.setAttribute("create_lot_flag", String.valueOf(""));

        String lotId = StringUtils.EMPTY;

        ObjectTransAttribute objectTransAttribute = new ObjectTransAttribute("LOT", getNamedSpace("LOT", LocalContext
                .getFacilityRrn()), TransactionNames.CREATE_KEY, null);
        Collection fields = getObjectTransAttributeFields(objectTransAttribute,
                                                          I18nUtils.getCurrentLanguage().toString());

        if ((fields != null) && (fields.size() > 0)) {
            request.setAttribute("attributes", fields);
        }


        String lotType = MapUtils.getString(map, "lotType");
        String lotQty = MapUtils.getString(map, "lotQty");
        int qty = 1;
        if (StringUtils.isNotEmpty(lotQty)) {
            qty = Integer.parseInt(lotQty);
        }
        String createCategory = sysService.referenceDetailExchangeByKey2(ReferenceDetailNames.LOT_NAMING_RULE, lotType,
                                                                         ReferenceFileConst.KEY_1_VALUE);

      /*  ReferenceFileDetail referenceFileDetail = getReferenceFileDetail(ReferenceDetailNames
      .LOT_NAMING_RULE,
                                                                         createCategory, lotType,
                                                                         LocalContext.getFacilityRrn());*/
        List<String> lotIds = baseService.generateLotId(qty, lotType);

        if (CollectionUtils.isNotEmpty(lotIds)) {
            lotId = lotIds.get(lotIds.size() - 1);
        }

        Map result = new HashMap();
        result.put("createCategory", createCategory);
        result.put("lotId", lotId);
        result.put("lotIds", lotIds);
        result.put("screenStatus", "CREATE_PLAN_LOT");
        result.put("hotFlag", "1");

        String isshow = request.getParameter("isshow");
        request.setAttribute("isshow", isshow);

        return result;
    }

    public ActionForward getPlanLotToForm(ActionMapping mapping, MonitorLotInfoForm theform, HttpServletRequest request,
                                          HttpServletResponse response) throws Exception {
        String id = StringUtils.trimToUpperCase(theform.getCreatedPlanLotId());
        request.setAttribute("create_lot_flag", String.valueOf(""));
        theform.setScreenStatus("CREATE_PLAN_LOT");
        PlanLot planLot = new PlanLot(LocalContext.getFacilityRrn(), id);
        planLot = getPlanLot(planLot);
        Assert.isFalse(
                (planLot == null) || (planLot.getLotRrn() == null) || (planLot.getLotRrn().compareTo(new Long(0)) <= 0),
                Errors.create().content("Plan Order").build());
        theform.setCreatedPlanLotId(planLot.getLotId());
        theform.setCreatedPlanLotRrn(planLot.getLotRrn());
        theform.setProductId(planLot.getProductId());

        // add plan lot message to formBean

        if (planLot.getPriority() != null) {
            theform.setPriority(new Integer(planLot.getPriority().intValue()));
        }
        theform.setDueDateS(planLot.getDate());
        theform.setLotOwner(planLot.getLotOwner());
        theform.setHotFlag(planLot.getHotFlag());
        theform.setLotType(planLot.getLotType());
        theform.setQty1(planLot.getQty1());

        request.setAttribute("productRrn", planLot.getProductRrn());
        return mapping.findForward("modify");
    }


    // -----------------------------------------------------------------------private

    private Collection getObjectTransAttributeFields(ObjectTransAttribute objectTransAttribute,
                                                     String language) throws Exception {
        objectTransAttribute.setFieldRrn(null);

        return sysService.getObjectTransAttributes(objectTransAttribute, Languages.valueOf(language));
    }

}

/*
 * Modification Log Log No : Name : Modified Date: Description :
 */