优化代码生成模板

This commit is contained in:
不做码农 2023-05-18 18:29:49 +08:00
parent 07ea3d1c48
commit 01e7fbd94f
10 changed files with 32 additions and 39 deletions

View File

@ -11,14 +11,11 @@ using ${options.ApiControllerNamespace}.Extensions;
using ${options.ApiControllerNamespace}.Filters; using ${options.ApiControllerNamespace}.Filters;
using ${options.BaseNamespace}Common; using ${options.BaseNamespace}Common;
//创建时间:${replaceDto.AddTime}
namespace ${options.ApiControllerNamespace}.Controllers namespace ${options.ApiControllerNamespace}.Controllers
{ {
/// <summary> /// <summary>
/// ${genTable.functionName}Controller /// ${genTable.functionName}
///
/// @tableName ${genTable.TableName}
/// @author ${replaceDto.Author}
/// @date ${replaceDto.AddTime}
/// </summary> /// </summary>
[Verify] [Verify]
[Route("${genTable.ModuleName}/${genTable.BusinessName}")] [Route("${genTable.ModuleName}/${genTable.BusinessName}")]
@ -120,7 +117,7 @@ $if(replaceDto.ShowBtnEdit)
} }
$end $end
$if(replaceDto.ShowBtnDelete) $if(replaceDto.ShowBtnDelete || replaceDto.ShowBtnMultiDel)
/// <summary> /// <summary>
/// 删除${genTable.FunctionName} /// 删除${genTable.FunctionName}
/// </summary> /// </summary>
@ -169,15 +166,13 @@ $if(replaceDto.ShowBtnTruncate)
[Log(Title = "${genTable.FunctionName}", BusinessType = BusinessType.CLEAN)] [Log(Title = "${genTable.FunctionName}", BusinessType = BusinessType.CLEAN)]
[ActionPermissionFilter(Permission = "${replaceDto.PermissionPrefix}:delete")] [ActionPermissionFilter(Permission = "${replaceDto.PermissionPrefix}:delete")]
[HttpDelete("clean")] [HttpDelete("clean")]
public ApiResult Clear() public IActionResult Clear()
{ {
if (!HttpContextExtension.IsAdmin(HttpContext)) if (!HttpContextExtension.IsAdmin(HttpContext))
{ {
return ApiResult.Error("操作失败"); return ToResponse(ResultCode.FAIL, "操作失败");
} }
_${replaceDto.ModelTypeName}Service.Truncate${replaceDto.ModelTypeName}(); return SUCCESS(_${replaceDto.ModelTypeName}Service.Truncate${replaceDto.ModelTypeName}());
return ToJson(1);
} }
$end $end
@ -196,7 +191,6 @@ $if(showCustomInput)
if (id <= 0) { return ToResponse(ApiResult.Error(101, "请求参数错误")); } if (id <= 0) { return ToResponse(ApiResult.Error(101, "请求参数错误")); }
var response = _${replaceDto.ModelTypeName}Service.Update(w => w.${replaceDto.PKName} == id, it => new ${replaceDto.ModelTypeName}() var response = _${replaceDto.ModelTypeName}Service.Update(w => w.${replaceDto.PKName} == id, it => new ${replaceDto.ModelTypeName}()
{ {
//Update 字段映射
$foreach(item in genTable.Columns) $foreach(item in genTable.Columns)
$if((item.htmlType == "customInput")) $if((item.htmlType == "customInput"))
$item.CsharpField = value, $item.CsharpField = value,

View File

@ -8,9 +8,6 @@ namespace ${options.IServicsNamespace}.${options.SubNamespace}.I${options.SubNam
{ {
/// <summary> /// <summary>
/// ${genTable.FunctionName}service接口 /// ${genTable.FunctionName}service接口
///
/// @author ${replaceDto.Author}
/// @date ${replaceDto.AddTime}
/// </summary> /// </summary>
public interface I${replaceDto.ModelTypeName}Service : IBaseService<${replaceDto.ModelTypeName}> public interface I${replaceDto.ModelTypeName}Service : IBaseService<${replaceDto.ModelTypeName}>
{ {
@ -23,7 +20,7 @@ $end
int Update${replaceDto.ModelTypeName}(${replaceDto.ModelTypeName} parm); int Update${replaceDto.ModelTypeName}(${replaceDto.ModelTypeName} parm);
$if(replaceDto.ShowBtnTruncate) $if(replaceDto.ShowBtnTruncate)
void Truncate${replaceDto.ModelTypeName}(); bool Truncate${replaceDto.ModelTypeName}();
$end $end
} }
} }

View File

@ -9,8 +9,6 @@ namespace ${options.ModelsNamespace}.${options.SubNamespace}
{ {
/// <summary> /// <summary>
/// ${genTable.FunctionName} /// ${genTable.FunctionName}
/// @author ${replaceDto.Author}
/// @date ${replaceDto.AddTime}
/// </summary> /// </summary>
[SugarTable("${genTable.TableName}")] [SugarTable("${genTable.TableName}")]
public class ${replaceDto.ModelTypeName} public class ${replaceDto.ModelTypeName}

View File

@ -5,9 +5,6 @@ namespace ${options.RepositoriesNamespace}
{ {
/// <summary> /// <summary>
/// ${genTable.FunctionName}仓储 /// ${genTable.FunctionName}仓储
///
/// @author ${replaceDto.Author}
/// @date ${replaceDto.AddTime}
/// </summary> /// </summary>
[AppService(ServiceLifetime = LifeTime.Transient)] [AppService(ServiceLifetime = LifeTime.Transient)]
public class ${replaceDto.ModelTypeName}Repository : BaseRepository<${replaceDto.ModelTypeName}> public class ${replaceDto.ModelTypeName}Repository : BaseRepository<${replaceDto.ModelTypeName}>

View File

@ -15,9 +15,6 @@ namespace ${options.ServicesNamespace}.${options.SubNamespace}
{ {
/// <summary> /// <summary>
/// ${genTable.FunctionName}Service业务层处理 /// ${genTable.FunctionName}Service业务层处理
///
/// @author ${replaceDto.Author}
/// @date ${replaceDto.AddTime}
/// </summary> /// </summary>
[AppService(ServiceType = typeof(I${replaceDto.ModelTypeName}Service), ServiceLifetime = LifeTime.Transient)] [AppService(ServiceType = typeof(I${replaceDto.ModelTypeName}Service), ServiceLifetime = LifeTime.Transient)]
public class ${replaceDto.ModelTypeName}Service : BaseService<${replaceDto.ModelTypeName}>, I${replaceDto.ModelTypeName}Service public class ${replaceDto.ModelTypeName}Service : BaseService<${replaceDto.ModelTypeName}>, I${replaceDto.ModelTypeName}Service
@ -124,9 +121,15 @@ $if(replaceDto.ShowBtnTruncate)
/// 清空${genTable.FunctionName} /// 清空${genTable.FunctionName}
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
public void Truncate${replaceDto.ModelTypeName}() public bool Truncate${replaceDto.ModelTypeName}()
{ {
Truncate(); var newTableName = $"${genTable.TableName}_{DateTime.Now:yyyyMMdd}";
if (Queryable().Any() && !Context.DbMaintenance.IsAnyTable(newTableName))
{
Context.DbMaintenance.BackupTable("${genTable.TableName}", newTableName);
}
return Truncate();
} }
$end $end
} }

View File

@ -73,7 +73,7 @@ export function get${genTable.BusinessName}(id) {
}) })
} }
$if(replaceDto.ShowBtnDelete) $if(replaceDto.ShowBtnDelete || replaceDto.ShowBtnMultiDel)
/** /**
* 删除${genTable.functionName} * 删除${genTable.functionName}
* @param {主键} pid * @param {主键} pid

View File

@ -17,8 +17,10 @@ VALUES ('新增', @menuId, 2, '#', NULL, 0, 0, 'F', '0', '0', '${replaceDto.Perm
INSERT INTO sys_menu(menuName, parentId, orderNum, path, component, isFrame, isCache, menuType, visible, status, perms, icon, create_by, create_time) INSERT INTO sys_menu(menuName, parentId, orderNum, path, component, isFrame, isCache, menuType, visible, status, perms, icon, create_by, create_time)
VALUES ('删除', @menuId, 3, '#', NULL, 0, 0, 'F', '0', '0', '${replaceDto.PermissionPrefix}:delete', '', 'system', sysdate()); VALUES ('删除', @menuId, 3, '#', NULL, 0, 0, 'F', '0', '0', '${replaceDto.PermissionPrefix}:delete', '', 'system', sysdate());
$if(replaceDto.ShowBtnEdit)
INSERT INTO sys_menu(menuName, parentId, orderNum, path, component, isFrame, isCache, menuType, visible, status, perms, icon, create_by, create_time) INSERT INTO sys_menu(menuName, parentId, orderNum, path, component, isFrame, isCache, menuType, visible, status, perms, icon, create_by, create_time)
VALUES ('修改', @menuId, 4, '#', NULL, 0, 0, 'F', '0', '0', '${replaceDto.PermissionPrefix}:edit', '', 'system', sysdate()); VALUES ('修改', @menuId, 4, '#', NULL, 0, 0, 'F', '0', '0', '${replaceDto.PermissionPrefix}:edit', '', 'system', sysdate());
$end
$if(replaceDto.ShowBtnExport) $if(replaceDto.ShowBtnExport)
INSERT INTO sys_menu(menuName, parentId, orderNum, path, component, isFrame, isCache, menuType, visible, status, perms, icon, create_by, create_time) INSERT INTO sys_menu(menuName, parentId, orderNum, path, component, isFrame, isCache, menuType, visible, status, perms, icon, create_by, create_time)

View File

@ -17,9 +17,10 @@ VALUES ('新增', @menuId, 2, '#', NULL, 0, 0, 'F', '0', '0', '${replaceDto.Perm
INSERT INTO sys_menu(menuName, parentId, orderNum, path, component, isFrame, isCache, menuType, visible, status, perms, icon, create_by,create_time) INSERT INTO sys_menu(menuName, parentId, orderNum, path, component, isFrame, isCache, menuType, visible, status, perms, icon, create_by,create_time)
VALUES ('删除', @menuId, 3, '#', NULL, 0, 0, 'F', '0', '0', '${replaceDto.PermissionPrefix}:delete', '', 'system', GETDATE()); VALUES ('删除', @menuId, 3, '#', NULL, 0, 0, 'F', '0', '0', '${replaceDto.PermissionPrefix}:delete', '', 'system', GETDATE());
$if(replaceDto.ShowBtnEdit)
INSERT INTO sys_menu(menuName, parentId, orderNum, path, component, isFrame, isCache, menuType, visible, status, perms, icon, create_by,create_time) INSERT INTO sys_menu(menuName, parentId, orderNum, path, component, isFrame, isCache, menuType, visible, status, perms, icon, create_by,create_time)
VALUES ('修改', @menuId, 4, '#', NULL, 0, 0, 'F', '0', '0', '${replaceDto.PermissionPrefix}:edit', '', 'system', GETDATE()); VALUES ('修改', @menuId, 4, '#', NULL, 0, 0, 'F', '0', '0', '${replaceDto.PermissionPrefix}:edit', '', 'system', GETDATE());
$end
$if(replaceDto.ShowBtnExport) $if(replaceDto.ShowBtnExport)
INSERT INTO sys_menu(menuName, parentId, orderNum, path, component, isFrame, isCache, menuType, visible, status, perms, icon, create_by,create_time) INSERT INTO sys_menu(menuName, parentId, orderNum, path, component, isFrame, isCache, menuType, visible, status, perms, icon, create_by,create_time)
VALUES ('导出', @menuId, 5, '#', NULL, 0, 0, 'F', '0', '0', '${replaceDto.PermissionPrefix}:export', '', 'system', GETDATE()); VALUES ('导出', @menuId, 5, '#', NULL, 0, 0, 'F', '0', '0', '${replaceDto.PermissionPrefix}:export', '', 'system', GETDATE());

View File

@ -1,10 +1,7 @@
<!-- <!--
* @Descripttion: (${genTable.functionName}/${genTable.tableName}) * @Descripttion: (${genTable.functionName}/${genTable.tableName})
* @version: (1.0)
* @Author: (${replaceDto.Author}) * @Author: (${replaceDto.Author})
* @Date: (${replaceDto.AddTime}) * @Date: (${replaceDto.AddTime})
* @LastEditors: (${replaceDto.Author})
* @LastEditTime: (${replaceDto.AddTime})
--> -->
<template> <template>
<div> <div>
@ -70,7 +67,7 @@ $end
<el-col :span="1.5"> <el-col :span="1.5">
<el-button type="info" plain icon="sort" @click="toggleExpandAll">展开/折叠</el-button> <el-button type="info" plain icon="sort" @click="toggleExpandAll">展开/折叠</el-button>
</el-col> </el-col>
$if(replaceDto.ShowBtnDelete) $if(replaceDto.ShowBtnMultiDel)
<el-col :span="1.5"> <el-col :span="1.5">
<el-button type="danger" :disabled="multiple" v-hasPermi="['${replaceDto.PermissionPrefix}:delete']" plain icon="delete" @click="handleDelete"> <el-button type="danger" :disabled="multiple" v-hasPermi="['${replaceDto.PermissionPrefix}:delete']" plain icon="delete" @click="handleDelete">
{{ ${t}t('btn.delete') }} {{ ${t}t('btn.delete') }}
@ -295,7 +292,11 @@ $end
</template> </template>
<script setup name="${genTable.BusinessName.ToLower()}"> <script setup name="${genTable.BusinessName.ToLower()}">
import { treelist${genTable.BusinessName}, list${genTable.BusinessName}, add${genTable.BusinessName}, del${genTable.BusinessName}, update${genTable.BusinessName}, get${genTable.BusinessName}, import { treelist${genTable.BusinessName}, list${genTable.BusinessName},
$if(replaceDto.ShowBtnAdd) add${genTable.BusinessName}, $end
$if(replaceDto.ShowBtnDelete || replaceDto.ShowBtnMultiDel)del${genTable.BusinessName},$end
$if(replaceDto.ShowBtnEdit) update${genTable.BusinessName},$end
get${genTable.BusinessName},
$if(showCustomInput) changeSort $end } from '@/api/${tool.FirstLowerCase(genTable.ModuleName)}/${genTable.BusinessName.ToLower()}.js' $if(showCustomInput) changeSort $end } from '@/api/${tool.FirstLowerCase(genTable.ModuleName)}/${genTable.BusinessName.ToLower()}.js'
$if(replaceDto.ShowEditor == 1) $if(replaceDto.ShowEditor == 1)
import Editor from '@/components/Editor' import Editor from '@/components/Editor'

View File

@ -1,10 +1,7 @@
<!-- <!--
* @Descripttion: (${genTable.functionName}/${genTable.tableName}) * @Descripttion: (${genTable.functionName}/${genTable.tableName})
* @version: (1.0)
* @Author: (${replaceDto.Author}) * @Author: (${replaceDto.Author})
* @Date: (${replaceDto.AddTime}) * @Date: (${replaceDto.AddTime})
* @LastEditors: (${replaceDto.Author})
* @LastEditTime: (${replaceDto.AddTime})
--> -->
<template> <template>
<div> <div>
@ -340,7 +337,11 @@ $end
</template> </template>
<script setup name="${genTable.BusinessName.ToLower()}"> <script setup name="${genTable.BusinessName.ToLower()}">
import { list${genTable.BusinessName}, add${genTable.BusinessName}, del${genTable.BusinessName}, update${genTable.BusinessName}, get${genTable.BusinessName}, import { list${genTable.BusinessName},
$if(replaceDto.ShowBtnAdd) add${genTable.BusinessName}, $end
$if(replaceDto.ShowBtnDelete || replaceDto.ShowBtnMultiDel)del${genTable.BusinessName},$end
$if(replaceDto.ShowBtnEdit) update${genTable.BusinessName},$end
get${genTable.BusinessName},
$if(replaceDto.ShowBtnTruncate) clear${genTable.BusinessName}, $end $if(replaceDto.ShowBtnTruncate) clear${genTable.BusinessName}, $end
$if(showCustomInput) changeSort $end } $if(showCustomInput) changeSort $end }
from '@/api/${tool.FirstLowerCase(genTable.ModuleName)}/${genTable.BusinessName.ToLower()}.js' from '@/api/${tool.FirstLowerCase(genTable.ModuleName)}/${genTable.BusinessName.ToLower()}.js'
@ -349,7 +350,6 @@ import Editor from '@/components/Editor'
$end $end
const { proxy } = getCurrentInstance() const { proxy } = getCurrentInstance()
// 选中${replaceDto.FistLowerPk}数组
const ids = ref([]) const ids = ref([])
const loading = ref(false) const loading = ref(false)
const showSearch = ref(true) const showSearch = ref(true)