|
@@ -2,6 +2,7 @@ package com.fs.app.controller;
|
|
|
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.fs.app.annotation.Login;
|
|
@@ -11,19 +12,32 @@ import com.fs.app.vo.CompanySubUserVO;
|
|
|
import com.fs.common.annotation.RepeatSubmit;
|
|
|
import com.fs.common.constant.UserConstants;
|
|
|
import com.fs.common.core.domain.R;
|
|
|
+import com.fs.common.core.page.TableDataInfo;
|
|
|
+import com.fs.common.core.redis.RedisCache;
|
|
|
import com.fs.common.exception.ServiceException;
|
|
|
import com.fs.common.utils.PatternUtils;
|
|
|
import com.fs.common.utils.bean.BeanUtils;
|
|
|
import com.fs.company.domain.*;
|
|
|
import com.fs.company.mapper.CompanyRoleMapper;
|
|
|
+import com.fs.company.mapper.CompanyUserMapper;
|
|
|
+import com.fs.company.param.companyUserAddPrintParam;
|
|
|
import com.fs.company.service.*;
|
|
|
import com.fs.company.vo.CompanyTagUserVO;
|
|
|
import com.fs.company.vo.CompanyUserChangeApplyVO;
|
|
|
+import com.fs.config.ai.AiHostProper;
|
|
|
import com.fs.core.security.SecurityUtils;
|
|
|
import com.fs.course.service.IFsCourseRedPacketLogService;
|
|
|
import com.fs.course.service.IFsCourseWatchLogService;
|
|
|
import com.fs.course.service.IFsUserCompanyUserService;
|
|
|
+import com.fs.fastGpt.domain.FastgptChatVoiceHomo;
|
|
|
+import com.fs.fastGpt.mapper.FastgptChatVoiceHomoMapper;
|
|
|
+import com.fs.fastgptApi.util.AudioUtils;
|
|
|
+import com.fs.fastgptApi.vo.AudioVO;
|
|
|
import com.fs.qw.dto.UserProjectDTO;
|
|
|
+import com.fs.sop.domain.QwSopTempVoice;
|
|
|
+import com.fs.sop.service.IQwSopTempVoiceService;
|
|
|
+import com.fs.system.oss.CloudStorageService;
|
|
|
+import com.fs.system.oss.OSSFactory;
|
|
|
import com.fs.system.service.ISysDictDataService;
|
|
|
import com.fs.system.vo.DictVO;
|
|
|
import com.github.pagehelper.PageHelper;
|
|
@@ -34,10 +48,19 @@ import io.swagger.annotations.ApiParam;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.collections.CollectionUtils;
|
|
|
+import org.apache.http.HttpResponse;
|
|
|
+import org.apache.http.client.methods.HttpPost;
|
|
|
+import org.apache.http.entity.StringEntity;
|
|
|
+import org.apache.http.impl.client.CloseableHttpClient;
|
|
|
+import org.apache.http.impl.client.HttpClients;
|
|
|
+import org.apache.http.util.EntityUtils;
|
|
|
+import org.apache.ibatis.annotations.Param;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import javax.validation.Valid;
|
|
|
+import java.io.File;
|
|
|
+import java.io.FileInputStream;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.math.RoundingMode;
|
|
|
import java.time.LocalDate;
|
|
@@ -59,12 +82,15 @@ public class CompanyUserController extends AppBaseController {
|
|
|
private final ICompanyUserChangeApplyService companyUserChangeApplyService;
|
|
|
private final CompanyRoleMapper companyRoleMapper;
|
|
|
private final IAppService appService;
|
|
|
- @Autowired
|
|
|
- private ISysDictDataService dictDataService;
|
|
|
- @Autowired
|
|
|
- private IFsUserCompanyUserService fsUserCompanyUserService;
|
|
|
- @Autowired
|
|
|
- private ICompanyTagUserService companyTagUserService;
|
|
|
+ private final RedisCache redisCache;
|
|
|
+ private final CompanyUserMapper companyUserMapper;
|
|
|
+ private final IQwSopTempVoiceService voiceService;
|
|
|
+ private final AiHostProper aiHostProper;
|
|
|
+ private final ISysDictDataService dictDataService;
|
|
|
+ private final IFsUserCompanyUserService fsUserCompanyUserService;
|
|
|
+ private final ICompanyTagUserService companyTagUserService;
|
|
|
+ private final FastgptChatVoiceHomoMapper fastgptChatVoiceHomoMapper;
|
|
|
+ public static final String SOP_TEMP_VOICE_KEY = "sop:tempVoice";
|
|
|
|
|
|
@Login
|
|
|
@ApiOperation("查询用户列表")
|
|
@@ -394,4 +420,186 @@ public class CompanyUserController extends AppBaseController {
|
|
|
.collect(Collectors.toList());
|
|
|
return R.ok().put("data",filteredDictVOS);
|
|
|
}
|
|
|
+ /**
|
|
|
+ * 当只有模板文字text时,生成表中对应条的voice_url和user_voice_url
|
|
|
+ * @param id qw_sop_temp_voice的id
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @GetMapping("/companyUserVoice")
|
|
|
+ public R companyUserVoice(@RequestParam("id") Long id){
|
|
|
+ AudioVO audioVO = new AudioVO();
|
|
|
+ Long companyUserId = getCompanyUserId();
|
|
|
+ List<QwSopTempVoice> sopTempVoices = redisCache.getVoiceAllList(SOP_TEMP_VOICE_KEY + ":" + companyUserId);
|
|
|
+ if(sopTempVoices != null && !sopTempVoices.isEmpty()){
|
|
|
+ List<Long> collect = sopTempVoices.stream().map(QwSopTempVoice::getId).collect(Collectors.toList());
|
|
|
+ if (collect.contains(id)){
|
|
|
+ return R.ok().put("code",202).put("msg","该语音已进入转换,请完成后再试。");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if(companyUserId != null){
|
|
|
+ CompanyUser companyUser = companyUserMapper.selectCompanyUserByCompanyUserId(companyUserId);
|
|
|
+ if(companyUser != null && companyUser.getVoicePrintUrl() == null){
|
|
|
+ return R.ok().put("code",201).put("msg","账号未录制声纹,请录制后再试!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ QwSopTempVoice qwSopTempVoice = voiceService.selectQwSopTempVoiceById(id);
|
|
|
+ if(qwSopTempVoice != null && qwSopTempVoice.getCompanyUserId() != null){
|
|
|
+ List<FastgptChatVoiceHomo> homos = fastgptChatVoiceHomoMapper.selectFastgptChatVoiceHomoList(new FastgptChatVoiceHomo());
|
|
|
+ audioVO = AudioUtils.createUserUrlAndUrl(homos,qwSopTempVoice.getCompanyUserId(), qwSopTempVoice.getVoiceTxt().replace(" ",""));
|
|
|
+ if(audioVO != null && audioVO.getWavUrl() != null && audioVO.getUrl() != null){
|
|
|
+ qwSopTempVoice.setVoiceUrl(audioVO.getUrl());
|
|
|
+ qwSopTempVoice.setUserVoiceUrl(audioVO.getWavUrl());
|
|
|
+ qwSopTempVoice.setDuration(audioVO.getDuration());
|
|
|
+ qwSopTempVoice.setRecordType(1);
|
|
|
+ voiceService.updateQwSopTempVoice(qwSopTempVoice);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return R.ok().put("data", audioVO);
|
|
|
+ }
|
|
|
+ @Login
|
|
|
+ @ApiOperation("上传声纹")
|
|
|
+ @PostMapping("/addVoicePrintUrl")
|
|
|
+ public R addVoicePrintUrl(@RequestBody companyUserAddPrintParam param) throws Exception {
|
|
|
+ Long userId=getCompanyUserId();
|
|
|
+ if(userId==null){
|
|
|
+ return R.error(403,"用户失效");
|
|
|
+ }
|
|
|
+ CompanyUser companyUser = new CompanyUser();
|
|
|
+ companyUser.setUserId(userId);
|
|
|
+ companyUser.setVoicePrintUrl(param.getVoicePrintUrl());
|
|
|
+
|
|
|
+ //转换音频格式 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();
|
|
|
+ String wavUrl = storage.uploadSuffix(fileInputStream, ".wav");
|
|
|
+
|
|
|
+ //更新销售员工声纹
|
|
|
+ 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();
|
|
|
+ }
|
|
|
+
|
|
|
+ httpClient.close();
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
+ return R.error();
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 当只有user_voice_url时,生成表中对应条的voice_url
|
|
|
+ * @param userVoiceUrl wav格式的语音文件
|
|
|
+ * @param id qw_sop_temp_voice的id
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @GetMapping("/companyUserVoiceNew")
|
|
|
+ public R companyUserVoiceNew( @RequestParam("id") Long id,@RequestParam("userVoiceUrl") String userVoiceUrl){
|
|
|
+
|
|
|
+ AudioVO audioVO = new AudioVO();
|
|
|
+ Long companyUserId = getCompanyUserId();
|
|
|
+ List<QwSopTempVoice> sopTempVoices = redisCache.getVoiceAllList(SOP_TEMP_VOICE_KEY + ":" + companyUserId);
|
|
|
+ if(sopTempVoices != null && !sopTempVoices.isEmpty()){
|
|
|
+ List<Long> collect = sopTempVoices.stream().map(QwSopTempVoice::getId).collect(Collectors.toList());
|
|
|
+ if (collect.contains(id)){
|
|
|
+ return R.ok().put("code",202).put("msg","该语音已进入转换,请完成后再试。");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ QwSopTempVoice qwSopTempVoice = voiceService.selectQwSopTempVoiceByIdAndUserVoiceUrl(id);
|
|
|
+ if(qwSopTempVoice != null && qwSopTempVoice.getId() != null){
|
|
|
+ audioVO = AudioUtils.createVoiceUrl(qwSopTempVoice.getCompanyUserId(), userVoiceUrl);
|
|
|
+ if(audioVO != null && audioVO.getUrl() != null){
|
|
|
+ qwSopTempVoice.setVoiceUrl(audioVO.getUrl());
|
|
|
+ qwSopTempVoice.setUserVoiceUrl(userVoiceUrl);
|
|
|
+ qwSopTempVoice.setDuration(audioVO.getDuration());
|
|
|
+ qwSopTempVoice.setRecordType(1);
|
|
|
+ voiceService.updateQwSopTempVoice(qwSopTempVoice);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return R.ok().put("data", audioVO);
|
|
|
+ }
|
|
|
+ @GetMapping("/querySopVoiceList")
|
|
|
+ public TableDataInfo querySopVoiceList(@Param("recordType") Integer recordType){
|
|
|
+ startPage();
|
|
|
+ QwSopTempVoice sopTempVoice = new QwSopTempVoice();
|
|
|
+ sopTempVoice.setRecordType(recordType);
|
|
|
+ sopTempVoice.setCompanyUserId(getCompanyUserId());
|
|
|
+ List<QwSopTempVoice> sopTempVoices = voiceService.selectQwSopTempVoiceNewList(sopTempVoice);
|
|
|
+ return getDataTable(sopTempVoices);
|
|
|
+ }
|
|
|
+ @GetMapping("/query/{id}")
|
|
|
+ public R querySopVoiceById(@PathVariable("id") Long id){
|
|
|
+ QwSopTempVoice tempVoice = voiceService.selectQwSopTempVoiceById(id);
|
|
|
+ AudioVO audioVO = new AudioVO();
|
|
|
+ if(tempVoice != null){
|
|
|
+ audioVO.setId(tempVoice.getId());
|
|
|
+ audioVO.setVoiceTxt(tempVoice.getVoiceTxt());
|
|
|
+ audioVO.setUrl(tempVoice.getVoiceUrl());
|
|
|
+ audioVO.setWavUrl(tempVoice.getUserVoiceUrl());
|
|
|
+ audioVO.setDuration(tempVoice.getDuration());
|
|
|
+ audioVO.setRecordType(tempVoice.getRecordType());
|
|
|
+ }
|
|
|
+ return R.ok().put("data", audioVO);
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 一键转换
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @GetMapping("/createUserAllVoice")
|
|
|
+ public R createUserAllVoice(){
|
|
|
+ QwSopTempVoice sopTempVoice = new QwSopTempVoice();
|
|
|
+ sopTempVoice.setRecordType(0);
|
|
|
+ Long companyUserId = getCompanyUserId();
|
|
|
+
|
|
|
+
|
|
|
+ if(companyUserId != null){
|
|
|
+ CompanyUser companyUser = companyUserMapper.selectCompanyUserByCompanyUserId(companyUserId);
|
|
|
+ if(companyUser != null && companyUser.getVoicePrintUrl() == null){
|
|
|
+ return R.ok().put("code",201).put("msg","账号未录制声纹,请录制后再试!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ sopTempVoice.setCompanyUserId(companyUserId);
|
|
|
+ List<QwSopTempVoice> sopTempVoices = voiceService.selectQwSopTempVoiceNewList(sopTempVoice);
|
|
|
+ if(sopTempVoices != null && !sopTempVoices.isEmpty()){
|
|
|
+ List<Long> newCompanyUserId = redisCache.getVoiceAllList(SOP_TEMP_VOICE_KEY);
|
|
|
+ if(newCompanyUserId != null && newCompanyUserId.contains(companyUserId)){
|
|
|
+ return R.error().put("code",202).put("msg","语音还未转换完成,请完成后再添加!");
|
|
|
+ }else{
|
|
|
+ redisCache.setVoice(SOP_TEMP_VOICE_KEY,companyUserId);
|
|
|
+ sopTempVoices.forEach(m -> m.setVoiceTxt(m.getVoiceTxt().replace(" ","")));
|
|
|
+ redisCache.setVoiceList(SOP_TEMP_VOICE_KEY + ":" + companyUserId, sopTempVoices);
|
|
|
+ return R.ok().put("msg","语音已加入队列进行转换,请耐心等待!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
}
|