开发代码生成功能
This commit is contained in:
@@ -9,9 +9,9 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using ZR.CodeGenerator;
|
||||
using ZR.CodeGenerator.Model;
|
||||
using ZR.CodeGenerator.Service;
|
||||
using ZR.Model;
|
||||
using ZR.Model.CodeGenerator;
|
||||
using ZR.Model.Vo;
|
||||
using ZR.Service.IService;
|
||||
using ZR.Service.System;
|
||||
@@ -21,7 +21,7 @@ namespace ZR.Admin.WebApi.Controllers
|
||||
/// <summary>
|
||||
/// 代码生成
|
||||
/// </summary>
|
||||
[Route("codeGenerator")]
|
||||
[Route("tool/gen")]
|
||||
public class CodeGeneratorController : BaseController
|
||||
{
|
||||
//public ICodeGeneratorService CodeGeneratorService;
|
||||
@@ -35,11 +35,13 @@ namespace ZR.Admin.WebApi.Controllers
|
||||
/// 获取所有数据库的信息
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet("GetListDataBase")]
|
||||
[HttpGet("getDbList")]
|
||||
//[YuebonAuthorize("GetListDataBase")]
|
||||
public IActionResult GetListDataBase()
|
||||
{
|
||||
return SUCCESS(_CodeGeneraterService.GetAllDataBases());
|
||||
var dbList = _CodeGeneraterService.GetAllDataBases();
|
||||
var defaultDb = dbList.Count > 0 ? dbList[0] : null;
|
||||
return SUCCESS(new { dbList, defaultDb });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -59,27 +61,35 @@ namespace ZR.Admin.WebApi.Controllers
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 代码生成器
|
||||
/// 获取表格列
|
||||
/// </summary>
|
||||
/// <param name="dbName"></param>
|
||||
/// <param name="tables">要生成代码的表</param>
|
||||
/// <param name="baseSpace">项目命名空间</param>
|
||||
/// <param name="replaceTableNameStr">要删除表名的字符串用英文逗号","隔开</param>
|
||||
/// <param name="tableName"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("QueryColumnInfo")]
|
||||
public IActionResult QueryColumnInfo(string dbName, string tableName)
|
||||
{
|
||||
if (string.IsNullOrEmpty(dbName) || string.IsNullOrEmpty(tableName))
|
||||
return ToRespose(ResultCode.PARAM_ERROR);
|
||||
|
||||
return SUCCESS(_CodeGeneraterService.GetColumnInfo(dbName, tableName));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 代码生成器
|
||||
/// </summary>
|
||||
/// <param name="dto">数据传输对象</param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("Generate")]
|
||||
[Log(Title = "代码生成", BusinessType = BusinessType.OTHER)]
|
||||
public IActionResult Generate(string dbName, string baseSpace, string tables, string replaceTableNameStr)
|
||||
public IActionResult Generate([FromQuery] GenerateDto dto)
|
||||
{
|
||||
if (string.IsNullOrEmpty(tables))
|
||||
if (string.IsNullOrEmpty(dto.tables))
|
||||
{
|
||||
throw new CustomException(ResultCode.CUSTOM_ERROR, "请求参数为空");
|
||||
}
|
||||
if (string.IsNullOrEmpty(baseSpace))
|
||||
{
|
||||
baseSpace = "ZR.Admin";
|
||||
}
|
||||
DbTableInfo dbTableInfo = new() { Name = tables };
|
||||
CodeGeneratorTool.Generate(dbName, baseSpace, dbTableInfo, replaceTableNameStr, true);
|
||||
DbTableInfo dbTableInfo = new() { Name = dto.tables };
|
||||
CodeGeneratorTool.Generate(dbTableInfo, dto);
|
||||
|
||||
return SUCCESS(1);
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ using ZR.Model;
|
||||
namespace ZRAdmin.Controllers
|
||||
{
|
||||
/// <summary>
|
||||
/// T4代码自动生成
|
||||
/// 代码自动生成
|
||||
/// </summary>
|
||||
|
||||
[Verify]
|
||||
@@ -39,7 +39,7 @@ namespace ZRAdmin.Controllers
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet("list")]
|
||||
[ActionPermissionFilter(Permission = "<#=ModelName#>:list")]
|
||||
[ActionPermissionFilter(Permission = "<#=Permission#>:list")]
|
||||
public IActionResult Query([FromQuery] <#=ModelName#>QueryDto parm)
|
||||
{
|
||||
//开始拼装查询条件
|
||||
@@ -59,7 +59,7 @@ namespace ZRAdmin.Controllers
|
||||
/// <param name="{primaryKey}"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("{{primaryKey}}")]
|
||||
public IActionResult Get(int {primaryKey})
|
||||
public IActionResult Get({KeyTypeName} {primaryKey})
|
||||
{
|
||||
var response = _<#=ServiceName#>.GetId({primaryKey});
|
||||
|
||||
@@ -71,7 +71,7 @@ namespace ZRAdmin.Controllers
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[ActionPermissionFilter(Permission = "<#=ModelName#>:add")]
|
||||
[ActionPermissionFilter(Permission = "<#=Permission#>:add")]
|
||||
[Log(Title = "<#=FileName#>添加", BusinessType = BusinessType.INSERT)]
|
||||
public IActionResult Create([FromBody] <#=ModelName#>Dto parm)
|
||||
{
|
||||
@@ -91,7 +91,7 @@ namespace ZRAdmin.Controllers
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPut("edit")]
|
||||
[ActionPermissionFilter(Permission = "<#=ModelName#>:update")]
|
||||
[ActionPermissionFilter(Permission = "<#=Permission#>:update")]
|
||||
[Log(Title = "<#=FileName#>修改", BusinessType = BusinessType.UPDATE)]
|
||||
public IActionResult Update([FromBody] <#=ModelName#>Dto parm)
|
||||
{
|
||||
@@ -109,9 +109,9 @@ namespace ZRAdmin.Controllers
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpDelete("{{primaryKey}}")]
|
||||
[ActionPermissionFilter(Permission = "<#=ModelName#>:delete")]
|
||||
[ActionPermissionFilter(Permission = "<#=Permission#>:delete")]
|
||||
[Log(Title = "<#=FileName#>删除", BusinessType = BusinessType.DELETE)]
|
||||
public IActionResult Delete(int {primaryKey} = 0)
|
||||
public IActionResult Delete({KeyTypeName} {primaryKey} = 0)
|
||||
{
|
||||
if ({primaryKey} <= 0) { return OutputJson(ApiResult.Error($"删除失败Id 不能为空")); }
|
||||
|
||||
|
||||
@@ -62,7 +62,7 @@
|
||||
<el-button size="mini" type="text" icon="el-icon-view" @click="handleView(scope.row)">详情</el-button>
|
||||
<el-button size="mini" v-hasPermi="['{ModelTypeName}:update']" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)">编辑</el-button>
|
||||
<el-popconfirm title="确定删除吗?" @onConfirm="handleDelete(scope.row)" style="margin-left:10px">
|
||||
<el-button slot="reference" v-hasPermi="['{ModelTypeName}:del']" size="mini" type="text" icon="el-icon-delete">删除</el-button>
|
||||
<el-button slot="reference" v-hasPermi="['{ModelTypeName}:delete']" size="mini" type="text" icon="el-icon-delete">删除</el-button>
|
||||
</el-popconfirm>
|
||||
</template>
|
||||
</el-table-column>
|
||||
@@ -83,7 +83,7 @@
|
||||
</div>
|
||||
</template>
|
||||
<script>
|
||||
// import { list{ModelTypeName},add{ModelTypeName},del{ModelTypeName},edit{ModelTypeName} } from '@/api/{ModelTypeName}.js'
|
||||
import { list{ModelTypeName},add{ModelTypeName},del{ModelTypeName},edit{ModelTypeName} } from '@{ModelTypeName}.js'
|
||||
|
||||
export default {
|
||||
name: '{ModelTypeName}',
|
||||
@@ -197,10 +197,7 @@ export default {
|
||||
|
||||
// TODO 给表单赋值
|
||||
this.form = {
|
||||
content: row.content,
|
||||
userId: row.userId,
|
||||
name: row.name,
|
||||
sortId: row.sortId,
|
||||
{VueViewEditFromBindContent}
|
||||
};
|
||||
},
|
||||
/** 提交按钮 */
|
||||
|
||||
Reference in New Issue
Block a user