alarmTerminalController.go 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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 AlarmTerminal = new(alarmTerminalCtl)
  15. type alarmTerminalCtl struct{}
  16. func (c *alarmTerminalCtl) 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.AlarmTerminalService.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 *alarmTerminalCtl) 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.AlarmTerminalService.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.RsqAlarmTerminalList{
  46. Current: current,
  47. Size: size,
  48. Total: len(devices),
  49. Pages: int(pages),
  50. Records: devices,
  51. }
  52. ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, rsp))
  53. }
  54. func (c *alarmTerminalCtl) CreateOrUpdate(ctx *gin.Context) {
  55. value, _ := ctx.Get(middleware.Authorization)
  56. claims := value.(*middleware.Claims)
  57. var req dao.AlarmTerminal
  58. if err := ctx.ShouldBindJSON(&req); err != nil {
  59. ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(err.Error(), nil))
  60. return
  61. }
  62. err := service.AlarmTerminalService.CreateOrUpdate(claims.UserId, claims.TenantId, req)
  63. ctx.JSON(http.StatusOK, err)
  64. }
  65. func (c *alarmTerminalCtl) Remove(ctx *gin.Context) {
  66. value, _ := ctx.Get(middleware.Authorization)
  67. claims := value.(*middleware.Claims)
  68. var req *model.ReqAlarmTerminalRemove
  69. if err := ctx.ShouldBindJSON(&req); err != nil {
  70. ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(err.Error(), nil))
  71. return
  72. }
  73. err := service.AlarmTerminalService.Remove(claims.UserId, claims.TenantId, req.IDs)
  74. if err != nil {
  75. ctx.JSON(http.StatusOK, err)
  76. return
  77. }
  78. ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, nil))
  79. }
  80. func (c *alarmTerminalCtl) ImportExcel(ctx *gin.Context) {
  81. }
  82. func (c *alarmTerminalCtl) ExportExcel(ctx *gin.Context) {
  83. }
  84. func (c *alarmTerminalCtl) ExportTemplate(ctx *gin.Context) {
  85. }