舆情自动化代码编写
This commit is contained in:
@@ -2,13 +2,15 @@ package com.volvo.ai.analytic.center.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import com.volvo.common.core.base.BaseEntity;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.*;
|
||||
|
||||
|
||||
@Data
|
||||
@Setter
|
||||
@Getter
|
||||
@TableName("tt_ai_analysis_request_logs")
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class AiAnalysisRequestLogs extends BaseEntity {
|
||||
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
|
||||
@@ -4,6 +4,7 @@ import cn.hutool.core.date.DateUtil;
|
||||
import com.alibaba.cloud.commons.lang.StringUtils;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.volvo.ai.analytic.center.constant.Constant;
|
||||
import com.volvo.ai.analytic.center.dto.req.*;
|
||||
@@ -25,6 +26,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.jdbc.core.BeanPropertyRowMapper;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
@@ -88,15 +90,8 @@ public class MqMessageRecordServiceImpl extends ServiceImpl<MqMessageRecordMappe
|
||||
}
|
||||
// 生成ai分析请求id
|
||||
String aiAnalysisRequestId = AiAnalysisUtils.getAiAnalysisRequestId(BusinessTypeEnum.COMMUNITYTARGET.getCode());
|
||||
|
||||
// 保存请求日志
|
||||
aiAnalysisRequestLogsMapper.insert(AiAnalysisRequestLogs.builder()
|
||||
.aiAnalysisRequestId(aiAnalysisRequestId)
|
||||
.businessRequest(message)
|
||||
.difyAgentKey(flowId)
|
||||
.difyRequest(JSON.toJSONString(communityTargetDTO))
|
||||
.aiAnalysisRequestType(BusinessTypeEnum.COMMUNITYTARGET.getCode())
|
||||
.build());
|
||||
// 异步保存请求日志
|
||||
syncSaveRequestLogs(message, aiAnalysisRequestId);
|
||||
|
||||
JSONObject difResult = new JSONObject();
|
||||
try {
|
||||
@@ -108,7 +103,6 @@ public class MqMessageRecordServiceImpl extends ServiceImpl<MqMessageRecordMappe
|
||||
communityTargetDTO.getContent().forEach(contentNode -> {
|
||||
if (contentNode.getNodeType().equals(NodeTypeEnum.IMAGE.getCode())) {
|
||||
//构建图片分析请求对象
|
||||
|
||||
DifyImageWorkFlow diFyImageWorkFlow = new DifyImageWorkFlow();
|
||||
diFyImageWorkFlow.setUrl(contentNode.getNodeContent());
|
||||
|
||||
@@ -133,7 +127,10 @@ public class MqMessageRecordServiceImpl extends ServiceImpl<MqMessageRecordMappe
|
||||
DifyCommunityTargetDTO difyCommunityTargetDTO = new DifyCommunityTargetDTO();
|
||||
difyCommunityTargetDTO.setTargetId(communityTargetDTO.getTargetId());
|
||||
difyCommunityTargetDTO.setTargetType(communityTargetDTO.getTargetType());
|
||||
difyCommunityTargetDTO.setTargetContent(textContent + sb.toString());
|
||||
difyCommunityTargetDTO.setTargetContent(textContent + sb);
|
||||
|
||||
//根据aiAnalysisRequestId更新请求日志表的difyRequest字段
|
||||
syncUpdateDiFyRequest(difyCommunityTargetDTO, aiAnalysisRequestId);
|
||||
|
||||
DiFyReq diFyReq = new DiFyReq();
|
||||
diFyReq.setUser(user);
|
||||
@@ -154,6 +151,8 @@ public class MqMessageRecordServiceImpl extends ServiceImpl<MqMessageRecordMappe
|
||||
//返回结果推送到社区的MQ
|
||||
rocketMQTemplate.syncSend("", JSON.toJSONString(difyCommunityTargetResult));
|
||||
log.info("舆情分析发送回调MQ完成: {}", JSON.toJSONString(difyCommunityTargetResult));
|
||||
//异步更新请求日志表的difyResponse字段
|
||||
syncUpdateDiFyResponse(difResult, aiAnalysisRequestId);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("请求DiFy异常:{}", e);
|
||||
@@ -167,6 +166,30 @@ public class MqMessageRecordServiceImpl extends ServiceImpl<MqMessageRecordMappe
|
||||
return true;
|
||||
}
|
||||
|
||||
@Async
|
||||
protected void syncUpdateDiFyRequest(DifyCommunityTargetDTO difyCommunityTargetDTO, String aiAnalysisRequestId) {
|
||||
aiAnalysisRequestLogsMapper.update(new AiAnalysisRequestLogs(),
|
||||
new UpdateWrapper<AiAnalysisRequestLogs>().set("dify_request", JSON.toJSONString(difyCommunityTargetDTO))
|
||||
.eq("ai_analysis_request_id", aiAnalysisRequestId));
|
||||
}
|
||||
|
||||
@Async
|
||||
protected void syncUpdateDiFyResponse(JSONObject difResult, String aiAnalysisRequestId) {
|
||||
aiAnalysisRequestLogsMapper.update(new AiAnalysisRequestLogs(),
|
||||
new UpdateWrapper<AiAnalysisRequestLogs>().set("business_response", difResult)
|
||||
.eq("ai_analysis_request_id", aiAnalysisRequestId));
|
||||
}
|
||||
|
||||
@Async
|
||||
protected void syncSaveRequestLogs(String message, String aiAnalysisRequestId) {
|
||||
aiAnalysisRequestLogsMapper.insert(AiAnalysisRequestLogs.builder()
|
||||
.aiAnalysisRequestId(aiAnalysisRequestId)
|
||||
.businessRequest(message)
|
||||
.difyAgentKey(flowId)
|
||||
.aiAnalysisRequestType(BusinessTypeEnum.COMMUNITYTARGET.getCode())
|
||||
.build());
|
||||
}
|
||||
|
||||
private void processMqSinceType51(MqFormData oldItem, MqMessageRecord curMQMessageRecord) {
|
||||
log.info("processMqSinceType51 辨别数据为分析请求 {}", SubSinceTypeEnum.SINCETYPE51.getCode());
|
||||
DiffDefeatanAlysis diffDefeatanAlysis = JSON.parseObject(JSON.toJSONString(oldItem.getData()), DiffDefeatanAlysis.class);
|
||||
|
||||
Reference in New Issue
Block a user