Blame view

src/main/java/com/huaheng/api/wcs/controller/EmptyContainerController.java 12 KB
游杰 authored
1
2
3
package com.huaheng.api.wcs.controller;
游杰 authored
4
import com.alibaba.fastjson.JSONArray;
游杰 authored
5
6
7
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.huaheng.api.wcs.domain.ManyEmptyDomain;
8
9
import com.huaheng.api.wcs.domain.WcsTask;
import com.huaheng.api.wcs.service.taskAssignService.TaskAssignService;
游杰 authored
10
11
12
13
14
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.support.Convert;
import com.huaheng.common.utils.StringUtils;
游杰 authored
15
import com.huaheng.framework.aspectj.lang.annotation.ApiLogger;
游杰 authored
16
17
18
19
20
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
21
import com.huaheng.pc.config.address.service.AddressService;
游杰 authored
22
23
import com.huaheng.pc.config.container.domain.Container;
import com.huaheng.pc.config.container.service.ContainerService;
24
25
import com.huaheng.pc.config.containerType.domain.ContainerType;
import com.huaheng.pc.config.containerType.service.ContainerTypeService;
26
27
import com.huaheng.pc.config.location.domain.Location;
import com.huaheng.pc.config.location.service.LocationService;
游杰 authored
28
29
30
31
32
33
34
35
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;
import com.huaheng.pc.config.zone.domain.Zone;
import com.huaheng.pc.config.zone.service.ZoneService;
import com.huaheng.pc.inventory.inventoryHeader.domain.InventoryHeader;
import com.huaheng.pc.inventory.inventoryHeader.service.InventoryHeaderService;
游杰 authored
36
37
import com.huaheng.pc.task.taskHeader.domain.TaskHeader;
import com.huaheng.pc.task.taskHeader.service.TaskHeaderService;
游杰 authored
38
39
import com.huaheng.pc.task.taskHeader.service.WorkTaskService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
游杰 authored
40
import org.springframework.beans.factory.annotation.Autowired;
游杰 authored
41
42
43
44
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
游杰 authored
45
import java.util.ArrayList;
游杰 authored
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

@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
63
64
    private LocationService locationService;
    @Resource
游杰 authored
65
66
67
68
69
    private LocationTypeService locationTypeService;
    @Resource
    private LocationHighService locationHighService;
    @Resource
    private ContainerService containerService;
70
71
    @Resource
    private ContainerTypeService containerTypeService;
肖超群 authored
72
    @Resource
游杰 authored
73
74
75
    private AddressService addressService;
    @Resource
    private TaskHeaderService taskHeaderService;
76
77
    @Resource
    private TaskAssignService taskAssignService;
游杰 authored
78
79
80
    @Resource
    private InventoryHeaderService inventoryHeaderService;
游杰 authored
81
    /**
游杰 authored
82
     * 生成空托盘组入库任务
游杰 authored
83
84
85
86
87
88
     * @return
     */
    @PostMapping("/manyEmptyIn")
    @Log(title = "任务-任务管理", operating = "生成空托盘组入库任务", action = BusinessType.INSERT)
    @ResponseBody
    @Transactional
游杰 authored
89
    @ApiLogger(apiName = "manyEmptyIn", from="ROBOT")
