This commit is contained in:
2023-05-31 10:19:05 +08:00
parent 1b65a7a9e5
commit 9c621c75cd
238 changed files with 9905 additions and 4034 deletions

View File

@@ -21,6 +21,7 @@ using JNPF.VisualDev.Entitys;
using JNPF.VisualDev.Entitys.Dto.CodeGen;
using JNPF.VisualDev.Entitys.Enum;
using Microsoft.AspNetCore.Mvc;
using NPOI.Util;
using SqlSugar;
using System.IO.Compression;
using System.Text;
@@ -124,7 +125,7 @@ public class CodeGenService : IDynamicApiController, ITransient
var templateEntity = await _repository.GetFirstAsync(v => v.Id == id && v.DeleteMark == null);
_ = templateEntity ?? throw Oops.Oh(ErrorCode.COM1005);
_ = templateEntity.Tables ?? throw Oops.Oh(ErrorCode.D2100);
var model = templateEntity.FormData.ToObject<FormDataModel>();
var model = templateEntity.FormData.ToObjectOld<FormDataModel>();
if (templateEntity.Type == 3)
downloadCodeForm.module = "WorkFlow";
model.className = new List<string>() { downloadCodeForm.className.ParseToPascalCase() };
@@ -186,7 +187,7 @@ public class CodeGenService : IDynamicApiController, ITransient
var templateEntity = await _repository.GetFirstAsync(v => v.Id == id && v.DeleteMark == null);
_ = templateEntity ?? throw Oops.Oh(ErrorCode.COM1005);
_ = templateEntity.Tables ?? throw Oops.Oh(ErrorCode.D2100);
var model = templateEntity.FormData.ToObject<FormDataModel>();
var model = templateEntity.FormData.ToObjectOld<FormDataModel>();
model.className = new List<string>() { downloadCodeForm.className.ParseToPascalCase() };
model.areasName = downloadCodeForm.module;
string fileName = SnowflakeIdHelper.NextId();
@@ -244,7 +245,7 @@ public class CodeGenService : IDynamicApiController, ITransient
List<DbTableRelationModel>? tableRelation = templateEntity.Tables.ToObject<List<DbTableRelationModel>>();
// 表单数据
var formDataModel = templateEntity.FormData.ToObject<FormDataModel>();
var formDataModel = templateEntity.FormData.ToObjectOld<FormDataModel>();
// 列表属性
ColumnDesignModel? pcColumnDesignModel = templateEntity.ColumnData?.ToObject<ColumnDesignModel>();
@@ -283,17 +284,42 @@ public class CodeGenService : IDynamicApiController, ITransient
case 1:
break;
default:
if (pcColumnDesignModel.type == 2 && (pcColumnDesignModel.searchList.Count == 0 || pcColumnDesignModel.searchList.Any(it => !it.prop.Equals(pcColumnDesignModel.treeRelation))))
if (pcColumnDesignModel.type == 2 && (pcColumnDesignModel.searchList.Count == 0 || !pcColumnDesignModel.searchList.Any(it => it.prop.Equals(pcColumnDesignModel.treeRelation))))
{
var search = controls.Find(x => x.__vModel__.Equals(pcColumnDesignModel.treeRelation));
pcColumnDesignModel.searchList.Add(new IndexSearchFieldModel
var search = new FieldsModel();
// 左侧树关联字段是否为子表字段
switch (pcColumnDesignModel.treeRelation.StartsWith("tableField"))
{
label = search.__config__.label,
prop = search.__vModel__,
jnpfKey = search.__config__.jnpfKey,
searchType = 1,
__vModel__ = search.__vModel__
});
case true:
foreach (var item in controls.FindAll(it => it.__config__.jnpfKey.Equals(JnpfKeyConst.TABLE)))
{
search = item.__config__.children.Find(x => x.__vModel__.Equals(pcColumnDesignModel.treeRelation.Replace(string.Format("{0}-", item.__vModel__), "")));
if (search != null)
{
pcColumnDesignModel.searchList.Add(new IndexSearchFieldModel
{
label = search.__config__.label,
prop = string.Format("{0}-{1}", item.__vModel__, search.__vModel__),
jnpfKey = search.__config__.jnpfKey,
searchType = 1,
__vModel__ = string.Format("{0}-{1}", item.__vModel__, search.__vModel__),
});
continue;
}
}
break;
default:
search = controls.Find(x => x.__vModel__.Equals(pcColumnDesignModel.treeRelation));
pcColumnDesignModel.searchList.Add(new IndexSearchFieldModel
{
label = search.__config__.label,
prop = search.__vModel__,
jnpfKey = search.__config__.jnpfKey,
searchType = 1,
__vModel__ = search.__vModel__
});
break;
}
}
// 统一处理下表单内控件
@@ -352,9 +378,10 @@ public class CodeGenService : IDynamicApiController, ITransient
// 默认主表开启自增子表也需要开启自增
if (formDataModel.primaryKeyPolicy == 2 && !fieldList.Any(it => it.primaryKey && it.identity))
{
throw Oops.Oh(ErrorCode.D2109);
}
if (formDataModel.logicalDelete && !fieldList.Any(it => it.field.ToLower().Equals("f_deletemark")))
throw Oops.Oh(ErrorCode.D2110);
// 后端生成
codeGenConfigModel = CodeGenWay.ChildTableBackEnd(item.table, item.className, fieldList, controls, templateEntity, controlId);
@@ -366,8 +393,7 @@ public class CodeGenService : IDynamicApiController, ITransient
for (int i = 0; i < templatePathList.Count; i++)
{
var tContent = File.ReadAllText(templatePathList[i]);
var tResult = _viewEngine.RunCompileFromCached(tContent, new
{
var tResult = _viewEngine.RunCompileFromCached(tContent, new {
BusName = codeGenConfigModel.BusName,
ClassName = codeGenConfigModel.ClassName,
NameSpace = formDataModel.areasName,
@@ -412,6 +438,8 @@ public class CodeGenService : IDynamicApiController, ITransient
IsConversion = codeGenConfigModel.TableField.Any(it => it.IsConversion.Equals(true)),
IsDetailConversion = codeGenConfigModel.TableField.Any(it => it.IsDetailConversion.Equals(true)),
IsImportData = codeGenConfigModel.TableField.Any(it => it.IsImportField.Equals(true)),
IsSearchMultiple = codeGenConfigModel.IsSearchMultiple,
IsControlParsing = codeGenConfigModel.TableField.Any(it => it.IsControlParsing),
});
// 还原全部控件
@@ -427,20 +455,20 @@ public class CodeGenService : IDynamicApiController, ITransient
// 开启乐观锁
if (formDataModel.concurrencyLock && !fieldList.Any(it => it.field.ToLower().Equals("f_version")))
{
throw Oops.Oh(ErrorCode.D2107);
}
if (formDataModel.primaryKeyPolicy == 2 && !fieldList.Any(it => it.primaryKey && it.identity))
{
throw Oops.Oh(ErrorCode.D2109);
}
if (templateEntity.EnableFlow == 1 && !fieldList.Any(it => it.field.ToLower().Equals("f_flowid")))
throw Oops.Oh(ErrorCode.D2105);
// 列表带流程 或者 流程表单 自增ID
if (formDataModel.primaryKeyPolicy == 2 && templateEntity.EnableFlow == 1 && !fieldList.Any(it => it.field.ToLower().Equals("f_flowtaskid")))
{
throw Oops.Oh(ErrorCode.D2108);
}
if (formDataModel.logicalDelete && !fieldList.Any(it => it.field.ToLower().Equals("f_deletemark")))
throw Oops.Oh(ErrorCode.D2110);
// 后端生成
codeGenConfigModel = CodeGenWay.MainBeltBackEnd(item.table, fieldList, controls, templateEntity);
@@ -448,21 +476,9 @@ public class CodeGenService : IDynamicApiController, ITransient
codeGenConfigModel.BusName = item.tableName;
codeGenConfigModel.TableRelations = tableRelationsList;
codeGenConfigModel.IsChildConversion = tableRelationsList.Any(it => it.IsConversion);
switch (codeGenConfigModel.IndexDataType)
switch (templateEntity.WebType)
{
case 4:
switch (templateEntity.Type)
{
case 3:
break;
default:
targetPathList = CodeGenTargetPathHelper.BackendTargetPathList(item.className, fileName, templateEntity.WebType, templateEntity.EnableFlow, codeGenConfigModel.IsInlineEditor, codeGenConfigModel.IsMapper);
templatePathList = CodeGenTargetPathHelper.BackendInlineEditorTemplatePathList("2-MainBelt", templateEntity.WebType, templateEntity.EnableFlow, codeGenConfigModel.IsMapper);
break;
}
break;
default:
case 1:
switch (templateEntity.Type)
{
case 3:
@@ -474,7 +490,37 @@ public class CodeGenService : IDynamicApiController, ITransient
templatePathList = CodeGenTargetPathHelper.BackendTemplatePathList("2-MainBelt", templateEntity.WebType, templateEntity.EnableFlow, codeGenConfigModel.IsMapper);
break;
}
break;
case 2:
switch (codeGenConfigModel.IndexDataType)
{
case 4:
switch (templateEntity.Type)
{
case 3:
break;
default:
targetPathList = CodeGenTargetPathHelper.BackendTargetPathList(item.className, fileName, templateEntity.WebType, templateEntity.EnableFlow, codeGenConfigModel.IsInlineEditor, codeGenConfigModel.IsMapper);
templatePathList = CodeGenTargetPathHelper.BackendInlineEditorTemplatePathList("2-MainBelt", templateEntity.WebType, templateEntity.EnableFlow, codeGenConfigModel.IsMapper);
break;
}
break;
default:
switch (templateEntity.Type)
{
case 3:
targetPathList = CodeGenTargetPathHelper.BackendFlowTargetPathList(item.className, fileName, codeGenConfigModel.IsMapper);
templatePathList = CodeGenTargetPathHelper.BackendFlowTemplatePathList("2-MainBelt", codeGenConfigModel.IsMapper);
break;
default:
targetPathList = CodeGenTargetPathHelper.BackendTargetPathList(item.className, fileName, templateEntity.WebType, templateEntity.EnableFlow, codeGenConfigModel.IsInlineEditor, codeGenConfigModel.IsMapper);
templatePathList = CodeGenTargetPathHelper.BackendTemplatePathList("2-MainBelt", templateEntity.WebType, templateEntity.EnableFlow, codeGenConfigModel.IsMapper);
break;
}
break;
}
break;
}
@@ -482,8 +528,7 @@ public class CodeGenService : IDynamicApiController, ITransient
for (int i = 0; i < templatePathList.Count; i++)
{
string tContent = File.ReadAllText(templatePathList[i]);
string tResult = _viewEngine.RunCompileFromCached(tContent, new
{
string tResult = _viewEngine.RunCompileFromCached(tContent, new {
NameSpace = codeGenConfigModel.NameSpace,
BusName = codeGenConfigModel.BusName,
ClassName = codeGenConfigModel.ClassName,
@@ -538,6 +583,12 @@ public class CodeGenService : IDynamicApiController, ITransient
ParsJnpfKeyConstList = codeGenConfigModel.ParsJnpfKeyConstList,
ParsJnpfKeyConstListDetails = codeGenConfigModel.ParsJnpfKeyConstListDetails,
ImportDataType = codeGenConfigModel.ImportDataType,
DataRuleJson = CodeGenControlsAttributeHelper.GetDataRuleList(templateEntity, codeGenConfigModel).ToJsonString().Replace("\"", "\\\"").Replace("\\\\\"", "\\\\\\\"").Replace("\\\\\\\\\"", "\\\\\\\\\\\\\""),
IsSearchMultiple = codeGenConfigModel.IsSearchMultiple,
IsTreeTable = codeGenConfigModel.IsTreeTable,
ParentField = codeGenConfigModel.ParentField,
TreeShowField = codeGenConfigModel.TreeShowField,
IsLogicalDelete = codeGenConfigModel.IsLogicalDelete,
});
var dirPath = new DirectoryInfo(targetPathList[i]).Parent.FullName;
if (!Directory.Exists(dirPath))
@@ -552,12 +603,6 @@ public class CodeGenService : IDynamicApiController, ITransient
}
break;
/*
* 使用导航查询一对一模式
* 优点:语法糖简单
* 缺点:子表的时间类型无法直接转换
*/
case GeneratePatterns.MainBeltVice:
{
var link = await _repository.AsSugarClient().Queryable<DbLinkEntity>().FirstAsync(m => m.Id == templateEntity.DbLinkId && m.DeleteMark == null);
@@ -584,6 +629,9 @@ public class CodeGenService : IDynamicApiController, ITransient
throw Oops.Oh(ErrorCode.D2109);
}
if (formDataModel.logicalDelete && !fieldList.Any(it => it.field.ToLower().Equals("f_deletemark")))
throw Oops.Oh(ErrorCode.D2110);
codeGenConfigModel = CodeGenWay.AuxiliaryTableBackEnd(item.table, fieldList, auxiliaryControls, templateEntity, tableNo, 0);
codeGenConfigModel.BusName = item.tableName;
codeGenConfigModel.ClassName = item.className;
@@ -600,8 +648,7 @@ public class CodeGenService : IDynamicApiController, ITransient
for (int i = 0; i < templatePathList.Count; i++)
{
var tContent = File.ReadAllText(templatePathList[i]);
var tResult = _viewEngine.RunCompileFromCached(tContent, new
{
var tResult = _viewEngine.RunCompileFromCached(tContent, new {
BusName = codeGenConfigModel.BusName,
ClassName = codeGenConfigModel.ClassName,
NameSpace = formDataModel.areasName,
@@ -633,6 +680,7 @@ public class CodeGenService : IDynamicApiController, ITransient
TableName = item.table.ParseToPascalCase(),
PrimaryKey = codeGenConfigModel.TableField.Find(it => it.PrimaryKey).ColumnName,
TableField = codeGenConfigModel.TableField.Find(it => it.ForeignKeyField).ColumnName,
ChilderColumnConfigList = codeGenConfigModel.TableField,
OriginalTableField = codeGenConfigModel.TableField.Find(it => it.ForeignKeyField).OriginalColumnName,
RelationField = item.relationField.ReplaceRegex("^f_", string.Empty).ParseToPascalCase(),
OriginalRelationField = item.relationField,
@@ -642,6 +690,8 @@ public class CodeGenService : IDynamicApiController, ITransient
IsImportData = codeGenConfigModel.TableField.Any(it => it.IsImportField.Equals(true)),
IsSystemControl = codeGenConfigModel.TableField.Any(it => it.IsSystemControl),
IsUpdate = codeGenConfigModel.TableField.Any(it => it.IsUpdate),
IsSearchMultiple = codeGenConfigModel.IsSearchMultiple,
IsControlParsing = codeGenConfigModel.TableField.Any(it => it.IsControlParsing),
});
auxiliaryTableColumnList.AddRange(codeGenConfigModel.TableField.FindAll(it => it.jnpfKey != null));
@@ -656,38 +706,27 @@ public class CodeGenService : IDynamicApiController, ITransient
// 开启乐观锁
if (formDataModel.concurrencyLock && !fieldList.Any(it => it.field.ToLower().Equals("f_version")))
{
throw Oops.Oh(ErrorCode.D2107);
}
if (formDataModel.primaryKeyPolicy == 2 && !fieldList.Any(it => it.primaryKey && it.identity))
{
throw Oops.Oh(ErrorCode.D2109);
}
if (templateEntity.EnableFlow == 1 && !fieldList.Any(it => it.field.ToLower().Equals("f_flowid")))
throw Oops.Oh(ErrorCode.D2105);
// 列表带流程 或者 流程表单 自增ID
if (formDataModel.primaryKeyPolicy == 2 && templateEntity.EnableFlow == 1 && !fieldList.Any(it => it.field.ToLower().Equals("f_flowtaskid")))
{
throw Oops.Oh(ErrorCode.D2108);
}
if (formDataModel.logicalDelete && !fieldList.Any(it => it.field.ToLower().Equals("f_deletemark")))
throw Oops.Oh(ErrorCode.D2110);
// 后端生成
codeGenConfigModel = CodeGenWay.MainBeltViceBackEnd(item.table, fieldList, auxiliaryTableColumnList, controls, templateEntity);
switch (codeGenConfigModel.IndexDataType)
switch (templateEntity.WebType)
{
case 4:
switch (templateEntity.Type)
{
case 3:
break;
default:
targetPathList = CodeGenTargetPathHelper.BackendTargetPathList(codeGenConfigModel.ClassName, fileName, templateEntity.WebType, templateEntity.EnableFlow, codeGenConfigModel.IsInlineEditor, codeGenConfigModel.IsMapper);
templatePathList = CodeGenTargetPathHelper.BackendInlineEditorTemplatePathList("4-MainBeltVice", templateEntity.WebType, templateEntity.EnableFlow, codeGenConfigModel.IsMapper);
break;
}
break;
default:
case 1:
switch (templateEntity.Type)
{
case 3:
@@ -700,13 +739,41 @@ public class CodeGenService : IDynamicApiController, ITransient
break;
}
break;
case 2:
switch (codeGenConfigModel.IndexDataType)
{
case 4:
switch (templateEntity.Type)
{
case 3:
break;
default:
targetPathList = CodeGenTargetPathHelper.BackendTargetPathList(codeGenConfigModel.ClassName, fileName, templateEntity.WebType, templateEntity.EnableFlow, codeGenConfigModel.IsInlineEditor, codeGenConfigModel.IsMapper);
templatePathList = CodeGenTargetPathHelper.BackendInlineEditorTemplatePathList("4-MainBeltVice", templateEntity.WebType, templateEntity.EnableFlow, codeGenConfigModel.IsMapper);
break;
}
break;
default:
switch (templateEntity.Type)
{
case 3:
targetPathList = CodeGenTargetPathHelper.BackendFlowTargetPathList(codeGenConfigModel.ClassName, fileName, codeGenConfigModel.IsMapper);
templatePathList = CodeGenTargetPathHelper.BackendFlowTemplatePathList("4-MainBeltVice", codeGenConfigModel.IsMapper);
break;
default:
targetPathList = CodeGenTargetPathHelper.BackendTargetPathList(codeGenConfigModel.ClassName, fileName, templateEntity.WebType, templateEntity.EnableFlow, codeGenConfigModel.IsInlineEditor, codeGenConfigModel.IsMapper);
templatePathList = CodeGenTargetPathHelper.BackendTemplatePathList("4-MainBeltVice", templateEntity.WebType, templateEntity.EnableFlow, codeGenConfigModel.IsMapper);
break;
}
break;
}
break;
}
for (var i = 0; i < templatePathList.Count; i++)
{
var tContent = File.ReadAllText(templatePathList[i]);
var tResult = _viewEngine.RunCompileFromCached(tContent, new
{
var tResult = _viewEngine.RunCompileFromCached(tContent, new {
NameSpace = codeGenConfigModel.NameSpace,
BusName = codeGenConfigModel.BusName,
ClassName = codeGenConfigModel.ClassName,
@@ -759,6 +826,12 @@ public class CodeGenService : IDynamicApiController, ITransient
ParsJnpfKeyConstList = codeGenConfigModel.ParsJnpfKeyConstList,
ParsJnpfKeyConstListDetails = codeGenConfigModel.ParsJnpfKeyConstListDetails,
ImportDataType = codeGenConfigModel.ImportDataType,
DataRuleJson = CodeGenControlsAttributeHelper.GetDataRuleList(templateEntity, codeGenConfigModel).ToJsonString().Replace("\"", "\\\"").Replace("\\\\\"", "\\\\\\\"").Replace("\\\\\\\\\"", "\\\\\\\\\\\\\""),
IsSearchMultiple = codeGenConfigModel.IsSearchMultiple,
IsTreeTable = codeGenConfigModel.IsTreeTable,
ParentField = codeGenConfigModel.ParentField,
TreeShowField = codeGenConfigModel.TreeShowField,
IsLogicalDelete = codeGenConfigModel.IsLogicalDelete,
});
var dirPath = new DirectoryInfo(targetPathList[i]).Parent.FullName;
if (!Directory.Exists(dirPath))
@@ -816,9 +889,10 @@ public class CodeGenService : IDynamicApiController, ITransient
// 默认主表开启自增子表也需要开启自增
if (formDataModel.primaryKeyPolicy == 2 && !fieldList.Any(it => it.primaryKey && it.identity))
{
throw Oops.Oh(ErrorCode.D2109);
}
if (formDataModel.logicalDelete && !fieldList.Any(it => it.field.ToLower().Equals("f_deletemark")))
throw Oops.Oh(ErrorCode.D2110);
// 后端生成
codeGenConfigModel = CodeGenWay.ChildTableBackEnd(item.table, item.className, fieldList, controls, templateEntity, controlId);
@@ -830,8 +904,7 @@ public class CodeGenService : IDynamicApiController, ITransient
for (int i = 0; i < templatePathList.Count; i++)
{
var tContent = File.ReadAllText(templatePathList[i]);
var tResult = _viewEngine.RunCompileFromCached(tContent, new
{
var tResult = _viewEngine.RunCompileFromCached(tContent, new {
BusName = codeGenConfigModel.BusName,
ClassName = codeGenConfigModel.ClassName,
NameSpace = formDataModel.areasName,
@@ -876,6 +949,8 @@ public class CodeGenService : IDynamicApiController, ITransient
IsConversion = codeGenConfigModel.TableField.Any(it => it.IsConversion.Equals(true)),
IsDetailConversion = codeGenConfigModel.TableField.Any(it => it.IsDetailConversion.Equals(true)),
IsImportData = codeGenConfigModel.TableField.Any(it => it.IsImportField.Equals(true)),
IsSearchMultiple = codeGenConfigModel.IsSearchMultiple,
IsControlParsing = codeGenConfigModel.TableField.Any(it => it.IsControlParsing),
});
tableNo++;
@@ -892,6 +967,10 @@ public class CodeGenService : IDynamicApiController, ITransient
var auxiliaryControls = controls.FindAll(it => it.__config__.tableName == item.table);
var fieldList = _databaseManager.GetFieldList(targetLink, item.table);
// 默认主表开启自增副表也需要开启自增
if (formDataModel.primaryKeyPolicy == 2 && !fieldList.Any(it => it.primaryKey && it.identity))
throw Oops.Oh(ErrorCode.D2109);
codeGenConfigModel = CodeGenWay.AuxiliaryTableBackEnd(item.table, fieldList, auxiliaryControls, templateEntity, tableNo, 1);
codeGenConfigModel.BusName = item.tableName;
codeGenConfigModel.ClassName = item.className;
@@ -901,18 +980,11 @@ public class CodeGenService : IDynamicApiController, ITransient
codeGenConfigModel.TableField.ForEach(items => items.ClassName = item.className);
// 默认主表开启自增副表也需要开启自增
if (formDataModel.primaryKeyPolicy == 2 && !fieldList.Any(it => it.primaryKey && it.identity))
{
throw Oops.Oh(ErrorCode.D2109);
}
// 生成副表相关文件
for (int i = 0; i < templatePathList.Count; i++)
{
var tContent = File.ReadAllText(templatePathList[i]);
var tResult = _viewEngine.RunCompileFromCached(tContent, new
{
var tResult = _viewEngine.RunCompileFromCached(tContent, new {
BusName = codeGenConfigModel.BusName,
ClassName = codeGenConfigModel.ClassName,
NameSpace = formDataModel.areasName,
@@ -944,6 +1016,7 @@ public class CodeGenService : IDynamicApiController, ITransient
TableName = item.table.ParseToPascalCase(),
PrimaryKey = codeGenConfigModel.TableField.Find(it => it.PrimaryKey).ColumnName,
TableField = codeGenConfigModel.TableField.Find(it => it.ForeignKeyField).ColumnName,
ChilderColumnConfigList = codeGenConfigModel.TableField,
OriginalTableField = codeGenConfigModel.TableField.Find(it => it.ForeignKeyField).OriginalColumnName,
RelationField = item.relationField.ReplaceRegex("^f_", string.Empty).ParseToPascalCase(),
OriginalRelationField = item.relationField,
@@ -953,6 +1026,8 @@ public class CodeGenService : IDynamicApiController, ITransient
IsImportData = codeGenConfigModel.TableField.Any(it => it.IsImportField.Equals(true)),
IsSystemControl = codeGenConfigModel.TableField.Any(it => it.IsSystemControl),
IsUpdate = codeGenConfigModel.TableField.Any(it => it.IsUpdate),
IsSearchMultiple = codeGenConfigModel.IsSearchMultiple,
IsControlParsing = codeGenConfigModel.TableField.Any(it => it.IsControlParsing),
});
auxiliaryTableColumnList.AddRange(codeGenConfigModel.TableField.FindAll(it => it.jnpfKey != null));
@@ -972,10 +1047,16 @@ public class CodeGenService : IDynamicApiController, ITransient
if (formDataModel.primaryKeyPolicy == 2 && !fieldList.Any(it => it.primaryKey && it.identity))
throw Oops.Oh(ErrorCode.D2109);
if (templateEntity.EnableFlow == 1 && !fieldList.Any(it => it.field.ToLower().Equals("f_flowid")))
throw Oops.Oh(ErrorCode.D2105);
// 列表带流程 或者 流程表单 自增ID
if (formDataModel.primaryKeyPolicy == 2 && templateEntity.EnableFlow == 1 && !fieldList.Any(it => it.field.ToLower().Equals("f_flowtaskid")))
throw Oops.Oh(ErrorCode.D2108);
if (formDataModel.logicalDelete && !fieldList.Any(it => it.field.ToLower().Equals("f_deletemark")))
throw Oops.Oh(ErrorCode.D2110);
// 后端生成
codeGenConfigModel = CodeGenWay.PrimarySecondaryBackEnd(item.table, fieldList, auxiliaryTableColumnList, controls, templateEntity);
@@ -983,21 +1064,10 @@ public class CodeGenService : IDynamicApiController, ITransient
codeGenConfigModel.BusName = tableRelation.Find(it => it.relationTable.Equals("")).tableName;
codeGenConfigModel.TableRelations = subTableRelationsList;
codeGenConfigModel.IsChildConversion = subTableRelationsList.Any(it => it.IsConversion);
switch (codeGenConfigModel.IndexDataType)
{
case 4:
switch (templateEntity.Type)
{
case 3:
break;
default:
targetPathList = CodeGenTargetPathHelper.BackendTargetPathList(item.className, fileName, templateEntity.WebType, templateEntity.EnableFlow, codeGenConfigModel.IsInlineEditor, codeGenConfigModel.IsMapper);
templatePathList = CodeGenTargetPathHelper.BackendInlineEditorTemplatePathList("5-PrimarySecondary", templateEntity.WebType, templateEntity.EnableFlow, codeGenConfigModel.IsMapper);
break;
}
break;
default:
switch (templateEntity.WebType)
{
case 1:
switch (templateEntity.Type)
{
case 3:
@@ -1009,7 +1079,37 @@ public class CodeGenService : IDynamicApiController, ITransient
templatePathList = CodeGenTargetPathHelper.BackendTemplatePathList("5-PrimarySecondary", templateEntity.WebType, templateEntity.EnableFlow, codeGenConfigModel.IsMapper);
break;
}
break;
case 2:
switch (codeGenConfigModel.IndexDataType)
{
case 4:
switch (templateEntity.Type)
{
case 3:
break;
default:
targetPathList = CodeGenTargetPathHelper.BackendTargetPathList(item.className, fileName, templateEntity.WebType, templateEntity.EnableFlow, codeGenConfigModel.IsInlineEditor, codeGenConfigModel.IsMapper);
templatePathList = CodeGenTargetPathHelper.BackendInlineEditorTemplatePathList("5-PrimarySecondary", templateEntity.WebType, templateEntity.EnableFlow, codeGenConfigModel.IsMapper);
break;
}
break;
default:
switch (templateEntity.Type)
{
case 3:
targetPathList = CodeGenTargetPathHelper.BackendFlowTargetPathList(item.className, fileName, codeGenConfigModel.IsMapper);
templatePathList = CodeGenTargetPathHelper.BackendFlowTemplatePathList("5-PrimarySecondary", codeGenConfigModel.IsMapper);
break;
default:
targetPathList = CodeGenTargetPathHelper.BackendTargetPathList(item.className, fileName, templateEntity.WebType, templateEntity.EnableFlow, codeGenConfigModel.IsInlineEditor, codeGenConfigModel.IsMapper);
templatePathList = CodeGenTargetPathHelper.BackendTemplatePathList("5-PrimarySecondary", templateEntity.WebType, templateEntity.EnableFlow, codeGenConfigModel.IsMapper);
break;
}
break;
}
break;
}
@@ -1017,8 +1117,7 @@ public class CodeGenService : IDynamicApiController, ITransient
for (int i = 0; i < templatePathList.Count; i++)
{
string tContent = File.ReadAllText(templatePathList[i]);
string tResult = _viewEngine.RunCompileFromCached(tContent, new
{
string tResult = _viewEngine.RunCompileFromCached(tContent, new {
NameSpace = codeGenConfigModel.NameSpace,
BusName = codeGenConfigModel.BusName,
ClassName = codeGenConfigModel.ClassName,
@@ -1073,6 +1172,12 @@ public class CodeGenService : IDynamicApiController, ITransient
ParsJnpfKeyConstList = codeGenConfigModel.ParsJnpfKeyConstList,
ParsJnpfKeyConstListDetails = codeGenConfigModel.ParsJnpfKeyConstListDetails,
ImportDataType = codeGenConfigModel.ImportDataType,
DataRuleJson = CodeGenControlsAttributeHelper.GetDataRuleList(templateEntity, codeGenConfigModel).ToJsonString().Replace("\"", "\\\"").Replace("\\\\\"", "\\\\\\\"").Replace("\\\\\\\\\"", "\\\\\\\\\\\\\""),
IsSearchMultiple = codeGenConfigModel.IsSearchMultiple,
IsTreeTable = codeGenConfigModel.IsTreeTable,
ParentField = codeGenConfigModel.ParentField,
TreeShowField = codeGenConfigModel.TreeShowField,
IsLogicalDelete = codeGenConfigModel.IsLogicalDelete,
});
var dirPath = new DirectoryInfo(targetPathList[i]).Parent.FullName;
if (!Directory.Exists(dirPath))
@@ -1097,50 +1202,67 @@ public class CodeGenService : IDynamicApiController, ITransient
// 开启乐观锁
if (formDataModel.concurrencyLock && !fieldList.Any(it => it.field.ToLower().Equals("f_version")))
{
throw Oops.Oh(ErrorCode.D2107);
}
if (formDataModel.primaryKeyPolicy == 2 && !fieldList.Any(it => it.primaryKey && it.identity))
{
throw Oops.Oh(ErrorCode.D2109);
}
if (templateEntity.EnableFlow == 1 && !fieldList.Any(it => it.field.ToLower().Equals("f_flowid")))
throw Oops.Oh(ErrorCode.D2105);
// 列表带流程 或者 流程表单 自增ID
if (formDataModel.primaryKeyPolicy == 2 && templateEntity.EnableFlow == 1 && !fieldList.Any(it => it.field.ToLower().Equals("f_flowtaskid")))
{
throw Oops.Oh(ErrorCode.D2108);
}
if (formDataModel.logicalDelete && !fieldList.Any(it => it.field.ToLower().Equals("f_deletemark")))
throw Oops.Oh(ErrorCode.D2110);
// 后端生成
codeGenConfigModel = CodeGenWay.SingleTableBackEnd(tableName, fieldList, controls, templateEntity);
switch (templateEntity.Type)
switch (templateEntity.WebType)
{
case 3:
switch (codeGenConfigModel.IndexDataType)
case 1:
switch (templateEntity.Type)
{
// 流程表单没有行内编辑
case 4:
break;
default:
case 3:
targetPathList = CodeGenTargetPathHelper.BackendFlowTargetPathList(codeGenConfigModel.ClassName, fileName, codeGenConfigModel.IsMapper);
templatePathList = CodeGenTargetPathHelper.BackendFlowTemplatePathList("1-SingleTable", codeGenConfigModel.IsMapper);
break;
default:
targetPathList = CodeGenTargetPathHelper.BackendTargetPathList(codeGenConfigModel.ClassName, fileName, templateEntity.WebType, templateEntity.EnableFlow, codeGenConfigModel.IsInlineEditor, codeGenConfigModel.IsMapper);
templatePathList = CodeGenTargetPathHelper.BackendTemplatePathList("1-SingleTable", templateEntity.WebType, templateEntity.EnableFlow, codeGenConfigModel.IsMapper);
break;
}
break;
case 4:
// 功能表单
targetPathList = CodeGenTargetPathHelper.BackendTargetPathList(codeGenConfigModel.ClassName, fileName, templateEntity.WebType, templateEntity.EnableFlow, codeGenConfigModel.IsInlineEditor, codeGenConfigModel.IsMapper);
break;
case 2:
switch (codeGenConfigModel.IndexDataType)
{
// 流程表单没有行内编辑
case 4:
templatePathList = CodeGenTargetPathHelper.BackendInlineEditorTemplatePathList("1-SingleTable", templateEntity.WebType, templateEntity.EnableFlow, codeGenConfigModel.IsMapper);
switch (templateEntity.Type)
{
// 流程表单没有行内编辑
case 3:
break;
default:
targetPathList = CodeGenTargetPathHelper.BackendTargetPathList(codeGenConfigModel.ClassName, fileName, templateEntity.WebType, templateEntity.EnableFlow, codeGenConfigModel.IsInlineEditor, codeGenConfigModel.IsMapper);
templatePathList = CodeGenTargetPathHelper.BackendInlineEditorTemplatePathList("1-SingleTable", templateEntity.WebType, templateEntity.EnableFlow, codeGenConfigModel.IsMapper);
break;
}
break;
default:
templatePathList = CodeGenTargetPathHelper.BackendTemplatePathList("1-SingleTable", templateEntity.WebType, templateEntity.EnableFlow, codeGenConfigModel.IsMapper);
switch (templateEntity.Type)
{
case 3:
targetPathList = CodeGenTargetPathHelper.BackendFlowTargetPathList(codeGenConfigModel.ClassName, fileName, codeGenConfigModel.IsMapper);
templatePathList = CodeGenTargetPathHelper.BackendFlowTemplatePathList("1-SingleTable", codeGenConfigModel.IsMapper);
break;
default:
targetPathList = CodeGenTargetPathHelper.BackendTargetPathList(codeGenConfigModel.ClassName, fileName, templateEntity.WebType, templateEntity.EnableFlow, codeGenConfigModel.IsInlineEditor, codeGenConfigModel.IsMapper);
templatePathList = CodeGenTargetPathHelper.BackendTemplatePathList("1-SingleTable", templateEntity.WebType, templateEntity.EnableFlow, codeGenConfigModel.IsMapper);
break;
}
break;
}
break;
@@ -1150,8 +1272,7 @@ public class CodeGenService : IDynamicApiController, ITransient
for (var i = 0; i < templatePathList.Count; i++)
{
var tContent = File.ReadAllText(templatePathList[i]);
var tResult = _viewEngine.RunCompileFromCached(tContent, new
{
var tResult = _viewEngine.RunCompileFromCached(tContent, new {
NameSpace = codeGenConfigModel.NameSpace,
BusName = codeGenConfigModel.BusName,
ClassName = codeGenConfigModel.ClassName,
@@ -1201,6 +1322,12 @@ public class CodeGenService : IDynamicApiController, ITransient
ParsJnpfKeyConstList = codeGenConfigModel.ParsJnpfKeyConstList,
ParsJnpfKeyConstListDetails = codeGenConfigModel.ParsJnpfKeyConstListDetails,
ImportDataType = codeGenConfigModel.ImportDataType,
DataRuleJson = CodeGenControlsAttributeHelper.GetDataRuleList(templateEntity, codeGenConfigModel).ToJsonString().Replace("\"", "\\\"").Replace("\\\\\"", "\\\\\\\"").Replace("\\\\\\\\\"", "\\\\\\\\\\\\\""),
IsSearchMultiple = codeGenConfigModel.IsSearchMultiple,
IsTreeTable = codeGenConfigModel.IsTreeTable,
ParentField = codeGenConfigModel.ParentField,
TreeShowField = codeGenConfigModel.TreeShowField,
IsLogicalDelete = codeGenConfigModel.IsLogicalDelete,
});
var dirPath = new DirectoryInfo(targetPathList[i]).Parent.FullName;
if (!Directory.Exists(dirPath))
@@ -1366,7 +1493,7 @@ public class CodeGenService : IDynamicApiController, ITransient
foreach (int logic in new List<int> { 4, 5 })
{
// 每次循环前重新定义表单数据
formDataModel = templateEntity.FormData.ToObject<FormDataModel>();
formDataModel = templateEntity.FormData.ToObjectOld<FormDataModel>();
frondEndGenConfig = CodeGenWay.SingleTableFrontEnd(logic, formDataModel, controls, tableColumns, templateEntity);
@@ -1390,6 +1517,7 @@ public class CodeGenService : IDynamicApiController, ITransient
{
case 1:
hasSuperQuery = false;
frondEndGenConfig.Type = 1;
break;
default:
hasSuperQuery = columnDesignModel.hasSuperQuery;
@@ -1430,8 +1558,7 @@ public class CodeGenService : IDynamicApiController, ITransient
for (int i = 0; i < templatePathList.Count; i++)
{
string tContent = File.ReadAllText(templatePathList[i]);
var tResult = _viewEngine.RunCompileFromCached(tContent, new
{
var tResult = _viewEngine.RunCompileFromCached(tContent, new {
NameSpace = frondEndGenConfig.NameSpace,
ClassName = frondEndGenConfig.ClassName,
FormRef = frondEndGenConfig.FormRef,
@@ -1453,6 +1580,7 @@ public class CodeGenService : IDynamicApiController, ITransient
TreePropsUrl = frondEndGenConfig.TreePropsUrl,
TreePropsLabel = frondEndGenConfig.TreePropsLabel,
TreePropsChildren = frondEndGenConfig.TreePropsChildren,
IsTreeRelationMultiple = frondEndGenConfig.IsTreeRelationMultiple,
IsExistQuery = frondEndGenConfig.IsExistQuery,
PrimaryKey = frondEndGenConfig.PrimaryKey,
FormList = frondEndGenConfig.FormList,
@@ -1463,6 +1591,8 @@ public class CodeGenService : IDynamicApiController, ITransient
ColumnDesign = frondEndGenConfig.ColumnDesign,
OptionsList = frondEndGenConfig.OptionsList,
IsBatchRemoveDel = frondEndGenConfig.IsBatchRemoveDel,
IsBatchPrint = frondEndGenConfig.IsBatchPrint,
PrintIds = frondEndGenConfig.PrintIds,
IsDownload = frondEndGenConfig.IsDownload,
IsRemoveDel = frondEndGenConfig.IsRemoveDel,
IsDetail = frondEndGenConfig.IsDetail,
@@ -1478,7 +1608,7 @@ public class CodeGenService : IDynamicApiController, ITransient
UseFormPermission = frondEndGenConfig.UseFormPermission,
DefaultSidx = defaultSidx,
WebType = templateEntity.Type == 3 ? templateEntity.Type : templateEntity.WebType,
HasPage = frondEndGenConfig.HasPage && !frondEndGenConfig.IndexDataType.Equals(3),
HasPage = frondEndGenConfig.HasPage,
IsSummary = frondEndGenConfig.IsSummary,
AddTitleName = frondEndGenConfig.TopButtonDesign?.Find(it => it.Value.Equals("add"))?.Label,
EditTitleName = frondEndGenConfig.ColumnButtonDesign?.Find(it => it.Value.Equals("edit"))?.Label,
@@ -1495,6 +1625,7 @@ public class CodeGenService : IDynamicApiController, ITransient
Tables = templateEntity.Tables.ToJsonString(),
DbLinkId = templateEntity.DbLinkId,
MianTable = tableName,
PropertyJson = frondEndGenConfig.PropertyJson.ToJsonString(),
CreatorTime = DateTime.Now.ParseToUnixTime(),
CreatorUserId = _userManager.UserId,
IsChildDataTransfer = frondEndGenConfig.IsChildDataTransfer,
@@ -1509,12 +1640,21 @@ public class CodeGenService : IDynamicApiController, ITransient
GroupShowField = frondEndGenConfig.GroupShowField,
PrimaryKeyPolicy = frondEndGenConfig.PrimaryKeyPolicy,
IsRelationForm = frondEndGenConfig.IsRelationForm,
ChildTableStyle = frondEndGenConfig.ChildTableStyle,
ChildTableStyle = controls.Any(it => it.__config__.jnpfKey.Equals(JnpfKeyConst.TABLE)) ? frondEndGenConfig.ChildTableStyle : 1,
IsFixed = frondEndGenConfig.IsFixed,
IsChildrenRegular = frondEndGenConfig.IsChildrenRegular,
TreeSynType = frondEndGenConfig.TreeSynType,
HasTreeQuery = frondEndGenConfig.HasTreeQuery,
ColumnData = frondEndGenConfig.ColumnData.ToJsonString(),
SummaryField = frondEndGenConfig.SummaryField.ToJsonString(),
ShowSummary = frondEndGenConfig.ShowSummary,
DefaultFormControlList = frondEndGenConfig.DefaultFormControlList,
IsDefaultFormControl = frondEndGenConfig.IsDefaultFormControl,
FormRealControl = frondEndGenConfig.FormRealControl,
}, builderAction: builder =>
{
builder.AddUsing("JNPF.VisualDev.Engine.Model.CodeGen");
builder.AddAssemblyReferenceByName("Tnb.VisualDev.Engine");
builder.AddAssemblyReferenceByName("JNPF.VisualDev.Engine");
});
var dirPath = new DirectoryInfo(targetPathList[i]).Parent.FullName;
if (!Directory.Exists(dirPath))