lrf 8 months ago
parent
commit
9888e55388

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

@@ -83,7 +83,7 @@ public class ChatRecordController {
     QueryWrapper qw = new QueryWrapper<>();
     qw.eq("id", data.getId());
     Map returnData = this.service.getMap(qw);
-    // TODO:发送mq消息,往chat.${apply_id}中发,客服和用户都会订阅这个
+    // 发送mq消息,往chat.${apply_id}中发,客服和用户都会订阅这个
     mqService.sendChatToApply(returnData);
     return ResponseFormat.success(returnData);
     // return ResponseFormat.success();

+ 7 - 4
src/main/java/com/free/controller/TransferApplyController.java

@@ -160,19 +160,22 @@ public class TransferApplyController {
      * 分页处理
      * TODO: 需要返回用户名称,客服名称
      */
+    List returnList = null;
     if (null != skip && null != limit) {
       IPage page = new Page<>(skip, limit);
       IPage pageResult = service.page(page, qw);
       List data = pageResult.getRecords();
-      List newData = service.getUserAndCustomerName(data);
+      returnList = service.getUserAndCustomerName(data);
       long total = pageResult.getTotal();
-      map.put("data", newData);
       map.put("total", total);
     } else {
       List list = service.list(qw);
-      List newData = service.getUserAndCustomerName(list);
-      map.put("data", newData);
+      returnList = service.getUserAndCustomerName(list);
     }
+    // 如果查询条件中有customer_id,客服id,需要查出其最后一条发言数据
+    returnList = service.getDataLastRecord(returnList);
+    map.put("data", returnList);
+
     return ResponseFormat.success(map);
   }
 

+ 2 - 0
src/main/java/com/free/mq/MqService.java

@@ -36,7 +36,9 @@ public class MqService {
     System.out.println(msg);
     String strMsg = null;
     ObjectMapper mapper = new ObjectMapper();
+    // 空值放过
     mapper.setSerializationInclusion(Include.NON_NULL);
+    // LocalDateTime处理
     JavaTimeModule jtmf = FormatJavaTimeModule.init();
     mapper.registerModule(jtmf);
     strMsg = mapper.writeValueAsString(msg);

+ 28 - 0
src/main/java/com/free/service/TransferApplyService.java

@@ -7,7 +7,9 @@ import java.util.Map;
 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.entity.TransferApply;
 import com.free.entity.system.Customer;
 import com.free.mapper.TransferApplyMapper;
@@ -18,6 +20,8 @@ import com.free.utils.Utils;
 public class TransferApplyService extends ServiceImpl<TransferApplyMapper, TransferApply> {
   @Autowired
   private CustomerService customerService;
+  @Autowired
+  private ChatRecordService chatRecordService;
 
   // @Autowired
   // private UserService userService
@@ -47,4 +51,28 @@ public class TransferApplyService extends ServiceImpl<TransferApplyMapper, Trans
     }
     return returnData;
   }
+
+  /**
+   * 获取每个转人工申请中聊天记录的最后一条
+   * 
+   * @param list
+   * @return
+   */
+  public List<Map> getDataLastRecord(List<Map> list) {
+    for (Map map : list) {
+      Long apply_id = Utils.getLongValue(map.get("id"));
+      QueryWrapper qw = new QueryWrapper<>();
+      qw.select("content", "time", "is_read");
+      qw.eq("apply_id", apply_id);
+      qw.orderByDesc("time");
+      Map chatRecord = chatRecordService.getMap(qw);
+      if (null == chatRecord) {
+        map.put("chatRecord", null);
+      } else {
+        map.put("chatRecord", chatRecord);
+      }
+    }
+
+    return list;
+  }
 }

+ 1 - 0
src/main/java/com/free/utils/FormatJavaTimeModule.java

@@ -8,6 +8,7 @@ import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
 import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
 
 public class FormatJavaTimeModule {
+  /** 对LocalDateTime进行格式化的 JavaTimeModule */
   public static JavaTimeModule init() {
     JavaTimeModule javaTimeModule = new JavaTimeModule();
     javaTimeModule.addSerializer(LocalDateTime.class,

+ 9 - 0
src/main/java/com/free/utils/Utils.java

@@ -92,4 +92,13 @@ public class Utils {
     }
     return null;
   }
+
+  public static Long getLongValue (Object value){
+    String str = String.valueOf(value);
+    if(null==str) {
+      return null;
+    }
+    Long l = Long.valueOf(str);
+    return l;
+  }
 }