net.go 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. package http
  2. import (
  3. "strconv"
  4. "go-common/app/admin/main/aegis/model/common"
  5. "go-common/app/admin/main/aegis/model/net"
  6. "go-common/library/ecode"
  7. bm "go-common/library/net/http/blademaster"
  8. )
  9. func listNet(c *bm.Context) {
  10. pm := new(net.ListNetParam)
  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. c.JSON(srv.GetNetList(c, pm))
  19. }
  20. func getNetByBusiness(c *bm.Context) {
  21. pm := c.Request.Form.Get("business_id")
  22. nid, err := strconv.ParseInt(pm, 10, 64)
  23. if err != nil || nid <= 0 {
  24. c.JSON(nil, ecode.RequestErr)
  25. return
  26. }
  27. c.JSON(srv.GetNetByBusiness(c, nid))
  28. }
  29. func showNet(c *bm.Context) {
  30. pm := c.Request.Form.Get("id")
  31. nid, err := strconv.ParseInt(pm, 10, 64)
  32. if err != nil {
  33. c.JSON(nil, ecode.RequestErr)
  34. return
  35. }
  36. c.JSON(srv.ShowNet(c, nid))
  37. }
  38. func addNet(c *bm.Context) {
  39. pm := new(net.Net)
  40. if err := c.Bind(pm); err != nil || pm.BusinessID <= 0 {
  41. c.JSON(nil, ecode.RequestErr)
  42. return
  43. }
  44. pm.ChName = common.FilterChname(pm.ChName)
  45. if pm.ChName == "" {
  46. c.JSON(nil, ecode.RequestErr)
  47. return
  48. }
  49. pm.UID = uid(c)
  50. id, err, msg := srv.AddNet(c, pm)
  51. c.JSONMap(map[string]interface{}{
  52. "id": id,
  53. "message": msg,
  54. }, err)
  55. }
  56. func updateNet(c *bm.Context) {
  57. pm := new(net.NetEditParam)
  58. if err := c.Bind(pm); err != nil || pm.ID <= 0 {
  59. c.JSON(nil, ecode.RequestErr)
  60. return
  61. }
  62. pm.ChName = common.FilterChname(pm.ChName)
  63. if pm.ChName == "" {
  64. c.JSON(nil, ecode.RequestErr)
  65. return
  66. }
  67. admin := uid(c)
  68. err, msg := srv.UpdateNet(c, admin, pm)
  69. c.JSONMap(map[string]interface{}{
  70. "message": msg,
  71. }, err)
  72. }
  73. func switchNet(c *bm.Context) {
  74. pm := new(net.SwitchParam)
  75. if err := c.Bind(pm); err != nil {
  76. c.JSON(nil, ecode.RequestErr)
  77. return
  78. }
  79. c.JSON(nil, srv.SwitchNet(c, pm.ID, pm.Disable))
  80. }