修改站点相关
parent
5c3a4d3bc6
commit
f70c5ef650
|
|
@ -1,11 +1,16 @@
|
|||
using DocumentFormat.OpenXml.Office2021.DocumentTasks;
|
||||
using DocumentFormat.OpenXml.Spreadsheet;
|
||||
using DocumentFormat.OpenXml.Wordprocessing;
|
||||
using Infrastructure;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Options;
|
||||
using NPOI.HSSF.UserModel;
|
||||
using NPOI.SS.Formula.Functions;
|
||||
using NPOI.SS.UserModel;
|
||||
using NPOI.XSSF.UserModel;
|
||||
using OpenAuth.App.BaseApp.Base;
|
||||
using OpenAuth.App.Common;
|
||||
using OpenAuth.App.FormModule;
|
||||
using OpenAuth.App.Interface;
|
||||
using OpenAuth.App.Response;
|
||||
using OpenAuth.App.ServiceApp.FireManagement.Response;
|
||||
|
|
@ -53,14 +58,14 @@ namespace OpenAuth.App.ServiceApp.FmFireSiteManage
|
|||
/// <param name="pageSize"></param>
|
||||
/// <param name="state"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<Response<PageInfo<List<FmSiteInfo>>>> LoadAllSite(string siteName, int pageIndex, int pageSize, int state)
|
||||
public async Task<Response<PageInfo<List<FmSiteInfo>>>> LoadAllSite(string siteName, int pageIndex, int pageSize, int? state)
|
||||
{
|
||||
var currentUser = _auth.GetCurrentUser();
|
||||
using (var db = base.UnitWork.CreateContext())
|
||||
{
|
||||
RefAsync<int> totalNumber = 0;
|
||||
var list = await db.FmSiteInfo.AsQueryable()
|
||||
.WhereIF(state != 3, (a) => a.State == state)
|
||||
.WhereIF(state != null, (a) => a.State == state)
|
||||
.WhereIF(!string.IsNullOrEmpty(siteName), (a) => a.SiteName.Contains(siteName))
|
||||
.Select((a) => new FmSiteInfo
|
||||
{
|
||||
|
|
@ -78,14 +83,54 @@ namespace OpenAuth.App.ServiceApp.FmFireSiteManage
|
|||
/// 导出所有站点
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public MemoryStream ExportSite(int state)
|
||||
public Response<MemoryStream> ExportSite(int? state)
|
||||
{
|
||||
var currentUser = _auth.GetCurrentUser();
|
||||
Response<MemoryStream> response = new Response<MemoryStream>();
|
||||
try
|
||||
{
|
||||
HSSFWorkbook workbook = new HSSFWorkbook();
|
||||
#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
|
||||
|
||||
|
||||
using (var db = base.UnitWork.CreateContext())
|
||||
{
|
||||
List<FmSiteInfo> list = new List<FmSiteInfo>();
|
||||
list = db.FmSiteInfo.AsQueryable()
|
||||
.WhereIF(state != 3, (a) => a.State == state)
|
||||
.WhereIF(state != null, (a) => a.State == state)
|
||||
.Select((a) => new FmSiteInfo
|
||||
{
|
||||
Id = a.Id.SelectAll(),
|
||||
|
|
@ -93,50 +138,69 @@ namespace OpenAuth.App.ServiceApp.FmFireSiteManage
|
|||
.OrderByDescending(a => a.CreateTime)
|
||||
.ToList();
|
||||
|
||||
//根目录
|
||||
var root = AppDomain.CurrentDomain.BaseDirectory;
|
||||
//Execl 文件
|
||||
var execlPath = "ExportFiles/ExportInterphoneInfo.xlsx";
|
||||
|
||||
using (FileStream fs = new FileStream($"{root}{execlPath}", FileMode.Open, FileAccess.Read))
|
||||
#region 创建表头
|
||||
int m = list.Count / 60000 + 1;
|
||||
for (int k = 0; k < m; k++)
|
||||
{
|
||||
var workBook = new XSSFWorkbook(fs);
|
||||
|
||||
#region
|
||||
|
||||
var sheet = workBook.GetSheetAt(0);
|
||||
|
||||
var columnWidth = 20 * 256; // 一个字符等于 256 个单位
|
||||
for (int i = 0; i < list.Count; i++)
|
||||
ISheet sheet = workbook.CreateSheet("Sheet" + k.ToString());
|
||||
IRow rowHeader = sheet.CreateRow(0);
|
||||
rowHeader.Height = 20 * 30;
|
||||
for (int i = 0; i < 5; i++)
|
||||
{
|
||||
sheet.SetColumnWidth(i, columnWidth);
|
||||
}
|
||||
var row1 = sheet.CreateRow(0);
|
||||
row1.Height = 30 * 20;
|
||||
row1.CreateCell(0).SetCellValue("站点名称");
|
||||
row1.CreateCell(1).SetCellValue("站点地址");
|
||||
row1.CreateCell(2).SetCellValue("审核状态");
|
||||
row1.CreateCell(3).SetCellValue("负责人");
|
||||
row1.CreateCell(4).SetCellValue("负责人电话");
|
||||
|
||||
for (int i = 0; i < list.Count; i++)
|
||||
{
|
||||
var num = i + 1;
|
||||
var row = sheet.CreateRow(num);
|
||||
row.Height = 30 * 20;
|
||||
row.CreateCell(0).SetCellValue(list[i].SiteName == null ? "" : list[i].SiteName);
|
||||
row.CreateCell(1).SetCellValue(list[i].SiteAddress == null ? "" : list[i].SiteAddress);
|
||||
row.CreateCell(2).SetCellValue(list[i].State == 0 ? "未审核" : (list[i].State == 1 ? "审核通过" : "审核未通过"));
|
||||
row.CreateCell(3).SetCellValue(list[i].Director == null ? "" : list[i].Director);
|
||||
row.CreateCell(4).SetCellValue(list[i].Phone == null ? "" : list[i].Phone);
|
||||
//ModuleColumn header = headers[i];
|
||||
rowHeader.CreateCell(i);
|
||||
rowHeader.Cells[i].CellStyle = style1;
|
||||
sheet.SetColumnWidth(i, 20 * 350);
|
||||
}
|
||||
rowHeader.Cells[0].SetCellValue("站点名称");
|
||||
rowHeader.Cells[1].SetCellValue("站点地址");
|
||||
rowHeader.Cells[2].SetCellValue("审核状态");
|
||||
rowHeader.Cells[3].SetCellValue("负责人");
|
||||
rowHeader.Cells[4].SetCellValue("负责人电话");
|
||||
#endregion
|
||||
MemoryStream ms = new MemoryStream();
|
||||
|
||||
workBook.Write(ms);
|
||||
return ms;
|
||||
#region 填充数据
|
||||
var val = (k + 1) * 60000;
|
||||
var num = 60000;
|
||||
if (val > list.Count)
|
||||
{
|
||||
num = list.Count - k * 60000;
|
||||
}
|
||||
for (int i = 0; i < num; i++) //循环数据
|
||||
{
|
||||
var item = list[k * 60000 + i]; //获取数据
|
||||
IRow dataRow = sheet.CreateRow(i + 1); //创建行
|
||||
for (int j = 0; j < 5; j++) //循环表头
|
||||
{
|
||||
//创建单元格
|
||||
dataRow.CreateCell(j);
|
||||
dataRow.Cells[j].CellStyle = style; //添加单元格样式
|
||||
}
|
||||
dataRow.Cells[0].SetCellValue(list[i].SiteName == null ? "" : list[i].SiteName);
|
||||
dataRow.Cells[1].SetCellValue(list[i].SiteAddress == null ? "" : list[i].SiteAddress);
|
||||
dataRow.Cells[2].SetCellValue(list[i].State == 0 ? "未审核" : (list[i].State == 1 ? "审核通过" : "审核未通过"));
|
||||
dataRow.Cells[3].SetCellValue(list[i].Director == null ? "" : list[i].Director);
|
||||
dataRow.Cells[4].SetCellValue(list[i].Phone == null ? "" : list[i].Phone);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
#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;
|
||||
}
|
||||
/// <summary>
|
||||
/// 站点审核
|
||||
|
|
@ -171,7 +235,6 @@ namespace OpenAuth.App.ServiceApp.FmFireSiteManage
|
|||
}
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 站点管理
|
||||
/// <summary>
|
||||
|
|
@ -181,7 +244,7 @@ namespace OpenAuth.App.ServiceApp.FmFireSiteManage
|
|||
/// <param name="pageIndex"></param>
|
||||
/// <param name="pageSize"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<Response<PageInfo<List<SiteUserRes>>>> LoadSiteUser(long siteId, long roleid, int pageIndex, int pageSize)
|
||||
public async Task<Response<PageInfo<List<SiteUserRes>>>> LoadSiteUser(long siteId, long? roleid, int pageIndex, int pageSize)
|
||||
{
|
||||
using (var db = base.UnitWork.CreateContext())
|
||||
{
|
||||
|
|
@ -189,7 +252,8 @@ namespace OpenAuth.App.ServiceApp.FmFireSiteManage
|
|||
var list = await db.FmSiteUser.AsQueryable()
|
||||
.LeftJoin<SysUser>((a, b) => a.SiteUserId == b.Id.ToString())
|
||||
.LeftJoin<SysUserRole>((a, b, c) => a.SiteUserId == c.UserId.ToString())
|
||||
.Where((a, b, c) => c.RoleId == roleid && a.SiteId == siteId)
|
||||
.Where((a, b, c) => a.SiteId == siteId)
|
||||
.WhereIF(roleid!=null, (a, b, c) => c.RoleId == roleid)
|
||||
.Select((a, b) => new SiteUserRes()
|
||||
{
|
||||
Id = a.Id,
|
||||
|
|
@ -214,60 +278,56 @@ namespace OpenAuth.App.ServiceApp.FmFireSiteManage
|
|||
/// <param name="pageIndex"></param>
|
||||
/// <param name="pageSize"></param>
|
||||
/// <returns></returns>
|
||||
public TableData LoadSiteAllUser(long roleid, int pageIndex, int pageSize)
|
||||
public async Task<Response<PageInfo<List<dynamic>>>> LoadSiteAllUser(long roleid, int pageIndex, int pageSize)
|
||||
{
|
||||
TableData data = new TableData();
|
||||
using (var db = base.UnitWork.CreateContext())
|
||||
{
|
||||
int totalCount = 0;
|
||||
var list = db.User.AsQueryable()
|
||||
RefAsync<int> totalNumber = 0;
|
||||
var list = await db.User.AsQueryable()
|
||||
.LeftJoin<SysUserRole>((a, r) => a.Id == r.UserId)
|
||||
.Where((a, r) => r.RoleId == roleid)
|
||||
.Select((a) => (dynamic)new
|
||||
.Select((a, r) => (dynamic)new
|
||||
{
|
||||
a.Id,
|
||||
a.Name,
|
||||
a.Account
|
||||
})
|
||||
.ToPageList(pageIndex, pageSize, ref totalCount);
|
||||
data.data = list;
|
||||
data.count = totalCount;
|
||||
data.code = 200;
|
||||
data.msg = "请求成功";
|
||||
.ToPageListAsync(pageIndex, pageSize, totalNumber);
|
||||
return new Response<PageInfo<List<dynamic>>>
|
||||
{
|
||||
Result = new PageInfo<List<dynamic>> { Items = list, Total = totalNumber }
|
||||
};
|
||||
}
|
||||
return data;
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取站点列表
|
||||
/// </summary>
|
||||
/// <param name="userId"></param>
|
||||
/// <returns></returns>
|
||||
public TableData LoadSiteByUserId(string userId, int pageIndex, int pageSize)
|
||||
public async Task<Response<PageInfo<List<dynamic>>>> LoadSiteByUserId(string userId, int pageIndex, int pageSize)
|
||||
{
|
||||
TableData data = new TableData();
|
||||
using (var db = base.UnitWork.CreateContext())
|
||||
{
|
||||
RefAsync<int> totalNumber = 0;
|
||||
//查询user的所有场地
|
||||
var siteids = db.FmSiteUser.AsQueryable().Where(a => a.SiteUserId == userId).Select(a => a.SiteId).ToList();
|
||||
var startTime = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd 00:00:00"));
|
||||
var endTime = DateTime.Now;
|
||||
int totalCount = 0;
|
||||
var list = db.FmSiteInfo.AsQueryable()
|
||||
//.LeftJoin<FmEnteringInfo>((a, b) => a.Id == b.SiteId)
|
||||
|
||||
var list = await db.FmSiteInfo.AsQueryable()
|
||||
.Where((a) => siteids.Contains(a.Id))
|
||||
//.Where((a, b) => b.InTime >= startTime && b.InTime <= endTime)
|
||||
//.GroupBy((a, b) => a.Id)
|
||||
.Select((a) => (dynamic)new
|
||||
{
|
||||
Id = a.Id.SelectAll(),
|
||||
incount = SqlFunc.Subqueryable<FmEnteringInfo>().Where(r => r.SiteId == a.Id && r.InTime >= startTime && r.InTime <= endTime).Count(),
|
||||
}).ToPageList(pageIndex, pageSize, ref totalCount);
|
||||
data.data = list;
|
||||
data.count = totalCount;
|
||||
data.code = 200;
|
||||
data.msg = "请求成功";
|
||||
}).ToPageListAsync(pageIndex, pageSize, totalNumber);
|
||||
return new Response<PageInfo<List<dynamic>>>
|
||||
{
|
||||
Result = new PageInfo<List<dynamic>> { Items = list, Total = totalNumber }
|
||||
};
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ namespace OpenAuth.Repository.Domain.FireManagement
|
|||
/// Default:
|
||||
/// Nullable:False
|
||||
/// </summary>
|
||||
[SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
|
||||
[SugarColumn(IsPrimaryKey = true)]
|
||||
public long Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -120,7 +120,7 @@ namespace OpenAuth.Repository.Domain.FireManagement
|
|||
/// <summary>
|
||||
/// 站点相关人员
|
||||
/// </summary>
|
||||
//[SugarColumn(IsIgnore = true)]
|
||||
[SugarColumn(IsIgnore = true)]
|
||||
//public List<Sugar_SiteUser> SiteUser { get; set; } = new List<Sugar_SiteUser>();
|
||||
[Navigate(NavigateType.OneToMany, nameof(FmSiteUser.SiteId))]
|
||||
public List<FmSiteUser> SiteUser { get; set; }
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ namespace OpenAuth.WebApi.Controllers.ServiceControllers.FireManagement
|
|||
/// <param name="state">状态(0-未审核,1-审核通过,2-未通过)</param>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public async Task<Response<PageInfo<List<FmSiteInfo>>>> LoadAllSite(string siteName, int pageIndex, int pageSize, int state)
|
||||
public async Task<Response<PageInfo<List<FmSiteInfo>>>> LoadAllSite(string siteName, int pageIndex, int pageSize, int? state)
|
||||
{
|
||||
Response<PageInfo<List<FmSiteInfo>>> response = new Response<PageInfo<List<FmSiteInfo>>>();
|
||||
try
|
||||
|
|
@ -53,12 +53,22 @@ namespace OpenAuth.WebApi.Controllers.ServiceControllers.FireManagement
|
|||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public IActionResult ExportSite(int state)
|
||||
public IActionResult ExportSite(int? state)
|
||||
{
|
||||
var ms = _app.ExportSite(state);
|
||||
ms.Position = 0;
|
||||
return File(ms, "application/octet-stream",
|
||||
$"站点{DateTime.Now.ToString("yyyyMMddHHmmss")}.xlsx");
|
||||
var res = new Response();
|
||||
var excelRes = _app.ExportSite(state);
|
||||
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 = "导出失败";
|
||||
}
|
||||
return Ok(res);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -93,7 +103,7 @@ namespace OpenAuth.WebApi.Controllers.ServiceControllers.FireManagement
|
|||
/// <param name="pageSize">页面大小</param>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public async Task<Response<PageInfo<List<SiteUserRes>>>> LoadSiteUser(long siteId, long roleid, int pageIndex, int pageSize)
|
||||
public async Task<Response<PageInfo<List<SiteUserRes>>>> LoadSiteUser(long siteId, long? roleid, int pageIndex, int pageSize)
|
||||
{
|
||||
Response<PageInfo<List<SiteUserRes>>> response = new Response<PageInfo<List<SiteUserRes>>>();
|
||||
try
|
||||
|
|
@ -117,9 +127,19 @@ namespace OpenAuth.WebApi.Controllers.ServiceControllers.FireManagement
|
|||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
[AllowAnonymous]
|
||||
public TableData LoadSiteAllUser(long roleid, int pageIndex, int pageSize)
|
||||
public async Task<Response<PageInfo<List<dynamic>>>> LoadSiteAllUser(long roleid, int pageIndex, int pageSize)
|
||||
{
|
||||
return _app.LoadSiteAllUser(roleid,pageIndex, pageSize);
|
||||
Response<PageInfo<List<dynamic>>> response = new Response<PageInfo<List<dynamic>>>();
|
||||
try
|
||||
{
|
||||
return await _app.LoadSiteAllUser(roleid,pageIndex, pageSize);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
response.Code = 500;
|
||||
response.Message = ex.InnerException?.Message ?? ex.Message;
|
||||
}
|
||||
return response;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -131,9 +151,19 @@ namespace OpenAuth.WebApi.Controllers.ServiceControllers.FireManagement
|
|||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
[AllowAnonymous]
|
||||
public TableData LoadSiteByUserId(string userId, int pageIndex, int pageSize)
|
||||
public async Task<Response<PageInfo<List<dynamic>>>> LoadSiteByUserId(string userId, int pageIndex, int pageSize)
|
||||
{
|
||||
return _app.LoadSiteByUserId(userId, pageIndex, pageSize);
|
||||
Response<PageInfo<List<dynamic>>> response = new Response<PageInfo<List<dynamic>>>();
|
||||
try
|
||||
{
|
||||
return await _app.LoadSiteByUserId(userId, pageIndex, pageSize);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
response.Code = 500;
|
||||
response.Message = ex.InnerException?.Message ?? ex.Message;
|
||||
}
|
||||
return response;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
|||
Loading…
Reference in New Issue