package com.xinelu.quartz.task;

import com.xinelu.common.enums.PhoneDialMethodEnum;
import com.xinelu.common.utils.StringUtils;
import com.xinelu.manage.domain.phonedialrecord.PhoneDialRecord;
import com.xinelu.manage.dto.phonedialrecord.PhoneDialRecordDto;
import com.xinelu.manage.mapper.phonedialrecord.PhoneDialRecordMapper;
import com.xinelu.manage.service.aiob.IAIOBService;
import java.time.LocalDateTime;
import java.util.List;
import javax.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * @description: 获取百度外呼通话记录录音定时任务
 * @author: haown
 * @create: 2024-11-08 13:34
 **/
@Slf4j
@Component("GetAiboRecordVideoTask")
public class GetAiobRecordVideoTask {

	@Resource
	private PhoneDialRecordMapper phoneDialRecordMapper;
	@Resource
	private IAIOBService aiobService;

	public void getVideo() {
		// 查询超过两分钟没有录音地址的通话记录
		PhoneDialRecordDto phoneDialRecordQuery = new PhoneDialRecordDto();
		LocalDateTime localDateTime = LocalDateTime.now();
		localDateTime.minusMinutes(2);
		phoneDialRecordQuery.setDialTime(localDateTime);
		phoneDialRecordQuery.setPhoneDialMethod(PhoneDialMethodEnum.AI.getInfo());
		List<PhoneDialRecord> phoneDialRecordList = phoneDialRecordMapper.getNoVideoList(phoneDialRecordQuery);
		phoneDialRecordList.forEach(phoneDialRecord -> {
			if (StringUtils.isNotBlank(phoneDialRecord.getCtUuid())) {
				String videoUrl = aiobService.getPhoneDialRecord(phoneDialRecord.getCtUuid());
				phoneDialRecord.setPhoneDialRecordVideo(videoUrl);
				phoneDialRecordMapper.updatePhoneDialRecord(phoneDialRecord);
			}
		});
	}

}
