feat: 删除冗余接口
This commit is contained in:
@@ -2,7 +2,7 @@ package com.klp.service.impl;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.klp.config.ImageRecognitionConfig;
|
||||
import com.klp.common.config.ImageRecognitionConfig;
|
||||
import com.klp.domain.bo.ImageRecognitionBo;
|
||||
import com.klp.domain.vo.AttributeVo;
|
||||
import com.klp.domain.vo.ImageRecognitionVo;
|
||||
@@ -87,28 +87,18 @@ public class ImageRecognitionServiceImpl implements IImageRecognitionService {
|
||||
ImageRecognitionVo result = new ImageRecognitionVo();
|
||||
result.setImageUrl(bo.getImageUrl());
|
||||
result.setRecognitionType("bom");
|
||||
result.setRecognizedText(aiResponse);
|
||||
|
||||
// 解析识别结果
|
||||
try {
|
||||
// 直接解析属性数组
|
||||
List<AttributeVo> attributes = parseAttributesResponse(aiResponse);
|
||||
result.setAttributes(attributes);
|
||||
// 直接解析属性数组
|
||||
List<AttributeVo> attributes = parseAttributesResponse(aiResponse);
|
||||
result.setAttributes(attributes);
|
||||
|
||||
// 构建结构化结果
|
||||
Map<String, Object> structuredResult = new HashMap<>();
|
||||
structuredResult.put("attributes", attributes);
|
||||
structuredResult.put("summary", "材料质保单识别结果");
|
||||
structuredResult.put("totalItems", attributes.size());
|
||||
result.setStructuredResult(structuredResult);
|
||||
// 构建结构化结果
|
||||
Map<String, Object> structuredResult = new HashMap<>();
|
||||
structuredResult.put("attributes", attributes);
|
||||
structuredResult.put("summary", "材料质保单识别结果");
|
||||
structuredResult.put("totalItems", attributes.size());
|
||||
|
||||
// BOM项目为空,因为这是质保单识别
|
||||
result.setBomItems(new ArrayList<>());
|
||||
|
||||
} catch (Exception e) {
|
||||
log.warn("解析识别响应失败: {}", e.getMessage());
|
||||
result.setRecognizedText(aiResponse);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -120,7 +110,6 @@ public class ImageRecognitionServiceImpl implements IImageRecognitionService {
|
||||
ImageRecognitionVo result = new ImageRecognitionVo();
|
||||
result.setImageUrl(bo.getImageUrl());
|
||||
result.setRecognitionType("text");
|
||||
result.setRecognizedText(aiResponse);
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -136,8 +125,6 @@ public class ImageRecognitionServiceImpl implements IImageRecognitionService {
|
||||
ImageRecognitionVo result = new ImageRecognitionVo();
|
||||
result.setImageUrl(bo.getImageUrl());
|
||||
result.setRecognitionType("general");
|
||||
result.setRecognizedText(aiResponse);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.klp.service.impl;
|
||||
|
||||
import com.klp.common.config.DeepseekConfig;
|
||||
import com.klp.common.core.page.TableDataInfo;
|
||||
import com.klp.common.core.domain.PageQuery;
|
||||
import com.klp.common.utils.StringUtils;
|
||||
@@ -23,6 +24,7 @@ import org.springframework.web.client.RestTemplate;
|
||||
import org.springframework.http.*;
|
||||
import org.springframework.http.client.SimpleClientHttpRequestFactory;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
@@ -43,31 +45,11 @@ public class WmsSalesScriptGeneratorServiceImpl implements IWmsSalesScriptGenera
|
||||
|
||||
private final IWmsProductService iWmsProductService;
|
||||
private final IWmsProductBomService iWmsProductBomService;
|
||||
private final IWmsProductSalesScriptService iWmsProductSalesScriptService;
|
||||
// private final RedisUtils redisUtils;
|
||||
@Qualifier("salesScriptRestTemplate")
|
||||
private final RestTemplate restTemplate;
|
||||
|
||||
// AI配置
|
||||
@Value("${sales.script.ai.api-key:sk-5eb55d2fb2cc4fe58a0150919a1f0d70}")
|
||||
private String apiKey;
|
||||
|
||||
@Value("${sales.script.ai.base-url:https://api.deepseek.com/v1}")
|
||||
private String baseUrl;
|
||||
|
||||
@Value("${sales.script.ai.model-name:deepseek-chat}")
|
||||
private String modelName;
|
||||
|
||||
@Value("${sales.script.ai.max-retries:3}")
|
||||
private Integer maxRetries;
|
||||
|
||||
@Value("${sales.script.ai.temperature:1.0}")
|
||||
private Double temperature;
|
||||
|
||||
// 客户类型配置
|
||||
private static final List<String> CUSTOMER_TYPES = Arrays.asList(
|
||||
"技术型客户", "价格敏感型客户", "质量优先型客户", "批量采购客户", "定制化需求客户"
|
||||
);
|
||||
@Resource
|
||||
private DeepseekConfig deepseekConfig;
|
||||
|
||||
// 产品特性关键词
|
||||
private static final List<String> FEATURE_KEYWORDS = Arrays.asList(
|
||||
@@ -211,168 +193,6 @@ public class WmsSalesScriptGeneratorServiceImpl implements IWmsSalesScriptGenera
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> testAiConnection() {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
try {
|
||||
// 构建测试请求
|
||||
Map<String, Object> requestBody = new HashMap<>();
|
||||
requestBody.put("model", modelName);
|
||||
Map<String, String> message = new HashMap<>();
|
||||
message.put("role", "user");
|
||||
message.put("content", "你好");
|
||||
requestBody.put("messages", Arrays.asList(message));
|
||||
requestBody.put("max_tokens", 10);
|
||||
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.setContentType(MediaType.APPLICATION_JSON);
|
||||
headers.setBearerAuth(apiKey);
|
||||
|
||||
HttpEntity<Map<String, Object>> entity = new HttpEntity<>(requestBody, headers);
|
||||
ResponseEntity<Map> response = restTemplate.postForEntity(
|
||||
baseUrl + "/chat/completions", entity, Map.class);
|
||||
|
||||
result.put("success", true);
|
||||
result.put("message", "AI连接测试成功");
|
||||
result.put("response", response.getBody());
|
||||
} catch (Exception e) {
|
||||
log.error("AI连接测试失败", e);
|
||||
result.put("success", false);
|
||||
result.put("message", "AI连接测试失败: " + e.getMessage());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> getGenerationConfig() {
|
||||
Map<String, Object> config = new HashMap<>();
|
||||
config.put("apiKey", StringUtils.isNotEmpty(apiKey) ? apiKey.substring(0, 10) + "..." : "");
|
||||
config.put("baseUrl", baseUrl);
|
||||
config.put("modelName", modelName);
|
||||
config.put("maxRetries", maxRetries);
|
||||
config.put("temperature", temperature);
|
||||
config.put("customerTypes", CUSTOMER_TYPES);
|
||||
config.put("featureKeywords", FEATURE_KEYWORDS);
|
||||
return config;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateGenerationConfig(Map<String, Object> config) {
|
||||
// 这里可以实现配置更新逻辑
|
||||
// 可以将配置保存到数据库或配置文件中
|
||||
log.info("更新生成配置: {}", config);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Map<String, Object>> getAvailableProducts() {
|
||||
List<Map<String, Object>> products = new ArrayList<>();
|
||||
try {
|
||||
List<WmsProductVo> productList = iWmsProductService.queryList(new com.klp.domain.bo.WmsProductBo());
|
||||
for (WmsProductVo product : productList) {
|
||||
if (product.getIsEnabled() != null && product.getIsEnabled() == 1) {
|
||||
Map<String, Object> productMap = new HashMap<>();
|
||||
productMap.put("productId", product.getProductId());
|
||||
productMap.put("productName", product.getProductName());
|
||||
productMap.put("productCode", product.getProductCode());
|
||||
productMap.put("owner", product.getOwner());
|
||||
products.add(productMap);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("获取可用产品列表失败", e);
|
||||
}
|
||||
return products;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TableDataInfo<Map<String, Object>> getGenerationHistory(PageQuery pageQuery) {
|
||||
// 这里可以实现生成历史查询逻辑
|
||||
// 可以创建一个专门的表来记录生成历史
|
||||
TableDataInfo<Map<String, Object>> result = new TableDataInfo<>();
|
||||
result.setRows(new ArrayList<>());
|
||||
result.setTotal(0L);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WmsProductSalesScriptVo regenerateScript(Long scriptId) {
|
||||
// 获取原话术信息
|
||||
WmsProductSalesScriptVo originalScript = iWmsProductSalesScriptService.queryById(scriptId);
|
||||
if (originalScript == null) {
|
||||
throw new RuntimeException("话术不存在");
|
||||
}
|
||||
|
||||
// 重新生成话术
|
||||
WmsSalesScriptGeneratorBo bo = new WmsSalesScriptGeneratorBo();
|
||||
bo.setProductId(originalScript.getProductId());
|
||||
bo.setScriptCount(1);
|
||||
bo.setSaveToDatabase(false);
|
||||
|
||||
List<WmsProductSalesScriptVo> newScripts = generateScriptsForProduct(bo);
|
||||
if (!newScripts.isEmpty()) {
|
||||
return newScripts.get(0);
|
||||
}
|
||||
|
||||
throw new RuntimeException("重新生成话术失败");
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Map<String, Object>> previewScripts(WmsSalesScriptGeneratorBo bo) {
|
||||
bo.setSaveToDatabase(false);
|
||||
List<WmsProductSalesScriptVo> scripts = generateScriptsForProduct(bo);
|
||||
|
||||
List<Map<String, Object>> previews = new ArrayList<>();
|
||||
for (WmsProductSalesScriptVo script : scripts) {
|
||||
Map<String, Object> preview = new HashMap<>();
|
||||
preview.put("title", script.getScriptTitle());
|
||||
preview.put("content", script.getScriptContent());
|
||||
preview.put("featurePoint", script.getFeaturePoint());
|
||||
previews.add(preview);
|
||||
}
|
||||
return previews;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Map<String, Object>> getCustomerTypes() {
|
||||
List<Map<String, Object>> customerTypes = new ArrayList<>();
|
||||
for (String type : CUSTOMER_TYPES) {
|
||||
Map<String, Object> customerType = new HashMap<>();
|
||||
customerType.put("type", type);
|
||||
customerType.put("description", getCustomerTypeDescription(type));
|
||||
customerTypes.add(customerType);
|
||||
}
|
||||
return customerTypes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getFeatureKeywords() {
|
||||
return new ArrayList<>(FEATURE_KEYWORDS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> analyzeProduct(WmsSalesScriptGeneratorBo bo) {
|
||||
Map<String, Object> analysis = new HashMap<>();
|
||||
try {
|
||||
WmsProductVo product = iWmsProductService.queryById(bo.getProductId());
|
||||
if (product == null) {
|
||||
throw new RuntimeException("产品不存在");
|
||||
}
|
||||
|
||||
List<WmsProductBom> bomList = iWmsProductBomService.listByProductId(bo.getProductId());
|
||||
|
||||
// 分析产品特性
|
||||
analysis.put("productInfo", product);
|
||||
analysis.put("bomInfo", bomList);
|
||||
analysis.put("suggestedCustomerTypes", suggestCustomerTypes(product, bomList));
|
||||
analysis.put("suggestedFeatures", extractFeatures(product, bomList));
|
||||
analysis.put("suggestedScriptCount", 5);
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("分析产品失败", e);
|
||||
analysis.put("error", e.getMessage());
|
||||
}
|
||||
return analysis;
|
||||
}
|
||||
|
||||
/**
|
||||
* 调用AI API
|
||||
@@ -381,7 +201,7 @@ public class WmsSalesScriptGeneratorServiceImpl implements IWmsSalesScriptGenera
|
||||
String prompt = buildPrompt(product, bomList, bo);
|
||||
|
||||
Map<String, Object> requestBody = new HashMap<>();
|
||||
requestBody.put("model", modelName);
|
||||
requestBody.put("model", deepseekConfig.getModelName());
|
||||
Map<String, String> systemMessage = new HashMap<>();
|
||||
systemMessage.put("role", "system");
|
||||
systemMessage.put("content", "你是一名专业的销售话术专家");
|
||||
@@ -396,14 +216,14 @@ public class WmsSalesScriptGeneratorServiceImpl implements IWmsSalesScriptGenera
|
||||
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.setContentType(MediaType.APPLICATION_JSON);
|
||||
headers.setBearerAuth(apiKey);
|
||||
headers.setBearerAuth(deepseekConfig.getApiKey());
|
||||
|
||||
HttpEntity<Map<String, Object>> entity = new HttpEntity<>(requestBody, headers);
|
||||
|
||||
for (int i = 0; i < bo.getMaxRetries(); i++) {
|
||||
try {
|
||||
ResponseEntity<Map> response = restTemplate.postForEntity(
|
||||
baseUrl + "/chat/completions", entity, Map.class);
|
||||
deepseekConfig.getBaseUrl() + "/chat/completions", entity, Map.class);
|
||||
|
||||
if (response.getStatusCode() == HttpStatus.OK && response.getBody() != null) {
|
||||
Map<String, Object> body = response.getBody();
|
||||
@@ -421,7 +241,6 @@ public class WmsSalesScriptGeneratorServiceImpl implements IWmsSalesScriptGenera
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
throw new RuntimeException("AI API调用失败,已达到最大重试次数");
|
||||
}
|
||||
|
||||
@@ -430,8 +249,10 @@ public class WmsSalesScriptGeneratorServiceImpl implements IWmsSalesScriptGenera
|
||||
*/
|
||||
private String buildPrompt(WmsProductVo product, List<WmsProductBom> bomList, WmsSalesScriptGeneratorBo bo) {
|
||||
StringBuilder prompt = new StringBuilder();
|
||||
prompt.append("请根据以下产品信息和BOM清单,生成").append(bo.getScriptCount()).append("条针对不同客户场景的销售话术。\n\n").append("不要给我加称呼\n");
|
||||
|
||||
prompt.append("请根据以下产品信息和BOM清单,生成")
|
||||
.append(bo.getScriptCount())
|
||||
.append("条针对不同客户场景的销售话术。\n\n")
|
||||
.append("不要给我加称呼\n");
|
||||
// 产品信息
|
||||
prompt.append("【产品信息】\n");
|
||||
prompt.append("产品名称:").append(product.getProductName()).append("\n");
|
||||
@@ -450,7 +271,6 @@ public class WmsSalesScriptGeneratorServiceImpl implements IWmsSalesScriptGenera
|
||||
if (StringUtils.isNotEmpty(product.getRemark())) {
|
||||
prompt.append("备注:").append(product.getRemark()).append("\n");
|
||||
}
|
||||
|
||||
// BOM信息
|
||||
if (Boolean.TRUE.equals(bo.getIncludeBomInfo()) && bomList != null && !bomList.isEmpty()) {
|
||||
prompt.append("\n【BOM清单】\n");
|
||||
@@ -460,7 +280,6 @@ public class WmsSalesScriptGeneratorServiceImpl implements IWmsSalesScriptGenera
|
||||
.append(" ").append(bom.getUnit()).append("\n");
|
||||
}
|
||||
}
|
||||
|
||||
// 生成要求
|
||||
prompt.append("\n【话术生成要求】\n");
|
||||
prompt.append("1. 每条话术必须包含产品的主要特性和优势\n");
|
||||
@@ -469,7 +288,6 @@ public class WmsSalesScriptGeneratorServiceImpl implements IWmsSalesScriptGenera
|
||||
prompt.append("4. 话术要自然、专业、有说服力\n");
|
||||
prompt.append("5. 包含具体的应用场景和解决方案\n");
|
||||
prompt.append("6. 突出产品的核心竞争力\n");
|
||||
|
||||
// 输出格式
|
||||
prompt.append("\n【输出格式】\n");
|
||||
prompt.append("请按以下格式输出:\n\n");
|
||||
@@ -478,7 +296,6 @@ public class WmsSalesScriptGeneratorServiceImpl implements IWmsSalesScriptGenera
|
||||
prompt.append("标题:").append(product.getProductName()).append(" - 话术标题\n");
|
||||
prompt.append("内容:[具体话术内容]\n\n");
|
||||
}
|
||||
|
||||
return prompt.toString();
|
||||
}
|
||||
|
||||
@@ -487,11 +304,9 @@ public class WmsSalesScriptGeneratorServiceImpl implements IWmsSalesScriptGenera
|
||||
*/
|
||||
private List<Map<String, Object>> parseAiResponse(String response) {
|
||||
List<Map<String, Object>> scripts = new ArrayList<>();
|
||||
|
||||
// 使用正则表达式解析响应
|
||||
Pattern pattern = Pattern.compile("【话术(\\d+)】(.*?)\\n标题:(.*?)\\n内容:(.*?)(?=\\n【话术|\\Z)", Pattern.DOTALL);
|
||||
Matcher matcher = pattern.matcher(response);
|
||||
|
||||
while (matcher.find()) {
|
||||
Map<String, Object> script = new HashMap<>();
|
||||
script.put("customerType", matcher.group(2).trim());
|
||||
@@ -500,7 +315,6 @@ public class WmsSalesScriptGeneratorServiceImpl implements IWmsSalesScriptGenera
|
||||
script.put("featurePoint", extractFeaturePoints(matcher.group(4)));
|
||||
scripts.add(script);
|
||||
}
|
||||
|
||||
return scripts;
|
||||
}
|
||||
|
||||
@@ -509,7 +323,6 @@ public class WmsSalesScriptGeneratorServiceImpl implements IWmsSalesScriptGenera
|
||||
*/
|
||||
private String extractFeaturePoints(String content) {
|
||||
List<String> features = new ArrayList<>();
|
||||
|
||||
// 提取技术参数
|
||||
for (String pattern : TECH_PATTERNS) {
|
||||
Pattern techPattern = Pattern.compile(pattern + "[::]\\s*([\\d.]+)");
|
||||
@@ -518,7 +331,6 @@ public class WmsSalesScriptGeneratorServiceImpl implements IWmsSalesScriptGenera
|
||||
features.add("技术参数: " + matcher.group(1));
|
||||
}
|
||||
}
|
||||
|
||||
// 提取材料优势
|
||||
for (String keyword : FEATURE_KEYWORDS) {
|
||||
if (content.contains(keyword)) {
|
||||
@@ -528,50 +340,4 @@ public class WmsSalesScriptGeneratorServiceImpl implements IWmsSalesScriptGenera
|
||||
|
||||
return features.isEmpty() ? "产品特性突出" : String.join("; ", features);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取客户类型描述
|
||||
*/
|
||||
private String getCustomerTypeDescription(String type) {
|
||||
Map<String, String> descriptions = new HashMap<>();
|
||||
descriptions.put("技术型客户", "突出技术参数和性能优势");
|
||||
descriptions.put("价格敏感型客户", "强调性价比和成本效益");
|
||||
descriptions.put("质量优先型客户", "重点介绍品质保证和可靠性");
|
||||
descriptions.put("批量采购客户", "突出批量优惠和供应能力");
|
||||
descriptions.put("定制化需求客户", "强调定制服务和个性化解决方案");
|
||||
|
||||
return descriptions.getOrDefault(type, "");
|
||||
}
|
||||
|
||||
/**
|
||||
* 建议客户类型
|
||||
*/
|
||||
private List<String> suggestCustomerTypes(WmsProductVo product, List<WmsProductBom> bomList) {
|
||||
List<String> suggestions = new ArrayList<>();
|
||||
suggestions.add("技术型客户");
|
||||
suggestions.add("质量优先型客户");
|
||||
|
||||
if (bomList != null && bomList.size() > 3) {
|
||||
suggestions.add("批量采购客户");
|
||||
}
|
||||
|
||||
return suggestions;
|
||||
}
|
||||
|
||||
/**
|
||||
* 提取特性
|
||||
*/
|
||||
private List<String> extractFeatures(WmsProductVo product, List<WmsProductBom> bomList) {
|
||||
List<String> features = new ArrayList<>();
|
||||
|
||||
if (product.getThickness() != null || product.getWidth() != null || product.getInnerDiameter() != null) {
|
||||
features.add("精密制造");
|
||||
}
|
||||
|
||||
if (bomList != null && !bomList.isEmpty()) {
|
||||
features.add("优质材料");
|
||||
}
|
||||
|
||||
return features;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user