Ver código fonte

1.提交益寿源的语音模块和功能

jzp 2 semanas atrás
pai
commit
637929f4fd

+ 86 - 4
fs-company/src/main/java/com/fs/company/controller/qw/QwSopController.java

@@ -1,5 +1,6 @@
 package com.fs.company.controller.qw;
 
+import com.alibaba.fastjson.JSONObject;
 import com.fs.common.annotation.Log;
 import com.fs.common.annotation.RepeatSubmit;
 import com.fs.common.core.controller.BaseController;
@@ -17,21 +18,29 @@ import com.fs.framework.service.TokenService;
 import com.fs.his.vo.OptionsVO;
 import com.fs.qw.domain.QwSopUpdateStatus;
 import com.fs.qw.service.IQwUserService;
+import com.fs.qw.vo.QwUserVO;
 import com.fs.sop.domain.QwSop;
+import com.fs.sop.domain.QwSopTempContent;
+import com.fs.sop.domain.QwSopTempVoice;
 import com.fs.sop.params.QwSopAutoTime;
 import com.fs.sop.params.QwSopEditQwUserParam;
 import com.fs.sop.service.ICompanySopRoleService;
 import com.fs.sop.service.IQwSopService;
+import com.fs.sop.service.IQwSopTempContentService;
+import com.fs.sop.service.IQwSopTempVoiceService;
 import com.fs.sop.vo.SopVoiceListVo;
+import org.apache.commons.beanutils.ConvertUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.web.bind.annotation.*;
 
 import java.io.IOException;
 import java.text.SimpleDateFormat;
+import java.time.LocalDateTime;
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
+import java.util.stream.Collectors;
 
 /**
  * 企微sopController
@@ -64,6 +73,13 @@ public class QwSopController extends BaseController
     @Autowired
     private IQwUserService iQwUserService;
 
+    @Autowired
+    private IQwSopTempContentService qwSopTempContentService;
+
+    @Autowired
+    private IQwSopTempVoiceService voiceService;
+
+
     /**
      * 查询企微sop列表
      */
@@ -228,8 +244,13 @@ public class QwSopController extends BaseController
         qwSop.setCompanyId(companyId);
         qwSop.setCreateBy(loginUser.getUser().getNickName());
         qwSop.setCreateTime(sdf.format(new Date()));
-
-        return toAjax(qwSopService.insertQwSop(qwSop));
+        int count = qwSopService.insertQwSop(qwSop);
+        if(count > 0){
+            if(qwSop.getQwUserIds() != null){
+                updateTempVoiceInfo(qwSop);
+            }
+        }
+        return toAjax(count);
 
     }
 
