自动化立体仓库 - WMS系统
skyouc
16 小时以前 7b72d43503aa5df4c152b777777085d3cd5e2132
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
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
package com.zy.asrs.controller;
 
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.core.annotations.ManagerAuth;
import com.core.common.BaseRes;
import com.core.common.Cools;
import com.core.common.R;
import com.core.exception.CoolException;
import com.zy.api.enums.LocAreaType;
import com.zy.asrs.entity.*;
import com.zy.asrs.service.*;
import com.zy.asrs.service.impl.BasAreasServiceImpl;
import com.zy.asrs.service.impl.BasStationServiceImpl;
import com.zy.asrs.service.impl.LocCacheServiceImpl;
import com.zy.common.model.LocDto;
import com.zy.common.model.TaskDto;
import com.zy.common.web.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
 
import javax.annotation.Resource;
import java.util.*;
import java.util.stream.Collectors;
 
/**
 * Created by vincent on 2022/3/26
 */
 
@RestController
public class OutController extends BaseController {
 
    @Autowired
    private OrderService orderService;
    @Autowired
    private OrderDetlService orderDetlService;
    @Autowired
    private OrderDetlPakoutService orderDetlPakoutService;
    @Autowired
    private LocDetlService locDetlService;
    @Autowired
    private LocMastService locMastService;
    @Autowired
    private StaDescService staDescService;
    @Autowired
    private WorkService workService;
    @Autowired
    private BasDevpService basDevpService;
 
    @Resource
    private OrderPakoutService orderPakOutService;
    @Autowired
    private CheckOrderService checkOrderService;
    @Autowired
    private BasAreasService basAreasService;
    @Autowired
    private LocCacheServiceImpl locCacheService;
    @Autowired
    private BasStationServiceImpl basStationService;
 
 
    @PostMapping("/out/pakout/orderDetlIds/auth")
    @ManagerAuth
    public R pakoutOrderDetlIds(@RequestParam Long orderId) throws InterruptedException {
        Thread.sleep(200);
        return R.ok().add(orderDetlPakoutService.selectByOrderId(orderId).stream().map(OrderDetlPakout::getId).distinct().collect(Collectors.toList()));
    }
 
