From 18b226789a7319aa39521de26189110207fbe00c Mon Sep 17 00:00:00 2001 From: huliyong <2783385703@qq.com> Date: Mon, 15 Sep 2025 20:02:35 +0800 Subject: [PATCH] 1 --- .../controller/AppletApiBooksController.java | 32 ++++- .../controller/AppletApiIndexController.java | 7 +- .../controller/AppletApiMemberController.java | 9 +- .../applet/controller/AppletApiTTSController.java | 77 ++++++----- .../applet/service/AppletApiBooksService.java | 6 + .../modules/applet/service/AppletApiTTService.java | 4 +- .../service/impl/AppletApiBooksServiceImpl.java | 18 +++ .../service/impl/AppletApiTTServiceImpl.java | 144 ++++++++++++++++----- 8 files changed, 221 insertions(+), 76 deletions(-) diff --git a/jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/controller/AppletApiBooksController.java b/jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/controller/AppletApiBooksController.java index 9295db5..4862ad8 100644 --- a/jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/controller/AppletApiBooksController.java +++ b/jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/controller/AppletApiBooksController.java @@ -12,6 +12,7 @@ import org.jeecg.modules.demo.appletBookStand.entity.AppletBookStand; import org.jeecg.modules.demo.appletBooks.entity.AppletBooks; import org.jeecg.modules.demo.appletCategorize.entity.AppletCategorize; import org.jeecg.modules.demo.appletCourse.entity.AppletCourse; +import org.jeecg.modules.demo.appletLabel.entity.AppletLabel; import org.springframework.beans.factory.annotation.Autowired; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import org.springframework.web.bind.annotation.*; @@ -54,6 +55,35 @@ public class AppletApiBooksController { return Result.OK(list); } + /** + * 查询书籍标签 + * + * @return 查询书籍标签 + */ + @Operation(summary = "查询书籍标签", description = "查询书籍标签") + @GetMapping(value = "/label") + @IgnoreAuth + public Result> label() { + log.info("查询书籍标签"); + List list = appletApiBooksService.getLabel(); + return Result.OK(list); + } + + + /** + * 查询书籍分类 + * + * @return 查询书籍分类 + */ + @Operation(summary = "查询书籍分类", description = "查询书籍分类") + @GetMapping(value = "/category") + @IgnoreAuth + public Result> category() { + log.info("查询书籍标签"); + List list = appletApiBooksService.category(); + return Result.OK(list); + } + /** * 查询书桌列表 @@ -90,6 +120,7 @@ public class AppletApiBooksController { * * @return 删除书桌 */ + @IgnoreAuth @Operation(summary = "删除书桌", description = "删除书桌,批量删除用,分割") @PostMapping(value = "/delStand") public Result delStand(@Parameter(description = "书籍id") String id) { @@ -97,7 +128,6 @@ public class AppletApiBooksController { return Result.OK(); } - //TODO 需删除 @IgnoreAuth @IgnoreAuth @Operation(summary = "获取课程列表", description = "根据书籍id获取课程列表") @GetMapping(value = "/course") diff --git a/jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/controller/AppletApiIndexController.java b/jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/controller/AppletApiIndexController.java index 8145523..e91273c 100644 --- a/jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/controller/AppletApiIndexController.java +++ b/jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/controller/AppletApiIndexController.java @@ -14,6 +14,7 @@ import org.jeecg.modules.demo.appletLink.entity.AppletLink; import org.jeecg.modules.demo.appletRegistration.entity.AppletRegistration; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @@ -52,27 +53,23 @@ public class AppletApiIndexController { @IgnoreAuth @Operation(summary = "首页底部内容链接", description = "首页底部内容链接") @GetMapping(value = "/link") - public Result> link() { log.info("查询首页底部内容链接"); List list = appletApiIndexService.getLink(); return Result.OK(list); } - @IgnoreAuth @Operation(summary = "首页底部内容链接详情", description = "首页底部内容链接详情") @GetMapping(value = "/linkDetails") - public Result linkDetails(@Parameter(description = "链接id") String id) { log.info("查询首页底部内容链接详情"); AppletLink deta = appletApiIndexService.linkDetails(id); return Result.OK(deta); } - @Operation(summary = "首页底部内容添加报名", description = "首页底部内容添加报名") - @GetMapping(value = "/linkSignup") + @PostMapping(value = "/linkSignup") public Result linkSignup(AppletRegistration appletRegistration) { log.info("首页底部内容添加报名"); appletApiIndexService.linkSignup(appletRegistration); diff --git a/jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/controller/AppletApiMemberController.java b/jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/controller/AppletApiMemberController.java index 8fc45e8..a2decda 100644 --- a/jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/controller/AppletApiMemberController.java +++ b/jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/controller/AppletApiMemberController.java @@ -9,10 +9,8 @@ import org.jeecg.config.shiro.IgnoreAuth; import org.jeecg.modules.applet.service.AppletApiCouponService; import org.jeecg.modules.applet.service.AppletApiVipService; import org.jeecg.modules.demo.appletCoupon.entity.AppletCoupon; -import org.jeecg.modules.demo.appletCoupon.service.IAppletCouponService; import org.jeecg.modules.demo.appletMemberOrder.entity.AppletMemberOrder; import org.jeecg.modules.demo.appletVip.entity.AppletVip; -import org.jeecg.modules.demo.appletVip.service.IAppletVipService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; @@ -49,18 +47,13 @@ public class AppletApiMemberController { } + @IgnoreAuth @PostMapping("/payNotify") public Object payNotify(@RequestBody String requestBody) { - - //1、添加流水 - - //2、修改订单状态已支付 - return appletApiVipService.payNotify(requestBody); } - @IgnoreAuth @Operation(summary = "获取优惠劵", description = "获取优惠劵") @GetMapping(value = "/coupon") public Result> coupon(AppletCoupon appletCoupon) { diff --git a/jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/controller/AppletApiTTSController.java b/jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/controller/AppletApiTTSController.java index a4f92df..d3fb08b 100644 --- a/jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/controller/AppletApiTTSController.java +++ b/jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/controller/AppletApiTTSController.java @@ -35,7 +35,49 @@ public class AppletApiTTSController { @Operation(summary = "文字转语音", description = "文字转语音") @PostMapping(value = "/textToVoice") @IgnoreAuth - public ResponseEntity textToVoice( +// public ResponseEntity textToVoice( +// @Parameter(description = "要转换的文本内容", required = true) String text, +// @Parameter(description = "语速,范围:[-2,6],默认为0-2代表0.6倍\n" + +// "-1代表0.8倍\n" + +// "0代表1.0倍(默认)\n" + +// "1代表1.2倍\n" + +// "2代表1.5倍\n" + +// "6代表2.5倍") Float speed, +// @Parameter(description = "音色ID,默认为0") Integer voiceType, +// @Parameter(description = "音量大小,范围[-10,10],默认为0") Float volume, +// @Parameter(description = "返回音频格式,可取值:wav(默认),mp3,pcm") String codec) { +// +// try { +// byte[] audioData = appletApiTTService.textToVoice(text, speed, voiceType, volume, codec, null); +// +// if (audioData == null || audioData.length == 0) { +// return ResponseEntity.noContent().build(); +// } +// +// // 根据codec设置对应的Content-Type +// MediaType mediaType = MediaType.APPLICATION_OCTET_STREAM; +// if ("wav".equalsIgnoreCase(codec)) { +// mediaType = MediaType.parseMediaType("audio/wav"); +// } else if ("mp3".equalsIgnoreCase(codec)) { +// mediaType = MediaType.parseMediaType("audio/mpeg"); +// } else if ("pcm".equalsIgnoreCase(codec)) { +// mediaType = MediaType.parseMediaType("audio/pcm"); +// } +// +// HttpHeaders headers = new HttpHeaders(); +// headers.setContentType(mediaType); +// headers.setContentLength(audioData.length); +// +// return ResponseEntity.ok() +// .headers(headers) +// .body(audioData); +// +// } catch (Exception e) { +// log.error("文字转语音失败: {}", e.getMessage(), e); +// return ResponseEntity.internalServerError().build(); +// } +// } + public Result textToVoice( @Parameter(description = "要转换的文本内容", required = true) String text, @Parameter(description = "语速,范围:[-2,6],默认为0-2代表0.6倍\n" + "-1代表0.8倍\n" + @@ -46,36 +88,9 @@ public class AppletApiTTSController { @Parameter(description = "音色ID,默认为0") Integer voiceType, @Parameter(description = "音量大小,范围[-10,10],默认为0") Float volume, @Parameter(description = "返回音频格式,可取值:wav(默认),mp3,pcm") String codec) { - - try { - byte[] audioData = appletApiTTService.textToVoice(text, speed, voiceType, volume, codec, null); - - if (audioData == null || audioData.length == 0) { - return ResponseEntity.noContent().build(); - } - - // 根据codec设置对应的Content-Type - MediaType mediaType = MediaType.APPLICATION_OCTET_STREAM; - if ("wav".equalsIgnoreCase(codec)) { - mediaType = MediaType.parseMediaType("audio/wav"); - } else if ("mp3".equalsIgnoreCase(codec)) { - mediaType = MediaType.parseMediaType("audio/mpeg"); - } else if ("pcm".equalsIgnoreCase(codec)) { - mediaType = MediaType.parseMediaType("audio/pcm"); - } - - HttpHeaders headers = new HttpHeaders(); - headers.setContentType(mediaType); - headers.setContentLength(audioData.length); - - return ResponseEntity.ok() - .headers(headers) - .body(audioData); - - } catch (Exception e) { - log.error("文字转语音失败: {}", e.getMessage(), e); - return ResponseEntity.internalServerError().build(); - } + + String audioData = appletApiTTService.textToVoice(text, speed, voiceType, volume, codec); + return Result.ok(audioData); } } diff --git a/jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/service/AppletApiBooksService.java b/jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/service/AppletApiBooksService.java index 24eb4c3..3ec4186 100644 --- a/jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/service/AppletApiBooksService.java +++ b/jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/service/AppletApiBooksService.java @@ -4,7 +4,9 @@ import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import org.jeecg.modules.demo.appletBookStand.entity.AppletBookStand; import org.jeecg.modules.demo.appletBooks.entity.AppletBooks; +import org.jeecg.modules.demo.appletCategorize.entity.AppletCategorize; import org.jeecg.modules.demo.appletCourse.entity.AppletCourse; +import org.jeecg.modules.demo.appletLabel.entity.AppletLabel; import java.util.List; @@ -44,4 +46,8 @@ public interface AppletApiBooksService { * @return */ IPage getCourses(Page coursePage, String id); + + List getLabel(); + + List category(); } diff --git a/jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/service/AppletApiTTService.java b/jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/service/AppletApiTTService.java index 1df930c..a0545b9 100644 --- a/jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/service/AppletApiTTService.java +++ b/jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/service/AppletApiTTService.java @@ -14,7 +14,7 @@ public interface AppletApiTTService { * @param codec 返回音频格式,可取值:wav(默认),mp3,pcm * @return 音频二进制数据 */ - byte[] textToVoice(String text, Float speed, Integer voiceType, Float volume, String codec); + String textToVoice(String text, Float speed, Integer voiceType, Float volume, String codec); /** * 文字转语音(带用户ID记录日志) @@ -26,7 +26,7 @@ public interface AppletApiTTService { * @param userId 用户ID,用于记录日志 * @return 音频二进制数据 */ - byte[] textToVoice(String text, Float speed, Integer voiceType, Float volume, String codec, String userId); + String textToVoice(String text, Float speed, Integer voiceType, Float volume, String codec, String userId); List list(); } diff --git a/jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/service/impl/AppletApiBooksServiceImpl.java b/jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/service/impl/AppletApiBooksServiceImpl.java index 6749826..6c5fae5 100644 --- a/jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/service/impl/AppletApiBooksServiceImpl.java +++ b/jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/service/impl/AppletApiBooksServiceImpl.java @@ -13,8 +13,12 @@ import org.jeecg.modules.demo.appletBookStand.entity.AppletBookStand; import org.jeecg.modules.demo.appletBookStand.service.IAppletBookStandService; import org.jeecg.modules.demo.appletBooks.entity.AppletBooks; import org.jeecg.modules.demo.appletBooks.service.IAppletBooksService; +import org.jeecg.modules.demo.appletCategorize.entity.AppletCategorize; +import org.jeecg.modules.demo.appletCategorize.service.IAppletCategorizeService; import org.jeecg.modules.demo.appletCourse.entity.AppletCourse; import org.jeecg.modules.demo.appletCourse.service.IAppletCourseService; +import org.jeecg.modules.demo.appletLabel.entity.AppletLabel; +import org.jeecg.modules.demo.appletLabel.service.IAppletLabelService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -31,6 +35,10 @@ public class AppletApiBooksServiceImpl implements AppletApiBooksService { private IAppletBookStandService appletBookStandService; @Autowired private IAppletCourseService appletCourseService; + @Autowired + private IAppletLabelService appletLabelService; + @Autowired + private IAppletCategorizeService appletCategorizeService; /** * 查询书籍列表 @@ -139,4 +147,14 @@ public class AppletApiBooksServiceImpl implements AppletApiBooksService { return pageResult; } + @Override + public List getLabel() { + return appletLabelService.list(); + } + + @Override + public List category() { + return appletCategorizeService.list(); + } + } 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 727a91c..e0ff1ef 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 @@ -34,35 +34,124 @@ public class AppletApiTTServiceImpl implements AppletApiTTService { private IAppletTtsPlayLogService appletTtsPlayLogService; @Override - public byte[] textToVoice(String text, Float speed, Integer voiceType, Float volume, String codec) { + public String textToVoice(String text, Float speed, Integer voiceType, Float volume, String codec) { return textToVoice(text, speed, voiceType, volume, codec, null); } - public byte[] textToVoice(String text, Float speed, Integer voiceType, Float volume, String codec, String userId) { +// public byte[] textToVoice(String text, Float speed, Integer voiceType, Float volume, String codec, String userId) { +// long startTime = System.currentTimeMillis(); +// +// try { +// // 创建认证对象 +// Credential cred = new Credential(secretId, secretKey); +// +// // 实例化一个http选项,可选的,没有特殊需求可以跳过 +// HttpProfile httpProfile = new HttpProfile(); +// httpProfile.setEndpoint("tts.tencentcloudapi.com"); +// +// // 实例化一个client选项,可选的,没有特殊需求可以跳过 +// ClientProfile clientProfile = new ClientProfile(); +// clientProfile.setHttpProfile(httpProfile); +// +// // 实例化要请求产品的client对象 +// TtsClient client = new TtsClient(cred, "", clientProfile); +// +// // 实例化一个请求对象 +// TextToVoiceRequest req = new TextToVoiceRequest(); +// +// // 设置必填参数 +// req.setText(text); +// req.setSessionId(UUID.randomUUID().toString()); +// +// // 设置可选参数 +// if (speed != null) { +// req.setSpeed(speed); +// } +// if (voiceType != null) { +// req.setVoiceType(voiceType.longValue()); +// } +// if (volume != null) { +// req.setVolume(volume); +// } +// if (codec != null && !codec.isEmpty()) { +// req.setCodec(codec); +// } else { +// req.setCodec("wav"); // 默认wav格式 +// } +// +// // 设置其他默认参数 +// req.setModelType(1L); // 默认模型 +// req.setPrimaryLanguage(2L); // 中文 +// req.setSampleRate(16000L); // 16k采样率 +// +// // 返回的resp是一个TextToVoiceResponse的实例,与请求对象对应 +// TextToVoiceResponse resp = client.TextToVoice(req); +// +// // 计算耗时 +// long endTime = System.currentTimeMillis(); +// double elapsedTime = (endTime - startTime) / 1000.0; +// +// // 获取base64编码的音频数据并解码为二进制 +// String audioBase64 = resp.getAudio(); +// byte[] audioData = null; +// +// if (audioBase64 != null && !audioBase64.isEmpty()) { +// audioData = java.util.Base64.getDecoder().decode(audioBase64); +// +// // 记录成功的TTS调用日志 +// savePlayLog(userId, text, voiceType, volume != null ? volume.doubleValue() : null, +// speed != null ? speed.doubleValue() : null, elapsedTime, true); +// +// log.info("TTS调用成功,文本长度: {}, 耗时: {}秒", text != null ? text.length() : 0, elapsedTime); +// return audioData; +// } else { +// // 记录失败的TTS调用日志 +// savePlayLog(userId, text, voiceType, volume != null ? volume.doubleValue() : null, +// speed != null ? speed.doubleValue() : null, elapsedTime, false); +// +// log.warn("TTS返回的音频数据为空"); +// return null; +// } +// +// } catch (Exception e) { +// // 计算耗时 +// long endTime = System.currentTimeMillis(); +// double elapsedTime = (endTime - startTime) / 1000.0; +// +// // 记录失败的TTS调用日志 +// savePlayLog(userId, text, voiceType, volume != null ? volume.doubleValue() : null, +// speed != null ? speed.doubleValue() : null, elapsedTime, false); +// +// log.error("调用腾讯云TTS接口失败: {}", e.getMessage(), e); +// return null; +// } +// } + + public String textToVoice(String text, Float speed, Integer voiceType, Float volume, String codec, String userId) { long startTime = System.currentTimeMillis(); - + try { // 创建认证对象 Credential cred = new Credential(secretId, secretKey); - + // 实例化一个http选项,可选的,没有特殊需求可以跳过 HttpProfile httpProfile = new HttpProfile(); httpProfile.setEndpoint("tts.tencentcloudapi.com"); - + // 实例化一个client选项,可选的,没有特殊需求可以跳过 ClientProfile clientProfile = new ClientProfile(); clientProfile.setHttpProfile(httpProfile); - + // 实例化要请求产品的client对象 TtsClient client = new TtsClient(cred, "", clientProfile); - + // 实例化一个请求对象 TextToVoiceRequest req = new TextToVoiceRequest(); - + // 设置必填参数 req.setText(text); req.setSessionId(UUID.randomUUID().toString()); - + // 设置可选参数 if (speed != null) { req.setSpeed(speed); @@ -78,50 +167,47 @@ public class AppletApiTTServiceImpl implements AppletApiTTService { } else { req.setCodec("wav"); // 默认wav格式 } - + // 设置其他默认参数 req.setModelType(1L); // 默认模型 req.setPrimaryLanguage(2L); // 中文 req.setSampleRate(16000L); // 16k采样率 - + // 返回的resp是一个TextToVoiceResponse的实例,与请求对象对应 TextToVoiceResponse resp = client.TextToVoice(req); - + // 计算耗时 long endTime = System.currentTimeMillis(); double elapsedTime = (endTime - startTime) / 1000.0; - + // 获取base64编码的音频数据并解码为二进制 String audioBase64 = resp.getAudio(); - byte[] audioData = null; - + if (audioBase64 != null && !audioBase64.isEmpty()) { - audioData = java.util.Base64.getDecoder().decode(audioBase64); - // 记录成功的TTS调用日志 - savePlayLog(userId, text, voiceType, volume != null ? volume.doubleValue() : null, - speed != null ? speed.doubleValue() : null, elapsedTime, true); - + savePlayLog(userId, text, voiceType, volume != null ? volume.doubleValue() : null, + speed != null ? speed.doubleValue() : null, elapsedTime, true); + log.info("TTS调用成功,文本长度: {}, 耗时: {}秒", text != null ? text.length() : 0, elapsedTime); - return audioData; + return audioBase64; } else { // 记录失败的TTS调用日志 - savePlayLog(userId, text, voiceType, volume != null ? volume.doubleValue() : null, - speed != null ? speed.doubleValue() : null, elapsedTime, false); - + savePlayLog(userId, text, voiceType, volume != null ? volume.doubleValue() : null, + speed != null ? speed.doubleValue() : null, elapsedTime, false); + log.warn("TTS返回的音频数据为空"); return null; } - + } catch (Exception e) { // 计算耗时 long endTime = System.currentTimeMillis(); double elapsedTime = (endTime - startTime) / 1000.0; - + // 记录失败的TTS调用日志 - savePlayLog(userId, text, voiceType, volume != null ? volume.doubleValue() : null, - speed != null ? speed.doubleValue() : null, elapsedTime, false); - + savePlayLog(userId, text, voiceType, volume != null ? volume.doubleValue() : null, + speed != null ? speed.doubleValue() : null, elapsedTime, false); + log.error("调用腾讯云TTS接口失败: {}", e.getMessage(), e); return null; }