2025-07-14 11:23:11 +08:00
|
|
|
package com.whdc.component;
|
|
|
|
|
|
|
|
|
|
import com.whdc.mapper.AutoCallConfigMapper;
|
2025-08-07 21:29:50 +08:00
|
|
|
import com.whdc.mapper.AutoCallPersonMapper;
|
2025-07-14 11:23:11 +08:00
|
|
|
import com.whdc.model.entity.AutoCallPerson;
|
|
|
|
|
import com.whdc.service.AutoCallTaskService2;
|
|
|
|
|
import com.whdc.utils.AutoCallHelper;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.boot.context.event.ApplicationReadyEvent;
|
|
|
|
|
import org.springframework.context.annotation.Profile;
|
|
|
|
|
import org.springframework.context.event.EventListener;
|
|
|
|
|
import org.springframework.scheduling.TaskScheduler;
|
|
|
|
|
import org.springframework.scheduling.annotation.Scheduled;
|
|
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.concurrent.atomic.AtomicBoolean;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @author lyf
|
|
|
|
|
* @since 2025-06-20
|
|
|
|
|
*/
|
|
|
|
|
@Component
|
|
|
|
|
@Slf4j
|
2025-08-06 17:21:07 +08:00
|
|
|
@Profile({"dev"})
|
2025-07-14 11:23:11 +08:00
|
|
|
public class AutoCallTaskScheduled {
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private AutoCallTaskService2 autoCallTaskService;
|
|
|
|
|
@Autowired
|
2025-08-07 21:29:50 +08:00
|
|
|
private AutoCallPersonMapper personMapper;
|
|
|
|
|
@Autowired
|
2025-07-14 11:23:11 +08:00
|
|
|
private AutoCallConfigMapper configMapper;
|
|
|
|
|
@Autowired
|
|
|
|
|
private AutoCallHelper autoCallHelper;
|
|
|
|
|
@Autowired
|
|
|
|
|
private TaskScheduler taskScheduler;
|
|
|
|
|
|
|
|
|
|
private AtomicBoolean initialized = new AtomicBoolean(false);
|
|
|
|
|
|
|
|
|
|
@EventListener(ApplicationReadyEvent.class)
|
|
|
|
|
public void initialize() throws Exception {
|
|
|
|
|
autoCallHelper.getToken();
|
|
|
|
|
initialized.set(true);
|
|
|
|
|
log.info("AutoCallTaskScheduled初始化完成");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Scheduled(cron = "*/3 * * * * ?")
|
|
|
|
|
public void generateLoop() {
|
|
|
|
|
if (configMapper.isScheduled()) {
|
|
|
|
|
autoCallTaskService.step1GenerateTask();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Scheduled(cron = "*/3 * * * * ?")
|
|
|
|
|
public void callLoop() {
|
|
|
|
|
if (!initialized.get()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (!configMapper.isScheduled()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
log.info("AutoCallTaskScheduled callLoop");
|
|
|
|
|
List<AutoCallPerson> personList = autoCallTaskService.step2GetOneUnUploadedPerson();
|
|
|
|
|
log.info("AutoCallTaskScheduled {}个外呼人, {}", personList.size(), personList.stream().map(AutoCallPerson::getUploadCustName).collect(Collectors.toList()));
|
|
|
|
|
try {
|
|
|
|
|
for (AutoCallPerson person : personList) {
|
2025-08-06 17:21:07 +08:00
|
|
|
if (person.getUploadedTimes() < 2) {
|
|
|
|
|
autoCallTaskService.step3UploadAICCTask(person);
|
|
|
|
|
} else {
|
|
|
|
|
autoCallTaskService.cancelPerson(person);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2025-08-07 21:29:50 +08:00
|
|
|
int pendingDuration = 60 * 1000 * 2;
|
2025-07-14 11:23:11 +08:00
|
|
|
int loopGap = 1000;
|
|
|
|
|
boolean success = false;
|
|
|
|
|
while (pendingDuration > 0) {
|
|
|
|
|
try {
|
|
|
|
|
Thread.sleep(loopGap);
|
|
|
|
|
} catch (InterruptedException ignore) {
|
|
|
|
|
Thread.currentThread().interrupt();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
pendingDuration -= loopGap;
|
|
|
|
|
|
|
|
|
|
success = autoCallTaskService.step4QueryAICCTaskResult(person);
|
|
|
|
|
if (success) break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!success) {
|
2025-08-07 21:29:50 +08:00
|
|
|
person.setUploadedTimes(personMapper.selectById(person.getId()).getUploadedTimes());
|
|
|
|
|
if (person.getUploadedTimes() == 2) {
|
|
|
|
|
autoCallTaskService.markPersonDetailQueryTimeout(person);
|
|
|
|
|
}
|
2025-07-14 11:23:11 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
log.error("AutoCallTaskScheduled callLoop error", e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|