hrSensors.go 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /**
  2. * @ File:
  3. * @ Date: 2021/1/25 16:15
  4. * @ Author: JYQ
  5. * @ Description:
  6. */
  7. package controller
  8. import (
  9. "net/http"
  10. "video_course/service"
  11. )
  12. type HrSensors struct {
  13. BaseController
  14. }
  15. type UpdateHrSensorsInfo struct {
  16. ResponseBase
  17. HrId int
  18. }
  19. // HrSensorsUpdate godoc
  20. // @Summary 心率带信息查询和更新
  21. // @tags HrSensors
  22. // @Description 心率带信息查询和更新
  23. // @Accept x-www-form-urlencoded
  24. // @Produce json
  25. // @Param token formData string true "Token"
  26. // @Param sn formData string true "心率带编号"
  27. // @Success 200 {object} controller.ResponseBase
  28. // @Router /HrSensors/HrSensorsUpdate [post]
  29. func (h *HrSensors) HrSensorsUpdate() (err error) {
  30. token := h.Ctx().PostForm("token")
  31. sn := h.Ctx().PostForm("sn")
  32. hrId, err := service.HrSensors{}.HrSensorsUpdate(token, sn)
  33. if err != nil {
  34. return
  35. }
  36. r := UpdateHrSensorsInfo{
  37. newResponseBase(),
  38. hrId,
  39. }
  40. h.Ctx().JSON(http.StatusOK, r)
  41. return
  42. }
  43. type AddHRRtn struct {
  44. ResponseBase
  45. InClass int
  46. }
  47. // AddAppHeartRate godoc
  48. // @Summary App心率数据上报
  49. // @tags HrSensors
  50. // @Description App心率数据上报
  51. // @Accept x-www-form-urlencoded
  52. // @Produce json
  53. // @Param token formData string true "Token"
  54. // @Param duId formData int true "duId"
  55. // @Param sn formData string true "sn"
  56. // @Param hrId formData int true "心率带id"
  57. // @Param heartRate formData int true "心跳"
  58. // @Param rcvTime formData int true "时间戳毫秒"
  59. // @Param calories formData int true "卡路里"
  60. // @Param pureCalories formData int true "运动卡路里"
  61. // @Success 200 {object} controller.AddHRRtn
  62. // @Router /HrSensors/AddAppHeartRate [post]
  63. func (h *HrSensors) AddAppHeartRate() (err error) {
  64. token := h.Ctx().PostForm("token")
  65. duId := h.postIntNecessary("duId")
  66. sn := h.Ctx().PostForm("sn")
  67. hrId := h.postIntNecessary("hrId")
  68. heartRate := h.postIntNecessary("heartRate")
  69. rcvTime := h.postIntNecessary("rcvTime")
  70. calories := h.postIntNecessary("calories")
  71. pureCalories := h.postIntNecessary("pureCalories")
  72. inClass, err := service.HrSensors{}.AddAppHeartRate(token, duId, sn, hrId, heartRate, rcvTime, calories, pureCalories)
  73. if err != nil {
  74. return
  75. }
  76. r := AddHRRtn{
  77. newResponseBase(),
  78. inClass,
  79. }
  80. h.Ctx().JSON(http.StatusOK, r)
  81. return
  82. }