feat:新增自定义字典功能

This commit is contained in:
不做码农 2022-09-16 08:20:09 +08:00
parent 698409d541
commit a5a3b2d19d
9 changed files with 70 additions and 8 deletions

View File

@ -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);

View File

@ -0,0 +1,28 @@
using System.ComponentModel.DataAnnotations;
namespace ZR.Model.System.Dto
{
public class SysDictTypeDto
{
public long DictId { get; set; }
/// <summary>
/// 字典名称
/// </summary>
public string DictName { get; set; }
/// <summary>
/// 字典类型
/// </summary>
[Required(ErrorMessage = "字典类型不能为空")]
[RegularExpression(pattern: "^[a-z][a-z0-9_]*$", ErrorMessage = ",线")]
public string DictType { get; set; }
public string Status { get; set; }
/// <summary>
/// 系统内置 Y是 N否
/// </summary>
public string Type { get; set; }
/// <summary>
/// 自定义sql
/// </summary>
public string CustomSql { get; set; }
}
}

View File

@ -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]
/// <summary>
/// 字典主键
/// </summary>
[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; }

View File

@ -13,7 +13,7 @@ namespace ZR.Model.System
/// <summary>
/// 字典主键
/// </summary>
[SugarColumn(IsPrimaryKey = true, IsIdentity = true)]//主键并且自增 string不能设置自增
[SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
public long DictId { get; set; }
/// <summary>
/// 字典名称
@ -32,5 +32,9 @@ namespace ZR.Model.System
/// 系统内置 Y是 N否
/// </summary>
public string Type { get; set; }
/// <summary>
/// 自定义sql
/// </summary>
public string CustomSql { get; set; }
}
}

View File

@ -110,5 +110,15 @@ namespace ZR.Repository.System
.Where(f => f.DictType == old_dictType)
.ExecuteCommand();
}
/// <summary>
/// 根据字典类型查询自定义sql
/// </summary>
/// <param name="dictType"></param>
/// <returns></returns>
public List<SysDictData> SelectDictDataByCustomSql(SysDictType sysDictType)
{
return Context.Ado.SqlQuery<SysDictData>(sysDictType?.CustomSql).ToList();
}
}
}

View File

@ -47,5 +47,7 @@ namespace ZR.Service.System.IService
/// <param name="dictId"></param>
/// <returns></returns>
SysDictType GetInfo(long dictId);
List<SysDictData> SelectDictDataByCustomSql(string dictType);
}
}

View File

@ -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);
}
/// <summary>
/// 根据字典类型查询自定义sql
/// </summary>
/// <param name="dictType"></param>
/// <returns></returns>
public List<SysDictData> 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);
}
}
}

View File

@ -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;

View File

@ -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)