dw_mini.go 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. package dwmini
  2. import (
  3. "encoding/json"
  4. "errors"
  5. "eta/eta_chart_lib/models"
  6. "eta/eta_chart_lib/services/alarm_msg"
  7. "eta/eta_chart_lib/utils"
  8. )
  9. type MyChartIsCollect struct {
  10. IsCollect bool
  11. }
  12. type BaseResponse struct {
  13. Ret int
  14. Msg string
  15. ErrMsg string
  16. ErrCode string
  17. Data MyChartIsCollect
  18. }
  19. type MyChartIsCollectReq struct {
  20. UniqueCode string
  21. }
  22. type MyChartCollectReq struct {
  23. UniqueCode string
  24. ChartName string
  25. ChartImage string
  26. ChartInfoId int
  27. }
  28. type MyChartCollectCancelReq struct {
  29. UniqueCode string
  30. }
  31. func GetMyChartIsCollect(token string, uniqueCode string) (isCollect bool, err error) {
  32. url := utils.ETA_MINI_URL + "mychart/isCollect"
  33. req := MyChartIsCollectReq{UniqueCode: uniqueCode}
  34. reqBody, _ := json.Marshal(req)
  35. result, err := HttpPost(url, string(reqBody), token)
  36. if err != nil {
  37. return
  38. }
  39. var resp BaseResponse
  40. if err = json.Unmarshal(result, &resp); err != nil {
  41. return
  42. }
  43. if resp.Ret != 200 {
  44. err = errors.New(resp.ErrMsg)
  45. return
  46. }
  47. isCollect = resp.Data.IsCollect
  48. return
  49. }
  50. func MyChartCollect(token, uniqueCode, chartName, chartImage string, chartInfoId int) (resp *models.BaseResponse, err error) {
  51. url := utils.ETA_MINI_URL + "mychart/collect"
  52. req := MyChartCollectReq{
  53. UniqueCode: uniqueCode,
  54. ChartName: chartName,
  55. ChartImage: chartImage,
  56. ChartInfoId: chartInfoId,
  57. }
  58. reqBody, _ := json.Marshal(req)
  59. result, err := HttpPost(url, string(reqBody), token)
  60. if err != nil {
  61. return
  62. }
  63. alarm_msg.SendAlarmMsg(string(reqBody), 1)
  64. if err = json.Unmarshal(result, &resp); err != nil {
  65. return
  66. }
  67. if resp.Ret != 200 {
  68. return
  69. }
  70. return
  71. }
  72. func MyChartCollectCancel(token string, uniqueCode string) (resp *models.BaseResponse, err error) {
  73. url := utils.ETA_MINI_URL + "mychart/collectCancel"
  74. req := MyChartCollectCancelReq{UniqueCode: uniqueCode}
  75. reqBody, _ := json.Marshal(req)
  76. result, err := HttpPost(url, string(reqBody), token)
  77. if err != nil {
  78. return
  79. }
  80. if err = json.Unmarshal(result, &resp); err != nil {
  81. return
  82. }
  83. if resp.Ret != 200 {
  84. return
  85. }
  86. return
  87. }