lrf 8 ماه پیش
والد
کامیت
b850bfbcc6

+ 2 - 1
src/main/java/com/free/controller/ChatRecordController.java

@@ -9,7 +9,6 @@ import javax.validation.Valid;
 
 import com.free.annotation.PassToken;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.DeleteMapping;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.PathVariable;
 import org.springframework.web.bind.annotation.PostMapping;
@@ -142,6 +141,8 @@ public class ChatRecordController {
       List list = service.list(qw);
       returnList = service.getUserAndCustomerName(list);
     }
+    // 查询当前用户未读数量
+    returnList = service.getUserNotReadNum(returnList);
     map.put("data", returnList);
 
     return ResponseFormat.success(map);

+ 50 - 26
src/main/java/com/free/service/ChatRecordService.java

@@ -1,12 +1,13 @@
 package com.free.service;
 
-import com.free.entity.TransferApply;
 import com.free.entity.system.Customer;
 import com.free.service.system.CustomerService;
+import com.free.utils.JwtUtil;
 import com.free.utils.Utils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.free.entity.ChatRecord;
 import com.free.mapper.ChatRecordMapper;
@@ -18,33 +19,56 @@ import java.util.Map;
 @Service
 public class ChatRecordService extends ServiceImpl<ChatRecordMapper, ChatRecord> {
 
-    @Autowired
-    private CustomerService customerService;
-
-    /**
-     * 将列表中的客服id和用户io的数据取出来
-     *
-     * @param list
-     * @return
-     */
-    public List<Map> getUserAndCustomerName(List<ChatRecord> list) {
-        List<Map> returnData = new ArrayList<>();
-        for (ChatRecord i : list) {
-            Map map = Utils.objectToMap(i);
-            String customer_id = i.getCustomer_id();
-            if (null != customer_id) {
-                Customer cData = customerService.getById(customer_id);
-                if (null != cData) {
-                    map.put("customer_name", cData.getNick_name());
-                }
-            }
-            // TODO:查询用户名称
-            map.put("user_name", "还没有呢");
-
-            returnData.add(map);
+  @Autowired
+  private CustomerService customerService;
 
+  /** 对话记录未读标识 */
+  public static final String chatRecordNotReadSign = "0";
+
+  /**
+   * 查询当前用户查出的列表中的未读数量
+   * @param list
+   * @return
+   */
+  public List<Map> getUserNotReadNum(List<Map> 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的数据取出来
+   *
+   * @param list
+   * @return
+   */
+  public List<Map> getUserAndCustomerName(List<ChatRecord> list) {
+    List<Map> returnData = new ArrayList<>();
+    for (ChatRecord i : list) {
+      Map map = Utils.objectToMap(i);
+      String customer_id = i.getCustomer_id();
+      if (null != customer_id) {
+        Customer cData = customerService.getById(customer_id);
+        if (null != cData) {
+          map.put("customer_name", cData.getNick_name());
         }
-        return returnData;
+      }
+      // TODO:查询用户名称
+      map.put("user_name", "还没有呢");
+
+      returnData.add(map);
+
     }
+    return returnData;
+  }
 
 }