#
Junjie
2026-02-05 54790321365355fa8007a920e8ccea7d50677354
src/main/java/com/zy/asrs/timer/WmsDataTimer.java
@@ -4,15 +4,17 @@
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.TvWrkDetlDto;
import com.zy.asrs.entity.dto.WcsStationDto;
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;
@@ -34,8 +36,9 @@
    @Autowired
    private RedisUtil redisUtil;
    //WMS任务查询接口
    @Scheduled(cron = "0/3 * * * * ? ")
    public synchronized void execute() {
    public synchronized void taskQuery() {
        Config wmsTaskQueryUrlConfig = configService.selectOne(new EntityWrapper<Config>().eq("code", "wmsTaskQueryUrl"));
        if (wmsTaskQueryUrlConfig == null) {
            return;
@@ -95,4 +98,180 @@
        }
    }
    //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();
        }
    }
}