自动化立体仓库 - WCS系统
luxiaotao1123
2020-08-28 99936813d924346e12bf1299a7bdcdbe485ea375
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
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
package com.zy.asrs.controller;
 
import com.core.annotations.ManagerAuth;
import com.core.common.Cools;
import com.core.common.R;
import com.zy.asrs.domain.enums.CrnStatusType;
import com.zy.asrs.domain.enums.SiteStatusType;
import com.zy.asrs.domain.param.SystemSwitchParam;
import com.zy.asrs.domain.vo.*;
import com.zy.asrs.entity.BasDevp;
import com.zy.asrs.entity.WrkMast;
import com.zy.asrs.mapper.LocMastMapper;
import com.zy.asrs.service.BasDevpService;
import com.zy.asrs.service.WrkMastService;
import com.zy.common.CodeRes;
import com.zy.core.Slave;
import com.zy.core.cache.SlaveConnection;
import com.zy.core.enums.CrnModeType;
import com.zy.core.enums.SlaveType;
import com.zy.core.model.CrnSlave;
import com.zy.core.model.DevpSlave;
import com.zy.core.model.protocol.CrnProtocol;
import com.zy.core.model.protocol.StaProtocol;
import com.zy.core.properties.SlaveProperties;
import com.zy.core.properties.SystemProperties;
import com.zy.core.thread.BarcodeThread;
import com.zy.core.thread.CrnThread;
import com.zy.core.thread.DevpThread;
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.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
 
import java.util.*;
 
/**
 * 主控图接口
 * Created by vincent on 2020-06-01
 */
@Slf4j
@RestController
@RequestMapping("/console")
public class ConsoleController {
 
    @Autowired
    private SlaveProperties slaveProperties;
    @Autowired
    private WrkMastService wrkMastService;
    @Autowired
    private BasDevpService basDevpService;
    @Autowired
    private LocMastMapper locMastMapper;
 
    @PostMapping("/system/running/status")
    @ManagerAuth(memo = "系统运行状态")
    public R systemRunningStatus(){
        return R.ok().add(Cools.add("status", SystemProperties.WCS_RUNNING_STATUS.get()));
    }
 
    @PostMapping("/system/switch")
    @ManagerAuth(memo = "系统运行开关操作")
    public R systemSwitch(SystemSwitchParam param) throws InterruptedException {
        if (Cools.isEmpty(param.getOperatorType())){
            return R.error();
        }
        if (param.getOperatorType() == 0) {
            if (Cools.isEmpty(param.getPassword())){
                return R.error("请输入口令");
            }
            if (!param.getPassword().equals(SystemProperties.WCS_PASSWORD)){
                return R.error("口令错误");
            }
        }
        Thread.sleep(200L);
        SystemProperties.WCS_RUNNING_STATUS.set(param.getOperatorType()==1?Boolean.TRUE:Boolean.FALSE);
        return R.ok().add(Cools.add("status", SystemProperties.WCS_RUNNING_STATUS.get()));
    }
 
    /****************************************************************/
    /************************** 实时数据 ******************************/
    /****************************************************************/
 
