diff --git a/README.md b/README.md index 6a818617e5102cc3fbe780450e15bd9f87976162..c0e1a9e8f8c98ef22e91b2570c1db6f984548b34 100644 --- a/README.md +++ b/README.md @@ -42,8 +42,9 @@ - 租户管理(未实现,理论阶段) -- .net4.5版地址:https://gitee.com/qian_wei_hong/WaterCloud/tree/net4.5 -- .netcore3.1版地址:https://gitee.com/qian_wei_hong/WaterCloud/tree/core3.1 +- .net5-SqlSugar版地址:https://gitee.com/qian_wei_hong/WaterCloud +- .net4.5版地址:https://gitee.com/qian_wei_hong/WaterCloud/tree/net4.5-Chloe +- .netcore3.1版地址:https://gitee.com/qian_wei_hong/WaterCloud/tree/core3.1-Chloe - 项目演示地址:http://106.75.169.226:5000/ (账号:admin 密码:0000,数据库2个小时还原一次) - 文档地址:https://gitee.com/qian_wei_hong/WaterCloud/wikis/pages diff --git a/WaterCloud.Code/DistributedIDGenerator/Enums/SequentialGuidType.cs b/WaterCloud.Code/DistributedIDGenerator/Enums/SequentialGuidType.cs new file mode 100644 index 0000000000000000000000000000000000000000..bfd1959aeb360d9c95b0ca77c4a843cb85993682 --- /dev/null +++ b/WaterCloud.Code/DistributedIDGenerator/Enums/SequentialGuidType.cs @@ -0,0 +1,40 @@ +// ----------------------------------------------------------------------------- +// 让 .NET 开发更简单,更通用,更流行。 +// Copyright © 2020-2021 Furion, 百小僧, Baiqian Co.,Ltd. +// +// 框架名称:Furion +// 框架作者:百小僧 +// 框架版本:2.7.9 +// 源码地址:Gitee: https://gitee.com/dotnetchina/Furion +// Github:https://github.com/monksoul/Furion +// 开源协议:Apache-2.0(https://gitee.com/dotnetchina/Furion/blob/master/LICENSE) +// ----------------------------------------------------------------------------- + +using System.ComponentModel; + +namespace WaterCloud.Code +{ + /// + /// 连续 GUID 类型选项 + /// + public enum SequentialGuidType + { + /// + /// 标准连续 GUID 字符串 + /// + [Description("标准连续 GUID 字符串")] + SequentialAsString, + + /// + /// Byte 数组类型的连续 `GUID` 字符串 + /// + [Description("Byte 数组类型的连续 `GUID` 字符串")] + SequentialAsBinary, + + /// + /// 连续部分在末尾展示 + /// + [Description("连续部分在末尾展示")] + SequentialAtEnd + } +} \ No newline at end of file diff --git a/WaterCloud.Code/DistributedIDGenerator/Generators/IDistributedIDGenerator.cs b/WaterCloud.Code/DistributedIDGenerator/Generators/IDistributedIDGenerator.cs new file mode 100644 index 0000000000000000000000000000000000000000..341c2409139ebdf29d00258e82f4ef74460002d5 --- /dev/null +++ b/WaterCloud.Code/DistributedIDGenerator/Generators/IDistributedIDGenerator.cs @@ -0,0 +1,27 @@ +// ----------------------------------------------------------------------------- +// 让 .NET 开发更简单,更通用,更流行。 +// Copyright © 2020-2021 Furion, 百小僧, Baiqian Co.,Ltd. +// +// 框架名称:Furion +// 框架作者:百小僧 +// 框架版本:2.7.9 +// 源码地址:Gitee: https://gitee.com/dotnetchina/Furion +// Github:https://github.com/monksoul/Furion +// 开源协议:Apache-2.0(https://gitee.com/dotnetchina/Furion/blob/master/LICENSE) +// ----------------------------------------------------------------------------- + +namespace WaterCloud.Code +{ + /// + /// 分布式 ID 生成器 + /// + public interface IDistributedIDGenerator + { + /// + /// 生成逻辑 + /// + /// + /// + object Create(object idGeneratorOptions = default); + } +} \ No newline at end of file diff --git a/WaterCloud.Code/DistributedIDGenerator/Generators/SequentialGuidIDGenerator.cs b/WaterCloud.Code/DistributedIDGenerator/Generators/SequentialGuidIDGenerator.cs new file mode 100644 index 0000000000000000000000000000000000000000..286a20de673ea279e1e18e29456326070a65ac88 --- /dev/null +++ b/WaterCloud.Code/DistributedIDGenerator/Generators/SequentialGuidIDGenerator.cs @@ -0,0 +1,86 @@ +// ----------------------------------------------------------------------------- +// 让 .NET 开发更简单,更通用,更流行。 +// Copyright © 2020-2021 Furion, 百小僧, Baiqian Co.,Ltd. +// +// 框架名称:Furion +// 框架作者:百小僧 +// 框架版本:2.7.9 +// 源码地址:Gitee: https://gitee.com/dotnetchina/Furion +// Github:https://github.com/monksoul/Furion +// 开源协议:Apache-2.0(https://gitee.com/dotnetchina/Furion/blob/master/LICENSE) +// ----------------------------------------------------------------------------- + +using System; +using System.Security.Cryptography; + +namespace WaterCloud.Code +{ + /// + /// 连续 GUID ID 生成器 + /// 代码参考自:https://github.com/PomeloFoundation/Pomelo.EntityFrameworkCore.MySql/blob/ebe011a6f1b2a2a9709fe558cfc7ed3215b55c37/src/EFCore.MySql/ValueGeneration/Internal/MySqlSequentialGuidValueGenerator.cs + /// + public class SequentialGuidIDGenerator : IDistributedIDGenerator + { + /// + /// 随机数生成器 + /// + private static readonly RandomNumberGenerator _rng = RandomNumberGenerator.Create(); + + /// + /// 生成逻辑 + /// + /// + /// + public object Create(object idGeneratorOptions = null) + { + // According to RFC 4122: + // dddddddd-dddd-Mddd-Ndrr-rrrrrrrrrrrr + // - M = RFC version, in this case '4' for random UUID + // - N = RFC variant (plus other bits), in this case 0b1000 for variant 1 + // - d = nibbles based on UTC date/time in ticks + // - r = nibbles based on random bytes + + var options = (idGeneratorOptions ?? new SequentialGuidSettings()) as SequentialGuidSettings; + + var randomBytes = new byte[7]; + _rng.GetBytes(randomBytes); + var ticks = (ulong)options.TimeNow.Ticks; + + var uuidVersion = (ushort)4; + var uuidVariant = (ushort)0b1000; + + var ticksAndVersion = (ushort)((ticks << 48 >> 52) | (ushort)(uuidVersion << 12)); + var ticksAndVariant = (byte)((ticks << 60 >> 60) | (byte)(uuidVariant << 4)); + + if (options.LittleEndianBinary16Format) + { + var guidBytes = new byte[16]; + var tickBytes = BitConverter.GetBytes(ticks); + if (BitConverter.IsLittleEndian) + { + Array.Reverse(tickBytes); + } + + Buffer.BlockCopy(tickBytes, 0, guidBytes, 0, 6); + guidBytes[6] = (byte)(ticksAndVersion << 8 >> 8); + guidBytes[7] = (byte)(ticksAndVersion >> 8); + guidBytes[8] = ticksAndVariant; + Buffer.BlockCopy(randomBytes, 0, guidBytes, 9, 7); + + return new Guid(guidBytes); + } + + var guid = new Guid((uint)(ticks >> 32), (ushort)(ticks << 32 >> 48), ticksAndVersion, + ticksAndVariant, + randomBytes[0], + randomBytes[1], + randomBytes[2], + randomBytes[3], + randomBytes[4], + randomBytes[5], + randomBytes[6]); + + return guid; + } + } +} \ No newline at end of file diff --git a/WaterCloud.Code/DistributedIDGenerator/IDGen.cs b/WaterCloud.Code/DistributedIDGenerator/IDGen.cs new file mode 100644 index 0000000000000000000000000000000000000000..d8944fd89605773461fb629c8927296af833c8c7 --- /dev/null +++ b/WaterCloud.Code/DistributedIDGenerator/IDGen.cs @@ -0,0 +1,45 @@ +// ----------------------------------------------------------------------------- +// 让 .NET 开发更简单,更通用,更流行。 +// Copyright © 2020-2021 Furion, 百小僧, Baiqian Co.,Ltd. +// +// 框架名称:Furion +// 框架作者:百小僧 +// 框架版本:2.7.9 +// 源码地址:Gitee: https://gitee.com/dotnetchina/Furion +// Github:https://github.com/monksoul/Furion +// 开源协议:Apache-2.0(https://gitee.com/dotnetchina/Furion/blob/master/LICENSE) +// ----------------------------------------------------------------------------- + +using System; + +namespace WaterCloud.Code +{ + /// + /// ID 生成器 + /// + public static class IDGen + { + /// + /// 生成唯一 ID + /// + /// + /// + /// + public static object NextID(object idGeneratorOptions) + { + return ((IDistributedIDGenerator)GlobalContext.ServiceProvider.GetService(typeof(IDistributedIDGenerator))).Create(idGeneratorOptions); + } + + /// + /// 生成连续 GUID + /// + /// + /// + /// + public static Guid NextID(SequentialGuidType guidType = SequentialGuidType.SequentialAsString) + { + var sequentialGuid = GlobalContext.ServiceProvider.GetService(typeof(IDistributedIDGenerator)) as IDistributedIDGenerator; + return (Guid)sequentialGuid.Create(); + } + } +} \ No newline at end of file diff --git a/WaterCloud.Code/DistributedIDGenerator/Settings/SequentialGuidSettings.cs b/WaterCloud.Code/DistributedIDGenerator/Settings/SequentialGuidSettings.cs new file mode 100644 index 0000000000000000000000000000000000000000..44a1ff4cc114872f594c0a82547c02fea85fb5cd --- /dev/null +++ b/WaterCloud.Code/DistributedIDGenerator/Settings/SequentialGuidSettings.cs @@ -0,0 +1,32 @@ +// ----------------------------------------------------------------------------- +// 让 .NET 开发更简单,更通用,更流行。 +// Copyright © 2020-2021 Furion, 百小僧, Baiqian Co.,Ltd. +// +// 框架名称:Furion +// 框架作者:百小僧 +// 框架版本:2.7.9 +// 源码地址:Gitee: https://gitee.com/dotnetchina/Furion +// Github:https://github.com/monksoul/Furion +// 开源协议:Apache-2.0(https://gitee.com/dotnetchina/Furion/blob/master/LICENSE) +// ----------------------------------------------------------------------------- + +using System; + +namespace WaterCloud.Code +{ + /// + /// 连续 GUID 配置 + /// + public sealed class SequentialGuidSettings + { + /// + /// 当前时间 + /// + public DateTimeOffset TimeNow { get; set; } = DateTimeOffset.UtcNow; + + /// + /// LittleEndianBinary 16 格式化 + /// + public bool LittleEndianBinary16Format { get; set; } = false; + } +} \ No newline at end of file diff --git a/WaterCloud.Code/DistributedIDGenerator/ShortID/Internal/Constants.cs b/WaterCloud.Code/DistributedIDGenerator/ShortID/Internal/Constants.cs new file mode 100644 index 0000000000000000000000000000000000000000..3c41ed7ddc20668a7657dde0984e77c11c28e47a --- /dev/null +++ b/WaterCloud.Code/DistributedIDGenerator/ShortID/Internal/Constants.cs @@ -0,0 +1,35 @@ +// ----------------------------------------------------------------------------- +// 让 .NET 开发更简单,更通用,更流行。 +// Copyright © 2020-2021 Furion, 百小僧, Baiqian Co.,Ltd. +// +// 框架名称:Furion +// 框架作者:百小僧 +// 框架版本:2.7.9 +// 源码地址:Gitee: https://gitee.com/dotnetchina/Furion +// Github:https://github.com/monksoul/Furion +// 开源协议:Apache-2.0(https://gitee.com/dotnetchina/Furion/blob/master/LICENSE) +// ----------------------------------------------------------------------------- + +namespace WaterCloud.Code +{ + /// + /// 短 ID 约束 + /// + internal static class Constants + { + /// + /// 最小长度 + /// + public const int MinimumAutoLength = 8; + + /// + /// 最大长度 + /// + public const int MaximumAutoLength = 14; + + /// + /// 最小可选字符长度 + /// + public const int MinimumCharacterSetLength = 50; + } +} \ No newline at end of file diff --git a/WaterCloud.Code/DistributedIDGenerator/ShortID/Internal/RandomHelpers.cs b/WaterCloud.Code/DistributedIDGenerator/ShortID/Internal/RandomHelpers.cs new file mode 100644 index 0000000000000000000000000000000000000000..742b10c7114bbba409997912fffd063ddd14ecd3 --- /dev/null +++ b/WaterCloud.Code/DistributedIDGenerator/ShortID/Internal/RandomHelpers.cs @@ -0,0 +1,46 @@ +// ----------------------------------------------------------------------------- +// 让 .NET 开发更简单,更通用,更流行。 +// Copyright © 2020-2021 Furion, 百小僧, Baiqian Co.,Ltd. +// +// 框架名称:Furion +// 框架作者:百小僧 +// 框架版本:2.7.9 +// 源码地址:Gitee: https://gitee.com/dotnetchina/Furion +// Github:https://github.com/monksoul/Furion +// 开源协议:Apache-2.0(https://gitee.com/dotnetchina/Furion/blob/master/LICENSE) +// ----------------------------------------------------------------------------- + +using System; + +namespace WaterCloud.Code +{ + /// + /// 随机数帮助类 + /// + internal static class RandomHelpers + { + /// + /// 随机数对象 + /// + private static readonly Random Random = new(); + + /// + /// 线程锁 + /// + private static readonly object ThreadLock = new(); + + /// + /// 生成线程安全的范围内随机数 + /// + /// + /// + /// + public static int GenerateNumberInRange(int min, int max) + { + lock (ThreadLock) + { + return Random.Next(min, max); + } + } + } +} \ No newline at end of file diff --git a/WaterCloud.Code/DistributedIDGenerator/ShortID/Options/GenerationOptions.cs b/WaterCloud.Code/DistributedIDGenerator/ShortID/Options/GenerationOptions.cs new file mode 100644 index 0000000000000000000000000000000000000000..1d7d5e32ba820d9e7f018405e30b36e1e7b9e234 --- /dev/null +++ b/WaterCloud.Code/DistributedIDGenerator/ShortID/Options/GenerationOptions.cs @@ -0,0 +1,38 @@ +// ----------------------------------------------------------------------------- +// 让 .NET 开发更简单,更通用,更流行。 +// Copyright © 2020-2021 Furion, 百小僧, Baiqian Co.,Ltd. +// +// 框架名称:Furion +// 框架作者:百小僧 +// 框架版本:2.7.9 +// 源码地址:Gitee: https://gitee.com/dotnetchina/Furion +// Github:https://github.com/monksoul/Furion +// 开源协议:Apache-2.0(https://gitee.com/dotnetchina/Furion/blob/master/LICENSE) +// ----------------------------------------------------------------------------- + + +namespace WaterCloud.Code +{ + /// + /// 短 ID 生成配置选项 + /// + public class GenerationOptions + { + /// + /// 是否使用数字 + /// 默认 false + /// + public bool UseNumbers { get; set; } + + /// + /// 是否使用特殊字符 + /// 默认 true + /// + public bool UseSpecialCharacters { get; set; } = true; + + /// + /// 设置短 ID 长度 + /// + public int Length { get; set; } = RandomHelpers.GenerateNumberInRange(Constants.MinimumAutoLength, Constants.MaximumAutoLength); + } +} \ No newline at end of file diff --git a/WaterCloud.Code/DistributedIDGenerator/ShortID/ShortIDGen.cs b/WaterCloud.Code/DistributedIDGenerator/ShortID/ShortIDGen.cs new file mode 100644 index 0000000000000000000000000000000000000000..4271d43e98237819e45e20ff0ed8bbcc083a8f61 --- /dev/null +++ b/WaterCloud.Code/DistributedIDGenerator/ShortID/ShortIDGen.cs @@ -0,0 +1,161 @@ +// ----------------------------------------------------------------------------- +// 让 .NET 开发更简单,更通用,更流行。 +// Copyright © 2020-2021 Furion, 百小僧, Baiqian Co.,Ltd. +// +// 框架名称:Furion +// 框架作者:百小僧 +// 框架版本:2.7.9 +// 源码地址:Gitee: https://gitee.com/dotnetchina/Furion +// Github:https://github.com/monksoul/Furion +// 开源协议:Apache-2.0(https://gitee.com/dotnetchina/Furion/blob/master/LICENSE) +// ----------------------------------------------------------------------------- + +using System; +using System.Linq; +using System.Text; + +namespace WaterCloud.Code +{ + /// + /// 短 ID 生成核心代码 + /// 代码参考自:https://github.com/bolorundurowb/shortid + /// + public static class ShortIDGen + { + /// + /// 短 ID 生成器期初数据 + /// + private static Random _random = new(); + + private const string Bigs = "ABCDEFGHIJKLMNPQRSTUVWXY"; + private const string Smalls = "abcdefghjklmnopqrstuvwxyz"; + private const string Numbers = "0123456789"; + private const string Specials = "_-"; + private static string _pool = $"{Smalls}{Bigs}"; + + /// + /// 线程安全锁 + /// + private static readonly object ThreadLock = new(); + + /// + /// 生成目前比较主流的短 ID + /// 包含字母、数字,不包含特殊字符 + /// 默认生成 8 位 + /// + /// + public static string NextID() + { + return NextID(new GenerationOptions + { + UseNumbers = true, + UseSpecialCharacters = false, + Length = 8 + }); + } + + /// + /// 生成短 ID + /// + /// + /// + public static string NextID(GenerationOptions options) + { + // 配置必填 + if (options == null) + { + throw new ArgumentNullException(nameof(options)); + } + + // 判断生成的长度是否小于规定的长度,规定为 8 + if (options.Length < Constants.MinimumAutoLength) + { + throw new ArgumentException( + $"The specified length of {options.Length} is less than the lower limit of {Constants.MinimumAutoLength} to avoid conflicts."); + } + + var characterPool = _pool; + var poolBuilder = new StringBuilder(characterPool); + + // 是否包含数字 + if (options.UseNumbers) + { + poolBuilder.Append(Numbers); + } + + // 是否包含特殊字符 + if (options.UseSpecialCharacters) + { + poolBuilder.Append(Specials); + } + + var pool = poolBuilder.ToString(); + + // 生成拼接 + var output = new char[options.Length]; + for (var i = 0; i < options.Length; i++) + { + lock (ThreadLock) + { + var charIndex = _random.Next(0, pool.Length); + output[i] = pool[charIndex]; + } + } + + return new string(output); + } + + /// + /// 设置参与运算的字符,最少 50 位 + /// + /// + public static void SetCharacters(string characters) + { + if (string.IsNullOrWhiteSpace(characters)) + { + throw new ArgumentException("The replacement characters must not be null or empty."); + } + + var charSet = characters + .ToCharArray() + .Where(x => !char.IsWhiteSpace(x)) + .Distinct() + .ToArray(); + + if (charSet.Length < Constants.MinimumCharacterSetLength) + { + throw new InvalidOperationException( + $"The replacement characters must be at least {Constants.MinimumCharacterSetLength} letters in length and without whitespace."); + } + + lock (ThreadLock) + { + _pool = new string(charSet); + } + } + + /// + /// 设置种子步长 + /// + /// + public static void SetSeed(int seed) + { + lock (ThreadLock) + { + _random = new Random(seed); + } + } + + /// + /// 重置所有配置 + /// + public static void Reset() + { + lock (ThreadLock) + { + _random = new Random(); + _pool = $"{Smalls}{Bigs}"; + } + } + } +} \ No newline at end of file diff --git a/WaterCloud.Code/HttpWebClient.cs b/WaterCloud.Code/HttpWebClient.cs new file mode 100644 index 0000000000000000000000000000000000000000..f5ff33f731bbe9da08f6b701002a9d1c41e4a7f4 --- /dev/null +++ b/WaterCloud.Code/HttpWebClient.cs @@ -0,0 +1,239 @@ +using System; +using System.Collections.Generic; +using System.Net.Http; +using System.Threading.Tasks; + +namespace WaterCloud.Code +{ + public class HttpWebClient + { + + private IHttpClientFactory _httpClientFactory; + public HttpWebClient(IHttpClientFactory httpClientFactory) + { + this._httpClientFactory = httpClientFactory; + } + /// + /// Get请求 + /// + /// + /// + /// + /// + //public async Task GetAsync(string url, int timeoutSecond = 120) + //{ + // var client = _httpClientFactory.CreateClient(); + // #region 最好不要这样绑定header, + // //DefaultRequestHeaders是和httpClient绑定的,当完成当前请求后,其它请求从factory中获取时,还是会有绑定的header的 + // //会造成错误 + // //if (dicHeaders != null) + // //{ + // // foreach (var header in dicHeaders) + // // { + // // client.DefaultRequestHeaders.Add(header.Key, header.Value); + // // } + // //} + // #endregion + // client.Timeout = TimeSpan.FromSeconds(timeoutSecond); + // var response = await client.GetAsync(url); + // var result = await response.Content.ReadAsStringAsync(); + // return result; + //} + + + + + /// + /// Get异步请求 + /// + /// + /// + /// + /// + public async Task GetAsync(string url, Dictionary dicHeaders, int timeoutSecond = 120) + { + var client = _httpClientFactory.CreateClient(); + var request = new HttpRequestMessage(HttpMethod.Get, url); + if (dicHeaders != null) + { + foreach (var header in dicHeaders) + { + request.Headers.Add(header.Key, header.Value); + } + } + client.Timeout = TimeSpan.FromSeconds(timeoutSecond); + var response = await client.SendAsync(request); + if (response.IsSuccessStatusCode) + { + var result = await response.Content.ReadAsStringAsync(); + return result; + } + else + { + throw new CustomerHttpException($"接口请求错误,错误代码{response.StatusCode},错误原因{response.ReasonPhrase}"); + + } + } + /// + /// + /// + /// + /// + /// + /// + /// + public async Task PostAsync(string url, string requestString, Dictionary dicHeaders, int timeoutSecond) + { + var client = _httpClientFactory.CreateClient(); + var requestContent = new StringContent(requestString); + if (dicHeaders != null) + { + foreach (var head in dicHeaders) + { + requestContent.Headers.Add(head.Key, head.Value); + } + } + client.Timeout = TimeSpan.FromSeconds(timeoutSecond); + var response = await client.PostAsync(url, requestContent); + if (response.IsSuccessStatusCode) + { + var result = await response.Content.ReadAsStringAsync(); + return result; + } + else + { + throw new CustomerHttpException($"接口请求错误,错误代码{response.StatusCode},错误原因{response.ReasonPhrase}"); + } + } + /// + /// + /// + /// + /// + /// + /// + /// + public async Task PutAsync(string url, string requestString, Dictionary dicHeaders, int timeoutSecond) + { + var client = _httpClientFactory.CreateClient(); + var requestContent = new StringContent(requestString); + if (dicHeaders != null) + { + foreach (var head in dicHeaders) + { + requestContent.Headers.Add(head.Key, head.Value); + } + } + client.Timeout = TimeSpan.FromSeconds(timeoutSecond); + var response = await client.PutAsync(url, requestContent); + if (response.IsSuccessStatusCode) + { + var result = await response.Content.ReadAsStringAsync(); + return result; + } + else + { + throw new CustomerHttpException($"接口请求错误,错误代码{response.StatusCode},错误原因{response.ReasonPhrase}"); + } + } + + /// + /// Patch异步请求 + /// + /// + /// + /// + /// + /// + public async Task PatchAsync(string url, string requestString, Dictionary dicHeaders, int timeoutSecond) + { + var client = _httpClientFactory.CreateClient(); + var requestContent = new StringContent(requestString); + if (dicHeaders != null) + { + foreach (var head in dicHeaders) + { + requestContent.Headers.Add(head.Key, head.Value); + } + } + client.Timeout = TimeSpan.FromSeconds(timeoutSecond); + var response = await client.PatchAsync(url, requestContent); + if (response.IsSuccessStatusCode) + { + var result = await response.Content.ReadAsStringAsync(); + return result; + } + else + { + throw new CustomerHttpException($"接口请求错误,错误代码{response.StatusCode},错误原因{response.ReasonPhrase}"); + } + } + public async Task DeleteAsync(string url, Dictionary dicHeaders, int timeoutSecond) + { + var client = _httpClientFactory.CreateClient(); + var request = new HttpRequestMessage(HttpMethod.Delete, url); + if (dicHeaders != null) + { + foreach (var head in dicHeaders) + { + request.Headers.Add(head.Key, head.Value); + } + } + client.Timeout = TimeSpan.FromSeconds(timeoutSecond); + var response = await client.SendAsync(request); + if (response.IsSuccessStatusCode) + { + var result = await response.Content.ReadAsStringAsync(); + return result; + } + else + { + throw new CustomerHttpException($"接口请求错误,错误代码{response.StatusCode},错误原因{response.ReasonPhrase}"); + } + } + /// + /// 异步请求(通用) + /// + /// + /// + /// + /// + /// + /// + public async Task ExecuteAsync(string url, HttpMethod method, string requestString, Dictionary dicHeaders, int timeoutSecond = 120) + { + var client = _httpClientFactory.CreateClient(); + var request = new HttpRequestMessage(method, url) + { + Content = new StringContent(requestString), + }; + if (dicHeaders != null) + { + foreach (var header in dicHeaders) + { + request.Headers.Add(header.Key, header.Value); + } + } + var response = await client.SendAsync(request); + if (response.IsSuccessStatusCode) + { + var result = await response.Content.ReadAsStringAsync(); + return result; + } + else + { + throw new CustomerHttpException($"接口请求错误,错误代码{response.StatusCode},错误原因{response.ReasonPhrase}"); + } + } + + } + public class CustomerHttpException : Exception + { + public CustomerHttpException() : base() + { } + public CustomerHttpException(string message) : base(message) + { + + } + } +} diff --git a/WaterCloud.Code/Model/SystemConfig.cs b/WaterCloud.Code/Model/SystemConfig.cs index 9ae59dc0a5cf59f3a7d0c5dc4a012baf6cd4bce1..aa6ce499d6d5790cedae3b46fe6b3f3261ce95de 100644 --- a/WaterCloud.Code/Model/SystemConfig.cs +++ b/WaterCloud.Code/Model/SystemConfig.cs @@ -62,8 +62,12 @@ namespace WaterCloud.Code.Model public string MainProgram { get; set; } public bool? LocalLAN { get; set; } /// - /// 雪花id配置 + /// 项目前缀 /// - public int WorkId { get; set; } - } + public string ProjectPrefix { get; set; } + /// + /// 重置密码 + /// + public bool? ReviseSysem { get; set; } + } } diff --git a/WaterCloud.Code/Operator/OperatorProvider.cs b/WaterCloud.Code/Operator/OperatorProvider.cs index 37cb82a29171a862f6ddf71103fe90a1f5173c8a..d2e4ec1a9cfad2d1860847ffbe264f6d9fe2a3fe 100644 --- a/WaterCloud.Code/Operator/OperatorProvider.cs +++ b/WaterCloud.Code/Operator/OperatorProvider.cs @@ -15,11 +15,12 @@ namespace WaterCloud.Code public class OperatorProvider { //登录信息保存方式 - private string LoginProvider = GlobalContext.SystemConfig.LoginProvider; + private static string LoginProvider = GlobalContext.SystemConfig.LoginProvider; //是否允许一个账户在多处登录 - private bool LoginMultiple = GlobalContext.SystemConfig.LoginMultiple; + private static bool LoginMultiple = GlobalContext.SystemConfig.LoginMultiple; //缓存过期时间 - private int LoginExpire = GlobalContext.SystemConfig.LoginExpire; + private static int LoginExpire = GlobalContext.SystemConfig.LoginExpire; + private static string projectPrefix = GlobalContext.SystemConfig.ProjectPrefix; public static OperatorProvider Provider { get { return new OperatorProvider(); } @@ -30,17 +31,17 @@ namespace WaterCloud.Code /// /// 缓存操作类 /// - private string cacheKeyOperator = "watercloud_operator_";// +登录者token - private string cacheKeyToken = "watercloud_token_";// +登录者token - private string cacheKeyError = "watercloud_error_";// + Mark + private string cacheKeyOperator = projectPrefix + "_operator_";// +登录者token + private string cacheKeyToken = projectPrefix + "_token_";// +登录者token + private string cacheKeyError = projectPrefix + "_error_";// + Mark /// /// 秘钥 /// - private string LoginUserToken = "watercloud_Token"; + private string LoginUserToken = projectPrefix + "_Token"; /// /// 标记登录的浏览器 /// - private string LoginUserMarkKey = "watercloud_Mark"; + private string LoginUserMarkKey = projectPrefix + "_Mark"; public string GetProvider(string key) { switch (LoginProvider) @@ -295,32 +296,14 @@ namespace WaterCloud.Code OperatorModel operatorInfo = await CacheHelper.Get(cacheKeyOperator + loginMark); if (operatorInfo != null) { - if (operatorInfo.LoginToken == token || LoginProvider == Define.PROVIDER_WEBAPI) + Dictionary tokenMarkList = await CacheHelper.Get>(cacheKeyToken + operatorInfo.UserId); + if ((token == operatorInfo.LoginToken || LoginProvider == Define.PROVIDER_WEBAPI) && tokenMarkList.ContainsKey(operatorInfo.loginMark) && tokenMarkList[operatorInfo.loginMark] == operatorInfo.LoginToken) { - //TimeSpan span = (TimeSpan)(DateTime.Now - operatorInfo.LoginTime); - ////超时 - //if (span.TotalHours >= 12)// 登录操作过12小时移除 - //{ - // operatorResult.stateCode = 0; - // Dictionary tokenMarkList = await CacheHelper.Get>(cacheKeyToken + operatorInfo.UserId); - // tokenMarkList.Remove(loginMark); - // await CacheHelper.Set(cacheKeyToken + operatorInfo.UserId, tokenMarkList); - // await CacheHelper.Remove(cacheKeyOperator + loginMark); - //} ////账号被顶(排除admin) - //else if (!LoginMultiple && !operatorInfo.IsSystem && token != await CacheHelper.Get(cacheKeyOperator + facilityMark + operatorInfo.UserId)) - if (!LoginMultiple && !operatorInfo.IsSystem && token != await CacheHelper.Get(cacheKeyOperator + facilityMark + operatorInfo.UserId)) - { - operatorResult.stateCode = -2; - Dictionary tokenMarkList = await CacheHelper.Get>(cacheKeyToken + operatorInfo.UserId); - tokenMarkList.Remove(loginMark); - await CacheHelper.Set(cacheKeyToken + operatorInfo.UserId, tokenMarkList); - await CacheHelper.Remove(cacheKeyOperator + loginMark); - } - else if (LoginProvider == Define.PROVIDER_WEBAPI && !operatorInfo.IsSystem && operatorInfo.LoginToken != await CacheHelper.Get(cacheKeyOperator + facilityMark + operatorInfo.UserId)) + if (!LoginMultiple && !operatorInfo.IsSystem && operatorInfo.LoginToken != await CacheHelper.Get(cacheKeyOperator + facilityMark + operatorInfo.UserId)) { operatorResult.stateCode = -2; - Dictionary tokenMarkList = await CacheHelper.Get>(cacheKeyToken + operatorInfo.UserId); + tokenMarkList = await CacheHelper.Get>(cacheKeyToken + operatorInfo.UserId); tokenMarkList.Remove(loginMark); await CacheHelper.Set(cacheKeyToken + operatorInfo.UserId, tokenMarkList); await CacheHelper.Remove(cacheKeyOperator + loginMark); diff --git a/WaterCloud.Code/Snowflake/Generators/DefaultIDGenerator.cs b/WaterCloud.Code/Snowflake/Generators/DefaultIDGenerator.cs deleted file mode 100644 index d4521137d9e76464151db021e1d8ab70b76471e5..0000000000000000000000000000000000000000 --- a/WaterCloud.Code/Snowflake/Generators/DefaultIDGenerator.cs +++ /dev/null @@ -1,91 +0,0 @@ -using System; -using System.Threading; - -namespace WaterCloud.Code -{ - /// - /// 默认实现 - /// - public class DefaultIDGenerator : IIDGenerator - { - /// - /// 雪花算法接口实例 - /// - private ISnowflakeWorker InternalSnowflakeWorker { get; set; } - - /// - /// 构造函数 - /// - /// - public DefaultIDGenerator(IDGeneratorOptions options) - { - if (options == null) - { - throw new ApplicationException("options error."); - } - - if (options.BaseTime < DateTime.Now.AddYears(-50) || options.BaseTime > DateTime.Now) - { - throw new ApplicationException("BaseTime error."); - } - - if (options.SeqBitLength + options.WorkerIdBitLength > 22) - { - throw new ApplicationException("error:WorkerIdBitLength + SeqBitLength <= 22."); - } - - var maxWorkerIdNumber = Math.Pow(2, options.WorkerIdBitLength) - 1; - if (options.WorkerId < 0 || options.WorkerId > maxWorkerIdNumber) - { - throw new ApplicationException("WorkerId error. (range:[1, " + maxWorkerIdNumber + "]."); - } - - if (options.SeqBitLength < 2 || options.SeqBitLength > 21) - { - throw new ApplicationException("SeqBitLength error. (range:[2, 21])."); - } - - var maxSeqNumber = Math.Pow(2, options.SeqBitLength) - 1; - if (options.MaxSeqNumber < 0 || options.MaxSeqNumber > maxSeqNumber) - { - throw new ApplicationException("MaxSeqNumber error. (range:[1, " + maxSeqNumber + "]."); - } - - var maxValue = maxSeqNumber; // maxSeqNumber - 1; - if (options.MinSeqNumber < 1 || options.MinSeqNumber > maxValue) - { - throw new ApplicationException("MinSeqNumber error. (range:[1, " + maxValue + "]."); - } - - InternalSnowflakeWorker = options.Method switch - { - 1 => new SnowflakeWorkerM1(options), - 2 => new SnowflakeWorkerM2(options), - _ => new SnowflakeWorkerM1(options), - }; - - if (options.Method == 1) - { - Thread.Sleep(500); - } - } - - /// - /// 生成雪花 ID 过程中的异步事件 - /// - public Action GenIdActionAsync - { - get => InternalSnowflakeWorker.GenAction; - set => InternalSnowflakeWorker.GenAction = value; - } - - /// - /// 生成新的 long 类型数据 - /// - /// - public long NewLong() - { - return InternalSnowflakeWorker.NextId(); - } - } -} \ No newline at end of file diff --git a/WaterCloud.Code/Snowflake/Generators/IIDGenerator.cs b/WaterCloud.Code/Snowflake/Generators/IIDGenerator.cs deleted file mode 100644 index df1b0523938949b575909d97cf0edbc26d457867..0000000000000000000000000000000000000000 --- a/WaterCloud.Code/Snowflake/Generators/IIDGenerator.cs +++ /dev/null @@ -1,21 +0,0 @@ -using System; - -namespace WaterCloud.Code -{ - /// - /// 雪花 ID 生成器接口 - /// - public interface IIDGenerator - { - /// - /// 生成过程中产生的事件 - /// - Action GenIdActionAsync { get; set; } - - /// - /// 生成新的long型Id - /// - /// - long NewLong(); - } -} \ No newline at end of file diff --git a/WaterCloud.Code/Snowflake/IDGenerator.cs b/WaterCloud.Code/Snowflake/IDGenerator.cs deleted file mode 100644 index 1236eaed1fe3c044ebab466e755f0460793ccf68..0000000000000000000000000000000000000000 --- a/WaterCloud.Code/Snowflake/IDGenerator.cs +++ /dev/null @@ -1,43 +0,0 @@ -namespace WaterCloud.Code -{ - /// - /// 雪花 ID 生成器静态类 - /// - public class IDGenerator - { - /// - /// 私有化实例 - /// - private static IIDGenerator instance = null; - - /// - /// 获取单例实例 - /// - public static IIDGenerator Instance => instance; - - /// - /// 设置参数,建议程序初始化时执行一次 - /// - /// - public static void SetIdGenerator(IDGeneratorOptions options) - { - instance = new DefaultIDGenerator(options); - } - - /// - /// 生成新的Id - /// 调用本方法前,请确保调用了 SetIdGenerator 方法做初始化。 - /// 否则将会初始化一个WorkerId为1的对象。 - /// - /// - public static long NextId() - { - if (instance == null) - { - instance = new DefaultIDGenerator(new IDGeneratorOptions() { WorkerId = 1 }); - } - - return instance.NewLong(); - } - } -} \ No newline at end of file diff --git a/WaterCloud.Code/Snowflake/Internal/OverCostActionArg.cs b/WaterCloud.Code/Snowflake/Internal/OverCostActionArg.cs deleted file mode 100644 index 2573b925e0a802f960e56831b6be682104b158fe..0000000000000000000000000000000000000000 --- a/WaterCloud.Code/Snowflake/Internal/OverCostActionArg.cs +++ /dev/null @@ -1,59 +0,0 @@ - -namespace WaterCloud.Code -{ - /// - /// Id生成时回调参数 - /// - public class OverCostActionArg - { - /// - /// 事件类型 - /// 1-开始,2-结束,8-漂移 - /// - public virtual int ActionType { get; set; } - - /// - /// 时间戳 - /// - public virtual long TimeTick { get; set; } - - /// - /// 机器码 - /// - public virtual ushort WorkerId { get; set; } - - /// - /// 漂移计算次数 - /// - public virtual int OverCostCountInOneTerm { get; set; } - - /// - /// 漂移期间生产ID个数 - /// - public virtual int GenCountInOneTerm { get; set; } - - /// - /// 漂移周期 - /// - public virtual int TermIndex { get; set; } - - /// - /// 构造函数 - /// - /// - /// - /// - /// - /// - /// - public OverCostActionArg(ushort workerId, long timeTick, int actionType = 0, int overCostCountInOneTerm = 0, int genCountWhenOverCost = 0, int index = 0) - { - ActionType = actionType; - TimeTick = timeTick; - WorkerId = workerId; - OverCostCountInOneTerm = overCostCountInOneTerm; - GenCountInOneTerm = genCountWhenOverCost; - TermIndex = index; - } - } -} \ No newline at end of file diff --git a/WaterCloud.Code/Snowflake/Options/IDGeneratorOptions.cs b/WaterCloud.Code/Snowflake/Options/IDGeneratorOptions.cs deleted file mode 100644 index 0b418f0ec82819185c865bac52a07f1f8c81c41f..0000000000000000000000000000000000000000 --- a/WaterCloud.Code/Snowflake/Options/IDGeneratorOptions.cs +++ /dev/null @@ -1,77 +0,0 @@ -using System; - -namespace WaterCloud.Code -{ - /// - /// 雪花 ID 生成器配置配置 - /// - public class IDGeneratorOptions - { - /// - /// 构造函数 - /// - public IDGeneratorOptions() - { - } - - /// - /// 构造函数 - /// - /// - public IDGeneratorOptions(ushort workerId) - { - WorkerId = workerId; - } - - /// - /// 雪花计算方法 - /// (1-漂移算法|2-传统算法),默认1 - /// - public virtual short Method { get; set; } = 1; - - /// - /// 开始时间(UTC格式) - /// 不能超过当前系统时间 - /// - public virtual DateTime BaseTime { get; set; } = new DateTime(2020, 2, 20, 2, 20, 2, 20, DateTimeKind.Utc); - - /// - /// 机器码 - /// 与 WorkerIdBitLength 有关系 - /// (ushort类型,最大值65535,如果有更高要求,请修改数据类型,或联系作者) - /// - public virtual ushort WorkerId { get; set; } = 0; - - /// - /// 机器码位长 - /// 范围:1-21(要求:序列数位长+机器码位长不超过22)。 - /// 建议范围:6-12。 - /// - public virtual byte WorkerIdBitLength { get; set; } = 6;//10; - - /// - /// 序列数位长 - /// 范围:2-21(要求:序列数位长+机器码位长不超过22)。 - /// 建议范围:6-14。 - /// - public virtual byte SeqBitLength { get; set; } = 6;//10; - - /// - /// 最大序列数(含) - /// (由SeqBitLength计算的最大值) - /// - public virtual int MaxSeqNumber { get; set; } = 0; - - /// - /// 最小序列数(含) - /// 默认5,不小于1,不大于MaxSeqNumber - /// - public virtual ushort MinSeqNumber { get; set; } = 5; - - /// - /// 最大漂移次数(含), - /// 默认2000,推荐范围500-10000(与计算能力有关) - /// - public virtual int TopOverCostCount { get; set; } = 2000; - } -} \ No newline at end of file diff --git a/WaterCloud.Code/Snowflake/Workers/ISnowflakeWorker.cs b/WaterCloud.Code/Snowflake/Workers/ISnowflakeWorker.cs deleted file mode 100644 index a4cc886e6a9709edc12286dfd6aaec38465a98e6..0000000000000000000000000000000000000000 --- a/WaterCloud.Code/Snowflake/Workers/ISnowflakeWorker.cs +++ /dev/null @@ -1,21 +0,0 @@ -using System; - -namespace WaterCloud.Code -{ - /// - /// 雪花算法接口 - /// - internal interface ISnowflakeWorker - { - /// - /// 雪花 ID 生成事件 - /// - Action GenAction { get; set; } - - /// - /// 下一个 雪花 ID - /// - /// - long NextId(); - } -} \ No newline at end of file diff --git a/WaterCloud.Code/Snowflake/Workers/SnowflakeWorkerM1.cs b/WaterCloud.Code/Snowflake/Workers/SnowflakeWorkerM1.cs deleted file mode 100644 index ec2718052b3d4fe0d06b2ae1b179ca138032f5cd..0000000000000000000000000000000000000000 --- a/WaterCloud.Code/Snowflake/Workers/SnowflakeWorkerM1.cs +++ /dev/null @@ -1,334 +0,0 @@ -using System; -using System.Threading; -using System.Threading.Tasks; - -namespace WaterCloud.Code -{ - /// - /// 雪花漂移算法 - /// - internal class SnowflakeWorkerM1 : ISnowflakeWorker - { - /// - /// 基础时间 - /// - protected readonly DateTime BaseTime; - - /// - /// 机器码 - /// - protected readonly ushort WorkerId = 0; - - /// - /// 机器码位长 - /// - protected readonly byte WorkerIdBitLength = 0; - - /// - /// 自增序列数位长 - /// - protected readonly byte SeqBitLength = 0; - - /// - /// 最大序列数(含) - /// - protected readonly int MaxSeqNumber = 0; - - /// - /// 最小序列数(含) - /// - protected readonly ushort MinSeqNumber = 0; - - /// - /// 最大漂移次数 - /// - protected readonly int TopOverCostCount = 0; - - protected readonly byte _TimestampShift = 0; - protected static object _SyncLock = new(); - - protected ushort _CurrentSeqNumber; - protected long _LastTimeTick = -1L; - protected long _TurnBackTimeTick = -1L; - protected byte _TurnBackIndex = 0; - - protected bool _IsOverCost = false; - protected int _OverCostCountInOneTerm = 0; - protected int _GenCountInOneTerm = 0; - protected int _TermIndex = 0; - - /// - /// 构造函数 - /// - /// - public SnowflakeWorkerM1(IDGeneratorOptions options) - { - WorkerId = options.WorkerId; - WorkerIdBitLength = options.WorkerIdBitLength; - SeqBitLength = options.SeqBitLength; - MaxSeqNumber = options.MaxSeqNumber; - MinSeqNumber = options.MinSeqNumber; - TopOverCostCount = options.TopOverCostCount; - - if (options.BaseTime != DateTime.MinValue) - { - BaseTime = options.BaseTime; - } - - if (WorkerId < 1) - { - WorkerId = (ushort)DateTime.Now.Millisecond; - } - - if (SeqBitLength == 0) - { - SeqBitLength = 6; - } - - if (WorkerIdBitLength == 0) - { - WorkerIdBitLength = 6; - } - - if (MaxSeqNumber == 0) - { - MaxSeqNumber = (int)Math.Pow(2, SeqBitLength) - 1; - } - - _TimestampShift = (byte)(WorkerIdBitLength + SeqBitLength); - _CurrentSeqNumber = options.MinSeqNumber; - } - - /// - /// 雪花 ID 生成事件 - /// - public Action GenAction { get; set; } - - /// - /// 下一个 雪花 ID - /// - /// - public virtual long NextId() - { - lock (_SyncLock) - { - return _IsOverCost ? NextOverCostId() : NextNormalId(); - } - } - - private void DoGenIdAction(OverCostActionArg arg) - { - Task.Run(() => - { - GenAction(arg); - }); - } - - private void BeginOverCostAction(in long useTimeTick) - { - if (GenAction == null) - { - return; - } - - DoGenIdAction(new OverCostActionArg( - WorkerId, - useTimeTick, - 1, - _OverCostCountInOneTerm, - _GenCountInOneTerm, - _TermIndex)); - } - - private void EndOverCostAction(in long useTimeTick) - { - if (_TermIndex > 10000) - { - _TermIndex = 0; - } - - if (GenAction == null) - { - return; - } - - DoGenIdAction(new OverCostActionArg( - WorkerId, - useTimeTick, - 2, - _OverCostCountInOneTerm, - _GenCountInOneTerm, - _TermIndex)); - } - - private void BeginTurnBackAction(in long useTimeTick) - { - if (GenAction == null) - { - return; - } - - DoGenIdAction(new OverCostActionArg( - WorkerId, - useTimeTick, - 8, - 0, - 0, - _TurnBackIndex)); - } - - private void EndTurnBackAction(in long useTimeTick) - { - if (GenAction == null) - { - return; - } - - DoGenIdAction(new OverCostActionArg( - WorkerId, - useTimeTick, - 9, - 0, - 0, - _TurnBackIndex)); - } - - private long NextOverCostId() - { - long currentTimeTick = GetCurrentTimeTick(); - - if (currentTimeTick > _LastTimeTick) - { - EndOverCostAction(currentTimeTick); - - _LastTimeTick = currentTimeTick; - _CurrentSeqNumber = MinSeqNumber; - _IsOverCost = false; - _OverCostCountInOneTerm = 0; - _GenCountInOneTerm = 0; - - return CalcId(_LastTimeTick); - } - - if (_OverCostCountInOneTerm >= TopOverCostCount) - { - EndOverCostAction(currentTimeTick); - - _LastTimeTick = GetNextTimeTick(); - _CurrentSeqNumber = MinSeqNumber; - _IsOverCost = false; - _OverCostCountInOneTerm = 0; - _GenCountInOneTerm = 0; - - return CalcId(_LastTimeTick); - } - - if (_CurrentSeqNumber > MaxSeqNumber) - { - _LastTimeTick++; - _CurrentSeqNumber = MinSeqNumber; - _IsOverCost = true; - _OverCostCountInOneTerm++; - _GenCountInOneTerm++; - - return CalcId(_LastTimeTick); - } - - _GenCountInOneTerm++; - return CalcId(_LastTimeTick); - } - - private long NextNormalId() - { - long currentTimeTick = GetCurrentTimeTick(); - - if (currentTimeTick < _LastTimeTick) - { - if (_TurnBackTimeTick < 1) - { - _TurnBackTimeTick = _LastTimeTick - 1; - _TurnBackIndex++; - - // 每毫秒序列数的前5位是预留位,0用于手工新值,1-4是时间回拨次序 - // 最多4次回拨(防止回拨重叠) - if (_TurnBackIndex > 4) - { - _TurnBackIndex = 1; - } - - BeginTurnBackAction(_TurnBackTimeTick); - } - - Thread.Sleep(10); - return CalcTurnBackId(_TurnBackTimeTick); - } - - // 时间追平时,_TurnBackTimeTick清零 - if (_TurnBackTimeTick > 0) - { - EndTurnBackAction(_TurnBackTimeTick); - _TurnBackTimeTick = 0; - } - - if (currentTimeTick > _LastTimeTick) - { - _LastTimeTick = currentTimeTick; - _CurrentSeqNumber = MinSeqNumber; - - return CalcId(_LastTimeTick); - } - - if (_CurrentSeqNumber > MaxSeqNumber) - { - BeginOverCostAction(currentTimeTick); - - _TermIndex++; - _LastTimeTick++; - _CurrentSeqNumber = MinSeqNumber; - _IsOverCost = true; - _OverCostCountInOneTerm = 1; - _GenCountInOneTerm = 1; - - return CalcId(_LastTimeTick); - } - - return CalcId(_LastTimeTick); - } - - private long CalcId(in long useTimeTick) - { - var result = ((useTimeTick << _TimestampShift) + - ((long)WorkerId << SeqBitLength) + - (uint)_CurrentSeqNumber); - - _CurrentSeqNumber++; - return result; - } - - private long CalcTurnBackId(in long useTimeTick) - { - var result = ((useTimeTick << _TimestampShift) + - ((long)WorkerId << SeqBitLength) + _TurnBackIndex); - - _TurnBackTimeTick--; - return result; - } - - protected virtual long GetCurrentTimeTick() - { - return (long)(DateTime.UtcNow - BaseTime).TotalMilliseconds; - } - - protected virtual long GetNextTimeTick() - { - long tempTimeTicker = GetCurrentTimeTick(); - - while (tempTimeTicker <= _LastTimeTick) - { - tempTimeTicker = GetCurrentTimeTick(); - } - - return tempTimeTicker; - } - } -} \ No newline at end of file diff --git a/WaterCloud.Code/Snowflake/Workers/SnowflakeWorkerM2.cs b/WaterCloud.Code/Snowflake/Workers/SnowflakeWorkerM2.cs deleted file mode 100644 index 42c8b694cbdf4b948db457fec65414c5e8b2c7cf..0000000000000000000000000000000000000000 --- a/WaterCloud.Code/Snowflake/Workers/SnowflakeWorkerM2.cs +++ /dev/null @@ -1,53 +0,0 @@ -using System; - -namespace WaterCloud.Code -{ - /// - /// 常规雪花算法 - /// - internal class SnowflakeWorkerM2 : SnowflakeWorkerM1 - { - /// - /// 构造函数 - /// - /// - public SnowflakeWorkerM2(IDGeneratorOptions options) : base(options) - { - } - - /// - /// 下一个 雪花 ID - /// - /// - public override long NextId() - { - lock (_SyncLock) - { - long currentTimeTick = GetCurrentTimeTick(); - - if (_LastTimeTick == currentTimeTick) - { - if (_CurrentSeqNumber++ > MaxSeqNumber) - { - _CurrentSeqNumber = MinSeqNumber; - currentTimeTick = GetNextTimeTick(); - } - } - else - { - _CurrentSeqNumber = MinSeqNumber; - } - - if (currentTimeTick < _LastTimeTick) - { - throw new Exception(string.Format("Time error for {0} milliseconds", _LastTimeTick - currentTimeTick)); - } - - _LastTimeTick = currentTimeTick; - var result = ((currentTimeTick << _TimestampShift) + ((long)WorkerId << SeqBitLength) + (uint)_CurrentSeqNumber); - - return result; - } - } - } -} \ No newline at end of file diff --git a/WaterCloud.Code/Utils.cs b/WaterCloud.Code/Utils.cs index d9b9eb98687a131bbf4ca19f7a3c4006ec777adc..a67cc889fc9609c3748e7552c58c1e1aa4f358ea 100644 --- a/WaterCloud.Code/Utils.cs +++ b/WaterCloud.Code/Utils.cs @@ -13,7 +13,7 @@ namespace WaterCloud.Code /// public static string GuId() { - return Guid.NewGuid().ToString(); + return IDGen.NextID().ToString(); } /// /// 自动生成编号 201008251145409865 @@ -29,7 +29,7 @@ namespace WaterCloud.Code #endregion public static string GetGuid() { - return Guid.NewGuid().ToString().Replace("-", string.Empty).ToLower(); + return IDGen.NextID().ToString().Replace("-", string.Empty).ToLower(); } } } diff --git a/WaterCloud.CodeGenerator/Template/SingleTableTemplate.cs b/WaterCloud.CodeGenerator/Template/SingleTableTemplate.cs index ba96bc3ff36f162bfd1146e8a51b2c154bdd6995..bce35f513fe67fcc1d8a81f8b27274e152626adf 100644 --- a/WaterCloud.CodeGenerator/Template/SingleTableTemplate.cs +++ b/WaterCloud.CodeGenerator/Template/SingleTableTemplate.cs @@ -16,16 +16,11 @@ namespace WaterCloud.CodeGenerator { public class SingleTableTemplate { - private string buttoncacheKey = "watercloud_modulebuttondata_"; - private string fieldscacheKey = "watercloud_modulefieldsdata_"; - private string cacheKey = "watercloud_moduleldata_"; - private string quickcacheKey = "watercloud_quickmoduledata_"; - private string initcacheKey = "watercloud_init_"; - private string authorizecacheKey = "watercloud_authorizeurldata_";// +权限 - private IRepositoryBase uniwork; - public SingleTableTemplate(IDbContext context) + private string authorizecacheKey = GlobalContext.SystemConfig.ProjectPrefix + "_authorizeurldata_";// +权限 + private IUnitOfWork unitwork; + public SingleTableTemplate(IUnitOfWork unitOfWork) { - uniwork = new RepositoryBase(context); + unitwork = unitOfWork; } #region GetBaseConfig public BaseConfigModel GetBaseConfig(string path, string username, string tableName, string tableDescription, List tableFieldList) @@ -194,6 +189,7 @@ namespace WaterCloud.CodeGenerator sb.AppendLine("using System.Threading.Tasks;"); sb.AppendLine("using System.Collections.Generic;"); sb.AppendLine("using WaterCloud.Code;"); + sb.AppendLine("using WaterCloud.DataBase;"); sb.AppendLine("using Chloe;"); sb.AppendLine("using WaterCloud.Domain." + baseConfigModel.OutputConfig.OutputModule + ";"); sb.AppendLine(); @@ -207,9 +203,9 @@ namespace WaterCloud.CodeGenerator sb.AppendLine(" {"); if (baseConfigModel.PageIndex.IsCache == true) { - sb.AppendLine(" private string cacheKey = \"watercloud_" + baseConfigModel.FileConfig.ClassPrefix.ToLower() + "data_\";"); + sb.AppendLine(" private string cacheKey = GlobalContext.SystemConfig.ProjectPrefix + \"_" + baseConfigModel.FileConfig.ClassPrefix.ToLower() + "data_\";"); } - sb.AppendLine(" public " + baseConfigModel.FileConfig.ServiceName + "(IDbContext context) : base(context)"); + sb.AppendLine(" public " + baseConfigModel.FileConfig.ServiceName + "(IUnitOfWork unitOfWork) : base(unitOfWork)"); sb.AppendLine(" {"); sb.AppendLine(" }"); @@ -718,7 +714,7 @@ namespace WaterCloud.CodeGenerator sb.AppendLine(" { title: '操作', width: 130, toolbar: '#currentTableBar', align: \"center\", fixed: 'right' }"); break; case 3: - sb.AppendLine(" { title: '操作', width: 170, toolbar: '#currentTableBar', align: \"center\", fixed: 'right' }"); + sb.AppendLine(" { title: '操作', width: 175, toolbar: '#currentTableBar', align: \"center\", fixed: 'right' }"); break; default: break; @@ -765,7 +761,7 @@ namespace WaterCloud.CodeGenerator sb.AppendLine(" { title: '操作', width: 130, toolbar: '#currentTableBar', align: \"center\", fixed: 'right' }"); break; case 3: - sb.AppendLine(" { title: '操作', width: 170, toolbar: '#currentTableBar', align: \"center\", fixed: 'right' }"); + sb.AppendLine(" { title: '操作', width: 175, toolbar: '#currentTableBar', align: \"center\", fixed: 'right' }"); break; default: break; @@ -1272,7 +1268,7 @@ namespace WaterCloud.CodeGenerator string menuUrl = "/" + baseConfigModel.OutputConfig.OutputModule + "/" + baseConfigModel.FileConfig.ClassPrefix + "/" + baseConfigModel.FileConfig.PageIndexName; ModuleEntity moduleEntity = new ModuleEntity(); moduleEntity.Create(); - moduleEntity.F_Layers = (await uniwork.FindEntity(a => a.F_EnCode == baseConfigModel.OutputConfig.OutputModule)).F_Layers + 1; ; + moduleEntity.F_Layers = (await unitwork.FindEntity(a => a.F_EnCode == baseConfigModel.OutputConfig.OutputModule)).F_Layers + 1; ; moduleEntity.F_FullName = baseConfigModel.FileConfig.ClassDescription; moduleEntity.F_UrlAddress = menuUrl; moduleEntity.F_EnCode = baseConfigModel.FileConfig.ClassPrefix; @@ -1285,9 +1281,9 @@ namespace WaterCloud.CodeGenerator moduleEntity.F_AllowDelete = false; moduleEntity.F_EnabledMark = true; moduleEntity.F_DeleteMark = false; - moduleEntity.F_ParentId = (await uniwork.FindEntity(a => a.F_EnCode == baseConfigModel.OutputConfig.OutputModule)).F_Id; - var parentModule = await uniwork.FindEntity(a => a.F_EnCode == baseConfigModel.OutputConfig.OutputModule); - moduleEntity.F_SortCode = (uniwork.IQueryable(a => a.F_ParentId == parentModule.F_Id).Max(a => a.F_SortCode) ?? 0) + 1; + moduleEntity.F_ParentId = (await unitwork.FindEntity(a => a.F_EnCode == baseConfigModel.OutputConfig.OutputModule)).F_Id; + var parentModule = await unitwork.FindEntity(a => a.F_EnCode == baseConfigModel.OutputConfig.OutputModule); + moduleEntity.F_SortCode = (unitwork.IQueryable(a => a.F_ParentId == parentModule.F_Id).Max(a => a.F_SortCode) ?? 0) + 1; List moduleButtonList = new List(); int sort = 0; foreach (var item in baseConfigModel.PageIndex.ButtonList) @@ -1340,21 +1336,14 @@ namespace WaterCloud.CodeGenerator moduleFields.F_DeleteMark = false; moduleFieldsList.Add(moduleFields); } - uniwork.BeginTrans(); - await uniwork.Insert(moduleEntity); - await uniwork.Insert(moduleButtonList); + unitwork.BeginTrans(); + await unitwork.Insert(moduleEntity); + await unitwork.Insert(moduleButtonList); if (moduleFieldsList.Count > 0) { - await uniwork.Insert(moduleFieldsList); + await unitwork.Insert(moduleFieldsList); } - uniwork.Commit(); - await CacheHelper.Remove(fieldscacheKey + "list"); - await CacheHelper.Remove(buttoncacheKey + "list"); - await CacheHelper.Remove(cacheKey + "list"); - await CacheHelper.Remove(quickcacheKey + "list"); - await CacheHelper.Remove(initcacheKey + "list"); - await CacheHelper.Remove(initcacheKey + "modulebutton_list"); - await CacheHelper.Remove(initcacheKey + "modulefields_list"); + unitwork.Commit(); await CacheHelper.Remove(authorizecacheKey + "list"); FileHelper.CreateFile(indexPath, codeIndex); result.Add(new KeyValue { Key = "列表页", Value = indexPath, Description = "生成成功!" }); diff --git a/WaterCloud.Data/Repository/IRepositoryBase.T.cs b/WaterCloud.Data/Repository/IRepositoryBase.T.cs index 03f32d81feafb60c78235b5f5f41d1d3b66de134..ef1b24f817b7f8d117848830f154584bb763174a 100644 --- a/WaterCloud.Data/Repository/IRepositoryBase.T.cs +++ b/WaterCloud.Data/Repository/IRepositoryBase.T.cs @@ -19,7 +19,8 @@ namespace WaterCloud.DataBase /// 实体类型 public interface IRepositoryBase where TEntity : class, new() { - IDbContext GetDbContext(); + IDbContext Db { get; } + IUnitOfWork unitOfWork { get; } Task Insert(TEntity entity); Task Insert(List entitys); Task Update(TEntity entity); @@ -28,8 +29,8 @@ namespace WaterCloud.DataBase Task Delete(Expression> predicate); Task FindEntity(object keyValue); Task FindEntity(Expression> predicate); - IQuery IQueryable(); - IQuery IQueryable(Expression> predicate); + IQuery IQueryable(LockType locktype = LockType.NoLock); + IQuery IQueryable(Expression> predicate, LockType locktype = LockType.NoLock); Task> FindList(string strSql); Task> FindList(string strSql, DbParam[] dbParameter); Task> FindList(Pagination pagination); diff --git a/WaterCloud.Data/Repository/IRepositoryBase.cs b/WaterCloud.Data/Repository/IUnitOfWork.cs similarity index 93% rename from WaterCloud.Data/Repository/IRepositoryBase.cs rename to WaterCloud.Data/Repository/IUnitOfWork.cs index 88a9887685d1f9bc09dc4a5ecd7cbfba6e72d414..3c9a8083f552d9531730f0d147703509802dafa2 100644 --- a/WaterCloud.Data/Repository/IRepositoryBase.cs +++ b/WaterCloud.Data/Repository/IUnitOfWork.cs @@ -1,155 +1,155 @@ -/******************************************************************************* - * Copyright © 2020 WaterCloud.Framework 版权所有 - * Author: WaterCloud - * Description: WaterCloud快速开发平台 - * Website: -*********************************************************************************/ -using Chloe; -using WaterCloud.Code; -using System; -using System.Collections.Generic; -using System.Linq.Expressions; -using System.Threading.Tasks; - -namespace WaterCloud.DataBase -{ - public interface IRepositoryBase : IDisposable - { - IDbContext GetDbContext(); - IRepositoryBase BeginTrans(); - void Commit(); - void Rollback(); - /// - /// 插入 - /// - /// - /// - Task Insert(TEntity entity) where TEntity : class; - /// - /// 批量插入 - /// - /// - /// - Task Insert(List entitys) where TEntity : class; - /// - /// 更新 - /// - /// - /// - /// - Task Update(TEntity entity) where TEntity : class; - /// - /// 批量更新 - /// - /// - /// - /// - /// - Task Update(Expression> predicate, Expression> content) where TEntity : class; - /// - /// 删除 - /// - /// - /// - /// - Task Delete(TEntity entity) where TEntity : class; - /// - /// 批量删除 - /// - /// - /// - /// - Task Delete(Expression> predicate) where TEntity : class; - /// - /// 查询单个对象根据主键 - /// - /// - /// - /// - Task FindEntity(object keyValue) where TEntity : class; - /// - /// 查询单个对象根据条件 - /// - /// - /// - /// - Task FindEntity(Expression> predicate) where TEntity : class; - /// - /// 查询 - /// - /// - /// - IQuery IQueryable() where TEntity : class; - /// - /// 查询根据条件 - /// - /// - /// - /// - IQuery IQueryable(Expression> predicate) where TEntity : class; - /// - /// SQL查询 - /// - /// - /// - /// - Task> FindList(string strSql) where TEntity : class; - /// - /// sql查询 - /// - /// - /// - /// - /// - Task> FindList(string strSql, DbParam[] dbParameter) where TEntity : class; - /// - /// 查询根据分页 - /// - /// - /// - /// - Task> FindList(Pagination pagination) where TEntity : class, new(); - /// - /// 查询根据条件和分页 - /// - /// - /// - /// - /// - Task> FindList(Expression> predicate, Pagination pagination) where TEntity : class, new(); - /// - /// 对IQuery参数分页 - /// - /// - /// - /// - /// - Task> OrderList(IQuery query, Pagination pagination); - /// - /// soultable-后端筛选 - /// - /// - /// - /// - /// - Task> OrderList(IQuery query, SoulPage pagination); - /// - /// 缓存单个对象 - /// - /// - /// - /// - /// - /// - Task CheckCache(string cacheKey, object keyValue, long old = 0) where TEntity : class; - /// - /// 缓存查询列表(大数据表谨慎使用) - /// - /// - /// - /// - /// - Task> CheckCacheList(string cacheKey, long old = 0) where TEntity : class; - - } -} +/******************************************************************************* + * Copyright © 2020 WaterCloud.Framework 版权所有 + * Author: WaterCloud + * Description: WaterCloud快速开发平台 + * Website: +*********************************************************************************/ +using Chloe; +using WaterCloud.Code; +using System; +using System.Collections.Generic; +using System.Linq.Expressions; +using System.Threading.Tasks; + +namespace WaterCloud.DataBase +{ + public interface IUnitOfWork : IDisposable + { + DbContext GetDbContext(); + IUnitOfWork BeginTrans(); + void Commit(); + void Rollback(); + /// + /// 插入 + /// + /// + /// + Task Insert(TEntity entity) where TEntity : class; + /// + /// 批量插入 + /// + /// + /// + Task Insert(List entitys) where TEntity : class; + /// + /// 更新 + /// + /// + /// + /// + Task Update(TEntity entity) where TEntity : class; + /// + /// 批量更新 + /// + /// + /// + /// + /// + Task Update(Expression> predicate, Expression> content) where TEntity : class; + /// + /// 删除 + /// + /// + /// + /// + Task Delete(TEntity entity) where TEntity : class; + /// + /// 批量删除 + /// + /// + /// + /// + Task Delete(Expression> predicate) where TEntity : class; + /// + /// 查询单个对象根据主键 + /// + /// + /// + /// + Task FindEntity(object keyValue) where TEntity : class; + /// + /// 查询单个对象根据条件 + /// + /// + /// + /// + Task FindEntity(Expression> predicate) where TEntity : class; + /// + /// 查询 + /// + /// + /// + IQuery IQueryable(LockType locktype = LockType.NoLock) where TEntity : class; + /// + /// 查询根据条件 + /// + /// + /// + /// + IQuery IQueryable(Expression> predicate, LockType locktype = LockType.NoLock) where TEntity : class; + /// + /// SQL查询 + /// + /// + /// + /// + Task> FindList(string strSql) where TEntity : class; + /// + /// sql查询 + /// + /// + /// + /// + /// + Task> FindList(string strSql, DbParam[] dbParameter) where TEntity : class; + /// + /// 查询根据分页 + /// + /// + /// + /// + Task> FindList(Pagination pagination) where TEntity : class, new(); + /// + /// 查询根据条件和分页 + /// + /// + /// + /// + /// + Task> FindList(Expression> predicate, Pagination pagination) where TEntity : class, new(); + /// + /// 对IQuery参数分页 + /// + /// + /// + /// + /// + Task> OrderList(IQuery query, Pagination pagination); + /// + /// soultable-后端筛选 + /// + /// + /// + /// + /// + Task> OrderList(IQuery query, SoulPage pagination); + /// + /// 缓存单个对象 + /// + /// + /// + /// + /// + /// + Task CheckCache(string cacheKey, object keyValue, long old = 0) where TEntity : class; + /// + /// 缓存查询列表(大数据表谨慎使用) + /// + /// + /// + /// + /// + Task> CheckCacheList(string cacheKey, long old = 0) where TEntity : class; + + } +} diff --git a/WaterCloud.Data/Repository/RepositoryBase.T.cs b/WaterCloud.Data/Repository/RepositoryBase.T.cs index a28e969f46d268e29ffd5d2945d705bc9a8c1a83..4488fa399cbfc06bbc40f1a7ef6d802f62c68b90 100644 --- a/WaterCloud.Data/Repository/RepositoryBase.T.cs +++ b/WaterCloud.Data/Repository/RepositoryBase.T.cs @@ -21,34 +21,36 @@ namespace WaterCloud.DataBase /// public class RepositoryBase : IRepositoryBase where TEntity : class, new() { - private IDbContext _context; - public IDbContext GetDbContext() - { - return _context; + private readonly DbContext _dbBase; + private readonly IUnitOfWork _unitOfWork; + public IDbContext Db + { + get { return _dbBase; } } - public RepositoryBase(string ConnectStr, string providerName) + public IUnitOfWork unitOfWork { - _context = DBContexHelper.Contex(ConnectStr, providerName); + get { return _unitOfWork; } } - public RepositoryBase(IDbContext context) + public RepositoryBase(IUnitOfWork unitOfWork) { - _context = context; + _unitOfWork = unitOfWork; + _dbBase = unitOfWork.GetDbContext(); } public async Task Insert(TEntity entity) { - return await _context.InsertAsync(entity); + return await _dbBase.InsertAsync(entity); } public async Task Insert(List entitys) { int i = 1; - await _context.InsertRangeAsync(entitys); + await _dbBase.InsertRangeAsync(entitys); return i; } public async Task Update(TEntity entity) { //反射对比更新对象变更 - TEntity newentity = _context.QueryByKey(entity); - _context.TrackEntity(newentity); + TEntity newentity = _dbBase.QueryByKey(entity); + _dbBase.TrackEntity(newentity); PropertyInfo[] newprops = newentity.GetType().GetProperties(); PropertyInfo[] props = entity.GetType().GetProperties(); foreach (PropertyInfo prop in props) @@ -64,47 +66,47 @@ namespace WaterCloud.DataBase } } } - return await _context.UpdateAsync(newentity); + return await _dbBase.UpdateAsync(newentity); } public async Task Update(Expression> predicate, Expression> content) { - return await _context.UpdateAsync(predicate, content); + return await _dbBase.UpdateAsync(predicate, content); } public async Task Delete(TEntity entity) { - return await _context.DeleteAsync(entity); + return await _dbBase.DeleteAsync(entity); } public async Task Delete(Expression> predicate) { - return await _context.DeleteAsync(predicate); + return await _dbBase.DeleteAsync(predicate); } public async Task FindEntity(object keyValue) { - return await _context.QueryByKeyAsync(keyValue); + return await _dbBase.QueryByKeyAsync(keyValue); } public async Task FindEntity(Expression> predicate) { - return _context.Query().FirstOrDefault(predicate); + return _dbBase.Query().FirstOrDefault(predicate); } - public IQuery IQueryable() + public IQuery IQueryable(LockType locktype = LockType.NoLock) { - return _context.Query(); + return _dbBase.Query(locktype); } - public IQuery IQueryable(Expression> predicate) + public IQuery IQueryable(Expression> predicate, LockType locktype = LockType.NoLock) { - return _context.Query().Where(predicate); + return _dbBase.Query(locktype).Where(predicate); } public async Task> FindList(string strSql) { - return await _context.SqlQueryAsync(strSql); + return await _dbBase.SqlQueryAsync(strSql); } public async Task> FindList(string strSql, DbParam[] dbParameter) { - return await _context.SqlQueryAsync(strSql, dbParameter); + return await _dbBase.SqlQueryAsync(strSql, dbParameter); } public async Task> FindList(Pagination pagination) { - var tempData = _context.Query(); + var tempData = _dbBase.Query(); pagination.records = tempData.Count(); tempData = tempData.OrderBy(pagination.sort); tempData = tempData.TakePage(pagination.page, pagination.rows); @@ -112,7 +114,7 @@ namespace WaterCloud.DataBase } public async Task> FindList(Expression> predicate, Pagination pagination) { - var tempData = _context.Query().Where(predicate); + var tempData = _dbBase.Query().Where(predicate); pagination.records = tempData.Count(); tempData = tempData.OrderBy(pagination.sort); tempData = tempData.TakePage(pagination.page, pagination.rows); @@ -151,7 +153,7 @@ namespace WaterCloud.DataBase var cachedata =await CacheHelper.Get>(cacheKey); if (cachedata == null || cachedata.Count() == 0) { - cachedata = _context.Query().ToList(); + cachedata = _dbBase.Query().ToList(); await CacheHelper.Set(cacheKey, cachedata); } return cachedata; @@ -161,7 +163,7 @@ namespace WaterCloud.DataBase var cachedata = await CacheHelper.Get(cacheKey + keyValue); if (cachedata == null) { - cachedata = await _context.QueryByKeyAsync(keyValue); + cachedata = await _dbBase.QueryByKeyAsync(keyValue); if (cachedata != null) { await CacheHelper.Set(cacheKey + keyValue, cachedata); diff --git a/WaterCloud.Data/Repository/RepositoryBase.cs b/WaterCloud.Data/Repository/UnitOfWork.cs similarity index 88% rename from WaterCloud.Data/Repository/RepositoryBase.cs rename to WaterCloud.Data/Repository/UnitOfWork.cs index f821b557f7b160fc45098e4f649aba2ca43ad68a..1e90441ea4ce3a6d1c3c01b0c6beaa7dfda660f6 100644 --- a/WaterCloud.Data/Repository/RepositoryBase.cs +++ b/WaterCloud.Data/Repository/UnitOfWork.cs @@ -1,264 +1,256 @@ -/******************************************************************************* - * Copyright © 2020 WaterCloud.Framework 版权所有 - * Author: WaterCloud - * Description: WaterCloud快速开发平台 - * Website: -*********************************************************************************/ -using Chloe; -using WaterCloud.Code; -using System; -using System.Collections.Generic; -using System.Data; -using System.Linq; -using System.Linq.Expressions; -using System.Reflection; -using System.Threading.Tasks; - -namespace WaterCloud.DataBase -{ - /// - /// 仓储实现 - /// - public class RepositoryBase : IRepositoryBase, IDisposable - { - private IDbContext _context; - public RepositoryBase(IDbContext context) - { - _context = context; - } - public IDbContext GetDbContext() - { - return _context; - } - public RepositoryBase(string ConnectStr, string providerName) - { - _context = DBContexHelper.Contex(ConnectStr, providerName); - } - public IRepositoryBase BeginTrans() - { - if (_context.Session.CurrentTransaction == null) - { - _context.Session.BeginTransaction(); - } - return this; - } - public void Commit() - { - try - { - if (_context.Session.CurrentTransaction != null) - { - _context.Session.CommitTransaction(); - } - } - catch (Exception) - { - this.Rollback(); - throw; - } - finally - { - this.Dispose(); - } - } - public void Dispose() - { - if (_context.Session.CurrentTransaction != null) - { - _context.Session.Dispose(); - } - } - public void Rollback() - { - if (_context.Session.CurrentTransaction != null) - { - _context.Session.RollbackTransaction(); - } - this.Dispose(); - } - public async Task Insert(TEntity entity) where TEntity : class - { - try - { - return await _context.InsertAsync(entity); - } - catch (Exception) - { - this.Rollback(); - throw; - } - } - public async Task Insert(List entitys) where TEntity : class - { - try - { - await _context.InsertRangeAsync(entitys); - return 1; - } - catch (Exception) - { - this.Rollback(); - throw; - } - } - public async Task Update(TEntity entity) where TEntity : class - { - try - { - TEntity newentity = _context.QueryByKey(entity); - _context.TrackEntity(newentity); - PropertyInfo[] newprops = newentity.GetType().GetProperties(); - PropertyInfo[] props = entity.GetType().GetProperties(); - foreach (PropertyInfo prop in props) - { - if (prop.GetValue(entity, null) != null) - { - PropertyInfo item = newprops.Where(a => a.Name == prop.Name).FirstOrDefault(); - if (item != null) - { - item.SetValue(newentity, prop.GetValue(entity, null), null); - if (prop.GetValue(entity, null).ToString() == " ") - item.SetValue(newentity, null, null); - } - } - } - return await _context.UpdateAsync(newentity); - } - catch (Exception) - { - this.Rollback(); - throw; - } - } - public async Task Update(Expression> predicate, Expression> content) where TEntity : class - { - try - { - return await _context.UpdateAsync(predicate, content); - } - catch (Exception) - { - this.Rollback(); - throw; - } - - } - public async Task Delete(TEntity entity) where TEntity : class - { - try - { - return await _context.DeleteAsync(entity); - } - catch (Exception) - { - this.Rollback(); - throw; - } - - } - public async Task Delete(Expression> predicate) where TEntity : class - { - try - { - return await _context.DeleteAsync(predicate); - } - catch (Exception) - { - this.Rollback(); - throw; - } - } - public async Task FindEntity(object keyValue) where TEntity : class - { - return await _context.QueryByKeyAsync(keyValue); - } - public async Task FindEntity(Expression> predicate) where TEntity : class - { - return _context.Query().FirstOrDefault(predicate); - } - public IQuery IQueryable() where TEntity : class - { - return _context.Query(); - } - public IQuery IQueryable(Expression> predicate) where TEntity : class - { - return _context.Query().Where(predicate); - } - public async Task> FindList(string strSql) where TEntity : class - { - return await _context.SqlQueryAsync(strSql); - } - public async Task> FindList(string strSql, DbParam[] dbParameter) where TEntity : class - { - return await _context.SqlQueryAsync(strSql, dbParameter); - } - public async Task> FindList(Pagination pagination) where TEntity : class, new() - { - var tempData = _context.Query(); - pagination.records = tempData.Count(); - tempData = tempData.OrderBy(pagination.sort); - tempData = tempData.TakePage(pagination.page, pagination.rows); - return tempData.ToList(); - } - public async Task> FindList(Expression> predicate, Pagination pagination) where TEntity : class, new() - { - var tempData = _context.Query().Where(predicate); - pagination.records = tempData.Count(); - tempData = tempData.OrderBy(pagination.sort); - tempData = tempData.TakePage(pagination.page, pagination.rows); - return tempData.ToList(); - } - public async Task> OrderList(IQuery query, Pagination pagination) - { - var tempData = query; - pagination.records = tempData.Count(); - tempData = tempData.OrderBy(pagination.sort); - tempData = tempData.TakePage(pagination.page, pagination.rows); - return tempData.ToList(); - } - public async Task> OrderList(IQuery query, SoulPage pagination) - { - var tempData = query; - List filterSos = pagination.getFilterSos(); - if (filterSos != null && filterSos.Count > 0) - { - tempData = tempData.GenerateFilter("u", filterSos); - } - pagination.count = tempData.Count(); - if (pagination.order == "desc") - { - tempData = tempData.OrderBy(pagination.field + " " + pagination.order); - } - else - { - tempData = tempData.OrderBy(pagination.field); - } - tempData = tempData.TakePage(pagination.page, pagination.rows); - return tempData.ToList(); - } - public async Task> CheckCacheList(string cacheKey, long old = 0) where TEntity : class - { - var cachedata = await CacheHelper.Get>(cacheKey); - if (cachedata == null || cachedata.Count() == 0) - { - cachedata = _context.Query().ToList(); - await CacheHelper.Set(cacheKey, cachedata); - } - return cachedata; - } - - public async Task CheckCache(string cacheKey, object keyValue, long old = 0) where TEntity : class - { - var cachedata = await CacheHelper.Get(cacheKey + keyValue); - if (cachedata == null) - { - cachedata = await _context.QueryByKeyAsync(keyValue); - if (cachedata != null) - { - await CacheHelper.Set(cacheKey + keyValue, cachedata); - } - } - return cachedata; - } - } -} +/******************************************************************************* + * Copyright © 2020 WaterCloud.Framework 版权所有 + * Author: WaterCloud + * Description: WaterCloud快速开发平台 + * Website: +*********************************************************************************/ +using Chloe; +using WaterCloud.Code; +using System; +using System.Collections.Generic; +using System.Data; +using System.Linq; +using System.Linq.Expressions; +using System.Reflection; +using System.Threading.Tasks; + +namespace WaterCloud.DataBase +{ + /// + /// 仓储实现 + /// + public class UnitOfWork : IUnitOfWork, IDisposable + { + private readonly IDbContext _context; + public UnitOfWork(IDbContext context) + { + _context = context; + } + public DbContext GetDbContext() + { + return _context as DbContext; + } + public UnitOfWork(string ConnectStr, string providerName) + { + _context = DBContexHelper.Contex(ConnectStr, providerName); + } + public IUnitOfWork BeginTrans() + { + if (_context.Session.CurrentTransaction == null) + { + _context.Session.BeginTransaction(); + } + return this; + } + public void Commit() + { + try + { + if (_context.Session.CurrentTransaction != null) + { + _context.Session.CommitTransaction(); + } + } + catch (Exception) + { + this.Rollback(); + throw; + } + } + public void Dispose() + { + _context.Dispose(); + } + public void Rollback() + { + if (_context.Session.CurrentTransaction != null) + { + _context.Session.RollbackTransaction(); + } + } + public async Task Insert(TEntity entity) where TEntity : class + { + try + { + return await _context.InsertAsync(entity); + } + catch (Exception) + { + this.Rollback(); + throw; + } + } + public async Task Insert(List entitys) where TEntity : class + { + try + { + await _context.InsertRangeAsync(entitys); + return 1; + } + catch (Exception) + { + this.Rollback(); + throw; + } + } + public async Task Update(TEntity entity) where TEntity : class + { + try + { + TEntity newentity = _context.QueryByKey(entity); + _context.TrackEntity(newentity); + PropertyInfo[] newprops = newentity.GetType().GetProperties(); + PropertyInfo[] props = entity.GetType().GetProperties(); + foreach (PropertyInfo prop in props) + { + if (prop.GetValue(entity, null) != null) + { + PropertyInfo item = newprops.Where(a => a.Name == prop.Name).FirstOrDefault(); + if (item != null) + { + item.SetValue(newentity, prop.GetValue(entity, null), null); + if (prop.GetValue(entity, null).ToString() == " ") + item.SetValue(newentity, null, null); + } + } + } + return await _context.UpdateAsync(newentity); + } + catch (Exception) + { + this.Rollback(); + throw; + } + } + public async Task Update(Expression> predicate, Expression> content) where TEntity : class + { + try + { + return await _context.UpdateAsync(predicate, content); + } + catch (Exception) + { + this.Rollback(); + throw; + } + + } + public async Task Delete(TEntity entity) where TEntity : class + { + try + { + return await _context.DeleteAsync(entity); + } + catch (Exception) + { + this.Rollback(); + throw; + } + + } + public async Task Delete(Expression> predicate) where TEntity : class + { + try + { + return await _context.DeleteAsync(predicate); + } + catch (Exception) + { + this.Rollback(); + throw; + } + } + public async Task FindEntity(object keyValue) where TEntity : class + { + return await _context.QueryByKeyAsync(keyValue); + } + public async Task FindEntity(Expression> predicate) where TEntity : class + { + return _context.Query().FirstOrDefault(predicate); + } + public IQuery IQueryable(LockType locktype = LockType.NoLock) where TEntity : class + { + return _context.Query(locktype); + } + public IQuery IQueryable(Expression> predicate, LockType locktype = LockType.NoLock) where TEntity : class + { + return _context.Query(locktype).Where(predicate); + } + public async Task> FindList(string strSql) where TEntity : class + { + return await _context.SqlQueryAsync(strSql); + } + public async Task> FindList(string strSql, DbParam[] dbParameter) where TEntity : class + { + return await _context.SqlQueryAsync(strSql, dbParameter); + } + public async Task> FindList(Pagination pagination) where TEntity : class, new() + { + var tempData = _context.Query(); + pagination.records = tempData.Count(); + tempData = tempData.OrderBy(pagination.sort); + tempData = tempData.TakePage(pagination.page, pagination.rows); + return tempData.ToList(); + } + public async Task> FindList(Expression> predicate, Pagination pagination) where TEntity : class, new() + { + var tempData = _context.Query().Where(predicate); + pagination.records = tempData.Count(); + tempData = tempData.OrderBy(pagination.sort); + tempData = tempData.TakePage(pagination.page, pagination.rows); + return tempData.ToList(); + } + public async Task> OrderList(IQuery query, Pagination pagination) + { + var tempData = query; + pagination.records = tempData.Count(); + tempData = tempData.OrderBy(pagination.sort); + tempData = tempData.TakePage(pagination.page, pagination.rows); + return tempData.ToList(); + } + public async Task> OrderList(IQuery query, SoulPage pagination) + { + var tempData = query; + List filterSos = pagination.getFilterSos(); + if (filterSos != null && filterSos.Count > 0) + { + tempData = tempData.GenerateFilter("u", filterSos); + } + pagination.count = tempData.Count(); + if (pagination.order == "desc") + { + tempData = tempData.OrderBy(pagination.field + " " + pagination.order); + } + else + { + tempData = tempData.OrderBy(pagination.field); + } + tempData = tempData.TakePage(pagination.page, pagination.rows); + return tempData.ToList(); + } + public async Task> CheckCacheList(string cacheKey, long old = 0) where TEntity : class + { + var cachedata = await CacheHelper.Get>(cacheKey); + if (cachedata == null || cachedata.Count() == 0) + { + cachedata = _context.Query().ToList(); + await CacheHelper.Set(cacheKey, cachedata); + } + return cachedata; + } + + public async Task CheckCache(string cacheKey, object keyValue, long old = 0) where TEntity : class + { + var cachedata = await CacheHelper.Get(cacheKey + keyValue); + if (cachedata == null) + { + cachedata = await _context.QueryByKeyAsync(keyValue); + if (cachedata != null) + { + await CacheHelper.Set(cacheKey + keyValue, cachedata); + } + } + return cachedata; + } + } +} diff --git a/WaterCloud.Domain/Entity/SystemSecurity/FilterIPEntity.cs b/WaterCloud.Domain/Entity/SystemSecurity/FilterIPEntity.cs index edd0dd910deb0481fe457d501423d50e02e2ec39..f8cc16455647195adf999ce0b3433e3b0e3c121b 100644 --- a/WaterCloud.Domain/Entity/SystemSecurity/FilterIPEntity.cs +++ b/WaterCloud.Domain/Entity/SystemSecurity/FilterIPEntity.cs @@ -30,6 +30,7 @@ namespace WaterCloud.Domain.SystemSecurity public DateTime? F_LastModifyTime { get; set; } public string F_LastModifyUserId { get; set; } public DateTime? F_DeleteTime { get; set; } - public string F_DeleteUserId { get; set; } + public string F_DeleteUserId { get; set; } + public DateTime? F_EndTime { get; set; } } } diff --git a/WaterCloud.Domain/Entity/SystemSecurity/OpenJobEntity.cs b/WaterCloud.Domain/Entity/SystemSecurity/OpenJobEntity.cs index e1f4be8e25bf2a620b1365fb0007558dbef5e245..fde554239e044d6fbb51400c290ddd35857d4b3d 100644 --- a/WaterCloud.Domain/Entity/SystemSecurity/OpenJobEntity.cs +++ b/WaterCloud.Domain/Entity/SystemSecurity/OpenJobEntity.cs @@ -70,5 +70,26 @@ namespace WaterCloud.Domain.SystemSecurity public string F_LastModifyUserId { get; set; } public DateTime? F_DeleteTime { get; set; } public string F_DeleteUserId { get; set; } + /// + /// 任务类型 + /// + public int? F_JobType { get; set; } + /// + /// 请求头 + /// + public string F_RequestHeaders { get; set; } + /// + /// 请求内容 + /// + public string F_RequestString { get; set; } + /// + /// 请求url + /// + public string F_RequestUrl { get; set; } + /// + /// 立即执行 + /// + [NotMapped] + public bool? F_DoItNow { get; set; } } } \ No newline at end of file diff --git a/WaterCloud.Service/AutoJob/Job/SaveServerStateJob.cs b/WaterCloud.Service/AutoJob/Job/SaveServerStateJob.cs index e909a9c54d7e278f309739e54ca2b7dd12118338..f2853d317f0cd2370aff7d4bd00a10f89127de64 100644 --- a/WaterCloud.Service/AutoJob/Job/SaveServerStateJob.cs +++ b/WaterCloud.Service/AutoJob/Job/SaveServerStateJob.cs @@ -5,6 +5,8 @@ using System.Threading.Tasks; using WaterCloud.Code; using WaterCloud.Domain.SystemSecurity; using WaterCloud.Service.SystemSecurity; +using WaterCloud.DataBase; + namespace WaterCloud.Service.AutoJob { @@ -12,10 +14,10 @@ namespace WaterCloud.Service.AutoJob { private IWebHostEnvironment _hostingEnvironment; private ServerStateService _server; - public SaveServerStateJob(IDbContext context) + public SaveServerStateJob(IUnitOfWork unitOfWork) { _hostingEnvironment = GlobalContext.HostingEnvironment; - _server = new ServerStateService(context); + _server = new ServerStateService(unitOfWork); } public async Task Start() { diff --git a/WaterCloud.Service/AutoJob/JobExecute.cs b/WaterCloud.Service/AutoJob/JobExecute.cs index 822099e48201c4dfc6270f7c2fb01db8c4f463f0..2e8d8f34bf5cce4517af96fdf094c2cb7b66c223 100644 --- a/WaterCloud.Service/AutoJob/JobExecute.cs +++ b/WaterCloud.Service/AutoJob/JobExecute.cs @@ -1,6 +1,8 @@ using System; +using System.Collections.Generic; using System.IO; using System.Linq; +using System.Net.Http; using System.Reflection; using System.Threading.Tasks; using Chloe; @@ -19,13 +21,15 @@ namespace WaterCloud.Service.AutoJob private IScheduler _scheduler; private ISchedulerFactory _schedulerFactory; private IJobFactory _iocJobfactory; + private readonly IHttpClientFactory _httpClient; - public JobExecute(ISchedulerFactory schedulerFactory, IJobFactory iocJobfactory) + public JobExecute(ISchedulerFactory schedulerFactory, IJobFactory iocJobfactory, IHttpClientFactory httpClient) { _scheduler = schedulerFactory.GetScheduler().GetAwaiter().GetResult(); _scheduler.JobFactory = iocJobfactory; _schedulerFactory = schedulerFactory; _iocJobfactory = iocJobfactory; + _httpClient = httpClient; } public Task Execute(IJobExecutionContext context) @@ -40,9 +44,9 @@ namespace WaterCloud.Service.AutoJob { jobData = context.JobDetail.JobDataMap; jobId = jobData["F_Id"].ToString(); - using (IDbContext _context= DBContexHelper.Contex()) + using (IUnitOfWork unitOfWork = new UnitOfWork(DBContexHelper.Contex())) { - OpenJobsService autoJobService = new OpenJobsService(_context, _schedulerFactory,_iocJobfactory); + OpenJobsService autoJobService = new OpenJobsService(unitOfWork, _schedulerFactory,_iocJobfactory, _httpClient); // 获取数据库中的任务 dbJobEntity = await autoJobService.GetForm(jobId); if (dbJobEntity != null) @@ -60,51 +64,85 @@ namespace WaterCloud.Service.AutoJob return; } #region 执行任务 - _context.Session.BeginTransaction(); - //反射执行就行 - var path = AppDomain.CurrentDomain.RelativeSearchPath ?? AppDomain.CurrentDomain.BaseDirectory; - //反射取指定前后缀的dll - var referencedAssemblies = Directory.GetFiles(path, "WaterCloud.*.dll").Select(Assembly.LoadFrom).ToArray(); - var types = referencedAssemblies - .SelectMany(a => a.GetTypes().Where(t => t.GetInterfaces() - .Contains(typeof(IJobTask)))).ToArray(); - string filename = dbJobEntity.F_FileName; - var implementType = types.Where(x => x.IsClass && x.FullName == filename).FirstOrDefault(); - var obj = System.Activator.CreateInstance(implementType, _context); // 创建实例(带参数) - MethodInfo method = implementType.GetMethod("Start", new Type[] { }); // 获取方法信息 - object[] parameters = null; - var temp = (Task)method.Invoke(obj, parameters); // 调用方法,参数为空 - #endregion - //需要同步,不然数据库连接会断开 - _context.Update(t => t.F_Id == jobId, a => new OpenJobEntity - { - F_LastRunTime = now - }); OpenJobLogEntity log = new OpenJobLogEntity(); log.F_Id = Utils.GuId(); log.F_JobId = jobId; log.F_JobName = dbJobEntity.F_JobName; log.F_CreatorTime = now; - if (temp.Result.state.ToString() == ResultType.success.ToString()) + unitOfWork.BeginTrans(); + AlwaysResult result = new AlwaysResult(); + if (dbJobEntity.F_JobType == 0) { - log.F_EnabledMark = true; - log.F_Description = "执行成功," + temp.Result.message.ToString(); + //反射执行就行 + var path = AppDomain.CurrentDomain.RelativeSearchPath ?? AppDomain.CurrentDomain.BaseDirectory; + //反射取指定前后缀的dll + var referencedAssemblies = Directory.GetFiles(path, "WaterCloud.*.dll").Select(Assembly.LoadFrom).ToArray(); + var types = referencedAssemblies + .SelectMany(a => a.GetTypes().Where(t => t.GetInterfaces() + .Contains(typeof(IJobTask)))).ToArray(); + string filename = dbJobEntity.F_FileName; + var implementType = types.Where(x => x.IsClass && x.FullName == filename).FirstOrDefault(); + var obj = System.Activator.CreateInstance(implementType, unitOfWork); // 创建实例(带参数) + MethodInfo method = implementType.GetMethod("Start", new Type[] { }); // 获取方法信息 + object[] parameters = null; + var temp = (Task)method.Invoke(obj, parameters); // 调用方法,参数为空 + if (temp.Result.state.ToString() == ResultType.success.ToString()) + { + log.F_EnabledMark = true; + log.F_Description = "执行成功," + temp.Result.message.ToString(); + } + else + { + log.F_EnabledMark = false; + log.F_Description = "执行失败," + temp.Result.message.ToString(); + } } else { - log.F_EnabledMark = false; - log.F_Description = "执行失败," + temp.Result.message.ToString(); + HttpMethod method = HttpMethod.Get; + switch (dbJobEntity.F_JobType) + { + case 1: + method = HttpMethod.Get; + break; + case 2: + method = HttpMethod.Post; + break; + case 3: + method = HttpMethod.Put; + break; + case 4: + method = HttpMethod.Delete; + break; + } + var dic = dbJobEntity.F_RequestHeaders.ToObject>(); + try + { + var temp = await new HttpWebClient(_httpClient).ExecuteAsync(dbJobEntity.F_RequestUrl, method, dbJobEntity.F_RequestString, dic); + log.F_EnabledMark = true; + log.F_Description = "执行成功。"; + } + catch (Exception ex) + { + log.F_EnabledMark = false; + log.F_Description = "执行失败," + ex.Message.ToString(); + } } + #endregion + await unitOfWork.Update(t => t.F_Id == dbJobEntity.F_Id,t => new OpenJobEntity + { + F_LastRunTime = now + }); string HandleLogProvider = GlobalContext.SystemConfig.HandleLogProvider; if (HandleLogProvider != Define.CACHEPROVIDER_REDIS) { - _context.Insert(log); + await unitOfWork.Insert(log); } else { await HandleLogHelper.HSetAsync(log.F_JobId, log.F_Id, log); } - _context.Session.CommitTransaction(); + unitOfWork.Commit(); } } } diff --git a/WaterCloud.Service/CommonService/DatabaseTableMySqlService.cs b/WaterCloud.Service/CommonService/DatabaseTableMySqlService.cs index cc6a571e99fae93d83e03dfaf008a3546b850ba3..2a8e5499278ac64f98f0e1b39b0f59918bf780bd 100644 --- a/WaterCloud.Service/CommonService/DatabaseTableMySqlService.cs +++ b/WaterCloud.Service/CommonService/DatabaseTableMySqlService.cs @@ -15,18 +15,19 @@ using WaterCloud.Domain.SystemSecurity; namespace WaterCloud.Service.CommonService { - public class DatabaseTableMySqlService : RepositoryBase, IDatabaseTableService + public class DatabaseTableMySqlService: IDatabaseTableService { - public DatabaseTableMySqlService(IDbContext context) : base(context) + private IUnitOfWork _unitOfWork; + public DatabaseTableMySqlService(IUnitOfWork unitOfWork) { - + _unitOfWork = unitOfWork; } #region 获取数据 public async Task> GetTableList(string tableName) { StringBuilder strSql = new StringBuilder(); strSql.Append(@"SELECT table_name TableName FROM information_schema.tables WHERE table_schema='" + GetDatabase() + "' AND (table_type='base table' or table_type='BASE TABLE' or table_type='view')"); - IEnumerable list =await FindList(strSql.ToString()); + IEnumerable list =await _unitOfWork.FindList(strSql.ToString()); if (!string.IsNullOrEmpty(tableName)) { list = list.Where(p => p.TableName.Contains(tableName)).ToList(); @@ -47,7 +48,7 @@ namespace WaterCloud.Service.CommonService parameter.Add(new DbParam("@TableName", '%' + tableName + '%')); } - IEnumerable list =await FindList(strSql.ToString(), parameter.ToArray()); + IEnumerable list =await _unitOfWork.FindList(strSql.ToString(), parameter.ToArray()); pagination.records = list.Count(); var tempData = list.OrderByDescending(a=>a.CreateTime).Skip(pagination.rows * (pagination.page - 1)).Take(pagination.rows).AsQueryable().ToList(); await SetTableDetail(tempData); @@ -67,7 +68,7 @@ namespace WaterCloud.Service.CommonService FROM information_schema.columns WHERE table_schema='" + GetDatabase() + "' AND table_name=@TableName"); var parameter = new List(); parameter.Add(new DbParam("@TableName", tableName)); - var list =await FindList(strSql.ToString(), parameter.ToArray()); + var list =await _unitOfWork.FindList(strSql.ToString(), parameter.ToArray()); return list; } #endregion @@ -109,8 +110,8 @@ namespace WaterCloud.Service.CommonService private async Task SyncSqlServerTable() where T : class, new() { string sqlServerConnectionString = "192.168.1.17;Initial Catalog = WaterCloudNetDb;User ID=sa;Password=admin@12345;MultipleActiveResultSets=true"; - var list = this.IQueryable().ToList(); - var context=new RepositoryBase(sqlServerConnectionString, "System.Data.SqlClient"); + var list = _unitOfWork.IQueryable().ToList(); + var context=new UnitOfWork(sqlServerConnectionString, "System.Data.SqlClient"); await context.Delete(p => true); foreach (var item in list) { @@ -131,7 +132,7 @@ namespace WaterCloud.Service.CommonService LEFT JOIN INFORMATION_SCHEMA.`KEY_COLUMN_USAGE` as t2 on t1.TABLE_NAME = t2.TABLE_NAME WHERE t1.TABLE_SCHEMA='" + GetDatabase() + "' AND t2.TABLE_SCHEMA='" + GetDatabase() + "'"; - IEnumerable list =await FindList(strSql.ToString()); + IEnumerable list =await _unitOfWork.FindList(strSql.ToString()); return list.ToList(); } diff --git a/WaterCloud.Service/CommonService/DatabaseTableOracleService.cs b/WaterCloud.Service/CommonService/DatabaseTableOracleService.cs index a25062d2f051a12a2a89255544a35a7aee0079f7..35dd7b04fc3a8fa5922428b9811b33e584fcd556 100644 --- a/WaterCloud.Service/CommonService/DatabaseTableOracleService.cs +++ b/WaterCloud.Service/CommonService/DatabaseTableOracleService.cs @@ -13,11 +13,12 @@ using WaterCloud.Domain; namespace WaterCloud.Service.CommonService { - public class DatabaseTableOracleService : RepositoryBase, IDatabaseTableService + public class DatabaseTableOracleService : IDatabaseTableService { - public DatabaseTableOracleService(IDbContext context) : base(context) + private IUnitOfWork _unitOfWork; + public DatabaseTableOracleService(IUnitOfWork unitOfWork) { - + _unitOfWork = unitOfWork; } #region 获取数据 public async Task> GetTableList(string tableName) @@ -25,7 +26,7 @@ namespace WaterCloud.Service.CommonService StringBuilder strSql = new StringBuilder(); //select TABLE_NAME Id,TABLE_NAME from user_tab_comments utc where utc.table_type='TABLE' strSql.Append(@"select a.TABLE_NAME TableName,b.CREATED CreateTime from sys.user_tables a left join user_objects b on b.object_name=upper(a.TABLE_NAME) where a.table_name not like '%$%' and a.table_name not like '%LOGMNR%'"); - IEnumerable list = await FindList(strSql.ToString()); + IEnumerable list = await _unitOfWork.FindList(strSql.ToString()); if (!tableName.IsEmpty()) { list = list.Where(p => p.TableName.Contains(tableName)); @@ -46,7 +47,7 @@ namespace WaterCloud.Service.CommonService parameter.Add(new DbParam(":TableName", '%' + tableName + '%')); } - IEnumerable list = await FindList(strSql.ToString(), parameter.ToArray()); + IEnumerable list = await _unitOfWork.FindList(strSql.ToString(), parameter.ToArray()); pagination.records = list.Count(); var tempData = list.OrderByDescending(a => a.CreateTime).Skip(pagination.rows * (pagination.page - 1)).Take(pagination.rows).AsQueryable().ToList(); await SetTableDetail(tempData); @@ -77,7 +78,7 @@ namespace WaterCloud.Service.CommonService var parameter = new List(); parameter.Add(new DbParam(":TableName", tableName)); - var list = await FindList(strSql.ToString(), parameter.ToArray()); + var list = await _unitOfWork.FindList(strSql.ToString(), parameter.ToArray()); return list.ToList(); } #endregion @@ -107,7 +108,7 @@ namespace WaterCloud.Service.CommonService    And a.Owner = b.Owner       And a.table_name = b.table_name AND a.table_name not like '%$%' and a.table_name not like '%LOGMNR%'"; - IEnumerable list = await FindList(strSql.ToString()); + IEnumerable list = await _unitOfWork.FindList(strSql.ToString()); return list.ToList(); } diff --git a/WaterCloud.Service/CommonService/DatabaseTableSqlServerService.cs b/WaterCloud.Service/CommonService/DatabaseTableSqlServerService.cs index 7287b722b681b9e831ec8e37c2cae4b4b73971a8..479d267cdf70b580caf10b8ba6e2929ea3d2f2ed 100644 --- a/WaterCloud.Service/CommonService/DatabaseTableSqlServerService.cs +++ b/WaterCloud.Service/CommonService/DatabaseTableSqlServerService.cs @@ -13,18 +13,19 @@ using WaterCloud.Domain; namespace WaterCloud.Service.CommonService { - public class DatabaseTableSqlServerService : RepositoryBase, IDatabaseTableService + public class DatabaseTableSqlServerService : IDatabaseTableService { - public DatabaseTableSqlServerService(IDbContext context) : base(context) + private IUnitOfWork _unitOfWork; + public DatabaseTableSqlServerService(IUnitOfWork unitOfWork) { - + _unitOfWork = unitOfWork; } #region 获取数据 public async Task> GetTableList(string tableName) { StringBuilder strSql = new StringBuilder(); strSql.Append(@"SELECT id Id,name TableName FROM sysobjects WHERE (xtype = 'u' or xtype='V') order by name"); - IEnumerable list =await FindList(strSql.ToString()); + IEnumerable list =await _unitOfWork.FindList(strSql.ToString()); if (!tableName.IsEmpty()) { list = list.Where(p => p.TableName.Contains(tableName)); @@ -45,7 +46,7 @@ namespace WaterCloud.Service.CommonService parameter.Add(new DbParam("@TableName", '%' + tableName + '%')); } - IEnumerable list =await FindList(strSql.ToString(), parameter.ToArray()); + IEnumerable list =await _unitOfWork.FindList(strSql.ToString(), parameter.ToArray()); pagination.records = list.Count(); var tempData = list.OrderByDescending(a=>a.CreateTime).Skip(pagination.rows * (pagination.page - 1)).Take(pagination.rows).AsQueryable().ToList(); await SetTableDetail(tempData); @@ -71,7 +72,7 @@ namespace WaterCloud.Service.CommonService ORDER BY b.colid"); var parameter = new List(); parameter.Add(new DbParam("@TableName", tableName)); - var list =await FindList(strSql.ToString(), parameter.ToArray()); + var list =await _unitOfWork.FindList(strSql.ToString(), parameter.ToArray()); return list.ToList(); } #endregion @@ -101,7 +102,7 @@ namespace WaterCloud.Service.CommonService AND sysindexkeys.indid = sysindexes.indid AND syscolumns.colid = sysindexkeys.colid"; - IEnumerable list =await FindList(strSql.ToString()); + IEnumerable list =await _unitOfWork.FindList(strSql.ToString()); return list.ToList(); } diff --git a/WaterCloud.Service/ContentManage/ArticleCategoryService.cs b/WaterCloud.Service/ContentManage/ArticleCategoryService.cs index 9a32ef790a1804ab7cfc4b7961009e5eb77ef9cd..0d0d2e048c9212ec179015ff5e9bc8572c0d9056 100644 --- a/WaterCloud.Service/ContentManage/ArticleCategoryService.cs +++ b/WaterCloud.Service/ContentManage/ArticleCategoryService.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; using WaterCloud.Code; using WaterCloud.Domain.ContentManage; using Chloe; +using WaterCloud.DataBase; namespace WaterCloud.Service.ContentManage { @@ -15,22 +16,20 @@ namespace WaterCloud.Service.ContentManage /// public class ArticleCategoryService : DataFilterService, IDenpendency { - public ArticleCategoryService(IDbContext context) : base(context) + public ArticleCategoryService(IUnitOfWork unitOfWork) : base(unitOfWork) { } - private string cacheKey = "watercloud_cms_articlecategorydata_"; - #region 获取数据 public async Task> GetList(string keyword = "") { - var cachedata = await repository.CheckCacheList(cacheKey + "list"); + var query = repository.IQueryable(); if (!string.IsNullOrEmpty(keyword)) { //此处需修改 - cachedata = cachedata.Where(t => t.F_FullName.Contains(keyword) || t.F_Description.Contains(keyword)).ToList(); + query = query.Where(t => t.F_FullName.Contains(keyword) || t.F_Description.Contains(keyword)); } - return cachedata.Where(t => t.F_DeleteMark == false).OrderByDescending(t => t.F_CreatorTime).ToList(); + return query.Where(t => t.F_DeleteMark == false).OrderByDesc(t => t.F_CreatorTime).ToList(); } public async Task> GetLookList(string keyword = "") @@ -60,13 +59,13 @@ namespace WaterCloud.Service.ContentManage public async Task GetForm(string keyValue) { - var cachedata = await repository.CheckCache(cacheKey, keyValue); - return cachedata; + var data= await repository.FindEntity(keyValue); + return data; } public async Task GetLookForm(string keyValue) { - var cachedata = await repository.CheckCache(cacheKey, keyValue); - return GetFieldsFilterData(cachedata); + var data = await repository.FindEntity(keyValue); + return GetFieldsFilterData(data); } #endregion @@ -79,31 +78,23 @@ namespace WaterCloud.Service.ContentManage //此处需修改 entity.Create(); await repository.Insert(entity); - await CacheHelper.Remove(cacheKey + "list"); } else { //此处需修改 entity.Modify(keyValue); await repository.Update(entity); - await CacheHelper.Remove(cacheKey + keyValue); - await CacheHelper.Remove(cacheKey + "list"); } } public async Task DeleteForm(string keyValue) { var ids = keyValue.Split(','); - if (uniwork.IQueryable(a=> ids.Contains(a.F_CategoryId)).Count()>0) + if (unitwork.IQueryable(a=> ids.Contains(a.F_CategoryId)).Count()>0) { throw new Exception("新闻类别使用中,无法删除"); } await repository.Delete(t => ids.Contains(t.F_Id)); - foreach (var item in ids) - { - await CacheHelper.Remove(cacheKey + item); - } - await CacheHelper.Remove(cacheKey + "list"); } #endregion diff --git a/WaterCloud.Service/ContentManage/ArticleNewsService.cs b/WaterCloud.Service/ContentManage/ArticleNewsService.cs index 0dafb5bd6cbd8881a722b97b8b4e4e64ac2411ba..c0c3c589312476f06798134735b765d93deb795d 100644 --- a/WaterCloud.Service/ContentManage/ArticleNewsService.cs +++ b/WaterCloud.Service/ContentManage/ArticleNewsService.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; using WaterCloud.Code; using WaterCloud.Domain.ContentManage; using Chloe; +using WaterCloud.DataBase; namespace WaterCloud.Service.ContentManage { @@ -15,22 +16,21 @@ namespace WaterCloud.Service.ContentManage /// public class ArticleNewsService : DataFilterService, IDenpendency { - public ArticleNewsService(IDbContext context) : base(context) + public ArticleNewsService(IUnitOfWork unitOfWork) : base(unitOfWork) { } - private string cacheKey = "watercloud_cms_articlenewsdata_"; #region 获取数据 public async Task> GetList(string keyword = "") { - var cachedata = await repository.CheckCacheList(cacheKey + "list"); + var data = repository.IQueryable(); if (!string.IsNullOrEmpty(keyword)) { //此处需修改 - cachedata = cachedata.Where(t => t.F_Title.Contains(keyword) || t.F_Tags.Contains(keyword)).ToList(); + data = data.Where(t => t.F_Title.Contains(keyword) || t.F_Tags.Contains(keyword)); } - return cachedata.Where(t => t.F_DeleteMark == false).OrderByDescending(t => t.F_CreatorTime).ToList(); + return data.Where(t => t.F_DeleteMark == false).OrderByDesc(t => t.F_CreatorTime).ToList(); } public async Task> GetLookList(SoulPage pagination, string keyword = "", string CategoryId="") @@ -167,15 +167,12 @@ namespace WaterCloud.Service.ContentManage //此处需修改 entity.Create(); await repository.Insert(entity); - await CacheHelper.Remove(cacheKey + "list"); } else { //此处需修改 entity.Modify(keyValue); await repository.Update(entity); - await CacheHelper.Remove(cacheKey + keyValue); - await CacheHelper.Remove(cacheKey + "list"); } } @@ -183,11 +180,6 @@ namespace WaterCloud.Service.ContentManage { var ids = keyValue.Split(','); await repository.Delete(t => ids.Contains(t.F_Id)); - foreach (var item in ids) - { - await CacheHelper.Remove(cacheKey + item); - } - await CacheHelper.Remove(cacheKey + "list"); } #endregion diff --git a/WaterCloud.Service/FileManage/UploadfileService.cs b/WaterCloud.Service/FileManage/UploadfileService.cs index 27d7e370c7d7a47fd8d4d5e9b3c1e5c7e397a2b8..65b8045fe663acf1d262a09137c87d546ae97268 100644 --- a/WaterCloud.Service/FileManage/UploadfileService.cs +++ b/WaterCloud.Service/FileManage/UploadfileService.cs @@ -6,6 +6,7 @@ using WaterCloud.Code; using Chloe; using WaterCloud.Domain.FileManage; using WaterCloud.Domain.SystemOrganize; +using WaterCloud.DataBase; namespace WaterCloud.Service.FileManage { @@ -16,21 +17,19 @@ namespace WaterCloud.Service.FileManage /// public class UploadfileService : DataFilterService, IDenpendency { - private string cacheKey = "watercloud_uploadfiledata_"; - - public UploadfileService(IDbContext context) : base(context) + public UploadfileService(IUnitOfWork unitOfWork) : base(unitOfWork) { } #region 获取数据 public async Task> GetList(string keyword = "") { - var cachedata = await repository.CheckCacheList(cacheKey + "list"); + var data = repository.IQueryable(); if (!string.IsNullOrEmpty(keyword)) { //此处需修改 - cachedata = cachedata.Where(t => t.F_FileName.Contains(keyword) || t.F_Description.Contains(keyword)).ToList(); + data = data.Where(t => t.F_FileName.Contains(keyword) || t.F_Description.Contains(keyword)); } - return cachedata.OrderByDescending(t => t.F_CreatorTime).ToList(); + return data.OrderByDesc(t => t.F_CreatorTime).ToList(); } public async Task> GetLookList(string keyword = "") @@ -46,7 +45,7 @@ namespace WaterCloud.Service.FileManage foreach (var item in data) { string[] departments = item.F_OrganizeId.Split(','); - item.F_OrganizeName = string.Join(',', uniwork.IQueryable(a => departments.Contains(a.F_Id)).Select(a => a.F_FullName).ToList()); + item.F_OrganizeName = string.Join(',', unitwork.IQueryable(a => departments.Contains(a.F_Id)).Select(a => a.F_FullName).ToList()); } return data; } @@ -73,7 +72,7 @@ namespace WaterCloud.Service.FileManage //权限过滤 query = GetDataPrivilege("u", "", query); var data = await repository.OrderList(query, pagination); - var orgs = uniwork.IQueryable().ToList(); + var orgs = unitwork.IQueryable().ToList(); foreach (var item in data) { string[] departments = item.F_OrganizeId.Split(','); @@ -105,13 +104,13 @@ namespace WaterCloud.Service.FileManage } public async Task GetForm(string keyValue) { - var cachedata = await repository.CheckCache(cacheKey, keyValue); - return cachedata; + var data = await repository.FindEntity(keyValue); + return data; } public async Task GetLookForm(string keyValue) { - var cachedata = await repository.CheckCache(cacheKey, keyValue); - return GetFieldsFilterData(cachedata); + var data = await repository.FindEntity(keyValue); + return GetFieldsFilterData(data); } #endregion @@ -123,15 +122,12 @@ namespace WaterCloud.Service.FileManage //此处需修改 entity.Create(); await repository.Insert(entity); - await CacheHelper.Remove(cacheKey + "list"); } else { //此处需修改 entity.Modify(keyValue); await repository.Update(entity); - await CacheHelper.Remove(cacheKey + keyValue); - await CacheHelper.Remove(cacheKey + "list"); } } @@ -139,11 +135,6 @@ namespace WaterCloud.Service.FileManage { var ids = keyValue.Split(','); await repository.Delete(t => ids.Contains(t.F_Id)); - foreach (var item in ids) - { - await CacheHelper.Remove(cacheKey + item); - } - await CacheHelper.Remove(cacheKey + "list"); } #endregion diff --git a/WaterCloud.Service/FlowManage/FlowinstanceService.cs b/WaterCloud.Service/FlowManage/FlowinstanceService.cs index 03e775f603a5369b9ea692cf180c309ccf212a78..02660e391b8b9d9514f6e4c9c317fefa4cfd4e66 100644 --- a/WaterCloud.Service/FlowManage/FlowinstanceService.cs +++ b/WaterCloud.Service/FlowManage/FlowinstanceService.cs @@ -13,6 +13,7 @@ using System.IO; using System.Reflection; using WaterCloud.Domain.InfoManage; using WaterCloud.Service.InfoManage; +using WaterCloud.DataBase; namespace WaterCloud.Service.FlowManage { @@ -24,30 +25,29 @@ namespace WaterCloud.Service.FlowManage public class FlowinstanceService : DataFilterService, IDenpendency { private IHttpClientFactory _httpClientFactory; - private string cacheKey = "watercloud_flowinstancedata_"; private MessageService messageApp; private string flowCreator; private string className = System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName.Split('.')[3]; - public FlowinstanceService(IDbContext context, IHttpClientFactory httpClientFactory) : base(context) + public FlowinstanceService(IUnitOfWork unitOfWork, IHttpClientFactory httpClientFactory) : base(unitOfWork) { _httpClientFactory = httpClientFactory; - messageApp = new MessageService(context, httpClientFactory); + messageApp = new MessageService(unitOfWork, httpClientFactory); } #region 获取数据 public async Task> GetList(string keyword = "") { - var cachedata = await repository.CheckCacheList(cacheKey + "list"); + var data = repository.IQueryable(); if (!string.IsNullOrEmpty(keyword)) { //此处需修改 - cachedata = cachedata.Where(t => t.F_Code.Contains(keyword) || t.F_CustomName.Contains(keyword)).ToList(); + data = data.Where(t => t.F_Code.Contains(keyword) || t.F_CustomName.Contains(keyword)); } - return cachedata.Where(a => a.F_EnabledMark == true).OrderByDescending(t => t.F_CreatorTime).ToList(); + return data.Where(a => a.F_EnabledMark == true).OrderByDesc(t => t.F_CreatorTime).ToList(); } public async Task> QueryHistories(string keyValue) { - return uniwork.IQueryable(u => u.F_InstanceId == keyValue).OrderBy(u => u.F_CreatorTime).ToList(); + return unitwork.IQueryable(u => u.F_InstanceId == keyValue).OrderBy(u => u.F_CreatorTime).ToList(); } public async Task> GetLookList(string keyword = "") @@ -87,7 +87,7 @@ namespace WaterCloud.Service.FlowManage } else if (type == "done") //已办事项(即我参与过的流程) { - var instances = uniwork.IQueryable(u => u.F_CreatorUserId == user.UserId) + var instances = unitwork.IQueryable(u => u.F_CreatorUserId == user.UserId) .Select(u => u.F_InstanceId).Distinct().ToList(); query = query.Where(u => instances.Contains(u.F_Id)); } @@ -102,15 +102,15 @@ namespace WaterCloud.Service.FlowManage public async Task GetForm(string keyValue) { - var cachedata = await repository.CheckCache(cacheKey, keyValue); - return cachedata; + var data = await repository.FindEntity(keyValue); + return data; } #endregion public async Task GetLookForm(string keyValue) { - var cachedata = await repository.CheckCache(cacheKey, keyValue); - return GetFieldsFilterData(cachedata); + var data = await repository.FindEntity(keyValue); + return GetFieldsFilterData(data); } #region 获取各种节点的流程审核者 @@ -141,7 +141,7 @@ namespace WaterCloud.Service.FlowManage wfruntime.MakeTagNode(wfruntime.currentNodeId, tag); flowInstance.F_IsFinish = 4;//4表示驳回(需要申请者重新提交表单) - uniwork.BeginTrans(); + unitwork.BeginTrans(); if (resnode != "") { wfruntime.RemoveNode(resnode); @@ -158,12 +158,12 @@ namespace WaterCloud.Service.FlowManage } else { - flowInstance.F_MakerList = await uniwork.IQueryable(a => a.F_FromNodeId == resnode && a.F_ToNodeId == prruntime.nextNodeId).OrderByDesc(a => a.F_CreatorTime).Select(a => a.F_CreatorUserId).FirstAsync();//当前节点可执行的人信息 + flowInstance.F_MakerList = await unitwork.IQueryable(a => a.F_FromNodeId == resnode && a.F_ToNodeId == prruntime.nextNodeId).OrderByDesc(a => a.F_CreatorTime).Select(a => a.F_CreatorUserId).FirstAsync();//当前节点可执行的人信息 } await AddRejectTransHistory(wfruntime, prruntime); await repository.Update(flowInstance); } - await uniwork.Insert(new FlowInstanceOperationHistory + await unitwork.Insert(new FlowInstanceOperationHistory { F_Id = Utils.GuId(), F_InstanceId = reqest.F_FlowInstanceId @@ -183,7 +183,7 @@ namespace WaterCloud.Service.FlowManage if (resnode == wfruntime.startNodeId) { msg.F_MessageInfo = flowInstance.F_CustomName + "--流程驳回"; - var module = uniwork.IQueryable(a => a.F_EnCode == className.Substring(0, className.Length - 7)).FirstOrDefault(); + var module = unitwork.IQueryable(a => a.F_EnCode == className.Substring(0, className.Length - 7)).FirstOrDefault(); msg.F_Href = module.F_UrlAddress; msg.F_HrefTarget = module.F_Target; msg.F_ToUserId = flowInstance.F_CreatorUserId; @@ -194,7 +194,7 @@ namespace WaterCloud.Service.FlowManage else { msg.F_MessageInfo = flowInstance.F_CustomName + "--流程待处理"; - var module = uniwork.IQueryable(a => a.F_EnCode == className.Substring(0, className.Length - 7)).FirstOrDefault(); + var module = unitwork.IQueryable(a => a.F_EnCode == className.Substring(0, className.Length - 7)).FirstOrDefault(); msg.F_Href = module.F_UrlAddress.Remove(module.F_UrlAddress.Length - 5, 5) + "ToDoFlow"; msg.F_HrefTarget = module.F_Target; msg.F_ToUserId = flowInstance.F_MakerList == "1" ? "" : flowInstance.F_MakerList; @@ -204,13 +204,13 @@ namespace WaterCloud.Service.FlowManage msg.F_CreatorUserName = currentuser.UserName; msg.F_EnabledMark = true; msg.F_MessageType = 2; - var lastmsg = uniwork.IQueryable(a => a.F_ClickRead == false && a.F_KeyValue == flowInstance.F_Id).OrderByDesc(a => a.F_CreatorTime).FirstOrDefault(); - if (lastmsg != null && uniwork.IQueryable(a => a.F_MessageId == lastmsg.F_Id).Count() == 0) + var lastmsg = unitwork.IQueryable(a => a.F_ClickRead == false && a.F_KeyValue == flowInstance.F_Id).OrderByDesc(a => a.F_CreatorTime).FirstOrDefault(); + if (lastmsg != null && unitwork.IQueryable(a => a.F_MessageId == lastmsg.F_Id).Count() == 0) { await messageApp.ReadMsgForm(lastmsg.F_Id); } await messageApp.SubmitForm(msg); - uniwork.Commit(); + unitwork.Commit(); wfruntime.NotifyThirdParty(_httpClientFactory.CreateClient(), tag); @@ -244,7 +244,7 @@ namespace WaterCloud.Service.FlowManage F_CreatorTime = DateTime.Now };//操作记录 FlowRuntime wfruntime = new FlowRuntime(flowInstance); - uniwork.BeginTrans(); + unitwork.BeginTrans(); #region 会签 if (flowInstance.F_ActivityType == 0)//当前节点是会签节点 { @@ -323,15 +323,15 @@ namespace WaterCloud.Service.FlowManage wfruntime.RemoveNode(wfruntime.nextNodeId); flowInstance.F_SchemeContent = wfruntime.ToSchemeObj().ToJson(); - await uniwork.Update(flowInstance); - await uniwork.Insert(flowInstanceOperationHistory); + await unitwork.Update(flowInstance); + await unitwork.Insert(flowInstanceOperationHistory); MessageEntity msg = new MessageEntity(); msg.F_CreatorUserName = currentuser.UserName; msg.F_EnabledMark = true; if (flowInstance.F_IsFinish == 1) { msg.F_MessageInfo = flowInstance.F_CustomName + "--流程已完成"; - var module = uniwork.IQueryable(a => a.F_EnCode == className.Substring(0, className.Length - 7)).FirstOrDefault(); + var module = unitwork.IQueryable(a => a.F_EnCode == className.Substring(0, className.Length - 7)).FirstOrDefault(); msg.F_Href = module.F_UrlAddress; msg.F_HrefTarget = module.F_Target; msg.F_ToUserId = flowInstance.F_CreatorUserId; @@ -341,10 +341,10 @@ namespace WaterCloud.Service.FlowManage else if (flowInstance.F_IsFinish == 3) { msg.F_MessageInfo = flowInstance.F_CustomName + "--流程已终止"; - var module = uniwork.IQueryable(a => a.F_EnCode == className.Substring(0, className.Length - 7)).FirstOrDefault(); + var module = unitwork.IQueryable(a => a.F_EnCode == className.Substring(0, className.Length - 7)).FirstOrDefault(); msg.F_Href = module.F_UrlAddress; msg.F_HrefTarget = module.F_Target; - var makerList = uniwork.IQueryable(a => a.F_InstanceId == flowInstance.F_Id && a.F_CreatorUserId != currentuser.UserId).Select(a => a.F_CreatorUserId).Distinct().ToList(); + var makerList = unitwork.IQueryable(a => a.F_InstanceId == flowInstance.F_Id && a.F_CreatorUserId != currentuser.UserId).Select(a => a.F_CreatorUserId).Distinct().ToList(); msg.F_ToUserId = flowInstance.F_CreatorUserId; msg.F_ClickRead = true; msg.F_KeyValue = flowInstance.F_Id; @@ -352,7 +352,7 @@ namespace WaterCloud.Service.FlowManage else { msg.F_MessageInfo = flowInstance.F_CustomName + "--流程待处理"; - var module = uniwork.IQueryable(a => a.F_EnCode == className.Substring(0, className.Length - 7)).FirstOrDefault(); + var module = unitwork.IQueryable(a => a.F_EnCode == className.Substring(0, className.Length - 7)).FirstOrDefault(); msg.F_Href = module.F_UrlAddress.Remove(module.F_UrlAddress.Length - 5, 5) + "ToDoFlow"; msg.F_HrefTarget = module.F_Target; msg.F_ToUserId = flowInstance.F_MakerList == "1" ? "" : flowInstance.F_MakerList; @@ -360,13 +360,13 @@ namespace WaterCloud.Service.FlowManage msg.F_KeyValue = flowInstance.F_Id; } msg.F_MessageType = 2; - var lastmsg = uniwork.IQueryable(a => a.F_ClickRead == false && a.F_KeyValue == flowInstance.F_Id).OrderByDesc(a => a.F_CreatorTime).FirstOrDefault(); - if (lastmsg != null && uniwork.IQueryable(a => a.F_MessageId == lastmsg.F_Id).Count() == 0) + var lastmsg = unitwork.IQueryable(a => a.F_ClickRead == false && a.F_KeyValue == flowInstance.F_Id).OrderByDesc(a => a.F_CreatorTime).FirstOrDefault(); + if (lastmsg != null && unitwork.IQueryable(a => a.F_MessageId == lastmsg.F_Id).Count() == 0) { await messageApp.ReadMsgForm(lastmsg.F_Id); } await messageApp.SubmitForm(msg); - uniwork.Commit(); + unitwork.Commit(); wfruntime.NotifyThirdParty(_httpClientFactory.CreateClient(), tag); return true; @@ -416,7 +416,7 @@ namespace WaterCloud.Service.FlowManage var users = new List(); foreach (var item in request.NodeDesignates) { - var temps = uniwork.IQueryable(a => a.F_RoleId.Contains(item) && a.F_EnabledMark == true && a.F_DeleteMark == false).Select(a => a.F_Id).ToList(); + var temps = unitwork.IQueryable(a => a.F_RoleId.Contains(item) && a.F_EnabledMark == true && a.F_DeleteMark == false).Select(a => a.F_Id).ToList(); if (temps!=null&&temps.Count>0) { users.AddRange(temps); @@ -528,11 +528,11 @@ namespace WaterCloud.Service.FlowManage List users = new List(); foreach (var item in node.setInfo.NodeDesignateData.roles) { - var temp = uniwork.IQueryable(a => a.F_RoleId.Contains(item)).ToList(); + var temp = unitwork.IQueryable(a => a.F_RoleId.Contains(item)).ToList(); var tempList = new List(); if (node.setInfo.NodeDesignateData.currentDepart) { - var currentDepartment = uniwork.FindEntity(flowCreator).GetAwaiter().GetResult().F_DepartmentId.Split(',').ToList(); + var currentDepartment = unitwork.FindEntity(flowCreator).GetAwaiter().GetResult().F_DepartmentId.Split(',').ToList(); foreach (var user in temp) { var nextCurrentDepartment = user.F_DepartmentId.Split(',').ToList(); @@ -592,7 +592,7 @@ namespace WaterCloud.Service.FlowManage if (flowinstance.NextNodeDesignateType==Setinfo.SPECIAL_USER) { flowinstance.NextNodeDesignates = runtime.nextNode.setInfo.NodeDesignateData.users; - flowinstance.NextMakerName = string.Join(',', uniwork.IQueryable(a => flowinstance.NextNodeDesignates.Contains(a.F_Id)).Select(a => a.F_RealName).ToList()); + flowinstance.NextMakerName = string.Join(',', unitwork.IQueryable(a => flowinstance.NextNodeDesignates.Contains(a.F_Id)).Select(a => a.F_RealName).ToList()); } else if (flowinstance.NextNodeDesignateType == Setinfo.SPECIAL_ROLE) { @@ -601,11 +601,11 @@ namespace WaterCloud.Service.FlowManage List users = new List(); foreach (var item in flowinstance.NextNodeDesignates) { - var temp = uniwork.IQueryable(a => a.F_RoleId.Contains(item)).ToList(); + var temp = unitwork.IQueryable(a => a.F_RoleId.Contains(item)).ToList(); var tempList = new List(); if (runtime.nextNode.setInfo.NodeDesignateData.currentDepart) { - var currentDepartment = uniwork.FindEntity(flowCreator).GetAwaiter().GetResult().F_DepartmentId.Split(',').ToList(); + var currentDepartment = unitwork.FindEntity(flowCreator).GetAwaiter().GetResult().F_DepartmentId.Split(',').ToList(); foreach (var user in temp) { var nextCurrentDepartment = user.F_DepartmentId.Split(',').ToList(); @@ -623,7 +623,7 @@ namespace WaterCloud.Service.FlowManage users.AddRange(tempFinal); } users = users.Distinct().ToList(); - flowinstance.NextMakerName = string.Join(',', uniwork.IQueryable(a => users.Contains(a.F_Id)).Select(a => a.F_RealName).ToList()); + flowinstance.NextMakerName = string.Join(',', unitwork.IQueryable(a => users.Contains(a.F_Id)).Select(a => a.F_RealName).ToList()); } } if (runtime.currentNode != null && runtime.currentNode.setInfo != null && runtime.currentNodeType != 4) @@ -632,7 +632,7 @@ namespace WaterCloud.Service.FlowManage if (flowinstance.F_MakerList!="1" && !string.IsNullOrEmpty(flowinstance.F_MakerList)) { var temps = flowinstance.F_MakerList.Split(','); - flowinstance.CurrentMakerName = string.Join(',', uniwork.IQueryable(a => temps.Contains(a.F_Id)).Select(a => a.F_RealName).ToList()); + flowinstance.CurrentMakerName = string.Join(',', unitwork.IQueryable(a => temps.Contains(a.F_Id)).Select(a => a.F_RealName).ToList()); } else { @@ -651,7 +651,7 @@ namespace WaterCloud.Service.FlowManage private async Task AddTransHistory(FlowRuntime wfruntime) { var tag = currentuser; - await uniwork.Insert(new FlowInstanceTransitionHistory + await unitwork.Insert(new FlowInstanceTransitionHistory { F_Id = Utils.GuId(), F_InstanceId = wfruntime.flowInstanceId, @@ -674,7 +674,7 @@ namespace WaterCloud.Service.FlowManage private async Task AddRejectTransHistory(FlowRuntime wfruntime, FlowRuntime prruntime) { var tag = currentuser; - await uniwork.Insert(new FlowInstanceTransitionHistory + await unitwork.Insert(new FlowInstanceTransitionHistory { F_Id = Utils.GuId(), F_InstanceId = wfruntime.flowInstanceId, @@ -702,8 +702,6 @@ namespace WaterCloud.Service.FlowManage { await NodeVerification(entity); } - await CacheHelper.Remove(cacheKey + entity.F_FlowInstanceId); - await CacheHelper.Remove(cacheKey + "list"); } public async Task CreateInstance(FlowinstanceEntity entity) { @@ -715,14 +713,14 @@ namespace WaterCloud.Service.FlowManage FlowschemeEntity scheme = null; if (!string.IsNullOrEmpty(entity.F_SchemeId)) { - scheme = await uniwork.FindEntity(entity.F_SchemeId); + scheme = await unitwork.FindEntity(entity.F_SchemeId); } if (scheme == null) { throw new Exception("该流程模板已不存在,请重新设计流程"); } entity.F_SchemeContent = scheme.F_SchemeContent; - var form = await uniwork.FindEntity(scheme.F_FrmId); + var form = await unitwork.FindEntity(scheme.F_FrmId); if (form == null) { throw new Exception("该流程模板对应的表单已不存在,请重新设计流程"); @@ -761,8 +759,8 @@ namespace WaterCloud.Service.FlowManage entity.F_CreatorUserName = user.UserName; entity.F_MakerList = (wfruntime.GetNextNodeType() != 4 ? GetNextMakers(wfruntime, nodeDesignate) : ""); entity.F_IsFinish = (wfruntime.GetNextNodeType() == 4 ? 1 : 0); - uniwork.BeginTrans(); - await uniwork.Insert(entity); + unitwork.BeginTrans(); + await unitwork.Insert(entity); wfruntime.flowInstanceId = entity.F_Id; //复杂表单提交 @@ -793,7 +791,7 @@ namespace WaterCloud.Service.FlowManage + entity.F_Code + "/" + entity.F_CustomName + "】" }; - await uniwork.Insert(processOperationHistoryEntity); + await unitwork.Insert(processOperationHistoryEntity); #endregion 流程操作记录 @@ -805,7 +803,7 @@ namespace WaterCloud.Service.FlowManage if (entity.F_IsFinish == 1) { msg.F_MessageInfo = entity.F_CustomName + "--流程已完成"; - var module = uniwork.IQueryable(a => a.F_EnCode == className.Substring(0, className.Length - 7)).FirstOrDefault(); + var module = unitwork.IQueryable(a => a.F_EnCode == className.Substring(0, className.Length - 7)).FirstOrDefault(); msg.F_Href = module.F_UrlAddress; msg.F_HrefTarget = module.F_Target; msg.F_ClickRead = true; @@ -814,10 +812,10 @@ namespace WaterCloud.Service.FlowManage else if (entity.F_IsFinish == 3) { msg.F_MessageInfo = entity.F_CustomName + "--流程已终止"; - var module = uniwork.IQueryable(a => a.F_EnCode == className.Substring(0, className.Length - 7)).FirstOrDefault(); + var module = unitwork.IQueryable(a => a.F_EnCode == className.Substring(0, className.Length - 7)).FirstOrDefault(); msg.F_Href = module.F_UrlAddress; msg.F_HrefTarget = module.F_Target; - var makerList = uniwork.IQueryable(a => a.F_InstanceId == entity.F_Id && a.F_CreatorUserId != currentuser.UserId).Select(a => a.F_CreatorUserId).Distinct().ToList(); + var makerList = unitwork.IQueryable(a => a.F_InstanceId == entity.F_Id && a.F_CreatorUserId != currentuser.UserId).Select(a => a.F_CreatorUserId).Distinct().ToList(); msg.F_ToUserId = entity.F_CreatorUserId; msg.F_ClickRead = true; msg.F_KeyValue = entity.F_Id; @@ -825,7 +823,7 @@ namespace WaterCloud.Service.FlowManage else { msg.F_MessageInfo = entity.F_CustomName + "--流程待处理"; - var module = uniwork.IQueryable(a => a.F_EnCode == className.Substring(0, className.Length - 7)).FirstOrDefault(); + var module = unitwork.IQueryable(a => a.F_EnCode == className.Substring(0, className.Length - 7)).FirstOrDefault(); msg.F_Href = module.F_UrlAddress.Remove(module.F_UrlAddress.Length - 5, 5) + "ToDoFlow"; msg.F_HrefTarget = module.F_Target; msg.F_ClickRead = false; @@ -833,14 +831,13 @@ namespace WaterCloud.Service.FlowManage } msg.F_MessageType = 2; msg.F_ToUserId = entity.F_MakerList == "1" ? "" : entity.F_MakerList; - var lastmsg = uniwork.IQueryable(a => a.F_ClickRead == false && a.F_KeyValue == entity.F_Id).OrderByDesc(a => a.F_CreatorTime).FirstOrDefault(); - if (lastmsg != null && uniwork.IQueryable(a => a.F_MessageId == lastmsg.F_Id).Count() == 0) + var lastmsg = unitwork.IQueryable(a => a.F_ClickRead == false && a.F_KeyValue == entity.F_Id).OrderByDesc(a => a.F_CreatorTime).FirstOrDefault(); + if (lastmsg != null && unitwork.IQueryable(a => a.F_MessageId == lastmsg.F_Id).Count() == 0) { await messageApp.ReadMsgForm(lastmsg.F_Id); } await messageApp.SubmitForm(msg); - uniwork.Commit(); - await CacheHelper.Remove(cacheKey + "list"); + unitwork.Commit(); } public async Task UpdateInstance(FlowinstanceEntity entity) { @@ -851,14 +848,14 @@ namespace WaterCloud.Service.FlowManage FlowschemeEntity scheme = null; if (!string.IsNullOrEmpty(entity.F_SchemeId)) { - scheme = await uniwork.FindEntity(entity.F_SchemeId); + scheme = await unitwork.FindEntity(entity.F_SchemeId); } if (scheme == null) { throw new Exception("该流程模板已不存在,请重新设计流程"); } entity.F_SchemeContent = scheme.F_SchemeContent; - var form = await uniwork.FindEntity(scheme.F_FrmId); + var form = await unitwork.FindEntity(scheme.F_FrmId); if (form == null) { throw new Exception("该流程模板对应的表单已不存在,请重新设计流程"); @@ -896,8 +893,8 @@ namespace WaterCloud.Service.FlowManage entity.F_CreatorUserName = user.UserName; entity.F_MakerList = (wfruntime.GetNextNodeType() != 4 ? GetNextMakers(wfruntime, nodeDesignate) : ""); entity.F_IsFinish = (wfruntime.GetNextNodeType() == 4 ? 1 : 0); - uniwork.BeginTrans(); - await uniwork.Update(entity); + unitwork.BeginTrans(); + await unitwork.Update(entity); wfruntime.flowInstanceId = entity.F_Id; //复杂表单提交 if (entity.F_FrmType == 1) @@ -925,7 +922,7 @@ namespace WaterCloud.Service.FlowManage + entity.F_Code + "/" + entity.F_CustomName + "】" }; - await uniwork.Insert(processOperationHistoryEntity); + await unitwork.Insert(processOperationHistoryEntity); #endregion await AddTransHistory(wfruntime); @@ -936,7 +933,7 @@ namespace WaterCloud.Service.FlowManage if (entity.F_IsFinish == 1) { msg.F_MessageInfo = entity.F_CustomName + "--流程已完成"; - var module = uniwork.IQueryable(a => a.F_EnCode == className.Substring(0, className.Length - 7)).FirstOrDefault(); + var module = unitwork.IQueryable(a => a.F_EnCode == className.Substring(0, className.Length - 7)).FirstOrDefault(); msg.F_Href = module.F_UrlAddress; msg.F_HrefTarget = module.F_Target; msg.F_ClickRead = true; @@ -945,10 +942,10 @@ namespace WaterCloud.Service.FlowManage else if (entity.F_IsFinish == 3) { msg.F_MessageInfo = entity.F_CustomName + "--流程已终止"; - var module = uniwork.IQueryable(a => a.F_EnCode == className.Substring(0, className.Length - 7)).FirstOrDefault(); + var module = unitwork.IQueryable(a => a.F_EnCode == className.Substring(0, className.Length - 7)).FirstOrDefault(); msg.F_Href = module.F_UrlAddress; msg.F_HrefTarget = module.F_Target; - var makerList = uniwork.IQueryable(a => a.F_InstanceId == entity.F_Id && a.F_CreatorUserId != currentuser.UserId).Select(a => a.F_CreatorUserId).Distinct().ToList(); + var makerList = unitwork.IQueryable(a => a.F_InstanceId == entity.F_Id && a.F_CreatorUserId != currentuser.UserId).Select(a => a.F_CreatorUserId).Distinct().ToList(); msg.F_ToUserId = entity.F_CreatorUserId; msg.F_ClickRead = true; msg.F_KeyValue = entity.F_Id; @@ -956,7 +953,7 @@ namespace WaterCloud.Service.FlowManage else { msg.F_MessageInfo = entity.F_CustomName + "--流程待处理"; - var module = uniwork.IQueryable(a => a.F_EnCode == className.Substring(0, className.Length - 7)).FirstOrDefault(); + var module = unitwork.IQueryable(a => a.F_EnCode == className.Substring(0, className.Length - 7)).FirstOrDefault(); msg.F_Href = module.F_UrlAddress.Remove(module.F_UrlAddress.Length - 5, 5) + "ToDoFlow"; msg.F_HrefTarget = module.F_Target; msg.F_ClickRead = false; @@ -964,17 +961,13 @@ namespace WaterCloud.Service.FlowManage } msg.F_MessageType = 2; msg.F_ToUserId = entity.F_MakerList == "1" ? "" : entity.F_MakerList; - var lastmsg = uniwork.IQueryable(a => a.F_ClickRead == false && a.F_KeyValue == entity.F_Id).OrderByDesc(a => a.F_CreatorTime).FirstOrDefault(); - if (lastmsg != null && uniwork.IQueryable(a => a.F_MessageId == lastmsg.F_Id).Count() == 0) + var lastmsg = unitwork.IQueryable(a => a.F_ClickRead == false && a.F_KeyValue == entity.F_Id).OrderByDesc(a => a.F_CreatorTime).FirstOrDefault(); + if (lastmsg != null && unitwork.IQueryable(a => a.F_MessageId == lastmsg.F_Id).Count() == 0) { await messageApp.ReadMsgForm(lastmsg.F_Id); } await messageApp.SubmitForm(msg); - uniwork.Commit(); - await CacheHelper.Remove(cacheKey + entity.F_Id); - await CacheHelper.Remove(cacheKey + "list"); - msg.F_ClickRead = false; - msg.F_KeyValue = entity.F_Id; + unitwork.Commit(); } public async Task DeleteForm(string keyValue) @@ -984,11 +977,6 @@ namespace WaterCloud.Service.FlowManage { F_EnabledMark = false }); - foreach (var item in ids) - { - await CacheHelper.Remove(cacheKey + item); - } - await CacheHelper.Remove(cacheKey + "list"); } #endregion diff --git a/WaterCloud.Service/FlowManage/FormTestService.cs b/WaterCloud.Service/FlowManage/FormTestService.cs index aea80f3b5b4b46de863ab84f4c05c1dfaffffa0c..442c6d89cb0c7176750ae710400f806b2de6956c 100644 --- a/WaterCloud.Service/FlowManage/FormTestService.cs +++ b/WaterCloud.Service/FlowManage/FormTestService.cs @@ -8,12 +8,13 @@ using System.Threading.Tasks; using WaterCloud.Code; using Chloe; using WaterCloud.Domain.FlowManage; +using WaterCloud.DataBase; namespace WaterCloud.Service.FlowManage { public class FormTestService : DataFilterService, IDenpendency,ICustomerForm { - public FormTestService(IDbContext context) : base(context) + public FormTestService(IUnitOfWork unitOfWork) : base(unitOfWork) { } public async Task Add(string flowInstanceId, string frmData) diff --git a/WaterCloud.Service/Hubs/MessageHub.cs b/WaterCloud.Service/Hubs/MessageHub.cs index c38cfc0864e33b80858b5b778b9da9459f3ec91e..fb85b1fcc67840aa6dd101d02a201cdfa981bcad 100644 --- a/WaterCloud.Service/Hubs/MessageHub.cs +++ b/WaterCloud.Service/Hubs/MessageHub.cs @@ -11,10 +11,10 @@ namespace WaterCloud.Service { public class MessageHub : Hub { - private string cacheKey = "watercloud_hubuserinfo_"; + private string cacheKey = GlobalContext.SystemConfig.ProjectPrefix + "_hubuserinfo_"; private readonly UserService _service; private readonly MessageService _msgService; - private string cacheKeyOperator = "watercloud_operator_";// +登录者tokens + private string cacheKeyOperator = GlobalContext.SystemConfig.ProjectPrefix + "_operator_";// +登录者tokens public MessageHub(UserService service, MessageService msgService) { _service = service; @@ -37,13 +37,21 @@ namespace WaterCloud.Service await Groups.AddToGroupAsync(Context.ConnectionId, user.CompanyId); //将用户信息存进缓存 var list = await CacheHelper.Get>(cacheKey + user.UserId); + //登录计数 + var onlinelist = await CacheHelper.Get>(cacheKey + "list_" + user.CompanyId); + if (onlinelist == null || onlinelist.Count == 0) + { + onlinelist = new List(); + } if (list == null) { list = new List(); } list.Add(Context.ConnectionId); + onlinelist.Add(Context.ConnectionId); await CacheHelper.Set(cacheKey + Context.ConnectionId, user.UserId); await CacheHelper.Set(cacheKey + user.UserId, list); + await CacheHelper.Set(cacheKey + "list_" + user.CompanyId, onlinelist); } } /// @@ -72,12 +80,15 @@ namespace WaterCloud.Service } public override async Task OnDisconnectedAsync(Exception exception) { + var user = _service.currentuser; //删除缓存连接 var userId = await CacheHelper.Get(cacheKey + Context.ConnectionId); if (!string.IsNullOrEmpty(userId)) { //将用户信息存进缓存 var list = await CacheHelper.Get>(cacheKey + userId); + //登录计数 + var onlinelist = await CacheHelper.Get>(cacheKey + "list_" + user.CompanyId); if (list != null) { list.Remove(Context.ConnectionId); @@ -90,6 +101,18 @@ namespace WaterCloud.Service await CacheHelper.Set(cacheKey + userId, list); } } + if (onlinelist != null) + { + onlinelist.Remove(Context.ConnectionId); + if (list.Count == 0) + { + await CacheHelper.Remove(cacheKey + "list_" + user.CompanyId); + } + else + { + await CacheHelper.Set(cacheKey + "list_" + user.CompanyId, onlinelist); + } + } await CacheHelper.Remove(cacheKey + Context.ConnectionId); } await base.OnDisconnectedAsync(exception); diff --git a/WaterCloud.Service/InfoManage/MessageService.cs b/WaterCloud.Service/InfoManage/MessageService.cs index cbaa812cd2121929abbc2c51c99c3ce70142f650..c0a0d311a6c6d64970df0362a352957d7685c5c0 100644 --- a/WaterCloud.Service/InfoManage/MessageService.cs +++ b/WaterCloud.Service/InfoManage/MessageService.cs @@ -11,6 +11,8 @@ using WaterCloud.Service.SystemManage; using System.Net.Http; using WaterCloud.Domain.SystemManage; using System.Text; +using WaterCloud.DataBase; + namespace WaterCloud.Service.InfoManage { @@ -21,14 +23,14 @@ namespace WaterCloud.Service.InfoManage /// public class MessageService : DataFilterService, IDenpendency { - private string cacheHubKey = "watercloud_hubuserinfo_"; + private string cacheHubKey = GlobalContext.SystemConfig.ProjectPrefix + "_hubuserinfo_"; private readonly IHubContext _messageHub; private ItemsDataService itemsApp; private IHttpClientFactory _httpClientFactory; - public MessageService(IDbContext context, IHttpClientFactory httpClientFactory, IHubContext messageHub = null) : base(context) + public MessageService(IUnitOfWork unitOfWork, IHttpClientFactory httpClientFactory, IHubContext messageHub = null) : base(unitOfWork) { - itemsApp = new ItemsDataService(context); + itemsApp = new ItemsDataService(unitOfWork); _messageHub = messageHub; _httpClientFactory = httpClientFactory; } @@ -58,7 +60,7 @@ namespace WaterCloud.Service.InfoManage public async Task> GetUnReadListJson() { - var hisquery = uniwork.IQueryable(a => a.F_CreatorUserId == currentuser.UserId).Select(a => a.F_MessageId).ToList(); + var hisquery = unitwork.IQueryable(a => a.F_CreatorUserId == currentuser.UserId).Select(a => a.F_MessageId).ToList(); var tempList= repository.IQueryable(a => a.F_MessageType == 2).InnerJoin((a, b) => a.F_Id == b.F_MessageId).Select((a, b) => a.F_Id).ToList(); hisquery.AddRange(tempList); var query = repository.IQueryable(a => (a.F_ToUserId.Contains(currentuser.UserId) || a.F_ToUserId == "") && a.F_EnabledMark == true).Where(a => !hisquery.Contains(a.F_Id)); @@ -118,13 +120,13 @@ namespace WaterCloud.Service.InfoManage else { var users = entity.F_ToUserId.Split(","); - entity.F_ToUserName = string.Join(",", uniwork.IQueryable(a => users.Contains(a.F_Id)).Select(a => a.F_RealName).ToList()); + entity.F_ToUserName = string.Join(",", unitwork.IQueryable(a => users.Contains(a.F_Id)).Select(a => a.F_RealName).ToList()); messageEntity= await repository.Insert(entity); } //通过http发送消息 messageEntity.companyId = currentuser.CompanyId; var mouduleName = ReflectionHelper.GetModuleName(1); - var module = uniwork.IQueryable(a => a.F_EnCode == mouduleName).FirstOrDefault(); + var module = unitwork.IQueryable(a => a.F_EnCode == mouduleName).FirstOrDefault(); var url = module.F_UrlAddress.Substring(0, module.F_UrlAddress.Length - 5) + "SendWebSocketMsg"; HttpContent httpContent = new StringContent(messageEntity.ToJson(), Encoding.UTF8); httpContent.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json"); @@ -159,12 +161,12 @@ namespace WaterCloud.Service.InfoManage { var unList=await GetUnReadListJson(); var strList = unList.Where(a => a.F_MessageType == type&&a.F_ClickRead==true).Select(a=>a.F_Id).ToList(); - uniwork.BeginTrans(); + unitwork.BeginTrans(); foreach (var item in strList) { await ReadMsgForm(item); } - uniwork.Commit(); + unitwork.Commit(); } public async Task ReadMsgForm(string keyValue) @@ -173,7 +175,7 @@ namespace WaterCloud.Service.InfoManage msghis.Create(); msghis.F_CreatorUserName = currentuser.UserName; msghis.F_MessageId = keyValue; - await uniwork.Insert(msghis); + await unitwork.Insert(msghis); } public async Task CheckMsg(string keyValue) @@ -187,7 +189,7 @@ namespace WaterCloud.Service.InfoManage { return true; } - if (uniwork.IQueryable(a => a.F_MessageId == keyValue && a.F_CreatorUserId == currentuser.UserId).Count() > 0) + if (unitwork.IQueryable(a => a.F_MessageId == keyValue && a.F_CreatorUserId == currentuser.UserId).Count() > 0) { return true; } diff --git a/WaterCloud.Service/Infrastructure/DataFilterService.cs b/WaterCloud.Service/Infrastructure/DataFilterService.cs index 4d485da5123fe713d7c24586b780a65c16442808..1044db3aceb172fedaf222b044f10a07cb6b1a0c 100644 --- a/WaterCloud.Service/Infrastructure/DataFilterService.cs +++ b/WaterCloud.Service/Infrastructure/DataFilterService.cs @@ -13,27 +13,19 @@ using WaterCloud.Domain.SystemOrganize; namespace WaterCloud.Service { - public class DataFilterService where T : class, new() + public class DataFilterService: RepositoryBase where T : class, new() { // 用户信息 public OperatorModel currentuser; // 用于当前表操作 protected IRepositoryBase repository; // 用于其他表操作 - protected IRepositoryBase uniwork; - public DataFilterService(IDbContext context) + protected IUnitOfWork unitwork; + public DataFilterService(IUnitOfWork unitOfWork):base(unitOfWork) { currentuser = OperatorProvider.Provider.GetCurrent(); - if (currentuser != null && !(currentuser.DBProvider == GlobalContext.SystemConfig.DBProvider && currentuser.DbString == GlobalContext.SystemConfig.DBConnectionString)) - { - repository = new RepositoryBase(currentuser.DbString, currentuser.DBProvider); - uniwork = new RepositoryBase(currentuser.DbString, currentuser.DBProvider); - } - else - { - repository = new RepositoryBase(context); - uniwork = new RepositoryBase(context); - } + repository = this; + unitwork = unitOfWork; if (currentuser == null) { currentuser = new OperatorModel(); @@ -57,7 +49,7 @@ namespace WaterCloud.Service { return GetFieldsFilterDataNew(parametername,query, moduleName); } - var rule = uniwork.IQueryable(u => u.F_ModuleCode == moduleName).FirstOrDefault(); + var rule = unitwork.IQueryable(u => u.F_ModuleCode == moduleName).FirstOrDefault(); if (rule.F_PrivilegeRules.Contains(Define.DATAPRIVILEGE_LOGINUSER) || rule.F_PrivilegeRules.Contains(Define.DATAPRIVILEGE_LOGINROLE) || rule.F_PrivilegeRules.Contains(Define.DATAPRIVILEGE_LOGINORG)) @@ -94,7 +86,7 @@ namespace WaterCloud.Service { return GetFieldsFilterDataNew(parametername,query, moduleName); } - var rule = uniwork.IQueryable(u => u.F_ModuleCode == moduleName).FirstOrDefault(); + var rule = unitwork.IQueryable(u => u.F_ModuleCode == moduleName).FirstOrDefault(); if (rule.F_PrivilegeRules.Contains(Define.DATAPRIVILEGE_LOGINUSER) || rule.F_PrivilegeRules.Contains(Define.DATAPRIVILEGE_LOGINROLE) || rule.F_PrivilegeRules.Contains(Define.DATAPRIVILEGE_LOGINORG)) @@ -122,7 +114,7 @@ namespace WaterCloud.Service { moduleName = string.IsNullOrEmpty(moduleName) ? ReflectionHelper.GetModuleName() : moduleName; if (currentuser.UserId == GlobalContext.SystemConfig.SysemUserId) return false; //超级管理员特权 - var rule = uniwork.IQueryable(u => u.F_ModuleCode == moduleName).FirstOrDefault(); + var rule = unitwork.IQueryable(u => u.F_ModuleCode == moduleName).FirstOrDefault(); ////系统菜单也不需要数据权限 跟字段重合取消这样处理 //var module = UnitWork.FindEntity(u => u.F_EnCode == moduleName).GetAwaiter().GetResult(); if (rule == null) @@ -178,9 +170,9 @@ namespace WaterCloud.Service return list; } //系统菜单跳过 - var module = uniwork.IQueryable(u => u.F_EnCode == moduleName).FirstOrDefault(); + var module = unitwork.IQueryable(u => u.F_EnCode == moduleName).FirstOrDefault(); //判断是否需要字段权限 - if (module.F_IsFields == false) + if (module == null || module.F_IsFields == false) { return list; } @@ -190,8 +182,8 @@ namespace WaterCloud.Service return list; } var rolelist = currentuser.RoleId.Split(','); - var rule = uniwork.IQueryable(u => rolelist.Contains(u.F_ObjectId) && u.F_ItemType == 3).Select(a => a.F_ItemId).Distinct().ToList(); - var fieldsList = uniwork.IQueryable(u => (rule.Contains(u.F_Id) || u.F_IsPublic == true) && u.F_ModuleId == module.F_Id).Select(u => u.F_EnCode).ToList(); + var rule = unitwork.IQueryable(u => rolelist.Contains(u.F_ObjectId) && u.F_ItemType == 3).Select(a => a.F_ItemId).Distinct().ToList(); + var fieldsList = unitwork.IQueryable(u => (rule.Contains(u.F_Id) || u.F_IsPublic == true) && u.F_ModuleId == module.F_Id).Select(u => u.F_EnCode).ToList(); //反射获取主键 PropertyInfo pkProp = typeof(TEntity).GetProperties().Where(p => p.GetCustomAttributes(typeof(ColumnAttribute), false).Length > 0).FirstOrDefault(); var idName = "F_Id"; @@ -218,9 +210,9 @@ namespace WaterCloud.Service return entity; } //系统菜单跳过 - var module = uniwork.IQueryable(u => u.F_EnCode == moduleName).FirstOrDefault(); + var module = unitwork.IQueryable(u => u.F_EnCode == moduleName).FirstOrDefault(); //判断是否需要字段权限 - if (module.F_IsFields == false) + if (module == null || module.F_IsFields == false) { return entity; } @@ -230,8 +222,8 @@ namespace WaterCloud.Service return entity; } var rolelist = currentuser.RoleId.Split(','); - var rule = uniwork.IQueryable(u => rolelist.Contains(u.F_ObjectId) && u.F_ItemType == 3).Select(a => a.F_ItemId).Distinct().ToList(); - var fieldsList = uniwork.IQueryable(u => (rule.Contains(u.F_Id) || u.F_IsPublic == true) && u.F_ModuleId == module.F_Id).Select(u => u.F_EnCode).ToList(); + var rule = unitwork.IQueryable(u => rolelist.Contains(u.F_ObjectId) && u.F_ItemType == 3).Select(a => a.F_ItemId).Distinct().ToList(); + var fieldsList = unitwork.IQueryable(u => (rule.Contains(u.F_Id) || u.F_IsPublic == true) && u.F_ModuleId == module.F_Id).Select(u => u.F_EnCode).ToList(); //反射获取主键 PropertyInfo pkProp = typeof(TEntity).GetProperties().Where(p => p.GetCustomAttributes(typeof(ColumnAttribute), false).Length > 0).FirstOrDefault(); var idName = "F_Id"; @@ -260,15 +252,15 @@ namespace WaterCloud.Service return query; } //系统菜单跳过 - var module = uniwork.IQueryable(u => u.F_EnCode == moduleName).FirstOrDefault(); + var module = unitwork.IQueryable(u => u.F_EnCode == moduleName).FirstOrDefault(); //判断是否需要字段权限 - if (module.F_IsFields == false) + if (module == null || module.F_IsFields == false) { return query; } var rolelist = currentuser.RoleId.Split(','); - var rule = uniwork.IQueryable(u => rolelist.Contains(u.F_ObjectId) && u.F_ItemType == 3).Select(a => a.F_ItemId).Distinct().ToList(); - var fieldsList = uniwork.IQueryable(u => (rule.Contains(u.F_Id) || u.F_IsPublic == true) && u.F_ModuleId == module.F_Id).Select(u => u.F_EnCode).ToList(); + var rule = unitwork.IQueryable(u => rolelist.Contains(u.F_ObjectId) && u.F_ItemType == 3).Select(a => a.F_ItemId).Distinct().ToList(); + var fieldsList = unitwork.IQueryable(u => (rule.Contains(u.F_Id) || u.F_IsPublic == true) && u.F_ModuleId == module.F_Id).Select(u => u.F_EnCode).ToList(); //反射获取主键 PropertyInfo pkProp = typeof(TEntity).GetProperties().Where(p => p.GetCustomAttributes(typeof(ColumnAttribute), false).Length > 0).FirstOrDefault(); var idName = "F_Id"; diff --git a/WaterCloud.Service/SystemManage/AreaService.cs b/WaterCloud.Service/SystemManage/AreaService.cs index d400912254712ac6b8abb1bda607b369afe39825..abc91be3410d57cd3862d695c432473fd664dbff 100644 --- a/WaterCloud.Service/SystemManage/AreaService.cs +++ b/WaterCloud.Service/SystemManage/AreaService.cs @@ -11,27 +11,21 @@ using System.Linq; using System.Threading.Tasks; using WaterCloud.Code; using Chloe; +using WaterCloud.DataBase; namespace WaterCloud.Service.SystemManage { public class AreaService : DataFilterService, IDenpendency { - public AreaService(IDbContext context) : base(context) + public AreaService(IUnitOfWork unitOfWork) : base(unitOfWork) { } - //获取类名 - - /// - /// 缓存操作类 - /// - private string cacheKey = "watercloud_areadata_";// 区域 public async Task> GetList(int layers = 0) { - var list = new List(); - list = await repository.CheckCacheList(cacheKey + "list"); + var list = repository.IQueryable(); if (layers != 0) { - list = list.Where(t => t.F_Layers == layers).ToList(); + list = list.Where(t => t.F_Layers == layers); } return list.Where(t => t.F_DeleteMark == false && t.F_EnabledMark == true).OrderBy(t => t.F_SortCode).ToList(); } @@ -47,13 +41,13 @@ namespace WaterCloud.Service.SystemManage } public async Task GetLookForm(string keyValue) { - var cachedata =await repository.CheckCache(cacheKey, keyValue); - return GetFieldsFilterData(cachedata); + var data =await repository.FindEntity(keyValue); + return GetFieldsFilterData(data); } public async Task GetForm(string keyValue) { - var cachedata = await repository.CheckCache(cacheKey, keyValue); - return cachedata; + var data = await repository.FindEntity(keyValue); + return data; } public async Task DeleteForm(string keyValue) { @@ -65,8 +59,6 @@ namespace WaterCloud.Service.SystemManage { await repository.Delete(t => t.F_Id == keyValue); } - await CacheHelper.Remove(cacheKey + keyValue); - await CacheHelper.Remove(cacheKey + "list"); } public async Task SubmitForm(AreaEntity mEntity, string keyValue) { @@ -74,15 +66,12 @@ namespace WaterCloud.Service.SystemManage { mEntity.Modify(keyValue); await repository.Update(mEntity); - await CacheHelper.Remove(cacheKey + keyValue); - await CacheHelper.Remove(cacheKey + "list"); } else { mEntity.F_DeleteMark = false; mEntity.Create(); await repository.Insert(mEntity); - await CacheHelper.Remove(cacheKey + "list"); } } } diff --git a/WaterCloud.Service/SystemManage/FlowschemeService.cs b/WaterCloud.Service/SystemManage/FlowschemeService.cs index e835373a80b3c93d9d1642c8028e53d248187843..395a765474201e6f6db822eb045aae16cd583d19 100644 --- a/WaterCloud.Service/SystemManage/FlowschemeService.cs +++ b/WaterCloud.Service/SystemManage/FlowschemeService.cs @@ -8,6 +8,7 @@ using WaterCloud.Domain.SystemManage; using WaterCloud.Service.CommonService; using WaterCloud.Domain.SystemOrganize; using WaterCloud.Domain.FlowManage; +using WaterCloud.DataBase; namespace WaterCloud.Service.SystemManage { @@ -18,26 +19,24 @@ namespace WaterCloud.Service.SystemManage /// public class FlowschemeService : DataFilterService, IDenpendency { - private string cacheKey = "watercloud_flowschemedata_"; - - public FlowschemeService(IDbContext context) : base(context) + public FlowschemeService(IUnitOfWork unitOfWork) : base(unitOfWork) { } #region 获取数据 public async Task> GetList(string keyword = "") { - var cachedata = await repository.CheckCacheList(cacheKey + "list"); + var data = repository.IQueryable(); if (!string.IsNullOrEmpty(keyword)) { - cachedata = cachedata.Where(t => t.F_SchemeCode.Contains(keyword) || t.F_SchemeName.Contains(keyword)).ToList(); + data = data.Where(t => t.F_SchemeCode.Contains(keyword) || t.F_SchemeName.Contains(keyword)); } var list = currentuser.DepartmentId.Split(','); if (list.Count() > 0) { - return cachedata.Where(t => t.F_DeleteMark == false && (t.F_OrganizeId == "" || t.F_OrganizeId == null || list.Contains(t.F_OrganizeId))).OrderByDescending(t => t.F_CreatorTime).ToList(); + return data.Where(t => t.F_DeleteMark == false && (t.F_OrganizeId == "" || t.F_OrganizeId == null || list.Contains(t.F_OrganizeId))).OrderByDesc(t => t.F_CreatorTime).ToList(); } - return cachedata.Where(t => t.F_DeleteMark == false && t.F_OrganizeId == "" || t.F_OrganizeId == null).OrderByDescending(t => t.F_CreatorTime).ToList(); + return data.Where(t => t.F_DeleteMark == false && t.F_OrganizeId == "" || t.F_OrganizeId == null).OrderByDesc(t => t.F_CreatorTime).ToList(); } public async Task> GetLookList(string ItemId = "", string keyword = "") @@ -69,21 +68,21 @@ namespace WaterCloud.Service.SystemManage public async Task GetForm(string keyValue) { - var cachedata = await repository.CheckCache(cacheKey, keyValue); - return cachedata; + var data = await repository.FindEntity(keyValue); + return data; } #endregion public async Task GetLookForm(string keyValue) { - var cachedata = await repository.CheckCache(cacheKey, keyValue); - return GetFieldsFilterData(cachedata); + var data = await repository.FindEntity(keyValue); + return GetFieldsFilterData(data); } public async Task GetFormExtend(string keyValue) { - var cachedata = await repository.CheckCache(cacheKey, keyValue); - var temp = cachedata.MapTo(); - var form = await uniwork.FindEntity(cachedata.F_FrmId); + var data = await repository.FindEntity(keyValue); + var temp = data.MapTo(); + var form = await unitwork.FindEntity(data.F_FrmId); temp.F_WebId = form.F_WebId; temp.F_FrmContentData = form.F_ContentData; temp.F_FrmContent = form.F_Content; @@ -97,7 +96,7 @@ namespace WaterCloud.Service.SystemManage if (temp.NextNodeDesignateType == Setinfo.SPECIAL_USER) { temp.NextNodeDesignates = runtime.nextNode.setInfo.NodeDesignateData.users; - temp.NextMakerName = string.Join(',', uniwork.IQueryable(a => temp.NextNodeDesignates.Contains(a.F_Id)).Select(a => a.F_RealName).ToList()); + temp.NextMakerName = string.Join(',', unitwork.IQueryable(a => temp.NextNodeDesignates.Contains(a.F_Id)).Select(a => a.F_RealName).ToList()); } else if (temp.NextNodeDesignateType == Setinfo.SPECIAL_ROLE) { @@ -106,11 +105,11 @@ namespace WaterCloud.Service.SystemManage List users = new List(); foreach (var item in temp.NextNodeDesignates) { - var usertemp = uniwork.IQueryable(a => a.F_RoleId.Contains(item)).ToList(); + var usertemp = unitwork.IQueryable(a => a.F_RoleId.Contains(item)).ToList(); var tempList = new List(); if (runtime.nextNode.setInfo.NodeDesignateData.currentDepart) { - var currentDepartment = uniwork.FindEntity(currentuser.UserId).GetAwaiter().GetResult().F_DepartmentId.Split(',').ToList(); + var currentDepartment = unitwork.FindEntity(currentuser.UserId).GetAwaiter().GetResult().F_DepartmentId.Split(',').ToList(); foreach (var user in usertemp) { var nextCurrentDepartment = user.F_DepartmentId.Split(',').ToList(); @@ -128,7 +127,7 @@ namespace WaterCloud.Service.SystemManage users.AddRange(tempFinal); } users = users.Distinct().ToList(); - temp.NextMakerName = string.Join(',', uniwork.IQueryable(a => users.Contains(a.F_Id)).Select(a => a.F_RealName).ToList()); + temp.NextMakerName = string.Join(',', unitwork.IQueryable(a => users.Contains(a.F_Id)).Select(a => a.F_RealName).ToList()); } } return temp; @@ -141,15 +140,12 @@ namespace WaterCloud.Service.SystemManage //此处需修改 entity.Create(); await repository.Insert(entity); - await CacheHelper.Remove(cacheKey + "list"); } else { //此处需修改 entity.Modify(keyValue); await repository.Update(entity); - await CacheHelper.Remove(cacheKey + keyValue); - await CacheHelper.Remove(cacheKey + "list"); } } @@ -157,11 +153,6 @@ namespace WaterCloud.Service.SystemManage { var ids = keyValue.Split(','); await repository.Delete(t => ids.Contains(t.F_Id)); - foreach (var item in ids) - { - await CacheHelper.Remove(cacheKey + item); - } - await CacheHelper.Remove(cacheKey + "list"); } #endregion diff --git a/WaterCloud.Service/SystemManage/FormService.cs b/WaterCloud.Service/SystemManage/FormService.cs index 1343751f06b6e6a6aabd7f1e3a7c9040660245c9..69c3aff5235d0359f69a5e3e1c96b20c4324ede2 100644 --- a/WaterCloud.Service/SystemManage/FormService.cs +++ b/WaterCloud.Service/SystemManage/FormService.cs @@ -7,6 +7,7 @@ using Chloe; using WaterCloud.Domain.SystemManage; using Serenity.Data; using WaterCloud.Domain.SystemOrganize; +using WaterCloud.DataBase; namespace WaterCloud.Service.SystemManage { @@ -17,21 +18,19 @@ namespace WaterCloud.Service.SystemManage /// public class FormService : DataFilterService, IDenpendency { - private string cacheKey = "watercloud_formdata_"; - - public FormService(IDbContext context) : base(context) + public FormService(DataBase.IUnitOfWork unitOfWork) : base(unitOfWork) { } #region 获取数据 public async Task> GetList(string keyword = "") { - var cachedata = await repository.CheckCacheList(cacheKey + "list"); + var data = repository.IQueryable(); if (!string.IsNullOrEmpty(keyword)) { //此处需修改 - cachedata = cachedata.Where(t => t.F_Name.Contains(keyword) || t.F_Description.Contains(keyword)).ToList(); + data = data.Where(t => t.F_Name.Contains(keyword) || t.F_Description.Contains(keyword)); } - return cachedata.Where(t => t.F_DeleteMark == false).OrderByDescending(t => t.F_CreatorTime).ToList(); + return data.Where(t => t.F_DeleteMark == false).OrderByDesc(t => t.F_CreatorTime).ToList(); } public async Task> GetLookList(string ItemId="", string keyword = "") @@ -89,15 +88,15 @@ namespace WaterCloud.Service.SystemManage } public async Task GetForm(string keyValue) { - var cachedata = await repository.CheckCache(cacheKey, keyValue); - return cachedata; + var data = await repository.FindEntity(keyValue); + return data; } #endregion public async Task GetLookForm(string keyValue) { - var cachedata = await repository.CheckCache(cacheKey, keyValue); - return GetFieldsFilterData(cachedata); + var data = await repository.FindEntity(keyValue); + return GetFieldsFilterData(data); } #region 提交数据 @@ -121,15 +120,12 @@ namespace WaterCloud.Service.SystemManage entity.F_DeleteMark = false; entity.Create(); await repository.Insert(entity); - await CacheHelper.Remove(cacheKey + "list"); } else { //此处需修改 entity.Modify(keyValue); await repository.Update(entity); - await CacheHelper.Remove(cacheKey + keyValue); - await CacheHelper.Remove(cacheKey + "list"); } } @@ -137,11 +133,6 @@ namespace WaterCloud.Service.SystemManage { var ids = keyValue.Split(','); await repository.Delete(t => ids.Contains(t.F_Id)); - foreach (var item in ids) - { - await CacheHelper.Remove(cacheKey + item); - } - await CacheHelper.Remove(cacheKey + "list"); } #endregion diff --git a/WaterCloud.Service/SystemManage/ItemsDataService.cs b/WaterCloud.Service/SystemManage/ItemsDataService.cs index 7fe9f45063c9fc2627e2bf33a4314f96981c1932..b26a027023ef46029a99c7db09b1d7638a8aeeee 100644 --- a/WaterCloud.Service/SystemManage/ItemsDataService.cs +++ b/WaterCloud.Service/SystemManage/ItemsDataService.cs @@ -10,6 +10,7 @@ using System.Linq; using System.Threading.Tasks; using WaterCloud.Code; using Chloe; +using WaterCloud.DataBase; namespace WaterCloud.Service.SystemManage { @@ -18,24 +19,21 @@ namespace WaterCloud.Service.SystemManage /// /// 缓存操作类 /// - public ItemsDataService(IDbContext context) : base(context) + public ItemsDataService(IUnitOfWork unitOfWork) : base(unitOfWork) { } - private string cacheKey = "watercloud_itemdetaildata_"; - private string itemcacheKey = "watercloud_itemsdata_"; //获取类名 public async Task> GetList(string itemId = "", string keyword = "") { - var list = new List(); - list = await repository.CheckCacheList(cacheKey + "list"); + var list = repository.IQueryable(); if (!string.IsNullOrEmpty(itemId)) { - list = list.Where(t => t.F_ItemId == itemId).ToList(); + list = list.Where(t => t.F_ItemId == itemId); } if (!string.IsNullOrEmpty(keyword)) { - list = list.Where(t => t.F_ItemName.Contains(keyword) || t.F_ItemCode.Contains(keyword)).ToList(); + list = list.Where(t => t.F_ItemName.Contains(keyword) || t.F_ItemCode.Contains(keyword)); } return list.Where(a => a.F_DeleteMark == false).OrderBy(t => t.F_SortCode).ToList(); } @@ -55,27 +53,24 @@ namespace WaterCloud.Service.SystemManage } public async Task> GetItemList(string enCode) { - var itemcachedata =await uniwork.CheckCacheList(itemcacheKey + "list"); - var item = itemcachedata.Find(a => a.F_EnCode == enCode); - var cachedata =await repository.CheckCacheList(cacheKey + "list"); - cachedata = cachedata.Where(a => a.F_DeleteMark == false && a.F_EnabledMark == true && a.F_ItemId == item.F_Id).OrderBy(a => a.F_SortCode).ToList(); - return cachedata; + var itemdata = unitwork.IQueryable().ToList(); + var item = itemdata.Find(a => a.F_EnCode == enCode); + var data = repository.IQueryable(); + return data.Where(a => a.F_DeleteMark == false && a.F_EnabledMark == true && a.F_ItemId == item.F_Id).OrderBy(a => a.F_SortCode).ToList(); } public async Task GetLookForm(string keyValue) { - var cachedata =await repository.CheckCache(cacheKey, keyValue); - return GetFieldsFilterData(cachedata); + var data =await repository.FindEntity(keyValue); + return GetFieldsFilterData(data); } public async Task GetForm(string keyValue) { - var cachedata = await repository.CheckCache(cacheKey, keyValue); - return cachedata; + var data = await repository.FindEntity(keyValue); + return data; } public async Task DeleteForm(string keyValue) { await repository.Delete(t => t.F_Id == keyValue); - await CacheHelper.Remove(cacheKey + keyValue); - await CacheHelper.Remove(cacheKey + "list"); } public async Task SubmitForm(ItemsDetailEntity itemsDetailEntity, string keyValue) { @@ -83,15 +78,12 @@ namespace WaterCloud.Service.SystemManage { itemsDetailEntity.Modify(keyValue); await repository.Update(itemsDetailEntity); - await CacheHelper.Remove(cacheKey + keyValue); - await CacheHelper.Remove(cacheKey + "list"); } else { itemsDetailEntity.F_DeleteMark = false; itemsDetailEntity.Create(); await repository.Insert(itemsDetailEntity); - await CacheHelper.Remove(cacheKey + "list"); } } } diff --git a/WaterCloud.Service/SystemManage/ItemsTypeService.cs b/WaterCloud.Service/SystemManage/ItemsTypeService.cs index 7de3328e172ca14035cda560ac8a6340c81d1003..3c552e545c9a2c48244ea2a81597b8fb07367a51 100644 --- a/WaterCloud.Service/SystemManage/ItemsTypeService.cs +++ b/WaterCloud.Service/SystemManage/ItemsTypeService.cs @@ -11,24 +11,19 @@ using System.Collections.Generic; using System.Threading.Tasks; using WaterCloud.Code; using Chloe; +using WaterCloud.DataBase; namespace WaterCloud.Service.SystemManage { public class ItemsTypeService : DataFilterService,IDenpendency - { - /// - /// 缓存操作类 - /// - private string cacheKey = "watercloud_itemsdata_";// 字典分类 - //获取类名 - - public ItemsTypeService(IDbContext context) : base(context) + { + public ItemsTypeService(IUnitOfWork unitOfWork) : base(unitOfWork) { } public async Task> GetList() { - var cachedata =await repository.CheckCacheList(cacheKey + "list"); - return cachedata.Where(a=>a.F_DeleteMark==false).OrderBy(t => t.F_SortCode).ToList(); + var data = repository.IQueryable(); + return data.Where(a=>a.F_DeleteMark==false).OrderBy(t => t.F_SortCode).ToList(); } public async Task> GetLookList() { @@ -38,14 +33,14 @@ namespace WaterCloud.Service.SystemManage } public async Task GetLookForm(string keyValue) { - var cachedata =await repository.CheckCache(cacheKey, keyValue); - return GetFieldsFilterData(cachedata); + var data =await repository.FindEntity(keyValue); + return GetFieldsFilterData(data); } public async Task GetForm(string keyValue) { - var cachedata = await repository.CheckCache(cacheKey, keyValue); - return cachedata; + var data = await repository.FindEntity(keyValue); + return data; } public async Task DeleteForm(string keyValue) @@ -57,8 +52,6 @@ namespace WaterCloud.Service.SystemManage else { await repository.Delete(t => t.F_Id == keyValue); - await CacheHelper.Remove(cacheKey + keyValue); - await CacheHelper.Remove(cacheKey + "list"); } } public async Task SubmitForm(ItemsEntity itemsEntity, string keyValue) @@ -67,8 +60,6 @@ namespace WaterCloud.Service.SystemManage { itemsEntity.Modify(keyValue); await repository.Update(itemsEntity); - await CacheHelper.Remove(cacheKey + keyValue); - await CacheHelper.Remove(cacheKey + "list"); } else { @@ -76,7 +67,6 @@ namespace WaterCloud.Service.SystemManage itemsEntity.F_IsTree = false; itemsEntity.Create(); await repository.Insert(itemsEntity); - await CacheHelper.Remove(cacheKey + "list"); } } } diff --git a/WaterCloud.Service/SystemManage/ModuleButtonService.cs b/WaterCloud.Service/SystemManage/ModuleButtonService.cs index 942e09dfac6efec3cc12b805c393c2f73dfc2922..202dc4dc69ce048943041bd72fc68cd2faaa1d8c 100644 --- a/WaterCloud.Service/SystemManage/ModuleButtonService.cs +++ b/WaterCloud.Service/SystemManage/ModuleButtonService.cs @@ -12,30 +12,22 @@ using System.Linq; using System.Threading.Tasks; using Chloe; using WaterCloud.Domain.SystemOrganize; +using WaterCloud.DataBase; namespace WaterCloud.Service.SystemManage { public class ModuleButtonService : DataFilterService, IDenpendency { - //获取类名 - - /// - /// 缓存操作类 - /// - - private string cacheKey = "watercloud_modulebuttondata_"; - private string initcacheKey = "watercloud_init_"; - private string authorizecacheKey = "watercloud_authorizeurldata_";// +权限 - public ModuleButtonService(IDbContext context) : base(context) + private string authorizecacheKey = GlobalContext.SystemConfig.ProjectPrefix + "_authorizeurldata_";// +权限 + public ModuleButtonService(IUnitOfWork unitOfWork) : base(unitOfWork) { } public async Task> GetList(string moduleId = "") { - var list = new List(); - list = await repository.CheckCacheList(cacheKey + "list"); + var list = repository.IQueryable(); if (!string.IsNullOrEmpty(moduleId)) { - list = list.Where(t => t.F_ModuleId == moduleId).ToList(); + list = list.Where(t => t.F_ModuleId == moduleId); } return list.Where(a => a.F_DeleteMark == false).OrderBy(t => t.F_SortCode).ToList(); } @@ -56,13 +48,13 @@ namespace WaterCloud.Service.SystemManage } public async Task GetLookForm(string keyValue) { - var cachedata =await repository.CheckCache(cacheKey, keyValue); - return GetFieldsFilterData(cachedata); + var data =await repository.FindEntity(keyValue); + return GetFieldsFilterData(data); } public async Task GetForm(string keyValue) { - var cachedata = await repository.CheckCache(cacheKey, keyValue); - return cachedata; + var data = await repository.FindEntity(keyValue); + return data; } public async Task DeleteForm(string keyValue) { @@ -73,17 +65,13 @@ namespace WaterCloud.Service.SystemManage else { await repository.Delete(t => t.F_Id == keyValue); - await CacheHelper.Remove(cacheKey + keyValue); - await CacheHelper.Remove(cacheKey + "list"); } - await CacheHelper.Remove(initcacheKey + "modulebutton_" + "list"); await CacheHelper.Remove(authorizecacheKey + "list"); - await CacheHelper.Remove(authorizecacheKey + "authorize_list"); } public async Task> GetListByRole(string roleid) { - var moduleList = uniwork.IQueryable(a => a.F_ObjectId == roleid && a.F_ItemType == 2).Select(a => a.F_ItemId).ToList(); + var moduleList = unitwork.IQueryable(a => a.F_ObjectId == roleid && a.F_ItemType == 2).Select(a => a.F_ItemId).ToList(); var query = repository.IQueryable().Where(a => (moduleList.Contains(a.F_Id) || a.F_IsPublic == true) && a.F_DeleteMark == false && a.F_EnabledMark == true); return query.OrderBy(a => a.F_SortCode).ToList(); } @@ -98,33 +86,28 @@ namespace WaterCloud.Service.SystemManage { moduleButtonEntity.Modify(keyValue); await repository.Update(moduleButtonEntity); - await CacheHelper.Remove(cacheKey + keyValue); - await CacheHelper.Remove(cacheKey + "list"); } else { moduleButtonEntity.F_DeleteMark = false; moduleButtonEntity.F_AllowEdit = false; moduleButtonEntity.F_AllowDelete = false; - var module = await uniwork.FindEntity(a => a.F_Id == moduleButtonEntity.F_ModuleId); + var module = await unitwork.FindEntity(a => a.F_Id == moduleButtonEntity.F_ModuleId); if (module.F_Target != "iframe" && module.F_Target != "expand") { throw new Exception("菜单不能创建按钮"); } moduleButtonEntity.Create(); await repository.Insert(moduleButtonEntity); - await CacheHelper.Remove(cacheKey + "list"); } - await CacheHelper.Remove(initcacheKey + "modulebutton_" + "list"); await CacheHelper.Remove(authorizecacheKey + "list"); - await CacheHelper.Remove(authorizecacheKey + "authorize_list"); } public async Task SubmitCloneButton(string moduleId, string Ids) { string[] ArrayId = Ids.Split(','); var data =await this.GetList(); List entitys = new List(); - var module = await uniwork.FindEntity(a => a.F_Id == moduleId); + var module = await unitwork.FindEntity(a => a.F_Id == moduleId); if (module.F_Target != "iframe" && module.F_Target != "expand") { throw new Exception("菜单不能创建按钮"); @@ -137,10 +120,7 @@ namespace WaterCloud.Service.SystemManage entitys.Add(moduleButtonEntity); } await repository.Insert(entitys); - await CacheHelper.Remove(cacheKey + "list"); - await CacheHelper.Remove(initcacheKey + "modulebutton_" + "list"); await CacheHelper.Remove(authorizecacheKey + "list"); - await CacheHelper.Remove(authorizecacheKey + "authorize_list"); } public async Task> GetListNew(string moduleId = "") diff --git a/WaterCloud.Service/SystemManage/ModuleFieldsService.cs b/WaterCloud.Service/SystemManage/ModuleFieldsService.cs index 6d7f8267fd12a914c28ea23a3bc54095c5658349..2cf39fed22d99f0999770ed5b49e193a2a3eb019 100644 --- a/WaterCloud.Service/SystemManage/ModuleFieldsService.cs +++ b/WaterCloud.Service/SystemManage/ModuleFieldsService.cs @@ -6,6 +6,7 @@ using WaterCloud.Code; using WaterCloud.Domain.SystemManage; using Chloe; using WaterCloud.Domain.SystemOrganize; +using WaterCloud.DataBase; namespace WaterCloud.Service.SystemManage { @@ -16,24 +17,21 @@ namespace WaterCloud.Service.SystemManage /// public class ModuleFieldsService : DataFilterService, IDenpendency { - private string cacheKey = "watercloud_ modulefieldsdata_"; - private string initcacheKey = "watercloud_init_"; - private string authorizecacheKey = "watercloud_authorizeurldata_";// +权限 //获取类名 - public ModuleFieldsService(IDbContext context) : base(context) + public ModuleFieldsService(IUnitOfWork unitOfWork) : base(unitOfWork) { } #region 获取数据 public async Task> GetList(string keyword = "") { - var cachedata = await repository.CheckCacheList(cacheKey + "list"); + var data = repository.IQueryable(); if (!string.IsNullOrEmpty(keyword)) { //此处需修改 - cachedata = cachedata.Where(t => t.F_FullName.Contains(keyword) || t.F_EnCode.Contains(keyword)).ToList(); + data = data.Where(t => t.F_FullName.Contains(keyword) || t.F_EnCode.Contains(keyword)); } - return cachedata.Where(a => a.F_DeleteMark == false).OrderByDescending(t => t.F_CreatorTime).ToList(); + return data.Where(a => a.F_DeleteMark == false).OrderByDesc(t => t.F_CreatorTime).ToList(); } public async Task> GetLookList(Pagination pagination, string moduleId, string keyword = "") @@ -51,13 +49,13 @@ namespace WaterCloud.Service.SystemManage public async Task GetLookForm(string keyValue) { - var cachedata = await repository.CheckCache(cacheKey, keyValue); - return GetFieldsFilterData(cachedata); + var data = await repository.FindEntity(keyValue); + return GetFieldsFilterData(data); } public async Task GetForm(string keyValue) { - var cachedata = await repository.CheckCache(cacheKey, keyValue); - return cachedata; + var data = await repository.FindEntity(keyValue); + return data; } #endregion @@ -69,25 +67,17 @@ namespace WaterCloud.Service.SystemManage entity.F_DeleteMark = false; entity.Create(); await repository.Insert(entity); - await CacheHelper.Remove(cacheKey + "list"); } else { entity.Modify(keyValue); await repository.Update(entity); - await CacheHelper.Remove(cacheKey + keyValue); - await CacheHelper.Remove(cacheKey + "list"); } - await CacheHelper.Remove(initcacheKey + "modulefields_" + "list"); } public async Task DeleteForm(string keyValue) { await repository.Delete(t => t.F_Id == keyValue); - await CacheHelper.Remove(cacheKey + keyValue); - await CacheHelper.Remove(cacheKey + "list"); - await CacheHelper.Remove(initcacheKey + "modulefields_" + "list"); - await CacheHelper.Remove(authorizecacheKey + "list"); } public async Task SubmitCloneFields(string moduleId, string ids) @@ -95,7 +85,7 @@ namespace WaterCloud.Service.SystemManage string[] ArrayId = ids.Split(','); var data = await this.GetList(); List entitys = new List(); - var module = await uniwork.FindEntity(a => a.F_Id == moduleId); + var module = await unitwork.FindEntity(a => a.F_Id == moduleId); if (string.IsNullOrEmpty(module.F_UrlAddress) || module.F_Target != "iframe") { throw new Exception("框架页才能创建按钮"); @@ -108,14 +98,11 @@ namespace WaterCloud.Service.SystemManage entitys.Add(moduleFieldsEntity); } await repository.Insert(entitys); - await CacheHelper.Remove(cacheKey + "list"); - await CacheHelper.Remove(initcacheKey + "modulefields_" + "list"); - await CacheHelper.Remove(authorizecacheKey + "list"); } public async Task> GetListByRole(string roleid) { - var moduleList = uniwork.IQueryable(a => a.F_ObjectId == roleid && a.F_ItemType == 3).Select(a => a.F_ItemId).ToList(); + var moduleList = unitwork.IQueryable(a => a.F_ObjectId == roleid && a.F_ItemType == 3).Select(a => a.F_ItemId).ToList(); var query = repository.IQueryable().Where(a => (moduleList.Contains(a.F_Id) || a.F_IsPublic == true) && a.F_DeleteMark == false && a.F_EnabledMark == true); return query.OrderByDesc(a => a.F_CreatorTime).ToList(); } diff --git a/WaterCloud.Service/SystemManage/ModuleService.cs b/WaterCloud.Service/SystemManage/ModuleService.cs index ebc2eae045d13307f514def2d4fb5b0cdcd65795..8873b596559f9e4285a7172e29b832ce6eeeea19 100644 --- a/WaterCloud.Service/SystemManage/ModuleService.cs +++ b/WaterCloud.Service/SystemManage/ModuleService.cs @@ -12,6 +12,7 @@ using System.Linq; using WaterCloud.Code; using Chloe; using WaterCloud.Domain.SystemOrganize; +using WaterCloud.DataBase; namespace WaterCloud.Service.SystemManage { @@ -20,27 +21,21 @@ namespace WaterCloud.Service.SystemManage /// /// 缓存操作类 /// - - private string cacheKey = "watercloud_moduleldata_"; - private string quickcacheKey = "watercloud_quickmoduledata_"; - private string initcacheKey = "watercloud_init_"; - private string modulebuttoncacheKey = "watercloud_modulebuttondata_"; - private string modulefieldscacheKey = "watercloud_modulefieldsdata_"; - private string authorizecacheKey = "watercloud_authorizeurldata_";// +权限 + private string authorizecacheKey = GlobalContext.SystemConfig.ProjectPrefix + "_authorizeurldata_";// +权限 //获取类名 - public ModuleService(IDbContext context) : base(context) + public ModuleService(IUnitOfWork unitOfWork) : base(unitOfWork) { } public async Task> GetList() { - var cachedata = await repository.CheckCacheList(cacheKey + "list"); - return cachedata.Where(a => a.F_DeleteMark == false).OrderBy(t => t.F_SortCode).ToList(); + var data = repository.IQueryable(); + return data.Where(a => a.F_DeleteMark == false).OrderBy(t => t.F_SortCode).ToList(); } public async Task> GetBesidesList() { - var moduleList = uniwork.IQueryable().Select(a => a.F_ModuleId).ToList(); + var moduleList = unitwork.IQueryable().Select(a => a.F_ModuleId).ToList(); var query = repository.IQueryable().Where(a => !moduleList.Contains(a.F_Id) && a.F_EnabledMark == true && a.F_Target == "iframe"); return query.OrderBy(a => a.F_SortCode).ToList(); } @@ -52,13 +47,13 @@ namespace WaterCloud.Service.SystemManage } public async Task GetLookForm(string keyValue) { - var cachedata = await repository.CheckCache(cacheKey, keyValue); - return GetFieldsFilterData(cachedata); + var data = await repository.FindEntity(keyValue); + return GetFieldsFilterData(data); } public async Task GetForm(string keyValue) { - var cachedata = await repository.CheckCache(cacheKey, keyValue); - return cachedata; + var data = await repository.FindEntity(keyValue); + return data; } public async Task DeleteForm(string keyValue) { @@ -68,27 +63,18 @@ namespace WaterCloud.Service.SystemManage } else { - uniwork.BeginTrans(); + unitwork.BeginTrans(); await repository.Delete(a => a.F_Id == keyValue); - await uniwork.Delete(a => a.F_ModuleId == keyValue); - await uniwork.Delete(a => a.F_ModuleId == keyValue); - uniwork.Commit(); - await CacheHelper.Remove(cacheKey + keyValue); - await CacheHelper.Remove(cacheKey + "list"); - await CacheHelper.Remove(quickcacheKey + "list"); - await CacheHelper.Remove(initcacheKey + "list"); - await CacheHelper.Remove(initcacheKey + "modulebutton_list"); - await CacheHelper.Remove(initcacheKey + "modulefields_list"); + await unitwork.Delete(a => a.F_ModuleId == keyValue); + await unitwork.Delete(a => a.F_ModuleId == keyValue); + unitwork.Commit(); await CacheHelper.Remove(authorizecacheKey + "list"); - await CacheHelper.Remove(authorizecacheKey + "authorize_list"); - await CacheHelper.Remove(modulebuttoncacheKey + "list"); - await CacheHelper.Remove(modulefieldscacheKey + "list"); } } public async Task> GetListByRole(string roleid) { - var moduleList = uniwork.IQueryable(a => a.F_ObjectId == roleid && a.F_ItemType == 1).Select(a => a.F_ItemId).ToList(); + var moduleList = unitwork.IQueryable(a => a.F_ObjectId == roleid && a.F_ItemType == 1).Select(a => a.F_ItemId).ToList(); var query = repository.IQueryable().Where(a => (moduleList.Contains(a.F_Id) || a.F_IsPublic == true) && a.F_DeleteMark == false && a.F_EnabledMark == true); return query.OrderBy(a => a.F_SortCode).ToList(); } @@ -103,23 +89,13 @@ namespace WaterCloud.Service.SystemManage { moduleEntity.Modify(keyValue); await repository.Update(moduleEntity); - await CacheHelper.Remove(cacheKey + keyValue); - await CacheHelper.Remove(cacheKey + "list"); } else { moduleEntity.Create(); await repository.Insert(moduleEntity); - await CacheHelper.Remove(cacheKey + "list"); } - await CacheHelper.Remove(quickcacheKey + "list"); - await CacheHelper.Remove(initcacheKey + "list"); - await CacheHelper.Remove(initcacheKey + "modulebutton_list"); - await CacheHelper.Remove(initcacheKey + "modulefields_list"); await CacheHelper.Remove(authorizecacheKey + "list"); - await CacheHelper.Remove(authorizecacheKey + "authorize_list"); - await CacheHelper.Remove(modulebuttoncacheKey + "list"); - await CacheHelper.Remove(modulefieldscacheKey + "list"); } } } diff --git a/WaterCloud.Service/SystemManage/QuickModuleService.cs b/WaterCloud.Service/SystemManage/QuickModuleService.cs index 7507a1e97b0359177403e05871adbfcac70c4e9c..a79953b8c9668c8000029a1aa67743b12627d9c7 100644 --- a/WaterCloud.Service/SystemManage/QuickModuleService.cs +++ b/WaterCloud.Service/SystemManage/QuickModuleService.cs @@ -14,37 +14,33 @@ using System.Threading.Tasks; using System.Linq; using Chloe; using WaterCloud.Domain.SystemOrganize; +using WaterCloud.DataBase; namespace WaterCloud.Service.SystemManage { public class QuickModuleService:DataFilterService ,IDenpendency { - /// - /// - /// - - private string cacheKey = "watercloud_quickmoduledata_"; - public QuickModuleService(IDbContext context) : base(context) + public QuickModuleService(IUnitOfWork unitOfWork) : base(unitOfWork) { } public async Task GetTransferList(string userId) { var quicklist = repository.IQueryable(t => t.F_CreatorUserId == userId && t.F_EnabledMark == true).ToList(); List quicks = new List(); - var user = await uniwork.FindEntity(userId); + var user = await unitwork.FindEntity(userId); var roleId = user.F_RoleId; if (user.F_Account == GlobalContext.SystemConfig.SysemUserCode || user.F_IsAdmin == true) { roleId = "admin"; } var rolelist = roleId.Split(','); - var modulelist = uniwork.IQueryable(a => roleId.Contains(a.F_ObjectId) && a.F_ItemType == 1).InnerJoin((a,b)=> a.F_ItemId == b.F_Id && b.F_IsMenu == true).Select((a, b) => a.F_ItemId).ToList(); + var modulelist = unitwork.IQueryable(a => roleId.Contains(a.F_ObjectId) && a.F_ItemType == 1).InnerJoin((a,b)=> a.F_ItemId == b.F_Id && b.F_IsMenu == true).Select((a, b) => a.F_ItemId).ToList(); if (roleId == "admin") { - modulelist = uniwork.IQueryable(a => a.F_EnabledMark == true && a.F_IsMenu == true && a.F_DeleteMark == false).Select(a => a.F_Id).ToList(); + modulelist = unitwork.IQueryable(a => a.F_EnabledMark == true && a.F_IsMenu == true && a.F_DeleteMark == false).Select(a => a.F_Id).ToList(); } modulelist = modulelist.Distinct().ToList(); - quicks = uniwork.IQueryable(a => (modulelist.Contains(a.F_Id) || a.F_IsPublic == true) && a.F_IsMenu == true && a.F_EnabledMark == true && a.F_UrlAddress != null) + quicks = unitwork.IQueryable(a => (modulelist.Contains(a.F_Id) || a.F_IsPublic == true) && a.F_IsMenu == true && a.F_EnabledMark == true && a.F_UrlAddress != null) .Select(a => new ModuleEntity { F_Id = a.F_Id, @@ -67,27 +63,27 @@ namespace WaterCloud.Service.SystemManage var quicklist = repository.IQueryable(t => t.F_CreatorUserId == userId && t.F_EnabledMark == true); List list = new List(); List quicks = new List(); - uniwork.BeginTrans(); + unitwork.BeginTrans(); if (quicklist.Count() == 0) { - var user = await uniwork.FindEntity(userId); + var user = await unitwork.FindEntity(userId); var roleId = user.F_RoleId; if (user.F_Account == GlobalContext.SystemConfig.SysemUserCode || user.F_IsAdmin == true) { roleId = "admin"; } var rolelist = roleId.Split(','); - var modulelist = uniwork.IQueryable(a => roleId.Contains(a.F_ObjectId) && a.F_ItemType == 1).InnerJoin((a, b) => a.F_ItemId == b.F_Id && b.F_IsMenu == true).Select((a, b) => a.F_ItemId).ToList(); + var modulelist = unitwork.IQueryable(a => roleId.Contains(a.F_ObjectId) && a.F_ItemType == 1).InnerJoin((a, b) => a.F_ItemId == b.F_Id && b.F_IsMenu == true).Select((a, b) => a.F_ItemId).ToList(); if (roleId == "admin") { - modulelist = uniwork.IQueryable(a => a.F_EnabledMark == true && a.F_IsMenu == true && a.F_DeleteMark == false).Select(a => a.F_Id).ToList(); + modulelist = unitwork.IQueryable(a => a.F_EnabledMark == true && a.F_IsMenu == true && a.F_DeleteMark == false).Select(a => a.F_Id).ToList(); } - var temp = uniwork.IQueryable(a => a.F_IsPublic == true && a.F_IsMenu == true && a.F_EnabledMark == true && a.F_DeleteMark == false).Select(a => a.F_Id).ToList(); + var temp = unitwork.IQueryable(a => a.F_IsPublic == true && a.F_IsMenu == true && a.F_EnabledMark == true && a.F_DeleteMark == false).Select(a => a.F_Id).ToList(); modulelist.AddRange(temp); modulelist = modulelist.Distinct().ToList(); foreach (var item in modulelist) { - var module = await uniwork.FindEntity(a => a.F_Id == item && a.F_EnabledMark == true); + var module = await unitwork.FindEntity(a => a.F_Id == item && a.F_EnabledMark == true); if (module != null && module.F_UrlAddress != null && list.Count < 8) { list.Add(new QuickModuleExtend @@ -110,7 +106,7 @@ namespace WaterCloud.Service.SystemManage { foreach (var item in quicklist.ToList()) { - var module = await uniwork.FindEntity(a => a.F_Id == item.F_ModuleId && a.F_EnabledMark == true); + var module = await unitwork.FindEntity(a => a.F_Id == item.F_ModuleId && a.F_EnabledMark == true); if (module != null) { list.Add(new QuickModuleExtend @@ -129,9 +125,9 @@ namespace WaterCloud.Service.SystemManage } if (quicks.Count > 0) { - await uniwork.Insert(quicks); + await unitwork.Insert(quicks); } - uniwork.Commit(); + unitwork.Commit(); return list; } @@ -150,17 +146,10 @@ namespace WaterCloud.Service.SystemManage list.Add(entity); } } - uniwork.BeginTrans(); + unitwork.BeginTrans(); await repository.Delete(t => t.F_CreatorUserId == currentuser.UserId); await repository.Insert(list); - uniwork.Commit(); - var data =await CacheHelper.Get>>(cacheKey + "list"); - if (data != null&&data.ContainsKey(currentuser.UserId)) - { - data.Remove(currentuser.UserId); - } - await CacheHelper.Remove(cacheKey + "list"); - await CacheHelper.Set(cacheKey + "list",data); + unitwork.Commit(); } } diff --git a/WaterCloud.Service/SystemOrganize/DataPrivilegeRuleService.cs b/WaterCloud.Service/SystemOrganize/DataPrivilegeRuleService.cs index 12bb646aace96d8eb45d3d3a5844bb541746f16e..1ca3cd0c34ba6484d0ffac3b5d5a7a8c5fc8c394 100644 --- a/WaterCloud.Service/SystemOrganize/DataPrivilegeRuleService.cs +++ b/WaterCloud.Service/SystemOrganize/DataPrivilegeRuleService.cs @@ -5,6 +5,7 @@ using WaterCloud.Code; using WaterCloud.Domain.SystemOrganize; using WaterCloud.Domain.SystemManage; using Chloe; +using WaterCloud.DataBase; namespace WaterCloud.Service.SystemOrganize { @@ -15,8 +16,7 @@ namespace WaterCloud.Service.SystemOrganize /// public class DataPrivilegeRuleService : DataFilterService,IDenpendency { - private string cacheKey = "watercloud_dataprivilegeruledata_"; - public DataPrivilegeRuleService(IDbContext context) : base(context) + public DataPrivilegeRuleService(IUnitOfWork unitOfWork) : base(unitOfWork) { } //获取类名 @@ -24,13 +24,12 @@ namespace WaterCloud.Service.SystemOrganize #region 获取数据 public async Task> GetList(string keyword = "") { - var list = new List(); - list = await repository.CheckCacheList(cacheKey + "list"); + var list = repository.IQueryable(); if (!string.IsNullOrEmpty(keyword)) { - list = list.Where(t => t.F_ModuleCode.Contains(keyword) || t.F_Description.Contains(keyword)).ToList(); + list = list.Where(t => t.F_ModuleCode.Contains(keyword) || t.F_Description.Contains(keyword)); } - return list.Where(t => t.F_DeleteMark == false).OrderByDescending(t => t.F_CreatorTime).ToList(); + return list.Where(t => t.F_DeleteMark == false).OrderByDesc(t => t.F_CreatorTime).ToList(); } public async Task> GetLookList(SoulPage pagination, string keyword = "") @@ -53,41 +52,36 @@ namespace WaterCloud.Service.SystemOrganize public async Task GetLookForm(string keyValue) { - var cachedata = await repository.CheckCache(cacheKey, keyValue); - return GetFieldsFilterData(cachedata); + var data = await repository.FindEntity(keyValue); + return GetFieldsFilterData(data); } public async Task GetForm(string keyValue) { - var cachedata = await repository.CheckCache(cacheKey, keyValue); - return cachedata; + var data = await repository.FindEntity(keyValue); + return data; } #endregion #region 提交数据 public async Task SubmitForm(DataPrivilegeRuleEntity entity, string keyValue) { - entity.F_ModuleCode = (await uniwork.FindEntity(entity.F_ModuleId)).F_EnCode; + entity.F_ModuleCode = (await unitwork.FindEntity(entity.F_ModuleId)).F_EnCode; if (string.IsNullOrEmpty(keyValue)) { entity.F_DeleteMark = false; entity.Create(); await repository.Insert(entity); - await CacheHelper.Remove(cacheKey + "list"); } else { entity.Modify(keyValue); await repository.Update(entity); - await CacheHelper.Remove(cacheKey + keyValue); - await CacheHelper.Remove(cacheKey + "list"); } } public async Task DeleteForm(string keyValue) { await repository.Delete(t => t.F_Id == keyValue); - await CacheHelper.Remove(cacheKey + keyValue); - await CacheHelper.Remove(cacheKey + "list"); } #endregion diff --git a/WaterCloud.Service/SystemOrganize/DutyService.cs b/WaterCloud.Service/SystemOrganize/DutyService.cs index e884860c61b3460804970f65e0108e6749c57ced..7cfc9e3a459850b9ba04edb31f9921bb72a53834 100644 --- a/WaterCloud.Service/SystemOrganize/DutyService.cs +++ b/WaterCloud.Service/SystemOrganize/DutyService.cs @@ -12,6 +12,8 @@ using System; using System.Threading.Tasks; using Chloe; using System.IO; +using WaterCloud.DataBase; +using WaterCloud.DataBase; using WaterCloud.Service.SystemManage; namespace WaterCloud.Service.SystemOrganize @@ -19,26 +21,19 @@ namespace WaterCloud.Service.SystemOrganize public class DutyService : DataFilterService, IDenpendency { private SystemSetService setApp; - public DutyService(IDbContext context) :base(context) + public DutyService(IUnitOfWork unitOfWork) :base(unitOfWork) { - setApp = new SystemSetService(context); + setApp = new SystemSetService(unitOfWork); } - /// - /// 缓存操作类 - /// - private string cacheKey = "watercloud_roledata_";// 岗位 - //获取类名 - - public async Task> GetList(string keyword = "") { - var cachedata =await repository.CheckCacheList(cacheKey + "list"); - cachedata = cachedata.Where(t => t.F_Category == 2&&t.F_DeleteMark==false).ToList(); + var data = repository.IQueryable(); + data = data.Where(t => t.F_Category == 2&&t.F_DeleteMark==false); if (!string.IsNullOrEmpty(keyword)) { - cachedata = cachedata.Where(t => t.F_FullName.Contains(keyword) || t.F_EnCode.Contains(keyword)).ToList(); + data = data.Where(t => t.F_FullName.Contains(keyword) || t.F_EnCode.Contains(keyword)); } - return cachedata.OrderBy(t => t.F_SortCode).ToList(); + return data.OrderBy(t => t.F_SortCode).ToList(); } public async Task> GetLookList(SoulPage pagination, string keyword = "") { @@ -67,13 +62,13 @@ namespace WaterCloud.Service.SystemOrganize } public async Task GetLookForm(string keyValue) { - var cachedata = await repository.CheckCache(cacheKey, keyValue); - return GetFieldsFilterData(cachedata); + var data = await repository.FindEntity(keyValue); + return GetFieldsFilterData(data); } public async Task GetForm(string keyValue) { - var cachedata = await repository.CheckCache(cacheKey, keyValue); - return cachedata; + var data = await repository.FindEntity(keyValue); + return data; } private IQuery GetQuery() { @@ -98,13 +93,11 @@ namespace WaterCloud.Service.SystemOrganize } public async Task DeleteForm(string keyValue) { - if (uniwork.IQueryable(a => a.F_DutyId == keyValue).Count() > 0) + if (unitwork.IQueryable(a => a.F_DutyId == keyValue).Count() > 0) { throw new Exception("岗位使用中,无法删除"); } await repository.Delete(t => t.F_Id == keyValue); - await CacheHelper.Remove(cacheKey + keyValue); - await CacheHelper.Remove(cacheKey + "list"); } public async Task SubmitForm(RoleEntity roleEntity, string keyValue) { @@ -112,8 +105,6 @@ namespace WaterCloud.Service.SystemOrganize { roleEntity.Modify(keyValue); await repository.Update(roleEntity); - await CacheHelper.Remove(cacheKey + keyValue); - await CacheHelper.Remove(cacheKey + "list"); } else { @@ -123,7 +114,6 @@ namespace WaterCloud.Service.SystemOrganize roleEntity.Create(); roleEntity.F_Category = 2; await repository.Insert(roleEntity); - await CacheHelper.Remove(cacheKey + "list"); } } @@ -178,7 +168,7 @@ namespace WaterCloud.Service.SystemOrganize { item.Create(); } - await uniwork.Insert(filterList); + await unitwork.Insert(filterList); } } } diff --git a/WaterCloud.Service/SystemOrganize/NoticeService.cs b/WaterCloud.Service/SystemOrganize/NoticeService.cs index 9dcad75d5550e843cd35ce8097a2c91e1eabd059..8e724108d5662eeeffcc39028f36df4154283e96 100644 --- a/WaterCloud.Service/SystemOrganize/NoticeService.cs +++ b/WaterCloud.Service/SystemOrganize/NoticeService.cs @@ -12,29 +12,22 @@ using System.Collections.Generic; using System.Linq; using WaterCloud.Code; using System.Threading.Tasks; +using WaterCloud.DataBase; using Chloe; namespace WaterCloud.Service.SystemOrganize { public class NoticeService: DataFilterService,IDenpendency { - //ȡ - - /// - /// - /// - - private string cacheKey = "watercloud_noticedata_"; - public NoticeService(IDbContext context) : base(context) + public NoticeService(IUnitOfWork unitOfWork) : base(unitOfWork) { } public async Task> GetList(string keyword) { - List list = new List(); - list = await repository.CheckCacheList(cacheKey + "list"); + var list = repository.IQueryable(); if (!string.IsNullOrEmpty(keyword)) { - list = list.Where(t => t.F_Title.Contains(keyword) || t.F_Content.Contains(keyword)).ToList(); + list = list.Where(t => t.F_Title.Contains(keyword) || t.F_Content.Contains(keyword)); } //ﲻ //Ȩ޺ͻȡͻ @@ -73,13 +66,13 @@ namespace WaterCloud.Service.SystemOrganize } public async Task GetLookForm(string keyValue) { - var cachedata =await repository.CheckCache(cacheKey, keyValue); - return GetFieldsFilterData(cachedata); + var data =await repository.FindEntity(keyValue); + return GetFieldsFilterData(data); } public async Task GetForm(string keyValue) { - var cachedata = await repository.CheckCache(cacheKey, keyValue); - return cachedata; + var data = await repository.FindEntity(keyValue); + return data; } public async Task SubmitForm(NoticeEntity entity, string keyValue) { @@ -87,8 +80,6 @@ namespace WaterCloud.Service.SystemOrganize { entity.Modify(keyValue); await repository.Update(entity); - await CacheHelper.Remove(cacheKey + keyValue); - await CacheHelper.Remove(cacheKey + "list"); } else { @@ -96,7 +87,6 @@ namespace WaterCloud.Service.SystemOrganize entity.F_DeleteMark = false; entity.Create(); await repository.Insert(entity); - await CacheHelper.Remove(cacheKey + "list"); } } @@ -104,11 +94,6 @@ namespace WaterCloud.Service.SystemOrganize { var ids = keyValue.Split(','); await repository.Delete(t => ids.Contains(t.F_Id)); - foreach (var item in ids) - { - await CacheHelper.Remove(cacheKey + item); - } - await CacheHelper.Remove(cacheKey + "list"); } } diff --git a/WaterCloud.Service/SystemOrganize/OrganizeService.cs b/WaterCloud.Service/SystemOrganize/OrganizeService.cs index 16d6b54c3a99768217bb7454b3620d1df1c1b643..ae404ba54348f06b7c45d4150146fd4a660536e1 100644 --- a/WaterCloud.Service/SystemOrganize/OrganizeService.cs +++ b/WaterCloud.Service/SystemOrganize/OrganizeService.cs @@ -11,25 +11,19 @@ using System.Threading.Tasks; using System.Linq; using WaterCloud.Code; using Chloe; +using WaterCloud.DataBase; namespace WaterCloud.Service.SystemOrganize { public class OrganizeService : DataFilterService, IDenpendency { - /// - /// 缓存操作类 - /// - - private string cacheKey = "watercloud_organizedata_"; - //获取类名 - - public OrganizeService(IDbContext context) : base(context) + public OrganizeService(IUnitOfWork unitOfWork) : base(unitOfWork) { } public async Task> GetList() { - var cachedata =await repository.CheckCacheList(cacheKey + "list"); - return cachedata.Where(a=>a.F_DeleteMark==false).ToList(); + var data = repository.IQueryable(); + return data.Where(a=>a.F_DeleteMark==false).ToList(); } public async Task> GetLookList() { @@ -39,13 +33,13 @@ namespace WaterCloud.Service.SystemOrganize } public async Task GetLookForm(string keyValue) { - var cachedata =await repository.CheckCache(cacheKey, keyValue); - return GetFieldsFilterData(cachedata); + var data =await repository.FindEntity(keyValue); + return GetFieldsFilterData(data); } public async Task GetForm(string keyValue) { - var cachedata = await repository.CheckCache(cacheKey, keyValue); - return cachedata; + var data = await repository.FindEntity(keyValue); + return data; } public async Task DeleteForm(string keyValue) { @@ -55,13 +49,11 @@ namespace WaterCloud.Service.SystemOrganize } else { - if (uniwork.IQueryable(a=>a.F_OrganizeId==keyValue).Count()>0|| uniwork.IQueryable(a => a.F_DepartmentId == keyValue).Count()>0) + if (unitwork.IQueryable(a=>a.F_OrganizeId==keyValue).Count()>0|| unitwork.IQueryable(a => a.F_DepartmentId == keyValue).Count()>0) { throw new Exception("组织使用中,无法删除"); } await repository.Delete(t => t.F_Id == keyValue); - await CacheHelper.Remove(cacheKey + keyValue); - await CacheHelper.Remove(cacheKey + "list"); } } public async Task SubmitForm(OrganizeEntity organizeEntity, string keyValue) @@ -70,8 +62,6 @@ namespace WaterCloud.Service.SystemOrganize { organizeEntity.Modify(keyValue); await repository.Update(organizeEntity); - await CacheHelper.Remove(cacheKey + keyValue); - await CacheHelper.Remove(cacheKey + "list"); } else { @@ -80,7 +70,6 @@ namespace WaterCloud.Service.SystemOrganize organizeEntity.F_DeleteMark = false; organizeEntity.Create(); await repository.Insert(organizeEntity); - await CacheHelper.Remove(cacheKey + "list"); } } } diff --git a/WaterCloud.Service/SystemOrganize/RoleAuthorizeService.cs b/WaterCloud.Service/SystemOrganize/RoleAuthorizeService.cs index d9a937f133541e0c046bf260813fd58ee200d59e..0c0c45043d2b7e2decedcf3d007a3bd063fdec7d 100644 --- a/WaterCloud.Service/SystemOrganize/RoleAuthorizeService.cs +++ b/WaterCloud.Service/SystemOrganize/RoleAuthorizeService.cs @@ -13,6 +13,7 @@ using System.Linq; using System.Threading.Tasks; using WaterCloud.Service.SystemManage; using WaterCloud.Domain.SystemManage; +using WaterCloud.DataBase; using Chloe; namespace WaterCloud.Service.SystemOrganize @@ -28,21 +29,21 @@ namespace WaterCloud.Service.SystemOrganize /// 缓存操作类 /// - private string cacheKey = "watercloud_authorizeurldata_";// +权限 - public RoleAuthorizeService(IDbContext context) : base(context) + private string cacheKey = GlobalContext.SystemConfig.ProjectPrefix + "_authorizeurldata_";// +权限 + public RoleAuthorizeService(IUnitOfWork unitOfWork) : base(unitOfWork) { - moduleApp = new ModuleService(context); - moduleButtonApp = new ModuleButtonService(context); - moduleFieldsApp = new ModuleFieldsService(context); - userApp = new UserService(context); - roleApp = new RoleService(context); + moduleApp = new ModuleService(unitOfWork); + moduleButtonApp = new ModuleButtonService(unitOfWork); + moduleFieldsApp = new ModuleFieldsService(unitOfWork); + userApp = new UserService(unitOfWork); + roleApp = new RoleService(unitOfWork); } public async Task> GetList(string ObjectId) { - var cachedata =await repository.CheckCacheList(cacheKey + "list"); - cachedata = cachedata.Where(t => t.F_ObjectId == ObjectId).ToList(); - return cachedata.ToList(); + var data = repository.IQueryable(); + data = data.Where(t => t.F_ObjectId == ObjectId); + return data.ToList(); } public async Task> GetMenuList(string roleId) { @@ -57,12 +58,12 @@ namespace WaterCloud.Service.SystemOrganize var rolelist = roleId.Split(','); var moduledata =await moduleApp.GetList(); moduledata = moduledata.Where(a => a.F_IsMenu == true && a.F_EnabledMark == true).ToList(); - var role =uniwork.IQueryable(a=>rolelist.Contains(a.F_Id)&&a.F_EnabledMark==true).ToList(); + var role =unitwork.IQueryable(a=>rolelist.Contains(a.F_Id)&&a.F_EnabledMark==true).ToList(); if (role.Count==0) { return data; } - var authorizedata =(await repository.CheckCacheList(cacheKey + "list")).Where(t => rolelist.Contains(t.F_ObjectId) && t.F_ItemType == 1).GroupBy(p => p.F_Id).Select(q => q.First()).ToList(); + var authorizedata = repository.IQueryable().Where(t => rolelist.Contains(t.F_ObjectId) && t.F_ItemType == 1).Distinct().ToList(); foreach (var item in authorizedata) { ModuleEntity moduleEntity = moduledata.Find(t => t.F_Id == item.F_ItemId && t.F_IsPublic==false); @@ -90,7 +91,7 @@ namespace WaterCloud.Service.SystemOrganize { return data; } - var authorizedata = (await repository.CheckCacheList(cacheKey + "list")).Where(t => t.F_ObjectId == roleId && t.F_ItemType == 2).ToList(); + var authorizedata = ( repository.IQueryable()).Where(t => t.F_ObjectId == roleId && t.F_ItemType == 2).ToList(); foreach (var item in authorizedata) { ModuleButtonEntity moduleButtonEntity = buttondata.Find(t => t.F_Id == item.F_ItemId && t.F_IsPublic == false); @@ -118,7 +119,7 @@ namespace WaterCloud.Service.SystemOrganize { return data; } - var authorizedata = (await repository.CheckCacheList(cacheKey + "list")).Where(t => t.F_ObjectId == roleId && t.F_ItemType == 3).ToList(); + var authorizedata = ( repository.IQueryable()).Where(t => t.F_ObjectId == roleId && t.F_ItemType == 3).ToList(); foreach (var item in authorizedata) { ModuleFieldsEntity moduleFieldsEntity = fieldsdata.Where(t => t.F_Id == item.F_ItemId && t.F_IsPublic == false).FirstOrDefault(); @@ -140,14 +141,14 @@ namespace WaterCloud.Service.SystemOrganize } var authorizeurldata = new List(); var rolelist = user.F_RoleId.Split(','); - var cachedata =await CacheHelper.Get>>(cacheKey + "authorize_list"); - if (cachedata == null) + var data =await CacheHelper.Get>>(cacheKey + "list"); + if (data == null) { - cachedata = new Dictionary>(); + data = new Dictionary>(); } foreach (var roles in rolelist) { - if (!cachedata.ContainsKey(roles)) + if (!data.ContainsKey(roles)) { var moduledata = await moduleApp.GetList(); moduledata = moduledata.Where(a => a.F_EnabledMark == true).ToList(); @@ -187,15 +188,15 @@ namespace WaterCloud.Service.SystemOrganize } authdata.AddRange(moduledata.Where(a => a.F_IsPublic == true).Select(a => new AuthorizeActionModel { F_Id = a.F_Id, F_UrlAddress = a.F_UrlAddress, F_Authorize = a.F_Authorize }).ToList()); authdata.AddRange(buttondata.Where(a => a.F_IsPublic == true).Select(a => new AuthorizeActionModel { F_Id = a.F_ModuleId, F_UrlAddress = a.F_UrlAddress, F_Authorize = a.F_Authorize }).ToList()); - cachedata.Add(roles, authdata); + data.Add(roles, authdata); authorizeurldata.AddRange(authdata); - await CacheHelper.Remove(cacheKey + "authorize_list"); - await CacheHelper.Set(cacheKey + "authorize_list", cachedata); + await CacheHelper.Remove(cacheKey + "list"); + await CacheHelper.Set(cacheKey + "list", data); } } else { - authorizeurldata.AddRange(cachedata[roles]); + authorizeurldata.AddRange(data[roles]); } } var module = authorizeurldata.Find(t => t.F_UrlAddress == action); @@ -224,14 +225,14 @@ namespace WaterCloud.Service.SystemOrganize } var authorizeurldata = new List(); var rolelist = user.F_RoleId.Split(','); - var cachedata = await CacheHelper.Get>>(cacheKey + "authorize_list"); - if (cachedata == null) + var data = await CacheHelper.Get>>(cacheKey + "list"); + if (data == null) { - cachedata = new Dictionary>(); + data = new Dictionary>(); } foreach (var roles in rolelist) { - if (!cachedata.ContainsKey(roles)) + if (!data.ContainsKey(roles)) { var moduledata = await moduleApp.GetList(); moduledata = moduledata.Where(a => a.F_EnabledMark == true).ToList(); @@ -271,15 +272,15 @@ namespace WaterCloud.Service.SystemOrganize } authdata.AddRange(moduledata.Where(a => a.F_IsPublic == true).Select(a => new AuthorizeActionModel { F_Id = a.F_Id, F_UrlAddress = a.F_UrlAddress, F_Authorize = a.F_Authorize }).ToList()); authdata.AddRange(buttondata.Where(a => a.F_IsPublic == true).Select(a => new AuthorizeActionModel { F_Id = a.F_ModuleId, F_UrlAddress = a.F_UrlAddress, F_Authorize = a.F_Authorize }).ToList()); - cachedata.Add(roles, authdata); + data.Add(roles, authdata); authorizeurldata.AddRange(authdata); - await CacheHelper.Remove(cacheKey + "authorize_list"); - await CacheHelper.Set(cacheKey + "authorize_list", cachedata); + await CacheHelper.Remove(cacheKey + "list"); + await CacheHelper.Set(cacheKey + "list", data); } } else { - authorizeurldata.AddRange(cachedata[roles]); + authorizeurldata.AddRange(data[roles]); } } if (authorizeurldata.Count>0) diff --git a/WaterCloud.Service/SystemOrganize/RoleService.cs b/WaterCloud.Service/SystemOrganize/RoleService.cs index 0e155df578a5a77a6c01f479c5f12718ea6d8f58..8a4fdabcbea725771ddcc5974ac2a9c045e8d88f 100644 --- a/WaterCloud.Service/SystemOrganize/RoleService.cs +++ b/WaterCloud.Service/SystemOrganize/RoleService.cs @@ -11,6 +11,7 @@ using System.Linq; using System; using System.Threading.Tasks; using WaterCloud.Service.SystemManage; +using WaterCloud.DataBase; using Chloe; namespace WaterCloud.Service.SystemOrganize @@ -24,28 +25,23 @@ namespace WaterCloud.Service.SystemOrganize /// /// 缓存操作类 /// - - private string cacheKey = "watercloud_roledata_"; - private string authorizecacheKey = "watercloud_authorizeurldata_";// +权限 - private string initcacheKey = "watercloud_init_"; - //获取类名 - - public RoleService(IDbContext context) : base(context) + private string authorizecacheKey = GlobalContext.SystemConfig.ProjectPrefix + "_authorizeurldata_";// +权限 + public RoleService(IUnitOfWork unitOfWork) : base(unitOfWork) { - moduleApp = new ModuleService(context); - moduleButtonApp = new ModuleButtonService(context); - moduleFieldsApp = new ModuleFieldsService(context); - itemsApp = new ItemsDataService(context); + moduleApp = new ModuleService(unitOfWork); + moduleButtonApp = new ModuleButtonService(unitOfWork); + moduleFieldsApp = new ModuleFieldsService(unitOfWork); + itemsApp = new ItemsDataService(unitOfWork); } public async Task> GetList( string keyword = "") { - var cachedata = GetQuery(); + var data = GetQuery(); if (!string.IsNullOrEmpty(keyword)) { - cachedata = cachedata.Where(t => t.F_FullName.Contains(keyword) || t.F_EnCode.Contains(keyword)); + data = data.Where(t => t.F_FullName.Contains(keyword) || t.F_EnCode.Contains(keyword)); } - return cachedata.ToList(); + return data.ToList(); } public async Task> GetLookList(SoulPage pagination, string keyword = "") { @@ -74,13 +70,13 @@ namespace WaterCloud.Service.SystemOrganize } public async Task GetForm(string keyValue) { - var cachedata =await repository.CheckCache(cacheKey, keyValue); - return cachedata; + var data =await repository.FindEntity(keyValue); + return data; } public async Task GetLookForm(string keyValue) { - var cachedata = await repository.CheckCache(cacheKey, keyValue); - return GetFieldsFilterData(cachedata); + var data = await repository.FindEntity(keyValue); + return GetFieldsFilterData(data); } private IQuery GetQuery() { @@ -108,21 +104,15 @@ namespace WaterCloud.Service.SystemOrganize } public async Task DeleteForm(string keyValue) { - if (uniwork.IQueryable(a => a.F_RoleId.Contains(keyValue)).Count() > 0 ) + if (unitwork.IQueryable(a => a.F_RoleId.Contains(keyValue)).Count() > 0 ) { throw new Exception("角色使用中,无法删除"); } - uniwork.BeginTrans(); + unitwork.BeginTrans(); await repository.Delete(t => t.F_Id == keyValue); - await uniwork.Delete(t => t.F_ObjectId == keyValue); - uniwork.Commit(); - await CacheHelper.Remove(cacheKey + keyValue); - await CacheHelper.Remove(cacheKey + "list"); + await unitwork.Delete(t => t.F_ObjectId == keyValue); + unitwork.Commit(); await CacheHelper.Remove(authorizecacheKey + "list"); - await CacheHelper.Remove(authorizecacheKey + "authorize_list"); - await CacheHelper.Remove(initcacheKey + "modulebutton_list"); - await CacheHelper.Remove(initcacheKey + "modulefields_list"); - await CacheHelper.Remove(initcacheKey + "list"); } public async Task SubmitForm(RoleEntity roleEntity, string[] permissionIds,string[] permissionfieldsIds, string keyValue) { @@ -174,7 +164,7 @@ namespace WaterCloud.Service.SystemOrganize roleAuthorizeEntitys.Add(roleAuthorizeEntity); } } - uniwork.BeginTrans(); + unitwork.BeginTrans(); if (!string.IsNullOrEmpty(keyValue)) { await repository.Update(roleEntity); @@ -184,16 +174,10 @@ namespace WaterCloud.Service.SystemOrganize roleEntity.F_Category = 1; await repository.Insert(roleEntity); } - await uniwork.Delete(t => t.F_ObjectId == roleEntity.F_Id); - await uniwork.Insert(roleAuthorizeEntitys); - uniwork.Commit(); - await CacheHelper.Remove(cacheKey + keyValue); - await CacheHelper.Remove(cacheKey + "list"); + await unitwork.Delete(t => t.F_ObjectId == roleEntity.F_Id); + await unitwork.Insert(roleAuthorizeEntitys); + unitwork.Commit(); await CacheHelper.Remove(authorizecacheKey + "list"); - await CacheHelper.Remove(authorizecacheKey + "authorize_list"); - await CacheHelper.Remove(initcacheKey + "modulebutton_list"); - await CacheHelper.Remove(initcacheKey + "modulefields_list"); - await CacheHelper.Remove(initcacheKey + "list"); } } } diff --git a/WaterCloud.Service/SystemOrganize/SystemSetService.cs b/WaterCloud.Service/SystemOrganize/SystemSetService.cs index 9faa7e1860b5c3be14ba880369a65621d925c341..5bab10f69f64119e043feacbd5bb34f49312a150 100644 --- a/WaterCloud.Service/SystemOrganize/SystemSetService.cs +++ b/WaterCloud.Service/SystemOrganize/SystemSetService.cs @@ -16,24 +16,22 @@ namespace WaterCloud.Service.SystemOrganize public class SystemSetService : DataFilterService, IDenpendency { private IDbContext _context; - private string cacheKey = "watercloud_systemsetdata_"; - private string cacheKeyOperator = "watercloud_operator_";// +登录者token - private string cacheKeyUser = "watercloud_userdata_"; + private string cacheKeyOperator = GlobalContext.SystemConfig.ProjectPrefix + "_operator_";// +登录者token - public SystemSetService(IDbContext context) : base(context) + public SystemSetService(IUnitOfWork unitOfWork) : base(unitOfWork) { - _context = context; + _context = unitOfWork.GetDbContext(); } #region 获取数据 public async Task> GetList(string keyword = "") { - var cachedata = await repository.CheckCacheList(cacheKey + "list"); + var data = repository.IQueryable(); if (!string.IsNullOrEmpty(keyword)) { //此处需修改 - cachedata = cachedata.Where(t => t.F_CompanyName.Contains(keyword) || t.F_ProjectName.Contains(keyword)).ToList(); + data = data.Where(t => t.F_CompanyName.Contains(keyword) || t.F_ProjectName.Contains(keyword)); } - return cachedata.Where(t => t.F_DeleteMark == false).OrderByDescending(t => t.F_CreatorTime).ToList(); + return data.Where(t => t.F_DeleteMark == false).OrderByDesc(t => t.F_CreatorTime).ToList(); } public async Task> GetLookList(string keyword = "") @@ -50,22 +48,22 @@ namespace WaterCloud.Service.SystemOrganize public async Task GetFormByHost(string host) { - var cachedata = await repository.CheckCacheList(cacheKey + "list"); + var data = repository.IQueryable(); if (!string.IsNullOrEmpty(host)) { //此处需修改 - cachedata = cachedata.Where(t => t.F_HostUrl.Contains(host)).ToList(); + data = data.Where(t => t.F_HostUrl.Contains(host)); } else { - cachedata = cachedata.Where(t => t.F_Id==GlobalContext.SystemConfig.SysemMasterProject).ToList(); + data = data.Where(t => t.F_Id==GlobalContext.SystemConfig.SysemMasterProject); } - if (cachedata.Count==0) + if (data.Count()==0) { - cachedata = await repository.CheckCacheList(cacheKey + "list"); - cachedata = cachedata.Where(t => t.F_Id == GlobalContext.SystemConfig.SysemMasterProject).ToList(); + data = repository.IQueryable(); + data = data.Where(t => t.F_Id == GlobalContext.SystemConfig.SysemMasterProject); } - return cachedata.Where(t => t.F_DeleteMark == false).FirstOrDefault(); + return data.Where(t => t.F_DeleteMark == false).FirstOrDefault(); } public async Task> GetLookList(Pagination pagination,string keyword = "") @@ -82,28 +80,27 @@ namespace WaterCloud.Service.SystemOrganize public async Task GetForm(string keyValue) { - var cachedata = await repository.CheckCache(cacheKey, keyValue); - return cachedata; + var data = await repository.FindEntity(keyValue); + return data; } #endregion public async Task GetLookForm(string keyValue) { - var cachedata = await repository.CheckCache(cacheKey, keyValue); - return GetFieldsFilterData(cachedata); + var data = await repository.FindEntity(keyValue); + return GetFieldsFilterData(data); } #region 提交数据 public async Task SubmitForm(SystemSetEntity entity, string keyValue) { - IRepositoryBase ibs = new RepositoryBase(_context); + IUnitOfWork ibs = new UnitOfWork(_context); if (string.IsNullOrEmpty(keyValue)) { entity.F_DeleteMark = false; //此处需修改 entity.Create(); await repository.Insert(entity); - await CacheHelper.Remove(cacheKey + "list"); } else { @@ -112,23 +109,22 @@ namespace WaterCloud.Service.SystemOrganize if (currentuser.UserId != GlobalContext.SystemConfig.SysemUserId || currentuser.UserId == null) { var setentity = await repository.FindEntity(entity.F_Id); - uniwork.BeginTrans(); - var user = uniwork.IQueryable(a => a.F_OrganizeId == entity.F_Id && a.F_IsAdmin == true).FirstOrDefault(); - var userinfo = uniwork.IQueryable(a => a.F_UserId == user.F_Id).FirstOrDefault(); + unitwork.BeginTrans(); + var user = unitwork.IQueryable(a => a.F_OrganizeId == entity.F_Id && a.F_IsAdmin == true).FirstOrDefault(); + var userinfo = unitwork.IQueryable(a => a.F_UserId == user.F_Id).FirstOrDefault(); userinfo.F_UserSecretkey = Md5.md5(Utils.CreateNo(), 16).ToLower(); userinfo.F_UserPassword = Md5.md5(DESEncrypt.Encrypt(Md5.md5(entity.F_AdminPassword, 32).ToLower(), userinfo.F_UserSecretkey).ToLower(), 32).ToLower(); - await uniwork.Update(a => a.F_Id == user.F_Id, a => new UserEntity + await unitwork.Update(a => a.F_Id == user.F_Id, a => new UserEntity { F_Account = entity.F_AdminAccount }); - await CacheHelper.Remove(cacheKeyUser + user.F_Id); - await uniwork.Update(a => a.F_Id == userinfo.F_Id, a => new UserLogOnEntity + await unitwork.Update(a => a.F_Id == userinfo.F_Id, a => new UserLogOnEntity { F_UserPassword = userinfo.F_UserPassword, F_UserSecretkey = userinfo.F_UserSecretkey }); - await uniwork.Update(entity); - uniwork.Commit(); + await unitwork.Update(entity); + unitwork.Commit(); } else { @@ -136,11 +132,9 @@ namespace WaterCloud.Service.SystemOrganize entity.F_AdminPassword = null; } await ibs.Update(entity); - await CacheHelper.Remove(cacheKey + keyValue); - await CacheHelper.Remove(cacheKey + "list"); } var set=await ibs.FindEntity(entity.F_Id); - var tempkey=new RepositoryBase(DBContexHelper.Contex(set.F_DbString, set.F_DBProvider)).IQueryable().Where(a => a.F_IsAdmin == true && a.F_OrganizeId == keyValue).FirstOrDefault().F_Id; + var tempkey= ibs.IQueryable().Where(a => a.F_IsAdmin == true && a.F_OrganizeId == keyValue).FirstOrDefault().F_Id; await CacheHelper.Remove(cacheKeyOperator + "info_" + tempkey); if (currentuser.UserId == null) { @@ -151,8 +145,6 @@ namespace WaterCloud.Service.SystemOrganize public async Task DeleteForm(string keyValue) { await repository.Delete(t => t.F_Id == keyValue); - await CacheHelper.Remove(cacheKey + keyValue); - await CacheHelper.Remove(cacheKey + "list"); } #endregion diff --git a/WaterCloud.Service/SystemOrganize/UserLogOnService.cs b/WaterCloud.Service/SystemOrganize/UserLogOnService.cs index bba224b69974e65b292c85fd811528c74243a525..cd5f71a4243416bb40e0db1165ffb1b53e21ba8d 100644 --- a/WaterCloud.Service/SystemOrganize/UserLogOnService.cs +++ b/WaterCloud.Service/SystemOrganize/UserLogOnService.cs @@ -8,6 +8,7 @@ using Chloe; using System; using System.Threading.Tasks; using WaterCloud.Code; +using WaterCloud.DataBase; using WaterCloud.Domain.SystemOrganize; namespace WaterCloud.Service.SystemOrganize @@ -18,8 +19,8 @@ namespace WaterCloud.Service.SystemOrganize /// 缓存操作类 /// - private string cacheKeyOperator = "watercloud_operator_";// +登录者token - public UserLogOnService(IDbContext context) : base(context) + private string cacheKeyOperator = GlobalContext.SystemConfig.ProjectPrefix + "_operator_";// +登录者token + public UserLogOnService(IUnitOfWork unitOfWork) : base(unitOfWork) { } diff --git a/WaterCloud.Service/SystemOrganize/UserService.cs b/WaterCloud.Service/SystemOrganize/UserService.cs index 8b53562678dd442e7526e41af6805f4e3aab7733..1231a1f5d3db71e746df41a60125c9af15a1afd5 100644 --- a/WaterCloud.Service/SystemOrganize/UserService.cs +++ b/WaterCloud.Service/SystemOrganize/UserService.cs @@ -12,23 +12,25 @@ using System.Linq; using System.Threading.Tasks; using Chloe; using WaterCloud.DataBase; +using WaterCloud.Service.SystemSecurity; +using WaterCloud.Domain.SystemSecurity; namespace WaterCloud.Service.SystemOrganize { public class UserService : DataFilterService, IDenpendency { - private SystemSetService syssetApp; + private SystemSetService syssetApp; + private FilterIPService ipApp; /// /// 缓存操作类 /// - - private string cacheKey = "watercloud_userdata_"; - private string cacheKeyOperator = "watercloud_operator_";// +登录者token + private string cacheKeyOperator = GlobalContext.SystemConfig.ProjectPrefix + "_operator_";// +登录者token //获取类名 - public UserService(IDbContext context) : base(context) + public UserService(IUnitOfWork unitOfWork) : base(unitOfWork) { - syssetApp = new SystemSetService(context); + syssetApp = new SystemSetService(unitOfWork); + ipApp = new FilterIPService(unitOfWork); } public async Task> GetLookList(SoulPage pagination, string keyword) @@ -52,8 +54,8 @@ namespace WaterCloud.Service.SystemOrganize } query = GetDataPrivilege("u", "", query); var data = await repository.OrderList(query, pagination); - var roles = uniwork.IQueryable().ToList(); - var orgs = uniwork.IQueryable().ToList(); + var roles = unitwork.IQueryable().ToList(); + var orgs = unitwork.IQueryable().ToList(); foreach (var item in data) { string[] roleIds = item.F_RoleId.Split(','); @@ -65,14 +67,14 @@ namespace WaterCloud.Service.SystemOrganize } public async Task> GetList(string keyword) { - var cachedata = GetQuery().Where(t => t.F_IsAdmin == false); + var query = GetQuery().Where(t => t.F_IsAdmin == false); if (!string.IsNullOrEmpty(keyword)) { - cachedata = cachedata.Where(t => t.F_Account.Contains(keyword) || t.F_RealName.Contains(keyword) || t.F_MobilePhone.Contains(keyword)); + query = query.Where(t => t.F_Account.Contains(keyword) || t.F_RealName.Contains(keyword) || t.F_MobilePhone.Contains(keyword)); } - var data = cachedata.OrderBy(t => t.F_Account).ToList(); - var roles = uniwork.IQueryable().ToList(); - var orgs = uniwork.IQueryable().ToList(); + var data = query.OrderBy(t => t.F_Account).ToList(); + var roles = unitwork.IQueryable().ToList(); + var orgs = unitwork.IQueryable().ToList(); foreach (var item in data) { string[] roleIds = item.F_RoleId.Split(','); @@ -132,74 +134,68 @@ namespace WaterCloud.Service.SystemOrganize public async Task SubmitUserForm(UserEntity userEntity) { await repository.Update(userEntity); - await CacheHelper.Remove(cacheKey + userEntity.F_Id); - await CacheHelper.Remove(cacheKey + "list"); } public async Task> GetUserList(string keyword) { - var cachedata =await repository.CheckCacheList(cacheKey + "list"); + var data = repository.IQueryable(); if (!string.IsNullOrEmpty(keyword)) { - cachedata = cachedata.Where(t => t.F_Account.Contains(keyword) || t.F_RealName.Contains(keyword) || t.F_MobilePhone.Contains(keyword)).ToList(); + data = data.Where(t => t.F_Account.Contains(keyword) || t.F_RealName.Contains(keyword) || t.F_MobilePhone.Contains(keyword)); } - return cachedata.Where(t => t.F_EnabledMark ==true && t.F_DeleteMark == false).OrderBy(t => t.F_Account).ToList(); + return data.Where(t => t.F_EnabledMark ==true && t.F_DeleteMark == false).OrderBy(t => t.F_Account).ToList(); } public async Task GetForm(string keyValue) { - var cachedata = await repository.CheckCache(cacheKey, keyValue); - return cachedata; + var data = await repository.FindEntity(keyValue); + return data; } public async Task GetFormExtend(string keyValue) { - var cachedata = await repository.CheckCache(cacheKey, keyValue); + var data = await repository.FindEntity(keyValue); string[] temp; - if (cachedata.F_RoleId != null) + if (data.F_RoleId != null) { - temp = cachedata.F_RoleId.Split(','); - cachedata.F_RoleName = string.Join(",", uniwork.IQueryable().Where(a => temp.Contains(a.F_Id)).Select(a => a.F_FullName).ToList().ToArray()); + temp = data.F_RoleId.Split(','); + data.F_RoleName = string.Join(",", unitwork.IQueryable().Where(a => temp.Contains(a.F_Id)).Select(a => a.F_FullName).ToList().ToArray()); } - if (cachedata.F_DepartmentId != null) + if (data.F_DepartmentId != null) { - temp = cachedata.F_DepartmentId.Split(','); - cachedata.F_DepartmentName = string.Join(",", uniwork.IQueryable().Where(a => temp.Contains(a.F_Id)).Select(a => a.F_FullName).ToList().ToArray()); + temp = data.F_DepartmentId.Split(','); + data.F_DepartmentName = string.Join(",", unitwork.IQueryable().Where(a => temp.Contains(a.F_Id)).Select(a => a.F_FullName).ToList().ToArray()); } - return cachedata; + return data; } public async Task GetLookForm(string keyValue) { - var cachedata = await repository.CheckCache(cacheKey, keyValue); + var data = await repository.FindEntity(keyValue); string[] temp; - if (cachedata.F_RoleId != null) + if (data.F_RoleId != null) { - temp = cachedata.F_RoleId.Split(','); - cachedata.F_RoleName = string.Join(",", uniwork.IQueryable().Where(a => temp.Contains(a.F_Id)).Select(a => a.F_FullName).ToList().ToArray()); + temp = data.F_RoleId.Split(','); + data.F_RoleName = string.Join(",", unitwork.IQueryable().Where(a => temp.Contains(a.F_Id)).Select(a => a.F_FullName).ToList().ToArray()); } - if (cachedata.F_DepartmentId != null) + if (data.F_DepartmentId != null) { - temp = cachedata.F_DepartmentId.Split(','); - cachedata.F_DepartmentName = string.Join(",", uniwork.IQueryable().Where(a => temp.Contains(a.F_Id)).Select(a => a.F_FullName).ToList().ToArray()); + temp = data.F_DepartmentId.Split(','); + data.F_DepartmentName = string.Join(",", unitwork.IQueryable().Where(a => temp.Contains(a.F_Id)).Select(a => a.F_FullName).ToList().ToArray()); } - return GetFieldsFilterData(cachedata); + return GetFieldsFilterData(data); } public async Task DeleteForm(string keyValue) { - uniwork.BeginTrans(); + unitwork.BeginTrans(); await repository.Delete(t => t.F_Id == keyValue); - await uniwork.Delete(t => t.F_UserId == keyValue); - uniwork.Commit(); - await CacheHelper.Remove(cacheKey + keyValue); - await CacheHelper.Remove(cacheKey + "list"); + await unitwork.Delete(t => t.F_UserId == keyValue); + unitwork.Commit(); } public async Task SubmitForm(UserEntity userEntity, UserLogOnEntity userLogOnEntity, string keyValue) { if (!string.IsNullOrEmpty(keyValue)) { userEntity.Modify(keyValue); - await CacheHelper.Remove(cacheKey + keyValue); - await CacheHelper.Remove(cacheKey + "list"); } else { @@ -209,9 +205,8 @@ namespace WaterCloud.Service.SystemOrganize userLogOnEntity.F_ErrorNum = 0; userLogOnEntity.F_UserOnLine = false; userLogOnEntity.F_LogOnCount = 0; - await CacheHelper.Remove(cacheKey + "list"); } - uniwork.BeginTrans(); + unitwork.BeginTrans(); if (!string.IsNullOrEmpty(keyValue)) { await repository.Update(userEntity); @@ -223,15 +218,13 @@ namespace WaterCloud.Service.SystemOrganize userLogOnEntity.F_UserSecretkey = Md5.md5(Utils.CreateNo(), 16).ToLower(); userLogOnEntity.F_UserPassword = Md5.md5(DESEncrypt.Encrypt(Md5.md5(userLogOnEntity.F_UserPassword, 32).ToLower(), userLogOnEntity.F_UserSecretkey).ToLower(), 32).ToLower(); await repository.Insert(userEntity); - await uniwork.Insert(userLogOnEntity); + await unitwork.Insert(userLogOnEntity); } - uniwork.Commit(); + unitwork.Commit(); } public async Task UpdateForm(UserEntity userEntity) { await repository.Update(userEntity); - await CacheHelper.Remove(cacheKey + userEntity.F_Id); - await CacheHelper.Remove(cacheKey + "list"); } /// /// 登录判断 @@ -242,15 +235,15 @@ namespace WaterCloud.Service.SystemOrganize public async Task CheckLogin(string username, string password,string localurl) { //根据登录公司查找公司 - if (!string.IsNullOrEmpty(localurl)) - { - var setTemp=(await syssetApp.GetList()).Where(a=> localurl.Contains(a.F_HostUrl)).FirstOrDefault(); - if (setTemp!=null) - { - repository = new RepositoryBase(setTemp.F_DbString,setTemp.F_DBProvider); - uniwork = new RepositoryBase(setTemp.F_DbString, setTemp.F_DBProvider); - } - } + //if (!string.IsNullOrEmpty(localurl)) + //{ + // var setTemp=(await syssetApp.GetList()).Where(a=> localurl.Contains(a.F_HostUrl)).FirstOrDefault(); + // if (setTemp!=null) + // { + // repository = new RepositoryBase(setTemp.F_DbString,setTemp.F_DBProvider); + // uniwork = new RepositoryBase(setTemp.F_DbString, setTemp.F_DBProvider); + // } + //} UserEntity userEntity =await repository.FindEntity(t => t.F_Account == username); if (userEntity != null) { @@ -261,7 +254,7 @@ namespace WaterCloud.Service.SystemOrganize if (userLogOnEntity==null) { userLogOnEntity = new OperatorUserInfo(); - UserLogOnEntity entity =await uniwork.FindEntity(userEntity.F_Id); + UserLogOnEntity entity =await unitwork.FindEntity(userEntity.F_Id); userLogOnEntity.F_UserPassword = entity.F_UserPassword; userLogOnEntity.F_UserSecretkey = entity.F_UserSecretkey; userLogOnEntity.F_AllowEndTime = entity.F_AllowEndTime; @@ -288,7 +281,7 @@ namespace WaterCloud.Service.SystemOrganize if (userEntity.F_Account != GlobalContext.SystemConfig.SysemUserCode) { var list = userEntity.F_RoleId.Split(','); - var rolelist =uniwork.IQueryable(a=>list.Contains(a.F_Id)&&a.F_EnabledMark==true).ToList(); + var rolelist =unitwork.IQueryable(a=>list.Contains(a.F_Id)&&a.F_EnabledMark==true).ToList(); if (rolelist.Count() == 0) { throw new Exception("账户未设置权限,请联系管理员"); @@ -309,26 +302,28 @@ namespace WaterCloud.Service.SystemOrganize return userEntity; } else - { - if (userEntity.F_Account != GlobalContext.SystemConfig.SysemUserCode) - { - int num =await OperatorProvider.Provider.AddCurrentErrorNum(); - string erornum = (5 - num).ToString(); - if (num == 5) - { - userEntity.F_EnabledMark = false; - await repository.Update(userEntity); - await OperatorProvider.Provider.ClearCurrentErrorNum(); - throw new Exception("密码不正确,账户被系统锁定"); - } - else - { - throw new Exception("密码不正确,请重新输入,还有" + erornum + "次机会"); - } - } - else - { - throw new Exception("密码不正确,请重新输入"); + { + //登录错误不超过3次 + int num = await OperatorProvider.Provider.AddCurrentErrorNum(); + string erornum = (4 - num).ToString(); + if (num == 4) + { + FilterIPEntity ipentity = new FilterIPEntity(); + ipentity.F_Id = Utils.GuId(); + ipentity.F_StartIP = WebHelper.Ip; + ipentity.F_CreatorTime = DateTime.Now; + ipentity.F_DeleteMark = false; + ipentity.F_EnabledMark = true; + ipentity.F_Type = false; + //封禁12小时 + ipentity.F_EndTime = DateTime.Now.AddHours(12); + await ipApp.SubmitForm(ipentity, null); + await OperatorProvider.Provider.ClearCurrentErrorNum(); + throw new Exception("密码不正确,IP被锁定"); + } + else + { + throw new Exception("密码不正确,请重新输入,还有" + erornum + "次机会"); } } } diff --git a/WaterCloud.Service/SystemSecurity/FilterIPService.cs b/WaterCloud.Service/SystemSecurity/FilterIPService.cs index 54dfec0df20b365f41f5afc45e2ea37d92f0bb37..8b186fad375788bfc93c38f519e4dcc10353d2ad 100644 --- a/WaterCloud.Service/SystemSecurity/FilterIPService.cs +++ b/WaterCloud.Service/SystemSecurity/FilterIPService.cs @@ -11,28 +11,21 @@ using System; using System.Threading.Tasks; using WaterCloud.Code; using Chloe; +using WaterCloud.DataBase; namespace WaterCloud.Service.SystemSecurity { public class FilterIPService : DataFilterService, IDenpendency { - /// - /// 缓存操作类 - /// - - private string cacheKey = "watercloud_filterip_";// IP过滤 - //获取类名 - - public FilterIPService(IDbContext context) : base(context) + public FilterIPService(IUnitOfWork unitOfWork) : base(unitOfWork) { } public async Task> GetList(string keyword) { - var list = new List(); - list = await repository.CheckCacheList(cacheKey + "list"); + var list = repository.IQueryable(); if (!string.IsNullOrEmpty(keyword)) { - list = list.Where(t => t.F_StartIP.Contains(keyword) || t.F_EndIP.Contains(keyword)).ToList(); + list = list.Where(t => t.F_StartIP.Contains(keyword) || t.F_EndIP.Contains(keyword)); } return list.Where(a => a.F_DeleteMark == false).OrderBy(t => t.F_CreatorTime).ToList(); @@ -50,41 +43,44 @@ namespace WaterCloud.Service.SystemSecurity } public async Task GetLookForm(string keyValue) { - var cachedata =await repository.CheckCache(cacheKey, keyValue); - return GetFieldsFilterData(cachedata); + var data =await repository.FindEntity(keyValue); + return GetFieldsFilterData(data); } public async Task GetForm(string keyValue) { - var cachedata = await repository.CheckCache(cacheKey, keyValue); - return cachedata; + var data = await repository.FindEntity(keyValue); + return data; } public async Task DeleteForm(string keyValue) { var ids = keyValue.Split(","); await repository.Delete(t => ids.Contains(t.F_Id)); - foreach (var item in ids) - { - await CacheHelper.Remove(cacheKey + item); - } - await CacheHelper.Remove(cacheKey + "list"); } public async Task CheckIP(string ip) { - var list =await GetList(""); - list = list.Where(a => a.F_EnabledMark == true&&a.F_DeleteMark==false).ToList(); + var list = repository.IQueryable().Where(a => a.F_EnabledMark == true && a.F_DeleteMark == false && a.F_Type == false && a.F_EndTime > DateTime.Now).ToList(); + long ipAddress = IP2Long(ip); foreach (var item in list) { - if (item.F_Type == false) - { - long start = IP2Long(item.F_StartIP); - long end = IP2Long(item.F_EndIP); - long ipAddress = IP2Long(ip); - bool inRange = (ipAddress >= start && ipAddress <= end); - if (inRange) + if (string.IsNullOrEmpty(item.F_EndIP)) { - return false; + long start = IP2Long(item.F_StartIP); + bool inRange = ipAddress == start; + if (inRange) + { + return false; + } + } + else + { + long start = IP2Long(item.F_StartIP); + long end = IP2Long(item.F_EndIP); + bool inRange = (ipAddress >= start && ipAddress <= end); + if (inRange) + { + return false; + } } - } } return true; } @@ -104,18 +100,17 @@ namespace WaterCloud.Service.SystemSecurity } public async Task SubmitForm(FilterIPEntity filterIPEntity, string keyValue) { + filterIPEntity.F_Type = false; if (!string.IsNullOrEmpty(keyValue)) { filterIPEntity.Modify(keyValue); await repository.Update(filterIPEntity); - await CacheHelper.Remove(cacheKey + keyValue); } else { filterIPEntity.Create(); await repository.Insert(filterIPEntity); } - await CacheHelper.Remove(cacheKey + "list"); } } } diff --git a/WaterCloud.Service/SystemSecurity/LogService.cs b/WaterCloud.Service/SystemSecurity/LogService.cs index b6fc40e35c85da8af5240a38553c51fd5bb9d0dc..502cdc37ac3d163288de80faae0360bfc36dcae5 100644 --- a/WaterCloud.Service/SystemSecurity/LogService.cs +++ b/WaterCloud.Service/SystemSecurity/LogService.cs @@ -12,6 +12,7 @@ using System.Threading.Tasks; using WaterCloud.Service.SystemManage; using System.Linq; using Chloe; +using WaterCloud.DataBase; using WaterCloud.Domain.SystemManage; namespace WaterCloud.Service.SystemSecurity @@ -24,9 +25,9 @@ namespace WaterCloud.Service.SystemSecurity private ModuleService moduleservice; //获取类名 - public LogService(IDbContext context) : base(context) + public LogService(IUnitOfWork unitOfWork) : base(unitOfWork) { - moduleservice = new ModuleService(context); + moduleservice = new ModuleService(unitOfWork); } public async Task> GetList(Pagination pagination, int timetype, string keyword="") { @@ -167,7 +168,7 @@ namespace WaterCloud.Service.SystemSecurity logEntity.Create(); if (HandleLogProvider != Define.CACHEPROVIDER_REDIS) { - uniwork.Rollback(); + unitwork.Rollback(); await repository.Insert(logEntity); } else diff --git a/WaterCloud.Service/SystemSecurity/OpenJobsService.cs b/WaterCloud.Service/SystemSecurity/OpenJobsService.cs index 0797227230b59e6acad27c6a449c7fb1ca2bb019..6de3f00b06f4aee256ef1314b556e71fdfbc05ce 100644 --- a/WaterCloud.Service/SystemSecurity/OpenJobsService.cs +++ b/WaterCloud.Service/SystemSecurity/OpenJobsService.cs @@ -16,23 +16,27 @@ using WaterCloud.Service.AutoJob; using Chloe; using Quartz.Spi; using WaterCloud.DataBase; +using System.Net.Http; +using System.IO; +using System.Reflection; namespace WaterCloud.Service.SystemSecurity { public class OpenJobsService : IDenpendency { private IRepositoryBase repository; - private IRepositoryBase uniwork; + private IUnitOfWork uniwork; private IScheduler _scheduler; private string HandleLogProvider = GlobalContext.SystemConfig.HandleLogProvider; - //获取类名 - - public OpenJobsService(IDbContext context, ISchedulerFactory schedulerFactory, IJobFactory iocJobfactory) + private HttpWebClient _httpClient; + + public OpenJobsService(IUnitOfWork unitOfWork, ISchedulerFactory schedulerFactory, IJobFactory iocJobfactory, IHttpClientFactory httpClient) { - repository = new RepositoryBase(context); - uniwork = new RepositoryBase(context); + repository = new RepositoryBase(unitOfWork); + uniwork = unitOfWork; _scheduler = schedulerFactory.GetScheduler().GetAwaiter().GetResult(); _scheduler.JobFactory = iocJobfactory; + _httpClient = new HttpWebClient(httpClient); } /// /// 加载列表 @@ -61,17 +65,17 @@ namespace WaterCloud.Service.SystemSecurity } public async Task> GetList(string keyword = "") { - var cachedata = repository.IQueryable(); + var data = repository.IQueryable(); if (!string.IsNullOrEmpty(keyword)) { - cachedata = cachedata.Where(t => t.F_JobName.Contains(keyword)); + data = data.Where(t => t.F_JobName.Contains(keyword)); } - return cachedata.Where(a => a.F_DeleteMark == false).ToList(); + return data.Where(a => a.F_DeleteMark == false).ToList(); } public async Task GetForm(string keyValue) { - var cachedata = await repository.FindEntity(keyValue); - return cachedata; + var data = await repository.FindEntity(keyValue); + return data; } public async Task SubmitForm(OpenJobEntity entity, string keyValue) { @@ -83,7 +87,14 @@ namespace WaterCloud.Service.SystemSecurity else { entity.Create(); + uniwork.BeginTrans(); + if (entity.F_DoItNow == true) + { + await ChangeJobStatus(entity.F_Id, 1); + await DoNow(entity.F_Id,false); + } await repository.Insert(entity); + uniwork.Commit(); } } @@ -106,6 +117,99 @@ namespace WaterCloud.Service.SystemSecurity return types.Select(u => u.FullName).ToList(); } + public async Task DoNow(string keyValue,bool commit=true) + { + // 获取数据库中的任务 + var dbJobEntity = await GetForm(keyValue); + if (dbJobEntity != null) + { + DateTime now = DateTime.Now; + #region 执行任务 + OpenJobLogEntity log = new OpenJobLogEntity(); + log.F_Id = Utils.GuId(); + log.F_JobId = keyValue; + log.F_JobName = dbJobEntity.F_JobName; + log.F_CreatorTime = now; + uniwork.BeginTrans(); + AlwaysResult result = new AlwaysResult(); + if (dbJobEntity.F_JobType == 0) + { + //反射执行就行 + var path = AppDomain.CurrentDomain.RelativeSearchPath ?? AppDomain.CurrentDomain.BaseDirectory; + //反射取指定前后缀的dll + var referencedAssemblies = Directory.GetFiles(path, "WaterCloud.*.dll").Select(Assembly.LoadFrom).ToArray(); + var types = referencedAssemblies + .SelectMany(a => a.GetTypes().Where(t => t.GetInterfaces() + .Contains(typeof(IJobTask)))).ToArray(); + string filename = dbJobEntity.F_FileName; + var implementType = types.Where(x => x.IsClass && x.FullName == filename).FirstOrDefault(); + var obj = System.Activator.CreateInstance(implementType, repository.unitOfWork); // 创建实例(带参数) + MethodInfo method = implementType.GetMethod("Start", new Type[] { }); // 获取方法信息 + object[] parameters = null; + result = ((Task)method.Invoke(obj, parameters)).GetAwaiter().GetResult(); // 调用方法,参数为空 + if (result.state.ToString() == ResultType.success.ToString()) + { + log.F_EnabledMark = true; + log.F_Description = "执行成功," + result.message.ToString(); + } + else + { + log.F_EnabledMark = false; + log.F_Description = "执行失败," + result.message.ToString(); + } + } + else + { + HttpMethod method = HttpMethod.Get; + switch (dbJobEntity.F_JobType) + { + case 1: + method = HttpMethod.Get; + break; + case 2: + method = HttpMethod.Post; + break; + case 3: + method = HttpMethod.Put; + break; + case 4: + method = HttpMethod.Delete; + break; + } + var dic = dbJobEntity.F_RequestHeaders.ToObject>(); + try + { + var temp = await _httpClient.ExecuteAsync(dbJobEntity.F_RequestUrl, method, dbJobEntity.F_RequestString, dic); + log.F_EnabledMark = true; + log.F_Description = "执行成功。"; + } + catch (Exception ex) + { + log.F_EnabledMark = false; + log.F_Description = "执行失败," + ex.Message.ToString(); + } + } + #endregion + await repository.Update(t => t.F_Id == keyValue, t => new OpenJobEntity + { + F_LastRunTime = now + }); + string HandleLogProvider = GlobalContext.SystemConfig.HandleLogProvider; + if (HandleLogProvider != Define.CACHEPROVIDER_REDIS) + { + await uniwork.Insert(log); + } + else + { + await HandleLogHelper.HSetAsync(log.F_JobId, log.F_Id, log); + } + if (commit) + { + uniwork.Commit(); + } + } + } + public async Task ChangeJobStatus(string keyValue, int status) { var job = await repository.FindEntity(u => u.F_Id == keyValue); diff --git a/WaterCloud.Service/SystemSecurity/ServerStateService.cs b/WaterCloud.Service/SystemSecurity/ServerStateService.cs index b7662ffd797821326602aee9502d42f761746353..8b11da31be367f5d503e6d96bad658d81421b8b9 100644 --- a/WaterCloud.Service/SystemSecurity/ServerStateService.cs +++ b/WaterCloud.Service/SystemSecurity/ServerStateService.cs @@ -20,11 +20,11 @@ namespace WaterCloud.Service.SystemSecurity public class ServerStateService:IDenpendency { private IRepositoryBase repository; - private IRepositoryBase uniwork; - public ServerStateService(IDbContext context) + private IUnitOfWork uniwork; + public ServerStateService(IUnitOfWork unitOfWork) { - repository = new RepositoryBase(context); - uniwork = new RepositoryBase(context); + repository = new RepositoryBase(unitOfWork); + uniwork = unitOfWork; } public async Task> GetList(int timetype) { diff --git a/WaterCloud.Service/TimeService/TimedService.cs b/WaterCloud.Service/TimeService/TimedService.cs index e28cccdc3074eb1b0db93d588c9178dc7b9da731..d9b5cd7b0a70cb3dd7048876cadebad168775373 100644 --- a/WaterCloud.Service/TimeService/TimedService.cs +++ b/WaterCloud.Service/TimeService/TimedService.cs @@ -8,6 +8,8 @@ using System.Threading.Tasks; using WaterCloud.Service.SystemSecurity; using WaterCloud.Code; using WaterCloud.Domain.SystemSecurity; +using WaterCloud.DataBase; + namespace WaterCloud.Service.TimeService { @@ -30,17 +32,17 @@ namespace WaterCloud.Service.TimeService private readonly ILogger _logger; private readonly IWebHostEnvironment _hostingEnvironment; - private readonly IDbContext _context; + private readonly IUnitOfWork _unitOfWork; //定时器 private Timer _timer; //private Timer _timer; - public TimedService(ILogger logger, IWebHostEnvironment hostingEnvironment, IDbContext context) + public TimedService(ILogger logger, IWebHostEnvironment hostingEnvironment, IUnitOfWork unitOfWork) { _logger = logger; _hostingEnvironment=hostingEnvironment; - _context = context; + _unitOfWork = unitOfWork; } protected override Task ExecuteAsync(CancellationToken stoppingToken) @@ -59,7 +61,7 @@ namespace WaterCloud.Service.TimeService entity.F_CPU = computer.CPURate; entity.F_IIS = "0"; entity.F_WebSite = _hostingEnvironment.ContentRootPath; - new ServerStateService(_context).SubmitForm(entity).GetAwaiter().GetResult(); + new ServerStateService(_unitOfWork).SubmitForm(entity).GetAwaiter().GetResult(); } public override void Dispose() diff --git a/WaterCloud.Web/Areas/ContentManage/Views/ArticleCategory/Index.cshtml b/WaterCloud.Web/Areas/ContentManage/Views/ArticleCategory/Index.cshtml index a6f7c70f3ca533f9edfcddd7361df743ea3f259a..d4c0d4338602d533b2289c020c0d7cf520e81645 100644 --- a/WaterCloud.Web/Areas/ContentManage/Views/ArticleCategory/Index.cshtml +++ b/WaterCloud.Web/Areas/ContentManage/Views/ArticleCategory/Index.cshtml @@ -70,17 +70,10 @@ } }, { - field: 'F_CreatorTime', title: '创建时间', minWidth: 150, filter: { type: 'date[yyyy-MM-dd HH:mm:ss]' }, - templet: function (d) { - if (d.F_CreatorTime) { - var time = new Date(d.F_CreatorTime); - return time.Format("yyyy-MM-dd hh:mm:ss"); - } - return ''; - } + field: 'F_CreatorTime', title: '创建时间', minWidth: 160, filter: { type: 'date[yyyy/MM/dd HH:mm:ss]' } }, { field: 'F_CreatorUserId', title: '创建人', width: 120, hide: true }, - { title: '操作', width: 170, toolbar: '#currentTableBar', align: "center", fixed: 'right' }//插件没有fixed参数 + { title: '操作', width: 175, toolbar: '#currentTableBar', align: "center", fixed: 'right' }//插件没有fixed参数 ]], }; commonTable.rendertreetable(options); diff --git a/WaterCloud.Web/Areas/ContentManage/Views/ArticleNews/Index.cshtml b/WaterCloud.Web/Areas/ContentManage/Views/ArticleNews/Index.cshtml index b7c4cdefa3db826e5b4cac0dca267193388ddf4f..50da675f8a028726335cf276334113007dc29670 100644 --- a/WaterCloud.Web/Areas/ContentManage/Views/ArticleNews/Index.cshtml +++ b/WaterCloud.Web/Areas/ContentManage/Views/ArticleNews/Index.cshtml @@ -106,17 +106,10 @@ { field: 'F_Source', title: '来源', width: 120, filter: true }, { field: 'F_Author', title: '作者', width: 120, filter: true }, { - field: 'F_CreatorTime', title: '创建时间', width: 160, filter: { type: 'date[yyyy-MM-dd HH:mm:ss]' }, - templet: function (d) { - if (d.F_CreatorTime) { - var time = new Date(d.F_CreatorTime); - return time.Format("yyyy-MM-dd hh:mm:ss"); - } - return ''; - } + field: 'F_CreatorTime', title: '创建时间', width: 160, filter: { type: 'date[yyyy/MM/dd HH:mm:ss]' } }, { field: 'F_CreatorUserId', title: '创建人', width: 120, filter: true, hide: true }, - { title: '操作', width: 170, toolbar: '#currentTableBar', align: "center", fixed: 'right' } + { title: '操作', width: 175, toolbar: '#currentTableBar', align: "center", fixed: 'right' } ]] }); $(function () { diff --git a/WaterCloud.Web/Areas/FileManage/Views/Uploadfile/Index.cshtml b/WaterCloud.Web/Areas/FileManage/Views/Uploadfile/Index.cshtml index 908ff56787b43718a9f250a14d544a8fc836891c..762aefc532455f3f343ae10e216e4f43425856cc 100644 --- a/WaterCloud.Web/Areas/FileManage/Views/Uploadfile/Index.cshtml +++ b/WaterCloud.Web/Areas/FileManage/Views/Uploadfile/Index.cshtml @@ -83,14 +83,7 @@ } }, { - field: 'F_CreatorTime', title: '创建时间', width: 120, sort: true, filter: { type: 'date[yyyy-MM-dd]' }, - templet: function (d) { - if (d.F_CreatorTime) { - var time = new Date(d.F_CreatorTime); - return time.Format("yyyy-MM-dd"); - } - return ''; - } + field: 'F_CreatorTime', title: '创建时间', width: 160, sort: true, filter: { type: 'date[yyyy/MM/dd HH:mm:ss]' } }, { field: 'F_CreatorUserName', title: '创建用户', width: 120, sort: true, filter: true }, { field: 'F_Description', title: '文件备注', minWidth: 150, sort: true, filter: true }, diff --git a/WaterCloud.Web/Areas/FlowManage/Views/Flowinstance/DoneFlow.cshtml b/WaterCloud.Web/Areas/FlowManage/Views/Flowinstance/DoneFlow.cshtml index 3b65973a08e2149aab1fbab943446942b16bdbdc..bdd02afd3d869f84ea70d660ae544b7916929365 100644 --- a/WaterCloud.Web/Areas/FlowManage/Views/Flowinstance/DoneFlow.cshtml +++ b/WaterCloud.Web/Areas/FlowManage/Views/Flowinstance/DoneFlow.cshtml @@ -70,14 +70,7 @@ { field: 'F_ActivityName', title: '当前节点名称', width: 140, filter: true }, { field: 'F_Description', title: '实例备注', minWidth: 150, filter: true }, { - field: 'F_CreatorTime', title: '创建时间', width: 120, filter: { type: 'date[yyyy-MM-dd]' }, - templet: function (d) { - if (d.F_CreatorTime) { - var time = new Date(d.F_CreatorTime); - return time.Format("yyyy-MM-dd"); - } - return ''; - } + field: 'F_CreatorTime', title: '创建时间', width: 160, filter: { type: 'date[yyyy/MM/dd HH:mm:ss]' } }, { field: 'F_CreatorUserName', title: '创建人', width: 120, sort: true, filter: true }, { title: '操作', width: 90, toolbar: '#currentTableBar', align: "center", fixed: 'right'} diff --git a/WaterCloud.Web/Areas/FlowManage/Views/Flowinstance/Index.cshtml b/WaterCloud.Web/Areas/FlowManage/Views/Flowinstance/Index.cshtml index 1bf259160697d7062a159d01bf020fc36c43b8fe..73e855d4fa8bf54b730d008adee98a422440f8c8 100644 --- a/WaterCloud.Web/Areas/FlowManage/Views/Flowinstance/Index.cshtml +++ b/WaterCloud.Web/Areas/FlowManage/Views/Flowinstance/Index.cshtml @@ -74,17 +74,10 @@ { field: 'F_ActivityName', title: '当前节点名称', width: 140, filter: true }, { field: 'F_Description', title: '实例备注', minWidth: 150, filter: true }, { - field: 'F_CreatorTime', title: '创建时间', width: 120, filter: { type: 'date[yyyy-MM-dd]' }, - templet: function (d) { - if (d.F_CreatorTime) { - var time = new Date(d.F_CreatorTime); - return time.Format("yyyy-MM-dd"); - } - return ''; - } + field: 'F_CreatorTime', title: '创建时间', width: 160, filter: { type: 'date[yyyy/MM/dd HH:mm:ss]' } }, { field: 'F_CreatorUserName', title: '创建人', width: 120, sort: true, filter: true }, - { title: '操作', width: 170, toolbar: '#currentTableBar', align: "center", fixed: 'right' } + { title: '操作', width: 175, toolbar: '#currentTableBar', align: "center", fixed: 'right' } ]] }); // 监听搜索操作 diff --git a/WaterCloud.Web/Areas/FlowManage/Views/Flowinstance/ToDoFlow.cshtml b/WaterCloud.Web/Areas/FlowManage/Views/Flowinstance/ToDoFlow.cshtml index ba75c1ae5aca27540a4a1f1dc1a0679efaae0656..cc16e4190b23eeca6bbd675e434ffe7ce731be0c 100644 --- a/WaterCloud.Web/Areas/FlowManage/Views/Flowinstance/ToDoFlow.cshtml +++ b/WaterCloud.Web/Areas/FlowManage/Views/Flowinstance/ToDoFlow.cshtml @@ -72,14 +72,7 @@ { field: 'F_ActivityName', title: '当前节点名称', width: 140, filter: true }, { field: 'F_Description', title: '实例备注', minWidth: 150, filter: true }, { - field: 'F_CreatorTime', title: '创建时间', width: 120, filter: { type: 'date[yyyy-MM-dd]' }, - templet: function (d) { - if (d.F_CreatorTime) { - var time = new Date(d.F_CreatorTime); - return time.Format("yyyy-MM-dd"); - } - return ''; - } + field: 'F_CreatorTime', title: '创建时间', width: 160, filter: { type: 'date[yyyy/MM/dd HH:mm:ss]' } }, { field: 'F_CreatorUserName', title: '创建人', width: 120, sort: true, filter: true }, { title: '操作', width: 130, toolbar: '#currentTableBar', align: "center", fixed: 'right' } diff --git a/WaterCloud.Web/Areas/InfoManage/Views/Message/Index.cshtml b/WaterCloud.Web/Areas/InfoManage/Views/Message/Index.cshtml index fe7eb5ee6e94fb27912646fd971a5549ab8aa662..de5967c512d33637534ecd7a772f77f3de96185c 100644 --- a/WaterCloud.Web/Areas/InfoManage/Views/Message/Index.cshtml +++ b/WaterCloud.Web/Areas/InfoManage/Views/Message/Index.cshtml @@ -63,14 +63,7 @@ { field: 'F_ToUserName', title: '收件人', width: 120, sort: true, filter: true }, { field: 'F_MessageInfo', title: '内容', minWidth: 150, sort: true, filter: true }, { - field: 'F_CreatorTime', title: '创建时间', width: 150, sort: true, filter: { type: 'date[yyyy-MM-dd HH:mm]' }, - templet: function (d) { - if (d.F_CreatorTime) { - var time = new Date(d.F_CreatorTime); - return time.Format("yyyy-MM-dd hh:mm"); - } - return ''; - } + field: 'F_CreatorTime', title: '创建时间', width: 160, sort: true, filter: { type: 'date[yyyy/MM/dd HH:mm:ss]' }, }, { field: 'F_CreatorUserId', title: '创建用户主键', width: 120, sort: true, hide: true, filter: true }, { field: 'F_CreatorUserName', title: '创建用户', width: 120, sort: true, filter: true }, diff --git a/WaterCloud.Web/Areas/SystemManage/Controllers/CodeGeneratorController.cs b/WaterCloud.Web/Areas/SystemManage/Controllers/CodeGeneratorController.cs index 8599994f993bb94a7fe99ee79f0647c18077ba26..ee415cee9754d2727f349fe0d4dbcfc7d58e5974 100644 --- a/WaterCloud.Web/Areas/SystemManage/Controllers/CodeGeneratorController.cs +++ b/WaterCloud.Web/Areas/SystemManage/Controllers/CodeGeneratorController.cs @@ -11,6 +11,7 @@ using WaterCloud.Service; using System.Threading.Tasks; using WaterCloud.Code.Extend; using Chloe; +using WaterCloud.DataBase; namespace WaterCloud.Web.Areas.SystemManage.Controllers { @@ -19,24 +20,24 @@ namespace WaterCloud.Web.Areas.SystemManage.Controllers { private readonly IDatabaseTableService _service; - private readonly IDbContext _context; - public CodeGeneratorController(IDbContext context) + private readonly IUnitOfWork _unitOfWork; + public CodeGeneratorController(IUnitOfWork unitOfWork) { string dbType = GlobalContext.SystemConfig.DBProvider; - _context = context; + _unitOfWork = unitOfWork; switch (dbType) { case Define.DBTYPE_SQLSERVER: - _service = new DatabaseTableSqlServerService(context); + _service = new DatabaseTableSqlServerService(unitOfWork); break; case Define.DBTYPE_MYSQL: - _service = new DatabaseTableMySqlService(context); + _service = new DatabaseTableMySqlService(unitOfWork); break; case Define.DBTYPE_ORACLE: - _service = new DatabaseTableOracleService(context); + _service = new DatabaseTableOracleService(unitOfWork); break; default: - _service = new DatabaseTableMySqlService(context); + _service = new DatabaseTableMySqlService(unitOfWork); break; } } @@ -124,7 +125,7 @@ namespace WaterCloud.Web.Areas.SystemManage.Controllers dic.Add(field); } string serverPath = GlobalContext.HostingEnvironment.ContentRootPath; - data = new SingleTableTemplate(_context).GetBaseConfig(serverPath, _logService.currentuser.UserName, keyValue, tableDescription, dic); + data = new SingleTableTemplate(_unitOfWork).GetBaseConfig(serverPath, _logService.currentuser.UserName, keyValue, tableDescription, dic); return Content(data.ToJson()); } #endregion @@ -138,7 +139,7 @@ namespace WaterCloud.Web.Areas.SystemManage.Controllers try { List list = await _service.GetTableFieldList(baseConfig.TableName); - SingleTableTemplate template = new SingleTableTemplate(_context); + SingleTableTemplate template = new SingleTableTemplate(_unitOfWork); DataTable dt = DataTableHelper.ListToDataTable(list); // 用DataTable类型,避免依赖 string idcolumn = string.Empty; Dictionary dic = new Dictionary(); @@ -223,7 +224,7 @@ namespace WaterCloud.Web.Areas.SystemManage.Controllers } else { - SingleTableTemplate template = new SingleTableTemplate(_context); + SingleTableTemplate template = new SingleTableTemplate(_unitOfWork); await template.CreateCode(baseConfig, HttpUtility.UrlDecode(Code)); } return await Success("操作成功。", "", ""); @@ -246,7 +247,7 @@ namespace WaterCloud.Web.Areas.SystemManage.Controllers else { List list = await _service.GetTableFieldList(baseConfig.TableName); - SingleTableTemplate template = new SingleTableTemplate(_context); + SingleTableTemplate template = new SingleTableTemplate(_unitOfWork); DataTable dt = DataTableHelper.ListToDataTable(list); // 用DataTable类型,避免依赖 string idcolumn = string.Empty; foreach (DataRow dr in dt.Rows) diff --git a/WaterCloud.Web/Areas/SystemManage/Views/Area/Index.cshtml b/WaterCloud.Web/Areas/SystemManage/Views/Area/Index.cshtml index 2a831adfd7083b8e9eda2b088c292ab10bd394bd..3fe494f0f410fbc80cc927e2bd6612df5d1627e3 100644 --- a/WaterCloud.Web/Areas/SystemManage/Views/Area/Index.cshtml +++ b/WaterCloud.Web/Areas/SystemManage/Views/Area/Index.cshtml @@ -65,7 +65,7 @@ } }, { field: 'F_Description', title: '备注', minWidth: 150 }, - { title: '操作', width: 170, toolbar: '#currentTableBar', align: "center" } + { title: '操作', width: 175, toolbar: '#currentTableBar', align: "center" } ]] }); // 监听搜索操作 diff --git a/WaterCloud.Web/Areas/SystemManage/Views/CodeGenerator/Index.cshtml b/WaterCloud.Web/Areas/SystemManage/Views/CodeGenerator/Index.cshtml index 9fdd365070668b9d8a97d515dfad08a26c51e6e2..d4424495a2f1af55ff2ec7d7ebe627e64fb83dd0 100644 --- a/WaterCloud.Web/Areas/SystemManage/Views/CodeGenerator/Index.cshtml +++ b/WaterCloud.Web/Areas/SystemManage/Views/CodeGenerator/Index.cshtml @@ -34,7 +34,7 @@ } }, { field: 'Remark', title: '备注', minWidth: 150 }, - { title: '操作', width: 170, toolbar: '#currentTableBar', align: "center", fixed: 'right' } + { title: '操作', width: 175, toolbar: '#currentTableBar', align: "center", fixed: 'right' } ]] }); // 监听搜索操作 diff --git a/WaterCloud.Web/Areas/SystemManage/Views/CodeGenerator/RuleForm.cshtml b/WaterCloud.Web/Areas/SystemManage/Views/CodeGenerator/RuleForm.cshtml index 08cdbea8fafbf33785c221da2371a7180674f877..68e0b30e1aa61c6aa282eaff9cac0135ecd3cc49 100644 --- a/WaterCloud.Web/Areas/SystemManage/Views/CodeGenerator/RuleForm.cshtml +++ b/WaterCloud.Web/Areas/SystemManage/Views/CodeGenerator/RuleForm.cshtml @@ -171,7 +171,7 @@ - + diff --git a/WaterCloud.Web/Areas/SystemManage/Views/ItemsType/Index.cshtml b/WaterCloud.Web/Areas/SystemManage/Views/ItemsType/Index.cshtml index 58a2ec40f5387c4b9543ff6a51ea3a80ba8d9ab0..21598bd63d0ec4f4682ce161f914368eb2afe219 100644 --- a/WaterCloud.Web/Areas/SystemManage/Views/ItemsType/Index.cshtml +++ b/WaterCloud.Web/Areas/SystemManage/Views/ItemsType/Index.cshtml @@ -45,7 +45,7 @@ } }, { field: 'F_Description', title: '备注', minWidth: 150 }, - { title: '操作', width: 170, toolbar: '#currentTableBar', align: "center", fixed: 'right' } + { title: '操作', width: 175, toolbar: '#currentTableBar', align: "center", fixed: 'right' } ]], }; commonTable.rendertreetable(options); diff --git a/WaterCloud.Web/Areas/SystemManage/Views/Module/Index.cshtml b/WaterCloud.Web/Areas/SystemManage/Views/Module/Index.cshtml index 255fffb310b2f260c781a22a18d1ab403b0ecfb4..bd1eca0de246801979b91f2f06a328331c8fb5db 100644 --- a/WaterCloud.Web/Areas/SystemManage/Views/Module/Index.cshtml +++ b/WaterCloud.Web/Areas/SystemManage/Views/Module/Index.cshtml @@ -97,14 +97,7 @@ }, { field: 'F_SortCode', title: '排序', width: 80, filter: true }, { - field: 'F_CreatorTime', title: '创建时间', width: 120, filter: { type: 'date[yyyy-MM-dd]' }, - templet: function (d) { - if (d.F_CreatorTime) { - var time = new Date(d.F_CreatorTime); - return time.Format("yyyy-MM-dd"); - } - return ''; - } + field: 'F_CreatorTime', title: '创建时间', width: 160, filter: { type: 'date[yyyy/MM/dd HH:mm:ss]' } }, { field: 'F_Description', title: '备注', minWidth: 100, filter: true }, { title: '操作', width: 210, toolbar: '#currentTableBar', align: "center", fixed: 'right' } diff --git a/WaterCloud.Web/Areas/SystemManage/Views/ModuleButton/Index.cshtml b/WaterCloud.Web/Areas/SystemManage/Views/ModuleButton/Index.cshtml index bb66928585e3f76e336adf1789f465cd50ac2a28..6bf728e87247768945977ebe9f7efcee3ccfd350 100644 --- a/WaterCloud.Web/Areas/SystemManage/Views/ModuleButton/Index.cshtml +++ b/WaterCloud.Web/Areas/SystemManage/Views/ModuleButton/Index.cshtml @@ -78,7 +78,7 @@ }, { field: 'F_SortCode', title: '排序', width: 60 }, { field: 'F_Description', title: '备注', minWidth: 100 }, - { title: '操作', width: 170, toolbar: '#currentTableBar', align: "center", fixed: 'right' } + { title: '操作', width: 175, toolbar: '#currentTableBar', align: "center", fixed: 'right' } ]] }); // 监听搜索操作 diff --git a/WaterCloud.Web/Areas/SystemManage/Views/ModuleFields/Index.cshtml b/WaterCloud.Web/Areas/SystemManage/Views/ModuleFields/Index.cshtml index fb23fe9b8b018c001d1e9bd30f1e9937bf83e6e5..16f8b0c23ce1ffe7e8bbfbfc1ad98045cd5dcbd0 100644 --- a/WaterCloud.Web/Areas/SystemManage/Views/ModuleFields/Index.cshtml +++ b/WaterCloud.Web/Areas/SystemManage/Views/ModuleFields/Index.cshtml @@ -96,7 +96,7 @@ } }, { field: 'F_Description', title: '备注', minWidth: 120 }, - { title: '操作', width: 170, toolbar: '#currentTableBar', align: "center", fixed: 'right' } + { title: '操作', width: 175, toolbar: '#currentTableBar', align: "center", fixed: 'right' } ]] }); // 监听搜索操作 diff --git a/WaterCloud.Web/Areas/SystemOrganize/Views/DataPrivilegeRule/Index.cshtml b/WaterCloud.Web/Areas/SystemOrganize/Views/DataPrivilegeRule/Index.cshtml index b56d91c421f824a0bee11d150afc6d0bee9254e2..a22a7c8b4307e61f7ae06954d387a09c42fd2e97 100644 --- a/WaterCloud.Web/Areas/SystemOrganize/Views/DataPrivilegeRule/Index.cshtml +++ b/WaterCloud.Web/Areas/SystemOrganize/Views/DataPrivilegeRule/Index.cshtml @@ -68,14 +68,7 @@ } }, { - field: 'F_CreatorTime', title: '创建时间', width: 120, sort: true, filter: { type: 'date[yyyy-MM-dd]' }, - templet: function (d) { - if (d.F_CreatorTime) { - var time = new Date(d.F_CreatorTime); - return time.Format("yyyy-MM-dd"); - } - return ''; - } + field: 'F_CreatorTime', title: '创建时间', width: 160, sort: true, filter: { type: 'date[yyyy/MM/dd HH:mm:ss]' } }, { field: 'F_Description', title: '备注', minWidth: 150, sort: true, filter: true }, { title: '操作', width: 130, toolbar: '#currentTableBar', align: "center", fixed: 'right' } diff --git a/WaterCloud.Web/Areas/SystemOrganize/Views/Duty/Index.cshtml b/WaterCloud.Web/Areas/SystemOrganize/Views/Duty/Index.cshtml index 63a28fe16caa4a71cccd539118a94bee4d785961..fc8dd4bd0490197c7fdd3de9f879498007897ff3 100644 --- a/WaterCloud.Web/Areas/SystemOrganize/Views/Duty/Index.cshtml +++ b/WaterCloud.Web/Areas/SystemOrganize/Views/Duty/Index.cshtml @@ -37,17 +37,10 @@ } }, { - field: 'F_CreatorTime', title: '创建时间', width: 120, sort: true, filter: { type: 'date[yyyy-MM-dd HH:mm:ss]' }, - templet: function (d) { - if (d.F_CreatorTime) { - var time = new Date(d.F_CreatorTime); - return time.Format("yyyy-MM-dd"); - } - return ''; - } + field: 'F_CreatorTime', title: '创建时间', width: 160, sort: true, filter: { type: 'date[yyyy/MM/dd HH:mm:ss]' } }, { field: 'F_Description', title: '备注', minWidth: 150, sort: true, filter: true }, - { title: '操作', width: 170, toolbar: '#currentTableBar', align: "center", fixed: 'right' } + { title: '操作', width: 175, toolbar: '#currentTableBar', align: "center", fixed: 'right' } ]] }); wcLoading.close(); diff --git a/WaterCloud.Web/Areas/SystemOrganize/Views/Notice/Index.cshtml b/WaterCloud.Web/Areas/SystemOrganize/Views/Notice/Index.cshtml index 0772c27da6194ffcc20c722280524231a5973291..d27936290ab7873c6e01f070e026006fe5013c7a 100644 --- a/WaterCloud.Web/Areas/SystemOrganize/Views/Notice/Index.cshtml +++ b/WaterCloud.Web/Areas/SystemOrganize/Views/Notice/Index.cshtml @@ -38,16 +38,9 @@ field: 'F_CreatorUserName', title: '创建人', Width: 100, sort: true, filter: true, }, { - field: 'F_CreatorTime', title: '创建时间', minWidth: 120, sort: true, filter: { type: 'date[yyyy-MM-dd]' }, - templet: function (d) { - if (d.F_CreatorTime) { - var time = new Date(d.F_CreatorTime); - return time.Format("yyyy-MM-dd"); - } - return ''; - } + field: 'F_CreatorTime', title: '创建时间', minWidth: 160, sort: true, filter: { type: 'date[yyyy/MM/dd HH:mm:ss]' } }, - { title: '操作', width: 170, toolbar: '#currentTableBar', align: "center", fixed: 'right'} + { title: '操作', width: 175, toolbar: '#currentTableBar', align: "center", fixed: 'right'} ]] }); // 监听搜索操作 diff --git a/WaterCloud.Web/Areas/SystemOrganize/Views/Organize/Index.cshtml b/WaterCloud.Web/Areas/SystemOrganize/Views/Organize/Index.cshtml index d3e58bb722afa6ab60fe0495929b6f547024160a..2b94773d3972c5cf24d4cc0074676122558d394d 100644 --- a/WaterCloud.Web/Areas/SystemOrganize/Views/Organize/Index.cshtml +++ b/WaterCloud.Web/Areas/SystemOrganize/Views/Organize/Index.cshtml @@ -40,17 +40,10 @@ } }, { - field: 'F_CreatorTime', title: '创建时间', width: 120,filter: { type: 'date[yyyy-MM-dd]' }, - templet: function (d) { - if (d.F_CreatorTime) { - var time = new Date(d.F_CreatorTime); - return time.Format("yyyy-MM-dd"); - } - return ''; - } + field: 'F_CreatorTime', title: '创建时间', width: 160,filter: { type: 'date[yyyy/MM/dd HH:mm:ss]' } }, { field: 'F_Description', title: '备注', minWidth: 150, filter: true }, - { title: '操作', width: 170, toolbar: '#currentTableBar', align: "center", fixed: 'right' } + { title: '操作', width: 175, toolbar: '#currentTableBar', align: "center", fixed: 'right' } ]], }; commonTable.rendertreetable(options); diff --git a/WaterCloud.Web/Areas/SystemOrganize/Views/Role/Index.cshtml b/WaterCloud.Web/Areas/SystemOrganize/Views/Role/Index.cshtml index c6f5b8bc719715f632d919a6352dbb8fd30d1b1b..6956cd51abf1fd93a8c865884d975aa2b5299dfa 100644 --- a/WaterCloud.Web/Areas/SystemOrganize/Views/Role/Index.cshtml +++ b/WaterCloud.Web/Areas/SystemOrganize/Views/Role/Index.cshtml @@ -54,7 +54,7 @@ } }, { field: 'F_Description', title: '备注', minWidth: 150, sort: true, filter: true }, - { title: '操作', width: 170, toolbar: '#currentTableBar', align: "center", fixed: 'right'} + { title: '操作', width: 175, toolbar: '#currentTableBar', align: "center", fixed: 'right'} ]] }); // 监听搜索操作 diff --git a/WaterCloud.Web/Areas/SystemOrganize/Views/SystemSet/Index.cshtml b/WaterCloud.Web/Areas/SystemOrganize/Views/SystemSet/Index.cshtml index a73273c1c6d14104fe7d15e1c29a9858e4a4bcdd..eed64fc0a51eecaeb086818d0c2e1551bb55a112 100644 --- a/WaterCloud.Web/Areas/SystemOrganize/Views/SystemSet/Index.cshtml +++ b/WaterCloud.Web/Areas/SystemOrganize/Views/SystemSet/Index.cshtml @@ -36,7 +36,7 @@
diff --git a/WaterCloud.Web/Controllers/ClientsDataController.cs b/WaterCloud.Web/Controllers/ClientsDataController.cs index bb31426deb373d75a774ca8704a04a616fe4351a..7b0ebd27fe03835c7d6e813560a2241b9e123366 100644 --- a/WaterCloud.Web/Controllers/ClientsDataController.cs +++ b/WaterCloud.Web/Controllers/ClientsDataController.cs @@ -27,9 +27,7 @@ namespace WaterCloud.Web.Controllers /// /// 缓存操作类 /// - private string cacheKey = "watercloud_quickmoduledata_"; - private string initcacheKey = "watercloud_init_"; - private string cacheKeyOperator = "watercloud_operator_";// +登录者token + private string cacheKeyOperator = GlobalContext.SystemConfig.ProjectPrefix + "_operator_";// +登录者token public QuickModuleService _quickModuleService { get; set; } public NoticeService _noticeService { get; set; } public UserService _userService { get; set; } @@ -110,26 +108,8 @@ namespace WaterCloud.Web.Controllers return null; } var userId = currentuser.UserId; - var data =await CacheHelper.Get>>(cacheKey + "list"); - if (data==null) - { - data = new Dictionary>(); - data.Add(userId,await _quickModuleService.GetQuickModuleList(userId)); - } - else - { - if (data.ContainsKey(userId)) - { - data[userId] =await _quickModuleService.GetQuickModuleList(userId); - } - else - { - data.Add(userId,await _quickModuleService.GetQuickModuleList(userId)); - } - } - await CacheHelper.Remove(cacheKey + "list"); - await CacheHelper.Set(cacheKey + "list", data); - return data[userId]; + var data = await _quickModuleService.GetQuickModuleList(userId); + return data; } /// /// 获取公告信息 @@ -147,32 +127,13 @@ namespace WaterCloud.Web.Controllers [HttpGet] public async Task GetInitDataJson() { - var currentuser = _userService.currentuser; - var userId = currentuser.UserId; + var currentuser = _userService.currentuser; if (currentuser.UserId == null) { return Content(""); } - Dictionary data =await CacheHelper.Get>(initcacheKey + "list"); - if (data == null) - { - data =new Dictionary (); - data.Add(userId, await this.GetMenuListNew()); - } - else - { - if (data.ContainsKey(userId)) - { - data[userId] = await this.GetMenuListNew(); - } - else - { - data.Add(userId, await this.GetMenuListNew()); - } - } - await CacheHelper.Remove(initcacheKey + "list"); - await CacheHelper.Set(initcacheKey + "list",data); - return Content(data[userId]); + var data = await GetMenuListNew(); + return Content(data); } /// /// 获取公告信息请求方法 @@ -214,7 +175,7 @@ namespace WaterCloud.Web.Controllers var data =await this.GetQuickModuleList(); return Content(data.ToJson()); } - catch (Exception) + catch (Exception ex) { return Content(""); } @@ -335,15 +296,14 @@ namespace WaterCloud.Web.Controllers /// /// private async Task GetMenuButtonListNew() - { + { var currentuser = _userService.currentuser; var roleId = currentuser.RoleId; - if (roleId==null&& currentuser.IsSystem) + if (roleId == null && currentuser.IsSystem) { roleId = "admin"; } var rolelist = roleId.Split(','); - Dictionary>> dictionary = await CacheHelper.Get>>>(initcacheKey + "modulebutton_list"); var dictionarylist = new Dictionary>(); if (currentuser.UserId == null) { @@ -361,32 +321,14 @@ namespace WaterCloud.Web.Controllers if (dictionarylist.ContainsKey(item.F_ModuleId)) { dictionarylist[item.F_ModuleId].AddRange(buttonList); - dictionarylist[item.F_ModuleId]= dictionarylist[item.F_ModuleId].GroupBy(p => p.F_Id).Select(q => q.First()).ToList(); + dictionarylist[item.F_ModuleId] = dictionarylist[item.F_ModuleId].GroupBy(p => p.F_Id).Select(q => q.First()).ToList(); } else { dictionarylist.Add(item.F_ModuleId, buttonList); } } - if (dictionary == null) - { - dictionary = new Dictionary>>(); - dictionary.Add(roles, dictionarytemp); - } - else - { - if (dictionary.ContainsKey(roles)) - { - dictionary[roles] = dictionarytemp; - } - else - { - dictionary.Add(roles, dictionarytemp); - } - } } - await CacheHelper.Remove(initcacheKey + "modulebutton_list"); - await CacheHelper.Set(initcacheKey + "modulebutton_list", dictionary); return dictionarylist; } /// @@ -394,7 +336,7 @@ namespace WaterCloud.Web.Controllers /// /// private async Task GetMenuFieldsListNew() - { + { var currentuser = _userService.currentuser; var roleId = currentuser.RoleId; if (roleId == null && currentuser.IsSystem) @@ -402,7 +344,6 @@ namespace WaterCloud.Web.Controllers roleId = "admin"; } var rolelist = roleId.Split(','); - Dictionary>> dictionary = await CacheHelper.Get>>>(initcacheKey + "modulefields_list"); var dictionarylist = new Dictionary>(); if (currentuser.UserId == null) { @@ -427,25 +368,7 @@ namespace WaterCloud.Web.Controllers dictionarylist.Add(item.F_ModuleId, buttonList); } } - if (dictionary == null) - { - dictionary = new Dictionary>>(); - dictionary.Add(roles, dictionarytemp); - } - else - { - if (dictionary.ContainsKey(roles)) - { - dictionary[roles] = dictionarytemp; - } - else - { - dictionary.Add(roles, dictionarytemp); - } - } } - await CacheHelper.Remove(initcacheKey + "modulefields_list"); - await CacheHelper.Set(initcacheKey + "modulefields_list", dictionary); return dictionarylist; } } diff --git a/WaterCloud.Web/Properties/launchSettings.json b/WaterCloud.Web/Properties/launchSettings.json index 1bf1e3e86c193c16e8dd822542ea6eec3d8fe930..2373955a831a00e9a8e290271a7e486433bddd48 100644 --- a/WaterCloud.Web/Properties/launchSettings.json +++ b/WaterCloud.Web/Properties/launchSettings.json @@ -3,8 +3,8 @@ "windowsAuthentication": false, "anonymousAuthentication": true, "iisExpress": { - "applicationUrl": "http://localhost:64629/", - "sslPort": 44315 + "applicationUrl": "http://localhost:58062/", + "sslPort": 44375 } }, "profiles": { diff --git a/WaterCloud.Web/Startup.cs b/WaterCloud.Web/Startup.cs index 009f107e80b447de5e59bfc27ec920df53c690aa..5487950c64f43d40b225b6743934657d0b4f28aa 100644 --- a/WaterCloud.Web/Startup.cs +++ b/WaterCloud.Web/Startup.cs @@ -67,9 +67,8 @@ namespace WaterCloud.Web services.AddSingleton(redisDB1); services.AddSingleton(redisDB2); } - //雪花id初始化,示例IDGenerator.NextId() - var options = new IDGeneratorOptions(ushort.Parse(Configuration.GetSection("SystemConfig:WorkId").Value)); - IDGenerator.SetIdGenerator(options); + //连续guid初始化,示例IDGen.NextId() + services.AddSingleton(); #region 依赖注入 //注入数据库连接 @@ -77,6 +76,7 @@ namespace WaterCloud.Web { return DBContexHelper.Contex(); }); + services.AddScoped(); #region 注入 Quartz调度类 services.AddSingleton(); //注册ISchedulerFactory的实例。 @@ -139,15 +139,16 @@ namespace WaterCloud.Web //更新数据库管理员和主系统 try { - using (var context = DBContexHelper.Contex()) + if (GlobalContext.SystemConfig.ReviseSysem == true) { - var _setService = new Service.SystemOrganize.SystemSetService(context); - Domain.SystemOrganize.SystemSetEntity temp = new Domain.SystemOrganize.SystemSetEntity(); - temp.F_AdminAccount = GlobalContext.SystemConfig.SysemUserCode; - temp.F_AdminPassword = GlobalContext.SystemConfig.SysemUserPwd; - temp.F_DBProvider = GlobalContext.SystemConfig.DBProvider; - temp.F_DbString = GlobalContext.SystemConfig.DBConnectionString; - _setService.SubmitForm(temp, GlobalContext.SystemConfig.SysemMasterProject).GetAwaiter().GetResult(); + using (IUnitOfWork unitOfWork = new UnitOfWork(DBContexHelper.Contex())) + { + var _setService = new Service.SystemOrganize.SystemSetService(unitOfWork); + Domain.SystemOrganize.SystemSetEntity temp = new Domain.SystemOrganize.SystemSetEntity(); + temp.F_AdminAccount = GlobalContext.SystemConfig.SysemUserCode; + temp.F_AdminPassword = GlobalContext.SystemConfig.SysemUserPwd; + _setService.SubmitForm(temp, GlobalContext.SystemConfig.SysemMasterProject).GetAwaiter().GetResult(); + } } } catch (Exception ex) diff --git a/WaterCloud.Web/Views/Home/Index.cshtml b/WaterCloud.Web/Views/Home/Index.cshtml index fbd1f299297beaa6824e5e86fc1dbb37b7b31a34..6a56e72edd6128515f8572250190ea352cf040f4 100644 --- a/WaterCloud.Web/Views/Home/Index.cshtml +++ b/WaterCloud.Web/Views/Home/Index.cshtml @@ -173,7 +173,7 @@ else { $('[data-clear]').parent().remove(); } - code.innerHTML = data.F_Account + ''; + code.innerHTML = data.F_Account + ''; sessionStorage.setItem('currentUser', JSON.stringify(data)); if (data.MsgCout > 0) { $('#noticeMarker').html(''); @@ -216,6 +216,7 @@ }); $('.login-out').on("click", function () { layer.msg('退出登录成功', function () { + window.onbeforeunload(); window.location.href = '../Login/OutLogin'; }); }); diff --git a/WaterCloud.Web/Views/Home/Message.cshtml b/WaterCloud.Web/Views/Home/Message.cshtml index 85415733cc7ca32c0606d981526cc922630a229f..29a7e46ec690aaec0d95281e1418b369602761a3 100644 --- a/WaterCloud.Web/Views/Home/Message.cshtml +++ b/WaterCloud.Web/Views/Home/Message.cshtml @@ -52,7 +52,7 @@ .message-list { position: absolute; top: 48px; - padding: 0px 15px; + padding: 0px 0px; left: 0; right: 0; bottom: 45px; @@ -172,7 +172,9 @@ .show-empty .message-btn-clear, .show-empty .message-list { display: none; } - + body { + margin: 5px 0px 5px 0px; + } /** //消息列表样式结束 */