游杰 authored
90
    public AjaxResult manyEmptyIn(@RequestBody ManyEmptyDomain manyEmptyDomain) {
91
        AjaxResult ajaxResult = handleMultiProcess("manyEmptyIn",new MultiProcessListener() {
游杰 authored
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
            @Override
            public AjaxResult doProcess() {
                AjaxResult ajaxResult = innerManyEmptyIn(manyEmptyDomain);
                return ajaxResult;
            }
        });
        return ajaxResult;
    }

    /**
     * 生成空托盘组出库任务
     * @return
     */
    @PostMapping("/manyEmptyOut")
    @Log(title = "任务-任务管理", operating = "生成空托盘组出库任务", action = BusinessType.INSERT)
    @ResponseBody
    @Transactional
    @ApiLogger(apiName = "manyEmptyOut", from="ROBOT")
    public AjaxResult manyEmptyOut(@RequestBody ManyEmptyDomain manyEmptyDomain) {
111
        AjaxResult ajaxResult = handleMultiProcess("manyEmptyOut",new MultiProcessListener() {
游杰 authored
112
113
114
115
116
117
118
119
120
121
            @Override
            public AjaxResult doProcess() {
                AjaxResult ajaxResult = innerManyEmptyOut(manyEmptyDomain);
                return ajaxResult;
            }
        });
        return ajaxResult;
    }

    private AjaxResult innerManyEmptyIn(@RequestBody ManyEmptyDomain manyEmptyDomain) {
游杰 authored
122
123
124
125
        if(manyEmptyDomain == null){
            throw new ServiceException("空托盘组参数不对!");
        }
        String containerCode = manyEmptyDomain.getContainerCode();
游杰 authored
126
        String warehouseCode = manyEmptyDomain.getWarehouseCode();
游杰 authored
127
        String area = manyEmptyDomain.getArea();
128
        String roadWay = manyEmptyDomain.getRoadWay();
129
        String height = manyEmptyDomain.getHeight();
游杰 authored
130
        List<String> roadWays = new ArrayList<>();
肖超群 authored
131
        String[] str= roadWay.split(",");
肖超群 authored
132
        roadWays = Arrays.asList(str);
游杰 authored
133
134
135
136
137
138
139
140
141
142
143
        String value = configService.getKey(QuantityConstant.RULE_ALLOCATION);
        if (StringUtils.isEmpty(value)) {
            return AjaxResult.error("未绑定定位规则");
        }
        int allocationRule = Integer.parseInt(value);
        LambdaQueryWrapper<Zone> zoneLambdaQueryWrapper = Wrappers.lambdaQuery();
        zoneLambdaQueryWrapper.eq(Zone::getArea, area);
        Zone zone = zoneService.getOne(zoneLambdaQueryWrapper);
        if(zone == null) {
            return AjaxResult.error("分配库位时,没有找到库区");
        }
游杰 authored
144
145
146
147
148
149
150
151
        LambdaQueryWrapper<TaskHeader> taskHeaderLambdaQueryWrapper = Wrappers.lambdaQuery();
        taskHeaderLambdaQueryWrapper.eq(TaskHeader::getContainerCode, containerCode)
                .eq(TaskHeader::getWarehouseCode, warehouseCode)
                .lt(TaskHeader::getStatus, QuantityConstant.TASK_STATUS_COMPLETED);
        TaskHeader taskHeader = taskHeaderService.getOne(taskHeaderLambdaQueryWrapper);
        if(taskHeader != null) {
            return AjaxResult.success("已经生成空托盘组任务");
        }
游杰 authored
152
153
154
155
156
157
158
159
160
161
        //查询满足条件的库位类型
        LambdaQueryWrapper<LocationType> lambdaQueryWrapper = Wrappers.lambdaQuery();
        lambdaQueryWrapper.eq(LocationType::getZoneCode, zone.getCode())
                .eq(LocationType::getWarehouseCode, warehouseCode);
        List<LocationType> locationTypeList = locationTypeService.list(lambdaQueryWrapper);
        if(locationTypeList == null) {
            return AjaxResult.error("分配库位时,没有找到库位类型");
        }
        List<String> locationTypeCodeList = locationTypeList.stream().
                map(t -> t.getCode()).collect(Collectors.toList());
游杰 authored
162
        int highHeight = Float.valueOf(height).intValue();
游杰 authored
163
        LambdaQueryWrapper<LocationHigh> locationHighLambdaQueryWrapper = Wrappers.lambdaQuery();
游杰 authored
164
        locationHighLambdaQueryWrapper.eq(LocationHigh::getHighLevel, highHeight)
游杰 authored
165
166
167
                .in(LocationHigh::getLocationTypeCode, locationTypeCodeList);
        LocationHigh locationHigh = locationHighService.getOne(locationHighLambdaQueryWrapper);
        int high = locationHigh.getHigh();
168
        //空托盘优先入1,2巷道
169
        List<String> roadWayReault = allocationService.getRoadWays(area, roadWays, warehouseCode);
游杰 authored
170
        String locationCode = allocationService.allocation(allocationRule, locationTypeCodeList, high, area,
171
                roadWayReault, warehouseCode, containerCode, null,null);
172
        if (StringUtils.isEmpty(locationCode)) {
游杰 authored
173
174
            return AjaxResult.error("分配库位时,没有找到库位");
        }
肖超群 authored
175
        return workTaskService.createManyEmptyIn(containerCode, locationCode, warehouseCode, 0);
游杰 authored
176
177
    }
