This commit is contained in:
van
2026-09-06 22:59:07 +08:00
parent 98246ce76b
commit 50284741b2
@@ -214,10 +214,13 @@ public class OrderProfitAnalysisServiceImpl implements IOrderProfitAnalysisServi
boolean pushed = false;
String pushError = null;
int chunkCount = 0;
String toUser = resolveTouser();
if (push) {
try {
pushed = pushReport(current.titlePrefix, report, toUser);
List<String> chunks = buildPushChunks(current.titlePrefix, report);
chunkCount = chunks.size();
pushed = pushChunks(chunks, toUser);
if (!pushed) {
pushError = StringUtils.isEmpty(toUser)
? "未配置接收人(touser / goofish-notify-touser)"
@@ -240,6 +243,7 @@ public class OrderProfitAnalysisServiceImpl implements IOrderProfitAnalysisServi
result.put("pushed", pushed);
result.put("pushError", pushError);
result.put("toUser", toUser);
result.put("chunkCount", chunkCount);
cacheLatest(normalizePeriod(periodType), result);
if (push) {
appendSendLog(result, stats);
@@ -423,7 +427,13 @@ public class OrderProfitAnalysisServiceImpl implements IOrderProfitAnalysisServi
return data.getString("reply");
}
private boolean pushReport(String title, String report, String toUser) {
private List<String> buildPushChunks(String title, String report) {
String body = stripThinkTags(report);
String full = (title == null ? "" : title) + "\n" + (body == null ? "" : body);
return labelChunks(splitUtf8Chunks(full, WECOM_CHUNK_BYTES));
}
private boolean pushChunks(List<String> chunks, String toUser) {
if (phoneForwardActivePush == null) {
log.warn("利润分析推送跳过:IPhoneForwardActivePush 不可用");
return false;
@@ -432,12 +442,28 @@ public class OrderProfitAnalysisServiceImpl implements IOrderProfitAnalysisServi
log.warn("利润分析推送跳过:未配置 jarvis.order-profit-analysis.touser 或 jarvis.wecom.goofish-notify-touser");
return false;
}
String body = stripThinkTags(report);
String full = (title == null ? "" : title) + "\n" + (body == null ? "" : body);
List<String> chunks = splitUtf8Chunks(full, WECOM_CHUNK_BYTES);
if (chunks == null || chunks.isEmpty()) {
return false;
}
log.info("利润分析推送拆成 {} 条 toUser={}", chunks.size(), toUser);
return phoneForwardActivePush.schedulePushChunks(toUser, null, chunks);
}
private static List<String> labelChunks(List<String> chunks) {
if (chunks == null || chunks.isEmpty()) {
return Collections.emptyList();
}
if (chunks.size() == 1) {
return chunks;
}
int n = chunks.size();
List<String> out = new ArrayList<>(n);
for (int i = 0; i < n; i++) {
out.add("(" + (i + 1) + "/" + n + ")\n" + chunks.get(i));
}
return out;
}
/**
* 去掉模型思考标签及其内容,避免推到企微。
* 兼容成对 {@code <think>...</think>},以及残留的开闭标签。
@@ -490,6 +516,7 @@ public class OrderProfitAnalysisServiceImpl implements IOrderProfitAnalysisServi
}
String report = result.get("report") == null ? "" : String.valueOf(result.get("report"));
row.put("report", report);
row.put("chunkCount", result.get("chunkCount"));
redisTemplate.opsForList().leftPush(REDIS_SEND_LOG, JSON.toJSONString(row));
redisTemplate.opsForList().trim(REDIS_SEND_LOG, 0, SEND_LOG_MAX - 1);
} catch (Exception e) {