Преглед на файлове

增加组织架构,字典列表,行政区域,事件导出接口

qinchaoyue преди 3 месеца
родител
ревизия
5ac29a2fb8

+ 1 - 1
src/Hotline.Api/Controllers/ExportData/ExportDataController.cs

@@ -147,7 +147,7 @@ public class ExportDataController : BaseController
         var name = controllerName + "Application";
         var type = AppDomain.CurrentDomain.GetAssemblies().ToList()
         .SelectMany(d => d.GetTypes())
-           .Where(d => d.Name == name)
+           .Where(d => d.Name.StartsWith(controllerName) && d.Name.EndsWith("Application") )
            .First();
         return type;
     }

+ 20 - 2
src/Hotline.Api/Controllers/HotSpotController.cs

@@ -1,4 +1,5 @@
-using Hotline.Caching.Interfaces;
+using Hotline.Application.ExportExcel;
+using Hotline.Caching.Interfaces;
 using Hotline.FlowEngine;
 using Hotline.Repository.SqlSugar.Extensions;
 using Hotline.Settings;
@@ -6,6 +7,7 @@ using Hotline.Settings.Hotspots;
 using Hotline.Settings.TimeLimits;
 using Hotline.Share.Dtos;
 using Hotline.Share.Dtos.Hotspots;
+using Hotline.Share.Dtos.Order;
 using Hotline.Share.Dtos.Settings;
 using Hotline.Share.Enums.Order;
 using Hotline.Share.Enums.Settings;
@@ -31,9 +33,10 @@ namespace Hotline.Api.Controllers
         private readonly ITimeLimitRepository _timeLimitRepository;
         private readonly ISystemDicDataCacheManager _sysDicDataCacheManager;
         private readonly IEventCategoryRepository _eventCategoryRepository;
+        private readonly IExportApplication _exportApplication;
 
         public HotspotController(IRepository<Hotspot> hotspotTypeRepository,
-            IMapper mapper, ITimeLimitDomainService timeLimitDomainService, ITimeLimitRepository timeLimitRepository, ISystemDicDataCacheManager sysDicDataCacheManager, IEventCategoryRepository eventCategoryRepository)
+            IMapper mapper, ITimeLimitDomainService timeLimitDomainService, ITimeLimitRepository timeLimitRepository, ISystemDicDataCacheManager sysDicDataCacheManager, IEventCategoryRepository eventCategoryRepository, IExportApplication exportApplication)
         {
             _hotspotTypeRepository = hotspotTypeRepository;
             _mapper = mapper;
@@ -41,6 +44,7 @@ namespace Hotline.Api.Controllers
             _timeLimitRepository = timeLimitRepository;
             _sysDicDataCacheManager = sysDicDataCacheManager;
             _eventCategoryRepository = eventCategoryRepository;
+            _exportApplication = exportApplication;
         }
 
         #region 热点
@@ -129,6 +133,20 @@ namespace Hotline.Api.Controllers
                 .ToTreeAsync(x => x.Children, it => it.ParentId,null);
         }
 
+        /// <summary>
+        /// 事件导出
+        /// </summary>
+        /// <param name="dto"></param>
+        /// <returns></returns>
+        [HttpPost("event/tree/export")]
+        public async Task<FileStreamResult> GetEventAllTreeExport([FromBody]ExportExcelDto<string> dto)
+        {
+            var items = await _eventCategoryRepository.Queryable()
+                .OrderBy(d => d.OrderBy)
+                .ToTreeAsync(x => x.Children, it => it.ParentId, null);
+            return _exportApplication.GetExcelFile(dto, items, "事件");
+        }
+
         /// <summary>
         /// 查询子项
         /// </summary>

+ 22 - 11
src/Hotline.Api/Controllers/OrgController.cs

@@ -1,6 +1,9 @@
-using Hotline.Configurations;
+using Hotline.Application.ExportExcel;
+using Hotline.Application.Users;
+using Hotline.Configurations;
 using Hotline.Permissions;
 using Hotline.Settings;
