using MoYu.FriendlyException;
using MoYu.RemoteRequest.Extensions;
using Newtonsoft.Json.Linq;
using SafeCampus.Application.Manager.DeepelephManager;
using SafeCampus.Application.Services.Business.PassengerFlowService;
using SafeCampus.Application.Services.Business.PassengerFlowService.Dto;
namespace SafeCampus.Web.Core.Controllers.Application.Business;
///
/// 客流查询接口
///
[Route("/business/[controller]")]
[ApiDescriptionSettings(ApiGroupConsts.SYSTEM_Business, Order = 96,Tag = " 客流查询")]
public class PassengerFlowApi : IDynamicApiController
{
private readonly IDeepelephManager _deepelephManager;
private readonly IPassengerFlowService _passengerFlowService;
public PassengerFlowApi(IDeepelephManager deepelephManager, IPassengerFlowService passengerFlowService)
{
_deepelephManager = deepelephManager;
_passengerFlowService = passengerFlowService;
}
///
/// 添加客流查询任务
///
/// 添加参数
///
public async Task Add(PassengerFlowDto input)
{
var appSettings = App.GetOptionsMonitor();
var str = await $"{appSettings.SXAPIURL}/dfield-api/ecology/passenger-flow/enter/search"
.SetBody(new
{
token = _deepelephManager.GetToken(),
tenantCode = appSettings.TenantCode,
poiId = appSettings.PoiId,
startTime = new DateTimeOffset(input.StartTime).ToUnixTimeMilliseconds(),
endTime = new DateTimeOffset(input.EndTime).ToUnixTimeMilliseconds(),
cameraId=input.CameraIds,
split = input.Split ? "HOUR" : "DAY",
})
.SetContentType("application/json")
.PostAsAsync();
var model = JsonConvert.DeserializeObject(str);
if ((bool)model["success"])
{
input.Total = (int)model["data"]["total"];
input.ExtJson = model["data"]["data"].ToString();
await _passengerFlowService.Add(input);
return true;
}
throw Oops.Oh(model["message"].ToString());
}
///
/// 分页查询列表
///
///
///
public async Task> GetPageList(PassengerFlowSearch search)
{
return await _passengerFlowService.GetPageList(search);
}
///
/// 客流查询
///
/// 查询参数
///
[Obsolete]
public async Task PostPassengerFlow(PassengerFlowDto search)
{
var appSettings = App.GetOptionsMonitor();
var str = await $"{appSettings.SXAPIURL}/dfield-api/ecology/passenger-flow/enter/search"
.SetBody(new
{
token = _deepelephManager.GetToken(),
tenantCode = appSettings.TenantCode,
poiId = appSettings.PoiId,
startTime = new DateTimeOffset(search.StartTime).ToUnixTimeMilliseconds(),
endTime = new DateTimeOffset(search.EndTime).ToUnixTimeMilliseconds(),
cameraId=search.CameraIds,
split = search.Split ? "HOUR" : "DAY",
})
.SetContentType("application/json")
.PostAsAsync();
var model = JsonConvert.DeserializeObject(str);
if ((bool)model["success"])
{
return model["data"];
}
throw Oops.Oh(model["message"].ToString());
}
}