Junjie
9 小时以前 f305e5244e059c5e43566412f69b180e2e790026
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
package com.zy.asrs.controller;
 
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.core.annotations.ManagerAuth;
import com.core.common.Cools;
import com.core.common.R;
import com.zy.asrs.domain.param.DualCrnCommandParam;
import com.zy.asrs.domain.param.DualCrnUpdateTaskNoParam;
import com.zy.asrs.domain.vo.DualCrnStateTableVo;
import com.zy.asrs.entity.BasDualCrnp;
import com.zy.asrs.service.BasDualCrnpService;
import com.zy.common.utils.RedisUtil;
import com.zy.core.cache.MessageQueue;
import com.zy.core.cache.SlaveConnection;
import com.zy.core.enums.RedisKeyType;
import com.zy.core.enums.SlaveType;
import com.zy.core.model.Task;
import com.zy.core.model.command.DualCrnCommand;
import com.zy.core.model.protocol.DualCrnProtocol;
import com.zy.core.thread.DualCrnThread;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
 
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;
 
@Slf4j
@RestController
public class DualCrnController {
 
    @Autowired
    private BasDualCrnpService basDualCrnpService;
    @Autowired
    private RedisUtil redisUtil;
 
    @PostMapping("/dualcrn/table/crn/state")
    @ManagerAuth(memo = "双工位堆垛机信息表")
    public R dualCrnStateTable() {
        List<DualCrnStateTableVo> list = new ArrayList<>();
        List<BasDualCrnp> crnps = basDualCrnpService.selectList(new EntityWrapper<BasDualCrnp>().orderBy("crn_no"));
        for (BasDualCrnp basDualCrnp : crnps) {
            DualCrnStateTableVo vo = new DualCrnStateTableVo();
            vo.setCrnNo(basDualCrnp.getCrnNo());
            list.add(vo);
            DualCrnThread crnThread = (DualCrnThread) SlaveConnection.get(SlaveType.DualCrn, basDualCrnp.getCrnNo());
            if (crnThread == null) {
                continue;
            }
            DualCrnProtocol p = crnThread.getStatus();
            if (p == null) {
                continue;
            }
            vo.setTaskNo(p.getTaskNo());
            vo.setTaskNoTwo(p.getTaskNoTwo());
            vo.setDeviceTaskNo(p.getDeviceTaskNo());
            vo.setDeviceTaskNoTwo(p.getDeviceTaskNoTwo());
            vo.setMode(p.getModeType() == null ? "-" : p.getModeType().desc);
            vo.setStatus(p.getStatusType() == null ? "-" : p.getStatusType().desc);
            vo.setStatusTwo(p.getStatusTypeTwo() == null ? "-" : p.getStatusTypeTwo().desc);
            vo.setLoading(p.getLoaded() != null && p.getLoaded() == 1 ? "有物" : "无物");
            vo.setLoadingTwo(p.getLoadedTwo() != null && p.getLoadedTwo() == 1 ? "有物" : "无物");
            vo.setBay(p.getBay());
            vo.setLev(p.getLevel());
            vo.setForkOffset(p.getForkPosType() == null ? "-" : p.getForkPosType().desc);
            vo.setForkOffsetTwo(p.getForkPosTypeTwo() == null ? "-" : p.getForkPosTypeTwo().desc);
            vo.setLiftPos(p.getLiftPosType() == null ? "-" : p.getLiftPosType().desc);
            vo.setWalkPos(p.getWalkPos() != null && p.getWalkPos() == 0 ? "在定位" : "不在定位");
            vo.setTaskReceive(String.valueOf(p.getTaskReceive()));
            vo.setTaskReceiveTwo(String.valueOf(p.getTaskReceiveTwo()));
            vo.setTaskSend(String.valueOf(p.getTaskSend()));
            vo.setTaskSendTwo(String.valueOf(p.getTaskSendTwo()));
 
            vo.setXspeed(String.format("%.2f", p.getXSpeed()));
            vo.setYspeed(String.format("%.2f", p.getYSpeed()));
            vo.setZspeed(String.format("%.2f", p.getZSpeed()));
            vo.setXdistance(String.format("%.2f", p.getXDistance()));
            vo.setYdistance(String.format("%.2f", p.getYDistance()));
            vo.setXduration(String.format("%.2f", p.getXDuration()));
            vo.setYduration(String.format("%.2f", p.getYDuration()));
            vo.setWarnCode(p.getAlarm() == null ? "-" : String.valueOf(p.getAlarm()));
            if (p.getAlarm() != null && p.getAlarm() > 0) {
                vo.setDeviceStatus("ERROR");
            } else if (p.getTaskNo() != null && p.getTaskNo() > 0 || p.getTaskNoTwo() != null && p.getTaskNoTwo() > 0) {
                vo.setDeviceStatus("WORKING");
            } else if (p.getModeType() != null && "AUTO".equals(p.getModeType().name())) {
                vo.setDeviceStatus("AUTO");
            } else {
                vo.setDeviceStatus("OFFLINE");
            }
        }
        return R.ok().add(list);
    }
 
