search2_test.go 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. package dao
  2. import (
  3. "context"
  4. "fmt"
  5. "math"
  6. "strconv"
  7. "testing"
  8. "time"
  9. "go-common/app/admin/main/workflow/model"
  10. "go-common/app/admin/main/workflow/model/search"
  11. "github.com/smartystreets/goconvey/convey"
  12. )
  13. func TestSearchAuditLogGroup(t *testing.T) {
  14. convey.Convey("SearchAuditLogGroup", t, func() {
  15. cond := &search.AuditLogGroupSearchCond{
  16. Group: []string{"oid"},
  17. Businesses: []int64{3},
  18. Order: "ctime",
  19. PS: 1000,
  20. PN: 1,
  21. Sort: "desc",
  22. //Oids: []int64{24648472, 24694284, 24706061, 24583668, 24703363},
  23. Oids: []int64{10110151},
  24. }
  25. result, err := d.SearchAuditLogGroup(context.TODO(), cond)
  26. convey.So(err, convey.ShouldBeNil)
  27. convey.So(result, convey.ShouldNotBeEmpty)
  28. fmt.Println(len(result.Data.Result))
  29. fmt.Println(result.Data.Result)
  30. })
  31. }
  32. func TestSearchChallengeMultiPage(t *testing.T) {
  33. convey.Convey("SearchChallengeMultiPage", t, func() {
  34. cond := &search.ChallSearchCommonCond{
  35. Fields: []string{"id", "gid", "mid", "state", "ctime"},
  36. //IDs: []int64{1869, 1872},
  37. IDs: []int64{1967, 1966, 1960},
  38. }
  39. result, err := d.SearchChallengeMultiPage(context.TODO(), cond)
  40. convey.So(err, convey.ShouldBeNil)
  41. fmt.Println("len", len(result))
  42. for _, c := range result {
  43. tc := &model.TinyChall{
  44. Cid: c.ID,
  45. Gid: c.Gid,
  46. Mid: c.Mid,
  47. }
  48. var t time.Time
  49. if t, err = time.Parse("2006-01-02 15:04:05", c.CTime); err != nil {
  50. fmt.Printf("time.Parse() error(%v)\n", err)
  51. }
  52. if err = tc.CTime.Scan(t); err != nil {
  53. fmt.Printf("xtime.Scan() error(%v)\n", err)
  54. }
  55. if str, ok := c.State.(string); ok {
  56. st, _ := strconv.Atoi(str)
  57. tc.State = int8(st)
  58. }
  59. if f, ok := c.State.(float64); ok {
  60. tc.State = int8(math.Floor(f))
  61. }
  62. fmt.Printf("%+v\n", tc)
  63. }
  64. })
  65. }
  66. func TestSearchWorkflowReportLog(t *testing.T) {
  67. convey.Convey("SearchWkf", t, func() {
  68. cond := &search.AuditReportSearchCond{
  69. AppID: search.LogAuditAction,
  70. Fields: []string{"uname", "extra_data"},
  71. Business: 11,
  72. Order: "ctime",
  73. Sort: "desc",
  74. UID: []int64{6},
  75. }
  76. result, err := d.SearchAuditReportLog(context.TODO(), cond)
  77. convey.So(err, convey.ShouldBeNil)
  78. convey.So(result, convey.ShouldNotBeEmpty)
  79. fmt.Println(len(result.Result))
  80. fmt.Printf("%+v\n", result.Result[0])
  81. })
  82. }
  83. func TestSearchArchiveReportLog(t *testing.T) {
  84. convey.Convey("SearchArc", t, func() {
  85. cond := &search.AuditReportSearchCond{
  86. AppID: search.LogAuditAction,
  87. Fields: []string{"oid", "ctime"},
  88. IndexTimeType: "month",
  89. IndexTimeFrom: time.Now().AddDate(0, -6, 0),
  90. IndexTimeEnd: time.Now(),
  91. Business: 3,
  92. Order: "ctime",
  93. Sort: "desc",
  94. Oid: []int64{1},
  95. Distinct: "oid",
  96. }
  97. result, err := d.SearchAuditReportLog(context.TODO(), cond)
  98. convey.So(err, convey.ShouldBeNil)
  99. convey.So(result, convey.ShouldNotBeEmpty)
  100. })
  101. }