调整实体代码生成,增加string?
This commit is contained in:
@@ -386,51 +386,39 @@ public class DataBaseService : IDynamicApiController, ITransient
|
||||
sugarClient = _dataBaseManager.ChangeDataBase(link);
|
||||
}
|
||||
|
||||
string CustomFormatName(string s)
|
||||
var entityName = string.Join("", input.TableName.Split('_').Select(a => a.ToPascalCase()));
|
||||
foreach (var item in sugarClient.DbMaintenance.GetTableInfoList().Where(t => t.Name == input.TableName))
|
||||
{
|
||||
var pos = 0;
|
||||
if ((pos = s.IndexOf("_", StringComparison.Ordinal)) > -1)
|
||||
{
|
||||
var separatorStrings = Regex.Split(s, @"_", RegexOptions.Compiled);
|
||||
if (separatorStrings.Length > 2)
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
foreach (var item in separatorStrings)
|
||||
{
|
||||
sb.Append(item.ToUpperCase());
|
||||
}
|
||||
return sb.ToString();
|
||||
}
|
||||
else
|
||||
{
|
||||
var first = s.AsSpan().Slice(0, pos).ToString().ToUpperCase();
|
||||
var second = s.AsSpan().Slice(pos + 1).ToString().ToUpperCase();
|
||||
return $"{first}{second}";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return s.ToUpperCase();
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var item in sugarClient!.DbMaintenance.GetTableInfoList().Where(t => t.Name == input.TableName))
|
||||
{
|
||||
string entityName = CustomFormatName(item.Name);/*实体名首字母大写*/
|
||||
//string entityName = CustomFormatName(item.Name);/*实体名首字母大写*/
|
||||
sugarClient.MappingTables.Add(entityName, item.Name);
|
||||
foreach (var col in sugarClient.DbMaintenance.GetColumnInfosByTableName(item.Name))
|
||||
{
|
||||
//var colName = CustomFormatName(col.DbColumnName);
|
||||
sugarClient.MappingColumns.Add(col.DbColumnName /*类的属性首字母大写*/, col.DbColumnName, entityName);
|
||||
}
|
||||
//foreach (var col in sugarClient.DbMaintenance.GetColumnInfosByTableName(item.Name))
|
||||
//{
|
||||
// //var colName = CustomFormatName(col.DbColumnName);
|
||||
// sugarClient.MappingColumns.Add(col.DbColumnName /*类的属性首字母大写*/, col.DbColumnName, entityName);
|
||||
//}
|
||||
}
|
||||
var prefix = input.TableName.Split('_')[0];
|
||||
Dictionary<string, string> nsMapper = new()
|
||||
{
|
||||
{"bas", "Tnb.BasicData.Entities" },
|
||||
{"prd", "Tnb.ProductionMgr.Entities" },
|
||||
{"wms", "Tnb.WarehouseMgr.Entities" },
|
||||
{"eqp", "Tnb.EquipMgr.Entities" },
|
||||
{"tool", "Tnb.EquipMgr.Entities" },
|
||||
{"qc", "Tnb.QcMgr.Entities" },
|
||||
};
|
||||
sugarClient.DbFirst.Where(input.TableName)
|
||||
.FormatFileName(CustomFormatName)
|
||||
.SettingConstructorTemplate(a =>
|
||||
{
|
||||
return a;
|
||||
})
|
||||
//.IsCreateDefaultValue(true)
|
||||
.IsCreateAttribute()
|
||||
.CreateClassFile(dir, "DbModels");
|
||||
.StringNullable()
|
||||
.CreateClassFile(dir, nsMapper.ContainsKey(prefix) ? nsMapper[prefix] : "Tnb.Entities");
|
||||
|
||||
var previewContent = "";
|
||||
var codeFile = Path.Combine(dir, $"{CustomFormatName(input.TableName)}.cs");
|
||||
var codeFile = Path.Combine(dir, $"{entityName}.cs");
|
||||
if (File.Exists(codeFile))
|
||||
{
|
||||
using (var sr = File.OpenText(codeFile))
|
||||
|
||||
Reference in New Issue
Block a user