captureController.go 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. package controller
  2. import (
  3. "github.com/gin-gonic/gin"
  4. "iot_manager_service/app/middleware"
  5. "iot_manager_service/app/operation/model"
  6. "iot_manager_service/app/operation/service"
  7. "iot_manager_service/util/common"
  8. "net/http"
  9. "strconv"
  10. )
  11. // Capture 抓拍单元
  12. var Capture = new(captureCtl)
  13. type captureCtl struct{}
  14. // CountList 取车流量 月日
  15. func (c captureCtl) CountList(ctx *gin.Context) {
  16. value, _ := ctx.Get(middleware.Authorization)
  17. claims := value.(*middleware.Claims)
  18. var req model.RequestCaptureFilter
  19. err := ctx.ShouldBindQuery(&req)
  20. if err != nil {
  21. ctx.JSON(http.StatusOK, err)
  22. return
  23. }
  24. var records interface{}
  25. err = nil
  26. if req.QueryType == "day" {
  27. records, err = service.CaptureService.GetDayVehicleTotal(claims.TenantId, req)
  28. } else {
  29. records, err = service.CaptureService.GetMonthVehicleTotal(claims.TenantId, req)
  30. }
  31. if err != nil {
  32. ctx.JSON(http.StatusOK, err)
  33. return
  34. }
  35. ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, records))
  36. }
  37. // SuggestSpeed 取抓拍单元 方位
  38. func (c captureCtl) SuggestSpeed(ctx *gin.Context) {
  39. captureId, err := strconv.Atoi(ctx.Query("captureId"))
  40. if err != nil {
  41. ctx.JSON(http.StatusOK, err)
  42. return
  43. }
  44. value, _ := ctx.Get(middleware.Authorization)
  45. claims := value.(*middleware.Claims)
  46. var records interface{}
  47. records, err = service.CaptureService.GetSuggestSpeed(claims.TenantId, captureId)
  48. if err != nil {
  49. ctx.JSON(http.StatusOK, err)
  50. return
  51. }
  52. ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, records))
  53. }
  54. // AreaList 归属地统计 list
  55. func (c captureCtl) AreaList(ctx *gin.Context) {
  56. value, _ := ctx.Get(middleware.Authorization)
  57. claims := value.(*middleware.Claims)
  58. var req model.RequestCaptureFilter
  59. err := ctx.ShouldBindQuery(&req)
  60. if err != nil {
  61. ctx.JSON(http.StatusOK, err)
  62. return
  63. }
  64. var records interface{}
  65. records, err = service.CaptureAreaService.GetAreaList(claims.TenantId, req)
  66. if err != nil {
  67. ctx.JSON(http.StatusOK, err)
  68. return
  69. }
  70. ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, records))
  71. }
  72. // AreaTypeList 归属地统计 line图表
  73. func (c captureCtl) AreaTypeList(ctx *gin.Context) {
  74. value, _ := ctx.Get(middleware.Authorization)
  75. claims := value.(*middleware.Claims)
  76. var req model.RequestCaptureFilter
  77. err := ctx.ShouldBindQuery(&req)
  78. if err != nil {
  79. ctx.JSON(http.StatusOK, err)
  80. return
  81. }
  82. var records interface{}
  83. records, err = service.CaptureAreaService.GetAreaTypeList(claims.TenantId, req)
  84. if err != nil {
  85. ctx.JSON(http.StatusOK, err)
  86. return
  87. }
  88. ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, records))
  89. }
  90. // VehicleTypeEx 车型 列表 查询
  91. func (c captureCtl) VehicleTypeEx(ctx *gin.Context) {
  92. value, _ := ctx.Get(middleware.Authorization)
  93. claims := value.(*middleware.Claims)
  94. var req model.RequestCaptureFilter
  95. err := ctx.ShouldBindQuery(&req)
  96. if err != nil {
  97. ctx.JSON(http.StatusOK, err)
  98. return
  99. }
  100. var records interface{}
  101. err = nil
  102. records, err = service.CaptureVehicleTypeExService.GetVehicleList(claims.TenantId, req)
  103. if err != nil {
  104. ctx.JSON(http.StatusOK, err)
  105. return
  106. }
  107. ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, records))
  108. }
  109. // VehicleTypeList 车型 line线图数据
  110. func (c captureCtl) VehicleTypeList(ctx *gin.Context) {
  111. value, _ := ctx.Get(middleware.Authorization)
  112. claims := value.(*middleware.Claims)
  113. var req model.RequestCaptureFilter
  114. err := ctx.ShouldBindQuery(&req)
  115. if err != nil {
  116. ctx.JSON(http.StatusOK, err)
  117. return
  118. }
  119. var records interface{}
  120. err = nil
  121. records, err = service.CaptureVehicleTypeExService.GetVehicleTypeList(claims.TenantId, req)
  122. if err != nil {
  123. ctx.JSON(http.StatusOK, err)
  124. return
  125. }
  126. ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, records))
  127. }
  128. // SpeedList 车速统计
  129. func (c captureCtl) SpeedList(ctx *gin.Context) {
  130. value, _ := ctx.Get(middleware.Authorization)
  131. claims := value.(*middleware.Claims)
  132. var req model.RequestCaptureFilter
  133. err := ctx.ShouldBindQuery(&req)
  134. if err != nil {
  135. ctx.JSON(http.StatusOK, err)
  136. return
  137. }
  138. var records interface{}
  139. records, err = service.CaptureSpeedService.GetList(claims.TenantId, req)
  140. if err != nil {
  141. ctx.JSON(http.StatusOK, err)
  142. return
  143. }
  144. ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, records))
  145. }
  146. // OverSpeedRecord 超速明细
  147. func (c captureCtl) OverSpeedRecord(ctx *gin.Context) {
  148. var req model.RequestCaptureOverSpeed
  149. _ = ctx.ShouldBindQuery(&req)
  150. var records interface{}
  151. records, err := service.CaptureSpeedService.GetOverSpeedRecord(req)
  152. if err != nil {
  153. ctx.JSON(http.StatusOK, err)
  154. return
  155. }
  156. ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, records))
  157. }
  158. // OverSpeedRecordSync 同步超速明细记录
  159. func (c captureCtl) OverSpeedRecordSync(ctx *gin.Context) {
  160. var req model.RequestCaptureFilter
  161. _ = ctx.ShouldBindQuery(&req)
  162. go func() {
  163. service.CaptureSpeedService.SyncOverSpeedRecord(req.StartTime, req.EndTime)
  164. }()
  165. ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, nil))
  166. }
  167. // PeriodsList 时段统计
  168. func (c captureCtl) PeriodsList(ctx *gin.Context) {
  169. value, _ := ctx.Get(middleware.Authorization)
  170. claims := value.(*middleware.Claims)
  171. var req model.RequestCaptureFilter
  172. err := ctx.ShouldBindQuery(&req)
  173. if err != nil {
  174. ctx.JSON(http.StatusOK, err)
  175. return
  176. }
  177. records, err := service.CapturePeriodsService.GetPeriodsList(claims.TenantId, req)
  178. if err != nil {
  179. ctx.JSON(http.StatusOK, err)
  180. return
  181. }
  182. ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, records))
  183. }