lrf 8 mesi fa
parent
commit
90e4023a6d

+ 0 - 13
src/main/java/com/free/controller/ChatRecordController.java

@@ -18,7 +18,6 @@ import com.free.config.CustomizationException;
 import com.free.config.ExceptionEnum;
 import com.free.config.ExceptionEnum;
 import com.free.config.ResponseFormat;
 import com.free.config.ResponseFormat;
 import com.free.dto.ChatRecordCreateDTO;
 import com.free.dto.ChatRecordCreateDTO;
-import com.free.dto.ChatRecordToReadDTO;
 import com.free.entity.ChatRecord;
 import com.free.entity.ChatRecord;
 import com.free.entity.TransferApply;
 import com.free.entity.TransferApply;
 import com.free.mq.MqService;
 import com.free.mq.MqService;
@@ -40,16 +39,6 @@ public class ChatRecordController {
   @Autowired
   @Autowired
   private MqService mqService;
   private MqService mqService;
 
 
-  @ApiOperation("对话已读")
-  @PostMapping("/read")
-  public Object readMsg(@RequestBody ChatRecordToReadDTO body) {
-    ChatRecord updateData = new ChatRecord();
-    updateData.setIs_read(service.chatRecordReadSign);
-    QueryWrapper qw = new QueryWrapper<>();
-    qw.eq("apply_id", body.getApply_id());
-    return ResponseFormat.success();
-  }
-
   /** 创建数据 */
   /** 创建数据 */
   @PassToken
   @PassToken
   @ApiOperation("创建数据")
   @ApiOperation("创建数据")
@@ -131,8 +120,6 @@ public class ChatRecordController {
       List list = service.list(qw);
       List list = service.list(qw);
       returnList = service.getUserAndCustomerName(list);
       returnList = service.getUserAndCustomerName(list);
     }
     }
-    // 查询当前用户未读数量
-    returnList = service.getUserNotReadNum(returnList);
     map.put("data", returnList);
     map.put("data", returnList);
 
 
     return ResponseFormat.success(map);
     return ResponseFormat.success(map);

+ 2 - 0
src/main/java/com/free/controller/TransferApplyController.java

@@ -178,6 +178,8 @@ public class TransferApplyController {
     }
     }
     // 如果查询条件中有customer_id,客服id,需要查出其最后一条发言数据
     // 如果查询条件中有customer_id,客服id,需要查出其最后一条发言数据
     returnList = service.getDataLastRecord(returnList);
     returnList = service.getDataLastRecord(returnList);
+    // 查询当前用户的未读数量
+    returnList = service.getUserNotReadNum(returnList);
     map.put("data", returnList);
     map.put("data", returnList);
 
 
     return ResponseFormat.success(map);
     return ResponseFormat.success(map);

+ 64 - 0
src/main/java/com/free/schedule/ClearTransferApply.java

@@ -0,0 +1,64 @@
+package com.free.schedule;
+
+import java.util.List;
+import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.scheduling.annotation.EnableScheduling;
+import org.springframework.scheduling.annotation.Scheduled;
+import org.springframework.stereotype.Component;
+
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.free.controller.TransferApplyController;
+import com.free.entity.ChatRecord;
+import com.free.entity.TransferApply;
+import com.free.service.ChatRecordService;
+import com.free.service.TransferApplyService;
+
+import lombok.extern.slf4j.Slf4j;
+
+@Slf4j
+@Component
+@EnableScheduling
+public class ClearTransferApply {
+  @Autowired
+  private TransferApplyService transferApplyService;
+  @Autowired
+  private ChatRecordService chatRecordService;
+  /** 自动关闭时间: 10分钟 */
+  private Long limit = 10L;
+  // 每2分整执行一次
+  @Scheduled(cron = "0 0/2 * * * ? ")
+  public void schedule() {
+    DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
+    LocalDateTime nowTime = LocalDateTime.now();
+    String nowTimeStr = df.format(nowTime);
+    log.info("当前执行任务的线程号ID===>{}", Thread.currentThread().getId()); // 日志输出
+    log.info("当前执行任务时间===>{}", nowTimeStr); // 日志输出
+    // 查询受理但是没有结束的转人工申请
+    // QueryWrapper applyQw = new QueryWrapper<>();
+    // applyQw.eq("is_agree", TransferApplyController.TransferApplyAgree);
+    // applyQw.eq("is_close", TransferApplyController.TransferApplyNotClose);
+    // List<TransferApply> agreeNotCloseApplyList = transferApplyService.list(applyQw);
+    // // 查询这些没结束的转人工申请, 最后一次发言时间
+    // for (TransferApply i : agreeNotCloseApplyList) {
+    //   QueryWrapper chatRecordQw = new QueryWrapper<>();
+    //   chatRecordQw.eq("apply_id", i.getId());
+    //   chatRecordQw.orderByDesc("time");
+    //   ChatRecord chatRecord = chatRecordService.getOne(chatRecordQw);
+    //   LocalDateTime chat_time = chatRecord.getTime();
+    //   chat_time.plusMinutes(limit);
+    //   // 判断, 最后的发言时间 + 自动关闭时间的10分钟 是否在当前时间之前:
+    //   // 在当前时间之前: 不处理,未超时
+    //   // 不在当前时间之前: 超过自动关闭的时间,直接关闭
+    //   boolean isBefore = nowTime.isBefore(chat_time);
+    //   if (!isBefore) {
+    //     TransferApply closeData = new TransferApply();
+    //     closeData.setId(i.getId());
+    //     closeData.setIs_close(TransferApplyController.TransferApplyClose);
+    //     transferApplyService.updateById(closeData);
+    //   }
+    // }
+  }
+}