游杰 authored
178
179

    private AjaxResult innerManyEmptyOut(ManyEmptyDomain manyEmptyDomain) {
180
        if(manyEmptyDomain == null) {
游杰 authored
181
182
            throw new ServiceException("空托盘组参数不对!");
        }
游杰 authored
183
        String warehouseCode = manyEmptyDomain.getWarehouseCode();
184
        String area = manyEmptyDomain.getArea();
游杰 authored
185
        String port = manyEmptyDomain.getPort();
186
187
188
189
190
191
192
193
194
195
196
197
198
199
        LambdaQueryWrapper<Container> containerLambdaQueryWrapper = Wrappers.lambdaQuery();
        containerLambdaQueryWrapper.eq(Container::getStatus, QuantityConstant.STATUS_CONTAINER_MANY)
                .eq(Container::getWarehouseCode, warehouseCode);
        List<Container> containerList = containerService.list(containerLambdaQueryWrapper);
        List<Container> removeContainerList = new ArrayList<>();
        if(containerList != null && containerList.size() > 0) {
            for(Container container : containerList) {
                String locationCode = container.getLocationCode();
                Location location = locationService.getLocationByCode(locationCode, warehouseCode);
                if(!location.getArea().equals(area)) {
                    removeContainerList.add(container);
                }
            }
        }
肖超群 authored
200
201
202
        containerList.removeAll(removeContainerList);
        if(!(containerList != null && containerList.size() > 0)) {
游杰 authored
203
            return AjaxResult.error("没有找到合适的空托盘组!");
游杰 authored
204
        }
205
        String containerCode = containerList.get(0).getCode();
游杰 authored
206
        Container container = containerService.getContainerByCode(containerCode, warehouseCode);
肖超群 authored
207
        if(container == null) {
208
            return AjaxResult.error("没有找到托盘, 托盘号:" + containerCode);
游杰 authored
209
        }
210
        return workTaskService.createManyEmptyOut(containerCode, warehouseCode, port);
游杰 authored
211
    }
游杰 authored
212
213
214
215
216
217
218
219
220
221

    /**
     * 生成空托出库任务
     * @return
     */
    @PostMapping("/wcsCallEmptyOut")
    @Log(title = "任务-任务管理", operating = "生成空托出库任务", action = BusinessType.INSERT)
    @ResponseBody
    @ApiLogger(apiName = "生成空托出库任务", from="WCS")
    public AjaxResult wcsCallEmptyOut(@RequestBody ManyEmptyDomain manyEmptyDomain) {
222
        AjaxResult ajaxResult = handleMultiProcess("wcsCallEmptyOut",new MultiProcessListener() {
游杰 authored
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
            @Override
            public AjaxResult doProcess() {
                AjaxResult ajaxResult = innerWcsCallEmptyOut(manyEmptyDomain);
                return ajaxResult;
            }
        });
        return ajaxResult;
    }

    private AjaxResult innerWcsCallEmptyOut(ManyEmptyDomain manyEmptyDomain) {
        String warehouseCode = manyEmptyDomain.getWarehouseCode();
        String area = manyEmptyDomain.getArea();
        String port = manyEmptyDomain.getPort();
        if(warehouseCode == null) {
            return AjaxResult.error("warehouseCode 不能为空");
        }
        if(area == null) {
            return AjaxResult.error("area 不能为空");
        }
        if(port == null) {
            return AjaxResult.error("port 不能为空");
        }
        LambdaQueryWrapper<Zone> zoneLambdaQueryWrapper = Wrappers.lambdaQuery();
        zoneLambdaQueryWrapper.eq(Zone::getWarehouseCode, warehouseCode)
                .eq(Zone::getArea, area);
        Zone zone = zoneService.getOne(zoneLambdaQueryWrapper);
        if(zone == null) {
            return AjaxResult.error("area不正确,没有找到对应区域");
        }
        String zoneCode = zone.getCode();
        List<Location> list = containerService.getEmptyContainerInLocation(zoneCode,
                "","", warehouseCode);
        if(list == null || list.size() <= 0) {
            return AjaxResult.error("没有找到空托盘");
        }
        Location location = list.get(0);
        String containerCode = location.getContainerCode();
        String locationCode = location.getCode();
        return inventoryHeaderService.createEmptyOut(containerCode, locationCode, port, warehouseCode);
    }
游杰 authored
263
}