瀏覽代碼

FIX: 推送微信物流状态

xdd 1 周之前
父節點
當前提交
ef31b78f07

+ 3 - 0
fs-service-system/src/main/java/com/fs/live/mapper/LiveOrderPaymentMapper.java

@@ -79,4 +79,7 @@ public interface LiveOrderPaymentMapper {
 
     @Select("select * from live_order_payment where business_id= #{orderId}")
     List<LiveOrderPayment> selectLiveOrderPaymentByOrderId(@Param("orderId") Long orderId);
+
+    @Select("select * from live_order_payment where business_id= #{orderId} and status=1 order by create_time desc limit 1")
+    LiveOrderPayment selectLiveOrderLatestPayByOrderId(@Param("orderId") Long orderId);
 }

+ 31 - 0
fs-service-system/src/main/java/com/fs/store/service/ExpressToWxHolder.java

@@ -0,0 +1,31 @@
+package com.fs.store.service;
+
+import com.fs.store.service.channel.PaymentHandler;
+import com.fs.store.service.channel.PaymentHandlerHolder;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.ApplicationContext;
+import org.springframework.stereotype.Service;
+
+@Slf4j
+@Service
+public class ExpressToWxHolder {
+    private static ApplicationContext applicationContext;
+
+    @Autowired
+    public void setApplicationContext(ApplicationContext applicationContext) {
+        ExpressToWxHolder.applicationContext = applicationContext;
+    }
+
+    public static ExpressToWxService findBest(Integer type) {
+        String[] beanNames = applicationContext.getBeanNamesForType(ExpressToWxService.class);
+
+        for (String beanName : beanNames) {
+            ExpressToWxService handler = (ExpressToWxService) applicationContext.getBean(beanName);
+            if (handler.support(type)) {
+                return handler;
+            }
+        }
+        return null;
+    }
+}

+ 24 - 0
fs-service-system/src/main/java/com/fs/store/service/ExpressToWxService.java

@@ -0,0 +1,24 @@
+package com.fs.store.service;
+
+import lombok.Getter;
+
+@Getter
+public abstract class ExpressToWxService {
+
+    private String orderCode;
+
+    public void setOrderCode(String orderCode) {
+        this.orderCode = orderCode;
+    }
+
+    public abstract String getTransactionId();
+
+
+    public abstract String getUserPhone();
+
+
+    public abstract String getOrderGoodsInfo();
+
+
+    public abstract boolean support(Integer type);
+}

+ 12 - 47
fs-service-system/src/main/java/com/fs/store/service/impl/FsStoreOrderServiceImpl.java

@@ -56,6 +56,8 @@ import com.fs.huifuPay.domain.HuiFuCreateOrder;
 import com.fs.huifuPay.domain.HuifuCreateOrderResult;
 import com.fs.huifuPay.dto.*;
 import com.fs.huifuPay.service.HuiFuService;
+import com.fs.live.mapper.LiveOrderMapper;
+import com.fs.live.mapper.LiveOrderPaymentMapper;
 import com.fs.pay.pay.domain.CreateWxOrderResult;
 import com.fs.pay.pay.domain.RefundResult;
 import com.fs.pay.pay.dto.OrderQueryDTO;
@@ -261,9 +263,6 @@ public class FsStoreOrderServiceImpl implements IFsStoreOrderService
     @Autowired
     private ShippingService shippingService;
 
-    @Autowired
-    private OrderQueryService orderQueryService;
-
     @Autowired
     private FsWarehousesMapper fsWarehousesMapper;
 
@@ -273,12 +272,6 @@ public class FsStoreOrderServiceImpl implements IFsStoreOrderService
     @Autowired
     private FsUserMapper fsUserMapper;
 
