shape上传

DataMaintenance
lgd 2025-04-17 14:48:05 +08:00
parent 040e2e9def
commit d1a5186b04
5 changed files with 1046 additions and 145 deletions

View File

@ -3,6 +3,7 @@ using System.Net;
using System.Net.Http.Headers;
using System.Text;
using System.Xml.Linq;
using Microsoft.AspNetCore.Http;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using OSGeo.GDAL;
@ -1149,4 +1150,56 @@ public class GeoUtil
obj.srs = epsgCode;
return obj;
}
}
/// <summary>
/// 更新图层样式
/// </summary>
private static async Task<bool> UpdateLayerStyleAsync(string layerName, string style)
{
// 构建请求 URL
string url = $"{GeoserverUrl}/rest/layers/{Workspace}:{layerName}";
// 构建请求体
var requestBody = new
{
layer = new
{
defaultStyle = new
{
name = style,
workspace = Workspace
}
}
};
// 将请求体序列化为 JSON
string jsonBody = Newtonsoft.Json.JsonConvert.SerializeObject(requestBody);
// 创建 HttpClient
using (HttpClient client = new HttpClient())
{
// 设置基本认证
var authHeader = Convert.ToBase64String(Encoding.ASCII.GetBytes($"{Username}:{Password}"));
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", authHeader);
// 设置请求头
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
// 发送 PUT 请求
HttpContent content = new StringContent(jsonBody, Encoding.UTF8, "application/json");
HttpResponseMessage response = await client.PutAsync(url, content);
// 检查响应状态
if (response.IsSuccessStatusCode)
{
return true; // 更新成功
}
else
{
// 输出错误信息
string errorResponse = await response.Content.ReadAsStringAsync();
Console.WriteLine($"错误响应: {errorResponse}");
return false; // 更新失败
}
}
}
}

View File

@ -10,8 +10,6 @@ namespace OpenAuth.App.Request
{
public string TableName { get; set; }
public int Id { get; set; }
public List<Dictionary<string,object>> list { get; set; }
}
}

File diff suppressed because it is too large Load Diff

View File

@ -5,6 +5,7 @@ using OpenAuth.App;
using OpenAuth.App.Request;
using OpenAuth.App.ServiceApp.LayerManagerApp;
using OpenAuth.App.ServiceApp.LayerManagerApp.Request;
using Org.BouncyCastle.Ocsp;
namespace OpenAuth.WebApi.Controllers.ServiceControllers.DataMaintenance;
@ -39,9 +40,10 @@ public class LayerController : ControllerBase
/// <param name="req"></param>
/// <returns></returns>
[HttpPost]
public async Task<Response<bool>> UploadShape(LayerReq req)
[AllowAnonymous]
public async Task<Response<bool>> UploadShape(string zipFilePath, string tableName)
{
return await _app.UploadShape(req);
return await _app.UploadShape3( zipFilePath, tableName);
}
[HttpGet]
@ -52,34 +54,73 @@ public class LayerController : ControllerBase
[HttpGet]
[AllowAnonymous]
public IActionResult TempeleteByTableName(string tablename)
public IActionResult TempeleteByTableName(string tablename,int type)
{
var res = new Response();
var excelRes = _app.TempeleteByTableName(tablename);
if (excelRes.Code == 200)
if (type ==0)
{
return File(excelRes.Result.ToArray(),
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
"数据导出" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xls");
var excelRes = _app.TempeleteByTableName(tablename,type,"","");
if (excelRes.Code == 200)
{
return File(excelRes.Result.ToArray(),
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
"数据导出" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xls");
}
else
{
res.Code = excelRes.Code;
res.Message = "导出失败";
}
}
else
if (type==1)
{
res.Code = excelRes.Code;
res.Message = "导出失败";
try
{
string shpFilePath = Path.Combine(Path.GetTempPath(), $"图斑信息{DateTime.Now:yyyyMMddHHmmss}.shp");
string shpFilePathzip = Path.Combine(Path.GetTempPath(), $"图斑信息{DateTime.Now:yyyyMMddHHmmss}.zip");
_app.TempeleteByTableName(tablename,type, shpFilePath, shpFilePathzip);
byte[] fileBytes = System.IO.File.ReadAllBytes(shpFilePathzip);
return File(fileBytes, "application/octet-stream", $"图斑信息{DateTime.Now:yyyyMMddHHmmss}.zip");
}
catch (Exception ex)
{
return StatusCode(500, $"Internal server error: {ex.Message}");
}
}
return Ok(res);
}
[HttpPost]
[AllowAnonymous]
public async Task<Response<bool>> UploadExcelAll([FromBody]UploadExcelReq req)
public async Task<Response<bool>> UploadExcelAll(string tableName, IFormFile file)
{
Response<bool> response = new Response<bool>();
try
{
response.Result = await _app.UploadExcel1(req);
response.Result = await _app.UploadExcel1(tableName, file);
}
catch (Exception ex)
{
response.Code = 500;
response.Message = ex.InnerException?.Message ?? ex.Message;
}
return response;
}
[HttpPost]
[AllowAnonymous]
public async Task<Response<bool>> UploadExcelInsert(string tableName, IFormFile file)
{
Response<bool> response = new Response<bool>();
try
{
response.Result = await _app.UploadExcel2(tableName, file);
}
catch (Exception ex)
{
@ -111,9 +152,9 @@ public class LayerController : ControllerBase
[HttpPost]
[AllowAnonymous]
public async Task<Response<bool>> AddUploadExcel([FromBody] UploadExcelReq req)
public async Task<Response<bool>> AddUploadExcel(string tableName, IFormFile file)
{
UploadExcelReq req = new UploadExcelReq { tableName = tableName, file = file };
Response<bool> response = new Response<bool>();
try
{
@ -127,4 +168,54 @@ public class LayerController : ControllerBase
return response;
}
[HttpGet]
[AllowAnonymous]
public async Task<Response<bool>> UploadSldStyle(string tablename,string styleName, string filepath)
{
Response<bool> response = new Response<bool>();
try
{
var result = await _app.uploadSldStyle(styleName,tablename, filepath);
return result;
}
catch (Exception ex)
{
response.Code = 500;
response.Message = ex.InnerException?.Message ?? ex.Message;
response.Result = false;
}
return response;
}
/// <returns></returns>
[HttpPost]
[AllowAnonymous]
public async Task<Response<Dictionary<string, object>>> UploadShape1(string zipFilePath, string tableName)
{
return await _app.UploadShape1(zipFilePath,tableName);
}
[HttpPost]
[AllowAnonymous]
public async Task<Response<bool>> UploadShape2(string zipFilePath, string tableName)
{
return await _app.UploadShape2(zipFilePath, tableName);
}
[HttpPost]
[AllowAnonymous]
public Response<bool> UpdateTableOriginalData(UpdateTableReq req)
{
Response<bool> response = new Response<bool>();
try
{
response.Result = _app.UpdateTableData1(req);
}
catch (Exception ex)
{
response.Code = 500;
response.Message = ex.InnerException?.Message ?? ex.Message;
}
return response;
}
}

View File

@ -57,7 +57,7 @@
//"AppSecret": "8f4ba2bf57c360d5b77751fc8a82701b"
},
"GeoServer": {
"GeoserverUrl": "http://192.168.10.141:8080/geoserver",
"GeoserverUrl": "http://192.168.10.163:8080/geoserver",
"JobwebUrl": "http://192.168.10.125:9023/",
"Workspace": "my_workspace",
"Username": "admin",