diff --git a/Infrastructure/Utilities/Excel/ExcelColumnAttribute.cs b/Infrastructure/Utilities/Excel/ExcelColumnAttribute.cs
new file mode 100644
index 0000000..fb61854
--- /dev/null
+++ b/Infrastructure/Utilities/Excel/ExcelColumnAttribute.cs
@@ -0,0 +1,14 @@
+namespace Infrastructure.Utilities.Excel;
+
+using System;
+
+[AttributeUsage(AttributeTargets.Property)]
+public class ExcelColumnAttribute : Attribute
+{
+ public string HeaderName { get; }
+
+ public ExcelColumnAttribute(string headerName)
+ {
+ HeaderName = headerName;
+ }
+}
diff --git a/Infrastructure/Utilities/Excel/ExcelExporter.cs b/Infrastructure/Utilities/Excel/ExcelExporter.cs
new file mode 100644
index 0000000..c74610b
--- /dev/null
+++ b/Infrastructure/Utilities/Excel/ExcelExporter.cs
@@ -0,0 +1,124 @@
+using System.Reflection;
+using NPOI.SS.UserModel;
+using NPOI.SS.Util;
+using NPOI.XSSF.UserModel;
+
+namespace Infrastructure.Utilities.Excel;
+
+public class ExcelExporter
+{
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ public static Response ExportToExcel(IEnumerable data, string headerTitle) where T : class
+ {
+ var workbook = new XSSFWorkbook();
+ var sheet = workbook.CreateSheet("Sheet1");
+
+ // 获取实体类的属性信息,并筛选出标记了ExcelColumnAttribute的特性
+ PropertyInfo[] properties = typeof(T).GetProperties()
+ .Where(p => p.GetCustomAttribute() != null)
+ .ToArray();
+
+ var rowIndex = 0;
+ if (!string.IsNullOrEmpty(headerTitle))
+ {
+ var headerTitleRow = sheet.CreateRow(rowIndex++);
+ sheet.AddMergedRegion(new CellRangeAddress(0, 0, 0, properties.Length - 1));
+ var cell = headerTitleRow.CreateCell(0);
+ cell.SetCellValue(headerTitle);
+ var style = workbook.CreateCellStyle();
+ var font = workbook.CreateFont();
+ font.FontName = "方正小标宋简体";
+ font.FontHeightInPoints = 36;
+ font.IsBold = true;
+ style.SetFont(font);
+ style.BorderBottom = BorderStyle.Thin;
+ style.BorderLeft = BorderStyle.Thin;
+ style.BorderRight = BorderStyle.Thin;
+ style.BorderTop = BorderStyle.Thin;
+ style.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Center;
+ style.VerticalAlignment = VerticalAlignment.Center;
+ style.WrapText = true;
+ cell.CellStyle = style;
+ }
+
+ // 写入表头
+ var headerRow = sheet.CreateRow(rowIndex++);
+ for (var i = 0; i < properties.Length; i++)
+ {
+ // 自动调节列宽
+ sheet.AutoSizeColumn(i);
+ var cell = headerRow.CreateCell(i);
+ cell.SetCellValue(properties[i].GetCustomAttribute()?.HeaderName);
+ // 应用表头样式
+ var headerStyleAttr = properties[i].GetCustomAttribute();
+ var style = workbook.CreateCellStyle();
+ if (headerStyleAttr != null)
+ {
+ var font = workbook.CreateFont();
+ font.FontName = headerStyleAttr.FontName;
+ font.FontHeightInPoints = (short)headerStyleAttr.FontSize;
+ font.IsBold = true;
+ style.SetFont(font);
+ // 填充模式
+ style.FillPattern = FillPattern.SolidForeground;
+ style.WrapText = true;
+ // 设置边框样式
+ style.BorderBottom = BorderStyle.Thin;
+ style.BorderLeft = BorderStyle.Thin;
+ style.BorderRight = BorderStyle.Thin;
+ style.BorderTop = BorderStyle.Thin;
+ style.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Center;
+ style.VerticalAlignment = VerticalAlignment.Center;
+ }
+ else
+ {
+ var font = workbook.CreateFont();
+ font.FontName = "Microsoft YaHei";
+ font.FontHeightInPoints = 12f;
+ font.IsBold = true;
+ style.SetFont(font);
+ // 填充模式
+ style.FillPattern = FillPattern.SolidForeground;
+ style.WrapText = true;
+ // 设置边框样式
+ style.BorderBottom = BorderStyle.Thin;
+ style.BorderLeft = BorderStyle.Thin;
+ style.BorderRight = BorderStyle.Thin;
+ style.BorderTop = BorderStyle.Thin;
+ style.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Center;
+ style.VerticalAlignment = VerticalAlignment.Center;
+ }
+
+ cell.CellStyle = style;
+ }
+
+ foreach (var item in data)
+ {
+ var row = sheet.CreateRow(rowIndex++);
+ for (var i = 0; i < properties.Length; i++)
+ {
+ var cell = row.CreateCell(i);
+ cell.SetCellValue(properties[i].GetValue(item)?.ToString());
+ }
+ }
+
+ var response = new Response
+ {
+ Result = new MemoryStream()
+ };
+ // MemoryStream中写入数据
+ workbook.Write(response.Result);
+ workbook.Close();
+ response.Result.Close();
+ response.Result.Dispose();
+ response.Code = 200;
+ response.Message = "获取成功";
+ return response;
+ }
+}
\ No newline at end of file
diff --git a/Infrastructure/Utilities/Excel/ExcelHeaderStyleAttribute.cs b/Infrastructure/Utilities/Excel/ExcelHeaderStyleAttribute.cs
new file mode 100644
index 0000000..3c9e6d4
--- /dev/null
+++ b/Infrastructure/Utilities/Excel/ExcelHeaderStyleAttribute.cs
@@ -0,0 +1,51 @@
+using Color = System.Drawing.Color;
+
+namespace Infrastructure.Utilities.Excel;
+// 用于Color类型
+
+// 自定义特性类,用于存储表头样式信息
+[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property, Inherited = false)]
+public class ExcelHeaderStyleAttribute : Attribute
+{
+ public string FontName { get; set; }
+ public float FontSize { get; set; }
+ public string FontColor { get; set; }
+ public bool Bold { get; set; }
+ public bool Italic { get; set; }
+ public HorizontalAlignment HorizontalAlignment { get; set; } // 注意:这里的HorizontalAlignment需要自定义或引用相关枚举
+
+
+
+
+
+
+ // 构造函数,用于初始化特性
+ public ExcelHeaderStyleAttribute(string fontName, float fontSize, string fontColor, bool bold, bool italic,
+ HorizontalAlignment horizontalAlignment)
+ {
+ FontName = fontName;
+ FontSize = fontSize;
+ FontColor = fontColor;
+ Bold = bold;
+ Italic = italic;
+ HorizontalAlignment = horizontalAlignment;
+ }
+
+ // 为了方便,可以提供一个简化的构造函数
+ public ExcelHeaderStyleAttribute() : this("Microsoft YaHei", 12f, "black", false, false, HorizontalAlignment.General)
+ {
+ }
+}
+
+// 自定义的HorizontalAlignment枚举(如果未从其他库引用)
+public enum HorizontalAlignment
+{
+ General,
+ Left,
+ Center,
+ Right,
+ Fill,
+ Justify,
+ CenterContinuous,
+ Distributed
+}
\ No newline at end of file
diff --git a/OpenAuth.App/ServiceApp/DroneSsnydManage/DroneSsnyApp.cs b/OpenAuth.App/ServiceApp/DroneSsnydManage/DroneSsnyApp.cs
index aa14970..9588f58 100644
--- a/OpenAuth.App/ServiceApp/DroneSsnydManage/DroneSsnyApp.cs
+++ b/OpenAuth.App/ServiceApp/DroneSsnydManage/DroneSsnyApp.cs
@@ -1,13 +1,11 @@
using Infrastructure;
using OpenAuth.App.BaseApp.Base;
using OpenAuth.App.Interface;
+using OpenAuth.App.ServiceApp.DroneSsnydManage.Export;
using OpenAuth.App.ServiceApp.DroneSsnydManage.Request;
using OpenAuth.Repository;
using OpenAuth.Repository.Domain;
using SqlSugar;
-using Infrastructure;
-using DocumentFormat.OpenXml.Spreadsheet;
-using NPOI.SS.Formula.Functions;
namespace OpenAuth.App.ServiceApp.DroneSsnydManage
{
@@ -24,18 +22,19 @@ namespace OpenAuth.App.ServiceApp.DroneSsnydManage
///
///
///
- public PageInfo> TimeoutWarning(string xiangmumc, string countyid, string streetid, int pageIndex, int pageSize)
+ public PageInfo> TimeoutWarning(string xiangmumc, string countyid, string streetid,
+ int pageIndex, int pageSize)
{
int totalCount = 0;
var endTime = DateTime.Now.AddMonths(2);
var list = base.Repository.AsQueryable()
- .WhereIF(!string.IsNullOrEmpty(xiangmumc),a=>a.xiangmu_name.Contains(xiangmumc))
- .WhereIF(!string.IsNullOrEmpty(countyid),a=>a.countyid==countyid)
- .WhereIF(!string.IsNullOrEmpty(streetid),a=>a.streetid==streetid)
- .Where(a => a.end_time <= endTime&&a.end_time>DateTime.Now)
- .OrderBy(a => a.end_time, OrderByType.Desc)
- .ToPageList(pageIndex, pageSize, ref totalCount);
+ .WhereIF(!string.IsNullOrEmpty(xiangmumc), a => a.xiangmu_name.Contains(xiangmumc))
+ .WhereIF(!string.IsNullOrEmpty(countyid), a => a.countyid == countyid)
+ .WhereIF(!string.IsNullOrEmpty(streetid), a => a.streetid == streetid)
+ .Where(a => a.end_time <= endTime && a.end_time > DateTime.Now)
+ .OrderBy(a => a.end_time, OrderByType.Desc)
+ .ToPageList(pageIndex, pageSize, ref totalCount);
return new PageInfo>
{
@@ -50,18 +49,19 @@ namespace OpenAuth.App.ServiceApp.DroneSsnydManage
///
///
///
- public PageInfo> TimeOutAlarmList(string xiangmumc, string countyid, string streetid, int pageIndex, int pageSize)
+ public PageInfo> TimeOutAlarmList(string xiangmumc, string countyid, string streetid,
+ int pageIndex, int pageSize)
{
int totalCount = 0;
var endTime = DateTime.Now;
var list = base.Repository.AsQueryable()
- .WhereIF(!string.IsNullOrEmpty(xiangmumc), a => a.xiangmu_name.Contains(xiangmumc))
- .WhereIF(!string.IsNullOrEmpty(countyid), a => a.countyid == countyid)
- .WhereIF(!string.IsNullOrEmpty(streetid), a => a.streetid == streetid)
- .Where(a => a.end_time a.end_time, OrderByType.Desc)
- .ToPageList(pageIndex, pageSize, ref totalCount);
+ .WhereIF(!string.IsNullOrEmpty(xiangmumc), a => a.xiangmu_name.Contains(xiangmumc))
+ .WhereIF(!string.IsNullOrEmpty(countyid), a => a.countyid == countyid)
+ .WhereIF(!string.IsNullOrEmpty(streetid), a => a.streetid == streetid)
+ .Where(a => a.end_time < endTime)
+ .OrderBy(a => a.end_time, OrderByType.Desc)
+ .ToPageList(pageIndex, pageSize, ref totalCount);
return new PageInfo>
{
@@ -112,5 +112,63 @@ namespace OpenAuth.App.ServiceApp.DroneSsnydManage
Total = totalCount
};
}
+
+ public List HistoryProjectList(DroneSnnyAppReq req)
+ {
+ var list = Repository.AsQueryable()
+ .Where(a => a.handle_status_id == 99)
+ .WhereIF(!string.IsNullOrEmpty(req.xiangmu_no), a => a.xiangmu_no.Contains(req.xiangmu_no))
+ .WhereIF(!string.IsNullOrEmpty(req.xiangmumc), a => a.xiangmumc.Contains(req.xiangmumc))
+ .Select(
+ a => new DroneSsnydExport()
+ {
+ xiangmu_no = a.xiangmu_no,
+ xiangmu_name = a.xiangmu_name,
+ streetname = a.streetname,
+ communityname = a.communityname,
+ quanliren = a.quanliren,
+ xingzhengquhua = a.xingzhengquhua,
+ beian_no = a.beian_no,
+ start_time = a.start_time,
+ end_time = a.end_time,
+ xiangmu_yt = a.xiangmu_yt,
+ shengchan_area = a.shengchan_area,
+ fuzhu_area = a.fuzhu_area,
+ shenqing_area = a.shenqing_area,
+ handle_status_name = a.handle_status_name,
+ xiafatime = a.xiafatime
+ })
+ .ToList();
+ return list;
+ }
+
+ public List ProjectChangeExport(DroneSnnyAppReq req)
+ {
+ var list = Repository.AsQueryable()
+ .Where(a => a.handle_status_id != 99)
+ .WhereIF(!string.IsNullOrEmpty(req.xiangmu_no), a => a.xiangmu_no.Contains(req.xiangmu_no))
+ .WhereIF(!string.IsNullOrEmpty(req.xiangmumc), a => a.xiangmumc.Contains(req.xiangmumc))
+ .Select(
+ a => new DroneSsnydExport()
+ {
+ xiangmu_no = a.xiangmu_no,
+ xiangmu_name = a.xiangmu_name,
+ streetname = a.streetname,
+ communityname = a.communityname,
+ quanliren = a.quanliren,
+ xingzhengquhua = a.xingzhengquhua,
+ beian_no = a.beian_no,
+ start_time = a.start_time,
+ end_time = a.end_time,
+ xiangmu_yt = a.xiangmu_yt,
+ shengchan_area = a.shengchan_area,
+ fuzhu_area = a.fuzhu_area,
+ shenqing_area = a.shenqing_area,
+ handle_status_name = a.handle_status_name,
+ xiafatime = a.xiafatime
+ })
+ .ToList();
+ return list;
+ }
}
}
\ No newline at end of file
diff --git a/OpenAuth.App/ServiceApp/DroneSsnydManage/Export/DroneSsnydExport.cs b/OpenAuth.App/ServiceApp/DroneSsnydManage/Export/DroneSsnydExport.cs
new file mode 100644
index 0000000..3db6521
--- /dev/null
+++ b/OpenAuth.App/ServiceApp/DroneSsnydManage/Export/DroneSsnydExport.cs
@@ -0,0 +1,105 @@
+using Infrastructure.Utilities.Excel;
+
+namespace OpenAuth.App.ServiceApp.DroneSsnydManage.Export;
+
+///
+///设施农用地主表
+///
+[ExcelHeaderStyle]
+public class DroneSsnydExport
+{
+ ///
+ /// 项目编号
+ ///
+ [ExcelColumn("项目编号")]
+ public string xiangmu_no { get; set; }
+
+ ///
+ /// 项目名称
+ ///
+ [ExcelColumn("项目名称")]
+ public string xiangmu_name { get; set; }
+
+ ///
+ /// 镇街道
+ ///
+ [ExcelColumn("多镇")]
+ public string streetname { get; set; }
+
+ ///
+ /// 村庄
+ ///
+
+ [ExcelColumn("村庄")]
+ public string communityname { get; set; }
+
+ ///
+ /// 权利人
+ ///
+ [ExcelColumn("权利人")]
+ public string quanliren { get; set; }
+
+ ///
+ /// 行政区划
+ ///
+ [ExcelColumn("行政区划")]
+ public string xingzhengquhua { get; set; }
+
+ ///
+ /// 备案编号
+ ///
+ [ExcelColumn("备案编号")]
+ public string beian_no { get; set; }
+
+ ///
+ /// 开始时间
+ ///
+ [ExcelColumn("开始时间")]
+ public DateTime? start_time { get; set; }
+
+ ///
+ /// 结束时间
+ ///
+ [ExcelColumn("结束时间")]
+ public DateTime? end_time { get; set; }
+
+ ///
+ /// 项目当前用途
+ ///
+ [ExcelColumn("项目当前用途")]
+ public string xiangmu_yt { get; set; }
+
+ ///
+ /// 设施农业申请用地面积(公顷)
+ ///
+ [ExcelColumn("设施农业申请用地面积(公顷)")]
+ public decimal? shenqing_area { get; set; }
+
+ ///
+ /// 生产设施用地(公顷)
+ ///
+ ///
+ ///
+ [ExcelColumn("生产设施用地(公顷)")]
+ public decimal? shengchan_area { get; set; }
+
+ ///
+ /// 辅助设施用地(公顷)
+ ///
+ ///
+ ///
+ [ExcelColumn("辅助设施用地(公顷)")]
+ public decimal? fuzhu_area { get; set; }
+
+ ///
+ /// 下发时间
+ ///
+ [ExcelColumn("下发时间")]
+ public DateTime? xiafatime { get; set; }
+
+ ///
+ /// 项目状态
+ ///
+ [ExcelColumn("项目状态")]
+ public string handle_status_name { get; set; }
+}
\ No newline at end of file
diff --git a/OpenAuth.App/ServiceApp/DroneSsnydManage/Request/DroneSnnyAppReq.cs b/OpenAuth.App/ServiceApp/DroneSsnydManage/Request/DroneSnnyAppReq.cs
new file mode 100644
index 0000000..f1ee84d
--- /dev/null
+++ b/OpenAuth.App/ServiceApp/DroneSsnydManage/Request/DroneSnnyAppReq.cs
@@ -0,0 +1,15 @@
+using OpenAuth.App.Request;
+
+namespace OpenAuth.App.ServiceApp.DroneSsnydManage.Request;
+
+public class DroneSnnyAppReq
+{
+ ///
+ /// 项目名称
+ ///
+ public string xiangmumc { get; set; }
+ ///
+ /// 项目编号
+ ///
+ public string xiangmu_no { get; set; }
+}
diff --git a/OpenAuth.WebApi/Controllers/ServiceControllers/DroneSsnyController.cs b/OpenAuth.WebApi/Controllers/ServiceControllers/DroneSsnyController.cs
index 404952a..3f0de8c 100644
--- a/OpenAuth.WebApi/Controllers/ServiceControllers/DroneSsnyController.cs
+++ b/OpenAuth.WebApi/Controllers/ServiceControllers/DroneSsnyController.cs
@@ -1,4 +1,5 @@
using Infrastructure;
+using Infrastructure.Utilities.Excel;
using Microsoft.AspNetCore.Mvc;
using OpenAuth.App.ServiceApp.DroneSsnydManage;
using OpenAuth.App.ServiceApp.DroneSsnydManage.Request;
@@ -30,12 +31,13 @@ namespace OpenAuth.WebApi.Controllers.ServiceControllers
///
///
[HttpGet]
- public Response>> TimeoutWarning(string xiangmumc, string countyid, string streetid, int page, int limit)
+ public Response>> TimeoutWarning(string xiangmumc, string countyid, string streetid,
+ int page, int limit)
{
var response = new Response>>();
try
{
- response.Result = droneSsnyApp.TimeoutWarning(xiangmumc, countyid, streetid,page, limit);
+ response.Result = droneSsnyApp.TimeoutWarning(xiangmumc, countyid, streetid, page, limit);
}
catch (Exception ex)
{
@@ -56,7 +58,8 @@ namespace OpenAuth.WebApi.Controllers.ServiceControllers
///
///
[HttpGet]
- public Response>> TimeOutAlarmList(string xiangmumc, string countyid,string streetid,int page, int limit)
+ public Response>> TimeOutAlarmList(string xiangmumc, string countyid, string streetid,
+ int page, int limit)
{
var response = new Response>>();
try
@@ -71,7 +74,7 @@ namespace OpenAuth.WebApi.Controllers.ServiceControllers
return response;
}
-
+
///
/// 历史项目
///
@@ -115,5 +118,35 @@ namespace OpenAuth.WebApi.Controllers.ServiceControllers
return response;
}
+ // todo 项目列表
+
+ ///
+ /// 历史项目导出
+ ///
+ ///
+ ///
+ [HttpGet]
+ public IActionResult HistoryProjectExport([FromQuery] DroneSnnyAppReq req)
+ {
+ var data = droneSsnyApp.HistoryProjectList(req);
+ var x = ExcelExporter.ExportToExcel(data, "历史项目");
+ return File(x.Result.ToArray(),
+ "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
+ "历史项目导出" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xlsx");
+ }
+ ///
+ /// 项目变更导出
+ ///
+ ///
+ ///
+ [HttpGet]
+ public IActionResult ProjectChangeExport([FromQuery] DroneSnnyAppReq req)
+ {
+ var data = droneSsnyApp.ProjectChangeExport(req);
+ var x = ExcelExporter.ExportToExcel(data, "项目变更");
+ return File(x.Result.ToArray(),
+ "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
+ "项目变更导出" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xlsx");
+ }
}
}
\ No newline at end of file