Blame view

src/main/java/com/huaheng/api/wcs/service/warecellAllocation/LocationAllocationServiceImpl.java 10.8 KB
游杰 authored
1
2
3
package com.huaheng.api.wcs.service.warecellAllocation;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
周鸿 authored
4
import com.huaheng.common.utils.Wrappers;
游杰 authored
5
import com.huaheng.common.constant.Constants;
游杰 authored
6
import com.huaheng.common.constant.QuantityConstant;
游杰 authored
7
8
import com.huaheng.common.exception.service.ServiceException;
import com.huaheng.common.utils.StringUtils;
9
import com.huaheng.framework.web.service.ConfigService;
游杰 authored
10
11
12
13
import com.huaheng.pc.config.container.domain.Container;
import com.huaheng.pc.config.container.service.ContainerService;
import com.huaheng.pc.config.containerType.domain.ContainerType;
import com.huaheng.pc.config.containerType.service.ContainerTypeService;
游杰 authored
14
15
16
import com.huaheng.pc.config.location.domain.Location;
import com.huaheng.pc.config.location.service.LocationService;
import com.huaheng.pc.config.locationType.domain.LocationType;
游杰 authored
17
import com.huaheng.pc.config.locationType.service.LocationTypeService;
游杰 authored
18
19
import com.huaheng.pc.config.zone.domain.Zone;
import com.huaheng.pc.config.zone.service.ZoneService;
游杰 authored
20
21
22
23
24
25
26
27
import com.huaheng.pc.task.taskHeader.service.TaskHeaderService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
游杰 authored
28
29
import static java.util.stream.Collectors.toList;
游杰 authored
30
31
32
33
34
35
@Service
public class LocationAllocationServiceImpl implements LocationAllocationService {

    @Resource
    private LocationService locationService;
    @Resource
游杰 authored
36
37
38
39
40
41
    private LocationTypeService locationTypeService;
    @Resource
    private ContainerService containerService;
    @Resource
    private ContainerTypeService containerTypeService;
    @Resource
游杰 authored
42
    private TaskHeaderService taskHeaderService;
游杰 authored
43
44
    @Resource
    private ZoneService zoneService;
45
46
    @Resource
    private ConfigService configService;
游杰 authored
47
48

