|
@@ -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")
|