diff --git a/Infrastructure/Helpers/Excel/ExcelHelper.cs b/Infrastructure/Helpers/Excel/ExcelHelper.cs index 21a2ff8..5bcc945 100644 --- a/Infrastructure/Helpers/Excel/ExcelHelper.cs +++ b/Infrastructure/Helpers/Excel/ExcelHelper.cs @@ -501,5 +501,7 @@ namespace Infrastructure.Helpers.Excel } #endregion + + } } diff --git a/OpenAuth.App/ServiceApp/DroneSsnydManage/DroneSsnyApp.cs b/OpenAuth.App/ServiceApp/DroneSsnydManage/DroneSsnyApp.cs index 9588f58..1468d6b 100644 --- a/OpenAuth.App/ServiceApp/DroneSsnydManage/DroneSsnyApp.cs +++ b/OpenAuth.App/ServiceApp/DroneSsnydManage/DroneSsnyApp.cs @@ -6,6 +6,12 @@ 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; +using NPOI.HSSF.UserModel; +using NPOI.SS.UserModel; +using Newtonsoft.Json.Linq; namespace OpenAuth.App.ServiceApp.DroneSsnydManage { @@ -29,12 +35,12 @@ namespace OpenAuth.App.ServiceApp.DroneSsnydManage 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> { @@ -43,6 +49,8 @@ namespace OpenAuth.App.ServiceApp.DroneSsnydManage }; } + + /// /// 超期报警 /// @@ -56,12 +64,12 @@ namespace OpenAuth.App.ServiceApp.DroneSsnydManage 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 < endTime) - .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) + .OrderBy(a => a.end_time, OrderByType.Desc) + .ToPageList(pageIndex, pageSize, ref totalCount); return new PageInfo> { @@ -170,5 +178,223 @@ namespace OpenAuth.App.ServiceApp.DroneSsnydManage .ToList(); return list; } + + + #region 导出 + //超期预警 + public List TimeoutWarningExport(string xiangmumc, string countyid, string streetid) + { + 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) + .ToList(); + + return list; + } + + /// + /// 超期报警 + /// + /// + /// + /// + public List TimeOutAlarmExport(string xiangmumc, string countyid, string streetid) + { + 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 < endTime) + .OrderBy(a => a.end_time, OrderByType.Desc) + .ToList(); + + return list; + } + /// + /// 导出 + /// + /// + /// + /// + public Response ListToExcel(List list, List headers) + { + Response response = new Response(); + try + { + HSSFWorkbook workbook = new HSSFWorkbook(); + ISheet sheet = workbook.CreateSheet(); + + #region 内容样式 + + IFont font1 = workbook.CreateFont(); //创建一个字体样式对象 + font1.FontName = "Microsoft YaHei"; //和excel里面的字体对应 + //font1.Boldweight = short.MaxValue;//字体加粗 + font1.FontHeightInPoints = 12; //字体大小 + ICellStyle style = workbook.CreateCellStyle(); //创建样式对象 + 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.SetFont(font1); //将字体样式赋给样式对象 + style.WrapText = true; + + #endregion + + #region 标题样式 + + IFont font = workbook.CreateFont(); //创建一个字体样式对象 + font.FontName = "Microsoft YaHei"; //和excel里面的字体对应 + font.Boldweight = (short)FontBoldWeight.Bold; //字体加粗 + font.FontHeightInPoints = 12; //字体大小 + ICellStyle style1 = workbook.CreateCellStyle(); //创建样式对象 + style1.BorderBottom = BorderStyle.Thin; + style1.BorderLeft = BorderStyle.Thin; + style1.BorderRight = BorderStyle.Thin; + style1.BorderTop = BorderStyle.Thin; + style1.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Center; + style1.VerticalAlignment = VerticalAlignment.Center; + style1.SetFont(font); //将字体样式赋给样式对象 + + #endregion + + #region 创建表头 + + IRow rowHeader = sheet.CreateRow(0); + rowHeader.Height = 20 * 30; + for (int i = 0; i < headers.Count; i++) + { + var header = headers[i]; + rowHeader.CreateCell(i); + rowHeader.Cells[i].CellStyle = style1; + rowHeader.Cells[i].SetCellValue(header); + if (i == 0) + { + sheet.SetColumnWidth(0, 20 * 200); + } + else + { + sheet.SetColumnWidth(i, 20 * 350); + } + + } + + #endregion + + #region 填充数据 + + for (int i = 0; i < list.Count; i++) //循环数据 + { + var item = list[i]; + IRow dataRow = sheet.CreateRow(i + 1); + //dataRow.Height = 20 * 20; + var type = item.GetType(); + var props = type.GetProperties(); + for (int j = 0; j < headers.Count; j++) + { + dataRow.CreateCell(j); + dataRow.Cells[j].CellStyle = style; + } + dataRow.Cells[0].SetCellValue(item.xiangmu_no); + dataRow.Cells[1].SetCellValue(item.xiangmu_name); + dataRow.Cells[2].SetCellValue(item.streetname); + dataRow.Cells[3].SetCellValue(item.communityname); + dataRow.Cells[4].SetCellValue(item.quanliren); + dataRow.Cells[5].SetCellValue(item.xingzhengquhua); + dataRow.Cells[6].SetCellValue(item.beian_no); + dataRow.Cells[7].SetCellValue(item.start_time.ToString()); + dataRow.Cells[8].SetCellValue(item.end_time.ToString()); + dataRow.Cells[9].SetCellValue(item.xiangmu_yt); + if (item.shenqing_area != null) + { + dataRow.Cells[10].SetCellValue(item.shenqing_area.ToString()); + } + else + { + dataRow.Cells[10].SetCellValue("0.00"); + } + if (item.shengchan_area != null) + { + dataRow.Cells[11].SetCellValue(item.shenqing_area.ToString()); + } + else + { + dataRow.Cells[11].SetCellValue("0.00"); + } + if (item.fuzhu_area != null) + { + dataRow.Cells[12].SetCellValue(item.fuzhu_area.ToString()); + } + else + { + dataRow.Cells[12].SetCellValue("0.00"); + } + + dataRow.Cells[13].SetCellValue(item.xiafatime.ToString()); + + if (item.handle_status_id != null) + { + StatusType status = (StatusType)item.handle_status_id; + dataRow.Cells[14].SetCellValue(status.ToString()); + } + else + { + dataRow.Cells[14].SetCellValue("--"); + } + } + + #endregion + + response.Result = new MemoryStream(); + + workbook.Write(response.Result); + workbook = null; + response.Result.Close(); + response.Result.Dispose(); + response.Code = 200; + response.Message = "获取成功"; + } + catch (Exception ex) + { + response.Code = 500; + response.Message = ex.Message; + } + + return response; + } + #endregion + + #region 项目列表 + /// + /// 到期预警 + /// + /// + /// + /// + public PageInfo> GetDronssnydList(string xiangmumc, string countyid, string streetid, int pageIndex, int pageSize) + { + int totalCount = 0; + 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) + .OrderBy(a => a.end_time, OrderByType.Desc) + .ToPageList(pageIndex, pageSize, ref totalCount); + + return new PageInfo> + { + Items = list, + Total = totalCount + }; + } + #endregion } } \ No newline at end of file diff --git a/OpenAuth.App/ServiceApp/DroneSsnydManage/Request/StatusType.cs b/OpenAuth.App/ServiceApp/DroneSsnydManage/Request/StatusType.cs new file mode 100644 index 0000000..b7613a4 --- /dev/null +++ b/OpenAuth.App/ServiceApp/DroneSsnydManage/Request/StatusType.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace OpenAuth.App.ServiceApp.DroneSsnydManage.Request +{ + public enum StatusType + { + /// + /// 待接收 + /// + [Description("待接收")] + 待接收 = 0, + /// + /// 待填报 + /// + [Description("待填报")] + 待填报 = 1, + /// + /// 填报县级审核 + /// + [Description("填报县级审核")] + 填报县级审核 = 2, + /// + /// 填报市级审核 + /// + [Description("填报市级审核")] + 填报市级审核 = 3, + /// + /// 待整改 + /// + [Description("待整改")] + 待整改 = 4, + /// + /// 整改县级审核 + /// + [Description("整改县级审核")] + 整改县级审核 = 5, + /// + /// 整改市级审核 + /// + [Description("整改市级审核")] + 整改市级审核 = 6, + /// + /// 已归档 + /// + [Description("已归档")] + 已归档 = 7, + } +} diff --git a/OpenAuth.App/ServiceApp/DroneSsnydManage/Request/TimeOutReq.cs b/OpenAuth.App/ServiceApp/DroneSsnydManage/Request/TimeOutReq.cs new file mode 100644 index 0000000..8e1a6d0 --- /dev/null +++ b/OpenAuth.App/ServiceApp/DroneSsnydManage/Request/TimeOutReq.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace OpenAuth.App.ServiceApp.DroneSsnydManage.Request +{ + public class TimeOutReq + { + public string xiangmumc { get; set; } + public string countyid { get; set; } + public string streetid { get; set; } + } +} diff --git a/OpenAuth.WebApi/Controllers/ServiceControllers/DroneSsnyController.cs b/OpenAuth.WebApi/Controllers/ServiceControllers/DroneSsnyController.cs index 3f0de8c..9831d97 100644 --- a/OpenAuth.WebApi/Controllers/ServiceControllers/DroneSsnyController.cs +++ b/OpenAuth.WebApi/Controllers/ServiceControllers/DroneSsnyController.cs @@ -1,6 +1,11 @@ -using Infrastructure; +using DocumentFormat.OpenXml.Math; +using DocumentFormat.OpenXml.Spreadsheet; +using Infrastructure; using Infrastructure.Utilities.Excel; +using Infrastructure.Helpers.Excel; +using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; +using NPOI.SS.Formula.Functions; using OpenAuth.App.ServiceApp.DroneSsnydManage; using OpenAuth.App.ServiceApp.DroneSsnydManage.Request; using OpenAuth.Repository.Domain; @@ -31,13 +36,12 @@ 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) { @@ -58,8 +62,7 @@ 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 @@ -74,7 +77,7 @@ namespace OpenAuth.WebApi.Controllers.ServiceControllers return response; } - + /// /// 历史项目 /// @@ -148,5 +151,108 @@ namespace OpenAuth.WebApi.Controllers.ServiceControllers "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "项目变更导出" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xlsx"); } + + #region 预警报警导出 + /// + /// 超期预警数据导出 + /// + /// + /// + [HttpPost] + public IActionResult TimeoutWarningExport([FromQuery] TimeOutReq import) + { + var data = new Response(); + List headers = null; + headers = new List { "项目编号", "项目名称", "乡镇", "村庄", "权利人", "行政区划", "备案编号", "项目开始时间", "项目结束时间", "项目当前用途", "设施农业申请用地面积", "生产设施用地", "辅助设施用地","下发时间","项目状态"}; + var response = droneSsnyApp.TimeoutWarningExport(import.xiangmumc, import.countyid, import.streetid); + if (response.Count > 0) + { + var excelRes = droneSsnyApp.ListToExcel(response, headers); + if (excelRes.Code == 200) + { + return File(excelRes.Result.ToArray(), + "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", + "超期预警" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xls"); + } + else + { + data.Code = excelRes.Code; + data.Message = "导出失败"; + } + } + else + { + data.Code = 300; + data.Message = "暂无数据"; + } + return Ok(data); + } + + + /// + /// 超期报警数据导出 + /// + /// + /// + [HttpPost] + public IActionResult TimeoutAlarmExport([FromQuery] TimeOutReq import) + { + var data = new Response(); + List headers = null; + headers = new List { "项目编号", "项目名称", "乡镇", "村庄", "权利人", "行政区划", "备案编号", "项目开始时间", "项目结束时间", "项目当前用途", "设施农业申请用地面积", "生产设施用地", "辅助设施用地", "下发时间", "项目状态" }; + var response = droneSsnyApp.TimeOutAlarmExport(import.xiangmumc, import.countyid, import.streetid); + if (response.Count > 0) + { + var excelRes = droneSsnyApp.ListToExcel(response, headers); + if (excelRes.Code == 200) + { + return File(excelRes.Result.ToArray(), + "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", + "超期报警" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xls"); + } + else + { + data.Code = excelRes.Code; + data.Message = "导出失败"; + } + } + else + { + data.Code = 300; + data.Message = "暂无数据"; + } + return Ok(data); + } + + #endregion + + #region 项目列表 + /// + /// 项目列表 + /// + /// 项目名称 + /// 县 + /// 镇 + /// + /// + /// + [HttpGet] + [AllowAnonymous] + public Response>> GetDronssnydList(string xiangmumc, string countyid, string streetid, int page, int limit) + { + var response = new Response>>(); + try + { + response.Result = droneSsnyApp.GetDronssnydList(xiangmumc, countyid, streetid, page, limit); + } + catch (Exception ex) + { + response.Code = 500; + response.Message = ex.InnerException?.Message ?? ex.Message; + } + + return response; + } + #endregion } } \ No newline at end of file