handler_get_chat_log.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. //@Author : KaiShin
  2. //@Time : 2021/10/28
  3. package handler
  4. import (
  5. "call_center/db/rpc/internal/svc"
  6. "call_center/db/rpc/pb"
  7. "fmt"
  8. "log"
  9. )
  10. func GetChatLog(svcCtx *svc.ServiceContext, cmdMsg *pb.DbCommandMsg) *pb.DbCommandMsg {
  11. playerId := cmdMsg.CmdStr
  12. querySql := fmt.Sprintf(`select * from service_chat_visitor_log_r where sessionId = "%s" limit 100`, playerId)
  13. log.Println("<handler.HandleGetChatLog> querySql:", querySql)
  14. dataRes := svcCtx.Es.Query(querySql)
  15. if dataRes == nil {
  16. return &pb.DbCommandMsg{}
  17. }
  18. chatLogList := new(pb.ArrayDbChatLog)
  19. for _, v := range dataRes {
  20. data := v.(map[string]interface{})
  21. chatLogList.DataList = append(chatLogList.DataList, &pb.DbChatLog{
  22. GameId: int32(data["gameId"].(float64)),
  23. Content: data["content"].(string),
  24. FromId: data["fromId"].(string),
  25. ToId: data["toId"].(string),
  26. ChatType: pb.EDbChatType(data["chatType"].(float64)),
  27. SessionId: data["sessionId"].(string),
  28. // IsVisitor: data["isVisitor"].(bool),
  29. TimeStamp: int64(data["logDt"].(float64)),
  30. })
  31. }
  32. log.Println("<handler.GetChatLog>, data len: ", len(dataRes), " playerId:", playerId)
  33. return &pb.DbCommandMsg{Data: &pb.DbCommandMsg_ArrayChatLog{ArrayChatLog: chatLogList}}
  34. }