Merge branch 'dev_master'
This commit is contained in:
commit
13f83da131
@ -59,7 +59,7 @@ namespace Infrastructure.Extensions
|
||||
services.AddTransient(serviceType, type);
|
||||
break;
|
||||
}
|
||||
Console.WriteLine($"注册:{serviceType}");
|
||||
//Console.WriteLine($"注册:{serviceType}");
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@ -6,22 +6,11 @@ namespace Infrastructure
|
||||
/// </summary>
|
||||
public class OptionsSetting
|
||||
{
|
||||
public static string ConnAdmin = "Conn_admin";
|
||||
public static string Conn = "ConnDynamic";
|
||||
public static string DbType = "DbType";
|
||||
public static string CodeGenDbType = "CodeGenDbType";
|
||||
public static string ConnAdmin = "conn_zrAdmin";
|
||||
public static string ConnDbType = "conn_zrAdmin_Type";
|
||||
public static string DbKey = "DbKey";
|
||||
|
||||
public string Conn_Admin { get; set; }
|
||||
|
||||
public string AppName { get; set; }
|
||||
/// <summary>
|
||||
/// 主库
|
||||
/// </summary>
|
||||
public string Master { get; set; }
|
||||
|
||||
public string Redis { get; set; }
|
||||
|
||||
public string Database { get; set; }
|
||||
/// <summary>
|
||||
/// 是否演示模式
|
||||
|
||||
38
README.md
38
README.md
@ -3,15 +3,13 @@
|
||||
## 🍟概述
|
||||
* 本项目适合有一定NetCore和 vue基础的开发人员
|
||||
* 基于.NET 5实现的通用权限管理平台(RBAC模式)。整合最新技术高效快速开发,前后端分离模式,开箱即用。
|
||||
* 模块化架构设计,层次清晰,业务层推荐写到单独模块,框架升级不影响业务!
|
||||
* 代码量少、通俗易懂、功能强大、易扩展,轻松开发从现在开始!
|
||||
* 代码量少、学习简单、通俗易懂、功能强大、易扩展、轻量级,让web开发更快速、简单高效,解决70%的重复工作,专注您的业务,轻松开发从现在开始!
|
||||
* 前端采用Vue2.0、Element UI。
|
||||
* 后端采用Net5、Sqlsugar、MySQL。
|
||||
* 权限认证使用Jwt,支持多终端认证系统。
|
||||
* 支持加载动态权限菜单,多方式轻松权限控制
|
||||
* 基于若依vue分离版本(java版本)修改
|
||||
|
||||
> 如果对您有帮助,点击右上角⭐Star⭐关注 ,感谢支持开源!
|
||||
> 如果对您有帮助,您可以点右上角 “Star” 收藏一下 ,这样作者才有继续免费下去的动力,谢谢!~
|
||||
|
||||
## 🍿在线体验
|
||||
体验地址:http://www.izhaorui.cn:8080/
|
||||
@ -36,7 +34,7 @@ Vue版前端技术栈 :基于vue、vuex、vue-router 、vue-cli 、axios 和 e
|
||||
|
||||
## 🍄快速启动
|
||||
需要安装:VS2019(最新版)、npm或yarn(最新版)
|
||||
准备工作:将document文件夹下面的admin.sql脚本导入到数据库中,修改ZRAdmin项目里面的Conn_Admin数据库连接字符串以及DbType选择对应的数据库类型,目前仅MySQL验证了
|
||||
准备工作:将document文件夹下面的admin.sql脚本导入到数据库中,修改ZR.Admin.WebApi项目里面配置文件中的conn_zrAdmin数据库连接字符串以及DbType选择对应的数据库类型,目前仅支持MySQL、SQL server
|
||||
启动后台:打开项目根目录的startup.bat即可启动(数据库默认MySQL)
|
||||
启动前端:打开ZR.Vue文件夹,运行npm install命令,再运行npm run serve启动
|
||||
浏览器访问:http://localhost:8887 (默认前端端口为:8887,后台端口为:8888)
|
||||
@ -59,7 +57,30 @@ Vue版前端技术栈 :基于vue、vuex、vue-router 、vue-cli 、axios 和 e
|
||||
13. [X] 在线构建器:拖动表单元素生成相应的VUE代码。
|
||||
14. [X] 任务系统:基于Quartz.NET定时任务执行。
|
||||
15. [X] 文章管理:可以写文章记录。
|
||||
16. [X] 代码生成:可以一键生成前后端代码。
|
||||
16. [X] 代码生成:可以一键生成前后端代码(.cs、.vue、.js),自定义配置前端展示控件、让开发更快捷高效。
|
||||
|
||||
## 项目结构
|
||||
|
||||
ZRAdmin解决方案包含:
|
||||
|
||||
Infrastructure[基础类库]:包框架的核心组件,包含一系列快速开发中经常用到的Utility辅助工具功能,部分核心功能的实现;
|
||||
|
||||
ZR.Service[服务层类库]:提供WebApi接口调用;
|
||||
|
||||
ZR.Tasks[定时任务类库]:提供项目定时任务实现功能;
|
||||
|
||||
ZR.Repository[仓库层类库]:方便提供有执行存储过程的操作;
|
||||
|
||||
ZR.Model[实体层类库],提供项目中的数据库表、数据传输对象;
|
||||
|
||||
ZR.CodeGenerator[代码生成功能],包含代码生成的模板、方法、代码生成的下载。
|
||||
|
||||
ZR.Admin.WebApi[webapi接口]:为Vue版或其他三方系统提供接口服务。
|
||||
|
||||
ZR.Vue[前端UI]:vue版本UI层。
|
||||
|
||||
DataBase是最新数据库备份文件,目前支持MS SQL Server和MySql。
|
||||
|
||||
|
||||
## 🍎演示图
|
||||
|
||||
@ -92,6 +113,10 @@ Vue版前端技术栈 :基于vue、vuex、vue-router 、vue-cli 、axios 和 e
|
||||
<td><img src="https://www.izhaorui.cn/images/zradmin/13.png"/></td>
|
||||
<td><img src="https://www.izhaorui.cn/images/zradmin/14.png"/></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><img src="https://www.izhaorui.cn/images/zradmin/15.png"/></td>
|
||||
<td><img src="https://www.izhaorui.cn/images/zradmin/16.png"/></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
## 🎉优势
|
||||
@ -100,6 +125,7 @@ Vue版前端技术栈 :基于vue、vuex、vue-router 、vue-cli 、axios 和 e
|
||||
2. 后台系统无需任何二次开发,直接发布即可使用
|
||||
3. 前台与后台系统分离,分别为不同的系统(域名可独立)
|
||||
4. 全局异常统一处理
|
||||
5. 自定义的代码生成功能
|
||||
|
||||
## 💐 特别鸣谢
|
||||
- 👉Ruoyi.vue:[Ruoyi](http://www.ruoyi.vip/)
|
||||
|
||||
@ -1,15 +1,25 @@
|
||||
using Infrastructure;
|
||||
using Infrastructure.Attribute;
|
||||
using Infrastructure.Enums;
|
||||
using Mapster;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using ZR.Admin.WebApi.Extensions;
|
||||
using ZR.Admin.WebApi.Filters;
|
||||
using ZR.CodeGenerator;
|
||||
using ZR.CodeGenerator.Model;
|
||||
using ZR.CodeGenerator.Service;
|
||||
using ZR.Common;
|
||||
using ZR.Model;
|
||||
using ZR.Model.System.Dto;
|
||||
using ZR.Model.System.Generate;
|
||||
using ZR.Model.Vo;
|
||||
using ZR.Service.System.IService;
|
||||
|
||||
namespace ZR.Admin.WebApi.Controllers
|
||||
{
|
||||
@ -20,6 +30,15 @@ namespace ZR.Admin.WebApi.Controllers
|
||||
public class CodeGeneratorController : BaseController
|
||||
{
|
||||
private CodeGeneraterService _CodeGeneraterService = new CodeGeneraterService();
|
||||
private IGenTableService GenTableService;
|
||||
private IGenTableColumnService GenTableColumnService;
|
||||
private IWebHostEnvironment WebHostEnvironment;
|
||||
public CodeGeneratorController(IGenTableService genTableService, IGenTableColumnService genTableColumnService, IWebHostEnvironment webHostEnvironment)
|
||||
{
|
||||
GenTableService = genTableService;
|
||||
GenTableColumnService = genTableColumnService;
|
||||
WebHostEnvironment = webHostEnvironment;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取所有数据库的信息
|
||||
@ -51,22 +70,6 @@ namespace ZR.Admin.WebApi.Controllers
|
||||
return SUCCESS(vm);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取表格列
|
||||
/// </summary>
|
||||
/// <param name="dbName"></param>
|
||||
/// <param name="tableName"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("getColumnInfo")]
|
||||
[ActionPermissionFilter(Permission = "tool:gen:list")]
|
||||
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>
|
||||
@ -77,14 +80,143 @@ namespace ZR.Admin.WebApi.Controllers
|
||||
[ActionPermissionFilter(Permission = "tool:gen:code")]
|
||||
public IActionResult Generate([FromBody] GenerateDto dto)
|
||||
{
|
||||
if (string.IsNullOrEmpty(dto.tableName))
|
||||
if (dto.TableId <= 0)
|
||||
{
|
||||
throw new CustomException(ResultCode.CUSTOM_ERROR, "请求参数为空");
|
||||
}
|
||||
DbTableInfo dbTableInfo = new() { Name = dto.tableName };
|
||||
CodeGeneratorTool.Generate(dbTableInfo, dto);
|
||||
dto.ZipPath = Path.Combine(WebHostEnvironment.WebRootPath, "Generatecode");
|
||||
dto.GenCodePath = Path.Combine(dto.ZipPath, DateTime.Now.ToString("yyyyMMdd"));
|
||||
|
||||
return SUCCESS(dbTableInfo);
|
||||
var genTableInfo = GenTableService.GetGenTableInfo(dto.TableId);
|
||||
genTableInfo.Columns = GenTableColumnService.GenTableColumns(dto.TableId);
|
||||
|
||||
dto.GenTable = genTableInfo;
|
||||
//生成代码
|
||||
CodeGeneratorTool.Generate(genTableInfo, dto);
|
||||
//下载文件
|
||||
CodeGeneratorTool.ZipGenCode(dto);
|
||||
|
||||
//HttpContext.Response.Headers.Add("Content-disposition", $"attachment; filename={zipFileName}");
|
||||
return SUCCESS(new { zipPath = "/Generatecode/" + dto.ZipFileName, fileName = dto.ZipFileName });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取代码生成表列表
|
||||
/// </summary>
|
||||
/// <param name="tableName">表名</param>
|
||||
/// <param name="pagerInfo">分页信息</param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("listGenTable")]
|
||||
public IActionResult GetGenTable(string tableName, PagerInfo pagerInfo)
|
||||
{
|
||||
//查询原表数据,部分字段映射到代码生成表字段
|
||||
var rows = GenTableService.GetGenTables(new GenTable() { TableName = tableName }, pagerInfo);
|
||||
|
||||
return SUCCESS(rows);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查询表字段列表
|
||||
/// </summary>
|
||||
/// <param name="tableId">genTable表id</param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("column/{tableId}")]
|
||||
public IActionResult GetColumnList(long tableId)
|
||||
{
|
||||
var tableColumns = GenTableColumnService.GenTableColumns(tableId);
|
||||
var tableInfo = GenTableService.GetGenTableInfo(tableId);
|
||||
return SUCCESS(new { result = tableColumns, info = tableInfo });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除代码生成
|
||||
/// </summary>
|
||||
/// <param name="tableIds"></param>
|
||||
/// <returns></returns>
|
||||
[Log(Title = "代码生成", BusinessType = BusinessType.DELETE)]
|
||||
[HttpDelete("{tableIds}")]
|
||||
[ActionPermissionFilter(Permission = "tool:gen:remove")]
|
||||
public IActionResult Remove(string tableIds)
|
||||
{
|
||||
long[] tableId = Tools.SpitLongArrary(tableIds);
|
||||
|
||||
int result = GenTableService.DeleteGenTableByIds(tableId);
|
||||
return SUCCESS(result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 导入表
|
||||
/// </summary>
|
||||
/// <param name="tables"></param>
|
||||
/// <param name="dbName"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("importTable")]
|
||||
[Log(Title = "代码生成", BusinessType = BusinessType.IMPORT)]
|
||||
[ActionPermissionFilter(Permission = "tool:gen:import")]
|
||||
public IActionResult ImportTableSave(string tables, string dbName)
|
||||
{
|
||||
if (string.IsNullOrEmpty(tables))
|
||||
{
|
||||
throw new CustomException("表不能为空");
|
||||
}
|
||||
string[] tableNames = tables.Split(',', StringSplitOptions.RemoveEmptyEntries);
|
||||
string userName = User.Identity.Name;
|
||||
|
||||
foreach (var tableName in tableNames)
|
||||
{
|
||||
var tabInfo = _CodeGeneraterService.GetTableInfo(dbName, tableName);
|
||||
if (tabInfo != null)
|
||||
{
|
||||
GenTable genTable = new()
|
||||
{
|
||||
BaseNameSpace = "ZR.",//导入默认命名空间前缀
|
||||
ModuleName = "business",//导入默认模块名
|
||||
ClassName = CodeGeneratorTool.GetClassName(tableName),
|
||||
BusinessName = CodeGeneratorTool.GetClassName(tableName),
|
||||
FunctionAuthor = ConfigUtils.Instance.GetConfig(GenConstants.Gen_author),
|
||||
FunctionName = tabInfo.Description,
|
||||
TableName = tableName,
|
||||
TableComment = tabInfo.Description,
|
||||
Create_by = userName,
|
||||
};
|
||||
genTable.TableId = GenTableService.ImportGenTable(genTable);
|
||||
|
||||
if (genTable.TableId > 0)
|
||||
{
|
||||
//保存列信息
|
||||
List<DbColumnInfo> dbColumnInfos = _CodeGeneraterService.GetColumnInfo(dbName, tableName);
|
||||
List<GenTableColumn> genTableColumns = CodeGeneratorTool.InitGenTableColumn(genTable, dbColumnInfos);
|
||||
|
||||
GenTableColumnService.DeleteGenTableColumnByTableName(tableName);
|
||||
GenTableColumnService.InsertGenTableColumn(genTableColumns);
|
||||
genTable.Columns = genTableColumns;
|
||||
|
||||
return SUCCESS(genTable);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ToRespose(ResultCode.FAIL);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 修改保存代码生成业务
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPut]
|
||||
//[Log(Title = "代码生成", BusinessType = BusinessType.UPDATE)]
|
||||
[ActionPermissionFilter(Permission = "tool:gen:edit")]
|
||||
public IActionResult EditSave([FromBody] GenTableDto genTableDto)
|
||||
{
|
||||
if (genTableDto == null) throw new CustomException("请求参数错误");
|
||||
var genTable = genTableDto.Adapt<GenTable>().ToUpdate(HttpContext);
|
||||
|
||||
int rows = GenTableService.UpdateGenTable(genTable);
|
||||
if (rows > 0)
|
||||
{
|
||||
GenTableColumnService.UpdateGenTableColumn(genTable.Columns);
|
||||
}
|
||||
return SUCCESS(rows);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,22 +1,12 @@
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// 此代码已从模板生成。
|
||||
//
|
||||
// 手动更改此文件可能导致应用程序出现意外的行为。
|
||||
// 如果重新生成代码,将覆盖对此文件的手动更改。
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
using Infrastructure.Attribute;
|
||||
using Infrastructure.Attribute;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using ZR.Admin.WebApi.Filters;
|
||||
using ZR.Model.System;
|
||||
using ZR.Service.IService;
|
||||
using ZR.Service.System.IService;
|
||||
using Infrastructure.Model;
|
||||
using SqlSugar;
|
||||
using Mapster;
|
||||
using ZR.Model.Dto.System;
|
||||
using ZR.Model.System.Dto;
|
||||
using Infrastructure.Enums;
|
||||
using Infrastructure;
|
||||
using ZR.Admin.WebApi.Extensions;
|
||||
|
||||
@ -7,7 +7,7 @@ using ZR.Admin.WebApi.Filters;
|
||||
using ZR.Common;
|
||||
using ZR.Model.System;
|
||||
using ZR.Service;
|
||||
using ZR.Service.IService;
|
||||
using ZR.Service.System.IService;
|
||||
|
||||
namespace ZR.Admin.WebApi.Controllers.System
|
||||
{
|
||||
|
||||
@ -7,7 +7,7 @@ using ZR.Admin.WebApi.Filters;
|
||||
using ZR.Model;
|
||||
using ZR.Model.System;
|
||||
using ZR.Model.Vo;
|
||||
using ZR.Service.IService;
|
||||
using ZR.Service.System.IService;
|
||||
|
||||
namespace ZR.Admin.WebApi.Controllers.System
|
||||
{
|
||||
|
||||
@ -8,7 +8,7 @@ using ZR.Common;
|
||||
using ZR.Model;
|
||||
using ZR.Model.System;
|
||||
using ZR.Model.Vo;
|
||||
using ZR.Service.IService;
|
||||
using ZR.Service.System.IService;
|
||||
|
||||
namespace ZR.Admin.WebApi.Controllers.System
|
||||
{
|
||||
|
||||
@ -11,8 +11,8 @@ using Infrastructure.Model;
|
||||
using Infrastructure;
|
||||
using Infrastructure.Attribute;
|
||||
using ZR.Model.System;
|
||||
using ZR.Model.Dto.System;
|
||||
using ZR.Service.IService;
|
||||
using ZR.Model.System.Dto;
|
||||
using ZR.Service.System.IService;
|
||||
using Hei.Captcha;
|
||||
using ZR.Common;
|
||||
|
||||
|
||||
@ -5,10 +5,10 @@ using Infrastructure.Model;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using ZR.Admin.WebApi.Extensions;
|
||||
using ZR.Admin.WebApi.Filters;
|
||||
using ZR.Model.Dto.System;
|
||||
using ZR.Model.System.Dto;
|
||||
using ZR.Model.System;
|
||||
using ZR.Service;
|
||||
using ZR.Service.IService;
|
||||
using ZR.Service.System.IService;
|
||||
|
||||
namespace ZR.Admin.WebApi.Controllers.System
|
||||
{
|
||||
|
||||
@ -8,7 +8,7 @@ using Infrastructure.Extensions;
|
||||
using Infrastructure.Attribute;
|
||||
using Infrastructure.Enums;
|
||||
using Infrastructure;
|
||||
using ZR.Service.IService;
|
||||
using ZR.Service.System.IService;
|
||||
|
||||
namespace ZR.Admin.WebApi.Controllers.System
|
||||
{
|
||||
|
||||
@ -12,9 +12,9 @@ using System.IO;
|
||||
using ZR.Admin.WebApi.Extensions;
|
||||
using ZR.Admin.WebApi.Filters;
|
||||
using ZR.Common;
|
||||
using ZR.Model.Dto.System;
|
||||
using ZR.Model.System.Dto;
|
||||
using ZR.Model.System;
|
||||
using ZR.Service.IService;
|
||||
using ZR.Service.System.IService;
|
||||
|
||||
namespace ZR.Admin.WebApi.Controllers.System
|
||||
{
|
||||
|
||||
@ -8,7 +8,7 @@ using ZR.Admin.WebApi.Filters;
|
||||
using ZR.Model;
|
||||
using ZR.Model.System;
|
||||
using ZR.Model.Vo;
|
||||
using ZR.Service.IService;
|
||||
using ZR.Service.System.IService;
|
||||
using ZR.Admin.WebApi.Extensions;
|
||||
|
||||
namespace ZR.Admin.WebApi.Controllers.System
|
||||
|
||||
@ -10,7 +10,7 @@ using ZR.Admin.WebApi.Filters;
|
||||
using ZR.Model;
|
||||
using ZR.Model.System;
|
||||
using ZR.Model.Vo;
|
||||
using ZR.Service.IService;
|
||||
using ZR.Service.System.IService;
|
||||
|
||||
namespace ZR.Admin.WebApi.Controllers.System
|
||||
{
|
||||
|
||||
@ -5,9 +5,9 @@ using System;
|
||||
using System.Linq;
|
||||
using ZR.Admin.WebApi.Filters;
|
||||
using ZR.Model;
|
||||
using ZR.Model.Dto.System;
|
||||
using ZR.Model.System.Dto;
|
||||
using ZR.Model.System;
|
||||
using ZR.Service.IService;
|
||||
using ZR.Service.System.IService;
|
||||
|
||||
namespace ZR.Admin.WebApi.Controllers.System
|
||||
{
|
||||
|
||||
@ -10,9 +10,9 @@ using System.Threading.Tasks;
|
||||
using ZR.Admin.WebApi.Extensions;
|
||||
using ZR.Admin.WebApi.Filters;
|
||||
using ZR.Model;
|
||||
using ZR.Model.Dto.System;
|
||||
using ZR.Model.System.Dto;
|
||||
using ZR.Model.System;
|
||||
using ZR.Service.IService;
|
||||
using ZR.Service.System.IService;
|
||||
using ZR.Tasks;
|
||||
|
||||
namespace ZR.Admin.WebApi.Controllers
|
||||
|
||||
@ -1,14 +1,14 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using SqlSugar;
|
||||
using ZR.Model;
|
||||
using ZR.Model.Dto.System;
|
||||
using ZR.Model.System.Dto;
|
||||
using ZR.Model.System;
|
||||
using Infrastructure.Extensions;
|
||||
using Infrastructure.Attribute;
|
||||
using ZR.Admin.WebApi.Filters;
|
||||
using ZR.Common;
|
||||
using Infrastructure.Enums;
|
||||
using ZR.Service.IService;
|
||||
using ZR.Service.System.IService;
|
||||
|
||||
namespace ZR.Admin.WebApi.Controllers.System
|
||||
{
|
||||
|
||||
@ -5,7 +5,7 @@ using ZR.Common;
|
||||
using ZR.Model;
|
||||
using ZR.Model.System;
|
||||
using ZR.Model.Vo;
|
||||
using ZR.Service.IService;
|
||||
using ZR.Service.System.IService;
|
||||
|
||||
namespace ZR.Admin.WebApi.Controllers.monitor
|
||||
{
|
||||
|
||||
@ -5,10 +5,10 @@ using Microsoft.AspNetCore.Mvc;
|
||||
using ZR.Admin.WebApi.Filters;
|
||||
using ZR.Common;
|
||||
using ZR.Model;
|
||||
using ZR.Model.Dto.System;
|
||||
using ZR.Model.System.Dto;
|
||||
using ZR.Model.System;
|
||||
using ZR.Model.Vo;
|
||||
using ZR.Service.IService;
|
||||
using ZR.Service.System.IService;
|
||||
|
||||
namespace ZR.Admin.WebApi.Controllers.monitor
|
||||
{
|
||||
|
||||
@ -49,27 +49,34 @@ namespace ZR.Admin.WebApi.Extensions
|
||||
return source;
|
||||
}
|
||||
|
||||
//public static TSource ToUpdate<TSource>(this TSource source, UserSessionVM userSession)
|
||||
//{
|
||||
// var types = source.GetType();
|
||||
|
||||
// if (types.GetProperty("UpdateTime") != null)
|
||||
// {
|
||||
// types.GetProperty("UpdateTime").SetValue(source, DateTime.Now, null);
|
||||
// }
|
||||
public static TSource ToUpdate<TSource>(this TSource source, HttpContext context = null)
|
||||
{
|
||||
var types = source.GetType();
|
||||
|
||||
if (types.GetProperty("UpdateTime") != null)
|
||||
{
|
||||
types.GetProperty("UpdateTime").SetValue(source, DateTime.Now, null);
|
||||
}
|
||||
if (types.GetProperty("Update_Time") != null)
|
||||
{
|
||||
types.GetProperty("Update_Time").SetValue(source, DateTime.Now, null);
|
||||
}
|
||||
//if (types.GetProperty("UpdateID") != null)
|
||||
//{
|
||||
// types.GetProperty("UpdateID").SetValue(source, userSession.UserID, null);
|
||||
//}
|
||||
|
||||
// if (types.GetProperty("UpdateName") != null)
|
||||
// {
|
||||
// types.GetProperty("UpdateName").SetValue(source, userSession.UserName, null);
|
||||
// }
|
||||
if (types.GetProperty("UpdateBy") != null)
|
||||
{
|
||||
types.GetProperty("UpdateBy").SetValue(source,context.GetName(), null);
|
||||
}
|
||||
if (types.GetProperty("Update_by") != null)
|
||||
{
|
||||
types.GetProperty("Update_by").SetValue(source, context.GetName(), null);
|
||||
}
|
||||
|
||||
// return source;
|
||||
//}
|
||||
return source;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -71,7 +71,7 @@ namespace ZR.Admin.WebApi.Extensions
|
||||
}
|
||||
public static string GetName(this HttpContext context)
|
||||
{
|
||||
var uid = context.User.Identity.Name;
|
||||
var uid = context.User?.Identity?.Name;
|
||||
|
||||
return uid;
|
||||
}
|
||||
|
||||
@ -3,7 +3,7 @@ using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Quartz.Spi;
|
||||
using System;
|
||||
using ZR.Service.IService;
|
||||
using ZR.Service.System.IService;
|
||||
using ZR.Tasks;
|
||||
|
||||
namespace ZR.Admin.WebApi.Extensions
|
||||
|
||||
@ -54,7 +54,7 @@ namespace ZR.Admin.WebApi.Filters
|
||||
bool isDemoMode = ConfigUtils.Instance.GetAppConfig("DemoMode", false);
|
||||
|
||||
//演示公开环境屏蔽权限
|
||||
string[] denyPerms = new string[] { "update", "add", "remove", "add", "edit", "delete", "import", "run", "start", "stop", "clear", "code" };
|
||||
string[] denyPerms = new string[] { "update", "add", "remove", "add", "edit", "delete", "import", "run", "start", "stop", "clear" };
|
||||
if (isDemoMode && (denyPerms.Any(f => Permission.ToLower().Contains(f.ToLower())) || Permission.Equals("system")))
|
||||
{
|
||||
context.Result = new JsonResult(new { code = ResultCode.FORBIDDEN, msg = "演示模式 , 不允许操作" });
|
||||
|
||||
@ -12,7 +12,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using ZR.Admin.WebApi.Extensions;
|
||||
using ZR.Model.System;
|
||||
using ZR.Service.IService;
|
||||
using ZR.Service.System.IService;
|
||||
|
||||
namespace ZR.Admin.WebApi.Filters
|
||||
{
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Infrastructure;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.IdentityModel.Tokens;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
@ -43,12 +44,13 @@ namespace ZR.Admin.WebApi.Framework
|
||||
{
|
||||
var tokenHandler = new JwtSecurityTokenHandler();
|
||||
var key = Encoding.ASCII.GetBytes(KEY);
|
||||
var expires = ConfigUtils.Instance.GetAppConfig("sysConfig:tokenExpire", 10);
|
||||
var tokenDescriptor = new SecurityTokenDescriptor
|
||||
{
|
||||
Subject = new ClaimsIdentity(claims),
|
||||
//Issuer = "",
|
||||
//Audience = "",
|
||||
Expires = DateTime.Now.AddDays(7),
|
||||
Expires = DateTime.Now.AddMinutes(expires),
|
||||
SigningCredentials = new SigningCredentials(new SymmetricSecurityKey(key), SecurityAlgorithms.HmacSha256Signature)
|
||||
};
|
||||
var token = tokenHandler.CreateToken(tokenDescriptor);
|
||||
|
||||
@ -9,7 +9,7 @@ using System.Threading.Tasks;
|
||||
using ZR.Admin.WebApi.Extensions;
|
||||
using ZR.Admin.WebApi.Filters;
|
||||
using ZR.Model.System;
|
||||
using ZR.Service.IService;
|
||||
using ZR.Service.System.IService;
|
||||
|
||||
namespace ZR.Admin.WebApi.Middleware
|
||||
{
|
||||
|
||||
@ -23,7 +23,8 @@
|
||||
<!--archiveAboveSize每个日志文件大小的最大值(单位:字节),主日志文件超过大小超过该值时会将文件内容写入滚动日志并清空主日志文件内容-->
|
||||
<!--${basedir}表示当前应用程序域所在的根目录-->
|
||||
<target name="allfile" xsi:type="File"
|
||||
fileName="${basedir}/adminlogs/nlog-all-${shortdate}.log"
|
||||
fileName="${basedir}/adminlogs/all.log"
|
||||
archiveFileName="${basedir}/adminlogs/all.{###}.txt"
|
||||
archiveAboveSize="20000000"
|
||||
maxArchiveFiles="30"
|
||||
keepFileOpen="false"
|
||||
|
||||
@ -1,130 +0,0 @@
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// 此代码已从模板生成。
|
||||
//
|
||||
// 手动更改此文件可能导致应用程序出现意外的行为。
|
||||
// 如果重新生成代码,将覆盖对此文件的手动更改。
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
using Infrastructure.Attribute;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using ZR.Admin.WebApi.Filters;
|
||||
using ZR.Model.System;
|
||||
using ZR.Service.IService;
|
||||
using Infrastructure.Model;
|
||||
using SqlSugar;
|
||||
using Mapster;
|
||||
using ZR.Model.Dto.System;
|
||||
using Infrastructure.Enums;
|
||||
using Infrastructure;
|
||||
using ZR.Admin.WebApi.Extensions;
|
||||
|
||||
namespace ZR.Admin.WebApi.Controllers
|
||||
{
|
||||
/// <summary>
|
||||
/// T4代码自动生成
|
||||
/// </summary>
|
||||
|
||||
[Verify]
|
||||
[Route("system/SysFile")]
|
||||
public class SysFile1Controller: BaseController
|
||||
{
|
||||
/// <summary>
|
||||
/// 文件管理接口
|
||||
/// </summary>
|
||||
private readonly ISysFileService _SysFileService;
|
||||
|
||||
public SysFile1Controller(ISysFileService SysFileService)
|
||||
{
|
||||
_SysFileService = SysFileService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查询文件管理列表
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet("list")]
|
||||
//[ActionPermissionFilter(Permission = "system:SysFile:list")]
|
||||
public IActionResult Query([FromQuery] SysFileQueryDto parm)
|
||||
{
|
||||
//开始拼装查询条件
|
||||
var predicate = Expressionable.Create<SysFile>();
|
||||
|
||||
//TODO 搜索条件
|
||||
//predicate = predicate.And(m => m.Name.Contains(parm.Name));
|
||||
|
||||
var response = _SysFileService.GetPages(predicate.ToExpression(), parm);
|
||||
|
||||
return SUCCESS(response);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查询文件管理详情
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("{id}")]
|
||||
public IActionResult Get(string id)
|
||||
{
|
||||
var response = _SysFileService.GetId(id);
|
||||
|
||||
return SUCCESS(response);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加文件管理
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
//[ActionPermissionFilter(Permission = "system:SysFile:add")]
|
||||
[Log(Title = "文件管理添加", BusinessType = BusinessType.INSERT)]
|
||||
public IActionResult Create([FromBody] SysFile parm)
|
||||
{
|
||||
if (parm == null)
|
||||
{
|
||||
throw new CustomException("请求参数错误");
|
||||
}
|
||||
//从 Dto 映射到 实体
|
||||
var addModel = parm.Adapt<SysFile>().ToCreate();
|
||||
//addModel.CreateID = User.Identity.Name;
|
||||
|
||||
return SUCCESS(_SysFileService.Add(addModel));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新文件管理
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPut("edit")]
|
||||
//[ActionPermissionFilter(Permission = "system:SysFile:update")]
|
||||
[Log(Title = "文件管理修改", BusinessType = BusinessType.UPDATE)]
|
||||
public IActionResult Update([FromBody] SysFile parm)
|
||||
{
|
||||
//从 Dto 映射到 实体
|
||||
var addModel = parm.Adapt<SysFile>().ToCreate();
|
||||
//addModel.CreateID = User.Identity.Name;
|
||||
//TODO 字段映射
|
||||
var response = _SysFileService.Update(addModel);
|
||||
|
||||
return SUCCESS(response);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除文件管理
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpDelete("{id}")]
|
||||
//[ActionPermissionFilter(Permission = "system:SysFile:delete")]
|
||||
[Log(Title = "文件管理删除", BusinessType = BusinessType.DELETE)]
|
||||
public IActionResult Delete(int id = 0)
|
||||
{
|
||||
if (id <= 0) { return OutputJson(ApiResult.Error($"删除失败Id 不能为空")); }
|
||||
|
||||
// 删除文件管理
|
||||
var response = _SysFileService.Delete(id);
|
||||
|
||||
return SUCCESS(response);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,145 +0,0 @@
|
||||
<#@ template debug="false" hostspecific="false" language="C#" #>
|
||||
<#@ assembly name="System.Core" #>
|
||||
<#@ import namespace="System.Linq" #>
|
||||
<#@ import namespace="System.Text" #>
|
||||
<#@ import namespace="System.Collections.Generic" #>
|
||||
<#@ output extension=".cs" #>
|
||||
|
||||
<#
|
||||
string ModelName="SysFile";
|
||||
string ControllerName="SysFile";
|
||||
string ServiceName="SysFileService";
|
||||
string FileName="文件管理";
|
||||
string ModelNameSpace="ZRAdmin.Controllers";
|
||||
#>
|
||||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// 此代码已从模板生成。
|
||||
//
|
||||
// 手动更改此文件可能导致应用程序出现意外的行为。
|
||||
// 如果重新生成代码,将覆盖对此文件的手动更改。
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
using Infrastructure.Attribute;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using ZRAdmin.Filters;
|
||||
using ZR.Model;
|
||||
using ZR.Model.System;
|
||||
using ZR.Model.Vo;
|
||||
using ZR.Service.IService;
|
||||
using Infrastructure.Model;
|
||||
using SqlSugar;
|
||||
using Mapster;
|
||||
using ZR.Model.Dto.System;
|
||||
using Infrastructure.Enums;
|
||||
using Infrastructure;
|
||||
using ZRAdmin.Extensions;
|
||||
|
||||
namespace <#=ModelNameSpace#>
|
||||
{
|
||||
/// <summary>
|
||||
/// T4代码自动生成
|
||||
/// </summary>
|
||||
|
||||
[Verify]
|
||||
[Route("system/<#=ModelName#>")]
|
||||
public class <#=ControllerName#>1Controller: BaseController
|
||||
{
|
||||
/// <summary>
|
||||
/// <#=FileName#>接口
|
||||
/// </summary>
|
||||
private readonly I<#=ServiceName#> _<#=ServiceName#>;
|
||||
|
||||
public <#=ControllerName#>1Controller(I<#=ServiceName#> <#=ServiceName#>)
|
||||
{
|
||||
_<#=ServiceName#> = <#=ServiceName#>;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查询<#=FileName#>列表
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet("list")]
|
||||
//[ActionPermissionFilter(Permission = "system:<#=ModelName#>:list")]
|
||||
public IActionResult Query([FromQuery] <#=ModelName#>QueryDto parm)
|
||||
{
|
||||
//开始拼装查询条件
|
||||
var predicate = Expressionable.Create<<#=ModelName#>>();
|
||||
|
||||
//TODO 搜索条件
|
||||
//predicate = predicate.And(m => m.Name.Contains(parm.Name));
|
||||
|
||||
var response = _<#=ServiceName#>.GetPages(predicate.ToExpression(), parm);
|
||||
|
||||
return SUCCESS(response);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查询<#=FileName#>详情
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("{id}")]
|
||||
public IActionResult Get(string id)
|
||||
{
|
||||
var response = _<#=ServiceName#>.GetId(id);
|
||||
|
||||
return SUCCESS(response);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加<#=FileName#>
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
//[ActionPermissionFilter(Permission = "system:<#=ModelName#>:add")]
|
||||
[Log(Title = "<#=FileName#>添加", BusinessType = BusinessType.INSERT)]
|
||||
public IActionResult Create([FromBody] <#=ModelName#> parm)
|
||||
{
|
||||
if (parm == null)
|
||||
{
|
||||
throw new CustomException("请求参数错误");
|
||||
}
|
||||
//从 Dto 映射到 实体
|
||||
var addModel = parm.Adapt<<#=ModelName#>>().ToCreate();
|
||||
//addModel.CreateID = User.Identity.Name;
|
||||
|
||||
return SUCCESS(_<#=ServiceName#>.Add(addModel));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新<#=FileName#>
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPut("edit")]
|
||||
//[ActionPermissionFilter(Permission = "system:<#=ModelName#>:update")]
|
||||
[Log(Title = "<#=FileName#>修改", BusinessType = BusinessType.UPDATE)]
|
||||
public IActionResult Update([FromBody] <#=ModelName#> parm)
|
||||
{
|
||||
//从 Dto 映射到 实体
|
||||
var addModel = parm.Adapt<<#=ModelName#>>().ToCreate();
|
||||
//addModel.CreateID = User.Identity.Name;
|
||||
//TODO 字段映射
|
||||
var response = _<#=ServiceName#>.Update(addModel);
|
||||
|
||||
return SUCCESS(response);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除<#=FileName#>
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpDelete("{id}")]
|
||||
//[ActionPermissionFilter(Permission = "system:<#=ModelName#>:delete")]
|
||||
[Log(Title = "<#=FileName#>删除", BusinessType = BusinessType.DELETE)]
|
||||
public IActionResult Delete(int id = 0)
|
||||
{
|
||||
if (id <= 0) { return OutputJson(ApiResult.Error($"删除失败Id 不能为空")); }
|
||||
|
||||
// 删除<#=FileName#>
|
||||
var response = _<#=ServiceName#>.Delete(id);
|
||||
|
||||
return SUCCESS(response);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,134 +0,0 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using ZR.Admin.WebApi.Filters;
|
||||
using ZR.Admin.WebApi.Controllers;
|
||||
using ZR.Service.Business;
|
||||
using SqlSugar;
|
||||
using Infrastructure;
|
||||
using Infrastructure.Attribute;
|
||||
using Infrastructure.Enums;
|
||||
using Infrastructure.Model;
|
||||
using Mapster;
|
||||
using ZR.Admin.WebApi.Extensions;
|
||||
using {ModelsNamespace}.Dto;
|
||||
using {ModelsNamespace}.Models;
|
||||
|
||||
namespace ZRAdmin.Controllers
|
||||
{
|
||||
/// <summary>
|
||||
/// 代码自动生成
|
||||
/// </summary>
|
||||
|
||||
[Verify]
|
||||
[Route("bus/{ModelName}")]
|
||||
public class {ControllerName}Controller: BaseController
|
||||
{
|
||||
/// <summary>
|
||||
/// {FileName}接口
|
||||
/// </summary>
|
||||
private readonly I{ServiceName} _{ServiceName};
|
||||
|
||||
public {ControllerName}Controller(I{ServiceName} {ServiceName})
|
||||
{
|
||||
_{ServiceName} = {ServiceName};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查询{FileName}列表
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet("list")]
|
||||
[ActionPermissionFilter(Permission = "{Permission}:list")]
|
||||
public IActionResult Query([FromQuery] {ModelName}QueryDto parm)
|
||||
{
|
||||
//开始拼装查询条件
|
||||
var predicate = Expressionable.Create<{ModelName}>();
|
||||
|
||||
//TODO 搜索条件
|
||||
//predicate = predicate.And(m => m.Name.Contains(parm.Name));
|
||||
|
||||
var response = _{ServiceName}.GetPages(predicate.ToExpression(), parm);
|
||||
|
||||
return SUCCESS(response);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查询{FileName}详情
|
||||
/// </summary>
|
||||
/// <param name="{primaryKey}"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("{{primaryKey}}")]
|
||||
[ActionPermissionFilter(Permission = "{Permission}:query")]
|
||||
public IActionResult Get({KeyTypeName} {primaryKey})
|
||||
{
|
||||
var response = _{ServiceName}.GetId({primaryKey});
|
||||
|
||||
return SUCCESS(response);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加{FileName}
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[ActionPermissionFilter(Permission = "{Permission}:add")]
|
||||
[Log(Title = "{FileName}添加", BusinessType = BusinessType.INSERT)]
|
||||
public IActionResult Create([FromBody] {ModelName}Dto parm)
|
||||
{
|
||||
if (parm == null)
|
||||
{
|
||||
throw new CustomException("请求参数错误");
|
||||
}
|
||||
//从 Dto 映射到 实体
|
||||
var addModel = parm.Adapt<{ModelName}>().ToCreate();
|
||||
//addModel.CreateID = User.Identity.Name;
|
||||
|
||||
return SUCCESS(_{ServiceName}.Add(addModel));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新{FileName}
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPut]
|
||||
[ActionPermissionFilter(Permission = "{Permission}:update")]
|
||||
[Log(Title = "{FileName}修改", BusinessType = BusinessType.UPDATE)]
|
||||
public IActionResult Update([FromBody] {ModelName}Dto parm)
|
||||
{
|
||||
if (parm == null)
|
||||
{
|
||||
throw new CustomException("请求实体不能为空");
|
||||
}
|
||||
//从 Dto 映射到 实体
|
||||
var updateModel = parm.Adapt<{ModelName}>().ToCreate();
|
||||
//updateModel.CreateID = User.Identity.Name;
|
||||
|
||||
var response = _{ServiceName}.Update(w => w.{primaryKey} == updateModel.{primaryKey}, it => new {ModelName}()
|
||||
{
|
||||
//TODO 字段映射
|
||||
{updateColumn}
|
||||
});
|
||||
|
||||
return SUCCESS(response);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除{FileName}
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpDelete("{{primaryKey}}")]
|
||||
[ActionPermissionFilter(Permission = "{Permission}:delete")]
|
||||
[Log(Title = "{FileName}删除", BusinessType = BusinessType.DELETE)]
|
||||
public IActionResult Delete({KeyTypeName} {primaryKey} = 0)
|
||||
{
|
||||
if ({primaryKey} <= 0) { return OutputJson(ApiResult.Error($"删除失败Id 不能为空")); }
|
||||
|
||||
// 删除{FileName}
|
||||
var response = _{ServiceName}.Delete({primaryKey});
|
||||
|
||||
return SUCCESS(response);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -15,6 +15,11 @@
|
||||
<ItemGroup>
|
||||
<Compile Remove="Filters\GlobalExceptionFilter.cs" />
|
||||
<Compile Remove="Middleware\RequestIPMiddleware.cs" />
|
||||
<Compile Remove="Template\Controller.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Remove="Template\Controller.tt" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
@ -53,10 +58,6 @@
|
||||
<None Update="ip2region.db">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Template\Controller.tt">
|
||||
<Generator>TextTemplatingFileGenerator</Generator>
|
||||
<LastGenOutput>Controller.cs</LastGenOutput>
|
||||
</None>
|
||||
<None Update="Template\ControllersTemplate.txt">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
@ -85,7 +86,7 @@
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Controllers\business\" />
|
||||
<Folder Include="wwwroot\" />
|
||||
<Folder Include="wwwroot\Generatecode\" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
@ -102,12 +103,4 @@
|
||||
<Service Include="{508349b6-6b84-4df5-91f0-309beebad82d}" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Update="Template\Controller.cs">
|
||||
<DesignTime>True</DesignTime>
|
||||
<AutoGen>True</AutoGen>
|
||||
<DependentUpon>Controller.tt</DependentUpon>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@ -1,31 +0,0 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft": "Warning",
|
||||
"Microsoft.Hosting.Lifetime": "Information"
|
||||
}
|
||||
},
|
||||
"ConnectionStrings": {
|
||||
"Conn_Admin": "server=127.0.0.1;user=zr;pwd=abc;database=admin",
|
||||
"ConnDynamic": "server=127.0.0.1;user=zr;pwd=abc;database={database}"//代码生成使用
|
||||
},
|
||||
"urls": "http://localhost:8888", //启动url
|
||||
"sysConfig": {
|
||||
"DBCommandTimeout": 10,
|
||||
"cors": "http://localhost:8887" //配置跨域地址
|
||||
},
|
||||
"DemoMode": false, //是否演示模式
|
||||
"DbKey": "",
|
||||
"DbType": 0, //MySql = 0, SqlServer = 1, Sqlite = 2, Oracle = 3, PostgreSQL = 4,
|
||||
"CodeGenDbType": 0,//代码生成数据库类型
|
||||
"Upload": {
|
||||
"UploadDirectory": "/",
|
||||
"UploadUrl": "http://localhost:8888"
|
||||
},
|
||||
"ALYUN_OCS": {
|
||||
"REGIONID": "cn-hangzhou",
|
||||
"KEY": "XX",
|
||||
"SECRET": "XX"
|
||||
}
|
||||
}
|
||||
@ -1,9 +0,0 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft": "Warning",
|
||||
"Microsoft.Hosting.Lifetime": "Information"
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -5,5 +5,33 @@
|
||||
"Microsoft": "Warning",
|
||||
"Microsoft.Hosting.Lifetime": "Information"
|
||||
}
|
||||
},
|
||||
"ConnectionStrings": {
|
||||
"conn_zrAdmin": "server=127.0.0.1;user=zr;pwd=abc;database=admin"
|
||||
},
|
||||
"conn_zrAdmin_Type": 0, //MySql = 0, SqlServer = 1
|
||||
"urls": "http://localhost:8888", //项目启动url
|
||||
"sysConfig": {
|
||||
"DBCommandTimeout": 10,
|
||||
"tokenExpire": 1440,//Jwt token超时时间(分)
|
||||
"cors": "http://localhost:8887" //跨域地址,多个用","隔开
|
||||
},
|
||||
"DemoMode": false, //是否演示模式
|
||||
"DbKey": "", //数据库加密key
|
||||
"Upload": {
|
||||
"UploadDirectory": "/",
|
||||
"UploadUrl": "http://localhost:8888"
|
||||
},
|
||||
"ALYUN_OCS": {
|
||||
"REGIONID": "cn-hangzhou",
|
||||
"KEY": "XX",
|
||||
"SECRET": "XX"
|
||||
},
|
||||
"gen": {
|
||||
"conn": "server=127.0.0.1;user=zr;pwd=abc;database={database}",
|
||||
"dbType": 0, //MySql = 0, SqlServer = 1
|
||||
"autoPre": true, //自动去除表前缀
|
||||
"author": "zr",
|
||||
"tablePrefix": "live_,sys_" //"表前缀(生成类名不会包含表前缀,多个用逗号分隔)",
|
||||
}
|
||||
}
|
||||
|
||||
134
ZR.Admin.WebApi/wwwroot/CodeGenTemplate/ControllersTemplate.txt
Normal file
134
ZR.Admin.WebApi/wwwroot/CodeGenTemplate/ControllersTemplate.txt
Normal file
@ -0,0 +1,134 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using SqlSugar;
|
||||
using Infrastructure;
|
||||
using Infrastructure.Attribute;
|
||||
using Infrastructure.Enums;
|
||||
using Infrastructure.Model;
|
||||
using Mapster;
|
||||
using {ModelsNamespace}.Dto;
|
||||
using {ModelsNamespace}.Models;
|
||||
using {ServicesNamespace}.Business;
|
||||
using {ApiControllerNamespace}.Extensions;
|
||||
using {ApiControllerNamespace}.Filters;
|
||||
using ZR.Common;
|
||||
|
||||
namespace {ApiControllerNamespace}.Controllers
|
||||
{
|
||||
/// <summary>
|
||||
/// 代码自动生成
|
||||
/// </summary>
|
||||
[Verify]
|
||||
[Route("{ModuleName}/{ModelName}")]
|
||||
public class {ModelName}Controller: BaseController
|
||||
{
|
||||
/// <summary>
|
||||
/// {TableDesc}接口
|
||||
/// </summary>
|
||||
private readonly I{ModelName}Service _{ModelName}Service;
|
||||
|
||||
public {ModelName}Controller(I{ModelName}Service {ModelName}Service)
|
||||
{
|
||||
_{ModelName}Service = {ModelName}Service;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查询{TableDesc}列表
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet("list")]
|
||||
[ActionPermissionFilter(Permission = "{Permission}:list")]
|
||||
public IActionResult Query{ModelName}([FromQuery] {ModelName}QueryDto parm)
|
||||
{
|
||||
//开始拼装查询条件
|
||||
var predicate = Expressionable.Create<{ModelName}>();
|
||||
|
||||
//TODO 搜索条件
|
||||
//predicate = predicate.And(m => m.Name.Contains(parm.Name));
|
||||
|
||||
var response = _{ModelName}Service.GetPages(predicate.ToExpression(), parm);
|
||||
|
||||
return SUCCESS(response);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查询{TableDesc}详情
|
||||
/// </summary>
|
||||
/// <param name="{PrimaryKey}"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("{{PrimaryKey}}")]
|
||||
[ActionPermissionFilter(Permission = "{Permission}:query")]
|
||||
public IActionResult Get{ModelName}({PKCsharpType} {PrimaryKey})
|
||||
{
|
||||
var response = _{ModelName}Service.GetId({PrimaryKey});
|
||||
|
||||
return SUCCESS(response);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加{TableDesc}
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[ActionPermissionFilter(Permission = "{Permission}:add")]
|
||||
[Log(Title = "{TableDesc}添加", BusinessType = BusinessType.INSERT)]
|
||||
public IActionResult Add{ModelName}([FromBody] {ModelName}Dto parm)
|
||||
{
|
||||
if (parm == null)
|
||||
{
|
||||
throw new CustomException("请求参数错误");
|
||||
}
|
||||
//从 Dto 映射到 实体
|
||||
var model = parm.Adapt<{ModelName}>().ToCreate();
|
||||
|
||||
return SUCCESS(_{ModelName}Service.Add(model, it => new
|
||||
{
|
||||
{InsertColumn}
|
||||
}));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新{TableDesc}
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPut]
|
||||
[ActionPermissionFilter(Permission = "{Permission}:update")]
|
||||
[Log(Title = "{TableDesc}修改", BusinessType = BusinessType.UPDATE)]
|
||||
public IActionResult Update{ModelName}([FromBody] {ModelName}Dto parm)
|
||||
{
|
||||
if (parm == null)
|
||||
{
|
||||
throw new CustomException("请求实体不能为空");
|
||||
}
|
||||
//从 Dto 映射到 实体
|
||||
var model = parm.Adapt<{ModelName}>().ToUpdate();
|
||||
|
||||
var response = _{ModelName}Service.Update(w => w.{PrimaryKey} == model.{PrimaryKey}, it => new {ModelName}()
|
||||
{
|
||||
//Update 字段映射
|
||||
{UpdateColumn}
|
||||
});
|
||||
|
||||
return SUCCESS(response);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除{TableDesc}
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpDelete("{ids}")]
|
||||
[ActionPermissionFilter(Permission = "{Permission}:delete")]
|
||||
[Log(Title = "{TableDesc}删除", BusinessType = BusinessType.DELETE)]
|
||||
public IActionResult Delete{ModelName}(string ids)
|
||||
{
|
||||
int[] idsArr = Tools.SpitIntArrary(ids);
|
||||
if (idsArr.Length <= 0) { return OutputJson(ApiResult.Error($"删除失败Id 不能为空")); }
|
||||
|
||||
var response = _{ModelName}Service.Delete(idsArr);
|
||||
|
||||
return SUCCESS(response);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -13,8 +13,12 @@ namespace {DtosNamespace}.Dto
|
||||
{PropertyName}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// {TableNameDesc}查询对象模型
|
||||
/// </summary>
|
||||
public class {ModelTypeName}QueryDto: PagerInfo
|
||||
{
|
||||
{QueryProperty}
|
||||
public DateTime? BeginTime { get; set; }
|
||||
public DateTime? EndTime { get; set; }
|
||||
}
|
||||
@ -9,7 +9,6 @@ using System.Text;
|
||||
using ZR.Common;
|
||||
using {ModelsNamespace}.Models;
|
||||
using {IRepositoriesNamespace};
|
||||
using {ServicesNamespace}.IService;
|
||||
|
||||
namespace {ServicesNamespace}.Business
|
||||
{
|
||||
19
ZR.Admin.WebApi/wwwroot/CodeGenTemplate/SqlTemplate.txt
Normal file
19
ZR.Admin.WebApi/wwwroot/CodeGenTemplate/SqlTemplate.txt
Normal file
@ -0,0 +1,19 @@
|
||||
-- 菜单
|
||||
INSERT INTO sys_menu(menuName, parentId, orderNum, path, component, isFrame, isCache, menuType, visible, status, perms, icon, create_by,create_time, update_by, update_time, remark)
|
||||
VALUES ('{FunctionName}', 0, 1, '/{ModuleName}/{ModelTypeName}', '{ModuleName}/{ViewsFileName}/index', 0, 0, 'C', '0', '0', '', '{Permission}:list', '', GETDATE(), '', NULL, '{ModelTypeDesc}');
|
||||
|
||||
-- 按钮父菜单id
|
||||
declare @menuId int = @@identity
|
||||
|
||||
|
||||
INSERT INTO sys_menu(menuName, parentId, orderNum, path, component, isFrame, isCache, menuType, visible, status, perms, icon, create_by,create_time, update_by, update_time, remark)
|
||||
VALUES ('查询', @menuId, 1, '#', NULL, 0, 0, 'F', '0', '0', '{Permission}:query', '', '', GETDATE(), '', NULL, '');
|
||||
|
||||
INSERT INTO sys_menu(menuName, parentId, orderNum, path, component, isFrame, isCache, menuType, visible, status, perms, icon, create_by,create_time, update_by, update_time, remark)
|
||||
VALUES ('新增', @menuId, 1, '#', NULL, 0, 0, 'F', '0', '0', '{Permission}:add', '', '', GETDATE(), '', NULL, NULL);
|
||||
|
||||
INSERT INTO sys_menu(menuName, parentId, orderNum, path, component, isFrame, isCache, menuType, visible, status, perms, icon, create_by,create_time, update_by, update_time, remark)
|
||||
VALUES ('删除', @menuId, 2, '#', NULL, 0, 0, 'F', '0', '0', '{Permission}:delete', '', '', GETDATE(), '', NULL, NULL);
|
||||
|
||||
INSERT INTO sys_menu(menuName, parentId, orderNum, path, component, isFrame, isCache, menuType, visible, status, perms, icon, create_by,create_time, update_by, update_time, remark)
|
||||
VALUES ('修改', @menuId, 3, '#', NULL, 0, 0, 'F', '0', '0', '{Permission}:update', '', '', GETDATE(), '', NULL, NULL);
|
||||
@ -4,11 +4,11 @@
|
||||
* {ModelTypeDesc}分页查询
|
||||
* @param {查询条件} data
|
||||
*/
|
||||
export function list{ModelTypeName}(data) {
|
||||
export function list{ModelTypeName}(query) {
|
||||
return request({
|
||||
url: 'bus/{ModelTypeName}/list',
|
||||
url: '{ModuleName}/{ModelTypeName}/list',
|
||||
method: 'get',
|
||||
params: data,
|
||||
params: query,
|
||||
})
|
||||
}
|
||||
|
||||
@ -18,7 +18,7 @@ export function list{ModelTypeName}(data) {
|
||||
*/
|
||||
export function add{ModelTypeName}(data) {
|
||||
return request({
|
||||
url: '/bus/{ModelTypeName}',
|
||||
url: '{ModuleName}/{ModelTypeName}',
|
||||
method: 'post',
|
||||
data: data,
|
||||
})
|
||||
@ -30,7 +30,7 @@ export function add{ModelTypeName}(data) {
|
||||
*/
|
||||
export function update{ModelTypeName}(data) {
|
||||
return request({
|
||||
url: '/bus/{ModelTypeName}',
|
||||
url: '{ModuleName}/{ModelTypeName}',
|
||||
method: 'PUT',
|
||||
data: data,
|
||||
})
|
||||
@ -42,7 +42,7 @@ export function update{ModelTypeName}(data) {
|
||||
*/
|
||||
export function get{ModelTypeName}(id) {
|
||||
return request({
|
||||
url: '/bus/{ModelTypeName}/' + id,
|
||||
url: '{ModuleName}/{ModelTypeName}/' + id,
|
||||
method: 'get'
|
||||
})
|
||||
}
|
||||
@ -53,7 +53,7 @@ export function get{ModelTypeName}(id) {
|
||||
*/
|
||||
export function del{ModelTypeName}(pid) {
|
||||
return request({
|
||||
url: '/bus/{ModelTypeName}/' + pid,
|
||||
url: '{ModuleName}/{ModelTypeName}/' + pid,
|
||||
method: 'delete'
|
||||
})
|
||||
}
|
||||
@ -2,23 +2,7 @@
|
||||
<div class="app-container">
|
||||
<!-- :model属性用于表单验证使用 比如下面的el-form-item 的 prop属性用于对表单值进行验证操作 -->
|
||||
<el-form :model="queryParams" label-position="left" inline ref="queryForm" :label-width="labelWidth" v-show="showSearch" @submit.native.prevent>
|
||||
<el-form-item label="文本文字">
|
||||
<el-input v-model="queryParams.xxx" placeholder="" />
|
||||
</el-form-item>
|
||||
<el-form-item label="数字">
|
||||
<el-input v-model.number="queryParams.xxx" placeholder="" />
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item label="下拉框">
|
||||
<el-select v-model="queryParams.xxx" placeholder="">
|
||||
<el-option v-for="dict in statusOptions" :key="dict.dictValue" :label="dict.dictLabel" :value="dict.dictValue" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item label="时间范围">
|
||||
<el-date-picker size="small" style="width: 240px" v-model="timeRange" value-format="yyyy-MM-dd" type="daterange" range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期">
|
||||
</el-date-picker>
|
||||
</el-form-item>
|
||||
{vueQueryFormHtml}
|
||||
|
||||
<el-row class="mb8" style="text-align:center">
|
||||
<el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
|
||||
@ -35,7 +19,7 @@
|
||||
<el-button type="success" :disabled="single" v-hasPermi="['{Permission}:update']" plain icon="el-icon-edit" size="mini" @click="handleUpdate">修改</el-button>
|
||||
</el-col>
|
||||
<el-col :span="1.5">
|
||||
<el-button type="danger" v-hasPermi="['{Permission}:delete']" plain icon="el-icon-delete" size="mini" @click="handleDelete">删除</el-button>
|
||||
<el-button type="danger" :disabled="multiple" v-hasPermi="['{Permission}:delete']" plain icon="el-icon-delete" size="mini" @click="handleDelete">删除</el-button>
|
||||
</el-col>
|
||||
<right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
|
||||
</el-row>
|
||||
@ -46,14 +30,14 @@
|
||||
{VueViewListContent}
|
||||
<el-table-column label="操作" align="center" width="200">
|
||||
<template slot-scope="scope">
|
||||
<el-button size="mini" v-hasPermi="['{Permission}: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="['{Permission}:delete']" size="mini" type="text" icon="el-icon-delete">删除</el-button>
|
||||
<el-button v-hasPermi="['{Permission}:update']" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)">编辑</el-button>
|
||||
<el-popconfirm title="确定删除吗?" @confirm="handleDelete(scope.row)" style="margin-left:10px">
|
||||
<el-button slot="reference" v-hasPermi="['{Permission}:delete']" type="text" icon="el-icon-delete">删除</el-button>
|
||||
</el-popconfirm>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
<el-pagination class="mt10" background :total="total" :current-page.sync="queryParams.pageNum" :page-size="queryParams.pageSize" :page-sizes="[20, 30, 50, 100]" layout="total, sizes, prev, pager, next, jumper" @size-change="handleSizeChange" @current-change="getList" />
|
||||
<pagination class="mt10" background :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList" />
|
||||
|
||||
<!-- 添加或修改菜单对话框 -->
|
||||
<el-dialog :title="title" :lock-scroll="false" :visible.sync="open" >
|
||||
@ -83,7 +67,7 @@ export default {
|
||||
return {
|
||||
labelWidth: "100px",
|
||||
formLabelWidth:"100px",
|
||||
// 选中数组
|
||||
// 选中{primaryKey}数组
|
||||
ids: [],
|
||||
// 非单个禁用
|
||||
single: true,
|
||||
@ -103,8 +87,7 @@ export default {
|
||||
form: {},
|
||||
// 时间范围数组
|
||||
timeRange: [],
|
||||
// xxx下拉框
|
||||
statusOptions: [],
|
||||
{VueDataContent}
|
||||
// 数据列表
|
||||
dataList: [],
|
||||
// 总记录数
|
||||
@ -124,6 +107,7 @@ export default {
|
||||
// this.getDicts("sys_normal_disable").then((response) => {
|
||||
// this.statusOptions = response.data;
|
||||
// });
|
||||
{MountedMethod}
|
||||
},
|
||||
methods: {
|
||||
// 查询数据
|
||||
@ -144,8 +128,8 @@ export default {
|
||||
// 重置数据表单
|
||||
reset() {
|
||||
this.form = {
|
||||
{VueViewEditFormContent}
|
||||
//需个性化处理内容
|
||||
{VueViewFormResetHtml}
|
||||
//TODO 根据实际内容调整
|
||||
};
|
||||
this.resetForm("form");
|
||||
},
|
||||
@ -158,6 +142,7 @@ export default {
|
||||
pageSize: 20,
|
||||
//TODO 重置字段
|
||||
};
|
||||
this.handleQuery();
|
||||
},
|
||||
// 多选框选中数据
|
||||
handleSelectionChange(selection) {
|
||||
@ -183,7 +168,8 @@ export default {
|
||||
},
|
||||
/** 删除按钮操作 */
|
||||
handleDelete(row) {
|
||||
del{ModelTypeName}(row.{primaryKey}).then((res) => {
|
||||
const {primaryKey}s = row.{primaryKey} || this.ids;
|
||||
del{ModelTypeName}({primaryKey}s.toString()).then((res) => {
|
||||
this.msgSuccess("删除成功");
|
||||
this.handleQuery();
|
||||
});
|
||||
@ -201,7 +187,6 @@ export default {
|
||||
});
|
||||
},
|
||||
beforeFileUpload(file) { },
|
||||
//文件上传成功方法
|
||||
{vueJsMethod}
|
||||
/** 提交按钮 */
|
||||
submitForm: function () {
|
||||
@ -49,6 +49,6 @@ namespace ZR.CodeGenerator
|
||||
/// <summary>
|
||||
/// 要生数据的表,用“,”分割
|
||||
/// </summary>
|
||||
public string TableList { get; set; }
|
||||
//public string TableList { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,152 +1,250 @@
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using ZR.CodeGenerator.CodeGenerator;
|
||||
using ZR.Model.System.Generate;
|
||||
|
||||
namespace ZR.CodeGenerator
|
||||
{
|
||||
/// <summary>
|
||||
/// 代码生成模板
|
||||
/// </summary>
|
||||
public class CodeGenerateTemplate
|
||||
{
|
||||
#region Template
|
||||
|
||||
public static string GetVueJsMethod(DbColumnInfo dbColumnInfo)
|
||||
/// <summary>
|
||||
/// 生成vuejs模板,目前只有上传文件方法
|
||||
/// </summary>
|
||||
/// <param name="dbColumnInfo"></param>
|
||||
/// <returns></returns>
|
||||
public static string GetVueJsMethod(GenTableColumn dbFieldInfo)
|
||||
{
|
||||
string columnName = CodeGeneratorTool.FirstLowerCase(dbColumnInfo.DbColumnName);
|
||||
string columnName = dbFieldInfo.ColumnName;
|
||||
string js = "";
|
||||
if (CodeGeneratorTool.imageFiled.Any(f => columnName.Contains(f)))
|
||||
if (dbFieldInfo.HtmlType.Equals(GenConstants.HTML_IMAGE_UPLOAD))
|
||||
{
|
||||
js += $"handleUpload{columnName}Success(res, file) {{\n";
|
||||
js += $" this.form.{columnName} = URL.createObjectURL(file.raw);\n";
|
||||
js += " // this.$refs.upload.clearFiles();\n";
|
||||
js += "},\n";
|
||||
js += " //文件上传成功方法\r\n";
|
||||
js += $" handleUpload{dbFieldInfo.CsharpField}Success(res, file) {{\r\n";
|
||||
js += $" this.form.{columnName} = URL.createObjectURL(file.raw);\r\n";
|
||||
js += " // this.$refs.upload.clearFiles();\r\n";
|
||||
js += " },\r";
|
||||
}
|
||||
//有下拉框选项初列表查询数据
|
||||
if (dbFieldInfo.HtmlType == GenConstants.HTML_SELECT && !string.IsNullOrEmpty(dbFieldInfo.DictType))
|
||||
{
|
||||
var sb = new System.Text.StringBuilder(500);
|
||||
sb.AppendLine(@$" // {dbFieldInfo.ColumnComment}字典翻译");
|
||||
sb.AppendLine($" {columnName}Format(row, column) {{");
|
||||
sb.AppendLine(@$" return this.selectDictLabel(this.{columnName}Options, row.{columnName});");
|
||||
sb.AppendLine(@" },");
|
||||
js += sb.ToString();
|
||||
}
|
||||
return js;
|
||||
}
|
||||
|
||||
//rules
|
||||
public static string GetFormRules(DbColumnInfo dbFieldInfo)
|
||||
public static string GetFormRules(GenTableColumn dbFieldInfo)
|
||||
{
|
||||
string vueViewEditFromRuleContent = "";
|
||||
//Rule 规则验证
|
||||
if (!dbFieldInfo.IsNullable && !dbFieldInfo.IsIdentity)
|
||||
if ((!dbFieldInfo.IsPk && !dbFieldInfo.IsIncrement) && dbFieldInfo.IsRequired)
|
||||
{
|
||||
vueViewEditFromRuleContent += $" {dbFieldInfo.DbColumnName}: [\n";
|
||||
vueViewEditFromRuleContent += $" {{ required: true, message:\"请输入{dbFieldInfo.ColumnDescription}\", trigger: \"blur\"}},\n";
|
||||
//vueViewEditFromRuleContent += " { min: 2, max: 50, message: \"长度在 2 到 50 个字符\", trigger:\"blur\" }\n";
|
||||
vueViewEditFromRuleContent += " ],\n";
|
||||
vueViewEditFromRuleContent += $" {dbFieldInfo.ColumnName}: [\r\n";
|
||||
vueViewEditFromRuleContent += $" {{ required: true, message: '请输入{dbFieldInfo.ColumnComment}', trigger: \"blur\"}},\r\n";
|
||||
vueViewEditFromRuleContent += " ],\r\n";
|
||||
}
|
||||
else if (TableMappingHelper.IsNumber(dbFieldInfo.ColumnType) && dbFieldInfo.IsRequired)
|
||||
{
|
||||
vueViewEditFromRuleContent += $" {dbFieldInfo.ColumnName}: [\r\n";
|
||||
vueViewEditFromRuleContent += $" {{ type: 'number', message: '{dbFieldInfo.ColumnName}必须为数字值', trigger: \"blur\"}},\r\n";
|
||||
vueViewEditFromRuleContent += " ],\r\n";
|
||||
}
|
||||
|
||||
return vueViewEditFromRuleContent;
|
||||
}
|
||||
|
||||
//model 属性
|
||||
public static string GetModelTemplate(DbColumnInfo dbFieldInfo)
|
||||
public static string GetModelTemplate(GenTableColumn dbFieldInfo)
|
||||
{
|
||||
string columnName = dbFieldInfo.DbColumnName.Substring(0, 1).ToUpper() + dbFieldInfo.DbColumnName[1..];
|
||||
var modelcontent = "";
|
||||
modelcontent += " /// <summary>\n";
|
||||
modelcontent += $" /// 描述 :{dbFieldInfo.ColumnDescription}\n";
|
||||
modelcontent += $" /// 空值 :{dbFieldInfo.IsNullable}\n";
|
||||
modelcontent += $" /// 默认 :{dbFieldInfo.DefaultValue}\n";
|
||||
modelcontent += " /// </summary>\n";
|
||||
if (dbFieldInfo.IsIdentity || dbFieldInfo.IsPrimarykey)
|
||||
modelcontent += " /// <summary>\r\n";
|
||||
modelcontent += $" /// 描述 :{dbFieldInfo.ColumnComment}\r\n";
|
||||
modelcontent += $" /// 空值 :{!dbFieldInfo.IsRequired}\r\n";
|
||||
modelcontent += " /// </summary>\r\n";
|
||||
if (dbFieldInfo.IsPk || dbFieldInfo.IsIncrement)
|
||||
{
|
||||
modelcontent += $" [SqlSugar.SugarColumn(IsPrimaryKey = {dbFieldInfo.IsPrimarykey.ToString().ToLower()}, IsIdentity = {dbFieldInfo.IsIdentity.ToString().ToLower()})]\n";
|
||||
modelcontent += $" [SqlSugar.SugarColumn(IsPrimaryKey = {dbFieldInfo.IsPk.ToString().ToLower()}, IsIdentity = {dbFieldInfo.IsIncrement.ToString().ToLower()})]\r\n";
|
||||
}
|
||||
modelcontent += $" public {TableMappingHelper.GetPropertyDatatype(dbFieldInfo.DataType)} {columnName} {{ get; set; }}\n\r";
|
||||
modelcontent += $" public {dbFieldInfo.CsharpType}{(GetModelRequired(dbFieldInfo))} {dbFieldInfo.CsharpField} {{ get; set; }}\r\n";
|
||||
return modelcontent;
|
||||
}
|
||||
//DTO model
|
||||
public static string GetDtoContent(DbColumnInfo dbFieldInfo)
|
||||
public static string GetModelRequired(GenTableColumn dbFieldInfo)
|
||||
{
|
||||
string str = "";
|
||||
if (!dbFieldInfo.IsRequired && (dbFieldInfo.CsharpType == "int" || dbFieldInfo.CsharpType == "long" || dbFieldInfo.CsharpType == "DateTime"))
|
||||
{
|
||||
str = "?";
|
||||
}
|
||||
|
||||
return str;
|
||||
}
|
||||
//DTO model
|
||||
public static string GetDtoProperty(GenTableColumn dbFieldInfo)
|
||||
{
|
||||
string columnName = dbFieldInfo.DbColumnName.Substring(0, 1).ToUpper() + dbFieldInfo.DbColumnName[1..];
|
||||
string InputDtoContent = "";
|
||||
InputDtoContent += $" public {TableMappingHelper.GetPropertyDatatype(dbFieldInfo.DataType)} {columnName} {{ get; set; }}\n\r";
|
||||
if (GenConstants.inputDtoNoField.Any(f => f.Replace("_", "").ToLower().Contains(dbFieldInfo.CsharpField.ToLower().Replace("_", ""))))
|
||||
{
|
||||
return InputDtoContent;
|
||||
}
|
||||
else if (dbFieldInfo.IsInsert || dbFieldInfo.IsEdit || dbFieldInfo.IsPk || dbFieldInfo.IsIncrement)
|
||||
{
|
||||
InputDtoContent += $" public {dbFieldInfo.CsharpType}{GetModelRequired(dbFieldInfo)} {dbFieldInfo.CsharpField} {{ get; set; }}\r\n";
|
||||
}
|
||||
|
||||
return InputDtoContent;
|
||||
}
|
||||
/// <summary>
|
||||
/// 查询Dto属性
|
||||
/// </summary>
|
||||
/// <param name="dbFieldInfo"></param>
|
||||
/// <returns></returns>
|
||||
public static string GetQueryDtoProperty(GenTableColumn dbFieldInfo)
|
||||
{
|
||||
string QueryDtoContent = "";
|
||||
if (dbFieldInfo.IsQuery && !GenConstants.inputDtoNoField.Any(f => f.Replace("_", "").ToLower().Contains(dbFieldInfo.CsharpField.ToLower().Replace("_", ""))))
|
||||
{
|
||||
QueryDtoContent += $" public {dbFieldInfo.CsharpType} {dbFieldInfo.CsharpField} {{ get; set; }}\r\n";
|
||||
}
|
||||
|
||||
return QueryDtoContent;
|
||||
}
|
||||
|
||||
//form-item
|
||||
public static string GetVueViewFormContent(DbColumnInfo dbFieldInfo)
|
||||
public static string GetVueViewFormContent(GenTableColumn dbFieldInfo)
|
||||
{
|
||||
string columnName = CodeGeneratorTool.FirstLowerCase(dbFieldInfo.DbColumnName);
|
||||
string labelName = CodeGeneratorTool.GetLabelName(dbFieldInfo.ColumnDescription, columnName);
|
||||
string columnName = dbFieldInfo.ColumnName;
|
||||
string labelName = CodeGeneratorTool.GetLabelName(dbFieldInfo.ColumnComment, columnName);
|
||||
string vueViewFromContent = "";
|
||||
string labelDisabled = dbFieldInfo.IsIdentity ? ":disabled=\"true\"" : "";
|
||||
string placeHolder = dbFieldInfo.IsIdentity ? "" : $"请输入{CodeGeneratorTool.GetLabelName(dbFieldInfo.ColumnDescription, columnName)}";
|
||||
|
||||
if (dbFieldInfo.DataType == "datetime")
|
||||
string labelDisabled = dbFieldInfo.IsPk ? ":disabled=\"true\"" : "";
|
||||
string placeHolder = dbFieldInfo.IsIncrement ? "" : $"请输入{labelName}";
|
||||
if (GenConstants.inputDtoNoField.Any(f => f.Replace("_", "").ToLower().Contains(dbFieldInfo.CsharpField.ToLower().Replace("_", ""))))
|
||||
{
|
||||
return vueViewFromContent;
|
||||
}
|
||||
if (!dbFieldInfo.IsInsert || !dbFieldInfo.IsEdit)
|
||||
{
|
||||
return vueViewFromContent;
|
||||
}
|
||||
if (dbFieldInfo.HtmlType == GenConstants.HTML_DATETIME)
|
||||
{
|
||||
//时间
|
||||
vueViewFromContent += $" <el-form-item label=\"{labelName}\" :label-width=\"labelWidth\" prop=\"{columnName}\">\n";
|
||||
vueViewFromContent += $" <el-date-picker v-model=\"form.{columnName}\" type=\"datetime\" placeholder=\"选择日期时间\" default-time=\"12:00:00\"> </el-date-picker>\n";
|
||||
vueViewFromContent += " </el-form-item>\n";
|
||||
vueViewFromContent += $" <el-form-item label=\"{labelName}\" :label-width=\"labelWidth\" prop=\"{columnName}\">\r\n";
|
||||
vueViewFromContent += $" <el-date-picker v-model=\"form.{columnName}\" type=\"datetime\" placeholder=\"选择日期时间\" default-time=\"12:00:00\"> </el-date-picker>\r\n";
|
||||
vueViewFromContent += " </el-form-item>\r\n";
|
||||
}
|
||||
else if (CodeGeneratorTool.imageFiled.Any(f => columnName.Contains(f)))
|
||||
else if (dbFieldInfo.HtmlType == GenConstants.HTML_IMAGE_UPLOAD)
|
||||
{
|
||||
//图片
|
||||
vueViewFromContent += $" <el-form-item label=\"{labelName}\" :label-width=\"labelWidth\" prop=\"{columnName}\">\n";
|
||||
vueViewFromContent += $" <el-upload class=\"avatar-uploader\" name=\"file\" action=\"/api/upload/saveFile/\" :show-file-list=\"false\" :on-success=\"handleUpload{columnName}Success\" :before-upload=\"beforeFileUpload\">\n";
|
||||
vueViewFromContent += $" <img v-if=\"form.{columnName}\" :src=\"form.{columnName}\" class=\"icon\">\n";
|
||||
vueViewFromContent += " <i v-else class=\"el-icon-plus uploader-icon\"></i>\n";
|
||||
vueViewFromContent += " </el-upload>\n";
|
||||
vueViewFromContent += $" <el-input v-model=\"form.{columnName}\" placeholder=\"请上传文件或手动输入文件地址\"></el-input>\n";
|
||||
vueViewFromContent += " </el-form-item>\n";
|
||||
vueViewFromContent += $" <el-form-item label=\"{labelName}\" :label-width=\"labelWidth\" prop=\"{columnName}\">\r\n";
|
||||
vueViewFromContent += $" <el-upload class=\"avatar-uploader\" name=\"file\" action=\"/api/upload/saveFile/\" :show-file-list=\"false\" :on-success=\"handleUpload{dbFieldInfo.CsharpField}Success\" :before-upload=\"beforeFileUpload\">\r\n";
|
||||
vueViewFromContent += $" <img v-if=\"form.{columnName}\" :src=\"form.{columnName}\" class=\"icon\">\r\n";
|
||||
vueViewFromContent += " <i v-else class=\"el-icon-plus uploader-icon\"></i>\r\n";
|
||||
vueViewFromContent += " </el-upload>\r\n";
|
||||
vueViewFromContent += $" <el-input v-model=\"form.{columnName}\" placeholder=\"请上传文件或手动输入文件地址\"></el-input>\r\n";
|
||||
vueViewFromContent += " </el-form-item>\r\n";
|
||||
}
|
||||
else if (CodeGeneratorTool.radioFiled.Any(f => columnName.Contains(f)) && (dbFieldInfo.DataType == "bool" || dbFieldInfo.DataType == "tinyint" || dbFieldInfo.DataType == "int"))
|
||||
else if (dbFieldInfo.HtmlType == GenConstants.HTML_RADIO)
|
||||
{
|
||||
vueViewFromContent += $" <el-form-item label=\"{labelName}\" :label-width=\"labelWidth\" prop=\"{columnName}\">";
|
||||
vueViewFromContent += $" <el-radio-group v-model=\"form.{columnName}\">\n";
|
||||
vueViewFromContent += " <el-radio v-for=\"dict in statusOptions\" :key=\"dict.dictValue\" :label=\"dict.dictValue\">{{dict.dictLabel}}</el-radio>\n";
|
||||
vueViewFromContent += " </el-radio-group>\n";
|
||||
vueViewFromContent += " </el-form-item>\n";
|
||||
vueViewFromContent += $" <el-form-item label=\"{labelName}\" :label-width=\"labelWidth\" prop=\"{columnName}\">\r\n";
|
||||
vueViewFromContent += $" <el-radio-group v-model=\"form.{columnName}\">\r\n";
|
||||
vueViewFromContent += " <el-radio :key=\"1\" :label=\"1\">是</el-radio>\r\n";
|
||||
vueViewFromContent += " <el-radio :key=\"0\" :label=\"0\">否</el-radio>\r\n";
|
||||
vueViewFromContent += " </el-radio-group>\r\n";
|
||||
vueViewFromContent += " </el-form-item>\r\n";
|
||||
}
|
||||
else if (dbFieldInfo.HtmlType == GenConstants.HTML_TEXTAREA)
|
||||
{
|
||||
vueViewFromContent += $" <el-form-item label=\"{ labelName}\" :label-width=\"labelWidth\" prop=\"{columnName}\">\r\n";
|
||||
vueViewFromContent += $" <el-input type=\"textarea\" v-model=\"form.{columnName}\" placeholder=\"请输入内容\"/>\r\n";
|
||||
vueViewFromContent += " </el-form-item>\r\n";
|
||||
}
|
||||
else if (dbFieldInfo.HtmlType == GenConstants.HTML_SELECT && !string.IsNullOrEmpty(dbFieldInfo.DictType))
|
||||
{
|
||||
string value = TableMappingHelper.IsNumber(dbFieldInfo.CsharpType) ? "parseInt(item.dictValue)" : "item.dictValue";
|
||||
vueViewFromContent += $" <el-form-item label=\"{ labelName}\" :label-width=\"labelWidth\" prop=\"{columnName}\">\r\n";
|
||||
vueViewFromContent += $" <el-select v-model=\"form.{columnName}\">\r\n";
|
||||
vueViewFromContent += $" <el-option v-for=\"item in {columnName}Options\" :key=\"item.dictValue\" :label=\"item.dictLabel\" :value=\"{value}\"></el-option>\r\n";
|
||||
vueViewFromContent += " </el-select>\r\n";
|
||||
vueViewFromContent += " </el-form-item>\r\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
vueViewFromContent += $" <el-form-item label=\"{ CodeGeneratorTool.GetLabelName(dbFieldInfo.ColumnDescription, columnName)}\" :label-width=\"labelWidth\" prop=\"{CodeGeneratorTool.FirstLowerCase(columnName)}\">\n";
|
||||
vueViewFromContent += $" <el-input v-model=\"form.{CodeGeneratorTool.FirstLowerCase(columnName)}\" placeholder=\"{placeHolder}\" {labelDisabled}/>\n";
|
||||
vueViewFromContent += " </el-form-item>\n";
|
||||
string inputNumTxt = TableMappingHelper.IsNumber(dbFieldInfo.CsharpType) ? ".number" : "";
|
||||
vueViewFromContent += $" <el-form-item label=\"{labelName}\" :label-width=\"labelWidth\" prop=\"{CodeGeneratorTool.FirstLowerCase(columnName)}\">\r\n";
|
||||
vueViewFromContent += $" <el-input v-model{inputNumTxt}=\"form.{CodeGeneratorTool.FirstLowerCase(columnName)}\" placeholder=\"{placeHolder}\" {labelDisabled}/>\r\n";
|
||||
vueViewFromContent += " </el-form-item>\r\n";
|
||||
}
|
||||
|
||||
return vueViewFromContent;
|
||||
}
|
||||
|
||||
//table-column
|
||||
public static string GetTableColumn(DbColumnInfo dbFieldInfo)
|
||||
/// <summary>
|
||||
/// 查询表单
|
||||
/// </summary>
|
||||
/// <param name="dbFieldInfo"></param>
|
||||
/// <returns></returns>
|
||||
public static string GetQueryFormHtml(GenTableColumn dbFieldInfo)
|
||||
{
|
||||
string columnName = CodeGeneratorTool.FirstLowerCase(dbFieldInfo.DbColumnName);
|
||||
string label = CodeGeneratorTool.GetLabelName(dbFieldInfo.ColumnDescription, columnName);
|
||||
string vueViewListContent = "";
|
||||
string showToolTip = dbFieldInfo.DataType.Contains("varchar") ? ":show-overflow-tooltip=\"true\"" : "";
|
||||
string queryFormHtml = "";
|
||||
string labelName = CodeGeneratorTool.GetLabelName(dbFieldInfo.ColumnComment, dbFieldInfo.ColumnName);
|
||||
if (!dbFieldInfo.IsQuery || dbFieldInfo.HtmlType == GenConstants.HTML_FILE_UPLOAD) return queryFormHtml;
|
||||
|
||||
if (CodeGeneratorTool.imageFiled.Any(f => columnName.ToLower().Contains(f)))
|
||||
if (dbFieldInfo.HtmlType == GenConstants.HTML_DATETIME)
|
||||
{
|
||||
vueViewListContent += $" <el-table-column prop=\"{ columnName}\" label=\"图片\">\n";
|
||||
vueViewListContent += " <template slot-scope=\"scope\">\n";
|
||||
vueViewListContent += $" <el-image class=\"table-td-thumb\" :src=\"scope.row.{columnName}\" :preview-src-list=\"[scope.row.{columnName}]\"></el-image>\n";
|
||||
vueViewListContent += " </template>\n";
|
||||
vueViewListContent += " </el-table-column>\n";
|
||||
}
|
||||
else if (dbFieldInfo.DataType == "bool" || dbFieldInfo.DataType == "tinyint")
|
||||
{
|
||||
vueViewListContent += $" <el-table-column prop=\"{columnName}\" label=\"{label}\" width=\"120\" >\n";
|
||||
vueViewListContent += " <template slot-scope=\"scope\">\n";
|
||||
vueViewListContent += $" <el-tag :type=\"scope.row.{columnName} === true ? 'success' : 'info'\" disable-transitions >";
|
||||
vueViewListContent += $" {{scope.row.{columnName}===true?'启用':'禁用'}} </el-tag>\n";
|
||||
vueViewListContent += " </template>\n";
|
||||
vueViewListContent += " </el-table-column>\n";
|
||||
queryFormHtml += "<el-form-item label=\"时间\">\r\n";
|
||||
queryFormHtml += " <el-date-picker v-model=\"dateRange\" size=\"small\" value-format=\"yyyy-MM-dd\" type=\"daterange\" range-separator=\"-\" start-placeholder=\"开始日期\" end-placeholder=\"结束日期\"></el-date-picker>\r\n";
|
||||
queryFormHtml += "</el-form-item>\r\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
string inputNumTxt = TableMappingHelper.IsNumber(dbFieldInfo.CsharpType) ? ".number" : "";
|
||||
queryFormHtml += $" <el-form-item label=\"{ labelName}\" :label-width=\"labelWidth\">\r\n";
|
||||
queryFormHtml += $" <el-input v-model{inputNumTxt}=\"queryParams.{CodeGeneratorTool.FirstLowerCase(dbFieldInfo.CsharpField)}\"/>\r\n";
|
||||
queryFormHtml += " </el-form-item>\r\n";
|
||||
}
|
||||
|
||||
return queryFormHtml;
|
||||
}
|
||||
|
||||
//table-column
|
||||
vueViewListContent += $" <el-table-column prop=\"{CodeGeneratorTool.FirstLowerCase(columnName)}\" label=\"{CodeGeneratorTool.GetLabelName(dbFieldInfo.ColumnDescription, columnName)}\" align=\"center\" width=\"100\" {showToolTip} />\n";
|
||||
public static string GetTableColumn(GenTableColumn dbFieldInfo)
|
||||
{
|
||||
string columnName = dbFieldInfo.ColumnName;
|
||||
string label = CodeGeneratorTool.GetLabelName(dbFieldInfo.ColumnComment, columnName);
|
||||
string vueViewListContent = "";
|
||||
string showToolTip = dbFieldInfo.CsharpType == "string" ? ":show-overflow-tooltip=\"true\"" : "";
|
||||
string formatter = !string.IsNullOrEmpty(dbFieldInfo.DictType) ? $" :formatter=\"{columnName}Format\"" : "";
|
||||
|
||||
if (dbFieldInfo.IsList && dbFieldInfo.HtmlType.Equals(GenConstants.HTML_IMAGE_UPLOAD))
|
||||
{
|
||||
vueViewListContent += $" <el-table-column prop=\"{columnName}\" label=\"图片\">\r\n";
|
||||
vueViewListContent += " <template slot-scope=\"scope\">\r\n";
|
||||
vueViewListContent += $" <el-image class=\"table-td-thumb\" :src=\"scope.row.{columnName}\" :preview-src-list=\"[scope.row.{columnName}]\"></el-image>\r\n";
|
||||
vueViewListContent += " </template>\r\n";
|
||||
vueViewListContent += " </el-table-column>\r\n";
|
||||
}
|
||||
//else if (dbFieldInfo.HtmlType.Equals(GenConstants.HTML_RADIO))
|
||||
//{
|
||||
// vueViewListContent += $" <el-table-column prop=\"{columnName}\" label=\"{label}\" width=\"120\" >\r\n";
|
||||
// vueViewListContent += " <template slot-scope=\"scope\">\r\n";
|
||||
// vueViewListContent += $" <el-tag :type=\"scope.row.{columnName} === true ? 'success' : 'info'\" disable-transitions >";
|
||||
// vueViewListContent += $" {{scope.row.{columnName}===true?'启用':'禁用'}} </el-tag>\r\n";
|
||||
// vueViewListContent += " </template>\r\n";
|
||||
// vueViewListContent += " </el-table-column>\r\n";
|
||||
//}
|
||||
else if(dbFieldInfo.IsList)
|
||||
{
|
||||
vueViewListContent += $" <el-table-column prop=\"{columnName}\" label=\"{label}\" align=\"center\" {showToolTip}{formatter}/>\r\n";
|
||||
}
|
||||
return vueViewListContent;
|
||||
}
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,10 +1,15 @@
|
||||
using SqlSugar;
|
||||
using Infrastructure;
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using ZR.CodeGenerator.CodeGenerator;
|
||||
using ZR.CodeGenerator.Model;
|
||||
using ZR.CodeGenerator.Service;
|
||||
using ZR.Model.System.Generate;
|
||||
|
||||
namespace ZR.CodeGenerator
|
||||
{
|
||||
@ -20,38 +25,26 @@ namespace ZR.CodeGenerator
|
||||
/// 代码生成器配置
|
||||
/// </summary>
|
||||
private static CodeGenerateOption _option = new CodeGenerateOption();
|
||||
/// <summary>
|
||||
/// InputDto输入实体是不包含字段
|
||||
/// </summary>
|
||||
public static readonly string[] inputDtoNoField = new string[] { "DeleteMark", "CreateTime", "updateTime", "addtime" };
|
||||
public static readonly string[] imageFiled = new string[] { "icon", "img", "image", "url", "pic", "photo" };
|
||||
public static readonly string[] selectFiled = new string[] { "status", "type", "state", "sex", "gender" };
|
||||
public static readonly string[] radioFiled = new string[] { "status", "state", "isShow", "isHidden", "ishide" };
|
||||
|
||||
/// <summary>
|
||||
/// 代码生成器入口方法
|
||||
/// </summary>
|
||||
/// <param name="dbTableInfo"></param>
|
||||
/// <param name="dto"></param>
|
||||
public static void Generate(DbTableInfo dbTableInfo, GenerateDto dto)
|
||||
public static List<string> Generate(GenTable dbTableInfo, GenerateDto dto)
|
||||
{
|
||||
//_option.BaseNamespace = baseNamespace;
|
||||
//_option.TableList = listTable;
|
||||
_option.ReplaceTableNameStr = dto.replaceTableNameStr;
|
||||
_option.DtosNamespace = "ZR.Model";
|
||||
_option.ModelsNamespace = "ZR.Model";
|
||||
_option.RepositoriesNamespace = "ZR.Repository";
|
||||
_option.IRepositoriesNamespace = "ZR.Repository";
|
||||
_option.IServicsNamespace = "ZR.Service";
|
||||
_option.ServicesNamespace = "ZR.Service";
|
||||
_option.ApiControllerNamespace = "ZR.Admin.WebApi";
|
||||
_option.BaseNamespace = dbTableInfo.BaseNameSpace;
|
||||
_option.DtosNamespace = _option.BaseNamespace + "Model";
|
||||
_option.ModelsNamespace = _option.BaseNamespace + "Model";
|
||||
_option.RepositoriesNamespace = _option.BaseNamespace + "Repository";
|
||||
_option.IRepositoriesNamespace = _option.BaseNamespace + "Repository";
|
||||
_option.IServicsNamespace = _option.BaseNamespace + "Service";
|
||||
_option.ServicesNamespace = _option.BaseNamespace + "Service";
|
||||
_option.ApiControllerNamespace = _option.BaseNamespace + "Admin.WebApi";
|
||||
|
||||
CodeGeneraterService codeGeneraterService = new CodeGeneraterService();
|
||||
List<string> list = GenerateSingle(dbTableInfo?.Columns, dbTableInfo, dto);
|
||||
|
||||
List<DbColumnInfo> listField = codeGeneraterService.GetColumnInfo(dto.dbName, dbTableInfo.Name);
|
||||
GenerateSingle(listField, dbTableInfo, dto);
|
||||
|
||||
//GenerateDtoProfile(_option.ModelsNamespace, profileContent, ifExsitedCovered);
|
||||
return list;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -59,162 +52,172 @@ namespace ZR.CodeGenerator
|
||||
/// </summary>
|
||||
/// <param name="listField">表字段集合</param>
|
||||
/// <param name="tableInfo">表信息</param>
|
||||
/// <param name="ifExsitedCovered">如果目标文件存在,是否覆盖。默认为false</param>
|
||||
public static void GenerateSingle(List<DbColumnInfo> listField, DbTableInfo tableInfo, GenerateDto dto)
|
||||
/// <param name="dto"></param>
|
||||
public static List<string> GenerateSingle(List<GenTableColumn> listField, GenTable tableInfo, GenerateDto dto)
|
||||
{
|
||||
bool ifExsitedCovered = dto.coverd;
|
||||
var modelTypeName = GetModelClassName(tableInfo.Name);//表名对应C# 实体类名
|
||||
var modelTypeDesc = tableInfo.Description;//表描述
|
||||
var primaryKey = "id";//主键
|
||||
string PKName = "id";
|
||||
string PKType = "int";
|
||||
List<string> genPathList = new();
|
||||
ReplaceDto replaceDto = new();
|
||||
replaceDto.ModelTypeName = tableInfo.ClassName;//表名对应C# 实体类名
|
||||
replaceDto.TableName = tableInfo.TableName;//表名
|
||||
replaceDto.TableDesc = tableInfo.TableComment;//表说明描述
|
||||
replaceDto.Permission = tableInfo.ClassName.ToLower();//权限
|
||||
replaceDto.ViewsFileName = FirstLowerCase(replaceDto.ModelTypeName);
|
||||
//循环表字段信息
|
||||
foreach (GenTableColumn dbFieldInfo in listField)
|
||||
{
|
||||
string columnName = dbFieldInfo.ColumnName;
|
||||
|
||||
string keyTypeName = "int";//主键数据类型
|
||||
string modelContent = "";//数据库模型字段
|
||||
string InputDtoContent = "";//输入模型
|
||||
//string outputDtoContent = "";//输出模型
|
||||
string updateColumn = "";//修改数据映射字段
|
||||
string vueViewListContent = string.Empty;//Vue列表输出内容
|
||||
string vueViewFormContent = string.Empty;//Vue表单输出内容
|
||||
string vueViewEditFromContent = string.Empty;//Vue变量输出内容
|
||||
string vueViewEditFromBindContent = string.Empty;//Vue显示初始化输出内容
|
||||
string vueViewSaveBindContent = string.Empty;//Vue保存时输出内容
|
||||
string vueViewEditFromRuleContent = string.Empty;//Vue数据校验
|
||||
string vueJsMethod = string.Empty;//Vue js自定义方法
|
||||
if (dbFieldInfo.IsInsert || dbFieldInfo.IsEdit)
|
||||
{
|
||||
replaceDto.VueViewFormResetHtml += $" {columnName}: undefined,\r\n";
|
||||
}
|
||||
if (dbFieldInfo.IsPk || dbFieldInfo.IsIncrement)
|
||||
{
|
||||
PKName = dbFieldInfo.CsharpField;
|
||||
PKType = dbFieldInfo.CsharpType;
|
||||
}
|
||||
//编辑字段
|
||||
if (dbFieldInfo.IsEdit)
|
||||
{
|
||||
replaceDto.UpdateColumn += $"{dbFieldInfo.CsharpField} = model.{dbFieldInfo.CsharpField}, ";
|
||||
}
|
||||
//新增字段
|
||||
if (dbFieldInfo.IsInsert)
|
||||
{
|
||||
replaceDto.InsertColumn += $"it.{dbFieldInfo.CsharpField}, ";
|
||||
}
|
||||
//TODO 查询
|
||||
//if (dbFieldInfo.IsQuery)
|
||||
//{
|
||||
// replaceDto.Querycondition += $"predicate = predicate.And(m => m.{dbFieldInfo.CsharpField}.Contains(parm.Name));";
|
||||
//}
|
||||
if ((dbFieldInfo.HtmlType == GenConstants.HTML_SELECT || dbFieldInfo.HtmlType == GenConstants.HTML_RADIO) && !string.IsNullOrEmpty(dbFieldInfo.DictType))
|
||||
{
|
||||
replaceDto.VueDataContent += $" // {dbFieldInfo.ColumnComment}选项列表\n";
|
||||
replaceDto.VueDataContent += $" {FirstLowerCase(dbFieldInfo.CsharpField)}Options: [],";
|
||||
|
||||
foreach (DbColumnInfo dbFieldInfo in listField)
|
||||
{
|
||||
string columnName = FirstLowerCase(dbFieldInfo.DbColumnName);
|
||||
|
||||
if (dbFieldInfo.DataType == "bool" || dbFieldInfo.DataType == "tinyint")
|
||||
{
|
||||
vueViewEditFromContent += $" {columnName}: 'true',\n";
|
||||
//vueViewEditFromBindContent += $" this.form.{columnName} = res.data.{0}+''\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
vueViewEditFromContent += $" {columnName}: undefined,\n";
|
||||
//vueViewEditFromBindContent += $" {columnName}: row.{columnName},\n";
|
||||
}
|
||||
//vueViewSaveBindContent += string.Format(" '{0}':this.editFrom.{0},\n", columnName);
|
||||
//主键
|
||||
if (dbFieldInfo.IsIdentity || dbFieldInfo.IsPrimarykey)
|
||||
{
|
||||
primaryKey = columnName.Substring(0, 1).ToUpper() + columnName[1..];
|
||||
keyTypeName = dbFieldInfo.DataType;
|
||||
}
|
||||
else
|
||||
{
|
||||
var tempColumnName = columnName.Substring(0, 1).ToUpper() + columnName[1..];
|
||||
updateColumn += $" {tempColumnName} = parm.{tempColumnName},\n";
|
||||
replaceDto.MountedMethod += $" this.getDicts(\"{dbFieldInfo.DictType}\").then((response) => {{\n";
|
||||
replaceDto.MountedMethod += $" this.{FirstLowerCase(dbFieldInfo.CsharpField)}Options = response.data;\n";
|
||||
replaceDto.MountedMethod += " })\n";
|
||||
}
|
||||
|
||||
dbFieldInfo.DbColumnName = columnName;
|
||||
modelContent += CodeGenerateTemplate.GetModelTemplate(dbFieldInfo);
|
||||
vueViewFormContent += CodeGenerateTemplate.GetVueViewFormContent(dbFieldInfo);
|
||||
vueJsMethod += CodeGenerateTemplate.GetVueJsMethod(dbFieldInfo);
|
||||
vueViewListContent += CodeGenerateTemplate.GetTableColumn(dbFieldInfo);
|
||||
vueViewEditFromRuleContent += CodeGenerateTemplate.GetFormRules(dbFieldInfo);
|
||||
InputDtoContent += CodeGenerateTemplate.GetDtoContent(dbFieldInfo);
|
||||
replaceDto.QueryProperty += CodeGenerateTemplate.GetQueryDtoProperty(dbFieldInfo);
|
||||
replaceDto.ModelProperty += CodeGenerateTemplate.GetModelTemplate(dbFieldInfo);
|
||||
replaceDto.VueViewFormHtml += CodeGenerateTemplate.GetVueViewFormContent(dbFieldInfo);
|
||||
replaceDto.VueJsMethod += CodeGenerateTemplate.GetVueJsMethod(dbFieldInfo);
|
||||
replaceDto.VueViewListHtml += CodeGenerateTemplate.GetTableColumn(dbFieldInfo);
|
||||
replaceDto.VueViewEditFormRuleContent += CodeGenerateTemplate.GetFormRules(dbFieldInfo);
|
||||
replaceDto.InputDtoProperty += CodeGenerateTemplate.GetDtoProperty(dbFieldInfo);
|
||||
replaceDto.VueQueryFormHtml += CodeGenerateTemplate.GetQueryFormHtml(dbFieldInfo);
|
||||
}
|
||||
replaceDto.PKName = PKName;
|
||||
replaceDto.PKType = PKType;
|
||||
|
||||
if (dto.genFiles.Contains(1))
|
||||
{
|
||||
GenerateModels(_option.ModelsNamespace, modelTypeName, tableInfo.Name, modelContent, modelTypeDesc, keyTypeName, ifExsitedCovered);
|
||||
Tuple<string, string> tuple = GenerateModels(replaceDto, dto);
|
||||
genPathList.Add(tuple.Item1);
|
||||
WriteAndSave(tuple.Item1, tuple.Item2);
|
||||
}
|
||||
if (dto.genFiles.Contains(2))
|
||||
{
|
||||
GenerateInputDto(_option.ModelsNamespace, modelTypeName, modelTypeDesc, InputDtoContent, keyTypeName, ifExsitedCovered);
|
||||
Tuple<string, string> tuple = GenerateInputDto(replaceDto, dto);
|
||||
genPathList.Add(tuple.Item1);
|
||||
WriteAndSave(tuple.Item1, tuple.Item2);
|
||||
}
|
||||
if (dto.genFiles.Contains(3))
|
||||
{
|
||||
GenerateRepository(modelTypeName, modelTypeDesc, tableInfo.Name, keyTypeName, ifExsitedCovered);
|
||||
Tuple<string, string> tuple = GenerateRepository(replaceDto, dto);
|
||||
genPathList.Add(tuple.Item1);
|
||||
WriteAndSave(tuple.Item1, tuple.Item2);
|
||||
}
|
||||
if (dto.genFiles.Contains(4))
|
||||
{
|
||||
GenerateIService(_option.ModelsNamespace, modelTypeName, modelTypeDesc, keyTypeName, ifExsitedCovered);
|
||||
GenerateService(_option.ModelsNamespace, modelTypeName, modelTypeDesc, keyTypeName, ifExsitedCovered);
|
||||
Tuple<string, string> tuple = GenerateIService(replaceDto, dto);
|
||||
Tuple<string, string> tuple_1 = GenerateService(replaceDto, dto);
|
||||
genPathList.Add(tuple.Item1);
|
||||
genPathList.Add(tuple_1.Item1);
|
||||
WriteAndSave(tuple.Item1, tuple.Item2);
|
||||
WriteAndSave(tuple_1.Item1, tuple_1.Item2);
|
||||
}
|
||||
if (dto.genFiles.Contains(5))
|
||||
{
|
||||
GenerateControllers(modelTypeName, primaryKey, modelTypeDesc, keyTypeName, updateColumn, ifExsitedCovered);
|
||||
Tuple<string, string> tuple = GenerateControllers(replaceDto, dto);
|
||||
genPathList.Add(tuple.Item1);
|
||||
WriteAndSave(tuple.Item1, tuple.Item2);
|
||||
}
|
||||
if (dto.genFiles.Contains(6))
|
||||
{
|
||||
GenerateVueViews(modelTypeName, primaryKey, modelTypeDesc, vueViewListContent, vueViewFormContent, vueViewEditFromContent, vueViewEditFromBindContent, vueViewSaveBindContent, vueViewEditFromRuleContent, vueJsMethod, ifExsitedCovered);
|
||||
Tuple<string, string> tuple = GenerateVueViews(replaceDto, dto);
|
||||
Tuple<string, string> tuple_1 = GenerateVueJs(replaceDto, dto);
|
||||
genPathList.Add(tuple.Item1);
|
||||
genPathList.Add(tuple_1.Item1);
|
||||
WriteAndSave(tuple.Item1, tuple.Item2);
|
||||
WriteAndSave(tuple_1.Item1, tuple_1.Item2);
|
||||
}
|
||||
//GenerateIRepository(modelTypeName, modelTypeDesc, keyTypeName, ifExsitedCovered);
|
||||
//GenerateOutputDto(modelTypeName, modelTypeDesc, outputDtocontent, ifExsitedCovered);
|
||||
if (dto.genFiles.Contains(7))
|
||||
{
|
||||
Tuple<string, string> tuple = GenerateSql(replaceDto, dto);
|
||||
WriteAndSave(tuple.Item1, tuple.Item2);
|
||||
}
|
||||
return genPathList;
|
||||
}
|
||||
|
||||
|
||||
#region 生成Model
|
||||
|
||||
/// <summary>
|
||||
/// 生成Models文件
|
||||
/// </summary>
|
||||
/// <param name="modelsNamespace">命名空间</param>
|
||||
/// <param name="modelTypeName">类名</param>
|
||||
/// <param name="tableName">表名称</param>
|
||||
/// <param name="modelTypeDesc">表描述</param>
|
||||
/// <param name="modelContent">数据库表实体内容</param>
|
||||
/// <param name="keyTypeName">主键数据类型</param>
|
||||
/// <param name="ifExsitedCovered">如果目标文件存在,是否覆盖。默认为false</param>
|
||||
private static Tuple<string, string> GenerateModels(string modelsNamespace, string modelTypeName, string tableName, string modelContent, string modelTypeDesc, string keyTypeName, bool ifExsitedCovered = false)
|
||||
/// <param name="generateDto"></param>
|
||||
/// <param name="replaceDto">替换实体</param>
|
||||
private static Tuple<string, string> GenerateModels(ReplaceDto replaceDto, GenerateDto generateDto)
|
||||
{
|
||||
var parentPath = "..";
|
||||
//../ZR.Model
|
||||
var servicesPath = parentPath + "\\" + modelsNamespace + "\\Models\\";
|
||||
if (!Directory.Exists(servicesPath))
|
||||
{
|
||||
Directory.CreateDirectory(servicesPath);
|
||||
}
|
||||
var servicesPath = Path.Combine(generateDto.GenCodePath, _option.ModelsNamespace, "Models");
|
||||
Console.WriteLine("创建文件夹" + servicesPath);
|
||||
CreateDirectory(servicesPath);
|
||||
// ../ZR.Model/Models/User.cs
|
||||
var fullPath = servicesPath + modelTypeName + ".cs";
|
||||
Console.WriteLine(fullPath);
|
||||
if (File.Exists(fullPath) && !ifExsitedCovered)
|
||||
var fullPath = Path.Combine(servicesPath, replaceDto.ModelTypeName + ".cs");
|
||||
|
||||
if (File.Exists(fullPath) && !generateDto.coverd)
|
||||
return Tuple.Create(fullPath, "");
|
||||
var content = ReadTemplate("ModelTemplate.txt");
|
||||
content = content
|
||||
.Replace("{ModelsNamespace}", modelsNamespace)
|
||||
.Replace("{ModelTypeName}", modelTypeName)
|
||||
.Replace("{TableNameDesc}", modelTypeDesc)
|
||||
.Replace("{KeyTypeName}", keyTypeName)
|
||||
.Replace("{PropertyName}", modelContent)
|
||||
.Replace("{TableName}", tableName);
|
||||
WriteAndSave(fullPath, content);
|
||||
|
||||
var content = ReadTemplate("ModelTemplate.txt")
|
||||
.Replace("{ModelsNamespace}", _option.ModelsNamespace)
|
||||
.Replace("{ModelTypeName}", replaceDto.ModelTypeName)
|
||||
.Replace("{TableNameDesc}", replaceDto.TableDesc)
|
||||
.Replace("{KeyTypeName}", replaceDto.PKName)
|
||||
.Replace("{PropertyName}", replaceDto.ModelProperty)
|
||||
.Replace("{TableName}", replaceDto.TableName);
|
||||
|
||||
return Tuple.Create(fullPath, content);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 生成InputDto文件
|
||||
/// </summary>
|
||||
/// <param name="modelsNamespace"></param>
|
||||
/// <param name="modelTypeName"></param>
|
||||
/// <param name="modelTypeDesc"></param>
|
||||
/// <param name="modelContent"></param>
|
||||
/// <param name="keyTypeName"></param>
|
||||
/// <param name="ifExsitedCovered">如果目标文件存在,是否覆盖。默认为false</param>
|
||||
private static Tuple<string, string> GenerateInputDto(string modelsNamespace, string modelTypeName, string modelTypeDesc, string modelContent, string keyTypeName, bool ifExsitedCovered = false)
|
||||
/// <param name="generateDto"></param>
|
||||
/// <param name="replaceDto">替换实体</param>
|
||||
private static Tuple<string, string> GenerateInputDto(ReplaceDto replaceDto, GenerateDto generateDto)
|
||||
{
|
||||
var parentPath = "..";
|
||||
var servicesPath = parentPath + "\\" + modelsNamespace + "\\Dto\\";
|
||||
if (!Directory.Exists(servicesPath))
|
||||
{
|
||||
Directory.CreateDirectory(servicesPath);
|
||||
}
|
||||
var servicesPath = Path.Combine(generateDto.GenCodePath, _option.ModelsNamespace, "Dto");
|
||||
CreateDirectory(servicesPath);
|
||||
// ../ZR.Model/Dto/User.cs
|
||||
var fullPath = servicesPath + modelTypeName + "Dto.cs";
|
||||
Console.WriteLine(fullPath);
|
||||
if (File.Exists(fullPath) && !ifExsitedCovered)
|
||||
return Tuple.Create(fullPath, ""); ;
|
||||
var content = ReadTemplate("InputDtoTemplate.txt");
|
||||
content = content
|
||||
var fullPath = Path.Combine(servicesPath, $"{replaceDto.ModelTypeName}Dto.cs");
|
||||
|
||||
if (File.Exists(fullPath) && !generateDto.coverd)
|
||||
return Tuple.Create(fullPath, "");
|
||||
|
||||
var content = ReadTemplate("InputDtoTemplate.txt")
|
||||
.Replace("{DtosNamespace}", _option.DtosNamespace)
|
||||
.Replace("{ModelsNamespace}", modelsNamespace)
|
||||
.Replace("{TableNameDesc}", modelTypeDesc)
|
||||
.Replace("{KeyTypeName}", keyTypeName)
|
||||
.Replace("{PropertyName}", modelContent)
|
||||
.Replace("{ModelTypeName}", modelTypeName);
|
||||
WriteAndSave(fullPath, content);
|
||||
.Replace("{ModelsNamespace}", _option.ModelsNamespace)
|
||||
.Replace("{TableNameDesc}", replaceDto.TableDesc)
|
||||
.Replace("{PropertyName}", replaceDto.InputDtoProperty)
|
||||
.Replace("{QueryProperty}", replaceDto.QueryProperty)
|
||||
.Replace("{ModelTypeName}", replaceDto.ModelTypeName);
|
||||
|
||||
return Tuple.Create(fullPath, content);
|
||||
}
|
||||
#endregion
|
||||
@ -224,32 +227,25 @@ namespace ZR.CodeGenerator
|
||||
/// <summary>
|
||||
/// 生成Repository层代码文件
|
||||
/// </summary>
|
||||
/// <param name="modelTypeName"></param>
|
||||
/// <param name="modelTypeDesc"></param>
|
||||
/// <param name="tableName">表名</param>
|
||||
/// <param name="keyTypeName"></param>
|
||||
/// <param name="ifExsitedCovered">如果目标文件存在,是否覆盖。默认为false</param>
|
||||
private static Tuple<string, string> GenerateRepository(string modelTypeName, string modelTypeDesc, string tableName, string keyTypeName, bool ifExsitedCovered = false)
|
||||
/// <param name="generateDto"></param>
|
||||
/// <param name="replaceDto">替换实体</param>
|
||||
private static Tuple<string, string> GenerateRepository(ReplaceDto replaceDto, GenerateDto generateDto)
|
||||
{
|
||||
var parentPath = "..";
|
||||
var repositoryPath = parentPath + "\\" + _option.RepositoriesNamespace + "\\Repositories\\";
|
||||
if (!Directory.Exists(repositoryPath))
|
||||
{
|
||||
Directory.CreateDirectory(repositoryPath);
|
||||
}
|
||||
var fullPath = repositoryPath + "\\" + modelTypeName + "Repository.cs";
|
||||
Console.WriteLine(fullPath);
|
||||
if (File.Exists(fullPath) && !ifExsitedCovered)
|
||||
var repositoryPath = Path.Combine(generateDto.GenCodePath, _option.RepositoriesNamespace, "Repositories");
|
||||
CreateDirectory(repositoryPath);
|
||||
|
||||
var fullPath = Path.Combine(repositoryPath, $"{replaceDto.ModelTypeName}Repository.cs");
|
||||
|
||||
if (File.Exists(fullPath) && !generateDto.coverd)
|
||||
return Tuple.Create(fullPath, "");
|
||||
var content = ReadTemplate("RepositoryTemplate.txt");
|
||||
content = content.Replace("{ModelsNamespace}", _option.ModelsNamespace)
|
||||
//.Replace("{IRepositoriesNamespace}", _option.IRepositoriesNamespace)
|
||||
|
||||
var content = ReadTemplate("RepositoryTemplate.txt")
|
||||
.Replace("{ModelsNamespace}", _option.ModelsNamespace)
|
||||
.Replace("{RepositoriesNamespace}", _option.RepositoriesNamespace)
|
||||
.Replace("{ModelTypeName}", modelTypeName)
|
||||
.Replace("{TableNameDesc}", modelTypeDesc)
|
||||
.Replace("{TableName}", tableName)
|
||||
.Replace("{KeyTypeName}", keyTypeName);
|
||||
WriteAndSave(fullPath, content);
|
||||
.Replace("{ModelTypeName}", replaceDto.ModelTypeName)
|
||||
.Replace("{TableNameDesc}", replaceDto.TableDesc)
|
||||
.Replace("{TableName}", replaceDto.TableName);
|
||||
|
||||
return Tuple.Create(fullPath, content);
|
||||
}
|
||||
|
||||
@ -259,66 +255,49 @@ namespace ZR.CodeGenerator
|
||||
/// <summary>
|
||||
/// 生成IService文件
|
||||
/// </summary>
|
||||
/// <param name="modelsNamespace"></param>
|
||||
/// <param name="modelTypeName"></param>
|
||||
/// <param name="modelTypeDesc"></param>
|
||||
/// <param name="keyTypeName"></param>
|
||||
/// <param name="ifExsitedCovered">如果目标文件存在,是否覆盖。默认为false</param>
|
||||
private static Tuple<string, string> GenerateIService(string modelsNamespace, string modelTypeName, string modelTypeDesc, string keyTypeName, bool ifExsitedCovered = false)
|
||||
/// <param name="generateDto"></param>
|
||||
/// <param name="replaceDto">替换实体</param>
|
||||
private static Tuple<string, string> GenerateIService(ReplaceDto replaceDto, GenerateDto generateDto)
|
||||
{
|
||||
var parentPath = "..";
|
||||
var iServicesPath = parentPath + "\\" + _option.IServicsNamespace + "\\Business\\IBusService\\";
|
||||
if (!Directory.Exists(iServicesPath))
|
||||
{
|
||||
Directory.CreateDirectory(iServicesPath);
|
||||
}
|
||||
var fullPath = $"{iServicesPath}\\I{modelTypeName}Service.cs";
|
||||
var iServicesPath = Path.Combine(generateDto.GenCodePath, _option.IServicsNamespace, "Business", "IBusService");
|
||||
CreateDirectory(iServicesPath);
|
||||
|
||||
var fullPath = Path.Combine(iServicesPath, $"I{replaceDto.ModelTypeName}Service.cs");
|
||||
Console.WriteLine(fullPath);
|
||||
if (File.Exists(fullPath) && !ifExsitedCovered)
|
||||
if (File.Exists(fullPath) && !generateDto.coverd)
|
||||
return Tuple.Create(fullPath, "");
|
||||
var content = ReadTemplate("IServiceTemplate.txt");
|
||||
content = content.Replace("{ModelsNamespace}", modelsNamespace)
|
||||
.Replace("{TableNameDesc}", modelTypeDesc)
|
||||
var content = ReadTemplate("IServiceTemplate.txt")
|
||||
.Replace("{ModelsNamespace}", _option.ModelsNamespace)
|
||||
.Replace("{TableNameDesc}", replaceDto.TableDesc)
|
||||
.Replace("{DtosNamespace}", _option.DtosNamespace)
|
||||
.Replace("{IServicsNamespace}", _option.IServicsNamespace)
|
||||
.Replace("{RepositoriesNamespace}", _option.RepositoriesNamespace)
|
||||
.Replace("{ModelTypeName}", modelTypeName)
|
||||
.Replace("{KeyTypeName}", keyTypeName);
|
||||
WriteAndSave(fullPath, content);
|
||||
.Replace("{ModelTypeName}", replaceDto.ModelTypeName);
|
||||
|
||||
return Tuple.Create(fullPath, content);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 生成Service文件
|
||||
/// </summary>
|
||||
/// <param name="modelsNamespace"></param>
|
||||
/// <param name="modelTypeName"></param>
|
||||
/// <param name="modelTypeDesc"></param>
|
||||
/// <param name="keyTypeName"></param>
|
||||
/// <param name="ifExsitedCovered">如果目标文件存在,是否覆盖。默认为false</param>
|
||||
private static Tuple<string, string> GenerateService(string modelsNamespace, string modelTypeName, string modelTypeDesc, string keyTypeName, bool ifExsitedCovered = false)
|
||||
private static Tuple<string, string> GenerateService(ReplaceDto replaceDto, GenerateDto generateDto)
|
||||
{
|
||||
var parentPath = "..";
|
||||
var servicesPath = parentPath + "\\" + _option.ServicesNamespace + "\\Business\\";
|
||||
if (!Directory.Exists(servicesPath))
|
||||
{
|
||||
Directory.CreateDirectory(servicesPath);
|
||||
}
|
||||
var fullPath = servicesPath + modelTypeName + "Service.cs";
|
||||
var servicesPath = Path.Combine(generateDto.GenCodePath, _option.ServicesNamespace, "Business");
|
||||
CreateDirectory(servicesPath);
|
||||
var fullPath = Path.Combine(servicesPath, $"{replaceDto.ModelTypeName}Service.cs");
|
||||
Console.WriteLine(fullPath);
|
||||
if (File.Exists(fullPath) && !ifExsitedCovered)
|
||||
if (File.Exists(fullPath) && !generateDto.coverd)
|
||||
return Tuple.Create(fullPath, "");
|
||||
var content = ReadTemplate("ServiceTemplate.txt");
|
||||
content = content
|
||||
|
||||
var content = ReadTemplate("ServiceTemplate.txt")
|
||||
.Replace("{IRepositoriesNamespace}", _option.IRepositoriesNamespace)
|
||||
.Replace("{DtosNamespace}", _option.DtosNamespace)
|
||||
.Replace("{IServicsNamespace}", _option.IServicsNamespace)
|
||||
.Replace("{TableNameDesc}", modelTypeDesc)
|
||||
.Replace("{ModelsNamespace}", modelsNamespace)
|
||||
.Replace("{TableNameDesc}", replaceDto.TableDesc)
|
||||
.Replace("{ModelsNamespace}", _option.ModelsNamespace)
|
||||
.Replace("{ServicesNamespace}", _option.ServicesNamespace)
|
||||
.Replace("{ModelTypeName}", modelTypeName)
|
||||
.Replace("{KeyTypeName}", keyTypeName);
|
||||
WriteAndSave(fullPath, content);
|
||||
.Replace("{ModelTypeName}", replaceDto.ModelTypeName);
|
||||
|
||||
return Tuple.Create(fullPath, content);
|
||||
}
|
||||
|
||||
@ -328,36 +307,28 @@ namespace ZR.CodeGenerator
|
||||
/// <summary>
|
||||
/// 生成控制器ApiControllers文件
|
||||
/// </summary>
|
||||
/// <param name="modelTypeName">实体类型名称</param>
|
||||
/// <param name="primaryKey">主键</param>
|
||||
/// <param name="modelTypeDesc">实体描述</param>
|
||||
/// <param name="keyTypeName"></param>
|
||||
/// <param name="ifExsitedCovered">如果目标文件存在,是否覆盖。默认为false</param>
|
||||
private static Tuple<string, string> GenerateControllers(string modelTypeName, string primaryKey, string modelTypeDesc, string keyTypeName, string updateColumn, bool ifExsitedCovered = false)
|
||||
private static Tuple<string, string> GenerateControllers(ReplaceDto replaceDto, GenerateDto generateDto)
|
||||
{
|
||||
var parentPath = "..";
|
||||
var servicesPath = parentPath + "\\" + _option.ApiControllerNamespace + "\\Controllers\\business\\";
|
||||
if (!Directory.Exists(servicesPath))
|
||||
{
|
||||
Directory.CreateDirectory(servicesPath);
|
||||
}
|
||||
var fullPath = servicesPath + modelTypeName + "Controller.cs";
|
||||
Console.WriteLine(fullPath);
|
||||
if (File.Exists(fullPath) && !ifExsitedCovered)
|
||||
var servicesPath = Path.Combine(generateDto.GenCodePath, _option.ApiControllerNamespace, "Controllers", generateDto.GenTable.ModuleName);
|
||||
CreateDirectory(servicesPath);
|
||||
|
||||
var fullPath = Path.Combine(servicesPath, $"{replaceDto.ModelTypeName}Controller.cs");
|
||||
if (File.Exists(fullPath) && !generateDto.coverd)
|
||||
return Tuple.Create(fullPath, "");
|
||||
var content = ReadTemplate("ControllersTemplate.txt");
|
||||
content = content
|
||||
//.Replace("{DtosNamespace}", _option.DtosNamespace)
|
||||
.Replace("{ControllerName}", modelTypeName)
|
||||
|
||||
var content = ReadTemplate("ControllersTemplate.txt")
|
||||
.Replace("{ApiControllerNamespace}", _option.ApiControllerNamespace)
|
||||
.Replace("{ServicesNamespace}", _option.ServicesNamespace)
|
||||
.Replace("{ModelsNamespace}", _option.ModelsNamespace)
|
||||
.Replace("{FileName}", modelTypeDesc)
|
||||
.Replace("{ServiceName}", modelTypeName + "Service")
|
||||
.Replace("{ModelName}", modelTypeName)
|
||||
.Replace("{Permission}", modelTypeName.ToLower())
|
||||
.Replace("{primaryKey}", primaryKey)
|
||||
.Replace("{updateColumn}", updateColumn)
|
||||
.Replace("{KeyTypeName}", keyTypeName);
|
||||
WriteAndSave(fullPath, content);
|
||||
.Replace("{TableDesc}", replaceDto.TableDesc)
|
||||
.Replace("{ModelName}", replaceDto.ModelTypeName)
|
||||
.Replace("{Permission}", replaceDto.Permission)
|
||||
.Replace("{PrimaryKey}", replaceDto.PKName)
|
||||
.Replace("{UpdateColumn}", replaceDto.UpdateColumn)
|
||||
.Replace("{InsertColumn}", replaceDto.InsertColumn)
|
||||
.Replace("{ModuleName}", generateDto.GenTable.ModuleName)
|
||||
.Replace("{PKCsharpType}", replaceDto.PKType);
|
||||
|
||||
return Tuple.Create(fullPath, content);
|
||||
}
|
||||
#endregion
|
||||
@ -365,57 +336,71 @@ namespace ZR.CodeGenerator
|
||||
#region 生成Vue页面
|
||||
/// <summary>
|
||||
/// 生成Vue页面
|
||||
/// </summary>
|
||||
/// <param name="modelTypeName">类名</param>
|
||||
/// <param name="modelTypeDesc">表/类描述</param>
|
||||
/// <param name="vueViewListContent"></param>
|
||||
/// <param name="vueViewFromContent"></param>
|
||||
/// <param name="vueViewEditFromContent"></param>
|
||||
/// <param name="vueViewEditFromBindContent"></param>
|
||||
/// <param name="vueViewSaveBindContent"></param>
|
||||
/// <param name="vueViewEditFromRuleContent"></param>
|
||||
/// <param name="ifExsitedCovered">如果目标文件存在,是否覆盖。默认为false</param>
|
||||
private static Tuple<string, string> GenerateVueViews(string modelTypeName, string primaryKey, string modelTypeDesc, string vueViewListContent, string vueViewFromContent, string vueViewEditFromContent, string vueViewEditFromBindContent, string vueViewSaveBindContent, string vueViewEditFromRuleContent, string vueJsMethod, bool ifExsitedCovered = false)
|
||||
private static Tuple<string, string> GenerateVueViews(ReplaceDto replaceDto, GenerateDto generateDto)
|
||||
{
|
||||
//var parentPath = "..\\CodeGenerate";//若要生成到项目中将路径改成 “..\\ZR.Vue\\src”
|
||||
var parentPath = "..\\ZR.Vue\\src";
|
||||
var servicesPath = parentPath + "\\views\\" + FirstLowerCase(modelTypeName);
|
||||
if (!Directory.Exists(servicesPath))
|
||||
{
|
||||
Directory.CreateDirectory(servicesPath);
|
||||
}
|
||||
var fullPath = servicesPath + "\\" + "index.vue";
|
||||
Console.WriteLine(fullPath);
|
||||
if (File.Exists(fullPath) && !ifExsitedCovered)
|
||||
return Tuple.Create(fullPath, ""); ;
|
||||
var content = ReadTemplate("VueTemplate.txt");
|
||||
content = content
|
||||
.Replace("{fileClassName}", FirstLowerCase(modelTypeName))
|
||||
.Replace("{VueViewListContent}", vueViewListContent)//查询 table列
|
||||
.Replace("{VueViewFormContent}", vueViewFromContent)//添加、修改表单
|
||||
.Replace("{ModelTypeName}", modelTypeName)
|
||||
.Replace("{Permission}", modelTypeName.ToLower())
|
||||
.Replace("{VueViewEditFormContent}", vueViewEditFromContent)
|
||||
.Replace("{vueJsMethod}", vueJsMethod)
|
||||
//.Replace("{VueViewEditFromBindContent}", vueViewEditFromBindContent)
|
||||
//.Replace("{VueViewSaveBindContent}", vueViewSaveBindContent)
|
||||
.Replace("{primaryKey}", FirstLowerCase(primaryKey))
|
||||
.Replace("{VueViewEditFormRuleContent}", vueViewEditFromRuleContent);//添加、修改表单验证规则
|
||||
WriteAndSave(fullPath, content);
|
||||
var parentPath = Path.Combine(generateDto.GenCodePath, "ZR.Vue", "src");
|
||||
var servicesPath = Path.Combine(parentPath, "views", generateDto.GenTable.ModuleName, replaceDto.ViewsFileName);
|
||||
CreateDirectory(servicesPath);
|
||||
|
||||
//api js
|
||||
servicesPath = parentPath + "\\api\\";
|
||||
Directory.CreateDirectory(servicesPath);
|
||||
fullPath = servicesPath + "\\" + FirstLowerCase(modelTypeName) + ".js";
|
||||
Console.WriteLine(fullPath);
|
||||
if (File.Exists(fullPath) && !ifExsitedCovered)
|
||||
var fullPath = Path.Combine(servicesPath, "index.vue");
|
||||
|
||||
if (File.Exists(fullPath) && !generateDto.coverd)
|
||||
return Tuple.Create(fullPath, "");
|
||||
content = ReadTemplate("VueJsTemplate.txt");
|
||||
content = content
|
||||
.Replace("{ModelTypeName}", modelTypeName)
|
||||
.Replace("{ModelTypeDesc}", modelTypeDesc);
|
||||
//.Replace("{fileClassName}", fileClassName)
|
||||
WriteAndSave(fullPath, content);
|
||||
|
||||
var content = ReadTemplate("VueTemplate.txt")
|
||||
.Replace("{fileClassName}", replaceDto.ViewsFileName)
|
||||
.Replace("{VueViewListContent}", replaceDto.VueViewListHtml)//查询 table列
|
||||
.Replace("{VueViewFormContent}", replaceDto.VueViewFormHtml)//添加、修改表单
|
||||
.Replace("{ModelTypeName}", replaceDto.ModelTypeName)
|
||||
.Replace("{Permission}", replaceDto.Permission)
|
||||
.Replace("{VueViewFormResetHtml}", replaceDto.VueViewFormResetHtml)
|
||||
.Replace("{vueJsMethod}", replaceDto.VueJsMethod)
|
||||
.Replace("{vueQueryFormHtml}", replaceDto.VueQueryFormHtml)
|
||||
.Replace("{VueDataContent}", replaceDto.VueDataContent)
|
||||
.Replace("{primaryKey}", FirstLowerCase(replaceDto.PKName))
|
||||
.Replace("{MountedMethod}", replaceDto.MountedMethod)
|
||||
.Replace("{VueViewEditFormRuleContent}", replaceDto.VueViewEditFormRuleContent);//添加、修改表单验证规则
|
||||
|
||||
return Tuple.Create(fullPath, content);
|
||||
}
|
||||
public static Tuple<string, string> GenerateVueJs(ReplaceDto replaceDto, GenerateDto generateDto)
|
||||
{
|
||||
//api js
|
||||
var parentPath = Path.Combine(generateDto.GenCodePath, "ZR.Vue", "src");
|
||||
string servicesPath = Path.Combine(parentPath, "api");
|
||||
CreateDirectory(servicesPath);
|
||||
|
||||
string fullPath = Path.Combine(servicesPath, replaceDto.ViewsFileName + ".js");
|
||||
|
||||
if (File.Exists(fullPath) && !generateDto.coverd)
|
||||
return Tuple.Create(fullPath, "");
|
||||
|
||||
var content = ReadTemplate("VueJsTemplate.txt")
|
||||
.Replace("{ModelTypeName}", replaceDto.ModelTypeName)
|
||||
.Replace("{ModelTypeDesc}", replaceDto.TableDesc)
|
||||
.Replace("{ModuleName}", generateDto.GenTable.ModuleName);
|
||||
|
||||
return Tuple.Create(fullPath, content);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 生成SQL
|
||||
|
||||
public static Tuple<string, string> GenerateSql(ReplaceDto replaceDto, GenerateDto generateDto)
|
||||
{
|
||||
string fullPath = Path.Combine(generateDto.GenCodePath, replaceDto.ViewsFileName + ".sql");
|
||||
|
||||
if (File.Exists(fullPath) && !generateDto.coverd)
|
||||
return Tuple.Create(fullPath, "");
|
||||
var content = ReadTemplate("SqlTemplate.txt")
|
||||
.Replace("{ModelTypeName}", replaceDto.ModelTypeName)
|
||||
.Replace("{Permission}", replaceDto.Permission)
|
||||
.Replace("{ModelTypeDesc}", replaceDto.TableDesc)
|
||||
.Replace("{ModuleName}", generateDto.GenTable.ModuleName)
|
||||
.Replace("{ViewsFileName}", replaceDto.ViewsFileName)
|
||||
.Replace("{FunctionName}", generateDto.GenTable.FunctionName);
|
||||
|
||||
return Tuple.Create(fullPath, content);
|
||||
}
|
||||
|
||||
@ -425,19 +410,29 @@ namespace ZR.CodeGenerator
|
||||
|
||||
/// <summary>
|
||||
/// 如果有前缀替换将前缀替换成空,替换下划线"_"为空再将首字母大写
|
||||
/// 表名转换成C#类名
|
||||
/// </summary>
|
||||
/// <param name="modelTypeName"></param>
|
||||
/// <param name="tableName"></param>
|
||||
/// <returns></returns>
|
||||
public static string GetModelClassName(string modelTypeName)
|
||||
public static string GetClassName(string tableName)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(_option.ReplaceTableNameStr))
|
||||
bool autoRemovePre = ConfigUtils.Instance.GetAppConfig(GenConstants.Gen_autoPre, false);
|
||||
string tablePrefix = ConfigUtils.Instance.GetAppConfig<string>(GenConstants.Gen_tablePrefix);
|
||||
|
||||
if (!string.IsNullOrEmpty(tablePrefix) && autoRemovePre)
|
||||
{
|
||||
modelTypeName = modelTypeName.Replace(_option.ReplaceTableNameStr.ToString(), "");
|
||||
string[] searcList = tablePrefix.Split(",", StringSplitOptions.RemoveEmptyEntries);
|
||||
for (int i = 0; i < searcList.Length; i++)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(searcList[i].ToString()))
|
||||
{
|
||||
tableName = tableName.Replace(searcList[i], "");
|
||||
}
|
||||
modelTypeName = modelTypeName.Replace("_", "");
|
||||
modelTypeName = modelTypeName.Substring(0, 1).ToUpper() + modelTypeName[1..];
|
||||
return modelTypeName;
|
||||
}
|
||||
}
|
||||
return tableName.Substring(0, 1).ToUpper() + tableName[1..].Replace("_", "");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 首字母转小写,输出前端
|
||||
/// </summary>
|
||||
@ -465,8 +460,10 @@ namespace ZR.CodeGenerator
|
||||
/// <returns></returns>
|
||||
private static string ReadTemplate(string templateName)
|
||||
{
|
||||
var path = AppDomain.CurrentDomain.BaseDirectory;
|
||||
string fullName = $"{path}\\Template\\{templateName}";
|
||||
string path = Environment.CurrentDirectory;
|
||||
string fullName = $"{path}/wwwroot/CodeGenTemplate/{templateName}";
|
||||
|
||||
Console.WriteLine("开始读取模板=" + fullName);
|
||||
string temp = fullName;
|
||||
string str = "";
|
||||
if (!File.Exists(temp))
|
||||
@ -479,11 +476,13 @@ namespace ZR.CodeGenerator
|
||||
sr = new StreamReader(temp);
|
||||
str = sr.ReadToEnd(); // 读取文件
|
||||
}
|
||||
catch { }
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"读取模板出错了{ex.Message}");
|
||||
}
|
||||
sr?.Close();
|
||||
sr?.Dispose();
|
||||
return str;
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -493,6 +492,8 @@ namespace ZR.CodeGenerator
|
||||
/// <param name="content"></param>
|
||||
private static void WriteAndSave(string fileName, string content)
|
||||
{
|
||||
fileName = fileName.Replace("\\", "/").Replace("//", "/");
|
||||
Console.WriteLine("写入文件:" + fileName);
|
||||
try
|
||||
{
|
||||
//实例化一个文件流--->与写入文件相关联
|
||||
@ -513,6 +514,132 @@ namespace ZR.CodeGenerator
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建文件夹
|
||||
/// </summary>
|
||||
/// <param name="path"></param>
|
||||
/// <returns></returns>
|
||||
public static bool CreateDirectory(string path)
|
||||
{
|
||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
|
||||
{
|
||||
path = path.Replace("\\", "/").Replace("//", "/");
|
||||
}
|
||||
try
|
||||
{
|
||||
if (!Directory.Exists(path))
|
||||
{
|
||||
DirectoryInfo info = Directory.CreateDirectory(path);
|
||||
Console.WriteLine("不存在创建文件夹" + info);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"创建文件夹出错了,{ex.Message}");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// 初始化列属性字段数据
|
||||
/// </summary>
|
||||
/// <param name="genTable"></param>
|
||||
/// <param name="dbColumnInfos"></param>
|
||||
public static List<GenTableColumn> InitGenTableColumn(GenTable genTable, List<DbColumnInfo> dbColumnInfos)
|
||||
{
|
||||
List<GenTableColumn> genTableColumns = new();
|
||||
foreach (var column in dbColumnInfos)
|
||||
{
|
||||
GenTableColumn genTableColumn = new()
|
||||
{
|
||||
ColumnName = FirstLowerCase(column.DbColumnName),
|
||||
ColumnComment = column.ColumnDescription,
|
||||
IsPk = column.IsPrimarykey,
|
||||
ColumnType = column.DataType,
|
||||
TableId = genTable.TableId,
|
||||
TableName = genTable.TableName,
|
||||
CsharpType = TableMappingHelper.GetCSharpDatatype(column.DataType),
|
||||
CsharpField = column.DbColumnName.Substring(0, 1).ToUpper() + column.DbColumnName[1..],
|
||||
IsRequired = !column.IsNullable,
|
||||
IsIncrement = column.IsIdentity,
|
||||
Create_by = genTable.Create_by,
|
||||
Create_time = DateTime.Now,
|
||||
IsInsert = !column.IsIdentity,//非自增字段都需要插入
|
||||
IsQuery = false,
|
||||
HtmlType = GenConstants.HTML_INPUT
|
||||
};
|
||||
|
||||
if (GenConstants.imageFiled.Any(f => column.DbColumnName.ToLower().Contains(f.ToLower())))
|
||||
{
|
||||
genTableColumn.HtmlType = GenConstants.HTML_IMAGE_UPLOAD;
|
||||
}
|
||||
else if (GenConstants.COLUMNTYPE_TIME.Any(f => genTableColumn.CsharpType.ToLower().Contains(f.ToLower())))
|
||||
{
|
||||
genTableColumn.HtmlType = GenConstants.HTML_DATETIME;
|
||||
}
|
||||
else if (GenConstants.radioFiled.Any(f => column.DbColumnName.EndsWith(f, StringComparison.OrdinalIgnoreCase)) ||
|
||||
GenConstants.radioFiled.Any(f => column.DbColumnName.StartsWith(f, StringComparison.OrdinalIgnoreCase)))
|
||||
{
|
||||
genTableColumn.HtmlType = GenConstants.HTML_RADIO;
|
||||
}
|
||||
else if (GenConstants.selectFiled.Any(f => column.DbColumnName == f) ||
|
||||
GenConstants.selectFiled.Any(f => column.DbColumnName.EndsWith(f, StringComparison.OrdinalIgnoreCase)))
|
||||
{
|
||||
genTableColumn.HtmlType = GenConstants.HTML_SELECT;
|
||||
}
|
||||
else if (column.Length > 500)
|
||||
{
|
||||
genTableColumn.HtmlType = GenConstants.HTML_TEXTAREA;
|
||||
}
|
||||
//编辑字段
|
||||
if (GenConstants.COLUMNNAME_NOT_EDIT.Any(f => column.DbColumnName.Contains(f)) && !column.IsIdentity && !column.IsPrimarykey)
|
||||
{
|
||||
genTableColumn.IsEdit = true;
|
||||
}
|
||||
//列表字段
|
||||
if (!GenConstants.COLUMNNAME_NOT_LIST.Any(f => column.DbColumnName.Contains(f) && !column.IsPrimarykey))
|
||||
{
|
||||
genTableColumn.IsList = true;
|
||||
}
|
||||
|
||||
genTableColumns.Add(genTableColumn);
|
||||
}
|
||||
return genTableColumns;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 压缩代码
|
||||
/// </summary>
|
||||
/// <param name="dto"></param>
|
||||
/// <returns></returns>
|
||||
public static string ZipGenCode(GenerateDto dto)
|
||||
{
|
||||
try
|
||||
{
|
||||
//生成压缩包
|
||||
string zipReturnFileName = dto.GenTable.BaseNameSpace + DateTime.Now.ToString("yyyyMMddHHmmss") + ".zip";
|
||||
|
||||
CreateDirectory(dto.GenCodePath);
|
||||
string zipFileName = Path.Combine(dto.ZipPath, zipReturnFileName);
|
||||
if (File.Exists(zipFileName))
|
||||
{
|
||||
File.Delete(zipFileName);
|
||||
}
|
||||
|
||||
ZipFile.CreateFromDirectory(dto.GenCodePath, zipFileName);
|
||||
FileHelper.DeleteDirectory(dto.GenCodePath);
|
||||
dto.ZipFileName = zipReturnFileName;
|
||||
return zipReturnFileName;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine("压缩文件出错。" + ex.Message);
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -8,6 +8,9 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace ZR.CodeGenerator
|
||||
{
|
||||
/// <summary>
|
||||
/// 代码生成数据库连接
|
||||
/// </summary>
|
||||
public class DbProvider
|
||||
{
|
||||
protected static SqlSugarScope CodeDb;
|
||||
@ -19,12 +22,13 @@ namespace ZR.CodeGenerator
|
||||
/// <returns></returns>
|
||||
public SqlSugarScope GetSugarDbContext(string dbName = "")
|
||||
{
|
||||
string connStr = ConfigUtils.Instance.GetConnectionStrings(OptionsSetting.Conn).Replace("{database}", dbName);
|
||||
int dbType = ConfigUtils.Instance.GetAppConfig(OptionsSetting.CodeGenDbType, 0);
|
||||
string connStr = ConfigUtils.Instance.GetConfig(GenConstants.Gen_conn);
|
||||
int dbType = ConfigUtils.Instance.GetAppConfig(GenConstants.Gen_conn_dbType, 0);
|
||||
connStr = connStr.Replace("{database}", dbName);
|
||||
if (string.IsNullOrEmpty(dbName))
|
||||
{
|
||||
connStr = ConfigUtils.Instance.GetConnectionStrings(OptionsSetting.ConnAdmin);
|
||||
dbType = ConfigUtils.Instance.GetAppConfig(OptionsSetting.DbType, 0);
|
||||
dbType = ConfigUtils.Instance.GetAppConfig<int>(OptionsSetting.ConnDbType);
|
||||
}
|
||||
var db = new SqlSugarScope(new List<ConnectionConfig>()
|
||||
{
|
||||
|
||||
183
ZR.CodeGenerator/FileHelper.cs
Normal file
183
ZR.CodeGenerator/FileHelper.cs
Normal file
@ -0,0 +1,183 @@
|
||||
using ICSharpCode.SharpZipLib.Checksum;
|
||||
using ICSharpCode.SharpZipLib.Zip;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ZR.CodeGenerator
|
||||
{
|
||||
public class FileHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// 制作压缩包(多个文件压缩到一个压缩包,支持加密、注释)
|
||||
/// </summary>
|
||||
/// <param name="fileNames">要压缩的文件</param>
|
||||
/// <param name="topDirectoryName">压缩文件目录</param>
|
||||
/// <param name="zipedFileName">压缩包文件名</param>
|
||||
/// <param name="compresssionLevel">压缩级别 1-9</param>
|
||||
/// <param name="password">密码</param>
|
||||
/// <param name="comment">注释</param>
|
||||
public static void ZipFiles(string[] fileNames, string topDirectoryName, string zipedFileName, int? compresssionLevel, string password = "", string comment = "")
|
||||
{
|
||||
using (ZipOutputStream zos = new ZipOutputStream(File.Open(zipedFileName, FileMode.OpenOrCreate)))
|
||||
{
|
||||
if (compresssionLevel.HasValue)
|
||||
{
|
||||
zos.SetLevel(compresssionLevel.Value);//设置压缩级别
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(password))
|
||||
{
|
||||
zos.Password = password;//设置zip包加密密码
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(comment))
|
||||
{
|
||||
zos.SetComment(comment);//设置zip包的注释
|
||||
}
|
||||
|
||||
foreach (string file in fileNames)
|
||||
{
|
||||
//string fileName = string.Format("{0}/{1}", topDirectoryName, file);
|
||||
string fileName = file;
|
||||
|
||||
if (File.Exists(fileName))
|
||||
{
|
||||
FileInfo item = new FileInfo(fileName);
|
||||
FileStream fs = File.OpenRead(item.FullName);
|
||||
byte[] buffer = new byte[fs.Length];
|
||||
fs.Read(buffer, 0, buffer.Length);
|
||||
|
||||
ZipEntry entry = new ZipEntry(item.Name);
|
||||
zos.PutNextEntry(entry);
|
||||
zos.Write(buffer, 0, buffer.Length);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 压缩多层目录
|
||||
/// </summary>
|
||||
/// <param name="topDirectoryName">压缩文件目录</param>
|
||||
/// <param name="zipedFileName">压缩包文件名</param>
|
||||
/// <param name="compresssionLevel">压缩级别 1-9 </param>
|
||||
/// <param name="password">密码</param>
|
||||
/// <param name="comment">注释</param>
|
||||
/// <param name="filetype">文件类型</param>
|
||||
public static void ZipFileDirectory(string topDirectoryName, string zipedFileName, int compresssionLevel, string password, string comment, string filetype)
|
||||
{
|
||||
using (System.IO.FileStream ZipFile = File.Open(zipedFileName, FileMode.OpenOrCreate))
|
||||
{
|
||||
using (ZipOutputStream zos = new ZipOutputStream(ZipFile))
|
||||
{
|
||||
if (compresssionLevel != 0)
|
||||
{
|
||||
zos.SetLevel(compresssionLevel);//设置压缩级别
|
||||
}
|
||||
if (!string.IsNullOrEmpty(password))
|
||||
{
|
||||
zos.Password = password;//设置zip包加密密码
|
||||
}
|
||||
if (!string.IsNullOrEmpty(comment))
|
||||
{
|
||||
zos.SetComment(comment);//设置zip包的注释
|
||||
}
|
||||
ZipSetp(topDirectoryName, zos, "", filetype);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 递归遍历目录
|
||||
/// </summary>
|
||||
/// <param name="strDirectory">The directory.</param>
|
||||
/// <param name="s">The ZipOutputStream Object.</param>
|
||||
/// <param name="parentPath">The parent path.</param>
|
||||
private static void ZipSetp(string strDirectory, ZipOutputStream s, string parentPath, string filetype)
|
||||
{
|
||||
if (strDirectory[^1] != Path.DirectorySeparatorChar)
|
||||
{
|
||||
strDirectory += Path.DirectorySeparatorChar;
|
||||
}
|
||||
Console.WriteLine("strDirectory=" + strDirectory);
|
||||
Crc32 crc = new Crc32();
|
||||
|
||||
string[] filenames = Directory.GetFileSystemEntries(strDirectory, filetype);
|
||||
foreach (string file in filenames)// 遍历所有的文件和目录
|
||||
{
|
||||
if (Directory.Exists(file))// 先当作目录处理如果存在这个目录就递归Copy该目录下面的文件
|
||||
{
|
||||
string pPath = parentPath;
|
||||
pPath += file[(file.LastIndexOf("/") + 1)..];
|
||||
pPath += "/";
|
||||
Console.WriteLine("递归路径" + pPath);
|
||||
ZipSetp(file, s, pPath, filetype);
|
||||
}
|
||||
else // 否则直接压缩文件
|
||||
{
|
||||
//打开压缩文件
|
||||
using (FileStream fs = File.OpenRead(file))
|
||||
{
|
||||
byte[] buffer = new byte[fs.Length];
|
||||
fs.Read(buffer, 0, buffer.Length);
|
||||
string fileName = parentPath + file[(file.LastIndexOf("/") + 1)..];
|
||||
ZipEntry entry = new ZipEntry(fileName);
|
||||
entry.DateTime = DateTime.Now;
|
||||
entry.Size = fs.Length;
|
||||
fs.Close();
|
||||
crc.Reset();
|
||||
crc.Update(buffer);
|
||||
entry.Crc = crc.Value;
|
||||
s.PutNextEntry(entry);
|
||||
s.Write(buffer, 0, buffer.Length);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除指定目录下的所有文件及文件夹(保留目录)
|
||||
/// </summary>
|
||||
/// <param name="file">文件目录</param>
|
||||
public static void DeleteDirectory(string file)
|
||||
{
|
||||
try
|
||||
{
|
||||
//判断文件夹是否还存在
|
||||
if (Directory.Exists(file))
|
||||
{
|
||||
DirectoryInfo fileInfo = new DirectoryInfo(file);
|
||||
//去除文件夹的只读属性
|
||||
fileInfo.Attributes = FileAttributes.Normal & FileAttributes.Directory;
|
||||
foreach (string f in Directory.GetFileSystemEntries(file))
|
||||
{
|
||||
if (File.Exists(f))
|
||||
{
|
||||
//去除文件的只读属性
|
||||
File.SetAttributes(file, FileAttributes.Normal);
|
||||
//如果有子文件删除文件
|
||||
File.Delete(f);
|
||||
}
|
||||
else
|
||||
{
|
||||
//循环递归删除子文件夹
|
||||
DeleteDirectory(f);
|
||||
}
|
||||
}
|
||||
//删除空文件夹
|
||||
Directory.Delete(file);
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception ex) // 异常处理
|
||||
{
|
||||
//Log4NetHelper.Error("代码生成异常", ex);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
136
ZR.CodeGenerator/GenConstants.cs
Normal file
136
ZR.CodeGenerator/GenConstants.cs
Normal file
@ -0,0 +1,136 @@
|
||||
|
||||
|
||||
namespace ZR.CodeGenerator
|
||||
{
|
||||
/// <summary>
|
||||
/// 代码生成常量
|
||||
/// </summary>
|
||||
public class GenConstants
|
||||
{
|
||||
public static string Gen_conn = "gen:conn";
|
||||
public static string Gen_conn_dbType = "gen:dbType";
|
||||
public static string Gen_author = "gen:author";
|
||||
public static string Gen_autoPre = "gen:autoPre";
|
||||
public static string Gen_tablePrefix = "gen:tablePrefix";
|
||||
|
||||
/// <summary>
|
||||
/// InputDto输入实体是不包含字段
|
||||
/// </summary>
|
||||
public static readonly string[] inputDtoNoField = new string[] { "createTime", "updateTime", "addtime" };
|
||||
/// <summary>
|
||||
/// 图片字段
|
||||
/// </summary>
|
||||
public static readonly string[] imageFiled = new string[] { "icon", "img", "image", "url", "pic", "photo", "avatar" };
|
||||
/// <summary>
|
||||
/// 下拉框字段
|
||||
/// </summary>
|
||||
public static readonly string[] selectFiled = new string[] { "status", "type", "state", "sex", "gender" };
|
||||
/// <summary>
|
||||
/// 单选按钮字段
|
||||
/// </summary>
|
||||
public static readonly string[] radioFiled = new string[] { "status", "state", "is"};
|
||||
|
||||
|
||||
/** 单表(增删改查) */
|
||||
public static string TPL_CRUD = "crud";
|
||||
|
||||
/** 树表(增删改查) */
|
||||
public static string TPL_TREE = "tree";
|
||||
|
||||
/** 主子表(增删改查) */
|
||||
public static string TPL_SUB = "sub";
|
||||
|
||||
/** 树编码字段 */
|
||||
public static string TREE_CODE = "treeCode";
|
||||
|
||||
/** 树父编码字段 */
|
||||
public static string TREE_PARENT_CODE = "treeParentCode";
|
||||
|
||||
/** 树名称字段 */
|
||||
public static string TREE_NAME = "treeName";
|
||||
|
||||
/** 上级菜单ID字段 */
|
||||
public static string PARENT_MENU_ID = "parentMenuId";
|
||||
|
||||
/** 上级菜单名称字段 */
|
||||
public static string PARENT_MENU_NAME = "parentMenuName";
|
||||
|
||||
/** 数据库字符串类型 */
|
||||
public static string[] COLUMNTYPE_STR = { "char", "varchar", "nvarchar", "varchar2" };
|
||||
|
||||
/** 数据库文本类型 */
|
||||
public static string[] COLUMNTYPE_TEXT = { "tinytext", "text", "mediumtext", "longtext" };
|
||||
|
||||
/** 数据库时间类型 */
|
||||
public static string[] COLUMNTYPE_TIME = { "datetime", "time", "date", "timestamp" };
|
||||
|
||||
/** 数据库数字类型 */
|
||||
public static string[] COLUMNTYPE_NUMBER = { "tinyint", "smallint", "mediumint", "int", "number", "integer",
|
||||
"bit", "bigint", "float", "double", "decimal" };
|
||||
|
||||
/** 页面不需要编辑字段 */
|
||||
public static string[] COLUMNNAME_NOT_EDIT = { "id", "create_by", "create_time", "delFlag" };
|
||||
|
||||
/** 页面不需要显示的列表字段 */
|
||||
public static string[] COLUMNNAME_NOT_LIST = { "create_by", "create_time", "delFlag", "update_by",
|
||||
"update_time" , "password"};
|
||||
|
||||
/** 页面不需要查询字段 */
|
||||
public static string[] COLUMNNAME_NOT_QUERY = { "id", "create_by", "create_time", "delFlag", "update_by",
|
||||
"update_time", "remark" };
|
||||
|
||||
/** Entity基类字段 */
|
||||
public static string[] BASE_ENTITY = { "createBy", "createTime", "updateBy", "updateTime", "remark" };
|
||||
|
||||
/** Tree基类字段 */
|
||||
public static string[] TREE_ENTITY = { "parentName", "parentId", "orderNum", "ancestors", "children" };
|
||||
|
||||
/** 文本框 */
|
||||
public static string HTML_INPUT = "input";
|
||||
|
||||
/** 文本域 */
|
||||
public static string HTML_TEXTAREA = "textarea";
|
||||
|
||||
/** 下拉框 */
|
||||
public static string HTML_SELECT = "select";
|
||||
|
||||
/** 单选框 */
|
||||
public static string HTML_RADIO = "radio";
|
||||
|
||||
/** 复选框 */
|
||||
public static string HTML_CHECKBOX = "checkbox";
|
||||
|
||||
/** 日期控件 */
|
||||
public static string HTML_DATETIME = "datetime";
|
||||
|
||||
/** 图片上传控件 */
|
||||
public static string HTML_IMAGE_UPLOAD = "imageUpload";
|
||||
|
||||
/** 文件上传控件 */
|
||||
public static string HTML_FILE_UPLOAD = "fileUpload";
|
||||
|
||||
/** 富文本控件 */
|
||||
public static string HTML_EDITOR = "editor";
|
||||
|
||||
/** 字符串类型 */
|
||||
public static string TYPE_STRING = "string";
|
||||
|
||||
/** 整型 */
|
||||
public static string TYPE_INT = "int";
|
||||
|
||||
/** 长整型 */
|
||||
public static string TYPE_LONG = "long";
|
||||
|
||||
/** 浮点型 */
|
||||
public static string TYPE_DOUBLE = "Double";
|
||||
|
||||
/** 时间类型 */
|
||||
public static string TYPE_DATE = "Date";
|
||||
|
||||
/** 模糊查询 */
|
||||
public static string QUERY_LIKE = "LIKE";
|
||||
|
||||
/** 需要 */
|
||||
public static string REQUIRE = "1";
|
||||
}
|
||||
}
|
||||
@ -3,32 +3,45 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using ZR.Model.System.Generate;
|
||||
|
||||
namespace ZR.CodeGenerator.Model
|
||||
{
|
||||
public class GenerateDto
|
||||
{
|
||||
public string[] queryColumn { get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public string dbName { get; set; }
|
||||
/// <summary>
|
||||
/// 项目命名空间
|
||||
/// </summary>
|
||||
public string baseSpace { get; set; }
|
||||
/// <summary>
|
||||
/// 要生成代码的表
|
||||
/// </summary>
|
||||
public string tableName { get; set; }
|
||||
/// <summary>
|
||||
/// 要删除表名的字符串用
|
||||
/// </summary>
|
||||
public string replaceTableNameStr { get; set; }
|
||||
public long TableId { get; set; }
|
||||
public string[] QueryColumn { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 要生成的文件
|
||||
/// </summary>
|
||||
public int[] genFiles { get; set; }
|
||||
/// <summary>
|
||||
/// 如果目标文件存在,是否覆盖。默认为false
|
||||
/// </summary>
|
||||
public bool coverd { get; set; } = true;
|
||||
public GenTable GenTable { get; set; }
|
||||
#region 存储路径
|
||||
//public string ModelPath { get; set; }
|
||||
//public string ServicePath { get; set; }
|
||||
//public string RepositoryPath { get; set; }
|
||||
//public string ApiPath { get; set; }
|
||||
//public string VuePath { get; set; }
|
||||
//public string VueApiPath { get; set; }
|
||||
|
||||
//public string ParentPath { get; set; } = "..";
|
||||
/// <summary>
|
||||
/// 代码生成路径
|
||||
/// </summary>
|
||||
public string GenCodePath { get; set; }
|
||||
/// <summary>
|
||||
/// 代码生成压缩包路径
|
||||
/// </summary>
|
||||
public string ZipPath { get; set; }
|
||||
/// <summary>
|
||||
/// 代码生成压缩包名称
|
||||
/// </summary>
|
||||
public string ZipFileName { get; set; }
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
104
ZR.CodeGenerator/Model/ReplaceDto.cs
Normal file
104
ZR.CodeGenerator/Model/ReplaceDto.cs
Normal file
@ -0,0 +1,104 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ZR.CodeGenerator.Model
|
||||
{
|
||||
public class ReplaceDto
|
||||
{
|
||||
//public string ModelsNamespace { get; set; }
|
||||
//public string DtosNamespace { get; set; }
|
||||
//public string RepositoriesNamespace { get; set; }
|
||||
//public string IRepositoriesNamespace { get; set; }
|
||||
//public string IServicsNamespace { get; set; }
|
||||
//public string ServicesNamespace { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 主键字段
|
||||
/// </summary>
|
||||
public string PKName { get; set; }
|
||||
/// <summary>
|
||||
/// 主键类型
|
||||
/// </summary>
|
||||
public string PKType { get; set; }
|
||||
/// <summary>
|
||||
/// 控制器权限
|
||||
/// </summary>
|
||||
public string Permission { get; set; }
|
||||
/// <summary>
|
||||
/// C#类名
|
||||
/// </summary>
|
||||
public string ModelTypeName { get; set; }
|
||||
/// <summary>
|
||||
/// 数据库表名
|
||||
/// </summary>
|
||||
public string TableName { get; set; }
|
||||
/// <summary>
|
||||
/// 表描述、说明
|
||||
/// </summary>
|
||||
public string TableDesc { get; set; }
|
||||
/// <summary>
|
||||
/// 修改列
|
||||
/// </summary>
|
||||
public string UpdateColumn { get; set; }
|
||||
/// <summary>
|
||||
/// 插入列
|
||||
/// </summary>
|
||||
public string InsertColumn { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 实体属性模板
|
||||
/// </summary>
|
||||
public string ModelProperty { get; set; }
|
||||
/// <summary>
|
||||
/// 输入Dto模板
|
||||
/// </summary>
|
||||
public string InputDtoProperty { get; set; }
|
||||
|
||||
//vue、api
|
||||
public string VueViewFormResetHtml { get; set; }
|
||||
/// <summary>
|
||||
/// 前端列表查询html
|
||||
/// </summary>
|
||||
public string VueViewListHtml { get; set; }
|
||||
/// <summary>
|
||||
/// 前端添加、编辑表格html
|
||||
/// </summary>
|
||||
public string VueViewFormHtml { get; set; }
|
||||
/// <summary>
|
||||
/// 前端搜索表单html
|
||||
/// </summary>
|
||||
public string VueQueryFormHtml { get; set; }
|
||||
/// <summary>
|
||||
/// vue js方法
|
||||
/// </summary>
|
||||
public string VueJsMethod { get; set; }
|
||||
/// <summary>
|
||||
/// vue 添加、编辑表单规则
|
||||
/// </summary>
|
||||
public string VueViewEditFormRuleContent { get; set; }
|
||||
/// <summary>
|
||||
/// 查询条件
|
||||
/// </summary>
|
||||
public string QueryCondition { get; set; }
|
||||
/// <summary>
|
||||
/// 查询属性
|
||||
/// </summary>
|
||||
public string QueryProperty { get; set; }
|
||||
/// <summary>
|
||||
/// vue data内容
|
||||
/// </summary>
|
||||
public string VueDataContent { get; set; }
|
||||
/// <summary>
|
||||
/// vue mounted 方法
|
||||
/// </summary>
|
||||
public string MountedMethod { get; set; }
|
||||
/// <summary>
|
||||
/// views、js文件名
|
||||
/// </summary>
|
||||
public string ViewsFileName { get; set; }
|
||||
}
|
||||
}
|
||||
@ -33,10 +33,27 @@ namespace ZR.CodeGenerator.Service
|
||||
{
|
||||
tableList = tableList.Where(f => f.Name.ToLower().Contains(tableName.ToLower())).ToList();
|
||||
}
|
||||
tableList = tableList.Where(f => !new string[] { "gen", "sys_" }.Contains(f.Name)).ToList();
|
||||
pager.TotalNum = tableList.Count;
|
||||
return tableList.Skip(pager.PageSize * (pager.PageNum - 1)).Take(pager.PageSize).OrderBy(f => f.Name).ToList();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取单表数据
|
||||
/// </summary>
|
||||
/// <param name="dbName"></param>
|
||||
/// <param name="tableName"></param>
|
||||
/// <returns></returns>
|
||||
public DbTableInfo GetTableInfo(string dbName, string tableName)
|
||||
{
|
||||
var tableList = GetSugarDbContext(dbName).DbMaintenance.GetTableInfoList(true);
|
||||
if (!string.IsNullOrEmpty(tableName))
|
||||
{
|
||||
return tableList.Where(f => f.Name.ToLower() == (tableName.ToLower())).FirstOrDefault();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取列信息
|
||||
/// </summary>
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Infrastructure.Extensions;
|
||||
using ZR.Common.Extension;
|
||||
@ -44,69 +45,33 @@ namespace ZR.CodeGenerator.CodeGenerator
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
public static string GetPropertyDatatype(string sDatatype)
|
||||
/// <summary>
|
||||
/// 获取C# 类型
|
||||
/// </summary>
|
||||
/// <param name="sDatatype"></param>
|
||||
/// <returns></returns>
|
||||
public static string GetCSharpDatatype(string sDatatype)
|
||||
{
|
||||
string sTempDatatype = string.Empty;
|
||||
sDatatype = sDatatype.ToLower();
|
||||
switch (sDatatype)
|
||||
string sTempDatatype = sDatatype switch
|
||||
{
|
||||
case "int":
|
||||
case "number":
|
||||
case "integer":
|
||||
case "smallint":
|
||||
sTempDatatype = "int?";
|
||||
break;
|
||||
|
||||
case "bigint":
|
||||
sTempDatatype = "long?";
|
||||
break;
|
||||
|
||||
case "tinyint":
|
||||
sTempDatatype = "byte?";
|
||||
break;
|
||||
|
||||
case "numeric":
|
||||
case "real":
|
||||
sTempDatatype = "Single?";
|
||||
break;
|
||||
|
||||
case "float":
|
||||
sTempDatatype = "float?";
|
||||
break;
|
||||
|
||||
case "decimal":
|
||||
case "numer(8,2)":
|
||||
sTempDatatype = "decimal?";
|
||||
break;
|
||||
|
||||
case "bit":
|
||||
sTempDatatype = "bool?";
|
||||
break;
|
||||
|
||||
case "date":
|
||||
case "datetime":
|
||||
case "datetime2":
|
||||
case "smalldatetime":
|
||||
sTempDatatype = "DateTime?";
|
||||
break;
|
||||
|
||||
case "money":
|
||||
case "smallmoney":
|
||||
sTempDatatype = "double?";
|
||||
break;
|
||||
|
||||
case "char":
|
||||
case "varchar":
|
||||
case "nvarchar2":
|
||||
case "text":
|
||||
case "nchar":
|
||||
case "nvarchar":
|
||||
case "ntext":
|
||||
default:
|
||||
sTempDatatype = "string";
|
||||
break;
|
||||
}
|
||||
"int" or "number" or "integer" or "smallint" => "int",
|
||||
"bigint" => "long",
|
||||
"tinyint" => "byte",
|
||||
"numeric" or "real" or "float" => "float",
|
||||
"decimal" or "numer(8,2)" => "decimal",
|
||||
"bit" => "bool",
|
||||
"date" or "datetime" or "datetime2" or "smalldatetime" => "DateTime",
|
||||
"money" or "smallmoney" => "double",
|
||||
_ => "string",
|
||||
};
|
||||
return sTempDatatype;
|
||||
}
|
||||
|
||||
public static bool IsNumber(string tableDataType)
|
||||
{
|
||||
string[] arr = new string[] { "int", "long" };
|
||||
return arr.Any(f => f.Contains(GetCSharpDatatype(tableDataType)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace ZR.Model.Dto.System
|
||||
namespace ZR.Model.System.Dto
|
||||
{
|
||||
public class ArticleQueryDto: PagerInfo
|
||||
{
|
||||
53
ZR.Model/System/Dto/GenTableDto.cs
Normal file
53
ZR.Model/System/Dto/GenTableDto.cs
Normal file
@ -0,0 +1,53 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using ZR.Model.System.Generate;
|
||||
|
||||
namespace ZR.Model.System.Dto
|
||||
{
|
||||
public class GenTableDto
|
||||
{
|
||||
public int TableId { get; set; }
|
||||
public string TableName { get; set; }
|
||||
public string TableComment { get; set; }
|
||||
public string SubTableName { get; set; }
|
||||
public string SubTableFkName { get; set; }
|
||||
public string ClassName { get; set; }
|
||||
public string TplCategory { get; set; }
|
||||
public string BaseNameSpace { get; set; }
|
||||
public string ModuleName { get; set; }
|
||||
public string BusinessName { get; set; }
|
||||
public string FunctionName { get; set; }
|
||||
public string FunctionAuthor { get; set; }
|
||||
public string GenType { get; set; }
|
||||
public string Options { get; set; }
|
||||
public List<GenTableColumnDto> Columns { get; set; }
|
||||
}
|
||||
|
||||
public class GenTableColumnDto
|
||||
{
|
||||
public int ColumnId { get; set; }
|
||||
public int TableId { get; set; }
|
||||
public string ColumnComment { get; set; }
|
||||
public string CsharpType { get; set; }
|
||||
public string CsharpField { get; set; }
|
||||
public bool IsInsert { get; set; }
|
||||
public bool IsEdit { get; set; }
|
||||
public bool IsList { get; set; }
|
||||
public bool IsQuery { get; set; }
|
||||
public bool IsRequired { get; set; }
|
||||
/// <summary>
|
||||
/// 显示类型(文本框、文本域、下拉框、复选框、单选框、日期控件)
|
||||
/// </summary>
|
||||
public string HtmlType { get; set; }
|
||||
/// <summary>
|
||||
/// 查询类型(等于、不等于、大于、小于、范围)
|
||||
/// </summary>
|
||||
public string QueryType { get; set; } = "EQ";
|
||||
public int Sort { get; set; }
|
||||
/// <summary>
|
||||
/// 字典类型
|
||||
/// </summary>
|
||||
public string DictType { get; set; }
|
||||
}
|
||||
}
|
||||
@ -1,6 +1,6 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace ZR.Model.Dto.System
|
||||
namespace ZR.Model.System.Dto
|
||||
{
|
||||
public class LoginBodyDto
|
||||
{
|
||||
@ -2,7 +2,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace ZR.Model.Dto.System
|
||||
namespace ZR.Model.System.Dto
|
||||
{
|
||||
public class MenuDto
|
||||
{
|
||||
@ -3,7 +3,7 @@ using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Text;
|
||||
|
||||
namespace ZR.Model.Dto.System
|
||||
namespace ZR.Model.System.Dto
|
||||
{
|
||||
public class RoleUsersCreateDto
|
||||
{
|
||||
@ -2,7 +2,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace ZR.Model.Dto.System
|
||||
namespace ZR.Model.System.Dto
|
||||
{
|
||||
public class SysFileQueryDto : PagerInfo
|
||||
{
|
||||
@ -3,7 +3,7 @@ using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using ZR.Model.System;
|
||||
|
||||
namespace ZR.Model.Dto.System
|
||||
namespace ZR.Model.System.Dto
|
||||
{
|
||||
public class SysLogininfoDto : SysBase
|
||||
{
|
||||
@ -3,7 +3,7 @@ using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using ZR.Model.System;
|
||||
|
||||
namespace ZR.Model.Dto.System
|
||||
namespace ZR.Model.System.Dto
|
||||
{
|
||||
public class SysOperLogDto : SysBase
|
||||
{
|
||||
@ -3,7 +3,7 @@ using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using ZR.Model.System;
|
||||
|
||||
namespace ZR.Model.Dto.System
|
||||
namespace ZR.Model.System.Dto
|
||||
{
|
||||
public class SysRoleDto: SysBase
|
||||
{
|
||||
@ -3,7 +3,7 @@ using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using ZR.Model.System;
|
||||
|
||||
namespace ZR.Model.Dto.System
|
||||
namespace ZR.Model.System.Dto
|
||||
{
|
||||
public class SysUserDto
|
||||
{
|
||||
@ -3,7 +3,7 @@ using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Text;
|
||||
|
||||
namespace ZR.Model.Dto.System
|
||||
namespace ZR.Model.System.Dto
|
||||
{
|
||||
public class TasksQueryDto
|
||||
{
|
||||
@ -2,7 +2,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace ZR.Model.Dto.System
|
||||
namespace ZR.Model.System.Dto
|
||||
{
|
||||
public class TasksLogQueryDto
|
||||
{
|
||||
34
ZR.Model/System/Generate/GenTable.cs
Normal file
34
ZR.Model/System/Generate/GenTable.cs
Normal file
@ -0,0 +1,34 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace ZR.Model.System.Generate
|
||||
{
|
||||
/// <summary>
|
||||
/// 代码生成表
|
||||
/// </summary>
|
||||
[SqlSugar.SugarTable("gen_table")]
|
||||
public class GenTable: SysBase
|
||||
{
|
||||
[SqlSugar.SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
|
||||
public int TableId { get; set; }
|
||||
public string TableName { get; set; }
|
||||
public string TableComment { get; set; }
|
||||
public string SubTableName { get; set; }
|
||||
public string SubTableFkName { get; set; }
|
||||
public string ClassName { get; set; }
|
||||
public string TplCategory { get; set; }
|
||||
public string BaseNameSpace { get; set; }
|
||||
public string ModuleName { get; set; }
|
||||
public string BusinessName { get; set; }
|
||||
public string FunctionName { get; set; }
|
||||
public string FunctionAuthor { get; set; }
|
||||
public string GenType { get; set; }
|
||||
public string Options { get; set; }
|
||||
|
||||
|
||||
/** 表列信息 */
|
||||
[SqlSugar.SugarColumn(IsIgnore = true)]
|
||||
public List<GenTableColumn> Columns { get; set; }
|
||||
}
|
||||
}
|
||||
66
ZR.Model/System/Generate/GenTableColumn.cs
Normal file
66
ZR.Model/System/Generate/GenTableColumn.cs
Normal file
@ -0,0 +1,66 @@
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace ZR.Model.System.Generate
|
||||
{
|
||||
/// <summary>
|
||||
/// 代码生成表字段
|
||||
/// </summary>
|
||||
[SqlSugar.SugarTable("gen_table_column")]
|
||||
public class GenTableColumn: SysBase
|
||||
{
|
||||
[SqlSugar.SugarColumn(IsIdentity = true, IsPrimaryKey = true)]
|
||||
public int ColumnId { get; set; }
|
||||
public string ColumnName { get; set; }
|
||||
[SqlSugar.SugarColumn(IsOnlyIgnoreUpdate = true)]
|
||||
public int TableId { get; set; }
|
||||
|
||||
[SqlSugar.SugarColumn(IsOnlyIgnoreUpdate = true)]
|
||||
public string TableName { get; set; }
|
||||
public string ColumnComment { get; set; }
|
||||
|
||||
[SqlSugar.SugarColumn(IsOnlyIgnoreUpdate = true)]
|
||||
public string ColumnType { get; set; }
|
||||
public string CsharpType { get; set; }
|
||||
public string CsharpField { get; set; }
|
||||
/// <summary>
|
||||
/// 是否主键(1是)
|
||||
/// </summary>
|
||||
[SqlSugar.SugarColumn(IsOnlyIgnoreUpdate = true)]
|
||||
public bool IsPk { get; set; }
|
||||
/// <summary>
|
||||
/// 是否必填(1是)
|
||||
/// </summary>
|
||||
public bool IsRequired { get; set; }
|
||||
[SqlSugar.SugarColumn(IsOnlyIgnoreUpdate = true)]
|
||||
public bool IsIncrement { get; set; }
|
||||
/// <summary>
|
||||
/// 是否插入
|
||||
/// </summary>
|
||||
public bool IsInsert { get; set; }
|
||||
/// <summary>
|
||||
/// 是否需要编辑
|
||||
/// </summary>
|
||||
public bool IsEdit { get; set; }
|
||||
/// <summary>
|
||||
/// isList
|
||||
/// </summary>
|
||||
public bool IsList { get; set; }
|
||||
public bool IsQuery { get; set; }
|
||||
/// <summary>
|
||||
/// 显示类型(文本框、文本域、下拉框、复选框、单选框、日期控件)
|
||||
/// </summary>
|
||||
public string HtmlType { get; set; }
|
||||
/// <summary>
|
||||
/// 查询类型(等于、不等于、大于、小于、范围)
|
||||
/// </summary>
|
||||
public string QueryType { get; set; } = "EQ";
|
||||
public int Sort { get; set; }
|
||||
/// <summary>
|
||||
/// 字典类型
|
||||
/// </summary>
|
||||
public string DictType { get; set; }
|
||||
}
|
||||
}
|
||||
@ -22,10 +22,10 @@ namespace ZR.Model.System
|
||||
[SugarColumn(IsOnlyIgnoreInsert = true)]
|
||||
public string Update_by { get; set; }
|
||||
|
||||
//[JsonIgnore]
|
||||
[SugarColumn(IsOnlyIgnoreInsert = true)]//设置后插入数据不会有此字段
|
||||
[JsonIgnore]
|
||||
[JsonProperty(propertyName: "UpdateTime")]
|
||||
public DateTime Update_time { get; set; } = DateTime.Now;
|
||||
public DateTime? Update_time { get; set; }
|
||||
|
||||
public string Remark { get; set; }
|
||||
|
||||
@ -39,7 +39,6 @@ namespace ZR.Model.System
|
||||
/// [Computed]计算属性,打上此标签,对象地insert,update等操作会忽略此列
|
||||
/// </summary>
|
||||
[SugarColumn(IsIgnore = true)]
|
||||
//[Computed]
|
||||
[JsonIgnore]
|
||||
public DateTime? BeginTime { get; set; }
|
||||
|
||||
@ -47,7 +46,6 @@ namespace ZR.Model.System
|
||||
/// 用于搜索使用
|
||||
/// </summary>
|
||||
[SugarColumn(IsIgnore = true)]
|
||||
//[Computed]
|
||||
[JsonIgnore]
|
||||
public DateTime? EndTime { get; set; }
|
||||
}
|
||||
|
||||
@ -17,6 +17,7 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Dto\" />
|
||||
<Folder Include="Enum\" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
@ -22,7 +22,7 @@ namespace ZR.Repository.DbProvider
|
||||
{
|
||||
string connStr = ConfigUtils.Instance.GetConnectionStrings(OptionsSetting.ConnAdmin);
|
||||
string dbKey = ConfigUtils.Instance.GetAppConfig<string>(OptionsSetting.DbKey);
|
||||
int dbType = ConfigUtils.Instance.GetAppConfig(OptionsSetting.DbType, 0);
|
||||
int dbType = ConfigUtils.Instance.GetAppConfig<int>(OptionsSetting.ConnDbType);
|
||||
if (!string.IsNullOrEmpty(dbKey))
|
||||
{
|
||||
connStr = NETCore.Encrypt.EncryptProvider.DESDecrypt(connStr, dbKey);
|
||||
@ -52,21 +52,5 @@ namespace ZR.Repository.DbProvider
|
||||
Console.WriteLine();
|
||||
};
|
||||
}
|
||||
|
||||
public SqlSugarClient GetSugarDbContext(string dbName)
|
||||
{
|
||||
string connStr = ConfigUtils.Instance.GetConnectionStrings(OptionsSetting.Conn).Replace("{DbName}", dbName);
|
||||
int dbType = ConfigUtils.Instance.GetAppConfig(OptionsSetting.DbType, 0);
|
||||
|
||||
return new SqlSugarClient(new List<ConnectionConfig>()
|
||||
{
|
||||
new ConnectionConfig(){
|
||||
ConnectionString = connStr,
|
||||
DbType = (DbType)dbType,
|
||||
IsAutoCloseConnection = true,//开启自动释放模式和EF原理一样
|
||||
InitKeyType = InitKeyType.Attribute,//从特性读取主键和自增列信息
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -4,7 +4,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using ZR.Model.Dto.System;
|
||||
using ZR.Model.System.Dto;
|
||||
using ZR.Model.System;
|
||||
|
||||
namespace ZR.Repository.System
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
using Infrastructure.Extensions;
|
||||
using System.Collections.Generic;
|
||||
using ZR.Model;
|
||||
using ZR.Model.Dto.System;
|
||||
using ZR.Model.System.Dto;
|
||||
using ZR.Model.System;
|
||||
|
||||
namespace ZR.Repository.System
|
||||
|
||||
@ -3,7 +3,7 @@ using SqlSugar;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using ZR.Model.Dto.System;
|
||||
using ZR.Model.System.Dto;
|
||||
using ZR.Model.System;
|
||||
|
||||
namespace ZR.Repository.System
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
using Infrastructure.Extensions;
|
||||
using System.Collections.Generic;
|
||||
using ZR.Model;
|
||||
using ZR.Model.Dto.System;
|
||||
using ZR.Model.System.Dto;
|
||||
using ZR.Model.System;
|
||||
|
||||
namespace ZR.Repository.System
|
||||
|
||||
@ -54,6 +54,18 @@ namespace ZR.Service
|
||||
return Db.Insertable(parm).RemoveDataCache().ExecuteCommand();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加
|
||||
/// </summary>
|
||||
/// <param name="parm"></param>
|
||||
/// <param name="iClumns">插入列</param>
|
||||
/// <param name="ignoreNull">忽略null列</param>
|
||||
/// <returns></returns>
|
||||
public int Add(T parm, Expression<Func<T, object>> iClumns = null, bool ignoreNull = true)
|
||||
{
|
||||
return Db.Insertable(parm).InsertColumns(iClumns).IgnoreColumns(ignoreNullColumn: ignoreNull).ExecuteCommand();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 批量添加数据
|
||||
/// </summary>
|
||||
@ -65,7 +77,7 @@ namespace ZR.Service
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加或更新数据
|
||||
/// 添加或更新数据,不推荐使用了
|
||||
/// </summary>
|
||||
/// <param name="parm">List<T></param>
|
||||
/// <returns></returns>
|
||||
|
||||
@ -42,6 +42,8 @@ namespace ZR.Service
|
||||
/// <returns></returns>
|
||||
int Add(T parm);
|
||||
|
||||
int Add(T parm, Expression<Func<T, object>> iClumns = null, bool ignoreNull = false);
|
||||
|
||||
/// <summary>
|
||||
/// 批量添加数据
|
||||
/// </summary>
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using ZR.Model.System;
|
||||
using ZR.Service.IService;
|
||||
using ZR.Service.System.IService;
|
||||
|
||||
namespace ZR.Service.System
|
||||
{
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
using Infrastructure.Attribute;
|
||||
using ZR.Model.System;
|
||||
using ZR.Service.IService;
|
||||
using ZR.Service.System.IService;
|
||||
|
||||
namespace ZR.Service.System
|
||||
{
|
||||
|
||||
193
ZR.Service/System/GenTableService.cs
Normal file
193
ZR.Service/System/GenTableService.cs
Normal file
@ -0,0 +1,193 @@
|
||||
using Infrastructure.Attribute;
|
||||
using Infrastructure.Extensions;
|
||||
using Infrastructure.Model;
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using ZR.Model.System.Generate;
|
||||
using ZR.Service.System.IService;
|
||||
|
||||
namespace ZR.Service.System
|
||||
{
|
||||
/// <summary>
|
||||
/// 代码生成表
|
||||
/// </summary>
|
||||
[AppService(ServiceType = typeof(IGenTableService), ServiceLifetime = LifeTime.Transient)]
|
||||
public class GenTableService : BaseService<GenTable>, IGenTableService
|
||||
{
|
||||
public IGenTableColumnService GenTableColumnService;
|
||||
public GenTableService(IGenTableColumnService genTableColumnService)
|
||||
{
|
||||
GenTableColumnService = genTableColumnService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除表
|
||||
/// </summary>
|
||||
/// <param name="tableIds">需要删除的表id</param>
|
||||
/// <returns></returns>
|
||||
public int DeleteGenTableByIds(long[] tableIds)
|
||||
{
|
||||
Db.Deleteable<GenTable>().Where(f => tableIds.Contains(f.TableId)).ExecuteCommand();
|
||||
return GenTableColumnService.DeleteGenTableColumn(tableIds);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除表根据表名
|
||||
/// </summary>
|
||||
/// <param name="tableName"></param>
|
||||
/// <returns></returns>
|
||||
public int DeleteGenTableByTbName(string tableName)
|
||||
{
|
||||
return Db.Deleteable<GenTable>().Where(f => f.TableName == tableName).ExecuteCommand();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取表信息
|
||||
/// </summary>
|
||||
/// <param name="tableId"></param>
|
||||
/// <returns></returns>
|
||||
public GenTable GetGenTableInfo(long tableId)
|
||||
{
|
||||
return GetId(tableId);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查询代码生成表信息
|
||||
/// </summary>
|
||||
/// <param name="genTable"></param>
|
||||
/// <param name="pagerInfo"></param>
|
||||
/// <returns></returns>
|
||||
public PagedInfo<GenTable> GetGenTables(GenTable genTable, Model.PagerInfo pagerInfo)
|
||||
{
|
||||
var predicate = Expressionable.Create<GenTable>();
|
||||
predicate = predicate.AndIF(genTable.TableName.IfNotEmpty(), it => it.TableName.Contains(genTable.TableName));
|
||||
|
||||
return GetPages(predicate.ToExpression(), pagerInfo);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 插入代码生成表
|
||||
/// </summary>
|
||||
/// <param name="table"></param>
|
||||
/// <returns></returns>
|
||||
public int ImportGenTable(GenTable table)
|
||||
{
|
||||
var db = Db;
|
||||
table.Create_time = db.GetDate();
|
||||
//导入前删除现有表
|
||||
//DeleteGenTableByIds(new long[] { table.TableId });
|
||||
DeleteGenTableByTbName(table.TableName);
|
||||
|
||||
return db.Insertable(table).IgnoreColumns(ignoreNullColumn: true).ExecuteReturnIdentity();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取表数据
|
||||
/// </summary>
|
||||
/// <param name="tableNames"></param>
|
||||
/// <returns></returns>
|
||||
public List<GenTable> SelectDbTableListByNamess(string[] tableNames)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public int UpdateGenTable(GenTable genTable)
|
||||
{
|
||||
var db = Db;
|
||||
genTable.Update_time = db.GetDate();
|
||||
return db.Updateable(genTable).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommand();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 代码生成表列
|
||||
/// </summary>
|
||||
[AppService(ServiceType = typeof(IGenTableColumnService), ServiceLifetime = LifeTime.Transient)]
|
||||
public class GenTableColumnService : BaseService<GenTableColumn>, IGenTableColumnService
|
||||
{
|
||||
/// <summary>
|
||||
/// 删除表字段
|
||||
/// </summary>
|
||||
/// <param name="tableColumn"></param>
|
||||
/// <returns></returns>
|
||||
public int DeleteGenTableColumn(long tableId)
|
||||
{
|
||||
return DeleteGenTableColumn(new long[] { tableId });
|
||||
}
|
||||
/// <summary>
|
||||
/// 根据表id批量删除表字段
|
||||
/// </summary>
|
||||
/// <param name="tableId"></param>
|
||||
/// <returns></returns>
|
||||
public int DeleteGenTableColumn(long[] tableId)
|
||||
{
|
||||
return Db.Deleteable<GenTableColumn>().Where(f => tableId.Contains(f.TableId)).ExecuteCommand();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据表名删除字段
|
||||
/// </summary>
|
||||
/// <param name="tableName"></param>
|
||||
/// <returns></returns>
|
||||
public int DeleteGenTableColumnByTableName(string tableName)
|
||||
{
|
||||
return Db.Deleteable<GenTableColumn>().Where(f => f.TableName == tableName).ExecuteCommand();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取表所有字段
|
||||
/// </summary>
|
||||
/// <param name="tableId"></param>
|
||||
/// <returns></returns>
|
||||
public List<GenTableColumn> GenTableColumns(long tableId)
|
||||
{
|
||||
return Db.Queryable<GenTableColumn>().Where(f => f.TableId == tableId).OrderBy(x => x.Sort).ToList();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 插入表字段
|
||||
/// </summary>
|
||||
/// <param name="tableColumn"></param>
|
||||
/// <returns></returns>
|
||||
public int InsertGenTableColumn(List<GenTableColumn> tableColumn)
|
||||
{
|
||||
return Db.Insertable(tableColumn).IgnoreColumns(x => new { x.Remark }).ExecuteCommand();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 批量更新表字段
|
||||
/// </summary>
|
||||
/// <param name="tableColumn"></param>
|
||||
/// <returns></returns>
|
||||
public int UpdateGenTableColumn(List<GenTableColumn> tableColumn)
|
||||
{
|
||||
foreach (var item in tableColumn)
|
||||
{
|
||||
Db.Updateable<GenTableColumn>()
|
||||
.Where(f => f.TableId == item.TableId)
|
||||
.SetColumns(it => new GenTableColumn()
|
||||
{
|
||||
ColumnComment = item.ColumnComment,
|
||||
CsharpField = item.CsharpField,
|
||||
CsharpType = item.CsharpType,
|
||||
IsQuery = item.IsQuery,
|
||||
IsEdit = item.IsEdit,
|
||||
IsInsert = item.IsInsert,
|
||||
IsList = item.IsList,
|
||||
QueryType = item.QueryType,
|
||||
HtmlType = item.HtmlType,
|
||||
IsRequired = item.IsRequired,
|
||||
Sort = item.Sort,
|
||||
Update_time = DateTime.Now,
|
||||
DictType = item.DictType
|
||||
})
|
||||
.Where(f => f.ColumnId == item.ColumnId)
|
||||
.ExecuteCommand();
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -5,7 +5,7 @@ using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using ZR.Model.System;
|
||||
|
||||
namespace ZR.Service.IService
|
||||
namespace ZR.Service.System.IService
|
||||
{
|
||||
public interface IArticleCategoryService : IBaseService<ArticleCategory>
|
||||
{
|
||||
@ -3,10 +3,10 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using ZR.Model.Dto.System;
|
||||
using ZR.Model.System.Dto;
|
||||
using ZR.Model.System;
|
||||
|
||||
namespace ZR.Service.IService
|
||||
namespace ZR.Service.System.IService
|
||||
{
|
||||
public interface IArticleService : IBaseService<Article>
|
||||
{
|
||||
34
ZR.Service/System/IService/IGenTableService.cs
Normal file
34
ZR.Service/System/IService/IGenTableService.cs
Normal file
@ -0,0 +1,34 @@
|
||||
using Infrastructure.Model;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using ZR.Model.System.Generate;
|
||||
|
||||
namespace ZR.Service.System.IService
|
||||
{
|
||||
public interface IGenTableService
|
||||
{
|
||||
List<GenTable> SelectDbTableListByNamess(string[] tableNames);
|
||||
|
||||
int ImportGenTable(GenTable tables);
|
||||
|
||||
int DeleteGenTableByIds(long[] tableIds);
|
||||
int DeleteGenTableByTbName(string tableName);
|
||||
PagedInfo<GenTable> GetGenTables(GenTable genTable, Model.PagerInfo pagerInfo);
|
||||
GenTable GetGenTableInfo(long tableId);
|
||||
int UpdateGenTable(GenTable genTable);
|
||||
}
|
||||
|
||||
public interface IGenTableColumnService
|
||||
{
|
||||
int InsertGenTableColumn(List<GenTableColumn> tableColumn);
|
||||
|
||||
int DeleteGenTableColumn(long tableId);
|
||||
int DeleteGenTableColumn(long[] tableIds);
|
||||
int DeleteGenTableColumnByTableName(string tableName);
|
||||
List<GenTableColumn> GenTableColumns(long tableId);
|
||||
int UpdateGenTableColumn(List<GenTableColumn> tableColumn);
|
||||
}
|
||||
}
|
||||
@ -4,7 +4,7 @@ using System.Text;
|
||||
using ZR.Model.System;
|
||||
using ZR.Model.Vo.System;
|
||||
|
||||
namespace ZR.Service.IService
|
||||
namespace ZR.Service.System.IService
|
||||
{
|
||||
public interface ISysDeptService : IBaseService<SysDept>
|
||||
{
|
||||
@ -3,7 +3,7 @@ using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using ZR.Model.System;
|
||||
|
||||
namespace ZR.Service.IService
|
||||
namespace ZR.Service.System.IService
|
||||
{
|
||||
public interface ISysDictDataService : IBaseService<SysDictData>
|
||||
{
|
||||
@ -3,7 +3,7 @@ using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using ZR.Model.System;
|
||||
|
||||
namespace ZR.Service.IService
|
||||
namespace ZR.Service.System.IService
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
@ -1,7 +1,7 @@
|
||||
using Infrastructure.Attribute;
|
||||
using ZR.Model.System;
|
||||
|
||||
namespace ZR.Service.IService
|
||||
namespace ZR.Service.System.IService
|
||||
{
|
||||
public interface ISysFileService : IBaseService<SysFile>
|
||||
{
|
||||
@ -2,10 +2,10 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using ZR.Model;
|
||||
using ZR.Model.Dto.System;
|
||||
using ZR.Model.System.Dto;
|
||||
using ZR.Model.System;
|
||||
|
||||
namespace ZR.Service.IService
|
||||
namespace ZR.Service.System.IService
|
||||
{
|
||||
public interface ISysLoginService
|
||||
{
|
||||
@ -1,10 +1,10 @@
|
||||
using System.Collections.Generic;
|
||||
using ZR.Model.Dto.System;
|
||||
using ZR.Model.System.Dto;
|
||||
using ZR.Model.System;
|
||||
using ZR.Model.System.Vo;
|
||||
using ZR.Model.Vo.System;
|
||||
|
||||
namespace ZR.Service.IService
|
||||
namespace ZR.Service.System.IService
|
||||
{
|
||||
public interface ISysMenuService: IBaseService<SysMenu>
|
||||
{
|
||||
@ -1,10 +1,10 @@
|
||||
using System.Collections.Generic;
|
||||
using ZR.Model;
|
||||
using ZR.Model.Dto.System;
|
||||
using ZR.Model.System.Dto;
|
||||
using ZR.Model.System;
|
||||
using ZR.Service.System;
|
||||
|
||||
namespace ZR.Service.IService
|
||||
namespace ZR.Service.System.IService
|
||||
{
|
||||
public interface ISysOperLogService : IBaseService<SysOperLog>
|
||||
{
|
||||
@ -5,7 +5,7 @@ using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using ZR.Model.System;
|
||||
|
||||
namespace ZR.Service.IService
|
||||
namespace ZR.Service.System.IService
|
||||
{
|
||||
public interface ISysPermissionService
|
||||
{
|
||||
@ -3,7 +3,7 @@ using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using ZR.Model.System;
|
||||
|
||||
namespace ZR.Service.IService
|
||||
namespace ZR.Service.System.IService
|
||||
{
|
||||
public interface ISysPostService: IBaseService<SysPost>
|
||||
{
|
||||
@ -4,7 +4,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using ZR.Model.System;
|
||||
|
||||
namespace ZR.Service.IService
|
||||
namespace ZR.Service.System.IService
|
||||
{
|
||||
public interface ISysRoleService: IBaseService<SysRole>
|
||||
{
|
||||
@ -1,6 +1,6 @@
|
||||
using ZR.Model.System;
|
||||
|
||||
namespace ZR.Service.IService
|
||||
namespace ZR.Service.System.IService
|
||||
{
|
||||
public interface ISysTasksLogService : IBaseService<SysTasksLog>
|
||||
{
|
||||
@ -5,7 +5,7 @@ using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using ZR.Model.System;
|
||||
|
||||
namespace ZR.Service.IService
|
||||
namespace ZR.Service.System.IService
|
||||
{
|
||||
public interface ISysTasksQzService: IBaseService<SysTasksQz>
|
||||
{
|
||||
@ -1,7 +1,7 @@
|
||||
using System.Collections.Generic;
|
||||
using ZR.Model.System;
|
||||
|
||||
namespace ZR.Service.IService
|
||||
namespace ZR.Service.System.IService
|
||||
{
|
||||
public interface ISysUserPostService: IBaseService<SysUserPost>
|
||||
{
|
||||
@ -3,10 +3,10 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using ZR.Model.Dto.System;
|
||||
using ZR.Model.System.Dto;
|
||||
using ZR.Model.System;
|
||||
|
||||
namespace ZR.Service.IService
|
||||
namespace ZR.Service.System.IService
|
||||
{
|
||||
public interface ISysUserRoleService
|
||||
{
|
||||
@ -6,7 +6,7 @@ using System.Threading.Tasks;
|
||||
using ZR.Model;
|
||||
using ZR.Model.System;
|
||||
|
||||
namespace ZR.Service.IService
|
||||
namespace ZR.Service.System.IService
|
||||
{
|
||||
public interface ISysUserService : IBaseService<SysUser>
|
||||
{
|
||||
@ -10,7 +10,7 @@ using ZR.Common;
|
||||
using ZR.Model.System;
|
||||
using ZR.Model.Vo.System;
|
||||
using ZR.Repository.System;
|
||||
using ZR.Service.IService;
|
||||
using ZR.Service.System.IService;
|
||||
|
||||
namespace ZR.Service.System
|
||||
{
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user