app_cat_controller.go 2.6 KB

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