| | |
| | | /** |
| | | * 每天17点,定时分配订单库位(查询前一天17点到今天17点支付完成且未分配库位的订单) |
| | | */ |
| | | @Scheduled(cron = "0 0 17 * * ?") |
| | | @Scheduled(cron = "0 35 15 * * ?") |
| | | public void allocatedWarehouseLocation() { |
| | | log.info("定时分配订单库位开始:" + DateFormatUtils.format(System.currentTimeMillis(), "yyyy-MM-dd HH:mm:ss")); |
| | | //查询当日待分配的订单 |
| | | List<Order> orders = orderService.selectPaymentOrderList(); |
| | | if(orders!=null && orders.size()>0){ |
| | | //订单按照合伙人分组排序 |
| | | Map<Long,List<String>> partnerOrders = new HashMap<>(); |
| | | List<String> customerOrders = new ArrayList<>(); |
| | | Map<Long,List<Order>> partnerOrders = new HashMap<>(); |
| | | List<Order> customerOrders = new ArrayList<>(); |
| | | for (Order order : orders) { |
| | | Long partnerId = order.getPartnerId(); |
| | | if(partnerId==null || partnerId==0){ //非合伙人订单 |
| | | customerOrders.add(order.getId()); |
| | | customerOrders.add(order); |
| | | }else{ //合伙人订单 |
| | | if(partnerOrders.containsKey(partnerId)){ |
| | | partnerOrders.get(partnerId).add(order.getId()); |
| | | partnerOrders.get(partnerId).add(order); |
| | | }else{ |
| | | List<String> orderIds = new ArrayList<>(); |
| | | orderIds.add(order.getId()); |
| | | List<Order> orderIds = new ArrayList<>(); |
| | | orderIds.add(order); |
| | | partnerOrders.put(partnerId,orderIds); |
| | | } |
| | | } |
| | |
| | | //查询库位队列信息 |
| | | Queue<WarehouseLocationDTO> locations = warehouseService.selectAllocatedWarehouseLocation(); |
| | | if(locations!=null && locations.size()>0){ |
| | | Map<String, WarehouseLocationDTO> partnerLocationMap = new HashMap<>(); |
| | | if(partnerOrders!=null && partnerOrders.size()>0 ){ //合伙人订单 |
| | | for (Long partnerId : partnerOrders.keySet()) { |
| | | List<String> orderIds = partnerOrders.get(partnerId); |
| | | for (String orderId : orderIds) { |
| | | List<Order> orderIds = partnerOrders.get(partnerId); |
| | | for (Order order : orderIds) { |
| | | if(locations!=null && locations.size()>0){ |
| | | WarehouseLocationDTO location = locations.poll(); |
| | | orderService.allocatedWarehouseLocation(orderId, location.getWarehouseId(), |
| | | location.getWarehouseName(),location.getId(), location.getCode()); |
| | | String key = order.getCreateBy()+"||"+order.getCustomerAddress(); |
| | | WarehouseLocationDTO location = null; |
| | | if(partnerLocationMap.containsKey(key)){ |
| | | location = partnerLocationMap.get(key); |
| | | } else { |
| | | location = locations.poll(); |
| | | partnerLocationMap.put(key,location); |
| | | } |
| | | orderService.allocatedWarehouseLocation(order.getId(), location.getWarehouseId(), |
| | | location.getWarehouseName(), location.getId(), location.getCode()); |
| | | } |
| | | } |
| | | if(locations!=null && locations.size()>0){ //两个合伙人之间空一个库位 |
| | |
| | | } |
| | | } |
| | | if(customerOrders!=null && customerOrders.size()>0){ //散户订单 |
| | | for (String orderId : customerOrders) { |
| | | for (Order order : customerOrders) { |
| | | Map<String, WarehouseLocationDTO> customerLocationMap = new HashMap<>(); |
| | | if(locations!=null && locations.size()>0){ |
| | | WarehouseLocationDTO location = locations.poll(); |
| | | orderService.allocatedWarehouseLocation(orderId, location.getWarehouseId(), |
| | | String key = order.getCreateBy()+"||"+order.getCustomerAddress(); |
| | | WarehouseLocationDTO location = null; |
| | | if(customerLocationMap.containsKey(key)){ |
| | | location = customerLocationMap.get(key); |
| | | } else { |
| | | location = locations.poll(); |
| | | customerLocationMap.put(key,location); |
| | | } |
| | | orderService.allocatedWarehouseLocation(order.getId(), location.getWarehouseId(), |
| | | location.getWarehouseName(),location.getId(), location.getCode()); |
| | | } |
| | | } |