From f6706f579860e3608b014096e3df4ada0d3fb7f9 Mon Sep 17 00:00:00 2001 From: TanYibin <5491541@qq.com> Date: Tue, 13 Jun 2023 10:20:41 +0800 Subject: [PATCH] 托盘库位service方法优化 --- huaheng-wms-core/src/main/java/org/jeecg/modules/wms/config/container/service/impl/ContainerServiceImpl.java | 46 ++++++++++++++++++++++++++-------------------- huaheng-wms-core/src/main/java/org/jeecg/modules/wms/config/location/service/impl/LocationServiceImpl.java | 81 ++++++++++++++++++++++++++++++++++++++++++++++----------------------------------- 2 files changed, 72 insertions(+), 55 deletions(-) diff --git a/huaheng-wms-core/src/main/java/org/jeecg/modules/wms/config/container/service/impl/ContainerServiceImpl.java b/huaheng-wms-core/src/main/java/org/jeecg/modules/wms/config/container/service/impl/ContainerServiceImpl.java index 420ed48..14b72a4 100644 --- a/huaheng-wms-core/src/main/java/org/jeecg/modules/wms/config/container/service/impl/ContainerServiceImpl.java +++ b/huaheng-wms-core/src/main/java/org/jeecg/modules/wms/config/container/service/impl/ContainerServiceImpl.java @@ -6,6 +6,7 @@ import java.util.Calendar; import java.util.List; import javax.annotation.Resource; +import javax.transaction.Transactional; import org.jeecg.common.api.vo.Result; import org.jeecg.common.exception.JeecgBootException; @@ -15,6 +16,7 @@ import org.jeecg.modules.wms.config.container.service.IContainerService; import org.jeecg.modules.wms.config.containerType.service.IContainerTypeService; import org.jeecg.utils.StringUtils; import org.jeecg.utils.constant.QuantityConstant; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; @@ -33,10 +35,15 @@ public class ContainerServiceImpl extends ServiceImpl<ContainerMapper, Container @Resource IContainerTypeService containerTypeService; + @Resource ContainerMapper containerMapper; + @Autowired + IContainerService containerService; + @Override + @Transactional public Result<?> batchAddContainers(Container container, int number) { String containerTypeCode = container.getContainerTypeCode(); String warehouseCode = container.getWarehouseCode(); @@ -44,16 +51,16 @@ public class ContainerServiceImpl extends ServiceImpl<ContainerMapper, Container List<Container> containerList = new ArrayList<>(); for (int i = 0; i < number; i++) { startNumber++; - Container container1 = new Container(); - container1.setContainerTypeCode(containerTypeCode); + Container addcontainer = new Container(); + addcontainer.setContainerTypeCode(containerTypeCode); String code = String.format("%s%05d", containerTypeCode, startNumber); - container1.setCode(code); - container1.setStatus(QuantityConstant.STATUS_CONTAINER_EMPTY); - container1.setFillStatus(QuantityConstant.STATUS_CONTAINER_FILL_EMPTY); - container1.setWarehouseCode(warehouseCode); - containerList.add(container1); + addcontainer.setCode(code); + addcontainer.setStatus(QuantityConstant.STATUS_CONTAINER_EMPTY); + addcontainer.setFillStatus(QuantityConstant.STATUS_CONTAINER_FILL_EMPTY); + addcontainer.setWarehouseCode(warehouseCode); + containerList.add(addcontainer); } - boolean success = saveBatch(containerList); + boolean success = containerService.saveBatch(containerList); if (success) { return Result.OK("添加成功!"); } @@ -67,19 +74,21 @@ public class ContainerServiceImpl extends ServiceImpl<ContainerMapper, Container } LambdaQueryWrapper<Container> containerLambdaQueryWrapper = Wrappers.lambdaQuery(); containerLambdaQueryWrapper.eq(Container::getCode, containCode).eq(Container::getWarehouseCode, warehouseCode); - Container container = this.getOne(containerLambdaQueryWrapper); + Container container = containerService.getOne(containerLambdaQueryWrapper); return container; } @Override + @Transactional public boolean updateStatus(String containerCode, String status, String warehouseCode) { LambdaUpdateWrapper<Container> updateWrapper = Wrappers.lambdaUpdate(); updateWrapper.ne(Container::getStatus, status).eq(Container::getCode, containerCode).eq(Container::getWarehouseCode, warehouseCode).set(Container::getStatus, status); - return update(updateWrapper); + return containerService.update(updateWrapper); } @Override + @Transactional public boolean updateLocationCodeAndStatus(String containerCode, String locationCode, String status, String warehouseCode) { if (StringUtils.isNotEmpty(locationCode)) { LambdaQueryWrapper<Container> containerLambdaQueryWrapper = Wrappers.lambdaQuery(); @@ -93,15 +102,16 @@ public class ContainerServiceImpl extends ServiceImpl<ContainerMapper, Container LambdaUpdateWrapper<Container> updateWrapper = Wrappers.lambdaUpdate(); updateWrapper.ne(Container::getStatus, status).eq(Container::getCode, containerCode).eq(Container::getWarehouseCode, warehouseCode) .set(Container::getLocationCode, locationCode).set(Container::getStatus, status); - return update(updateWrapper); + return containerService.update(updateWrapper); } @Override + @Transactional public boolean updateLocationCodeAndStatus(String containerCode, String locationCode, String status, String fillStatus, String warehouseCode) { LambdaUpdateWrapper<Container> updateWrapper = Wrappers.lambdaUpdate(); updateWrapper.ne(Container::getStatus, status).eq(Container::getCode, containerCode).eq(Container::getWarehouseCode, warehouseCode) .set(Container::getLocationCode, locationCode).set(Container::getStatus, status).set(Container::getFillStatus, fillStatus); - return update(updateWrapper); + return containerService.update(updateWrapper); } @Override @@ -122,16 +132,14 @@ public class ContainerServiceImpl extends ServiceImpl<ContainerMapper, Container public List<Container> getContainerListByStatus(String status, String warehouseCode) { LambdaQueryWrapper<Container> containerLambdaQueryWrapper = Wrappers.lambdaQuery(); containerLambdaQueryWrapper.eq(Container::getStatus, status).eq(Container::getWarehouseCode, warehouseCode); - List<Container> containerList = list(containerLambdaQueryWrapper); - return containerList; + return list(containerLambdaQueryWrapper); } @Override public List<Container> getContainerListByCodeList(List<String> containerCodeList, String warehouseCode) { LambdaQueryWrapper<Container> containerLambdaQueryWrapper = Wrappers.lambdaQuery(); containerLambdaQueryWrapper.in(Container::getCode, containerCodeList).eq(Container::getWarehouseCode, warehouseCode); - List<Container> containerList = list(containerLambdaQueryWrapper); - return containerList; + return list(containerLambdaQueryWrapper); } private int getStartNumber(String containerTypeCode, String warehouseCode) { @@ -141,11 +149,9 @@ public class ContainerServiceImpl extends ServiceImpl<ContainerMapper, Container Container container = this.getOne(containerLambdaQueryWrapper); // 如果指定类型的最后的code存在,那么 code = 容器类型 + (排序号 + 1) if (container != null && container.getCode() != null) { - Integer number = Integer.valueOf(container.getCode().substring(container.getCode().length() - 5, container.getCode().length())); - return number; - } else { - return 0; + return Integer.valueOf(container.getCode().substring(container.getCode().length() - 5, container.getCode().length())); } + return 0; } } diff --git a/huaheng-wms-core/src/main/java/org/jeecg/modules/wms/config/location/service/impl/LocationServiceImpl.java b/huaheng-wms-core/src/main/java/org/jeecg/modules/wms/config/location/service/impl/LocationServiceImpl.java index dc2a9cf..59851a6 100644 --- a/huaheng-wms-core/src/main/java/org/jeecg/modules/wms/config/location/service/impl/LocationServiceImpl.java +++ b/huaheng-wms-core/src/main/java/org/jeecg/modules/wms/config/location/service/impl/LocationServiceImpl.java @@ -1,7 +1,14 @@ package org.jeecg.modules.wms.config.location.service.impl; import java.text.MessageFormat; -import java.util.*; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; import java.util.function.Function; import java.util.stream.Collectors; @@ -13,7 +20,15 @@ import org.jeecg.common.exception.JeecgBootException; import org.jeecg.modules.wms.config.address.service.IAddressService; import org.jeecg.modules.wms.config.container.entity.Container; import org.jeecg.modules.wms.config.container.service.IContainerService; -import org.jeecg.modules.wms.config.location.dto.*; +import org.jeecg.modules.wms.config.location.dto.CompareContainerTaskDto; +import org.jeecg.modules.wms.config.location.dto.CompareLocationDto; +import org.jeecg.modules.wms.config.location.dto.CompareLocationTaskDto; +import org.jeecg.modules.wms.config.location.dto.QueryCompareContainerTaskDto; +import org.jeecg.modules.wms.config.location.dto.QueryCompareLocationDto; +import org.jeecg.modules.wms.config.location.dto.QueryCompareLocationTaskDto; +import org.jeecg.modules.wms.config.location.dto.WcsLocationDto; +import org.jeecg.modules.wms.config.location.dto.WcsResultDto; +import org.jeecg.modules.wms.config.location.dto.WcsTaskDto; import org.jeecg.modules.wms.config.location.entity.BatchLocation; import org.jeecg.modules.wms.config.location.entity.Location; import org.jeecg.modules.wms.config.location.entity.LocationInfo; @@ -31,6 +46,7 @@ import org.jeecg.utils.OkHttpUtils; import org.jeecg.utils.PageUtil; import org.jeecg.utils.StringUtils; import org.jeecg.utils.constant.QuantityConstant; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -76,6 +92,9 @@ public class LocationServiceImpl extends ServiceImpl<LocationMapper, Location> i @Resource private IInventoryDetailService inventoryDetailService; + + @Autowired + private ILocationService locationService; @Override public Location getLocationByCode(String locationCode, String warehouseCode) { @@ -85,8 +104,7 @@ public class LocationServiceImpl extends ServiceImpl<LocationMapper, Location> i LambdaQueryWrapper<Location> locationLambdaQueryWrapper = Wrappers.lambdaQuery(); locationLambdaQueryWrapper.eq(Location::getCode, locationCode).eq(Location::getEnable, QuantityConstant.STATUS_ENABLE).eq(Location::getWarehouseCode, warehouseCode); - Location location = this.getOne(locationLambdaQueryWrapper); - return location; + return locationService.getOne(locationLambdaQueryWrapper); } @Override @@ -94,8 +112,7 @@ public class LocationServiceImpl extends ServiceImpl<LocationMapper, Location> i LambdaQueryWrapper<Location> locationLambdaQueryWrapper = Wrappers.lambdaQuery(); locationLambdaQueryWrapper.eq(Location::getRow, row).eq(Location::getIcolumn, column).eq(Location::getLayer, layer) .eq(Location::getEnable, QuantityConstant.STATUS_ENABLE).eq(Location::getWarehouseCode, warehouseCode); - Location location = this.getOne(locationLambdaQueryWrapper); - return location; + return locationService.getOne(locationLambdaQueryWrapper); } @Override @@ -103,16 +120,16 @@ public class LocationServiceImpl extends ServiceImpl<LocationMapper, Location> i LambdaQueryWrapper<Location> locationLambdaQueryWrapper = Wrappers.lambdaQuery(); locationLambdaQueryWrapper.eq(Location::getZoneCode, zoneCode).eq(Location::getEnable, QuantityConstant.STATUS_ENABLE).eq(Location::getWarehouseCode, warehouseCode); - List<Location> locationList = this.list(locationLambdaQueryWrapper); - return locationList; + return locationService.list(locationLambdaQueryWrapper); } @Override + @Transactional public boolean updateStatus(String locationCode, String status, String warehouseCode) { LambdaUpdateWrapper<Location> updateWrapper = Wrappers.lambdaUpdate(); updateWrapper.ne(Location::getStatus, status).eq(Location::getCode, locationCode).eq(Location::getWarehouseCode, warehouseCode).set(Location::getStatus, status); - return update(updateWrapper); + return locationService.update(updateWrapper); } /** @@ -120,6 +137,7 @@ public class LocationServiceImpl extends ServiceImpl<LocationMapper, Location> i * 更新库位时,先判断库位状态是不一致的才能更新 */ @Override + @Transactional public boolean updateContainerCodeAndStatus(String locationCode, String containerCode, String status, String warehouseCode) { if (StringUtils.isNotEmpty(containerCode)) { LambdaQueryWrapper<Location> locationLambdaQueryWrapper = Wrappers.lambdaQuery(); @@ -133,19 +151,19 @@ public class LocationServiceImpl extends ServiceImpl<LocationMapper, Location> i LambdaUpdateWrapper<Location> updateWrapper = Wrappers.lambdaUpdate(); updateWrapper.ne(Location::getStatus, status).eq(Location::getCode, locationCode).eq(Location::getWarehouseCode, warehouseCode) .set(Location::getContainerCode, containerCode).set(Location::getStatus, status); - return update(updateWrapper); + return locationService.update(updateWrapper); } @Override public Location getNear(Location location) { int rowFlag = location.getRowFlag(); - Location locaiton1 = null; + Location nearlocaiton = null; if (rowFlag == 1) { - locaiton1 = getInsideNear(location); + nearlocaiton = getInsideNear(location); } else { - locaiton1 = getOutSideNear(location); + nearlocaiton = getOutSideNear(location); } - return locaiton1; + return nearlocaiton; } @Override @@ -155,10 +173,9 @@ public class LocationServiceImpl extends ServiceImpl<LocationMapper, Location> i .eq(Location::getRoadWay, location.getRoadWay()).eq(Location::getIcolumn, location.getIcolumn()).eq(Location::getLayer, location.getLayer()) .eq(Location::getLocationTypeCode, location.getLocationTypeCode()).eq(Location::getRowFlag, QuantityConstant.ROW_IN); List<Location> locationList = list(locationLambdaQueryWrapper); - for (Location location1 : locationList) { - int diff = Math.abs(location1.getRow().intValue() - location.getRow().intValue()); - if (diff == 1) { - return location1; + for (Location insideLocation : locationList) { + if (Math.abs(insideLocation.getRow().intValue() - location.getRow().intValue()) == 1) { + return insideLocation; } } return null; @@ -171,10 +188,9 @@ public class LocationServiceImpl extends ServiceImpl<LocationMapper, Location> i .eq(Location::getRoadWay, location.getRoadWay()).eq(Location::getIcolumn, location.getIcolumn()).eq(Location::getLayer, location.getLayer()) .eq(Location::getLocationTypeCode, location.getLocationTypeCode()).eq(Location::getRowFlag, QuantityConstant.ROW_OUT); List<Location> locationList = list(locationLambdaQueryWrapper); - for (Location location1 : locationList) { - int diff = Math.abs(location1.getRow().intValue() - location.getRow().intValue()); - if (diff == 1) { - return location1; + for (Location outSideLocation : locationList) { + if (Math.abs(outSideLocation.getRow().intValue() - location.getRow().intValue()) == 1) { + return outSideLocation; } } return null; @@ -182,11 +198,11 @@ public class LocationServiceImpl extends ServiceImpl<LocationMapper, Location> i @Override public Location getEmptyLocation(Location location) { - Location location1 = getEmptyOutSideLocation(location); - if (location1 == null) { - location1 = getEmptyInsideLocation(location); + Location emptyLocation = getEmptyOutSideLocation(location); + if (emptyLocation == null) { + emptyLocation = getEmptyInsideLocation(location); } - return location1; + return emptyLocation; } @Override @@ -194,8 +210,7 @@ public class LocationServiceImpl extends ServiceImpl<LocationMapper, Location> i LambdaQueryWrapper<Location> locationLambdaQueryWrapper = Wrappers.lambdaQuery(); locationLambdaQueryWrapper.eq(Location::getRoadWay, roadWay).eq(Location::getWarehouseCode, warehouseCode) .eq(Location::getStatus, QuantityConstant.STATUS_LOCATION_EMPTY).eq(Location::getContainerCode, QuantityConstant.EMPTY_STRING); - int count = count(locationLambdaQueryWrapper); - return count; + return locationService.count(locationLambdaQueryWrapper); } @Override @@ -231,8 +246,7 @@ public class LocationServiceImpl extends ServiceImpl<LocationMapper, Location> i if (locationList == null || locationList.size() <= 0) { return null; } - Location location1 = locationList.get(0); - return location1; + return locationList.get(0); } @Override @@ -271,8 +285,7 @@ public class LocationServiceImpl extends ServiceImpl<LocationMapper, Location> i if (locationList == null || locationList.size() <= 0) { return null; } - Location location1 = locationList.get(0); - return location1; + return locationList.get(0); } @Override @@ -365,9 +378,7 @@ public class LocationServiceImpl extends ServiceImpl<LocationMapper, Location> i } } } - - boolean success = saveBatch(locationList); - if (!success) { + if (!locationService.saveBatch(locationList)) { throw new JeecgBootException("批量增加库位失败"); } return Result.ok("批量增加库位成功"); -- libgit2 0.22.2