using DocumentFormat.OpenXml.Wordprocessing; using Infrastructure; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; 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; /// /// 图层 /// [Route("api/[controller]/[action]")] [ApiController] public class LayerController : ControllerBase { private readonly LayerApp _app; public LayerController(LayerApp layerApp) { _app = layerApp; } /// /// excel 上传 /// /// /// [HttpPost] public async Task> UploadExcel(LayerReq req) { return await _app.UploadExcel(req); } /// /// shape文件上传 /// /// /// [HttpPost] [AllowAnonymous] [RequestSizeLimit(214748364800)] public async Task> UploadShape(string zipFilePath, string tableName) { return await _app.UploadShape3( zipFilePath, tableName); } [HttpGet] [AllowAnonymous] public Response> TableDataByTableName(string tablename,string type,string keyword,string keyvalue,int page=1,int limit = 10) { return _app.TableDataByTableName(tablename,type, keyword,keyvalue, page,limit); } [HttpGet] [AllowAnonymous] public IActionResult TempeleteByTableName(string tablename,int type) { var res = new Response(); if (type ==0) { 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 = "导出失败"; } } if (type==1) { 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] [RequestSizeLimit(214748364800)] public async Task> UploadExcelAll(string tableName, IFormFile file) { Response response = new Response(); try { response.Result = await _app.UploadExcel1(tableName, file); return response; } catch (Exception ex) { response.Code = 500; response.Message = ex.InnerException?.Message ?? ex.Message; return response; } } [HttpPost] [AllowAnonymous] [RequestSizeLimit(214748364800)] public async Task>> UploadExcelInsert(string tableName, IFormFile file) { return await _app.UploadExcel2(tableName, file); } [HttpPost] [AllowAnonymous] public Response UpdateTableData(UpdateTableReq req) { Response response = new Response(); try { response.Result = _app.UpdateTableData(req); } catch (Exception ex) { response.Code = 500; response.Message = ex.InnerException?.Message ?? ex.Message; } return response; } [HttpPost] [AllowAnonymous] public Response AddTableData(UpdateTableReq req) { Response response = new Response(); try { response.Result = _app.AddTableData(req); } catch (Exception ex) { response.Code = 500; response.Message = ex.InnerException?.Message ?? ex.Message; } return response; } [HttpPost] [AllowAnonymous] [RequestSizeLimit(214748364800)] public async Task>> AddUploadExcel(string tableName, IFormFile file) { UploadExcelReq req = new UploadExcelReq { tableName = tableName, file = file }; return await _app.AddUploadExcel(req); } [HttpGet] [AllowAnonymous] public async Task> GetSldFilePath(string tablename) { Response response = new Response(); try { var result = await _app.GetSldFilePath( tablename); return result; } catch (Exception ex) { response.Code = 500; response.Message = ex.InnerException?.Message ?? ex.Message; response.Result = null; } return response; } [HttpGet] [AllowAnonymous] public async Task> UploadSldStyle(string tablename,string styleName, string filepath,string id) { Response response = new Response(); try { var result = await _app.uploadSldStyle(styleName,tablename, filepath,id); return result; } catch (Exception ex) { response.Code = 500; response.Message = ex.InnerException?.Message ?? ex.Message; response.Result = false; } return response; } /// [HttpPost] [AllowAnonymous] [RequestSizeLimit(214748364800)] public async Task>> UploadShape1(string zipFilePath, string tableName) { return await _app.UploadShape1(zipFilePath,tableName); } [HttpPost] [AllowAnonymous] public async Task>> UploadShape2(string zipFilePath, string tableName) { return await _app.UploadShape2(zipFilePath, tableName); } [HttpPost] [AllowAnonymous] public Response UpdateTableOriginalData(UpdateTableReq req) { Response response = new Response(); try { response.Result = _app.UpdateTableData1(req); } catch (Exception ex) { response.Code = 500; response.Message = ex.InnerException?.Message ?? ex.Message; } return response; } }