business.go 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. package http
  2. import (
  3. "net/http"
  4. "net/url"
  5. "strings"
  6. "go-common/app/admin/main/workflow/model/param"
  7. "go-common/library/ecode"
  8. bm "go-common/library/net/http/blademaster"
  9. "go-common/library/net/http/blademaster/binding"
  10. "go-common/library/net/http/blademaster/render"
  11. )
  12. func busMetaList(ctx *bm.Context) {
  13. req := ctx.Request
  14. itemType := req.Form.Get("item_type")
  15. ctx.JSON(wkfSvc.ListMeta(ctx, itemType))
  16. }
  17. func listBusAttr(ctx *bm.Context) {
  18. ctx.JSON(wkfSvc.ListBusAttr(ctx))
  19. }
  20. func listBusAttrV3(ctx *bm.Context) {
  21. ctx.JSON(wkfSvc.ListBusAttrV3(ctx))
  22. }
  23. func addOrUpdateBusAttr(ctx *bm.Context) {
  24. abap := &param.AddBusAttrParam{}
  25. if err := ctx.BindWith(abap, binding.FormPost); err != nil {
  26. return
  27. }
  28. ctx.JSON(nil, wkfSvc.AddOrUpdateBusAttr(ctx, abap))
  29. }
  30. func setSwitch(ctx *bm.Context) {
  31. bs := new(param.BusAttrButtonSwitch)
  32. if err := ctx.BindWith(bs, binding.FormPost); err != nil {
  33. return
  34. }
  35. ctx.JSON(nil, wkfSvc.SetSwitch(ctx, bs))
  36. }
  37. func setShortCut(ctx *bm.Context) {
  38. sc := new(param.BusAttrButtonShortCut)
  39. if err := ctx.BindWith(sc, binding.FormPost); err != nil {
  40. return
  41. }
  42. if len(sc.ShortCut) != 1 { // only support char
  43. ctx.Render(http.StatusOK, render.JSON{
  44. Code: ecode.RequestErr.Code(),
  45. Message: "short cut only length 1",
  46. Data: nil,
  47. })
  48. ctx.Abort()
  49. return
  50. }
  51. sc.ShortCut = strings.ToUpper(sc.ShortCut)
  52. ctx.JSON(nil, wkfSvc.SetShortCut(ctx, sc))
  53. }
  54. func setExtAPI(ctx *bm.Context) {
  55. ea := new(param.BusAttrExtAPI)
  56. if err := ctx.BindWith(ea, binding.FormPost); err != nil {
  57. return
  58. }
  59. if ea.ExternalAPI != "" {
  60. if _, err := url.Parse(ea.ExternalAPI); err != nil {
  61. ctx.Render(http.StatusOK, render.JSON{
  62. Code: ecode.RequestErr.Code(),
  63. Message: err.Error(),
  64. Data: nil,
  65. })
  66. ctx.Abort()
  67. return
  68. }
  69. }
  70. ctx.JSON(nil, wkfSvc.SetExtAPI(ctx, ea))
  71. }
  72. func mngTag(ctx *bm.Context) {
  73. ctx.JSON(wkfSvc.ManagerTag(ctx))
  74. }
  75. func userBlockInfo(ctx *bm.Context) {
  76. bi := new(param.BlockInfo)
  77. if err := ctx.Bind(bi); err != nil {
  78. return
  79. }
  80. ctx.JSON(wkfSvc.UserBlockInfo(ctx, bi))
  81. }
  82. func srcList(ctx *bm.Context) {
  83. src := new(param.Source)
  84. if err := ctx.Bind(src); err != nil {
  85. return
  86. }
  87. ctx.JSON(wkfSvc.SourceList(ctx, src))
  88. }