自动化立体仓库 - WMS系统
zyh
20 小时以前 3bf6f972604761c9ac59a2cb9ea01eeacaec2189
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
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
package com.zy.asrs.controller;
 
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.core.annotations.AppAuth;
import com.core.annotations.ManagerAuth;
import com.core.common.Cools;
import com.core.common.R;
import com.core.exception.CoolException;
import com.zy.asrs.entity.CanFin;
import com.zy.asrs.entity.Task;
import com.zy.asrs.entity.WrkMast;
import com.zy.asrs.entity.mes.*;
import com.zy.asrs.entity.param.CombParam;
import com.zy.asrs.mapper.CanFinMapper;
import com.zy.asrs.service.MesService;
import com.zy.asrs.service.MobileService;
import com.zy.asrs.service.TaskService;
import com.zy.asrs.service.WrkMastService;
import com.zy.common.web.BaseController;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
 
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.Date;
import java.util.List;
 
@RestController
@Slf4j
public class MesController extends BaseController {
 
    @Resource
    private MesService mesService;
 
    @Autowired
    private MobileService mobileService;
    @Autowired
    private WrkMastService wrkMastService;
    @Autowired
    private TaskService taskService;
    @Autowired
    private CanFinMapper canFinMapper;
 
    private void auth(String appkey, Object obj, HttpServletRequest request) {
        log.info("{}接口被访问;appkey:{};请求数据:{}", request.getRequestURI(), appkey, JSON.toJSONString(obj));
        request.setAttribute("cache", obj);
    }
 
    // 物料信息同步
    @PostMapping("/api/mes/synMatInfo")
    @AppAuth(memo = "物料信息同步")
//    public MesReturn synMatInfo(@RequestHeader(required = false) String appkey, @RequestBody List<MesMatRecvForm> params, HttpServletRequest request){
    public MesReturn synMatInfo(@RequestHeader(required = false) String appkey, @RequestBody MesMatRecvForm params, HttpServletRequest request){
        auth(appkey, params, request);
        MesReturn mesReturn = new MesReturn();
        try {
//            for (MesMatRecvForm param : params){
//                mesReturn = mesService.matInfoAndInBound(param);
//            }
                mesReturn = mesService.matInfoAndInBound(params);
        } catch (Exception e) {
            log.error(String.valueOf(e));
            mesReturn.setSuccess("2");
            mesReturn.setMessage("物料信息同步失败");
        }
        return mesReturn;
    }
 
    // 出库申请
    @PostMapping("/api/mes/outBoundOrder")
    public MesReturn outBoundOrder(@RequestBody MesOutApply param){
 
        MesReturn mesReturn = new MesReturn();
        mesReturn.setSuccess(mesService.outBoundOrder(param) == 1 ? "1" : "2");
        return mesReturn;
    }
 
//    // 出库入库订单申请
    @PostMapping("/api/mes/callOutBoundOrder")
    public MesReturn callOutBoundOrder(@RequestBody MesCallOutApply param){
 
        MesReturn mesReturn = new MesReturn();
        mesReturn.setSuccess(mesService.callOutBoundOrder(param) == 1 ? "1" : "2");
        return mesReturn;
    }
 
    // 入库申请
    @PostMapping("/api/mes/inBoundOrder")
    public MesReturn inBoundOrder(@RequestBody MesInApply param){
 
        MesReturn mesReturn = new MesReturn();
        mesReturn.setSuccess(mesService.inBoundOrder(param) == 1 ? "1" : "2");
        return mesReturn;
    }
 
    // 入站允许
    @PostMapping("/api/mes/allowInStation")
    public MesReturn allowInStation(@RequestBody TransInOutStationAllow param){
        return mesService.allowInStation(param);
    }
 
    // 离站允许,装配库、滑块库
    @PostMapping("/api/mes/allowOutStation")
    public MesReturn allowOutStation(@RequestBody TransInOutStationAllow param){
        return mesService.allowOutStation(param);
    }
 
    // 下发运输任务
    @PostMapping("/api/mes/submitTask")
    public JSONObject submitTask(@RequestBody TransTask param){
 
        return mesService.submitTask(param);
    }
 
    // region 临时测试
 
    @GetMapping("/api/mes/testInFeedback")
    public int test(@RequestParam String orderNo){
 
        return mesService.inFeedback(orderNo);
    }
 
    @GetMapping("/api/mes/testInFeedback2")
    public int test(@RequestParam String orderNo, @RequestParam String zapplet){
 
        return mesService.recvFeedback(orderNo, zapplet);
    }
    // endregion
 
    // 库存查询接口
    // 按 物料编码+oderNo
    @PostMapping("/api/mes/queryInventory")
    public MesReturn queryInventory(@RequestBody JSONObject param){
        MesReturn mesReturn = new MesReturn();
        String itemno = param.getString("itemno");
        String orderNo = param.getString("orderNo");
        if(Cools.isEmpty(itemno,orderNo)) {
            mesReturn.setSuccess("2");
            mesReturn.setMessage("参数不能为空");
            return mesReturn;
        }
 
        return mesService.queryInventory(itemno,orderNo);
    }
 
