event.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. package http
  2. import (
  3. "strconv"
  4. "go-common/app/admin/main/workflow/model/param"
  5. "go-common/library/ecode"
  6. "go-common/library/log"
  7. bm "go-common/library/net/http/blademaster"
  8. "go-common/library/net/http/blademaster/binding"
  9. )
  10. func addEvent(ctx *bm.Context) {
  11. ep := &param.EventParam{}
  12. if err := ctx.BindWith(ep, binding.JSON); err != nil {
  13. return
  14. }
  15. if !ep.ValidComponent() {
  16. ctx.JSON(nil, ecode.RequestErr)
  17. return
  18. }
  19. eid, err := wkfSvc.AddEvent(ctx, ep)
  20. if err != nil {
  21. log.Error("wkfSvc.AddEvent(%v) error(%v)", ep, err)
  22. ctx.JSON(nil, ecode.RequestErr)
  23. return
  24. }
  25. ctx.JSON(map[string]int64{
  26. "eventNo": eid,
  27. }, nil)
  28. }
  29. func batchAddEvent(ctx *bm.Context) {
  30. bep := &param.BatchEventParam{}
  31. if err := ctx.BindWith(bep, binding.JSON); err != nil {
  32. return
  33. }
  34. if !bep.ValidComponent() {
  35. ctx.JSON(nil, ecode.RequestErr)
  36. return
  37. }
  38. eids, err := wkfSvc.BatchAddEvent(ctx, bep)
  39. if err != nil {
  40. log.Error("wkfSvc.BatchAddEvent(%v) error(%v)", bep, err)
  41. ctx.JSON(nil, ecode.RequestErr)
  42. return
  43. }
  44. ctx.JSON(map[string][]int64{
  45. "eventNo": eids,
  46. }, nil)
  47. }
  48. func eventList(ctx *bm.Context) {
  49. params := ctx.Request.Form
  50. cidStr := params.Get("cid")
  51. // check params
  52. cid, err := strconv.ParseInt(cidStr, 10, 32)
  53. if err != nil {
  54. log.Error("strconv.ParseInt(%s) error(%v)", cidStr, err)
  55. ctx.JSON(nil, ecode.RequestErr)
  56. return
  57. }
  58. ctx.JSON(wkfSvc.ListEvent(ctx, cid))
  59. }