From c97a386f0f305934be247c21baf1bb6bb3c02892 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=8D=E5=81=9A=E7=A0=81=E5=86=9C?= <599854767@qq.com> Date: Fri, 28 Jul 2023 07:26:40 +0800 Subject: [PATCH 01/20] =?UTF-8?q?:sparkles:=20=E7=A7=BB=E5=8A=A8=E7=AB=AF?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=E7=94=9F=E6=88=90=E8=8E=B7=E5=8F=96=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E6=96=B0=E5=A2=9E=E5=8A=A0=E8=BD=BD=E4=B8=AD=E6=8F=90?= =?UTF-8?q?=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../wwwroot/CodeGenTemplate/app/vue2.txt | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/app/vue2.txt b/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/app/vue2.txt index b2f51734..c964ad94 100644 --- a/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/app/vue2.txt +++ b/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/app/vue2.txt @@ -126,7 +126,7 @@ $end - + @@ -174,13 +174,14 @@ $end loading: false, $foreach(item in genTable.Columns) $if((item.HtmlType == "radio" || item.HtmlType == "select" || item.HtmlType == "checkbox") && item.DictType == "") - // ${item.ColumnComment}选项列表 格式 eg:{ dictLabel: '标签', dictValue: '0'} + // ${item.ColumnComment}选项列表 格式 eg:{ label: '标签', value: '0'} ${item.CsharpFieldFl}Options: [], $elseif(item.HtmlType == "datetime" && item.IsQuery == true) //${item.ColumnComment}时间范围 dateRange${item.CsharpField}: [], $end $end + // 排序集合 格式 eg:{ label: '名称', value: 'userId'} sortOptions: [ $foreach(column in genTable.Columns) $if(column.IsSort) @@ -199,6 +200,9 @@ $end methods: { checkPermi, getList() { + uni.showLoading({ + title: 'loading...' + }); $foreach(item in genTable.Columns) $if(item.HtmlType == "datetime" && item.IsQuery == true) this.addDateRange(this.queryParams, this.dateRange${item.CsharpField}, '${item.CsharpField}'); @@ -206,9 +210,8 @@ $end $end list${genTable.BusinessName}(this.queryParams).then(res => { if (res.code == 200) { - this.dataList = res.data.result; + this.dataList = [...this.dataList, ...res.data.result] this.total = res.data.totalNum; - this.loading = false; } }) }, @@ -282,10 +285,4 @@ $end } } } - - - \ No newline at end of file + \ No newline at end of file From a5b2a564b7073fcc4b75058ba04aafddad9cbf3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=8D=E5=81=9A=E7=A0=81=E5=86=9C?= <599854767@qq.com> Date: Fri, 28 Jul 2023 07:27:03 +0800 Subject: [PATCH 02/20] =?UTF-8?q?:sparkles:=20=E7=94=A8=E6=88=B7=E6=9F=A5?= =?UTF-8?q?=E8=AF=A2=E6=96=B0=E5=A2=9E=E6=A0=B9=E6=8D=AE=E7=94=A8=E6=88=B7?= =?UTF-8?q?id=E6=9F=A5=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ZR.Model/System/Dto/SysUserDto.cs | 2 +- ZR.Service/System/SysUserService.cs | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/ZR.Model/System/Dto/SysUserDto.cs b/ZR.Model/System/Dto/SysUserDto.cs index d8ba37a4..2dc0b955 100644 --- a/ZR.Model/System/Dto/SysUserDto.cs +++ b/ZR.Model/System/Dto/SysUserDto.cs @@ -18,7 +18,7 @@ namespace ZR.Model.System.Dto public class SysUserQueryDto { - public long UserId { get; set; } + public long? UserId { get; set; } public string UserName { get; set; } public string NickName { get; set; } public string Email { get; set; } diff --git a/ZR.Service/System/SysUserService.cs b/ZR.Service/System/SysUserService.cs index ee874d4f..ff31d263 100644 --- a/ZR.Service/System/SysUserService.cs +++ b/ZR.Service/System/SysUserService.cs @@ -43,6 +43,7 @@ namespace ZR.Service { var exp = Expressionable.Create(); exp.AndIF(!string.IsNullOrEmpty(user.UserName), u => u.UserName.Contains(user.UserName)); + exp.AndIF(user.UserId > 0, u => u.UserId == user.UserId); exp.AndIF(user.Status != -1, u => u.Status == user.Status); exp.AndIF(user.BeginTime != DateTime.MinValue && user.BeginTime != null, u => u.Create_time >= user.BeginTime); exp.AndIF(user.EndTime != DateTime.MinValue && user.EndTime != null, u => u.Create_time <= user.EndTime); From 84ae9b0a922208b1489fb3d382519580c984152e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=8D=E5=81=9A=E7=A0=81=E5=86=9C?= <599854767@qq.com> Date: Thu, 27 Jul 2023 17:56:52 +0800 Subject: [PATCH 03/20] =?UTF-8?q?:arrow=5Fup:=20=E5=8D=87=E7=BA=A7sqlsugar?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ZR.Admin.WebApi/Program.cs | 3 +-- ZR.CodeGenerator/ZR.CodeGenerator.csproj | 2 +- ZR.Model/ZR.Model.csproj | 2 +- ZR.Repository/BaseRepository.cs | 15 +++++++++++---- ZR.Repository/ZR.Repository.csproj | 2 +- 5 files changed, 15 insertions(+), 9 deletions(-) diff --git a/ZR.Admin.WebApi/Program.cs b/ZR.Admin.WebApi/Program.cs index 690339a5..db451842 100644 --- a/ZR.Admin.WebApi/Program.cs +++ b/ZR.Admin.WebApi/Program.cs @@ -80,8 +80,7 @@ builder.Services.AddMvc(options => }) .AddJsonOptions(options => { - options.JsonSerializerOptions.NumberHandling = JsonNumberHandling.AllowReadingFromString | - JsonNumberHandling.WriteAsString; + options.JsonSerializerOptions.NumberHandling = JsonNumberHandling.AllowReadingFromString | JsonNumberHandling.WriteAsString; options.JsonSerializerOptions.WriteIndented = true; options.JsonSerializerOptions.Converters.Add(new JsonConverterUtil.DateTimeConverter()); options.JsonSerializerOptions.Converters.Add(new JsonConverterUtil.DateTimeNullConverter()); diff --git a/ZR.CodeGenerator/ZR.CodeGenerator.csproj b/ZR.CodeGenerator/ZR.CodeGenerator.csproj index 8cb72a71..f764c135 100644 --- a/ZR.CodeGenerator/ZR.CodeGenerator.csproj +++ b/ZR.CodeGenerator/ZR.CodeGenerator.csproj @@ -12,6 +12,6 @@ - + diff --git a/ZR.Model/ZR.Model.csproj b/ZR.Model/ZR.Model.csproj index b5eba233..e9dd6178 100644 --- a/ZR.Model/ZR.Model.csproj +++ b/ZR.Model/ZR.Model.csproj @@ -9,7 +9,7 @@ - + diff --git a/ZR.Repository/BaseRepository.cs b/ZR.Repository/BaseRepository.cs index e6d7351e..577acd56 100644 --- a/ZR.Repository/BaseRepository.cs +++ b/ZR.Repository/BaseRepository.cs @@ -351,8 +351,12 @@ namespace ZR.Repository var total = 0; page.PageSize = parm.PageSize; page.PageIndex = parm.PageNum; - - page.Result = source.OrderByIF(parm.Sort.IsNotEmpty(), $"{parm.Sort.ToSqlFilter()} {(!string.IsNullOrWhiteSpace(parm.SortType) && parm.SortType.Contains("desc") ? "desc" : "asc")}") + if (parm.Sort.IsNotEmpty()) + { + source.OrderByPropertyName(parm.Sort, parm.SortType.Contains("desc") ? OrderByType.Desc : OrderByType.Asc); + } + page.Result = source + //.OrderByIF(parm.Sort.IsNotEmpty(), $"{parm.Sort.ToSqlFilter()} {(!string.IsNullOrWhiteSpace(parm.SortType) && parm.SortType.Contains("desc") ? "desc" : "asc")}") .ToPageList(parm.PageNum, parm.PageSize, ref total); page.TotalNum = total; return page; @@ -372,9 +376,12 @@ namespace ZR.Repository var total = 0; page.PageSize = parm.PageSize; page.PageIndex = parm.PageNum; - + if (parm.Sort.IsNotEmpty()) + { + source.OrderByPropertyName(parm.Sort, parm.SortType.Contains("desc") ? OrderByType.Desc : OrderByType.Asc); + } var result = source - .OrderByIF(parm.Sort.IsNotEmpty(), $"{parm.Sort.ToSqlFilter()} {(!string.IsNullOrWhiteSpace(parm.SortType) && parm.SortType.Contains("desc") ? "desc" : "asc")}") + //.OrderByIF(parm.Sort.IsNotEmpty(), $"{parm.Sort.ToSqlFilter()} {(!string.IsNullOrWhiteSpace(parm.SortType) && parm.SortType.Contains("desc") ? "desc" : "asc")}") .ToPageList(parm.PageNum, parm.PageSize, ref total); page.TotalNum = total; diff --git a/ZR.Repository/ZR.Repository.csproj b/ZR.Repository/ZR.Repository.csproj index a47f0544..a545e8bc 100644 --- a/ZR.Repository/ZR.Repository.csproj +++ b/ZR.Repository/ZR.Repository.csproj @@ -15,6 +15,6 @@ - + From 2ad3ea1fd8084ba0cf368fc67661f4d8079f98a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=8D=E5=81=9A=E7=A0=81=E5=86=9C?= <599854767@qq.com> Date: Fri, 28 Jul 2023 17:37:36 +0800 Subject: [PATCH 04/20] =?UTF-8?q?:sparkles:=E4=BB=A3=E7=A0=81=E7=94=9F?= =?UTF-8?q?=E6=88=90=E6=96=B0=E5=A2=9E=E5=AF=BC=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ZR.Admin.WebApi/Controllers/BaseController.cs | 30 +++++++------ .../System/CodeGeneratorController.cs | 2 +- ZR.Admin.WebApi/GlobalUsing.cs | 7 +++ .../CodeGenTemplate/TplControllers.txt | 43 ++++++++++++++++--- .../wwwroot/CodeGenTemplate/TplIService.txt | 4 ++ .../wwwroot/CodeGenTemplate/TplService.txt | 35 +++++++++++++++ .../wwwroot/CodeGenTemplate/v3/Vue.txt | 41 ++++++++++++++++-- ZR.CodeGenerator/CodeGeneratorTool.cs | 2 + ZR.CodeGenerator/Model/ReplaceDto.cs | 1 + ZR.Service/GlobalUsing.cs | 1 + ZR.Service/System/IService/ISysMenuService.cs | 2 +- ZR.Service/System/SysMenuService.cs | 18 +++++++- 12 files changed, 160 insertions(+), 26 deletions(-) create mode 100644 ZR.Admin.WebApi/GlobalUsing.cs create mode 100644 ZR.Service/GlobalUsing.cs diff --git a/ZR.Admin.WebApi/Controllers/BaseController.cs b/ZR.Admin.WebApi/Controllers/BaseController.cs index 53110266..50576ea4 100644 --- a/ZR.Admin.WebApi/Controllers/BaseController.cs +++ b/ZR.Admin.WebApi/Controllers/BaseController.cs @@ -58,9 +58,11 @@ namespace ZR.Admin.WebApi.Controllers /// protected IActionResult ExportExcel(string path, string fileName) { - //IWebHostEnvironment webHostEnvironment = (IWebHostEnvironment)App.ServiceProvider.GetService(typeof(IWebHostEnvironment)); - //string fileDir = Path.Combine(webHostEnvironment.WebRootPath, path, fileName); - + //var webHostEnvironment = App.WebHostEnvironment; + if (!Path.Exists(path)) + { + throw new CustomException(fileName + "文件不存在"); + } var stream = Io.File.OpenRead(path); //创建文件流 Response.Headers.Add("Access-Control-Expose-Headers", "Content-Disposition"); @@ -169,23 +171,23 @@ namespace ZR.Admin.WebApi.Controllers /// /// 下载导入模板 /// - /// - /// - /// + /// 数据类型 + /// 空数据类型集合 /// 下载文件名 /// - protected string DownloadImportTemplate(List list, Stream stream, string fileName) + protected (string, string) DownloadImportTemplate(List list, string fileName) { - IWebHostEnvironment webHostEnvironment = (IWebHostEnvironment)App.ServiceProvider.GetService(typeof(IWebHostEnvironment)); - string sFileName = $"{fileName}模板.xlsx"; - string newFileName = Path.Combine(webHostEnvironment.WebRootPath, "ImportTemplate", sFileName); + IWebHostEnvironment webHostEnvironment = App.WebHostEnvironment; + string sFileName = $"{fileName}.xlsx"; + string fullPath = Path.Combine(webHostEnvironment.WebRootPath, "ImportTemplate", sFileName); - if (!Directory.Exists(newFileName)) + //不存在模板创建模板 + if (!Directory.Exists(fullPath)) { - Directory.CreateDirectory(Path.GetDirectoryName(newFileName)); + Directory.CreateDirectory(Path.GetDirectoryName(fullPath)); + MiniExcel.SaveAs(fullPath, list, overwriteFile: true); } - MiniExcel.SaveAs(newFileName, list); - return sFileName; + return (sFileName, fullPath); } /// diff --git a/ZR.Admin.WebApi/Controllers/System/CodeGeneratorController.cs b/ZR.Admin.WebApi/Controllers/System/CodeGeneratorController.cs index 2ae41e22..92187a78 100644 --- a/ZR.Admin.WebApi/Controllers/System/CodeGeneratorController.cs +++ b/ZR.Admin.WebApi/Controllers/System/CodeGeneratorController.cs @@ -280,7 +280,7 @@ namespace ZR.Admin.WebApi.Controllers CodeGeneratorTool.Generate(dto); if (genTableInfo.Options.GenerateMenu) { - SysMenuService.AddSysMenu(genTableInfo, dto.ReplaceDto.PermissionPrefix, dto.ReplaceDto.ShowBtnEdit, dto.ReplaceDto.ShowBtnExport); + SysMenuService.AddSysMenu(genTableInfo, dto.ReplaceDto.PermissionPrefix, dto.ReplaceDto.ShowBtnEdit, dto.ReplaceDto.ShowBtnExport, dto.ReplaceDto.ShowBtnImport); } foreach (var item in dto.GenCodes) diff --git a/ZR.Admin.WebApi/GlobalUsing.cs b/ZR.Admin.WebApi/GlobalUsing.cs new file mode 100644 index 00000000..4d4888ff --- /dev/null +++ b/ZR.Admin.WebApi/GlobalUsing.cs @@ -0,0 +1,7 @@ +global using ZR.Common; +global using Microsoft.AspNetCore.Authorization; +global using Infrastructure; +global using Infrastructure.Attribute; +global using Infrastructure.Enums; +global using Infrastructure.Model; +global using Mapster; \ No newline at end of file diff --git a/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/TplControllers.txt b/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/TplControllers.txt index 3727ab99..34b8aba6 100644 --- a/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/TplControllers.txt +++ b/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/TplControllers.txt @@ -1,15 +1,12 @@ -using Infrastructure; -using Infrastructure.Attribute; -using Infrastructure.Enums; -using Infrastructure.Model; -using Mapster; using Microsoft.AspNetCore.Mvc; using ${options.DtosNamespace}; using ${options.ModelsNamespace}.${options.SubNamespace}; using ${options.IServicsNamespace}.${options.SubNamespace}.I${options.SubNamespace}Service; using ${options.ApiControllerNamespace}.Extensions; using ${options.ApiControllerNamespace}.Filters; -using ${options.BaseNamespace}Common; +$if(replaceDto.ShowBtnImport) +using MiniExcelLibs; +$end //创建时间:${replaceDto.AddTime} namespace ${options.ApiControllerNamespace}.Controllers @@ -168,6 +165,40 @@ $if(replaceDto.ShowBtnTruncate) } $end +$if(replaceDto.ShowBtnImport) + /// + /// 导入 + /// + /// + /// + [HttpPost("importData")] + [Log(Title = "${genTable.FunctionName}导入", BusinessType = BusinessType.IMPORT, IsSaveRequestData = false, IsSaveResponseData = true)] + [ActionPermissionFilter(Permission = "${replaceDto.PermissionPrefix}:import")] + public IActionResult ImportData([FromForm(Name = "file")] IFormFile formFile) + { + List<${replaceDto.ModelTypeName}> list = new(); + using (var stream = formFile.OpenReadStream()) + { + list = stream.Query<${replaceDto.ModelTypeName}>(startCell: "A1").ToList(); + } + + return SUCCESS(_${replaceDto.ModelTypeName}Service.Import${replaceDto.ModelTypeName}(list)); + } + + /// + /// ${genTable.FunctionName}导入模板下载 + /// + /// + [HttpGet("importTemplate")] + [Log(Title = "${genTable.FunctionName}模板", BusinessType = BusinessType.EXPORT, IsSaveRequestData = true, IsSaveResponseData = false)] + [AllowAnonymous] + public IActionResult ImportTemplateExcel() + { + var result = DownloadImportTemplate(new List<${replaceDto.ModelTypeName}>() { }, "${replaceDto.ModelTypeName}"); + return ExportExcel(result.Item2, result.Item1); + } +$end + $if(showCustomInput) /// /// 保存排序 diff --git a/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/TplIService.txt b/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/TplIService.txt index 9e4cc3d1..b2ae84b0 100644 --- a/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/TplIService.txt +++ b/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/TplIService.txt @@ -24,5 +24,9 @@ $end $if(replaceDto.ShowBtnTruncate) bool Truncate${replaceDto.ModelTypeName}(); $end + +$if(replaceDto.ShowBtnImport) + (string, object, object) Import${replaceDto.ModelTypeName}(List<${replaceDto.ModelTypeName}> list); +$end } } diff --git a/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/TplService.txt b/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/TplService.txt index 9a26f934..66c559ef 100644 --- a/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/TplService.txt +++ b/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/TplService.txt @@ -159,5 +159,40 @@ $if(replaceDto.ShowBtnTruncate) return Truncate(); } $end + +$if(replaceDto.ShowBtnImport) + /// + /// 导入${genTable.FunctionName} + /// + /// + public (string, object, object) Import${replaceDto.ModelTypeName}(List<${replaceDto.ModelTypeName}> list) + { + var x = Context.Storageable(list) + .SplitInsert(it => !it.Any()) +$foreach(column in genTable.Columns) +$if(column.IsRequired && column.IsIncrement == false) + .SplitError(x => x.Item.${column.CsharpField}.IsEmpty(), "${column.ColumnComment}不能为空") +$end +$end + //.WhereColumns(it => it.UserName)//如果不是主键可以这样实现(多字段it=>new{it.x1,it.x2}) + .ToStorage(); + var result = x.AsInsertable.ExecuteCommand();//插入可插入部分; + + string msg = $"插入{x.InsertList.Count} 更新{x.UpdateList.Count} 错误数据{x.ErrorList.Count} 不计算数据{x.IgnoreList.Count} 删除数据{x.DeleteList.Count} 总共{x.TotalList.Count}"; + Console.WriteLine(msg); + + //输出错误信息 + foreach (var item in x.ErrorList) + { + Console.WriteLine("错误" + item.StorageMessage); + } + foreach (var item in x.IgnoreList) + { + Console.WriteLine("忽略" + item.StorageMessage); + } + + return (msg, x.ErrorList, x.IgnoreList); + } +$end } } \ No newline at end of file diff --git a/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/v3/Vue.txt b/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/v3/Vue.txt index a126b9ce..96eda459 100644 --- a/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/v3/Vue.txt +++ b/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/v3/Vue.txt @@ -108,6 +108,25 @@ $if(replaceDto.ShowBtnTruncate) $end +$if(replaceDto.ShowBtnImport) + + + + {{ ${t}t('btn.import') }} + + + + +$end $if(replaceDto.ShowBtnExport) @@ -136,7 +155,7 @@ $end $if(sub) $end @@ -194,7 +213,7 @@ $end $else $if(replaceDto.ShowBtnView) - + $end $if(replaceDto.ShowBtnEdit) @@ -426,7 +445,9 @@ from '@/api/${tool.FirstLowerCase(genTable.ModuleName)}/${genTable.BusinessName. $if(replaceDto.ShowEditor == 1) import Editor from '@/components/Editor' $end - +$if(replaceDto.ShowBtnImport) +import importData from '@/components/ImportData' +$end const { proxy } = getCurrentInstance() const ids = ref([]) const loading = ref(false) @@ -746,6 +767,20 @@ function handlePreview(row) { } $end +$if(replaceDto.ShowBtnImport) +// 导入数据成功处理 +const handleFileSuccess = (response) => { + const { item1, item2 } = response.data + var error = '' + item2.forEach((item) => { + error += item.storageMessage + ',' + }) + proxy.${alert}alert(item1 + '

