PrintLabelAction.java

package com.mycim.webapp.actions.lot;

import com.fa.sesa.exception.Assert;
import com.fa.sesa.exception.Errors;
import com.mycim.framework.utils.lang.ObjectUtils;
import com.mycim.framework.utils.lang.StringUtils;
import com.mycim.framework.utils.lang.collections.MapUtils;
import com.mycim.framework.utils.lang.time.DateUtils;
import com.mycim.valueobject.MessageIdList;
import com.mycim.valueobject.consts.ReferenceDetailNames;
import com.mycim.valueobject.prp.ProcessSpecFormDto;
import com.mycim.valueobject.prp.ProcessSpecItemDto;
import com.mycim.valueobject.wip.Lot;
import com.mycim.valueobject.wip.Unit;
import com.mycim.webapp.actions.WipSetupAction;
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.Comparator;
import java.util.HashMap;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @Author: zhen.wang
 * @Date: 2022/1/17 11:00
 */
public class PrintLabelAction extends WipSetupAction {

    public ActionForward init(ActionMapping mapping, ActionForm form, HttpServletRequest request,
                                            HttpServletResponse response) {
        return mapping.getInputForward();
    }

    public Map<String, Object> repeatPrintShippingLabel(Map param) {
        String lotId = MapUtils.getString(param, "lotId");
        Map<String, Object> map = new HashMap<>();
        //检查输入Lot id是否存在
        Assert.state(StringUtils.isNotEmpty(lotId), Errors.create().key(MessageIdList.LOT_ENTER_CORRECT_LOTID).build());
        Lot lot = lotQueryService.getLot(lotId);
        Assert.state(lot.getLotRrn() > 0, Errors.create().key(MessageIdList.LOT_MISSING).content("Lot did not find!").build());
        // 查找flow中的第一个stage为INS-OQI的步骤
        String stageId = sysService.getReferenceFileData1ValueByKey1Value(ReferenceDetailNames.PRINT_SHIPPING_LABEL,"STAGEID");
        if (StringUtils.isEmpty(stageId)) {
            stageId = "";
        }
        ProcessSpecFormDto processSpecForm = new ProcessSpecFormDto();
        processSpecForm.setProcessId(lot.getProcessId());
        processSpecForm.setProcessRrn(lot.getProcessRrn());
        processSpecForm.setProcessVersion(lot.getProcessVersion());
        processSpecForm.setProductId(lot.getProductId());

        String finalStageId = StringUtils.trimToUpperCase(stageId);
        ProcessSpecItemDto processSpecItemDto = processSpecService.queryProcessSpecItems(processSpecForm)
                                 .stream().sorted(Comparator.comparing(ProcessSpecItemDto::getFlowSeq))
                                 .filter(p-> StringUtils.equalsIgnoreCase(p.getStageId(), finalStageId))
                                 .findFirst().orElse(null);
        Assert.state(ObjectUtils.isNotEmpty(processSpecItemDto) &&
                     StringUtils.compare(lot.getFlowSeq(),processSpecItemDto.getFlowSeq()) > 0,
                     Errors.create().key(MessageIdList.LOT_CANNOT_REPEAT_PRINT_LABEL).args(lotId).build());
        map.put("LOTID", StringUtils.replace(lot.getLotId(), ".MAINRC", ""));
        map.put("PRODUCTID", lot.getProductId());
        map.put("LOTTYPE",lot.getLotType());
        map.put("QTY1", lot.getQty1().intValue());
        map.put("DUEDATE", DateUtils.getNowTime(DateUtils.DATE_FORMAT4DAYD));
        String waferIdStr = wipQueryService.getUnitList(lot.getLotRrn()).stream().sorted(Comparator.comparing(Unit::getPositionInCarrier))
                                 .map(unit -> {
                                     if (StringUtils.isEmpty(unit.getUnitId())) {
                                         return StringUtils.EMPTY;
                                     } else {
                                         return StringUtils
                                                 .substring(unit.getUnitId(), unit.getUnitId().length() - 3);
                                     }
                                 }).collect(Collectors.joining(","));
        map.put("WAFERID", waferIdStr);
        return map;
    }
}