DiffBatchAction.java
package com.mycim.webapp.actions.diffbatch;
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.context.spring.SpringContext;
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.server.emas.service.EmasService;
import com.mycim.server.wip.service.DiffBatchService;
import com.mycim.valueobject.MessageIdList;
import com.mycim.valueobject.ObjectList;
import com.mycim.valueobject.bas.ErrorMsg;
import com.mycim.valueobject.consts.LotInfoConstants;
import com.mycim.valueobject.consts.ReferenceDetailNames;
import com.mycim.valueobject.consts.ReferenceFileConst;
import com.mycim.valueobject.consts.StepTypeConst;
import com.mycim.valueobject.ems.Equipment;
import com.mycim.valueobject.prp.Operation;
import com.mycim.valueobject.prp.RecipeStatus;
import com.mycim.valueobject.prp.RecipeVersion;
import com.mycim.valueobject.runcard.util.RunCardUtils;
import com.mycim.valueobject.wip.*;
import com.mycim.webapp.Constants;
import com.mycim.webapp.WebUtils;
import com.mycim.webapp.actions.WipSetupAction;
import com.mycim.webapp.forms.RootForm;
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.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
* @author Johnson.Wang
* @version 6.0.0
* @date 2019/9/24
**/
public class DiffBatchAction extends WipSetupAction {
protected DiffBatchService diffBatchService = SpringContext.getBean(DiffBatchService.class);
private EmasService emasService = SpringContext.getBean(EmasService.class);
@Override
public ActionForward init(ActionMapping mapping, ActionForm form, HttpServletRequest request,
HttpServletResponse response) throws Exception {
request.setAttribute("operate_panel", "operate_panel");
return (mapping.findForward(Constants.ERROR_KEY));
}
public ActionForward initBatch(ActionMapping mapping, ActionForm form, HttpServletRequest request,
HttpServletResponse response) {
List<Lot> normalLotList = new ArrayList<>();
List<RunCardLotInfo> runCardLotList = new ArrayList<>();
int cou = WebUtils.getParameterInt("cou", request);
long eqptRrn = NumberUtils.toLong(request.getParameter("eqptRrn"));
Equipment equipment = emsService.getEquipment(eqptRrn);
// 检查设备上recipe失效间隔限制
emsService.checkEquipmentRecipeInvalid(equipment.getInstanceRrn());
List<Map<String, Object>> recipes = recipeService.getRecipeList4Equipment(equipment.getInstanceRrn());
// check product constrain
Long recipeRrn = null;
String pollutionLevel = null;
for (int i = 0; i < cou; i++) {
String lotId = WebUtils.getParameter("lotId" + i, request);
Lot lot = lotInqService.getLot(lotId);
if (LotStatus.isRunCardHold(lot.getLotStatus())) {
lot = lotInqService.getLot(RunCardUtils.buildMainRcLotId(lotId));
}
Assert.state(!diffBatchQueryService.checkLotInBatch(lot.getLotRrn()),
Errors.create().key(MessageIdList.BATCH_LOT_IN).args(lotId).build());
Assert.state(LotStatus.isMoveInCheckStatus(lot.getLotStatus()),
Errors.create().key(MessageIdList.LOT_STATUS_NOT_ALLOW).build());
String recipePhysicalId = StringUtils.EMPTY;
if(LotInfoConstants.SysType.isRunCardLot(lot.getSysType())) {
recipePhysicalId = lot.getRecipeId();
}
if (RunCardUtils.checkLotIdIsRunCardLot(lot.getLotId())) {
RunCardLotInfo runCardLotInfo = lotRunCardQueryService.getRunCardLotInfo(lot.getLotId());
recipePhysicalId = runCardLotInfo == null ? StringUtils.EMPTY : runCardLotInfo.getRecipeId();
runCardLotList.add(runCardLotInfo);
} else {
lot.setEqptID(equipment.getInstanceId());
RecipeVersion version = recipeService.getLotRecipe(lot);
recipePhysicalId = version == null ? StringUtils.EMPTY : version.getPpid();
normalLotList.add(lot);
}
Assert.isFalse(StringUtils.isBlank(recipePhysicalId),
Errors.create().key(MessageIdList.RECIPE_MISSING_GET_RECIPE)
.content("Do not get the Recipe ID, please confirm!").build());
boolean isRecipeOk = false;
long physicalRecipeRrn = baseService.getNamedObjectRrn(recipePhysicalId,
getNamedSpace(ObjectList.RECIPE_KEY,
LocalContext.getFacilityRrn()),
ObjectList.RECIPE_KEY);
Assert.isFalse(physicalRecipeRrn <= 0, Errors.create().key(MessageIdList.RECIPE_NOT_DEFINED)
.content("The recipe is not defined in the system!").build());
for (Map<String, Object> recipe : recipes) {
String status = MapUtils.getString(recipe, "status");
if (StringUtils.equalsIgnoreCase(recipePhysicalId, MapUtils.getString(recipe, "recipeId")) &&
RecipeStatus.isAvailable(status)) {
isRecipeOk = true;
break;
}
}
Assert.state(isRecipeOk, Errors.create().key(MessageIdList.RECIPE_RECIPE_NOT_SAME).content(
"The available recipe and lot on the EQP.: {} Recipe does not match!").args(lotId).build());
if (recipeRrn == null) {
recipeRrn = physicalRecipeRrn;
} else {
Assert.isFalse(recipeRrn.longValue() != physicalRecipeRrn,
Errors.create().key(MessageIdList.RECIPE_RECIPE_DIFFERENT).content("Recipe different!")
.build());
}
ErrorMsg errorMsg = constrainService.checkLotConstrain(equipment, lot);
Assert.isFalse(errorMsg.getError(), Errors.create().content(errorMsg.getErrorMsg()).build());
if (StringUtils.isNotBlank(lot.getPollutionLevel())) {
if (pollutionLevel == null) {
pollutionLevel = lot.getPollutionLevel();
}
Assert.isTrue(StringUtils.equals(pollutionLevel, lot.getPollutionLevel()),
Errors.create().key(MessageIdList.TRACK_CONTAMINATION_DIFFERENT)
.content("Contamination different!").build());
} else {
Assert.isFalse(StringUtils.isNotBlank(pollutionLevel),
Errors.create().key(MessageIdList.TRACK_CONTAMINATION_DIFFERENT)
.content("Contamination different!").build());
}
lot.setRecipePhysicalId(recipePhysicalId);
}
if (CollectionUtils.isEmpty(normalLotList) && CollectionUtils.isEmpty(runCardLotList)) {
Assert.isFalse(request.getParameter(Constants.CREATE_KEY) != null,
Errors.create().key(MessageIdList.BATCH_NOT_SELECT_LOT)
.content("No lot selected to be created !").build());
Assert.isTrue(request.getParameter(Constants.CREATE_KEY) != null,
Errors.create().key(MessageIdList.BATCH_DELETE_LOTS_USE_CANCELJOB)
.content("Use cancel job to delete all lots in job list").build());
}
if(CollectionUtils.isNotEmpty(normalLotList)) {
ErrorMsg errorMsg = constrainService.checkLotListConstrain(equipment,normalLotList);
Assert.isFalse(errorMsg.getError(), Errors.create().content(errorMsg.getErrorMsg()).build());
}
request.setAttribute("recipeRrn", recipeRrn);
checkNormalLotOperationInfo(normalLotList);
request.setAttribute("lots", normalLotList);
request.setAttribute("runcardLots", runCardLotList);
String eqptId = getInstanceId(eqptRrn);
request.setAttribute("eqptRrn", eqptRrn);
request.setAttribute("eqptId", eqptId);
List<EqpRcpDiffBatchSetupInfo> diffBatchSetupInfoList = diffBatchQueryService.getEqpRecipeDiffBatchSet(eqptRrn);
for (EqpRcpDiffBatchSetupInfo setupInfo : diffBatchSetupInfoList) {
if (setupInfo.getRecipeRrn().longValue() == recipeRrn.longValue()) {
request.setAttribute("needMonitor", NumberUtils.INTEGER_ONE);
request.setAttribute("monitorProductRrn", setupInfo.getMonitorProductRrn());
}
}
String batchId = diffBatchQueryService.buildBatchId(eqptId);
request.setAttribute("batchId", batchId);
return mapping.findForward("batchset");
}
private void checkNormalLotOperationInfo(List<Lot> normalLotList) {
// end
//rc+rc 组batch 会调用这里
if(CollectionUtils.isEmpty(normalLotList)){//没有normal lot 则不检查
return;
}
Lot slot = normalLotList.iterator().next();
String operationId = slot.getOperationId();
Operation operation = prpService.getOperation(operationId, LocalContext.getFacilityRrn());
for (Lot lotInfo : normalLotList) {
String lotOperationId = lotInfo.getOperationId();
Operation lotOperation = prpService.getOperation(lotOperationId, LocalContext.getFacilityRrn());
if (lotOperation != null) {
lotOperation.setObjectType(lotQueryService.getOperationType(lotInfo));
Assert.isTrue(StepTypeConst.isProcessingStep(lotOperation.getObjectType()),
Errors.create().key(MessageIdList.STEP_TYPE_MUST_P)
.content("Step: {} step type must be P").args(lotOperation.getInstanceId())
.build());
}
Assert.isTrue(StringUtils.equals(operation.getMvinWflId(), lotOperation.getMvinWflId()),
Errors.create().key(MessageIdList.BATCH_START_ROUTINE_NOT_SAME).content(
"The Lot's Start Routine not same,please re-select Lots with same Start Routine!")
.build());
Assert.isTrue(StringUtils.equals(operation.getMvouWflId(), lotOperation.getMvouWflId()),
Errors.create().key(MessageIdList.BATCH_ENT_ROUTINE_NOT_SAME)
.content("The Lot's End Routine not same,please re-select Lots with same End Routine!")
.build());
}
}
public String validateEqpDiffFlag(Map form) {
long eqptRrn = MapUtils.getLongValue(form, "eqptRrn");
Map entityExtMap = emsService.getEquipmentExtMap(eqptRrn);
return MapUtils.getString(entityExtMap, "diffFlag", StringUtils.EMPTY);
}
public ActionForward createBatch(ActionMapping mapping, HttpServletRequest request) {
Long eqptRrn = NumberUtils.toLong(request.getParameter("eqptRrn"));
String eqptId = getInstanceId(eqptRrn);
String batchId = request.getParameter("batchId");
long recipeRrn = NumberUtils.toLong(request.getParameter("recipeRrn"));
String oraBatchId = diffBatchQueryService.buildBatchId(eqptId);
Assert.isTrue(StringUtils.equalsIgnoreCase(batchId, oraBatchId),
Errors.create().key(MessageIdList.BATCH_BATCH_ID_HAS_USED).content("batch id已经被使用").build());
Lot monitorLot = null;
if (StringUtils.isNotBlank(request.getParameter("monitorLotId"))) {
monitorLot = lotQueryService.getLot(request.getParameter("monitorLotId"), LocalContext.getFacilityRrn());
Assert.isFalse(monitorLot == null || monitorLot.getLotRrn() <= 0,
Errors.create().key(MessageIdList.UNFINISHLOT_NOT_FIND_LOT).content("Cannot Find Lot!")
.build());
List<EqpRcpDiffBatchSetupInfo> diffBatchSetupInfoList = diffBatchQueryService
.getEqpRecipeDiffBatchSet(eqptRrn);
for (EqpRcpDiffBatchSetupInfo setupInfo : diffBatchSetupInfoList) {
Assert.isFalse(setupInfo.getRecipeRrn().longValue() == recipeRrn &&
monitorLot.getInt_qty1().intValue() < setupInfo.getMonitorLimit().intValue(),
Errors.create().content("Monitor lot Qty must more than {}")
.args(setupInfo.getMonitorLimit()).build());
}
List lots = lotInqService.getLotListByCarrierId(monitorLot.getCarrierId());
Assert.state(lots.size() == 1, Errors.create().content("Monitor Lot carrier not the single type").build());
} else {
List<EqpRcpDiffBatchSetupInfo> diffBatchSetupInfoList = diffBatchQueryService.getEqpRecipeDiffBatchSet(eqptRrn);
for (EqpRcpDiffBatchSetupInfo setupInfo : diffBatchSetupInfoList) {
if (setupInfo.getRecipeRrn().longValue() == recipeRrn) {
Assert.state(StringUtils.isNotBlank(request.getParameter("monitorLotId")),
Errors.create().key(MessageIdList.BATCH_HAS_MONITOR).build());
}
}
}
List<BatchLotStore> batchList = new ArrayList<BatchLotStore>();
String[] lotIds = request.getParameterValues("lotIds");
for (int i = 0; i < lotIds.length; i++) {
String lotId = lotIds[i];
Lot lot = lotQueryService.getLot(lotId, LocalContext.getFacilityRrn());
BatchLotStore lotStore = new BatchLotStore();
if (monitorLot != null) {
lotStore.setMonitorLotId(monitorLot.getLotId());
lotStore.setMonitorLotRrn(monitorLot.getLotRrn());
}
lotStore.setLotId(lot.getLotId());
lotStore.setLotRrn(lot.getLotRrn());
lotStore.setLotStepSequence(lot.getStepSequence());
lotStore.setLotSeq(i + 1);
lotStore.setEqptId(eqptId);
lotStore.setEqptRrn(eqptRrn);
lotStore.setBatchId(batchId);
lotStore.setRecipeId(getInstanceId(recipeRrn));
lotStore.setRecipeRrn(recipeRrn);
batchList.add(lotStore);
}
diffBatchService.saveBatchLotsInfo(batchList);
request.setAttribute("endDispatchPage", NumberUtils.INTEGER_ONE);
return mapping.findForward("batchset");
}
public Lot getMonitorLot(String monitorLotId) {
Lot lot = lotInqService.getLot(monitorLotId);
Assert.isFalse(lot == null || lot.getLotRrn() <= 0,
Errors.create().key(MessageIdList.LOT_LOTRRN_NOT_FOUND).content("Cannot Find Lot!").build());
Assert.isTrue(checkLotIsMonitorLot(lot),
Errors.create().key(MessageIdList.MONITOR_NOT_FOUND).content("Monitor is not found!").build());
Assert.isFalse(diffBatchQueryService.checkLotInBatch(lot.getLotRrn()),
Errors.create().content("Lot:{} had batch").args(lot.getLotId()).build());
String lotCategoryStr = sysService
.getRefFileValue(ReferenceDetailNames.LOT_CREATE_CATEGORY, lot.getCreateCategory(),
ReferenceFileConst.DATA_1_VALUE);
lot.setCreateCategory(lotCategoryStr);
return lot;
}
public ActionForward deletBatchPage(ActionMapping mapping, ActionForm form, HttpServletRequest request,
HttpServletResponse response) {
String[] lotRrns = StringUtils.split(request.getParameter("lotList"), "#");
if (lotRrns != null && lotRrns.length > 0) {
String batchId = null;
List<BatchLotStore> batchList = new ArrayList<BatchLotStore>();
for (int i = 0; i < lotRrns.length; i++) {
Lot _lot = lotInqService.getLot(new Long(lotRrns[i]).longValue());
batchList = diffBatchQueryService.getBatchStoreListByLot(_lot.getLotRrn());
Assert.isFalse(CollectionUtils.isEmpty(batchList),
Errors.create().content("Lot:{} not in batch").args(_lot.getLotId()).build());
if (StringUtils.isBlank(batchId)) {
batchId = batchList.iterator().next().getBatchId();
} else {
Assert.isTrue(StringUtils.equalsIgnoreCase(batchId, batchList.iterator().next().getBatchId()),
Errors.create().content("Lot's not in same batch !!").build());
}
}
List<Lot> lots = new ArrayList<Lot>();
for (BatchLotStore bond : batchList) {
Lot _lot = lotInqService.getLot(bond.getLotRrn());
buildRecipeId(_lot);
String lotCategoryStr = sysService.getRefFileValue("$LOT_CREATE_CATEGORY", _lot.getCreateCategory(),
ReferenceFileConst.DATA_1_VALUE);
_lot.setCreateCategory(lotCategoryStr);
lots.add(_lot);
request.setAttribute("lotRrn", _lot.getLotRrn());
}
if (batchList.size() > 0 && batchList.get(0).getMonitorLotRrn() != null &&
batchList.get(0).getMonitorLotRrn().longValue() > 0) {
Lot monitorLot = lotInqService.getLot(batchList.get(0).getMonitorLotRrn());
request.setAttribute("monitorLot", monitorLot);
}
request.setAttribute("batchId", batchId);
request.setAttribute("lots", lots);
long eqptRrn = NumberUtils.toLong(request.getParameter("eqptRrn"));
String eqptId = getInstanceId(eqptRrn);
request.setAttribute("eqptRrn", eqptRrn);
request.setAttribute("eqptId", eqptId);
} else if (StringUtils.isNotBlank(request.getParameter("lotRrn"))) {
Long lotRrn = NumberUtils.toLong(request.getParameter("lotRrn"));
List<BatchLotStore> batchList = diffBatchQueryService.getBatchStoreListByLot(lotRrn);
if (batchList.size() > 0) {
List<Lot> lots = new ArrayList<Lot>();
for (BatchLotStore bond : batchList) {
Lot _lot = lotInqService.getLot(bond.getLotRrn());
buildRecipeId(_lot);
String lotCategoryStr = sysService.getRefFileValue("$LOT_CREATE_CATEGORY", _lot.getCreateCategory(),
ReferenceFileConst.DATA_1_VALUE);
_lot.setCreateCategory(lotCategoryStr);
lots.add(_lot);
request.setAttribute("lotRrn", _lot.getLotRrn());
}
if (batchList.get(0).getMonitorLotRrn() != null &&
batchList.get(0).getMonitorLotRrn().longValue() > 0) {
Lot monitorLot = lotInqService.getLot(batchList.get(0).getMonitorLotRrn());
request.setAttribute("monitorLot", monitorLot);
}
request.setAttribute("batchId", batchList.get(0).getBatchId());
request.setAttribute("lots", lots);
request.setAttribute("byLot", "1");
if (StringUtils.isNotBlank(request.getParameter("viewWindow"))) {
request.setAttribute("viewWindow", "1");
}
}
} else {
throw new SystemIllegalArgumentException(Errors.create().content("Lot can't be empty!").build());
}
return mapping.findForward("debatch");
}
public ActionForward deletBatch(ActionMapping mapping, ActionForm form, HttpServletRequest request,
HttpServletResponse response) throws Exception {
String user = LocalContext.getUserId();
RootForm theform = (RootForm) form;
String reason = theform.getReasonCode() + " " + theform.getDeptExt().trim().toUpperCase() + " " + user + " " +
theform.getReason();
String comments = request.getParameter("comments");
Assert.isFalse(reason != null && reason.getBytes(StandardCharsets.UTF_8).length > 1024,
Errors.create().content("The input content exceeds the length limit!").build());
TransReason transReason = new TransReason();
transReason.setReasonCode(theform.getReasonCode());
transReason.setReason(reason);
transReason.setResponsibility(user);
String batchId = request.getParameter("batchId");
if (StringUtils.isNotBlank(batchId)) {
diffBatchService.deBatchLots(batchId, user, transReason, comments);
}
if (StringUtils.isNotBlank(request.getParameter("byLot"))) {
return searchBatch(mapping, theform, request, response);
}
request.setAttribute("endCancelJobPage", "1");
return mapping.findForward("debatch");
}
public ActionForward searchBatch(ActionMapping mapping, ActionForm form, HttpServletRequest request,
HttpServletResponse response) {
String batchId = WebUtils.getParameterUpperCase("batchId", request);
String eqptId = WebUtils.getParameterUpperCase("eqptId", request);
boolean showAll = StringUtils.isNotBlank(request.getParameter("showAll"));
if (StringUtils.isNotBlank(batchId)) {
showAll = true;
}
BatchLotStore storeCondition = new BatchLotStore();
storeCondition.setBatchId(batchId);
storeCondition.setEqptId(eqptId);
if (StringUtils.isBlank(request.getParameter("init"))) {
List<Map<String, Object>> list = diffBatchQueryService.getBatchLotStoreHistory(storeCondition, showAll);
request.setAttribute("batchList", list);
}
request.setAttribute("batchId", batchId);
request.setAttribute("eqptId", eqptId);
if (StringUtils.isNotBlank(request.getParameter("viewWindow"))) {
request.setAttribute("viewWindow", "1");
}
return mapping.findForward("searchbatch");
}
public ActionForward viewBatch(ActionMapping mapping, ActionForm form, HttpServletRequest request,
HttpServletResponse response) {
String lotList = request.getParameter("lotList");
String[] lotRrns = lotList.split("#");
Assert.isTrue(lotRrns.length > 0,
Errors.create().key(MessageIdList.LOT_ID_EMPTY).content("Lot Id can't be Empty!").build());
String batchId = null;
List<BatchLotStore> batchList = new ArrayList<BatchLotStore>();
for (int i = 0; i < lotRrns.length; i++) {
Lot _lot = lotInqService.getLot(new Long(lotRrns[i]).longValue());
batchList = diffBatchQueryService.getBatchStoreListByLot(_lot.getLotRrn());
Assert.isFalse(CollectionUtils.isEmpty(batchList),
Errors.create().content("Lot:{} not in batch").args(_lot.getLotId()).build());
if (StringUtils.isBlank(batchId)) {
batchId = batchList.iterator().next().getBatchId();
} else {
Assert.isTrue(StringUtils.equalsIgnoreCase(batchId, batchList.iterator().next().getBatchId()),
Errors.create().content("Lot's not in same batch !").build());
}
}
List<Lot> lots = new ArrayList<Lot>();
for (BatchLotStore bond : batchList) {
Lot _lot = lotInqService.getLot(bond.getLotRrn());
buildRecipeId(_lot);
String lotCategoryStr = sysService
.getRefFileValue("$LOT_CREATE_CATEGORY", _lot.getCreateCategory(), ReferenceFileConst.DATA_1_VALUE);
_lot.setCreateCategory(lotCategoryStr);
lots.add(_lot);
}
if (batchList.size() > 0 && batchList.get(0).getMonitorLotRrn() != null &&
batchList.get(0).getMonitorLotRrn().longValue() > 0) {
Lot monitorLot = lotInqService.getLot(batchList.get(0).getMonitorLotRrn());
request.setAttribute("monitorLot", monitorLot);
request.setAttribute("needMonitor", "1");
}
request.setAttribute("viewBatch", "1");
request.setAttribute("batchId", batchId);
request.setAttribute("lots", lots);
long eqptRrn = NumberUtils.toLong(request.getParameter("eqptRrn"));
String eqptId = getInstanceId(eqptRrn);
request.setAttribute("eqptRrn", eqptRrn);
request.setAttribute("eqptId", eqptId);
return mapping.findForward("batchset");
}
public String checkEmasByBatch(Map map) {
Long eqptRrn = NumberUtils.toLong(MapUtils.getString(map, "eqptRrn"));
String eqptId = getInstanceId(eqptRrn);
long recipeRrn = NumberUtils.toLong(MapUtils.getString(map, "recipeRrn"));
String recipeId = getInstanceId(recipeRrn);
return emasService.checkByBatchEmas(eqptId, recipeId);
}
private boolean checkLotIsMonitorLot(Lot lot) {
if (LotInfoConstants.isCategoryC(lot.getCreateCategory())) {
return true;
}
return false;
}
}