自动化立体仓库 - WCS系统
#
zjj
2023-12-08 d04ce586afce3b78f238289dad10dacd4c22206a
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
290
291
292
293
package com.zy.asrs.controller;
 
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.core.common.DateUtils;
import com.zy.asrs.domain.enums.TaskStatusType;
import com.zy.asrs.entity.CommandInfo;
import com.zy.asrs.entity.TaskWrk;
import com.zy.asrs.entity.param.TaskOverToWms;
import com.zy.asrs.service.CommandInfoService;
import com.zy.asrs.service.TaskWrkService;
import com.core.annotations.ManagerAuth;
import com.core.common.BaseRes;
import com.core.common.Cools;
import com.core.common.R;
import com.zy.common.utils.HttpHandler;
import com.zy.common.web.BaseController;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
 
import java.util.*;
 
@RestController
@Slf4j
public class TaskWrkController extends BaseController {
 
    @Value("${wms.url}")
    private String wmsUrl;
 
    @Autowired
    private TaskWrkService taskWrkService;
 
    @Autowired
    private CommandInfoService commandInfoService;
 
    @RequestMapping(value = "/taskWrk/{wrkNo}/auth")
    @ManagerAuth
    public R get(@PathVariable("wrkNo") Integer wrkNo) {
        return R.ok(taskWrkService.selectByWrkNo(wrkNo));
    }
 
    @RequestMapping(value = "/taskWrk/list/auth")
    @ManagerAuth
    public R list(@RequestParam(defaultValue = "1")Integer curr,
                  @RequestParam(defaultValue = "10")Integer limit,
                  @RequestParam(required = false)String orderByField,
                  @RequestParam(required = false)String orderByType,
                  @RequestParam Map<String, Object> param){
        EntityWrapper<TaskWrk> wrapper = new EntityWrapper<>();
        excludeTrash(param);
        convert(param, wrapper);
        if (!Cools.isEmpty(orderByField)){wrapper.orderBy(humpToLine(orderByField), "asc".equals(orderByType));}
        return R.ok(taskWrkService.selectPage(new Page<>(curr, limit), wrapper));
    }
 
    private <T> void convert(Map<String, Object> map, EntityWrapper<T> wrapper){
        for (Map.Entry<String, Object> entry : map.entrySet()){
            String val = String.valueOf(entry.getValue());
            if (val.contains(RANGE_TIME_LINK)){
                String[] dates = val.split(RANGE_TIME_LINK);
                wrapper.ge(entry.getKey(), DateUtils.convert(dates[0]));
                wrapper.le(entry.getKey(), DateUtils.convert(dates[1]));
            } else {
                wrapper.like(entry.getKey(), val);
            }
        }
    }
 
    @RequestMapping(value = "/taskWrk/add/auth")
    @ManagerAuth
    public R add(TaskWrk taskWrk) {
        taskWrkService.insert(taskWrk);
        return R.ok();
    }
 
    @RequestMapping(value = "/taskWrk/update/auth")
    @ManagerAuth
    public R update(TaskWrk taskWrk){
        if (Cools.isEmpty(taskWrk) || null == taskWrk.getTaskNo()) {
            return R.error();
        }
        taskWrkService.updateById(taskWrk);
        return R.ok();
    }
 
    @RequestMapping(value = "/taskWrk/updatePoint/auth")
    @ManagerAuth
    public R updatePoint(TaskWrk taskWrk){
        if (Cools.isEmpty(taskWrk) || null == taskWrk.getTaskNo()) {
            return R.error();
        }
        TaskWrk taskWrk1 = taskWrkService.selectByTaskNo(taskWrk.getTaskNo());
        if (taskWrk1 == null) {
            return R.error();
        }
        taskWrk1.setStartPoint(taskWrk.getStartPoint());
        taskWrk1.setTargetPoint(taskWrk.getTargetPoint());
        taskWrk1.setModiTime(new Date());
        taskWrk1.setModiUser(getUserId());
        taskWrkService.updateById(taskWrk1);
        return R.ok();
    }
 
