增加redis
This commit is contained in:
@@ -226,6 +226,11 @@
|
|||||||
<version>2.3.0</version>
|
<version>2.3.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-data-redis</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
package com.volvo.ai.analytic.center.config;
|
||||||
|
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.data.redis.connection.RedisConnectionFactory;
|
||||||
|
import org.springframework.data.redis.core.RedisTemplate;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
public class RedisConfig {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory connectionFactory) {
|
||||||
|
RedisTemplate<String, Object> template = new RedisTemplate<>();
|
||||||
|
template.setConnectionFactory(connectionFactory);
|
||||||
|
|
||||||
|
return template;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -34,6 +34,7 @@ import org.apache.rocketmq.spring.core.RocketMQTemplate;
|
|||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.cloud.context.config.annotation.RefreshScope;
|
import org.springframework.cloud.context.config.annotation.RefreshScope;
|
||||||
|
import org.springframework.data.redis.core.RedisTemplate;
|
||||||
import org.springframework.messaging.support.MessageBuilder;
|
import org.springframework.messaging.support.MessageBuilder;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
@@ -44,6 +45,7 @@ import java.time.format.DateTimeFormatter;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
|
||||||
@@ -77,6 +79,9 @@ public class TmTelephoneCorpusServiceImpl extends ServiceImpl<TmTelephoneCorpusM
|
|||||||
@Autowired
|
@Autowired
|
||||||
private AiAnalysisRequestLogsService aiAnalysisRequestLogsService;
|
private AiAnalysisRequestLogsService aiAnalysisRequestLogsService;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private RedisTemplate<String, Object> redisTemplate;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional
|
@Transactional
|
||||||
public void saveTelephoneCorpus(TmTelephoneCorpus tmTelephoneCorpus) {
|
public void saveTelephoneCorpus(TmTelephoneCorpus tmTelephoneCorpus) {
|
||||||
@@ -117,9 +122,9 @@ public class TmTelephoneCorpusServiceImpl extends ServiceImpl<TmTelephoneCorpusM
|
|||||||
String role = analysisInfo.getString("role");
|
String role = analysisInfo.getString("role");
|
||||||
String title="";
|
String title="";
|
||||||
if(role.equals("AGENT")){
|
if(role.equals("AGENT")){
|
||||||
title="客服:";
|
title="顾问";
|
||||||
}else{
|
}else{
|
||||||
title="客户:";
|
title="客户";
|
||||||
}
|
}
|
||||||
// 拼接 role 和 text
|
// 拼接 role 和 text
|
||||||
String chat = title + ": " + text;
|
String chat = title + ": " + text;
|
||||||
@@ -176,6 +181,12 @@ public class TmTelephoneCorpusServiceImpl extends ServiceImpl<TmTelephoneCorpusM
|
|||||||
|
|
||||||
public String getCarModelList(){
|
public String getCarModelList(){
|
||||||
try {
|
try {
|
||||||
|
// 从 Redis 中获取缓存数据
|
||||||
|
String cachedModelNames = (String) redisTemplate.opsForValue().get(ConstantStr.CARMODELLIST_CACHEKEY);
|
||||||
|
if (cachedModelNames != null) {
|
||||||
|
log.info("从缓存中获取车型列表: {}", cachedModelNames);
|
||||||
|
return cachedModelNames;
|
||||||
|
}
|
||||||
long startTime = System.currentTimeMillis();
|
long startTime = System.currentTimeMillis();
|
||||||
CarModelReqDTO carModelReqDTO = new CarModelReqDTO();
|
CarModelReqDTO carModelReqDTO = new CarModelReqDTO();
|
||||||
carModelReqDTO.setOnSale(10041001);
|
carModelReqDTO.setOnSale(10041001);
|
||||||
@@ -190,6 +201,9 @@ public class TmTelephoneCorpusServiceImpl extends ServiceImpl<TmTelephoneCorpusM
|
|||||||
.collect(Collectors.joining(", ")); // 用逗号和空格拼接
|
.collect(Collectors.joining(", ")); // 用逗号和空格拼接
|
||||||
|
|
||||||
log.info("拼接后的车型名称: {}", modelNames);
|
log.info("拼接后的车型名称: {}", modelNames);
|
||||||
|
// 将结果存入 Redis,设置过期时间为 1 小时
|
||||||
|
redisTemplate.opsForValue().set(ConstantStr.CARMODELLIST_CACHEKEY, modelNames, 5, TimeUnit.DAYS);
|
||||||
|
|
||||||
return modelNames;
|
return modelNames;
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|||||||
@@ -11,4 +11,6 @@ public class ConstantStr {
|
|||||||
|
|
||||||
public static final String CHANNEL_DCC = "Channel_Dcc";
|
public static final String CHANNEL_DCC = "Channel_Dcc";
|
||||||
public static final String corpus_user = "corpush_user";
|
public static final String corpus_user = "corpush_user";
|
||||||
|
|
||||||
|
public static final String CARMODELLIST_CACHEKEY = "ai_carmodellist";
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user