group_cat_controller.go 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. package controllers
  2. import (
  3. "github.com/kataras/iris/v12/mvc"
  4. "xps/datamodels"
  5. "xps/service/system"
  6. )
  7. type GroupCatController struct {
  8. Base
  9. Service system.GroupCatService
  10. }
  11. func (c *GroupCatController) BeforeActivation(b mvc.BeforeActivation) {
  12. b.Handle("GET", "/", "GetList" )
  13. b.Handle("GET", "/page", "GetPage" )
  14. b.Handle("GET", "/{groupCatId:int64}", "GetById" )
  15. b.Handle("POST", "/add", "Create" )
  16. b.Handle("PUT", "/update", "Update" )
  17. b.Handle("DELETE", "/{groupCatId:int64}", "DeleteByID")
  18. }
  19. func (c *GroupCatController) GetList() *JsonResult {
  20. params := c.buildParams()
  21. data, err := c.Service.GetList(params)
  22. if err != nil {
  23. return ResultErr(err.Error(), nil)
  24. } else {
  25. return ResultOk("获取成功", data)
  26. }
  27. }
  28. func (c *GroupCatController) GetPage() *JsonResult {
  29. params := c.buildParams()
  30. data, err := c.Service.GetPage(params)
  31. if err != nil {
  32. return ResultErr(err.Error(), nil)
  33. } else {
  34. return ResultOk("获取成功", data)
  35. }
  36. }
  37. func (c *GroupCatController) GetById(groupCatId int64) *JsonResult {
  38. ocId := c.GetCurOcId()
  39. data, err := c.Service.GetById(ocId, groupCatId)
  40. if err != nil {
  41. return ResultErr(err.Error(), nil)
  42. } else {
  43. return ResultOk("获取成功", data)
  44. }
  45. }
  46. func (c *GroupCatController) Create() *JsonResult {
  47. ocId := c.GetCurOcId()
  48. userId := c.GetCurUserId()
  49. groupCat := datamodels.GroupCat{}
  50. if err := c.Ctx.ReadJSON(&groupCat); err != nil {
  51. return ResultErr("读取数据失败", nil)
  52. }
  53. groupCat.OcId = ocId
  54. groupCat.CreatedBy = userId
  55. err := c.Service.Create(&groupCat)
  56. if err != nil {
  57. return ResultErr(err.Error(), nil)
  58. } else {
  59. return ResultOk("新增成功", nil)
  60. }
  61. }
  62. func (c *GroupCatController) Update() *JsonResult {
  63. ocId := c.GetCurOcId()
  64. userId := c.GetCurUserId()
  65. groupCat := datamodels.GroupCat{}
  66. if err := c.Ctx.ReadJSON(&groupCat); err != nil {
  67. return ResultErr("读取数据失败", nil)
  68. }
  69. groupCat.OcId = ocId
  70. groupCat.UpdatedBy = userId
  71. err := c.Service.Update(&groupCat)
  72. if err != nil {
  73. return ResultErr(err.Error(), nil)
  74. } else {
  75. return ResultOk("更新成功", nil)
  76. }
  77. }
  78. func (c *GroupCatController) DeleteByID(groupCatId int64) *JsonResult {
  79. ocId := c.GetCurOcId()
  80. userId := c.GetCurUserId()
  81. m := make(map[string]interface{})
  82. m["ocId"] = ocId
  83. m["groupCatId"] = groupCatId
  84. m["deletedBy"] = userId
  85. err := c.Service.Delete(m)
  86. if err != nil {
  87. return ResultErr(err.Error(), nil)
  88. } else {
  89. return ResultOk("删除成功", nil)
  90. }
  91. }