自动化立体仓库 - WMS系统
pang.jiabao
4 天以前 10e6a9a8adad2226f13a4e4704ca5b2ad5b9ef9a
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
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.common.Cools;
import com.core.common.R;
import com.zy.asrs.entity.BasStation;
import com.zy.asrs.entity.mes.*;
import com.zy.asrs.service.BasStationService;
import com.zy.asrs.service.MesService;
import com.zy.common.web.BaseController;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
 
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.List;
 
@RestController
@Slf4j
public class MesController extends BaseController {
 
    @Resource
    private MesService mesService;
 
    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 MesMatInfo param,HttpServletRequest request){
        auth(appkey, param, request);
        MesReturn mesReturn = new MesReturn();
        mesReturn.setSuccess(mesService.synMatInfo(param) == 1 ? "1" : "2");
        return mesReturn;
    }
 
    @PostMapping("/api/tms/queryStock")
    @AppAuth(memo = "TMS查询库存")
    public R queryStock(@RequestHeader(required = false) String appkey,@RequestBody JSONObject param,HttpServletRequest request){
        auth(appkey, param, request);
        String matnr = param.getString("matnr");
        return mesService.queryStock(matnr);
    }
 
    // 出库申请
    @PostMapping("/api/mes/outBoundOrder")
    @AppAuth(memo = "出库申请(TMS调用)")
    public MesReturn outBoundOrder(@RequestHeader(required = false) String appkey,@RequestBody MesInApply param,HttpServletRequest request){
        auth(appkey, param, request);
        if(Cools.isEmpty(param.getTaskNo(),param.getOrderNo(),param.getStationId())) {
            MesReturn mesReturn = new MesReturn();
            mesReturn.setSuccess("2");
            mesReturn.setMessage("参数不能为空:" + JSONObject.toJSONString(param));
            return  mesReturn;
        }
 
        return mesService.outBoundOrder(param);
    }
 
//    // 出库申请(叫料),装配库、滑块库
//    @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, 0) == 1 ? "1" : "2");
        return mesReturn;
    }
 
    @PostMapping("/api/mes/allowInStation")
    @AppAuth(memo = "入站允许")
    public MesReturn allowInStation(@RequestHeader(required = false) String appkey,@RequestBody TransInOutStationAllow param,HttpServletRequest request){
        auth(appkey, param, request);
        return mesService.allowInStation(param);
    }
 
    // 离站允许,装配库、滑块库
    @PostMapping("/api/mes/allowOutStation")
    public MesReturn allowOutStation(@RequestBody TransInOutStationAllow param){
 
        return mesService.allowOutStation(param);
    }
 
    @Resource
    private BasStationService basStationService;
 
    // 下发运输任务,mes调用下刀06(呼叫agv搬运)
    @PostMapping("/api/mes/submitTask")
    public JSONObject submitTask(@RequestBody TransTask param){
        log.info("下刀(退刀):{}",JSONObject.toJSONString(param));
        // 终点为空,计算接驳位
        BasStation basStation = null;
        if (Cools.isEmpty(param.getNextStationId())) {
            List<BasStation> basStations = basStationService.selectList(new EntityWrapper<BasStation>().eq("loc_sts", "O"));
            if(basStations.isEmpty()) {
                JSONObject result = new JSONObject();
                result.put("taskno", param.getTaskno());
                result.put("Success", "2");
                result.put("Message", "无空接驳位,请稍后再试!");
                return result;
            }
            // 接驳点
            basStation = basStations.get(0);
            param.setNextStationId(basStation.getDevNo());
 
            // 先更新接驳点状态
            basStation.setModiTime(new Date());
            basStation.setLocSts("S");
            basStation.setBarcode(param.getDjNo());
            basStationService.updateById(basStation);
        }
        JSONObject sendAgvTask;
        param.setAgvFactory(1); // 海康
        try {
            sendAgvTask = mesService.submitTask(param);
            if (!"1".equals(sendAgvTask.getString("Success"))) {
                // 释放接驳点
                if(basStation != null) {
                    basStation.setModiTime(new Date());
                    basStation.setLocSts("O");
                    basStation.setBarcode("");
                    basStationService.updateById(basStation);
                }
            }
        }catch (Exception e){
            // 释放接驳点
            if(basStation != null) {
                basStation.setModiTime(new Date());
                basStation.setLocSts("O");
                basStation.setBarcode("");
                basStationService.updateById(basStation);
            }
            throw e;
        }
        return sendAgvTask;
    }
 
    // 接受成品刀可以入库二维码
    @PostMapping("/api/mes/inBoundItemBarcode")
    public MesReturn inBoundItemBarcode(@RequestBody MesItemBarCode param){
 
        MesReturn mesReturn = new MesReturn();
        mesReturn.setSuccess("1"); // TODO:待缓存成品刀二维码;
        return mesReturn;
    }
 
 
}