direction.go 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. package http
  2. import (
  3. "strconv"
  4. "go-common/app/admin/main/aegis/model/net"
  5. "go-common/library/ecode"
  6. "go-common/library/log"
  7. bm "go-common/library/net/http/blademaster"
  8. )
  9. func listDirection(c *bm.Context) {
  10. pm := new(net.ListDirectionParam)
  11. if err := c.Bind(pm); err != nil {
  12. c.JSON(nil, ecode.RequestErr)
  13. return
  14. }
  15. if pm.Sort != "desc" && pm.Sort != "asc" {
  16. pm.Sort = "desc"
  17. }
  18. //direction只有在确立了flow_id/transition_id后才能选择
  19. if pm.FlowID == 0 && pm.TransitionID == 0 {
  20. pm.Direction = 0
  21. }
  22. c.JSON(srv.GetDirectionList(c, pm))
  23. }
  24. func showDirection(c *bm.Context) {
  25. pm := c.Request.Form.Get("id")
  26. id, err := strconv.ParseInt(pm, 10, 64)
  27. if err != nil {
  28. c.JSON(nil, ecode.RequestErr)
  29. return
  30. }
  31. c.JSON(srv.ShowDirection(c, id))
  32. }
  33. func preDir(pm *net.DirEditParam) (invalid bool) {
  34. if pm.Direction == net.DirInput && pm.Output != "" {
  35. pm.Output = ""
  36. }
  37. invalid = pm.Order == net.DirOrderOrSplit && pm.Guard == ""
  38. return
  39. }
  40. func addDirection(c *bm.Context) {
  41. pm := new(net.DirEditParam)
  42. if err := c.Bind(pm); err != nil || pm.NetID <= 0 {
  43. c.JSON(nil, ecode.RequestErr)
  44. return
  45. }
  46. if preDir(pm) {
  47. c.JSON(nil, ecode.RequestErr)
  48. return
  49. }
  50. admin := uid(c)
  51. id, err, msg := srv.AddDirection(c, admin, pm)
  52. c.JSONMap(map[string]interface{}{
  53. "id": id,
  54. "message": msg,
  55. }, err)
  56. }
  57. func updateDirection(c *bm.Context) {
  58. pm := new(net.DirEditParam)
  59. if err := c.Bind(pm); err != nil || pm.ID <= 0 {
  60. log.Error("updateDirection bind error(%+v)", err)
  61. c.JSON(nil, ecode.RequestErr)
  62. return
  63. }
  64. if preDir(pm) {
  65. c.JSON(nil, ecode.RequestErr)
  66. return
  67. }
  68. admin := uid(c)
  69. err, msg := srv.UpdateDirection(c, admin, pm)
  70. c.JSONMap(map[string]interface{}{
  71. "message": msg,
  72. }, err)
  73. }
  74. func switchDirection(c *bm.Context) {
  75. pm := new(net.SwitchParam)
  76. if err := c.Bind(pm); err != nil {
  77. c.JSON(nil, ecode.RequestErr)
  78. return
  79. }
  80. err, msg := srv.SwitchDirection(c, pm.ID, pm.Disable)
  81. c.JSONMap(map[string]interface{}{
  82. "message": msg,
  83. }, err)
  84. }