发布时间处理
This commit is contained in:
@@ -129,34 +129,8 @@ public class SpokesManService {
|
|||||||
JSONObject difSpokesManResult = (JSONObject) diFyService.getDiFyObject(diFyReq);
|
JSONObject difSpokesManResult = (JSONObject) diFyService.getDiFyObject(diFyReq);
|
||||||
difSpokesManResult.put("communityRequestId", spokesManDTO.getCommunityRequestId());
|
difSpokesManResult.put("communityRequestId", spokesManDTO.getCommunityRequestId());
|
||||||
difSpokesManResult.put("aiAnalysisRequestId", aiAnalysisRequestId);
|
difSpokesManResult.put("aiAnalysisRequestId", aiAnalysisRequestId);
|
||||||
|
|
||||||
//处理发布时间
|
//处理发布时间
|
||||||
// 获取原始时间字段
|
updatePublishedTime(difSpokesManResult);
|
||||||
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 cloudEvents = new CloudEvents();
|
||||||
cloudEvents.setData(difSpokesManResult);
|
cloudEvents.setData(difSpokesManResult);
|
||||||
@@ -165,7 +139,6 @@ public class SpokesManService {
|
|||||||
cloudEvents.setDatacontenttype("application/json");
|
cloudEvents.setDatacontenttype("application/json");
|
||||||
cloudEvents.setType("SPOKESMAN");
|
cloudEvents.setType("SPOKESMAN");
|
||||||
cloudEvents.setId(aiAnalysisRequestId);
|
cloudEvents.setId(aiAnalysisRequestId);
|
||||||
log.info("发送特邀发言官事件消息:{}",difSpokesManResult.toString());
|
|
||||||
huaWeiEGService.sendEvent(cloudEvents, channelId);
|
huaWeiEGService.sendEvent(cloudEvents, channelId);
|
||||||
//异步更新dify响应日志
|
//异步更新dify响应日志
|
||||||
syncUpdateDiFyResponse(difSpokesManResult, aiAnalysisRequestId);
|
syncUpdateDiFyResponse(difSpokesManResult, aiAnalysisRequestId);
|
||||||
@@ -180,24 +153,33 @@ public class SpokesManService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void updatePublishedTime(JSONObject rootJson) {
|
||||||
|
String contentAnalysisResultStr = rootJson.getString("ContentAnalysisResult");
|
||||||
|
if (contentAnalysisResultStr == null || contentAnalysisResultStr.isEmpty()) return;
|
||||||
|
|
||||||
String str = "{\n" +
|
JSONObject contentAnalysisResult = JSON.parseObject(contentAnalysisResultStr);
|
||||||
"\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" +
|
JSONObject contentAnalysisReport = contentAnalysisResult.getJSONObject("contentAnalysisReport");
|
||||||
"\t\"auditReport\": \"{\\n \\\"auditReport\\\": {\\n \\\"auditRule\\\": \\\"1. 根据是否需要订阅判定是否为本人发布,需要订阅的为非本人发布;2. 互动量要累计点赞、评论、收藏、转发的总数。\\\",\\n \\\"auditResult\\\": \\\"PASS\\\",\\n \\\"reportsummary\\\": \\\"审核通过。内容为本人发布,无需订阅;互动量数据为空,暂无风险检测异常问题。\\\"\\n }\\n}\"\n" +
|
if (contentAnalysisReport == null) return;
|
||||||
"}";
|
|
||||||
|
|
||||||
String str1 = "{\n" +
|
JSONObject publishedContentOuter = contentAnalysisReport.getJSONObject("publishedContent");
|
||||||
"\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" +
|
if (publishedContentOuter == null) return;
|
||||||
"\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 publishedContentInner = publishedContentOuter.getJSONObject("publishedContent");
|
||||||
JSONObject difSpokesManResult = JSON.parseObject(str1);
|
if (publishedContentInner == null) return;
|
||||||
String publishedTime = difSpokesManResult.getJSONObject("ContentAnalysisResult").getJSONObject("contentAnalysisReport").getJSONObject("publishedContent").getJSONObject("publishedContent").getString("publishedTime");
|
|
||||||
//处理publishedTime转换为年月日,年默认为当前年
|
String publishedTime = publishedContentInner.getString("publishedTime");
|
||||||
System.out.println(publishedTime);
|
String formattedPublishedTime = PublishedTimeFormatter.parsePublishedTime(publishedTime);
|
||||||
|
|
||||||
|
if (formattedPublishedTime != null) {
|
||||||
|
publishedContentInner.put("publishedTime", formattedPublishedTime);
|
||||||
|
publishedContentOuter.put("publishedContent", publishedContentInner);
|
||||||
|
contentAnalysisReport.put("publishedContent", publishedContentOuter);
|
||||||
|
contentAnalysisResult.put("contentAnalysisReport", contentAnalysisReport);
|
||||||
|
rootJson.put("ContentAnalysisResult", contentAnalysisResult.toJSONString());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Async
|
@Async
|
||||||
protected void syncSaveRequestLogs(String message, String aiAnalysisRequestId) {
|
protected void syncSaveRequestLogs(String message, String aiAnalysisRequestId) {
|
||||||
aiAnalysisRequestLogsMapper.insert(AiAnalysisRequestLogs.builder()
|
aiAnalysisRequestLogsMapper.insert(AiAnalysisRequestLogs.builder()
|
||||||
|
|||||||
@@ -11,8 +11,7 @@ import java.time.temporal.ChronoUnit;
|
|||||||
@Slf4j
|
@Slf4j
|
||||||
@Component
|
@Component
|
||||||
public class PublishedTimeFormatter {
|
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:ss");
|
||||||
private static final DateTimeFormatter DATE_TIME_FORMAT = DateTimeFormatter.ofPattern("yyyy-MM-dd HH.mm");
|
|
||||||
|
|
||||||
public static String parsePublishedTime(String publishedTime) {
|
public static String parsePublishedTime(String publishedTime) {
|
||||||
if (publishedTime == null || publishedTime.isEmpty() || publishedTime.equals("\"\"")) {
|
if (publishedTime == null || publishedTime.isEmpty() || publishedTime.equals("\"\"")) {
|
||||||
@@ -22,20 +21,29 @@ public class PublishedTimeFormatter {
|
|||||||
LocalDate now = LocalDate.now();
|
LocalDate now = LocalDate.now();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// 处理 "8天前" 格式
|
// 处理 "X天前" 格式
|
||||||
if (publishedTime.endsWith("天前")) {
|
if (publishedTime.endsWith("天前")) {
|
||||||
int daysAgo = Integer.parseInt(publishedTime.replace("天前", ""));
|
int daysAgo = Integer.parseInt(publishedTime.replace("天前", ""));
|
||||||
return now.minus(daysAgo, ChronoUnit.DAYS).format(DateTimeFormatter.ISO_DATE);
|
return now.minus(daysAgo, ChronoUnit.DAYS).format(DateTimeFormatter.ISO_DATE);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 处理 "4月16日" 格式
|
// 处理 "X月X日" 格式
|
||||||
if (publishedTime.matches("\\d+月\\d+日")) {
|
if (publishedTime.matches("\\d+月\\d+日")) {
|
||||||
LocalDate parsed = LocalDate.parse(publishedTime, MONTH_DAY_FORMAT);
|
// 提取月份和日期
|
||||||
return LocalDate.of(now.getYear(), parsed.getMonth(), parsed.getDayOfMonth())
|
int monthStart = 0;
|
||||||
|
int monthEnd = publishedTime.indexOf("月");
|
||||||
|
int dayStart = monthEnd + 1;
|
||||||
|
int dayEnd = publishedTime.indexOf("日");
|
||||||
|
|
||||||
|
int monthValue = Integer.parseInt(publishedTime.substring(monthStart, monthEnd));
|
||||||
|
int dayValue = Integer.parseInt(publishedTime.substring(dayStart, dayEnd));
|
||||||
|
|
||||||
|
// 构建当年的 LocalDate 对象
|
||||||
|
return LocalDate.of(now.getYear(), monthValue, dayValue)
|
||||||
.format(DateTimeFormatter.ISO_DATE);
|
.format(DateTimeFormatter.ISO_DATE);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 处理 "2025-05-06 23.00" 格式
|
// 处理 "2025-05-06 23:00:00" 格式
|
||||||
if (publishedTime.contains("-")) {
|
if (publishedTime.contains("-")) {
|
||||||
LocalDateTime parsed = LocalDateTime.parse(publishedTime, DATE_TIME_FORMAT);
|
LocalDateTime parsed = LocalDateTime.parse(publishedTime, DATE_TIME_FORMAT);
|
||||||
return parsed.toLocalDate().format(DateTimeFormatter.ISO_DATE);
|
return parsed.toLocalDate().format(DateTimeFormatter.ISO_DATE);
|
||||||
@@ -43,7 +51,7 @@ public class PublishedTimeFormatter {
|
|||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
// 可记录异常或忽略错误格式
|
// 可记录异常或忽略错误格式
|
||||||
System.err.println("无法解析时间: " + publishedTime);
|
log.error("无法解析时间:{} " ,publishedTime);
|
||||||
}
|
}
|
||||||
return null; // 未知格式返回null
|
return null; // 未知格式返回null
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user