基于mall4j产品的二开项目后端
lee
2024-12-18 efdb99f8cecc4afb592afad79c761081d5d5cf22
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
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"));
    }
}