diff --git a/jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/service/impl/AppletApiTTServiceImpl.java b/jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/service/impl/AppletApiTTServiceImpl.java index 02b02d7..af605ce 100644 --- a/jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/service/impl/AppletApiTTServiceImpl.java +++ b/jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/service/impl/AppletApiTTServiceImpl.java @@ -418,6 +418,17 @@ public class AppletApiTTServiceImpl implements AppletApiTTService { return CompletableFuture.completedFuture(successCache.getTaskId()); } + // 写入缓存,标记生成中(text字段保存哈希) + AppletTtsCache cache = new AppletTtsCache(); + cache.setText(textHash); + cache.setVoiceType(voiceType); + cache.setVolume(volume != null ? volume.doubleValue() : null); + cache.setSpeed(speed != null ? speed.doubleValue() : null); + cache.setSuccess("N"); + cache.setState(0); + cache.setCreateTime(new java.util.Date()); + appletTtsCacheService.save(cache); + // 应用并发控制,等待获取请求许可 log.info("开始等待长文本TTS请求许可,textHash: {}", textHash); waitForLongTextTtsPermit(); @@ -445,17 +456,8 @@ public class AppletApiTTServiceImpl implements AppletApiTTService { throw new JeecgBootException("创建长文本TTS任务失败,未返回任务ID"); } - // 写入缓存,标记生成中(text字段保存哈希) - AppletTtsCache cache = new AppletTtsCache(); cache.setTaskId(taskId); - cache.setText(textHash); - cache.setVoiceType(voiceType); - cache.setVolume(volume != null ? volume.doubleValue() : null); - cache.setSpeed(speed != null ? speed.doubleValue() : null); - cache.setSuccess("N"); - cache.setState(0); - cache.setCreateTime(new java.util.Date()); - appletTtsCacheService.save(cache); + appletTtsCacheService.updateById(cache); log.info("长文本TTS任务创建成功,taskId: {},textHash: {}", taskId, textHash); return CompletableFuture.completedFuture(taskId); diff --git a/jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/demo/appletArticle/controller/AppletArticleController.java b/jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/demo/appletArticle/controller/AppletArticleController.java index 09fa0da..08a755e 100644 --- a/jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/demo/appletArticle/controller/AppletArticleController.java +++ b/jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/demo/appletArticle/controller/AppletArticleController.java @@ -14,6 +14,7 @@ import org.jeecg.common.api.vo.Result; import org.jeecg.common.system.query.QueryGenerator; import org.jeecg.common.system.query.QueryRuleEnum; import org.jeecg.common.util.oConvertUtils; +import org.jeecg.modules.applet.util.HtmlUtils; import org.jeecg.modules.demo.appletArticle.entity.AppletArticle; import org.jeecg.modules.demo.appletArticle.service.IAppletArticleService; @@ -96,20 +97,12 @@ public class AppletArticleController extends JeecgController add(@RequestBody AppletArticle appletArticle) { + String content = appletArticle.getContent(); + if (content != null && !content.trim().isEmpty()) { + String contentHashcode = HtmlUtils.calculateStringHash(HtmlUtils.stripHtml(content)); + appletArticle.setContentHashcode(contentHashcode); + } appletArticleService.save(appletArticle); - - // 触发长文本TTS生成:遍历所有启用音色,对content进行转换 -// try { -// String content = appletArticle.getContent(); -// if (content != null && !content.trim().isEmpty()) { -// String code = appletApiTTService.generateLongTextForArticleContentAllTimbres(content); -// appletArticle.setContentHashcode(code); -// appletArticleService.updateById(appletArticle); -// } -// } catch (Exception e) { -// log.warn("文章添加后触发长文本TTS失败: {}", e.getMessage()); -// } - return Result.OK("添加成功!"); } @@ -124,16 +117,11 @@ public class AppletArticleController extends JeecgController edit(@RequestBody AppletArticle appletArticle) { - // 触发长文本TTS生成:遍历所有启用音色,对content进行转换 -// try { -// String content = appletArticle.getContent(); -// if (content != null && !content.trim().isEmpty()) { -// String code = appletApiTTService.generateLongTextForArticleContentAllTimbres(content); -// appletArticle.setContentHashcode(code); -// } -// } catch (Exception e) { -// log.warn("文章编辑后触发长文本TTS失败: {}", e.getMessage()); -// } + String content = appletArticle.getContent(); + if (content != null && !content.trim().isEmpty()) { + String contentHashcode = HtmlUtils.calculateStringHash(HtmlUtils.stripHtml(content)); + appletArticle.setContentHashcode(contentHashcode); + } appletArticleService.updateById(appletArticle); return Result.OK("编辑成功!"); }