+using Hotline.Share.Dtos.Order;
 using Hotline.Share.Dtos.Org;
 using Hotline.Share.Enums.Order;
 using MapsterMapper;
@@ -25,6 +28,8 @@ namespace Hotline.Api.Controllers
         private readonly IMapper _mapper;
         private readonly ISessionContext _sessionContext;
 		private readonly IOptionsSnapshot<AppConfiguration> _appOptions;
+        private readonly IOrgApplication _orgApplication;
+        private readonly IExportApplication _exportApplication;
 
         public OrgController(
             ISystemOrganizeRepository systemOrganizeRepository,
@@ -32,7 +37,9 @@ namespace Hotline.Api.Controllers
             ISystemAreaDomainService areaDomainService,
             IMapper mapper,
             ISessionContext sessionContext,
-            IOptionsSnapshot<AppConfiguration> appOptions)
+            IOptionsSnapshot<AppConfiguration> appOptions,
+            IOrgApplication orgApplication,
+            IExportApplication exportApplication)
         {
             _systemOrganizeRepository = systemOrganizeRepository;
             _systemDomainService = systemDomainService;
@@ -40,6 +47,8 @@ namespace Hotline.Api.Controllers
             _mapper = mapper;
             _sessionContext = sessionContext;
             _appOptions = appOptions;
+            _orgApplication = orgApplication;
+            _exportApplication = exportApplication;
         }
 
         /// <summary>
@@ -55,18 +64,20 @@ namespace Hotline.Api.Controllers
 
         [HttpGet("getorgjsonforuser")]
         [AllowAnonymous]
-        public async Task<IReadOnlyList<SystemOrganize>> GetOrgJsonForUser()
+        public async Task<IReadOnlyList<SystemOrganize>> GetOrgJsonItems()
         {
-            if (_sessionContext.OrgIsCenter)
-            {
-                return await _systemOrganizeRepository.GetOrgJson();
-            }
-            else
-            {
-                return await _systemOrganizeRepository.GetOrgJsonForUser(_sessionContext.RequiredOrgId);
-            }
+            return await _orgApplication.GetOrgJsonItems();
         }
 
+        [HttpPost("getorgjsonforuser/export")]
+        [AllowAnonymous]
+        public async Task<FileStreamResult> GetOrgJsonItemsExport([FromBody] ExportExcelDto<string> dto)
+        {
+            var items = await _orgApplication.GetOrgJsonItems();
+            return _exportApplication.GetExcelFile(dto, items.ToList(), "组织架构");
+        }
+
+
         ///// <summary>
         ///// 新增组织架构
         ///// </summary>

+ 8 - 16
src/Hotline.Api/Controllers/RoleController.cs

@@ -1,4 +1,5 @@
 using Fw.Utility.UnifyResponse;
+using Hotline.Application.Users;
 using Hotline.Caching.Interfaces;
 using Hotline.Identity.Roles;
 using Hotline.Permissions;
@@ -12,6 +13,7 @@ using Hotline.Share.Enums.Identity;
 using Hotline.Share.Enums.Order;
 using Hotline.Share.Enums.Settings;
 using Hotline.Share.Enums.User;
+using Hotline.Share.Tools;
 using MapsterMapper;
 using Microsoft.AspNetCore.Mvc;
 using Microsoft.Extensions.Options;
@@ -39,6 +41,7 @@ public class RoleController : BaseController
     private readonly IOptions<IdentityConfiguration> _identityConfigurationAccessor;
     private readonly IRepository<SystemDataTable> _systemDataTableRepository;
     private readonly ISessionContext _sessionContext;
