前端-胡立永 1 week ago
parent
commit
0140f044be
2 changed files with 152 additions and 148 deletions
  1. +4
    -0
      jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/util/HtmlUtils.java
  2. +148
    -148
      jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/demo/appletArticle/controller/AppletArticleController.java

+ 4
- 0
jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/util/HtmlUtils.java View File

@ -230,6 +230,10 @@ public class HtmlUtils {
// 移除HTML标签 // 移除HTML标签
String noTag = html.replaceAll("<[^>]*>", ""); String noTag = html.replaceAll("<[^>]*>", "");
// 处理常见的HTML实体 // 处理常见的HTML实体
noTag = noTag.replace("&rdquo;", " ");
noTag = noTag.replace("&mdash;", " ");
noTag = noTag.replace("&ldquo;", " ");
noTag = noTag.replace("&middot;", " ");
noTag = noTag.replace("&nbsp;", " "); noTag = noTag.replace("&nbsp;", " ");
noTag = noTag.replace("&amp;", "&"); noTag = noTag.replace("&amp;", "&");
noTag = noTag.replace("&lt;", "<"); noTag = noTag.replace("&lt;", "<");


+ 148
- 148
jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/demo/appletArticle/controller/AppletArticleController.java View File

@ -51,127 +51,127 @@ import org.jeecg.modules.applet.service.AppletApiTTService;
@RequestMapping("/appletArticle/appletArticle") @RequestMapping("/appletArticle/appletArticle")
@Slf4j @Slf4j
public class AppletArticleController extends JeecgController<AppletArticle, IAppletArticleService> { public class AppletArticleController extends JeecgController<AppletArticle, IAppletArticleService> {
@Autowired
private IAppletArticleService appletArticleService;
@Autowired
private IAppletArticleService appletArticleService;
@Autowired @Autowired
private AppletApiTTService appletApiTTService; private AppletApiTTService appletApiTTService;
/**
* 分页列表查询
*
* @param appletArticle
* @param pageNo
* @param pageSize
* @param req
* @return
*/
//@AutoLog(value = "小程序文章-分页列表查询")
@Operation(summary="小程序文章-分页列表查询")
@GetMapping(value = "/list")
public Result<IPage<AppletArticle>> 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<IPage<AppletArticle>> queryPageList(AppletArticle appletArticle,
@RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
@RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
HttpServletRequest req) {
QueryWrapper<AppletArticle> queryWrapper = QueryGenerator.initQueryWrapper(appletArticle, req.getParameterMap()); QueryWrapper<AppletArticle> queryWrapper = QueryGenerator.initQueryWrapper(appletArticle, req.getParameterMap());
Page<AppletArticle> page = new Page<AppletArticle>(pageNo, pageSize);
IPage<AppletArticle> 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<String> 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<String> 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<String> 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<String> 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<AppletArticle> queryById(@RequestParam(name="id",required=true) String id) {
AppletArticle appletArticle = appletArticleService.getById(id);
if(appletArticle==null) {
return Result.error("未找到对应数据");
}
return Result.OK(appletArticle);
}
Page<AppletArticle> page = new Page<AppletArticle>(pageNo, pageSize);
IPage<AppletArticle> 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<String> 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<String> 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<String> 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<String> 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<AppletArticle> queryById(@RequestParam(name="id",required=true) String id) {
AppletArticle appletArticle = appletArticleService.getById(id);
if(appletArticle==null) {
return Result.error("未找到对应数据");
}
return Result.OK(appletArticle);
}
/** /**
* 导出excel * 导出excel
@ -198,38 +198,38 @@ public class AppletArticleController extends JeecgController<AppletArticle, IApp
return super.importExcel(request, response, AppletArticle.class); return super.importExcel(request, response, AppletArticle.class);
} }
/**
* 手动触发音频转换
*
* @param id 文章ID
* @return
*/
@AutoLog(value = "小程序文章-触发音频转换")
@Operation(summary="小程序文章-触发音频转换")
@RequiresPermissions("appletArticle:applet_article:edit")
@GetMapping(value = "/generateAudio")
public Result<String> 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<String> 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());
}
}
} }

Loading…
Cancel
Save