|
|
@@ -7,10 +7,10 @@ import com.fs.erp.domain.ErpOrderQuery;
|
|
|
import com.fs.erp.dto.ErpOrderQueryRequert;
|
|
|
import com.fs.erp.dto.ErpOrderQueryResponse;
|
|
|
import com.fs.erp.service.FsJstAftersalePushService;
|
|
|
-import com.fs.erp.service.IErpOrderService;
|
|
|
-import com.fs.erp.utils.ErpContextHolder;
|
|
|
+import com.fs.erp.service.impl.JSTErpOrderServiceImpl;
|
|
|
import com.fs.express.FsStoreDeliversService;
|
|
|
import com.fs.common.utils.StringUtils;
|
|
|
+import com.google.common.collect.Lists;
|
|
|
import com.fs.huifuPay.domain.HuiFuQueryOrderResult;
|
|
|
import com.fs.huifuPay.sdk.opps.core.request.V2TradePaymentScanpayQueryRequest;
|
|
|
import com.fs.live.domain.LiveOrderPayment;
|
|
|
@@ -30,7 +30,6 @@ import com.fs.store.mapper.*;
|
|
|
import com.fs.store.param.LiveAfterSalesAudit1Param;
|
|
|
import com.fs.store.service.*;
|
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
|
-import org.apache.commons.lang.ObjectUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
@@ -39,6 +38,7 @@ import org.springframework.stereotype.Component;
|
|
|
|
|
|
import java.text.ParseException;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
@@ -52,6 +52,9 @@ import static com.fs.live.utils.redis.RedisBatchHandler.CONSUME_INTERVAL;
|
|
|
public class LiveTask {
|
|
|
Logger logger = LoggerFactory.getLogger(LiveTask.class);
|
|
|
|
|
|
+ /** 聚水潭发货查询每批 o_id 数量 */
|
|
|
+ private static final int DELIVERY_QUERY_BATCH_SIZE = 30;
|
|
|
+ private static final String JST_SHOP_ID = "18675245";
|
|
|
|
|
|
@Autowired
|
|
|
private ILiveOrderService liveOrderService;
|
|
|
@@ -67,8 +70,7 @@ public class LiveTask {
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
- private IErpOrderService erpOrderService;
|
|
|
-
|
|
|
+ private JSTErpOrderServiceImpl jstErpOrderService;
|
|
|
|
|
|
@Autowired
|
|
|
private IFsExpressService expressService;
|
|
|
@@ -77,10 +79,6 @@ public class LiveTask {
|
|
|
@Autowired
|
|
|
private ILiveOrderLogsService orderLogsService;
|
|
|
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private FsWarehousesMapper fsWarehousesMapper;
|
|
|
-
|
|
|
@Autowired
|
|
|
public FsJstAftersalePushService fsJstAftersalePushService;
|
|
|
@Autowired
|
|
|
@@ -166,57 +164,86 @@ public class LiveTask {
|
|
|
* 发货任务
|
|
|
*/
|
|
|
@QuartzRunnable(name = "发货任务")
|
|
|
- public void deliveryOp() {
|
|
|
+ public void deliveryOp() throws InterruptedException {
|
|
|
List<LiveOrder> list = liveOrderService.selectDeliverPenddingData();
|
|
|
|
|
|
- for (LiveOrder order : list) {
|
|
|
- String orderCode = order.getOrderCode();
|
|
|
- ErpOrderQueryRequert request = new ErpOrderQueryRequert();
|
|
|
- request.setCode(order.getExtendOrderId());
|
|
|
-
|
|
|
- try {
|
|
|
- // 根据仓库code找erp
|
|
|
- if (com.fs.common.utils.StringUtils.isNotBlank(order.getStoreHouseCode())) {
|
|
|
- String erp = fsWarehousesMapper.selectErpByCode(order.getStoreHouseCode());
|
|
|
- ErpContextHolder.setErpType(erp);
|
|
|
- }
|
|
|
- ErpOrderQueryResponse response = erpOrderService.getOrderLive(request);
|
|
|
- if (CollectionUtils.isNotEmpty(response.getOrders())) {
|
|
|
- for (ErpOrderQuery orderQuery : response.getOrders()) {
|
|
|
- if (CollectionUtils.isNotEmpty(orderQuery.getDeliverys())) {
|
|
|
- // 部分发货或者全部发货
|
|
|
- if (ObjectUtils.equals(orderQuery.getDelivery_state(), 1) || ObjectUtils.equals(orderQuery.getDelivery_state(), 2)) {
|
|
|
-
|
|
|
- orderLogsService.create(order.getOrderId(), OrderLogEnum.DELIVERY_GOODS.getValue(),
|
|
|
- OrderLogEnum.DELIVERY_GOODS.getDesc());
|
|
|
+ ArrayList<Long> oIds = new ArrayList<>();
|
|
|
+ for (LiveOrder liveOrder : list) {
|
|
|
+ if (StringUtils.isNotEmpty(liveOrder.getExtendOrderId())) {
|
|
|
+ oIds.add(Long.parseLong(liveOrder.getExtendOrderId()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!CollectionUtils.isEmpty(oIds)) {
|
|
|
+ jstErpOrderDelivery(oIds);
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- for (ErpDeliverys delivery : orderQuery.getDeliverys()) {
|
|
|
+ private void jstErpOrderDelivery(List<Long> oIds) throws InterruptedException {
|
|
|
+ if (CollectionUtils.isEmpty(oIds)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
- FsExpress express = expressService.selectFsExpressByOmsCode(delivery.getExpress_code());
|
|
|
+ List<List<Long>> batches = Lists.partition(oIds, DELIVERY_QUERY_BATCH_SIZE);
|
|
|
+ for (List<Long> batch : batches) {
|
|
|
+ List<String> extendIds = new ArrayList<>();
|
|
|
+ for (Long oId : batch) {
|
|
|
+ extendIds.add(oId.toString());
|
|
|
+ }
|
|
|
+ int pageIndex = 1;
|
|
|
+ boolean hasNext;
|
|
|
+ do {
|
|
|
+ Thread.sleep(300);
|
|
|
+ ErpOrderQueryRequert request = new ErpOrderQueryRequert();
|
|
|
+ request.setPage_size(100);
|
|
|
+ request.setPage_index(pageIndex);
|
|
|
+ request.setShop_id(JST_SHOP_ID);
|
|
|
+ request.setO_ids(batch);
|
|
|
+
|
|
|
+ ErpOrderQueryResponse response = jstErpOrderService.getOrderLive(request);
|
|
|
+ hasNext = response.hasNextSafe();
|
|
|
+ liveOrderService.updateUpdateTimeByExtendIds(extendIds);
|
|
|
+
|
|
|
+ if (response.getOrders() != null) {
|
|
|
+ for (ErpOrderQuery orderQuery : response.getOrders()) {
|
|
|
+ if (orderQuery.getDeliverys() == null || orderQuery.getDeliverys().isEmpty()) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ for (ErpDeliverys delivery : orderQuery.getDeliverys()) {
|
|
|
+ if (!delivery.getDelivery() || org.apache.commons.lang3.StringUtils.isEmpty(delivery.getMail_no())) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ LiveOrder liveOrder = liveOrderService.selectLiveOrderByOrderCode(orderQuery.getCode());
|
|
|
+ if (liveOrder == null) {
|
|
|
+ logger.warn("直播发货任务未找到订单 orderCode={}", orderQuery.getCode());
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ orderLogsService.create(liveOrder.getOrderId(), OrderLogEnum.DELIVERY_GOODS.getValue(),
|
|
|
+ OrderLogEnum.DELIVERY_GOODS.getDesc());
|
|
|
+ try {
|
|
|
+ for (ErpDeliverys deli : orderQuery.getDeliverys()) {
|
|
|
+ FsExpress express = expressService.selectFsExpressByOmsCode(deli.getExpress_code());
|
|
|
if (express == null) {
|
|
|
- logger.warn("当前express_code: {} 不存在!", delivery.getExpress_code());
|
|
|
+ logger.error("当前express_code: {} 不存在!", deli.getExpress_code());
|
|
|
continue;
|
|
|
}
|
|
|
-
|
|
|
- if (delivery.getDelivery()) {
|
|
|
- liveOrderService.deliveryOrder(orderCode, delivery.getMail_no(),
|
|
|
- delivery.getExpress_code(), delivery.getExpress_name());
|
|
|
+ if (deli.getDelivery()) {
|
|
|
+ liveOrderService.deliveryOrder(orderQuery.getCode(), deli.getMail_no(),
|
|
|
+ deli.getExpress_code(), deli.getExpress_name());
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- logger.info("订单 {} 发货信息同步成功", order.getOrderCode());
|
|
|
+ logger.info("直播订单 {} 发货信息同步成功", orderQuery.getCode());
|
|
|
+ } catch (Exception e) {
|
|
|
+ logger.error("同步直播订单发货状态失败 orderCode={} mailNo={}",
|
|
|
+ orderQuery.getCode(), delivery.getMail_no(), e);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- } catch (Exception e) {
|
|
|
- logger.error(String.format("[发货任务]调用erp查询接口失败!原因: %s", e));
|
|
|
- }
|
|
|
-
|
|
|
+ pageIndex++;
|
|
|
+ } while (hasNext);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
/**
|
|
|
* 同步近三天直播订单关联的APP用户数据
|
|
|
*/
|