dir.go 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. package sysfiledir
  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 GetSysFileDirList(c *gin.Context) {
  11. var SysFileDir models.SysFileDir
  12. SysFileDir.Label = c.Request.FormValue("label")
  13. SysFileDir.PId, _ = tools.StringToInt(c.Request.FormValue("pid"))
  14. SysFileDir.Id, _ = tools.StringToInt(c.Request.FormValue("id"))
  15. SysFileDir.DataScope = tools.GetUserIdStr(c)
  16. result, err := SysFileDir.SetSysFileDir()
  17. tools.HasError(err, "抱歉未找到相关信息", -1)
  18. app.OK(c, result, "")
  19. }
  20. func GetSysFileDir(c *gin.Context) {
  21. var data models.SysFileDir
  22. data.Id, _ = tools.StringToInt(c.Param("id"))
  23. result, err := data.Get()
  24. tools.HasError(err, "抱歉未找到相关信息", -1)
  25. app.OK(c, result, "")
  26. }
  27. // @Summary 添加SysFileDir
  28. // @Description 获取JSON
  29. // @Tags SysFileDir
  30. // @Accept application/json
  31. // @Product application/json
  32. // @Param data body models.SysFileDir true "data"
  33. // @Success 200 {string} string "{"code": 200, "message": "添加成功"}"
  34. // @Success 200 {string} string "{"code": -1, "message": "添加失败"}"
  35. // @Router /api/v1/sysfiledir [post]
  36. func InsertSysFileDir(c *gin.Context) {
  37. var data models.SysFileDir
  38. err := c.ShouldBindJSON(&data)
  39. data.CreateBy = tools.GetUserIdStr(c)
  40. tools.HasError(err, "", 500)
  41. result, err := data.Create()
  42. tools.HasError(err, "", -1)
  43. app.OK(c, result, "")
  44. }
  45. func UpdateSysFileDir(c *gin.Context) {
  46. var data models.SysFileDir
  47. err := c.BindWith(&data, binding.JSON)
  48. tools.HasError(err, "数据解析失败", -1)
  49. data.UpdateBy = tools.GetUserIdStr(c)
  50. result, err := data.Update(data.Id)
  51. tools.HasError(err, "", -1)
  52. app.OK(c, result, "")
  53. }
  54. func DeleteSysFileDir(c *gin.Context) {
  55. var data models.SysFileDir
  56. data.UpdateBy = tools.GetUserIdStr(c)
  57. IDS := tools.IdsStrToIdsIntGroup("id", c)
  58. _, err := data.BatchDelete(IDS)
  59. tools.HasError(err, msg.DeletedFail, 500)
  60. app.OK(c, nil, msg.DeletedSuccess)
  61. }