35 Commits
Author SHA1 Message Date
wenyongda 7d4d113e60 Revert "升级.net 9"
This reverts commit b25e6dc736.
2025-04-12 09:31:53 +08:00
wenyongda b25e6dc736 升级.net 9 2025-03-17 16:46:02 +08:00
wenyongda 096f8485b4 完善邮箱登录,日志完善,操作日志中增加详细报错堆栈信息 2024-01-26 08:17:04 +08:00
wenyongda 0d077bea34 去除BloomFilter 2023-12-14 14:55:08 +08:00
wenyongda 8568e7c406 完善nlog日志打印到控制台 2023-12-07 16:13:21 +08:00
wenyongda 8ce45c0de5 优化nlog sql备份文件名格式,ZR.Model引用Infrastructure 2023-11-23 16:17:19 +08:00
wenyongda bebcf559a1 文件上传加密及增加根据配置文件存储类型自动选择上传方式 2023-11-22 10:29:07 +08:00
wenyongda 43c9d3564b 完善Dockerfile,更改数据库配置文件,日志记录增加Id主键 2023-11-10 16:35:37 +08:00
wenyongda b7ebad03d0 Dockerfile添加容器运行命令解决Exception has been thrown by the target of an invocation. 2023-10-27 16:36:48 +08:00
wenyongda a4f03cfbc1 修改提交Dockerfile 2023-10-27 12:57:47 +08:00
wenyongda 67992af570 新增删除修改通知后,会向当前登录的用户组发送通知,修改通知后,如果该通知之前被用户已读过,则将其重新置于未读状态 2023-10-20 17:12:58 +08:00
wenyongda 99d2ebcbe8 解决文件本地上传报错问题,速率限制独立配置文件,解决通知公告修改删除报错,nlog增加速率限制日志文件写入,增加业务单号模块,生成业务单号工具类,IIS部署用web.config 2023-10-19 16:28:09 +08:00
wenyongda 5174fc9ec0 增加业务model基类 2023-10-18 23:17:17 +08:00
wenyongda e49d007908 注释grpc demo 2023-10-17 14:01:22 +08:00
wenyongda 10b57594ac 调整字段初始化和获取Model列表,备份sql 2023-10-16 17:00:45 +08:00
wenyongda 52cd22c4c6 集成gRPC模块 2023-10-13 16:56:33 +08:00
wenyongda 28c53b71ce 修复SqlSugarSetup类名修改后,nlog不打印日志问题,日期时间转换类增加格式,暂存区块和字段关联 2023-10-11 16:58:48 +08:00
wenyongda e6dae7d1e2 集成BloomFilter.CSRedis.NetCore,并结合进SqlSugar二级缓存中,缓解缓存穿透攻击 2023-10-11 00:03:45 +08:00
wenyongda e7fe909fd0 重写SqlSugar二级缓存模糊删除缓存方法覆盖ICacheService实现类SqlSugarCache中的GetAllKey和Remove方法解决是否含有key前缀不一致问题,ipratelimit接入分布式缓存 2023-10-08 16:36:32 +08:00
wenyongda c592925096 暂存字段权限更改 2023-09-28 16:26:03 +08:00
wenyongda 38eda262d6 速率限制可根据ip查看对应日志 2023-09-28 16:25:28 +08:00
wenyongda 1c08c837e6 完善系统通知,增加系统通知日志记录已读和未读通知 2023-09-28 14:49:16 +08:00
wenyongda b932f6f6a0 增加字段dto数据传输对象,对该角色没有关联的属性是否授权赋值为null 2023-09-27 00:04:37 +08:00
wenyongda 764a77456e 新增数据字段拦截器,json序列化解析器 2023-09-26 17:07:40 +08:00
wenyongda 4199736bc7 ServiceCore下Model命名空间转换 2023-09-25 16:47:37 +08:00
wenyongda cacb525b3a 登录claim增加昵称,signalr去除不必要的消息 2023-09-25 10:38:11 +08:00
wenyongda ee9f6bacf3 新增速率限制,调整本地文件上传,服务监控IP取本机网络IP,仓储增加方法 2023-09-22 15:46:43 +08:00
wenyongda d3556cc058 集成CSRedis分布式存储,调整创建者和更新者字段,登录RSA使用配置文件配置私钥 2023-09-22 01:09:47 +08:00
wenyongda de76f5872a Merge remote-tracking branch 'zrorigin/master' into net7.0
# Conflicts:
#	ZR.Admin.WebApi/Controllers/System/SysLoginController.cs
2023-09-21 22:23:08 +08:00
wenyongda dc705768fe 修改为自己阿里云服务器数据库及阿里云对象存储 2023-07-17 10:05:02 +08:00
wenyongda cead939fe4 Merge branch 'net7.0' of https://gitee.com/wenyongda/ZrAdminNetCore into net7.0
# Conflicts:
#	ZR.Admin.WebApi/appsettings.json
2023-07-17 09:59:48 +08:00
wenyongda 586f4c36a6 修改为服务器数据库 2023-07-17 09:55:56 +08:00
wenyongda 301d27e5ef 前端Vue2引入jsrsasign进行RSA加密,登录Action增加RSA密码加密 2023-06-17 22:24:59 +08:00
不做码农 36de53cbcc Merge commit 'refs/pull/35/head' of https://gitee.com/izory/ZrAdminNetCore into net7.0 2023-06-17 16:05:49 +08:00
wenyongda f767752aa4 登录增加获取RSA密钥接口,登录接口增加密码解密 2023-06-12 09:42:22 +08:00
321 changed files with 8286 additions and 3160 deletions
+25
View File
@@ -0,0 +1,25 @@
**/.dockerignore
**/.env
**/.git
**/.gitignore
**/.project
**/.settings
**/.toolstarget
**/.vs
**/.vscode
**/.idea
**/*.*proj.user
**/*.dbmdl
**/*.jfm
**/azds.yaml
**/bin
**/charts
**/docker-compose*
**/Dockerfile*
**/node_modules
**/npm-debug.log
**/obj
**/secrets.dev.yaml
**/values.dev.yaml
LICENSE
README.md
-88
View File
@@ -1,88 +0,0 @@
name: 问题反馈
description: 当你在代码中发现了一个 Bug,导致应用崩溃或抛出异常,或者有一个组件存在问题,或者某些地方看起来不对劲。
title: "[Bug]: "
labels: ["bug"]
body:
- type: markdown
attributes:
value: |
感谢对项目的支持与关注。在提出问题之前,请确保你已查看相关开发或使用文档:
- http://www.izhaorui.cn/doc
- type: checkboxes
attributes:
label: 这个问题是否已经存在?
options:
- label: 我已经搜索过现有的问题 (https://gitee.com/../../issues)
required: true
- type: checkboxes
attributes:
label: 代码是否是最新获取的?
options:
- label: 我已经确认代码是最新主分支的代码
required: true
- type: textarea
attributes:
label: 如何复现
description: 请详细告诉我们如何复现你遇到的问题,如涉及代码,可提供一个最小代码示例,并使用反引号```附上它
placeholder: |
1. ...
2. ...
3. ...
validations:
required: true
- type: textarea
attributes:
label: 预期结果
description: 请告诉我们你预期会发生什么。
validations:
required: false
- type: textarea
attributes:
label: 实际结果
description: 请告诉我们实际发生了什么。
validations:
required: false
- type: textarea
attributes:
label: 截图或视频
description: 如果可以的话,上传任何关于 bug 的截图。
value: |
[在这里上传图片]
- type: dropdown
id: version
attributes:
label: vue版本
description: 你当前正在使用我们软件的哪个前端版本
options:
- vue3 (默认)
- vue2
validations:
required: true
- type: dropdown
id: version
attributes:
label: 运行环境
options:
- 开发环境 (development)
- 生产环境(production)
validations:
required: true
- type: dropdown
id: version
attributes:
label: 应用程序托管
options:
- 前端iis + 后端iis
- 前端nginx + 后端 iis
- 前端nginx + 后端自启动
- docker
- 其他
validations:
required: true
contact_links:
- name: 使用文档
url: http://www.izhaorui.cn/doc/
about: 官方文档
- name: ♥️ VIP 服务 ♥️
url: https://www.izhaorui.cn/doc/support.html
about: 支持作者
-13
View File
@@ -1,13 +0,0 @@
name: 功能建议
description: 对本项目提出一个功能建议
title: "[功能建议]: "
labels: ["enhancement"]
body:
- type: markdown
attributes:
value: |
感谢对项目的支持与关注。如果你在使用中有什么好的建议欢迎提出来
- type: textarea
attributes:
label: 请输入内容
description: 如果可以的话,上传任何关于 功能 的截图。
+2 -1
View File
@@ -1,7 +1,7 @@
using CSRedis;
using Infrastructure;
namespace ZR.Common.Cache
namespace ZR.Infrastructure.Cache
{
public class RedisServer
{
@@ -12,6 +12,7 @@ namespace ZR.Common.Cache
{
Cache = new CSRedisClient(AppSettings.GetConfig("RedisServer:Cache"));
Session = new CSRedisClient(AppSettings.GetConfig("RedisServer:Session"));
RedisHelper.Initialization(Session);
}
}
}
@@ -0,0 +1,8 @@
namespace ZR.Infrastructure.Constant;
public class SysNoticeLogStatus
{
public const string Unread = "0";
public const string Read = "1";
}
@@ -8,7 +8,6 @@ using Newtonsoft.Json.Serialization;
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
using System.Web;
namespace Infrastructure.Controllers
@@ -16,7 +15,6 @@ namespace Infrastructure.Controllers
/// <summary>
/// web层通用数据处理
/// </summary>
//[ApiController]
public class BaseController : ControllerBase
{
public static string TIME_FORMAT_FULL = "yyyy-MM-dd HH:mm:ss";
@@ -76,23 +74,6 @@ namespace Infrastructure.Controllers
return File(stream, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", HttpUtility.UrlEncode(fileName));
}
/// <summary>
/// 下载文件
/// </summary>
/// <param name="path"></param>
/// <param name="fileName">文件名,一定要带扩展名</param>
/// <returns></returns>
protected IActionResult DownFile(string path, string fileName)
{
if (!System.IO.File.Exists(path))
{
return NotFound();
}
var stream = System.IO.File.OpenRead(path); //创建文件流
Response.Headers.Add("Access-Control-Expose-Headers", "Content-Disposition");
return File(stream, "application/octet-stream", HttpUtility.UrlEncode(fileName));
}
#region 方法
/// <summary>
@@ -170,7 +170,7 @@ namespace Infrastructure.Extensions
{
try
{
return bool.Parse(str.ToString());
return bool.Parse(str.ToString() ?? string.Empty);
}
catch
{
@@ -284,6 +284,9 @@ namespace Infrastructure.Extensions
return DateTime.ParseExact(str, "yyyyMMddHH", System.Globalization.CultureInfo.CurrentCulture);
case 12:
return DateTime.ParseExact(str, "yyyyMMddHHmm", System.Globalization.CultureInfo.CurrentCulture);
case 13:
return DateTime.ParseExact(str, "yyyy.MM.dd ddd",
System.Globalization.CultureInfo.CurrentCulture);
case 14:
return DateTime.ParseExact(str, "yyyyMMddHHmmss", System.Globalization.CultureInfo.CurrentCulture);
default:
+5
View File
@@ -5,6 +5,11 @@
/// </summary>
public class GlobalConstant
{
/// <summary>
/// 代码生成常量
/// </summary>
public static readonly string CodeGenDbConfig;
/// <summary>
/// 管理员权限
/// </summary>
+12 -2
View File
@@ -144,7 +144,7 @@ namespace Infrastructure
/// 写文件
/// </summary>
/// <param name="path">完整路径带扩展名的</param>
/// <param name="content">写入文件内容</param>
/// <param name="content"></param>
public static void WriteAndSave(string path, string content)
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
@@ -158,7 +158,17 @@ namespace Infrastructure
Console.WriteLine("开始写入文件,Path=" + path);
try
{
File.WriteAllText(path, content);
//实例化一个文件流--->与写入文件相关联
using var fs = new FileStream(path, FileMode.Create, FileAccess.Write);
//实例化一个StreamWriter-->与fs相关联
using var sw = new StreamWriter(fs);
//开始写入
sw.Write(content);
//清空缓冲区
sw.Flush();
//关闭流
sw.Close();
fs.Close();
}
catch (Exception ex)
{
-25
View File
@@ -1,25 +0,0 @@
using System;
using System.Text;
namespace ZR.Infrastructure.Helper
{
public class RandomHelper
{
/// <summary>
/// 生成n为验证码
/// </summary>
/// <param name="Length"></param>
/// <returns></returns>
public static string GenerateNum(int Length)
{
char[] constant = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' };
StringBuilder newRandom = new(constant.Length);
Random rd = new();
for (int i = 0; i < Length; i++)
{
newRandom.Append(constant[rd.Next(constant.Length - 1)]);
}
return newRandom.ToString();
}
}
}
+4 -5
View File
@@ -155,11 +155,10 @@ namespace Infrastructure
{
var claims = new List<Claim>()
{
new(ClaimTypes.PrimarySid, user.UserId.ToString()),
new(ClaimTypes.NameIdentifier, user.UserId.ToString()),
new(ClaimTypes.Name, user.UserName),
new(ClaimTypes.GroupSid, user.DeptId.ToString()),
new(ClaimTypes.UserData, JsonConvert.SerializeObject(user))
new Claim(ClaimTypes.PrimarySid, user.UserId.ToString()),
new Claim(ClaimTypes.Name, user.UserName),
new Claim(ClaimTypes.UserData, JsonConvert.SerializeObject(user)),
new Claim("NickName", user.NickName)
};
return claims;
+16 -10
View File
@@ -1,24 +1,26 @@
using Infrastructure.Constant;
using Newtonsoft.Json;
using System.Collections.Generic;
namespace Infrastructure.Model
{
public class ApiResult : Dictionary<string, object>
{
/// <summary>
/// 状态码
/// </summary>
/** 状态码 */
public static readonly string CODE_TAG = "code";
/// <summary>
/// 返回内容
/// </summary>
/** 返回内容 */
public static readonly string MSG_TAG = "msg";
/// <summary>
/// 数据对象
/// </summary>
/** 数据对象 */
public static readonly string DATA_TAG = "data";
//public int Code { get; set; }
//public string Msg { get; set; }
/// <summary>
/// 如果data值为null,则忽略序列化将不会返回data字段
/// </summary>
//[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
//public object Data { get; set; }
/// <summary>
/// 初始化一个新创建的APIResult对象,使其表示一个空消息
@@ -53,7 +55,6 @@ namespace Infrastructure.Model
Add(DATA_TAG, data);
}
}
/// <summary>
/// 返回成功消息
/// </summary>
@@ -124,4 +125,9 @@ namespace Infrastructure.Model
return this;
}
}
public class ApiResult<T> : ApiResult
{
public T Result { get; set; }
}
}
+3 -5
View File
@@ -23,7 +23,7 @@ namespace Infrastructure.Model
public Upload Upload { get; set; }
public ALIYUN_OSS ALIYUN_OSS { get; set; }
public JwtSettings JwtSettings { get; set; }
public CodeGen CodeGen { get; set; }
public Gen Gen { get; set; }
public List<DbConfigs> DbConfigs { get; set; }
public DbConfigs CodeGenDbConfig { get; set; }
}
@@ -94,15 +94,13 @@ namespace Infrastructure.Model
public string TokenType { get; set; } = "Bearer";
}
public class CodeGen
public class Gen
{
public bool ShowApp { get; set; }
public bool AutoPre { get; set; }
public string VuePath { get; set; }
public string Author { get; set; }
public string TablePrefix { get; set; }
public string ModuleName { get; set; }
public int FrontTpl { get; set; }
public DbConfigs GenDbConfig { get; set; }
public CsharpTypeArr CsharpTypeArr { get; set; }
}
+2 -6
View File
@@ -12,9 +12,9 @@ namespace Infrastructure.Model
/// <summary>
/// 主题
/// </summary>
[Required(ErrorMessage = "主题不能为空")]
// [Required(ErrorMessage = "主题不能为空")]
public string Subject { get; set; }
[Required(ErrorMessage = "发送人不能为空")]
// [Required(ErrorMessage = "发送人不能为空")]
public string ToUser { get; set; }
public string Content { get; set; } = "";
public string HtmlContent { get; set; }
@@ -23,9 +23,5 @@ namespace Infrastructure.Model
/// </summary>
public bool SendMe { get; set; }
public DateTime AddTime { get; set; }
/// <summary>
/// 是否发送
/// </summary>
public bool IsSend { get; set; }
}
}
+2
View File
@@ -9,6 +9,7 @@ namespace Infrastructure.Model
public long UserId { get; set; }
public long DeptId { get; set; }
public string UserName { get; set; }
public string NickName { get; set; }
/// <summary>
/// 角色集合
/// </summary>
@@ -33,6 +34,7 @@ namespace Infrastructure.Model
{
UserId = info.UserId;
UserName = info.UserName;
NickName = info.NickName;
DeptId = info.DeptId;
Roles = roles;
RoleIds = roles.Select(f => f.RoleKey).ToList();
+59
View File
@@ -0,0 +1,59 @@
using System;
namespace ZR.Infrastructure.Resolver;
public static class AntPathMatcher
{
public static bool Match(string pattern, string value)
{
if (pattern == null || value == null)
return false;
if (pattern == "**")
return true;
var patternSegments = pattern.Split('/');
var valueSegments = value.Split('/');
int patternIndex = 0;
int valueIndex = 0;
int patternWildcardIndex = -1;
int valueWildcardIndex = -1;
while (valueIndex < valueSegments.Length)
{
if (patternIndex < patternSegments.Length && IsMatch(patternSegments[patternIndex], valueSegments[valueIndex]))
{
patternIndex++;
valueIndex++;
}
else if (patternWildcardIndex != -1)
{
patternIndex = patternWildcardIndex + 1;
valueIndex = ++valueWildcardIndex;
}
else
{
return false;
}
}
while (patternIndex < patternSegments.Length && patternSegments[patternIndex] == "**")
{
patternIndex++;
}
return patternIndex >= patternSegments.Length && valueIndex >= valueSegments.Length;
}
private static bool IsMatch(string patternSegment, string valueSegment)
{
if (patternSegment == "*")
return true;
if (patternSegment.StartsWith("{") && patternSegment.EndsWith("}"))
return true; // 支持占位符的匹配逻辑
return string.Equals(patternSegment, valueSegment, StringComparison.OrdinalIgnoreCase);
}
}
@@ -0,0 +1,42 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using Newtonsoft.Json.Serialization;
namespace ZR.Infrastructure.Resolver;
public class JsonPropertyContractResolver : CamelCasePropertyNamesContractResolver
{
private HashSet<string> _propertySet;
public JsonPropertyContractResolver(IEnumerable<string> propertyNames)
{
if (propertyNames != null)
{
_propertySet = new HashSet<string>(propertyNames, StringComparer.Ordinal);
}
}
// protected override IList<JsonProperty> CreateProperties(Type type, MemberSerialization memberSerialization)
// {
// var list = base.CreateProperties(type, memberSerialization).ToList();
// var resList = list
// .Where(a => !this._lstInclude.Contains(a.PropertyName))
// .ToList();
// return resList;
// // .FindAll(p => _lstInclude.Contains(p.PropertyName));
// }
protected override List<MemberInfo> GetSerializableMembers(Type objectType)
{
List<MemberInfo> serializableMembers = null;
var allMembers = base.GetSerializableMembers(objectType);
if (_propertySet != null && _propertySet.Count > 0)
{
serializableMembers = allMembers.Where(m => !_propertySet.Contains(m.Name)).ToList();
}
return serializableMembers != null && serializableMembers.Count > 0 ? serializableMembers : allMembers;
}
}
@@ -0,0 +1,44 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
namespace ZR.Infrastructure.Resolver;
public class PropertyFilterContractResolver : CamelCasePropertyNamesContractResolver
{
private readonly HashSet<string> _includedPaths;
private readonly HashSet<string> _excludedPaths;
public PropertyFilterContractResolver(IEnumerable<string> includedPaths, IEnumerable<string> excludedPaths)
{
_includedPaths = includedPaths.ToHashSet();
_excludedPaths = excludedPaths.ToHashSet();
}
protected override IList<JsonProperty> CreateProperties(Type type, MemberSerialization memberSerialization)
{
var properties = base.CreateProperties(type, memberSerialization);
properties = properties.Where(p => IsIncluded(p) && !IsExcluded(p)).ToList();
return properties;
}
private bool IsIncluded(JsonProperty property)
{
if (_includedPaths == null || _includedPaths.Count == 0)
return true;
return _includedPaths.Any(path => AntPathMatcher.Match(path, property.PropertyName));
}
private bool IsExcluded(JsonProperty property)
{
if (_excludedPaths == null || _excludedPaths.Count == 0)
return false;
return _excludedPaths.Any(path => AntPathMatcher.Match(path, property.PropertyName));
}
}
@@ -16,10 +16,11 @@ namespace Infrastructure
types.GetProperty("CreateTime", flag)?.SetValue(source, DateTime.Now, null);
types.GetProperty("AddTime", flag)?.SetValue(source, DateTime.Now, null);
types.GetProperty("CreateBy", flag)?.SetValue(source, context.GetName(), null);
types.GetProperty("Create_by", flag)?.SetValue(source, context.GetName(), null);
types.GetProperty("CreateBy", flag)?.SetValue(source, context.GetUId(), null);
types.GetProperty("CreateName", flag)?.SetValue(source, context.GetNickName(), null);
types.GetProperty("Create_by", flag)?.SetValue(source, context.GetUId(), null);
types.GetProperty("Create_name", flag)?.SetValue(source, context.GetNickName(), null);
types.GetProperty("UserId", flag)?.SetValue(source, context.GetUId(), null);
types.GetProperty("DeptId", flag)?.SetValue(source, context.GetDeptId(), null);
return source;
}
@@ -32,9 +33,10 @@ namespace Infrastructure
types.GetProperty("UpdateTime", flag)?.SetValue(source, DateTime.Now, null);
types.GetProperty("Update_time", flag)?.SetValue(source, DateTime.Now, null);
types.GetProperty("UpdateBy", flag)?.SetValue(source, context.GetName(), null);
types.GetProperty("Update_by", flag)?.SetValue(source, context.GetName(), null);
types.GetProperty("UpdateBy", flag)?.SetValue(source, context.GetUId(), null);
types.GetProperty("Update_by", flag)?.SetValue(source, context.GetUId(), null);
types.GetProperty("UpdateName", flag)?.SetValue(source, context.GetNickName(), null);
types.GetProperty("Update_name", flag)?.SetValue(source, context.GetNickName(), null);
return source;
}
@@ -80,17 +80,6 @@ namespace Infrastructure.Extensions
return !string.IsNullOrEmpty(uid) ? long.Parse(uid) : 0;
}
/// <summary>
/// 获取部门id
/// </summary>
/// <param name="context"></param>
/// <returns></returns>
public static long GetDeptId(this HttpContext context)
{
var deptId = context.User.FindFirstValue(ClaimTypes.GroupSid);
return !string.IsNullOrEmpty(deptId) ? long.Parse(deptId) : 0;
}
/// <summary>
/// 获取登录用户名
/// </summary>
@@ -103,6 +92,14 @@ namespace Infrastructure.Extensions
return uid;
}
public static string? GetNickName(this HttpContext context)
{
var nickName = context.User.FindFirstValue("NickName");
if (string.IsNullOrEmpty(nickName))
nickName = null;
return nickName;
}
/// <summary>
/// 判断是否是管理员
/// </summary>
@@ -17,8 +17,8 @@ namespace ZR.Infrastructure.WebExtensions
//从appsettings.json中加载Ip规则
services.Configure<IpRateLimitPolicies>(configuration.GetSection("IpRateLimitPolicies"));
//注入计数器和规则存储
services.AddSingleton<IIpPolicyStore, MemoryCacheIpPolicyStore>();
services.AddSingleton<IRateLimitCounterStore, MemoryCacheRateLimitCounterStore>();
services.AddSingleton<IIpPolicyStore, DistributedCacheIpPolicyStore>();
services.AddSingleton<IRateLimitCounterStore, DistributedCacheRateLimitCounterStore>();
//配置(解析器、计数器密钥生成器)
services.AddSingleton<IRateLimitConfiguration, RateLimitConfiguration>();
services.AddSingleton<IProcessingStrategy, AsyncKeyLockProcessingStrategy>();
@@ -1,35 +0,0 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http.Features;
using Microsoft.AspNetCore.Server.Kestrel.Core;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
namespace ZR.Infrastructure.WebExtensions
{
public static class RequestLimitExtension
{
/// <summary>
/// 请求body大小设置
/// </summary>
/// <param name="services"></param>
/// <param name="configuration"></param>
public static void AddRequestLimit(this IServiceCollection services, IConfiguration configuration)
{
var sizeM = configuration.GetSection("upload:requestLimitSize").Get<int>();
services.Configure<FormOptions>(x =>
{
x.MultipartBodyLengthLimit = sizeM * 1024 * 1024;
x.MemoryBufferThreshold = sizeM * 1024 * 1024;
x.ValueLengthLimit = int.MaxValue;
});
services.Configure<KestrelServerOptions>(options =>
{
options.Limits.MaxRequestBodySize = sizeM * 1024 * 1024;
});
services.Configure<IISServerOptions>(options =>
{
options.MaxRequestBodySize = sizeM * 1024 * 1024; // 设置最大请求体大小为500MB
});
}
}
}
+8 -3
View File
@@ -12,14 +12,19 @@
<ItemGroup>
<PackageReference Include="AspectCore.Abstractions" Version="2.4.0" />
<PackageReference Include="Caching.CSRedis" Version="3.8.670" />
<PackageReference Include="Microsoft.AspNetCore.SignalR.Client" Version="7.0.12" />
<PackageReference Include="Microsoft.Extensions.DependencyModel" Version="7.0.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="RulesEngine" Version="5.0.2" />
<PackageReference Include="SqlSugar.IOC" Version="2.0.0" />
<PackageReference Include="SqlSugarCoreNoDrive" Version="5.1.4.109" />
<PackageReference Include="UAParser" Version="3.1.47" />
<PackageReference Include="IPTools.China" Version="1.6.0" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="7.0.7" />
<PackageReference Include="JinianNet.JNTemplate" Version="2.4.2" />
<PackageReference Include="MiniExcel" Version="1.31.3" />
<PackageReference Include="CSRedisCore" Version="3.8.802" />
<PackageReference Include="JinianNet.JNTemplate" Version="2.3.3" />
<PackageReference Include="MiniExcel" Version="1.31.2" />
<PackageReference Include="CSRedisCore" Version="3.8.670" />
<PackageReference Include="AspNetCoreRateLimit" Version="5.0.0" />
</ItemGroup>
+8 -29
View File
@@ -1,17 +1,12 @@
<h2 align="center"> ZR.Admin.NET Back-end management system</h2>
<h4 align="center">base .Net7 + vue2.x/vue3.x/uniapp Front-end and back-end separation of .NET rapid development framework</h4>
<div style="text-align:center">
[![stars](https://gitee.com/izory/ZrAdminNetCore/badge/star.svg?theme=dark)](https://gitee.com/izory/ZrAdminNetCore)
[![fork](https://gitee.com//izory/ZrAdminNetCore/badge/fork.svg?theme=dark)](https://gitee.com/izory/ZrAdminNetCore/members)
[![Change log](https://img.shields.io/badge/ChangeLog-20240105-yellow)](http://www.izhaorui.cn/doc/changelog.html)
[![GitHub license](https://img.shields.io/github/license/izhaorui/ZrAdmin.NET)](https://github.com/izhaorui/ZrAdmin.NET/blob/main/LICENSE)
[![GitHub stars](https://img.shields.io/github/stars/izhaorui/ZrAdmin.NET?style=social)](https://github.com/izhaorui/ZrAdmin.NET/stargazers)
[![GitHub forks](https://img.shields.io/github/forks/izhaorui/ZrAdmin.NET?style=social)](https://github.com/izhaorui/ZrAdmin.NET/network)
</div>
<p align="center">
<a href="https://gitee.com/izory/ZrAdminNetCore"><img src="https://gitee.com/izory/ZrAdminNetCore/badge/star.svg?theme=dark"></a>
<a href='https://gitee.com/izory/ZrAdminNetCore/members'><img src='https://gitee.com/izory/ZrAdminNetCore/badge/fork.svg?theme=dark' alt='fork'></img></a>
<a href="https://gitee.com/izory/ZrAdminNetCore/blob/master/LICENSE"><img src="https://img.shields.io/github/license/mashape/apistatus.svg"></a>
<a href="http://www.izhaorui.cn/doc/changelog.html"><img src="https://img.shields.io/badge/更新日志-20230920-yellow"/></a>
</p>
---
@@ -32,10 +27,6 @@
If it helps you, you can click "Star" in the upper right corner to collect it, so that the author has the motivation to continue to go on for free, thank you! ~
```
## 📈 Quick start
- Quick start:[https://www.izhaorui.cn/doc/quickstart.html](https://www.izhaorui.cn/doc/quickstart.html)
## 🍿 Online experience
- Official documentation:http://www.izhaorui.cn/doc
@@ -56,7 +47,7 @@ Since it is a personal project, the funds are limited, and the experience server
## 💒 Code repository
| repository | Github | Gitee |
| ---------- | ----------------------------------------------------------- | -------------------------------------------------------- |
| -------------- | ------------------------------------------------------ | ---------------------------------------------------------------- |
| Net7 | [Clone/Download](https://github.com/izhaorui/Zr.Admin.NET) | [Clone/Download](https://gitee.com/izory/ZrAdminNetCore) |
| Vue3(Hot) | [Clone/Download](https://github.com/izhaorui/ZR.Admin.Vue3) | [Clone/Download](https://gitee.com/izory/ZRAdmin-vue) |
@@ -158,16 +149,9 @@ Vue Front-end technology stack: Based on Vue2.x/Vue3.x/UniApp, Vue, Vue-router,
<td><img src="https://gitee.com/izory/ZrAdminNetCore/raw/master/document/images/19.png"/></td>
<td><img src="https://gitee.com/izory/ZrAdminNetCore/raw/master/document/images/20.png"/></td>
</tr>
<tr>
<td><img src="https://gitee.com/izory/ZrAdminNetCore/raw/master/document/images/21.png"/></td>
<td><img src="https://gitee.com/izory/ZrAdminNetCore/raw/master/document/images/22.png"/></td>
</tr>
<tr>
<td><img src="https://gitee.com/izory/ZrAdminNetCore/raw/master/document/images/23.png"/></td>
</tr>
</table>
## 📱 Mobile Storyplate
## Mobile Storyplate
<table>
<tr>
@@ -188,10 +172,6 @@ Vue Front-end technology stack: Based on Vue2.x/Vue3.x/UniApp, Vue, Vue-router,
</tr>
<tr>
<td><img src="https://gitee.com/izory/ZrAdminNetCore/raw/master/document/images/a10.png"/></td>
<td><img src="https://gitee.com/izory/ZrAdminNetCore/raw/master/document/images/a11.png"/></td>
</tr>
<tr>
<td><img src="https://gitee.com/izory/ZrAdminNetCore/raw/master/document/images/a12.png"/></td>
</tr>
</table>
@@ -212,7 +192,6 @@ Vue Front-end technology stack: Based on Vue2.x/Vue3.x/UniApp, Vue, Vue-router,
- 👉SqlSugar:[SqlSugar](https://gitee.com/dotnetchina/SqlSugar)
- 👉vue-element-admin:[vue-element-admin](https://github.com/PanJiaChen/vue-element-admin)
- 👉Meiam.System:[Meiam.System](https://github.com/91270/Meiam.System)
- 👉Furion:[Furion](https://gitee.com/dotnetchina/Furion)
## 🎀 donation
+11 -37
View File
@@ -1,24 +1,12 @@
<h2 align="center"> ZR.Admin.NET后台管理系统</h2>
<h4 align="center">基于.Net7 + vue2.x/vue3.x/uniapp前后端分离的.net快速开发框架</h4>
<!-- <p align="center">
<p align="center">
<a href="https://gitee.com/izory/ZrAdminNetCore"><img src="https://gitee.com/izory/ZrAdminNetCore/badge/star.svg?theme=dark"></a>
<a href='https://gitee.com/izory/ZrAdminNetCore/members'><img src='https://gitee.com/izory/ZrAdminNetCore/badge/fork.svg?theme=dark' alt='fork'></img></a>
<a href="https://gitee.com/izory/ZrAdminNetCore/blob/master/LICENSE"><img src="https://img.shields.io/github/license/mashape/apistatus.svg"></a>
<a href="http://www.izhaorui.cn/doc/changelog.html"><img src="https://img.shields.io/badge/更新日志-20230920-yellow"/></a>
</p> -->
<div style="text-align:center">
[![stars](https://gitee.com/izory/ZrAdminNetCore/badge/star.svg?theme=dark)](https://gitee.com/izory/ZrAdminNetCore)
[![fork](https://gitee.com//izory/ZrAdminNetCore/badge/fork.svg?theme=dark)](https://gitee.com/izory/ZrAdminNetCore/members)
[![更新日志](https://img.shields.io/badge/更新日志-20240105-yellow)](http://www.izhaorui.cn/doc/changelog.html)
[![GitHub license](https://img.shields.io/github/license/izhaorui/ZrAdmin.NET)](https://github.com/izhaorui/ZrAdmin.NET/blob/main/LICENSE)
[![GitHub stars](https://img.shields.io/github/stars/izhaorui/ZrAdmin.NET?style=social)](https://github.com/izhaorui/ZrAdmin.NET/stargazers)
[![GitHub forks](https://img.shields.io/github/forks/izhaorui/ZrAdmin.NET?style=social)](https://github.com/izhaorui/ZrAdmin.NET/network)
</div>
</p>
---
@@ -43,17 +31,13 @@
如果对您有帮助,您可以点右上角 “Star” 收藏一下 ,谢谢!~
```
## 📈 快速开始
- 快速开始:[https://www.izhaorui.cn/doc/quickstart.html](https://www.izhaorui.cn/doc/quickstart.html)
## 🍿 在线体验
- 官方文档:http://www.izhaorui.cn/doc
- 加入群聊:[立即加入](http://www.izhaorui.cn/doc/contact.html)
- Vue3.x 版本体验:[http://demo.izhaorui.cn/vue3](http://demo.izhaorui.cn/vue3)
- Vue2.x 版本体验:[http://demo.izhaorui.cn/admin](http://demo.izhaorui.cn/admin)
- Uniapp 版本体验:[http://demo.izhaorui.cn/h5](http://demo.izhaorui.cn/h5)
- Vue3.x 版本体验:[http://www.izhaorui.cn/vue3](http://www.izhaorui.cn/vue3)
- Vue2.x 版本体验:[http://www.izhaorui.cn/admin](http://www.izhaorui.cn/admin)
- Uniapp 版本体验:[http://www.izhaorui.cn/h5](http://www.izhaorui.cn/h5)
- 账号密码:admin/123456,普通用户 user/123456
| H5 | 微信小程序 |
@@ -77,7 +61,7 @@ Vue 版前端技术栈 :基于 vue2.x/vue3.x/uniapp、vuex、vue-router 、vue
## 🍀 后端技术
- 核心框架:.Net7.0 + Web API + sqlsugar + swagger + signalR + IpRateLimit + Quartz.net + Redis
- 核心框架:.Net5.0/.Net7.0 + Web API + sqlsugar + swagger + signalR + IpRateLimit + Quartz.net + Redis
- 定时计划任务:Quartz.Net 组件,支持执行程序集或者 http 网络请求
- 安全支持:过滤器(数据权限过滤)、Sql 注入、请求伪造
- 日志管理:NLog、登录日志、操作日志、定时任务日志
@@ -86,7 +70,7 @@ Vue 版前端技术栈 :基于 vue2.x/vue3.x/uniapp、vuex、vue-router 、vue
- 代码生成:高效率开发,代码生成器可以一键生成所有前后端代码
- 数据字典:支持数据字典,可以方便对一些状态进行管理
- 分库分表:使用 orm sqlsugar 可以很轻松的实现分库分库性能优越
- 多 租 户:支持多租户功能(多数据库源)
- 多 租 户:支持多租户功能
- 缓存数据:内置内存缓存和 Redis
- signalR:使用 signalr 管理用户在线状态
@@ -103,7 +87,7 @@ Vue 版前端技术栈 :基于 vue2.x/vue3.x/uniapp、vuex、vue-router 、vue
9. 系统接口:使用 swagger 生成相关 api 接口文档。
10. 服务监控:监视当前系统 CPU、内存、磁盘、堆栈等相关信息。
11. 在线构建器:拖动表单元素生成相应的 VUE 代码(仅支持 vue2)。
12. 任务系统:基于 Quartz.NET,可以在线(添加、修改、删除、手动执行)任务调度包含执行结果日志。
12. 任务系统:基于 Quartz.NET,可以在线(添加、修改、删除、手动执行)任务调度包含执行结果日志。
13. 文章管理:可以写文章记录。
14. 代码生成:可以一键生成前后端代码(.cs、.vue、.js、.sql、uniapp 等)支持下载,自定义配置前端展示控件、让开发更快捷高效(史上最强)。
15. 参数管理:对系统动态配置常用参数。
@@ -115,8 +99,6 @@ Vue 版前端技术栈 :基于 vue2.x/vue3.x/uniapp、vuex、vue-router 、vue
21. 在线用户:可以查看正在登录使用的用户,可以对其踢出、通知操作
22. db 审计日志:数据库审计功能
23. 三方登录:提供三方登录实现逻辑
24. 导入导出:支持中文表头导入、字典数据转换成文本导出
25. 数据大屏:更直观的展示数据
## 🍻 项目结构
@@ -179,15 +161,10 @@ Vue 版前端技术栈 :基于 vue2.x/vue3.x/uniapp、vuex、vue-router 、vue
</tr>
<tr>
<td><img src="https://gitee.com/izory/ZrAdminNetCore/raw/master/document/images/21.png"/></td>
<td><img src="https://gitee.com/izory/ZrAdminNetCore/raw/master/document/images/22.png"/></td>
</tr>
<tr>
<td><img src="https://gitee.com/izory/ZrAdminNetCore/raw/master/document/images/23.png"/></td>
<td><img src="https://gitee.com/izory/ZrAdminNetCore/raw/master/document/images/24.png"/></td>
</tr>
</table>
## 📱 移动端演示图
## 移动端演示图
<table>
<tr>
@@ -208,10 +185,6 @@ Vue 版前端技术栈 :基于 vue2.x/vue3.x/uniapp、vuex、vue-router 、vue
</tr>
<tr>
<td><img src="https://gitee.com/izory/ZrAdminNetCore/raw/master/document/images/a10.png"/></td>
<td><img src="https://gitee.com/izory/ZrAdminNetCore/raw/master/document/images/a11.png"/></td>
</tr>
<tr>
<td><img src="https://gitee.com/izory/ZrAdminNetCore/raw/master/document/images/a12.png"/></td>
</tr>
</table>
@@ -223,8 +196,9 @@ Vue 版前端技术栈 :基于 vue2.x/vue3.x/uniapp、vuex、vue-router 、vue
3. 前台与后台系统分离,分别为不同的系统(域名可独立)
4. 全局异常统一处理
5. 自定义的代码生成功能
6. 依赖少(只需数据库即可使用),上手容易
6. 依赖少,上手容易
7. 文档全面
8. 支持中文表头导入数据
## 💐 特别鸣谢
@@ -0,0 +1,17 @@
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
namespace ZR.Admin.Grpc.Extensions;
public static class GrpcServiceExtensions
{
public static void AddGrpcServiceConfiguration(this IServiceCollection services, IConfiguration configuration)
{
// services.AddTransient<AuthUn>()
services.AddGrpcClient<Greeter.GreeterClient>(options =>
{
options.Address = new Uri(configuration.GetValue<string>("GrpcUrls:FindTeacher"));
});
}
}
+17
View File
@@ -0,0 +1,17 @@
syntax = "proto3";
option csharp_namespace = "GrpcService1";
package block;
service Block {
rpc GetBlock (BlockRequest) returns (BlockReply);
}
message BlockRequest {
string in = 1;
}
message BlockReply {
string out = 1;
}
+21
View File
@@ -0,0 +1,21 @@
syntax = "proto3";
option csharp_namespace = "ZR.Admin.Grpc";
package greet;
// The greeting service definition.
service Greeter {
// Sends a greeting
rpc SayHello (HelloRequest) returns (HelloReply);
}
// The request message containing the user's name.
message HelloRequest {
string name = 1;
}
// The response message containing the greetings.
message HelloReply {
string message = 1;
}
+22
View File
@@ -0,0 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<Protobuf Include="Protos\greet.proto" GrpcServices="Both"/>
<Protobuf Include="Protos\block.proto" GrpcServices="Client"/>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Grpc.AspNetCore" Version="2.49.0"/>
</ItemGroup>
<ItemGroup>
<Folder Include="Services\" />
</ItemGroup>
</Project>
+48 -36
View File
@@ -1,8 +1,12 @@
using Microsoft.AspNetCore.Mvc;
using Infrastructure.Helper;
using JinianNet.JNTemplate;
using Microsoft.Extensions.Options;
using Newtonsoft.Json;
using ZR.Admin.WebApi.Filters;
using ZR.Model.System;
using ZR.Service.IService;
using ZR.Service.System;
using ZR.ServiceCore.Model;
using ZR.ServiceCore.Services.IService;
namespace ZR.Admin.WebApi.Controllers
{
@@ -41,8 +45,11 @@ namespace ZR.Admin.WebApi.Controllers
[HttpGet]
public IActionResult Index()
{
return Ok("看到这里页面说明你已经成功启动了本项目:)\n\n" +
"如果觉得项目有用,打赏作者喝杯咖啡作为奖励\n☛☛http://www.izhaorui.cn/doc/support.html\n");
var contentTpl = JnHelper.ReadTemplate("", "logo.txt");
var content = contentTpl?.Render();
// return Ok("看到这里页面说明你已经成功启动了本项目:)\n\n" +
// $"{content}如果觉得项目有用,打赏作者喝杯咖啡作为奖励\n☛☛http://www.izhaorui.cn/doc/support.html\n");
return Ok($"{content}\n\n看到这里页面说明你已经成功启动了本项目:)\n");
}
/// <summary>
@@ -72,6 +79,39 @@ namespace ZR.Admin.WebApi.Controllers
return SUCCESS(msg);
}
/// <summary>
/// 发送邮件
/// </summary>
/// <param name="sendEmailVo">请求参数接收实体</param>
/// <returns></returns>
[ActionPermissionFilter(Permission = "tool:email:send")]
[Log(Title = "发送邮件")]
[HttpPost]
public IActionResult SendEmail([FromBody] SendEmailDto sendEmailVo)
{
if (sendEmailVo == null)
{
return ToResponse(ApiResult.Error($"请求参数不完整"));
}
if (string.IsNullOrEmpty(OptionsSetting.MailOptions.FromEmail) || string.IsNullOrEmpty(OptionsSetting.MailOptions.Password))
{
return ToResponse(ApiResult.Error($"请配置邮箱信息"));
}
MailHelper mailHelper = new();
string[] toUsers = sendEmailVo.ToUser.Split(",", StringSplitOptions.RemoveEmptyEntries);
if (sendEmailVo.SendMe)
{
toUsers.Append(mailHelper.FromEmail);
}
string result = mailHelper.SendMail(toUsers, sendEmailVo.Subject, sendEmailVo.Content, sendEmailVo.FileUrl, sendEmailVo.HtmlContent);
logger.Info($"发送邮件{JsonConvert.SerializeObject(sendEmailVo)}, 结果{result}");
return SUCCESS(result);
}
#region 上传
/// <summary>
@@ -111,7 +151,8 @@ namespace ZR.Admin.WebApi.Controllers
{
uploadDto.FileDir = OptionsSetting.Upload.LocalSavePath;
}
file = await SysFileService.SaveFileToLocal(savePath, uploadDto.FileName, uploadDto.FileDir, HttpContext.GetName(), formFile);
file = await SysFileService.SaveFileToLocal(savePath, uploadDto.FileName, uploadDto.FileDir,
HttpContext.GetUId(), HttpContext.GetNickName(), formFile, OptionsSetting.Upload.UploadUrl);
break;
case StoreType.REMOTE:
break;
@@ -125,7 +166,8 @@ namespace ZR.Admin.WebApi.Controllers
{
return ToResponse(ResultCode.CUSTOM_ERROR, "上传文件过大,不能超过 " + AlimaxContentLength + " MB");
}
file = new(formFile.FileName, uploadDto.FileName, fileExt, fileSize + "kb", uploadDto.FileDir, HttpContext.GetName())
file = new(formFile.FileName, uploadDto.FileName, fileExt, fileSize + "kb",
uploadDto.FileDir, HttpContext.GetUId(), HttpContext.GetNickName())
{
StoreType = (int)StoreType.ALIYUN,
FileType = formFile.ContentType
@@ -151,36 +193,6 @@ namespace ZR.Admin.WebApi.Controllers
#endregion
/// <summary>
/// 下载文件
/// </summary>
/// <param name="path"></param>
/// <param name="fileId"></param>
/// <returns></returns>
[HttpGet]
[Verify]
[ActionPermissionFilter(Permission = "common")]
[Log(Title = "下载文件", IsSaveResponseData = false)]
public IActionResult DownloadFile(string? path, long fileId = 0)
{
var tempPath = path;
if (fileId > 0)
{
var fileInfo = SysFileService.GetById(fileId);
if (fileInfo != null)
{
tempPath = fileInfo.FileUrl;
}
}
string fullPath = tempPath;
if (tempPath.StartsWith("/"))
{
fullPath = Path.Combine(WebHostEnvironment.WebRootPath, tempPath.ReplaceFirst("/", ""));
}
string fileName = Path.GetFileName(fullPath);
return DownFile(fullPath, fileName);
}
/// <summary>
/// 初始化种子数据
/// </summary>
@@ -1,142 +0,0 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;
using ZR.Admin.WebApi.Filters;
using ZR.Model.Dto;
using ZR.ServiceCore.Model;
using ZR.ServiceCore.Services;
//创建时间:2023-11-20
namespace ZR.Admin.WebApi.Controllers.Email
{
/// <summary>
/// 邮件发送记录
/// </summary>
[Verify]
[Route("system/EmailLog")]
[ApiExplorerSettings(GroupName = "sys")]
public class EmailLogController : BaseController
{
/// <summary>
/// 邮件发送记录接口
/// </summary>
private readonly IEmailLogService _EmailLogService;
private OptionsSetting OptionsSetting;
public EmailLogController(
IEmailLogService EmailLogService,
IOptions<OptionsSetting> options)
{
_EmailLogService = EmailLogService;
OptionsSetting = options.Value;
}
/// <summary>
/// 查询邮件发送记录列表
/// </summary>
/// <param name="parm"></param>
/// <returns></returns>
[HttpGet("list")]
[ActionPermissionFilter(Permission = "emaillog:list")]
public IActionResult QueryEmailLog([FromQuery] EmailLogQueryDto parm)
{
var response = _EmailLogService.GetList(parm);
return SUCCESS(response);
}
/// <summary>
/// 查询邮件发送记录详情
/// </summary>
/// <param name="Id"></param>
/// <returns></returns>
[HttpGet("{Id}")]
[ActionPermissionFilter(Permission = "emaillog:query")]
public IActionResult GetEmailLog(long Id)
{
var response = _EmailLogService.GetInfo(Id);
var info = response.Adapt<EmailLogDto>();
return SUCCESS(info);
}
/// <summary>
/// 添加邮件发送记录
/// </summary>
/// <returns></returns>
[HttpPost("sendEmail")]
[ActionPermissionFilter(Permission = "tool:email:send")]
[Log(Title = "邮件发送", BusinessType = BusinessType.INSERT)]
public IActionResult SendEmail([FromBody] EmailLogDto dto)
{
if (dto.IdArr.Length <= 0) { return ToResponse(ApiResult.Error($"发送失败Id 不能为空")); }
int count = 0;
foreach (var item in dto.IdArr)
{
var response = _EmailLogService.GetInfo(item);
if (response?.IsSend == 0)
{
MailHelper mailHelper = new();
string[] toUsers = response.ToEmails.Split(",", StringSplitOptions.RemoveEmptyEntries);
string result = mailHelper.SendMail(toUsers, response.Subject, "", response.FileUrl, response.EmailContent);
count += _EmailLogService.Update(x => x.Id == item, x => new EmailLog()
{
IsSend = 1,
SendTime = DateTime.Now,
SendResult = result
});
}
}
return SUCCESS(count);
}
/// <summary>
/// 删除邮件发送记录
/// </summary>
/// <returns></returns>
[HttpDelete("{ids}")]
[ActionPermissionFilter(Permission = "emaillog:delete")]
[Log(Title = "邮件发送记录", BusinessType = BusinessType.DELETE)]
public IActionResult DeleteEmailLog(string ids)
{
long[] idsArr = Tools.SpitLongArrary(ids);
if (idsArr.Length <= 0) { return ToResponse(ApiResult.Error($"删除失败Id 不能为空")); }
var response = _EmailLogService.Delete(idsArr);
return ToResponse(response);
}
/// <summary>
/// 发送邮件
/// </summary>
/// <param name="sendEmailVo">请求参数接收实体</param>
/// <returns></returns>
[ActionPermissionFilter(Permission = "tool:email:send")]
[Log(Title = "发送邮件")]
[HttpPost("/common/SendEmail")]
public IActionResult SendEmail([FromBody] SendEmailDto sendEmailVo)
{
if (sendEmailVo == null)
{
return ToResponse(ApiResult.Error($"请求参数不完整"));
}
if (string.IsNullOrEmpty(OptionsSetting.MailOptions.FromEmail) || string.IsNullOrEmpty(OptionsSetting.MailOptions.Password))
{
return ToResponse(ApiResult.Error($"请配置邮箱信息"));
}
MailHelper mailHelper = new();
string[] toUsers = sendEmailVo.ToUser.Split(",", StringSplitOptions.RemoveEmptyEntries);
string result = string.Empty;
if (sendEmailVo.IsSend)
{
result = mailHelper.SendMail(toUsers, sendEmailVo.Subject, sendEmailVo.Content, sendEmailVo.FileUrl, sendEmailVo.HtmlContent);
}
_EmailLogService.AddEmailLog(new EmailLog() { EmailContent = sendEmailVo.HtmlContent, Subject = sendEmailVo.Subject, ToEmails = sendEmailVo.ToUser, AddTime = DateTime.Now, FromEmail = OptionsSetting.MailOptions.FromEmail, IsSend = sendEmailVo.IsSend ? 1 : 0, SendResult = result });
//logger.Info($"发送邮件{JsonConvert.SerializeObject(sendEmailVo)}, 结果{result}");
return SUCCESS(result);
}
}
}
@@ -1,102 +0,0 @@
using Microsoft.AspNetCore.Mvc;
using ZR.Admin.WebApi.Filters;
using ZR.Model.Dto;
using ZR.ServiceCore.Model;
//创建时间:2023-11-12
namespace ZR.Admin.WebApi.Controllers.Email
{
/// <summary>
/// 邮件模板
/// </summary>
[Verify]
[Route("system/EmailTpl")]
[ApiExplorerSettings(GroupName = "sys")]
public class EmailTplController : BaseController
{
/// <summary>
/// 邮件模板接口
/// </summary>
private readonly IEmailTplService _EmailTplService;
public EmailTplController(IEmailTplService EmailTplService)
{
_EmailTplService = EmailTplService;
}
/// <summary>
/// 查询邮件模板列表
/// </summary>
/// <param name="parm"></param>
/// <returns></returns>
[HttpGet("list")]
[ActionPermissionFilter(Permission = "tool:emailtpl:list")]
public IActionResult QueryEmailTpl([FromQuery] EmailTplQueryDto parm)
{
var response = _EmailTplService.GetList(parm);
return SUCCESS(response);
}
/// <summary>
/// 查询邮件模板详情
/// </summary>
/// <param name="Id"></param>
/// <returns></returns>
[HttpGet("{Id}")]
public IActionResult GetEmailTpl(int Id)
{
var response = _EmailTplService.GetInfo(Id);
var info = response.Adapt<EmailTpl>();
return SUCCESS(info);
}
/// <summary>
/// 添加邮件模板
/// </summary>
/// <returns></returns>
[HttpPost]
[ActionPermissionFilter(Permission = "tool:emailtpl:add")]
[Log(Title = "邮件模板", BusinessType = BusinessType.INSERT)]
public IActionResult AddEmailTpl([FromBody] EmailTplDto parm)
{
var modal = parm.Adapt<EmailTpl>().ToCreate(HttpContext);
var response = _EmailTplService.AddEmailTpl(modal);
return SUCCESS(response);
}
/// <summary>
/// 更新邮件模板
/// </summary>
/// <returns></returns>
[HttpPut]
[ActionPermissionFilter(Permission = "tool:emailtpl:edit")]
[Log(Title = "邮件模板", BusinessType = BusinessType.UPDATE)]
public IActionResult UpdateEmailTpl([FromBody] EmailTplDto parm)
{
var modal = parm.Adapt<EmailTpl>().ToUpdate(HttpContext);
var response = _EmailTplService.UpdateEmailTpl(modal);
return ToResponse(response);
}
/// <summary>
/// 删除邮件模板
/// </summary>
/// <returns></returns>
[HttpDelete("{ids}")]
[ActionPermissionFilter(Permission = "tool:emailtpl:delete")]
[Log(Title = "邮件模板", BusinessType = BusinessType.DELETE)]
public IActionResult DeleteEmailTpl(string ids)
{
int[] idsArr = Tools.SpitIntArrary(ids);
if (idsArr.Length <= 0) { return ToResponse(ApiResult.Error($"删除失败Id 不能为空")); }
var response = _EmailTplService.Delete(idsArr);
return ToResponse(response);
}
}
}
@@ -1,8 +1,10 @@
using Microsoft.AspNetCore.Mvc;
using ZR.Admin.WebApi.Extensions;
using ZR.Admin.WebApi.Filters;
using ZR.Model.Dto;
using ZR.Model.System;
using ZR.Service.System.IService;
using ZR.ServiceCore.Model;
using ZR.ServiceCore.Model.Dto;
namespace ZR.Admin.WebApi.Controllers
{
@@ -1,9 +1,13 @@
using Microsoft.AspNetCore.Mvc;
using SqlSugar;
using ZR.Admin.WebApi.Extensions;
using ZR.Admin.WebApi.Filters;
using ZR.Model;
using ZR.Model.System;
using ZR.Model.System.Dto;
using ZR.Service.System.IService;
using ZR.ServiceCore.Filters;
using ZR.ServiceCore.Model;
using ZR.ServiceCore.Model.Dto;
namespace ZR.Admin.WebApi.Controllers
{
@@ -32,7 +36,8 @@ namespace ZR.Admin.WebApi.Controllers
/// </summary>
/// <returns></returns>
[HttpGet("list")]
[ActionPermissionFilter(Permission = "system:article:list")]
// [ActionPermissionFilter(RolePermi = "admin")]
[DataFieldFilter(typeof(PagedInfo<ArticleDto>))]
public IActionResult Query([FromQuery] ArticleQueryDto parm)
{
var response = _ArticleService.GetList(parm);
@@ -85,7 +90,6 @@ namespace ZR.Admin.WebApi.Controllers
long userId = HttpContext.GetUId();
var response = _ArticleService.GetId(id);
var model = response.Adapt<ArticleDto>();
if (model == null) return ToResponse(ResultCode.FAIL, "文章不存在");
if (model.IsPublic == 0 && userId != model.UserId)
{
return ToResponse(ResultCode.CUSTOM_ERROR, "访问失败");
@@ -0,0 +1,45 @@
using ZR.Model;
using ZR.Model.System;
using ZR.ServiceCore.Services.IService;
namespace ZR.Admin.WebApi.Controllers.System;
[Route("base/codeRule")]
public class BaseCodeRuleController : BaseController
{
private static readonly NLog.Logger Logger = NLog.LogManager.GetCurrentClassLogger();
private readonly IBaseCodeRuleService _baseCodeRuleService;
public BaseCodeRuleController(IBaseCodeRuleService baseCodeRuleService)
{
_baseCodeRuleService = baseCodeRuleService;
}
[HttpPost("addBaseCodeRule")]
public async Task<IActionResult> AddBaseCodeRule([FromBody] BaseCodeRule baseCodeRule)
{
var result = await _baseCodeRuleService.InsertBaseCodeRuleAsync(baseCodeRule);
return SUCCESS(result);
}
[HttpDelete("deleteBaseCodeRule/{code}")]
public async Task<IActionResult> DeleteBaseCodeRule(string code)
{
var result = await _baseCodeRuleService.DeleteBaseCodeRuleAsync(code);
return SUCCESS(result);
}
[HttpPut("updateBaseCodeRule")]
public async Task<IActionResult> UpdateBaseCodeRule([FromBody] BaseCodeRule baseCodeRule)
{
var result = await _baseCodeRuleService.UpdateBaseCodeRule(baseCodeRule);
return SUCCESS(result);
}
[HttpGet("getBaseCodeRuleList")]
public IActionResult GetBaseCodeRuleList([FromQuery] BaseCodeRule baseCodeRule, [FromQuery] PagerInfo pagerInfo)
{
var result = _baseCodeRuleService.SelectBaseCodeRulePage(baseCodeRule, pagerInfo);
return SUCCESS(result);
}
}
@@ -1,13 +1,15 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;
using SqlSugar;
using ZR.Admin.WebApi.Extensions;
using ZR.Admin.WebApi.Filters;
using ZR.CodeGenerator;
using ZR.CodeGenerator.Model;
using ZR.CodeGenerator.Service;
using ZR.Model;
using ZR.Model.System.Dto;
using ZR.Model.System.Generate;
using ZR.Service.System.IService;
using ZR.ServiceCore.Model.Dto;
using ZR.ServiceCore.Model.Generate;
using ZR.ServiceCore.Services.IService;
namespace ZR.Admin.WebApi.Controllers
{
@@ -24,20 +26,16 @@ namespace ZR.Admin.WebApi.Controllers
private readonly IGenTableColumnService GenTableColumnService;
private readonly ISysMenuService SysMenuService;
private readonly IWebHostEnvironment WebHostEnvironment;
private readonly OptionsSetting OptionsSetting;
public CodeGeneratorController(
IGenTableService genTableService,
IGenTableColumnService genTableColumnService,
IWebHostEnvironment webHostEnvironment,
IOptions<OptionsSetting> options,
ISysMenuService sysMenuService)
{
GenTableService = genTableService;
GenTableColumnService = genTableColumnService;
WebHostEnvironment = webHostEnvironment;
SysMenuService = sysMenuService;
OptionsSetting = options.Value;
}
/// <summary>
@@ -137,49 +135,45 @@ namespace ZR.Admin.WebApi.Controllers
/// <summary>
/// 导入表结构(保存)
/// </summary>
/// <param name="dto"></param>
/// <param name="tables"></param>
/// <param name="dbName"></param>
/// <returns></returns>
[HttpPost("importTable")]
[Log(Title = "代码生成", BusinessType = BusinessType.IMPORT)]
[ActionPermissionFilter(Permission = "tool:gen:import")]
public IActionResult ImportTableSave([FromBody] ImportCodeGenTableDto dto)
public IActionResult ImportTableSave(string tables, string dbName)
{
if (string.IsNullOrEmpty(dto.DbName) || dto.Tables == null)
if (string.IsNullOrEmpty(tables))
{
throw new CustomException("表或数据库不能为空");
throw new CustomException("表不能为空");
}
DbConfigs dbConfig = AppSettings.Get<DbConfigs>(nameof(GlobalConstant.CodeGenDbConfig));
string[] tableNames = tables.Split(',', StringSplitOptions.RemoveEmptyEntries);
int result = 0;
foreach (var table in dto.Tables)
foreach (var tableName in tableNames)
{
var tabInfo = _CodeGeneraterService.GetTableInfo(dbName, tableName);
if (tabInfo != null)
{
List<OracleSeq> seqs = new();
InitTableDto initTableDto = new()
{
DbName = dto.DbName,
UserName = HttpContext.GetName(),
TableName = table.Name,
Desc = table.Description,
CodeGen = OptionsSetting.CodeGen,
FrontTpl = dto.FrontTpl,
};
GenTable genTable = CodeGeneratorTool.InitTable(initTableDto);
GenTable genTable = CodeGeneratorTool.InitTable(dbName, HttpContext.GetName(), tableName, tabInfo?.Description);
genTable.TableId = GenTableService.ImportGenTable(genTable);
if (OptionsSetting.CodeGenDbConfig.DbType == 3)
if (dbConfig.DbType == 3)
{
seqs = _CodeGeneraterService.GetAllOracleSeqs(table.Name);
seqs = _CodeGeneraterService.GetAllOracleSeqs(dbName);
}
if (genTable.TableId > 0)
{
//保存列信息
List<DbColumnInfo> dbColumnInfos = _CodeGeneraterService.GetColumnInfo(dto.DbName, table.Name);
List<GenTableColumn> genTableColumns = CodeGeneratorTool.InitGenTableColumn(genTable, dbColumnInfos, seqs, OptionsSetting.CodeGen);
GenTableColumnService.DeleteGenTableColumnByTableName(table.Name);
List<DbColumnInfo> dbColumnInfos = _CodeGeneraterService.GetColumnInfo(dbName, tableName);
List<GenTableColumn> genTableColumns = CodeGeneratorTool.InitGenTableColumn(genTable, dbColumnInfos, seqs);
GenTableColumnService.DeleteGenTableColumnByTableName(tableName);
GenTableColumnService.InsertGenTableColumn(genTableColumns);
genTable.Columns = genTableColumns;
result++;
}
}
}
return ToResponse(result);
}
@@ -202,7 +196,7 @@ namespace ZR.Admin.WebApi.Controllers
var genTable = genTableDto.Adapt<GenTable>().ToUpdate(HttpContext);
//将前端额外参数转成字符串存入Options中
genTable.Options = genTableDto.Params.Adapt<CodeOptions>();
genTable.Options = genTableDto.Params.Adapt<Options>();
DbResult<bool> result = GenTableService.UseTran(() =>
{
int rows = GenTableService.UpdateGenTable(genTable);
@@ -231,8 +225,9 @@ namespace ZR.Admin.WebApi.Controllers
throw new CustomException(ResultCode.CUSTOM_ERROR, "请求参数为空");
}
var genTableInfo = GenTableService.GetGenTableInfo(dto.TableId);
var dbConfig = AppSettings.Get<DbConfigs>(nameof(GlobalConstant.CodeGenDbConfig));
dto.DbType = OptionsSetting.CodeGenDbConfig.DbType;
dto.DbType = dbConfig.DbType;
dto.GenTable = genTableInfo;
dto.IsPreview = true;
@@ -255,53 +250,44 @@ namespace ZR.Admin.WebApi.Controllers
{
throw new CustomException(ResultCode.CUSTOM_ERROR, "请求参数为空");
}
var genTableInfo = GenTableService.GetGenTableInfo(dto.TableId);
var dbConfig = AppSettings.Get<DbConfigs>(nameof(GlobalConstant.CodeGenDbConfig));
dto.DbType = OptionsSetting.CodeGenDbConfig.DbType;
dto.GenTable = GenTableService.GetGenTableInfo(dto.TableId);
//生成压缩包
string zipReturnFileName = $"ZrAdmin.NET-{dto.GenTable.TableName}-{DateTime.Now:MMddHHmmss}.zip";
//生成代码到指定文件夹
CodeGeneratorTool.Generate(dto);
if (dto.GenTable.Options.GenerateMenu)
dto.DbType = dbConfig.DbType;
dto.GenTable = genTableInfo;
//自定义路径
if (genTableInfo.GenType == "1")
{
SysMenuService.AddSysMenu(dto.GenTable, dto.ReplaceDto.PermissionPrefix, dto.ReplaceDto.ShowBtnEdit, dto.ReplaceDto.ShowBtnExport, dto.ReplaceDto.ShowBtnImport);
}
if (dto.GenTable.GenType == "1")//自定义路径
{
var genPath = dto.GenTable.GenPath;
string parentPath;
var genPath = genTableInfo.GenPath;
string tempPath = WebHostEnvironment.ContentRootPath;
if (ComputerHelper.IsUnix())
{
parentPath = Path.Combine(WebHostEnvironment.WebRootPath, "Generatecode");
}
else
{
parentPath = tempPath[..tempPath.LastIndexOf(@"\")];
}
Console.WriteLine("代码生成路径" + parentPath);
var parentPath = tempPath[..tempPath.LastIndexOf(@"\")];
//代码生成文件夹路径
dto.GenCodePath = (genPath.IsEmpty() || genPath.Equals("/")) ? parentPath : genPath;
dto.GenCodePath = (genPath.IsEmpty() || genPath.Equals("/")) ? parentPath : genTableInfo.GenPath;
}
else
{
dto.ZipPath = Path.Combine(WebHostEnvironment.WebRootPath, "Generatecode");
dto.GenCodePath = Path.Combine(dto.ZipPath, DateTime.Now.ToString("yyyyMMdd"));
}
//生成压缩包
string zipReturnFileName = $"ZrAdmin.NET-{genTableInfo.TableComment}-{DateTime.Now:MMddHHmmss}.zip";
//生成代码到指定文件夹
CodeGeneratorTool.Generate(dto);
if (genTableInfo.Options.GenerateMenu)
{
SysMenuService.AddSysMenu(genTableInfo, dto.ReplaceDto.PermissionPrefix, dto.ReplaceDto.ShowBtnEdit, dto.ReplaceDto.ShowBtnExport, dto.ReplaceDto.ShowBtnImport);
}
//写入文件
foreach (var item in dto.GenCodes)
{
item.Path = Path.Combine(dto.GenCodePath, item.Path);
FileUtil.WriteAndSave(item.Path, item.Content);
}
if (dto.GenTable.GenType != "1")
{
//压缩文件
//下载文件
FileUtil.ZipGenCode(dto.ZipPath, dto.GenCodePath, zipReturnFileName);
}
return SUCCESS(new { path = "/Generatecode/" + zipReturnFileName, fileName = dto.ZipFileName });
}
@@ -319,11 +305,11 @@ namespace ZR.Admin.WebApi.Controllers
if (string.IsNullOrEmpty(tableName) || tableId <= 0) throw new CustomException("参数错误");
GenTable table = GenTableService.GetGenTableInfo(tableId);
if (table == null) { throw new CustomException("同步数据失败,原表结构不存在"); }
table.Update_by = HttpContext.GetName();
table.Update_by = HttpContext.GetUId();
table.Update_name = HttpContext.GetNickName();
var codeGen = AppSettings.Get<CodeGen>("codeGen");
List<DbColumnInfo> dbColumnInfos = _CodeGeneraterService.GetColumnInfo(table.DbName, tableName);
List<GenTableColumn> dbTableColumns = CodeGeneratorTool.InitGenTableColumn(table, dbColumnInfos, codeGen: codeGen);
List<GenTableColumn> dbTableColumns = CodeGeneratorTool.InitGenTableColumn(table, dbColumnInfos);
bool result = GenTableService.SynchDb(tableId, table, dbTableColumns);
return SUCCESS(result);
@@ -1,9 +1,11 @@
using Infrastructure.Extensions;
using Microsoft.AspNetCore.Mvc;
using MiniExcelLibs;
using ZR.Admin.WebApi.Filters;
using ZR.Model;
using ZR.Model.Dto;
using ZR.Model.Models;
using ZR.Service.System.IService;
using ZR.ServiceCore.Model;
using ZR.ServiceCore.Model.Dto;
namespace ZR.Admin.WebApi.Controllers
{
@@ -1,8 +1,12 @@
using Infrastructure.Extensions;
using Microsoft.AspNetCore.Mvc;
using SqlSugar;
using ZR.Admin.WebApi.Extensions;
using ZR.Admin.WebApi.Filters;
using ZR.Model.System;
using ZR.Model.System.Dto;
using ZR.Service.System.IService;
using ZR.ServiceCore.Model;
using ZR.ServiceCore.Model.Dto;
namespace ZR.Admin.WebApi.Controllers
{
@@ -2,7 +2,9 @@
using System.Collections;
using ZR.Admin.WebApi.Filters;
using ZR.Model.System;
using ZR.Model.System.Dto;
using ZR.Service.System.IService;
using ZR.ServiceCore.Model;
using ZR.ServiceCore.Model.Dto;
namespace ZR.Admin.WebApi.Controllers.System
{
@@ -113,7 +115,8 @@ namespace ZR.Admin.WebApi.Controllers.System
{
return ToResponse(ResultCode.CUSTOM_ERROR, $"新增部门{dept.DeptName}失败,部门名称已存在");
}
dept.Create_by = HttpContext.GetName();
dept.Create_by = HttpContext.GetUId();
dept.Create_name = HttpContext.GetNickName();
return ToResponse(DeptService.InsertDept(dept));
}
@@ -135,7 +138,8 @@ namespace ZR.Admin.WebApi.Controllers.System
{
return ToResponse(ResultCode.CUSTOM_ERROR, $"修改部门{dept.DeptName}失败,上级部门不能是自己");
}
dept.Update_by = HttpContext.GetName();
dept.Update_by = HttpContext.GetUId();
dept.Update_name = HttpContext.GetNickName();
return ToResponse(DeptService.UpdateDept(dept));
}
@@ -2,7 +2,9 @@
using ZR.Admin.WebApi.Filters;
using ZR.Model;
using ZR.Model.System;
using ZR.Model.System.Dto;
using ZR.Service.System.IService;
using ZR.ServiceCore.Model;
using ZR.ServiceCore.Model.Dto;
namespace ZR.Admin.WebApi.Controllers.System
{
@@ -64,14 +66,14 @@ namespace ZR.Admin.WebApi.Controllers.System
/// <returns></returns>
[AllowAnonymous]
[HttpPost("types")]
public IActionResult DictTypes([FromBody] List<SysdictDataDto> dto)
public IActionResult DictTypes([FromBody] List<SysDictDataDto> dto)
{
var list = SysDictDataService.SelectDictDataByTypes(dto.Select(f => f.DictType).ToArray());
List<SysdictDataDto> dataVos = new();
List<SysDictDataDto> dataVos = new();
foreach (var dic in dto)
{
SysdictDataDto vo = new()
SysDictDataDto vo = new()
{
DictType = dic.DictType,
ColumnName = dic.ColumnName,
@@ -108,7 +110,8 @@ namespace ZR.Admin.WebApi.Controllers.System
[HttpPost()]
public IActionResult Add([FromBody] SysDictData dict)
{
dict.Create_by = HttpContext.GetName();
dict.Create_by = HttpContext.GetUId();
dict.Create_name = HttpContext.GetNickName();
dict.Create_time = DateTime.Now;
return SUCCESS(SysDictDataService.InsertDictData(dict));
}
@@ -123,7 +126,8 @@ namespace ZR.Admin.WebApi.Controllers.System
[HttpPut()]
public IActionResult Edit([FromBody] SysDictData dict)
{
dict.Update_by = HttpContext.GetName();
dict.Update_by = HttpContext.GetUId();
dict.Update_name = HttpContext.GetNickName();
return SUCCESS(SysDictDataService.UpdateDictData(dict));
}
@@ -3,8 +3,9 @@ using ZR.Admin.WebApi.Extensions;
using ZR.Admin.WebApi.Filters;
using ZR.Model;
using ZR.Model.System;
using ZR.Model.System.Dto;
using ZR.Service.System.IService;
using ZR.ServiceCore.Model;
using ZR.ServiceCore.Model.Dto;
namespace ZR.Admin.WebApi.Controllers.System
{
@@ -65,7 +66,8 @@ namespace ZR.Admin.WebApi.Controllers.System
{
return ToResponse(ApiResult.Error($"新增字典'{dict.DictName}'失败,字典类型已存在"));
}
dict.Create_by = HttpContext.GetName();
dict.Create_by = HttpContext.GetUId();
dict.Create_name = HttpContext.GetNickName();
dict.Create_time = DateTime.Now;
return SUCCESS(SysDictService.InsertDictType(dict));
}
@@ -87,7 +89,8 @@ namespace ZR.Admin.WebApi.Controllers.System
return ToResponse(ApiResult.Error($"修改字典'{dict.DictName}'失败,字典类型已存在"));
}
//设置添加人
dict.Update_by = HttpContext.GetName();
dict.Update_by = HttpContext.GetUId();
dict.Update_name = HttpContext.GetNickName();
return SUCCESS(SysDictService.UpdateDictType(dict));
}
@@ -0,0 +1,62 @@
using ZR.Admin.WebApi.Filters;
using ZR.Model;
using ZR.ServiceCore.Model;
using ZR.ServiceCore.Model.Dto;
using ZR.ServiceCore.Services.IService;
namespace ZR.Admin.WebApi.Controllers.System;
[Verify]
[Route("system/field")]
public class SysFieldController : BaseController
{
private readonly ISysFieldService _sysFieldService;
private readonly ISysRoleFieldService _sysRoleFieldService;
public SysFieldController(ISysFieldService sysFieldService, ISysRoleFieldService sysRoleFieldService)
{
_sysFieldService = sysFieldService;
_sysRoleFieldService = sysRoleFieldService;
}
[HttpGet("getModelList")]
public async Task<IActionResult> GetModelList([FromQuery] PagerInfo pagerInfo)
=> SUCCESS(await _sysFieldService.GetModelList(pagerInfo));
[HttpGet("getFields")]
public async Task<IActionResult> GetFields([FromQuery] string fullName, long roleId)
=> SUCCESS(await _sysFieldService.GetFields(fullName, roleId));
[HttpPost("initFields")]
public async Task<IActionResult> InitFields()
=> SUCCESS(await _sysFieldService.InitFields());
[HttpPut("addOrUpdateSysRoleField/{roleId}")]
public async Task<IActionResult> AddOrUpdateSysRoleField([FromBody] List<SysFieldDto> sysFieldDtos,
[FromRoute] long roleId)
=> SUCCESS(await _sysRoleFieldService.InsertOrUpdateSysRoleField(sysFieldDtos, roleId));
[HttpPost("fieldDisplay")]
public async Task<IActionResult> FieldDisplay(string blockCode)
{
var info = JwtUtil.GetLoginUser(HttpContext);
var roleIds = info.Roles.Select(it => it.RoleId).ToList();
var list = await _sysFieldService.Queryable()
.LeftJoin<SysFieldBlock>((sf, sfb) => sf.Id == sfb.FieldId)
.LeftJoin<SysBlock>((sf, sfb, sb) => sfb.BlockId == sb.Id )
.LeftJoin<SysRoleField>((sf,sfb, sb, srf) => sf.Id == srf.FieldId)
.Where((sf,sfb, sb, srf) => roleIds.Contains(srf.RoleId))
.Where((sf,sfb, sb, srf) => sb.Code == blockCode)
.WithCache(10 * 60)
.Select((sf,sfb, sb, srf) => sf.FieldName)
.ToListAsync();
// var list = await _sysFieldService.Queryable()
// .LeftJoin<SysRoleField>((sf, srf) => sf.Id == srf.FieldId)
// .Where((sf, srf) => roleIds.Contains(srf.RoleId))
// .WithCache(10 * 60)
// .Select((sf, srf) => sf.FieldName)
// .ToListAsync();
return SUCCESS(list);
}
}
@@ -1,8 +1,8 @@
using Microsoft.AspNetCore.Mvc;
using SqlSugar;
using ZR.Admin.WebApi.Filters;
using ZR.Model.System;
using ZR.Model.System.Dto;
using ZR.ServiceCore.Model;
using ZR.ServiceCore.Model.Dto;
using ZR.ServiceCore.Services.IService;
namespace ZR.Admin.WebApi.Controllers
{
@@ -17,11 +17,11 @@ namespace ZR.Admin.WebApi.Controllers
/// <summary>
/// 文件存储接口
/// </summary>
private readonly ISysFileService _SysFileService;
private readonly ISysFileService _sysFileService;
public SysFileController(ISysFileService SysFileService)
public SysFileController(ISysFileService sysFileService)
{
_SysFileService = SysFileService;
_sysFileService = sysFileService;
}
/// <summary>
@@ -40,7 +40,7 @@ namespace ZR.Admin.WebApi.Controllers
predicate = predicate.AndIF(parm.StoreType != null, m => m.StoreType == parm.StoreType);
predicate = predicate.AndIF(parm.FileId != null, m => m.Id == parm.FileId);
var response = _SysFileService.GetPages(predicate.ToExpression(), parm, x => x.Id, OrderByType.Desc);
var response = _sysFileService.GetPages(predicate.ToExpression(), parm, x => x.Id, OrderByType.Desc);
return SUCCESS(response);
}
@@ -53,7 +53,7 @@ namespace ZR.Admin.WebApi.Controllers
[ActionPermissionFilter(Permission = "tool:file:query")]
public IActionResult GetSysFile(long Id)
{
var response = _SysFileService.GetFirst(x => x.Id == Id);
var response = _sysFileService.GetFirst(x => x.Id == Id);
return SUCCESS(response);
}
@@ -65,13 +65,12 @@ namespace ZR.Admin.WebApi.Controllers
[HttpDelete("{ids}")]
[ActionPermissionFilter(Permission = "tool:file:delete")]
[Log(Title = "文件存储", BusinessType = BusinessType.DELETE)]
public IActionResult DeleteSysFile(string ids)
public async Task<IActionResult> DeleteSysFile(string ids)
{
long[] idsArr = Tools.SpitLongArrary(ids);
if (idsArr.Length <= 0) { return ToResponse(ApiResult.Error($"删除失败Id 不能为空")); }
var response = _SysFileService.Delete(idsArr);
//TODO 删除本地资源
var response = await _sysFileService.DeleteSysFileAsync(idsArr);
return ToResponse(response);
}
@@ -85,10 +84,50 @@ namespace ZR.Admin.WebApi.Controllers
[ActionPermissionFilter(Permission = "tool:file:export")]
public IActionResult Export()
{
var list = _SysFileService.GetAll();
var list = _sysFileService.GetAll();
string sFileName = ExportExcel(list, "SysFile", "文件存储");
return SUCCESS(new { path = "/export/" + sFileName, fileName = sFileName });
}
/// <summary>
/// 通过文件ID下载文件
/// </summary>
/// <param name="file"></param>
/// <returns></returns>
[HttpPost("download")]
public IActionResult Download([FromBody] SysFile file)
{
var sysFile = _sysFileService.Queryable().Where(it => it.Id == file.Id).First();
if (sysFile == null)
{
return NoContent();
}
Stream? stream = null;
switch ((StoreType)Enum.Parse(typeof(StoreType), sysFile.StoreType.ToString() ?? string.Empty))
{
case StoreType.LOCAL:
stream = sysFile.IsEncrypted == "1" ? _sysFileService.DecryptSysFileStream(sysFile.FileUrl)
: new FileStream(sysFile.FileUrl, FileMode.Open);
break;
case StoreType.ALIYUN:
stream = AliyunOssHelper.DownloadFile(sysFile.FileUrl, "", sysFile.IsEncrypted == "1");
break;
default:
throw new CustomException("不支持的存储类型");
}
if (stream != null)
{
return new FileStreamResult(stream, "application/octet-stream")
{
FileDownloadName = sysFile.RealName
};
}
else
{
return NoContent();
}
}
}
}
@@ -1,10 +1,13 @@
using Lazy.Captcha.Core;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;
using NETCore.Encrypt;
using ZR.Admin.WebApi.Filters;
using ZR.Infrastructure.Helper;
using ZR.Model.System;
using ZR.Model.System.Dto;
using ZR.Infrastructure.Cache;
using ZR.Service.System;
using ZR.Service.System.IService;
using ZR.ServiceCore.Model;
using ZR.ServiceCore.Model.Dto;
using ZR.ServiceCore.Services.IService;
namespace ZR.Admin.WebApi.Controllers.System
{
@@ -14,6 +17,8 @@ namespace ZR.Admin.WebApi.Controllers.System
[ApiExplorerSettings(GroupName = "sys")]
public class SysLoginController : BaseController
{
//static readonly NLog.Logger logger = NLog.LogManager.GetLogger("LoginController");
private readonly IHttpContextAccessor httpContextAccessor;
private readonly ISysUserService sysUserService;
private readonly ISysMenuService sysMenuService;
private readonly ISysLoginService sysLoginService;
@@ -21,28 +26,32 @@ namespace ZR.Admin.WebApi.Controllers.System
private readonly ICaptcha SecurityCodeHelper;
private readonly ISysConfigService sysConfigService;
private readonly ISysRoleService roleService;
private readonly ISmsCodeLogService smsCodeLogService;
private readonly OptionsSetting optionSettings;
public SysLoginController(
IHttpContextAccessor contextAccessor,
ISysMenuService sysMenuService,
ISysUserService sysUserService,
ISysLoginService sysLoginService,
ISysPermissionService permissionService,
ISysConfigService configService,
ISysRoleService sysRoleService,
ISmsCodeLogService smsCodeLogService,
ICaptcha captcha)
ICaptcha captcha,
IOptions<OptionsSetting> optionSettings)
{
httpContextAccessor = contextAccessor;
SecurityCodeHelper = captcha;
this.sysMenuService = sysMenuService;
this.sysUserService = sysUserService;
this.sysLoginService = sysLoginService;
this.permissionService = permissionService;
this.sysConfigService = configService;
this.smsCodeLogService = smsCodeLogService;
roleService = sysRoleService;
this.optionSettings = optionSettings.Value;
}
// RSA私钥
private static readonly string PrivatePem = AppSettings.GetConfig("RSA:PrivatePem");
/// <summary>
/// 登录
@@ -56,14 +65,21 @@ namespace ZR.Admin.WebApi.Controllers.System
{
if (loginBody == null) { throw new CustomException("请求参数错误"); }
loginBody.LoginIP = HttpContextExtension.GetClientUserIp(HttpContext);
SysConfig sysConfig = sysConfigService.GetSysConfigByKey("sys.account.captchaOnOff");
if (sysConfig?.ConfigValue != "off" && !SecurityCodeHelper.Validate(loginBody.Uuid, loginBody.Code))
var sysConfig = sysConfigService.GetSysConfigByKey("sys.account.captchaOnOff");
var headers = HttpContext.Request.Headers;
var isRemoteInvoke = headers["Remote-Invoke"].FirstOrDefault().ParseToBool();
if (sysConfig?.ConfigValue != "off" && !SecurityCodeHelper.Validate(loginBody.Uuid, loginBody.Code)
&& !isRemoteInvoke)
{
return ToResponse(ResultCode.CAPTCHA_ERROR, "验证码错误");
}
sysLoginService.CheckLockUser(loginBody.Username);
string location = HttpContextExtension.GetIpInfo(loginBody.LoginIP);
// RSA解密
loginBody.Password = EncryptProvider.RSADecryptWithPem(PrivatePem, loginBody.Password);
var user = sysLoginService.Login(loginBody, new SysLogininfor() { LoginLocation = location });
List<SysRole> roles = roleService.SelectUserRoleListByUserId(user.UserId);
@@ -167,7 +183,7 @@ namespace ZR.Admin.WebApi.Controllers.System
{
return ToResponse(ResultCode.CAPTCHA_ERROR, "验证码错误");
}
dto.UserIP = HttpContext.GetClientUserIp();
SysUser user = sysUserService.Register(dto);
if (user.UserId > 0)
{
@@ -176,6 +192,64 @@ namespace ZR.Admin.WebApi.Controllers.System
return ToResponse(ResultCode.CUSTOM_ERROR, "注册失败,请联系管理员");
}
/// <summary>
/// 发送邮箱验证码
/// </summary>
/// <param name="sendEmailVo"></param>
/// <returns></returns>
[HttpPost("getMailCode")]
public async Task<IActionResult> GetMailCode([FromBody] SendEmailDto sendEmailVo)
{
if (string.IsNullOrEmpty(sendEmailVo.ToUser))
{
return ToResponse(ApiResult.Error($"邮箱不能为空"));
}
if (string.IsNullOrEmpty(optionSettings.MailOptions.FromEmail) || string.IsNullOrEmpty(optionSettings.MailOptions.Password))
{
return ToResponse(ApiResult.Error($"请配置邮箱信息"));
}
if (sendEmailVo.ToUser.Length > 32)
{
// 解密邮箱
sendEmailVo.ToUser = EncryptProvider.RSADecryptWithPem(PrivatePem, sendEmailVo.ToUser);
// 验证邮箱是否存在于系统用户中
var user = await sysUserService.IsAnyAsync(it => it.Email == sendEmailVo.ToUser);
// if (user == null || user.UserId <= 0)
// 不存在则提示错误
if (!user)
{
return ToResponse(ApiResult.Error($"邮箱错误,请联系管理员"));
}
}
else
{
string[] saltKey = await RedisServer.Session.LRangeAsync("saltMail:" + sendEmailVo.ToUser, 0, 1);
if (saltKey.Length > 0)
{
sendEmailVo.ToUser = saltKey[0];
}
else
{
return ToResponse(ApiResult.Error($"邮箱错误,请联系管理员"));
}
}
// 实例化MailHelper以准备发送邮件
MailHelper mailHelper = new();
// 生成6位邮箱验证码
var verifyCode = mailHelper.VerifyCode(6);
// 设置存入Redis的key为 verifyCode: 前缀 + (盐 + 邮箱)的MD5值
var key = "verifyCode:" + sendEmailVo.ToUser;
// 存入Redis中设置过期时间为15分钟
var res = await RedisServer.Session.SetAsync(key, verifyCode, 900);
// 发送邮件,主题为 ZRAdmin.NET邮箱验证码,内容为验证码
mailHelper.SendMail(sendEmailVo.ToUser, "ZRAdmin.NET邮箱验证码", verifyCode);
return SUCCESS(res);
}
#region 二维码登录
/// <summary>
@@ -256,73 +330,5 @@ namespace ZR.Admin.WebApi.Controllers.System
}
#endregion
/// <summary>
///
/// </summary>
/// <param name="dto"></param>
/// <returns></returns>
[HttpPost("checkMobile")]
[Log(Title = "发送短息", BusinessType = BusinessType.INSERT)]
public IActionResult CheckMobile([FromBody] PhoneLoginDto dto)
{
dto.LoginIP = HttpContextExtension.GetClientUserIp(HttpContext);
SysConfig sysConfig = sysConfigService.GetSysConfigByKey("sys.account.captchaOnOff");
if (sysConfig?.ConfigValue != "off" && !SecurityCodeHelper.Validate(dto.Uuid, dto.Code, false))
{
return ToResponse(ResultCode.CUSTOM_ERROR, "验证码错误");
}
string location = HttpContextExtension.GetIpInfo(dto.LoginIP);
var info = sysUserService.GetFirst(f => f.Phonenumber == dto.PhoneNum) ?? throw new CustomException(ResultCode.CUSTOM_ERROR, "该手机号不存在", false);
var smsCode = RandomHelper.GenerateNum(6);
var smsContent = $"验证码{smsCode}(随机验证码),有效期10分钟。";
//TODO 发送短息验证码,1分钟内允许一次
smsCodeLogService.AddSmscodeLog(new ServiceCore.Model.SmsCodeLog()
{
Userid = info.UserId,
PhoneNum = dto.PhoneNum.ParseToLong(),
AddTime = DateTime.Now,
SendType = 1,
SmsCode = smsCode,
SmsContent = smsContent,
UserIP = dto.LoginIP,
Location = location,
});
CacheService.SetPhoneCode(dto.PhoneNum, smsCode);
return SUCCESS(new { smsCode });
}
/// <summary>
/// 手机号登录
/// </summary>
/// <param name="loginBody">登录对象</param>
/// <returns></returns>
[Route("PhoneLogin")]
[HttpPost]
[Log(Title = "手机号登录")]
public IActionResult PhoneLogin([FromBody] PhoneLoginDto loginBody)
{
if (loginBody == null) { throw new CustomException("请求参数错误"); }
loginBody.LoginIP = HttpContextExtension.GetClientUserIp(HttpContext);
if (!CacheService.CheckPhoneCode(loginBody.PhoneNum, loginBody.PhoneCode))
{
return ToResponse(ResultCode.CUSTOM_ERROR, "短信验证码错误");
}
var info = sysUserService.GetFirst(f => f.Phonenumber == loginBody.PhoneNum) ?? throw new CustomException(ResultCode.CUSTOM_ERROR, "该手机号不存在", false);
sysLoginService.CheckLockUser(info.UserName);
string location = HttpContextExtension.GetIpInfo(loginBody.LoginIP);
var user = sysLoginService.PhoneLogin(loginBody, new SysLogininfor() { LoginLocation = location }, info);
List<SysRole> roles = roleService.SelectUserRoleListByUserId(user.UserId);
//权限集合 eg *:*:*,system:user:list
List<string> permissions = permissionService.GetMenuPermission(user);
TokenModel loginUser = new(user.Adapt<TokenModel>(), roles.Adapt<List<Roles>>());
CacheService.SetUserPerms(GlobalConstant.UserPermKEY + user.UserId, permissions);
return SUCCESS(JwtUtil.GenerateJwtToken(JwtUtil.AddClaims(loginUser)));
}
}
}
@@ -1,8 +1,10 @@
using Microsoft.AspNetCore.Mvc;
using ZR.Admin.WebApi.Filters;
using ZR.Model.System;
using ZR.Model.System.Dto;
using ZR.Service.System.IService;
using ZR.ServiceCore.Model;
using ZR.ServiceCore.Model.Dto;
using ZR.ServiceCore.Services.IService;
namespace ZR.Admin.WebApi.Controllers.System
{
@@ -28,28 +30,16 @@ namespace ZR.Admin.WebApi.Controllers.System
this.sysRoleMenuService = sysRoleMenuService;
}
/// <summary>
/// 获取菜单树列表
/// </summary>
/// <returns></returns>
[ActionPermissionFilter(Permission = "system:menu:list")]
[HttpGet("treelist")]
public IActionResult TreeMenuList([FromQuery] MenuQueryDto menu)
{
long userId = HttpContext.GetUId();
return SUCCESS(sysMenuService.SelectTreeMenuList(menu, userId), "yyyy-MM-dd HH:mm:ss");
}
/// <summary>
/// 获取菜单列表
/// </summary>
/// <returns></returns>
[ActionPermissionFilter(Permission = "system:menu:list")]
[HttpGet("list")]
public IActionResult MenuList([FromQuery] MenuQueryDto menu)
public IActionResult TreeMenuList([FromQuery] MenuQueryDto menu)
{
long userId = HttpContext.GetUId();
return SUCCESS(sysMenuService.SelectMenuList(menu, userId), "yyyy-MM-dd HH:mm:ss");
return SUCCESS(sysMenuService.SelectTreeMenuList(menu, userId), "yyyy-MM-dd HH:mm:ss");
}
/// <summary>
@@ -125,7 +115,8 @@ namespace ZR.Admin.WebApi.Controllers.System
{
return ToResponse(ApiResult.Error($"修改菜单'{modal.MenuName}'失败,上级菜单不能选择自己"));
}
modal.Update_by = HttpContext.GetName();
modal.Update_by = HttpContext.GetUId();
modal.Update_name = HttpContext.GetNickName();
long result = sysMenuService.EditMenu(modal);
return ToResponse(result);
@@ -157,7 +148,8 @@ namespace ZR.Admin.WebApi.Controllers.System
return ToResponse(ApiResult.Error($"新增菜单'{menu.MenuName}'失败,地址必须以http(s)://开头"));
}
menu.Create_by = HttpContext.GetName();
menu.Create_by = HttpContext.GetUId();
menu.Create_name = HttpContext.GetNickName();
long result = sysMenuService.AddMenu(menu);
return ToResponse(result);
@@ -1,10 +1,15 @@
using Microsoft.AspNetCore.Mvc;
using System.Net;
using System.Net.Sockets;
using Microsoft.AspNetCore.SignalR;
using Microsoft.AspNetCore.SignalR.Client;
using NLog;
using SqlSugar;
using ZR.Admin.WebApi.Filters;
using ZR.Model;
using ZR.Model.System;
using ZR.Model.System.Dto;
using ZR.Service.System.IService;
using ZR.ServiceCore.Model;
using ZR.ServiceCore.Model.Dto;
using ZR.ServiceCore.Services.IService;
using ZR.ServiceCore.Signalr;
namespace ZR.Admin.WebApi.Controllers.System
@@ -20,13 +25,17 @@ namespace ZR.Admin.WebApi.Controllers.System
/// <summary>
/// 通知公告表接口
/// </summary>
private readonly ISysNoticeService _SysNoticeService;
private readonly ISysNoticeService _sysNoticeService;
private readonly IHubContext<MessageHub> _hubContext;
public SysNoticeController(ISysNoticeService SysNoticeService, IHubContext<MessageHub> hubContext)
private readonly ISysNoticeLogService _sysNoticeLogService;
private readonly IWebHostEnvironment _webHostEnvironment;
private readonly Logger Logger = LogManager.GetCurrentClassLogger();
public SysNoticeController(ISysNoticeService sysNoticeService, IHubContext<MessageHub> hubContext, ISysNoticeLogService sysNoticeLogService, IWebHostEnvironment webHostEnvironment)
{
_SysNoticeService = SysNoticeService;
_sysNoticeService = sysNoticeService;
_hubContext = hubContext;
_sysNoticeLogService = sysNoticeLogService;
_webHostEnvironment = webHostEnvironment;
}
/// <summary>
@@ -39,7 +48,7 @@ namespace ZR.Admin.WebApi.Controllers.System
var predicate = Expressionable.Create<SysNotice>();
predicate = predicate.And(m => m.Status == 0);
var response = _SysNoticeService.GetPages(predicate.ToExpression(), parm);
var response = _sysNoticeService.GetPages(predicate.ToExpression(), parm);
return SUCCESS(response);
}
@@ -51,19 +60,19 @@ namespace ZR.Admin.WebApi.Controllers.System
[ActionPermissionFilter(Permission = "system:notice:list")]
public IActionResult QuerySysNotice([FromQuery] SysNoticeQueryDto parm)
{
PagedInfo<SysNotice> response = _SysNoticeService.GetPageList(parm);
PagedInfo<SysNotice> response = _sysNoticeService.GetPageList(parm);
return SUCCESS(response);
}
/// <summary>
/// 查询通知公告表详情
/// </summary>
/// <param name="NoticeId"></param>
/// <param name="noticeId"></param>
/// <returns></returns>
[HttpGet("{NoticeId}")]
public IActionResult GetSysNotice(int NoticeId)
[HttpGet("{noticeId}")]
public IActionResult GetSysNotice(long noticeId)
{
var response = _SysNoticeService.GetFirst(x => x.NoticeId == NoticeId);
var response = _sysNoticeService.GetFirst(x => x.NoticeId == noticeId);
return SUCCESS(response);
}
@@ -75,21 +84,41 @@ namespace ZR.Admin.WebApi.Controllers.System
[HttpPost]
[ActionPermissionFilter(Permission = "system:notice:add")]
[Log(Title = "发布通告", BusinessType = BusinessType.INSERT)]
public IActionResult AddSysNotice([FromBody] SysNoticeDto parm)
public async Task<IActionResult> AddSysNotice([FromBody] SysNoticeDto parm)
{
var modal = parm.Adapt<SysNotice>().ToCreate(HttpContext);
modal.Create_by = HttpContext.GetUId();
modal.Create_name = HttpContext.GetNickName();
modal.Create_time = DateTime.Now;
int result = _SysNoticeService.Insert(modal, it => new
// int result = _SysNoticeService.Insert(modal, it => new
// {
// it.NoticeTitle,
// it.NoticeType,
// it.NoticeContent,
// it.Status,
// it.Remark,
// it.Create_by,
// it.Create_time
// });
var result = await _sysNoticeService
.Insertable(modal)
.ExecuteReturnSnowflakeIdAsync();
var scheme = HttpContext.Request.Scheme + "://";
var serverIP = HttpContext.Request.Host.Value;
if (_webHostEnvironment.IsProduction())
{
it.NoticeTitle,
it.NoticeType,
it.NoticeContent,
it.Status,
it.Remark,
it.Create_by,
it.Create_time
});
var host = await Dns.GetHostEntryAsync(Dns.GetHostName());
var ip = host.AddressList
.FirstOrDefault(it => it.AddressFamily == AddressFamily.InterNetwork);
serverIP = ip + ":" + Request.HttpContext.Connection.LocalPort;//获取服务器IP
}
var url = scheme + serverIP;
var hubConnection = new HubConnectionBuilder().WithUrl(url + "/msghub").Build();
await hubConnection.StartAsync();
await hubConnection.InvokeAsync("SendNoticeToOnlineUsers", result, true);
await hubConnection.StopAsync();
return SUCCESS(result);
}
@@ -100,37 +129,56 @@ namespace ZR.Admin.WebApi.Controllers.System
[HttpPut]
[ActionPermissionFilter(Permission = "system:notice:update")]
[Log(Title = "修改公告", BusinessType = BusinessType.UPDATE)]
public IActionResult UpdateSysNotice([FromBody] SysNoticeDto parm)
public async Task<IActionResult> UpdateSysNotice([FromBody] SysNoticeDto parm)
{
var model = parm.Adapt<SysNotice>().ToUpdate(HttpContext);
model.Update_by = HttpContext.GetName();
var response = _SysNoticeService.Update(w => w.NoticeId == model.NoticeId, it => new SysNotice()
var config = new TypeAdapterConfig();
config.ForType<SysNoticeDto, SysNotice>()
.Map(dest => dest.NoticeId, src => src.NoticeId.ParseToLong());
var model = parm.Adapt<SysNotice>(config).ToUpdate(HttpContext);
var nowDate = DateTime.Now;
var response = _sysNoticeService.Update(w => w.NoticeId == model.NoticeId, it => new SysNotice()
{
NoticeTitle = model.NoticeTitle,
NoticeType = model.NoticeType,
NoticeContent = model.NoticeContent,
Status = model.Status,
Remark = model.Remark,
Update_by = HttpContext.GetName(),
Update_time = DateTime.Now
Update_by = HttpContext.GetUId(),
Update_name = HttpContext.GetNickName(),
Update_time = nowDate,
Create_time = nowDate
});
var scheme = HttpContext.Request.Scheme + "://";
var serverIP = HttpContext.Request.Host.Value;
if (_webHostEnvironment.IsProduction())
{
var host = await Dns.GetHostEntryAsync(Dns.GetHostName());
var ip = host.AddressList
.FirstOrDefault(it => it.AddressFamily == AddressFamily.InterNetwork);
serverIP = ip + ":" + Request.HttpContext.Connection.LocalPort;//获取服务器IP
}
var url = scheme + serverIP;
var hubConnection = new HubConnectionBuilder().WithUrl(url + "/msghub").Build();
await hubConnection.StartAsync();
await hubConnection.InvokeAsync("SendNoticeToOnlineUsers", model.NoticeId, true);
await hubConnection.StopAsync();
return SUCCESS(response);
}
/// <summary>
/// 发送通知公告表
/// </summary>
/// <returns></returns>
[HttpPut("send/{NoticeId}")]
[HttpPut("send/{noticeId}")]
[ActionPermissionFilter(Permission = "system:notice:update")]
[Log(Title = "发送通知公告", BusinessType = BusinessType.OTHER)]
public IActionResult SendNotice(int NoticeId = 0)
public IActionResult SendNotice(long noticeId = 0)
{
if (NoticeId <= 0)
if (noticeId <= 0)
{
throw new CustomException("请求实体不能为空");
}
var response = _SysNoticeService.GetFirst(x => x.NoticeId == NoticeId);
var response = _sysNoticeService.GetFirst(x => x.NoticeId == noticeId);
if (response != null && response.Status == 0)
{
_hubContext.Clients.All.SendAsync(HubsConstant.ReceiveNotice, response.NoticeTitle, response.NoticeContent);
@@ -145,13 +193,30 @@ namespace ZR.Admin.WebApi.Controllers.System
[HttpDelete("{ids}")]
[ActionPermissionFilter(Permission = "system:notice:delete")]
[Log(Title = "通知公告", BusinessType = BusinessType.DELETE)]
public IActionResult DeleteSysNotice(string ids)
public async Task<IActionResult> DeleteSysNotice(string ids)
{
int[] idsArr = Tools.SpitIntArrary(ids);
var idsArr = Tools.SpitLongArrary(ids);
if (idsArr.Length <= 0) { return ToResponse(ApiResult.Error($"删除失败Id 不能为空")); }
var response = _SysNoticeService.Delete(idsArr);
var response = _sysNoticeService.Delete(idsArr);
await _sysNoticeLogService.Deleteable()
.Where(it => idsArr.Contains(it.NoticeId))
.ExecuteCommandAsync();
var scheme = HttpContext.Request.Scheme + "://";
var serverIP = HttpContext.Request.Host.Value;
if (_webHostEnvironment.IsProduction())
{
var host = await Dns.GetHostEntryAsync(Dns.GetHostName());
var ip = host.AddressList
.FirstOrDefault(it => it.AddressFamily == AddressFamily.InterNetwork);
serverIP = ip + ":" + Request.HttpContext.Connection.LocalPort;//获取服务器IP
}
var url = scheme + serverIP;
var hubConnection = new HubConnectionBuilder().WithUrl(url + "/msghub").Build();
await hubConnection.StartAsync();
await hubConnection.InvokeAsync("SendNoticeToOnlineUsers", null, false);
await hubConnection.StopAsync();
return SUCCESS(response);
}
}
@@ -3,7 +3,8 @@ using SqlSugar;
using ZR.Admin.WebApi.Filters;
using ZR.Model;
using ZR.Model.System;
using ZR.Service.System.IService;
using ZR.ServiceCore.Model;
namespace ZR.Admin.WebApi.Controllers.System
{
@@ -1,8 +1,9 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;
using ZR.Admin.WebApi.Filters;
using ZR.Model.System;
using ZR.Model.System.Dto;
using ZR.Service.System.IService;
using ZR.ServiceCore.Model;
using ZR.ServiceCore.Model.Dto;
using ZR.ServiceCore.Services.IService;
namespace ZR.Admin.WebApi.Controllers.System
{
@@ -20,6 +21,7 @@ namespace ZR.Admin.WebApi.Controllers.System
private readonly ISysDeptService DeptService;
private readonly ISysFileService FileService;
private IWebHostEnvironment hostEnvironment;
private readonly OptionsSetting _optionsSetting;
public SysProfileController(
ISysUserService userService,
@@ -27,7 +29,8 @@ namespace ZR.Admin.WebApi.Controllers.System
ISysUserPostService postService,
ISysDeptService deptService,
ISysFileService sysFileService,
IWebHostEnvironment hostEnvironment)
IWebHostEnvironment hostEnvironment,
IOptions<OptionsSetting> options)
{
UserService = userService;
RoleService = roleService;
@@ -35,6 +38,7 @@ namespace ZR.Admin.WebApi.Controllers.System
DeptService = deptService;
FileService = sysFileService;
this.hostEnvironment = hostEnvironment;
_optionsSetting = options.Value;
}
/// <summary>
@@ -119,7 +123,9 @@ namespace ZR.Admin.WebApi.Controllers.System
long userId = HttpContext.GetUId();
if (formFile == null) throw new CustomException("请选择文件");
SysFile file = await FileService.SaveFileToLocal(hostEnvironment.WebRootPath, "", "avatar", HttpContext.GetName(), formFile);
var file = await FileService.SaveFileToLocal(hostEnvironment.WebRootPath, "", "avatar",
HttpContext.GetUId(), HttpContext.GetName(), formFile, _optionsSetting.Upload.UploadUrl);
UserService.UpdatePhoto(new SysUser() { Avatar = file.AccessUrl, UserId = userId });
return SUCCESS(new { imgUrl = file.AccessUrl });
@@ -2,8 +2,10 @@
using ZR.Admin.WebApi.Filters;
using ZR.Model;
using ZR.Model.System;
using ZR.Model.System.Dto;
using ZR.Service.System.IService;
using ZR.ServiceCore.Model;
using ZR.ServiceCore.Model.Dto;
using ZR.ServiceCore.Services.IService;
namespace ZR.Admin.WebApi.Controllers.System
{
@@ -70,7 +72,8 @@ namespace ZR.Admin.WebApi.Controllers.System
return ToResponse(ApiResult.Error((int)ResultCode.CUSTOM_ERROR, $"新增角色'{sysRoleDto.RoleName}'失败,角色权限已存在"));
}
sysRoleDto.Create_by = HttpContext.GetName();
sysRoleDto.Create_by = HttpContext.GetUId();
sysRoleDto.Create_name = HttpContext.GetNickName();
long roleId = sysRoleService.InsertRole(sysRoleDto);
return ToResponse(roleId);
@@ -101,7 +104,8 @@ namespace ZR.Admin.WebApi.Controllers.System
return ToResponse(ApiResult.Error($"编辑角色'{sysRoleDto.RoleName}'失败,角色权限已存在"));
}
}
sysRoleDto.Update_by = HttpContext.GetName();
sysRoleDto.Update_by = HttpContext.GetUId();
sysRoleDto.Update_name = HttpContext.GetNickName();
int upResult = sysRoleService.UpdateRole(sysRoleDto);
if (upResult > 0)
{
@@ -122,7 +126,8 @@ namespace ZR.Admin.WebApi.Controllers.System
{
if (sysRoleDto == null || sysRoleDto.RoleId <= 0) return ToResponse(ApiResult.Error(101, "请求参数错误"));
SysRole sysRole = sysRoleDto.Adapt<SysRole>();
sysRoleDto.Create_by = HttpContext.GetName();
sysRoleDto.Create_by = HttpContext.GetUId();
sysRoleDto.Create_name = HttpContext.GetNickName();
sysRoleService.CheckRoleAllowed(sysRole);
bool result = sysRoleService.AuthDataScope(sysRoleDto);
@@ -168,7 +173,7 @@ namespace ZR.Admin.WebApi.Controllers.System
/// <returns></returns>
[Log(BusinessType = BusinessType.EXPORT, IsSaveResponseData = false, Title = "角色导出")]
[HttpGet("export")]
[ActionPermissionFilter(Permission = "system:role:export")]
//[ActionPermissionFilter(Permission = "system:role:export")]
public IActionResult Export()
{
var list = sysRoleService.SelectRoleAll();
@@ -184,7 +189,7 @@ namespace ZR.Admin.WebApi.Controllers.System
/// <returns></returns>
[Log(BusinessType = BusinessType.EXPORT, IsSaveResponseData = false, Title = "角色菜单导出")]
[HttpGet("exportRoleMenu")]
[ActionPermissionFilter(Permission = "system:role:export")]
[AllowAnonymous]
public IActionResult ExportRoleMenu(int roleId)
{
MenuQueryDto dto = new() { Status = "0", MenuTypeIds = "M,C,F" };
@@ -4,7 +4,9 @@ using SqlSugar;
using ZR.Admin.WebApi.Filters;
using ZR.Model;
using ZR.Model.System;
using ZR.Model.System.Dto;
using ZR.Service.System.IService;
using ZR.ServiceCore.Model;
using ZR.ServiceCore.Model.Dto;
namespace ZR.Admin.WebApi.Controllers.System
{
@@ -78,20 +80,22 @@ namespace ZR.Admin.WebApi.Controllers.System
/// <summary>
/// 添加用户
/// </summary>
/// <param name="parm"></param>
/// <param name="user"></param>
/// <returns></returns>
[HttpPost("add")]
[HttpPost("edit")]
[Log(Title = "用户管理", BusinessType = BusinessType.INSERT)]
[ActionPermissionFilter(Permission = "system:user:add")]
public IActionResult AddUser([FromBody] SysUserDto parm)
public IActionResult AddUser([FromBody] SysUser user)
{
var user = parm.Adapt<SysUser>().ToCreate(HttpContext);
if (user == null) { return ToResponse(ApiResult.Error(101, "请求参数错误")); }
if (UserConstants.NOT_UNIQUE.Equals(UserService.CheckUserNameUnique(user.UserName)))
{
return ToResponse(ApiResult.Error($"新增用户 '{user.UserName}'失败,登录账号已存在"));
}
user.Create_by = HttpContext.GetUId();
user.Create_name = HttpContext.GetNickName();
user.Create_time = DateTime.Now;
user.Password = NETCore.Encrypt.EncryptProvider.Md5(user.Password);
return SUCCESS(UserService.InsertUser(user));
@@ -100,16 +104,17 @@ namespace ZR.Admin.WebApi.Controllers.System
/// <summary>
/// 修改用户
/// </summary>
/// <param name="parm"></param>
/// <param name="user"></param>
/// <returns></returns>
[HttpPut("edit")]
[Log(Title = "用户管理", BusinessType = BusinessType.UPDATE)]
[ActionPermissionFilter(Permission = "system:user:edit")]
public IActionResult UpdateUser([FromBody] SysUserDto parm)
public IActionResult UpdateUser([FromBody] SysUser user)
{
var user = parm.Adapt<SysUser>().ToUpdate(HttpContext);
if (user == null || user.UserId <= 0) { return ToResponse(ApiResult.Error(101, "请求参数错误")); }
user.Update_by = HttpContext.GetUId();
user.Update_name = HttpContext.GetNickName();
int upResult = UserService.UpdateUser(user);
return ToResponse(upResult);
@@ -1,7 +1,7 @@
using Microsoft.AspNetCore.Mvc;
using ZR.Admin.WebApi.Filters;
using ZR.Model.System.Dto;
using ZR.Service.System.IService;
using ZR.ServiceCore.Model.Dto;
namespace ZR.Admin.WebApi.Controllers.System
{
@@ -3,8 +3,9 @@ using Quartz;
using SqlSugar;
using ZR.Admin.WebApi.Filters;
using ZR.Model.System;
using ZR.Model.System.Dto;
using ZR.Service.System.IService;
using ZR.ServiceCore.Model;
using ZR.ServiceCore.Model.Dto;
using ZR.Tasks;
namespace ZR.Admin.WebApi.Controllers
@@ -87,7 +88,8 @@ namespace ZR.Admin.WebApi.Controllers
}
//从 Dto 映射到 实体
var tasksQz = parm.Adapt<SysTasks>().ToCreate(HttpContext);
tasksQz.Create_by = HttpContext.GetName();
tasksQz.Create_by = HttpContext.GetUId();
tasksQz.Create_name = HttpContext.GetNickName();
tasksQz.ID = SnowFlakeSingle.Instance.NextId().ToString();
return SUCCESS(_tasksQzService.AddTasks(tasksQz));
@@ -126,7 +128,8 @@ namespace ZR.Admin.WebApi.Controllers
throw new CustomException($"该任务正在运行中,请先停止在更新");
}
var model = parm.Adapt<SysTasks>();
model.Update_by = HttpContextExtension.GetName(HttpContext);
model.Update_by = HttpContext.GetUId();
model.Update_name = HttpContext.GetNickName();
int response = _tasksQzService.UpdateTasks(model);
if (response > 0)
{
@@ -3,8 +3,9 @@ using SqlSugar;
using ZR.Admin.WebApi.Filters;
using ZR.Model;
using ZR.Model.System;
using ZR.Model.System.Dto;
using ZR.Service.System.IService;
using ZR.ServiceCore.Model;
using ZR.ServiceCore.Model.Dto;
namespace ZR.Admin.WebApi.Controllers.System
{
@@ -0,0 +1,195 @@
using AspNetCoreRateLimit;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;
using ZR.Admin.WebApi.Filters;
using ZR.Model;
using ZR.ServiceCore.Model;
using ZR.ServiceCore.Services.IService;
using IpRateLimitPolicy = ZR.ServiceCore.Model.IpRateLimitPolicy;
namespace ZR.Admin.WebApi.Controllers.System.monitor;
[Verify]
[Route("ip/route/limit")]
public class IpRateLimitController : BaseController
{
private readonly IpRateLimitOptions _options;
private readonly IIpPolicyStore _ipPolicyStore;
private readonly IIpRateLimitPolicyService _ipRateLimitPolicyService;
private readonly IRateLimitRuleService _rateLimitRuleService;
private readonly IIpRateLimitLogService _ipRateLimitLogService;
public IpRateLimitController(IOptions<IpRateLimitOptions> optionsAccessor, IIpPolicyStore ipPolicyStore,
IIpRateLimitPolicyService ipRateLimitPolicyService, IRateLimitRuleService rateLimitRuleService,
IIpRateLimitLogService ipRateLimitLogService)
{
_options = optionsAccessor.Value;
_ipPolicyStore = ipPolicyStore;
_ipRateLimitPolicyService = ipRateLimitPolicyService;
_rateLimitRuleService = rateLimitRuleService;
_ipRateLimitLogService = ipRateLimitLogService;
}
/// <summary>
/// 获取限制规则
/// </summary>
/// <returns></returns>
[HttpGet("getIpRateLimitPolicyPage")]
public async Task<IActionResult> GetIpRateLimitPolicyPage([FromQuery] IpRateLimitPolicy ipRateLimitPolicy,
PagerInfo pager)
{
var page = await _ipRateLimitPolicyService.SelectIpRateLimitPolicyPageAsync(ipRateLimitPolicy, pager);
return SUCCESS(page);
}
[HttpPost("addIpRateLimitPolicy")]
public async Task<IActionResult> AddIpRateLimitPolicy([FromBody] IpRateLimitPolicy ipRateLimitPolicy)
{
var isExist = await _ipRateLimitPolicyService.Queryable()
.Where(it => it.Ip == ipRateLimitPolicy.Ip)
.AnyAsync();
if (isExist) throw new CustomException("该IP已存在");
var res = await _ipRateLimitPolicyService.InsertNav(ipRateLimitPolicy)
.Include(it => it.Rules)
.ExecuteCommandAsync();
return SUCCESS(res);
}
[HttpPut("updateIpRateLimitPolicy")]
public async Task<IActionResult> UpdateIpRateLimitPolicy(
[FromBody] IpRateLimitPolicy ipRateLimitPolicy)
{
var isEnable = await _ipRateLimitPolicyService
.Queryable()
.Where(it => it.Id == ipRateLimitPolicy.Id
&& it.Flag == '1')
.AnyAsync();
var res = await _ipRateLimitPolicyService.UpdateNav(ipRateLimitPolicy)
.Include(it => it.Rules)
.ExecuteCommandAsync();
if (!isEnable) return SUCCESS(res);
{
await _ipPolicyStore.RemoveAsync(_options.IpPolicyPrefix);
var ipRateLimitPolicies = _ipRateLimitPolicyService.Queryable()
.Includes(it => it.Rules.Where(r => r.Flag == '1').ToList())
.Where(it => it.Flag == '1')
.ToListAsync()
.GetAwaiter().GetResult()
.Adapt<List<AspNetCoreRateLimit.IpRateLimitPolicy>>();
await _ipPolicyStore.SeedAsync();
var pol = await _ipPolicyStore.GetAsync(_options.IpPolicyPrefix);
pol.IpRules.AddRange(ipRateLimitPolicies);
await _ipPolicyStore.SetAsync(_options.IpPolicyPrefix, pol);
}
return SUCCESS(res);
}
[HttpPatch("enableIpRateLimitPolicy/{id}")]
public async Task<IActionResult> EnableIpRateLimitPolicy([FromRoute] long id)
{
var isEnable = await _ipRateLimitPolicyService
.Queryable()
.Where(it => it.Id == id
&& it.Flag == '1')
.AnyAsync();
if (isEnable)
{
throw new CustomException("已启用,无法再次启用");
}
await _ipRateLimitPolicyService.Updateable(new IpRateLimitPolicy
{
Id = id,
Flag = '1'
}).UpdateColumns(it => it.Flag)
.ExecuteCommandAsync();
var ipRateLimitPolicy = await _ipRateLimitPolicyService.Queryable()
.Includes(it => it.Rules.Where(r => r.Flag == '1').ToList())
.Where(it => it.Id == id)
.SingleAsync();
var pol = await _ipPolicyStore.GetAsync(_options.IpPolicyPrefix);
pol.IpRules.Add(ipRateLimitPolicy.Adapt<AspNetCoreRateLimit.IpRateLimitPolicy>());
await _ipPolicyStore.SetAsync(_options.IpPolicyPrefix, pol);
return SUCCESS('1');
}
[HttpPatch("disableIpRateLimitPolicy/{id}")]
public async Task<IActionResult> DisableIpRateLimitPolicy([FromRoute] long id)
{
var isEnable = await _ipRateLimitPolicyService
.Queryable()
.Where(it => it.Id == id
&& it.Flag == '1')
.AnyAsync();
if (!isEnable)
{
throw new CustomException("已禁用,无法再次禁用");
}
await _ipRateLimitPolicyService.Updateable(new IpRateLimitPolicy
{
Id = id,
Flag = '0'
}).UpdateColumns(it => it.Flag)
.ExecuteCommandAsync();
var ipRateLimitPolicies = _ipRateLimitPolicyService.Queryable()
.Includes(it => it.Rules.Where(r => r.Flag == '1').ToList())
.Where(it => it.Flag == '1')
.ToListAsync()
.GetAwaiter().GetResult()
.Adapt<List<AspNetCoreRateLimit.IpRateLimitPolicy>>();
await _ipPolicyStore.RemoveAsync(_options.IpPolicyPrefix);
await _ipPolicyStore.SeedAsync();
var pol = await _ipPolicyStore.GetAsync(_options.IpPolicyPrefix);
pol.IpRules.AddRange(ipRateLimitPolicies);
await _ipPolicyStore.SetAsync(_options.IpPolicyPrefix, pol);
return SUCCESS('0');
}
[HttpDelete("deleteIpRateLimitPolicy/{id}")]
public async Task DeleteIpRateLimitPolicyAsync([FromRoute] long id)
{
var isEnable = await _ipRateLimitPolicyService
.Queryable()
.Where(it => it.Id == id
&& it.Flag == '1')
.AnyAsync();
await _ipRateLimitPolicyService
.DeleteNav(it => it.Id == id)
.Include(it => it.Rules)
.ExecuteCommandAsync();
if (isEnable)
{
var ipRateLimitPolicies = _ipRateLimitPolicyService.Queryable()
.Includes(it => it.Rules.Where(r => r.Flag == '1').ToList())
.Where(it => it.Flag == '1')
.ToListAsync()
.GetAwaiter().GetResult()
.Adapt<List<AspNetCoreRateLimit.IpRateLimitPolicy>>();
await _ipPolicyStore.RemoveAsync(_options.IpPolicyPrefix);
await _ipPolicyStore.SeedAsync();
var pol = await _ipPolicyStore.GetAsync(_options.IpPolicyPrefix);
pol.IpRules.AddRange(ipRateLimitPolicies);
await _ipPolicyStore.SetAsync(_options.IpPolicyPrefix, pol);
}
}
[HttpGet("getIpRateLimitLogPage")]
public async Task<IActionResult> GetIpRateLimitLogPage([FromQuery] IpRateLimitLog ipRateLimitLog, PagerInfo pager)
{
return SUCCESS(await _ipRateLimitLogService.SelectIpRateLimitLogPageAsync(ipRateLimitLog, pager));
}
[HttpGet("get")]
public async Task<IpRateLimitPolicies> Get()
{
return await _ipPolicyStore.GetAsync(_options.IpPolicyPrefix);
}
[HttpGet("checkIp/{ip}")]
public async Task<IActionResult> CheckIp(string ip)
{
var res = await _ipRateLimitPolicyService.Queryable()
.Where(it => it.Ip == ip)
.AnyAsync();
return SUCCESS(res);
}
}
@@ -2,8 +2,9 @@ using Infrastructure.Extensions;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;
using System.Diagnostics;
using System.Net;
using System.Net.Sockets;
using System.Runtime.InteropServices;
using ZR.Admin.WebApi.Filters;
namespace ZR.Admin.WebApi.Controllers.monitor
{
@@ -11,7 +12,6 @@ namespace ZR.Admin.WebApi.Controllers.monitor
/// 系统监控
/// </summary>
[ApiExplorerSettings(GroupName = "sys")]
[Verify]
public class MonitorController : BaseController
{
private OptionsSetting Options;
@@ -50,7 +50,11 @@ namespace ZR.Admin.WebApi.Controllers.monitor
string appRAM = ((double)Process.GetCurrentProcess().WorkingSet64 / 1048576).ToString("N2") + " MB";
string startTime = Process.GetCurrentProcess().StartTime.ToString("yyyy-MM-dd HH:mm:ss");
string sysRunTime = ComputerHelper.GetRunTime();
string serverIP = Request.HttpContext.Connection.LocalIpAddress.MapToIPv4().ToString() + ":" + Request.HttpContext.Connection.LocalPort;//获取服务器IP
// string serverIP = Request.HttpContext.Connection.LocalIpAddress.MapToIPv4().ToString() + ":" + Request.HttpContext.Connection.LocalPort;//获取服务器IP
var host = Dns.GetHostEntry(Dns.GetHostName());
var ip = host.AddressList
.FirstOrDefault(it => it.AddressFamily == AddressFamily.InterNetwork);
var serverIP = ip + ":" + Request.HttpContext.Connection.LocalPort;//获取服务器IP
var programStartTime = Process.GetCurrentProcess().StartTime;
string programRunTime = DateTimeHelper.FormatTime((DateTime.Now - programStartTime).TotalMilliseconds.ToString().Split('.')[0].ParseToLong());
@@ -1,77 +0,0 @@
using Microsoft.AspNetCore.Mvc;
using ZR.Admin.WebApi.Filters;
using ZR.Model.Dto;
using ZR.ServiceCore.Services;
//创建时间:2023-11-19
namespace ZR.Admin.WebApi.Controllers.System.monitor
{
/// <summary>
/// 短信验证码记录
/// </summary>
[Verify]
[Route("system/SmscodeLog")]
[ApiExplorerSettings(GroupName = "sys")]
public class SmsCodeLogController : BaseController
{
/// <summary>
/// 短信验证码记录接口
/// </summary>
private readonly ISmsCodeLogService _SmscodeLogService;
public SmsCodeLogController(ISmsCodeLogService SmscodeLogService)
{
_SmscodeLogService = SmscodeLogService;
}
/// <summary>
/// 查询短信验证码记录列表
/// </summary>
/// <param name="parm"></param>
/// <returns></returns>
[HttpGet("list")]
[ActionPermissionFilter(Permission = "smscodelog:list")]
public IActionResult QuerySmscodeLog([FromQuery] SmscodeLogQueryDto parm)
{
var response = _SmscodeLogService.GetList(parm);
return SUCCESS(response);
}
/// <summary>
/// 删除短信验证码记录
/// </summary>
/// <returns></returns>
[HttpDelete("{ids}")]
[ActionPermissionFilter(Permission = "smscodelog:delete")]
[Log(Title = "短信验证码记录", BusinessType = BusinessType.DELETE)]
public IActionResult DeleteSmscodeLog(string ids)
{
long[] idsArr = Tools.SpitLongArrary(ids);
if (idsArr.Length <= 0) { return ToResponse(ApiResult.Error($"删除失败Id 不能为空")); }
var response = _SmscodeLogService.Delete(idsArr);
return ToResponse(response);
}
/// <summary>
/// 导出短信验证码记录
/// </summary>
/// <returns></returns>
[Log(Title = "短信验证码记录", BusinessType = BusinessType.EXPORT, IsSaveResponseData = false)]
[HttpGet("export")]
[ActionPermissionFilter(Permission = "smscodelog:export")]
public IActionResult Export([FromQuery] SmscodeLogQueryDto parm)
{
parm.PageNum = 1;
parm.PageSize = 100000;
var list = _SmscodeLogService.GetList(parm).Result;
if (list == null || list.Count <= 0)
{
return ToResponse(ResultCode.FAIL, "没有要导出的数据");
}
var result = ExportExcelMini(list, "短信验证码记录", "短信验证码记录");
return ExportExcel(result.Item2, result.Item1);
}
}
}
@@ -1,7 +1,7 @@
using Microsoft.AspNetCore.Mvc;
using ZR.Admin.WebApi.Filters;
using ZR.Model.System.Dto;
using ZR.Service.System.IService;
using ZR.ServiceCore.Model.Dto;
//创建时间:2023-08-17
namespace ZR.Admin.WebApi.Controllers
@@ -4,7 +4,8 @@ using ZR.Admin.WebApi.Extensions;
using ZR.Admin.WebApi.Filters;
using ZR.Model;
using ZR.Model.System;
using ZR.Service.System.IService;
using ZR.ServiceCore.Model;
namespace ZR.Admin.WebApi.Controllers.monitor
{
@@ -1,7 +1,8 @@
using Microsoft.AspNetCore.Mvc;
using ZR.Admin.WebApi.Extensions;
using ZR.Admin.WebApi.Filters;
using ZR.Model.System.Dto;
using ZR.Service.System.IService;
using ZR.ServiceCore.Model.Dto;
namespace ZR.Admin.WebApi.Controllers.monitor
{
@@ -14,10 +15,12 @@ namespace ZR.Admin.WebApi.Controllers.monitor
public class SysOperlogController : BaseController
{
private ISysOperLogService sysOperLogService;
private IWebHostEnvironment WebHostEnvironment;
public SysOperlogController(ISysOperLogService sysOperLogService)
public SysOperlogController(ISysOperLogService sysOperLogService, IWebHostEnvironment hostEnvironment)
{
this.sysOperLogService = sysOperLogService;
WebHostEnvironment = hostEnvironment;
}
/// <summary>
@@ -2,7 +2,7 @@
using Microsoft.AspNetCore.SignalR;
using ZR.Admin.WebApi.Filters;
using ZR.Model;
using ZR.Model.System.Dto;
using ZR.ServiceCore.Model.Dto;
using ZR.ServiceCore.Signalr;
namespace ZR.Admin.WebApi.Controllers.monitor
@@ -30,11 +30,11 @@ namespace ZR.Admin.WebApi.Controllers.monitor
[HttpGet("list")]
public IActionResult Index([FromQuery] PagerInfo parm)
{
var result = MessageHub.onlineClients
var result = MessageHub.OnlineClients
.OrderByDescending(f => f.LoginTime)
.Skip(parm.PageNum - 1).Take(parm.PageSize);
return SUCCESS(new { result, totalNum = MessageHub.onlineClients.Count });
return SUCCESS(new { result, totalNum = MessageHub.OnlineClients.Count });
}
/// <summary>
+29 -16
View File
@@ -1,21 +1,34 @@
FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build
#创建 /app文件夹
FROM mcr.microsoft.com/dotnet/aspnet:7.0 AS base
WORKDIR /app
#创建挂载目录,用于将程序部署在服务器本地
#VOLUME /app
#设置docker容器对外暴露端口
EXPOSE 8888
VOLUME /app/logs
#COPY bin/Release/net5.0/publish/ app/
COPY . app/
#EXPOSE 443
VOLUME /app/adminlogs
VOLUME /app/wwwroot
#设置容器内的时区,如果不设置,默认时区是标准时间比北京时间晚8个小时
RUN echo "Asia/shanghai" > /etc/timezone
RUN cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build
WORKDIR /src
COPY ["ZR.Admin.WebApi/ZR.Admin.WebApi.csproj", "ZR.Admin.WebApi/"]
COPY ["ZR.CodeGenerator/ZR.CodeGenerator.csproj", "ZR.CodeGenerator/"]
COPY ["Infrastructure/ZR.Infrastructure.csproj", "Infrastructure/"]
COPY ["ZR.Common/ZR.Common.csproj", "ZR.Common/"]
COPY ["ZR.ServiceCore/ZR.ServiceCore.csproj", "ZR.ServiceCore/"]
COPY ["ZR.Repository/ZR.Repository.csproj", "ZR.Repository/"]
COPY ["ZR.Model/ZR.Model.csproj", "ZR.Model/"]
COPY ["ZR.Service/ZR.Service.csproj", "ZR.Service/"]
COPY ["ZR.Tasks/ZR.Tasks.csproj", "ZR.Tasks/"]
COPY ["ZR.Admin.Grpc/ZR.Admin.Grpc.csproj", "ZR.Admin.Grpc/"]
RUN dotnet restore "ZR.Admin.WebApi/ZR.Admin.WebApi.csproj"
COPY . .
WORKDIR "/src/ZR.Admin.WebApi"
RUN dotnet build "ZR.Admin.WebApi.csproj" -c Release -o /app/build
# 复制发布文件到工作目录
#COPY . app/
FROM build AS publish
RUN dotnet publish "ZR.Admin.WebApi.csproj" -c Release -o /app/publish /p:UseAppHost=false
FROM base AS final
WORKDIR /app
#等价于 dotnet ZR.Admin.WebApi.dll,如果不指定启动端口默认在docker里面启动端口是80端口
ENTRYPOINT ["dotnet", "ZR.Admin.WebApi.dll", "--server.urls","http://*:8888"]
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "ZR.Admin.WebApi.dll"]
ENV TZ=Asia/Shanghai
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
RUN apt-get update && apt-get install -y libfontconfig1
+1 -25
View File
@@ -1,7 +1,7 @@
using Quartz.Spi;
using SqlSugar;
using SqlSugar.IOC;
using ZR.Model.System;
using ZR.ServiceCore.Model;
using ZR.Tasks;
namespace ZR.Admin.WebApi.Extensions
@@ -50,29 +50,5 @@ namespace ZR.Admin.WebApi.Extensions
return app;
}
/// <summary>
/// 初始化字典
/// </summary>
/// <param name="app"></param>
/// <returns></returns>
public static IApplicationBuilder UseInit(this IApplicationBuilder app)
{
Console.WriteLine("初始化字典数据...");
var db = DbScoped.SugarScope;
var types = db.Queryable<SysDictType>()
.Where(it => it.Status == "0")
.Select(it => it.DictType)
.ToList();
//上面有耗时操作写在Any上面,保证程序启动后只执行一次
if (!db.ConfigQuery.Any())
{
foreach (var type in types)
{
db.ConfigQuery.SetTable<SysDictData>(it => SqlFunc.ToString(it.DictValue), it => it.DictLabel, type, it => it.DictType == type);
}
}
return app;
}
}
}
+1 -1
View File
@@ -8,4 +8,4 @@ global using Mapster;
global using Infrastructure.Extensions;
global using Infrastructure.Controllers;
global using ZR.ServiceCore.Middleware;
global using ZR.ServiceCore.Services;
global using Microsoft.AspNetCore.Mvc;
@@ -6,12 +6,19 @@
"RealIpHeader": "X-Real-IP",
"ClientIdHeader": "X-ClientId",
"HttpStatusCode": 429,
"EndpointWhitelist": [ "post:/system/dict/data/types", "*:/msghub/negotiate", "*:/LogOut", "*:/common/uploadfile", "*:/VerifyScan" ],
"EndpointWhitelist": [
"post:/system/dict/data/types",
"*:/msghub/negotiate",
"*:/LogOut",
"*:/common/uploadfile",
"post:/aim/msg/list/sendmsg"
],
"QuotaExceededResponse": {
"Content": "{{\"code\":429,\"msg\":\"访问过于频繁,请稍后重试\"}}",
"ContentType": "application/json",
"StatusCode": 429
},
// "IpWhitelist": [ "127.0.0.1", "::1/10", "192.168.0.0/24" ],
//通用规则,api规则,结尾一定要带*
"GeneralRules": [
{
@@ -24,7 +31,17 @@
"Endpoint": "((post)|(put)):*",
"Period": "3s",
"Limit": 1
},
{
"Endpoint": "*:/aim/msg/list/SendMsg",
"Period": "1s",
"Limit": 0,
}
]
},
"IpRateLimitPolicies": {
//ip规则
"IpRules": [
]
}
}
+32 -5
View File
@@ -4,7 +4,8 @@
xsi:schemaLocation="http://www.nlog-project.org/schemas/NLog.xsd NLog.xsd"
autoReload="true"
internalLogLevel="Info"
internalLogFile="nlog-internal.log">
internalLogFile="nlog-internal.log"
throwConfigExceptions="true">
<!--Nlog 文档参考地址:https://github.com/NLog/NLog/wiki/Getting-started-with-ASP.NET-Core-2-->
<!--internalLogLevel Nlog内部日志记录为Off关闭。除非纠错,不可以设为Trace否则速度很慢,起码Debug以上-->
@@ -46,7 +47,7 @@
<!--SQL文件-->
<target name="sqlfile" xsi:type="File"
fileName="${basedir}/adminlogs/sql.txt"
archiveFileName="${basedir}/adminlogs/bak/sql/sql{###}.txt"
archiveFileName="${basedir}/adminlogs/bak/sql/sql.{###}.txt"
archiveEvery="Day"
archiveNumbering="DateAndSequence"
archiveAboveSize="20000000"
@@ -67,8 +68,34 @@
<highlight-word regex="】" foregroundColor="Blue" />
</target>
<!--日志打印到控制台-->
<target name="console" xsi:type="ColoredConsole"
layout="${date:format=MM-dd HH\:mm\:ss} | ${aspnet-request-url} ${newline} ${message}">
<highlight-row condition="level == LogLevel.Debug" foregroundColor="DarkGray" />
<highlight-row condition="level == LogLevel.Info" foregroundColor="Gray" />
<highlight-row condition="level == LogLevel.Warn" foregroundColor="Yellow" />
<highlight-row condition="level == LogLevel.Error" foregroundColor="Red" />
<highlight-row condition="level == LogLevel.Fatal" foregroundColor="Red" backgroundColor="White" />
</target>
<!--写入黑洞-->
<target name="blackhole" xsi:type="Null" />
<target name="ipRateLimitFile" xsi:type="File"
fileName="${basedir}/adminlogs/ipratelimit.txt"
archiveFileName="${basedir}/adminlogs/bak/ipratelimit/ipratelimit{###}.txt"
archiveEvery="Day"
archiveNumbering="DateAndSequence"
archiveAboveSize="20000000"
maxArchiveFiles="30"
keepFileOpen="false"
layout="${date:format=MM-dd HH\:mm\:ss} | ${aspnet-request-url} ${newline} ${message}"
/>
<!-- 速率限制日志写入控制台 -->
<target name="consoleIpRateLimit" xsi:type="ColoredConsole" useDefaultRowHighlightingRules="false"
layout="${date:format=MM-dd HH\:mm\:ss} | ${aspnet-request-url} ${newline} ${message}">
<highlight-row condition="level == LogLevel.Info" foregroundColor="Blue" />
</target>
</targets>
<rules>
@@ -79,10 +106,10 @@
<!--<logger name="System.*" writeTo="blackhole" final="true" />-->
<!-- Quartz -->
<logger name="Quartz*" minlevel="Trace" maxlevel="Info" final="true" />
<logger name="*.SqlSugar.SqlsugarSetup" final="true" writeTo="consoleSql,sqlfile"/>
<logger name="*" minLevel="Trace" writeTo="allfile" />
<logger name="*.SqlSugar.SqlSugarSetup" final="true" writeTo="consoleSql,sqlfile"/>
<logger name="*" minLevel="Trace" writeTo="allfile,console" />
<logger name="*.GlobalExceptionMiddleware" final="true" writeTo="consoleSql,errorfile"/>
<logger name="ZR.Admin.WebApi.Middleware.CustomIpRateLimitMiddleware" final="true" writeTo="consoleIpRateLimit,ipRateLimitFile" />
<!--Skip non-critical Microsoft logs and so log only own logs-->
<logger name="Microsoft.*,Quartz.Core.QuartzSchedulerThread" maxlevel="Info" final="true" />
</rules>
+62 -17
View File
@@ -2,15 +2,28 @@ using AspNetCoreRateLimit;
using Infrastructure.Converter;
using Microsoft.AspNetCore.DataProtection;
using NLog.Web;
using SqlSugar;
using System.Text.Json;
using Microsoft.Extensions.Caching.Distributed;
using Microsoft.Extensions.Caching.Redis;
using Microsoft.Extensions.Options;
using ZR.Admin.Grpc;
using ZR.Admin.Grpc.Extensions;
using ZR.Admin.WebApi.Extensions;
using ZR.Common.Cache;
using ZR.Infrastructure.Cache;
using ZR.Infrastructure.WebExtensions;
using ZR.ServiceCore.Services.IService;
using ZR.ServiceCore.Signalr;
using ZR.ServiceCore.SqlSugar;
using IpRateLimitPolicy = AspNetCoreRateLimit.IpRateLimitPolicy;
var builder = WebApplication.CreateBuilder(args);
//load json config by ipRateLimit
builder.Configuration.AddJsonFile("IpRateLimitConfig.json", true, true);
//load json config by loginVerify
builder.Configuration.AddJsonFile("loginVerifyConf.json", true, true);
// NLog: Setup NLog for Dependency injection
//builder.Logging.ClearProviders();
builder.Host.UseNLog();
@@ -24,6 +37,8 @@ builder.Services.AddSwaggerGen();
builder.Services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
// 跨域配置
builder.Services.AddCors(builder.Configuration);
// Grpc
builder.Services.AddGrpc();
// 显示logo
builder.Services.AddLogo();
//消除Error unprotecting the session cookie警告
@@ -37,8 +52,7 @@ builder.Services.AddIPRate(builder.Configuration);
builder.Services.AddHttpContextAccessor();
//绑定整个对象到Model上
builder.Services.Configure<OptionsSetting>(builder.Configuration);
builder.Configuration.AddJsonFile("codeGen.json");
builder.Configuration.AddJsonFile("iprate.json");
//jwt 认证
builder.Services.AddJwt();
//配置文件
@@ -47,16 +61,17 @@ builder.Services.AddSingleton(new AppSettings(builder.Configuration));
builder.Services.AddAppService();
//开启计划任务
builder.Services.AddTaskSchedulers();
//请求大小限制
builder.Services.AddRequestLimit(builder.Configuration);
//注册REDIS 服务
var openRedis = builder.Configuration["RedisServer:open"];
if (openRedis == "1")
{
RedisServer.Initalize();
builder.Services.AddSingleton<IDistributedCache>(new CSRedisCache(RedisHelper.Instance));
}
builder.Services.AddMvc(options =>
{
options.Filters.Add(typeof(GlobalActionMonitor));//全局注册
@@ -79,19 +94,22 @@ builder.Services.AddSignalR()
options.PayloadSerializerOptions.PropertyNamingPolicy = JsonNamingPolicy.CamelCase;
});
builder.Services.AddSwaggerConfig();
// using var channel = GrpcChannel.ForAddress("https://localhost:7025");
// var client = new Greeter.GreeterClient(channel);
// var reply = await client.SayHelloAsync(new HelloRequest { Name = "GreeterClient" });
// Console.WriteLine("Greeting: " + reply.Message);
//
// var blockClient = new Block.BlockClient(channel);
// var blockReply = await blockClient.GetBlockAsync(new BlockRequest { In = "asads" });
// Console.WriteLine("BlockReply: " + blockReply.Out);
builder.Services.AddGrpcServiceConfiguration(builder.Configuration);
var app = builder.Build();
InternalApp.ServiceProvider = app.Services;
InternalApp.Configuration = builder.Configuration;
InternalApp.WebHostEnvironment = app.Environment;
//初始化db
builder.Services.AddDb(app.Environment);
var workId = builder.Configuration["workId"].ParseToInt();
if (app.Environment.IsDevelopment())
{
workId += 1;
}
SnowFlakeSingle.WorkId = workId;
//使用全局异常中间件
app.UseMiddleware<GlobalExceptionMiddleware>();
@@ -129,13 +147,11 @@ if (builder.Environment.IsProduction())
//恢复/启动任务
app.UseAddTaskSchedulers();
}
//初始化字典数据
app.UseInit();
//使用swagger
app.UseSwagger();
//启用客户端IP限制速率
app.UseIpRateLimiting();
// app.UseIpRateLimiting();
app.UseMiddleware<CustomIpRateLimitMiddleware>();
app.UseRateLimiter();
//设置socket连接
app.MapHub<MessageHub>("/msgHub");
@@ -145,4 +161,33 @@ app.MapControllerRoute(
pattern: "{controller=Home}/{action=Index}/{id?}");
app.MapControllers();
using (var serviceScope = app.Services.CreateScope())
{
var services = serviceScope.ServiceProvider;
// get the IpPolicyStore instance
var ipPolicyStore = services.GetRequiredService<IIpPolicyStore>();
// seed IP data from appsettings
ipPolicyStore.SeedAsync().GetAwaiter().GetResult();
var optionsAccessor = services.GetRequiredService<IOptions<IpRateLimitOptions>>();
var ipRateLimitPolicyService = services.GetRequiredService<IIpRateLimitPolicyService>();
var ipRateLimitPolicies = ipRateLimitPolicyService.Queryable()
.Includes(it => it.Rules.Where(r => r.Flag == '1').ToList())
.Where(it => it.Flag == '1')
.ToListAsync().GetAwaiter().GetResult();
var pol = await ipPolicyStore.GetAsync(optionsAccessor.Value.IpPolicyPrefix);
pol.IpRules.AddRange(ipRateLimitPolicies.Adapt<List<IpRateLimitPolicy>>());
await ipPolicyStore.SetAsync(optionsAccessor.Value.IpPolicyPrefix, pol);
// var greeterClient = services.GetRequiredService<Greeter.GreeterClient>();
// var helloReply = await greeterClient.SayHelloAsync(new HelloRequest
// {
// Name = "gree"
// });
// Console.WriteLine(helloReply);
}
app.Run();
+13 -5
View File
@@ -4,23 +4,25 @@
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<NoWarn>1701;1702;1591,8603,8602,8604,8600,8618</NoWarn>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\ZR.Admin.Grpc\ZR.Admin.Grpc.csproj" />
<ProjectReference Include="..\ZR.CodeGenerator\ZR.CodeGenerator.csproj" />
<ProjectReference Include="..\ZR.Service\ZR.Service.csproj" />
<ProjectReference Include="..\ZR.Tasks\ZR.Tasks.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Lazy.Captcha.Core" Version="2.0.7" />
<PackageReference Include="Lazy.Captcha.Core" Version="2.0.3" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
<PackageReference Include="Swashbuckle.AspNetCore.Filters" Version="7.0.12" />
<PackageReference Include="NLog.Web.AspNetCore" Version="5.3.8" />
<PackageReference Include="Mapster" Version="7.4.0" />
<PackageReference Include="SkiaSharp.NativeAssets.Linux" Version="2.88.6" />
<PackageReference Include="Swashbuckle.AspNetCore.Filters" Version="7.0.6" />
<PackageReference Include="NLog.Web.AspNetCore" Version="5.3.3" />
<PackageReference Include="Mapster" Version="7.3.0" />
<PackageReference Include="SkiaSharp.NativeAssets.Linux" Version="2.88.5" />
</ItemGroup>
<ItemGroup>
@@ -28,6 +30,9 @@
</ItemGroup>
<ItemGroup>
<Content Include="..\.dockerignore">
<Link>.dockerignore</Link>
</Content>
<None Update="ip2region.db">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
@@ -37,5 +42,8 @@
<Content Update="wwwroot\export\**\*">
<CopyToPublishDirectory>Never</CopyToPublishDirectory>
</Content>
<Content Update="appsettings.Production.json">
<DependentUpon>appsettings.json</DependentUpon>
</Content>
</ItemGroup>
</Project>
+54 -33
View File
@@ -8,8 +8,8 @@
},
"dbConfigs": [
{
"Conn": "Data Source=LAPTOP-STKF2M8H\\SQLEXPRESS;User ID=admin;Password=admin123;Initial Catalog=ZrAdmin;",
"DbType": 1, //数据库类型 MySql = 0, SqlServer = 1, Oracle = 3,PgSql = 4
"Conn": "server=8.140.174.251;user=admin;pwd=admin123;database=ZrAdmin;port=33060",
"DbType": 0, //数据库类型 MySql = 0, SqlServer = 1, Oracle = 3,PgSql = 4
"ConfigId": "0", //多租户唯一标识
"IsAutoCloseConnection": true
}
@@ -30,31 +30,28 @@
"Audience": "ZRAdmin.NET", //指该token是服务于哪个群体的(群体范围)
"SecretKey": "SecretKey-ZRADMIN.NET-20210101",
"Expire": 1440, //jwt登录过期时间(分)
"RefreshTokenTime": 30, //分钟
"RefreshTokenTime": 5,//分钟
"TokenType": "Bearer"
},
"InjectClass": [ "ZR.Repository", "ZR.Service", "ZR.Tasks", "ZR.ServiceCore" ], //自动注入类
"ShowDbLog": true, //是否打印db日志
"InitDb": false, //是否初始化db
"DemoMode": false, //是否演示模式
"SingleLogin": false, //是否允许多设备/浏览器登录
"workId": 1, //雪花id唯一数字
"sqlExecutionTime": 5, //Sql执行时间超过多少秒记录日志并警报
"SingleLogin": false,//是否单点登录
"Upload": {
"uploadUrl": "http://localhost:8888", //本地存储资源访问路径
"localSavePath": "", //本地上传默认文件存储目录 wwwroot
"maxSize": 15, //上传文件大小限制 15M
"notAllowedExt": [ ".bat", ".exe", ".jar", ".js" ],
"requestLimitSize": 50//请求body大小限制
"notAllowedExt": [ ".bat", ".exe", ".jar", ".js" ]
},
//阿里云存储配置
"ALIYUN_OSS": {
"REGIONID": "", //eg:cn-hangzhou
"KEY": "XX",
"SECRET": "XX",
"bucketName": "bucketName",
"domainUrl": "http://xxx.xxx.com", //访问资源域名
"maxSize": 100 //上传文件大小限制 100M
"REGIONID": "oss-cn-hangzhou.aliyuncs.com", //eg:cn-hangzhou
"KEY": "LTAI5tBjDZatWWunAhxLAAFR",
"SECRET": "Klcm77KdpkIROAl2ffPemK5I1yDshM",
"bucketName": "markdownhexo",
"domainUrl": "https://markdownhexo.oss-cn-hangzhou.aliyuncs.com", //访问资源域名
"maxSize": 1000 //上传文件大小限制 1000M
},
//企业微信通知配置
"WxCorp": {
@@ -68,40 +65,64 @@
"AppID": "",
"AppSecret": ""
},
//代码生成配置
"gen": {
//是否显示移动端代码生成
"showApp": false,
//自动去除表前缀
"autoPre": true,
"author": "admin",
"tablePrefix": "sys_", //"表前缀(生成类名不会包含表前缀,多个用逗号分隔)",
"vuePath": "", //前端代码存储路径eg:D:\Work\ZRAdmin-Vue3
"csharpTypeArr": {
"string": [ "varchar", "nvarchar", "text", "longtext" ],
"int": [ "int", "integer", "smallint", "int4", "int8", "int2" ],
"long": [ "bigint", "number" ],
"float": [ "numeric", "real", "float" ],
"decimal": [ "money", "decimal", "smallmoney" ],
"dateTime": [ "date", "datetime", "datetime2", "smalldatetime", "timestamp" ],
"byte": [ "tinyint" ],
"bool": [ "bit" ]
}
},
//邮箱配置信息
"MailOptions": {
//发件人名称
"FromName": "system",
"FromName": "文永达",
//发送人邮箱
"FromEmail": "", //eg:xxxx@qq.com
"FromEmail": "1224169330@qq.com", //eg:xxxx@qq.com
//发送人邮箱密码
"Password": "",
"Password": "wbctsfvdazchibdh",
//协议
"Smtp": "smtp.qq.com",
"Port": 587,
"Port": 465,
"Signature": "系统邮件,请勿回复!",
"UseSsl": true
},
//redis服务配置
"RedisServer": {
"open": 0, //是否启用redis
"Cache": "127.0.0.1:6379,defaultDatabase=0,poolsize=50,ssl=false,writeBuffer=10240,prefix=cache:",
"Session": "127.0.0.1:6379,defaultDatabase=0,poolsize=50,ssl=false,writeBuffer=10240,prefix=session:"
"open": 1, //是否启用redis
"Cache": "8.140.174.251:6379,password=Wyd210213,defaultDatabase=0,poolsize=50,ssl=false,writeBuffer=10240,prefix=cache:",
// "Cache": "127.0.0.1:6379,password=Wyd210213,defaultDatabase=0,poolsize=50,ssl=false,writeBuffer=10240,prefix=cache:",
"Session": "8.140.174.251:6379,password=Wyd210213,defaultDatabase=0,poolsize=50,ssl=false,writeBuffer=10240,prefix=session:"
// "Session": "127.0.0.1:6379,password=Wyd210213,defaultDatabase=0,poolsize=50,ssl=false,writeBuffer=10240,prefix=session:"
},
//验证码配置
"CaptchaOptions": {
"IgnoreCase": true // 比较时是否忽略大小写
"CaptchaType": 10,
"IgnoreCase": true, // 比较时是否忽略大小写
"ImageOption": {
"FontSize": 36, // 字体大小
"Animation": true, // 是否启用动画
"TextBold": true, // 是否启用粗体
"InterferenceLineCount": 4, // 干扰线数量
"BubbleMinRadius": 5, // 气泡最小半径
"BubbleMaxRadius": 10, // 气泡最大半径
"BubbleCount": 3, // 气泡数量
"BubbleThickness": 1.0 // 气泡边沿厚度
}
},
//代码生成配置
"CodeGen": {
//是否显示移动端代码生成
"showApp": false,
//自动去除表前缀
"autoPre": true,
//默认生成业务模块名
"moduleName": "business",
"author": "admin",
"tablePrefix": "sys_", //"表前缀(生成类名不会包含表前缀,多个用逗号分隔)",
"vuePath": "" //前端代码存储路径eg:D:\Work\ZRAdmin-Vue3
"GrpcUrls": {
"FindTeacher": "http://localhost:5212"
}
}
-14
View File
@@ -1,14 +0,0 @@
{
"CodeGen": {
"csharpTypeArr": {
"string": [ "varchar", "nvarchar", "text", "longtext" ],
"int": [ "int", "integer", "smallint", "int4", "int8", "int2" ],
"long": [ "bigint", "number" ],
"float": [ "numeric", "real", "float" ],
"decimal": [ "money", "decimal", "smallmoney" ],
"dateTime": [ "date", "datetime", "datetime2", "smalldatetime", "timestamp" ],
"byte": [ "tinyint" ],
"bool": [ "bit" ]
}
}
}
+5
View File
@@ -0,0 +1,5 @@
{
"RSA": {
"PrivatePem": "-----BEGIN PRIVATE KEY-----MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCjvJHH6V8fHL9zuVkW1mcDcYF5D72fEG45xLP8jyXR0/klmxZUT6My2ajGcWtOAKyca4Mcw2lKV7FRzchVyylsLi1JaH+vgbL0qwjDS0hjSm6Uqw39WFX//t1qMxX8OD5F3lvAYaNauVY6nYQ9VgEcjrq5nc+kRB7cVsR1ouQlFMQ1vLCAZwajW2pSmpjkEMYC70iJfBl7iF0za6eIVLZEpxgOi8KIkTWUDvLLH0cRR30+FgyE8wu8gh09ZbYarGyLchmAbbmERHT6jfMgKCob/ZVuh0EzrklMsFj4qdjofejzRvS/arA4HtOS1W1ZBHovPxR36quWB4DO9lvkWakNAgMBAAECggEADiLHizTQq4T12m3UDS6xchColuUO/96RRZd/2nwZTcY5Kk/7W4gMlOVJtugv1WolfNOjXCZavrpXarKTayTBDL/n1QCalXJjGtBxTzr+ouPYLCmgaZDoy9MbFoIWkdHhPnL2BOPpEHoTwbe7pPf53JdN85x2Qr5G08sB5w4LGFBRPAkOoD2LgW4QK7Ut5k4GAHmcn7nqHlkMM8ksdNGkQEhSHfoQOh7FFgR1GHJMeO0JgXprJCIFjyhtyzzDj47r02LWqEaaTdokvkYPEqyzjSI/Gufvq6nvgIlf2mU9KA2NC3VwJrXtAQQezy7yB6blvBceygwXChVKAuUtEyOf2QKBgQDaKC76PlG+p61DIwfIJIcP6JgzWVXj7gJr82hpu8NIf0Wz354eYRl1gdW6dkgpkPhnDvZ/b23P5FsWG8OR0f0VMgPvKVDo+Z+cHLsoroqeCw7B1MEdv2d69gbAk343BTVkTui94152GeCu3O/C0QmaZyqOtumEbxDl8K+lsusEkwKBgQDAI7XzXx+EqKD1m2DKnj2YILEplB4pmJnTWaZi5qAKO+XxbUTGcSxRALBYxuMEvd2AIEk9VhQiLpJ9DoOzVg5LY/zeRvK1vE2tUj/cx8X8jekdY7QayP6KigWbe3juqBHm9eD97wwmQgbFRg+ZZrpKhENym4BVqCuJwc7nC02/3wKBgFIvCyuIqKDraBE/tCHI6PysQhIuGHZKZq0mQHJ8op/AGpEdr+J/7+hdphedkaffDkU81M3DO5oyy8GzaeSYOABxHBxP80QhLejQxg0YW+4X+lI5BRtgzOn8nySTK9wsYSXNuE44xpA1RXh6kPRSbYy2SskCzUvvz2zgVDtXAMRzAoGABItTrFPdnPeYBvcLzP79GfH7/q3AIN+5E6SVKNWnh1ZvU8xvyfm3QJsxkIfzqpMLABLDaK32f/B2CnsjZkRsxh+xRViMOPwhIi5F0GTxK833a3iGM/P5ATHOfCTpcUuMUNgT4C2dLfJ10oibqdciJM0IA1fmKyB1Fyb8S76asiUCgYEAu6ZQ5BfxtbhZCjZ7/hYKHuzDjRzyiaBkKjtN5ZvqLgkG6Zdfjrm2/RcFCMVtqZKXcgVcD9yxy561fmS+5gE3yTfKiFcYoYITT/N26MJ5G7Qeb/FPpmDRVQGjCaAw0o8dvaqe3pUEROdYX+JVQMxQ4WOPiV45FXazAZtFNr8Z+xA=-----END PRIVATE KEY-----"
}
}
+18
View File
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<location path="." inheritInChildApplications="false">
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath="dotnet" arguments=".\ZR.Admin.WebApi.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="inprocess" />
</system.webServer>
</location>
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxQueryString="2097151" maxAllowedContentLength="1073741824" />
</requestFiltering>
</security>
</system.webServer>
</configuration>
@@ -66,7 +66,7 @@ $end
{
var response = _${replaceDto.ModelTypeName}Service.GetInfo(${replaceDto.PKName});
var info = response.Adapt<${replaceDto.ModelTypeName}Dto>();
var info = response.Adapt<${replaceDto.ModelTypeName}>();
return SUCCESS(info);
}
@@ -86,8 +86,8 @@ $if(replaceDto.ShowBtnAdd)
return SUCCESS(response);
}
$end
$if(replaceDto.ShowBtnEdit)
/// <summary>
/// 更新${genTable.FunctionName}
@@ -103,24 +103,27 @@ $if(replaceDto.ShowBtnEdit)
return ToResponse(response);
}
$end
$if(replaceDto.ShowBtnDelete || replaceDto.ShowBtnMultiDel)
/// <summary>
/// 删除${genTable.FunctionName}
/// </summary>
/// <returns></returns>
[HttpDelete("delete/{ids}")]
[HttpDelete("{ids}")]
[ActionPermissionFilter(Permission = "${replaceDto.PermissionPrefix}:delete")]
[Log(Title = "${genTable.FunctionName}", BusinessType = BusinessType.DELETE)]
public IActionResult Delete${replaceDto.ModelTypeName}([FromRoute]string ids)
public IActionResult Delete${replaceDto.ModelTypeName}(string ids)
{
var idArr = Tools.SplitAndConvert<${replaceDto.PKType}>(ids);
int[] idsArr = Tools.SpitIntArrary(ids);
if (idsArr.Length <= 0) { return ToResponse(ApiResult.Error($"删除失败Id 不能为空")); }
return ToResponse(_${replaceDto.ModelTypeName}Service.Delete(idArr$if(replaceDto.enableLog), "删除${genTable.FunctionName}"$end));
var response = _${replaceDto.ModelTypeName}Service.Delete(idsArr);
return ToResponse(response);
}
$end
$if(replaceDto.ShowBtnExport)
/// <summary>
/// 导出${genTable.FunctionName}
@@ -133,7 +136,7 @@ $if(replaceDto.ShowBtnExport)
{
parm.PageNum = 1;
parm.PageSize = 100000;
var list = _${replaceDto.ModelTypeName}Service.ExportList(parm).Result;
var list = _${replaceDto.ModelTypeName}Service.GetList(parm).Result;
if (list == null || list.Count <= 0)
{
return ToResponse(ResultCode.FAIL, "没有要导出的数据");
@@ -141,8 +144,8 @@ $if(replaceDto.ShowBtnExport)
var result = ExportExcelMini(list, "${genTable.FunctionName}", "${genTable.FunctionName}");
return ExportExcel(result.Item2, result.Item1);
}
$end
$if(replaceDto.ShowBtnTruncate)
/// <summary>
/// 清空${genTable.FunctionName}
@@ -159,8 +162,8 @@ $if(replaceDto.ShowBtnTruncate)
}
return SUCCESS(_${replaceDto.ModelTypeName}Service.Truncate${replaceDto.ModelTypeName}());
}
$end
$if(replaceDto.ShowBtnImport)
/// <summary>
/// 导入
@@ -193,8 +196,8 @@ $if(replaceDto.ShowBtnImport)
var result = DownloadImportTemplate(new List<${replaceDto.ModelTypeName}Dto>() { }, "${replaceDto.ModelTypeName}");
return ExportExcel(result.Item2, result.Item1);
}
$end
$if(showCustomInput)
/// <summary>
/// 保存排序
@@ -1,3 +1,7 @@
using System.ComponentModel.DataAnnotations;
$if(replaceDto.ShowBtnExport)
using MiniExcelLibs.Attributes;
$end
$if(null != genTable.SubTableName && "" != genTable.SubTableName)
using ${subTableOptions.ModelsNamespace}.${subTableOptions.SubNamespace};
$end
@@ -29,24 +33,18 @@ $end
public class ${replaceDto.ModelTypeName}Dto
{
$foreach(item in genTable.Columns)
$set(labelName = "")
$if(item.ColumnComment != "")
$set(labelName = item.ColumnComment)
$else
$set(labelName = item.CsharpField)
$end
$if(item.IsRequired)
[Required(ErrorMessage = "${item.ColumnComment}不能为空")]
$end
$if(replaceDto.ShowBtnExport)
$if(item.IsExport)
[ExcelColumn(Name = "$labelName"$if(item.CsharpType == "DateTime"), Format = "yyyy-MM-dd HH:mm:ss", Width = 20$end)]
[ExcelColumnName("$labelName")]
[ExcelColumn(Name = "$if(item.ColumnComment == "")${item.CsharpField}${else}${item.ColumnComment}${end}"$if(item.CsharpType == "DateTime"), Format = "yyyy-MM-dd HH:mm:ss"$end)]
[ExcelColumnName("$if(item.ColumnComment == "")${item.CsharpField}${else}${item.ColumnComment}${end}")]
$else
[ExcelIgnore]
$end
$end
$if(item.CsharpType == "long" && replaceDto.useSnowflakeId == true && item.IsPk)
$if(item.CsharpType == "long")
[JsonConverter(typeof(ValueToStringConverter))]
$end
public $item.CsharpType$item.RequiredStr $item.CsharpField { get; set; }
@@ -65,12 +63,6 @@ $if(replaceDto.ShowBtnExport)
[ExcelIgnore]
$end
public List<${genTable.SubTable.ClassName}Dto> ${genTable.SubTable.ClassName}Nav { get; set; }
$end
$foreach(column in dicts)
$if(column.IsExport)
[ExcelColumn(Name = "$if(column.ColumnComment == "")${column.CsharpField}${else}${column.ColumnComment}${end}")]
public string ${column.CsharpField}Label { get; set; }
$end
$end
}
}
@@ -1,6 +1,8 @@
using ${options.BaseNamespace}Model;
using System;
using ${options.BaseNamespace}Model;
using ${options.DtosNamespace};
using ${options.ModelsNamespace}.${options.SubNamespace};
using System.Collections.Generic;
namespace ${options.IServicsNamespace}.${options.SubNamespace}.I${options.SubNamespace}Service
{
@@ -16,7 +18,6 @@ namespace ${options.IServicsNamespace}.${options.SubNamespace}.I${options.SubNam
$if(genTable.TplCategory == "tree")
List<${replaceDto.ModelTypeName}> GetTreeList(${replaceDto.ModelTypeName}QueryDto parm);
$end
${replaceDto.ModelTypeName} Add${replaceDto.ModelTypeName}(${replaceDto.ModelTypeName} parm);
int Update${replaceDto.ModelTypeName}(${replaceDto.ModelTypeName} parm);
@@ -27,9 +28,5 @@ $end
$if(replaceDto.ShowBtnImport)
(string, object, object) Import${replaceDto.ModelTypeName}(List<${replaceDto.ModelTypeName}> list);
$end
$if(replaceDto.ShowBtnExport)
PagedInfo<${replaceDto.ModelTypeName}Dto> ExportList(${replaceDto.ModelTypeName}QueryDto parm);
$end
}
}
@@ -1,4 +1,6 @@
using Infrastructure.Attribute;
using System;
using SqlSugar;
using Infrastructure.Attribute;
using Infrastructure.Extensions;
using ${options.BaseNamespace}Model;
using ${options.DtosNamespace};
@@ -25,8 +27,28 @@ namespace ${options.ServicesNamespace}.${options.SubNamespace}
/// <returns></returns>
public PagedInfo<${replaceDto.ModelTypeName}Dto> GetList(${replaceDto.ModelTypeName}QueryDto parm)
{
var predicate = QueryExp(parm);
var predicate = Expressionable.Create<${replaceDto.ModelTypeName}>();
$foreach(column in genTable.Columns)
$if(column.IsQuery)
$if(column.HtmlType == "selectMulti")
predicate = predicate.AndIF(parm.${column.CsharpField} != null, it => parm.${column.CsharpField}.Contains(it.${column.CsharpField}));
$elseif(column.CsharpType == "string")
predicate = predicate.AndIF(!string.IsNullOrEmpty(parm.${column.CsharpField}), ${codeTool.QueryExp(column.CsharpField, column.QueryType)};
$elseif(column.CsharpType == "DateTime")
$if(column.HtmlType == "month")
DateTime monthEnd = Convert.ToDateTime(parm.${column.CsharpField}).AddMonths(1);
predicate = predicate.AndIF(parm.${column.CsharpField} != null, it => it.${column.CsharpField} >= parm.${column.CsharpField} && it.${column.CsharpField} < monthEnd);
$else
predicate = predicate.AndIF(parm.Begin${column.CsharpField} == null, it => it.${column.CsharpField} >= DateTime.Now.ToShortDateString().ParseToDateTime());
predicate = predicate.AndIF(parm.Begin${column.CsharpField} != null, it => it.${column.CsharpField} >= parm.Begin${column.CsharpField});
predicate = predicate.AndIF(parm.End${column.CsharpField} != null, it => it.${column.CsharpField} <= parm.End${column.CsharpField});
$end
$elseif(column.CsharpType == "int" || column.CsharpType == "long")
predicate = predicate.AndIF(parm.${column.CsharpField} != null, ${codeTool.QueryExp(column.CsharpField, column.QueryType)};
$end
$end
$end
var response = Queryable()
$if(null != genTable.SubTableName && "" != genTable.SubTableName)
//.Includes(x => x.${genTable.SubTable.ClassName}Nav) //填充子对象
@@ -95,12 +117,7 @@ $end
$if(null != genTable.SubTableName && "" != genTable.SubTableName)
return Context.InsertNav(model).Include(s1 => s1.${genTable.SubTable.ClassName}Nav).ExecuteReturnEntity();
$else
$if(replaceDto.useSnowflakeId)
Insertable(model).ExecuteReturnSnowflakeId();
return model;
$else
return Insertable(model).ExecuteReturnEntity();
$end
return Context.Insertable(model).ExecuteReturnEntity();
$end
}
@@ -111,10 +128,19 @@ $end
/// <returns></returns>
public int Update${replaceDto.ModelTypeName}(${replaceDto.ModelTypeName} model)
{
//var response = Update(w => w.${replaceDto.PKName} == model.${replaceDto.PKName}, it => new ${replaceDto.ModelTypeName}()
//{
$foreach(item in genTable.Columns)
$if((item.IsEdit))
// $item.CsharpField = model.$item.CsharpField,
$end
${end}
//});
//return response;
$if(null != genTable.SubTableName && "" != genTable.SubTableName)
return Context.UpdateNav(model).Include(z1 => z1.${genTable.SubTable.ClassName}Nav).ExecuteCommand() ? 1 : 0;
$else
return Update(model, true$if(replaceDto.enableLog), "修改${genTable.FunctionName}"$end);
return Update(model, true);
$end
}
$if(replaceDto.ShowBtnTruncate)
@@ -168,63 +194,5 @@ $end
return (msg, x.ErrorList, x.IgnoreList);
}
$end
$if(replaceDto.ShowBtnExport)
/// <summary>
/// 导出${genTable.FunctionName}
/// </summary>
/// <param name="parm"></param>
/// <returns></returns>
public PagedInfo<${replaceDto.ModelTypeName}Dto> ExportList(${replaceDto.ModelTypeName}QueryDto parm)
{
var predicate = QueryExp(parm);
var response = Queryable()
.Where(predicate.ToExpression())
.Select((it) => new ${replaceDto.ModelTypeName}Dto()
{
$foreach(column in dicts)
$if(column.DictType != "")
${column.CsharpField}Label = it.${column.CsharpField}.GetConfigValue<Model.System.SysDictData>("${column.DictType}"),
$end
$end
}, true)
.ToPage(parm);
return response;
}
$end
/// <summary>
/// 查询导出表达式
/// </summary>
/// <param name="parm"></param>
/// <returns></returns>
private static Expressionable<${replaceDto.ModelTypeName}> QueryExp(${replaceDto.ModelTypeName}QueryDto parm)
{
var predicate = Expressionable.Create<${replaceDto.ModelTypeName}>();
$foreach(column in genTable.Columns)
$if(column.IsQuery)
$if(column.HtmlType == "selectMulti")
predicate = predicate.AndIF(parm.${column.CsharpField} != null, it => parm.${column.CsharpField}.Contains(it.${column.CsharpField}));
$elseif(column.CsharpType == "string")
predicate = predicate.AndIF(!string.IsNullOrEmpty(parm.${column.CsharpField}), ${codeTool.QueryExp(column.CsharpField, column.QueryType)};
$elseif(column.CsharpType == "DateTime")
$if(column.HtmlType == "month")
DateTime monthEnd = Convert.ToDateTime(parm.${column.CsharpField}).AddMonths(1);
predicate = predicate.AndIF(parm.${column.CsharpField} != null, it => it.${column.CsharpField} >= parm.${column.CsharpField} && it.${column.CsharpField} < monthEnd);
$else
predicate = predicate.AndIF(parm.Begin${column.CsharpField} == null, it => it.${column.CsharpField} >= DateTime.Now.ToShortDateString().ParseToDateTime());
predicate = predicate.AndIF(parm.Begin${column.CsharpField} != null, it => it.${column.CsharpField} >= parm.Begin${column.CsharpField});
predicate = predicate.AndIF(parm.End${column.CsharpField} != null, it => it.${column.CsharpField} <= parm.End${column.CsharpField});
$end
$elseif(column.CsharpType == "int" || column.CsharpType == "long")
predicate = predicate.AndIF(parm.${column.CsharpField} != null, ${codeTool.QueryExp(column.CsharpField, column.QueryType)};
$end
$end
$end
return predicate;
}
}
}
@@ -80,7 +80,7 @@ $if(replaceDto.ShowBtnDelete || replaceDto.ShowBtnMultiDel)
*/
export function del${genTable.BusinessName}(pid) {
return request({
url: '${genTable.ModuleName}/${genTable.BusinessName}/delete/' + pid,
url: '${genTable.ModuleName}/${genTable.BusinessName}/' + pid,
method: 'delete'
})
}
@@ -1 +0,0 @@
你在期待什么...
@@ -56,7 +56,7 @@ $if(replaceDto.ShowBtnDelete || replaceDto.ShowBtnMultiDel)
*/
export function del${genTable.BusinessName}(pid) {
return request({
url: '/${genTable.ModuleName}/${genTable.BusinessName}/delete/' + pid,
url: '/${genTable.ModuleName}/${genTable.BusinessName}/' + pid,
method: 'delete'
})
}
@@ -73,6 +73,6 @@ $end
$if(replaceDto.ShowBtnExport)
// 导出${genTable.functionName}
export async function export${genTable.BusinessName}(query) {
await downFile('/${genTable.ModuleName}/${genTable.BusinessName}/export', { ...query })
await downFile('$/{genTable.ModuleName}/${genTable.BusinessName}/export', { ...query })
}
$end
@@ -12,7 +12,7 @@ $if(column.CsharpType == "int" || column.CsharpType == "long")
$end
$if(column.IsPK || column.IsIncrement)
$if(column.IsPK && column.IsIncrement == false && replaceDto.useSnowflakeId == false)
$if(column.IsPK && column.IsIncrement == false)
<u-form-item label="${labelName}" prop="${columnName}">
<u--input type="number" v-model.number="form.${columnName}" placeholder="请输入${labelName}" :disabled="opertype != 1"></u--input>
</u-form-item>
@@ -83,6 +83,7 @@ $end
</template>
<script>
import "@/static/scss/page.scss";
import {
get${genTable.BusinessName},
$if(replaceDto.ShowBtnAdd)
@@ -91,9 +92,15 @@ $end
$if(replaceDto.ShowBtnEdit)
update${genTable.BusinessName},
$end
} from '@/api/${tool.FirstLowerCase(genTable.ModuleName)}/${genTable.BusinessName.ToLower()}.js'
}
from '@/api/${tool.FirstLowerCase(genTable.ModuleName)}/${genTable.BusinessName.ToLower()}.js'
export default {
$if(replaceDto.UploadFile == 1)
components: {
UploadImage
},
$end
dicts: [
$foreach(item in genTable.Columns)
$if((item.HtmlType == "radio" || item.HtmlType.Contains("select") || item.HtmlType == "checkbox") && item.DictType != "")
@@ -103,15 +110,7 @@ $end
],
data() {
return {
form: {
$foreach(item in genTable.Columns)
$if(item.HtmlType == "checkbox")
${item.CsharpFieldFl}Checked: [],
$else
$item.CsharpFieldFl: undefined,
$end
$end
},
form: {},
rules: {
$foreach(column in genTable.Columns)
$if(column.IsRequired && column.IsIncrement == false)
@@ -203,8 +202,7 @@ $end
}
</script>
<style lang="scss" scoped>
@import "@/static/scss/page.scss";
<style scoped>
.btn-wrap {
margin: 150rpx auto 0 auto;
width: 80%
@@ -134,12 +134,14 @@ $end
import {
checkPermi
} from '@/utils/permission.js'
import "@/static/scss/page.scss";
import {
list${genTable.BusinessName},
$if(replaceDto.ShowBtnDelete)
del${genTable.BusinessName},
$end
} from '@/api/${tool.FirstLowerCase(genTable.ModuleName)}/${genTable.BusinessName.ToLower()}.js'
}
from '@/api/${tool.FirstLowerCase(genTable.ModuleName)}/${genTable.BusinessName.ToLower()}.js'
import {
getDate
@@ -284,7 +286,3 @@ $end
}
}
</script>
<style lang="scss" scoped>
@import "@/static/scss/page.scss";
</style>
@@ -230,7 +230,7 @@ $end
$* 一对一/一对多列表显示详情 *$
$if(sub)
<el-drawer v-model="drawer" size="50%" direction="rtl">
<el-drawer v-model="drawer" :with-header="false" direction="btt">
<el-table :data="$tool.FirstLowerCase(genTable.SubTable.ClassName)List" header-row-class-name="text-navy">
<el-table-column label="序号" type="index" width="80" />
$foreach(column in genSubTable.Columns)
@@ -267,7 +267,7 @@ $if(column.CsharpType == "int" || column.CsharpType == "long")
$end
$if(column.IsPK || column.IsIncrement)
$if(column.IsPK && column.IsIncrement == false && replaceDto.useSnowflakeId == false)
$if(column.IsPK && column.IsIncrement == false)
<el-col :lg="${options.ColNum}">
<el-form-item label="${labelName}" prop="${columnName}">
<el-input v-model${number}="form.${columnName}" placeholder="请输入${labelName}" :disabled="opertype != 1"/>
@@ -392,7 +392,7 @@ $if(sub)
</el-col>
</el-row>
<el-table :data="${tool.FirstLowerCase(genTable.SubTable.ClassName)}List" :row-class-name="row${genTable.SubTable.ClassName}Index" @selection-change="handle${genTable.SubTable.ClassName}SelectionChange" ref="${genTable.SubTable.ClassName}Ref">
<el-table-column type="selection" width="40" align="center" />
<el-table-column type="selection" width="50" align="center" />
<el-table-column label="序号" align="center" prop="index" width="50"/>
$foreach(column in genTable.SubTable.Columns)
$set(labelName = column.ColumnComment)
@@ -435,12 +435,6 @@ $elseif(column.HtmlType == "switch")
<el-switch v-model="scope.row.${columnName}" ${switchType} />
</template>
</el-table-column>
$elseif(column.HtmlType == "imageUpload")
<el-table-column label="${labelName}" prop="${columnName}">
<template #default="scope">
<UploadImage v-model="form.${columnName}" :isShowTip="false" :style="{ 'width': '50px' }" :data="{ uploadType: 1 }" />
</template>
</el-table-column>
$else
<el-table-column label="${labelName}" align="center" prop="${columnName}">
<template #default="scope">
@@ -641,9 +635,7 @@ const state = reactive({
form: {},
rules: {
$foreach(column in genTable.Columns)
$if(column.IsRequired && column.IsPk && replaceDto.useSnowflakeId)
${column.CsharpFieldFl}: [{ required: true, message: "${column.ColumnComment}不能为空", trigger: $if(column.htmlType == "select")"change"$else"blur"$end }],
$elseif(column.IsRequired && column.IsIncrement == false)
$if(column.IsRequired && column.IsIncrement == false)
${column.CsharpFieldFl}: [{ required: true, message: "${column.ColumnComment}不能为空", trigger: $if(column.htmlType == "select")"change"$else"blur"$end
$if(column.CsharpType == "int" || column.CsharpType == "long"), type: "number"$end }],
$end
@@ -683,37 +675,6 @@ $if(sub)
$end
proxy.resetForm("formRef")
}
$if(replaceDto.ShowBtnView)
/**
* 查看
* @param {*} row
*/
function handlePreview(row) {
reset()
const id = row.${replaceDto.FistLowerPk}
get${genTable.BusinessName}(id).then((res) => {
const { code, data } = res
if (code == 200) {
open.value = true
title.value = '查看'
opertype.value = 3
form.value = {
...data,
$foreach(item in genTable.Columns)
$if(item.HtmlType == "checkbox" || item.HtmlType == "selectMulti")
${item.CsharpFieldFl}Checked: data.${item.CsharpFieldFl} ? data.${item.CsharpFieldFl}.split(',') : [],
$end
$end
}
$if(sub)
${tool.FirstLowerCase(genTable.SubTable.ClassName)}List.value = res.data.${tool.FirstLowerCase(genTable.SubTable.ClassName)}Nav
$end
}
})
}
$end
$if(replaceDto.ShowBtnAdd)
// 添加按钮操作
function handleAdd() {
@@ -821,6 +782,20 @@ function handleClear() {
}
$end
$if(replaceDto.ShowBtnView)
/**
* 查看
* @param {*} row
*/
function handlePreview(row) {
reset()
open.value = true
title.value = '查看'
opertype.value = 3
form.value = { ...row }
}
$end
$if(replaceDto.ShowBtnImport)
// 导入数据成功处理
const handleFileSuccess = (response) => {
@@ -866,7 +841,6 @@ function row${genTable.SubTable.ClassName}Index({ row, rowIndex }) {
/** ${genTable.SubTable.FunctionName}添加按钮操作 */
function handleAdd${genTable.SubTable.ClassName}() {
let obj = {};
//下面的代码自己设置默认值
$foreach(column in genTable.SubTable.Columns)
$if(column.IsPK || column.CsharpField == genTable.SubTableFkName)
$elseif(column.IsList == true && "" != column.CsharpField)
Binary file not shown.
@@ -1,4 +1,4 @@
namespace ZR.CodeGenerator.Model
namespace ZR.CodeGenerator
{
public class CodeGenerateOption
{
@@ -39,6 +39,11 @@
/// Api控制器命名空间
/// </summary>
public string ApiControllerNamespace { get; set; }
/// <summary>
/// 去掉的表头字符
/// </summary>
public string ReplaceTableNameStr { get; set; }
/// <summary>
/// 要生数据的表,用“,”分割
/// </summary>
+5 -1
View File
@@ -1,4 +1,8 @@
namespace ZR.CodeGenerator
using System;
using System.Linq;
using System.Text;
namespace ZR.CodeGenerator
{
/// <summary>
/// 代码生成模板
+72 -80
View File
@@ -9,7 +9,7 @@ using System.Collections.Generic;
using System.IO;
using System.Linq;
using ZR.CodeGenerator.Model;
using ZR.Model.System.Generate;
using ZR.ServiceCore.Model.Generate;
namespace ZR.CodeGenerator
{
@@ -27,8 +27,8 @@ namespace ZR.CodeGenerator
/// <param name="dto"></param>
public static void Generate(GenerateDto dto)
{
var genOptions = AppSettings.Get<CodeGen>("codeGen");
dto.VueParentPath = "Frontend";
var genOptions = AppSettings.Get<Gen>("gen");
dto.VueParentPath = dto.VueVersion == 3 ? "ZRAdmin-vue" : "ZR.Vue";
if (!genOptions.VuePath.IsEmpty())
{
dto.VueParentPath = genOptions.VuePath;
@@ -38,10 +38,6 @@ namespace ZR.CodeGenerator
{
dto.SubTableOptions = GenerateOption(dto.GenTable.SubTable);
}
if (dto.GenTable.SubTableName.IsNotEmpty() && dto.GenTable.SubTable == null)
{
throw new CustomException($"{dto.GenTable.SubTableName}子表不存在");
}
ReplaceDto replaceDto = new()
{
@@ -57,9 +53,7 @@ namespace ZR.CodeGenerator
ShowBtnMultiDel = dto.GenTable.Options.CheckedBtn.Any(f => f == 7),
ShowBtnImport = dto.GenTable.Options.CheckedBtn.Any(f => f == 8),
ViewFileName = dto.GenTable.BusinessName.FirstUpperCase(),
OperBtnStyle = dto.GenTable.Options.OperBtnStyle,
UseSnowflakeId = dto.GenTable.Options.UseSnowflakeId,
EnableLog = dto.GenTable.Options.EnableLog
OperBtnStyle = dto.GenTable.Options.OperBtnStyle
};
var columns = dto.GenTable.Columns;
@@ -75,17 +69,13 @@ namespace ZR.CodeGenerator
GenerateModels(replaceDto, dto);
GenerateService(replaceDto, dto);
GenerateControllers(replaceDto, dto);
if (dto.GenTable.Options.FrontTpl == 2)
if (dto.VueVersion == 3)
{
GenerateVue3Views(replaceDto, dto);
}
else if (dto.GenTable.Options.FrontTpl == 1)
{
GenerateVueViews(replaceDto, dto);
}
else
{
GenerateAntDesignViews(replaceDto, dto);
GenerateVueViews(replaceDto, dto);
}
if (dto.GenTable.Options.GenerateRepo == 1)
{
@@ -128,9 +118,8 @@ namespace ZR.CodeGenerator
/// <param name="replaceDto">替换实体</param>
private static void GenerateModels(ReplaceDto replaceDto, GenerateDto generateDto)
{
var path = Path.Combine(CodeTemplateDir, "csharp");
var tpl = JnHelper.ReadTemplate(path, "TplModel.txt");
var tplDto = JnHelper.ReadTemplate(path, "TplDto.txt");
var tpl = JnHelper.ReadTemplate(CodeTemplateDir, "TplModel.txt");
var tplDto = JnHelper.ReadTemplate(CodeTemplateDir, "TplDto.txt");
string fullPath = Path.Combine(generateDto.GenOptions.ModelsNamespace, "Models", generateDto.GenOptions.SubNamespace, replaceDto.ModelTypeName + ".cs");
string fullPathDto = Path.Combine(generateDto.GenOptions.ModelsNamespace, "Dto", generateDto.GenOptions.SubNamespace, replaceDto.ModelTypeName + "Dto.cs");
@@ -146,7 +135,7 @@ namespace ZR.CodeGenerator
/// <param name="replaceDto">替换实体</param>
private static void GenerateRepository(ReplaceDto replaceDto, GenerateDto generateDto)
{
var tpl = JnHelper.ReadTemplate(Path.Combine(CodeTemplateDir, "csharp"), "TplRepository.txt");
var tpl = JnHelper.ReadTemplate(CodeTemplateDir, "TplRepository.txt");
var result = tpl.Render();
var fullPath = Path.Combine(generateDto.GenOptions.RepositoriesNamespace, generateDto.GenOptions.SubNamespace, $"{replaceDto.ModelTypeName}Repository.cs");
@@ -158,9 +147,8 @@ namespace ZR.CodeGenerator
/// </summary>
private static void GenerateService(ReplaceDto replaceDto, GenerateDto generateDto)
{
var path = Path.Combine(CodeTemplateDir, "csharp");
var tpl = JnHelper.ReadTemplate(path, "TplService.txt");
var tpl2 = JnHelper.ReadTemplate(path, "TplIService.txt");
var tpl = JnHelper.ReadTemplate(CodeTemplateDir, "TplService.txt");
var tpl2 = JnHelper.ReadTemplate(CodeTemplateDir, "TplIService.txt");
var fullPath = Path.Combine(generateDto.GenOptions.ServicesNamespace, generateDto.GenOptions.SubNamespace, $"{replaceDto.ModelTypeName}Service.cs");
var fullPath2 = Path.Combine(generateDto.GenOptions.IServicsNamespace, generateDto.GenOptions.SubNamespace, $"I{generateDto.GenOptions.SubNamespace}Service", $"I{replaceDto.ModelTypeName}Service.cs");
@@ -174,7 +162,7 @@ namespace ZR.CodeGenerator
/// </summary>
private static void GenerateControllers(ReplaceDto replaceDto, GenerateDto generateDto)
{
var tpl = JnHelper.ReadTemplate(Path.Combine(CodeTemplateDir, "csharp"), "TplControllers.txt");
var tpl = JnHelper.ReadTemplate(CodeTemplateDir, "TplControllers.txt");
tpl.Set("QueryCondition", replaceDto.QueryCondition);
var result = tpl.Render();
@@ -192,11 +180,9 @@ namespace ZR.CodeGenerator
"select" => "TplVueSelect.txt",
_ => "TplVue.txt",
};
var path = Path.Combine(CodeTemplateDir, "vue2");
fileName = Path.Combine("vue2", fileName);
replaceDto.VueViewListHtml = JnHelper.ReadTemplate(path, "TableList.txt").Render();
replaceDto.VueQueryFormHtml = JnHelper.ReadTemplate(path, "QueryForm.txt").Render();
replaceDto.VueViewFormHtml = JnHelper.ReadTemplate(path, "CurdForm.txt").Render();
replaceDto.VueViewListHtml = GenerateVueTableList();
replaceDto.VueQueryFormHtml = GenerateVueQueryForm();
replaceDto.VueViewFormHtml = GenerateCurdForm();
var tpl = JnHelper.ReadTemplate(CodeTemplateDir, fileName);
var fullPath = Path.Combine(generateDto.VueParentPath, "src", "views", generateDto.GenTable.ModuleName.FirstLowerCase(), $"{replaceDto.ViewFileName}.vue");
@@ -227,29 +213,6 @@ namespace ZR.CodeGenerator
generateDto.GenCodes.Add(new GenCode(16, "index.vue", fullPath, result));
}
/// <summary>
/// AntDesign
/// </summary>
/// <param name="generateDto"></param>
private static void GenerateAntDesignViews(ReplaceDto replaceDto, GenerateDto generateDto)
{
string fileName = generateDto.GenTable.TplCategory switch
{
"tree" => "TreeVue.txt",
_ => "Vue2.txt",
};
fileName = Path.Combine("antDesign", fileName);
var tpl = JnHelper.ReadTemplate(CodeTemplateDir, fileName);
tpl.Set("treeCode", generateDto.GenTable?.Options?.TreeCode?.FirstLowerCase());
tpl.Set("treeName", generateDto.GenTable?.Options?.TreeName?.FirstLowerCase());
tpl.Set("treeParentCode", generateDto.GenTable?.Options?.TreeParentCode?.FirstLowerCase());
tpl.Set("options", generateDto.GenTable?.Options);
var result = tpl.Render();
var fullPath = Path.Combine(generateDto.VueParentPath, "src", "views", generateDto.GenTable.ModuleName.FirstLowerCase(), $"{replaceDto.ViewFileName}.vue");
generateDto.GenCodes.Add(new GenCode(16, "index.vue", fullPath, result));
}
/// <summary>
/// 生成vue页面api
/// </summary>
@@ -292,9 +255,35 @@ namespace ZR.CodeGenerator
var result = tpl.Render();
string fullPath = Path.Combine(generateDto.GenCodePath, "sql", generateDto.GenTable.BusinessName + ".sql");
generateDto.GenCodes.Add(new GenCode(8, "sql菜单", fullPath, result));
generateDto.GenCodes.Add(new GenCode(8, "sql", fullPath, result));
}
/// <summary>
/// 生成vue页面查询form
/// </summary>
/// <returns></returns>
public static string GenerateVueQueryForm()
{
return JnHelper.ReadTemplate(CodeTemplateDir, "QueryForm.txt").Render();
}
/// <summary>
/// 生成vue页面table
/// </summary>
/// <returns></returns>
public static string GenerateVueTableList()
{
return JnHelper.ReadTemplate(CodeTemplateDir, "TableList.txt").Render();
}
/// <summary>
/// 生成vue表单
/// </summary>
/// <returns></returns>
public static string GenerateCurdForm()
{
return JnHelper.ReadTemplate(CodeTemplateDir, "CurdForm.txt").Render();
}
#endregion
#region app页面
@@ -351,8 +340,11 @@ namespace ZR.CodeGenerator
/// </summary>
/// <param name="tableName"></param>
/// <returns></returns>
public static string GetClassName(string tableName, bool autoRemovePre, string tablePrefix)
public static string GetClassName(string tableName)
{
bool autoRemovePre = AppSettings.GetAppConfig(GenConstants.Gen_autoPre, false);
string tablePrefix = AppSettings.GetAppConfig<string>(GenConstants.Gen_tablePrefix);
if (!string.IsNullOrEmpty(tablePrefix) && autoRemovePre)
{
string[] prefixList = tablePrefix.Split(",", StringSplitOptions.RemoveEmptyEntries);
@@ -429,32 +421,32 @@ namespace ZR.CodeGenerator
/// <summary>
/// 初始化表信息
/// </summary>
/// <param name="dto"></param>
/// <param name="dbName"></param>
/// <param name="userName"></param>
/// <param name="tableName"></param>
/// <param name="desc"></param>
/// <returns></returns>
public static GenTable InitTable(InitTableDto dto)
public static GenTable InitTable(string dbName, string userName, string tableName, string desc)
{
var className = GetClassName(dto.TableName, dto.CodeGen.AutoPre, dto.CodeGen.TablePrefix);
GenTable genTable = new()
{
DbName = dto.DbName,
DbName = dbName,
BaseNameSpace = "ZR.",//导入默认命名空间前缀
ModuleName = dto.CodeGen.ModuleName,//导入默认模块名
ClassName = className,
BusinessName = className,
FunctionAuthor = dto.CodeGen.Author,
TableName = dto.TableName,
TableComment = dto.Desc,
FunctionName = dto.Desc,
Create_by = dto.UserName,
Options = new CodeOptions()
ModuleName = "business",//导入默认模块名
ClassName = GetClassName(tableName),
BusinessName = GetClassName(tableName),
FunctionAuthor = AppSettings.GetConfig(GenConstants.Gen_author),
TableName = tableName,
TableComment = desc,
FunctionName = desc,
Create_name = userName,
Options = new Options()
{
SortType = "asc",
CheckedBtn = new int[] { 1, 2, 3 },
PermissionPrefix = className.ToLower(),
FrontTpl = dto.FrontTpl
CheckedBtn = new int[] { 1, 2, 3 }
}
};
genTable.Options.PermissionPrefix = $"{genTable.ModuleName.ToLower()}:{genTable.ClassName.ToLower()}";//权限
return genTable;
}
@@ -465,16 +457,16 @@ namespace ZR.CodeGenerator
/// <param name="genTable"></param>
/// <param name="dbColumnInfos"></param>
/// <param name="seqs"></param>
/// <param name="codeGen"></param>
public static List<GenTableColumn> InitGenTableColumn(GenTable genTable, List<DbColumnInfo> dbColumnInfos, List<OracleSeq> seqs = null, CodeGen codeGen = null)
public static List<GenTableColumn> InitGenTableColumn(GenTable genTable, List<DbColumnInfo> dbColumnInfos, List<OracleSeq> seqs = null)
{
OptionsSetting optionsSetting = new();
var dbConfig = AppSettings.Get<DbConfigs>(nameof(GenConstants.CodeGenDbConfig));
optionsSetting.CodeGenDbConfig = dbConfig ?? throw new CustomException("代码生成节点数据配置异常"); ;
optionsSetting.CodeGen = codeGen ?? throw new CustomException("代码生成节点配置异常");
var gen = AppSettings.Get<Gen>("gen");
var dbConfig = AppSettings.Get<DbConfigs>("CodeGenDbConfig");
optionsSetting.CodeGenDbConfig = dbConfig;
optionsSetting.Gen = gen ?? throw new CustomException("代码生成节点配置异常");
optionsSetting.Gen.GenDbConfig = dbConfig ?? throw new CustomException("代码生成节点数据配置异常");
List<GenTableColumn> genTableColumns = new();
foreach (var column in dbColumnInfos)
{
@@ -494,7 +486,7 @@ namespace ZR.CodeGenerator
private static GenTableColumn InitColumnField(GenTable genTable, DbColumnInfo column, List<OracleSeq> seqs, OptionsSetting optionsSetting)
{
var dataType = column.DataType;
if (optionsSetting.CodeGenDbConfig.DbType == 3)
if (optionsSetting.Gen.GenDbConfig.DbType == 3)
{
dataType = column.OracleDataType;
var seqName = $"SEQ_{genTable.TableName}_{column.DbColumnName}";
@@ -509,7 +501,7 @@ namespace ZR.CodeGenerator
ColumnType = dataType,
TableId = genTable.TableId,
TableName = genTable.TableName,
CsharpType = GetCSharpDatatype(dataType, optionsSetting.CodeGen.CsharpTypeArr).ToString(),
CsharpType = GetCSharpDatatype(dataType, optionsSetting.Gen.CsharpTypeArr).ToString(),
CsharpField = column.DbColumnName.ConvertToPascal("_"),
IsRequired = !column.IsNullable,
IsIncrement = column.IsIdentity,
@@ -612,7 +604,7 @@ namespace ZR.CodeGenerator
options.Data.Set("showCustomInput", showCustomInput);
options.Data.Set("tool", new CodeGeneratorTool());
options.Data.Set("codeTool", new CodeGenerateTemplate());
options.Data.Set("dicts", dicts.DistinctBy(x => x.DictType));
options.Data.Set("dicts", dicts);
options.Data.Set("sub", dto.GenTable.SubTable != null && dto.GenTable.SubTableName.IsNotEmpty());
options.EnableCache = true;
//...其它数据
+3 -2
View File
@@ -7,8 +7,9 @@ namespace ZR.CodeGenerator
/// </summary>
public class GenConstants
{
public static string Gen_author = "codeGen:author";
public static string CodeGenDbConfig;
public static string Gen_author = "gen:author";
public static string Gen_autoPre = "gen:autoPre";
public static string Gen_tablePrefix = "gen:tablePrefix";
/// <summary>
/// InputDto输入实体是不包含字段
+1 -1
View File
@@ -1,5 +1,5 @@
using System.Collections.Generic;
using ZR.Model.System.Generate;
using ZR.ServiceCore.Model.Generate;
namespace ZR.CodeGenerator.Model
{
@@ -1,17 +0,0 @@
using System.Collections.Generic;
namespace ZR.CodeGenerator.Model
{
public class ImportCodeGenTableDto
{
public int FrontTpl { get; set; }
public string DbName { get; set; }
public List<CodeGenTables> Tables { get; set; }
}
public class CodeGenTables
{
public string Name { get; set; }
public string Description { get; set; }
}
}
-14
View File
@@ -1,14 +0,0 @@
using Infrastructure.Model;
namespace ZR.CodeGenerator.Model
{
public class InitTableDto
{
public int FrontTpl { get; set; }
public string DbName { get; set; }
public string UserName { get; set; }
public string TableName { get; set; }
public string Desc { get; set; }
public CodeGen CodeGen { get; set; }
}
}
-5
View File
@@ -74,10 +74,5 @@ namespace ZR.CodeGenerator.Model
/// 操作按钮样式
/// </summary>
public int OperBtnStyle { get; set; }
/// <summary>
/// 是否使用雪花id
/// </summary>
public bool UseSnowflakeId { get; set; }
public bool EnableLog { get; set; }
}
}
@@ -18,7 +18,7 @@ namespace ZR.CodeGenerator.Service
{
var db = GetSugarDbContext();
//Oracle库特殊处理
DbConfigs configs = AppSettings.Get<DbConfigs>(nameof(GenConstants.CodeGenDbConfig));
DbConfigs configs = AppSettings.Get<DbConfigs>(nameof(GlobalConstant.CodeGenDbConfig));
if (configs.DbType == 3)
{
return new List<string>() { configs?.DbName };
+2 -2
View File
@@ -11,7 +11,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="JinianNet.JNTemplate" Version="2.4.2" />
<PackageReference Include="SqlSugarCoreNoDrive" Version="5.1.4.130" />
<PackageReference Include="JinianNet.JNTemplate" Version="2.3.3" />
<PackageReference Include="SqlSugarCoreNoDrive" Version="5.1.4.109" />
</ItemGroup>
</Project>

Some files were not shown because too many files have changed in this diff Show More