ShipLotAction.java

// Decompiled by DJ v2.8.8.54 Copyright 2000 Atanas Neshkov  Date: 2002-9-6 11:15:32
// Home Page : http://members.fortunecity.com/neshkov/dj.html  - Check often for new version!
// Decompiler options: packimports(3)
package com.mycim.webapp.actions.unit.shipandunshiplot;

import com.fa.sesa.exception.Assert;
import com.fa.sesa.exception.Errors;
import com.fa.sesa.threadlocal.LocalContext;
import com.mycim.framework.utils.beans.BeanUtils;
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.framework.utils.lang.math.NumberUtils;
import com.mycim.valueobject.MessageIdList;
import com.mycim.valueobject.prp.Operation;
import com.mycim.valueobject.wip.Lot;
import com.mycim.valueobject.wip.LotStatus;
import com.mycim.valueobject.wip.TransReason;
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.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

public class ShipLotAction extends WipSetupAction {

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

        return mapping.getInputForward();
    }

    public Map<String, Object> loadWafersByLotId(Map map) {
        long facilityRrn = LocalContext.getFacilityRrn();
        Map msg = new HashMap();
        String lotId = MapUtils.getString(map, "lotIdForWafers");
        Lot lot = lotQueryService.getLot(lotId.trim(), facilityRrn);
        List<Map<String, Object>> unitListByLot = wipQueryService.getUsefulUnits(lot.getLotRrn());
        Assert.isFalse(unitListByLot.size() < 1, Errors.create().key(MessageIdList.SHIPLOT_WAFER_NOT_EXISTS).content(
                "This lot has no wafer! Please check whether the" + " " + "Lot exists").build());
        msg.put("unitLists", unitListByLot);
        return msg;
    }

    public Map<String, Object> addmemberLot(Map map) {
        Map<String, Object> result = new HashMap();
        long facilityRrn = LocalContext.getFacilityRrn();
        String lotId = MapUtils.getString(map, "lotId");
        List<Map<String, Object>> lots = new ArrayList<Map<String, Object>>();
        Lot lot = null;
        Assert.isTrue(StringUtils.isNotBlank(lotId),
                      Errors.create().key(MessageIdList.SHIPLOT_ENTER_LOTID).content("Please enter lot Id!").build());
        lot = lotQueryService.getLot(lotId, facilityRrn);
        Assert.isFalse((lot == null) || (lot.getLotRrn() <= 0),
                       Errors.create().key(MessageIdList.SHIPLOT_LOT_NOT_EXISTS).content("This lot does not exist!")
                             .build());
        if (StringUtils.isNotBlank(lot.getLotStatus())) {
            Assert.isTrue((LotStatus.FINISH.equalsIgnoreCase(lot.getLotStatus())) &&
                                  (!"S".equalsIgnoreCase(lot.getLastScheduleFlag())),
                          Errors.create().key(MessageIdList.SHIPLOT_STATUS_ERROR)
                                .content("Lot: {} can't do ship! " + "Please check lot status!").args(lotId).build());
            // Validate the lot can do the ship
            Long operationRrn = lot.getOperationRrn();
            Operation myoperation = prpService.getOperation(operationRrn);
            Assert.nonNull(myoperation, Errors.create().key(MessageIdList.SHIPLOT_OPERATION_ERROR)
                                              .content("Lot: {} can't do ship! " + "Please check operation!")
                                              .args(lotId).build());
        }
        Long recipeRrn = NumberUtils.toLong(lot.getRecipeId());
        if (recipeRrn > 0) {
            lot.setRecipeId(getInstanceId(recipeRrn));
        }
        Map<String, Object> resultMap = BeanUtils.copyBeanToMap(lot);
        String completedssType = MapUtils.getString(map, "completedssType");
        resultMap.put("storageChoose", MapUtils.getString(map, "storageChoose"));
        resultMap.put("storage", MapUtils.getString(map, "storage"));
        resultMap.put("completedssType", completedssType);
        resultMap.put("completedssLevel", MapUtils.getString(map, "completedssLevel"));
        resultMap.put("dieNums", map.get("dieNums"));
		/*if (CompletedssConstants.COMPLETEDSS_TYPE_DIE.equalsIgnoreCase(completedssType)) {
		    resultMap.put("dieNums", map.get("dieNums"));
		} else {
		    resultMap.put("dieNums", "");
		}*/
        lots.add(resultMap);
        result.put("lots", lots);
        return result;
    }

    public void shipLot(Map map) {
        String user = LocalContext.getUserId();
        Long facilityRrn = LocalContext.getFacilityRrn();
        String fromFacilityId = getInstanceId(facilityRrn);
        String toFacilityId = getInstanceId(MapUtils.getLong(map, "toFacilityRrn"));
        String reason = MapUtils.getString(map, "reason");
        map.put("transPerformedBy", user);
        map.put("toFacilityId", toFacilityId);
        TransReason transReason = new TransReason();
        transReason.setReason(reason);
        transReason.setResponsibility(user);
        map.put("transReason", transReason);
        //mep 中获取 传进来的 lot 数组 抓取 所有rrn
        List dataArray = (ArrayList) map.get("dataArray");
        List<String>lots=new ArrayList<>();
        if(CollectionUtils.isNotEmpty(dataArray)){
            lots = (List<String>) dataArray.stream().map((e)->{
               if(e instanceof  HashMap&&((HashMap<?, ?>) e).containsKey("lotRrn")){
                  return StringUtils.toString(((HashMap) e).get("lotRrn")) ;
               }
               return "";
            }).distinct().collect(Collectors.toList());
        }
        //删除所有空字符串
        lots.remove("");
        //如果为空 则 抛出异常
        Assert.isFalse(CollectionUtils.isEmpty(lots), Errors.create().key(MessageIdList.LOT_LOTRRN_NOT_FOUND)
                                                            .content("LotRrns is Empty!").build());
        boolean completeLotFlag = checkFacilityProperty(fromFacilityId, toFacilityId);
        lotService.shipLot(map,lots);
        if (completeLotFlag) {
            lotService.completeLot(map,lots);
        }
    }

    private boolean checkFacilityProperty(String fromFacility, String toFacility) {
        String data_1_value = sysService
                .referenceDetailExchangeNull("$SHIPFACILITYLIST", fromFacility, toFacility, "DATA_1_VALUE");
        if (data_1_value != null && data_1_value.trim().equalsIgnoreCase("1")) {
            return true;
        } else {
            return false;
        }
    }

}