using System.IO.Compression;
using System.Text;
using JNPF.Common.Configuration;
using JNPF.Common.Const;
using JNPF.Common.Core.Manager;
using JNPF.Common.Enums;
using JNPF.Common.Extension;
using JNPF.Common.Manager;
using JNPF.Common.Security;
using JNPF.DataEncryption;
using JNPF.DependencyInjection;
using JNPF.DynamicApiController;
using JNPF.FriendlyException;
using JNPF.Systems.Entitys.System;
using JNPF.Systems.Interfaces.Common;
using JNPF.Systems.Interfaces.System;
using JNPF.ViewEngine;
using JNPF.VisualDev.Engine;
using JNPF.VisualDev.Engine.CodeGen;
using JNPF.VisualDev.Engine.Model.CodeGen;
using JNPF.VisualDev.Engine.Security;
using JNPF.VisualDev.Entitys;
using JNPF.VisualDev.Entitys.Dto.CodeGen;
using JNPF.VisualDev.Entitys.Enum;
using Microsoft.AspNetCore.Mvc;
using SqlSugar;
namespace JNPF.CodeGen;
///
/// 业务实现:代码生成.
///
[ApiDescriptionSettings(Tag = "CodeGenerater", Name = "Generater", Order = 175)]
[Route("api/visualdev/[controller]")]
public class CodeGenService : IDynamicApiController, ITransient
{
///
/// 服务基础仓储.
///
private readonly ISqlSugarRepository _repository;
///
/// 视图引擎.
///
private readonly IViewEngine _viewEngine;
///
/// 数据连接服务.
///
private readonly IDbLinkService _dbLinkService;
///
/// 字典数据服务.
///
private readonly IDictionaryDataService _dictionaryDataService;
///
/// 文件服务.
///
private readonly IFileService _fileService;
///
/// 用户管理器.
///
private readonly IUserManager _userManager;
///
/// 数据库管理器.
///
private readonly IDataBaseManager _databaseManager;
///
/// 文件服务.
///
private readonly ICacheManager _cacheManager;
///
/// 初始化一个类型的新实例.
///
public CodeGenService(
ISqlSugarRepository visualDevRepository,
IViewEngine viewEngine,
IDbLinkService dbLinkService,
IDictionaryDataService dictionaryDataService,
IFileService fileService,
IUserManager userManager,
ICacheManager cacheManager,
IDataBaseManager databaseManager)
{
_repository = visualDevRepository;
_viewEngine = viewEngine;
_dbLinkService = dbLinkService;
_dictionaryDataService = dictionaryDataService;
_fileService = fileService;
_userManager = userManager;
_cacheManager = cacheManager;
_databaseManager = databaseManager;
}
#region Get
///
/// 获取命名空间.
///
[HttpGet("AreasName")]
public dynamic GetAreasName()
{
List areasName = new List();
if (KeyVariable.AreasName.Count > 0)
areasName = KeyVariable.AreasName;
return areasName;
}
#endregion
#region Post
///
/// 下载代码.
///
[HttpPost("{id}/Actions/DownloadCode")]
public async Task DownloadCode(string id, [FromBody] DownloadCodeFormInput downloadCodeForm)
{
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.ToObjectOld();
if (templateEntity.Type == 3)
downloadCodeForm.module = "WorkFlow";
model.className = new List() { downloadCodeForm.className.ParseToPascalCase() };
model.areasName = downloadCodeForm.module;
string fileName = string.Format("{0}_{1:yyyyMMddHHmmss}", templateEntity.FullName, DateTime.Now);
// 判断子表名称
var childTb = new List();
if (!downloadCodeForm.subClassName.IsNullOrEmpty())
childTb = new List(downloadCodeForm.subClassName.Split(','));
// 子表名称去重
HashSet set = new HashSet(childTb);
var tableList = templateEntity.Tables.ToObject>();
tableList.FindAll(it => it.relationTable.Equals("")).ForEach(item =>
{
item.className = downloadCodeForm.className.ParseToPascalCase();
item.tableName = downloadCodeForm.description;
});
bool result = childTb.Count == set.Count ? true : false;
if (!result)
throw Oops.Oh(ErrorCode.D2101);
var numNo = 0;
tableList.FindAll(it => !it.relationTable.Equals("")).ForEach(item =>
{
item.className = childTb[numNo].ParseToPascalCase();
numNo++;
});
templateEntity.FormData = model.ToJsonString();
templateEntity.Tables = tableList.ToJsonString();
// 模板数据聚合
await TemplatesDataAggregation(fileName, templateEntity);
string randPath = Path.Combine(KeyVariable.SystemPath, "CodeGenerate", fileName);
string downloadPath = randPath + ".zip";
// 判断是否存在同名称文件
if (File.Exists(downloadPath))
File.Delete(downloadPath);
ZipFile.CreateFromDirectory(randPath, downloadPath);
if (!App.Configuration["OSS:Provider"].Equals("Invalid"))
await _fileService.UploadFileByType(downloadPath, "CodeGenerate", string.Format("{0}.zip", fileName));
var downloadFileName = string.Format("{0}|{1}.zip|codeGenerator", _userManager.UserId, fileName);
_cacheManager.Set(fileName + ".zip", string.Empty);
return new { name = fileName, url = "/api/File/Download?encryption=" + DESCEncryption.Encrypt(downloadFileName, "JNPF") };
}
///
/// 预览代码.
///
///
///
///
[HttpPost("{id}/Actions/CodePreview")]
public async Task CodePreview(string id, [FromBody] DownloadCodeFormInput downloadCodeForm)
{
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.ToObjectOld();
model.className = new List() { downloadCodeForm.className.ParseToPascalCase() };
model.areasName = downloadCodeForm.module;
string fileName = SnowflakeIdHelper.NextId();
// 判断子表名称
var childTb = new List();
if (!downloadCodeForm.subClassName.IsNullOrEmpty())
childTb = new List(downloadCodeForm.subClassName.Split(','));
// 子表名称去重
HashSet set = new HashSet(childTb);
var tableList = templateEntity.Tables.ToObject>();
tableList.FindAll(it => it.relationTable.Equals("")).ForEach(item =>
{
item.className = downloadCodeForm.className.ParseToPascalCase();
item.tableName = downloadCodeForm.description;
});
bool result = childTb.Count == set.Count ? true : false;
if (!result)
throw Oops.Oh(ErrorCode.D2101);
var numNo = 0;
tableList.FindAll(it => !it.relationTable.Equals("")).ForEach(item =>
{
item.className = childTb[numNo].ParseToPascalCase();
numNo++;
});
templateEntity.FormData = model.ToJsonString();
templateEntity.Tables = tableList.ToJsonString();
await TemplatesDataAggregation(fileName, templateEntity);
string randPath = Path.Combine(App.Configuration["JNPF_App:SystemPath"], "CodeGenerate", fileName);
var dataList = this.PriviewCode(randPath);
if (dataList == null && dataList.Count == 0)
throw Oops.Oh(ErrorCode.D2102);
return new { list = dataList };
}
#endregion
#region PrivateMethod
///
/// 模板数据聚合.
///
/// 生成ZIP文件名.
/// 模板实体.
///
private async Task TemplatesDataAggregation(string fileName, VisualDevEntity templateEntity)
{
// 类型名称
var categoryName = (await _dictionaryDataService.GetInfo(templateEntity.Category)).EnCode;
// 表关系
List? tableRelation = templateEntity.Tables.ToObject>();
// 表单数据
var formDataModel = templateEntity.FormData.ToObjectOld();
// 列表属性
ColumnDesignModel? pcColumnDesignModel = templateEntity.ColumnData?.ToObject();
ColumnDesignModel? appColumnDesignModel = templateEntity.AppColumnData?.ToObject();
pcColumnDesignModel ??= new ColumnDesignModel();
appColumnDesignModel ??= new ColumnDesignModel();
bool useDataPermission = false;
if (pcColumnDesignModel.useDataPermission && appColumnDesignModel.useDataPermission)
{
useDataPermission = true;
}
else if (!pcColumnDesignModel.useDataPermission && appColumnDesignModel.useDataPermission)
{
useDataPermission = true;
}
else if (pcColumnDesignModel.useDataPermission && !appColumnDesignModel.useDataPermission)
{
useDataPermission = true;
}
else
{
useDataPermission = false;
}
// 剔除多余布局控件组
var controls = TemplateAnalysis.AnalysisTemplateData(formDataModel.fields);
switch (templateEntity.Type)
{
case 4:
case 5:
switch (templateEntity.WebType)
{
case 1:
break;
default:
if (pcColumnDesignModel.type == 2 && (pcColumnDesignModel.searchList.Count == 0 || !pcColumnDesignModel.searchList.Any(it => it.prop.Equals(pcColumnDesignModel.treeRelation))))
{
var search = new FieldsModel();
// 左侧树关联字段是否为子表字段
switch (pcColumnDesignModel.treeRelation.StartsWith("tableField"))
{
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;
}
}
// 统一处理下表单内控件
controls = CodeGenUnifiedHandlerHelper.UnifiedHandlerFormDataModel(controls, pcColumnDesignModel, appColumnDesignModel);
controls = CodeGenUnifiedHandlerHelper.UnifiedHandlerControlRelationship(controls);
break;
}
break;
}
List targetPathList = new List();
List templatePathList = new List();
string tableName = string.Empty;
CodeGenConfigModel codeGenConfigModel = new CodeGenConfigModel();
// 主表代码生成配置模型
CodeGenConfigModel codeGenMainTableConfigModel = new CodeGenConfigModel();
/*
* 区分是纯主表、主带副、主带子、主带副与子
* 1-纯主表、2-主带子、3-主带副、4-主带副与子
* 生成模式
* 因ORM原因 导航查询 一对多 列表查询
* 不能使用ORM 自带函数 待作者开放.Select()
* 导致一对多列表查询转换必须全使用子查询
* 远端数据与静态数据无法列表转换所以全部ThenMapper内转换
* 数据字典又分为两种值转换ID与EnCode
*/
switch (JudgmentGenerationModel(tableRelation, controls))
{
case GeneratePatterns.MainBelt:
{
var link = await _repository.AsSugarClient().Queryable().FirstAsync(m => m.Id == templateEntity.DbLinkId && m.DeleteMark == null);
var targetLink = link ?? _databaseManager.GetTenantDbLink(_userManager.TenantId, _userManager.TenantDbName);
List tableRelationsList = new List();
var tableNo = 0;
// 生成子表
foreach (DbTableRelationModel? item in tableRelation.FindAll(it => it.typeId == "0"))
{
tableNo++;
var controlId = string.Empty;
var children = controls.Find(it => it.__config__.jnpfKey.Equals(JnpfKeyConst.TABLE) && it.__config__.tableName.Equals(item.table));
codeGenConfigModel.BusName = children.__config__.label;
codeGenConfigModel.ClassName = item.className;
controlId = children.__vModel__;
if (children != null) controls = children.__config__.children;
var fieldList = _databaseManager.GetFieldList(targetLink, item.table);
if (fieldList.Count == 0) throw Oops.Oh(ErrorCode.D2106);
// 默认主表开启自增子表也需要开启自增
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);
targetPathList = CodeGenTargetPathHelper.BackendChildTableTargetPathList(codeGenConfigModel.ClassName, fileName, templateEntity.WebType, templateEntity.Type, codeGenConfigModel.IsMapper, codeGenConfigModel.IsShowSubTableField);
templatePathList = CodeGenTargetPathHelper.BackendChildTableTemplatePathList("SubTable", templateEntity.WebType, templateEntity.Type, codeGenConfigModel.IsMapper, codeGenConfigModel.IsShowSubTableField);
// 生成子表相关文件
for (int i = 0; i < templatePathList.Count; i++)
{
var tContent = File.ReadAllText(templatePathList[i]);
var tResult = _viewEngine.RunCompileFromCached(tContent, new
{
BusName = codeGenConfigModel.BusName,
ClassName = codeGenConfigModel.ClassName,
NameSpace = formDataModel.areasName,
PrimaryKey = codeGenConfigModel.TableField.Find(it => it.PrimaryKey).ColumnName,
MainClassName = codeGenConfigModel.ClassName,
OriginalMainTableName = item.table,
TableField = codeGenConfigModel.TableField,
IsUploading = codeGenConfigModel.IsUpload,
IsMapper = codeGenConfigModel.IsMapper,
WebType = templateEntity.WebType,
Type = templateEntity.Type,
PrimaryKeyPolicy = codeGenConfigModel.PrimaryKeyPolicy,
IsImportData = codeGenConfigModel.IsImportData,
EnableFlow = templateEntity.EnableFlow == 0 ? false : true,
});
var dirPath = new DirectoryInfo(targetPathList[i]).Parent.FullName;
if (!Directory.Exists(dirPath))
Directory.CreateDirectory(dirPath);
File.WriteAllText(targetPathList[i], tResult, Encoding.UTF8);
}
tableRelationsList.Add(new CodeGenTableRelationsModel
{
ClassName = item.className,
OriginalTableName = item.table,
RelationTable = item.relationTable,
TableName = item.table.ParseToPascalCase(),
PrimaryKey = codeGenConfigModel.TableField.Find(it => it.PrimaryKey).ColumnName,
TableField = codeGenConfigModel.TableField.Find(it => it.ForeignKeyField).ColumnName,
OriginalTableField = codeGenConfigModel.TableField.Find(it => it.ForeignKeyField).OriginalColumnName,
RelationField = item.relationField.ReplaceRegex("^f_", string.Empty).ParseToPascalCase(),
OriginalRelationField = item.relationField,
ControlTableComment = codeGenConfigModel.BusName,
TableComment = item.tableName,
ChilderColumnConfigList = codeGenConfigModel.TableField,
ChilderColumnConfigListCount = codeGenConfigModel.TableField.FindAll(it => !it.PrimaryKey && !it.ForeignKeyField && it.jnpfKey != null).Count(),
TableNo = tableNo,
ControlModel = controlId,
IsQueryWhether = codeGenConfigModel.TableField.Any(it => it.QueryWhether),
IsShowField = codeGenConfigModel.TableField.Any(it => it.IsShow),
IsUnique = codeGenConfigModel.TableField.Any(it => it.IsUnique),
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),
});
// 还原全部控件
controls = TemplateAnalysis.AnalysisTemplateData(formDataModel.fields);
}
// 生成主表
foreach (DbTableRelationModel? item in tableRelation.FindAll(it => it.typeId == "1"))
{
var fieldList = _databaseManager.GetFieldList(targetLink, item.table);
if (fieldList.Count == 0) throw Oops.Oh(ErrorCode.D2106);
// 开启乐观锁
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);
codeGenConfigModel.BusName = item.tableName;
codeGenConfigModel.TableRelations = tableRelationsList;
codeGenConfigModel.IsChildConversion = tableRelationsList.Any(it => it.IsConversion);
switch (templateEntity.WebType)
{
case 1:
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;
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;
}
// 生成后端文件
for (int i = 0; i < templatePathList.Count; i++)
{
string tContent = File.ReadAllText(templatePathList[i]);
string tResult = _viewEngine.RunCompileFromCached(tContent, new
{
NameSpace = codeGenConfigModel.NameSpace,
BusName = codeGenConfigModel.BusName,
ClassName = codeGenConfigModel.ClassName,
PrimaryKey = codeGenConfigModel.PrimaryKey,
LowerPrimaryKey = codeGenConfigModel.LowerPrimaryKey,
OriginalPrimaryKey = codeGenConfigModel.OriginalPrimaryKey,
MainTable = codeGenConfigModel.MainTable,
LowerMainTable = codeGenConfigModel.LowerMainTable,
OriginalMainTableName = codeGenConfigModel.OriginalMainTableName,
hasPage = codeGenConfigModel.hasPage && !codeGenConfigModel.IndexDataType.Equals(3),
Function = codeGenConfigModel.Function,
TableField = codeGenConfigModel.TableField,
TableFieldCount = codeGenConfigModel.TableField.FindAll(it => !it.PrimaryKey && it.jnpfKey != null).Count(),
DefaultSidx = codeGenConfigModel.DefaultSidx,
IsExport = codeGenConfigModel.IsExport,
IsBatchRemove = codeGenConfigModel.IsBatchRemove,
IsUploading = codeGenConfigModel.IsUpload,
IsTableRelations = codeGenConfigModel.IsTableRelations,
IsMapper = codeGenConfigModel.IsMapper,
IsSystemControl = codeGenConfigModel.IsSystemControl,
IsUpdate = codeGenConfigModel.IsUpdate,
IsBillRule = codeGenConfigModel.IsBillRule,
DbLinkId = codeGenConfigModel.DbLinkId,
FormId = codeGenConfigModel.FormId,
WebType = codeGenConfigModel.WebType,
Type = codeGenConfigModel.Type,
EnableFlow = codeGenConfigModel.EnableFlow,
IsMainTable = codeGenConfigModel.IsMainTable,
EnCode = codeGenConfigModel.EnCode,
UseDataPermission = useDataPermission,
SearchControlNum = codeGenConfigModel.SearchControlNum,
IsAuxiliaryTable = codeGenConfigModel.IsAuxiliaryTable,
ExportField = codeGenConfigModel.ExportField,
TableRelations = codeGenConfigModel.TableRelations,
ConfigId = _userManager.TenantId,
DBName = _userManager.TenantDbName,
PcUseDataPermission = pcColumnDesignModel.useDataPermission ? "true" : "false",
AppUseDataPermission = appColumnDesignModel.useDataPermission ? "true" : "false",
FullName = codeGenConfigModel.FullName,
IsConversion = codeGenConfigModel.IsConversion,
HasSuperQuery = codeGenConfigModel.HasSuperQuery,
PrimaryKeyPolicy = codeGenConfigModel.PrimaryKeyPolicy,
ConcurrencyLock = codeGenConfigModel.ConcurrencyLock,
IsUnique = codeGenConfigModel.IsUnique || codeGenConfigModel.TableRelations.Any(it => it.IsUnique),
IsChildConversion = codeGenConfigModel.IsChildConversion,
IsChildIndexShow = codeGenConfigModel.TableRelations.Any(it => it.IsShowField),
IsInlineEditor = codeGenConfigModel.IsInlineEditor,
IndexDataType = codeGenConfigModel.IndexDataType,
GroupField = codeGenConfigModel.GroupField,
GroupShowField = codeGenConfigModel.GroupShowField,
IsImportData = codeGenConfigModel.IsImportData,
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))
Directory.CreateDirectory(dirPath);
File.WriteAllText(targetPathList[i], tResult, Encoding.UTF8);
}
controls = TemplateAnalysis.AnalysisTemplateData(formDataModel.fields);
codeGenMainTableConfigModel = codeGenConfigModel;
}
}
break;
case GeneratePatterns.MainBeltVice:
{
var link = await _repository.AsSugarClient().Queryable().FirstAsync(m => m.Id == templateEntity.DbLinkId && m.DeleteMark == null);
var targetLink = link ?? _databaseManager.GetTenantDbLink(_userManager.TenantId, _userManager.TenantDbName);
List tableRelationsList = new List();
// 副表表字段配置
List auxiliaryTableColumnList = new List();
var tableNo = 0;
tableName = tableRelation.Find(it => it.relationTable.Equals(string.Empty)).table;
// 生成副表
foreach (DbTableRelationModel? item in tableRelation.FindAll(it => it.typeId == "0"))
{
tableNo++;
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);
}
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;
targetPathList = CodeGenTargetPathHelper.BackendAuxiliaryTargetPathList(codeGenConfigModel.ClassName, fileName, templateEntity.WebType, templateEntity.Type, templateEntity.EnableFlow);
templatePathList = CodeGenTargetPathHelper.BackendAuxiliaryTemplatePathList("3-Auxiliary", templateEntity.WebType, templateEntity.Type, templateEntity.EnableFlow);
codeGenConfigModel.TableField.ForEach(items =>
{
items.ClassName = item.className;
});
// 生成副表相关文件
for (int i = 0; i < templatePathList.Count; i++)
{
var tContent = File.ReadAllText(templatePathList[i]);
var tResult = _viewEngine.RunCompileFromCached(tContent, new
{
BusName = codeGenConfigModel.BusName,
ClassName = codeGenConfigModel.ClassName,
NameSpace = formDataModel.areasName,
PrimaryKey = codeGenConfigModel.TableField.Find(it => it.PrimaryKey).ColumnName,
AuxiliaryTable = item.table.ParseToPascalCase(),
MainTable = tableName.ParseToPascalCase(),
MainClassName = codeGenConfigModel.ClassName,
OriginalMainTableName = codeGenConfigModel.OriginalMainTableName,
TableField = codeGenConfigModel.TableField,
IsUploading = codeGenConfigModel.IsUpload,
IsMapper = true,
WebType = templateEntity.WebType,
Type = templateEntity.Type,
PrimaryKeyPolicy = codeGenConfigModel.PrimaryKeyPolicy,
IsImportData = codeGenConfigModel.IsImportData,
EnableFlow = codeGenConfigModel.EnableFlow,
});
var dirPath = new DirectoryInfo(targetPathList[i]).Parent.FullName;
if (!Directory.Exists(dirPath))
Directory.CreateDirectory(dirPath);
File.WriteAllText(targetPathList[i], tResult, Encoding.UTF8);
}
tableRelationsList.Add(new CodeGenTableRelationsModel
{
ClassName = codeGenConfigModel.ClassName,
OriginalTableName = item.table,
RelationTable = item.relationTable,
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,
TableComment = item.tableName,
TableNo = tableNo,
IsConversion = codeGenConfigModel.TableField.Any(it => it.IsConversion.Equals(true)),
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));
}
// 生成主表
foreach (DbTableRelationModel? item in tableRelation.FindAll(it => it.typeId == "1"))
{
var fieldList = _databaseManager.GetFieldList(targetLink, tableName);
if (fieldList.Count == 0) throw Oops.Oh(ErrorCode.D2106);
// 开启乐观锁
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 (templateEntity.WebType)
{
case 1:
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;
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
{
NameSpace = codeGenConfigModel.NameSpace,
BusName = codeGenConfigModel.BusName,
ClassName = codeGenConfigModel.ClassName,
PrimaryKey = codeGenConfigModel.PrimaryKey,
LowerPrimaryKey = codeGenConfigModel.LowerPrimaryKey,
OriginalPrimaryKey = codeGenConfigModel.OriginalPrimaryKey,
MainTable = codeGenConfigModel.MainTable,
LowerMainTable = codeGenConfigModel.LowerMainTable,
OriginalMainTableName = codeGenConfigModel.OriginalMainTableName,
hasPage = codeGenConfigModel.hasPage && !codeGenConfigModel.IndexDataType.Equals(3),
Function = codeGenConfigModel.Function,
TableField = codeGenConfigModel.TableField,
TableFieldCount = codeGenConfigModel.TableField.FindAll(it => !it.PrimaryKey && it.jnpfKey != null).Count(),
DefaultSidx = codeGenConfigModel.DefaultSidx,
IsExport = codeGenConfigModel.IsExport,
IsBatchRemove = codeGenConfigModel.IsBatchRemove,
IsUploading = codeGenConfigModel.IsUpload,
IsTableRelations = codeGenConfigModel.IsTableRelations,
IsMapper = codeGenConfigModel.IsMapper,
IsBillRule = codeGenConfigModel.IsBillRule,
DbLinkId = codeGenConfigModel.DbLinkId,
FormId = codeGenConfigModel.FormId,
WebType = codeGenConfigModel.WebType,
Type = codeGenConfigModel.Type,
EnableFlow = codeGenConfigModel.EnableFlow,
IsMainTable = codeGenConfigModel.IsMainTable,
EnCode = codeGenConfigModel.EnCode,
UseDataPermission = useDataPermission,
SearchControlNum = codeGenConfigModel.SearchControlNum,
IsAuxiliaryTable = codeGenConfigModel.IsAuxiliaryTable,
ExportField = codeGenConfigModel.ExportField,
ConfigId = _userManager.TenantId,
DBName = _userManager.TenantDbName,
PcUseDataPermission = pcColumnDesignModel.useDataPermission ? "true" : "false",
AppUseDataPermission = appColumnDesignModel.useDataPermission ? "true" : "false",
AuxiliayTableRelations = tableRelationsList,
FullName = codeGenConfigModel.FullName,
IsConversion = codeGenConfigModel.IsConversion,
IsMainConversion = codeGenConfigModel.TableField.Any(it => it.IsAuxiliary.Equals(false) && it.IsConversion.Equals(true)),
IsUpdate = codeGenConfigModel.TableField.Any(it => it.IsUpdate.Equals(true) && it.IsAuxiliary.Equals(false) && it.jnpfKey != null),
HasSuperQuery = codeGenConfigModel.HasSuperQuery,
PrimaryKeyPolicy = codeGenConfigModel.PrimaryKeyPolicy,
ConcurrencyLock = codeGenConfigModel.ConcurrencyLock,
IsUnique = codeGenConfigModel.IsUnique,
IsInlineEditor = codeGenConfigModel.IsInlineEditor,
IndexDataType = codeGenConfigModel.IndexDataType,
GroupField = codeGenConfigModel.GroupField,
GroupShowField = codeGenConfigModel.GroupShowField,
IsImportData = codeGenConfigModel.IsImportData,
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))
Directory.CreateDirectory(dirPath);
File.WriteAllText(targetPathList[i], tResult, Encoding.UTF8);
codeGenMainTableConfigModel = codeGenConfigModel;
}
}
}
break;
case GeneratePatterns.PrimarySecondary:
{
var link = await _repository.AsSugarClient().Queryable().FirstAsync(m => m.Id == templateEntity.DbLinkId && m.DeleteMark == null);
var targetLink = link ?? _databaseManager.GetTenantDbLink(_userManager.TenantId, _userManager.TenantDbName);
// 解析子表
var subTable = new List();
var secondaryTable = new List();
foreach (DbTableRelationModel? item in tableRelation.FindAll(it => it.typeId == "0"))
{
// 解析子表比副表效率
// 先获取出子表 其他的默认为副表
switch (controls.Any(it => it.__config__.jnpfKey.Equals(JnpfKeyConst.TABLE) && it.__config__.tableName.Equals(item.table)))
{
case true:
subTable.Add(item);
break;
default:
secondaryTable.Add(item);
break;
}
}
List subTableRelationsList = new List();
List secondaryTableRelationsList = new List();
int tableNo = 1;
// 已经区分子表与副表
// 生成子表
foreach (DbTableRelationModel? item in subTable)
{
var controlId = string.Empty;
var children = controls.Find(it => it.__config__.jnpfKey.Equals(JnpfKeyConst.TABLE) && it.__config__.tableName.Equals(item.table));
codeGenConfigModel.BusName = children.__config__.label;
codeGenConfigModel.ClassName = item.className;
controlId = children.__vModel__;
if (children != null) controls = children.__config__.children;
var fieldList = _databaseManager.GetFieldList(targetLink, item.table);
if (fieldList.Count == 0) throw Oops.Oh(ErrorCode.D2106);
// 默认主表开启自增子表也需要开启自增
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);
targetPathList = CodeGenTargetPathHelper.BackendChildTableTargetPathList(codeGenConfigModel.ClassName, fileName, templateEntity.WebType, templateEntity.Type, codeGenConfigModel.IsMapper, codeGenConfigModel.IsShowSubTableField);
templatePathList = CodeGenTargetPathHelper.BackendChildTableTemplatePathList("SubTable", templateEntity.WebType, templateEntity.Type, codeGenConfigModel.IsMapper, codeGenConfigModel.IsShowSubTableField);
// 生成子表相关文件
for (int i = 0; i < templatePathList.Count; i++)
{
var tContent = File.ReadAllText(templatePathList[i]);
var tResult = _viewEngine.RunCompileFromCached(tContent, new
{
BusName = codeGenConfigModel.BusName,
ClassName = codeGenConfigModel.ClassName,
NameSpace = formDataModel.areasName,
PrimaryKey = codeGenConfigModel.TableField.Find(it => it.PrimaryKey).ColumnName,
MainClassName = codeGenConfigModel.ClassName,
OriginalMainTableName = item.table,
TableField = codeGenConfigModel.TableField,
IsUploading = codeGenConfigModel.IsUpload,
IsMapper = codeGenConfigModel.IsMapper,
WebType = templateEntity.WebType,
Type = templateEntity.Type,
PrimaryKeyPolicy = codeGenConfigModel.PrimaryKeyPolicy,
IsImportData = codeGenConfigModel.IsImportData,
EnableFlow = templateEntity.EnableFlow == 0 ? false : true,
});
var dirPath = new DirectoryInfo(targetPathList[i]).Parent.FullName;
if (!Directory.Exists(dirPath))
Directory.CreateDirectory(dirPath);
File.WriteAllText(targetPathList[i], tResult, Encoding.UTF8);
}
subTableRelationsList.Add(new CodeGenTableRelationsModel
{
ClassName = item.className,
OriginalTableName = item.table,
RelationTable = item.relationTable,
TableName = item.table.ParseToPascalCase(),
PrimaryKey = codeGenConfigModel.TableField.Find(it => it.PrimaryKey).ColumnName,
TableField = codeGenConfigModel.TableField.Find(it => it.ForeignKeyField).ColumnName,
OriginalTableField = codeGenConfigModel.TableField.Find(it => it.ForeignKeyField).OriginalColumnName,
RelationField = item.relationField.ReplaceRegex("^f_", string.Empty).ParseToPascalCase(),
OriginalRelationField = item.relationField,
ControlTableComment = codeGenConfigModel.BusName,
TableComment = item.tableName,
ChilderColumnConfigList = codeGenConfigModel.TableField,
ChilderColumnConfigListCount = codeGenConfigModel.TableField.FindAll(it => !it.PrimaryKey && !it.ForeignKeyField && it.jnpfKey != null).Count(),
TableNo = tableNo,
ControlModel = controlId,
IsQueryWhether = codeGenConfigModel.TableField.Any(it => it.QueryWhether),
IsShowField = codeGenConfigModel.TableField.Any(it => it.IsShow),
IsUnique = codeGenConfigModel.TableField.Any(it => it.IsUnique),
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++;
// 还原全部控件
controls = TemplateAnalysis.AnalysisTemplateData(formDataModel.fields);
}
// 副表表字段配置
List auxiliaryTableColumnList = new List();
// 生成副表
foreach (DbTableRelationModel? item in secondaryTable)
{
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;
targetPathList = CodeGenTargetPathHelper.BackendAuxiliaryTargetPathList(codeGenConfigModel.ClassName, fileName, templateEntity.WebType, templateEntity.Type, templateEntity.EnableFlow);
templatePathList = CodeGenTargetPathHelper.BackendAuxiliaryTemplatePathList("3-Auxiliary", templateEntity.WebType, templateEntity.Type, templateEntity.EnableFlow);
codeGenConfigModel.TableField.ForEach(items => items.ClassName = item.className);
// 生成副表相关文件
for (int i = 0; i < templatePathList.Count; i++)
{
var tContent = File.ReadAllText(templatePathList[i]);
var tResult = _viewEngine.RunCompileFromCached(tContent, new
{
BusName = codeGenConfigModel.BusName,
ClassName = codeGenConfigModel.ClassName,
NameSpace = formDataModel.areasName,
PrimaryKey = codeGenConfigModel.TableField.Find(it => it.PrimaryKey).ColumnName,
AuxiliaryTable = item.table.ParseToPascalCase(),
MainTable = tableName.ParseToPascalCase(),
MainClassName = codeGenConfigModel.ClassName,
OriginalMainTableName = codeGenConfigModel.OriginalMainTableName,
TableField = codeGenConfigModel.TableField,
IsUploading = codeGenConfigModel.IsUpload,
IsMapper = true,
WebType = templateEntity.WebType,
Type = templateEntity.Type,
PrimaryKeyPolicy = codeGenConfigModel.PrimaryKeyPolicy,
IsImportData = codeGenConfigModel.IsImportData,
EnableFlow = codeGenConfigModel.EnableFlow,
});
var dirPath = new DirectoryInfo(targetPathList[i]).Parent.FullName;
if (!Directory.Exists(dirPath))
Directory.CreateDirectory(dirPath);
File.WriteAllText(targetPathList[i], tResult, Encoding.UTF8);
}
secondaryTableRelationsList.Add(new CodeGenTableRelationsModel
{
ClassName = codeGenConfigModel.ClassName,
OriginalTableName = item.table,
RelationTable = item.relationTable,
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,
TableComment = item.tableName,
TableNo = tableNo,
IsConversion = codeGenConfigModel.TableField.Any(it => it.IsConversion.Equals(true)),
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));
}
// 解析主表
foreach (DbTableRelationModel? item in tableRelation.FindAll(it => it.typeId == "1"))
{
var fieldList = _databaseManager.GetFieldList(targetLink, item.table);
if (fieldList.Count == 0) throw Oops.Oh(ErrorCode.D2106);
// 开启乐观锁
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.PrimarySecondaryBackEnd(item.table, fieldList, auxiliaryTableColumnList, controls, templateEntity);
codeGenConfigModel.IsMapper = true;
codeGenConfigModel.BusName = tableRelation.Find(it => it.relationTable.Equals("")).tableName;
codeGenConfigModel.TableRelations = subTableRelationsList;
codeGenConfigModel.IsChildConversion = subTableRelationsList.Any(it => it.IsConversion);
switch (templateEntity.WebType)
{
case 1:
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;
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;
}
// 生成后端文件
for (int i = 0; i < templatePathList.Count; i++)
{
string tContent = File.ReadAllText(templatePathList[i]);
string tResult = _viewEngine.RunCompileFromCached(tContent, new
{
NameSpace = codeGenConfigModel.NameSpace,
BusName = codeGenConfigModel.BusName,
ClassName = codeGenConfigModel.ClassName,
PrimaryKey = codeGenConfigModel.PrimaryKey,
LowerPrimaryKey = codeGenConfigModel.LowerPrimaryKey,
OriginalPrimaryKey = codeGenConfigModel.OriginalPrimaryKey,
MainTable = codeGenConfigModel.MainTable,
LowerMainTable = codeGenConfigModel.LowerMainTable,
OriginalMainTableName = codeGenConfigModel.OriginalMainTableName,
hasPage = codeGenConfigModel.hasPage && !codeGenConfigModel.IndexDataType.Equals(3),
Function = codeGenConfigModel.Function,
TableField = codeGenConfigModel.TableField,
TableFieldCount = codeGenConfigModel.TableField.FindAll(it => !it.PrimaryKey && it.jnpfKey != null).Count(),
DefaultSidx = codeGenConfigModel.DefaultSidx,
IsExport = codeGenConfigModel.IsExport,
IsBatchRemove = codeGenConfigModel.IsBatchRemove,
IsUploading = codeGenConfigModel.IsUpload,
IsTableRelations = codeGenConfigModel.IsTableRelations,
IsMapper = codeGenConfigModel.IsMapper,
IsBillRule = codeGenConfigModel.IsBillRule,
DbLinkId = codeGenConfigModel.DbLinkId,
FormId = codeGenConfigModel.FormId,
WebType = codeGenConfigModel.WebType,
Type = codeGenConfigModel.Type,
EnableFlow = codeGenConfigModel.EnableFlow,
IsMainTable = codeGenConfigModel.IsMainTable,
EnCode = codeGenConfigModel.EnCode,
UseDataPermission = useDataPermission,
SearchControlNum = codeGenConfigModel.SearchControlNum,
IsAuxiliaryTable = codeGenConfigModel.IsAuxiliaryTable,
ExportField = codeGenConfigModel.ExportField,
TableRelations = codeGenConfigModel.TableRelations,
ConfigId = _userManager.TenantId,
DBName = _userManager.TenantDbName,
PcUseDataPermission = pcColumnDesignModel.useDataPermission ? "true" : "false",
AppUseDataPermission = appColumnDesignModel.useDataPermission ? "true" : "false",
AuxiliayTableRelations = secondaryTableRelationsList,
FullName = codeGenConfigModel.FullName,
IsConversion = codeGenConfigModel.IsConversion,
HasSuperQuery = codeGenConfigModel.HasSuperQuery,
PrimaryKeyPolicy = codeGenConfigModel.PrimaryKeyPolicy,
ConcurrencyLock = codeGenConfigModel.ConcurrencyLock,
IsUpdate = codeGenConfigModel.TableField.Any(it => it.IsUpdate.Equals(true) && it.IsAuxiliary.Equals(false) && it.jnpfKey != null),
IsUnique = codeGenConfigModel.IsUnique || codeGenConfigModel.TableRelations.Any(it => it.IsUnique),
IsChildConversion = codeGenConfigModel.IsChildConversion,
IsChildIndexShow = codeGenConfigModel.TableRelations.Any(it => it.IsShowField),
IsInlineEditor = codeGenConfigModel.IsInlineEditor,
IndexDataType = codeGenConfigModel.IndexDataType,
GroupField = codeGenConfigModel.GroupField,
GroupShowField = codeGenConfigModel.GroupShowField,
IsImportData = codeGenConfigModel.IsImportData,
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))
Directory.CreateDirectory(dirPath);
File.WriteAllText(targetPathList[i], tResult, Encoding.UTF8);
codeGenMainTableConfigModel = codeGenConfigModel;
}
}
}
break;
default:
{
tableName = tableRelation.FirstOrDefault().table;
var link = await _repository.AsSugarClient().Queryable().FirstAsync(m => m.Id == templateEntity.DbLinkId && m.DeleteMark == null);
var targetLink = link ?? _databaseManager.GetTenantDbLink(_userManager.TenantId, _userManager.TenantDbName);
// 获取表结构
var fieldList = _databaseManager.GetFieldList(targetLink, tableName);
if (fieldList.Count == 0) throw Oops.Oh(ErrorCode.D2106);
// 开启乐观锁
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.WebType)
{
case 1:
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;
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("1-SingleTable", 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("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;
}
// 生成后端文件
for (var i = 0; i < templatePathList.Count; i++)
{
var tContent = File.ReadAllText(templatePathList[i]);
var tResult = _viewEngine.RunCompileFromCached(tContent, new
{
NameSpace = codeGenConfigModel.NameSpace,
BusName = codeGenConfigModel.BusName,
ClassName = codeGenConfigModel.ClassName,
PrimaryKey = codeGenConfigModel.PrimaryKey,
LowerPrimaryKey = codeGenConfigModel.LowerPrimaryKey,
OriginalPrimaryKey = codeGenConfigModel.OriginalPrimaryKey,
MainTable = codeGenConfigModel.MainTable,
LowerMainTable = codeGenConfigModel.LowerMainTable,
OriginalMainTableName = codeGenConfigModel.OriginalMainTableName,
hasPage = codeGenConfigModel.hasPage && !codeGenConfigModel.IndexDataType.Equals(3),
Function = codeGenConfigModel.Function,
TableField = codeGenConfigModel.TableField,
TableFieldCount = codeGenConfigModel.TableField.FindAll(it => !it.PrimaryKey && it.jnpfKey != null).Count(),
DefaultSidx = codeGenConfigModel.DefaultSidx,
IsExport = codeGenConfigModel.IsExport,
IsBatchRemove = codeGenConfigModel.IsBatchRemove,
IsUploading = codeGenConfigModel.IsUpload,
IsTableRelations = codeGenConfigModel.IsTableRelations,
IsMapper = codeGenConfigModel.IsMapper,
IsSystemControl = codeGenConfigModel.IsSystemControl,
IsUpdate = codeGenConfigModel.IsUpdate,
IsBillRule = codeGenConfigModel.IsBillRule,
DbLinkId = codeGenConfigModel.DbLinkId,
FormId = codeGenConfigModel.FormId,
WebType = codeGenConfigModel.WebType,
Type = codeGenConfigModel.Type,
EnableFlow = codeGenConfigModel.EnableFlow,
EnCode = codeGenConfigModel.EnCode,
UseDataPermission = useDataPermission,
SearchControlNum = codeGenConfigModel.SearchControlNum,
ExportField = codeGenConfigModel.ExportField,
ConfigId = _userManager.TenantId,
DBName = _userManager.TenantDbName,
PcUseDataPermission = pcColumnDesignModel.useDataPermission ? "true" : "false",
AppUseDataPermission = appColumnDesignModel.useDataPermission ? "true" : "false",
FullName = codeGenConfigModel.FullName,
IsConversion = codeGenConfigModel.IsConversion,
HasSuperQuery = codeGenConfigModel.HasSuperQuery,
PrimaryKeyPolicy = codeGenConfigModel.PrimaryKeyPolicy,
ConcurrencyLock = codeGenConfigModel.ConcurrencyLock,
IsUnique = codeGenConfigModel.IsUnique,
IsInlineEditor = codeGenConfigModel.IsInlineEditor,
IndexDataType = codeGenConfigModel.IndexDataType,
GroupField = codeGenConfigModel.GroupField,
GroupShowField = codeGenConfigModel.GroupShowField,
IsImportData = codeGenConfigModel.IsImportData,
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))
Directory.CreateDirectory(dirPath);
File.WriteAllText(targetPathList[i], tResult, Encoding.UTF8);
}
codeGenMainTableConfigModel = codeGenConfigModel;
}
break;
}
// 强行将文件夹名称定义成 下载代码中输出配置的功能类名
tableName = formDataModel.className.FirstOrDefault();
// 还原模板
controls = TemplateAnalysis.AnalysisTemplateData(formDataModel.fields);
// 生成前端
await GenFrondEnd(tableName.ToLowerCase(), codeGenConfigModel.DefaultSidx, formDataModel, controls, codeGenMainTableConfigModel.TableField, templateEntity, fileName);
}
///
/// 预览代码.
///
///
///
private List> PriviewCode(string codePath)
{
var dataList = FileHelper.GetAllFiles(codePath);
List> datas = new List>();
List> allDatas = new List>();
foreach (var item in dataList)
{
Dictionary data = new Dictionary();
var content = FileHelper.FileToString(item.FullName);
switch (item.Extension)
{
case ".cs":
{
string fileName = item.FullName.ToLower();
if (fileName.Contains("listqueryinput") || fileName.Contains("crinput") || fileName.Contains("upinput") || fileName.Contains("upoutput") || fileName.Contains("listoutput") || fileName.Contains("infooutput") || fileName.Contains("detailoutput") || fileName.Contains("inlineeditoroutput"))
{
data.Add("folderName", "dto");
}
else if (fileName.Contains("mapper"))
{
data.Add("folderName", "mapper");
}
else if (fileName.Contains("entity"))
{
data.Add("folderName", "entity");
}
else
{
data.Add("folderName", "dotnet");
}
data.Add("fileName", item.Name);
data.Add("fileContent", content);
data.Add("fileType", item.Extension.Replace(".", string.Empty));
datas.Add(data);
}
break;
case ".fff":
{
data.Add("folderName", "fff");
data.Add("id", SnowflakeIdHelper.NextId());
data.Add("fileName", item.Name);
data.Add("fileContent", content);
data.Add("fileType", item.Extension.Replace(".", string.Empty));
datas.Add(data);
}
break;
case ".vue":
{
if (item.FullName.ToLower().Contains("app"))
data.Add("folderName", "app");
else if (item.FullName.ToLower().Contains("pc"))
data.Add("folderName", "web");
data.Add("id", SnowflakeIdHelper.NextId());
data.Add("fileName", item.Name);
data.Add("fileContent", content);
data.Add("fileType", item.Extension.Replace(".", string.Empty));
datas.Add(data);
}
break;
case ".js":
{
if (item.FullName.ToLower().Contains("app"))
data.Add("folderName", "app");
else if (item.FullName.ToLower().Contains("pc"))
data.Add("folderName", "web");
data.Add("id", SnowflakeIdHelper.NextId());
data.Add("fileName", item.Name);
data.Add("fileContent", content);
data.Add("fileType", item.Extension.Replace(".", string.Empty));
datas.Add(data);
}
break;
}
}
// datas 集合去重
foreach (var item in datas.GroupBy(d => d["folderName"]).Select(d => d.First()).OrderBy(d => d["folderName"]).ToList())
{
Dictionary dataMap = new Dictionary();
dataMap["fileName"] = item["folderName"];
dataMap["id"] = SnowflakeIdHelper.NextId();
dataMap["children"] = datas.FindAll(d => d["folderName"] == item["folderName"]);
allDatas.Add(dataMap);
}
return allDatas;
}
///
/// 判断生成模式.
///
/// 1-纯主表、2-主带子、3-主带副、4-主带副与子.
private GeneratePatterns JudgmentGenerationModel(List tableRelation, List controls)
{
// 默认纯主表
var codeModel = GeneratePatterns.PrimaryTable;
// 找副表控件
if (tableRelation.Count > 1 && controls.Any(x => x.__vModel__.Contains("_jnpf_")) && controls.Any(it => it.__config__.jnpfKey.Equals(JnpfKeyConst.TABLE)))
codeModel = GeneratePatterns.PrimarySecondary;
else if (tableRelation.Count > 1 && controls.Any(x => x.__vModel__.Contains("_jnpf_")))
codeModel = GeneratePatterns.MainBeltVice;
else if (tableRelation.Count > 1 && controls.Any(it => it.__config__.jnpfKey.Equals(JnpfKeyConst.TABLE)))
codeModel = GeneratePatterns.MainBelt;
return codeModel;
}
///
/// 生成前端.
///
/// 表名称.
/// 默认排序.
/// 表单JSON包.
/// 移除布局控件后的控件列表.
/// 表字段.
/// 模板实体.
/// 文件夹名称.
private async Task GenFrondEnd(string tableName, string defaultSidx, FormDataModel formDataModel, List controls, List tableColumns, VisualDevEntity templateEntity, string fileName)
{
var categoryName = (await _dictionaryDataService.GetInfo(templateEntity.Category)).EnCode;
List targetPathList = new List();
List templatePathList = new List();
FrontEndGenConfigModel frondEndGenConfig = new FrontEndGenConfigModel();
// 前端生成 APP与PC合并 4-pc,5-app
foreach (int logic in new List { 4, 5 })
{
// 每次循环前重新定义表单数据
formDataModel = templateEntity.FormData.ToObjectOld();
frondEndGenConfig = CodeGenWay.SingleTableFrontEnd(logic, formDataModel, controls, tableColumns, templateEntity);
switch (templateEntity.Type)
{
case 3:
{
targetPathList = CodeGenTargetPathHelper.FlowFrontEndTargetPathList(logic, tableName, fileName);
templatePathList = CodeGenTargetPathHelper.FlowFrontEndTemplatePathList(logic);
}
break;
default:
{
switch (logic)
{
case 4:
var columnDesignModel = templateEntity.ColumnData?.ToObject();
var hasSuperQuery = false;
switch (templateEntity.WebType)
{
case 1:
hasSuperQuery = false;
frondEndGenConfig.Type = 1;
break;
default:
hasSuperQuery = columnDesignModel.hasSuperQuery;
break;
}
switch (frondEndGenConfig.Type)
{
case 4:
targetPathList = CodeGenTargetPathHelper.FrontEndInlineEditorTargetPathList(tableName, fileName, templateEntity.EnableFlow, frondEndGenConfig.IsDetail, hasSuperQuery);
templatePathList = CodeGenTargetPathHelper.FrontEndInlineEditorTemplatePathList(templateEntity.EnableFlow, frondEndGenConfig.IsDetail, hasSuperQuery);
break;
default:
targetPathList = CodeGenTargetPathHelper.FrontEndTargetPathList(tableName, fileName, templateEntity.WebType, templateEntity.EnableFlow, frondEndGenConfig.IsDetail, hasSuperQuery);
templatePathList = CodeGenTargetPathHelper.FrontEndTemplatePathList(templateEntity.WebType, templateEntity.EnableFlow, frondEndGenConfig.IsDetail, hasSuperQuery);
break;
}
break;
case 5:
switch (templateEntity.EnableFlow)
{
case 0:
targetPathList = CodeGenTargetPathHelper.AppFrontEndTargetPathList(tableName, fileName, templateEntity.WebType, frondEndGenConfig.IsDetail);
templatePathList = CodeGenTargetPathHelper.AppFrontEndTemplatePathList(templateEntity.WebType, frondEndGenConfig.IsDetail);
break;
case 1:
targetPathList = CodeGenTargetPathHelper.AppFrontEndWorkflowTargetPathList(tableName, fileName, templateEntity.WebType);
templatePathList = CodeGenTargetPathHelper.AppFrontEndWorkflowTemplatePathList(templateEntity.WebType);
break;
}
break;
}
}
break;
}
for (int i = 0; i < templatePathList.Count; i++)
{
string tContent = File.ReadAllText(templatePathList[i]);
var tResult = _viewEngine.RunCompileFromCached(tContent, new
{
NameSpace = frondEndGenConfig.NameSpace,
ClassName = frondEndGenConfig.ClassName,
FormRef = frondEndGenConfig.FormRef,
FormModel = frondEndGenConfig.FormModel,
Size = frondEndGenConfig.Size,
LabelPosition = frondEndGenConfig.LabelPosition,
LabelWidth = frondEndGenConfig.LabelWidth,
FormRules = frondEndGenConfig.FormRules,
GeneralWidth = frondEndGenConfig.GeneralWidth,
FullScreenWidth = frondEndGenConfig.FullScreenWidth,
DrawerWidth = frondEndGenConfig.DrawerWidth,
FormStyle = frondEndGenConfig.FormStyle,
Type = frondEndGenConfig.Type,
TreeRelation = frondEndGenConfig.TreeRelation,
TreeTitle = frondEndGenConfig.TreeTitle,
TreePropsValue = frondEndGenConfig.TreePropsValue,
TreeDataSource = frondEndGenConfig.TreeDataSource,
TreeDictionary = frondEndGenConfig.TreeDictionary,
TreePropsUrl = frondEndGenConfig.TreePropsUrl,
TreePropsLabel = frondEndGenConfig.TreePropsLabel,
TreePropsChildren = frondEndGenConfig.TreePropsChildren,
IsTreeRelationMultiple = frondEndGenConfig.IsTreeRelationMultiple,
IsExistQuery = frondEndGenConfig.IsExistQuery,
PrimaryKey = frondEndGenConfig.PrimaryKey,
FormList = frondEndGenConfig.FormList,
PopupType = frondEndGenConfig.PopupType,
SearchColumnDesign = frondEndGenConfig.SearchColumnDesign,
TopButtonDesign = frondEndGenConfig.TopButtonDesign,
ColumnButtonDesign = frondEndGenConfig.ColumnButtonDesign,
ColumnDesign = frondEndGenConfig.ColumnDesign,
OptionsList = frondEndGenConfig.OptionsList,
IsBatchRemoveDel = frondEndGenConfig.IsBatchRemoveDel,
IsBatchPrint = frondEndGenConfig.IsBatchPrint,
PrintIds = frondEndGenConfig.PrintIds,
IsDownload = frondEndGenConfig.IsDownload,
IsRemoveDel = frondEndGenConfig.IsRemoveDel,
IsDetail = frondEndGenConfig.IsDetail,
IsEdit = frondEndGenConfig.IsEdit,
IsAdd = frondEndGenConfig.IsAdd,
IsSort = frondEndGenConfig.IsSort,
IsUpload = frondEndGenConfig.IsUpload,
FormAllContols = frondEndGenConfig.FormAllContols,
CancelButtonText = frondEndGenConfig.CancelButtonText,
ConfirmButtonText = frondEndGenConfig.ConfirmButtonText,
UseBtnPermission = frondEndGenConfig.UseBtnPermission,
UseColumnPermission = frondEndGenConfig.UseColumnPermission,
UseFormPermission = frondEndGenConfig.UseFormPermission,
DefaultSidx = defaultSidx,
WebType = templateEntity.Type == 3 ? templateEntity.Type : templateEntity.WebType,
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,
DetailTitleName = frondEndGenConfig.ColumnButtonDesign?.Find(it => it.IsDetail.Equals(true))?.Label,
PageSize = frondEndGenConfig.PageSize,
Sort = frondEndGenConfig.Sort,
HasPrintBtn = frondEndGenConfig.HasPrintBtn,
PrintButtonText = frondEndGenConfig.PrintButtonText,
PrintId = frondEndGenConfig.PrintId,
EnCode = templateEntity.EnCode,
FormId = templateEntity.Id,
FullName = templateEntity.FullName,
Category = categoryName,
Tables = templateEntity.Tables.ToJsonString(),
DbLinkId = templateEntity.DbLinkId,
MianTable = tableName,
PropertyJson = frondEndGenConfig.PropertyJson.ToJsonString(),
CreatorTime = DateTime.Now.ParseToUnixTime(),
CreatorUserId = _userManager.UserId,
IsChildDataTransfer = frondEndGenConfig.IsChildDataTransfer,
IsChildTableQuery = frondEndGenConfig.IsChildTableQuery,
IsChildTableShow = frondEndGenConfig.IsChildTableShow,
ColumnList = frondEndGenConfig.ColumnList,
HasSuperQuery = frondEndGenConfig.HasSuperQuery,
ColumnOptions = frondEndGenConfig.ColumnOptions,
IsInlineEditor = frondEndGenConfig.IsInlineEditor,
IndexDataType = frondEndGenConfig.IndexDataType,
GroupField = frondEndGenConfig.GroupField,
GroupShowField = frondEndGenConfig.GroupShowField,
PrimaryKeyPolicy = frondEndGenConfig.PrimaryKeyPolicy,
IsRelationForm = frondEndGenConfig.IsRelationForm,
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("JNPF.VisualDev.Engine");
});
var dirPath = new DirectoryInfo(targetPathList[i]).Parent.FullName;
if (!Directory.Exists(dirPath))
Directory.CreateDirectory(dirPath);
File.WriteAllText(targetPathList[i], tResult, Encoding.UTF8);
}
}
}
#endregion
}