Blame view

src/main/java/com/huaheng/api/wcs/controller/EmptyContainerController.java 17.5 KB
游杰 authored
1
2
package com.huaheng.api.wcs.controller;
3
4
5
6
7
8
9
import java.util.*;
import java.util.stream.Collectors;

import javax.annotation.Resource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
游杰 authored
10
11
12
13

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.huaheng.api.wcs.domain.ManyEmptyDomain;
14
import com.huaheng.api.wcs.domain.WarecellLocationDomain;
15
16
import com.huaheng.api.wcs.domain.WcsTask;
import com.huaheng.api.wcs.service.taskAssignService.TaskAssignService;
游杰 authored
17
18
19
20
import com.huaheng.api.wcs.service.warecellAllocation.LocationAllocationService;
import com.huaheng.common.constant.QuantityConstant;
import com.huaheng.common.exception.service.ServiceException;
import com.huaheng.common.utils.StringUtils;
游杰 authored
21
import com.huaheng.framework.aspectj.lang.annotation.ApiLogger;
游杰 authored
22
23
24
25
26
import com.huaheng.framework.aspectj.lang.annotation.Log;
import com.huaheng.framework.aspectj.lang.constant.BusinessType;
import com.huaheng.framework.web.controller.BaseController;
import com.huaheng.framework.web.domain.AjaxResult;
import com.huaheng.framework.web.service.ConfigService;
游杰 authored
27
import com.huaheng.pc.config.address.service.AddressService;
游杰 authored
28
29
import com.huaheng.pc.config.container.domain.Container;
import com.huaheng.pc.config.container.service.ContainerService;
30
import com.huaheng.pc.config.containerType.service.ContainerTypeService;
31
32
import com.huaheng.pc.config.location.domain.Location;
import com.huaheng.pc.config.location.service.LocationService;
游杰 authored
33
34
35
36
import com.huaheng.pc.config.locationHigh.domain.LocationHigh;
import com.huaheng.pc.config.locationHigh.service.LocationHighService;
import com.huaheng.pc.config.locationType.domain.LocationType;
import com.huaheng.pc.config.locationType.service.LocationTypeService;
tongzhonghao authored
37
38
import com.huaheng.pc.config.station.domain.Station;
import com.huaheng.pc.config.station.service.StationService;
游杰 authored
39
40
41
import com.huaheng.pc.config.zone.domain.Zone;
import com.huaheng.pc.config.zone.service.ZoneService;
import com.huaheng.pc.inventory.inventoryHeader.service.InventoryHeaderService;
42
import com.huaheng.pc.system.dict.service.IDictDataService;
游杰 authored
43
44
import com.huaheng.pc.task.taskHeader.domain.TaskHeader;
import com.huaheng.pc.task.taskHeader.service.TaskHeaderService;
游杰 authored
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import com.huaheng.pc.task.taskHeader.service.WorkTaskService;

@RestController
@RequestMapping("/API/WMS/v2")
public class EmptyContainerController extends BaseController {

    @Resource
    private WorkTaskService workTaskService;
    @Resource
    private LocationAllocationService allocationService;
    @Resource
    private ConfigService configService;
    @Resource
    private ZoneService zoneService;
    @Resource
60
61
    private LocationService locationService;
    @Resource
游杰 authored
62
63
64
65
66
    private LocationTypeService locationTypeService;
    @Resource
    private LocationHighService locationHighService;
    @Resource
    private ContainerService containerService;
67
68
    @Resource
    private ContainerTypeService containerTypeService;
游杰 authored
69
70
71
72
    @Autowired
    private AddressService addressService;
    @Resource
    private TaskHeaderService taskHeaderService;
73
74
    @Resource
    private TaskAssignService taskAssignService;
游杰 authored
75
76
    @Resource
    private InventoryHeaderService inventoryHeaderService;
77
78
    @Resource
    private IDictDataService iDictDataService;
tongzhonghao authored
79
80
    @Resource
    private StationService stationService;
游杰 authored
81
游杰 authored
82
    /**
tongzhonghao authored
83
84
85
86
87
88
     * 生成空托盘出库任务
     * @return
     */
    @PostMapping("/emptyOut")
    @Log(title = "任务-任务管理", operating = "生成空托盘出库任务", action = BusinessType.INSERT)
    @ResponseBody
tongzhonghao authored
89
    @ApiLogger(apiName = "emptyOut", from = "ROBOT")
tongzhonghao authored
90
    public AjaxResult emptyOut(@RequestBody ManyEmptyDomain manyEmptyDomain) {
肖超群 authored
91
        AjaxResult ajaxResult = handleMultiProcess("emptyOut", new MultiProcessListener() {
tongzhonghao authored
92
93
            @Override
            public AjaxResult doProcess() {
94
95
                AjaxResult ajaxResult =
                    inventoryHeaderService.createEmptyOut(manyEmptyDomain.getContainerCode(), null, manyEmptyDomain.getPort(), QuantityConstant.WAREHOUSECODE);
tongzhonghao authored
96
97
98
99
100
101
102
                return ajaxResult;
            }
        });
        return ajaxResult;
    }

