浏览代码

开发智能对话记录功能提交

zsy 1 年之前
父节点
当前提交
f7c800353c

+ 1 - 1
src/main/java/com/rf/kjb/chat/dao/domain/ChatAnswerEntity.java

@@ -34,6 +34,6 @@ public class ChatAnswerEntity extends BaseEntry {
     @Column(name = "answer",columnDefinition = "varchar(200) not null comment '答案信息'")
     private String answer;
 
-    @Column(name = "label",columnDefinition = "varchar(2) not null comment '分类:1-焦虑;2-抑郁;3-失眠;4-压力'")
+    @Column(name = "label",columnDefinition = "varchar(2) not null comment '分类:1-焦虑;2-抑郁;3-失眠;4-压力;5-开场白'")
     private String label;
 }

+ 1 - 1
src/main/java/com/rf/kjb/chat/dao/domain/ChatQuestionEntity.java

@@ -32,7 +32,7 @@ public class ChatQuestionEntity   {
     private String questionType;
 
     @Id
-    @Column(name = "label",columnDefinition = "varchar(2) not null comment '分类:1-焦虑;2-抑郁;3-失眠;4-压力'")
+    @Column(name = "label",columnDefinition = "varchar(2) not null comment '分类:1-焦虑;2-抑郁;3-失眠;4-压力;5-开场白'")
     private String label;
 
     @Column(name = "scale_flag",columnDefinition = "varchar(50) comment '量表标志,如果是量表的题目信息,此处为量表flag'")

+ 9 - 1
src/main/java/com/rf/kjb/chat/rest/ChatController.java

@@ -73,7 +73,15 @@ public class ChatController extends BaseController {
             id = "1";
         }
         ChatQuestionEntity questionEntity = this.questionService.findByIdAndLabel(id, label);
-        if (questionEntity.getId().equals("1")){
+        if (questionEntity.getLabel().equals("5") && questionEntity.getId().equals("3")){
+            String token = request.getHeader("Authorization");
+            token = token.split(" ")[1];//以空格划分Bearer token,获取token
+            //从请求头中获取token
+            DecodedJWT verify = JWTUtil.verify(token);
+            String userName = verify.getClaim("userName").asString();
+            questionEntity.setQuestion(userName+questionEntity.getQuestion());
+        }
+        if (!questionEntity.getLabel().equals("5") && questionEntity.getId().equals("1")){
             String token = request.getHeader("Authorization");
             token = token.split(" ")[1];//以空格划分Bearer token,获取token
             //从请求头中获取token

+ 9 - 1
src/main/java/com/rf/kjb/intelligentDialogue/dao/domain/IntelligentDialogueEntity.java

@@ -27,9 +27,17 @@ public class IntelligentDialogueEntity extends BaseEntry {
     @Column(name = "identifier" ,columnDefinition = "varchar(20) not null  comment '用户编号'")
     private String identifier;
 
-    @Column(name = "label",columnDefinition = "varchar(2) not null comment '对话分类:0-问;1-答'")
+    @Column(name = "label",columnDefinition = "varchar(2) not null comment '对话分类:0-电脑;1-用户'")
     private String label;
 
     @Column(name = "content",columnDefinition = "varchar(500) not null comment '对话内容'")
     private String content;
+
+    @Column(name = "type",columnDefinition = "varchar(2) not null comment '分类:0-智能对话;1-焦虑;2-抑郁;3-失眠;4-压力;5-开场白'")
+    private String type;
+
+    @Column(name = "question_no",columnDefinition = "varchar(50) null comment '问题编号'")
+    private String questionNo;
+
+
 }

+ 32 - 2
src/main/java/com/rf/kjb/intelligentDialogue/rest/IntelligentDialogueController.java

@@ -1,6 +1,7 @@
 package com.rf.kjb.intelligentDialogue.rest;
 
 import com.alibaba.fastjson.JSONObject;
+import com.auth0.jwt.interfaces.DecodedJWT;
 import com.rf.kjb.base.rest.BaseController;
 import com.rf.kjb.chat.rest.ChatController;
 import com.rf.kjb.excel.ExcelUtil;
@@ -8,6 +9,7 @@ import com.rf.kjb.exception.ErrorCode;
 import com.rf.kjb.intelligentDialogue.dao.domain.IntelligentDialogueEntity;
 import com.rf.kjb.intelligentDialogue.service.IntelligentDialogueService;
 import com.rf.kjb.scale.util.DateUtil;
+import com.rf.kjb.utils.JWTUtil;
 import com.rf.kjb.utils.Result;
 import com.rf.kjb.utils.ZipUtils;
 import io.swagger.annotations.Api;
@@ -22,11 +24,14 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.domain.Page;
 import org.springframework.web.bind.annotation.*;
 
+import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import java.io.*;
 import java.nio.file.Files;
 import java.nio.file.Path;
 import java.nio.file.Paths;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
 import java.util.*;
 import java.util.stream.Stream;
 
@@ -52,9 +57,34 @@ public class IntelligentDialogueController extends BaseController {
 
     @GetMapping("/dialogueRecords")
     @ApiOperation(value = "用户智能对话记录查询", notes = "identifier:编号;pageNum:页数;pageSize:每页记录数")
-    public Result getDialogueRecords(String identifier, int pageNum, int pageSize) {
+    public Result getDialogueRecords(String identifier, int pageNum, int pageSize, HttpServletRequest request) {
         Page<IntelligentDialogueEntity> intelligentDialogueEntities = this.intelligentDialogueService.getIntelligentDialogueEntityByIdentifier(identifier, pageNum, pageSize);
-        return success(intelligentDialogueEntities);
+        String greetings = null;
+        if (intelligentDialogueEntities.getContent().size() == 0){
+            JSONObject jsonObject = new JSONObject();
+            jsonObject.put("intelligentDialogueEntities", intelligentDialogueEntities);
+            jsonObject.put("greetings", null);
+            return success(jsonObject);
+        }else {
+            Date beginTime = intelligentDialogueEntities.getContent().get(0).getCreateTime();
+            //当前时间
+            Date endTime = new Date();
+            //计算时间差---分钟
+            int diff = DateUtil.getDistanceByUnit(beginTime, endTime, 4);
+            if (diff < 0 || diff >= 4) {
+                String token = request.getHeader("Authorization");
+                token = token.split(" ")[1];//以空格划分Bearer token,获取token
+                //从请求头中获取token
+                DecodedJWT verify = JWTUtil.verify(token);
+                String userName = verify.getClaim("userName").asString();
+                greetings = userName + "你好,很高兴你又来跟我聊天了。咱们已经" + diff + "天没有见面了。";
+            }
+
+            JSONObject jsonObject = new JSONObject();
+            jsonObject.put("intelligentDialogueEntities", intelligentDialogueEntities);
+            jsonObject.put("greetings", greetings);
+            return success(jsonObject);
+        }
     }
 
     @GetMapping("/dialogueList")

+ 18 - 0
src/main/java/com/rf/kjb/user/rest/UserController.java

@@ -79,6 +79,24 @@ public class UserController extends BaseController {
         this.userService.save(userEntry);
         return success();
     }
+
+    /**
+     * 修改用户昵称
+     * @param json
+     * @return
+     */
+    @PostMapping("/updateUserName")
+    @ApiOperation(value = "修改用户昵称",notes = " userName 用户名 字符串,identifier:用户编号 字符串")
+    public Result updateUserName( @RequestBody String json){
+        JSONObject jsonObject =JSONObject.parseObject(json);
+        UserEntry userEntry = this.userService.findByIdentifier(jsonObject.getString("identifier"));
+        userEntry.setUserName(jsonObject.getString("userName"));
+        assertUser(userEntry);
+        userEntry.setUpdateTime(new Date());
+        this.userService.save(userEntry);
+        return success();
+    }
+
     @DeleteMapping("/delete/{identifier}")
     @ApiOperation(value = "删除用户",notes = "identifier:用户编号")
     public Result delete(@PathVariable String identifier){