infoBoardController.go 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. package controller
  2. import (
  3. "github.com/gin-gonic/gin"
  4. "iot_manager_service/app/device/dao"
  5. "iot_manager_service/app/device/model"
  6. "iot_manager_service/app/device/service"
  7. "iot_manager_service/app/middleware"
  8. "iot_manager_service/util"
  9. "math"
  10. "net/http"
  11. "strconv"
  12. )
  13. // 信息屏基本信息管理对象
  14. var InfoBoard = new(infoBoardCtl)
  15. type infoBoardCtl struct{}
  16. func (c *infoBoardCtl) Detail(ctx *gin.Context) {
  17. id, e := strconv.Atoi(ctx.Query("id"))
  18. if e != nil {
  19. ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(e.Error(), nil))
  20. return
  21. }
  22. device, err := service.InfoBoardService.Get(id)
  23. if err != nil {
  24. ctx.JSON(http.StatusOK, err)
  25. return
  26. }
  27. ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, device))
  28. }
  29. func (c *infoBoardCtl) List(ctx *gin.Context) {
  30. searchValue := ctx.Query("searchValue")
  31. current, _ := strconv.Atoi(ctx.Query("current"))
  32. size, _ := strconv.Atoi(ctx.Query("size"))
  33. if current == 0 {
  34. current = 1
  35. }
  36. if size <= 0 || size > 100 {
  37. size = 10
  38. }
  39. devices, err := service.InfoBoardService.List(searchValue, current, size)
  40. if err != nil {
  41. ctx.JSON(http.StatusOK, err)
  42. return
  43. }
  44. pages := math.Ceil(float64(len(devices)) / float64(size))
  45. rsp := model.RsqInfoBoardList{
  46. Current: current,
  47. Size: size,
  48. Total: len(devices),
  49. Pages: int(pages),
  50. }
  51. for _, device := range devices {
  52. rsp.Records = append(rsp.Records, device)
  53. }
  54. ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, rsp))
  55. }
  56. func (c *infoBoardCtl) CreateOrUpdate(ctx *gin.Context) {
  57. value, _ := ctx.Get(middleware.Authorization)
  58. claims := value.(*middleware.Claims)
  59. var req dao.InfoBoard
  60. if err := ctx.ShouldBindJSON(&req); err != nil {
  61. ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(err.Error(), nil))
  62. return
  63. }
  64. err := service.InfoBoardService.CreateOrUpdate(claims.UserId, claims.TenantId, req)
  65. ctx.JSON(http.StatusOK, err)
  66. }
  67. func (c *infoBoardCtl) Remove(ctx *gin.Context) {
  68. value, _ := ctx.Get(middleware.Authorization)
  69. claims := value.(*middleware.Claims)
  70. var req *model.ReqInfoBoardRemove
  71. if err := ctx.ShouldBindJSON(&req); err != nil {
  72. ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(err.Error(), nil))
  73. return
  74. }
  75. err := service.InfoBoardService.Remove(claims.UserId, req.IDs)
  76. if err != nil {
  77. ctx.JSON(http.StatusOK, err)
  78. return
  79. }
  80. ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, nil))
  81. }
  82. func (c *infoBoardCtl) ImportExcel(ctx *gin.Context) {
  83. }
  84. func (c *infoBoardCtl) ExportExcel(ctx *gin.Context) {
  85. }
  86. func (c *infoBoardCtl) ExportTemplate(ctx *gin.Context) {
  87. }
  88. func (c *infoBoardCtl) SystemOperation(ctx *gin.Context) {
  89. }
  90. func (c *infoBoardCtl) Enable(ctx *gin.Context) {
  91. }
  92. func (c *infoBoardCtl) ShowSetting(ctx *gin.Context) {
  93. }