|
|
|
package com.supervision.controller;
|
|
|
|
|
|
|
|
import cn.hutool.core.collection.ListUtil;
|
|
|
|
import cn.hutool.core.lang.hash.Hash;
|
|
|
|
import cn.hutool.crypto.digest.MD5;
|
|
|
|
import cn.hutool.extra.pinyin.PinyinUtil;
|
|
|
|
import cn.hutool.http.HttpUtil;
|
|
|
|
import cn.hutool.json.JSONObject;
|
|
|
|
import cn.hutool.json.JSONUtil;
|
|
|
|
import cn.hutool.poi.excel.ExcelReader;
|
|
|
|
import cn.hutool.poi.excel.ExcelUtil;
|
|
|
|
import com.supervision.exception.BusinessException;
|
|
|
|
import com.supervision.model.AskDiseaseQuestionAnswer;
|
|
|
|
import com.supervision.model.AskTemplateQuestion;
|
|
|
|
import com.supervision.model.ConfigPhysicalTool;
|
|
|
|
import com.supervision.service.AskDiseaseQuestionAnswerService;
|
|
|
|
import com.supervision.service.AskTemplateQuestionService;
|
|
|
|
import com.supervision.service.ConfigPhysicalToolService;
|
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
|
|
import java.util.*;
|
|
|
|
|
|
|
|
@RestController
|
|
|
|
@RequestMapping("test")
|
|
|
|
@RequiredArgsConstructor
|
|
|
|
public class TestController {
|
|
|
|
|
|
|
|
private final ConfigPhysicalToolService configPhysicalToolService;
|
|
|
|
|
|
|
|
@GetMapping("testExpireTime")
|
|
|
|
public String testExpireTime() {
|
|
|
|
return "OK";
|
|
|
|
}
|
|
|
|
|
|
|
|
@GetMapping("testQueryJSON")
|
|
|
|
public List<ConfigPhysicalTool> testQueryJSON() {
|
|
|
|
return configPhysicalToolService.list();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 数字人获取房间号
|
|
|
|
* @param key 数字人ID,张总那边提供
|
|
|
|
* @param token 前端每打开一个页面,就给一个新的UUID
|
|
|
|
* @return 房间号
|
|
|
|
*/
|
|
|
|
@GetMapping("queryRoomId")
|
|
|
|
public String queryRoomId(String key,String token){
|
|
|
|
Map<String, Object> param = new HashMap<>();
|
|
|
|
param.put("token",token);
|
|
|
|
param.put("key",key);
|
|
|
|
String s = HttpUtil.get("https://digital-human.jd.com/getRoomId", param);
|
|
|
|
JSONObject entries = JSONUtil.parseObj(s);
|
|
|
|
if (200 != entries.getInt("code")){
|
|
|
|
throw new BusinessException(entries.getStr("data"));
|
|
|
|
}
|
|
|
|
return entries.getStr("data");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 调用数字人接口进行语音的播放
|
|
|
|
* @param text 需要播放的文本
|
|
|
|
* @param roomId 房间ID
|
|
|
|
*/
|
|
|
|
@GetMapping("shuZiRenSend")
|
|
|
|
public void shuZiRenSend(String text, String roomId) {
|
|
|
|
HashMap<String, Object> param = new HashMap<>();
|
|
|
|
long timeStamp = System.currentTimeMillis();
|
|
|
|
|
|
|
|
param.put("text", text);
|
|
|
|
param.put("roomId", roomId);
|
|
|
|
param.put("action", "-1");
|
|
|
|
param.put("nonce", UUID.randomUUID().toString());
|
|
|
|
param.put("timeStamp", String.valueOf(timeStamp));
|
|
|
|
param.put("sign", getSign(String.valueOf(timeStamp),
|
|
|
|
(String) param.get("nonce"),
|
|
|
|
(String) param.get("text"),
|
|
|
|
(String) param.get("actionId"),
|
|
|
|
(String) param.get("roomId")));
|
|
|
|
String s = HttpUtil.get("https://digital-human.jd.com/text_driven", param);
|
|
|
|
System.out.println(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
private static String getSign(String timeStamp, String nonce, String text, String actionId, String roomId) {
|
|
|
|
Map<String, Object> paramMap = new TreeMap<>();
|
|
|
|
paramMap.put("action", actionId);
|
|
|
|
paramMap.put("nonce", nonce);
|
|
|
|
paramMap.put("roomId", roomId);
|
|
|
|
paramMap.put("text", text);
|
|
|
|
paramMap.put("timeStamp", timeStamp);
|
|
|
|
String paramJsonString = JSONUtil.toJsonStr(paramMap);
|
|
|
|
System.out.println(paramJsonString);
|
|
|
|
String signServer = new MD5().digestHex16(paramJsonString);
|
|
|
|
System.out.println("---------> :" + signServer);
|
|
|
|
return signServer;
|
|
|
|
}
|
|
|
|
|
|
|
|
@PostMapping("saveQuestion")
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
public void saveQuestion() {
|
|
|
|
ExcelReader reader = ExcelUtil.getReader("/Users/flevance/Desktop/template.xlsx");
|
|
|
|
List<List<Object>> read = reader.read();
|
|
|
|
for (List<Object> readLine : read) {
|
|
|
|
String desc = (String) readLine.get(0);
|
|
|
|
String pinyin = PinyinUtil.getPinyin((String) readLine.get(0), "_");
|
|
|
|
String question = (String) readLine.get(1);
|
|
|
|
String answer = (String) readLine.get(2);
|
|
|
|
String otherQuestionStr = (String) readLine.get(3);
|
|
|
|
|
|
|
|
AskTemplateQuestion templateQuestion = new AskTemplateQuestion();
|
|
|
|
templateQuestion.setCode("ask_" + pinyin);
|
|
|
|
templateQuestion.setDescription(desc);
|
|
|
|
List<String> questionList = JSONUtil.toList(otherQuestionStr, String.class);
|
|
|
|
questionList.add(0, question);
|
|
|
|
templateQuestion.setQuestion(questionList);
|
|
|
|
templateQuestion.insert();
|
|
|
|
|
|
|
|
|
|
|
|
AskDiseaseQuestionAnswer askDiseaseQuestionAnswer = new AskDiseaseQuestionAnswer();
|
|
|
|
askDiseaseQuestionAnswer.setDiseaseId("1");
|
|
|
|
askDiseaseQuestionAnswer.setTemplateQuestionId(templateQuestion.getId());
|
|
|
|
askDiseaseQuestionAnswer.setAnswer(ListUtil.of(answer));
|
|
|
|
askDiseaseQuestionAnswer.insert();
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|