Blame view

src/test/java/com.huaheng.test/Demo.java 5.58 KB
易文鹏 authored
1
2
package com.huaheng.test;
3
import cn.hutool.core.collection.CollectionUtil;
4
import cn.hutool.core.math.MathUtil;
5
import cn.hutool.core.util.ObjectUtil;
易文鹏 authored
6
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
7
8
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
易文鹏 authored
9
import com.huaheng.HuaHengApplication;
10
import com.huaheng.framework.redis.RedisCache;
易文鹏 authored
11
import com.huaheng.pc.config.location.domain.Location;
12
import com.huaheng.pc.config.location.domain.LocationStatus;
易文鹏 authored
13
import com.huaheng.pc.config.location.service.LocationService;
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;
易文鹏 authored
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;
23
import org.springframework.data.redis.core.RedisTemplate;
易文鹏 authored
24
25
import org.springframework.test.context.junit4.SpringRunner;
26
import javax.annotation.Resource;
27
import java.util.*;
28
import java.util.stream.Collectors;
易文鹏 authored
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;
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区。

    方案二:找到哪个离出口最近的库位,然后分配库位的时候,用方法找到离这个库位最近的库位,进行分配,但是每次分配只能分配离这个库位最近的。
    */
59
60
    private final static String INVENTORY_RANKING_KEY = "INVENTORY_RANKING";
易文鹏 authored
61
62
    @Test
    public void test() {
63
64
65
66
67
68
69
70
        // 统计物料出入库的频率,将常用的物料优先分配离出入口近的库位,外侧库位优先。
        // 常用的物料,需要华恒自己根据物料出入库的频次进行判断

        // 获取统计排行前30位的物料信息
        // 优先出库原始数据,历史数据(1期暂时不做考虑,不需要考虑原始数据)
        // 入库数据存放至A区
        // 常用库位(A区)
71
72
73
74
        Map<String, InventoryRankVO> inventoryRankMap =
                inventoryTransactionService.getMaterialDetailByKey(INVENTORY_RANKING_KEY);

        String inputOrOutMaterialCode = "DR-QB-01M";
75
76
        InventoryRankVO inputMaterialCode = inventoryRankMap.get(inputOrOutMaterialCode);
77
78
79
        // 判断是否存在排行物料
        if (ObjectUtil.isNotEmpty(inputMaterialCode)) {
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)) {
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.");
                }
94
            }
95
        }
易文鹏 authored
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;
    }

}