| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- package com.uas.eis.task;
- import com.alibaba.fastjson.JSONObject;
- import com.uas.eis.dto.stksto.QueryTravellingMerchantDto;
- import com.uas.eis.sdk.dto.CustvendDTO;
- import com.uas.eis.service.RequestSTKService;
- import com.uas.eis.service.STKService;
- import com.uas.eis.vo.stkVo.TravellingMerchantVo;
- import lombok.extern.slf4j.Slf4j;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.beans.factory.annotation.Value;
- import org.springframework.scheduling.annotation.Scheduled;
- import org.springframework.stereotype.Component;
- import java.util.Date;
- import java.util.List;
- import java.util.Set;
- @Slf4j
- @Component
- public class STKTask {
- /**
- * 复杂查询接口请求地址
- * */
- @Value("${STK.complexity_query_url}")
- private String COMPLEXITY_QUERY_URL;
- /**
- * 获取客商信息接口编码
- * */
- @Value("${STK.get_travelling_merchant}")
- private String GET_TRAVELLING_MERCHANT;
- /**
- * 获取客商状态反馈信息
- * */
- @Value("${STK.get_travelling_merchant_status}")
- private String GET_TRAVELLING_MERCHANT_STATUS;
- @Autowired
- RequestSTKService requestSTKService;
- @Autowired
- private STKService stkService;
- /*@Scheduled(cron = "0 55 22 * * ?")
- public void getSellerOrders(){
- log.info("开始获取深投控客商状态信息=========start=============");
- Date date = new Date();
- QueryTravellingMerchantDto dto = new QueryTravellingMerchantDto();
- dto.setCode(GET_TRAVELLING_MERCHANT);
- dto.setPage(1);
- dto.setSize(500);
- TravellingMerchantVo travellingMerchantVo = new TravellingMerchantVo();
- Boolean exception = false;
- try{
- travellingMerchantVo = requestSTKService.selectTravellingMerchantList(dto,COMPLEXITY_QUERY_URL);
- }catch (Exception e){
- log.info("获取客商信息数据异常:{}",e.getMessage());
- exception = true;
- }
- log.info("定时任务获取深投控客商信息数据结果:{}", JSONObject.toJSONString(travellingMerchantVo));
- //第一次删除STK_CUSTVEND的数据
- stkService.getCustvend(travellingMerchantVo, true);
- if (travellingMerchantVo.getData().getHasNextPage()){
- Boolean isBreak = true;
- while(isBreak) {
- if(!exception){
- dto.setPage(travellingMerchantVo.getData().getNextPage());
- }
- log.info("while循环获取客商数据,查询参数:{}",JSONObject.toJSONString(dto));
- try{
- travellingMerchantVo = requestSTKService.selectTravellingMerchantList(dto, COMPLEXITY_QUERY_URL);
- }catch (Exception e){
- log.info("获取客商信息数据异常:{}",e.getMessage());
- exception = true;
- }
- stkService.getCustvend(travellingMerchantVo, false);
- if (!travellingMerchantVo.getData().getHasNextPage() || dto.getSize() > travellingMerchantVo.getData().getEndRow()){
- isBreak = false;
- }
- }
- }
- log.info("定时任务获取深投控客商信息数据结果2:{}", JSONObject.toJSONString(travellingMerchantVo));
- log.info("开始获取深投控客商状态信息,结束:"+((System.currentTimeMillis()-date.getTime())/1000));
- }*/
- @Scheduled(cron = "0 30 23 * * ?")
- public void getSellerOrders(){
- log.info("开始获取深投控客商状态信息=========start=============");
- Date date = new Date();
- QueryTravellingMerchantDto dto = new QueryTravellingMerchantDto();
- dto.setCode(GET_TRAVELLING_MERCHANT);
- dto.setPage(1);
- dto.setSize(500);
- //第一次删除STK_CUSTVEND的数据
- stkService.delete();
- //是否跳出循环
- Boolean isBreak = true;
- //是否发生异常
- Boolean exception = false;
- //异常跳过次数
- Integer num = 0;
- while(isBreak) {
- log.info("while循环获取客商数据,查询参数:{}",JSONObject.toJSONString(dto));
- TravellingMerchantVo travellingMerchantVo = new TravellingMerchantVo();
- try{
- travellingMerchantVo = requestSTKService.selectTravellingMerchantList(dto, COMPLEXITY_QUERY_URL);
- //获取到客商数据,数据入库
- stkService.getCustvend(travellingMerchantVo, false);
- }catch (Exception e){
- log.info("获取客商信息数据异常:{}",e.getMessage());
- exception = true;
- num = num +1;
- }
- if(num >=5){
- break;
- }
- //判断没发生异常,且是最后一页条件判断==》没有下页编码,或者返回的数据量小于每次查询的每页数量
- if (!exception && null != travellingMerchantVo && null != travellingMerchantVo.getData() && dto.getSize() > travellingMerchantVo.getData().getEndRow()){
- isBreak = false;
- }
- if(!exception){
- dto.setPage(travellingMerchantVo.getData().getNextPage());
- }
- log.info("定时任务获取深投控客商信息数据结果2:{}", JSONObject.toJSONString(travellingMerchantVo));
- }
- log.info("开始获取深投控客商状态信息,结束:"+((System.currentTimeMillis()-date.getTime())/1000));
- }
- }
|