代码生成新增加排序字段

This commit is contained in:
不做码农 2021-12-01 21:03:27 +08:00
parent 5a03ce182b
commit 31b2681028
14 changed files with 106 additions and 50 deletions

View File

@ -101,7 +101,7 @@ namespace ZR.Admin.WebApi.Controllers
{
var tableColumns = GenTableColumnService.GenTableColumns(tableId);
var tableInfo = GenTableService.GetGenTableInfo(tableId);
return SUCCESS(new { result = tableColumns, info = tableInfo });
return SUCCESS(new { cloumns = tableColumns, info = tableInfo });
}
/// <summary>
@ -188,7 +188,12 @@ namespace ZR.Admin.WebApi.Controllers
if (genTableDto == null) throw new CustomException("请求参数错误");
var genTable = genTableDto.Adapt<GenTable>().ToUpdate(HttpContext);
genTable.Options = JsonConvert.SerializeObject(new { parentMenuId = genTableDto.ParentMenuId });
genTable.Options = JsonConvert.SerializeObject(new
{
parentMenuId = genTableDto.ParentMenuId,
sortField = genTableDto.SortField,
sortType = genTable.SortType
});
int rows = GenTableService.UpdateGenTable(genTable);
if (rows > 0)
{

View File

@ -7,19 +7,19 @@ SELECT @menuId := LAST_INSERT_ID();
INSERT INTO sys_menu(menuName, parentId, orderNum, path, component, isFrame, isCache, menuType, visible, status, perms, icon, create_time)
VALUES ('${genTable.functionName}查询', @menuId, 1, '#', NULL, 0, 0, 'F', '0', '0', '${replaceDto.PermissionPrefix}:query', '', sysdate());
VALUES ('查询', @menuId, 1, '#', NULL, 0, 0, 'F', '0', '0', '${replaceDto.PermissionPrefix}:query', '', sysdate());
INSERT INTO sys_menu(menuName, parentId, orderNum, path, component, isFrame, isCache, menuType, visible, status, perms, icon, create_time)
VALUES ('${genTable.functionName}新增', @menuId, 2, '#', NULL, 0, 0, 'F', '0', '0', '${replaceDto.PermissionPrefix}:add', '', sysdate());
VALUES ('新增', @menuId, 2, '#', NULL, 0, 0, 'F', '0', '0', '${replaceDto.PermissionPrefix}:add', '', sysdate());
INSERT INTO sys_menu(menuName, parentId, orderNum, path, component, isFrame, isCache, menuType, visible, status, perms, icon, create_time)
VALUES ('${genTable.functionName}删除', @menuId, 3, '#', NULL, 0, 0, 'F', '0', '0', '${replaceDto.PermissionPrefix}:delete', '', sysdate());
VALUES ('删除', @menuId, 3, '#', NULL, 0, 0, 'F', '0', '0', '${replaceDto.PermissionPrefix}:delete', '', sysdate());
INSERT INTO sys_menu(menuName, parentId, orderNum, path, component, isFrame, isCache, menuType, visible, status, perms, icon, create_time)
VALUES ('${genTable.functionName}修改', @menuId, 4, '#', NULL, 0, 0, 'F', '0', '0', '${replaceDto.PermissionPrefix}:update', '', sysdate());
VALUES ('修改', @menuId, 4, '#', NULL, 0, 0, 'F', '0', '0', '${replaceDto.PermissionPrefix}:update', '', sysdate());
INSERT INTO sys_menu(menuName, parentId, orderNum, path, component, isFrame, isCache, menuType, visible, status, perms, icon, create_time)
VALUES ('${genTable.functionName}导出', @menuId, 5, '#', NULL, 0, 0, 'F', '0', '0', '${replaceDto.PermissionPrefix}:export', '', sysdate());
VALUES ('导出', @menuId, 5, '#', NULL, 0, 0, 'F', '0', '0', '${replaceDto.PermissionPrefix}:export', '', sysdate());
SELECT * FROM sys_menu WHERE parentId = @menuId;
SELECT * FROM sys_menu WHERE menuId = @menuId;

View File

@ -7,19 +7,19 @@ declare @menuId int = @@identity
INSERT INTO sys_menu(menuName, parentId, orderNum, path, component, isFrame, isCache, menuType, visible, status, perms, icon, create_by,create_time)
VALUES ('${genTable.functionName}查询', @menuId, 1, '#', NULL, 0, 0, 'F', '0', '0', '${replaceDto.PermissionPrefix}:query', '', '', GETDATE());
VALUES ('查询', @menuId, 1, '#', NULL, 0, 0, 'F', '0', '0', '${replaceDto.PermissionPrefix}:query', '', '', GETDATE());
INSERT INTO sys_menu(menuName, parentId, orderNum, path, component, isFrame, isCache, menuType, visible, status, perms, icon, create_by,create_time)
VALUES ('${genTable.functionName}新增', @menuId, 2, '#', NULL, 0, 0, 'F', '0', '0', '${replaceDto.PermissionPrefix}:add', '', '', GETDATE());
VALUES ('新增', @menuId, 2, '#', NULL, 0, 0, 'F', '0', '0', '${replaceDto.PermissionPrefix}:add', '', '', GETDATE());
INSERT INTO sys_menu(menuName, parentId, orderNum, path, component, isFrame, isCache, menuType, visible, status, perms, icon, create_by,create_time)
VALUES ('${genTable.functionName}删除', @menuId, 3, '#', NULL, 0, 0, 'F', '0', '0', '${replaceDto.PermissionPrefix}:delete', '', '', GETDATE());
VALUES ('删除', @menuId, 3, '#', NULL, 0, 0, 'F', '0', '0', '${replaceDto.PermissionPrefix}:delete', '', '', GETDATE());
INSERT INTO sys_menu(menuName, parentId, orderNum, path, component, isFrame, isCache, menuType, visible, status, perms, icon, create_by,create_time)
VALUES ('${genTable.functionName}修改', @menuId, 4, '#', NULL, 0, 0, 'F', '0', '0', '${replaceDto.PermissionPrefix}:update', '', '', GETDATE());
VALUES ('修改', @menuId, 4, '#', NULL, 0, 0, 'F', '0', '0', '${replaceDto.PermissionPrefix}:update', '', '', GETDATE());
INSERT INTO sys_menu(menuName, parentId, orderNum, path, component, isFrame, isCache, menuType, visible, status, perms, icon, create_by,create_time)
VALUES ('${genTable.functionName}导出', @menuId, 5, '#', NULL, 0, 0, 'F', '0', '0', '${replaceDto.PermissionPrefix}:export', '', '', GETDATE());
VALUES ('导出', @menuId, 5, '#', NULL, 0, 0, 'F', '0', '0', '${replaceDto.PermissionPrefix}:export', '', '', GETDATE());
SELECT * FROM sys_menu WHERE parentId = @menuId;
SELECT * FROM sys_menu WHERE menuId = @menuId;

View File

@ -50,11 +50,14 @@ namespace ${options.ApiControllerNamespace}.Controllers
//开始拼装查询条件
var predicate = Expressionable.Create<${replaceDto.ModelTypeName}>();
//TODO 自己实现搜索条件查询语法参考Sqlsugar,默认查询所有
//搜索条件查询语法参考Sqlsugar
//predicate = predicate.And(m => m.Name.Contains(parm.Name));
${QueryCondition}
$if(genTable.SortField != "")
var response = _${replaceDto.ModelTypeName}Service.GetPages(predicate.ToExpression(), parm, x => x.${genTable.SortField}, "${genTable.SortType}");
$else
var response = _${replaceDto.ModelTypeName}Service.GetPages(predicate.ToExpression(), parm);
$end
return SUCCESS(response);
}

