铭牌解析提交
This commit is contained in:
@@ -25,7 +25,7 @@ public class CorpusReportDTO {
|
||||
private String aiAnalysisRequestId;
|
||||
|
||||
/**
|
||||
* 语料类型【1:企业微信,2:电话】
|
||||
* 语料类型【1:企业微信,2:电话, 3:铭牌】
|
||||
*/
|
||||
private Long analysisScene;
|
||||
|
||||
@@ -46,6 +46,9 @@ public class CorpusReportDTO {
|
||||
|
||||
private String recordId;
|
||||
|
||||
private String customerFlowId;
|
||||
|
||||
private String carModel;
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,115 @@
|
||||
package com.volvo.ai.analytic.center.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @description 铭牌记录表-湖仓同步表
|
||||
* @author BEJSON
|
||||
* @date 2025-03-10
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@TableName("tm_nameplate_corpus")
|
||||
public class TmNameplateCorpus {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 主键id
|
||||
*/
|
||||
@TableId(value="id", type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 客流id
|
||||
*/
|
||||
@TableField(value="customer_flow_id")
|
||||
private String customerFlowId;
|
||||
|
||||
/**
|
||||
* 语料内容
|
||||
*/
|
||||
@TableField(value="nameplate_content")
|
||||
private String nameplateContent;
|
||||
|
||||
/**
|
||||
* 录音开始时间
|
||||
*/
|
||||
@TableField(value="nameplate_start_time")
|
||||
private Date nameplateStartTime;
|
||||
|
||||
/**
|
||||
* 录音结束时间
|
||||
*/
|
||||
@TableField(value="nameplate_end_time")
|
||||
private Date nameplateEndTime;
|
||||
|
||||
/**
|
||||
* 时长
|
||||
*/
|
||||
@TableField(value="nameplate_time")
|
||||
private Long nameplateTime;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 删除标识(0-未删除,1-已删除)
|
||||
*/
|
||||
@TableField("is_deleted")
|
||||
private Integer isDeleted;
|
||||
|
||||
/**
|
||||
* 记录版本号,即乐观锁
|
||||
*/
|
||||
@TableField("versions")
|
||||
private Integer versions;
|
||||
|
||||
/**
|
||||
* 创建人
|
||||
*/
|
||||
@TableField("create_by")
|
||||
private String createBy;
|
||||
|
||||
/**
|
||||
* 更新人
|
||||
*/
|
||||
@TableField("update_by")
|
||||
private String updateBy;
|
||||
|
||||
/**
|
||||
* 创建sql人
|
||||
*/
|
||||
@TableField("create_sqlby")
|
||||
private String createSqlby;
|
||||
|
||||
/**
|
||||
* 更新sql人
|
||||
*/
|
||||
@TableField("update_sqlby")
|
||||
private String updateSqlby;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@TableField("create_time")
|
||||
private Date createTime;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
@TableField("update_time")
|
||||
private Date updateTime;
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
package com.volvo.ai.analytic.center.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @description 铭牌解析记录表
|
||||
* @author BEJSON
|
||||
* @date 2025-03-10
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@TableName("tt_nameplate_record")
|
||||
public class TtNameplateRecord {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 主键id
|
||||
*/
|
||||
@TableId(value="id", type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 语料内容Id
|
||||
*/
|
||||
@TableField(value="nameplate_corpus_id")
|
||||
private Long nameplateCorpusId;
|
||||
/**
|
||||
* 客流id
|
||||
*/
|
||||
@TableField(value="customer_flow_id")
|
||||
private String customerFlowId;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 删除标识(0-未删除,1-已删除)
|
||||
*/
|
||||
@TableField("is_deleted")
|
||||
private Integer isDeleted;
|
||||
|
||||
/**
|
||||
* 记录版本号,即乐观锁
|
||||
*/
|
||||
@TableField("version")
|
||||
private Integer version;
|
||||
|
||||
/**
|
||||
* 创建人
|
||||
*/
|
||||
@TableField("create_by")
|
||||
private String createBy;
|
||||
|
||||
/**
|
||||
* 更新人
|
||||
*/
|
||||
@TableField("update_by")
|
||||
private String updateBy;
|
||||
|
||||
/**
|
||||
* 创建sql人
|
||||
*/
|
||||
@TableField("create_sqlby")
|
||||
private String createSqlby;
|
||||
|
||||
/**
|
||||
* 更新sql人
|
||||
*/
|
||||
@TableField("update_sqlby")
|
||||
private String updateSqlby;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@TableField("create_time")
|
||||
private Date createTime;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
@TableField("update_time")
|
||||
private Date updateTime;
|
||||
/**
|
||||
* 记录版本号,即乐观锁
|
||||
*/
|
||||
@TableField("versions")
|
||||
private Integer versions;
|
||||
|
||||
}
|
||||
@@ -6,7 +6,9 @@ import lombok.Getter;
|
||||
public enum BusinessTypeEnum {
|
||||
|
||||
COMMUNITYTARGET("CommunityTarget", "社区舆情分析"),
|
||||
SMART_ASSISTANT("SMART_ASSISTANT", "智能助手")
|
||||
SMART_ASSISTANT("SMART_ASSISTANT", "智能助手"),
|
||||
|
||||
SMART_ASSISTANT_NAMEPLATE("SMART_ASSISTANT_NAMEPLATE", "智能助手-铭牌")
|
||||
;
|
||||
|
||||
private String code;
|
||||
|
||||
@@ -4,6 +4,9 @@ public enum CategoryEnum {
|
||||
|
||||
ENTERPRISE_WECHAT("enterprise_wechat", "企微记录"),
|
||||
PHONE_VOICE("phone_voice", "语音电话"),
|
||||
|
||||
NAMEPLATE_VOICE("nameplate_voice", "铭牌"),
|
||||
|
||||
OTHER("未知", "未知记录"),
|
||||
;
|
||||
private String code;
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
package com.volvo.ai.analytic.center.controller;
|
||||
|
||||
import com.volvo.ai.analytic.center.service.AiAnalysisRequestLogsService;
|
||||
import com.volvo.ai.analytic.center.service.TmNameplateCorpusService;
|
||||
import com.volvo.common.core.util.ResultMsg;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cloud.context.config.annotation.RefreshScope;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* 铭牌语料
|
||||
*/
|
||||
@RestController()
|
||||
@Api(tags = "铭牌语料解析接口")
|
||||
@Slf4j
|
||||
@RefreshScope
|
||||
@RequestMapping("/nameplate")
|
||||
public class NameplateCorpusController {
|
||||
|
||||
@Autowired
|
||||
private TmNameplateCorpusService tmNameplateCorpusService;
|
||||
@Autowired
|
||||
private AiAnalysisRequestLogsService aiAnalysisRequestLogsService;
|
||||
@PostMapping("/updateNameplate")
|
||||
@ApiOperation(value = "更新dify结果")
|
||||
public ResultMsg<Object> updateNameplate(@RequestBody String message) {
|
||||
log.info("updateByAiId message: {}", message);
|
||||
return tmNameplateCorpusService.updateNameplate(message);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
package com.volvo.ai.analytic.center.job;
|
||||
|
||||
import com.volvo.ai.analytic.center.mapper.TmTelephoneCorpusMapper;
|
||||
import com.volvo.ai.analytic.center.service.TmNameplateCorpusService;
|
||||
import com.volvo.ai.analytic.center.service.TmTelephoneCorpusService;
|
||||
import com.volvo.common.core.util.ResultMsg;
|
||||
import com.xxl.job.core.context.XxlJobHelper;
|
||||
import com.xxl.job.core.handler.annotation.XxlJob;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.cloud.context.config.annotation.RefreshScope;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* 铭牌语料处理
|
||||
*/
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
@RestController
|
||||
@RefreshScope
|
||||
public class NameplateCorpusJob {
|
||||
|
||||
@Autowired
|
||||
private TmNameplateCorpusService tmNameplateCorpusService;
|
||||
|
||||
@Autowired
|
||||
private TmTelephoneCorpusService tmTelephoneCorpusService;
|
||||
|
||||
@Autowired
|
||||
private TmTelephoneCorpusMapper tmTelephoneCorpusMapper;
|
||||
@Value("${dify.corpus.nameplate.isUse}")
|
||||
private boolean isUse;
|
||||
/**
|
||||
* 铭牌语料处理
|
||||
*/
|
||||
@XxlJob("nameplateCorpusTask")
|
||||
@PostMapping("nameplateCorpusTask")
|
||||
public ResultMsg nameplateCorpusTask(@RequestBody String paramJson) {
|
||||
try {
|
||||
// 获取任务参数
|
||||
String param = XxlJobHelper.getJobParam();
|
||||
if(StringUtils.isEmpty(param)){
|
||||
param = paramJson;
|
||||
}
|
||||
// 执行业务逻辑
|
||||
XxlJobHelper.log("任务参数: {}", param);
|
||||
log.info("nameplateCorpusTask 铭牌语料查询处理:{}",param);
|
||||
tmNameplateCorpusService.runNameplateCorpusDify(param);
|
||||
} catch (Exception e) {
|
||||
log.error("nameplateCorpusTask 定时任务补偿处理消息异常",e.getMessage());
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return ResultMsg.ok();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 铭牌语料处理失败重试
|
||||
* @param paramJson
|
||||
* @return
|
||||
*/
|
||||
@XxlJob("nameplateCorpusTaskFailRetry")
|
||||
@PostMapping("nameplateCorpusTaskFailRetry")
|
||||
public ResultMsg nameplateCorpusTaskFailRetry(@RequestBody String paramJson) {
|
||||
try {
|
||||
// 获取任务参数
|
||||
String param = XxlJobHelper.getJobParam();
|
||||
if(StringUtils.isEmpty(param)){
|
||||
param = paramJson;
|
||||
}
|
||||
// 执行业务逻辑
|
||||
XxlJobHelper.log("任务参数: {}", param);
|
||||
tmNameplateCorpusService.runNameplateCorpusDifyRetry(param);
|
||||
} catch (Exception e) {
|
||||
log.error("nameplateCorpusTaskFailRetry 定时任务补偿处理消息异常",e.getMessage());
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return ResultMsg.ok();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.volvo.ai.analytic.center.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.volvo.ai.analytic.center.entity.TmNameplateCorpus;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @description 铭牌数据记录表-湖仓同步表
|
||||
* @author BEJSON
|
||||
* @date 2025-03-10
|
||||
*/
|
||||
@Mapper
|
||||
public interface TmNameplateCorpusMapper extends BaseMapper<TmNameplateCorpus> {
|
||||
|
||||
int countTmNameplateCorpusByData(@Param("statTime") String statTime, @Param("endTime") String endTime);
|
||||
|
||||
List<TmNameplateCorpus> queryTmNameplateCorpusByData(@Param("statTime") String statTime, @Param("endTime") String endTime, @Param("offset") int offset, @Param("pageSize") int pageSize);
|
||||
|
||||
int countQueryTmNameplateCorpusRetry(@Param("statTime") String statTime, @Param("endTime") String endTime, @Param("customerFlowIds") List<String> customerFlowIds, @Param("retry") boolean retry);
|
||||
|
||||
List<TmNameplateCorpus> queryTmNameplateCorpusRetry(@Param("statTime") String statTime, @Param("endTime") String endTime,@Param("offset") int offset, @Param("pageSize") int pageSize, @Param("customerFlowIds") List<String> customerFlowIds, @Param("retry") boolean retry);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.volvo.ai.analytic.center.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.volvo.ai.analytic.center.entity.TtNameplateRecord;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
/**
|
||||
* @description 铭牌解析推送成功记录表
|
||||
* @author BEJSON
|
||||
* @date 2025-03-04
|
||||
*/
|
||||
@Mapper
|
||||
@Repository
|
||||
public interface TtNameplateRecordMapper extends BaseMapper<TtNameplateRecord> {
|
||||
|
||||
|
||||
}
|
||||
@@ -6,6 +6,6 @@ import com.volvo.ai.analytic.center.entity.AiAnalysisRequestLogs;
|
||||
public interface AiAnalysisRequestLogsService extends IService<AiAnalysisRequestLogs> {
|
||||
|
||||
boolean saveAiAnalysisRequestLogs(AiAnalysisRequestLogs aiAnalysisRequestLogs);
|
||||
|
||||
AiAnalysisRequestLogs queryByAiAnalysisRequestId(String aiAnalysisRequestId);
|
||||
AiAnalysisRequestLogs queryAiAnalysisRequestLogsByBusinessReponse(String sourceId);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.volvo.ai.analytic.center.service;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.volvo.ai.analytic.center.entity.TmNameplateCorpus;
|
||||
import com.volvo.common.core.util.ResultMsg;
|
||||
|
||||
/**
|
||||
* @description 铭牌语料表-同步表
|
||||
* @author BEJSON
|
||||
* @date 2025-03-04
|
||||
*/
|
||||
public interface TmNameplateCorpusService extends IService<TmNameplateCorpus> {
|
||||
|
||||
void runNameplateCorpusDify(String paramJson);
|
||||
|
||||
void runNameplateCorpusDifyRetry(String paramJson);
|
||||
|
||||
void sendNameplateLto(JSONObject execDifyFlow, TmNameplateCorpus tmNameplateCorpus);
|
||||
|
||||
ResultMsg<Object> updateNameplate(String message);
|
||||
}
|
||||
@@ -32,6 +32,13 @@ public class AiAnalysisRequestLogsServiceImpl extends ServiceImpl<AiAnalysisRequ
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public AiAnalysisRequestLogs queryByAiAnalysisRequestId(String aiAnalysisRequestId) {
|
||||
LambdaQueryWrapper<AiAnalysisRequestLogs> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(AiAnalysisRequestLogs::getAiAnalysisRequestId, aiAnalysisRequestId);
|
||||
return aiAnalysisRequestLogsMapper.selectOne(queryWrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AiAnalysisRequestLogs queryAiAnalysisRequestLogsByBusinessReponse(String sourceId) {
|
||||
return aiAnalysisRequestLogsMapper.queryAiAnalysisRequestLogsByBusinessReponse(sourceId);
|
||||
|
||||
@@ -63,7 +63,6 @@ public class DiFyServiceImpl implements DiFyService{
|
||||
.businessRequest(businessData)
|
||||
.difyAgentKey(diFyReq.getFlowId())
|
||||
.difyRequest(JSON.toJSONString(diFyReq))
|
||||
.difyResponse(JSON.toJSONString(""))
|
||||
.aiAnalysisRequestType(businessType)
|
||||
.build());
|
||||
|
||||
@@ -75,7 +74,6 @@ public class DiFyServiceImpl implements DiFyService{
|
||||
|
||||
aiAnalysisRequestLogsService.saveAiAnalysisRequestLogs(AiAnalysisRequestLogs.builder()
|
||||
.aiAnalysisRequestId(aiAnalysisRequestId)
|
||||
.businessRequest(JSONObject.toJSONString(""))
|
||||
.difyResponse(data.toJSONString())
|
||||
.build());
|
||||
|
||||
|
||||
@@ -0,0 +1,284 @@
|
||||
package com.volvo.ai.analytic.center.service.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.volvo.ai.analytic.center.dto.PageDto;
|
||||
import com.volvo.ai.analytic.center.dto.corpus.CorpusReportDTO;
|
||||
import com.volvo.ai.analytic.center.dto.req.DiFyReq;
|
||||
import com.volvo.ai.analytic.center.dto.req.RunMaskingRuleInput;
|
||||
import com.volvo.ai.analytic.center.entity.AiAnalysisRequestLogs;
|
||||
import com.volvo.ai.analytic.center.entity.DataMaskingRule;
|
||||
import com.volvo.ai.analytic.center.entity.TmNameplateCorpus;
|
||||
import com.volvo.ai.analytic.center.entity.TtNameplateRecord;
|
||||
import com.volvo.ai.analytic.center.enums.BusinessTypeEnum;
|
||||
import com.volvo.ai.analytic.center.enums.CategoryEnum;
|
||||
import com.volvo.ai.analytic.center.feign.RemoteCarModelClient;
|
||||
import com.volvo.ai.analytic.center.mapper.TmNameplateCorpusMapper;
|
||||
import com.volvo.ai.analytic.center.mapper.TmOdsVdqwMessagearchivingMapper;
|
||||
import com.volvo.ai.analytic.center.mapper.TtNameplateRecordMapper;
|
||||
import com.volvo.ai.analytic.center.service.*;
|
||||
import com.volvo.ai.analytic.center.utils.ConstantStr;
|
||||
import com.volvo.ai.analytic.center.utils.FlowResultSplitUtil;
|
||||
import com.volvo.common.core.util.ResultMsg;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.rocketmq.spring.core.RocketMQTemplate;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.cloud.context.config.annotation.RefreshScope;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.time.LocalDate;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
|
||||
/**
|
||||
* @description 铭牌语料表-同步表
|
||||
* @author rz
|
||||
* @date 2025-03-04
|
||||
*/
|
||||
@RefreshScope
|
||||
@Slf4j
|
||||
@Service
|
||||
public class TmNameplateCorpusServiceImpl extends ServiceImpl<TmNameplateCorpusMapper, TmNameplateCorpus> implements TmNameplateCorpusService {
|
||||
|
||||
@Autowired
|
||||
private TmOdsVdqwMessagearchivingMapper tmOdsVdqwMessagearchivingMapper;
|
||||
|
||||
@Autowired
|
||||
private TmNameplateCorpusMapper tmNameplateCorpusMapper;
|
||||
|
||||
@Autowired
|
||||
private TtNameplateRecordMapper ttNameplateRecordMapper;
|
||||
@Autowired
|
||||
private TmTelephoneCorpusService tmTelephoneCorpusService;
|
||||
|
||||
@Autowired
|
||||
private AiAnalysisRequestLogsService aiAnalysisRequestLogsService;
|
||||
@Autowired
|
||||
private DiFyService diFyService;
|
||||
|
||||
@Resource
|
||||
private RocketMQTemplate rocketMqTemplate;
|
||||
@Value("${dify.corpus.nameplate.appkey}")
|
||||
private String nameplateAppKey;
|
||||
|
||||
@Value("${batch.size}")
|
||||
public int pageSize = 100;
|
||||
@Autowired
|
||||
private RemoteCarModelClient remoteCarModelClient;
|
||||
|
||||
@Autowired
|
||||
private DataMaskingRuleService dataMaskingRuleService;
|
||||
|
||||
|
||||
@Override
|
||||
public void runNameplateCorpusDify(String paramJson) {
|
||||
long startTime = System.currentTimeMillis();
|
||||
log.info("runNameplateCorpusDify paramJson {}", paramJson);
|
||||
// 获取当前日期
|
||||
LocalDate today = LocalDate.now();
|
||||
// 获取前一天日期
|
||||
LocalDate yesterday = today.minusDays(1);
|
||||
boolean retry = false;
|
||||
// 格式化输出
|
||||
String formattedDate = yesterday.toString(); // 默认格式为 yyyy-MM-dd
|
||||
String statTime = formattedDate.concat(" 00:00:00");
|
||||
String endTime = formattedDate.concat(" 23:59:59");
|
||||
if (StringUtils.isNotBlank(paramJson)) {
|
||||
JSONObject paramJsonObj = JSONObject.parseObject(paramJson);
|
||||
if (null != paramJsonObj && paramJsonObj.containsKey("statTime") && paramJsonObj.containsKey("endTime")) {
|
||||
statTime = paramJsonObj.getString("statTime");
|
||||
endTime = paramJsonObj.getString("endTime");
|
||||
}
|
||||
}
|
||||
|
||||
Integer total = tmNameplateCorpusMapper.countTmNameplateCorpusByData(statTime, endTime);
|
||||
int totalPages = PageDto.getTotalPages(total, pageSize);
|
||||
|
||||
// 获取消息列表
|
||||
int optimalThreadPoolSize = Runtime.getRuntime().availableProcessors() + 1;
|
||||
log.info("获取的线程数:{}",optimalThreadPoolSize);
|
||||
// 创建线程池
|
||||
ExecutorService executor = Executors.newFixedThreadPool(optimalThreadPoolSize); // 根据需求调整线程池大小
|
||||
|
||||
for (int i = 1; i <= totalPages; i++) {
|
||||
int offset = (i - 1) * pageSize;
|
||||
List<TmNameplateCorpus> messageList = tmNameplateCorpusMapper.queryTmNameplateCorpusByData(statTime, endTime, offset, pageSize);
|
||||
// 处理查询到的数据
|
||||
// 使用 CompletableFuture 并行处理
|
||||
CompletableFuture<?>[] futures = messageList.stream()
|
||||
.map(item -> CompletableFuture.runAsync(() -> {
|
||||
try {
|
||||
processItem(item);
|
||||
} catch (Exception e) {
|
||||
log.error("铭牌语料失败: customerFlowId={}, AcceptUserId={}, 异常: {}",
|
||||
item.getCustomerFlowId(), e.getMessage(), e);
|
||||
}
|
||||
}, executor))
|
||||
.toArray(CompletableFuture[]::new);
|
||||
// 等待所有任务完成
|
||||
CompletableFuture.allOf(futures).join();
|
||||
}
|
||||
// 关闭线程池
|
||||
executor.shutdown();
|
||||
log.info("企微数据跑批结束 耗时:{}",System.currentTimeMillis()-startTime);
|
||||
}
|
||||
@Override
|
||||
public void runNameplateCorpusDifyRetry(String paramJson) {
|
||||
long startTime = System.currentTimeMillis();
|
||||
log.info("runNameplateCorpusDifyRetry paramJson {}", paramJson);
|
||||
// 获取当前日期
|
||||
LocalDate today = LocalDate.now();
|
||||
// 获取前一天日期
|
||||
LocalDate yesterday = today.minusDays(1);
|
||||
boolean retry = true;
|
||||
String customerFlowIds = null;
|
||||
// 格式化输出
|
||||
String formattedDate = yesterday.toString(); // 默认格式为 yyyy-MM-dd
|
||||
String statTime = formattedDate.concat(" 00:00:00");
|
||||
String endTime = formattedDate.concat(" 23:59:59");
|
||||
if (StringUtils.isNotBlank(paramJson)) {
|
||||
JSONObject paramJsonObj = JSONObject.parseObject(paramJson);
|
||||
if (null != paramJsonObj && paramJsonObj.containsKey("statTime") && paramJsonObj.containsKey("endTime")) {
|
||||
statTime = paramJsonObj.getString("statTime");
|
||||
endTime = paramJsonObj.getString("endTime");
|
||||
retry = paramJsonObj.getBoolean("retry");
|
||||
customerFlowIds = paramJsonObj.getString("customerFlowIds");
|
||||
}
|
||||
}
|
||||
|
||||
Integer total = tmNameplateCorpusMapper.countQueryTmNameplateCorpusRetry(statTime, endTime, Arrays.asList(customerFlowIds.split(",")),retry);
|
||||
int totalPages = PageDto.getTotalPages(total, pageSize);
|
||||
|
||||
// 获取消息列表
|
||||
int optimalThreadPoolSize = Runtime.getRuntime().availableProcessors() + 1;
|
||||
log.info("获取的线程数:{}",optimalThreadPoolSize);
|
||||
// 创建线程池
|
||||
ExecutorService executor = Executors.newFixedThreadPool(optimalThreadPoolSize); // 根据需求调整线程池大小
|
||||
|
||||
for (int i = 1; i <= totalPages; i++) {
|
||||
int offset = (i - 1) * pageSize;
|
||||
List<TmNameplateCorpus> messageList = tmNameplateCorpusMapper.queryTmNameplateCorpusRetry(statTime, endTime, offset, pageSize, Arrays.asList(customerFlowIds.split(",")), retry);
|
||||
// 处理查询到的数据
|
||||
// 使用 CompletableFuture 并行处理
|
||||
CompletableFuture<?>[] futures = messageList.stream()
|
||||
.map(item -> CompletableFuture.runAsync(() -> {
|
||||
try {
|
||||
processItem(item);
|
||||
} catch (Exception e) {
|
||||
log.error("重跑铭牌语料失败: customerFlowId={}, AcceptUserId={}, 异常: {}",
|
||||
item.getCustomerFlowId(), e.getMessage(), e);
|
||||
}
|
||||
}, executor))
|
||||
.toArray(CompletableFuture[]::new);
|
||||
// 等待所有任务完成
|
||||
CompletableFuture.allOf(futures).join();
|
||||
}
|
||||
// 关闭线程池
|
||||
executor.shutdown();
|
||||
log.info("重跑铭牌语料铭牌数据跑批结束 耗时:{}",System.currentTimeMillis()-startTime);
|
||||
}
|
||||
|
||||
private void processItem(TmNameplateCorpus item) {
|
||||
|
||||
Optional.ofNullable(item).filter(tmNameplateCorpus -> tmNameplateCorpus.getCustomerFlowId()!=null && tmNameplateCorpus.getNameplateContent()!=null).orElseThrow(()->new RuntimeException("铭牌语料为空"));
|
||||
|
||||
String customerFlowId = item.getCustomerFlowId();
|
||||
String nameplateContent = item.getNameplateContent();
|
||||
log.info("铭牌数据处理:customerFlowId:{}", customerFlowId);
|
||||
|
||||
DiFyReq diFyImageReq = new DiFyReq();
|
||||
diFyImageReq.setUser(ConstantStr.corpus_user);
|
||||
diFyImageReq.setFlowId(nameplateAppKey);
|
||||
List<DataMaskingRule> maskingRuleItems = dataMaskingRuleService.getDataMaskingRuleListByApplicationChannel(BusinessTypeEnum.SMART_ASSISTANT_NAMEPLATE.getCode());
|
||||
RunMaskingRuleInput runMaskingRuleInput = new RunMaskingRuleInput();
|
||||
runMaskingRuleInput.setDataMaskingRules(maskingRuleItems);
|
||||
|
||||
runMaskingRuleInput.setOldStr(nameplateContent);
|
||||
String corpusChat = dataMaskingRuleService.runMaskingRule(runMaskingRuleInput);
|
||||
Map<String, Object> inputMap = new HashMap<>();
|
||||
String carModel = tmTelephoneCorpusService.getCarModelList();
|
||||
inputMap.put("dialogue", corpusChat);
|
||||
inputMap.put("model", carModel);
|
||||
inputMap.put("customerFlowId", item.getCustomerFlowId());
|
||||
diFyImageReq.setInputs(inputMap);
|
||||
|
||||
CorpusReportDTO corpusReportDTO = new CorpusReportDTO();
|
||||
corpusReportDTO.setCustomerFlowId(customerFlowId);
|
||||
corpusReportDTO.setAnalysisScene(3l);
|
||||
corpusReportDTO.setCarModel(carModel);
|
||||
// 获取配置
|
||||
JSONObject execDifyFlow = diFyService.executeDifyFlow(diFyImageReq, BusinessTypeEnum.SMART_ASSISTANT_NAMEPLATE.getCode(), JSONObject.toJSONString(corpusReportDTO),null);
|
||||
log.info("runDify execDifyFlow {}", execDifyFlow);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void sendNameplateLto(JSONObject execDifyFlow, TmNameplateCorpus tmNameplateCorpus) {
|
||||
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);
|
||||
if (StringUtils.isBlank(resultStrOne) || StringUtils.isBlank(resultStrTwo)){
|
||||
log.info("铭牌语料解析为空,text:{}", text);
|
||||
return;
|
||||
}
|
||||
Map<String, String> ltoMap = new HashMap<>();
|
||||
ltoMap.put("analysisRecordId", execDifyFlow.getString("aiAnalysisRequestId"));
|
||||
ltoMap.put("analysisScene", "3");
|
||||
ltoMap.put("customerFlowId", tmNameplateCorpus.getCustomerFlowId());
|
||||
ltoMap.put("analysisResult", resultStrOne);
|
||||
ltoMap.put("analysisDetail", resultStrTwo);
|
||||
// 发送MQ
|
||||
log.info("send mq {}", ltoMap);
|
||||
tmTelephoneCorpusService.sendMq( CategoryEnum.NAMEPLATE_VOICE.getCode(), JSONObject.toJSONString(ltoMap));
|
||||
|
||||
try {
|
||||
ttNameplateRecordMapper.insert(TtNameplateRecord.builder().nameplateCorpusId(tmNameplateCorpus.getId()).customerFlowId(tmNameplateCorpus.getCustomerFlowId()).build());
|
||||
aiAnalysisRequestLogsService.saveAiAnalysisRequestLogs(AiAnalysisRequestLogs.builder().aiAnalysisRequestId(execDifyFlow.getString("aiAnalysisRequestId")).businessResponse(JSONObject.toJSONString(ltoMap)).build());
|
||||
} catch (Exception e) {
|
||||
log.info(" 铭牌语料处理保存报告异常processItem:{} ", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResultMsg<Object> updateNameplate(String message) {
|
||||
if(StringUtils.isNotEmpty(message)){
|
||||
JSONObject analysisResp = JSONObject.parseObject(message);
|
||||
String aiAnalysisRequestId = analysisResp.getString("aiAnalysisRequestId");
|
||||
String difyResponse = analysisResp.getString("difyResponse");
|
||||
String customerFlowId = analysisResp.getString("customerFlowId");
|
||||
Optional.ofNullable(aiAnalysisRequestLogsService.queryByAiAnalysisRequestId(aiAnalysisRequestId))
|
||||
.orElseThrow(() -> new IllegalArgumentException("AiAnalysisRequestId查询对象为空!"));
|
||||
|
||||
AiAnalysisRequestLogs aiAnalysisRequestLogs = new AiAnalysisRequestLogs();
|
||||
aiAnalysisRequestLogs.setAiAnalysisRequestId(aiAnalysisRequestId);
|
||||
aiAnalysisRequestLogs.setDifyResponse(difyResponse);
|
||||
|
||||
JSONObject difyJson = JSONObject.parseObject(difyResponse);
|
||||
aiAnalysisRequestLogs.setBusinessResponse(difyJson.getString("outputs"));
|
||||
aiAnalysisRequestLogsService.saveAiAnalysisRequestLogs(aiAnalysisRequestLogs);
|
||||
LambdaQueryWrapper<TmNameplateCorpus> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(TmNameplateCorpus::getCustomerFlowId, customerFlowId);
|
||||
List<TmNameplateCorpus> tmNameplateCorpusList = tmNameplateCorpusMapper.selectList(queryWrapper);
|
||||
if (CollectionUtils.isNotEmpty(tmNameplateCorpusList)){
|
||||
sendNameplateLto(difyJson, tmNameplateCorpusList.get(0));
|
||||
}
|
||||
return ResultMsg.ok();
|
||||
}
|
||||
return ResultMsg.failed();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user