|
|
@@ -196,56 +196,58 @@ public class CompanyUserController extends AppBaseController {
|
|
|
CompanyUser companyUser = new CompanyUser();
|
|
|
companyUser.setUserId(userId);
|
|
|
companyUser.setVoicePrintUrl(param.getVoicePrintUrl());
|
|
|
- String wavUrl = null;
|
|
|
+
|
|
|
//转换音频格式 mp3-wav
|
|
|
String s = AudioUtils.audioWAVFromUrl(param.getVoicePrintUrl());
|
|
|
-
|
|
|
//保存文件并且上传存储桶
|
|
|
System.out.println(s);
|
|
|
File file = new File(s);
|
|
|
FileInputStream fileInputStream = new FileInputStream(file);
|
|
|
CloudStorageService storage = OSSFactory.build();
|
|
|
- wavUrl = storage.uploadSuffix(fileInputStream, ".wav");
|
|
|
+ String wavUrl = storage.uploadSuffix(fileInputStream, ".wav");
|
|
|
+ //更新销售员工声纹
|
|
|
+ companyUser.setVoicePrintUrl(wavUrl);
|
|
|
+ companyUserMapper.updateCompanyUser(companyUser);
|
|
|
/*判断sys的声纹复刻的配置value是不是2*/
|
|
|
JSONObject vcConfig = configUtil.generateConfigByKey(SysConfigEnum.VS_CONFIG.getKey());
|
|
|
if (vcConfig != null && !vcConfig.isEmpty() &&
|
|
|
// !vcConfig.equals(new JSONObject()) &&
|
|
|
"2".equals(vcConfig.getString("type"))) {
|
|
|
- uploadVoice(userId, wavUrl);
|
|
|
- }
|
|
|
- //更新销售员工声纹
|
|
|
- companyUser.setVoicePrintUrl(wavUrl);
|
|
|
- companyUserMapper.updateCompanyUser(companyUser);
|
|
|
-
|
|
|
-
|
|
|
- try {
|
|
|
- CloseableHttpClient httpClient = HttpClients.createDefault();
|
|
|
- HttpPost httpPost = new HttpPost(aiHostProper.getCommonApi() + "/app/common/addCompanyAudio");
|
|
|
- String json = "{\"url\":\"" + wavUrl + "\",\"id\":\"" + userId + "\"}";
|
|
|
- StringEntity entity = new StringEntity(json);
|
|
|
- httpPost.setEntity(entity);
|
|
|
- httpPost.setHeader("Content-type", "application/json");
|
|
|
- HttpResponse response = httpClient.execute(httpPost);
|
|
|
-
|
|
|
- if (response.getStatusLine().getStatusCode() == 200) {
|
|
|
- String responseBody = EntityUtils.toString(response.getEntity());
|
|
|
- JSONObject jsonObject = JSON.parseObject(responseBody);
|
|
|
- Integer code = (Integer) jsonObject.get("code");
|
|
|
- if (code == 200) {
|
|
|
- voiceService.insertQwSopTempVoiceModel(userId);
|
|
|
- return R.ok();
|
|
|
- }
|
|
|
- } else {
|
|
|
- return R.error();
|
|
|
+ /*走豆包直接不走原逻辑*/
|
|
|
+ AjaxResult ajaxResult = uploadVoice(userId, wavUrl);
|
|
|
+ if (!ajaxResult.get("code").equals(200)){
|
|
|
+ return R.error((String) ajaxResult.get("msg"));
|
|
|
}
|
|
|
+ voiceService.insertQwSopTempVoiceModel(userId);
|
|
|
+ return R.ok();
|
|
|
+ }else {
|
|
|
+ try {
|
|
|
+ CloseableHttpClient httpClient = HttpClients.createDefault();
|
|
|
+ HttpPost httpPost = new HttpPost(aiHostProper.getCommonApi() + "/app/common/addCompanyAudio");
|
|
|
+ String json = "{\"url\":\"" + wavUrl + "\",\"id\":\"" + userId + "\"}";
|
|
|
+ StringEntity entity = new StringEntity(json);
|
|
|
+ httpPost.setEntity(entity);
|
|
|
+ httpPost.setHeader("Content-type", "application/json");
|
|
|
+ HttpResponse response = httpClient.execute(httpPost);
|
|
|
+
|
|
|
+ if (response.getStatusLine().getStatusCode() == 200) {
|
|
|
+ String responseBody = EntityUtils.toString(response.getEntity());
|
|
|
+ JSONObject jsonObject = JSON.parseObject(responseBody);
|
|
|
+ Integer code = (Integer) jsonObject.get("code");
|
|
|
+ if (code == 200) {
|
|
|
+ voiceService.insertQwSopTempVoiceModel(userId);
|
|
|
+ return R.ok();
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ return R.error();
|
|
|
+ }
|
|
|
|
|
|
- httpClient.close();
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
+ httpClient.close();
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return R.error();
|
|
|
}
|
|
|
-
|
|
|
- return R.error();
|
|
|
-
|
|
|
}
|
|
|
|
|
|
@ApiOperation("小程序销售绑定医生")
|
|
|
@@ -543,16 +545,16 @@ public class CompanyUserController extends AppBaseController {
|
|
|
* @throws Exception
|
|
|
*/
|
|
|
@PostMapping("/uploadVoice")
|
|
|
- public R uploadVoice(
|
|
|
+ public AjaxResult uploadVoice(
|
|
|
Long userId,
|
|
|
String voicePrintUrl) throws Exception {
|
|
|
if (userId == null) userId = 123L;
|
|
|
VcCompanyUser vcCompanyUser = companyUserMapper.selectVcCompanyUserByCompanyUserId(userId);
|
|
|
if (vcCompanyUser == null) {
|
|
|
- return R.error("用户没有声纹槽位,请联系管理员");
|
|
|
+ return AjaxResult.error("用户没有声纹槽位,请联系管理员");
|
|
|
}
|
|
|
if (vcCompanyUser.getTimes() != null && vcCompanyUser.getTimes() >= 5)
|
|
|
- return R.error("用户已上传声纹达到上限");
|
|
|
+ return AjaxResult.error("用户已上传声纹达到上限");
|
|
|
vcCompanyUser.setUploadUrl(voicePrintUrl);
|
|
|
File file = downloadFileFromUrl(voicePrintUrl);
|
|
|
/*获取文件时长*/
|
|
|
@@ -567,7 +569,7 @@ public class CompanyUserController extends AppBaseController {
|
|
|
vcCompanyUser.incrementTimes();
|
|
|
vcCompanyUser.setUploadTime(duration);
|
|
|
companyUserMapper.updateVcCompanyUser(vcCompanyUser);
|
|
|
- return R.ok();
|
|
|
+ return AjaxResult.success();
|
|
|
}
|
|
|
// private static MultipartFile downloadAsMultipartFile(String fileUrl) throws Exception {
|
|
|
// URL url = new URL(fileUrl);
|