+    private readonly IRoleApplication _roleApplication;
 
     public RoleController(
         IRepository<Role> roleRepository,
@@ -50,7 +53,8 @@ public class RoleController : BaseController
         IMapper mapper,
         IOptions<IdentityConfiguration> identityConfigurationAccessor,
         IRepository<SystemDataTable> systemDataTableRepository,
-        ISessionContext sessionContext)
+        ISessionContext sessionContext,
+        IRoleApplication roleApplication)
     {
         _roleRepository = roleRepository;
         _systemAuthorityRepository = systemAuthorityRepository;
@@ -62,6 +66,7 @@ public class RoleController : BaseController
         _identityConfigurationAccessor = identityConfigurationAccessor;
         _systemDataTableRepository = systemDataTableRepository;
         _sessionContext = sessionContext;
+        _roleApplication = roleApplication;
     }
 
     /// <summary>
@@ -70,22 +75,9 @@ public class RoleController : BaseController
     /// <param name="dto"></param>
     /// <returns></returns>
     [HttpGet("paged")]
-    public async Task<PagedDto<RoleDto>> QueryPaged([FromQuery] QueryRolesPagedDto dto)
+    public async Task<PagedDto<RoleDto>> GetRuleItems([FromQuery] QueryRolesPagedDto dto)
     {
-        var query = _roleRepository.Queryable(includeDeleted: true);
-        if (dto.IsDeleted.HasValue)
-            query = query.Where(d => d.IsDeleted == dto.IsDeleted);
-
-        var (total, items) = await query
-            .Includes(d => d.Accounts.Where(x => !x.IsDeleted && x.Status == EAccountStatus.Normal).ToList())
-            .WhereIF(!string.IsNullOrEmpty(dto.Keyword), d => d.Name.Contains(dto.Keyword!) || d.DisplayName.Contains(dto.Keyword!))
-            .WhereIF(_sessionContext.OrgIsCenter==false,d=>d.RoleType == ERoleType.OrgRole)
-            .Where(x=>x.Id != RoleSeedData.AdminId)
-            .OrderBy(d => d.IsDeleted)
-            .OrderByDescending(d => d.CreationTime)
-            .ToPagedListAsync(dto.PageIndex, dto.PageSize, HttpContext.RequestAborted);
-
-        return new PagedDto<RoleDto>(total, _mapper.Map<IReadOnlyList<RoleDto>>(items));
+        return (await _roleApplication.GetRuleItems(dto).ToPagedListAsync(dto)).ToPaged();
     }
 
     /// <summary>

+ 41 - 27
src/Hotline.Api/Controllers/SysController.cs

@@ -1,4 +1,5 @@
 using EasyCaching.Core;
+using Hotline.Application.ExportExcel;
 using Hotline.Application.Systems;
 using Hotline.Caching.Interfaces;
 using Hotline.CallCenter.Ivrs;
@@ -14,6 +15,7 @@ using Hotline.Settings.CommonOpinions;
 using Hotline.Share.Dtos;
 using Hotline.Share.Dtos.Dic;
 using Hotline.Share.Dtos.Menu;
+using Hotline.Share.Dtos.Order;
 using Hotline.Share.Dtos.Settings;
 using Hotline.Share.Enums.Settings;
 using Hotline.Share.Requests;
@@ -58,6 +60,8 @@ namespace Hotline.Api.Controllers
         private readonly IRedisCachingProvider _redisCaching;
         private readonly IEasyCachingProvider _easyCaching;
         private readonly IOptionsSnapshot<AppConfiguration> _appOptions;
+        private readonly ISystemLogApplication _systemLogApplication;
+        private readonly IExportApplication _exportApplication;
 
         /// <summary>
         /// 系统管理相关接口
@@ -93,7 +97,9 @@ namespace Hotline.Api.Controllers
             IRedisCachingProvider redisCaching,
             IEasyCachingProvider easyCaching
 ,
-            IOptionsSnapshot<AppConfiguration> appOptions)
+            IOptionsSnapshot<AppConfiguration> appOptions,
+            ISystemLogApplication systemLogApplication,
+            IExportApplication exportApplication)
         {
             _mapper = mapper;
             _systemSettingsRepository = systemSettingsRepository;
@@ -112,6 +118,8 @@ namespace Hotline.Api.Controllers
             _redisCaching = redisCaching;
             _easyCaching = easyCaching;
             _appOptions = appOptions;
+            _systemLogApplication = systemLogApplication;
+            _exportApplication = exportApplication;
         }
 
         #region 菜单管理