    @RequestMapping(value = "/taskWrk/delete/auth")
    @ManagerAuth
    public R delete(@RequestParam(value="ids[]") Long[] ids){
         for (Long id : ids){
            taskWrkService.deleteById(id);
        }
        return R.ok();
    }
 
    @RequestMapping(value = "/taskWrk/export/auth")
    @ManagerAuth
    public R export(@RequestBody JSONObject param){
        EntityWrapper<TaskWrk> wrapper = new EntityWrapper<>();
        List<String> fields = JSONObject.parseArray(param.getJSONArray("fields").toJSONString(), String.class);
        Map<String, Object> map = excludeTrash(param.getJSONObject("taskWrk"));
        convert(map, wrapper);
        List<TaskWrk> list = taskWrkService.selectList(wrapper);
        return R.ok(exportSupport(list, fields));
    }
 
    @RequestMapping(value = "/taskWrkQuery/auth")
    @ManagerAuth
    public R query(String condition) {
        EntityWrapper<TaskWrk> wrapper = new EntityWrapper<>();
        wrapper.like("id", condition);
        Page<TaskWrk> page = taskWrkService.selectPage(new Page<>(0, 10), wrapper);
        List<Map<String, Object>> result = new ArrayList<>();
        for (TaskWrk taskWrk : page.getRecords()){
            Map<String, Object> map = new HashMap<>();
            map.put("id", taskWrk.getTaskNo());
            map.put("value", taskWrk.getTaskNo());
            result.add(map);
        }
        return R.ok(result);
    }
 
    @RequestMapping(value = "/taskWrk/check/column/auth")
    @ManagerAuth
    public R query(@RequestBody JSONObject param) {
        Wrapper<TaskWrk> wrapper = new EntityWrapper<TaskWrk>().eq(humpToLine(String.valueOf(param.get("key"))), param.get("val"));
        if (null != taskWrkService.selectOne(wrapper)){
            return R.parse(BaseRes.REPEAT).add(getComment(TaskWrk.class, String.valueOf(param.get("key"))));
        }
        return R.ok();
    }
 
    @PostMapping(value = "/taskWrk/distribute/auth")
    @ManagerAuth(memo = "手动派发任务")
    public R distribute(@RequestParam String taskNo) {
        taskWrkService.distribute(taskNo, getUserId());
        return R.ok();
    }
 
