diff --git a/ruoyi-system/src/main/java/com/ruoyi/jarvis/service/impl/SocialMediaServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/jarvis/service/impl/SocialMediaServiceImpl.java index 660b291..0a05c97 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/jarvis/service/impl/SocialMediaServiceImpl.java +++ b/ruoyi-system/src/main/java/com/ruoyi/jarvis/service/impl/SocialMediaServiceImpl.java @@ -24,12 +24,12 @@ import java.util.regex.PatternSyntaxException; /** * 小红书/抖音内容生成Service业务层处理 - * + * * @author ruoyi * @date 2025-01-XX */ @Service -public class SocialMediaServiceImpl implements ISocialMediaService +public class SocialMediaServiceImpl implements ISocialMediaService { private static final Logger log = LoggerFactory.getLogger(SocialMediaServiceImpl.class); @@ -194,7 +194,7 @@ public class SocialMediaServiceImpl implements ISocialMediaService @Override public Map extractKeywords(String productName) { Map result = new HashMap<>(); - + if (StringUtils.isEmpty(productName)) { result.put("success", false); result.put("error", "商品名称不能为空"); @@ -206,15 +206,15 @@ public class SocialMediaServiceImpl implements ISocialMediaService String url = jarvisBaseUrl + "/jarvis/social-media/extract-keywords"; JSONObject requestBody = new JSONObject(); requestBody.put("productName", productName); - + log.info("调用jarvis_java提取关键词接口,URL: {}, 参数: {}", url, requestBody.toJSONString()); String response = HttpUtils.sendJsonPost(url, requestBody.toJSONString()); log.info("jarvis_java响应: {}", response); - + if (StringUtils.isEmpty(response)) { throw new Exception("jarvis_java返回空结果"); } - + // 解析响应 Object parsed = JSON.parse(response); if (parsed instanceof JSONObject) { @@ -233,11 +233,11 @@ public class SocialMediaServiceImpl implements ISocialMediaService return result; } } - + result.put("success", false); result.put("error", "响应格式错误"); return result; - + } catch (Exception e) { log.error("提取关键词失败", e); result.put("success", false); @@ -250,10 +250,10 @@ public class SocialMediaServiceImpl implements ISocialMediaService * 生成文案 */ @Override - public Map generateContent(String productName, Object originalPrice, + public Map generateContent(String productName, Object originalPrice, Object finalPrice, String keywords, String style) { Map result = new HashMap<>(); - + if (StringUtils.isEmpty(productName)) { result.put("success", false); result.put("error", "商品名称不能为空"); @@ -277,15 +277,15 @@ public class SocialMediaServiceImpl implements ISocialMediaService if (StringUtils.isNotEmpty(style)) { requestBody.put("style", style); } - + log.info("调用jarvis_java生成文案接口,URL: {}, 参数: {}", url, requestBody.toJSONString()); String response = HttpUtils.sendJsonPost(url, requestBody.toJSONString()); log.info("jarvis_java响应: {}", response); - + if (StringUtils.isEmpty(response)) { throw new Exception("jarvis_java返回空结果"); } - + // 解析响应 Object parsed = JSON.parse(response); if (parsed instanceof JSONObject) { @@ -304,11 +304,11 @@ public class SocialMediaServiceImpl implements ISocialMediaService return result; } } - + result.put("success", false); result.put("error", "响应格式错误"); return result; - + } catch (Exception e) { log.error("生成文案失败", e); result.put("success", false); @@ -324,7 +324,7 @@ public class SocialMediaServiceImpl implements ISocialMediaService public Map generateCompleteContent(String productImageUrl, String productName, Object originalPrice, Object finalPrice, String style) { Map result = new HashMap<>(); - + if (StringUtils.isEmpty(productName)) { result.put("success", false); result.put("error", "商品名称不能为空"); @@ -348,15 +348,15 @@ public class SocialMediaServiceImpl implements ISocialMediaService if (StringUtils.isNotEmpty(style)) { requestBody.put("style", style); } - + log.info("调用jarvis_java生成完整内容接口,URL: {}, 参数: {}", url, requestBody.toJSONString()); String response = HttpUtils.sendJsonPost(url, requestBody.toJSONString()); log.info("jarvis_java响应: {}", response); - + if (StringUtils.isEmpty(response)) { throw new Exception("jarvis_java返回空结果"); } - + // 解析响应 Object parsed = JSON.parse(response); if (parsed instanceof JSONObject) { @@ -375,11 +375,11 @@ public class SocialMediaServiceImpl implements ISocialMediaService return result; } } - + result.put("success", false); result.put("error", "响应格式错误"); return result; - + } catch (Exception e) { log.error("生成完整内容失败", e); result.put("success", false); @@ -395,20 +395,20 @@ public class SocialMediaServiceImpl implements ISocialMediaService public AjaxResult listPromptTemplates() { try { Map templates = new HashMap<>(); - + for (String key : TEMPLATE_KEYS) { Map templateInfo = new HashMap<>(); templateInfo.put("key", key); templateInfo.put("description", TEMPLATE_DESCRIPTIONS.get(key)); - + String stored = getTemplateFromRedis(key); boolean isDefault = StringUtils.isEmpty(stored); templateInfo.put("template", isDefault ? DEFAULT_PROMPT_TEMPLATES.getOrDefault(key, "") : stored); templateInfo.put("isDefault", isDefault); - + templates.put(key, templateInfo); } - + return AjaxResult.success(templates); } catch (Exception e) { log.error("获取提示词模板列表失败", e); @@ -425,7 +425,7 @@ public class SocialMediaServiceImpl implements ISocialMediaService if (!isValidKey(key)) { return AjaxResult.error("无效的模板键名"); } - + String stored = getTemplateFromRedis(key); boolean isDefault = StringUtils.isEmpty(stored); Map data = new HashMap<>(); @@ -433,7 +433,7 @@ public class SocialMediaServiceImpl implements ISocialMediaService data.put("description", TEMPLATE_DESCRIPTIONS.get(key)); data.put("template", isDefault ? DEFAULT_PROMPT_TEMPLATES.getOrDefault(key, "") : stored); data.put("isDefault", isDefault); - + return AjaxResult.success(data); } catch (Exception e) { log.error("获取提示词模板失败", e); @@ -449,19 +449,19 @@ public class SocialMediaServiceImpl implements ISocialMediaService try { String key = (String) request.get("key"); String template = (String) request.get("template"); - + if (!isValidKey(key)) { return AjaxResult.error("无效的模板键名"); } - + if (StringUtils.isEmpty(template)) { return AjaxResult.error("模板内容不能为空"); } - + if (redisTemplate == null) { return AjaxResult.error("Redis未配置,无法保存模板"); } - + String redisKey = REDIS_KEY_PREFIX + key; String templateValue = template.trim(); if (StringUtils.isEmpty(templateValue)) { @@ -475,10 +475,10 @@ public class SocialMediaServiceImpl implements ISocialMediaService } } redisTemplate.opsForValue().set(redisKey, templateValue); - + log.info("保存提示词模板成功: {}", key); return AjaxResult.success("保存成功"); - + } catch (Exception e) { log.error("保存提示词模板失败", e); return AjaxResult.error("保存失败: " + e.getMessage()); @@ -494,17 +494,17 @@ public class SocialMediaServiceImpl implements ISocialMediaService if (!isValidKey(key)) { return AjaxResult.error("无效的模板键名"); } - + if (redisTemplate == null) { return AjaxResult.error("Redis未配置,无法删除模板"); } - + String redisKey = REDIS_KEY_PREFIX + key; redisTemplate.delete(redisKey); - + log.info("删除提示词模板成功: {}", key); return AjaxResult.success("删除成功,已恢复默认模板"); - + } catch (Exception e) { log.error("删除提示词模板失败", e); return AjaxResult.error("删除失败: " + e.getMessage()); @@ -518,7 +518,7 @@ public class SocialMediaServiceImpl implements ISocialMediaService if (redisTemplate == null) { return null; } - + try { String redisKey = REDIS_KEY_PREFIX + key; String template = redisTemplate.opsForValue().get(redisKey); @@ -1021,7 +1021,7 @@ public class SocialMediaServiceImpl implements ISocialMediaService // 标题行 StringBuilder daixiadanBuilder = new StringBuilder(); - daixiadanBuilder.append("(一键代下) ").append(cleanTitle).append("\n"); + daixiadanBuilder.append(cleanTitle).append("\n"); // 型号行(可选) if (StringUtils.isNotEmpty(cleanRemark)) { daixiadanBuilder.append("型号:").append(cleanRemark).append("\n"); @@ -1030,7 +1030,7 @@ public class SocialMediaServiceImpl implements ISocialMediaService // 教你下单版 StringBuilder jiaonixiadanBuilder = new StringBuilder(); - jiaonixiadanBuilder.append("【教你下单】 ").append(cleanTitle).append("\n"); + jiaonixiadanBuilder.append(cleanTitle).append("\n"); if (StringUtils.isNotEmpty(cleanRemark)) { jiaonixiadanBuilder.append("型号:").append(cleanRemark).append("\n"); }