package com.yami.shop.api.task;
|
|
import cn.hutool.core.date.DateUtil;
|
import com.google.gson.Gson;
|
import com.xxl.job.core.handler.annotation.XxlJob;
|
import com.yami.shop.bean.model.V1BoxIncome;
|
import com.yami.shop.bean.response.CdnApiResponse;
|
import com.yami.shop.bean.response.CdnSingleEarningsResponse;
|
import com.yami.shop.cdn.common.utils.CdnUtils;
|
import com.yami.shop.cdn.common.vo.CdnVo;
|
import com.yami.shop.common.config.Constant;
|
import com.yami.shop.service.SysConfigService;
|
import com.yami.shop.service.V1BoxIncomeService;
|
import com.yami.shop.service.V1BoxService;
|
import lombok.extern.slf4j.Slf4j;
|
import ma.glasnost.orika.MapperFacade;
|
import org.slf4j.Logger;
|
import org.slf4j.LoggerFactory;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Component;
|
|
import java.io.IOException;
|
import java.text.SimpleDateFormat;
|
import java.time.LocalDate;
|
import java.time.LocalDateTime;
|
import java.time.LocalTime;
|
import java.time.ZoneId;
|
import java.util.Date;
|
|
@Slf4j
|
@Component
|
public class V1BoxTask {
|
private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
|
@Autowired
|
private V1BoxService v1BoxService;
|
@Autowired
|
private V1BoxIncomeService v1BoxIncomeService;
|
@Autowired
|
private SysConfigService sysConfigService;
|
@Autowired
|
private MapperFacade mapperFacade;
|
|
/**
|
* 每日拉取盒子收益
|
*/
|
@XxlJob("pullV1BoxIncome")
|
public void pullV1BoxIncome() throws IOException {
|
Date now = new Date();
|
logger.info("拉取盒子收益。。。"+ DateUtil.format(now, "yyyy-MM-dd HH:mm:ss"));
|
// 假设CdnUtils.getBoxIncomeToPost()是用于拉取收益数据的方法
|
// 这里使用昨天的日期作为参数
|
LocalDate today = LocalDate.now();
|
LocalDate yesterday = today.minusDays(1);
|
LocalDateTime yesterdayStart = LocalDateTime.of(yesterday, LocalTime.MIN);
|
Date yesterdayStartAsDate = Date.from(yesterdayStart.atZone(ZoneId.systemDefault()).toInstant());
|
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
|
String value = sysConfigService.getValue(Constant.CDN_CONFIG);
|
Gson gson = new Gson();
|
CdnVo cdnVo = gson.fromJson(value, CdnVo.class);
|
CdnApiResponse<CdnSingleEarningsResponse> boxIncomeToPost = CdnUtils.getBoxIncomeToPost(null, null, null, format.format(yesterdayStartAsDate), null, cdnVo);
|
CdnSingleEarningsResponse data = boxIncomeToPost.getData();
|
if (data.getTotal() != null && !data.getTotal().equals("0")) {
|
for (CdnSingleEarningsResponse.V1SupplierIncomeV2ResponseItem item : data.getList()) {
|
v1BoxIncomeService.save(mapperFacade.map(item, V1BoxIncome.class));
|
|
}
|
}
|
logger.info("拉取盒子收益完成... {}", DateUtil.format(new Date(), "yyyy-MM-dd HH:mm:ss"));
|
}
|
}
|