diff --git a/OpenAuth.App/ServiceApp/FmPreventionPlanManage/FmPreventionPlanApp.cs b/OpenAuth.App/ServiceApp/FmPreventionPlanManage/FmPreventionPlanApp.cs index 30fadc1..de6c7e6 100644 --- a/OpenAuth.App/ServiceApp/FmPreventionPlanManage/FmPreventionPlanApp.cs +++ b/OpenAuth.App/ServiceApp/FmPreventionPlanManage/FmPreventionPlanApp.cs @@ -18,6 +18,12 @@ using OpenAuth.App.ServiceApp.FireManagement.Request; using OpenAuth.App.ServiceApp.FmPreventionPlanManage.Request; using Yitter.IdGenerator; using OpenAuth.App.Const; +using NetTopologySuite.Geometries; +using NetTopologySuite.IO; +using System.IO.Compression; +using Org.BouncyCastle.Ocsp; +using DocumentFormat.OpenXml.EMMA; +using DocumentFormat.OpenXml.Office2010.Excel; namespace OpenAuth.App.ServiceApp.FmPreventionPlanManage { @@ -103,10 +109,11 @@ namespace OpenAuth.App.ServiceApp.FmPreventionPlanManage } //添加预案 - public async Task> AddPreventionplan(FmPreventionplan info) + public async Task> AddPreventionplan(PrePlanAddReq req) { using (var db = base.UnitWork.CreateContext()) { + FmPreventionplan info = req.MapTo(); var user = _auth.GetCurrentUser().User; info.Id = Guid.NewGuid().ToString(); info.CreateTime = DateTime.Now; @@ -125,9 +132,22 @@ namespace OpenAuth.App.ServiceApp.FmPreventionPlanManage throw new Exception("预案编号已存在,请重新输入"); } - var flag=await db.FmPreventionplan.InsertAsync(info); + FmPrePlanGeom geom = new FmPrePlanGeom(); + geom.Id= Guid.NewGuid().ToString(); + geom.PrePlanId = info.Id; - if (db.Commit()&&flag) + string _wktModel = req.geom; + + geom.geom = null; + + StringBuilder geomSql = new StringBuilder(); + geomSql.AppendFormat( + $" update lasa_shpdata set \"Geom\" = st_geomfromtext('{_wktModel}',4326) where \"Id\" = '{geom.Id}'"); + var flag=await db.FmPreventionplan.InsertAsync(info); + var geomflag = await db.FmPrePlanGeom.InsertAsync(geom); + var flag1= db.Db.Ado.ExecuteCommandAsync(geomSql.ToString()); + + if (db.Commit()&&flag&&geomflag) { return new Response { Result = true, Message = "操作成功" }; } @@ -137,5 +157,108 @@ namespace OpenAuth.App.ServiceApp.FmPreventionPlanManage } } } + + + #region 备用代码 + //添加预案范围 + private async Task ReadShapefile(string zipFilePath, string Id) + { + var extractPath = zipFilePath.Substring(0, zipFilePath.LastIndexOf(".")) + "extract"; + //解压缩 + await UnZip(zipFilePath, extractPath); + var searchPattern = "*.shp"; // 设置你想要遍历的文件后缀名 + var fileName = Directory.GetFiles(extractPath, searchPattern, SearchOption.AllDirectories); + string shpFileName = fileName[0]; + // 创建一个 ShapefileDataReader 对象 + using (var reader = new ShapefileDataReader(shpFileName, GeometryFactory.Default)) + { + StringBuilder geomSql = new StringBuilder(); + while (reader.Read()) + { + // 获取几何数据 + Geometry geometry = reader.Geometry; + if (!geometry.IsValid) + { + throw new Exception("图斑未闭合,请重新整理数据"); + } + + // 如果几何数据是一个多边形(Polygon),需要转换为 MultiPolygon + MultiPolygon multiPolygon; + if (geometry is Polygon polygon) + { + // 单个Polygon转MultiPolygon + multiPolygon = new MultiPolygon(new[] { polygon }); + } + else if (geometry is MultiPolygon existingMultiPolygon) + { + // 如果已经是MultiPolygon,直接使用 + multiPolygon = existingMultiPolygon; + } + else + { + // 如果是其他类型的几何图形,可以根据需求进行处理 + throw new Exception("几何图形不是多边形或多重多边形类型"); + } + + // 将几何数据转换为 WKT 格式,并用 SRID 4326 + var geometryForWgs84 = multiPolygon.Copy(); + geometryForWgs84.SRID = 4326; + //var geometryForWgs84 = GeometryFactory.Default.WithSRID(4326).CreateGeometry(geometry); + geomSql.AppendFormat( + $" update drone_shp_data set geom = '{geometryForWgs84.AsText()}' where \"relid\" = '{Id}';"); + } + + return geomSql; + } + } + + private static async Task UnZip(string zipFilePath, string extractPath) + { + await Task.Run(() => + { + Directory.CreateDirectory(extractPath); + // 设置字符编码 + Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); + var gbk = Encoding.GetEncoding("utf-8"); + using (var archive = ZipFile.OpenRead(zipFilePath)) + { + // 列举ZIP文件中的条目 + foreach (var entry in archive.Entries) + { + var xxx = gbk.GetString(Encoding.Default.GetBytes(entry.FullName)); + Console.WriteLine(xxx); + } + + // 提取ZIP文件中的所有文件到指定目录 + + foreach (var entry in archive.Entries) + { + if (entry.Name != string.Empty) + { + // 确保完整路径存在 entry.FullName 是否可以编码 + var fixedEntryName = entry.FullName.Replace("/", ""); + var destinationPath = + System.IO.Path.GetFullPath(System.IO.Path.Combine(extractPath, fixedEntryName)); + Console.WriteLine("解压文件路径:" + destinationPath); + if (!destinationPath.StartsWith(System.IO.Path.GetFullPath(extractPath) + + System.IO.Path.DirectorySeparatorChar)) + { + throw new UnauthorizedAccessException("试图提取的文件超出了目标文件夹的路径边界。"); + } + + // 提取条目到目标路径 + entry.ExtractToFile(destinationPath, overwrite: true); + } + } + } + + // 遍历解压目录,是否有shp后缀的文件 + if (!Directory.Exists(extractPath)) + { + throw new Exception("文件解压失败"); + } + }); + } + #endregion } } diff --git a/OpenAuth.App/ServiceApp/FmPreventionPlanManage/Request/PrePlanAddReq.cs b/OpenAuth.App/ServiceApp/FmPreventionPlanManage/Request/PrePlanAddReq.cs new file mode 100644 index 0000000..6c27aac --- /dev/null +++ b/OpenAuth.App/ServiceApp/FmPreventionPlanManage/Request/PrePlanAddReq.cs @@ -0,0 +1,140 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace OpenAuth.App.ServiceApp.FmPreventionPlanManage.Request +{ + public class PrePlanAddReq + { + public string Id { get; set; } + + /// + /// Desc:预案名称 + /// Default: + /// Nullable:True + /// + public string PlanName { get; set; } + + /// + /// Desc:预案编号 + /// Default: + /// Nullable:True + /// + public string PlanCode { get; set; } + + /// + /// Desc:预案类别(0总体应急预案、1专项应急预案、2部门预案) + /// Default: + /// Nullable:True + /// + public int? PlanCategory { get; set; } + + /// + /// Desc:行政级别(省、市、区县、乡镇) + /// Default: + /// Nullable:True + /// + public string AdmLevel { get; set; } + + /// + /// Desc:预案描述 + /// Default: + /// Nullable:True + /// + public string Description { get; set; } + + /// + /// Desc:预案内容 + /// Default: + /// Nullable:True + /// + public string Content { get; set; } + + /// + /// Desc:预案状态(0草稿,1生效,2过期) + /// Default: + /// Nullable:True + /// + public int? Status { get; set; } + + /// + /// Desc:预案版本 + /// Default: + /// Nullable:True + /// + public string Version { get; set; } + + /// + /// Desc:编制单位 + /// Default: + /// Nullable:True + /// + public string WriteUnit { get; set; } + + /// + /// Desc:编制时间 + /// Default: + /// Nullable:True + /// + public DateTime? CreateTime { get; set; } + + /// + /// Desc:创建人 + /// Default: + /// Nullable:True + /// + public string CreateUser { get; set; } + + /// + /// Desc:生效日期 + /// Default: + /// Nullable:True + /// + public DateTime? EffectiveDate { get; set; } + + /// + /// Desc:失效日期 + /// Default: + /// Nullable:True + /// + public DateTime? expiry_date { get; set; } + + /// + /// Desc:具体负责人的姓名 + /// Default: + /// Nullable:True + /// + public string ResponsiblePerson { get; set; } + + /// + /// Desc:责任人联系电话 + /// Default: + /// Nullable:True + /// + public string Contact { get; set; } + + /// + /// Desc:预案附件 + /// Default: + /// Nullable:True + /// + public string Attachment { get; set; } + + /// + /// Desc:备注 + /// Default: + /// Nullable:True + /// + public string Remarks { get; set; } + + /// + /// Desc:是否删除 + /// Default: + /// Nullable:True + /// + public bool IsDelete { get; set; } + public string geom { get; set; } + } +} diff --git a/OpenAuth.Repository/Domain/FireManagement/FmPrePlanGeom.cs b/OpenAuth.Repository/Domain/FireManagement/FmPrePlanGeom.cs new file mode 100644 index 0000000..a62a15e --- /dev/null +++ b/OpenAuth.Repository/Domain/FireManagement/FmPrePlanGeom.cs @@ -0,0 +1,36 @@ +using SqlSugar; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace OpenAuth.Repository.Domain.FireManagement +{ + /// + /// 站点信息 + /// + [SugarTable("fm_siteinfo")] + public class FmPrePlanGeom + { + /// + /// Desc:Id + /// Default: + /// Nullable:False + /// + [SugarColumn(IsPrimaryKey = true)] + public string Id { get; set; } + /// + /// 预案id + /// + public string PrePlanId { get; set; } + + + /// + /// Desc:预案范围 + /// Default: + /// Nullable:True + /// + public string geom { get; set; } + } +} diff --git a/OpenAuth.Repository/SugarDbContext.cs b/OpenAuth.Repository/SugarDbContext.cs index 9011ba1..5da7711 100644 --- a/OpenAuth.Repository/SugarDbContext.cs +++ b/OpenAuth.Repository/SugarDbContext.cs @@ -86,6 +86,7 @@ namespace OpenAuth.Repository public SugarRepositiry FmCamera { get; set; } public SugarRepositiry FmCamera_yjj { get; set; } public SugarRepositiry FmPreventionplan { get; set; } + public SugarRepositiry FmPrePlanGeom { get; set; } public SugarRepositiry FmInterphonePoint { get; set; } #endregion diff --git a/OpenAuth.WebApi/Controllers/ServiceControllers/FireManagement/FmPreventionPlanController.cs b/OpenAuth.WebApi/Controllers/ServiceControllers/FireManagement/FmPreventionPlanController.cs index c0becee..052479d 100644 --- a/OpenAuth.WebApi/Controllers/ServiceControllers/FireManagement/FmPreventionPlanController.cs +++ b/OpenAuth.WebApi/Controllers/ServiceControllers/FireManagement/FmPreventionPlanController.cs @@ -72,7 +72,7 @@ namespace OpenAuth.WebApi.Controllers.ServiceControllers.FireManagement /// /// [HttpPost] - public async Task> AddPreventionplan(FmPreventionplan info) + public async Task> AddPreventionplan(PrePlanAddReq info) { Response response = new(); try