LotPlanEditAction.java

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

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.logging.Logger;
import com.mycim.framework.logging.LoggerFactory;
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.MessageIdList;
import com.mycim.valueobject.ObjectList;
import com.mycim.valueobject.consts.ReferenceDetailNames;
import com.mycim.valueobject.consts.SessionNames;
import com.mycim.valueobject.sys.ObjectTransAttribute;
import com.mycim.valueobject.sys.ReferenceFileDetail;
import com.mycim.valueobject.wip.PlanLot;
import com.mycim.webapp.Constants;
import com.mycim.webapp.WebUtils;
import com.mycim.webapp.actions.WipSetupAction;
import com.mycim.webapp.forms.lot.LotInfoForm;
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 LotPlanEditAction extends WipSetupAction {

    public static final String CATEGORY_PROCESS_KEY = "PROCESS";

    public static final String CATEGORY_EPI_KEY = "EPI";

    private static final Logger log = LoggerFactory.getLogger(LotPlanEditAction.class);

    // --------------------------------------------------------- Public Methods
    @Override
    public ActionForward init(ActionMapping mapping, ActionForm form, HttpServletRequest request,
                              HttpServletResponse response) throws Exception {
        LotInfoForm theform = (LotInfoForm) 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)) {
            LotInfoForm emptyForm = new LotInfoForm();
            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("lotInfoForm", 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));

        return lotTypeOptions;
    }

    public Map getByPlanLotFlagProductResult(Map map, HttpServletRequest request){
        request.setAttribute("create_lot_flag", StringUtils.EMPTY);
        String lotId = StringUtils.EMPTY;

        String lotType = MapUtils.getString(map, "lotType");
        Integer lotQty = MapUtils.getInteger(map, "lotQty",1);//函数要求int 类型
        String category = MapUtils.getString(map, "category");  //工艺/外延

        //没有用到的变量  注释 by mingcz
        // String substrate = MapUtils.getString(map, "substrate");
        // String duumyFlag = MapUtils.getString(map, "dummyFlag");
        // String lotArea = MapUtils.getString(map, "lotArea");
        // String projectCode = MapUtils.getString(map, "project");
        // String extensionEqpt = MapUtils.getString(map, "extensionEqpt"); //外延设备

        //通过maputils 直接获取为int 类型数据,默认给1 等效下四行代码 //by mingcz
        // int qty = 1;
        // if (StringUtils.isNotEmpty(lotQty)) {
        //     qty = Integer.parseInt(lotQty);
        // }

        //创建查询实体
        ReferenceFileDetail referenceFileDetail = new ReferenceFileDetail();
        referenceFileDetail.setInstanceId(ReferenceDetailNames.LOT_NAMING_RULE);
        referenceFileDetail.setNamedSpace(getNamedSpace(ObjectList.REFERENCE_FILE_KEY, LocalContext.getFacilityRrn()));
        referenceFileDetail.setObject(ObjectList.REFERENCE_FILE_KEY);
        referenceFileDetail.setKey1Value(category);
        referenceFileDetail.setKey2Value(lotType);
        //查询
        referenceFileDetail = sysService.getReferenceFileDetail(referenceFileDetail);
        //结果非空判断
        Assert.isFalse(Objects.isNull(referenceFileDetail),
                       Errors.create().key(MessageIdList.SYSTEM_INSTANCE_NOT_FOUND).content("{} 没有找到对象!")
                             .args(referenceFileDetail.getInstanceId()).build());
        //生成实际返回数据
        List<String> lotIds = baseService.generateLotId(referenceFileDetail, lotQty);
        if (CollectionUtils.isNotEmpty(lotIds)) {
            lotId = lotIds.get(lotIds.size() - 1);
        }

        Map<String,Object> result = new HashMap();
        result.put("lotId", lotId);
        result.put("lotIds", lotIds);
        result.put("screenStatus", "CREATE_PLAN_LOT");
        //result.put("hotFlag", "1");
        request.setAttribute("isshow", request.getParameter("isshow"));
        return result;
    }

    public ActionForward getPlanLotToForm(ActionMapping mapping, LotInfoForm 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());
        log.debug("!!!!!!!!!!!!!!!!!!in plantlot productRrn is " + request.getAttribute("productRrn"));
        return mapping.findForward("modify");
    }


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

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

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

    private String checkLotIdsExceededMaxLotId(List<String> lotIds, String lotIdPrefix, int serialLen) {
        if (CollectionUtils.isEmpty(lotIds)) {
            return "";
        }
        StringBuilder checkMsg = new StringBuilder();
        List<String> exceedsMaxLotIds = new ArrayList<>();
        for (String lotId : lotIds) {
            String serial = StringUtils.substringAfter(lotId, lotIdPrefix);
            if (!StringUtils.isNumeric(serial)) {
                exceedsMaxLotIds.add(lotId);
            }
        }
        if (CollectionUtils.isNotEmpty(exceedsMaxLotIds)) {
            String maxLotId = lotIdPrefix;
            for (int i = 0; i < serialLen; i++) {
                maxLotId += "9";
            }
            String lotIdsStr = String.join(StringUtils.COMMA_SIGN, exceedsMaxLotIds);
            checkMsg.append(exceedsMaxLotIds.size() > 1 ? "These lotIds " : "This lotId ").append(lotIdsStr);
            checkMsg.append(" exceeds MaxLotId ").append(maxLotId);
            checkMsg.append(", please contact the administrator!");
        }
        return checkMsg.toString();
    }

}

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