294 lines
9.3 KiB
C#
294 lines
9.3 KiB
C#
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Net.Http;
|
|
using System.Text;
|
|
using System.Text.Json;
|
|
using System.Threading.Tasks;
|
|
using VOL.Ai.IServices;
|
|
using VOL.Business.IServices.School;
|
|
using VOL.Core.Enums;
|
|
using VOL.Core.Extensions;
|
|
using VOL.Core.Filters;
|
|
using VOL.Core.Services;
|
|
using VOL.Core.Utilities;
|
|
using VOL.Model;
|
|
using VOL.Model.Ai;
|
|
using VOL.Model.Ai.Request;
|
|
using VOL.Model.IOT.Response;
|
|
|
|
namespace VOL.WebApi.Controllers
|
|
{
|
|
/// <summary>
|
|
/// Ai接口
|
|
/// </summary>
|
|
[Route("api")]
|
|
[ApiController]
|
|
[ApiExplorerSettings(GroupName = "v5")]
|
|
[TypeFilter(typeof(CustomApiResponseFilter))]
|
|
[AllowAnonymous]
|
|
public class AiController : ControllerBase
|
|
{
|
|
#region 初始化
|
|
private readonly IFaceDetectService _faceDetectService;
|
|
private readonly IAiService _aiService;
|
|
private readonly HttpClient _httpClient;
|
|
public AiController(IFaceDetectService faceDetectService, IAiService aiService, HttpClient httpClient)
|
|
{
|
|
_faceDetectService = faceDetectService;
|
|
_aiService = aiService;
|
|
_httpClient = httpClient;
|
|
}
|
|
#endregion
|
|
|
|
/// <summary>
|
|
/// 学生人脸识别
|
|
/// </summary>
|
|
/// <param name="paramDto"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("student/face")]
|
|
public async Task<Ai_StudentFaceInfo> Face([FromBody] GetFaceParam paramDto)
|
|
{
|
|
//var base64 = paramDto.Base64.Split(',')[1];
|
|
var base64 = "";
|
|
var res = await _faceDetectService.Face(base64);
|
|
|
|
|
|
// return new Ai_FaceInfo()
|
|
// {
|
|
// Classes = "1",
|
|
// ClassName = "一班",
|
|
// Grade = "1",
|
|
// GradeName = "一年级",
|
|
// IdCard = "",
|
|
// SchoolName = "测试",
|
|
// SchoolNo = "1",
|
|
// Age = res.Age,
|
|
// Sex = (int)res.Sex,
|
|
// StudentName = res.StudentName,
|
|
// StudentNo = res.StudentNo,
|
|
// Nation = "",
|
|
// };
|
|
|
|
if (res != null)
|
|
{
|
|
return new Ai_StudentFaceInfo()
|
|
{
|
|
ClassId = res.ClassId,
|
|
ClassName = res.ClassName,
|
|
GradeId = res.GradeId,
|
|
GradeName = res.GradeName,
|
|
//IdCard = "",
|
|
//SchoolName = "测试",
|
|
//SchoolCode = "1",
|
|
Age = res.Age,
|
|
Sex = res.Sex,
|
|
StudentName = res.StudentName,
|
|
StudentCode = res.StudentNo
|
|
};
|
|
}
|
|
|
|
return new Ai_StudentFaceInfo();
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 获取Ai设备信息
|
|
/// </summary>
|
|
/// <param name="code"></param>
|
|
/// <param name="studentNo"></param>
|
|
/// <returns></returns>
|
|
[HttpGet("device/detail")]
|
|
public async Task<Ai_DeviceDto> AiDetail(Ai_DeviceRequest paramDto)
|
|
{
|
|
long timestamp = DateTimeOffset.UtcNow.ToUnixTimeSeconds();
|
|
|
|
var json = JsonSerializer.Serialize(paramDto);
|
|
|
|
var signature = IOTSignatureHelper.GenerateSignature(json, timestamp);
|
|
|
|
_httpClient.DefaultRequestHeaders.Add("X-Timestamp", timestamp.ToString());
|
|
_httpClient.DefaultRequestHeaders.Add("X-Signature", signature);
|
|
|
|
HttpContent content = new StringContent(json, Encoding.UTF8, "application/json");
|
|
|
|
var response = await _httpClient.PostAsync("http://localhost:9991/api/AiApp/Test", content);
|
|
response.EnsureSuccessStatusCode();
|
|
|
|
var responseBody = string.Empty;
|
|
using (var reader = new StreamReader(await response.Content.ReadAsStreamAsync(), Encoding.UTF8))
|
|
{
|
|
responseBody = await reader.ReadToEndAsync();
|
|
}
|
|
|
|
//Console.WriteLine($"Response: {responseBody}");
|
|
var res = await _aiService.AiDetail(paramDto);
|
|
return res;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取学校信息
|
|
/// </summary>
|
|
/// <param name="paramDto"></param>
|
|
/// <returns></returns>
|
|
[HttpGet("school/detail")]
|
|
public async Task<Ai_SchoolDto> AiSchoolDetail(Ai_SchoolRequest paramDto)
|
|
{
|
|
var res = await _aiService.AiSchoolDetail(paramDto);
|
|
return res;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 学生
|
|
/// </summary>
|
|
/// <param name="paramDto"></param>
|
|
/// <returns></returns>
|
|
[HttpGet("student/list")]
|
|
public async Task<List<Ai_StudentListDto>> StudentList(Ai_StudentListRequest paramDto)
|
|
{
|
|
var res = await _aiService.StudentList(paramDto);
|
|
return res;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 学生详情
|
|
/// </summary>
|
|
/// <param name="paramDto"></param>
|
|
/// <returns></returns>
|
|
[HttpGet("student/detail")]
|
|
public async Task<Ai_StudentDetailsDto> StudentDetail(Ai_StudentDetailRequest paramDto)
|
|
{
|
|
var res = await _aiService.StudentDetail(paramDto);
|
|
return res;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 阿里云OSS获取上传文件的签名
|
|
/// </summary>
|
|
/// <param name="paramDto"></param>
|
|
/// <returns></returns>
|
|
[HttpGet("oss/policy")]
|
|
public async Task<Ai_OSSSignDto> OSSPolicy(Ai_Request paramDto)
|
|
{
|
|
return new Ai_OSSSignDto()
|
|
{
|
|
Accessid = "1",
|
|
Policy = 1,
|
|
Dir = "/",
|
|
Expire = "30",
|
|
Host = "127.0.0.1",
|
|
Signature = "xxxx"
|
|
};
|
|
}
|
|
|
|
/// <summary>
|
|
/// 阿里云OSS获取上传文件的配置信息
|
|
/// </summary>
|
|
/// <param name="paramDto"></param>
|
|
/// <returns></returns>
|
|
[HttpGet("oss/info")]
|
|
public async Task<Ai_OSSInfoDto> OSSInfo(Ai_Request paramDto)
|
|
{
|
|
return new Ai_OSSInfoDto()
|
|
{
|
|
Accessid = "1",
|
|
AccessKeySecret = "1",
|
|
BucketName = "1",
|
|
Endpoint = "127.0.0.1",
|
|
Prefix = "1"
|
|
};
|
|
}
|
|
|
|
/// <summary>
|
|
/// 局域网OSS上传文件
|
|
/// </summary>
|
|
/// <param name="file"></param>
|
|
/// <returns></returns>
|
|
|
|
[HttpPost("oss/upload")]
|
|
public async Task<Ai_OSSUploadDto> OSSUpload(IFormFile file)
|
|
{
|
|
Logger.Info(LoggerType.System, "局域网OSS上传文件");
|
|
|
|
return new Ai_OSSUploadDto()
|
|
{
|
|
FileName = "FileName",
|
|
Url = "/"
|
|
};
|
|
}
|
|
|
|
/// <summary>
|
|
/// AI设备上传学生测试成绩
|
|
/// </summary>
|
|
/// <param name="paramDto"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("result/upload")]
|
|
public async Task<IActionResult> ResultUpload([FromBody] Ai_ResultUploadRequest paramDto)
|
|
{
|
|
await _aiService.ResultUpload(paramDto);
|
|
return Ok("上传成功");
|
|
}
|
|
|
|
/// <summary>
|
|
/// 接收AI设备的心跳
|
|
/// </summary>
|
|
/// <param name="paramDto"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("device/heartbeat")]
|
|
public async Task<IActionResult> Heartbeat([FromBody] Ai_Request paramDto)
|
|
{
|
|
Logger.Info(LoggerType.System, paramDto.Serialize(), paramDto.Serialize(), "接收AI设备的心跳");
|
|
return Ok("上传成功");
|
|
}
|
|
|
|
/// <summary>
|
|
/// AI设备上传成绩关联文件
|
|
/// </summary>
|
|
/// <param name="paramDto"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("result/files")]
|
|
public async Task<IActionResult> ResultFiles([FromBody] Ai_Request paramDto)
|
|
{
|
|
Logger.Info(LoggerType.System, paramDto.Serialize(), paramDto.Serialize(), "AI设备上传成绩关联文件");
|
|
return Ok("上传成功");
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取项目类型
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[HttpGet(nameof(GetAiCategoryType))]
|
|
public async Task<List<Ai_ItemTypeModel>> GetAiCategoryType()
|
|
{
|
|
return await _aiService.GetAiCategoryType();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 年级班级
|
|
/// </summary>
|
|
/// <param name="deviceSn"></param>
|
|
/// <returns></returns>
|
|
[HttpGet("school/grades")]
|
|
public async Task<List<Grades>> AiGradesList(string deviceSn)
|
|
{
|
|
var res = await _aiService.AiGradesList(deviceSn);
|
|
return res;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 成绩排名
|
|
/// </summary>
|
|
/// <param name="deviceSn"></param>
|
|
/// <returns></returns>
|
|
[HttpGet("result/ranking")]
|
|
public async Task<List<Ai_RankingListDto>> AiGradesList([FromQuery] Ai_RankingListRequest paramDto)
|
|
{
|
|
var res = await _aiService.AiScoreRanking(paramDto);
|
|
return res;
|
|
}
|
|
}
|
|
}
|