Эх сурвалжийг харах

添加近3天异常物流数据重新监听

yzc 1 жил өмнө
parent
commit
4030f16493

+ 51 - 3
hx-victoriatourist/src/main/java/com/fjhx/victoriatourist/service/logistics/impl/LogisticsInfosServiceImpl.java

@@ -11,9 +11,11 @@ import com.fjhx.area.utils.CustomizeAreaUtil;
 import com.fjhx.common.constant.SourceConstant;
 import com.fjhx.common.utils.Assert;
 import com.fjhx.kd100.entity.company.po.CompanyInfo;
+import com.fjhx.kd100.entity.config.po.ConfigInfo;
 import com.fjhx.kd100.entity.logistics.po.LogisticsInfo;
 import com.fjhx.kd100.event.Kd100CallbackEvent;
 import com.fjhx.kd100.service.company.CompanyInfoService;
+import com.fjhx.kd100.service.config.ConfigInfoService;
 import com.fjhx.kd100.util.KD100Result;
 import com.fjhx.kd100.util.KD100Util;
 import com.fjhx.purchase.entity.purchase.po.Purchase;
@@ -24,7 +26,6 @@ import com.fjhx.victoriatourist.entity.logistics.po.LogisticsDetails;
 import com.fjhx.victoriatourist.entity.logistics.po.LogisticsInfos;
 import com.fjhx.victoriatourist.entity.logistics.vo.LogisticsInfosVo;
 import com.fjhx.victoriatourist.mapper.logistics.LogisticsInfosMapper;
-import com.fjhx.victoriatourist.service.jd.JdBackDetailsService;
 import com.fjhx.victoriatourist.service.jd.JdBackService;
 import com.fjhx.victoriatourist.service.logistics.LogisticsDetailsService;
 import com.fjhx.victoriatourist.service.logistics.LogisticsInfosService;
@@ -32,9 +33,12 @@ import com.fjhx.victoriatourist.utils.LogisticsConstant;
 import com.ruoyi.common.core.domain.entity.SysDept;
 import com.ruoyi.common.utils.SecurityUtils;
 import com.ruoyi.common.utils.wrapper.IWrapper;
+import com.ruoyi.framework.mybatis.holder.TenantHolder;
 import com.ruoyi.system.service.ISysRoleService;
+import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.context.event.EventListener;
+import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.stereotype.Service;
 
 import java.util.Collections;
@@ -52,6 +56,7 @@ import java.util.stream.Collectors;
  * @author
  * @since 2023-04-17
  */
+@Slf4j
 @Service
 public class LogisticsInfosServiceImpl extends ServiceImpl<LogisticsInfosMapper, LogisticsInfos> implements LogisticsInfosService {
     @Autowired
@@ -63,9 +68,9 @@ public class LogisticsInfosServiceImpl extends ServiceImpl<LogisticsInfosMapper,
     @Autowired
     private JdBackService jdBackService;
     @Autowired
-    private JdBackDetailsService jdBackDetailsService;
-    @Autowired
     private ISysRoleService sysRoleService;
+    @Autowired
+    private ConfigInfoService configInfoService;
 
 
     @Override
@@ -246,4 +251,47 @@ public class LogisticsInfosServiceImpl extends ServiceImpl<LogisticsInfosMapper,
         return baseMapper.getDepts();
     }
 
+    /**
+     * 每天0点刷新近3天的异常物流信息
+     * "0 0/1 * * * ?"
+     */
+    @Scheduled(cron = "0 0 0 * * ?")
+    void updateLast3DayInfo() {
+        String tenantId = "wdly";
+        TenantHolder.setIgnore(true);
+        ConfigInfo configInfo = configInfoService.getOne(q -> q.eq(ConfigInfo::getTenantId, tenantId));
+        if (configInfo == null) {
+            return;
+        }
+        DynamicDataSourceContextHolder.push(SourceConstant.VICTORIATOURIST);
+        IWrapper<LogisticsInfos> wrapper = IWrapper.getWrapper();
+        wrapper.eq(LogisticsInfos::getStatus, -1);
+        wrapper.eq(LogisticsInfos::getIsKd100, 1);
+        wrapper.eq("tenant_id", tenantId);
+        wrapper.apply("DATE_SUB( CURDATE(), INTERVAL 3 DAY )<= create_time");
+        List<LogisticsInfos> list = this.list(wrapper);
+        if (ObjectUtil.isEmpty(list)) {
+            return;
+        }
+        for (LogisticsInfos logisticsInfos : list) {
+            String com = logisticsInfos.getLogisticsCompanyCode();
+            String num = logisticsInfos.getCode();
+            try {
+                KD100Result kd100Result = KD100Util.queryTrack(com, num, configInfo);
+                if (kd100Result.getState() == null || kd100Result.getState() == -1) {
+                    return;
+                }
+                logisticsInfos.setStatus(kd100Result.getState());
+                //重新订阅
+                KD100Util.subscribe(com, num, configInfo);
+                Thread.sleep(2000);
+            } catch (Exception e) {
+                log.error("重新同步异常物流信息出错: com:{}, num:{}, message:{}", com, num, e.getMessage(), e);
+            }
+        }
+        this.updateBatchById(list);
+        DynamicDataSourceContextHolder.clear();
+        TenantHolder.clear();
+    }
+
 }