1
This commit is contained in:
@@ -755,7 +755,8 @@ public class TencentDocController extends BaseController {
|
||||
List<Map<String, Object>> successLogs = new java.util.ArrayList<>();
|
||||
successLogs.add(successLog);
|
||||
|
||||
sendWeChatNotification(successLogs, 1, 0, 0, true);
|
||||
// 手动执行时,batchId为null
|
||||
sendWeChatNotification(successLogs, 1, 0, 0, null, fileId, sheetId, true);
|
||||
} catch (Exception e) {
|
||||
log.error("发送微信推送失败", e);
|
||||
// 不影响主流程,继续返回成功
|
||||
@@ -1566,7 +1567,8 @@ public class TencentDocController extends BaseController {
|
||||
// 如果有成功记录,发送微信推送
|
||||
if (!successLogs.isEmpty()) {
|
||||
try {
|
||||
sendWeChatNotification(successLogs, filledCount, skippedCount, errorCount);
|
||||
// 传递batchId给推送方法,用于日志关联
|
||||
sendWeChatNotificationWithBatchId(successLogs, filledCount, skippedCount, errorCount, batchId, fileId, sheetId, false);
|
||||
} catch (Exception e) {
|
||||
log.error("发送微信推送失败", e);
|
||||
// 不影响主流程,继续返回成功
|
||||
@@ -2078,7 +2080,23 @@ public class TencentDocController extends BaseController {
|
||||
* @param errorCount 错误数量
|
||||
*/
|
||||
private void sendWeChatNotification(List<Map<String, Object>> successLogs, int filledCount, int skippedCount, int errorCount) {
|
||||
sendWeChatNotification(successLogs, filledCount, skippedCount, errorCount, false);
|
||||
sendWeChatNotification(successLogs, filledCount, skippedCount, errorCount, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送微信推送通知(同步成功日志)- 带batchId参数
|
||||
*
|
||||
* @param successLogs 成功日志列表
|
||||
* @param filledCount 成功填充数量
|
||||
* @param skippedCount 跳过数量
|
||||
* @param errorCount 错误数量
|
||||
* @param batchId 批次ID
|
||||
* @param fileId 文档ID
|
||||
* @param sheetId 工作表ID
|
||||
* @param isManual 是否为手动执行
|
||||
*/
|
||||
private void sendWeChatNotificationWithBatchId(List<Map<String, Object>> successLogs, int filledCount, int skippedCount, int errorCount, String batchId, String fileId, String sheetId, boolean isManual) {
|
||||
sendWeChatNotification(successLogs, filledCount, skippedCount, errorCount, batchId, fileId, sheetId, isManual);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2091,7 +2109,38 @@ public class TencentDocController extends BaseController {
|
||||
* @param isManual 是否为手动执行
|
||||
*/
|
||||
private void sendWeChatNotification(List<Map<String, Object>> successLogs, int filledCount, int skippedCount, int errorCount, boolean isManual) {
|
||||
// 从配置中读取文档信息
|
||||
final String CONFIG_KEY_PREFIX = "tencent:doc:auto:config:";
|
||||
String fileId = redisCache.getCacheObject(CONFIG_KEY_PREFIX + "fileId");
|
||||
String sheetId = redisCache.getCacheObject(CONFIG_KEY_PREFIX + "sheetId");
|
||||
if (fileId == null || fileId.isEmpty()) {
|
||||
fileId = tencentDocConfig.getFileId();
|
||||
}
|
||||
if (sheetId == null || sheetId.isEmpty()) {
|
||||
sheetId = tencentDocConfig.getSheetId();
|
||||
}
|
||||
sendWeChatNotification(successLogs, filledCount, skippedCount, errorCount, null, fileId, sheetId, isManual);
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送微信推送通知(同步成功日志)
|
||||
*
|
||||
* @param successLogs 成功日志列表
|
||||
* @param filledCount 成功填充数量
|
||||
* @param skippedCount 跳过数量
|
||||
* @param errorCount 错误数量
|
||||
* @param batchId 批次ID(可为null)
|
||||
* @param fileId 文档ID
|
||||
* @param sheetId 工作表ID
|
||||
* @param isManual 是否为手动执行
|
||||
*/
|
||||
private void sendWeChatNotification(List<Map<String, Object>> successLogs, int filledCount, int skippedCount, int errorCount, String batchId, String fileId, String sheetId, boolean isManual) {
|
||||
try {
|
||||
log.info("========== 开始发送微信推送通知 ==========");
|
||||
log.info("推送类型: {}, 成功: {} 条, 跳过: {} 条, 错误: {} 条",
|
||||
isManual ? "手动执行" : "批量同步", filledCount, skippedCount, errorCount);
|
||||
log.info("批次ID: {}, 文档ID: {}, 工作表ID: {}", batchId, fileId, sheetId);
|
||||
|
||||
// 微信推送服务配置
|
||||
String wxSendBaseUrl = "https://wxts.van333.cn";
|
||||
String pushToken = "super_token_b62190c26";
|
||||
@@ -2150,14 +2199,33 @@ public class TencentDocController extends BaseController {
|
||||
|
||||
String jsonBody = requestBody.toJSONString();
|
||||
|
||||
log.info("微信推送请求 - URL: {}", pushUrl);
|
||||
log.info("微信推送请求体: {}", jsonBody);
|
||||
|
||||
// 发送POST请求
|
||||
String result = sendPostRequest(pushUrl, jsonBody, pushToken);
|
||||
|
||||
log.info("微信推送发送完成 - URL: {}, 响应: {}", pushUrl, result);
|
||||
log.info("========== 微信推送发送完成 ==========");
|
||||
log.info("推送URL: {}", pushUrl);
|
||||
log.info("推送响应: {}", result);
|
||||
|
||||
// 记录微信推送操作日志
|
||||
String pushLogMessage = String.format("微信推送成功 - 类型: %s, 成功: %d条, 跳过: %d条, 错误: %d条",
|
||||
isManual ? "手动执行" : "批量同步", filledCount, skippedCount, errorCount);
|
||||
logOperation(batchId, fileId, sheetId, "WECHAT_PUSH", null, null, null,
|
||||
"SUCCESS", pushLogMessage);
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("发送微信推送失败", e);
|
||||
throw new RuntimeException("发送微信推送失败: " + e.getMessage(), e);
|
||||
log.error("========== 发送微信推送失败 ==========", e);
|
||||
|
||||
// 记录微信推送失败日志
|
||||
String pushLogMessage = String.format("微信推送失败 - 类型: %s, 错误: %s",
|
||||
isManual ? "手动执行" : "批量同步", e.getMessage());
|
||||
logOperation(batchId, fileId, sheetId, "WECHAT_PUSH", null, null, null,
|
||||
"FAILED", pushLogMessage);
|
||||
|
||||
// 不抛出异常,避免影响主流程
|
||||
log.warn("微信推送失败,但不影响主流程,继续执行");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2174,6 +2242,10 @@ public class TencentDocController extends BaseController {
|
||||
java.io.PrintWriter out = null;
|
||||
StringBuilder result = new StringBuilder();
|
||||
try {
|
||||
log.info(">>> 发送HTTP POST请求到微信推送服务");
|
||||
log.info(">>> 请求URL: {}", url);
|
||||
log.info(">>> 请求体长度: {} 字节", jsonBody.length());
|
||||
|
||||
java.net.URL realUrl = new java.net.URL(url);
|
||||
java.net.URLConnection conn = realUrl.openConnection();
|
||||
|
||||
@@ -2185,6 +2257,8 @@ public class TencentDocController extends BaseController {
|
||||
conn.setRequestProperty("Content-Type", "application/json");
|
||||
conn.setRequestProperty("vanToken", token);
|
||||
|
||||
log.info(">>> 请求头已设置 - vanToken: {}...", token != null && token.length() > 10 ? token.substring(0, 10) : token);
|
||||
|
||||
conn.setDoOutput(true);
|
||||
conn.setDoInput(true);
|
||||
|
||||
@@ -2192,11 +2266,14 @@ public class TencentDocController extends BaseController {
|
||||
conn.setConnectTimeout(10000); // 10秒连接超时
|
||||
conn.setReadTimeout(10000); // 10秒读取超时
|
||||
|
||||
log.info(">>> 开始发送请求体...");
|
||||
// 发送请求体
|
||||
out = new java.io.PrintWriter(conn.getOutputStream());
|
||||
out.print(jsonBody);
|
||||
out.flush();
|
||||
log.info(">>> 请求体已发送");
|
||||
|
||||
log.info(">>> 开始读取响应...");
|
||||
// 读取响应
|
||||
in = new java.io.BufferedReader(new java.io.InputStreamReader(conn.getInputStream(), java.nio.charset.StandardCharsets.UTF_8));
|
||||
String line;
|
||||
@@ -2204,18 +2281,18 @@ public class TencentDocController extends BaseController {
|
||||
result.append(line);
|
||||
}
|
||||
|
||||
log.debug("微信推送请求成功 - URL: {}, 响应: {}", url, result.toString());
|
||||
log.info(">>> HTTP请求成功 - URL: {}, 响应: {}", url, result.toString());
|
||||
} catch (java.net.ConnectException e) {
|
||||
log.error("微信推送连接失败 - URL: {}", url, e);
|
||||
log.error(">>> HTTP请求连接失败 - URL: {}", url, e);
|
||||
throw new RuntimeException("连接失败: " + e.getMessage(), e);
|
||||
} catch (java.net.SocketTimeoutException e) {
|
||||
log.error("微信推送请求超时 - URL: {}", url, e);
|
||||
log.error(">>> HTTP请求超时 - URL: {}", url, e);
|
||||
throw new RuntimeException("请求超时: " + e.getMessage(), e);
|
||||
} catch (java.io.IOException e) {
|
||||
log.error("微信推送IO异常 - URL: {}", url, e);
|
||||
log.error(">>> HTTP请求IO异常 - URL: {}", url, e);
|
||||
throw new RuntimeException("IO异常: " + e.getMessage(), e);
|
||||
} catch (Exception e) {
|
||||
log.error("微信推送异常 - URL: {}", url, e);
|
||||
log.error(">>> HTTP请求异常 - URL: {}", url, e);
|
||||
throw new RuntimeException("推送异常: " + e.getMessage(), e);
|
||||
} finally {
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user