舆情自动化上线分支移除代码
This commit is contained in:
@@ -1,154 +0,0 @@
|
||||
package com.volvo.ai.analytic.center.service.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.volvo.ai.analytic.center.dto.corpus.AicorpusTelephoneDTO;
|
||||
import com.volvo.ai.analytic.center.dto.req.CarModelReqDTO;
|
||||
import com.volvo.ai.analytic.center.dto.req.DiFyReq;
|
||||
import com.volvo.ai.analytic.center.dto.resp.CarModelRespDTO;
|
||||
import com.volvo.ai.analytic.center.dto.resp.ResultDTO;
|
||||
import com.volvo.ai.analytic.center.entity.TmTelephoneCorpus;
|
||||
import com.volvo.ai.analytic.center.enums.BizEnum;
|
||||
import com.volvo.ai.analytic.center.enums.BusinessTypeEnum;
|
||||
import com.volvo.ai.analytic.center.feign.RemoteCarModelClient;
|
||||
import com.volvo.ai.analytic.center.mapper.TmTelephoneCorpusMapper;
|
||||
import com.volvo.ai.analytic.center.service.DiFyService;
|
||||
import com.volvo.ai.analytic.center.service.TmTelephoneCorpusService;
|
||||
import com.volvo.ai.analytic.center.utils.FlowResultSplitUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.rocketmq.client.producer.SendCallback;
|
||||
import org.apache.rocketmq.client.producer.SendResult;
|
||||
import org.apache.rocketmq.spring.core.RocketMQTemplate;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.messaging.support.MessageBuilder;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
||||
/**
|
||||
* @description 电话语料表-同步表
|
||||
* @author rz
|
||||
* @date 2025-03-04
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class TmTelephoneCorpusServiceImpl extends ServiceImpl<TmTelephoneCorpusMapper, TmTelephoneCorpus> implements TmTelephoneCorpusService {
|
||||
|
||||
|
||||
@Autowired
|
||||
private DiFyService diFyService;
|
||||
|
||||
@Resource
|
||||
private RocketMQTemplate rocketMqTemplate;
|
||||
|
||||
@Value("${rocketmq.corpusTelephone.topic}")
|
||||
private String topic;
|
||||
|
||||
@Autowired
|
||||
private RemoteCarModelClient remoteCarModelClient;
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void saveTelephoneCorpus(TmTelephoneCorpus tmTelephoneCorpus) {
|
||||
this.save(tmTelephoneCorpus);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runDify(AicorpusTelephoneDTO aicorpusTelephone) {
|
||||
|
||||
if(null != aicorpusTelephone){
|
||||
|
||||
Map<String, Object> inputMap = new HashMap();
|
||||
DiFyReq diFyImageReq = new DiFyReq();
|
||||
diFyImageReq.setUser("11111");
|
||||
diFyImageReq.setFlowId("app-peJXSjHjVKdkYxjdOUuPnZ5b");
|
||||
|
||||
|
||||
JSONObject jsonObject = JSONObject.parseObject( aicorpusTelephone.getDisplay());
|
||||
JSONArray segments = jsonObject.getJSONArray("segments");
|
||||
// 遍历 segments
|
||||
segments.stream()
|
||||
.map(segment -> (JSONObject) segment)
|
||||
.forEach(segment -> {
|
||||
JSONObject result = segment.getJSONObject("result");
|
||||
String text = result.getString("text");
|
||||
JSONObject analysisInfo = result.getJSONObject("analysis_info");
|
||||
String role = analysisInfo.getString("role");
|
||||
|
||||
// 拼接 role 和 text
|
||||
String chat = role + ": " + text;
|
||||
inputMap.put("chat",chat);
|
||||
});
|
||||
|
||||
|
||||
inputMap.put("model",getCarModelList());
|
||||
diFyImageReq.setInputs(inputMap);
|
||||
// 获取配置
|
||||
JSONObject execDifyFlow = diFyService.execDifyFlow(diFyImageReq, BusinessTypeEnum.SMART_ASSISTANT.getCode());
|
||||
log.info("runDify execDifyFlow {}",execDifyFlow);
|
||||
if(null != execDifyFlow && execDifyFlow.get("status").equals("succeeded")){
|
||||
|
||||
String text = execDifyFlow.getJSONObject("outputs").getString("text");
|
||||
String resultStrOne = FlowResultSplitUtil.flowOutputTextSplit(text, "任务1", "任务2");
|
||||
String resultStrTwo =FlowResultSplitUtil.flowOutputTextSplit(text, "任务2", null);
|
||||
Map<String, String> ltoMap = new HashMap();
|
||||
ltoMap.put("analysisRecordId", aicorpusTelephone.getSourceId());
|
||||
ltoMap.put("analysisScene", "2");
|
||||
// ltoMap.put("unionId", aicorpusTelephone.getSourceId());
|
||||
ltoMap.put("recordId", aicorpusTelephone.getSourceId());
|
||||
ltoMap.put("communicateDate", jsonObject.getString("start_time"));
|
||||
ltoMap.put("analysisResult", resultStrOne);
|
||||
ltoMap.put("analysisDetail", resultStrTwo);
|
||||
// 发送MQ
|
||||
|
||||
log.info("send mq {}",ltoMap);
|
||||
rocketMqTemplate.asyncSend(topic, MessageBuilder.withPayload(JSON.toJSONString(ltoMap)).build(),
|
||||
new SendCallback() {
|
||||
@Override
|
||||
public void onSuccess(SendResult sendResult) {
|
||||
log.info("发送导入标签值成功 消息体:{}", JSON.toJSONString(ltoMap));
|
||||
}
|
||||
@Override
|
||||
public void onException(Throwable e) {
|
||||
log.error("发送导入标签值异常 消息体:{}, 异常:", JSON.toJSONString(ltoMap), e);
|
||||
}
|
||||
}, 10000);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private String getCarModelList(){
|
||||
try {
|
||||
long startTime = System.currentTimeMillis();
|
||||
CarModelReqDTO carModelReqDTO = new CarModelReqDTO();
|
||||
carModelReqDTO.setOnSale(10041001);
|
||||
carModelReqDTO.setIsValid(10041001);
|
||||
ResultDTO<List<CarModelRespDTO>> cardModelResult= remoteCarModelClient.queryCarModelList(carModelReqDTO);
|
||||
log.info("queryCarModelList 导出查询耗时开始时间:{}",System.currentTimeMillis()-startTime);
|
||||
if (BizEnum.SUCCESS.getCode().toString().equals(cardModelResult.getReturnCode()) && CollectionUtils.isNotEmpty(cardModelResult.getData())) {
|
||||
List<CarModelRespDTO> carModelRespDTOList = cardModelResult.getData();
|
||||
// 拼接 modelName
|
||||
String modelNames = carModelRespDTOList.stream()
|
||||
.map(CarModelRespDTO::getModelName) // 提取 modelName
|
||||
.collect(Collectors.joining(", ")); // 用逗号和空格拼接
|
||||
|
||||
log.info("拼接后的车型名称: {}", modelNames);
|
||||
return modelNames;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("getCarModelList Exception: {}", e);
|
||||
}
|
||||
return "C40 RECHARGE、EM90、EX30、S60、S90、V60、V90、XC40、XC40 RECHARGE、XC60、XC90";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user