⚡ 代码生成Csharp数据类型改为配置文件
This commit is contained in:
parent
f848aa94ac
commit
2c287f66f3
@ -1,4 +1,5 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Infrastructure
|
||||
@ -80,7 +81,11 @@ namespace Infrastructure
|
||||
|
||||
public class Gen
|
||||
{
|
||||
public string Database { get; set; }
|
||||
public bool AutoPre { get; set; }
|
||||
public string VuePath { get; set; }
|
||||
public string Author { get; set; }
|
||||
public DbConfigs GenDbConfig { get; set; }
|
||||
public CsharpTypeArr CsharpTypeArr { get; set; }
|
||||
}
|
||||
|
||||
public class DbConfigs
|
||||
@ -95,4 +100,15 @@ namespace Infrastructure
|
||||
public bool IsGenerateDb { get; set; }
|
||||
public string DbName { get; set; }
|
||||
}
|
||||
|
||||
public class CsharpTypeArr
|
||||
{
|
||||
public string[] String { get; set; }
|
||||
public string[] Int { get; set; }
|
||||
public string[] Long { get; set; }
|
||||
public string[] DateTime { get; set; }
|
||||
public string[] Float { get; set; }
|
||||
public string[] Decimal { get; set; }
|
||||
public string[] Bool { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@ -62,7 +62,17 @@
|
||||
"autoPre": true, //自动去除表前缀
|
||||
"author": "admin",
|
||||
"tablePrefix": "sys_", //"表前缀(生成类名不会包含表前缀,多个用逗号分隔)",
|
||||
"vuePath": "" //前端代码存储路径eg:D:\Work\ZRAdmin-Vue3
|
||||
"vuePath": "", //前端代码存储路径eg:D:\Work\ZRAdmin-Vue3
|
||||
"csharpTypeArr": {
|
||||
"string": [ "varchar", "nvarchar", "text", "longtext" ],
|
||||
"int": [ "int", "integer", "smallint", "int4", "int8", "int2" ],
|
||||
"long": [ "bigint", "number" ],
|
||||
"float": [ "numeric", "real", "float" ],
|
||||
"decimal": [ "money", "decimal", "smallmoney" ],
|
||||
"dateTime": [ "date", "datetime", "datetime2", "smalldatetime", "timestamp" ],
|
||||
"byte": [ "tinyint" ],
|
||||
"bool": [ "bit" ]
|
||||
}
|
||||
},
|
||||
//邮箱配置信息
|
||||
"MailOptions": {
|
||||
@ -71,7 +81,7 @@
|
||||
//发送人邮箱
|
||||
"FromEmail": "", //eg:xxxx@qq.com
|
||||
//发送人邮箱密码
|
||||
"Password": "123456",
|
||||
"Password": "",
|
||||
//协议
|
||||
"Smtp": "smtp.qq.com",
|
||||
"Port": 587,
|
||||
|
||||
@ -334,23 +334,36 @@ namespace ZR.CodeGenerator
|
||||
/// 获取C# 类型
|
||||
/// </summary>
|
||||
/// <param name="sDatatype"></param>
|
||||
/// <param name="csharpType"></param>
|
||||
/// <returns></returns>
|
||||
public static string GetCSharpDatatype(string sDatatype)
|
||||
public static CSharpDataType GetCSharpDatatype(string sDatatype, CsharpTypeArr csharpType)
|
||||
{
|
||||
sDatatype = sDatatype.ToLower();
|
||||
string sTempDatatype = sDatatype switch
|
||||
if (csharpType.Int.Contains(sDatatype))
|
||||
{
|
||||
"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",
|
||||
"bit" => "bool",
|
||||
"date" or "datetime" or "datetime2" or "smalldatetime" or "timestamp" => "DateTime",
|
||||
"money" or "smallmoney" => "decimal",
|
||||
_ => "string",
|
||||
};
|
||||
return sTempDatatype;
|
||||
return CSharpDataType.@int;
|
||||
}
|
||||
else if (csharpType.Long.Contains(sDatatype))
|
||||
{
|
||||
return CSharpDataType.@long;
|
||||
}
|
||||
else if (csharpType.Float.Contains(sDatatype))
|
||||
{
|
||||
return CSharpDataType.@float;
|
||||
}
|
||||
else if (csharpType.Decimal.Contains(sDatatype))
|
||||
{
|
||||
return CSharpDataType.@decimal;
|
||||
}
|
||||
else if (csharpType.DateTime.Contains(sDatatype))
|
||||
{
|
||||
return CSharpDataType.DateTime;
|
||||
}
|
||||
else if (csharpType.Bool.Contains(sDatatype))
|
||||
{
|
||||
return CSharpDataType.@bool;
|
||||
}
|
||||
return CSharpDataType.@string;
|
||||
}
|
||||
|
||||
#endregion
|
||||
@ -398,10 +411,18 @@ namespace ZR.CodeGenerator
|
||||
/// <param name="seqs"></param>
|
||||
public static List<GenTableColumn> InitGenTableColumn(GenTable genTable, List<DbColumnInfo> dbColumnInfos, List<OracleSeq> seqs = null)
|
||||
{
|
||||
OptionsSetting optionsSetting = new();
|
||||
|
||||
var gen = AppSettings.Get<Gen>("gen");
|
||||
var dbConfigs = AppSettings.Get<List<DbConfigs>>("dbConfigs");
|
||||
var dbConfig = dbConfigs.FirstOrDefault(f => f.IsGenerateDb);
|
||||
optionsSetting.DbConfigs = dbConfigs;
|
||||
optionsSetting.Gen = gen ?? throw new CustomException("代码生成节点配置异常");
|
||||
optionsSetting.Gen.GenDbConfig = dbConfig ?? throw new CustomException("代码生成节点数据配置异常");
|
||||
List<GenTableColumn> genTableColumns = new();
|
||||
foreach (var column in dbColumnInfos)
|
||||
{
|
||||
genTableColumns.Add(InitColumnField(genTable, column, seqs));
|
||||
genTableColumns.Add(InitColumnField(genTable, column, seqs, optionsSetting));
|
||||
}
|
||||
return genTableColumns;
|
||||
}
|
||||
@ -411,12 +432,13 @@ namespace ZR.CodeGenerator
|
||||
/// </summary>
|
||||
/// <param name="genTable"></param>
|
||||
/// <param name="column"></param>
|
||||
/// <param name="optionsSetting"></param>
|
||||
/// <param name="seqs">oracle 序列</param>
|
||||
/// <returns></returns>
|
||||
private static GenTableColumn InitColumnField(GenTable genTable, DbColumnInfo column, List<OracleSeq> seqs)
|
||||
private static GenTableColumn InitColumnField(GenTable genTable, DbColumnInfo column, List<OracleSeq> seqs, OptionsSetting optionsSetting)
|
||||
{
|
||||
var dbConfig = AppSettings.Get<List<DbConfigs>>("dbConfigs").FirstOrDefault(f => f.IsGenerateDb);
|
||||
var dataType = column.DataType;
|
||||
if (dbConfig.DbType == 3)
|
||||
if (optionsSetting.Gen.GenDbConfig.DbType == 3)
|
||||
{
|
||||
dataType = column.OracleDataType;
|
||||
var seqName = $"SEQ_{genTable.TableName}_{column.DbColumnName}";
|
||||
@ -431,7 +453,7 @@ namespace ZR.CodeGenerator
|
||||
ColumnType = dataType,
|
||||
TableId = genTable.TableId,
|
||||
TableName = genTable.TableName,
|
||||
CsharpType = GetCSharpDatatype(dataType),
|
||||
CsharpType = GetCSharpDatatype(dataType, optionsSetting.Gen.CsharpTypeArr).ToString(),
|
||||
CsharpField = column.DbColumnName.ConvertToPascal("_"),
|
||||
IsRequired = !column.IsNullable,
|
||||
IsIncrement = column.IsIdentity,
|
||||
|
||||
@ -28,7 +28,6 @@ namespace ZR.CodeGenerator
|
||||
/// </summary>
|
||||
public static readonly string[] radioFiled = new string[] { "status", "state", "is" };
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 单表(增删改查)
|
||||
/// </summary>
|
||||
@ -69,38 +68,60 @@ namespace ZR.CodeGenerator
|
||||
/// </summary>
|
||||
public static string PARENT_MENU_NAME = "parentMenuName";
|
||||
|
||||
/** 数据库字符串类型 */
|
||||
/// <summary>
|
||||
/// 数据库字符串类型
|
||||
/// </summary>
|
||||
public static string[] COLUMNTYPE_STR = { "char", "varchar", "nvarchar", "varchar2" };
|
||||
|
||||
/** 数据库文本类型 */
|
||||
/// <summary>
|
||||
/// 数据库文本类型
|
||||
/// </summary>
|
||||
public static string[] COLUMNTYPE_TEXT = { "tinytext", "text", "mediumtext", "longtext" };
|
||||
|
||||
/** 数据库时间类型 */
|
||||
/// <summary>
|
||||
/// 数据库时间类型
|
||||
/// </summary>
|
||||
public static string[] COLUMNTYPE_TIME = { "datetime", "time", "date", "timestamp" };
|
||||
|
||||
/** 页面不需要编辑字段 */
|
||||
/// <summary>
|
||||
/// 页面不需要编辑字段
|
||||
/// </summary>
|
||||
public static string[] COLUMNNAME_NOT_EDIT = { "id", "create_by", "create_time", "delFlag" };
|
||||
|
||||
/** 页面不需要显示的列表字段 */
|
||||
/// <summary>
|
||||
/// 页面不需要显示的列表字段
|
||||
/// </summary>
|
||||
public static string[] COLUMNNAME_NOT_LIST = { "create_by", "create_time", "delFlag", "update_by",
|
||||
"update_time" , "password"};
|
||||
|
||||
/** 页面不需要查询字段 */
|
||||
/// <summary>
|
||||
/// 页面不需要查询字段
|
||||
/// </summary>
|
||||
public static string[] COLUMNNAME_NOT_QUERY = { "id", "create_by", "create_time", "delFlag", "update_by",
|
||||
"update_time", "remark" };
|
||||
|
||||
/** Entity基类字段 */
|
||||
/// <summary>
|
||||
/// Entity基类字段
|
||||
/// </summary>
|
||||
public static string[] BASE_ENTITY = { "createBy", "createTime", "updateBy", "updateTime", "remark" };
|
||||
|
||||
/** Tree基类字段 */
|
||||
/// <summary>
|
||||
/// Tree基类字段
|
||||
/// </summary>
|
||||
public static string[] TREE_ENTITY = { "parentName", "parentId", "orderNum", "ancestors", "children" };
|
||||
|
||||
/** 文本框 */
|
||||
/// <summary>
|
||||
/// 文本框
|
||||
/// </summary>
|
||||
public static string HTML_INPUT = "input";
|
||||
/** 数字框 */
|
||||
/// <summary>
|
||||
/// 数字框
|
||||
/// </summary>
|
||||
public static string HTML_INPUT_NUMBER = "inputNumber";
|
||||
|
||||
/** 文本域 */
|
||||
/// <summary>
|
||||
/// 文本域
|
||||
/// </summary>
|
||||
public static string HTML_TEXTAREA = "textarea";
|
||||
|
||||
/** 下拉框 */
|
||||
@ -110,53 +131,56 @@ namespace ZR.CodeGenerator
|
||||
/// </summary>
|
||||
public static string HTML_SELECT_MULTI = "selectMulti";
|
||||
|
||||
/** 单选框 */
|
||||
/// <summary>
|
||||
/// 单选框
|
||||
/// </summary>
|
||||
public static string HTML_RADIO = "radio";
|
||||
|
||||
/** 复选框 */
|
||||
/// <summary>
|
||||
/// 复选框
|
||||
/// </summary>
|
||||
public static string HTML_CHECKBOX = "checkbox";
|
||||
|
||||
/** 日期控件 */
|
||||
/// <summary>
|
||||
/// 日期控件
|
||||
/// </summary>
|
||||
public static string HTML_DATETIME = "datetime";
|
||||
|
||||
/** 图片上传控件 */
|
||||
/// <summary>
|
||||
/// 图片上传控件
|
||||
/// </summary>
|
||||
public static string HTML_IMAGE_UPLOAD = "imageUpload";
|
||||
|
||||
/** 文件上传控件 */
|
||||
/// <summary>
|
||||
/// 文件上传控件
|
||||
/// </summary>
|
||||
public static string HTML_FILE_UPLOAD = "fileUpload";
|
||||
|
||||
/** 富文本控件 */
|
||||
/// <summary>
|
||||
/// 富文本控件
|
||||
/// </summary>
|
||||
public static string HTML_EDITOR = "editor";
|
||||
// 自定义排序
|
||||
public static string HTML_SORT = "sort";
|
||||
/// <summary>
|
||||
/// 自定义输入框
|
||||
/// </summary>
|
||||
public static string HTML_CUSTOM_INPUT = "customInput";
|
||||
//颜色选择器
|
||||
/// <summary>
|
||||
/// 颜色选择器
|
||||
/// </summary>
|
||||
public static string HTML_COLORPICKER = "colorPicker";
|
||||
//switch开关
|
||||
public static string HTML_SWITCH { get; set; }
|
||||
|
||||
/** 字符串类型 */
|
||||
public static string TYPE_STRING = "string";
|
||||
|
||||
/** 整型 */
|
||||
public static string TYPE_INT = "int";
|
||||
|
||||
/** 长整型 */
|
||||
public static string TYPE_LONG = "long";
|
||||
|
||||
/** 浮点型 */
|
||||
public static string TYPE_DOUBLE = "Double";
|
||||
|
||||
/** 时间类型 */
|
||||
public static string TYPE_DATE = "DateTime";
|
||||
|
||||
/** 模糊查询 */
|
||||
/// <summary>
|
||||
/// 模糊查询
|
||||
/// </summary>
|
||||
public static string QUERY_LIKE = "LIKE";
|
||||
|
||||
/** 需要 */
|
||||
/// <summary>
|
||||
/// 需要
|
||||
/// </summary>
|
||||
public static string REQUIRE = "1";
|
||||
/// <summary>
|
||||
/// 时间类型
|
||||
/// </summary>
|
||||
public static string TYPE_DATE = "DateTime";
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user