' + error + '

', '导入结果', { + dangerouslyUseHTMLString: true + }) +} +$end + $if(replaceDto.ShowBtnExport) // 导出按钮操作 function handleExport() { diff --git a/ZR.CodeGenerator/CodeGeneratorTool.cs b/ZR.CodeGenerator/CodeGeneratorTool.cs index 0495e04e..c4d1947e 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), + ShowBtnImport = dto.GenTable.Options.CheckedBtn.Any(f => f == 8), ViewFileName = dto.GenTable.BusinessName.FirstUpperCase(), OperBtnStyle = dto.GenTable.Options.OperBtnStyle }; @@ -586,6 +587,7 @@ namespace ZR.CodeGenerator options.Data.Set("refs", "$");//特殊标签替换 options.Data.Set("t", "$");//特殊标签替换 options.Data.Set("modal", "$");//特殊标签替换 + options.Data.Set("alert", "$");//特殊标签替换 options.Data.Set("index", "$");//特殊标签替换 options.Data.Set("confirm", "$");//特殊标签替换 options.Data.Set("nextTick", "$"); diff --git a/ZR.CodeGenerator/Model/ReplaceDto.cs b/ZR.CodeGenerator/Model/ReplaceDto.cs index e2f974e4..3719e491 100644 --- a/ZR.CodeGenerator/Model/ReplaceDto.cs +++ b/ZR.CodeGenerator/Model/ReplaceDto.cs @@ -50,6 +50,7 @@ namespace ZR.CodeGenerator.Model public bool ShowBtnView { get; set; } public bool ShowBtnTruncate { get; set; } public bool ShowBtnMultiDel { get; set; } + public bool ShowBtnImport { get; set; } /// /// 上传URL data /// diff --git a/ZR.Service/GlobalUsing.cs b/ZR.Service/GlobalUsing.cs new file mode 100644 index 00000000..57439d9e --- /dev/null +++ b/ZR.Service/GlobalUsing.cs @@ -0,0 +1 @@ +global using System.Collections.Generic; \ No newline at end of file diff --git a/ZR.Service/System/IService/ISysMenuService.cs b/ZR.Service/System/IService/ISysMenuService.cs index 29bd0219..5896af80 100644 --- a/ZR.Service/System/IService/ISysMenuService.cs +++ b/ZR.Service/System/IService/ISysMenuService.cs @@ -39,7 +39,7 @@ namespace ZR.Service.System.IService List BuildMenuTreeSelect(List menus); - void AddSysMenu(GenTable genTableInfo, string permPrefix, bool showEdit, bool showExport); + void AddSysMenu(GenTable genTableInfo, string permPrefix, bool showEdit, bool showExport, bool showImport); List SelectTreeMenuListByRoles(MenuQueryDto menu, List roles); List SelectRoleMenuListByRole(MenuQueryDto menu, int roleId); } diff --git a/ZR.Service/System/SysMenuService.cs b/ZR.Service/System/SysMenuService.cs index 2e625764..fbf84c2d 100644 --- a/ZR.Service/System/SysMenuService.cs +++ b/ZR.Service/System/SysMenuService.cs @@ -588,7 +588,7 @@ namespace ZR.Service #endregion - public void AddSysMenu(GenTable genTableInfo, string permPrefix, bool showEdit, bool showExport) + public void AddSysMenu(GenTable genTableInfo, string permPrefix, bool showEdit, bool showExport, bool showImport) { var menu = GetFirst(f => f.MenuName == genTableInfo.FunctionName); if (menu is null) @@ -671,6 +671,18 @@ namespace ZR.Service Icon = "", }; + SysMenu menuImport = new() + { + MenuName = "导入", + ParentId = menu.MenuId, + OrderNum = 5, + Perms = $"{permPrefix}:import", + MenuType = "F", + Visible = "0", + Status = "0", + Icon = "", + }; + menuList.Add(menuQuery); menuList.Add(menuAdd); menuList.Add(menuDel); @@ -682,6 +694,10 @@ namespace ZR.Service { menuList.Add(menuExport); } + if (showImport) + { + menuList.Add(menuImport); + } //Insert(menuList); var x = Storageable(menuList) From 84fb0a0934fb4420bb3776a48ce004c7e320f4f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=8D=E5=81=9A=E7=A0=81=E5=86=9C?= <599854767@qq.com> Date: Mon, 31 Jul 2023 17:28:06 +0800 Subject: [PATCH 05/20] =?UTF-8?q?:sparkles:=E6=96=B0=E5=A2=9EsqlDiffLog?= =?UTF-8?q?=E5=BB=BA=E8=A1=A8=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- document/mysql/admin-mysql.sql | 20 ++++++++++++ .../admin-sqlserver-表字段说明导入.sql | 31 +++++++++++++++++++ document/sqlserver/admin-sqlserver.sql | 21 +++++++++++-- 3 files changed, 70 insertions(+), 2 deletions(-) diff --git a/document/mysql/admin-mysql.sql b/document/mysql/admin-mysql.sql index 5b60a344..d5812740 100644 --- a/document/mysql/admin-mysql.sql +++ b/document/mysql/admin-mysql.sql @@ -511,3 +511,23 @@ CREATE TABLE `sys_common_lang` ( `addtime` datetime(0) NULL DEFAULT NULL COMMENT '添加时间', PRIMARY KEY (`Id`) USING BTREE ) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic; + + + +-- ---------------------------- +-- Table structure for SqlDiffLog +-- ---------------------------- +DROP TABLE IF EXISTS `SqlDiffLog`; +CREATE TABLE `SqlDiffLog` ( + `PId` bigint(20) NOT NULL COMMENT '主键', + `TableName` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '表名', + `BusinessData` varchar(4000) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '业务数据内容', + `DiffType` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '差异类型insert,update,delete', + `Sql` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL COMMENT '执行sql语句', + `BeforeData` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL COMMENT '变更前数据', + `AfterData` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL COMMENT '变更后数据', + `UserName` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '操作用户名', + `AddTime` datetime NULL DEFAULT NULL, + `ConfigId` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '数据库配置id', + PRIMARY KEY (`PId`) USING BTREE +) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '数据差异日志' ROW_FORMAT = Dynamic; diff --git a/document/sqlserver/admin-sqlserver-表字段说明导入.sql b/document/sqlserver/admin-sqlserver-表字段说明导入.sql index 83f73966..44a40514 100644 --- a/document/sqlserver/admin-sqlserver-表字段说明导入.sql +++ b/document/sqlserver/admin-sqlserver-表字段说明导入.sql @@ -650,3 +650,34 @@ EXEC sp_addextendedproperty 'TABLE', N'gen_demo', 'COLUMN', N'remark' GO + + +EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'主键' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'SqlDiffLog', @level2type=N'COLUMN',@level2name=N'PId' +GO + +EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'表名' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'SqlDiffLog', @level2type=N'COLUMN',@level2name=N'TableName' +GO + +EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'业务数据内容' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'SqlDiffLog', @level2type=N'COLUMN',@level2name=N'BusinessData' +GO + +EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'差异类型insert,update,delete' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'SqlDiffLog', @level2type=N'COLUMN',@level2name=N'DiffType' +GO + +EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'执行sql语句' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'SqlDiffLog', @level2type=N'COLUMN',@level2name=N'Sql' +GO + +EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'变更前数据' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'SqlDiffLog', @level2type=N'COLUMN',@level2name=N'BeforeData' +GO + +EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'变更后数据' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'SqlDiffLog', @level2type=N'COLUMN',@level2name=N'AfterData' +GO + +EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'操作用户名' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'SqlDiffLog', @level2type=N'COLUMN',@level2name=N'UserName' +GO + +EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'数据库配置id' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'SqlDiffLog', @level2type=N'COLUMN',@level2name=N'ConfigId' +GO + +EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'数据差异日志' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'SqlDiffLog' +GO diff --git a/document/sqlserver/admin-sqlserver.sql b/document/sqlserver/admin-sqlserver.sql index d3c984ae..8db47340 100644 --- a/document/sqlserver/admin-sqlserver.sql +++ b/document/sqlserver/admin-sqlserver.sql @@ -486,7 +486,7 @@ CREATE TABLE [dbo].[sys_file]( [storeType] [INT] NULL ) GO -IF OBJECT_ID(N'sys_common_lang',N'U') is not NULL DROP TABLE sys_common_lang +IF OBJECT_ID(N'sys_common_lang',N'U') is not NULL DROP TABLE dbo.sys_common_lang GO CREATE TABLE sys_common_lang ( @@ -496,4 +496,21 @@ CREATE TABLE sys_common_lang lang_name NVARCHAR(2000) NOT NULL, -- addtime DATETIME ) -GO \ No newline at end of file +GO + +GO +IF OBJECT_ID(N'SqlDiffLog',N'U') is not NULL DROP TABLE dbo.SqlDiffLog +GO +CREATE TABLE [dbo].[SqlDiffLog]( + [PId] [BIGINT] NOT NULL PRIMARY KEY, + [TableName] [VARCHAR](255) NULL, + [BusinessData] [VARCHAR](4000) NULL, + [DiffType] [VARCHAR](255) NULL, + [Sql] [NVARCHAR](MAX) NULL, + [BeforeData] [NVARCHAR](MAX) NULL, + [AfterData] [NVARCHAR](MAX) NULL, + [UserName] [VARCHAR](255) NULL, + [AddTime] [DATETIME] NULL, + [ConfigId] [VARCHAR](255) NULL +) +GO From e627ddc60d241fcdec211397e5f5d4aace3f30e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=8D=E5=81=9A=E7=A0=81=E5=86=9C?= <599854767@qq.com> Date: Mon, 31 Jul 2023 18:41:23 +0800 Subject: [PATCH 06/20] =?UTF-8?q?:zap:=E4=BC=98=E5=8C=96=E5=91=BD=E5=90=8D?= =?UTF-8?q?=E7=A9=BA=E9=97=B4=E5=BC=95=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ZR.Admin.WebApi/Controllers/BaseController.cs | 4 +--- ZR.Admin.WebApi/Controllers/CommonController.cs | 7 +------ .../System/ArticleCategoryController.cs | 10 ++-------- .../Controllers/System/ArticleController.cs | 6 +----- .../Controllers/System/CommonLangController.cs | 7 ------- .../Controllers/System/SysConfigController.cs | 7 ------- .../Controllers/System/SysDeptController.cs | 6 +----- .../Controllers/System/SysDictDataController.cs | 5 +---- .../Controllers/System/SysDictTypeController.cs | 7 +------ .../Controllers/System/SysLoginController.cs | 5 +---- .../Controllers/System/SysMenuController.cs | 7 +------ .../Controllers/System/SysNoticeController.cs | 8 +------- .../Controllers/System/SysPostController.cs | 8 +------- .../Controllers/System/SysProfileController.cs | 5 ----- .../Controllers/System/SysRoleController.cs | 17 +++-------------- .../Controllers/System/SysUserController.cs | 4 ---- .../Controllers/System/SysUserRoleController.cs | 4 +--- .../Controllers/System/TasksController.cs | 6 +----- .../System/monitor/SysLogininforController.cs | 7 +------ .../System/monitor/SysOperlogController.cs | 6 +----- 20 files changed, 19 insertions(+), 117 deletions(-) diff --git a/ZR.Admin.WebApi/Controllers/BaseController.cs b/ZR.Admin.WebApi/Controllers/BaseController.cs index 50576ea4..fb72640c 100644 --- a/ZR.Admin.WebApi/Controllers/BaseController.cs +++ b/ZR.Admin.WebApi/Controllers/BaseController.cs @@ -1,6 +1,4 @@ -using Infrastructure; -using Infrastructure.Extensions; -using Infrastructure.Model; +using Infrastructure.Extensions; using Microsoft.AspNetCore.Mvc; using MiniExcelLibs; using Newtonsoft.Json; diff --git a/ZR.Admin.WebApi/Controllers/CommonController.cs b/ZR.Admin.WebApi/Controllers/CommonController.cs index 20590bc6..f664c561 100644 --- a/ZR.Admin.WebApi/Controllers/CommonController.cs +++ b/ZR.Admin.WebApi/Controllers/CommonController.cs @@ -1,14 +1,9 @@ -using Infrastructure; -using Infrastructure.Attribute; -using Infrastructure.Enums; -using Infrastructure.Extensions; -using Infrastructure.Model; +using Infrastructure.Extensions; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Options; using Newtonsoft.Json; using ZR.Admin.WebApi.Extensions; using ZR.Admin.WebApi.Filters; -using ZR.Common; using ZR.Model.System; using ZR.Service.System; using ZR.Service.System.IService; diff --git a/ZR.Admin.WebApi/Controllers/System/ArticleCategoryController.cs b/ZR.Admin.WebApi/Controllers/System/ArticleCategoryController.cs index 75fd1357..77339a02 100644 --- a/ZR.Admin.WebApi/Controllers/System/ArticleCategoryController.cs +++ b/ZR.Admin.WebApi/Controllers/System/ArticleCategoryController.cs @@ -1,15 +1,9 @@ -using Infrastructure; -using Infrastructure.Attribute; -using Infrastructure.Enums; -using Infrastructure.Model; -using Mapster; using Microsoft.AspNetCore.Mvc; -using ZR.Model.Dto; using ZR.Admin.WebApi.Extensions; using ZR.Admin.WebApi.Filters; -using ZR.Common; -using ZR.Service.System.IService; +using ZR.Model.Dto; using ZR.Model.System; +using ZR.Service.System.IService; namespace ZR.Admin.WebApi.Controllers { diff --git a/ZR.Admin.WebApi/Controllers/System/ArticleController.cs b/ZR.Admin.WebApi/Controllers/System/ArticleController.cs index c9a67d13..c71e4acd 100644 --- a/ZR.Admin.WebApi/Controllers/System/ArticleController.cs +++ b/ZR.Admin.WebApi/Controllers/System/ArticleController.cs @@ -1,8 +1,4 @@ -using Infrastructure.Attribute; -using Infrastructure.Enums; -using Mapster; -using Microsoft.AspNetCore.Authorization; -using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc; using SqlSugar; using ZR.Admin.WebApi.Extensions; using ZR.Admin.WebApi.Filters; diff --git a/ZR.Admin.WebApi/Controllers/System/CommonLangController.cs b/ZR.Admin.WebApi/Controllers/System/CommonLangController.cs index eedd9f1c..7e3680de 100644 --- a/ZR.Admin.WebApi/Controllers/System/CommonLangController.cs +++ b/ZR.Admin.WebApi/Controllers/System/CommonLangController.cs @@ -1,13 +1,6 @@ -using Infrastructure; -using Infrastructure.Attribute; -using Infrastructure.Enums; using Infrastructure.Extensions; -using Infrastructure.Model; -using Mapster; -using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using ZR.Admin.WebApi.Filters; -using ZR.Common; using ZR.Model; using ZR.Model.Dto; using ZR.Service.System.IService; diff --git a/ZR.Admin.WebApi/Controllers/System/SysConfigController.cs b/ZR.Admin.WebApi/Controllers/System/SysConfigController.cs index 1d33ee3a..82a3b448 100644 --- a/ZR.Admin.WebApi/Controllers/System/SysConfigController.cs +++ b/ZR.Admin.WebApi/Controllers/System/SysConfigController.cs @@ -1,15 +1,8 @@ -using Infrastructure; -using Infrastructure.Attribute; -using Infrastructure.Enums; using Infrastructure.Extensions; -using Infrastructure.Model; -using Mapster; -using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using SqlSugar; using ZR.Admin.WebApi.Extensions; using ZR.Admin.WebApi.Filters; -using ZR.Common; using ZR.Model.System; using ZR.Model.System.Dto; using ZR.Service.System.IService; diff --git a/ZR.Admin.WebApi/Controllers/System/SysDeptController.cs b/ZR.Admin.WebApi/Controllers/System/SysDeptController.cs index eeeb8ca7..a1e65115 100644 --- a/ZR.Admin.WebApi/Controllers/System/SysDeptController.cs +++ b/ZR.Admin.WebApi/Controllers/System/SysDeptController.cs @@ -1,11 +1,7 @@ -using Infrastructure; -using Infrastructure.Attribute; -using Infrastructure.Enums; -using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc; using System.Collections; using ZR.Admin.WebApi.Extensions; using ZR.Admin.WebApi.Filters; -using ZR.Common; using ZR.Model.System; using ZR.Model.System.Dto; using ZR.Service.System.IService; diff --git a/ZR.Admin.WebApi/Controllers/System/SysDictDataController.cs b/ZR.Admin.WebApi/Controllers/System/SysDictDataController.cs index a3cab525..a1f835fd 100644 --- a/ZR.Admin.WebApi/Controllers/System/SysDictDataController.cs +++ b/ZR.Admin.WebApi/Controllers/System/SysDictDataController.cs @@ -1,7 +1,4 @@ -using Infrastructure.Attribute; -using Infrastructure.Enums; -using Microsoft.AspNetCore.Authorization; -using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc; using ZR.Admin.WebApi.Extensions; using ZR.Admin.WebApi.Filters; using ZR.Model; diff --git a/ZR.Admin.WebApi/Controllers/System/SysDictTypeController.cs b/ZR.Admin.WebApi/Controllers/System/SysDictTypeController.cs index bdfc22f9..543b8e9f 100644 --- a/ZR.Admin.WebApi/Controllers/System/SysDictTypeController.cs +++ b/ZR.Admin.WebApi/Controllers/System/SysDictTypeController.cs @@ -1,11 +1,6 @@ -using Infrastructure.Attribute; -using Infrastructure.Enums; -using Infrastructure.Model; -using Mapster; -using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc; using ZR.Admin.WebApi.Extensions; using ZR.Admin.WebApi.Filters; -using ZR.Common; using ZR.Model; using ZR.Model.System; using ZR.Model.System.Dto; diff --git a/ZR.Admin.WebApi/Controllers/System/SysLoginController.cs b/ZR.Admin.WebApi/Controllers/System/SysLoginController.cs index 87892827..2f160a63 100644 --- a/ZR.Admin.WebApi/Controllers/System/SysLoginController.cs +++ b/ZR.Admin.WebApi/Controllers/System/SysLoginController.cs @@ -1,8 +1,5 @@ -using Infrastructure; -using Infrastructure.Attribute; -using IPTools.Core; +using IPTools.Core; using Lazy.Captcha.Core; -using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Options; using UAParser; diff --git a/ZR.Admin.WebApi/Controllers/System/SysMenuController.cs b/ZR.Admin.WebApi/Controllers/System/SysMenuController.cs index ebfe5380..da54b1b2 100644 --- a/ZR.Admin.WebApi/Controllers/System/SysMenuController.cs +++ b/ZR.Admin.WebApi/Controllers/System/SysMenuController.cs @@ -1,9 +1,4 @@ -using Infrastructure; -using Infrastructure.Attribute; -using Infrastructure.Enums; -using Infrastructure.Model; -using Mapster; -using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc; using ZR.Admin.WebApi.Extensions; using ZR.Admin.WebApi.Filters; using ZR.Model.System; diff --git a/ZR.Admin.WebApi/Controllers/System/SysNoticeController.cs b/ZR.Admin.WebApi/Controllers/System/SysNoticeController.cs index e5a7ec17..c5a5ef04 100644 --- a/ZR.Admin.WebApi/Controllers/System/SysNoticeController.cs +++ b/ZR.Admin.WebApi/Controllers/System/SysNoticeController.cs @@ -1,16 +1,10 @@ -using Infrastructure; -using Infrastructure.Attribute; -using Infrastructure.Constant; -using Infrastructure.Enums; -using Infrastructure.Model; -using Mapster; +using Infrastructure.Constant; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.SignalR; using SqlSugar; using ZR.Admin.WebApi.Extensions; using ZR.Admin.WebApi.Filters; using ZR.Admin.WebApi.Hubs; -using ZR.Common; using ZR.Model; using ZR.Model.System; using ZR.Model.System.Dto; diff --git a/ZR.Admin.WebApi/Controllers/System/SysPostController.cs b/ZR.Admin.WebApi/Controllers/System/SysPostController.cs index b1e9c916..b99d9e99 100644 --- a/ZR.Admin.WebApi/Controllers/System/SysPostController.cs +++ b/ZR.Admin.WebApi/Controllers/System/SysPostController.cs @@ -1,14 +1,8 @@ -using Aliyun.OSS; -using Infrastructure; -using Infrastructure.Attribute; -using Infrastructure.Enums; -using Infrastructure.Extensions; -using Mapster; +using Infrastructure.Extensions; using Microsoft.AspNetCore.Mvc; using SqlSugar; using ZR.Admin.WebApi.Extensions; using ZR.Admin.WebApi.Filters; -using ZR.Common; using ZR.Model; using ZR.Model.System; using ZR.Service.System.IService; diff --git a/ZR.Admin.WebApi/Controllers/System/SysProfileController.cs b/ZR.Admin.WebApi/Controllers/System/SysProfileController.cs index 875538b0..144f2c1b 100644 --- a/ZR.Admin.WebApi/Controllers/System/SysProfileController.cs +++ b/ZR.Admin.WebApi/Controllers/System/SysProfileController.cs @@ -1,8 +1,3 @@ -using Infrastructure; -using Infrastructure.Attribute; -using Infrastructure.Enums; -using Infrastructure.Model; -using Mapster; using Microsoft.AspNetCore.Mvc; using ZR.Admin.WebApi.Extensions; using ZR.Admin.WebApi.Filters; diff --git a/ZR.Admin.WebApi/Controllers/System/SysRoleController.cs b/ZR.Admin.WebApi/Controllers/System/SysRoleController.cs index 10b89d9e..e8fa8bad 100644 --- a/ZR.Admin.WebApi/Controllers/System/SysRoleController.cs +++ b/ZR.Admin.WebApi/Controllers/System/SysRoleController.cs @@ -1,21 +1,10 @@ -using Infrastructure; -using Infrastructure.Attribute; -using Infrastructure.Enums; -using Infrastructure.Model; -using Microsoft.AspNetCore.Mvc; -using ZR.Common; +using Microsoft.AspNetCore.Mvc; +using ZR.Admin.WebApi.Extensions; using ZR.Admin.WebApi.Filters; using ZR.Model; using ZR.Model.System; -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; +using ZR.Service.System.IService; namespace ZR.Admin.WebApi.Controllers.System { diff --git a/ZR.Admin.WebApi/Controllers/System/SysUserController.cs b/ZR.Admin.WebApi/Controllers/System/SysUserController.cs index 0f2e2e3b..e2ad1667 100644 --- a/ZR.Admin.WebApi/Controllers/System/SysUserController.cs +++ b/ZR.Admin.WebApi/Controllers/System/SysUserController.cs @@ -1,7 +1,3 @@ -using Infrastructure.Attribute; -using Infrastructure.Enums; -using Infrastructure.Model; -using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using MiniExcelLibs; using SqlSugar; diff --git a/ZR.Admin.WebApi/Controllers/System/SysUserRoleController.cs b/ZR.Admin.WebApi/Controllers/System/SysUserRoleController.cs index 6a145c8f..90fc836b 100644 --- a/ZR.Admin.WebApi/Controllers/System/SysUserRoleController.cs +++ b/ZR.Admin.WebApi/Controllers/System/SysUserRoleController.cs @@ -1,6 +1,4 @@ -using Infrastructure; -using Infrastructure.Attribute; -using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc; using ZR.Admin.WebApi.Filters; using ZR.Model.System.Dto; using ZR.Service.System.IService; diff --git a/ZR.Admin.WebApi/Controllers/System/TasksController.cs b/ZR.Admin.WebApi/Controllers/System/TasksController.cs index 67a57529..8f8cf736 100644 --- a/ZR.Admin.WebApi/Controllers/System/TasksController.cs +++ b/ZR.Admin.WebApi/Controllers/System/TasksController.cs @@ -1,8 +1,4 @@ -using Infrastructure; -using Infrastructure.Attribute; -using Infrastructure.Enums; -using Infrastructure.Extensions; -using Mapster; +using Infrastructure.Extensions; using Microsoft.AspNetCore.Mvc; using Quartz; using SqlSugar; diff --git a/ZR.Admin.WebApi/Controllers/System/monitor/SysLogininforController.cs b/ZR.Admin.WebApi/Controllers/System/monitor/SysLogininforController.cs index 0b6e61d1..9a935571 100644 --- a/ZR.Admin.WebApi/Controllers/System/monitor/SysLogininforController.cs +++ b/ZR.Admin.WebApi/Controllers/System/monitor/SysLogininforController.cs @@ -1,12 +1,7 @@ -using Infrastructure; -using Infrastructure.Attribute; -using Infrastructure.Enums; -using Infrastructure.Model; -using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc; using SqlSugar; using ZR.Admin.WebApi.Extensions; using ZR.Admin.WebApi.Filters; -using ZR.Common; using ZR.Model; using ZR.Model.System; using ZR.Service.System.IService; diff --git a/ZR.Admin.WebApi/Controllers/System/monitor/SysOperlogController.cs b/ZR.Admin.WebApi/Controllers/System/monitor/SysOperlogController.cs index a374833b..7b608480 100644 --- a/ZR.Admin.WebApi/Controllers/System/monitor/SysOperlogController.cs +++ b/ZR.Admin.WebApi/Controllers/System/monitor/SysOperlogController.cs @@ -1,10 +1,6 @@ -using Infrastructure.Attribute; -using Infrastructure.Enums; -using Infrastructure.Model; -using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc; using ZR.Admin.WebApi.Extensions; using ZR.Admin.WebApi.Filters; -using ZR.Common; using ZR.Model.System.Dto; using ZR.Service.System.IService; From 946f4a6de9cf645db308327d32cd336a56912b1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=8D=E5=81=9A=E7=A0=81=E5=86=9C?= <599854767@qq.com> Date: Mon, 31 Jul 2023 18:42:08 +0800 Subject: [PATCH 07/20] =?UTF-8?q?:bug:fix=E9=83=A8=E9=97=A8=E8=A1=A8?= =?UTF-8?q?=E5=AD=97=E6=AE=B5=E5=B1=9E=E6=80=A7=E6=9B=B4=E6=94=B9=E5=AF=BC?= =?UTF-8?q?=E8=87=B4=E6=B7=BB=E5=8A=A0=E5=A4=B1=E8=B4=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ZR.Model/System/UserConstants.cs | 2 +- ZR.Service/System/SysDeptService.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ZR.Model/System/UserConstants.cs b/ZR.Model/System/UserConstants.cs index a944b6e2..e023591d 100644 --- a/ZR.Model/System/UserConstants.cs +++ b/ZR.Model/System/UserConstants.cs @@ -30,7 +30,7 @@ /// /// 部门正常状态 /// - public static string DEPT_NORMAL = "0"; + public static int DEPT_NORMAL = 0; /// /// 部门停用状态 diff --git a/ZR.Service/System/SysDeptService.cs b/ZR.Service/System/SysDeptService.cs index 78bb0ba7..36693228 100644 --- a/ZR.Service/System/SysDeptService.cs +++ b/ZR.Service/System/SysDeptService.cs @@ -67,7 +67,7 @@ namespace ZR.Service.System { SysDept info = GetFirst(it => it.DeptId == dept.ParentId); //如果父节点不为正常状态,则不允许新增子节点 - if (info != null && !UserConstants.DEPT_NORMAL.Equals(info?.Status)) + if (info != null && UserConstants.DEPT_NORMAL != info?.Status) { throw new CustomException("部门停用,不允许新增"); } From e496d4095ba7ec6ae9d794f457410e2f04866ebc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=8D=E5=81=9A=E7=A0=81=E5=86=9C?= <599854767@qq.com> Date: Wed, 19 Jul 2023 07:29:49 +0800 Subject: [PATCH 08/20] =?UTF-8?q?:sparkles:=E6=96=B0=E5=A2=9E=E5=BE=AE?= =?UTF-8?q?=E4=BF=A1=E5=85=AC=E4=BC=97=E5=8F=B7=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Infrastructure/Helper/DateTimeHelper.cs | 6 + .../Controllers/WxOpenController.cs | 43 +++++++ ZR.Admin.WebApi/appsettings.json | 5 + ZR.Common/Model/WxTokenResult.cs | 13 ++ ZR.Common/WxHelper.cs | 119 ++++++++++++++++++ ZR.Common/WxNoticeHelper.cs | 19 +-- 6 files changed, 191 insertions(+), 14 deletions(-) create mode 100644 ZR.Admin.WebApi/Controllers/WxOpenController.cs create mode 100644 ZR.Common/Model/WxTokenResult.cs create mode 100644 ZR.Common/WxHelper.cs diff --git a/Infrastructure/Helper/DateTimeHelper.cs b/Infrastructure/Helper/DateTimeHelper.cs index 37aa6b98..72076c4d 100644 --- a/Infrastructure/Helper/DateTimeHelper.cs +++ b/Infrastructure/Helper/DateTimeHelper.cs @@ -100,6 +100,12 @@ namespace Infrastructure long unixTime = ((DateTimeOffset)dt).ToUnixTimeMilliseconds(); return unixTime; } + + public static long GetUnixTimeSeconds(DateTime dt) + { + long unixTime = ((DateTimeOffset)dt).ToUnixTimeSeconds(); + return unixTime; + } #endregion #region 获取日期天的最小时间 diff --git a/ZR.Admin.WebApi/Controllers/WxOpenController.cs b/ZR.Admin.WebApi/Controllers/WxOpenController.cs new file mode 100644 index 00000000..2ed49878 --- /dev/null +++ b/ZR.Admin.WebApi/Controllers/WxOpenController.cs @@ -0,0 +1,43 @@ +using Infrastructure.Extensions; +using Microsoft.AspNetCore.Mvc; +using System.Web; + +namespace ZR.Admin.WebApi.Controllers +{ + /// + /// 微信公众号 + /// + [Route("[controller]/[action]")] + [AllowAnonymous] + public class WxOpenController : BaseController + { + private NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger(); + public WxOpenController() { } + + /// + /// 获取签名 + /// + /// + /// + [Log(Title = "获取微信签名")] + [HttpGet] + public IActionResult GetSignature(string url = "") + { + url = HttpUtility.UrlDecode(url); + var appId = AppSettings.App(new string[] { "WxOpen", "AppID" }); + var noncestr = Guid.NewGuid().ToString().Replace("-", ""); + var timestamp = DateTimeHelper.GetUnixTimeSeconds(DateTime.Now); + var ticketResult = WxHelper.GetTicket(); + if (appId.IsEmpty()) return ToResponse(ResultCode.CUSTOM_ERROR, "appId未配置"); + if (ticketResult?.errcode != 0) + { + return ToResponse(ResultCode.CUSTOM_ERROR, "获取配置失败"); + } + + var signature = WxHelper.GetSignature(ticketResult.ticket, timestamp.ToString(), noncestr, url); + + return SUCCESS(new { appId, signature, noncestr, timestamp, url }); + } + + } +} diff --git a/ZR.Admin.WebApi/appsettings.json b/ZR.Admin.WebApi/appsettings.json index 17494bab..2a47d0f6 100644 --- a/ZR.Admin.WebApi/appsettings.json +++ b/ZR.Admin.WebApi/appsettings.json @@ -56,6 +56,11 @@ "CorpSecret": "", "SendUser": "@all" }, + //微信公众号设置 + "WxOpen": { + "AppID": "", + "AppSecret": "" + }, //代码生成配置 "gen": { "autoPre": true, //自动去除表前缀 diff --git a/ZR.Common/Model/WxTokenResult.cs b/ZR.Common/Model/WxTokenResult.cs new file mode 100644 index 00000000..bea1614b --- /dev/null +++ b/ZR.Common/Model/WxTokenResult.cs @@ -0,0 +1,13 @@ +namespace ZR.Common.Model +{ + public class WxTokenResult + { + /// + /// 0、正常 + /// + public int errcode { get; set; } + public string errmsg { get; set; } + public string access_token { get; set; } + public string ticket { get; set; } + } +} diff --git a/ZR.Common/WxHelper.cs b/ZR.Common/WxHelper.cs new file mode 100644 index 00000000..5063c8e2 --- /dev/null +++ b/ZR.Common/WxHelper.cs @@ -0,0 +1,119 @@ +using Infrastructure; +using Infrastructure.Extensions; +using Newtonsoft.Json; +using System; +using System.Security.Cryptography; +using System.Text; +using ZR.Common.Model; + +namespace ZR.Common +{ + public class WxHelper + { + private static readonly string GetTokenUrl = "https://api.weixin.qq.com/cgi-bin/token"; + private static readonly string GetTicketUrl = "https://api.weixin.qq.com/cgi-bin/ticket/getticket"; + private static readonly string AppID = AppSettings.App(new string[] { "WxOpen", "AppID" }); + private static readonly string AppSECRET = AppSettings.App(new string[] { "WxOpen", "AppSecret" }); + + /// + /// 获取访问token + /// + /// + /// {"errcode":0,"errmsg":"ok","access_token":"iCbcfE1OjfRhV0_io-CzqTNC0lnrudeW3oF5rhJKfmINaxLClLa1FoqAY_wEXtodYh_DTnrtAwZfzeb-NRXvwiOoqUTHx3i6QKLYcfBtF8y-xd5mvaeaf3e9mvTAPhmX0lkm1cLTwRLmoa1IwzgQ-QZEZcuIcntWdEMGseVYok3BwCGpC87bt6nNdgnekZdFVRp1uuaxoctDGlXpoQlQsA","expires_in":7200} + /// + private static WxTokenResult GetAccessToken() + { + if (AppID.IsEmpty() || AppSECRET.IsEmpty()) + { + Console.WriteLine("公众号配置错误"); + throw new ArgumentException("公众号配置错误"); + }; + var Ck = "wx_token"; + string getTokenUrl = $"{GetTokenUrl}?grant_type=client_credential&appid={AppID}&secret={AppSECRET}"; + if (CacheHelper.Get(Ck) is WxTokenResult tokenResult) + { + return tokenResult; + } + else + { + string result = HttpHelper.HttpGet(getTokenUrl); + + tokenResult = JsonConvert.DeserializeObject(result); + + if (tokenResult?.errcode == 0) + { + CacheHelper.SetCache(Ck, tokenResult, 110); + } + else + { + Console.WriteLine("GetAccessToken失败,结果=" + result); + throw new Exception("获取AccessToken失败"); + } + } + return tokenResult; + } + + /// + /// 获取ticket + /// + /// + public static WxTokenResult GetTicket() + { + WxTokenResult token = GetAccessToken(); + string ticket = token?.access_token; + var Ck = "wx_ticket"; + string getTokenUrl = $"{GetTicketUrl}?access_token={ticket}&type=jsapi"; + if (CacheHelper.Get(Ck) is WxTokenResult tokenResult) + { + return tokenResult; + } + else + { + string result = HttpHelper.HttpGet(getTokenUrl); + tokenResult = JsonConvert.DeserializeObject(result); + + if (tokenResult?.errcode == 0) + { + CacheHelper.SetCache(Ck, tokenResult, 110); + } + else + { + Console.WriteLine("GetTicket,结果=" + result); + throw new Exception("获取ticket失败"); + } + } + return tokenResult; + } + + /// + /// 返回正确的签名 + /// + /// + /// + /// + /// + /// + public static string GetSignature(string jsapi_ticket, string timestamp, string noncestr, string url = null) + { + if (string.IsNullOrEmpty(jsapi_ticket) || string.IsNullOrEmpty(noncestr) || string.IsNullOrEmpty(timestamp) || string.IsNullOrEmpty(url)) + return null; + + //将字段添加到列表中。 + string[] arr = new[] + { + string.Format("jsapi_ticket={0}",jsapi_ticket), + string.Format("noncestr={0}",noncestr), + string.Format("timestamp={0}",timestamp), + string.Format("url={0}",url) + }; + //字典排序 + Array.Sort(arr); + //使用URL键值对的格式拼接成字符串 + var temp = string.Join("&", arr); + + var sha1Arr = SHA1.HashData(Encoding.UTF8.GetBytes(temp)); + + return BitConverter.ToString(sha1Arr).Replace("-", "").ToLower(); + } + } +} diff --git a/ZR.Common/WxNoticeHelper.cs b/ZR.Common/WxNoticeHelper.cs index 976feb60..a89ab73b 100644 --- a/ZR.Common/WxNoticeHelper.cs +++ b/ZR.Common/WxNoticeHelper.cs @@ -1,6 +1,7 @@ using Infrastructure; using System.Collections.Generic; using System.Text.Json; +using ZR.Common.Model; namespace ZR.Common { @@ -44,7 +45,7 @@ namespace ZR.Common System.Console.WriteLine("请完成企业微信配置"); return (0, "请完成企业微信通知配置"); } - GetTokenResult tokenResult = GetAccessToken(); + WxTokenResult tokenResult = GetAccessToken(); if (tokenResult == null || tokenResult.errcode != 0) { @@ -74,7 +75,7 @@ namespace ZR.Common //返回结果 //{"errcode":0,"errmsg":"ok","invaliduser":""} string msgResult = HttpHelper.HttpPost(msgUrl, postData, "contentType/json"); - GetTokenResult getTokenResult = JsonSerializer.Deserialize(msgResult); + WxTokenResult getTokenResult = JsonSerializer.Deserialize(msgResult); System.Console.WriteLine(msgResult); return (getTokenResult?.errcode == 0 ? 100 : 0, getTokenResult?.errmsg); } @@ -89,12 +90,12 @@ namespace ZR.Common /// /// {"errcode":0,"errmsg":"ok","access_token":"iCbcfE1OjfRhV0_io-CzqTNC0lnrudeW3oF5rhJKfmINaxLClLa1FoqAY_wEXtodYh_DTnrtAwZfzeb-NRXvwiOoqUTHx3i6QKLYcfBtF8y-xd5mvaeaf3e9mvTAPhmX0lkm1cLTwRLmoa1IwzgQ-QZEZcuIcntWdEMGseVYok3BwCGpC87bt6nNdgnekZdFVRp1uuaxoctDGlXpoQlQsA","expires_in":7200} /// - private static GetTokenResult GetAccessToken() + private static WxTokenResult GetAccessToken() { string getTokenUrl = $"{GetTokenUrl}?corpid={CORPID}&corpsecret={CORPSECRET}"; string getTokenResult = HttpHelper.HttpGet(getTokenUrl); System.Console.WriteLine(getTokenResult); - GetTokenResult tokenResult = JsonSerializer.Deserialize(getTokenResult); + WxTokenResult tokenResult = JsonSerializer.Deserialize(getTokenResult); return tokenResult; } @@ -146,15 +147,5 @@ namespace ZR.Common }; return dic; } - - public class GetTokenResult - { - /// - /// 0、正常 - /// - public int errcode { get; set; } - public string errmsg { get; set; } - public string access_token { get; set; } - } } } From 5f063ad9d38580be2c8add3d66b301a4b3b1b699 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=8D=E5=81=9A=E7=A0=81=E5=86=9C?= <599854767@qq.com> Date: Tue, 1 Aug 2023 11:44:34 +0800 Subject: [PATCH 09/20] =?UTF-8?q?:sparkles:=E4=BB=A3=E7=A0=81=E7=94=9F?= =?UTF-8?q?=E6=88=90=E6=96=B0=E5=A2=9Eswitch=E7=BB=84=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/System/SysUserController.cs | 2 +- ZR.Admin.WebApi/wwwroot/CodeGenTemplate/v3/Vue.txt | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/ZR.Admin.WebApi/Controllers/System/SysUserController.cs b/ZR.Admin.WebApi/Controllers/System/SysUserController.cs index e2ad1667..78b8c81b 100644 --- a/ZR.Admin.WebApi/Controllers/System/SysUserController.cs +++ b/ZR.Admin.WebApi/Controllers/System/SysUserController.cs @@ -45,7 +45,7 @@ namespace ZR.Admin.WebApi.Controllers.System { var list = UserService.SelectUserList(user, pager); - return SUCCESS(list, TIME_FORMAT_FULL); + return SUCCESS(list); } /// diff --git a/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/v3/Vue.txt b/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/v3/Vue.txt index 96eda459..88648aaa 100644 --- a/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/v3/Vue.txt +++ b/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/v3/Vue.txt @@ -262,6 +262,7 @@ $set(labelName = column.ColumnComment) $if(column.CsharpType == "int" || column.CsharpType == "long") $set(value = "parseInt(item.dictValue)") $set(number = ".number") + $set(switchType = ":active-value='1' :inactive-value='0'") $end $if(column.IsPK || column.IsIncrement) @@ -353,6 +354,12 @@ $elseif(column.HtmlType == "colorPicker") +$elseif(column.HtmlType == "switch") + + + + + $else @@ -386,6 +393,7 @@ $set(columnName = column.CsharpFieldFl) $if(column.CsharpType == "int" || column.CsharpType == "long") $set(value = "parseInt(item.dictValue)") $set(number = ".number") +$set(switchType = ":active-value='1' :inactive-value='0'") $end $if(column.IsList == true) $if(column.IsPk || column.CsharpField == genTable.SubTableFkName) @@ -413,6 +421,12 @@ $elseif(column.HtmlType == "radio" || column.HtmlType == "selectRadio" || column +$elseif(column.HtmlType == "switch") + +