    /**
103
104
105
106
107
108
     * 生成空托盘入库任务
     * @return
     */
    @PostMapping("/emptyIn")
    @Log(title = "任务-任务管理", operating = "生成空托盘入库任务", action = BusinessType.INSERT)
    @ResponseBody
tongzhonghao authored
109
    @ApiLogger(apiName = "WCS空托入库", from = "WCS")
110
    public AjaxResult emptyIn(@RequestBody ManyEmptyDomain manyEmptyDomain) {
肖超群 authored
111
        AjaxResult ajaxResult = handleMultiProcess("emptyIn", new MultiProcessListener() {
112
113
            @Override
            public AjaxResult doProcess() {
114
115
                AjaxResult ajaxResult =
                    inventoryHeaderService.createEmptyIn(manyEmptyDomain.getContainerCode(), null, manyEmptyDomain.getArea(), manyEmptyDomain.getPort());
116
117
118
119
                return ajaxResult;
            }
        });
        return ajaxResult;
120
121
122
    }

    /**
游杰 authored
123
     * 生成空托盘组入库任务
游杰 authored
124
125
126
127
128
     * @return
     */
    @PostMapping("/manyEmptyIn")
    @Log(title = "任务-任务管理", operating = "生成空托盘组入库任务", action = BusinessType.INSERT)
    @ResponseBody
tongzhonghao authored
129
    @ApiLogger(apiName = "manyEmptyIn", from = "ROBOT")
游杰 authored
130
    public AjaxResult manyEmptyIn(@RequestBody ManyEmptyDomain manyEmptyDomain) {
肖超群 authored
131
        AjaxResult ajaxResult = handleMultiProcess("manyEmptyIn", new MultiProcessListener() {
游杰 authored
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
            @Override
            public AjaxResult doProcess() {
                AjaxResult ajaxResult = innerManyEmptyIn(manyEmptyDomain);
                return ajaxResult;
            }
        });
        return ajaxResult;
    }

    /**
     * 生成空托盘组出库任务
     * @return
     */
    @PostMapping("/manyEmptyOut")
    @Log(title = "任务-任务管理", operating = "生成空托盘组出库任务", action = BusinessType.INSERT)
    @ResponseBody
tongzhonghao authored
148
    @ApiLogger(apiName = "manyEmptyOut", from = "ROBOT")
游杰 authored
149
    public AjaxResult manyEmptyOut(@RequestBody ManyEmptyDomain manyEmptyDomain) {
肖超群 authored
150
        AjaxResult ajaxResult = handleMultiProcess("manyEmptyOut", new MultiProcessListener() {
游杰 authored
151
152
153
154
155
156
157
158
159
160
            @Override
            public AjaxResult doProcess() {
                AjaxResult ajaxResult = innerManyEmptyOut(manyEmptyDomain);
                return ajaxResult;
            }
        });
        return ajaxResult;
    }

