using MoYu.FriendlyException;
using MoYu.RemoteRequest.Extensions;
using Newtonsoft.Json.Linq;
using SafeCampus.Application.Manager.DeepelephManager;
using SafeCampus.Application.Services.Business.AttendanceService;
namespace SafeCampus.Web.Core.Controllers.Application.Business;
///
/// 考勤事件管理接口
///
[Route("/business/[controller]")]
[ApiDescriptionSettings(ApiGroupConsts.SYSTEM_Business, Order = 94,Tag = "考勤事件管理")]
public class AttendanceApi : IDynamicApiController
{
private readonly IAttendanceService _attendanceService;
private readonly IDeepelephManager _deepelephManager;
public AttendanceApi(IDeepelephManager deepelephManager, IAttendanceService attendanceService)
{
_deepelephManager = deepelephManager;
_attendanceService = attendanceService;
}
///
/// 考勤查询
///
/// 查询参数
///
[Obsolete]
public async Task GetPassengerFlow(ClassRoomCallTaskSearchRequest search)
{
var appSettings = App.GetOptionsMonitor();
var str = await $"{appSettings.SXAPIURL}/dfield-api/ecology/attendance/data/query"
.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.cameraId,
pageIndex = search.PageNum,
pageSize = search.PageSize,
})
.SetContentType("application/json")
.PostAsAsync();
var model = JsonConvert.DeserializeObject(str);
if (!(bool)model["success"]) throw Oops.Oh(model["message"].ToString());
if (model["data"] != null)
{
return new
{
pageNum = search.PageNum,
pageSize = model["data"]["size"],
total = model["data"]["total"],
pages = model["data"]["pages"],
list = model["data"]["items"]
};
}
return new
{
pageNum = search.PageNum,
pageSize = 0,
total = 0,
pages = 0,
list = new List()
};
}
///
/// 添加考勤记录
///
///
///
public async Task Add(List input)
{
var appSettings = App.GetOptionsMonitor();
foreach (var attendanceAddInput in input)
{
var vm = new AttendanceDto
{
CreateTime = DateTime.Now,
TenantCode = appSettings.TenantCode,
FaceScore = 100,
IsAuto = false,
PersonSetId = attendanceAddInput.PersonSetId,
PersonId = attendanceAddInput.PersonId,
PoiId = appSettings.PoiId,
Tick = attendanceAddInput.Tick,
Similarity = 100,
EventId = "",
CameraId = "",
Extend = "",
TrackId = "",
SnapshotUrl = "",
SnapshotData = "",
Rects = ""
};
await _attendanceService.Add(vm);
}
return true;
}
///
/// 分页获取考勤列表
///
///
///
public async Task> GetPageList(AttendanceSearch search)
{
return await _attendanceService.GetPageList(search);
}
///
/// 不分页获取考勤列表
///
///
///
public async Task> GetNoPageList(AttendanceSearch search)
{
return await _attendanceService.GetNoPageList(search);
}
///
/// 根据宿舍楼id获取出入记录
///
///
///
public async Task> GetPageListByBuild(BuildAttendanceSearch search)
{
return await _attendanceService.GetPageListByBuild(search);
}
}