#
zwl
2025-07-19 6193eddf242c4b879402367704b8b5b2e8df84a4
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
package com.zy.asrs.task;
 
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.BasDevp;
import com.zy.asrs.entity.BasShuttle;
import com.zy.asrs.entity.TaskWrk;
import com.zy.asrs.entity.param.GetShuttleStatusParam;
import com.zy.asrs.entity.param.Result;
import com.zy.asrs.service.ApiLogService;
import com.zy.asrs.service.BasDevpService;
import com.zy.asrs.service.BasShuttleService;
import com.zy.common.utils.HttpHandler;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
 
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
 
@Slf4j
@Component
public class GetshuttlerStatusScheduler {
    @Value("${wcs.urlWcs}")
    private String wcsUrl;
    @Value("${wcs.shuttleStatus}")
    private String shuttleStatus;
    @Autowired
    private ApiLogService apiLogService;
    @Autowired
    private BasShuttleService basShuttleService;
    /**
     * 获取rcs小车信息
     *
     * @throws IOException
     */
    @Scheduled(cron = "0/3 * * * * ? ")
    public void execute() throws IOException {
        String response = "";
        Boolean bool = false;
        try {
//            log.info("wcs获取rcs小车信息");
            response = new HttpHandler.Builder()
                    // .setHeaders(headParam)
                    .setUri(wcsUrl)
                    .setPath(shuttleStatus)
                    .setJson(JSON.toJSONString(""))
                    .build()
                    .doPost();
            JSONObject jsonObject = JSON.parseObject(response);
            if (jsonObject.get("code").equals(200)) {
                JSONObject data = JSON.parseObject(jsonObject.get("data").toString());
                List<GetShuttleStatusParam> shuttles = JSON.parseArray(data.get("shuttle").toString(), GetShuttleStatusParam.class);
                for (GetShuttleStatusParam shuttle : shuttles) {
                    //对小车二维码进行处理
                    Integer lev=1;
                    //小车模式
                    Integer mode=0;
                    //小车是否在充电
                    Integer autoCharge=0;
                    if(!Cools.isEmpty(shuttle.getCurrentCode())){
                        JSONObject jsonObject1 = JSON.parseObject(shuttle.getCurrentCode());
                        lev=jsonObject1.getInteger("z");
                    }
                    if(!Cools.isEmpty(shuttle.getMode())){
                        mode=shuttle.getMode();
                    }
                    if(!Cools.isEmpty(shuttle.getHasCharge())&&shuttle.getHasCharge()){
                        mode=2;
                    }
 
                    BasShuttle shuttle1 = basShuttleService.selectOne(new EntityWrapper<BasShuttle>().eq("shuttle_no", shuttle.getShuttleNo()));
                    shuttle1.setStatus(mode);//小车模式
                    shuttle1.setShuttleStatus(shuttle.getProtocolStatus());//小车状态
                    shuttle1.setDeviceStatus(shuttle.getProtocolStatus$());//小车状态中文版
                    shuttle1.setChargeLine(lev);//小车所在层
                    shuttle1.setErrorCode(shuttle.getErrorCode());//异常码
                    basShuttleService.updateById(shuttle1);
                }
 
                bool = true;
            }
        } catch (Exception e) {
            log.error("wcs获取小车状态失败");
        }
 
    }
}