SplitRunCardSplitAction.java
package com.mycim.webapp.actions.splitruncardlot;
import com.fa.sesa.exception.Assert;
import com.fa.sesa.exception.Errors;
import com.fa.sesa.exception.SystemIllegalArgumentException;
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.MapUtils;
import com.mycim.framework.utils.lang.math.NumberUtils;
import com.mycim.framework.utils.msg.JsonUtils;
import com.mycim.valueobject.MessageIdList;
import com.mycim.valueobject.ObjectList;
import com.mycim.valueobject.consts.TransactionNames;
import com.mycim.valueobject.wip.*;
import com.mycim.webapp.actions.RunCardAction;
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.*;
import java.util.regex.Pattern;
/**
* SRC split
*
* @author pinyan.song
* @version 6.0.0
* @date 2020-1-9
**/
public class SplitRunCardSplitAction extends RunCardAction {
/**
* Action 方法: init
*/
@Override
public ActionForward init(ActionMapping mapping, ActionForm form, HttpServletRequest request,
HttpServletResponse response) throws Exception {
String lotId = request.getParameter("lotId");
Lot lot =lotInqService.getLot(lotId);
Assert.state(StringUtils.equals(LotStatus.WAITING, lot.getLotStatus()) ||
StringUtils.equals(LotStatus.RUNCARD_WAITSPLIT, lot.getLotStatus()),
Errors.create().content("Lot Status is :{}").args(lot.getLotStatus()).build());
RunCardLotInfo lotInfo = runCardLotInqService.getRunCardLotInfo(lot.getLotRrn());
//创建了SRC_SPLIT 的SortJob以后,在没有完成SortJob的情况下,不允许在手动Split了。
Long carrierRrn = lotInfo.getCarrierRrn();
this.checkWaitJobs(carrierRrn, 0L, 0L, null);
LotRunCard runcard = lotRunCardQueryService.getLotSplitRunCardSetByLot(lotId);
if (runcard != null) {
String runcardId = getInstanceId(runcard.getRunCardRrn());
String lotCategoryCode = lot.getCreateCategory();
String carrierType = carrierService
.getCarrier(LocalContext.getFacilityRrn(), lotInfo.getCarrierId())
.getObjectSubtype();
request.setAttribute("lot", lot);
request.setAttribute("lotInfo", lotInfo);
request.setAttribute("carrierType", carrierType);
request.setAttribute("lotCategoryCode", lotCategoryCode);
request.setAttribute("runcardId", runcardId);
} else {
throw new SystemIllegalArgumentException(Errors.create().content("Can't split lot.").build());
}
return mapping.getInputForward();
}
/**
* Action 方法: getSplitStepsList
*/
public Map<String, Object> getSplitStepsList(Map<String, Object> params) {
String runcardId = MapUtils.getString(params, "runcardId");
Integer splitSeq = MapUtils.getInteger(params, "splitSeq");
long runcardRrn = getInstanceRrn(runcardId, LocalContext.getFacilityRrn(), ObjectList.ECN_KEY);
List<LotRunCardStep> stepList = lotRunCardQueryService.getLotRunCardStepList(runcardRrn, splitSeq);
List<Map<String, Object>> stepInfoList = new ArrayList<>();
for (LotRunCardStep step : stepList) {
Map<String, Object> stepInfoMap = BeanUtils.copyBeanToMap(step);
stepInfoMap.put("equipmentId", baseService.getNamedObjectId(step.getEquipmentRrn()));
stepInfoMap.put("equipmentGroupId", baseService.getNamedObjectId(step.getEquipmentGroupRrn()));
for (String key : stepInfoMap.keySet()) {
if (MapUtils.getObject(stepInfoMap, key) == null) {
stepInfoMap.put(key, "");
}
}
stepInfoList.add(stepInfoMap);
}
Map<String, Object> returnMap = MapUtils.newHashMap();
returnMap.put("stepList", stepInfoList);
return returnMap;
}
/**
* Action 方法: getSplitedLots
*/
public Map<String, Object> getSplitedLots(Map<String, Object> params) {
String runcardId = MapUtils.getString(params, "runcardId");
long runcardRrn = getInstanceRrn(runcardId, LocalContext.getFacilityRrn(), ObjectList.ECN_KEY);
List<LotRunCardSplit> splitSet = lotRunCardQueryService.getLotRunCardSplit(runcardRrn);
List<LotRunCardStore> storeList = runCardLotInqService.getLotRunCardStoreList(runcardRrn);
List<LotRunCardSplit> returnSplitSet = new ArrayList<>();
List<Map<String,String>> returnSplitLotList = new ArrayList<>();
for (LotRunCardSplit splitInfo : splitSet) {
boolean notSplited = true;
for (LotRunCardStore store : storeList) {
if (Objects.nonNull(store.getSplitSeq()) &&
store.getSplitSeq().intValue() == splitInfo.getSplitSeq().intValue()) {
notSplited = false;
Map<String,String> returnSplitLot = MapUtils.newHashMap();
returnSplitLot.put("showLotId",store.getShowLotId());
returnSplitLot.put("carrierId",store.getCarrierId());
returnSplitLot.put("unitId",splitInfo.getUnitIds());
returnSplitLot.put("lotStatus",lotInqService.getLotStatus(store.getLotRrn()));
returnSplitLotList.add(returnSplitLot);
break;
}
}
if (notSplited) {
returnSplitSet.add(splitInfo);
}
}
Map<String, Object> returnMap = MapUtils.newHashMap();
returnMap.put("splitsList", returnSplitSet);
returnMap.put("childsList", returnSplitLotList);
return returnMap;
}
/**
* Action 方法: splitLots
*/
public void splitLots(Map<String, Object> params) throws Exception {
long facilityRrn = LocalContext.getFacilityRrn();
String lotId = MapUtils.getString(params, "lotId");
String mainLotId = MapUtils.getString(params, "mainLotId");//母批的LOT_ID
String carrierId = MapUtils.getString(params, "carrierId");//目标晶舟的ID
String runcardId = MapUtils.getString(params, "runcardId");
String isMainLot = MapUtils.getString(params, "isMainLot");
int splitSeq = MapUtils.getIntValue(params, "splitSeq");
//isMainLot 值为""时表示为子批,Cassette ID只校验子批
Assert.isFalse(StringUtils.isBlank(carrierId) && StringUtils.isBlank(isMainLot),
Errors.create().key(MessageIdList.CASSETTE_ID_EMPTY)
.content("Cassette ID " + "can " + "not " + "empty!").build());
long runCardRrn = getInstanceRrn(runcardId, facilityRrn, ObjectList.ECN_KEY);
params.put("runCardRrn", runCardRrn);
long carrierRrn = getInstanceRrn(carrierId, getNamedSpace(ObjectList.ENTITY_KEY, facilityRrn),
ObjectList.ENTITY_KEY, ObjectList.CARRIER_KEY);
params.put("carrierRrn", carrierRrn);
//查询 Lotrrn
Lot lot = lotQueryService.getLot(lotId);
Assert.isFalse(lot==null,
Errors.create().key(MessageIdList.LOT_ID_EMPTY)
.content("Lot ID " + "can " + "not " + "empty!").build());
Map<String, Object> lotInfoMap = lotRunCardQueryService.getRCLotInfoMap(lotId);
//创建了SRC_SPLIT 的SortJob以后,在没有完成SortJob的情况下,不允许在手动Split了。
long sourceCarrierRrn = MapUtils.getLong(lotInfoMap, "carrierRrn", -1L);
this.checkWaitJobs(sourceCarrierRrn, carrierRrn, 0L, null);
lotRunCardService.splitRunCardLots(params, LocalContext.getUserId(),StringUtils.toString(lot.getLotRrn()));
}
}