瀏覽代碼

防止重复刷新

liujunchi 2 年之前
父節點
當前提交
85ed1291d4

+ 1 - 1
cooleshow-mall/mall-portal/src/main/java/com/yonge/cooleshow/portal/controller/OmsPortalOrderController.java

@@ -233,7 +233,7 @@ public class OmsPortalOrderController {
     @ApiOperation("用户刷新物流信息")
     @GetMapping(value = "/refreshCourier")
     @ResponseBody
-    public CommonResult refreshCourier(@RequestParam String  deliverySn) {
+    public CommonResult refreshCourier(@RequestParam String  deliverySn) throws InterruptedException {
         orderCourierService.refreshCourier(deliverySn);
         return CommonResult.success(null);
     }

+ 1 - 1
cooleshow-mall/mall-portal/src/main/java/com/yonge/cooleshow/portal/service/OmsOrderCourierService.java

@@ -25,5 +25,5 @@ public interface OmsOrderCourierService {
      * 刷新物流信息
      */
     @Transactional
-    void refreshCourier(String deliverySn);
+    void refreshCourier(String deliverySn) throws InterruptedException;
 }

+ 8 - 7
cooleshow-mall/mall-portal/src/main/java/com/yonge/cooleshow/portal/service/impl/OmsOrderCourierServiceImpl.java

@@ -45,13 +45,14 @@ public class OmsOrderCourierServiceImpl implements OmsOrderCourierService {
     }
 
     @Override
-    public void refreshCourier(String deliverySn) {
+    public void refreshCourier(String deliverySn) throws InterruptedException {
         RLock lock = redissonClient.getLock(OrderCacheEnum.COURIER_LOCK.getCode());
-        lock.lock(1, TimeUnit.HOURS);
-        OmsOrderCourier omsOrderCourier = omsOrderCourierMapper.queryByCourierNo(deliverySn);
-        CourierInfo courierInfo = courierService.queryTrack(CompanyEnum.valueOf(omsOrderCourier.getCompany()),
-                                                            omsOrderCourier.getCourierNo());
-        updateCourierInfo(courierInfo);
-
+        boolean b = lock.tryLock(1, TimeUnit.HOURS);
+        if (b) {
+            OmsOrderCourier omsOrderCourier = omsOrderCourierMapper.queryByCourierNo(deliverySn);
+            CourierInfo courierInfo = courierService.queryTrack(CompanyEnum.valueOf(omsOrderCourier.getCompany()),
+                                                                omsOrderCourier.getCourierNo());
+            updateCourierInfo(courierInfo);
+        }
     }
 }