24282 1 ano atrás
pai
commit
39a82e4679

+ 40 - 0
sd-starter/src/main/resources/application-prod.yml

@@ -37,6 +37,46 @@ spring:
         # #连接池最大阻塞等待时间(使用负值表示没有限制)
         max-wait: -1ms
 
+
+## 数据源配置
+#spring:
+#  datasource:
+#    dynamic:
+#      strict: true
+#      primary: base
+#      datasource:
+#        base:
+#          url: jdbc:mysql://110.41.2.116:23063/sd_base?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=Asia/Shanghai
+#          username: sd_prod
+#          password: lG0-nX8#rJ4#jT5
+#        business:
+#          url: jdbc:mysql://110.41.2.116:23063/sd_business?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=Asia/Shanghai
+#          username: sd_prod
+#          password: lG0-nX8#rJ4#jT5
+#
+#  # redis 配置
+#  redis:
+#    # 地址
+#    host: 121.37.194.75
+#    # 端口,默认为6379
+#    port: 30103
+#    # 数据库索引
+#    database: 3
+#    # 密码
+#    password: Fjhx@pwd123
+#    # 连接超时时间
+#    timeout: 10s
+#    lettuce:
+#      pool:
+#        # 连接池中的最小空闲连接
+#        min-idle: 0
+#        # 连接池中的最大空闲连接
+#        max-idle: 8
+#        # 连接池的最大数据库连接数
+#        max-active: 8
+#        # #连接池最大阻塞等待时间(使用负值表示没有限制)
+#        max-wait: -1ms
+
 server:
   servlet:
     context-path: /prod-api

+ 11 - 44
sd-wln/src/main/java/com/sd/wln/context/OrderContext.java

@@ -20,8 +20,8 @@ import com.sd.business.service.order.OrderSkuService;
 import com.sd.business.service.price.PriceBillingStandardDetailService;
 import com.sd.business.service.sku.SkuSpecLinkService;
 import com.sd.business.service.sku.SkuSpecService;
-import com.sd.wln.util.WlnUtil;
 import lombok.Getter;
+import lombok.Setter;
 import lombok.extern.slf4j.Slf4j;
 
 import java.util.*;
