init commit
This commit is contained in:
207
20220330_Vote/Ewide.Core/Service/CodeGen/CodeGenConfigService.cs
Normal file
207
20220330_Vote/Ewide.Core/Service/CodeGen/CodeGenConfigService.cs
Normal file
@@ -0,0 +1,207 @@
|
||||
using Furion.DatabaseAccessor;
|
||||
using Furion.DatabaseAccessor.Extensions;
|
||||
using Furion.DependencyInjection;
|
||||
using Furion.DynamicApiController;
|
||||
using Mapster;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Ewide.Core.Service
|
||||
{
|
||||
/// <summary>
|
||||
/// 代码生成详细配置服务
|
||||
/// </summary>
|
||||
[ApiDescriptionSettings(Name = "CodeGenConfig", Order = 100)]
|
||||
public class CodeGenConfigService : ICodeGenConfigService, IDynamicApiController, ITransient
|
||||
{
|
||||
private readonly IRepository<SysCodeGenConfig> _sysCodeGenConfigRep; // 代码生成详细配置仓储
|
||||
|
||||
public CodeGenConfigService(IRepository<SysCodeGenConfig> sysCodeGenConfigRep)
|
||||
{
|
||||
_sysCodeGenConfigRep = sysCodeGenConfigRep;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 代码生成详细配置列表
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
|
||||
[HttpGet("/sysCodeGenerateConfig/list")]
|
||||
public async Task<List<CodeGenConfig>> List([FromQuery] CodeGenConfig input)
|
||||
{
|
||||
return await _sysCodeGenConfigRep.DetachedEntities.Where(u => u.CodeGenId == input.CodeGenId && u.WhetherCommon != YesOrNot.Y.ToString())
|
||||
.Select(u => u.Adapt<CodeGenConfig>()).ToListAsync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 增加
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
[NonAction]
|
||||
public async Task Add(CodeGenConfig input)
|
||||
{
|
||||
var codeGenConfig = input.Adapt<SysCodeGenConfig>();
|
||||
await codeGenConfig.InsertAsync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除
|
||||
/// </summary>
|
||||
/// <param name="codeGenId"></param>
|
||||
/// <returns></returns>
|
||||
[NonAction]
|
||||
public async Task Delete(string codeGenId)
|
||||
{
|
||||
var codeGenConfigList = await _sysCodeGenConfigRep.Where(u => u.CodeGenId == codeGenId).ToListAsync();
|
||||
codeGenConfigList.ForEach(u =>
|
||||
{
|
||||
u.Delete();
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新
|
||||
/// </summary>
|
||||
/// <param name="inputList"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("/sysCodeGenerateConfig/edit")]
|
||||
public async Task Update(List<CodeGenConfig> inputList)
|
||||
{
|
||||
if (inputList == null || inputList.Count < 1) return;
|
||||
inputList.ForEach(u =>
|
||||
{
|
||||
var codeGenConfig = u.Adapt<SysCodeGenConfig>();
|
||||
codeGenConfig.Update(true);
|
||||
});
|
||||
await Task.CompletedTask;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 详情
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("/sysCodeGenerateConfig/detail")]
|
||||
public async Task<SysCodeGenConfig> Detail(CodeGenConfig input)
|
||||
{
|
||||
return await _sysCodeGenConfigRep.FirstOrDefaultAsync(u => u.Id == input.Id);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 批量增加
|
||||
/// </summary>
|
||||
/// <param name="tableColumnOuputList"></param>
|
||||
/// <param name="codeGenerate"></param>
|
||||
[NonAction]
|
||||
public void AddList(List<TableColumnOuput> tableColumnOuputList, SysCodeGen codeGenerate)
|
||||
{
|
||||
if (tableColumnOuputList == null) return;
|
||||
|
||||
foreach (var tableColumn in tableColumnOuputList)
|
||||
{
|
||||
var codeGenConfig = new SysCodeGenConfig();
|
||||
|
||||
var YesOrNo = YesOrNot.Y.ToString();
|
||||
if (Convert.ToBoolean(tableColumn.ColumnKey))
|
||||
{
|
||||
YesOrNo = YesOrNot.N.ToString();
|
||||
}
|
||||
|
||||
if (IsCommonColumn(tableColumn.ColumnName))
|
||||
{
|
||||
codeGenConfig.WhetherCommon = YesOrNot.Y.ToString();
|
||||
YesOrNo = YesOrNot.N.ToString();
|
||||
}
|
||||
else
|
||||
{
|
||||
codeGenConfig.WhetherCommon = YesOrNot.N.ToString();
|
||||
}
|
||||
|
||||
codeGenConfig.CodeGenId = codeGenerate.Id;
|
||||
codeGenConfig.ColumnName = tableColumn.ColumnName;
|
||||
codeGenConfig.ColumnComment = tableColumn.ColumnComment;
|
||||
codeGenConfig.NetType = ConvertDataType(tableColumn.DataType);
|
||||
codeGenConfig.WhetherRetract = YesOrNot.N.ToString();
|
||||
|
||||
codeGenConfig.WhetherRequired = YesOrNot.N.ToString();
|
||||
codeGenConfig.QueryWhether = YesOrNo;
|
||||
codeGenConfig.WhetherAddUpdate = YesOrNo;
|
||||
codeGenConfig.WhetherTable = YesOrNo;
|
||||
|
||||
codeGenConfig.ColumnKey = tableColumn.ColumnKey;
|
||||
|
||||
codeGenConfig.DataType = tableColumn.DataType;
|
||||
codeGenConfig.EffectType = DataTypeToEff(codeGenConfig.NetType);
|
||||
codeGenConfig.QueryType = "=="; // QueryTypeEnum.eq.ToString();
|
||||
|
||||
codeGenConfig.InsertAsync();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 数据类型转显示类型
|
||||
/// </summary>
|
||||
/// <param name="dataType"></param>
|
||||
/// <returns></returns>
|
||||
private static string DataTypeToEff(string dataType)
|
||||
{
|
||||
if (string.IsNullOrEmpty(dataType)) return "";
|
||||
return dataType switch
|
||||
{
|
||||
"string" => "input",
|
||||
"int" => "inputnumber",
|
||||
"long" => "input",
|
||||
"float" => "input",
|
||||
"double" => "input",
|
||||
"decimal" => "input",
|
||||
"bool" => "switch",
|
||||
"Guid" => "input",
|
||||
"DateTime" => "datepicker",
|
||||
"DateTimeOffset" => "datepicker",
|
||||
_ => "input",
|
||||
};
|
||||
}
|
||||
|
||||
// 转换.NET数据类型
|
||||
[NonAction]
|
||||
public string ConvertDataType(string dataType)
|
||||
{
|
||||
if (string.IsNullOrEmpty(dataType)) return "";
|
||||
if (dataType.StartsWith("System.Nullable"))
|
||||
dataType = new Regex(@"(?i)(?<=\[)(.*)(?=\])").Match(dataType).Value; // 中括号[]里面值
|
||||
|
||||
switch (dataType)
|
||||
{
|
||||
case "System.Guid": return "Guid";
|
||||
case "System.String": return "string";
|
||||
case "System.Int32": return "int";
|
||||
case "System.Int64": return "long";
|
||||
case "System.Single": return "float";
|
||||
case "System.Double": return "double";
|
||||
case "System.Decimal": return "decimal";
|
||||
case "System.Boolean": return "bool";
|
||||
case "System.DateTime": return "DateTime";
|
||||
case "System.DateTimeOffset": return "DateTimeOffset";
|
||||
case "System.Byte": return "byte";
|
||||
case "System.Byte[]": return "byte[]";
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return dataType;
|
||||
}
|
||||
|
||||
// 是否通用字段
|
||||
private static bool IsCommonColumn(string columnName)
|
||||
{
|
||||
var columnList = new List<string>() { "CreatedTime", "UpdatedTime", "CreatedUserId", "CreatedUserName", "UpdatedUserId", "UpdatedUserName", "IsDeleted" };
|
||||
return columnList.Contains(columnName);
|
||||
}
|
||||
}
|
||||
}
|
||||
348
20220330_Vote/Ewide.Core/Service/CodeGen/CodeGenService.cs
Normal file
348
20220330_Vote/Ewide.Core/Service/CodeGen/CodeGenService.cs
Normal file
@@ -0,0 +1,348 @@
|
||||
using Furion;
|
||||
using Furion.DatabaseAccessor;
|
||||
using Furion.DatabaseAccessor.Extensions;
|
||||
using Furion.DependencyInjection;
|
||||
using Furion.DynamicApiController;
|
||||
using Furion.FriendlyException;
|
||||
using Furion.ViewEngine;
|
||||
using Mapster;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Ewide.Core.Service.CodeGen
|
||||
{
|
||||
/// <summary>
|
||||
/// 代码生成器服务
|
||||
/// </summary>
|
||||
[ApiDescriptionSettings(Name = "CodeGen", Order = 100)]
|
||||
public class CodeGenService : ICodeGenService, IDynamicApiController, ITransient
|
||||
{
|
||||
private readonly IRepository<SysCodeGen> _sysCodeGenRep; // 代码生成器仓储
|
||||
private readonly ICodeGenConfigService _codeGenConfigService;
|
||||
private readonly IViewEngine _viewEngine;
|
||||
|
||||
private readonly IRepository<SysMenu> _sysMenuRep; // 菜单表仓储
|
||||
|
||||
public CodeGenService(IRepository<SysCodeGen> sysCodeGenRep,
|
||||
ICodeGenConfigService codeGenConfigService,
|
||||
IViewEngine viewEngine,
|
||||
IRepository<SysMenu> sysMenuRep)
|
||||
{
|
||||
_sysCodeGenRep = sysCodeGenRep;
|
||||
_codeGenConfigService = codeGenConfigService;
|
||||
_viewEngine = viewEngine;
|
||||
_sysMenuRep = sysMenuRep;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 分页查询
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("/codeGenerate/page")]
|
||||
public async Task<dynamic> QueryCodeGenPageList([FromBody] CodeGenInput input)
|
||||
{
|
||||
var tableName = !string.IsNullOrEmpty(input.TableName?.Trim());
|
||||
var codeGens = await _sysCodeGenRep.DetachedEntities
|
||||
.Where((tableName, u => EF.Functions.Like(u.TableName, $"%{input.TableName.Trim()}%")))
|
||||
.ToPagedListAsync(input.PageIndex, input.PageSize);
|
||||
return PageDataResult<SysCodeGen>.PageResult(codeGens);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 增加
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("/codeGenerate/add")]
|
||||
public async Task AddCodeGen(AddCodeGenInput input)
|
||||
{
|
||||
var isExist = await _sysCodeGenRep.DetachedEntities.AnyAsync(u => u.TableName == input.TableName);
|
||||
if (isExist)
|
||||
throw Oops.Oh(ErrorCode.D1400);
|
||||
|
||||
var codeGen = input.Adapt<SysCodeGen>();
|
||||
var newCodeGen = await codeGen.InsertNowAsync();
|
||||
|
||||
// 加入配置表中
|
||||
_codeGenConfigService.AddList(GetColumnList(input), newCodeGen.Entity);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除
|
||||
/// </summary>
|
||||
/// <param name="inputs"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("/codeGenerate/delete")]
|
||||
public async Task DeleteCodeGen(List<DeleteCodeGenInput> inputs)
|
||||
{
|
||||
if (inputs == null || inputs.Count < 1) return;
|
||||
|
||||
var codeGenConfigTaskList = new List<Task>();
|
||||
inputs.ForEach(u =>
|
||||
{
|
||||
_sysCodeGenRep.Delete(u.Id);
|
||||
|
||||
// 删除配置表中
|
||||
codeGenConfigTaskList.Add(_codeGenConfigService.Delete(u.Id));
|
||||
});
|
||||
await Task.WhenAll(codeGenConfigTaskList);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("/codeGenerate/edit")]
|
||||
public async Task UpdateCodeGen(UpdateCodeGenInput input)
|
||||
{
|
||||
var isExist = await _sysCodeGenRep.DetachedEntities.AnyAsync(u => u.TableName == input.TableName && u.Id != input.Id);
|
||||
if (isExist)
|
||||
throw Oops.Oh(ErrorCode.D1400);
|
||||
|
||||
var codeGen = input.Adapt<SysCodeGen>();
|
||||
await codeGen.UpdateAsync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 详情
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("/codeGenerate/detail")]
|
||||
public async Task<SysCodeGen> GetCodeGen([FromQuery] QueryCodeGenInput input)
|
||||
{
|
||||
return await _sysCodeGenRep.DetachedEntities.FirstOrDefaultAsync(u => u.Id == input.Id);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取数据库表(实体)集合
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
|
||||
[HttpGet("/codeGenerate/InformationList")]
|
||||
public List<TableOutput> GetTableList()
|
||||
{
|
||||
return Db.GetDbContext().Model.GetEntityTypes().Select(u => new TableOutput
|
||||
{
|
||||
TableName = u.GetDefaultTableName(),
|
||||
TableComment = u.GetComment()
|
||||
}).ToList();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取数据表列(实体属性)集合
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[NonAction]
|
||||
public List<TableColumnOuput> GetColumnList(AddCodeGenInput input)
|
||||
{
|
||||
var entityType = Db.GetDbContext().Model.GetEntityTypes().FirstOrDefault(u => u.ClrType.Name == input.TableName);
|
||||
if (entityType == null) return null;
|
||||
|
||||
return entityType.GetProperties().Select(u => new TableColumnOuput
|
||||
{
|
||||
ColumnName = u.Name,
|
||||
ColumnKey = u.IsKey().ToString(),
|
||||
DataType = u.PropertyInfo.PropertyType.ToString(),
|
||||
ColumnComment = u.GetComment()
|
||||
}).ToList();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 代码生成_本地项目
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost("/codeGenerate/runLocal")]
|
||||
public async void RunLocal(SysCodeGen input)
|
||||
{
|
||||
var templatePathList = GetTemplatePathList();
|
||||
var targetPathList = GetTargetPathList(input);
|
||||
for (var i = 0; i < templatePathList.Count; i++)
|
||||
{
|
||||
var tContent = File.ReadAllText(templatePathList[i]);
|
||||
|
||||
var tableFieldList = await _codeGenConfigService.List(new CodeGenConfig() { CodeGenId = input.Id }); // 字段集合
|
||||
if (i >= 4) // 适应前端首字母小写
|
||||
{
|
||||
tableFieldList.ForEach(u =>
|
||||
{
|
||||
u.ColumnName = u.ColumnName.Substring(0, 1).ToLower() + u.ColumnName.Substring(1);
|
||||
});
|
||||
}
|
||||
var queryWhetherList = tableFieldList.Where(u => u.QueryWhether == YesOrNot.Y.ToString()).ToList(); // 前端查询集合
|
||||
var tResult = _viewEngine.RunCompileFromCached(tContent, new
|
||||
{
|
||||
input.AuthorName,
|
||||
input.BusName,
|
||||
input.NameSpace,
|
||||
ClassName = input.TableName,
|
||||
QueryWhetherList = queryWhetherList,
|
||||
TableField = tableFieldList
|
||||
});
|
||||
|
||||
var dirPath = new DirectoryInfo(targetPathList[i]).Parent.FullName;
|
||||
if (!Directory.Exists(dirPath))
|
||||
Directory.CreateDirectory(dirPath);
|
||||
File.WriteAllText(targetPathList[i], tResult, Encoding.UTF8);
|
||||
}
|
||||
|
||||
await AddMenu(input.TableName, input.BusName);
|
||||
}
|
||||
|
||||
private async Task AddMenu(string className, string busName)
|
||||
{
|
||||
// 先删除该表已生成的菜单列表
|
||||
var menus = await _sysMenuRep.DetachedEntities.Where(u => u.Code.StartsWith("dilon_" + className.ToLower())).ToListAsync();
|
||||
menus.ForEach(u =>
|
||||
{
|
||||
u.Delete();
|
||||
});
|
||||
var emptyGuid = System.Guid.Empty.ToString();
|
||||
// 目录
|
||||
var menuType0 = new SysMenu
|
||||
{
|
||||
Pid = emptyGuid,
|
||||
Pids = "["+ emptyGuid + "],",
|
||||
Name = busName + "管理",
|
||||
Code = "dilon_" + className.ToLower(),
|
||||
Type = 1,
|
||||
Icon = "robot",
|
||||
Router = "/" + className.ToLower(),
|
||||
Component = "PageView",
|
||||
Application = "busapp"
|
||||
};
|
||||
var pid0 = _sysMenuRep.InsertNowAsync(menuType0).GetAwaiter().GetResult().Entity.Id;
|
||||
|
||||
// 菜单
|
||||
var menuType1 = new SysMenu
|
||||
{
|
||||
Pid = pid0,
|
||||
Pids = "[0],[" + pid0 + "],",
|
||||
Name = busName + "管理",
|
||||
Code = "dilon_" + className.ToLower() + "_mgr",
|
||||
Type = 1,
|
||||
Router = "/" + className.ToLower(),
|
||||
Component = "main/" + className + "/index",
|
||||
Application = "busapp",
|
||||
OpenType = 1
|
||||
};
|
||||
var pid1 = _sysMenuRep.InsertNowAsync(menuType1).GetAwaiter().GetResult().Entity.Id;
|
||||
|
||||
// 按钮-page
|
||||
var menuType2 = new SysMenu
|
||||
{
|
||||
Pid = pid1,
|
||||
Pids = "[0],[" + pid0 + "],[" + pid1 + "],",
|
||||
Name = busName + "查询",
|
||||
Code = "dilon_" + className.ToLower() + "_mgr_page",
|
||||
Type = 2,
|
||||
Permission = className + ":page",
|
||||
Application = "busapp",
|
||||
}.InsertAsync();
|
||||
|
||||
// 按钮-detail
|
||||
var menuType2_1 = new SysMenu
|
||||
{
|
||||
Pid = pid1,
|
||||
Pids = "[0],[" + pid0 + "],[" + pid1 + "],",
|
||||
Name = busName + "详情",
|
||||
Code = "dilon_" + className.ToLower() + "_mgr_detail",
|
||||
Type = 2,
|
||||
Permission = className + ":detail",
|
||||
Application = "busapp",
|
||||
}.InsertAsync();
|
||||
|
||||
// 按钮-add
|
||||
var menuType2_2 = new SysMenu
|
||||
{
|
||||
Pid = pid1,
|
||||
Pids = "[0],[" + pid0 + "],[" + pid1 + "],",
|
||||
Name = busName + "增加",
|
||||
Code = "dilon_" + className.ToLower() + "_mgr_add",
|
||||
Type = 2,
|
||||
Permission = className + ":add",
|
||||
Application = "busapp",
|
||||
}.InsertAsync();
|
||||
|
||||
// 按钮-delete
|
||||
var menuType2_3 = new SysMenu
|
||||
{
|
||||
Pid = pid1,
|
||||
Pids = "[0],[" + pid0 + "],[" + pid1 + "],",
|
||||
Name = busName + "删除",
|
||||
Code = "dilon_" + className.ToLower() + "_mgr_delete",
|
||||
Type = 2,
|
||||
Permission = className + ":delete",
|
||||
Application = "busapp",
|
||||
}.InsertAsync();
|
||||
|
||||
// 按钮-edit
|
||||
var menuType2_4 = new SysMenu
|
||||
{
|
||||
Pid = pid1,
|
||||
Pids = "[0],[" + pid0 + "],[" + pid1 + "],",
|
||||
Name = busName + "编辑",
|
||||
Code = "dilon_" + className.ToLower() + "_mgr_edit",
|
||||
Type = 2,
|
||||
Permission = className + ":edit",
|
||||
Application = "busapp",
|
||||
}.InsertAsync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取模板文件路径集合
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
private List<string> GetTemplatePathList()
|
||||
{
|
||||
var templatePath = App.WebHostEnvironment.WebRootPath + @"\Template\";
|
||||
return new List<string>() {
|
||||
templatePath + "Service.cs.vm",
|
||||
templatePath + "IService.cs.vm",
|
||||
templatePath + "Input.cs.vm",
|
||||
templatePath + "Output.cs.vm",
|
||||
templatePath + "index.vue.vm",
|
||||
templatePath + "addForm.vue.vm",
|
||||
templatePath + "editForm.vue.vm",
|
||||
templatePath + "manage.js.vm",
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置生成文件路径
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
private List<string> GetTargetPathList(SysCodeGen input)
|
||||
{
|
||||
var backendPath = new DirectoryInfo(App.WebHostEnvironment.ContentRootPath).Parent.FullName + @"\Ewide.Application\Service\" + input.TableName + @"\";
|
||||
var servicePath = backendPath + input.TableName + "Service.cs";
|
||||
var iservicePath = backendPath + "I" + input.TableName + "Service.cs";
|
||||
var inputPath = backendPath + @"Dto\" + input.TableName + "Input.cs";
|
||||
var outputPath = backendPath + @"Dto\" + input.TableName + "Output.cs";
|
||||
var frontendPath = new DirectoryInfo(App.WebHostEnvironment.ContentRootPath).Parent.Parent.FullName + @"\frontend\src\views\main\";
|
||||
var indexPath = frontendPath + input.TableName + @"\index.vue";
|
||||
var addFormPath = frontendPath + input.TableName + @"\addForm.vue";
|
||||
var editFormPath = frontendPath + input.TableName + @"\editForm.vue";
|
||||
var apiJsPath = new DirectoryInfo(App.WebHostEnvironment.ContentRootPath).Parent.Parent.FullName + @"\frontend\src\api\modular\main\" + input.TableName + "Manage.js";
|
||||
|
||||
return new List<string>() {
|
||||
servicePath,
|
||||
iservicePath,
|
||||
inputPath,
|
||||
outputPath,
|
||||
indexPath,
|
||||
addFormPath,
|
||||
editFormPath,
|
||||
apiJsPath
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
namespace Ewide.Core.Service
|
||||
{
|
||||
/// <summary>
|
||||
/// 代码生成详细配置参数
|
||||
/// </summary>
|
||||
public class CodeGenConfig
|
||||
{
|
||||
/// <summary>
|
||||
/// 主键
|
||||
/// </summary>
|
||||
public string Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 代码生成主表ID
|
||||
/// </summary>
|
||||
public string CodeGenId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 数据库字段名
|
||||
/// </summary>
|
||||
public string ColumnName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 字段描述
|
||||
/// </summary>
|
||||
public string ColumnComment { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// .NET类型
|
||||
/// </summary>
|
||||
public string NetType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 作用类型(字典)
|
||||
/// </summary>
|
||||
public string EffectType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 字典code
|
||||
/// </summary>
|
||||
public string DictTypeCode { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 列表是否缩进(字典)
|
||||
/// </summary>
|
||||
public string WhetherRetract { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否必填(字典)
|
||||
/// </summary>
|
||||
public string WhetherRequired { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否是查询条件
|
||||
/// </summary>
|
||||
public string QueryWhether { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 查询方式
|
||||
/// </summary>
|
||||
public string QueryType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 列表显示
|
||||
/// </summary>
|
||||
public string WhetherTable { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 增改
|
||||
/// </summary>
|
||||
public string WhetherAddUpdate { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 主外键
|
||||
/// </summary>
|
||||
public string ColumnKey { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 数据库中类型(物理类型)
|
||||
/// </summary>
|
||||
public string DataType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否是通用字段
|
||||
/// </summary>
|
||||
public string WhetherCommon { get; set; }
|
||||
}
|
||||
}
|
||||
124
20220330_Vote/Ewide.Core/Service/CodeGen/Dto/CodeGenInput.cs
Normal file
124
20220330_Vote/Ewide.Core/Service/CodeGen/Dto/CodeGenInput.cs
Normal file
@@ -0,0 +1,124 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace Ewide.Core.Service
|
||||
{
|
||||
/// <summary>
|
||||
/// 代码生成参数类
|
||||
/// </summary>
|
||||
public class CodeGenInput : InputBase
|
||||
{
|
||||
/// <summary>
|
||||
/// 作者姓名
|
||||
/// </summary>
|
||||
public virtual string AuthorName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 类名
|
||||
/// </summary>
|
||||
public virtual string ClassName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否移除表前缀
|
||||
/// </summary>
|
||||
public virtual string TablePrefix { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 生成方式
|
||||
/// </summary>
|
||||
public virtual string GenerateType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 数据库表名
|
||||
/// </summary>
|
||||
public virtual string TableName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 命名空间
|
||||
/// </summary>
|
||||
public virtual string NameSpace { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 业务名(业务代码包名称)
|
||||
/// </summary>
|
||||
public virtual string BusName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 功能名(数据库表名称)
|
||||
/// </summary>
|
||||
public virtual string TableComment { get; set; }
|
||||
}
|
||||
|
||||
public class AddCodeGenInput : CodeGenInput
|
||||
{
|
||||
/// <summary>
|
||||
/// 数据库表名
|
||||
/// </summary>
|
||||
[Required(ErrorMessage = "数据库表名不能为空")]
|
||||
public override string TableName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 业务名(业务代码包名称)
|
||||
/// </summary>
|
||||
[Required(ErrorMessage = "业务名不能为空")]
|
||||
public override string BusName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 命名空间
|
||||
/// </summary>
|
||||
[Required(ErrorMessage = "命名空间不能为空")]
|
||||
public override string NameSpace { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 作者姓名
|
||||
/// </summary>
|
||||
[Required(ErrorMessage = "作者姓名不能为空")]
|
||||
public override string AuthorName { get; set; }
|
||||
|
||||
///// <summary>
|
||||
///// 类名
|
||||
///// </summary>
|
||||
//[Required(ErrorMessage = "类名不能为空")]
|
||||
//public override string ClassName { get; set; }
|
||||
|
||||
///// <summary>
|
||||
///// 是否移除表前缀
|
||||
///// </summary>
|
||||
//[Required(ErrorMessage = "是否移除表前缀不能为空")]
|
||||
//public override string TablePrefix { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 生成方式
|
||||
/// </summary>
|
||||
[Required(ErrorMessage = "生成方式不能为空")]
|
||||
public override string GenerateType { get; set; }
|
||||
|
||||
///// <summary>
|
||||
///// 功能名(数据库表名称)
|
||||
///// </summary>
|
||||
//[Required(ErrorMessage = "数据库表名不能为空")]
|
||||
//public override string TableComment { get; set; }
|
||||
}
|
||||
|
||||
public class DeleteCodeGenInput
|
||||
{
|
||||
/// <summary>
|
||||
/// 代码生成器Id
|
||||
/// </summary>
|
||||
[Required(ErrorMessage = "代码生成器Id不能为空")]
|
||||
public string Id { get; set; }
|
||||
}
|
||||
|
||||
public class UpdateCodeGenInput : CodeGenInput
|
||||
{
|
||||
/// <summary>
|
||||
/// 代码生成器Id
|
||||
/// </summary>
|
||||
[Required(ErrorMessage = "代码生成器Id不能为空")]
|
||||
public string Id { get; set; }
|
||||
}
|
||||
|
||||
public class QueryCodeGenInput : DeleteCodeGenInput
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
namespace Ewide.Core.Service
|
||||
{
|
||||
/// <summary>
|
||||
/// 代码生成参数类
|
||||
/// </summary>
|
||||
public class CodeGenOutput
|
||||
{
|
||||
/// <summary>
|
||||
/// 代码生成器Id
|
||||
/// </summary>
|
||||
public long Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 作者姓名
|
||||
/// </summary>
|
||||
public string AuthorName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 类名
|
||||
/// </summary>
|
||||
public string ClassName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否移除表前缀
|
||||
/// </summary>
|
||||
public string TablePrefix { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 生成方式
|
||||
/// </summary>
|
||||
public string GenerateType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 数据库表名
|
||||
/// </summary>
|
||||
public string TableName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 包名
|
||||
/// </summary>
|
||||
public string PackageName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 业务名(业务代码包名称)
|
||||
/// </summary>
|
||||
public string BusName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 功能名(数据库表名称)
|
||||
/// </summary>
|
||||
public string TableComment { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
namespace Ewide.Core.Service
|
||||
{
|
||||
/// <summary>
|
||||
/// 数据库表列
|
||||
/// </summary>
|
||||
public class TableColumnOuput
|
||||
{
|
||||
/// <summary>
|
||||
/// 字段名
|
||||
/// </summary>
|
||||
public string ColumnName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 数据库中类型
|
||||
/// </summary>
|
||||
public string DataType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 字段描述
|
||||
/// </summary>
|
||||
public string ColumnComment { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 主外键
|
||||
/// </summary>
|
||||
public string ColumnKey { get; set; }
|
||||
}
|
||||
}
|
||||
28
20220330_Vote/Ewide.Core/Service/CodeGen/Dto/TableOutput.cs
Normal file
28
20220330_Vote/Ewide.Core/Service/CodeGen/Dto/TableOutput.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
namespace Ewide.Core.Service
|
||||
{
|
||||
/// <summary>
|
||||
/// 数据库表列表参数
|
||||
/// </summary>
|
||||
public class TableOutput
|
||||
{
|
||||
/// <summary>
|
||||
/// 表名(字母形式的)
|
||||
/// </summary>
|
||||
public string TableName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 创建时间
|
||||
/// </summary>
|
||||
public string CreateTime { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 更新时间
|
||||
/// </summary>
|
||||
public string UpdateTime { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 表名称描述(注释)(功能名)
|
||||
/// </summary>
|
||||
public string TableComment { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Ewide.Core.Service
|
||||
{
|
||||
public interface ICodeGenConfigService
|
||||
{
|
||||
Task Add(CodeGenConfig input);
|
||||
void AddList(List<TableColumnOuput> tableColumnOuputList, SysCodeGen codeGenerate);
|
||||
string ConvertDataType(string dataType);
|
||||
Task Delete(string codeGenId);
|
||||
Task<SysCodeGenConfig> Detail(CodeGenConfig input);
|
||||
Task<List<CodeGenConfig>> List([FromQuery] CodeGenConfig input);
|
||||
Task Update(List<CodeGenConfig> inputList);
|
||||
}
|
||||
}
|
||||
18
20220330_Vote/Ewide.Core/Service/CodeGen/ICodeGenService.cs
Normal file
18
20220330_Vote/Ewide.Core/Service/CodeGen/ICodeGenService.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Ewide.Core.Service.CodeGen
|
||||
{
|
||||
public interface ICodeGenService
|
||||
{
|
||||
Task AddCodeGen(AddCodeGenInput input);
|
||||
Task DeleteCodeGen(List<DeleteCodeGenInput> inputs);
|
||||
Task<SysCodeGen> GetCodeGen([FromQuery] QueryCodeGenInput input);
|
||||
List<TableColumnOuput> GetColumnList(AddCodeGenInput input);
|
||||
List<TableOutput> GetTableList();
|
||||
Task<dynamic> QueryCodeGenPageList([FromQuery] CodeGenInput input);
|
||||
void RunLocal(SysCodeGen input);
|
||||
Task UpdateCodeGen(UpdateCodeGenInput input);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user