    @PostMapping(value = "/taskWrk/complete/auth")
    @ManagerAuth(memo = "手动完成任务")
    public R complete(@RequestParam String taskNo) {
        TaskWrk taskWrk = taskWrkService.selectByTaskNo(taskNo);
 
 
        Map<String, Object> map = new HashMap<>();
        map.put("x-api-key","7a15b5db-29b6-552c-8cff-0cfec3756da2");
        TaskOverToWms taskOverToWms = new TaskOverToWms();
        taskOverToWms.setFeedbackFrom("WCS"); //来源
        taskOverToWms.setWarehouseId("1688469798893297665"); //仓库标识
        taskOverToWms.setTaskNo(taskWrk.getTaskNo()); //任务号
        taskOverToWms.setTaskType(getTaskType(taskWrk.getIoType())); // 任务类型
        taskOverToWms.setContainerCode(taskWrk.getBarcode()); // 容器编码
        if (taskWrk.getIoType() ==1 ){
            taskOverToWms.setEquipmentCode(String.valueOf(taskWrk.getCrnNo())); //设备编码
            taskOverToWms.setTargetLocationCode(taskWrk.getOriginTargetPoint()); //目标库位
        }else if (taskWrk.getIoType() ==2){
            Map<Integer,String> map1 = new HashMap<>();
            map1.put(102,"J-1101");
            map1.put(106,"J-1103");
            map1.put(110,"J-1105");
            map1.put(114,"J-1107");
            map1.put(118,"J-1109");
            map1.put(122,"J-1111");
            taskOverToWms.setEquipmentCode(map1.get(taskWrk.getTargetPoint())); //设备编码
            taskOverToWms.setSourceLocationCode(taskWrk.getOriginStartPoint()); //源库位
        }
 
        taskOverToWms.setTaskStatus("handle"); //任务状态
        String response = null;
        try {
            response = new HttpHandler.Builder()
                    .setHeaders(map)
                    .setUri(wmsUrl)
                    .setPath("wcsManager/wcsInterface/taskStatusFeedback")
                    .setJson(JSON.toJSONString(taskOverToWms))
                    .build()
                    .doPost();
        }catch (Exception e){
            log.error("wms连接失败");
        }
 
        JSONObject jsonObject = JSON.parseObject(response);
        if (jsonObject.getInteger("code").equals(200)){
            if (taskWrk == null) {
                return R.error();
            }
            if (taskWrk.getStatus().equals(TaskStatusType.COMPLETE.id)) {
                return R.error(taskWrk.getTaskNo() + "已完结");
            }
            Date now = new Date();
            taskWrk.setStatus(TaskStatusType.COMPLETE.id);
            taskWrk.setModiTime(now);//操作时间
            try{
                taskWrk.setModiUser(getUserId());//操作员
            }catch (Exception e){
                taskWrk.setModiUser(9999L);//操作员
            }
            taskWrk.setCompleteTime(now);//完结时间
            taskWrkService.updateById(taskWrk);
 
 
            if (taskWrkService.saveToHistory(taskWrk.getTaskNo()) > 0) {
                //任务已经转日志,将该任务下面的指令转日志
                commandInfoService.saveToHistory(taskWrk.getTaskNo());
 
                //删除任务
                taskWrkService.delete(new EntityWrapper<TaskWrk>().eq("task_no", taskWrk.getTaskNo()));
                //删除指令
                commandInfoService.delete(new EntityWrapper<CommandInfo>().eq("task_no", taskWrk.getTaskNo()));
            }
        }else {
            return R.error("wms通讯失败");
        }
 
 
        return R.ok();
    }
 
    @PostMapping(value = "/taskWrk/cancel/auth")
    @ManagerAuth(memo = "手动取消任务")
    public R cancel(@RequestParam String taskNo) {
        TaskWrk taskWrk = taskWrkService.selectByTaskNo(taskNo);
        if (taskWrk == null) {
            return R.error();
        }
        if (taskWrk.getStatus().equals(TaskStatusType.CANCEL.id)) {
            return R.error(taskWrk.getTaskNo() + "已被取消");
        }
        Date now = new Date();
        taskWrk.setStatus(TaskStatusType.CANCEL.id);
        taskWrk.setModiTime(now);//操作时间
        try{
            taskWrk.setModiUser(getUserId());//操作员
        }catch (Exception e){
            taskWrk.setModiUser(9999L);//操作员
        }
        taskWrk.setCompleteTime(now);//完结时间
        taskWrkService.updateById(taskWrk);
        return R.ok();
    }
 
    @PostMapping(value = "/taskWrk/updateCommandStep")
    @ManagerAuth(memo = "更新步序")
    public R updateCommandStep(@RequestParam Integer wrkNo, @RequestParam Integer commandStep) {
        TaskWrk taskWrk = taskWrkService.selectByWrkNo(wrkNo);
        if (taskWrk == null) {
            return R.error();
        }
        Date now = new Date();
        taskWrk.setCommandStep(commandStep);
        taskWrk.setModiTime(now);//操作时间
        taskWrk.setModiUser(getUserId());//操作员
        taskWrkService.updateById(taskWrk);
        return R.ok();
    }
 
    public static String getTaskType(Integer paramIoType){
        switch (paramIoType){
            case 1:
                return "RK";
            case 2:
                return "CK";
            case 3:
                return "YK";
            default:
                return "未知";
        }
    }
 
}