lbq
17 小时以前 076cd7a73eb60c86d43eda67c5625704576d44cc
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
package com.vincent.rsf.openApi.controller.phyz;
 
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.vincent.rsf.framework.common.R;
import com.vincent.rsf.framework.exception.CoolException;
import com.vincent.rsf.openApi.entity.dto.CommonResponse;
import com.vincent.rsf.openApi.entity.phyz.*;
import com.vincent.rsf.openApi.feign.wms.WmsServerFeignClient;
import com.vincent.rsf.openApi.feign.wms.fallback.WmsServerFeignClientFallback;
import com.vincent.rsf.openApi.service.phyz.MesReportService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
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.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
 
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
 
import static com.vincent.rsf.openApi.controller.AuthController.SIMULATED_DATA_ENABLE;
import static com.vincent.rsf.openApi.controller.phyz.ERPController.paramsFormat;
 
@Slf4j
@RestController
@RequestMapping("/mes")
@Api("银座新工厂(五期)MES接口")
public class MESController {
 
    @Resource
    private MesReportService mesReportService;
    @Autowired(required = false)
    private WmsServerFeignClient wmsServerFeignClient;
 
 
    @ApiOperation("备料通知")
    @PostMapping("/callMaterial")
    public CommonResponse callMaterial(@RequestBody Object objParams) {
        if (Objects.isNull(objParams)) {
            throw new CoolException("参数不能为空!!");
        }
//        // 返回模拟数据
//        if (SIMULATED_DATA_ENABLE.equals("1")) {
//            JSONArray params = paramsFormat(objParams);
//            List<MatPreparationOrder> orders = JSON.parseArray(params.toJSONString(), MatPreparationOrder.class);
//            JSONArray array = ERPController.map;
//            for (int i = 0; i < ERPController.map.size(); i++) {
//                JSONObject obj = array.getJSONObject(i);
//                obj.put("orderNo", orders.get(0).getOrderNo());
//                obj.put("matNr", orders.get(0).getOrderItems().get(0).getMatNr());
//            }
//            ERPController.map = array;
//
//            return CommonResponse.ok();
//        }
 
        JSONArray params = paramsFormat(objParams);
        List<MatPreparationOrder> orders = JSON.parseArray(params.toJSONString(), MatPreparationOrder.class);
        // 数据处理,转发server
        for (MatPreparationOrder order : orders) {
            mesReportService.callMaterial(order);
        }
        return CommonResponse.ok();
    }
 
    @ApiOperation("简单生产领料、退料AGV任务")
    @PostMapping("/transTask/simpleProduction")
    public CommonResponse simpleProductionTask(@RequestBody Object objParams) {
        if (Objects.isNull(objParams)) {
            throw new CoolException("参数不能为空!!");
        }
        // 返回模拟数据
        if (SIMULATED_DATA_ENABLE.equals("1")) {
            return CommonResponse.ok();
        }
 
        JSONArray params = paramsFormat(objParams);
        List<SimpleProductionTask> tasks = JSON.parseArray(params.toJSONString(), SimpleProductionTask.class);
        // 数据处理,转发server
        return CommonResponse.ok();
    }
 
    @ApiOperation("空托出库")
    @PostMapping("/emptyTray/callOut")
    public CommonResponse callOutEmptyTray(@RequestBody Object objParams) {
        if (Objects.isNull(objParams)) {
            throw new CoolException("参数不能为空!!");
        }
        // 返回模拟数据
        if (SIMULATED_DATA_ENABLE.equals("1")) {
            return CommonResponse.ok();
        }
 
        JSONArray params = paramsFormat(objParams);
        List<Task> tasks = JSON.parseArray(params.toJSONString(), Task.class);
        // 数据处理,转发server          http://127.0.0.1:8085/rsf-server/pda/callForEmptyContainers   {"staNo":"103-1","type":"3"}
        int success = 0;
        StringBuilder errorMsg = new StringBuilder();
        for (Task task : tasks) {
            try {
                if (wmsServerFeignClient == null) {
                    log.warn("WmsServerFeignClient未注入,无法进行调用");
                    return CommonResponse.error("服务未初始化");
                }
 
                JSONObject jsonObject = new JSONObject();
                jsonObject.put("type", task.getPalletType());
                jsonObject.put("taskNo", task.getTaskNo());
                jsonObject.put("staNo", task.getEndStationId());
                jsonObject.put("taskOrigin", "mes");
 
                log.info("mes空托出库参数: {}", JSON.toJSONString(jsonObject));
 
                // 直接传递实体类,Feign会自动序列化为JSON
                R result = wmsServerFeignClient.callForEmptyContainers(jsonObject);
 
                log.info("mes空托出库返回结果: {}", JSON.toJSONString(result));
 
                if (result != null) {
                    Integer code = (Integer) result.get("code");
                    if (code != null && code == 200) {
                        success++;
                    } else {
                        errorMsg.append((String) result.get("msg"));
                    }
                } else {
                    return CommonResponse.error("空托出库执行失败:返回结果为空");
                }
            } catch (Exception e) {
                log.error("空托出库执行失败", e);
                String errorMessage = WmsServerFeignClientFallback.filterErrorMessage(e);
                errorMsg.append(errorMessage);
            }
        }
 
        if (success == tasks.size()) {
            return CommonResponse.ok();
        } else {
            return CommonResponse.error(errorMsg.toString());
        }
    }
 
