新增加代码生成器功能
This commit is contained in:
commit
6ba14c3aa9
1
.gitignore
vendored
1
.gitignore
vendored
@ -262,3 +262,4 @@ __pycache__/
|
||||
/ZRAdmin/Properties/launchSettings.json
|
||||
/ZRAdmin/Properties/PublishProfiles
|
||||
/ZR.Admin.WebApi/appsettings.Stage.json
|
||||
/CodeGenerate
|
||||
|
||||
@ -59,7 +59,7 @@ namespace Infrastructure.Extensions
|
||||
services.AddTransient(serviceType, type);
|
||||
break;
|
||||
}
|
||||
Console.WriteLine($"注册:{serviceType}");
|
||||
//Console.WriteLine($"注册:{serviceType}");
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@ -5,7 +5,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ZR.Common.Extension
|
||||
namespace Infrastructure.Extensions
|
||||
{
|
||||
public static partial class Extensions
|
||||
{
|
||||
@ -7,7 +7,7 @@ using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
//using Newtonsoft.Json;
|
||||
|
||||
namespace ZR.Common.Extension
|
||||
namespace Infrastructure.Extensions
|
||||
{
|
||||
public static partial class Extensions
|
||||
{
|
||||
@ -4,7 +4,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ZR.Common.Extension
|
||||
namespace Infrastructure.Extensions
|
||||
{
|
||||
public static partial class Extensions
|
||||
{
|
||||
@ -5,7 +5,7 @@ using System.Linq.Expressions;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ZR.Common.Extension
|
||||
namespace Infrastructure.Extensions
|
||||
{
|
||||
public static class LinqExtensions
|
||||
{
|
||||
@ -5,7 +5,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ZR.Common.Extension
|
||||
namespace Infrastructure.Extensions
|
||||
{
|
||||
public static partial class Extensions
|
||||
{
|
||||
@ -1,10 +1,10 @@
|
||||
using System;
|
||||
using Infrastructure.Extensions;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using ZR.Common.Extension;
|
||||
|
||||
namespace ZR.Common
|
||||
namespace Infrastructure
|
||||
{
|
||||
public class ComputerHelper
|
||||
{
|
||||
@ -2,7 +2,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace ZR.Common
|
||||
namespace Infrastructure
|
||||
{
|
||||
public class DateTimeHelper
|
||||
{
|
||||
@ -4,7 +4,7 @@ using System.IO;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
|
||||
namespace ZR.Common
|
||||
namespace Infrastructure
|
||||
{
|
||||
public class FileUtil
|
||||
{
|
||||
@ -4,7 +4,7 @@ using System.Net.Http;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ZR.Common
|
||||
namespace Infrastructure
|
||||
{
|
||||
public class HttpHelper
|
||||
{
|
||||
@ -3,7 +3,7 @@ using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Text;
|
||||
|
||||
namespace ZR.Common
|
||||
namespace Infrastructure
|
||||
{
|
||||
public class ShellHelper
|
||||
{
|
||||
@ -6,20 +6,11 @@ namespace Infrastructure
|
||||
/// </summary>
|
||||
public class OptionsSetting
|
||||
{
|
||||
public static string ConnAdmin = "Conn_admin";
|
||||
public static string DbType = "DbType";
|
||||
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>
|
||||
/// 是否演示模式
|
||||
|
||||
110
README.md
110
README.md
@ -2,26 +2,29 @@
|
||||
|
||||
## 🍟概述
|
||||
* 本项目适合有一定NetCore和 vue基础的开发人员
|
||||
* ZRAdmin.NET是基于.NET 5开发的权限管理及快速开发框架,整合最新技术包括Asp.NetCore WebApi、Sqlsugar、Swagger、Vue等,核心模块包括组织机构、角色用户、权限授权、定时任务、文章管理等。
|
||||
* 模块化架构设计,层次清晰,业务层推荐写到单独模块,框架升级不影响业务!
|
||||
* 代码量少、通俗易懂、功能强大、易扩展,轻松开发从现在开始!
|
||||
* 基于.NET 5实现的通用权限管理平台(RBAC模式)。整合最新技术高效快速开发,前后端分离模式,开箱即用。
|
||||
* 代码量少、学习简单、通俗易懂、功能强大、易扩展、轻量级,让web开发更快速、简单高效,解决70%的重复工作,专注您的业务,轻松开发从现在开始!
|
||||
* 前端采用Vue2.0、Element UI。
|
||||
* 后端采用Net5、Sqlsugar、MySQL。
|
||||
* 权限认证使用Jwt,支持多终端认证系统。
|
||||
* 支持加载动态权限菜单,多方式轻松权限控制
|
||||
* 基于若依vue分离版本(java版本)修改
|
||||
|
||||
~ 如果对您有帮助,您可以点右上角 “Star” 收藏一下 ,获取第一时间更新,谢谢!~
|
||||
```
|
||||
如果对您有帮助,您可以点右上角 “Star” 收藏一下 ,这样作者才有继续免费下去的动力,谢谢!~
|
||||
```
|
||||
|
||||
## 🍿在线体验
|
||||
vue版本体验地址:http://www.izhaorui.cn:8080/ (用户名:admin,密码:123456)
|
||||
- 体验地址:http://www.izhaorui.cn:8080/
|
||||
- 管理员:admin
|
||||
- 密 码:123456
|
||||
|
||||
**由于是个人项目,资金有限,体验服是低配,请大家爱惜,轻戳,不胜感激!!!**
|
||||
|
||||
## 🥼前端技术
|
||||
```
|
||||
由于是个人项目,资金有限,体验服是低配,请大家爱惜,轻戳,不胜感激!!!
|
||||
```
|
||||
## 🍁前端技术
|
||||
Vue版前端技术栈 :基于vue、vuex、vue-router 、vue-cli 、axios 和 element-ui,前端采用vscode工具开发
|
||||
|
||||
## 🥼后端技术
|
||||
## 🍀后端技术
|
||||
核心框架:.Net5.0 + Web API + sqlsugar + swagger
|
||||
|
||||
定时计划任务:Quartz.Net组件
|
||||
@ -30,11 +33,11 @@ Vue版前端技术栈 :基于vue、vuex、vue-router 、vue-cli 、axios 和 e
|
||||
|
||||
日志管理:NLog、登录日志、操作日志
|
||||
|
||||
工具类:验证码、丰富公共功能
|
||||
工具类:验证码、丰富公共功能、代码生成
|
||||
|
||||
## 🍄快速启动
|
||||
需要安装:VS2019(最新版)、npm或yarn(最新版)
|
||||
准备工作:将document文件夹下面的admin.sql脚本导入到数据库中,修改ZRAdmin项目里面的Conn_Admin数据库连接字符串以及DbType选择对应的数据库类型,目前仅MySQL验证了
|
||||
准备工作:将document文件夹下面的admin.sql脚本导入到数据库中,修改appsettings.json配置文件里面中的conn_zrAdmin数据库连接字符串以及conn_zrAdmin_Type选择对应的数据库类型,目前仅支持MySQL、SQL server
|
||||
启动后台:打开项目根目录的startup.bat即可启动(数据库默认MySQL)
|
||||
启动前端:打开ZR.Vue文件夹,运行npm install命令,再运行npm run serve启动
|
||||
浏览器访问:http://localhost:8887 (默认前端端口为:8887,后台端口为:8888)
|
||||
@ -42,21 +45,47 @@ Vue版前端技术栈 :基于vue、vuex、vue-router 、vue-cli 、axios 和 e
|
||||
|
||||
## 🍖内置功能
|
||||
|
||||
1. [X] 用户管理:用户是系统操作者,该功能主要完成系统用户配置。
|
||||
2. [X] 部门管理:配置系统组织机构(公司、部门、小组),树结构展现。
|
||||
3. [X] 岗位管理:配置系统用户所属担任职务。
|
||||
4. [X] 菜单管理:配置系统菜单,操作权限,按钮权限标识等。
|
||||
5. [X] 角色管理:角色菜单权限分配。
|
||||
6. [X] 字典管理:对系统中经常使用的一些较为固定的数据进行维护。
|
||||
7. [ ] 参数管理:对系统动态配置常用参数。
|
||||
8. [X] 操作日志:系统正常操作日志记录和查询;系统异常信息日志记录和查询。
|
||||
9. [X] 登录日志:系统登录日志记录查询包含登录异常。
|
||||
10. [ ] 在线用户:当前系统中活跃用户状态监控。
|
||||
11. [X] 系统接口:使用swagger生成相关api接口文档。
|
||||
12. [X] 服务监控:监视当前系统CPU、内存、磁盘、堆栈等相关信息。
|
||||
13. [X] 在线构建器:拖动表单元素生成相应的VUE代码。
|
||||
14. [X] 任务系统:基于Quartz.NET定时任务执行。
|
||||
15. [X] 文章管理:可以写文章记录。
|
||||
1. 用户管理:用户是系统操作者,该功能主要完成系统用户配置。
|
||||
2. 部门管理:配置系统组织机构(公司、部门、小组),树结构展现。
|
||||
3. 岗位管理:配置系统用户所属担任职务。
|
||||
4. 菜单管理:配置系统菜单,操作权限,按钮权限标识等。
|
||||
5. 角色管理:角色菜单权限分配。
|
||||
6. 字典管理:对系统中经常使用的一些较为固定的数据进行维护。
|
||||
6. 操作日志:系统正常操作日志记录和查询;系统异常信息日志记录和查询。
|
||||
7. 登录日志:系统登录日志记录查询包含登录异常。
|
||||
8. 系统接口:使用swagger生成相关api接口文档。
|
||||
9. 服务监控:监视当前系统CPU、内存、磁盘、堆栈等相关信息。
|
||||
10. 在线构建器:拖动表单元素生成相应的VUE代码。
|
||||
11. 任务系统:基于Quartz.NET定时任务执行。
|
||||
12. 文章管理:可以写文章记录。
|
||||
13. 代码生成:可以一键生成前后端代码(.cs、.vue、.js),自定义配置前端展示控件、让开发更快捷高效。
|
||||
|
||||
|
||||
## 🍻项目结构
|
||||
|
||||
```
|
||||
- ZR.Service[服务层类库]:提供WebApi接口调用;
|
||||
- ZR.Repository[仓库层类库]:方便提供有执行存储过程的操作;
|
||||
- ZR.Model[实体层类库],提供项目中的数据库表、数据传输对象;
|
||||
- ZR.Admin.WebApi[webapi接口]:为Vue版或其他三方系统提供接口服务。
|
||||
- ZR.Vue[前端UI]:vue版本UI层。
|
||||
- ZR.Tasks[定时任务类库]:提供项目定时任务实现功能;
|
||||
- ZR.CodeGenerator[代码生成功能],包含代码生成的模板、方法、代码生成的下载。
|
||||
```
|
||||
## ⚡ 近期计划
|
||||
|
||||
- [ ] 参数管理
|
||||
- [ ] 在线用户
|
||||
- [ ] 文件管理
|
||||
- [ ] 邮件发送
|
||||
- [ ] 集成微信开发
|
||||
|
||||
## 📖 帮助文档
|
||||
👉快捷部署到Linux文档:
|
||||
- [本地md文件](./document/nginx部署文档.md "代码生成")
|
||||
|
||||
👉代码生成器使用教程:
|
||||
- [本地md文件](./document/代码生成器使用.md "代码生成")
|
||||
|
||||
## 🍎演示图
|
||||
|
||||
@ -80,7 +109,22 @@ Vue版前端技术栈 :基于vue、vuex、vue-router 、vue-cli 、axios 和 e
|
||||
<tr>
|
||||
<td><img src="https://www.izhaorui.cn/images/zradmin/9.png"/></td>
|
||||
<td><img src="https://www.izhaorui.cn/images/zradmin/10.png"/></td>
|
||||
</tr>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><img src="https://www.izhaorui.cn/images/zradmin/11.png"/></td>
|
||||
<td><img src="https://www.izhaorui.cn/images/zradmin/12.png"/></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<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>
|
||||
<tr>
|
||||
<td><img src="https://www.izhaorui.cn/images/zradmin/17.png"/></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
## 🎉优势
|
||||
@ -89,16 +133,14 @@ Vue版前端技术栈 :基于vue、vuex、vue-router 、vue-cli 、axios 和 e
|
||||
2. 后台系统无需任何二次开发,直接发布即可使用
|
||||
3. 前台与后台系统分离,分别为不同的系统(域名可独立)
|
||||
4. 全局异常统一处理
|
||||
5. 自定义的代码生成功能
|
||||
|
||||
## 💐 特别鸣谢
|
||||
- 👉Ruoyi.vue:[Ruoyi](http://www.ruoyi.vip/)
|
||||
- 👉SqlSugar:https://gitee.com/dotnetchina/SqlSugar
|
||||
- 👉SqlSugar:[SqlSugar](https://gitee.com/dotnetchina/SqlSugar)
|
||||
|
||||
## 🍻参与贡献
|
||||
- Fork 本项目
|
||||
- 新建 Feat_xxx 分支
|
||||
- 提交代码
|
||||
- 新建 Pull Request
|
||||
## 😎联系作者
|
||||
QQ:599854767
|
||||
|
||||
## 🎀捐赠
|
||||
如果这个项目对您有所帮助,请扫下方二维码打赏一杯咖啡。
|
||||
|
||||
@ -16,34 +16,36 @@ namespace ZR.Admin.WebApi.Controllers
|
||||
public static string TIME_FORMAT_FULL = "yyyy-MM-dd HH:mm:ss";
|
||||
public static string TIME_FORMAT_FULL_2 = "MM-dd HH:mm:ss";
|
||||
|
||||
protected IActionResult SUCCESS(object data, string timeFormatStr = "MM-dd HH:mm:ss")
|
||||
protected IActionResult SUCCESS(object data, string timeFormatStr = "yyyy-MM-dd HH:mm:ss")
|
||||
{
|
||||
string jsonStr = GetJsonStr(GetApiResult(data != null ? ResultCode.SUCCESS : ResultCode.FAIL, data), timeFormatStr);
|
||||
return Content(jsonStr, "application/json");
|
||||
}
|
||||
|
||||
protected IActionResult ToRespose(ResultCode resultCode, object data = null)
|
||||
{
|
||||
string jsonStr = GetJsonStr(GetApiResult(resultCode, data), "");
|
||||
return Content(jsonStr, "application/json");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// json输出带时间格式的
|
||||
/// </summary>
|
||||
/// <param name="apiResult"></param>
|
||||
/// <param name="timeFormatStr"></param>
|
||||
/// <returns></returns>
|
||||
protected IActionResult OutputJson(ApiResult apiResult, string timeFormatStr = "MM-dd HH:mm:ss")
|
||||
protected IActionResult OutputJson(ApiResult apiResult, string timeFormatStr = "yyyy-MM-dd HH:mm:ss")
|
||||
{
|
||||
string jsonStr = GetJsonStr(apiResult, timeFormatStr);
|
||||
|
||||
return Content(jsonStr, "application/json");
|
||||
}
|
||||
protected IActionResult OutputJson(long rows, string timeFormatStr = "MM-dd HH:mm:ss")
|
||||
protected IActionResult OutputJson(long rows, string timeFormatStr = "yyyy-MM-dd HH:mm:ss")
|
||||
{
|
||||
string jsonStr = GetJsonStr(ToJson(rows), timeFormatStr);
|
||||
|
||||
return Content(jsonStr, "application/json");
|
||||
}
|
||||
protected string SerializeObject(object obj)
|
||||
{
|
||||
return JsonConvert.SerializeObject(obj);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 响应返回结果
|
||||
|
||||
249
ZR.Admin.WebApi/Controllers/CodeGeneratorController.cs
Normal file
249
ZR.Admin.WebApi/Controllers/CodeGeneratorController.cs
Normal file
@ -0,0 +1,249 @@
|
||||
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
|
||||
{
|
||||
/// <summary>
|
||||
/// 代码生成
|
||||
/// </summary>
|
||||
[Route("tool/gen")]
|
||||
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>
|
||||
/// 获取所有数据库的信息
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet("getDbList")]
|
||||
[ActionPermissionFilter(Permission = "tool:gen:list")]
|
||||
public IActionResult GetListDataBase()
|
||||
{
|
||||
var dbList = _CodeGeneraterService.GetAllDataBases();
|
||||
var defaultDb = dbList.Count > 0 ? dbList[0] : null;
|
||||
return SUCCESS(new { dbList, defaultDb });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///获取所有表根据数据名
|
||||
/// </summary>
|
||||
/// <param name="dbName">数据库名</param>
|
||||
/// <param name="tableName">表名</param>
|
||||
/// <param name="pager">分页信息</param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("getTableList")]
|
||||
[ActionPermissionFilter(Permission = "tool:gen:list")]
|
||||
public IActionResult FindListTable(string dbName, string tableName, PagerInfo pager)
|
||||
{
|
||||
List<DbTableInfo> list = _CodeGeneraterService.GetAllTables(dbName, tableName, pager);
|
||||
var vm = new VMPageResult<DbTableInfo>(list, pager);
|
||||
|
||||
return SUCCESS(vm);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 代码生成器
|
||||
/// </summary>
|
||||
/// <param name="dto">数据传输对象</param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("genCode")]
|
||||
[Log(Title = "代码生成", BusinessType = BusinessType.GENCODE)]
|
||||
[ActionPermissionFilter(Permission = "tool:gen:code")]
|
||||
public IActionResult Generate([FromBody] GenerateDto dto)
|
||||
{
|
||||
if (dto.TableId <= 0)
|
||||
{
|
||||
throw new CustomException(ResultCode.CUSTOM_ERROR, "请求参数为空");
|
||||
}
|
||||
dto.ZipPath = Path.Combine(WebHostEnvironment.WebRootPath, "Generatecode");
|
||||
dto.GenCodePath = Path.Combine(dto.ZipPath, DateTime.Now.ToString("yyyyMMdd"));
|
||||
|
||||
var genTableInfo = GenTableService.GetGenTableInfo(dto.TableId);
|
||||
genTableInfo.Columns = GenTableColumnService.GenTableColumns(dto.TableId);
|
||||
|
||||
dto.GenTable = genTableInfo;
|
||||
//生成代码
|
||||
CodeGeneratorTool.Generate(genTableInfo, dto);
|
||||
//下载文件
|
||||
FileHelper.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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 预览代码
|
||||
/// </summary>
|
||||
/// <param name="tableId"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("preview/{tableId}")]
|
||||
[ActionPermissionFilter(Permission = "tool:gen:preview")]
|
||||
public IActionResult Preview(long tableId)
|
||||
{
|
||||
if (tableId <= 0)
|
||||
{
|
||||
throw new CustomException(ResultCode.CUSTOM_ERROR, "请求参数为空");
|
||||
}
|
||||
var genTableInfo = GenTableService.GetGenTableInfo(tableId);
|
||||
genTableInfo.Columns = GenTableColumnService.GenTableColumns(tableId);
|
||||
GenerateDto dto = new();
|
||||
dto.GenTable = genTableInfo;
|
||||
dto.ZipPath = Path.Combine(WebHostEnvironment.WebRootPath, "Generatecode");
|
||||
dto.GenCodePath = Path.Combine(dto.ZipPath, DateTime.Now.ToString("yyyyMMdd"));
|
||||
dto.IsPreview = 1;
|
||||
dto.GenCodeFiles = new int[] { 1, 2, 3, 4, 5, 6, 7, 8 };
|
||||
//生成代码
|
||||
CodeGeneratorTool.Generate(genTableInfo, dto);
|
||||
|
||||
return SUCCESS(dto.GenCodes);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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
|
||||
{
|
||||
@ -36,8 +36,8 @@ namespace ZR.Admin.WebApi.Controllers.System
|
||||
[HttpGet("list")]
|
||||
public IActionResult List([FromQuery] SysDictType dict, [FromQuery] PagerInfo pagerInfo)
|
||||
{
|
||||
var list = SysDictService.SelectDictTypeList(dict);
|
||||
pagerInfo.TotalNum = list.Count;
|
||||
var list = SysDictService.SelectDictTypeList(dict, pagerInfo);
|
||||
|
||||
var vm = new VMPageResult<SysDictType>(list, pagerInfo);
|
||||
return SUCCESS(vm, TIME_FORMAT_FULL);
|
||||
}
|
||||
@ -51,7 +51,7 @@ namespace ZR.Admin.WebApi.Controllers.System
|
||||
[ActionPermissionFilter(Permission = "system:dict:query")]
|
||||
public IActionResult GetInfo(long dictId = 0)
|
||||
{
|
||||
return SUCCESS(SysDictService.SelectDictTypeById(dictId));
|
||||
return SUCCESS(SysDictService.GetFirst(f => f.DictId == dictId));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@ -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,15 @@
|
||||
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;
|
||||
using Infrastructure;
|
||||
|
||||
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
|
||||
{
|
||||
|
||||
@ -10,13 +10,13 @@ namespace ZR.Admin.WebApi.Extensions
|
||||
{
|
||||
var types = source.GetType();
|
||||
|
||||
var worker = new IdWorker(1, 1);
|
||||
if (types.GetProperty("ID") != null)
|
||||
{
|
||||
long id = worker.NextId();
|
||||
//var worker = new IdWorker(1, 1);
|
||||
//if (types.GetProperty("ID") != null)
|
||||
//{
|
||||
// long id = worker.NextId();
|
||||
|
||||
types.GetProperty("ID").SetValue(source, id.ToString(), null);
|
||||
}
|
||||
// types.GetProperty("ID").SetValue(source, id.ToString(), null);
|
||||
//}
|
||||
|
||||
if (types.GetProperty("CreateTime") != null)
|
||||
{
|
||||
@ -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();
|
||||
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("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("UpdateID") != null)
|
||||
// {
|
||||
// types.GetProperty("UpdateID").SetValue(source, userSession.UserID, 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);
|
||||
}
|
||||
|
||||
// if (types.GetProperty("UpdateName") != null)
|
||||
// {
|
||||
// types.GetProperty("UpdateName").SetValue(source, userSession.UserName, 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
|
||||
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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>
|
||||
@ -32,6 +37,7 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\ZR.CodeGenerator\ZR.CodeGenerator.csproj" />
|
||||
<ProjectReference Include="..\ZR.Service\ZR.Service.csproj" />
|
||||
<ProjectReference Include="..\ZR.Tasks\ZR.Tasks.csproj" />
|
||||
</ItemGroup>
|
||||
@ -52,27 +58,49 @@
|
||||
<None Update="ip2region.db">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Template\Controller.tt">
|
||||
<Generator>TextTemplatingFileGenerator</Generator>
|
||||
<LastGenOutput>Controller.cs</LastGenOutput>
|
||||
<None Update="Template\ControllersTemplate.txt">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Template\InputDtoTemplate.txt">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Template\IServiceTemplate.txt">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Template\ModelTemplate.txt">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Template\RepositoryTemplate.txt">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Template\ServiceTemplate.txt">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Template\VueJsTemplate.txt">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Template\VueTemplate.txt">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Controllers\business\" />
|
||||
<Folder Include="wwwroot\" />
|
||||
<Folder Include="wwwroot\Generatecode\" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Resource Include="Template\RepositoryTemplate.txt" />
|
||||
<Resource Include="Template\ServiceTemplate.txt">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</Resource>
|
||||
<Resource Include="Template\VueJsTemplate.txt">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</Resource>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<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,30 +0,0 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft": "Warning",
|
||||
"Microsoft.Hosting.Lifetime": "Information"
|
||||
}
|
||||
},
|
||||
"appName": "ZR Admin System",
|
||||
"ConnectionStrings": {
|
||||
"Conn_Admin": "server=127.0.0.1;database=admin;user=zr;pwd=abc"
|
||||
},
|
||||
"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,
|
||||
"Upload": {
|
||||
"UploadDirectory": "/",
|
||||
"UploadUrl": "http://localhost:8888"
|
||||
},
|
||||
"ALYUN_OCS": {
|
||||
"REGIONID": "cn-hangzhou",
|
||||
"KEY": "XX",
|
||||
"SECRET": "XX"
|
||||
}
|
||||
}
|
||||
@ -1,30 +0,0 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft": "Warning",
|
||||
"Microsoft.Hosting.Lifetime": "Information"
|
||||
}
|
||||
},
|
||||
"appName": "ZR Admin system",
|
||||
"ConnectionStrings": {
|
||||
"Conn_Admin": "server=127.0.0.1;database=admin;user=zr;pwd=abc"
|
||||
},
|
||||
"urls": "http://localhost:8888",
|
||||
"sysConfig": {
|
||||
"DBCommandTimeout": 10,
|
||||
"cors": "http://localhost:8887"
|
||||
},
|
||||
"DemoMode": false, //ÊÇ·ñÑÝʾģʽ
|
||||
"DbKey": "",
|
||||
"DbType": 0, //MySql = 0, SqlServer = 1, Sqlite = 2, Oracle = 3, PostgreSQL = 4,
|
||||
"Upload": {
|
||||
"UploadDirectory": "/",
|
||||
"UploadUrl": "http://localhost:8888"
|
||||
},
|
||||
"ALYUN_OCS": {
|
||||
"REGIONID": "cn-hangzhou",
|
||||
"KEY": "XX",
|
||||
"SECRET": "XX"
|
||||
}
|
||||
}
|
||||
@ -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_" //"表前缀(生成类名不会包含表前缀,多个用逗号分隔)",
|
||||
}
|
||||
}
|
||||
|
||||
137
ZR.Admin.WebApi/wwwroot/CodeGenTemplate/ControllersTemplate.txt
Normal file
137
ZR.Admin.WebApi/wwwroot/CodeGenTemplate/ControllersTemplate.txt
Normal file
@ -0,0 +1,137 @@
|
||||
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>
|
||||
/// {FunctionName}Controller
|
||||
///
|
||||
/// @author {Author}
|
||||
/// @date {DateTime}
|
||||
/// </summary>
|
||||
[Verify]
|
||||
[Route("{ModuleName}/{ModelName}")]
|
||||
public class {ModelName}Controller: BaseController
|
||||
{
|
||||
/// <summary>
|
||||
/// {FunctionName}接口
|
||||
/// </summary>
|
||||
private readonly I{ModelName}Service _{ModelName}Service;
|
||||
|
||||
public {ModelName}Controller(I{ModelName}Service {ModelName}Service)
|
||||
{
|
||||
_{ModelName}Service = {ModelName}Service;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查询{FunctionName}列表
|
||||
/// </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>
|
||||
/// 查询{FunctionName}详情
|
||||
/// </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>
|
||||
/// 添加{FunctionName}
|
||||
/// </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>
|
||||
/// 更新{FunctionName}
|
||||
/// </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>
|
||||
/// 删除{FunctionName}
|
||||
/// </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);
|
||||
}
|
||||
}
|
||||
}
|
||||
15
ZR.Admin.WebApi/wwwroot/CodeGenTemplate/IServiceTemplate.txt
Normal file
15
ZR.Admin.WebApi/wwwroot/CodeGenTemplate/IServiceTemplate.txt
Normal file
@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using {ModelsNamespace}.Models;
|
||||
|
||||
namespace {IServicsNamespace}.Business
|
||||
{
|
||||
/// <summary>
|
||||
/// {FunctionName}service接口
|
||||
///
|
||||
/// @author {Author}
|
||||
/// @date {DateTime}
|
||||
/// </summary>
|
||||
public interface I{ModelTypeName}Service: IBaseService<{ModelTypeName}>
|
||||
{
|
||||
}
|
||||
}
|
||||
25
ZR.Admin.WebApi/wwwroot/CodeGenTemplate/InputDtoTemplate.txt
Normal file
25
ZR.Admin.WebApi/wwwroot/CodeGenTemplate/InputDtoTemplate.txt
Normal file
@ -0,0 +1,25 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using {ModelsNamespace}.Dto;
|
||||
using {ModelsNamespace}.Models;
|
||||
|
||||
namespace {DtosNamespace}.Dto
|
||||
{
|
||||
/// <summary>
|
||||
/// {FunctionName}输入对象模型
|
||||
/// </summary>
|
||||
public class {ModelTypeName}Dto
|
||||
{
|
||||
{PropertyName}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// {FunctionName}查询对象模型
|
||||
/// </summary>
|
||||
public class {ModelTypeName}QueryDto: PagerInfo
|
||||
{
|
||||
{QueryProperty}
|
||||
public DateTime? BeginTime { get; set; }
|
||||
public DateTime? EndTime { get; set; }
|
||||
}
|
||||
}
|
||||
17
ZR.Admin.WebApi/wwwroot/CodeGenTemplate/ModelTemplate.txt
Normal file
17
ZR.Admin.WebApi/wwwroot/CodeGenTemplate/ModelTemplate.txt
Normal file
@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace {ModelsNamespace}.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// {FunctionName},数据实体对象
|
||||
///
|
||||
/// @author {Author}
|
||||
/// @date {DateTime}
|
||||
/// </summary>
|
||||
[SqlSugar.SugarTable("{TableName}")]
|
||||
public class {ModelTypeName}
|
||||
{
|
||||
{PropertyName}
|
||||
}
|
||||
}
|
||||
23
ZR.Admin.WebApi/wwwroot/CodeGenTemplate/MySqlTemplate.txt
Normal file
23
ZR.Admin.WebApi/wwwroot/CodeGenTemplate/MySqlTemplate.txt
Normal file
@ -0,0 +1,23 @@
|
||||
-- 菜单
|
||||
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', '#', '', sysdate(), '', NULL, '{ModelTypeDesc}菜单');
|
||||
|
||||
-- 按钮父菜单id
|
||||
SELECT @menuId := LAST_INSERT_ID();
|
||||
|
||||
|
||||
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', '', '', sysdate(), '', 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', '', '', sysdate(), '', 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', '', '', sysdate(), '', 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', '', '', sysdate(), '', NULL, NULL);
|
||||
|
||||
|
||||
SELECT * FROM sys_menu WHERE parentId = @menuId;
|
||||
SELECT * FROM sys_menu WHERE menuId = @menuId;
|
||||
@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using Infrastructure.Attribute;
|
||||
using {RepositoriesNamespace}.System;
|
||||
using {ModelsNamespace}.Models;
|
||||
|
||||
namespace {RepositoriesNamespace}
|
||||
{
|
||||
/// <summary>
|
||||
/// {FunctionName}仓储接口的实现
|
||||
///
|
||||
/// @author {Author}
|
||||
/// @date {DateTime}
|
||||
/// </summary>
|
||||
[AppService(ServiceLifetime = LifeTime.Transient)]
|
||||
public class {ModelTypeName}Repository : BaseRepository
|
||||
{
|
||||
#region 业务逻辑代码
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
34
ZR.Admin.WebApi/wwwroot/CodeGenTemplate/ServiceTemplate.txt
Normal file
34
ZR.Admin.WebApi/wwwroot/CodeGenTemplate/ServiceTemplate.txt
Normal file
@ -0,0 +1,34 @@
|
||||
using Infrastructure;
|
||||
using Infrastructure.Attribute;
|
||||
using Infrastructure.Extensions;
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using ZR.Common;
|
||||
using {ModelsNamespace}.Models;
|
||||
using {IRepositoriesNamespace};
|
||||
|
||||
namespace {ServicesNamespace}.Business
|
||||
{
|
||||
/// <summary>
|
||||
/// {FunctionName}Service业务层处理
|
||||
///
|
||||
/// @author {Author}
|
||||
/// @date {DateTime}
|
||||
/// </summary>
|
||||
[AppService(ServiceType = typeof(I{ModelTypeName}Service), ServiceLifetime = LifeTime.Transient)]
|
||||
public class {ModelTypeName}Service: BaseService<{ModelTypeName}>, I{ModelTypeName}Service
|
||||
{
|
||||
private readonly {ModelTypeName}Repository _repository;
|
||||
public {ModelTypeName}Service({ModelTypeName}Repository repository)
|
||||
{
|
||||
_repository = repository;
|
||||
}
|
||||
|
||||
#region 业务逻辑代码
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
23
ZR.Admin.WebApi/wwwroot/CodeGenTemplate/SqlTemplate.txt
Normal file
23
ZR.Admin.WebApi/wwwroot/CodeGenTemplate/SqlTemplate.txt
Normal file
@ -0,0 +1,23 @@
|
||||
-- 菜单
|
||||
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);
|
||||
|
||||
GO
|
||||
SELECT * FROM sys_menu WHERE parentId = @menuId;
|
||||
SELECT * FROM sys_menu WHERE menuId = @menuId;
|
||||
59
ZR.Admin.WebApi/wwwroot/CodeGenTemplate/VueJsTemplate.txt
Normal file
59
ZR.Admin.WebApi/wwwroot/CodeGenTemplate/VueJsTemplate.txt
Normal file
@ -0,0 +1,59 @@
|
||||
import request from '@/utils/request'
|
||||
|
||||
/**
|
||||
* {FunctionName}分页查询
|
||||
* @param {查询条件} data
|
||||
*/
|
||||
export function list{ModelTypeName}(query) {
|
||||
return request({
|
||||
url: '{ModuleName}/{ModelTypeName}/list',
|
||||
method: 'get',
|
||||
params: query,
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增{FunctionName}
|
||||
* @param data
|
||||
*/
|
||||
export function add{ModelTypeName}(data) {
|
||||
return request({
|
||||
url: '{ModuleName}/{ModelTypeName}',
|
||||
method: 'post',
|
||||
data: data,
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改{FunctionName}
|
||||
* @param data
|
||||
*/
|
||||
export function update{ModelTypeName}(data) {
|
||||
return request({
|
||||
url: '{ModuleName}/{ModelTypeName}',
|
||||
method: 'PUT',
|
||||
data: data,
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取{FunctionName}详情
|
||||
* @param {Id} {ModelTypeDesc}Id
|
||||
*/
|
||||
export function get{ModelTypeName}(id) {
|
||||
return request({
|
||||
url: '{ModuleName}/{ModelTypeName}/' + id,
|
||||
method: 'get'
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
* @param {主键} pid
|
||||
*/
|
||||
export function del{ModelTypeName}(pid) {
|
||||
return request({
|
||||
url: '{ModuleName}/{ModelTypeName}/' + pid,
|
||||
method: 'delete'
|
||||
})
|
||||
}
|
||||
210
ZR.Admin.WebApi/wwwroot/CodeGenTemplate/VueTemplate.txt
Normal file
210
ZR.Admin.WebApi/wwwroot/CodeGenTemplate/VueTemplate.txt
Normal file
@ -0,0 +1,210 @@
|
||||
<template>
|
||||
<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>
|
||||
{vueQueryFormHtml}
|
||||
<el-row class="mb8" style="text-align:center">
|
||||
<el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
|
||||
<el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
|
||||
</el-row>
|
||||
</el-form>
|
||||
|
||||
<!-- 工具区域 -->
|
||||
<el-row :gutter="10" class="mb8">
|
||||
<el-col :span="1.5">
|
||||
<el-button type="primary" v-hasPermi="['{Permission}:add']" plain icon="el-icon-plus" size="mini" @click="handleAdd">新增</el-button>
|
||||
</el-col>
|
||||
<el-col :span="1.5">
|
||||
<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" :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>
|
||||
|
||||
<!-- 数据区域 -->
|
||||
<el-table :data="dataList" ref="table" border @selection-change="handleSelectionChange">
|
||||
<el-table-column type="selection" width="50" />
|
||||
{VueViewListContent}
|
||||
<el-table-column label="操作" align="center" width="200">
|
||||
<template slot-scope="scope">
|
||||
<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>
|
||||
<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" >
|
||||
<el-form ref="form" :model="form" :rules="rules" :label-width="formLabelWidth">
|
||||
{VueViewFormContent}
|
||||
</el-form>
|
||||
<div slot="footer" class="dialog-footer" v-if="btnSubmitVisible">
|
||||
<el-button @click="cancel">取 消</el-button>
|
||||
<el-button type="primary" @click="submitForm">确 定</el-button>
|
||||
</div>
|
||||
</el-dialog>
|
||||
|
||||
</div>
|
||||
</template>
|
||||
<script>
|
||||
import {
|
||||
list{ModelTypeName},
|
||||
add{ModelTypeName},
|
||||
del{ModelTypeName},
|
||||
update{ModelTypeName},
|
||||
get{ModelTypeName}
|
||||
} from '@/api/{fileClassName}.js';
|
||||
|
||||
export default {
|
||||
name: '{ModelTypeName}',
|
||||
data() {
|
||||
return {
|
||||
labelWidth: "100px",
|
||||
formLabelWidth:"100px",
|
||||
// 选中{PrimaryKey}数组
|
||||
ids: [],
|
||||
// 非单个禁用
|
||||
single: true,
|
||||
// 非多个禁用
|
||||
multiple: true,
|
||||
// 遮罩层
|
||||
loading: true,
|
||||
// 显示搜索条件
|
||||
showSearch: true,
|
||||
// 查询参数
|
||||
queryParams: {},
|
||||
// 弹出层标题
|
||||
title: "",
|
||||
// 是否显示弹出层
|
||||
open: false,
|
||||
// 表单参数
|
||||
form: {},
|
||||
// 时间范围数组
|
||||
timeRange: [],
|
||||
{VueDataContent}
|
||||
// 数据列表
|
||||
dataList: [],
|
||||
// 总记录数
|
||||
total: 0,
|
||||
// 提交按钮是否显示
|
||||
btnSubmitVisible: true,
|
||||
// 表单校验
|
||||
rules: {
|
||||
{VueViewEditFormRuleContent}
|
||||
},
|
||||
};
|
||||
},
|
||||
mounted() {
|
||||
// 列表数据查询
|
||||
this.getList();
|
||||
|
||||
{MountedMethod}
|
||||
},
|
||||
methods: {
|
||||
// 查询数据
|
||||
getList() {
|
||||
console.log(JSON.stringify(this.queryParams));
|
||||
list{ModelTypeName}(this.addDateRange(this.queryParams, this.timeRange)).then(res => {
|
||||
if (res.code == 200) {
|
||||
this.dataList = res.data.result;
|
||||
this.total = res.data.totalCount;
|
||||
}
|
||||
})
|
||||
},
|
||||
// 取消按钮
|
||||
cancel() {
|
||||
this.open = false;
|
||||
this.reset();
|
||||
},
|
||||
// 重置数据表单
|
||||
reset() {
|
||||
this.form = {
|
||||
{VueViewFormResetHtml}
|
||||
//TODO 根据实际内容调整
|
||||
};
|
||||
this.resetForm("form");
|
||||
},
|
||||
/** 重置查询操作 */
|
||||
resetQuery() {
|
||||
this.timeRange = [];
|
||||
this.resetForm("queryForm");
|
||||
this.queryParams = {
|
||||
pageNum: 1,
|
||||
pageSize: 20,
|
||||
//TODO 重置字段
|
||||
};
|
||||
this.handleQuery();
|
||||
},
|
||||
// 多选框选中数据
|
||||
handleSelectionChange(selection) {
|
||||
this.ids = selection.map((item) => item.{PrimaryKey});
|
||||
this.single = selection.length!=1
|
||||
this.multiple = !selection.length;
|
||||
},
|
||||
/** 搜索按钮操作 */
|
||||
handleQuery() {
|
||||
this.getList();
|
||||
},
|
||||
/** 新增按钮操作 */
|
||||
handleAdd() {
|
||||
this.reset();
|
||||
this.open = true;
|
||||
this.title = "添加";
|
||||
},
|
||||
/** 删除按钮操作 */
|
||||
handleDelete(row) {
|
||||
const {PrimaryKey}s = row.{PrimaryKey} || this.ids;
|
||||
del{ModelTypeName}({PrimaryKey}s.toString()).then((res) => {
|
||||
this.msgSuccess("删除成功");
|
||||
this.handleQuery();
|
||||
});
|
||||
},
|
||||
/** 修改按钮操作 */
|
||||
handleUpdate(row) {
|
||||
this.reset();
|
||||
const {PrimaryKey} = row.{PrimaryKey} || this.ids;
|
||||
get{ModelTypeName}({PrimaryKey}).then((res) => {
|
||||
if(res.code == 200){
|
||||
this.form = res.data;
|
||||
this.open = true;
|
||||
this.title = "修改数据";
|
||||
}
|
||||
});
|
||||
},
|
||||
beforeFileUpload(file) { },
|
||||
{vueJsMethod}
|
||||
/** 提交按钮 */
|
||||
submitForm: function () {
|
||||
this.$refs["form"].validate((valid) => {
|
||||
if (valid) {
|
||||
console.log(JSON.stringify(this.form));
|
||||
|
||||
if (this.form.{PrimaryKey} != undefined || this.title === '修改数据') {
|
||||
update{ModelTypeName}(this.form).then((res) => {
|
||||
this.msgSuccess("修改成功");
|
||||
this.open = false;
|
||||
this.getList();
|
||||
});
|
||||
} else {
|
||||
add{ModelTypeName}(this.form).then((res) => {
|
||||
this.msgSuccess("新增成功");
|
||||
this.open = false;
|
||||
this.getList();
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
},
|
||||
};
|
||||
</script>
|
||||
<style scoped>
|
||||
.table-td-thumb {
|
||||
width: 80px;
|
||||
}
|
||||
</style>
|
||||
54
ZR.CodeGenerator/CodeGenerateOption.cs
Normal file
54
ZR.CodeGenerator/CodeGenerateOption.cs
Normal file
@ -0,0 +1,54 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ZR.CodeGenerator
|
||||
{
|
||||
public class CodeGenerateOption
|
||||
{
|
||||
/// <summary>
|
||||
/// 项目命名空间
|
||||
/// </summary>
|
||||
public string BaseNamespace { get; set; }
|
||||
/// <summary>
|
||||
/// 数据实体命名空间
|
||||
/// </summary>
|
||||
public string ModelsNamespace { get; set; }
|
||||
/// <summary>
|
||||
/// 输入输出数据实体名称空间
|
||||
/// </summary>
|
||||
public string DtosNamespace { get; set; }
|
||||
/// <summary>
|
||||
/// 仓储接口命名空间
|
||||
/// </summary>
|
||||
public string IRepositoriesNamespace { get; set; }
|
||||
/// <summary>
|
||||
/// 仓储实现名称空间
|
||||
/// </summary>
|
||||
public string RepositoriesNamespace { get; set; }
|
||||
/// <summary>
|
||||
/// 服务接口命名空间
|
||||
/// </summary>
|
||||
public string IServicsNamespace { get; set; }
|
||||
/// <summary>
|
||||
/// 服务接口实现命名空间
|
||||
/// </summary>
|
||||
public string ServicesNamespace { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Api控制器命名空间
|
||||
/// </summary>
|
||||
public string ApiControllerNamespace { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 去掉的表头字符
|
||||
/// </summary>
|
||||
public string ReplaceTableNameStr { get; set; }
|
||||
/// <summary>
|
||||
/// 要生数据的表,用“,”分割
|
||||
/// </summary>
|
||||
//public string TableList { get; set; }
|
||||
}
|
||||
}
|
||||
243
ZR.CodeGenerator/CodeGenerateTemplate.cs
Normal file
243
ZR.CodeGenerator/CodeGenerateTemplate.cs
Normal file
@ -0,0 +1,243 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using ZR.Model.System.Generate;
|
||||
|
||||
namespace ZR.CodeGenerator
|
||||
{
|
||||
/// <summary>
|
||||
/// 代码生成模板
|
||||
/// </summary>
|
||||
public class CodeGenerateTemplate
|
||||
{
|
||||
/// <summary>
|
||||
/// 生成vuejs模板,目前只有上传文件方法
|
||||
/// </summary>
|
||||
/// <param name="dbFieldInfo"></param>
|
||||
/// <returns></returns>
|
||||
public static string GetVueJsMethod(GenTableColumn dbFieldInfo)
|
||||
{
|
||||
string columnName = dbFieldInfo.ColumnName;
|
||||
var sb = new StringBuilder();
|
||||
|
||||
if (dbFieldInfo.HtmlType.Equals(GenConstants.HTML_IMAGE_UPLOAD))
|
||||
{
|
||||
sb.AppendLine($" //文件上传成功方法");
|
||||
sb.AppendLine($" handleUpload{dbFieldInfo.CsharpField}Success(res, file) {{");
|
||||
sb.AppendLine($" this.form.{columnName} = URL.createObjectURL(file.raw);");
|
||||
sb.AppendLine($" // this.$refs.upload.clearFiles();");
|
||||
sb.AppendLine($" }},");
|
||||
}
|
||||
//有下拉框选项初列表查询数据
|
||||
if ((dbFieldInfo.HtmlType == GenConstants.HTML_SELECT || dbFieldInfo.HtmlType == GenConstants.HTML_RADIO) && !string.IsNullOrEmpty(dbFieldInfo.DictType))
|
||||
{
|
||||
sb.AppendLine(@$" // {dbFieldInfo.ColumnComment}字典翻译");
|
||||
sb.AppendLine($" {columnName}Format(row, column) {{");
|
||||
sb.AppendLine(@$" return this.selectDictLabel(this.{columnName}Options, row.{columnName});");
|
||||
sb.AppendLine(@" },");
|
||||
|
||||
}
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
//rules
|
||||
public static string GetFormRules(GenTableColumn dbFieldInfo)
|
||||
{
|
||||
StringBuilder sbRule = new StringBuilder();
|
||||
//Rule 规则验证
|
||||
if (!dbFieldInfo.IsPk && !dbFieldInfo.IsIncrement && dbFieldInfo.IsRequired)
|
||||
{
|
||||
sbRule.AppendLine($" {dbFieldInfo.ColumnName}: [{{ required: true, message: '请输入{dbFieldInfo.ColumnComment}', trigger: \"blur\"}}],");
|
||||
}
|
||||
else if (CodeGeneratorTool.IsNumber(dbFieldInfo.ColumnType) && dbFieldInfo.IsRequired)
|
||||
{
|
||||
sbRule.AppendLine($" {dbFieldInfo.ColumnName}: [{{ type: 'number', message: '{dbFieldInfo.ColumnName}必须为数字值', trigger: \"blur\"}}],");
|
||||
}
|
||||
return sbRule.ToString();
|
||||
}
|
||||
|
||||
//model 属性
|
||||
public static string GetModelTemplate(GenTableColumn dbFieldInfo)
|
||||
{
|
||||
StringBuilder sbModel = new StringBuilder();
|
||||
sbModel.AppendLine(" /// <summary>");
|
||||
sbModel.AppendLine($" /// 描述 :{dbFieldInfo.ColumnComment}");
|
||||
sbModel.AppendLine($" /// 空值 :{!dbFieldInfo.IsRequired}");
|
||||
sbModel.AppendLine(" /// </summary>");
|
||||
if (dbFieldInfo.IsPk || dbFieldInfo.IsIncrement)
|
||||
{
|
||||
sbModel.AppendLine($" [SqlSugar.SugarColumn(IsPrimaryKey = {dbFieldInfo.IsPk.ToString().ToLower()}, IsIdentity = {dbFieldInfo.IsIncrement.ToString().ToLower()})]");
|
||||
}
|
||||
sbModel.AppendLine($" public {dbFieldInfo.CsharpType}{(GetModelRequired(dbFieldInfo))} {dbFieldInfo.CsharpField} {{ get; set; }}");
|
||||
return sbModel.ToString();
|
||||
}
|
||||
public static string GetModelRequired(GenTableColumn dbFieldInfo)
|
||||
{
|
||||
string str = "";
|
||||
if (!dbFieldInfo.IsRequired && (CodeGeneratorTool.IsNumber(dbFieldInfo.ColumnType) || dbFieldInfo.CsharpType == "DateTime"))
|
||||
{
|
||||
str = "?";
|
||||
}
|
||||
|
||||
return str;
|
||||
}
|
||||
//DTO model
|
||||
public static string GetDtoProperty(GenTableColumn dbFieldInfo)
|
||||
{
|
||||
string InputDtoContent = "";
|
||||
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.ToLower().Contains(dbFieldInfo.CsharpField.ToLower())))
|
||||
{
|
||||
QueryDtoContent += $" public {dbFieldInfo.CsharpType} {dbFieldInfo.CsharpField} {{ get; set; }}\r\n";
|
||||
}
|
||||
|
||||
return QueryDtoContent;
|
||||
}
|
||||
|
||||
//form-item
|
||||
public static string GetVueViewFormContent(GenTableColumn dbFieldInfo)
|
||||
{
|
||||
string columnName = dbFieldInfo.ColumnName;
|
||||
string labelName = CodeGeneratorTool.GetLabelName(dbFieldInfo.ColumnComment, columnName);
|
||||
string labelDisabled = dbFieldInfo.IsPk ? ":disabled=\"true\"" : "";
|
||||
string placeHolder = dbFieldInfo.IsIncrement ? "" : $"请输入{labelName}";
|
||||
StringBuilder sb = new StringBuilder();
|
||||
if (GenConstants.inputDtoNoField.Any(f => f.ToLower().Contains(dbFieldInfo.CsharpField.ToLower())))
|
||||
{
|
||||
return sb.ToString();
|
||||
}
|
||||
if (!dbFieldInfo.IsInsert || !dbFieldInfo.IsEdit)
|
||||
{
|
||||
return sb.ToString();
|
||||
}
|
||||
if (dbFieldInfo.HtmlType == GenConstants.HTML_DATETIME)
|
||||
{
|
||||
//时间
|
||||
sb.AppendLine($" <el-form-item label=\"{labelName}\" :label-width=\"labelWidth\" prop=\"{columnName}\">");
|
||||
sb.AppendLine($" <el-date-picker v-model=\"form.{columnName}\" type=\"datetime\" placeholder=\"选择日期时间\" default-time=\"12:00:00\"> </el-date-picker>");
|
||||
sb.AppendLine(" </el-form-item>");
|
||||
}
|
||||
else if (dbFieldInfo.HtmlType == GenConstants.HTML_IMAGE_UPLOAD)
|
||||
{
|
||||
//图片
|
||||
sb.AppendLine($" <el-form-item label=\"{labelName}\" :label-width=\"labelWidth\" prop=\"{columnName}\">");
|
||||
sb.AppendLine($" <el-upload class=\"avatar-uploader\" name=\"file\" action=\"/api/upload/saveFile/\" :show-file-list=\"false\" :on-success=\"handleUpload{dbFieldInfo.CsharpField}Success\" :before-upload=\"beforeFileUpload\">");
|
||||
sb.AppendLine($" <img v-if=\"form.{columnName}\" :src=\"form.{columnName}\" class=\"icon\">");
|
||||
sb.AppendLine(" <i v-else class=\"el-icon-plus uploader-icon\"></i>");
|
||||
sb.AppendLine(" </el-upload>");
|
||||
sb.AppendLine($" <el-input v-model=\"form.{columnName}\" placeholder=\"请上传文件或手动输入文件地址\"></el-input>");
|
||||
sb.AppendLine(" </el-form-item>");
|
||||
}
|
||||
else if (dbFieldInfo.HtmlType == GenConstants.HTML_RADIO)
|
||||
{
|
||||
sb.AppendLine($" <el-form-item label=\"{labelName}\" :label-width=\"labelWidth\" prop=\"{columnName}\">");
|
||||
sb.AppendLine($" <el-radio-group v-model=\"form.{columnName}\">");
|
||||
sb.AppendLine(" <el-radio :key=\"1\" :label=\"1\">是</el-radio>");
|
||||
sb.AppendLine(" <el-radio :key=\"0\" :label=\"0\">否</el-radio>");
|
||||
sb.AppendLine(" </el-radio-group>");
|
||||
sb.AppendLine(" </el-form-item>");
|
||||
}
|
||||
else if (dbFieldInfo.HtmlType == GenConstants.HTML_TEXTAREA)
|
||||
{
|
||||
sb.AppendLine($" <el-form-item label=\"{ labelName}\" :label-width=\"labelWidth\" prop=\"{columnName}\">");
|
||||
sb.AppendLine($" <el-input type=\"textarea\" v-model=\"form.{columnName}\" placeholder=\"请输入内容\"/>");
|
||||
sb.AppendLine(" </el-form-item>");
|
||||
}
|
||||
else if (dbFieldInfo.HtmlType == GenConstants.HTML_SELECT && !string.IsNullOrEmpty(dbFieldInfo.DictType))
|
||||
{
|
||||
string value = CodeGeneratorTool.IsNumber(dbFieldInfo.CsharpType) ? "parseInt(item.dictValue)" : "item.dictValue";
|
||||
sb.AppendLine($" <el-form-item label=\"{ labelName}\" :label-width=\"labelWidth\" prop=\"{columnName}\">");
|
||||
sb.AppendLine($" <el-select v-model=\"form.{columnName}\">");
|
||||
sb.AppendLine($" <el-option v-for=\"item in {columnName}Options\" :key=\"item.dictValue\" :label=\"item.dictLabel\" :value=\"{value}\"></el-option>");
|
||||
sb.AppendLine(" </el-select>");
|
||||
sb.AppendLine(" </el-form-item>");
|
||||
}
|
||||
else
|
||||
{
|
||||
string inputNumTxt = CodeGeneratorTool.IsNumber(dbFieldInfo.CsharpType) ? ".number" : "";
|
||||
sb.AppendLine($" <el-form-item label=\"{labelName}\" :label-width=\"labelWidth\" prop=\"{CodeGeneratorTool.FirstLowerCase(columnName)}\">");
|
||||
sb.AppendLine($" <el-input v-model{inputNumTxt}=\"form.{CodeGeneratorTool.FirstLowerCase(columnName)}\" placeholder=\"{placeHolder}\" {labelDisabled}/>");
|
||||
sb.AppendLine(" </el-form-item>");
|
||||
}
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查询表单
|
||||
/// </summary>
|
||||
/// <param name="dbFieldInfo"></param>
|
||||
/// <returns></returns>
|
||||
public static string GetQueryFormHtml(GenTableColumn dbFieldInfo)
|
||||
{
|
||||
StringBuilder sb = new();
|
||||
string labelName = CodeGeneratorTool.GetLabelName(dbFieldInfo.ColumnComment, dbFieldInfo.ColumnName);
|
||||
if (!dbFieldInfo.IsQuery || dbFieldInfo.HtmlType == GenConstants.HTML_FILE_UPLOAD) return sb.ToString();
|
||||
if (dbFieldInfo.HtmlType == GenConstants.HTML_DATETIME)
|
||||
{
|
||||
sb.AppendLine(" <el-form-item label=\"时间\">");
|
||||
sb.AppendLine(" <el-date-picker v-model=\"timeRange\" size=\"small\" value-format=\"yyyy-MM-dd\" type=\"daterange\" range-separator=\"-\" start-placeholder=\"开始日期\" end-placeholder=\"结束日期\"></el-date-picker>");
|
||||
sb.AppendLine(" </el-form-item>");
|
||||
}
|
||||
else
|
||||
{
|
||||
string inputNumTxt = CodeGeneratorTool.IsNumber(dbFieldInfo.CsharpType) ? ".number" : "";
|
||||
sb.AppendLine($" <el-form-item label=\"{ labelName}\" :label-width=\"labelWidth\">");
|
||||
sb.AppendLine($" <el-input v-model{inputNumTxt}=\"queryParams.{CodeGeneratorTool.FirstLowerCase(dbFieldInfo.CsharpField)}\"/>");
|
||||
sb.AppendLine(" </el-form-item>");
|
||||
}
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
//table-column
|
||||
public static string GetTableColumn(GenTableColumn dbFieldInfo)
|
||||
{
|
||||
string columnName = dbFieldInfo.ColumnName;
|
||||
string label = CodeGeneratorTool.GetLabelName(dbFieldInfo.ColumnComment, columnName);
|
||||
string showToolTip = dbFieldInfo.CsharpType == "string" ? ":show-overflow-tooltip=\"true\"" : "";
|
||||
string formatter = !string.IsNullOrEmpty(dbFieldInfo.DictType) ? $" :formatter=\"{columnName}Format\"" : "";
|
||||
StringBuilder sb = new StringBuilder();
|
||||
if (dbFieldInfo.IsList && dbFieldInfo.HtmlType.Equals(GenConstants.HTML_IMAGE_UPLOAD))
|
||||
{
|
||||
sb.AppendLine($" <el-table-column prop=\"{columnName}\" label=\"图片\">");
|
||||
sb.AppendLine(" <template slot-scope=\"scope\">");
|
||||
sb.AppendLine($" <el-image class=\"table-td-thumb\" :src=\"scope.row.{columnName}\" :preview-src-list=\"[scope.row.{columnName}]\"></el-image>");
|
||||
sb.AppendLine(" </template>");
|
||||
sb.AppendLine(" </el-table-column>");
|
||||
}
|
||||
//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)
|
||||
{
|
||||
sb.AppendLine($" <el-table-column prop=\"{columnName}\" label=\"{label}\" align=\"center\" {showToolTip}{formatter}/>");
|
||||
}
|
||||
return sb.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
551
ZR.CodeGenerator/CodeGeneratorTool.cs
Normal file
551
ZR.CodeGenerator/CodeGeneratorTool.cs
Normal file
@ -0,0 +1,551 @@
|
||||
using Infrastructure;
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using ZR.CodeGenerator.Model;
|
||||
using ZR.Model.System.Generate;
|
||||
|
||||
namespace ZR.CodeGenerator
|
||||
{
|
||||
/// <summary>
|
||||
/// 代码生成器。
|
||||
/// </remarks>
|
||||
/// </summary>
|
||||
public class CodeGeneratorTool
|
||||
{
|
||||
/// <summary>
|
||||
/// 代码生成器配置
|
||||
/// </summary>
|
||||
private static CodeGenerateOption _option = new CodeGenerateOption();
|
||||
|
||||
/// <summary>
|
||||
/// 代码生成器入口方法
|
||||
/// </summary>
|
||||
/// <param name="dbTableInfo"></param>
|
||||
/// <param name="dto"></param>
|
||||
public static void Generate(GenTable dbTableInfo, GenerateDto dto)
|
||||
{
|
||||
_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";
|
||||
|
||||
GenerateSingle(dbTableInfo?.Columns, dbTableInfo, dto);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 单表生成代码
|
||||
/// </summary>
|
||||
/// <param name="listField">表字段集合</param>
|
||||
/// <param name="tableInfo">表信息</param>
|
||||
/// <param name="dto"></param>
|
||||
public static void GenerateSingle(List<GenTableColumn> listField, GenTable tableInfo, GenerateDto dto)
|
||||
{
|
||||
string PKName = "id";
|
||||
string PKType = "int";
|
||||
ReplaceDto replaceDto = new();
|
||||
replaceDto.ModelTypeName = tableInfo.ClassName;//表名对应C# 实体类名
|
||||
replaceDto.TableName = tableInfo.TableName;//表名
|
||||
replaceDto.TableDesc = tableInfo.TableComment;//表说明描述
|
||||
replaceDto.Permission = $"{tableInfo.ModuleName}:{tableInfo.ClassName.ToLower()}";//权限
|
||||
replaceDto.ViewsFileName = FirstLowerCase(replaceDto.ModelTypeName);
|
||||
replaceDto.Author = tableInfo.FunctionAuthor;
|
||||
|
||||
StringBuilder sb1 = new StringBuilder();
|
||||
StringBuilder sb2 = new StringBuilder();
|
||||
|
||||
//循环表字段信息
|
||||
foreach (GenTableColumn dbFieldInfo in listField)
|
||||
{
|
||||
string columnName = dbFieldInfo.ColumnName;
|
||||
|
||||
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))
|
||||
{
|
||||
sb1.AppendLine($" // {dbFieldInfo.ColumnComment}选项列表");
|
||||
sb1.AppendLine($" {FirstLowerCase(dbFieldInfo.CsharpField)}Options: [],");
|
||||
|
||||
sb2.AppendLine($" this.getDicts(\"{dbFieldInfo.DictType}\").then((response) => {{");
|
||||
sb2.AppendLine($" this.{FirstLowerCase(dbFieldInfo.CsharpField)}Options = response.data;");
|
||||
sb2.AppendLine(" })");
|
||||
}
|
||||
|
||||
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.VueDataContent = sb1.ToString();
|
||||
replaceDto.MountedMethod = sb2.ToString();
|
||||
|
||||
replaceDto.PKName = PKName;
|
||||
replaceDto.PKType = PKType;
|
||||
|
||||
if (dto.GenCodeFiles.Contains(1))
|
||||
{
|
||||
GenerateModels(replaceDto, dto);
|
||||
}
|
||||
if (dto.GenCodeFiles.Contains(2))
|
||||
{
|
||||
GenerateInputDto(replaceDto, dto);
|
||||
}
|
||||
if (dto.GenCodeFiles.Contains(3))
|
||||
{
|
||||
GenerateRepository(replaceDto, dto);
|
||||
}
|
||||
if (dto.GenCodeFiles.Contains(4))
|
||||
{
|
||||
GenerateIService(replaceDto, dto);
|
||||
GenerateService(replaceDto, dto);
|
||||
}
|
||||
if (dto.GenCodeFiles.Contains(5))
|
||||
{
|
||||
GenerateControllers(replaceDto, dto);
|
||||
}
|
||||
if (dto.GenCodeFiles.Contains(6))
|
||||
{
|
||||
GenerateVueViews(replaceDto, dto);
|
||||
}
|
||||
if (dto.GenCodeFiles.Contains(7))
|
||||
{
|
||||
GenerateVueJs(replaceDto, dto);
|
||||
}
|
||||
if (dto.GenCodeFiles.Contains(8))
|
||||
{
|
||||
GenerateSql(replaceDto, dto);
|
||||
}
|
||||
if (dto.IsPreview == 1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
foreach (var item in dto.GenCodes)
|
||||
{
|
||||
FileHelper.WriteAndSave(item.Path, item.Content);
|
||||
}
|
||||
}
|
||||
|
||||
#region 生成Model
|
||||
|
||||
/// <summary>
|
||||
/// 生成实体类Model
|
||||
/// </summary>
|
||||
/// <param name="generateDto"></param>
|
||||
/// <param name="replaceDto">替换实体</param>
|
||||
private static void GenerateModels(ReplaceDto replaceDto, GenerateDto generateDto)
|
||||
{
|
||||
// ../ZR.Model/Models/User.cs
|
||||
var fullPath = Path.Combine(generateDto.GenCodePath, _option.ModelsNamespace, "Models", replaceDto.ModelTypeName + ".cs");
|
||||
|
||||
if (File.Exists(fullPath) && !generateDto.Coverd)
|
||||
return;
|
||||
|
||||
var content = FileHelper.ReadTemplate("ModelTemplate.txt")
|
||||
.Replace("{ModelsNamespace}", _option.ModelsNamespace)
|
||||
.Replace("{ModelTypeName}", replaceDto.ModelTypeName)
|
||||
.Replace("{FunctionName}", generateDto.GenTable.FunctionName)
|
||||
.Replace("{KeyTypeName}", replaceDto.PKName)
|
||||
.Replace("{PropertyName}", replaceDto.ModelProperty)
|
||||
.Replace("{TableName}", replaceDto.TableName)
|
||||
.Replace("{Author}", replaceDto.Author)
|
||||
.Replace("{DateTime}", replaceDto.AddTime);
|
||||
|
||||
generateDto.GenCodes.Add(new GenCode(1, "实体类", fullPath, content));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 生成表单提交输入参数Dto
|
||||
/// </summary>
|
||||
/// <param name="generateDto"></param>
|
||||
/// <param name="replaceDto">替换实体</param>
|
||||
private static void GenerateInputDto(ReplaceDto replaceDto, GenerateDto generateDto)
|
||||
{
|
||||
var fullPath = Path.Combine(generateDto.GenCodePath, _option.ModelsNamespace, "Dto", $"{replaceDto.ModelTypeName}Dto.cs");
|
||||
|
||||
if (File.Exists(fullPath) && !generateDto.Coverd)
|
||||
return;
|
||||
|
||||
var content = FileHelper.ReadTemplate("InputDtoTemplate.txt")
|
||||
.Replace("{DtosNamespace}", _option.DtosNamespace)
|
||||
.Replace("{ModelsNamespace}", _option.ModelsNamespace)
|
||||
.Replace("{FunctionName}", generateDto.GenTable.FunctionName)
|
||||
.Replace("{PropertyName}", replaceDto.InputDtoProperty)
|
||||
.Replace("{QueryProperty}", replaceDto.QueryProperty)
|
||||
.Replace("{ModelTypeName}", replaceDto.ModelTypeName)
|
||||
.Replace("{Author}", replaceDto.Author)
|
||||
.Replace("{DateTime}", replaceDto.AddTime);
|
||||
|
||||
generateDto.GenCodes.Add(new GenCode(2, "数据传输实体类", fullPath, content));
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 生成Repository
|
||||
|
||||
/// <summary>
|
||||
/// 生成Repository层代码文件
|
||||
/// </summary>
|
||||
/// <param name="generateDto"></param>
|
||||
/// <param name="replaceDto">替换实体</param>
|
||||
private static void GenerateRepository(ReplaceDto replaceDto, GenerateDto generateDto)
|
||||
{
|
||||
var fullPath = Path.Combine(generateDto.GenCodePath, _option.RepositoriesNamespace, "Repositories", $"{replaceDto.ModelTypeName}Repository.cs");
|
||||
|
||||
if (File.Exists(fullPath) && !generateDto.Coverd)
|
||||
return;
|
||||
|
||||
var content = FileHelper.ReadTemplate("RepositoryTemplate.txt")
|
||||
.Replace("{ModelsNamespace}", _option.ModelsNamespace)
|
||||
.Replace("{RepositoriesNamespace}", _option.RepositoriesNamespace)
|
||||
.Replace("{ModelTypeName}", replaceDto.ModelTypeName)
|
||||
.Replace("{FunctionName}", generateDto.GenTable.FunctionName)
|
||||
.Replace("{TableName}", replaceDto.TableName)
|
||||
.Replace("{Author}", replaceDto.Author)
|
||||
.Replace("{DateTime}", replaceDto.AddTime);
|
||||
|
||||
generateDto.GenCodes.Add(new GenCode(3, "仓储层", fullPath, content));
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 生成Service
|
||||
/// <summary>
|
||||
/// 生成IService文件
|
||||
/// </summary>
|
||||
/// <param name="generateDto"></param>
|
||||
/// <param name="replaceDto">替换实体</param>
|
||||
private static void GenerateIService(ReplaceDto replaceDto, GenerateDto generateDto)
|
||||
{
|
||||
var fullPath = Path.Combine(generateDto.GenCodePath, _option.IServicsNamespace, "Business", "IBusService", $"I{replaceDto.ModelTypeName}Service.cs");
|
||||
|
||||
if (File.Exists(fullPath) && !generateDto.Coverd)
|
||||
return;
|
||||
var content = FileHelper.ReadTemplate("IServiceTemplate.txt")
|
||||
.Replace("{ModelsNamespace}", _option.ModelsNamespace)
|
||||
.Replace("{FunctionName}", generateDto.GenTable.FunctionName)
|
||||
.Replace("{DtosNamespace}", _option.DtosNamespace)
|
||||
.Replace("{IServicsNamespace}", _option.IServicsNamespace)
|
||||
.Replace("{RepositoriesNamespace}", _option.RepositoriesNamespace)
|
||||
.Replace("{ModelTypeName}", replaceDto.ModelTypeName)
|
||||
.Replace("{Author}", replaceDto.Author)
|
||||
.Replace("{DateTime}", replaceDto.AddTime);
|
||||
|
||||
generateDto.GenCodes.Add(new GenCode(4, "接口层", fullPath, content));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 生成Service文件
|
||||
/// </summary>
|
||||
private static void GenerateService(ReplaceDto replaceDto, GenerateDto generateDto)
|
||||
{
|
||||
var fullPath = Path.Combine(generateDto.GenCodePath, _option.ServicesNamespace, "Business", $"{replaceDto.ModelTypeName}Service.cs");
|
||||
|
||||
if (File.Exists(fullPath) && !generateDto.Coverd)
|
||||
return;
|
||||
|
||||
var content = FileHelper.ReadTemplate("ServiceTemplate.txt")
|
||||
.Replace("{IRepositoriesNamespace}", _option.IRepositoriesNamespace)
|
||||
.Replace("{DtosNamespace}", _option.DtosNamespace)
|
||||
.Replace("{IServicsNamespace}", _option.IServicsNamespace)
|
||||
.Replace("{FunctionName}", generateDto.GenTable.FunctionName)
|
||||
.Replace("{ModelsNamespace}", _option.ModelsNamespace)
|
||||
.Replace("{ServicesNamespace}", _option.ServicesNamespace)
|
||||
.Replace("{ModelTypeName}", replaceDto.ModelTypeName)
|
||||
.Replace("{Author}", replaceDto.Author)
|
||||
.Replace("{DateTime}", replaceDto.AddTime);
|
||||
|
||||
generateDto.GenCodes.Add(new GenCode(4, "服务层", fullPath, content));
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 生成Controller
|
||||
/// <summary>
|
||||
/// 生成控制器ApiControllers文件
|
||||
/// </summary>
|
||||
private static void GenerateControllers(ReplaceDto replaceDto, GenerateDto generateDto)
|
||||
{
|
||||
var fullPath = Path.Combine(generateDto.GenCodePath, _option.ApiControllerNamespace, "Controllers", generateDto.GenTable.ModuleName, $"{replaceDto.ModelTypeName}Controller.cs");
|
||||
if (File.Exists(fullPath) && !generateDto.Coverd)
|
||||
return;
|
||||
|
||||
var content = FileHelper.ReadTemplate("ControllersTemplate.txt")
|
||||
.Replace("{ApiControllerNamespace}", _option.ApiControllerNamespace)
|
||||
.Replace("{ServicesNamespace}", _option.ServicesNamespace)
|
||||
.Replace("{ModelsNamespace}", _option.ModelsNamespace)
|
||||
.Replace("{FunctionName}", generateDto.GenTable.FunctionName)
|
||||
.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)
|
||||
.Replace("{Author}", replaceDto.Author)
|
||||
.Replace("{DateTime}", replaceDto.AddTime);
|
||||
|
||||
generateDto.GenCodes.Add(new GenCode(5, "控制器", fullPath, content));
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 生成Vue页面 & api
|
||||
/// <summary>
|
||||
/// 6、生成Vue页面
|
||||
private static void GenerateVueViews(ReplaceDto replaceDto, GenerateDto generateDto)
|
||||
{
|
||||
var fullPath = Path.Combine(generateDto.GenCodePath, "ZR.Vue", "src", "views", generateDto.GenTable.ModuleName, replaceDto.ViewsFileName, "index.vue");
|
||||
|
||||
if (File.Exists(fullPath) && !generateDto.Coverd)
|
||||
return;
|
||||
|
||||
var content = FileHelper.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);//添加、修改表单验证规则
|
||||
|
||||
generateDto.GenCodes.Add(new GenCode(6, "index.vue", fullPath, content));
|
||||
}
|
||||
/// <summary>
|
||||
/// 7、生成vue页面api
|
||||
/// </summary>
|
||||
/// <param name="replaceDto"></param>
|
||||
/// <param name="generateDto"></param>
|
||||
/// <returns></returns>
|
||||
public static void GenerateVueJs(ReplaceDto replaceDto, GenerateDto generateDto)
|
||||
{
|
||||
string fullPath = Path.Combine(generateDto.GenCodePath, "ZR.Vue", "src", "api", replaceDto.ViewsFileName + ".js");
|
||||
|
||||
if (File.Exists(fullPath) && !generateDto.Coverd)
|
||||
return;
|
||||
|
||||
var content = FileHelper.ReadTemplate("VueJsTemplate.txt")
|
||||
.Replace("{ModelTypeName}", replaceDto.ModelTypeName)
|
||||
.Replace("{FunctionName}", generateDto.GenTable.FunctionName)
|
||||
.Replace("{ModuleName}", generateDto.GenTable.ModuleName);
|
||||
|
||||
generateDto.GenCodes.Add(new GenCode(7, "api.js", fullPath, content));
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 8、生成SQL
|
||||
|
||||
public static void GenerateSql(ReplaceDto replaceDto, GenerateDto generateDto)
|
||||
{
|
||||
string fullPath = Path.Combine(generateDto.GenCodePath, replaceDto.ViewsFileName + ".sql");
|
||||
|
||||
if (File.Exists(fullPath) && !generateDto.Coverd)
|
||||
return;
|
||||
var tempName = "";
|
||||
switch (generateDto.DbType)
|
||||
{
|
||||
case 0:
|
||||
tempName = "MySqlTemplate";
|
||||
break;
|
||||
case 1:
|
||||
tempName = "SqlTemplate";
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
var content = FileHelper.ReadTemplate($"{tempName}.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);
|
||||
|
||||
generateDto.GenCodes.Add(new GenCode(8, "sql", fullPath, content));
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 帮助方法
|
||||
|
||||
/// <summary>
|
||||
/// 如果有前缀替换将前缀替换成空,替换下划线"_"为空再将首字母大写
|
||||
/// 表名转换成C#类名
|
||||
/// </summary>
|
||||
/// <param name="tableName"></param>
|
||||
/// <returns></returns>
|
||||
public static string GetClassName(string tableName)
|
||||
{
|
||||
bool autoRemovePre = ConfigUtils.Instance.GetAppConfig(GenConstants.Gen_autoPre, false);
|
||||
string tablePrefix = ConfigUtils.Instance.GetAppConfig<string>(GenConstants.Gen_tablePrefix);
|
||||
|
||||
if (!string.IsNullOrEmpty(tablePrefix) && autoRemovePre)
|
||||
{
|
||||
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], "");
|
||||
}
|
||||
}
|
||||
}
|
||||
return tableName.Substring(0, 1).ToUpper() + tableName[1..].Replace("_", "");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 首字母转小写,输出前端
|
||||
/// </summary>
|
||||
/// <param name="str"></param>
|
||||
/// <returns></returns>
|
||||
public static string FirstLowerCase(string str)
|
||||
{
|
||||
return string.IsNullOrEmpty(str) ? str : str.Substring(0, 1).ToLower() + str[1..];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取前端标签名
|
||||
/// </summary>
|
||||
/// <param name="columnDescription"></param>
|
||||
/// <param name="columnName"></param>
|
||||
/// <returns></returns>
|
||||
public static string GetLabelName(string columnDescription, string columnName)
|
||||
{
|
||||
return string.IsNullOrEmpty(columnDescription) ? columnName : columnDescription;
|
||||
}
|
||||
#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 = 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>
|
||||
/// 获取C# 类型
|
||||
/// </summary>
|
||||
/// <param name="sDatatype"></param>
|
||||
/// <returns></returns>
|
||||
public static string GetCSharpDatatype(string sDatatype)
|
||||
{
|
||||
sDatatype = sDatatype.ToLower();
|
||||
string sTempDatatype = sDatatype switch
|
||||
{
|
||||
"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)));
|
||||
}
|
||||
}
|
||||
}
|
||||
47
ZR.CodeGenerator/DbProvider.cs
Normal file
47
ZR.CodeGenerator/DbProvider.cs
Normal file
@ -0,0 +1,47 @@
|
||||
using Infrastructure;
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ZR.CodeGenerator
|
||||
{
|
||||
/// <summary>
|
||||
/// 代码生成数据库连接
|
||||
/// </summary>
|
||||
public class DbProvider
|
||||
{
|
||||
protected static SqlSugarScope CodeDb;
|
||||
|
||||
/// <summary>
|
||||
/// 获取动态连接字符串
|
||||
/// </summary>
|
||||
/// <param name="dbName">数据库名</param>
|
||||
/// <returns></returns>
|
||||
public SqlSugarScope GetSugarDbContext(string dbName = "")
|
||||
{
|
||||
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<int>(OptionsSetting.ConnDbType);
|
||||
}
|
||||
var db = new SqlSugarScope(new List<ConnectionConfig>()
|
||||
{
|
||||
new ConnectionConfig(){
|
||||
ConnectionString = connStr,
|
||||
DbType = (DbType)dbType,
|
||||
IsAutoCloseConnection = true,//开启自动释放模式和EF原理一样
|
||||
InitKeyType = InitKeyType.Attribute,//从特性读取主键和自增列信息
|
||||
},
|
||||
});
|
||||
|
||||
CodeDb = db;
|
||||
return db;
|
||||
}
|
||||
}
|
||||
}
|
||||
184
ZR.CodeGenerator/FileHelper.cs
Normal file
184
ZR.CodeGenerator/FileHelper.cs
Normal file
@ -0,0 +1,184 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using ZR.CodeGenerator.Model;
|
||||
|
||||
namespace ZR.CodeGenerator
|
||||
{
|
||||
public class FileHelper
|
||||
{
|
||||
/// <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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 写文件
|
||||
/// </summary>
|
||||
/// <param name="path">完整路径带扩展名的</param>
|
||||
/// <param name="content"></param>
|
||||
public static void WriteAndSave(string path, string content)
|
||||
{
|
||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
|
||||
{
|
||||
path = path.Replace("\\", "/").Replace("//", "/");
|
||||
}
|
||||
if (!Directory.Exists(Path.GetDirectoryName(path)))
|
||||
{
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(path));
|
||||
}
|
||||
Console.WriteLine("写入文件:" + path);
|
||||
try
|
||||
{
|
||||
//实例化一个文件流--->与写入文件相关联
|
||||
using var fs = new FileStream(path, FileMode.Create, FileAccess.Write);
|
||||
//实例化一个StreamWriter-->与fs相关联
|
||||
using var sw = new StreamWriter(fs);
|
||||
//开始写入
|
||||
sw.Write(content);
|
||||
//清空缓冲区
|
||||
sw.Flush();
|
||||
//关闭流
|
||||
sw.Close();
|
||||
fs.Close();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine("写入文件出错了:" + ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 从代码模板中读取内容
|
||||
/// </summary>
|
||||
/// <param name="templateName">模板名称,应包括文件扩展名称。比如:template.txt</param>
|
||||
/// <returns></returns>
|
||||
public static string ReadTemplate(string templateName)
|
||||
{
|
||||
string path = Environment.CurrentDirectory;
|
||||
string fullName = $"{path}/wwwroot/CodeGenTemplate/{templateName}";
|
||||
|
||||
Console.WriteLine("开始读取模板=" + fullName);
|
||||
string temp = fullName;
|
||||
string str = "";
|
||||
if (!File.Exists(temp))
|
||||
{
|
||||
return str;
|
||||
}
|
||||
StreamReader sr = null;
|
||||
try
|
||||
{
|
||||
sr = new StreamReader(temp);
|
||||
str = sr.ReadToEnd(); // 读取文件
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"读取模板出错了{ex.Message}");
|
||||
}
|
||||
sr?.Close();
|
||||
sr?.Dispose();
|
||||
return str;
|
||||
}
|
||||
|
||||
|
||||
/// <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);
|
||||
DeleteDirectory(dto.GenCodePath);
|
||||
dto.ZipFileName = zipReturnFileName;
|
||||
return zipReturnFileName;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine("压缩文件出错。" + ex.Message);
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
/// <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", "create_time", "update_time" };
|
||||
/// <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";
|
||||
}
|
||||
}
|
||||
66
ZR.CodeGenerator/Model/GenerateDto.cs
Normal file
66
ZR.CodeGenerator/Model/GenerateDto.cs
Normal file
@ -0,0 +1,66 @@
|
||||
using System;
|
||||
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 long TableId { get; set; }
|
||||
//public string[] QueryColumn { get; set; }
|
||||
/// <summary>
|
||||
/// 是否预览代码
|
||||
/// </summary>
|
||||
public int IsPreview { get; set; }
|
||||
/// <summary>
|
||||
/// 要生成的文件
|
||||
/// </summary>
|
||||
public int[] GenCodeFiles { get; set; }
|
||||
/// <summary>
|
||||
/// 如果目标文件存在,是否覆盖。默认为false
|
||||
/// </summary>
|
||||
public bool Coverd { get; set; } = true;
|
||||
/// <summary>
|
||||
/// 生成代码的数据库类型 0、mysql 1、sqlserver
|
||||
/// </summary>
|
||||
public int DbType { get; set; }
|
||||
public GenTable GenTable { get; set; }
|
||||
#region 存储路径
|
||||
/// <summary>
|
||||
/// 代码模板预览存储路径存放
|
||||
/// </summary>
|
||||
public List<GenCode> GenCodes { get; set; } = new List<GenCode>();
|
||||
/// <summary>
|
||||
/// 代码生成路径
|
||||
/// </summary>
|
||||
public string GenCodePath { get; set; }
|
||||
/// <summary>
|
||||
/// 代码生成压缩包路径
|
||||
/// </summary>
|
||||
public string ZipPath { get; set; }
|
||||
/// <summary>
|
||||
/// 代码生成压缩包名称
|
||||
/// </summary>
|
||||
public string ZipFileName { get; set; }
|
||||
#endregion
|
||||
}
|
||||
|
||||
public class GenCode
|
||||
{
|
||||
public int Type { get; set; }
|
||||
public string Title { get; set; }
|
||||
public string Path { get; set; }
|
||||
public string Content { get; set; }
|
||||
|
||||
public GenCode(int type, string title, string path, string content)
|
||||
{
|
||||
Type = type;
|
||||
Title = title;
|
||||
Path = path;
|
||||
Content = content;
|
||||
}
|
||||
}
|
||||
}
|
||||
106
ZR.CodeGenerator/Model/ReplaceDto.cs
Normal file
106
ZR.CodeGenerator/Model/ReplaceDto.cs
Normal file
@ -0,0 +1,106 @@
|
||||
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; }
|
||||
public string Author { get; set; }
|
||||
public string AddTime { get; set; } = DateTime.Now.ToString("yyyy-MM-dd");
|
||||
}
|
||||
}
|
||||
69
ZR.CodeGenerator/Service/CodeGeneraterService.cs
Normal file
69
ZR.CodeGenerator/Service/CodeGeneraterService.cs
Normal file
@ -0,0 +1,69 @@
|
||||
using SqlSugar;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using ZR.Model;
|
||||
|
||||
namespace ZR.CodeGenerator.Service
|
||||
{
|
||||
public class CodeGeneraterService : DbProvider
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取所有数据库名
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public List<string> GetAllDataBases()
|
||||
{
|
||||
var db = GetSugarDbContext();
|
||||
var templist = db.DbMaintenance.GetDataBaseList(db.ScopedContext);
|
||||
|
||||
return templist;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取所有表
|
||||
/// </summary>
|
||||
/// <param name="dbName"></param>
|
||||
/// <param name="tableName"></param>
|
||||
/// <param name="pager"></param>
|
||||
/// <returns></returns>
|
||||
public List<DbTableInfo> GetAllTables(string dbName, string tableName, PagerInfo pager)
|
||||
{
|
||||
var tableList = GetSugarDbContext(dbName).DbMaintenance.GetTableInfoList(true);
|
||||
if (!string.IsNullOrEmpty(tableName))
|
||||
{
|
||||
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>
|
||||
/// <param name="dbName"></param>
|
||||
/// <param name="tableName"></param>
|
||||
/// <returns></returns>
|
||||
public List<DbColumnInfo> GetColumnInfo(string dbName, string tableName)
|
||||
{
|
||||
return GetSugarDbContext(dbName).DbMaintenance.GetColumnInfosByTableName(tableName, true);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@ -1,110 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using Infrastructure.Extensions;
|
||||
using ZR.Common.Extension;
|
||||
|
||||
namespace ZR.CodeGenerator.CodeGenerator
|
||||
{
|
||||
public class TableMappingHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// UserService转成userService
|
||||
/// </summary>
|
||||
/// <param name="s"></param>
|
||||
/// <returns></returns>
|
||||
public static string FirstLetterLowercase(string instanceName)
|
||||
{
|
||||
instanceName = instanceName.ParseToString();
|
||||
if (!instanceName.IsEmpty())
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.Append(instanceName[0].ToString().ToLower() + instanceName.Substring(1));
|
||||
return sb.ToString();
|
||||
}
|
||||
else
|
||||
{
|
||||
return instanceName;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// sys_menu_authorize变成MenuAuthorize
|
||||
/// </summary>
|
||||
public static string GetClassNamePrefix(string tableName)
|
||||
{
|
||||
string[] arr = tableName.Split('_');
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 1; i < arr.Length; i++)
|
||||
{
|
||||
sb.Append(arr[i][0].ToString().ToUpper() + arr[i].Substring(1));
|
||||
}
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
public static string GetPropertyDatatype(string sDatatype)
|
||||
{
|
||||
string sTempDatatype = string.Empty;
|
||||
sDatatype = sDatatype.ToLower();
|
||||
switch (sDatatype)
|
||||
{
|
||||
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;
|
||||
}
|
||||
return sTempDatatype;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -11,8 +11,13 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Model\" />
|
||||
<Folder Include="Template\" />
|
||||
<PackageReference Include="SqlSugarCoreNoDrive" Version="5.0.3.4" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Update="Template\ModelTemplate.txt">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
1
ZR.Model/Models/README.txt
Normal file
1
ZR.Model/Models/README.txt
Normal file
@ -0,0 +1 @@
|
||||
此文件夹用于存放业务代码数据库实体类
|
||||
@ -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; }
|
||||
}
|
||||
|
||||
@ -11,7 +11,7 @@ namespace ZR.Model.System
|
||||
public class SysLogininfor: SysBase
|
||||
{
|
||||
//[Key]
|
||||
[SugarColumn(IsPrimaryKey = true)]
|
||||
[SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
|
||||
public long infoId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
|
||||
@ -13,7 +13,7 @@ namespace ZR.Model.System
|
||||
/// 菜单ID
|
||||
/// </summary>
|
||||
//[Key]//非自动增长主键时使用ExplicitKey
|
||||
[SqlSugar.SugarColumn(IsPrimaryKey = true)]
|
||||
[SqlSugar.SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
|
||||
public long menuId { get; set; }
|
||||
/// <summary>
|
||||
/// 菜单名称
|
||||
|
||||
@ -8,7 +8,7 @@ namespace ZR.Model.System
|
||||
[SqlSugar.SugarTable("sys_oper_log")]
|
||||
public class SysOperLog
|
||||
{
|
||||
[SqlSugar.SugarColumn(IsPrimaryKey = true)]
|
||||
[SqlSugar.SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
|
||||
public long OperId { get; set; }
|
||||
/** 操作模块 */
|
||||
//@Excel(name = "操作模块")
|
||||
|
||||
@ -17,6 +17,7 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Dto\" />
|
||||
<Folder Include="Enum\" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
@ -22,11 +22,12 @@ 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);
|
||||
}
|
||||
|
||||
Db = new SqlSugarClient(new List<ConnectionConfig>()
|
||||
{
|
||||
new ConnectionConfig(){
|
||||
@ -41,6 +42,7 @@ namespace ZR.Repository.DbProvider
|
||||
//调式代码 用来打印SQL
|
||||
Db.Aop.OnLogExecuting = (sql, pars) =>
|
||||
{
|
||||
Console.BackgroundColor = ConsoleColor.Yellow;
|
||||
Console.WriteLine("【SQL语句】" + sql.ToLower() + "\r\n" + Db.Utilities.SerializeObject(pars.ToDictionary(it => it.ParameterName, it => it.Value)));
|
||||
};
|
||||
//出错打印日志
|
||||
|
||||
@ -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
|
||||
|
||||
@ -37,16 +37,6 @@ namespace ZR.Repository.System
|
||||
.ToList();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据DictCode查询
|
||||
/// </summary>
|
||||
/// <param name="dictCode"></param>
|
||||
/// <returns></returns>
|
||||
public SysDictData SelectDictDataById(long dictCode)
|
||||
{
|
||||
return Db.Queryable<SysDictData>().Where(f => f.DictCode == dictCode).First();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 新增保存字典数据信息
|
||||
/// </summary>
|
||||
@ -89,16 +79,6 @@ namespace ZR.Repository.System
|
||||
return Db.Deleteable<SysDictData>().In(dictCodes).ExecuteCommand();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查询字典数据
|
||||
/// </summary>
|
||||
/// <param name="dictType"></param>
|
||||
/// <returns></returns>
|
||||
public int CountDictDataByType(string dictType)
|
||||
{
|
||||
return Db.Queryable<SysDictData>().Count(f => f.DictType == dictType);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 同步修改字典类型
|
||||
/// </summary>
|
||||
|
||||
@ -17,43 +17,17 @@ namespace ZR.Repository.System
|
||||
/// </summary>
|
||||
/// <param name="dictType">实体模型</param>
|
||||
/// <returns></returns>
|
||||
public List<SysDictType> SelectDictTypeList(SysDictType dictType)
|
||||
public List<SysDictType> SelectDictTypeList(SysDictType dictType, Model.PagerInfo pager)
|
||||
{
|
||||
return Db
|
||||
var totalNum = 0;
|
||||
var list = Db
|
||||
.Queryable<SysDictType>()
|
||||
.WhereIF(!string.IsNullOrEmpty(dictType.DictName), it => it.DictName.Contains(dictType.DictName))
|
||||
.WhereIF(!string.IsNullOrEmpty(dictType.Status), it => it.Status == dictType.Status)
|
||||
.WhereIF(!string.IsNullOrEmpty(dictType.DictType), it => it.DictType == dictType.DictType).ToList();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据Id查询
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
public SysDictType SelectDictTypeById(long id)
|
||||
{
|
||||
return Db.Queryable<SysDictType>().First(it => it.DictId == id);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 检查字典类型唯一值
|
||||
/// </summary>
|
||||
/// <param name="dictType"></param>
|
||||
/// <returns></returns>
|
||||
public SysDictType CheckDictTypeUnique(string dictType)
|
||||
{
|
||||
return Db.Queryable<SysDictType>().First(it => it.DictType == dictType);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除一个
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
public int DeleteDictTypeById(long id)
|
||||
{
|
||||
return Db.Deleteable<SysDictType>().In(id).ExecuteCommand();
|
||||
.WhereIF(!string.IsNullOrEmpty(dictType.DictType), it => it.DictType == dictType.DictType)
|
||||
.ToPageList(pager.PageNum, pager.PageSize, ref totalNum);
|
||||
pager.TotalNum = totalNum;
|
||||
return list;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -66,18 +40,6 @@ namespace ZR.Repository.System
|
||||
return Db.Deleteable<SysDictType>().In(id).ExecuteCommand();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 插入
|
||||
/// </summary>
|
||||
/// <param name="sysDictType"></param>
|
||||
/// <returns></returns>
|
||||
public long InsertDictType(SysDictType sysDictType)
|
||||
{
|
||||
var result = Db.Insertable(sysDictType).IgnoreColumns(it => new { sysDictType.Update_by })
|
||||
.ExecuteReturnIdentity();
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 修改
|
||||
/// </summary>
|
||||
|
||||
@ -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
|
||||
|
||||
@ -29,7 +29,7 @@ namespace ZR.Repository.System
|
||||
.WhereIF(!string.IsNullOrEmpty(user.UserName), it => it.UserName.Contains(user.UserName))
|
||||
.WhereIF(!string.IsNullOrEmpty(user.Status), it => it.Status == user.Status)
|
||||
.WhereIF(user.BeginTime != DateTime.MinValue && user.BeginTime != null, it => it.Create_time >= user.BeginTime)
|
||||
.WhereIF(user.EndTime != DateTime.MinValue && user.BeginTime != null, it => it.EndTime <= user.EndTime)
|
||||
.WhereIF(user.EndTime != DateTime.MinValue && user.BeginTime != null, it => it.Create_time <= user.EndTime)
|
||||
.WhereIF(user.DeptId != 0, it => it.DeptId == user.DeptId)
|
||||
.OrderBy(it => it.UserId)
|
||||
.ToPageList(pager.PageNum, pager.PageSize, ref totalCount);
|
||||
|
||||
@ -67,10 +67,10 @@ namespace ZR.Repository.System
|
||||
/// <returns></returns>
|
||||
public List<SysUser> GetSysUsersByRoleId(long roleId)
|
||||
{
|
||||
return Db.Queryable<SysUserRole, SysUser>((t1, user) => new JoinQueryInfos(
|
||||
JoinType.Left, t1.UserId == user.UserId))
|
||||
.Where((t1, user) => t1.RoleId == roleId && user.DelFlag == "0")
|
||||
.Select((t1, user) => user)
|
||||
return Db.Queryable<SysUserRole, SysUser>((t1, u) => new JoinQueryInfos(
|
||||
JoinType.Left, t1.UserId == u.UserId))
|
||||
.Where((t1, u) => t1.RoleId == roleId && u.DelFlag == "0")
|
||||
.Select((t1, u) => u)
|
||||
.ToList();
|
||||
}
|
||||
}
|
||||
|
||||
@ -15,4 +15,8 @@
|
||||
<PackageReference Include="NETCore.Encrypt" Version="2.0.9" />
|
||||
<PackageReference Include="SqlSugarCoreNoDrive" Version="5.0.3.4" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Repositories\" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
||||
@ -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>
|
||||
@ -166,7 +178,7 @@ namespace ZR.Service
|
||||
/// 查询所有数据(无分页,请慎用)
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public List<T> GetAll(bool useCache = false, int cacheSecond = 3600)
|
||||
public List<T> GetAll(bool useCache = false, int cacheSecond = 3600)
|
||||
{
|
||||
return Db.Queryable<T>().WithCacheIF(useCache, cacheSecond).ToList();
|
||||
}
|
||||
|
||||
@ -3,8 +3,6 @@ using SqlSugar;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq.Expressions;
|
||||
using System.Threading.Tasks;
|
||||
using ZR.Model;
|
||||
|
||||
namespace ZR.Service
|
||||
{
|
||||
@ -44,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>
|
||||
@ -138,7 +138,7 @@ namespace ZR.Service
|
||||
/// <param name="where"></param>
|
||||
/// <param name="parm"></param>
|
||||
/// <returns></returns>
|
||||
PagedInfo<T> GetPages(Expression<Func<T, bool>> where, PagerInfo parm);
|
||||
PagedInfo<T> GetPages(Expression<Func<T, bool>> where, Model.PagerInfo parm);
|
||||
|
||||
/// <summary>
|
||||
/// 根据条件查询分页
|
||||
@ -148,7 +148,7 @@ namespace ZR.Service
|
||||
/// <param name="order"></param>
|
||||
/// <param name="orderEnum"></param>
|
||||
/// <returns></returns>
|
||||
PagedInfo<T> GetPages(Expression<Func<T, bool>> where, PagerInfo parm, Expression<Func<T, object>> order, string orderEnum = "Asc");
|
||||
PagedInfo<T> GetPages(Expression<Func<T, bool>> where, Model.PagerInfo parm, Expression<Func<T, object>> order, string orderEnum = "Asc");
|
||||
|
||||
/// <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
|
||||
{
|
||||
|
||||
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