diff --git a/jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/util/HtmlUtils.java b/jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/util/HtmlUtils.java index 286d339..a12de8d 100644 --- a/jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/util/HtmlUtils.java +++ b/jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/util/HtmlUtils.java @@ -230,6 +230,10 @@ public class HtmlUtils { // 移除HTML标签 String noTag = html.replaceAll("<[^>]*>", ""); // 处理常见的HTML实体 + noTag = noTag.replace("”", " "); + noTag = noTag.replace("—", " "); + noTag = noTag.replace("“", " "); + noTag = noTag.replace("·", " "); noTag = noTag.replace(" ", " "); noTag = noTag.replace("&", "&"); noTag = noTag.replace("<", "<"); 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 08a755e..3e3e43c 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 @@ -51,127 +51,127 @@ import org.jeecg.modules.applet.service.AppletApiTTService; @RequestMapping("/appletArticle/appletArticle") @Slf4j public class AppletArticleController extends JeecgController { - @Autowired - private IAppletArticleService appletArticleService; + @Autowired + private IAppletArticleService appletArticleService; @Autowired private AppletApiTTService appletApiTTService; - - /** - * 分页列表查询 - * - * @param appletArticle - * @param pageNo - * @param pageSize - * @param req - * @return - */ - //@AutoLog(value = "小程序文章-分页列表查询") - @Operation(summary="小程序文章-分页列表查询") - @GetMapping(value = "/list") - public Result> queryPageList(AppletArticle appletArticle, - @RequestParam(name="pageNo", defaultValue="1") Integer pageNo, - @RequestParam(name="pageSize", defaultValue="10") Integer pageSize, - HttpServletRequest req) { + + /** + * 分页列表查询 + * + * @param appletArticle + * @param pageNo + * @param pageSize + * @param req + * @return + */ + //@AutoLog(value = "小程序文章-分页列表查询") + @Operation(summary="小程序文章-分页列表查询") + @GetMapping(value = "/list") + public Result> queryPageList(AppletArticle appletArticle, + @RequestParam(name="pageNo", defaultValue="1") Integer pageNo, + @RequestParam(name="pageSize", defaultValue="10") Integer pageSize, + HttpServletRequest req) { QueryWrapper queryWrapper = QueryGenerator.initQueryWrapper(appletArticle, req.getParameterMap()); - Page page = new Page(pageNo, pageSize); - IPage pageList = appletArticleService.page(page, queryWrapper); - - for (AppletArticle record : page.getRecords()) { - record.setAudioStatus(appletApiTTService.getAudioBuildStatus(record.getContentHashcode())); - } - - return Result.OK(pageList); - } - - /** - * 添加 - * - * @param appletArticle - * @return - */ - @AutoLog(value = "小程序文章-添加") - @Operation(summary="小程序文章-添加") - @RequiresPermissions("appletArticle:applet_article:add") - @PostMapping(value = "/add") - public Result 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); - return Result.OK("添加成功!"); - } - - /** - * 编辑 - * - * @param appletArticle - * @return - */ - @AutoLog(value = "小程序文章-编辑") - @Operation(summary="小程序文章-编辑") - @RequiresPermissions("appletArticle:applet_article:edit") - @RequestMapping(value = "/edit", method = {RequestMethod.PUT,RequestMethod.POST}) - public Result edit(@RequestBody AppletArticle appletArticle) { - 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("编辑成功!"); - } - - /** - * 通过id删除 - * - * @param id - * @return - */ - @AutoLog(value = "小程序文章-通过id删除") - @Operation(summary="小程序文章-通过id删除") - @RequiresPermissions("appletArticle:applet_article:delete") - @DeleteMapping(value = "/delete") - public Result delete(@RequestParam(name="id",required=true) String id) { - appletArticleService.removeById(id); - return Result.OK("删除成功!"); - } - - /** - * 批量删除 - * - * @param ids - * @return - */ - @AutoLog(value = "小程序文章-批量删除") - @Operation(summary="小程序文章-批量删除") - @RequiresPermissions("appletArticle:applet_article:deleteBatch") - @DeleteMapping(value = "/deleteBatch") - public Result deleteBatch(@RequestParam(name="ids",required=true) String ids) { - this.appletArticleService.removeByIds(Arrays.asList(ids.split(","))); - return Result.OK("批量删除成功!"); - } - - /** - * 通过id查询 - * - * @param id - * @return - */ - //@AutoLog(value = "小程序文章-通过id查询") - @Operation(summary="小程序文章-通过id查询") - @GetMapping(value = "/queryById") - public Result queryById(@RequestParam(name="id",required=true) String id) { - AppletArticle appletArticle = appletArticleService.getById(id); - if(appletArticle==null) { - return Result.error("未找到对应数据"); - } - return Result.OK(appletArticle); - } + Page page = new Page(pageNo, pageSize); + IPage pageList = appletArticleService.page(page, queryWrapper); + + for (AppletArticle record : page.getRecords()) { + record.setAudioStatus(appletApiTTService.getAudioBuildStatus(record.getContentHashcode())); + } + + return Result.OK(pageList); + } + + /** + * 添加 + * + * @param appletArticle + * @return + */ + @AutoLog(value = "小程序文章-添加") + @Operation(summary="小程序文章-添加") + @RequiresPermissions("appletArticle:applet_article:add") + @PostMapping(value = "/add") + public Result 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); + return Result.OK("添加成功!"); + } + + /** + * 编辑 + * + * @param appletArticle + * @return + */ + @AutoLog(value = "小程序文章-编辑") + @Operation(summary="小程序文章-编辑") + @RequiresPermissions("appletArticle:applet_article:edit") + @RequestMapping(value = "/edit", method = {RequestMethod.PUT,RequestMethod.POST}) + public Result edit(@RequestBody AppletArticle appletArticle) { + 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("编辑成功!"); + } + + /** + * 通过id删除 + * + * @param id + * @return + */ + @AutoLog(value = "小程序文章-通过id删除") + @Operation(summary="小程序文章-通过id删除") + @RequiresPermissions("appletArticle:applet_article:delete") + @DeleteMapping(value = "/delete") + public Result delete(@RequestParam(name="id",required=true) String id) { + appletArticleService.removeById(id); + return Result.OK("删除成功!"); + } + + /** + * 批量删除 + * + * @param ids + * @return + */ + @AutoLog(value = "小程序文章-批量删除") + @Operation(summary="小程序文章-批量删除") + @RequiresPermissions("appletArticle:applet_article:deleteBatch") + @DeleteMapping(value = "/deleteBatch") + public Result deleteBatch(@RequestParam(name="ids",required=true) String ids) { + this.appletArticleService.removeByIds(Arrays.asList(ids.split(","))); + return Result.OK("批量删除成功!"); + } + + /** + * 通过id查询 + * + * @param id + * @return + */ + //@AutoLog(value = "小程序文章-通过id查询") + @Operation(summary="小程序文章-通过id查询") + @GetMapping(value = "/queryById") + public Result queryById(@RequestParam(name="id",required=true) String id) { + AppletArticle appletArticle = appletArticleService.getById(id); + if(appletArticle==null) { + return Result.error("未找到对应数据"); + } + return Result.OK(appletArticle); + } /** * 导出excel @@ -198,38 +198,38 @@ public class AppletArticleController extends JeecgController generateAudio(@RequestParam(name="id",required=true) String id) { - try { - AppletArticle appletArticle = appletArticleService.getById(id); - if (appletArticle == null) { - return Result.error("文章不存在"); - } - - String content = appletArticle.getContent(); - if (content == null || content.trim().isEmpty()) { - return Result.error("文章内容为空,无法生成音频"); - } - - // 触发长文本TTS生成:遍历所有启用音色,对content进行转换 - String code = appletApiTTService.generateLongTextForArticleContentAllTimbres(content); - appletArticle.setContentHashcode(code); - appletArticleService.updateById(appletArticle); - - return Result.OK("音频转换已开始,请稍后查看状态"); - } catch (Exception e) { - log.error("触发音频转换失败: {}", e.getMessage(), e); - return Result.error("音频转换失败: " + e.getMessage()); - } - } + /** + * 手动触发音频转换 + * + * @param id 文章ID + * @return + */ + @AutoLog(value = "小程序文章-触发音频转换") + @Operation(summary="小程序文章-触发音频转换") + @RequiresPermissions("appletArticle:applet_article:edit") + @GetMapping(value = "/generateAudio") + public Result generateAudio(@RequestParam(name="id",required=true) String id) { + try { + AppletArticle appletArticle = appletArticleService.getById(id); + if (appletArticle == null) { + return Result.error("文章不存在"); + } + + String content = appletArticle.getContent(); + if (content == null || content.trim().isEmpty()) { + return Result.error("文章内容为空,无法生成音频"); + } + + // 触发长文本TTS生成:遍历所有启用音色,对content进行转换 + String code = appletApiTTService.generateLongTextForArticleContentAllTimbres(content); + appletArticle.setContentHashcode(code); + appletArticleService.updateById(appletArticle); + + return Result.OK("音频转换已开始,请稍后查看状态"); + } catch (Exception e) { + log.error("触发音频转换失败: {}", e.getMessage(), e); + return Result.error("音频转换失败: " + e.getMessage()); + } + } }