发布时间处理
This commit is contained in:
@@ -17,6 +17,7 @@ import com.volvo.ai.analytic.center.mapper.AiAnalysisErrorsMapper;
|
||||
import com.volvo.ai.analytic.center.mapper.AiAnalysisRequestLogsMapper;
|
||||
import com.volvo.ai.analytic.center.mapper.AiAnalyticBusinessConfigMapper;
|
||||
import com.volvo.ai.analytic.center.utils.AiAnalysisUtils;
|
||||
import com.volvo.ai.analytic.center.utils.PublishedTimeFormatter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
@@ -128,6 +129,34 @@ public class SpokesManService {
|
||||
JSONObject difSpokesManResult = (JSONObject) diFyService.getDiFyObject(diFyReq);
|
||||
difSpokesManResult.put("communityRequestId", spokesManDTO.getCommunityRequestId());
|
||||
difSpokesManResult.put("aiAnalysisRequestId", aiAnalysisRequestId);
|
||||
|
||||
//处理发布时间
|
||||
// 获取原始时间字段
|
||||
String publishedTime = difSpokesManResult.getJSONObject("ContentAnalysisResult")
|
||||
.getJSONObject("contentAnalysisReport")
|
||||
.getJSONObject("publishedContent")
|
||||
.getJSONObject("publishedContent")
|
||||
.getString("publishedTime");
|
||||
|
||||
// 格式化时间
|
||||
String formattedPublishedTime = PublishedTimeFormatter.parsePublishedTime(publishedTime);
|
||||
|
||||
// 如果转换成功,则更新回 JSON 对象
|
||||
if (formattedPublishedTime != null) {
|
||||
difSpokesManResult.getJSONObject("ContentAnalysisResult")
|
||||
.getJSONObject("contentAnalysisReport")
|
||||
.getJSONObject("publishedContent")
|
||||
.getJSONObject("publishedContent")
|
||||
.put("publishedTime", formattedPublishedTime);
|
||||
} else {
|
||||
// 可选:设置为空或默认值
|
||||
difSpokesManResult.getJSONObject("ContentAnalysisResult")
|
||||
.getJSONObject("contentAnalysisReport")
|
||||
.getJSONObject("publishedContent")
|
||||
.getJSONObject("publishedContent")
|
||||
.put("publishedTime", "");
|
||||
}
|
||||
|
||||
//发送事件网格
|
||||
CloudEvents cloudEvents = new CloudEvents();
|
||||
cloudEvents.setData(difSpokesManResult);
|
||||
@@ -136,6 +165,7 @@ public class SpokesManService {
|
||||
cloudEvents.setDatacontenttype("application/json");
|
||||
cloudEvents.setType("SPOKESMAN");
|
||||
cloudEvents.setId(aiAnalysisRequestId);
|
||||
log.info("发送特邀发言官事件消息:{}",difSpokesManResult.toString());
|
||||
huaWeiEGService.sendEvent(cloudEvents, channelId);
|
||||
//异步更新dify响应日志
|
||||
syncUpdateDiFyResponse(difSpokesManResult, aiAnalysisRequestId);
|
||||
@@ -150,6 +180,24 @@ public class SpokesManService {
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
String str = "{\n" +
|
||||
"\t\"ContentAnalysisResult\": \"{\\n \\\"contentAnalysisReport\\\": {\\n \\\"publishedContent\\\": {\\n \\\"publisherAccount\\\": \\\"\\\",\\n \\\"needSubscribe\\\": \\\"No\\\",\\n \\\"publishedContent\\\": {\\n \\\"contentType\\\": \\\"Normal\\\",\\n \\\"matchTheme\\\": \\\"Yes\\\",\\n \\\"publishedTime\\\": \\\"\\\",\\n \\\"contentOverview\\\": \\\"图片展示了一辆沃尔沃全新XC90停在一座传统建筑前,背景为山景和古建筑。\\\",\\n \\\"pictureOverview\\\": \\\"图片内容为一辆沃尔沃全新XC90停在传统建筑前,共有2张图片。\\\",\\n \\\"topicTags\\\": []\\n }\\n },\\n \\\"indicatorData\\\": {\\n \\\"contentTopic\\\": \\\"沃尔沃全新XC90\\\",\\n \\\"countCharacters\\\": 0,\\n \\\"totalNumberOfPictures\\\": 2,\\n \\\"videoDuration\\\": \\\"\\\",\\n \\\"interactionVolume\\\": {\\n \\\"read\\\": \\\"\\\",\\n \\\"like\\\": \\\"\\\",\\n \\\"collection\\\": \\\"\\\",\\n \\\"comment\\\": \\\"\\\",\\n \\\"forward\\\": \\\"\\\"\\n }\\n },\\n \\\"riskDetection\\\": {\\n \\\"sensitiveWords\\\": \\\"NOT\\\",\\n \\\"sensitiveContent\\\": \\\"\\\"\\n }\\n }\\n}\",\n" +
|
||||
"\t\"auditReport\": \"{\\n \\\"auditReport\\\": {\\n \\\"auditRule\\\": \\\"1. 根据是否需要订阅判定是否为本人发布,需要订阅的为非本人发布;2. 互动量要累计点赞、评论、收藏、转发的总数。\\\",\\n \\\"auditResult\\\": \\\"PASS\\\",\\n \\\"reportsummary\\\": \\\"审核通过。内容为本人发布,无需订阅;互动量数据为空,暂无风险检测异常问题。\\\"\\n }\\n}\"\n" +
|
||||
"}";
|
||||
|
||||
String str1 = "{\n" +
|
||||
"\t\"ContentAnalysisResult\": \"{\\n\\t\\\"contentAnalysisReport\\\": {\\n\\t\\t\\\"publishedContent\\\": {\\n\\t\\t\\t\\\"publisherAccount\\\": \\\"林宇 325\\\",\\n \\\"needSubscribe\\\": \\\"No\\\",\\n\\t\\t\\t\\\"publishedContent\\\": {\\n \\\"matchTheme\\\": \\\"Yes\\\", \\n\\t\\t\\t\\t\\\"publishedTime\\\": \\\"8天前\\\",\\n\\t\\t\\t\\t\\\"contentOverview\\\": \\\"心向往之 行则将至 #沃尔沃\\\",\\n\\t\\t\\t\\t\\\"pictureOverview\\\": \\\"图片内容为一辆白色汽车停在草地上,背景是多云的天空。图片总数为1张。\\\",\\n\\t\\t\\t\\t\\\"topicTags\\\": [\\\"#沃尔沃\\\"]\\n\\t\\t\\t}\\n\\t\\t},\\n\\t\\t\\\"indicatorData\\\": {\\n\\t\\t\\t\\\"contentTopic\\\": \\\"#沃尔沃\\\",\\n\\t\\t\\t\\\"countCharacters\\\": 14,\\n\\t\\t\\t\\\"totalNumberOfPictures\\\": 1,\\n\\t\\t\\t\\\"videoDuration\\\": \\\"\\\",\\n\\t\\t\\t\\\"interactionVolume\\\": {\\n\\t\\t\\t\\t\\\"like\\\": 12,\\n\\t\\t\\t\\t\\\"collection\\\": 3,\\n\\t\\t\\t\\t\\\"comment\\\": 7,\\n\\t\\t\\t\\t\\\"forward\\\": 7\\n\\t\\t\\t}\\n\\t\\t},\\n\\t\\t\\\"riskDetection\\\": {\\n\\t\\t\\t\\\"sensitiveWords\\\": \\\"NOT\\\",\\n\\t\\t\\t\\\"sensitiveContent\\\": \\\"\\\"\\n\\t\\t}\\n\\t}\\n}\",\n" +
|
||||
"\t\"auditReport\": \"{\\n \\\"auditReport\\\": {\\n \\\"auditRule\\\": \\\"必须为本人发布,视频时长≥15秒,标题内容不含敏感词,发布时间需在2025年5月31日之前,互动量(点赞+评论+收藏+转发)总和≥10,带沃尔沃相关话题。\\\",\\n \\\"auditResult\\\": \\\"FAIL\\\",\\n \\\"reportsummary\\\": \\\"审核未通过。原因如下:1. 发布内容非视频,且视频时长不足15秒;2. 互动量满足要求(总和为29),发布时间符合要求(8天前),内容匹配主题并带有沃尔沃相关话题;3. 标题内容未检测到敏感词。综上,因缺少视频及视频时长不达标,判定为未通过。\\\"\\n }\\n}\"\n" +
|
||||
"}";
|
||||
|
||||
String str2 = "{ \"ContentAnalysisResult\": \"{\\n \\\"contentAnalysisReport\\\": {\\n \\\"publishedContent\\\": {\\n \\\"publisherAccount\\\": \\\"@yoyo\\\",\\n \\\"needSubscribe\\\": \\\"Yes\\\",\\n \\\"publishedContent\\\": {\\n \\\"matchTheme\\\": \\\"Yes\\\",\\n \\\"publishedTime\\\": \\\"4月16日\\\",\\n \\\"contentOverview\\\": \\\"全新XC90耀世登场 ✨ 北欧匠心设计×六座奢适空间 以安全与豪华重新定义出行 \uD83D\uDEE1 邀您共赏旗舰风范\\\",\\n \\\"pictureOverview\\\": \\\"图片内容为沃尔沃全新XC90的发布会现场,包括主持人和活动现场的照片。图片总数为2张,当前展示的是第1张和第2张。\\\",\\n \\\"topicTags\\\": [\\\"#沃尔沃全新XC90\\\", \\\"#全新XC90进口旗舰大六座\\\"]\\n }\\n },\\n \\\"indicatorData\\\": {\\n \\\"contentTopic\\\": \\\"沃尔沃全新XC90\\\",\\n \\\"countCharacters\\\": 63,\\n \\\"totalNumberOfPictures\\\": 2,\\n \\\"videoDuration\\\": \\\"00:33\\\",\\n \\\"interactionVolume\\\": {\\n \\\"like\\\": \\\"4\\\",\\n \\\"collection\\\": \\\"\\\",\\n \\\"comment\\\": \\\"\\\",\\n \\\"forward\\\": \\\"\\\"\\n }\\n },\\n \\\"riskDetection\\\": {\\n \\\"sensitiveWords\\\": \\\"NOT\\\",\\n \\\"sensitiveContent\\\": \\\"\\\"\\n }\\n }\\n}\", \"auditReport\": \"{\\n \\\"auditReport\\\": {\\n \\\"auditRule\\\": \\\"必须为本人发布,视频时长≥15秒,标题内容不含敏感词,发布时间需在2025年5月31日之前,互动量(点赞+评论+收藏+转发)总和≥10,带沃尔沃相关话题。\\\",\\n \\\"auditResult\\\": \\\"FAIL\\\",\\n \\\"reportSummary\\\": \\\"审核未通过。原因:1. 发布账户需要订阅,判定为非本人发布;2. 互动总量不足,当前仅有4次点赞,未达到最低要求的10次互动量。\\\"\\n }\\n}\" }";
|
||||
JSONObject difSpokesManResult = JSON.parseObject(str1);
|
||||
String publishedTime = difSpokesManResult.getJSONObject("ContentAnalysisResult").getJSONObject("contentAnalysisReport").getJSONObject("publishedContent").getJSONObject("publishedContent").getString("publishedTime");
|
||||
//处理publishedTime转换为年月日,年默认为当前年
|
||||
System.out.println(publishedTime);
|
||||
}
|
||||
@Async
|
||||
protected void syncSaveRequestLogs(String message, String aiAnalysisRequestId) {
|
||||
aiAnalysisRequestLogsMapper.insert(AiAnalysisRequestLogs.builder()
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
package com.volvo.ai.analytic.center.utils;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
public class PublishedTimeFormatter {
|
||||
private static final DateTimeFormatter MONTH_DAY_FORMAT = DateTimeFormatter.ofPattern("M月d日");
|
||||
private static final DateTimeFormatter DATE_TIME_FORMAT = DateTimeFormatter.ofPattern("yyyy-MM-dd HH.mm");
|
||||
|
||||
public static String parsePublishedTime(String publishedTime) {
|
||||
if (publishedTime == null || publishedTime.isEmpty() || publishedTime.equals("\"\"")) {
|
||||
return null; // 空值直接返回null或按需处理
|
||||
}
|
||||
|
||||
LocalDate now = LocalDate.now();
|
||||
|
||||
try {
|
||||
// 处理 "8天前" 格式
|
||||
if (publishedTime.endsWith("天前")) {
|
||||
int daysAgo = Integer.parseInt(publishedTime.replace("天前", ""));
|
||||
return now.minus(daysAgo, ChronoUnit.DAYS).format(DateTimeFormatter.ISO_DATE);
|
||||
}
|
||||
|
||||
// 处理 "4月16日" 格式
|
||||
if (publishedTime.matches("\\d+月\\d+日")) {
|
||||
LocalDate parsed = LocalDate.parse(publishedTime, MONTH_DAY_FORMAT);
|
||||
return LocalDate.of(now.getYear(), parsed.getMonth(), parsed.getDayOfMonth())
|
||||
.format(DateTimeFormatter.ISO_DATE);
|
||||
}
|
||||
|
||||
// 处理 "2025-05-06 23.00" 格式
|
||||
if (publishedTime.contains("-")) {
|
||||
LocalDateTime parsed = LocalDateTime.parse(publishedTime, DATE_TIME_FORMAT);
|
||||
return parsed.toLocalDate().format(DateTimeFormatter.ISO_DATE);
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
// 可记录异常或忽略错误格式
|
||||
System.err.println("无法解析时间: " + publishedTime);
|
||||
}
|
||||
return null; // 未知格式返回null
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user