@@ -292,6 +300,18 @@ namespace Hotline.Api.Controllers
             //return await _sysDicDataRepository.Queryable().Where(x => x.DicTypeId == dto.typeid).WhereIF(!string.IsNullOrEmpty(dto.datavalue), x => x.DicDataValue.Contains(dto.datavalue)).WhereIF(!string.IsNullOrEmpty(dto.ParentId), x => x.ParentId == dto.ParentId).ToListAsync();
         }
 
+        /// <summary>
+        /// 根据字典类型ID获取字典列表
+        /// </summary>
+        /// <param name="dto"></param>
+        /// <returns></returns>
+        [HttpPost("dictdata-type/export")]
+        public async Task<FileStreamResult> GetSysDicDataExport([FromBody]ExportExcelDto<GetSysDicDataDto> dto)
+        {
+            var items = await _sysDicDataRepository.Queryable().Where(x => x.DicTypeId == dto.QueryDto.typeid).OrderBy(x => x.Sort).ToTreeAsync(x => x.Children, x => x.ParentId, "");
+            return _exportApplication.GetExcelFile(dto, items, "字典列表");
+        }
+
         /// <summary>
         /// 根据字典类型Code获取字典列表
         /// </summary>
@@ -369,6 +389,17 @@ namespace Hotline.Api.Controllers
             return await _systemAreaDomainService.GetAreaTree(_appOptions.Value.IsZiGong ? 6 : 0);
         }
 
+        /// <summary>
+        /// 获取省市区树形
+        /// </summary>
+        /// <returns></returns>
+        [HttpPost("area/tree/export")]
+        public async Task<FileStreamResult> GetAreaTreeExport([FromBody]ExportExcelDto<string> dto)
+        {
+            var items = await _systemAreaDomainService.GetAreaTree(_appOptions.Value.IsZiGong ? 6 : 0);
+            return _exportApplication.GetExcelFile(dto, items, "行政区域");
+        }
+
         /// <summary>
         /// 新增省市区
         /// </summary>
@@ -565,34 +596,17 @@ namespace Hotline.Api.Controllers
         /// <param name="dto"></param>
         /// <returns></returns>
         [HttpGet("log_list")]
-        public async Task<PagedDto<SystemLogDto>> List([FromQuery] SysLogPagedKeywordRequest dto)
-        {
-            var (total, items) = await _systemLogRepository.Queryable()
-                .WhereIF(dto.IsAll.HasValue && !dto.IsAll.Value, x => !string.IsNullOrEmpty(x.Name))
-                .WhereIF(!string.IsNullOrEmpty(dto.Name), x => x.Name.Contains(dto.Name))
-                .WhereIF(!string.IsNullOrEmpty(dto.CreatorName), x => x.CreatorName.Contains(dto.CreatorName))
-                .WhereIF(!string.IsNullOrEmpty(dto.ExecuteUrl), x => x.ExecuteUrl.Contains(dto.ExecuteUrl))
-                .WhereIF(!string.IsNullOrEmpty(dto.ExecuteParam),
-                    x => SqlFunc.JsonLike(x.ExecuteParam, dto.ExecuteParam))
-                .WhereIF(dto.StartTime.HasValue && dto.EndTime.HasValue,
-                    x => x.CreationTime >= dto.StartTime && x.CreationTime <= dto.EndTime)
-                                //.WhereIF(!string.IsNullOrEmpty(dto.Keyword), x => x.Name.Contains(dto.Keyword!) || x.CreatorName.Contains(dto.Keyword!))
-                .Select(x => new SystemLogDto
-                {
-                    ExecuteParam = x.ExecuteParam
-                }, true)
-                .OrderByDescending(x => x.CreationTime)
-                .ToPagedListAsync(dto.PageIndex, dto.PageSize, HttpContext.RequestAborted);
-            return new PagedDto<SystemLogDto>(total, items);
-
+        public async Task<PagedDto<SystemLogDto>> GetSystemLotItems([FromQuery] SysLogPagedKeywordRequest dto)
+        {
+            return (await _systemLogApplication.GetSystemLotItems(dto).ToPagedListAsync(dto)).ToPaged();
         }
 
-		/// <summary>
-		/// 获取日志实体
-		/// </summary>
-		/// <param name="id"></param>
-		/// <returns></returns>
-		[HttpGet("log/{id}")]
+        /// <summary>
+        /// 获取日志实体
+        /// </summary>
+        /// <param name="id"></param>
+        /// <returns></returns>
+        [HttpGet("log/{id}")]
         public async Task<SystemLogDto> ItemEntity(string id)
         {
             var log = await _systemLogRepository.Queryable()

+ 5 - 1
src/Hotline.Application/Systems/ISystemLogApplication.cs

@@ -1,4 +1,7 @@
-using Microsoft.AspNetCore.Http;
+using Hotline.Share.Dtos.Settings;
+using Hotline.Share.Requests;
+using Microsoft.AspNetCore.Http;
+using SqlSugar;
 using System;
 using System.Collections.Generic;
 using System.Linq;
@@ -13,5 +16,6 @@ namespace Hotline.Application.Systems
 
 		Task<bool> HasByIpUrlAsync(string ipUrl);
 
+		ISugarQueryable<SystemLogDto> GetSystemLotItems(SysLogPagedKeywordRequest dto);
     }
 }