@@ -72,13 +72,20 @@ public class OrderContext {
      * 当前时间
      */
     @Getter
-    private final Date endDate;
+    public final Date endDate;
+
+    /**
+     * 仓库编码
+     */
+    @Getter
+    public final String warehouseCode;
 
     /**
      * 万里牛订单列表
      */
     @Getter
-    private final List<JSONObject> wlnOrderList;
+    @Setter
+    private List<JSONObject> wlnOrderList;
 
     /**
      * 事业部
@@ -131,51 +138,11 @@ public class OrderContext {
      */
     public OrderContext(String warehouseCode) {
         this.endDate = new Date();
-        this.wlnOrderList = selectWlnOrderList(warehouseCode);
+        this.warehouseCode = warehouseCode;
         this.department = departmentService.getDepartmentByWarehouseCode(warehouseCode);
     }
 
     /**
-     * 查询万里牛订单列表
-     */
-    private List<JSONObject> selectWlnOrderList(String warehouseCode) {
-
-        long endTime = endDate.getTime();
-        long startTime;
-
-        OrderInfo orderInfo = orderService.getOne(q -> q
-                .eq(OrderInfo::getWlnStorageCode, warehouseCode)
-                .orderByDesc(OrderInfo::getWlnModifyTimestamp));
-
-        if (orderInfo == null) {
-            startTime = endTime - 1000 * 60 * 60 * 24;
-        } else {
-            startTime = orderInfo.getWlnModifyTimestamp();
-            if (endTime - startTime > 1000 * 60 * 60 * 24 * 7) {
-                startTime = endTime - 1000 * 60 * 60 * 24 * 7;
-            }
-        }
-
-        List<JSONObject> list = new ArrayList<>();
-
-        int page = 1;
-        int size;
-        do {
-            try {
-                List<JSONObject> itemList = WlnUtil.getOrderList(page, 200, startTime, endTime, warehouseCode);
-                page++;
-                size = itemList.size();
-                list.addAll(itemList);
-            } catch (Exception e) {
-                log.error("订单同步失败", e);
-                return Collections.emptyList();
-            }
-        } while (size >= 200);
-
-        return list;
-    }
-
-    /**
      * 获取已存在数据库中的订单map
      */
     public Map<String, OrderInfo> getExistOrderMap() {

+ 2 - 0
sd-wln/src/main/java/com/sd/wln/service/impl/OrderHandleServiceImpl.java

@@ -16,6 +16,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
+import java.util.Collections;
 import java.util.Objects;
 
 @Slf4j
@@ -53,6 +54,7 @@ public class OrderHandleServiceImpl implements OrderHandleService {
 
         String storageCode = wlnOrder.getString("storage_code");
         OrderContext context = new OrderContext(storageCode);
+        context.setWlnOrderList(Collections.singletonList(wlnOrder));
         OrderInfo order = wlnOrderService.createOrder(context, wlnOrder);
         wlnOrderService.addOrder(context, wlnOrder, order);
         wlnOrderService.saveOrUpdateOrder(context);

+ 44 - 0
sd-wln/src/main/java/com/sd/wln/service/impl/WlnOrderServiceImpl.java

@@ -7,6 +7,7 @@ import com.baomidou.mybatisplus.core.toolkit.IdWorker;
 import com.fjhx.tenant.entity.dict.po.DictCommonData;
 import com.fjhx.tenant.service.dict.DictCommonDataService;
 import com.ruoyi.common.constant.StatusConstant;
+import com.ruoyi.common.exception.ServiceException;
 import com.sd.business.entity.bom.bo.BomSpecBo;
 import com.sd.business.entity.department.po.Department;
 import com.sd.business.entity.order.enums.OrderExceptionTypeEnum;
@@ -24,6 +25,7 @@ import com.sd.business.service.order.OrderSkuBomService;
 import com.sd.business.service.order.OrderSkuService;
 import com.sd.wln.context.OrderContext;
 import com.sd.wln.service.WlnOrderService;
+import com.sd.wln.util.WlnUtil;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
@@ -71,6 +73,7 @@ public class WlnOrderServiceImpl implements WlnOrderService {
 
         for (DictCommonData dictCommonData : warehouseCodeList) {
             OrderContext context = new OrderContext(dictCommonData.getDictValue());
+            setWlnOrderList(context);
 
             // 万里牛订单若为0,结束同步任务
             List<JSONObject> wlnOrderList = context.getWlnOrderList();
@@ -532,4 +535,45 @@ public class WlnOrderServiceImpl implements WlnOrderService {
 
     }
 
+    /**
+     * 查询万里牛订单列表
+     */
+    private void setWlnOrderList(OrderContext context) {
+        String warehouseCode = context.getWarehouseCode();
+        long endTime = context.getEndDate().getTime();
+        long startTime;
+
+        OrderInfo orderInfo = orderService.getOne(q -> q
+                .eq(OrderInfo::getWlnStorageCode, warehouseCode)
+                .orderByDesc(OrderInfo::getWlnModifyTimestamp));
+
+        if (orderInfo == null) {
+            startTime = endTime - 1000 * 60 * 60 * 24;
+        } else {
+            startTime = orderInfo.getWlnModifyTimestamp();
+            if (endTime - startTime > 1000 * 60 * 60 * 24 * 7) {
+                startTime = endTime - 1000 * 60 * 60 * 24 * 7;
+            }
+        }
+
+        List<JSONObject> list = new ArrayList<>();
+
+        int page = 1;
+        int size;
+        do {
+            try {
+                List<JSONObject> itemList = WlnUtil.getOrderList(page, 200, startTime, endTime, warehouseCode);
+                page++;
+                size = itemList.size();
+                list.addAll(itemList);
+            } catch (Exception e) {
+                log.error("订单同步失败", e);
+                context.setWlnOrderList(Collections.emptyList());
+                throw new ServiceException("订单同步失败");
+            }
+        } while (size >= 200);
+
+        context.setWlnOrderList(list);
+    }
+
 }