#
Junjie
2026-02-05 54790321365355fa8007a920e8ccea7d50677354
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
package com.zy.asrs.timer;
 
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.core.common.Cools;
import com.zy.asrs.entity.BasStation;
import com.zy.asrs.entity.dto.*;
import com.zy.asrs.enums.RedisKeyType;
import com.zy.asrs.service.BasStationService;
import com.zy.asrs.utils.StationUtils;
import com.zy.common.utils.HttpHandler;
import com.zy.common.utils.RedisUtil;
import com.zy.system.entity.Config;
import com.zy.system.service.ConfigService;
import lombok.Synchronized;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
 
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.concurrent.TimeUnit;
 
@Component
public class WmsDataTimer {
 
    @Autowired
    private ConfigService configService;
    @Autowired
    private BasStationService basStationService;
    @Autowired
    private StationUtils stationUtils;
    @Autowired
    private RedisUtil redisUtil;
 
    //WMS任务查询接口
    @Scheduled(cron = "0/3 * * * * ? ")
    public synchronized void taskQuery() {
        Config wmsTaskQueryUrlConfig = configService.selectOne(new EntityWrapper<Config>().eq("code", "wmsTaskQueryUrl"));
        if (wmsTaskQueryUrlConfig == null) {
            return;
        }
 
        String wmsTaskQueryUrl = wmsTaskQueryUrlConfig.getValue();
 
        String response = null;
        try {
            HashMap<String, Object> requestParam = new HashMap<>();
 
            List<BasStation> basStations = basStationService.selectList(new EntityWrapper<BasStation>().eq("out_enable", "Y"));
            for (BasStation basStation : basStations) {
                WcsStationDto wcsStationDto = stationUtils.stationMap.get(basStation.getStationId());
                if (wcsStationDto == null) {
                    continue;
                }
 
                if (wcsStationDto.getAuto() != 1
                        || wcsStationDto.getLoading() != 1
                        || wcsStationDto.getTaskNo().equals("0")
                ) {
                    continue;
                }
 
                requestParam.put("taskNo", wcsStationDto.getTaskNo());
                response = new HttpHandler.Builder()
                        .setUri(wmsTaskQueryUrl)
                        .setJson(JSON.toJSONString(requestParam))
                        .setTimeout(30, TimeUnit.SECONDS)
                        .build()
                        .doPost();
                if (response != null) {
                    JSONObject jsonObject = JSON.parseObject(response);
                    JSONObject data = jsonObject.getJSONObject("data");
 
                    List<TvWrkDetlDto> list = new ArrayList<>();
                    for (Object o : data.getJSONArray("wrkDetls")) {
                        JSONObject wrkDetl = (JSONObject) o;
                        TvWrkDetlDto tvWrkDetlDto = new TvWrkDetlDto();
                        list.add(tvWrkDetlDto);
 
                        tvWrkDetlDto.setMatnr(wrkDetl.getString("matnr"));
                        tvWrkDetlDto.setMaktx(wrkDetl.getString("maktx"));
                        tvWrkDetlDto.setSpecs(wrkDetl.getString("specs"));
                        tvWrkDetlDto.setBatch(wrkDetl.getString("batch"));
                        tvWrkDetlDto.setAnfme(wrkDetl.getDouble("anfme"));
                    }
 
                    wcsStationDto.setIoType(data.getInteger("ioType"));
                    wcsStationDto.setWrkDetls(list);
                    stationUtils.stationMap.put(wcsStationDto.getStationId(), wcsStationDto);
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
 
    //WMS入库任务查询接口
    @Scheduled(cron = "0/3 * * * * ? ")
    public synchronized void inTaskQuery() {
        Config wmsCombQueryUrlConfig = configService.selectOne(new EntityWrapper<Config>().eq("code", "wmsCombQueryUrl"));
        if (wmsCombQueryUrlConfig == null) {
            return;
        }
 
        String wmsCombQueryUrl = wmsCombQueryUrlConfig.getValue();
 
        String response = null;
        try {
            HashMap<String, Object> requestParam = new HashMap<>();
 
            List<BasStation> basStations = basStationService.selectList(new EntityWrapper<BasStation>().eq("in_enable", "Y"));
            for (BasStation basStation : basStations) {
                WcsStationDto wcsStationDto = stationUtils.stationMap.get(basStation.getStationId());
                if (wcsStationDto == null) {
                    continue;
                }
 
                if (wcsStationDto.getAuto() != 1
                        || wcsStationDto.getLoading() != 1
                ) {
                    continue;
                }
 
                if (Cools.isEmpty(wcsStationDto.getBarcode())) {
                    continue;
                }
 
                requestParam.put("barcode", wcsStationDto.getBarcode());
                response = new HttpHandler.Builder()
                        .setUri(wmsCombQueryUrl)
                        .setJson(JSON.toJSONString(requestParam))
                        .setTimeout(30, TimeUnit.SECONDS)
                        .build()
                        .doPost();
                if (response != null) {
                    JSONObject jsonObject = JSON.parseObject(response);
                    JSONObject data = jsonObject.getJSONObject("data");
 
                    List<TvWrkDetlDto> list = new ArrayList<>();
                    for (Object o : data.getJSONArray("combDetls")) {
                        JSONObject wrkDetl = (JSONObject) o;
                        TvWrkDetlDto tvWrkDetlDto = new TvWrkDetlDto();
                        list.add(tvWrkDetlDto);
 
                        tvWrkDetlDto.setMatnr(wrkDetl.getString("matnr"));
                        tvWrkDetlDto.setMaktx(wrkDetl.getString("maktx"));
                        tvWrkDetlDto.setSpecs(wrkDetl.getString("specs"));
                        tvWrkDetlDto.setBatch(wrkDetl.getString("batch"));
                        tvWrkDetlDto.setAnfme(wrkDetl.getDouble("anfme"));
                    }
 
                    wcsStationDto.setIoType(1);
                    wcsStationDto.setWrkDetls(list);
                    stationUtils.stationMap.put(wcsStationDto.getStationId(), wcsStationDto);
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
 
    //WMS库存数据查询
    @Synchronized
    @Scheduled(cron = "0/3 * * * * ? ")
    public void locQuery() {
        Config wmsUrlConfig = configService.selectOne(new EntityWrapper<Config>().eq("code", "wmsLocQueryUrl"));
        if (wmsUrlConfig == null) {
            return;
        }
 
        String wmsUrl = wmsUrlConfig.getValue();
 
        String response = null;
        try {
            response = new HttpHandler.Builder()
                    .setUri(wmsUrl)
                    .setTimeout(30, TimeUnit.SECONDS)
                    .build()
                    .doGet();
            if (response != null) {
                JSONObject jsonObject = JSON.parseObject(response);
                JSONObject data = jsonObject.getJSONObject("data");
 
                TvLocDataDto tvLocDataDto = new TvLocDataDto();
                tvLocDataDto.setEmptyCount(data.getInteger("emptyCount"));
                tvLocDataDto.setDisableCount(data.getInteger("disableCount"));
                tvLocDataDto.setTotal(data.getInteger("total"));
                tvLocDataDto.setStockCount(data.getInteger("stockCount"));
                tvLocDataDto.setUsedPr(data.getDouble("usedPr"));
                tvLocDataDto.setUsed(data.getInteger("used"));
 
                List<CommonNvDto> pieList = new ArrayList<>();
                JSONArray list = data.getJSONArray("pie");
                for (Object o : list) {
                    CommonNvDto commonNvDto = JSON.parseObject(JSON.toJSONString(o), CommonNvDto.class);
                    pieList.add(commonNvDto);
                }
 
                tvLocDataDto.setPie(pieList);
 
                redisUtil.set(RedisKeyType.TV_LOC_DATA_DTO.key, JSON.toJSONString(tvLocDataDto));
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
 
    //WMS入出库折线图
    @Synchronized
    @Scheduled(cron = "0/3 * * * * ? ")
    public void inOutLineCharts() {
        Config wmsUrlConfig = configService.selectOne(new EntityWrapper<Config>().eq("code", "wmsInOutLineChartsQueryUrl"));
        if (wmsUrlConfig == null) {
            return;
        }
 
        String wmsUrl = wmsUrlConfig.getValue();
 
        String response = null;
        try {
            response = new HttpHandler.Builder()
                    .setUri(wmsUrl)
                    .setTimeout(30, TimeUnit.SECONDS)
                    .build()
                    .doGet();
            if (response != null) {
                JSONObject jsonObject = JSON.parseObject(response);
                JSONObject data = jsonObject.getJSONObject("data");
 
                redisUtil.set(RedisKeyType.TV_LINE_CHARTS.key, JSON.toJSONString(data));
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
 
    //WMS库存数据统计
    @Synchronized
    @Scheduled(cron = "0/3 * * * * ? ")
    public void locDetlStatistics() {
        Config wmsUrlConfig = configService.selectOne(new EntityWrapper<Config>().eq("code", "wmsLocDetlStatisticsQueryUrl"));
        if (wmsUrlConfig == null) {
            return;
        }
 
        String wmsUrl = wmsUrlConfig.getValue();
 
        String response = null;
        try {
            response = new HttpHandler.Builder()
                    .setUri(wmsUrl)
                    .setTimeout(30, TimeUnit.SECONDS)
                    .build()
                    .doGet();
            if (response != null) {
                JSONObject jsonObject = JSON.parseObject(response);
                JSONObject data = jsonObject.getJSONObject("data");
 
                List<TvLocDetlStatisticsDto> list = new ArrayList<>();
                JSONArray records = data.getJSONArray("records");
                for (Object record : records) {
                    TvLocDetlStatisticsDto tvLocDetlStatisticsDto = JSON.parseObject(JSON.toJSONString(record), TvLocDetlStatisticsDto.class);
                    list.add(tvLocDetlStatisticsDto);
                }
 
                redisUtil.set(RedisKeyType.TV_LOC_DETL_STATISTICS.key, JSON.toJSONString(list));
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
 
}