    private AjaxResult innerManyEmptyIn(@RequestBody ManyEmptyDomain manyEmptyDomain) {
tongzhonghao authored
161
        if (manyEmptyDomain == null) {
游杰 authored
162
163
164
            throw new ServiceException("空托盘组参数不对!");
        }
        String containerCode = manyEmptyDomain.getContainerCode();
游杰 authored
165
        String warehouseCode = manyEmptyDomain.getWarehouseCode();
游杰 authored
166
167
        String area = manyEmptyDomain.getArea();
        String roadWay = manyEmptyDomain.getRoadWay();
游杰 authored
168
        List<String> roadWays = new ArrayList<>();
tongzhonghao authored
169
        String[] str = roadWay.split(",");
周鸿 authored
170
        roadWays = Arrays.asList(str);
171
tongzhonghao authored
172
        if (StringUtils.isEmpty(manyEmptyDomain.getArea())) {
周鸿 authored
173
174
            throw new ServiceException("参数area不能为空!");
        }
游杰 authored
175
176
177
        LambdaQueryWrapper<Zone> zoneLambdaQueryWrapper = Wrappers.lambdaQuery();
        zoneLambdaQueryWrapper.eq(Zone::getArea, area);
        Zone zone = zoneService.getOne(zoneLambdaQueryWrapper);
tongzhonghao authored
178
179
        if (zone == null) {
            return AjaxResult.error("分配库位时,没有找到库区,area" + area);
游杰 authored
180
        }
181
        // String value = configService.getKey(QuantityConstant.RULE_ALLOCATION);
tongzhonghao authored
182
        String value = iDictDataService.getDictValueByLabel(QuantityConstant.RULE_ALLOCATION, zone.getCode());
183
184

        String height = manyEmptyDomain.getHeight();
185
186
187
188
189
        /*
         * if (StringUtils.isEmpty(height)) {
         * return AjaxResult.error("高度参数为空,请输入高度");
         * }
         */
190
        if (StringUtils.isEmpty(value)) {
tongzhonghao authored
191
            return AjaxResult.error(zone.getCode() + "库区未绑定定位规则,请到字典管理中绑定库区定位规则");
192
193
194
        }
        int allocationRule = Integer.parseInt(value);
游杰 authored
195
        LambdaQueryWrapper<TaskHeader> taskHeaderLambdaQueryWrapper = Wrappers.lambdaQuery();
196
197
        taskHeaderLambdaQueryWrapper.eq(TaskHeader::getContainerCode, containerCode).eq(TaskHeader::getWarehouseCode, warehouseCode).lt(TaskHeader::getStatus,
            QuantityConstant.TASK_STATUS_COMPLETED);
游杰 authored
198
        TaskHeader taskHeader = taskHeaderService.getOne(taskHeaderLambdaQueryWrapper);
tongzhonghao authored
199
        if (taskHeader != null) {
游杰 authored
200
201
            return AjaxResult.success("已经生成空托盘组任务");
        }
202
        // 查询满足条件的库位类型
游杰 authored
203
        LambdaQueryWrapper<LocationType> lambdaQueryWrapper = Wrappers.lambdaQuery();
204
        lambdaQueryWrapper.eq(LocationType::getZoneCode, zone.getCode()).eq(LocationType::getWarehouseCode, warehouseCode);
游杰 authored
205
        List<LocationType> locationTypeList = locationTypeService.list(lambdaQueryWrapper);
tongzhonghao authored
206
207
        if (locationTypeList == null) {
            return AjaxResult.error(zone.getCode() + "库区分配库位时,没有找到库位类型,请到库位类型确认库区");
游杰 authored
208
        }
209
        List<String> locationTypeCodeList = locationTypeList.stream().map(t -> t.getCode()).collect(Collectors.toList());
游杰 authored
210
        int highHeight = Float.valueOf(height).intValue();
游杰 authored
211
        LambdaQueryWrapper<LocationHigh> locationHighLambdaQueryWrapper = Wrappers.lambdaQuery();
212
        locationHighLambdaQueryWrapper.eq(LocationHigh::getHighLevel, highHeight).in(LocationHigh::getLocationTypeCode, locationTypeCodeList);
游杰 authored
213
214
        LocationHigh locationHigh = locationHighService.getOne(locationHighLambdaQueryWrapper);
        int high = locationHigh.getHigh();
215
216
217
        WarecellLocationDomain domain =
            allocationService.createWarecellLcaotionDoamin(allocationRule, locationTypeCodeList, high, area, roadWays, warehouseCode, containerCode, null);
218
        String locationCode = allocationService.allocation(domain);
tongzhonghao authored
219
        if (locationCode == null) {
游杰 authored
220
221
222
223
224
            return AjaxResult.error("分配库位时,没有找到库位");
        }
        return workTaskService.createManyEmptyIn(containerCode, locationCode, warehouseCode);
    }
游杰 authored
225
    private AjaxResult innerManyEmptyOut(ManyEmptyDomain manyEmptyDomain) {
tongzhonghao authored
226
        if (manyEmptyDomain == null) {
游杰 authored
227
228
            throw new ServiceException("空托盘组参数不对!");
        }
tongzhonghao authored
229
        if (StringUtils.isEmpty(manyEmptyDomain.getArea())) {
周鸿 authored
230
231
            throw new ServiceException("参数area不能为空!");
        }
游杰 authored
232
        String warehouseCode = manyEmptyDomain.getWarehouseCode();
233
        String area = manyEmptyDomain.getArea();
游杰 authored
234
        String port = manyEmptyDomain.getPort();
235
        LambdaQueryWrapper<Container> containerLambdaQueryWrapper = Wrappers.lambdaQuery();
236
        containerLambdaQueryWrapper.eq(Container::getStatus, QuantityConstant.STATUS_CONTAINER_MANY).eq(Container::getWarehouseCode, warehouseCode);
237
238
        List<Container> containerList = containerService.list(containerLambdaQueryWrapper);
        List<Container> removeContainerList = new ArrayList<>();
tongzhonghao authored
239
240
        if (containerList != null && containerList.size() > 0) {
            for (Container container : containerList) {
241
242
                String locationCode = container.getLocationCode();
                Location location = locationService.getLocationByCode(locationCode, warehouseCode);
tongzhonghao authored
243
                if (!location.getArea().equals(area)) {
244
245
246
247
248
249
250
251
252
                    removeContainerList.add(container);
                }
            }
        }
        LambdaQueryWrapper<Zone> zoneLambdaQueryWrapper = Wrappers.lambdaQuery();
        zoneLambdaQueryWrapper.eq(Zone::getArea, area);
        Zone zone = zoneService.getOne(zoneLambdaQueryWrapper);
        LambdaQueryWrapper<TaskHeader> taskHeaderLambdaQueryWrapper = Wrappers.lambdaQuery();
        taskHeaderLambdaQueryWrapper.lt(TaskHeader::getStatus, QuantityConstant.TASK_STATUS_COMPLETED)
253
            .eq(TaskHeader::getTaskType, QuantityConstant.TASK_TYPE_MANY_EMPTYSHIPMENT).eq(TaskHeader::getPort, port).eq(TaskHeader::getZoneCode, zone.getCode());
254
        TaskHeader taskHeader = taskHeaderService.getOne(taskHeaderLambdaQueryWrapper);
tongzhonghao authored
255
        if (taskHeader != null) {
256
257
258
259
260
261
262
263
264
            WcsTask wcsTask = new WcsTask();
            wcsTask.setTaskType(taskHeader.getTaskType());
            wcsTask.setTaskNo(String.valueOf(taskHeader.getId()));
            wcsTask.setContainerCode(taskHeader.getContainerCode());
            wcsTask.setWarehouseCode(warehouseCode);
            wcsTask.setFromLocationCode(taskHeader.getFromLocation());
            wcsTask.setPlatform(QuantityConstant.PLATFORM_WMS);
            wcsTask.setPriority(1000);
            wcsTask.setTaskStatus(taskHeader.getStatus());
游杰 authored
265
            wcsTask.setToPort(port);
tongzhonghao authored
266
            wcsTask = taskAssignService.switchTaskTypeToWcs(wcsTask, taskHeader);
267
268
269
            return AjaxResult.success(wcsTask);
        }
        containerList.removeAll(removeContainerList);
tongzhonghao authored
270
        if (!(containerList != null && containerList.size() > 0)) {
游杰 authored
271
            return AjaxResult.error("没有找到合适的空托盘组!");
游杰 authored
272
        }
273
        String containerCode = containerList.get(0).getCode();
游杰 authored
274
        Container container = containerService.getContainerByCode(containerCode, warehouseCode);
tongzhonghao authored
275
        if (container == null) {
游杰 authored
276
277
            throw new ServiceException("没有找到托盘“");
        }
278
        return workTaskService.createManyEmptyOut(containerCode, warehouseCode, port);
游杰 authored
279
    }
游杰 authored
280
281
282
283
284
285
286
287

