1
This commit is contained in:
@@ -886,6 +886,12 @@ public class TencentDocController extends BaseController {
|
|||||||
// 从参数获取批次ID(如果是批量调用会传入)
|
// 从参数获取批次ID(如果是批量调用会传入)
|
||||||
String batchId = params.get("batchId") != null ? String.valueOf(params.get("batchId")) : null;
|
String batchId = params.get("batchId") != null ? String.valueOf(params.get("batchId")) : null;
|
||||||
|
|
||||||
|
// 如果batchId为空,创建一个新的批次ID(用于日志记录)
|
||||||
|
if (batchId == null || batchId.trim().isEmpty()) {
|
||||||
|
batchId = java.util.UUID.randomUUID().toString().replace("-", "");
|
||||||
|
log.info("未提供batchId,自动创建新的批次ID: {}", batchId);
|
||||||
|
}
|
||||||
|
|
||||||
// 从参数或配置中获取文档信息
|
// 从参数或配置中获取文档信息
|
||||||
String fileId = (String) params.get("fileId");
|
String fileId = (String) params.get("fileId");
|
||||||
String sheetId = (String) params.get("sheetId");
|
String sheetId = (String) params.get("sheetId");
|
||||||
@@ -1157,6 +1163,9 @@ public class TencentDocController extends BaseController {
|
|||||||
int skippedCount = 0;
|
int skippedCount = 0;
|
||||||
int errorCount = 0;
|
int errorCount = 0;
|
||||||
|
|
||||||
|
// 收集同步成功的详细日志(用于微信推送)
|
||||||
|
List<Map<String, Object>> successLogs = new java.util.ArrayList<>();
|
||||||
|
|
||||||
JSONArray updates = new JSONArray(); // 存储需要更新的行和值
|
JSONArray updates = new JSONArray(); // 存储需要更新的行和值
|
||||||
|
|
||||||
for (int i = 0; i < values.size(); i++) {
|
for (int i = 0; i < values.size(); i++) {
|
||||||
@@ -1403,6 +1412,16 @@ public class TencentDocController extends BaseController {
|
|||||||
// 记录操作日志
|
// 记录操作日志
|
||||||
logOperation(batchId, fileId, sheetId, "BATCH_SYNC", expectedOrderNo, row, logisticsLink,
|
logOperation(batchId, fileId, sheetId, "BATCH_SYNC", expectedOrderNo, row, logisticsLink,
|
||||||
"SUCCESS", null);
|
"SUCCESS", null);
|
||||||
|
|
||||||
|
// 收集成功日志信息(用于微信推送)
|
||||||
|
Map<String, Object> successLog = new java.util.HashMap<>();
|
||||||
|
successLog.put("orderNo", expectedOrderNo);
|
||||||
|
successLog.put("row", row);
|
||||||
|
successLog.put("logisticsLink", logisticsLink);
|
||||||
|
if (phone != null) {
|
||||||
|
successLog.put("phone", phone);
|
||||||
|
}
|
||||||
|
successLogs.add(successLog);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("写入数据失败 - 行: {}", entry.getKey(), e);
|
log.error("写入数据失败 - 行: {}", entry.getKey(), e);
|
||||||
errorCount++;
|
errorCount++;
|
||||||
@@ -1492,6 +1511,35 @@ public class TencentDocController extends BaseController {
|
|||||||
);
|
);
|
||||||
result.put("message", message);
|
result.put("message", message);
|
||||||
|
|
||||||
|
// 更新批量推送记录状态(如果batchId存在)
|
||||||
|
if (batchId != null && !batchId.trim().isEmpty()) {
|
||||||
|
try {
|
||||||
|
String status = "SUCCESS";
|
||||||
|
if (errorCount > 0 && filledCount == 0) {
|
||||||
|
status = "FAILED";
|
||||||
|
} else if (errorCount > 0) {
|
||||||
|
status = "PARTIAL_SUCCESS";
|
||||||
|
}
|
||||||
|
batchPushService.updateBatchPushRecord(batchId, status, filledCount, skippedCount, errorCount,
|
||||||
|
message, null);
|
||||||
|
log.info("✓ 批量推送记录已更新 - batchId: {}, status: {}, 成功: {}, 跳过: {}, 错误: {}",
|
||||||
|
batchId, status, filledCount, skippedCount, errorCount);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("更新批量推送记录失败", e);
|
||||||
|
// 不影响主流程,继续执行
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 如果有成功记录,发送微信推送
|
||||||
|
if (!successLogs.isEmpty()) {
|
||||||
|
try {
|
||||||
|
sendWeChatNotification(successLogs, filledCount, skippedCount, errorCount);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("发送微信推送失败", e);
|
||||||
|
// 不影响主流程,继续返回成功
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return AjaxResult.success("填充物流链接完成", result);
|
return AjaxResult.success("填充物流链接完成", result);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("填充物流链接失败", e);
|
log.error("填充物流链接失败", e);
|
||||||
@@ -1988,6 +2036,147 @@ public class TencentDocController extends BaseController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 发送微信推送通知(同步成功日志)
|
||||||
|
*
|
||||||
|
* @param successLogs 成功日志列表
|
||||||
|
* @param filledCount 成功填充数量
|
||||||
|
* @param skippedCount 跳过数量
|
||||||
|
* @param errorCount 错误数量
|
||||||
|
*/
|
||||||
|
private void sendWeChatNotification(List<Map<String, Object>> successLogs, int filledCount, int skippedCount, int errorCount) {
|
||||||
|
try {
|
||||||
|
// 微信推送服务配置
|
||||||
|
String wxSendBaseUrl = "https://wxts.van333.cn";
|
||||||
|
String pushToken = "super_token_b62190c26";
|
||||||
|
String pushUrl = wxSendBaseUrl + "/dc/send/ty";
|
||||||
|
|
||||||
|
// 构建推送内容
|
||||||
|
StringBuilder content = new StringBuilder();
|
||||||
|
content.append("【腾讯文档同步成功】\n\n");
|
||||||
|
content.append(String.format("✓ 成功填充: %d 条\n", filledCount));
|
||||||
|
content.append(String.format("⊘ 跳过: %d 条\n", skippedCount));
|
||||||
|
content.append(String.format("✗ 错误: %d 条\n\n", errorCount));
|
||||||
|
|
||||||
|
if (!successLogs.isEmpty()) {
|
||||||
|
content.append("【成功详情】\n");
|
||||||
|
// 最多显示20条详细记录,避免消息过长
|
||||||
|
int maxDisplay = Math.min(20, successLogs.size());
|
||||||
|
for (int i = 0; i < maxDisplay; i++) {
|
||||||
|
Map<String, Object> log = successLogs.get(i);
|
||||||
|
String orderNo = (String) log.get("orderNo");
|
||||||
|
Integer row = (Integer) log.get("row");
|
||||||
|
String logisticsLink = (String) log.get("logisticsLink");
|
||||||
|
String phone = (String) log.get("phone");
|
||||||
|
|
||||||
|
content.append(String.format("%d. 单号: %s\n", i + 1, orderNo));
|
||||||
|
content.append(String.format(" 行号: %d\n", row));
|
||||||
|
if (phone != null && !phone.isEmpty()) {
|
||||||
|
content.append(String.format(" 电话: %s\n", phone));
|
||||||
|
}
|
||||||
|
content.append(String.format(" 物流: %s\n", logisticsLink));
|
||||||
|
if (i < maxDisplay - 1) {
|
||||||
|
content.append("\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (successLogs.size() > maxDisplay) {
|
||||||
|
content.append(String.format("\n... 还有 %d 条记录未显示", successLogs.size() - maxDisplay));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 构建请求体
|
||||||
|
JSONObject requestBody = new JSONObject();
|
||||||
|
requestBody.put("title", "腾讯文档同步成功");
|
||||||
|
requestBody.put("text", content.toString());
|
||||||
|
requestBody.put("vanToken", pushToken);
|
||||||
|
requestBody.put("messageType", "TY");
|
||||||
|
// touser 可以为空,使用默认接收人
|
||||||
|
|
||||||
|
String jsonBody = requestBody.toJSONString();
|
||||||
|
|
||||||
|
// 发送POST请求
|
||||||
|
String result = sendPostRequest(pushUrl, jsonBody, pushToken);
|
||||||
|
|
||||||
|
log.info("微信推送发送完成 - URL: {}, 响应: {}", pushUrl, result);
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("发送微信推送失败", e);
|
||||||
|
throw new RuntimeException("发送微信推送失败: " + e.getMessage(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 发送POST请求到微信推送服务
|
||||||
|
*
|
||||||
|
* @param url 请求URL
|
||||||
|
* @param jsonBody JSON请求体
|
||||||
|
* @param token 认证token
|
||||||
|
* @return 响应结果
|
||||||
|
*/
|
||||||
|
private String sendPostRequest(String url, String jsonBody, String token) {
|
||||||
|
java.io.BufferedReader in = null;
|
||||||
|
java.io.PrintWriter out = null;
|
||||||
|
StringBuilder result = new StringBuilder();
|
||||||
|
try {
|
||||||
|
java.net.URL realUrl = new java.net.URL(url);
|
||||||
|
java.net.URLConnection conn = realUrl.openConnection();
|
||||||
|
|
||||||
|
// 设置请求头
|
||||||
|
conn.setRequestProperty("accept", "*/*");
|
||||||
|
conn.setRequestProperty("connection", "Keep-Alive");
|
||||||
|
conn.setRequestProperty("user-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64)");
|
||||||
|
conn.setRequestProperty("Accept-Charset", "utf-8");
|
||||||
|
conn.setRequestProperty("Content-Type", "application/json");
|
||||||
|
conn.setRequestProperty("vanToken", token);
|
||||||
|
|
||||||
|
conn.setDoOutput(true);
|
||||||
|
conn.setDoInput(true);
|
||||||
|
|
||||||
|
// 设置超时时间
|
||||||
|
conn.setConnectTimeout(10000); // 10秒连接超时
|
||||||
|
conn.setReadTimeout(10000); // 10秒读取超时
|
||||||
|
|
||||||
|
// 发送请求体
|
||||||
|
out = new java.io.PrintWriter(conn.getOutputStream());
|
||||||
|
out.print(jsonBody);
|
||||||
|
out.flush();
|
||||||
|
|
||||||
|
// 读取响应
|
||||||
|
in = new java.io.BufferedReader(new java.io.InputStreamReader(conn.getInputStream(), java.nio.charset.StandardCharsets.UTF_8));
|
||||||
|
String line;
|
||||||
|
while ((line = in.readLine()) != null) {
|
||||||
|
result.append(line);
|
||||||
|
}
|
||||||
|
|
||||||
|
log.debug("微信推送请求成功 - URL: {}, 响应: {}", url, result.toString());
|
||||||
|
} catch (java.net.ConnectException e) {
|
||||||
|
log.error("微信推送连接失败 - URL: {}", url, e);
|
||||||
|
throw new RuntimeException("连接失败: " + e.getMessage(), e);
|
||||||
|
} catch (java.net.SocketTimeoutException e) {
|
||||||
|
log.error("微信推送请求超时 - URL: {}", url, e);
|
||||||
|
throw new RuntimeException("请求超时: " + e.getMessage(), e);
|
||||||
|
} catch (java.io.IOException e) {
|
||||||
|
log.error("微信推送IO异常 - URL: {}", url, e);
|
||||||
|
throw new RuntimeException("IO异常: " + e.getMessage(), e);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("微信推送异常 - URL: {}", url, e);
|
||||||
|
throw new RuntimeException("推送异常: " + e.getMessage(), e);
|
||||||
|
} finally {
|
||||||
|
try {
|
||||||
|
if (out != null) {
|
||||||
|
out.close();
|
||||||
|
}
|
||||||
|
if (in != null) {
|
||||||
|
in.close();
|
||||||
|
}
|
||||||
|
} catch (java.io.IOException ex) {
|
||||||
|
log.error("关闭流异常", ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result.toString();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 清理物流链接
|
* 清理物流链接
|
||||||
* 去除空格、换行符、制表符、中文等特殊字符,只保留URL有效字符
|
* 去除空格、换行符、制表符、中文等特殊字符,只保留URL有效字符
|
||||||
|
|||||||
Reference in New Issue
Block a user