@@ -2,6 +2,7 @@ package com.volvo.ai.analytic.center.service.impl;
import cn.hutool.core.date.DatePattern ;
import cn.hutool.core.date.DatePattern ;
import cn.hutool.core.date.DateUtil ;
import cn.hutool.core.date.DateUtil ;
import com.alibaba.fastjson.JSONArray ;
import com.alibaba.fastjson.JSONObject ;
import com.alibaba.fastjson.JSONObject ;
import com.huaweicloud.sdk.eg.v1.model.CloudEvents ;
import com.huaweicloud.sdk.eg.v1.model.CloudEvents ;
import com.volvo.ai.analytic.center.dto.corpus.AicorpusTelephoneDTO ;
import com.volvo.ai.analytic.center.dto.corpus.AicorpusTelephoneDTO ;
@@ -14,6 +15,7 @@ import com.volvo.ai.analytic.center.dto.resp.ResultDTO;
import com.volvo.ai.analytic.center.entity.* ;
import com.volvo.ai.analytic.center.entity.* ;
import com.volvo.ai.analytic.center.enums.BizEnum ;
import com.volvo.ai.analytic.center.enums.BizEnum ;
import com.volvo.ai.analytic.center.enums.BusinessTypeEnum ;
import com.volvo.ai.analytic.center.enums.BusinessTypeEnum ;
import com.volvo.ai.analytic.center.enums.CategoryEnum ;
import com.volvo.ai.analytic.center.feign.CompetingBrandsClient ;
import com.volvo.ai.analytic.center.feign.CompetingBrandsClient ;
import com.volvo.ai.analytic.center.mapper.TmOdsVdqwMessagearchivingMapper ;
import com.volvo.ai.analytic.center.mapper.TmOdsVdqwMessagearchivingMapper ;
import com.volvo.ai.analytic.center.service.* ;
import com.volvo.ai.analytic.center.service.* ;
@@ -98,32 +100,71 @@ public class CorpusPortraitServiceImpl implements CorpusPortraitService {
diFyImageReq . setUser ( ConstantStr . corpus_user ) ;
diFyImageReq . setUser ( ConstantStr . corpus_user ) ;
diFyImageReq . setFlowId ( dccToken ) ;
diFyImageReq . setFlowId ( dccToken ) ;
JSONObject jsonObject = JSONObject . parseObject ( aicorpusTelephone . getDisplay ( ) ) ;
String chatCont ent = tmTelephoneCorpusService . processChatSegments ( aicorpusTelephone . getDisplay ( ) , maskingRuleItems ) ;
JSONArray segm ents = jsonObject . getJSONArray ( " segments " ) ;
if ( ch atC ontent = = null ) {
Long audioDur ati on = jsonObject . getLong ( " audio_duration " ) ; // 毫秒
if ( audioDuration / 1000 < = 10 ) {
log . info ( " 电话语料时长小于10秒, 不进行dify处理 " ) ;
return ;
return ;
}
}
if ( segments = = null | | segments . isEmpty ( ) ) {
log . info ( " 电话语料内容segments为空, 不进行dify处理 " ) ;
return ;
}
// 遍历 segments
StringBuffer chatList = new StringBuffer ( ) ;
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 " ) ;
String title = " " ;
if ( role . equals ( " AGENT " ) ) {
title = " 顾问 " ;
} else {
title = " 客户 " ;
}
// 拼接 role 和 text
String chat = title + " : " + text ;
runMaskingRuleInput . setOldStr ( chat ) ;
String corpusChat = dataMaskingRuleService . runMaskingRule ( runMaskingRuleInput ) ;
chatList . append ( corpusChat ) . append ( " \ n " ) ;
} ) ;
ZonedDateTime zonedDateTime = ZonedDateTime . parse ( JSONObject . parseObject ( aicorpusTelephone . getDisplay ( ) ) . getString ( " start_time " ) ) ;
ZonedDateTime zonedDateTime = ZonedDateTime . parse ( JSONObject . parseObject ( aicorpusTelephone . getDisplay ( ) ) . getString ( " start_time " ) ) ;
DateTimeFormatter formatter = DateTimeFormatter . ofPattern ( " yyyy-MM-dd HH:mm:ss " ) ;
DateTimeFormatter formatter = DateTimeFormatter . ofPattern ( " yyyy-MM-dd HH:mm:ss " ) ;
String formattedDateStartTime = zonedDateTime . format ( formatter ) ;
String formattedDateStartTime = zonedDateTime . format ( formatter ) ;
inputMap . put ( " chat " , chatConten t ) ;
inputMap . put ( " chat " , chatLis t ) ;
inputMap . put ( " recordId " , aicorpusTelephone . getSourceId ( ) ) ;
inputMap . put ( " recordId " , aicorpusTelephone . getSourceId ( ) ) ;
inputMap . put ( " communicateDate " , formattedDateStartTime ) ;
inputMap . put ( " communicateDate " , formattedDateStartTime ) ;
inputMap . put ( " brand " , getBrand ( ) ) ;
inputMap . put ( " brand " , getBrand ( ) ) ;
inputMap . put ( " brandSeries " , getSeriesByBrandId ( ) ) ;
inputMap . put ( " brandSeries " , getSeriesByBrandId ( ) ) ;
inputMap . put ( " customerFlowId " , aicorpusTelephone . getSourceId ( ) ) ;
diFyImageReq . setInputs ( inputMap ) ;
diFyImageReq . setInputs ( inputMap ) ;
CorpusReportDTO corpusReportDTO = new CorpusReportDTO ( ) ;
CorpusReportDTO corpusReportDTO = new CorpusReportDTO ( ) ;
corpusReportDTO . setCorpusTime ( formattedDateStartTime ) ;
corpusReportDTO . setCorpusTime ( formattedDateStartTime ) ;
corpusReportDTO . setRecordId ( aicorpusTelephone . getSourceId ( ) ) ;
corpusReportDTO . setRecordId ( aicorpusTelephone . getSourceId ( ) ) ;
corpusReportDTO . setAnalysisScene ( 2l ) ;
// 获取配置
// 获取配置
JSONObject execDifyFlow = diFyService . executeDifyFlow ( diFyImageReq , BusinessTypeEnum . CORPUS_PORTRAIT_DCC . getCode ( ) , JSONObject . toJSONString ( corpusReportDTO ) , aicorpusTelephone . getAiAnalysisRequestId ( ) ) ;
JSONObject execDifyFlow = diFyService . executeDifyFlow ( diFyImageReq , BusinessTypeEnum . CORPUS_PORTRAIT_DCC . getCode ( ) , JSONObject . toJSONString ( corpusReportDTO ) , aicorpusTelephone . getAiAnalysisRequestId ( ) ) ;
log . info ( " runDify execDifyFlow {} " , execDifyFlow ) ;
log . info ( " runDify execDifyFlow {} " , execDifyFlow ) ;
String aiAnalysisRequestId = execDifyFlow . getString ( " aiAnalysisRequestId " ) ;
String aiAnalysisRequestId = execDifyFlow . getString ( " aiAnalysisRequestId " ) ;
if ( null ! = execDifyFlow & & execDifyFlow . get ( " status " ) . equals ( " succeeded " ) ) {
if ( null ! = execDifyFlow & & execDifyFlow . get ( " status " ) . equals ( " succeeded " ) ) {
JSONObject text = execDifyFlow . getJSONObject ( " outputs " ) ;
JSONObject text = execDifyFlow . getJSONObject ( " outputs " ) ;
// huaWeiService.sendEvent(setCloudEvents(aiAnalysisRequestId, text.toJSONString(), "DCC"), ltoChannelId);
// 发送MQ
log . info ( " send mq , DCC语料, 画像场景 {} " , text ) ;
tmTelephoneCorpusService . sendMq ( BusinessTypeEnum . CORPUS_PORTRAIT_DCC . getCode ( ) , text . toJSONString ( ) ) ;
huaWeiService . sendEvent ( setCloudEvents ( aiAnalysisRequestId , text . toJSONString ( ) , " DCC " ) , ltoChannelId ) ;
aiAnalysisRequestLogsService . saveAiAnalysisRequestLogs ( AiAnalysisRequestLogs . builder ( ) . aiAnalysisRequestId ( execDifyFlow . getString ( " aiAnalysisRequestId " ) ) . businessResponse ( text . toJSONString ( ) ) . build ( ) ) ;
aiAnalysisRequestLogsService . saveAiAnalysisRequestLogs ( AiAnalysisRequestLogs . builder ( ) . aiAnalysisRequestId ( execDifyFlow . getString ( " aiAnalysisRequestId " ) ) . businessResponse ( text . toJSONString ( ) ) . build ( ) ) ;
}
}
@@ -223,7 +264,10 @@ public class CorpusPortraitServiceImpl implements CorpusPortraitService {
if ( null ! = execDifyFlow & & execDifyFlow . get ( " status " ) . equals ( " succeeded " ) ) {
if ( null ! = execDifyFlow & & execDifyFlow . get ( " status " ) . equals ( " succeeded " ) ) {
JSONObject text = execDifyFlow . getJSONObject ( " outputs " ) ;
JSONObject text = execDifyFlow . getJSONObject ( " outputs " ) ;
huaWeiService. sendEvent( setCloudEvents( aiAnalysisRequestId, text . toJSONString ( ) , " QIWEI " ) , ltoChannelId) ;
// huaWeiService. sendEvent( setCloudEvents( aiAnalysisRequestId, text.toJSONString(),"QIWEI"), ltoChannelId) ;
log . info ( " send mq ,企微语料,画像场景 {} " , text ) ;
tmTelephoneCorpusService . sendMq ( BusinessTypeEnum . CORPUS_PORTRAIT_QIWEI . getCode ( ) , text . toJSONString ( ) ) ;
aiAnalysisRequestLogsService . saveAiAnalysisRequestLogs ( AiAnalysisRequestLogs . builder ( ) . aiAnalysisRequestId ( execDifyFlow . getString ( " aiAnalysisRequestId " ) ) . businessResponse ( text . toJSONString ( ) ) . build ( ) ) ;
aiAnalysisRequestLogsService . saveAiAnalysisRequestLogs ( AiAnalysisRequestLogs . builder ( ) . aiAnalysisRequestId ( execDifyFlow . getString ( " aiAnalysisRequestId " ) ) . businessResponse ( text . toJSONString ( ) ) . build ( ) ) ;
}
}
@@ -270,7 +314,9 @@ public class CorpusPortraitServiceImpl implements CorpusPortraitService {
if ( null ! = execDifyFlow & & execDifyFlow . get ( " status " ) . equals ( " succeeded " ) ) {
if ( null ! = execDifyFlow & & execDifyFlow . get ( " status " ) . equals ( " succeeded " ) ) {
JSONObject text = execDifyFlow . getJSONObject ( " outputs " ) ;
JSONObject text = execDifyFlow . getJSONObject ( " outputs " ) ;
huaWeiService. sendEvent( setCloudEvents( aiAnalysisRequestId, text . toJSONString ( ) , " NAMEPLATE " ) , ltoChannelId) ;
// huaWeiService. sendEvent( setCloudEvents( aiAnalysisRequestId, text.toJSONString(),"NAMEPLATE"), ltoChannelId) ;
log . info ( " send mq ,铭牌语料,画像场景 {} " , text ) ;
tmTelephoneCorpusService . sendMq ( BusinessTypeEnum . CORPUS_PORTRAIT_NAMEPLATE . getCode ( ) , text . toJSONString ( ) ) ;
aiAnalysisRequestLogsService . saveAiAnalysisRequestLogs ( AiAnalysisRequestLogs . builder ( ) . aiAnalysisRequestId ( execDifyFlow . getString ( " aiAnalysisRequestId " ) ) . businessResponse ( text . toJSONString ( ) ) . build ( ) ) ;
aiAnalysisRequestLogsService . saveAiAnalysisRequestLogs ( AiAnalysisRequestLogs . builder ( ) . aiAnalysisRequestId ( execDifyFlow . getString ( " aiAnalysisRequestId " ) ) . businessResponse ( text . toJSONString ( ) ) . build ( ) ) ;