fix 任务图片连接处理

This commit is contained in:
2024-06-28 14:03:40 +08:00
parent 0214309e64
commit 9446ba6ffa
20 changed files with 427 additions and 14 deletions

View File

@@ -0,0 +1,76 @@
using Dlhis.Entity.Device.Enums;
using Dlhis.Middle.Api;
using Dlhis.Middle.Request;
using Dlhis.Middle.Response;
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 string _internalIp;
public AssignmentsController(IAssignmentDeviceTaskApi assignmentDeviceTaskApi, IConfiguration configuration)
{
_assignmentDeviceTaskApi = assignmentDeviceTaskApi;
_internalIp = configuration.GetSection("InternalIP").Value;
}
/// <summary>
/// 获取设备任务(按设备)
/// </summary>
/// <returns></returns>
[IgnoreTenant]
[HttpGet("deviceTasks")]
public async Task<DefaultApiResult<List<DeviceTaskToDeviceByDeviceResponse>>> DeviceGetTasksGetAsync([FromQuery] DeviceTaskGetRequest request)
{
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)
{
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;
}
}

View File

@@ -0,0 +1,52 @@
using Dlhis.Middle.Filters;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
namespace Dlhis.Middle.Controllers;
/// <summary>
/// sap档案表
/// </summary>
[Route("api/basic/[controller]")]
[ApiController]
public class GainfosController : ControllerBase
{
private readonly IHttpClientFactory _httpClientFactory;
private readonly IConfiguration _configuration;
public GainfosController(IHttpClientFactory httpClientFactory, IConfiguration configuration)
{
_httpClientFactory = httpClientFactory;
_configuration = configuration;
}
/// <summary>
/// 通过token获取人脸照片,失效或者找不到返回HttpStatus404状态码
/// </summary>
/// <param name="token"></param>
/// <returns></returns>
[NotFound]
[AllowAnonymous]
[HttpGet("face")]
public async Task<IActionResult> GetFaceAsync(string token)
{
var hostName = _configuration.GetSection("HostName").Value;
var httpClient = _httpClientFactory.CreateClient();
try
{
var faceBytes = await httpClient.GetByteArrayAsync($"https://{hostName}/api/basic/gainfos/face?token={token}");
if (faceBytes.Length == 0)
{
return new NotFoundResult();
}
return new FileContentResult(faceBytes, "image/png");
}
catch (Exception)
{
return new NotFoundResult();
}
}
}

View File

@@ -1,9 +1,8 @@
using Dlhis.Middle.Request;
using Dlhis.Middle.Api;
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.Authorization;
using Microsoft.AspNetCore.Mvc;
namespace Dlhis.Middle.Controllers;
@@ -15,11 +14,11 @@ namespace Dlhis.Middle.Controllers;
[ApiController]
public class OrdersController : ControllerBase
{
private readonly IOrderService _orderService;
private readonly ICanteenApi _canteenApi;
public OrdersController(IOrderService orderService)
public OrdersController(ICanteenApi canteenApi)
{
_orderService = orderService;
_canteenApi = canteenApi;
}
/// <summary>
@@ -31,6 +30,6 @@ public class OrdersController : ControllerBase
[IgnoreTenant]
public async Task<DefaultApiResult<OrderResultResponse>> AddAsync(OrderAddRequest request)
{
return await _orderService.AddAsync(request);
return await _canteenApi.AddAsync(request);
}
}