1
2
package com . huaheng . test ;
puff
authored
2 years ago
3
import cn.hutool.core.collection.CollectionUtil ;
puff
authored
2 years ago
4
import cn.hutool.core.math.MathUtil ;
puff
authored
2 years ago
5
import cn.hutool.core.util.ObjectUtil ;
6
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper ;
puff
authored
2 years ago
7
8
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper ;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page ;
9
import com.huaheng.HuaHengApplication ;
puff
authored
2 years ago
10
import com.huaheng.framework.redis.RedisCache ;
11
import com.huaheng.pc.config.location.domain.Location ;
puff
authored
2 years ago
12
import com.huaheng.pc.config.location.domain.LocationStatus ;
13
import com.huaheng.pc.config.location.service.LocationService ;
puff
authored
2 years ago
14
15
16
17
import com.huaheng.pc.config.material.service.MaterialService ;
import com.huaheng.pc.inventory.inventoryTransaction.domain.InventoryTransaction ;
import com.huaheng.pc.inventory.inventoryTransaction.domain.vo.InventoryRankVO ;
import com.huaheng.pc.inventory.inventoryTransaction.service.InventoryTransactionService ;
18
19
20
21
22
import lombok.extern.slf4j.Slf4j ;
import org.junit.Test ;
import org.junit.runner.RunWith ;
import org.springframework.beans.factory.annotation.Autowired ;
import org.springframework.boot.test.context.SpringBootTest ;
puff
authored
2 years ago
23
import org.springframework.data.redis.core.RedisTemplate ;
24
25
import org.springframework.test.context.junit4.SpringRunner ;
puff
authored
2 years ago
26
import javax.annotation.Resource ;
puff
authored
2 years ago
27
import java.util.* ;
puff
authored
2 years ago
28
import java.util.stream.Collectors ;
29
30
31
32
33
34
35
36
37
38
39
40
/**
* @author yiwenpeng
* @date 2023 / 7 / 20 09 : 49
*/
@Slf4j
@SpringBootTest ( classes = HuaHengApplication . class )
@RunWith ( SpringRunner . class )
public class Demo {
@Autowired
private LocationService locationService ;
puff
authored
2 years ago
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
@Resource
private RedisCache redisCache ;
@Resource
private MaterialService materialService ;
@Resource
private InventoryTransactionService inventoryTransactionService ;
/*
将上一周物料出库次数排名前 100 的记录到数据库里面,每周更新一次这个排名,每次入库的时候用托盘中的所有物料,根据物料出入库次数排名计算出本次入库要分配的库位。
方案一:假设一个仓库前后各一个出口,离这两个出口近的前 2 列,包括所有行和层,都设置为常用库位( A 区),前 4 列所有行和层的外侧库位,设置为一般常用库位( B 区),其他的就是剩余库位了,不常用 C 区。
方案二:找到哪个离出口最近的库位,然后分配库位的时候,用方法找到离这个库位最近的库位,进行分配,但是每次分配只能分配离这个库位最近的。
*/
puff
authored
2 years ago
59
60
private final static String INVENTORY_RANKING_KEY = "INVENTORY_RANKING" ;
61
62
@Test
public void test ( ) {
puff
authored
2 years ago
63
64
65
66
67
68
69
70
// 统计物料出入库的频率,将常用的物料优先分配离出入口近的库位,外侧库位优先。
// 常用的物料,需要华恒自己根据物料出入库的频次进行判断
// 获取统计排行前30位的物料信息
// 优先出库原始数据,历史数据(1期暂时不做考虑,不需要考虑原始数据)
// 入库数据存放至A区
// 常用库位(A区)
puff
authored
2 years ago
71
72
73
74
Map < String , InventoryRankVO > inventoryRankMap =
inventoryTransactionService . getMaterialDetailByKey ( INVENTORY_RANKING_KEY );
String inputOrOutMaterialCode = "DR-QB-01M" ;
puff
authored
2 years ago
75
puff
authored
2 years ago
76
InventoryRankVO inputMaterialCode = inventoryRankMap . get ( inputOrOutMaterialCode );
puff
authored
2 years ago
77
puff
authored
2 years ago
78
79
// 判断是否存在排行物料
if ( ObjectUtil . isNotEmpty ( inputMaterialCode )) {
puff
authored
2 years ago
80
81
82
83
84
// 获取常用库区
List < Location > locationList = locationService
. list ( new LambdaQueryWrapper < Location >()
. eq ( Location: : getZoneCode , "A" ));
// .eq(Location::getStatus, LocationStatus.));
85
if ( CollectionUtil . isNotEmpty ( locationList )) {
puff
authored
2 years ago
86
87
88
89
90
91
92
93
LinkedList < Location > locationLinkedList = new LinkedList <>( locationList );
locationLinkedList . sort ( Comparator . comparingInt ( Location: : getId ));
Location nearestLocation = locationLinkedList . pollFirst ();
if ( ObjectUtil . isNotEmpty ( nearestLocation )) {
System . out . print ( "Nearest Location: " + nearestLocation );
} else {
System . out . print ( "No locations available." );
}
puff
authored
2 years ago
94
}
puff
authored
2 years ago
95
}
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
}
public static Location findNearestLocation ( List < Location > locations , String locationCode ) {
if ( locations == null || locations . isEmpty () || locationCode == null ) {
return null ;
}
Location targetLocation = null ;
int minDistance = Integer . MAX_VALUE ;
int targetRow = Integer . parseInt ( locationCode . substring ( 1 , 3 )); // Extract row number from locationCode
int targetColumn = Integer . parseInt ( locationCode . substring ( 3 , 5 )); // Extract column number from locationCode
int targetLayer = Integer . parseInt ( locationCode . substring ( 5 , 7 )); // Extract layer number from locationCode
for ( Location location : locations ) {
if ( location . getCode (). equals ( locationCode )) {
continue ; // Skip the location with the same code as the target code
}
int rowDistance = Math . abs ( targetRow - location . getIRow ());
int columnDistance = Math . abs ( targetColumn - location . getIColumn ());
int layerDistance = Math . abs ( targetLayer - location . getILayer ());
int totalDistance = rowDistance + columnDistance + layerDistance ;
if ( totalDistance < minDistance ) {
minDistance = totalDistance ;
targetLocation = location ;
}
}
return targetLocation ;
}
}