    @Override
49
    public String allocation(int locationRule, List<String> locationTypeCodeList,
50
51
52
             int high, String area, List<String> raodWays, String warehouseCode,
             String containerCode, String materialAreaCode) {
        LambdaQueryWrapper<Container> containerLambdaQueryWrapper = Wrappers.lambdaQuery();
游杰 authored
53
54
55
        containerLambdaQueryWrapper.eq(Container::getCode, containerCode)
                .eq(Container::getWarehouseCode, warehouseCode);
        Container container = containerService.getOne(containerLambdaQueryWrapper);
56
游杰 authored
57
58
59
60
61
        LambdaQueryWrapper<ContainerType> containerTypeLambdaQueryWrapper = Wrappers.lambdaQuery();
        containerTypeLambdaQueryWrapper.eq(ContainerType::getCode, container.getContainerType())
                .eq(ContainerType::getWarehouseCode, warehouseCode);
        ContainerType containerType = containerTypeService.getOne(containerTypeLambdaQueryWrapper);
        List<LocationType> locationTypeList = new ArrayList<>();
游杰 authored
62
63
64
65
66
67
68
69
        if(containerType != null) {
            String locationType = containerType.getLocationType();
            String[] list = locationType.split(",");
            for (String str : list) {
                LambdaQueryWrapper<LocationType> locationTypeLambdaQueryWrapper = Wrappers.lambdaQuery();
                locationTypeLambdaQueryWrapper.eq(LocationType::getWarehouseCode, warehouseCode)
                        .eq(LocationType::getCode, str);
                LocationType locationType1 = locationTypeService.getOne(locationTypeLambdaQueryWrapper);
70
71
72
                if(locationType1!=null){
                    locationTypeList.add(locationType1);
                }
游杰 authored
73
74
75
76
77
78
79
80
81
82
83
84
            }
        } else {
            LambdaQueryWrapper<Zone> zoneLambdaQueryWrapper = Wrappers.lambdaQuery();
            zoneLambdaQueryWrapper.eq(Zone::getWarehouseCode, warehouseCode)
                                    .eq(Zone::getArea, area);
            Zone zone = zoneService.getOne(zoneLambdaQueryWrapper);
            if(zone != null) {
                LambdaQueryWrapper<LocationType> locationTypeLambdaQueryWrapper = Wrappers.lambdaQuery();
                locationTypeLambdaQueryWrapper.eq(LocationType::getWarehouseCode, warehouseCode)
                        .eq(LocationType::getZoneCode, zone.getCode());
                locationTypeList = locationTypeService.list(locationTypeLambdaQueryWrapper);
            }
游杰 authored
85
        }
游杰 authored
86
游杰 authored
87
88
89
        List<String> locationTypeCodes = locationTypeList.stream().
                map(t -> t.getCode()).collect(toList());
        List<String> mergelocationTypeCodeList = locationTypeCodeList.stream().filter(item -> locationTypeCodes.contains(item)).collect(toList());
游杰 authored
90
        switch (locationRule) {
游杰 authored
91
            case QuantityConstant.DOUBLE_FORK:
92
93
94
95
 				return doubleRk(area, raodWays, high, warehouseCode, mergelocationTypeCodeList, materialAreaCode);
            case QuantityConstant.SINGLE_FORK:
               return singleRk(area, raodWays, high, warehouseCode, mergelocationTypeCodeList, materialAreaCode);
        }
游杰 authored
96
97
98
        return null;
    }
99
    /**
游杰 authored
100
101
     * 双伸位库位入库分配库位
     */
102
103
    private String doubleRk(String area, List<String> roadWays, int high, String warehouseCode,
                            List<String> locationTypeCodeList, String materialAreaCode) {
104
105
106
107
108
109
        if(roadWays == null) {
            LambdaQueryWrapper<Location> locationLambdaQueryWrapper = Wrappers.lambdaQuery();
            locationLambdaQueryWrapper.eq(Location::getArea, area);
            List<Location> locationList = locationService.list(locationLambdaQueryWrapper);
            roadWays = locationList.stream().map(Location::getRoadway).distinct().collect(toList());
        }
110
        String value = configService.getKey(QuantityConstant.DOUBLE_FORK_RESERVE_LOCATION,warehouseCode);
111
112
113
114
115
116
117
118
        int reserveNumber = Integer.parseInt(value);
        List<String> removeRoadWays = new ArrayList<>();
        for(String roadWay : roadWays) {
            LambdaQueryWrapper<Location> locationLambdaQueryWrapper = Wrappers.lambdaQuery();
            locationLambdaQueryWrapper.eq(Location::getArea, area).
                    eq(Location::getWarehouseCode, warehouseCode)
                    .eq(StringUtils.isNotEmpty(roadWay), Location::getRoadway, roadWay)
                    .eq(Location::getStatus, QuantityConstant.STATUS_LOCATION_EMPTY)
xumiao authored
119
120
121
                    .ge(Location::getHigh, high)
//                    .eq(StringUtils.isNotEmpty(materialAreaCode), Location::getMaterialAreaCode, materialAreaCode)
                    .in(!warehouseCode.equalsIgnoreCase("KS0001"),Location::getLocationType, locationTypeCodeList)
122
123
124
125
126
                    .eq(Location::getContainerCode, "");
            List<Location> totalLocationList = locationService.list(locationLambdaQueryWrapper);
            if (totalLocationList.size() <= reserveNumber) {
                removeRoadWays.add(roadWay);
            }
游杰 authored
127
        }
128
        roadWays.removeAll(removeRoadWays);
游杰 authored
129
130
        LambdaQueryWrapper<Location> locationLambda = Wrappers.lambdaQuery();
131
        locationLambda.eq(Location::getArea, area).
游杰 authored
132
                eq(Location::getWarehouseCode, warehouseCode)
133
134
 				.in(StringUtils.isNotEmpty(roadWays), Location::getRoadway, roadWays)
                .eq(Location::getStatus, QuantityConstant.STATUS_LOCATION_EMPTY)
xumiao authored
135
136
                .ge(Location::getHigh, high)
//                .eq(StringUtils.isNotEmpty(materialAreaCode), Location::getMaterialAreaCode, materialAreaCode)
游杰 authored
137
                .eq(Location::getRowFlag, QuantityConstant.ROW_OUT)
xumiao authored
138
                .in(!warehouseCode.equalsIgnoreCase("KS0001"),Location::getLocationType, locationTypeCodeList)
游杰 authored
139
140
141
                .eq(Location::getContainerCode, "");
        List<Location> locationList = locationService.list(locationLambda);
        List<Location> removeLocaationList = new ArrayList<>();
游杰 authored
142
143
        if(locationList != null && locationList.size() > 0) {
            for (Location location1 : locationList) {
144
                //查出未完成
游杰 authored
145
146
147
                if (taskHeaderService.getUncompleteTaskInNear(location1) > 0) {
                    removeLocaationList.add(location1);
                }
xumiao authored
148
149
150
151
                Location insideNear = locationService.getInsideNear(location1);
                if(insideNear != null&&StringUtils.isNotEmpty(insideNear.getContainerCode())){
                    removeLocaationList.add(location1);
                }
游杰 authored
152
153
            }
        }
游杰 authored
154
        locationList.removeAll(removeLocaationList);
155
156
157
游杰 authored
158
159
        if (locationList == null || locationList.size() == 0) {
            locationLambda = Wrappers.lambdaQuery();
160
            locationLambda.eq(Location::getArea, area).
游杰 authored
161
                    eq(Location::getWarehouseCode, warehouseCode)
162
163
					.in(StringUtils.isNotEmpty(roadWays), Location::getRoadway, roadWays)
                    .eq(Location::getStatus, QuantityConstant.STATUS_LOCATION_EMPTY)
xumiao authored
164
165
                    .ge(Location::getHigh, high)
//                    .eq(StringUtils.isNotEmpty(materialAreaCode), Location::getMaterialAreaCode, materialAreaCode)
游杰 authored
166
                    .eq(Location::getRowFlag, QuantityConstant.ROW_IN)
xumiao authored
167
                    .in(!warehouseCode.equalsIgnoreCase("KS0001"),Location::getLocationType, locationTypeCodeList)
游杰 authored
168
169
170
                    .eq(Location::getContainerCode, "");
            locationList = locationService.list(locationLambda);
            removeLocaationList = new ArrayList<>();
171
172
173
174
175
            if(locationList != null && locationList.size() > 0) {
                for (Location location1 : locationList) {
                    if (taskHeaderService.getUncompleteTaskInNear(location1) > 0) {
                        removeLocaationList.add(location1);
                    }
游杰 authored
176
177
178
179
                }
            }
            locationList.removeAll(removeLocaationList);
        }
180
181
182
        if (locationList == null || locationList.size() == 0) {
            return null;
        }
183
184
        Location location = locationList.stream().findFirst().orElse(null);
        String locationCode = location.getCode();
游杰 authored
185
186
187
        return locationCode;
    }
188
    /**
游杰 authored
189
190
     * 单伸位库位入库分配库位
     */
191
192
193
    private String singleRk(String area, List<String> roadWays, int high, String warehouseCode,
                            List<String> locationTypeCodeList, String materialAreaCode) {
        LambdaQueryWrapper<Location> locationLambda = Wrappers.lambdaQuery();
194
        locationLambda.eq(Location::getArea, area).
195
196
197
198
199
200
201
        eq(Location::getWarehouseCode, warehouseCode)
        .in(StringUtils.isNotEmpty(roadWays), Location::getRoadway, roadWays)
        .eq(Location::getStatus, QuantityConstant.STATUS_LOCATION_EMPTY)
        .eq(Location::getHigh, high)
        .eq(StringUtils.isNotEmpty(materialAreaCode), Location::getMaterialAreaCode, materialAreaCode)
        .in(Location::getLocationType, locationTypeCodeList)
        .eq(Location::getContainerCode, "");
游杰 authored
202
        List<Location> locationList = locationService.list(locationLambda);
203
204
205
        if (locationList == null || locationList.size() == 0) {
            return null;
        }
游杰 authored
206
207
        Location location = locationList.stream().findFirst().orElse(null);
        String locationCode = location.getCode();
游杰 authored
208
209
210
211
        return locationCode;
    }

}