diff --git a/Src/Dlhis.Canteen/Order/Request/BalanceRecordPageByCostIdRequest.cs b/Src/Dlhis.Canteen/Order/Request/BalanceRecordPageByCostIdRequest.cs index 327b6a1c..c3660023 100644 --- a/Src/Dlhis.Canteen/Order/Request/BalanceRecordPageByCostIdRequest.cs +++ b/Src/Dlhis.Canteen/Order/Request/BalanceRecordPageByCostIdRequest.cs @@ -8,7 +8,6 @@ namespace Dlhis.Canteen.Order.Request /// /// 成本中心 /// - [Required(ErrorMessage = "成本中心号不能为空")] public string CostId { get; set; } /// diff --git a/Src/Dlhis.Canteen/Order/Request/BalanceRecordSummaryRequest.cs b/Src/Dlhis.Canteen/Order/Request/BalanceRecordSummaryRequest.cs index b208c8bd..e0c54589 100644 --- a/Src/Dlhis.Canteen/Order/Request/BalanceRecordSummaryRequest.cs +++ b/Src/Dlhis.Canteen/Order/Request/BalanceRecordSummaryRequest.cs @@ -8,7 +8,6 @@ namespace Dlhis.Canteen.Order.Request /// /// 成本中心 /// - [Required(ErrorMessage = "成本中心号不能为空")] public string CostId { get; set; } /// diff --git a/Src/Dlhis.Canteen/Order/Services/Implements/BalanceService.cs b/Src/Dlhis.Canteen/Order/Services/Implements/BalanceService.cs index 764466fd..38d59bb5 100644 --- a/Src/Dlhis.Canteen/Order/Services/Implements/BalanceService.cs +++ b/Src/Dlhis.Canteen/Order/Services/Implements/BalanceService.cs @@ -3,9 +3,12 @@ using Dlhis.Canteen.Order.Response; using Dlhis.Entity.Basic.Entity; using Dlhis.Entity.Canteen.Entities; using Dlhis.Entity.Canteen.Enums; +using Dlhis.Entity.Device.Entities; +using Dlhis.Entity.Device.Enums; using Kurisu.AspNetCore.UnifyResultAndValidation; using Kurisu.AspNetCore.Utils.Extensions; using Kurisu.Core.DataAccess.Dto; +using Kurisu.Core.DataAccess.Entity; using Kurisu.Core.User.Abstractions; using Kurisu.SqlSugar.Attributes; using Kurisu.SqlSugar.Extensions; @@ -81,6 +84,7 @@ public class BalanceService : IBalanceService .WhereIF(!request.UserCode.IsEmpty(), record => record.UserCode == request.UserCode) .WhereIF(!request.DepartmentNo.IsEmpty(), record => record.DepartmentNo == request.DepartmentNo) .WhereIF(!request.OriginTenantId.IsEmpty(), record => record.OriginTenantId == request.OriginTenantId) + .WhereIF(!request.CostId.IsEmpty(), record => record.CostId == request.CostId) .WhereIF(request.StartDatetime.HasValue, record => record.CostDateTime >= request.StartDatetime) .WhereIF(request.EndDatetime.HasValue, record => record.CostDateTime <= request.EndDatetime) .Where(record => record.Type == BalanceRecordTypeEnumType.Out) @@ -519,27 +523,41 @@ public class BalanceService : IBalanceService throw new UserFriendlyException("操作失败,请重试"); } - - private async Task> GetShiftCode() + [IgnoreTenant] + public async Task> GetShiftCode() { - var shiftCodeDict = new Dictionary(); + _dbContext.Client.QueryFilter.ClearAndBackup(); + try + { + var shiftCodeDict = new Dictionary(); - var shifts = await _dbContext.Queryable().ToListAsync(); - //guid - var breakfastCode = shifts.Where(x=>x.CustomCode == "shift-breakfast").Select(x => x.Code).First().ToString(); + var shifts = await _dbContext.Queryable().ToListAsync(); + //guid + var breakfastCode = shifts.Where(x => x.CustomCode == "shift-breakfast").Select(x => x.Code).First().ToString(); - var lunchCode = shifts.Where(x => x.CustomCode == "shift-lunch").Select(x => x.Code).First().ToString(); + var lunchCode = shifts.Where(x => x.CustomCode == "shift-lunch").Select(x => x.Code).First().ToString(); - var dinnerCode = shifts.Where(x => x.CustomCode == "shift-dinner").Select(x => x.Code).First().ToString(); + var dinnerCode = shifts.Where(x => x.CustomCode == "shift-dinner").Select(x => x.Code).First().ToString(); - var lateNightCode = shifts.Where(x => x.CustomCode == "shift-midnightsnack").Select(x => x.Code).First().ToString(); + var lateNightCode = shifts.Where(x => x.CustomCode == "shift-midnightsnack").Select(x => x.Code).First().ToString(); - shiftCodeDict.Add("Breakfast", breakfastCode.ToString()); - shiftCodeDict.Add("Lunch", lunchCode.ToString()); - shiftCodeDict.Add("Dinner", dinnerCode.ToString()); - shiftCodeDict.Add("LateNight", lateNightCode.ToString()); + shiftCodeDict.Add("Breakfast", breakfastCode.ToString()); + shiftCodeDict.Add("Lunch", lunchCode.ToString()); + shiftCodeDict.Add("Dinner", dinnerCode.ToString()); + shiftCodeDict.Add("LateNight", lateNightCode.ToString()); - return shiftCodeDict; + return shiftCodeDict; + } + catch (Exception ex) + { + _logger.LogError(ex, $"生成{DeviceTaskEnumType.UploadRecord.GetDescription()}任务失败:" + ex.Message); + return null; + } + finally + { + _dbContext.Client.QueryFilter.Restore(); + } + } } diff --git a/Src/Dlhis.Common/Controllers/ApkFIileController.cs b/Src/Dlhis.Common/Controllers/ApkFIileController.cs index 43ff9171..c77d5de2 100644 --- a/Src/Dlhis.Common/Controllers/ApkFIileController.cs +++ b/Src/Dlhis.Common/Controllers/ApkFIileController.cs @@ -22,18 +22,18 @@ public class ApkFIileController : ControllerBase _apkFIileService = apkFIileService; } /// - /// 文件上传 + /// minlo文件上传 /// /// /// - [HttpPost] + [HttpPost("minlo")] public async Task FormSingleFileUpload([FromForm] ApkRequest request) { return await _apkFIileService.FormSingleFileUpload(request); } /// - /// 文件下载 + /// minlo文件下载 /// /// /// @@ -42,8 +42,30 @@ public class ApkFIileController : ControllerBase { return await _apkFIileService.RequestDownloadFile(fileName); } - - + + + /// + /// 本地文件上传 + /// + /// + /// + [HttpPost("local")] + [RequestSizeLimit(100_000_000)] + + public async Task FormLocalFileUpload([FromForm] ApkRequest request) + { + return await _apkFIileService.FormLocalFileUpload(request); + } + /// + /// 本地文件下载 + /// + /// + /// + [HttpGet("local")] + public IActionResult FormLocalDownloadFile(string filePath) + { + return _apkFIileService.FormLocalDownloadFile(filePath); + } } diff --git a/Src/Dlhis.Common/Packs/MinioPack.cs b/Src/Dlhis.Common/Packs/MinioPack.cs index 636a2a7b..85635468 100644 --- a/Src/Dlhis.Common/Packs/MinioPack.cs +++ b/Src/Dlhis.Common/Packs/MinioPack.cs @@ -1,5 +1,6 @@ using Kurisu.AspNetCore.Startup; using Kurisu.SqlSugar.Extensions; +using Microsoft.AspNetCore.Http.Features; using Microsoft.Extensions.DependencyInjection; using Minio; @@ -17,6 +18,10 @@ namespace Dlhis.Common.Packs .WithCredentials("Zbjj05OFtR19e5TJopQU", "UMXtNdZhufhAAyYJ3XND4cEgZNUsgOWtbUzksizK") .Build(); services.AddSingleton(minioClient); + } + } + + } diff --git a/Src/Dlhis.Common/Response/ApkFileResponse.cs b/Src/Dlhis.Common/Response/ApkFileResponse.cs index 8a8166a7..f1529c84 100644 --- a/Src/Dlhis.Common/Response/ApkFileResponse.cs +++ b/Src/Dlhis.Common/Response/ApkFileResponse.cs @@ -4,6 +4,11 @@ namespace Dlhis.Common.Response { public class ApkFileResponse { + /// + /// 文件名称 + /// + public string Name { get; set; } + /// /// 地址 /// diff --git a/Src/Dlhis.Common/Services/IApkFIileService.cs b/Src/Dlhis.Common/Services/IApkFIileService.cs index deb37bdf..1a31d859 100644 --- a/Src/Dlhis.Common/Services/IApkFIileService.cs +++ b/Src/Dlhis.Common/Services/IApkFIileService.cs @@ -1,5 +1,6 @@ using Dlhis.Common.Request; using Dlhis.Common.Response; +using Microsoft.AspNetCore.Mvc; namespace Dlhis.Common.Services; @@ -17,6 +18,19 @@ namespace Dlhis.Common.Services; /// /// Task RequestDownloadFile(string fileName); + + /// + /// 本地上传 + /// + /// + /// + Task FormLocalFileUpload(ApkRequest request); + /// + /// 本地下载 + /// + /// + /// + IActionResult FormLocalDownloadFile(string filePath); } diff --git a/Src/Dlhis.Common/Services/Implements/ApkFIileService.cs b/Src/Dlhis.Common/Services/Implements/ApkFIileService.cs index 83d8523e..b8f5a236 100644 --- a/Src/Dlhis.Common/Services/Implements/ApkFIileService.cs +++ b/Src/Dlhis.Common/Services/Implements/ApkFIileService.cs @@ -3,6 +3,7 @@ using Dlhis.Common.Response; using Dlhis.Entity.Common; using Kurisu.SqlSugar.Services; using Mapster; +using Microsoft.AspNetCore.Mvc; namespace Dlhis.Common.Services.Implements; @@ -62,6 +63,96 @@ public class ApkFIileService : IApkFIileService { return await _minioService.MinloDownloadLinkAsync(fileName); } + + /// + /// 本地文件上传 + /// + /// + /// + public async Task FormLocalFileUpload(ApkRequest request) + { + //上传 + var completeFilePath = FormSingleFileUpload(request.formFile); + if (completeFilePath == "No file uploaded") + { + 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, + UpdateMessage = request.UpdateMessage, + }; + await _dbContext.InsertAsync(info); + } + else + { + entity.Url = completeFilePath; + entity.VersionCode = request.VersionCode; + entity.UpdateMessage = request.UpdateMessage; + await _dbContext.UpdateAsync(entity); + } + var newEntity = await _dbContext.Queryable().Where(x => x.Name == fileName).FirstAsync(); + var res = newEntity.Adapt(); + return res; + + } + public string FormSingleFileUpload(IFormFile formFile) + { + try + { + var filePath = "D:\\apk\\"; + + // 创建存储文件夹 + if (!Directory.Exists(filePath)) + { + Directory.CreateDirectory(filePath); + } + + if (formFile != null && formFile.Length > 0) + { + // 保存的文件名称 + var saveName = Path.GetFileName(formFile.FileName); + + // 文件保存 + using (var fs = File.Create(Path.Combine(filePath, saveName))) + { + formFile.CopyTo(fs); + fs.Flush(); + } + + // 完整的文件路径 + var completeFilePath = Path.Combine(filePath, saveName); + return completeFilePath; + } + else + { + return "No file uploaded"; + } + } + catch (Exception ex) + { + return $"Error uploading file: {ex.Message}"; + } + } + + + /// + /// 本地下载 + /// + /// + /// + public IActionResult FormLocalDownloadFile(string filePath) + { + string fileName = Path.GetFileName(filePath); + return new FileStreamResult(new FileStream(filePath, FileMode.Open), "application/octet-stream") { FileDownloadName = fileName }; + } }