diff --git a/ms-biz/src/main/java/com/ms/biz/spi/timer/GetAuthInfoTimerService.java b/ms-biz/src/main/java/com/ms/biz/spi/timer/GetAuthInfoTimerService.java new file mode 100644 index 0000000..e32d3a9 --- /dev/null +++ b/ms-biz/src/main/java/com/ms/biz/spi/timer/GetAuthInfoTimerService.java @@ -0,0 +1,26 @@ +package com.ms.biz.spi.timer; + +import com.jinritemai.cloud.base.api.BaseRequest; +import com.jinritemai.cloud.base.api.BaseResponse; +import com.jinritemai.cloud.base.api.ExtensionService; +import com.jinritemai.cloud.base.api.ExtensionServiceHandler; +import com.ms.api.dto.ItemDTO; +import com.ms.biz.common.R; +import com.ms.biz.common.Ret; +import com.ms.biz.common.TimerBaseService; +import com.ms.biz.task.GetAuthInfoTaskService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; + +@ExtensionService("getAuthInfoTimer") +@Slf4j +public class GetAuthInfoTimerService extends TimerBaseService implements ExtensionServiceHandler { + @Autowired + GetAuthInfoTaskService getAuthInfoTaskService; + + @Override + public BaseResponse handle(BaseRequest req) { + getAuthInfoTaskService.runTask(); + return R.ok(Ret.success()); + } +} diff --git a/ms-biz/src/main/java/com/ms/biz/task/GetAuthInfoTaskService.java b/ms-biz/src/main/java/com/ms/biz/task/GetAuthInfoTaskService.java new file mode 100644 index 0000000..41a070d --- /dev/null +++ b/ms-biz/src/main/java/com/ms/biz/task/GetAuthInfoTaskService.java @@ -0,0 +1,71 @@ +package com.ms.biz.task; + +import com.alibaba.fastjson.JSONObject; +import com.doudian.open.api.open_getAuthInfo.data.OpenGetAuthInfoData; +import com.doudian.open.api.open_getAuthInfo.param.OpenGetAuthInfoParam; +import com.ms.biz.common.TaskBaseService; +import com.ms.biz.util.DDApi; +import lombok.extern.slf4j.Slf4j; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.scheduling.annotation.Async; +import org.springframework.scheduling.annotation.Scheduled; +import org.springframework.stereotype.Component; + +import javax.annotation.Resource; +import java.util.concurrent.Executor; + +@Configuration +@Component +@Slf4j +public class GetAuthInfoTaskService extends TaskBaseService { + + @Bean(name = "getAuthInfoTaskPool") + @Override + public Executor getAsyncExecutor() { + return super.getAsyncExecutor(); + } + + @Resource(name = "getAuthInfoTaskPool") + protected Executor taskPool; + + @Async("getAuthInfoTaskPool") + @Scheduled(fixedRate = 10000) + @Override + public void runTask() { + super.runTask(); + } + + @Override + public int getCorePoolSiz() { + return 3; + } + + @Override + public String getTaskExecutorName() { + return "getAuthInfoTaskPool"; + } + + @Override + protected Executor getTaskPool() { + return taskPool; + } + + @Override + public Object getTask() { + return true; + } + + @Override + public Object processTask(Object params) { + OpenGetAuthInfoParam param = new OpenGetAuthInfoParam(); + param.setAuthId("1111502210"); + OpenGetAuthInfoData data = DDApi.getAuthInfo(param); + log.info("GetAuthInfoService:" + JSONObject.toJSONString(data)); + return null; + } + + @Override + public void clearTask(Object params) { + } +} diff --git a/ms-biz/src/main/java/com/ms/biz/util/DDApi.java b/ms-biz/src/main/java/com/ms/biz/util/DDApi.java index 71b86cc..31a1ef6 100644 --- a/ms-biz/src/main/java/com/ms/biz/util/DDApi.java +++ b/ms-biz/src/main/java/com/ms/biz/util/DDApi.java @@ -2,6 +2,10 @@ package com.ms.biz.util; import cn.hutool.core.util.ObjectUtil; import com.alibaba.fastjson.JSONObject; +import com.doudian.open.api.open_getAuthInfo.OpenGetAuthInfoRequest; +import com.doudian.open.api.open_getAuthInfo.OpenGetAuthInfoResponse; +import com.doudian.open.api.open_getAuthInfo.data.OpenGetAuthInfoData; +import com.doudian.open.api.open_getAuthInfo.param.OpenGetAuthInfoParam; import com.doudian.open.api.order_logisticsAddMultiPack.OrderLogisticsAddMultiPackRequest; import com.doudian.open.api.order_logisticsAddMultiPack.OrderLogisticsAddMultiPackResponse; import com.doudian.open.api.order_logisticsAddMultiPack.data.OrderLogisticsAddMultiPackData; @@ -148,6 +152,16 @@ public class DDApi { throw new RuntimeException(String.format("抖店请求错误:%s", response.getMsg())); } + public static OpenGetAuthInfoData getAuthInfo(OpenGetAuthInfoParam param) { + OpenGetAuthInfoRequest request = new OpenGetAuthInfoRequest(); + request.setParam(param); + OpenGetAuthInfoResponse response = request.execute(); + if (response.isSuccess()) { + return response.getData(); + } + throw new RuntimeException(String.format("抖店请求错误:%s", response.getMsg())); + } + private static T execute(DoudianOpRequest request) { // GlobalConfig.getGlobalConfig().addHttpRequestHeader("X-USE-BOE", "1"); // GlobalConfig.getGlobalConfig().addHttpRequestHeader("Origin-From", "djt_prod");