From afa723170f1547f7fdb8528f5ae12cf941d3e375 Mon Sep 17 00:00:00 2001 From: lixiaojun <1287241240@qq.com> Date: 星期四, 04 八月 2022 17:43:09 +0800 Subject: [PATCH] 新增Epanet模块,文件管理相关问题修复 --- Service/IStation.Service4Epanet/helpers/ConfigHelper.cs | 41 Service/IStation.Service4Epanet/epanet_file/EpanetFile.cs | 314 ++++++ Application/IStation.Application4Core/helper/FileHelper.cs | 12 Application/IStation.Application4Epanet/epanet_file/_/dto/SetEpanetFileWorkingInput.cs | 34 DAL/IStation.DAL4Epanet/helpers/ConfigHelper.cs | 68 + Settings/IStation.Settings/paras_settings.json | 6 Application/IStation.Application4Epanet/epanet_file/_/dto/AddEpanetFileInput.cs | 46 Application/IStation.Application4Core/helper/ConfigHelper.cs | 2 Application/IStation.Application4Epanet/helper/Constant.cs | 18 DAL/IStation.DAL4Epanet/EpanetFile.cs | 91 + Service/IStation.Service4Epanet/epanet_file/EpanetFile_Instance.cs | 63 + DAL/IStation.DAL4Epanet/IStation.DAL4Epanet.csproj | 17 Settings/IStation.Settings/models/Paras.cs | 5 Entity/IStation.Entity4Epanet/EpanetFile.cs | 79 + Settings/IStation.Settings/models/epanet/Paras_Epanet_DataBase.cs | 20 Model/IStation.Model4Epanet/EpanetFile.cs | 134 ++ Application/IStation.Application4Epanet/config/Mapper.cs | 43 Service/IStation.Service4Epanet/helpers/CacheHelper.cs | 40 Model/IStation.Model/enum/eFileFormat.cs | 0 Application/IStation.Application4Epanet/IStation.Application4Epanet.csproj | 17 Core/IStation.WebApi.Core/applicationconfig.json | 7 Entity/IStation.Entity4Epanet/IStation.Entity4Epanet.csproj | 16 Settings/IStation.Settings/models/epanet/Paras_Epanet.cs | 19 Application/IStation.Application4Epanet/epanet_file/_/dto/EpanetFileDto.cs | 105 ++ Application/IStation.Application4Epanet/epanet_file/logic/EpanetFile_LogicController.cs | 609 ++++++++++++ Application/IStation.Application4Epanet/epanet_file/_/EpanetFile_Controller.cs | 360 +++++++ IStation.WebApi.sln | 35 Service/IStation.Service4Epanet/epanet_file/cache/EpanetFileCacheHelper.cs | 71 + Application/IStation.Application4Epanet/epanet_file/_/dto/AddEpanetFileTogetherInput.cs | 44 Application/IStation.Application4File/file/File_Controller.cs | 44 /dev/null | 440 -------- Settings/IStation.Settings/paras/Settings.cs | 8 Model/IStation.Model4Epanet/IStation.Model4Epanet.csproj | 16 Service/IStation.Service4Epanet/IStation.Service4Epanet.csproj | 18 Application/IStation.Application4Epanet/epanet_file/logic/dto/EpanetFileLogicDto.cs | 105 ++ Entry/IStation.WebApi.Entry/IStation.WebApi.Entry.csproj | 1 Application/IStation.Application4Epanet/epanet_file/_/dto/UpdateEpanetFileInput.cs | 36 37 files changed, 2,530 insertions(+), 454 deletions(-) diff --git a/Application/IStation.Application4Repair/helper/ConfigHelper.cs b/Application/IStation.Application4Core/helper/ConfigHelper.cs similarity index 96% rename from Application/IStation.Application4Repair/helper/ConfigHelper.cs rename to Application/IStation.Application4Core/helper/ConfigHelper.cs index 0c027fa..c6b0ef0 100644 --- a/Application/IStation.Application4Repair/helper/ConfigHelper.cs +++ b/Application/IStation.Application4Core/helper/ConfigHelper.cs @@ -8,7 +8,7 @@ /// <summary> /// /// </summary> - internal class ConfigHelper + public class ConfigHelper { /// <summary> /// 鏁版嵁鏂囦欢澶硅矾寰� diff --git a/Application/IStation.Application4Repair/helper/FileHelper.cs b/Application/IStation.Application4Core/helper/FileHelper.cs similarity index 98% rename from Application/IStation.Application4Repair/helper/FileHelper.cs rename to Application/IStation.Application4Core/helper/FileHelper.cs index 99f86d7..075b31f 100644 --- a/Application/IStation.Application4Repair/helper/FileHelper.cs +++ b/Application/IStation.Application4Core/helper/FileHelper.cs @@ -467,12 +467,12 @@ } return Model.eFileFormat.UnKnown; } - private static List<string> _imgSuffixList = new List<string>() { ".png",".jpg",".jpeg"}; - private static List<string> _excelSuffixList = new List<string>() { ".xls",".xlsx"}; - private static List<string> _wordSuffixList = new List<string>() { ".doc",".docx"}; - private static List<string> _pdfSuffixList = new List<string>() { ".pdf"}; - private static List<string> _audioSuffixList = new List<string>() { ".wav",".mp3", ".mppr", ".wma", ".asf" }; - private static List<string> _videoSuffixList = new List<string>() { ".avi" , ".mv", ".wmv", ".mp4" ,".rm"}; + private static List<string> _imgSuffixList = new List<string>() { ".png", ".jpg", ".jpeg" }; + private static List<string> _excelSuffixList = new List<string>() { ".xls", ".xlsx" }; + private static List<string> _wordSuffixList = new List<string>() { ".doc", ".docx" }; + private static List<string> _pdfSuffixList = new List<string>() { ".pdf" }; + private static List<string> _audioSuffixList = new List<string>() { ".wav", ".mp3", ".mppr", ".wma", ".asf" }; + private static List<string> _videoSuffixList = new List<string>() { ".avi", ".mv", ".wmv", ".mp4", ".rm" }; #endregion diff --git a/Application/IStation.Application4Epanet/IStation.Application4Epanet.csproj b/Application/IStation.Application4Epanet/IStation.Application4Epanet.csproj new file mode 100644 index 0000000..a93264a --- /dev/null +++ b/Application/IStation.Application4Epanet/IStation.Application4Epanet.csproj @@ -0,0 +1,17 @@ +<Project Sdk="Microsoft.NET.Sdk"> + + <PropertyGroup> + <TargetFramework>net6.0</TargetFramework> + <ImplicitUsings>enable</ImplicitUsings> + <Nullable>disable</Nullable> + <AssemblyName>IStation.Application4Epanet</AssemblyName> + <RootNamespace>IStation.Application</RootNamespace> + <GenerateDocumentationFile>True</GenerateDocumentationFile> + </PropertyGroup> + + <ItemGroup> + <ProjectReference Include="..\..\Service\IStation.Service4Epanet\IStation.Service4Epanet.csproj" /> + <ProjectReference Include="..\IStation.Application4Core\IStation.Application4Core.csproj" /> + </ItemGroup> + +</Project> diff --git a/Application/IStation.Application4Epanet/config/Mapper.cs b/Application/IStation.Application4Epanet/config/Mapper.cs new file mode 100644 index 0000000..d66ba23 --- /dev/null +++ b/Application/IStation.Application4Epanet/config/Mapper.cs @@ -0,0 +1,43 @@ +锘縰sing Mapster; +using System; + +namespace IStation.Application +{ + /// <summary> + /// + /// </summary> + public class Mapper : IRegister + { + /// <summary> + /// + /// </summary> + /// <param name="config"></param> + public void Register(TypeAdapterConfig config) + { + + #region EpanetFile + + config.ForType<AddEpanetFileInput, Model.EpanetFile>() + .Map(dest=>dest.StorageHouse,src=>Constant.EpanetStorageHouse) + .Map(dest => dest.IsWorking, src =>false) + .Map(dest => dest.CreateTime, src => DateTime.Now) + .Map(dest => dest.CreateUserID, src => UserManager.UserID); + + config.ForType<AddEpanetFileTogetherInput, Model.EpanetFile>() + .Map(dest => dest.StorageHouse, src => Constant.EpanetStorageHouse) + .Map(dest => dest.IsWorking, src => false) + .Map(dest => dest.CreateTime, src => DateTime.Now) + .Map(dest => dest.CreateUserID, src => UserManager.UserID); + + config.ForType<UpdateEpanetFileInput, Model.EpanetFile>() + .Map(dest => dest.UpdateTime, src => DateTime.Now) + .Map(dest => dest.UpdateUserID, src => UserManager.UserID); + + + + + #endregion + + } + } +} \ No newline at end of file diff --git a/Application/IStation.Application4Epanet/epanet_file/_/EpanetFile_Controller.cs b/Application/IStation.Application4Epanet/epanet_file/_/EpanetFile_Controller.cs new file mode 100644 index 0000000..d998bd3 --- /dev/null +++ b/Application/IStation.Application4Epanet/epanet_file/_/EpanetFile_Controller.cs @@ -0,0 +1,360 @@ +锘縰sing Microsoft.AspNetCore.Mvc; +using System.Net; +using System.Net.Http.Headers; +using Microsoft.Extensions.Hosting.Internal; +using Microsoft.AspNetCore.Http.Extensions; +using IStation.Untity; +using Furion.DynamicApiController; +using System.ComponentModel.DataAnnotations; +using Mapster; +using Microsoft.AspNetCore.Http; + +namespace IStation.Application +{ + /// <summary> + /// EpanetFile + /// </summary> + [Route("Epanet/EpanetFile")] + [ApiDescriptionSettings("Epanet", Name = "Epanet鏂囦欢", Order = 1000)] + public class EpanetFile_Controller : IDynamicApiController + { + + private readonly IHttpContextAccessor _httpContextAccessor; + + /// <summary> + /// + /// </summary> + public EpanetFile_Controller(IHttpContextAccessor httpContextAccessor) + { + _httpContextAccessor = httpContextAccessor; + } + + private readonly Service.EpanetFile _service = new Service.EpanetFile(); + + #region Query + + /// <summary> + /// 閫氳繃 CorpID 鑾峰彇 + /// </summary> + [Route("GetByCorpID@V1.0")] + [HttpGet] + public List<EpanetFileDto> GetByCorpID([FromQuery][Required] CorpIDInput input) + { + var list = _service.GetByCorpID(input.CorpID); + var vmList = list?.Select(x => new EpanetFileDto(x)).ToList(); + return vmList; + } + + /// <summary> + /// 閫氳繃 ID 鑾峰彇 + /// </summary> + [Route("GetByID@V1.0")] + [HttpGet] + public EpanetFileDto GetByID([FromQuery][Required] IDUnderCorpInput input) + { + var model = _service.GetByID(input.CorpID, input.ID); + if (model == null) + return default; + var vm = new EpanetFileDto(model); + return vm; + } + + /// <summary> + /// 閫氳繃 Ids 鑾峰彇 + /// </summary> + [Route("GetByIds@V1.0")] + [HttpGet] + public List<EpanetFileDto> GetByIds([FromQuery] IdsUnderCorpInput input) + { + var ids = LongListHelper.ToList(input.Ids); + var list = _service.GetByIds(input.CorpID, ids); + var vmList = list?.Select(x => new EpanetFileDto(x)).ToList(); + return vmList; + } + + /// <summary> + /// 閫氳繃 BelongType 鍜� BelongID 鑾峰彇 + /// </summary> + [Route("GetByBelongTypeAndBelongID@V1.0")] + [HttpGet] + public List<EpanetFileDto> GetByBelongTypeAndBelongID([FromQuery][Required] BelongUnderCorpInput input) + { + var list = _service.GetByBelongTypeAndBelongID(input.CorpID, input.BelongType, input.BelongID); + var vmList = list?.Select(x => new EpanetFileDto(x)).ToList(); + return vmList; + } + + /// <summary> + /// 閫氳繃 BelongType 鍜� BelongID 鑾峰彇宸ヤ綔鏂囦欢 + /// </summary> + [Route("GetWorkingByBelongTypeAndBelongID@V1.0")] + [HttpGet] + public EpanetFileDto GetWorkingByBelongTypeAndBelongID([FromQuery][Required] BelongUnderCorpInput input) + { + var model = _service.GetWorkingByBelongTypeAndBelongID(input.CorpID,input.BelongType,input.BelongID); + if (model == null) + return default; + var vm = new EpanetFileDto(model); + return vm; + } + + /// <summary> + /// 閫氳繃 BelongType 鍜� BelongID 鑾峰彇榛樿宸ヤ綔鏂囦欢 + /// </summary> + [Route("GetDefaultWorkingByBelongTypeAndBelongID@V1.0")] + [HttpGet] + public EpanetFileDto GetDefaultWorkingByBelongTypeAndBelongID([FromQuery][Required] BelongUnderCorpInput input) + { + var model = _service.GetWorkingByBelongTypeAndBelongID(input.CorpID, input.BelongType, input.BelongID); + if (model == null) + return default; + var vm = new EpanetFileDto(model); + return vm; + } + + /// <summary> + /// 鑾峰彇鏂囦欢Url锛堝叏璺緞 閲囩敤ip+port璁块棶姝e父锛岀敤鍩熷悕璁块棶浼氭湁闂锛� + /// </summary> + [Route("GetFileUrl@V1.0")] + [HttpGet] + public string GetFileUrl([FromQuery] IDUnderCorpInput input) + { + var model = _service.GetByID(input.CorpID,input.ID); + if (model == null) + { + throw new Exception("鏈绱㈠埌鍩虹淇℃伅"); + } + var url = $"http://{_httpContextAccessor.HttpContext.Request.Host}/{FileHelper.GetRelatedFilePath(model.StorageHouse,model.StorageCode)}"; + return url; + } + + /// <summary> + /// 鑾峰彇鏂囦欢鐩稿Url锛堝幓鎺夊墠缂�锛� + /// </summary> + [Route("GetFileRelatedUrl@V1.0")] + [HttpGet] + public string GetFileRelatedUrl([FromQuery] IDUnderCorpInput input) + { + var model = _service.GetByID(input.CorpID, input.ID); + if (model == null) + { + throw new Exception("鏈绱㈠埌鍩虹淇℃伅"); + } + var url = FileHelper.GetRelatedFilePath(model.StorageHouse, model.StorageCode); + return url; + } + + /// <summary> + /// 涓嬭浇鏂囦欢锛堣繑鍥炴祦锛� + /// </summary> + [Route("DownloadFile@V1.0")] + [HttpGet] + [NonUnify] + public HttpResponseMessage DownloadFile([FromQuery] IDUnderCorpInput input) + { + var model=_service.GetByID(input.CorpID,input.ID); + if (model == null) + { + return new HttpResponseMessage(HttpStatusCode.NoContent); + } + if (string.IsNullOrEmpty(model.StorageCode)) + { + return new HttpResponseMessage(HttpStatusCode.NoContent); + } + + var file = FileHelper.DownloadSubFile(model.StorageHouse, model.StorageCode); + if (file == null) + { + return new HttpResponseMessage(HttpStatusCode.NoContent); + } + + var result = new HttpResponseMessage(HttpStatusCode.OK); + result.Content = new StreamContent(file); + result.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream"); + return result; + } + + #endregion + + #region Insert + + /// <summary> + /// 涓婁紶鏂囦欢杩斿洖瀛樺偍缂栫爜锛堜粎鏀寔涓婁紶涓�涓枃浠讹級 + /// </summary> + [Route("UploadFile@V1.0")] + [HttpPost] + public string UploadFile() + { + var request = _httpContextAccessor.HttpContext.Request; + if (request.Form.Files == null || request.Form.Files.Count != 1) + { + return string.Empty; + } + var uploadFile = request.Form.Files[0]; + + var fileName = FileHelper.UploadSubFile(Constant.EpanetStorageHouse, uploadFile.OpenReadStream(), Path.GetExtension(uploadFile.FileName)); + return fileName; + } + + /// <summary> + /// 鎻掑叆涓�鏉� (鏂囦欢宸插崟鐙笂浼狅紝鎻愪氦鐨勬暟鎹腑鍖呭惈鏂囦欢瀛樺偍缂栫爜) + /// </summary> + [Route("Insert@V1.0")] + [HttpPost] + public long Insert_V1_0(AddEpanetFileInput input) + { + if (input == null) + return default; + var model = input.Adapt<AddEpanetFileInput, Model.EpanetFile>(); + var id = _service.Insert(model); + return id; + } + + /// <summary> + /// 鎻掑叆涓�鏉� (鏂囦欢涓庡熀纭�鏁版嵁涓�璧锋彁浜�) + /// </summary> + [Route("Insert@V1.1")] + [HttpPost] + public long Insert_V1_1([FromForm] AddEpanetFileTogetherInput input) + { + if (input == null) + return default; + var request = _httpContextAccessor.HttpContext.Request; + if (request.Form.Files == null || request.Form.Files.Count < 1) + return default; + var uploadFile = request.Form.Files[0]; + var storageCode = FileHelper.UploadSubFile(Constant.EpanetStorageHouse, uploadFile.OpenReadStream(), Path.GetExtension(uploadFile.FileName)); + var model = input.Adapt<AddEpanetFileTogetherInput, Model.EpanetFile>(); + model.StorageCode = storageCode; + var id = _service.Insert(model); + return id; + } + + #endregion + + #region Update + + /// <summary> + /// 鏇存柊涓�鏉� + /// </summary> + [Route("Update@V1.0")] + [HttpPut] + public bool Update([Required] UpdateEpanetFileInput input) + { + if (input == null) + return false; + var model = _service.GetByID(input.CorpID, input.ID); + if (model == null) + return false; + var rhs = new Model.EpanetFile(model); + input.Adapt(rhs); + var bol = _service.Update(rhs); + return bol; + } + + /// <summary> + /// 鏇存柊澶氭潯 + /// </summary> + [Route("Updates@V1.0")] + [HttpPut] + public bool Updates([Required] List<UpdateEpanetFileInput> inputList) + { + if (inputList == null || inputList.Count() < 1) + { + return false; + } + var corpIds = inputList.Select(x => x.CorpID).Distinct().ToList(); + if (corpIds.Count > 1) + return false; + var modelList = _service.GetByIds(corpIds[0], inputList.Select(x => x.ID).ToList()); + if (modelList == null || modelList.Count < 1) + return false; + var rhsList = new List<Model.EpanetFile>(); + modelList.ForEach(x => + { + var input = inputList.Find(t => t.ID == x.ID); + if (input != null) + { + var rhs = new Model.EpanetFile(x); + input.Adapt(rhs); + rhsList.Add(rhs); + } + }); + if (rhsList.Count < 1) + return false; + var bol = _service.Updates(rhsList); + return bol; + } + + /// <summary> + /// 鏇存柊鏂囦欢锛堢敤鏂扮殑鏂囦欢鏇存柊鏃ф枃浠讹紝骞舵洿鏂板熀纭�淇℃伅锛� + /// </summary> + [Route("UpdateFile@V1.0")] + [HttpPut] + public bool UpdateFile([FromForm] IDUnderCorpInput input) + { + var request = _httpContextAccessor.HttpContext.Request; + if (request.Form.Files == null || request.Form.Files.Count <1) + { + return default; + } + var model = _service.GetByID(input.CorpID,input.ID); + if (model == null) + { + throw new Exception("鏈绱㈠埌鍩虹鏁版嵁"); + } + var uploadFile = request.Form.Files[0]; + + var code = FileHelper.UpdateSubFile(Constant.EpanetStorageHouse, model.StorageCode, uploadFile.OpenReadStream(), Path.GetExtension(uploadFile.FileName)); + var bol = _service.UpdateStorageCode(input.CorpID,input.ID,code,UserManager.UserID,DateTime.Now); + return bol; + } + + #endregion + + #region Set + + /// <summary> + /// 璁剧疆宸ヤ綔鏂囦欢 + /// </summary> + [Route("SetWorking@V1.0")] + [HttpPost] + public bool SetWorking([Required] SetEpanetFileWorkingInput input) + { + if (input == null) + return default; + var bol = _service.SetWorking(input.CorpID, input.BelongType,input.BelongID, input.ID,UserManager.UserID,DateTime.Now); + return bol; + } + + + #endregion + + #region Delete + + /// <summary> + /// 鍒犻櫎 + /// </summary> + [Route("DeleteByID@V1.0")] + [HttpDelete] + public DeleteReasonOutput DeleteByID([FromQuery][Required] IDUnderCorpInput input) + { + var bol = _service.DeleteByID(input.CorpID, input.ID, out string Msg); + return new DeleteReasonOutput() { Success = bol, Reason = Msg }; + } + + + #endregion + + + + + + + + + + + + } +} diff --git a/Application/IStation.Application4Epanet/epanet_file/_/dto/AddEpanetFileInput.cs b/Application/IStation.Application4Epanet/epanet_file/_/dto/AddEpanetFileInput.cs new file mode 100644 index 0000000..35c2f89 --- /dev/null +++ b/Application/IStation.Application4Epanet/epanet_file/_/dto/AddEpanetFileInput.cs @@ -0,0 +1,46 @@ +锘縰sing System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace IStation.Application +{ + /// <summary> + /// + /// </summary> + public class AddEpanetFileInput + { + + /// <summary> + /// 瀹㈡埛鏍囪瘑 + /// </summary> + public long CorpID { get; set; } + + /// <summary> + /// 鎵�灞炵被鍨� + /// </summary> + public string BelongType { get; set; } + + /// <summary> + /// 鎵�灞瀒d + /// </summary> + public long BelongID { get; set; } + + /// <summary> + /// 鍚嶇О + /// </summary> + public string Name { get; set; } + + /// <summary> + /// 瀛樺偍缂栫爜 + /// </summary> + public string StorageCode { get; set; } + + /// <summary> + /// 璇存槑 + /// </summary> + public string Description { get; set; } + + } +} diff --git a/Application/IStation.Application4Epanet/epanet_file/_/dto/AddEpanetFileTogetherInput.cs b/Application/IStation.Application4Epanet/epanet_file/_/dto/AddEpanetFileTogetherInput.cs new file mode 100644 index 0000000..639c28d --- /dev/null +++ b/Application/IStation.Application4Epanet/epanet_file/_/dto/AddEpanetFileTogetherInput.cs @@ -0,0 +1,44 @@ +锘縰sing System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace IStation.Application +{ + /// <summary> + /// 娣诲姞鐨勫悓鏃朵笂浼犳枃浠� + /// </summary> + public class AddEpanetFileTogetherInput + { + /// <summary> + /// 瀹㈡埛鏍囪瘑 + /// </summary> + public long CorpID { get; set; } + + /// <summary> + /// 鎵�灞炵被鍨� + /// </summary> + public string BelongType { get; set; } + + /// <summary> + /// 鎵�灞瀒d + /// </summary> + public long BelongID { get; set; } + + /// <summary> + /// 鍚嶇О + /// </summary> + public string Name { get; set; } + + /// <summary> + /// 瀛樺偍缂栫爜 + /// </summary> + public string StorageCode { get; set; } + + /// <summary> + /// 璇存槑 + /// </summary> + public string Description { get; set; } + } +} diff --git a/Application/IStation.Application4Epanet/epanet_file/_/dto/EpanetFileDto.cs b/Application/IStation.Application4Epanet/epanet_file/_/dto/EpanetFileDto.cs new file mode 100644 index 0000000..dd21a92 --- /dev/null +++ b/Application/IStation.Application4Epanet/epanet_file/_/dto/EpanetFileDto.cs @@ -0,0 +1,105 @@ +锘縰sing System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace IStation.Application +{ + /// <summary> + /// + /// </summary> + public class EpanetFileDto + { + /// <summary> + /// + /// </summary> + public EpanetFileDto() { } + + /// <summary> + /// + /// </summary> + public EpanetFileDto(Model.EpanetFile rhs) + { + this.ID = rhs.ID; + this.CorpID = rhs.CorpID; + this.BelongType = rhs.BelongType; + this.BelongID = rhs.BelongID; + this.Name = rhs.Name; + this.StorageHouse = rhs.StorageHouse; + this.StorageCode = rhs.StorageCode; + this.IsWorking = rhs.IsWorking; + this.Description = rhs.Description; + this.CreateTime = rhs.CreateTime; + this.CreateUserID = rhs.CreateUserID; + this.UpdateTime = rhs.UpdateTime; + this.UpdateUserID = rhs.UpdateUserID; + } + + /// <summary> + /// 鏍囪瘑 + /// </summary> + public long ID { get; set; } + + /// <summary> + /// 瀹㈡埛鏍囪瘑 + /// </summary> + public long CorpID { get; set; } + + /// <summary> + /// 鎵�灞炵被鍨� + /// </summary> + public string BelongType { get; set; } + + /// <summary> + /// 鎵�灞瀒d + /// </summary> + public long BelongID { get; set; } + + /// <summary> + /// 鍚嶇О + /// </summary> + public string Name { get; set; } + + /// <summary> + /// 瀛樺偍浠撳簱 + /// </summary> + public string StorageHouse { get; set; } + + /// <summary> + /// 瀛樺偍缂栫爜 + /// </summary> + public string StorageCode { get; set; } + + /// <summary> + /// 宸ヤ綔鏂囦欢 + /// </summary> + public bool IsWorking { get; set; } + + /// <summary> + /// 璇存槑 + /// </summary> + public string Description { get; set; } + + /// <summary> + /// 鍒涘缓鐢ㄦ埛鏍囪瘑 + /// </summary> + public long CreateUserID { get; set; } + + /// <summary> + /// 鍒涘缓鏃堕棿 + /// </summary> + public DateTime CreateTime { get; set; } + + /// <summary> + /// 鏇存柊鐢ㄦ埛鏍囪瘑 + /// </summary> + public long? UpdateUserID { get; set; } + + /// <summary> + /// 鏇存柊鏃堕棿 + /// </summary> + public DateTime? UpdateTime { get; set; } + + } +} diff --git a/Application/IStation.Application4Epanet/epanet_file/_/dto/SetEpanetFileWorkingInput.cs b/Application/IStation.Application4Epanet/epanet_file/_/dto/SetEpanetFileWorkingInput.cs new file mode 100644 index 0000000..d84a7d6 --- /dev/null +++ b/Application/IStation.Application4Epanet/epanet_file/_/dto/SetEpanetFileWorkingInput.cs @@ -0,0 +1,34 @@ +锘縰sing System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace IStation.Application +{ + /// <summary> + /// + /// </summary> + public class SetEpanetFileWorkingInput + { + /// <summary> + /// 瀹㈡埛鏍囪瘑 + /// </summary> + public long CorpID { get; set; } + + /// <summary> + /// 鎵�灞炵被鍨� + /// </summary> + public string BelongType { get; set; } + + /// <summary> + /// 鎵�灞炴爣璇� + /// </summary> + public long BelongID { get; set; } + + /// <summary> + /// id + /// </summary> + public long ID { get; set; } + } +} diff --git a/Application/IStation.Application4Epanet/epanet_file/_/dto/UpdateEpanetFileInput.cs b/Application/IStation.Application4Epanet/epanet_file/_/dto/UpdateEpanetFileInput.cs new file mode 100644 index 0000000..19246dd --- /dev/null +++ b/Application/IStation.Application4Epanet/epanet_file/_/dto/UpdateEpanetFileInput.cs @@ -0,0 +1,36 @@ +锘縰sing System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace IStation.Application +{ + /// <summary> + /// 鏇存柊 + /// </summary> + public class UpdateEpanetFileInput + { + /// <summary> + /// 鏍囪瘑 + /// </summary> + public long ID { get; set; } + + /// <summary> + /// 瀹㈡埛鏍囪瘑 + /// </summary> + public long CorpID { get; set; } + + /// <summary> + /// 鍚嶇О + /// </summary> + public string Name { get; set; } + + /// <summary> + /// 璇存槑 + /// </summary> + public string Description { get; set; } + + + } +} diff --git a/Application/IStation.Application4Epanet/epanet_file/logic/EpanetFile_LogicController.cs b/Application/IStation.Application4Epanet/epanet_file/logic/EpanetFile_LogicController.cs new file mode 100644 index 0000000..1bbf953 --- /dev/null +++ b/Application/IStation.Application4Epanet/epanet_file/logic/EpanetFile_LogicController.cs @@ -0,0 +1,609 @@ +锘縰sing Microsoft.AspNetCore.Mvc; +using System.Net; +using System.Net.Http.Headers; +using Microsoft.Extensions.Hosting.Internal; +using Microsoft.AspNetCore.Http.Extensions; +using IStation.Untity; +using Furion.DynamicApiController; +using System.ComponentModel.DataAnnotations; +using Mapster; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Authorization; + +namespace IStation.Application +{ + /// <summary> + /// EpanetFile + /// </summary> + [Route("Epanet/EpanetFile/Logic")] + [ApiDescriptionSettings("Epanet", Name = "Epanet鏂囦欢(涓氬姟)", Order = 900)] + public class EpanetFile_LogicController : IDynamicApiController + { + + private readonly IHttpContextAccessor _httpContextAccessor; + + /// <summary> + /// + /// </summary> + public EpanetFile_LogicController(IHttpContextAccessor httpContextAccessor) + { + _httpContextAccessor = httpContextAccessor; + } + + #region 閫氳繃 BelongType 鍜� BelongID 鑾峰彇 + + /// <summary> + /// 閫氳繃 BelongType 鍜� BelongID 鑾峰彇 + /// </summary> + [Route("GetByBelongTypeAndBelongID@V1.0")] + [HttpGet] + public List<EpanetFileLogicDto> GetByBelongTypeAndBelongID_V1_0([FromQuery][Required] BelongUnderCorpInput input) + { + var list = new Service.EpanetFile().GetByBelongTypeAndBelongID(input.CorpID, input.BelongType, input.BelongID); + var vmList = list?.Select(x => new EpanetFileLogicDto(x)).ToList(); + return vmList; + } + + /// <summary> + /// 閫氳繃 BelongType 鍜� BelongID 鑾峰彇(涓嶉渶瑕侀獙璇乀oken) + /// </summary> + [AllowAnonymous] + [Route("GetByBelongTypeAndBelongID@V1.1")] + [HttpGet] + public List<EpanetFileLogicDto> GetByBelongTypeAndBelongID_V1_1([FromQuery][Required] BelongUnderCorpInput input) + { + var list = new Service.EpanetFile().GetByBelongTypeAndBelongID(input.CorpID, input.BelongType, input.BelongID); + var vmList = list?.Select(x => new EpanetFileLogicDto(x)).ToList(); + return vmList; + } + + #endregion + + #region 閫氳繃 ID 鑾峰彇 + + /// <summary> + /// 閫氳繃 ID 鑾峰彇 + /// </summary> + [Route("GetByID@V1.0")] + [HttpGet] + public EpanetFileLogicDto GetByID_V1_0([FromQuery][Required] IDUnderCorpInput input) + { + var model = new Service.EpanetFile().GetByID(input.CorpID, input.ID); + if (model == null) + return default; + var vm = new EpanetFileLogicDto(model); + return vm; + } + + /// <summary> + /// 閫氳繃 ID 鑾峰彇(涓嶉渶瑕侀獙璇乀oken) + /// </summary> + [AllowAnonymous] + [Route("GetByID@V1.1")] + [HttpGet] + public EpanetFileLogicDto GetByID_V1_1([FromQuery][Required] IDUnderCorpInput input) + { + var model = new Service.EpanetFile().GetByID(input.CorpID, input.ID); + if (model == null) + return default; + var vm = new EpanetFileLogicDto(model); + return vm; + } + + #endregion + + #region 閫氳繃 Ids 鑾峰彇 + + /// <summary> + /// 閫氳繃 Ids 鑾峰彇 + /// </summary> + [Route("GetByIds@V1.0")] + [HttpGet] + public List<EpanetFileLogicDto> GetByIds_V1_0([FromQuery] IdsUnderCorpInput input) + { + var ids = LongListHelper.ToList(input.Ids); + var list = new Service.EpanetFile().GetByIds(input.CorpID, ids); + var vmList = list?.Select(x => new EpanetFileLogicDto(x)).ToList(); + return vmList; + } + + /// <summary> + /// 閫氳繃 Ids 鑾峰彇(涓嶉渶瑕侀獙璇乀oken) + /// </summary> + [AllowAnonymous] + [Route("GetByIds@V1.1")] + [HttpGet] + public List<EpanetFileLogicDto> GetByIds_V1_1([FromQuery] IdsUnderCorpInput input) + { + var ids = LongListHelper.ToList(input.Ids); + var list = new Service.EpanetFile().GetByIds(input.CorpID, ids); + var vmList = list?.Select(x => new EpanetFileLogicDto(x)).ToList(); + return vmList; + } + + #endregion + + #region 閫氳繃 BelongType 鍜� BelongID 鑾峰彇宸ヤ綔鏂囦欢 + + /// <summary> + /// 閫氳繃 BelongType 鍜� BelongID 鑾峰彇宸ヤ綔鏂囦欢 + /// </summary> + [Route("GetWorkingByBelongTypeAndBelongID@V1.0")] + [HttpGet] + public EpanetFileLogicDto GetWorkingByBelongTypeAndBelongID_V1_0([FromQuery][Required] BelongUnderCorpInput input) + { + var model = new Service.EpanetFile().GetWorkingByBelongTypeAndBelongID(input.CorpID, input.BelongType, input.BelongID); + if (model == null) + return default; + var vm = new EpanetFileLogicDto(model); + return vm; + } + + /// <summary> + /// 閫氳繃 BelongType 鍜� BelongID 鑾峰彇宸ヤ綔鏂囦欢(涓嶉渶瑕侀獙璇乀oken) + /// </summary> + [AllowAnonymous] + [Route("GetWorkingByBelongTypeAndBelongID@V1.1")] + [HttpGet] + public EpanetFileLogicDto GetWorkingByBelongTypeAndBelongID_V1_1([FromQuery][Required] BelongUnderCorpInput input) + { + var model = new Service.EpanetFile().GetWorkingByBelongTypeAndBelongID(input.CorpID, input.BelongType, input.BelongID); + if (model == null) + return default; + var vm = new EpanetFileLogicDto(model); + return vm; + } + + #endregion + + #region 閫氳繃 BelongType 鍜� BelongID 鑾峰彇榛樿宸ヤ綔鏂囦欢 + + /// <summary> + /// 閫氳繃 BelongType 鍜� BelongID 鑾峰彇榛樿宸ヤ綔鏂囦欢 + /// </summary> + [Route("GetDefaultWorkingByBelongTypeAndBelongID@V1.0")] + [HttpGet] + public EpanetFileLogicDto GetDefaultWorkingByBelongTypeAndBelongID_V1_0([FromQuery][Required] BelongUnderCorpInput input) + { + var model = new Service.EpanetFile().GetWorkingByBelongTypeAndBelongID(input.CorpID, input.BelongType, input.BelongID); + if (model == null) + return default; + var vm = new EpanetFileLogicDto(model); + return vm; + } + + /// <summary> + /// 閫氳繃 BelongType 鍜� BelongID 鑾峰彇榛樿宸ヤ綔鏂囦欢(涓嶉渶瑕侀獙璇乀oken) + /// </summary> + [AllowAnonymous] + [Route("GetDefaultWorkingByBelongTypeAndBelongID@V1.1")] + [HttpGet] + public EpanetFileLogicDto GetDefaultWorkingByBelongTypeAndBelongID_V1_1([FromQuery][Required] BelongUnderCorpInput input) + { + var model = new Service.EpanetFile().GetWorkingByBelongTypeAndBelongID(input.CorpID, input.BelongType, input.BelongID); + if (model == null) + return default; + var vm = new EpanetFileLogicDto(model); + return vm; + } + + #endregion + + #region 閫氳繃 BelongType 鍜� BelongID 鑾峰彇宸ヤ綔鏂囦欢Url + + /// <summary> + /// 閫氳繃 BelongType 鍜� BelongID 鑾峰彇宸ヤ綔鏂囦欢Url(鍏ㄨ矾寰� 閲囩敤ip+port璁块棶姝e父锛岀敤鍩熷悕璁块棶浼氭湁闂锛� + /// </summary> + [Route("GetWorkingFileUrlByBelongTypeAndBelongID@V1.0")] + [HttpGet] + public string GetWorkingFileUrlByBelongTypeAndBelongID_V1_0([FromQuery][Required] BelongUnderCorpInput input) + { + var model = new Service.EpanetFile().GetWorkingByBelongTypeAndBelongID(input.CorpID, input.BelongType, input.BelongID); + if (model == null) + return default; + var url = $"http://{_httpContextAccessor.HttpContext.Request.Host}/{FileHelper.GetRelatedFilePath(model.StorageHouse, model.StorageCode)}"; + return url; + } + + /// <summary> + /// 閫氳繃 BelongType 鍜� BelongID 鑾峰彇宸ヤ綔鏂囦欢Url(鍏ㄨ矾寰� 閲囩敤ip+port璁块棶姝e父锛岀敤鍩熷悕璁块棶浼氭湁闂锛�(涓嶉渶瑕侀獙璇乀oken) + /// </summary> + [AllowAnonymous] + [Route("GetWorkingFileUrlByBelongTypeAndBelongID@V1.1")] + [HttpGet] + public string GetWorkingFileUrlByBelongTypeAndBelongID_V1_1([FromQuery][Required] BelongUnderCorpInput input) + { + var model = new Service.EpanetFile().GetWorkingByBelongTypeAndBelongID(input.CorpID, input.BelongType, input.BelongID); + if (model == null) + return default; + var url = $"http://{_httpContextAccessor.HttpContext.Request.Host}/{FileHelper.GetRelatedFilePath(model.StorageHouse, model.StorageCode)}"; + return url; + } + + #endregion + + #region 閫氳繃 BelongType 鍜� BelongID 鑾峰彇宸ヤ綔鏂囦欢鐩稿Url + + /// <summary> + /// 閫氳繃 BelongType 鍜� BelongID 鑾峰彇宸ヤ綔鏂囦欢鐩稿Url(鍘绘帀鍓嶇紑锛� + /// </summary> + [Route("GetWorkingFileRelatedUrlByBelongTypeAndBelongID@V1.0")] + [HttpGet] + public string GetWorkingFileRelatedUrlByBelongTypeAndBelongID_V1_0([FromQuery][Required] BelongUnderCorpInput input) + { + var model = new Service.EpanetFile().GetWorkingByBelongTypeAndBelongID(input.CorpID, input.BelongType, input.BelongID); + if (model == null) + return default; + var url = FileHelper.GetRelatedFilePath(model.StorageHouse, model.StorageCode); + return url; + } + + /// <summary> + /// 閫氳繃 BelongType 鍜� BelongID 鑾峰彇宸ヤ綔鏂囦欢鐩稿Url(鍘绘帀鍓嶇紑锛�(涓嶉渶瑕侀獙璇乀oken) + /// </summary> + [AllowAnonymous] + [Route("GetWorkingFileRelatedUrlByBelongTypeAndBelongID@V1.1")] + [HttpGet] + public string GetWorkingFileRelatedUrlByBelongTypeAndBelongID_V1_1([FromQuery][Required] BelongUnderCorpInput input) + { + var model = new Service.EpanetFile().GetWorkingByBelongTypeAndBelongID(input.CorpID, input.BelongType, input.BelongID); + if (model == null) + return default; + var url = FileHelper.GetRelatedFilePath(model.StorageHouse, model.StorageCode); + return url; + } + + #endregion + + #region 閫氳繃 BelongType 鍜� BelongID 鑾峰彇榛樿宸ヤ綔鏂囦欢Url + + /// <summary> + /// 閫氳繃 BelongType 鍜� BelongID 鑾峰彇榛樿宸ヤ綔鏂囦欢Url(鍏ㄨ矾寰� 閲囩敤ip+port璁块棶姝e父锛岀敤鍩熷悕璁块棶浼氭湁闂锛� + /// </summary> + [Route("GetDefaultWorkingFileUrlByBelongTypeAndBelongID@V1.0")] + [HttpGet] + public string GetDefaultWorkingFileUrlByBelongTypeAndBelongID_V1_0([FromQuery][Required] BelongUnderCorpInput input) + { + var model = new Service.EpanetFile().GetDefaultWorkingByBelongTypeAndBelongID(input.CorpID, input.BelongType, input.BelongID); + if (model == null) + return default; + var url = $"http://{_httpContextAccessor.HttpContext.Request.Host}/{FileHelper.GetRelatedFilePath(model.StorageHouse, model.StorageCode)}"; + return url; + } + + /// <summary> + /// 閫氳繃 BelongType 鍜� BelongID 鑾峰彇榛樿宸ヤ綔鏂囦欢Url(鍏ㄨ矾寰� 閲囩敤ip+port璁块棶姝e父锛岀敤鍩熷悕璁块棶浼氭湁闂锛�(涓嶉渶瑕侀獙璇乀oken) + /// </summary> + [AllowAnonymous] + [Route("GetDefaultWorkingFileUrlByBelongTypeAndBelongID@V1.1")] + [HttpGet] + public string GetDefaultWorkingFileUrlByBelongTypeAndBelongID_V1_1([FromQuery][Required] BelongUnderCorpInput input) + { + var model = new Service.EpanetFile().GetDefaultWorkingByBelongTypeAndBelongID(input.CorpID, input.BelongType, input.BelongID); + if (model == null) + return default; + var url = $"http://{_httpContextAccessor.HttpContext.Request.Host}/{FileHelper.GetRelatedFilePath(model.StorageHouse, model.StorageCode)}"; + return url; + } + + #endregion + + #region 閫氳繃 BelongType 鍜� BelongID 鑾峰彇榛樿宸ヤ綔鏂囦欢鐩稿Url + + /// <summary> + /// 閫氳繃 BelongType 鍜� BelongID 鑾峰彇榛樿宸ヤ綔鏂囦欢鐩稿Url(鍘绘帀鍓嶇紑锛� + /// </summary> + [Route("GetDefaultWorkingFileRelatedUrlByBelongTypeAndBelongID@V1.0")] + [HttpGet] + public string GetDefaultWorkingFileRelatedUrlByBelongTypeAndBelongID_V1_0([FromQuery][Required] BelongUnderCorpInput input) + { + var model = new Service.EpanetFile().GetDefaultWorkingByBelongTypeAndBelongID(input.CorpID, input.BelongType, input.BelongID); + if (model == null) + return default; + var url = FileHelper.GetRelatedFilePath(model.StorageHouse, model.StorageCode); + return url; + } + + /// <summary> + /// 閫氳繃 BelongType 鍜� BelongID 鑾峰彇榛樿宸ヤ綔鏂囦欢鐩稿Url(鍘绘帀鍓嶇紑锛�(涓嶉渶瑕侀獙璇乀oken) + /// </summary> + [AllowAnonymous] + [Route("GetDefaultWorkingFileRelatedUrlByBelongTypeAndBelongID@V1.1")] + [HttpGet] + public string GetDefaultWorkingFileRelatedUrlByBelongTypeAndBelongID_V1_1([FromQuery][Required] BelongUnderCorpInput input) + { + var model = new Service.EpanetFile().GetDefaultWorkingByBelongTypeAndBelongID(input.CorpID, input.BelongType, input.BelongID); + if (model == null) + return default; + var url = FileHelper.GetRelatedFilePath(model.StorageHouse, model.StorageCode); + return url; + } + + #endregion + + #region 閫氳繃 BelongType 鍜� BelongID 涓嬭浇宸ヤ綔鏂囦欢 + + /// <summary> + /// 閫氳繃 BelongType 鍜� BelongID 涓嬭浇宸ヤ綔鏂囦欢 + /// </summary> + [Route("DownloadWorkingFileByBelongTypeAndBelongID@V1.0")] + [HttpGet] + [NonUnify] + public HttpResponseMessage DownloadWorkingFileByBelongTypeAndBelongID_V1_0([FromQuery][Required] BelongUnderCorpInput input) + { + var model = new Service.EpanetFile().GetWorkingByBelongTypeAndBelongID(input.CorpID, input.BelongType, input.BelongID); + if (model == null) + { + return new HttpResponseMessage(HttpStatusCode.NoContent); + } + if (string.IsNullOrEmpty(model.StorageCode)) + { + return new HttpResponseMessage(HttpStatusCode.NoContent); + } + + var file = FileHelper.DownloadSubFile(model.StorageHouse, model.StorageCode); + if (file == null) + { + return new HttpResponseMessage(HttpStatusCode.NoContent); + } + + var result = new HttpResponseMessage(HttpStatusCode.OK); + result.Content = new StreamContent(file); + result.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream"); + return result; + } + + /// <summary> + /// 閫氳繃 BelongType 鍜� BelongID 涓嬭浇宸ヤ綔鏂囦欢(涓嶉渶瑕侀獙璇乀oken) + /// </summary> + [AllowAnonymous] + [Route("DownloadWorkingFileByBelongTypeAndBelongID@V1.1")] + [HttpGet] + [NonUnify] + public HttpResponseMessage DownloadWorkingFileByBelongTypeAndBelongID_V1_1([FromQuery][Required] BelongUnderCorpInput input) + { + var model = new Service.EpanetFile().GetWorkingByBelongTypeAndBelongID(input.CorpID, input.BelongType, input.BelongID); + if (model == null) + { + return new HttpResponseMessage(HttpStatusCode.NoContent); + } + if (string.IsNullOrEmpty(model.StorageCode)) + { + return new HttpResponseMessage(HttpStatusCode.NoContent); + } + + var file = FileHelper.DownloadSubFile(model.StorageHouse, model.StorageCode); + if (file == null) + { + return new HttpResponseMessage(HttpStatusCode.NoContent); + } + + var result = new HttpResponseMessage(HttpStatusCode.OK); + result.Content = new StreamContent(file); + result.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream"); + return result; + } + + #endregion + + #region 閫氳繃 BelongType 鍜� BelongID 涓嬭浇榛樿宸ヤ綔鏂囦欢 + + /// <summary> + /// 閫氳繃 BelongType 鍜� BelongID 涓嬭浇榛樿宸ヤ綔鏂囦欢 + /// </summary> + [Route("DownloadDefaultWorkingFileByBelongTypeAndBelongID@V1.0")] + [HttpGet] + [NonUnify] + public HttpResponseMessage DownloadDefaultWorkingFileByBelongTypeAndBelongID_V1_0([FromQuery][Required] BelongUnderCorpInput input) + { + var model = new Service.EpanetFile().GetDefaultWorkingByBelongTypeAndBelongID(input.CorpID, input.BelongType, input.BelongID); + if (model == null) + { + return new HttpResponseMessage(HttpStatusCode.NoContent); + } + if (string.IsNullOrEmpty(model.StorageCode)) + { + return new HttpResponseMessage(HttpStatusCode.NoContent); + } + + var file = FileHelper.DownloadSubFile(model.StorageHouse, model.StorageCode); + if (file == null) + { + return new HttpResponseMessage(HttpStatusCode.NoContent); + } + + var result = new HttpResponseMessage(HttpStatusCode.OK); + result.Content = new StreamContent(file); + result.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream"); + return result; + } + + /// <summary> + /// 閫氳繃 BelongType 鍜� BelongID 涓嬭浇榛樿宸ヤ綔鏂囦欢(涓嶉渶瑕侀獙璇乀oken) + /// </summary> + [AllowAnonymous] + [Route("DownloadDefaultWorkingFileByBelongTypeAndBelongID@V1.1")] + [HttpGet] + [NonUnify] + public HttpResponseMessage DownloadDefaultWorkingFileByBelongTypeAndBelongID_V1_1([FromQuery][Required] BelongUnderCorpInput input) + { + var model = new Service.EpanetFile().GetDefaultWorkingByBelongTypeAndBelongID(input.CorpID, input.BelongType, input.BelongID); + if (model == null) + { + return new HttpResponseMessage(HttpStatusCode.NoContent); + } + if (string.IsNullOrEmpty(model.StorageCode)) + { + return new HttpResponseMessage(HttpStatusCode.NoContent); + } + + var file = FileHelper.DownloadSubFile(model.StorageHouse, model.StorageCode); + if (file == null) + { + return new HttpResponseMessage(HttpStatusCode.NoContent); + } + + var result = new HttpResponseMessage(HttpStatusCode.OK); + result.Content = new StreamContent(file); + result.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream"); + return result; + } + + #endregion + + #region 鑾峰彇鏂囦欢Url + + /// <summary> + /// 鑾峰彇鏂囦欢Url锛堝叏璺緞 閲囩敤ip+port璁块棶姝e父锛岀敤鍩熷悕璁块棶浼氭湁闂锛� + /// </summary> + [Route("GetFileUrl@V1.0")] + [HttpGet] + public string GetFileUrl_V1_0([FromQuery] IDUnderCorpInput input) + { + var model = new Service.EpanetFile().GetByID(input.CorpID, input.ID); + if (model == null) + { + throw new Exception("鏈绱㈠埌鍩虹淇℃伅"); + } + var url = $"http://{_httpContextAccessor.HttpContext.Request.Host}/{FileHelper.GetRelatedFilePath(model.StorageHouse, model.StorageCode)}"; + return url; + } + + /// <summary> + /// 鑾峰彇鏂囦欢Url锛堝叏璺緞 閲囩敤ip+port璁块棶姝e父锛岀敤鍩熷悕璁块棶浼氭湁闂锛�(涓嶉渶瑕侀獙璇乀oken) + /// </summary> + [AllowAnonymous] + [Route("GetFileUrl@V1.1")] + [HttpGet] + public string GetFileUrl_V1_1([FromQuery] IDUnderCorpInput input) + { + var model = new Service.EpanetFile().GetByID(input.CorpID, input.ID); + if (model == null) + { + throw new Exception("鏈绱㈠埌鍩虹淇℃伅"); + } + var url = $"http://{_httpContextAccessor.HttpContext.Request.Host}/{FileHelper.GetRelatedFilePath(model.StorageHouse, model.StorageCode)}"; + return url; + } + + #endregion + + #region 鑾峰彇鏂囦欢鐩稿Url + + /// <summary> + /// 鑾峰彇鏂囦欢鐩稿Url锛堝幓鎺夊墠缂�锛� + /// </summary> + [Route("GetFileRelatedUrl@V1.0")] + [HttpGet] + public string GetFileRelatedUrl_V1_0([FromQuery] IDUnderCorpInput input) + { + var model = new Service.EpanetFile().GetByID(input.CorpID, input.ID); + if (model == null) + { + throw new Exception("鏈绱㈠埌鍩虹淇℃伅"); + } + var url = FileHelper.GetRelatedFilePath(model.StorageHouse, model.StorageCode); + return url; + } + + /// <summary> + /// 鑾峰彇鏂囦欢鐩稿Url锛堝幓鎺夊墠缂�锛�(涓嶉渶瑕侀獙璇乀oken) + /// </summary> + [AllowAnonymous] + [Route("GetFileRelatedUrl@V1.1")] + [HttpGet] + public string GetFileRelatedUrl_V1_1([FromQuery] IDUnderCorpInput input) + { + var model = new Service.EpanetFile().GetByID(input.CorpID, input.ID); + if (model == null) + { + throw new Exception("鏈绱㈠埌鍩虹淇℃伅"); + } + var url = FileHelper.GetRelatedFilePath(model.StorageHouse, model.StorageCode); + return url; + } + + #endregion + + #region 涓嬭浇鏂囦欢 + + /// <summary> + /// 涓嬭浇鏂囦欢锛堣繑鍥炴祦锛� + /// </summary> + [Route("DownloadFile@V1.0")] + [HttpGet] + [NonUnify] + public HttpResponseMessage DownloadFile_V1_0([FromQuery] IDUnderCorpInput input) + { + var model = new Service.EpanetFile().GetByID(input.CorpID, input.ID); + if (model == null) + { + return new HttpResponseMessage(HttpStatusCode.NoContent); + } + if (string.IsNullOrEmpty(model.StorageCode)) + { + return new HttpResponseMessage(HttpStatusCode.NoContent); + } + + var file = FileHelper.DownloadSubFile(model.StorageHouse, model.StorageCode); + if (file == null) + { + return new HttpResponseMessage(HttpStatusCode.NoContent); + } + + var result = new HttpResponseMessage(HttpStatusCode.OK); + result.Content = new StreamContent(file); + result.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream"); + return result; + } + + /// <summary> + /// 涓嬭浇鏂囦欢锛堣繑鍥炴祦锛�(涓嶉渶瑕侀獙璇乀oken) + /// </summary> + [AllowAnonymous] + [Route("DownloadFile@V1.1")] + [HttpGet] + [NonUnify] + public HttpResponseMessage DownloadFile_V1_1([FromQuery] IDUnderCorpInput input) + { + var model = new Service.EpanetFile().GetByID(input.CorpID, input.ID); + if (model == null) + { + return new HttpResponseMessage(HttpStatusCode.NoContent); + } + if (string.IsNullOrEmpty(model.StorageCode)) + { + return new HttpResponseMessage(HttpStatusCode.NoContent); + } + + var file = FileHelper.DownloadSubFile(model.StorageHouse, model.StorageCode); + if (file == null) + { + return new HttpResponseMessage(HttpStatusCode.NoContent); + } + + var result = new HttpResponseMessage(HttpStatusCode.OK); + result.Content = new StreamContent(file); + result.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream"); + return result; + } + + #endregion + + + + + + + + + + + + + + + + + } +} diff --git a/Application/IStation.Application4Epanet/epanet_file/logic/dto/EpanetFileLogicDto.cs b/Application/IStation.Application4Epanet/epanet_file/logic/dto/EpanetFileLogicDto.cs new file mode 100644 index 0000000..45e2e38 --- /dev/null +++ b/Application/IStation.Application4Epanet/epanet_file/logic/dto/EpanetFileLogicDto.cs @@ -0,0 +1,105 @@ +锘縰sing System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace IStation.Application +{ + /// <summary> + /// + /// </summary> + public class EpanetFileLogicDto + { + /// <summary> + /// + /// </summary> + public EpanetFileLogicDto() { } + + /// <summary> + /// + /// </summary> + public EpanetFileLogicDto(Model.EpanetFile rhs) + { + this.ID = rhs.ID; + this.CorpID = rhs.CorpID; + this.BelongType = rhs.BelongType; + this.BelongID = rhs.BelongID; + this.Name = rhs.Name; + this.StorageHouse = rhs.StorageHouse; + this.StorageCode = rhs.StorageCode; + this.IsWorking = rhs.IsWorking; + this.Description = rhs.Description; + this.CreateTime = rhs.CreateTime; + this.CreateUserID = rhs.CreateUserID; + this.UpdateTime = rhs.UpdateTime; + this.UpdateUserID = rhs.UpdateUserID; + } + + /// <summary> + /// 鏍囪瘑 + /// </summary> + public long ID { get; set; } + + /// <summary> + /// 瀹㈡埛鏍囪瘑 + /// </summary> + public long CorpID { get; set; } + + /// <summary> + /// 鎵�灞炵被鍨� + /// </summary> + public string BelongType { get; set; } + + /// <summary> + /// 鎵�灞瀒d + /// </summary> + public long BelongID { get; set; } + + /// <summary> + /// 鍚嶇О + /// </summary> + public string Name { get; set; } + + /// <summary> + /// 瀛樺偍浠撳簱 + /// </summary> + public string StorageHouse { get; set; } + + /// <summary> + /// 瀛樺偍缂栫爜 + /// </summary> + public string StorageCode { get; set; } + + /// <summary> + /// 宸ヤ綔鏂囦欢 + /// </summary> + public bool IsWorking { get; set; } + + /// <summary> + /// 璇存槑 + /// </summary> + public string Description { get; set; } + + /// <summary> + /// 鍒涘缓鐢ㄦ埛鏍囪瘑 + /// </summary> + public long CreateUserID { get; set; } + + /// <summary> + /// 鍒涘缓鏃堕棿 + /// </summary> + public DateTime CreateTime { get; set; } + + /// <summary> + /// 鏇存柊鐢ㄦ埛鏍囪瘑 + /// </summary> + public long? UpdateUserID { get; set; } + + /// <summary> + /// 鏇存柊鏃堕棿 + /// </summary> + public DateTime? UpdateTime { get; set; } + + } +} diff --git a/Application/IStation.Application4Epanet/helper/Constant.cs b/Application/IStation.Application4Epanet/helper/Constant.cs new file mode 100644 index 0000000..bac4d29 --- /dev/null +++ b/Application/IStation.Application4Epanet/helper/Constant.cs @@ -0,0 +1,18 @@ +锘縰sing System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace IStation.Application +{ + internal class Constant + { + /// <summary> + /// Epanet浠撳簱 + /// </summary> + public const string EpanetStorageHouse = "EpanetFile"; + + + } +} diff --git a/Application/IStation.Application4File/Helpers/ConfigHelper.cs b/Application/IStation.Application4File/Helpers/ConfigHelper.cs deleted file mode 100644 index 95d5f2b..0000000 --- a/Application/IStation.Application4File/Helpers/ConfigHelper.cs +++ /dev/null @@ -1,46 +0,0 @@ -锘縰sing System; -using System.Collections.Generic; -using System.Linq; -using System.Web; - -namespace IStation.Application -{ - /// <summary> - /// - /// </summary> - internal class ConfigHelper - { - /// <summary> - /// 鏁版嵁鏂囦欢澶硅矾寰� - /// </summary> - public static string DataPath - { - get - { - if (string.IsNullOrEmpty(_dataPath)) - { - _dataPath = Settings.File.GetFullPath(nameof(Settings.File.DataFolder)); - } - return _dataPath; - } - } - private static string _dataPath = null; - - /// <summary> - /// 鏁版嵁鏂囦欢澶� - /// </summary> - public static string DataFolder - { - get - { - if (string.IsNullOrEmpty(_datafolder)) - { - _datafolder = Settings.File.DataFolder; - } - return _datafolder; - } - } - private static string _datafolder = null; - - } -} \ No newline at end of file diff --git a/Application/IStation.Application4File/Helpers/FileHelper.cs b/Application/IStation.Application4File/Helpers/FileHelper.cs deleted file mode 100644 index c93e3f0..0000000 --- a/Application/IStation.Application4File/Helpers/FileHelper.cs +++ /dev/null @@ -1,440 +0,0 @@ -锘縰sing System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using IStation.Untity; - -namespace IStation.Application -{ - /// <summary> - /// 澶勭悊鏂囦欢杈呭姪绫� - /// </summary> - public partial class FileHelper - { - - #region Upload - - /// <summary> - /// 涓婁紶鏂囦欢 鏂囦欢娴佸舰寮� - /// </summary> - /// <param name="suffix"></param> - /// <param name="stream"></param> - /// <returns></returns> - public static string UploadFile(Stream stream, string suffix) - { - var root = ConfigHelper.DataPath; - if (!Directory.Exists(root)) - Directory.CreateDirectory(root); - var guid = GuidCreater.CreateN(); - var fileName = guid + suffix; - var filePath = Path.Combine(root, fileName); - StreamTransfer.ToFile(stream, filePath); - return fileName; - } - - /// <summary> - /// 涓婁紶鍒板瓙鏂囦欢澶规枃浠� 鏂囦欢娴佸舰寮� - /// </summary> - /// <param name="sub">瀛愭枃浠跺す</param> - /// <param name="suffix">鏂囦欢鎷撳睍鍚�</param> - /// <param name="stream">鏂囦欢娴�</param> - /// <returns></returns> - public static string UploadSubFile(string sub, Stream stream, string suffix) - { - string root; - if (string.IsNullOrEmpty(sub)) - { - root = ConfigHelper.DataPath; - } - else - { - root = Path.Combine(ConfigHelper.DataPath, sub); - } - if (!Directory.Exists(root)) - Directory.CreateDirectory(root); - var guid = GuidCreater.CreateN(); - var fileName = guid + suffix; - var filePath = Path.Combine(root, fileName); - StreamTransfer.ToFile(stream, filePath); - return fileName; - } - - - /// <summary> - /// 涓婁紶鏂囦欢 瀛楄妭褰㈠紡 - /// </summary> - /// <param name="bytes">瀛楄妭娴�</param> - /// <param name="suffix">鏂囦欢鎷撳睍鍚�</param> - /// <returns></returns> - public static string UploadFile(byte[] bytes, string suffix) - { - string root = ConfigHelper.DataPath; - if (!Directory.Exists(root)) - Directory.CreateDirectory(root); - var guid = GuidCreater.CreateN(); - var fileName = guid + suffix; - var filePath = Path.Combine(root, fileName); - System.IO.File.WriteAllBytes(filePath, bytes); - return fileName; - } - - /// <summary> - /// 涓婁紶鍒板瓙鏂囦欢澶规枃浠� 瀛楄妭褰㈠紡 - /// </summary> - /// <param name="sub">瀛愭枃浠跺す鍚�</param> - /// <param name="suffix">鏂囦欢鎷撳睍鍚�</param> - /// <param name="bytes">瀛楄妭鏁扮粍</param> - /// <returns></returns> - public static string UploadSubFile(string sub, byte[] bytes, string suffix) - { - string root; - if (string.IsNullOrEmpty(sub)) - { - root = ConfigHelper.DataPath; - } - else - { - root = Path.Combine(ConfigHelper.DataPath, sub); - } - if (!Directory.Exists(root)) - Directory.CreateDirectory(root); - var guid = GuidCreater.CreateN(); - var fileName = guid + suffix; - var filePath = Path.Combine(root, fileName); - System.IO.File.WriteAllBytes(filePath, bytes); - return fileName; - } - - - #endregion - - #region Download - - /// <summary> - /// 涓嬭浇鏂囦欢 鏂囦欢娴� - /// </summary> - /// <param name="fileName">鏂囦欢鍚嶇О</param> - /// <returns></returns> - public static Stream DownloadFile(string fileName) - { - var root = ConfigHelper.DataPath; - var filePath = Path.Combine(root, fileName); - if (System.IO.File.Exists(filePath)) - { - return StreamTransfer.FromFile(filePath); - } - return null; - } - - /// <summary> - /// 涓嬭浇鏂囦欢 鏂囦欢娴佹柟寮� - /// </summary> - /// <param name="sub">瀛愭枃浠跺す鍚�</param> - /// <param name="fileName">鏂囦欢鍚嶇О</param> - /// <returns></returns> - public static Stream DownloadSubFile(string sub, string fileName) - { - string root; - if (string.IsNullOrEmpty(sub)) - { - root = ConfigHelper.DataPath; - } - else - { - root = Path.Combine(ConfigHelper.DataPath, sub); - } - var filePath = Path.Combine(root, fileName); - - if (System.IO.File.Exists(filePath)) - { - return StreamTransfer.FromFile(filePath); - } - return default; - } - - /// <summary> - /// 涓嬭浇鏂囦欢 瀛楄妭褰㈠紡 - /// </summary> - /// <param name="fileName">鏂囦欢鍚嶇О</param> - /// <returns></returns> - public static byte[] DownloadFile2(string fileName) - { - var root = ConfigHelper.DataPath; - var filePath = Path.Combine(root, fileName); - if (System.IO.File.Exists(filePath)) - { - return System.IO.File.ReadAllBytes(filePath); - } - return default; - } - - /// <summary> - /// 涓嬭浇鏂囦欢 瀛楄妭褰㈠紡 - /// </summary> - /// <param name="sub">瀛愭枃浠跺す鍚�</param> - /// <param name="fileName">鏂囦欢鍚嶇О</param> - /// <returns></returns> - public static byte[] DownloadSubFile2(string sub, string fileName) - { - string root; - if (string.IsNullOrEmpty(sub)) - { - root = ConfigHelper.DataPath; - } - else - { - root = Path.Combine(ConfigHelper.DataPath, sub); - } - var filePath = Path.Combine(root, fileName); - if (System.IO.File.Exists(filePath)) - { - return System.IO.File.ReadAllBytes(filePath); - } - return default; - } - - - - #endregion - - #region Update - - /// <summary> - /// 鏇存柊鏂囦欢 - /// </summary> - /// <param name="fileName">鏂囦欢鍚嶇О</param> - /// <param name="stream">娴�</param> - /// <param name="suffix">鏂囦欢鍚庣紑</param> - /// <returns></returns> - public static string UpdateFile(string fileName, Stream stream, string suffix) - { - try - { - var code = UploadFile(stream, suffix); - if (!string.IsNullOrEmpty(code)) - { - if (!string.IsNullOrEmpty(fileName)) - Delete(fileName); - } - return code; - } - catch (Exception) - { - return default; - } - - } - - /// <summary> - /// 鏇存柊鏂囦欢 - /// </summary> - /// <param name="fileName">鑰佹枃浠跺悕</param> - /// <param name="suffix">鏂囦欢鍚庣紑</param> - /// <param name="bytes">瀛楄妭娴�</param> - /// <returns></returns> - public static string UpdateFile2(string fileName, byte[] bytes, string suffix) - { - try - { - var code = UploadFile(bytes, suffix); - if (!string.IsNullOrEmpty(code)) - { - if (!string.IsNullOrEmpty(fileName)) - Delete(fileName); - } - return code; - } - catch (Exception) - { - return default; - } - } - - /// <summary> - /// 鏇存柊鏂囦欢 - /// </summary> - /// <param name="sub">瀛愭枃浠跺す</param> - /// <param name="fileName">鑰佹枃浠跺悕</param> - /// <param name="suffix">鏂囦欢鍚庣紑</param> - /// <param name="stream">瀛楄妭娴�</param> - /// <returns></returns> - public static string UpdateSubFile(string sub, string fileName, Stream stream, string suffix) - { - try - { - var code = UploadSubFile(sub, stream, suffix); - if (!string.IsNullOrEmpty(code)) - { - if (!string.IsNullOrEmpty(fileName)) - Delete(sub, fileName); - } - return code; - } - catch (Exception) - { - return null; - } - - } - - - /// <summary> - /// 鏇存柊鏂囦欢 - /// </summary> - /// <param name="sub">瀛愭枃浠跺す</param> - /// <param name="fileName">鑰佹枃浠跺悕</param> - /// <param name="suffix">鏂囦欢鍚庣紑</param> - /// <param name="bytes">瀛楄妭娴�</param> - /// <returns></returns> - public static string UpdateSubFile2(string sub, string fileName, byte[] bytes, string suffix) - { - try - { - var code = UploadSubFile(sub, bytes, suffix); - if (!string.IsNullOrEmpty(code)) - { - if (!string.IsNullOrEmpty(fileName)) - Delete(sub, fileName); - } - return code; - } - catch (Exception) - { - return null; - } - - } - - #endregion - - #region Delete - - /// <summary> - /// 鍒犻櫎鏂囦欢 - /// </summary> - /// <param name="fileName">鏂囦欢鍚嶇О</param> - /// <returns></returns> - public static bool Delete(string fileName) - { - if (string.IsNullOrEmpty(fileName)) - return default; - try - { - var root = ConfigHelper.DataPath; - var filePath = System.IO.Path.Combine(root, fileName); - if (System.IO.File.Exists(filePath)) - { - System.IO.File.Delete(filePath); - } - } - catch (Exception) - { - return false; - } - return true; - } - - /// <summary> - /// 鍒犻櫎鏂囦欢 - /// </summary> - /// <param name="sub">瀛愭枃浠跺悕</param> - /// <param name="fileName">鏂囦欢鍚嶇О</param> - /// <returns></returns> - public static bool Delete(string sub, string fileName) - { - if (string.IsNullOrEmpty(fileName)) - return default; - string root; - if (string.IsNullOrEmpty(sub)) - { - root = ConfigHelper.DataPath; - } - else - { - root = Path.Combine(ConfigHelper.DataPath, sub); - } - var filePath = Path.Combine(root, fileName); - try - { - if (System.IO.File.Exists(filePath)) - { - System.IO.File.Delete(filePath); - } - } - catch (Exception) - { - return false; - } - - return true; - } - - #endregion - - #region Path - - /// <summary> - /// 鑾峰彇鏂囦欢璺緞 - /// </summary> - public static string GetFilePath(string fileName) - { - if (string.IsNullOrEmpty(fileName)) - return default; - var root = ConfigHelper.DataPath; - var filePath = System.IO.Path.Combine(root, fileName); - return filePath; - } - - /// <summary> - /// 鑾峰彇鏂囦欢鐩稿璺緞 - /// </summary> - public static string GetRelatedFilePath(string fileName) - { - if (string.IsNullOrEmpty(fileName)) - return default; - return $"{ConfigHelper.DataFolder}/{fileName}"; - } - - /// <summary> - /// 鑾峰彇鏂囦欢璺緞 - /// </summary> - public static string GetFilePath(string sub, string fileName) - { - if (string.IsNullOrEmpty(fileName)) - return default; - string root; - if (string.IsNullOrEmpty(sub)) - { - root = ConfigHelper.DataPath; - } - else - { - root = Path.Combine(ConfigHelper.DataPath, sub); - } - var filePath = Path.Combine(root, fileName); - return filePath; - } - - /// <summary> - /// 鑾峰彇鏂囦欢鐩稿璺緞 - /// </summary> - public static string GetRelatedFilePath(string sub, string fileName) - { - if (string.IsNullOrEmpty(fileName)) - return default; - if (string.IsNullOrEmpty(sub)) - return GetRelatedFilePath(fileName); - return $"{ConfigHelper.DataFolder}/{sub}/{fileName}"; - } - - #endregion - - - - - - - } -} diff --git a/Application/IStation.Application4File/file/File_Controller.cs b/Application/IStation.Application4File/file/File_Controller.cs index f377496..606e437 100644 --- a/Application/IStation.Application4File/file/File_Controller.cs +++ b/Application/IStation.Application4File/file/File_Controller.cs @@ -35,7 +35,7 @@ #region 涓婁紶鏂囦欢 /// <summary> - /// 涓婁紶鏂囦欢 + /// 涓婁紶鏂囦欢锛堜粎鏀寔涓婁紶涓�涓枃浠讹級 /// </summary> [Route("UploadFile@V1.0")] [HttpPost] @@ -53,7 +53,7 @@ } /// <summary> - /// 涓婁紶鏂囦欢鍒板瓙鐩綍涓� + /// 涓婁紶鏂囦欢鍒板瓙鐩綍涓嬶紙浠呮敮鎸佷笂浼犱竴涓枃浠讹級 /// </summary> [Route("UploadSubFile@V1.0")] [HttpPost] @@ -78,7 +78,7 @@ #region 涓嬭浇鏂囦欢 /// <summary> - /// 涓嬭浇鏂囦欢 + /// 涓嬭浇鏂囦欢锛堣繑鍥炴祦锛� /// </summary> [Route("DownloadFile@V1.0")] [HttpGet] @@ -107,7 +107,7 @@ } /// <summary> - /// 涓嬭浇瀛愮洰褰曚笅鐨勬枃浠� + /// 涓嬭浇瀛愮洰褰曚笅鐨勬枃浠讹紙杩斿洖娴侊級 /// </summary> [Route("DownloadSubFile@V1.0")] [HttpGet] @@ -230,11 +230,11 @@ #region 鑾峰彇Url /// <summary> - /// 鑾峰彇鏂囦欢Url + /// 鑾峰彇鏂囦欢Url锛堝叏璺緞 閲囩敤ip+port璁块棶姝e父锛岀敤鍩熷悕璁块棶浼氭湁闂锛� /// </summary> [Route("GetFileUrl@V1.0")] [HttpGet] - public string GetFileUrl + public string GetFileUrl_V1_0 ( [Required,DataValidation(AllowEmptyStrings =false)] string FileName @@ -245,7 +245,21 @@ } /// <summary> - /// 鑾峰彇瀛愭枃浠跺す涓嬬殑鏂囦欢Url + /// 鑾峰彇鏂囦欢鐩稿Url锛堝幓闄ゅ墠缂�锛� + /// </summary> + [Route("GetFileRelatedUrl@V1.0")] + [HttpGet] + public string GetFileRelatedUrl_V1_0 + ( + [Required,DataValidation(AllowEmptyStrings =false)] + string FileName + ) + { + return FileHelper.GetRelatedFilePath(FileName); + } + + /// <summary> + /// 鑾峰彇瀛愭枃浠跺す涓嬬殑鏂囦欢Url锛堝叏璺緞 閲囩敤ip+port璁块棶姝e父锛岀敤鍩熷悕璁块棶浼氭湁闂锛� /// </summary> [Route("GetSubFileUrl@V1.0")] [HttpGet] @@ -261,6 +275,22 @@ return url; } + /// <summary> + /// 鑾峰彇瀛愭枃浠跺す涓嬬殑鏂囦欢鐩稿Url锛堝幓闄ゅ墠缂�锛� + /// </summary> + [Route("GetSubFileRelatedUrl@V1.0")] + [HttpGet] + public string GetSubFileRelatedUrl_V1_0 + ( + [Required,DataValidation(AllowEmptyStrings =false)] + string Sub, + [Required,DataValidation(AllowEmptyStrings =false)] + string FileName + ) + { + return FileHelper.GetRelatedFilePath(Sub, FileName); + } + #endregion diff --git a/Core/IStation.WebApi.Core/applicationconfig.json b/Core/IStation.WebApi.Core/applicationconfig.json index 124d242..948e9f7 100644 --- a/Core/IStation.WebApi.Core/applicationconfig.json +++ b/Core/IStation.WebApi.Core/applicationconfig.json @@ -150,6 +150,13 @@ "Order": 83, "Description": "浠诲姟妯″潡", "Version": "V1" + }, + { + "Group": "Epanet", + "Title": "Epanet妯″潡", + "Order": 82, + "Description": "Epanet妯″潡", + "Version": "V1" } ] } diff --git a/DAL/IStation.DAL4Epanet/EpanetFile.cs b/DAL/IStation.DAL4Epanet/EpanetFile.cs new file mode 100644 index 0000000..3db5b1a --- /dev/null +++ b/DAL/IStation.DAL4Epanet/EpanetFile.cs @@ -0,0 +1,91 @@ +锘縰sing SqlSugar; +using System; +using System.Collections.Generic; +using System.Data; +using System.Linq; + +namespace IStation.DAL +{ + /// <summary> + /// Epanet鏂囦欢 + /// </summary> + public partial class EpanetFile : CorpTraceDAL<Entity.EpanetFile> + { + /// <summary> + /// + /// </summary> + public override ConnectionConfig ConnectionConfig + { + get { return ConfigHelper.DefaultConnectionConfig; } + } + + + /// <summary> + /// 閫氳繃 BelongType 鍜� BelongID 鑾峰彇 + /// </summary> + public List<Entity.EpanetFile> GetByBelongTypeAndBelongID(long CorpID, string BelongType, long BelongID) + { + using (var db = new SqlSugarClient(ConnectionConfig)) + { + return db.Queryable<Entity.EpanetFile>() + .Where(x => x.CorpID == CorpID && x.BelongType == BelongType && x.BelongID == BelongID).ToList(); + } + } + + /// <summary> + /// 鏇存柊瀛樺偍缂栫爜 + /// </summary> + public bool UpdateStorageCode(long CorpID, long ID, string StorageCode, long UpdateUserID, DateTime UpdateTime) + { + using (SqlSugarClient db = new SqlSugarClient(ConnectionConfig)) + { + return db.Updateable<Entity.EpanetFile>() + .SetColumns(x => x.StorageCode == StorageCode) + .SetColumns(x => x.UpdateUserID == UpdateUserID) + .SetColumns(x => x.UpdateTime == UpdateTime) + .Where(x => x.CorpID == CorpID && x.ID == ID) + .ExecuteCommand() > 0; + } + } + + /// <summary> + /// 璁剧疆宸ヤ綔鏂囦欢 + /// </summary> + public bool SetWorking(long CorpID, string BelongType, long BelongID, long ID, long UpdateUserID, DateTime UpdateTime) + { + using (var db = new SqlSugarClient(ConnectionConfig)) + { + try + { + db.BeginTran(); + var bol = db.Updateable<Entity.EpanetFile>() + .SetColumns(x => x.IsWorking == true) + .SetColumns(x => x.UpdateUserID == UpdateUserID) + .SetColumns(x => x.UpdateTime == UpdateTime) + .Where(x => x.CorpID == CorpID && x.BelongType == BelongType && x.BelongID == BelongID && x.ID == ID).ExecuteCommand() > 0; + if (!bol) + { + db.RollbackTran(); + return false; + } + db.Updateable<Entity.EpanetFile>() + .SetColumns(x => x.IsWorking == false) + .SetColumns(x => x.UpdateUserID == UpdateUserID) + .SetColumns(x => x.UpdateTime == UpdateTime) + .Where(x => x.CorpID == CorpID && x.BelongType==BelongType&&x.BelongID==BelongID && x.ID != ID).ExecuteCommand(); + db.CommitTran(); + return true; + } + catch + { + db.RollbackTran(); + throw; + } + } + } + + + + + } +} \ No newline at end of file diff --git a/DAL/IStation.DAL4Epanet/IStation.DAL4Epanet.csproj b/DAL/IStation.DAL4Epanet/IStation.DAL4Epanet.csproj new file mode 100644 index 0000000..1ee70ae --- /dev/null +++ b/DAL/IStation.DAL4Epanet/IStation.DAL4Epanet.csproj @@ -0,0 +1,17 @@ +<Project Sdk="Microsoft.NET.Sdk"> + + <PropertyGroup> + <TargetFramework>net6.0</TargetFramework> + <ImplicitUsings>enable</ImplicitUsings> + <Nullable>disable</Nullable> + <AssemblyName>IStation.DAL4Epanet</AssemblyName> + <RootNamespace>IStation.DAL</RootNamespace> + <GenerateDocumentationFile>True</GenerateDocumentationFile> + </PropertyGroup> + + <ItemGroup> + <ProjectReference Include="..\..\Entity\IStation.Entity4Epanet\IStation.Entity4Epanet.csproj" /> + <ProjectReference Include="..\IStation.DAL\IStation.DAL.csproj" /> + </ItemGroup> + +</Project> diff --git a/DAL/IStation.DAL4Epanet/helpers/ConfigHelper.cs b/DAL/IStation.DAL4Epanet/helpers/ConfigHelper.cs new file mode 100644 index 0000000..df10b9e --- /dev/null +++ b/DAL/IStation.DAL4Epanet/helpers/ConfigHelper.cs @@ -0,0 +1,68 @@ +锘縰sing System; +using System.Collections.Generic; +using System.Configuration; +using System.Data; +using System.Data.SqlClient; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using SqlSugar; + +namespace IStation.DAL +{ + internal class ConfigHelper + { + /// <summary> + /// 榛樿杩炴帴瀛楃涓� + /// </summary> + public static string DefaultConnString + { + get + { + return Settings.Epanet.DataBase.ConnectString; + } + } + + /// <summary> + /// 榛樿杩炴帴閰嶇疆 + /// </summary> + public static ConnectionConfig DefaultConnectionConfig + { + get + { + return new ConnectionConfig() + { + DbType = SqlSugar.DbType.PostgreSQL,//鏁版嵁搴撶被鍨� + ConnectionString = DefaultConnString, + IsAutoCloseConnection = true,//鏄惁鑷姩鍏抽棴 + MoreSettings = new ConnMoreSettings() + { + //PgSqlIsAutoToLower = false //鏁版嵁搴撳瓨鍦ㄥぇ鍐欏瓧娈电殑 锛岄渶瑕佹妸杩欎釜璁句负false 锛屽苟涓斿疄浣撳拰瀛楁鍚嶇О瑕佷竴鏍� + }, + AopEvents = new AopEvents + { + OnLogExecuting = (sql, p) => + { + // Console.WriteLine(sql); + } + } + }; + } + } + + + + + + + + + + + + + + + + } +} diff --git a/Entity/IStation.Entity4Epanet/EpanetFile.cs b/Entity/IStation.Entity4Epanet/EpanetFile.cs new file mode 100644 index 0000000..fb13db3 --- /dev/null +++ b/Entity/IStation.Entity4Epanet/EpanetFile.cs @@ -0,0 +1,79 @@ +锘縰sing SqlSugar; + +namespace IStation.Entity +{ + /// <summary> + /// Epanet鏂囦欢 + /// </summary> + [SugarTable("epanet_file")] + public class EpanetFile:CorpTraceEntity, System.ICloneable + { + /// <summary> + /// + /// </summary> + public EpanetFile() { } + + /// <summary> + /// + /// </summary> + public EpanetFile(EpanetFile rhs):base(rhs) + { + this.BelongType = rhs.BelongType; + this.BelongID = rhs.BelongID; + this.Name = rhs.Name; + this.StorageHouse = rhs.StorageHouse; + this.StorageCode = rhs.StorageCode; + this.IsWorking = rhs.IsWorking; + this.Description = rhs.Description; + } + + /// <summary> + /// 鎵�灞炵被鍨� + /// </summary> + public string BelongType { get; set; } + + /// <summary> + /// 鎵�灞瀒d + /// </summary> + public long BelongID { get; set; } + + /// <summary> + /// 鍚嶇О + /// </summary> + public string Name { get; set; } + + /// <summary> + /// 瀛樺偍浠撳簱 + /// </summary> + public string StorageHouse { get; set; } + + /// <summary> + /// 瀛樺偍缂栫爜 + /// </summary> + public string StorageCode { get; set; } + + /// <summary> + /// 宸ヤ綔鏂囦欢 + /// </summary> + public bool IsWorking { get; set; } + + /// <summary> + /// 璇存槑 + /// </summary> + public string Description { get; set; } + + /// <summary> + /// + /// </summary> + public EpanetFile Clone() + { + return (EpanetFile)this.MemberwiseClone(); + } + + object ICloneable.Clone() + { + return this.MemberwiseClone(); + } + + } +} \ No newline at end of file diff --git a/Entity/IStation.Entity4Epanet/IStation.Entity4Epanet.csproj b/Entity/IStation.Entity4Epanet/IStation.Entity4Epanet.csproj new file mode 100644 index 0000000..7da20b4 --- /dev/null +++ b/Entity/IStation.Entity4Epanet/IStation.Entity4Epanet.csproj @@ -0,0 +1,16 @@ +<Project Sdk="Microsoft.NET.Sdk"> + + <PropertyGroup> + <TargetFramework>net6.0</TargetFramework> + <ImplicitUsings>enable</ImplicitUsings> + <Nullable>disable</Nullable> + <AssemblyName>IStation.Entity4Epanet</AssemblyName> + <RootNamespace>IStation.Entity</RootNamespace> + <GenerateDocumentationFile>True</GenerateDocumentationFile> + </PropertyGroup> + + <ItemGroup> + <ProjectReference Include="..\IStation.Entity\IStation.Entity.csproj" /> + </ItemGroup> + +</Project> diff --git a/Entry/IStation.WebApi.Entry/IStation.WebApi.Entry.csproj b/Entry/IStation.WebApi.Entry/IStation.WebApi.Entry.csproj index 92dd563..e3ae206 100644 --- a/Entry/IStation.WebApi.Entry/IStation.WebApi.Entry.csproj +++ b/Entry/IStation.WebApi.Entry/IStation.WebApi.Entry.csproj @@ -15,6 +15,7 @@ <ProjectReference Include="..\..\Application\IStation.Application4Bimface\IStation.Application4Bimface.csproj" /> <ProjectReference Include="..\..\Application\IStation.Application4DataFile\IStation.Application4DataFile.csproj" /> <ProjectReference Include="..\..\Application\IStation.Application4Dma\IStation.Application4Dma.csproj" /> + <ProjectReference Include="..\..\Application\IStation.Application4Epanet\IStation.Application4Epanet.csproj" /> <ProjectReference Include="..\..\Application\IStation.Application4Eta\IStation.Application4Eta.csproj" /> <ProjectReference Include="..\..\Application\IStation.Application4File\IStation.Application4File.csproj" /> <ProjectReference Include="..\..\Application\IStation.Application4Inspect\IStation.Application4Inspect.csproj" /> diff --git a/IStation.WebApi.sln b/IStation.WebApi.sln index df9b38a..6ed65c1 100644 --- a/IStation.WebApi.sln +++ b/IStation.WebApi.sln @@ -243,6 +243,16 @@ EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IStation.Application4Job", "Application\IStation.Application4Job\IStation.Application4Job.csproj", "{398CD0EE-C62E-4E44-85FB-AC04A0DE30CE}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IStation.Entity4Epanet", "Entity\IStation.Entity4Epanet\IStation.Entity4Epanet.csproj", "{F851F9AA-7267-4AF8-B60C-C62FB21F5A3A}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IStation.Model4Epanet", "Model\IStation.Model4Epanet\IStation.Model4Epanet.csproj", "{B9D5D2DA-09E9-4853-AD30-1D2717F21B90}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IStation.DAL4Epanet", "DAL\IStation.DAL4Epanet\IStation.DAL4Epanet.csproj", "{85CDAFFC-F0BE-4328-ADC3-CA54C44CB411}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IStation.Service4Epanet", "Service\IStation.Service4Epanet\IStation.Service4Epanet.csproj", "{18557443-7507-41F7-93CD-156104EA164E}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IStation.Application4Epanet", "Application\IStation.Application4Epanet\IStation.Application4Epanet.csproj", "{0E635F6A-71C0-4BC4-AE69-6ABCFC902BA3}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -681,6 +691,26 @@ {398CD0EE-C62E-4E44-85FB-AC04A0DE30CE}.Debug|Any CPU.Build.0 = Debug|Any CPU {398CD0EE-C62E-4E44-85FB-AC04A0DE30CE}.Release|Any CPU.ActiveCfg = Release|Any CPU {398CD0EE-C62E-4E44-85FB-AC04A0DE30CE}.Release|Any CPU.Build.0 = Release|Any CPU + {F851F9AA-7267-4AF8-B60C-C62FB21F5A3A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F851F9AA-7267-4AF8-B60C-C62FB21F5A3A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F851F9AA-7267-4AF8-B60C-C62FB21F5A3A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F851F9AA-7267-4AF8-B60C-C62FB21F5A3A}.Release|Any CPU.Build.0 = Release|Any CPU + {B9D5D2DA-09E9-4853-AD30-1D2717F21B90}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B9D5D2DA-09E9-4853-AD30-1D2717F21B90}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B9D5D2DA-09E9-4853-AD30-1D2717F21B90}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B9D5D2DA-09E9-4853-AD30-1D2717F21B90}.Release|Any CPU.Build.0 = Release|Any CPU + {85CDAFFC-F0BE-4328-ADC3-CA54C44CB411}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {85CDAFFC-F0BE-4328-ADC3-CA54C44CB411}.Debug|Any CPU.Build.0 = Debug|Any CPU + {85CDAFFC-F0BE-4328-ADC3-CA54C44CB411}.Release|Any CPU.ActiveCfg = Release|Any CPU + {85CDAFFC-F0BE-4328-ADC3-CA54C44CB411}.Release|Any CPU.Build.0 = Release|Any CPU + {18557443-7507-41F7-93CD-156104EA164E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {18557443-7507-41F7-93CD-156104EA164E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {18557443-7507-41F7-93CD-156104EA164E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {18557443-7507-41F7-93CD-156104EA164E}.Release|Any CPU.Build.0 = Release|Any CPU + {0E635F6A-71C0-4BC4-AE69-6ABCFC902BA3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {0E635F6A-71C0-4BC4-AE69-6ABCFC902BA3}.Debug|Any CPU.Build.0 = Debug|Any CPU + {0E635F6A-71C0-4BC4-AE69-6ABCFC902BA3}.Release|Any CPU.ActiveCfg = Release|Any CPU + {0E635F6A-71C0-4BC4-AE69-6ABCFC902BA3}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -793,6 +823,11 @@ {C7C288AF-B39C-4E4A-9E0D-9D9943693E85} = {49E7CA43-7FD9-48A3-B0DB-6D99FA93F393} {71B73D1F-56ED-44D3-A3E3-B409A2DF88F4} = {3BE2BA1A-B93F-4EDE-BC37-915663317C33} {398CD0EE-C62E-4E44-85FB-AC04A0DE30CE} = {C7614DA2-0679-407D-B9E3-66D448DD7488} + {F851F9AA-7267-4AF8-B60C-C62FB21F5A3A} = {A24F4CA7-C6A3-4663-9A07-017814E614E7} + {B9D5D2DA-09E9-4853-AD30-1D2717F21B90} = {61C58B21-80C9-4092-ACC5-141B424D15E8} + {85CDAFFC-F0BE-4328-ADC3-CA54C44CB411} = {49E7CA43-7FD9-48A3-B0DB-6D99FA93F393} + {18557443-7507-41F7-93CD-156104EA164E} = {3BE2BA1A-B93F-4EDE-BC37-915663317C33} + {0E635F6A-71C0-4BC4-AE69-6ABCFC902BA3} = {C7614DA2-0679-407D-B9E3-66D448DD7488} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {18D1EA07-81E5-4443-8512-F303BC79DCF4} diff --git a/Model/IStation.Model4Basic/enums/eFileFormat.cs b/Model/IStation.Model/enum/eFileFormat.cs similarity index 100% rename from Model/IStation.Model4Basic/enums/eFileFormat.cs rename to Model/IStation.Model/enum/eFileFormat.cs diff --git a/Model/IStation.Model4Epanet/EpanetFile.cs b/Model/IStation.Model4Epanet/EpanetFile.cs new file mode 100644 index 0000000..1bf97cd --- /dev/null +++ b/Model/IStation.Model4Epanet/EpanetFile.cs @@ -0,0 +1,134 @@ +锘� + +namespace IStation.Model +{ + /// <summary> + /// Epanet鏂囦欢 + /// </summary> + public class EpanetFile : System.ICloneable + { + /// <summary> + /// + /// </summary> + public EpanetFile() { } + + /// <summary> + /// + /// </summary> + public EpanetFile(EpanetFile rhs) + { + this.ID = rhs.ID; + this.CorpID = rhs.CorpID; + this.BelongType = rhs.BelongType; + this.BelongID = rhs.BelongID; + this.Name = rhs.Name; + this.StorageHouse = rhs.StorageHouse; + this.StorageCode = rhs.StorageCode; + this.IsWorking = rhs.IsWorking; + this.Description = rhs.Description; + this.CreateTime = rhs.CreateTime; + this.CreateUserID = rhs.CreateUserID; + this.UpdateTime = rhs.UpdateTime; + this.UpdateUserID = rhs.UpdateUserID; + } + + /// <summary> + /// 閲嶇疆 + /// </summary> + public void Reset(EpanetFile rhs) + { + this.ID = rhs.ID; + this.CorpID = rhs.CorpID; + this.BelongType = rhs.BelongType; + this.BelongID = rhs.BelongID; + this.Name = rhs.Name; + this.StorageHouse = rhs.StorageHouse; + this.StorageCode = rhs.StorageCode; + this.IsWorking = rhs.IsWorking; + this.Description = rhs.Description; + this.CreateTime = rhs.CreateTime; + this.CreateUserID = rhs.CreateUserID; + this.UpdateTime = rhs.UpdateTime; + this.UpdateUserID = rhs.UpdateUserID; + } + + /// <summary> + /// 鏍囪瘑 + /// </summary> + public long ID { get; set; } + + /// <summary> + /// 瀹㈡埛鏍囪瘑 + /// </summary> + public long CorpID { get; set; } + + /// <summary> + /// 鎵�灞炵被鍨� + /// </summary> + public string BelongType { get; set; } + + /// <summary> + /// 鎵�灞瀒d + /// </summary> + public long BelongID { get; set; } + + /// <summary> + /// 鍚嶇О + /// </summary> + public string Name { get; set; } + + /// <summary> + /// 瀛樺偍浠撳簱 + /// </summary> + public string StorageHouse { get; set; } + + /// <summary> + /// 瀛樺偍缂栫爜 + /// </summary> + public string StorageCode { get; set; } + + /// <summary> + /// 宸ヤ綔鏂囦欢 + /// </summary> + public bool IsWorking { get; set; } + + /// <summary> + /// 璇存槑 + /// </summary> + public string Description { get; set; } + + /// <summary> + /// 鍒涘缓鐢ㄦ埛鏍囪瘑 + /// </summary> + public long CreateUserID { get; set; } + + /// <summary> + /// 鍒涘缓鏃堕棿 + /// </summary> + public DateTime CreateTime { get; set; } + + /// <summary> + /// 鏇存柊鐢ㄦ埛鏍囪瘑 + /// </summary> + public long? UpdateUserID { get; set; } + + /// <summary> + /// 鏇存柊鏃堕棿 + /// </summary> + public DateTime? UpdateTime { get; set; } + + /// <summary> + /// + /// </summary> + public EpanetFile Clone() + { + return (EpanetFile)this.MemberwiseClone(); + } + + object ICloneable.Clone() + { + return this.MemberwiseClone(); + } + + } +} \ No newline at end of file diff --git a/Model/IStation.Model4Epanet/IStation.Model4Epanet.csproj b/Model/IStation.Model4Epanet/IStation.Model4Epanet.csproj new file mode 100644 index 0000000..243274d --- /dev/null +++ b/Model/IStation.Model4Epanet/IStation.Model4Epanet.csproj @@ -0,0 +1,16 @@ +<Project Sdk="Microsoft.NET.Sdk"> + + <PropertyGroup> + <TargetFramework>net6.0</TargetFramework> + <ImplicitUsings>enable</ImplicitUsings> + <Nullable>disable</Nullable> + <AssemblyName>IStation.Model4Epanet</AssemblyName> + <RootNamespace>IStation.Model</RootNamespace> + <GenerateDocumentationFile>True</GenerateDocumentationFile> + </PropertyGroup> + + <ItemGroup> + <ProjectReference Include="..\IStation.Model\IStation.Model.csproj" /> + </ItemGroup> + +</Project> diff --git a/Service/IStation.Service4Epanet/IStation.Service4Epanet.csproj b/Service/IStation.Service4Epanet/IStation.Service4Epanet.csproj new file mode 100644 index 0000000..c1abd71 --- /dev/null +++ b/Service/IStation.Service4Epanet/IStation.Service4Epanet.csproj @@ -0,0 +1,18 @@ +<Project Sdk="Microsoft.NET.Sdk"> + + <PropertyGroup> + <TargetFramework>net6.0</TargetFramework> + <ImplicitUsings>enable</ImplicitUsings> + <Nullable>disable</Nullable> + <AssemblyName>IStation.Service4Epanet</AssemblyName> + <RootNamespace>IStation.Service</RootNamespace> + <GenerateDocumentationFile>True</GenerateDocumentationFile> + </PropertyGroup> + + <ItemGroup> + <ProjectReference Include="..\..\DAL\IStation.DAL4Epanet\IStation.DAL4Epanet.csproj" /> + <ProjectReference Include="..\..\Model\IStation.Model4Epanet\IStation.Model4Epanet.csproj" /> + <ProjectReference Include="..\IStation.Service4Basic\IStation.Service4Basic.csproj" /> + </ItemGroup> + +</Project> diff --git a/Service/IStation.Service4Epanet/epanet_file/EpanetFile.cs b/Service/IStation.Service4Epanet/epanet_file/EpanetFile.cs new file mode 100644 index 0000000..36bfc85 --- /dev/null +++ b/Service/IStation.Service4Epanet/epanet_file/EpanetFile.cs @@ -0,0 +1,314 @@ +锘縰sing IStation.Untity; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace IStation.Service +{ + /// <summary> + /// Epanet鏂囦欢 + /// </summary> + public partial class EpanetFile + { + #region Cache + + //閫氳繃 CorpID 鑾峰彇缂撳瓨 + private List<Model.EpanetFile> GetCorpCache(long CorpID) + { + return EpanetFileCacheHelper.GetSet(CorpID, () => + { + var dal = new DAL.EpanetFile(); + var entity_list = dal.GetByCorpID(CorpID); + var model_list = Entity2Models(entity_list); + if (model_list == null) + { + model_list = new List<Model.EpanetFile>(); + } + return model_list; + }, ConfigHelper.CacheKeepTime, ConfigHelper.CacheRandomTime); + } + + //閫氳繃 ID 鏇存柊缂撳瓨 + private void UpdateCorpCache(long CorpID, long ID) + { + var dal = new DAL.EpanetFile(); + var entity_ds = dal.GetByID(CorpID, ID); + var model_ds = Entity2Model(entity_ds); + var all = GetCorpCache(CorpID); + var model = all.Find(x => x.ID == ID); + if (model == null) + { + all.Add(model_ds); + } + else + { + model.Reset(model_ds); + } + } + + //閫氳繃 Ids 鏇存柊缂撳瓨 + private void UpdateCorpCache(long CorpID, List<long> Ids) + { + if (Ids == null || Ids.Count() < 1) + return; + var dal = new DAL.EpanetFile(); + var entity_list = dal.GetByIds(CorpID, Ids); + var model_list = Entity2Models(entity_list); + var all = GetCorpCache(CorpID); + all.RemoveAll(x => Ids.Contains(x.ID)); + if (model_list != null && model_list.Count > 0) + { + all.AddRange(model_list); + } + } + + //閫氳繃 BelongType 鍜� BelongID 鑾峰彇 + private void UpdateCorpCacheByBelongTypeAndBelongID(long CorpID, string BelongType, long BelongID) + { + var dal = new DAL.EpanetFile(); + var entity_list = dal.GetByBelongTypeAndBelongID(CorpID, BelongType,BelongID); + var model_list = Entity2Models(entity_list); + var all = GetCorpCache(CorpID); + all.RemoveAll(x => x.BelongType==BelongType&&x.BelongID==BelongID); + if (model_list != null && model_list.Count > 0) + { + all.AddRange(model_list); + } + } + + //閫氳繃 ID 绉婚櫎缂撳瓨 + private void RemoveCorpCache(long CorpID, long ID) + { + var all = GetCorpCache(CorpID); + all.RemoveAll(x => x.ID == ID); + } + + #endregion + + #region Query + + /// <summary> + /// 閫氳繃 CorpID 鑾峰彇 + /// </summary> + public List<Model.EpanetFile> GetByCorpID(long CorpID) + { + var all = GetCorpCache(CorpID); + return all.OrderBy(x => x.CreateTime).ToList(); + } + + /// <summary> + /// 閫氳繃 ID 鑾峰彇 + /// </summary> + public Model.EpanetFile GetByID(long CorpID, long ID) + { + var all = GetByCorpID(CorpID); + return all.Find(x => x.ID == ID); + } + + /// <summary> + /// 閫氳繃 Ids 鑾峰彇 + /// </summary> + public List<Model.EpanetFile> GetByIds(long CorpID, List<long> Ids) + { + if (Ids == null || Ids.Count() < 1) + return default; + var all = GetByCorpID(CorpID); + return all.Where(x => Ids.Contains(x.ID)).OrderBy(x => x.CreateTime).ToList(); + } + + /// <summary> + /// 閫氳繃 BelongType 鍜� BelongID 鑾峰彇 + /// </summary> + public List<Model.EpanetFile> GetByBelongTypeAndBelongID(long CorpID,string BelongType,long BelongID) + { + var all = GetByCorpID(CorpID); + return all.Where(x => x.BelongType == BelongType && x.BelongID == BelongID).OrderBy(x => x.CreateUserID).ToList(); + } + + /// <summary> + /// 閫氳繃 BelongType 鍜� BelongID 鑾峰彇宸ヤ綔鏂囦欢 + /// </summary> + public Model.EpanetFile GetWorkingByBelongTypeAndBelongID(long CorpID, string BelongType, long BelongID) + { + var all = GetByCorpID(CorpID); + var list = all.Where(x => x.BelongType == BelongType && x.BelongID == BelongID).ToList(); + return list.FirstOrDefault(x => x.IsWorking); + } + + /// <summary> + /// 閫氳繃 BelongType 鍜� BelongID 鑾峰彇榛樿宸ヤ綔鏂囦欢 + /// </summary> + public Model.EpanetFile GetDefaultWorkingByBelongTypeAndBelongID(long CorpID, string BelongType, long BelongID) + { + var all = GetByCorpID(CorpID); + var list = all.Where(x => x.BelongType == BelongType && x.BelongID == BelongID).ToList(); + var working= list.FirstOrDefault(x => x.IsWorking); + if (working == null) + { + working = list.OrderBy(x => x.CreateTime).LastOrDefault(); + } + return working; + } + + #endregion + + #region Insert + + /// <summary> + /// 鎻掑叆涓�鏉℃暟鎹� + /// </summary> + public long Insert(Model.EpanetFile model) + { + if (model == null) + return default; + if (model.CorpID < 1) + return default; + var dal = new DAL.EpanetFile(); + var entity = Model2Entity(model); + var id = dal.Insert(entity); + if (id > 0) + { + UpdateCorpCache(model.CorpID, id); + } + return id; + } + + /// <summary> + /// 鎻掑叆澶氭潯 + /// </summary> + public bool Inserts(List<Model.EpanetFile> list) + { + if (list == null || list.Count() < 1) + return default; + var corpIds = list.Select(x => x.CorpID).Distinct().ToList(); + if (corpIds.Count != 1 || corpIds[0] < 1) + return default; + var dal = new DAL.EpanetFile(); + var entity_list = Model2Entities(list.ToList()); + var ids = dal.InsertsR(entity_list); + if (ids != null && ids.Count > 0) + { + UpdateCorpCache(corpIds[0], ids); + return true; + } + return false; + } + + #endregion + + #region Update + + /// <summary> + /// 鏇存柊涓�鏉� + /// </summary> + public bool Update(Model.EpanetFile model) + { + if (model == null) + return default; + if (model.CorpID < 1) + return default; + if (model.ID < 1) + return default; + var dal = new DAL.EpanetFile(); + var entity = Model2Entity(model); + var bol = dal.Update(entity); + if (bol) + { + UpdateCorpCache(model.CorpID, model.ID); + } + return bol; + } + + /// <summary> + /// 鏇存柊澶氭潯 + /// </summary> + public bool Updates(List<Model.EpanetFile> list) + { + if (list == null || list.Count() < 1) + return default; + var corpIds = list.Select(x => x.CorpID).Distinct().ToList(); + if (corpIds.Count != 1 || corpIds[0] < 1) + return default; + if (list.ToList().Exists(x => x.ID < 1)) + return default; + var dal = new DAL.EpanetFile(); + var entity_list = Model2Entities(list.ToList()); + var bol = dal.Updates(entity_list); + if (bol) + { + UpdateCorpCache(corpIds[0], list.Select(x => x.ID).ToList()); + } + return bol; + } + + /// <summary> + /// 鏇存柊瀛樺偍缂栫爜 + /// </summary> + public bool UpdateStorageCode(long CorpID,long ID,string StorageCode,long UpdateUserID,DateTime UpdateTime) + { + var dal=new DAL.EpanetFile(); + var bol = dal.UpdateStorageCode(CorpID,ID,StorageCode,UpdateUserID,UpdateTime); + if (bol) + { + UpdateCorpCache(CorpID,ID); + } + return bol; + } + + #endregion + + #region Set + + /// <summary> + /// 璁剧疆宸ヤ綔鏂囦欢 + /// </summary> + public bool SetWorking(long CorpID, string BelongType,long BelongID,long ID,long UpdateUserID,DateTime UpdateTime) + { + var dal = new DAL.EpanetFile(); + var bol = dal.SetWorking(CorpID, BelongType, BelongID, ID, UpdateUserID, UpdateTime); + if (bol) + { + UpdateCorpCacheByBelongTypeAndBelongID(CorpID,BelongType,BelongID); + } + return bol; + } + + #endregion + + #region Exist + + /// <summary> + /// 鏍规嵁 ID 鍒ゆ柇鏄惁瀛樺湪 + /// </summary> + public bool IsExistByID(long CorpID, long ID) + { + var all = GetByCorpID(CorpID); + return all.Exists(x => x.ID == ID); + } + + #endregion + + #region Delete + + /// <summary> + /// 閫氳繃 ID 鍒犻櫎 + /// </summary> + public bool DeleteByID(long CorpID, long ID, out string Msg) + { + Msg = string.Empty; + var dal = new DAL.EpanetFile(); + var bol = dal.DeleteByID(CorpID, ID); + if (bol) + { + RemoveCorpCache(CorpID, ID); + } + return bol; + } + + #endregion + + + } +} diff --git a/Service/IStation.Service4Epanet/epanet_file/EpanetFile_Instance.cs b/Service/IStation.Service4Epanet/epanet_file/EpanetFile_Instance.cs new file mode 100644 index 0000000..68c8383 --- /dev/null +++ b/Service/IStation.Service4Epanet/epanet_file/EpanetFile_Instance.cs @@ -0,0 +1,63 @@ +锘縰sing AutoMapper; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace IStation.Service +{ + public partial class EpanetFile + { + //Entity to GetModel + private Model.EpanetFile Entity2Model(Entity.EpanetFile entity) + { + if (entity == null) + return default; + var mapper = new MapperConfiguration(cfg => cfg.CreateMap<Entity.EpanetFile, Model.EpanetFile>()).CreateMapper(); + var model = mapper.Map<Entity.EpanetFile, Model.EpanetFile>(entity); + return model; + } + + //Entities to GetModels + private List<Model.EpanetFile> Entity2Models(List<Entity.EpanetFile> entities) + { + if (entities == null || entities.Count() < 1) + return default; + var mapper = new MapperConfiguration(cfg => cfg.CreateMap<Entity.EpanetFile, Model.EpanetFile>()).CreateMapper(); + var models = mapper.Map<List<Entity.EpanetFile>, List<Model.EpanetFile>>(entities); + return models; + } + + //Model to Entity + private Entity.EpanetFile Model2Entity(Model.EpanetFile model) + { + if (model == null) + return default; + var mapper = new MapperConfiguration(cfg => cfg.CreateMap<Model.EpanetFile, Entity.EpanetFile>()).CreateMapper(); + var entity = mapper.Map<Model.EpanetFile, Entity.EpanetFile>(model); + return entity; + } + + //Models to Entities + private List<Entity.EpanetFile> Model2Entities(List<Model.EpanetFile> models) + { + if (models == null || models.Count < 1) + return default; + var mapper = new MapperConfiguration(cfg => cfg.CreateMap<Model.EpanetFile, Entity.EpanetFile>()).CreateMapper(); + var entities = mapper.Map<List<Model.EpanetFile>, List<Entity.EpanetFile>>(models); + return entities; + } + + //Model to Entity + private void Model2Entity(Model.EpanetFile model, Entity.EpanetFile entity) + { + if (model == null || entity == null) + return; + var mapper = new MapperConfiguration(cfg => cfg.CreateMap<Model.EpanetFile, Entity.EpanetFile>()).CreateMapper(); + mapper.Map(model, entity); + } + + + } +} diff --git a/Service/IStation.Service4Epanet/epanet_file/cache/EpanetFileCacheHelper.cs b/Service/IStation.Service4Epanet/epanet_file/cache/EpanetFileCacheHelper.cs new file mode 100644 index 0000000..d2c0e72 --- /dev/null +++ b/Service/IStation.Service4Epanet/epanet_file/cache/EpanetFileCacheHelper.cs @@ -0,0 +1,71 @@ +锘縰sing System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace IStation.Service +{ + /// <summary> + /// EpanetFile缂撳瓨杈呭姪绫� + /// </summary> + internal class EpanetFileCacheHelper + { + private const string _contentKey = "EpanetFileListKey"; + + private static string GetCacheKey(long CorpID) + { + var contentKey = string.Format("{0}-{1}", _contentKey, CorpID); + return CacheHelper.GetCacheKey(contentKey); + } + + /// <summary> + /// 璁剧疆缂撳瓨 + /// </summary> + public static void Set(long CorpID, List<Model.EpanetFile> list, int Minites = 30, int RandomSeconds = 0) + { + var cacheKey = GetCacheKey(CorpID); + MemoryCacheHelper.Set(cacheKey, list, Minites * 60 + RandomSeconds); + } + + /// <summary> + /// 鑾峰彇缂撳瓨 + /// </summary> + public static List<Model.EpanetFile> Get(long CorpID) + { + var cacheKey = GetCacheKey(CorpID); + return MemoryCacheHelper.Get<List<Model.EpanetFile>>(cacheKey); + } + + /// <summary> + /// 鑾峰彇璁剧疆缂撳瓨 + /// </summary> + public static List<Model.EpanetFile> GetSet(long CorpID, Func<List<Model.EpanetFile>> func, int Minites = 30, int RandomSeconds = 0) + { + var cacheKey = GetCacheKey(CorpID); + return MemoryCacheHelper.GetSet(cacheKey, func, Minites * 60 + RandomSeconds); + } + + /// <summary> + /// 绉婚櫎缂撳瓨 + /// </summary> + public static void Remove(long CorpID) + { + var cacheKey = GetCacheKey(CorpID); + MemoryCacheHelper.Remove(cacheKey); + } + + /// <summary> + /// 鍏ㄩ儴绉婚櫎 + /// </summary> + public static void RemoveAll() + { + MemoryCacheHelper.Remove((key) => + { + return key.Contains(CacheHelper.GetCacheKey(_contentKey)); + }); + } + + + } +} \ No newline at end of file diff --git a/Service/IStation.Service4Epanet/helpers/CacheHelper.cs b/Service/IStation.Service4Epanet/helpers/CacheHelper.cs new file mode 100644 index 0000000..4bcdbb9 --- /dev/null +++ b/Service/IStation.Service4Epanet/helpers/CacheHelper.cs @@ -0,0 +1,40 @@ +锘縰sing System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace IStation.Service +{ + /// <summary> + /// 缂撳瓨杈呭姪绫� + /// </summary> + internal class CacheHelper + { + private const string _cacheKeyPrefix = "*Default_Epanet_Prefix*";//缂撳瓨閿墠缂� + + /// <summary> + /// 鑾峰彇缂撳瓨閿� + /// </summary> + public static string GetCacheKey(string keyContent) + { + return string.Format("{0}_{1}", _cacheKeyPrefix, keyContent); + } + + /// <summary> + /// 娓呴櫎鍏ㄩ儴 + /// </summary> + public static void Clear() + { + MemoryCacheHelper.Remove((key) => + { + return key.StartsWith(_cacheKeyPrefix); + }); + } + + + + + + } +} diff --git a/Service/IStation.Service4Epanet/helpers/ConfigHelper.cs b/Service/IStation.Service4Epanet/helpers/ConfigHelper.cs new file mode 100644 index 0000000..269056b --- /dev/null +++ b/Service/IStation.Service4Epanet/helpers/ConfigHelper.cs @@ -0,0 +1,41 @@ +锘縰sing System; +using System.Collections.Generic; +using System.Configuration; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using IStation.Untity; + +namespace IStation.Service +{ + /// <summary> + /// 閰嶇疆杈呭姪绫� + /// </summary> + internal class ConfigHelper + { + /// <summary> + /// 缂撳瓨淇濇寔鏃堕棿 锛堝垎閽燂級 + /// </summary> + public static int CacheKeepTime + { + get + { + return Settings.MemoryCache.KeepTime; + } + } + + /// <summary> + /// 缂撳瓨闅忔満鏃堕棿 锛堢锛� + /// </summary> + public static int CacheRandomTime + { + get + { + return RandomHelper.Random(0, Settings.MemoryCache.RandomTime); + } + } + + + + } +} diff --git a/Settings/IStation.Settings/models/Paras.cs b/Settings/IStation.Settings/models/Paras.cs index b7fd9bc..9513d53 100644 --- a/Settings/IStation.Settings/models/Paras.cs +++ b/Settings/IStation.Settings/models/Paras.cs @@ -105,6 +105,11 @@ public Paras_Job Job { get; set; } /// <summary> + /// Epanet 鍙傛暟 + /// </summary> + public Paras_Epanet Epanet { get; set; } + + /// <summary> /// 宸℃鍙傛暟 /// </summary> public Paras_Inspect Inspect { get; set; } diff --git a/Settings/IStation.Settings/models/epanet/Paras_Epanet.cs b/Settings/IStation.Settings/models/epanet/Paras_Epanet.cs new file mode 100644 index 0000000..13cb8db --- /dev/null +++ b/Settings/IStation.Settings/models/epanet/Paras_Epanet.cs @@ -0,0 +1,19 @@ +锘縰sing System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace IStation +{ + /// <summary> + /// Epanet鍙傛暟 + /// </summary> + public class Paras_Epanet + { + /// <summary> + /// 鏁版嵁搴� + /// </summary> + public Paras_Epanet_DataBase DataBase { get; set; } + } +} diff --git a/Settings/IStation.Settings/models/epanet/Paras_Epanet_DataBase.cs b/Settings/IStation.Settings/models/epanet/Paras_Epanet_DataBase.cs new file mode 100644 index 0000000..c2852f5 --- /dev/null +++ b/Settings/IStation.Settings/models/epanet/Paras_Epanet_DataBase.cs @@ -0,0 +1,20 @@ +锘縰sing System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace IStation +{ + /// <summary> + /// 鏁版嵁搴� + /// </summary> + public class Paras_Epanet_DataBase + { + /// <summary> + /// 杩炴帴瀛楃涓� + /// </summary> + public string ConnectString { get; set; } + } + +} diff --git a/Settings/IStation.Settings/paras/Settings.cs b/Settings/IStation.Settings/paras/Settings.cs index 569af72..4f5f4f0 100644 --- a/Settings/IStation.Settings/paras/Settings.cs +++ b/Settings/IStation.Settings/paras/Settings.cs @@ -165,6 +165,14 @@ } /// <summary> + /// Epanet鍙傛暟 + /// </summary> + public static Paras_Epanet Epanet + { + get { return SettingsHelper.Get().Epanet; } + } + + /// <summary> /// Inspect 鍙傛暟 /// </summary> public static Paras_Inspect Inspect diff --git a/Settings/IStation.Settings/paras_settings.json b/Settings/IStation.Settings/paras_settings.json index b96c76c..c9520ad 100644 --- a/Settings/IStation.Settings/paras_settings.json +++ b/Settings/IStation.Settings/paras_settings.json @@ -166,6 +166,12 @@ } }, + "Epanet": { + "DataBase": { + "ConnectString": "PORT=5432;DATABASE=istation_epanet_test;HOST=101.133.223.111;PASSWORD=Eventech2010;USER ID=postgres;" + } + }, + "Inspect": { "DataBase": { "ConnectString": "PORT=5432;DATABASE=istation_inspect_test;HOST=101.133.223.111;PASSWORD=Eventech2010;USER ID=postgres;", -- Gitblit v1.9.3