View File

@ -25,6 +25,8 @@ namespace ZR.Model.System.Dto
/// 上级菜单id
/// </summary>
public int? ParentMenuId { get; set; }
public string SortField { get; set; }
public string SortType { get; set; }
public List<GenTableColumnDto> Columns { get; set; }
}

View File

@ -9,7 +9,7 @@ namespace ZR.Model.System.Generate
/// </summary>
[SqlSugar.SugarTable("gen_table")]
[SqlSugar.Tenant("0")]
public class GenTable: SysBase
public class GenTable : SysBase
{
/// <summary>
/// 表id
@ -73,8 +73,14 @@ namespace ZR.Model.System.Generate
/** 表列信息 */
[SqlSugar.SugarColumn(IsIgnore = true)]
public List<GenTableColumn> Columns { get; set; }
//以下 Options扩展字段
[SqlSugar.SugarColumn(IsIgnore = true)]
public string ParentMenuId { get; set; }
public object ParentMenuId { get; set; }
[SqlSugar.SugarColumn(IsIgnore = true)]
public object SortType { get; set; } = "asc";
[SqlSugar.SugarColumn(IsIgnore = true)]
public object SortField { get; set; } = "";
#endregion
}
}

View File

@ -43,7 +43,7 @@ namespace ZR.Service
{
return baseRepository.Add(t);
}
public IInsertable<T> Insertable(T t)
public IInsertable<T> Insertable(T t)
{
return baseRepository.Insertable(t);
}
@ -179,7 +179,7 @@ namespace ZR.Service
public DbResult<bool> UseTran(Action action)
{
var result = baseRepository.UseTran(action) ;
var result = baseRepository.UseTran(action);
return result;
}
@ -330,6 +330,10 @@ namespace ZR.Service
{
return baseRepository.GetPages(where, parm, order, orderEnum);
}
public PagedInfo<T> GetPages(Expression<Func<T, bool>> where, PagerInfo parm, Expression<Func<T, object>> order, string orderByType)
{
return baseRepository.GetPages(where, parm, order, orderByType == "desc" ? OrderByType.Desc : OrderByType.Asc);
}
/// <summary>
/// 查询所有数据(无分页,请慎用)
/// </summary>

