ReceptionFileMergeOrAsrCreateTask.java
3.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package com.bs.reception.task;
import com.bs.common.xxljob.annotations.XxlRegister;
import com.bs.reception.service.BizService.ReceptionService;
import com.xxl.job.core.handler.annotation.XxlJob;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;
import java.text.SimpleDateFormat;
import java.util.Date;
/**
* 接待录音文件合并和语音转文本任务创建补偿
*
* @author yelq
* @date 2025年11月21日
*/
@Slf4j
@Component
public class ReceptionFileMergeOrAsrCreateTask {
/**
* 保存待worktool推送程序是否正在进行处理的标记
*/
private static final String WAIT_FLAG = "bs.scheduler.task:reception.fileMerge.or.asrTaskCreate.waitFlag";
@Resource
private ReceptionService receptionService;
@Resource
private RedisTemplate<String, String> stringRedisTemplate;
@Autowired
private Environment env;
@XxlJob("ReceptionFileMergeOrAsrCreateTask")
@XxlRegister(cron = "0 0/2 * * * ? *", author = "yelq",
jobDesc = "接待录音文件合并和语音转文本任务创建补偿")
public void execute() {
try {
String flag = stringRedisTemplate.opsForValue().get(WAIT_FLAG);
// 上一次自动任务还在处理,此次不执行
if (flag != null) return;
stringRedisTemplate.opsForValue().set(WAIT_FLAG, "ReceptionFileMergeOrAsrCreateTask", 60 * 30);// 30分钟
receptionService.fileMergeOrFunAsrTaskCreate();
// 处理发送逻辑
stringRedisTemplate.delete(WAIT_FLAG);
} catch (Exception e) {
log.error(e.getMessage(), e);
sendMsgNotice("数据推送任务执行异常:" + e.getMessage());
stringRedisTemplate.delete(WAIT_FLAG);
}
}
public void sendMsgNotice(String msg) {
try {
log.info("发送到通知群消息:{}", msg);
// String key = env.getProperty("action.report.test.webhook.key");
// EnterpriseWechatBaseResponse resp = sendText(msg, key);
// if (resp != null && resp.getErrCode() != 0) {
// log.error("发送到通知群消息异常:{},消息内容:{}", resp.getErrMsg(), msg);
// }
} catch (Exception e) {
log.error("发送到通知群消息异常:{},消息内容:{}", e.getMessage(), msg, e);
}
}
public String getDateTimeStartString() {
SimpleDateFormat format = new SimpleDateFormat("yyyy年MM月dd日HH时mm分ss秒");
return format.format(new Date());
}
/**
* 发送企微群机器人文本消息
*
* @param content 文本内容
* @param key 企微群机器人key
* @return 响应结果
* @throws Exception
*/
/*public static EnterpriseWechatBaseResponse sendText(String content, String key) throws Exception {
try {
// 构建请求体
Map<String, Object> requestBody = new HashMap<>();
requestBody.put("msgtype", "text");
Map<String, Object> text = new HashMap<>();
text.put("content", content);
requestBody.put("text", text);
String ROBOT_URL_PRE = "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=";
// 使用 Hutool 发送请求
String response = HttpUtil.post(ROBOT_URL_PRE + key, JSONUtil.toJsonStr(requestBody));
return JSONUtil.toBean(response, EnterpriseWechatBaseResponse.class);
} catch (Exception e) {
throw new RuntimeException("发送企微机器人消息失败", e);
}
}*/
}