开发代码生成功能
This commit is contained in:
parent
c1e014a5d0
commit
37155011f0
@ -7,6 +7,7 @@ using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using ZR.Model;
|
||||
using ZR.Model.CodeGenerator;
|
||||
using ZR.Model.Vo;
|
||||
using ZR.Service.IService;
|
||||
using ZR.Service.System;
|
||||
|
||||
@ -43,18 +44,30 @@ namespace ZR.Admin.WebApi.Controllers
|
||||
/// </summary>
|
||||
/// <param name="enCode">数据库名</param>
|
||||
/// <param name="keywords">表名</param>
|
||||
/// <param name="pagerInfo">分页信息</param>
|
||||
/// <param name="pager">分页信息</param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("FindListTable")]
|
||||
public IActionResult FindListTable(string enCode, string keywords, PagerInfo pagerInfo)
|
||||
public IActionResult FindListTable(string enCode, string keywords, PagerInfo pager)
|
||||
{
|
||||
if (string.IsNullOrEmpty(enCode))
|
||||
{
|
||||
return ToRespose(ResultCode.PARAM_ERROR);
|
||||
}
|
||||
List<DbTableInfo> listTable = CodeGeneratorService.GetTablesWithPage(keywords, enCode, pagerInfo);
|
||||
List<DbTableInfo> list = CodeGeneratorService.GetTablesWithPage(keywords, enCode, pager);
|
||||
var vm = new VMPageResult<DbTableInfo>(list, pager);
|
||||
|
||||
return SUCCESS(listTable);
|
||||
return SUCCESS(vm);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 生成代码
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet("Generate")]
|
||||
public IActionResult Generate()
|
||||
{
|
||||
|
||||
return SUCCESS(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -27,6 +27,7 @@ namespace ZR.Repository.DbProvider
|
||||
{
|
||||
connStr = NETCore.Encrypt.EncryptProvider.DESDecrypt(connStr, dbKey);
|
||||
}
|
||||
|
||||
Db = new SqlSugarClient(new List<ConnectionConfig>()
|
||||
{
|
||||
new ConnectionConfig(){
|
||||
|
||||
@ -10,7 +10,7 @@ using ZR.Model.CodeGenerator;
|
||||
namespace ZR.Repository.System
|
||||
{
|
||||
[AppService(ServiceLifetime = LifeTime.Transient)]
|
||||
public class CodeGeneratorRepository: BaseRepository
|
||||
public class CodeGeneratorRepository : BaseRepository
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取数据库信息
|
||||
@ -24,11 +24,22 @@ namespace ZR.Repository.System
|
||||
/// <summary>
|
||||
/// 获取所有的表
|
||||
/// </summary>
|
||||
/// <param name="dbName"></param>
|
||||
/// <param name="pager"></param>
|
||||
/// <param name="tableName"></param>
|
||||
/// <returns></returns>
|
||||
public List<DbTableInfo> GetAllTables(string dbName)
|
||||
public List<DbTableInfo> GetAllTables(string dbName, string tableName, PagerInfo pager)
|
||||
{
|
||||
string sql = $"SELECT name as TableName FROM {dbName}..SysObjects Where XType='U' ORDER BY Name";
|
||||
return Db.Ado.SqlQuery<DbTableInfo>(sql, new { dbName});
|
||||
string sql = $"SELECT name as TableName FROM {dbName}..SysObjects Where XType='U'";
|
||||
int total = 0;
|
||||
var list = Db.SqlQueryable<DbTableInfo>(sql)
|
||||
//.WithCache(60 * 10)
|
||||
.WhereIF(!string.IsNullOrEmpty(tableName), it => it.TableName.Contains(tableName))
|
||||
.AddParameters(new { dbName })
|
||||
.OrderBy(x => x.TableName)
|
||||
.ToPageList(pager.PageNum, pager.PageSize, ref total);
|
||||
pager.TotalNum = total;
|
||||
return list;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -43,22 +43,22 @@ namespace ZR.Service.System
|
||||
return list;
|
||||
}
|
||||
|
||||
public List<DbTableInfo> GetTablesWithPage(string tablename, string dbName, PagerInfo info)
|
||||
public List<DbTableInfo> GetTablesWithPage(string tablename, string dbName, PagerInfo pager)
|
||||
{
|
||||
var dbType = ConfigUtils.Instance.GetConfig("CodeGenDbType");
|
||||
List<DbTableInfo> list = new List<DbTableInfo>();
|
||||
if (dbType == "1")
|
||||
{
|
||||
list = CodeGeneratorRepository.GetAllTables(dbName);
|
||||
list = CodeGeneratorRepository.GetAllTables(dbName, tablename, pager);
|
||||
}
|
||||
else if (dbType.Contains("MySql"))
|
||||
{
|
||||
//list = mysqlExtractor.GetAllTables(this.dbName, tablename, fieldNameToSort, isDescending, info);
|
||||
}
|
||||
if (!string.IsNullOrEmpty(tablename))
|
||||
{
|
||||
list = list.Where(f => f.TableName.Contains(tablename)).ToList();
|
||||
}
|
||||
//if (!string.IsNullOrEmpty(tablename))
|
||||
//{
|
||||
// list = list.Where(f => f.TableName.Contains(tablename)).ToList();
|
||||
//}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
@ -46,12 +46,12 @@
|
||||
<el-button type="primary" @click="handleSearch()">查询</el-button>
|
||||
</el-form-item>
|
||||
<el-form-item label="项目命名空间:" prop="baseSpace">
|
||||
<el-tooltip class="item" effect="dark" content="系统会根据项目命名空间自动生成IService、Service、Models等子命名空间" placement="top">
|
||||
<el-input v-model="codeform.baseSpace" clearable placeholder="如Yuebon.WMS" />
|
||||
<el-tooltip class="item" effect="dark" content="系统会根据项目命名空间自动生成IService、Service、Models等子命名空间" placement="bottom">
|
||||
<el-input v-model="codeform.baseSpace" clearable placeholder="如Zr" />
|
||||
</el-tooltip>
|
||||
</el-form-item>
|
||||
<el-form-item label="去掉表名前缀:">
|
||||
<el-tooltip class="item" effect="dark" content="表名直接变为类名,去掉表名前缀。多个前缀用“;”隔开和结束" placement="top">
|
||||
<el-tooltip class="item" effect="dark" content="表名直接变为类名,去掉表名前缀。多个前缀用“;”隔开和结束" placement="bottom">
|
||||
<el-input v-model="codeform.replaceTableNameStr" clearable width="300" placeholder="多个前缀用“;”隔开" />
|
||||
</el-tooltip>
|
||||
</el-form-item>
|
||||
@ -129,7 +129,7 @@ export default {
|
||||
},
|
||||
],
|
||||
tableData: [],
|
||||
tableloading: true,
|
||||
tableloading: false,
|
||||
pagination: {
|
||||
pageNum: 1,
|
||||
pagesize: 20,
|
||||
@ -146,7 +146,7 @@ export default {
|
||||
created() {
|
||||
this.pagination.pageNum = 1;
|
||||
this.loadData();
|
||||
this.loadTableData();
|
||||
// this.loadTableData();
|
||||
},
|
||||
methods: {
|
||||
loadData: function () {
|
||||
@ -169,7 +169,7 @@ export default {
|
||||
// Sort: this.sortableData.sort,
|
||||
};
|
||||
codeGetTableList(seachdata).then((res) => {
|
||||
this.tableData = res.data;
|
||||
this.tableData = res.data.result;
|
||||
this.pagination.pageTotal = res.data.totalNum;
|
||||
this.tableloading = false;
|
||||
});
|
||||
@ -179,6 +179,7 @@ export default {
|
||||
* 点击查询
|
||||
*/
|
||||
handleSearch: function () {
|
||||
this.tableloading = true;
|
||||
this.pagination.pageNum = 1;
|
||||
this.loadTableData();
|
||||
},
|
||||
@ -230,20 +231,15 @@ export default {
|
||||
};
|
||||
codeGenerator(seachdata)
|
||||
.then((res) => {
|
||||
if (res.Success) {
|
||||
if (res.code == 100) {
|
||||
downloadFile(
|
||||
defaultSettings.fileUrl + res.ResData[0],
|
||||
res.ResData[1]
|
||||
);
|
||||
this.$message({
|
||||
message: "恭喜你,代码生成完成!",
|
||||
type: "success",
|
||||
});
|
||||
|
||||
this.msgSuccess("恭喜你,代码生成完成!");
|
||||
} else {
|
||||
this.$message({
|
||||
message: res.ErrMsg,
|
||||
type: "error",
|
||||
});
|
||||
this.msgError(res.msg);
|
||||
}
|
||||
pageLoading.close();
|
||||
})
|
||||
|
||||
@ -44,9 +44,15 @@
|
||||
</summary>
|
||||
<param name="enCode">数据库名</param>
|
||||
<param name="keywords">表名</param>
|
||||
<param name="pagerInfo">分页信息</param>
|
||||
<param name="pager">分页信息</param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:ZR.Admin.WebApi.Controllers.CodeGeneratorController.Generate">
|
||||
<summary>
|
||||
生成代码
|
||||
</summary>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:ZR.Admin.WebApi.Controllers.HomeController.Health">
|
||||
<summary>
|
||||
心跳
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user