From 4162e9f08a21317cb0e5df869c75bca7ca6a5135 Mon Sep 17 00:00:00 2001 From: cKey <35512826+colinin@users.noreply.github.com> Date: Wed, 1 Feb 2023 11:55:43 +0800 Subject: [PATCH] Fix multiple issues * Unreference the **Volo.Abp.Json.Newtonsoft** package. * Remove the user history message sql statement. --- aspnet-core/LINGYUN.MicroService.All.sln | 8 + .../LINGYUN.Abp.Location.Baidu.csproj | 2 +- .../Location/Baidu/AbpBaiduLocationModule.cs | 4 +- .../Location/Baidu/BaiduLocationHttpClient.cs | 15 +- .../LINGYUN.Abp.Location.Tencent.csproj | 2 +- .../Tencent/AbpTencentLocationModule.cs | 4 +- .../Tencent/TencentLocationHttpClient.cs | 11 +- .../Chat/EfCoreMessageRepository.cs | 492 +++++++++--------- .../LINGYUN.Platform.Domain.csproj | 2 +- .../LINGYUN.Abp.PushPlus.csproj | 2 +- .../LINGYUN/Abp/PushPlus/AbpPushPlusModule.cs | 2 - .../LINGYUN.Abp.WeChat.csproj | 2 +- .../LINGYUN/Abp/WeChat/AbpWeChatModule.cs | 2 - .../LINGYUN.Abp.WxPusher.csproj | 2 +- .../LINGYUN/Abp/WxPusher/AbpWxPusherModule.cs | 2 - 15 files changed, 272 insertions(+), 280 deletions(-) diff --git a/aspnet-core/LINGYUN.MicroService.All.sln b/aspnet-core/LINGYUN.MicroService.All.sln index ebefea6f9..e4d1eccdc 100644 --- a/aspnet-core/LINGYUN.MicroService.All.sln +++ b/aspnet-core/LINGYUN.MicroService.All.sln @@ -549,6 +549,13 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LINGYUN.Abp.Notifications.H EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LINGYUN.Abp.Localization.Persistence", "modules\localization\LINGYUN.Abp.Localization.Persistence\LINGYUN.Abp.Localization.Persistence.csproj", "{42A0FC3F-C38E-4FF4-B78A-5ED29DF144BF}" EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".github", ".github", "{52E60F16-6304-4E37-A220-C94D8C5D27DC}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "workflows", "workflows", "{F3E04039-7BEE-46F8-B33B-FE13E977DCCA}" + ProjectSection(SolutionItems) = preProject + ..\.github\workflows\release.yml = ..\.github\workflows\release.yml + EndProjectSection +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -1670,6 +1677,7 @@ Global {B153F98A-7DA9-4A12-A1D7-105BE9408FA1} = {1A23BB7F-1839-4204-88C5-7E9A6C9FBF1E} {EFC5C34F-81A1-4EFC-966F-50B646C54FA6} = {1A23BB7F-1839-4204-88C5-7E9A6C9FBF1E} {42A0FC3F-C38E-4FF4-B78A-5ED29DF144BF} = {90E88EAC-4291-4406-8D88-EFDF61B11292} + {F3E04039-7BEE-46F8-B33B-FE13E977DCCA} = {52E60F16-6304-4E37-A220-C94D8C5D27DC} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {C95FDF91-16F2-4A8B-A4BE-0E62D1B66718} diff --git a/aspnet-core/modules/common/LINGYUN.Abp.Location.Baidu/LINGYUN.Abp.Location.Baidu.csproj b/aspnet-core/modules/common/LINGYUN.Abp.Location.Baidu/LINGYUN.Abp.Location.Baidu.csproj index 872228d9a..bf12c4e82 100644 --- a/aspnet-core/modules/common/LINGYUN.Abp.Location.Baidu/LINGYUN.Abp.Location.Baidu.csproj +++ b/aspnet-core/modules/common/LINGYUN.Abp.Location.Baidu/LINGYUN.Abp.Location.Baidu.csproj @@ -18,9 +18,9 @@ + - diff --git a/aspnet-core/modules/common/LINGYUN.Abp.Location.Baidu/LINGYUN/Abp/Location/Baidu/AbpBaiduLocationModule.cs b/aspnet-core/modules/common/LINGYUN.Abp.Location.Baidu/LINGYUN/Abp/Location/Baidu/AbpBaiduLocationModule.cs index 2979d0bfa..8cf5c921e 100644 --- a/aspnet-core/modules/common/LINGYUN.Abp.Location.Baidu/LINGYUN/Abp/Location/Baidu/AbpBaiduLocationModule.cs +++ b/aspnet-core/modules/common/LINGYUN.Abp.Location.Baidu/LINGYUN/Abp/Location/Baidu/AbpBaiduLocationModule.cs @@ -1,8 +1,7 @@ using LINGYUN.Abp.Location.Baidu.Localization; using Microsoft.Extensions.DependencyInjection; using Polly; -using System; -using Volo.Abp.Json.Newtonsoft; +using System; using Volo.Abp.Localization; using Volo.Abp.Modularity; using Volo.Abp.Threading; @@ -12,7 +11,6 @@ namespace LINGYUN.Abp.Location.Baidu { [DependsOn( typeof(AbpLocationModule), - typeof(AbpJsonNewtonsoftModule), typeof(AbpThreadingModule))] public class AbpBaiduLocationModule : AbpModule { diff --git a/aspnet-core/modules/common/LINGYUN.Abp.Location.Baidu/LINGYUN/Abp/Location/Baidu/BaiduLocationHttpClient.cs b/aspnet-core/modules/common/LINGYUN.Abp.Location.Baidu/LINGYUN/Abp/Location/Baidu/BaiduLocationHttpClient.cs index 8a33269a5..51020e09d 100644 --- a/aspnet-core/modules/common/LINGYUN.Abp.Location.Baidu/LINGYUN/Abp/Location/Baidu/BaiduLocationHttpClient.cs +++ b/aspnet-core/modules/common/LINGYUN.Abp.Location.Baidu/LINGYUN/Abp/Location/Baidu/BaiduLocationHttpClient.cs @@ -1,9 +1,10 @@ -using LINGYUN.Abp.Location.Baidu.Response; +using LINGYUN.Abp.Location.Baidu.Localization; +using LINGYUN.Abp.Location.Baidu.Response; using LINGYUN.Abp.Location.Baidu.Utils; -using LINGYUN.Abp.Location.Baidu.Localization; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Localization; using Microsoft.Extensions.Options; +using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Linq; @@ -13,7 +14,6 @@ using System.Threading; using System.Threading.Tasks; using Volo.Abp; using Volo.Abp.DependencyInjection; -using Volo.Abp.Json; using Volo.Abp.Threading; namespace LINGYUN.Abp.Location.Baidu @@ -21,20 +21,17 @@ namespace LINGYUN.Abp.Location.Baidu public class BaiduLocationHttpClient : ITransientDependency { protected BaiduLocationOptions Options { get; } - protected IJsonSerializer JsonSerializer { get; } protected IServiceProvider ServiceProvider { get; } protected IHttpClientFactory HttpClientFactory { get; } protected ICancellationTokenProvider CancellationTokenProvider { get; } public BaiduLocationHttpClient( IOptions options, - IJsonSerializer jsonSerializer, IServiceProvider serviceProvider, IHttpClientFactory httpClientFactory, ICancellationTokenProvider cancellationTokenProvider) { Options = options.Value; - JsonSerializer = jsonSerializer; ServiceProvider = serviceProvider; HttpClientFactory = httpClientFactory; CancellationTokenProvider = cancellationTokenProvider; @@ -58,7 +55,7 @@ namespace LINGYUN.Abp.Location.Baidu } var requestUrl = BuildRequestUrl(baiduMapUrl, baiduMapPath, requestParamters); var responseContent = await MakeRequestAndGetResultAsync(requestUrl); - var baiduLocationResponse = JsonSerializer.Deserialize(responseContent); + var baiduLocationResponse = JsonConvert.DeserializeObject(responseContent); if (!baiduLocationResponse.IsSuccess()) { var localizerFactory = ServiceProvider.GetRequiredService(); @@ -111,7 +108,7 @@ namespace LINGYUN.Abp.Location.Baidu } var requestUrl = BuildRequestUrl(baiduMapUrl, baiduMapPath, requestParamters); var responseContent = await MakeRequestAndGetResultAsync(requestUrl); - var baiduLocationResponse = JsonSerializer.Deserialize(responseContent); + var baiduLocationResponse = JsonConvert.DeserializeObject(responseContent); if (!baiduLocationResponse.IsSuccess()) { var localizerFactory = ServiceProvider.GetRequiredService(); @@ -163,7 +160,7 @@ namespace LINGYUN.Abp.Location.Baidu requestParamters["location"] = string.Format("{0}%2C{1}", lat, lng); var requestUrl = BuildRequestUrl(baiduMapUrl, baiduMapPath, requestParamters); var responseContent = await MakeRequestAndGetResultAsync(requestUrl); - var baiduLocationResponse = JsonSerializer.Deserialize(responseContent); + var baiduLocationResponse = JsonConvert.DeserializeObject(responseContent); if (!baiduLocationResponse.IsSuccess()) { var localizerFactory = ServiceProvider.GetRequiredService(); diff --git a/aspnet-core/modules/common/LINGYUN.Abp.Location.Tencent/LINGYUN.Abp.Location.Tencent.csproj b/aspnet-core/modules/common/LINGYUN.Abp.Location.Tencent/LINGYUN.Abp.Location.Tencent.csproj index 99fe956e9..a77e70f7d 100644 --- a/aspnet-core/modules/common/LINGYUN.Abp.Location.Tencent/LINGYUN.Abp.Location.Tencent.csproj +++ b/aspnet-core/modules/common/LINGYUN.Abp.Location.Tencent/LINGYUN.Abp.Location.Tencent.csproj @@ -18,9 +18,9 @@ + - diff --git a/aspnet-core/modules/common/LINGYUN.Abp.Location.Tencent/LINGYUN/Abp/Location/Tencent/AbpTencentLocationModule.cs b/aspnet-core/modules/common/LINGYUN.Abp.Location.Tencent/LINGYUN/Abp/Location/Tencent/AbpTencentLocationModule.cs index 6e121cc39..118a4923c 100644 --- a/aspnet-core/modules/common/LINGYUN.Abp.Location.Tencent/LINGYUN/Abp/Location/Tencent/AbpTencentLocationModule.cs +++ b/aspnet-core/modules/common/LINGYUN.Abp.Location.Tencent/LINGYUN/Abp/Location/Tencent/AbpTencentLocationModule.cs @@ -1,8 +1,7 @@ using LINGYUN.Abp.Location.Tencent.Localization; using Microsoft.Extensions.DependencyInjection; using Polly; -using System; -using Volo.Abp.Json.Newtonsoft; +using System; using Volo.Abp.Localization; using Volo.Abp.Modularity; using Volo.Abp.Threading; @@ -12,7 +11,6 @@ namespace LINGYUN.Abp.Location.Tencent { [DependsOn( typeof(AbpLocationModule), - typeof(AbpJsonNewtonsoftModule), typeof(AbpThreadingModule))] public class AbpTencentLocationModule : AbpModule { diff --git a/aspnet-core/modules/common/LINGYUN.Abp.Location.Tencent/LINGYUN/Abp/Location/Tencent/TencentLocationHttpClient.cs b/aspnet-core/modules/common/LINGYUN.Abp.Location.Tencent/LINGYUN/Abp/Location/Tencent/TencentLocationHttpClient.cs index 863f04032..1219f9f07 100644 --- a/aspnet-core/modules/common/LINGYUN.Abp.Location.Tencent/LINGYUN/Abp/Location/Tencent/TencentLocationHttpClient.cs +++ b/aspnet-core/modules/common/LINGYUN.Abp.Location.Tencent/LINGYUN/Abp/Location/Tencent/TencentLocationHttpClient.cs @@ -1,9 +1,10 @@ -using LINGYUN.Abp.Location.Tencent.Response; +using LINGYUN.Abp.Location.Tencent.Localization; +using LINGYUN.Abp.Location.Tencent.Response; using LINGYUN.Abp.Location.Tencent.Utils; -using LINGYUN.Abp.Location.Tencent.Localization; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Localization; using Microsoft.Extensions.Options; +using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Linq; @@ -13,7 +14,6 @@ using System.Threading; using System.Threading.Tasks; using Volo.Abp; using Volo.Abp.DependencyInjection; -using Volo.Abp.Json; using Volo.Abp.Threading; namespace LINGYUN.Abp.Location.Tencent @@ -21,20 +21,17 @@ namespace LINGYUN.Abp.Location.Tencent public class TencentLocationHttpClient : ITransientDependency { protected TencentLocationOptions Options { get; } - protected IJsonSerializer JsonSerializer { get; } protected IServiceProvider ServiceProvider { get; } protected IHttpClientFactory HttpClientFactory { get; } protected ICancellationTokenProvider CancellationTokenProvider { get; } public TencentLocationHttpClient( IOptions options, - IJsonSerializer jsonSerializer, IServiceProvider serviceProvider, IHttpClientFactory httpClientFactory, ICancellationTokenProvider cancellationTokenProvider) { Options = options.Value; - JsonSerializer = jsonSerializer; ServiceProvider = serviceProvider; HttpClientFactory = httpClientFactory; CancellationTokenProvider = cancellationTokenProvider; @@ -193,7 +190,7 @@ namespace LINGYUN.Abp.Location.Tencent { var requestUrl = BuildRequestUrl(url, path, paramters); var responseContent = await MakeRequestAndGetResultAsync(requestUrl); - var tencentLocationResponse = JsonSerializer.Deserialize(responseContent); + var tencentLocationResponse = JsonConvert.DeserializeObject(responseContent); if (!tencentLocationResponse.IsSuccessed) { if (Options.VisableErrorToClient) diff --git a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.EntityFrameworkCore/LINGYUN/Abp/MessageService/Chat/EfCoreMessageRepository.cs b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.EntityFrameworkCore/LINGYUN/Abp/MessageService/Chat/EfCoreMessageRepository.cs index 614466f08..3ccdcdbc6 100644 --- a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.EntityFrameworkCore/LINGYUN/Abp/MessageService/Chat/EfCoreMessageRepository.cs +++ b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.EntityFrameworkCore/LINGYUN/Abp/MessageService/Chat/EfCoreMessageRepository.cs @@ -167,263 +167,263 @@ namespace LINGYUN.Abp.MessageService.Chat #region SQL 原型 - var sqlBuilder = new StringBuilder(1280); - sqlBuilder.AppendLine("SELECT"); - sqlBuilder.AppendLine(" msg.* "); - sqlBuilder.AppendLine("FROM"); - sqlBuilder.AppendLine(" ("); - sqlBuilder.AppendLine(" SELECT"); - sqlBuilder.AppendLine(" um.Content,"); - sqlBuilder.AppendLine(" um.CreationTime,"); - sqlBuilder.AppendLine(" um.CreatorId,"); - sqlBuilder.AppendLine(" um.SendUserName,"); - sqlBuilder.AppendLine(" ac.NickName AS Object,"); - sqlBuilder.AppendLine(" ac.AvatarUrl,"); - sqlBuilder.AppendLine(" um.Source,"); - sqlBuilder.AppendLine(" um.MessageId,"); - sqlBuilder.AppendLine(" um.Type,"); - sqlBuilder.AppendLine(" um.TenantId,"); - sqlBuilder.AppendLine(" um.ReceiveUserId,"); - sqlBuilder.AppendLine(" '' AS GroupId,"); - sqlBuilder.AppendLine(" um.ExtraProperties"); - sqlBuilder.AppendLine(" FROM"); - sqlBuilder.AppendLine(" ("); - sqlBuilder.AppendLine(" SELECT"); - sqlBuilder.AppendLine(" um.* "); - sqlBuilder.AppendLine(" FROM"); - sqlBuilder.AppendLine(" appusermessages um"); - sqlBuilder.AppendLine(" INNER JOIN ( SELECT max( um.MessageId ) AS MessageId FROM appusermessages um"); - sqlBuilder.AppendLine(" WHERE"); - sqlBuilder.AppendLine(" um.ReceiveUserId = @ReceiveUserId"); - if (state.HasValue) - { - sqlBuilder.AppendLine(" AND um.State = @State"); - } - if (CurrentTenant.IsAvailable) - { - sqlBuilder.AppendLine(" AND um.TenantId = @TenantId"); - } - sqlBuilder.AppendLine(" GROUP BY um.ReceiveUserId ) gum ON um.MessageId = gum.MessageId"); - sqlBuilder.AppendLine(" ) um"); - sqlBuilder.AppendLine(" LEFT JOIN appuserchatcards ac ON ac.UserId = um.CreatorId "); - sqlBuilder.AppendLine(" UNION ALL"); - sqlBuilder.AppendLine(" SELECT"); - sqlBuilder.AppendLine(" gm.Content,"); - sqlBuilder.AppendLine(" gm.CreationTime,"); - sqlBuilder.AppendLine(" gm.CreatorId,"); - sqlBuilder.AppendLine(" gm.SendUserName,"); - sqlBuilder.AppendLine(" ag.Name AS Object,"); - sqlBuilder.AppendLine(" ag.AvatarUrl,"); - sqlBuilder.AppendLine(" gm.Source,"); - sqlBuilder.AppendLine(" gm.MessageId,"); - sqlBuilder.AppendLine(" gm.Type,"); - sqlBuilder.AppendLine(" gm.TenantId,"); - sqlBuilder.AppendLine(" '' AS ReceiveUserId,"); - sqlBuilder.AppendLine(" gm.GroupId,"); - sqlBuilder.AppendLine(" gm.ExtraProperties"); - sqlBuilder.AppendLine(" FROM"); - sqlBuilder.AppendLine(" appgroupmessages gm"); - sqlBuilder.AppendLine(" INNER JOIN ("); - sqlBuilder.AppendLine(" SELECT"); - sqlBuilder.AppendLine(" max( gm.MessageId ) AS MessageId "); - sqlBuilder.AppendLine(" FROM"); - sqlBuilder.AppendLine(" appuserchatcards ac"); - sqlBuilder.AppendLine(" LEFT JOIN appuserchatgroups acg ON acg.UserId = ac.UserId"); - sqlBuilder.AppendLine(" LEFT JOIN appgroupmessages gm ON gm.GroupId = acg.GroupId "); - sqlBuilder.AppendLine(" WHERE"); - sqlBuilder.AppendLine(" ac.UserId = @ReceiveUserId "); - if (state.HasValue) - { - sqlBuilder.AppendLine(" AND gm.State = @State"); - } - if (CurrentTenant.IsAvailable) - { - sqlBuilder.AppendLine(" AND gm.TenantId = @TenantId"); - } - sqlBuilder.AppendLine(" GROUP BY"); - sqlBuilder.AppendLine(" gm.GroupId"); - sqlBuilder.AppendLine(" ) ggm ON ggm.MessageId = gm.MessageId "); - sqlBuilder.AppendLine(" INNER JOIN appchatgroups ag on ag.GroupId = gm.GroupId"); - sqlBuilder.AppendLine(" ) AS msg"); - sqlBuilder.AppendLine("ORDER BY "); - sqlBuilder.AppendLine(" @Sorting"); - sqlBuilder.AppendLine(" LIMIT @MaxResultCount"); - - using var dbContection = dbContext.Database.GetDbConnection(); - await dbContection.OpenAsync(); - using var command = dbContection.CreateCommand(); - command.Transaction = dbContext.Database.CurrentTransaction?.GetDbTransaction(); - command.CommandText = sqlBuilder.ToString(); - - var receivedUser = command.CreateParameter(); - receivedUser.DbType = System.Data.DbType.Guid; - receivedUser.ParameterName = "@ReceiveUserId"; - receivedUser.Value = userId; - command.Parameters.Add(receivedUser); - - var sorttingParam = command.CreateParameter(); - sorttingParam.DbType = System.Data.DbType.String; - sorttingParam.ParameterName = "@Sorting"; - sorttingParam.Value = sorting; - command.Parameters.Add(sorttingParam); - - var limitParam = command.CreateParameter(); - limitParam.DbType = System.Data.DbType.Int32; - limitParam.ParameterName = "@MaxResultCount"; - limitParam.Value = maxResultCount; - command.Parameters.Add(limitParam); - - if (state.HasValue) - { - var stateParam = command.CreateParameter(); - stateParam.DbType = System.Data.DbType.Int32; - stateParam.ParameterName = "@State"; - stateParam.Value = (int)state.Value; - command.Parameters.Add(stateParam); - } - if (CurrentTenant.IsAvailable) - { - var tenantParam = command.CreateParameter(); - tenantParam.DbType = System.Data.DbType.Guid; - tenantParam.ParameterName = "@TenantId"; - tenantParam.Value = CurrentTenant.Id.Value; - command.Parameters.Add(tenantParam); - } - var messages = new List(); - using var reader = await command.ExecuteReaderAsync(); - - T GetValue(DbDataReader reader, int index) - { - var value = reader.GetValue(index); - if (value == null || value == DBNull.Value) - { - return default; - } + //var sqlBuilder = new StringBuilder(1280); + //sqlBuilder.AppendLine("SELECT"); + //sqlBuilder.AppendLine(" msg.* "); + //sqlBuilder.AppendLine("FROM"); + //sqlBuilder.AppendLine(" ("); + //sqlBuilder.AppendLine(" SELECT"); + //sqlBuilder.AppendLine(" um.Content,"); + //sqlBuilder.AppendLine(" um.CreationTime,"); + //sqlBuilder.AppendLine(" um.CreatorId,"); + //sqlBuilder.AppendLine(" um.SendUserName,"); + //sqlBuilder.AppendLine(" ac.NickName AS Object,"); + //sqlBuilder.AppendLine(" ac.AvatarUrl,"); + //sqlBuilder.AppendLine(" um.Source,"); + //sqlBuilder.AppendLine(" um.MessageId,"); + //sqlBuilder.AppendLine(" um.Type,"); + //sqlBuilder.AppendLine(" um.TenantId,"); + //sqlBuilder.AppendLine(" um.ReceiveUserId,"); + //sqlBuilder.AppendLine(" '' AS GroupId,"); + //sqlBuilder.AppendLine(" um.ExtraProperties"); + //sqlBuilder.AppendLine(" FROM"); + //sqlBuilder.AppendLine(" ("); + //sqlBuilder.AppendLine(" SELECT"); + //sqlBuilder.AppendLine(" um.* "); + //sqlBuilder.AppendLine(" FROM"); + //sqlBuilder.AppendLine(" appusermessages um"); + //sqlBuilder.AppendLine(" INNER JOIN ( SELECT max( um.MessageId ) AS MessageId FROM appusermessages um"); + //sqlBuilder.AppendLine(" WHERE"); + //sqlBuilder.AppendLine(" um.ReceiveUserId = @ReceiveUserId"); + //if (state.HasValue) + //{ + // sqlBuilder.AppendLine(" AND um.State = @State"); + //} + //if (CurrentTenant.IsAvailable) + //{ + // sqlBuilder.AppendLine(" AND um.TenantId = @TenantId"); + //} + //sqlBuilder.AppendLine(" GROUP BY um.ReceiveUserId ) gum ON um.MessageId = gum.MessageId"); + //sqlBuilder.AppendLine(" ) um"); + //sqlBuilder.AppendLine(" LEFT JOIN appuserchatcards ac ON ac.UserId = um.CreatorId "); + //sqlBuilder.AppendLine(" UNION ALL"); + //sqlBuilder.AppendLine(" SELECT"); + //sqlBuilder.AppendLine(" gm.Content,"); + //sqlBuilder.AppendLine(" gm.CreationTime,"); + //sqlBuilder.AppendLine(" gm.CreatorId,"); + //sqlBuilder.AppendLine(" gm.SendUserName,"); + //sqlBuilder.AppendLine(" ag.Name AS Object,"); + //sqlBuilder.AppendLine(" ag.AvatarUrl,"); + //sqlBuilder.AppendLine(" gm.Source,"); + //sqlBuilder.AppendLine(" gm.MessageId,"); + //sqlBuilder.AppendLine(" gm.Type,"); + //sqlBuilder.AppendLine(" gm.TenantId,"); + //sqlBuilder.AppendLine(" '' AS ReceiveUserId,"); + //sqlBuilder.AppendLine(" gm.GroupId,"); + //sqlBuilder.AppendLine(" gm.ExtraProperties"); + //sqlBuilder.AppendLine(" FROM"); + //sqlBuilder.AppendLine(" appgroupmessages gm"); + //sqlBuilder.AppendLine(" INNER JOIN ("); + //sqlBuilder.AppendLine(" SELECT"); + //sqlBuilder.AppendLine(" max( gm.MessageId ) AS MessageId "); + //sqlBuilder.AppendLine(" FROM"); + //sqlBuilder.AppendLine(" appuserchatcards ac"); + //sqlBuilder.AppendLine(" LEFT JOIN appuserchatgroups acg ON acg.UserId = ac.UserId"); + //sqlBuilder.AppendLine(" LEFT JOIN appgroupmessages gm ON gm.GroupId = acg.GroupId "); + //sqlBuilder.AppendLine(" WHERE"); + //sqlBuilder.AppendLine(" ac.UserId = @ReceiveUserId "); + //if (state.HasValue) + //{ + // sqlBuilder.AppendLine(" AND gm.State = @State"); + //} + //if (CurrentTenant.IsAvailable) + //{ + // sqlBuilder.AppendLine(" AND gm.TenantId = @TenantId"); + //} + //sqlBuilder.AppendLine(" GROUP BY"); + //sqlBuilder.AppendLine(" gm.GroupId"); + //sqlBuilder.AppendLine(" ) ggm ON ggm.MessageId = gm.MessageId "); + //sqlBuilder.AppendLine(" INNER JOIN appchatgroups ag on ag.GroupId = gm.GroupId"); + //sqlBuilder.AppendLine(" ) AS msg"); + //sqlBuilder.AppendLine("ORDER BY "); + //sqlBuilder.AppendLine(" @Sorting"); + //sqlBuilder.AppendLine(" LIMIT @MaxResultCount"); + + //using var dbContection = dbContext.Database.GetDbConnection(); + //await dbContection.OpenAsync(); + //using var command = dbContection.CreateCommand(); + //command.Transaction = dbContext.Database.CurrentTransaction?.GetDbTransaction(); + //command.CommandText = sqlBuilder.ToString(); + + //var receivedUser = command.CreateParameter(); + //receivedUser.DbType = System.Data.DbType.Guid; + //receivedUser.ParameterName = "@ReceiveUserId"; + //receivedUser.Value = userId; + //command.Parameters.Add(receivedUser); + + //var sorttingParam = command.CreateParameter(); + //sorttingParam.DbType = System.Data.DbType.String; + //sorttingParam.ParameterName = "@Sorting"; + //sorttingParam.Value = sorting; + //command.Parameters.Add(sorttingParam); + + //var limitParam = command.CreateParameter(); + //limitParam.DbType = System.Data.DbType.Int32; + //limitParam.ParameterName = "@MaxResultCount"; + //limitParam.Value = maxResultCount; + //command.Parameters.Add(limitParam); + + //if (state.HasValue) + //{ + // var stateParam = command.CreateParameter(); + // stateParam.DbType = System.Data.DbType.Int32; + // stateParam.ParameterName = "@State"; + // stateParam.Value = (int)state.Value; + // command.Parameters.Add(stateParam); + //} + //if (CurrentTenant.IsAvailable) + //{ + // var tenantParam = command.CreateParameter(); + // tenantParam.DbType = System.Data.DbType.Guid; + // tenantParam.ParameterName = "@TenantId"; + // tenantParam.Value = CurrentTenant.Id.Value; + // command.Parameters.Add(tenantParam); + //} + //var messages = new List(); + //using var reader = await command.ExecuteReaderAsync(); + + //T GetValue(DbDataReader reader, int index) + //{ + // var value = reader.GetValue(index); + // if (value == null || value == DBNull.Value) + // { + // return default; + // } - var valueType = typeof(T); - var converter = TypeDescriptor.GetConverter(valueType); - if (converter.CanConvertFrom(value.GetType())) - { - return (T)converter.ConvertFrom(value); - } - return (T)Convert.ChangeType(value, typeof(T)); - }; - - ExtraPropertyDictionary GetExtraProperties(DbDataReader reader, int index) - { - var value = reader.GetValue(index); - if (value == null || value == DBNull.Value) - { - return new ExtraPropertyDictionary(); - } - var extraPropertiesAsJson = value.ToString(); - if (extraPropertiesAsJson.IsNullOrEmpty() || extraPropertiesAsJson == "{}") - { - return new ExtraPropertyDictionary(); - } + // var valueType = typeof(T); + // var converter = TypeDescriptor.GetConverter(valueType); + // if (converter.CanConvertFrom(value.GetType())) + // { + // return (T)converter.ConvertFrom(value); + // } + // return (T)Convert.ChangeType(value, typeof(T)); + //}; + + //ExtraPropertyDictionary GetExtraProperties(DbDataReader reader, int index) + //{ + // var value = reader.GetValue(index); + // if (value == null || value == DBNull.Value) + // { + // return new ExtraPropertyDictionary(); + // } + // var extraPropertiesAsJson = value.ToString(); + // if (extraPropertiesAsJson.IsNullOrEmpty() || extraPropertiesAsJson == "{}") + // { + // return new ExtraPropertyDictionary(); + // } - var deserializeOptions = new JsonSerializerOptions(); - deserializeOptions.Converters.Add(new ObjectToInferredTypesConverter()); + // var deserializeOptions = new JsonSerializerOptions(); + // deserializeOptions.Converters.Add(new ObjectToInferredTypesConverter()); - var dictionary = JsonSerializer.Deserialize(extraPropertiesAsJson, deserializeOptions) ?? - new ExtraPropertyDictionary(); + // var dictionary = JsonSerializer.Deserialize(extraPropertiesAsJson, deserializeOptions) ?? + // new ExtraPropertyDictionary(); - return dictionary; - } + // return dictionary; + //} - while (reader.Read()) - { - messages.Add(new LastChatMessage - { - Content = GetValue(reader, 0), - SendTime = GetValue(reader, 1), - FormUserId = GetValue(reader, 2), - FormUserName = GetValue(reader, 3), - Object = GetValue(reader, 4), - AvatarUrl = GetValue(reader, 5), - Source = (MessageSourceType)GetValue(reader, 6), - MessageId = GetValue(reader, 7), - MessageType = (MessageType)GetValue(reader, 8), - TenantId = GetValue(reader, 9), - ToUserId = GetValue(reader, 10), - GroupId = GetValue(reader, 11), - ExtraProperties = GetExtraProperties(reader, 12), - }); - } + //while (reader.Read()) + //{ + // messages.Add(new LastChatMessage + // { + // Content = GetValue(reader, 0), + // SendTime = GetValue(reader, 1), + // FormUserId = GetValue(reader, 2), + // FormUserName = GetValue(reader, 3), + // Object = GetValue(reader, 4), + // AvatarUrl = GetValue(reader, 5), + // Source = (MessageSourceType)GetValue(reader, 6), + // MessageId = GetValue(reader, 7), + // MessageType = (MessageType)GetValue(reader, 8), + // TenantId = GetValue(reader, 9), + // ToUserId = GetValue(reader, 10), + // GroupId = GetValue(reader, 11), + // ExtraProperties = GetExtraProperties(reader, 12), + // }); + //} - return messages; + //return messages; #endregion #region 待 EF 团队解决此问题 //// 聚合用户消息 - //var aggreUserMsgIdQuery = dbContext.Set() - // .Where(msg => msg.ReceiveUserId == userId) - // .WhereIf(state.HasValue, x => x.SendState == state) - // .GroupBy(msg => msg.ReceiveUserId) - // .Select(msg => new - // { - // MessageId = msg.Max(x => x.MessageId) - // }); - //var joinUserMsg = from um in dbContext.Set() - // join aum in aggreUserMsgIdQuery - // on um.MessageId equals aum.MessageId - // join ucc in dbContext.Set() - // on um.CreatorId equals ucc.UserId - // select new LastChatMessage - // { - // Content = um.Content, - // SendTime = um.CreationTime, - // FormUserId = um.CreatorId.Value, - // FormUserName = um.SendUserName, - // Object = ucc.NickName, - // AvatarUrl = ucc.AvatarUrl, - // Source = um.Source, - // MessageId = Convert.ToString(um.MessageId), - // MessageType = um.Type, - // TenantId = um.TenantId, - // // ToUserId = Convert.ToString(um.ReceiveUserId), - // // GroupId = "", - // }; - //// 聚合群组消息 - //var aggreGroupMsgIdQuery = from ucc in dbContext.Set() - // join ucg in dbContext.Set() - // on ucc.UserId equals ucg.UserId - // join gm in dbContext.Set() - // on ucg.GroupId equals gm.GroupId - // where ucc.UserId.Equals(userId) - // group gm by gm.GroupId into ggm - // select new - // { - // MessageId = ggm.Max(gm => gm.MessageId), - // }; - - //var joinGroupMsg = from gm in dbContext.Set() - // join agm in aggreGroupMsgIdQuery - // on gm.MessageId equals agm.MessageId - // join cg in dbContext.Set() - // on gm.GroupId equals cg.GroupId - // select new LastChatMessage - // { - // Content = gm.Content, - // SendTime = gm.CreationTime, - // FormUserId = gm.CreatorId.Value, - // FormUserName = gm.SendUserName, - // Object = cg.Name, - // AvatarUrl = cg.AvatarUrl, - // Source = gm.Source, - // MessageId = Convert.ToString(gm.MessageId), - // MessageType = gm.Type, - // TenantId = gm.TenantId, - // // ToUserId = "", - // // GroupId = Convert.ToString(gm.GroupId) - // }; - - //return await joinUserMsg - // .Concat(joinGroupMsg) - // .OrderBy(sorting) - // .Take(maxResultCount) - // .ToListAsync(GetCancellationToken(cancellationToken)); + var aggreUserMsgIdQuery = dbContext.Set() + .Where(msg => msg.ReceiveUserId == userId) + .WhereIf(state.HasValue, x => x.State == state) + .GroupBy(msg => msg.ReceiveUserId) + .Select(msg => new + { + MessageId = msg.Max(x => x.MessageId) + }); + var joinUserMsg = from um in dbContext.Set() + join aum in aggreUserMsgIdQuery + on um.MessageId equals aum.MessageId + join ucc in dbContext.Set() + on um.CreatorId equals ucc.UserId + select new LastChatMessage + { + Content = Convert.ToString(um.Content), + SendTime = um.CreationTime, + FormUserId = um.CreatorId.Value, + FormUserName = Convert.ToString(um.SendUserName), + Object = Convert.ToString(ucc.NickName), + AvatarUrl = Convert.ToString(ucc.AvatarUrl), + Source = um.Source, + MessageId = Convert.ToString(um.MessageId), + MessageType = um.Type, + TenantId = um.TenantId, + ToUserId = Convert.ToString(um.ReceiveUserId), + GroupId = Convert.ToString(""), + }; + // 聚合群组消息 + var aggreGroupMsgIdQuery = from ucc in dbContext.Set() + join ucg in dbContext.Set() + on ucc.UserId equals ucg.UserId + join gm in dbContext.Set() + on ucg.GroupId equals gm.GroupId + where ucc.UserId.Equals(userId) + group gm by gm.GroupId into ggm + select new + { + MessageId = ggm.Max(gm => gm.MessageId), + }; + + var joinGroupMsg = from gm in dbContext.Set() + join agm in aggreGroupMsgIdQuery + on gm.MessageId equals agm.MessageId + join cg in dbContext.Set() + on gm.GroupId equals cg.GroupId + select new LastChatMessage + { + Content = Convert.ToString(gm.Content), + SendTime = gm.CreationTime, + FormUserId = gm.CreatorId.Value, + FormUserName = Convert.ToString(gm.SendUserName), + Object = Convert.ToString(cg.Name), + AvatarUrl = Convert.ToString(cg.AvatarUrl), + Source = gm.Source, + MessageId = Convert.ToString(gm.MessageId), + MessageType = gm.Type, + TenantId = gm.TenantId, + ToUserId = Convert.ToString(""), + GroupId = Convert.ToString(gm.GroupId) + }; + + return await joinUserMsg + .Concat(joinGroupMsg) + .OrderBy(sorting) + .Take(maxResultCount) + .ToListAsync(GetCancellationToken(cancellationToken)); #endregion diff --git a/aspnet-core/modules/platform/LINGYUN.Platform.Domain/LINGYUN.Platform.Domain.csproj b/aspnet-core/modules/platform/LINGYUN.Platform.Domain/LINGYUN.Platform.Domain.csproj index 60a5ecba1..597e146df 100644 --- a/aspnet-core/modules/platform/LINGYUN.Platform.Domain/LINGYUN.Platform.Domain.csproj +++ b/aspnet-core/modules/platform/LINGYUN.Platform.Domain/LINGYUN.Platform.Domain.csproj @@ -9,11 +9,11 @@ + - diff --git a/aspnet-core/modules/pushplus/LINGYUN.Abp.PushPlus/LINGYUN.Abp.PushPlus.csproj b/aspnet-core/modules/pushplus/LINGYUN.Abp.PushPlus/LINGYUN.Abp.PushPlus.csproj index 6de1f3879..133e126df 100644 --- a/aspnet-core/modules/pushplus/LINGYUN.Abp.PushPlus/LINGYUN.Abp.PushPlus.csproj +++ b/aspnet-core/modules/pushplus/LINGYUN.Abp.PushPlus/LINGYUN.Abp.PushPlus.csproj @@ -18,7 +18,7 @@ - + diff --git a/aspnet-core/modules/pushplus/LINGYUN.Abp.PushPlus/LINGYUN/Abp/PushPlus/AbpPushPlusModule.cs b/aspnet-core/modules/pushplus/LINGYUN.Abp.PushPlus/LINGYUN/Abp/PushPlus/AbpPushPlusModule.cs index 02272f61e..2d3b64148 100644 --- a/aspnet-core/modules/pushplus/LINGYUN.Abp.PushPlus/LINGYUN/Abp/PushPlus/AbpPushPlusModule.cs +++ b/aspnet-core/modules/pushplus/LINGYUN.Abp.PushPlus/LINGYUN/Abp/PushPlus/AbpPushPlusModule.cs @@ -2,7 +2,6 @@ using LINGYUN.Abp.PushPlus.Localization; using Microsoft.Extensions.DependencyInjection; using Volo.Abp.Caching; -using Volo.Abp.Json.Newtonsoft; using Volo.Abp.Localization; using Volo.Abp.Modularity; using Volo.Abp.Settings; @@ -11,7 +10,6 @@ using Volo.Abp.VirtualFileSystem; namespace LINGYUN.Abp.PushPlus; [DependsOn( - typeof(AbpJsonNewtonsoftModule), typeof(AbpSettingsModule), typeof(AbpCachingModule), typeof(AbpFeaturesLimitValidationModule))] diff --git a/aspnet-core/modules/wechat/LINGYUN.Abp.WeChat/LINGYUN.Abp.WeChat.csproj b/aspnet-core/modules/wechat/LINGYUN.Abp.WeChat/LINGYUN.Abp.WeChat.csproj index 0c38e32af..696105297 100644 --- a/aspnet-core/modules/wechat/LINGYUN.Abp.WeChat/LINGYUN.Abp.WeChat.csproj +++ b/aspnet-core/modules/wechat/LINGYUN.Abp.WeChat/LINGYUN.Abp.WeChat.csproj @@ -19,7 +19,7 @@ - + diff --git a/aspnet-core/modules/wechat/LINGYUN.Abp.WeChat/LINGYUN/Abp/WeChat/AbpWeChatModule.cs b/aspnet-core/modules/wechat/LINGYUN.Abp.WeChat/LINGYUN/Abp/WeChat/AbpWeChatModule.cs index 5d1ea6f6f..95788bec2 100644 --- a/aspnet-core/modules/wechat/LINGYUN.Abp.WeChat/LINGYUN/Abp/WeChat/AbpWeChatModule.cs +++ b/aspnet-core/modules/wechat/LINGYUN.Abp.WeChat/LINGYUN/Abp/WeChat/AbpWeChatModule.cs @@ -3,7 +3,6 @@ using Microsoft.Extensions.DependencyInjection; using System; using Volo.Abp.Caching; using Volo.Abp.Features; -using Volo.Abp.Json.Newtonsoft; using Volo.Abp.Localization; using Volo.Abp.Modularity; using Volo.Abp.Settings; @@ -14,7 +13,6 @@ namespace LINGYUN.Abp.WeChat [DependsOn( typeof(AbpCachingModule), typeof(AbpFeaturesModule), - typeof(AbpJsonNewtonsoftModule), typeof(AbpSettingsModule))] public class AbpWeChatModule : AbpModule { diff --git a/aspnet-core/modules/wx-pusher/LINGYUN.Abp.WxPusher/LINGYUN.Abp.WxPusher.csproj b/aspnet-core/modules/wx-pusher/LINGYUN.Abp.WxPusher/LINGYUN.Abp.WxPusher.csproj index aa35fe450..097da6615 100644 --- a/aspnet-core/modules/wx-pusher/LINGYUN.Abp.WxPusher/LINGYUN.Abp.WxPusher.csproj +++ b/aspnet-core/modules/wx-pusher/LINGYUN.Abp.WxPusher/LINGYUN.Abp.WxPusher.csproj @@ -18,7 +18,7 @@ - + diff --git a/aspnet-core/modules/wx-pusher/LINGYUN.Abp.WxPusher/LINGYUN/Abp/WxPusher/AbpWxPusherModule.cs b/aspnet-core/modules/wx-pusher/LINGYUN.Abp.WxPusher/LINGYUN/Abp/WxPusher/AbpWxPusherModule.cs index 918dd87fc..68fb05d30 100644 --- a/aspnet-core/modules/wx-pusher/LINGYUN.Abp.WxPusher/LINGYUN/Abp/WxPusher/AbpWxPusherModule.cs +++ b/aspnet-core/modules/wx-pusher/LINGYUN.Abp.WxPusher/LINGYUN/Abp/WxPusher/AbpWxPusherModule.cs @@ -4,7 +4,6 @@ using LINGYUN.Abp.WxPusher.User; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection.Extensions; using Volo.Abp.Caching; -using Volo.Abp.Json.Newtonsoft; using Volo.Abp.Localization; using Volo.Abp.Modularity; using Volo.Abp.Settings; @@ -13,7 +12,6 @@ using Volo.Abp.VirtualFileSystem; namespace LINGYUN.Abp.WxPusher; [DependsOn( - typeof(AbpJsonNewtonsoftModule), typeof(AbpSettingsModule), typeof(AbpCachingModule), typeof(AbpFeaturesLimitValidationModule))]