    @PostMapping("/out/pakout/preview/auth")
    @ManagerAuth
    public R pakoutPreview(@RequestBody List<Long> ids) {
        if (Cools.isEmpty(ids)) {
            return R.parse(BaseRes.PARAM);
        }
        List<OrderDetlPakout> orderDetlPakouts = orderDetlPakoutService.selectBatchIds(ids);
 
        if (orderDetlPakouts.size() == 0) {
            return R.parse("订单明细为空");
        }
 
        List<LocDto> locDtos = new ArrayList<>();
 
        Set<String> exist = new HashSet<>();        
 
 
 
        // 获取订单主表
        OrderPakout orderPakOut = orderPakOutService.selectByNo(orderDetlPakouts.get(0).getOrderNo());
        // 备货单
        if (orderPakOut.getDocType() == 5) {
            List<BasAreas> basAreas = basAreasService.selectList(new EntityWrapper<BasAreas>().in("whs_type_id", LocAreaType.SO_HOLDING.type, LocAreaType.EO_HOLDING.type));
            List<Long> areaIds = basAreas.stream()
                    .map(BasAreas::getId)
                    .collect(Collectors.toList());
            for (OrderDetlPakout orderDetl : orderDetlPakouts) {
                double issued = Optional.of(orderDetl.getAnfme() - orderDetl.getWorkQty()).orElse(0.0D);
                if (issued <= 0.0D) {
                    continue;
                }
                List<LocDetl> locDetls = locDetlService.queryStockAllCache(null, exist,orderDetl.getMatnr(), orderDetl.getBatch(),
                        orderDetl.getBrand(),orderDetl.getStandby1(),orderDetl.getStandby2(),orderDetl.getStandby3(),orderDetl.getBoxType1(),orderDetl.getBoxType2(),orderDetl.getBoxType3(),areaIds);
                for (LocDetl locDetl : locDetls) {
                    if (issued > 0) {
                        LocDto locDto = new LocDto(locDetl.getLocNo(), locDetl.getMatnr(), locDetl.getMaktx(), locDetl.getBatch(), orderDetl.getOrderNo(),
                                issued >= locDetl.getAnfme() ? locDetl.getAnfme() : issued);
//                        LocMast locMast = locMastService.selectOne(new EntityWrapper<LocMast>().eq("loc_no", locDetl.getLocNo()));
                        LocCache locCache = locCacheService.selectOne(new EntityWrapper<LocCache>().eq("loc_no", locDetl.getLocNo()));
                        locDto.setFrozen(locDetl.getFrozen());
                        locDto.setFrozenLoc(locCache.getFrozen());
                        List<BasStation> basStations = basStationService.selectList(new EntityWrapper<BasStation>().in("area_id", areaIds));
                        List<String> collect = basStations.stream().map(BasStation::getDevNo).collect(Collectors.toList());
                        locDto.setAgvStaNos(collect);
                        locDto.setBrand(orderDetl.getBrand());
 
                        locDto.setStandby1(orderDetl.getStandby1());
                        locDto.setStandby2(orderDetl.getStandby2());
                        locDto.setStandby3(orderDetl.getStandby3());
                        locDto.setBoxType1(orderDetl.getBoxType1());
                        locDto.setBoxType2(orderDetl.getBoxType2());
                        locDto.setBoxType3(orderDetl.getBoxType3());
                        locDtos.add(locDto);
                        exist.add(locDetl.getLocNo());
                        // 剩余待出数量递减
                        issued = issued - locDetl.getAnfme();
                    } else {
                        break;
                    }
                }
                if (issued > 0) {
                    LocDto locDto = new LocDto(null, orderDetl.getMatnr(), orderDetl.getMaktx(), orderDetl.getBatch(), orderDetl.getOrderNo(), issued);
                    locDto.setBrand(orderDetl.getBrand());
                    locDto.setStandby1(orderDetl.getStandby1());
                    locDto.setStandby2(orderDetl.getStandby2());
                    locDto.setStandby3(orderDetl.getStandby3());
                    locDto.setBoxType1(orderDetl.getBoxType1());
                    locDto.setBoxType2(orderDetl.getBoxType2());
                    locDto.setBoxType3(orderDetl.getBoxType3());
                    locDto.setLack(Boolean.TRUE);
                    locDtos.add(locDto);
                }
            }
        } else {
            List<BasAreas> basAreas = basAreasService.selectList(new EntityWrapper<BasAreas>().in("whs_type_id", LocAreaType.AUTOMATED.type));
            List<Long> areaIds = basAreas.stream()
                    .map(BasAreas::getId)
                    .collect(Collectors.toList());
            for (OrderDetlPakout orderDetl : orderDetlPakouts) {
                double issued = Optional.of(orderDetl.getAnfme() - orderDetl.getWorkQty()).orElse(0.0D);
                if (issued <= 0.0D) {
                    continue;
                }
                List<LocDetl> locDetls = locDetlService.queryStockAll(null, exist,orderDetl.getMatnr(), orderDetl.getBatch(),
                        orderDetl.getBrand(),orderDetl.getStandby1(),orderDetl.getStandby2(),orderDetl.getStandby3(),orderDetl.getBoxType1(),orderDetl.getBoxType2(),orderDetl.getBoxType3(),areaIds);
                for (LocDetl locDetl : locDetls) {
                    if (issued > 0) {
                        LocDto locDto = new LocDto(locDetl.getLocNo(), locDetl.getMatnr(), locDetl.getMaktx(), locDetl.getBatch(), orderDetl.getOrderNo(),
                                issued >= locDetl.getAnfme() ? locDetl.getAnfme() : issued);
                        LocMast locMast = locMastService.selectOne(new EntityWrapper<LocMast>().eq("loc_no", locDetl.getLocNo()));
                        locDto.setFrozen(locDetl.getFrozen());
                        locDto.setFrozenLoc(locMast.getFrozen());
                        List<Integer> staNos = staDescService.queryOutStaNosByLocNo(locDetl.getLocNo(), issued >= locDetl.getAnfme() ? 101 : 103);
                        locDto.setStaNos(staNos);
                        locDto.setBrand(orderDetl.getBrand());
 
                        locDto.setStandby1(orderDetl.getStandby1());
                        locDto.setStandby2(orderDetl.getStandby2());
                        locDto.setStandby3(orderDetl.getStandby3());
                        locDto.setBoxType1(orderDetl.getBoxType1());
                        locDto.setBoxType2(orderDetl.getBoxType2());
                        locDto.setBoxType3(orderDetl.getBoxType3());
                        locDtos.add(locDto);
                        exist.add(locDetl.getLocNo());
                        // 剩余待出数量递减
                        issued = issued - locDetl.getAnfme();
                    } else {
                        break;
                    }
                }
                if (issued > 0) {
                    LocDto locDto = new LocDto(null, orderDetl.getMatnr(), orderDetl.getMaktx(), orderDetl.getBatch(), orderDetl.getOrderNo(), issued);
                    locDto.setBrand(orderDetl.getBrand());
                    locDto.setStandby1(orderDetl.getStandby1());
                    locDto.setStandby2(orderDetl.getStandby2());
                    locDto.setStandby3(orderDetl.getStandby3());
                    locDto.setBoxType1(orderDetl.getBoxType1());
                    locDto.setBoxType2(orderDetl.getBoxType2());
                    locDto.setBoxType3(orderDetl.getBoxType3());
                    locDto.setLack(Boolean.TRUE);
                    locDtos.add(locDto);
                }
            }
        }
        return R.ok().add(locDtos);
    }
 
