From d9ef6a167e54d4b8b298ccf4ab02eb5154dd2bd6 Mon Sep 17 00:00:00 2001
From: tanglong <842690096@qq.com>
Date: Thu, 30 Oct 2025 13:00:35 +0800
Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BA=BA=E8=84=B8?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../Dto/Open/AddWeBankUserFaceDto.cs | 15 ++
.../net6.0/YD_XinWei.Commons.AssemblyInfo.cs | 2 +-
...YD_XinWei.Commons.AssemblyInfoInputs.cache | 2 +-
.../YD_XinWei/Controllers/XinWeiController.cs | 13 ++
.../YD_XinWei/Services/Impl/XinWeiService.cs | 23 +++
.../Services/Interface/IXinWeiService.cs | 7 +
Server/YD_XinWei/Utilities/ALiYunOss.cs | 143 ++++++++++++++++++
Server/YD_XinWei/Utilities/AppSettings.cs | 93 +++++++-----
Server/YD_XinWei/appsettings.json | 9 ++
.../obj/Debug/net6.0/ApiEndpoints.json | 36 +++++
.../net6.0/EndpointInfo/YD_XinWei.Api.json | 68 +++++++++
.../net6.0/YD_XinWei.Api.AssemblyInfo.cs | 2 +-
.../YD_XinWei.Api.AssemblyInfoInputs.cache | 2 +-
..._XinWei.Api.csproj.AssemblyReference.cache | Bin 22505 -> 22605 bytes
Server/YD_XinWei/obj/Debug/net6.0/apphost.exe | Bin 151040 -> 151040 bytes
15 files changed, 377 insertions(+), 38 deletions(-)
create mode 100644 Server/YD_XinWei.Commons/Dto/Open/AddWeBankUserFaceDto.cs
create mode 100644 Server/YD_XinWei/Utilities/ALiYunOss.cs
diff --git a/Server/YD_XinWei.Commons/Dto/Open/AddWeBankUserFaceDto.cs b/Server/YD_XinWei.Commons/Dto/Open/AddWeBankUserFaceDto.cs
new file mode 100644
index 0000000..7f08a1d
--- /dev/null
+++ b/Server/YD_XinWei.Commons/Dto/Open/AddWeBankUserFaceDto.cs
@@ -0,0 +1,15 @@
+using Microsoft.AspNetCore.Http;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace YD_XinWei.Commons.Dto.Open
+{
+ public class AddWeBankUserFaceDto
+ {
+ public int UserId { get; set; }
+ public IFormFile PicUrlA { get; set; }
+ }
+}
diff --git a/Server/YD_XinWei.Commons/obj/Debug/net6.0/YD_XinWei.Commons.AssemblyInfo.cs b/Server/YD_XinWei.Commons/obj/Debug/net6.0/YD_XinWei.Commons.AssemblyInfo.cs
index 28f58ef..fb235f1 100644
--- a/Server/YD_XinWei.Commons/obj/Debug/net6.0/YD_XinWei.Commons.AssemblyInfo.cs
+++ b/Server/YD_XinWei.Commons/obj/Debug/net6.0/YD_XinWei.Commons.AssemblyInfo.cs
@@ -14,7 +14,7 @@ using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("YD_XinWei.Commons")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
-[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+9efa54fc9112aa3e7fc065c5055a05260858c013")]
+[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+11cd01c9e34d6d14a8b8b162a2061662baefd602")]
[assembly: System.Reflection.AssemblyProductAttribute("YD_XinWei.Commons")]
[assembly: System.Reflection.AssemblyTitleAttribute("YD_XinWei.Commons")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
diff --git a/Server/YD_XinWei.Commons/obj/Debug/net6.0/YD_XinWei.Commons.AssemblyInfoInputs.cache b/Server/YD_XinWei.Commons/obj/Debug/net6.0/YD_XinWei.Commons.AssemblyInfoInputs.cache
index 43ae660..1fe3f36 100644
--- a/Server/YD_XinWei.Commons/obj/Debug/net6.0/YD_XinWei.Commons.AssemblyInfoInputs.cache
+++ b/Server/YD_XinWei.Commons/obj/Debug/net6.0/YD_XinWei.Commons.AssemblyInfoInputs.cache
@@ -1 +1 @@
-969a4a6c36c831881df492a490d81a260eb7b441da8fcb9718db314cc018b26d
+a9221cd8adc502c2d9936f3952d45bcfae80eabea5c75cf6e597e715edc85d39
diff --git a/Server/YD_XinWei/Controllers/XinWeiController.cs b/Server/YD_XinWei/Controllers/XinWeiController.cs
index 9b1a045..9907ae3 100644
--- a/Server/YD_XinWei/Controllers/XinWeiController.cs
+++ b/Server/YD_XinWei/Controllers/XinWeiController.cs
@@ -227,5 +227,18 @@ namespace YD_XinWei.Api.Controllers
var res = await _xinWeiService.GetProjectInfo(orgId);
return res;
}
+
+ ///
+ /// 设备端人脸录入
+ ///
+ ///
+ ///
+ [HttpPut]
+ [Route("/basic/{apiVersion}/open/addWeBankUserFace")]
+ public async Task AddWeBankUserFace(IFormFile picUrlA, int userId)
+ {
+ var res = await _xinWeiService.AddWeBankUserFace(new AddWeBankUserFaceDto() { PicUrlA = picUrlA, UserId = userId });
+ return res;
+ }
}
}
diff --git a/Server/YD_XinWei/Services/Impl/XinWeiService.cs b/Server/YD_XinWei/Services/Impl/XinWeiService.cs
index 686a1ca..1a4d46f 100644
--- a/Server/YD_XinWei/Services/Impl/XinWeiService.cs
+++ b/Server/YD_XinWei/Services/Impl/XinWeiService.cs
@@ -912,5 +912,28 @@ namespace YD_XinWei.Api.Services.Impl
return res;
}
+
+ ///
+ /// 设备端人脸录入
+ ///
+ ///
+ ///
+ public async Task AddWeBankUserFace(AddWeBankUserFaceDto dto)
+ {
+ if (dto == null || dto.PicUrlA.Length == 0 || dto.UserId == 0)
+ return false;
+
+ var student = await _sportsContext.Student.Where(x => x.Id == dto.UserId).FirstOrDefaultAsync();
+ if (student == null)
+ return false;
+
+ var gradeId = await _sportsContext.Class.Where(x => x.Id == student.ClassId).Select(x => x.GradeId).FirstOrDefaultAsync();
+ var url = ALiYunOss.Upload(dto.PicUrlA, $"Upload/{student.SchoolCode}/Photo/Student/{gradeId}/{student.ClassId}/", student.StudentNo);
+
+ student.Photo = url;
+ _sportsContext.Student.Update(student);
+
+ return await _sportsContext.SaveChangesAsync() > 0;
+ }
}
}
diff --git a/Server/YD_XinWei/Services/Interface/IXinWeiService.cs b/Server/YD_XinWei/Services/Interface/IXinWeiService.cs
index bb27fb0..24648bb 100644
--- a/Server/YD_XinWei/Services/Interface/IXinWeiService.cs
+++ b/Server/YD_XinWei/Services/Interface/IXinWeiService.cs
@@ -127,5 +127,12 @@ namespace YD_XinWei.Api.Services.Interface
///
///
Task> GetProjectInfo(int orgId);
+
+ ///
+ /// 设备端人脸录入
+ ///
+ ///
+ ///
+ Task AddWeBankUserFace(AddWeBankUserFaceDto dto);
}
}
diff --git a/Server/YD_XinWei/Utilities/ALiYunOss.cs b/Server/YD_XinWei/Utilities/ALiYunOss.cs
new file mode 100644
index 0000000..9d76144
--- /dev/null
+++ b/Server/YD_XinWei/Utilities/ALiYunOss.cs
@@ -0,0 +1,143 @@
+using Aliyun.OSS;
+using System.Net;
+
+namespace YD_XinWei.Api.Utilities
+{
+
+ ///
+ /// 阿里云Oss
+ ///
+ public class ALiYunOss
+ {
+ ///
+ /// 上传
+ ///
+ /// 是否包含文件后缀名
+ ///
+ public static string Upload(IFormFile file, string filePath, string fileName, bool isIncludeExtension = false)
+ {
+ if (file == null || file.Length == 0)
+ {
+ throw new ArgumentNullException("上传文件为空");
+ }
+ var url = string.Empty;
+
+ if (!isIncludeExtension)
+ {
+ // 拼接文件后缀名
+ var extension = Path.GetExtension(file.FileName);
+ filePath += fileName + extension;
+ }
+ else
+ {
+ filePath += fileName;
+ }
+
+ var stream = new MemoryStream();
+ file.CopyTo(stream);
+ stream.Position = 0;
+
+ // 创建OSSClient实例
+ var client = new OssClient(
+ AppSettings.ALiYunOSS.Endpoint,
+ AppSettings.ALiYunOSS.AccessKeyId,
+ AppSettings.ALiYunOSS.SecretAccessKey);
+
+ try
+ {
+ // 上传文件
+ var result = client.PutObject(AppSettings.YueDongServerOSS.BucketName, filePath, stream);
+ var uri = client.GeneratePresignedUri(AppSettings.YueDongServerOSS.BucketName, filePath);
+ url = "https://" + uri.Host + uri.LocalPath;
+ if (result.HttpStatusCode != HttpStatusCode.OK)
+ throw new Exception("上传失败");
+ }
+ catch (Exception ex)
+ {
+ throw new Exception("上传失败!");
+ }
+ finally
+ {
+ stream.Dispose();
+ }
+
+ return url;
+ }
+
+ ///
+ /// 获取指定前缀目录下的所有文件列表
+ ///
+ /// 目录前缀,例如"student/"
+ /// 文件键列表
+ public static Dictionary GetFileFromOss(string prefix)
+ {
+ var client = new OssClient(
+ AppSettings.ALiYunOSS.Endpoint,
+ AppSettings.ALiYunOSS.AccessKeyId,
+ AppSettings.ALiYunOSS.SecretAccessKey);
+
+ var listObjectsRequest = new ListObjectsRequest(AppSettings.YueDongServerOSS.BucketName)
+ {
+ Prefix = prefix
+ };
+
+ var result = client.ListObjects(listObjectsRequest);
+
+ Dictionary imageDataDict = new Dictionary();
+ foreach (var obj in result.ObjectSummaries)
+ {
+ // Fetch the object data from OSS
+ var objectData = client.GetObject(AppSettings.YueDongServerOSS.BucketName, obj.Key);
+ using (var memoryStream = new MemoryStream())
+ {
+ objectData.Content.CopyTo(memoryStream);
+ byte[] imageBytes = memoryStream.ToArray();
+ string base64Image = Convert.ToBase64String(imageBytes);
+ imageDataDict.Add(obj.Key, base64Image); // Store the file name and base64 data
+ }
+ }
+
+ return imageDataDict;
+ }
+
+ ///
+ /// 根据前缀删除指定路径下的所有文件
+ ///
+ /// 目录前缀,例如"student/"
+ public static void DeleteFilesByPrefix(string prefix)
+ {
+ var client = new OssClient(
+ AppSettings.ALiYunOSS.Endpoint,
+ AppSettings.ALiYunOSS.AccessKeyId,
+ AppSettings.ALiYunOSS.SecretAccessKey);
+
+ // 列出指定前缀的所有文件
+ var listObjectsRequest = new ListObjectsRequest(AppSettings.YueDongServerOSS.BucketName)
+ {
+ Prefix = prefix
+ };
+
+ var result = client.ListObjects(listObjectsRequest);
+
+ // 如果没有找到文件,直接返回
+ if (result.ObjectSummaries.Count() == 0)
+ {
+ return;
+ }
+
+ // 删除所有文件
+ foreach (var obj in result.ObjectSummaries)
+ {
+ try
+ {
+ // 删除文件
+ client.DeleteObject(AppSettings.YueDongServerOSS.BucketName, obj.Key);
+ }
+ catch (Exception ex)
+ {
+ throw new Exception("删除失败!");
+ }
+ }
+ }
+ }
+}
diff --git a/Server/YD_XinWei/Utilities/AppSettings.cs b/Server/YD_XinWei/Utilities/AppSettings.cs
index d05e684..d8303af 100644
--- a/Server/YD_XinWei/Utilities/AppSettings.cs
+++ b/Server/YD_XinWei/Utilities/AppSettings.cs
@@ -1,4 +1,6 @@
-namespace YD_XinWei.Api.Utilities
+using Autofac.Core;
+
+namespace YD_XinWei.Api.Utilities
{
public static class AppSettings
{
@@ -13,6 +15,16 @@
public static string RedisConnectionString { get; set; }
public static WeChatConfig WeChat { get; set; }
+ ///
+ /// 阿里云OSS
+ ///
+ public static ALiYunOSS ALiYunOSS { get; set; }
+
+ ///
+ /// YueDongServerOSS
+ ///
+ public static YueDongServerOSS YueDongServerOSS { get; set; }
+
public static void Init(IConfiguration configuration)
{
Logging = configuration.GetSection("Logging").Get();
@@ -24,41 +36,54 @@
RedisConnectionString = configuration["RedisConnectionString"];
CorsUrls = configuration["CorsUrls"].Split(',');
WeChat = configuration.GetSection("WeChat").Get();
- }
- public class LoggingConfig
- {
- public LogLevelConfig LogLevel { get; set; }
- }
-
- public class LogLevelConfig
- {
- public string Default { get; set; }
- public string Microsoft { get; set; }
- public string MicrosoftHostingLifetime { get; set; }
- }
-
- public class VirtualPathConfig
- {
- public string StaticFile { get; set; }
- public string FolderName { get; set; }
- }
-
- public class SecretConfig
- {
- public string JWT { get; set; }
- public string Audience { get; set; }
- public string Issuer { get; set; }
- public string User { get; set; }
- public string DB { get; set; }
- public string Redis { get; set; }
- }
-
- public class WeChatConfig
- {
- public string Appid { get; set; }
- public string Secret { get; set; }
+ ALiYunOSS = configuration.GetSection("ALiYunOSS").Get();
+ YueDongServerOSS = configuration.GetSection("YueDongServerOSS").Get();
}
}
+ public class LoggingConfig
+ {
+ public LogLevelConfig LogLevel { get; set; }
+ }
+
+ public class LogLevelConfig
+ {
+ public string Default { get; set; }
+ public string Microsoft { get; set; }
+ public string MicrosoftHostingLifetime { get; set; }
+ }
+
+ public class VirtualPathConfig
+ {
+ public string StaticFile { get; set; }
+ public string FolderName { get; set; }
+ }
+
+ public class SecretConfig
+ {
+ public string JWT { get; set; }
+ public string Audience { get; set; }
+ public string Issuer { get; set; }
+ public string User { get; set; }
+ public string DB { get; set; }
+ public string Redis { get; set; }
+ }
+
+ public class WeChatConfig
+ {
+ public string Appid { get; set; }
+ public string Secret { get; set; }
+ }
+ public class ALiYunOSS
+ {
+ public string AccessKeyId { get; set; }
+ public string SecretAccessKey { get; set; }
+ public string Endpoint { get; set; }
+ }
+ public class YueDongServerOSS
+ {
+ public string BucketName { get; set; }
+ public string Prefix { get; set; }
+ }
}
diff --git a/Server/YD_XinWei/appsettings.json b/Server/YD_XinWei/appsettings.json
index 3a1c5b8..d8042e2 100644
--- a/Server/YD_XinWei/appsettings.json
+++ b/Server/YD_XinWei/appsettings.json
@@ -38,5 +38,14 @@
"WeChat": {
"Appid": "xxx",
"Secret": "xxx"
+ },
+ "ALiYunOSS": {
+ "AccessKeyId": "LTAI5tDQAYU8PbXN7tcxW6Qw",
+ "SecretAccessKey": "oVpeH1PpDUnWTcBrUSSYkQNS4Fex8Y",
+ "Endpoint": "oss-cn-shanghai.aliyuncs.com"
+ },
+ "YueDongServerOSS": {
+ "BucketName": "yuedong-server",
+ "Prefix": "Upload"
}
}
diff --git a/Server/YD_XinWei/obj/Debug/net6.0/ApiEndpoints.json b/Server/YD_XinWei/obj/Debug/net6.0/ApiEndpoints.json
index 528e9ef..19be6ff 100644
--- a/Server/YD_XinWei/obj/Debug/net6.0/ApiEndpoints.json
+++ b/Server/YD_XinWei/obj/Debug/net6.0/ApiEndpoints.json
@@ -30,6 +30,42 @@
}
]
},
+ {
+ "ContainingType": "YD_XinWei.Api.Controllers.XinWeiController",
+ "Method": "AddWeBankUserFace",
+ "RelativePath": "basic/{apiVersion}/open/addWeBankUserFace",
+ "HttpMethod": "PUT",
+ "IsController": true,
+ "Order": 0,
+ "Parameters": [
+ {
+ "Name": "picUrlA",
+ "Type": "Microsoft.AspNetCore.Http.IFormFile",
+ "IsRequired": false
+ },
+ {
+ "Name": "userId",
+ "Type": "System.Int32",
+ "IsRequired": false
+ },
+ {
+ "Name": "apiVersion",
+ "Type": "",
+ "IsRequired": true
+ }
+ ],
+ "ReturnTypes": [
+ {
+ "Type": "System.Boolean",
+ "MediaTypes": [
+ "text/plain",
+ "application/json",
+ "text/json"
+ ],
+ "StatusCode": 200
+ }
+ ]
+ },
{
"ContainingType": "YD_XinWei.Api.Controllers.XinWeiController",
"Method": "GetFaceListOfDevicePage",
diff --git a/Server/YD_XinWei/obj/Debug/net6.0/EndpointInfo/YD_XinWei.Api.json b/Server/YD_XinWei/obj/Debug/net6.0/EndpointInfo/YD_XinWei.Api.json
index e9b378e..1cfbc47 100644
--- a/Server/YD_XinWei/obj/Debug/net6.0/EndpointInfo/YD_XinWei.Api.json
+++ b/Server/YD_XinWei/obj/Debug/net6.0/EndpointInfo/YD_XinWei.Api.json
@@ -1216,6 +1216,74 @@
}
}
}
+ },
+ "/basic/{apiVersion}/open/addWeBankUserFace": {
+ "put": {
+ "tags": [
+ "XinWei"
+ ],
+ "summary": "设备端人脸录入",
+ "parameters": [
+ {
+ "name": "userId",
+ "in": "query",
+ "schema": {
+ "type": "integer",
+ "format": "int32"
+ }
+ },
+ {
+ "name": "apiVersion",
+ "in": "path",
+ "required": true,
+ "schema": {
+ "type": "string"
+ }
+ }
+ ],
+ "requestBody": {
+ "content": {
+ "multipart/form-data": {
+ "schema": {
+ "type": "object",
+ "properties": {
+ "picUrlA": {
+ "type": "string",
+ "format": "binary"
+ }
+ }
+ },
+ "encoding": {
+ "picUrlA": {
+ "style": "form"
+ }
+ }
+ }
+ }
+ },
+ "responses": {
+ "200": {
+ "description": "Success",
+ "content": {
+ "text/plain": {
+ "schema": {
+ "type": "boolean"
+ }
+ },
+ "application/json": {
+ "schema": {
+ "type": "boolean"
+ }
+ },
+ "text/json": {
+ "schema": {
+ "type": "boolean"
+ }
+ }
+ }
+ }
+ }
+ }
}
},
"components": {
diff --git a/Server/YD_XinWei/obj/Debug/net6.0/YD_XinWei.Api.AssemblyInfo.cs b/Server/YD_XinWei/obj/Debug/net6.0/YD_XinWei.Api.AssemblyInfo.cs
index bec2f55..a860a81 100644
--- a/Server/YD_XinWei/obj/Debug/net6.0/YD_XinWei.Api.AssemblyInfo.cs
+++ b/Server/YD_XinWei/obj/Debug/net6.0/YD_XinWei.Api.AssemblyInfo.cs
@@ -14,7 +14,7 @@ using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("YD_XinWei.Api")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
-[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+9efa54fc9112aa3e7fc065c5055a05260858c013")]
+[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+11cd01c9e34d6d14a8b8b162a2061662baefd602")]
[assembly: System.Reflection.AssemblyProductAttribute("YD_XinWei.Api")]
[assembly: System.Reflection.AssemblyTitleAttribute("YD_XinWei.Api")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
diff --git a/Server/YD_XinWei/obj/Debug/net6.0/YD_XinWei.Api.AssemblyInfoInputs.cache b/Server/YD_XinWei/obj/Debug/net6.0/YD_XinWei.Api.AssemblyInfoInputs.cache
index cce966c..554de09 100644
--- a/Server/YD_XinWei/obj/Debug/net6.0/YD_XinWei.Api.AssemblyInfoInputs.cache
+++ b/Server/YD_XinWei/obj/Debug/net6.0/YD_XinWei.Api.AssemblyInfoInputs.cache
@@ -1 +1 @@
-d59d3583c895d140f4361bdf32eb75e79da767c3850e31f97b2bd9a44ed8184f
+fba16e66043b8885ec0cd85a53aee89b6246d24a8a3a9bea59c28cea15ba55ec
diff --git a/Server/YD_XinWei/obj/Debug/net6.0/YD_XinWei.Api.csproj.AssemblyReference.cache b/Server/YD_XinWei/obj/Debug/net6.0/YD_XinWei.Api.csproj.AssemblyReference.cache
index 54c8e9c5243a495412bc27c74f0059500cefa625..eab4ece3dc06f6a26d48841872e295f04a0697b7 100644
GIT binary patch
delta 56
zcmV-80LTC7uK~@l0g!P9&1k(rY!{(-0Rb1YcmY`k0V0!e92Jw_1O*31Wnpx6a%Gd?
O0WOmr1r)Q<2N+ORofDM+
delta 30
mcmX@Rf$`;f#tDUNQN=UAZWLQs&d4aXxq>m0ZL=wdL;wKHnF~|^
diff --git a/Server/YD_XinWei/obj/Debug/net6.0/apphost.exe b/Server/YD_XinWei/obj/Debug/net6.0/apphost.exe
index e082a71b26c47aab1d57840b49f669fad2755761..3b0baff1c9cd39ecf2db2ad1deba988dabfc89df 100644
GIT binary patch
delta 99
zcmZpe!`T2tEsR^347~jf84MYc8B!Pwz_cYpDuXeD36O6F#D+jtB7+4(5*Ql-#f*S_
eBcNI{pqv?)p9B<1Wk>_-Fkmp+UhmD+$OHhquMw*N
delta 99
zcmZpe!`T2tEsR^347~j<8B!V27!nyw8BBn5GJ_?9ArKk?MG_f|fpX?xQ3D1upo(N5
gHUMH%pd5%c0*V?iSO8fTKsf`TKI856-b{^50L!BhTL1t6