Commit 3d40fb333eda68c17d1d36b4695ef4b4494a3a5f
1 parent
7aa98c40
fix: 动态分配库位调整:方法加上事物,数据库操作加上对数据结果判断,清除魔法值,查询相同标记不为4就抛异常
Showing
3 changed files
with
63 additions
and
43 deletions
src/main/java/com/huaheng/api/wcs/service/warecellAllocation/LocationAllocationServiceImpl.java
... | ... | @@ -20,6 +20,7 @@ import com.huaheng.pc.config.zone.domain.Zone; |
20 | 20 | import com.huaheng.pc.config.zone.service.ZoneService; |
21 | 21 | import com.huaheng.pc.task.taskHeader.service.TaskHeaderService; |
22 | 22 | import org.springframework.stereotype.Service; |
23 | +import org.springframework.transaction.annotation.Transactional; | |
23 | 24 | import org.springframework.util.StopWatch; |
24 | 25 | |
25 | 26 | import javax.annotation.Resource; |
... | ... | @@ -28,6 +29,7 @@ import java.time.format.DateTimeFormatter; |
28 | 29 | import java.util.*; |
29 | 30 | import java.util.stream.Collectors; |
30 | 31 | |
32 | +import static com.huaheng.common.constant.QuantityConstant.*; | |
31 | 33 | import static java.util.stream.Collectors.toList; |
32 | 34 | |
33 | 35 | @Service |
... | ... | @@ -48,20 +50,14 @@ public class LocationAllocationServiceImpl implements LocationAllocationService |
48 | 50 | @Resource |
49 | 51 | private ConfigService configService; |
50 | 52 | |
53 | + @Transactional | |
51 | 54 | @Override |
52 | 55 | public String allocation(int high, String area, String roadWay, String containerCode, Integer frequencyLocation, |
53 | 56 | Integer emptyContainerTask, Integer isSelfCreated, boolean isFlammable) { |
54 | 57 | |
55 | - //容器 | |
56 | - Container container = containerService.getOne(new LambdaQueryWrapper<Container>().eq(Container::getCode, containerCode)); | |
57 | - //容器类型 | |
58 | - ContainerType containerType = containerTypeService.getOne(new LambdaQueryWrapper<ContainerType>().eq(ContainerType::getCode, container.getContainerType())); | |
59 | - if (containerType == null) { | |
60 | - throw new ServiceException("容器类型不存在"); | |
61 | - } | |
62 | 58 | //二期5号巷道 |
63 | 59 | if (roadWay.equals("5")) { |
64 | - return fiveStacker(high, containerType.getCode()); | |
60 | + return fiveStacker(high, containerCode); | |
65 | 61 | } else { |
66 | 62 | return doubleRk(area, roadWay, high, frequencyLocation, emptyContainerTask, isSelfCreated, isFlammable); |
67 | 63 | } |
... | ... | @@ -70,13 +66,15 @@ public class LocationAllocationServiceImpl implements LocationAllocationService |
70 | 66 | |
71 | 67 | //一厂二期5号堆垛机,大小托盘 |
72 | 68 | //分配库位排序,(层-外侧-内侧-列) |
73 | - private String fiveStacker(int high, String containerTypeCode) { | |
69 | + private String fiveStacker(int high, String containerCode) { | |
70 | + Container container = containerService.getOne(new LambdaQueryWrapper<Container>().eq(Container::getCode, containerCode)); | |
71 | + String containerType = container.getContainerType(); | |
74 | 72 | //判断预留库位 |
75 | 73 | int reserveNumber = getReserveNumber(); |
76 | 74 | LambdaQueryWrapper<Location> wrapper = Wrappers.lambdaQuery(); |
77 | 75 | wrapper |
78 | 76 | .eq(Location::getRoadway, 5) |
79 | - .eq(Location::getStatus, QuantityConstant.STATUS_LOCATION_EMPTY) | |
77 | + .eq(Location::getStatus, STATUS_LOCATION_EMPTY) | |
80 | 78 | .eq(Location::getHigh, high) |
81 | 79 | .eq(Location::getContainerCode, "") |
82 | 80 | .ne(Location::getIColumn, "26") |
... | ... | @@ -91,17 +89,17 @@ public class LocationAllocationServiceImpl implements LocationAllocationService |
91 | 89 | } |
92 | 90 | |
93 | 91 | //大托盘占两个库位 |
94 | - if (containerTypeCode.equals("X") || containerTypeCode.equals("W")) { | |
92 | + if (containerType.equals(CONTAINER_TYPE_X) || containerType.equals(CONTAINER_TYPE_W)) { | |
95 | 93 | for (Location location : list) { |
96 | - if (location.getIColumn() % 2 != 0 && location.getTemporaryType().charAt(0) != '1') { | |
94 | + if (location.getIColumn() % 2 != 0 && location.getTemporaryType().startsWith(SMALL_CONTAINER_TYPE)) { | |
97 | 95 | Location rightLocation = locationService.getRightEmptyLocation(location); |
98 | 96 | if (rightLocation != null) { |
99 | 97 | //禁用库位 |
100 | - int updateCount = locationService.updateStatusNew(rightLocation.getCode(), "CS0001", QuantityConstant.STATUS_LOCATION_DISABLE, QuantityConstant.STATUS_LOCATION_EMPTY); | |
98 | + int updateCount = locationService.updateStatusNew(rightLocation.getCode(), DEFAULT_WAREHOUSE, STATUS_LOCATION_DISABLE, STATUS_LOCATION_EMPTY); | |
101 | 99 | if (updateCount != 1) { |
102 | 100 | throw new ServiceException("禁用库位失败"); |
103 | 101 | } |
104 | - if (location.getTemporaryType().equals("0")) { | |
102 | + if (location.getTemporaryType().equals(UNDEFINED_CONTAINER_TYPE)) { | |
105 | 103 | //设置相邻临时库位类型 |
106 | 104 | setTemporaryLocationType(location, true); |
107 | 105 | } |
... | ... | @@ -113,12 +111,12 @@ public class LocationAllocationServiceImpl implements LocationAllocationService |
113 | 111 | } else { |
114 | 112 | //小托盘不分配25列 |
115 | 113 | list = list.stream().filter(location -> location.getIColumn() != 25 |
116 | - && location.getTemporaryType().charAt(0) != '2').collect(toList()); | |
114 | + && !String.valueOf(location.getTemporaryType()).startsWith(BIG_CONTAINER_TYPE)).collect(Collectors.toList()); | |
117 | 115 | if (list.isEmpty()) { |
118 | 116 | return null; |
119 | 117 | } |
120 | 118 | Location location = list.get(0); |
121 | - if (location.getTemporaryType().equals("0")) { | |
119 | + if (location.getTemporaryType().equals(UNDEFINED_CONTAINER_TYPE)) { | |
122 | 120 | //设置相邻临时库位类型 |
123 | 121 | setTemporaryLocationType(location, false); |
124 | 122 | } |
... | ... | @@ -129,7 +127,7 @@ public class LocationAllocationServiceImpl implements LocationAllocationService |
129 | 127 | //设置相邻临时库位类型 |
130 | 128 | void setTemporaryLocationType(Location location, boolean isBigContainer) { |
131 | 129 | List<Location> setTemporaryTypeList = new ArrayList<>(); |
132 | - String prefix = isBigContainer ? "2-" : "1-"; | |
130 | + String prefix = isBigContainer ? BIG_CONTAINER_TYPE : SMALL_CONTAINER_TYPE; | |
133 | 131 | |
134 | 132 | setTemporaryTypeList.add(location); |
135 | 133 | setTemporaryTypeList.add(getLocationByOffset(location, 0, 1)); |
... | ... | @@ -138,8 +136,10 @@ public class LocationAllocationServiceImpl implements LocationAllocationService |
138 | 136 | |
139 | 137 | for (Location temporaryLocation : setTemporaryTypeList) { |
140 | 138 | if (temporaryLocation != null) { |
141 | - temporaryLocation.setTemporaryType(prefix + location.getCode() + "-" + LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd-HH:mm:ss"))); | |
142 | - locationService.updateById(temporaryLocation); | |
139 | + temporaryLocation.setTemporaryType(prefix + "-" + location.getCode() + "-" + LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd-HH:mm:ss"))); | |
140 | + if (locationService.updateById(temporaryLocation)) { | |
141 | + throw new ServiceException("设置临时库位类型失败"); | |
142 | + } | |
143 | 143 | } |
144 | 144 | } |
145 | 145 | } |
... | ... | @@ -164,7 +164,7 @@ public class LocationAllocationServiceImpl implements LocationAllocationService |
164 | 164 | LambdaQueryWrapper<Location> wrapper = Wrappers.lambdaQuery(); |
165 | 165 | wrapper.eq(Location::getArea, area) |
166 | 166 | .eq(Location::getRoadway, roadWay) |
167 | - .eq(Location::getStatus, QuantityConstant.STATUS_LOCATION_EMPTY) | |
167 | + .eq(Location::getStatus, STATUS_LOCATION_EMPTY) | |
168 | 168 | .eq(Location::getHigh, high) |
169 | 169 | .eq(Location::getContainerCode, "") |
170 | 170 | .orderByAsc(Location::getILayer) |
... | ... | @@ -196,9 +196,9 @@ public class LocationAllocationServiceImpl implements LocationAllocationService |
196 | 196 | LambdaQueryWrapper<Location> locationLambda = Wrappers.lambdaQuery(); |
197 | 197 | locationLambda.eq(Location::getArea, area) |
198 | 198 | .eq(Location::getRoadway, roadWay) |
199 | - .eq(Location::getStatus, QuantityConstant.STATUS_LOCATION_EMPTY) | |
199 | + .eq(Location::getStatus, STATUS_LOCATION_EMPTY) | |
200 | 200 | .eq(Location::getHigh, high) |
201 | - .eq(Location::getRowFlag, QuantityConstant.ROW_OUT)//外侧 | |
201 | + .eq(Location::getRowFlag, ROW_OUT)//外侧 | |
202 | 202 | .eq(Location::getContainerCode, "") |
203 | 203 | .last(" limit 20"); |
204 | 204 | |
... | ... | @@ -217,7 +217,7 @@ public class LocationAllocationServiceImpl implements LocationAllocationService |
217 | 217 | } |
218 | 218 | |
219 | 219 | //频繁库位 |
220 | - String str = ""; | |
220 | + String str; | |
221 | 221 | if (frequencyLocation == 1) { |
222 | 222 | str = "frequencyLocation asc"; |
223 | 223 | //locationLambda.orderByAsc(Location::getFrequencyLocation); //升序 |
... | ... | @@ -258,9 +258,9 @@ public class LocationAllocationServiceImpl implements LocationAllocationService |
258 | 258 | locationLambda = Wrappers.lambdaQuery(); |
259 | 259 | locationLambda.eq(Location::getArea, area) |
260 | 260 | .eq(StringUtils.isNotEmpty(roadWay), Location::getRoadway, roadWay) |
261 | - .eq(Location::getStatus, QuantityConstant.STATUS_LOCATION_EMPTY) | |
261 | + .eq(Location::getStatus, STATUS_LOCATION_EMPTY) | |
262 | 262 | .eq(Location::getHigh, high) |
263 | - .eq(Location::getRowFlag, QuantityConstant.ROW_IN) | |
263 | + .eq(Location::getRowFlag, ROW_IN) | |
264 | 264 | .eq(Location::getContainerCode, "") |
265 | 265 | .last(" limit 20"); |
266 | 266 | if (emptyContainerTask == 1) { |
... | ... | @@ -318,7 +318,7 @@ public class LocationAllocationServiceImpl implements LocationAllocationService |
318 | 318 | |
319 | 319 | //获取双伸位预留库位数 |
320 | 320 | private int getReserveNumber() { |
321 | - String value = configService.getKey(QuantityConstant.DOUBLE_FORK_RESERVE_LOCATION); | |
321 | + String value = configService.getKey(DOUBLE_FORK_RESERVE_LOCATION); | |
322 | 322 | return StringUtils.isNotEmpty(value) ? Integer.parseInt(value) : 0; |
323 | 323 | } |
324 | 324 | |
... | ... |
src/main/java/com/huaheng/common/constant/QuantityConstant.java
... | ... | @@ -545,4 +545,19 @@ public class QuantityConstant { |
545 | 545 | public static final String DEFAULT_DEPT = "01030101"; |
546 | 546 | public static final String DEFAULT_STOCK = "035"; |
547 | 547 | |
548 | + | |
549 | + /** | |
550 | + * 动态分配库位 | |
551 | + */ | |
552 | + public static final String CONTAINER_TYPE_X = "X"; | |
553 | + public static final String CONTAINER_TYPE_W = "W"; | |
554 | + | |
555 | + /** | |
556 | + * 库位临时托盘类型 | |
557 | + */ | |
558 | + public static final String UNDEFINED_CONTAINER_TYPE = "0"; | |
559 | + public static final String SMALL_CONTAINER_TYPE = "1"; | |
560 | + public static final String BIG_CONTAINER_TYPE = "2"; | |
561 | + | |
562 | + | |
548 | 563 | } |
... | ... |
src/main/java/com/huaheng/pc/config/location/service/LocationServiceImpl.java
... | ... | @@ -33,6 +33,8 @@ import com.huaheng.pc.task.taskHeader.service.TaskHeaderService; |
33 | 33 | import io.swagger.models.auth.In; |
34 | 34 | import org.springframework.stereotype.Service; |
35 | 35 | |
36 | +import static com.huaheng.common.constant.QuantityConstant.*; | |
37 | + | |
36 | 38 | import javax.annotation.Resource; |
37 | 39 | import java.text.MessageFormat; |
38 | 40 | import java.util.*; |
... | ... | @@ -783,36 +785,39 @@ public class LocationServiceImpl extends ServiceImpl<LocationMapper, Location> i |
783 | 785 | @Override |
784 | 786 | public void unbanRightLocationAndUnmark(String containerType, String locationCode) { |
785 | 787 | //解禁用右侧库位 |
786 | - Location location = locationService.getLocationByCode(locationCode, "CS0001"); | |
787 | - if (("X".equals(containerType) || "W".equals(containerType)) && "5".equals(location.getRoadway())) { | |
788 | + Location location = locationService.getLocationByCode(locationCode, DEFAULT_WAREHOUSE); | |
789 | + if ((CONTAINER_TYPE_X.equals(containerType) || CONTAINER_TYPE_W.equals(containerType)) && "5".equals(location.getRoadway())) { | |
788 | 790 | Location rightLocation = locationService.getRightDisableLocation(location); |
789 | 791 | if (rightLocation != null) { |
790 | - int updateCount = locationService.updateStatusNew(rightLocation.getCode(), "CS0001", QuantityConstant.STATUS_LOCATION_EMPTY, QuantityConstant.STATUS_LOCATION_DISABLE); | |
792 | + int updateCount = locationService.updateStatusNew(rightLocation.getCode(), DEFAULT_WAREHOUSE, STATUS_LOCATION_EMPTY, STATUS_LOCATION_DISABLE); | |
791 | 793 | if (updateCount != 1) { |
792 | 794 | throw new ServiceException("重复分配库位时,解锁禁用失败!"); |
793 | 795 | } |
794 | 796 | } |
795 | 797 | } |
796 | 798 | |
797 | - //清除库位的上下左右库位标记 | |
798 | - if (location.getTemporaryType().equals("0")) { | |
799 | + //清除就近4个库位的标记 | |
800 | + if (location.getTemporaryType().equals(UNDEFINED_CONTAINER_TYPE)) { | |
799 | 801 | throw new ServiceException("库位未被标记异常!"); |
800 | 802 | } |
801 | 803 | List<Location> list = locationService.list(new LambdaQueryWrapper<Location>().eq(Location::getTemporaryType, location.getTemporaryType())); |
802 | - if (!list.isEmpty()) { | |
803 | - boolean flat = true; | |
804 | - for (Location l : list) { | |
805 | - if (StringUtils.isNotEmpty(l.getContainerCode()) || !l.getStatus().equals(QuantityConstant.STATUS_LOCATION_EMPTY)) { | |
806 | - flat = false; | |
807 | - break; | |
808 | - } | |
809 | - } | |
810 | - if (flat) { | |
811 | - locationService.update(new LambdaUpdateWrapper<Location>() | |
812 | - .set(Location::getTemporaryType, "0").in(Location::getCode, list.stream() | |
813 | - .map(Location::getCode).collect(Collectors.toList()))); | |
804 | + if (list.size() != 4) { | |
805 | + throw new ServiceException("库位标记异常,相同标记未达4个:" + list.size()); | |
806 | + } | |
807 | + | |
808 | + //4个库位都是空的,并且状态位空,才能清除标记 | |
809 | + boolean flat = true; | |
810 | + for (Location l : list) { | |
811 | + if (StringUtils.isNotEmpty(l.getContainerCode()) || !l.getStatus().equals(STATUS_LOCATION_EMPTY)) { | |
812 | + flat = false; | |
813 | + break; | |
814 | 814 | } |
815 | 815 | } |
816 | + if (flat) { | |
817 | + locationService.update(new LambdaUpdateWrapper<Location>() | |
818 | + .set(Location::getTemporaryType, UNDEFINED_CONTAINER_TYPE).in(Location::getCode, list.stream() | |
819 | + .map(Location::getCode).collect(Collectors.toList()))); | |
820 | + } | |
816 | 821 | |
817 | 822 | } |
818 | 823 | |
... | ... |