merge from 2023-03-14
This commit is contained in:
449
common/Tnb.Common.Core/Handlers/IMHandler.cs
Normal file
449
common/Tnb.Common.Core/Handlers/IMHandler.cs
Normal file
@@ -0,0 +1,449 @@
|
||||
using System.Net.WebSockets;
|
||||
using JNPF.Common.Configuration;
|
||||
using JNPF.Common.Const;
|
||||
using JNPF.Common.Enums;
|
||||
using JNPF.Common.Extension;
|
||||
using JNPF.Common.Manager;
|
||||
using JNPF.Common.Models.User;
|
||||
using JNPF.Common.Options;
|
||||
using JNPF.Common.Security;
|
||||
using JNPF.DataEncryption;
|
||||
using JNPF.Extras.WebSockets.Models;
|
||||
using JNPF.Message.Entitys;
|
||||
using JNPF.Message.Entitys.Dto.IM;
|
||||
using JNPF.Message.Entitys.Entity;
|
||||
using JNPF.Message.Entitys.Enums;
|
||||
using JNPF.Message.Entitys.Model.IM;
|
||||
using JNPF.RemoteRequest.Extensions;
|
||||
using JNPF.Systems.Entitys.Permission;
|
||||
using JNPF.WebSockets;
|
||||
using Mapster;
|
||||
using SqlSugar;
|
||||
|
||||
namespace JNPF.Common.Core.Handlers;
|
||||
|
||||
/// <summary>
|
||||
/// IM 处理程序.
|
||||
/// </summary>
|
||||
public class IMHandler : WebSocketHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// SqlSugarClient客户端.
|
||||
/// </summary>
|
||||
private static SqlSugarScope? _sqlSugarClient;
|
||||
|
||||
/// <summary>
|
||||
/// 缓存管理.
|
||||
/// </summary>
|
||||
private readonly ICacheManager _cacheManager;
|
||||
|
||||
private readonly MessageOptions _messageOptions = App.GetConfig<MessageOptions>("Message", true);
|
||||
|
||||
/// <summary>
|
||||
/// 初始化一个<see cref="IMHandler"/>类型的新实例.
|
||||
/// </summary>
|
||||
public IMHandler(
|
||||
WebSocketConnectionManager webSocketConnectionManager,
|
||||
ISqlSugarClient sqlSugarClient,
|
||||
ICacheManager cacheManager)
|
||||
: base(webSocketConnectionManager)
|
||||
{
|
||||
_sqlSugarClient = (SqlSugarScope)sqlSugarClient;
|
||||
_cacheManager = cacheManager;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 消息接收.
|
||||
/// </summary>
|
||||
/// <param name="client"></param>
|
||||
/// <param name="result"></param>
|
||||
/// <param name="receivedMessage"></param>
|
||||
/// <returns></returns>
|
||||
public override async Task ReceiveAsync(WebSocketClient client, WebSocketReceiveResult result, string receivedMessage)
|
||||
{
|
||||
try
|
||||
{
|
||||
MessageInput? message = receivedMessage.ToObject<MessageInput>();
|
||||
var claims = JWTEncryption.ReadJwtToken(message.token.Replace("Bearer ", string.Empty).Replace("bearer ", string.Empty))?.Claims;
|
||||
client.UserId = claims.FirstOrDefault(e => e.Type == ClaimConst.CLAINMUSERID)?.Value;
|
||||
client.ConnectionConfig = claims.FirstOrDefault(e => e.Type == ClaimConst.CONNECTIONCONFIG)?.Value.ToObject<ConnectionConfigOptions>();
|
||||
client.Account = claims.FirstOrDefault(e => e.Type == ClaimConst.CLAINMACCOUNT)?.Value;
|
||||
client.UserName = claims.FirstOrDefault(e => e.Type == ClaimConst.CLAINMREALNAME)?.Value;
|
||||
client.SingleLogin = (LoginMethod)Enum.Parse(typeof(LoginMethod), claims.FirstOrDefault(e => e.Type == ClaimConst.SINGLELOGIN)?.Value);
|
||||
client.LoginTime = string.Format("{0:yyyy-MM-dd HH:mm}", string.Format("{0}000", claims.FirstOrDefault(e => e.Type == "iat")?.Value).TimeStampToDateTime());
|
||||
client.LoginIpAddress = client.LoginIpAddress;
|
||||
client.Token = message.token;
|
||||
client.IsMobileDevice = message.mobileDevice;
|
||||
if (client.WebSocket.State != WebSocketState.Open) return;
|
||||
await OnConnected(client.ConnectionId, client);
|
||||
WebSocketConnectionManager.AddToTenant(client.ConnectionId, client.ConnectionConfig?.ConfigId);
|
||||
WebSocketConnectionManager.AddToUser(client.ConnectionId, string.Format("{0}-{1}", client.ConnectionConfig?.ConfigId, client.UserId));
|
||||
message.sendClientId = client.ConnectionId;
|
||||
await MessageRoute(message);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 消息通道.
|
||||
/// </summary>
|
||||
/// <param name="message"></param>
|
||||
private async Task MessageRoute(MessageInput message)
|
||||
{
|
||||
WebSocketClient client = WebSocketConnectionManager.GetSocketById(message.sendClientId);
|
||||
if (string.IsNullOrEmpty(client.UserId))
|
||||
{
|
||||
await SendMessageAsync(client.ConnectionId, new { method = "logout" }.ToJsonString());
|
||||
return;
|
||||
}
|
||||
|
||||
// 判断ORM内是否存在该连接
|
||||
if (!_sqlSugarClient.IsAnyConnection(client.ConnectionConfig.ConfigId))
|
||||
{
|
||||
_sqlSugarClient.AddConnection(JNPFTenantExtensions.GetConfig(client.ConnectionConfig));
|
||||
_sqlSugarClient.Ado.CommandTimeOut = 10;
|
||||
}
|
||||
|
||||
// 当前数据连接ConfigId是否等于目标库ConfigId
|
||||
if (_sqlSugarClient.CurrentConnectionConfig.ConfigId != client.ConnectionConfig.ConfigId)
|
||||
{
|
||||
_sqlSugarClient.ChangeDatabase(client.ConnectionConfig.ConfigId);
|
||||
}
|
||||
|
||||
// 验证连接是否成功
|
||||
if (!_sqlSugarClient.Ado.IsValidConnection())
|
||||
{
|
||||
await OnDisconnected(client.WebSocket);
|
||||
return;
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(client.HeadIcon))
|
||||
{
|
||||
UserEntity userEntity = await _sqlSugarClient.Queryable<UserEntity>().SingleAsync(it => it.Id == client.UserId);
|
||||
if (userEntity != null)
|
||||
{
|
||||
client.HeadIcon = "/api/file/Image/userAvatar/" + userEntity.HeadIcon;
|
||||
await OnConnected(client.ConnectionId, client);
|
||||
}
|
||||
}
|
||||
|
||||
switch (message.method)
|
||||
{
|
||||
// 建立连接
|
||||
case MothodType.OnConnection:
|
||||
{
|
||||
List<UserOnlineModel> list = await GetOnlineUserList(client.ConnectionConfig.ConfigId);
|
||||
if (list == null)
|
||||
{
|
||||
list = new List<UserOnlineModel>();
|
||||
}
|
||||
|
||||
switch (client.SingleLogin)
|
||||
{
|
||||
case LoginMethod.Single:
|
||||
{
|
||||
UserOnlineModel? user = list.Find(it => it.userId.Equals(client.UserId) && it.isMobileDevice.Equals(client.IsMobileDevice));
|
||||
if (user == null)
|
||||
{
|
||||
list.Add(new UserOnlineModel()
|
||||
{
|
||||
connectionId = client.ConnectionId,
|
||||
userId = client.UserId,
|
||||
account = client.Account,
|
||||
userName = client.UserName,
|
||||
lastTime = DateTime.Now,
|
||||
lastLoginIp = client.LoginIpAddress,
|
||||
tenantId = client.ConnectionConfig.ConfigId,
|
||||
lastLoginPlatForm = client.LoginPlatForm,
|
||||
isMobileDevice = client.IsMobileDevice,
|
||||
token = message.token
|
||||
});
|
||||
await SetOnlineUserList(client.ConnectionConfig.ConfigId, list);
|
||||
}
|
||||
|
||||
// 不同浏览器
|
||||
else if (user != null && !user.token.Equals(message.token))
|
||||
{
|
||||
var onlineUser = WebSocketConnectionManager.GetSocketById(user.connectionId);
|
||||
if (onlineUser != null)
|
||||
await SendMessageAsync(onlineUser.ConnectionId, new { method = MessageSendType.logout.ToString(), msg = "此账号已在其他地方登陆" }.ToJsonString());
|
||||
list.RemoveAll((x) => x.connectionId == user.connectionId);
|
||||
|
||||
list.Add(new UserOnlineModel()
|
||||
{
|
||||
connectionId = client.ConnectionId,
|
||||
userId = client.UserId,
|
||||
account = client.Account,
|
||||
userName = client.UserName,
|
||||
lastTime = DateTime.Now,
|
||||
lastLoginIp = client.LoginIpAddress,
|
||||
tenantId = client.ConnectionConfig.ConfigId,
|
||||
lastLoginPlatForm = client.LoginPlatForm,
|
||||
isMobileDevice = client.IsMobileDevice,
|
||||
token = message.token
|
||||
});
|
||||
await SetOnlineUserList(client.ConnectionConfig.ConfigId, list);
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
case LoginMethod.SameTime:
|
||||
{
|
||||
UserOnlineModel? user = list.Find(it => it.token.Equals(message.token));
|
||||
if (user != null)
|
||||
{
|
||||
WebSocketClient? onlineUser = WebSocketConnectionManager.GetSocketById(user.connectionId);
|
||||
if (onlineUser != null)
|
||||
await SendMessageAsync(onlineUser.ConnectionId, new { method = MessageSendType.closeSocket.ToString() }.ToJsonString());
|
||||
list.RemoveAll((x) => x.connectionId == user.connectionId);
|
||||
}
|
||||
|
||||
list.Add(new UserOnlineModel()
|
||||
{
|
||||
connectionId = client.ConnectionId,
|
||||
userId = client.UserId,
|
||||
account = client.Account,
|
||||
userName = client.UserName,
|
||||
lastTime = DateTime.Now,
|
||||
lastLoginIp = client.LoginIpAddress,
|
||||
tenantId = client.ConnectionConfig.ConfigId,
|
||||
lastLoginPlatForm = client.LoginPlatForm,
|
||||
isMobileDevice = client.IsMobileDevice,
|
||||
token = message.token
|
||||
});
|
||||
await SetOnlineUserList(client.ConnectionConfig.ConfigId, list);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
var onlineUserList = GetAllUserIdFromTenant(client.ConnectionConfig.ConfigId);
|
||||
|
||||
// 获取接收者为当前用户的聊天且未读的信息
|
||||
var imContentList = _sqlSugarClient.Queryable<IMContentEntity>().Where(x => x.ReceiveUserId.Equals(client.UserId) && x.State.Equals(0) && (SqlFunc.IsNullOrEmpty(x.SendDeleteMark) || x.SendDeleteMark != client.UserId)).GroupBy(x => new { x.SendUserId, x.ReceiveUserId }).Select(x => new IMContentEntity
|
||||
{
|
||||
State = SqlFunc.AggregateSum(SqlFunc.IIF(x.State == 0, 1, 0)),
|
||||
SendUserId = x.SendUserId,
|
||||
ReceiveUserId = x.ReceiveUserId
|
||||
}).ToList();
|
||||
|
||||
var receiveList = _sqlSugarClient.Queryable<IMContentEntity>().Where(x => x.ReceiveUserId == client.UserId && (SqlFunc.IsNullOrEmpty(x.SendDeleteMark) || x.SendDeleteMark != client.UserId)).OrderBy(x => x.SendTime, OrderByType.Desc).ToList();
|
||||
var unreadNums = imContentList.Adapt<List<IMUnreadNumModel>>();
|
||||
foreach (var item in unreadNums)
|
||||
{
|
||||
var entity = receiveList.FirstOrDefault(x => x.SendUserId == item.sendUserId);
|
||||
item.defaultMessage = entity?.Content;
|
||||
item.defaultMessageType = entity?.ContentType;
|
||||
item.defaultMessageTime = entity?.SendTime.ToString();
|
||||
}
|
||||
var unreadNoticeCount = await _sqlSugarClient.Queryable<MessageEntity, MessageReceiveEntity>((m, mr) => new JoinQueryInfos(JoinType.Left, m.Id == mr.MessageId)).Where((m, mr) => m.Type == 1 && m.DeleteMark == null && mr.UserId == client.UserId && mr.IsRead == 0).Select((m, mr) => new { mr.Id, mr.UserId, mr.IsRead, m.Type, m.DeleteMark }).CountAsync();
|
||||
var unreadMessageCount = await _sqlSugarClient.Queryable<MessageEntity, MessageReceiveEntity>((m, mr) => new JoinQueryInfos(JoinType.Left, m.Id == mr.MessageId)).Select((m, mr) => new { mr.Id, mr.UserId, mr.IsRead, m.Type, m.DeleteMark }).MergeTable().Where(x => x.Type == 2 && x.DeleteMark == null && x.UserId == client.UserId && x.IsRead == 0).CountAsync();
|
||||
var messageDefault = await _sqlSugarClient.Queryable<MessageEntity>().Where(x => x.DeleteMark == null && x.EnabledMark == 1).OrderBy(x => x.CreatorTime, OrderByType.Desc).FirstAsync();
|
||||
var messageDefaultText = messageDefault == null ? string.Empty : messageDefault.Title;
|
||||
var messageDefaultTime = messageDefault == null ? DateTime.Now : messageDefault.CreatorTime;
|
||||
await SendMessageAsync(client.ConnectionId, new { method = MessageSendType.initMessage.ToString(), onlineUserList, unreadNums, unreadNoticeCount, unreadMessageCount, messageDefaultText, messageDefaultTime }.ToJsonString());
|
||||
|
||||
await SendMessageToTenantAsync(client.ConnectionConfig.ConfigId, new { method = MessageSendType.online.ToString(), userId = client.UserId }.ToJsonString(), client.ConnectionId);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
// 发送消息
|
||||
case MothodType.SendMessage:
|
||||
{
|
||||
string toUserId = message.toUserId;
|
||||
MessageReceiveType messageType = message.messageType;
|
||||
object messageContent = message.messageContent;
|
||||
string fileName = string.Empty;
|
||||
|
||||
var toUserEntity = await _sqlSugarClient.Queryable<UserEntity>().SingleAsync(it => it.Id == toUserId);
|
||||
|
||||
// 将发送消息对象信息补全
|
||||
var toAccount = toUserEntity.Account;
|
||||
var toHeadIcon = toUserEntity.HeadIcon;
|
||||
var toRealName = toUserEntity.RealName;
|
||||
|
||||
var entity = new IMContentEntity();
|
||||
var toMessage = new object();
|
||||
switch (messageType)
|
||||
{
|
||||
case MessageReceiveType.text:
|
||||
entity = CreateIMContent(client.UserId, toUserId, messageContent.ToString(), messageType.ToString());
|
||||
break;
|
||||
case MessageReceiveType.image:
|
||||
{
|
||||
var directoryPath = FileVariable.IMContentFilePath;
|
||||
if (!Directory.Exists(directoryPath))
|
||||
Directory.CreateDirectory(directoryPath);
|
||||
var imageInput = messageContent.ToObject<MessagetImageInput>();
|
||||
fileName = fileName = imageInput.name;
|
||||
|
||||
toMessage = new { path = "/api/file/Image/IM/" + fileName, width = imageInput.width, height = imageInput.height };
|
||||
|
||||
entity = CreateIMContent(client.UserId, toUserId, toMessage.ToJsonString(), messageType.ToString());
|
||||
}
|
||||
|
||||
break;
|
||||
case MessageReceiveType.voice:
|
||||
var voiceInput = messageContent.ToObject<MessageVoiceInput>();
|
||||
toMessage = new { path = "/api/file/Image/IM/" + voiceInput.name, length = voiceInput.length };
|
||||
entity = CreateIMContent(client.UserId, toUserId, toMessage.ToJsonString(), messageType.ToString());
|
||||
break;
|
||||
}
|
||||
|
||||
// 写入到会话表中
|
||||
if (await _sqlSugarClient.Queryable<ImReplyEntity>().AnyAsync(it => it.UserId == client.UserId && it.ReceiveUserId == toUserId))
|
||||
{
|
||||
var imReplyEntity = await _sqlSugarClient.Queryable<ImReplyEntity>().SingleAsync(it => it.UserId == client.UserId && it.ReceiveUserId == toUserId);
|
||||
imReplyEntity.ReceiveTime = entity.SendTime;
|
||||
await _sqlSugarClient.Updateable(imReplyEntity).ExecuteCommandAsync();
|
||||
}
|
||||
else
|
||||
{
|
||||
var imReplyEntity = new ImReplyEntity()
|
||||
{
|
||||
Id = SnowflakeIdHelper.NextId(),
|
||||
UserId = client.UserId,
|
||||
ReceiveUserId = toUserId,
|
||||
ReceiveTime = entity.SendTime
|
||||
};
|
||||
await _sqlSugarClient.Insertable(imReplyEntity).ExecuteCommandAsync();
|
||||
}
|
||||
|
||||
await _sqlSugarClient.Insertable(entity).ExecuteCommandAsync();
|
||||
|
||||
switch (messageType)
|
||||
{
|
||||
case MessageReceiveType.text:
|
||||
await SendMessageAsync(client.ConnectionId, new { method = MessageSendType.sendMessage.ToString(), client.UserId, account = client.Account, headIcon = client.HeadIcon, realName = client.UserName, toAccount, toHeadIcon, messageType = messageType.ToString(), toUserId, toRealName, toMessage = messageContent, dateTime = DateTime.Now, latestDate = DateTime.Now }.ToJsonString());
|
||||
break;
|
||||
case MessageReceiveType.image:
|
||||
var imageInput = messageContent.ToObject<MessagetImageInput>();
|
||||
toMessage = new { path = "/api/file/Image/IM/" + fileName, width = imageInput.width, height = imageInput.height };
|
||||
await SendMessageAsync(client.ConnectionId, new { method = MessageSendType.sendMessage.ToString(), client.UserId, account = client.Account, headIcon = client.HeadIcon, realName = client.UserName, toAccount, toHeadIcon, messageType = messageType.ToString(), toUserId, toMessage, dateTime = DateTime.Now, latestDate = DateTime.Now }.ToJsonString());
|
||||
break;
|
||||
case MessageReceiveType.voice:
|
||||
var voiceInput = messageContent.ToObject<MessageVoiceInput>();
|
||||
toMessage = new { path = "/api/file/Image/IM/" + voiceInput.name, length = voiceInput.length };
|
||||
await SendMessageAsync(client.ConnectionId, new { method = MessageSendType.sendMessage.ToString(), client.UserId, account = client.Account, headIcon = client.HeadIcon, realName = client.UserName, toAccount, toHeadIcon, messageType = messageType.ToString(), toUserId, toMessage, dateTime = DateTime.Now }.ToJsonString());
|
||||
break;
|
||||
}
|
||||
|
||||
if (WebSocketConnectionManager.GetSocketClientToUserCount(string.Format("{0}-{1}", client.ConnectionConfig.ConfigId, toUserId)) > 0)
|
||||
{
|
||||
switch (messageType)
|
||||
{
|
||||
case MessageReceiveType.text:
|
||||
await SendMessageToUserAsync(string.Format("{0}-{1}", client.ConnectionConfig.ConfigId, toUserId), new { method = MessageSendType.receiveMessage.ToString(), messageType = messageType.ToString(), formUserId = client.UserId, formMessage = messageContent, dateTime = DateTime.Now, latestDate = DateTime.Now, headIcon = client.HeadIcon, realName = client.UserName, account = client.Account }.ToJsonString());
|
||||
break;
|
||||
case MessageReceiveType.image:
|
||||
var imageInput = messageContent.ToObject<MessagetImageInput>();
|
||||
var formMessage = new { path = "/api/file/Image/IM/" + fileName, width = imageInput.width, height = imageInput.height };
|
||||
await SendMessageToUserAsync(string.Format("{0}-{1}", client.ConnectionConfig.ConfigId, toUserId), new { method = MessageSendType.receiveMessage.ToString(), messageType = messageType.ToString(), formUserId = client.UserId, formMessage, dateTime = DateTime.Now, latestDate = DateTime.Now, headIcon = client.HeadIcon, realName = client.UserName, account = client.Account }.ToJsonString());
|
||||
break;
|
||||
case MessageReceiveType.voice:
|
||||
var voiceInput = messageContent.ToObject<MessageVoiceInput>();
|
||||
toMessage = new { path = "/api/file/Image/IM/" + voiceInput.name, length = voiceInput.length };
|
||||
await SendMessageToUserAsync(string.Format("{0}-{1}", client.ConnectionConfig.ConfigId, toUserId), new { method = MessageSendType.receiveMessage.ToString(), messageType = messageType.ToString(), formUserId = client.UserId, formMessage = toMessage, dateTime = DateTime.Now, latestDate = DateTime.Now, headIcon = client.HeadIcon, realName = client.UserName, account = client.Account }.ToJsonString());
|
||||
break;
|
||||
}
|
||||
}
|
||||
await GeTuiMessage(toUserId, client);
|
||||
}
|
||||
|
||||
break;
|
||||
case MothodType.UpdateReadMessage:
|
||||
var fromUserId = message.formUserId;
|
||||
await _sqlSugarClient.Updateable<IMContentEntity>()
|
||||
.SetColumns(x => new IMContentEntity()
|
||||
{
|
||||
State = 1,
|
||||
ReceiveTime = DateTime.Now
|
||||
}).Where(x => x.State == 0 && x.SendUserId == fromUserId && x.ReceiveUserId == client.UserId).ExecuteCommandAsync();
|
||||
break;
|
||||
case MothodType.MessageList:
|
||||
var sendUserId = message.toUserId; // 发送者
|
||||
var receiveUserId = message.formUserId; // 接收者
|
||||
|
||||
var data = await _sqlSugarClient.Queryable<IMContentEntity>().WhereIF(!string.IsNullOrEmpty(message.keyword), it => it.Content.Contains(message.keyword))
|
||||
.Where(i => (i.SendUserId == message.toUserId && i.ReceiveUserId == message.formUserId) || (i.SendUserId == message.formUserId && i.ReceiveUserId == message.toUserId) && (SqlFunc.IsNullOrEmpty(i.SendDeleteMark) || i.SendDeleteMark != client.UserId)).OrderBy(it => it.SendTime, message.sord == "asc" ? OrderByType.Asc : OrderByType.Desc)
|
||||
.Select(it => new IMContentListOutput
|
||||
{
|
||||
id = it.Id,
|
||||
sendUserId = it.SendUserId,
|
||||
sendTime = it.SendTime,
|
||||
receiveUserId = it.ReceiveUserId,
|
||||
receiveTime = it.ReceiveTime,
|
||||
content = it.Content,
|
||||
contentType = it.ContentType,
|
||||
state = it.State
|
||||
}).ToPagedListAsync(message.currentPage, message.pageSize);
|
||||
|
||||
await SendMessageAsync(client.ConnectionId, new { method = MessageSendType.messageList.ToString(), list = data.list.OrderBy(x => x.sendTime), pagination = data.pagination }.ToJsonString());
|
||||
break;
|
||||
case MothodType.HeartCheck: break;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取在线用户列表.
|
||||
/// </summary>
|
||||
/// <param name="tenantId">租户ID.</param>
|
||||
/// <returns></returns>
|
||||
public async Task<List<UserOnlineModel>> GetOnlineUserList(string tenantId)
|
||||
{
|
||||
string cacheKey = string.Format("{0}{1}", CommonConst.CACHEKEYONLINEUSER, tenantId);
|
||||
return await _cacheManager.GetAsync<List<UserOnlineModel>>(cacheKey);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 保存在线用户列表.
|
||||
/// </summary>
|
||||
/// <param name="tenantId">租户ID.</param>
|
||||
/// <param name="onlineList">在线用户列表.</param>
|
||||
/// <returns></returns>
|
||||
public async Task<bool> SetOnlineUserList(string tenantId, List<UserOnlineModel> onlineList)
|
||||
{
|
||||
return await _cacheManager.SetAsync(string.Format("{0}{1}", CommonConst.CACHEKEYONLINEUSER, tenantId), onlineList);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建IM内容.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
private IMContentEntity CreateIMContent(string sendUserId, string receiveUserId, string message, string messageType)
|
||||
{
|
||||
return new IMContentEntity()
|
||||
{
|
||||
Id = SnowflakeIdHelper.NextId(),
|
||||
SendUserId = sendUserId,
|
||||
SendTime = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")),
|
||||
ReceiveUserId = receiveUserId,
|
||||
State = 0,
|
||||
Content = message,
|
||||
ContentType = messageType
|
||||
};
|
||||
}
|
||||
|
||||
private async Task GeTuiMessage(string toUserIds, WebSocketClient client)
|
||||
{
|
||||
var getuiUrl = "{0}?clientId={1}&title={2}&content={3}1&text={4}&create=true";
|
||||
if (toUserIds.Any())
|
||||
{
|
||||
var clientIdList = await _sqlSugarClient.Queryable<UserDeviceEntity>().Where(x => toUserIds==x.UserId && x.DeleteMark == null).Select(x => x.ClientId).ToListAsync();
|
||||
if (clientIdList.Any())
|
||||
{
|
||||
var clientId = string.Join(",", clientIdList);
|
||||
var textDic = new Dictionary<string, string>();
|
||||
textDic.Add("type", "3");
|
||||
textDic.Add("name", client.UserName+"/"+ client.Account);
|
||||
textDic.Add("formUserId", client.UserId);
|
||||
textDic.Add("headIcon", "/api/File/Image/userAvatar/" + client.HeadIcon);
|
||||
getuiUrl = string.Format(getuiUrl, _messageOptions.AppPushUrl, clientId, client.UserName + "/" + client.Account, "您有一条新消息", textDic.ToJsonString());
|
||||
await getuiUrl.GetAsStringAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -13,7 +13,6 @@ using JNPF.Systems.Entitys.Permission;
|
||||
using JNPF.Systems.Entitys.System;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using SqlSugar;
|
||||
using System.Net.Http;
|
||||
using System.Security.Claims;
|
||||
|
||||
namespace JNPF.Common.Core.Manager;
|
||||
@@ -206,7 +205,7 @@ public class UserManager : IUserManager, IScoped
|
||||
UserAgent userAgent = new UserAgent(_httpContext);
|
||||
var data = new UserInfoModel();
|
||||
var ipAddress = NetHelper.Ip;
|
||||
//var ipAddressName = await NetHelper.GetLocation(ipAddress);
|
||||
var ipAddressName = await NetHelper.GetLocation(ipAddress);
|
||||
var userDataScope = await GetUserDataScopeAsync(UserId);
|
||||
var sysConfigInfo = await _repository.AsSugarClient().Queryable<SysConfigEntity>().FirstAsync(s => s.Category.Equals("SysConfig") && s.Key.ToLower().Equals("tokentimeout"));
|
||||
data = await _repository.AsQueryable().Where(it => it.Id == UserId)
|
||||
@@ -252,8 +251,8 @@ public class UserManager : IUserManager, IScoped
|
||||
data.loginTime = DateTime.Now;
|
||||
data.prevLogin = (await _repository.AsSugarClient().Queryable<SysConfigEntity>().FirstAsync(x => x.Category.Equals("SysConfig") && x.Key.ToLower().Equals("lastlogintimeswitch"))).Value.ParseToInt();
|
||||
data.loginIPAddress = ipAddress;
|
||||
//data.loginIPAddressName = ipAddressName;
|
||||
//data.prevLoginIPAddressName = await NetHelper.GetLocation(data.prevLoginIPAddress);
|
||||
data.loginIPAddressName = ipAddressName;
|
||||
data.prevLoginIPAddressName = await NetHelper.GetLocation(data.prevLoginIPAddress);
|
||||
data.loginPlatForm = userAgent.RawValue;
|
||||
data.subsidiary = await GetSubsidiaryAsync(data.organizeId, data.isAdministrator);
|
||||
data.subordinates = await this.GetSubordinatesAsync(UserId);
|
||||
@@ -501,11 +500,13 @@ public class UserManager : IUserManager, IScoped
|
||||
var itemValue = fieldItem.Value;
|
||||
var itemMethod = (QueryType)System.Enum.Parse(typeof(QueryType), fieldItem.Op);
|
||||
|
||||
var cmodel = GetConditionalModel(itemMethod, itemField, User.OrganizeId);
|
||||
if (itemMethod.Equals(QueryType.Equal)) cmodel.ConditionalType = ConditionalType.Like;
|
||||
if (itemMethod.Equals(QueryType.NotEqual)) cmodel.ConditionalType = ConditionalType.NoLike;
|
||||
switch (itemValue)
|
||||
{
|
||||
case "@userId": // 当前用户
|
||||
{
|
||||
var cmodel = GetConditionalModel(itemMethod, itemField, userInfo.userId);
|
||||
switch (conditionItem.Logic)
|
||||
{
|
||||
case "and":
|
||||
@@ -524,17 +525,29 @@ public class UserManager : IUserManager, IScoped
|
||||
{
|
||||
var ids = new List<string>() { userInfo.userId };
|
||||
ids.AddRange(userInfo.subordinates);
|
||||
var cmodel = GetConditionalModel(itemMethod, itemField, string.Join(",", ids));
|
||||
switch (conditionItem.Logic)
|
||||
for (int i = 0; i < ids.Count; i++)
|
||||
{
|
||||
case "and":
|
||||
conditionalList.Add(new { Key = (int)WhereType.And, Value = new { FieldName = itemField, FieldValue = string.Join(",", ids), ConditionalType = (int)cmodel.ConditionalType } });
|
||||
if (i == 0)
|
||||
{
|
||||
switch (conditionItem.Logic)
|
||||
{
|
||||
case "and":
|
||||
conditionalList.Add(new { Key = (int)WhereType.And, Value = new { FieldName = itemField, FieldValue = ids[i], ConditionalType = (int)cmodel.ConditionalType } });
|
||||
|
||||
break;
|
||||
case "or":
|
||||
conditionalList.Add(new { Key = (int)WhereType.Or, Value = new { FieldName = itemField, FieldValue = string.Join(",", ids), ConditionalType = (int)cmodel.ConditionalType } });
|
||||
break;
|
||||
case "or":
|
||||
conditionalList.Add(new { Key = (int)WhereType.Or, Value = new { FieldName = itemField, FieldValue = ids[i], ConditionalType = (int)cmodel.ConditionalType } });
|
||||
|
||||
break;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (itemMethod.Equals(QueryType.NotEqual) || itemMethod.Equals(QueryType.NotIncluded))
|
||||
conditionalList.Add(new { Key = (int)WhereType.And, Value = new { FieldName = itemField, FieldValue = ids[i], ConditionalType = (int)cmodel.ConditionalType } });
|
||||
else
|
||||
conditionalList.Add(new { Key = (int)WhereType.Or, Value = new { FieldName = itemField, FieldValue = ids[i], ConditionalType = (int)cmodel.ConditionalType } });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -543,7 +556,6 @@ public class UserManager : IUserManager, IScoped
|
||||
{
|
||||
if (!string.IsNullOrEmpty(userInfo.organizeId))
|
||||
{
|
||||
var cmodel = GetConditionalModel(itemMethod, itemField, userInfo.organizeId);
|
||||
switch (conditionItem.Logic)
|
||||
{
|
||||
case "and":
|
||||
@@ -554,7 +566,6 @@ public class UserManager : IUserManager, IScoped
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
break;
|
||||
@@ -564,17 +575,29 @@ public class UserManager : IUserManager, IScoped
|
||||
{
|
||||
var ids = new List<string>() { userInfo.organizeId };
|
||||
ids.AddRange(userInfo.subsidiary);
|
||||
var cmodel = GetConditionalModel(itemMethod, itemField, string.Join(",", ids));
|
||||
switch (conditionItem.Logic)
|
||||
for (int i = 0; i < ids.Count; i++)
|
||||
{
|
||||
case "and":
|
||||
conditionalList.Add(new { Key = (int)WhereType.And, Value = new { FieldName = itemField, FieldValue = string.Join(",", ids), ConditionalType = (int)cmodel.ConditionalType } });
|
||||
if (i == 0)
|
||||
{
|
||||
switch (conditionItem.Logic)
|
||||
{
|
||||
case "and":
|
||||
conditionalList.Add(new { Key = (int)WhereType.And, Value = new { FieldName = itemField, FieldValue = ids[i], ConditionalType = (int)cmodel.ConditionalType } });
|
||||
|
||||
break;
|
||||
case "or":
|
||||
conditionalList.Add(new { Key = (int)WhereType.Or, Value = new { FieldName = itemField, FieldValue = string.Join(",", ids), ConditionalType = (int)cmodel.ConditionalType } });
|
||||
break;
|
||||
case "or":
|
||||
conditionalList.Add(new { Key = (int)WhereType.Or, Value = new { FieldName = itemField, FieldValue = ids[i], ConditionalType = (int)cmodel.ConditionalType } });
|
||||
|
||||
break;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (itemMethod.Equals(QueryType.NotEqual) || itemMethod.Equals(QueryType.NotIncluded))
|
||||
conditionalList.Add(new { Key = (int)WhereType.And, Value = new { FieldName = itemField, FieldValue = ids[i], ConditionalType = (int)cmodel.ConditionalType } });
|
||||
else
|
||||
conditionalList.Add(new { Key = (int)WhereType.Or, Value = new { FieldName = itemField, FieldValue = ids[i], ConditionalType = (int)cmodel.ConditionalType } });
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -583,43 +606,79 @@ public class UserManager : IUserManager, IScoped
|
||||
|
||||
case "@branchManageOrganize": // 当前分管组织
|
||||
{
|
||||
var orgId = DataScope.Where(x => x.Select).Select(x => x.organizeId).ToList();
|
||||
if (orgId != null)
|
||||
var ids = DataScope.Where(x => x.Select).Select(x => x.organizeId).ToList();
|
||||
if (ids != null)
|
||||
{
|
||||
var cmodel = GetConditionalModel(itemMethod, itemField, string.Join(",", orgId));
|
||||
switch (conditionItem.Logic)
|
||||
for (int i = 0; i < ids.Count; i++)
|
||||
{
|
||||
case "and":
|
||||
conditionalList.Add(new { Key = (int)WhereType.And, Value = new { FieldName = itemField, FieldValue = string.Join(",", orgId), ConditionalType = (int)cmodel.ConditionalType } });
|
||||
break;
|
||||
case "or":
|
||||
conditionalList.Add(new { Key = (int)WhereType.Or, Value = new { FieldName = itemField, FieldValue = string.Join(",", orgId), ConditionalType = (int)cmodel.ConditionalType } });
|
||||
break;
|
||||
if (i == 0)
|
||||
{
|
||||
switch (conditionItem.Logic)
|
||||
{
|
||||
case "and":
|
||||
conditionalList.Add(new { Key = (int)WhereType.And, Value = new { FieldName = itemField, FieldValue = ids[i], ConditionalType = (int)cmodel.ConditionalType } });
|
||||
|
||||
break;
|
||||
case "or":
|
||||
conditionalList.Add(new { Key = (int)WhereType.Or, Value = new { FieldName = itemField, FieldValue = ids[i], ConditionalType = (int)cmodel.ConditionalType } });
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (itemMethod.Equals(QueryType.NotEqual) || itemMethod.Equals(QueryType.NotIncluded))
|
||||
conditionalList.Add(new { Key = (int)WhereType.And, Value = new { FieldName = itemField, FieldValue = ids[i], ConditionalType = (int)cmodel.ConditionalType } });
|
||||
else
|
||||
conditionalList.Add(new { Key = (int)WhereType.Or, Value = new { FieldName = itemField, FieldValue = ids[i], ConditionalType = (int)cmodel.ConditionalType } });
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
conditionalList.Add(new { Key = (int)WhereType.Or, Value = new { FieldName = itemField, FieldValue = "jnpf", ConditionalType = (int)ConditionalType.Equal } });
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case "@branchManageOrganizeAndSub": // 当前分管组织及子组织
|
||||
{
|
||||
var subOrgIds = new List<string>();
|
||||
var ids = new List<string>();
|
||||
DataScope.Where(x => x.Select).Select(x => x.organizeId).ToList()
|
||||
.ForEach(item => subOrgIds.AddRange(_repository.AsSugarClient().Queryable<OrganizeEntity>().Where(x => x.OrganizeIdTree.Contains(item)).Select(x => x.Id).ToList()));
|
||||
.ForEach(item => ids.AddRange(_repository.AsSugarClient().Queryable<OrganizeEntity>().Where(x => x.OrganizeIdTree.Contains(item)).Select(x => x.Id).ToList()));
|
||||
|
||||
if (subOrgIds.Any())
|
||||
if (ids.Any())
|
||||
{
|
||||
var cmodel = GetConditionalModel(itemMethod, itemField, string.Join(",", subOrgIds));
|
||||
switch (conditionItem.Logic)
|
||||
for (int i = 0; i < ids.Count; i++)
|
||||
{
|
||||
case "and":
|
||||
conditionalList.Add(new { Key = (int)WhereType.And, Value = new { FieldName = itemField, FieldValue = string.Join(",", subOrgIds), ConditionalType = (int)cmodel.ConditionalType } });
|
||||
break;
|
||||
case "or":
|
||||
conditionalList.Add(new { Key = (int)WhereType.Or, Value = new { FieldName = itemField, FieldValue = string.Join(",", subOrgIds), ConditionalType = (int)cmodel.ConditionalType } });
|
||||
break;
|
||||
if (i == 0)
|
||||
{
|
||||
switch (conditionItem.Logic)
|
||||
{
|
||||
case "and":
|
||||
conditionalList.Add(new { Key = (int)WhereType.And, Value = new { FieldName = itemField, FieldValue = ids[i], ConditionalType = (int)cmodel.ConditionalType } });
|
||||
|
||||
break;
|
||||
case "or":
|
||||
conditionalList.Add(new { Key = (int)WhereType.Or, Value = new { FieldName = itemField, FieldValue = ids[i], ConditionalType = (int)cmodel.ConditionalType } });
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (itemMethod.Equals(QueryType.NotEqual) || itemMethod.Equals(QueryType.NotIncluded))
|
||||
conditionalList.Add(new { Key = (int)WhereType.And, Value = new { FieldName = itemField, FieldValue = ids[i], ConditionalType = (int)cmodel.ConditionalType } });
|
||||
else
|
||||
conditionalList.Add(new { Key = (int)WhereType.Or, Value = new { FieldName = itemField, FieldValue = ids[i], ConditionalType = (int)cmodel.ConditionalType } });
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
conditionalList.Add(new { Key = (int)WhereType.Or, Value = new { FieldName = itemField, FieldValue = "jnpf", ConditionalType = (int)ConditionalType.Equal } });
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
@@ -628,9 +687,9 @@ public class UserManager : IUserManager, IScoped
|
||||
{
|
||||
if (!string.IsNullOrEmpty(itemValue))
|
||||
{
|
||||
var cmodel = GetConditionalModel(itemMethod, itemField, itemValue, fieldItem.Type);
|
||||
if (cmodel.ConditionalType.Equals(ConditionalType.In)) cmodel.ConditionalType = ConditionalType.Like;
|
||||
if (cmodel.ConditionalType.Equals(ConditionalType.NotIn)) cmodel.ConditionalType = ConditionalType.NoLike;
|
||||
var defCmodel = GetConditionalModel(itemMethod, itemField, itemValue, fieldItem.Type);
|
||||
if (defCmodel.ConditionalType.Equals(ConditionalType.In)) defCmodel.ConditionalType = ConditionalType.Like;
|
||||
if (defCmodel.ConditionalType.Equals(ConditionalType.NotIn)) defCmodel.ConditionalType = ConditionalType.NoLike;
|
||||
switch (conditionItem.Logic)
|
||||
{
|
||||
case "and":
|
||||
@@ -646,6 +705,8 @@ public class UserManager : IUserManager, IScoped
|
||||
|
||||
break;
|
||||
}
|
||||
if (itemMethod.Equals(QueryType.NotEqual) || itemMethod.Equals(QueryType.NotIncluded))
|
||||
conditionalList.Add(new { Key = (int)WhereType.Or, Value = new { FieldName = itemField, FieldValue = string.Empty, ConditionalType = ConditionalType.IsNullOrEmpty } });
|
||||
}
|
||||
|
||||
if (conditionalList.Any())
|
||||
@@ -749,19 +810,21 @@ public class UserManager : IUserManager, IScoped
|
||||
var itemValue = fieldItem.Value;
|
||||
var itemMethod = (QueryType)System.Enum.Parse(typeof(QueryType), fieldItem.Op);
|
||||
|
||||
var cmodel = GetConditionalModel(itemMethod, itemField, User.OrganizeId);
|
||||
if (itemMethod.Equals(QueryType.Equal)) cmodel.ConditionalType = ConditionalType.Like;
|
||||
if (itemMethod.Equals(QueryType.NotEqual)) cmodel.ConditionalType = ConditionalType.NoLike;
|
||||
switch (itemValue)
|
||||
{
|
||||
case "@userId": // 当前用户
|
||||
{
|
||||
var cmodel = GetConditionalModel(itemMethod, itemField, userInfo.userId);
|
||||
switch (conditionItem.Logic)
|
||||
{
|
||||
case "and":
|
||||
conditionalList.Add(new { Key = (int)WhereType.And, Value = new { FieldName = itemField, FieldValue = userInfo.userId, ConditionalType = (int)cmodel.ConditionalType } });
|
||||
conditionalList.Add(new { Key = (int)WhereType.And, Value = new { FieldName = itemField, FieldValue = UserId, ConditionalType = (int)cmodel.ConditionalType } });
|
||||
|
||||
break;
|
||||
case "or":
|
||||
conditionalList.Add(new { Key = (int)WhereType.Or, Value = new { FieldName = itemField, FieldValue = userInfo.userId, ConditionalType = (int)cmodel.ConditionalType } });
|
||||
conditionalList.Add(new { Key = (int)WhereType.Or, Value = new { FieldName = itemField, FieldValue = UserId, ConditionalType = (int)cmodel.ConditionalType } });
|
||||
|
||||
break;
|
||||
}
|
||||
@@ -770,59 +833,81 @@ public class UserManager : IUserManager, IScoped
|
||||
break;
|
||||
case "@userAraSubordinates": // 当前用户集下属
|
||||
{
|
||||
var ids = new List<string>() { userInfo.userId };
|
||||
ids.AddRange(userInfo.subordinates);
|
||||
var cmodel = GetConditionalModel(itemMethod, itemField, string.Join(",", ids));
|
||||
switch (conditionItem.Logic)
|
||||
var ids = new List<string>() { UserId };
|
||||
ids.AddRange(Subordinates);
|
||||
for (int i = 0; i < ids.Count; i++)
|
||||
{
|
||||
case "and":
|
||||
conditionalList.Add(new { Key = (int)WhereType.And, Value = new { FieldName = itemField, FieldValue = string.Join(",", ids), ConditionalType = (int)cmodel.ConditionalType } });
|
||||
if (i == 0)
|
||||
{
|
||||
switch (conditionItem.Logic)
|
||||
{
|
||||
case "and":
|
||||
conditionalList.Add(new { Key = (int)WhereType.And, Value = new { FieldName = itemField, FieldValue = ids[i], ConditionalType = (int)cmodel.ConditionalType } });
|
||||
|
||||
break;
|
||||
case "or":
|
||||
conditionalList.Add(new { Key = (int)WhereType.Or, Value = new { FieldName = itemField, FieldValue = string.Join(",", ids), ConditionalType = (int)cmodel.ConditionalType } });
|
||||
break;
|
||||
case "or":
|
||||
conditionalList.Add(new { Key = (int)WhereType.Or, Value = new { FieldName = itemField, FieldValue = ids[i], ConditionalType = (int)cmodel.ConditionalType } });
|
||||
|
||||
break;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (itemMethod.Equals(QueryType.NotEqual) || itemMethod.Equals(QueryType.NotIncluded))
|
||||
conditionalList.Add(new { Key = (int)WhereType.And, Value = new { FieldName = itemField, FieldValue = ids[i], ConditionalType = (int)cmodel.ConditionalType } });
|
||||
else
|
||||
conditionalList.Add(new { Key = (int)WhereType.Or, Value = new { FieldName = itemField, FieldValue = ids[i], ConditionalType = (int)cmodel.ConditionalType } });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
case "@organizeId": // 当前组织
|
||||
{
|
||||
if (!string.IsNullOrEmpty(userInfo.organizeId))
|
||||
if (!string.IsNullOrEmpty(User.OrganizeId))
|
||||
{
|
||||
var cmodel = GetConditionalModel(itemMethod, itemField, userInfo.organizeId);
|
||||
switch (conditionItem.Logic)
|
||||
{
|
||||
case "and":
|
||||
conditionalList.Add(new { Key = (int)WhereType.And, Value = new { FieldName = itemField, FieldValue = userInfo.organizeId, ConditionalType = (int)cmodel.ConditionalType } });
|
||||
conditionalList.Add(new { Key = (int)WhereType.And, Value = new { FieldName = itemField, FieldValue = User.OrganizeId, ConditionalType = (int)cmodel.ConditionalType } });
|
||||
break;
|
||||
case "or":
|
||||
conditionalList.Add(new { Key = (int)WhereType.Or, Value = new { FieldName = itemField, FieldValue = userInfo.organizeId, ConditionalType = (int)cmodel.ConditionalType } });
|
||||
conditionalList.Add(new { Key = (int)WhereType.Or, Value = new { FieldName = itemField, FieldValue = User.OrganizeId, ConditionalType = (int)cmodel.ConditionalType } });
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
break;
|
||||
case "@organizationAndSuborganization": // 当前组织及子组织
|
||||
{
|
||||
if (!string.IsNullOrEmpty(userInfo.organizeId))
|
||||
if (!string.IsNullOrEmpty(User.OrganizeId))
|
||||
{
|
||||
var ids = new List<string>() { userInfo.organizeId };
|
||||
ids.AddRange(userInfo.subsidiary);
|
||||
var cmodel = GetConditionalModel(itemMethod, itemField, string.Join(",", ids));
|
||||
switch (conditionItem.Logic)
|
||||
var ids = new List<string>() { User.OrganizeId };
|
||||
ids.AddRange(Subsidiary);
|
||||
for (int i = 0; i < ids.Count; i++)
|
||||
{
|
||||
case "and":
|
||||
conditionalList.Add(new { Key = (int)WhereType.And, Value = new { FieldName = itemField, FieldValue = string.Join(",", ids), ConditionalType = (int)cmodel.ConditionalType } });
|
||||
if (i == 0)
|
||||
{
|
||||
switch (conditionItem.Logic)
|
||||
{
|
||||
case "and":
|
||||
conditionalList.Add(new { Key = (int)WhereType.And, Value = new { FieldName = itemField, FieldValue = ids[i], ConditionalType = (int)cmodel.ConditionalType } });
|
||||
|
||||
break;
|
||||
case "or":
|
||||
conditionalList.Add(new { Key = (int)WhereType.Or, Value = new { FieldName = itemField, FieldValue = string.Join(",", ids), ConditionalType = (int)cmodel.ConditionalType } });
|
||||
break;
|
||||
case "or":
|
||||
conditionalList.Add(new { Key = (int)WhereType.Or, Value = new { FieldName = itemField, FieldValue = ids[i], ConditionalType = (int)cmodel.ConditionalType } });
|
||||
|
||||
break;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (itemMethod.Equals(QueryType.NotEqual) || itemMethod.Equals(QueryType.NotIncluded))
|
||||
conditionalList.Add(new { Key = (int)WhereType.And, Value = new { FieldName = itemField, FieldValue = ids[i], ConditionalType = (int)cmodel.ConditionalType } });
|
||||
else
|
||||
conditionalList.Add(new { Key = (int)WhereType.Or, Value = new { FieldName = itemField, FieldValue = ids[i], ConditionalType = (int)cmodel.ConditionalType } });
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -831,18 +916,32 @@ public class UserManager : IUserManager, IScoped
|
||||
|
||||
case "@branchManageOrganize": // 当前分管组织
|
||||
{
|
||||
var orgId = DataScope.Where(x => x.Select).Select(x => x.organizeId).ToList();
|
||||
if (orgId != null)
|
||||
var ids = DataScope.Where(x => x.Select).Select(x => x.organizeId).ToList();
|
||||
if (ids != null)
|
||||
{
|
||||
var cmodel = GetConditionalModel(itemMethod, itemField, string.Join(",", orgId));
|
||||
switch (conditionItem.Logic)
|
||||
for (int i = 0; i < ids.Count; i++)
|
||||
{
|
||||
case "and":
|
||||
conditionalList.Add(new { Key = (int)WhereType.And, Value = new { FieldName = itemField, FieldValue = string.Join(",", orgId), ConditionalType = (int)cmodel.ConditionalType } });
|
||||
break;
|
||||
case "or":
|
||||
conditionalList.Add(new { Key = (int)WhereType.Or, Value = new { FieldName = itemField, FieldValue = string.Join(",", orgId), ConditionalType = (int)cmodel.ConditionalType } });
|
||||
break;
|
||||
if (i == 0)
|
||||
{
|
||||
switch (conditionItem.Logic)
|
||||
{
|
||||
case "and":
|
||||
conditionalList.Add(new { Key = (int)WhereType.And, Value = new { FieldName = itemField, FieldValue = ids[i], ConditionalType = (int)cmodel.ConditionalType } });
|
||||
|
||||
break;
|
||||
case "or":
|
||||
conditionalList.Add(new { Key = (int)WhereType.Or, Value = new { FieldName = itemField, FieldValue = ids[i], ConditionalType = (int)cmodel.ConditionalType } });
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (itemMethod.Equals(QueryType.NotEqual) || itemMethod.Equals(QueryType.NotIncluded))
|
||||
conditionalList.Add(new { Key = (int)WhereType.And, Value = new { FieldName = itemField, FieldValue = ids[i], ConditionalType = (int)cmodel.ConditionalType } });
|
||||
else
|
||||
conditionalList.Add(new { Key = (int)WhereType.Or, Value = new { FieldName = itemField, FieldValue = ids[i], ConditionalType = (int)cmodel.ConditionalType } });
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -855,21 +954,35 @@ public class UserManager : IUserManager, IScoped
|
||||
|
||||
case "@branchManageOrganizeAndSub": // 当前分管组织及子组织
|
||||
{
|
||||
var subOrgIds = new List<string>();
|
||||
var ids = new List<string>();
|
||||
DataScope.Where(x => x.Select).Select(x => x.organizeId).ToList()
|
||||
.ForEach(item => subOrgIds.AddRange(_repository.AsSugarClient().Queryable<OrganizeEntity>().Where(x => x.OrganizeIdTree.Contains(item)).Select(x => x.Id).ToList()));
|
||||
.ForEach(item => ids.AddRange(_repository.AsSugarClient().Queryable<OrganizeEntity>().Where(x => x.OrganizeIdTree.Contains(item)).Select(x => x.Id).ToList()));
|
||||
|
||||
if (subOrgIds.Any())
|
||||
if (ids.Any())
|
||||
{
|
||||
var cmodel = GetConditionalModel(itemMethod, itemField, string.Join(",", subOrgIds));
|
||||
switch (conditionItem.Logic)
|
||||
for (int i = 0; i < ids.Count; i++)
|
||||
{
|
||||
case "and":
|
||||
conditionalList.Add(new { Key = (int)WhereType.And, Value = new { FieldName = itemField, FieldValue = string.Join(",", subOrgIds), ConditionalType = (int)cmodel.ConditionalType } });
|
||||
break;
|
||||
case "or":
|
||||
conditionalList.Add(new { Key = (int)WhereType.Or, Value = new { FieldName = itemField, FieldValue = string.Join(",", subOrgIds), ConditionalType = (int)cmodel.ConditionalType } });
|
||||
break;
|
||||
if (i == 0)
|
||||
{
|
||||
switch (conditionItem.Logic)
|
||||
{
|
||||
case "and":
|
||||
conditionalList.Add(new { Key = (int)WhereType.And, Value = new { FieldName = itemField, FieldValue = ids[i], ConditionalType = (int)cmodel.ConditionalType } });
|
||||
|
||||
break;
|
||||
case "or":
|
||||
conditionalList.Add(new { Key = (int)WhereType.Or, Value = new { FieldName = itemField, FieldValue = ids[i], ConditionalType = (int)cmodel.ConditionalType } });
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (itemMethod.Equals(QueryType.NotEqual) || itemMethod.Equals(QueryType.NotIncluded))
|
||||
conditionalList.Add(new { Key = (int)WhereType.And, Value = new { FieldName = itemField, FieldValue = ids[i], ConditionalType = (int)cmodel.ConditionalType } });
|
||||
else
|
||||
conditionalList.Add(new { Key = (int)WhereType.Or, Value = new { FieldName = itemField, FieldValue = ids[i], ConditionalType = (int)cmodel.ConditionalType } });
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -884,16 +997,16 @@ public class UserManager : IUserManager, IScoped
|
||||
{
|
||||
if (!string.IsNullOrEmpty(itemValue))
|
||||
{
|
||||
var cmodel = GetConditionalModel(itemMethod, itemField, itemValue, fieldItem.Type);
|
||||
if (cmodel.ConditionalType.Equals(ConditionalType.In)) cmodel.ConditionalType = ConditionalType.Like;
|
||||
if (cmodel.ConditionalType.Equals(ConditionalType.NotIn)) cmodel.ConditionalType = ConditionalType.NoLike;
|
||||
var defCmodel = GetConditionalModel(itemMethod, itemField, itemValue, fieldItem.Type);
|
||||
if (defCmodel.ConditionalType.Equals(ConditionalType.In)) defCmodel.ConditionalType = ConditionalType.Like;
|
||||
if (defCmodel.ConditionalType.Equals(ConditionalType.NotIn)) defCmodel.ConditionalType = ConditionalType.NoLike;
|
||||
switch (conditionItem.Logic)
|
||||
{
|
||||
case "and":
|
||||
conditionalList.Add(new { Key = (int)WhereType.And, Value = new { FieldName = itemField, FieldValue = itemValue, ConditionalType = (int)cmodel.ConditionalType } });
|
||||
conditionalList.Add(new { Key = (int)WhereType.And, Value = new { FieldName = itemField, FieldValue = itemValue, ConditionalType = (int)defCmodel.ConditionalType } });
|
||||
break;
|
||||
case "or":
|
||||
conditionalList.Add(new { Key = (int)WhereType.Or, Value = new { FieldName = itemField, FieldValue = itemValue, ConditionalType = (int)cmodel.ConditionalType } });
|
||||
conditionalList.Add(new { Key = (int)WhereType.Or, Value = new { FieldName = itemField, FieldValue = itemValue, ConditionalType = (int)defCmodel.ConditionalType } });
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -902,6 +1015,8 @@ public class UserManager : IUserManager, IScoped
|
||||
|
||||
break;
|
||||
}
|
||||
if (itemMethod.Equals(QueryType.NotEqual) || itemMethod.Equals(QueryType.NotIncluded))
|
||||
conditionalList.Add(new { Key = (int)WhereType.Or, Value = new { FieldName = itemField, FieldValue = string.Empty, ConditionalType = ConditionalType.IsNullOrEmpty } });
|
||||
}
|
||||
|
||||
if (conditionalList.Any())
|
||||
@@ -1048,11 +1163,13 @@ public class UserManager : IUserManager, IScoped
|
||||
var itemValue = fieldItem.Value;
|
||||
var itemMethod = (QueryType)System.Enum.Parse(typeof(QueryType), fieldItem.Op);
|
||||
|
||||
var cmodel = GetConditionalModel(itemMethod, itemField, User.OrganizeId);
|
||||
if (itemMethod.Equals(QueryType.Equal)) cmodel.ConditionalType = ConditionalType.Like;
|
||||
if (itemMethod.Equals(QueryType.NotEqual)) cmodel.ConditionalType = ConditionalType.NoLike;
|
||||
switch (itemValue)
|
||||
{
|
||||
case "@userId": // 当前用户
|
||||
{
|
||||
var cmodel = GetConditionalModel(itemMethod, itemField, UserId);
|
||||
switch (conditionItem.Logic)
|
||||
{
|
||||
case "and":
|
||||
@@ -1070,19 +1187,30 @@ public class UserManager : IUserManager, IScoped
|
||||
case "@userAraSubordinates": // 当前用户集下属
|
||||
{
|
||||
var ids = new List<string>() { UserId };
|
||||
var subordinates = await this.GetSubordinatesAsync(UserId);
|
||||
ids.AddRange(subordinates);
|
||||
var cmodel = GetConditionalModel(itemMethod, itemField, string.Join(",", ids));
|
||||
switch (conditionItem.Logic)
|
||||
ids.AddRange(Subordinates);
|
||||
for (int i = 0; i < ids.Count; i++)
|
||||
{
|
||||
case "and":
|
||||
conditionalList.Add(new { Key = (int)WhereType.And, Value = new { FieldName = itemField, FieldValue = string.Join(",", ids), ConditionalType = (int)cmodel.ConditionalType } });
|
||||
if (i == 0)
|
||||
{
|
||||
switch (conditionItem.Logic)
|
||||
{
|
||||
case "and":
|
||||
conditionalList.Add(new { Key = (int)WhereType.And, Value = new { FieldName = itemField, FieldValue = ids[i], ConditionalType = (int)cmodel.ConditionalType } });
|
||||
|
||||
break;
|
||||
case "or":
|
||||
conditionalList.Add(new { Key = (int)WhereType.Or, Value = new { FieldName = itemField, FieldValue = string.Join(",", ids), ConditionalType = (int)cmodel.ConditionalType } });
|
||||
break;
|
||||
case "or":
|
||||
conditionalList.Add(new { Key = (int)WhereType.Or, Value = new { FieldName = itemField, FieldValue = ids[i], ConditionalType = (int)cmodel.ConditionalType } });
|
||||
|
||||
break;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (itemMethod.Equals(QueryType.NotEqual) || itemMethod.Equals(QueryType.NotIncluded))
|
||||
conditionalList.Add(new { Key = (int)WhereType.And, Value = new { FieldName = itemField, FieldValue = ids[i], ConditionalType = (int)cmodel.ConditionalType } });
|
||||
else
|
||||
conditionalList.Add(new { Key = (int)WhereType.Or, Value = new { FieldName = itemField, FieldValue = ids[i], ConditionalType = (int)cmodel.ConditionalType } });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1091,7 +1219,6 @@ public class UserManager : IUserManager, IScoped
|
||||
{
|
||||
if (!string.IsNullOrEmpty(User.OrganizeId))
|
||||
{
|
||||
var cmodel = GetConditionalModel(itemMethod, itemField, User.OrganizeId);
|
||||
switch (conditionItem.Logic)
|
||||
{
|
||||
case "and":
|
||||
@@ -1108,23 +1235,33 @@ public class UserManager : IUserManager, IScoped
|
||||
break;
|
||||
case "@organizationAndSuborganization": // 当前组织及子组织
|
||||
{
|
||||
var userInfo = User;
|
||||
if (!string.IsNullOrEmpty(userInfo.OrganizeId))
|
||||
if (!string.IsNullOrEmpty(User.OrganizeId))
|
||||
{
|
||||
var subsidiary = await GetSubsidiaryAsync(userInfo.OrganizeId, userInfo.IsAdministrator.Equals(1));
|
||||
var ids = new List<string>() { userInfo.OrganizeId };
|
||||
ids.AddRange(subsidiary);
|
||||
var cmodel = GetConditionalModel(itemMethod, itemField, string.Join(",", ids));
|
||||
switch (conditionItem.Logic)
|
||||
var ids = new List<string>() { User.OrganizeId };
|
||||
ids.AddRange(Subsidiary);
|
||||
for (int i = 0; i < ids.Count; i++)
|
||||
{
|
||||
case "and":
|
||||
conditionalList.Add(new { Key = (int)WhereType.And, Value = new { FieldName = itemField, FieldValue = string.Join(",", ids), ConditionalType = (int)cmodel.ConditionalType } });
|
||||
if (i == 0)
|
||||
{
|
||||
switch (conditionItem.Logic)
|
||||
{
|
||||
case "and":
|
||||
conditionalList.Add(new { Key = (int)WhereType.And, Value = new { FieldName = itemField, FieldValue = ids[i], ConditionalType = (int)cmodel.ConditionalType } });
|
||||
|
||||
break;
|
||||
case "or":
|
||||
conditionalList.Add(new { Key = (int)WhereType.Or, Value = new { FieldName = itemField, FieldValue = string.Join(",", ids), ConditionalType = (int)cmodel.ConditionalType } });
|
||||
break;
|
||||
case "or":
|
||||
conditionalList.Add(new { Key = (int)WhereType.Or, Value = new { FieldName = itemField, FieldValue = ids[i], ConditionalType = (int)cmodel.ConditionalType } });
|
||||
|
||||
break;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (itemMethod.Equals(QueryType.NotEqual) || itemMethod.Equals(QueryType.NotIncluded))
|
||||
conditionalList.Add(new { Key = (int)WhereType.And, Value = new { FieldName = itemField, FieldValue = ids[i], ConditionalType = (int)cmodel.ConditionalType } });
|
||||
else
|
||||
conditionalList.Add(new { Key = (int)WhereType.Or, Value = new { FieldName = itemField, FieldValue = ids[i], ConditionalType = (int)cmodel.ConditionalType } });
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1133,18 +1270,32 @@ public class UserManager : IUserManager, IScoped
|
||||
|
||||
case "@branchManageOrganize": // 当前分管组织
|
||||
{
|
||||
var orgId = DataScope.Where(x => x.Select).Select(x => x.organizeId).ToList();
|
||||
if (orgId != null)
|
||||
var ids = DataScope.Where(x => x.Select).Select(x => x.organizeId).ToList();
|
||||
if (ids != null)
|
||||
{
|
||||
var cmodel = GetConditionalModel(itemMethod, itemField, string.Join(",", orgId));
|
||||
switch (conditionItem.Logic)
|
||||
for (int i = 0; i < ids.Count; i++)
|
||||
{
|
||||
case "and":
|
||||
conditionalList.Add(new { Key = (int)WhereType.And, Value = new { FieldName = itemField, FieldValue = string.Join(",", orgId), ConditionalType = (int)cmodel.ConditionalType } });
|
||||
break;
|
||||
case "or":
|
||||
conditionalList.Add(new { Key = (int)WhereType.Or, Value = new { FieldName = itemField, FieldValue = string.Join(",", orgId), ConditionalType = (int)cmodel.ConditionalType } });
|
||||
break;
|
||||
if (i == 0)
|
||||
{
|
||||
switch (conditionItem.Logic)
|
||||
{
|
||||
case "and":
|
||||
conditionalList.Add(new { Key = (int)WhereType.And, Value = new { FieldName = itemField, FieldValue = ids[i], ConditionalType = (int)cmodel.ConditionalType } });
|
||||
|
||||
break;
|
||||
case "or":
|
||||
conditionalList.Add(new { Key = (int)WhereType.Or, Value = new { FieldName = itemField, FieldValue = ids[i], ConditionalType = (int)cmodel.ConditionalType } });
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (itemMethod.Equals(QueryType.NotEqual) || itemMethod.Equals(QueryType.NotIncluded))
|
||||
conditionalList.Add(new { Key = (int)WhereType.And, Value = new { FieldName = itemField, FieldValue = ids[i], ConditionalType = (int)cmodel.ConditionalType } });
|
||||
else
|
||||
conditionalList.Add(new { Key = (int)WhereType.Or, Value = new { FieldName = itemField, FieldValue = ids[i], ConditionalType = (int)cmodel.ConditionalType } });
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -1157,21 +1308,35 @@ public class UserManager : IUserManager, IScoped
|
||||
|
||||
case "@branchManageOrganizeAndSub": // 当前分管组织及子组织
|
||||
{
|
||||
var subOrgIds = new List<string>();
|
||||
var ids = new List<string>();
|
||||
DataScope.Where(x => x.Select).Select(x => x.organizeId).ToList()
|
||||
.ForEach(item => subOrgIds.AddRange(_repository.AsSugarClient().Queryable<OrganizeEntity>().Where(x => x.OrganizeIdTree.Contains(item)).Select(x => x.Id).ToList()));
|
||||
.ForEach(item => ids.AddRange(_repository.AsSugarClient().Queryable<OrganizeEntity>().Where(x => x.OrganizeIdTree.Contains(item)).Select(x => x.Id).ToList()));
|
||||
|
||||
if (subOrgIds.Any())
|
||||
if (ids.Any())
|
||||
{
|
||||
var cmodel = GetConditionalModel(itemMethod, itemField, string.Join(",", subOrgIds));
|
||||
switch (conditionItem.Logic)
|
||||
for (int i = 0; i < ids.Count; i++)
|
||||
{
|
||||
case "and":
|
||||
conditionalList.Add(new { Key = (int)WhereType.And, Value = new { FieldName = itemField, FieldValue = string.Join(",", subOrgIds), ConditionalType = (int)cmodel.ConditionalType } });
|
||||
break;
|
||||
case "or":
|
||||
conditionalList.Add(new { Key = (int)WhereType.Or, Value = new { FieldName = itemField, FieldValue = string.Join(",", subOrgIds), ConditionalType = (int)cmodel.ConditionalType } });
|
||||
break;
|
||||
if (i == 0)
|
||||
{
|
||||
switch (conditionItem.Logic)
|
||||
{
|
||||
case "and":
|
||||
conditionalList.Add(new { Key = (int)WhereType.And, Value = new { FieldName = itemField, FieldValue = ids[i], ConditionalType = (int)cmodel.ConditionalType } });
|
||||
|
||||
break;
|
||||
case "or":
|
||||
conditionalList.Add(new { Key = (int)WhereType.Or, Value = new { FieldName = itemField, FieldValue = ids[i], ConditionalType = (int)cmodel.ConditionalType } });
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (itemMethod.Equals(QueryType.NotEqual) || itemMethod.Equals(QueryType.NotIncluded))
|
||||
conditionalList.Add(new { Key = (int)WhereType.And, Value = new { FieldName = itemField, FieldValue = ids[i], ConditionalType = (int)cmodel.ConditionalType } });
|
||||
else
|
||||
conditionalList.Add(new { Key = (int)WhereType.Or, Value = new { FieldName = itemField, FieldValue = ids[i], ConditionalType = (int)cmodel.ConditionalType } });
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -1186,24 +1351,25 @@ public class UserManager : IUserManager, IScoped
|
||||
{
|
||||
if (!string.IsNullOrEmpty(itemValue))
|
||||
{
|
||||
var cmodel = GetConditionalModel(itemMethod, itemField, itemValue, fieldItem.Type);
|
||||
if (cmodel.ConditionalType.Equals(ConditionalType.In)) cmodel.ConditionalType = ConditionalType.Like;
|
||||
if (cmodel.ConditionalType.Equals(ConditionalType.NotIn)) cmodel.ConditionalType = ConditionalType.NoLike;
|
||||
var defCmodel = GetConditionalModel(itemMethod, itemField, itemValue, fieldItem.Type);
|
||||
if (defCmodel.ConditionalType.Equals(ConditionalType.In)) defCmodel.ConditionalType = ConditionalType.Like;
|
||||
if (defCmodel.ConditionalType.Equals(ConditionalType.NotIn)) defCmodel.ConditionalType = ConditionalType.NoLike;
|
||||
switch (conditionItem.Logic)
|
||||
{
|
||||
case "and":
|
||||
conditionalList.Add(new { Key = (int)WhereType.And, Value = new { FieldName = itemField, FieldValue = itemValue, ConditionalType = (int)cmodel.ConditionalType } });
|
||||
conditionalList.Add(new { Key = (int)WhereType.And, Value = new { FieldName = itemField, FieldValue = itemValue, ConditionalType = (int)defCmodel.ConditionalType } });
|
||||
break;
|
||||
case "or":
|
||||
conditionalList.Add(new { Key = (int)WhereType.Or, Value = new { FieldName = itemField, FieldValue = itemValue, ConditionalType = (int)cmodel.ConditionalType } });
|
||||
conditionalList.Add(new { Key = (int)WhereType.Or, Value = new { FieldName = itemField, FieldValue = itemValue, ConditionalType = (int)defCmodel.ConditionalType } });
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
if (itemMethod.Equals(QueryType.NotEqual) || itemMethod.Equals(QueryType.NotIncluded))
|
||||
conditionalList.Add(new { Key = (int)WhereType.Or, Value = new { FieldName = itemField, FieldValue = string.Empty, ConditionalType = ConditionalType.IsNullOrEmpty } });
|
||||
codeGenConditionalObject.Find(it => it.FieldRule == fieldRule && it.TableName.Equals(tableName)).conditionalModel.AddRange(conditionalList);
|
||||
}
|
||||
|
||||
@@ -1329,11 +1495,13 @@ public class UserManager : IUserManager, IScoped
|
||||
var itemValue = fieldItem.Value;
|
||||
var itemMethod = (QueryType)System.Enum.Parse(typeof(QueryType), fieldItem.Op);
|
||||
|
||||
var cmodel = GetConditionalModel(itemMethod, itemField, User.OrganizeId);
|
||||
if (itemMethod.Equals(QueryType.Equal)) cmodel.ConditionalType = ConditionalType.Like;
|
||||
if (itemMethod.Equals(QueryType.NotEqual)) cmodel.ConditionalType = ConditionalType.NoLike;
|
||||
switch (itemValue)
|
||||
{
|
||||
case "@userId": // 当前用户
|
||||
{
|
||||
var cmodel = GetConditionalModel(itemMethod, itemField, UserId);
|
||||
switch (conditionItem.Logic)
|
||||
{
|
||||
case "and":
|
||||
@@ -1352,17 +1520,29 @@ public class UserManager : IUserManager, IScoped
|
||||
{
|
||||
var ids = new List<string>() { UserId };
|
||||
ids.AddRange(Subordinates);
|
||||
var cmodel = GetConditionalModel(itemMethod, itemField, string.Join(",", ids));
|
||||
switch (conditionItem.Logic)
|
||||
for (int i = 0; i < ids.Count; i++)
|
||||
{
|
||||
case "and":
|
||||
conditionalList.Add(new { Key = (int)WhereType.And, Value = new { FieldName = itemField, FieldValue = string.Join(",", ids), ConditionalType = (int)cmodel.ConditionalType } });
|
||||
if (i == 0)
|
||||
{
|
||||
switch (conditionItem.Logic)
|
||||
{
|
||||
case "and":
|
||||
conditionalList.Add(new { Key = (int)WhereType.And, Value = new { FieldName = itemField, FieldValue = ids[i], ConditionalType = (int)cmodel.ConditionalType } });
|
||||
|
||||
break;
|
||||
case "or":
|
||||
conditionalList.Add(new { Key = (int)WhereType.Or, Value = new { FieldName = itemField, FieldValue = string.Join(",", ids), ConditionalType = (int)cmodel.ConditionalType } });
|
||||
break;
|
||||
case "or":
|
||||
conditionalList.Add(new { Key = (int)WhereType.Or, Value = new { FieldName = itemField, FieldValue = ids[i], ConditionalType = (int)cmodel.ConditionalType } });
|
||||
|
||||
break;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (itemMethod.Equals(QueryType.NotEqual) || itemMethod.Equals(QueryType.NotIncluded))
|
||||
conditionalList.Add(new { Key = (int)WhereType.And, Value = new { FieldName = itemField, FieldValue = ids[i], ConditionalType = (int)cmodel.ConditionalType } });
|
||||
else
|
||||
conditionalList.Add(new { Key = (int)WhereType.Or, Value = new { FieldName = itemField, FieldValue = ids[i], ConditionalType = (int)cmodel.ConditionalType } });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1371,7 +1551,6 @@ public class UserManager : IUserManager, IScoped
|
||||
{
|
||||
if (!string.IsNullOrEmpty(User.OrganizeId))
|
||||
{
|
||||
var cmodel = GetConditionalModel(itemMethod, itemField, User.OrganizeId);
|
||||
switch (conditionItem.Logic)
|
||||
{
|
||||
case "and":
|
||||
@@ -1382,7 +1561,6 @@ public class UserManager : IUserManager, IScoped
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
break;
|
||||
@@ -1392,17 +1570,29 @@ public class UserManager : IUserManager, IScoped
|
||||
{
|
||||
var ids = new List<string>() { User.OrganizeId };
|
||||
ids.AddRange(Subsidiary);
|
||||
var cmodel = GetConditionalModel(itemMethod, itemField, string.Join(",", ids));
|
||||
switch (conditionItem.Logic)
|
||||
for (int i = 0; i < ids.Count; i++)
|
||||
{
|
||||
case "and":
|
||||
conditionalList.Add(new { Key = (int)WhereType.And, Value = new { FieldName = itemField, FieldValue = string.Join(",", ids), ConditionalType = (int)cmodel.ConditionalType } });
|
||||
if(i == 0)
|
||||
{
|
||||
switch (conditionItem.Logic)
|
||||
{
|
||||
case "and":
|
||||
conditionalList.Add(new { Key = (int)WhereType.And, Value = new { FieldName = itemField, FieldValue = ids[i], ConditionalType = (int)cmodel.ConditionalType } });
|
||||
|
||||
break;
|
||||
case "or":
|
||||
conditionalList.Add(new { Key = (int)WhereType.Or, Value = new { FieldName = itemField, FieldValue = string.Join(",", ids), ConditionalType = (int)cmodel.ConditionalType } });
|
||||
break;
|
||||
case "or":
|
||||
conditionalList.Add(new { Key = (int)WhereType.Or, Value = new { FieldName = itemField, FieldValue = ids[i], ConditionalType = (int)cmodel.ConditionalType } });
|
||||
|
||||
break;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (itemMethod.Equals(QueryType.NotEqual) || itemMethod.Equals(QueryType.NotIncluded))
|
||||
conditionalList.Add(new { Key = (int)WhereType.And, Value = new { FieldName = itemField, FieldValue = ids[i], ConditionalType = (int)cmodel.ConditionalType } });
|
||||
else
|
||||
conditionalList.Add(new { Key = (int)WhereType.Or, Value = new { FieldName = itemField, FieldValue = ids[i], ConditionalType = (int)cmodel.ConditionalType } });
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1411,18 +1601,32 @@ public class UserManager : IUserManager, IScoped
|
||||
|
||||
case "@branchManageOrganize": // 当前分管组织
|
||||
{
|
||||
var orgId = DataScope.Where(x => x.Select).Select(x => x.organizeId).ToList();
|
||||
if (orgId != null)
|
||||
var ids = DataScope.Where(x => x.Select).Select(x => x.organizeId).ToList();
|
||||
if (ids != null)
|
||||
{
|
||||
var cmodel = GetConditionalModel(itemMethod, itemField, string.Join(",", orgId));
|
||||
switch (conditionItem.Logic)
|
||||
for (int i = 0; i < ids.Count; i++)
|
||||
{
|
||||
case "and":
|
||||
conditionalList.Add(new { Key = (int)WhereType.And, Value = new { FieldName = itemField, FieldValue = string.Join(",", orgId), ConditionalType = (int)cmodel.ConditionalType } });
|
||||
break;
|
||||
case "or":
|
||||
conditionalList.Add(new { Key = (int)WhereType.Or, Value = new { FieldName = itemField, FieldValue = string.Join(",", orgId), ConditionalType = (int)cmodel.ConditionalType } });
|
||||
break;
|
||||
if (i == 0)
|
||||
{
|
||||
switch (conditionItem.Logic)
|
||||
{
|
||||
case "and":
|
||||
conditionalList.Add(new { Key = (int)WhereType.And, Value = new { FieldName = itemField, FieldValue = ids[i], ConditionalType = (int)cmodel.ConditionalType } });
|
||||
|
||||
break;
|
||||
case "or":
|
||||
conditionalList.Add(new { Key = (int)WhereType.Or, Value = new { FieldName = itemField, FieldValue = ids[i], ConditionalType = (int)cmodel.ConditionalType } });
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(itemMethod.Equals(QueryType.NotEqual) || itemMethod.Equals(QueryType.NotIncluded))
|
||||
conditionalList.Add(new { Key = (int)WhereType.And, Value = new { FieldName = itemField, FieldValue = ids[i], ConditionalType = (int)cmodel.ConditionalType } });
|
||||
else
|
||||
conditionalList.Add(new { Key = (int)WhereType.Or, Value = new { FieldName = itemField, FieldValue = ids[i], ConditionalType = (int)cmodel.ConditionalType } });
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -1435,21 +1639,35 @@ public class UserManager : IUserManager, IScoped
|
||||
|
||||
case "@branchManageOrganizeAndSub": // 当前分管组织及子组织
|
||||
{
|
||||
var subOrgIds = new List<string>();
|
||||
var ids = new List<string>();
|
||||
DataScope.Where(x => x.Select).Select(x => x.organizeId).ToList()
|
||||
.ForEach(item => subOrgIds.AddRange(_repository.AsSugarClient().Queryable<OrganizeEntity>().Where(x => x.OrganizeIdTree.Contains(item)).Select(x => x.Id).ToList()));
|
||||
.ForEach(item => ids.AddRange(_repository.AsSugarClient().Queryable<OrganizeEntity>().Where(x => x.OrganizeIdTree.Contains(item)).Select(x => x.Id).ToList()));
|
||||
|
||||
if (subOrgIds.Any())
|
||||
if (ids.Any())
|
||||
{
|
||||
var cmodel = GetConditionalModel(itemMethod, itemField, string.Join(",", subOrgIds));
|
||||
switch (conditionItem.Logic)
|
||||
for (int i = 0; i < ids.Count; i++)
|
||||
{
|
||||
case "and":
|
||||
conditionalList.Add(new { Key = (int)WhereType.And, Value = new { FieldName = itemField, FieldValue = string.Join(",", subOrgIds), ConditionalType = (int)cmodel.ConditionalType } });
|
||||
break;
|
||||
case "or":
|
||||
conditionalList.Add(new { Key = (int)WhereType.Or, Value = new { FieldName = itemField, FieldValue = string.Join(",", subOrgIds), ConditionalType = (int)cmodel.ConditionalType } });
|
||||
break;
|
||||
if (i == 0)
|
||||
{
|
||||
switch (conditionItem.Logic)
|
||||
{
|
||||
case "and":
|
||||
conditionalList.Add(new { Key = (int)WhereType.And, Value = new { FieldName = itemField, FieldValue = ids[i], ConditionalType = (int)cmodel.ConditionalType } });
|
||||
|
||||
break;
|
||||
case "or":
|
||||
conditionalList.Add(new { Key = (int)WhereType.Or, Value = new { FieldName = itemField, FieldValue = ids[i], ConditionalType = (int)cmodel.ConditionalType } });
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (itemMethod.Equals(QueryType.NotEqual) || itemMethod.Equals(QueryType.NotIncluded))
|
||||
conditionalList.Add(new { Key = (int)WhereType.And, Value = new { FieldName = itemField, FieldValue = ids[i], ConditionalType = (int)cmodel.ConditionalType } });
|
||||
else
|
||||
conditionalList.Add(new { Key = (int)WhereType.Or, Value = new { FieldName = itemField, FieldValue = ids[i], ConditionalType = (int)cmodel.ConditionalType } });
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -1464,16 +1682,16 @@ public class UserManager : IUserManager, IScoped
|
||||
{
|
||||
if (!string.IsNullOrEmpty(itemValue))
|
||||
{
|
||||
var cmodel = GetConditionalModel(itemMethod, itemField, itemValue, fieldItem.Type);
|
||||
if (cmodel.ConditionalType.Equals(ConditionalType.In)) cmodel.ConditionalType = ConditionalType.Like;
|
||||
if (cmodel.ConditionalType.Equals(ConditionalType.NotIn)) cmodel.ConditionalType = ConditionalType.NoLike;
|
||||
var defCmodel = GetConditionalModel(itemMethod, itemField, itemValue, fieldItem.Type);
|
||||
if (defCmodel.ConditionalType.Equals(ConditionalType.In)) defCmodel.ConditionalType = ConditionalType.Like;
|
||||
if (defCmodel.ConditionalType.Equals(ConditionalType.NotIn)) defCmodel.ConditionalType = ConditionalType.NoLike;
|
||||
switch (conditionItem.Logic)
|
||||
{
|
||||
case "and":
|
||||
conditionalList.Add(new { Key = (int)WhereType.And, Value = new { FieldName = itemField, FieldValue = itemValue, ConditionalType = (int)cmodel.ConditionalType } });
|
||||
conditionalList.Add(new { Key = (int)WhereType.And, Value = new { FieldName = itemField, FieldValue = itemValue, ConditionalType = (int)defCmodel.ConditionalType } });
|
||||
break;
|
||||
case "or":
|
||||
conditionalList.Add(new { Key = (int)WhereType.Or, Value = new { FieldName = itemField, FieldValue = itemValue, ConditionalType = (int)cmodel.ConditionalType } });
|
||||
conditionalList.Add(new { Key = (int)WhereType.Or, Value = new { FieldName = itemField, FieldValue = itemValue, ConditionalType = (int)defCmodel.ConditionalType } });
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -1482,6 +1700,8 @@ public class UserManager : IUserManager, IScoped
|
||||
|
||||
break;
|
||||
}
|
||||
if (itemMethod.Equals(QueryType.NotEqual) || itemMethod.Equals(QueryType.NotIncluded))
|
||||
conditionalList.Add(new { Key = (int)WhereType.Or, Value = new { FieldName = itemField, FieldValue = string.Empty, ConditionalType = ConditionalType.IsNullOrEmpty } });
|
||||
}
|
||||
|
||||
if (conditionalList.Any())
|
||||
@@ -1691,12 +1911,14 @@ public class UserManager : IUserManager, IScoped
|
||||
|
||||
// 包含
|
||||
case QueryType.In:
|
||||
case QueryType.Included:
|
||||
return new ConditionalModel() { FieldName = fieldName, ConditionalType = ConditionalType.In, FieldValue = fieldValue };
|
||||
case QueryType.Included:
|
||||
return new ConditionalModel() { FieldName = fieldName, ConditionalType = ConditionalType.Like, FieldValue = fieldValue };
|
||||
// 不包含
|
||||
case QueryType.NotIn:
|
||||
return new ConditionalModel() { FieldName = fieldName, ConditionalType = ConditionalType.In, FieldValue = fieldValue };
|
||||
case QueryType.NotIncluded:
|
||||
return new ConditionalModel() { FieldName = fieldName, ConditionalType = ConditionalType.NotIn, FieldValue = fieldValue };
|
||||
return new ConditionalModel() { FieldName = fieldName, ConditionalType = ConditionalType.NoLike, FieldValue = fieldValue };
|
||||
}
|
||||
|
||||
return new ConditionalModel();
|
||||
|
||||
@@ -14,8 +14,10 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\message\Tnb.Message.Entitys\Tnb.Message.Entitys.csproj" />
|
||||
<ProjectReference Include="..\..\system\Tnb.Systems.Entitys\Tnb.Systems.Entitys.csproj" />
|
||||
<ProjectReference Include="..\..\visualdev\Tnb.VisualDev.Entitys\Tnb.VisualDev.Entitys.csproj" />
|
||||
<ProjectReference Include="..\Tnb.WebSockets\Tnb.WebSockets.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -86,12 +86,14 @@ public class CodeGenUploadAttribute : Attribute
|
||||
/// 构造函数
|
||||
/// "popupSelect".
|
||||
/// </summary>
|
||||
public CodeGenUploadAttribute(string Model, string SecondParameter, string ThreeParameters, string FourParameters, string Config)
|
||||
public CodeGenUploadAttribute(string Model, string dataConversionModel, string SecondParameter, string ThreeParameters, string FourParameters, string ShowField, string Config)
|
||||
{
|
||||
__Model__ = Model;
|
||||
__vModel__ = dataConversionModel;
|
||||
interfaceId = SecondParameter;
|
||||
propsValue = ThreeParameters;
|
||||
relationField = FourParameters;
|
||||
showField = ShowField;
|
||||
__config__ = Config.ToObject<CodeGenConfigModel>();
|
||||
}
|
||||
|
||||
@@ -135,9 +137,7 @@ public class CodeGenUploadAttribute : Attribute
|
||||
/// <summary>
|
||||
/// 构造函数
|
||||
/// "treeSelect"
|
||||
/// "usersSelect":
|
||||
/// "depSelect":
|
||||
/// "relationForm".
|
||||
/// "depSelect":.
|
||||
/// </summary>
|
||||
public CodeGenUploadAttribute(string Model, bool Multiple, string ThreeParameters, string FourParameters, string Config)
|
||||
{
|
||||
@@ -146,18 +146,10 @@ public class CodeGenUploadAttribute : Attribute
|
||||
__config__ = Config.ToObject<CodeGenConfigModel>();
|
||||
switch (__config__.jnpfKey)
|
||||
{
|
||||
case JnpfKeyConst.RELATIONFORM:
|
||||
modelId = ThreeParameters;
|
||||
relationField = FourParameters;
|
||||
break;
|
||||
case JnpfKeyConst.DEPSELECT:
|
||||
selectType = ThreeParameters;
|
||||
ableDepIds = FourParameters?.ToObject<List<string>>();
|
||||
break;
|
||||
case JnpfKeyConst.USERSSELECT:
|
||||
selectType = ThreeParameters;
|
||||
ableIds = FourParameters?.ToObject<List<string>>();
|
||||
break;
|
||||
default:
|
||||
props = ThreeParameters?.ToObject<CodeGenPropsModel>();
|
||||
options = FourParameters?.ToObject<List<object>>();
|
||||
@@ -165,10 +157,25 @@ public class CodeGenUploadAttribute : Attribute
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 构造函数
|
||||
/// "usersSelect":.
|
||||
/// </summary>
|
||||
public CodeGenUploadAttribute(string Model, string dataConversionModel, bool Multiple, string ThreeParameters, string FourParameters, string Config)
|
||||
{
|
||||
__Model__ = Model;
|
||||
__vModel__ = dataConversionModel;
|
||||
multiple = Multiple;
|
||||
__config__ = Config.ToObject<CodeGenConfigModel>();
|
||||
selectType = ThreeParameters;
|
||||
ableIds = FourParameters?.ToObject<List<string>>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 构造函数
|
||||
/// "cascader"
|
||||
/// "posSelect":
|
||||
/// "relationForm"
|
||||
/// "popupTableSelect".
|
||||
/// </summary>
|
||||
public CodeGenUploadAttribute(string Model, bool Multiple, string InterfaceId, string PropsValue, string RelationField, string Config)
|
||||
@@ -196,6 +203,21 @@ public class CodeGenUploadAttribute : Attribute
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 构造函数
|
||||
/// "relationForm".
|
||||
/// </summary>
|
||||
public CodeGenUploadAttribute(string Model, string dataConversionModel, bool Multiple, string InterfaceId, string PropsValue, string RelationField, string Config)
|
||||
{
|
||||
__Model__ = Model;
|
||||
__vModel__ = dataConversionModel;
|
||||
multiple = Multiple;
|
||||
__config__ = Config.ToObject<CodeGenConfigModel>();
|
||||
modelId = InterfaceId;
|
||||
relationField = PropsValue;
|
||||
showField = RelationField;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 构造函数
|
||||
/// "userSelect":.
|
||||
@@ -218,6 +240,11 @@ public class CodeGenUploadAttribute : Attribute
|
||||
/// </summary>
|
||||
public string __Model__ { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 数据转换.
|
||||
/// </summary>
|
||||
public string __vModel__ { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 最小值.
|
||||
/// </summary>
|
||||
@@ -332,4 +359,9 @@ public class CodeGenUploadAttribute : Attribute
|
||||
/// 新用户选择控件.
|
||||
/// </summary>
|
||||
public List<string> ableIds { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 展示字段.
|
||||
/// </summary>
|
||||
public string showField { get; set; }
|
||||
}
|
||||
@@ -222,6 +222,18 @@ public enum ErrorCode
|
||||
[ErrorCodeItemMetadata("登录票据已失效")]
|
||||
D1035,
|
||||
|
||||
/// <summary>
|
||||
/// 主系统不允许禁用.
|
||||
/// </summary>
|
||||
[ErrorCodeItemMetadata("主系统不允许禁用")]
|
||||
D1036,
|
||||
|
||||
/// <summary>
|
||||
/// 主系统不允许更改应用编码.
|
||||
/// </summary>
|
||||
[ErrorCodeItemMetadata("主系统不允许更改应用编码")]
|
||||
D1037,
|
||||
|
||||
#endregion
|
||||
|
||||
#region 机构 2
|
||||
@@ -504,6 +516,12 @@ public enum ErrorCode
|
||||
[ErrorCodeItemMetadata("当前导入菜单为Web端菜单,请在对应模块下导入!")]
|
||||
D4013,
|
||||
|
||||
/// <summary>
|
||||
/// 该系统已被禁用
|
||||
/// </summary>
|
||||
[ErrorCodeItemMetadata("切换失败,当前系统已被管理员禁用")]
|
||||
D4014,
|
||||
|
||||
#endregion
|
||||
|
||||
#region 用户 5
|
||||
|
||||
@@ -83,4 +83,9 @@ public class ConvertSuperQuery
|
||||
/// 是否主条件.
|
||||
/// </summary>
|
||||
public bool mainWhere { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 象征.
|
||||
/// </summary>
|
||||
public string symbol { get; set; }
|
||||
}
|
||||
@@ -22,14 +22,14 @@ public static class CodeGenHelper
|
||||
case "nchar":
|
||||
case "timestamp":
|
||||
case "string":
|
||||
return "string";
|
||||
return "string?";
|
||||
|
||||
case "int":
|
||||
case "smallint":
|
||||
return "int";
|
||||
return "int?";
|
||||
|
||||
case "tinyint":
|
||||
return "byte";
|
||||
return "byte?";
|
||||
|
||||
case "bigint":
|
||||
// sqlite数据库
|
||||
@@ -43,10 +43,10 @@ public static class CodeGenHelper
|
||||
case "smallmoney":
|
||||
case "numeric":
|
||||
case "decimal":
|
||||
return "decimal";
|
||||
return "decimal?";
|
||||
|
||||
case "real":
|
||||
return "Single";
|
||||
return "Single?";
|
||||
|
||||
case "datetime":
|
||||
case "datetime2":
|
||||
@@ -55,7 +55,7 @@ public static class CodeGenHelper
|
||||
return "DateTime?";
|
||||
|
||||
case "float":
|
||||
return "double";
|
||||
return "double?";
|
||||
|
||||
case "image":
|
||||
case "binary":
|
||||
@@ -218,7 +218,7 @@ public static class CodeGenHelper
|
||||
result.Add(label, "系统自动生成");
|
||||
break;
|
||||
case JnpfKeyConst.COMSELECT:
|
||||
result.Add(label, multiple ? "例:拓通智联/产品部,拓通智联/技术部" : "例:拓通智联/技术部");
|
||||
result.Add(label, multiple ? "例:引迈信息/产品部,引迈信息/技术部" : "例:引迈信息/技术部");
|
||||
break;
|
||||
case JnpfKeyConst.DEPSELECT:
|
||||
result.Add(label, multiple ? "例:产品部/部门编码,技术部/部门编码" : "例:技术部/部门编码");
|
||||
@@ -230,7 +230,7 @@ public static class CodeGenHelper
|
||||
result.Add(label, multiple ? "例:张三/账号,李四/账号" : "例:张三/账号");
|
||||
break;
|
||||
case JnpfKeyConst.USERSSELECT:
|
||||
result.Add(label, multiple ? "例:拓通智联/产品部,产品部/部门编码,技术经理/岗位编码,研发人员/角色编码,A分组/分组编码,张三/账号" : "例:李四/账号");
|
||||
result.Add(label, multiple ? "例:引迈信息/产品部,产品部/部门编码,技术经理/岗位编码,研发人员/角色编码,A分组/分组编码,张三/账号" : "例:李四/账号");
|
||||
break;
|
||||
case JnpfKeyConst.ROLESELECT:
|
||||
result.Add(label, multiple ? "例:研发人员/角色编码,测试人员/角色编码" : "例:研发人员/角色编码");
|
||||
|
||||
Reference in New Issue
Block a user