+ 25 - 0
src/Hotline.Application/Systems/SystemLogApplication.cs

@@ -1,10 +1,14 @@
 using Hotline.Settings;
+using Hotline.Share.Attributes;
+using Hotline.Share.Dtos.Settings;
+using Hotline.Share.Requests;
 using Hotline.Tools;
 using MapsterMapper;
 using Microsoft.AspNetCore.Http;
 using Microsoft.AspNetCore.Mvc;
 using Newtonsoft.Json;
 using Org.BouncyCastle.Asn1.Ocsp;
+using SqlSugar;
 using System.Text;
 using XF.Domain.Dependency;
 using XF.Domain.Repository;
@@ -47,6 +51,27 @@ namespace Hotline.Application.Systems
         public async Task<bool> HasByIpUrlAsync(string ipUrl)
         {
 			return await _systemLogRepository.Queryable().Where(x => x.IpUrl == ipUrl).AnyAsync();
+        }
+
+		[ExportExcel("操作日志")]
+        public ISugarQueryable<SystemLogDto> GetSystemLotItems(SysLogPagedKeywordRequest dto)
+		{
+			var query =  _systemLogRepository.Queryable()
+				.WhereIF(dto.IsAll.HasValue && !dto.IsAll.Value, x => !string.IsNullOrEmpty(x.Name))
+				.WhereIF(!string.IsNullOrEmpty(dto.Name), x => x.Name.Contains(dto.Name))
+				.WhereIF(!string.IsNullOrEmpty(dto.CreatorName), x => x.CreatorName.Contains(dto.CreatorName))
+				.WhereIF(!string.IsNullOrEmpty(dto.ExecuteUrl), x => x.ExecuteUrl.Contains(dto.ExecuteUrl))
+				.WhereIF(!string.IsNullOrEmpty(dto.ExecuteParam),
+					x => SqlFunc.JsonLike(x.ExecuteParam, dto.ExecuteParam))
+				.WhereIF(dto.StartTime.HasValue && dto.EndTime.HasValue,
+					x => x.CreationTime >= dto.StartTime && x.CreationTime <= dto.EndTime)
+				//.WhereIF(!string.IsNullOrEmpty(dto.Keyword), x => x.Name.Contains(dto.Keyword!) || x.CreatorName.Contains(dto.Keyword!))
+				.Select(x => new SystemLogDto
+				{
+					ExecuteParam = x.ExecuteParam
+				}, true)
+				.OrderByDescending(x => x.CreationTime);
+			return query;
         }
     }
 }