-    @Value("${snowflake.worker-id:1}")
-    private long workerId;
-
-    @Value("${snowflake.datacenter-id:1}")
-    private long datacenterId;
-
 
     @Override
     public void syncExpressToWx() {
@@ -297,26 +290,21 @@ public class FsStoreOrderServiceImpl implements IFsStoreOrderService
               orderKey.setOrderNumberType(2);
 
 
+
               FsUser fsUser = fsUserMapper.selectFsUserById(fsWxExpressTask.getUserId());
-              FsStoreOrder fsStoreOrder = fsStoreOrderMapper.selectFsStoreOrderByOrderCode(fsWxExpressTask.getOrderCode());
 
+              ExpressToWxService service = ExpressToWxHolder.findBest(fsWxExpressTask.getType());
+              Asserts.notNull(service,"订单类型不被支持!");
+              service.setOrderCode(fsWxExpressTask.getOrderCode());
 
-              if(ObjectUtil.isNotNull(fsStoreOrder)){
-                  List<FsStorePayment> fsStorePayments = paymentService.selectFsStorePaymentByOrder(fsStoreOrder.getId());
 
 
-                  if(CollectionUtils.isNotEmpty(fsStorePayments)){
-                      FsStorePayment fsStorePayment = fsStorePayments.get(0);
-                      orderKey.setTransactionId(fsStorePayment.getBankTransactionId());
-                  }
-              }
+              orderKey.setTransactionId(service.getTransactionId());
+
+
+              String userPhone = service.getUserPhone();
+              String orderGoodsInfo = service.getOrderGoodsInfo();
 
-              String userPhone = "";
-              String orderGoodsInfo = "商品";
-              if(fsStoreOrder != null){
-                  userPhone = fsStoreOrder.getUserPhone();
-                  orderGoodsInfo = getOrderGoodsInfo(fsStoreOrder);
-              }
 
               Payer payer = new Payer();
               if(StringUtils.isNotBlank(fsUser.getMaOpenId())){
@@ -363,30 +351,7 @@ public class FsStoreOrderServiceImpl implements IFsStoreOrderService
 
     }
 
-    /**
-     * 获取订单商品信息
-     * @return
-     */
-    private String getOrderGoodsInfo(FsStoreOrder order){
-        StringBuilder title = new StringBuilder();
-        // 如果是套餐
-        if(ObjectUtil.equal(order.getIsPackage(),1)){
-            String packageJson = order.getPackageJson();
-            JSONObject jsonObject = JSON.parseObject(packageJson);
-            title = new StringBuilder(jsonObject.getString("title"));
-        } else {
-            String itemJson = order.getItemJson();
-            com.alibaba.fastjson.JSONArray arrays = JSON.parseArray(itemJson);
-            for(int i=0;i<arrays.size();i++){
-                JSONObject jsonObject = arrays.getJSONObject(i);
-                String jsonInfo = jsonObject.getString("jsonInfo");
-                JSONObject jsonObject1 = JSON.parseObject(jsonInfo);
-                String productName = jsonObject1.getString("productName");
-                title.append(productName).append("\n");
-            }
-        }
-        return title.toString();
-    }
+
 
     /**
      * 查询订单

+ 77 - 0
fs-service-system/src/main/java/com/fs/store/service/impl/LiveStreamShopExpressToWxService.java

@@ -0,0 +1,77 @@
+package com.fs.store.service.impl;
+
+import cn.hutool.core.util.ObjectUtil;
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
+import com.fs.live.domain.LiveOrder;
+import com.fs.live.domain.LiveOrderItem;
+import com.fs.live.domain.LiveOrderPayment;
+import com.fs.live.mapper.LiveOrderItemMapper;
+import com.fs.live.mapper.LiveOrderMapper;
+import com.fs.live.mapper.LiveOrderPaymentMapper;
+import com.fs.store.service.ExpressToWxService;
+import org.apache.commons.collections4.CollectionUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Scope;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.PostConstruct;
+import java.util.List;
+
+@Service
+@Scope("SCOPE_PROTOTYPE")
+public class LiveStreamShopExpressToWxService extends ExpressToWxService {
+
+    @Autowired
+    private LiveOrderMapper liveOrderMapper;
+    @Autowired
+    private LiveOrderPaymentMapper liveOrderPaymentMapper;
+    @Autowired
+    private LiveOrderItemMapper liveOrderItemMapper;
+
+    private LiveOrder liveOrder;
+    private LiveOrderPayment liveOrderPayment;
+
+
+
+    @Override
+    public void setOrderCode(String orderCode) {
+        this.liveOrder = liveOrderMapper.selectLiveOrderByOrderCode(getOrderCode());
+        if(ObjectUtil.isNull(this.liveOrder)){
+            throw new IllegalArgumentException(String.format("订单%s未找到!", this.getOrderCode()));
+        }
+        LiveOrderPayment liveOrderPayments = liveOrderPaymentMapper.selectLiveOrderLatestPayByOrderId(liveOrder.getOrderId());
+        if(ObjectUtil.isNotNull(liveOrderPayments)){
+            liveOrderPayment = liveOrderPayments;
+        }
+    }
+
+    @Override
+    public String getTransactionId() {
+        return liveOrderPayment.getBankTransactionId();
+    }
+
+    @Override
+    public String getUserPhone() {
+        return liveOrder.getUserPhone();
+    }
+
+    @Override
+    public String getOrderGoodsInfo() {
+        List<LiveOrderItem> liveOrderItems = liveOrderItemMapper.selectLiveOrderItemByOrderId(liveOrder.getOrderId());
+        StringBuffer sb = new StringBuffer();
+        for (LiveOrderItem liveOrderItem : liveOrderItems) {
+            JSONObject jsonObject = JSON.parseObject(liveOrderItem.getJsonInfo());
+            String productName = jsonObject.getString("productName");
+            sb.append(productName).append("\n");
+        }
+        return sb.toString();
+    }
+
+    @Override
+    public boolean support(Integer type) {
+        return 1==type;
+    }
+
+
+}

+ 91 - 0
fs-service-system/src/main/java/com/fs/store/service/impl/ShopExpressToWxService.java

@@ -0,0 +1,91 @@
+package com.fs.store.service.impl;
+
+import cn.hutool.core.util.ObjectUtil;
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
+import com.fs.store.domain.FsStoreOrder;
+import com.fs.store.domain.FsStorePayment;
+import com.fs.store.mapper.FsStoreOrderMapper;
+import com.fs.store.mapper.FsStorePaymentMapper;
+import com.fs.store.service.ExpressToWxService;
+import org.apache.commons.collections4.CollectionUtils;
+import org.apache.http.util.Asserts;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Scope;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.PostConstruct;
+import java.util.List;
+
+@Service
+@Scope("SCOPE_PROTOTYPE")
+public class ShopExpressToWxService extends ExpressToWxService {
+    @Autowired
+    private FsStoreOrderMapper fsStoreOrderMapper;
+    @Autowired
+    private FsStorePaymentMapper fsStorePaymentMapper;
+
+
+    private FsStoreOrder fsStoreOrder;
+    private FsStorePayment fsStorePayment;
+
+    @Override
+    public void setOrderCode(String orderCode) {
+        this.fsStoreOrder = fsStoreOrderMapper.selectFsStoreOrderByOrderCode(getOrderCode());
+        if(ObjectUtil.isNull(fsStoreOrder)) {
+            throw new IllegalArgumentException(String.format("该订单 %s 未找到!",getOrderCode()));
+        }
+        List<FsStorePayment> fsStorePayments = fsStorePaymentMapper.selectFsStorePaymentByOrderId(fsStoreOrder.getId());
+        if(CollectionUtils.isEmpty(fsStorePayments)){
+            throw new IllegalArgumentException(String.format("该订单 %s 未找到对应支付记录!", getOrderCode()));
+        }
+        fsStorePayment = fsStorePayments.get(0);
+    }
+
+
+    @Override
+    public String getTransactionId() {
+        return fsStorePayment.getBankTransactionId();
+    }
+
+    @Override
+    public String getUserPhone() {
+        return fsStoreOrder.getUserPhone();
+    }
+
+    @Override
+    public String getOrderGoodsInfo() {
+        return getOrderGoodsInfo(fsStoreOrder);
+    }
+
+    @Override
+    public boolean support(Integer type) {
+        return 0 == type;
+    }
+
+
+    /**
+     * 获取订单商品信息
+     * @return
+     */
+    private String getOrderGoodsInfo(FsStoreOrder order){
+        StringBuilder title = new StringBuilder();
+        // 如果是套餐
+        if(ObjectUtil.equal(order.getIsPackage(),1)){
+            String packageJson = order.getPackageJson();
+            JSONObject jsonObject = JSON.parseObject(packageJson);
+            title = new StringBuilder(jsonObject.getString("title"));
+        } else {
+            String itemJson = order.getItemJson();
+            com.alibaba.fastjson.JSONArray arrays = JSON.parseArray(itemJson);
+            for(int i=0;i<arrays.size();i++){
+                JSONObject jsonObject = arrays.getJSONObject(i);
+                String jsonInfo = jsonObject.getString("jsonInfo");
+                JSONObject jsonObject1 = JSON.parseObject(jsonInfo);
+                String productName = jsonObject1.getString("productName");
+                title.append(productName).append("\n");
+            }
+        }
+        return title.toString();
+    }
+}

+ 2 - 0
fs-service-system/src/main/java/com/fs/wx/domain/FsWxExpressTask.java

@@ -93,4 +93,6 @@ public class FsWxExpressTask {
      * 快递编号
      */
     private String expressNo;
+
+    private Integer type;
 }