#
Junjie
1 天以前 7b87595a7379c7b250233e2bfcbf8b44ab4a539d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
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);
        }
    }
 
}