    /**
     * 生成空托出库任务
     * @return
     */
    @PostMapping("/wcsCallEmptyOut")
    @Log(title = "任务-任务管理", operating = "生成空托出库任务", action = BusinessType.INSERT)
    @ResponseBody
tongzhonghao authored
288
    @ApiLogger(apiName = "生成空托出库任务", from = "WCS")
游杰 authored
289
    public AjaxResult wcsCallEmptyOut(@RequestBody ManyEmptyDomain manyEmptyDomain) {
肖超群 authored
290
        AjaxResult ajaxResult = handleMultiProcess("wcsCallEmptyOut", new MultiProcessListener() {
游杰 authored
291
292
293
294
295
296
297
298
299
300
            @Override
            public AjaxResult doProcess() {
                AjaxResult ajaxResult = innerWcsCallEmptyOut(manyEmptyDomain);
                return ajaxResult;
            }
        });
        return ajaxResult;
    }

    private AjaxResult innerWcsCallEmptyOut(ManyEmptyDomain manyEmptyDomain) {
tongzhonghao authored
301
        boolean isSuc = false;
游杰 authored
302
303
304
        String warehouseCode = manyEmptyDomain.getWarehouseCode();
        String area = manyEmptyDomain.getArea();
        String port = manyEmptyDomain.getPort();
305
        String areaByWcs = manyEmptyDomain.getAreaByWcs();
tongzhonghao authored
306
tongzhonghao authored
307
        if (warehouseCode == null) {
游杰 authored
308
309
            return AjaxResult.error("warehouseCode 不能为空");
        }
tongzhonghao authored
310
        if (area == null) {
游杰 authored
311
312
            return AjaxResult.error("area 不能为空");
        }
tongzhonghao authored
313
        if (port == null) {
游杰 authored
314
315
316
            return AjaxResult.error("port 不能为空");
        }
        LambdaQueryWrapper<Zone> zoneLambdaQueryWrapper = Wrappers.lambdaQuery();
317
        zoneLambdaQueryWrapper.eq(Zone::getWarehouseCode, warehouseCode).eq(Zone::getArea, area);
游杰 authored
318
        Zone zone = zoneService.getOne(zoneLambdaQueryWrapper);
tongzhonghao authored
319
        if (zone == null) {
游杰 authored
320
321
322
            return AjaxResult.error("area不正确,没有找到对应区域");
        }
        String zoneCode = zone.getCode();
323
324
325
        List<TaskHeader> taskHeaders =
            taskHeaderService.list(new LambdaQueryWrapper<TaskHeader>().eq(TaskHeader::getPort, port).eq(TaskHeader::getZoneCode, zoneCode)
                .eq(TaskHeader::getWarehouseCode, QuantityConstant.WAREHOUSECODE).lt(TaskHeader::getStatus, QuantityConstant.TASK_STATUS_COMPLETED));
tongzhonghao authored
326
        isSuc = !taskHeaders.isEmpty();
tongzhonghao authored
327
        switch (area) {
328
            // 外观仓 可以出多个空托盘
tongzhonghao authored
329
            case "6":
tongzhonghao authored
330
331
                isSuc = taskHeaders.size() > 2;
                break;
tongzhonghao authored
332
            default:
tongzhonghao authored
333
        }
334
        // 有该站台任务 返回成功
tongzhonghao authored
335
        if (isSuc) {
336
337
            return AjaxResult.success();
        }
338
        // 对应巷道 站台出到 选择对应库内容器
tongzhonghao authored
339
        Station station = stationService.getStaionByCode(port);
tongzhonghao authored
340
341
342

        String[] strs = station.getRoadWay().split(",");
        List<String> roadways = Arrays.asList(strs);
343
        List<Location> list = containerService.getEmptyContainerInLocation(zoneCode, "", "", warehouseCode, null, roadways);
tongzhonghao authored
344
345
        if (list.isEmpty()) {
            return AjaxResult.error(zoneCode + "库区没有找到空托盘");
游杰 authored
346
        }
347
348
        List<Location> areaByWcsLocations = new ArrayList<>();
349
        // 获取最大库位高度 空托盘
350
351
        Optional<Location> max = list.stream().max(Comparator.comparing(Location::getHigh));
        Location location1 = max.get();
352
        // 获取最大库位高度空托盘列表
tongzhonghao authored
353
        areaByWcsLocations = list.stream().filter(e -> e.getHigh().equals(location1.getHigh())).collect(Collectors.toList());
354
355
        areaByWcsLocations =
            areaByWcsLocations.stream().sorted(Comparator.comparing(Location::getILayer).thenComparing(Location::getId)).collect(Collectors.toList());
tongzhonghao authored
356
357
358
        if (StringUtils.isNotEmpty(areaByWcs)) {
            switch (areaByWcs) {
                case "A":
359
360
361
                    areaByWcsLocations.sort(Comparator.comparing(Location::getIColumn, (l1, l2) -> {
                        return l1.compareTo(l2);
                    }));
tongzhonghao authored
362
363
                    break;
                case "B":
364
365
366
                    areaByWcsLocations.sort(Comparator.comparing(Location::getIColumn, (l1, l2) -> {
                        return l2.compareTo(l1);
                    }));
tongzhonghao authored
367
368
369
                    break;
                default:
            }
370
371
        }
372
        Location location = areaByWcsLocations.get(0);
游杰 authored
373
374
375
376
        String containerCode = location.getContainerCode();
        String locationCode = location.getCode();
        return inventoryHeaderService.createEmptyOut(containerCode, locationCode, port, warehouseCode);
    }
游杰 authored
377
}