+ 0 - 34
src/main/java/com/free/service/ChatRecordService.java

@@ -2,12 +2,10 @@ package com.free.service;
 
 
 import com.free.entity.system.Customer;
 import com.free.entity.system.Customer;
 import com.free.service.system.CustomerService;
 import com.free.service.system.CustomerService;
-import com.free.utils.JwtUtil;
 import com.free.utils.Utils;
 import com.free.utils.Utils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.stereotype.Service;
 
 
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.free.entity.ChatRecord;
 import com.free.entity.ChatRecord;
 import com.free.mapper.ChatRecordMapper;
 import com.free.mapper.ChatRecordMapper;
@@ -22,39 +20,7 @@ public class ChatRecordService extends ServiceImpl<ChatRecordMapper, ChatRecord>
   @Autowired
   @Autowired
   private CustomerService customerService;
   private CustomerService customerService;
 
 
-  /** 对话记录未读标识 */
-  public static final String chatRecordNotReadSign = "0";
 
 
-  /** 对话记录已读标识 */
-  public static final String chatRecordReadSign = "1";
-
-  /**
-   * 查询当前用户查出的列表中的未读数量
-   * 
-   * @param list
-   * @return
-   */
-  public List<Map> getUserNotReadNum(List<Map> list) {
-    String token=null;
-    try {
-      token = JwtUtil.getToken();
-    }catch (Exception e){}
-    if (null == token) {
-      return list;
-    }
-    Map userInfo = JwtUtil.getDetails(null);
-    String user_id = (String) userInfo.get("id");
-    for (Map map : list) {
-      String apply_id = (String) map.get("apply_id");
-      QueryWrapper qw = new QueryWrapper<>();
-      qw.eq("apply_id", apply_id);
-      qw.eq("is_read", chatRecordNotReadSign);
-      qw.ne("speaker", user_id);
-      Long num = this.count(qw);
-      map.put("notRead", num);
-    }
-    return list;
-  }
 
 
   /**
   /**
    * 将列表中的客服id和用户io的数据取出来
    * 将列表中的客服id和用户io的数据取出来

+ 37 - 1
src/main/java/com/free/service/TransferApplyService.java

@@ -14,6 +14,7 @@ import com.free.entity.TransferApply;
 import com.free.entity.system.Customer;
 import com.free.entity.system.Customer;
 import com.free.mapper.TransferApplyMapper;
 import com.free.mapper.TransferApplyMapper;
 import com.free.service.system.CustomerService;
 import com.free.service.system.CustomerService;
+import com.free.utils.JwtUtil;
 import com.free.utils.Utils;
 import com.free.utils.Utils;
 
 
 @Service
 @Service
@@ -23,6 +24,12 @@ public class TransferApplyService extends ServiceImpl<TransferApplyMapper, Trans
   @Autowired
   @Autowired
   private ChatRecordService chatRecordService;
   private ChatRecordService chatRecordService;
 
 
+  /** 对话记录未读标识 */
+  public static final String chatRecordNotReadSign = "0";
+
+  /** 对话记录已读标识 */
+  public static final String chatRecordReadSign = "1";
+
   // @Autowired
   // @Autowired
   // private UserService userService
   // private UserService userService
   /**
   /**
@@ -51,6 +58,35 @@ public class TransferApplyService extends ServiceImpl<TransferApplyMapper, Trans
     return returnData;
     return returnData;
   }
   }
 
 
+  /**
+   * 查询当前用户查出的列表中的未读数量
+   * 
+   * @param list
+   * @return
+   */
+  public List<Map> getUserNotReadNum(List<Map> list) {
+    String token = null;
+    try {
+      token = JwtUtil.getToken();
+    } catch (Exception e) {
+    }
+    if (null == token) {
+      return list;
+    }
+    Map userInfo = JwtUtil.getDetails(null);
+    String user_id = (String) userInfo.get("id");
+    for (Map map : list) {
+      String apply_id = (String) map.get("id");
+      QueryWrapper qw = new QueryWrapper<>();
+      qw.eq("apply_id", apply_id);
+      qw.eq("is_read", chatRecordNotReadSign);
+      qw.ne("speaker", user_id);
+      Long num = this.count(qw);
+      map.put("notRead", num);
+    }
+    return list;
+  }
+
   /**
   /**
    * 获取每个转人工申请中聊天记录的最后一条
    * 获取每个转人工申请中聊天记录的最后一条
    * 
    * 
@@ -61,7 +97,7 @@ public class TransferApplyService extends ServiceImpl<TransferApplyMapper, Trans
     for (Map map : list) {
     for (Map map : list) {
       String apply_id = (String) map.get("id");
       String apply_id = (String) map.get("id");
       QueryWrapper qw = new QueryWrapper<>();
       QueryWrapper qw = new QueryWrapper<>();
-      qw.select("content", "time", "is_read","content_type");
+      qw.select("content", "time", "is_read", "content_type");
       qw.eq("apply_id", apply_id);
       qw.eq("apply_id", apply_id);
       qw.orderByDesc("time");
       qw.orderByDesc("time");
       Map chatRecord = chatRecordService.getMap(qw);
       Map chatRecord = chatRecordService.getMap(qw);