package com.zy.core.plugin.store;
|
|
import com.core.common.Cools;
|
import com.zy.asrs.domain.param.CreateInTaskParam;
|
import com.zy.asrs.entity.BasDevp;
|
import com.zy.asrs.entity.WrkMast;
|
import com.zy.common.model.StartupDto;
|
import com.zy.core.enums.RedisKeyType;
|
import com.zy.core.model.StationObjModel;
|
import com.zy.core.model.protocol.StationProtocol;
|
|
import java.util.List;
|
|
public interface StoreInTaskPolicy {
|
|
default boolean isEnabled() {
|
return true;
|
}
|
|
default String getPolicyName() {
|
return getClass().getSimpleName();
|
}
|
|
default List<StationObjModel> getBarcodeStations(BasDevp basDevp) {
|
return basDevp.getBarcodeStationList$();
|
}
|
|
boolean matchCandidate(StoreInTaskContext context);
|
|
default boolean beforeApply(StoreInTaskContext context) {
|
return true;
|
}
|
|
default void onRequestPermitGranted(StoreInTaskContext context) {
|
}
|
|
default String getGenerateLockKey(StoreInTaskContext context) {
|
return RedisKeyType.GENERATE_IN_TASK_LIMIT.key + context.getStationObjModel().getStationId();
|
}
|
|
default int getSubmitLockSeconds(StoreInTaskContext context) {
|
return 2;
|
}
|
|
default int getRetryLockSeconds(StoreInTaskContext context) {
|
return 2;
|
}
|
|
default InTaskApplyRequest buildApplyRequest(StoreInTaskContext context) {
|
InTaskApplyRequest request = new InTaskApplyRequest();
|
request.setBarcode(context.getStationProtocol().getBarcode());
|
request.setSourceStaNo(context.getStationProtocol().getStationId());
|
request.setTaskNo(context.getStationProtocol().getTaskNo());
|
request.setLocType1(context.getStationProtocol().getPalletHeight());
|
return request;
|
}
|
|
default CreateInTaskParam buildCreateInTaskParam(StoreInTaskContext context, StartupDto dto) {
|
CreateInTaskParam taskParam = new CreateInTaskParam();
|
taskParam.setTaskNo(dto.getTaskNo());
|
taskParam.setLocNo(dto.getLocNo());
|
taskParam.setTaskPri(dto.getTaskPri());
|
taskParam.setBarcode(context.getStationProtocol().getBarcode());
|
return taskParam;
|
}
|
|
default void afterTaskCreated(StoreInTaskContext context, WrkMast wrkMast) {
|
}
|
|
default void onApplySubmitted(StoreInTaskContext context) {
|
context.getStationProtocol().setSystemWarning("请求入库中");
|
}
|
|
default void onApplyFailed(StoreInTaskContext context, AsyncInTaskResult result) {
|
String warning = "请求入库失败,WMS返回=" + buildFailureMessage(result);
|
context.getStationProtocol().setSystemWarning(warning);
|
syncWarningToBackStation(context, warning);
|
}
|
|
default String buildFailureMessage(AsyncInTaskResult result) {
|
if (!Cools.isEmpty(result.getResponse())) {
|
return result.getResponse();
|
}
|
return result.getMessage();
|
}
|
|
default void syncWarningToBackStation(StoreInTaskContext context, String warning) {
|
if (context == null || context.getStationObjModel() == null || context.getStationThread() == null) {
|
return;
|
}
|
StationObjModel backStation = context.getStationObjModel().getBackStation();
|
if (backStation == null || backStation.getStationId() == null) {
|
return;
|
}
|
if (backStation.getStationId().equals(context.getStationProtocol().getStationId())) {
|
return;
|
}
|
|
List<StationProtocol> stations = context.getStationThread().getStatus();
|
if (stations != null) {
|
for (StationProtocol station : stations) {
|
if (station != null && backStation.getStationId().equals(station.getStationId())) {
|
station.setSystemWarning(warning);
|
return;
|
}
|
}
|
}
|
|
java.util.Map<Integer, StationProtocol> stationMap = context.getStationThread().getStatusMap();
|
if (stationMap == null) {
|
return;
|
}
|
StationProtocol backStationProtocol = stationMap.get(backStation.getStationId());
|
if (backStationProtocol != null) {
|
backStationProtocol.setSystemWarning(warning);
|
}
|
}
|
|
}
|