SplitRunCardOutAction.java
package com.mycim.webapp.actions.splitruncardlot;
import com.fa.sesa.exception.Assert;
import com.fa.sesa.exception.Errors;
import com.fa.sesa.threadlocal.LocalContext;
import com.mycim.framework.utils.lang.StringUtils;
import com.mycim.framework.utils.lang.collections.MapUtils;
import com.mycim.valueobject.MessageIdList;
import com.mycim.valueobject.consts.TransactionNames;
import com.mycim.valueobject.wip.Lot;
import com.mycim.valueobject.wip.LotRunCard;
import com.mycim.valueobject.wip.LotRunCardStore;
import com.mycim.valueobject.wip.LotStatus;
import com.mycim.valueobject.wip.TransReason;
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.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @author pinyan.song
* @version 6.0.0
* @date 2020-1-10
**/
public class SplitRunCardOutAction extends RunCardAction {
/**
* Action 方法: init
*/
@Override
public ActionForward init(ActionMapping mapping, ActionForm form, HttpServletRequest request,
HttpServletResponse response) throws Exception {
Lot lot = initLotBaseInfoForJsp(request);
// 卡控 cst是否存在 sort job
Map<String, Object> lotInfoMap = lotRunCardQueryService.getRCLotInfoMap(lot.getLotId());
long carrierRrn = MapUtils.getLong(lotInfoMap, "carrierRrn", -1L);
this.checkWaitJobs(carrierRrn, 0L, 0L, null);
return new ActionForward(mapping.getInput());
}
/**
* Action 方法: doOutRC
*/
public void doOutRC(Map<String, Object> params) {
String lotId = MapUtils.getString(params, "lotId");
Lot lot = lotQueryService.getLot(lotId);
String targetFlowSeq = MapUtils.getString(params, "targetFlowSeq");
String targetStepPath = MapUtils.getString(params, "targetStepPath");
String targetOperationRrn = MapUtils.getString(params, "targetOperationRrn");
// 当存在targetFlowSeq时,表示原mergeStep 不存在于当前flow中了
if (StringUtils.isNotBlank(targetFlowSeq) && StringUtils.isNotBlank(targetStepPath) &&
StringUtils.isNotBlank(targetOperationRrn)) {
LotRunCardStore store = lotRunCardQueryService.getSplitRunCardLotStore(lotQueryService.getLotRrn(lotId));
HashMap<String, Object> map = MapUtils.newHashMap();
map.put("mergeFlowSeq", targetFlowSeq);
map.put("mergeStepPath", targetStepPath);
map.put("mergeOperationRrn", targetOperationRrn);
runCardService.updateLotRunCardForMergeStep(store.getRuncardId(), LocalContext.getUserId(), map);
}
String userId = MapUtils.getString(params, "userId");
String reasonCode = MapUtils.getString(params, "reasonCode");
String deptExt = MapUtils.getString(params, "deptExt");
String reason = MapUtils.getString(params, "reason");
reason = reasonCode + " " + StringUtils.trimToUpperCase(deptExt) + " " + userId + " " + reason;
TransReason transReason = new TransReason();
transReason.setReasonCode(reasonCode);
transReason.setReason(reason);
transReason.setResponsibility(userId);
transReason.setTransQty1(lot.getQty1());
transReason.setTransQty2(lot.getQty2());
long runCardRrn = MapUtils.getLongValue(params, "runcardRrn");
LotRunCard lotRunCard = lotRunCardQueryService.getLotRunCard(runCardRrn);
Assert.isFalse(StringUtils.equals(lotRunCard.getStatus(), "CLOSED"),
Errors.create().key(MessageIdList.RUNCARD_STATUS_NOT_ALLOW).content("Runcard status not allow")
.build());
LotRunCardStore lotStore = lotRunCardQueryService.getSplitRunCardLotStore(lot.getLotRrn());
Assert.isTrue(lotStore != null && lotStore.getRuncardRrn() != null &&
lotStore.getRuncardRrn().longValue() == runCardRrn,
Errors.create().key(MessageIdList.RUNCARD_STATUS_NOT_ALLOW).content("Lot back out runcard!")
.build());
if (StringUtils.equals(LotStatus.RUNCARD_WAITFINISH, lot.getLotStatus())) {
lotRunCardService.outSplitRuncard(lot.getLotRrn(), transReason, LocalContext.getUserId());
// doCloseRunCard(lot);
} else {
List<Map<String, Object>> subList = lotRunCardQueryService
.getRunCardLotsByRuncardRrn(lotStore.getRuncardRrn());
if (subList.size() > 1) {
lotRunCardService.finishRunCard(lot.getLotRrn(), transReason, LocalContext.getUserId(),runCardRrn);
// RunCardLot结束,将最后一次moveOut时的设备赋值给主Lot上的Location
//Lot mainLot = getLot(lotStore.getMainLotId(), facilityRrn);
//lotService.changeLotLocationInfoByRunCard(mainLot, runcardRrn, facilityRrn);
} else if (subList.size() == 1) {
lotRunCardService.finishRunCard(lot.getLotRrn(), transReason, LocalContext.getUserId(),runCardRrn);
doCloseRunCard(lot);
}
}
}
/**
* Action 方法: removeRunCard
*/
public void removeRunCard(Map<String, Object> params) {
long runCardRrn = MapUtils.getLongValue(params, "runCardRrn");
String lotId = MapUtils.getString(params, "lotId");
Lot lot = lotQueryService.getLot(lotId);
LotRunCardStore lotStore = lotRunCardQueryService.getSplitRunCardLotStore(lot.getLotRrn());
Assert.isTrue(lotStore != null && lotStore.getRuncardRrn() != null &&
lotStore.getRuncardRrn().longValue() == runCardRrn,
Errors.create().key(MessageIdList.RUNCARD_STATUS_NOT_ALLOW).content("Lot back out runcard!")
.build());
lotRunCardService.removeRunCard(lot, LocalContext.getUserId(),runCardRrn);
// doCloseRunCard(user, userRrn, facilityRrn, lot);
}
}