3 Commits

Author SHA1 Message Date
  前端-胡立永 4c031fec10 1 1 week ago
  前端-胡立永 27057bec9d 1 1 week ago
  前端-胡立永 0140f044be 1 1 week ago
4 changed files with 166 additions and 154 deletions
Unified View
  1. +1
    -0
      jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/controller/AppletApiTTSController.java
  2. +13
    -6
      jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/service/impl/AppletApiTTServiceImpl.java
  3. +4
    -0
      jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/util/HtmlUtils.java
  4. +148
    -148
      jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/demo/appletArticle/controller/AppletArticleController.java

+ 1
- 0
jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/controller/AppletApiTTSController.java View File

@ -32,6 +32,7 @@ public class AppletApiTTSController {
@Operation(summary = "查询音色列表", description = "查询音色列表") @Operation(summary = "查询音色列表", description = "查询音色列表")
@GetMapping(value = "/list") @GetMapping(value = "/list")
@IgnoreAuth
public Result<List<AppletTtsTimbre>> list() { public Result<List<AppletTtsTimbre>> list() {
return Result.OK(appletApiTTService.list()); return Result.OK(appletApiTTService.list());
} }


+ 13
- 6
jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/service/impl/AppletApiTTServiceImpl.java View File

@ -15,6 +15,7 @@ import com.tencentcloudapi.tts.v20190823.models.CreateTtsTaskResponse;
import com.tencentcloudapi.tts.v20190823.models.DescribeTtsTaskStatusRequest; import com.tencentcloudapi.tts.v20190823.models.DescribeTtsTaskStatusRequest;
import com.tencentcloudapi.tts.v20190823.models.DescribeTtsTaskStatusResponse; import com.tencentcloudapi.tts.v20190823.models.DescribeTtsTaskStatusResponse;
import lombok.extern.log4j.Log4j2; import lombok.extern.log4j.Log4j2;
import org.apache.commons.lang.StringUtils;
import org.jeecg.common.exception.JeecgBootException; import org.jeecg.common.exception.JeecgBootException;
import org.jeecg.common.system.util.AppletUserUtil; import org.jeecg.common.system.util.AppletUserUtil;
import org.jeecg.common.util.oss.OssBootUtil; import org.jeecg.common.util.oss.OssBootUtil;
@ -193,7 +194,8 @@ public class AppletApiTTServiceImpl implements AppletApiTTService {
.eq(speed != null, AppletTtsCache::getSpeed, speed != null ? speed.doubleValue() : null) .eq(speed != null, AppletTtsCache::getSpeed, speed != null ? speed.doubleValue() : null)
.eq(AppletTtsCache::getSuccess, "Y"); .eq(AppletTtsCache::getSuccess, "Y");
AppletTtsCache existingCache = appletTtsCacheService.getOne(queryWrapper);
List<AppletTtsCache> list = appletTtsCacheService.list(queryWrapper);
AppletTtsCache existingCache = list.size() > 0 ? list.get(0) : null;
if (existingCache != null) { if (existingCache != null) {
// 缓存命中直接返回缓存的音频ID // 缓存命中直接返回缓存的音频ID
@ -201,13 +203,17 @@ public class AppletApiTTServiceImpl implements AppletApiTTService {
// 记录播放日志 // 记录播放日志
long endTime = System.currentTimeMillis(); long endTime = System.currentTimeMillis();
double elapsedTime = (endTime - startTime) / 1000.0;
savePlayLog(userId, text, voiceType, volume != null ? volume.doubleValue() : null,
speed != null ? speed.doubleValue() : null, elapsedTime, true, existingCache.getId());
// double elapsedTime = (endTime - startTime) / 1000.0;
// savePlayLog(userId, text, voiceType, volume != null ? volume.doubleValue() : null,
// speed != null ? speed.doubleValue() : null, elapsedTime, true, existingCache.getId());
if (StringUtils.isBlank(existingCache.getAudioId())){
throw new JeecgBootException("音频URL无效");
}
return TtsVo.builder() return TtsVo.builder()
.url(existingCache.getAudioId()) .url(existingCache.getAudioId())
.time(existingCache.getDuration())
.time(existingCache.getDuration() == null ? 0 : existingCache.getDuration())
.build(); .build();
} }
@ -286,7 +292,8 @@ public class AppletApiTTServiceImpl implements AppletApiTTService {
log.info("TTS调用成功,文本长度: {}, 耗时: {}秒", text != null ? text.length() : 0, elapsedTime); log.info("TTS调用成功,文本长度: {}, 耗时: {}秒", text != null ? text.length() : 0, elapsedTime);
return TtsVo.builder() return TtsVo.builder()
.url(cache.getAudioId()) .url(cache.getAudioId())
.time(cache.getDuration())
// .time(cache.getDuration())
.time(cache.getDuration() == null ? 0 : cache.getDuration())
.build(); .build();
} else { } else {
// 记录失败的TTS调用日志 // 记录失败的TTS调用日志


+ 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