diff --git a/mallinkSchedule/src/main/java/com/iformall/schedule/TtMerchantPoiSchedule.java b/mallinkSchedule/src/main/java/com/iformall/schedule/TtMerchantPoiSchedule.java index 159c89a25..aa30f3ba9 100644 --- a/mallinkSchedule/src/main/java/com/iformall/schedule/TtMerchantPoiSchedule.java +++ b/mallinkSchedule/src/main/java/com/iformall/schedule/TtMerchantPoiSchedule.java @@ -1,40 +1,58 @@ -package com.iformall.schedule; - -import com.iformall.domain.po.*; -import com.iformall.enums.EnumSupplierMathStatus; -import com.iformall.service.TtMerchantPoiService; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.scheduling.annotation.Async; -import org.springframework.scheduling.annotation.Scheduled; -import org.springframework.stereotype.Component; - -import java.util.List; - -@Component -public class TtMerchantPoiSchedule { - - private final Logger logger = LoggerFactory.getLogger(this.getClass()); - - @Autowired - private TtMerchantPoiService ttMerchantPoiService; - - @Async - @Scheduled(cron = "0 0 */1 * * *?") // 每小时检查一次 - public void merchantCountSchedule() { - TtMerchantPoi merchantPoiQ = new TtMerchantPoi(); - merchantPoiQ.setMatchStatus(EnumSupplierMathStatus.match_ing.getCode()); - List pois = ttMerchantPoiService.findTaskIdList(merchantPoiQ); - if(pois != null && pois.size() > 0){ - for (TtMerchantPoi poi:pois) { - try{ - ttMerchantPoiService.supplierQueryTask(poi); - }catch(Exception e){ - logger.error("查询匹配任务失败"); - } - } - } - } - -} \ No newline at end of file +//package com.iformall.schedule; +// +//import com.iformall.domain.po.*; +//import com.iformall.enums.EnumSupplierMathStatus; +//import com.iformall.enums.EnumSupplierSyncStatus; +//import com.iformall.service.TtMerchantPoiService; +//import org.slf4j.Logger; +//import org.slf4j.LoggerFactory; +//import org.springframework.beans.factory.annotation.Autowired; +//import org.springframework.scheduling.annotation.Async; +//import org.springframework.scheduling.annotation.Scheduled; +//import org.springframework.stereotype.Component; +// +//import java.util.List; +// +//@Component +//public class TtMerchantPoiSchedule { +// +// private final Logger logger = LoggerFactory.getLogger(this.getClass()); +// +// @Autowired +// private TtMerchantPoiService ttMerchantPoiService; +// +// @Async +// @Scheduled(cron = "0 0 */1 * * *?") // 每小时检查一次 +// public void supplierQueryTaskSchedule() { +// TtMerchantPoi merchantPoiQ = new TtMerchantPoi(); +// merchantPoiQ.setMatchStatus(EnumSupplierMathStatus.match_ing.getCode()); +// List pois = ttMerchantPoiService.findTaskIdList(merchantPoiQ); +// if(pois != null && pois.size() > 0){ +// for (TtMerchantPoi poi:pois) { +// try{ +// ttMerchantPoiService.supplierQueryTask(poi); +// }catch(Exception e){ +// logger.error("查询匹配任务失败"); +// } +// } +// } +// } +// +// @Async +// @Scheduled(cron = "0 0 */1 * * *?") // 每小时检查一次 +// public void supplierQuerySchedule() { +// TtMerchantPoi merchantPoiQ = new TtMerchantPoi(); +// merchantPoiQ.setLastSyncStatus(EnumSupplierSyncStatus.sync_wait.getCode()); +// List ids = ttMerchantPoiService.findIdList(merchantPoiQ); +// if(ids != null && ids.size() > 0){ +// for (Long id:ids) { +// try{ +// ttMerchantPoiService.supplierQuery(id); +// }catch(Exception e){ +// logger.error("查询匹配任务失败"); +// } +// } +// } +// } +// +//} \ No newline at end of file diff --git a/mallinkService/src/main/java/com/iformall/douyin/web/api/TtWebProductService.java b/mallinkService/src/main/java/com/iformall/douyin/web/api/TtWebProductService.java index 56d8b6b1f..da18d0ee3 100644 --- a/mallinkService/src/main/java/com/iformall/douyin/web/api/TtWebProductService.java +++ b/mallinkService/src/main/java/com/iformall/douyin/web/api/TtWebProductService.java @@ -55,7 +55,7 @@ public interface TtWebProductService { * https://open.douyin.com/platform/doc?doc=docs/openapi/life-service-open-ability/shop/search * * @param supplierExtId - * supplier_ext_id 第三方上传任务id列表,多个任务id用 , 分割,单次查询最多10个任务。 + * supplier_ext_id */ TtSupplierSyncQuery supplierQuery(String supplierExtId) throws WxErrorException ; diff --git a/mallinkService/src/main/java/com/iformall/enums/EnumSupplierSyncStatus.java b/mallinkService/src/main/java/com/iformall/enums/EnumSupplierSyncStatus.java index 327447c23..6798a4c25 100644 --- a/mallinkService/src/main/java/com/iformall/enums/EnumSupplierSyncStatus.java +++ b/mallinkService/src/main/java/com/iformall/enums/EnumSupplierSyncStatus.java @@ -5,10 +5,10 @@ package com.iformall.enums; */ public enum EnumSupplierSyncStatus { // 最近一次同步状态, 0 - 未处理; 1 - 通过; 2 - 未通过 -// match_update(-1, "等待重新同步"), - match_wait(0, " 未处理"), - match_success(1, "通过"), - match_fail(2, "未通过"), +// sync_update(-1, "等待重新同步"), + sync_wait(0, " 未处理"), + sync_success(1, "通过"), + sync_fail(2, "未通过"), ; public static EnumSupplierSyncStatus getEnum(Integer code) { diff --git a/mallinkService/src/main/java/com/iformall/service/TtMerchantPoiService.java b/mallinkService/src/main/java/com/iformall/service/TtMerchantPoiService.java index 52613a933..ec032bd42 100644 --- a/mallinkService/src/main/java/com/iformall/service/TtMerchantPoiService.java +++ b/mallinkService/src/main/java/com/iformall/service/TtMerchantPoiService.java @@ -37,6 +37,10 @@ public interface TtMerchantPoiService { ResultData merchantSync(TenantEntity tenantInfo, Long id); + List findIdList(TtMerchantPoi merchantPoiQ); + + void supplierQuery(Long id); + TtWebService getTtWebService(TenantEntity tenantInfo); } diff --git a/mallinkService/src/main/java/com/iformall/service/impl/TtMerchantPoiServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/TtMerchantPoiServiceImpl.java index 902d6f6fa..2f072d6e7 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/TtMerchantPoiServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/TtMerchantPoiServiceImpl.java @@ -14,6 +14,7 @@ import com.iformall.douyin.web.api.TtWebService; import com.iformall.douyin.web.bean.TtSupplierMatch; import com.iformall.douyin.web.bean.TtSupplierMatchList; import com.iformall.douyin.web.bean.TtSupplierSync; +import com.iformall.douyin.web.bean.TtSupplierSyncQuery; import com.iformall.enums.*; import com.iformall.exception.MallinkException; import com.iformall.mapper.*; @@ -149,6 +150,31 @@ public class TtMerchantPoiServiceImpl implements TtMerchantPoiService { return new ResultData(); } + private String supplierMatch(TenantEntity tenantInfo, List merchantPoiList) throws MallinkException{ + TtSupplierMatchList matchList = new TtSupplierMatchList(); + for (TtMerchantPoi poi:merchantPoiList) { + TtSupplierMatch match = new TtSupplierMatch(); + match.setSupplierExtId(poi.getSupplierExtId()); + match.setPoiName(poi.getMerchantName()); + match.setProvince(poi.getMerchantProvince()); + match.setCity(poi.getMerchantCity()); + match.setAddress(poi.getMerchantAddr()); + match.setLongitude(poi.getLongitude()); + match.setLatitude(poi.getLatitude()); + match.setAmapId(poi.getAmapId()); + + matchList.getMatchDataList().add(match); + } + String taskId = null; + try { + taskId = getTtWebService(tenantInfo).getShopMatchService().supplierMatch(matchList); + } catch (WxErrorException e) { + logger.error("发起店铺匹配POI同步任务error"+e.getMessage()); + throw new MallinkException(ErrorCode.MSG_METHOD_REQUEST_ERROR.getCode(),e.getMessage()); + } + return taskId; + } + @Override public List findTaskIdList(TtMerchantPoi merchantPoiQ) { return ttMerchantPoiMapper.findTaskIdList(merchantPoiQ); @@ -175,8 +201,12 @@ public class TtMerchantPoiServiceImpl implements TtMerchantPoiService { ttMerchantPoiMapper.updateById(poiUpd); }else if(EnumSupplierMathStatus.match_fail.getCode().equals(match.getMatchStatus())){ ttMerchantPoiMapper.updateById(poiUpd); + }else{ + logger.error("门店id["+match.getSupplierExtId()+"]暂未处理成功"+match.getMismatchStatusDesc()); } } + }else{ + logger.error("请求接口返回为空"); } } catch (WxErrorException e) { logger.error("查询匹配任务error"+e.getMessage()); @@ -200,7 +230,7 @@ public class TtMerchantPoiServiceImpl implements TtMerchantPoiService { TtMerchantPoi updPoi = new TtMerchantPoi(); updPoi.setId(id); updPoi.setSupplierId(supplierId); - updPoi.setLastSyncStatus(EnumSupplierSyncStatus.match_wait.getCode()); + updPoi.setLastSyncStatus(EnumSupplierSyncStatus.sync_wait.getCode()); updPoi.setUpdateDate(new Date()); ttMerchantPoiMapper.updateById(merchantPoi); return new ResultData(); @@ -246,29 +276,37 @@ public class TtMerchantPoiServiceImpl implements TtMerchantPoiService { return supplierId; } - private String supplierMatch(TenantEntity tenantInfo, List merchantPoiList) throws MallinkException{ - TtSupplierMatchList matchList = new TtSupplierMatchList(); - for (TtMerchantPoi poi:merchantPoiList) { - TtSupplierMatch match = new TtSupplierMatch(); - match.setSupplierExtId(poi.getSupplierExtId()); - match.setPoiName(poi.getMerchantName()); - match.setProvince(poi.getMerchantProvince()); - match.setCity(poi.getMerchantCity()); - match.setAddress(poi.getMerchantAddr()); - match.setLongitude(poi.getLongitude()); - match.setLatitude(poi.getLatitude()); - match.setAmapId(poi.getAmapId()); + @Override + public List findIdList(TtMerchantPoi merchantPoiQ) { + return ttMerchantPoiMapper.findIdList(merchantPoiQ); + } - matchList.getMatchDataList().add(match); + @Override + public void supplierQuery(Long id) { + TtMerchantPoi merchantPoi = ttMerchantPoiMapper.selectById(id); + if(merchantPoi == null){ + logger.error("未找到数据"); + return; + } + if(!EnumSupplierSyncStatus.sync_wait.getCode().equals(merchantPoi.getLastSyncStatus())){ + logger.error("该店铺暂未申请同步或已知同步结果"); + return; } - String taskId = null; try { - taskId = getTtWebService(tenantInfo).getShopMatchService().supplierMatch(matchList); + TtSupplierSyncQuery syncQuery = getTtWebService(merchantPoi).getProductService().supplierQuery(merchantPoi.getSupplierExtId()); + if(syncQuery != null && syncQuery.getSyncStatus() != null ){ + TtMerchantPoi poiUpd = new TtMerchantPoi(); + poiUpd.setId(id); + poiUpd.setLastSyncStatus(syncQuery.getSyncStatus().getLastSyncStatus()); + poiUpd.setFailReason(syncQuery.getSyncStatus().getFailReason()); + poiUpd.setUpdateDate(new Date()); + ttMerchantPoiMapper.updateById(poiUpd); + }else{ + logger.error("请求接口返回为空"); + } } catch (WxErrorException e) { - logger.error("发起店铺匹配POI同步任务error"+e.getMessage()); - throw new MallinkException(ErrorCode.MSG_METHOD_REQUEST_ERROR.getCode(),e.getMessage()); + logger.error("查询匹配任务error"+e.getMessage()); } - return taskId; }