    @PostMapping("/out/pakout/auth")
    @ManagerAuth(memo = "订单出库")
    public synchronized R pakout(@RequestBody List<LocDto> locDtos) throws InterruptedException {
        if (Cools.isEmpty(locDtos)) {
            return R.parse(BaseRes.PARAM);
        }
        List<LocDto> locDtoArrayList = new ArrayList<>();
        for (LocDto locDto : locDtos){
            if (locDto.getFrozen()!=1 && locDto.getFrozenLoc()!=1){
                locDtoArrayList.add(locDto);
            }
        }
        locDtos = locDtoArrayList;
        if (Cools.isEmpty(locDtos)) {
            return R.parse("库存/库位被冻结,请处理后出库!!!");
        }
        boolean lack = true;
        for (LocDto locDto : locDtos) {
            if (!locDto.isLack()) {
                lack = false;
                break;
            }
        }
        if (lack) {
            return R.error("库存不足");
        }
 
        Thread.sleep(1000L);
 
        List<TaskDto> taskDtos = new ArrayList<>();
        // 根据 (库位 & 出库站) 分组; 理想状态:一组为一次出库任务
        for (LocDto locDto : locDtos) {
            if (locDto.isLack()) { continue; }
            TaskDto taskDto = new TaskDto(locDto.getLocNo(), locDto.getStaNo(), locDto);
            if (TaskDto.has(taskDtos, taskDto)) {
                TaskDto dto = TaskDto.find(taskDtos, taskDto);
                assert dto != null;
                dto.getLocDtos().addAll(taskDto.getLocDtos());
            } else {
                taskDtos.add(taskDto);
            }
        }
        // -----------------------------------------------------------------------------------------------
        for (TaskDto taskDto : taskDtos) {
            BasDevp staNo = basDevpService.checkSiteStatus(taskDto.getStaNo());
            workService.stockOut(staNo, taskDto, getUserId());
        }
        return R.ok();
    }
 
