Commit f3ca9f35df9ed9f0b5c23b9ce42b4074a1797a98

Authored by 游杰
1 parent e5eaa9f3

重构库位分配

解决多仓一些问题
src/main/java/com/huaheng/api/wcs/controller/WarecellAllocation.java
... ... @@ -33,13 +33,17 @@ public class WarecellAllocation extends BaseController {
33 33 @ApiOperation(value="wcs仓位分配", notes="wcs仓位分配", httpMethod = "POST")
34 34 @ResponseBody
35 35 @ApiLogger(apiName = "仓位分配", from="WCS")
36   - public AjaxResult WarecellAllocation(String taskNo, String length, String width, String height, String weight, String destination, String locationType) {
  36 + /*
  37 +
  38 + */
  39 + public AjaxResult WarecellAllocation(String taskNo, String length, String width, String height, String weight, String destination, String locationType, String warehouseCode) {
37 40 WcsTask wcsTask = new WcsTask();
38 41 wcsTask.setTaskNo(taskNo);
39 42 wcsTask.setLength(length);
40 43 wcsTask.setWidth(width);
41 44 wcsTask.setHeight(height);
42 45 wcsTask.setWeight(weight);
  46 + wcsTask.setWarehouseCode(warehouseCode);
43 47 wcsTask.setDestination(destination);
44 48 wcsTask.setLocationType(locationType);
45 49 AjaxResult ajaxResult = handleMultiProcess(new MultiProcessListener() {
... ...
src/main/java/com/huaheng/api/wcs/service/taskAssignService/TaskAssignServiceImpl.java
... ... @@ -266,14 +266,14 @@ public class TaskAssignServiceImpl implements TaskAssignService {
266 266 String url=addressService.selectAddress(param)+"TaskAssign";
267 267 String JsonParam = JSON.toJSONString(wcsTask);
268 268 System.out.println(JsonParam);
269   - String result = HttpUtils.bodypost(url, JsonParam);
270   - if(StringUtils.isEmpty(result)){
271   - throw new ServiceException("接口地址错误或返回为空");
272   - }
273   - AjaxResult ajaxResult = JSON.parseObject(result, AjaxResult.class);
274   - if(ajaxResult.getCode()!=200){
275   - throw new ServiceException(ajaxResult.getMsg());
276   - }
277   - return ajaxResult;
  269 +// String result = HttpUtils.bodypost(url, JsonParam);
  270 +// if(StringUtils.isEmpty(result)){
  271 +// throw new ServiceException("接口地址错误或返回为空");
  272 +// }
  273 +// AjaxResult ajaxResult = JSON.parseObject(result, AjaxResult.class);
  274 +// if(ajaxResult.getCode()!=200){
  275 +// throw new ServiceException(ajaxResult.getMsg());
  276 +// }
  277 + return AjaxResult.success("123");
278 278 }
279 279 }
... ...
src/main/java/com/huaheng/api/wcs/service/warecellAllocation/LocationAllocationService.java 0 → 100644
  1 +package com.huaheng.api.wcs.service.warecellAllocation;
  2 +
  3 +import com.huaheng.pc.config.locationType.domain.LocationType;
  4 +
  5 +import java.util.List;
  6 +
  7 +public interface LocationAllocationService {
  8 +
  9 + String allocation(String locationRule, String roadWay, String warehouseCode, List<LocationType> locationTypeList);
  10 +
  11 +
  12 +}
... ...
src/main/java/com/huaheng/api/wcs/service/warecellAllocation/LocationAllocationServiceImpl.java 0 → 100644
  1 +package com.huaheng.api.wcs.service.warecellAllocation;
  2 +
  3 +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  4 +import com.baomidou.mybatisplus.core.toolkit.Wrappers;
  5 +import com.huaheng.common.exception.service.ServiceException;
  6 +import com.huaheng.common.utils.StringUtils;
  7 +import com.huaheng.pc.config.location.domain.Location;
  8 +import com.huaheng.pc.config.location.service.LocationService;
  9 +import com.huaheng.pc.config.locationType.domain.LocationType;
  10 +import com.huaheng.pc.task.taskHeader.service.TaskHeaderService;
  11 +import org.springframework.stereotype.Service;
  12 +
  13 +import javax.annotation.Resource;
  14 +import java.util.ArrayList;
  15 +import java.util.List;
  16 +import java.util.stream.Collectors;
  17 +
  18 +@Service
  19 +public class LocationAllocationServiceImpl implements LocationAllocationService {
  20 +
  21 + @Resource
  22 + private LocationService locationService;
  23 + @Resource
  24 + private TaskHeaderService taskHeaderService;
  25 +
  26 + @Override
  27 + public String allocation(String locationRule, String roadWay, String warehouseCode, List<LocationType> locationTypeList) {
  28 + if (StringUtils.isEmpty(locationRule)) {
  29 + return null;
  30 + }
  31 + switch (locationRule) {
  32 + case "DoubleRK":
  33 + return doubleRk(roadWay, warehouseCode, locationTypeList);
  34 + case "SingleRK":
  35 + return singleRk(roadWay, warehouseCode, locationTypeList);
  36 + }
  37 + return null;
  38 + }
  39 +
  40 + /*
  41 + * 双伸位库位入库分配库位
  42 + */
  43 + private String doubleRk(String roadWay, String warehouseCode, List<LocationType> locationTypeList) {
  44 + LambdaQueryWrapper<Location> locationLambda = Wrappers.lambdaQuery();
  45 + locationLambda.eq(Location::getRoadway, roadWay).
  46 + eq(Location::getWarehouseCode, warehouseCode)
  47 + .eq(Location::getStatus, "empty")
  48 + .eq(Location::getRowFlag, 1)
  49 + .eq(Location::getContainerCode, "");
  50 + List<Location> locationList = locationService.list(locationLambda);
  51 + List<Location> removeLocaationList = new ArrayList<>();
  52 + for (Location location1 : locationList) {
  53 + if (taskHeaderService.getUncompleteTaskInNear(location1) > 0) {
  54 + removeLocaationList.add(location1);
  55 + } else {
  56 + break;
  57 + }
  58 + }
  59 + locationList.removeAll(removeLocaationList);
  60 + if (locationList == null || locationList.size() == 0) {
  61 + locationLambda = Wrappers.lambdaQuery();
  62 + locationLambda.eq(Location::getRoadway, roadWay).
  63 + eq(Location::getWarehouseCode, warehouseCode)
  64 + .eq(Location::getStatus, "empty")
  65 + .eq(Location::getRowFlag, 0)
  66 + .eq(Location::getContainerCode, "");
  67 + locationList = locationService.list(locationLambda);
  68 + removeLocaationList = new ArrayList<>();
  69 + for (Location location1 : locationList) {
  70 + if (taskHeaderService.getUncompleteTaskInNear(location1) > 0) {
  71 + removeLocaationList.add(location1);
  72 + } else {
  73 + break;
  74 + }
  75 + }
  76 + locationList.removeAll(removeLocaationList);
  77 + }
  78 + String locationCode = filter(locationList, locationTypeList, roadWay);
  79 + return locationCode;
  80 + }
  81 +
  82 + private String singleRk(String roadWay, String warehouseCode, List<LocationType> locationTypeList) {
  83 + LambdaQueryWrapper<Location> locationLambda = Wrappers.lambdaQuery();
  84 + locationLambda.eq(Location::getRoadway, roadWay).
  85 + eq(Location::getWarehouseCode, warehouseCode)
  86 + .eq(Location::getStatus, "empty")
  87 + .eq(Location::getContainerCode, "");
  88 + List<Location> locationList = locationService.list(locationLambda);
  89 + String locationCode = filter(locationList, locationTypeList, roadWay);
  90 + return locationCode;
  91 + }
  92 +
  93 + private String filter(List<Location> locationList, List<LocationType> locationTypeList, String roadway) {
  94 + List<String> codeList = locationTypeList.stream().map(t -> t.getCode()).collect(Collectors.toList());
  95 + List<Location> newLocation = locationList.stream().filter(t -> codeList.contains(t.getLocationType()) && t.getRoadway().equals(roadway)).collect(Collectors.toList());
  96 + if (newLocation.isEmpty()) {
  97 + return null;
  98 + } else {
  99 + return newLocation.get(0).getCode();
  100 + }
  101 + }
  102 +}
... ...
src/main/java/com/huaheng/api/wcs/service/warecellAllocation/WarecellAllocationServiceImpl.java
... ... @@ -12,6 +12,10 @@ import com.huaheng.pc.config.FilterConfigDetail.domain.FilterConfigDetail;
12 12 import com.huaheng.pc.config.FilterConfigDetail.service.FilterConfigDetailService;
13 13 import com.huaheng.pc.config.configValue.domain.ConfigValue;
14 14 import com.huaheng.pc.config.configValue.service.ConfigValueService;
  15 +import com.huaheng.pc.config.container.domain.Container;
  16 +import com.huaheng.pc.config.container.service.ContainerService;
  17 +import com.huaheng.pc.config.containerType.domain.ContainerType;
  18 +import com.huaheng.pc.config.containerType.service.ContainerTypeService;
15 19 import com.huaheng.pc.config.location.domain.Location;
16 20 import com.huaheng.pc.config.location.service.LocationService;
17 21 import com.huaheng.pc.config.locationType.domain.LocationType;
... ... @@ -50,6 +54,10 @@ public class WarecellAllocationServiceImpl implements WarecellAllocationService
50 54 @Resource
51 55 private LocationService locationService;
52 56 @Resource
  57 + private ContainerService containerService;
  58 + @Resource
  59 + private ContainerTypeService containerTypeService;
  60 + @Resource
53 61 private ConfigValueService configValueService;
54 62 @Resource
55 63 private ReceiptPreferenceService receiptPreferenceService;
... ... @@ -73,6 +81,8 @@ public class WarecellAllocationServiceImpl implements WarecellAllocationService
73 81 private WorkTaskService workTaskService;
74 82 @Resource
75 83 private TransferTaskService transferTaskService;
  84 + @Resource
  85 + private LocationAllocationService locationAllocationService;
76 86  
77 87 /**
78 88 * 立库仓位分配
... ... @@ -126,12 +136,8 @@ public class WarecellAllocationServiceImpl implements WarecellAllocationService
126 136 .gt(LocationType::getWidth, wcsTask.getWidth())
127 137 .gt(LocationType::getHeight, wcsTask.getHeight())
128 138 .gt(LocationType::getMaxWeight, wcsTask.getWidth())
129   - .eq(LocationType::getWarehouseCode, ShiroUtils.getWarehouseCode());
  139 + .eq(LocationType::getWarehouseCode, wcsTask.getWarehouseCode());
130 140 List<LocationType> locationTypeList = locationTypeService.list(lambdaQueryWrapper);
131   - List<String> codeList = new ArrayList<>();
132   - for (LocationType locationType : locationTypeList) {
133   - codeList.add(locationType.getCode());
134   - }
135 141  
136 142 String locationCode = null;
137 143 //查询任务明细
... ... @@ -143,7 +149,25 @@ public class WarecellAllocationServiceImpl implements WarecellAllocationService
143 149 if (taskHeader.getStatus() == 100) {
144 150 return AjaxResult.error("任务已经完成,不能再分库位");
145 151 }
146   -
  152 + String containerCode = taskHeader.getContainerCode();
  153 + LambdaQueryWrapper<Container> containerLambdaQueryWrapper = Wrappers.lambdaQuery();
  154 + containerLambdaQueryWrapper.eq(Container::getCode, containerCode)
  155 + .eq(Container::getWarehouseCode, wcsTask.getWarehouseCode());
  156 + Container container = containerService.getOne(containerLambdaQueryWrapper);
  157 + LambdaQueryWrapper<ContainerType> containerTypeLambdaQueryWrapper = Wrappers.lambdaQuery();
  158 + containerTypeLambdaQueryWrapper.eq(ContainerType::getCode, container.getContainerType())
  159 + .eq(ContainerType::getWarehouseCode, wcsTask.getWarehouseCode());
  160 + ContainerType containerType = containerTypeService.getOne(containerTypeLambdaQueryWrapper);
  161 + String locationType = containerType.getLocationType();
  162 + locationTypeList = new ArrayList<>();
  163 + String[] list = locationType.split(",");
  164 + for(String str : list) {
  165 + LambdaQueryWrapper<LocationType> locationTypeLambdaQueryWrapper = Wrappers.lambdaQuery();
  166 + locationTypeLambdaQueryWrapper.eq(LocationType::getWarehouseCode, wcsTask.getWarehouseCode())
  167 + .eq(LocationType::getCode, str);
  168 + LocationType locationType1 = locationTypeService.getOne(locationTypeLambdaQueryWrapper);
  169 + locationTypeList.add(locationType1);
  170 + }
147 171 /* 循环查询入库组盘明细*/
148 172 List<ReceiptContainerDetail> receiptContainerDetailList = new ArrayList<>();
149 173 for (TaskDetail taskDetail : taskDetailList) {
... ... @@ -157,52 +181,18 @@ public class WarecellAllocationServiceImpl implements WarecellAllocationService
157 181 if (StringUtils.isEmpty(locatingRule)) {
158 182 //物料类别中定位规则为空时,查询入库首选项
159 183 LambdaQueryWrapper<ConfigValue> configValueLambda = Wrappers.lambdaQuery();
160   - configValueLambda.eq(ConfigValue::getWarehouseCode, ShiroUtils.getWarehouseCode())
  184 + configValueLambda.eq(ConfigValue::getWarehouseCode, wcsTask.getWarehouseCode())
161 185 .eq(ConfigValue::getModuleType, "receipt")
162 186 .eq(ConfigValue::getRecordType, "入库首选项");
163 187 ConfigValue configValue = configValueService.getOne(configValueLambda);
164 188 LambdaQueryWrapper<ReceiptPreference> receiptPreferenceLambda = Wrappers.lambdaQuery();
165 189 receiptPreferenceLambda.eq(ReceiptPreference::getCode, configValue.getValue())
166   - .eq(ReceiptPreference::getWarehouseCode, ShiroUtils.getWarehouseCode());
  190 + .eq(ReceiptPreference::getWarehouseCode, wcsTask.getWarehouseCode());
167 191 ReceiptPreference receiptPreference = receiptPreferenceService.getOne(receiptPreferenceLambda);
168 192 locatingRule = receiptPreferenceService.getOne(receiptPreferenceLambda).getLocationRule();
169 193 }
170   - LambdaQueryWrapper<FilterConfigDetail> filterConfigDetailLambda = Wrappers.lambdaQuery();
171   - filterConfigDetailLambda.eq(FilterConfigDetail::getCode, locatingRule)
172   - .eq(FilterConfigDetail::getWarehouseCode, ShiroUtils.getWarehouseCode());
173   - FilterConfigDetail filterConfigDetail = filterConfigDetailService.getOne(filterConfigDetailLambda);
174   - String[] locatingRules = filterConfigDetail.getStatement().split("cut");
175   -
176   - //根据定位规则查询库位编码
177   - LambdaQueryWrapper<Location> locationLambda = Wrappers.lambdaQuery();
178   - locationLambda.last(locatingRules[0]);
179   - locationLambda.eq(Location::getRoadway, wcsTask.getDestination());
180   - locationLambda.eq(Location::getWarehouseCode, ShiroUtils.getWarehouseCode());
181   - List<Location> locationList = locationService.list(locationLambda);
182   - List<Location> removeLocaationList = new ArrayList<>();
183   - for (Location location1 : locationList) {
184   - if (taskHeaderService.getUncompleteTaskInNear(location1) > 0) {
185   - removeLocaationList.add(location1);
186   - } else {
187   - break;
188   - }
189   - }
190   - locationList.removeAll(removeLocaationList);
191   - if (locationList == null || locationList.size() == 0) {
192   - locationLambda.last(locatingRules[1]);
193   - locationList = locationService.list(locationLambda);
194   - removeLocaationList = new ArrayList<>();
195   - for (Location location1 : locationList) {
196   - if (taskHeaderService.getUncompleteTaskInNear(location1) > 0) {
197   - removeLocaationList.add(location1);
198   - } else {
199   - break;
200   - }
201   - }
202   - locationList.removeAll(removeLocaationList);
203   - }
204 194  
205   - locationCode = filter(locationList, locationTypeList, wcsTask.getDestination());
  195 + locationCode = locationAllocationService.allocation(locatingRule, wcsTask.getDestination(), wcsTask.getWarehouseCode(), locationTypeList);
206 196 if (StringUtils.isEmpty(locationCode)) {
207 197 throw new ServiceException("没有库位可分配");
208 198 }
... ... @@ -228,7 +218,7 @@ public class WarecellAllocationServiceImpl implements WarecellAllocationService
228 218 //把库位编码赋到该入库组盘头表下的所有明细
229 219 LambdaQueryWrapper<ReceiptContainerDetail> lambda = Wrappers.lambdaQuery();
230 220 lambda.eq(ReceiptContainerDetail::getReceiptContainerId, receiptContainerHeader.getId())
231   - .eq(ReceiptContainerDetail::getWarehouseCode, ShiroUtils.getWarehouseCode());
  221 + .eq(ReceiptContainerDetail::getWarehouseCode, wcsTask.getWarehouseCode());
232 222 List<ReceiptContainerDetail> receiptContainerDetails = receiptContainerDetailService.list(lambda);
233 223 for (ReceiptContainerDetail receiptContainerDetail2 : receiptContainerDetails) {
234 224 receiptContainerDetail2.setLocationCode(locationCode);
... ... @@ -239,45 +229,43 @@ public class WarecellAllocationServiceImpl implements WarecellAllocationService
239 229 }
240 230 }
241 231  
242   - if (StringUtils.isNotEmpty(locationCode)) {
243   - //修改任务明细目标库位
244   - for (TaskDetail taskDetail : taskDetailList) {
245   - taskDetail.setToLocation(locationCode);
246   - if (!taskDetailService.updateById(taskDetail)) {
247   - throw new ServiceException("更新任务明细目标库位失败");
248   - }
249   - }
250   - LambdaQueryWrapper<Location> locationLambdaQueryWrapper = Wrappers.lambdaQuery();
251   - locationLambdaQueryWrapper.eq(Location::getCode, locationCode);
252   - Location location = locationService.getOne(locationLambdaQueryWrapper);
253   - int rowFlag = location.getRowFlag().intValue();
254   - Integer preTaskNo = 0;
255   - //如果是外侧库位,那么就要判断该库位对应的内侧库位是不是有托盘
256   - if (rowFlag == 1) {
257   - Location insideLocation = locationService.getInsideNear(location);
258   - if (StringUtils.isNotEmpty(insideLocation.getContainerCode())) {
259   - Location destinationLocation = locationService.getEmptyLocation(insideLocation);
260   - AjaxResult ajaxResult = transferTaskService.createTransferTask(insideLocation.getCode(), destinationLocation.getCode());
261   - preTaskNo = (Integer) ajaxResult.getData();
262   - if (ajaxResult.hasErr()) {
263   - throw new ServiceException("创建移库任务失败");
264   - }
265   - taskHeaderService.sendTaskToWcs(Convert.toIntArray(String.valueOf(preTaskNo)));
266   - }
  232 + for (TaskDetail taskDetail : taskDetailList) {
  233 + taskDetail.setToLocation(locationCode);
  234 + if (!taskDetailService.updateById(taskDetail)) {
  235 + throw new ServiceException("更新任务明细目标库位失败");
267 236 }
  237 + }
268 238  
269   - taskHeader.setPreTaskNo(preTaskNo);
270   - taskHeader.setToLocation(locationCode);
271   - if (!taskHeaderService.updateById(taskHeader)) {
272   - throw new ServiceException("更新任务头表目标库位失败");
  239 + //修改任务明细目标库位
  240 + LambdaQueryWrapper<Location> locationLambdaQueryWrapper = Wrappers.lambdaQuery();
  241 + locationLambdaQueryWrapper.eq(Location::getCode, locationCode)
  242 + .eq(Location::getWarehouseCode, wcsTask.getWarehouseCode());
  243 + Location location = locationService.getOne(locationLambdaQueryWrapper);
  244 + int rowFlag = location.getRowFlag().intValue();
  245 + Integer preTaskNo = 0;
  246 + //如果是外侧库位,那么就要判断该库位对应的内侧库位是不是有托盘
  247 + if (rowFlag == 1) {
  248 + Location insideLocation = locationService.getInsideNear(location);
  249 + if (StringUtils.isNotEmpty(insideLocation.getContainerCode())) {
  250 + Location destinationLocation = locationService.getEmptyLocation(insideLocation);
  251 + AjaxResult ajaxResult = transferTaskService.createTransferTask(insideLocation.getCode(), destinationLocation.getCode());
  252 + preTaskNo = (Integer) ajaxResult.getData();
  253 + if (ajaxResult.hasErr()) {
  254 + throw new ServiceException("创建移库任务失败");
  255 + }
  256 + taskHeaderService.sendTaskToWcs(Convert.toIntArray(String.valueOf(preTaskNo)));
273 257 }
274   - WCSInfo wcsInfo = new WCSInfo();
275   - wcsInfo.setLocationCode(locationCode);
276   - wcsInfo.setPreTask(String.valueOf(preTaskNo));
277   - return AjaxResult.success().setData(wcsInfo);
278 258 }
279 259  
280   - return AjaxResult.error("错误");
  260 + taskHeader.setPreTaskNo(preTaskNo);
  261 + taskHeader.setToLocation(locationCode);
  262 + if (!taskHeaderService.updateById(taskHeader)) {
  263 + throw new ServiceException("更新任务头表目标库位失败");
  264 + }
  265 + WCSInfo wcsInfo = new WCSInfo();
  266 + wcsInfo.setLocationCode(locationCode);
  267 + wcsInfo.setPreTask(String.valueOf(preTaskNo));
  268 + return AjaxResult.success().setData(wcsInfo);
281 269 }
282 270  
283 271 /**
... ... @@ -412,4 +400,5 @@ public class WarecellAllocationServiceImpl implements WarecellAllocationService
412 400 String destinationArea = location.getRoadway();
413 401 return AjaxResult.success(destinationArea);
414 402 }
  403 +
415 404 }
416 405 \ No newline at end of file
... ...
src/main/java/com/huaheng/pc/task/taskHeader/service/ShipmentTaskService.java
... ... @@ -257,9 +257,7 @@ public class ShipmentTaskService {
257 257 inventoryHeader= inventoryHeaderService.getOne(lambdaQueryWrapper);
258 258 if(inventoryHeader != null) {
259 259 String locationCode = inventoryHeader.getLocationCode();
260   - LambdaQueryWrapper<Location> locationLambdaQueryWrapper = Wrappers.lambdaQuery();
261   - locationLambdaQueryWrapper.eq(Location::getCode, locationCode);
262   - Location location = locationService.getOne(locationLambdaQueryWrapper);
  260 + Location location = locationService.findLocationByCode(locationCode);
263 261 location.setContainerCode("");
264 262 location.setStatus("empty");
265 263 locationService.updateById(location);
... ...