♻️代码重构

This commit is contained in:
不做码农 2023-08-31 08:27:48 +08:00
parent c65952202a
commit be515339fe
176 changed files with 372 additions and 245 deletions

View File

@ -1,11 +1,16 @@
using Microsoft.AspNetCore.Mvc; using Infrastructure.Extensions;
using Infrastructure.Model;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc;
using MiniExcelLibs; using MiniExcelLibs;
using Newtonsoft.Json; using Newtonsoft.Json;
using Newtonsoft.Json.Serialization; using Newtonsoft.Json.Serialization;
using System;
using System.Collections.Generic;
using System.IO;
using System.Web; using System.Web;
using Io = System.IO;
namespace ZR.Admin.WebApi.Controllers namespace Infrastructure.Controllers
{ {
public class BaseController : ControllerBase public class BaseController : ControllerBase
{ {
@ -60,7 +65,7 @@ namespace ZR.Admin.WebApi.Controllers
{ {
throw new CustomException(fileName + "文件不存在"); throw new CustomException(fileName + "文件不存在");
} }
var stream = Io.File.OpenRead(path); //创建文件流 var stream = System.IO.File.OpenRead(path); //创建文件流
Response.Headers.Add("Access-Control-Expose-Headers", "Content-Disposition"); Response.Headers.Add("Access-Control-Expose-Headers", "Content-Disposition");
return File(stream, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", HttpUtility.UrlEncode(fileName)); return File(stream, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", HttpUtility.UrlEncode(fileName));

View File

@ -2,7 +2,7 @@
using System.Text.Json; using System.Text.Json;
using System.Text.Json.Serialization; using System.Text.Json.Serialization;
namespace Infrastructure namespace Infrastructure.Converter
{ {
public class JsonConverterUtil public class JsonConverterUtil
{ {

View File

@ -4,7 +4,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.Text.Json; using System.Text.Json;
namespace Infrastructure namespace Infrastructure.Converter
{ {
/// <summary> /// <summary>
/// Json任何类型读取到字符串属性 /// Json任何类型读取到字符串属性
@ -33,10 +33,10 @@ namespace Infrastructure
writer.WriteStringValue(value); writer.WriteStringValue(value);
} }
/// <summary> /// <summary>
/// 非字符类型,返回原生内容 /// 非字符类型,返回原生内容
/// </summary> /// </summary>
/// <param name="jsonReader"></param> /// <param name="jsonReader"></param>
/// <returns></returns> /// <returns></returns>
private static string GetRawPropertyValue(Utf8JsonReader jsonReader) private static string GetRawPropertyValue(Utf8JsonReader jsonReader)
{ {
ReadOnlySpan<byte> utf8Bytes = jsonReader.HasValueSequence ? ReadOnlySpan<byte> utf8Bytes = jsonReader.HasValueSequence ?

View File

@ -54,5 +54,10 @@
/// 清空数据 /// 清空数据
/// </summary> /// </summary>
CLEAN = 9, CLEAN = 9,
/// <summary>
/// 下载
/// </summary>
DOWNLOAD = 10,
} }
} }

View File

@ -2,7 +2,7 @@
using System; using System;
using System.IO; using System.IO;
namespace ZR.Common namespace Infrastructure.Helper
{ {
public class JnHelper public class JnHelper
{ {

View File

@ -1,6 +1,5 @@
using Infrastructure.Extensions; using Infrastructure.Extensions;
using Infrastructure.Model; using Infrastructure.Model;
using Infrastructure.WebExtensins;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.IdentityModel.Tokens; using Microsoft.IdentityModel.Tokens;
using Newtonsoft.Json; using Newtonsoft.Json;

View File

@ -15,6 +15,10 @@ namespace Infrastructure.Model
/// 是否演示模式 /// 是否演示模式
/// </summary> /// </summary>
public bool DemoMode { get; set; } public bool DemoMode { get; set; }
/// <summary>
/// 初始化db
/// </summary>
public bool InitDb { get; set; }
public MailOptions MailOptions { get; set; } public MailOptions MailOptions { get; set; }
public Upload Upload { get; set; } public Upload Upload { get; set; }
public ALIYUN_OSS ALIYUN_OSS { get; set; } public ALIYUN_OSS ALIYUN_OSS { get; set; }

View File

@ -1,5 +1,12 @@
namespace ZR.Admin.WebApi.Extensions using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using System;
namespace Infrastructure
{ {
/// <summary>
/// 跨域扩展
/// </summary>
public static class CorsExtension public static class CorsExtension
{ {
/// <summary> /// <summary>

View File

@ -1,7 +1,10 @@
 
using Infrastructure.Extensions;
using Microsoft.AspNetCore.Http;
using System;
using System.Reflection; using System.Reflection;
namespace ZR.Admin.WebApi.Extensions namespace Infrastructure
{ {
public static class EntityExtension public static class EntityExtension
{ {

View File

@ -1,5 +1,4 @@
using Infrastructure.Extensions; using IPTools.Core;
using IPTools.Core;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
@ -10,7 +9,7 @@ using System.Text;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using UAParser; using UAParser;
namespace Infrastructure.WebExtensins namespace Infrastructure.Extensions
{ {
/// <summary> /// <summary>
/// HttpContext扩展类 /// HttpContext扩展类
@ -220,7 +219,8 @@ namespace Infrastructure.WebExtensins
if (HttpMethods.IsPost(reqMethod) || HttpMethods.IsPut(reqMethod) || HttpMethods.IsDelete(reqMethod)) if (HttpMethods.IsPost(reqMethod) || HttpMethods.IsPut(reqMethod) || HttpMethods.IsDelete(reqMethod))
{ {
param = context.GetBody(); param = context.GetBody();
param = PwdRep().Replace(param, "***"); string regex = "(?<=\"password\":\")[^\",]*";
param = Regex.Replace(param, regex, "***");
} }
if (param.IsEmpty()) if (param.IsEmpty())
{ {
@ -228,9 +228,6 @@ namespace Infrastructure.WebExtensins
} }
return param; return param;
} }
[GeneratedRegex("(?<=\"password\":\")[^\",]*")]
private static partial Regex PwdRep();
} }
} }

View File

@ -1,6 +1,9 @@
using AspNetCoreRateLimit; using AspNetCoreRateLimit;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using System;
namespace ZR.Admin.WebApi.Extensions namespace ZR.Infrastructure.WebExtensions
{ {
public static class IPRateExtension public static class IPRateExtension
{ {

View File

@ -1,4 +1,7 @@
using JinianNet.JNTemplate; using Infrastructure.Helper;
using JinianNet.JNTemplate;
using Microsoft.Extensions.DependencyInjection;
using System;
namespace Infrastructure namespace Infrastructure
{ {

View File

@ -8,18 +8,19 @@
<ItemGroup> <ItemGroup>
<FrameworkReference Include="Microsoft.AspNetCore.App" /> <FrameworkReference Include="Microsoft.AspNetCore.App" />
<Compile Remove="Model\PagedInfo.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="AspectCore.Abstractions" Version="2.4.0" /> <PackageReference Include="AspectCore.Abstractions" Version="2.4.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="7.0.4" />
<PackageReference Include="Microsoft.Extensions.DependencyModel" Version="7.0.0" /> <PackageReference Include="Microsoft.Extensions.DependencyModel" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="7.0.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" /> <PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="UAParser" Version="3.1.47" /> <PackageReference Include="UAParser" Version="3.1.47" />
<PackageReference Include="IPTools.China" Version="1.6.0" /> <PackageReference Include="IPTools.China" Version="1.6.0" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="7.0.7" /> <PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="7.0.7" />
<PackageReference Include="JinianNet.JNTemplate" Version="2.3.3" />
<PackageReference Include="MiniExcel" Version="1.31.2" />
<PackageReference Include="CSRedisCore" Version="3.8.670" />
<PackageReference Include="AspNetCoreRateLimit" Version="5.0.0" />
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@ -1,10 +1,9 @@
using Infrastructure.Extensions; using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options; using Microsoft.Extensions.Options;
using Newtonsoft.Json; using Newtonsoft.Json;
using ZR.Admin.WebApi.Extensions;
using ZR.Admin.WebApi.Filters; using ZR.Admin.WebApi.Filters;
using ZR.Model.System; using ZR.Model.System;
using ZR.Service.IService;
using ZR.Service.System; using ZR.Service.System;
using ZR.Service.System.IService; using ZR.Service.System.IService;
@ -14,7 +13,6 @@ namespace ZR.Admin.WebApi.Controllers
/// 公共模块 /// 公共模块
/// </summary> /// </summary>
[Route("[controller]/[action]")] [Route("[controller]/[action]")]
[Tags("公共模块Common")]
[ApiExplorerSettings(GroupName = "sys")] [ApiExplorerSettings(GroupName = "sys")]
public class CommonController : BaseController public class CommonController : BaseController
{ {
@ -23,18 +21,22 @@ namespace ZR.Admin.WebApi.Controllers
private IWebHostEnvironment WebHostEnvironment; private IWebHostEnvironment WebHostEnvironment;
private ISysFileService SysFileService; private ISysFileService SysFileService;
private IHelloService HelloService;
public CommonController( public CommonController(
IOptions<OptionsSetting> options, IOptions<OptionsSetting> options,
IWebHostEnvironment webHostEnvironment, IWebHostEnvironment webHostEnvironment,
ISysFileService fileService) ISysFileService fileService,
IHelloService helloService)
{ {
WebHostEnvironment = webHostEnvironment; WebHostEnvironment = webHostEnvironment;
SysFileService = fileService; SysFileService = fileService;
OptionsSetting = options.Value; OptionsSetting = options.Value;
HelloService = helloService;
} }
/// <summary> /// <summary>
/// hello /// home
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
[Route("/")] [Route("/")]
@ -45,6 +47,18 @@ namespace ZR.Admin.WebApi.Controllers
"如果觉得项目有用,打赏作者喝杯咖啡作为奖励\n☛☛http://www.izhaorui.cn/doc/support.html\n"); "如果觉得项目有用,打赏作者喝杯咖啡作为奖励\n☛☛http://www.izhaorui.cn/doc/support.html\n");
} }
/// <summary>
/// hello
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
[Route("/hello")]
[HttpGet]
public IActionResult Hello(string name)
{
return Ok(HelloService.SayHello(name));
}
/// <summary> /// <summary>
/// 企业消息测试 /// 企业消息测试
/// </summary> /// </summary>

View File

@ -11,7 +11,6 @@ namespace ZR.Admin.WebApi.Controllers
/// 文章目录Controller /// 文章目录Controller
/// </summary> /// </summary>
[Route("article/ArticleCategory")] [Route("article/ArticleCategory")]
[Tags("文章目录")]
[ApiExplorerSettings(GroupName = "article")] [ApiExplorerSettings(GroupName = "article")]
public class ArticleCategoryController : BaseController public class ArticleCategoryController : BaseController
{ {

View File

@ -13,7 +13,6 @@ namespace ZR.Admin.WebApi.Controllers
/// </summary> /// </summary>
[Verify] [Verify]
[Route("article")] [Route("article")]
[Tags("文章管理")]
[ApiExplorerSettings(GroupName = "article")] [ApiExplorerSettings(GroupName = "article")]
public class ArticleController : BaseController public class ArticleController : BaseController
{ {
@ -89,7 +88,7 @@ namespace ZR.Admin.WebApi.Controllers
var model = response.Adapt<ArticleDto>(); var model = response.Adapt<ArticleDto>();
if (model.IsPublic == 0 && userId != model.UserId) if (model.IsPublic == 0 && userId != model.UserId)
{ {
return ToResponse(Infrastructure.ResultCode.CUSTOM_ERROR, "访问失败"); return ToResponse(ResultCode.CUSTOM_ERROR, "访问失败");
} }
if (model != null) if (model != null)
{ {

View File

@ -1,5 +1,4 @@
using Infrastructure.Extensions; using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc;
using SqlSugar; using SqlSugar;
using ZR.Admin.WebApi.Extensions; using ZR.Admin.WebApi.Extensions;
using ZR.Admin.WebApi.Filters; using ZR.Admin.WebApi.Filters;
@ -18,7 +17,6 @@ namespace ZR.Admin.WebApi.Controllers
/// </summary> /// </summary>
[Verify] [Verify]
[Route("tool/gen")] [Route("tool/gen")]
[Tags("代码生成CodeGenerator")]
[ApiExplorerSettings(GroupName = "sys")] [ApiExplorerSettings(GroupName = "sys")]
public class CodeGeneratorController : BaseController public class CodeGeneratorController : BaseController
{ {

View File

@ -14,7 +14,6 @@ namespace ZR.Admin.WebApi.Controllers
/// </summary> /// </summary>
[Verify] [Verify]
[Route("system/CommonLang")] [Route("system/CommonLang")]
[Tags("多语言配置CommonLang")]
[ApiExplorerSettings(GroupName = "sys")] [ApiExplorerSettings(GroupName = "sys")]
public class CommonLangController : BaseController public class CommonLangController : BaseController
{ {

View File

@ -14,7 +14,6 @@ namespace ZR.Admin.WebApi.Controllers
/// </summary> /// </summary>
[Verify] [Verify]
[Route("system/config")] [Route("system/config")]
[Tags("系统配置SysConfig")]
[ApiExplorerSettings(GroupName = "sys")] [ApiExplorerSettings(GroupName = "sys")]
public class SysConfigController : BaseController public class SysConfigController : BaseController
{ {

View File

@ -1,6 +1,5 @@
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using System.Collections; using System.Collections;
using ZR.Admin.WebApi.Extensions;
using ZR.Admin.WebApi.Filters; using ZR.Admin.WebApi.Filters;
using ZR.Model.System; using ZR.Model.System;
using ZR.Model.System.Dto; using ZR.Model.System.Dto;
@ -13,7 +12,6 @@ namespace ZR.Admin.WebApi.Controllers.System
/// </summary> /// </summary>
[Verify] [Verify]
[Route("system/dept")] [Route("system/dept")]
[Tags("部门管理SysDept")]
[ApiExplorerSettings(GroupName = "sys")] [ApiExplorerSettings(GroupName = "sys")]
public class SysDeptController : BaseController public class SysDeptController : BaseController
{ {

View File

@ -1,5 +1,4 @@
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using ZR.Admin.WebApi.Extensions;
using ZR.Admin.WebApi.Filters; using ZR.Admin.WebApi.Filters;
using ZR.Model; using ZR.Model;
using ZR.Model.System; using ZR.Model.System;
@ -13,7 +12,6 @@ namespace ZR.Admin.WebApi.Controllers.System
/// </summary> /// </summary>
[Verify] [Verify]
[Route("system/dict/data")] [Route("system/dict/data")]
[Tags("字典数据SysDictData")]
[ApiExplorerSettings(GroupName = "sys")] [ApiExplorerSettings(GroupName = "sys")]
public class SysDictDataController : BaseController public class SysDictDataController : BaseController
{ {

View File

@ -13,7 +13,6 @@ namespace ZR.Admin.WebApi.Controllers.System
/// </summary> /// </summary>
[Verify] [Verify]
[Route("system/dict/type")] [Route("system/dict/type")]
[Tags("字典数据类型SysDictType")]
[ApiExplorerSettings(GroupName = "sys")] [ApiExplorerSettings(GroupName = "sys")]
public class SysDictTypeController : BaseController public class SysDictTypeController : BaseController
{ {

View File

@ -12,7 +12,6 @@ namespace ZR.Admin.WebApi.Controllers
/// </summary> /// </summary>
[Verify] [Verify]
[Route("tool/file")] [Route("tool/file")]
[Tags(" 文件存储SysFile")]
[ApiExplorerSettings(GroupName = "sys")] [ApiExplorerSettings(GroupName = "sys")]
public class SysFileController : BaseController public class SysFileController : BaseController
{ {

View File

@ -12,7 +12,6 @@ namespace ZR.Admin.WebApi.Controllers.System
/// <summary> /// <summary>
/// 登录 /// 登录
/// </summary> /// </summary>
[Tags("登录SysLogin")]
[ApiExplorerSettings(GroupName = "sys")] [ApiExplorerSettings(GroupName = "sys")]
public class SysLoginController : BaseController public class SysLoginController : BaseController
{ {
@ -160,7 +159,7 @@ namespace ZR.Admin.WebApi.Controllers.System
/// <returns></returns> /// <returns></returns>
[HttpPost("/register")] [HttpPost("/register")]
[AllowAnonymous] [AllowAnonymous]
[Log(Title = "注册", BusinessType = Infrastructure.Enums.BusinessType.INSERT)] [Log(Title = "注册", BusinessType = BusinessType.INSERT)]
public IActionResult Register([FromBody] RegisterDto dto) public IActionResult Register([FromBody] RegisterDto dto)
{ {
SysConfig config = sysConfigService.GetSysConfigByKey("sys.account.register"); SysConfig config = sysConfigService.GetSysConfigByKey("sys.account.register");

View File

@ -1,5 +1,4 @@
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using ZR.Admin.WebApi.Extensions;
using ZR.Admin.WebApi.Filters; using ZR.Admin.WebApi.Filters;
using ZR.Model.System; using ZR.Model.System;
using ZR.Model.System.Dto; using ZR.Model.System.Dto;
@ -12,7 +11,6 @@ namespace ZR.Admin.WebApi.Controllers.System
/// </summary> /// </summary>
[Verify] [Verify]
[Route("/system/menu")] [Route("/system/menu")]
[Tags("菜单管理SysMenu")]
[ApiExplorerSettings(GroupName = "sys")] [ApiExplorerSettings(GroupName = "sys")]
public class SysMenuController : BaseController public class SysMenuController : BaseController
{ {

View File

@ -1,8 +1,6 @@
using Infrastructure.Constant; using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.SignalR; using Microsoft.AspNetCore.SignalR;
using SqlSugar; using SqlSugar;
using ZR.Admin.WebApi.Extensions;
using ZR.Admin.WebApi.Filters; using ZR.Admin.WebApi.Filters;
using ZR.Admin.WebApi.Hubs; using ZR.Admin.WebApi.Hubs;
using ZR.Model; using ZR.Model;
@ -17,7 +15,6 @@ namespace ZR.Admin.WebApi.Controllers.System
/// </summary> /// </summary>
[Verify] [Verify]
[Route("system/notice")] [Route("system/notice")]
[Tags("系统通知SysNotice")]
[ApiExplorerSettings(GroupName = "sys")] [ApiExplorerSettings(GroupName = "sys")]
public class SysNoticeController : BaseController public class SysNoticeController : BaseController
{ {

View File

@ -1,7 +1,5 @@
using Infrastructure.Extensions; using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc;
using SqlSugar; using SqlSugar;
using ZR.Admin.WebApi.Extensions;
using ZR.Admin.WebApi.Filters; using ZR.Admin.WebApi.Filters;
using ZR.Model; using ZR.Model;
using ZR.Model.System; using ZR.Model.System;
@ -14,7 +12,6 @@ namespace ZR.Admin.WebApi.Controllers.System
/// </summary> /// </summary>
[Verify] [Verify]
[Route("system/post")] [Route("system/post")]
[Tags("岗位管理SysPost")]
[ApiExplorerSettings(GroupName = "sys")] [ApiExplorerSettings(GroupName = "sys")]
public class SysPostController : BaseController public class SysPostController : BaseController
{ {

View File

@ -1,5 +1,4 @@
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using ZR.Admin.WebApi.Extensions;
using ZR.Admin.WebApi.Filters; using ZR.Admin.WebApi.Filters;
using ZR.Model.System; using ZR.Model.System;
using ZR.Model.System.Dto; using ZR.Model.System.Dto;
@ -12,7 +11,6 @@ namespace ZR.Admin.WebApi.Controllers.System
/// </summary> /// </summary>
[Verify] [Verify]
[Route("system/user/profile")] [Route("system/user/profile")]
[Tags("个人中心SysProfile")]
[ApiExplorerSettings(GroupName = "sys")] [ApiExplorerSettings(GroupName = "sys")]
public class SysProfileController : BaseController public class SysProfileController : BaseController
{ {

View File

@ -1,5 +1,4 @@
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using ZR.Admin.WebApi.Extensions;
using ZR.Admin.WebApi.Filters; using ZR.Admin.WebApi.Filters;
using ZR.Model; using ZR.Model;
using ZR.Model.System; using ZR.Model.System;
@ -13,7 +12,6 @@ namespace ZR.Admin.WebApi.Controllers.System
/// </summary> /// </summary>
[Verify] [Verify]
[Route("system/role")] [Route("system/role")]
[Tags("角色管理SysRole")]
[ApiExplorerSettings(GroupName = "sys")] [ApiExplorerSettings(GroupName = "sys")]
public class SysRoleController : BaseController public class SysRoleController : BaseController
{ {

View File

@ -14,7 +14,6 @@ namespace ZR.Admin.WebApi.Controllers.System
/// </summary> /// </summary>
[Verify] [Verify]
[Route("system/user")] [Route("system/user")]
[Tags("用户管理SysUser")]
[ApiExplorerSettings(GroupName = "sys")] [ApiExplorerSettings(GroupName = "sys")]
public class SysUserController : BaseController public class SysUserController : BaseController
{ {

View File

@ -10,7 +10,6 @@ namespace ZR.Admin.WebApi.Controllers.System
/// </summary> /// </summary>
[Verify] [Verify]
[Route("system/userRole")] [Route("system/userRole")]
[Tags("用户角色管理SysUserRole")]
[ApiExplorerSettings(GroupName = "sys")] [ApiExplorerSettings(GroupName = "sys")]
public class SysUserRoleController : BaseController public class SysUserRoleController : BaseController
{ {
@ -45,7 +44,7 @@ namespace ZR.Admin.WebApi.Controllers.System
/// <returns></returns> /// <returns></returns>
[HttpPost("create")] [HttpPost("create")]
[ActionPermissionFilter(Permission = "system:roleusers:add")] [ActionPermissionFilter(Permission = "system:roleusers:add")]
[Log(Title = "添加角色用户", BusinessType = Infrastructure.Enums.BusinessType.INSERT)] [Log(Title = "添加角色用户", BusinessType = BusinessType.INSERT)]
public IActionResult Create([FromBody] RoleUsersCreateDto roleUsersCreateDto) public IActionResult Create([FromBody] RoleUsersCreateDto roleUsersCreateDto)
{ {
var response = SysUserRoleService.InsertRoleUser(roleUsersCreateDto); var response = SysUserRoleService.InsertRoleUser(roleUsersCreateDto);
@ -60,7 +59,7 @@ namespace ZR.Admin.WebApi.Controllers.System
/// <returns></returns> /// <returns></returns>
[HttpPost("delete")] [HttpPost("delete")]
[ActionPermissionFilter(Permission = "system:roleusers:remove")] [ActionPermissionFilter(Permission = "system:roleusers:remove")]
[Log(Title = "删除角色用户", BusinessType = Infrastructure.Enums.BusinessType.DELETE)] [Log(Title = "删除角色用户", BusinessType = BusinessType.DELETE)]
public IActionResult Delete([FromBody] RoleUsersCreateDto roleUsersCreateDto) public IActionResult Delete([FromBody] RoleUsersCreateDto roleUsersCreateDto)
{ {
return SUCCESS(SysUserRoleService.DeleteRoleUserByUserIds(roleUsersCreateDto.RoleId, roleUsersCreateDto.UserIds)); return SUCCESS(SysUserRoleService.DeleteRoleUserByUserIds(roleUsersCreateDto.RoleId, roleUsersCreateDto.UserIds));

View File

@ -1,8 +1,6 @@
using Infrastructure.Extensions; using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc;
using Quartz; using Quartz;
using SqlSugar; using SqlSugar;
using ZR.Admin.WebApi.Extensions;
using ZR.Admin.WebApi.Filters; using ZR.Admin.WebApi.Filters;
using ZR.Model.System; using ZR.Model.System;
using ZR.Model.System.Dto; using ZR.Model.System.Dto;
@ -16,7 +14,6 @@ namespace ZR.Admin.WebApi.Controllers
/// </summary> /// </summary>
[Verify] [Verify]
[Route("system/Tasks")] [Route("system/Tasks")]
[Tags("计划Tasks")]
[ApiExplorerSettings(GroupName = "sys")] [ApiExplorerSettings(GroupName = "sys")]
public class TasksController : BaseController public class TasksController : BaseController
{ {

View File

@ -1,5 +1,4 @@
using Infrastructure.Extensions; using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc;
using SqlSugar; using SqlSugar;
using ZR.Admin.WebApi.Filters; using ZR.Admin.WebApi.Filters;
using ZR.Model; using ZR.Model;
@ -14,7 +13,6 @@ namespace ZR.Admin.WebApi.Controllers.System
/// </summary> /// </summary>
[Verify] [Verify]
[Route("/monitor/jobLog")] [Route("/monitor/jobLog")]
[Tags("任务日志TasksLog")]
[ApiExplorerSettings(GroupName = "sys")] [ApiExplorerSettings(GroupName = "sys")]
public class TasksLogController : BaseController public class TasksLogController : BaseController
{ {

View File

@ -9,7 +9,6 @@ namespace ZR.Admin.WebApi.Controllers.monitor
/// <summary> /// <summary>
/// 系统监控 /// 系统监控
/// </summary> /// </summary>
[Tags("系统监控Monitor")]
[ApiExplorerSettings(GroupName = "sys")] [ApiExplorerSettings(GroupName = "sys")]
public class MonitorController : BaseController public class MonitorController : BaseController
{ {

View File

@ -11,7 +11,6 @@ namespace ZR.Admin.WebApi.Controllers
/// </summary> /// </summary>
[Verify] [Verify]
[Route("monitor/SqlDiffLog")] [Route("monitor/SqlDiffLog")]
[Tags("差异日志SqlDiffLog")]
[ApiExplorerSettings(GroupName = "sys")] [ApiExplorerSettings(GroupName = "sys")]
public class SqlDiffLogController : BaseController public class SqlDiffLogController : BaseController
{ {

View File

@ -13,7 +13,6 @@ namespace ZR.Admin.WebApi.Controllers.monitor
/// </summary> /// </summary>
[Verify] [Verify]
[Route("/monitor/logininfor")] [Route("/monitor/logininfor")]
[Tags("登录日志SysLogininfor")]
[ApiExplorerSettings(GroupName = "sys")] [ApiExplorerSettings(GroupName = "sys")]
public class SysLogininforController : BaseController public class SysLogininforController : BaseController
{ {

View File

@ -11,7 +11,6 @@ namespace ZR.Admin.WebApi.Controllers.monitor
/// </summary> /// </summary>
[Verify] [Verify]
[Route("/monitor/operlog")] [Route("/monitor/operlog")]
[Tags("操作日志SysOperlog")]
[ApiExplorerSettings(GroupName = "sys")] [ApiExplorerSettings(GroupName = "sys")]
public class SysOperlogController : BaseController public class SysOperlogController : BaseController
{ {
@ -67,7 +66,7 @@ namespace ZR.Admin.WebApi.Controllers.monitor
{ {
if (!HttpContextExtension.IsAdmin(HttpContext)) if (!HttpContextExtension.IsAdmin(HttpContext))
{ {
return ToResponse(Infrastructure.ResultCode.CUSTOM_ERROR,"操作失败"); return ToResponse(ResultCode.CUSTOM_ERROR,"操作失败");
} }
sysOperLogService.CleanOperLog(); sysOperLogService.CleanOperLog();

View File

@ -7,9 +7,11 @@ using ZR.Model.System.Dto;
namespace ZR.Admin.WebApi.Controllers.monitor namespace ZR.Admin.WebApi.Controllers.monitor
{ {
/// <summary>
/// 在线用户
/// </summary>
[Verify] [Verify]
[Route("monitor/online")] [Route("monitor/online")]
[Tags("在线用户SysUserOnline")]
[ApiExplorerSettings(GroupName = "sys")] [ApiExplorerSettings(GroupName = "sys")]
public class SysUserOnlineController : BaseController public class SysUserOnlineController : BaseController
{ {

View File

@ -1,5 +1,4 @@
using Infrastructure.Extensions; using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc;
using System.Web; using System.Web;
namespace ZR.Admin.WebApi.Controllers namespace ZR.Admin.WebApi.Controllers
@ -11,9 +10,6 @@ namespace ZR.Admin.WebApi.Controllers
[AllowAnonymous] [AllowAnonymous]
public class WxOpenController : BaseController public class WxOpenController : BaseController
{ {
private NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
public WxOpenController() { }
/// <summary> /// <summary>
/// 获取签名 /// 获取签名
/// </summary> /// </summary>

View File

@ -75,6 +75,9 @@ namespace ZR.Admin.WebApi.Extensions
//添加文档注释 //添加文档注释
var baseDir = AppContext.BaseDirectory; var baseDir = AppContext.BaseDirectory;
c.IncludeXmlComments(Path.Combine(baseDir, "ZR.Model.xml"), true); c.IncludeXmlComments(Path.Combine(baseDir, "ZR.Model.xml"), true);
c.IncludeXmlComments(Path.Combine(baseDir, "ZR.ServiceCore.xml"), true);
c.IncludeXmlComments(Path.Combine(baseDir, "ZR.Service.xml"), true);
c.IncludeXmlComments(Path.Combine(baseDir, "ZR.Admin.WebApi.xml"), true);
var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml"; var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
var xmlPath = Path.Combine(baseDir, xmlFile); var xmlPath = Path.Combine(baseDir, xmlFile);

View File

@ -6,4 +6,5 @@ global using Infrastructure.Enums;
global using Infrastructure.Model; global using Infrastructure.Model;
global using Mapster; global using Mapster;
global using Infrastructure.Extensions; global using Infrastructure.Extensions;
global using Infrastructure.WebExtensins; global using Infrastructure.Controllers;
global using ZR.ServiceCore.Middleware;

View File

@ -80,8 +80,8 @@
<!--<logger name="System.*" writeTo="blackhole" final="true" />--> <!--<logger name="System.*" writeTo="blackhole" final="true" />-->
<!-- Quartz --> <!-- Quartz -->
<logger name="Quartz*" minlevel="Trace" maxlevel="Info" final="true" /> <logger name="Quartz*" minlevel="Trace" maxlevel="Info" final="true" />
<logger name="ZR.Admin.WebApi.Middleware.GlobalExceptionMiddleware" final="true" writeTo="console,errorfile"/> <logger name="ZR.ServiceCore.Middleware.GlobalExceptionMiddleware" final="true" writeTo="console,errorfile"/>
<logger name="ZR.Admin.WebApi.Extensions.DbExtension" final="true" writeTo="consoleSql,sqlfile"/> <logger name="ZR.ServiceCore.SqlSugar.SqlsugarSetup" final="true" writeTo="consoleSql,sqlfile"/>
<logger name="*" writeTo="console"/> <logger name="*" writeTo="console"/>
<logger name="*" minLevel="Trace" writeTo="allfile" /> <logger name="*" minLevel="Trace" writeTo="allfile" />

View File

@ -1,13 +1,15 @@
using AspNetCoreRateLimit; using AspNetCoreRateLimit;
using Infrastructure.Converter;
using Microsoft.AspNetCore.Authentication.JwtBearer; using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.DataProtection; using Microsoft.AspNetCore.DataProtection;
using Microsoft.IdentityModel.Tokens; using Microsoft.IdentityModel.Tokens;
using System.Text.Json.Serialization; using System.Text.Json.Serialization;
using ZR.Admin.WebApi.Extensions; using ZR.Admin.WebApi.Extensions;
using ZR.Admin.WebApi.Filters;
using ZR.Admin.WebApi.Hubs; using ZR.Admin.WebApi.Hubs;
using ZR.Admin.WebApi.Middleware;
using ZR.Common.Cache; using ZR.Common.Cache;
using ZR.Infrastructure.WebExtensions;
using ZR.ServiceCore.Middleware;
using ZR.ServiceCore.SqlSugar;
var builder = WebApplication.CreateBuilder(args); var builder = WebApplication.CreateBuilder(args);
@ -83,7 +85,7 @@ builder.Services.AddMvc(options =>
options.JsonSerializerOptions.WriteIndented = true; options.JsonSerializerOptions.WriteIndented = true;
options.JsonSerializerOptions.Converters.Add(new JsonConverterUtil.DateTimeConverter()); options.JsonSerializerOptions.Converters.Add(new JsonConverterUtil.DateTimeConverter());
options.JsonSerializerOptions.Converters.Add(new JsonConverterUtil.DateTimeNullConverter()); options.JsonSerializerOptions.Converters.Add(new JsonConverterUtil.DateTimeNullConverter());
options.JsonSerializerOptions.Converters.Add(new Infrastructure.StringConverter()); options.JsonSerializerOptions.Converters.Add(new StringConverter());
}); });
builder.Services.AddSwaggerConfig(); builder.Services.AddSwaggerConfig();
@ -93,7 +95,7 @@ InternalApp.ServiceProvider = app.Services;
InternalApp.Configuration = builder.Configuration; InternalApp.Configuration = builder.Configuration;
InternalApp.WebHostEnvironment = app.Environment; InternalApp.WebHostEnvironment = app.Environment;
//初始化db //初始化db
builder.Services.AddDb(builder.Configuration, app.Environment); builder.Services.AddDb(app.Environment);
//使用全局异常中间件 //使用全局异常中间件
app.UseMiddleware<GlobalExceptionMiddleware>(); app.UseMiddleware<GlobalExceptionMiddleware>();

View File

@ -15,11 +15,9 @@
<ProjectReference Include="..\ZR.Tasks\ZR.Tasks.csproj" /> <ProjectReference Include="..\ZR.Tasks\ZR.Tasks.csproj" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="AspNetCoreRateLimit" Version="5.0.0" />
<PackageReference Include="Lazy.Captcha.Core" Version="2.0.3" /> <PackageReference Include="Lazy.Captcha.Core" Version="2.0.3" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" /> <PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
<PackageReference Include="Swashbuckle.AspNetCore.Filters" Version="7.0.6" /> <PackageReference Include="Swashbuckle.AspNetCore.Filters" Version="7.0.6" />
<PackageReference Include="NLog" Version="5.2.3" />
<PackageReference Include="NLog.Web.AspNetCore" Version="5.3.3" /> <PackageReference Include="NLog.Web.AspNetCore" Version="5.3.3" />
<PackageReference Include="Mapster" Version="7.3.0" /> <PackageReference Include="Mapster" Version="7.3.0" />
<PackageReference Include="SkiaSharp.NativeAssets.Linux" Version="2.88.3" /> <PackageReference Include="SkiaSharp.NativeAssets.Linux" Version="2.88.3" />
@ -33,5 +31,11 @@
<None Update="ip2region.db"> <None Update="ip2region.db">
<CopyToOutputDirectory>Always</CopyToOutputDirectory> <CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None> </None>
<Content Update="wwwroot\Generatecode\**\*">
<CopyToPublishDirectory>Never</CopyToPublishDirectory>
</Content>
<Content Update="wwwroot\export\**\*">
<CopyToPublishDirectory>Never</CopyToPublishDirectory>
</Content>
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@ -33,7 +33,7 @@
"RefreshTokenTime": 5,// "RefreshTokenTime": 5,//
"TokenType": "Bearer" "TokenType": "Bearer"
}, },
"InjectClass": [ "ZR.Repository", "ZR.Service", "ZR.Tasks" ], // "InjectClass": [ "ZR.Repository", "ZR.Service", "ZR.Tasks", "ZR.ServiceCore" ], //
"ShowDbLog": true, //db "ShowDbLog": true, //db
"InitDb": false, //db "InitDb": false, //db
"DemoMode": false, // "DemoMode": false, //
@ -130,6 +130,11 @@
"Endpoint": "((post)|(put)):*", "Endpoint": "((post)|(put)):*",
"Period": "3s", "Period": "3s",
"Limit": 1 "Limit": 1
},
{
"Endpoint": "*:*",
"Period": "5s",
"Limit": 3
} }
] ]
}, },

View File

@ -1,5 +1,6 @@
using Infrastructure; using Infrastructure;
using Infrastructure.Extensions; using Infrastructure.Extensions;
using Infrastructure.Helper;
using Infrastructure.Model; using Infrastructure.Model;
using JinianNet.JNTemplate; using JinianNet.JNTemplate;
using SqlSugar; using SqlSugar;
@ -8,7 +9,6 @@ using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using ZR.CodeGenerator.Model; using ZR.CodeGenerator.Model;
using ZR.Common;
using ZR.Model.System.Generate; using ZR.Model.System.Generate;
namespace ZR.CodeGenerator namespace ZR.CodeGenerator

View File

@ -5,9 +5,9 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\Infrastructure\Infrastructure.csproj" /> <ProjectReference Include="..\Infrastructure\ZR.Infrastructure.csproj" />
<ProjectReference Include="..\ZR.Common\ZR.Common.csproj" /> <ProjectReference Include="..\ZR.Common\ZR.Common.csproj" />
<ProjectReference Include="..\ZR.Model\ZR.Model.csproj" /> <ProjectReference Include="..\ZR.ServiceCore\ZR.ServiceCore.csproj" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

View File

@ -6,14 +6,10 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="Aliyun.OSS.SDK.NetCore" Version="2.13.0" /> <PackageReference Include="Aliyun.OSS.SDK.NetCore" Version="2.13.0" />
<PackageReference Include="CSRedisCore" Version="3.8.670" />
<PackageReference Include="JinianNet.JNTemplate" Version="2.3.3" />
<PackageReference Include="MailKit" Version="4.1.0" /> <PackageReference Include="MailKit" Version="4.1.0" />
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="7.0.0" />
<PackageReference Include="MiniExcel" Version="1.31.2" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\Infrastructure\Infrastructure.csproj" /> <ProjectReference Include="..\Infrastructure\ZR.Infrastructure.csproj" />
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@ -1 +0,0 @@
此文件夹用于存放业务代码数据库实体类

View File

@ -1,9 +0,0 @@
using System;
namespace ZR.Model
{
public enum ProteryConstant
{
NOTNULL = 0
}
}

View File

@ -12,4 +12,8 @@
<PackageReference Include="SqlSugarCoreNoDrive" Version="5.1.4.98" /> <PackageReference Include="SqlSugarCoreNoDrive" Version="5.1.4.98" />
<PackageReference Include="System.ComponentModel.Annotations" Version="5.0.0" /> <PackageReference Include="System.ComponentModel.Annotations" Version="5.0.0" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<Folder Include="Models\" />
</ItemGroup>
</Project> </Project>

View File

@ -5,15 +5,13 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\Infrastructure\Infrastructure.csproj" /> <ProjectReference Include="..\Infrastructure\ZR.Infrastructure.csproj" />
<ProjectReference Include="..\ZR.Model\ZR.Model.csproj" /> <ProjectReference Include="..\ZR.Model\ZR.Model.csproj" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Mapster" Version="7.3.0" /> <PackageReference Include="Mapster" Version="7.3.0" />
<PackageReference Include="Microsoft.Extensions.Options" Version="7.0.1" />
<PackageReference Include="MySqlConnector" Version="2.2.6" /> <PackageReference Include="MySqlConnector" Version="2.2.6" />
<PackageReference Include="NETCore.Encrypt" Version="2.1.1" />
<PackageReference Include="SqlSugar.IOC" Version="2.0.0" /> <PackageReference Include="SqlSugar.IOC" Version="2.0.0" />
<PackageReference Include="SqlSugarCoreNoDrive" Version="5.1.4.98" /> <PackageReference Include="SqlSugarCoreNoDrive" Version="5.1.4.98" />
</ItemGroup> </ItemGroup>

View File

@ -1 +1,4 @@
global using System.Collections.Generic; global using System.Collections.Generic;
global using System;
global using SqlSugar;
global using Newtonsoft.Json;

View File

@ -0,0 +1,59 @@
using Infrastructure;
using Infrastructure.Attribute;
using SqlSugar.IOC;
using ZR.Model.System;
using ZR.Repository;
using ZR.Service.IService;
using ZR.Service.System.IService;
namespace ZR.Service
{
/// <summary>
/// 注意下面的AppService不要漏了
/// </summary>
[AppService(ServiceType = typeof(IHelloService), ServiceLifetime = LifeTime.Transient)]
public class HelloService : BaseService<ArticleCategory>, IHelloService
{
/// <summary>
/// 引用User服务
/// </summary>
private readonly ISysUserService userService;
/// <summary>
///
/// </summary>
/// <param name="userService"></param>
public HelloService(ISysUserService userService)
{
this.userService = userService;
}
/// <summary>
/// 数据库使用案例
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public string SayHello(string name)
{
//构造函数式使用
var user = JsonConvert.SerializeObject(userService.GetFirst(f => f.UserId == 1));
Console.WriteLine(user);
var postService = App.GetRequiredService<ISysPostService>();
Console.WriteLine(JsonConvert.SerializeObject(postService.GetId(1)));
BaseRepository<SysDept> deptRepo = new();
Console.WriteLine(JsonConvert.SerializeObject(deptRepo.GetId(1)));
var result = DbScoped.SugarScope.Queryable<SysDictType>().Where(f => f.DictId == 1).First();
Console.WriteLine(JsonConvert.SerializeObject(result));
//切换库
//DbScoped.SugarScope.GetConnectionScope(2);
GetFirst(x => x.CategoryId == 1);
Context.Queryable<SysUser>().First(f => f.UserId == 1);
return "Hello:" + name;
}
}
}

View File

@ -0,0 +1,17 @@
using ZR.Model.System;
namespace ZR.Service.IService
{
/// <summary>
/// Hello接口
/// </summary>
public interface IHelloService : IBaseService<ArticleCategory>
{
/// <summary>
///
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
string SayHello(string name);
}
}

View File

@ -2,11 +2,14 @@
<PropertyGroup> <PropertyGroup>
<TargetFramework>net7.0</TargetFramework> <TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<NoWarn>1591</NoWarn>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\ZR.Common\ZR.Common.csproj" /> <ProjectReference Include="..\ZR.ServiceCore\ZR.ServiceCore.csproj" />
<ProjectReference Include="..\ZR.Repository\ZR.Repository.csproj" />
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@ -1,10 +1,12 @@
using Microsoft.AspNetCore.Mvc; using Infrastructure;
using Infrastructure.Model;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters; using Microsoft.AspNetCore.Mvc.Filters;
using ZR.Model.System; using ZR.Model.System;
using ZR.Service.System; using ZR.Service.System;
using ZR.Service.System.IService; using ZR.Service.System.IService;
namespace ZR.Admin.WebApi.Filters namespace ZR.ServiceCore.Middleware
{ {
/// <summary> /// <summary>
/// API授权判断 /// API授权判断

View File

@ -1,4 +1,8 @@
using IPTools.Core; using Infrastructure;
using Infrastructure.Attribute;
using Infrastructure.Model;
using IPTools.Core;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Controllers; using Microsoft.AspNetCore.Mvc.Controllers;
using Microsoft.AspNetCore.Mvc.Filters; using Microsoft.AspNetCore.Mvc.Filters;
@ -6,12 +10,12 @@ using NLog;
using ZR.Model.System; using ZR.Model.System;
using ZR.Service.System.IService; using ZR.Service.System.IService;
namespace ZR.Admin.WebApi.Filters namespace ZR.ServiceCore.Middleware
{ {
public class GlobalActionMonitor : ActionFilterAttribute public class GlobalActionMonitor : ActionFilterAttribute
{ {
static readonly Logger logger = LogManager.GetCurrentClassLogger(); static readonly Logger logger = LogManager.GetCurrentClassLogger();
private ISysOperLogService OperLogService; private readonly ISysOperLogService OperLogService;
public GlobalActionMonitor(ISysOperLogService operLogService) public GlobalActionMonitor(ISysOperLogService operLogService)
{ {
OperLogService = operLogService; OperLogService = operLogService;
@ -126,7 +130,7 @@ namespace ZR.Admin.WebApi.Filters
} }
} }
private LogAttribute? GetLogAttribute(ControllerActionDescriptor controllerActionDescriptor) private LogAttribute GetLogAttribute(ControllerActionDescriptor controllerActionDescriptor)
{ {
var attribute = controllerActionDescriptor.MethodInfo.GetCustomAttributes(inherit: true) var attribute = controllerActionDescriptor.MethodInfo.GetCustomAttributes(inherit: true)
.FirstOrDefault(a => a.GetType().Equals(typeof(LogAttribute))); .FirstOrDefault(a => a.GetType().Equals(typeof(LogAttribute)));

View File

@ -1,18 +1,21 @@
using Microsoft.AspNetCore.Mvc; using Infrastructure;
using Infrastructure.Model;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Controllers; using Microsoft.AspNetCore.Mvc.Controllers;
using Microsoft.AspNetCore.Mvc.Filters; using Microsoft.AspNetCore.Mvc.Filters;
using NLog; using ZR.Common;
//本命名空间暂时先不改改动比较大2023年9月2日
namespace ZR.Admin.WebApi.Filters namespace ZR.Admin.WebApi.Filters
{ {
/// <summary> /// <summary>
/// 授权校验访问 /// 授权校验访问
/// 如果跳过授权登录在Action 或controller加上 AllowAnonymousAttribute /// 如果跳过授权登录在Action 或controller加上 AllowAnonymousAttribute
/// </summary> /// </summary>
[AttributeUsage(AttributeTargets.All)]
public class VerifyAttribute : Attribute, IAuthorizationFilter public class VerifyAttribute : Attribute, IAuthorizationFilter
{ {
static readonly Logger logger = LogManager.GetCurrentClassLogger();
/// <summary> /// <summary>
/// 只判断token是否正确不判断权限 /// 只判断token是否正确不判断权限
/// 如果需要判断权限的在Action上加上ApiActionPermission属性标识权限类别ActionPermissionFilter作权限处理 /// 如果需要判断权限的在Action上加上ApiActionPermission属性标识权限类别ActionPermissionFilter作权限处理
@ -32,7 +35,7 @@ namespace ZR.Admin.WebApi.Filters
string ip = HttpContextExtension.GetClientUserIp(context.HttpContext); string ip = HttpContextExtension.GetClientUserIp(context.HttpContext);
string url = context.HttpContext.Request.Path; string url = context.HttpContext.Request.Path;
var isAuthed = context.HttpContext.User.Identity.IsAuthenticated; var isAuthed = context.HttpContext.User.Identity.IsAuthenticated;
string osType = context.HttpContext.Request.Headers["os"];
//使用jwt token校验2020-11-21 //使用jwt token校验2020-11-21
TokenModel loginUser = JwtUtil.GetLoginUser(context.HttpContext); TokenModel loginUser = JwtUtil.GetLoginUser(context.HttpContext);
if (loginUser != null) if (loginUser != null)
@ -48,6 +51,11 @@ namespace ZR.Admin.WebApi.Filters
var newToken = JwtUtil.GenerateJwtToken(JwtUtil.AddClaims(loginUser)); var newToken = JwtUtil.GenerateJwtToken(JwtUtil.AddClaims(loginUser));
CacheHelper.SetCache(CK, CK, 1); CacheHelper.SetCache(CK, CK, 1);
//移动端不加下面这个获取不到自定义Header
if (osType != null)
{
context.HttpContext.Response.Headers.Add("Access-Control-Expose-Headers", "X-Refresh-Token");
}
context.HttpContext.Response.Headers.Add("X-Refresh-Token", newToken); context.HttpContext.Response.Headers.Add("X-Refresh-Token", newToken);
} }
} }

View File

@ -0,0 +1,5 @@
global using Newtonsoft.Json;
global using SqlSugar;
global using System;
global using System.Collections.Generic;
global using Infrastructure.Extensions;

View File

@ -1,12 +1,17 @@
using IPTools.Core; using Infrastructure;
using Infrastructure.Attribute;
using Infrastructure.Model;
using IPTools.Core;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Http.Features;
using NLog; using NLog;
using System.Text.Encodings.Web; using System.Text.Encodings.Web;
using System.Text.Json; using ZR.Common;
using ZR.Model.System; using ZR.Model.System;
using ZR.Service.System.IService; using ZR.Service.System.IService;
using textJson = System.Text.Json;
namespace ZR.Admin.WebApi.Middleware namespace ZR.ServiceCore.Middleware
{ {
/// <summary> /// <summary>
/// 全局异常处理中间件 /// 全局异常处理中间件
@ -62,15 +67,15 @@ namespace ZR.Admin.WebApi.Middleware
logLevel = NLog.LogLevel.Error; logLevel = NLog.LogLevel.Error;
context.Response.StatusCode = 500; context.Response.StatusCode = 500;
} }
var options = new JsonSerializerOptions var options = new textJson.JsonSerializerOptions
{ {
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping, Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping,
PropertyNamingPolicy = JsonNamingPolicy.CamelCase, PropertyNamingPolicy = textJson.JsonNamingPolicy.CamelCase,
WriteIndented = true WriteIndented = true
}; };
ApiResult apiResult = new(code, msg); ApiResult apiResult = new(code, msg);
string responseResult = JsonSerializer.Serialize(apiResult, options).ToLower(); string responseResult = textJson.JsonSerializer.Serialize(apiResult, options);
string ip = HttpContextExtension.GetClientUserIp(context); string ip = HttpContextExtension.GetClientUserIp(context);
var ip_info = IpTool.Search(ip); var ip_info = IpTool.Search(ip);
@ -119,8 +124,8 @@ namespace ZR.Admin.WebApi.Middleware
$"\n> 操作地址:{sysOperLog.OperUrl}" + $"\n> 操作地址:{sysOperLog.OperUrl}" +
$"\n> 错误信息:{msg}\n\n> {error}"; $"\n> 错误信息:{msg}\n\n> {error}";
WxNoticeHelper.SendMsg("系统出错", errorMsg, "", WxNoticeHelper.MsgType.markdown);
SysOperLogService.InsertOperlog(sysOperLog); SysOperLogService.InsertOperlog(sysOperLog);
WxNoticeHelper.SendMsg("系统出错", errorMsg, "", WxNoticeHelper.MsgType.markdown);
} }
public static Endpoint GetEndpoint(HttpContext context) public static Endpoint GetEndpoint(HttpContext context)

Some files were not shown because too many files have changed in this diff Show More