zjj
21 小时以前 4114759a57d73661937f28a765fb8a67c017b14b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
package com.vincent.rsf.server.manager.utils;
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.vincent.rsf.framework.common.SpringUtils;
import com.vincent.rsf.server.api.utils.LocUtils;
import com.vincent.rsf.server.manager.entity.DeviceSite;
import com.vincent.rsf.server.manager.entity.Loc;
import com.vincent.rsf.server.manager.entity.LocItem;
import com.vincent.rsf.server.manager.service.DeviceSiteService;
import com.vincent.rsf.server.manager.service.LocItemService;
import com.vincent.rsf.server.manager.service.LocService;
import com.vincent.rsf.server.manager.enums.LocStsType;
 
import java.util.Comparator;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
 
public class LocManageUtil {
 
    /**
     * @author Ryan
     * @description  获取目标库位, 包含库位获取策略
     * @param
     * @return
     * @time 2025/3/31 08:50
     */
    public static String getTargetLoc(Long areaId) {
        //TODO 库位策略后续排期
        LocService locService = SpringUtils.getBean(LocService.class);
 
        Loc loc = locService.getOne(new LambdaQueryWrapper<Loc>()
                .eq(Loc::getAreaId, areaId)
                .orderByAsc(Loc::getLev)
                .orderByAsc(Loc::getCol)
                .orderByAsc(Loc::getRow)
                .eq(Loc::getUseStatus, LocStsType.LOC_STS_TYPE_O.type), false
        );
 
        return !Objects.isNull(loc) ? loc.getCode() : null;
    }
 
 
    /**
    * @author Ryan
    * @description 获取目标站点
    * @param
    * @return
    * @time 2025/3/31 09:49
    */
    public static String getTargetSite() {
        //TODO 站点策略后续排期
        DeviceSiteService deviceSite = SpringUtils.getBean(DeviceSiteService.class);
        DeviceSite loc = deviceSite.getOne(new LambdaQueryWrapper<DeviceSite>().eq(DeviceSite::getStatus, 1), false);
        return !Objects.isNull(loc) ? loc.getSite() : null;
    }
 
    /**
     * 出库策略:--〈效率优化〉
     * @param matnrCode
     * @param splrBatch
     * @param anfme
     * @return
     */
    public static List<LocItem> getEfficiencyFirstItemList(String matnrCode, String splrBatch, Double anfme) {
        LambdaQueryWrapper<LocItem> locItemQueryWrapper = new LambdaQueryWrapper<>();
        locItemQueryWrapper.eq(LocItem::getMatnrCode, matnrCode);
        locItemQueryWrapper.eq(LocItem::getBatch, splrBatch);
        String applySql = String.format(
                "EXISTS (SELECT 1 FROM man_loc ml " +
                        "WHERE ml.use_status = '%s'" +
                        "AND ml.id = man_loc_item.loc_id " +
                        ")",
                LocStsType.LOC_STS_TYPE_F.type
        );
        locItemQueryWrapper.apply(applySql);
        LocItemService locItemService = SpringUtils.getBean(LocItemService.class);
        List<LocItem> locItems = locItemService.list(locItemQueryWrapper);
        locItems.sort(Comparator.comparing((LocItem item) -> !LocUtils.isShallowLoc(item.getLocCode())));
        List<LocItem> locsSet = locItems.stream().filter(locItem -> locItem.getAnfme().compareTo(anfme) == 0.0).collect(Collectors.toList());
        if (!locsSet.isEmpty()) {
            return locsSet;
        }
        return locItems;
    }
 
 
    /**
     * 出库策略:--<先进先出>
     * @param matnrCode
     * @param splrBatch
     * @param anfme
     * @return
     */
    public static List<LocItem> getFirstInFirstOutItemList(String matnrCode, String splrBatch, Double anfme) {
        LambdaQueryWrapper<LocItem> locItemQueryWrapper = new LambdaQueryWrapper<>();
        locItemQueryWrapper.eq(LocItem::getMatnrCode, matnrCode);
        locItemQueryWrapper.eq(LocItem::getBatch, splrBatch);
        locItemQueryWrapper.orderByAsc(LocItem::getCreateTime);
        String applySql = String.format(
                "EXISTS (SELECT 1 FROM man_loc ml " +
                        "WHERE ml.use_status = '%s'" +
                        "AND ml.id = man_loc_item.loc_id " +
                        ")",
                LocStsType.LOC_STS_TYPE_F.type
        );
        locItemQueryWrapper.apply(applySql);
        LocItemService locItemService = SpringUtils.getBean(LocItemService.class);
        List<LocItem> locItems = locItemService.list(locItemQueryWrapper);
        return locItems;
    }
 
 
 
}