    @PostMapping("/dualcrn/command/take")
    @ManagerAuth(memo = "双工位堆垛机取放货命令")
    public R dualCrnCommandTake(@RequestBody DualCrnCommandParam param) {
        if (Cools.isEmpty(param)) {
            return R.error("缺少参数");
        }
        Integer crnNo = param.getCrnNo();
        String sourceLocNo = param.getSourceLocNo();
        String targetLocNo = param.getTargetLocNo();
        Integer station = param.getStation();
        DualCrnThread crnThread = (DualCrnThread) SlaveConnection.get(SlaveType.DualCrn, crnNo);
        if (crnThread == null) {
            return R.error("线程不存在");
        }
        DualCrnCommand command = crnThread.getPickAndPutCommand(sourceLocNo, targetLocNo, 9999, crnNo, station);
        MessageQueue.offer(SlaveType.DualCrn, crnNo, new Task(3, command));
        return R.ok();
    }
 
    @PostMapping("/dualcrn/command/pick")
    @ManagerAuth(memo = "双工位堆垛机取货命令")
    public R dualCrnCommandPick(@RequestBody DualCrnCommandParam param) {
        if (Cools.isEmpty(param)) {
            return R.error("缺少参数");
        }
        Integer crnNo = param.getCrnNo();
        String targetLocNo = param.getTargetLocNo();
        Integer station = param.getStation();
        DualCrnThread crnThread = (DualCrnThread) SlaveConnection.get(SlaveType.DualCrn, crnNo);
        if (crnThread == null) {
            return R.error("线程不存在");
        }
        DualCrnCommand command = crnThread.getPickCommand(targetLocNo, 9999, crnNo, station);
        MessageQueue.offer(SlaveType.DualCrn, crnNo, new Task(3, command));
        return R.ok();
    }
 
    @PostMapping("/dualcrn/command/put")
    @ManagerAuth(memo = "双工位堆垛机放货命令")
    public R dualCrnCommandPut(@RequestBody DualCrnCommandParam param) {
        if (Cools.isEmpty(param)) {
            return R.error("缺少参数");
        }
        Integer crnNo = param.getCrnNo();
        String targetLocNo = param.getTargetLocNo();
        Integer station = param.getStation();
        DualCrnThread crnThread = (DualCrnThread) SlaveConnection.get(SlaveType.DualCrn, crnNo);
        if (crnThread == null) {
            return R.error("线程不存在");
        }
        DualCrnCommand command = crnThread.getPutCommand(targetLocNo, 9999, crnNo, station);
        MessageQueue.offer(SlaveType.DualCrn, crnNo, new Task(3, command));
        return R.ok();
    }
    
 
    @PostMapping("/dualcrn/command/move")
    @ManagerAuth(memo = "双工位堆垛机移动命令")
    public R dualCrnCommandMove(@RequestBody DualCrnCommandParam param) {
        if (Cools.isEmpty(param)) {
            return R.error("缺少参数");
        }
        Integer crnNo = param.getCrnNo();
        String targetLocNo = param.getTargetLocNo();
        Integer station = param.getStation();
        DualCrnThread crnThread = (DualCrnThread) SlaveConnection.get(SlaveType.DualCrn, crnNo);
        if (crnThread == null) {
            return R.error("线程不存在");
        }
        DualCrnCommand command = crnThread.getMoveCommand(targetLocNo, 9999, crnNo);
        if (station != null) {
            command.setStation(station);
        }
        MessageQueue.offer(SlaveType.DualCrn, crnNo, new Task(3, command));
        return R.ok();
    }
 
    @PostMapping("/dualcrn/command/taskComplete")
    @ManagerAuth(memo = "双工位堆垛机任务完成确认")
    public R dualCrnCommandTaskComplete(@RequestBody DualCrnCommandParam param) {
        if (Cools.isEmpty(param)) {
            return R.error("缺少参数");
        }
        Integer crnNo = param.getCrnNo();
        Integer station = param.getStation();
        DualCrnThread crnThread = (DualCrnThread) SlaveConnection.get(SlaveType.DualCrn, crnNo);
        if (crnThread == null) {
            return R.error("线程不存在");
        }
        DualCrnCommand command = crnThread.getResetCommand(9999, crnNo, station);
        MessageQueue.offer(SlaveType.DualCrn, crnNo, new Task(3, command));
        return R.ok();
    }
 
    @PostMapping("/dualcrn/command/updateTaskNo")
    @ManagerAuth(memo = "双工位堆垛机编辑任务号")
    public R dualCrnUpdateTaskNo(@RequestBody DualCrnUpdateTaskNoParam param) {
        if (Cools.isEmpty(param) || param.getCrnNo() == null || param.getStation() == null || param.getTaskNo() == null) {
            return R.error("缺少参数");
        }
        Integer station = param.getStation();
        if (station != 1 && station != 2) {
            return R.error("工位参数错误");
        }
        Integer taskNo = param.getTaskNo();
        if (taskNo < 0) {
            return R.error("任务号不能小于0");
        }
        Integer crnNo = param.getCrnNo();
        DualCrnThread crnThread = (DualCrnThread) SlaveConnection.get(SlaveType.DualCrn, crnNo);
        if (crnThread == null) {
            return R.error("线程不存在");
        }
        DualCrnProtocol protocol = crnThread.getStatus();
        if (protocol == null) {
            return R.error("设备状态不存在");
        }
        if (station == 1) {
            redisUtil.set(RedisKeyType.DUAL_CRN_STATION1_FLAG.key + crnNo, taskNo, 60 * 60 * 24);
        } else {
            redisUtil.set(RedisKeyType.DUAL_CRN_STATION2_FLAG.key + crnNo, taskNo, 60 * 60 * 24);
        }
        return R.ok();
    }
}