callLog.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package service
  2. import (
  3. "log"
  4. "sfis/db"
  5. "sfis/model"
  6. "sfis/utils"
  7. "strings"
  8. "time"
  9. )
  10. func CallLog(appid, startTime, endTime string) ([]map[string]interface{}, error) {
  11. key := []string{}
  12. param := []interface{}{}
  13. datas := []map[string]interface{}{}
  14. if startTime != "" {
  15. key = append(key, "create_at >= ?")
  16. param = append(param, startTime+" 00:00:00")
  17. }
  18. if endTime != "" {
  19. key = append(key, "create_at <= ?")
  20. param = append(param, endTime+" 23:59:59")
  21. } else {
  22. key = append(key, "create_at <= ?")
  23. param = append(param, time.Now().Local().Format("2006-01-02 15:04:05"))
  24. }
  25. whereSql := strings.Join(key, " and ")
  26. log.Println("whereSql", whereSql)
  27. userCallRecord := []model.UserCallRecord{}
  28. err := db.GetSFISDB().Where(whereSql, param...).Where("app_id = ? ", appid).Find(&userCallRecord).Error
  29. if err != nil {
  30. return nil, err
  31. } else {
  32. for _, v := range userCallRecord {
  33. productname := ""
  34. if product, ok := utils.ProductCaches.Map.Load(v.ProductId); ok {
  35. productname = product.(*model.Product).Name
  36. }
  37. dataMap := map[string]interface{}{
  38. "app_id": v.AppID,
  39. "invok_time": v.CreateAt.Local().Format("2006-01-02 15:04:05"),
  40. "ip": v.Ip,
  41. "name": productname,
  42. }
  43. datas = append(datas, dataMap)
  44. }
  45. }
  46. return datas, nil
  47. }