#
Junjie
2026-01-22 afc1bebb2eafc87ba81fb9fe39ef0386d1fb3d17
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
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.zy.asrs.entity.BasStation;
import com.zy.asrs.entity.dto.TvWrkDetlDto;
import com.zy.asrs.entity.dto.WcsStationDto;
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 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;
 
    @Scheduled(cron = "0/3 * * * * ? ")
    public synchronized void execute() {
        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();
        }
    }
 
}