添加预案范围

DataMaintenance
洁 任 2026-01-29 11:13:58 +08:00
parent 352100f314
commit c462dad962
5 changed files with 304 additions and 4 deletions

View File

@ -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<Response<bool>> AddPreventionplan(FmPreventionplan info)
public async Task<Response<bool>> AddPreventionplan(PrePlanAddReq req)
{
using (var db = base.UnitWork.CreateContext())
{
FmPreventionplan info = req.MapTo<FmPreventionplan>();
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<bool> { Result = true, Message = "操作成功" };
}
@ -137,5 +157,108 @@ namespace OpenAuth.App.ServiceApp.FmPreventionPlanManage
}
}
}
#region 备用代码
//添加预案范围
private async Task<StringBuilder> 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
}
}

View File

@ -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; }
/// <summary>
/// Desc:预案名称
/// Default:
/// Nullable:True
/// </summary>
public string PlanName { get; set; }
/// <summary>
/// Desc:预案编号
/// Default:
/// Nullable:True
/// </summary>
public string PlanCode { get; set; }
/// <summary>
/// Desc:预案类别0总体应急预案、1专项应急预案、2部门预案
/// Default:
/// Nullable:True
/// </summary>
public int? PlanCategory { get; set; }
/// <summary>
/// Desc:行政级别(省、市、区县、乡镇)
/// Default:
/// Nullable:True
/// </summary>
public string AdmLevel { get; set; }
/// <summary>
/// Desc:预案描述
/// Default:
/// Nullable:True
/// </summary>
public string Description { get; set; }
/// <summary>
/// Desc:预案内容
/// Default:
/// Nullable:True
/// </summary>
public string Content { get; set; }
/// <summary>
/// Desc:预案状态0草稿1生效2过期
/// Default:
/// Nullable:True
/// </summary>
public int? Status { get; set; }
/// <summary>
/// Desc:预案版本
/// Default:
/// Nullable:True
/// </summary>
public string Version { get; set; }
/// <summary>
/// Desc:编制单位
/// Default:
/// Nullable:True
/// </summary>
public string WriteUnit { get; set; }
/// <summary>
/// Desc:编制时间
/// Default:
/// Nullable:True
/// </summary>
public DateTime? CreateTime { get; set; }
/// <summary>
/// Desc:创建人
/// Default:
/// Nullable:True
/// </summary>
public string CreateUser { get; set; }
/// <summary>
/// Desc:生效日期
/// Default:
/// Nullable:True
/// </summary>
public DateTime? EffectiveDate { get; set; }
/// <summary>
/// Desc:失效日期
/// Default:
/// Nullable:True
/// </summary>
public DateTime? expiry_date { get; set; }
/// <summary>
/// Desc:具体负责人的姓名
/// Default:
/// Nullable:True
/// </summary>
public string ResponsiblePerson { get; set; }
/// <summary>
/// Desc:责任人联系电话
/// Default:
/// Nullable:True
/// </summary>
public string Contact { get; set; }
/// <summary>
/// Desc:预案附件
/// Default:
/// Nullable:True
/// </summary>
public string Attachment { get; set; }
/// <summary>
/// Desc:备注
/// Default:
/// Nullable:True
/// </summary>
public string Remarks { get; set; }
/// <summary>
/// Desc:是否删除
/// Default:
/// Nullable:True
/// </summary>
public bool IsDelete { get; set; }
public string geom { get; set; }
}
}

View File

@ -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
{
/// <summary>
/// 站点信息
/// </summary>
[SugarTable("fm_siteinfo")]
public class FmPrePlanGeom
{
/// <summary>
/// Desc:Id
/// Default:
/// Nullable:False
/// </summary>
[SugarColumn(IsPrimaryKey = true)]
public string Id { get; set; }
/// <summary>
/// 预案id
/// </summary>
public string PrePlanId { get; set; }
/// <summary>
/// Desc:预案范围
/// Default:
/// Nullable:True
/// </summary>
public string geom { get; set; }
}
}

View File

@ -86,6 +86,7 @@ namespace OpenAuth.Repository
public SugarRepositiry<FmCamera> FmCamera { get; set; }
public SugarRepositiry<FmCamera_yjj> FmCamera_yjj { get; set; }
public SugarRepositiry<FmPreventionplan> FmPreventionplan { get; set; }
public SugarRepositiry<FmPrePlanGeom> FmPrePlanGeom { get; set; }
public SugarRepositiry<FmInterphonePoint> FmInterphonePoint { get; set; }
#endregion

View File

@ -72,7 +72,7 @@ namespace OpenAuth.WebApi.Controllers.ServiceControllers.FireManagement
/// <param name="info"></param>
/// <returns></returns>
[HttpPost]
public async Task<Response<bool>> AddPreventionplan(FmPreventionplan info)
public async Task<Response<bool>> AddPreventionplan(PrePlanAddReq info)
{
Response<bool> response = new();
try