商品rpc数据格式及调用方法
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

73 lines
1.1 KiB

  1. package productrpc
  2. import (
  3. "log"
  4. "sort"
  5. "strconv"
  6. "testing"
  7. )
  8. func Test_GetAllActivity(t *testing.T) {
  9. // dbname := "shop_v2"
  10. // id := "10248"
  11. // site_id := "10248"
  12. // sku_id := "10248"
  13. // ret, err := GetAllActivity(site_id, dbname, id, sku_id)
  14. // t.Log(ret)
  15. // t.Log(err)
  16. res_arr := []map[string]string{
  17. map[string]string{
  18. "Id": "55",
  19. "Starttime": "19852365",
  20. },
  21. map[string]string{
  22. "Id": "22",
  23. "Starttime": "17852365",
  24. },
  25. map[string]string{
  26. "Id": "11",
  27. "Starttime": "18852365",
  28. },
  29. }
  30. t.Log(res_arr)
  31. var activitys Activitys
  32. var err error
  33. if len(res_arr) > 0 {
  34. var start int
  35. for _, item := range res_arr {
  36. start, err = strconv.Atoi(item["Starttime"])
  37. if err != nil {
  38. log.Println(err)
  39. }
  40. activitys = append(activitys, Activity{
  41. Id: item["Id"],
  42. Start: start,
  43. })
  44. }
  45. }
  46. sort.Sort(activitys)
  47. t.Log(activitys)
  48. var list []map[string]string = make([]map[string]string, 0)
  49. if len(activitys) > 0 {
  50. for _, v := range activitys {
  51. for _, old := range res_arr {
  52. if v.Id == old["Id"] {
  53. list = append(list, old)
  54. break
  55. }
  56. }
  57. }
  58. }
  59. t.Log(list)
  60. }