@@ -241,7 +262,60 @@ public class QwSopController extends BaseController
     @PutMapping
     public R edit(@RequestBody QwSop qwSop)
     {
-        return qwSopService.updateQwSop(qwSop);
+        R sop = qwSopService.updateQwSop(qwSop);
+        String code = sop.get("code").toString();
+        if(code.equals("200")){
+            if(qwSop != null && qwSop.getQwUserIds() != null){
+                updateTempVoiceInfo(qwSop);
+            }
+        }
+        return sop;
+    }
+
+    /**
+     * 修改qwSop任务,新增或者删除qwUser
+     * @param qwSop
+     */
+    private void updateTempVoiceInfo(QwSop qwSop) {
+        try {
+            String tempId = qwSop.getTempId();
+            String[] split = qwSop.getQwUserIds().split(",");
+            Long[] qwUserIds = (Long[]) ConvertUtils.convert(split, Long.class);
+
+            List<QwSopTempContent> qwSopTempContentList = qwSopTempContentService.selectQwSopTempContentByTempId(tempId);
+            if(qwSopTempContentList != null && !qwSopTempContentList.isEmpty()){
+                for (QwSopTempContent qwSopTemp : qwSopTempContentList) {
+                    if(qwSopTemp != null && qwSopTemp.getContent() != null){
+                        String content = qwSopTemp.getContent();
+                        JSONObject jsonObject = JSONObject.parseObject(content);
+                        String voiceTxt = jsonObject.getString("value");
+                        String contentType = jsonObject.getString("contentType");
+                        if("7".equals(contentType)){
+                            List<QwUserVO> qwUserVoS = qwUserService.selectQwUserVOByIds(qwUserIds);
+                            if(qwUserVoS != null && !qwUserVoS.isEmpty()){
+                                List<Long> companyUserIdList = qwUserVoS.stream().map(QwUserVO::getCompanyUserId).collect(Collectors.toList());
+                                for (Long companyUserId : companyUserIdList) {
+                                    QwSopTempVoice qwSopTempVoice = voiceService.selectQwSopTempVoiceByCompanyUserIdAndVoiceTxt(companyUserId,voiceTxt);
+                                    if(qwSopTempVoice == null){
+                                        if(companyUserId != null && voiceTxt != null){
+                                            QwSopTempVoice tempVoice = new QwSopTempVoice();
+                                            tempVoice.setVoiceTxt(voiceTxt);
+                                            tempVoice.setCompanyUserId(companyUserId);
+                                            tempVoice.setRecordType(0);
+                                            tempVoice.setCreateTime(LocalDateTime.now());
+                                            tempVoice.setTempId(tempId);
+                                            voiceService.insertQwSopTempVoice(tempVoice);
+                                        }
+                                    }
+                                }
+                            }
+                        }
+                    }
+                }
+            }
+        } catch (Exception e) {
+            logger.error("修改企微sop任务,新增或者删除qwUser异常:" + e.getMessage());
+        }
     }
 
 
@@ -307,7 +381,15 @@ public class QwSopController extends BaseController
     @PreAuthorize("@ss.hasPermi('qw:sop:updateSopQwUser')")
     public R updateSopQwUser(@RequestBody QwSopEditQwUserParam param)
     {
-        return qwSopService.updateSopQwUser(param);
+        R sop = qwSopService.updateSopQwUser(param);
+        String code = sop.get("code").toString();
+        if(code.equals("200")){
+            QwSop qwSop = qwSopService.selectQwSopById(param.getId());
+            if(qwSop != null && qwSop.getQwUserIds() != null){
+                updateTempVoiceInfo(qwSop);
+            }
+        }
+        return sop;
     }
 
     /**

+ 3 - 0
fs-service/src/main/java/com/fs/config/ai/AiHostProper.java

@@ -16,4 +16,7 @@ public class AiHostProper {
     @Value("${ipad.voiceApi}")
     private String voiceApi;
 
+    @Value("${ipad.commonApi}")
+    private String commonApi;
+
 }

+ 10 - 2
fs-service/src/main/java/com/fs/fastgptApi/util/AudioUtils.java

@@ -5,6 +5,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
 import com.fs.common.exception.ServiceException;
 import com.fs.common.exception.base.BaseException;
 import com.fs.config.ai.AiHostProper;
+import com.fs.config.cloud.CloudHostProper;
 import com.fs.fastGpt.domain.FastgptChatVoiceHomo;
 import com.fs.fastGpt.service.IFastGptChatMsgService;
 import com.fs.fastgptApi.vo.AudioVO;
@@ -38,11 +39,18 @@ public class AudioUtils {
 
     private static AiHostProper staticAiHostProper;
 
+    private static CloudHostProper cloudHostProper;
+
     @Autowired
     public void setAiHostProper(AiHostProper service) {
         AudioUtils.staticAiHostProper = service;
     }
 
+    @Autowired
+    public void setCloudHostProper(CloudHostProper service) {
+        AudioUtils.cloudHostProper = service;
+    }
+
     /**
      * 工具地址
      **/