    @ApiOperation("空托入库")
    @PostMapping("/emptyTray/backIn")
    public CommonResponse emptyTrayBackIn(@RequestBody Object objParams) {
        if (Objects.isNull(objParams)) {
            throw new CoolException("参数不能为空!!");
        }
        // 返回模拟数据
        if (SIMULATED_DATA_ENABLE.equals("1")) {
            return CommonResponse.ok();
        }
 
        JSONArray params = paramsFormat(objParams);
        List<Task> tasks = JSON.parseArray(params.toJSONString(), Task.class);
        // 数据处理,转发server
        int success = 0;
        StringBuilder errorMsg = new StringBuilder();
        for (Task task : tasks) {
            try {
                if (wmsServerFeignClient == null) {
                    log.warn("WmsServerFeignClient未注入,无法进行调用");
                    return CommonResponse.error("服务未初始化");
                }
 
                JSONObject jsonObject = new JSONObject();
                jsonObject.put("containerNo", task.getPalletId());
                jsonObject.put("taskNo", task.getTaskNo());
                jsonObject.put("transferStationNo", task.getStartStationId());
                jsonObject.put("taskOrigin", "mes");
 
                log.info("mes空托入库参数: {}", JSON.toJSONString(jsonObject));
 
                // 直接传递实体类,Feign会自动序列化为JSON
                R result = wmsServerFeignClient.emptyContainerWarehousing(jsonObject);
 
                log.info("mes空托入库返回结果: {}", JSON.toJSONString(result));
 
                if (result != null) {
                    Integer code = (Integer) result.get("code");
                    if (code != null && code == 200) {
                        success++;
                    } else {
                        errorMsg.append((String) result.get("msg"));
                    }
                } else {
                    return CommonResponse.error("空托入库执行失败:返回结果为空");
                }
            } catch (Exception e) {
                log.error("空托入库执行失败", e);
                String errorMessage = WmsServerFeignClientFallback.filterErrorMessage(e);
                errorMsg.append(errorMessage);
            }
        }
 
        if (success == tasks.size()) {
            return CommonResponse.ok();
        } else {
            return CommonResponse.error(errorMsg.toString());
        }
    }
 
    // region 测试推送功能
    @ApiOperation("托盘信息同步")
    @PostMapping("/syncPalletInfo")
    public CommonResponse syncPalletInfo(@RequestBody Object objParams) {
        try {
            return mesReportService.syncPalletInfo(objParams);
        } catch (Exception e) {
            log.error("mes, syncPalletInfo", e);
        }
        return CommonResponse.ok();
    }
 
    @ApiOperation("站点信息同步")
    @PostMapping("/syncStationInfo")
    public CommonResponse syncStationInfo(@RequestBody Object objParams) {
        try {
            return mesReportService.syncStationInfo(objParams);
        } catch (Exception e) {
            log.error("mes, syncStationInfo", e);
        }
        return CommonResponse.ok();
    }
 
    @ApiOperation("AGV任务回调")
    @PostMapping("/reportTaskExecute")
    public CommonResponse reportTaskExecute(@RequestBody Object objParams) {
        try {
            return mesReportService.reportTaskExecute(objParams);
        } catch (Exception e) {
            log.error("mes, reportTaskExecute", e);
        }
        return CommonResponse.ok();
    }
    // endregion
 
}