自动化立体仓库 - WMS系统
Junjie
昨天 796103a3913320b81a5769ef3b643109be82b6aa
src/main/java/com/zy/asrs/controller/OutController.java
@@ -11,6 +11,9 @@
import com.zy.common.model.LocDto;
import com.zy.common.model.TaskDto;
import com.zy.common.web.BaseController;
import com.zy.system.entity.User;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
@@ -29,6 +32,7 @@
@RestController
public class OutController extends BaseController {
    private static final Logger log = LoggerFactory.getLogger(OutController.class);
    @Autowired
    private OrderService orderService;
    @Autowired
@@ -59,15 +63,22 @@
    @PostMapping("/out/pakout/preview/auth")
    @ManagerAuth
    public R pakoutPreview(@RequestBody List<Long> ids) {
    public R pakoutPreview(@RequestBody HashMap<String,Object> param) {
        List<Long> ids = (List<Long>) param.get("ids");
        if (Cools.isEmpty(ids)) {
            return R.parse(BaseRes.PARAM);
        }
        String cstateid = param.getOrDefault("cstateid", "").toString();
        List<OrderDetlPakout> orderDetlPakouts = orderDetlPakoutService.selectBatchIds(ids);
        if (orderDetlPakouts.size() == 0) {
            return R.parse("订单明细为空");
        }
        List<String> disableCstateidList = new ArrayList<>();
        disableCstateidList.add("1001A1100000000H0KJP");//不合格
        disableCstateidList.add("1001A1100000000LFERA");//待处理
        List<LocDto> locDtos = new ArrayList<>();
@@ -83,8 +94,8 @@
                if (issued <= 0.0D) {
                    continue;
                }
                List<LocDetl> locDetls = locDetlService.queryStockAll(null, exist,orderDetl.getMatnr(), orderDetl.getBatch(),
                        orderDetl.getBrand(),orderDetl.getStandby1(),orderDetl.getStandby2(),orderDetl.getStandby3(),orderDetl.getBoxType1(),orderDetl.getBoxType2(),orderDetl.getBoxType3());
                List<LocDetl> locDetls = locDetlService.queryStockAll(null, exist, orderDetl.getMatnr(), orderDetl.getBatch(),
                        orderDetl.getBrand(), orderDetl.getStandby1(), orderDetl.getStandby2(), orderDetl.getStandby3(), orderDetl.getBoxType1(), orderDetl.getBoxType2(), orderDetl.getBoxType3(), cstateid);
                for (LocDetl locDetl : locDetls) {
                    if (issued > 0) {
                        LocDto locDto = new LocDto(locDetl.getLocNo(), locDetl.getMatnr(), locDetl.getMaktx(), locDetl.getBatch(), orderDetl.getOrderNo(),
@@ -143,9 +154,85 @@
                if (issued <= 0.0D) {
                    continue;
                }
                List<LocDetl> locDetls = locDetlService.queryStockAll(null, exist,orderDetl.getMatnr(), orderDetl.getBatch(),
                        orderDetl.getBrand(),orderDetl.getStandby1(),orderDetl.getStandby2(),orderDetl.getStandby3(),orderDetl.getBoxType1(),orderDetl.getBoxType2(),orderDetl.getBoxType3());
                List<LocDetl> locDetls = locDetlService.queryStockAll(null, exist, orderDetl.getMatnr(), orderDetl.getBatch(),
                        orderDetl.getBrand(), orderDetl.getStandby1(), orderDetl.getStandby2(), orderDetl.getStandby3(), orderDetl.getBoxType1(), orderDetl.getBoxType2(), orderDetl.getBoxType3(), cstateid);
                HashMap<String, Double> locAnfmeMap = new HashMap<>();
                HashMap<String, List<LocDetl>> map = new HashMap<>();
                for (LocDetl locDetl : locDetls) {
                    if (map.containsKey(locDetl.getLocNo())) {
                        List<LocDetl> list = map.get(locDetl.getLocNo());
                        list.add(locDetl);
                        map.put(locDetl.getLocNo(), list);
                        Double originAnfme = locAnfmeMap.get(locDetl.getLocNo());
                        originAnfme += locDetl.getAnfme();
                        locAnfmeMap.put(locDetl.getLocNo(), originAnfme);
                    }else {
                        List<LocDetl> list = new ArrayList<>();
                        list.add(locDetl);
                        map.put(locDetl.getLocNo(), list);
                        locAnfmeMap.put(locDetl.getLocNo(), locDetl.getAnfme());
                    }
                }
                // 使用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));
                //未匹配上整托库存
                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);
                    // 剩余待出数量递减
                    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 = Optional.of(BigDecimal.valueOf(orderDetl.getAnfme()).subtract(BigDecimal.valueOf(orderDetl.getWorkQty()))).orElse(new BigDecimal(0));
                issued = issuedBigDecimal.doubleValue();
                for (LocDetl locDetl : allLoc) {
                    if (disableCstateidList.contains(locDetl.getCstateid())) {
                        continue;
                    }
                    if (issued > 0) {
                        LocDto locDto = new LocDto(locDetl.getLocNo(), locDetl.getMatnr(), locDetl.getMaktx(), locDetl.getBatch(), orderDetl.getOrderNo(),
                                issued >= locDetl.getAnfme() ? locDetl.getAnfme() : issued);
@@ -164,6 +251,8 @@
                        locDto.setBoxType2(orderDetl.getBoxType2());
                        locDto.setBoxType3(orderDetl.getBoxType3());
                        locDto.setUnit(orderDetl.getUnit());
                        locDto.setInitialAnfme(locDetl.getAnfme());//原托盘数量
                        locDto.setInitialWeight(locDetl.getWeight());//原托盘辅数量
                        //计算辅单位
                        Double weight = MatUtils.calcWeight(locDto.getMatnr(), locDto.getAnfme());
@@ -197,7 +286,62 @@
                    locDtos.add(locDto);
                }
            }
            // 重新计算出库站点,可能存在一个托盘多条明细,多条明细统计下来可全板出库,但实际给出的站点只能拣选出库
            HashMap<String, Double> locAnfmeMap = new HashMap<>();
            for (LocDto locDto : locDtos) {
                if(locAnfmeMap.containsKey(locDto.getLocNo())) {
                    Double anfme = locAnfmeMap.get(locDto.getLocNo());
                    BigDecimal decimal = BigDecimal.valueOf(locDto.getAnfme()).add(BigDecimal.valueOf(anfme));
                    locAnfmeMap.put(locDto.getLocNo(), decimal.doubleValue());
                }else {
                    locAnfmeMap.put(locDto.getLocNo(), locDto.getAnfme());
                }
            }
            HashMap<String, List<Integer>> locStaNosMap = new HashMap<>();
            for (Map.Entry<String, Double> entry : locAnfmeMap.entrySet()) {
                String locNo = entry.getKey();
                Double realAnfme = entry.getValue();
                double stockAnfme = 0D;
                List<LocDetl> locDetls = locDetlService.selectList(new EntityWrapper<LocDetl>().eq("loc_no", locNo));
                for (LocDetl locDetl : locDetls) {
                    BigDecimal decimal = BigDecimal.valueOf(stockAnfme).add(BigDecimal.valueOf(locDetl.getAnfme()));
                    stockAnfme = decimal.doubleValue();
                }
                int ioType = 103;
                if(stockAnfme == realAnfme) {
                    ioType = 101;
                }
                List<Integer> staNos = staDescService.queryOutStaNosByLocNo(locNo, ioType);
                User user = null;
                try {
                    user = getUser();
                } catch (Exception e) {
                }
                if(user != null) {
                    Integer defaultOutSta = user.getDefaultOutSta();
                    if(defaultOutSta != null) {
                        if (staNos.contains(defaultOutSta)) {
                            staNos.remove(defaultOutSta);
                            staNos.add(0, defaultOutSta);
                        }
                    }
                }
                locStaNosMap.put(locNo, staNos);
            }
            for (LocDto locDto : locDtos) {
                List<Integer> staNos = locStaNosMap.get(locDto.getLocNo());
                locDto.setStaNos(staNos);
            }
        }
        return R.ok().add(locDtos);
    }