aKeyAlarmRecordController.go 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. package controller
  2. import (
  3. "github.com/gin-gonic/gin"
  4. "iot_manager_service/app/record/dao"
  5. "iot_manager_service/app/record/service"
  6. "iot_manager_service/util/common"
  7. "math"
  8. "net/http"
  9. "strconv"
  10. )
  11. var AKeyAlarmRecord = new(aKeyAlarmRecordCtl)
  12. type aKeyAlarmRecordCtl struct{}
  13. type AKeyAlarmRecordRespose struct {
  14. Records []dao.AkeyAlarmRecord `json:"records"` //记录列表
  15. Current int `json:"current"` //当前分页
  16. Size int `json:"size"` //每页数量
  17. Total int `json:"total"` //总数
  18. Pages int `json:"pages"` //总页数
  19. }
  20. func (c *aKeyAlarmRecordCtl) List(ctx *gin.Context) {
  21. searchValue := ctx.Query("searchValue")
  22. start := ctx.Query("queryStartTime")
  23. end := ctx.Query("queryEndTime")
  24. serveId := ctx.Query("serveId")
  25. current, _ := strconv.Atoi(ctx.Query("current"))
  26. size, _ := strconv.Atoi(ctx.Query("size"))
  27. if current == 0 {
  28. current = 1
  29. }
  30. if size <= 0 || size > 100 {
  31. size = 10
  32. }
  33. id := -1
  34. if serveId != "" {
  35. id, _ = strconv.Atoi(serveId)
  36. }
  37. records, err := service.AKeyAlarmRecordService.List(searchValue, start, end, id, current, size)
  38. if err != nil {
  39. ctx.JSON(http.StatusOK, err)
  40. return
  41. }
  42. pages := math.Ceil(float64(len(records)) / float64(size))
  43. rsp := AKeyAlarmRecordRespose{
  44. Current: current,
  45. Size: size,
  46. Total: len(records),
  47. Pages: int(pages),
  48. Records: records,
  49. }
  50. ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, rsp))
  51. }
  52. // refresh 同步sos记录
  53. func (c *aKeyAlarmRecordCtl) Refresh(ctx *gin.Context) {
  54. c.SosRecordSync()
  55. ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, nil))
  56. }
  57. func (c *aKeyAlarmRecordCtl) SosRecordSync() {
  58. recordService := service.AKeyAlarmRecordService
  59. go func() {
  60. recordService.Refresh()
  61. }()
  62. }
  63. // Detail 查看详情
  64. func (c *aKeyAlarmRecordCtl) Detail(ctx *gin.Context) {
  65. id, _ := strconv.Atoi(ctx.Query("id"))
  66. record, err := service.AKeyAlarmRecordService.Detail(id)
  67. if err != nil {
  68. ctx.JSON(http.StatusOK, err)
  69. return
  70. }
  71. ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, record))
  72. }
  73. // Dispose 添加备注
  74. func (c *aKeyAlarmRecordCtl) Dispose(ctx *gin.Context) {
  75. id, _ := strconv.Atoi(ctx.Query("id"))
  76. remark := ctx.Query("remark")
  77. err := service.AKeyAlarmRecordService.UpdateRemark(id, remark)
  78. if err != nil {
  79. ctx.JSON(http.StatusOK, err)
  80. return
  81. }
  82. ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, nil))
  83. }