View File

@ -99,7 +99,7 @@ namespace ZR.Service
PagedInfo<T> GetPages(Expression<Func<T, bool>> where, PagerInfo parm);
PagedInfo<T> GetPages(Expression<Func<T, bool>> where, PagerInfo parm, Expression<Func<T, object>> order, OrderByType orderEnum = OrderByType.Asc);
PagedInfo<T> GetPages(Expression<Func<T, bool>> where, PagerInfo parm, Expression<Func<T, object>> order, string orderType);
bool Any(Expression<Func<T, bool>> expression);
ISugarQueryable<T> Queryable();

View File

@ -70,7 +70,9 @@ namespace ZR.Service.System
if (!string.IsNullOrEmpty(genTable?.Options))
{
Dictionary<string, object> options = JsonConvert.DeserializeObject<Dictionary<string, object>>(genTable.Options);
genTable.ParentMenuId = Convert.ToString(options.GetValueOrDefault("parentMenuId"));
genTable.ParentMenuId = options.GetValueOrDefault("parentMenuId") ?? null;
genTable.SortType = options.GetValueOrDefault("sortType") ?? "asc";
genTable.SortField = options.GetValueOrDefault("sortField") ?? null;
}
}

View File

@ -10,6 +10,6 @@ namespace ZR.Service.System.IService
/// </summary>
/// <returns></returns>
//public int AddTaskLog(string jobId);
public SysTasksLog AddTaskLog(string jobId, SysTasksLog tasksLog);
SysTasksLog AddTaskLog(string jobId, SysTasksLog tasksLog);
}
}

View File

@ -1,5 +1,7 @@
using Infrastructure.Attribute;
using System;
using System.Linq.Expressions;
using ZR.Model;
using ZR.Model.System;
using ZR.Repository;
using ZR.Service.System.IService;
@ -34,5 +36,10 @@ namespace ZR.Service.System
Add(logModel);
return logModel;
}
public PagedInfo<SysTasksLog> GetPages(Expression<Func<SysTasksLog, bool>> where, PagerInfo parm, Expression<Func<SysTasksLog, object>> order, string orderType)
{
throw new NotImplementedException();
}
}
}

View File

