syscategory.go 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. package syscategory
  2. import (
  3. "github.com/gin-gonic/gin"
  4. "github.com/gin-gonic/gin/binding"
  5. "device-manage/app/admin/models"
  6. "device-manage/tools"
  7. "device-manage/tools/app"
  8. "device-manage/tools/app/msg"
  9. )
  10. func GetSysCategoryList(c *gin.Context) {
  11. var data models.SysCategory
  12. var err error
  13. var pageSize = 10
  14. var pageIndex = 1
  15. if size := c.Request.FormValue("pageSize"); size != "" {
  16. pageSize, err = tools.StringToInt(size)
  17. }
  18. if index := c.Request.FormValue("pageIndex"); index != "" {
  19. pageIndex, err = tools.StringToInt(index)
  20. }
  21. data.Name = c.Request.FormValue("name")
  22. data.Status = c.Request.FormValue("status")
  23. data.DataScope = tools.GetUserIdStr(c)
  24. result, count, err := data.GetPage(pageSize, pageIndex)
  25. tools.HasError(err, "", -1)
  26. app.PageOK(c, result, count, pageIndex, pageSize, "")
  27. }
  28. func GetSysCategory(c *gin.Context) {
  29. var data models.SysCategory
  30. data.Id, _ = tools.StringToInt(c.Param("id"))
  31. result, err := data.Get()
  32. tools.HasError(err, "抱歉未找到相关信息", -1)
  33. app.OK(c, result, "")
  34. }
  35. // @Summary 添加分类
  36. // @Description 获取JSON
  37. // @Tags 分类
  38. // @Accept application/json
  39. // @Product application/json
  40. // @Param data body models.SysCategory true "data"
  41. // @Success 200 {string} string "{"code": 200, "message": "添加成功"}"
  42. // @Success 200 {string} string "{"code": -1, "message": "添加失败"}"
  43. // @Router /api/v1/syscategory [post]
  44. func InsertSysCategory(c *gin.Context) {
  45. var data models.SysCategory
  46. err := c.ShouldBindJSON(&data)
  47. data.CreateBy = tools.GetUserIdStr(c)
  48. tools.HasError(err, "", 500)
  49. result, err := data.Create()
  50. tools.HasError(err, "", -1)
  51. app.OK(c, result, "")
  52. }
  53. func UpdateSysCategory(c *gin.Context) {
  54. var data models.SysCategory
  55. err := c.BindWith(&data, binding.JSON)
  56. tools.HasError(err, "数据解析失败", -1)
  57. data.UpdateBy = tools.GetUserIdStr(c)
  58. result, err := data.Update(data.Id)
  59. tools.HasError(err, "", -1)
  60. app.OK(c, result, "")
  61. }
  62. func DeleteSysCategory(c *gin.Context) {
  63. var data models.SysCategory
  64. data.UpdateBy = tools.GetUserIdStr(c)
  65. IDS := tools.IdsStrToIdsIntGroup("id", c)
  66. _, err := data.BatchDelete(IDS)
  67. tools.HasError(err, msg.DeletedFail, 500)
  68. app.OK(c, nil, msg.DeletedSuccess)
  69. }