dataplatform.go 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. package http
  2. import (
  3. "context"
  4. "encoding/json"
  5. "strconv"
  6. "time"
  7. "go-common/app/admin/main/push/model"
  8. pushmdl "go-common/app/service/main/push/model"
  9. "go-common/library/ecode"
  10. "go-common/library/log"
  11. bm "go-common/library/net/http/blademaster"
  12. )
  13. func addDPTask(ctx *bm.Context) {
  14. task := &model.DPTask{}
  15. if err := ctx.Bind(task); err != nil {
  16. return
  17. }
  18. if err := parseDpTask(task); err != nil {
  19. ctx.JSON(nil, ecode.RequestErr)
  20. return
  21. }
  22. ctx.JSON(nil, pushSrv.AddDPTask(context.Background(), task))
  23. }
  24. func parseDpTask(task *model.DPTask) (err error) {
  25. if task.ActivePeriodStr != "" {
  26. if err = json.Unmarshal([]byte(task.ActivePeriodStr), &task.ActivePeriods); err != nil {
  27. log.Error("parse ActivePeriod(%s) error(%v)", task.ActivePeriodStr, err)
  28. return
  29. }
  30. }
  31. if task.VipExpireStr != "" {
  32. if err = json.Unmarshal([]byte(task.VipExpireStr), &task.VipExpires); err != nil {
  33. log.Error("parse VipExpire(%s) error(%v)", task.VipExpireStr, err)
  34. return
  35. }
  36. }
  37. if task.AttentionStr != "" {
  38. if err = json.Unmarshal([]byte(task.AttentionStr), &task.Attentions); err != nil {
  39. log.Error("parse Attention(%s) error(%v)", task.AttentionStr, err)
  40. return
  41. }
  42. }
  43. task.PushTime = time.Unix(task.PushTimeUnix, 0)
  44. task.ExpireTime = time.Unix(task.ExpireTimeUnix, 0)
  45. task.Job = strconv.FormatInt(pushmdl.JobName(time.Now().UnixNano(), task.Summary, task.LinkValue, task.Group), 10)
  46. task.Status = int(pushmdl.TaskStatusPending)
  47. extra, _ := json.Marshal(pushmdl.TaskExtra{Group: task.Group})
  48. task.Extra = string(extra)
  49. return
  50. }
  51. func dpTaskInfo(ctx *bm.Context) {
  52. task := new(model.Task)
  53. if err := ctx.Bind(task); err != nil {
  54. return
  55. }
  56. id, _ := strconv.ParseInt(task.ID, 10, 64)
  57. if id < 1 {
  58. ctx.JSON(nil, ecode.RequestErr)
  59. return
  60. }
  61. ctx.JSON(pushSrv.DpTaskInfo(ctx, id, task.Job))
  62. }
  63. func checkDpData(ctx *bm.Context) {
  64. ctx.JSON(nil, pushSrv.CheckDpData(ctx))
  65. }