    /**
     * MES调用PDA的AGV订单入库接口
     * @param combParam
     * @return
     */
    @RequestMapping("/comb/auth")
    @ManagerAuth(memo = "组托")
    public R comb(@RequestBody CombParam combParam){
        log.info("=============== MES下发组托订单 ===============");
        log.info("{}", combParam);
        log.info("=============== MES下发组托订单 ===============");
        if (combParam.getUserId() != null && !combParam.getUserId().equals(null)){
            mobileService.comb(combParam, combParam.getUserId());
        }else {
            mobileService.comb(combParam, getUserId());
        }
        return R.ok("组托成功");
    }
 
    /**
     * MES调用PDA的补空板
     *
     * @param locNo 目标站点
     * @param size  托盘大小 1:小托盘  2:大托盘
     * @return
     */
    @PostMapping("/callEmptyBinOutBound")
    public synchronized R callEmptyBinOutBound(@RequestParam(required = false) String locNo
            , @RequestParam(required = false) String size
            , @RequestParam(required = false) String palletFormat
            , @RequestParam(required = false) String agvTaskNo) {
        if (Cools.isEmpty(locNo) || Cools.isEmpty(size)) {
            return R.error("站点或者大小不能为空");
        }
        WrkMast wrkMast = wrkMastService.selectOne(new EntityWrapper<WrkMast>().eq("io_type", 110).eq("memo", locNo));
        if (wrkMast != null) {
            return R.error("该站点="+locNo+"已经有空板出库任务,为了不堵塞堆垛机接驳站点,禁止下发多个空板出库任务");
        }
        return mobileService.callEmptyBinOutBound(locNo, size, palletFormat, agvTaskNo, 9995L);
    }
 
 
    /**
     * 空板回库或者拣料回库
     *
     * @param sourceStaNo
     * @param staNo
     * @return
     */
    @RequestMapping("/AGVStartReturn")
    public synchronized R AGVStartReturn(@RequestParam(required = false) String sourceStaNo
            , @RequestParam(required = false) String staNo
            , @RequestParam(required = false) String taskNo) {
        if (Cools.isEmpty(sourceStaNo) || Cools.isEmpty(staNo)) {
            return R.error("源站点和托盘码不能为空");
        }
        List<Task> tasks = taskService.selectList(new EntityWrapper<Task>().eq("source_sta_no", sourceStaNo).eq("barcode", staNo));
        if (tasks.size() > 0) {
            return R.error("该托盘="+staNo+"已经存在搬运任务,请不要重复下发");
        }
 
        String barcode = staNo.substring(0,1);
        if(barcode.equals("3")){
            taskNo = "307";
        }else if(barcode.equals("4")){
            taskNo = "402";
        }else if(barcode.equals("5")){
            taskNo = "401";
        }
 
        R r = R.ok();
        //生成AGV搬运出库任务
        // 保存工作档
        Task task = new Task();
        Date date = new Date();
        String TaskNo = 555555 + "aa" + date.getTime();
        task.setWrkNo((int) date.getTime())
                .setTaskNo(TaskNo)
                .setIoTime(date)
                .setWrkSts(301L) // 工作状态:301.任务下发
                .setIoType(3) // 入出库状态: 3.站到站  4.站到区域
                .setTaskType("agv")
                .setIoPri(10D)
                .setFullPlt("Y") // 满板:Y
                .setPicking("N") // 拣料
                .setExitMk("N")// 退出
                .setStaNo(taskNo)
                .setSourceStaNo(sourceStaNo)//agv取货站点
                .setEmptyMk("N")// 空板
                .setBarcode(staNo)// 托盘码
                .setLinkMis("N")
                .setAppeUser(9945L)
                .setAppeTime(date)
                .setModiUser(9945L)
                .setModiTime(date);
        if (taskService.insert(task)) {
            Date now = new Date();
            CanFin canFin = new CanFin();
            canFin.setAgvType("agv-in");
            canFin.setInNo(TaskNo);
            canFin.setApplyTime(now);
            canFinMapper.insert(canFin);
        }else{
            throw new CoolException("保存工作档失败");
        }
 
        return r;
    }
    @PostMapping("/api/mes/pauseAGV")
    public MesReturn AGVPause(@RequestBody JSONObject param){
        MesReturn mesReturn = new MesReturn();
 
        String type = "STOP";
        if (param.getString("type") != null){
            type = "START";
        }
 
        switch (mesService.AGVPause(param, type)){
            case 1:
                mesReturn.setSuccess("1");
                mesReturn.setMessage("AGV暂停或启动成功");
                return mesReturn;
            case 2:
                mesReturn.setSuccess("1");
                mesReturn.setMessage("海康AGV暂停或启动成功");
                return mesReturn;
            case 3:
                mesReturn.setSuccess("1");
                mesReturn.setMessage("华晓AGV暂停或启动成功");
                return mesReturn;
            case 4:
                mesReturn.setSuccess("2");
                mesReturn.setMessage("AGV暂停或启动调用失败");
                return mesReturn;
        }
        mesReturn.setSuccess("2");
        mesReturn.setMessage("AGV暂停或启动调用失败");
        return mesReturn;
    }
}