    @PostMapping("/latest/data/site")
    @ManagerAuth(memo = "站点实时数据")
    public R siteLatestData(){
        List<SiteLatestDataVo> vos = new ArrayList<>();
        Map<Integer, StaProtocol> stations = new HashMap<>();
        for (DevpSlave devp : slaveProperties.getDevp()) {
            DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, devp.getId());
            if (null != devpThread) {
                stations.putAll(devpThread.getStation());
            }
        }
        for (Map.Entry<Integer, StaProtocol> entry : stations.entrySet()) {
            SiteLatestDataVo vo = new SiteLatestDataVo();
            StaProtocol staProtocol = entry.getValue();
            vo.setSiteId(String.valueOf(entry.getKey())); // 站点编号
            vo.setWorkNo(staProtocol.getWorkNo()); // 工作号
            vo.setSiteStatus(SiteStatusType.process(staProtocol));  // 状态
            vos.add(vo);
        }
        return R.ok().add(vos);
    }
 
    @PostMapping("/latest/data/crn")
    @ManagerAuth(memo = "堆垛机实时数据")
    public R crnLatestData(){
        List<CrnLatestDataVo> vos = new ArrayList<>();
        for (CrnSlave crn : slaveProperties.getCrn()) {
            // 获取堆垛机信息
            CrnThread crnThread = (CrnThread) SlaveConnection.get(SlaveType.Crn, crn.getId());
            if (crnThread == null) {
                log.error("{}号堆垛机连接失败", crn.getId());
                continue;
            }
            CrnProtocol crnProtocol = crnThread.getCrnProtocol();
            if (crnProtocol == null) {
                log.error("{}号堆垛机连接失败", crn.getId());
                continue;
            }
            CrnLatestDataVo vo = new CrnLatestDataVo();
            vo.setCrnId(crn.getId());   //  堆垛机编号
 
//            Short totalBay = locMastMapper.selectTotalBay();
 
            vo.setOffset((double) new Random().nextInt(560));     //  堆垛机偏移量
            vo.setBay((short) (crnProtocol.getBay() - crn.getOffset()));    //  当前列
            /**
             * 堆垛机状态判断
             */
            if (crnProtocol.getTaskNo()>0) {
                WrkMast wrkMast = wrkMastService.selectById(crnProtocol.getTaskNo());
                if (wrkMast != null) {
                    vo.setCrnStatus(CrnStatusType.process(wrkMast.getIoType()));
                } else {
                    vo.setCrnStatus(crnProtocol.modeType.equals(CrnModeType.AUTO)? CrnStatusType.MACHINE_AUTO: CrnStatusType.MACHINE_UN_AUTO);
                }
            } else {
                vo.setCrnStatus(crnProtocol.modeType.equals(CrnModeType.AUTO)? CrnStatusType.MACHINE_AUTO: CrnStatusType.MACHINE_UN_AUTO);
            }
            vos.add(vo);
 
        }
        return R.ok().add(vos);
    }
 
    @PostMapping("/latest/data/barcode")
    @ManagerAuth(memo = "条码扫描仪实时数据")
    public R barcodeLatestData(){
        List<BarcodeDataVo> list = new ArrayList<>();
        for (Slave barcode : slaveProperties.getBarcode()) {
            BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, barcode.getId());
            BarcodeDataVo vo = new BarcodeDataVo();
            vo.setBarcodeId(barcode.getId());
            vo.setCodeValue(barcodeThread.getBarcode());
            list.add(vo);
        }
        return R.ok().add(list);
    }
 
    /****************************************************************/
    /************************** 详情操作 ******************************/
    /****************************************************************/
 
    @PostMapping("/site/detail")
    @ManagerAuth(memo = "输送设备数据详情")
    public R siteDetail(@RequestParam Integer siteId){
        if (Cools.isEmpty(siteId)){
            return R.parse(CodeRes.EMPTY);
        }
        SiteDetailVo vo = new SiteDetailVo();
        for (DevpSlave devp : slaveProperties.getDevp()) {
            DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, devp.getId());
            if (null != devpThread) {
                StaProtocol staProtocol = devpThread.getStation().get(siteId);
                if (staProtocol != null) {
                    BasDevp basDevp = basDevpService.selectById(siteId);
                    if (basDevp == null) {
                        return R.error("数据库维护异常");
                    }
                    vo.setSiteId(siteId);   // 站点编号
                    vo.setWorkNo(staProtocol.getWorkNo());   // 工作号
 
                    if (staProtocol.getWorkNo() > 0) {
                        WrkMast wrkMast = wrkMastService.selectById(staProtocol.getWorkNo());
                        if (wrkMast != null) {
                            vo.setWrkSts(wrkMast.getWrkSts$());   // 工作状态
                            vo.setIoType(wrkMast.getIoType$());   //  入出库类型
                            vo.setSourceStaNo(wrkMast.getSourceStaNo$());
                            vo.setStaNo(wrkMast.getStaNo$());
                            vo.setSourceLocNo(wrkMast.getSourceLocNo$());
                            vo.setLocNo(wrkMast.getLocNo$());
                        }
                    }
 
                    vo.setAutoing(staProtocol.isAutoing()?"Y":"N"); //  自动
                    vo.setLoading(staProtocol.isLoading()?"Y":"N"); //  有物
 
                    vo.setCanining(basDevp.getCanining());  //  能入
                    vo.setCanouting(basDevp.getCanouting());    //  能出
 
                    return R.ok().add(vo);
                }
            }
        }
        return R.error();
 
    }
 
    @PostMapping("/crn/detail")
    @ManagerAuth(memo = "堆垛机设备数据详情")
    public R crnDetail(@RequestParam Integer crnNo){
        if (Cools.isEmpty(crnNo)){
            return R.parse(CodeRes.EMPTY);
        }
        CrnDetailVo vo = new CrnDetailVo();
        for (CrnSlave crnSlave : slaveProperties.getCrn()) {
            if (crnSlave.getId().equals(crnNo)) {
                CrnThread crnThread = (CrnThread) SlaveConnection.get(SlaveType.Crn, crnSlave.getId());
                CrnProtocol crnProtocol = crnThread.getCrnProtocol();
                vo.setCrnNo(crnNo);
                vo.setWorkNo(crnProtocol.getTaskNo());
                if (crnProtocol.getTaskNo() > 0) {
                    WrkMast wrkMast = wrkMastService.selectById(crnProtocol.getTaskNo());
                    if (wrkMast != null) {
                        vo.setSourceStaNo(wrkMast.getSourceStaNo$());
                        vo.setStaNo(wrkMast.getStaNo$());
                        vo.setWrkSts(wrkMast.getWrkSts$());   // 工作状态
                        vo.setIoType(wrkMast.getIoType$());   //  入出库类型
                        vo.setSourceLocNo(wrkMast.getSourceLocNo$());
                        vo.setLocNo(wrkMast.getLocNo$());
                        vo.setCrnStatus(crnProtocol.getStatusType().desc);
                        vo.setError("");    // todo
                    }
                }
                return R.ok().add(vo);
            }
        }
        return R.error();
    }
 
    @Deprecated
    @PostMapping("/site/update")
    @ManagerAuth(memo = "输送设备数据修改")
    public R updateSite(){
        return R.ok();
    }
 
    @Deprecated
    @PostMapping("/crn/update")
    @ManagerAuth(memo = "堆垛机数据修改")
    public R updateCrn(){
        return R.ok();
    }
 
}