LotCurrentInfoAction.java

/*
 *        @ Copyright 2001 FA Software;
 *        All right reserved. No part of this program may be reproduced or
 *        transmitted in any form or by any means, electronic or
 *        mechanical, including photocopying, recording, or by any
 *        information storage or retrieval system without written
 *        permission from FA Software, except for inclusion of brief
 *        quotations in a review.
 */
package com.mycim.webapp.actions.lotcurrentinfo;

import com.fa.sesa.threadlocal.LocalContext;
import com.mycim.framework.utils.beans.BeanUtils;
import com.mycim.framework.utils.lang.StringUtils;
import com.mycim.valueobject.consts.TransactionNames;
import com.mycim.valueobject.prp.Operation;
import com.mycim.valueobject.prp.ProcessLoopInfo;
import com.mycim.valueobject.wip.Lot;
import com.mycim.webapp.actions.NpwSetupAction;
import com.mycim.webapp.forms.LotInfoFormNpw;
import org.apache.commons.beanutils.PropertyUtils;
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.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.HashMap;
import java.util.Map;

public class LotCurrentInfoAction extends NpwSetupAction {

    private static String timestampToString(Timestamp timestamp) {
        String dateString = "";

        if (timestamp != null) {
            SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");

            dateString = formatter.format(timestamp);
        }

        return dateString;
    }

    @Override
    public ActionForward init(ActionMapping mapping, ActionForm form, HttpServletRequest request,
                              HttpServletResponse response) throws Exception {
        String user = LocalContext.getUserId();
        Long facilityRrn = LocalContext.getFacilityRrn();

        LotInfoFormNpw theform = (LotInfoFormNpw) form;
        String lotId = request.getParameter("lotId");
        Lot lot = lotQueryService.getLot(lotId);
        Operation oper = prpService.getOperation(lot.getOperationRrn().longValue());
        lot.setOperationDesc(oper.getInstanceDesc());
        PropertyUtils.copyProperties(theform, lot);


        String nSpace = getNamedSpace("OPERATION", facilityRrn);
        if (oper.getNamedSpace().equalsIgnoreCase(nSpace)) {
            theform.setStartedFlag("true");
        } else {
            theform.setStartedFlag("false");
        }

        String recipePhysicalId = recipeService.buildRecipePhysicalId(lot.getRecipeId(), BeanUtils.copyBeanToMap(lot));
        theform.setRecipePhysicalId(recipePhysicalId);

        Timestamp dueDate = lot.getDueDate();

        request.setAttribute("priority", lot.getPriority());

        String due_date = timestampToString(dueDate);

        request.setAttribute("due_date", due_date);


        if (StringUtils.isNotBlank((String) request.getAttribute("isDummyLot"))) {
            Integer count = prpService.getProductSumLoopCount(lot.getProductRrn());
            ProcessLoopInfo loopInfo = new ProcessLoopInfo();
            loopInfo.setLoopCount(count + "");
            loopInfo.setProcessRrn(lot.getProcessRrn());
            Map<String, Object> loopCountInfo = new HashMap<String, Object>();
            loopCountInfo.put("lotRrn", lot.getLotRrn());
            loopCountInfo.put("count", count);
            loopCountInfo.put("loopInfo", loopInfo);
            loopCountInfo.put("transType", TransactionNames.NPWUNITSINIT);
            loopCountInfo.put("reasonCode", "DUMMY-CREATELOT");
            loopCountInfo.put("user", user);
            loopCountInfo.put("reason", "DUMMY投批-units usage 初始化");
            loopCountInfo.put("comments", "DUMMY投批");
            loopCountInfo.put("userRrn", LocalContext.getUserRrn());
            dmmLotService.initDMMUnitCounts(loopCountInfo);
        }
        return mapping.findForward("setup");
    }

}