payShield.go 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. package dao
  2. import (
  3. "context"
  4. "go-common/app/service/openplatform/anti-fraud/model"
  5. "go-common/library/log"
  6. )
  7. const (
  8. _ipList = "select ip,count(1) as num from shield_ip_log where mtime >= ? group by ip order by num desc limit 50"
  9. _ipDetail = "select ip,uid from shield_ip_log where ip = ? and mtime >= ? and mtime <= ?"
  10. _uidList = "select uid,count(1) as num from shield_user_log where mtime >= ? group by uid order by num desc limit 50"
  11. _uidDetail = "select ip,uid from shield_user_log where uid = ? and mtime >= ? and mtime <= ?"
  12. )
  13. // ShieldIPList .
  14. func (d *Dao) ShieldIPList(c context.Context, mtime string) (res []*model.IPListDetail, err error) {
  15. res = make([]*model.IPListDetail, 0)
  16. rows, err := d.payShieldDb.Query(c, _ipList, mtime)
  17. if err != nil {
  18. log.Warn("select err %s %v", _ipList, err)
  19. return
  20. }
  21. for rows.Next() {
  22. r := new(model.IPListDetail)
  23. if err = rows.Scan(&r.IP, &r.Num); err != nil {
  24. log.Warn("scan err %v", err)
  25. return
  26. }
  27. res = append(res, r)
  28. }
  29. return
  30. }
  31. // ShieldIPDetail .
  32. func (d *Dao) ShieldIPDetail(c context.Context, ip, stime, etime string) (res []*model.ListDetail, err error) {
  33. res = make([]*model.ListDetail, 0)
  34. rows, err := d.payShieldDb.Query(c, _ipDetail, ip, stime, etime)
  35. if err != nil {
  36. log.Warn("select err %s %v", _ipDetail, err)
  37. return
  38. }
  39. for rows.Next() {
  40. r := new(model.ListDetail)
  41. if err = rows.Scan(&r.IP, &r.UID); err != nil {
  42. log.Warn("scan err %v", err)
  43. return
  44. }
  45. res = append(res, r)
  46. }
  47. return
  48. }
  49. // ShieldUIDList .
  50. func (d *Dao) ShieldUIDList(c context.Context, mtime string) (res []*model.UIDListDetail, err error) {
  51. res = make([]*model.UIDListDetail, 0)
  52. rows, err := d.payShieldDb.Query(c, _uidList, mtime)
  53. if err != nil {
  54. log.Warn("select err %s %v", _uidList, err)
  55. return
  56. }
  57. for rows.Next() {
  58. r := new(model.UIDListDetail)
  59. if err = rows.Scan(&r.UID, &r.Num); err != nil {
  60. log.Warn("scan err %v", err)
  61. return
  62. }
  63. res = append(res, r)
  64. }
  65. return
  66. }
  67. // ShieldUIDDetail .
  68. func (d *Dao) ShieldUIDDetail(c context.Context, uid, stime, etime string) (res []*model.ListDetail, err error) {
  69. res = make([]*model.ListDetail, 0)
  70. rows, err := d.payShieldDb.Query(c, _uidDetail, uid, stime, etime)
  71. if err != nil {
  72. log.Warn("select err %s %v", _uidDetail, err)
  73. return
  74. }
  75. for rows.Next() {
  76. r := new(model.ListDetail)
  77. if err = rows.Scan(&r.IP, &r.UID); err != nil {
  78. log.Warn("scan err %v", err)
  79. return
  80. }
  81. res = append(res, r)
  82. }
  83. return
  84. }