From a27817f01817b22fff839a2d0b98cbb6e45a22f7 Mon Sep 17 00:00:00 2001 From: lixiaojun <1287241240@qq.com> Date: 星期五, 25 十月 2024 14:18:19 +0800 Subject: [PATCH] 增加云文件选择功能 --- BLL/HStation.BLL.TransferFile.Core/03-localclient/02-revit/TransferRevitFile.cs | 197 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 195 insertions(+), 2 deletions(-) diff --git a/BLL/HStation.BLL.TransferFile.Core/03-localclient/02-revit/TransferRevitFile.cs b/BLL/HStation.BLL.TransferFile.Core/03-localclient/02-revit/TransferRevitFile.cs index 91c424c..c756416 100644 --- a/BLL/HStation.BLL.TransferFile.Core/03-localclient/02-revit/TransferRevitFile.cs +++ b/BLL/HStation.BLL.TransferFile.Core/03-localclient/02-revit/TransferRevitFile.cs @@ -1,12 +1,205 @@ -锘縩amespace HStation.CAL.LocalClient +锘縰sing HStation.Dto.TransferFile; +using Microsoft.AspNetCore.Http; + +namespace HStation.CAL.LocalClient { /// <summary> - /// + /// /// </summary> public class TransferRevitFile : ITransferRevitFile { private readonly HStation.Service.TransferRevitFile _service = new(); + public TransferRevitFile(IHttpContextAccessor httpContextAccessor) + { + _httpContextAccessor = httpContextAccessor; + } + private readonly IHttpContextAccessor _httpContextAccessor; + + #region Query + + /// <summary> + /// 鑾峰彇鎵�鏈� + /// </summary> + public async Task<List<TransferRevitFileDto>> GetAll() + { + return await Task.Factory.StartNew(() => + { + var list = _service.GetAll(); + var vmList = list?.Select(x => new TransferRevitFileDto(x)).ToList(); + return vmList; + }); + } + + /// <summary> + /// 閫氳繃 ID 鑾峰彇 + /// </summary> + public async Task<TransferRevitFileDto> GetByID(long input) + { + return await Task.Factory.StartNew(() => + { + var model = _service.GetByID(input); + return model == null ? null : new TransferRevitFileDto(model); + }); + } + + /// <summary> + /// 閫氳繃 Ids 鑾峰彇 + /// </summary> + public async Task<List<TransferRevitFileDto>> GetByIds(List<long> ids) + { + return await Task.Factory.StartNew(() => + { + var list = _service.GetByIds(ids); + var vmList = list?.Select(x => new TransferRevitFileDto(x)).ToList(); + return vmList; + }); + } + + /// <summary> + /// 鑾峰彇妯$硦鍒楄〃 + /// </summary> + public async Task<List<TransferRevitFileDto>> GetFluzzyList + ( + string FileName, + string FileCode, + string FileSuffix, + string UploadUserName, + DateTime? StartTime, + DateTime? EndTime + ) + { + return await Task.Factory.StartNew(() => + { + var list = _service.GetFluzzyList(FileName, FileCode, FileSuffix, UploadUserName, StartTime, EndTime); + var vmList = list?.Select(x => new TransferRevitFileDto(x)).ToList(); + return vmList; + }); + } + + /// <summary> + /// 鑾峰彇妯$硦鍒嗛〉鍒楄〃 + /// </summary> + public async Task<PageListOutput<TransferRevitFileDto>> GetFluzzyPageList(QueryTransferRevitFileFluzzyPageListInput input) + { + return await Task.Factory.StartNew(() => + { + int total = 0; + var list = _service.GetFluzzyPageList(input.FileName, input.FileCode, input.FileSuffix, input.UploadUserName, input.StartTime, input.EndTime, input.PageIndex, input.PageSize, ref total); + var vmList = list?.Select(x => new TransferRevitFileDto(x)).ToList(); + return new PageListOutput<TransferRevitFileDto>() { Total = total, List = vmList }; + }); + } + + #endregion Query + + #region Insert + + /// <summary> + /// 鎻掑叆涓�鏉� (鍚屾椂涓婁紶鏂囦欢) + /// </summary> + public async Task<long> Insert(AddTransferRevitFileInput input) + { + return await Task.Factory.StartNew(() => + { + var request = _httpContextAccessor.HttpContext.Request; + if (request.Form.Files == null || request.Form.Files.Count != 1) + { + throw YOops.Oh(eResultCode.Alert, InternalErrorCodes.V001, "鏂囦欢楠岃瘉閿欒"); + } + var fileCode = input.FileCode; + if (string.IsNullOrEmpty(fileCode)) + { + fileCode = Yw.YitIdHelper.NextId().ToString(); + } + if (_service.IsExistFileCode(fileCode)) + { + throw YOops.Oh(eResultCode.Alert, InternalErrorCodes.V001, "鏂囦欢缂栫爜宸插瓨鍦�"); + } + var user = new HStation.Service.TransferFileUser().GetByName(input.UploadUserName); + if (user == null) + { + throw YOops.Oh(eResultCode.Alert, InternalErrorCodes.V001, "鐢ㄦ埛鍚嶇О涓嶅瓨鍦�"); + } + + var uploadFile = request.Form.Files[0]; + var model = new Model.TransferRevitFile(); + model.FileName = uploadFile.FileName; + model.FileCode = fileCode; + model.FileSuffix = Path.GetExtension(uploadFile.FileName); + model.StorageHouse = ConfigHelper.DataFolder; + model.StorageCode = Yw.Service.FileHelper.UploadSubFile(ConfigHelper.DataFolder, uploadFile.OpenReadStream(), Path.GetExtension(uploadFile.FileName)); + var filePath = Yw.Service.FileHelper.GetFilePath(model.StorageHouse, model.StorageCode); + var fileInfo = new FileInfo(filePath); + model.FileSize = fileInfo.Length; + model.UploadTime = DateTime.Now; + model.UploadUserID = user.ID; + model.UploadUserName = input.UploadUserName; + model.Description = input.Description; + var id = _service.Insert(model); + if (id < 1) + { + Yw.Service.FileHelper.Delete(model.StorageHouse, model.StorageCode); + } + return id; + }); + } + + #endregion Insert + + #region Exist + + /// <summary> + /// 鍒ゆ柇 FileCode 鏄惁瀛樺湪 + /// </summary> + public async Task<bool> IsExistFileCode(string FileCode) + { + return await Task.Factory.StartNew(() => + { + var bol = _service.IsExistFileCode(FileCode); + return bol; + }); + } + + /// <summary> + /// 鍒ゆ柇 FileCode 鏄惁瀛樺湪 ExceptID + /// </summary> + public async Task<bool> IsExistFileCodeExceptID(FileCodeExceptIDInput input) + { + return await Task.Factory.StartNew(() => + { + var bol = _service.IsExistFileCodeExceptID(input.FileCode, input.ExceptID); + return bol; + }); + } + + #endregion Exist + + #region Delete + + /// <summary> + /// 閫氳繃 ID 鍒犻櫎 + /// </summary> + public async Task<bool> DeleteByID(long input) + { + return await Task.Factory.StartNew(() => + { + var model = _service.GetByID(input); + if (model == null) + { + throw YOops.Oh(eResultCode.Alert, InternalErrorCodes.D001, "鏁版嵁涓嶅瓨鍦�"); + } + var bol = _service.DeleteByID(input, out string msg); + if (bol) + { + Yw.Service.FileHelper.Delete(model.StorageHouse, model.StorageCode); + return bol; + } + throw YOops.Oh(eResultCode.Alert, InternalErrorCodes.D999, msg); + }); + } + + #endregion Delete } } \ No newline at end of file -- Gitblit v1.9.3