@@ -789,7 +797,7 @@ public class AudioUtils {
                 .replaceAll("[a-zA-Z]", "")
                 .replaceAll("\\s", "");
         try {
-            String fileUrl = "http://127.0.0.1:9880/?text="+text+"&ref_audio=./参考音频/companyUser"+userId+".wav&ref_text=在这片神奇的森林里,小鸟轻快地唱着歌,仿佛在诉说着春天的故事。"; // 替换为要下载的文件URL
+            String fileUrl = "http://127.0.0.1:9880/?text="+text+"&ref_audio=./参考音频/companyUser" + cloudHostProper.getProjectCode() + userId+".wav&ref_text=在这片神奇的森林里,小鸟轻快地唱着歌,仿佛在诉说着春天的故事。"; // 替换为要下载的文件URL
             try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
                 HttpGet httpGet = new HttpGet(fileUrl);
                 HttpResponse response = httpClient.execute(httpGet);
@@ -836,7 +844,7 @@ public class AudioUtils {
                 .replaceAll("[a-zA-Z]", "")
                 .replaceAll("\\s", "");
         try {
-            String fileUrl = "http://127.0.0.1:9880/?text="+text+"&ref_audio=./参考音频/companyUser"+userId+".wav&ref_text=在这片神奇的森林里,小鸟轻快地唱着歌,仿佛在诉说着春天的故事。"; // 替换为要下载的文件URL
+            String fileUrl = "http://127.0.0.1:9880/?text="+text+"&ref_audio=./参考音频/companyUser"+ cloudHostProper.getProjectCode() +userId+".wav&ref_text=在这片神奇的森林里,小鸟轻快地唱着歌,仿佛在诉说着春天的故事。"; // 替换为要下载的文件URL
             try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
                 HttpGet httpGet = new HttpGet(fileUrl);
                 HttpResponse response = httpClient.execute(httpGet);

+ 4 - 1
fs-service/src/main/java/com/fs/qw/service/impl/QwUserVoiceLogServiceImpl.java

@@ -217,7 +217,10 @@ public class QwUserVoiceLogServiceImpl extends ServiceImpl<QwUserVoiceLogMapper,
                 if (recordType == 2) {//2是未接通的处理
                     qwUserVoiceLog.setStatus(recordType);
                     qwUserVoiceLog.setTitle("通话拒接");
-                } else {
+                } else if(recordType == 3){
+                    qwUserVoiceLog.setStatus(recordType);
+                    qwUserVoiceLog.setTitle("通话未接听");
+                }else {
                     qwUserVoiceLog.setStatus(1);
                     if (totalSeconds != null) {
                         qwUserVoiceLog.setDuration(totalSeconds);

+ 4 - 1
fs-user-app/src/main/java/com/fs/app/controller/CompanyUserController.java

@@ -27,6 +27,7 @@ import com.fs.company.param.companyUserAddPrintParam;
 import com.fs.company.service.ICompanyUserCardService;
 import com.fs.company.service.ICompanyUserService;
 import com.fs.company.service.ICompanyUserUserService;
+import com.fs.config.ai.AiHostProper;
 import com.fs.fastGpt.domain.FastgptChatVoiceHomo;
 import com.fs.fastGpt.mapper.FastgptChatVoiceHomoMapper;
 import com.fs.fastgptApi.util.AudioUtils;
@@ -83,6 +84,8 @@ public class CompanyUserController extends  AppBaseController {
     private IQwSopTempVoiceService voiceService;
     @Autowired
     private FastgptChatVoiceHomoMapper fastgptChatVoiceHomoMapper;
+    @Autowired
+    private AiHostProper aiHostProper;
 
     public static final String SOP_TEMP_VOICE_KEY = "sop:tempVoice";
     @PostMapping("/login")
@@ -168,7 +171,7 @@ public class CompanyUserController extends  AppBaseController {
         companyUserMapper.updateCompanyUser(companyUser);
         try {
             CloseableHttpClient httpClient = HttpClients.createDefault();
-            HttpPost httpPost = new HttpPost("http://127.0.0.1:7771/app/common/addCompanyAudio");
+            HttpPost httpPost = new HttpPost(aiHostProper.getCommonApi()+ "/app/common/addCompanyAudio");
             String json = "{\"url\":\""+wavUrl+"\",\"id\":\""+userId+"\"}";
             StringEntity entity = new StringEntity(json);
             httpPost.setEntity(entity);