captureController.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. }