captureService.go 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. //fmt.Printf("forData = %v \n", forData)
  37. var countTimes []string
  38. if flag == 1 {
  39. countTimes = common.GetTimeMonths(req.StartTime, req.EndTime) //时间范围 月
  40. } else {
  41. countTimes = common.GetTimeDays(req.StartTime, req.EndTime) //时间范围 天
  42. }
  43. for _, countTime := range countTimes {
  44. var countT int
  45. for _, datum := range forData {
  46. time := datum.Time
  47. if flag == 1 {
  48. time += "-01"
  49. }
  50. if time == countTime {
  51. countT = datum.Total
  52. continue
  53. }
  54. }
  55. list = append(list, model.ResponseCaptureVehicleTotal{
  56. CountTime: countTime,
  57. CountT: countT,
  58. })
  59. }
  60. if err != nil {
  61. return nil, err
  62. }
  63. return list, nil
  64. }
  65. // GetSuggestSpeed 从数据库查抓拍单元风向
  66. func (s captureService) GetSuggestSpeed(tenantId string, captureId int) (*dao.CaptureUnit, error) {
  67. unit := dao.CaptureUnit{
  68. TenantId: tenantId,
  69. ID: captureId,
  70. }
  71. if err := unit.GetDevice(); err != nil {
  72. return nil, err
  73. }
  74. return &unit, nil
  75. }