fix 代码合并,minio上传文件

This commit is contained in:
2024-01-26 18:22:57 +08:00
parent f83afdb4d0
commit 05c2073ea7
57 changed files with 637 additions and 203 deletions

View File

@@ -27,7 +27,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Dlhis.Sys", "Src\Dlhis.Sys\
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Dlhis.Canteen", "Src\Dlhis.Canteen\Dlhis.Canteen.csproj", "{8317C526-3523-4195-9B19-2F17CFD71927}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Dlhis.Canteen", "Src\Dlhis.Canteen\Dlhis.Canteen.csproj", "{8317C526-3523-4195-9B19-2F17CFD71927}"
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Dlhis.User.Api", "Src\Dlhis.User.Api\Dlhis.User.Api.csproj", "{F294CD7D-0412-48AD-A7E9-E72B9BA0E48E}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Dlhis.Sys.Api", "Src\Dlhis.User.Api\Dlhis.Sys.Api.csproj", "{F294CD7D-0412-48AD-A7E9-E72B9BA0E48E}"
EndProject EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution

View File

@@ -24,7 +24,7 @@
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\Dlhis.Common.Api\Dlhis.Common.Api.csproj" /> <ProjectReference Include="..\Dlhis.Common.Api\Dlhis.Common.Api.csproj" />
<ProjectReference Include="..\Dlhis.Entity\Dlhis.Entity.csproj" /> <ProjectReference Include="..\Dlhis.Entity\Dlhis.Entity.csproj" />
<ProjectReference Include="..\Dlhis.User.Api\Dlhis.User.Api.csproj" /> <ProjectReference Include="..\Dlhis.User.Api\Dlhis.Sys.Api.csproj" />
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@@ -7,7 +7,7 @@
}, },
"InternalRequest": { "InternalRequest": {
"CommonRequestUrl": "http://localhost:5001", "CommonRequestUrl": "http://localhost:5001",
"UserRequestUrl": "http://localhost:5004" "SysRequestUrl": "http://localhost:5003"
}, },
"SwaggerOptions": { "SwaggerOptions": {
"Enable": true, "Enable": true,

View File

@@ -8,7 +8,7 @@
"AllowedHosts": "*", "AllowedHosts": "*",
"InternalRequest": { "InternalRequest": {
"CommonRequestUrl": "http://common", "CommonRequestUrl": "http://common",
"UserRequestUrl": "http://user" "SysRequestUrl": "http://sys"
}, },
"FaceUrlOptions": { "FaceUrlOptions": {
"Url": "https://yikatong.isawesome.cn/api/basic/gainfos/face?token=", "Url": "https://yikatong.isawesome.cn/api/basic/gainfos/face?token=",

View File

@@ -20,10 +20,6 @@
<ProjectReference Include="..\Dlhis.Entity\Dlhis.Entity.csproj" /> <ProjectReference Include="..\Dlhis.Entity\Dlhis.Entity.csproj" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<Folder Include="FileOperation\" />
</ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Kurisu.AspNetCore" Version="0.5.2" /> <PackageReference Include="Kurisu.AspNetCore" Version="0.5.2" />
<PackageReference Include="Minio" Version="6.0.1" /> <PackageReference Include="Minio" Version="6.0.1" />

View File

@@ -1,5 +1,5 @@
using System.Reflection; using System.Reflection;
using Dlhis.Common.Response; using Dlhis.Common.FileOperation.Response;
using Dlhis.Entity.Basic.Entity; using Dlhis.Entity.Basic.Entity;
using Kurisu.AspNetCore.Utils.Extensions; using Kurisu.AspNetCore.Utils.Extensions;
using Kurisu.SqlSugar.Services; using Kurisu.SqlSugar.Services;

View File

@@ -0,0 +1,20 @@
using System.ComponentModel.DataAnnotations;
using Kurisu.Core.ConfigurableOptions.Attributes;
namespace Dlhis.Common.FileOperation.Configurations;
[Configuration("MinIO")]
public class MinIOOptions
{
[Required]
public string Endpoint { get; set; }
[Required]
public string AccessKey { get; set; }
[Required]
public string SecretKey { get; set; }
public string DefaultBucket { get; set; }
}

View File

@@ -0,0 +1,73 @@
using Dlhis.Common.FileOperation.Request;
using Dlhis.Common.FileOperation.Response;
using Dlhis.Common.FileOperation.Services;
using Dlhis.Common.Request;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
namespace Dlhis.Common.FileOperation.Controllers;
/// <summary>
/// 文件上传/下载
/// </summary>
[Authorize]
[Route("api/[controller]")]
[ApiController]
public class ApkFileController : ControllerBase
{
private IApkFIileService _apkFIileService;
public ApkFileController(IApkFIileService apkFIileService)
{
_apkFIileService = apkFIileService;
}
/// <summary>
/// minlo文件上传
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
[HttpPost("minlo")]
public async Task<ApkFileResponse> FormSingleFileUpload([FromForm] ApkRequest request)
{
return await _apkFIileService.FormSingleFileUpload(request);
}
/// <summary>
/// minlo文件下载
/// </summary>
/// <param name="fileName"></param>
/// <returns></returns>
[HttpGet("url")]
public async Task<string> RequestDownloadFile(string fileName)
{
return await _apkFIileService.RequestDownloadFile(fileName);
}
/// <summary>
/// 本地文件上传
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
[HttpPost("local")]
[RequestSizeLimit(100_000_0000)]
public async Task<ApkFileResponse> FormLocalFileUpload([FromForm] ApkRequest request)
{
return await _apkFIileService.FormLocalFileUpload(request);
}
/// <summary>
/// 本地文件下载
/// </summary>
/// <param name="filePath"></param>
/// <returns></returns>
[HttpGet("local")]
public IActionResult FormLocalDownloadFile(string filePath)
{
return _apkFIileService.FormLocalDownloadFile(filePath);
}
}

View File

@@ -0,0 +1,30 @@
using Dlhis.Common.FileOperation.Request;
using Dlhis.Common.FileOperation.Services;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
namespace Dlhis.Common.FileOperation.Controllers;
[Authorize]
[Route("api/[controller]")]
[ApiController]
public class FileController : ControllerBase
{
private readonly IMinioService _minioService;
public FileController(IMinioService minioService)
{
_minioService = minioService;
}
/// <summary>
/// 文件上传
/// </summary>
/// <param name="request"></param>
/// <returns>相对路径</returns>
[HttpPost("{Bucket}/upload")]
public async Task<string> UploadFileAsync([FromForm] UploadFileReuqest request)
{
return await _minioService.UploadFileAsync(request.Bucket, request.File);
}
}

View File

@@ -0,0 +1,11 @@
using Microsoft.AspNetCore.Mvc;
namespace Dlhis.Common.FileOperation.Request;
public class UploadFileReuqest
{
[FromRoute]
public string Bucket { get; set; }
public IFormFile File { get; set; }
}

View File

@@ -0,0 +1,27 @@
using SqlSugar;
namespace Dlhis.Common.FileOperation.Response
{
public class ApkFileResponse
{
/// <summary>
/// 文件名称
/// </summary>
public string Name { get; set; }
/// <summary>
/// 地址
/// </summary>
public string Url { get; set; }
/// <summary>
/// 版本号
/// </summary>
public int VersionCode { get; set; }
/// <summary>
/// 修改信息
/// </summary>
public string UpdateMessage { get; set; }
}
}

View File

@@ -1,4 +1,4 @@
namespace Dlhis.Common.Response namespace Dlhis.Common.FileOperation.Response
{ {
public class CommonEnumResponse public class CommonEnumResponse
{ {

View File

@@ -0,0 +1,8 @@
namespace Dlhis.Common.FileOperation.Response;
public class KeyValueDto
{
public string Key { get; set; }
public object Value { get; set; }
}

View File

@@ -0,0 +1,38 @@
using Dlhis.Common.FileOperation.Request;
using Dlhis.Common.FileOperation.Response;
using Dlhis.Common.Request;
using Microsoft.AspNetCore.Mvc;
namespace Dlhis.Common.FileOperation.Services;
public interface IApkFIileService : IScopeDependency
{
/// <summary>
/// 文件上传
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
Task<ApkFileResponse> FormSingleFileUpload(ApkRequest request);
/// <summary>
/// 文件下载
/// </summary>
/// <returns></returns>
Task<string> RequestDownloadFile(string fileName);
/// <summary>
/// 本地上传
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
Task<ApkFileResponse> FormLocalFileUpload(ApkRequest request);
/// <summary>
/// 本地下载
/// </summary>
/// <param name="filePath"></param>
/// <returns></returns>
IActionResult FormLocalDownloadFile(string filePath);
}

View File

@@ -0,0 +1,21 @@
using Dlhis.Common.Request;
namespace Dlhis.Common.FileOperation.Services;
public interface IMinioService : ISingletonDependency
{
Task<string> MinloUploadFileAsync(ApkRequest request);
Task<string> MinloDownloadLinkAsync(string fileName);
Task MinloRemoveFileAsync(string fileName);
Task<bool> ExistsBucketAsync(string bucket);
Task<bool> ExistsFileAsync(string bucket, string objectName);
Task<string> UploadFileAsync(string bucket, IFormFile formFile);
}

View File

@@ -0,0 +1,162 @@
using Dlhis.Common.FileOperation.Request;
using Dlhis.Common.FileOperation.Response;
using Dlhis.Common.FileOperation.Services;
using Dlhis.Common.Request;
using Dlhis.Entity.Common;
using Kurisu.AspNetCore.Utils.Extensions;
using Kurisu.SqlSugar.Services;
using Mapster;
using Microsoft.AspNetCore.Mvc;
namespace Dlhis.Common.FileOperation.Services.Implements;
public class ApkFIileService : IApkFIileService
{
private readonly IMinioService _minioService;
private readonly IDbContext _dbContext;
public ApkFIileService(IMinioService minioService, IDbContext dbContext)
{
_minioService = minioService;
_dbContext = dbContext;
}
/// <summary>
/// 文件上传
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
public async Task<ApkFileResponse> FormSingleFileUpload(ApkRequest request)
{
//上传
var fileUrl = await _minioService.MinloUploadFileAsync(request);
string fileName = request.formFile.FileName;
//更新数据库
var entity = await _dbContext.Queryable<ApkFileEntity>().Where(x => x.Name == fileName).FirstAsync();
if (entity == null)
{
var info = new ApkFileEntity
{
Name = fileName,
Url = fileUrl,
VersionCode = request.VersionCode,
UpdateMessage = request.UpdateMessage,
};
await _dbContext.InsertAsync(info);
}
else
{
entity.Url = fileUrl;
entity.VersionCode = request.VersionCode;
entity.UpdateMessage = request.UpdateMessage;
await _dbContext.UpdateAsync(entity);
}
var newEntity = await _dbContext.Queryable<ApkFileEntity>().Where(x => x.Name == fileName).FirstAsync();
var res = newEntity.Adapt<ApkFileResponse>();
return res;
}
/// <summary>
/// 文件下载
/// </summary>
/// <returns></returns>
public async Task<string> RequestDownloadFile(string fileName)
{
return await _minioService.MinloDownloadLinkAsync(fileName);
}
/// <summary>
/// 本地文件上传
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
public async Task<ApkFileResponse> FormLocalFileUpload(ApkRequest request)
{
//上传
var completeFilePath = FormSingleFileUpload(request.formFile);
if (completeFilePath == "No file uploaded" || completeFilePath.IsEmpty())
{
return null;
}
//更新数据库
var fileName = request.formFile.FileName;
var entity = await _dbContext.Queryable<ApkFileEntity>().Where(x => x.Name == fileName).FirstAsync();
if (entity == null)
{
var info = new ApkFileEntity
{
Name = fileName,
Url = completeFilePath,
VersionCode = request.VersionCode,
UpdateMessage = request.UpdateMessage,
};
await _dbContext.InsertAsync(info);
}
else
{
entity.Url = completeFilePath;
entity.VersionCode = request.VersionCode;
entity.UpdateMessage = request.UpdateMessage;
await _dbContext.UpdateAsync(entity);
}
var newEntity = await _dbContext.Queryable<ApkFileEntity>().Where(x => x.Name == fileName).FirstAsync();
var res = newEntity.Adapt<ApkFileResponse>();
return res;
}
public string FormSingleFileUpload(IFormFile formFile)
{
try
{
var filePath = "D:\\apk\\";
// 创建存储文件夹
if (!Directory.Exists(filePath))
{
Directory.CreateDirectory(filePath);
}
if (formFile != null && formFile.Length > 0)
{
// 保存的文件名称
var saveName = Path.GetFileName(formFile.FileName);
// 文件保存
using (var fs = File.Create(Path.Combine(filePath, saveName)))
{
formFile.CopyTo(fs);
fs.Flush();
}
// 完整的文件路径
var completeFilePath = Path.Combine(filePath, saveName);
return completeFilePath;
}
else
{
return "No file uploaded";
}
}
catch (Exception)
{
return null;
throw;
}
}
/// <summary>
/// 本地下载
/// </summary>
/// <param name="filePath"></param>
/// <returns></returns>
public IActionResult FormLocalDownloadFile(string filePath)
{
string fileName = Path.GetFileName(filePath);
return new FileStreamResult(new FileStream(filePath, FileMode.Open), "application/octet-stream") { FileDownloadName = fileName };
}
}

View File

@@ -0,0 +1,134 @@
using Dlhis.Common.FileOperation.Configurations;
using Dlhis.Common.FileOperation.Request;
using Dlhis.Common.Request;
using Microsoft.Extensions.Options;
using Minio;
using Minio.DataModel.Args;
using Minio.Exceptions;
namespace Dlhis.Common.FileOperation.Services.Implements;
public class MinioService : IMinioService
{
private readonly IMinioClient _client;
private readonly MinIOOptions _minIOOptions;
public MinioService(IMinioClient client, IOptions<MinIOOptions> options)
{
_client = client;
_minIOOptions = options.Value;
}
public async Task<bool> ExistsBucketAsync(string bucket)
{
var args = new BucketExistsArgs().WithBucket(bucket);
return await _client.BucketExistsAsync(args);
}
public async Task CreateBucketIfNotExistsAsync(string bucket)
{
if (!await ExistsBucketAsync(bucket))
{
var policy = "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\",\"Principal\":{\"AWS\":[\"*\"]},\"Action\":[\"s3:GetBucketLocation\",\"s3:ListBucket\"],\"Resource\":[\"arn:aws:s3:::BUCKETNAME\"]},{\"Effect\":\"Allow\",\"Principal\":{\"AWS\":[\"*\"]},\"Action\":[\"s3:GetObject\"],\"Resource\":[\"arn:aws:s3:::BUCKETNAME/*\"]}]}".Replace("BUCKETNAME", bucket);
await _client.MakeBucketAsync(new MakeBucketArgs().WithBucket(bucket));
await _client.SetPolicyAsync(new SetPolicyArgs().WithBucket(bucket).WithPolicy(policy));
}
}
public async Task<bool> ExistsFileAsync(string bucket, string objectName)
{
try
{
var obj = new StatObjectArgs().WithBucket(bucket).WithObject(objectName);
var objStat = await _client.StatObjectAsync(obj);
}
catch (Exception)
{
return false;
}
return true;
}
public async Task<string> UploadFileAsync(string bucket, IFormFile formFile)
{
await CreateBucketIfNotExistsAsync(bucket);
var ms = DateTime.Now.ToString("yyyyMMddHHmmssfff");
var fileName = Path.GetFileNameWithoutExtension(formFile.FileName) + "_" + ms + Path.GetExtension(formFile.FileName);
fileName = $"{DateTime.Now.Year}/{DateTime.Now.Month}/{fileName}";
var response = await _client.PutObjectAsync(new PutObjectArgs().WithBucket(bucket)
.WithObject(fileName)
.WithObjectSize(formFile.Length)
.WithStreamData(formFile.OpenReadStream())
.WithContentType(formFile.ContentType)
.WithVersionId(bucket)
);
return $"/{bucket}/{response.ObjectName}";
}
/// <summary>
/// 上传文件
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
public async Task<string> MinloUploadFileAsync(ApkRequest request)
{
string fileName = request.formFile.FileName;
using (MemoryStream filestream = new MemoryStream())
{
await request.formFile.CopyToAsync(filestream);
filestream.Position = 0;
var res = await _client.PutObjectAsync(new PutObjectArgs()
.WithBucket(_minIOOptions.DefaultBucket)
.WithObject(fileName)
.WithStreamData(filestream)
.WithObjectSize(filestream.Length));
}
var filerl = await MinloDownloadLinkAsync(fileName);
return filerl;
}
/// <summary>
/// 文件下载链接
/// </summary>
/// <returns></returns>
public async Task<string> MinloDownloadLinkAsync(string fileName)
{
try
{
var url = await _client.PresignedGetObjectAsync(new PresignedGetObjectArgs()
.WithBucket(_minIOOptions.DefaultBucket)
.WithObject(fileName)
.WithExpiry(60 * 60 * 24 * 7));//链接时效
return url;
}
catch (MinioException e)
{
Console.Out.WriteLine("Error occurred: " + e);
return null;
}
}
/// <summary>
/// 单个删除文件
/// </summary>
/// <param name="fileName"></param>
/// <returns></returns>
public async Task MinloRemoveFileAsync(string fileName)
{
await _client.RemoveObjectAsync(new RemoveObjectArgs()
.WithBucket(_minIOOptions.DefaultBucket)
.WithObject(fileName));
}
}

View File

@@ -1,23 +1,25 @@
using Kurisu.AspNetCore.Startup; using Dlhis.Common.FileOperation.Configurations;
using Kurisu.AspNetCore.Startup;
using Microsoft.Extensions.Options;
using Minio; using Minio;
namespace Dlhis.Common.Packs; namespace Dlhis.Common.Packs;
public class MinioPack : BaseAppPack public class MinioPack : BaseAppPack
{
public override bool IsBeforeUseRouting { get; }
public override void ConfigureServices(IServiceCollection services)
{ {
public override bool IsBeforeUseRouting { get; } services.AddSingleton(sp =>
public override void ConfigureServices(IServiceCollection services)
{ {
//注入minioClient var config = sp.GetService<IOptions<MinIOOptions>>().Value;
IMinioClient minioClient = (MinioClient)new MinioClient() return new MinioClient().WithEndpoint(new Uri(config.Endpoint))
.WithEndpoint("192.168.199.124:9000") .WithCredentials(config.AccessKey, config.SecretKey)
.WithCredentials("Zbjj05OFtR19e5TJopQU", "UMXtNdZhufhAAyYJ3XND4cEgZNUsgOWtbUzksizK") .Build();
.Build(); });
services.AddSingleton(minioClient);
}
} }
}

View File

@@ -1,8 +0,0 @@
namespace Dlhis.Common.Response
{
public class KeyValueDto
{
public string Key { get; set; }
public object Value { get; set; }
}
}

View File

@@ -1,11 +0,0 @@
using Dlhis.Common.Request;
namespace Dlhis.Common.Services
{
public interface IMinioService : IScopeDependency
{
Task<string> MinloUploadFileAsync(ApkRequest request);
Task<string> MinloDownloadLinkAsync(string fileName);
Task MinloRemoveFileAsync(string fileName);
}
}

View File

@@ -1,4 +1,5 @@
using Dlhis.Common.Request; using Dlhis.Common.FileOperation.Services;
using Dlhis.Common.Request;
using Dlhis.Common.Response; using Dlhis.Common.Response;
using Dlhis.Entity.Common; using Dlhis.Entity.Common;
using Kurisu.AspNetCore.Utils.Extensions; using Kurisu.AspNetCore.Utils.Extensions;

View File

@@ -1,79 +0,0 @@
using Dlhis.Common.Request;
using Minio;
using Minio.DataModel.Args;
using Minio.Exceptions;
namespace Dlhis.Common.Services.Implements
{
public class MinioService : IMinioService
{
private readonly IMinioClient _client;
private static string bucketName = "apk";
public MinioService( IMinioClient client)
{
_client = client;
}
/// <summary>
/// 上传文件
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
public async Task<string> MinloUploadFileAsync(ApkRequest request)
{
string fileName = request.formFile.FileName;
using (MemoryStream filestream = new MemoryStream())
{
await request.formFile.CopyToAsync(filestream);
filestream.Position = 0;
var res = await _client.PutObjectAsync(new PutObjectArgs()
.WithBucket(bucketName)
.WithObject(fileName)
.WithStreamData(filestream)
.WithObjectSize(filestream.Length));
}
var filerl = await MinloDownloadLinkAsync(fileName);
return filerl;
}
/// <summary>
/// 文件下载链接
/// </summary>
/// <returns></returns>
public async Task<string> MinloDownloadLinkAsync(string fileName)
{
try
{
var url = await _client.PresignedGetObjectAsync(new PresignedGetObjectArgs()
.WithBucket(bucketName)
.WithObject(fileName)
.WithExpiry(60 * 60 * 24*7));//链接时效
return url;
}
catch (MinioException e)
{
Console.Out.WriteLine("Error occurred: " + e);
return null;
}
}
/// <summary>
/// 单个删除文件
/// </summary>
/// <param name="fileName"></param>
/// <returns></returns>
public async Task MinloRemoveFileAsync(string fileName)
{
await _client.RemoveObjectAsync(new RemoveObjectArgs()
.WithBucket(bucketName)
.WithObject(fileName));
}
}
}

View File

@@ -33,10 +33,10 @@
//服务器IP //服务器IP
"Endpoint": "http://192.168.199.124:9000", "Endpoint": "http://192.168.199.124:9000",
//账号 //账号
"AccessKey": "Zbjj05OFtR19e5TJopQU", "AccessKey": "oQ7tD55EVNElIoO3D43r",
//密码 //密码
"SecretKey": "UMXtNdZhufhAAyYJ3XND4cEgZNUsgOWtbUzksizK", "SecretKey": "3eWLaAFQ9fnFx8pOp5SgJogoF47ecAH6dcCWlyAp",
//默认存储桶 //默认存储桶
"Bucket": "apk" "DefaultBucket": "apk"
} }
} }

View File

@@ -45,7 +45,7 @@
//密码 //密码
"SecretKey": "UMXtNdZhufhAAyYJ3XND4cEgZNUsgOWtbUzksizK", "SecretKey": "UMXtNdZhufhAAyYJ3XND4cEgZNUsgOWtbUzksizK",
//apk默认存储桶 //apk默认存储桶
"Bucket": "apk" "DefaultBucket": "apk"
}, },
"Serilog": { "Serilog": {
"MinimumLevel": { "MinimumLevel": {

View File

@@ -22,11 +22,12 @@
<PackageReference Include="Hangfire.MySqlStorage" Version="2.0.3" /> <PackageReference Include="Hangfire.MySqlStorage" Version="2.0.3" />
<PackageReference Include="Kurisu.AspNetCore" Version="0.5.2" /> <PackageReference Include="Kurisu.AspNetCore" Version="0.5.2" />
<PackageReference Include="Microsoft.AspNetCore.DataProtection.StackExchangeRedis" Version="6.0.26" /> <PackageReference Include="Microsoft.AspNetCore.DataProtection.StackExchangeRedis" Version="6.0.26" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.19.4" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\Dlhis.Entity\Dlhis.Entity.csproj" /> <ProjectReference Include="..\Dlhis.Entity\Dlhis.Entity.csproj" />
<ProjectReference Include="..\Dlhis.User.Api\Dlhis.User.Api.csproj" /> <ProjectReference Include="..\Dlhis.User.Api\Dlhis.Sys.Api.csproj" />
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@@ -8,7 +8,7 @@ FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /src WORKDIR /src
COPY ["Src/Dlhis.ScheduledTask/Dlhis.ScheduledTask.csproj", "Src/Dlhis.ScheduledTask/"] COPY ["Src/Dlhis.ScheduledTask/Dlhis.ScheduledTask.csproj", "Src/Dlhis.ScheduledTask/"]
COPY ["Src/Dlhis.Entity/Dlhis.Entity.csproj", "Src/Dlhis.Entity/"] COPY ["Src/Dlhis.Entity/Dlhis.Entity.csproj", "Src/Dlhis.Entity/"]
COPY ["Src/Dlhis.User.Api/Dlhis.User.Api.csproj", "Src/Dlhis.User.Api/"] COPY ["Src/Dlhis.User.Api/Dlhis.Sys.Api.csproj", "Src/Dlhis.User.Api/"]
RUN dotnet restore "Src/Dlhis.ScheduledTask/Dlhis.ScheduledTask.csproj" RUN dotnet restore "Src/Dlhis.ScheduledTask/Dlhis.ScheduledTask.csproj"
COPY . . COPY . .
WORKDIR "/src/Src/Dlhis.ScheduledTask" WORKDIR "/src/Src/Dlhis.ScheduledTask"

View File

@@ -18,11 +18,11 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="Kurisu.AspNetCore" Version="0.5.2" /> <PackageReference Include="Kurisu.AspNetCore" Version="0.5.2" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.19.4" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\Dlhis.Entity\Dlhis.Entity.csproj" /> <ProjectReference Include="..\Dlhis.Entity\Dlhis.Entity.csproj" />
<ProjectReference Include="..\Dlhis.User.Api\Dlhis.User.Api.csproj" />
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@@ -8,7 +8,6 @@ FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /src WORKDIR /src
COPY ["Src/Dlhis.Sys/Dlhis.Sys.csproj", "Src/Dlhis.Sys/"] COPY ["Src/Dlhis.Sys/Dlhis.Sys.csproj", "Src/Dlhis.Sys/"]
COPY ["Src/Dlhis.Entity/Dlhis.Entity.csproj", "Src/Dlhis.Entity/"] COPY ["Src/Dlhis.Entity/Dlhis.Entity.csproj", "Src/Dlhis.Entity/"]
COPY ["Src/Dlhis.User.Api/Dlhis.User.Api.csproj", "Src/Dlhis.User.Api/"]
RUN dotnet restore "Src/Dlhis.Sys/Dlhis.Sys.csproj" RUN dotnet restore "Src/Dlhis.Sys/Dlhis.Sys.csproj"
COPY . . COPY . .
WORKDIR "/src/Src/Dlhis.Sys" WORKDIR "/src/Src/Dlhis.Sys"

View File

@@ -1,11 +1,11 @@
using Dlhis.User.Identity.Request; using Dlhis.Sys.Identity.Request;
using Dlhis.User.Identity.Response; using Dlhis.Sys.Identity.Response;
using Dlhis.User.Identity.Services; using Dlhis.User.Identity.Services;
using Kurisu.Core.DataAccess.Dto; using Kurisu.Core.DataAccess.Dto;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
namespace Dlhis.User.Identity.Controllers; namespace Dlhis.Sys.Identity.Controllers;
/// <summary> /// <summary>
/// 角色 /// 角色

View File

@@ -1,11 +1,11 @@
using Dlhis.User.Identity.Request; using Dlhis.Sys.Identity.Request;
using Dlhis.User.Identity.Response; using Dlhis.Sys.Identity.Response;
using Dlhis.User.Identity.Services; using Dlhis.Sys.Identity.Services;
using Kurisu.Core.DataAccess.Dto; using Kurisu.Core.DataAccess.Dto;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
namespace Dlhis.User.Identity.Controllers; namespace Dlhis.Sys.Identity.Controllers;
[Authorize] [Authorize]
[Route("api/[controller]")] [Route("api/[controller]")]

View File

@@ -1,11 +1,11 @@
using Dlhis.User.Identity.Request; using Dlhis.Sys.Identity.Request;
using Dlhis.User.Identity.Response; using Dlhis.Sys.Identity.Response;
using Dlhis.User.Identity.Services; using Dlhis.Sys.Identity.Services;
using Kurisu.Core.DataAccess.Dto; using Kurisu.Core.DataAccess.Dto;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
namespace Dlhis.User.Identity.Controllers; namespace Dlhis.Sys.Identity.Controllers;
/// <summary> /// <summary>
/// 用户 /// 用户
@@ -44,6 +44,11 @@ public class UsersController : ControllerBase
return await _userService.GetUsersAsync(); return await _userService.GetUsersAsync();
} }
/// <summary>
/// 根据id获取用户
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
[Authorize] [Authorize]
[HttpGet] [HttpGet]
public async Task<UserResponse> GetUserByIdAsync(int id) public async Task<UserResponse> GetUserByIdAsync(int id)
@@ -51,6 +56,11 @@ public class UsersController : ControllerBase
return await _userService.GetUserByIdAsync(id); return await _userService.GetUserByIdAsync(id);
} }
/// <summary>
/// 上传头像
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
[Authorize] [Authorize]
[HttpPost("avatar")] [HttpPost("avatar")]
public async Task UploadUserAvatarAsync([FromForm] UserAvatarUploadRequest request) public async Task UploadUserAvatarAsync([FromForm] UserAvatarUploadRequest request)

View File

@@ -0,0 +1,10 @@
namespace Dlhis.Sys.Identity.Request;
public class ClientGrantRequest
{
public string ClientId { get; set; }
public string ClientSecret { get; set; }
public string Scope { get; set; } = "yikatong";
}

View File

@@ -1,6 +1,6 @@
using Kurisu.Core.DataAccess.Dto; using Kurisu.Core.DataAccess.Dto;
namespace Dlhis.User.Identity.Request; namespace Dlhis.Sys.Identity.Request;
public class RolePageRequest : PageDto public class RolePageRequest : PageDto
{ {

View File

@@ -1,6 +1,6 @@
using Kurisu.Core.DataAccess.Dto; using Kurisu.Core.DataAccess.Dto;
namespace Dlhis.User.Identity.Request namespace Dlhis.Sys.Identity.Request
{ {
public class TenantPageRequest : PageDto public class TenantPageRequest : PageDto
{ {

View File

@@ -1,6 +1,6 @@
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
namespace Dlhis.User.Identity.Request; namespace Dlhis.Sys.Identity.Request;
public class UserAvatarUploadRequest public class UserAvatarUploadRequest
{ {

View File

@@ -1,6 +1,6 @@
using Kurisu.Core.DataAccess.Dto; using Kurisu.Core.DataAccess.Dto;
namespace Dlhis.User.Identity.Request; namespace Dlhis.Sys.Identity.Request;
public class UserPageRequest : PageDto public class UserPageRequest : PageDto
{ {

View File

@@ -1,4 +1,4 @@
namespace Dlhis.User.Identity.Response; namespace Dlhis.Sys.Identity.Response;
public class RoleRespone public class RoleRespone
{ {

View File

@@ -1,4 +1,4 @@
namespace Dlhis.User.Identity.Response; namespace Dlhis.Sys.Identity.Response;
public class TenantResponse public class TenantResponse
{ {

View File

@@ -1,4 +1,4 @@
namespace Dlhis.User.Identity.Response; namespace Dlhis.Sys.Identity.Response;
public class UserResponse public class UserResponse
{ {

View File

@@ -1,5 +1,5 @@
using Dlhis.User.Identity.Request; using Dlhis.Sys.Identity.Request;
using Dlhis.User.Identity.Response; using Dlhis.Sys.Identity.Response;
using Kurisu.Core.DataAccess.Dto; using Kurisu.Core.DataAccess.Dto;
namespace Dlhis.User.Identity.Services; namespace Dlhis.User.Identity.Services;

View File

@@ -1,8 +1,8 @@
using Dlhis.User.Identity.Request; using Dlhis.Sys.Identity.Request;
using Dlhis.User.Identity.Response; using Dlhis.Sys.Identity.Response;
using Kurisu.Core.DataAccess.Dto; using Kurisu.Core.DataAccess.Dto;
namespace Dlhis.User.Identity.Services; namespace Dlhis.Sys.Identity.Services;
public interface ITenantService : IScopeDependency public interface ITenantService : IScopeDependency
{ {

View File

@@ -1,8 +1,8 @@
using Dlhis.User.Identity.Request; using Dlhis.Sys.Identity.Request;
using Dlhis.User.Identity.Response; using Dlhis.Sys.Identity.Response;
using Kurisu.Core.DataAccess.Dto; using Kurisu.Core.DataAccess.Dto;
namespace Dlhis.User.Identity.Services; namespace Dlhis.Sys.Identity.Services;
public interface IUserService : IScopeDependency public interface IUserService : IScopeDependency
{ {

View File

@@ -1,12 +1,13 @@
using Dlhis.Entity.Sys.Entities; using Dlhis.Entity.Sys.Entities;
using Dlhis.User.Identity.Request; using Dlhis.Sys.Identity.Request;
using Dlhis.User.Identity.Response; using Dlhis.Sys.Identity.Response;
using Dlhis.User.Identity.Services;
using Kurisu.AspNetCore.Utils.Extensions; using Kurisu.AspNetCore.Utils.Extensions;
using Kurisu.Core.DataAccess.Dto; using Kurisu.Core.DataAccess.Dto;
using Kurisu.SqlSugar.Extensions; using Kurisu.SqlSugar.Extensions;
using Kurisu.SqlSugar.Services; using Kurisu.SqlSugar.Services;
namespace Dlhis.User.Identity.Services.Implements; namespace Dlhis.Sys.Identity.Services.Implements;
public class RoleService : IRoleService public class RoleService : IRoleService
{ {

View File

@@ -1,12 +1,12 @@
using Dlhis.Entity.Sys.Entities; using Dlhis.Entity.Sys.Entities;
using Dlhis.User.Identity.Request; using Dlhis.Sys.Identity.Request;
using Dlhis.User.Identity.Response; using Dlhis.Sys.Identity.Response;
using Kurisu.AspNetCore.Utils.Extensions; using Kurisu.AspNetCore.Utils.Extensions;
using Kurisu.Core.DataAccess.Dto; using Kurisu.Core.DataAccess.Dto;
using Kurisu.SqlSugar.Extensions; using Kurisu.SqlSugar.Extensions;
using Kurisu.SqlSugar.Services; using Kurisu.SqlSugar.Services;
namespace Dlhis.User.Identity.Services.Implements; namespace Dlhis.Sys.Identity.Services.Implements;
public class TenantService : ITenantService public class TenantService : ITenantService
{ {

View File

@@ -1,12 +1,12 @@
using Dlhis.Entity.Sys.Entities; using Dlhis.Entity.Sys.Entities;
using Dlhis.User.Identity.Request; using Dlhis.Sys.Identity.Request;
using Dlhis.User.Identity.Response; using Dlhis.Sys.Identity.Response;
using Kurisu.AspNetCore.Utils.Extensions; using Kurisu.AspNetCore.Utils.Extensions;
using Kurisu.Core.DataAccess.Dto; using Kurisu.Core.DataAccess.Dto;
using Kurisu.SqlSugar.Extensions; using Kurisu.SqlSugar.Extensions;
using Kurisu.SqlSugar.Services; using Kurisu.SqlSugar.Services;
namespace Dlhis.User.Identity.Services.Implements; namespace Dlhis.Sys.Identity.Services.Implements;
public class UserService : IUserService public class UserService : IUserService
{ {

View File

@@ -1,8 +1,8 @@
using Dlhis.Entity.Sys.Entities; using Dlhis.Entity.Sys.Entities;
using Dlhis.Entity.Sys.Enums; using Dlhis.Entity.Sys.Enums;
using Dlhis.Sys.Identity.Services;
using Dlhis.Sys.Menu.Request; using Dlhis.Sys.Menu.Request;
using Dlhis.Sys.Menu.Response; using Dlhis.Sys.Menu.Response;
using Dlhis.User.Api;
using Kurisu.AspNetCore.Utils.Extensions; using Kurisu.AspNetCore.Utils.Extensions;
using Kurisu.Core.Result; using Kurisu.Core.Result;
using Kurisu.Core.User.Abstractions; using Kurisu.Core.User.Abstractions;
@@ -16,13 +16,13 @@ public class MenuService : IMenuService
{ {
private readonly IDbContext _dbContext; private readonly IDbContext _dbContext;
private readonly ICurrentUser _currentUser; private readonly ICurrentUser _currentUser;
private readonly IUserApi _userApi; private readonly IUserService _userService;
public MenuService(IDbContext dbContext, ICurrentUser currentUser, IUserApi userApi) public MenuService(IDbContext dbContext, ICurrentUser currentUser, IUserService userService)
{ {
_dbContext = dbContext; _dbContext = dbContext;
_currentUser = currentUser; _currentUser = currentUser;
_userApi = userApi; _userService = userService;
} }
public async Task<List<MenuResponse>> GetListAsync(PlatformEnumType platform) public async Task<List<MenuResponse>> GetListAsync(PlatformEnumType platform)
@@ -270,9 +270,7 @@ public class MenuService : IMenuService
private async Task<List<string>> GetAllAssignmentCodesAsync() private async Task<List<string>> GetAllAssignmentCodesAsync()
{ {
var userApiResult = await _userApi.GetUserByIdAsync(_currentUser.GetIntSubjectId()); var user = await _userService.GetUserByIdAsync(_currentUser.GetIntSubjectId());
(userApiResult.Code == ApiStateCode.Success).ThrowIfFalse(userApiResult.Msg);
var user = userApiResult.Data;
// var groupCodes = await GetAssignmentCodesAsync(MenuPermissionTypeEnumType.Group, manager.usergrp); // var groupCodes = await GetAssignmentCodesAsync(MenuPermissionTypeEnumType.Group, manager.usergrp);

View File

@@ -7,6 +7,14 @@
}, },
"dotnetRunMessages": true, "dotnetRunMessages": true,
"applicationUrl": "http://localhost:5003" "applicationUrl": "http://localhost:5003"
},
"Docker": {
"commandName": "Docker",
"launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}",
"environmentVariables": {
"ASPNETCORE_URLS": "http://+:80"
},
"publishAllPorts": true
} }
} }
} }

View File

@@ -7,7 +7,7 @@
}, },
"InternalRequest": { "InternalRequest": {
"CommonRequestUrl": "http://localhost:5001", "CommonRequestUrl": "http://localhost:5001",
"UserRequestUrl": "http://localhost:5004" "SysRequestUrl": "http://localhost:5003"
}, },
"SwaggerOptions": { "SwaggerOptions": {
"Enable": true, "Enable": true,

View File

@@ -8,7 +8,7 @@
"AllowedHosts": "*", "AllowedHosts": "*",
"InternalRequest": { "InternalRequest": {
"CommonRequestUrl": "http://common", "CommonRequestUrl": "http://common",
"UserRequestUrl": "http://user" "SysRequestUrl": "http://sys"
}, },
"SqlSugarOptions": { "SqlSugarOptions": {
"DefaultConnectionString": "server=192.168.199.124;port=3306;userid=root;password=dlhis123;database=yikatong;charset=utf8mb4;", "DefaultConnectionString": "server=192.168.199.124;port=3306;userid=root;password=dlhis123;database=yikatong;charset=utf8mb4;",

View File

@@ -7,7 +7,7 @@ namespace Dlhis.User.Api;
/// <summary> /// <summary>
/// 租户Api /// 租户Api
/// </summary> /// </summary>
[EnableRemoteClient(Name = "user-service", BaseUrl = "${InternalRequest:UserRequestUrl}")] [EnableRemoteClient(Name = "sys-service", BaseUrl = "${InternalRequest:SysRequestUrl}")]
public interface ITenantApi public interface ITenantApi
{ {
/// <summary> /// <summary>

View File

@@ -4,7 +4,7 @@ using Kurisu.RemoteCall.Attributes;
namespace Dlhis.User.Api; namespace Dlhis.User.Api;
[EnableRemoteClient(Name = "user-service", BaseUrl = "${InternalRequest:UserRequestUrl}")] [EnableRemoteClient(Name = "sys-service", BaseUrl = "${InternalRequest:SysRequestUrl}")]
public interface IUserApi public interface IUserApi
{ {
[Auth] [Auth]

View File

@@ -18,9 +18,6 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="Kurisu.AspNetCore" Version="0.5.2" /> <PackageReference Include="Kurisu.AspNetCore" Version="0.5.2" />
</ItemGroup> <PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.19.4" />
<ItemGroup>
<ProjectReference Include="..\Dlhis.Entity\Dlhis.Entity.csproj" />
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@@ -7,7 +7,6 @@ EXPOSE 80
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /src WORKDIR /src
COPY ["Src/Dlhis.User/Dlhis.User.csproj", "Src/Dlhis.User/"] COPY ["Src/Dlhis.User/Dlhis.User.csproj", "Src/Dlhis.User/"]
COPY ["Src/Dlhis.Entity/Dlhis.Entity.csproj", "Src/Dlhis.Entity/"]
RUN dotnet restore "Src/Dlhis.User/Dlhis.User.csproj" RUN dotnet restore "Src/Dlhis.User/Dlhis.User.csproj"
COPY . . COPY . .
WORKDIR "/src/Src/Dlhis.User" WORKDIR "/src/Src/Dlhis.User"

View File

@@ -1,14 +0,0 @@
using Kurisu.AspNetCore.Startup;
using Kurisu.SqlSugar.Extensions;
namespace Dlhis.User.Packs;
public class SqlSugarPack : BaseAppPack
{
public override bool IsBeforeUseRouting { get; }
public override void ConfigureServices(IServiceCollection services)
{
services.AddSqlSugar();
}
}

View File

@@ -7,6 +7,14 @@
}, },
"dotnetRunMessages": true, "dotnetRunMessages": true,
"applicationUrl": "http://localhost:5004" "applicationUrl": "http://localhost:5004"
},
"Docker": {
"commandName": "Docker",
"launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}",
"environmentVariables": {
"ASPNETCORE_URLS": "http://+:80"
},
"publishAllPorts": true
} }
}, },
"$schema": "https://json.schemastore.org/launchsettings.json" "$schema": "https://json.schemastore.org/launchsettings.json"

View File

@@ -56,14 +56,6 @@
"Args": { "Args": {
"outputTemplate": "[{Timestamp:HH:mm:ss} {Level:u3}] [{SourceContext}] {Message:lj}{NewLine}{Exception}" "outputTemplate": "[{Timestamp:HH:mm:ss} {Level:u3}] [{SourceContext}] {Message:lj}{NewLine}{Exception}"
} }
},
{
"Name": "MySQL",
"Args": {
"connectionString": "server=192.168.199.124;port=3306;userid=root;password=dlhis123;database=log;charset=utf8mb4;",
"tableName": "Logs",
"autoCreateSqlTable": true
}
} }
] ]
} }