新增加系统表导出功能
This commit is contained in:
@@ -1,9 +1,14 @@
|
||||
using Infrastructure;
|
||||
using Infrastructure.Model;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Serialization;
|
||||
using OfficeOpenXml;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using ZR.Admin.WebApi.Filters;
|
||||
|
||||
namespace ZR.Admin.WebApi.Controllers
|
||||
@@ -99,5 +104,33 @@ namespace ZR.Admin.WebApi.Controllers
|
||||
{
|
||||
return ToResponse(GetApiResult(resultCode, msg));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 导出Excel
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="list"></param>
|
||||
/// <param name="sheetName"></param>
|
||||
/// <param name="fileName"></param>
|
||||
protected string ExportExcel<T>(List<T> list, string sheetName, string fileName)
|
||||
{
|
||||
IWebHostEnvironment webHostEnvironment = (IWebHostEnvironment)App.ServiceProvider.GetService(typeof(IWebHostEnvironment));
|
||||
string sFileName = $"{fileName}{DateTime.Now:yyyyMMddHHmmss}.xlsx";
|
||||
string newFileName = Path.Combine(webHostEnvironment.WebRootPath, "export", sFileName);
|
||||
//调试模式需要加上
|
||||
ExcelPackage.LicenseContext = LicenseContext.NonCommercial;
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(newFileName));
|
||||
using (ExcelPackage package = new ExcelPackage(new FileInfo(newFileName)))
|
||||
{
|
||||
// 添加worksheet
|
||||
ExcelWorksheet worksheet = package.Workbook.Worksheets.Add(sheetName);
|
||||
|
||||
//全部字段导出
|
||||
worksheet.Cells.LoadFromCollection(list, true);
|
||||
package.Save();
|
||||
}
|
||||
|
||||
return sFileName;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -107,5 +107,20 @@ namespace ZR.Admin.WebApi.Controllers.System
|
||||
|
||||
return SUCCESS(SysDictService.DeleteDictTypeByIds(idss));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 字典导出
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[Log(BusinessType = BusinessType.EXPORT, IsSaveResponseData = false, Title = "字典导出")]
|
||||
[HttpGet("export")]
|
||||
[ActionPermissionFilter(Permission = "system:dict:export")]
|
||||
public IActionResult Export()
|
||||
{
|
||||
var list = SysDictService.GetAll();
|
||||
|
||||
string sFileName = ExportExcel(list, "sysdictType", "字典");
|
||||
return SUCCESS(new { path = "/export/" + sFileName, fileName = sFileName });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -120,5 +120,20 @@ namespace ZR.Admin.WebApi.Controllers.System
|
||||
List<SysPost> posts = PostService.GetAll();
|
||||
return SUCCESS(posts);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 岗位导出
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[Log(BusinessType = BusinessType.EXPORT, IsSaveResponseData = false, Title= "岗位导出")]
|
||||
[HttpGet("export")]
|
||||
[ActionPermissionFilter(Permission = "system:post:export")]
|
||||
public IActionResult Export()
|
||||
{
|
||||
var list = PostService.GetAll();
|
||||
|
||||
string sFileName = ExportExcel(list, "syspost", "岗位");
|
||||
return SUCCESS(new { path = "/export/" + sFileName, fileName = sFileName });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -166,5 +166,20 @@ namespace ZR.Admin.WebApi.Controllers.System
|
||||
|
||||
return ToResponse(ToJson(result));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 角色导出
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[Log(BusinessType = BusinessType.EXPORT, IsSaveResponseData = false, Title = "角色导出")]
|
||||
[HttpGet("export")]
|
||||
[ActionPermissionFilter(Permission = "system:role:export")]
|
||||
public IActionResult Export()
|
||||
{
|
||||
var list = sysRoleService.SelectRoleAll();
|
||||
|
||||
string sFileName = ExportExcel(list, "sysrole", "角色");
|
||||
return SUCCESS(new { path = "/export/" + sFileName, fileName = sFileName });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ using ZR.Service.System.IService;
|
||||
|
||||
namespace ZR.Admin.WebApi.Controllers.System
|
||||
{
|
||||
//[Verify]
|
||||
[Verify]
|
||||
[Route("system/user")]
|
||||
public class SysUserController : BaseController
|
||||
{
|
||||
@@ -217,6 +217,7 @@ namespace ZR.Admin.WebApi.Controllers.System
|
||||
/// <returns></returns>
|
||||
[HttpGet("export")]
|
||||
[Log(Title = "用户导出", BusinessType = BusinessType.EXPORT)]
|
||||
[ActionPermissionFilter(Permission = "system:user:export")]
|
||||
public IActionResult UserExport([FromQuery] SysUser user)
|
||||
{
|
||||
string sFileName = $"用户列表{DateTime.Now:yyyyMMddHHmmss}.xlsx";
|
||||
@@ -230,35 +231,38 @@ namespace ZR.Admin.WebApi.Controllers.System
|
||||
{
|
||||
// 添加worksheet
|
||||
ExcelWorksheet worksheet = package.Workbook.Worksheets.Add("sysuser");
|
||||
|
||||
#region 自定义导出
|
||||
//添加头
|
||||
worksheet.Cells[1, 1].Value = "用户id";
|
||||
worksheet.Cells[1, 2].Value = "用户名称";
|
||||
worksheet.Cells[1, 3].Value = "用户昵称";
|
||||
worksheet.Cells[1, 4].Value = "部门";
|
||||
worksheet.Cells[1, 5].Value = "手机号码";
|
||||
worksheet.Cells[1, 6].Value = "性别";
|
||||
worksheet.Cells[1, 7].Value = "状态";
|
||||
worksheet.Cells[1, 8].Value = "添加时间";
|
||||
worksheet.Cells[1, 9].Value = "登录IP";
|
||||
worksheet.Cells[1, 10].Value = "最后登录时间";
|
||||
for (int i = 0; i < list.Count; i++)
|
||||
{
|
||||
var item = list[i];
|
||||
worksheet.Cells[$"A{i + 2}"].Value = item.UserId;
|
||||
worksheet.Cells[$"B{i + 2}"].Value = item.UserName;
|
||||
worksheet.Cells[$"C{i + 2}"].Value = item.NickName;
|
||||
worksheet.Cells[$"D{i + 2}"].Value = item.DeptName;
|
||||
worksheet.Cells[$"E{i + 2}"].Value = item.Phonenumber;
|
||||
worksheet.Cells[$"F{i + 2}"].Value = item.Sex;
|
||||
worksheet.Cells[$"G{i + 2}"].Value = item.Status;
|
||||
worksheet.Cells[$"H{i + 2}"].Value = item.Create_time.ToString();
|
||||
worksheet.Cells[$"I{i + 2}"].Value = item.LoginIP;
|
||||
worksheet.Cells[$"J{i + 2}"].Value = item.LoginDate.ToString();
|
||||
}
|
||||
//worksheet.Cells[1, 1].Value = "用户id";
|
||||
//worksheet.Cells[1, 2].Value = "用户名称";
|
||||
//worksheet.Cells[1, 3].Value = "用户昵称";
|
||||
//worksheet.Cells[1, 4].Value = "部门";
|
||||
//worksheet.Cells[1, 5].Value = "手机号码";
|
||||
//worksheet.Cells[1, 6].Value = "性别";
|
||||
//worksheet.Cells[1, 7].Value = "状态";
|
||||
//worksheet.Cells[1, 8].Value = "添加时间";
|
||||
//worksheet.Cells[1, 9].Value = "登录IP";
|
||||
//worksheet.Cells[1, 10].Value = "最后登录时间";
|
||||
//for (int i = 0; i < list.Count; i++)
|
||||
//{
|
||||
// var item = list[i];
|
||||
// //worksheet.Cells[i + 2, 1].Value = item.UserId;
|
||||
// //worksheet.Cells[i + 2, 2].Value = item.UserName;
|
||||
// //worksheet.Cells[i + 2, 3].Value = item.NickName;
|
||||
// //worksheet.Cells[i + 2, 4].Value = item.DeptName;
|
||||
// //worksheet.Cells[i + 2, 5].Value = item.Phonenumber;
|
||||
// //worksheet.Cells[i + 2, 6].Value = item.Sex;
|
||||
// //worksheet.Cells[i + 2, 7].Value = item.Status;
|
||||
// //worksheet.Cells[i + 2, 8].Value = item.Create_time.ToString();
|
||||
// //worksheet.Cells[i + 2, 9].Value = item.LoginIP;
|
||||
// //worksheet.Cells[i + 2, 10].Value = item.LoginDate.ToString();
|
||||
//}
|
||||
#endregion
|
||||
//全部字段导出
|
||||
worksheet.Cells.LoadFromCollection(list, true);
|
||||
package.Save();
|
||||
}
|
||||
return SUCCESS(new { zipPath = "/export/" + sFileName, fileName = sFileName });
|
||||
return SUCCESS(new { path = "/export/" + sFileName, fileName = sFileName });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -265,5 +265,20 @@ namespace ZR.Admin.WebApi.Controllers
|
||||
|
||||
return ToResponse(taskResult);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 定时任务导出
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[Log(BusinessType = BusinessType.EXPORT, IsSaveResponseData = false, Title = "定时任务导出")]
|
||||
[HttpGet("export")]
|
||||
[ActionPermissionFilter(Permission = "monitor:job:export")]
|
||||
public IActionResult Export()
|
||||
{
|
||||
var list = _tasksQzService.GetAll();
|
||||
|
||||
string sFileName = ExportExcel(list, "monitorjob", "定时任务");
|
||||
return SUCCESS(new { path = "/export/" + sFileName, fileName = sFileName });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,5 +76,20 @@ namespace ZR.Admin.WebApi.Controllers.System
|
||||
tasksLogService.DeleteTable();
|
||||
return SUCCESS(1);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 定时任务日志导出
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[Log(BusinessType = BusinessType.EXPORT, IsSaveResponseData = false, Title = "定时任务日志导出")]
|
||||
[HttpGet("export")]
|
||||
[ActionPermissionFilter(Permission = "PRIV_JOBLOG_EXPORT")]
|
||||
public IActionResult Export()
|
||||
{
|
||||
var list = tasksLogService.GetAll();
|
||||
|
||||
string sFileName = ExportExcel(list, "jobLog", "定时任务日志");
|
||||
return SUCCESS(new { path = "/export/" + sFileName, fileName = sFileName });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
using Infrastructure.Attribute;
|
||||
using Infrastructure;
|
||||
using Infrastructure.Attribute;
|
||||
using Infrastructure.Enums;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using SqlSugar;
|
||||
using System.Linq.Expressions;
|
||||
using ZR.Admin.WebApi.Filters;
|
||||
using ZR.Common;
|
||||
using ZR.Model;
|
||||
@@ -44,7 +48,7 @@ namespace ZR.Admin.WebApi.Controllers.monitor
|
||||
/// /monitor/logininfor/clean
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[Log(Title = "清空登录日志")]
|
||||
[Log(Title = "清空登录日志", BusinessType= BusinessType.CLEAN)]
|
||||
[ActionPermissionFilter(Permission = "monitor:logininfor:remove")]
|
||||
[HttpDelete("clean")]
|
||||
public IActionResult CleanLoginInfo()
|
||||
@@ -58,7 +62,7 @@ namespace ZR.Admin.WebApi.Controllers.monitor
|
||||
/// </summary>
|
||||
/// <param name="infoIds"></param>
|
||||
/// <returns></returns>
|
||||
[Log(Title = "删除登录日志")]
|
||||
[Log(Title = "删除登录日志", BusinessType = BusinessType.DELETE)]
|
||||
[HttpDelete("{infoIds}")]
|
||||
[ActionPermissionFilter(Permission = "monitor:logininfor:remove")]
|
||||
public IActionResult Remove(string infoIds)
|
||||
@@ -67,5 +71,26 @@ namespace ZR.Admin.WebApi.Controllers.monitor
|
||||
return SUCCESS(sysLoginService.DeleteLogininforByIds(infoIdss));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 登录日志导出
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[Log(BusinessType = BusinessType.EXPORT, IsSaveResponseData = false, Title = "登录日志导出")]
|
||||
[HttpGet("export")]
|
||||
[ActionPermissionFilter(Permission = "monitor:logininfor:export")]
|
||||
public IActionResult Export([FromQuery] SysLogininfor logininfoDto)
|
||||
{
|
||||
logininfoDto.BeginTime = DateTimeHelper.GetBeginTime(logininfoDto.BeginTime, -1);
|
||||
logininfoDto.EndTime = DateTimeHelper.GetBeginTime(logininfoDto.EndTime, 1);
|
||||
var exp = Expressionable.Create<SysLogininfor>()
|
||||
.And(it => it.loginTime >= logininfoDto.BeginTime && it.loginTime <= logininfoDto.EndTime);
|
||||
|
||||
var list = sysLoginService.Queryable().Where(exp.ToExpression())
|
||||
.IgnoreColumns(it => new { it.Create_by, it.Create_time, it.Update_by, it.Update_time, it.Remark })
|
||||
.ToList();
|
||||
|
||||
string sFileName = ExportExcel(list, "loginlog", "登录日志");
|
||||
return SUCCESS(new { path = "/export/" + sFileName, fileName = sFileName });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,11 @@ using ZR.Model.System.Dto;
|
||||
using ZR.Model.System;
|
||||
using ZR.Model.Vo;
|
||||
using ZR.Service.System.IService;
|
||||
using System;
|
||||
using System.IO;
|
||||
using OfficeOpenXml;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace ZR.Admin.WebApi.Controllers.monitor
|
||||
{
|
||||
@@ -17,10 +22,12 @@ namespace ZR.Admin.WebApi.Controllers.monitor
|
||||
public class SysOperlogController : BaseController
|
||||
{
|
||||
private ISysOperLogService sysOperLogService;
|
||||
private IWebHostEnvironment WebHostEnvironment;
|
||||
|
||||
public SysOperlogController(ISysOperLogService sysOperLogService)
|
||||
public SysOperlogController(ISysOperLogService sysOperLogService, IWebHostEnvironment hostEnvironment)
|
||||
{
|
||||
this.sysOperLogService = sysOperLogService;
|
||||
WebHostEnvironment = hostEnvironment;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -67,5 +74,19 @@ namespace ZR.Admin.WebApi.Controllers.monitor
|
||||
return ToJson(1);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 导出操作日志
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[Log(Title = "操作日志", BusinessType = BusinessType.EXPORT)]
|
||||
[ActionPermissionFilter(Permission = "monitor:operlog:export")]
|
||||
[HttpGet("export")]
|
||||
public IActionResult Export([FromQuery] SysOperLogDto sysOperLog)
|
||||
{
|
||||
var list = sysOperLogService.SelectOperLogList(sysOperLog, new PagerInfo(1, 10000));
|
||||
string sFileName = ExportExcel(list, "operlog", "操作日志");
|
||||
return SUCCESS(new { path = "/export/" + sFileName, fileName = sFileName });
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ namespace ZR.Admin.WebApi.Filters
|
||||
bool isDemoMode = ConfigUtils.Instance.GetAppConfig("DemoMode", false);
|
||||
|
||||
//演示公开环境屏蔽权限
|
||||
string[] denyPerms = new string[] { "update", "add", "remove", "add", "edit", "delete", "import", "run", "start", "stop", "clear", "send" };
|
||||
string[] denyPerms = new string[] { "update", "add", "remove", "add", "edit", "delete", "import", "run", "start", "stop", "clear", "send" ,"export"};
|
||||
if (isDemoMode && (denyPerms.Any(f => Permission.ToLower().Contains(f.ToLower())) || Permission.Equals("system")))
|
||||
{
|
||||
context.Result = new JsonResult(new { code = ResultCode.FORBIDDEN, msg = "演示模式 , 不允许操作" });
|
||||
|
||||
Reference in New Issue
Block a user