自动化立体仓库 - WMS系统
#
Junjie
10 小时以前 5f2bb7dd02cce1696dcc37d9591830864509eb27
src/main/java/com/zy/asrs/controller/OutController.java
@@ -22,6 +22,9 @@
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.ZoneId;
import java.util.*;
import java.util.stream.Collectors;
@@ -162,8 +165,13 @@
                        orderDetl.getBrand(), orderDetl.getStandby1(), orderDetl.getStandby2(), orderDetl.getStandby3(), orderDetl.getBoxType1(), orderDetl.getBoxType2(), orderDetl.getBoxType3(), cstateid);
                HashMap<String, Double> locAnfmeMap = new HashMap<>();
                HashMap<String, Date> locTimeMap = new HashMap<>();
                HashMap<String, List<LocDetl>> map = new HashMap<>();
                for (LocDetl locDetl : locDetls) {
                    if (disableCstateidList.contains(locDetl.getCstateid())) {
                        continue;
                    }
                    if (map.containsKey(locDetl.getLocNo())) {
                        List<LocDetl> list = map.get(locDetl.getLocNo());
                        list.add(locDetl);
@@ -177,59 +185,85 @@
                        list.add(locDetl);
                        map.put(locDetl.getLocNo(), list);
                        locAnfmeMap.put(locDetl.getLocNo(), locDetl.getAnfme());
                        locTimeMap.put(locDetl.getLocNo(), locDetl.getAppeTime());
                    }
                }
                // 使用Stream API进行排序并创建新的Map,同时保持插入顺序。
                Map<String, Double> sortedMap = locAnfmeMap.entrySet().stream()
                        .sorted(Map.Entry.<String, Double>comparingByValue(Comparator.reverseOrder())) // 根据值排序条目。
                        .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (e1, e2) -> e1, LinkedHashMap::new));
                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
                // 使用 TreeMap(自动按 key 升序排序)
                Map<String, List<Map.Entry<String, Date>>> sortedByDayAsc = locTimeMap.entrySet()
                        .stream()
                        .collect(Collectors.groupingBy(
                                entry -> sdf.format(entry.getValue()),
                                TreeMap::new, // 自动按键(日期)升序排序
                                Collectors.toList()
                        ));
                //未匹配上整托库存
                HashMap<String, Double> lessMap = new HashMap<>();
                List<LocDetl> allLoc = new ArrayList<>();
                List<LocDetl> lessLoc = new ArrayList<>();
                //优先找整托
                for (Map.Entry<String, Double> entry : sortedMap.entrySet()) {
                    if (issued <= 0) {
                        break;
                    }
                    String locNo = entry.getKey();
                    Double anfme = entry.getValue();
                    if(anfme > orderDetl.getAnfme()) {
                        lessMap.put(locNo, anfme);
                        continue;
                    }
                    List<LocDetl> list = map.get(locNo);
                    allLoc.addAll(list);
//                //优先找整托
//                for (Map.Entry<String, List<Map.Entry<String, Date>>> listEntry : sortedByDayAsc.entrySet()) {
//                    for (Map.Entry<String, Date> dateEntry : listEntry.getValue()) {
//                        if (issued <= 0) {
//                            break;
//                        }
//                        String locNo = dateEntry.getKey();
//                        Double anfme = locAnfmeMap.get(locNo);
//                        if(anfme > orderDetl.getAnfme()) {
//                            lessMap.put(locNo, anfme);
//                            continue;
//                        }
//                        List<LocDetl> list = map.get(locNo);
//                        allLoc.addAll(list);
//
//                        // 剩余待出数量递减
//                        issuedBigDecimal = issuedBigDecimal.subtract(BigDecimal.valueOf(anfme));
//                        issued = issuedBigDecimal.doubleValue();
//                    }
//                }
//
//                if(issued > 0) {
//                    //零散搜索
//                    for (Map.Entry<String, Double> entry : lessMap.entrySet()) {
//                        if (issued <= 0) {
//                            break;
//                        }
//
//                        String locNo = entry.getKey();
//                        Double anfme = entry.getValue();
//                        if (anfme >= issued) {
//                            List<LocDetl> list = map.get(locNo);
//                            lessLoc.addAll(list);
//                            // 剩余待出数量递减
//                            issuedBigDecimal = issuedBigDecimal.subtract(BigDecimal.valueOf(anfme));
//                            issued = issuedBigDecimal.doubleValue();
//                        }
//                    }
//                }
//                allLoc.addAll(lessLoc);
                    // 剩余待出数量递减
                    issuedBigDecimal = issuedBigDecimal.subtract(BigDecimal.valueOf(anfme));
                    issued = issuedBigDecimal.doubleValue();
                }
                if(issued > 0) {
                    //零散搜索
                    for (Map.Entry<String, Double> entry : lessMap.entrySet()) {
                //必须把当天库存用完
                for (Map.Entry<String, List<Map.Entry<String, Date>>> listEntry : sortedByDayAsc.entrySet()) {
                    for (Map.Entry<String, Date> dateEntry : listEntry.getValue()) {
                        if (issued <= 0) {
                            break;
                        }
                        String locNo = dateEntry.getKey();
                        Double anfme = locAnfmeMap.get(locNo);
                        String locNo = entry.getKey();
                        Double anfme = entry.getValue();
                        if (anfme >= issued) {
                            List<LocDetl> list = map.get(locNo);
                            lessLoc.addAll(list);
                            // 剩余待出数量递减
                            issuedBigDecimal = issuedBigDecimal.subtract(BigDecimal.valueOf(anfme));
                            issued = issuedBigDecimal.doubleValue();
                        }
                        List<LocDetl> list = map.get(locNo);
                        allLoc.addAll(list);
                        // 剩余待出数量递减
                        issuedBigDecimal = issuedBigDecimal.subtract(BigDecimal.valueOf(anfme));
                        issued = issuedBigDecimal.doubleValue();
                    }
                }
                allLoc.addAll(lessLoc);
                issuedBigDecimal = Optional.of(BigDecimal.valueOf(orderDetl.getAnfme()).subtract(BigDecimal.valueOf(orderDetl.getWorkQty()))).orElse(new BigDecimal(0));
                issued = issuedBigDecimal.doubleValue();
                for (LocDetl locDetl : allLoc) {