noticeSetContoller.go 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. package controller
  2. import (
  3. "fmt"
  4. "github.com/gin-gonic/gin"
  5. "iot_manager_service/app/middleware"
  6. "iot_manager_service/app/warn/model"
  7. "iot_manager_service/app/warn/service"
  8. "iot_manager_service/util/common"
  9. "math"
  10. "net/http"
  11. "strconv"
  12. )
  13. var NoticeSet = new(noticeSetCtl)
  14. type noticeSetCtl struct {
  15. }
  16. func (c noticeSetCtl) List(ctx *gin.Context) {
  17. value, _ := ctx.Get(middleware.Authorization)
  18. claims := value.(*middleware.Claims)
  19. current, _ := strconv.Atoi(ctx.Query("current"))
  20. size, _ := strconv.Atoi(ctx.Query("size"))
  21. searchValue := ctx.Query("searchValue")
  22. if current == 0 {
  23. current = 1
  24. }
  25. if size <= 0 || size > 100 {
  26. size = 10
  27. }
  28. records, err := service.NoticeSetService.GetList(claims.TenantId, searchValue)
  29. if err != nil {
  30. ctx.JSON(http.StatusBadRequest, err)
  31. return
  32. }
  33. pages := math.Ceil(float64(len(records)) / float64(size))
  34. rsp := model.ResposeNoticeSetRecords{
  35. Current: current,
  36. Size: size,
  37. Total: len(records),
  38. Pages: int(pages),
  39. Records: records,
  40. }
  41. ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, rsp))
  42. }
  43. func (c noticeSetCtl) GetUserList(ctx *gin.Context) {
  44. current, _ := strconv.Atoi(ctx.Query("current"))
  45. size, _ := strconv.Atoi(ctx.Query("size"))
  46. account := ctx.Query("account")
  47. realName := ctx.Query("realName")
  48. if current == 0 {
  49. current = 1
  50. }
  51. if size <= 0 || size > 100 {
  52. size = 10
  53. }
  54. users, err := service.NoticeSetService.UserList(account, realName, current, size)
  55. if err != nil {
  56. ctx.JSON(http.StatusBadRequest, err)
  57. return
  58. }
  59. fmt.Printf("users = %v", users)
  60. userN := `
  61. {"code":200,"success":true,"msg":"操作成功","data":[{"id":"10","tenantId":100000,"code":"13","account":"huangxz","password":"4b51712f9748dbba080ed1d8dac9a7d24abb24c2","name":"huang","realName":"黄小柱","avatar":"","email":"38612744@qq.com","phone":"13787020473","birthday":"1981-04-24T12:00:00+08:00","sex":1,"roleId":1,"createUser":1432148790919352321,"createDept":1263036048201457666,"createTime":"2022-03-14T08:52:27+08:00","updateUser":1123598821738675201,"updateTime":"2022-04-28T11:24:30+08:00","status":1,"isDeleted":0,"groupId":1,"bigScreenIndexCameraIds":"","securitySixScreen":"85,-1,-1,-1,86,-1","tenantName":"平江县智慧路灯","roleName":"超级管理员","sexName":"男"},{"id":"11","tenantId":100000,"code":"13","account":"test","password":"4b51712f9748dbba080ed1d8dac9a7d24abb24c2","name":"test","realName":"测试","avatar":"","email":"38612744@qq.com","phone":"13787020473","birthday":"","sex":0,"roleId":1,"createUser":1432148790919352321,"createDept":1263036048201457666,"createTime":"2022-03-14T08:52:27+08:00","updateUser":0,"updateTime":"2022-04-28T11:24:30+08:00","status":1,"isDeleted":0,"groupId":1,"bigScreenIndexCameraIds":"","securitySixScreen":"","tenantName":"平江县智慧路灯","roleName":"超级管理员","sexName":""}]}
  62. `
  63. ctx.String(200, userN)
  64. //ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, users))
  65. }
  66. func (c noticeSetCtl) Detail(ctx *gin.Context) {
  67. id := ctx.Query("id")
  68. data, err := service.NoticeSetService.GetById(id)
  69. if err != nil {
  70. ctx.JSON(http.StatusOK, err)
  71. return
  72. }
  73. ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, data))
  74. }
  75. func (c noticeSetCtl) Update(ctx *gin.Context) {
  76. value, _ := ctx.Get(middleware.Authorization)
  77. claims := value.(*middleware.Claims)
  78. post := model.NoticeUpdateData{}
  79. err := ctx.ShouldBindJSON(&post)
  80. if err != nil {
  81. ctx.JSON(http.StatusBadRequest, err)
  82. return
  83. }
  84. //fmt.Printf("post = %v", post)
  85. err = service.NoticeSetService.Update(post, claims.TenantId)
  86. if err != nil {
  87. ctx.JSON(http.StatusBadRequest, err)
  88. return
  89. }
  90. ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, nil))
  91. }
  92. func (c noticeSetCtl) Remove(ctx *gin.Context) {
  93. value, _ := ctx.Get(middleware.Authorization)
  94. claims := value.(*middleware.Claims)
  95. id := ctx.Query("ids")
  96. err := service.NoticeSetService.Remove(id, claims.TenantId)
  97. if err != nil {
  98. ctx.JSON(http.StatusBadRequest, err)
  99. return
  100. }
  101. ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, nil))
  102. }