v3.7.0
This commit is contained in:
commit
86628e4fd9
8
.gitignore
vendored
8
.gitignore
vendored
@ -259,7 +259,11 @@ paket-files/
|
||||
# Python Tools for Visual Studio (PTVS)
|
||||
__pycache__/
|
||||
*.pyc
|
||||
/ZRAdmin/Properties/launchSettings.json
|
||||
/ZRAdmin/Properties/PublishProfiles
|
||||
/ZR.Admin.WebApi/appsettings.Stage.json
|
||||
/CodeGenerate
|
||||
/ZR.Admin.WebApi/appsettings.Production.json
|
||||
/ZR.Admin.WebApi/wwwroot/uploads
|
||||
/ZR.Admin.WebApi/wwwroot/Generatecode
|
||||
/ZR.Admin.WebApi/wwwroot/export
|
||||
/ZR.Vue/src/views/business/Gendemo.vue
|
||||
/ZR.Admin.WebApi/Properties/launchSettings.json
|
||||
|
||||
@ -14,7 +14,7 @@ namespace Infrastructure
|
||||
|
||||
static ConfigUtils()
|
||||
{
|
||||
Config = App.ServiceProvider.GetRequiredService<IConfiguration>();
|
||||
Configuration = App.ServiceProvider.GetRequiredService<IConfiguration>();
|
||||
|
||||
if (Instance == null)
|
||||
Instance = new ConfigUtils();
|
||||
@ -22,35 +22,22 @@ namespace Infrastructure
|
||||
|
||||
public static ConfigUtils Instance { get; private set; }
|
||||
#endregion
|
||||
|
||||
private static IConfiguration Config { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 泛型读取配置文件
|
||||
/// 目前还不能绑定到实体类
|
||||
/// </summary>
|
||||
/// <param name="defaultValue">获取不到配置文件设定默认值</param>
|
||||
/// <param name="key">要获取的配置文件节点名称</param>
|
||||
/// <returns></returns>
|
||||
//public T GetConfig<T>(string key, T defaultValue = default)
|
||||
//{
|
||||
// //GetValue扩展包需要安装Microsoft.Extensions.Configuration
|
||||
// var setting = Config.GetValue(key, defaultValue);
|
||||
|
||||
// Console.WriteLine($"获取配置文件值key={key},value={setting}");
|
||||
// return setting;
|
||||
//}
|
||||
private static IConfiguration Configuration { get; set; }
|
||||
|
||||
public T GetAppConfig<T>(string key, T defaultValue = default(T))
|
||||
{
|
||||
T setting = (T)Convert.ChangeType(Config[key], typeof(T));
|
||||
T setting = (T)Convert.ChangeType(Configuration[key], typeof(T));
|
||||
var value = setting;
|
||||
if (setting == null)
|
||||
value = defaultValue;
|
||||
//Console.WriteLine($"获取配置文件值key={key},value={value}");
|
||||
return value;
|
||||
}
|
||||
public T Bind<T>(string key, T t)
|
||||
{
|
||||
Configuration.Bind(key, t);
|
||||
|
||||
return t;
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取配置文件
|
||||
/// </summary>
|
||||
@ -58,7 +45,7 @@ namespace Infrastructure
|
||||
/// <returns></returns>
|
||||
public string GetConfig(string key)
|
||||
{
|
||||
return Config[key];
|
||||
return Configuration[key];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -66,10 +53,9 @@ namespace Infrastructure
|
||||
/// </summary>
|
||||
/// <param name="key"></param>
|
||||
/// <returns></returns>
|
||||
public string GetConnectionStrings(string key)
|
||||
public string GetConnectionString(string key)
|
||||
{
|
||||
return Config.GetConnectionString(key);
|
||||
|
||||
return Configuration.GetConnectionString(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -4,6 +4,10 @@
|
||||
<TargetFramework>net5.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Remove="Model\PagedInfo.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="AspectCore.Abstractions" Version="2.2.0" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Hosting" Version="2.2.7" />
|
||||
|
||||
@ -50,4 +50,27 @@ namespace Infrastructure
|
||||
public string KEY { get; set; }
|
||||
public string SECRET { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Jwt
|
||||
/// </summary>
|
||||
public class JwtSettings
|
||||
{
|
||||
/// <summary>
|
||||
/// token是谁颁发的
|
||||
/// </summary>
|
||||
public string Issuer { get; set; }
|
||||
/// <summary>
|
||||
/// token可以给那些客户端使用
|
||||
/// </summary>
|
||||
public string Audience { get; set; }
|
||||
/// <summary>
|
||||
/// 加密的key(SecretKey必须大于16个,是大于,不是大于等于)
|
||||
/// </summary>
|
||||
public string SecretKey { get; set; }
|
||||
/// <summary>
|
||||
/// token时间(分)
|
||||
/// </summary>
|
||||
public int Expire { get; set; } = 1440;
|
||||
}
|
||||
}
|
||||
|
||||
@ -9,6 +9,8 @@ using OfficeOpenXml;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using ZR.Admin.WebApi.Filters;
|
||||
|
||||
namespace ZR.Admin.WebApi.Controllers
|
||||
@ -120,13 +122,13 @@ namespace ZR.Admin.WebApi.Controllers
|
||||
//调试模式需要加上
|
||||
ExcelPackage.LicenseContext = LicenseContext.NonCommercial;
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(newFileName));
|
||||
using (ExcelPackage package = new ExcelPackage(new FileInfo(newFileName)))
|
||||
using (ExcelPackage package = new(new FileInfo(newFileName)))
|
||||
{
|
||||
// 添加worksheet
|
||||
ExcelWorksheet worksheet = package.Workbook.Worksheets.Add(sheetName);
|
||||
|
||||
//全部字段导出
|
||||
worksheet.Cells.LoadFromCollection(list, true);
|
||||
worksheet.Cells.LoadFromCollection(list, true, OfficeOpenXml.Table.TableStyles.Light13);
|
||||
package.Save();
|
||||
}
|
||||
|
||||
|
||||
135
ZR.Admin.WebApi/Controllers/CommonController.cs
Normal file
135
ZR.Admin.WebApi/Controllers/CommonController.cs
Normal file
@ -0,0 +1,135 @@
|
||||
using Infrastructure;
|
||||
using Infrastructure.Attribute;
|
||||
using Infrastructure.Model;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using ZR.Admin.WebApi.Filters;
|
||||
using ZR.Common;
|
||||
using ZR.Service.System.IService;
|
||||
|
||||
namespace ZR.Admin.WebApi.Controllers
|
||||
{
|
||||
/// <summary>
|
||||
/// 公共模块
|
||||
/// </summary>
|
||||
[Route("[controller]/[action]")]
|
||||
public class CommonController : BaseController
|
||||
{
|
||||
private OptionsSetting OptionsSetting;
|
||||
private NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
|
||||
|
||||
private IWebHostEnvironment WebHostEnvironment;
|
||||
private ISysFileService SysFileService;
|
||||
public CommonController(IOptions<OptionsSetting> options, IWebHostEnvironment webHostEnvironment, ISysFileService fileService)
|
||||
{
|
||||
WebHostEnvironment = webHostEnvironment;
|
||||
SysFileService = fileService;
|
||||
OptionsSetting = options.Value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 心跳
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet, Route("health/index")]
|
||||
public IActionResult Health()
|
||||
{
|
||||
return SUCCESS(true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 发送邮件
|
||||
/// </summary>
|
||||
/// <param name="sendEmailVo">请求参数接收实体</param>
|
||||
/// <returns></returns>
|
||||
[ActionPermissionFilter(Permission = "tool:email:send")]
|
||||
[Log(Title = "发送邮件", IsSaveRequestData = false)]
|
||||
[HttpPost]
|
||||
public IActionResult SendEmail([FromBody] SendEmailDto sendEmailVo)
|
||||
{
|
||||
if (sendEmailVo == null || string.IsNullOrEmpty(sendEmailVo.Subject) || string.IsNullOrEmpty(sendEmailVo.ToUser))
|
||||
{
|
||||
return ToResponse(ApiResult.Error($"请求参数不完整"));
|
||||
}
|
||||
if (string.IsNullOrEmpty(OptionsSetting.MailOptions.From) || string.IsNullOrEmpty(OptionsSetting.MailOptions.Password))
|
||||
{
|
||||
return ToResponse(ApiResult.Error($"请配置邮箱信息"));
|
||||
}
|
||||
MailHelper mailHelper = new MailHelper(OptionsSetting.MailOptions.From, OptionsSetting.MailOptions.Smtp, OptionsSetting.MailOptions.Port, OptionsSetting.MailOptions.Password);
|
||||
|
||||
mailHelper.SendMail(sendEmailVo.ToUser, sendEmailVo.Subject, sendEmailVo.Content, sendEmailVo.FileUrl, sendEmailVo.HtmlContent);
|
||||
|
||||
logger.Info($"发送邮件{JsonConvert.SerializeObject(sendEmailVo)}");
|
||||
|
||||
return SUCCESS(true);
|
||||
}
|
||||
|
||||
#region 上传
|
||||
|
||||
/// <summary>
|
||||
/// 存储文件
|
||||
/// </summary>
|
||||
/// <param name="formFile"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost()]
|
||||
[Verify]
|
||||
[ActionPermissionFilter(Permission = "system")]
|
||||
public IActionResult UploadFile([FromForm(Name = "file")] IFormFile formFile)
|
||||
{
|
||||
if (formFile == null) throw new CustomException(ResultCode.PARAM_ERROR, "上传图片不能为空");
|
||||
string fileExt = Path.GetExtension(formFile.FileName);
|
||||
string fileName = FileUtil.HashFileName(Guid.NewGuid().ToString()).ToLower() + fileExt;
|
||||
string finalFilePath = Path.Combine(WebHostEnvironment.WebRootPath, FileUtil.GetdirPath("uploads"), fileName);
|
||||
finalFilePath = finalFilePath.Replace("\\", "/").Replace("//", "/");
|
||||
|
||||
if (!Directory.Exists(Path.GetDirectoryName(finalFilePath)))
|
||||
{
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(finalFilePath));
|
||||
}
|
||||
|
||||
using (var stream = new FileStream(finalFilePath, FileMode.Create))
|
||||
{
|
||||
formFile.CopyTo(stream);
|
||||
}
|
||||
|
||||
string accessPath = $"{OptionsSetting.Upload.UploadUrl}/{FileUtil.GetdirPath("uploads").Replace("\\", " /")}{fileName}";
|
||||
return ToResponse(ResultCode.SUCCESS, accessPath);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 存储文件到阿里云
|
||||
/// </summary>
|
||||
/// <param name="formFile"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Verify]
|
||||
[ActionPermissionFilter(Permission = "system")]
|
||||
public IActionResult UploadFileAliyun([FromForm(Name = "file")] IFormFile formFile)
|
||||
{
|
||||
if (formFile == null) throw new CustomException(ResultCode.PARAM_ERROR, "上传文件不能为空");
|
||||
string fileExt = Path.GetExtension(formFile.FileName);
|
||||
string[] AllowedFileExtensions = new string[] { ".jpg", ".gif", ".png", ".jpeg", ".webp", ".svga", ".xls" };
|
||||
int MaxContentLength = 1024 * 1024 * 4;
|
||||
|
||||
if (!AllowedFileExtensions.Contains(fileExt))
|
||||
{
|
||||
return ToResponse(ResultCode.CUSTOM_ERROR, "上传失败,未经允许上传类型");
|
||||
}
|
||||
|
||||
if (formFile.Length > MaxContentLength)
|
||||
{
|
||||
return ToResponse(ResultCode.CUSTOM_ERROR, "上传文件过大,不能超过 " + (MaxContentLength / 1024).ToString() + " MB");
|
||||
}
|
||||
(bool, string) result = SysFileService.SaveFile("", formFile);
|
||||
|
||||
return ToResponse(ResultCode.SUCCESS, result.Item2);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@ -1,91 +0,0 @@
|
||||
using Infrastructure;
|
||||
using Infrastructure.Attribute;
|
||||
using Infrastructure.Model;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using ZR.Admin.WebApi.Filters;
|
||||
using ZR.Common;
|
||||
|
||||
namespace ZR.Admin.WebApi.Controllers
|
||||
{
|
||||
public class HomeController : BaseController
|
||||
{
|
||||
private OptionsSetting OptionsSetting;
|
||||
private NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
|
||||
|
||||
public HomeController(IOptions<OptionsSetting> options)
|
||||
{
|
||||
OptionsSetting = options.Value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 心跳
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet, Route("health/index")]
|
||||
[Log()]
|
||||
public IActionResult Health()
|
||||
{
|
||||
return SUCCESS(true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 加密
|
||||
/// </summary>
|
||||
/// <param name="content"></param>
|
||||
/// <returns></returns>
|
||||
public IActionResult Encrypt(string content)
|
||||
{
|
||||
if (string.IsNullOrEmpty(content))
|
||||
{
|
||||
throw new Exception("content不能为空");
|
||||
}
|
||||
string key = ConfigUtils.Instance.GetConfig("DbKey");
|
||||
string encryptTxt = NETCore.Encrypt.EncryptProvider.DESEncrypt(content, key);
|
||||
return Ok(new { content, encryptTxt });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 解密
|
||||
/// </summary>
|
||||
/// <param name="content"></param>
|
||||
/// <returns></returns>
|
||||
public IActionResult Decrypt(string content)
|
||||
{
|
||||
if (string.IsNullOrEmpty(content))
|
||||
{
|
||||
throw new Exception("content不能为空");
|
||||
}
|
||||
string key = ConfigUtils.Instance.GetConfig("DbKey");
|
||||
string encryptTxt = NETCore.Encrypt.EncryptProvider.DESDecrypt(content, key);
|
||||
return Ok(new { content, encryptTxt });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 发送邮件
|
||||
/// </summary>
|
||||
/// <param name="sendEmailVo">请求参数接收实体</param>
|
||||
/// <returns></returns>
|
||||
[ActionPermissionFilter(Permission = "tool:email:send")]
|
||||
public IActionResult SendEmail([FromBody] SendEmailDto sendEmailVo)
|
||||
{
|
||||
if (sendEmailVo == null || string.IsNullOrEmpty(sendEmailVo.Subject) || string.IsNullOrEmpty(sendEmailVo.ToUser))
|
||||
{
|
||||
return ToResponse(ApiResult.Error($"请求参数不完整"));
|
||||
}
|
||||
if (string.IsNullOrEmpty(OptionsSetting.MailOptions.From) || string.IsNullOrEmpty(OptionsSetting.MailOptions.Password))
|
||||
{
|
||||
return ToResponse(ApiResult.Error($"请配置邮箱信息"));
|
||||
}
|
||||
MailHelper mailHelper = new MailHelper(OptionsSetting.MailOptions.From, OptionsSetting.MailOptions.Smtp, OptionsSetting.MailOptions.Port, OptionsSetting.MailOptions.Password);
|
||||
|
||||
mailHelper.SendMail(sendEmailVo.ToUser, sendEmailVo.Subject, sendEmailVo.Content, sendEmailVo.FileUrl, sendEmailVo.HtmlContent);
|
||||
|
||||
logger.Info($"发送邮件{JsonConvert.SerializeObject(sendEmailVo)}");
|
||||
|
||||
return SUCCESS(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -49,7 +49,7 @@ namespace ZR.Admin.WebApi.Controllers
|
||||
predicate = predicate.AndIF(!string.IsNullOrEmpty(parm.Title), m => m.Title.Contains(parm.Title));
|
||||
predicate = predicate.AndIF(!string.IsNullOrEmpty(parm.Status), m => m.Status == parm.Status);
|
||||
|
||||
var response = _ArticleService.GetPages(predicate.ToExpression(), parm, f => f.Cid, "Desc");
|
||||
var response = _ArticleService.GetPages(predicate.ToExpression(), parm, f => f.Cid, OrderByType.Desc);
|
||||
|
||||
return SUCCESS(response);
|
||||
}
|
||||
|
||||
@ -19,7 +19,7 @@ using ZR.Common;
|
||||
using ZR.Model;
|
||||
using ZR.Model.System.Dto;
|
||||
using ZR.Model.System.Generate;
|
||||
using ZR.Model.Vo;
|
||||
using ZR.Service;
|
||||
using ZR.Service.System.IService;
|
||||
|
||||
namespace ZR.Admin.WebApi.Controllers
|
||||
@ -27,17 +27,24 @@ namespace ZR.Admin.WebApi.Controllers
|
||||
/// <summary>
|
||||
/// 代码生成
|
||||
/// </summary>
|
||||
[Verify]
|
||||
[Route("tool/gen")]
|
||||
public class CodeGeneratorController : BaseController
|
||||
{
|
||||
private CodeGeneraterService _CodeGeneraterService = new CodeGeneraterService();
|
||||
private IGenTableService GenTableService;
|
||||
private IGenTableColumnService GenTableColumnService;
|
||||
private readonly ISysDictDataService SysDictDataService;
|
||||
private IWebHostEnvironment WebHostEnvironment;
|
||||
public CodeGeneratorController(IGenTableService genTableService, IGenTableColumnService genTableColumnService, IWebHostEnvironment webHostEnvironment)
|
||||
public CodeGeneratorController(
|
||||
IGenTableService genTableService,
|
||||
IGenTableColumnService genTableColumnService,
|
||||
ISysDictDataService dictDataService,
|
||||
IWebHostEnvironment webHostEnvironment)
|
||||
{
|
||||
GenTableService = genTableService;
|
||||
GenTableColumnService = genTableColumnService;
|
||||
SysDictDataService = dictDataService;
|
||||
WebHostEnvironment = webHostEnvironment;
|
||||
}
|
||||
|
||||
@ -66,43 +73,8 @@ namespace ZR.Admin.WebApi.Controllers
|
||||
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);
|
||||
if (!string.IsNullOrEmpty(genTableInfo.Options))
|
||||
{
|
||||
Dictionary<string, object> options = JsonConvert.DeserializeObject<Dictionary<string, object>>(genTableInfo.Options);
|
||||
dto.ParentMenuId = (long)options.GetValueOrDefault("parentMenuId", 0);
|
||||
}
|
||||
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 });
|
||||
return SUCCESS(list.ToPage(pager));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -130,7 +102,7 @@ namespace ZR.Admin.WebApi.Controllers
|
||||
{
|
||||
var tableColumns = GenTableColumnService.GenTableColumns(tableId);
|
||||
var tableInfo = GenTableService.GetGenTableInfo(tableId);
|
||||
return SUCCESS(new { result = tableColumns, info = tableInfo });
|
||||
return SUCCESS(new { cloumns = tableColumns, info = tableInfo });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -177,11 +149,11 @@ namespace ZR.Admin.WebApi.Controllers
|
||||
BaseNameSpace = "ZR.",//导入默认命名空间前缀
|
||||
ModuleName = "business",//导入默认模块名
|
||||
ClassName = CodeGeneratorTool.GetClassName(tableName),
|
||||
BusinessName = CodeGeneratorTool.GetClassName(tableName),
|
||||
BusinessName = CodeGeneratorTool.GetBusinessName(tableName),
|
||||
FunctionAuthor = ConfigUtils.Instance.GetConfig(GenConstants.Gen_author),
|
||||
FunctionName = string.IsNullOrEmpty(tabInfo.Description) ? tableName : tabInfo.Description,
|
||||
TableName = tableName,
|
||||
TableComment = string.IsNullOrEmpty(tabInfo.Description) ? tableName : tabInfo.Description,
|
||||
TableComment = tabInfo?.Description,
|
||||
FunctionName = tabInfo?.Description,
|
||||
Create_by = userName,
|
||||
};
|
||||
genTable.TableId = GenTableService.ImportGenTable(genTable);
|
||||
@ -217,7 +189,12 @@ namespace ZR.Admin.WebApi.Controllers
|
||||
if (genTableDto == null) throw new CustomException("请求参数错误");
|
||||
var genTable = genTableDto.Adapt<GenTable>().ToUpdate(HttpContext);
|
||||
|
||||
genTable.Options = JsonConvert.SerializeObject(new { parentMenuId = genTableDto.ParentMenuId });
|
||||
genTable.Options = JsonConvert.SerializeObject(new
|
||||
{
|
||||
parentMenuId = genTableDto.ParentMenuId,
|
||||
sortField = genTableDto.SortField,
|
||||
sortType = genTable.SortType
|
||||
});
|
||||
int rows = GenTableService.UpdateGenTable(genTable);
|
||||
if (rows > 0)
|
||||
{
|
||||
@ -241,16 +218,52 @@ namespace ZR.Admin.WebApi.Controllers
|
||||
}
|
||||
var genTableInfo = GenTableService.GetGenTableInfo(tableId);
|
||||
genTableInfo.Columns = GenTableColumnService.GenTableColumns(tableId);
|
||||
|
||||
//var dictList = genTableInfo.Columns.FindAll(x => !string.IsNullOrEmpty(x.DictType));
|
||||
//foreach (var item in dictList)
|
||||
//{
|
||||
// item.DictDatas = SysDictDataService.SelectDictDataByType(item.DictType);
|
||||
//}
|
||||
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);
|
||||
CodeGeneratorTool.Generate(dto);
|
||||
|
||||
return SUCCESS(dto.GenCodes);
|
||||
}
|
||||
|
||||
/// <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(dto);
|
||||
//下载文件
|
||||
FileHelper.ZipGenCode(dto);
|
||||
|
||||
//HttpContext.Response.Headers.Add("Content-disposition", $"attachment; filename={zipFileName}");
|
||||
return SUCCESS(new { zipPath = "/Generatecode/" + dto.ZipFileName, fileName = dto.ZipFileName });
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@ -9,14 +9,13 @@ using Infrastructure.Enums;
|
||||
using Infrastructure.Model;
|
||||
using Mapster;
|
||||
using ZR.Model.Dto;
|
||||
using ZR.Model.Models;
|
||||
using ZR.Service.Business;
|
||||
using ZR.Admin.WebApi.Extensions;
|
||||
using ZR.Admin.WebApi.Filters;
|
||||
using ZR.Common;
|
||||
using ZR.Service.System;
|
||||
using ZR.Model.System;
|
||||
using Infrastructure.Extensions;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
|
||||
namespace ZR.Admin.WebApi.Controllers
|
||||
{
|
||||
@ -83,6 +82,7 @@ namespace ZR.Admin.WebApi.Controllers
|
||||
/// <param name="configKey"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("configKey/{configKey}")]
|
||||
[AllowAnonymous]
|
||||
public IActionResult GetConfigKey(string configKey)
|
||||
{
|
||||
//TODO 增加缓存
|
||||
@ -107,7 +107,7 @@ namespace ZR.Admin.WebApi.Controllers
|
||||
//从 Dto 映射到 实体
|
||||
var model = parm.Adapt<SysConfig>().ToCreate();
|
||||
|
||||
return SUCCESS(_SysConfigService.Add(model, it => new
|
||||
return SUCCESS(_SysConfigService.Insert(model, it => new
|
||||
{
|
||||
it.ConfigName,
|
||||
it.ConfigKey,
|
||||
@ -144,6 +144,7 @@ namespace ZR.Admin.WebApi.Controllers
|
||||
ConfigType = model.ConfigType,
|
||||
Update_by = model.Update_by,
|
||||
Update_time = model.Update_time,
|
||||
Remark = model.Remark
|
||||
});
|
||||
|
||||
return SUCCESS(response);
|
||||
|
||||
@ -38,10 +38,8 @@ namespace ZR.Admin.WebApi.Controllers.System
|
||||
[HttpGet("list")]
|
||||
public IActionResult List([FromQuery] SysDictData dictData, [FromQuery] PagerInfo pagerInfo)
|
||||
{
|
||||
var list = SysDictDataService.SelectDictDataList(dictData);
|
||||
pagerInfo.TotalNum = list.Count;
|
||||
var vm = new VMPageResult<SysDictData>(list, pagerInfo);
|
||||
return SUCCESS(vm);
|
||||
var list = SysDictDataService.SelectDictDataList(dictData, pagerInfo);
|
||||
return SUCCESS(list);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -107,7 +105,7 @@ namespace ZR.Admin.WebApi.Controllers.System
|
||||
[HttpDelete("{dictCode}")]
|
||||
public IActionResult Remove(string dictCode)
|
||||
{
|
||||
long[] dictCodes = ZR.Common.Tools.SpitLongArrary(dictCode);
|
||||
long[] dictCodes = Common.Tools.SpitLongArrary(dictCode);
|
||||
|
||||
return SUCCESS(SysDictDataService.DeleteDictDataByIds(dictCodes));
|
||||
}
|
||||
|
||||
@ -38,8 +38,7 @@ namespace ZR.Admin.WebApi.Controllers.System
|
||||
{
|
||||
var list = SysDictService.SelectDictTypeList(dict, pagerInfo);
|
||||
|
||||
var vm = new VMPageResult<SysDictType>(list, pagerInfo);
|
||||
return SUCCESS(vm, TIME_FORMAT_FULL);
|
||||
return SUCCESS(list, TIME_FORMAT_FULL);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@ -15,6 +15,7 @@ using ZR.Model.System.Dto;
|
||||
using ZR.Service.System.IService;
|
||||
using Hei.Captcha;
|
||||
using ZR.Common;
|
||||
using ZR.Service.System;
|
||||
|
||||
namespace ZR.Admin.WebApi.Controllers.System
|
||||
{
|
||||
@ -30,6 +31,7 @@ namespace ZR.Admin.WebApi.Controllers.System
|
||||
private readonly ISysLoginService sysLoginService;
|
||||
private readonly ISysPermissionService permissionService;
|
||||
private readonly SecurityCodeHelper SecurityCodeHelper;
|
||||
private readonly ISysConfigService sysConfigService;
|
||||
|
||||
public SysLoginController(
|
||||
IHttpContextAccessor contextAccessor,
|
||||
@ -37,6 +39,7 @@ namespace ZR.Admin.WebApi.Controllers.System
|
||||
ISysUserService sysUserService,
|
||||
ISysLoginService sysLoginService,
|
||||
ISysPermissionService permissionService,
|
||||
ISysConfigService configService,
|
||||
SecurityCodeHelper captcha)
|
||||
{
|
||||
httpContextAccessor = contextAccessor;
|
||||
@ -45,6 +48,7 @@ namespace ZR.Admin.WebApi.Controllers.System
|
||||
this.sysUserService = sysUserService;
|
||||
this.sysLoginService = sysLoginService;
|
||||
this.permissionService = permissionService;
|
||||
this.sysConfigService = configService;
|
||||
}
|
||||
|
||||
|
||||
@ -60,7 +64,8 @@ namespace ZR.Admin.WebApi.Controllers.System
|
||||
{
|
||||
if (loginBody == null) { throw new CustomException("请求参数错误"); }
|
||||
loginBody.LoginIP = HttpContextExtension.GetClientUserIp(HttpContext);
|
||||
if (CacheHelper.Get(loginBody.Uuid) is string str && !str.ToLower().Equals(loginBody.Code.ToLower()))
|
||||
SysConfig sysConfig = sysConfigService.GetSysConfigByKey("sys.account.captchaOnOff");
|
||||
if (sysConfig?.ConfigValue != "off" && CacheHelper.Get(loginBody.Uuid) is string str && !str.ToLower().Equals(loginBody.Code.ToLower()))
|
||||
{
|
||||
throw new CustomException(ResultCode.CAPTCHA_ERROR, "验证码错误");
|
||||
}
|
||||
@ -74,7 +79,7 @@ namespace ZR.Admin.WebApi.Controllers.System
|
||||
#endregion
|
||||
LoginUser loginUser = new LoginUser(user.UserId, user.UserName, roles, permissions);
|
||||
|
||||
return SUCCESS(JwtUtil.GenerateJwtToken(HttpContext.WriteCookies(loginUser)));
|
||||
return SUCCESS(JwtUtil.GenerateJwtToken(HttpContext.AddClaims(loginUser)));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -85,11 +90,11 @@ namespace ZR.Admin.WebApi.Controllers.System
|
||||
[HttpPost("logout")]
|
||||
public IActionResult LogOut()
|
||||
{
|
||||
Task.Run(async () =>
|
||||
{
|
||||
//注销登录的用户,相当于ASP.NET中的FormsAuthentication.SignOut
|
||||
await HttpContext.SignOutAsync();
|
||||
}).Wait();
|
||||
//Task.Run(async () =>
|
||||
//{
|
||||
// //注销登录的用户,相当于ASP.NET中的FormsAuthentication.SignOut
|
||||
// await HttpContext.SignOutAsync();
|
||||
//}).Wait();
|
||||
|
||||
return SUCCESS(1);
|
||||
}
|
||||
@ -136,8 +141,26 @@ namespace ZR.Admin.WebApi.Controllers.System
|
||||
public ApiResult CaptchaImage()
|
||||
{
|
||||
string uuid = Guid.NewGuid().ToString().Replace("-", "");
|
||||
|
||||
SysConfig sysConfig = sysConfigService.GetSysConfigByKey("sys.account.captchaOnOff");
|
||||
var code = SecurityCodeHelper.GetRandomEnDigitalText(4);
|
||||
var imgByte = SecurityCodeHelper.GetEnDigitalCodeByte(code);
|
||||
byte[] imgByte;
|
||||
if (sysConfig.ConfigValue == "1")
|
||||
{
|
||||
imgByte = SecurityCodeHelper.GetGifEnDigitalCodeByte(code);//动态gif数字字母
|
||||
}
|
||||
else if (sysConfig.ConfigValue == "2")
|
||||
{
|
||||
imgByte = SecurityCodeHelper.GetGifBubbleCodeByte(code);//动态gif泡泡
|
||||
}
|
||||
else if (sysConfig.ConfigValue == "3")
|
||||
{
|
||||
imgByte = SecurityCodeHelper.GetBubbleCodeByte(code);//泡泡
|
||||
}
|
||||
else
|
||||
{
|
||||
imgByte = SecurityCodeHelper.GetEnDigitalCodeByte(code);//英文字母加数字
|
||||
}
|
||||
string base64Str = Convert.ToBase64String(imgByte);
|
||||
CacheHelper.SetCache(uuid, code);
|
||||
var obj = new { uuid, img = base64Str };// File(stream, "image/png")
|
||||
|
||||
@ -120,6 +120,7 @@ namespace ZR.Admin.WebApi.Controllers.System
|
||||
/// <summary>
|
||||
/// 修改头像
|
||||
/// </summary>
|
||||
/// <param name="formFile"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("Avatar")]
|
||||
[ActionPermissionFilter(Permission = "system")]
|
||||
@ -131,7 +132,7 @@ namespace ZR.Admin.WebApi.Controllers.System
|
||||
if (formFile == null) throw new CustomException("请选择文件");
|
||||
|
||||
string fileExt = Path.GetExtension(formFile.FileName);
|
||||
string savePath = Path.Combine("wwwroot", FileUtil.GetdirPath("uploads"));
|
||||
string savePath = Path.Combine(hostEnvironment.WebRootPath, FileUtil.GetdirPath("uploads"));
|
||||
|
||||
Console.WriteLine(savePath);
|
||||
if (!Directory.Exists(savePath)) { Directory.CreateDirectory(savePath); }
|
||||
@ -141,7 +142,7 @@ namespace ZR.Admin.WebApi.Controllers.System
|
||||
|
||||
using (var stream = new FileStream(finalFilePath, FileMode.Create))
|
||||
{
|
||||
formFile.CopyToAsync(stream);
|
||||
formFile.CopyTo(stream);
|
||||
}
|
||||
string accessUrl = $"{OptionsSetting.Upload.UploadUrl}/{FileUtil.GetdirPath("uploads")}{fileName}";
|
||||
|
||||
|
||||
@ -11,7 +11,7 @@ using System.IO;
|
||||
using ZR.Admin.WebApi.Filters;
|
||||
using ZR.Model;
|
||||
using ZR.Model.System;
|
||||
using ZR.Model.Vo;
|
||||
using ZR.Service;
|
||||
using ZR.Service.System.IService;
|
||||
|
||||
namespace ZR.Admin.WebApi.Controllers.System
|
||||
@ -53,9 +53,7 @@ namespace ZR.Admin.WebApi.Controllers.System
|
||||
{
|
||||
var list = UserService.SelectUserList(user, pager);
|
||||
|
||||
var vm = new VMPageResult<SysUser>(list, pager);
|
||||
|
||||
return SUCCESS(vm, TIME_FORMAT_FULL);
|
||||
return SUCCESS(list.ToPage(pager), TIME_FORMAT_FULL);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -220,48 +218,10 @@ namespace ZR.Admin.WebApi.Controllers.System
|
||||
[ActionPermissionFilter(Permission = "system:user:export")]
|
||||
public IActionResult UserExport([FromQuery] SysUser user)
|
||||
{
|
||||
string sFileName = $"用户列表{DateTime.Now:yyyyMMddHHmmss}.xlsx";
|
||||
string newFileName = Path.Combine(WebHostEnvironment.WebRootPath, "export", sFileName);
|
||||
var list = UserService.SelectUserList(user, new PagerInfo(1, 10000));
|
||||
|
||||
//调试模式需要加上
|
||||
ExcelPackage.LicenseContext = LicenseContext.NonCommercial;
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(newFileName));
|
||||
using (ExcelPackage package = new ExcelPackage(new FileInfo(newFileName)))
|
||||
{
|
||||
// 添加worksheet
|
||||
ExcelWorksheet worksheet = package.Workbook.Worksheets.Add("sysuser");
|
||||
#region 自定义导出
|
||||
//添加头
|
||||
//worksheet.Cells[1, 1].Value = "用户id";
|
||||
//worksheet.Cells[1, 2].Value = "用户名称";
|
||||
//worksheet.Cells[1, 3].Value = "用户昵称";
|
||||
//worksheet.Cells[1, 4].Value = "部门";
|
||||
//worksheet.Cells[1, 5].Value = "手机号码";
|
||||
//worksheet.Cells[1, 6].Value = "性别";
|
||||
//worksheet.Cells[1, 7].Value = "状态";
|
||||
//worksheet.Cells[1, 8].Value = "添加时间";
|
||||
//worksheet.Cells[1, 9].Value = "登录IP";
|
||||
//worksheet.Cells[1, 10].Value = "最后登录时间";
|
||||
//for (int i = 0; i < list.Count; i++)
|
||||
//{
|
||||
// var item = list[i];
|
||||
// //worksheet.Cells[i + 2, 1].Value = item.UserId;
|
||||
// //worksheet.Cells[i + 2, 2].Value = item.UserName;
|
||||
// //worksheet.Cells[i + 2, 3].Value = item.NickName;
|
||||
// //worksheet.Cells[i + 2, 4].Value = item.DeptName;
|
||||
// //worksheet.Cells[i + 2, 5].Value = item.Phonenumber;
|
||||
// //worksheet.Cells[i + 2, 6].Value = item.Sex;
|
||||
// //worksheet.Cells[i + 2, 7].Value = item.Status;
|
||||
// //worksheet.Cells[i + 2, 8].Value = item.Create_time.ToString();
|
||||
// //worksheet.Cells[i + 2, 9].Value = item.LoginIP;
|
||||
// //worksheet.Cells[i + 2, 10].Value = item.LoginDate.ToString();
|
||||
//}
|
||||
#endregion
|
||||
//全部字段导出
|
||||
worksheet.Cells.LoadFromCollection(list, true);
|
||||
package.Save();
|
||||
}
|
||||
string sFileName = ExportExcel(list, "user", "用户列表");
|
||||
return SUCCESS(new { path = "/export/" + sFileName, fileName = sFileName });
|
||||
}
|
||||
}
|
||||
|
||||
@ -20,7 +20,7 @@ namespace ZR.Admin.WebApi.Controllers
|
||||
/// <summary>
|
||||
/// 计划任务
|
||||
/// </summary>
|
||||
//[Verify]
|
||||
[Verify]
|
||||
[Route("system/Tasks")]
|
||||
public class TasksController : BaseController
|
||||
{
|
||||
@ -51,7 +51,7 @@ namespace ZR.Admin.WebApi.Controllers
|
||||
m.JobGroup.Contains(parm.QueryText) ||
|
||||
m.AssemblyName.Contains(parm.QueryText));
|
||||
|
||||
var response = _tasksQzService.GetPages(predicate.ToExpression(), pager, f => f.IsStart, "Desc");
|
||||
var response = _tasksQzService.GetPages(predicate.ToExpression(), pager, f => f.IsStart, OrderByType.Desc);
|
||||
|
||||
return SUCCESS(response, TIME_FORMAT_FULL);
|
||||
}
|
||||
|
||||
@ -13,6 +13,7 @@ using Infrastructure;
|
||||
|
||||
namespace ZR.Admin.WebApi.Controllers.System
|
||||
{
|
||||
[Verify]
|
||||
[Route("/monitor/jobLog")]
|
||||
public class TasksLogController : BaseController
|
||||
{
|
||||
@ -42,7 +43,7 @@ namespace ZR.Admin.WebApi.Controllers.System
|
||||
predicate = predicate.AndIF(queryDto.Status.IfNotEmpty(), m => m.Status == queryDto.Status);
|
||||
predicate = predicate.AndIF(queryDto.JobId.IfNotEmpty(), m => m.JobId == queryDto.JobId);
|
||||
|
||||
var response = tasksLogService.GetPages(predicate.ToExpression(), pager, m => m.CreateTime, "Desc");
|
||||
var response = tasksLogService.GetPages(predicate.ToExpression(), pager, m => m.CreateTime, OrderByType.Desc);
|
||||
|
||||
return SUCCESS(response, TIME_FORMAT_FULL);
|
||||
}
|
||||
|
||||
@ -38,9 +38,8 @@ namespace ZR.Admin.WebApi.Controllers.monitor
|
||||
public IActionResult LoignLogList([FromQuery] SysLogininfor sysLogininfoDto, [FromQuery] PagerInfo pagerInfo)
|
||||
{
|
||||
var list = sysLoginService.GetLoginLog(sysLogininfoDto, pagerInfo);
|
||||
var vMPage = new VMPageResult<SysLogininfor>(list, pagerInfo);
|
||||
|
||||
return ToResponse(ToJson(vMPage.TotalNum, vMPage), TIME_FORMAT_FULL_2);
|
||||
return ToResponse(ToJson(list.Count, list.ToPage(pagerInfo)), TIME_FORMAT_FULL_2);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@ -41,9 +41,8 @@ namespace ZR.Admin.WebApi.Controllers.monitor
|
||||
PagerInfo pagerInfo = new PagerInfo(sysOperLog.pageNum);
|
||||
|
||||
var list = sysOperLogService.SelectOperLogList(sysOperLog, pagerInfo);
|
||||
var vMPage = new VMPageResult<SysOperLog>(list, pagerInfo);
|
||||
|
||||
return ToResponse(ToJson(vMPage.TotalNum, vMPage), TIME_FORMAT_FULL_2);
|
||||
return ToResponse(ToJson(list.TotalNum, list), TIME_FORMAT_FULL_2);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -84,7 +83,7 @@ namespace ZR.Admin.WebApi.Controllers.monitor
|
||||
public IActionResult Export([FromQuery] SysOperLogDto sysOperLog)
|
||||
{
|
||||
var list = sysOperLogService.SelectOperLogList(sysOperLog, new PagerInfo(1, 10000));
|
||||
string sFileName = ExportExcel(list, "operlog", "操作日志");
|
||||
string sFileName = ExportExcel(list.Result, "operlog", "操作日志");
|
||||
return SUCCESS(new { path = "/export/" + sFileName, fileName = sFileName });
|
||||
}
|
||||
|
||||
|
||||
@ -1,54 +0,0 @@
|
||||
using Infrastructure;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Options;
|
||||
using System;
|
||||
using System.IO;
|
||||
using ZR.Admin.WebApi.Filters;
|
||||
using ZR.Common;
|
||||
|
||||
namespace ZR.Admin.WebApi.Controllers
|
||||
{
|
||||
[Route("[controller]/[action]")]
|
||||
public class UploadController : BaseController
|
||||
{
|
||||
private NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
|
||||
private OptionsSetting OptionsSetting;
|
||||
private IWebHostEnvironment WebHostEnvironment;
|
||||
public UploadController(IOptions<OptionsSetting> optionsSetting, IWebHostEnvironment webHostEnvironment)
|
||||
{
|
||||
OptionsSetting = optionsSetting.Value;
|
||||
WebHostEnvironment = webHostEnvironment;
|
||||
}
|
||||
/// <summary>
|
||||
/// 存储文件
|
||||
/// </summary>
|
||||
/// <param name="formFile"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Verify]
|
||||
[ActionPermissionFilter(Permission = "system")]
|
||||
public IActionResult SaveFile([FromForm(Name = "file")] IFormFile formFile)
|
||||
{
|
||||
if (formFile == null) throw new CustomException(ResultCode.PARAM_ERROR, "上传图片不能为空");
|
||||
string fileExt = Path.GetExtension(formFile.FileName);
|
||||
string fileName = FileUtil.HashFileName(Guid.NewGuid().ToString()).ToLower() + fileExt;
|
||||
string finalFilePath = Path.Combine(WebHostEnvironment.WebRootPath, FileUtil.GetdirPath("uploads"), fileName);
|
||||
finalFilePath = finalFilePath.Replace("\\", "/").Replace("//", "/");
|
||||
|
||||
if (!Directory.Exists(Path.GetDirectoryName(finalFilePath)))
|
||||
{
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(finalFilePath));
|
||||
}
|
||||
|
||||
using (var stream = new FileStream(finalFilePath, FileMode.Create))
|
||||
{
|
||||
formFile.CopyToAsync(stream);
|
||||
}
|
||||
|
||||
string accessPath = $"{OptionsSetting.Upload.UploadUrl}/{FileUtil.GetdirPath("uploads").Replace("\\", " /")}{fileName}";
|
||||
return ToResponse(ResultCode.SUCCESS, new { accessPath, fullPath = finalFilePath });
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,154 +0,0 @@
|
||||
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 ZR.Model.Dto;
|
||||
using ZR.Model.Models;
|
||||
using ZR.Service.Business;
|
||||
using ZR.Admin.WebApi.Extensions;
|
||||
using ZR.Admin.WebApi.Filters;
|
||||
using ZR.Common;
|
||||
using Infrastructure.Extensions;
|
||||
|
||||
namespace ZR.Admin.WebApi.Controllers
|
||||
{
|
||||
/// <summary>
|
||||
/// 代码生成演示Controller
|
||||
///
|
||||
/// @author zr
|
||||
/// @date 2021-11-24
|
||||
/// </summary>
|
||||
[Verify]
|
||||
[Route("business/Gendemo")]
|
||||
public class GendemoController : BaseController
|
||||
{
|
||||
/// <summary>
|
||||
/// 代码生成演示接口
|
||||
/// </summary>
|
||||
private readonly IGendemoService _GendemoService;
|
||||
|
||||
public GendemoController(IGendemoService GendemoService)
|
||||
{
|
||||
_GendemoService = GendemoService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查询代码生成演示列表
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet("list")]
|
||||
[ActionPermissionFilter(Permission = "business:gendemo:list")]
|
||||
public IActionResult QueryGendemo([FromQuery] GendemoQueryDto parm)
|
||||
{
|
||||
//开始拼装查询条件
|
||||
var predicate = Expressionable.Create<Gendemo>();
|
||||
|
||||
//TODO 自己实现搜索条件查询语法参考Sqlsugar,默认查询所有
|
||||
//predicate = predicate.And(m => m.Name.Contains(parm.Name));
|
||||
|
||||
var response = _GendemoService.GetPages(predicate.ToExpression(), parm);
|
||||
|
||||
return SUCCESS(response);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查询代码生成演示详情
|
||||
/// </summary>
|
||||
/// <param name="Id"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("{Id}")]
|
||||
[ActionPermissionFilter(Permission = "business:gendemo:query")]
|
||||
public IActionResult GetGendemo(int Id)
|
||||
{
|
||||
var response = _GendemoService.GetId(Id);
|
||||
|
||||
return SUCCESS(response);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加代码生成演示
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[ActionPermissionFilter(Permission = "business:gendemo:add")]
|
||||
[Log(Title = "代码生成演示", BusinessType = BusinessType.INSERT)]
|
||||
public IActionResult AddGendemo([FromBody] GendemoDto parm)
|
||||
{
|
||||
if (parm == null)
|
||||
{
|
||||
throw new CustomException("请求参数错误");
|
||||
}
|
||||
//从 Dto 映射到 实体
|
||||
var model = parm.Adapt<Gendemo>().ToCreate(HttpContext);
|
||||
|
||||
return SUCCESS(_GendemoService.Add(model, it => new
|
||||
{
|
||||
it.Name,
|
||||
it.Icon,
|
||||
it.ShowStatus,
|
||||
it.AddTime,
|
||||
it.Sex,
|
||||
it.Sort,
|
||||
it.BeginTime,
|
||||
it.EndTime,
|
||||
it.Remark,
|
||||
}));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新代码生成演示
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPut]
|
||||
[ActionPermissionFilter(Permission = "business:gendemo:update")]
|
||||
[Log(Title = "代码生成演示", BusinessType = BusinessType.UPDATE)]
|
||||
public IActionResult UpdateGendemo([FromBody] GendemoDto parm)
|
||||
{
|
||||
if (parm == null)
|
||||
{
|
||||
throw new CustomException("请求实体不能为空");
|
||||
}
|
||||
//从 Dto 映射到 实体
|
||||
var model = parm.Adapt<Gendemo>().ToUpdate(HttpContext);
|
||||
|
||||
var response = _GendemoService.Update(w => w.Id == model.Id, it => new Gendemo()
|
||||
{
|
||||
//Update 字段映射
|
||||
Name = model.Name,
|
||||
Icon = model.Icon,
|
||||
ShowStatus = model.ShowStatus,
|
||||
AddTime = model.AddTime,
|
||||
Sex = model.Sex,
|
||||
Sort = model.Sort,
|
||||
BeginTime = model.BeginTime,
|
||||
EndTime = model.EndTime,
|
||||
Remark = model.Remark,
|
||||
});
|
||||
|
||||
return SUCCESS(response);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除代码生成演示
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpDelete("{ids}")]
|
||||
[ActionPermissionFilter(Permission = "business:gendemo:delete")]
|
||||
[Log(Title = "代码生成演示", BusinessType = BusinessType.DELETE)]
|
||||
public IActionResult DeleteGendemo(string ids)
|
||||
{
|
||||
int[] idsArr = Tools.SpitIntArrary(ids);
|
||||
if (idsArr.Length <= 0) { return ToResponse(ApiResult.Error($"删除失败Id 不能为空")); }
|
||||
|
||||
var response = _GendemoService.Delete(idsArr);
|
||||
|
||||
return SUCCESS(response);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,6 +1,7 @@
|
||||
using Infrastructure;
|
||||
using Microsoft.AspNetCore.Authentication;
|
||||
using Microsoft.AspNetCore.Authentication.Cookies;
|
||||
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
@ -75,6 +76,16 @@ namespace ZR.Admin.WebApi.Extensions
|
||||
|
||||
return uid;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// ClaimsIdentity
|
||||
/// </summary>
|
||||
/// <param name="context"></param>
|
||||
/// <returns></returns>
|
||||
public static IEnumerable<ClaimsIdentity> GetClaims(this HttpContext context)
|
||||
{
|
||||
return context.User?.Identities;
|
||||
}
|
||||
//public static int GetRole(this HttpContext context)
|
||||
//{
|
||||
// var roleid = context.User.FindFirstValue(ClaimTypes.Role) ?? "0";
|
||||
@ -84,9 +95,7 @@ namespace ZR.Admin.WebApi.Extensions
|
||||
|
||||
public static string GetUserAgent(this HttpContext context)
|
||||
{
|
||||
var str = context.Request.Headers["User-Agent"];
|
||||
|
||||
return str;
|
||||
return context.Request.Headers["User-Agent"];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -96,9 +105,7 @@ namespace ZR.Admin.WebApi.Extensions
|
||||
/// <returns></returns>
|
||||
public static string GetToken(this HttpContext context)
|
||||
{
|
||||
var str = context.Request.Headers["Token"];
|
||||
|
||||
return str;
|
||||
return context.Request.Headers["Authorization"];
|
||||
}
|
||||
|
||||
public static ClientInfo GetClientInfo(this HttpContext context)
|
||||
@ -116,12 +123,12 @@ namespace ZR.Admin.WebApi.Extensions
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 登录cookie写入
|
||||
///组装Claims
|
||||
/// </summary>
|
||||
/// <param name="context"></param>
|
||||
/// <param name="user"></param>
|
||||
/// <returns></returns>
|
||||
public static List<Claim> WriteCookies(this HttpContext context, LoginUser user)
|
||||
public static List<Claim> AddClaims(this HttpContext context, LoginUser user)
|
||||
{
|
||||
//1、创建Cookie保存用户信息,使用claim
|
||||
var claims = new List<Claim>()
|
||||
@ -138,13 +145,21 @@ namespace ZR.Admin.WebApi.Extensions
|
||||
{
|
||||
claims.Add(new Claim("perm", string.Join(",", user.Permissions)));
|
||||
}
|
||||
|
||||
//写入Cookie
|
||||
//WhiteCookie(context, claims);
|
||||
return claims;
|
||||
}
|
||||
|
||||
private static void WhiteCookie(HttpContext context, List<Claim> claims)
|
||||
{
|
||||
//2.创建声明主题 指定认证方式 这里使用cookie
|
||||
var claimsIdentity = new ClaimsIdentity(claims, "Login");
|
||||
|
||||
Task.Run(async () =>
|
||||
{
|
||||
await context.SignInAsync(
|
||||
CookieAuthenticationDefaults.AuthenticationScheme,//这里要注意的是HttpContext.SignInAsync(AuthenticationType,…) 所设置的Scheme一定要与前面的配置一样,这样对应的登录授权才会生效。
|
||||
JwtBearerDefaults.AuthenticationScheme,//这里要注意的是HttpContext.SignInAsync(AuthenticationType,…) 所设置的Scheme一定要与前面的配置一样,这样对应的登录授权才会生效。
|
||||
new ClaimsPrincipal(claimsIdentity),
|
||||
new AuthenticationProperties()
|
||||
{
|
||||
@ -153,7 +168,6 @@ namespace ZR.Admin.WebApi.Extensions
|
||||
ExpiresUtc = DateTimeOffset.Now.AddDays(1),//有效时间
|
||||
});
|
||||
}).Wait();
|
||||
return claims;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
57
ZR.Admin.WebApi/Extensions/SwaggerExtension.cs
Normal file
57
ZR.Admin.WebApi/Extensions/SwaggerExtension.cs
Normal file
@ -0,0 +1,57 @@
|
||||
using Infrastructure;
|
||||
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.OpenApi.Models;
|
||||
using Swashbuckle.AspNetCore.Filters;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ZR.Admin.WebApi.Extensions
|
||||
{
|
||||
public static class SwaggerExtension
|
||||
{
|
||||
public static void AddSwaggerConfig(this IServiceCollection services)
|
||||
{
|
||||
if (services == null) throw new ArgumentNullException(nameof(services));
|
||||
IWebHostEnvironment hostEnvironment = App.GetRequiredService<IWebHostEnvironment>();
|
||||
|
||||
services.AddSwaggerGen(c =>
|
||||
{
|
||||
c.SwaggerDoc("v1", new OpenApiInfo
|
||||
{
|
||||
Title = "ZrAdmin.NET Api - .NET5",
|
||||
Version = "v1",
|
||||
Description = "",
|
||||
});
|
||||
//if (CurrentEnvironment.IsDevelopment())
|
||||
//{
|
||||
//添加文档注释
|
||||
c.IncludeXmlComments(Path.Combine(hostEnvironment.ContentRootPath, "ZRAdmin.xml"), true);
|
||||
//}
|
||||
//参考文章:http://www.zyiz.net/tech/detail-134965.html
|
||||
//需要安装包Swashbuckle.AspNetCore.Filters
|
||||
// 开启权限小锁 需要在对应的Action上添加[Authorize]才能看到
|
||||
c.OperationFilter<AddResponseHeadersFilter>();
|
||||
c.OperationFilter<AppendAuthorizeToSummaryOperationFilter>();
|
||||
|
||||
//在header 中添加token,传递到后台
|
||||
c.OperationFilter<SecurityRequirementsOperationFilter>();
|
||||
|
||||
c.AddSecurityDefinition(JwtBearerDefaults.AuthenticationScheme,
|
||||
new OpenApiSecurityScheme
|
||||
{
|
||||
In = ParameterLocation.Header,
|
||||
Description = "请输入Login接口返回的Token,前置Bearer。示例:Bearer {Token}",
|
||||
Name = "Authorization",//jwt默认的参数名称,
|
||||
Type = SecuritySchemeType.ApiKey, //指定ApiKey
|
||||
BearerFormat = "JWT",//标识承载令牌的格式 该信息主要是出于文档目的
|
||||
Scheme = JwtBearerDefaults.AuthenticationScheme//授权中要使用的HTTP授权方案的名称
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -10,6 +10,7 @@ using NLog;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using ZR.Admin.WebApi.Extensions;
|
||||
using ZR.Admin.WebApi.Framework;
|
||||
using ZR.Model.System;
|
||||
|
||||
namespace ZR.Admin.WebApi.Filters
|
||||
@ -44,12 +45,10 @@ namespace ZR.Admin.WebApi.Filters
|
||||
string ip = HttpContextExtension.GetClientUserIp(context.HttpContext);
|
||||
string url = context.HttpContext.Request.Path;
|
||||
var isAuthed = context.HttpContext.User.Identity.IsAuthenticated;
|
||||
// 检查登陆 - 在SignIn中判断用户合法性,将登陆信息保存在Cookie中,在SignOut中移除登陆信息
|
||||
var userName = context.HttpContext.User.Identity.Name;
|
||||
|
||||
//使用jwt token校验2020-11-21
|
||||
//string token = context.HttpContext.Request.Headers["Token"];
|
||||
LoginUser info = Framework.JwtUtil.GetLoginUser(context.HttpContext);
|
||||
LoginUser info = JwtUtil.GetLoginUser(context.HttpContext);
|
||||
|
||||
if (info != null && info.UserId > 0)
|
||||
{
|
||||
@ -58,7 +57,7 @@ namespace ZR.Admin.WebApi.Filters
|
||||
else
|
||||
{
|
||||
string msg = $"请求访问:{url}授权认证失败,无法访问系统资源";
|
||||
logger.Info(msg);
|
||||
logger.Info($"用户{userName}{msg}");
|
||||
|
||||
context.Result = new JsonResult(new ApiResult((int)ResultCode.DENY, msg));
|
||||
}
|
||||
|
||||
@ -18,8 +18,6 @@ namespace ZR.Admin.WebApi.Framework
|
||||
/// </summary>
|
||||
public class JwtUtil
|
||||
{
|
||||
public static readonly string KEY = "asdfghjklzxcvbnm";
|
||||
|
||||
/// <summary>
|
||||
/// 获取用户身份信息
|
||||
/// </summary>
|
||||
@ -28,6 +26,7 @@ namespace ZR.Admin.WebApi.Framework
|
||||
public static LoginUser GetLoginUser(HttpContext httpContext)
|
||||
{
|
||||
string token = HttpContextExtension.GetToken(httpContext);
|
||||
|
||||
if (!string.IsNullOrEmpty(token))
|
||||
{
|
||||
return ValidateJwtToken(ParseToken(token));
|
||||
@ -42,21 +41,52 @@ namespace ZR.Admin.WebApi.Framework
|
||||
/// <returns></returns>
|
||||
public static string GenerateJwtToken(List<Claim> claims)
|
||||
{
|
||||
JwtSettings jwtSettings = new();
|
||||
ConfigUtils.Instance.Bind("JwtSettings", jwtSettings);
|
||||
|
||||
var tokenHandler = new JwtSecurityTokenHandler();
|
||||
var key = Encoding.ASCII.GetBytes(KEY);
|
||||
var expires = ConfigUtils.Instance.GetAppConfig("sysConfig:tokenExpire", 10);
|
||||
var key = Encoding.ASCII.GetBytes(jwtSettings.SecretKey);
|
||||
claims.Add(new Claim("Audience", jwtSettings.Audience));
|
||||
claims.Add(new Claim("Issuer", jwtSettings.Issuer));
|
||||
|
||||
var tokenDescriptor = new SecurityTokenDescriptor
|
||||
{
|
||||
Subject = new ClaimsIdentity(claims),
|
||||
//Issuer = "",
|
||||
//Audience = "",
|
||||
Expires = DateTime.Now.AddMinutes(expires),
|
||||
Issuer = jwtSettings.Issuer,
|
||||
Audience = jwtSettings.Audience,
|
||||
IssuedAt = DateTime.Now,//token生成时间
|
||||
Expires = DateTime.Now.AddMinutes(jwtSettings.Expire),
|
||||
TokenType = "Bearer",
|
||||
//对称秘钥,签名证书
|
||||
SigningCredentials = new SigningCredentials(new SymmetricSecurityKey(key), SecurityAlgorithms.HmacSha256Signature)
|
||||
};
|
||||
var token = tokenHandler.CreateToken(tokenDescriptor);
|
||||
return tokenHandler.WriteToken(token);
|
||||
}
|
||||
/// <summary>
|
||||
/// 验证Token
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static TokenValidationParameters ValidParameters()
|
||||
{
|
||||
JwtSettings jwtSettings = new();
|
||||
ConfigUtils.Instance.Bind("JwtSettings", jwtSettings);
|
||||
|
||||
var key = Encoding.ASCII.GetBytes(jwtSettings.SecretKey);
|
||||
|
||||
var tokenDescriptor = new TokenValidationParameters
|
||||
{
|
||||
ValidateIssuerSigningKey = true,
|
||||
ValidateIssuer = true,
|
||||
ValidateAudience = true,
|
||||
ValidIssuer = jwtSettings.Issuer,
|
||||
ValidAudience = jwtSettings.Audience,
|
||||
IssuerSigningKey = new SymmetricSecurityKey(key),
|
||||
ValidateLifetime = true,//是否验证Token有效期,使用当前时间与Token的Claims中的NotBefore和Expires对比
|
||||
RequireExpirationTime = true,//过期时间
|
||||
};
|
||||
return tokenDescriptor;
|
||||
}
|
||||
/// <summary>
|
||||
/// 从令牌中获取数据声明
|
||||
/// </summary>
|
||||
@ -65,21 +95,13 @@ namespace ZR.Admin.WebApi.Framework
|
||||
public static IEnumerable<Claim> ParseToken(string token)
|
||||
{
|
||||
var tokenHandler = new JwtSecurityTokenHandler();
|
||||
var key = Encoding.ASCII.GetBytes(KEY);
|
||||
var validateParameter = ValidParameters();
|
||||
token = token.Replace("Bearer ", "");
|
||||
try
|
||||
{
|
||||
tokenHandler.ValidateToken(token, new TokenValidationParameters
|
||||
{
|
||||
ValidateIssuerSigningKey = true,
|
||||
IssuerSigningKey = new SymmetricSecurityKey(key),
|
||||
ValidateIssuer = false,
|
||||
ValidateAudience = false,
|
||||
// set clockskew to zero so tokens expire exactly at token expiration time (instead of 5 minutes later)
|
||||
ClockSkew = TimeSpan.Zero
|
||||
}, out SecurityToken validatedToken);
|
||||
tokenHandler.ValidateToken(token, validateParameter, out SecurityToken validatedToken);
|
||||
|
||||
//{{"alg":"HS256","typ":"JWT"}.{"http://schemas.xmlsoap.org/ws/2005/05/identity/claims/sid":"2","unique_name":"ry","nameid":"2","given_name":"若依","nbf":1606654010,"exp":1606740410,"iat":1606654010}}
|
||||
var jwtToken = (JwtSecurityToken)validatedToken;
|
||||
var jwtToken = tokenHandler.ReadJwtToken(token);
|
||||
return jwtToken.Claims;
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
||||
@ -2,11 +2,11 @@
|
||||
"profiles": {
|
||||
"ZRAdmin": {
|
||||
"commandName": "Project",
|
||||
"launchBrowser": true,
|
||||
"launchBrowser": false,
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": ""
|
||||
"ASPNETCORE_ENVIRONMENT": "Production"
|
||||
},
|
||||
"applicationUrl": "https://localhost:5001;http://localhost:5000"
|
||||
"applicationUrl": "http://localhost:8888"
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -2,6 +2,7 @@ using Hei.Captcha;
|
||||
using Infrastructure;
|
||||
using Infrastructure.Extensions;
|
||||
using Microsoft.AspNetCore.Authentication.Cookies;
|
||||
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.DataProtection;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
@ -12,6 +13,7 @@ using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.OpenApi.Models;
|
||||
using SqlSugar.IOC;
|
||||
using Swashbuckle.AspNetCore.Filters;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
@ -42,7 +44,7 @@ namespace ZR.Admin.WebApi
|
||||
{
|
||||
c.AddPolicy("Policy", policy =>
|
||||
{
|
||||
policy.WithOrigins(corsUrls.Split(',', System.StringSplitOptions.RemoveEmptyEntries))
|
||||
policy.WithOrigins(corsUrls.Split(',', StringSplitOptions.RemoveEmptyEntries))
|
||||
.AllowAnyHeader()//允许任意头
|
||||
.AllowCredentials()//允许cookie
|
||||
.AllowAnyMethod();//允许任意方法
|
||||
@ -55,35 +57,37 @@ namespace ZR.Admin.WebApi
|
||||
services.AddSession();
|
||||
services.AddHttpContextAccessor();
|
||||
|
||||
//Cookie 认证
|
||||
services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme).AddCookie();
|
||||
|
||||
//绑定整个对象到Model上
|
||||
services.Configure<OptionsSetting>(Configuration);
|
||||
services.Configure<JwtSettings>(Configuration);
|
||||
var jwtSettings = new JwtSettings();
|
||||
Configuration.Bind("JwtSettings", jwtSettings);
|
||||
|
||||
InjectRepositories(services);
|
||||
//Cookie ÈÏÖ¤
|
||||
services.AddAuthentication(options =>
|
||||
{
|
||||
options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
|
||||
options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
|
||||
}).AddCookie()
|
||||
.AddJwtBearer(o =>
|
||||
{
|
||||
o.TokenValidationParameters = JwtUtil.ValidParameters();
|
||||
});
|
||||
|
||||
InjectServices(services);
|
||||
|
||||
services.AddMvc(options =>
|
||||
{
|
||||
options.Filters.Add(typeof(GlobalActionMonitor));//全局注册异常
|
||||
})
|
||||
.AddMvcLocalization()
|
||||
.AddViewLocalization(LanguageViewLocationExpanderFormat.Suffix)
|
||||
.AddJsonOptions(options =>
|
||||
{
|
||||
options.JsonSerializerOptions.Converters.Add(new JsonConverterUtil.DateTimeConverter());
|
||||
options.JsonSerializerOptions.Converters.Add(new JsonConverterUtil.DateTimeNullConverter());
|
||||
});
|
||||
|
||||
services.AddSwaggerGen(c =>
|
||||
{
|
||||
c.SwaggerDoc("v1", new OpenApiInfo { Title = "ZrAdmin", Version = "v1" });
|
||||
if (CurrentEnvironment.IsDevelopment())
|
||||
{
|
||||
//添加文档注释
|
||||
c.IncludeXmlComments("ZRAdmin.xml", true);
|
||||
}
|
||||
});
|
||||
services.AddSwaggerConfig();
|
||||
}
|
||||
|
||||
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
||||
@ -111,7 +115,9 @@ namespace ZR.Admin.WebApi
|
||||
//app.UseAuthentication会启用Authentication中间件,该中间件会根据当前Http请求中的Cookie信息来设置HttpContext.User属性(后面会用到),
|
||||
//所以只有在app.UseAuthentication方法之后注册的中间件才能够从HttpContext.User中读取到值,
|
||||
//这也是为什么上面强调app.UseAuthentication方法一定要放在下面的app.UseMvc方法前面,因为只有这样ASP.NET Core的MVC中间件中才能读取到HttpContext.User的值。
|
||||
//1.ÏÈ¿ªÆôÈÏÖ¤
|
||||
app.UseAuthentication();
|
||||
//2.ÔÙ¿ªÆôÊÚȨ
|
||||
app.UseAuthorization();
|
||||
app.UseSession();
|
||||
app.UseResponseCaching();
|
||||
@ -133,7 +139,7 @@ namespace ZR.Admin.WebApi
|
||||
/// 注册Services服务
|
||||
/// </summary>
|
||||
/// <param name="services"></param>
|
||||
private void InjectRepositories(IServiceCollection services)
|
||||
private void InjectServices(IServiceCollection services)
|
||||
{
|
||||
services.AddAppService();
|
||||
|
||||
@ -148,12 +154,12 @@ namespace ZR.Admin.WebApi
|
||||
|
||||
SugarIocServices.AddSqlSugar(new List<IocConfig>() {
|
||||
new IocConfig() {
|
||||
ConfigId = "0", //主数据库
|
||||
ConfigId = "0",
|
||||
ConnectionString = connStr,
|
||||
DbType = (IocDbType)dbType,
|
||||
IsAutoCloseConnection = true//自动释放
|
||||
}, new IocConfig() {
|
||||
ConfigId = "1", // 多租户用到
|
||||
ConfigId = "1",
|
||||
ConnectionString = connStrBus,
|
||||
DbType = (IocDbType)dbType_bus,
|
||||
IsAutoCloseConnection = true//自动释放
|
||||
@ -161,14 +167,13 @@ namespace ZR.Admin.WebApi
|
||||
});
|
||||
|
||||
//调式代码 用来打印SQL
|
||||
DbScoped.SugarScope.GetConnection(0).Aop.OnLogExecuting = (sql, pars) =>
|
||||
DbScoped.SugarScope.GetConnection("0").Aop.OnLogExecuting = (sql, pars) =>
|
||||
{
|
||||
Console.BackgroundColor = ConsoleColor.Yellow;
|
||||
Console.WriteLine("【SQL语句】" + sql.ToLower() + "\r\n"
|
||||
+ DbScoped.SugarScope.Utilities.SerializeObject(pars.ToDictionary(it => it.ParameterName, it => it.Value)));
|
||||
};
|
||||
//出错打印日志
|
||||
DbScoped.SugarScope.GetConnection(0).Aop.OnError = (e) =>
|
||||
DbScoped.SugarScope.GetConnection("0").Aop.OnError = (e) =>
|
||||
{
|
||||
Console.WriteLine($"[执行Sql出错]{e.Message},SQL={e.Sql}");
|
||||
Console.WriteLine();
|
||||
@ -177,7 +182,6 @@ namespace ZR.Admin.WebApi
|
||||
//调式代码 用来打印SQL
|
||||
DbScoped.SugarScope.GetConnection(1).Aop.OnLogExecuting = (sql, pars) =>
|
||||
{
|
||||
Console.BackgroundColor = ConsoleColor.Yellow;
|
||||
Console.WriteLine("【SQL语句Bus】" + sql.ToLower() + "\r\n"
|
||||
+ DbScoped.SugarScope.Utilities.SerializeObject(pars.ToDictionary(it => it.ParameterName, it => it.Value)));
|
||||
};
|
||||
|
||||
@ -15,11 +15,10 @@
|
||||
<ItemGroup>
|
||||
<Compile Remove="Filters\GlobalExceptionFilter.cs" />
|
||||
<Compile Remove="Middleware\RequestIPMiddleware.cs" />
|
||||
<Compile Remove="Template\Controller.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Remove="Template\Controller.tt" />
|
||||
<Content Remove="wwwroot\CodeGenTemplate\VueTemplate.txt" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
@ -35,6 +34,7 @@
|
||||
<PackageReference Include="Snowflake.Core" Version="2.0.0" />
|
||||
<PackageReference Include="SqlSugar.IOC" Version="1.7.0" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.1.4" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore.Filters" Version="7.0.2" />
|
||||
<PackageReference Include="UAParser" Version="3.1.46" />
|
||||
</ItemGroup>
|
||||
|
||||
@ -60,49 +60,14 @@
|
||||
<None Update="ip2region.db">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<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>
|
||||
<None Update="ZRAdmin.xml">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Controllers\business\" />
|
||||
<Folder Include="Controllers\demo\" />
|
||||
<Folder Include="wwwroot\export\" />
|
||||
<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>
|
||||
<Folder Include="wwwroot\uploads\" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@ -15,26 +15,34 @@
|
||||
"urls": "http://localhost:8888", //项目启动url
|
||||
"sysConfig": {
|
||||
"DBCommandTimeout": 10,
|
||||
"tokenExpire": 1440, //Jwt token超时时间(分)
|
||||
"cors": "http://localhost:8887" //跨域地址,多个用","隔开
|
||||
},
|
||||
"JwtSettings": {
|
||||
"Issuer": "https://localhost:8888",
|
||||
"Audience": "https://localhost:8888",
|
||||
"SecretKey": "Hello-key-ZRADMIN.NET-20210101",
|
||||
"Expire": 5
|
||||
},
|
||||
"DemoMode": false, //是否演示模式
|
||||
"DbKey": "", //数据库加密key
|
||||
"Upload": {
|
||||
"UploadDirectory": "/",
|
||||
"UploadUrl": "http://localhost:8888"
|
||||
},
|
||||
"QIQIU_OSS": {
|
||||
//阿里云存储配置
|
||||
"ALIYUN_OSS": {
|
||||
"REGIONID": "cn-hangzhou",
|
||||
"KEY": "XX",
|
||||
"SECRET": "XX"
|
||||
"SECRET": "XX",
|
||||
"bucketName": "bucketName",
|
||||
"domainUrl": "http://xxx.xxx.com" //访问资源域名
|
||||
},
|
||||
"gen": {
|
||||
"conn": "server=LAPTOP-STKF2M8H\\SQLEXPRESS;user=zr;pwd=abc;database={database};Trusted_Connection=SSPI",
|
||||
"conn": "server=LAPTOP-STKF2M8H\\SQLEXPRESS;user=zr;pwd=abc;database=ZrAdmin;Trusted_Connection=SSPI",
|
||||
"dbType": 1, //MySql = 0, SqlServer = 1
|
||||
"autoPre": true, //自动去除表前缀
|
||||
"author": "zr",
|
||||
"tablePrefix": "live_,sys_" //"表前缀(生成类名不会包含表前缀,多个用逗号分隔)",
|
||||
"tablePrefix": "sys_" //"表前缀(生成类名不会包含表前缀,多个用逗号分隔)",
|
||||
},
|
||||
//邮箱配置信息
|
||||
"MailOptions": {
|
||||
|
||||
@ -1,138 +0,0 @@
|
||||
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;
|
||||
using Infrastructure.Extensions;
|
||||
|
||||
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 自己实现搜索条件查询语法参考Sqlsugar,默认查询所有
|
||||
//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 = "{FunctionName}", BusinessType = BusinessType.INSERT)]
|
||||
public IActionResult Add{ModelName}([FromBody] {ModelName}Dto parm)
|
||||
{
|
||||
if (parm == null)
|
||||
{
|
||||
throw new CustomException("请求参数错误");
|
||||
}
|
||||
//从 Dto 映射到 实体
|
||||
var model = parm.Adapt<{ModelName}>().ToCreate(HttpContext);
|
||||
|
||||
return SUCCESS(_{ModelName}Service.Add(model, it => new
|
||||
{
|
||||
{InsertColumn}
|
||||
}));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新{FunctionName}
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPut]
|
||||
[ActionPermissionFilter(Permission = "{Permission}:update")]
|
||||
[Log(Title = "{FunctionName}", BusinessType = BusinessType.UPDATE)]
|
||||
public IActionResult Update{ModelName}([FromBody] {ModelName}Dto parm)
|
||||
{
|
||||
if (parm == null)
|
||||
{
|
||||
throw new CustomException("请求实体不能为空");
|
||||
}
|
||||
//从 Dto 映射到 实体
|
||||
var model = parm.Adapt<{ModelName}>().ToUpdate(HttpContext);
|
||||
|
||||
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 = "{FunctionName}", BusinessType = BusinessType.DELETE)]
|
||||
public IActionResult Delete{ModelName}(string ids)
|
||||
{
|
||||
int[] idsArr = Tools.SpitIntArrary(ids);
|
||||
if (idsArr.Length <= 0) { return ToResponse(ApiResult.Error($"删除失败Id 不能为空")); }
|
||||
|
||||
var response = _{ModelName}Service.Delete(idsArr);
|
||||
|
||||
return SUCCESS(response);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,15 +0,0 @@
|
||||
using System;
|
||||
using {ModelsNamespace}.Models;
|
||||
|
||||
namespace {IServicsNamespace}.Business
|
||||
{
|
||||
/// <summary>
|
||||
/// {FunctionName}service接口
|
||||
///
|
||||
/// @author {Author}
|
||||
/// @date {DateTime}
|
||||
/// </summary>
|
||||
public interface I{ModelTypeName}Service: IBaseService<{ModelTypeName}>
|
||||
{
|
||||
}
|
||||
}
|
||||
@ -1,25 +0,0 @@
|
||||
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; }
|
||||
}
|
||||
}
|
||||
@ -1,17 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace {ModelsNamespace}.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// {FunctionName},数据实体对象
|
||||
///
|
||||
/// @author {Author}
|
||||
/// @date {DateTime}
|
||||
/// </summary>
|
||||
[SqlSugar.SugarTable("{TableName}")]
|
||||
public class {ModelTypeName}
|
||||
{
|
||||
{PropertyName}
|
||||
}
|
||||
}
|
||||
@ -1,23 +1,25 @@
|
||||
-- 菜单
|
||||
INSERT INTO sys_menu(menuName, parentId, orderNum, path, component, isFrame, isCache, menuType, visible, status, perms, icon, create_time, remark)
|
||||
VALUES ('{FunctionName}', 0, 1, '{ModuleName}/{ModelTypeName}', '{ModuleName}/{ViewsFileName}/index', 0, 0, 'C', '0', '0', '{Permission}:list', 'icon1', sysdate(), '{FunctionName}菜单');
|
||||
INSERT INTO sys_menu(menuName, parentId, orderNum, path, component, isFrame, isCache, menuType, visible, status, perms, icon, create_by, create_time, remark)
|
||||
VALUES ('${genTable.functionName}', ${parentId}, 1, '${genTable.ModuleName}/${replaceDto.ModelTypeName}', '${genTable.ModuleName}/${genTable.BusinessName}/index', 0, 0, 'C', '0', '0', '${replaceDto.PermissionPrefix}:list', 'icon1', '', sysdate(), '${genTable.functionName}菜单');
|
||||
|
||||
-- 按钮父菜单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 ('{FunctionName}查询', @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_time)
|
||||
VALUES ('查询', @menuId, 1, '#', NULL, 0, 0, 'F', '0', '0', '${replaceDto.PermissionPrefix}:query', '', sysdate());
|
||||
|
||||
INSERT INTO sys_menu(menuName, parentId, orderNum, path, component, isFrame, isCache, menuType, visible, status, perms, icon, create_by,create_time, update_by, update_time, remark)
|
||||
VALUES ('{FunctionName}新增', @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_time)
|
||||
VALUES ('新增', @menuId, 2, '#', NULL, 0, 0, 'F', '0', '0', '${replaceDto.PermissionPrefix}:add', '', sysdate());
|
||||
|
||||
INSERT INTO sys_menu(menuName, parentId, orderNum, path, component, isFrame, isCache, menuType, visible, status, perms, icon, create_by,create_time, update_by, update_time, remark)
|
||||
VALUES ('{FunctionName}删除', @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_time)
|
||||
VALUES ('删除', @menuId, 3, '#', NULL, 0, 0, 'F', '0', '0', '${replaceDto.PermissionPrefix}:delete', '', sysdate());
|
||||
|
||||
INSERT INTO sys_menu(menuName, parentId, orderNum, path, component, isFrame, isCache, menuType, visible, status, perms, icon, create_by,create_time, update_by, update_time, remark)
|
||||
VALUES ('{FunctionName}修改', @menuId, 3, '#', NULL, 0, 0, 'F', '0', '0', '{Permission}:update', '', '', sysdate(), '', NULL, NULL);
|
||||
INSERT INTO sys_menu(menuName, parentId, orderNum, path, component, isFrame, isCache, menuType, visible, status, perms, icon, create_time)
|
||||
VALUES ('修改', @menuId, 4, '#', NULL, 0, 0, 'F', '0', '0', '${replaceDto.PermissionPrefix}:update', '', sysdate());
|
||||
|
||||
INSERT INTO sys_menu(menuName, parentId, orderNum, path, component, isFrame, isCache, menuType, visible, status, perms, icon, create_time)
|
||||
VALUES ('导出', @menuId, 5, '#', NULL, 0, 0, 'F', '0', '0', '${replaceDto.PermissionPrefix}:export', '', sysdate());
|
||||
|
||||
SELECT * FROM sys_menu WHERE parentId = @menuId;
|
||||
SELECT * FROM sys_menu WHERE menuId = @menuId;
|
||||
@ -1,20 +0,0 @@
|
||||
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<{ModelTypeName}>
|
||||
{
|
||||
#region 业务逻辑代码
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@ -1,27 +0,0 @@
|
||||
using Infrastructure;
|
||||
using Infrastructure.Attribute;
|
||||
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 _{ModelTypeName}repository;
|
||||
public {ModelTypeName}Service({ModelTypeName}Repository repository)
|
||||
{
|
||||
_{ModelTypeName}repository = repository;
|
||||
}
|
||||
|
||||
#region 业务逻辑代码
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@ -1,22 +1,25 @@
|
||||
-- {FunctionName}菜单
|
||||
-- ${genTable.functionName}菜单
|
||||
INSERT INTO sys_menu(menuName, parentId, orderNum, path, component, isFrame, isCache, menuType, visible, status, perms, icon, create_time, remark)
|
||||
VALUES ('{FunctionName}', {ParentId}, 1, '{ModuleName}/{ModelTypeName}', '{ModuleName}/{ViewsFileName}/index', 0, 0, 'C', '0', '0', '{Permission}:list', 'icon1', GETDATE(), '{FunctionName}');
|
||||
VALUES ('${genTable.functionName}', ${parentId}, 1, '${genTable.ModuleName}/${genTable.BusinessName}', '${genTable.ModuleName}/${genTable.BusinessName}', 0, 0, 'C', '0', '0', '${replaceDto.PermissionPrefix}:list', 'icon1', GETDATE(), '${genTable.functionName}');
|
||||
|
||||
-- 按钮父菜单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 ('{FunctionName}查询', @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)
|
||||
VALUES ('查询', @menuId, 1, '#', NULL, 0, 0, 'F', '0', '0', '${replaceDto.PermissionPrefix}:query', '', '', GETDATE());
|
||||
|
||||
INSERT INTO sys_menu(menuName, parentId, orderNum, path, component, isFrame, isCache, menuType, visible, status, perms, icon, create_by,create_time, update_by, update_time, remark)
|
||||
VALUES ('{FunctionName}新增', @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)
|
||||
VALUES ('新增', @menuId, 2, '#', NULL, 0, 0, 'F', '0', '0', '${replaceDto.PermissionPrefix}:add', '', '', GETDATE());
|
||||
|
||||
INSERT INTO sys_menu(menuName, parentId, orderNum, path, component, isFrame, isCache, menuType, visible, status, perms, icon, create_by,create_time, update_by, update_time, remark)
|
||||
VALUES ('{FunctionName}删除', @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)
|
||||
VALUES ('删除', @menuId, 3, '#', NULL, 0, 0, 'F', '0', '0', '${replaceDto.PermissionPrefix}:delete', '', '', GETDATE());
|
||||
|
||||
INSERT INTO sys_menu(menuName, parentId, orderNum, path, component, isFrame, isCache, menuType, visible, status, perms, icon, create_by,create_time, update_by, update_time, remark)
|
||||
VALUES ('{FunctionName}修改', @menuId, 3, '#', NULL, 0, 0, 'F', '0', '0', '{Permission}:update', '', '', GETDATE(), '', NULL, NULL);
|
||||
INSERT INTO sys_menu(menuName, parentId, orderNum, path, component, isFrame, isCache, menuType, visible, status, perms, icon, create_by,create_time)
|
||||
VALUES ('修改', @menuId, 4, '#', NULL, 0, 0, 'F', '0', '0', '${replaceDto.PermissionPrefix}:update', '', '', GETDATE());
|
||||
|
||||
SELECT * FROM sys_menu WHERE parentId = {ParentId};
|
||||
INSERT INTO sys_menu(menuName, parentId, orderNum, path, component, isFrame, isCache, menuType, visible, status, perms, icon, create_by,create_time)
|
||||
VALUES ('导出', @menuId, 5, '#', NULL, 0, 0, 'F', '0', '0', '${replaceDto.PermissionPrefix}:export', '', '', GETDATE());
|
||||
|
||||
SELECT * FROM sys_menu WHERE parentId = @menuId;
|
||||
SELECT * FROM sys_menu WHERE menuId = @menuId;
|
||||
184
ZR.Admin.WebApi/wwwroot/CodeGenTemplate/TplControllers.txt
Normal file
184
ZR.Admin.WebApi/wwwroot/CodeGenTemplate/TplControllers.txt
Normal file
@ -0,0 +1,184 @@
|
||||
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 ${options.ModelsNamespace}.Dto;
|
||||
using ${options.ModelsNamespace}.Models;
|
||||
using ${options.ServicesNamespace}.Business;
|
||||
using ${options.ApiControllerNamespace}.Extensions;
|
||||
using ${options.ApiControllerNamespace}.Filters;
|
||||
using ZR.Common;
|
||||
using Infrastructure.Extensions;
|
||||
using System.Linq;
|
||||
|
||||
namespace ${options.ApiControllerNamespace}.Controllers
|
||||
{
|
||||
/// <summary>
|
||||
/// ${genTable.functionName}Controller
|
||||
///
|
||||
/// @author ${replaceDto.Author}
|
||||
/// @date ${replaceDto.AddTime}
|
||||
/// </summary>
|
||||
[Verify]
|
||||
[Route("${genTable.ModuleName}/${replaceDto.ModelTypeName}")]
|
||||
public class ${replaceDto.ModelTypeName}Controller : BaseController
|
||||
{
|
||||
/// <summary>
|
||||
/// ${genTable.FunctionName}接口
|
||||
/// </summary>
|
||||
private readonly I${replaceDto.ModelTypeName}Service _${replaceDto.ModelTypeName}Service;
|
||||
|
||||
public ${replaceDto.ModelTypeName}Controller(I${replaceDto.ModelTypeName}Service ${replaceDto.ModelTypeName}Service)
|
||||
{
|
||||
_${replaceDto.ModelTypeName}Service = ${replaceDto.ModelTypeName}Service;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查询${genTable.FunctionName}列表
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet("list")]
|
||||
[ActionPermissionFilter(Permission = "${replaceDto.PermissionPrefix}:list")]
|
||||
public IActionResult Query${replaceDto.ModelTypeName}([FromQuery] ${replaceDto.ModelTypeName}QueryDto parm)
|
||||
{
|
||||
//开始拼装查询条件
|
||||
var predicate = Expressionable.Create<${replaceDto.ModelTypeName}>();
|
||||
|
||||
//搜索条件查询语法参考Sqlsugar
|
||||
${QueryCondition}
|
||||
$if(genTable.SortField != "")
|
||||
var response = _${replaceDto.ModelTypeName}Service.GetPages(predicate.ToExpression(), parm, x => x.${genTable.SortField}, "${genTable.SortType}");
|
||||
$else
|
||||
var response = _${replaceDto.ModelTypeName}Service.GetPages(predicate.ToExpression(), parm);
|
||||
$end
|
||||
return SUCCESS(response);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查询${genTable.FunctionName}详情
|
||||
/// </summary>
|
||||
/// <param name="${replaceDto.PKName}"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("{${replaceDto.PKName}}")]
|
||||
[ActionPermissionFilter(Permission = "${replaceDto.PermissionPrefix}:query")]
|
||||
public IActionResult Get${replaceDto.ModelTypeName}(${replaceDto.PKType} ${replaceDto.PKName})
|
||||
{
|
||||
var response = _${replaceDto.ModelTypeName}Service.GetFirst(x => x.${replaceDto.PKName} == ${replaceDto.PKName});
|
||||
|
||||
return SUCCESS(response);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加${genTable.FunctionName}
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[ActionPermissionFilter(Permission = "${replaceDto.PermissionPrefix}:add")]
|
||||
[Log(Title = "${genTable.FunctionName}", BusinessType = BusinessType.INSERT)]
|
||||
public IActionResult Add${replaceDto.ModelTypeName}([FromBody] ${replaceDto.ModelTypeName}Dto parm)
|
||||
{
|
||||
if (parm == null)
|
||||
{
|
||||
throw new CustomException("请求参数错误");
|
||||
}
|
||||
//从 Dto 映射到 实体
|
||||
var model = parm.Adapt<${replaceDto.ModelTypeName}>().ToCreate(HttpContext);
|
||||
|
||||
return SUCCESS(_${replaceDto.ModelTypeName}Service.Insert(model, it => new
|
||||
{
|
||||
$foreach(item in genTable.Columns)
|
||||
$if((item.IsInsert))
|
||||
it.$item.CsharpField,
|
||||
$end
|
||||
${end}
|
||||
}));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新${genTable.FunctionName}
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPut]
|
||||
[ActionPermissionFilter(Permission = "${replaceDto.PermissionPrefix}:update")]
|
||||
[Log(Title = "${genTable.FunctionName}", BusinessType = BusinessType.UPDATE)]
|
||||
public IActionResult Update${replaceDto.ModelTypeName}([FromBody] ${replaceDto.ModelTypeName}Dto parm)
|
||||
{
|
||||
if (parm == null)
|
||||
{
|
||||
throw new CustomException("请求实体不能为空");
|
||||
}
|
||||
//从 Dto 映射到 实体
|
||||
var model = parm.Adapt<${replaceDto.ModelTypeName}>().ToUpdate(HttpContext);
|
||||
|
||||
var response = _${replaceDto.ModelTypeName}Service.Update(w => w.${replaceDto.PKName} == model.${replaceDto.PKName}, it => new ${replaceDto.ModelTypeName}()
|
||||
{
|
||||
//Update 字段映射
|
||||
$foreach(item in genTable.Columns)
|
||||
$if((item.IsEdit))
|
||||
$item.CsharpField = model.$item.CsharpField,
|
||||
$end
|
||||
${end}
|
||||
});
|
||||
|
||||
return SUCCESS(response);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除${genTable.FunctionName}
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpDelete("{ids}")]
|
||||
[ActionPermissionFilter(Permission = "${replaceDto.PermissionPrefix}:delete")]
|
||||
[Log(Title = "${genTable.FunctionName}", BusinessType = BusinessType.DELETE)]
|
||||
public IActionResult Delete${replaceDto.ModelTypeName}(string ids)
|
||||
{
|
||||
int[] idsArr = Tools.SpitIntArrary(ids);
|
||||
if (idsArr.Length <= 0) { return ToResponse(ApiResult.Error($"删除失败Id 不能为空")); }
|
||||
|
||||
var response = _${replaceDto.ModelTypeName}Service.Delete(idsArr);
|
||||
|
||||
return SUCCESS(response);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// ${genTable.FunctionName}导出
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[Log(BusinessType = BusinessType.EXPORT, IsSaveResponseData = false, Title = "${genTable.FunctionName}")]
|
||||
[HttpGet("export")]
|
||||
[ActionPermissionFilter(Permission = "${replaceDto.PermissionPrefix}:export")]
|
||||
public IActionResult Export()
|
||||
{
|
||||
var list = _${replaceDto.ModelTypeName}Service.GetAll();
|
||||
|
||||
string sFileName = ExportExcel(list, "${replaceDto.ModelTypeName}", "${genTable.FunctionName}");
|
||||
return SUCCESS(new { path = "/export/" + sFileName, fileName = sFileName });
|
||||
}
|
||||
|
||||
$if(genTable.SortField != "")
|
||||
/// <summary>
|
||||
/// 保存排序
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <param name="orderNum"></param>
|
||||
/// <returns></returns>
|
||||
[ActionPermissionFilter(Permission = "${replaceDto.PermissionPrefix}:update")]
|
||||
[HttpGet("ChangeSort")]
|
||||
[Log(Title = "保存排序", BusinessType = BusinessType.UPDATE)]
|
||||
public IActionResult ChangeSort(int id = 0, int orderNum = 0)
|
||||
{
|
||||
if (id <= 0) { return ToResponse(ApiResult.Error(101, "请求参数错误")); }
|
||||
|
||||
bool result = _${replaceDto.ModelTypeName}Service.Update(w => w.${replaceDto.PKName} == id, it => new ${replaceDto.ModelTypeName}() { ${genTable.SortField} = orderNum });;
|
||||
|
||||
return SUCCESS(result);
|
||||
}
|
||||
$end
|
||||
}
|
||||
}
|
||||
34
ZR.Admin.WebApi/wwwroot/CodeGenTemplate/TplDto.txt
Normal file
34
ZR.Admin.WebApi/wwwroot/CodeGenTemplate/TplDto.txt
Normal file
@ -0,0 +1,34 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using ${options.ModelsNamespace}.Dto;
|
||||
using ${options.ModelsNamespace}.Models;
|
||||
|
||||
namespace ${options.DtosNamespace}.Dto
|
||||
{
|
||||
/// <summary>
|
||||
/// ${genTable.FunctionName}输入对象
|
||||
/// </summary>
|
||||
public class ${replaceDto.ModelTypeName}Dto
|
||||
{
|
||||
$foreach(item in genTable.Columns)
|
||||
$if((item.IsInsert || item.IsEdit || item.IsPk || item.IsIncrement))
|
||||
public $item.CsharpType$item.RequiredStr $item.CsharpField { get; set; }
|
||||
$end
|
||||
${end}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// ${genTable.FunctionName}查询对象
|
||||
/// </summary>
|
||||
public class ${replaceDto.ModelTypeName}QueryDto : PagerInfo
|
||||
{
|
||||
$foreach(item in genTable.Columns)
|
||||
$if(item.IsQuery)
|
||||
public $item.CsharpType $item.CsharpField { get; set; }
|
||||
$end
|
||||
${end}
|
||||
|
||||
public DateTime? BeginTime { get; set; }
|
||||
public DateTime? EndTime { get; set; }
|
||||
}
|
||||
}
|
||||
15
ZR.Admin.WebApi/wwwroot/CodeGenTemplate/TplIService.txt
Normal file
15
ZR.Admin.WebApi/wwwroot/CodeGenTemplate/TplIService.txt
Normal file
@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using ${options.ModelsNamespace}.Models;
|
||||
|
||||
namespace ${options.IServicsNamespace}.Business
|
||||
{
|
||||
/// <summary>
|
||||
/// ${genTable.FunctionName}service接口
|
||||
///
|
||||
/// @author ${replaceDto.Author}
|
||||
/// @date ${replaceDto.AddTime}
|
||||
/// </summary>
|
||||
public interface I${replaceDto.ModelTypeName}Service: IBaseService<${replaceDto.ModelTypeName}>
|
||||
{
|
||||
}
|
||||
}
|
||||
27
ZR.Admin.WebApi/wwwroot/CodeGenTemplate/TplModel.txt
Normal file
27
ZR.Admin.WebApi/wwwroot/CodeGenTemplate/TplModel.txt
Normal file
@ -0,0 +1,27 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using SqlSugar;
|
||||
|
||||
namespace ${options.ModelsNamespace}.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// ${genTable.FunctionName},数据实体对象
|
||||
///
|
||||
/// @author ${replaceDto.Author}
|
||||
/// @date ${replaceDto.AddTime}
|
||||
/// </summary>
|
||||
[SugarTable("${genTable.TableName}")]
|
||||
public class ${replaceDto.ModelTypeName}
|
||||
{
|
||||
$foreach(item in genTable.Columns)
|
||||
/// <summary>
|
||||
/// 描述 : ${item.ColumnComment}
|
||||
/// 空值 :$if(item.IsRequired == "True") false $else true $end
|
||||
/// </summary>
|
||||
$if(item.IsPk || item.IsIncrement)
|
||||
[SqlSugar.SugarColumn(IsPrimaryKey = ${item.IsPk.ToString().ToLower()}, IsIdentity = ${item.IsIncrement.ToString().ToLower()})]
|
||||
$end
|
||||
public $item.CsharpType$item.RequiredStr $item.CsharpField { get; set; }
|
||||
${end}
|
||||
}
|
||||
}
|
||||
20
ZR.Admin.WebApi/wwwroot/CodeGenTemplate/TplRepository.txt
Normal file
20
ZR.Admin.WebApi/wwwroot/CodeGenTemplate/TplRepository.txt
Normal file
@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using Infrastructure.Attribute;
|
||||
using ${options.RepositoriesNamespace}.System;
|
||||
using ${options.ModelsNamespace}.Models;
|
||||
|
||||
namespace ${options.RepositoriesNamespace}
|
||||
{
|
||||
/// <summary>
|
||||
/// ${genTable.FunctionName}仓储
|
||||
///
|
||||
/// @author ${replaceDto.Author}
|
||||
/// @date ${replaceDto.AddTime}
|
||||
/// </summary>
|
||||
[AppService(ServiceLifetime = LifeTime.Transient)]
|
||||
public class ${replaceDto.ModelTypeName}Repository : BaseRepository<${replaceDto.ModelTypeName}>
|
||||
{
|
||||
#region 业务逻辑代码
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
27
ZR.Admin.WebApi/wwwroot/CodeGenTemplate/TplService.txt
Normal file
27
ZR.Admin.WebApi/wwwroot/CodeGenTemplate/TplService.txt
Normal file
@ -0,0 +1,27 @@
|
||||
using Infrastructure;
|
||||
using Infrastructure.Attribute;
|
||||
using ${options.ModelsNamespace}.Models;
|
||||
using ${options.IRepositoriesNamespace};
|
||||
|
||||
namespace ${options.ServicesNamespace}.Business
|
||||
{
|
||||
/// <summary>
|
||||
/// ${genTable.FunctionName}Service业务层处理
|
||||
///
|
||||
/// @author ${replaceDto.Author}
|
||||
/// @date ${replaceDto.AddTime}
|
||||
/// </summary>
|
||||
[AppService(ServiceType = typeof(I${replaceDto.ModelTypeName}Service), ServiceLifetime = LifeTime.Transient)]
|
||||
public class ${replaceDto.ModelTypeName}Service : BaseService<${replaceDto.ModelTypeName}>, I${replaceDto.ModelTypeName}Service
|
||||
{
|
||||
private readonly ${replaceDto.ModelTypeName}Repository _${replaceDto.ModelTypeName}repository;
|
||||
public ${replaceDto.ModelTypeName}Service(${replaceDto.ModelTypeName}Repository repository) : base(repository)
|
||||
{
|
||||
_${replaceDto.ModelTypeName}repository = repository;
|
||||
}
|
||||
|
||||
#region 业务逻辑代码
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
276
ZR.Admin.WebApi/wwwroot/CodeGenTemplate/TplVue.txt
Normal file
276
ZR.Admin.WebApi/wwwroot/CodeGenTemplate/TplVue.txt
Normal file
@ -0,0 +1,276 @@
|
||||
<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="['${replaceDto.PermissionPrefix}: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="['${replaceDto.PermissionPrefix}: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="['${replaceDto.PermissionPrefix}:delete']" plain icon="el-icon-delete" size="mini" @click="handleDelete">删除</el-button>
|
||||
</el-col>
|
||||
$if(genTable.SortField != "")
|
||||
<el-col :span="1.5">
|
||||
<el-button type="info" plain icon="el-icon-edit" size="mini" @click="handleShowSort" v-hasPermi="['${replaceDto.PermissionPrefix}:update']">修改排序</el-button>
|
||||
</el-col>
|
||||
$end
|
||||
<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="['${replaceDto.PermissionPrefix}: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="['${replaceDto.PermissionPrefix}: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">
|
||||
<el-row>
|
||||
${VueViewFormContent}
|
||||
</el-row>
|
||||
</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${genTable.BusinessName},
|
||||
add${genTable.BusinessName},
|
||||
del${genTable.BusinessName},
|
||||
update${genTable.BusinessName},
|
||||
get${genTable.BusinessName},
|
||||
$if(genTable.SortField != "")
|
||||
changeSort
|
||||
$end
|
||||
} from '@/api/${genTable.ModuleName}/${lowerBusinessName}.js';
|
||||
|
||||
export default {
|
||||
name: "${genTable.BusinessName}",
|
||||
data() {
|
||||
return {
|
||||
labelWidth: "100px",
|
||||
formLabelWidth:"100px",
|
||||
// 选中${replaceDto.FistLowerPk}数组
|
||||
ids: [],
|
||||
// 非单个禁用
|
||||
single: true,
|
||||
// 非多个禁用
|
||||
multiple: true,
|
||||
// 遮罩层
|
||||
loading: true,
|
||||
// 显示搜索条件
|
||||
showSearch: true,
|
||||
// 查询参数
|
||||
queryParams: {},
|
||||
// 弹出层标题
|
||||
title: "",
|
||||
// 是否显示弹出层
|
||||
open: false,
|
||||
// 表单参数
|
||||
form: {},
|
||||
// 时间范围数组
|
||||
timeRange: [],
|
||||
$foreach(item in genTable.Columns)
|
||||
$if((item.HtmlType == "radio" || item.HtmlType == "select"))
|
||||
// ${item.ColumnComment}选项列表
|
||||
${item.ColumnName}Options: [],
|
||||
$end
|
||||
$end
|
||||
$if(genTable.SortField != "")
|
||||
// 是否显示编辑排序
|
||||
showEditSort: false,
|
||||
$end
|
||||
// 数据列表
|
||||
dataList: [],
|
||||
// 总记录数
|
||||
total: 0,
|
||||
// 提交按钮是否显示
|
||||
btnSubmitVisible: true,
|
||||
// 表单校验
|
||||
rules: {
|
||||
${VueViewEditFormRuleContent}
|
||||
},
|
||||
};
|
||||
},
|
||||
mounted() {
|
||||
// 列表数据查询
|
||||
this.getList();
|
||||
|
||||
$foreach(item in genTable.Columns)
|
||||
$if((item.HtmlType == "radio" || item.HtmlType == "select") && item.DictType != "")
|
||||
this.getDicts("${item.DictType}").then((response) => {
|
||||
this.${item.ColumnName}Options = response.data;
|
||||
})
|
||||
$end
|
||||
$end
|
||||
},
|
||||
methods: {
|
||||
// 查询数据
|
||||
getList() {
|
||||
console.log(JSON.stringify(this.queryParams));
|
||||
list${genTable.BusinessName}(this.addDateRange(this.queryParams, this.timeRange)).then(res => {
|
||||
if (res.code == 200) {
|
||||
this.dataList = res.data.result;
|
||||
this.total = res.data.totalNum;
|
||||
}
|
||||
})
|
||||
},
|
||||
// 取消按钮
|
||||
cancel() {
|
||||
this.open = false;
|
||||
this.reset();
|
||||
},
|
||||
// 重置数据表单
|
||||
reset() {
|
||||
this.form = {
|
||||
$foreach(item in genTable.Columns)
|
||||
$if((item.IsEdit || item.IsInsert))
|
||||
$item.ColumnName: undefined,
|
||||
$end
|
||||
$end
|
||||
};
|
||||
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.${replaceDto.FistLowerPk});
|
||||
this.single = selection.length != 1
|
||||
this.multiple = !selection.length;
|
||||
},
|
||||
/** 搜索按钮操作 */
|
||||
handleQuery() {
|
||||
this.getList();
|
||||
},
|
||||
/** 新增按钮操作 */
|
||||
handleAdd() {
|
||||
this.reset();
|
||||
this.open = true;
|
||||
this.title = "添加";
|
||||
},
|
||||
/** 删除按钮操作 */
|
||||
handleDelete(row) {
|
||||
const Ids = row.${replaceDto.FistLowerPk} || this.ids;
|
||||
del${genTable.BusinessName}(Ids).then((res) => {
|
||||
this.msgSuccess("删除成功");
|
||||
this.handleQuery();
|
||||
});
|
||||
},
|
||||
/** 修改按钮操作 */
|
||||
handleUpdate(row) {
|
||||
this.reset();
|
||||
const id = row.${replaceDto.FistLowerPk} || this.ids;
|
||||
get${genTable.BusinessName}(id).then((res) => {
|
||||
if (res.code == 200) {
|
||||
this.form = res.data;
|
||||
this.open = true;
|
||||
this.title = "修改数据";
|
||||
}
|
||||
});
|
||||
},
|
||||
$if(genTable.SortField != "")
|
||||
// 显示编辑排序
|
||||
handleShowSort() {
|
||||
this.showEditSort = !this.showEditSort;
|
||||
},
|
||||
// 保存排序
|
||||
handleChangeSort(item, orderNum) {
|
||||
changeSort({ orderNum: orderNum, id: item.${replaceDto.FistLowerPk} }).then(
|
||||
(response) => {
|
||||
this.msgSuccess("修改成功");
|
||||
this.getList();
|
||||
this.showEditSort = false;
|
||||
}
|
||||
);
|
||||
},
|
||||
$end
|
||||
$if(replaceDto.UploadFile == 1)
|
||||
//图片上传成功方法
|
||||
handleUploadSuccess(res, columnName) {
|
||||
console.log(columnName, res)
|
||||
this.form[columnName] = res.data;
|
||||
console.log(JSON.stringify(this.form))
|
||||
},
|
||||
$end
|
||||
$foreach(item in genTable.Columns)
|
||||
$if((item.HtmlType == "radio" || item.HtmlType == "select") && item.DictType != "")
|
||||
// ${item.ColumnComment}字典翻译
|
||||
${item.ColumnName}Format(row, column) {
|
||||
return this.selectDictLabel(this.${item.ColumnName}Options, row.${item.ColumnName});
|
||||
},
|
||||
$end
|
||||
$end
|
||||
/** 提交按钮 */
|
||||
submitForm: function () {
|
||||
this.${refs}refs["form"].validate((valid) => {
|
||||
if (valid) {
|
||||
console.log(JSON.stringify(this.form));
|
||||
|
||||
if (this.form.${replaceDto.FistLowerPk} != undefined || this.title === "修改数据") {
|
||||
update${genTable.BusinessName}(this.form).then((res) => {
|
||||
if (!res.data) {
|
||||
this.msgError("修改失败");
|
||||
return;
|
||||
}
|
||||
this.msgSuccess("修改成功");
|
||||
this.open = false;
|
||||
this.getList();
|
||||
});
|
||||
} else {
|
||||
add${genTable.BusinessName}(this.form).then((res) => {
|
||||
if (!res.data) {
|
||||
this.msgError("新增失败");
|
||||
return;
|
||||
}
|
||||
this.msgSuccess("新增成功");
|
||||
this.open = false;
|
||||
this.getList();
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
},
|
||||
};
|
||||
</script>
|
||||
<style scoped>
|
||||
.table-td-thumb {
|
||||
width: 80px;
|
||||
}
|
||||
</style>
|
||||
79
ZR.Admin.WebApi/wwwroot/CodeGenTemplate/TplVueApi.txt
Normal file
79
ZR.Admin.WebApi/wwwroot/CodeGenTemplate/TplVueApi.txt
Normal file
@ -0,0 +1,79 @@
|
||||
import request from '@/utils/request'
|
||||
|
||||
/**
|
||||
* ${genTable.functionName}分页查询
|
||||
* @param {查询条件} data
|
||||
*/
|
||||
export function list${genTable.BusinessName}(query) {
|
||||
return request({
|
||||
url: '${genTable.ModuleName}/${replaceDto.ModelTypeName}/list',
|
||||
method: 'get',
|
||||
params: query,
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增${genTable.functionName}
|
||||
* @param data
|
||||
*/
|
||||
export function add${genTable.BusinessName}(data) {
|
||||
return request({
|
||||
url: '${genTable.ModuleName}/${replaceDto.ModelTypeName}',
|
||||
method: 'post',
|
||||
data: data,
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改${genTable.functionName}
|
||||
* @param data
|
||||
*/
|
||||
export function update${genTable.BusinessName}(data) {
|
||||
return request({
|
||||
url: '${genTable.ModuleName}/${replaceDto.ModelTypeName}',
|
||||
method: 'PUT',
|
||||
data: data,
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取${genTable.functionName}详情
|
||||
* @param {Id}
|
||||
*/
|
||||
export function get${genTable.BusinessName}(id) {
|
||||
return request({
|
||||
url: '${genTable.ModuleName}/${replaceDto.ModelTypeName}/' + id,
|
||||
method: 'get'
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除${genTable.functionName}
|
||||
* @param {主键} pid
|
||||
*/
|
||||
export function del${genTable.BusinessName}(pid) {
|
||||
return request({
|
||||
url: '${genTable.ModuleName}/${replaceDto.ModelTypeName}/' + pid,
|
||||
method: 'delete'
|
||||
})
|
||||
}
|
||||
// 导出${genTable.functionName}
|
||||
export function export${replaceDto.ModelTypeName}(query) {
|
||||
return request({
|
||||
url: '${genTable.ModuleName}/${replaceDto.ModelTypeName}/export',
|
||||
method: 'get',
|
||||
params: query
|
||||
})
|
||||
}
|
||||
|
||||
$if(genTable.SortField != "")
|
||||
//排序
|
||||
export function changeSort(data) {
|
||||
return request({
|
||||
url: '${genTable.ModuleName}/${replaceDto.ModelTypeName}/ChangeSort',
|
||||
method: 'get',
|
||||
params: data
|
||||
})
|
||||
}
|
||||
|
||||
$end
|
||||
@ -1,59 +0,0 @@
|
||||
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} {FunctionName}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'
|
||||
})
|
||||
}
|
||||
@ -41,7 +41,9 @@
|
||||
<!-- 添加或修改菜单对话框 -->
|
||||
<el-dialog :title="title" :lock-scroll="false" :visible.sync="open" >
|
||||
<el-form ref="form" :model="form" :rules="rules" :label-width="formLabelWidth">
|
||||
<el-row>
|
||||
{VueViewFormContent}
|
||||
</el-row>
|
||||
</el-form>
|
||||
<div slot="footer" class="dialog-footer" v-if="btnSubmitVisible">
|
||||
<el-button @click="cancel">取 消</el-button>
|
||||
@ -58,13 +60,10 @@ import {
|
||||
del{ModelTypeName},
|
||||
update{ModelTypeName},
|
||||
get{ModelTypeName}
|
||||
} from '@/api/{fileClassName}.js';
|
||||
|
||||
{VueComponentImport}
|
||||
} from '@/api/{ModuleName}/{fileClassName}.js';
|
||||
|
||||
export default {
|
||||
name: '{ModelTypeName}',
|
||||
components: { {VueComponent} },
|
||||
name: "{ModelTypeName}",
|
||||
data() {
|
||||
return {
|
||||
labelWidth: "100px",
|
||||
@ -115,7 +114,7 @@ export default {
|
||||
list{ModelTypeName}(this.addDateRange(this.queryParams, this.timeRange)).then(res => {
|
||||
if (res.code == 200) {
|
||||
this.dataList = res.data.result;
|
||||
this.total = res.data.totalCount;
|
||||
this.total = res.data.totalNum;
|
||||
}
|
||||
})
|
||||
},
|
||||
@ -179,7 +178,6 @@ export default {
|
||||
}
|
||||
});
|
||||
},
|
||||
beforeFileUpload(file) { },
|
||||
{vueJsMethod}
|
||||
/** 提交按钮 */
|
||||
submitForm: function () {
|
||||
@ -187,7 +185,7 @@ export default {
|
||||
if (valid) {
|
||||
console.log(JSON.stringify(this.form));
|
||||
|
||||
if (this.form.{PrimaryKey} != undefined || this.title === '修改数据') {
|
||||
if (this.form.{PrimaryKey} != undefined || this.title === "修改数据") {
|
||||
update{ModelTypeName}(this.form).then((res) => {
|
||||
if (!res.data) {
|
||||
this.msgError("修改失败");
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using ZR.CodeGenerator.Model;
|
||||
using ZR.Model.System.Generate;
|
||||
|
||||
namespace ZR.CodeGenerator
|
||||
@ -11,36 +12,42 @@ namespace ZR.CodeGenerator
|
||||
public class CodeGenerateTemplate
|
||||
{
|
||||
/// <summary>
|
||||
/// 生成vuejs模板,目前只有上传文件方法
|
||||
/// 查询Dto属性
|
||||
/// </summary>
|
||||
/// <param name="tbColumn"></param>
|
||||
/// <param name="replaceDto">替换字符对象</param>
|
||||
/// <returns></returns>
|
||||
public static void GetQueryDtoProperty(GenTableColumn tbColumn, ReplaceDto replaceDto)
|
||||
{
|
||||
if (tbColumn.IsQuery)
|
||||
{
|
||||
//字符串类型表达式
|
||||
if (tbColumn.CsharpType == GenConstants.TYPE_STRING)
|
||||
{
|
||||
replaceDto.QueryCondition += $" predicate = predicate.AndIF(!string.IsNullOrEmpty(parm.{tbColumn.CsharpField}), {QueryExp(tbColumn.CsharpField, tbColumn.QueryType)};\n";
|
||||
}
|
||||
//int类型表达式
|
||||
if (CodeGeneratorTool.IsNumber(tbColumn.CsharpType))
|
||||
{
|
||||
replaceDto.QueryCondition += $" predicate = predicate.AndIF(parm.{tbColumn.CsharpField} > 0, {QueryExp(tbColumn.CsharpField, tbColumn.QueryType)};\n";
|
||||
}
|
||||
//时间类型
|
||||
if (tbColumn.CsharpType == GenConstants.TYPE_DATE)
|
||||
{
|
||||
replaceDto.QueryCondition += $" predicate = predicate.AndIF(parm.BeginTime != null, it => it.{tbColumn.CsharpField} >= parm.BeginTime);\n";
|
||||
replaceDto.QueryCondition += $" predicate = predicate.AndIF(parm.EndTime != null, it => it.{tbColumn.CsharpField} <= parm.EndTime);\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#region vue 模板
|
||||
|
||||
/// <summary>
|
||||
/// Vue rules
|
||||
/// </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)
|
||||
public static string TplFormRules(GenTableColumn dbFieldInfo)
|
||||
{
|
||||
StringBuilder sbRule = new StringBuilder();
|
||||
//Rule 规则验证
|
||||
@ -55,68 +62,12 @@ namespace ZR.CodeGenerator
|
||||
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.HtmlType == GenConstants.HTML_DATETIME)
|
||||
//{
|
||||
// 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属性
|
||||
/// Vue 添加修改表单
|
||||
/// </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)
|
||||
public static string TplVueFormContent(GenTableColumn dbFieldInfo)
|
||||
{
|
||||
string columnName = dbFieldInfo.ColumnName;
|
||||
string labelName = CodeGeneratorTool.GetLabelName(dbFieldInfo.ColumnComment, columnName);
|
||||
@ -133,83 +84,103 @@ namespace ZR.CodeGenerator
|
||||
}
|
||||
if (dbFieldInfo.HtmlType == GenConstants.HTML_INPUT_NUMBER)
|
||||
{
|
||||
sb.AppendLine(" <el-col :span=\"12\">");
|
||||
sb.AppendLine($" <el-form-item label=\"{labelName}\" :label-width=\"labelWidth\" prop=\"{CodeGeneratorTool.FirstLowerCase(columnName)}\">");
|
||||
sb.AppendLine($" <el-input-number v-model.number=\"form.{CodeGeneratorTool.FirstLowerCase(columnName)}\" placeholder=\"{placeHolder}\" {labelDisabled}/>");
|
||||
sb.AppendLine(" </el-form-item>");
|
||||
sb.AppendLine(" </el-col>");
|
||||
}
|
||||
else if (dbFieldInfo.HtmlType == GenConstants.HTML_DATETIME)
|
||||
{
|
||||
//时间
|
||||
sb.AppendLine(" <el-col :span=\"12\">");
|
||||
sb.AppendLine($" <el-form-item label=\"{labelName}\" :label-width=\"labelWidth\" prop=\"{columnName}\">");
|
||||
sb.AppendLine($" <el-date-picker v-model=\"form.{columnName}\" format=\"yyyy-MM-dd HH:mm:ss\" value-format=\"yyyy-MM-dd HH:mm:ss\" type=\"datetime\" placeholder=\"选择日期时间\"> </el-date-picker>");
|
||||
sb.AppendLine(" </el-form-item>");
|
||||
sb.AppendLine(" </el-col>");
|
||||
}
|
||||
else if (dbFieldInfo.HtmlType == GenConstants.HTML_IMAGE_UPLOAD)
|
||||
{
|
||||
//图片
|
||||
sb.AppendLine(" <el-col :span=\"24\">");
|
||||
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-upload class=\"avatar-uploader\" name=\"file\" :action=\"uploadUrl\" :show-file-list=\"false\" :on-success=\"handleUpload{dbFieldInfo.CsharpField}Success\" :before-upload=\"beforeFileUpload\">");
|
||||
//sb.AppendLine($" <el-image 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($@" <UploadImage :icon=""form.{columnName}"" column='{columnName}' :key=""form.{columnName}"" @handleUploadSuccess=""handleUploadSuccess"" />");
|
||||
sb.AppendLine(" </el-form-item>");
|
||||
sb.AppendLine(" </el-col>");
|
||||
}
|
||||
else if (dbFieldInfo.HtmlType == GenConstants.HTML_RADIO && !string.IsNullOrEmpty(dbFieldInfo.DictType))
|
||||
{
|
||||
string value = CodeGeneratorTool.IsNumber(dbFieldInfo.CsharpType) ? "parseInt(item.dictValue)" : "item.dictValue";
|
||||
sb.AppendLine(" <el-col :span=\"12\">");
|
||||
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 v-for=\"item in {columnName}Options\" :key=\"item.dictValue\" :label=\"{value}\">{{{{item.dictLabel}}}}</el-radio>");
|
||||
sb.AppendLine(" </el-radio-group>");
|
||||
sb.AppendLine(" </el-form-item>");
|
||||
sb.AppendLine(" </el-col>");
|
||||
}
|
||||
else if (dbFieldInfo.HtmlType == GenConstants.HTML_RADIO)
|
||||
{
|
||||
sb.AppendLine(" <el-col :span=\"12\">");
|
||||
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>");
|
||||
sb.AppendLine(" </el-col>");
|
||||
}
|
||||
//else if (dbFieldInfo.HtmlType == GenConstants.HTML_RADIO && !string.IsNullOrEmpty(dbFieldInfo.DictType))
|
||||
//{
|
||||
// sb.AppendLine($" <el-form-item label=\"{labelName}\" :label-width=\"labelWidth\" prop=\"{columnName}\">");
|
||||
// sb.AppendLine($" <el-radio-group v-model=\"form.{columnName}\">");
|
||||
// //TODO 根据字典类型循环
|
||||
// sb.AppendLine(" </el-radio-group>");
|
||||
// sb.AppendLine(" </el-form-item>");
|
||||
//}
|
||||
else if (dbFieldInfo.HtmlType == GenConstants.HTML_TEXTAREA)
|
||||
{
|
||||
sb.AppendLine(" <el-col :span=\"24\">");
|
||||
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>");
|
||||
sb.AppendLine(" </el-col>");
|
||||
}
|
||||
else if (dbFieldInfo.HtmlType == GenConstants.HTML_EDITOR)
|
||||
{
|
||||
sb.AppendLine(" <el-col :span=\"24\">");
|
||||
sb.AppendLine($" <el-form-item label=\"{ labelName}\" :label-width=\"labelWidth\" prop=\"{columnName}\">");
|
||||
sb.AppendLine($" <editor v-model=\"form.{columnName}\" :min-height=\"200\" />");
|
||||
sb.AppendLine(" </el-form-item>");
|
||||
sb.AppendLine(" </el-col>");
|
||||
}
|
||||
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-col :span=\"12\">");
|
||||
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>");
|
||||
sb.AppendLine(" </el-col>");
|
||||
}
|
||||
else
|
||||
{
|
||||
string inputNumTxt = CodeGeneratorTool.IsNumber(dbFieldInfo.CsharpType) ? ".number" : "";
|
||||
sb.AppendLine(" <el-col :span=\"12\">");
|
||||
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>");
|
||||
sb.AppendLine(" </el-col>");
|
||||
}
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查询表单
|
||||
/// Vue 查询表单
|
||||
/// </summary>
|
||||
/// <param name="dbFieldInfo"></param>
|
||||
/// <returns></returns>
|
||||
public static string GetQueryFormHtml(GenTableColumn dbFieldInfo)
|
||||
public static string TplQueryFormHtml(GenTableColumn dbFieldInfo)
|
||||
{
|
||||
StringBuilder sb = new();
|
||||
string labelName = CodeGeneratorTool.GetLabelName(dbFieldInfo.ColumnComment, dbFieldInfo.ColumnName);
|
||||
@ -217,7 +188,17 @@ namespace ZR.CodeGenerator
|
||||
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-date-picker v-model=\"timeRange\" size=\"small\" value-format=\"yyyy-MM-dd\" type=\"daterange\" range-separator=\"-\" start-placeholder=\"开始日期\"");
|
||||
sb.AppendLine(" end-placeholder=\"结束日期\"></el-date-picker>");
|
||||
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=\"{dbFieldInfo.ColumnName}\">");
|
||||
sb.AppendLine($" <el-select v-model=\"queryParams.{dbFieldInfo.ColumnName}\">");
|
||||
sb.AppendLine($" <el-option v-for=\"item in {dbFieldInfo.ColumnName}Options\" :key=\"item.dictValue\" :label=\"item.dictLabel\" :value=\"item.dictValue\"></el-option>");
|
||||
sb.AppendLine(" </el-select>");
|
||||
sb.AppendLine(" </el-form-item>");
|
||||
}
|
||||
else
|
||||
@ -231,15 +212,31 @@ namespace ZR.CodeGenerator
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
//table-column
|
||||
public static string GetTableColumn(GenTableColumn dbFieldInfo)
|
||||
/// <summary>
|
||||
/// Vue 查询列表
|
||||
/// </summary>
|
||||
/// <param name="dbFieldInfo"></param>
|
||||
/// <param name="genTable"></param>
|
||||
/// <returns></returns>
|
||||
public static string TplTableColumn(GenTableColumn dbFieldInfo, GenTable genTable)
|
||||
{
|
||||
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))
|
||||
|
||||
//有排序字段
|
||||
if (!string.IsNullOrEmpty(genTable?.SortField.ToString()) && genTable?.SortField.ToString() == dbFieldInfo.CsharpField)
|
||||
{
|
||||
sb.AppendLine($@" <el-table-column prop=""{columnName}"" label=""排序"" width=""90"" sortable align=""center"">");
|
||||
sb.AppendLine(@" <template slot-scope=""scope"">");
|
||||
sb.AppendLine($@" <el-input size=""mini"" style=""width:50px"" controls-position=""no"" v-model.number=""scope.row.{columnName}"" @blur=""handleChangeSort(scope.row, scope.row.{columnName})"" v-if=""showEditSort"" />");
|
||||
sb.AppendLine($" <span v-else>{{{{scope.row.{columnName}}}}}</span>");
|
||||
sb.AppendLine(@" </template>");
|
||||
sb.AppendLine(@" </el-table-column>");
|
||||
}
|
||||
else if (dbFieldInfo.IsList && dbFieldInfo.HtmlType.Equals(GenConstants.HTML_IMAGE_UPLOAD))
|
||||
{
|
||||
sb.AppendLine($" <el-table-column prop=\"{columnName}\" label=\"图片\">");
|
||||
sb.AppendLine(" <template slot-scope=\"scope\">");
|
||||
@ -247,20 +244,46 @@ namespace ZR.CodeGenerator
|
||||
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();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public static string QueryExp(string propertyName, string queryType)
|
||||
{
|
||||
if (queryType.Equals("EQ"))
|
||||
{
|
||||
return $"m => m.{ propertyName} == parm.{propertyName})";
|
||||
}
|
||||
if (queryType.Equals("GTE"))
|
||||
{
|
||||
return $"m => m.{ propertyName} >= parm.{propertyName})";
|
||||
}
|
||||
if (queryType.Equals("GT"))
|
||||
{
|
||||
return $"m => m.{ propertyName} > parm.{propertyName})";
|
||||
}
|
||||
if (queryType.Equals("LT"))
|
||||
{
|
||||
return $"m => m.{ propertyName} < parm.{propertyName})";
|
||||
}
|
||||
if (queryType.Equals("LTE"))
|
||||
{
|
||||
return $"m => m.{ propertyName} <= parm.{propertyName})";
|
||||
}
|
||||
if (queryType.Equals("NE"))
|
||||
{
|
||||
return $"m => m.{ propertyName} != parm.{propertyName})";
|
||||
}
|
||||
if (queryType.Equals("LIKE"))
|
||||
{
|
||||
return $"m => m.{ propertyName}.Contains(parm.{propertyName}))";
|
||||
}
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,10 +1,10 @@
|
||||
using Infrastructure;
|
||||
using JinianNet.JNTemplate;
|
||||
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;
|
||||
|
||||
@ -24,11 +24,10 @@ namespace ZR.CodeGenerator
|
||||
/// <summary>
|
||||
/// 代码生成器入口方法
|
||||
/// </summary>
|
||||
/// <param name="dbTableInfo"></param>
|
||||
/// <param name="dto"></param>
|
||||
public static void Generate(GenTable dbTableInfo, GenerateDto dto)
|
||||
public static void Generate(GenerateDto dto)
|
||||
{
|
||||
_option.BaseNamespace = dbTableInfo.BaseNameSpace;
|
||||
_option.BaseNamespace = dto.GenTable.BaseNameSpace;
|
||||
_option.DtosNamespace = _option.BaseNamespace + "Model";
|
||||
_option.ModelsNamespace = _option.BaseNamespace + "Model";
|
||||
_option.RepositoriesNamespace = _option.BaseNamespace + "Repository";
|
||||
@ -37,128 +36,59 @@ namespace ZR.CodeGenerator
|
||||
_option.ServicesNamespace = _option.BaseNamespace + "Service";
|
||||
_option.ApiControllerNamespace = _option.BaseNamespace + "Admin.WebApi";
|
||||
|
||||
GenerateSingle(dbTableInfo?.Columns, dbTableInfo, dto);
|
||||
dto.GenOptions = _option;
|
||||
GenerateSingle(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)
|
||||
public static void GenerateSingle(GenerateDto dto)
|
||||
{
|
||||
string PKName = "id";
|
||||
string PKType = "int";
|
||||
ReplaceDto replaceDto = new();
|
||||
replaceDto.ModelTypeName = tableInfo.ClassName;//表名对应C# 实体类名
|
||||
replaceDto.TableName = tableInfo.TableName;//表名
|
||||
replaceDto.Permission = $"{tableInfo.ModuleName}:{tableInfo.ClassName.ToLower()}";//权限
|
||||
replaceDto.ViewsFileName = FirstLowerCase(replaceDto.ModelTypeName);
|
||||
replaceDto.Author = tableInfo.FunctionAuthor;
|
||||
|
||||
StringBuilder sb1 = new StringBuilder();
|
||||
StringBuilder sb2 = new StringBuilder();
|
||||
StringBuilder sb3 = new StringBuilder();
|
||||
replaceDto.ModelTypeName = dto.GenTable.ClassName;//表名对应C# 实体类名
|
||||
replaceDto.PermissionPrefix = $"{dto.GenTable.ModuleName}:{dto.GenTable.ClassName.ToLower()}";//权限
|
||||
replaceDto.Author = dto.GenTable.FunctionAuthor;
|
||||
|
||||
//循环表字段信息
|
||||
foreach (GenTableColumn dbFieldInfo in listField)
|
||||
foreach (GenTableColumn dbFieldInfo in dto.GenTable.Columns)
|
||||
{
|
||||
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)
|
||||
if (dbFieldInfo.HtmlType.Equals(GenConstants.HTML_IMAGE_UPLOAD))
|
||||
{
|
||||
replaceDto.UpdateColumn += $" {dbFieldInfo.CsharpField} = model.{dbFieldInfo.CsharpField}, \n";
|
||||
replaceDto.UploadFile = 1;
|
||||
}
|
||||
//新增字段
|
||||
if (dbFieldInfo.IsInsert)
|
||||
{
|
||||
replaceDto.InsertColumn += $" it.{dbFieldInfo.CsharpField}, \n";
|
||||
}
|
||||
//TODO 查询
|
||||
//if (dbFieldInfo.IsQuery)
|
||||
//{
|
||||
// replaceDto.Querycondition += $"predicate = predicate.And(m => m.{dbFieldInfo.CsharpField}.Contains(parm.Name));";
|
||||
//}
|
||||
CodeGenerateTemplate.GetQueryDtoProperty(dbFieldInfo, replaceDto);
|
||||
|
||||
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.VueViewFormHtml += CodeGenerateTemplate.TplVueFormContent(dbFieldInfo);
|
||||
replaceDto.VueViewListHtml += CodeGenerateTemplate.TplTableColumn(dbFieldInfo, dto.GenTable);
|
||||
replaceDto.VueViewEditFormRuleContent += CodeGenerateTemplate.TplFormRules(dbFieldInfo);
|
||||
replaceDto.VueQueryFormHtml += CodeGenerateTemplate.TplQueryFormHtml(dbFieldInfo);
|
||||
}
|
||||
//引用组件
|
||||
if (dbFieldInfo.HtmlType == GenConstants.HTML_EDITOR)
|
||||
{
|
||||
replaceDto.VueComponent += "Editor,";
|
||||
replaceDto.VueComponentImport += "import Editor from '@/components/Editor';\n";
|
||||
}
|
||||
|
||||
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;
|
||||
replaceDto.FistLowerPk = FirstLowerCase(PKName);
|
||||
InitJntTemplate(dto, replaceDto);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
if (dto.IsPreview == 1) return;
|
||||
|
||||
foreach (var item in dto.GenCodes)
|
||||
{
|
||||
FileHelper.WriteAndSave(item.Path, item.Content);
|
||||
@ -177,20 +107,10 @@ namespace ZR.CodeGenerator
|
||||
// ../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 tpl = FileHelper.ReadJtTemplate("TplModel.txt");
|
||||
var result = tpl.Render();
|
||||
|
||||
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));
|
||||
generateDto.GenCodes.Add(new GenCode(1, "Model", fullPath, result));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -202,20 +122,10 @@ namespace ZR.CodeGenerator
|
||||
{
|
||||
var fullPath = Path.Combine(generateDto.GenCodePath, _option.ModelsNamespace, "Dto", $"{replaceDto.ModelTypeName}Dto.cs");
|
||||
|
||||
if (File.Exists(fullPath) && !generateDto.Coverd)
|
||||
return;
|
||||
var tpl = FileHelper.ReadJtTemplate("TplDto.txt");
|
||||
|
||||
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));
|
||||
var result = tpl.Render();
|
||||
generateDto.GenCodes.Add(new GenCode(2, "Dto", fullPath, result));
|
||||
}
|
||||
#endregion
|
||||
|
||||
@ -229,48 +139,15 @@ namespace ZR.CodeGenerator
|
||||
private static void GenerateRepository(ReplaceDto replaceDto, GenerateDto generateDto)
|
||||
{
|
||||
var fullPath = Path.Combine(generateDto.GenCodePath, _option.RepositoriesNamespace, "Repositories", $"{replaceDto.ModelTypeName}Repository.cs");
|
||||
var tpl = FileHelper.ReadJtTemplate("TplRepository.txt");
|
||||
|
||||
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));
|
||||
var result = tpl.Render();
|
||||
generateDto.GenCodes.Add(new GenCode(3, "Repository", fullPath, result));
|
||||
}
|
||||
|
||||
#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文件
|
||||
@ -278,22 +155,16 @@ namespace ZR.CodeGenerator
|
||||
private static void GenerateService(ReplaceDto replaceDto, GenerateDto generateDto)
|
||||
{
|
||||
var fullPath = Path.Combine(generateDto.GenCodePath, _option.ServicesNamespace, "Business", $"{replaceDto.ModelTypeName}Service.cs");
|
||||
var tpl = FileHelper.ReadJtTemplate("TplService.txt");
|
||||
|
||||
if (File.Exists(fullPath) && !generateDto.Coverd)
|
||||
return;
|
||||
var result = tpl.Render();
|
||||
generateDto.GenCodes.Add(new GenCode(4, "Service", fullPath, result));
|
||||
|
||||
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);
|
||||
var fullPath2 = Path.Combine(generateDto.GenCodePath, _option.IServicsNamespace, "Business", "IBusService", $"I{replaceDto.ModelTypeName}Service.cs");
|
||||
var tpl2 = FileHelper.ReadJtTemplate("TplIService.txt");
|
||||
|
||||
generateDto.GenCodes.Add(new GenCode(4, "服务层", fullPath, content));
|
||||
var result2 = tpl2.Render();
|
||||
generateDto.GenCodes.Add(new GenCode(4, "IService", fullPath2, result2));
|
||||
}
|
||||
|
||||
#endregion
|
||||
@ -305,31 +176,11 @@ namespace ZR.CodeGenerator
|
||||
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 tpl = FileHelper.ReadJtTemplate("TplControllers.txt");
|
||||
|
||||
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("{ModuleName}", generateDto.GenTable.ModuleName)
|
||||
.Replace("{PKCsharpType}", replaceDto.PKType)
|
||||
.Replace("{Author}", replaceDto.Author)
|
||||
.Replace("{DateTime}", replaceDto.AddTime);
|
||||
|
||||
if (replaceDto.UpdateColumn != null)
|
||||
{
|
||||
content = content.Replace("{UpdateColumn}", replaceDto.UpdateColumn.TrimEnd('\n'));
|
||||
}
|
||||
if (replaceDto.InsertColumn != null)
|
||||
{
|
||||
content = content.Replace("{InsertColumn}", replaceDto.InsertColumn.TrimEnd('\n'));
|
||||
}
|
||||
generateDto.GenCodes.Add(new GenCode(5, "控制器", fullPath, content));
|
||||
tpl.Set("QueryCondition", replaceDto.QueryCondition);
|
||||
var result = tpl.Render();
|
||||
generateDto.GenCodes.Add(new GenCode(5, "Controller", fullPath, result));
|
||||
}
|
||||
#endregion
|
||||
|
||||
@ -338,28 +189,17 @@ namespace ZR.CodeGenerator
|
||||
/// 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");
|
||||
var fullPath = Path.Combine(generateDto.GenCodePath, "ZR.Vue", "src", "views", generateDto.GenTable.ModuleName, $"{generateDto.GenTable.BusinessName}.vue");
|
||||
|
||||
if (File.Exists(fullPath) && !generateDto.Coverd)
|
||||
return;
|
||||
var tpl = FileHelper.ReadJtTemplate("TplVue.txt");
|
||||
tpl.Set("vueQueryFormHtml", replaceDto.VueQueryFormHtml);
|
||||
tpl.Set("VueViewEditFormRuleContent", replaceDto.VueViewEditFormRuleContent);//添加、修改表单验证规则
|
||||
tpl.Set("VueViewFormContent", replaceDto.VueViewFormHtml);//添加、修改表单
|
||||
tpl.Set("VueViewListContent", replaceDto.VueViewListHtml);//查询 table列
|
||||
tpl.Set("lowerBusinessName", FirstLowerCase(generateDto.GenTable.BusinessName));
|
||||
|
||||
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("{VueComponent}", replaceDto.VueComponent.TrimEnd(','))
|
||||
.Replace("{VueComponentImport}", replaceDto.VueComponentImport)
|
||||
.Replace("{VueViewEditFormRuleContent}", replaceDto.VueViewEditFormRuleContent);//添加、修改表单验证规则
|
||||
|
||||
generateDto.GenCodes.Add(new GenCode(6, "index.vue", fullPath, content));
|
||||
var result = tpl.Render();
|
||||
generateDto.GenCodes.Add(new GenCode(6, "index.vue", fullPath, result));
|
||||
}
|
||||
/// <summary>
|
||||
/// 7、生成vue页面api
|
||||
@ -369,29 +209,21 @@ namespace ZR.CodeGenerator
|
||||
/// <returns></returns>
|
||||
public static void GenerateVueJs(ReplaceDto replaceDto, GenerateDto generateDto)
|
||||
{
|
||||
string fullPath = Path.Combine(generateDto.GenCodePath, "ZR.Vue", "src", "api", replaceDto.ViewsFileName + ".js");
|
||||
string fullPath = Path.Combine(generateDto.GenCodePath, "ZR.Vue", "src", "api", generateDto.GenTable.ModuleName, FirstLowerCase(generateDto.GenTable.BusinessName) + ".js");
|
||||
var tpl = FileHelper.ReadJtTemplate("TplVueApi.txt");
|
||||
|
||||
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));
|
||||
var result = tpl.Render();
|
||||
generateDto.GenCodes.Add(new GenCode(7, "api.js", fullPath, result));
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 8、生成SQL
|
||||
#region 生成SQL
|
||||
|
||||
public static void GenerateSql(ReplaceDto replaceDto, GenerateDto generateDto)
|
||||
{
|
||||
string fullPath = Path.Combine(generateDto.GenCodePath, replaceDto.ViewsFileName + ".sql");
|
||||
string fullPath = Path.Combine(generateDto.GenCodePath, generateDto.GenTable.BusinessName + ".sql");
|
||||
|
||||
if (File.Exists(fullPath) && !generateDto.Coverd)
|
||||
return;
|
||||
var tempName = "";
|
||||
switch (generateDto.DbType)
|
||||
{
|
||||
@ -404,15 +236,10 @@ namespace ZR.CodeGenerator
|
||||
default:
|
||||
break;
|
||||
}
|
||||
var content = FileHelper.ReadTemplate($"{tempName}.txt")
|
||||
.Replace("{ModelTypeName}", replaceDto.ModelTypeName)
|
||||
.Replace("{Permission}", replaceDto.Permission)
|
||||
.Replace("{ModuleName}", generateDto.GenTable.ModuleName)
|
||||
.Replace("{ViewsFileName}", replaceDto.ViewsFileName)
|
||||
.Replace("{ParentId}", generateDto.ParentMenuId.ToString())
|
||||
.Replace("{FunctionName}", generateDto.GenTable.FunctionName);
|
||||
|
||||
generateDto.GenCodes.Add(new GenCode(8, "sql", fullPath, content));
|
||||
var tpl = FileHelper.ReadJtTemplate($"{tempName}.txt");
|
||||
tpl.Set("parentId", generateDto.GenTable.ParentMenuId ?? 0);
|
||||
var result = tpl.Render();
|
||||
generateDto.GenCodes.Add(new GenCode(8, "sql", fullPath, result));
|
||||
}
|
||||
|
||||
#endregion
|
||||
@ -444,6 +271,19 @@ namespace ZR.CodeGenerator
|
||||
return tableName.Substring(0, 1).ToUpper() + tableName[1..].Replace("_", "");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取业务名
|
||||
/// </summary>
|
||||
/// <param name="tableName">tableName 表名</param>
|
||||
/// <returns>业务名</returns>
|
||||
public static string GetBusinessName(string tableName)
|
||||
{
|
||||
int lastIndex = tableName.LastIndexOf("_");
|
||||
int nameLength = tableName.Length;
|
||||
string businessName = tableName[(nameLength - lastIndex + 1)..];
|
||||
return businessName.ToLower();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 首字母转小写,输出前端
|
||||
/// </summary>
|
||||
@ -464,6 +304,34 @@ namespace ZR.CodeGenerator
|
||||
{
|
||||
return string.IsNullOrEmpty(columnDescription) ? columnName : columnDescription;
|
||||
}
|
||||
/// <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)" or "numeric" => "decimal",
|
||||
"bit" => "bool",
|
||||
"date" or "datetime" or "datetime2" or "smalldatetime" or "timestamp" => "DateTime",
|
||||
"money" or "smallmoney" => "decimal",
|
||||
_ => "string",
|
||||
};
|
||||
return sTempDatatype;
|
||||
}
|
||||
|
||||
public static bool IsNumber(string tableDataType)
|
||||
{
|
||||
string[] arr = new string[] { "int", "long" };
|
||||
return arr.Any(f => f.Contains(GetCSharpDatatype(tableDataType)));
|
||||
}
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
@ -535,32 +403,29 @@ namespace ZR.CodeGenerator
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取C# 类型
|
||||
/// 初始化Jnt模板
|
||||
/// </summary>
|
||||
/// <param name="sDatatype"></param>
|
||||
/// <returns></returns>
|
||||
public static string GetCSharpDatatype(string sDatatype)
|
||||
/// <param name="dto"></param>
|
||||
/// <param name="replaceDto"></param>
|
||||
private static void InitJntTemplate(GenerateDto dto, ReplaceDto replaceDto)
|
||||
{
|
||||
sDatatype = sDatatype.ToLower();
|
||||
string sTempDatatype = sDatatype switch
|
||||
Engine.Current.Clean();
|
||||
|
||||
//jnt模板引擎全局变量
|
||||
Engine.Configure((options) =>
|
||||
{
|
||||
"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;
|
||||
options.TagPrefix = "${";
|
||||
options.TagSuffix = "}";
|
||||
options.TagFlag = '$';
|
||||
options.OutMode = OutMode.Auto;
|
||||
//options.DisableeLogogram = true;//禁用简写
|
||||
options.Data.Set("refs", "$");//特殊标签替换
|
||||
options.Data.Set("replaceDto", replaceDto);
|
||||
options.Data.Set("options", dto.GenOptions);
|
||||
options.Data.Set("genTable", dto.GenTable);
|
||||
//...其它数据
|
||||
});
|
||||
}
|
||||
|
||||
public static bool IsNumber(string tableDataType)
|
||||
{
|
||||
string[] arr = new string[] { "int", "long" };
|
||||
return arr.Any(f => f.Contains(GetCSharpDatatype(tableDataType)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -4,6 +4,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ZR.CodeGenerator
|
||||
@ -24,11 +25,11 @@ namespace ZR.CodeGenerator
|
||||
{
|
||||
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))
|
||||
|
||||
if (!string.IsNullOrEmpty(dbName))
|
||||
{
|
||||
connStr = ConfigUtils.Instance.GetConnectionStrings(OptionsSetting.ConnAdmin);
|
||||
dbType = ConfigUtils.Instance.GetAppConfig<int>(OptionsSetting.ConnDbType);
|
||||
string replaceStr = GetValue(connStr, "database=", ";");
|
||||
connStr = connStr.Replace(replaceStr, dbName);
|
||||
}
|
||||
var db = new SqlSugarScope(new List<ConnectionConfig>()
|
||||
{
|
||||
@ -43,5 +44,18 @@ namespace ZR.CodeGenerator
|
||||
CodeDb = db;
|
||||
return db;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获得字符串中开始和结束字符串中间得值
|
||||
/// </summary>
|
||||
/// <param name="str">字符串</param>
|
||||
/// <param name="s">开始</param>
|
||||
/// <param name="e">结束</param>
|
||||
/// <returns></returns>
|
||||
public static string GetValue(string str, string s, string e)
|
||||
{
|
||||
Regex rg = new Regex("(?<=(" + s + "))[.\\s\\S]*?(?=(" + e + "))", RegexOptions.Multiline | RegexOptions.Singleline);
|
||||
return rg.Match(str).Value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using JinianNet.JNTemplate;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
@ -108,6 +109,16 @@ namespace ZR.CodeGenerator
|
||||
return str;
|
||||
}
|
||||
|
||||
public static ITemplate ReadJtTemplate(string tplName)
|
||||
{
|
||||
string path = Environment.CurrentDirectory;
|
||||
string fullName = Path.Combine(path, "wwwroot", "CodeGenTemplate", tplName);
|
||||
if (File.Exists(fullName))
|
||||
{
|
||||
return Engine.LoadTemplate(fullName);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 压缩代码
|
||||
|
||||
@ -64,10 +64,6 @@ namespace ZR.CodeGenerator
|
||||
/** 数据库时间类型 */
|
||||
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" };
|
||||
|
||||
@ -127,7 +123,7 @@ namespace ZR.CodeGenerator
|
||||
public static string TYPE_DOUBLE = "Double";
|
||||
|
||||
/** 时间类型 */
|
||||
public static string TYPE_DATE = "Date";
|
||||
public static string TYPE_DATE = "DateTime";
|
||||
|
||||
/** 模糊查询 */
|
||||
public static string QUERY_LIKE = "LIKE";
|
||||
|
||||
@ -1,8 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Collections.Generic;
|
||||
using ZR.Model.System.Generate;
|
||||
|
||||
namespace ZR.CodeGenerator.Model
|
||||
@ -10,24 +6,16 @@ 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; }
|
||||
public CodeGenerateOption GenOptions { get; set; }
|
||||
#region 存储路径
|
||||
/// <summary>
|
||||
/// 代码模板预览存储路径存放
|
||||
@ -45,10 +33,6 @@ namespace ZR.CodeGenerator.Model
|
||||
/// 代码生成压缩包名称
|
||||
/// </summary>
|
||||
public string ZipFileName { get; set; }
|
||||
/// <summary>
|
||||
/// 父级菜单id
|
||||
/// </summary>
|
||||
public long ParentMenuId { get; set; }
|
||||
#endregion
|
||||
}
|
||||
|
||||
|
||||
@ -1,8 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ZR.CodeGenerator.Model
|
||||
{
|
||||
@ -13,40 +9,21 @@ namespace ZR.CodeGenerator.Model
|
||||
/// </summary>
|
||||
public string PKName { get; set; }
|
||||
/// <summary>
|
||||
/// 首字母小写主键
|
||||
/// </summary>
|
||||
public string FistLowerPk{ get; set; }
|
||||
/// <summary>
|
||||
/// 主键类型
|
||||
/// </summary>
|
||||
public string PKType { get; set; }
|
||||
/// <summary>
|
||||
/// 控制器权限
|
||||
/// </summary>
|
||||
public string Permission { get; set; }
|
||||
public string PermissionPrefix { get; set; }
|
||||
/// <summary>
|
||||
/// C#类名
|
||||
/// </summary>
|
||||
public string ModelTypeName { get; set; }
|
||||
/// <summary>
|
||||
/// 数据库表名
|
||||
/// </summary>
|
||||
public string TableName { 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>
|
||||
@ -61,10 +38,7 @@ namespace ZR.CodeGenerator.Model
|
||||
/// 前端搜索表单html
|
||||
/// </summary>
|
||||
public string VueQueryFormHtml { get; set; }
|
||||
/// <summary>
|
||||
/// vue js方法
|
||||
/// </summary>
|
||||
public string VueJsMethod { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// vue 添加、编辑表单规则
|
||||
/// </summary>
|
||||
@ -72,31 +46,13 @@ namespace ZR.CodeGenerator.Model
|
||||
/// <summary>
|
||||
/// 查询条件
|
||||
/// </summary>
|
||||
public string QueryCondition { get; set; }
|
||||
public string QueryCondition { get; set; } = "";
|
||||
|
||||
/// <summary>
|
||||
/// 查询属性
|
||||
/// 上传URL data
|
||||
/// </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; }
|
||||
/// <summary>
|
||||
/// vue组件引用
|
||||
/// </summary>
|
||||
public string VueComponent { get; set; } = "";
|
||||
/// <summary>
|
||||
/// vue组件导入
|
||||
/// </summary>
|
||||
public string VueComponentImport { get; set; } = "";
|
||||
//public string VueUploadUrl { get; set; }
|
||||
public int UploadFile { get; set; } = 0;
|
||||
public string Author { get; set; }
|
||||
public string AddTime { get; set; } = DateTime.Now.ToString("yyyy-MM-dd");
|
||||
}
|
||||
|
||||
@ -11,13 +11,7 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="JinianNet.JNTemplate" Version="2.2.4" />
|
||||
<PackageReference Include="SqlSugarCoreNoDrive" Version="5.0.4.3" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Update="Template\ModelTemplate.txt">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
47
ZR.Common/AliyunOssHelper.cs
Normal file
47
ZR.Common/AliyunOssHelper.cs
Normal file
@ -0,0 +1,47 @@
|
||||
using Aliyun.OSS;
|
||||
using Aliyun.OSS.Common;
|
||||
using Infrastructure;
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
namespace ZR.Common
|
||||
{
|
||||
public class AliyunOssHelper
|
||||
{
|
||||
static string accessKeyId = ConfigUtils.Instance.GetConfig("ALIYUN_OSS:KEY");
|
||||
static string accessKeySecret = ConfigUtils.Instance.GetConfig("ALIYUN_OSS:SECRET");
|
||||
static string endpoint = ConfigUtils.Instance.GetConfig("ALIYUN_OSS:REGIONID");
|
||||
static string bucketName1 = ConfigUtils.Instance.GetConfig("ALIYUN_OSS:bucketName");
|
||||
|
||||
/// <summary>
|
||||
/// 上传到阿里云
|
||||
/// </summary>
|
||||
/// <param name="filestreams"></param>
|
||||
/// <param name="dirPath">存储路径 eg: upload/2020/01/01/xxx.png</param>
|
||||
/// <param name="bucketName">存储桶 如果为空默认取配置文件</param>
|
||||
public static System.Net.HttpStatusCode PutObjectFromFile(Stream filestreams, string dirPath, string bucketName = "")
|
||||
{
|
||||
OssClient client = new OssClient(endpoint, accessKeyId, accessKeySecret);
|
||||
if (string.IsNullOrEmpty(bucketName)) { bucketName = bucketName1; }
|
||||
try
|
||||
{
|
||||
dirPath = dirPath.Replace("\\", "/");
|
||||
PutObjectResult putObjectResult = client.PutObject(bucketName, dirPath, filestreams);
|
||||
// Console.WriteLine("Put object:{0} succeeded", directory);
|
||||
|
||||
return putObjectResult.HttpStatusCode;
|
||||
}
|
||||
catch (OssException ex)
|
||||
{
|
||||
Console.WriteLine("Failed with error code: {0}; Error info: {1}. \nRequestID:{2}\tHostID:{3}",
|
||||
ex.ErrorCode, ex.Message, ex.RequestId, ex.HostId);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine("Failed with error info: {0}", ex.Message);
|
||||
}
|
||||
return System.Net.HttpStatusCode.BadRequest;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@ -14,6 +14,7 @@ namespace ZR.Common
|
||||
public static long[] SpitLongArrary(string str)
|
||||
{
|
||||
if (string.IsNullOrEmpty(str)) { return Array.Empty<long>(); }
|
||||
str = str.TrimStart(',').TrimEnd(',');
|
||||
string[] strIds = str.Split(',', (char)StringSplitOptions.RemoveEmptyEntries);
|
||||
long[] infoIdss = Array.ConvertAll(strIds, s => long.Parse(s));
|
||||
return infoIdss;
|
||||
|
||||
@ -5,7 +5,12 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Aliyun.OSS.SDK.NetCore" Version="2.13.0" />
|
||||
<PackageReference Include="MailKit" Version="2.15.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="5.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Infrastructure\Infrastructure.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
||||
@ -1,103 +0,0 @@
|
||||
using Newtonsoft.Json;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace ZRModel
|
||||
{
|
||||
/// <summary>
|
||||
/// 通用json格式实体返回类
|
||||
/// Author by zhaorui
|
||||
/// </summary>
|
||||
public class ApiResult
|
||||
{
|
||||
public int Code { get; set; }
|
||||
public string Msg { get; set; }
|
||||
/// <summary>
|
||||
/// 如果data值为null,则忽略序列化将不会返回data字段
|
||||
/// </summary>
|
||||
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
|
||||
public object Data { get; set; }
|
||||
|
||||
public ApiResult()
|
||||
{
|
||||
Code = 0;
|
||||
Msg = "fail";
|
||||
}
|
||||
|
||||
public ApiResult OnSuccess()
|
||||
{
|
||||
Code = 100;
|
||||
Msg = "success";
|
||||
return this;
|
||||
}
|
||||
public ApiResult(int code, string msg, object data = null)
|
||||
{
|
||||
Code = code;
|
||||
Msg = msg;
|
||||
Data = data;
|
||||
}
|
||||
|
||||
public ApiResult OnSuccess(object data = null)
|
||||
{
|
||||
Code = (int)ResultCode.SUCCESS;
|
||||
Msg = "SUCCESS";
|
||||
Data = data;
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 返回成功消息
|
||||
/// </summary>
|
||||
/// <param name="data">数据对象</param>
|
||||
/// <returns>成功消息</returns>
|
||||
public static ApiResult Success(object data) { return new ApiResult(100, "success", data); }
|
||||
|
||||
/// <summary>
|
||||
/// 返回成功消息
|
||||
/// </summary>
|
||||
/// <param name="msg">返回内容</param>
|
||||
/// <returns>成功消息</returns>
|
||||
public static ApiResult Success(string msg) { return new ApiResult(100, msg, null); }
|
||||
|
||||
/// <summary>
|
||||
/// 返回成功消息
|
||||
/// </summary>
|
||||
/// <param name="msg">返回内容</param>
|
||||
/// <param name="data">数据对象</param>
|
||||
/// <returns>成功消息</returns>
|
||||
public static ApiResult Success(string msg, object data) { return new ApiResult(100, msg, data); }
|
||||
|
||||
/// <summary>
|
||||
/// 返回失败消息
|
||||
/// </summary>
|
||||
/// <param name="code"></param>
|
||||
/// <param name="msg"></param>
|
||||
/// <returns></returns>
|
||||
public static ApiResult Error(int code, string msg) { return new ApiResult(code, msg); }
|
||||
|
||||
/// <summary>
|
||||
/// 返回失败消息
|
||||
/// </summary>
|
||||
/// <param name="msg"></param>
|
||||
/// <returns></returns>
|
||||
public static ApiResult Error(string msg) { return new ApiResult(200, msg); }
|
||||
|
||||
}
|
||||
public enum ResultCode
|
||||
{
|
||||
[Description("success")]
|
||||
SUCCESS = 100,
|
||||
[Description("参数错误")]
|
||||
PARAM_ERROR = 101,
|
||||
[Description("自定义错误")]
|
||||
CUSTOM_ERROR = 200,
|
||||
FAIL = 0,
|
||||
[Description("程序出错啦")]
|
||||
GLOBAL_ERROR = 104,
|
||||
[Description("请先绑定手机号")]
|
||||
NOBIND_PHONENUM = 102,
|
||||
[Description("授权失败")]
|
||||
OAUTH_FAIL = 201,
|
||||
[Description("未授权")]
|
||||
DENY = 401
|
||||
}
|
||||
}
|
||||
@ -1,34 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using ZR.Model.Dto;
|
||||
using ZR.Model.Models;
|
||||
|
||||
namespace ZR.Model.Dto
|
||||
{
|
||||
/// <summary>
|
||||
/// 代码生成演示输入对象模型
|
||||
/// </summary>
|
||||
public class GendemoDto
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string Icon { get; set; }
|
||||
public int ShowStatus { get; set; }
|
||||
public int? Sex { get; set; }
|
||||
public int? Sort { get; set; }
|
||||
public DateTime? BeginTime { get; set; }
|
||||
public DateTime? EndTime { get; set; }
|
||||
public string Remark { get; set; }
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 代码生成演示查询对象模型
|
||||
/// </summary>
|
||||
public class GendemoQueryDto: PagerInfo
|
||||
{
|
||||
|
||||
public DateTime? BeginTime { get; set; }
|
||||
public DateTime? EndTime { get; set; }
|
||||
}
|
||||
}
|
||||
30
ZR.Model/Extensions/QueryableExtension.cs
Normal file
30
ZR.Model/Extensions/QueryableExtension.cs
Normal file
@ -0,0 +1,30 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace ZR.Model
|
||||
{
|
||||
/// <summary>
|
||||
/// 分页扩展
|
||||
/// </summary>
|
||||
public static class PageExtension
|
||||
{
|
||||
/// <summary>
|
||||
/// 读取列表
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="source"></param>
|
||||
/// <param name="parm"></param>
|
||||
/// <returns></returns>
|
||||
public static PagedInfo<T> ToPage<T>(this List<T> source, PagerInfo parm)
|
||||
{
|
||||
var page = new PagedInfo<T>
|
||||
{
|
||||
TotalPage = parm.TotalPage,
|
||||
TotalNum = parm.TotalNum,
|
||||
PageSize = parm.PageSize,
|
||||
PageIndex = parm.PageNum,
|
||||
Result = source
|
||||
};
|
||||
return page;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,68 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace ZR.Model.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// 代码生成演示,数据实体对象
|
||||
///
|
||||
/// @author zr
|
||||
/// @date 2021-11-24
|
||||
/// </summary>
|
||||
[SqlSugar.SugarTable("gen_demo")]
|
||||
public class Gendemo
|
||||
{
|
||||
/// <summary>
|
||||
/// 描述 :自增id
|
||||
/// 空值 :False
|
||||
/// </summary>
|
||||
[SqlSugar.SugarColumn(IsPrimaryKey = false, IsIdentity = true)]
|
||||
public int Id { get; set; }
|
||||
/// <summary>
|
||||
/// 描述 :名称
|
||||
/// 空值 :True
|
||||
/// </summary>
|
||||
public string Name { get; set; }
|
||||
/// <summary>
|
||||
/// 描述 :图片
|
||||
/// 空值 :True
|
||||
/// </summary>
|
||||
public string Icon { get; set; }
|
||||
/// <summary>
|
||||
/// 描述 :显示状态
|
||||
/// 空值 :False
|
||||
/// </summary>
|
||||
public int ShowStatus { get; set; }
|
||||
/// <summary>
|
||||
/// 描述 :添加时间
|
||||
/// 空值 :True
|
||||
/// </summary>
|
||||
public DateTime? AddTime { get; set; }
|
||||
/// <summary>
|
||||
/// 描述 :用户性别
|
||||
/// 空值 :True
|
||||
/// </summary>
|
||||
public int? Sex { get; set; }
|
||||
/// <summary>
|
||||
/// 描述 :排序
|
||||
/// 空值 :True
|
||||
/// </summary>
|
||||
public int? Sort { get; set; }
|
||||
/// <summary>
|
||||
/// 描述 :开始时间
|
||||
/// 空值 :True
|
||||
/// </summary>
|
||||
public DateTime? BeginTime { get; set; }
|
||||
/// <summary>
|
||||
/// 描述 :结束时间
|
||||
/// 空值 :True
|
||||
/// </summary>
|
||||
public DateTime? EndTime { get; set; }
|
||||
/// <summary>
|
||||
/// 描述 :备注
|
||||
/// 空值 :True
|
||||
/// </summary>
|
||||
public string Remark { get; set; }
|
||||
|
||||
}
|
||||
}
|
||||
@ -1,50 +0,0 @@
|
||||
|
||||
namespace ZRModel
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取配置文件POCO实体类
|
||||
/// </summary>
|
||||
public class OptionsSetting
|
||||
{
|
||||
/// <summary>
|
||||
/// 1、喵播 2、fireStar
|
||||
/// </summary>
|
||||
public int Platform { get; set; }
|
||||
public string AppName { get; set; }
|
||||
public string Redis { get; set; }
|
||||
public string Conn_Live { get; set; }
|
||||
public string Conn_Admin { get; set; }
|
||||
/// <summary>
|
||||
/// mongodb连接字符串
|
||||
/// </summary>
|
||||
public string Mongo_Conn { get; set; }
|
||||
public string Database { get; set; }
|
||||
|
||||
public LoggingOptions Logging { get; set; }
|
||||
public MailOptions MailOptions { get; set; }
|
||||
}
|
||||
/// <summary>
|
||||
/// 发送邮件数据配置
|
||||
/// </summary>
|
||||
public class MailOptions
|
||||
{
|
||||
public string From { get; set; }
|
||||
public string Password { get; set; }
|
||||
public string Host { get; set; }
|
||||
public int Port { get; set; }
|
||||
}
|
||||
/// <summary>
|
||||
/// 日志
|
||||
/// </summary>
|
||||
public class LoggingOptions
|
||||
{
|
||||
public LogLevelOptions LogLevel { get; set; }
|
||||
}
|
||||
public class LogLevelOptions
|
||||
{
|
||||
public string Default { get; set; }
|
||||
public string Ssytem { get; set; }
|
||||
public string Microsoft { get; set; }
|
||||
}
|
||||
|
||||
}
|
||||
@ -2,7 +2,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Infrastructure.Model
|
||||
namespace ZR.Model
|
||||
{
|
||||
/// <summary>
|
||||
/// 分页参数
|
||||
@ -20,34 +20,33 @@ namespace Infrastructure.Model
|
||||
/// <summary>
|
||||
/// 排序列
|
||||
/// </summary>
|
||||
//public string Sort { get; set; }
|
||||
public string Sort { get; set; }
|
||||
/// <summary>
|
||||
/// 排序类型
|
||||
/// </summary>
|
||||
//public string SortType { get; set; }
|
||||
public string SortType { get; set; }
|
||||
/// <summary>
|
||||
/// 总记录数
|
||||
/// </summary>
|
||||
public int TotalCount { get; set; }
|
||||
public int TotalNum { get; set; }
|
||||
/// <summary>
|
||||
/// 总页数
|
||||
/// </summary>
|
||||
//public int TotalPage
|
||||
//{
|
||||
// get
|
||||
// {
|
||||
// if (TotalCount > 0)
|
||||
// {
|
||||
// return TotalCount % this.PageSize == 0 ? TotalCount / this.PageSize : TotalCount / this.PageSize + 1;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// return 0;
|
||||
// }
|
||||
// }
|
||||
// set { }
|
||||
//}
|
||||
public int TotalPage { get; set; }
|
||||
public int TotalPage
|
||||
{
|
||||
get
|
||||
{
|
||||
if (TotalNum > 0)
|
||||
{
|
||||
return TotalNum % this.PageSize == 0 ? TotalNum / this.PageSize : TotalNum / this.PageSize + 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
set { }
|
||||
}
|
||||
public List<T> Result { get; set; }
|
||||
|
||||
public PagedInfo()
|
||||
@ -59,8 +58,8 @@ namespace Infrastructure.Model
|
||||
{
|
||||
PageIndex = pageIndex;
|
||||
PageSize = pageSize;
|
||||
TotalCount = source.Count;
|
||||
TotalPage = (int)Math.Ceiling(TotalCount / (double)PageSize);//计算总页数
|
||||
TotalNum = source.Count;
|
||||
TotalPage = (int)Math.Ceiling(TotalNum / (double)PageSize);//计算总页数
|
||||
}
|
||||
|
||||
}
|
||||
@ -18,9 +18,20 @@ namespace ZR.Model
|
||||
/// <summary>
|
||||
/// 总页码
|
||||
/// </summary>
|
||||
public int TotalPageNum { get; set; }
|
||||
/// <summary>
|
||||
/// 总页数
|
||||
/// </summary>
|
||||
public int TotalPage
|
||||
{
|
||||
get
|
||||
{
|
||||
return TotalNum > 0 ? TotalNum % PageSize == 0 ? TotalNum / PageSize : TotalNum / PageSize + 1 : 0;
|
||||
}
|
||||
set { }
|
||||
}
|
||||
public int PageSize { get => pageSize; set => pageSize = value; }
|
||||
|
||||
public string Sort { get; set; }
|
||||
public string OrderBy { get; set; }
|
||||
public PagerInfo()
|
||||
{
|
||||
PageNum = 1;
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
@ -8,6 +9,7 @@ namespace ZR.Model.System
|
||||
/// 文章表
|
||||
/// </summary>
|
||||
[SqlSugar.SugarTable("article")]
|
||||
[Tenant("0")]
|
||||
public class Article
|
||||
{
|
||||
[SqlSugar.SugarColumn(IsIdentity = true, IsPrimaryKey = true)]
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
using Newtonsoft.Json;
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
@ -8,7 +9,8 @@ namespace ZR.Model.System
|
||||
/// <summary>
|
||||
/// 文章目录
|
||||
/// </summary>
|
||||
[SqlSugar.SugarTable("articleCategory")]
|
||||
[SugarTable("articleCategory")]
|
||||
[Tenant("0")]
|
||||
public class ArticleCategory
|
||||
{
|
||||
public int Category_Id { get; set; }
|
||||
@ -16,7 +18,7 @@ namespace ZR.Model.System
|
||||
public int ParentId { get; set; }
|
||||
|
||||
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
|
||||
[SqlSugar.SugarColumn(IsIgnore = true)]
|
||||
[SugarColumn(IsIgnore = true)]
|
||||
public List<ArticleCategory> Children { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@ -24,7 +24,9 @@ namespace ZR.Model.System.Dto
|
||||
/// <summary>
|
||||
/// 上级菜单id
|
||||
/// </summary>
|
||||
public int ParentMenuId { get; set; }
|
||||
public int? ParentMenuId { get; set; }
|
||||
public string SortField { get; set; }
|
||||
public string SortType { get; set; }
|
||||
public List<GenTableColumnDto> Columns { get; set; }
|
||||
}
|
||||
|
||||
|
||||
@ -1,7 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using ZR.Model.Dto;
|
||||
using ZR.Model.Models;
|
||||
|
||||
namespace ZR.Model.Dto
|
||||
{
|
||||
@ -15,6 +12,7 @@ namespace ZR.Model.Dto
|
||||
public string ConfigKey { get; set; }
|
||||
public string ConfigValue { get; set; }
|
||||
public string ConfigType { get; set; }
|
||||
public string Remark { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@ -8,6 +8,7 @@ namespace ZR.Model.System.Generate
|
||||
/// 代码生成表
|
||||
/// </summary>
|
||||
[SqlSugar.SugarTable("gen_table")]
|
||||
[SqlSugar.Tenant("0")]
|
||||
public class GenTable : SysBase
|
||||
{
|
||||
/// <summary>
|
||||
@ -68,8 +69,18 @@ namespace ZR.Model.System.Generate
|
||||
/// </summary>
|
||||
public string Options { get; set; }
|
||||
|
||||
#region 表额外字段
|
||||
/** 表列信息 */
|
||||
[SqlSugar.SugarColumn(IsIgnore = true)]
|
||||
public List<GenTableColumn> Columns { get; set; }
|
||||
|
||||
//以下 Options扩展字段
|
||||
[SqlSugar.SugarColumn(IsIgnore = true)]
|
||||
public object ParentMenuId { get; set; }
|
||||
[SqlSugar.SugarColumn(IsIgnore = true)]
|
||||
public object SortType { get; set; } = "asc";
|
||||
[SqlSugar.SugarColumn(IsIgnore = true)]
|
||||
public object SortField { get; set; } = "";
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,53 +1,74 @@
|
||||
using Newtonsoft.Json;
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Linq;
|
||||
|
||||
namespace ZR.Model.System.Generate
|
||||
{
|
||||
/// <summary>
|
||||
/// 代码生成表字段
|
||||
/// </summary>
|
||||
[SqlSugar.SugarTable("gen_table_column")]
|
||||
[SugarTable("gen_table_column")]
|
||||
[Tenant("0")]
|
||||
public class GenTableColumn : SysBase
|
||||
{
|
||||
[SqlSugar.SugarColumn(IsIdentity = true, IsPrimaryKey = true)]
|
||||
[SugarColumn(IsIdentity = true, IsPrimaryKey = true)]
|
||||
public int ColumnId { get; set; }
|
||||
/// <summary>
|
||||
/// 导入代码生成表列名 首字母转了小写
|
||||
/// </summary>
|
||||
public string ColumnName { get; set; }
|
||||
[SqlSugar.SugarColumn(IsOnlyIgnoreUpdate = true)]
|
||||
[SugarColumn(IsOnlyIgnoreUpdate = true)]
|
||||
public int TableId { get; set; }
|
||||
|
||||
[SqlSugar.SugarColumn(IsOnlyIgnoreUpdate = true)]
|
||||
[SugarColumn(IsOnlyIgnoreUpdate = true)]
|
||||
public string TableName { get; set; }
|
||||
/// <summary>
|
||||
/// 列说明
|
||||
/// </summary>
|
||||
public string ColumnComment { get; set; }
|
||||
/// <summary>
|
||||
/// 数据库列类型
|
||||
/// </summary>
|
||||
|
||||
[SqlSugar.SugarColumn(IsOnlyIgnoreUpdate = true)]
|
||||
[SugarColumn(IsOnlyIgnoreUpdate = true)]
|
||||
public string ColumnType { get; set; }
|
||||
/// <summary>
|
||||
/// C#类型
|
||||
/// </summary>
|
||||
public string CsharpType { get; set; }
|
||||
/// <summary>
|
||||
/// C# 字段名 首字母大写
|
||||
/// </summary>
|
||||
public string CsharpField { get; set; }
|
||||
/// <summary>
|
||||
/// 是否主键(1是)
|
||||
/// </summary>
|
||||
[SqlSugar.SugarColumn(IsOnlyIgnoreUpdate = true)]
|
||||
[SugarColumn(IsOnlyIgnoreUpdate = true)]
|
||||
public bool IsPk { get; set; }
|
||||
/// <summary>
|
||||
/// 是否必填(1是)
|
||||
/// </summary>
|
||||
public bool IsRequired { get; set; }
|
||||
[SqlSugar.SugarColumn(IsOnlyIgnoreUpdate = true)]
|
||||
/// <summary>
|
||||
/// 是否自增(1是)
|
||||
/// </summary>
|
||||
[SugarColumn(IsOnlyIgnoreUpdate = true)]
|
||||
public bool IsIncrement { get; set; }
|
||||
/// <summary>
|
||||
/// 是否插入
|
||||
/// 是否插入(1是)
|
||||
/// </summary>
|
||||
public bool IsInsert { get; set; }
|
||||
/// <summary>
|
||||
/// 是否需要编辑
|
||||
/// 是否需要编辑(1是)
|
||||
/// </summary>
|
||||
public bool IsEdit { get; set; }
|
||||
/// <summary>
|
||||
/// isList
|
||||
/// 是否显示列表(1是)
|
||||
/// </summary>
|
||||
public bool IsList { get; set; }
|
||||
/// <summary>
|
||||
/// 是否查询(1是)
|
||||
/// </summary>
|
||||
public bool IsQuery { get; set; }
|
||||
/// <summary>
|
||||
/// 显示类型(文本框、文本域、下拉框、复选框、单选框、日期控件)
|
||||
@ -61,6 +82,23 @@ namespace ZR.Model.System.Generate
|
||||
/// <summary>
|
||||
/// 字典类型
|
||||
/// </summary>
|
||||
public string DictType { get; set; }
|
||||
public string DictType { get; set; } = "";
|
||||
|
||||
#region 额外字段
|
||||
[SugarColumn(IsIgnore = true)]
|
||||
public string RequiredStr
|
||||
{
|
||||
get
|
||||
{
|
||||
string[] arr = new string[] { "int", "long" };
|
||||
return (!IsRequired && (arr.Any(f => f.Contains(CsharpType))) || typeof(DateTime).Name == CsharpType) ? "?" : "";
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 字典集合
|
||||
/// </summary>
|
||||
//[SqlSugar.SugarColumn(IsIgnore = true)]
|
||||
//public List<SysDictData> DictDatas { get; set; }
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@ -4,27 +4,33 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using SqlSugar;
|
||||
using OfficeOpenXml.Attributes;
|
||||
|
||||
namespace ZR.Model.System
|
||||
{
|
||||
[EpplusTable(PrintHeaders = true, AutofitColumns = true, AutoCalculate = true, ShowTotal = true)]
|
||||
public class SysBase
|
||||
{
|
||||
[SugarColumn(IsOnlyIgnoreUpdate = true)]//设置后修改不会有此字段
|
||||
[JsonProperty(propertyName: "CreateBy")]
|
||||
[EpplusIgnore]
|
||||
public string Create_by { get; set; }
|
||||
|
||||
[SugarColumn(IsOnlyIgnoreUpdate = true)]//设置后修改不会有此字段
|
||||
[JsonProperty(propertyName: "CreateTime")]
|
||||
[EpplusTableColumn(NumberFormat = "yyyy-MM-dd HH:mm:ss")]
|
||||
public DateTime Create_time { get; set; } = DateTime.Now;
|
||||
|
||||
[JsonIgnore]
|
||||
[JsonProperty(propertyName: "UpdateBy")]
|
||||
[SugarColumn(IsOnlyIgnoreInsert = true)]
|
||||
[EpplusIgnore]
|
||||
public string Update_by { get; set; }
|
||||
|
||||
//[JsonIgnore]
|
||||
[SugarColumn(IsOnlyIgnoreInsert = true)]//设置后插入数据不会有此字段
|
||||
[JsonProperty(propertyName: "UpdateTime")]
|
||||
[EpplusIgnore]
|
||||
public DateTime? Update_time { get; set; }
|
||||
|
||||
public string Remark { get; set; }
|
||||
@ -40,6 +46,7 @@ namespace ZR.Model.System
|
||||
/// </summary>
|
||||
[SugarColumn(IsIgnore = true)]
|
||||
[JsonIgnore]
|
||||
[EpplusIgnore]
|
||||
public DateTime? BeginTime { get; set; }
|
||||
|
||||
/// <summary>
|
||||
@ -47,6 +54,7 @@ namespace ZR.Model.System
|
||||
/// </summary>
|
||||
[SugarColumn(IsIgnore = true)]
|
||||
[JsonIgnore]
|
||||
[EpplusIgnore]
|
||||
public DateTime? EndTime { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
@ -10,7 +11,8 @@ namespace ZR.Model.System
|
||||
/// @author zhaorui
|
||||
/// @date 2021-09-29
|
||||
/// </summary>
|
||||
[SqlSugar.SugarTable("sys_config")]
|
||||
[SugarTable("sys_config")]
|
||||
[Tenant("0")]
|
||||
public class SysConfig: SysBase
|
||||
{
|
||||
/// <summary>
|
||||
|
||||
@ -8,7 +8,8 @@ namespace ZR.Model.System
|
||||
/// <summary>
|
||||
/// 部门表
|
||||
/// </summary>
|
||||
[SqlSugar.SugarTable("sys_dept")]
|
||||
[SugarTable("sys_dept")]
|
||||
[Tenant("0")]
|
||||
public class SysDept: SysBase
|
||||
{
|
||||
/** 部门ID */
|
||||
|
||||
@ -9,7 +9,7 @@ namespace ZR.Model.System
|
||||
/// <summary>
|
||||
/// 字典数据表
|
||||
/// </summary>
|
||||
//[Table("sys_dict_data")]
|
||||
[Tenant("0")]
|
||||
[SugarTable("sys_dict_data")]
|
||||
public class SysDictData: SysBase
|
||||
{
|
||||
|
||||
@ -1,8 +1,5 @@
|
||||
//using Dapper.Contrib.Extensions;
|
||||
using OfficeOpenXml.Attributes;
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace ZR.Model.System
|
||||
{
|
||||
@ -10,7 +7,7 @@ namespace ZR.Model.System
|
||||
/// 字典类型表
|
||||
/// </summary>
|
||||
[SugarTable("sys_dict_type")]//当和数据库名称不一样可以设置别名
|
||||
//[Table("sys_dict_type")]
|
||||
[Tenant("0")]
|
||||
public class SysDictType : SysBase
|
||||
{
|
||||
/// <summary>
|
||||
@ -30,6 +27,7 @@ namespace ZR.Model.System
|
||||
/// <summary>
|
||||
/// 状态 0、正常 1、停用
|
||||
/// </summary>
|
||||
[EpplusIgnore]
|
||||
public string Status { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,10 +1,12 @@
|
||||
using System;
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace ZR.Model.System
|
||||
{
|
||||
[SqlSugar.SugarTable("sys_file")]
|
||||
[Tenant("0")]
|
||||
[SugarTable("sys_file")]
|
||||
public class SysFile
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
//using Dapper.Contrib.Extensions;
|
||||
using OfficeOpenXml.Attributes;
|
||||
using SqlSugar;
|
||||
using System;
|
||||
|
||||
@ -8,6 +9,7 @@ namespace ZR.Model.System
|
||||
/// sys_logininfor 表
|
||||
/// </summary>
|
||||
[SugarTable("sys_logininfor")]
|
||||
[Tenant("0")]
|
||||
public class SysLogininfor: SysBase
|
||||
{
|
||||
//[Key]
|
||||
@ -51,6 +53,7 @@ namespace ZR.Model.System
|
||||
/// <summary>
|
||||
/// 访问时间
|
||||
/// </summary>
|
||||
[EpplusTableColumn(NumberFormat = "yyyy-MM-dd HH:mm:ss")]
|
||||
public DateTime loginTime { get; set; } = DateTime.Now;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,12 +1,13 @@
|
||||
using System.Collections.Generic;
|
||||
using SqlSugar;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace ZR.Model.System
|
||||
{
|
||||
/// <summary>
|
||||
/// Sys_menu表
|
||||
/// </summary>
|
||||
//[Table("sys_menu")]
|
||||
[SqlSugar.SugarTable("sys_menu")]
|
||||
[SugarTable("sys_menu")]
|
||||
[Tenant("0")]
|
||||
public class SysMenu: SysBase
|
||||
{
|
||||
/// <summary>
|
||||
|
||||
@ -1,34 +1,37 @@
|
||||
using Newtonsoft.Json;
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using OfficeOpenXml.Attributes;
|
||||
|
||||
namespace ZR.Model.System
|
||||
{
|
||||
[SqlSugar.SugarTable("sys_oper_log")]
|
||||
[SugarTable("sys_oper_log")]
|
||||
[Tenant("0")]
|
||||
public class SysOperLog
|
||||
{
|
||||
[SqlSugar.SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
|
||||
[SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
|
||||
public long OperId { get; set; }
|
||||
/** 操作模块 */
|
||||
//@Excel(name = "操作模块")
|
||||
public String title { get; set; }
|
||||
public string title { get; set; }
|
||||
|
||||
/** 业务类型(0其它 1新增 2修改 3删除) */
|
||||
//@Excel(name = "业务类型", readConverterExp = "0=其它,1=新增,2=修改,3=删除,4=授权,5=导出,6=导入,7=强退,8=生成代码,9=清空数据")
|
||||
public int businessType { get; set; }
|
||||
|
||||
/** 业务类型数组 */
|
||||
[SqlSugar.SugarColumn(IsIgnore = true)]
|
||||
[SugarColumn(IsIgnore = true)]
|
||||
public int[] businessTypes { get; set; }
|
||||
|
||||
/** 请求方法 */
|
||||
//@Excel(name = "请求方法")
|
||||
public String method { get; set; }
|
||||
public string method { get; set; }
|
||||
|
||||
/** 请求方式 */
|
||||
//@Excel(name = "请求方式")
|
||||
public String requestMethod { get; set; }
|
||||
public string requestMethod { get; set; }
|
||||
|
||||
/** 操作类别(0其它 1后台用户 2手机端用户) */
|
||||
//@Excel(name = "操作类别", readConverterExp = "0=其它,1=后台用户,2=手机端用户")
|
||||
@ -36,31 +39,31 @@ namespace ZR.Model.System
|
||||
|
||||
/** 操作人员 */
|
||||
//@Excel(name = "操作人员")
|
||||
public String operName { get; set; }
|
||||
public string operName { get; set; }
|
||||
|
||||
/** 部门名称 */
|
||||
//@Excel(name = "部门名称")
|
||||
public String deptName { get; set; }
|
||||
public string deptName { get; set; }
|
||||
|
||||
/** 请求url */
|
||||
//@Excel(name = "请求地址")
|
||||
public String operUrl { get; set; }
|
||||
public string operUrl { get; set; }
|
||||
|
||||
/** 操作地址 */
|
||||
//@Excel(name = "操作地址")
|
||||
public String operIp { get; set; }
|
||||
public string operIp { get; set; }
|
||||
|
||||
/** 操作地点 */
|
||||
//@Excel(name = "操作地点")
|
||||
public String operLocation { get; set; }
|
||||
public string operLocation { get; set; }
|
||||
|
||||
/** 请求参数 */
|
||||
//@Excel(name = "请求参数")
|
||||
public String operParam { get; set; }
|
||||
public string operParam { get; set; }
|
||||
|
||||
/** 返回参数 */
|
||||
//@Excel(name = "返回参数")
|
||||
public String jsonResult { get; set; }
|
||||
public string jsonResult { get; set; }
|
||||
|
||||
/** 操作状态(0正常 1异常) */
|
||||
//@Excel(name = "状态", readConverterExp = "0=正常,1=异常")
|
||||
@ -68,13 +71,14 @@ namespace ZR.Model.System
|
||||
|
||||
/** 错误消息 */
|
||||
//@Excel(name = "错误消息")
|
||||
public String errorMsg { get; set; }
|
||||
public string errorMsg { get; set; }
|
||||
|
||||
/** 操作时间 */
|
||||
//@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
//@Excel(name = "操作时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
|
||||
//[DataType]
|
||||
[JsonConverter(typeof(JsonDateConverter))]
|
||||
[EpplusTableColumn(NumberFormat = "yyyy-MM-dd HH:mm:ss")]
|
||||
public DateTime? operTime { get; set; }
|
||||
/// <summary>
|
||||
/// 操作用时
|
||||
|
||||
@ -1,16 +1,22 @@
|
||||
namespace ZR.Model.System
|
||||
using OfficeOpenXml.Attributes;
|
||||
using SqlSugar;
|
||||
|
||||
namespace ZR.Model.System
|
||||
{
|
||||
[SqlSugar.SugarTable("sys_post")]
|
||||
[SugarTable("sys_post")]
|
||||
[Tenant("0")]
|
||||
public class SysPost : SysBase
|
||||
{
|
||||
/// <summary>
|
||||
/// 岗位Id
|
||||
/// </summary>
|
||||
[SqlSugar.SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
|
||||
[SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
|
||||
public long PostId { get; set; }
|
||||
public string PostCode { get; set; }
|
||||
public string PostName { get; set; }
|
||||
[EpplusIgnore]
|
||||
public int PostSort { get; set; }
|
||||
[EpplusIgnore]
|
||||
public string Status { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
using Newtonsoft.Json;
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
@ -8,13 +9,14 @@ namespace ZR.Model.System
|
||||
/// <summary>
|
||||
/// 角色表 sys_role
|
||||
/// </summary>
|
||||
[SqlSugar.SugarTable("sys_role")]
|
||||
[SugarTable("sys_role")]
|
||||
[Tenant("0")]
|
||||
public class SysRole : SysBase
|
||||
{
|
||||
/// <summary>
|
||||
/// 角色ID
|
||||
/// </summary>
|
||||
[SqlSugar.SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
|
||||
[SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
|
||||
public long RoleId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
@ -40,18 +42,18 @@ namespace ZR.Model.System
|
||||
/// <summary>
|
||||
/// 删除标志(0代表存在 2代表删除)
|
||||
/// </summary>
|
||||
[SqlSugar.SugarColumn(IsOnlyIgnoreInsert = true, IsOnlyIgnoreUpdate = true)]
|
||||
[SugarColumn(IsOnlyIgnoreInsert = true, IsOnlyIgnoreUpdate = true)]
|
||||
public string DelFlag { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 菜单组
|
||||
/// </summary>
|
||||
[SqlSugar.SugarColumn(IsIgnore = true)]
|
||||
[SugarColumn(IsIgnore = true)]
|
||||
public long[] MenuIds { get; set; }
|
||||
/// <summary>
|
||||
/// 部门组(数据权限)
|
||||
/// </summary>
|
||||
[SqlSugar.SugarColumn(IsIgnore = true)]
|
||||
[SugarColumn(IsIgnore = true)]
|
||||
public long[] DeptIds { get; set; }
|
||||
|
||||
public SysRole() { }
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
using Newtonsoft.Json;
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
@ -8,14 +9,15 @@ namespace ZR.Model.System
|
||||
/// <summary>
|
||||
/// 角色菜单
|
||||
/// </summary>
|
||||
[SqlSugar.SugarTable("sys_role_menu")]
|
||||
[SugarTable("sys_role_menu")]
|
||||
[Tenant("0")]
|
||||
public class SysRoleMenu
|
||||
{
|
||||
[JsonProperty("roleId")]
|
||||
[SqlSugar.SugarColumn(IsPrimaryKey = true)]
|
||||
[SugarColumn(IsPrimaryKey = true)]
|
||||
public long Role_id { get; set; }
|
||||
[JsonProperty("menuId")]
|
||||
[SqlSugar.SugarColumn(IsPrimaryKey = true)]
|
||||
[SugarColumn(IsPrimaryKey = true)]
|
||||
public long Menu_id { get; set; }
|
||||
public DateTime Create_time { get; set; }
|
||||
public string Create_by { get; set; }
|
||||
|
||||
@ -9,6 +9,7 @@ namespace ZR.Model.System
|
||||
/// 角色部门
|
||||
/// </summary>
|
||||
[SugarTable("sys_role_post")]
|
||||
[Tenant("0")]
|
||||
public class SysRolePost
|
||||
{
|
||||
public long RoleId { get; set; }
|
||||
|
||||
@ -1,4 +1,6 @@
|
||||
using System;
|
||||
using OfficeOpenXml.Attributes;
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
@ -7,13 +9,14 @@ namespace ZR.Model.System
|
||||
/// <summary>
|
||||
/// 任务日志
|
||||
/// </summary>
|
||||
[SqlSugar.SugarTable("sys_Tasks_log")]
|
||||
[SugarTable("sys_Tasks_log")]
|
||||
[Tenant("0")]
|
||||
public class SysTasksLog
|
||||
{
|
||||
/// <summary>
|
||||
/// 日志Id
|
||||
/// </summary>
|
||||
[SqlSugar.SugarColumn(IsIdentity = true, IsPrimaryKey = true)]
|
||||
[SugarColumn(IsIdentity = true, IsPrimaryKey = true)]
|
||||
public long JobLogId { get; set; }
|
||||
/// <summary>
|
||||
/// 任务Id
|
||||
@ -37,6 +40,8 @@ namespace ZR.Model.System
|
||||
/// 调用目标字符串
|
||||
/// </summary>
|
||||
public string InvokeTarget { get; set; }
|
||||
|
||||
[EpplusTableColumn(NumberFormat = "yyyy-MM-dd HH:mm:ss")]
|
||||
public DateTime CreateTime { get; set; }
|
||||
/// <summary>
|
||||
/// 执行用时,毫秒
|
||||
|
||||
@ -11,6 +11,7 @@ namespace ZR.Model.System
|
||||
///计划任务
|
||||
///</summary>
|
||||
[SugarTable("Sys_TasksQz")]
|
||||
[Tenant("0")]
|
||||
public class SysTasksQz
|
||||
{
|
||||
public SysTasksQz()
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
using Newtonsoft.Json;
|
||||
using OfficeOpenXml.Attributes;
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@ -10,6 +11,7 @@ namespace ZR.Model.System
|
||||
/// 用户表
|
||||
/// </summary>
|
||||
[SugarTable("sys_user")]
|
||||
[Tenant("0")]
|
||||
public class SysUser : SysBase
|
||||
{
|
||||
/// <summary>
|
||||
@ -28,12 +30,13 @@ namespace ZR.Model.System
|
||||
//[JsonProperty(propertyName: "userType")]
|
||||
//public string User_type { get; set; } = "";
|
||||
[SugarColumn(IsOnlyIgnoreInsert = true)]
|
||||
[EpplusIgnore]
|
||||
public string Avatar { get; set; }
|
||||
|
||||
public string Email { get; set; }
|
||||
|
||||
[JsonIgnore]
|
||||
//[ColName("用户密码")]
|
||||
[EpplusIgnore]
|
||||
public string Password { get; set; }
|
||||
|
||||
//[ColName("手机号")]
|
||||
@ -47,6 +50,7 @@ namespace ZR.Model.System
|
||||
/// <summary>
|
||||
/// 帐号状态(0正常 1停用)
|
||||
/// </summary>
|
||||
[EpplusIgnore]
|
||||
public string Status { get; set; }
|
||||
|
||||
/// <summary>
|
||||
@ -65,6 +69,7 @@ namespace ZR.Model.System
|
||||
/// 最后登录时间
|
||||
/// </summary>
|
||||
[SugarColumn(IsOnlyIgnoreInsert = true)]
|
||||
[EpplusTableColumn(NumberFormat = "yyyy-MM-dd HH:mm:ss")]
|
||||
public DateTime LoginDate { get; set; }
|
||||
|
||||
/// <summary>
|
||||
@ -93,14 +98,17 @@ namespace ZR.Model.System
|
||||
/// 角色id集合
|
||||
/// </summary>
|
||||
[SugarColumn(IsIgnore = true)]
|
||||
[EpplusIgnore]
|
||||
public int[] RoleIds { get; set; }
|
||||
/// <summary>
|
||||
/// 岗位集合
|
||||
/// </summary>
|
||||
[SugarColumn(IsIgnore = true)]
|
||||
[EpplusIgnore]
|
||||
public int[] PostIds { get; set; }
|
||||
|
||||
[SugarColumn(IsIgnore = true)]
|
||||
[EpplusIgnore]
|
||||
public List<SysRole> Roles { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
@ -10,6 +10,7 @@ namespace ZR.Model.System
|
||||
/// 用户岗位
|
||||
/// </summary>
|
||||
[SugarTable("sys_user_post")]
|
||||
[Tenant("0")]
|
||||
public class SysUserPost
|
||||
{
|
||||
public long UserId { get; set; }
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
@ -8,6 +9,7 @@ namespace ZR.Model.System
|
||||
/// 用户角色关联表 用户N-1 角色
|
||||
/// </summary>
|
||||
[SqlSugar.SugarTable("sys_user_role")]
|
||||
[Tenant("0")]
|
||||
public class SysUserRole
|
||||
{
|
||||
[SqlSugar.SugarColumn(ColumnName = "user_id", IsPrimaryKey = true)]
|
||||
|
||||
@ -1,53 +0,0 @@
|
||||
using Newtonsoft.Json;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
|
||||
namespace ZR.Model.Vo
|
||||
{
|
||||
public class VMPageResult<T> where T : new()
|
||||
{
|
||||
public int Page { get; set; }
|
||||
public int PageSize { get; set; }
|
||||
public long TotalNum { get; set; }
|
||||
//public int TotalPages { get; set; }
|
||||
public IList<T> Result { get; set; }
|
||||
public long EndPage { get; set; }
|
||||
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
|
||||
public DataTable Data { get; set; }
|
||||
|
||||
public VMPageResult()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 集合使用
|
||||
/// </summary>
|
||||
/// <param name="result"></param>
|
||||
/// <param name="pagerInfo"></param>
|
||||
public VMPageResult(IList<T> result, PagerInfo pagerInfo)
|
||||
{
|
||||
this.Result = result;
|
||||
this.TotalNum = pagerInfo.TotalNum;
|
||||
this.PageSize = pagerInfo.PageSize;
|
||||
this.Page = pagerInfo.PageNum;
|
||||
//计算
|
||||
this.EndPage = pagerInfo.TotalNum % PageSize == 0 ? pagerInfo.TotalNum / PageSize : pagerInfo.TotalNum / PageSize + 1;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// datable使用
|
||||
/// </summary>
|
||||
/// <param name="result"></param>
|
||||
/// <param name="pagerInfo"></param>
|
||||
public VMPageResult(DataTable result, PagerInfo pagerInfo)
|
||||
{
|
||||
this.Data = result;
|
||||
this.TotalNum = pagerInfo.TotalNum;
|
||||
this.PageSize = pagerInfo.PageSize;
|
||||
this.Page = pagerInfo.PageNum;
|
||||
//计算
|
||||
this.EndPage = pagerInfo.TotalNum % PageSize == 0 ? pagerInfo.TotalNum / PageSize : pagerInfo.TotalNum / PageSize + 1;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -5,11 +5,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Remove="ApiResult.cs" />
|
||||
<Compile Remove="OptionsSetting.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="EPPlus" Version="5.8.3" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
|
||||
<PackageReference Include="SqlSugarCoreNoDrive" Version="5.0.4.3" />
|
||||
<PackageReference Include="System.ComponentModel.Annotations" Version="5.0.0" />
|
||||
@ -18,6 +14,7 @@
|
||||
<ItemGroup>
|
||||
<Folder Include="Dto\" />
|
||||
<Folder Include="Enum\" />
|
||||
<Folder Include="Vo\" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@ -4,7 +4,9 @@ using SqlSugar.IOC;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Reflection;
|
||||
using ZR.Model;
|
||||
|
||||
namespace ZR.Repository
|
||||
@ -16,54 +18,37 @@ namespace ZR.Repository
|
||||
public class BaseRepository<T> : IBaseRepository<T> where T : class, new()
|
||||
{
|
||||
public ISqlSugarClient Context;
|
||||
public BaseRepository(string configId = "0")
|
||||
|
||||
public BaseRepository(ISqlSugarClient client = null)
|
||||
{
|
||||
Context = DbScoped.SugarScope.GetConnection(configId);//根据类传入的ConfigId自动选择
|
||||
var configId = typeof(T).GetCustomAttribute<TenantAttribute>()?.configId;
|
||||
if(configId != null)
|
||||
{
|
||||
Context = DbScoped.SugarScope.GetConnection(configId);
|
||||
}
|
||||
else
|
||||
{
|
||||
Context = client ?? DbScoped.SugarScope.GetConnection(1);//根据类传入的ConfigId自动选择
|
||||
}
|
||||
}
|
||||
|
||||
#region add
|
||||
/// <summary>
|
||||
/// 插入指定列使用
|
||||
/// </summary>
|
||||
/// <param name="parm"></param>
|
||||
/// <param name="iClumns"></param>
|
||||
/// <param name="ignoreNull"></param>
|
||||
/// <returns></returns>
|
||||
public int Add(T parm, Expression<Func<T, object>> iClumns = null, bool ignoreNull = true)
|
||||
{
|
||||
return Context.Insertable(parm).InsertColumns(iClumns).IgnoreColumns(ignoreNullColumn: ignoreNull).ExecuteCommand();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 插入实体
|
||||
/// </summary>
|
||||
/// <param name="t"></param>
|
||||
/// <param name="IgnoreNullColumn">默认忽略null列</param>
|
||||
/// <returns></returns>
|
||||
public int Add(T t)
|
||||
{
|
||||
return Context.Insertable(t).ExecuteCommand();
|
||||
return Context.Insertable(t).IgnoreColumns(true).ExecuteCommand();
|
||||
}
|
||||
|
||||
//public int InsertIgnoreNullColumn(T t)
|
||||
//{
|
||||
// return Context.Insertable(t).IgnoreColumns(true).ExecuteCommand();
|
||||
//}
|
||||
|
||||
//public int InsertIgnoreNullColumn(T t, params string[] columns)
|
||||
//{
|
||||
// return Context.Insertable(t).IgnoreColumns(columns).ExecuteCommand();
|
||||
//}
|
||||
|
||||
//public int Insert(SqlSugarClient client, T t)
|
||||
//{
|
||||
// return client.Insertable(t).ExecuteCommand();
|
||||
//}
|
||||
|
||||
//public long InsertBigIdentity(T t)
|
||||
//{
|
||||
// return base.Context.Insertable(t).ExecuteReturnBigIdentity();
|
||||
//}
|
||||
|
||||
public int Insert(List<T> t)
|
||||
{
|
||||
return Context.Insertable(t).ExecuteCommand();
|
||||
@ -82,10 +67,10 @@ namespace ZR.Repository
|
||||
//{
|
||||
// return base.Context.Insertable(t).IgnoreColumns(columns).ExecuteCommand();
|
||||
//}
|
||||
//public int Insert(T parm, Expression<Func<T, object>> iClumns = null, bool ignoreNull = true)
|
||||
//{
|
||||
// return base.Context.Insertable(parm).InsertColumns(iClumns).IgnoreColumns(ignoreNullColumn: ignoreNull).ExecuteCommand();
|
||||
//}
|
||||
public int Insert(T parm, Expression<Func<T, object>> iClumns = null, bool ignoreNull = true)
|
||||
{
|
||||
return Context.Insertable(parm).InsertColumns(iClumns).IgnoreColumns(ignoreNullColumn: ignoreNull).ExecuteCommand();
|
||||
}
|
||||
//public DbResult<bool> InsertTran(T t)
|
||||
//{
|
||||
// var result = base.Context.Ado.UseTran(() =>
|
||||
@ -128,35 +113,33 @@ namespace ZR.Repository
|
||||
//{
|
||||
// return base.Context.Ado.ExecuteCommand(sql, parameters) > 0;
|
||||
//}
|
||||
|
||||
public IInsertable<T> Insertable(T t)
|
||||
{
|
||||
return Context.Insertable<T>(t);
|
||||
}
|
||||
#endregion add
|
||||
|
||||
#region update
|
||||
|
||||
//public bool UpdateEntity(T entity, bool ignoreNullColumns = false)
|
||||
//{
|
||||
// return base.Context.Updateable(entity).IgnoreColumns(ignoreNullColumns).ExecuteCommand() > 0;
|
||||
//}
|
||||
public bool Update(T entity, bool ignoreNullColumns = false)
|
||||
{
|
||||
return Context.Updateable(entity).IgnoreColumns(ignoreNullColumns).ExecuteCommand() > 0;
|
||||
}
|
||||
|
||||
//public bool Update(T entity, Expression<Func<T, bool>> expression)
|
||||
//{
|
||||
// return base.Context.Updateable(entity).Where(expression).ExecuteCommand() > 0;
|
||||
//}
|
||||
public bool Update(T entity, Expression<Func<T, object>> expression, bool ignoreAllNull = false)
|
||||
{
|
||||
return Context.Updateable(entity).UpdateColumns(expression).IgnoreColumns(ignoreAllNull).ExecuteCommand() > 0;
|
||||
}
|
||||
|
||||
//public bool Update(T entity, Expression<Func<T, object>> expression, bool ignoreAllNull = false)
|
||||
//{
|
||||
// return base.Context.Updateable(entity).UpdateColumns(expression).IgnoreColumns(ignoreAllNull).ExecuteCommand() > 0;
|
||||
//}
|
||||
public bool Update(T entity, Expression<Func<T, object>> expression, Expression<Func<T, bool>> where)
|
||||
{
|
||||
return Context.Updateable(entity).UpdateColumns(expression).Where(where).ExecuteCommand() > 0;
|
||||
}
|
||||
|
||||
//public bool Update(T entity, Expression<Func<T, object>> expression, Expression<Func<T, bool>> where)
|
||||
//{
|
||||
// return base.Context.Updateable(entity).UpdateColumns(expression).Where(where).ExecuteCommand() > 0;
|
||||
//}
|
||||
|
||||
//public bool Update(SqlSugarClient client, T entity, Expression<Func<T, object>> expression, Expression<Func<T, bool>> where)
|
||||
//{
|
||||
// return client.Updateable(entity).UpdateColumns(expression).Where(where).ExecuteCommand() > 0;
|
||||
//}
|
||||
public bool Update(SqlSugarClient client, T entity, Expression<Func<T, object>> expression, Expression<Func<T, bool>> where)
|
||||
{
|
||||
return client.Updateable(entity).UpdateColumns(expression).Where(where).ExecuteCommand() > 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
@ -175,7 +158,6 @@ namespace ZR.Repository
|
||||
"Create_time"
|
||||
};
|
||||
}
|
||||
//base.Context.Updateable(entity).IgnoreColumns(c => list.Contains(c)).Where(isNull).ExecuteCommand()
|
||||
return Context.Updateable(entity).IgnoreColumns(isNull).IgnoreColumns(list.ToArray()).ExecuteCommand() > 0;
|
||||
}
|
||||
|
||||
@ -281,40 +263,40 @@ namespace ZR.Repository
|
||||
// return Context.Queryable<T>(tableName).ToList();
|
||||
//}
|
||||
|
||||
//public (List<T>, int) QueryableToPage(Expression<Func<T, bool>> expression, int pageIndex = 0, int pageSize = 10)
|
||||
//{
|
||||
// int totalNumber = 0;
|
||||
// var list = Context.Queryable<T>().Where(expression).ToPageList(pageIndex, pageSize, ref totalNumber);
|
||||
// return (list, totalNumber);
|
||||
//}
|
||||
public (List<T>, int) QueryableToPage(Expression<Func<T, bool>> expression, int pageIndex = 0, int pageSize = 10)
|
||||
{
|
||||
int totalNumber = 0;
|
||||
var list = Context.Queryable<T>().Where(expression).ToPageList(pageIndex, pageSize, ref totalNumber);
|
||||
return (list, totalNumber);
|
||||
}
|
||||
|
||||
//public (List<T>, int) QueryableToPage(Expression<Func<T, bool>> expression, string order, int pageIndex = 0, int pageSize = 10)
|
||||
//{
|
||||
// int totalNumber = 0;
|
||||
// var list = Context.Queryable<T>().Where(expression).OrderBy(order).ToPageList(pageIndex, pageSize, ref totalNumber);
|
||||
// return (list, totalNumber);
|
||||
//}
|
||||
public (List<T>, int) QueryableToPage(Expression<Func<T, bool>> expression, string order, int pageIndex = 0, int pageSize = 10)
|
||||
{
|
||||
int totalNumber = 0;
|
||||
var list = Context.Queryable<T>().Where(expression).OrderBy(order).ToPageList(pageIndex, pageSize, ref totalNumber);
|
||||
return (list, totalNumber);
|
||||
}
|
||||
|
||||
//public (List<T>, int) QueryableToPage(Expression<Func<T, bool>> expression, Expression<Func<T, object>> orderFiled, string orderBy, int pageIndex = 0, int pageSize = 10)
|
||||
//{
|
||||
// int totalNumber = 0;
|
||||
public (List<T>, int) QueryableToPage(Expression<Func<T, bool>> expression, Expression<Func<T, object>> orderFiled, string orderBy, int pageIndex = 0, int pageSize = 10)
|
||||
{
|
||||
int totalNumber = 0;
|
||||
|
||||
// if (orderBy.Equals("DESC", StringComparison.OrdinalIgnoreCase))
|
||||
// {
|
||||
// var list = Context.Queryable<T>().Where(expression).OrderBy(orderFiled, OrderByType.Desc).ToPageList(pageIndex, pageSize, ref totalNumber);
|
||||
// return (list, totalNumber);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// var list = Context.Queryable<T>().Where(expression).OrderBy(orderFiled, OrderByType.Asc).ToPageList(pageIndex, pageSize, ref totalNumber);
|
||||
// return (list, totalNumber);
|
||||
// }
|
||||
//}
|
||||
if (orderBy.Equals("DESC", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
var list = Context.Queryable<T>().Where(expression).OrderBy(orderFiled, OrderByType.Desc).ToPageList(pageIndex, pageSize, ref totalNumber);
|
||||
return (list, totalNumber);
|
||||
}
|
||||
else
|
||||
{
|
||||
var list = Context.Queryable<T>().Where(expression).OrderBy(orderFiled, OrderByType.Asc).ToPageList(pageIndex, pageSize, ref totalNumber);
|
||||
return (list, totalNumber);
|
||||
}
|
||||
}
|
||||
|
||||
//public List<T> SqlQueryToList(string sql, object obj = null)
|
||||
//{
|
||||
// return Context.Ado.SqlQuery<T>(sql, obj);
|
||||
//}
|
||||
public List<T> SqlQueryToList(string sql, object obj = null)
|
||||
{
|
||||
return Context.Ado.SqlQuery<T>(sql, obj);
|
||||
}
|
||||
/// <summary>
|
||||
/// 获得一条数据
|
||||
/// </summary>
|
||||
@ -347,9 +329,9 @@ namespace ZR.Repository
|
||||
return source.ToPage(parm);
|
||||
}
|
||||
|
||||
public PagedInfo<T> GetPages(Expression<Func<T, bool>> where, PagerInfo parm, Expression<Func<T, object>> order, string orderEnum = "Asc")
|
||||
public PagedInfo<T> GetPages(Expression<Func<T, bool>> where, PagerInfo parm, Expression<Func<T, object>> order, OrderByType orderEnum = OrderByType.Asc)
|
||||
{
|
||||
var source = Context.Queryable<T>().Where(where).OrderByIF(orderEnum == "Asc", order, OrderByType.Asc).OrderByIF(orderEnum == "Desc", order, OrderByType.Desc);
|
||||
var source = Context.Queryable<T>().Where(where).OrderByIF(orderEnum == OrderByType.Asc, order, OrderByType.Asc).OrderByIF(orderEnum == OrderByType.Desc, order, OrderByType.Desc);
|
||||
|
||||
return source.ToPage(parm);
|
||||
}
|
||||
@ -395,11 +377,6 @@ namespace ZR.Repository
|
||||
var result = (Context.Ado.UseStoredProcedure().GetDataTable(procedureName, parameters), parameters);
|
||||
return result;
|
||||
}
|
||||
|
||||
//public string QueryableToJson(string select, Expression<Func<T, bool>> expressionWhere)
|
||||
//{
|
||||
// throw new NotImplementedException();
|
||||
//}
|
||||
}
|
||||
|
||||
public static class QueryableExtension
|
||||
@ -414,13 +391,13 @@ namespace ZR.Repository
|
||||
public static PagedInfo<T> ToPage<T>(this ISugarQueryable<T> source, PagerInfo parm)
|
||||
{
|
||||
var page = new PagedInfo<T>();
|
||||
var total = source.Count();
|
||||
page.TotalCount = total;
|
||||
var total = 0;
|
||||
page.PageSize = parm.PageSize;
|
||||
page.PageIndex = parm.PageNum;
|
||||
|
||||
//page.DataSource = source.OrderByIF(!string.IsNullOrEmpty(parm.Sort), $"{parm.OrderBy} {(parm.Sort == "descending" ? "desc" : "asc")}").ToPageList(parm.PageNum, parm.PageSize);
|
||||
page.Result = source.ToPageList(parm.PageNum, parm.PageSize);
|
||||
page.Result = source.OrderByIF(!string.IsNullOrEmpty(parm.Sort), $"{parm.OrderBy} {(parm.Sort == "desc" ? "desc" : "asc")}")
|
||||
.ToPageList(parm.PageNum, parm.PageSize, ref total);
|
||||
page.TotalNum = total;
|
||||
return page;
|
||||
}
|
||||
|
||||
|
||||
@ -15,19 +15,12 @@ namespace ZR.Repository
|
||||
public interface IBaseRepository<T> where T : class, new()
|
||||
{
|
||||
#region add
|
||||
int Add(T parm, Expression<Func<T, object>> iClumns = null, bool ignoreNull = true);
|
||||
int Add(T t);
|
||||
|
||||
//int InsertIgnoreNullColumn(T t);
|
||||
|
||||
//int InsertIgnoreNullColumn(T t, params string[] columns);
|
||||
|
||||
//int Insert(SqlSugarClient client, T t);
|
||||
|
||||
//long InsertBigIdentity(T t);
|
||||
|
||||
int Insert(List<T> t);
|
||||
//int Insert(T parm, Expression<Func<T, object>> iClumns = null, bool ignoreNull = true);
|
||||
int Insert(T parm, Expression<Func<T, object>> iClumns = null, bool ignoreNull = true);
|
||||
|
||||
//int InsertIgnoreNullColumn(List<T> t);
|
||||
|
||||
@ -46,14 +39,12 @@ namespace ZR.Repository
|
||||
//bool ExecuteCommand(string sql, params SugarParameter[] parameters);
|
||||
|
||||
//bool ExecuteCommand(string sql, List<SugarParameter> parameters);
|
||||
|
||||
IInsertable<T> Insertable(T t);
|
||||
#endregion add
|
||||
|
||||
#region update
|
||||
|
||||
//bool UpdateEntity(T entity, bool ignoreNullColumns = false);
|
||||
|
||||
//bool Update(T entity, Expression<Func<T, bool>> expression);
|
||||
bool Update(T entity, bool ignoreNullColumns = false);
|
||||
|
||||
/// <summary>
|
||||
/// 只更新表达式的值
|
||||
@ -61,22 +52,12 @@ namespace ZR.Repository
|
||||
/// <param name="entity"></param>
|
||||
/// <param name="expression"></param>
|
||||
/// <returns></returns>
|
||||
//bool Update(T entity, Expression<Func<T, object>> expression, bool ignoreAllNull = false);
|
||||
bool Update(T entity, Expression<Func<T, object>> expression, bool ignoreAllNull = false);
|
||||
|
||||
//bool Update(T entity, Expression<Func<T, object>> expression, Expression<Func<T, bool>> where);
|
||||
bool Update(T entity, Expression<Func<T, object>> expression, Expression<Func<T, bool>> where);
|
||||
|
||||
//bool Update(SqlSugarClient client, T entity, Expression<Func<T, object>> expression, Expression<Func<T, bool>> where);
|
||||
bool Update(SqlSugarClient client, T entity, Expression<Func<T, object>> expression, Expression<Func<T, bool>> where);
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="entity">T</param>
|
||||
/// <param name="list">忽略更新</param>
|
||||
/// <param name="isNull">Null不更新</param>
|
||||
/// <returns></returns>
|
||||
bool Update(T entity, List<string> list = null, bool isNull = true);
|
||||
|
||||
//bool Update(List<T> entity);
|
||||
bool Update(Expression<Func<T, bool>> where, Expression<Func<T, T>> columns);
|
||||
|
||||
#endregion update
|
||||
@ -105,7 +86,7 @@ namespace ZR.Repository
|
||||
/// <returns></returns>
|
||||
PagedInfo<T> GetPages(Expression<Func<T, bool>> where, PagerInfo parm);
|
||||
|
||||
PagedInfo<T> GetPages(Expression<Func<T, bool>> where, PagerInfo parm, Expression<Func<T, object>> order, string orderEnum = "Asc");
|
||||
PagedInfo<T> GetPages(Expression<Func<T, bool>> where, PagerInfo parm, Expression<Func<T, object>> order, OrderByType orderEnum = OrderByType.Asc);
|
||||
|
||||
bool Any(Expression<Func<T, bool>> expression);
|
||||
|
||||
@ -124,15 +105,13 @@ namespace ZR.Repository
|
||||
|
||||
//List<T> QueryableToList(string tableName);
|
||||
|
||||
//(List<T>, int) QueryableToPage(Expression<Func<T, bool>> expression, int pageIndex = 0, int pageSize = 10);
|
||||
(List<T>, int) QueryableToPage(Expression<Func<T, bool>> expression, int pageIndex = 0, int pageSize = 10);
|
||||
|
||||
//(List<T>, int) QueryableToPage(Expression<Func<T, bool>> expression, string order, int pageIndex = 0, int pageSize = 10);
|
||||
(List<T>, int) QueryableToPage(Expression<Func<T, bool>> expression, string order, int pageIndex = 0, int pageSize = 10);
|
||||
|
||||
//(List<T>, int) QueryableToPage(Expression<Func<T, bool>> expression, Expression<Func<T, object>> orderFiled, string orderBy, int pageIndex = 0, int pageSize = 10);
|
||||
(List<T>, int) QueryableToPage(Expression<Func<T, bool>> expression, Expression<Func<T, object>> orderFiled, string orderBy, int pageIndex = 0, int pageSize = 10);
|
||||
|
||||
//(List<T>, int) QueryableToPage(Expression<Func<T, bool>> expression, Bootstrap.BootstrapParams bootstrap);
|
||||
|
||||
//List<T> SqlQueryToList(string sql, object obj = null);
|
||||
List<T> SqlQueryToList(string sql, object obj = null);
|
||||
/// <summary>
|
||||
/// 获得一条数据
|
||||
/// </summary>
|
||||
|
||||
@ -1,20 +0,0 @@
|
||||
using System;
|
||||
using Infrastructure.Attribute;
|
||||
using ZR.Repository.System;
|
||||
using ZR.Model.Models;
|
||||
|
||||
namespace ZR.Repository
|
||||
{
|
||||
/// <summary>
|
||||
/// 代码生成演示仓储接口的实现
|
||||
///
|
||||
/// @author zr
|
||||
/// @date 2021-11-24
|
||||
/// </summary>
|
||||
[AppService(ServiceLifetime = LifeTime.Transient)]
|
||||
public class GendemoRepository : BaseRepository<Gendemo>
|
||||
{
|
||||
#region 业务逻辑代码
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@ -13,7 +13,16 @@ namespace ZR.Repository.System
|
||||
/// 文章管理
|
||||
/// </summary>
|
||||
[AppService(ServiceLifetime = LifeTime.Transient)]
|
||||
public class ArticleRepository
|
||||
public class ArticleRepository : BaseRepository<Article>
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 文章目录
|
||||
/// </summary>
|
||||
[AppService(ServiceLifetime = LifeTime.Transient)]
|
||||
public class ArticleCategoryRepository : BaseRepository<ArticleCategory>
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
using Infrastructure.Attribute;
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
@ -1,7 +1,5 @@
|
||||
using System;
|
||||
using Infrastructure.Attribute;
|
||||
using ZR.Repository.System;
|
||||
using ZR.Model.Models;
|
||||
using ZR.Model.System;
|
||||
|
||||
namespace ZR.Repository
|
||||
|
||||
@ -1,6 +1,9 @@
|
||||
using Infrastructure.Attribute;
|
||||
using Infrastructure.Model;
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using ZR.Model;
|
||||
using ZR.Model.System;
|
||||
|
||||
namespace ZR.Repository.System
|
||||
@ -15,14 +18,15 @@ namespace ZR.Repository.System
|
||||
/// 字典类型数据搜索
|
||||
/// </summary>
|
||||
/// <param name="dictData"></param>
|
||||
/// <param name="pagerInfo"></param>
|
||||
/// <returns></returns>
|
||||
public List<SysDictData> SelectDictDataList(SysDictData dictData)
|
||||
public PagedInfo<SysDictData> SelectDictDataList(SysDictData dictData, PagerInfo pagerInfo)
|
||||
{
|
||||
return Context.Queryable<SysDictData>()
|
||||
.WhereIF(!string.IsNullOrEmpty(dictData.DictLabel), it => it.DictLabel.Contains(dictData.DictLabel))
|
||||
.WhereIF(!string.IsNullOrEmpty(dictData.Status), it => it.Status == dictData.Status)
|
||||
.WhereIF(!string.IsNullOrEmpty(dictData.DictType), it => it.DictType == dictData.DictType)
|
||||
.ToList();
|
||||
var exp = Expressionable.Create<SysDictData>();
|
||||
exp.AndIF(!string.IsNullOrEmpty(dictData.DictLabel), it => it.DictLabel.Contains(dictData.DictLabel));
|
||||
exp.AndIF(!string.IsNullOrEmpty(dictData.Status), it => it.Status == dictData.Status);
|
||||
exp.AndIF(!string.IsNullOrEmpty(dictData.DictType), it => it.DictType == dictData.DictType);
|
||||
return GetPages(exp.ToExpression(), pagerInfo);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
using Infrastructure.Attribute;
|
||||
using System;
|
||||
using SqlSugar;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using ZR.Model;
|
||||
using ZR.Model.System;
|
||||
|
||||
namespace ZR.Repository.System
|
||||
@ -22,17 +22,14 @@ namespace ZR.Repository.System
|
||||
/// </summary>
|
||||
/// <param name="dictType">实体模型</param>
|
||||
/// <returns></returns>
|
||||
public List<SysDictType> SelectDictTypeList(SysDictType dictType, Model.PagerInfo pager)
|
||||
public PagedInfo<SysDictType> SelectDictTypeList(SysDictType dictType, Model.PagerInfo pager)
|
||||
{
|
||||
var totalNum = 0;
|
||||
var list = Context
|
||||
.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)
|
||||
.ToPageList(pager.PageNum, pager.PageSize, ref totalNum);
|
||||
pager.TotalNum = totalNum;
|
||||
return list;
|
||||
var exp = Expressionable.Create<SysDictType>();
|
||||
exp.AndIF(!string.IsNullOrEmpty(dictType.DictName), it => it.DictName.Contains(dictType.DictName));
|
||||
exp.AndIF(!string.IsNullOrEmpty(dictType.Status), it => it.Status == dictType.Status);
|
||||
exp.AndIF(!string.IsNullOrEmpty(dictType.DictType), it => it.DictType == dictType.DictType);
|
||||
|
||||
return GetPages(exp.ToExpression(), pager);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@ -4,6 +4,8 @@ using System.Collections.Generic;
|
||||
using ZR.Model;
|
||||
using ZR.Model.System.Dto;
|
||||
using ZR.Model.System;
|
||||
using SqlSugar;
|
||||
using Infrastructure.Model;
|
||||
|
||||
namespace ZR.Repository.System
|
||||
{
|
||||
@ -16,19 +18,16 @@ namespace ZR.Repository.System
|
||||
/// <param name="sysOper"></param>
|
||||
/// <param name="pagerInfo">分页数据</param>
|
||||
/// <returns></returns>
|
||||
public List<SysOperLog> GetSysOperLog(SysOperLogDto sysOper, PagerInfo pagerInfo)
|
||||
public PagedInfo<SysOperLog> GetSysOperLog(SysOperLogDto sysOper, PagerInfo pagerInfo)
|
||||
{
|
||||
int totalCount = 0;
|
||||
var list = Context.Queryable<SysOperLog>()
|
||||
.Where(it => it.operTime >= sysOper.BeginTime && it.operTime <= sysOper.EndTime)
|
||||
.WhereIF(sysOper.Title.IfNotEmpty(), it => it.title.Contains(sysOper.Title))
|
||||
.WhereIF(sysOper.operName.IfNotEmpty(), it => it.operName.Contains(sysOper.operName))
|
||||
.WhereIF(sysOper.BusinessType != -1, it =>it.businessType == sysOper.BusinessType)
|
||||
.WhereIF(sysOper.Status != -1, it => it.status == sysOper.Status)
|
||||
.OrderBy(it => it.OperId, SqlSugar.OrderByType.Desc)
|
||||
.ToPageList(pagerInfo.PageNum, pagerInfo.PageSize, ref totalCount);
|
||||
pagerInfo.TotalNum = totalCount;
|
||||
return list;
|
||||
var exp = Expressionable.Create<SysOperLog>();
|
||||
exp.And(it => it.operTime >= sysOper.BeginTime && it.operTime <= sysOper.EndTime);
|
||||
exp.AndIF(sysOper.Title.IfNotEmpty(), it => it.title.Contains(sysOper.Title));
|
||||
exp.AndIF(sysOper.operName.IfNotEmpty(), it => it.operName.Contains(sysOper.operName));
|
||||
exp.AndIF(sysOper.BusinessType != -1, it => it.businessType == sysOper.BusinessType);
|
||||
exp.AndIF(sysOper.Status != -1, it => it.status == sysOper.Status);
|
||||
|
||||
return GetPages(exp.ToExpression(), pagerInfo, x => x.OperId, OrderByType.Desc);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
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