captureService.go 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. package service
  2. import (
  3. "iot_manager_service/app/device/dao"
  4. "iot_manager_service/app/operation/edge_service"
  5. "iot_manager_service/app/operation/model"
  6. "iot_manager_service/util/common"
  7. )
  8. // CaptureService 车流统计
  9. var CaptureService = new(captureService)
  10. type captureService struct{}
  11. // GetDayVehicleTotal 车流统计 日
  12. func (s captureService) GetDayVehicleTotal(tenantId string, req model.RequestCaptureFilter) ([]model.ResponseCaptureVehicleTotal, error) {
  13. return s.getVehicleTotalData(0, tenantId, req)
  14. }
  15. // GetMonthVehicleTotal 车流统计 月
  16. func (s captureService) GetMonthVehicleTotal(tenantId string, req model.RequestCaptureFilter) ([]model.ResponseCaptureVehicleTotal, error) {
  17. return s.getVehicleTotalData(1, tenantId, req)
  18. }
  19. // 车流统计公用方法
  20. func (s captureService) getVehicleTotalData(flag int, tenantId string, req model.RequestCaptureFilter) ([]model.ResponseCaptureVehicleTotal, error) {
  21. unit := dao.CaptureUnit{
  22. TenantId: tenantId,
  23. ID: req.CaptureId,
  24. }
  25. unit.GetDevice()
  26. var codes []string
  27. codes = append(codes, unit.CaptureSn)
  28. var list []model.ResponseCaptureVehicleTotal
  29. forCaptureIts := edge_service.ForCaptureIts{}
  30. forData, err := forCaptureIts.VehicleTotal(edge_service.ForCaptureItsReq{
  31. Codes: codes,
  32. Start: req.StartTime,
  33. End: req.EndTime,
  34. Flag: flag,
  35. })
  36. var countTimes []string
  37. if flag == 1 {
  38. countTimes = common.GetTimeMonths(req.StartTime, req.EndTime) //时间范围 月
  39. } else {
  40. countTimes = common.GetTimeDays(req.StartTime, req.EndTime) //时间范围 天
  41. }
  42. for _, countTime := range countTimes {
  43. var countT int
  44. for _, datum := range forData {
  45. time := datum.Time
  46. if flag == 1 {
  47. time += "-01"
  48. }
  49. if time == countTime {
  50. countT = datum.Total
  51. continue
  52. }
  53. }
  54. list = append(list, model.ResponseCaptureVehicleTotal{
  55. CountTime: countTime,
  56. CountT: countT,
  57. })
  58. }
  59. if err != nil {
  60. return nil, err
  61. }
  62. return list, nil
  63. }
  64. // GetSuggestSpeed 从数据库查抓拍单元风向
  65. func (s captureService) GetSuggestSpeed(tenantId string, captureId int) (*dao.CaptureUnit, error) {
  66. unit := dao.CaptureUnit{
  67. TenantId: tenantId,
  68. ID: captureId,
  69. }
  70. if err := unit.GetDevice(); err != nil {
  71. return nil, err
  72. }
  73. return &unit, nil
  74. }