+ 13 - 0
src/Hotline.Application/Users/IOrgApplication.cs

@@ -0,0 +1,13 @@
+using Hotline.Settings;
+using SqlSugar;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Hotline.Application.Users;
+public interface IOrgApplication
+{
+    Task<IReadOnlyList<SystemOrganize>> GetOrgJsonItems();
+}

+ 13 - 0
src/Hotline.Application/Users/IRoleApplication.cs

@@ -0,0 +1,13 @@
+using Hotline.Share.Dtos.Roles;
+using SqlSugar;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Hotline.Application.Users;
+public interface IRoleApplication
+{
+    ISugarQueryable<RoleDto> GetRuleItems(QueryRolesPagedDto dto);
+}

+ 35 - 0
src/Hotline.Application/Users/OrgApplication.cs

@@ -0,0 +1,35 @@
+using Hotline.Repository.SqlSugar.System;
+using Hotline.Settings;
+using SqlSugar;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using XF.Domain.Authentications;
+using XF.Domain.Dependency;
+
+namespace Hotline.Application.Users;
+public class OrgApplication : IOrgApplication, IScopeDependency
+{
+    private readonly ISystemOrganizeRepository _systemOrganizeRepository;
+    private readonly ISessionContext _sessionContext;
+
+    public OrgApplication(ISystemOrganizeRepository systemOrganizeRepository, ISessionContext sessionContext)
+    {
+        _systemOrganizeRepository = systemOrganizeRepository;
+        _sessionContext = sessionContext;
+    }
+
+    public async Task<IReadOnlyList<SystemOrganize>> GetOrgJsonItems()
+    {
+        if (_sessionContext.OrgIsCenter)
+        {
+            return await _systemOrganizeRepository.GetOrgJson();
+        }
+        else
+        {
+            return await _systemOrganizeRepository.GetOrgJsonForUser(_sessionContext.RequiredOrgId);
+        }
+    }
+}

+ 48 - 0
src/Hotline.Application/Users/RoleApplication.cs

@@ -0,0 +1,48 @@
+using Hotline.Identity.Roles;
+using Hotline.SeedData;
+using Hotline.Share.Attributes;
+using Hotline.Share.Dtos;
+using Hotline.Share.Dtos.Roles;
+using Hotline.Share.Enums.Identity;
+using Hotline.Share.Enums.User;
+using Microsoft.AspNetCore.Http;
+using SqlSugar;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using XF.Domain.Authentications;
+using XF.Domain.Dependency;
+using XF.Domain.Repository;
+
+namespace Hotline.Application.Users;
+public class RoleApplication : IRoleApplication, IScopeDependency
+{
+    private readonly IRepository<Role> _roleRepository;
+    private readonly ISessionContext _sessionContext;
+
+    public RoleApplication(IRepository<Role> roleRepository, ISessionContext sessionContext)
+    {
+        _roleRepository = roleRepository;
+        _sessionContext = sessionContext;
+    }
+
+    [ExportExcel("角色")]
+    public ISugarQueryable<RoleDto> GetRuleItems(QueryRolesPagedDto dto)
+    {
+        var query = _roleRepository.Queryable(includeDeleted: true);
+        if (dto.IsDeleted.HasValue)
+            query = query.Where(d => d.IsDeleted == dto.IsDeleted);
+
+        var roleQuery = query
+            .Includes(d => d.Accounts.Where(x => !x.IsDeleted && x.Status == EAccountStatus.Normal).ToList())
+            .WhereIF(!string.IsNullOrEmpty(dto.Keyword), d => d.Name.Contains(dto.Keyword!) || d.DisplayName.Contains(dto.Keyword!))
+            .WhereIF(_sessionContext.OrgIsCenter == false, d => d.RoleType == ERoleType.OrgRole)
+            .Where(x => x.Id != RoleSeedData.AdminId)
+            .OrderBy(d => d.IsDeleted)
+            .OrderByDescending(d => d.CreationTime)
+            .Select<RoleDto>();
+        return roleQuery;
+    }
+}