From 5940914e5733f21dc5522970cca151b4b2ae3f10 Mon Sep 17 00:00:00 2001 From: liguoyang Date: Tue, 2 Apr 2024 16:59:26 +0800 Subject: [PATCH 1/6] =?UTF-8?q?feat=20=E7=82=B9=E4=BD=8D=E5=9B=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Map/Controllers/PointMapsController.cs | 93 +++++++++++++++++++ .../Map/Request/SavePointMapDetailRequest.cs | 38 ++++++++ .../Map/Request/SavePointMapRequest.cs | 22 +++++ .../Map/Response/PointMapDetailResponse.cs | 26 ++++++ .../Map/Response/PointMapResponse.cs | 23 +++++ .../Map/Services/IPointMapDetailService.cs | 13 +++ .../Map/Services/IPointMapService.cs | 14 +++ .../Implements/PointMapDetailService.cs | 45 +++++++++ .../Services/Implements/PointMapService.cs | 56 +++++++++++ .../Response/MealSupplementRecordResponse.cs | 2 - .../Basic/Entity/PointMapDetailEntity.cs | 44 +++++++++ .../Basic/Entity/PointMapEntity.cs | 36 +++++++ .../Basic/Enums/PointMapDetailEnumType.cs | 16 ++++ 13 files changed, 426 insertions(+), 2 deletions(-) create mode 100644 Src/Dlhis.Basic/Map/Controllers/PointMapsController.cs create mode 100644 Src/Dlhis.Basic/Map/Request/SavePointMapDetailRequest.cs create mode 100644 Src/Dlhis.Basic/Map/Request/SavePointMapRequest.cs create mode 100644 Src/Dlhis.Basic/Map/Response/PointMapDetailResponse.cs create mode 100644 Src/Dlhis.Basic/Map/Response/PointMapResponse.cs create mode 100644 Src/Dlhis.Basic/Map/Services/IPointMapDetailService.cs create mode 100644 Src/Dlhis.Basic/Map/Services/IPointMapService.cs create mode 100644 Src/Dlhis.Basic/Map/Services/Implements/PointMapDetailService.cs create mode 100644 Src/Dlhis.Basic/Map/Services/Implements/PointMapService.cs create mode 100644 Src/Dlhis.Entity/Basic/Entity/PointMapDetailEntity.cs create mode 100644 Src/Dlhis.Entity/Basic/Entity/PointMapEntity.cs create mode 100644 Src/Dlhis.Entity/Basic/Enums/PointMapDetailEnumType.cs diff --git a/Src/Dlhis.Basic/Map/Controllers/PointMapsController.cs b/Src/Dlhis.Basic/Map/Controllers/PointMapsController.cs new file mode 100644 index 00000000..eaf928eb --- /dev/null +++ b/Src/Dlhis.Basic/Map/Controllers/PointMapsController.cs @@ -0,0 +1,93 @@ +using Dlhis.Basic.Map.Request; +using Dlhis.Basic.Map.Response; +using Dlhis.Basic.Map.Services; +using Kurisu.Core.DataAccess.Dto; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; + +namespace Dlhis.Basic.Map.Controllers; + +/// +/// 点位图 +/// +[Authorize] +[Route("api/[controller]")] +[ApiController] +public class PointMapsController : ControllerBase +{ + private readonly IPointMapService _pointMapService; + private readonly IPointMapDetailService _pointMapDetailService; + + public PointMapsController(IPointMapService pointMapService, + IPointMapDetailService pointMapDetailService) + { + _pointMapService = pointMapService; + _pointMapDetailService = pointMapDetailService; + } + + /// + /// 点位图分页 + /// + /// + /// + [HttpGet("page")] + public async Task> GetPointMapPageAsync([FromQuery] PageDto request) + { + return await _pointMapService.GetPageAsync(request); + } + + /// + /// 保存点位图 + /// + /// + /// + [HttpPost("save")] + public async Task SavePointMapAsync(SavePointMapRequest request) + { + await _pointMapService.SaveAsync(request); + } + + /// + /// 删除点位图 + /// + /// + /// + [HttpDelete("{id}")] + public async Task DeletePointMapAsync(long id) + { + await _pointMapService.DeleteAsync(id); + } + + /// + /// 点位数据明细保存 + /// + /// + /// + [HttpPost("detail/save")] + public async Task SaveDetailAsync(SavePointMapDetailRequest request) + { + await _pointMapDetailService.SaveAsync(request); + } + + /// + /// 点位数据明细 + /// + /// + /// + [HttpGet("detail/list")] + public async Task> GetDetailListByPointMapCodeAsync([FromQuery] Guid pointMapCode) + { + return await _pointMapDetailService.GetListByPointMapCodeAsync(pointMapCode); + } + + /// + /// 删除点位数据明细 + /// + /// + /// + [HttpDelete("detail/{id}")] + public async Task DeleteDetailAsync(long id) + { + await _pointMapDetailService.DeleteAsync(id); + } +} diff --git a/Src/Dlhis.Basic/Map/Request/SavePointMapDetailRequest.cs b/Src/Dlhis.Basic/Map/Request/SavePointMapDetailRequest.cs new file mode 100644 index 00000000..3cec3f52 --- /dev/null +++ b/Src/Dlhis.Basic/Map/Request/SavePointMapDetailRequest.cs @@ -0,0 +1,38 @@ +using Dlhis.Entity.Basic.Enums; +using System.ComponentModel.DataAnnotations; + +namespace Dlhis.Basic.Map.Request; + +public class SavePointMapDetailRequest +{ + public long? Id { get; set; } + + /// + /// 点位图code + /// + [Required] + public Guid PointMapCode { get; set; } + + /// + /// 数据code 如果是设备那么为设备code + /// + [Required] + public Guid UniqueCode { get; set; } + + /// + /// 数据类型 PointMapDetailEnumType + /// + [EnumDataType(typeof(PointMapDetailEnumType))] + public PointMapDetailEnumType Type { get; set; } + + /// + /// XYZ + /// + [Required] + public string Position { get; set; } + + /// + /// 备注 + /// + public string Remark { get; set; } +} diff --git a/Src/Dlhis.Basic/Map/Request/SavePointMapRequest.cs b/Src/Dlhis.Basic/Map/Request/SavePointMapRequest.cs new file mode 100644 index 00000000..3195ac5d --- /dev/null +++ b/Src/Dlhis.Basic/Map/Request/SavePointMapRequest.cs @@ -0,0 +1,22 @@ +using System.ComponentModel.DataAnnotations; + +namespace Dlhis.Basic.Map.Request; + +public class SavePointMapRequest +{ + public long? Id { get; set; } + + /// + /// 位置名称 + /// + [Required(ErrorMessage = "位置名称不可为空")] + public string Name { get; set; } + + /// + /// 图 + /// + [Required(ErrorMessage = "图片不可为空")] + public string ImageUrl { get; set; } + + public string Remark { get; set; } +} diff --git a/Src/Dlhis.Basic/Map/Response/PointMapDetailResponse.cs b/Src/Dlhis.Basic/Map/Response/PointMapDetailResponse.cs new file mode 100644 index 00000000..2528f29f --- /dev/null +++ b/Src/Dlhis.Basic/Map/Response/PointMapDetailResponse.cs @@ -0,0 +1,26 @@ +using Dlhis.Entity.Basic.Enums; + +namespace Dlhis.Basic.Map.Response; + +public class PointMapDetailResponse +{ + /// + /// 数据code + /// + public Guid UniqueCode { get; set; } + + /// + /// 数据类型 + /// + public PointMapDetailEnumType Type { get; set; } + + /// + /// XYZ + /// + public string Position { get; set; } + + /// + /// 备注 + /// + public string Remark { get; set; } +} diff --git a/Src/Dlhis.Basic/Map/Response/PointMapResponse.cs b/Src/Dlhis.Basic/Map/Response/PointMapResponse.cs new file mode 100644 index 00000000..44bcad67 --- /dev/null +++ b/Src/Dlhis.Basic/Map/Response/PointMapResponse.cs @@ -0,0 +1,23 @@ +using SqlSugar; + +namespace Dlhis.Basic.Map.Response; + +public class PointMapResponse +{ + public long Id { get; set; } + + public Guid Code { get; set; } + + /// + /// 位置名称 + /// + public string Name { get; set; } + + /// + /// 图 + /// + public string ImageUrl { get; set; } + + + public string Remark { get; set; } +} diff --git a/Src/Dlhis.Basic/Map/Services/IPointMapDetailService.cs b/Src/Dlhis.Basic/Map/Services/IPointMapDetailService.cs new file mode 100644 index 00000000..3a060636 --- /dev/null +++ b/Src/Dlhis.Basic/Map/Services/IPointMapDetailService.cs @@ -0,0 +1,13 @@ +using Dlhis.Basic.Map.Request; +using Dlhis.Basic.Map.Response; + +namespace Dlhis.Basic.Map.Services; + +public interface IPointMapDetailService : IScopeDependency +{ + Task SaveAsync(SavePointMapDetailRequest request); + + Task DeleteAsync(long id); + + Task> GetListByPointMapCodeAsync(Guid pointMapCode); +} diff --git a/Src/Dlhis.Basic/Map/Services/IPointMapService.cs b/Src/Dlhis.Basic/Map/Services/IPointMapService.cs new file mode 100644 index 00000000..d91d8010 --- /dev/null +++ b/Src/Dlhis.Basic/Map/Services/IPointMapService.cs @@ -0,0 +1,14 @@ +using Dlhis.Basic.Map.Request; +using Dlhis.Basic.Map.Response; +using Kurisu.Core.DataAccess.Dto; + +namespace Dlhis.Basic.Map.Services; + +public interface IPointMapService : IScopeDependency +{ + Task> GetPageAsync(PageDto request); + + Task SaveAsync(SavePointMapRequest request); + + Task DeleteAsync(long id); +} diff --git a/Src/Dlhis.Basic/Map/Services/Implements/PointMapDetailService.cs b/Src/Dlhis.Basic/Map/Services/Implements/PointMapDetailService.cs new file mode 100644 index 00000000..44563249 --- /dev/null +++ b/Src/Dlhis.Basic/Map/Services/Implements/PointMapDetailService.cs @@ -0,0 +1,45 @@ +using Dlhis.Basic.Map.Request; +using Dlhis.Basic.Map.Response; +using Dlhis.Entity.Basic.Entity; +using Kurisu.SqlSugar.Services; +using Mapster; + +namespace Dlhis.Basic.Map.Services.Implements; + +public class PointMapDetailService : IPointMapDetailService +{ + private readonly IDbContext _dbContext; + + public PointMapDetailService(IDbContext dbContext) + { + _dbContext = dbContext; + } + + public async Task SaveAsync(SavePointMapDetailRequest request) + { + if (!request.Id.HasValue) + { + var entity = request.Adapt(); + await _dbContext.InsertAsync(entity); + } + else + { + var entity = await _dbContext.Queryable().Where(x => x.Id == request.Id).SingleAsync(); + request.Adapt(entity); + await _dbContext.UpdateAsync(entity); + } + } + + public async Task DeleteAsync(long id) + { + await _dbContext.Deleteable().Where(x => x.Id == id).ExecuteCommandAsync(); + } + + public async Task> GetListByPointMapCodeAsync(Guid pointMapCode) + { + return await _dbContext.Queryable() + .Where(x => x.PointMapCode == pointMapCode) + .Select() + .ToListAsync(); + } +} diff --git a/Src/Dlhis.Basic/Map/Services/Implements/PointMapService.cs b/Src/Dlhis.Basic/Map/Services/Implements/PointMapService.cs new file mode 100644 index 00000000..fe5f1338 --- /dev/null +++ b/Src/Dlhis.Basic/Map/Services/Implements/PointMapService.cs @@ -0,0 +1,56 @@ +using Dlhis.Basic.Map.Request; +using Dlhis.Basic.Map.Response; +using Dlhis.Entity.Basic.Entity; +using Kurisu.AspNetCore.Utils.Extensions; +using Kurisu.Core.DataAccess.Dto; +using Kurisu.SqlSugar.Extensions; +using Kurisu.SqlSugar.Services; +using Mapster; + +namespace Dlhis.Basic.Map.Services.Implements; + +public class PointMapService : IPointMapService +{ + private readonly IDbContext _dbContext; + + public PointMapService(IDbContext dbContext) + { + _dbContext = dbContext; + } + + + public async Task> GetPageAsync(PageDto request) + { + return await _dbContext.Queryable() + .Select() + .ToPageListAsync(request); + } + + public async Task SaveAsync(SavePointMapRequest request) + { + if (!request.Id.HasValue) + { + var entity = request.Adapt(); + entity.Code = Guid.NewGuid(); + + await _dbContext.InsertAsync(entity); + } + else + { + var entity = await _dbContext.Queryable().Where(x => x.Id == request.Id).SingleAsync(); + entity.ThrowIfNull("点位图不存在,无法编辑!"); + request.Adapt(entity); + await _dbContext.UpdateAsync(entity); + } + } + + public async Task DeleteAsync(long id) + { + var entity = await _dbContext.Queryable().Where(x => x.Id == id).SingleAsync(); + if (entity != null) + { + await _dbContext.Deleteable().Where(x => x.Id == id).ExecuteCommandAsync(); + await _dbContext.Deleteable().Where(x => x.PointMapCode == entity.Code).ExecuteCommandAsync(); + } + } +} diff --git a/Src/Dlhis.Canteen/MealSupplementRecord/Response/MealSupplementRecordResponse.cs b/Src/Dlhis.Canteen/MealSupplementRecord/Response/MealSupplementRecordResponse.cs index fe39466d..01d8baf3 100644 --- a/Src/Dlhis.Canteen/MealSupplementRecord/Response/MealSupplementRecordResponse.cs +++ b/Src/Dlhis.Canteen/MealSupplementRecord/Response/MealSupplementRecordResponse.cs @@ -1,6 +1,4 @@ using Dlhis.Entity.Basic.Enums; -using SqlSugar.DbConvert; -using SqlSugar; using Kurisu.AspNetCore.Utils.Extensions; namespace Dlhis.Canteen.MealSupplementRecord.Response; diff --git a/Src/Dlhis.Entity/Basic/Entity/PointMapDetailEntity.cs b/Src/Dlhis.Entity/Basic/Entity/PointMapDetailEntity.cs new file mode 100644 index 00000000..eb95854f --- /dev/null +++ b/Src/Dlhis.Entity/Basic/Entity/PointMapDetailEntity.cs @@ -0,0 +1,44 @@ +using Dlhis.Entity.Basic.Enums; +using Kurisu.Core.DataAccess.Entity; +using Kurisu.SqlSugar; +using SqlSugar; +using SqlSugar.DbConvert; + +namespace Dlhis.Entity.Basic.Entity; + +/// +/// 点位图数据 +/// +[SugarTable(TableName = "PointMapDetail", TableDescription = "点位图数据")] +public class PointMapDetailEntity : SugarBaseEntity, ITenantId +{ + /// + /// 点位图code + /// + [SugarColumn(IsNullable = false, ColumnDescription = "点位图code")] + public Guid PointMapCode { get; set; } + + /// + /// 数据code + /// + public Guid UniqueCode { get; set; } + + /// + /// 数据类型 + /// + [SugarColumn(IsNullable = false, ColumnDescription = "数据类型", ColumnDataType = "varchar(50)", SqlParameterDbType = typeof(EnumToStringConvert))] + public PointMapDetailEnumType Type { get; set; } + + /// + /// XYZ + /// + [SugarColumn(IsNullable = false, ColumnDescription = "XYZ")] + public string Position { get; set; } + + /// + /// 备注 + /// + public string Remark { get; set; } + + public string TenantId { get; set; } +} diff --git a/Src/Dlhis.Entity/Basic/Entity/PointMapEntity.cs b/Src/Dlhis.Entity/Basic/Entity/PointMapEntity.cs new file mode 100644 index 00000000..53414e4e --- /dev/null +++ b/Src/Dlhis.Entity/Basic/Entity/PointMapEntity.cs @@ -0,0 +1,36 @@ +using Kurisu.Core.DataAccess.Entity; +using Kurisu.SqlSugar; +using SqlSugar; + +namespace Dlhis.Entity.Basic.Entity; + +/// +/// 点位图 +/// +[SugarTable(TableName = "PointMaps", TableDescription = "点位图")] +public class PointMapEntity : SugarBaseEntity, ITenantId, IImageUrl +{ + /// + /// code + /// + [SugarColumn(IsNullable = false, ColumnDescription = "code")] + public Guid Code { get; set; } + + /// + /// 位置名称 + /// + [SugarColumn(IsNullable = false, ColumnDescription = "点位名称")] + public string Name { get; set; } + + /// + /// 图 + /// + [SugarColumn(IsNullable = false, ColumnDescription = "图片地址")] + public string ImageUrl { get; set; } + + + [SugarColumn(ColumnDescription = "备注")] + public string Remark { get; set; } + + public string TenantId { get; set; } +} diff --git a/Src/Dlhis.Entity/Basic/Enums/PointMapDetailEnumType.cs b/Src/Dlhis.Entity/Basic/Enums/PointMapDetailEnumType.cs new file mode 100644 index 00000000..df499bc3 --- /dev/null +++ b/Src/Dlhis.Entity/Basic/Enums/PointMapDetailEnumType.cs @@ -0,0 +1,16 @@ +using System.ComponentModel; + +namespace Dlhis.Entity.Basic.Enums; + +/// +/// 点位图数据类型 +/// +[Description("点位图数据类型")] +public enum PointMapDetailEnumType +{ + /// + /// 设备 + /// + [Description("设备")] + Device = 1, +} From 29b0008960e05c6a78255f80ef186614ac241d69 Mon Sep 17 00:00:00 2001 From: liguoyang Date: Tue, 2 Apr 2024 19:56:08 +0800 Subject: [PATCH 2/6] =?UTF-8?q?refactor=20=E6=96=87=E4=BB=B6=E7=89=88?= =?UTF-8?q?=E6=9C=AC=E9=87=8D=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Src/Dlhis.Common/Dlhis.Common.csproj | 8 +- .../EnumSetting/EnumsController.cs | 7 +- .../Constants/FileBucketConstants.cs | 13 ++ .../Controllers/ApkFileController.cs | 61 ------ .../Controllers/FileController.cs | 58 +++++- .../FileOperation/Request/ApkRequest.cs | 30 --- .../Request/FileVersionUploadRequest.cs | 45 +++++ .../Request/UploadFileReuqest.cs | 14 +- .../Response/ApkFile1Response.cs | 32 --- .../Response/ApkFileFormLocalResponse.cs | 25 --- .../FileOperation/Response/ApkFileResponse.cs | 37 ---- .../Response/CommonEnumResponse.cs | 17 +- .../Response/FileVersionResponse.cs | 31 +++ .../FileOperation/Response/KeyValueDto.cs | 8 - .../FileOperation/Services/ApkFIileService.cs | 188 ------------------ .../Services/IApkFIileService.cs | 27 --- .../Services/IFileVersionService.cs | 16 ++ .../FileOperation/Services/IMinioService.cs | 34 +++- .../Services/Implements/ApkFIileService.cs | 102 ---------- .../Services/Implements/FileVersionService.cs | 74 +++++++ .../Services/Implements/MinioService.cs | 65 ------ Src/Dlhis.Entity/Common/ApkFileEntity.cs | 48 ----- Src/Dlhis.Entity/Common/FileVersionEntity.cs | 43 ++++ 23 files changed, 332 insertions(+), 651 deletions(-) create mode 100644 Src/Dlhis.Common/FileOperation/Constants/FileBucketConstants.cs delete mode 100644 Src/Dlhis.Common/FileOperation/Controllers/ApkFileController.cs delete mode 100644 Src/Dlhis.Common/FileOperation/Request/ApkRequest.cs create mode 100644 Src/Dlhis.Common/FileOperation/Request/FileVersionUploadRequest.cs delete mode 100644 Src/Dlhis.Common/FileOperation/Response/ApkFile1Response.cs delete mode 100644 Src/Dlhis.Common/FileOperation/Response/ApkFileFormLocalResponse.cs delete mode 100644 Src/Dlhis.Common/FileOperation/Response/ApkFileResponse.cs create mode 100644 Src/Dlhis.Common/FileOperation/Response/FileVersionResponse.cs delete mode 100644 Src/Dlhis.Common/FileOperation/Response/KeyValueDto.cs delete mode 100644 Src/Dlhis.Common/FileOperation/Services/ApkFIileService.cs delete mode 100644 Src/Dlhis.Common/FileOperation/Services/IApkFIileService.cs create mode 100644 Src/Dlhis.Common/FileOperation/Services/IFileVersionService.cs delete mode 100644 Src/Dlhis.Common/FileOperation/Services/Implements/ApkFIileService.cs create mode 100644 Src/Dlhis.Common/FileOperation/Services/Implements/FileVersionService.cs delete mode 100644 Src/Dlhis.Entity/Common/ApkFileEntity.cs create mode 100644 Src/Dlhis.Entity/Common/FileVersionEntity.cs diff --git a/Src/Dlhis.Common/Dlhis.Common.csproj b/Src/Dlhis.Common/Dlhis.Common.csproj index a2e461e0..bc489a52 100644 --- a/Src/Dlhis.Common/Dlhis.Common.csproj +++ b/Src/Dlhis.Common/Dlhis.Common.csproj @@ -11,9 +11,13 @@ + + + + @@ -25,8 +29,4 @@ - - - - diff --git a/Src/Dlhis.Common/EnumSetting/EnumsController.cs b/Src/Dlhis.Common/EnumSetting/EnumsController.cs index cc940da5..1821b42f 100644 --- a/Src/Dlhis.Common/EnumSetting/EnumsController.cs +++ b/Src/Dlhis.Common/EnumSetting/EnumsController.cs @@ -2,6 +2,7 @@ using Dlhis.Common.FileOperation.Response; using Dlhis.Entity.Basic.Entity; using Kurisu.AspNetCore.Utils.Extensions; +using Kurisu.Core.CustomClass; using Kurisu.SqlSugar.Services; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; @@ -46,7 +47,7 @@ public class EnumsController : ControllerBase { var e = (Enum)Enum.Parse(item.FieldType, item.GetValue(null).ToString()); var fd = e.GetDescription(); - return new KeyValueDto + return new KeyValueDto { Key = fd, Value = (int)item.GetValue(null) @@ -66,7 +67,7 @@ public class EnumsController : ControllerBase { Code = type, Name = type, - Data = g.AsEnumerable().Select(x => new KeyValueDto + Data = g.AsEnumerable().Select(x => new KeyValueDto { Key = x.Display, Value = x.Code @@ -94,7 +95,7 @@ public class EnumsController : ControllerBase { var e = (Enum)Enum.Parse(item.FieldType, item.GetValue(null).ToString()); var fd = e.GetDescription(); - return new KeyValueDto + return new KeyValueDto { Key = fd, Value = (int)item.GetValue(null) diff --git a/Src/Dlhis.Common/FileOperation/Constants/FileBucketConstants.cs b/Src/Dlhis.Common/FileOperation/Constants/FileBucketConstants.cs new file mode 100644 index 00000000..a26b3e14 --- /dev/null +++ b/Src/Dlhis.Common/FileOperation/Constants/FileBucketConstants.cs @@ -0,0 +1,13 @@ +namespace Dlhis.Common.FileOperation.Constants; + +public static class FileBucketConstants +{ + /// + /// 文件buckets + /// + public static List Buckets { get; } = new() + { + "restaurant", + "apk" + }; +} diff --git a/Src/Dlhis.Common/FileOperation/Controllers/ApkFileController.cs b/Src/Dlhis.Common/FileOperation/Controllers/ApkFileController.cs deleted file mode 100644 index 6036920e..00000000 --- a/Src/Dlhis.Common/FileOperation/Controllers/ApkFileController.cs +++ /dev/null @@ -1,61 +0,0 @@ -using Dlhis.Common.FileOperation.Request; -using Dlhis.Common.FileOperation.Response; -using Dlhis.Common.FileOperation.Services; -using Microsoft.AspNetCore.Authorization; -using Microsoft.AspNetCore.Mvc; -using Org.BouncyCastle.Asn1.Ocsp; - -namespace Dlhis.Common.FileOperation.Controllers; - -/// -/// APK文件操作 -/// -[Obsolete("作废重写")] -[Authorize] -[Route("api/[controller]")] -[ApiController] -public class ApkFileController : ControllerBase -{ - private readonly IApkFIileService _apkFIileService; - - public ApkFileController(IApkFIileService apkFIileService) - { - _apkFIileService = apkFIileService; - } - /// - /// minlo文件上传 - /// - /// - /// - [HttpPost("minio")] - [RequestSizeLimit(300_000_000)] - public async Task FormSingleFileUpload([FromForm] ApkRequest request) - { - return await _apkFIileService.FormSingleFileUpload(request); - } - - /// - /// minlo文件下载 - /// - /// - /// - [HttpGet("url")] - public async Task RequestDownloadFile(string fileName) - { - return await _apkFIileService.RequestDownloadFile(fileName); - } - - /// - /// 获取最新版本 - /// - /// - /// - [HttpGet("lastversion")] - public async Task GetLastVersionAsync(string productCode) - { - return await _apkFIileService.GetLastVersionAsync(productCode); - } -} - - - diff --git a/Src/Dlhis.Common/FileOperation/Controllers/FileController.cs b/Src/Dlhis.Common/FileOperation/Controllers/FileController.cs index 46fb28f3..9d95fc60 100644 --- a/Src/Dlhis.Common/FileOperation/Controllers/FileController.cs +++ b/Src/Dlhis.Common/FileOperation/Controllers/FileController.cs @@ -1,20 +1,28 @@ -using Dlhis.Common.FileOperation.Request; +using System.ComponentModel.DataAnnotations; +using Dlhis.Common.FileOperation.Request; +using Dlhis.Common.FileOperation.Response; using Dlhis.Common.FileOperation.Services; +using Kurisu.Core.DataAccess.Dto; 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; + private readonly IFileVersionService _fileVersionService; - public FileController(IMinioService minioService) + public FileController(IMinioService minioService, IFileVersionService fileVersionService) { _minioService = minioService; + _fileVersionService = fileVersionService; } /// @@ -27,4 +35,50 @@ public class FileController : ControllerBase { return await _minioService.UploadFileAsync(request.Bucket, request.File); } + + + /// + /// 文件上传(版本) + /// + /// + /// + [HttpPost("{Bucket}/version/upload")] + [RequestSizeLimit(300_000_000)] + public async Task UploadFileAsync([FromForm] FileVersionUploadRequest request) + { + return await _fileVersionService.UploadFileAsync(request); + } + + /// + /// 文件版本分页 + /// + /// + /// + [HttpGet("version/page")] + public async Task> GetPageAsync([FromQuery] PageDto request) + { + return await _fileVersionService.GetPageAsync(request); + } + + /// + /// 文件版本列表 + /// + /// + /// + [HttpGet("version/list")] + public async Task> GetListByCodeAsync([Required] string code) + { + return await _fileVersionService.GetListByCodeAsync(code); + } + + /// + /// 文件版本最新 + /// + /// + /// + [HttpGet("version/last")] + public async Task GetLastByCodeAsync([Required] string code) + { + return await _fileVersionService.GetLastByCodeAsync(code); + } } diff --git a/Src/Dlhis.Common/FileOperation/Request/ApkRequest.cs b/Src/Dlhis.Common/FileOperation/Request/ApkRequest.cs deleted file mode 100644 index aca49440..00000000 --- a/Src/Dlhis.Common/FileOperation/Request/ApkRequest.cs +++ /dev/null @@ -1,30 +0,0 @@ -namespace Dlhis.Common.FileOperation.Request -{ - public class ApkRequest - { - /// - /// 文件 - /// - public IFormFile formFile { get; set; } - - /// - /// 版本号 - /// - public int VersionCode { get; set; } - - /// - /// 版本名称 - /// - public string VersionName { get; set; } - - /// - /// 修改信息 - /// - public string UpdateMessage { get; set; } - - /// - /// 产品代码 - /// - public string ProductCode { get; set; } - } -} diff --git a/Src/Dlhis.Common/FileOperation/Request/FileVersionUploadRequest.cs b/Src/Dlhis.Common/FileOperation/Request/FileVersionUploadRequest.cs new file mode 100644 index 00000000..04249399 --- /dev/null +++ b/Src/Dlhis.Common/FileOperation/Request/FileVersionUploadRequest.cs @@ -0,0 +1,45 @@ +using System.ComponentModel.DataAnnotations; +using Dlhis.Common.FileOperation.Constants; +using Microsoft.AspNetCore.Mvc; + +namespace Dlhis.Common.FileOperation.Request; + +public class FileVersionUploadRequest : IValidatableObject +{ + /// + /// bucket + /// + [FromRoute] + public string Bucket { get; set; } + + /// + /// 文件 + /// + [Required] + public IFormFile File { get; set; } + + /// + /// 文件名称 + /// + [Required] + public string Name { get; set; } + + /// + /// code + /// + [Required] + public string Code { get; set; } + + /// + /// 描述信息 + /// + public string Description { get; set; } + + public IEnumerable Validate(ValidationContext validationContext) + { + if (!FileBucketConstants.Buckets.Contains(Bucket)) + { + yield return new ValidationResult($"不支持{Bucket}", new[] { nameof(Bucket) }); + } + } +} diff --git a/Src/Dlhis.Common/FileOperation/Request/UploadFileReuqest.cs b/Src/Dlhis.Common/FileOperation/Request/UploadFileReuqest.cs index ac690a39..767287bf 100644 --- a/Src/Dlhis.Common/FileOperation/Request/UploadFileReuqest.cs +++ b/Src/Dlhis.Common/FileOperation/Request/UploadFileReuqest.cs @@ -1,8 +1,10 @@ -using Microsoft.AspNetCore.Mvc; +using System.ComponentModel.DataAnnotations; +using Dlhis.Common.FileOperation.Constants; +using Microsoft.AspNetCore.Mvc; namespace Dlhis.Common.FileOperation.Request; -public class UploadFileReuqest +public class UploadFileReuqest : IValidatableObject { /// /// bucket @@ -14,4 +16,12 @@ public class UploadFileReuqest /// 文件 /// public IFormFile File { get; set; } + + public IEnumerable Validate(ValidationContext validationContext) + { + if (!FileBucketConstants.Buckets.Contains(Bucket)) + { + yield return new ValidationResult($"不支持{Bucket}", new[] { nameof(Bucket) }); + } + } } diff --git a/Src/Dlhis.Common/FileOperation/Response/ApkFile1Response.cs b/Src/Dlhis.Common/FileOperation/Response/ApkFile1Response.cs deleted file mode 100644 index 143be5fb..00000000 --- a/Src/Dlhis.Common/FileOperation/Response/ApkFile1Response.cs +++ /dev/null @@ -1,32 +0,0 @@ -using SqlSugar; - -namespace Dlhis.Common.FileOperation.Response -{ - public class ApkFile1Response - { - /// - /// 文件名称 - /// - public string Name { get; set; } - - /// - /// 地址 - /// - public string Url { get; set; } - - /// - /// 版本号 - /// - public int VersionCode { get; set; } - - /// - /// 版本名称 - /// - public int VersionName { get; set; } - - /// - /// 修改信息 - /// - public string UpdateMessage { get; set; } - } -} diff --git a/Src/Dlhis.Common/FileOperation/Response/ApkFileFormLocalResponse.cs b/Src/Dlhis.Common/FileOperation/Response/ApkFileFormLocalResponse.cs deleted file mode 100644 index b4c78bf2..00000000 --- a/Src/Dlhis.Common/FileOperation/Response/ApkFileFormLocalResponse.cs +++ /dev/null @@ -1,25 +0,0 @@ -namespace Dlhis.Common.FileOperation.Response -{ - public class ApkFileFormLocalResponse - { - /// - /// 文件名称 - /// - public string Name { get; set; } - - /// - /// 版本号 - /// - public int VersionCode { get; set; } - - /// - /// 版本名称 - /// - public int VersionName { get; set; } - - /// - /// 修改信息 - /// - public string UpdateMessage { get; set; } - } -} diff --git a/Src/Dlhis.Common/FileOperation/Response/ApkFileResponse.cs b/Src/Dlhis.Common/FileOperation/Response/ApkFileResponse.cs deleted file mode 100644 index 78a8db3f..00000000 --- a/Src/Dlhis.Common/FileOperation/Response/ApkFileResponse.cs +++ /dev/null @@ -1,37 +0,0 @@ -using SqlSugar; - -namespace Dlhis.Common.FileOperation.Response -{ - public class ApkFileResponse - { - /// - /// 文件名称 - /// - public string Name { get; set; } - - /// - /// 版本号 - /// - public int VersionCode { get; set; } - - /// - /// 版本名称 - /// - public string VersionName { get; set; } - - /// - /// 修改信息 - /// - public string UpdateMessage { get; set; } - - /// - /// 产品代码 - /// - public string ProductCode { get; set; } - - /// - /// url - /// - public string Url { get; set; } - } -} diff --git a/Src/Dlhis.Common/FileOperation/Response/CommonEnumResponse.cs b/Src/Dlhis.Common/FileOperation/Response/CommonEnumResponse.cs index 06a5a66e..3d4ee959 100644 --- a/Src/Dlhis.Common/FileOperation/Response/CommonEnumResponse.cs +++ b/Src/Dlhis.Common/FileOperation/Response/CommonEnumResponse.cs @@ -1,9 +1,12 @@ -namespace Dlhis.Common.FileOperation.Response +using Kurisu.Core.CustomClass; + +namespace Dlhis.Common.FileOperation.Response; + +public class CommonEnumResponse { - public class CommonEnumResponse - { - public string Code { get; set; } - public string Name { get; set; } - public List Data { get; set; } - } + public string Code { get; set; } + + public string Name { get; set; } + + public List> Data { get; set; } } diff --git a/Src/Dlhis.Common/FileOperation/Response/FileVersionResponse.cs b/Src/Dlhis.Common/FileOperation/Response/FileVersionResponse.cs new file mode 100644 index 00000000..891f6358 --- /dev/null +++ b/Src/Dlhis.Common/FileOperation/Response/FileVersionResponse.cs @@ -0,0 +1,31 @@ +namespace Dlhis.Common.FileOperation.Response; + +public class FileVersionResponse +{ + public long Id { get; set; } + + /// + /// 文件名称 + /// + public string Name { get; set; } + + /// + /// 文件code + /// + public string Code { get; set; } + + /// + /// 版本号 + /// + public int Version { get; set; } + + /// + /// 描述信息 + /// + public string Description { get; set; } + + /// + /// 文件地址 + /// + public string Url { get; set; } +} diff --git a/Src/Dlhis.Common/FileOperation/Response/KeyValueDto.cs b/Src/Dlhis.Common/FileOperation/Response/KeyValueDto.cs deleted file mode 100644 index f7cc487f..00000000 --- a/Src/Dlhis.Common/FileOperation/Response/KeyValueDto.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace Dlhis.Common.FileOperation.Response; - -public class KeyValueDto -{ - public string Key { get; set; } - - public object Value { get; set; } -} diff --git a/Src/Dlhis.Common/FileOperation/Services/ApkFIileService.cs b/Src/Dlhis.Common/FileOperation/Services/ApkFIileService.cs deleted file mode 100644 index 2ebc1240..00000000 --- a/Src/Dlhis.Common/FileOperation/Services/ApkFIileService.cs +++ /dev/null @@ -1,188 +0,0 @@ -using Dlhis.Common.ApiLog.Response; -using Dlhis.Common.FileOperation.Request; -using Dlhis.Common.FileOperation.Response; -using Dlhis.Entity.Common; -using Kurisu.AspNetCore.Utils.Extensions; -using Kurisu.SqlSugar.Services; -using Mapster; -using Microsoft.AspNetCore.Mvc; - -namespace Dlhis.Common.FileOperation.Services; - -public class ApkFIileService : IApkFIileService -{ - private readonly IMinioService _minioService; - private readonly IDbContext _dbContext; - - public ApkFIileService(IMinioService minioService, IDbContext dbContext) - { - _minioService = minioService; - _dbContext = dbContext; - } - - /// - /// 文件上传 - /// - /// - /// - public async Task FormSingleFileUpload(ApkRequest request) - { - //上传 - var fileUrl = await _minioService.MinloUploadFileAsync(request); - - string fileName = request.formFile.FileName; - - //更新数据库 - var entity = await _dbContext.Queryable().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().Where(x => x.Name == fileName).FirstAsync(); - var res = newEntity.Adapt(); - return res; - } - - /// - /// 文件下载 - /// - /// - public async Task RequestDownloadFile(string fileName) - { - return await _minioService.MinloDownloadLinkAsync(fileName); - } - - /// - /// 本地文件上传 - /// - /// - /// - public async Task 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().Where(x => x.Name == fileName).FirstAsync(); - if (entity == null) - { - var info = new ApkFileEntity - { - Name = fileName, - //Url = completeFilePath, - VersionCode = request.VersionCode, - VersionName = request.VersionName, - UpdateMessage = request.UpdateMessage, - }; - await _dbContext.InsertAsync(info); - } - else - { - //entity.Url = completeFilePath; - entity.VersionCode = request.VersionCode; - entity.VersionName = request.VersionName; - entity.UpdateMessage = request.UpdateMessage; - await _dbContext.UpdateAsync(entity); - } - var newEntity = await _dbContext.Queryable().Where(x => x.Name == fileName).FirstAsync(); - var res = newEntity.Adapt(); - return res; - - } - public string FormSingleFileUpload(IFormFile formFile) - { - try - { - var filePath = "C:\\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; - } - } - /// - /// 返回最新版本信息 - /// - /// - /// - public async Task LatestFile(string fileName) - { - var info = await _dbContext.Queryable() - .Where(x => x.Name == fileName) - .OrderByDescending(x => x.VersionCode) - .FirstAsync(); - info.ThrowIfNull($"没有{fileName}信息"); - var res = info.Adapt(); - return res; - } - - /// - /// 本地下载 - /// - /// - /// - public IActionResult FormLocalDownloadFile(string fileName) - { - var filePath = "C:\\apk\\"; - string path = filePath + fileName; - return new FileStreamResult(new FileStream(path, FileMode.Open), "application/octet-stream") { FileDownloadName = fileName }; - } - - Task IApkFIileService.FormSingleFileUpload(ApkRequest request) - { - throw new NotImplementedException(); - } - - public Task GetLastVersionAsync(string productCode) - { - throw new NotImplementedException(); - } -} - - diff --git a/Src/Dlhis.Common/FileOperation/Services/IApkFIileService.cs b/Src/Dlhis.Common/FileOperation/Services/IApkFIileService.cs deleted file mode 100644 index 047b8f6b..00000000 --- a/Src/Dlhis.Common/FileOperation/Services/IApkFIileService.cs +++ /dev/null @@ -1,27 +0,0 @@ -using Dlhis.Common.FileOperation.Request; -using Dlhis.Common.FileOperation.Response; -using Microsoft.AspNetCore.Mvc; - -namespace Dlhis.Common.FileOperation.Services; - -public interface IApkFIileService : IScopeDependency -{ - /// - /// 文件上传 - /// - /// - /// - Task FormSingleFileUpload(ApkRequest request); - - /// - /// 文件下载 - /// - /// - Task RequestDownloadFile(string fileName); - - - Task GetLastVersionAsync(string productCode); -} - - - diff --git a/Src/Dlhis.Common/FileOperation/Services/IFileVersionService.cs b/Src/Dlhis.Common/FileOperation/Services/IFileVersionService.cs new file mode 100644 index 00000000..69c2bdb7 --- /dev/null +++ b/Src/Dlhis.Common/FileOperation/Services/IFileVersionService.cs @@ -0,0 +1,16 @@ +using Dlhis.Common.FileOperation.Request; +using Dlhis.Common.FileOperation.Response; +using Kurisu.Core.DataAccess.Dto; + +namespace Dlhis.Common.FileOperation.Services; + +public interface IFileVersionService : IScopeDependency +{ + Task UploadFileAsync(FileVersionUploadRequest request); + + Task> GetPageAsync(PageDto request); + + Task> GetListByCodeAsync(string code); + + Task GetLastByCodeAsync(string code); +} diff --git a/Src/Dlhis.Common/FileOperation/Services/IMinioService.cs b/Src/Dlhis.Common/FileOperation/Services/IMinioService.cs index f70c17f0..6a318f01 100644 --- a/Src/Dlhis.Common/FileOperation/Services/IMinioService.cs +++ b/Src/Dlhis.Common/FileOperation/Services/IMinioService.cs @@ -1,21 +1,35 @@ -using Dlhis.Common.FileOperation.Request; - -namespace Dlhis.Common.FileOperation.Services; +namespace Dlhis.Common.FileOperation.Services; public interface IMinioService : ISingletonDependency { - Task MinloUploadFileAsync(ApkRequest request); - - Task MinloDownloadLinkAsync(string fileName); - - Task MinloRemoveFileAsync(string fileName); - - + /// + /// bucket不存在即创建 + /// + /// + /// + Task CreateBucketIfNotExistsAsync(string bucket); + /// + /// 判断是否存在bucket + /// + /// + /// Task ExistsBucketAsync(string bucket); + /// + /// 判断文件是否存在 + /// + /// + /// + /// Task ExistsFileAsync(string bucket, string objectName); + /// + /// 上传文件 + /// + /// + /// + /// Task UploadFileAsync(string bucket, IFormFile formFile); } diff --git a/Src/Dlhis.Common/FileOperation/Services/Implements/ApkFIileService.cs b/Src/Dlhis.Common/FileOperation/Services/Implements/ApkFIileService.cs deleted file mode 100644 index 9b920f5c..00000000 --- a/Src/Dlhis.Common/FileOperation/Services/Implements/ApkFIileService.cs +++ /dev/null @@ -1,102 +0,0 @@ -using Dlhis.Common.FileOperation.Request; -using Dlhis.Common.FileOperation.Response; -using Dlhis.Common.FileOperation.Services; -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; - private readonly IConfiguration Configuration; - - public ApkFIileService(IMinioService minioService, IDbContext dbContext, IConfiguration configuration) - { - _minioService = minioService; - _dbContext = dbContext; - Configuration = configuration; - } - - /// - /// 文件上传 - /// - /// - /// - public async Task FormSingleFileUpload(ApkRequest request) - { - //上传 - var fileUrl = await _minioService.MinloUploadFileAsync(request); - - string fileName = request.formFile.FileName; - - var lenFive = request.formFile.FileName.Length >= 5; - - lenFive.ThrowIfFalse("文件名长度不能小于5"); - var houzhui = request.formFile.FileName.Substring(request.formFile.FileName.Length - 4, 4).ToLower(); - var isApk = request.formFile.FileName.Substring(request.formFile.FileName.Length - 4, 4) == ".apk"; - isApk.ThrowIfFalse("文件不是apk类型"); - - //更新数据库 - var entity = await _dbContext.Queryable().Where(x => x.ProductCode == request.ProductCode).FirstAsync(); - if (entity == null) - { - var info = new ApkFileEntity - { - Name = fileName, - ProductCode = request.ProductCode, - VersionCode = request.VersionCode, - UpdateMessage = request.UpdateMessage, - VersionName = request.VersionName, - }; - await _dbContext.InsertAsync(info); - } - else - { - entity.VersionCode = request.VersionCode; - entity.UpdateMessage = request.UpdateMessage; - entity.VersionName = request.VersionName; - entity.Name = fileName; - await _dbContext.UpdateAsync(entity); - } - var newEntity = await _dbContext.Queryable().Where(x => x.ProductCode == request.ProductCode).FirstAsync(); - var res = newEntity.Adapt(); - return res; - } - - public async Task GetLastVersionAsync(string productCode) - { - var info = await _dbContext.Queryable() - .Where(x => x.ProductCode == productCode) - .Select() - .FirstAsync(); - info.ThrowIfNull($"产品{productCode}下没有apk存在"); - var url =await RequestDownloadFile(info.Name); - - var host = Configuration["MinIO:Endpoint"]; - - var modified_url = url.Replace(host, "https://yikatong.isawesome.cn/m"); - - info.Url = modified_url; - - return info; - } - - /// - /// 文件下载 - /// - /// - public async Task RequestDownloadFile(string fileName) - { - return await _minioService.MinloDownloadLinkAsync(fileName); - } - - - -} - - diff --git a/Src/Dlhis.Common/FileOperation/Services/Implements/FileVersionService.cs b/Src/Dlhis.Common/FileOperation/Services/Implements/FileVersionService.cs new file mode 100644 index 00000000..3d4a4285 --- /dev/null +++ b/Src/Dlhis.Common/FileOperation/Services/Implements/FileVersionService.cs @@ -0,0 +1,74 @@ +using Dlhis.Common.FileOperation.Request; +using Dlhis.Common.FileOperation.Response; +using Dlhis.Entity.Common; +using Kurisu.Core.DataAccess.Dto; +using Kurisu.SqlSugar.Extensions; +using Kurisu.SqlSugar.Services; + +namespace Dlhis.Common.FileOperation.Services.Implements; + +public class FileVersionService : IFileVersionService +{ + private readonly IMinioService _minioService; + private readonly IDbContext _dbContext; + + public FileVersionService(IMinioService minioService, IDbContext dbContext) + { + _minioService = minioService; + _dbContext = dbContext; + } + + public async Task UploadFileAsync(FileVersionUploadRequest request) + { + var url = await _minioService.UploadFileAsync(request.Bucket, request.File); + + var version = (await GetLastVersionAsync(request.Code)) + 1; + await _dbContext.InsertAsync(new FileVersionEntity + { + Name = request.Name, + Url = url, + Description = request.Description, + Code = request.Code, + Version = version, + }); + + return url; + } + + public async Task> GetPageAsync(PageDto request) + { + return await _dbContext.Queryable() + .OrderByDescending(x => x.CreateTime) + .Select() + .ToPageListAsync(request); + } + + public async Task> GetListByCodeAsync(string code) + { + return await _dbContext.Queryable() + .Where(x => x.Code == code) + .OrderByDescending(x => x.CreateTime) + .Select() + .ToListAsync(); + } + + public async Task GetLastByCodeAsync(string code) + { + return await _dbContext.Queryable() + .Where(x => x.Code == code) + .OrderByDescending(x => x.Version) + .Select() + .SingleAsync(); + } + + //************************************************************* help methods *************************************************************** + + private async Task GetLastVersionAsync(string code) + { + return await _dbContext.Queryable() + .Where(x => x.Code == code) + .OrderByDescending(x => x.Version) + .Select(x => x.Version) + .SingleAsync(); + } +} diff --git a/Src/Dlhis.Common/FileOperation/Services/Implements/MinioService.cs b/Src/Dlhis.Common/FileOperation/Services/Implements/MinioService.cs index 70d82c49..811f8a0a 100644 --- a/Src/Dlhis.Common/FileOperation/Services/Implements/MinioService.cs +++ b/Src/Dlhis.Common/FileOperation/Services/Implements/MinioService.cs @@ -1,22 +1,17 @@ using Dlhis.Common.FileOperation.Configurations; -using Dlhis.Common.FileOperation.Request; -using Microsoft.CodeAnalysis.CSharp.Syntax; 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 options) { _client = client; - _minIOOptions = options.Value; } public async Task ExistsBucketAsync(string bucket) @@ -71,64 +66,4 @@ public class MinioService : IMinioService return $"/{bucket}/{response.ObjectName}"; } - - - /// - /// 上传文件 - /// - /// - /// - public async Task MinloUploadFileAsync(ApkRequest request) - { - string fileName = request.formFile.FileName; - - using (var 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; - } - - /// - /// 文件下载链接 - /// - /// - public async Task 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; - } - } - - - /// - /// 单个删除文件 - /// - /// - /// - public async Task MinloRemoveFileAsync(string fileName) - { - await _client.RemoveObjectAsync(new RemoveObjectArgs() - .WithBucket(_minIOOptions.DefaultBucket) - .WithObject(fileName)); - } - } diff --git a/Src/Dlhis.Entity/Common/ApkFileEntity.cs b/Src/Dlhis.Entity/Common/ApkFileEntity.cs deleted file mode 100644 index e32c5bf9..00000000 --- a/Src/Dlhis.Entity/Common/ApkFileEntity.cs +++ /dev/null @@ -1,48 +0,0 @@ -using Kurisu.SqlSugar; -using SqlSugar; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Dlhis.Entity.Common; - -/// -/// Apk文件表 -/// -[SugarTable(TableName = "ApkFIile", TableDescription = "Apk文件表")] -public class ApkFileEntity : SugarBaseEntity -{ - /// - /// 文件名称 - /// - [SugarColumn(ColumnDescription = "文件名称")] - public string Name { get; set; } - - /// - /// 版本号 - /// - [SugarColumn(ColumnDescription = "版本号")] - public int VersionCode { get; set; } - - /// - /// 版本名称 - /// - [SugarColumn(ColumnDescription = "版本名称")] - public string VersionName { get; set; } - - /// - /// 修改信息 - /// - [SugarColumn(ColumnDescription = "修改信息")] - public string UpdateMessage { get; set; } - - /// - /// 产品代码 - /// - [SugarColumn(ColumnDescription = "产品代码")] - public string ProductCode { get; set; } -} - - diff --git a/Src/Dlhis.Entity/Common/FileVersionEntity.cs b/Src/Dlhis.Entity/Common/FileVersionEntity.cs new file mode 100644 index 00000000..d0973b26 --- /dev/null +++ b/Src/Dlhis.Entity/Common/FileVersionEntity.cs @@ -0,0 +1,43 @@ +using Kurisu.SqlSugar; +using SqlSugar; + +namespace Dlhis.Entity.Common; + +/// +/// 文件版本信息 +/// +[SugarTable(TableName = "FileVersion", TableDescription = "文件版本信息")] +public class FileVersionEntity : SugarBaseEntity +{ + /// + /// 文件名称 + /// + [SugarColumn(IsNullable = false, ColumnDescription = "文件名称")] + public string Name { get; set; } + + /// + /// 文件code + /// + [SugarColumn(IsNullable = false, ColumnDescription = "文件code", UniqueGroupNameList = new[] { "idx_FileVersion_Code" })] + public string Code { get; set; } + + /// + /// 版本号 + /// + [SugarColumn(IsNullable = false, ColumnDescription = "版本号")] + public int Version { get; set; } + + /// + /// 描述信息 + /// + [SugarColumn(ColumnDescription = "描述信息")] + public string Description { get; set; } + + /// + /// 文件地址 + /// + [SugarColumn(IsNullable = false, ColumnDescription = "文件地址")] + public string Url { get; set; } +} + + From bc69c97789b85495fd263f8970b4c6e1d2f092e9 Mon Sep 17 00:00:00 2001 From: liguoyang Date: Tue, 2 Apr 2024 20:28:05 +0800 Subject: [PATCH 3/6] =?UTF-8?q?fix=20=E6=96=87=E4=BB=B6=E5=A4=A7=E5=B0=8F?= =?UTF-8?q?=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Src/Dlhis.Common/FileOperation/Controllers/FileController.cs | 4 +++- .../FileOperation/Request/FileVersionUploadRequest.cs | 2 +- .../FileOperation/Services/Implements/FileVersionService.cs | 4 ++-- .../FileOperation/Services/Implements/MinioService.cs | 3 +++ Src/Dlhis.Entity/Common/FileVersionEntity.cs | 4 ++-- 5 files changed, 11 insertions(+), 6 deletions(-) diff --git a/Src/Dlhis.Common/FileOperation/Controllers/FileController.cs b/Src/Dlhis.Common/FileOperation/Controllers/FileController.cs index 9d95fc60..d6b329e3 100644 --- a/Src/Dlhis.Common/FileOperation/Controllers/FileController.cs +++ b/Src/Dlhis.Common/FileOperation/Controllers/FileController.cs @@ -42,8 +42,10 @@ public class FileController : ControllerBase /// /// /// + [Authorize(Roles = "admin")] [HttpPost("{Bucket}/version/upload")] - [RequestSizeLimit(300_000_000)] + [RequestFormLimits(MultipartBodyLengthLimit = int.MaxValue)] + [RequestSizeLimit(int.MaxValue)] public async Task UploadFileAsync([FromForm] FileVersionUploadRequest request) { return await _fileVersionService.UploadFileAsync(request); diff --git a/Src/Dlhis.Common/FileOperation/Request/FileVersionUploadRequest.cs b/Src/Dlhis.Common/FileOperation/Request/FileVersionUploadRequest.cs index 04249399..45e4726d 100644 --- a/Src/Dlhis.Common/FileOperation/Request/FileVersionUploadRequest.cs +++ b/Src/Dlhis.Common/FileOperation/Request/FileVersionUploadRequest.cs @@ -15,7 +15,7 @@ public class FileVersionUploadRequest : IValidatableObject /// /// 文件 /// - [Required] + [FromForm] public IFormFile File { get; set; } /// diff --git a/Src/Dlhis.Common/FileOperation/Services/Implements/FileVersionService.cs b/Src/Dlhis.Common/FileOperation/Services/Implements/FileVersionService.cs index 3d4a4285..7466973c 100644 --- a/Src/Dlhis.Common/FileOperation/Services/Implements/FileVersionService.cs +++ b/Src/Dlhis.Common/FileOperation/Services/Implements/FileVersionService.cs @@ -58,7 +58,7 @@ public class FileVersionService : IFileVersionService .Where(x => x.Code == code) .OrderByDescending(x => x.Version) .Select() - .SingleAsync(); + .FirstAsync(); } //************************************************************* help methods *************************************************************** @@ -69,6 +69,6 @@ public class FileVersionService : IFileVersionService .Where(x => x.Code == code) .OrderByDescending(x => x.Version) .Select(x => x.Version) - .SingleAsync(); + .FirstAsync(); } } diff --git a/Src/Dlhis.Common/FileOperation/Services/Implements/MinioService.cs b/Src/Dlhis.Common/FileOperation/Services/Implements/MinioService.cs index 811f8a0a..b89a842f 100644 --- a/Src/Dlhis.Common/FileOperation/Services/Implements/MinioService.cs +++ b/Src/Dlhis.Common/FileOperation/Services/Implements/MinioService.cs @@ -1,4 +1,5 @@ using Dlhis.Common.FileOperation.Configurations; +using Kurisu.AspNetCore.Utils.Extensions; using Microsoft.Extensions.Options; using Minio; using Minio.DataModel.Args; @@ -50,6 +51,8 @@ public class MinioService : IMinioService public async Task UploadFileAsync(string bucket, IFormFile formFile) { + formFile.ThrowIfNull("请选择文件上传!"); + await CreateBucketIfNotExistsAsync(bucket); var ms = DateTime.Now.ToString("yyyyMMddHHmmssfff"); diff --git a/Src/Dlhis.Entity/Common/FileVersionEntity.cs b/Src/Dlhis.Entity/Common/FileVersionEntity.cs index d0973b26..5755a41b 100644 --- a/Src/Dlhis.Entity/Common/FileVersionEntity.cs +++ b/Src/Dlhis.Entity/Common/FileVersionEntity.cs @@ -18,13 +18,13 @@ public class FileVersionEntity : SugarBaseEntity /// /// 文件code /// - [SugarColumn(IsNullable = false, ColumnDescription = "文件code", UniqueGroupNameList = new[] { "idx_FileVersion_Code" })] + [SugarColumn(IsNullable = false, ColumnDescription = "文件code", UniqueGroupNameList = new[] { "idx_FileVersion_Code_Version" })] public string Code { get; set; } /// /// 版本号 /// - [SugarColumn(IsNullable = false, ColumnDescription = "版本号")] + [SugarColumn(IsNullable = false, ColumnDescription = "版本号", UniqueGroupNameList = new[] { "idx_FileVersion_Code_Version" })] public int Version { get; set; } /// From f3dacebaf6291eb13c7a9498aca56af51e2c0434 Mon Sep 17 00:00:00 2001 From: liguoyang Date: Tue, 2 Apr 2024 16:59:26 +0800 Subject: [PATCH 4/6] =?UTF-8?q?feat=20=E7=82=B9=E4=BD=8D=E5=9B=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Map/Controllers/PointMapsController.cs | 93 +++++++++++++++++++ .../Map/Request/SavePointMapDetailRequest.cs | 38 ++++++++ .../Map/Request/SavePointMapRequest.cs | 22 +++++ .../Map/Response/PointMapDetailResponse.cs | 26 ++++++ .../Map/Response/PointMapResponse.cs | 23 +++++ .../Map/Services/IPointMapDetailService.cs | 13 +++ .../Map/Services/IPointMapService.cs | 14 +++ .../Implements/PointMapDetailService.cs | 45 +++++++++ .../Services/Implements/PointMapService.cs | 56 +++++++++++ .../Response/MealSupplementRecordResponse.cs | 2 - .../Basic/Entity/PointMapDetailEntity.cs | 44 +++++++++ .../Basic/Entity/PointMapEntity.cs | 36 +++++++ .../Basic/Enums/PointMapDetailEnumType.cs | 16 ++++ 13 files changed, 426 insertions(+), 2 deletions(-) create mode 100644 Src/Dlhis.Basic/Map/Controllers/PointMapsController.cs create mode 100644 Src/Dlhis.Basic/Map/Request/SavePointMapDetailRequest.cs create mode 100644 Src/Dlhis.Basic/Map/Request/SavePointMapRequest.cs create mode 100644 Src/Dlhis.Basic/Map/Response/PointMapDetailResponse.cs create mode 100644 Src/Dlhis.Basic/Map/Response/PointMapResponse.cs create mode 100644 Src/Dlhis.Basic/Map/Services/IPointMapDetailService.cs create mode 100644 Src/Dlhis.Basic/Map/Services/IPointMapService.cs create mode 100644 Src/Dlhis.Basic/Map/Services/Implements/PointMapDetailService.cs create mode 100644 Src/Dlhis.Basic/Map/Services/Implements/PointMapService.cs create mode 100644 Src/Dlhis.Entity/Basic/Entity/PointMapDetailEntity.cs create mode 100644 Src/Dlhis.Entity/Basic/Entity/PointMapEntity.cs create mode 100644 Src/Dlhis.Entity/Basic/Enums/PointMapDetailEnumType.cs diff --git a/Src/Dlhis.Basic/Map/Controllers/PointMapsController.cs b/Src/Dlhis.Basic/Map/Controllers/PointMapsController.cs new file mode 100644 index 00000000..eaf928eb --- /dev/null +++ b/Src/Dlhis.Basic/Map/Controllers/PointMapsController.cs @@ -0,0 +1,93 @@ +using Dlhis.Basic.Map.Request; +using Dlhis.Basic.Map.Response; +using Dlhis.Basic.Map.Services; +using Kurisu.Core.DataAccess.Dto; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; + +namespace Dlhis.Basic.Map.Controllers; + +/// +/// 点位图 +/// +[Authorize] +[Route("api/[controller]")] +[ApiController] +public class PointMapsController : ControllerBase +{ + private readonly IPointMapService _pointMapService; + private readonly IPointMapDetailService _pointMapDetailService; + + public PointMapsController(IPointMapService pointMapService, + IPointMapDetailService pointMapDetailService) + { + _pointMapService = pointMapService; + _pointMapDetailService = pointMapDetailService; + } + + /// + /// 点位图分页 + /// + /// + /// + [HttpGet("page")] + public async Task> GetPointMapPageAsync([FromQuery] PageDto request) + { + return await _pointMapService.GetPageAsync(request); + } + + /// + /// 保存点位图 + /// + /// + /// + [HttpPost("save")] + public async Task SavePointMapAsync(SavePointMapRequest request) + { + await _pointMapService.SaveAsync(request); + } + + /// + /// 删除点位图 + /// + /// + /// + [HttpDelete("{id}")] + public async Task DeletePointMapAsync(long id) + { + await _pointMapService.DeleteAsync(id); + } + + /// + /// 点位数据明细保存 + /// + /// + /// + [HttpPost("detail/save")] + public async Task SaveDetailAsync(SavePointMapDetailRequest request) + { + await _pointMapDetailService.SaveAsync(request); + } + + /// + /// 点位数据明细 + /// + /// + /// + [HttpGet("detail/list")] + public async Task> GetDetailListByPointMapCodeAsync([FromQuery] Guid pointMapCode) + { + return await _pointMapDetailService.GetListByPointMapCodeAsync(pointMapCode); + } + + /// + /// 删除点位数据明细 + /// + /// + /// + [HttpDelete("detail/{id}")] + public async Task DeleteDetailAsync(long id) + { + await _pointMapDetailService.DeleteAsync(id); + } +} diff --git a/Src/Dlhis.Basic/Map/Request/SavePointMapDetailRequest.cs b/Src/Dlhis.Basic/Map/Request/SavePointMapDetailRequest.cs new file mode 100644 index 00000000..3cec3f52 --- /dev/null +++ b/Src/Dlhis.Basic/Map/Request/SavePointMapDetailRequest.cs @@ -0,0 +1,38 @@ +using Dlhis.Entity.Basic.Enums; +using System.ComponentModel.DataAnnotations; + +namespace Dlhis.Basic.Map.Request; + +public class SavePointMapDetailRequest +{ + public long? Id { get; set; } + + /// + /// 点位图code + /// + [Required] + public Guid PointMapCode { get; set; } + + /// + /// 数据code 如果是设备那么为设备code + /// + [Required] + public Guid UniqueCode { get; set; } + + /// + /// 数据类型 PointMapDetailEnumType + /// + [EnumDataType(typeof(PointMapDetailEnumType))] + public PointMapDetailEnumType Type { get; set; } + + /// + /// XYZ + /// + [Required] + public string Position { get; set; } + + /// + /// 备注 + /// + public string Remark { get; set; } +} diff --git a/Src/Dlhis.Basic/Map/Request/SavePointMapRequest.cs b/Src/Dlhis.Basic/Map/Request/SavePointMapRequest.cs new file mode 100644 index 00000000..3195ac5d --- /dev/null +++ b/Src/Dlhis.Basic/Map/Request/SavePointMapRequest.cs @@ -0,0 +1,22 @@ +using System.ComponentModel.DataAnnotations; + +namespace Dlhis.Basic.Map.Request; + +public class SavePointMapRequest +{ + public long? Id { get; set; } + + /// + /// 位置名称 + /// + [Required(ErrorMessage = "位置名称不可为空")] + public string Name { get; set; } + + /// + /// 图 + /// + [Required(ErrorMessage = "图片不可为空")] + public string ImageUrl { get; set; } + + public string Remark { get; set; } +} diff --git a/Src/Dlhis.Basic/Map/Response/PointMapDetailResponse.cs b/Src/Dlhis.Basic/Map/Response/PointMapDetailResponse.cs new file mode 100644 index 00000000..2528f29f --- /dev/null +++ b/Src/Dlhis.Basic/Map/Response/PointMapDetailResponse.cs @@ -0,0 +1,26 @@ +using Dlhis.Entity.Basic.Enums; + +namespace Dlhis.Basic.Map.Response; + +public class PointMapDetailResponse +{ + /// + /// 数据code + /// + public Guid UniqueCode { get; set; } + + /// + /// 数据类型 + /// + public PointMapDetailEnumType Type { get; set; } + + /// + /// XYZ + /// + public string Position { get; set; } + + /// + /// 备注 + /// + public string Remark { get; set; } +} diff --git a/Src/Dlhis.Basic/Map/Response/PointMapResponse.cs b/Src/Dlhis.Basic/Map/Response/PointMapResponse.cs new file mode 100644 index 00000000..44bcad67 --- /dev/null +++ b/Src/Dlhis.Basic/Map/Response/PointMapResponse.cs @@ -0,0 +1,23 @@ +using SqlSugar; + +namespace Dlhis.Basic.Map.Response; + +public class PointMapResponse +{ + public long Id { get; set; } + + public Guid Code { get; set; } + + /// + /// 位置名称 + /// + public string Name { get; set; } + + /// + /// 图 + /// + public string ImageUrl { get; set; } + + + public string Remark { get; set; } +} diff --git a/Src/Dlhis.Basic/Map/Services/IPointMapDetailService.cs b/Src/Dlhis.Basic/Map/Services/IPointMapDetailService.cs new file mode 100644 index 00000000..3a060636 --- /dev/null +++ b/Src/Dlhis.Basic/Map/Services/IPointMapDetailService.cs @@ -0,0 +1,13 @@ +using Dlhis.Basic.Map.Request; +using Dlhis.Basic.Map.Response; + +namespace Dlhis.Basic.Map.Services; + +public interface IPointMapDetailService : IScopeDependency +{ + Task SaveAsync(SavePointMapDetailRequest request); + + Task DeleteAsync(long id); + + Task> GetListByPointMapCodeAsync(Guid pointMapCode); +} diff --git a/Src/Dlhis.Basic/Map/Services/IPointMapService.cs b/Src/Dlhis.Basic/Map/Services/IPointMapService.cs new file mode 100644 index 00000000..d91d8010 --- /dev/null +++ b/Src/Dlhis.Basic/Map/Services/IPointMapService.cs @@ -0,0 +1,14 @@ +using Dlhis.Basic.Map.Request; +using Dlhis.Basic.Map.Response; +using Kurisu.Core.DataAccess.Dto; + +namespace Dlhis.Basic.Map.Services; + +public interface IPointMapService : IScopeDependency +{ + Task> GetPageAsync(PageDto request); + + Task SaveAsync(SavePointMapRequest request); + + Task DeleteAsync(long id); +} diff --git a/Src/Dlhis.Basic/Map/Services/Implements/PointMapDetailService.cs b/Src/Dlhis.Basic/Map/Services/Implements/PointMapDetailService.cs new file mode 100644 index 00000000..44563249 --- /dev/null +++ b/Src/Dlhis.Basic/Map/Services/Implements/PointMapDetailService.cs @@ -0,0 +1,45 @@ +using Dlhis.Basic.Map.Request; +using Dlhis.Basic.Map.Response; +using Dlhis.Entity.Basic.Entity; +using Kurisu.SqlSugar.Services; +using Mapster; + +namespace Dlhis.Basic.Map.Services.Implements; + +public class PointMapDetailService : IPointMapDetailService +{ + private readonly IDbContext _dbContext; + + public PointMapDetailService(IDbContext dbContext) + { + _dbContext = dbContext; + } + + public async Task SaveAsync(SavePointMapDetailRequest request) + { + if (!request.Id.HasValue) + { + var entity = request.Adapt(); + await _dbContext.InsertAsync(entity); + } + else + { + var entity = await _dbContext.Queryable().Where(x => x.Id == request.Id).SingleAsync(); + request.Adapt(entity); + await _dbContext.UpdateAsync(entity); + } + } + + public async Task DeleteAsync(long id) + { + await _dbContext.Deleteable().Where(x => x.Id == id).ExecuteCommandAsync(); + } + + public async Task> GetListByPointMapCodeAsync(Guid pointMapCode) + { + return await _dbContext.Queryable() + .Where(x => x.PointMapCode == pointMapCode) + .Select() + .ToListAsync(); + } +} diff --git a/Src/Dlhis.Basic/Map/Services/Implements/PointMapService.cs b/Src/Dlhis.Basic/Map/Services/Implements/PointMapService.cs new file mode 100644 index 00000000..fe5f1338 --- /dev/null +++ b/Src/Dlhis.Basic/Map/Services/Implements/PointMapService.cs @@ -0,0 +1,56 @@ +using Dlhis.Basic.Map.Request; +using Dlhis.Basic.Map.Response; +using Dlhis.Entity.Basic.Entity; +using Kurisu.AspNetCore.Utils.Extensions; +using Kurisu.Core.DataAccess.Dto; +using Kurisu.SqlSugar.Extensions; +using Kurisu.SqlSugar.Services; +using Mapster; + +namespace Dlhis.Basic.Map.Services.Implements; + +public class PointMapService : IPointMapService +{ + private readonly IDbContext _dbContext; + + public PointMapService(IDbContext dbContext) + { + _dbContext = dbContext; + } + + + public async Task> GetPageAsync(PageDto request) + { + return await _dbContext.Queryable() + .Select() + .ToPageListAsync(request); + } + + public async Task SaveAsync(SavePointMapRequest request) + { + if (!request.Id.HasValue) + { + var entity = request.Adapt(); + entity.Code = Guid.NewGuid(); + + await _dbContext.InsertAsync(entity); + } + else + { + var entity = await _dbContext.Queryable().Where(x => x.Id == request.Id).SingleAsync(); + entity.ThrowIfNull("点位图不存在,无法编辑!"); + request.Adapt(entity); + await _dbContext.UpdateAsync(entity); + } + } + + public async Task DeleteAsync(long id) + { + var entity = await _dbContext.Queryable().Where(x => x.Id == id).SingleAsync(); + if (entity != null) + { + await _dbContext.Deleteable().Where(x => x.Id == id).ExecuteCommandAsync(); + await _dbContext.Deleteable().Where(x => x.PointMapCode == entity.Code).ExecuteCommandAsync(); + } + } +} diff --git a/Src/Dlhis.Canteen/MealSupplementRecord/Response/MealSupplementRecordResponse.cs b/Src/Dlhis.Canteen/MealSupplementRecord/Response/MealSupplementRecordResponse.cs index fe39466d..01d8baf3 100644 --- a/Src/Dlhis.Canteen/MealSupplementRecord/Response/MealSupplementRecordResponse.cs +++ b/Src/Dlhis.Canteen/MealSupplementRecord/Response/MealSupplementRecordResponse.cs @@ -1,6 +1,4 @@ using Dlhis.Entity.Basic.Enums; -using SqlSugar.DbConvert; -using SqlSugar; using Kurisu.AspNetCore.Utils.Extensions; namespace Dlhis.Canteen.MealSupplementRecord.Response; diff --git a/Src/Dlhis.Entity/Basic/Entity/PointMapDetailEntity.cs b/Src/Dlhis.Entity/Basic/Entity/PointMapDetailEntity.cs new file mode 100644 index 00000000..eb95854f --- /dev/null +++ b/Src/Dlhis.Entity/Basic/Entity/PointMapDetailEntity.cs @@ -0,0 +1,44 @@ +using Dlhis.Entity.Basic.Enums; +using Kurisu.Core.DataAccess.Entity; +using Kurisu.SqlSugar; +using SqlSugar; +using SqlSugar.DbConvert; + +namespace Dlhis.Entity.Basic.Entity; + +/// +/// 点位图数据 +/// +[SugarTable(TableName = "PointMapDetail", TableDescription = "点位图数据")] +public class PointMapDetailEntity : SugarBaseEntity, ITenantId +{ + /// + /// 点位图code + /// + [SugarColumn(IsNullable = false, ColumnDescription = "点位图code")] + public Guid PointMapCode { get; set; } + + /// + /// 数据code + /// + public Guid UniqueCode { get; set; } + + /// + /// 数据类型 + /// + [SugarColumn(IsNullable = false, ColumnDescription = "数据类型", ColumnDataType = "varchar(50)", SqlParameterDbType = typeof(EnumToStringConvert))] + public PointMapDetailEnumType Type { get; set; } + + /// + /// XYZ + /// + [SugarColumn(IsNullable = false, ColumnDescription = "XYZ")] + public string Position { get; set; } + + /// + /// 备注 + /// + public string Remark { get; set; } + + public string TenantId { get; set; } +} diff --git a/Src/Dlhis.Entity/Basic/Entity/PointMapEntity.cs b/Src/Dlhis.Entity/Basic/Entity/PointMapEntity.cs new file mode 100644 index 00000000..53414e4e --- /dev/null +++ b/Src/Dlhis.Entity/Basic/Entity/PointMapEntity.cs @@ -0,0 +1,36 @@ +using Kurisu.Core.DataAccess.Entity; +using Kurisu.SqlSugar; +using SqlSugar; + +namespace Dlhis.Entity.Basic.Entity; + +/// +/// 点位图 +/// +[SugarTable(TableName = "PointMaps", TableDescription = "点位图")] +public class PointMapEntity : SugarBaseEntity, ITenantId, IImageUrl +{ + /// + /// code + /// + [SugarColumn(IsNullable = false, ColumnDescription = "code")] + public Guid Code { get; set; } + + /// + /// 位置名称 + /// + [SugarColumn(IsNullable = false, ColumnDescription = "点位名称")] + public string Name { get; set; } + + /// + /// 图 + /// + [SugarColumn(IsNullable = false, ColumnDescription = "图片地址")] + public string ImageUrl { get; set; } + + + [SugarColumn(ColumnDescription = "备注")] + public string Remark { get; set; } + + public string TenantId { get; set; } +} diff --git a/Src/Dlhis.Entity/Basic/Enums/PointMapDetailEnumType.cs b/Src/Dlhis.Entity/Basic/Enums/PointMapDetailEnumType.cs new file mode 100644 index 00000000..df499bc3 --- /dev/null +++ b/Src/Dlhis.Entity/Basic/Enums/PointMapDetailEnumType.cs @@ -0,0 +1,16 @@ +using System.ComponentModel; + +namespace Dlhis.Entity.Basic.Enums; + +/// +/// 点位图数据类型 +/// +[Description("点位图数据类型")] +public enum PointMapDetailEnumType +{ + /// + /// 设备 + /// + [Description("设备")] + Device = 1, +} From 56ef9a87609d24100c1d649ad8b021446028282c Mon Sep 17 00:00:00 2001 From: liguoyang Date: Tue, 2 Apr 2024 19:56:08 +0800 Subject: [PATCH 5/6] =?UTF-8?q?refactor=20=E6=96=87=E4=BB=B6=E7=89=88?= =?UTF-8?q?=E6=9C=AC=E9=87=8D=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Src/Dlhis.Common/Dlhis.Common.csproj | 8 +- .../EnumSetting/EnumsController.cs | 7 +- .../Constants/FileBucketConstants.cs | 13 ++ .../Controllers/ApkFileController.cs | 61 ------ .../Controllers/FileController.cs | 58 +++++- .../FileOperation/Request/ApkRequest.cs | 30 --- .../Request/FileVersionUploadRequest.cs | 45 +++++ .../Request/UploadFileReuqest.cs | 14 +- .../Response/ApkFile1Response.cs | 32 --- .../Response/ApkFileFormLocalResponse.cs | 25 --- .../FileOperation/Response/ApkFileResponse.cs | 37 ---- .../Response/CommonEnumResponse.cs | 17 +- .../Response/FileVersionResponse.cs | 31 +++ .../FileOperation/Response/KeyValueDto.cs | 8 - .../FileOperation/Services/ApkFIileService.cs | 188 ------------------ .../Services/IApkFIileService.cs | 27 --- .../Services/IFileVersionService.cs | 16 ++ .../FileOperation/Services/IMinioService.cs | 34 +++- .../Services/Implements/ApkFIileService.cs | 102 ---------- .../Services/Implements/FileVersionService.cs | 74 +++++++ .../Services/Implements/MinioService.cs | 65 ------ Src/Dlhis.Entity/Common/ApkFileEntity.cs | 48 ----- Src/Dlhis.Entity/Common/FileVersionEntity.cs | 43 ++++ 23 files changed, 332 insertions(+), 651 deletions(-) create mode 100644 Src/Dlhis.Common/FileOperation/Constants/FileBucketConstants.cs delete mode 100644 Src/Dlhis.Common/FileOperation/Controllers/ApkFileController.cs delete mode 100644 Src/Dlhis.Common/FileOperation/Request/ApkRequest.cs create mode 100644 Src/Dlhis.Common/FileOperation/Request/FileVersionUploadRequest.cs delete mode 100644 Src/Dlhis.Common/FileOperation/Response/ApkFile1Response.cs delete mode 100644 Src/Dlhis.Common/FileOperation/Response/ApkFileFormLocalResponse.cs delete mode 100644 Src/Dlhis.Common/FileOperation/Response/ApkFileResponse.cs create mode 100644 Src/Dlhis.Common/FileOperation/Response/FileVersionResponse.cs delete mode 100644 Src/Dlhis.Common/FileOperation/Response/KeyValueDto.cs delete mode 100644 Src/Dlhis.Common/FileOperation/Services/ApkFIileService.cs delete mode 100644 Src/Dlhis.Common/FileOperation/Services/IApkFIileService.cs create mode 100644 Src/Dlhis.Common/FileOperation/Services/IFileVersionService.cs delete mode 100644 Src/Dlhis.Common/FileOperation/Services/Implements/ApkFIileService.cs create mode 100644 Src/Dlhis.Common/FileOperation/Services/Implements/FileVersionService.cs delete mode 100644 Src/Dlhis.Entity/Common/ApkFileEntity.cs create mode 100644 Src/Dlhis.Entity/Common/FileVersionEntity.cs diff --git a/Src/Dlhis.Common/Dlhis.Common.csproj b/Src/Dlhis.Common/Dlhis.Common.csproj index a2e461e0..bc489a52 100644 --- a/Src/Dlhis.Common/Dlhis.Common.csproj +++ b/Src/Dlhis.Common/Dlhis.Common.csproj @@ -11,9 +11,13 @@ + + + + @@ -25,8 +29,4 @@ - - - - diff --git a/Src/Dlhis.Common/EnumSetting/EnumsController.cs b/Src/Dlhis.Common/EnumSetting/EnumsController.cs index cc940da5..1821b42f 100644 --- a/Src/Dlhis.Common/EnumSetting/EnumsController.cs +++ b/Src/Dlhis.Common/EnumSetting/EnumsController.cs @@ -2,6 +2,7 @@ using Dlhis.Common.FileOperation.Response; using Dlhis.Entity.Basic.Entity; using Kurisu.AspNetCore.Utils.Extensions; +using Kurisu.Core.CustomClass; using Kurisu.SqlSugar.Services; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; @@ -46,7 +47,7 @@ public class EnumsController : ControllerBase { var e = (Enum)Enum.Parse(item.FieldType, item.GetValue(null).ToString()); var fd = e.GetDescription(); - return new KeyValueDto + return new KeyValueDto { Key = fd, Value = (int)item.GetValue(null) @@ -66,7 +67,7 @@ public class EnumsController : ControllerBase { Code = type, Name = type, - Data = g.AsEnumerable().Select(x => new KeyValueDto + Data = g.AsEnumerable().Select(x => new KeyValueDto { Key = x.Display, Value = x.Code @@ -94,7 +95,7 @@ public class EnumsController : ControllerBase { var e = (Enum)Enum.Parse(item.FieldType, item.GetValue(null).ToString()); var fd = e.GetDescription(); - return new KeyValueDto + return new KeyValueDto { Key = fd, Value = (int)item.GetValue(null) diff --git a/Src/Dlhis.Common/FileOperation/Constants/FileBucketConstants.cs b/Src/Dlhis.Common/FileOperation/Constants/FileBucketConstants.cs new file mode 100644 index 00000000..a26b3e14 --- /dev/null +++ b/Src/Dlhis.Common/FileOperation/Constants/FileBucketConstants.cs @@ -0,0 +1,13 @@ +namespace Dlhis.Common.FileOperation.Constants; + +public static class FileBucketConstants +{ + /// + /// 文件buckets + /// + public static List Buckets { get; } = new() + { + "restaurant", + "apk" + }; +} diff --git a/Src/Dlhis.Common/FileOperation/Controllers/ApkFileController.cs b/Src/Dlhis.Common/FileOperation/Controllers/ApkFileController.cs deleted file mode 100644 index 6036920e..00000000 --- a/Src/Dlhis.Common/FileOperation/Controllers/ApkFileController.cs +++ /dev/null @@ -1,61 +0,0 @@ -using Dlhis.Common.FileOperation.Request; -using Dlhis.Common.FileOperation.Response; -using Dlhis.Common.FileOperation.Services; -using Microsoft.AspNetCore.Authorization; -using Microsoft.AspNetCore.Mvc; -using Org.BouncyCastle.Asn1.Ocsp; - -namespace Dlhis.Common.FileOperation.Controllers; - -/// -/// APK文件操作 -/// -[Obsolete("作废重写")] -[Authorize] -[Route("api/[controller]")] -[ApiController] -public class ApkFileController : ControllerBase -{ - private readonly IApkFIileService _apkFIileService; - - public ApkFileController(IApkFIileService apkFIileService) - { - _apkFIileService = apkFIileService; - } - /// - /// minlo文件上传 - /// - /// - /// - [HttpPost("minio")] - [RequestSizeLimit(300_000_000)] - public async Task FormSingleFileUpload([FromForm] ApkRequest request) - { - return await _apkFIileService.FormSingleFileUpload(request); - } - - /// - /// minlo文件下载 - /// - /// - /// - [HttpGet("url")] - public async Task RequestDownloadFile(string fileName) - { - return await _apkFIileService.RequestDownloadFile(fileName); - } - - /// - /// 获取最新版本 - /// - /// - /// - [HttpGet("lastversion")] - public async Task GetLastVersionAsync(string productCode) - { - return await _apkFIileService.GetLastVersionAsync(productCode); - } -} - - - diff --git a/Src/Dlhis.Common/FileOperation/Controllers/FileController.cs b/Src/Dlhis.Common/FileOperation/Controllers/FileController.cs index 46fb28f3..9d95fc60 100644 --- a/Src/Dlhis.Common/FileOperation/Controllers/FileController.cs +++ b/Src/Dlhis.Common/FileOperation/Controllers/FileController.cs @@ -1,20 +1,28 @@ -using Dlhis.Common.FileOperation.Request; +using System.ComponentModel.DataAnnotations; +using Dlhis.Common.FileOperation.Request; +using Dlhis.Common.FileOperation.Response; using Dlhis.Common.FileOperation.Services; +using Kurisu.Core.DataAccess.Dto; 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; + private readonly IFileVersionService _fileVersionService; - public FileController(IMinioService minioService) + public FileController(IMinioService minioService, IFileVersionService fileVersionService) { _minioService = minioService; + _fileVersionService = fileVersionService; } /// @@ -27,4 +35,50 @@ public class FileController : ControllerBase { return await _minioService.UploadFileAsync(request.Bucket, request.File); } + + + /// + /// 文件上传(版本) + /// + /// + /// + [HttpPost("{Bucket}/version/upload")] + [RequestSizeLimit(300_000_000)] + public async Task UploadFileAsync([FromForm] FileVersionUploadRequest request) + { + return await _fileVersionService.UploadFileAsync(request); + } + + /// + /// 文件版本分页 + /// + /// + /// + [HttpGet("version/page")] + public async Task> GetPageAsync([FromQuery] PageDto request) + { + return await _fileVersionService.GetPageAsync(request); + } + + /// + /// 文件版本列表 + /// + /// + /// + [HttpGet("version/list")] + public async Task> GetListByCodeAsync([Required] string code) + { + return await _fileVersionService.GetListByCodeAsync(code); + } + + /// + /// 文件版本最新 + /// + /// + /// + [HttpGet("version/last")] + public async Task GetLastByCodeAsync([Required] string code) + { + return await _fileVersionService.GetLastByCodeAsync(code); + } } diff --git a/Src/Dlhis.Common/FileOperation/Request/ApkRequest.cs b/Src/Dlhis.Common/FileOperation/Request/ApkRequest.cs deleted file mode 100644 index aca49440..00000000 --- a/Src/Dlhis.Common/FileOperation/Request/ApkRequest.cs +++ /dev/null @@ -1,30 +0,0 @@ -namespace Dlhis.Common.FileOperation.Request -{ - public class ApkRequest - { - /// - /// 文件 - /// - public IFormFile formFile { get; set; } - - /// - /// 版本号 - /// - public int VersionCode { get; set; } - - /// - /// 版本名称 - /// - public string VersionName { get; set; } - - /// - /// 修改信息 - /// - public string UpdateMessage { get; set; } - - /// - /// 产品代码 - /// - public string ProductCode { get; set; } - } -} diff --git a/Src/Dlhis.Common/FileOperation/Request/FileVersionUploadRequest.cs b/Src/Dlhis.Common/FileOperation/Request/FileVersionUploadRequest.cs new file mode 100644 index 00000000..04249399 --- /dev/null +++ b/Src/Dlhis.Common/FileOperation/Request/FileVersionUploadRequest.cs @@ -0,0 +1,45 @@ +using System.ComponentModel.DataAnnotations; +using Dlhis.Common.FileOperation.Constants; +using Microsoft.AspNetCore.Mvc; + +namespace Dlhis.Common.FileOperation.Request; + +public class FileVersionUploadRequest : IValidatableObject +{ + /// + /// bucket + /// + [FromRoute] + public string Bucket { get; set; } + + /// + /// 文件 + /// + [Required] + public IFormFile File { get; set; } + + /// + /// 文件名称 + /// + [Required] + public string Name { get; set; } + + /// + /// code + /// + [Required] + public string Code { get; set; } + + /// + /// 描述信息 + /// + public string Description { get; set; } + + public IEnumerable Validate(ValidationContext validationContext) + { + if (!FileBucketConstants.Buckets.Contains(Bucket)) + { + yield return new ValidationResult($"不支持{Bucket}", new[] { nameof(Bucket) }); + } + } +} diff --git a/Src/Dlhis.Common/FileOperation/Request/UploadFileReuqest.cs b/Src/Dlhis.Common/FileOperation/Request/UploadFileReuqest.cs index ac690a39..767287bf 100644 --- a/Src/Dlhis.Common/FileOperation/Request/UploadFileReuqest.cs +++ b/Src/Dlhis.Common/FileOperation/Request/UploadFileReuqest.cs @@ -1,8 +1,10 @@ -using Microsoft.AspNetCore.Mvc; +using System.ComponentModel.DataAnnotations; +using Dlhis.Common.FileOperation.Constants; +using Microsoft.AspNetCore.Mvc; namespace Dlhis.Common.FileOperation.Request; -public class UploadFileReuqest +public class UploadFileReuqest : IValidatableObject { /// /// bucket @@ -14,4 +16,12 @@ public class UploadFileReuqest /// 文件 /// public IFormFile File { get; set; } + + public IEnumerable Validate(ValidationContext validationContext) + { + if (!FileBucketConstants.Buckets.Contains(Bucket)) + { + yield return new ValidationResult($"不支持{Bucket}", new[] { nameof(Bucket) }); + } + } } diff --git a/Src/Dlhis.Common/FileOperation/Response/ApkFile1Response.cs b/Src/Dlhis.Common/FileOperation/Response/ApkFile1Response.cs deleted file mode 100644 index 143be5fb..00000000 --- a/Src/Dlhis.Common/FileOperation/Response/ApkFile1Response.cs +++ /dev/null @@ -1,32 +0,0 @@ -using SqlSugar; - -namespace Dlhis.Common.FileOperation.Response -{ - public class ApkFile1Response - { - /// - /// 文件名称 - /// - public string Name { get; set; } - - /// - /// 地址 - /// - public string Url { get; set; } - - /// - /// 版本号 - /// - public int VersionCode { get; set; } - - /// - /// 版本名称 - /// - public int VersionName { get; set; } - - /// - /// 修改信息 - /// - public string UpdateMessage { get; set; } - } -} diff --git a/Src/Dlhis.Common/FileOperation/Response/ApkFileFormLocalResponse.cs b/Src/Dlhis.Common/FileOperation/Response/ApkFileFormLocalResponse.cs deleted file mode 100644 index b4c78bf2..00000000 --- a/Src/Dlhis.Common/FileOperation/Response/ApkFileFormLocalResponse.cs +++ /dev/null @@ -1,25 +0,0 @@ -namespace Dlhis.Common.FileOperation.Response -{ - public class ApkFileFormLocalResponse - { - /// - /// 文件名称 - /// - public string Name { get; set; } - - /// - /// 版本号 - /// - public int VersionCode { get; set; } - - /// - /// 版本名称 - /// - public int VersionName { get; set; } - - /// - /// 修改信息 - /// - public string UpdateMessage { get; set; } - } -} diff --git a/Src/Dlhis.Common/FileOperation/Response/ApkFileResponse.cs b/Src/Dlhis.Common/FileOperation/Response/ApkFileResponse.cs deleted file mode 100644 index 78a8db3f..00000000 --- a/Src/Dlhis.Common/FileOperation/Response/ApkFileResponse.cs +++ /dev/null @@ -1,37 +0,0 @@ -using SqlSugar; - -namespace Dlhis.Common.FileOperation.Response -{ - public class ApkFileResponse - { - /// - /// 文件名称 - /// - public string Name { get; set; } - - /// - /// 版本号 - /// - public int VersionCode { get; set; } - - /// - /// 版本名称 - /// - public string VersionName { get; set; } - - /// - /// 修改信息 - /// - public string UpdateMessage { get; set; } - - /// - /// 产品代码 - /// - public string ProductCode { get; set; } - - /// - /// url - /// - public string Url { get; set; } - } -} diff --git a/Src/Dlhis.Common/FileOperation/Response/CommonEnumResponse.cs b/Src/Dlhis.Common/FileOperation/Response/CommonEnumResponse.cs index 06a5a66e..3d4ee959 100644 --- a/Src/Dlhis.Common/FileOperation/Response/CommonEnumResponse.cs +++ b/Src/Dlhis.Common/FileOperation/Response/CommonEnumResponse.cs @@ -1,9 +1,12 @@ -namespace Dlhis.Common.FileOperation.Response +using Kurisu.Core.CustomClass; + +namespace Dlhis.Common.FileOperation.Response; + +public class CommonEnumResponse { - public class CommonEnumResponse - { - public string Code { get; set; } - public string Name { get; set; } - public List Data { get; set; } - } + public string Code { get; set; } + + public string Name { get; set; } + + public List> Data { get; set; } } diff --git a/Src/Dlhis.Common/FileOperation/Response/FileVersionResponse.cs b/Src/Dlhis.Common/FileOperation/Response/FileVersionResponse.cs new file mode 100644 index 00000000..891f6358 --- /dev/null +++ b/Src/Dlhis.Common/FileOperation/Response/FileVersionResponse.cs @@ -0,0 +1,31 @@ +namespace Dlhis.Common.FileOperation.Response; + +public class FileVersionResponse +{ + public long Id { get; set; } + + /// + /// 文件名称 + /// + public string Name { get; set; } + + /// + /// 文件code + /// + public string Code { get; set; } + + /// + /// 版本号 + /// + public int Version { get; set; } + + /// + /// 描述信息 + /// + public string Description { get; set; } + + /// + /// 文件地址 + /// + public string Url { get; set; } +} diff --git a/Src/Dlhis.Common/FileOperation/Response/KeyValueDto.cs b/Src/Dlhis.Common/FileOperation/Response/KeyValueDto.cs deleted file mode 100644 index f7cc487f..00000000 --- a/Src/Dlhis.Common/FileOperation/Response/KeyValueDto.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace Dlhis.Common.FileOperation.Response; - -public class KeyValueDto -{ - public string Key { get; set; } - - public object Value { get; set; } -} diff --git a/Src/Dlhis.Common/FileOperation/Services/ApkFIileService.cs b/Src/Dlhis.Common/FileOperation/Services/ApkFIileService.cs deleted file mode 100644 index 2ebc1240..00000000 --- a/Src/Dlhis.Common/FileOperation/Services/ApkFIileService.cs +++ /dev/null @@ -1,188 +0,0 @@ -using Dlhis.Common.ApiLog.Response; -using Dlhis.Common.FileOperation.Request; -using Dlhis.Common.FileOperation.Response; -using Dlhis.Entity.Common; -using Kurisu.AspNetCore.Utils.Extensions; -using Kurisu.SqlSugar.Services; -using Mapster; -using Microsoft.AspNetCore.Mvc; - -namespace Dlhis.Common.FileOperation.Services; - -public class ApkFIileService : IApkFIileService -{ - private readonly IMinioService _minioService; - private readonly IDbContext _dbContext; - - public ApkFIileService(IMinioService minioService, IDbContext dbContext) - { - _minioService = minioService; - _dbContext = dbContext; - } - - /// - /// 文件上传 - /// - /// - /// - public async Task FormSingleFileUpload(ApkRequest request) - { - //上传 - var fileUrl = await _minioService.MinloUploadFileAsync(request); - - string fileName = request.formFile.FileName; - - //更新数据库 - var entity = await _dbContext.Queryable().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().Where(x => x.Name == fileName).FirstAsync(); - var res = newEntity.Adapt(); - return res; - } - - /// - /// 文件下载 - /// - /// - public async Task RequestDownloadFile(string fileName) - { - return await _minioService.MinloDownloadLinkAsync(fileName); - } - - /// - /// 本地文件上传 - /// - /// - /// - public async Task 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().Where(x => x.Name == fileName).FirstAsync(); - if (entity == null) - { - var info = new ApkFileEntity - { - Name = fileName, - //Url = completeFilePath, - VersionCode = request.VersionCode, - VersionName = request.VersionName, - UpdateMessage = request.UpdateMessage, - }; - await _dbContext.InsertAsync(info); - } - else - { - //entity.Url = completeFilePath; - entity.VersionCode = request.VersionCode; - entity.VersionName = request.VersionName; - entity.UpdateMessage = request.UpdateMessage; - await _dbContext.UpdateAsync(entity); - } - var newEntity = await _dbContext.Queryable().Where(x => x.Name == fileName).FirstAsync(); - var res = newEntity.Adapt(); - return res; - - } - public string FormSingleFileUpload(IFormFile formFile) - { - try - { - var filePath = "C:\\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; - } - } - /// - /// 返回最新版本信息 - /// - /// - /// - public async Task LatestFile(string fileName) - { - var info = await _dbContext.Queryable() - .Where(x => x.Name == fileName) - .OrderByDescending(x => x.VersionCode) - .FirstAsync(); - info.ThrowIfNull($"没有{fileName}信息"); - var res = info.Adapt(); - return res; - } - - /// - /// 本地下载 - /// - /// - /// - public IActionResult FormLocalDownloadFile(string fileName) - { - var filePath = "C:\\apk\\"; - string path = filePath + fileName; - return new FileStreamResult(new FileStream(path, FileMode.Open), "application/octet-stream") { FileDownloadName = fileName }; - } - - Task IApkFIileService.FormSingleFileUpload(ApkRequest request) - { - throw new NotImplementedException(); - } - - public Task GetLastVersionAsync(string productCode) - { - throw new NotImplementedException(); - } -} - - diff --git a/Src/Dlhis.Common/FileOperation/Services/IApkFIileService.cs b/Src/Dlhis.Common/FileOperation/Services/IApkFIileService.cs deleted file mode 100644 index 047b8f6b..00000000 --- a/Src/Dlhis.Common/FileOperation/Services/IApkFIileService.cs +++ /dev/null @@ -1,27 +0,0 @@ -using Dlhis.Common.FileOperation.Request; -using Dlhis.Common.FileOperation.Response; -using Microsoft.AspNetCore.Mvc; - -namespace Dlhis.Common.FileOperation.Services; - -public interface IApkFIileService : IScopeDependency -{ - /// - /// 文件上传 - /// - /// - /// - Task FormSingleFileUpload(ApkRequest request); - - /// - /// 文件下载 - /// - /// - Task RequestDownloadFile(string fileName); - - - Task GetLastVersionAsync(string productCode); -} - - - diff --git a/Src/Dlhis.Common/FileOperation/Services/IFileVersionService.cs b/Src/Dlhis.Common/FileOperation/Services/IFileVersionService.cs new file mode 100644 index 00000000..69c2bdb7 --- /dev/null +++ b/Src/Dlhis.Common/FileOperation/Services/IFileVersionService.cs @@ -0,0 +1,16 @@ +using Dlhis.Common.FileOperation.Request; +using Dlhis.Common.FileOperation.Response; +using Kurisu.Core.DataAccess.Dto; + +namespace Dlhis.Common.FileOperation.Services; + +public interface IFileVersionService : IScopeDependency +{ + Task UploadFileAsync(FileVersionUploadRequest request); + + Task> GetPageAsync(PageDto request); + + Task> GetListByCodeAsync(string code); + + Task GetLastByCodeAsync(string code); +} diff --git a/Src/Dlhis.Common/FileOperation/Services/IMinioService.cs b/Src/Dlhis.Common/FileOperation/Services/IMinioService.cs index f70c17f0..6a318f01 100644 --- a/Src/Dlhis.Common/FileOperation/Services/IMinioService.cs +++ b/Src/Dlhis.Common/FileOperation/Services/IMinioService.cs @@ -1,21 +1,35 @@ -using Dlhis.Common.FileOperation.Request; - -namespace Dlhis.Common.FileOperation.Services; +namespace Dlhis.Common.FileOperation.Services; public interface IMinioService : ISingletonDependency { - Task MinloUploadFileAsync(ApkRequest request); - - Task MinloDownloadLinkAsync(string fileName); - - Task MinloRemoveFileAsync(string fileName); - - + /// + /// bucket不存在即创建 + /// + /// + /// + Task CreateBucketIfNotExistsAsync(string bucket); + /// + /// 判断是否存在bucket + /// + /// + /// Task ExistsBucketAsync(string bucket); + /// + /// 判断文件是否存在 + /// + /// + /// + /// Task ExistsFileAsync(string bucket, string objectName); + /// + /// 上传文件 + /// + /// + /// + /// Task UploadFileAsync(string bucket, IFormFile formFile); } diff --git a/Src/Dlhis.Common/FileOperation/Services/Implements/ApkFIileService.cs b/Src/Dlhis.Common/FileOperation/Services/Implements/ApkFIileService.cs deleted file mode 100644 index 9b920f5c..00000000 --- a/Src/Dlhis.Common/FileOperation/Services/Implements/ApkFIileService.cs +++ /dev/null @@ -1,102 +0,0 @@ -using Dlhis.Common.FileOperation.Request; -using Dlhis.Common.FileOperation.Response; -using Dlhis.Common.FileOperation.Services; -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; - private readonly IConfiguration Configuration; - - public ApkFIileService(IMinioService minioService, IDbContext dbContext, IConfiguration configuration) - { - _minioService = minioService; - _dbContext = dbContext; - Configuration = configuration; - } - - /// - /// 文件上传 - /// - /// - /// - public async Task FormSingleFileUpload(ApkRequest request) - { - //上传 - var fileUrl = await _minioService.MinloUploadFileAsync(request); - - string fileName = request.formFile.FileName; - - var lenFive = request.formFile.FileName.Length >= 5; - - lenFive.ThrowIfFalse("文件名长度不能小于5"); - var houzhui = request.formFile.FileName.Substring(request.formFile.FileName.Length - 4, 4).ToLower(); - var isApk = request.formFile.FileName.Substring(request.formFile.FileName.Length - 4, 4) == ".apk"; - isApk.ThrowIfFalse("文件不是apk类型"); - - //更新数据库 - var entity = await _dbContext.Queryable().Where(x => x.ProductCode == request.ProductCode).FirstAsync(); - if (entity == null) - { - var info = new ApkFileEntity - { - Name = fileName, - ProductCode = request.ProductCode, - VersionCode = request.VersionCode, - UpdateMessage = request.UpdateMessage, - VersionName = request.VersionName, - }; - await _dbContext.InsertAsync(info); - } - else - { - entity.VersionCode = request.VersionCode; - entity.UpdateMessage = request.UpdateMessage; - entity.VersionName = request.VersionName; - entity.Name = fileName; - await _dbContext.UpdateAsync(entity); - } - var newEntity = await _dbContext.Queryable().Where(x => x.ProductCode == request.ProductCode).FirstAsync(); - var res = newEntity.Adapt(); - return res; - } - - public async Task GetLastVersionAsync(string productCode) - { - var info = await _dbContext.Queryable() - .Where(x => x.ProductCode == productCode) - .Select() - .FirstAsync(); - info.ThrowIfNull($"产品{productCode}下没有apk存在"); - var url =await RequestDownloadFile(info.Name); - - var host = Configuration["MinIO:Endpoint"]; - - var modified_url = url.Replace(host, "https://yikatong.isawesome.cn/m"); - - info.Url = modified_url; - - return info; - } - - /// - /// 文件下载 - /// - /// - public async Task RequestDownloadFile(string fileName) - { - return await _minioService.MinloDownloadLinkAsync(fileName); - } - - - -} - - diff --git a/Src/Dlhis.Common/FileOperation/Services/Implements/FileVersionService.cs b/Src/Dlhis.Common/FileOperation/Services/Implements/FileVersionService.cs new file mode 100644 index 00000000..3d4a4285 --- /dev/null +++ b/Src/Dlhis.Common/FileOperation/Services/Implements/FileVersionService.cs @@ -0,0 +1,74 @@ +using Dlhis.Common.FileOperation.Request; +using Dlhis.Common.FileOperation.Response; +using Dlhis.Entity.Common; +using Kurisu.Core.DataAccess.Dto; +using Kurisu.SqlSugar.Extensions; +using Kurisu.SqlSugar.Services; + +namespace Dlhis.Common.FileOperation.Services.Implements; + +public class FileVersionService : IFileVersionService +{ + private readonly IMinioService _minioService; + private readonly IDbContext _dbContext; + + public FileVersionService(IMinioService minioService, IDbContext dbContext) + { + _minioService = minioService; + _dbContext = dbContext; + } + + public async Task UploadFileAsync(FileVersionUploadRequest request) + { + var url = await _minioService.UploadFileAsync(request.Bucket, request.File); + + var version = (await GetLastVersionAsync(request.Code)) + 1; + await _dbContext.InsertAsync(new FileVersionEntity + { + Name = request.Name, + Url = url, + Description = request.Description, + Code = request.Code, + Version = version, + }); + + return url; + } + + public async Task> GetPageAsync(PageDto request) + { + return await _dbContext.Queryable() + .OrderByDescending(x => x.CreateTime) + .Select() + .ToPageListAsync(request); + } + + public async Task> GetListByCodeAsync(string code) + { + return await _dbContext.Queryable() + .Where(x => x.Code == code) + .OrderByDescending(x => x.CreateTime) + .Select() + .ToListAsync(); + } + + public async Task GetLastByCodeAsync(string code) + { + return await _dbContext.Queryable() + .Where(x => x.Code == code) + .OrderByDescending(x => x.Version) + .Select() + .SingleAsync(); + } + + //************************************************************* help methods *************************************************************** + + private async Task GetLastVersionAsync(string code) + { + return await _dbContext.Queryable() + .Where(x => x.Code == code) + .OrderByDescending(x => x.Version) + .Select(x => x.Version) + .SingleAsync(); + } +} diff --git a/Src/Dlhis.Common/FileOperation/Services/Implements/MinioService.cs b/Src/Dlhis.Common/FileOperation/Services/Implements/MinioService.cs index 70d82c49..811f8a0a 100644 --- a/Src/Dlhis.Common/FileOperation/Services/Implements/MinioService.cs +++ b/Src/Dlhis.Common/FileOperation/Services/Implements/MinioService.cs @@ -1,22 +1,17 @@ using Dlhis.Common.FileOperation.Configurations; -using Dlhis.Common.FileOperation.Request; -using Microsoft.CodeAnalysis.CSharp.Syntax; 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 options) { _client = client; - _minIOOptions = options.Value; } public async Task ExistsBucketAsync(string bucket) @@ -71,64 +66,4 @@ public class MinioService : IMinioService return $"/{bucket}/{response.ObjectName}"; } - - - /// - /// 上传文件 - /// - /// - /// - public async Task MinloUploadFileAsync(ApkRequest request) - { - string fileName = request.formFile.FileName; - - using (var 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; - } - - /// - /// 文件下载链接 - /// - /// - public async Task 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; - } - } - - - /// - /// 单个删除文件 - /// - /// - /// - public async Task MinloRemoveFileAsync(string fileName) - { - await _client.RemoveObjectAsync(new RemoveObjectArgs() - .WithBucket(_minIOOptions.DefaultBucket) - .WithObject(fileName)); - } - } diff --git a/Src/Dlhis.Entity/Common/ApkFileEntity.cs b/Src/Dlhis.Entity/Common/ApkFileEntity.cs deleted file mode 100644 index e32c5bf9..00000000 --- a/Src/Dlhis.Entity/Common/ApkFileEntity.cs +++ /dev/null @@ -1,48 +0,0 @@ -using Kurisu.SqlSugar; -using SqlSugar; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Dlhis.Entity.Common; - -/// -/// Apk文件表 -/// -[SugarTable(TableName = "ApkFIile", TableDescription = "Apk文件表")] -public class ApkFileEntity : SugarBaseEntity -{ - /// - /// 文件名称 - /// - [SugarColumn(ColumnDescription = "文件名称")] - public string Name { get; set; } - - /// - /// 版本号 - /// - [SugarColumn(ColumnDescription = "版本号")] - public int VersionCode { get; set; } - - /// - /// 版本名称 - /// - [SugarColumn(ColumnDescription = "版本名称")] - public string VersionName { get; set; } - - /// - /// 修改信息 - /// - [SugarColumn(ColumnDescription = "修改信息")] - public string UpdateMessage { get; set; } - - /// - /// 产品代码 - /// - [SugarColumn(ColumnDescription = "产品代码")] - public string ProductCode { get; set; } -} - - diff --git a/Src/Dlhis.Entity/Common/FileVersionEntity.cs b/Src/Dlhis.Entity/Common/FileVersionEntity.cs new file mode 100644 index 00000000..d0973b26 --- /dev/null +++ b/Src/Dlhis.Entity/Common/FileVersionEntity.cs @@ -0,0 +1,43 @@ +using Kurisu.SqlSugar; +using SqlSugar; + +namespace Dlhis.Entity.Common; + +/// +/// 文件版本信息 +/// +[SugarTable(TableName = "FileVersion", TableDescription = "文件版本信息")] +public class FileVersionEntity : SugarBaseEntity +{ + /// + /// 文件名称 + /// + [SugarColumn(IsNullable = false, ColumnDescription = "文件名称")] + public string Name { get; set; } + + /// + /// 文件code + /// + [SugarColumn(IsNullable = false, ColumnDescription = "文件code", UniqueGroupNameList = new[] { "idx_FileVersion_Code" })] + public string Code { get; set; } + + /// + /// 版本号 + /// + [SugarColumn(IsNullable = false, ColumnDescription = "版本号")] + public int Version { get; set; } + + /// + /// 描述信息 + /// + [SugarColumn(ColumnDescription = "描述信息")] + public string Description { get; set; } + + /// + /// 文件地址 + /// + [SugarColumn(IsNullable = false, ColumnDescription = "文件地址")] + public string Url { get; set; } +} + + From e464fd811b0502113f93d9a957d93b94e7e20343 Mon Sep 17 00:00:00 2001 From: liguoyang Date: Tue, 2 Apr 2024 20:28:05 +0800 Subject: [PATCH 6/6] =?UTF-8?q?fix=20=E6=96=87=E4=BB=B6=E5=A4=A7=E5=B0=8F?= =?UTF-8?q?=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Src/Dlhis.Common/FileOperation/Controllers/FileController.cs | 4 +++- .../FileOperation/Request/FileVersionUploadRequest.cs | 2 +- .../FileOperation/Services/Implements/FileVersionService.cs | 4 ++-- .../FileOperation/Services/Implements/MinioService.cs | 3 +++ Src/Dlhis.Entity/Common/FileVersionEntity.cs | 4 ++-- 5 files changed, 11 insertions(+), 6 deletions(-) diff --git a/Src/Dlhis.Common/FileOperation/Controllers/FileController.cs b/Src/Dlhis.Common/FileOperation/Controllers/FileController.cs index 9d95fc60..d6b329e3 100644 --- a/Src/Dlhis.Common/FileOperation/Controllers/FileController.cs +++ b/Src/Dlhis.Common/FileOperation/Controllers/FileController.cs @@ -42,8 +42,10 @@ public class FileController : ControllerBase /// /// /// + [Authorize(Roles = "admin")] [HttpPost("{Bucket}/version/upload")] - [RequestSizeLimit(300_000_000)] + [RequestFormLimits(MultipartBodyLengthLimit = int.MaxValue)] + [RequestSizeLimit(int.MaxValue)] public async Task UploadFileAsync([FromForm] FileVersionUploadRequest request) { return await _fileVersionService.UploadFileAsync(request); diff --git a/Src/Dlhis.Common/FileOperation/Request/FileVersionUploadRequest.cs b/Src/Dlhis.Common/FileOperation/Request/FileVersionUploadRequest.cs index 04249399..45e4726d 100644 --- a/Src/Dlhis.Common/FileOperation/Request/FileVersionUploadRequest.cs +++ b/Src/Dlhis.Common/FileOperation/Request/FileVersionUploadRequest.cs @@ -15,7 +15,7 @@ public class FileVersionUploadRequest : IValidatableObject /// /// 文件 /// - [Required] + [FromForm] public IFormFile File { get; set; } /// diff --git a/Src/Dlhis.Common/FileOperation/Services/Implements/FileVersionService.cs b/Src/Dlhis.Common/FileOperation/Services/Implements/FileVersionService.cs index 3d4a4285..7466973c 100644 --- a/Src/Dlhis.Common/FileOperation/Services/Implements/FileVersionService.cs +++ b/Src/Dlhis.Common/FileOperation/Services/Implements/FileVersionService.cs @@ -58,7 +58,7 @@ public class FileVersionService : IFileVersionService .Where(x => x.Code == code) .OrderByDescending(x => x.Version) .Select() - .SingleAsync(); + .FirstAsync(); } //************************************************************* help methods *************************************************************** @@ -69,6 +69,6 @@ public class FileVersionService : IFileVersionService .Where(x => x.Code == code) .OrderByDescending(x => x.Version) .Select(x => x.Version) - .SingleAsync(); + .FirstAsync(); } } diff --git a/Src/Dlhis.Common/FileOperation/Services/Implements/MinioService.cs b/Src/Dlhis.Common/FileOperation/Services/Implements/MinioService.cs index 811f8a0a..b89a842f 100644 --- a/Src/Dlhis.Common/FileOperation/Services/Implements/MinioService.cs +++ b/Src/Dlhis.Common/FileOperation/Services/Implements/MinioService.cs @@ -1,4 +1,5 @@ using Dlhis.Common.FileOperation.Configurations; +using Kurisu.AspNetCore.Utils.Extensions; using Microsoft.Extensions.Options; using Minio; using Minio.DataModel.Args; @@ -50,6 +51,8 @@ public class MinioService : IMinioService public async Task UploadFileAsync(string bucket, IFormFile formFile) { + formFile.ThrowIfNull("请选择文件上传!"); + await CreateBucketIfNotExistsAsync(bucket); var ms = DateTime.Now.ToString("yyyyMMddHHmmssfff"); diff --git a/Src/Dlhis.Entity/Common/FileVersionEntity.cs b/Src/Dlhis.Entity/Common/FileVersionEntity.cs index d0973b26..5755a41b 100644 --- a/Src/Dlhis.Entity/Common/FileVersionEntity.cs +++ b/Src/Dlhis.Entity/Common/FileVersionEntity.cs @@ -18,13 +18,13 @@ public class FileVersionEntity : SugarBaseEntity /// /// 文件code /// - [SugarColumn(IsNullable = false, ColumnDescription = "文件code", UniqueGroupNameList = new[] { "idx_FileVersion_Code" })] + [SugarColumn(IsNullable = false, ColumnDescription = "文件code", UniqueGroupNameList = new[] { "idx_FileVersion_Code_Version" })] public string Code { get; set; } /// /// 版本号 /// - [SugarColumn(IsNullable = false, ColumnDescription = "版本号")] + [SugarColumn(IsNullable = false, ColumnDescription = "版本号", UniqueGroupNameList = new[] { "idx_FileVersion_Code_Version" })] public int Version { get; set; } ///