    @PostMapping("/out/checkPakOut/auth")
    @ManagerAuth(memo = "订单出库")
    public synchronized R checkPakOut(@RequestBody List<LocDto> locDtos) throws InterruptedException {
        if (Cools.isEmpty(locDtos)) {
            return R.parse(BaseRes.PARAM);
        }
        List<LocDto> locDtoArrayList = new ArrayList<>();
        for (LocDto locDto : locDtos){
            if (locDto.getFrozen()!=1 && locDto.getFrozenLoc()!=1){
                locDtoArrayList.add(locDto);
            }
        }
        locDtos = locDtoArrayList;
        if (Cools.isEmpty(locDtos)) {
            return R.parse("库存/库位被冻结,请处理后出库!!!");
        }
        boolean lack = true;
        for (LocDto locDto : locDtos) {
            if (!locDto.isLack()) {
                lack = false;
                break;
            }
        }
        if (lack) {
            return R.error("库存不足");
        }
 
        Thread.sleep(1000L);
 
        List<TaskDto> taskDtos = new ArrayList<>();
        // 根据 (库位 & 出库站) 分组; 理想状态:一组为一次出库任务
        for (LocDto locDto : locDtos) {
            if (locDto.isLack()) { continue; }
            TaskDto taskDto = new TaskDto(locDto.getLocNo(), locDto.getStaNo(), locDto);
            if (TaskDto.has(taskDtos, taskDto)) {
                TaskDto dto = TaskDto.find(taskDtos, taskDto);
                assert dto != null;
                dto.getLocDtos().addAll(taskDto.getLocDtos());
            } else {
                taskDtos.add(taskDto);
            }
        }
        // -----------------------------------------------------------------------------------------------
        for (TaskDto taskDto : taskDtos) {
            BasDevp staNo = basDevpService.checkSiteStatus(taskDto.getStaNo());
            workService.checkStockOut(staNo, taskDto, getUserId());
        }
 
        String orderNo = taskDtos.get(0).getLocDtos().get(0).getOrderNo();
        CheckOrder checkOrder = checkOrderService.selectOne(new EntityWrapper<CheckOrder>().eq("order_no", orderNo));
        checkOrder.setSettle(11L);
        if (!checkOrderService.updateById(checkOrder)) {
            throw new CoolException("更新盘点单状态失败");
        }
        return R.ok();
    }
 
 
    @PostMapping("/out/agvPakOut/auth")
    @ManagerAuth(memo = "订单出库")
    public synchronized R agvPakOut(@RequestBody List<LocDto> locDtos) throws InterruptedException {
        if (Cools.isEmpty(locDtos)) {
            return R.parse(BaseRes.PARAM);
        }
        List<LocDto> locDtoArrayList = new ArrayList<>();
        for (LocDto locDto : locDtos){
            if (locDto.getFrozen()!=1 && locDto.getFrozenLoc()!=1){
                locDtoArrayList.add(locDto);
            }
        }
        locDtos = locDtoArrayList;
        if (Cools.isEmpty(locDtos)) {
            return R.parse("库存/库位被冻结,请处理后出库!!!");
        }
        boolean lack = true;
        for (LocDto locDto : locDtos) {
            if (!locDto.isLack()) {
                lack = false;
                break;
            }
        }
        if (lack) {
            return R.error("库存不足");
        }
 
        Thread.sleep(1000L);
 
        List<TaskDto> taskDtos = new ArrayList<>();
        // 根据 (库位 & 出库站) 分组; 理想状态:一组为一次出库任务
        for (LocDto locDto : locDtos) {
            if (locDto.isLack()) { continue; }
            TaskDto taskDto = new TaskDto(locDto.getLocNo(), locDto.getAgvStaNo(), locDto);
            if (TaskDto.has(taskDtos, taskDto)) {
                TaskDto dto = TaskDto.find(taskDtos, taskDto);
                assert dto != null;
                dto.getLocDtos().addAll(taskDto.getLocDtos());
            } else {
                taskDtos.add(taskDto);
            }
        }
        // -----------------------------------------------------------------------------------------------
        for (TaskDto taskDto : taskDtos) {
//            BasDevp staNo = basDevpService.checkSiteStatus(taskDto.getStaNo());
            BasStation station = basStationService.selectOne(new EntityWrapper<BasStation>().eq("dev_no", taskDto.getAgvStaNo()));
            workService.agvStockOut(station, taskDto, getUserId());
        }
        return R.ok();
    }
 
}