1
zhang
2025-09-08 5936220e860f561ff100a9eef4fbd5471c195946
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
package com.zy.asrs.controller;
 
import com.core.common.R;
import com.zy.asrs.domain.param.AskStaParam;
import com.zy.asrs.domain.param.TaskReportParam;
import com.zy.asrs.service.LocMastService;
import com.zy.asrs.service.impl.CtuMainServiceImpl;
import com.zy.common.web.BaseController;
import com.zy.core.DevpThread;
import com.zy.core.cache.MessageQueue;
import com.zy.core.cache.SlaveConnection;
import com.zy.core.enums.SlaveType;
import com.zy.core.model.Task;
import com.zy.core.model.protocol.StaProtocol;
import com.zy.core.thread.SiemensDevpThread;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
 
import java.util.ArrayList;
import java.util.Map;
import java.util.Random;
 
/**
 * Created by vincent on 2022/4/8
 */
@Slf4j
@RestController
@RequestMapping("open/asrs")
public class OpenController extends BaseController {
 
 
    @Autowired
    private LocMastService locMastService;
 
 
    @Autowired
    private CtuMainServiceImpl ctuMainService;
 
 
    @Value("${ctu.url}")
    private String ctuUrl;
 
    @Value("${ctu.locSync}")
    private String locSync;
 
    private static final boolean auth = true;
 
    public static final ArrayList<String> APP_KEY_LIST = new ArrayList<String>() {{
        add("ea1f0459efc02a79f046f982767939ae");
    }};
 
 
    private String getLocSts(Long sts) {
        //15    IDLE    空闲
        //16    STOCK    在库
        //17    PAKIN    入库预约
        //18    PAKOUT    出库预约
        //19    DISABLED    禁用
        switch (sts.intValue()) {
            case 15:
                return "O";
            case 16:
                return "F";
            case 17:
                return "S";
            case 18:
                return "R";
            case 19:
                return "X";
            default:
                return "W";
        }
    }
 
    /**
     * 任务状态上报接收
     */
    @RequestMapping("/task/sync/v1")
    public R taskSync(@RequestBody TaskReportParam param) {
        if (param == null || param.getSeqNum() == null || param.getQrCode() == null) {
            return R.error("参数为空");
        }
        if ((param.getQrCode().equals("00001547") || param.getQrCode().equals("1001")) && param.getTaskSts() == 10) {
            log.info("1001任务状态上报接收:{}", param);
            DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, 1);
            Map<Integer, StaProtocol> station = devpThread.getStation();
            StaProtocol staProtocol = station.get(1001);
            if (staProtocol == null) {
                return R.error("未找到站点");
            } else {
                staProtocol = staProtocol.clone();
            }
            Random rand = new Random();
            staProtocol.setWorkNo(rand.nextInt(1000));
            staProtocol.setStaNo((short) 1004);
            boolean result = MessageQueue.offer(SlaveType.Devp, 1, new Task(2, staProtocol));
            if (result) {
                log.info("下发成功:{},{}", staProtocol.getWorkNo(), 1004);
            }
        } else if (param.getQrCode().equals("00001612") && param.getTaskSts() == 5) {
            log.info("1007任务状态上报接收:{}", param);
 
        }
        return R.ok();
    }
 
    /**
     * 任务状态上报接收
     */
    @RequestMapping("/sta/ask/v1")
    public R taskSync(@RequestBody AskStaParam param) {
        log.info("状态询问:{}", param);
        if (param == null || param.getAskSta() == null || param.getAskType() == null) {
            return R.error("参数为空");
        }
        SiemensDevpThread devpThread = (SiemensDevpThread) SlaveConnection.get(SlaveType.Devp, 1);
        StaProtocol staProtocol = devpThread.getStation().get(param.getAskSta());
        if (staProtocol != null) {
            if (param.getAskType() == 1) {
                if (staProtocol.isLoading() && staProtocol.isAutoing() && staProtocol.isOutEnable()) {
                    return R.ok();
                }
            } else if (param.getAskType() == 2) {
                if (!staProtocol.isLoading() && staProtocol.isAutoing() && staProtocol.isInEnable()) {
                    return R.ok();
                }
            }
        }
        return R.error("状态不对");
    }
 
 
}