ChatController.java 54 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113
  1. package com.rf.kjb.chat.rest;
  2. import com.alibaba.fastjson.JSONObject;
  3. import com.auth0.jwt.interfaces.DecodedJWT;
  4. import com.rf.kjb.base.rest.BaseController;
  5. import com.rf.kjb.chat.dao.domain.*;
  6. import com.rf.kjb.chat.service.*;
  7. import com.rf.kjb.excel.ExcelUtil;
  8. import com.rf.kjb.exception.ErrorCode;
  9. import com.rf.kjb.intelligentDialogue.dao.domain.IntelligentDialogueEntity;
  10. import com.rf.kjb.intelligentDialogue.service.IntelligentDialogueService;
  11. import com.rf.kjb.opLog.dao.model.SysLogEntity;
  12. import com.rf.kjb.scale.util.DateUtil;
  13. import com.rf.kjb.user.dao.model.UserEntry;
  14. import com.rf.kjb.user.service.UserService;
  15. import com.rf.kjb.utils.FileUtils;
  16. import com.rf.kjb.utils.JWTUtil;
  17. import com.rf.kjb.utils.Result;
  18. import com.rf.kjb.utils.ZipUtils;
  19. import io.swagger.annotations.Api;
  20. import io.swagger.annotations.ApiOperation;
  21. import lombok.SneakyThrows;
  22. import lombok.extern.slf4j.Slf4j;
  23. import org.apache.commons.io.IOUtils;
  24. import org.apache.commons.lang3.StringUtils;
  25. import org.apache.poi.xssf.usermodel.XSSFCell;
  26. import org.apache.poi.xssf.usermodel.XSSFRow;
  27. import org.apache.poi.xssf.usermodel.XSSFSheet;
  28. import org.apache.poi.xssf.usermodel.XSSFWorkbook;
  29. import org.springframework.beans.factory.annotation.Autowired;
  30. import org.springframework.data.domain.Page;
  31. import org.springframework.web.bind.annotation.*;
  32. import org.springframework.web.multipart.MultipartFile;
  33. import javax.servlet.http.HttpServletRequest;
  34. import javax.servlet.http.HttpServletResponse;
  35. import java.io.*;
  36. import java.net.URLEncoder;
  37. import java.nio.file.Files;
  38. import java.nio.file.Path;
  39. import java.nio.file.Paths;
  40. import java.util.*;
  41. import java.util.stream.Stream;
  42. @Slf4j
  43. @RestController
  44. @RequestMapping("/chat")
  45. @Api(tags = "对话")
  46. public class ChatController extends BaseController {
  47. @Autowired
  48. private ChatQuestionService questionService;
  49. @Autowired
  50. private ChatAnswerService answerService;
  51. @Autowired
  52. private ResultQuestionService resultQuestionService;
  53. @Autowired
  54. private ChatRecordService chatRecordService;
  55. @Autowired
  56. private UserService userService;
  57. @Autowired
  58. private IntelligentDialogueService intelligentDialogueService;
  59. @Autowired
  60. private QuestionSkipService questionSkipService;
  61. /**
  62. * 查询会话问题
  63. */
  64. @GetMapping("/getQuestion/{label}")
  65. @ApiOperation("查询问题信息:首次查询时,id传空字符串即可查询出第一道题目;questionType=0表示选择题,questionType=1表示填空题;当改问题的nextQuestionNo 不为空是,则表示改题为陈述,没有答案,直接在显示此问题之后再次请求该接口显示questionNo对应的题目信息即可")
  66. public Result getQuestion(String id, String num, @PathVariable String label, HttpServletRequest request) {
  67. if (StringUtils.isBlank(id)) {
  68. id = "1";
  69. }
  70. ChatQuestionEntity questionEntity = this.questionService.findByIdAndLabelAndNum(id, label, num);
  71. String token = request.getHeader("Authorization");
  72. token = token.split(" ")[1];//以空格划分Bearer token,获取token
  73. //从请求头中获取token
  74. DecodedJWT verify = JWTUtil.verify(token);
  75. String identifier = verify.getClaim("identifier").asString();
  76. UserEntry userEntry = this.userService.findByIdentifier(identifier);
  77. if (questionEntity.getLabel().equals("5") && questionEntity.getId().equals("3")){
  78. questionEntity.setQuestion(userEntry.getUserName()+questionEntity.getQuestion());
  79. }
  80. //情绪打分跳转
  81. List<QuestionSkipEntity> questionSkipEntities = this.questionSkipService.findByLabelAndNumAndType(label,num,"5");
  82. for (QuestionSkipEntity questionSkipEntity : questionSkipEntities) {
  83. if (id.equals(questionSkipEntity.getQuestionNo())){
  84. int a = emotionScore(identifier,label,num,questionSkipEntity.getSkipQuestionNo());
  85. switch (a) {
  86. case 1:
  87. questionEntity = this.questionService.findByIdAndLabelAndNum(id, label, num);
  88. break;
  89. case 2:
  90. questionEntity = this.questionService.findByIdAndLabelAndNum(String.valueOf(Integer.valueOf(id)+2), label, num);
  91. break;
  92. case 3:
  93. questionEntity = this.questionService.findByIdAndLabelAndNum(String.valueOf(Integer.valueOf(id)+4), label, num);
  94. break;
  95. case 4:
  96. questionEntity = this.questionService.findByIdAndLabelAndNum(String.valueOf(Integer.valueOf(id)+6), label, num);
  97. break;
  98. default:
  99. break;
  100. }
  101. }
  102. }
  103. //情绪二次打分跳转
  104. if (id.equals("4")){
  105. if (num.equals("2") || num.equals("3") || num.equals("4") || num.equals("5")){
  106. String lastNum = String.valueOf(Integer.valueOf(num) - 1);
  107. IntelligentDialogueEntity intelligentDialogue = this.intelligentDialogueService.findLastScoreByIdentifierByLabelByNumByQuestionNo(identifier,label,lastNum,"5");
  108. int lastScore = 0;
  109. if (intelligentDialogue != null){
  110. lastScore = Integer.valueOf(intelligentDialogue.getContent());
  111. }
  112. IntelligentDialogueEntity intelligentDialogueEntity = this.intelligentDialogueService.findScoreByIdentifierByLabelByNumByQuestionNo(identifier,label,num);
  113. int score = Integer.valueOf(intelligentDialogueEntity.getContent()) - lastScore;
  114. if (score <= -80){
  115. questionEntity = this.questionService.findByIdAndLabelAndNum("13", label, num);
  116. }else if (score <= -60 && score > -80){
  117. questionEntity = this.questionService.findByIdAndLabelAndNum("11", label, num);
  118. }else if (score <= -40 && score > -60){
  119. questionEntity = this.questionService.findByIdAndLabelAndNum("9", label, num);
  120. }else if (score <= -20 && score > -40){
  121. questionEntity = this.questionService.findByIdAndLabelAndNum("7", label, num);
  122. }else if (score <= -1 && score > -20){
  123. questionEntity = this.questionService.findByIdAndLabelAndNum("5", label, num);
  124. }else if (score <= 20 && score > -1){
  125. questionEntity = this.questionService.findByIdAndLabelAndNum("4", label, num);
  126. }else if (score <= 40 && score > 20){
  127. questionEntity = this.questionService.findByIdAndLabelAndNum("6", label, num);
  128. }else if (score <= 60 && score > 40){
  129. questionEntity = this.questionService.findByIdAndLabelAndNum("8", label, num);
  130. }else if (score <= 80 && score > 60){
  131. questionEntity = this.questionService.findByIdAndLabelAndNum("10", label, num);
  132. }else {
  133. questionEntity = this.questionService.findByIdAndLabelAndNum("12", label, num);
  134. }
  135. }
  136. }
  137. /*if (label.equals("2")){
  138. if (num.equals("1")){
  139. if (id.equals("41")){
  140. questionEntity = emotionScoreSkip(identifier,label,num,"40");
  141. }
  142. if (id.equals("83")){
  143. questionEntity = emotionScoreSkip(identifier,label,num,"82");
  144. }
  145. if (id.equals("121")){
  146. questionEntity = emotionScoreSkip(identifier,label,num,"120");
  147. }
  148. if (id.equals("169")){
  149. questionEntity = emotionScoreSkip(identifier,label,num,"168");
  150. }
  151. if (id.equals("210")){
  152. questionEntity = emotionScoreSkip(identifier,label,num,"209");
  153. }
  154. if (id.equals("249")){
  155. questionEntity = emotionScoreSkip(identifier,label,num,"246");
  156. }
  157. if (id.equals("288")){
  158. questionEntity = emotionScoreSkip(identifier,label,num,"285");
  159. }
  160. if (id.equals("336")){
  161. questionEntity = emotionScoreSkip(identifier,label,num,"333");
  162. }
  163. if (id.equals("377")){
  164. questionEntity = emotionScoreSkip(identifier,label,num,"374");
  165. }
  166. if (id.equals("414")){
  167. questionEntity = emotionScoreSkip(identifier,label,num,"411");
  168. }
  169. }
  170. if (num.equals("2") || num.equals("3") || num.equals("4") || num.equals("5")){
  171. if (id.equals("57")){
  172. questionEntity = emotionScoreSkip(identifier,label,num,"56");
  173. }
  174. if (id.equals("99")){
  175. questionEntity = emotionScoreSkip(identifier,label,num,"98");
  176. }
  177. if (id.equals("137")){
  178. questionEntity = emotionScoreSkip(identifier,label,num,"136");
  179. }
  180. if (id.equals("185")){
  181. questionEntity = emotionScoreSkip(identifier,label,num,"184");
  182. }
  183. if (id.equals("226")){
  184. questionEntity = emotionScoreSkip(identifier,label,num,"225");
  185. }
  186. if (id.equals("265")){
  187. questionEntity = emotionScoreSkip(identifier,label,num,"262");
  188. }
  189. if (id.equals("304")){
  190. questionEntity = emotionScoreSkip(identifier,label,num,"301");
  191. }
  192. if (id.equals("352")){
  193. questionEntity = emotionScoreSkip(identifier,label,num,"349");
  194. }
  195. if (id.equals("393")){
  196. questionEntity = emotionScoreSkip(identifier,label,num,"390");
  197. }
  198. if (id.equals("430")){
  199. questionEntity = emotionScoreSkip(identifier,label,num,"427");
  200. }
  201. //情绪二次打分跳转
  202. if (id.equals("4")){
  203. String lastNum = String.valueOf(Integer.valueOf(num) - 1);
  204. IntelligentDialogueEntity intelligentDialogue = this.intelligentDialogueService.findLastScoreByIdentifierByLabelByNumByQuestionNo(identifier,label,lastNum,"4");
  205. int lastScore = 0;
  206. if (intelligentDialogue != null){
  207. lastScore = Integer.valueOf(intelligentDialogue.getContent());
  208. }
  209. IntelligentDialogueEntity intelligentDialogueEntity = this.intelligentDialogueService.findScoreByIdentifierByLabelByNumByQuestionNo(identifier,label,num);
  210. int score = Integer.valueOf(intelligentDialogueEntity.getContent()) - lastScore;
  211. if (score <= -80){
  212. questionEntity = this.questionService.findByIdAndLabelAndNum("13", label, num);
  213. }else if (score <= -60 && score > -80){
  214. questionEntity = this.questionService.findByIdAndLabelAndNum("11", label, num);
  215. }else if (score <= -40 && score > -60){
  216. questionEntity = this.questionService.findByIdAndLabelAndNum("9", label, num);
  217. }else if (score <= -20 && score > -40){
  218. questionEntity = this.questionService.findByIdAndLabelAndNum("7", label, num);
  219. }else if (score <= 0 && score > -20){
  220. questionEntity = this.questionService.findByIdAndLabelAndNum("5", label, num);
  221. }else if (score <= 20 && score > 0){
  222. questionEntity = this.questionService.findByIdAndLabelAndNum("4", label, num);
  223. }else if (score <= 40 && score > 20){
  224. questionEntity = this.questionService.findByIdAndLabelAndNum("6", label, num);
  225. }else if (score <= 60 && score > 40){
  226. questionEntity = this.questionService.findByIdAndLabelAndNum("8", label, num);
  227. }else if (score <= 80 && score > 60){
  228. questionEntity = this.questionService.findByIdAndLabelAndNum("10", label, num);
  229. }else {
  230. questionEntity = this.questionService.findByIdAndLabelAndNum("12", label, num);
  231. }
  232. }
  233. }
  234. }*/
  235. //替换用户名
  236. if (questionEntity.getQuestion().contains("userName")){
  237. questionEntity.setQuestion(questionEntity.getQuestion().replace("userName",userEntry.getUserName()));
  238. }
  239. //替换使用时长
  240. if (questionEntity.getQuestion().contains("utilityTime")){
  241. IntelligentDialogueEntity intelligentDialogueEntity = this.intelligentDialogueService.findByIdentifierByLabelByNum(identifier,label,num);
  242. Date beginTime = intelligentDialogueEntity.getCreateTime();
  243. //当前时间
  244. Date endTime = new Date();
  245. //计算时间差
  246. int diff = DateUtil.getDistanceByUnit(beginTime, endTime, 2);
  247. if (diff <= 60){
  248. questionEntity.setQuestion(questionEntity.getQuestion().replace("utilityTime",diff+"分钟"));
  249. }else {
  250. int MINUTE = diff%60;
  251. int HOUR = diff/60;
  252. if (HOUR <= 24){
  253. questionEntity.setQuestion(questionEntity.getQuestion().replace("utilityTime",HOUR + "小时" + MINUTE + "分钟"));
  254. }else {
  255. int DAY = HOUR/24;
  256. HOUR = HOUR%24;
  257. questionEntity.setQuestion(questionEntity.getQuestion().replace("utilityTime",DAY + "天" + HOUR + "小时" + MINUTE + "分钟"));
  258. }
  259. }
  260. }
  261. //替换天数问候
  262. if (questionEntity.getQuestion().contains("days")){
  263. String lastNum = String.valueOf(Integer.valueOf(num) - 1);
  264. IntelligentDialogueEntity intelligentDialogueEntity = this.intelligentDialogueService.findDateByIdentifierByLabelByNum(identifier,label,lastNum);
  265. Date beginTime = intelligentDialogueEntity.getCreateTime();
  266. //当前时间
  267. Date endTime = new Date();
  268. //计算时间差
  269. int diff = DateUtil.getDistanceByUnit(beginTime, endTime, 4);
  270. questionEntity.setQuestion(questionEntity.getQuestion().replace("days",String.valueOf(diff)));
  271. }
  272. //替换评测结果
  273. if (questionEntity.getQuestion().contains("SDSEvaluationResult")){
  274. IntelligentDialogueEntity intelligentDialogueEntity = this.intelligentDialogueService.findByIdentifierByLabelByNumByQuestionNo(identifier,label,num,"1");
  275. questionEntity.setQuestion(questionEntity.getQuestion().replace("SDSEvaluationResult",intelligentDialogueEntity.getContent()));
  276. }
  277. //替换治疗成绩
  278. if (questionEntity.getQuestion().contains("therapeuticAchievement")){
  279. List<IntelligentDialogueEntity> intelligentDialogueEntityList = this.intelligentDialogueService.findGradeByIdentifierByLabelByNumByQuestionNo(identifier,label,num,"2");
  280. int therapeuticAchievement = Integer.valueOf(intelligentDialogueEntityList.get(1).getContent()) - Integer.valueOf(intelligentDialogueEntityList.get(0).getContent());
  281. questionEntity.setQuestion(questionEntity.getQuestion().replace("therapeuticAchievement",String.valueOf(therapeuticAchievement)));
  282. }
  283. //替换上次训练内容
  284. if (questionEntity.getQuestion().contains("LastTrainingContent")){
  285. String lastNum = String.valueOf(Integer.valueOf(num) - 1);
  286. IntelligentDialogueEntity intelligentDialogueEntity = this.intelligentDialogueService.findJobByIdentifierByLabelByNumByQuestionNo(identifier,label,lastNum,"3");
  287. questionEntity.setQuestion(questionEntity.getQuestion().replace("LastTrainingContent",intelligentDialogueEntity.getContent()));
  288. }
  289. return success(questionEntity);
  290. }
  291. @PostMapping("/import/{label}/{num}/faq")
  292. @ApiOperation("智能问答导入")
  293. public Result importQuestionAndAnswer(@RequestPart("file") MultipartFile file, @PathVariable String label, @PathVariable String num) {
  294. // FileInputStream fileInputStream = new FileInputStream(file);
  295. String[] fileNames = Objects.requireNonNull(file.getOriginalFilename()).split("\\.");
  296. File targetFile = null;
  297. List<ChatQuestionEntity> chatQuestionEntityList = new ArrayList<>();
  298. List<ChatAnswerEntity> chatAnswerEntityList = new ArrayList<>();
  299. try {
  300. // targetFile = new File("./"+fileNames[0]+ UUID.randomUUID()+"."+fileNames[1]);
  301. // FileUtils.copyInputStreamToFile(file.getInputStream(),targetFile);
  302. targetFile = File.createTempFile(fileNames[0], "." + fileNames[1]);
  303. file.transferTo(targetFile);
  304. List<List<List<Object>>> datas = ExcelUtil.getBankListByExcelSheet(Files.newInputStream(Paths.get(targetFile.getAbsolutePath())), targetFile.getName());
  305. List<List<Object>> questionList = datas.get(0);
  306. List<List<Object>> answerList = datas.get(1);
  307. questionList.forEach(item -> {
  308. ChatQuestionEntity chatQuestionEntity = new ChatQuestionEntity();
  309. chatQuestionEntity.setId((String) item.get(0));
  310. chatQuestionEntity.setQuestion((String) item.get(1));
  311. String nextQuestionNo = String.valueOf(item.get(2)).replace("aaa","");
  312. chatQuestionEntity.setNextQuestionNo(nextQuestionNo);
  313. String questionType = (String) item.get(3);
  314. if (questionType.equals("单选")) {
  315. chatQuestionEntity.setQuestionType("0");
  316. } else if (questionType.equals("填空")) {
  317. chatQuestionEntity.setQuestionType("1");
  318. } else if (questionType.equals("多选")) {
  319. chatQuestionEntity.setQuestionType("2");
  320. } else if (questionType.equals("整数")) {
  321. chatQuestionEntity.setQuestionType("3");
  322. } else {
  323. chatQuestionEntity.setQuestionType("0");
  324. }
  325. //chatQuestionEntity.setScaleFlag((String) item.get(4));
  326. chatQuestionEntity.setLabel(label);
  327. chatQuestionEntity.setNum(num);
  328. chatQuestionEntityList.add(chatQuestionEntity);
  329. });
  330. answerList.forEach(item -> {
  331. ChatAnswerEntity chatAnswerEntity = new ChatAnswerEntity();
  332. chatAnswerEntity.setQuestionNo((String) item.get(0));
  333. chatAnswerEntity.setNextQuestionNo((String) item.get(1));
  334. chatAnswerEntity.setAnswer((String) item.get(2));
  335. chatAnswerEntity.setLabel(label);
  336. chatAnswerEntity.setQuestionType("0");
  337. chatAnswerEntity.setNum(num);
  338. chatAnswerEntityList.add(chatAnswerEntity);
  339. });
  340. } catch (Exception e) {
  341. throw new RuntimeException(e);
  342. }
  343. if (chatQuestionEntityList.size() > 0 && chatAnswerEntityList.size() > 0) {
  344. //this.questionService.deleteByLabel(label);
  345. //this.answerService.deleteByLabel(label);
  346. /*this.questionService.saveBatch(chatQuestionEntityList);
  347. this.answerService.saveBatch(chatAnswerEntityList);*/
  348. }
  349. return success();
  350. }
  351. @GetMapping("/getAnswer/{questionNo}/{label}/{num}")
  352. @ApiOperation("查询答案信息列表,questionNo为问题的id字段,nextQuestionNo 为此答案被选中后的下一个应该呈现的问题")
  353. public Result getAnswer(@PathVariable String questionNo, @PathVariable String label, @PathVariable String num) {
  354. List<ChatAnswerEntity> answerEntities = this.answerService.findByQuestionNoAndLabelAndNum(questionNo, label, num);
  355. return success(answerEntities);
  356. }
  357. @GetMapping("/getNextQuestionByScaleResult")
  358. @ApiOperation("根据量表测试结果查询下一问题编号")
  359. public Result getNextQuestionByScaleResult(String label, String result, String num) {
  360. ResultQuestionEntity resultQuestionEntity = this.resultQuestionService.findByLabelAndResultAndNum(label, result, num);
  361. //ResultQuestionEntity resultQuestionEntity = this.resultQuestionService.findByLabelAndNum(label, num);
  362. if (resultQuestionEntity == null) {
  363. return fail(ErrorCode.NEXT_QUESTION_NO_NOT_FOUND);
  364. }
  365. ChatQuestionEntity byIdAndLabel = this.questionService.findByIdAndLabelAndNum(resultQuestionEntity.getNextQuestionNo(), label, resultQuestionEntity.getNum());
  366. if (byIdAndLabel == null) {
  367. return fail(ErrorCode.NEXT_QUESTION_NO_ERROR);
  368. }
  369. return success(resultQuestionEntity);
  370. }
  371. @PostMapping("/complete/chat")
  372. @ApiOperation(value = "结束会话,保存会话记录", notes = "identifier:用户编号;userName:用户名;label:智能对话分类 1-焦虑;2-抑郁;3-失眠;4-压力;content:会话详情")
  373. public Result completeChat(@RequestBody String json) throws IOException {
  374. ChatRecordEntity chatRecordEntity = JSONObject.parseObject(json, ChatRecordEntity.class);
  375. //生成文件
  376. List<ChatEntity> chatEntityList = JSONObject.parseArray(chatRecordEntity.getContent(), ChatEntity.class);
  377. if (chatEntityList != null && chatEntityList.size() > 0) {
  378. String filePath = "./对话记录/" + chatRecordEntity.getIdentifier() + "-对话记录-" + DateUtil.getNowTime_CN() + ".xlsx";
  379. File file = new File(filePath);
  380. if (!file.exists()) {
  381. file.createNewFile();
  382. }
  383. XSSFWorkbook workbook = new XSSFWorkbook();
  384. ExcelUtil.createFont(workbook);
  385. XSSFSheet sheet = workbook.createSheet("对话记录");
  386. XSSFRow titleRow = sheet.createRow(0);
  387. XSSFCell cellOrder = titleRow.createCell(0);
  388. cellOrder.setCellValue("角色");
  389. XSSFCell cellQuestion = titleRow.createCell(1);
  390. cellQuestion.setCellValue("内容");
  391. for (int i = 0; i < chatEntityList.size(); i++) {
  392. XSSFRow row = sheet.createRow(i + 1);
  393. XSSFCell cellOrder1 = row.createCell(0);
  394. if (chatEntityList.get(i).getFrom().equals("1")) {
  395. cellOrder1.setCellValue("智能助手:");
  396. } else {
  397. cellOrder1.setCellValue("用户:");
  398. }
  399. XSSFCell cellQuestion1 = row.createCell(1);
  400. cellQuestion1.setCellValue(chatEntityList.get(i).getQuestion());
  401. }
  402. OutputStream outputStream = Files.newOutputStream(file.toPath());
  403. workbook.write(outputStream);
  404. outputStream.close();
  405. //保存记录
  406. chatRecordEntity.setFilePath(filePath);
  407. chatRecordEntity.setCreateTime(new Date());
  408. this.chatRecordService.save(chatRecordEntity);
  409. return success();
  410. } else {
  411. return fail(ErrorCode.CHAT_CONTENT_EMPTY);
  412. }
  413. }
  414. @GetMapping("/chat/list")
  415. @ApiOperation(value = "智能对话列表", notes = "identifier:编号;beginDate:查询起始日期;endDate:查询结束日期;pageNum:页数;pageSize:每页记录数")
  416. public Result getChatList(String identifier, String beginDate, String endDate, int pageNum, int pageSize) {
  417. Page<ChatRecordEntity> chatRecordEntities = this.chatRecordService.find(identifier, beginDate, endDate, pageNum, pageSize);
  418. return success(chatRecordEntities);
  419. }
  420. @GetMapping("/chat/download")
  421. @ApiOperation(value = "下载对话记录", notes = "")
  422. public Result downloadChatList(@RequestBody String json, HttpServletResponse response) throws IOException {
  423. List<String> list = JSONObject.parseArray(json, String.class);
  424. if (list.size() > 0) {
  425. for (String item : list) {
  426. File file = new File(item);
  427. if (file.exists()) {
  428. InputStream inputStream = null;
  429. OutputStream outputStream = null;
  430. try {
  431. inputStream = Files.newInputStream(file.toPath());
  432. outputStream = new FileOutputStream("./对话列表/" + item);
  433. IOUtils.copy(inputStream, outputStream);
  434. } catch (IOException e) {
  435. log.error("对话记录下载失败:" + e.getMessage());
  436. } finally {
  437. if (inputStream != null) {
  438. inputStream.close();
  439. }
  440. if (outputStream != null) {
  441. outputStream.close();
  442. }
  443. }
  444. }
  445. }
  446. File dir = new File("./对话列表");
  447. if (!dir.exists()) {
  448. return fail(ErrorCode.FAILED);
  449. } else {
  450. ZipUtils.createZip("./对话列表", "./对话列表" + DateUtil.getNowTime_CN() + ".zip", false);
  451. FileUtils.downloadFile(new File("./对话列表", "对话列表" + DateUtil.getNowTime_CN() + ".zip"), "", "对话列表" + DateUtil.getNowTime_CN() + ".zip", response);
  452. return success();
  453. }
  454. }
  455. return fail(ErrorCode.FAILED);
  456. }
  457. @ApiOperation(value = "对话记录下载")
  458. @GetMapping("/chatRecord/download")
  459. public Result chatRecordDownload(String id, HttpServletResponse response) throws Exception {
  460. if (id != null) {
  461. ChatRecordEntity chatRecordEntity = this.chatRecordService.findById(id);
  462. if (chatRecordEntity == null) {
  463. return fail(ErrorCode.FAILED);
  464. }
  465. File file = null;
  466. if (new File(chatRecordEntity.getFilePath()).exists()) {
  467. file = new File(chatRecordEntity.getFilePath());
  468. response.reset();
  469. response.setContentType("application/octet-stream");
  470. response.setCharacterEncoding("utf-8");
  471. response.setContentLength((int) file.length());
  472. response.setHeader("Content-Disposition", "attachment;filename=" + java.net.URLEncoder.encode(file.getName(), "UTF-8"));
  473. response.setHeader("filename",java.net.URLEncoder.encode(file.getName(), "UTF-8"));
  474. byte[] buffer = new byte[1024];
  475. FileInputStream fis = null;
  476. BufferedInputStream bis = null;
  477. try {
  478. fis = new FileInputStream(file);
  479. bis = new BufferedInputStream(fis);
  480. OutputStream os = response.getOutputStream();
  481. int i = bis.read(buffer);
  482. while (i != -1) {
  483. os.write(buffer, 0, i);
  484. i = bis.read(buffer);
  485. }
  486. return success();
  487. } catch (Exception e) {
  488. e.printStackTrace();
  489. } finally {
  490. if (bis != null) {
  491. try {
  492. bis.close();
  493. } catch (IOException e) {
  494. e.printStackTrace();
  495. }
  496. }
  497. if (fis != null) {
  498. try {
  499. fis.close();
  500. } catch (IOException e) {
  501. e.printStackTrace();
  502. }
  503. }
  504. }
  505. } else {
  506. return fail(ErrorCode.FAILED);
  507. }
  508. }
  509. return fail(ErrorCode.FAILED);
  510. }
  511. @SneakyThrows
  512. @ApiOperation(value = "对话记录批量下载接口")
  513. @GetMapping("/chatRecord/batchDownload")
  514. public Result chatRecordBatchDownload(@RequestParam(value = "ids", required = false) List<String> recordingIds, HttpServletResponse response) {
  515. //原始记录文件
  516. File file = null;
  517. //原始记录复制后文件
  518. File destFile = null;
  519. //所有记录汇总后文件夹,用来压缩
  520. String filePath ="./对话记录/记录下载";
  521. //原始记录文件名
  522. String fileName = null;
  523. for (int i = 0; i < recordingIds.size(); i++) {
  524. ChatRecordEntity chatRecordEntity = this.chatRecordService.findById(recordingIds.get(i));
  525. String[] split = chatRecordEntity.getFilePath().split("/");
  526. if (split.length > 1){
  527. fileName = split[split.length-1];
  528. }else {
  529. fileName = chatRecordEntity.getFilePath();
  530. }
  531. //设置文件路径
  532. file = new File(chatRecordEntity.getFilePath());
  533. if (file.exists()){
  534. destFile = new File(filePath+"/"+fileName+".xlsx");
  535. //将原始文件进行复制
  536. org.apache.commons.io.FileUtils.copyFile(file, destFile);
  537. }
  538. }
  539. //将复制后的整个文件夹打包
  540. ZipUtils.createZip(filePath, filePath + ".zip", true);
  541. File zipFile = new File(filePath + ".zip");
  542. //下载压缩后文件
  543. if (zipFile.exists()) {
  544. response.reset();
  545. response.setContentType("application/octet-stream");
  546. response.setCharacterEncoding("utf-8");
  547. response.setContentLength((int) zipFile.length());
  548. response.setHeader("Content-Disposition", "attachment;filename=" + java.net.URLEncoder.encode("chatRecord.zip", "UTF-8"));
  549. response.setHeader("filename",java.net.URLEncoder.encode("chatRecord.zip", "UTF-8"));
  550. byte[] buffer = new byte[1024];
  551. FileInputStream fis = null;
  552. BufferedInputStream bis = null;
  553. try {
  554. fis = new FileInputStream(zipFile);
  555. bis = new BufferedInputStream(fis);
  556. OutputStream os = response.getOutputStream();
  557. int i = bis.read(buffer);
  558. while (i != -1) {
  559. os.write(buffer, 0, i);
  560. i = bis.read(buffer);
  561. }
  562. return success();
  563. } catch (Exception e) {
  564. e.printStackTrace();
  565. } finally {
  566. if (bis != null) {
  567. try {
  568. bis.close();
  569. } catch (IOException e) {
  570. e.printStackTrace();
  571. }
  572. }
  573. if (fis != null) {
  574. try {
  575. fis.close();
  576. } catch (IOException e) {
  577. e.printStackTrace();
  578. }
  579. }
  580. //将复制后的整个文件夹删除
  581. Path path = Paths.get(filePath);
  582. try (Stream<Path> walk = Files.walk(path)) {
  583. walk.sorted(Comparator.reverseOrder())
  584. .forEach(ChatController::deleteDirectoryStream);
  585. }
  586. //删除生成的压缩包
  587. Files.delete(Paths.get(filePath + ".zip"));
  588. }
  589. }
  590. //删除生成的压缩包
  591. Files.delete(Paths.get(filePath + ".zip"));
  592. //将复制后的整个文件夹删除
  593. Path path = Paths.get(filePath);
  594. try (Stream<Path> walk = Files.walk(path)) {
  595. walk.sorted(Comparator.reverseOrder())
  596. .forEach(ChatController::deleteDirectoryStream);
  597. }
  598. return fail(ErrorCode.FAILED);
  599. }
  600. @SneakyThrows
  601. @ApiOperation(value = "对话记录全部下载接口")
  602. @GetMapping("/chatRecord/AllDownload")
  603. public Result chatRecordAllDownload(String identifier, String beginDate, String endDate, HttpServletResponse response) {
  604. List<ChatRecordEntity> chatRecordEntityList = this.chatRecordService.findAll(identifier, beginDate, endDate);
  605. //原始记录文件
  606. File file = null;
  607. //原始记录复制后文件
  608. File destFile = null;
  609. //所有记录汇总后文件夹,用来压缩
  610. String filePath ="./对话记录/记录下载";
  611. //原始记录文件名
  612. String fileName = null;
  613. for (int i = 0; i < chatRecordEntityList.size(); i++) {
  614. ChatRecordEntity chatRecordEntity = chatRecordEntityList.get(i);
  615. String[] split = chatRecordEntity.getFilePath().split("/");
  616. if (split.length > 1){
  617. fileName = split[split.length-1];
  618. }else {
  619. fileName = chatRecordEntity.getFilePath();
  620. }
  621. //设置文件路径
  622. file = new File(chatRecordEntity.getFilePath());
  623. if (file.exists()){
  624. destFile = new File(filePath+"/"+fileName+".xlsx");
  625. //将原始文件进行复制
  626. org.apache.commons.io.FileUtils.copyFile(file, destFile);
  627. }
  628. }
  629. //将复制后的整个文件夹打包
  630. ZipUtils.createZip(filePath, filePath + ".zip", true);
  631. File zipFile = new File(filePath + ".zip");
  632. //下载压缩后文件
  633. if (zipFile.exists()) {
  634. response.reset();
  635. response.setContentType("application/octet-stream");
  636. response.setCharacterEncoding("utf-8");
  637. response.setContentLength((int) zipFile.length());
  638. response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode("chatRecord.zip", "UTF-8"));
  639. response.setHeader("filename",java.net.URLEncoder.encode("chatRecord.zip", "UTF-8"));
  640. byte[] buffer = new byte[1024];
  641. FileInputStream fis = null;
  642. BufferedInputStream bis = null;
  643. try {
  644. fis = new FileInputStream(zipFile);
  645. bis = new BufferedInputStream(fis);
  646. OutputStream os = response.getOutputStream();
  647. int i = bis.read(buffer);
  648. while (i != -1) {
  649. os.write(buffer, 0, i);
  650. i = bis.read(buffer);
  651. }
  652. return success();
  653. } catch (Exception e) {
  654. e.printStackTrace();
  655. } finally {
  656. if (bis != null) {
  657. try {
  658. bis.close();
  659. } catch (IOException e) {
  660. e.printStackTrace();
  661. }
  662. }
  663. if (fis != null) {
  664. try {
  665. fis.close();
  666. } catch (IOException e) {
  667. e.printStackTrace();
  668. }
  669. }
  670. //将复制后的整个文件夹删除
  671. Path path = Paths.get(filePath);
  672. try (Stream<Path> walk = Files.walk(path)) {
  673. walk.sorted(Comparator.reverseOrder())
  674. .forEach(ChatController::deleteDirectoryStream);
  675. }
  676. //删除生成的压缩包
  677. Files.delete(Paths.get(filePath + ".zip"));
  678. }
  679. }
  680. //删除生成的压缩包
  681. Files.delete(Paths.get(filePath + ".zip"));
  682. //将复制后的整个文件夹删除
  683. Path path = Paths.get(filePath);
  684. try (Stream<Path> walk = Files.walk(path)) {
  685. walk.sorted(Comparator.reverseOrder())
  686. .forEach(ChatController::deleteDirectoryStream);
  687. }
  688. return fail(ErrorCode.FAILED);
  689. }
  690. public static void deleteDirectoryStream(Path path) {
  691. try {
  692. Files.delete(path);
  693. } catch (IOException e) {
  694. }
  695. }
  696. private ChatQuestionEntity emotionScoreSkip(String identifier, String label, String num, String questionNo) {
  697. int a = emotionScore(identifier,label,num,questionNo);
  698. ChatQuestionEntity questionEntity = new ChatQuestionEntity();
  699. if (label.equals("2")){
  700. if (num.equals("1")){
  701. if (questionNo.equals("40")){
  702. switch (a) {
  703. case 1:
  704. questionEntity = this.questionService.findByIdAndLabelAndNum("41", label, num);
  705. break;
  706. case 2:
  707. questionEntity = this.questionService.findByIdAndLabelAndNum("43", label, num);
  708. break;
  709. case 3:
  710. questionEntity = this.questionService.findByIdAndLabelAndNum("45", label, num);
  711. break;
  712. case 4:
  713. questionEntity = this.questionService.findByIdAndLabelAndNum("47", label, num);
  714. break;
  715. default:
  716. break;
  717. }
  718. }
  719. if (questionNo.equals("82")){
  720. switch (a) {
  721. case 1:
  722. questionEntity = this.questionService.findByIdAndLabelAndNum("83", label, num);
  723. break;
  724. case 2:
  725. questionEntity = this.questionService.findByIdAndLabelAndNum("85", label, num);
  726. break;
  727. case 3:
  728. questionEntity = this.questionService.findByIdAndLabelAndNum("87", label, num);
  729. break;
  730. case 4:
  731. questionEntity = this.questionService.findByIdAndLabelAndNum("89", label, num);
  732. break;
  733. default:
  734. break;
  735. }
  736. }
  737. if (questionNo.equals("120")){
  738. switch (a) {
  739. case 1:
  740. questionEntity = this.questionService.findByIdAndLabelAndNum("121", label, num);
  741. break;
  742. case 2:
  743. questionEntity = this.questionService.findByIdAndLabelAndNum("123", label, num);
  744. break;
  745. case 3:
  746. questionEntity = this.questionService.findByIdAndLabelAndNum("125", label, num);
  747. break;
  748. case 4:
  749. questionEntity = this.questionService.findByIdAndLabelAndNum("157", label, num);
  750. break;
  751. default:
  752. break;
  753. }
  754. }
  755. if (questionNo.equals("168")){
  756. switch (a) {
  757. case 1:
  758. questionEntity = this.questionService.findByIdAndLabelAndNum("169", label, num);
  759. break;
  760. case 2:
  761. questionEntity = this.questionService.findByIdAndLabelAndNum("171", label, num);
  762. break;
  763. case 3:
  764. questionEntity = this.questionService.findByIdAndLabelAndNum("173", label, num);
  765. break;
  766. case 4:
  767. questionEntity = this.questionService.findByIdAndLabelAndNum("175", label, num);
  768. break;
  769. default:
  770. break;
  771. }
  772. }
  773. if (questionNo.equals("209")){
  774. switch (a) {
  775. case 1:
  776. questionEntity = this.questionService.findByIdAndLabelAndNum("210", label, num);
  777. break;
  778. case 2:
  779. questionEntity = this.questionService.findByIdAndLabelAndNum("212", label, num);
  780. break;
  781. case 3:
  782. questionEntity = this.questionService.findByIdAndLabelAndNum("214", label, num);
  783. break;
  784. case 4:
  785. questionEntity = this.questionService.findByIdAndLabelAndNum("216", label, num);
  786. break;
  787. default:
  788. break;
  789. }
  790. }
  791. if (questionNo.equals("246")){
  792. switch (a) {
  793. case 1:
  794. questionEntity = this.questionService.findByIdAndLabelAndNum("249", label, num);
  795. break;
  796. case 2:
  797. questionEntity = this.questionService.findByIdAndLabelAndNum("251", label, num);
  798. break;
  799. case 3:
  800. questionEntity = this.questionService.findByIdAndLabelAndNum("253", label, num);
  801. break;
  802. case 4:
  803. questionEntity = this.questionService.findByIdAndLabelAndNum("255", label, num);
  804. break;
  805. default:
  806. break;
  807. }
  808. }
  809. if (questionNo.equals("285")){
  810. switch (a) {
  811. case 1:
  812. questionEntity = this.questionService.findByIdAndLabelAndNum("288", label, num);
  813. break;
  814. case 2:
  815. questionEntity = this.questionService.findByIdAndLabelAndNum("290", label, num);
  816. break;
  817. case 3:
  818. questionEntity = this.questionService.findByIdAndLabelAndNum("292", label, num);
  819. break;
  820. case 4:
  821. questionEntity = this.questionService.findByIdAndLabelAndNum("294", label, num);
  822. break;
  823. default:
  824. break;
  825. }
  826. }
  827. if (questionNo.equals("333")){
  828. switch (a) {
  829. case 1:
  830. questionEntity = this.questionService.findByIdAndLabelAndNum("336", label, num);
  831. break;
  832. case 2:
  833. questionEntity = this.questionService.findByIdAndLabelAndNum("338", label, num);
  834. break;
  835. case 3:
  836. questionEntity = this.questionService.findByIdAndLabelAndNum("340", label, num);
  837. break;
  838. case 4:
  839. questionEntity = this.questionService.findByIdAndLabelAndNum("342", label, num);
  840. break;
  841. default:
  842. break;
  843. }
  844. }
  845. if (questionNo.equals("374")){
  846. switch (a) {
  847. case 1:
  848. questionEntity = this.questionService.findByIdAndLabelAndNum("377", label, num);
  849. break;
  850. case 2:
  851. questionEntity = this.questionService.findByIdAndLabelAndNum("379", label, num);
  852. break;
  853. case 3:
  854. questionEntity = this.questionService.findByIdAndLabelAndNum("381", label, num);
  855. break;
  856. case 4:
  857. questionEntity = this.questionService.findByIdAndLabelAndNum("383", label, num);
  858. break;
  859. default:
  860. break;
  861. }
  862. }
  863. if (questionNo.equals("411")){
  864. switch (a) {
  865. case 1:
  866. questionEntity = this.questionService.findByIdAndLabelAndNum("414", label, num);
  867. break;
  868. case 2:
  869. questionEntity = this.questionService.findByIdAndLabelAndNum("416", label, num);
  870. break;
  871. case 3:
  872. questionEntity = this.questionService.findByIdAndLabelAndNum("418", label, num);
  873. break;
  874. case 4:
  875. questionEntity = this.questionService.findByIdAndLabelAndNum("420", label, num);
  876. break;
  877. default:
  878. break;
  879. }
  880. }
  881. }
  882. }
  883. if (label.equals("2")) {
  884. if (num.equals("2") || num.equals("3") || num.equals("4") || num.equals("5")){
  885. if (questionNo.equals("56")) {
  886. switch (a) {
  887. case 1:
  888. questionEntity = this.questionService.findByIdAndLabelAndNum("57", label, num);
  889. break;
  890. case 2:
  891. questionEntity = this.questionService.findByIdAndLabelAndNum("59", label, num);
  892. break;
  893. case 3:
  894. questionEntity = this.questionService.findByIdAndLabelAndNum("61", label, num);
  895. break;
  896. case 4:
  897. questionEntity = this.questionService.findByIdAndLabelAndNum("63", label, num);
  898. break;
  899. default:
  900. break;
  901. }
  902. }
  903. if (questionNo.equals("98")) {
  904. switch (a) {
  905. case 1:
  906. questionEntity = this.questionService.findByIdAndLabelAndNum("99", label, num);
  907. break;
  908. case 2:
  909. questionEntity = this.questionService.findByIdAndLabelAndNum("101", label, num);
  910. break;
  911. case 3:
  912. questionEntity = this.questionService.findByIdAndLabelAndNum("103", label, num);
  913. break;
  914. case 4:
  915. questionEntity = this.questionService.findByIdAndLabelAndNum("105", label, num);
  916. break;
  917. default:
  918. break;
  919. }
  920. }if (questionNo.equals("136")) {
  921. switch (a) {
  922. case 1:
  923. questionEntity = this.questionService.findByIdAndLabelAndNum("137", label, num);
  924. break;
  925. case 2:
  926. questionEntity = this.questionService.findByIdAndLabelAndNum("139", label, num);
  927. break;
  928. case 3:
  929. questionEntity = this.questionService.findByIdAndLabelAndNum("141", label, num);
  930. break;
  931. case 4:
  932. questionEntity = this.questionService.findByIdAndLabelAndNum("143", label, num);
  933. break;
  934. default:
  935. break;
  936. }
  937. }if (questionNo.equals("184")) {
  938. switch (a) {
  939. case 1:
  940. questionEntity = this.questionService.findByIdAndLabelAndNum("185", label, num);
  941. break;
  942. case 2:
  943. questionEntity = this.questionService.findByIdAndLabelAndNum("187", label, num);
  944. break;
  945. case 3:
  946. questionEntity = this.questionService.findByIdAndLabelAndNum("189", label, num);
  947. break;
  948. case 4:
  949. questionEntity = this.questionService.findByIdAndLabelAndNum("191", label, num);
  950. break;
  951. default:
  952. break;
  953. }
  954. }if (questionNo.equals("225")) {
  955. switch (a) {
  956. case 1:
  957. questionEntity = this.questionService.findByIdAndLabelAndNum("226", label, num);
  958. break;
  959. case 2:
  960. questionEntity = this.questionService.findByIdAndLabelAndNum("228", label, num);
  961. break;
  962. case 3:
  963. questionEntity = this.questionService.findByIdAndLabelAndNum("230", label, num);
  964. break;
  965. case 4:
  966. questionEntity = this.questionService.findByIdAndLabelAndNum("232", label, num);
  967. break;
  968. default:
  969. break;
  970. }
  971. }if (questionNo.equals("262")) {
  972. switch (a) {
  973. case 1:
  974. questionEntity = this.questionService.findByIdAndLabelAndNum("265", label, num);
  975. break;
  976. case 2:
  977. questionEntity = this.questionService.findByIdAndLabelAndNum("267", label, num);
  978. break;
  979. case 3:
  980. questionEntity = this.questionService.findByIdAndLabelAndNum("269", label, num);
  981. break;
  982. case 4:
  983. questionEntity = this.questionService.findByIdAndLabelAndNum("271", label, num);
  984. break;
  985. default:
  986. break;
  987. }
  988. }if (questionNo.equals("301")) {
  989. switch (a) {
  990. case 1:
  991. questionEntity = this.questionService.findByIdAndLabelAndNum("304", label, num);
  992. break;
  993. case 2:
  994. questionEntity = this.questionService.findByIdAndLabelAndNum("306", label, num);
  995. break;
  996. case 3:
  997. questionEntity = this.questionService.findByIdAndLabelAndNum("308", label, num);
  998. break;
  999. case 4:
  1000. questionEntity = this.questionService.findByIdAndLabelAndNum("310", label, num);
  1001. break;
  1002. default:
  1003. break;
  1004. }
  1005. }if (questionNo.equals("349")) {
  1006. switch (a) {
  1007. case 1:
  1008. questionEntity = this.questionService.findByIdAndLabelAndNum("352", label, num);
  1009. break;
  1010. case 2:
  1011. questionEntity = this.questionService.findByIdAndLabelAndNum("354", label, num);
  1012. break;
  1013. case 3:
  1014. questionEntity = this.questionService.findByIdAndLabelAndNum("356", label, num);
  1015. break;
  1016. case 4:
  1017. questionEntity = this.questionService.findByIdAndLabelAndNum("358", label, num);
  1018. break;
  1019. default:
  1020. break;
  1021. }
  1022. }if (questionNo.equals("390")) {
  1023. switch (a) {
  1024. case 1:
  1025. questionEntity = this.questionService.findByIdAndLabelAndNum("393", label, num);
  1026. break;
  1027. case 2:
  1028. questionEntity = this.questionService.findByIdAndLabelAndNum("395", label, num);
  1029. break;
  1030. case 3:
  1031. questionEntity = this.questionService.findByIdAndLabelAndNum("397", label, num);
  1032. break;
  1033. case 4:
  1034. questionEntity = this.questionService.findByIdAndLabelAndNum("399", label, num);
  1035. break;
  1036. default:
  1037. break;
  1038. }
  1039. }if (questionNo.equals("427")) {
  1040. switch (a) {
  1041. case 1:
  1042. questionEntity = this.questionService.findByIdAndLabelAndNum("430", label, num);
  1043. break;
  1044. case 2:
  1045. questionEntity = this.questionService.findByIdAndLabelAndNum("432", label, num);
  1046. break;
  1047. case 3:
  1048. questionEntity = this.questionService.findByIdAndLabelAndNum("434", label, num);
  1049. break;
  1050. case 4:
  1051. questionEntity = this.questionService.findByIdAndLabelAndNum("436", label, num);
  1052. break;
  1053. default:
  1054. break;
  1055. }
  1056. }
  1057. }
  1058. }
  1059. return questionEntity;
  1060. }
  1061. private int emotionScore(String identifier, String label, String num, String questionNo) {
  1062. IntelligentDialogueEntity intelligentDialogueEntity = this.intelligentDialogueService.findEmotionScoreByIdentifierByLabelByNumByQuestionNo(identifier,label,num,questionNo);
  1063. int emotionScore = Integer.valueOf(intelligentDialogueEntity.getContent());
  1064. if (emotionScore <= 25){
  1065. emotionScore = 1;
  1066. }else if (emotionScore <= 50 && emotionScore >= 26){
  1067. emotionScore = 2;
  1068. }else if (emotionScore <= 75 && emotionScore >= 51){
  1069. emotionScore = 3;
  1070. }else {
  1071. emotionScore = 4;
  1072. }
  1073. return emotionScore;
  1074. }
  1075. }