1
zhang
2025-05-07 7a0edfcd4fe0d82a66f8be2c3f894505d544feda
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
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.devops.DevopsMessage;
import com.zy.asrs.domain.devops.ErrorType;
import com.zy.asrs.domain.vo.SiteTableVo;
import com.zy.asrs.entity.BasDevp;
import com.zy.asrs.entity.WrkMast;
import com.zy.asrs.mapper.WrkMastMapper;
import com.zy.asrs.service.BasDevpService;
import com.zy.asrs.service.WrkMastService;
import com.zy.core.CrnThread;
import com.zy.core.DevpThread;
import com.zy.core.cache.SlaveConnection;
import com.zy.core.enums.CrnForkPosType;
import com.zy.core.enums.CrnModeType;
import com.zy.core.enums.CrnStatusType;
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 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.RestController;
 
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
@RestController
@RequestMapping("/devops")
public class DevopsController {
 
    @Autowired
    private WrkMastService wrkMastService;
 
    @Autowired
    private SlaveProperties slaveProperties;
 
    @Autowired
    private WrkMastMapper wrkMastMapper;
 
    @Autowired
    private BasDevpService basDevpService;
 
    @RequestMapping("/wrkMast/list")
    public R list() {
        List<DevopsMessage> devopsMessages = new ArrayList<>();
        DevopsMessage devopsMessage;
        for (CrnSlave crnSlave : slaveProperties.getCrn()) {
            List<WrkMast> wrkMasts = wrkMastService.selectList(new EntityWrapper<WrkMast>().eq("crn_no", crnSlave.getId()).orderBy("wrk_sts", false));
            //先查询堆垛机是否在工作
            WrkMast working = wrkMastMapper.selectWorking(crnSlave.getId());
            for (WrkMast wrkMast : wrkMasts) {
                devopsMessage = new DevopsMessage();
                devopsMessage.setWrkNo(wrkMast.getWrkNo());
                if (working != null) {
                    //在工作,则判断是否未当前这条
                    if (working.getWrkNo().equals(wrkMast.getWrkNo())) {
                        devopsMessage.setError("该工作档正在出库,请稍后");
                    } else {
                        devopsMessage.setError(working.getWrkNo() + "号工作档正在出库,请稍后");
                    }
                    continue;
                }
                DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, 1);
                StaProtocol staProtocol = devpThread.getStation().get(wrkMast.getStaNo());
                List<ErrorType> staError = isStaError(staProtocol, wrkMast);
                for (ErrorType type : staError) {
                    if (!Cools.isEmpty(devopsMessage.getError())) {
                        devopsMessage.setError(devopsMessage.getError() + "\n" + type.getDesc());
                        devopsMessage.setMethod(devopsMessage.getMethod() + "\n" + type.getMethod());
                    } else {
                        devopsMessage.setError(type.getDesc()+ ";");
                        devopsMessage.setMethod(type.getMethod()+ ";" );
                    }
                }
                CrnThread crnThread = (CrnThread) SlaveConnection.get(SlaveType.Crn, wrkMast.getCrnNo());
                CrnProtocol crnProtocol = crnThread.getCrnProtocol();
                List<ErrorType> crnError = isCrnError(crnProtocol, wrkMast);
                for (ErrorType type : crnError) {
                    if (!Cools.isEmpty(devopsMessage.getError())) {
                        devopsMessage.setError(devopsMessage.getError() + "\n" + type.getDesc());
                        devopsMessage.setMethod(devopsMessage.getMethod() + "\n" + type.getMethod());
                    } else {
                        devopsMessage.setError(type.getDesc()+ ";");
                        devopsMessage.setMethod(type.getMethod()+ ";");
                    }
                }
                devopsMessages.add(devopsMessage);
            }
        }
        return R.ok(devopsMessages);
    }
 
    private List<ErrorType> isStaError(StaProtocol staProtocol, WrkMast wrkMast) {
        List<ErrorType> types = new ArrayList<>();
        if (staProtocol == null) {
            types.add(ErrorType.ERROR);
            return types;
        } else {
            staProtocol = staProtocol.clone();
        }
        // 自动
        if (staProtocol.isAutoing()) {
            types.add(ErrorType.FEIZIDONG);
        }
        if (wrkMast.getIoType() > 100) {
            // 出库校验
            // 有物
            if (staProtocol.isLoading()) {
                types.add(ErrorType.YOUWU);
            } // 工作号是否为0
            if (staProtocol.getWorkNo() == 0) {
                types.add(ErrorType.GONGZUOHAO);
            }
            // 目标站点
            if (staProtocol.getStaNo() == null) {
                types.add(ErrorType.STANO);
            }
        } else {
            // 入库校验
 
        }
        return types;
    }
 
 
    private List<ErrorType> isCrnError(CrnProtocol crnProtocol, WrkMast wrkMast) {
        List<ErrorType> types = new ArrayList<>();
        // 堆垛机是否空闲
        if (crnProtocol.getStatusType() == CrnStatusType.IDLE) {
            types.add(ErrorType.CRN_NO_IDLE);
        }
        //任务号是否为0
        if (crnProtocol.getTaskNo() == 0) {
            types.add(ErrorType.WORKING);
        }
        // 堆垛机是否自动
        if (crnProtocol.getModeType() == CrnModeType.AUTO) {
            types.add(ErrorType.CRN_FEIZIDONG);
        }
        // 载货台有物
        if (crnProtocol.getLoaded() == 0) {
            types.add(ErrorType.LOAD);
        }
        // 堆垛机取货中
        if (crnProtocol.statusType == CrnStatusType.FETCHING) {
            types.add(ErrorType.WORKING);
        }
        // 放货中
        if (crnProtocol.statusType == CrnStatusType.PUTTING) {
            types.add(ErrorType.WORKING);
        }
        // 堆垛机等待确认状态
        if (crnProtocol.statusType == CrnStatusType.WAITING) {
            types.add(ErrorType.WORKING);
        }
        // 货叉是否会回中
        if (crnProtocol.forkPosType == CrnForkPosType.HOME) {
            types.add(ErrorType.HOME);
        }
        return types;
    }
 
 
    @PostMapping("/site/list")
    @ManagerAuth(memo = "站点信息表")
    public R siteTable() {
        List<SiteTableVo> list = new ArrayList<>();
        // 内存数据
        Map<Integer, StaProtocol> station = new HashMap<>();
        for (DevpSlave devp : slaveProperties.getDevp()) {
            DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, devp.getId());
            station.putAll(devpThread.getStation());
        }
        // 持久数据
        List<BasDevp> basDevps = basDevpService.selectList(new EntityWrapper<BasDevp>().orderBy("dev_no"));
        for (BasDevp devp : basDevps) {
            StaProtocol staProtocol = station.get(devp.getDevNo());
            if (null == staProtocol) {
                continue;
            }
            SiteTableVo vo = new SiteTableVo();
            vo.setDevNo(devp.getDevNo());    // 站点编号
            vo.setWorkNo(staProtocol.getWorkNo());   //  工作号
            vo.setAutoing(staProtocol.isAutoing() ? "Y" : "N");     //  自动
            vo.setLoading(staProtocol.isLoading() ? "Y" : "N");     // 有物
            vo.setInEnable(staProtocol.isInEnable() ? "Y" : "N");   // 可入
            vo.setOutEnable(staProtocol.isOutEnable() ? "Y" : "N"); // 可出
            vo.setPakMk(staProtocol.isPakMk()?"Y":"N");       // 入库标记
            vo.setStaNo(staProtocol.getStaNo());                // 目标站
            vo.setEmptyMk(staProtocol.isEmptyMk()?"Y":"N");     // 空板信号
            list.add(vo);
        }
        return R.ok().add(list);
    }
}