From a5a3b2d19d0294e0069b5b6d96529f714fecbf16 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, 16 Sep 2022 08:20:09 +0800 Subject: [PATCH] =?UTF-8?q?feat=EF=BC=9A=E6=96=B0=E5=A2=9E=E8=87=AA?= =?UTF-8?q?=E5=AE=9A=E4=B9=89=E5=AD=97=E5=85=B8=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../System/SysDictDataController.cs | 4 +++ ZR.Model/System/Dto/SysDictTypeDto.cs | 28 +++++++++++++++++++ ZR.Model/System/SysDictData.cs | 9 ++---- ZR.Model/System/SysDictType.cs | 6 +++- ZR.Repository/System/SysDictDataRepository.cs | 10 +++++++ ZR.Service/System/IService/ISysDictService.cs | 2 ++ ZR.Service/System/SysDictService.cs | 17 +++++++++++ document/admin-mysql.sql | 1 + document/admin-sqlserver.sql | 1 + 9 files changed, 70 insertions(+), 8 deletions(-) create mode 100644 ZR.Model/System/Dto/SysDictTypeDto.cs diff --git a/ZR.Admin.WebApi/Controllers/System/SysDictDataController.cs b/ZR.Admin.WebApi/Controllers/System/SysDictDataController.cs index 70a163a..dd2a45a 100644 --- a/ZR.Admin.WebApi/Controllers/System/SysDictDataController.cs +++ b/ZR.Admin.WebApi/Controllers/System/SysDictDataController.cs @@ -73,6 +73,10 @@ namespace ZR.Admin.WebApi.Controllers.System ColumnName = dic.ColumnName, List = list.FindAll(f => f.DictType == dic.DictType) }; + if (dic.DictType.StartsWith("cus_")) + { + vo.List = SysDictService.SelectDictDataByCustomSql(dic.DictType); + } dataVos.Add(vo); } return SUCCESS(dataVos); diff --git a/ZR.Model/System/Dto/SysDictTypeDto.cs b/ZR.Model/System/Dto/SysDictTypeDto.cs new file mode 100644 index 0000000..4a39430 --- /dev/null +++ b/ZR.Model/System/Dto/SysDictTypeDto.cs @@ -0,0 +1,28 @@ +using System.ComponentModel.DataAnnotations; + +namespace ZR.Model.System.Dto +{ + public class SysDictTypeDto + { + public long DictId { get; set; } + /// + /// 字典名称 + /// + public string DictName { get; set; } + /// + /// 字典类型 + /// + [Required(ErrorMessage = "字典类型不能为空")] + [RegularExpression(pattern: "^[a-z][a-z0-9_]*$", ErrorMessage = "字典类型必须以字母开头,且字典类型只能由小写字母或加下划线还有数字组成")] + public string DictType { get; set; } + public string Status { get; set; } + /// + /// 系统内置 Y是 N否 + /// + public string Type { get; set; } + /// + /// 自定义sql + /// + public string CustomSql { get; set; } + } +} diff --git a/ZR.Model/System/SysDictData.cs b/ZR.Model/System/SysDictData.cs index 3451084..a2baabc 100644 --- a/ZR.Model/System/SysDictData.cs +++ b/ZR.Model/System/SysDictData.cs @@ -1,8 +1,4 @@ -//using Dapper.Contrib.Extensions; -using System; -using System.Collections.Generic; -using System.Text; -using SqlSugar; +using SqlSugar; namespace ZR.Model.System { @@ -13,11 +9,10 @@ namespace ZR.Model.System [SugarTable("sys_dict_data")] public class SysDictData: SysBase { - //[Key] /// /// 字典主键 /// - [SugarColumn(IsPrimaryKey = true, IsIdentity = true)]//主键并且自增 (string不能设置自增) + [SugarColumn(IsPrimaryKey = true, IsIdentity = true)] public long DictCode{ get; set; } public int DictSort { get; set; } public string DictLabel { get; set; } diff --git a/ZR.Model/System/SysDictType.cs b/ZR.Model/System/SysDictType.cs index 744f0a4..5e54970 100644 --- a/ZR.Model/System/SysDictType.cs +++ b/ZR.Model/System/SysDictType.cs @@ -13,7 +13,7 @@ namespace ZR.Model.System /// /// 字典主键 /// - [SugarColumn(IsPrimaryKey = true, IsIdentity = true)]//主键并且自增 (string不能设置自增) + [SugarColumn(IsPrimaryKey = true, IsIdentity = true)] public long DictId { get; set; } /// /// 字典名称 @@ -32,5 +32,9 @@ namespace ZR.Model.System /// 系统内置 Y是 N否 /// public string Type { get; set; } + /// + /// 自定义sql + /// + public string CustomSql { get; set; } } } diff --git a/ZR.Repository/System/SysDictDataRepository.cs b/ZR.Repository/System/SysDictDataRepository.cs index 294e655..c15ca6a 100644 --- a/ZR.Repository/System/SysDictDataRepository.cs +++ b/ZR.Repository/System/SysDictDataRepository.cs @@ -110,5 +110,15 @@ namespace ZR.Repository.System .Where(f => f.DictType == old_dictType) .ExecuteCommand(); } + + /// + /// 根据字典类型查询自定义sql + /// + /// + /// + public List SelectDictDataByCustomSql(SysDictType sysDictType) + { + return Context.Ado.SqlQuery(sysDictType?.CustomSql).ToList(); + } } } diff --git a/ZR.Service/System/IService/ISysDictService.cs b/ZR.Service/System/IService/ISysDictService.cs index 7e4313f..331d5f7 100644 --- a/ZR.Service/System/IService/ISysDictService.cs +++ b/ZR.Service/System/IService/ISysDictService.cs @@ -47,5 +47,7 @@ namespace ZR.Service.System.IService /// /// SysDictType GetInfo(long dictId); + + List SelectDictDataByCustomSql(string dictType); } } diff --git a/ZR.Service/System/SysDictService.cs b/ZR.Service/System/SysDictService.cs index 0df06e5..8a668f9 100644 --- a/ZR.Service/System/SysDictService.cs +++ b/ZR.Service/System/SysDictService.cs @@ -1,5 +1,6 @@ using Infrastructure; using Infrastructure.Attribute; +using System; using System.Collections.Generic; using System.Text; using ZR.Model; @@ -111,5 +112,21 @@ namespace ZR.Service.System { return DictRepository.GetFirst(f => f.DictId == dictId); } + + /// + /// 根据字典类型查询自定义sql + /// + /// + /// + public List SelectDictDataByCustomSql(string dictType) + { + var dictInfo = DictRepository.Queryable() + .Where(f => f.DictType == dictType).First(); + if (dictInfo == null || !dictInfo.CustomSql.StartsWith("select", StringComparison.OrdinalIgnoreCase)) + { + return null; + } + return DictDataRepository.SelectDictDataByCustomSql(dictInfo); + } } } diff --git a/document/admin-mysql.sql b/document/admin-mysql.sql index 098f5bf..322592c 100644 --- a/document/admin-mysql.sql +++ b/document/admin-mysql.sql @@ -181,6 +181,7 @@ CREATE TABLE `sys_dict_type` ( `update_by` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT '' COMMENT '更新者', `update_time` datetime(0) NULL DEFAULT NULL COMMENT '更新时间', `remark` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '备注', + `customSql` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '自定义sql语句', PRIMARY KEY (`dictId`) USING BTREE, UNIQUE INDEX `dictType`(`dictType`) USING BTREE ) ENGINE = InnoDB AUTO_INCREMENT = 12 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '字典类型表' ROW_FORMAT = Dynamic; diff --git a/document/admin-sqlserver.sql b/document/admin-sqlserver.sql index 35a56db..c3e6ac6 100644 --- a/document/admin-sqlserver.sql +++ b/document/admin-sqlserver.sql @@ -107,6 +107,7 @@ CREATE TABLE sys_dict_type ( update_by varchar(64) NULL DEFAULT '' ,-- '更新者', update_time datetime NULL DEFAULT NULL ,-- '更新时间', remark varchar(500) NULL DEFAULT NULL ,-- '备注', + customSql varchar(500) NULL DEFAULT NULL ,-- '自定义sql', ) GO CREATE UNIQUE INDEX dictType ON dbo.sys_dict_type(dictType)