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