96 lines
3.3 KiB
C#
96 lines
3.3 KiB
C#
using Dlhis.Entity.Device.Enums;
|
|
using Dlhis.Middle.Apis;
|
|
using Dlhis.Middle.Request;
|
|
using Dlhis.Middle.Response;
|
|
using Dlhis.Middle.Services;
|
|
using Kurisu.AspNetCore.DataAccess.SqlSugar.Aop;
|
|
using Kurisu.AspNetCore.UnifyResultAndValidation;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.AspNetCore.WebUtilities;
|
|
using Newtonsoft.Json.Linq;
|
|
|
|
namespace Dlhis.Middle.Controllers;
|
|
|
|
/// <summary>
|
|
/// 任务分配
|
|
/// </summary>
|
|
[Route("api/scheduled/[controller]")]
|
|
[ApiController]
|
|
public class AssignmentsController : ControllerBase
|
|
{
|
|
private readonly IAssignmentDeviceTaskApi _assignmentDeviceTaskApi;
|
|
private readonly IHealthCheckService _healthCheckService;
|
|
private readonly string _internalIp;
|
|
|
|
public AssignmentsController(IAssignmentDeviceTaskApi assignmentDeviceTaskApi, IConfiguration configuration, IHealthCheckService healthCheckService)
|
|
{
|
|
_assignmentDeviceTaskApi = assignmentDeviceTaskApi;
|
|
_healthCheckService = healthCheckService;
|
|
_internalIp = configuration.GetSection("InternalIP").Value;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取设备任务(按设备)
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[IgnoreTenant]
|
|
[HttpGet("deviceTasks")]
|
|
public async Task<DefaultApiResult<List<DeviceTaskToDeviceByDeviceResponse>>> DeviceGetTasksGetAsync([FromQuery] DeviceTaskGetRequest request)
|
|
{
|
|
if (_healthCheckService.GetIsOffline())
|
|
{
|
|
return new DefaultApiResult<List<DeviceTaskToDeviceByDeviceResponse>>
|
|
{
|
|
Data = new List<DeviceTaskToDeviceByDeviceResponse>()
|
|
};
|
|
}
|
|
|
|
var result = await _assignmentDeviceTaskApi.DeviceGetTasksAsync(request);
|
|
foreach (var data in result.Data)
|
|
{
|
|
foreach (var task in data.Tasks.Where(x => x.Type != DeviceTaskEnumType.Delete))
|
|
{
|
|
var currentUser = JObject.FromObject(task.Info).ToObject<UserToDeviceResponse>();
|
|
var token = QueryHelpers.ParseQuery(currentUser.Face).First().Value;
|
|
currentUser.Face = $"http://{_internalIp}/api/basic/gainfos/face?token=" + token;
|
|
|
|
task.Info = currentUser;
|
|
}
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取设备任务(按设备)
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[HttpPost("deviceTasks")]
|
|
[IgnoreTenant]
|
|
public async Task<DefaultApiResult<List<DeviceTaskToDeviceByDeviceResponse>>> DeviceGetTasksPostAsync(DeviceTaskGetRequest request)
|
|
{
|
|
if (_healthCheckService.GetIsOffline())
|
|
{
|
|
return new DefaultApiResult<List<DeviceTaskToDeviceByDeviceResponse>>
|
|
{
|
|
Data = new List<DeviceTaskToDeviceByDeviceResponse>()
|
|
};
|
|
}
|
|
|
|
var result = await _assignmentDeviceTaskApi.DeviceGetTasksAsync(request);
|
|
foreach (var data in result.Data)
|
|
{
|
|
foreach (var task in data.Tasks.Where(x => x.Type != DeviceTaskEnumType.Delete))
|
|
{
|
|
var currentUser = JObject.FromObject(task.Info).ToObject<UserToDeviceResponse>();
|
|
var token = QueryHelpers.ParseQuery(currentUser.Face).First().Value;
|
|
currentUser.Face = $"http://{_internalIp}/api/basic/gainfos/face?token=" + token;
|
|
|
|
task.Info = currentUser;
|
|
}
|
|
}
|
|
|
|
return result;
|
|
}
|
|
} |