package cn.com.ctop.job.kuaishou.handler;

import cn.com.ctop.kuaishou.modules.report.service.NewMonitorService;
import cn.com.ctop.toutiao.modules.agent.service.AgentManagementService;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.util.DateUtils;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

@Component
@Slf4j
public class SynchronousAccountTransactionJob {

    @Resource
    AgentManagementService  agentManagementService;

    /**
     * 同步头条账户交易流水
     *
     * @param
     * @return
     * @throws
     * @author ZZY
     */
    @XxlJob("synchronousAccountTransaction")
    public void execute() throws Exception {
        SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd");
        Calendar ca = Calendar.getInstance();//得到一个Calendar的实例
        ca.setTime(new Date()); //设置时间为当前时间
        ca.add(Calendar.DAY_OF_MONTH, -1);  //设置为前一天
        String date = sd.format(ca.getTime());
        try {
            agentManagementService.synchronousAccount();
            agentManagementService.synchronousAccountTransactionDay(date,date);
            agentManagementService.synchronousAccountTransactionDetails(date,date);
        } catch (Exception e) {
            log.info("同步完成");
        }

    }

    /**
     * 同步头条账户交易流水
     * 获取前3天数据
     */
    @XxlJob("synchronousAccountTransactionNew")
    public void synchronousAccountTransactionNew() throws Exception {
        String nowDate = DateUtils.getNowDate("yyyy-MM-dd");
        String yesterda1 = DateUtils.getAnotherDay("yyyy-MM-dd", nowDate, -1);
        String yesterda2 = DateUtils.getAnotherDay("yyyy-MM-dd", nowDate, -2);
        String yesterda3 = DateUtils.getAnotherDay("yyyy-MM-dd", nowDate, -3);

        try {
//            agentManagementService.synchronousAccount();

            agentManagementService.insertAccountTransactionDay(yesterda1,yesterda1);
            agentManagementService.insertAccountTransactionDay(yesterda2,yesterda2);
            agentManagementService.insertAccountTransactionDay(yesterda3,yesterda3);

        } catch (Exception e) {
            log.info("同步完成");
        }

    }
}
