package com.gree.mall.manager.schedule;

import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;

import com.gree.mall.manager.logic.unicom.UnicomLogic;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;

/**
 * 同步云呼通话记录
 */
@Slf4j
@Component
@ConditionalOnProperty(name = "schedule.enable", havingValue = "true", matchIfMissing = true)
public class SyncUnicomeCallRecord {
    @Autowired
    UnicomLogic unicomLogic;



    @Scheduled(fixedDelay = 60  * 1000)
    public void task(){
        //同步最近5分钟的通话记录
        try {
            DateTime startTime = DateUtil.offsetMinute(new Date(), -2);
            unicomLogic.syncMsgRecord(startTime, new Date());
        }catch(Exception e){
            log.error("【同步通话记录失败】...");
        }
    }
}
