80 lines
3.4 KiB
Java
80 lines
3.4 KiB
Java
package com.xinelu.quartz.task;
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
import com.aliyuncs.exceptions.ClientException;
|
|
import com.xinelu.manage.domain.shortmessagesendrecord.ShortMessageSendRecord;
|
|
import com.xinelu.manage.domain.textmessage.SmsReport;
|
|
import com.xinelu.manage.domain.textmessage.TaskMessageBackEntity;
|
|
import com.xinelu.manage.mapper.shortmessagesendrecord.ShortMessageSendRecordMapper;
|
|
import com.xinelu.quartz.service.SendTextMessageService;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
import org.springframework.stereotype.Component;
|
|
|
|
import javax.annotation.Resource;
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
import java.util.Objects;
|
|
import java.util.stream.Collectors;
|
|
|
|
/**
|
|
* @Description 短信相关定时任务
|
|
* @Author zh
|
|
* @Date 2024-07-22
|
|
*/
|
|
@Slf4j
|
|
@Component("sendTextMessageTask")
|
|
public class SendTextMessageTask {
|
|
|
|
@Resource
|
|
private SendTextMessageService sendTextMessageService;
|
|
@Resource
|
|
private ShortMessageSendRecordMapper shortMessageSendRecordMapper;
|
|
|
|
/**
|
|
* 签约患者管理任务路径节点短信发送定时任务
|
|
*/
|
|
public void automaticSendTextMessageTask() throws ClientException {
|
|
log.info("开始执行签约患者管理任务短信推送定时任务......");
|
|
sendTextMessageService.sendTextMessageSendTask();
|
|
log.info("完成订阅签约患者管理任务路径节点推送定时任务......");
|
|
}
|
|
|
|
public void smsReportBack() {
|
|
log.info("开始执行同步短信回调数据定时任务......");
|
|
TaskMessageBackEntity taskMessageBackEntity = new TaskMessageBackEntity();
|
|
taskMessageBackEntity.setReadState(0);
|
|
List<TaskMessageBackEntity> taskMessageBackEntityList = sendTextMessageService.taskMessageBack(taskMessageBackEntity);
|
|
List<ShortMessageSendRecord> shortMessageSendRecords = new ArrayList<>();
|
|
if (!CollectionUtils.isEmpty(taskMessageBackEntityList)) {
|
|
// 回调数据提取
|
|
List<SmsReport> smsReports = new ArrayList<>();
|
|
taskMessageBackEntityList.forEach(entity -> {
|
|
// JSONString 转 SmsReport
|
|
smsReports.addAll(JSON.parseArray(entity.getMessageBackData().toString(), SmsReport.class));
|
|
});
|
|
if (CollectionUtils.isNotEmpty(smsReports)) {
|
|
for (SmsReport smsReport : smsReports) {
|
|
// 回调数据解析
|
|
sendTextMessageService.taskTextMessageSendBack(smsReport, shortMessageSendRecords);
|
|
}
|
|
}
|
|
if (CollectionUtils.isNotEmpty(shortMessageSendRecords)) {
|
|
shortMessageSendRecordMapper.insertShortMessageSendRecords(shortMessageSendRecords);
|
|
}
|
|
List<Integer> ids = taskMessageBackEntityList.stream().filter(Objects::nonNull).map(TaskMessageBackEntity::getId).collect(Collectors.toList());
|
|
// 修改阿里云服务器回调数据已读状态
|
|
sendTextMessageService.updateReadState(1, ids);
|
|
}
|
|
log.info("完成同步百度外呼回调数据定时任务......");
|
|
}
|
|
|
|
public void clearCallbackData() {
|
|
log.info("开始执行清除过期的百度外呼回调数据定时任务......");
|
|
// 清除一个月前的数据
|
|
int count = sendTextMessageService.deleteData();
|
|
log.info("完成清除过期的百度外呼回调数据定时任务,共清除" + count + "条......");
|
|
}
|
|
}
|