@ -62,7 +62,7 @@
<li>Quartz.Net</li>
<li>MySql</li>
<li>Mapster</li>
<li>Epplus</li>
<li>Epplus</li>
<li>...</li>
</ul>
</el-col>
@ -109,27 +109,25 @@
<span>更新日志</span>
</div>
<el-collapse accordion>
<el-collapse-item title="v3.7.1 - 2021-12-01">
<el-collapse-item title="v3.7.0 - 2021-12-01">
<ol>
<li>代码生成新增加排序字段</li>
<li>新增加登录验证码开关</li>
<li>替换代码生成器模板引擎</li>
<li>富文本组件Editor改用全局注册</li>
<li>新增加上传文件到阿里云</li>
<li>fix gen_table_column表表名字段长度不够</li>
<li>其他功能优化</li>
</ol>
</el-collapse-item>
<el-collapse-item title="v3.7.0 - 2021-11-28">
<ol>
<li>替换代码生成器模板引擎</li>
<li>富文本组件Editor改用全局注册</li>
<li>新增加上传文件到阿里云</li>
<li>fix gen_table_column表表名字段长度不够</li>
<li>代码生成新增排序字段</li>
<li>fix 代码生成编辑表信息选择上级菜单bug</li>
<li>新增下拉框组件代码生成查询模块</li>
<li>优化代码生成模板</li>
<li>优化后端分页统一返回json</li>
<li>修改代码生成form表单显示</li>
<li>新增代码生成单选按钮动态绑定数据</li>
<li>代码生成查询新增一键生成可支持inputselect时间</li>
<li>修改代码生成数据库连接字符串</li>
<li>优化数据仓储</li>
<li>优化代码生成模板</li>
<li>优化后端分页统一返回json</li>
<li>修改代码生成form表单显示</li>
<li>新增代码生成单选按钮动态绑定数据</li>
<li>代码生成查询新增一键生成可支持inputselect时间</li>
<li>修改代码生成数据库连接字符串</li>
<li>优化数据仓储</li>
<li>其他功能优化</li>
</ol>
</el-collapse-item>
<el-collapse-item title="v3.6.0 - 2021-11-21">
@ -178,7 +176,7 @@
</template>
<script>
const defaultSettings = require('@/settings.js')
const defaultSettings = require("@/settings.js");
export default {
name: "index",
data() {

View File

@ -101,7 +101,7 @@
</el-table>
</el-tab-pane>
<el-tab-pane label="生成信息" name="genInfo">
<gen-info-form ref="genInfo" :info="info" :tables="tables" :menus="menus" />
<gen-info-form ref="genInfo" :info="info" :tables="tables" :menus="menus" :columns="cloumns"/>
</el-tab-pane>
</el-tabs>
<el-form label-width="100px">
@ -155,9 +155,9 @@ export default {
if (tableId) {
//
queryColumnInfo(tableId).then((res) => {
this.cloumns = res.data.result;
this.cloumns = res.data.cloumns;
this.info = res.data.info;
this.tables = res.data.tables;
// this.tables = res.data.tables;/
});
/** 查询字典下拉列表 */
listType().then((response) => {

View File

@ -68,7 +68,23 @@
<i class="el-icon-question"></i>
</el-tooltip>
</span>
<treeselect :append-to-body="true" v-model="info.parentMenuId" :options="menus" :normalizer="normalizer" :show-count="true" placeholder="请选择系统菜单" />
<treeselect :append-to-body="true" v-model="info.parentMenuId" :options="menus" :normalizer="normalizer" :show-count="true"
placeholder="请选择系统菜单" />
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item>
<span slot="label">
排序字段
</span>
<el-select v-model="info.sortField" placeholder="请选择字段" class="mr10">
<el-option v-for="item in columns" :key="item.columnId" :label="item.csharpField" :value="item.csharpField">
</el-option>
</el-select>
<el-radio v-model="info.sortType" label="asc">正序</el-radio>
<el-radio v-model="info.sortType" label="desc">倒序</el-radio>
</el-form-item>
</el-col>
@ -119,7 +135,8 @@
</el-tooltip>
</span>
<el-select v-model="info.treeCode" placeholder="请选择">
<el-option v-for="(column, index) in info.columns" :key="index" :label="column.columnName + '' + column.columnComment" :value="column.columnName"></el-option>
<el-option v-for="(column, index) in info.columns" :key="index" :label="column.columnName + '' + column.columnComment"
:value="column.columnName"></el-option>
</el-select>
</el-form-item>
</el-col>
@ -132,7 +149,8 @@
</el-tooltip>
</span>
<el-select v-model="info.treeParentCode" placeholder="请选择">
<el-option v-for="(column, index) in info.columns" :key="index" :label="column.columnName + '' + column.columnComment" :value="column.columnName"></el-option>
<el-option v-for="(column, index) in info.columns" :key="index" :label="column.columnName + '' + column.columnComment"
:value="column.columnName"></el-option>
</el-select>
</el-form-item>
</el-col>
@ -145,7 +163,8 @@
</el-tooltip>
</span>
<el-select v-model="info.treeName" placeholder="请选择">
<el-option v-for="(column, index) in info.columns" :key="index" :label="column.columnName + '' + column.columnComment" :value="column.columnName"></el-option>
<el-option v-for="(column, index) in info.columns" :key="index" :label="column.columnName + '' + column.columnComment"
:value="column.columnName"></el-option>
</el-select>
</el-form-item>
</el-col>
@ -161,7 +180,8 @@
</el-tooltip>
</span>
<el-select v-model="info.subTableName" placeholder="请选择" @change="subSelectChange">
<el-option v-for="(table, index) in tables" :key="index" :label="table.tableName + '' + table.tableComment" :value="table.tableName"></el-option>
<el-option v-for="(table, index) in tables" :key="index" :label="table.tableName + '' + table.tableComment" :value="table.tableName">
</el-option>
</el-select>
</el-form-item>
</el-col>
@ -174,7 +194,8 @@
</el-tooltip>
</span>
<el-select v-model="info.subTableFkName" placeholder="请选择">
<el-option v-for="(column, index) in subColumns" :key="index" :label="column.columnName + '' + column.columnComment" :value="column.columnName"></el-option>
<el-option v-for="(column, index) in subColumns" :key="index" :label="column.columnName + '' + column.columnComment"
:value="column.columnName"></el-option>
</el-select>
</el-form-item>
</el-col>
@ -193,6 +214,7 @@ export default {
type: Object,
default: null,
},
//
tables: {
type: Array,
default: null,
@ -201,6 +223,11 @@ export default {
type: Array,
default: [],
},
//
columns: {
type: Array,
default: [],
},
},
data() {
return {
@ -221,7 +248,9 @@ export default {
},
};
},
created() {},
created() {
console.log(this.columns);
},
watch: {
"info.subTableName": function (val) {
this.setSubTableColumns(val);