using NCC.Common.Configuration;
using NCC.Common.Core.Manager;
using NCC.Common.Enum;
using NCC.Common.Extension;
using NCC.Common.Helper;
using NCC.Common.Util;
using NCC.DataEncryption;
using NCC.Dependency;
using NCC.DynamicApiController;
using NCC.FriendlyException;
using NCC.System.Entitys.System;
using NCC.System.Interfaces.System;
using NCC.ViewEngine;
using NCC.VisualDev.Entitys;
using NCC.VisualDev.Entitys.Dto.VisualDev;
using NCC.VisualDev.Entitys.Model.CodeGen;
using NCC.VisualDev.Entitys.Model.VisualDevModelData;
using NCC.VisualDev.Run.Interfaces;
using Microsoft.AspNetCore.Mvc;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Yitter.IdGenerator;
namespace NCC.VisualDev
{
///
/// 可视化开发基础
///
[ApiDescriptionSettings(Tag = "VisualDev", Name = "Generater", Order = 175)]
[Route("api/visualdev/[controller]")]
public class CodeGenService : IDynamicApiController, ITransient
{
private readonly ISqlSugarRepository _visualDevRepository;
private readonly IViewEngine _viewEngine;
private readonly IUserManager _userManager;
private readonly IDbLinkService _dbLinkService;
private readonly IDataBaseService _databaseService;
private readonly IRunService _runService;
private readonly IDictionaryDataService _dictionaryDataService;
private int active = 1;
///
/// 初始化一个类型的新实例
///
public CodeGenService(ISqlSugarRepository visualDevRepository, IDataBaseService databaseService, IDbLinkService dbLinkService, IRunService runService, IViewEngine viewEngine, IUserManager userManager, IDictionaryDataService dictionaryDataService)
{
_visualDevRepository = visualDevRepository;
_viewEngine = viewEngine;
_userManager = userManager;
_databaseService = databaseService;
_dbLinkService = dbLinkService;
_runService = runService;
_dictionaryDataService = dictionaryDataService;
}
#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 userInfo = _userManager.GetUserInfo();
var templateEntity = await _visualDevRepository.FirstOrDefaultAsync(v => v.Id == id && v.DeleteMark == null);
_ = templateEntity ?? throw NCCException.Oh(ErrorCode.COM1005);
_ = templateEntity.Tables ?? throw NCCException.Oh(ErrorCode.D2100);
var model = TemplateKeywordsHelper.ReplaceKeywords(templateEntity.FormData).ToObject();
if (templateEntity.Type == 3)
{
downloadCodeForm.module = "WorkFlowForm";
}
model.className = downloadCodeForm.className.ToPascalCase();
model.areasName = downloadCodeForm.module;
string fileName = templateEntity.FullName;
//判断子表名称
var childTb = new List();
if (!downloadCodeForm.subClassName.IsNullOrEmpty())
{
childTb = new List(downloadCodeForm.subClassName.Split(','));
}
//子表名称去重
HashSet set = new HashSet(childTb);
templateEntity.FormData = model.ToJson();
bool result = childTb.Count == set.Count ? true : false;
if (!result)
{
throw NCCException.Oh(ErrorCode.D2101);
}
await this.TemplatesDataAggregation(fileName, templateEntity);
string randPath = Path.Combine(FileVariable.GenerateCodePath, fileName);
string downloadPath = randPath + ".zip";
//判断是否存在同名称文件
if (File.Exists(downloadPath))
{
File.Delete(downloadPath);
}
ZipFile.CreateFromDirectory(randPath, downloadPath);
var downloadFileName = userInfo.Id + "|" + fileName + ".zip|codeGenerator";
return new { name = fileName, url = "/api/File/Download?encryption=" + DESCEncryption.Encrypt(downloadFileName, "NCC") };
}
///
/// 预览代码
///
///
///
///
[HttpPost("{id}/Actions/CodePreview")]
public async Task CodePreview(string id, [FromBody] DownloadCodeFormInput downloadCodeForm)
{
var userInfo = _userManager.GetUserInfo();
var templateEntity = await _visualDevRepository.FirstOrDefaultAsync(v => v.Id == id && v.DeleteMark == null);
_ = templateEntity ?? throw NCCException.Oh(ErrorCode.COM1005);
_ = templateEntity.Tables ?? throw NCCException.Oh(ErrorCode.D2100);
var model = TemplateKeywordsHelper.ReplaceKeywords(templateEntity.FormData).ToObject();
model.className = downloadCodeForm.className.ToPascalCase();
model.areasName = downloadCodeForm.module;
string fileName = YitIdHelper.NextId().ToString();
//判断子表名称
var childTb = new List();
//子表名称去重
HashSet set = new HashSet(childTb);
templateEntity.FormData = model.ToJson();
bool result = childTb.Count == set.Count ? true : false;
if (!result)
{
throw NCCException.Oh(ErrorCode.D2101);
}
await this.TemplatesDataAggregation(fileName, templateEntity);
string randPath = Path.Combine(FileVariable.GenerateCodePath, fileName);
var dataList = this.PriviewCode(randPath, templateEntity.Type.ToInt(), templateEntity.WebType.ToInt());
if (dataList == null && dataList.Count == 0)
throw NCCException.Oh(ErrorCode.D2102);
return new { list = dataList };
}
#endregion
#region PublicMethod
///
/// 模板数据聚合
///
/// 生成ZIP文件名
/// 模板实体
///
public async Task TemplatesDataAggregation(string fileName, VisualDevEntity templateEntity)
{
var categoryName = (await _dictionaryDataService.GetInfo(templateEntity.Category)).EnCode;
var funcTablePrimaryKey = string.Empty;
var tableRelation = templateEntity.Tables.ToObject>();
var columnDesignModel = templateEntity.ColumnData.ToObject();
var formDataModel = templateEntity.FormData.ToObject();
var controls = _runService.TemplateDataConversion(formDataModel.fields);
var targetPathList = new List();
var templatePathList = new List();
//主表列配置
var mainTableColumnConfigList = new List();
#region 后端
//后端文件生成
foreach (var item in tableRelation)
{
int tableNum = 0;
if (item.relationTable != "")
{
//获取出子表控件值
var children = controls.Find(f => f.__vModel__.Contains("Field") && f.__config__.tableName.Equals(item.table));
if (children != null) controls = children.__config__.children;
tableNum++;
}
var tableName = item.table;
var link = await _dbLinkService.GetInfo(templateEntity.DbLinkId);
var table = _databaseService.GetFieldListByNoAsync(link, tableName);
var tableColumnList = new List();
foreach (var column in table)
{
var field = column.field.Replace("F_", "").Replace("f_", "").ToPascalCase().LowerFirstChar();
var columnControlKey = controls.Find(c => c.__vModel__ == field);
tableColumnList.Add(new TableColumnConfigModel()
{
ColumnName = column.field.Replace("F_", "").Replace("f_", "").ToPascalCase(),
Alias = column.field,
OriginalColumnName = column.field,
ColumnComment = column.fieldName,
DataType = column.dataType,
NetType = CodeGenUtil.ConvertDataType(column.dataType),
PrimaryKey = column.primaryKey.ToBool(),
QueryWhether = columnDesignModel != null ? GetIsColumnQueryWhether(columnDesignModel.searchList, field) : false,
QueryType = columnDesignModel != null ? GetColumnQueryType(columnDesignModel.searchList, field) : 0,
IsShow = columnDesignModel != null ? GetIsShowColumn(columnDesignModel.columnList, field) : false,
IsMultiple = GetIsMultipleColumn(controls, field),
NCCKey = columnControlKey != null ? columnControlKey.__config__.NCCKey : null,
Rule = columnControlKey != null ? columnControlKey.__config__.rule : null
});
}
if (item.relationTable == "")
{
mainTableColumnConfigList = tableColumnList;
}
var IsUplpad = tableColumnList.Find(it => it.NCCKey != null && (it.NCCKey.Equals("uploadImg") || it.NCCKey.Equals("uploadFz")));
var IsExport = columnDesignModel != null && columnDesignModel.btnsList != null && templateEntity.WebType != 1 ? columnDesignModel.btnsList.Find(it => it.value == "download") : null;
var IsMapper = tableColumnList.Find(it => it.NCCKey != null && (it.NCCKey.Equals("checkbox") || it.NCCKey.Equals("cascader") || it.NCCKey.Equals("address") || it.NCCKey.Equals("uploadImg") || it.NCCKey.Equals("uploadFz") || (it.NCCKey.Equals("select") && it.IsMultiple == true)));
var isBillRule = templateEntity.FormData.Contains("billRule");
var isFlowId = tableColumnList.Find(it => it.ColumnName.ToLower().Equals("flowid"));
var configModel = new CodeGenConfigModel();
if (templateEntity.Type == 4 || templateEntity.Type == 5)
{
//为生成功能方法模块添加数据
switch (templateEntity.Type)
{
case 4:
switch (templateEntity.WebType)
{
case 1:
columnDesignModel = new ColumnDesignModel();
columnDesignModel.btnsList = new List();
columnDesignModel.btnsList.Add(new ButtonConfigModel()
{
value = "add",
icon = "el-icon-plus",
label = "新增",
});
break;
case 2:
break;
case 3:
break;
}
break;
case 5:
switch (templateEntity.WebType)
{
case 1:
columnDesignModel = new ColumnDesignModel();
columnDesignModel.btnsList = new List();
columnDesignModel.btnsList.Add(new ButtonConfigModel()
{
value = "add",
icon = "el-icon-plus",
label = "新增",
});
break;
case 2:
case 3:
columnDesignModel.btnsList = new List();
columnDesignModel.columnBtnsList = new List();
columnDesignModel.btnsList.Add(new ButtonConfigModel()
{
value = "add",
icon = "el-icon-plus",
label = "新增",
});
columnDesignModel.columnBtnsList.Add(new ButtonConfigModel()
{
value = "edit",
icon = "el-icon-edit",
label = "编辑",
});
columnDesignModel.columnBtnsList.Add(new ButtonConfigModel()
{
value = "remove",
icon = "el-icon-delete",
label = "删除",
});
break;
}
break;
default:
break;
}
configModel = new CodeGenConfigModel()
{
NameSpace = formDataModel.areasName,
OriginalMainTableName = item.table,
PrimaryKey = tableColumnList.Find(t => t.PrimaryKey == true).ColumnName,
MainTable = item.table.ToPascalCase(),
BusName = templateEntity.FullName,
ClassName = formDataModel.className,
hasPage = columnDesignModel != null ? columnDesignModel.hasPage : false,
Function = GetCodeGenFunctionList(columnDesignModel.hasPage, columnDesignModel.btnsList, columnDesignModel.columnBtnsList, templateEntity.WebType.ToInt()),
TableField = tableColumnList,
TableRelations = GetCodeGenTableRelationList(tableRelation, item.table, link, controls.FindAll(it => it.__vModel__.Contains("tableField"))),
};
//为后续程序能正常运行还原数据
switch (templateEntity.Type)
{
case 4:
switch (templateEntity.WebType)
{
case 1:
columnDesignModel = null;
break;
case 2:
break;
case 3:
break;
}
break;
case 5:
switch (templateEntity.WebType)
{
case 1:
columnDesignModel.btnsList = null;
break;
case 2:
columnDesignModel.btnsList = null;
columnDesignModel.columnBtnsList = null;
break;
case 3:
columnDesignModel.btnsList = null;
columnDesignModel.columnBtnsList = null;
break;
}
break;
default:
break;
}
}
else if (templateEntity.Type == 3)
{
configModel = new CodeGenConfigModel()
{
NameSpace = formDataModel.areasName,
OriginalMainTableName = item.table,
PrimaryKey = tableColumnList.Find(t => t.PrimaryKey == true).ColumnName,
MainTable = item.table.ToPascalCase(),
BusName = templateEntity.FullName,
ClassName = formDataModel.className,
hasPage = columnDesignModel != null ? columnDesignModel.hasPage : false,
Function = GetCodeGenFlowFunctionList(),
TableField = tableColumnList,
TableRelations = GetCodeGenTableRelationList(tableRelation, item.table, link, controls.FindAll(it => it.__vModel__.Contains("tableField"))),
};
}
funcTablePrimaryKey = tableColumnList.Find(t => t.PrimaryKey == true).ColumnName;
var isChildTable = item.relationTable.IsNullOrEmpty() ? false : true;
//Web表单&||app代码生成器
if (templateEntity.Type == 4 || templateEntity.Type == 5)
{
if (!isChildTable)
{
targetPathList = GetMainTableBackendTargetPathList(item, fileName, templateEntity.WebType.ToInt());
templatePathList = GetMainTableBackendTemplatePathList(templateEntity.WebType.ToInt());
}
else
{
targetPathList = GetRelationTableBackendTargetPathList(item, fileName, templateEntity.WebType.ToInt());
templatePathList = GetRelationTableBackendTemplatePathList(templateEntity.WebType.ToInt());
}
}
//流程表单
else if (templateEntity.Type == 3)
{
if (!isChildTable)
{
targetPathList = GetFlowMainTableBackendTargetPathList(item, fileName);
templatePathList = GetFlowMainTableBackendTemplatePathList();
}
else
{
targetPathList = GetFlowRelationTableBackendTargetPathList(item, fileName);
templatePathList = GetFlowRelationTableBackendTemplatePathList();
}
}
var defaultSidx = tableColumnList.Find(it => it.PrimaryKey == true).LowerColumnName;
//生成后端文件
for (var i = 0; i < templatePathList.Count; i++)
{
var tContent = File.ReadAllText(templatePathList[i]);
var tResult = _viewEngine.RunCompileFromCached(tContent, new
{
BusName = configModel.BusName,
NameSpace = configModel.NameSpace,
PrimaryKey = configModel.PrimaryKey,
MainTable = configModel.MainTable,
OriginalMainTableName = configModel.OriginalMainTableName,
LowerMainTable = configModel.LowerMainTable,
ClassName = configModel.ClassName,
hasPage = configModel.hasPage,
Function = configModel.Function,
TableField = configModel.TableField,
TableRelations = configModel.TableRelations,
DefaultSidx = columnDesignModel != null && !string.IsNullOrEmpty(columnDesignModel.defaultSidx) ? columnDesignModel.defaultSidx : defaultSidx,
IsExport = IsExport == null ? false : true,
IsUplpad = IsUplpad == null ? false : true,
IsTableRelations = tableNum > 0 ? true : false,
ColumnField = IsExport == null ? null : GetMainTableColumnField(columnDesignModel.columnList),
IsMapper = IsMapper == null ? false : true,
IsBillRule = isBillRule,
DbLinkId = templateEntity.DbLinkId,
FlowId = templateEntity.Id,
WebType = templateEntity.WebType,
Type = templateEntity.Type,
IsMainTable = item.relationTable == "" ? true : false,
isFlowId = isFlowId == null ? true : false,
EnCode = templateEntity.EnCode,
useDataPermission = columnDesignModel != null ? columnDesignModel.useDataPermission : false,
SearchList = tableColumnList.FindAll(it => it.QueryType.Equals(1)).Count()
});
var dirPath = new DirectoryInfo(targetPathList[i]).Parent.FullName;
if (!Directory.Exists(dirPath))
Directory.CreateDirectory(dirPath);
File.WriteAllText(targetPathList[i], tResult, Encoding.UTF8);
}
controls = _runService.TemplateDataConversion(formDataModel.fields);
}
#endregion
#region 前端
//前端文件生成
//表单列
Dictionary> ListQueryControlsType = new Dictionary>();
Dictionary> ListColumnControlsType = new Dictionary>();
#region 查询控件归类
if (templateEntity.Type == 4)
{
var useInputList = new List();
useInputList.Add("comInput");
useInputList.Add("textarea");
useInputList.Add("NCCText");
useInputList.Add("billRule");
ListQueryControlsType["inputList"] = useInputList;
var useDateList = new List();
useDateList.Add("createTime");
useDateList.Add("modifyTime");
ListQueryControlsType["dateList"] = useDateList;
var useSelectList = new List();
useSelectList.Add("select");
useSelectList.Add("radio");
useSelectList.Add("checkbox");
ListQueryControlsType["selectList"] = useSelectList;
var timePickerList = new List();
timePickerList.Add("time");
ListQueryControlsType["timePickerList"] = timePickerList;
var numRangeList = new List();
numRangeList.Add("numInput");
numRangeList.Add("calculate");
ListQueryControlsType["numRangeList"] = numRangeList;
var datePickerList = new List();
datePickerList.Add("date");
ListQueryControlsType["datePickerList"] = datePickerList;
var userSelectList = new List();
userSelectList.Add("createUser");
userSelectList.Add("modifyUser");
userSelectList.Add("userSelect");
ListQueryControlsType["userSelectList"] = userSelectList;
var comSelectList = new List();
comSelectList.Add("currOrganize");
comSelectList.Add("comSelect");
ListQueryControlsType["comSelectList"] = comSelectList;
var depSelectList = new List();
depSelectList.Add("currDept");
depSelectList.Add("depSelect");
ListQueryControlsType["depSelectList"] = depSelectList;
var posSelectList = new List();
posSelectList.Add("currPosition");
posSelectList.Add("posSelect");
ListQueryControlsType["posSelectList"] = posSelectList;
var useCascaderList = new List();
useCascaderList.Add("cascader");
ListQueryControlsType["useCascaderList"] = useCascaderList;
var NCCAddressList = new List();
NCCAddressList.Add("address");
ListQueryControlsType["NCCAddressList"] = NCCAddressList;
var treeSelectList = new List();
treeSelectList.Add("treeSelect");
ListQueryControlsType["treeSelectList"] = treeSelectList;
}
else if (templateEntity.Type == 5)
{
var inputList = new List();
inputList.Add("comInput");
inputList.Add("textarea");
inputList.Add("NCCText");
inputList.Add("billRule");
inputList.Add("modifyUser");
inputList.Add("currOrganize");
inputList.Add("currDept");
inputList.Add("currPosition");
inputList.Add("calculate");
ListQueryControlsType["input"] = inputList;
var numRangeList = new List();
numRangeList.Add("numInput");
ListQueryControlsType["numRange"] = numRangeList;
var switchList = new List();
switchList.Add("switch");
ListQueryControlsType["switch"] = switchList;
var selectList = new List();
selectList.Add("radio");
selectList.Add("checkbox");
selectList.Add("select");
ListQueryControlsType["select"] = selectList;
var cascaderList = new List();
cascaderList.Add("cascader");
ListQueryControlsType["cascader"] = cascaderList;
var timeList = new List();
timeList.Add("time");
ListQueryControlsType["time"] = timeList;
var dateList = new List();
dateList.Add("date");
dateList.Add("createTime");
dateList.Add("modifyTime");
ListQueryControlsType["date"] = dateList;
var comSelectList = new List();
comSelectList.Add("comSelect");
ListQueryControlsType["comSelect"] = comSelectList;
var depSelectList = new List();
depSelectList.Add("depSelect");
ListQueryControlsType["depSelect"] = depSelectList;
var posSelectList = new List();
posSelectList.Add("posSelect");
ListQueryControlsType["posSelect"] = posSelectList;
var userSelectList = new List();
userSelectList.Add("userSelect");
ListQueryControlsType["userSelect"] = userSelectList;
var treeSelectList = new List();
treeSelectList.Add("treeSelect");
ListQueryControlsType["treeSelect"] = treeSelectList;
var addressList = new List();
addressList.Add("address");
ListQueryControlsType["address"] = addressList;
}
#endregion
#region 列控件归类
var columnList = new List();
columnList.Add("select");
columnList.Add("radio");
columnList.Add("checkbox");
columnList.Add("treeSelect");
columnList.Add("cascader");
ListColumnControlsType["columnList"] = columnList;
#endregion
//表单全控件
var formAllControlsList = GetFormAllControlsList(formDataModel.fields, formDataModel.gutter, true);
//表单控件
var formColimnList = new List();
//列表主表控件Option
var indnxListMainTableControlOption = GetFormAllControlsProps(formDataModel.fields, templateEntity.Type.ToInt(), true);
foreach (var item in controls)
{
var config = item.__config__;
switch (config.NCCKey)
{
case "table":
{
var childrenFormColimnList = new List();
foreach (var children in config.children)
{
var childrenConfig = children.__config__;
childrenFormColimnList.Add(new CodeGenFormColumnModel()
{
Name = children.__vModel__.ToPascalCase(),
OriginalName = children.__vModel__,
NCCKey = childrenConfig.NCCKey,
DataType = childrenConfig.dataType,
DictionaryType = childrenConfig.dataType == "dictionary" ? childrenConfig.dictionaryType : (childrenConfig.dataType == "dynamic" ? childrenConfig.propsUrl : null),
Format = children.format,
Multiple = children.multiple,
BillRule = childrenConfig.rule,
Required = childrenConfig.required,
Placeholder = childrenConfig.label,
Range = children.range,
RegList = childrenConfig.regList,
DefaultValue = childrenConfig.defaultValue != null && childrenConfig.defaultValue.ToString() != "[]" && !string.IsNullOrEmpty(childrenConfig.defaultValue.ToString()) ? childrenConfig.defaultValue : null,
Trigger = childrenConfig.trigger.ToJson() == "null" ? "blur" : (childrenConfig.trigger.ToJson().Contains("[") ? childrenConfig.trigger.ToJson() : childrenConfig.trigger.ToString()),
ChildrenList = null
});
}
formColimnList.Add(new CodeGenFormColumnModel()
{
Name = config.tableName.ToPascalCase(),
Placeholder = config.label,
OriginalName = config.tableName,
NCCKey = config.NCCKey,
ChildrenList = childrenFormColimnList
});
}
break;
default:
{
try
{
var originalName = mainTableColumnConfigList.Find(it => it.LowerColumnName == item.__vModel__);
formColimnList.Add(new CodeGenFormColumnModel()
{
Name = item.__vModel__.ToPascalCase(),
OriginalName = originalName.Alias,
NCCKey = config.NCCKey,
DataType = config.dataType,
DictionaryType = config.dataType == "dictionary" ? config.dictionaryType : (config.dataType == "dynamic" ? config.propsUrl : null),
Format = item.format,
Multiple = item.multiple,
BillRule = config.rule,
Required = config.required,
Placeholder = config.label,
Range = item.range,
RegList = config.regList,
DefaultValue = config.defaultValue != null && config.defaultValue.ToString() != "[]" && !string.IsNullOrEmpty(config.defaultValue.ToString()) ? config.defaultValue : null,
Trigger = config.trigger.ToJson() == "null" ? "blur" : (config.trigger.ToJson().Contains("[") ? config.trigger.ToJson() : config.trigger.ToString()),
ChildrenList = null
});
}
catch (Exception ex)
{
Console.WriteLine($" {item.__vModel__} {item.name} 获取失败 " + ex.Message);
}
}
break;
}
}
//列表页查询
var indexSearchColumnDesignList = new List();
//列表页按钮
var indexListTopButtonList = new List();
//列表列按钮
var indexListColumnButtonDesignList = new List();
//列表页列表
var indexListColumnDesignList = new List();
if (templateEntity.WebType != 1 && templateEntity.Type != 3)
{
foreach (var item in columnDesignModel.searchList)
{
var column = controls.Find(c => c.__vModel__ == item.__vModel__);
var queryControls = ListQueryControlsType.Where(q => q.Value.Contains(column.__config__.NCCKey)).FirstOrDefault();
indexSearchColumnDesignList.Add(new CodeGenConvIndexSearchColumnDesign()
{
Name = item.__vModel__.ToPascalCase(),
Tag = item.__config__.tag,
Clearable = item.clearable ? "clearable " : "",
Format = column.format,
ValueFormat = column.valueformat,
Label = item.__config__.label,
QueryControlsKey = queryControls.Key != null ? queryControls.Key : null,
Props = column.__config__.props,
Index = columnDesignModel.searchList.IndexOf(item),
Type = column.type,
ShowAllLevels = column.showalllevels ? "true" : "false",
Level = column.level
});
}
//为生成功能方法模块添加数据
switch (templateEntity.Type)
{
case 5:
switch (templateEntity.WebType)
{
case 2:
case 3:
columnDesignModel.btnsList = new List();
columnDesignModel.columnBtnsList = new List();
break;
}
break;
}
foreach (var item in columnDesignModel.btnsList)
{
indexListTopButtonList.Add(new CodeGenConvIndexListTopButtonDesign()
{
Type = columnDesignModel.btnsList.IndexOf(item) == 0 ? "primary" : "text",
Icon = item.icon,
Method = GetCodeGenConvIndexListTopButtonMethod(item.value),
Value = item.value,
Label = item.label
});
}
foreach (var item in columnDesignModel.columnBtnsList)
{
indexListColumnButtonDesignList.Add(new CodeGenConvIndexListTopButtonDesign()
{
Type = item.value == "remove" ? "class=\"NCC-table-delBtn\" " : "",
Icon = item.icon,
Method = GetCodeGenConvIndexListColumnButtonMethod(item.value, funcTablePrimaryKey),
Value = item.value,
Label = item.label,
Disabled = GetCodeGenWorkflowIndexListColumnButtonDisabled(item.value)
});
}
switch (templateEntity.Type)
{
case 5:
switch (templateEntity.WebType)
{
case 2:
case 3:
columnDesignModel.btnsList = null;
columnDesignModel.columnBtnsList = null;
break;
}
break;
}
foreach (var item in columnDesignModel.columnList)
{
var conversion = ListColumnControlsType.Where(q => q.Value.Contains(item.NCCKey)).FirstOrDefault();
indexListColumnDesignList.Add(new CodeGenConvIndexListColumnDesign()
{
Name = item.prop.ToPascalCase(),
NCCKey = item.NCCKey,
Label = item.label,
Width = item.width == "0" ? "" : "width=\"" + item.width + "\" ",
Align = item.align,
IsAutomatic = conversion.Key == null ? false : true,
IsSort = item.sortable ? "sortable=\"custom\" " : ""
});
}
}
var isBatchRemoveDel = indexListTopButtonList.Find(it => it.Value == "batchRemove");
var isDownload = indexListTopButtonList.Find(it => it.Value == "download");
var isRemoveDel = indexListColumnButtonDesignList.Find(it => it.Value == "remove");
var isSort = columnDesignModel != null && columnDesignModel.columnList != null ? columnDesignModel.columnList.Find(it => it.sortable == true) : null;
var convFromConfigModel = new CodeGenConvFormConfigModel()
{
NameSpace = formDataModel.areasName,
ClassName = formDataModel.className,
PrimaryKey = funcTablePrimaryKey,
BusName = tableRelation.FirstOrDefault().tableName,
FormList = formColimnList,
PopupType = formDataModel.popupType,
SearchColumnDesign = indexSearchColumnDesignList,
AllColumnDesign = columnDesignModel,
TopButtonDesign = indexListTopButtonList,
ColumnDesign = indexListColumnDesignList,
ColumnButtonDesign = indexListColumnButtonDesignList,
TreeRelation = columnDesignModel != null && columnDesignModel.treeRelation != null ? columnDesignModel.treeRelation.Replace("F_", "").Replace("f_", "").ToPascalCase().LowerFirstChar() : null,
IsExistQuery = columnDesignModel != null && columnDesignModel.searchList != null ? columnDesignModel.searchList.Select(it => it.__vModel__ == columnDesignModel.treeRelation).ToBool() : false,
OptionsList = indnxListMainTableControlOption,
IsBatchRemoveDel = isBatchRemoveDel == null ? false : true,
IsDownload = isDownload == null ? false : true,
IsRemoveDel = isRemoveDel == null ? false : true,
FormAllContols = formAllControlsList,
Type = columnDesignModel != null ? columnDesignModel.type : 0
};
targetPathList = new List();
templatePathList = new List();
var mianTable = tableRelation.Find(it => it.relationTable == "");
//Web表单
if (templateEntity.Type == 4)
{
targetPathList = GetFrontendTargetPathList(mianTable, fileName, templateEntity.WebType.ToInt());
templatePathList = GetFrontendTemplatePathList(templateEntity.WebType.ToInt());
}
//app代码生成器
else if (templateEntity.Type == 5)
{
targetPathList = GetAppFrontendTargetPathList(mianTable, fileName, templateEntity.WebType.ToInt());
templatePathList = GetAppFrontendTemplatePathList(templateEntity.WebType.ToInt());
}
//流程表单
else if (templateEntity.Type == 3)
{
targetPathList = GetFlowFrontendTargetPathList(mianTable, fileName);
templatePathList = GetFlowFrontendTemplatePathList();
}
var flowTemplateJson = templateEntity.FlowTemplateJson != null ? templateEntity.FlowTemplateJson.ToJson() : null;
if (tableRelation.Count > 1)
{
foreach (var item in tableRelation)
{
if (item.relationTable != "")
{
var tableField = controls.Find(it => it.__config__.NCCKey.Equals("table") && it.__config__.tableName.Equals(item.table));
if (flowTemplateJson != null)
flowTemplateJson = flowTemplateJson.Replace(tableField.__vModel__, item.table.ToPascalCase().LowerFirstChar());
}
}
}
for (var i = 0; i < templatePathList.Count; i++)
{
var tContent = File.ReadAllText(templatePathList[i]);
var tResult = _viewEngine.RunCompileFromCached(tContent, new
{
BusName = convFromConfigModel.BusName,
ClassName = formDataModel.className,
NameSpace = convFromConfigModel.NameSpace,
PrimaryKey = convFromConfigModel.PrimaryKey.LowerFirstChar(),
FormDataModel = formDataModel,
FormList = formColimnList,
PopupType = formDataModel.popupType,
SearchColumnDesign = convFromConfigModel.SearchColumnDesign,
AllColumnDesign = convFromConfigModel.AllColumnDesign,
TopButtonDesign = convFromConfigModel.TopButtonDesign,
ColumnDesign = convFromConfigModel.ColumnDesign,
ColumnButtonDesign = convFromConfigModel.ColumnButtonDesign,
TreeRelation = convFromConfigModel.TreeRelation,
IsExistQuery = convFromConfigModel.IsExistQuery,
Type = convFromConfigModel.Type,
OptionsList = convFromConfigModel.OptionsList,
IsBatchRemoveDel = convFromConfigModel.IsBatchRemoveDel,
IsDownload = convFromConfigModel.IsDownload,
IsRemoveDel = convFromConfigModel.IsRemoveDel,
IsSort = isSort == null ? false : true,
FormAllContols = convFromConfigModel.FormAllContols,
DefaultSidx = columnDesignModel != null && columnDesignModel.defaultSidx != null ? columnDesignModel.defaultSidx : "",
EnCode = templateEntity.EnCode,
FlowId = templateEntity.Id,
FullName = templateEntity.FullName,
DbLinkId = templateEntity.DbLinkId,
FlowTemplateJson = flowTemplateJson,
Tables = templateEntity.Tables.ToJson(),
Category = categoryName,
MianTable = mianTable.table.ToPascalCase().LowerFirstChar(),
WebType = templateEntity.WebType,
HasPage = columnDesignModel != null ? columnDesignModel.hasPage : false,
}, builderAction: builder =>
{
builder.AddUsing("NCC.JsonSerialization");
builder.AddUsing("NCC.VisualDev.Entitys.Model.CodeGen");
builder.AddAssemblyReferenceByName("NCC.VisualDev.Entitys");
});
var dirPath = new DirectoryInfo(targetPathList[i]).Parent.FullName;
if (!Directory.Exists(dirPath))
Directory.CreateDirectory(dirPath);
File.WriteAllText(targetPathList[i], tResult, Encoding.UTF8);
}
#endregion
}
///
/// 预览代码
///
///
/// 1-Web设计,2-App设计,3-流程表单,4-Web表单,5-App表单
/// 页面类型(1、纯表单,2、表单加列表,3、表单列表工作流)
///
public List> PriviewCode(string codePath, int type, int webType)
{
var dataList = FileHelper.GetAllFiles(codePath);
var parentFolder = dataList.Find(it => it.FullName.Contains("html")).Directory.Name;
List> datas = new List>();
List> allDatas = new List>();
foreach (var item in dataList)
{
Dictionary data = new Dictionary();
FileStream fileStream = new FileStream(item.FullName, FileMode.Open);
using (StreamReader reader = new StreamReader(fileStream))
{
var buffer = new Char[(int)reader.BaseStream.Length];
reader.Read(buffer, 0, (int)reader.BaseStream.Length);
var content = new string(buffer);
if ("cs".Equals(item.Extension.Replace(".", "")))
{
string fileName = item.FullName.ToLower();
if (fileName.Contains("listqueryinput") || fileName.Contains("crinput") || fileName.Contains("upinput") || fileName.Contains("upoutput") || fileName.Contains("listoutput") || fileName.Contains("infooutput"))
{
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);
//剔除"\0"特殊符号
data.Add("fileContent", content.Replace("\0", ""));
data.Add("fileType", item.Extension.Replace(".", ""));
datas.Add(data);
}
else if (".json".Equals(item.Extension))
{
data.Add("folderName", "json");
data.Add("id", YitIdHelper.NextId().ToString());
data.Add("fileName", item.Name);
//剔除"\0"特殊符号
data.Add("fileContent", content.Replace("\0", ""));
data.Add("fileType", item.Extension.Replace(".", ""));
datas.Add(data);
}
else if (".vue".Equals(item.Extension))
{
switch (type)
{
case 5:
data.Add("folderName", "app");
break;
default:
data.Add("folderName", "web");
break;
}
data.Add("id", YitIdHelper.NextId().ToString());
data.Add("fileName", item.Name);
//剔除"\0"特殊符号
data.Add("fileContent", content.Replace("\0", ""));
data.Add("fileType", item.Extension.Replace(".", ""));
datas.Add(data);
}
}
}
//datas 集合去重
var parent = datas.GroupBy(d => d["folderName"]).Select(d => d.First()).OrderByDescending(d => d["folderName"]).ToList();
foreach (var item in parent)
{
Dictionary dataMap = new Dictionary();
dataMap["fileName"] = item["folderName"];
dataMap["id"] = YitIdHelper.NextId().ToString();
dataMap["children"] = datas.FindAll(d => d["folderName"] == item["folderName"]);
allDatas.Add(dataMap);
}
return allDatas;
}
#endregion
#region PrivateMethod
#region 后端主表
///
/// 获取后端主表模板文件路径集合
///
/// 页面类型(1、纯表单,2、表单加列表,3、表单列表工作流)
///
private List GetMainTableBackendTemplatePathList(int webType)
{
var templatePath = Path.Combine(App.WebHostEnvironment.WebRootPath, "Template");
switch (webType)
{
case 1:
return new List()
{
Path.Combine(templatePath , "Service.cs.vm"),
Path.Combine(templatePath , "IService.cs.vm"),
Path.Combine(templatePath , "Entity.cs.vm"),
Path.Combine(templatePath , "CrInput.cs.vm"),
Path.Combine(templatePath , "Mapper.cs.vm"),
};
case 2:
return new List()
{
Path.Combine(templatePath , "Service.cs.vm"),
Path.Combine(templatePath , "IService.cs.vm"),
Path.Combine(templatePath , "Entity.cs.vm"),
Path.Combine(templatePath , "Mapper.cs.vm"),
Path.Combine(templatePath , "CrInput.cs.vm"),
Path.Combine(templatePath , "UpInput.cs.vm"),
Path.Combine(templatePath , "ListQueryInput.cs.vm"),
Path.Combine(templatePath , "InfoOutput.cs.vm"),
Path.Combine(templatePath , "ListOutput.cs.vm")
};
case 3:
return new List()
{
Path.Combine(templatePath , "WorkflowService.cs.vm"),
Path.Combine(templatePath , "IService.cs.vm"),
Path.Combine(templatePath , "Entity.cs.vm"),
Path.Combine(templatePath , "Mapper.cs.vm"),
Path.Combine(templatePath , "CrInput.cs.vm"),
Path.Combine(templatePath , "UpInput.cs.vm"),
Path.Combine(templatePath , "ListQueryInput.cs.vm"),
Path.Combine(templatePath , "InfoOutput.cs.vm"),
Path.Combine(templatePath , "ListOutput.cs.vm")
};
}
return null;
}
///
/// 获取后端主表生成文件路径
///
///
///
/// 页面类型(1、纯表单,2、表单加列表,3、表单列表工作流)
///
private List GetMainTableBackendTargetPathList(DbTableRelationModel tableInfo, string fileName, int webType)
{
var backendPath = Path.Combine(FileVariable.GenerateCodePath, fileName, "Net");
var tableName = tableInfo.table.ToPascalCase();
var servicePath = Path.Combine(backendPath, "Controller", tableName + "Service.cs");
var iservicePath = Path.Combine(backendPath, "Controller", "I" + tableName + "Service.cs");
var entityPath = Path.Combine(backendPath, "Models", "Entity", tableName + "Entity.cs");
var mapperPath = Path.Combine(backendPath, "Models", "Mapper", tableName + "Mapper.cs");
var inputCrPath = Path.Combine(backendPath, "Models", "Dto", tableName + "CrInput.cs");
var inputUpPath = Path.Combine(backendPath, "Models", "Dto", tableName + "UpInput.cs");
var inputListQueryPath = Path.Combine(backendPath, "Models", "Dto", tableName + "ListQueryInput.cs");
var outputInfoPath = Path.Combine(backendPath, "Models", "Dto", tableName + "InfoOutput.cs");
var outputListPath = Path.Combine(backendPath, "Models", "Dto", tableName + "ListOutput.cs");
switch (webType)
{
case 1:
return new List()
{
servicePath,
iservicePath,
entityPath,
inputCrPath,
mapperPath
};
case 2:
return new List()
{
servicePath,
iservicePath,
entityPath,
mapperPath,
inputCrPath,
inputUpPath,
inputListQueryPath,
outputInfoPath,
outputListPath
};
case 3:
return new List()
{
servicePath,
iservicePath,
entityPath,
mapperPath,
inputCrPath,
inputUpPath,
inputListQueryPath,
outputInfoPath,
outputListPath
};
}
return null;
}
///
/// 获取流程后端主表模板文件路径集合
///
///
private List GetFlowMainTableBackendTemplatePathList()
{
var templatePath = Path.Combine(App.WebHostEnvironment.WebRootPath, "Template");
return new List()
{
Path.Combine(templatePath , "WorkFlowFormService.cs.vm"),
Path.Combine(templatePath , "IService.cs.vm"),
Path.Combine(templatePath , "Entity.cs.vm"),
Path.Combine(templatePath , "Mapper.cs.vm"),
Path.Combine(templatePath , "CrInput.cs.vm"),
Path.Combine(templatePath , "UpInput.cs.vm"),
Path.Combine(templatePath , "InfoOutput.cs.vm")
};
}
///
/// 获取流程后端主表生成文件路径
///
///
///
///
private List GetFlowMainTableBackendTargetPathList(DbTableRelationModel tableInfo, string fileName)
{
var backendPath = Path.Combine(FileVariable.GenerateCodePath, fileName, "Net");
var tableName = tableInfo.table.ToPascalCase();
var servicePath = Path.Combine(backendPath, "Controller", tableName + "Service.cs");
var iservicePath = Path.Combine(backendPath, "Controller", "I" + tableName + "Service.cs");
var entityPath = Path.Combine(backendPath, "Models", "Entity", tableName + "Entity.cs");
var mapperPath = Path.Combine(backendPath, "Models", "Mapper", tableName + "Mapper.cs");
var inputCrPath = Path.Combine(backendPath, "Models", "Dto", tableName + "CrInput.cs");
var inputUpPath = Path.Combine(backendPath, "Models", "Dto", tableName + "UpInput.cs");
var outputInfoPath = Path.Combine(backendPath, "Models", "Dto", tableName + "InfoOutput.cs");
return new List()
{
servicePath,
iservicePath,
entityPath,
mapperPath,
inputCrPath,
inputUpPath,
outputInfoPath
};
}
#endregion
#region 后端关系表
///
/// 获取后端主表模板文件路径集合
///
/// 页面类型(1、纯表单,2、表单加列表,3、表单列表工作流)
///
private List GetRelationTableBackendTemplatePathList(int webType)
{
var templatePath = Path.Combine(App.WebHostEnvironment.WebRootPath, "Template");
switch (webType)
{
case 1:
return new List()
{
Path.Combine(templatePath , "Entity.cs.vm"),
Path.Combine(templatePath , "CrInput.cs.vm")
};
case 2:
case 3:
return new List()
{
Path.Combine(templatePath , "Entity.cs.vm"),
Path.Combine(templatePath , "Mapper.cs.vm"),
Path.Combine(templatePath , "CrInput.cs.vm"),
Path.Combine(templatePath , "UpInput.cs.vm"),
Path.Combine(templatePath , "InfoOutput.cs.vm")
};
}
return null;
}
///
/// 获取后端关系表生成文件路径
///
///
///
/// 页面类型(1、纯表单,2、表单加列表,3、表单列表工作流)
///
private List GetRelationTableBackendTargetPathList(DbTableRelationModel tableInfo, string fileName, int webType)
{
var backendPath = Path.Combine(FileVariable.GenerateCodePath, fileName, "Net");
var tableName = tableInfo.table.ToPascalCase();
var entityPath = Path.Combine(backendPath, "Models", "Entity", tableName + "Entity.cs");
var mapperPath = Path.Combine(backendPath, "Models", "Mapper", tableName + "Mapper.cs");
var inputCrPath = Path.Combine(backendPath, "Models", "Dto", tableName + "CrInput.cs");
var inputUpPath = Path.Combine(backendPath, "Models", "Dto", tableName + "UpInput.cs");
var outputInfoPath = Path.Combine(backendPath, "Models", "Dto", tableName + "InfoOutput.cs");
switch (webType)
{
case 1:
return new List()
{
entityPath,
inputCrPath
};
case 2:
return new List()
{
entityPath,
mapperPath,
inputCrPath,
inputUpPath,
outputInfoPath
};
case 3:
return new List()
{
entityPath,
mapperPath,
inputCrPath,
inputUpPath,
outputInfoPath
};
}
return null;
}
///
/// 获取流程主表模板文件路径集合
///
///
private List GetFlowRelationTableBackendTemplatePathList()
{
var templatePath = Path.Combine(App.WebHostEnvironment.WebRootPath, "Template");
return new List()
{
Path.Combine(templatePath , "Entity.cs.vm"),
Path.Combine(templatePath , "Mapper.cs.vm"),
Path.Combine(templatePath , "CrInput.cs.vm"),
Path.Combine(templatePath , "UpInput.cs.vm"),
Path.Combine(templatePath , "InfoOutput.cs.vm")
};
}
///
/// 获取流程后端关系表生成文件路径
///
///
///
///
private List GetFlowRelationTableBackendTargetPathList(DbTableRelationModel tableInfo, string fileName)
{
var backendPath = Path.Combine(FileVariable.GenerateCodePath, fileName, "Net");
var tableName = tableInfo.table.ToPascalCase();
var entityPath = Path.Combine(backendPath, "Models", "Entity", tableName + "Entity.cs");
var mapperPath = Path.Combine(backendPath, "Models", "Mapper", tableName + "Mapper.cs");
var inputCrPath = Path.Combine(backendPath, "Models", "Dto", tableName + "CrInput.cs");
var inputUpPath = Path.Combine(backendPath, "Models", "Dto", tableName + "UpInput.cs");
var outputInfoPath = Path.Combine(backendPath, "Models", "Dto", tableName + "InfoOutput.cs");
return new List()
{
entityPath,
mapperPath,
inputCrPath,
inputUpPath,
outputInfoPath
};
}
#endregion
#region 前端页面
///
/// 获取前端页面模板文件路径集合
///
/// 页面类型(1、纯表单,2、表单加列表,3、表单列表工作流)
///
private List GetFrontendTemplatePathList(int webType)
{
var templatePath = Path.Combine(App.WebHostEnvironment.WebRootPath, "Template");
switch (webType)
{
case 1:
return new List()
{
Path.Combine(templatePath , "Form.vue.vm")
};
case 2:
return new List()
{
Path.Combine(templatePath , "index.vue.vm"),
Path.Combine(templatePath , "Form.vue.vm"),
Path.Combine(templatePath , "ExportBox.vue.vm")
};
case 3:
return new List()
{
Path.Combine(templatePath , "WorkflowIndex.vue.vm"),
Path.Combine(templatePath , "WorkflowForm.vue.vm"),
Path.Combine(templatePath , "ExportBox.vue.vm"),
Path.Combine(templatePath , "ExportJson.json.vm")
};
default:
break;
}
return null;
}
///
/// 设置前端页面生成文件路径
///
///
///
/// 页面类型(1、纯表单,2、表单加列表,3、表单列表工作流)
///
private List GetFrontendTargetPathList(DbTableRelationModel tableInfo, string fileName, int webType)
{
var frontendPath = Path.Combine(FileVariable.GenerateCodePath, fileName, "Net");
var tableName = tableInfo.table.ToPascalCase().LowerFirstChar();
var indexPath = Path.Combine(frontendPath, "html", tableName, "index.vue");
var formPath = Path.Combine(frontendPath, "html", tableName, "Form.vue");
var exportBoxPath = Path.Combine(frontendPath, "html", tableName, "ExportBox.vue");
var exportJsonPath = Path.Combine(frontendPath, "json", "ExportJson.json");
switch (webType)
{
case 1:
return new List()
{
indexPath
};
case 2:
return new List()
{
indexPath,
formPath,
exportBoxPath
};
case 3:
return new List()
{
indexPath,
formPath,
exportBoxPath,
exportJsonPath
};
}
return null;
}
///
/// 获取App前端页面模板文件路径集合
///
///
///
private List GetAppFrontendTemplatePathList(int webType)
{
var templatePath = Path.Combine(App.WebHostEnvironment.WebRootPath, "Template");
switch (webType)
{
case 1:
return new List()
{
Path.Combine(templatePath , "appForm.vue.vm")
};
case 2:
return new List()
{
Path.Combine(templatePath , "appIndex.vue.vm"),
Path.Combine(templatePath , "appForm.vue.vm")
};
case 3:
return new List()
{
Path.Combine(templatePath , "appWorkflowIndex.vue.vm"),
Path.Combine(templatePath , "appWorkflowForm.vue.vm"),
Path.Combine(templatePath , "ExportJson.json.vm")
};
default:
break;
}
return null;
}
///
/// 设置App前端页面生成文件路径
///
///
///
/// 页面类型(1、纯表单,2、表单加列表,3、表单列表工作流)
///
private List GetAppFrontendTargetPathList(DbTableRelationModel tableInfo, string fileName, int webType)
{
var frontendPath = Path.Combine(FileVariable.GenerateCodePath, fileName, "Net");
var tableName = tableInfo.table.ToPascalCase().LowerFirstChar();
var indexPath = Path.Combine(frontendPath, "html", tableName, "index.vue");
var formPath = Path.Combine(frontendPath, "html", tableName, "form.vue");
var exportJsonPath = Path.Combine(frontendPath, "json", "ExportJson.json");
switch (webType)
{
case 1:
return new List()
{
indexPath
};
case 2:
return new List()
{
indexPath,
formPath,
};
case 3:
return new List()
{
Path.Combine(frontendPath, "html", "app","index", "index.vue"),
Path.Combine(frontendPath, "html", "app","form", "index.vue"),
exportJsonPath
};
}
return null;
}
///
/// 获取流程前端页面模板文件路径集合
///
///
private List GetFlowFrontendTemplatePathList()
{
var templatePath = Path.Combine(App.WebHostEnvironment.WebRootPath, "Template");
return new List()
{
Path.Combine(templatePath , "WorkflowForm.vue.vm"),
Path.Combine(templatePath , "appWorkflowForm.vue.vm")
};
}
///
/// 设置流程前端页面生成文件路径
///
///
///
///
private List GetFlowFrontendTargetPathList(DbTableRelationModel tableInfo, string fileName)
{
var frontendPath = Path.Combine(FileVariable.GenerateCodePath, fileName, "Net");
var tableName = tableInfo.table.ToPascalCase().LowerFirstChar();
var indexPath = Path.Combine(frontendPath, "html", "PC", tableName, "index.vue");
var indexAppPath = Path.Combine(frontendPath, "html", "APP", tableName, "index.vue");
return new List()
{
indexPath,
indexAppPath
};
}
#endregion
///
/// 获取主表字段名
///
///
///
private string GetMainTableColumnField(List list)
{
StringBuilder columnSb = new StringBuilder();
foreach (var item in list)
{
columnSb.AppendFormat("{{\\\"value\\\":\\\"{0}\\\",\\\"field\\\":\\\"{1}\\\"}},", item.label, item.prop);
}
return columnSb.ToString();
}
///
/// 获取是否查询列
///
///
///
///
private bool GetIsColumnQueryWhether(List searchList, string alias)
{
var column = searchList.Find(s => s.__vModel__ == alias);
return column == null ? false : true;
}
///
/// 获取列查询类型
///
///
///
///
private int GetColumnQueryType(List searchList, string alias)
{
var column = searchList.Find(s => s.__vModel__ == alias);
return column == null ? 0 : column.searchType;
}
///
/// 获取是否展示列
///
///
///
///
private bool GetIsShowColumn(List columnList, string alias)
{
var column = columnList.Find(s => s.prop == alias);
return column == null ? false : true;
}
///
/// 获取是否多选
///
///
///
///
public bool GetIsMultipleColumn(List columnList, string alias)
{
var column = columnList.Find(s => s.__vModel__ == alias);
if (column != null)
{
return column.multiple;
}
return false;
}
///
/// 获取代码生成方法列表
///
/// 是否分页
/// 头部按钮
/// 列表按钮
/// 页面类型(1、纯表单,2、表单加列表,3、表单列表工作流)
///
private List GetCodeGenFunctionList(bool hasPage, List btnsList, List columnBtnsList, int webType)
{
List functionList = new List();
switch (webType)
{
case 1:
functionList.Add(new CodeGenFunctionModel()
{
FullName = "add",
IsInterface = true
});
break;
default:
//信息
functionList.Add(new CodeGenFunctionModel()
{
FullName = "info",
IsInterface = true
});
if (!hasPage)
functionList.Add(new CodeGenFunctionModel()
{
FullName = "noPage",
IsInterface = true
});
else
functionList.Add(new CodeGenFunctionModel()
{
FullName = "page",
IsInterface = true
});
btnsList.ForEach(b =>
{
if (b.value == "download" && !hasPage)
functionList.Add(new CodeGenFunctionModel()
{
FullName = "page",
IsInterface = false
});
else if (b.value == "download" && hasPage)
functionList.Add(new CodeGenFunctionModel()
{
FullName = "noPage",
IsInterface = false
});
functionList.Add(new CodeGenFunctionModel()
{
FullName = b.value,
IsInterface = true
});
});
columnBtnsList.ForEach(c =>
{
functionList.Add(new CodeGenFunctionModel()
{
FullName = c.value,
IsInterface = true
});
});
break;
}
return functionList;
}
///
/// 获取代码生成流程方法列表
///
///
private List GetCodeGenFlowFunctionList()
{
List functionList = new List();
//信息
functionList.Add(new CodeGenFunctionModel()
{
FullName = "info",
IsInterface = true
});
functionList.Add(new CodeGenFunctionModel()
{
FullName = "add",
IsInterface = true
});
functionList.Add(new CodeGenFunctionModel()
{
FullName = "edit",
IsInterface = true
});
functionList.Add(new CodeGenFunctionModel()
{
FullName = "remove",
IsInterface = true
});
return functionList;
}
///
/// 获取代码生成表关系列表
///
/// 全部表列表
/// 当前表
/// 连接ID
/// 子表控件
///
private List GetCodeGenTableRelationList(List tableRelation, string currentTable, DbLinkEntity link, List fieldList)
{
List tableRelationsList = new List();
var relationTable = tableRelation.Find(t => t.table.Equals(currentTable)).relationTable;
if (!relationTable.IsNotEmptyOrNull())
{
tableRelation.ForEach(t =>
{
List tableColumnConfigList = new List();
if (t.relationTable.IsNotEmptyOrNull())
{
var table = _databaseService.GetFieldListByNoAsync(link, t.table);
var field = fieldList.Find(it => it.__config__.tableName.Equals(t.table));
if (field != null)
{
foreach (var column in table)
{
var columnName = column.field.Replace("F_", "").Replace("f_", "").ToPascalCase();
var control = field.__config__.children.Find(it => it.__vModel__.Equals(columnName.LowerFirstChar()));
tableColumnConfigList.Add(new TableColumnConfigModel()
{
ColumnName = columnName,
Alias = column.field,
OriginalColumnName = column.field,
ColumnComment = column.fieldName,
DataType = column.dataType,
NetType = CodeGenUtil.ConvertDataType(column.dataType),
PrimaryKey = column.primaryKey.ToBool(),
IsMultiple = GetIsMultipleColumn(fieldList, column.field),
NCCKey = control != null ? control.__config__.NCCKey : null,
Rule = control != null ? control.__config__.rule : null
});
}
}
tableRelationsList.Add(new CodeGenTableRelationsModel()
{
TableName = t.table.ToPascalCase(),
PrimaryKey = table.Find(t => t.primaryKey == 1).field.Replace("F_", "").Replace("f_", "").ToPascalCase(),
TableField = t.tableField.Replace("F_", "").Replace("f_", "").ToPascalCase(),
RelationField = t.relationField.Replace("F_", "").Replace("f_", "").ToPascalCase(),
TableComment = t.tableName,
ChilderColumnConfigList = tableColumnConfigList
});
}
});
}
return tableRelationsList;
}
///
/// 获取代码生成常规Index列表头部按钮方法
///
///
private string GetCodeGenConvIndexListTopButtonMethod(string value)
{
var method = string.Empty;
switch (value)
{
case "add":
method = "addOrUpdateHandle()";
break;
case "download":
method = "exportData()";
break;
case "batchRemove":
method = "handleBatchRemoveDel()";
break;
default:
break;
}
return method;
}
///
/// 获取代码生成常规Index列表列按钮方法
///
///
private string GetCodeGenConvIndexListColumnButtonMethod(string value, string primaryKey)
{
var method = string.Empty;
switch (value)
{
case "edit":
method = $"addOrUpdateHandle(scope.row.{primaryKey.LowerFirstChar()})";
break;
case "remove":
method = $"handleDel(scope.row.{primaryKey.LowerFirstChar()})";
break;
case "detail":
method = $"addOrUpdateHandle(scope.row.{primaryKey.LowerFirstChar()},true)";
break;
default:
break;
}
return method;
}
///
/// 获取代码生成流程Index列表列按钮是否禁用
///
///
///
private string GetCodeGenWorkflowIndexListColumnButtonDisabled(string value)
{
var disabled = string.Empty;
switch (value)
{
case "edit":
disabled = ":disabled = '[1, 2, 5].indexOf(scope.row.flowState) > -1' ";
break;
case "remove":
disabled = ":disabled = '[1, 2, 3, 5].indexOf(scope.row.flowState) > -1' ";
break;
}
return disabled;
}
///
/// 获取常规index列表控件Option
///
///
///
///
private string GetCodeGenConvIndexListControlOption(string name, List> options)
{
StringBuilder sb = new StringBuilder();
sb.Append($"{name}Options:");
sb.Append("[");
var list = options.ToObject>>();
foreach (var valueItem in list)
{
sb.Append("{");
foreach (var items in valueItem)
{
sb.Append($"\"{items.Key}\":{items.Value.ToJson()},");
}
sb = new StringBuilder(sb.ToString().TrimEnd(','));
sb.Append("},");
}
sb = new StringBuilder(sb.ToString().TrimEnd(','));
sb.Append("],");
return sb.ToString();
}
///
///
///
///
///
///
private string GetCodeGenConvIndexListControlOption(string name, List