开发代码生成自定义配置编辑
This commit is contained in:
@@ -49,6 +49,6 @@ namespace ZR.CodeGenerator
|
||||
/// <summary>
|
||||
/// 要生数据的表,用“,”分割
|
||||
/// </summary>
|
||||
public string TableList { get; set; }
|
||||
//public string TableList { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using ZR.CodeGenerator.CodeGenerator;
|
||||
using ZR.Model.System.Generate;
|
||||
|
||||
namespace ZR.CodeGenerator
|
||||
{
|
||||
@@ -20,11 +21,11 @@ namespace ZR.CodeGenerator
|
||||
/// </summary>
|
||||
/// <param name="dbColumnInfo"></param>
|
||||
/// <returns></returns>
|
||||
public static string GetVueJsMethod(DbColumnInfo dbColumnInfo)
|
||||
public static string GetVueJsMethod(GenTableColumn dbColumnInfo)
|
||||
{
|
||||
string columnName = CodeGeneratorTool.FirstLowerCase(dbColumnInfo.DbColumnName);
|
||||
string columnName = dbColumnInfo.ColumnName;
|
||||
string js = "";
|
||||
if (CodeGeneratorTool.imageFiled.Any(f => columnName.Contains(f)))
|
||||
if (dbColumnInfo.HtmlType.Equals(GenConstants.HTML_IMAGE_UPLOAD))
|
||||
{
|
||||
js += $"handleUpload{columnName}Success(res, file) {{\n";
|
||||
js += $" this.form.{columnName} = URL.createObjectURL(file.raw);\n";
|
||||
@@ -35,21 +36,20 @@ namespace ZR.CodeGenerator
|
||||
}
|
||||
|
||||
//rules
|
||||
public static string GetFormRules(DbColumnInfo dbFieldInfo)
|
||||
public static string GetFormRules(GenTableColumn dbFieldInfo)
|
||||
{
|
||||
string vueViewEditFromRuleContent = "";
|
||||
//Rule 规则验证
|
||||
if (!dbFieldInfo.IsNullable && !dbFieldInfo.IsIdentity)
|
||||
if (!dbFieldInfo.IsPk && !dbFieldInfo.IsIncrement)
|
||||
{
|
||||
vueViewEditFromRuleContent += $" {dbFieldInfo.DbColumnName}: [\n";
|
||||
vueViewEditFromRuleContent += $" {{ required: true, message: '请输入{dbFieldInfo.ColumnDescription}', trigger: \"blur\"}},\n";
|
||||
//vueViewEditFromRuleContent += " { min: 2, max: 50, message: \"长度在 2 到 50 个字符\", trigger:\"blur\" }\n";
|
||||
vueViewEditFromRuleContent += $" {dbFieldInfo.ColumnName}: [\n";
|
||||
vueViewEditFromRuleContent += $" {{ required: true, message: '请输入{dbFieldInfo.ColumnComment}', trigger: \"blur\"}},\n";
|
||||
vueViewEditFromRuleContent += " ],\n";
|
||||
}
|
||||
else if (TableMappingHelper.IsNumber(dbFieldInfo.DataType))
|
||||
else if (TableMappingHelper.IsNumber(dbFieldInfo.ColumnType) && dbFieldInfo.IsRequired)
|
||||
{
|
||||
vueViewEditFromRuleContent += $" {dbFieldInfo.DbColumnName}: [\n";
|
||||
vueViewEditFromRuleContent += $" {{ type: 'number', message: '{dbFieldInfo.DbColumnName}必须为数字值', trigger: \"blur\"}},\n";
|
||||
vueViewEditFromRuleContent += $" {dbFieldInfo.ColumnName}: [\n";
|
||||
vueViewEditFromRuleContent += $" {{ type: 'number', message: '{dbFieldInfo.ColumnName}必须为数字值', trigger: \"blur\"}},\n";
|
||||
vueViewEditFromRuleContent += " ],\n";
|
||||
}
|
||||
|
||||
@@ -57,49 +57,49 @@ namespace ZR.CodeGenerator
|
||||
}
|
||||
|
||||
//model 属性
|
||||
public static string GetModelTemplate(DbColumnInfo dbFieldInfo)
|
||||
public static string GetModelTemplate(GenTableColumn dbFieldInfo)
|
||||
{
|
||||
string columnName = dbFieldInfo.DbColumnName.Substring(0, 1).ToUpper() + dbFieldInfo.DbColumnName[1..];
|
||||
var modelcontent = "";
|
||||
modelcontent += " /// <summary>\n";
|
||||
modelcontent += $" /// 描述 :{dbFieldInfo.ColumnDescription}\n";
|
||||
modelcontent += $" /// 空值 :{dbFieldInfo.IsNullable}\n";
|
||||
modelcontent += $" /// 默认 :{dbFieldInfo.DefaultValue}\n";
|
||||
modelcontent += $" /// 描述 :{dbFieldInfo.ColumnComment}\n";
|
||||
modelcontent += $" /// 空值 :{dbFieldInfo.IsRequired}\n";
|
||||
modelcontent += " /// </summary>\n";
|
||||
if (dbFieldInfo.IsIdentity || dbFieldInfo.IsPrimarykey)
|
||||
if (dbFieldInfo.IsPk || dbFieldInfo.IsIncrement)
|
||||
{
|
||||
modelcontent += $" [SqlSugar.SugarColumn(IsPrimaryKey = {dbFieldInfo.IsPrimarykey.ToString().ToLower()}, IsIdentity = {dbFieldInfo.IsIdentity.ToString().ToLower()})]\n";
|
||||
modelcontent += $" [SqlSugar.SugarColumn(IsPrimaryKey = {dbFieldInfo.IsPk.ToString().ToLower()}, IsIdentity = {dbFieldInfo.IsIncrement.ToString().ToLower()})]\n";
|
||||
}
|
||||
modelcontent += $" public {TableMappingHelper.GetPropertyDatatype(dbFieldInfo.DataType)} {columnName} {{ get; set; }}\n\r";
|
||||
modelcontent += $" public {dbFieldInfo.CsharpType} {dbFieldInfo.CsharpField} {{ get; set; }}\n\r";
|
||||
return modelcontent;
|
||||
}
|
||||
//DTO model
|
||||
public static string GetDtoContent(DbColumnInfo dbFieldInfo)
|
||||
public static string GetDtoContent(GenTableColumn dbFieldInfo)
|
||||
{
|
||||
string columnName = dbFieldInfo.DbColumnName.Substring(0, 1).ToUpper() + dbFieldInfo.DbColumnName[1..];
|
||||
string InputDtoContent = "";
|
||||
InputDtoContent += $" public {TableMappingHelper.GetPropertyDatatype(dbFieldInfo.DataType)} {columnName} {{ get; set; }}\n\r";
|
||||
if (dbFieldInfo.IsInsert || dbFieldInfo.IsEdit)
|
||||
{
|
||||
InputDtoContent += $" public {dbFieldInfo.CsharpType} {dbFieldInfo.CsharpField} {{ get; set; }}\n\r";
|
||||
}
|
||||
|
||||
return InputDtoContent;
|
||||
}
|
||||
|
||||
//form-item
|
||||
public static string GetVueViewFormContent(DbColumnInfo dbFieldInfo)
|
||||
public static string GetVueViewFormContent(GenTableColumn dbFieldInfo)
|
||||
{
|
||||
string columnName = CodeGeneratorTool.FirstLowerCase(dbFieldInfo.DbColumnName);
|
||||
string labelName = CodeGeneratorTool.GetLabelName(dbFieldInfo.ColumnDescription, columnName);
|
||||
string columnName = dbFieldInfo.ColumnName;
|
||||
string labelName = CodeGeneratorTool.GetLabelName(dbFieldInfo.ColumnComment, columnName);
|
||||
string vueViewFromContent = "";
|
||||
string labelDisabled = dbFieldInfo.IsIdentity ? ":disabled=\"true\"" : "";
|
||||
string placeHolder = dbFieldInfo.IsIdentity ? "" : $"请输入{CodeGeneratorTool.GetLabelName(dbFieldInfo.ColumnDescription, columnName)}";
|
||||
string labelDisabled = dbFieldInfo.IsPk ? ":disabled=\"true\"" : "";
|
||||
string placeHolder = dbFieldInfo.IsIncrement ? "" : $"请输入{labelName}";
|
||||
|
||||
if (dbFieldInfo.DataType == "datetime")
|
||||
if (dbFieldInfo.HtmlType == GenConstants.HTML_DATETIME)
|
||||
{
|
||||
//时间
|
||||
vueViewFromContent += $" <el-form-item label=\"{labelName}\" :label-width=\"labelWidth\" prop=\"{columnName}\">\n";
|
||||
vueViewFromContent += $" <el-date-picker v-model=\"form.{columnName}\" type=\"datetime\" placeholder=\"选择日期时间\" default-time=\"12:00:00\"> </el-date-picker>\n";
|
||||
vueViewFromContent += " </el-form-item>\n";
|
||||
}
|
||||
else if (CodeGeneratorTool.imageFiled.Any(f => columnName.Contains(f)))
|
||||
else if (dbFieldInfo.HtmlType == GenConstants.HTML_IMAGE_UPLOAD)
|
||||
{
|
||||
//图片
|
||||
vueViewFromContent += $" <el-form-item label=\"{labelName}\" :label-width=\"labelWidth\" prop=\"{columnName}\">\n";
|
||||
@@ -110,7 +110,7 @@ namespace ZR.CodeGenerator
|
||||
vueViewFromContent += $" <el-input v-model=\"form.{columnName}\" placeholder=\"请上传文件或手动输入文件地址\"></el-input>\n";
|
||||
vueViewFromContent += " </el-form-item>\n";
|
||||
}
|
||||
else if (CodeGeneratorTool.radioFiled.Any(f => columnName.Contains(f)) && (dbFieldInfo.DataType == "bool" || dbFieldInfo.DataType == "tinyint" || dbFieldInfo.DataType == "int"))
|
||||
else if (dbFieldInfo.HtmlType == GenConstants.HTML_RADIO)
|
||||
{
|
||||
vueViewFromContent += $" <el-form-item label=\"{labelName}\" :label-width=\"labelWidth\" prop=\"{columnName}\">\n";
|
||||
vueViewFromContent += $" <el-radio-group v-model=\"form.{columnName}\">\n";
|
||||
@@ -119,10 +119,16 @@ namespace ZR.CodeGenerator
|
||||
vueViewFromContent += " </el-radio-group>\n";
|
||||
vueViewFromContent += " </el-form-item>\n";
|
||||
}
|
||||
else if (dbFieldInfo.HtmlType == GenConstants.HTML_TEXTAREA)
|
||||
{
|
||||
vueViewFromContent += $" <el-form-item label=\"{ labelName}\" :label-width=\"labelWidth\" prop=\"{columnName}\">\n";
|
||||
vueViewFromContent += $" <el-input type=\"textarea\" v-model=\"form.{columnName}\" placeholder=\"请输入内容\"/>\n";
|
||||
vueViewFromContent += " </el-form-item>\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
string inputNumTxt = TableMappingHelper.IsNumber(dbFieldInfo.DataType) ? ".number" : "";
|
||||
vueViewFromContent += $" <el-form-item label=\"{ CodeGeneratorTool.GetLabelName(dbFieldInfo.ColumnDescription, columnName)}\" :label-width=\"labelWidth\" prop=\"{CodeGeneratorTool.FirstLowerCase(columnName)}\">\n";
|
||||
string inputNumTxt = TableMappingHelper.IsNumber(dbFieldInfo.CsharpType) ? ".number" : "";
|
||||
vueViewFromContent += $" <el-form-item label=\"{ labelName}\" :label-width=\"labelWidth\" prop=\"{CodeGeneratorTool.FirstLowerCase(columnName)}\">\n";
|
||||
vueViewFromContent += $" <el-input v-model{inputNumTxt}=\"form.{CodeGeneratorTool.FirstLowerCase(columnName)}\" placeholder=\"{placeHolder}\" {labelDisabled}/>\n";
|
||||
vueViewFromContent += " </el-form-item>\n";
|
||||
}
|
||||
@@ -131,14 +137,18 @@ namespace ZR.CodeGenerator
|
||||
}
|
||||
|
||||
//table-column
|
||||
public static string GetTableColumn(DbColumnInfo dbFieldInfo)
|
||||
public static string GetTableColumn(GenTableColumn dbFieldInfo)
|
||||
{
|
||||
string columnName = CodeGeneratorTool.FirstLowerCase(dbFieldInfo.DbColumnName);
|
||||
string label = CodeGeneratorTool.GetLabelName(dbFieldInfo.ColumnDescription, columnName);
|
||||
string columnName = dbFieldInfo.ColumnName;
|
||||
string label = CodeGeneratorTool.GetLabelName(dbFieldInfo.ColumnComment, columnName);
|
||||
string vueViewListContent = "";
|
||||
string showToolTip = dbFieldInfo.DataType.Contains("varchar") ? ":show-overflow-tooltip=\"true\"" : "";
|
||||
string showToolTip = dbFieldInfo.ColumnType.Contains("varchar") ? ":show-overflow-tooltip=\"true\"" : "";
|
||||
if (!dbFieldInfo.IsQuery)
|
||||
{
|
||||
return vueViewListContent;
|
||||
}
|
||||
|
||||
if (CodeGeneratorTool.imageFiled.Any(f => columnName.ToLower().Contains(f)))
|
||||
if (dbFieldInfo.HtmlType.Equals(GenConstants.HTML_IMAGE_UPLOAD))
|
||||
{
|
||||
vueViewListContent += $" <el-table-column prop=\"{ columnName}\" label=\"图片\">\n";
|
||||
vueViewListContent += " <template slot-scope=\"scope\">\n";
|
||||
@@ -146,19 +156,19 @@ namespace ZR.CodeGenerator
|
||||
vueViewListContent += " </template>\n";
|
||||
vueViewListContent += " </el-table-column>\n";
|
||||
}
|
||||
else if (dbFieldInfo.DataType == "bool" || dbFieldInfo.DataType == "tinyint")
|
||||
{
|
||||
vueViewListContent += $" <el-table-column prop=\"{columnName}\" label=\"{label}\" width=\"120\" >\n";
|
||||
vueViewListContent += " <template slot-scope=\"scope\">\n";
|
||||
vueViewListContent += $" <el-tag :type=\"scope.row.{columnName} === true ? 'success' : 'info'\" disable-transitions >";
|
||||
vueViewListContent += $" {{scope.row.{columnName}===true?'启用':'禁用'}} </el-tag>\n";
|
||||
vueViewListContent += " </template>\n";
|
||||
vueViewListContent += " </el-table-column>\n";
|
||||
}
|
||||
//else if (dbFieldInfo.HtmlType.Equals(GenConstants.HTML_RADIO))
|
||||
//{
|
||||
// vueViewListContent += $" <el-table-column prop=\"{columnName}\" label=\"{label}\" width=\"120\" >\n";
|
||||
// vueViewListContent += " <template slot-scope=\"scope\">\n";
|
||||
// vueViewListContent += $" <el-tag :type=\"scope.row.{columnName} === true ? 'success' : 'info'\" disable-transitions >";
|
||||
// vueViewListContent += $" {{scope.row.{columnName}===true?'启用':'禁用'}} </el-tag>\n";
|
||||
// vueViewListContent += " </template>\n";
|
||||
// vueViewListContent += " </el-table-column>\n";
|
||||
//}
|
||||
else
|
||||
{
|
||||
//table-column
|
||||
vueViewListContent += $" <el-table-column prop=\"{CodeGeneratorTool.FirstLowerCase(columnName)}\" label=\"{CodeGeneratorTool.GetLabelName(dbFieldInfo.ColumnDescription, columnName)}\" align=\"center\" width=\"100\" {showToolTip} />\n";
|
||||
vueViewListContent += $" <el-table-column prop=\"{CodeGeneratorTool.FirstLowerCase(columnName)}\" label=\"{label}\" align=\"center\" width=\"100\" {showToolTip} />\n";
|
||||
}
|
||||
return vueViewListContent;
|
||||
}
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
using SqlSugar;
|
||||
using Infrastructure;
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using ZR.CodeGenerator.Model;
|
||||
using ZR.CodeGenerator.Service;
|
||||
using ZR.Model.System.Generate;
|
||||
|
||||
namespace ZR.CodeGenerator
|
||||
{
|
||||
@@ -33,7 +35,7 @@ namespace ZR.CodeGenerator
|
||||
/// </summary>
|
||||
/// <param name="dbTableInfo"></param>
|
||||
/// <param name="dto"></param>
|
||||
public static void Generate(DbTableInfo dbTableInfo, GenerateDto dto)
|
||||
public static void Generate(GenTable dbTableInfo, GenerateDto dto)
|
||||
{
|
||||
_option.BaseNamespace = "ZR.";
|
||||
//_option.TableList = listTable;
|
||||
@@ -46,9 +48,9 @@ namespace ZR.CodeGenerator
|
||||
_option.ServicesNamespace = _option.BaseNamespace + "Service";
|
||||
_option.ApiControllerNamespace = _option.BaseNamespace + "Admin.WebApi";
|
||||
|
||||
CodeGeneraterService codeGeneraterService = new();
|
||||
List<DbColumnInfo> listField = codeGeneraterService.GetColumnInfo(dto.dbName, dbTableInfo.Name);
|
||||
GenerateSingle(listField, dbTableInfo, dto);
|
||||
//CodeGeneraterService codeGeneraterService = new();
|
||||
//List<DbColumnInfo> listField = codeGeneraterService.GetColumnInfo(dto.dbName, dbTableInfo.TableName);
|
||||
GenerateSingle(dbTableInfo?.Columns, dbTableInfo, dto);
|
||||
|
||||
//GenerateDtoProfile(_option.ModelsNamespace, profileContent, ifExsitedCovered);
|
||||
}
|
||||
@@ -59,9 +61,9 @@ namespace ZR.CodeGenerator
|
||||
/// <param name="listField">表字段集合</param>
|
||||
/// <param name="tableInfo">表信息</param>
|
||||
/// <param name="dto"></param>
|
||||
public static void GenerateSingle(List<DbColumnInfo> listField, DbTableInfo tableInfo, GenerateDto dto)
|
||||
public static void GenerateSingle(List<GenTableColumn> listField, GenTable tableInfo, GenerateDto dto)
|
||||
{
|
||||
var modelTypeName = GetModelClassName(tableInfo.Name);//表名对应C# 实体类名
|
||||
var modelTypeName = tableInfo.ClassName;//表名对应C# 实体类名
|
||||
var primaryKey = "id";//主键
|
||||
|
||||
string keyTypeName = "int";//主键数据类型
|
||||
@@ -77,26 +79,24 @@ namespace ZR.CodeGenerator
|
||||
string vueViewEditFromRuleContent = string.Empty;//Vue数据校验
|
||||
string vueJsMethod = string.Empty;//Vue js自定义方法
|
||||
|
||||
foreach (DbColumnInfo dbFieldInfo in listField)
|
||||
foreach (GenTableColumn dbFieldInfo in listField)
|
||||
{
|
||||
string columnName = FirstLowerCase(dbFieldInfo.DbColumnName);
|
||||
string columnName = dbFieldInfo.ColumnName;
|
||||
|
||||
if (dbFieldInfo.DataType == "bool" || dbFieldInfo.DataType == "tinyint")
|
||||
if (dbFieldInfo.ColumnType == "bool" || dbFieldInfo.ColumnType == "tinyint")
|
||||
{
|
||||
vueViewEditFromContent += $" {columnName}: 'true',\n";
|
||||
//vueViewEditFromBindContent += $" this.form.{columnName} = res.data.{0}+''\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
vueViewEditFromContent += $" {columnName}: undefined,\n";
|
||||
//vueViewEditFromBindContent += $" {columnName}: row.{columnName},\n";
|
||||
}
|
||||
//vueViewSaveBindContent += string.Format(" '{0}':this.editFrom.{0},\n", columnName);
|
||||
//主键
|
||||
if (dbFieldInfo.IsIdentity || dbFieldInfo.IsPrimarykey)
|
||||
if (dbFieldInfo.IsPk || dbFieldInfo.IsIncrement)
|
||||
{
|
||||
primaryKey = columnName.Substring(0, 1).ToUpper() + columnName[1..];
|
||||
keyTypeName = dbFieldInfo.DataType;
|
||||
keyTypeName = dbFieldInfo.CsharpType;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -104,7 +104,6 @@ namespace ZR.CodeGenerator
|
||||
updateColumn += $" {tempColumnName} = parm.{tempColumnName},\n";
|
||||
}
|
||||
|
||||
dbFieldInfo.DbColumnName = columnName;
|
||||
modelContent += CodeGenerateTemplate.GetModelTemplate(dbFieldInfo);
|
||||
vueViewFormContent += CodeGenerateTemplate.GetVueViewFormContent(dbFieldInfo);
|
||||
vueJsMethod += CodeGenerateTemplate.GetVueJsMethod(dbFieldInfo);
|
||||
@@ -117,8 +116,8 @@ namespace ZR.CodeGenerator
|
||||
replaceDto.PrimaryKey = primaryKey;
|
||||
replaceDto.ModelTypeName = modelTypeName;
|
||||
replaceDto.ModelProperty = modelContent;
|
||||
replaceDto.TableName = tableInfo.Name;
|
||||
replaceDto.TableDesc = tableInfo.Description;
|
||||
replaceDto.TableName = tableInfo.TableName;
|
||||
replaceDto.TableDesc = tableInfo.TableComment;
|
||||
replaceDto.InputDtoProperty = InputDtoContent;
|
||||
replaceDto.updateColumn = updateColumn;
|
||||
replaceDto.VueJsMethod = vueJsMethod;
|
||||
@@ -407,19 +406,29 @@ namespace ZR.CodeGenerator
|
||||
|
||||
/// <summary>
|
||||
/// 如果有前缀替换将前缀替换成空,替换下划线"_"为空再将首字母大写
|
||||
/// 表名转换成C#类名
|
||||
/// </summary>
|
||||
/// <param name="modelTypeName"></param>
|
||||
/// <param name="tableName"></param>
|
||||
/// <returns></returns>
|
||||
public static string GetModelClassName(string modelTypeName)
|
||||
public static string GetClassName(string tableName)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(_option.ReplaceTableNameStr))
|
||||
bool autoRemovePre = ConfigUtils.Instance.GetAppConfig("gen:autoPre", false);
|
||||
string tablePrefix = ConfigUtils.Instance.GetAppConfig<string>("gen:tablePrefix");
|
||||
|
||||
if (!string.IsNullOrEmpty(tablePrefix) && autoRemovePre)
|
||||
{
|
||||
modelTypeName = modelTypeName.Replace(_option.ReplaceTableNameStr.ToString(), "");
|
||||
string[] searcList = tablePrefix.Split(",",StringSplitOptions.RemoveEmptyEntries);
|
||||
for (int i = 0; i < searcList.Length; i++)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(searcList[i].ToString()))
|
||||
{
|
||||
tableName = tableName.Replace(searcList[i].ToString(), "");
|
||||
}
|
||||
}
|
||||
}
|
||||
modelTypeName = modelTypeName.Replace("_", "");
|
||||
modelTypeName = modelTypeName.Substring(0, 1).ToUpper() + modelTypeName[1..];
|
||||
return modelTypeName;
|
||||
return tableName.Substring(0, 1).ToUpper() + tableName[1..].Replace("_", "");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 首字母转小写,输出前端
|
||||
/// </summary>
|
||||
|
||||
@@ -19,8 +19,8 @@ namespace ZR.CodeGenerator
|
||||
/// <returns></returns>
|
||||
public SqlSugarScope GetSugarDbContext(string dbName = "")
|
||||
{
|
||||
string connStr = ConfigUtils.Instance.GetConnectionStrings(OptionsSetting.Conn).Replace("{database}", dbName);
|
||||
int dbType = ConfigUtils.Instance.GetAppConfig(OptionsSetting.CodeGenDbType, 0);
|
||||
string connStr = ConfigUtils.Instance.GetConfig(OptionsSetting.Gen_conn).Replace("{database}", dbName);
|
||||
int dbType = ConfigUtils.Instance.GetAppConfig(OptionsSetting.Gen_conn_dbType, 0);
|
||||
if (string.IsNullOrEmpty(dbName))
|
||||
{
|
||||
connStr = ConfigUtils.Instance.GetConnectionStrings(OptionsSetting.ConnAdmin);
|
||||
|
||||
@@ -0,0 +1,119 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ZR.CodeGenerator
|
||||
{
|
||||
/// <summary>
|
||||
/// 代码生成常量
|
||||
/// </summary>
|
||||
public class GenConstants
|
||||
{
|
||||
/** 单表(增删改查) */
|
||||
public static string TPL_CRUD = "crud";
|
||||
|
||||
/** 树表(增删改查) */
|
||||
public static string TPL_TREE = "tree";
|
||||
|
||||
/** 主子表(增删改查) */
|
||||
public static string TPL_SUB = "sub";
|
||||
|
||||
/** 树编码字段 */
|
||||
public static string TREE_CODE = "treeCode";
|
||||
|
||||
/** 树父编码字段 */
|
||||
public static string TREE_PARENT_CODE = "treeParentCode";
|
||||
|
||||
/** 树名称字段 */
|
||||
public static string TREE_NAME = "treeName";
|
||||
|
||||
/** 上级菜单ID字段 */
|
||||
public static string PARENT_MENU_ID = "parentMenuId";
|
||||
|
||||
/** 上级菜单名称字段 */
|
||||
public static string PARENT_MENU_NAME = "parentMenuName";
|
||||
|
||||
/** 数据库字符串类型 */
|
||||
public static string[] COLUMNTYPE_STR = { "char", "varchar", "nvarchar", "varchar2" };
|
||||
|
||||
/** 数据库文本类型 */
|
||||
public static string[] COLUMNTYPE_TEXT = { "tinytext", "text", "mediumtext", "longtext" };
|
||||
|
||||
/** 数据库时间类型 */
|
||||
public static string[] COLUMNTYPE_TIME = { "datetime", "time", "date", "timestamp" };
|
||||
|
||||
/** 数据库数字类型 */
|
||||
public static string[] COLUMNTYPE_NUMBER = { "tinyint", "smallint", "mediumint", "int", "number", "integer",
|
||||
"bit", "bigint", "float", "double", "decimal" };
|
||||
|
||||
/** 页面不需要编辑字段 */
|
||||
public static string[] COLUMNNAME_NOT_EDIT = { "id", "create_by", "create_time", "del_flag" };
|
||||
|
||||
/** 页面不需要显示的列表字段 */
|
||||
public static string[] COLUMNNAME_NOT_LIST = { "id", "create_by", "create_time", "del_flag", "update_by",
|
||||
"update_time" };
|
||||
|
||||
/** 页面不需要查询字段 */
|
||||
public static string[] COLUMNNAME_NOT_QUERY = { "id", "create_by", "create_time", "del_flag", "update_by",
|
||||
"update_time", "remark" };
|
||||
|
||||
/** Entity基类字段 */
|
||||
public static string[] BASE_ENTITY = { "createBy", "createTime", "updateBy", "updateTime", "remark" };
|
||||
|
||||
/** Tree基类字段 */
|
||||
public static string[] TREE_ENTITY = { "parentName", "parentId", "orderNum", "ancestors", "children" };
|
||||
|
||||
/** 文本框 */
|
||||
public static string HTML_INPUT = "input";
|
||||
|
||||
/** 文本域 */
|
||||
public static string HTML_TEXTAREA = "textarea";
|
||||
|
||||
/** 下拉框 */
|
||||
public static string HTML_SELECT = "select";
|
||||
|
||||
/** 单选框 */
|
||||
public static string HTML_RADIO = "radio";
|
||||
|
||||
/** 复选框 */
|
||||
public static string HTML_CHECKBOX = "checkbox";
|
||||
|
||||
/** 日期控件 */
|
||||
public static string HTML_DATETIME = "datetime";
|
||||
|
||||
/** 图片上传控件 */
|
||||
public static string HTML_IMAGE_UPLOAD = "imageUpload";
|
||||
|
||||
/** 文件上传控件 */
|
||||
public static string HTML_FILE_UPLOAD = "fileUpload";
|
||||
|
||||
/** 富文本控件 */
|
||||
public static string HTML_EDITOR = "editor";
|
||||
|
||||
/** 字符串类型 */
|
||||
public static string TYPE_STRING = "string";
|
||||
|
||||
/** 整型 */
|
||||
public static string TYPE_INTEGER = "Integer";
|
||||
|
||||
/** 长整型 */
|
||||
public static string TYPE_LONG = "Long";
|
||||
|
||||
/** 浮点型 */
|
||||
public static string TYPE_DOUBLE = "Double";
|
||||
|
||||
/** 高精度计算类型 */
|
||||
public static string TYPE_BIGDECIMAL = "BigDecimal";
|
||||
|
||||
/** 时间类型 */
|
||||
public static string TYPE_DATE = "Date";
|
||||
|
||||
/** 模糊查询 */
|
||||
public static string QUERY_LIKE = "LIKE";
|
||||
|
||||
/** 需要 */
|
||||
public static string REQUIRE = "1";
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,7 @@ namespace ZR.CodeGenerator.Model
|
||||
{
|
||||
public class GenerateDto
|
||||
{
|
||||
public long TableId { get; set; }
|
||||
public string[] queryColumn { get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
|
||||
@@ -55,45 +55,45 @@ namespace ZR.CodeGenerator.CodeGenerator
|
||||
case "number":
|
||||
case "integer":
|
||||
case "smallint":
|
||||
sTempDatatype = "int?";
|
||||
sTempDatatype = "int";
|
||||
break;
|
||||
|
||||
case "bigint":
|
||||
sTempDatatype = "long?";
|
||||
sTempDatatype = "long";
|
||||
break;
|
||||
|
||||
case "tinyint":
|
||||
sTempDatatype = "byte?";
|
||||
sTempDatatype = "byte";
|
||||
break;
|
||||
|
||||
case "numeric":
|
||||
case "real":
|
||||
sTempDatatype = "Single?";
|
||||
sTempDatatype = "Single";
|
||||
break;
|
||||
|
||||
case "float":
|
||||
sTempDatatype = "float?";
|
||||
sTempDatatype = "float";
|
||||
break;
|
||||
|
||||
case "decimal":
|
||||
case "numer(8,2)":
|
||||
sTempDatatype = "decimal?";
|
||||
sTempDatatype = "decimal";
|
||||
break;
|
||||
|
||||
case "bit":
|
||||
sTempDatatype = "bool?";
|
||||
sTempDatatype = "bool";
|
||||
break;
|
||||
|
||||
case "date":
|
||||
case "datetime":
|
||||
case "datetime2":
|
||||
case "smalldatetime":
|
||||
sTempDatatype = "DateTime?";
|
||||
sTempDatatype = "DateTime";
|
||||
break;
|
||||
|
||||
case "money":
|
||||
case "smallmoney":
|
||||
sTempDatatype = "double?";
|
||||
sTempDatatype = "double";
|
||||
break;
|
||||
|
||||
case "char":
|
||||
@@ -113,7 +113,7 @@ namespace ZR.CodeGenerator.CodeGenerator
|
||||
public static bool IsNumber(string tableDataType)
|
||||
{
|
||||
string[] arr = new string[] { "int", "long" };
|
||||
return arr.Any(f => f.Replace("?", "").Contains(GetPropertyDatatype(tableDataType)));
|
||||
return arr.Any(f => f.Contains(GetPropertyDatatype(tableDataType)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user