diff --git a/Infrastructure/AppSettings.cs b/Infrastructure/AppSettings.cs index f2a6d2b..f93c764 100644 --- a/Infrastructure/AppSettings.cs +++ b/Infrastructure/AppSettings.cs @@ -45,17 +45,26 @@ namespace Infrastructure public static List App(params string[] sections) { List list = new(); - // 引用 Microsoft.Extensions.Configuration.Binder 包 - Configuration.Bind(string.Join(":", sections), list); + try + { + if (Configuration != null && sections.Any()) + { + Configuration.Bind(string.Join(":", sections), list); + } + } + catch + { + return list; + } return list; } public static T Bind(string key, T t) { Configuration.Bind(key, t); - return t; } + public static T GetAppConfig(string key, T defaultValue = default) { T setting = (T)Convert.ChangeType(Configuration[key], typeof(T)); @@ -74,5 +83,16 @@ namespace Infrastructure { return Configuration[key]; } + + /// + /// 获取配置节点并转换成指定类型 + /// + /// 节点类型 + /// 节点路径 + /// 节点类型实例 + public static T Get(string key) + { + return Configuration.GetSection(key).Get(); + } } } diff --git a/Infrastructure/CustomException/ResultCode.cs b/Infrastructure/CustomException/ResultCode.cs index b8296e7..58739e4 100644 --- a/Infrastructure/CustomException/ResultCode.cs +++ b/Infrastructure/CustomException/ResultCode.cs @@ -7,7 +7,7 @@ namespace Infrastructure [Description("success")] SUCCESS = 200, - [Description("no data")] + [Description("没有更多数据")] NO_DATA = 210, [Description("参数错误")] diff --git a/Infrastructure/Extensions/Extension.Enum.cs b/Infrastructure/Extensions/Extension.Enum.cs index 72710ff..ea8f6af 100644 --- a/Infrastructure/Extensions/Extension.Enum.cs +++ b/Infrastructure/Extensions/Extension.Enum.cs @@ -1,11 +1,7 @@ using System; using System.Collections.Generic; using System.ComponentModel; -using System.Linq; using System.Reflection; -using System.Text; -using System.Threading.Tasks; -//using Newtonsoft.Json; namespace Infrastructure.Extensions { diff --git a/Infrastructure/Helper/XmlCommentHelper.cs b/Infrastructure/Helper/XmlCommentHelper.cs new file mode 100644 index 0000000..984b8ef --- /dev/null +++ b/Infrastructure/Helper/XmlCommentHelper.cs @@ -0,0 +1,375 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Text.RegularExpressions; +using System.Threading.Tasks; +using System.Xml.XPath; + +namespace Infrastructure.Helper +{ + public class XmlCommentHelper + { + private static Regex RefTagPattern = new Regex(@"<(see|paramref) (name|cref)=""([TPF]{1}:)?(?.+?)"" ?/>"); + private static Regex CodeTagPattern = new Regex(@"(?.+?)"); + private static Regex ParaTagPattern = new Regex(@"(?.+?)", RegexOptions.Singleline); + + List navigators = new List(); + + /// + /// 从当前dll文件中加载所有的xml文件 + /// + public void LoadAll() + { + var files = Directory.GetFiles(Directory.GetCurrentDirectory()); + foreach (var file in files) + { + if (string.Equals(Path.GetExtension(file), ".xml", StringComparison.OrdinalIgnoreCase)) + { + Load(file); + } + } + } + /// + /// 从xml中加载 + /// + /// + public void LoadXml(params string[] xmls) + { + foreach (var xml in xmls) + { + Load(new MemoryStream(Encoding.UTF8.GetBytes(xml))); + } + } + /// + /// 从文件中加载 + /// + /// + public void Load(params string[] xmlFiles) + { + foreach (var xmlFile in xmlFiles) + { + var doc = new XPathDocument(xmlFile); + navigators.Add(doc.CreateNavigator()); + + //Console.WriteLine("加载xml文件=" + xmlFile); + } + } + /// + /// 从流中加载 + /// + /// + public void Load(params Stream[] streams) + { + foreach (var stream in streams) + { + var doc = new XPathDocument(stream); + navigators.Add(doc.CreateNavigator()); + } + } + + /// + /// 读取类型中的注释 + /// + /// 类型 + /// 注释路径 + /// 可读性优化(比如:去掉xml标记) + /// + public string GetTypeComment(Type type, string xPath = "summary", bool humanize = true) + { + var typeMemberName = GetMemberNameForType(type); + return GetComment(typeMemberName, xPath, humanize); + } + /// + /// 读取字段或者属性的注释 + /// + /// 字段或者属性 + /// 注释路径 + /// 可读性优化(比如:去掉xml标记) + /// + public string GetFieldOrPropertyComment(MemberInfo fieldOrPropertyInfo, string xPath = "summary", bool humanize = true) + { + var fieldOrPropertyMemberName = GetMemberNameForFieldOrProperty(fieldOrPropertyInfo); + return GetComment(fieldOrPropertyMemberName, xPath, humanize); + } + /// + /// 读取方法中的注释 + /// + /// 方法 + /// 注释路径 + /// 可读性优化(比如:去掉xml标记) + /// + public string GetMethodComment(MethodInfo methodInfo, string xPath = "summary", bool humanize = true) + { + var methodMemberName = GetMemberNameForMethod(methodInfo); + return GetComment(methodMemberName, xPath, humanize); + } + /// + /// 读取方法中的返回值注释 + /// + /// 方法 + /// 可读性优化(比如:去掉xml标记) + /// + public string GetMethodReturnComment(MethodInfo methodInfo, bool humanize = true) + { + return GetMethodComment(methodInfo, "returns", humanize); + } + /// + /// 读取参数的注释 + /// + /// 参数 + /// 可读性优化(比如:去掉xml标记) + /// + public string GetParameterComment(ParameterInfo parameterInfo, bool humanize = true) + { + if (!(parameterInfo.Member is MethodInfo methodInfo)) return string.Empty; + + var methodMemberName = GetMemberNameForMethod(methodInfo); + return GetComment(methodMemberName, $"param[@name='{parameterInfo.Name}']", humanize); + } + /// + /// 读取方法的所有参数的注释 + /// + /// 方法 + /// 可读性优化(比如:去掉xml标记) + /// + public Dictionary GetParameterComments(MethodInfo methodInfo, bool humanize = true) + { + var parameterInfos = methodInfo.GetParameters(); + Dictionary dict = new Dictionary(); + foreach (var parameterInfo in parameterInfos) + { + dict[parameterInfo.Name] = GetParameterComment(parameterInfo, humanize); + } + return dict; + } + /// + /// 读取指定名称节点的注释 + /// + /// 节点名称 + /// 注释路径 + /// 可读性优化(比如:去掉xml标记) + /// + public string GetComment(string name, string xPath, bool humanize = true) + { + foreach (var _xmlNavigator in navigators) + { + var typeSummaryNode = _xmlNavigator.SelectSingleNode($"/doc/members/member[@name='{name}']/{xPath.Trim('/', '\\')}"); + + if (typeSummaryNode != null) + { + return humanize ? Humanize(typeSummaryNode.InnerXml) : typeSummaryNode.InnerXml; + } + } + + return string.Empty; + } + /// + /// 读取指定节点的summary注释 + /// + /// 节点名称 + /// 可读性优化(比如:去掉xml标记) + /// + public string GetSummary(string name, bool humanize = true) + { + return GetComment(name, "summary", humanize); + } + /// + /// 读取指定节点的example注释 + /// + /// 节点名称 + /// 可读性优化(比如:去掉xml标记) + /// + public string GetExample(string name, bool humanize = true) + { + return GetComment(name, "example", humanize); + } + /// + /// 获取方法的节点名称 + /// + /// + /// + public string GetMemberNameForMethod(MethodInfo method) + { + var builder = new StringBuilder("M:"); + + builder.Append(QualifiedNameFor(method.DeclaringType)); + builder.Append($".{method.Name}"); + + var parameters = method.GetParameters(); + if (parameters.Any()) + { + var parametersNames = parameters.Select(p => + { + return p.ParameterType.IsGenericParameter + ? $"`{p.ParameterType.GenericParameterPosition}" + : QualifiedNameFor(p.ParameterType, expandGenericArgs: true); + }); + builder.Append($"({string.Join(",", parametersNames)})"); + } + + return builder.ToString(); + } + /// + /// 获取类型的节点名称 + /// + /// + /// + public string GetMemberNameForType(Type type) + { + var builder = new StringBuilder("T:"); + builder.Append(QualifiedNameFor(type)); + + return builder.ToString(); + } + /// + /// 获取字段或者属性的节点名称 + /// + /// + /// + public string GetMemberNameForFieldOrProperty(MemberInfo fieldOrPropertyInfo) + { + var builder = new StringBuilder(((fieldOrPropertyInfo.MemberType & MemberTypes.Field) != 0) ? "F:" : "P:"); + builder.Append(QualifiedNameFor(fieldOrPropertyInfo.DeclaringType)); + builder.Append($".{fieldOrPropertyInfo.Name}"); + + return builder.ToString(); + } + + private string QualifiedNameFor(Type type, bool expandGenericArgs = false) + { + if (type.IsArray) + return $"{QualifiedNameFor(type.GetElementType(), expandGenericArgs)}[]"; + + var builder = new StringBuilder(); + + if (!string.IsNullOrEmpty(type.Namespace)) + builder.Append($"{type.Namespace}."); + + if (type.IsNested) + { + builder.Append($"{string.Join(".", GetNestedTypeNames(type))}."); + } + + if (type.IsConstructedGenericType && expandGenericArgs) + { + var nameSansGenericArgs = type.Name.Split('`').First(); + builder.Append(nameSansGenericArgs); + + var genericArgsNames = type.GetGenericArguments().Select(t => + { + return t.IsGenericParameter + ? $"`{t.GenericParameterPosition}" + : QualifiedNameFor(t, true); + }); + + builder.Append($"{{{string.Join(",", genericArgsNames)}}}"); + } + else + { + builder.Append(type.Name); + } + + return builder.ToString(); + } + private IEnumerable GetNestedTypeNames(Type type) + { + if (!type.IsNested || type.DeclaringType == null) yield break; + + foreach (var nestedTypeName in GetNestedTypeNames(type.DeclaringType)) + { + yield return nestedTypeName; + } + + yield return type.DeclaringType.Name; + } + private string Humanize(string text) + { + if (text == null) + throw new ArgumentNullException("text"); + + //Call DecodeXml at last to avoid entities like < and > to break valid xml + text = NormalizeIndentation(text); + text = HumanizeRefTags(text); + text = HumanizeCodeTags(text); + text = HumanizeParaTags(text); + text = DecodeXml(text); + return text; + } + private string NormalizeIndentation(string text) + { + string[] lines = text.Split('\n'); + string padding = GetCommonLeadingWhitespace(lines); + + int padLen = padding == null ? 0 : padding.Length; + + // remove leading padding from each line + for (int i = 0, l = lines.Length; i < l; ++i) + { + string line = lines[i].TrimEnd('\r'); // remove trailing '\r' + + if (padLen != 0 && line.Length >= padLen && line.Substring(0, padLen) == padding) + line = line.Substring(padLen); + + lines[i] = line; + } + + // remove leading empty lines, but not all leading padding + // remove all trailing whitespace, regardless + return string.Join("\r\n", lines.SkipWhile(x => string.IsNullOrWhiteSpace(x))).TrimEnd(); + } + private string GetCommonLeadingWhitespace(string[] lines) + { + if (null == lines) + throw new ArgumentException("lines"); + + if (lines.Length == 0) + return null; + + string[] nonEmptyLines = lines + .Where(x => !string.IsNullOrWhiteSpace(x)) + .ToArray(); + + if (nonEmptyLines.Length < 1) + return null; + + int padLen = 0; + + // use the first line as a seed, and see what is shared over all nonEmptyLines + string seed = nonEmptyLines[0]; + for (int i = 0, l = seed.Length; i < l; ++i) + { + if (!char.IsWhiteSpace(seed, i)) + break; + + if (nonEmptyLines.Any(line => line[i] != seed[i])) + break; + + ++padLen; + } + + if (padLen > 0) + return seed.Substring(0, padLen); + + return null; + } + private string HumanizeRefTags(string text) + { + return RefTagPattern.Replace(text, (match) => match.Groups["display"].Value); + } + private string HumanizeCodeTags(string text) + { + return CodeTagPattern.Replace(text, (match) => "{" + match.Groups["display"].Value + "}"); + } + private string HumanizeParaTags(string text) + { + return ParaTagPattern.Replace(text, (match) => "
" + match.Groups["display"].Value); + } + private string DecodeXml(string text) + { + return System.Net.WebUtility.HtmlDecode(text); + } + } +} diff --git a/Infrastructure/Model/ApiResult.cs b/Infrastructure/Model/ApiResult.cs index d322029..cc72c73 100644 --- a/Infrastructure/Model/ApiResult.cs +++ b/Infrastructure/Model/ApiResult.cs @@ -57,12 +57,12 @@ namespace Infrastructure.Model return this; } - /// - /// 返回成功消息 - /// - /// 数据对象 - /// 成功消息 - public static ApiResult Success(object data) { return new ApiResult(HttpStatus.SUCCESS, "success", data); } + ///// + ///// 返回成功消息 + ///// + ///// 数据对象 + ///// < returns > 成功消息 + //public static ApiResult Success(object data) { return new ApiResult(HttpStatus.SUCCESS, "success", data); } /// /// 返回成功消息 @@ -82,7 +82,6 @@ namespace Infrastructure.Model /// /// 访问被拒 /// - /// /// public ApiResult On401() { diff --git a/Infrastructure/OptionsSetting.cs b/Infrastructure/OptionsSetting.cs index 1698580..160ced5 100644 --- a/Infrastructure/OptionsSetting.cs +++ b/Infrastructure/OptionsSetting.cs @@ -1,4 +1,6 @@  +using System.Collections.Generic; + namespace Infrastructure { /// @@ -15,16 +17,19 @@ namespace Infrastructure public ALIYUN_OSS ALIYUN_OSS { get; set; } public JwtSettings JwtSettings { get; set; } public Gen Gen { get; set; } + public List DbConfigs { get; set; } } /// /// 发送邮件数据配置 /// public class MailOptions { - public string From { get; set; } + public string FromName { get; set; } + public string FromEmail { get; set; } public string Password { get; set; } public string Smtp { get; set; } public int Port { get; set; } + public bool UseSsl { get; set; } public string Signature { get; set; } } /// @@ -75,10 +80,19 @@ namespace Infrastructure public class Gen { - public string Conn { get; set; } - public int DbType { get; set; } public string Database { get; set; } - } + public class DbConfigs + { + public string Conn { get; set; } + public int DbType { get; set; } + public string ConfigId { get; set; } + public bool IsAutoCloseConnection { get; set; } + /// + /// 是否代码生成使用库 + /// + public bool IsGenerateDb { get; set; } + public string DbName { get; set; } + } } diff --git a/README.md b/README.md index 07ee1e5..b7afa87 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@

ZR.Admin.NET后台管理系统

-

基于.NET5/.Net7 + vue2.x/vue3.x前后端分离的.net快速开发框架

+

基于.NET5/.Net7 + vue2.x/vue3.x/uniapp前后端分离的.net快速开发框架

@@ -146,6 +146,24 @@ Vue 版前端技术栈 :基于 vue2.x/vue3.x、vuex、vue-router 、vue-cli +## 移动端演示图 + + + + + + + + + + + + + + + +
+ ## 🎉 优势 1. 前台系统不用编写登录、授权、认证模块;只负责编写业务模块即可 diff --git a/ZR.Admin.WebApi/Controllers/BaseController.cs b/ZR.Admin.WebApi/Controllers/BaseController.cs index 90bc9ff..5311026 100644 --- a/ZR.Admin.WebApi/Controllers/BaseController.cs +++ b/ZR.Admin.WebApi/Controllers/BaseController.cs @@ -1,4 +1,5 @@ using Infrastructure; +using Infrastructure.Extensions; using Infrastructure.Model; using Microsoft.AspNetCore.Mvc; using MiniExcelLibs; @@ -12,7 +13,7 @@ namespace ZR.Admin.WebApi.Controllers public class BaseController : ControllerBase { public static string TIME_FORMAT_FULL = "yyyy-MM-dd HH:mm:ss"; - + ///

/// 返回成功封装 /// @@ -29,11 +30,10 @@ namespace ZR.Admin.WebApi.Controllers /// json输出带时间格式的 ///
/// - /// /// - protected IActionResult ToResponse(ApiResult apiResult, string timeFormatStr = "yyyy-MM-dd HH:mm:ss") + protected IActionResult ToResponse(ApiResult apiResult) { - string jsonStr = GetJsonStr(apiResult, timeFormatStr); + string jsonStr = GetJsonStr(apiResult, TIME_FORMAT_FULL); return Content(jsonStr, "application/json"); } @@ -47,7 +47,7 @@ namespace ZR.Admin.WebApi.Controllers protected IActionResult ToResponse(ResultCode resultCode, string msg = "") { - return ToResponse(GetApiResult(resultCode, msg)); + return ToResponse(new ApiResult((int)resultCode, msg)); } /// @@ -62,24 +62,24 @@ namespace ZR.Admin.WebApi.Controllers //string fileDir = Path.Combine(webHostEnvironment.WebRootPath, path, fileName); var stream = Io.File.OpenRead(path); //创建文件流 + + Response.Headers.Add("Access-Control-Expose-Headers", "Content-Disposition"); return File(stream, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", HttpUtility.UrlEncode(fileName)); } - + #region 方法 /// /// 响应返回结果 /// /// 受影响行数 + /// /// - protected ApiResult ToJson(long rows) + protected ApiResult ToJson(long rows, object? data = null) { - return rows > 0 ? GetApiResult(ResultCode.SUCCESS) : GetApiResult(ResultCode.FAIL); - } - protected ApiResult ToJson(long rows, object data) - { - return rows > 0 ? GetApiResult(ResultCode.SUCCESS, data) : GetApiResult(ResultCode.FAIL); + return rows > 0 ? ApiResult.Success("success", data) : GetApiResult(ResultCode.FAIL); } + /// /// 全局Code使用 /// @@ -88,17 +88,17 @@ namespace ZR.Admin.WebApi.Controllers /// protected ApiResult GetApiResult(ResultCode resultCode, object? data = null) { - var apiResult = new ApiResult((int)resultCode, resultCode.ToString()) - { - Data = data - }; + var msg = resultCode.GetDescription(); - return apiResult; - } - protected ApiResult GetApiResult(ResultCode resultCode, string msg) - { - return new ApiResult((int)resultCode, msg); + return new ApiResult((int)resultCode, msg, data); } + + /// + /// + /// + /// + /// + /// private static string GetJsonStr(ApiResult apiResult, string timeFormatStr) { if (string.IsNullOrEmpty(timeFormatStr)) @@ -128,12 +128,20 @@ namespace ZR.Admin.WebApi.Controllers return ExportExcelMini(list, sheetName, fileName).Item1; } + /// + /// + /// + /// + /// + /// + /// + /// protected (string, string) ExportExcelMini(List list, string sheetName, string fileName) { IWebHostEnvironment webHostEnvironment = (IWebHostEnvironment)App.ServiceProvider.GetService(typeof(IWebHostEnvironment)); string sFileName = $"{fileName}{DateTime.Now:MM-dd-HHmmss}.xlsx"; string fullPath = Path.Combine(webHostEnvironment.WebRootPath, "export", sFileName); - + Directory.CreateDirectory(Path.GetDirectoryName(fullPath)); MiniExcel.SaveAs(fullPath, list, sheetName: sheetName); @@ -171,7 +179,7 @@ namespace ZR.Admin.WebApi.Controllers IWebHostEnvironment webHostEnvironment = (IWebHostEnvironment)App.ServiceProvider.GetService(typeof(IWebHostEnvironment)); string sFileName = $"{fileName}模板.xlsx"; string newFileName = Path.Combine(webHostEnvironment.WebRootPath, "ImportTemplate", sFileName); - + if (!Directory.Exists(newFileName)) { Directory.CreateDirectory(Path.GetDirectoryName(newFileName)); diff --git a/ZR.Admin.WebApi/Controllers/CommonController.cs b/ZR.Admin.WebApi/Controllers/CommonController.cs index e2a5b67..20590bc 100644 --- a/ZR.Admin.WebApi/Controllers/CommonController.cs +++ b/ZR.Admin.WebApi/Controllers/CommonController.cs @@ -5,7 +5,6 @@ using Infrastructure.Extensions; using Infrastructure.Model; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Options; -using MiniExcelLibs; using Newtonsoft.Json; using ZR.Admin.WebApi.Extensions; using ZR.Admin.WebApi.Filters; @@ -70,15 +69,15 @@ namespace ZR.Admin.WebApi.Controllers /// 请求参数接收实体 /// [ActionPermissionFilter(Permission = "tool:email:send")] - [Log(Title = "发送邮件", IsSaveRequestData = false)] + [Log(Title = "发送邮件")] [HttpPost] public IActionResult SendEmail([FromBody] SendEmailDto sendEmailVo) { - if (sendEmailVo == null || string.IsNullOrEmpty(sendEmailVo.Subject) || string.IsNullOrEmpty(sendEmailVo.ToUser)) + if (sendEmailVo == null) { return ToResponse(ApiResult.Error($"请求参数不完整")); } - if (string.IsNullOrEmpty(OptionsSetting.MailOptions.From) || string.IsNullOrEmpty(OptionsSetting.MailOptions.Password)) + if (string.IsNullOrEmpty(OptionsSetting.MailOptions.FromEmail) || string.IsNullOrEmpty(OptionsSetting.MailOptions.Password)) { return ToResponse(ApiResult.Error($"请配置邮箱信息")); } @@ -90,11 +89,11 @@ namespace ZR.Admin.WebApi.Controllers { toUsers.Append(mailHelper.FromEmail); } - mailHelper.SendMail(toUsers, sendEmailVo.Subject, sendEmailVo.Content, sendEmailVo.FileUrl, sendEmailVo.HtmlContent); + string result = mailHelper.SendMail(toUsers, sendEmailVo.Subject, sendEmailVo.Content, sendEmailVo.FileUrl, sendEmailVo.HtmlContent); - logger.Info($"发送邮件{JsonConvert.SerializeObject(sendEmailVo)}"); + logger.Info($"发送邮件{JsonConvert.SerializeObject(sendEmailVo)}, 结果{result}"); - return SUCCESS(true); + return SUCCESS(result); } #region 上传 @@ -179,85 +178,29 @@ namespace ZR.Admin.WebApi.Controllers /// /// 初始化种子数据 /// + /// 是否清空数据 /// [HttpGet] - [ApiExplorerSettings(IgnoreApi = true)] [ActionPermissionFilter(Permission = "common")] [Log(BusinessType = BusinessType.INSERT, Title = "初始化数据")] - public IActionResult InitSeedData() + public IActionResult InitSeedData(bool clean = false) { if (!WebHostEnvironment.IsDevelopment()) { - return ToResponse(ResultCode.FAIL, "导入数据失败"); + return ToResponse(ResultCode.CUSTOM_ERROR, "导入数据失败"); } var path = Path.Combine(WebHostEnvironment.WebRootPath, "data.xlsx"); - //var sheetNames = MiniExcel.GetSheetNames(path); SeedDataService seedDataService = new(); - - var sysUser = MiniExcel.Query(path, sheetName: "user").ToList(); - var result1 = seedDataService.InitUserData(sysUser); - - var sysPost = MiniExcel.Query(path, sheetName: "post").ToList(); - var result2 = seedDataService.InitPostData(sysPost); - - var sysRole = MiniExcel.Query(path, sheetName: "role").ToList(); - var result3 = seedDataService.InitRoleData(sysRole); - - var sysUserRole = MiniExcel.Query(path, sheetName: "user_role").ToList(); - var result4 = seedDataService.InitUserRoleData(sysUserRole); - - var sysMenu = MiniExcel.Query(path, sheetName: "menu").ToList(); - var result5 = seedDataService.InitMenuData(sysMenu); - - var sysConfig = MiniExcel.Query(path, sheetName: "config").ToList(); - var result6 = seedDataService.InitConfigData(sysConfig); - - var sysRoleMenu = MiniExcel.Query(path, sheetName: "role_menu").ToList(); - var result7 = seedDataService.InitRoleMenuData(sysRoleMenu); - - var sysDict = MiniExcel.Query(path, sheetName: "dict_type").ToList(); - var result8 = seedDataService.InitDictType(sysDict); - - var sysDictData = MiniExcel.Query(path, sheetName: "dict_data").ToList(); - var result9 = seedDataService.InitDictData(sysDictData); - - var sysDept = MiniExcel.Query(path, sheetName: "dept").ToList(); - var result10 = seedDataService.InitDeptData(sysDept); - - var sysArticleCategory = MiniExcel.Query(path, sheetName: "article_category").ToList(); - var result11 = seedDataService.InitArticleCategoryData(sysArticleCategory); - - var sysTask = MiniExcel.Query(path, sheetName: "task").ToList(); - var result12 = seedDataService.InitTaskData(sysTask); - + var result = seedDataService.InitSeedData(path, clean); Console.ForegroundColor = ConsoleColor.Red; - Console.WriteLine(result1.Item1); - Console.WriteLine(result2.Item1); - Console.WriteLine(result3.Item1); - Console.WriteLine(result4.Item1); - Console.WriteLine(result5.Item1); - Console.WriteLine(result6.Item1); - Console.WriteLine(result7.Item1); - Console.WriteLine(result8.Item1); - Console.WriteLine(result9.Item1); - Console.WriteLine(result10.Item1); - Console.WriteLine(result11.Item1); - Console.WriteLine(result12.Item1); - + foreach (var item in result) + { + Console.WriteLine(item); + } + Console.ForegroundColor = ConsoleColor.White; return SUCCESS(new { - result1 = result1.Item1, - result2 = result2.Item1, - result3 = result3.Item1, - result4 = result4.Item1, - result5 = result5.Item1, - result6 = result6.Item1, - result7 = result7.Item1, - result8 = result8.Item1, - result9 = result9.Item1, - result10 = result10.Item1, - result11 = result11.Item1, - result12 = result12.Item1 + result }); } } diff --git a/ZR.Admin.WebApi/Controllers/System/CodeGeneratorController.cs b/ZR.Admin.WebApi/Controllers/System/CodeGeneratorController.cs index ec6384c..dcfe5c7 100644 --- a/ZR.Admin.WebApi/Controllers/System/CodeGeneratorController.cs +++ b/ZR.Admin.WebApi/Controllers/System/CodeGeneratorController.cs @@ -2,6 +2,7 @@ using Infrastructure.Attribute; using Infrastructure.Enums; using Infrastructure.Extensions; +using IP2Region.Ex.Models; using Mapster; using Microsoft.AspNetCore.Mvc; using SqlSugar; @@ -12,6 +13,7 @@ using ZR.CodeGenerator.Model; using ZR.CodeGenerator.Service; using ZR.Common; using ZR.Model; +using ZR.Model.System; using ZR.Model.System.Dto; using ZR.Model.System.Generate; using ZR.Service.System.IService; @@ -28,16 +30,18 @@ namespace ZR.Admin.WebApi.Controllers private readonly CodeGeneraterService _CodeGeneraterService = new CodeGeneraterService(); private readonly IGenTableService GenTableService; private readonly IGenTableColumnService GenTableColumnService; - + private readonly ISysMenuService SysMenuService; private readonly IWebHostEnvironment WebHostEnvironment; public CodeGeneratorController( IGenTableService genTableService, IGenTableColumnService genTableColumnService, - IWebHostEnvironment webHostEnvironment) + IWebHostEnvironment webHostEnvironment, + ISysMenuService sysMenuService) { GenTableService = genTableService; GenTableColumnService = genTableColumnService; WebHostEnvironment = webHostEnvironment; + SysMenuService = sysMenuService; } /// @@ -149,6 +153,7 @@ namespace ZR.Admin.WebApi.Controllers { throw new CustomException("表不能为空"); } + var dbConfig = AppSettings.Get>("dbConfigs").FirstOrDefault(f => f.IsGenerateDb); string[] tableNames = tables.Split(',', StringSplitOptions.RemoveEmptyEntries); int result = 0; foreach (var tableName in tableNames) @@ -156,15 +161,18 @@ namespace ZR.Admin.WebApi.Controllers var tabInfo = _CodeGeneraterService.GetTableInfo(dbName, tableName); if (tabInfo != null) { + List seqs = new(); GenTable genTable = CodeGeneratorTool.InitTable(dbName, HttpContext.GetName(), tableName, tabInfo?.Description); genTable.TableId = GenTableService.ImportGenTable(genTable); - + if (dbConfig.DbType == 3) + { + seqs = _CodeGeneraterService.GetAllOracleSeqs(dbName); + } if (genTable.TableId > 0) { //保存列信息 List dbColumnInfos = _CodeGeneraterService.GetColumnInfo(dbName, tableName); - List genTableColumns = CodeGeneratorTool.InitGenTableColumn(genTable, dbColumnInfos); - + List genTableColumns = CodeGeneratorTool.InitGenTableColumn(genTable, dbColumnInfos, seqs); GenTableColumnService.DeleteGenTableColumnByTableName(tableName); GenTableColumnService.InsertGenTableColumn(genTableColumns); genTable.Columns = genTableColumns; @@ -227,8 +235,9 @@ namespace ZR.Admin.WebApi.Controllers throw new CustomException(ResultCode.CUSTOM_ERROR, "请求参数为空"); } var genTableInfo = GenTableService.GetGenTableInfo(dto.TableId); + var dbConfig = AppSettings.Get>("dbConfigs").FirstOrDefault(f => f.IsGenerateDb); - dto.DbType = AppSettings.GetAppConfig("gen:dbType", 0); + dto.DbType = dbConfig.DbType; dto.GenTable = genTableInfo; dto.IsPreview = true; //生成代码 @@ -252,16 +261,18 @@ namespace ZR.Admin.WebApi.Controllers throw new CustomException(ResultCode.CUSTOM_ERROR, "请求参数为空"); } var genTableInfo = GenTableService.GetGenTableInfo(dto.TableId); + var dbConfig = AppSettings.Get>("dbConfigs").FirstOrDefault(f => f.IsGenerateDb); - dto.DbType = AppSettings.GetAppConfig("gen:dbType", 0); + dto.DbType = dbConfig.DbType; dto.GenTable = genTableInfo; //自定义路径 if (genTableInfo.GenType == "1") - { + { + var genPath = genTableInfo.GenPath; string tempPath = WebHostEnvironment.ContentRootPath; var parentPath = tempPath[..tempPath.LastIndexOf(@"\")]; //代码生成文件夹路径 - dto.GenCodePath = genTableInfo.GenPath.IsEmpty() ? parentPath : genTableInfo.GenPath; + dto.GenCodePath = (genPath.IsEmpty() || genPath.Equals("/")) ? parentPath : genTableInfo.GenPath; } else { @@ -275,7 +286,10 @@ namespace ZR.Admin.WebApi.Controllers CodeGeneratorTool.Generate(dto); //下载文件 FileUtil.ZipGenCode(dto.ZipPath, dto.GenCodePath, zipReturnFileName); - + if (genTableInfo.Options.GenerateMenu) + { + SysMenuService.AddSysMenu(genTableInfo, dto.ReplaceDto.PermissionPrefix, dto.ReplaceDto.ShowBtnEdit, dto.ReplaceDto.ShowBtnExport); + } return SUCCESS(new { path = "/Generatecode/" + zipReturnFileName, fileName = dto.ZipFileName }); } diff --git a/ZR.Admin.WebApi/Controllers/System/SysDeptController.cs b/ZR.Admin.WebApi/Controllers/System/SysDeptController.cs index 61ea218..e762c8b 100644 --- a/ZR.Admin.WebApi/Controllers/System/SysDeptController.cs +++ b/ZR.Admin.WebApi/Controllers/System/SysDeptController.cs @@ -3,6 +3,7 @@ using Infrastructure.Attribute; using Infrastructure.Enums; using Microsoft.AspNetCore.Mvc; using System.Collections; +using ZR.Admin.WebApi.Extensions; using ZR.Admin.WebApi.Filters; using ZR.Common; using ZR.Model.System; @@ -114,10 +115,10 @@ namespace ZR.Admin.WebApi.Controllers.System { if (UserConstants.NOT_UNIQUE.Equals(DeptService.CheckDeptNameUnique(dept))) { - return ToResponse(GetApiResult(ResultCode.CUSTOM_ERROR, $"新增部门{dept.DeptName}失败,部门名称已存在")); + return ToResponse(ResultCode.CUSTOM_ERROR, $"新增部门{dept.DeptName}失败,部门名称已存在"); } - dept.Create_by = User.Identity.Name; - return ToResponse(ToJson(DeptService.InsertDept(dept))); + dept.Create_by = HttpContext.GetName(); + return ToResponse(DeptService.InsertDept(dept)); } /// @@ -132,14 +133,14 @@ namespace ZR.Admin.WebApi.Controllers.System { if (UserConstants.NOT_UNIQUE.Equals(DeptService.CheckDeptNameUnique(dept))) { - return ToResponse(GetApiResult(ResultCode.CUSTOM_ERROR, $"修改部门{dept.DeptName}失败,部门名称已存在")); + return ToResponse(ResultCode.CUSTOM_ERROR, $"修改部门{dept.DeptName}失败,部门名称已存在"); } else if (dept.ParentId.Equals(dept.DeptId)) { - return ToResponse(GetApiResult(ResultCode.CUSTOM_ERROR, $"修改部门{dept.DeptName}失败,上级部门不能是自己")); + return ToResponse(ResultCode.CUSTOM_ERROR, $"修改部门{dept.DeptName}失败,上级部门不能是自己"); } - dept.Update_by = User.Identity.Name; - return ToResponse(ToJson(DeptService.UpdateDept(dept))); + dept.Update_by = HttpContext.GetName(); + return ToResponse(DeptService.UpdateDept(dept)); } /// @@ -153,11 +154,11 @@ namespace ZR.Admin.WebApi.Controllers.System { if (DeptService.Queryable().Count(it => it.ParentId == deptId && it.DelFlag == "0") > 0) { - return ToResponse(GetApiResult(ResultCode.CUSTOM_ERROR, $"存在下级部门,不允许删除")); + return ToResponse(ResultCode.CUSTOM_ERROR, $"存在下级部门,不允许删除"); } if (UserService.Queryable().Count(it => it.DeptId == deptId && it.DelFlag == 0) > 0) { - return ToResponse(GetApiResult(ResultCode.CUSTOM_ERROR, $"部门存在用户,不允许删除")); + return ToResponse(ResultCode.CUSTOM_ERROR, $"部门存在用户,不允许删除"); } return SUCCESS(DeptService.Delete(deptId)); diff --git a/ZR.Admin.WebApi/Controllers/System/SysDictDataController.cs b/ZR.Admin.WebApi/Controllers/System/SysDictDataController.cs index 2631348..a3cab52 100644 --- a/ZR.Admin.WebApi/Controllers/System/SysDictDataController.cs +++ b/ZR.Admin.WebApi/Controllers/System/SysDictDataController.cs @@ -38,6 +38,14 @@ namespace ZR.Admin.WebApi.Controllers.System public IActionResult List([FromQuery] SysDictData dictData, [FromQuery] PagerInfo pagerInfo) { var list = SysDictDataService.SelectDictDataList(dictData, pagerInfo); + + if (dictData.DictType.StartsWith("sql_")) + { + var result = SysDictService.SelectDictDataByCustomSql(dictData.DictType); + + list.Result.AddRange(result); + list.TotalNum += result.Count; + } return SUCCESS(list); } @@ -75,7 +83,7 @@ namespace ZR.Admin.WebApi.Controllers.System }; if (dic.DictType.StartsWith("cus_") || dic.DictType.StartsWith("sql_")) { - vo.List = SysDictService.SelectDictDataByCustomSql(dic.DictType); + vo.List.AddRange(SysDictService.SelectDictDataByCustomSql(dic.DictType)); } dataVos.Add(vo); } diff --git a/ZR.Admin.WebApi/Controllers/System/SysLoginController.cs b/ZR.Admin.WebApi/Controllers/System/SysLoginController.cs index 0850f9c..a4f3658 100644 --- a/ZR.Admin.WebApi/Controllers/System/SysLoginController.cs +++ b/ZR.Admin.WebApi/Controllers/System/SysLoginController.cs @@ -144,7 +144,7 @@ namespace ZR.Admin.WebApi.Controllers.System long uid = HttpContext.GetUId(); var menus = sysMenuService.SelectMenuTreeByUserId(uid); - return ToResponse(ToJson(1, sysMenuService.BuildMenus(menus))); + return SUCCESS(sysMenuService.BuildMenus(menus)); } /// @@ -152,7 +152,7 @@ namespace ZR.Admin.WebApi.Controllers.System /// /// [HttpGet("captchaImage")] - public ApiResult CaptchaImage() + public IActionResult CaptchaImage() { string uuid = Guid.NewGuid().ToString().Replace("-", ""); @@ -161,7 +161,7 @@ namespace ZR.Admin.WebApi.Controllers.System var info = SecurityCodeHelper.Generate(uuid, 60); var obj = new { captchaOff, uuid, img = info.Base64 };// File(stream, "image/png") - return ToJson(1, obj); + return SUCCESS(obj); } /// diff --git a/ZR.Admin.WebApi/Controllers/System/SysMenuController.cs b/ZR.Admin.WebApi/Controllers/System/SysMenuController.cs index 48f8063..ebfe538 100644 --- a/ZR.Admin.WebApi/Controllers/System/SysMenuController.cs +++ b/ZR.Admin.WebApi/Controllers/System/SysMenuController.cs @@ -119,7 +119,7 @@ namespace ZR.Admin.WebApi.Controllers.System return ToResponse(ApiResult.Error($"修改菜单'{modal.MenuName}'失败,上级菜单不能选择自己")); } modal.Update_by = HttpContext.GetName(); - int result = sysMenuService.EditMenu(modal); + long result = sysMenuService.EditMenu(modal); return ToResponse(result); } @@ -151,7 +151,7 @@ namespace ZR.Admin.WebApi.Controllers.System } menu.Create_by = HttpContext.GetName(); - int result = sysMenuService.AddMenu(menu); + long result = sysMenuService.AddMenu(menu); return ToResponse(result); } diff --git a/ZR.Admin.WebApi/Controllers/System/SysNoticeController.cs b/ZR.Admin.WebApi/Controllers/System/SysNoticeController.cs index 8b7d251..1027660 100644 --- a/ZR.Admin.WebApi/Controllers/System/SysNoticeController.cs +++ b/ZR.Admin.WebApi/Controllers/System/SysNoticeController.cs @@ -45,7 +45,7 @@ namespace ZR.Admin.WebApi.Controllers.System { var predicate = Expressionable.Create(); - predicate = predicate.And(m => m.Status == "0"); + predicate = predicate.And(m => m.Status == 0); var response = _SysNoticeService.GetPages(predicate.ToExpression(), parm); return SUCCESS(response); } @@ -61,9 +61,9 @@ namespace ZR.Admin.WebApi.Controllers.System var predicate = Expressionable.Create(); predicate = predicate.AndIF(!string.IsNullOrEmpty(parm.NoticeTitle), m => m.NoticeTitle.Contains(parm.NoticeTitle)); - predicate = predicate.AndIF(!string.IsNullOrEmpty(parm.NoticeType), m => m.NoticeType == parm.NoticeType); + predicate = predicate.AndIF(parm.NoticeType != null, m => m.NoticeType == parm.NoticeType); predicate = predicate.AndIF(!string.IsNullOrEmpty(parm.CreateBy), m => m.Create_by.Contains(parm.CreateBy) || m.Update_by.Contains(parm.CreateBy)); - predicate = predicate.AndIF(!string.IsNullOrEmpty(parm.Status), m => m.Status == parm.Status); + predicate = predicate.AndIF(parm.Status != null, m => m.Status == parm.Status); var response = _SysNoticeService.GetPages(predicate.ToExpression(), parm); return SUCCESS(response); } @@ -88,14 +88,9 @@ namespace ZR.Admin.WebApi.Controllers.System /// [HttpPost] [ActionPermissionFilter(Permission = "system:notice:add")] - [Log(Title = "通知公告表", BusinessType = BusinessType.INSERT)] + [Log(Title = "发布通告", BusinessType = BusinessType.INSERT)] public IActionResult AddSysNotice([FromBody] SysNoticeDto parm) { - if (parm == null) - { - throw new CustomException("请求参数错误"); - } - //从 Dto 映射到 实体 var modal = parm.Adapt().ToCreate(HttpContext); modal.Create_by = HttpContext.GetName(); modal.Create_time = DateTime.Now; @@ -120,19 +115,13 @@ namespace ZR.Admin.WebApi.Controllers.System /// [HttpPut] [ActionPermissionFilter(Permission = "system:notice:update")] - [Log(Title = "通知公告表", BusinessType = BusinessType.UPDATE)] + [Log(Title = "修改公告", BusinessType = BusinessType.UPDATE)] public IActionResult UpdateSysNotice([FromBody] SysNoticeDto parm) { - if (parm == null) - { - throw new CustomException("请求实体不能为空"); - } - //从 Dto 映射到 实体 var model = parm.Adapt().ToUpdate(HttpContext); - + model.Update_by = HttpContext.GetName(); var response = _SysNoticeService.Update(w => w.NoticeId == model.NoticeId, it => new SysNotice() { - //Update 字段映射 NoticeTitle = model.NoticeTitle, NoticeType = model.NoticeType, NoticeContent = model.NoticeContent, @@ -150,7 +139,7 @@ namespace ZR.Admin.WebApi.Controllers.System /// [HttpPut("send/{NoticeId}")] [ActionPermissionFilter(Permission = "system:notice:update")] - [Log(Title = "通知公告表", BusinessType = BusinessType.OTHER)] + [Log(Title = "发送通知公告", BusinessType = BusinessType.OTHER)] public IActionResult SendNotice(int NoticeId = 0) { if (NoticeId <= 0) @@ -158,7 +147,7 @@ namespace ZR.Admin.WebApi.Controllers.System throw new CustomException("请求实体不能为空"); } var response = _SysNoticeService.GetFirst(x => x.NoticeId == NoticeId); - if (response != null && response.Status == "0") + if (response != null && response.Status == 0) { _hubContext.Clients.All.SendAsync(HubsConstant.ReceiveNotice, response.NoticeTitle, response.NoticeContent); } @@ -171,7 +160,7 @@ namespace ZR.Admin.WebApi.Controllers.System /// [HttpDelete("{ids}")] [ActionPermissionFilter(Permission = "system:notice:delete")] - [Log(Title = "通知公告表", BusinessType = BusinessType.DELETE)] + [Log(Title = "通知公告", BusinessType = BusinessType.DELETE)] public IActionResult DeleteSysNotice(string ids) { int[] idsArr = Tools.SpitIntArrary(ids); @@ -181,20 +170,5 @@ namespace ZR.Admin.WebApi.Controllers.System return SUCCESS(response); } - - /// - /// 通知公告表导出 - /// - /// - [Log(BusinessType = BusinessType.EXPORT, IsSaveResponseData = false, Title = "通知公告表")] - [HttpGet("export")] - [ActionPermissionFilter(Permission = "system:notice:export")] - public IActionResult Export() - { - var list = _SysNoticeService.GetAll(); - - string sFileName = ExportExcel(list, "SysNotice", "通知公告表"); - return SUCCESS(new { path = "/export/" + sFileName, fileName = sFileName }); - } } } \ No newline at end of file diff --git a/ZR.Admin.WebApi/Controllers/System/SysPostController.cs b/ZR.Admin.WebApi/Controllers/System/SysPostController.cs index 49f1b1a..f9820fd 100644 --- a/ZR.Admin.WebApi/Controllers/System/SysPostController.cs +++ b/ZR.Admin.WebApi/Controllers/System/SysPostController.cs @@ -73,7 +73,7 @@ namespace ZR.Admin.WebApi.Controllers.System } post.Create_by = HttpContext.GetName(); - return ToResponse(ToJson(PostService.Add(post))); + return ToResponse(PostService.Add(post)); } /// @@ -109,7 +109,7 @@ namespace ZR.Admin.WebApi.Controllers.System public IActionResult Delete(string id) { int[] ids = Tools.SpitIntArrary(id); - return ToResponse(ToJson(PostService.Delete(ids))); + return ToResponse(PostService.Delete(ids)); } /// diff --git a/ZR.Admin.WebApi/Controllers/System/SysProfileController.cs b/ZR.Admin.WebApi/Controllers/System/SysProfileController.cs index c68be2d..875538b 100644 --- a/ZR.Admin.WebApi/Controllers/System/SysProfileController.cs +++ b/ZR.Admin.WebApi/Controllers/System/SysProfileController.cs @@ -3,12 +3,7 @@ using Infrastructure.Attribute; using Infrastructure.Enums; using Infrastructure.Model; using Mapster; -using Microsoft.AspNetCore.Hosting; -using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; -using Microsoft.Extensions.Options; -using System; -using System.Threading.Tasks; using ZR.Admin.WebApi.Extensions; using ZR.Admin.WebApi.Filters; using ZR.Model.System; diff --git a/ZR.Admin.WebApi/Controllers/System/SysRoleController.cs b/ZR.Admin.WebApi/Controllers/System/SysRoleController.cs index 7e3f7b8..10b89d9 100644 --- a/ZR.Admin.WebApi/Controllers/System/SysRoleController.cs +++ b/ZR.Admin.WebApi/Controllers/System/SysRoleController.cs @@ -11,6 +11,11 @@ using ZR.Service.System.IService; using ZR.Admin.WebApi.Extensions; using ZR.Model.System.Dto; using Mapster; +using ZR.Service; +using Microsoft.AspNetCore.Authorization; +using Aliyun.OSS; +using MiniExcelLibs.OpenXml; +using MiniExcelLibs; namespace ZR.Admin.WebApi.Controllers.System { @@ -22,11 +27,14 @@ namespace ZR.Admin.WebApi.Controllers.System public class SysRoleController : BaseController { private readonly ISysRoleService sysRoleService; + private readonly ISysMenuService sysMenuService; public SysRoleController( - ISysRoleService sysRoleService) + ISysRoleService sysRoleService, + ISysMenuService sysMenuService) { this.sysRoleService = sysRoleService; + this.sysMenuService = sysMenuService; } /// @@ -58,16 +66,16 @@ namespace ZR.Admin.WebApi.Controllers.System /// /// 添加角色 /// - /// + /// /// [HttpPost] [ActionPermissionFilter(Permission = "system:role:add")] [Log(Title = "角色管理", BusinessType = BusinessType.INSERT)] [Route("edit")] - public IActionResult RoleAdd([FromBody] SysRole sysRoleDto) + public IActionResult RoleAdd([FromBody] SysRoleDto dto) { - if (sysRoleDto == null) return ToResponse(ApiResult.Error(101, "请求参数错误")); - + if (dto == null) return ToResponse(ApiResult.Error(101, "请求参数错误")); + SysRole sysRoleDto = dto.Adapt(); if (UserConstants.NOT_UNIQUE.Equals(sysRoleService.CheckRoleKeyUnique(sysRoleDto))) { return ToResponse(ApiResult.Error((int)ResultCode.CUSTOM_ERROR, $"新增角色'{sysRoleDto.RoleName}'失败,角色权限已存在")); @@ -76,24 +84,25 @@ namespace ZR.Admin.WebApi.Controllers.System sysRoleDto.Create_by = HttpContext.GetName(); long roleId = sysRoleService.InsertRole(sysRoleDto); - return ToResponse(ToJson(roleId)); + return ToResponse(roleId); } /// /// 修改角色 /// - /// + /// /// [HttpPut] [ActionPermissionFilter(Permission = "system:role:edit")] [Log(Title = "角色管理", BusinessType = BusinessType.UPDATE)] [Route("edit")] - public IActionResult RoleEdit([FromBody] SysRole sysRoleDto) + public IActionResult RoleEdit([FromBody] SysRoleDto dto) { - if (sysRoleDto == null || sysRoleDto.RoleId <= 0 || string.IsNullOrEmpty(sysRoleDto.RoleKey)) + if (dto == null || dto.RoleId <= 0 || string.IsNullOrEmpty(dto.RoleKey)) { return ToResponse(ApiResult.Error(101, "请求参数错误")); } + SysRole sysRoleDto = dto.Adapt(); sysRoleService.CheckRoleAllowed(sysRoleDto); var info = sysRoleService.SelectRoleById(sysRoleDto.RoleId); if (info != null && info.RoleKey != sysRoleDto.RoleKey) @@ -145,7 +154,7 @@ namespace ZR.Admin.WebApi.Controllers.System long[] roleIds = Tools.SpitLongArrary(roleId); int result = sysRoleService.DeleteRoleByRoleId(roleIds); - return ToResponse(ToJson(result)); + return ToResponse(result); } /// @@ -161,7 +170,7 @@ namespace ZR.Admin.WebApi.Controllers.System sysRoleService.CheckRoleAllowed(roleDto); int result = sysRoleService.UpdateRoleStatus(roleDto); - return ToResponse(ToJson(result)); + return ToResponse(result); } /// @@ -178,5 +187,23 @@ namespace ZR.Admin.WebApi.Controllers.System string sFileName = ExportExcel(list, "sysrole", "角色"); return SUCCESS(new { path = "/export/" + sFileName, fileName = sFileName }); } + + /// + /// 导出角色菜单 + /// + /// + /// + [Log(BusinessType = BusinessType.EXPORT, IsSaveResponseData = false, Title = "角色菜单导出")] + [HttpGet("exportRoleMenu")] + [AllowAnonymous] + public IActionResult ExportRoleMenu(int roleId) + { + MenuQueryDto dto = new() { Status = "0", MenuTypeIds = "M,C,F" }; + + var list = sysMenuService.SelectRoleMenuListByRole(dto, roleId); + + var result = ExportExcelMini(list, roleId.ToString(), "角色菜单"); + return ExportExcel(result.Item2, result.Item1); + } } } diff --git a/ZR.Admin.WebApi/Controllers/System/SysUserController.cs b/ZR.Admin.WebApi/Controllers/System/SysUserController.cs index 7e3d0f7..0f2e2e3 100644 --- a/ZR.Admin.WebApi/Controllers/System/SysUserController.cs +++ b/ZR.Admin.WebApi/Controllers/System/SysUserController.cs @@ -9,6 +9,7 @@ using ZR.Admin.WebApi.Extensions; using ZR.Admin.WebApi.Filters; using ZR.Model; using ZR.Model.System; +using ZR.Model.System.Dto; using ZR.Service.System.IService; namespace ZR.Admin.WebApi.Controllers.System @@ -44,7 +45,7 @@ namespace ZR.Admin.WebApi.Controllers.System /// [ActionPermissionFilter(Permission = "system:user:list")] [HttpGet("list")] - public IActionResult List([FromQuery] SysUser user, PagerInfo pager) + public IActionResult List([FromQuery] SysUserQueryDto user, PagerInfo pager) { var list = UserService.SelectUserList(user, pager); @@ -76,7 +77,7 @@ namespace ZR.Admin.WebApi.Controllers.System dic.Add("roleIds", sysUser.RoleIds); } - return ToResponse(ApiResult.Success(dic)); + return SUCCESS(dic); } /// @@ -132,7 +133,7 @@ namespace ZR.Admin.WebApi.Controllers.System if (user == null) { return ToResponse(ApiResult.Error(101, "请求参数错误")); } int result = UserService.ChangeUserStatus(user); - return ToResponse(ToJson(result)); + return ToResponse(result); } /// @@ -149,7 +150,7 @@ namespace ZR.Admin.WebApi.Controllers.System if (userid == 1) return ToResponse(Infrastructure.ResultCode.FAIL, "不能删除管理员账号"); int result = UserService.DeleteUser(userid); - return ToResponse(ToJson(result)); + return ToResponse(result); } /// @@ -165,7 +166,7 @@ namespace ZR.Admin.WebApi.Controllers.System sysUser.Password = NETCore.Encrypt.EncryptProvider.Md5(sysUser.Password); int result = UserService.ResetPwd(sysUser.UserId, sysUser.Password); - return ToResponse(ToJson(result)); + return ToResponse(result); } /// @@ -181,7 +182,7 @@ namespace ZR.Admin.WebApi.Controllers.System List users = new(); using (var stream = formFile.OpenReadStream()) { - users = stream.Query().ToList(); + users = stream.Query(startCell: "A2").ToList(); } return SUCCESS(UserService.ImportUsers(users)); @@ -208,7 +209,7 @@ namespace ZR.Admin.WebApi.Controllers.System [HttpGet("export")] [Log(Title = "用户导出", BusinessType = BusinessType.EXPORT)] [ActionPermissionFilter(Permission = "system:user:export")] - public IActionResult UserExport([FromQuery] SysUser user) + public IActionResult UserExport([FromQuery] SysUserQueryDto user) { var list = UserService.SelectUserList(user, new PagerInfo(1, 10000)); diff --git a/ZR.Admin.WebApi/Controllers/System/TasksLogController.cs b/ZR.Admin.WebApi/Controllers/System/TasksLogController.cs index aff3178..115db6b 100644 --- a/ZR.Admin.WebApi/Controllers/System/TasksLogController.cs +++ b/ZR.Admin.WebApi/Controllers/System/TasksLogController.cs @@ -64,7 +64,7 @@ namespace ZR.Admin.WebApi.Controllers.System int result = tasksLogService.Delete(jobIdArr); - return ToResponse(ToJson(result, result)); + return ToResponse(result); } /// diff --git a/ZR.Admin.WebApi/Controllers/System/monitor/MonitorController.cs b/ZR.Admin.WebApi/Controllers/System/monitor/MonitorController.cs index 5e82e09..4dc5009 100644 --- a/ZR.Admin.WebApi/Controllers/System/monitor/MonitorController.cs +++ b/ZR.Admin.WebApi/Controllers/System/monitor/MonitorController.cs @@ -30,9 +30,9 @@ namespace ZR.Admin.WebApi.Controllers.monitor /// /// [HttpGet("monitor/cache")] - public ApiResult GetCache() + public IActionResult GetCache() { - return ToJson(1); + return SUCCESS(1); } /// diff --git a/ZR.Admin.WebApi/Controllers/System/monitor/SysOperlogController.cs b/ZR.Admin.WebApi/Controllers/System/monitor/SysOperlogController.cs index 867d32b..a374833 100644 --- a/ZR.Admin.WebApi/Controllers/System/monitor/SysOperlogController.cs +++ b/ZR.Admin.WebApi/Controllers/System/monitor/SysOperlogController.cs @@ -65,15 +65,15 @@ namespace ZR.Admin.WebApi.Controllers.monitor [Log(Title = "清空操作日志", BusinessType = BusinessType.CLEAN)] [ActionPermissionFilter(Permission = "monitor:operlog:delete")] [HttpDelete("clean")] - public ApiResult ClearOperLog() + public IActionResult ClearOperLog() { if (!HttpContextExtension.IsAdmin(HttpContext)) { - return ApiResult.Error("操作失败"); + return ToResponse(Infrastructure.ResultCode.CUSTOM_ERROR,"操作失败"); } sysOperLogService.CleanOperLog(); - return ToJson(1); + return SUCCESS(1); } /// diff --git a/ZR.Admin.WebApi/Extensions/AppServiceExtensions.cs b/ZR.Admin.WebApi/Extensions/AppServiceExtensions.cs index f888f1f..466f372 100644 --- a/ZR.Admin.WebApi/Extensions/AppServiceExtensions.cs +++ b/ZR.Admin.WebApi/Extensions/AppServiceExtensions.cs @@ -1,6 +1,5 @@ -using Infrastructure.Attribute; -using Microsoft.Extensions.DependencyInjection; -using System.Linq; +using Infrastructure; +using Infrastructure.Attribute; using System.Reflection; namespace ZR.Admin.WebApi.Extensions @@ -16,7 +15,11 @@ namespace ZR.Admin.WebApi.Extensions /// public static void AddAppService(this IServiceCollection services) { - string[] cls = new string[] { "ZR.Repository", "ZR.Service", "ZR.Tasks" }; + var cls = AppSettings.Get("InjectClass"); + if (cls == null || cls.Length <= 0) + { + throw new Exception("请更新appsettings类"); + } foreach (var item in cls) { Register(services, item); diff --git a/ZR.Admin.WebApi/Extensions/CorsExtension.cs b/ZR.Admin.WebApi/Extensions/CorsExtension.cs new file mode 100644 index 0000000..1240d80 --- /dev/null +++ b/ZR.Admin.WebApi/Extensions/CorsExtension.cs @@ -0,0 +1,27 @@ +namespace ZR.Admin.WebApi.Extensions +{ + public static class CorsExtension + { + /// + /// 跨域配置 + /// + /// + /// + public static void AddCors(this IServiceCollection services, IConfiguration configuration) + { + var corsUrls = configuration["corsUrls"]?.Split(',', StringSplitOptions.RemoveEmptyEntries); + + //配置跨域 + services.AddCors(c => + { + c.AddPolicy("Policy", policy => + { + policy.WithOrigins(corsUrls ?? Array.Empty()) + .AllowAnyHeader()//允许任意头 + .AllowCredentials()//允许cookie + .AllowAnyMethod();//允许任意方法 + }); + }); + } + } +} diff --git a/ZR.Admin.WebApi/Extensions/DbExtension.cs b/ZR.Admin.WebApi/Extensions/DbExtension.cs index 1e2d7d6..5840448 100644 --- a/ZR.Admin.WebApi/Extensions/DbExtension.cs +++ b/ZR.Admin.WebApi/Extensions/DbExtension.cs @@ -1,13 +1,16 @@ using Infrastructure; -using Infrastructure.Helper; +using Infrastructure.Extensions; using SqlSugar; using SqlSugar.IOC; -using System.Reflection; using ZR.Admin.WebApi.Framework; +using ZR.Model; using ZR.Model.System; namespace ZR.Admin.WebApi.Extensions { + /// + /// sqlsugar 数据处理 + /// public static class DbExtension { private static NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger(); @@ -22,42 +25,60 @@ namespace ZR.Admin.WebApi.Extensions //仅本人数据权限 public static long DATA_SCOPE_SELF = 5; - public static void AddDb(IConfiguration Configuration) + /// + /// 初始化db + /// + /// + /// + /// + public static void AddDb(this IServiceCollection services, IConfiguration Configuration, IWebHostEnvironment environment) { - string connStr = Configuration.GetConnectionString("conn_db"); - int dbType = Convert.ToInt32(Configuration.GetConnectionString("conn_db_type")); + List dbConfigs = Configuration.GetSection("DbConfigs").Get>(); - var iocList = new List() { - new IocConfig() { - ConfigId = "0",//默认db - ConnectionString = connStr, - DbType = (IocDbType)dbType, - IsAutoCloseConnection = true - }, - new IocConfig() { - ConfigId = "1", - ConnectionString = connStr, - DbType = (IocDbType)dbType, - IsAutoCloseConnection = true - } - }; + var iocList = new List(); + foreach (var item in dbConfigs.FindAll(f => !f.IsGenerateDb)) + { + iocList.Add(new IocConfig() + { + ConfigId = item.ConfigId, + ConnectionString = item.Conn, + DbType = (IocDbType)item.DbType, + IsAutoCloseConnection = item.IsAutoCloseConnection + }); + } SugarIocServices.AddSqlSugar(iocList); ICacheService cache = new SqlSugarCache(); SugarIocServices.ConfigurationSugar(db => { - //db0数据过滤 - FilterData(0); + var u = App.User; + if (u != null) + { + FilterData(0); + //ConfigId = 1的数据权限过滤 + //FilterData1(1); + } iocList.ForEach(iocConfig => { SetSugarAop(db, iocConfig, cache); }); }); + + if (Configuration["InitDb"].ParseToBool() == true && environment.IsDevelopment()) + { + InitTable.InitDb(); + } } + /// + /// 数据库Aop设置 + /// + /// + /// + /// private static void SetSugarAop(SqlSugarClient db, IocConfig iocConfig, ICacheService cache) { - var config = db.GetConnection(iocConfig.ConfigId).CurrentConnectionConfig; + var config = db.GetConnectionScope(iocConfig.ConfigId).CurrentConnectionConfig; string configId = config.ConfigId; db.GetConnectionScope(configId).Aop.OnLogExecuting = (sql, pars) => @@ -81,7 +102,6 @@ namespace ZR.Admin.WebApi.Extensions logger.Info(log); } }; - db.GetConnectionScope(configId).Aop.OnError = (ex) => { var pars = db.Utilities.SerializeObject(((SugarParameter[])ex.Parametres).ToDictionary(it => it.ParameterName, it => it.Value)); @@ -89,6 +109,9 @@ namespace ZR.Admin.WebApi.Extensions string sql = "【错误SQL】" + UtilMethods.GetSqlString(config.DbType, ex.Sql, (SugarParameter[])ex.Parametres) + "\r\n"; logger.Error(ex, $"{sql}\r\n{ex.Message}\r\n{ex.StackTrace}"); }; + db.GetConnectionScope(configId).Aop.DataExecuting = (oldValue, entiyInfo) => + { + }; db.GetConnectionScope(configId).CurrentConnectionConfig.MoreSettings = new ConnMoreSettings() { @@ -99,29 +122,58 @@ namespace ZR.Admin.WebApi.Extensions DataInfoCacheService = cache, EntityService = (c, p) => { - if (db.GetConnectionScope(configId).CurrentConnectionConfig.DbType == DbType.PostgreSQL && p.DataType != null && p.DataType.Contains("nvarchar")) + if (p.IsPrimarykey == true)//主键不能为null { - p.DataType = "text"; + p.IsNullable = false; } + else if (p.ExtendedAttribute?.ToString() == ProteryConstant.NOTNULL.ToString()) + { + p.IsNullable = false; + } + else//则否默认为null + { + p.IsNullable = true; + } + + if (config.DbType == DbType.PostgreSQL) + { + if (c.Name == nameof(SysMenu.IsCache) || c.Name == nameof(SysMenu.IsFrame)) + { + p.DataType = "char(1)"; + } + } + #region 兼容Oracle + if (config.DbType == DbType.Oracle) + { + if (p.IsIdentity == true) + { + if (p.EntityName == nameof(SysUser)) + { + p.OracleSequenceName = "SEQ_SYS_USER_USERID"; + } + else if (p.EntityName == nameof(SysRole)) + { + p.OracleSequenceName = "SEQ_SYS_ROLE_ROLEID"; + } + else if (p.EntityName == nameof(SysDept)) + { + p.OracleSequenceName = "SEQ_SYS_DEPT_DEPTID"; + } + else if (p.EntityName == nameof(SysMenu)) + { + p.OracleSequenceName = "SEQ_SYS_MENU_MENUID"; + } + else + { + p.OracleSequenceName = "SEQ_ID"; + } + } + } + #endregion } }; } - /// - /// 初始化db - /// - /// - public static void InitDb(this IServiceProvider service) - { - var db = DbScoped.SugarScope; - //建库:如果不存在创建数据库存在不会重复创建 - db.DbMaintenance.CreateDatabase();// 注意 :Oracle和个别国产库需不支持该方法,需要手动建库 - - var baseType = typeof(SysBase); - var entityes = AssemblyUtils.GetAllTypes().Where(p => !p.IsAbstract && p != baseType && /*p.IsAssignableTo(baseType) && */p.GetCustomAttribute() != null).ToArray(); - db.CodeFirst.SetStringDefaultLength(200).InitTables(entityes); - } - private static object GetParsValue(SugarParameter x) { if (x.DbType == System.Data.DbType.String || x.DbType == System.Data.DbType.DateTime || x.DbType == System.Data.DbType.String) @@ -137,8 +189,6 @@ namespace ZR.Admin.WebApi.Extensions /// 多库id private static void FilterData(int configId) { - var u = App.User; - if (u == null) return; //获取当前用户的信息 var user = JwtUtil.GetLoginUser(App.HttpContext); if (user == null) return; @@ -159,7 +209,7 @@ namespace ZR.Admin.WebApi.Extensions else if (DATA_SCOPE_CUSTOM.Equals(dataScope))//自定数据权限 { //" OR {}.dept_id IN ( SELECT dept_id FROM sys_role_dept WHERE role_id = {} ) ", deptAlias, role.getRoleId())); - + expUser.Or(it => SqlFunc.Subqueryable().Where(f => f.DeptId == it.DeptId && f.RoleId == role.RoleId).Any()); } else if (DATA_SCOPE_DEPT.Equals(dataScope))//本部门数据 @@ -184,5 +234,35 @@ namespace ZR.Admin.WebApi.Extensions db.QueryFilter.AddTableFilter(expLoginlog.ToExpression()); } } + + private static void FilterData1(int configId) + { + //获取当前用户的信息 + var user = JwtUtil.GetLoginUser(App.HttpContext); + if (user == null) return; + var db = DbScoped.SugarScope.GetConnectionScope(configId); + + foreach (var role in user.Roles.OrderBy(f => f.DataScope)) + { + long dataScope = role.DataScope; + if (DATA_SCOPE_ALL.Equals(dataScope))//所有权限 + { + break; + } + else if (DATA_SCOPE_CUSTOM.Equals(dataScope))//自定数据权限 + { + } + else if (DATA_SCOPE_DEPT.Equals(dataScope))//本部门数据 + { + } + else if (DATA_SCOPE_DEPT_AND_CHILD.Equals(dataScope))//本部门及以下数据 + { + + } + else if (DATA_SCOPE_SELF.Equals(dataScope))//仅本人数据 + { + } + } + } } } diff --git a/ZR.Admin.WebApi/Extensions/InitTable.cs b/ZR.Admin.WebApi/Extensions/InitTable.cs new file mode 100644 index 0000000..543f627 --- /dev/null +++ b/ZR.Admin.WebApi/Extensions/InitTable.cs @@ -0,0 +1,53 @@ +using SqlSugar.IOC; +using ZR.Model.Models; +using ZR.Model.System; +using ZR.Model.System.Generate; + +namespace ZR.Admin.WebApi.Extensions +{ + /// + /// 初始化表 + /// + public class InitTable + { + /// + /// 创建db、表 + /// + public static void InitDb() + { + var db = DbScoped.SugarScope; + //建库:如果不存在创建数据库存在不会重复创建 + db.DbMaintenance.CreateDatabase();// 注意 :Oracle和个别国产库需不支持该方法,需要手动建库 + + //var baseType = typeof(SysBase); + //var entityes = AssemblyUtils.GetAllTypes().Where(p => !p.IsAbstract && p != baseType && p.GetCustomAttribute() != null).ToArray(); + //db.CodeFirst.InitTables(entityes); + + //23个表,建议先使用下面方法初始化表,方便排查问题 + db.CodeFirst.InitTables(typeof(SysUser)); + db.CodeFirst.InitTables(typeof(SysRole)); + db.CodeFirst.InitTables(typeof(SysDept)); + db.CodeFirst.InitTables(typeof(SysPost)); + db.CodeFirst.InitTables(typeof(SysFile)); + db.CodeFirst.InitTables(typeof(SysConfig)); + db.CodeFirst.InitTables(typeof(SysNotice)); + db.CodeFirst.InitTables(typeof(SysLogininfor)); + db.CodeFirst.InitTables(typeof(SysOperLog)); + db.CodeFirst.InitTables(typeof(SysMenu)); + db.CodeFirst.InitTables(typeof(SysRoleMenu)); + db.CodeFirst.InitTables(typeof(SysRoleDept)); + db.CodeFirst.InitTables(typeof(SysUserRole)); + db.CodeFirst.InitTables(typeof(SysUserPost)); + db.CodeFirst.InitTables(typeof(SysTasks)); + db.CodeFirst.InitTables(typeof(SysTasksLog)); + db.CodeFirst.InitTables(typeof(CommonLang)); + db.CodeFirst.InitTables(typeof(GenTable)); + db.CodeFirst.InitTables(typeof(GenTableColumn)); + db.CodeFirst.InitTables(typeof(Article)); + db.CodeFirst.InitTables(typeof(ArticleCategory)); + db.CodeFirst.InitTables(typeof(SysDictData)); + db.CodeFirst.InitTables(typeof(SysDictType)); + } + + } +} diff --git a/ZR.Admin.WebApi/Extensions/SwaggerExtension.cs b/ZR.Admin.WebApi/Extensions/SwaggerExtension.cs index 2038144..a4c12f9 100644 --- a/ZR.Admin.WebApi/Extensions/SwaggerExtension.cs +++ b/ZR.Admin.WebApi/Extensions/SwaggerExtension.cs @@ -2,6 +2,7 @@ using Microsoft.AspNetCore.Authentication.JwtBearer; using Microsoft.OpenApi.Models; using Swashbuckle.AspNetCore.Filters; +using System.Reflection; namespace ZR.Admin.WebApi.Extensions { @@ -38,7 +39,7 @@ namespace ZR.Admin.WebApi.Extensions public static void AddSwaggerConfig(this IServiceCollection services) { if (services == null) throw new ArgumentNullException(nameof(services)); - //IWebHostEnvironment hostEnvironment = App.GetRequiredService(); + //IWebHostEnvironment hostEnvironment = services.BuildServiceProvider().GetRequiredService(); services.AddSwaggerGen(c => { @@ -50,11 +51,14 @@ namespace ZR.Admin.WebApi.Extensions }); try { - var tempPath = "";// hostEnvironment.ContentRootPath; + //var tempPath = hostEnvironment.ContentRootPath; //添加文档注释 - c.IncludeXmlComments(Path.Combine(tempPath, "ZRAdmin.xml"), true); - c.IncludeXmlComments(Path.Combine(tempPath, "ZRModel.xml"), true); - //c.IncludeXmlComments(Path.Combine(Directory.GetParent(tempPath).FullName, "ZR.Model", "ZRModel.xml"), true); + var baseDir = AppContext.BaseDirectory; + c.IncludeXmlComments(Path.Combine(baseDir, "ZR.Model.xml"), true); + + var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml"; + var xmlPath = Path.Combine(baseDir, xmlFile); + c.IncludeXmlComments(xmlPath); } catch (Exception ex) { diff --git a/ZR.Admin.WebApi/Extensions/TasksExtension.cs b/ZR.Admin.WebApi/Extensions/TasksExtension.cs index e39c620..3464bc7 100644 --- a/ZR.Admin.WebApi/Extensions/TasksExtension.cs +++ b/ZR.Admin.WebApi/Extensions/TasksExtension.cs @@ -1,8 +1,6 @@ -using Infrastructure; -using Microsoft.AspNetCore.Builder; -using Microsoft.Extensions.DependencyInjection; -using Quartz.Spi; -using System; +using Quartz.Spi; +using SqlSugar.IOC; +using ZR.Model.System; using ZR.Tasks; namespace ZR.Admin.WebApi.Extensions @@ -12,6 +10,11 @@ namespace ZR.Admin.WebApi.Extensions /// public static class TasksExtension { + /// + /// 注册任务 + /// + /// + /// public static void AddTaskSchedulers(this IServiceCollection services) { if (services == null) throw new ArgumentNullException(nameof(services)); @@ -30,11 +33,11 @@ namespace ZR.Admin.WebApi.Extensions { ITaskSchedulerServer _schedulerServer = app.ApplicationServices.GetRequiredService(); - var tasks = SqlSugar.IOC.DbScoped.SugarScope.Queryable() - .Where(m => m.IsStart == 1).ToList(); + var tasks = DbScoped.SugarScope.Queryable() + .Where(m => m.IsStart == 1).ToListAsync(); //程序启动后注册所有定时任务 - foreach (var task in tasks) + foreach (var task in tasks.Result) { var result = _schedulerServer.AddTaskScheduleAsync(task); if (result.Result.Code == 200) diff --git a/ZR.Admin.WebApi/Filters/ActionPermissionFilter.cs b/ZR.Admin.WebApi/Filters/ActionPermissionFilter.cs index 4d66ab2..09fe303 100644 --- a/ZR.Admin.WebApi/Filters/ActionPermissionFilter.cs +++ b/ZR.Admin.WebApi/Filters/ActionPermissionFilter.cs @@ -2,7 +2,7 @@ using Infrastructure.Model; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.Filters; -using ZR.Model.System; +using ZR.Model.System.Dto; namespace ZR.Admin.WebApi.Filters { diff --git a/ZR.Admin.WebApi/Filters/VerifyAttribute.cs b/ZR.Admin.WebApi/Filters/VerifyAttribute.cs index f0ec952..a925b3e 100644 --- a/ZR.Admin.WebApi/Filters/VerifyAttribute.cs +++ b/ZR.Admin.WebApi/Filters/VerifyAttribute.cs @@ -9,7 +9,7 @@ using System; using System.Linq; using ZR.Admin.WebApi.Extensions; using ZR.Admin.WebApi.Framework; -using ZR.Model.System; +using ZR.Model.System.Dto; namespace ZR.Admin.WebApi.Filters { diff --git a/ZR.Admin.WebApi/Framework/JwtUtil.cs b/ZR.Admin.WebApi/Framework/JwtUtil.cs index bb5b9f2..c6ef113 100644 --- a/ZR.Admin.WebApi/Framework/JwtUtil.cs +++ b/ZR.Admin.WebApi/Framework/JwtUtil.cs @@ -6,7 +6,7 @@ using System.IdentityModel.Tokens.Jwt; using System.Security.Claims; using System.Text; using ZR.Admin.WebApi.Extensions; -using ZR.Model.System; +using ZR.Model.System.Dto; using ZR.Service.System; namespace ZR.Admin.WebApi.Framework diff --git a/ZR.Admin.WebApi/Middleware/GlobalExceptionMiddleware.cs b/ZR.Admin.WebApi/Middleware/GlobalExceptionMiddleware.cs index cc97354..3ee7baa 100644 --- a/ZR.Admin.WebApi/Middleware/GlobalExceptionMiddleware.cs +++ b/ZR.Admin.WebApi/Middleware/GlobalExceptionMiddleware.cs @@ -119,7 +119,8 @@ namespace ZR.Admin.WebApi.Middleware context.Response.ContentType = "text/json;charset=utf-8"; await context.Response.WriteAsync(responseResult, System.Text.Encoding.UTF8); - string errorMsg = $"> 操作人:{sysOperLog.OperName} {sysOperLog.OperLocation}" + + string errorMsg = $"> 操作人:{sysOperLog.OperName}" + + $"\n> 操作地区:{sysOperLog.OperIp}({sysOperLog.OperLocation})" + $"\n> 操作模块:{sysOperLog.Title}" + $"\n> 操作地址:{sysOperLog.OperUrl}" + $"\n> 错误信息:{msg}\n\n> {error}"; diff --git a/ZR.Admin.WebApi/Program.cs b/ZR.Admin.WebApi/Program.cs index d217236..9684a36 100644 --- a/ZR.Admin.WebApi/Program.cs +++ b/ZR.Admin.WebApi/Program.cs @@ -1,14 +1,14 @@ +using AspNetCoreRateLimit; using Infrastructure; using Microsoft.AspNetCore.Authentication.JwtBearer; using Microsoft.AspNetCore.DataProtection; -using ZR.Admin.WebApi.Framework; -using Infrastructure.Extensions; +using Microsoft.IdentityModel.Tokens; using ZR.Admin.WebApi.Extensions; using ZR.Admin.WebApi.Filters; -using ZR.Admin.WebApi.Middleware; +using ZR.Admin.WebApi.Framework; using ZR.Admin.WebApi.Hubs; +using ZR.Admin.WebApi.Middleware; using ZR.Common.Cache; -using AspNetCoreRateLimit; var builder = WebApplication.CreateBuilder(args); @@ -20,19 +20,8 @@ builder.Services.AddEndpointsApiExplorer(); builder.Services.AddSwaggerGen(); //注入HttpContextAccessor builder.Services.AddSingleton(); -var corsUrls = builder.Configuration["corsUrls"]?.Split(',', StringSplitOptions.RemoveEmptyEntries); - -//配置跨域 -builder.Services.AddCors(c => -{ - c.AddPolicy("Policy", policy => - { - policy.WithOrigins(corsUrls ?? Array.Empty()) - .AllowAnyHeader()//允许任意头 - .AllowCredentials()//允许cookie - .AllowAnyMethod();//允许任意方法 - }); -}); +// 跨域配置 +builder.Services.AddCors(builder.Configuration); // 显示logo builder.Services.AddLogo(); //注入SignalR实时通讯,默认用json传输 @@ -58,15 +47,26 @@ builder.Services.AddAuthentication(options => .AddJwtBearer(o => { o.TokenValidationParameters = JwtUtil.ValidParameters(); + o.Events = new JwtBearerEvents + { + OnAuthenticationFailed = context => + { + // 如果过期,把过期信息添加到头部 + if (context.Exception.GetType() == typeof(SecurityTokenExpiredException)) + { + context.Response.Headers.Add("Token-Expired", "true"); + } + + return Task.CompletedTask; + } + }; }); //InternalApp.InternalServices = builder.Services; -builder.Services.AddAppService(); builder.Services.AddSingleton(new AppSettings(builder.Configuration)); +builder.Services.AddAppService(); //开启计划任务 builder.Services.AddTaskSchedulers(); -//初始化db -DbExtension.AddDb(builder.Configuration); //注册REDIS 服务 var openRedis = builder.Configuration["RedisServer:open"]; @@ -89,12 +89,11 @@ builder.Services.AddSwaggerConfig(); var app = builder.Build(); InternalApp.ServiceProvider = app.Services; -if (builder.Configuration["InitDb"].ParseToBool() == true && app.Environment.IsDevelopment()) -{ - app.Services.InitDb(); -} +//初始化db +builder.Services.AddDb(builder.Configuration, app.Environment); -app.UseSwagger(); +//使用全局异常中间件 +app.UseMiddleware(); //使可以多次多去body内容 app.Use((context, next) => @@ -120,8 +119,8 @@ app.UseAuthorization(); app.UseResponseCaching(); //恢复/启动任务 app.UseAddTaskSchedulers(); -//使用全局异常中间件 -app.UseMiddleware(); +//使用swagger +app.UseSwagger(); //启用客户端IP限制速率 app.UseIpRateLimiting(); app.UseRateLimiter(); diff --git a/ZR.Admin.WebApi/ZR.Admin.WebApi.csproj b/ZR.Admin.WebApi/ZR.Admin.WebApi.csproj index 18f8c35..927843a 100644 --- a/ZR.Admin.WebApi/ZR.Admin.WebApi.csproj +++ b/ZR.Admin.WebApi/ZR.Admin.WebApi.csproj @@ -3,10 +3,9 @@ net7.0 enable enable - True + true - ZRAdmin.xml 1701;1702;1591,8603,8602,8604,8600 diff --git a/ZR.Admin.WebApi/appsettings.json b/ZR.Admin.WebApi/appsettings.json index a4596e9..762a634 100644 --- a/ZR.Admin.WebApi/appsettings.json +++ b/ZR.Admin.WebApi/appsettings.json @@ -6,23 +6,38 @@ "Microsoft.Hosting.Lifetime": "Information" } }, - "ConnectionStrings": { - "conn_db": "server=8.140.174.251;user=admin;pwd=admin123;database=ZrAdmin", //其他连接字符串请看官方文档 - "conn_db_type": "0" //数据库类型 MySql = 0, SqlServer = 1, Oracle = 3,PgSql = 4 - }, + "dbConfigs": [ + { + "Conn": "Data Source=LAPTOP-STKF2M8H\\SQLEXPRESS;User ID=admin;Password=admin123;Initial Catalog=ZrAdmin;", + "DbType": 1, //数据库类型 MySql = 0, SqlServer = 1, Oracle = 3,PgSql = 4 + "ConfigId": "0", //多租户唯一标识 + "IsAutoCloseConnection": true + }, + { + //代码生成连接字符串,注意{dbName}为固定格式,不要填写数据库名 + "Conn": "Data Source=LAPTOP-STKF2M8H\\SQLEXPRESS;User ID=admin;Password=admin123;Initial Catalog={dbName};", + "DbType": 1, + "ConfigId": "0", + "IsAutoCloseConnection": true, + "DbName": "ZrAdmin", //代码生成默认连接数据库 + "IsGenerateDb": true //是否代码生成使用库,不要改动 + } + //...下面添加更多的数据库源 + ], "urls": "http://localhost:8888", //项目启动url,如果改动端口前端对应devServer也需要进行修改 "corsUrls": "http://localhost:8887", //跨域地址(前端启动项目,前后端分离单独部署需要设置),多个用","隔开 "JwtSettings": { - "Issuer": "ZRAdmin.NET", - "Audience": "ZRAdmin.NET", + "Issuer": "ZRAdmin.NET", //即token的签发者。 + "Audience": "ZRAdmin.NET", //指该token是服务于哪个群体的(群体范围) "SecretKey": "SecretKey-ZRADMIN.NET-20210101", "Expire": 1440 //jwt登录过期时间(分) }, - "InitDb": false,//是否初始化db + "InjectClass": [ "ZR.Repository", "ZR.Service", "ZR.Tasks" ], //自动注入类 + "InitDb": false, //是否初始化db "DemoMode": false, //是否演示模式 "Upload": { "uploadUrl": "http://localhost:8888", //本地存储资源访问路径 - "localSavePath": "uploads", //本地上传默认文件存储目录 wwwroot/uploads + "localSavePath": "uploads", //本地上传默认文件存储目录 wwwroot/uploads, 如果saveType= 2 (请使用完整路径,比如 /home/resource) "maxSize": 15, //上传文件大小限制 15M "notAllowedExt": [ ".bat", ".exe", ".jar", ".js" ] }, @@ -42,19 +57,19 @@ "CorpSecret": "", "SendUser": "@all" }, + //代码生成配置 "gen": { - "conn": "Data Source=LAPTOP-STKF2M8H\\SQLEXPRESS;User ID=admin;Password=admin123;Initial Catalog=ZrAdmin;", - "dbType": 1, //MySql = 0, SqlServer = 1 "autoPre": true, //自动去除表前缀 "author": "admin", "tablePrefix": "sys_", //"表前缀(生成类名不会包含表前缀,多个用逗号分隔)", - "vuePath": "", //前端代码存储路径eg:D:\Work\ZRAdmin-Vue3 - "oracle_db": "" + "vuePath": "" //前端代码存储路径eg:D:\Work\ZRAdmin-Vue3 }, //邮箱配置信息 "MailOptions": { + //发件人名称 + "FromName": "system", //发送人邮箱 - "From": "", //eg:xxxx@qq.com + "FromEmail": "", //eg:xxxx@qq.com //发送人邮箱密码 "Password": "123456", //协议 diff --git a/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/TplControllers.txt b/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/TplControllers.txt index 0690bb6..a15b37d 100644 --- a/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/TplControllers.txt +++ b/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/TplControllers.txt @@ -70,7 +70,8 @@ $end { var response = _${replaceDto.ModelTypeName}Service.GetFirst(x => x.${replaceDto.PKName} == ${replaceDto.PKName}); - return SUCCESS(response); + var info = response.Adapt<${replaceDto.ModelTypeName}>(); + return SUCCESS(info); } $if(replaceDto.ShowBtnAdd) diff --git a/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/TplService.txt b/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/TplService.txt index a3fb503..dd0e30a 100644 --- a/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/TplService.txt +++ b/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/TplService.txt @@ -1,6 +1,7 @@ using System; using SqlSugar; using Infrastructure.Attribute; +using Infrastructure.Extensions; using ${options.BaseNamespace}Model; using ${options.DtosNamespace}; using ${options.ModelsNamespace}.${options.SubNamespace}; diff --git a/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/sql/Other.txt b/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/sql/Other.txt new file mode 100644 index 0000000..c429c89 --- /dev/null +++ b/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/sql/Other.txt @@ -0,0 +1 @@ +请勾选 添加菜单 ,将会自动导入菜单到数据库中 \ No newline at end of file diff --git a/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/v3/TreeVue.txt b/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/v3/TreeVue.txt index f0beb2e..2b888d6 100644 --- a/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/v3/TreeVue.txt +++ b/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/v3/TreeVue.txt @@ -120,9 +120,7 @@ $if(column.HtmlType == "customInput" && column.IsPk == false) $elseif(column.HtmlType == "imageUpload") $elseif(column.HtmlType == "checkbox" || column.HtmlType == "select" || column.HtmlType == "radio") diff --git a/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/v3/Vue.txt b/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/v3/Vue.txt index d2c466e..e79e9c2 100644 --- a/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/v3/Vue.txt +++ b/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/v3/Vue.txt @@ -179,18 +179,7 @@ $if(column.HtmlType == "customInput" && column.IsPk == false) $elseif(column.HtmlType == "imageUpload") $elseif(column.HtmlType == "checkbox" || column.HtmlType.Contains("select") || column.HtmlType == "radio") diff --git a/ZR.Admin.WebApi/wwwroot/ImportTemplate/user.xlsx b/ZR.Admin.WebApi/wwwroot/ImportTemplate/user.xlsx index a8a2b77..74e4f1d 100644 Binary files a/ZR.Admin.WebApi/wwwroot/ImportTemplate/user.xlsx and b/ZR.Admin.WebApi/wwwroot/ImportTemplate/user.xlsx differ diff --git a/ZR.Admin.WebApi/wwwroot/data.xlsx b/ZR.Admin.WebApi/wwwroot/data.xlsx index a5c36f1..5546be9 100644 Binary files a/ZR.Admin.WebApi/wwwroot/data.xlsx and b/ZR.Admin.WebApi/wwwroot/data.xlsx differ diff --git a/ZR.CodeGenerator/CodeGeneratorTool.cs b/ZR.CodeGenerator/CodeGeneratorTool.cs index cf74cb4..26790b6 100644 --- a/ZR.CodeGenerator/CodeGeneratorTool.cs +++ b/ZR.CodeGenerator/CodeGeneratorTool.cs @@ -50,6 +50,7 @@ namespace ZR.CodeGenerator ShowBtnView = dto.GenTable.Options.CheckedBtn.Any(f => f == 5), ShowBtnTruncate = dto.GenTable.Options.CheckedBtn.Any(f => f == 6), ShowBtnMultiDel = dto.GenTable.Options.CheckedBtn.Any(f => f == 7), + ViewFileName = dto.GenTable.BusinessName.FirstUpperCase() }; var columns = dto.GenTable.Columns; @@ -67,7 +68,7 @@ namespace ZR.CodeGenerator GenerateControllers(replaceDto, dto); if (dto.VueVersion == 3) { - GenerateVue3Views(dto); + GenerateVue3Views(replaceDto, dto); } else { @@ -79,7 +80,7 @@ namespace ZR.CodeGenerator } GenerateVueJs(dto); GenerateSql(dto); - + dto.ReplaceDto = replaceDto; if (dto.IsPreview) return; foreach (var item in dto.GenCodes) @@ -182,7 +183,7 @@ namespace ZR.CodeGenerator replaceDto.VueViewFormHtml = GenerateCurdForm(); var tpl = JnHelper.ReadTemplate(CodeTemplateDir, fileName); - var fullPath = Path.Combine(generateDto.VueParentPath, "src", "views", generateDto.GenTable.ModuleName.FirstLowerCase(), $"{generateDto.GenTable.BusinessName.FirstUpperCase()}.vue"); + var fullPath = Path.Combine(generateDto.VueParentPath, "src", "views", generateDto.GenTable.ModuleName.FirstLowerCase(), $"{replaceDto.ViewFileName}.vue"); generateDto.GenCodes.Add(new GenCode(6, "index.vue", fullPath, tpl.Render())); } @@ -191,7 +192,7 @@ namespace ZR.CodeGenerator /// vue3 /// /// - private static void GenerateVue3Views(GenerateDto generateDto) + private static void GenerateVue3Views(ReplaceDto replaceDto, GenerateDto generateDto) { string fileName = generateDto.GenTable.TplCategory switch { @@ -206,7 +207,7 @@ namespace ZR.CodeGenerator tpl.Set("options", generateDto.GenTable?.Options); var result = tpl.Render(); - var fullPath = Path.Combine(generateDto.VueParentPath, "src", "views", generateDto.GenTable.ModuleName.FirstLowerCase(), $"{generateDto.GenTable.BusinessName.FirstUpperCase()}.vue"); + var fullPath = Path.Combine(generateDto.VueParentPath, "src", "views", generateDto.GenTable.ModuleName.FirstLowerCase(), $"{replaceDto.ViewFileName}.vue"); generateDto.GenCodes.Add(new GenCode(16, "index.vue", fullPath, result)); } @@ -240,21 +241,13 @@ namespace ZR.CodeGenerator /// public static void GenerateSql(GenerateDto generateDto) { - var tempName = ""; - switch (generateDto.DbType) + string tempName = generateDto.DbType switch { - case 0: - tempName = "MySqlTemplate"; - break; - case 1: - tempName = "SqlTemplate"; - break; - case 4: - tempName = "PgSql"; - break; - default: - break; - } + 0 => "MySqlTemplate", + 1 => "SqlTemplate", + 4 => "PgSql", + _ => "Other", + }; var tpl = JnHelper.ReadTemplate(CodeTemplateDir, Path.Combine("sql", $"{tempName}.txt")); tpl.Set("parentId", generateDto.GenTable?.Options?.ParentMenuId ?? 0); var result = tpl.Render(); @@ -315,18 +308,8 @@ namespace ZR.CodeGenerator } } } - return tableName.UnderScoreToCamelCase(); - } - - /// - /// 获取前端标签名 - /// - /// - /// - /// - public static string GetLabelName(string columnDescription, string columnName) - { - return string.IsNullOrEmpty(columnDescription) ? columnName : columnDescription; + //return tableName.UnderScoreToCamelCase(); + return tableName.ConvertToPascal("_"); } /// @@ -343,7 +326,7 @@ namespace ZR.CodeGenerator catch (Exception ex) { Console.WriteLine(ex.Message); - return ""; + return str; } } @@ -357,8 +340,8 @@ namespace ZR.CodeGenerator sDatatype = sDatatype.ToLower(); string sTempDatatype = sDatatype switch { - "int" or "number" or "integer" or "smallint" or "int4" or "int8" or "int2" => "int", - "bigint" => "long", + "int" or "integer" or "smallint" or "int4" or "int8" or "int2" => "int", + "bigint" or "number" => "long", "tinyint" => "byte", "numeric" or "real" or "float" => "float", "decimal" or "numer(8,2)" or "numeric" => "decimal", @@ -389,8 +372,8 @@ namespace ZR.CodeGenerator DbName = dbName, BaseNameSpace = "ZR.",//导入默认命名空间前缀 ModuleName = "business",//导入默认模块名 - ClassName = GetClassName(tableName).FirstUpperCase(), - BusinessName = tableName.UnderScoreToCamelCase().FirstUpperCase(), + ClassName = GetClassName(tableName), + BusinessName = GetClassName(tableName), FunctionAuthor = AppSettings.GetConfig(GenConstants.Gen_author), TableName = tableName, TableComment = desc, @@ -412,12 +395,13 @@ namespace ZR.CodeGenerator /// /// /// - public static List InitGenTableColumn(GenTable genTable, List dbColumnInfos) + /// + public static List InitGenTableColumn(GenTable genTable, List dbColumnInfos, List seqs = null) { List genTableColumns = new(); foreach (var column in dbColumnInfos) { - genTableColumns.Add(InitColumnField(genTable, column)); + genTableColumns.Add(InitColumnField(genTable, column, seqs)); } return genTableColumns; } @@ -428,17 +412,26 @@ namespace ZR.CodeGenerator /// /// /// - private static GenTableColumn InitColumnField(GenTable genTable, DbColumnInfo column) + private static GenTableColumn InitColumnField(GenTable genTable, DbColumnInfo column, List seqs) { + var dbConfig = AppSettings.Get>("dbConfigs").FirstOrDefault(f => f.IsGenerateDb); + var dataType = column.DataType; + if (dbConfig.DbType == 3) + { + dataType = column.OracleDataType; + var seqName = $"SEQ_{genTable.TableName}_{column.DbColumnName}"; + var isIdentity = seqs.Any(f => seqName.Equals(f.SEQUENCE_NAME, StringComparison.CurrentCultureIgnoreCase)); + column.IsIdentity = isIdentity; + } GenTableColumn genTableColumn = new() { ColumnName = column.DbColumnName.FirstLowerCase(), ColumnComment = column.ColumnDescription, IsPk = column.IsPrimarykey, - ColumnType = column.DataType, + ColumnType = dataType, TableId = genTable.TableId, TableName = genTable.TableName, - CsharpType = GetCSharpDatatype(column.DataType), + CsharpType = GetCSharpDatatype(dataType), CsharpField = column.DbColumnName.ConvertToPascal("_"), IsRequired = !column.IsNullable, IsIncrement = column.IsIdentity, diff --git a/ZR.CodeGenerator/DbProvider.cs b/ZR.CodeGenerator/DbProvider.cs index 0696d62..afbff3d 100644 --- a/ZR.CodeGenerator/DbProvider.cs +++ b/ZR.CodeGenerator/DbProvider.cs @@ -1,5 +1,4 @@ using Infrastructure; -using Infrastructure.Extensions; using SqlSugar; using System; using System.Collections.Generic; @@ -21,27 +20,22 @@ namespace ZR.CodeGenerator /// public SqlSugarClient GetSugarDbContext(string dbName = "") { - Gen options = new(); - AppSettings.Bind("gen", options); - string connStr = options.Conn; + List dbConfigs = AppSettings.Get>("dbConfigs"); + + DbConfigs configs = dbConfigs.Find(f => f.IsGenerateDb == true); + string connStr = configs.Conn; + if (!string.IsNullOrEmpty(dbName)) { - string replaceStr = GetValue(options.Conn, "Database=", ";"); - string replaceStr2 = GetValue(options.Conn, "Initial Catalog=", ";"); - if (replaceStr.IsNotEmpty()) - { - connStr = options.Conn.Replace(replaceStr, dbName, StringComparison.OrdinalIgnoreCase); - } - if (replaceStr2.IsNotEmpty()) - { - connStr = options.Conn.Replace(replaceStr2, dbName, StringComparison.OrdinalIgnoreCase); - } + configs.DbName = dbName; } + connStr = connStr.Replace("{dbName}", configs.DbName, StringComparison.OrdinalIgnoreCase); + var db = new SqlSugarClient(new List() { new ConnectionConfig(){ ConnectionString = connStr, - DbType = (DbType)options.DbType, + DbType = (DbType)configs.DbType, IsAutoCloseConnection = true,//开启自动释放模式和EF原理一样 InitKeyType = InitKeyType.Attribute,//从特性读取主键和自增列信息 }, diff --git a/ZR.CodeGenerator/GenConstants.cs b/ZR.CodeGenerator/GenConstants.cs index e7bfc94..fe5a8fc 100644 --- a/ZR.CodeGenerator/GenConstants.cs +++ b/ZR.CodeGenerator/GenConstants.cs @@ -7,17 +7,14 @@ namespace ZR.CodeGenerator /// public class GenConstants { - public static string Gen_conn = "gen:conn"; - public static string Gen_conn_dbType = "gen:dbType"; public static string Gen_author = "gen:author"; public static string Gen_autoPre = "gen:autoPre"; public static string Gen_tablePrefix = "gen:tablePrefix"; - public static string Gen_oracle_db = "gen:oracle_db"; /// /// InputDto输入实体是不包含字段 /// - public static readonly string[] inputDtoNoField = new string[] { "createTime", "updateTime", "addtime", "create_time", "update_time" }; + public static readonly string[] inputDtoNoField = new string[] { "createTime", "updateTime", "addtime", "create_time", "update_time", "create_by", "update_by" }; /// /// 图片字段 /// @@ -29,7 +26,7 @@ namespace ZR.CodeGenerator /// /// 单选按钮字段 /// - public static readonly string[] radioFiled = new string[] { "status", "state", "is"}; + public static readonly string[] radioFiled = new string[] { "status", "state", "is" }; /// diff --git a/ZR.CodeGenerator/Model/GenerateDto.cs b/ZR.CodeGenerator/Model/GenerateDto.cs index 47fb4ba..ab35089 100644 --- a/ZR.CodeGenerator/Model/GenerateDto.cs +++ b/ZR.CodeGenerator/Model/GenerateDto.cs @@ -58,6 +58,7 @@ namespace ZR.CodeGenerator.Model /// public string VueParentPath { get; set; } #endregion + public ReplaceDto ReplaceDto { get; set; } } public class GenCode diff --git a/ZR.CodeGenerator/Model/OracleSeq.cs b/ZR.CodeGenerator/Model/OracleSeq.cs new file mode 100644 index 0000000..6a56a30 --- /dev/null +++ b/ZR.CodeGenerator/Model/OracleSeq.cs @@ -0,0 +1,11 @@ +namespace ZR.CodeGenerator.Model +{ + /// + /// Oracle库序列 + /// + public class OracleSeq + { + public string SEQUENCE_NAME { get; set; } + public long LAST_NUMBER { get; set; } + } +} diff --git a/ZR.CodeGenerator/Model/ReplaceDto.cs b/ZR.CodeGenerator/Model/ReplaceDto.cs index 325fd48..6ea178f 100644 --- a/ZR.CodeGenerator/Model/ReplaceDto.cs +++ b/ZR.CodeGenerator/Model/ReplaceDto.cs @@ -65,5 +65,9 @@ namespace ZR.CodeGenerator.Model /// 是否有编辑器 /// public int ShowEditor { get; set; } + /// + /// vue页面文件名 + /// + public string ViewFileName { get; set; } } } diff --git a/ZR.CodeGenerator/Service/CodeGeneraterService.cs b/ZR.CodeGenerator/Service/CodeGeneraterService.cs index fd82340..bbe2557 100644 --- a/ZR.CodeGenerator/Service/CodeGeneraterService.cs +++ b/ZR.CodeGenerator/Service/CodeGeneraterService.cs @@ -2,6 +2,7 @@ using SqlSugar; using System.Collections.Generic; using System.Linq; +using ZR.CodeGenerator.Model; using ZR.Model; namespace ZR.CodeGenerator.Service @@ -16,15 +17,15 @@ namespace ZR.CodeGenerator.Service { var db = GetSugarDbContext(); //Oracle库特殊处理 - var dbType = AppSettings.GetAppConfig(GenConstants.Gen_conn_dbType, 0); - if (dbType == 3) + List dbConfigs = AppSettings.Get>("dbConfigs"); + DbConfigs configs = dbConfigs.Find(f => f.IsGenerateDb == true); + if (configs.DbType == 3) { - var defaultDb = AppSettings.GetAppConfig(GenConstants.Gen_oracle_db, string.Empty); - return new List() { defaultDb }; + return new List() { configs?.DbName }; } var templist = db.DbMaintenance.GetDataBaseList(db); - return templist; + return templist.FindAll(f => !f.Contains("schema")); } /// @@ -72,5 +73,18 @@ namespace ZR.CodeGenerator.Service { return GetSugarDbContext(dbName).DbMaintenance.GetColumnInfosByTableName(tableName, true); } + + /// + /// 获取Oracle所有序列 + /// + /// + /// + public List GetAllOracleSeqs(string dbName) + { + string sql = "SELECT * FROM USER_SEQUENCES"; + var seqs = GetSugarDbContext(dbName).Ado.SqlQuery(sql); + + return seqs.ToList(); + } } } diff --git a/ZR.CodeGenerator/ZR.CodeGenerator.csproj b/ZR.CodeGenerator/ZR.CodeGenerator.csproj index 31c8979..a1a2040 100644 --- a/ZR.CodeGenerator/ZR.CodeGenerator.csproj +++ b/ZR.CodeGenerator/ZR.CodeGenerator.csproj @@ -12,6 +12,6 @@ - + diff --git a/ZR.Common/MailHelper.cs b/ZR.Common/MailHelper.cs index f3984be..79b8b3d 100644 --- a/ZR.Common/MailHelper.cs +++ b/ZR.Common/MailHelper.cs @@ -14,50 +14,18 @@ namespace ZR.Common /// 发送人邮箱 /// public string FromEmail { get; set; } = ""; - /// - /// 发送人密码 - /// - public string FromPwd { get; set; } = ""; - /// - /// 发送协议 - /// - public string Smtp { get; set; } = "smtp.qq.com"; - /// - /// 协议端口 - /// - public int Port { get; set; } = 587; - /// - /// 邮件签名 - /// - public string Signature { get; set; } - /// - /// 是否使用SSL协议 - /// - public bool UseSsl { get; set; } = false; private readonly MailOptions mailOptions = new(); public MailHelper() { AppSettings.Bind("MailOptions", mailOptions); - FromEmail = mailOptions.From; - Smtp = mailOptions.Smtp; - FromPwd = mailOptions.Password; - Port = mailOptions.Port; + FromEmail= mailOptions.FromEmail; } - public MailHelper(string fromEmail, string smtp, int port, string fromPwd) + public MailHelper(MailOptions _mailOptions) { - FromEmail = fromEmail; - Smtp = smtp; - FromPwd = fromPwd; - Port = port; + this.mailOptions = _mailOptions; + FromEmail = _mailOptions.FromEmail; } - - public MailHelper(string fromEmail, string fromPwd) - { - FromEmail = fromEmail; - FromPwd = fromPwd; - } - /// /// 发送一个 /// @@ -65,13 +33,13 @@ namespace ZR.Common /// /// /// - public void SendMail(string toAddress, string subject, string text, string path = "", string html = "") + public string SendMail(string toAddress, string subject, string text, string path = "", string html = "") { IEnumerable mailboxes = new List() { new MailboxAddress(toAddress, toAddress) }; - SendMail(mailboxes, subject, text, path, html); + return SendMail(mailboxes, subject, text, path, html); } /// @@ -81,7 +49,7 @@ namespace ZR.Common /// /// /// - public void SendMail(string[] toAddress, string subject, string text, string path = "", string html = "") + public string SendMail(string[] toAddress, string subject, string text, string path = "", string html = "") { IList mailboxes = new List() { }; foreach (var item in toAddress) @@ -89,7 +57,7 @@ namespace ZR.Common mailboxes.Add(new MailboxAddress(item, item)); } - SendMail(mailboxes, subject, text, path, html); + return SendMail(mailboxes, subject, text, path, html); } /// @@ -100,16 +68,16 @@ namespace ZR.Common /// /// 附件url地址 /// 网页HTML内容 - private void SendMail(IEnumerable toAddress, string subject, string text, string path = "", string html = "") + private string SendMail(IEnumerable toAddress, string subject, string text, string path = "", string html = "") { MimeMessage message = new MimeMessage(); //发件人 - message.From.Add(new MailboxAddress(FromEmail, FromEmail)); + message.From.Add(new MailboxAddress(mailOptions.FromName, mailOptions.FromEmail)); //收件人 message.To.AddRange(toAddress); message.Subject = subject; message.Date = DateTime.Now; - + //创建附件Multipart Multipart multipart = new Multipart("mixed"); var alternative = new MultipartAlternative(); @@ -157,18 +125,18 @@ namespace ZR.Common //开始发送 using var client = new SmtpClient(); client.ServerCertificateValidationCallback = (s, c, h, e) => true; + //client.CheckCertificateRevocation = false; + client.Connect(mailOptions.Smtp, mailOptions.Port, mailOptions.UseSsl); - //Smtp服务器 - //client.Connect("smtp.qq.com", 587, false); - client.Connect(Smtp, Port, true); //登录,发送 //特别说明,对于服务器端的中文相应,Exception中有编码问题,显示乱码了 - client.Authenticate(FromEmail, FromPwd); + client.Authenticate(System.Text.Encoding.UTF8, mailOptions.FromEmail, mailOptions.Password); - client.Send(message); + var result = client.Send(message); //断开 client.Disconnect(true); - Console.WriteLine($"发送邮件成功{DateTime.Now}"); + Console.WriteLine($"【{DateTime.Now}】发送邮件结果{result}"); + return result; } } } \ No newline at end of file diff --git a/ZR.Model/ProteryConstant.cs b/ZR.Model/ProteryConstant.cs new file mode 100644 index 0000000..382c459 --- /dev/null +++ b/ZR.Model/ProteryConstant.cs @@ -0,0 +1,9 @@ +using System; + +namespace ZR.Model +{ + public enum ProteryConstant + { + NOTNULL = 0 + } +} diff --git a/ZR.Model/System/Article.cs b/ZR.Model/System/Article.cs index a5ecfb3..52854ae 100644 --- a/ZR.Model/System/Article.cs +++ b/ZR.Model/System/Article.cs @@ -6,7 +6,7 @@ namespace ZR.Model.System /// /// 文章表 /// - [SugarTable("article")] + [SugarTable("article", "文章管理")] [Tenant("0")] public class Article { @@ -18,54 +18,64 @@ namespace ZR.Model.System /// /// 文章标题 /// + [SugarColumn(ColumnDescription = "文章标题", Length = 254, ExtendedAttribute = ProteryConstant.NOTNULL)] public string Title { get; set; } /// /// 发布时间 /// + [SugarColumn(ColumnDescription = "发布时间")] public DateTime? CreateTime { get; set; } /// /// 更新时间 /// - [SugarColumn(IsOnlyIgnoreInsert = true)] + [SugarColumn(IsOnlyIgnoreInsert = true, ColumnDescription = "更新时间")] public DateTime? UpdateTime { get; set; } /// /// 文章内容 /// + [SugarColumn(ColumnDescription = "文章内容", ColumnDataType = StaticConfig.CodeFirst_BigString)] public string Content { get; set; } /// /// 作者名 /// + [SugarColumn(ColumnDescription = "作者名", Length = 20, ExtendedAttribute = ProteryConstant.NOTNULL)] public string AuthorName { get; set; } /// /// 发布者用户id /// + [SugarColumn(ColumnDescription = "发布者用户id", ExtendedAttribute = ProteryConstant.NOTNULL)] public long UserId { get; set; } /// /// 文章状态 1、发布 2、草稿 /// + [SugarColumn(ColumnDescription = "文章状态 1、发布 2、草稿", Length = 20)] public string Status { get; set; } /// /// 编辑器类型 markdown,html /// - [SugarColumn(ColumnName = "fmt_type")] + [SugarColumn(ColumnDescription = "编辑器类型markdown,html", ColumnName = "fmt_type", Length = 20, IsNullable = true)] public string FmtType { get; set; } /// /// 文章标签eg:Net5,java /// + [SugarColumn(ColumnDescription = "文章标签", Length = 20)] public string Tags { get; set; } /// /// 点击量 /// + [SugarColumn(ColumnDescription = "点击量", DefaultValue = "0")] public int Hits { get; set; } - [SugarColumn(ColumnName = "category_Id")] + [SugarColumn(ColumnDescription = "目录id", ColumnName = "category_Id")] public int CategoryId { get; set; } /// /// 封面地址 /// + [SugarColumn(ColumnDescription = "封面地址", Length = 255)] public string CoverUrl { get; set; } /// /// 是否公开 1、公开 0、不公开 /// + [SugarColumn(ColumnDescription = "是否公开 1、公开 0、不公开", DefaultValue = "0")] public int IsPublic { get; set; } [Navigate(NavigateType.OneToOne, nameof(CategoryId), nameof(ArticleCategory.CategoryId))] //自定义关系映射 diff --git a/ZR.Model/System/ArticleCategory.cs b/ZR.Model/System/ArticleCategory.cs index d10569b..934b257 100644 --- a/ZR.Model/System/ArticleCategory.cs +++ b/ZR.Model/System/ArticleCategory.cs @@ -8,18 +8,20 @@ namespace ZR.Model.System /// /// 文章目录 /// - [SugarTable("articleCategory")] + [SugarTable("articleCategory", "文章目录")] [Tenant("0")] public class ArticleCategory { /// /// 目录id /// - [SugarColumn(IsPrimaryKey = true, ColumnName = "Category_id")] + [SugarColumn(IsPrimaryKey = true, IsIdentity = true, ColumnName = "category_id")] public int CategoryId { get; set; } + + [SugarColumn(ColumnDescription = "目录名", Length = 20, ExtendedAttribute = ProteryConstant.NOTNULL)] public string Name { get; set; } - public int ParentId { get; set; } - [SugarColumn(ColumnName = "create_time", IsNullable = true)] + public int? ParentId { get; set; } + [SugarColumn(ColumnDescription = "创建时间", ColumnName = "create_time")] public DateTime? CreateTime { get; set; } [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] diff --git a/ZR.Model/System/CommonLang.cs b/ZR.Model/System/CommonLang.cs index 8f27bb0..883e46e 100644 --- a/ZR.Model/System/CommonLang.cs +++ b/ZR.Model/System/CommonLang.cs @@ -9,7 +9,7 @@ namespace ZR.Model.Models /// 多语言配置,数据实体对象 /// [Tenant("0")] - [SugarTable("sys_common_lang")] + [SugarTable("sys_common_lang", "多语言配置表")] public class CommonLang { /// @@ -23,21 +23,21 @@ namespace ZR.Model.Models /// 语言code /// [DisplayName("语言code")] - [SugarColumn(ColumnName = "lang_code", IsNullable = false)] + [SugarColumn(ColumnName = "lang_code", Length = 10, ExtendedAttribute = ProteryConstant.NOTNULL)] public string LangCode { get; set; } /// /// 语言key /// [DisplayName("语言key")] - [SugarColumn(ColumnName = "lang_key")] + [SugarColumn(ColumnName = "lang_key", Length = 100, ExtendedAttribute = ProteryConstant.NOTNULL)] public string LangKey { get; set; } /// /// 名称 /// [DisplayName("名称")] - [SugarColumn(ColumnName = "lang_name", IsNullable = false)] + [SugarColumn(ColumnName = "lang_name", Length = 2000, ExtendedAttribute = ProteryConstant.NOTNULL)] public string LangName { get; set; } /// diff --git a/ZR.Model/System/LoginUser.cs b/ZR.Model/System/Dto/LoginUser.cs similarity index 97% rename from ZR.Model/System/LoginUser.cs rename to ZR.Model/System/Dto/LoginUser.cs index 4ded62a..8bf08d7 100644 --- a/ZR.Model/System/LoginUser.cs +++ b/ZR.Model/System/Dto/LoginUser.cs @@ -1,7 +1,7 @@ using System.Collections.Generic; using System.Linq; -namespace ZR.Model.System +namespace ZR.Model.System.Dto { /// /// 登录用户信息存储 diff --git a/ZR.Model/System/Dto/MenuDto.cs b/ZR.Model/System/Dto/MenuDto.cs index b75a59e..32ffaed 100644 --- a/ZR.Model/System/Dto/MenuDto.cs +++ b/ZR.Model/System/Dto/MenuDto.cs @@ -1,4 +1,6 @@ -using System; +using MiniExcelLibs.Attributes; +using System; +using System.Collections.Generic; using System.ComponentModel.DataAnnotations; namespace ZR.Model.System.Dto @@ -7,7 +9,9 @@ namespace ZR.Model.System.Dto { //{"parentId":0,"menuName":"aaa","icon":"documentation","menuType":"M","orderNum":999,"visible":0,"status":0,"path":"aaa"} [Required(ErrorMessage = "菜单id不能为空")] + [ExcelColumn(Name = "菜单id")] public int MenuId { get; set; } + [ExcelColumn(Name = "菜单名")] public string MenuName { get; set; } /// /// 父菜单ID @@ -22,22 +26,25 @@ namespace ZR.Model.System.Dto /// /// 路由地址 /// + [ExcelColumn(Name = "路由地址")] public string Path { get; set; } = "#"; /// /// 组件路径 /// + [ExcelColumn(Name = "组件地址")] public string Component { get; set; } /// /// 是否缓存(1缓存 0不缓存) /// [Required(ErrorMessage = "是否缓存不能为空")] - public string IsCache { get; set; } + [ExcelColumn(Name = "是否缓存")] + public int IsCache { get; set; } /// /// 是否外链 1、是 0、否 /// - public string IsFrame { get; set; } + public int IsFrame { get; set; } /// /// 类型(M目录 C菜单 F按钮 L链接) @@ -60,6 +67,7 @@ namespace ZR.Model.System.Dto /// /// 权限字符串 /// + [ExcelColumn(Name = "权限字符串")] public string Perms { get; set; } /// @@ -70,6 +78,7 @@ namespace ZR.Model.System.Dto /// 翻译key /// public string MenuNameKey { get; set; } + public List Children { get; set; } = new List(); } public class MenuQueryDto diff --git a/ZR.Model/System/Dto/RoleMenuExportDto.cs b/ZR.Model/System/Dto/RoleMenuExportDto.cs new file mode 100644 index 0000000..9145137 --- /dev/null +++ b/ZR.Model/System/Dto/RoleMenuExportDto.cs @@ -0,0 +1,30 @@ +using MiniExcelLibs.Attributes; +using SqlSugar.DbConvert; +using ZR.Model.System.Enums; + +namespace ZR.Model.System.Dto +{ + public class RoleMenuExportDto + { + /// + /// 一级目录名 + /// + [ExcelColumn(Name = "菜单", Width = 50)] + public string MenuName { get; set; } + //[ExcelColumn(Name = "菜单名", Width = 20)] + //public string MenuName1 { get; set; } + //[ExcelColumn(Name = "权限按钮", Width = 20)] + //public string MenuName2 { get; set; } + [ExcelColumn(Name = "路径", Width = 20)] + public string Path { get; set; } + [ExcelColumn(Name = "组件名", Width = 20)] + public string Component { get; set; } + [ExcelColumn(Name = "权限字符", Width = 20)] + public string Perms { get; set; } + //[ExcelColumn(Name = "菜单类型")] + //[SqlSugar.SugarColumn(SqlParameterDbType = typeof(EnumToStringConvert))] + //public MenuType MenuType { get; set; } + //[ExcelColumn(Name = "菜单状态")] + //public MenuStatus Status { get; set; } + } +} diff --git a/ZR.Model/System/Dto/SysNoticeDto.cs b/ZR.Model/System/Dto/SysNoticeDto.cs index 26e23d9..e770064 100644 --- a/ZR.Model/System/Dto/SysNoticeDto.cs +++ b/ZR.Model/System/Dto/SysNoticeDto.cs @@ -1,3 +1,5 @@ +using System.ComponentModel.DataAnnotations; + namespace ZR.Model.System.Dto { /// @@ -6,10 +8,11 @@ namespace ZR.Model.System.Dto public class SysNoticeDto { public int NoticeId { get; set; } + [Required] public string NoticeTitle { get; set; } - public string NoticeType { get; set; } + public int NoticeType { get; set; } public string NoticeContent { get; set; } - public string Status { get; set; } + public int Status { get; set; } public string Remark { get; set; } } @@ -19,8 +22,8 @@ namespace ZR.Model.System.Dto public class SysNoticeQueryDto : PagerInfo { public string NoticeTitle { get; set; } - public string NoticeType { get; set; } + public int? NoticeType { get; set; } public string CreateBy { get; set; } - public string Status { get; set; } + public int? Status { get; set; } } } diff --git a/ZR.Model/System/Dto/SysRoleDto.cs b/ZR.Model/System/Dto/SysRoleDto.cs index 1ff297f..8ad6866 100644 --- a/ZR.Model/System/Dto/SysRoleDto.cs +++ b/ZR.Model/System/Dto/SysRoleDto.cs @@ -12,10 +12,15 @@ namespace ZR.Model.System.Dto public string RoleName { get; set; } public string RoleKey { get; set; } public int RoleSort { get; set; } - public string Status { get; set; } + public int Status { get; set; } + public int DataScope { get; set; } + public int[] DeptIds { get; set; } /// /// 减少菜单集合 /// public List DelMenuIds { get; set; } = new List(); + public bool MenuCheckStrictly { get; set; } + public bool DeptCheckStrictly { get; set; } + } } diff --git a/ZR.Model/System/Dto/SysUserDto.cs b/ZR.Model/System/Dto/SysUserDto.cs index 771d501..d8ba37a 100644 --- a/ZR.Model/System/Dto/SysUserDto.cs +++ b/ZR.Model/System/Dto/SysUserDto.cs @@ -1,4 +1,6 @@ -namespace ZR.Model.System.Dto +using System; + +namespace ZR.Model.System.Dto { public class SysUserDto { @@ -13,4 +15,22 @@ /// public int Sex { get; set; } } + + public class SysUserQueryDto + { + public long UserId { get; set; } + public string UserName { get; set; } + public string NickName { get; set; } + public string Email { get; set; } + public string Remark { get; set; } + public string Phonenumber { get; set; } + /// + /// 用户性别(0男 1女 2未知) + /// + public int Sex { get; set; } + public DateTime? BeginTime { get; set; } + public DateTime? EndTime { get; set; } + public int Status { get; set; } + public long DeptId { get; set; } + } } diff --git a/ZR.Model/System/Enums/MenuStatus.cs b/ZR.Model/System/Enums/MenuStatus.cs new file mode 100644 index 0000000..b648ca1 --- /dev/null +++ b/ZR.Model/System/Enums/MenuStatus.cs @@ -0,0 +1,15 @@ +using System.ComponentModel; + +namespace ZR.Model.System.Enums +{ + /// + /// 菜单状态(0正常 1停用) + /// + public enum MenuStatus + { + [Description("正常")] + 正常 = 0, + [Description("停用")] + 停用 = 1, + } +} diff --git a/ZR.Model/System/Enums/MenuType.cs b/ZR.Model/System/Enums/MenuType.cs new file mode 100644 index 0000000..4325223 --- /dev/null +++ b/ZR.Model/System/Enums/MenuType.cs @@ -0,0 +1,19 @@ +using System.ComponentModel; + +namespace ZR.Model.System.Enums +{ + /// + /// M目录 C菜单 F按钮 L链接 + /// + public enum MenuType + { + [Description("目录")] + M, + [Description("菜单")] + C, + [Description("按钮")] + F, + [Description("链接")] + L + } +} diff --git a/ZR.Model/System/Generate/GenTable.cs b/ZR.Model/System/Generate/GenTable.cs index cde1f43..ec49963 100644 --- a/ZR.Model/System/Generate/GenTable.cs +++ b/ZR.Model/System/Generate/GenTable.cs @@ -1,38 +1,44 @@ -using System.Collections.Generic; +using SqlSugar; +using System.Collections.Generic; namespace ZR.Model.System.Generate { /// /// 代码生成表 /// - [SqlSugar.SugarTable("gen_table")] - [SqlSugar.Tenant("0")] + [SugarTable("gen_table", "代码生成表")] + [Tenant("0")] public class GenTable : SysBase { /// /// 表id /// - [SqlSugar.SugarColumn(IsPrimaryKey = true, IsIdentity = true)] - public int TableId { get; set; } + [SugarColumn(IsPrimaryKey = true, IsIdentity = true)] + public long TableId { get; set; } /// /// 数据库名 /// + [SugarColumn(Length = 50)] public string DbName { get; set; } /// /// 表名 /// + [SugarColumn(Length = 150)] public string TableName { get; set; } /// /// 表描述 /// + [SugarColumn(Length = 150)] public string TableComment { get; set; } /// /// 关联父表的表名 /// + [SugarColumn(Length = 150)] public string SubTableName { get; set; } /// /// 本表关联父表的外键名 /// + [SugarColumn(Length = 150)] public string SubTableFkName { get; set; } /// /// csharp类名 @@ -41,18 +47,22 @@ namespace ZR.Model.System.Generate /// /// 使用的模板(crud单表操作 tree树表操作 sub主子表操作) /// + [SugarColumn(Length = 50, DefaultValue = "crud")] public string TplCategory { get; set; } /// /// 基本命名空间前缀 /// + [SugarColumn(Length = 100)] public string BaseNameSpace { get; set; } /// /// 生成模块名 /// + [SugarColumn(Length = 50)] public string ModuleName { get; set; } /// /// 生成业务名 /// + [SugarColumn(Length = 50)] public string BusinessName { get; set; } /// /// 生成功能名 @@ -65,23 +75,30 @@ namespace ZR.Model.System.Generate /// /// 生成代码方式(0zip压缩包 1自定义路径) /// + [SugarColumn(Length = 1, DefaultValue = "0")] public string GenType { get; set; } + /// + /// 代码生成保存路径 + /// + [SugarColumn(Length = 200, DefaultValue = "/")] public string GenPath { get; set; } /// /// 其他生成选项 /// - [SqlSugar.SugarColumn(IsJson = true, ColumnDataType = "nvarchar(4000)")] + [SugarColumn(IsJson = true)] public Options Options { get; set; } #region 表额外字段 - /** 表列信息 */ - [SqlSugar.SugarColumn(IsIgnore = true)] + /// + /// 表列信息 + /// + [SugarColumn(IsIgnore = true)] public List Columns { get; set; } /// /// 字表信息 /// - [SqlSugar.SugarColumn(IsIgnore = true)] + [SugarColumn(IsIgnore = true)] public GenTable SubTable { get; set; } #endregion } @@ -107,5 +124,9 @@ namespace ZR.Model.System.Generate /// 是否生成仓储层 /// public int GenerateRepo { get; set; } + /// + /// 自动生成菜单 + /// + public bool GenerateMenu { get; set; } } } diff --git a/ZR.Model/System/Generate/GenTableColumn.cs b/ZR.Model/System/Generate/GenTableColumn.cs index 12f5ff6..917fc78 100644 --- a/ZR.Model/System/Generate/GenTableColumn.cs +++ b/ZR.Model/System/Generate/GenTableColumn.cs @@ -7,18 +7,21 @@ namespace ZR.Model.System.Generate /// /// 代码生成表字段 /// - [SugarTable("gen_table_column")] + [SugarTable("gen_table_column", "代码生成表字段")] [Tenant("0")] public class GenTableColumn : SysBase { + /// + /// 列id + /// [SugarColumn(IsIdentity = true, IsPrimaryKey = true)] - public int ColumnId { get; set; } + public long ColumnId { get; set; } /// /// 导入代码生成表列名 首字母转了小写 /// public string ColumnName { get; set; } [SugarColumn(IsOnlyIgnoreUpdate = true)] - public int TableId { get; set; } + public long TableId { get; set; } [SugarColumn(IsOnlyIgnoreUpdate = true)] public string TableName { get; set; } @@ -96,6 +99,7 @@ namespace ZR.Model.System.Generate /// /// 查询类型(等于、不等于、大于、小于、范围) /// + [SugarColumn(DefaultValue = "EQ")] public string QueryType { get; set; } = "EQ"; public int Sort { get; set; } /// diff --git a/ZR.Model/System/SysBase.cs b/ZR.Model/System/SysBase.cs index 5e1f58c..b46ce8e 100644 --- a/ZR.Model/System/SysBase.cs +++ b/ZR.Model/System/SysBase.cs @@ -8,22 +8,34 @@ namespace ZR.Model.System //[EpplusTable(PrintHeaders = true, AutofitColumns = true, AutoCalculate = true, ShowTotal = true)] public class SysBase { + /// + /// 创建人 + /// [SugarColumn(IsOnlyIgnoreUpdate = true, Length = 64, IsNullable = true)] [JsonProperty(propertyName: "CreateBy")] [ExcelIgnore] public string Create_by { get; set; } + /// + /// 创建时间 + /// [SugarColumn(IsOnlyIgnoreUpdate = true, IsNullable = true)] [JsonProperty(propertyName: "CreateTime")] [ExcelColumn(Format = "yyyy-MM-dd HH:mm:ss")] public DateTime Create_time { get; set; } = DateTime.Now; + /// + /// 更新人 + /// [JsonIgnore] [JsonProperty(propertyName: "UpdateBy")] [SugarColumn(IsOnlyIgnoreInsert = true, Length = 64, IsNullable = true)] [ExcelIgnore] public string Update_by { get; set; } + /// + /// 更新时间 + /// //[JsonIgnore] [SugarColumn(IsOnlyIgnoreInsert = true, IsNullable = true)] [JsonProperty(propertyName: "UpdateTime")] @@ -31,13 +43,5 @@ namespace ZR.Model.System public DateTime? Update_time { get; set; } [SugarColumn(Length = 500)] public string Remark { get; set; } - [SugarColumn(IsIgnore = true, IsNullable = true)] - [JsonIgnore] - [ExcelIgnore] - public DateTime? BeginTime { get; set; } - [SugarColumn(IsIgnore = true, IsNullable = true)] - [JsonIgnore] - [ExcelIgnore] - public DateTime? EndTime { get; set; } } } diff --git a/ZR.Model/System/SysConfig.cs b/ZR.Model/System/SysConfig.cs index c253b36..764cf52 100644 --- a/ZR.Model/System/SysConfig.cs +++ b/ZR.Model/System/SysConfig.cs @@ -8,7 +8,7 @@ namespace ZR.Model.System /// @author mr.zhao /// @date 2021-09-29 /// - [SugarTable("sys_config")] + [SugarTable("sys_config", "配置表")] [Tenant("0")] public class SysConfig : SysBase { @@ -20,18 +20,22 @@ namespace ZR.Model.System /// /// 参数名称 /// + [SugarColumn(Length = 100)] public string ConfigName { get; set; } /// /// 参数键名 /// + [SugarColumn(Length = 100)] public string ConfigKey { get; set; } /// /// 参数键值 /// + [SugarColumn(Length = 500)] public string ConfigValue { get; set; } /// /// 系统内置(Y是 N否) /// + [SugarColumn(Length = 1)] public string ConfigType { get; set; } } diff --git a/ZR.Model/System/SysDept.cs b/ZR.Model/System/SysDept.cs index b38e3af..4e37a0b 100644 --- a/ZR.Model/System/SysDept.cs +++ b/ZR.Model/System/SysDept.cs @@ -6,9 +6,9 @@ namespace ZR.Model.System /// /// 部门表 /// - [SugarTable("sys_dept")] + [SugarTable("sys_dept", "部门配置表")] [Tenant("0")] - public class SysDept: SysBase + public class SysDept : SysBase { /// /// 部门ID @@ -29,6 +29,7 @@ namespace ZR.Model.System /// /// 部门名称 /// + [SugarColumn(Length = 30, ExtendedAttribute = ProteryConstant.NOTNULL)] public string DeptName { get; set; } /// @@ -39,32 +40,36 @@ namespace ZR.Model.System /// /// 负责人 /// + [SugarColumn(Length = 30)] public string Leader { get; set; } /// /// 联系电话 /// + [SugarColumn(Length = 11)] public string Phone { get; set; } /// /// 邮箱 /// + [SugarColumn(Length = 50)] public string Email { get; set; } /// /// 部门状态:0正常,1停用 /// + [SugarColumn(Length = 1, DefaultValue = "0")] public string Status { get; set; } /// /// 删除标志(0代表存在 2代表删除) /// - [SugarColumn(IsOnlyIgnoreInsert = true)] + [SugarColumn(Length = 1, DefaultValue = "0")] public string DelFlag { get; set; } /// /// 子菜单 /// - public List children = new List(); + public List children = new(); } } diff --git a/ZR.Model/System/SysDictData.cs b/ZR.Model/System/SysDictData.cs index d11ad44..9dbccae 100644 --- a/ZR.Model/System/SysDictData.cs +++ b/ZR.Model/System/SysDictData.cs @@ -6,7 +6,7 @@ namespace ZR.Model.System /// 字典数据表 /// [Tenant("0")] - [SugarTable("sys_dict_data")] + [SugarTable("sys_dict_data", "字典数据表")] public class SysDictData : SysBase { /// @@ -21,30 +21,37 @@ namespace ZR.Model.System /// /// 字典标签 /// + [SugarColumn(Length = 100, ExtendedAttribute = ProteryConstant.NOTNULL)] public string DictLabel { get; set; } /// /// 字典键值 /// + [SugarColumn(Length = 100, ExtendedAttribute = ProteryConstant.NOTNULL)] public string DictValue { get; set; } /// /// 字典类型 /// + [SugarColumn(Length = 100, ExtendedAttribute = ProteryConstant.NOTNULL)] public string DictType { get; set; } /// /// 样式属性(其他样式扩展) /// + [SugarColumn(Length = 100)] public string CssClass { get; set; } = string.Empty; /// /// 表格回显样式 /// + [SugarColumn(Length = 100)] public string ListClass { get; set; } = string.Empty; /// /// 是否默认(Y是 N否) /// + [SugarColumn(Length = 1, DefaultValue = "N")] public string IsDefault { get; set; } /// /// 状态(0正常 1停用) /// + [SugarColumn(Length = 1)] public string Status { get; set; } } } diff --git a/ZR.Model/System/SysDictType.cs b/ZR.Model/System/SysDictType.cs index 17b07c1..c323a63 100644 --- a/ZR.Model/System/SysDictType.cs +++ b/ZR.Model/System/SysDictType.cs @@ -5,7 +5,8 @@ namespace ZR.Model.System /// /// 字典类型表 /// - [SugarTable("sys_dict_type")] + [SugarTable("sys_dict_type", "字典类型表")] + [SugarIndex("index_dict_type", nameof(DictType), OrderByType.Asc, true)] [Tenant("0")] public class SysDictType : SysBase { @@ -17,18 +18,22 @@ namespace ZR.Model.System /// /// 字典名称 /// + [SugarColumn(Length = 100, ExtendedAttribute = ProteryConstant.NOTNULL)] public string DictName { get; set; } /// /// 字典类型 /// + [SugarColumn(Length = 100, ExtendedAttribute = ProteryConstant.NOTNULL)] public string DictType { get; set; } /// /// 状态 0、正常 1、停用 /// + [SugarColumn(Length = 1, DefaultValue = "0")] public string Status { get; set; } /// /// 系统内置 Y是 N否 /// + [SugarColumn(Length = 1, DefaultValue = "N")] public string Type { get; set; } /// /// 自定义sql diff --git a/ZR.Model/System/SysFile.cs b/ZR.Model/System/SysFile.cs index 5c18651..cc8eb1d 100644 --- a/ZR.Model/System/SysFile.cs +++ b/ZR.Model/System/SysFile.cs @@ -5,7 +5,7 @@ using System; namespace ZR.Model.System { [Tenant("0")] - [SugarTable("sys_file")] + [SugarTable("sys_file", "文件存储表")] public class SysFile { /// diff --git a/ZR.Model/System/SysLogininfor.cs b/ZR.Model/System/SysLogininfor.cs index 4cdc074..79b979c 100644 --- a/ZR.Model/System/SysLogininfor.cs +++ b/ZR.Model/System/SysLogininfor.cs @@ -6,7 +6,7 @@ namespace ZR.Model.System /// /// sys_logininfor 表 /// - [SugarTable("sys_logininfor")] + [SugarTable("sys_logininfor", "登录日志表")] [Tenant("0")] public class SysLogininfor { @@ -21,32 +21,33 @@ namespace ZR.Model.System /// /// 登录状态 0成功 1失败 /// + [SugarColumn(Length = 1, DefaultValue = "0")] public string Status { get; set; } /// /// 登录IP地址 /// - public string Ipaddr { get; set; } + public string Ipaddr { get; set; } = string.Empty; /// /// 登录地点 /// - public string LoginLocation { get; set; } + public string LoginLocation { get; set; } = string.Empty; /// /// 浏览器类型 /// - public string Browser { get; set; } + public string Browser { get; set; } = string.Empty; /// /// 操作系统 /// - public string Os { get; set; } + public string Os { get; set; } = string.Empty; /// /// 提示消息 /// - public string Msg { get; set; } + public string Msg { get; set; } = string.Empty; /// /// 访问时间 diff --git a/ZR.Model/System/SysMenu.cs b/ZR.Model/System/SysMenu.cs index 8edfc50..028f11e 100644 --- a/ZR.Model/System/SysMenu.cs +++ b/ZR.Model/System/SysMenu.cs @@ -6,7 +6,7 @@ namespace ZR.Model.System /// /// Sys_menu表 /// - [SugarTable("sys_menu")] + [SugarTable("sys_menu", "系统菜单表")] [Tenant("0")] public class SysMenu : SysBase { @@ -18,22 +18,25 @@ namespace ZR.Model.System /// /// 菜单名称 /// + [SugarColumn(Length = 50, ExtendedAttribute = ProteryConstant.NOTNULL)] public string MenuName { get; set; } /// /// 父菜单ID /// + [SugarColumn(DefaultValue = "0")] public long ParentId { get; set; } /// /// 显示顺序 /// + [SugarColumn(DefaultValue = "0")] public int OrderNum { get; set; } /// /// 路由地址 /// - public string Path { get; set; } = "#"; + public string Path { get; set; } = ""; /// /// 组件路径 @@ -43,35 +46,42 @@ namespace ZR.Model.System /// /// 是否缓存(1缓存 0不缓存) /// + [SugarColumn(DefaultValue = "0", ColumnDataType = "int")] public string IsCache { get; set; } /// /// 是否外链 1、是 0、否 /// - public string IsFrame { get; set; } + [SugarColumn(DefaultValue = "0", ColumnDataType = "int")] + public string IsFrame { get; set; } = "0"; /// /// 类型(M目录 C菜单 F按钮 L链接) /// - public string MenuType { get; set; } + [SugarColumn(Length = 1)] + public string MenuType { get; set; } = string.Empty; /// /// 显示状态(0显示 1隐藏) /// + [SugarColumn(DefaultValue = "0", Length = 1)] public string Visible { get; set; } /// /// 菜单状态(0正常 1停用) /// + [SugarColumn(DefaultValue = "0", Length = 1)] public string Status { get; set; } /// /// 权限字符串 /// + [SugarColumn(Length = 100)] public string Perms { get; set; } /// /// 菜单图标 /// + [SugarColumn(DefaultValue = "#")] public string Icon { get; set; } = string.Empty; /// /// 菜单名key diff --git a/ZR.Model/System/SysNotice.cs b/ZR.Model/System/SysNotice.cs index accf568..ff00e34 100644 --- a/ZR.Model/System/SysNotice.cs +++ b/ZR.Model/System/SysNotice.cs @@ -3,12 +3,12 @@ using SqlSugar; namespace ZR.Model.System { /// - /// 通知公告表,数据实体对象 + /// 通知公告表 /// /// @author zr /// @date 2021-12-15 /// - [SugarTable("sys_notice")] + [SugarTable("sys_notice", "通知公告表")] [Tenant(0)] public class SysNotice : SysBase { @@ -20,21 +20,22 @@ namespace ZR.Model.System /// /// 公告标题 /// - [SugarColumn(ColumnName = "notice_title")] + [SugarColumn(ColumnName = "notice_title", ExtendedAttribute = ProteryConstant.NOTNULL)] public string NoticeTitle { get; set; } /// /// 公告类型 (1通知 2公告) /// - [SugarColumn(ColumnName = "notice_type")] - public string NoticeType { get; set; } + [SugarColumn(ColumnName = "notice_type", ExtendedAttribute = ProteryConstant.NOTNULL)] + public int NoticeType { get; set; } /// /// 公告内容 /// - [SugarColumn(ColumnName = "notice_content")] + [SugarColumn(ColumnName = "notice_content", ColumnDataType = StaticConfig.CodeFirst_BigString)] public string NoticeContent { get; set; } /// /// 公告状态 (0正常 1关闭) /// - public string Status { get; set; } + [SugarColumn(DefaultValue = "0", ExtendedAttribute = ProteryConstant.NOTNULL)] + public int Status { get; set; } } } \ No newline at end of file diff --git a/ZR.Model/System/SysOperLog.cs b/ZR.Model/System/SysOperLog.cs index 9929ffb..3eed289 100644 --- a/ZR.Model/System/SysOperLog.cs +++ b/ZR.Model/System/SysOperLog.cs @@ -5,22 +5,24 @@ using System.ComponentModel; namespace ZR.Model.System { - [SugarTable("sys_oper_log")] + [SugarTable("sys_oper_log", "操作日志表")] [Tenant("0")] public class SysOperLog { + /// + /// 操作id + /// [SugarColumn(IsPrimaryKey = true, IsIdentity = true)] public long OperId { get; set; } /// /// 操作模块 /// - [DisplayName("操作模块")] public string Title { get; set; } /// /// 业务类型(0其它 1新增 2修改 3删除 4=授权,5=导出,6=导入,7=强退,8=生成代码,9=清空数据) /// - [DisplayName("业务类型")] + [SugarColumn(DefaultValue = "0")] public int BusinessType { get; set; } /// @@ -33,79 +35,71 @@ namespace ZR.Model.System /// /// 请求方法 /// - [DisplayName("请求方法")] public string Method { get; set; } /// /// 请求方式 /// - [DisplayName("请求方式")] public string RequestMethod { get; set; } /// /// 操作类别(0其它 1后台用户 2手机端用户) /// //@Excel(name = "操作类别", readConverterExp = "0=其它,1=后台用户,2=手机端用户") - [DisplayName("操作类别")] + [SugarColumn(DefaultValue = "0")] public int OperatorType { get; set; } /// /// 操作人员 /// - [DisplayName("操作人员")] public string OperName { get; set; } /// /// 请求url /// - [DisplayName("请求地址")] public string OperUrl { get; set; } /// /// 操作地址 /// - [DisplayName("操作地址")] public string OperIp { get; set; } /// /// 操作地点 /// - [DisplayName("操作地点")] public string OperLocation { get; set; } /// /// 请求参数 /// - [DisplayName("请求参数")] + [SugarColumn(Length = 4000)] public string OperParam { get; set; } /// /// 返回参数 /// - [DisplayName("返回结果")] + [SugarColumn(ColumnDataType = StaticConfig.CodeFirst_BigString)] public string JsonResult { get; set; } /// /// 操作状态(0正常 1异常) /// - [DisplayName("状态")] + [SugarColumn(DefaultValue = "0")] public int Status { get; set; } /// /// 错误消息 /// - [DisplayName("错误消息")] public string ErrorMsg { get; set; } /// /// 操作时间 /// - [DisplayName("操作时间")] public DateTime? OperTime { get; set; } /// /// 操作用时 /// - [DisplayName("操作用时")] public long Elapsed { get; set; } + public string DeptName { get; set; } } } diff --git a/ZR.Model/System/SysPost.cs b/ZR.Model/System/SysPost.cs index 8441f26..26edfcf 100644 --- a/ZR.Model/System/SysPost.cs +++ b/ZR.Model/System/SysPost.cs @@ -2,7 +2,7 @@ namespace ZR.Model.System { - [SugarTable("sys_post")] + [SugarTable("sys_post", "岗位表")] [Tenant("0")] public class SysPost : SysBase { @@ -11,9 +11,13 @@ namespace ZR.Model.System /// [SugarColumn(IsPrimaryKey = true, IsIdentity = true)] public long PostId { get; set; } + [SugarColumn(ExtendedAttribute = ProteryConstant.NOTNULL)] public string PostCode { get; set; } + [SugarColumn(ExtendedAttribute = ProteryConstant.NOTNULL)] public string PostName { get; set; } + [SugarColumn(ExtendedAttribute = ProteryConstant.NOTNULL)] public int PostSort { get; set; } + [SugarColumn(Length = 1)] public string Status { get; set; } } } diff --git a/ZR.Model/System/SysRole.cs b/ZR.Model/System/SysRole.cs index dea2527..3f48946 100644 --- a/ZR.Model/System/SysRole.cs +++ b/ZR.Model/System/SysRole.cs @@ -5,7 +5,7 @@ namespace ZR.Model.System /// /// 角色表 sys_role /// - [SugarTable("sys_role")] + [SugarTable("sys_role", "角色表")] [Tenant("0")] public class SysRole : SysBase { @@ -18,41 +18,47 @@ namespace ZR.Model.System /// /// 角色名称 /// + [SugarColumn(Length = 30, ExtendedAttribute = ProteryConstant.NOTNULL)] public string RoleName { get; set; } /// /// 角色权限 /// + [SugarColumn(Length = 100, ExtendedAttribute = ProteryConstant.NOTNULL)] public string RoleKey { get; set; } /// /// 角色排序 /// + [SugarColumn(ExtendedAttribute = ProteryConstant.NOTNULL)] public int RoleSort { get; set; } /// /// 帐号状态(0正常 1停用) /// + [SugarColumn(DefaultValue = "0")] public int Status { get; set; } /// /// 删除标志(0代表存在 2代表删除) /// + [SugarColumn(DefaultValue = "0")] public int DelFlag { get; set; } /// /// 数据范围(1:全部数据权限 2:自定数据权限 3:本部门数据权限 4:本部门及以下数据权限)) /// + [SugarColumn(DefaultValue = "1")] public int DataScope { get; set; } /// /// 菜单树选择项是否关联显示 /// [SugarColumn(ColumnName = "menu_check_strictly")] - public bool MenuCheckStrictly { get; set; } + public bool MenuCheckStrictly { get; set; } = true; /// /// 部门树选择项是否关联显示 /// [SugarColumn(ColumnName = "dept_check_strictly")] - public bool DeptCheckStrictly { get; set; } + public bool DeptCheckStrictly { get; set; } = true; /// /// 菜单组 /// diff --git a/ZR.Model/System/SysRoleDept.cs b/ZR.Model/System/SysRoleDept.cs index bbe4a96..168d048 100644 --- a/ZR.Model/System/SysRoleDept.cs +++ b/ZR.Model/System/SysRoleDept.cs @@ -1,10 +1,15 @@ -namespace ZR.Model.System +using SqlSugar; + +namespace ZR.Model.System { - [SqlSugar.SugarTable("sys_role_dept")] - [SqlSugar.Tenant(0)] + [SugarTable("sys_role_dept", "角色部门")] + [Tenant(0)] public class SysRoleDept { + [SugarColumn(ExtendedAttribute = ProteryConstant.NOTNULL, IsPrimaryKey = true)] public long RoleId { get; set; } + + [SugarColumn(ExtendedAttribute = ProteryConstant.NOTNULL, IsPrimaryKey = true)] public long DeptId { get; set; } } } diff --git a/ZR.Model/System/SysRoleMenu.cs b/ZR.Model/System/SysRoleMenu.cs index ba32d30..9a037a4 100644 --- a/ZR.Model/System/SysRoleMenu.cs +++ b/ZR.Model/System/SysRoleMenu.cs @@ -1,23 +1,20 @@ using Newtonsoft.Json; using SqlSugar; -using System; namespace ZR.Model.System { /// /// 角色菜单 /// - [SugarTable("sys_role_menu")] + [SugarTable("sys_role_menu", "角色菜单")] [Tenant("0")] - public class SysRoleMenu + public class SysRoleMenu : SysBase { [JsonProperty("roleId")] - [SugarColumn(IsPrimaryKey = true)] + [SugarColumn(IsPrimaryKey = true, ExtendedAttribute = ProteryConstant.NOTNULL)] public long Role_id { get; set; } [JsonProperty("menuId")] - [SugarColumn(IsPrimaryKey = true)] + [SugarColumn(IsPrimaryKey = true, ExtendedAttribute = ProteryConstant.NOTNULL)] public long Menu_id { get; set; } - public DateTime Create_time { get; set; } - public string Create_by { get; set; } } } diff --git a/ZR.Model/System/SysRolePost.cs b/ZR.Model/System/SysRolePost.cs deleted file mode 100644 index d0cee95..0000000 --- a/ZR.Model/System/SysRolePost.cs +++ /dev/null @@ -1,15 +0,0 @@ -using SqlSugar; - -namespace ZR.Model.System -{ - /// - /// 角色部门 - /// - [SugarTable("sys_role_post")] - [Tenant("0")] - public class SysRolePost - { - public long RoleId { get; set; } - public long DeptId { get; set; } - } -} diff --git a/ZR.Model/System/SysTasks.cs b/ZR.Model/System/SysTasks.cs index 56519f7..b1a413c 100644 --- a/ZR.Model/System/SysTasks.cs +++ b/ZR.Model/System/SysTasks.cs @@ -1,5 +1,4 @@ -using Newtonsoft.Json; -using SqlSugar; +using SqlSugar; using System; using System.ComponentModel.DataAnnotations; @@ -8,9 +7,9 @@ namespace ZR.Model.System /// ///计划任务 /// - [SugarTable("sys_tasks")] + [SugarTable("sys_tasks", "计划任务表")] [Tenant("0")] - public class SysTasks + public class SysTasks : SysBase { public SysTasks() { @@ -28,42 +27,42 @@ namespace ZR.Model.System /// 任务名称 /// [Display(Name = "任务名称")] + [SugarColumn(ExtendedAttribute = ProteryConstant.NOTNULL)] public string Name { get; set; } /// /// 任务分组 /// [Display(Name = "任务分组")] + [SugarColumn(ExtendedAttribute = ProteryConstant.NOTNULL)] public string JobGroup { get; set; } /// /// 运行时间表达式 /// [Display(Name = "运行时间表达式")] + [SugarColumn(ExtendedAttribute = ProteryConstant.NOTNULL)] public string Cron { get; set; } /// /// 程序集名称 /// [Display(Name = "程序集名称")] + [SugarColumn(ExtendedAttribute = ProteryConstant.NOTNULL)] public string AssemblyName { get; set; } /// /// 任务所在类 /// [Display(Name = "任务所在类")] + [SugarColumn(ExtendedAttribute = ProteryConstant.NOTNULL)] public string ClassName { get; set; } - /// - /// 任务描述 - /// - [Display(Name = "任务描述")] - public string Remark { get; set; } - /// /// 执行次数 /// [Display(Name = "执行次数")] + [SugarColumn(DefaultValue = "0", ExtendedAttribute = ProteryConstant.NOTNULL)] public int RunTimes { get; set; } /// @@ -83,6 +82,7 @@ namespace ZR.Model.System /// 默认 : 1 /// [Display(Name = "触发器类型(0、simple 1、cron)")] + [SugarColumn(ExtendedAttribute = ProteryConstant.NOTNULL)] public int TriggerType { get; set; } /// @@ -90,42 +90,22 @@ namespace ZR.Model.System /// 默认 : 0 /// [Display(Name = "执行间隔时间(单位:秒)")] + [SugarColumn(ExtendedAttribute = ProteryConstant.NOTNULL)] public int IntervalSecond { get; set; } /// /// 是否启动 - /// 默认 : 0 /// [Display(Name = "是否启动")] + [SugarColumn(DefaultValue = "0", ExtendedAttribute = ProteryConstant.NOTNULL)] public int IsStart { get; set; } /// /// 传入参数 - /// 默认 : /// [Display(Name = "传入参数")] public string JobParams { get; set; } - [SugarColumn(IsOnlyIgnoreUpdate = true)]//设置后修改不会有此字段 - [JsonProperty(propertyName: "CreateBy")] - public string Create_by { get; set; } - - /// - /// 创建时间 - /// - //[Display(Name = "创建时间")] - [SugarColumn(IsOnlyIgnoreUpdate = true)]//设置后修改不会有此字段 - [JsonProperty(propertyName: "CreateTime")] - public DateTime Create_time { get; set; } = DateTime.Now; - - [JsonIgnore] - [JsonProperty(propertyName: "UpdateBy")] - [SugarColumn(IsOnlyIgnoreInsert = true)] - public string Update_by { get; set; } - - [SugarColumn(IsOnlyIgnoreInsert = true)]//设置后插入数据不会有此字段 - [JsonProperty(propertyName: "UpdateTime")] - public DateTime Update_time { get; set; } = DateTime.Now; /// /// 最后运行时间 /// @@ -137,6 +117,7 @@ namespace ZR.Model.System /// /// 任务类型 1、程序集 2、网络请求 3、SQL语句 /// + [SugarColumn(DefaultValue = "1")] public int TaskType { get; set; } /// @@ -146,6 +127,7 @@ namespace ZR.Model.System /// /// 网络请求方式 /// + [SugarColumn(Length = 20)] public string RequestMethod { get; set; } } } diff --git a/ZR.Model/System/SysTasksLog.cs b/ZR.Model/System/SysTasksLog.cs index 666f1ea..88fbcfc 100644 --- a/ZR.Model/System/SysTasksLog.cs +++ b/ZR.Model/System/SysTasksLog.cs @@ -6,7 +6,7 @@ namespace ZR.Model.System /// /// 任务日志 /// - [SugarTable("sys_tasks_log")] + [SugarTable("sys_tasks_log", "任务日志表")] [Tenant("0")] public class SysTasksLog { @@ -18,12 +18,22 @@ namespace ZR.Model.System /// /// 任务Id /// + [SugarColumn(ExtendedAttribute = ProteryConstant.NOTNULL)] public string JobId { get; set; } + /// + /// 任务名 + /// + [SugarColumn(ExtendedAttribute = ProteryConstant.NOTNULL)] public string JobName { get; set; } + /// + /// 任务分组 + /// + [SugarColumn(ExtendedAttribute = ProteryConstant.NOTNULL)] public string JobGroup { get; set; } /// /// 执行状态(0正常 1失败) /// + [SugarColumn(DefaultValue = "0")] public string Status { get; set; } /// /// 异常 diff --git a/ZR.Model/System/SysUser.cs b/ZR.Model/System/SysUser.cs index e9d31ae..ff55b72 100644 --- a/ZR.Model/System/SysUser.cs +++ b/ZR.Model/System/SysUser.cs @@ -9,7 +9,7 @@ namespace ZR.Model.System /// /// 用户表 /// - [SugarTable("sys_user")] + [SugarTable("sys_user", "用户表")] [Tenant("0")] public class SysUser : SysBase { @@ -21,12 +21,12 @@ namespace ZR.Model.System /// /// 登录用户名 /// - [SugarColumn(Length = 30, ColumnDescription = "用户账号", IsNullable = false)] + [SugarColumn(Length = 30, ColumnDescription = "用户账号", ExtendedAttribute = ProteryConstant.NOTNULL)] public string UserName { get; set; } /// /// 用户昵称 /// - [SugarColumn(Length = 30, ColumnDescription = "用户昵称", IsNullable = false)] + [SugarColumn(Length = 30, ColumnDescription = "用户昵称", ExtendedAttribute = ProteryConstant.NOTNULL)] public string NickName { get; set; } /// /// 用户类型(00系统用户) @@ -40,7 +40,7 @@ namespace ZR.Model.System [JsonIgnore] [ExcelIgnore] - [SugarColumn(Length = 100, ColumnDescription = "密码", IsNullable = false)] + [SugarColumn(Length = 100, ColumnDescription = "密码", ExtendedAttribute = ProteryConstant.NOTNULL)] public string Password { get; set; } /// /// 手机号 diff --git a/ZR.Model/System/SysUserPost.cs b/ZR.Model/System/SysUserPost.cs index e58c2f1..7eadfd0 100644 --- a/ZR.Model/System/SysUserPost.cs +++ b/ZR.Model/System/SysUserPost.cs @@ -5,11 +5,13 @@ namespace ZR.Model.System /// /// 用户岗位 /// - [SugarTable("sys_user_post")] + [SugarTable("sys_user_post", "用户与岗位关联表")] [Tenant("0")] public class SysUserPost { + [SugarColumn(IsPrimaryKey = true, ExtendedAttribute = ProteryConstant.NOTNULL)] public long UserId { get; set; } + [SugarColumn(IsPrimaryKey = true, ExtendedAttribute = ProteryConstant.NOTNULL)] public long PostId { get; set; } } } diff --git a/ZR.Model/System/SysUserRole.cs b/ZR.Model/System/SysUserRole.cs index fab8cfd..c1570dc 100644 --- a/ZR.Model/System/SysUserRole.cs +++ b/ZR.Model/System/SysUserRole.cs @@ -5,7 +5,7 @@ namespace ZR.Model.System /// /// 用户角色关联表 用户N-1 角色 /// - [SugarTable("sys_user_role")] + [SugarTable("sys_user_role", "用户和角色关联表")] [Tenant("0")] public class SysUserRole { diff --git a/ZR.Model/ZR.Model.csproj b/ZR.Model/ZR.Model.csproj index 627c363..7efcd39 100644 --- a/ZR.Model/ZR.Model.csproj +++ b/ZR.Model/ZR.Model.csproj @@ -2,16 +2,14 @@ net7.0 - True - ../ZR.Admin.WebApi/ZRModel.xml + true 1701;1702;1591;1570 - + - diff --git a/ZR.Repository/BaseRepository.cs b/ZR.Repository/BaseRepository.cs index 36a8559..30a4a4b 100644 --- a/ZR.Repository/BaseRepository.cs +++ b/ZR.Repository/BaseRepository.cs @@ -12,7 +12,7 @@ using ZR.Model; namespace ZR.Repository { /// - /// + /// 数据仓库类 /// /// public class BaseRepository : SimpleClient where T : class, new() @@ -79,7 +79,7 @@ namespace ZR.Repository /// /// 实体根据主键更新指定字段 - /// return Update(user, t => new { t.NickName, }, true); + /// return Update(new SysUser(){ Status = 1 }, t => new { t.NickName, }, true); /// /// /// @@ -91,12 +91,12 @@ namespace ZR.Repository } /// - /// 根据指定条件更新指定列 eg:Update(new SysUser(){ }, it => new { it.Status }, f => f.Userid == 1)); + /// 根据指定条件更新指定列 eg:Update(new SysUser(){ Status = 1 }, it => new { it.Status }, f => f.Userid == 1)); /// 只更新Status列,条件是包含 /// - /// - /// - /// + /// 实体类 + /// 要更新列的表达式 + /// where表达式 /// public int Update(T entity, Expression> expression, Expression> where) { @@ -117,14 +117,11 @@ namespace ZR.Repository /// public int Update(T entity, List list = null, bool isNull = true) { - if (list == null) - { - list = new List() + list ??= new List() { "Create_By", "Create_time" }; - } return Context.Updateable(entity).IgnoreColumns(isNull).IgnoreColumns(list.ToArray()).ExecuteCommand(); } @@ -171,6 +168,7 @@ namespace ZR.Repository { return Context.Storageable(t); } + /// /// /// @@ -192,6 +190,11 @@ namespace ZR.Repository } } + /// + /// 使用事务 + /// + /// + /// public bool UseTran2(Action action) { var result = Context.Ado.UseTran(() => action()); @@ -239,36 +242,6 @@ namespace ZR.Repository return Context.Queryable(); } - public (List, int) QueryableToPage(Expression> expression, int pageIndex = 0, int pageSize = 10) - { - int totalNumber = 0; - var list = Context.Queryable().Where(expression).ToPageList(pageIndex, pageSize, ref totalNumber); - return (list, totalNumber); - } - - public (List, int) QueryableToPage(Expression> expression, string order, int pageIndex = 0, int pageSize = 10) - { - int totalNumber = 0; - var list = Context.Queryable().Where(expression).OrderBy(order).ToPageList(pageIndex, pageSize, ref totalNumber); - return (list, totalNumber); - } - - public (List, int) QueryableToPage(Expression> expression, Expression> orderFiled, string orderBy, int pageIndex = 0, int pageSize = 10) - { - int totalNumber = 0; - - if (orderBy.Equals("DESC", StringComparison.OrdinalIgnoreCase)) - { - var list = Context.Queryable().Where(expression).OrderBy(orderFiled, OrderByType.Desc).ToPageList(pageIndex, pageSize, ref totalNumber); - return (list, totalNumber); - } - else - { - var list = Context.Queryable().Where(expression).OrderBy(orderFiled, OrderByType.Asc).ToPageList(pageIndex, pageSize, ref totalNumber); - return (list, totalNumber); - } - } - public List SqlQueryToList(string sql, object obj = null) { return Context.Ado.SqlQuery(sql, obj); @@ -296,9 +269,21 @@ namespace ZR.Repository return source.ToPage(parm); } + /// + /// 分页获取数据 + /// + /// 条件表达式 + /// + /// + /// + /// public PagedInfo GetPages(Expression> where, PagerInfo parm, Expression> order, OrderByType orderEnum = OrderByType.Asc) { - var source = Context.Queryable().Where(where).OrderByIF(orderEnum == OrderByType.Asc, order, OrderByType.Asc).OrderByIF(orderEnum == OrderByType.Desc, order, OrderByType.Desc); + var source = Context + .Queryable() + .Where(where) + .OrderByIF(orderEnum == OrderByType.Asc, order, OrderByType.Asc) + .OrderByIF(orderEnum == OrderByType.Desc, order, OrderByType.Desc); return source.ToPage(parm); } diff --git a/ZR.Repository/IBaseRepository.cs b/ZR.Repository/IBaseRepository.cs index 640612f..a1b4f66 100644 --- a/ZR.Repository/IBaseRepository.cs +++ b/ZR.Repository/IBaseRepository.cs @@ -71,12 +71,6 @@ namespace ZR.Repository ISugarQueryable Queryable(); List GetAll(bool useCache = false, int cacheSecond = 3600); - (List, int) QueryableToPage(Expression> expression, int pageIndex = 0, int pageSize = 10); - - (List, int) QueryableToPage(Expression> expression, string order, int pageIndex = 0, int pageSize = 10); - - (List, int) QueryableToPage(Expression> expression, Expression> orderFiled, string orderBy, int pageIndex = 0, int pageSize = 10); - List SqlQueryToList(string sql, object obj = null); T GetId(object pkValue); diff --git a/ZR.Repository/ZR.Repository.csproj b/ZR.Repository/ZR.Repository.csproj index 7ff20e2..22ea936 100644 --- a/ZR.Repository/ZR.Repository.csproj +++ b/ZR.Repository/ZR.Repository.csproj @@ -15,6 +15,6 @@ - + diff --git a/ZR.Service/System/CacheService.cs b/ZR.Service/System/CacheService.cs index a18a0bd..1b5a336 100644 --- a/ZR.Service/System/CacheService.cs +++ b/ZR.Service/System/CacheService.cs @@ -1,9 +1,7 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; using System.Linq; -using System.Text; -using System.Threading.Tasks; using ZR.Common; +using ZR.Common.Cache; namespace ZR.Service.System { @@ -13,15 +11,18 @@ namespace ZR.Service.System public static List GetUserPerms(string key) { return (List)CacheHelper.GetCache(key); + //return RedisServer.Cache.Get>(key).ToList(); } public static void SetUserPerms(string key, object data) { CacheHelper.SetCache(key, data); + //RedisServer.Cache.Set(key, data); } public static void RemoveUserPerms(string key) { CacheHelper.Remove(key); + //RedisServer.Cache.Del(key); } #endregion } diff --git a/ZR.Service/System/IService/ISysMenuService.cs b/ZR.Service/System/IService/ISysMenuService.cs index 2eb3abc..29bd021 100644 --- a/ZR.Service/System/IService/ISysMenuService.cs +++ b/ZR.Service/System/IService/ISysMenuService.cs @@ -2,6 +2,7 @@ using ZR.Model.System.Dto; using ZR.Model.System; using ZR.Model.System.Vo; +using ZR.Model.System.Generate; namespace ZR.Service.System.IService { @@ -14,9 +15,9 @@ namespace ZR.Service.System.IService SysMenu GetMenuByMenuId(int menuId); List GetMenusByMenuId(int menuId, long userId); - int AddMenu(SysMenu menu); + long AddMenu(SysMenu menu); - int EditMenu(SysMenu menu); + long EditMenu(SysMenu menu); int DeleteMenuById(int menuId); @@ -37,6 +38,10 @@ namespace ZR.Service.System.IService List BuildMenus(List menus); List BuildMenuTreeSelect(List menus); + + void AddSysMenu(GenTable genTableInfo, string permPrefix, bool showEdit, bool showExport); + List SelectTreeMenuListByRoles(MenuQueryDto menu, List roles); + List SelectRoleMenuListByRole(MenuQueryDto menu, int roleId); } /// diff --git a/ZR.Service/System/IService/ISysUserService.cs b/ZR.Service/System/IService/ISysUserService.cs index 493ac59..eb463fb 100644 --- a/ZR.Service/System/IService/ISysUserService.cs +++ b/ZR.Service/System/IService/ISysUserService.cs @@ -7,7 +7,7 @@ namespace ZR.Service.System.IService { public interface ISysUserService : IBaseService { - public PagedInfo SelectUserList(SysUser user, PagerInfo pager); + public PagedInfo SelectUserList(SysUserQueryDto user, PagerInfo pager); /// /// 通过用户ID查询用户 diff --git a/ZR.Service/System/SeedDataService.cs b/ZR.Service/System/SeedDataService.cs index 4cffdc4..62bd9a4 100644 --- a/ZR.Service/System/SeedDataService.cs +++ b/ZR.Service/System/SeedDataService.cs @@ -1,11 +1,16 @@ using Infrastructure.Extensions; +using MiniExcelLibs; using SqlSugar.IOC; using System.Collections.Generic; +using System.Linq; using ZR.Common; using ZR.Model.System; namespace ZR.Service.System { + /// + /// 种子数据处理 + /// public class SeedDataService { /// @@ -44,14 +49,12 @@ namespace ZR.Service.System public (string, object, object) InitMenuData(List data) { var db = DbScoped.SugarScope; - db.Ado.BeginTran(); var x = db.Storageable(data) .SplitInsert(it => it.NotAny()) .WhereColumns(it => it.MenuId)//如果不是主键可以这样实现(多字段it=>new{it.x1,it.x2}) .ToStorage(); var result = x.AsInsertable.OffIdentity().ExecuteCommand();//插入可插入部分; - db.Ado.CommitTran(); - + string msg = $"[菜单数据] 插入{x.InsertList.Count} 错误数据{x.ErrorList.Count} 总共{x.TotalList.Count}"; return (msg, x.ErrorList, x.IgnoreList); } @@ -84,7 +87,7 @@ namespace ZR.Service.System .SplitInsert(it => it.NotAny()) .WhereColumns(it => it.DeptId) .ToStorage(); - var result = x.AsInsertable.ExecuteCommand(); + var result = x.AsInsertable.OffIdentity().ExecuteCommand(); string msg = $"[部门数据] 插入{x.InsertList.Count} 错误数据{x.ErrorList.Count} 总共{x.TotalList.Count}"; return (msg, x.ErrorList, x.IgnoreList); @@ -218,5 +221,74 @@ namespace ZR.Service.System string msg = $"[任务数据] 插入{x.InsertList.Count} 错误数据{x.ErrorList.Count} 总共{x.TotalList.Count}"; return (msg, x.ErrorList, x.IgnoreList); } + + /// + /// 初始化种子数据 + /// + /// + /// + /// + public List InitSeedData(string path, bool clean) + { + List result = new(); + + var db = DbScoped.SugarScope; + if (clean) + { + db.DbMaintenance.TruncateTable(); + db.DbMaintenance.TruncateTable(); + db.DbMaintenance.TruncateTable(); + db.DbMaintenance.TruncateTable(); + db.DbMaintenance.TruncateTable(); + db.DbMaintenance.TruncateTable(); + db.DbMaintenance.TruncateTable(); + } + + var sysUser = MiniExcel.Query(path, sheetName: "user").ToList(); + var result1 = InitUserData(sysUser); + result.Add(result1.Item1); + + var sysPost = MiniExcel.Query(path, sheetName: "post").ToList(); + var result2 = InitPostData(sysPost); + result.Add(result2.Item1); + + var sysRole = MiniExcel.Query(path, sheetName: "role").ToList(); + var result3 = InitRoleData(sysRole); + result.Add(result3.Item1); + + var sysUserRole = MiniExcel.Query(path, sheetName: "user_role").ToList(); + var result4 = InitUserRoleData(sysUserRole); + result.Add(result4.Item1); + + var sysMenu = MiniExcel.Query(path, sheetName: "menu").ToList(); + var result5 = InitMenuData(sysMenu); + result.Add(result5.Item1); + + var sysConfig = MiniExcel.Query(path, sheetName: "config").ToList(); + var result6 = InitConfigData(sysConfig); + result.Add(result6.Item1); + + var sysRoleMenu = MiniExcel.Query(path, sheetName: "role_menu").ToList(); + var result7 = InitRoleMenuData(sysRoleMenu); + result.Add(result7.Item1); + + var sysDict = MiniExcel.Query(path, sheetName: "dict_type").ToList(); + var result8 = InitDictType(sysDict); + result.Add(result8.Item1); + + var sysDictData = MiniExcel.Query(path, sheetName: "dict_data").ToList(); + var result9 = InitDictData(sysDictData); + result.Add(result9.Item1); + + var sysDept = MiniExcel.Query(path, sheetName: "dept").ToList(); + var result10 = InitDeptData(sysDept); + result.Add(result10.Item1); + + var sysArticleCategory = MiniExcel.Query(path, sheetName: "article_category").ToList(); + var result11 = InitArticleCategoryData(sysArticleCategory); + result.Add(result11.Item1); + + return result; + } } } diff --git a/ZR.Service/System/SysMenuService.cs b/ZR.Service/System/SysMenuService.cs index 54b963b..7db43f3 100644 --- a/ZR.Service/System/SysMenuService.cs +++ b/ZR.Service/System/SysMenuService.cs @@ -7,6 +7,8 @@ using System.Linq; using ZR.Common; using ZR.Model.System; using ZR.Model.System.Dto; +using ZR.Model.System.Enums; +using ZR.Model.System.Generate; using ZR.Model.System.Vo; using ZR.Service.System.IService; @@ -31,17 +33,11 @@ namespace ZR.Service /// public List SelectTreeMenuList(MenuQueryDto menu, long userId) { - List menuList; - //if (SysRoleService.IsAdmin(userId)) - //{ - // menuList = SelectTreeMenuList(menu); - //} - //else - //{ - // var userRoles = SysRoleService.SelectUserRoles(userId); - // menuList = SelectTreeMenuListByRoles(menu, userRoles); - //} - menuList = BuildMenuTree(SelectMenuList(menu, userId)); + if (menu.ParentId != null) + { + return GetMenusByMenuId(menu.ParentId.ParseToInt(), userId); + } + List menuList = BuildMenuTree(SelectMenuList(menu, userId)); return menuList; } @@ -106,10 +102,10 @@ namespace ZR.Service /// /// /// - public int AddMenu(SysMenu menu) + public long AddMenu(SysMenu menu) { menu.Create_time = DateTime.Now; - return InsertReturnIdentity(menu); + return InsertReturnBigIdentity(menu); } /// @@ -117,7 +113,7 @@ namespace ZR.Service /// /// /// - public int EditMenu(SysMenu menu) + public long EditMenu(SysMenu menu) { menu.Icon = string.IsNullOrEmpty(menu.Icon) ? "" : menu.Icon; return Update(menu, false); @@ -219,7 +215,7 @@ namespace ZR.Service /// /// 用户角色集合 /// - private List SelectTreeMenuListByRoles(MenuQueryDto menu, List roles) + public List SelectTreeMenuListByRoles(MenuQueryDto menu, List roles) { var roleMenus = Context.Queryable() .Where(r => roles.Contains(r.Role_id)) @@ -236,20 +232,52 @@ namespace ZR.Service .ToTree(it => it.Children, it => it.ParentId, 0); } + /// + /// 根据用户查询系统菜单列表 + /// + /// + /// 用户角色 + /// + public List SelectRoleMenuListByRole(MenuQueryDto menu, int roleId) + { + var menuIds = Context.Queryable() + .Where(r => r.Role_id == roleId) + .Select(f => f.Menu_id).Distinct().ToList(); + + return Context.Queryable() + .InnerJoin((t1, t2) => t1.MenuId == t2.ParentId) + .InnerJoin((t1, t2, t3) => t2.MenuId == t3.ParentId) + .Where((t1, t2, t3) => menuIds.Contains(t1.MenuId)) + .Select((t1, t2, t3) => new RoleMenuExportDto() + { + MenuName = $"{t1.MenuName}->{t2.MenuName}->{t3.MenuName}", + //MenuName1 = t2.MenuName, + //MenuName2 = t3.MenuName, + Path = t2.Path, + Component = t2.Component, + Perms = t3.Perms, + //MenuType = (MenuType)Enum.Parse(typeof(MenuType), t3.MenuType) //(MenuType)t3.MenuType, + //Status = t3.Status + }).ToList(); + } + /// /// 获取所有菜单 /// /// private List SelectMenuList(MenuQueryDto menu) { + var menuExp = Expressionable.Create(); + menuExp.AndIF(!string.IsNullOrEmpty(menu.MenuName), it => it.MenuName.Contains(menu.MenuName)); + menuExp.AndIF(!string.IsNullOrEmpty(menu.Visible), it => it.Visible == menu.Visible); + menuExp.AndIF(!string.IsNullOrEmpty(menu.Status), it => it.Status == menu.Status); + menuExp.AndIF(!string.IsNullOrEmpty(menu.MenuTypeIds), it => menu.MenuTypeIdArr.Contains(it.MenuType)); + menuExp.AndIF(menu.ParentId != null, it => it.ParentId == menu.ParentId); + return Queryable() - .WhereIF(!string.IsNullOrEmpty(menu.MenuName), it => it.MenuName.Contains(menu.MenuName)) - .WhereIF(!string.IsNullOrEmpty(menu.Visible), it => it.Visible == menu.Visible) - .WhereIF(!string.IsNullOrEmpty(menu.Status), it => it.Status == menu.Status) - .WhereIF(!string.IsNullOrEmpty(menu.MenuTypeIds), it => menu.MenuTypeIdArr.Contains(it.MenuType)) - .WhereIF(menu.ParentId != null, it => it.ParentId == menu.ParentId) - .OrderBy(it => new { it.ParentId, it.OrderNum }) - .ToList(); + .Where(menuExp.ToExpression()) + .OrderBy(it => new { it.ParentId, it.OrderNum }) + .ToList(); } /// @@ -561,5 +589,110 @@ namespace ZR.Service } #endregion + + public void AddSysMenu(GenTable genTableInfo, string permPrefix, bool showEdit, bool showExport) + { + var menu = GetFirst(f => f.MenuName == genTableInfo.FunctionName); + if (menu is null) + { + menu = new() + { + MenuName = genTableInfo.FunctionName, + ParentId = genTableInfo.Options.ParentMenuId, + OrderNum = 0, + Path = genTableInfo.BusinessName, + Component = $"{genTableInfo.ModuleName.FirstLowerCase()}/{genTableInfo.BusinessName}", + Perms = $"{permPrefix}:list", + IsCache = "1", + MenuType = "C", + Visible = "0", + Status = "0", + Icon = "icon1", + Create_by = "system", + }; + menu.MenuId = AddMenu(menu); + } + + List menuList = new(); + + SysMenu menuQuery = new() + { + MenuName = "查询", + ParentId = menu.MenuId, + OrderNum = 1, + Perms = $"{permPrefix}:query", + MenuType = "F", + Visible = "0", + Status = "0", + Icon = "", + }; + SysMenu menuAdd = new() + { + MenuName = "新增", + ParentId = menu.MenuId, + OrderNum = 2, + Perms = $"{permPrefix}:add", + MenuType = "F", + Visible = "0", + Status = "0", + Icon = "", + }; + SysMenu menuDel = new() + { + MenuName = "删除", + ParentId = menu.MenuId, + OrderNum = 3, + Perms = $"{permPrefix}:delete", + MenuType = "F", + Visible = "0", + Status = "0", + Icon = "", + }; + + SysMenu menuEdit = new() + { + MenuName = "修改", + ParentId = menu.MenuId, + OrderNum = 4, + Perms = $"{permPrefix}:edit", + MenuType = "F", + Visible = "0", + Status = "0", + Icon = "", + }; + + SysMenu menuExport = new() + { + MenuName = "导出", + ParentId = menu.MenuId, + OrderNum = 5, + Perms = $"{permPrefix}:export", + MenuType = "F", + Visible = "0", + Status = "0", + Icon = "", + }; + + menuList.Add(menuQuery); + menuList.Add(menuAdd); + menuList.Add(menuDel); + if (showEdit) + { + menuList.Add(menuEdit); + } + if (showExport) + { + menuList.Add(menuExport); + } + //Insert(menuList); + + var x = Storageable(menuList) + .SplitInsert(it => !it.Any()) + .SplitUpdate(it => !it.Any()) + .WhereColumns(it => new { it.MenuName, it.ParentId }) + .ToStorage(); + x.AsInsertable.ExecuteCommand();//插入可插入部分; + x.AsUpdateable.ExecuteCommand(); + } } } diff --git a/ZR.Service/System/SysNoticeService.cs b/ZR.Service/System/SysNoticeService.cs index bbe99e9..168297a 100644 --- a/ZR.Service/System/SysNoticeService.cs +++ b/ZR.Service/System/SysNoticeService.cs @@ -28,7 +28,7 @@ namespace ZR.Service.System var predicate = Expressionable.Create(); //搜索条件查询语法参考Sqlsugar - predicate = predicate.And(m => m.Status == "0"); + predicate = predicate.And(m => m.Status == 0); return GetList(predicate.ToExpression()); } diff --git a/ZR.Service/System/SysUserService.cs b/ZR.Service/System/SysUserService.cs index 959bfbe..ee874d4 100644 --- a/ZR.Service/System/SysUserService.cs +++ b/ZR.Service/System/SysUserService.cs @@ -39,7 +39,7 @@ namespace ZR.Service /// 根据条件分页查询用户列表 /// /// - public PagedInfo SelectUserList(SysUser user, PagerInfo pager) + public PagedInfo SelectUserList(SysUserQueryDto user, PagerInfo pager) { var exp = Expressionable.Create(); exp.AndIF(!string.IsNullOrEmpty(user.UserName), u => u.UserName.Contains(user.UserName)); @@ -51,15 +51,9 @@ namespace ZR.Service if (user.DeptId != 0) { - List depts = Context.Queryable().ToList(); + var allChildDepts = Context.Queryable().ToChildList(it => it.ParentId, user.DeptId); - var newDepts = depts.FindAll(delegate (SysDept dept) - { - string[] parentDeptId = dept.Ancestors.Split(",", StringSplitOptions.RemoveEmptyEntries); - return parentDeptId.Contains(user.DeptId.ToString()); - }); - string[] deptArr = newDepts.Select(x => x.DeptId.ToString()).ToArray(); - exp.AndIF(user.DeptId != 0, u => u.DeptId == user.DeptId || deptArr.Contains(u.DeptId.ToString())); + exp.And(u => allChildDepts.Select(f => f.DeptId).ToList().Contains(u.DeptId)); } var query = Queryable() .LeftJoin((u, dept) => u.DeptId == dept.DeptId) @@ -223,6 +217,10 @@ namespace ZR.Service { throw new CustomException("密码强度不符合要求"); } + if (!Tools.CheckUserName(dto.Username)) + { + throw new CustomException("用户名不符合要求"); + } //密码md5 string password = NETCore.Encrypt.EncryptProvider.Md5(dto.Password); @@ -325,7 +323,7 @@ namespace ZR.Service /// public SysUser Login(LoginBodyDto user) { - return GetFirst(it => it.UserName == user.Username && it.Password == user.Password); + return GetFirst(it => it.UserName == user.Username && it.Password.ToLower() == user.Password.ToLower()); } /// diff --git a/ZR.Vue/package.json b/ZR.Vue/package.json index 87c3a41..8c356a7 100644 --- a/ZR.Vue/package.json +++ b/ZR.Vue/package.json @@ -34,6 +34,7 @@ "js-beautify": "1.10.2", "js-cookie": "2.2.0", "jsencrypt": "3.0.0-rc.1", + "jsrsasign": "^10.8.6", "less-loader": "^6.0.0", "mavon-editor": "^2.9.1", "normalize.css": "7.0.0", diff --git a/ZR.Vue/src/api/system/login.js b/ZR.Vue/src/api/system/login.js index cd56aa7..91ea419 100644 --- a/ZR.Vue/src/api/system/login.js +++ b/ZR.Vue/src/api/system/login.js @@ -6,7 +6,7 @@ export function login(username, password, code, uuid) { username, password, code, - uuid + uuid, } return request({ url: '/login', @@ -19,7 +19,7 @@ export function login(username, password, code, uuid) { export function getInfo() { return request({ url: '/getInfo', - method: 'get' + method: 'get', }) } @@ -27,7 +27,7 @@ export function getInfo() { export function logout() { return request({ url: '/LogOut', - method: 'POST' + method: 'POST', }) } @@ -35,18 +35,26 @@ export function logout() { export function getCodeImg() { return request({ url: '/captchaImage', - method: 'get' + method: 'get', }) } /** * 注册 - * @returns + * @returns */ export function register(data) { return request({ url: '/register', method: 'post', - data: data + data: data, }) -} \ No newline at end of file +} + +// 获取RSA公钥 +export function getRsaKey() { + return request({ + url: '/getRsaKey', + method: 'get', + }) +} diff --git a/ZR.Vue/src/store/modules/user.js b/ZR.Vue/src/store/modules/user.js index 8923977..5830b5a 100644 --- a/ZR.Vue/src/store/modules/user.js +++ b/ZR.Vue/src/store/modules/user.js @@ -1,6 +1,6 @@ -import { login, logout, getInfo } from '@/api/system/login' +import { login, logout, getInfo, getRsaKey } from '@/api/system/login' import { getToken, setToken, removeToken } from '@/utils/auth' - +import { encryptByPublicKey } from '@/api/utils/jsencrypt' const user = { state: { userInfo: '', @@ -8,7 +8,7 @@ const user = { name: '', avatar: '', roles: [], - permissions: [] + permissions: [], }, mutations: { @@ -29,29 +29,34 @@ const user = { }, SET_USERINFO: (state, value) => { state.userInfo = value - } + }, }, actions: { // 登录 Login({ commit }, userInfo) { - const username = userInfo.username.trim() - const password = userInfo.password - const code = userInfo.code - const uuid = userInfo.uuid return new Promise((resolve, reject) => { - login(username, password, code, uuid).then(res => { - if (res.code == 200) { - setToken(res.data) - //提交上面的mutaions方法 - commit('SET_TOKEN', res.data) - resolve() //then处理 - } else { - console.log('login error ' + res); - reject(res) //catch处理 - } - }).catch(err => { - reject(err); + getRsaKey().then((response) => { + const publicKey = response.data.publicKey + const username = userInfo.username.trim() + const password = encryptByPublicKey(userInfo.password, publicKey) + const code = userInfo.code + const uuid = userInfo.uuid + login(username, password, code, uuid) + .then((res) => { + if (res.code == 200) { + setToken(res.data) + //提交上面的mutaions方法 + commit('SET_TOKEN', res.data) + resolve() //then处理 + } else { + console.log('login error ' + res) + reject(res) //catch处理 + } + }) + .catch((err) => { + reject(err) + }) }) }) }, @@ -59,24 +64,27 @@ const user = { // 获取用户信息 GetInfo({ commit, state }) { return new Promise((resolve, reject) => { - getInfo().then(res => { - const data = res.data - const avatar = data.user.avatar == "" ? require("@/assets/image/profile.jpg") : data.user.avatar; + getInfo() + .then((res) => { + const data = res.data + const avatar = data.user.avatar == '' ? require('@/assets/image/profile.jpg') : data.user.avatar - if (data.roles && data.roles.length > 0) { // 验证返回的roles是否是一个非空数组 - commit('SET_ROLES', data.roles) - commit('SET_PERMISSIONS', data.permissions) - } else { - commit('SET_ROLES', ['ROLE_DEFAULT']) - } + if (data.roles && data.roles.length > 0) { + // 验证返回的roles是否是一个非空数组 + commit('SET_ROLES', data.roles) + commit('SET_PERMISSIONS', data.permissions) + } else { + commit('SET_ROLES', ['ROLE_DEFAULT']) + } - commit('SET_NAME', data.user.nickName) - commit('SET_AVATAR', avatar) - commit('SET_USERINFO', data.user) //新加 - resolve(res) - }).catch(error => { - reject(error) - }) + commit('SET_NAME', data.user.nickName) + commit('SET_AVATAR', avatar) + commit('SET_USERINFO', data.user) //新加 + resolve(res) + }) + .catch((error) => { + reject(error) + }) }) }, @@ -84,27 +92,29 @@ const user = { LogOut({ commit, state }) { console.log('退出登录') return new Promise((resolve, reject) => { - logout().then((res) => { - removeToken() // 必须先移除token - commit('SET_TOKEN', '') - commit('SET_ROLES', []) - commit('SET_PERMISSIONS', []) - resolve(res) - }).catch(error => { - reject(error) - }) + logout() + .then((res) => { + removeToken() // 必须先移除token + commit('SET_TOKEN', '') + commit('SET_ROLES', []) + commit('SET_PERMISSIONS', []) + resolve(res) + }) + .catch((error) => { + reject(error) + }) }) }, // 前端 登出 FedLogOut({ commit }) { - return new Promise(resolve => { + return new Promise((resolve) => { commit('SET_TOKEN', '') removeToken() resolve() }) - } - } + }, + }, } -export default user \ No newline at end of file +export default user diff --git a/ZR.Vue/src/utils/jsencrypt.js b/ZR.Vue/src/utils/jsencrypt.js index d8ce5cd..0181419 100644 --- a/ZR.Vue/src/utils/jsencrypt.js +++ b/ZR.Vue/src/utils/jsencrypt.js @@ -1,5 +1,5 @@ import JSEncrypt from 'jsencrypt/bin/jsencrypt.min' - +import jsrsasign from 'jsrsasign' // 密钥对生成 http://web.chacuo.net/netrsakeypair const publicKey = 'MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBALj0zjON+EVdBsnMcR4Uj+jOYgp5ZipftQZ1utW8KvVioz+RSaotF1JHt59q9SC/mZcWWpbpcEqQ3WyyyCC33msCAwEAAQ==' @@ -21,3 +21,7 @@ export function decrypt(txt) { return encryptor.decrypt(txt) // 对数据进行解密 } +export const encryptByPublicKey = (txt, publicKey) => { + const pubKey = jsrsasign.KEYUTIL.getKey(publicKey) + return jsrsasign.KJUR.crypto.Cipher.encrypt(txt, pubKey) +} diff --git a/ZR.Vue/src/views/monitor/job/index.vue b/ZR.Vue/src/views/monitor/job/index.vue index 2976c98..68ff18b 100644 --- a/ZR.Vue/src/views/monitor/job/index.vue +++ b/ZR.Vue/src/views/monitor/job/index.vue @@ -4,8 +4,14 @@ - + 搜索 @@ -25,10 +31,13 @@ 删除 --> - 导出 + 导出 - 日志 + 日志 @@ -45,29 +54,77 @@ @@ -79,7 +136,7 @@ -
{{form.id}}
+
{{ form.id }}
@@ -89,7 +146,7 @@ - + @@ -164,12 +221,12 @@ 开始日期 - + - + @@ -191,14 +248,14 @@ - + -

{{item.jobMessage}}

-

{{item.exception}}

+

{{ item.jobMessage }}

+

{{ item.exception }}

@@ -207,17 +264,7 @@ diff --git a/ZR.Vue/src/views/monitor/onlineuser/index.vue b/ZR.Vue/src/views/monitor/onlineuser/index.vue new file mode 100644 index 0000000..3525132 --- /dev/null +++ b/ZR.Vue/src/views/monitor/onlineuser/index.vue @@ -0,0 +1,3 @@ + diff --git a/ZR.Vue/src/views/system/notice/index.vue b/ZR.Vue/src/views/system/notice/index.vue index ee85336..301947c 100644 --- a/ZR.Vue/src/views/system/notice/index.vue +++ b/ZR.Vue/src/views/system/notice/index.vue @@ -23,13 +23,28 @@ 新增
- + 修改 - 删除 + 删除 @@ -58,15 +73,20 @@
- + @@ -80,14 +100,14 @@ - + - {{dict.dictLabel}} + {{ dict.dictLabel }} @@ -115,10 +135,10 @@ import { updateNotice, sendNotice, // exportNotice, -} from "@/api/system/notice"; +} from '@/api/system/notice' export default { - name: "notice", + name: 'notice', data() { return { // 遮罩层 @@ -136,7 +156,7 @@ export default { // 公告表格数据 noticeList: [], // 弹出层标题 - title: "", + title: '', // 是否显示弹出层 open: false, // 类型数据字典 @@ -155,38 +175,34 @@ export default { form: {}, // 表单校验 rules: { - noticeTitle: [ - { required: true, message: "公告标题不能为空", trigger: "blur" }, - ], - noticeType: [ - { required: true, message: "公告类型不能为空", trigger: "change" }, - ], + noticeTitle: [{ required: true, message: '公告标题不能为空', trigger: 'blur' }], + noticeType: [{ required: true, message: '公告类型不能为空', trigger: 'change' }], }, - }; + } }, created() { - this.getList(); - this.getDicts("sys_notice_status").then((response) => { - this.statusOptions = response.data; - }); - this.getDicts("sys_notice_type").then((response) => { - this.typeOptions = response.data; - }); + this.getList() + this.getDicts('sys_notice_status').then((response) => { + this.statusOptions = response.data + }) + this.getDicts('sys_notice_type').then((response) => { + this.typeOptions = response.data + }) }, methods: { /** 查询公告列表 */ getList() { - this.loading = true; + this.loading = true listNotice(this.queryParams).then((res) => { - this.noticeList = res.data.result; - this.total = res.data.totalNum; - this.loading = false; - }); + this.noticeList = res.data.result + this.total = res.data.totalNum + this.loading = false + }) }, // 取消按钮 cancel() { - this.open = false; - this.reset(); + this.open = false + this.reset() }, // 表单重置 reset() { @@ -195,93 +211,89 @@ export default { noticeTitle: undefined, noticeType: undefined, noticeContent: undefined, - status: "0", - }; - this.resetForm("form"); + status: 0, + } + this.resetForm('form') }, /** 搜索按钮操作 */ handleQuery() { - this.queryParams.pageNum = 1; - this.getList(); + this.queryParams.pageNum = 1 + this.getList() }, /** 重置按钮操作 */ resetQuery() { - this.resetForm("queryForm"); - this.handleQuery(); + this.resetForm('queryForm') + this.handleQuery() }, // 多选框选中数据 handleSelectionChange(selection) { - this.ids = selection.map((item) => item.noticeId); - this.single = selection.length != 1; - this.multiple = !selection.length; + this.ids = selection.map((item) => item.noticeId) + this.single = selection.length != 1 + this.multiple = !selection.length }, /** 新增按钮操作 */ handleAdd() { - this.reset(); - this.open = true; - this.title = "添加公告"; + this.reset() + this.open = true + this.title = '添加公告' }, /** 修改按钮操作 */ handleUpdate(row) { - this.reset(); - const noticeId = row.noticeId || this.ids; + this.reset() + const noticeId = row.noticeId || this.ids getNotice(noticeId).then((response) => { - this.form = response.data; - this.open = true; - this.title = "修改公告"; - }); + this.form = response.data + this.open = true + this.title = '修改公告' + }) }, - // 发送通知 + // 发送通知 handleNotice(row) { - const noticeId = row.noticeId || this.ids; - sendNotice(noticeId).then(res => { - this.msgSuccess("发送通知成功"); - }); + const noticeId = row.noticeId || this.ids + sendNotice(noticeId).then((res) => { + this.msgSuccess('发送通知成功') + }) }, /** 提交按钮 */ submitForm: function () { - this.$refs["form"].validate((valid) => { + this.$refs['form'].validate((valid) => { if (valid) { if (this.form.noticeId != undefined) { updateNotice(this.form).then((response) => { if (!response.data) { - this.msgError("修改失败"); - return; + this.msgError('修改失败') + return } - this.msgSuccess("修改成功"); - this.open = false; - this.getList(); - }); + this.msgSuccess('修改成功') + this.open = false + this.getList() + }) } else { addNotice(this.form).then((response) => { - this.msgSuccess("新增成功"); - this.open = false; - this.getList(); - }); + this.msgSuccess('新增成功') + this.open = false + this.getList() + }) } } - }); + }) }, /** 删除按钮操作 */ handleDelete(row) { - const noticeIds = row.noticeId || this.ids; - this.$confirm( - '是否确认删除公告编号为"' + noticeIds + '"的数据项?', - "警告", - { - confirmButtonText: "确定", - cancelButtonText: "取消", - type: "warning", - } - ) + const noticeIds = row.noticeId || this.ids + this.$confirm('是否确认删除公告编号为"' + noticeIds + '"的数据项?', '警告', { + confirmButtonText: '确定', + cancelButtonText: '取消', + type: 'warning', + }) .then(function () { - return delNotice(noticeIds); + return delNotice(noticeIds) }) .then(() => { - this.getList(); - this.msgSuccess("删除成功"); - }); + this.getList() + this.msgSuccess('删除成功') + }) }, }, -}; +} diff --git a/document/images/1.png b/document/images/1.png index 7086dd7..d146fc0 100644 Binary files a/document/images/1.png and b/document/images/1.png differ diff --git a/document/images/14.png b/document/images/14.png index 5af9de6..62f0596 100644 Binary files a/document/images/14.png and b/document/images/14.png differ diff --git a/document/images/a1.png b/document/images/a1.png new file mode 100644 index 0000000..4f2b934 Binary files /dev/null and b/document/images/a1.png differ diff --git a/document/images/a2.png b/document/images/a2.png new file mode 100644 index 0000000..5fe545b Binary files /dev/null and b/document/images/a2.png differ diff --git a/document/images/a4.png b/document/images/a4.png new file mode 100644 index 0000000..992af2a Binary files /dev/null and b/document/images/a4.png differ diff --git a/document/images/a5.png b/document/images/a5.png new file mode 100644 index 0000000..ede23b4 Binary files /dev/null and b/document/images/a5.png differ diff --git a/document/images/a6.png b/document/images/a6.png new file mode 100644 index 0000000..4f0e1d6 Binary files /dev/null and b/document/images/a6.png differ diff --git a/document/images/a8.png b/document/images/a8.png new file mode 100644 index 0000000..f8d813c Binary files /dev/null and b/document/images/a8.png differ diff --git a/document/images/qrcodeH5.png b/document/images/qrcodeH5.png index 0f27fa5..584c0b0 100644 Binary files a/document/images/qrcodeH5.png and b/document/images/qrcodeH5.png differ diff --git a/document/mysql/admin-mysql.sql b/document/mysql/admin-mysql.sql index 7b56701..e8b4d55 100644 --- a/document/mysql/admin-mysql.sql +++ b/document/mysql/admin-mysql.sql @@ -35,38 +35,52 @@ CREATE TABLE `sys_tasks` ( -- ---------------------------- -- Table structure for sys_tasks_log -- ---------------------------- -DROP TABLE IF EXISTS `sys_tasks_log`; -CREATE TABLE `sys_tasks_log` ( - `jobLogId` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '任务日志ID', - `jobId` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '任务id', - `jobName` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '任务名称', - `jobGroup` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '任务组名', - `jobMessage` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '日志信息', - `status` char(1) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT '0' COMMENT '执行状态(0正常 1失败)', - `exception` varchar(2000) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT '' COMMENT '异常信息', - `createTime` datetime(0) NULL DEFAULT NULL COMMENT '创建时间', - `invokeTarget` varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '调用目标', - `elapsed` double(10, 0) NULL DEFAULT NULL COMMENT '作业用时', - PRIMARY KEY (`jobLogId`) USING BTREE -) ENGINE = InnoDB AUTO_INCREMENT = 198 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '定时任务调度日志表' ROW_FORMAT = Dynamic; - +DROP TABLE +IF + EXISTS `sys_tasks_log`; +CREATE TABLE `sys_tasks_log` ( + `jobLogId` BIGINT ( 20 ) NOT NULL AUTO_INCREMENT COMMENT '任务日志ID', + `jobId` VARCHAR ( 20 ) CHARACTER + SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '任务id', + `jobName` VARCHAR ( 64 ) CHARACTER + SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '任务名称', + `jobGroup` VARCHAR ( 64 ) CHARACTER + SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '任务组名', + `jobMessage` VARCHAR ( 500 ) CHARACTER + SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '日志信息', + `status` CHAR ( 1 ) CHARACTER + SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT '0' COMMENT '执行状态(0正常 1失败)', + `exception` VARCHAR ( 2000 ) CHARACTER + SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT '' COMMENT '异常信息', + `createTime` DATETIME ( 0 ) NULL DEFAULT NULL COMMENT '创建时间', + `invokeTarget` VARCHAR ( 200 ) CHARACTER + SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '调用目标', + `elapsed` DOUBLE ( 10, 0 ) NULL DEFAULT NULL COMMENT '作业用时', + PRIMARY KEY ( `jobLogId` ) USING BTREE +) ENGINE = INNODB AUTO_INCREMENT = 198 CHARACTER +SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '定时任务调度日志表' ROW_FORMAT = Dynamic; -- ---------------------------- -- 通知公告表 -- ---------------------------- -drop table if exists sys_notice; -create table sys_notice ( - notice_id int(4) not null auto_increment comment '公告ID', - notice_title varchar(50) not null comment '公告标题', - notice_type char(1) not null comment '公告类型(1通知 2公告)', - notice_content varchar(500) default null comment '公告内容', - status char(1) default '0' comment '公告状态(0正常 1关闭)', - create_by varchar(64) default '' comment '创建者', - create_time datetime comment '创建时间', - update_by varchar(64) default '' comment '更新者', - update_time datetime comment '更新时间', - remark varchar(255) default null comment '备注', - primary key (notice_id) -) engine=innodb auto_increment=10 comment = '通知公告表'; +DROP TABLE +IF + EXISTS sys_notice; +CREATE TABLE sys_notice ( + notice_id INT ( 4 ) NOT NULL auto_increment COMMENT '公告ID', + notice_title VARCHAR ( 50 ) CHARACTER + SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '公告标题', + notice_type INT NOT NULL COMMENT '公告类型(1通知 2公告)', + notice_content TEXT CHARACTER + SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '公告内容', + `status` INT DEFAULT 0 COMMENT '公告状态(0正常 1关闭)', + create_by VARCHAR ( 64 ) DEFAULT '' COMMENT '创建者', + create_time DATETIME COMMENT '创建时间', + update_by VARCHAR ( 64 ) DEFAULT '' COMMENT '更新者', + update_time DATETIME COMMENT '更新时间', + remark VARCHAR ( 255 ) CHARACTER + SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '备注', + PRIMARY KEY ( notice_id ) +) ENGINE = INNODB auto_increment = 1 COMMENT = '通知公告表'; -- ---------------------------- @@ -82,8 +96,8 @@ CREATE TABLE `sys_dept` ( `leader` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '负责人', `phone` varchar(11) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '联系电话', `email` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '邮箱', - `status` char(1) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT '0' COMMENT '部门状态(0正常 1停用)', - `delFlag` char(1) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT '0' COMMENT '删除标志(0代表存在 2代表删除)', + `status` varchar(1) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT '0' COMMENT '部门状态(0正常 1停用)', + `delFlag` varchar(1) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT '0' COMMENT '删除标志(0代表存在 2代表删除)', `create_by` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT '' COMMENT '创建者', `create_time` datetime(0) NULL DEFAULT NULL COMMENT '创建时间', `update_by` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT '' COMMENT '更新者', @@ -167,9 +181,9 @@ CREATE TABLE `sys_menu` ( `component` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '组件路径', `isFrame` int(1) NULL DEFAULT 0 COMMENT '是否外链(0 否 1 是)', `isCache` int(1) NULL DEFAULT 0 COMMENT '是否缓存(0缓存 1不缓存)', - `menuType` char(1) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT '' COMMENT '菜单类型(M目录 C菜单 F按钮 L链接)', - `visible` char(1) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT '0' COMMENT '菜单状态(0显示 1隐藏)', - `status` char(1) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT '0' COMMENT '菜单状态(0正常 1停用)', + `menuType` varchar(1) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT '' COMMENT '菜单类型(M目录 C菜单 F按钮 L链接)', + `visible` varchar(1) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT '0' COMMENT '菜单状态(0显示 1隐藏)', + `status` varchar(1) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT '0' COMMENT '菜单状态(0正常 1停用)', `perms` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '权限标识', `icon` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT '#' COMMENT '菜单图标', `create_by` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT '' COMMENT '创建者', @@ -215,7 +229,7 @@ CREATE TABLE `sys_post` ( `postCode` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '岗位编码', `postName` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '岗位名称', `postSort` int(4) NOT NULL COMMENT '显示顺序', - `status` char(1) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '状态(0正常 1停用)', + `status` varchar(1) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '状态(0正常 1停用)', `create_by` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT '' COMMENT '创建者', `create_time` datetime(0) NULL DEFAULT NULL COMMENT '创建时间', `update_by` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT '' COMMENT '更新者', @@ -360,7 +374,7 @@ create table sys_config ( configName varchar(100) default '' comment '参数名称', configKey varchar(100) default '' comment '参数键名', configValue varchar(500) default '' comment '参数键值', - configType char(1) default 'N' comment '系统内置(Y是 N否)', + configType varchar(1) default 'N' comment '系统内置(Y是 N否)', create_by varchar(64) default '' comment '创建者', create_time datetime comment '创建时间', update_by varchar(64) default '' comment '更新者', diff --git a/document/oracle/seq.txt b/document/oracle/seq.txt new file mode 100644 index 0000000..c8d5468 --- /dev/null +++ b/document/oracle/seq.txt @@ -0,0 +1,46 @@ + +--通用序列id +create sequence SEQ_ID +minvalue 1 +maxvalue 99999999 +start with 1 +increment by 1 +nocache +order; + +--角色表序列id +create sequence SEQ_SYS_ROLE_ROLEID +minvalue 10 +maxvalue 99999999 +start with 10 +increment by 1 +nocache +order; + +--菜单表序列id +create sequence SEQ_SYS_MENU_MENUID +minvalue 2000 +maxvalue 99999999 +start with 2000 +increment by 1 +nocache +order; + +--用户表序列id +create sequence SEQ_SYS_USER_USERID +minvalue 100 +maxvalue 99999999 +start with 1 +increment by 100 +nocache +order; + +--部门表序列id +create sequence SEQ_SYS_DEPT_DEPTID +minvalue 200 +maxvalue 99999999 +start with 200 +increment by 1 +nocache +order; + diff --git a/document/pgsql/admin-pg15.sql b/document/pgsql/admin-pg15.sql index d14fb75..abb95cf 100644 --- a/document/pgsql/admin-pg15.sql +++ b/document/pgsql/admin-pg15.sql @@ -683,9 +683,9 @@ DROP TABLE IF EXISTS "public"."sys_notice"; CREATE TABLE "public"."sys_notice" ( "notice_id" int4 NOT NULL DEFAULT nextval('sys_noticeid_seq'::regclass), "notice_title" varchar(50) COLLATE "pg_catalog"."default" NOT NULL, - "notice_type" char(1) COLLATE "pg_catalog"."default" NOT NULL, + "notice_type" int4 NOT NULL, "notice_content" varchar(500) COLLATE "pg_catalog"."default", - "status" char(1) COLLATE "pg_catalog"."default", + "status" int4, "create_by" varchar(64) COLLATE "pg_catalog"."default", "create_time" timestamp(6), "update_by" varchar(64) COLLATE "pg_catalog"."default", @@ -788,8 +788,8 @@ CREATE TABLE "public"."sys_role" ( "rolekey" varchar(100) COLLATE "pg_catalog"."default" NOT NULL, "rolesort" int4 NOT NULL, "datascope" int4 COLLATE "pg_catalog"."default", - "menu_check_strictly" int2, - "dept_check_strictly" int2 NOT NULL, + "menu_check_strictly" bool, + "dept_check_strictly" bool NOT NULL, "status" int4 COLLATE "pg_catalog"."default" NOT NULL, "delflag" int4 COLLATE "pg_catalog"."default" NOT NULL, "create_by" varchar(64) COLLATE "pg_catalog"."default", diff --git a/document/sqlserver/admin-sqlserver.sql b/document/sqlserver/admin-sqlserver.sql index 3c72ac8..a2bd8e5 100644 --- a/document/sqlserver/admin-sqlserver.sql +++ b/document/sqlserver/admin-sqlserver.sql @@ -31,7 +31,6 @@ CREATE TABLE sys_tasks requestMethod VARCHAR(10) --请求方法 ) GO -GO if OBJECT_ID(N'sys_tasks_log',N'U') is not NULL DROP TABLE sys_tasks_log GO /**定时任务调度日志表*/ @@ -55,9 +54,9 @@ GO CREATE TABLE [dbo].[sys_notice]( [notice_id] [int] NOT NULL PRIMARY KEY IDENTITY(1,1), [notice_title] [varchar](100) NULL, - [notice_type] [char](1) NULL, + [notice_type] int NULL, [notice_content] [text] NULL, - [status] [char](1) NULL, + [status] int NULL, [create_by] [varchar](64) NULL, [create_time] [datetime] NULL, [update_by] [varchar](64) NULL, @@ -105,8 +104,8 @@ CREATE TABLE sys_dict_type ( customSql varchar(500) NULL DEFAULT NULL ,-- '自定义sql', ) GO -CREATE UNIQUE INDEX dictType ON dbo.sys_dict_type(dictType) -GO +--CREATE UNIQUE INDEX dictType ON dbo.sys_dict_type(dictType) +--GO if OBJECT_ID(N'sys_dict_data',N'U') is not NULL DROP TABLE sys_dict_data GO @@ -138,7 +137,7 @@ CREATE TABLE sys_logininfor ( loginLocation varchar(255) NULL DEFAULT '' ,-- '登录地点', browser varchar(50) NULL DEFAULT '' ,-- '浏览器类型', os varchar(50) NULL DEFAULT '' ,-- '操作系统', - status char(1) NULL DEFAULT '0' ,-- '登录状态(0成功 1失败)', + status varchar(1) NULL DEFAULT '0' ,-- '登录状态(0成功 1失败)', msg varchar(255) NULL DEFAULT '' ,-- '提示消息', loginTime DATETIME NULL DEFAULT NULL ,-- '访问时间', ) @@ -154,9 +153,9 @@ CREATE TABLE sys_menu ( component varchar(255) NULL DEFAULT NULL ,-- '组件路径', isFrame int NULL DEFAULT 0 ,-- '是否外链(0 否 1 是)', isCache int NULL DEFAULT 0 ,-- '是否缓存(0缓存 1不缓存)', - menuType char(1) NULL DEFAULT '' ,-- '菜单类型(M目录 C菜单 F按钮 L链接)', - visible char(1) NULL DEFAULT '0' ,-- '菜单状态(0显示 1隐藏)', - status char(1) NULL DEFAULT '0' ,-- '菜单状态(0正常 1停用)', + menuType varchar(1) NULL DEFAULT '' ,-- '菜单类型(M目录 C菜单 F按钮 L链接)', + visible varchar(1) NULL DEFAULT '0' ,-- '菜单状态(0显示 1隐藏)', + status varchar(1) NULL DEFAULT '0' ,-- '菜单状态(0正常 1停用)', perms varchar(100) NULL DEFAULT NULL ,-- '权限标识', icon varchar(100) NULL DEFAULT '#' ,-- '菜单图标', create_by varchar(64) NULL DEFAULT '' ,-- '创建者', @@ -187,7 +186,7 @@ CREATE TABLE sys_oper_log ( operIP varchar(50) DEFAULT '' , -- '主机地址', operLocation varchar(255) DEFAULT '' , -- '操作地点', operParam varchar(2000) DEFAULT '' , -- '请求参数', - jsonResult varchar(max) DEFAULT '' , -- '返回参数', + jsonResult TEXT DEFAULT '' , -- '返回参数', status int NULL DEFAULT 0 , -- '操作状态(0正常 1异常)', errorMsg varchar(2000) DEFAULT '' , -- '错误消息', operTime datetime NULL DEFAULT NULL , -- '操作时间', @@ -266,8 +265,8 @@ CREATE TABLE sys_role ( roleKey varchar(100) NOT NULL , -- '角色权限字符串', roleSort int NOT NULL , -- '显示顺序', dataScope int NULL DEFAULT 1 , -- '数据范围(1:全部数据权限 2:自定数据权限 3:本部门数据权限 )', - menu_check_strictly int NULL DEFAULT 1 , -- '菜单树选择项是否关联显示', - dept_check_strictly int NOT NULL DEFAULT 1 , -- '部门树选择项是否关联显示', + menu_check_strictly BIT NOT NULL DEFAULT 1 , -- '菜单树选择项是否关联显示', + dept_check_strictly BIT NOT NULL DEFAULT 1 , -- '部门树选择项是否关联显示', status int NOT NULL , -- '角色状态(0正常 1停用)', delFlag int NOT NULL DEFAULT 0 , -- '删除标志(0代表存在 2代表删除)', create_by varchar(64) NULL DEFAULT '' , -- '创建者', @@ -311,7 +310,10 @@ CREATE TABLE sys_role_menu ( role_id bigint NOT NULL , -- '角色ID', menu_id bigint NOT NULL , -- '菜单ID', create_by varchar(20) DEFAULT NULL, - create_time datetime NULL DEFAULT NULL + create_time datetime NULL DEFAULT NULL, + update_by VARCHAR(20) DEFAULT NULL, + update_time DATETIME NULL , + remark VARCHAR(100) ) GO alter table sys_role_menu add primary key(menu_id,role_id)