| | |
| | | |
| | | 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; |
| | | |
| | |
| | | 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())) { |
| | |
| | | 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)); |
| | | // // 使用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()) { |
| | | 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 = entry.getKey(); |
| | | Double anfme = entry.getValue(); |
| | | String locNo = dateEntry.getKey(); |
| | | Double anfme = locAnfmeMap.get(locNo); |
| | | if(anfme > orderDetl.getAnfme()) { |
| | | lessMap.put(locNo, anfme); |
| | | continue; |
| | |
| | | issuedBigDecimal = issuedBigDecimal.subtract(BigDecimal.valueOf(anfme)); |
| | | issued = issuedBigDecimal.doubleValue(); |
| | | } |
| | | } |
| | | |
| | | if(issued > 0) { |
| | | //零散搜索 |