merge from 2023-03-14
This commit is contained in:
@@ -46,7 +46,8 @@ namespace JNPF.Systems;
|
||||
/// <summary>
|
||||
/// 数据接口
|
||||
/// 版 本:V3.2
|
||||
/// 版 权:拓通智联科技有限公司(http://www.tuotong-tech.com)
|
||||
/// 版 权:引迈信息技术有限公司(https://www.jnpfsoft.com)
|
||||
/// 作 者:JNPF开发平台组
|
||||
/// 日 期:2021-06-01.
|
||||
/// </summary>
|
||||
[ApiDescriptionSettings(Tag = "System", Name = "DataInterface", Order = 204)]
|
||||
@@ -345,7 +346,7 @@ public class DataInterfaceService : IDataInterfaceService, IDynamicApiController
|
||||
{
|
||||
string sheetData = Regex.Match(info.DataProcessing, @"\{(.*)\}", RegexOptions.Singleline).Groups[1].Value;
|
||||
var scriptStr = "var result = function(data){data = JSON.parse(data);" + sheetData + "}";
|
||||
return JsEngineUtil.CallFunction(scriptStr, output.ToJsonString());
|
||||
return JsEngineUtil.CallFunction(scriptStr, output.ToJsonString(CommonConst.options));//此处时间非时间戳
|
||||
}
|
||||
}
|
||||
|
||||
@@ -732,7 +733,7 @@ public class DataInterfaceService : IDataInterfaceService, IDynamicApiController
|
||||
|
||||
list = await GetDynamicDataCache(dynamic.Id);
|
||||
|
||||
if (list == null)
|
||||
if (list == null || list.Count == 0)
|
||||
{
|
||||
list = new List<StaticDataModel>();
|
||||
// 远端数据 配置参数
|
||||
|
||||
@@ -1,7 +1,12 @@
|
||||
using JNPF.Common.Core.Manager;
|
||||
using JNPF.Common.Const;
|
||||
using JNPF.Common.Core.Handlers;
|
||||
using JNPF.Common.Core.Manager;
|
||||
using JNPF.Common.Enums;
|
||||
using JNPF.Common.Extension;
|
||||
using JNPF.Common.Filter;
|
||||
using JNPF.Common.Manager;
|
||||
using JNPF.Common.Models.User;
|
||||
using JNPF.Common.Security;
|
||||
using JNPF.DependencyInjection;
|
||||
using JNPF.DynamicApiController;
|
||||
using JNPF.FriendlyException;
|
||||
@@ -27,6 +32,16 @@ public class SystemService : IDynamicApiController, ITransient
|
||||
/// </summary>
|
||||
private readonly ISqlSugarRepository<SystemEntity> _repository;
|
||||
|
||||
/// <summary>
|
||||
/// 缓存管理器.
|
||||
/// </summary>
|
||||
private readonly ICacheManager _cacheManager;
|
||||
|
||||
/// <summary>
|
||||
/// IM中心处理程序.
|
||||
/// </summary>
|
||||
private IMHandler _imHandler;
|
||||
|
||||
/// <summary>
|
||||
/// 用户管理.
|
||||
/// </summary>
|
||||
@@ -37,9 +52,13 @@ public class SystemService : IDynamicApiController, ITransient
|
||||
/// </summary>
|
||||
public SystemService(
|
||||
ISqlSugarRepository<SystemEntity> repository,
|
||||
ICacheManager cacheManager,
|
||||
IMHandler imHandler,
|
||||
IUserManager userManager)
|
||||
{
|
||||
_repository = repository;
|
||||
_cacheManager = cacheManager;
|
||||
_imHandler = imHandler;
|
||||
_userManager = userManager;
|
||||
}
|
||||
|
||||
@@ -108,10 +127,99 @@ public class SystemService : IDynamicApiController, ITransient
|
||||
{
|
||||
if (await _repository.IsAnyAsync(x => x.Id != id && (x.EnCode == input.enCode || x.FullName == input.fullName) && x.DeleteMark == null))
|
||||
throw Oops.Oh(ErrorCode.COM1004);
|
||||
var entity = input.Adapt<SystemEntity>();
|
||||
var isOk = await _repository.AsUpdateable(entity).IgnoreColumns(ignoreAllNullColumns: true).CallEntityMethod(m => m.LastModify()).ExecuteCommandHasChangeAsync();
|
||||
if (!isOk)
|
||||
|
||||
var mainSystem = await _repository.GetFirstAsync(it => it.IsMain.Equals(1) && it.EnabledMark.Equals(1) && it.DeleteMark == null);
|
||||
|
||||
// 判断主系统是否被禁用.
|
||||
if (input.id.Equals(mainSystem.Id) && input.enabledMark.Equals(0))
|
||||
throw Oops.Oh(ErrorCode.D1036);
|
||||
|
||||
// 判断主系统是否有修改系统编码.
|
||||
if (input.id.Equals(mainSystem.Id) && !input.enCode.Equals(mainSystem.EnCode))
|
||||
throw Oops.Oh(ErrorCode.D1037);
|
||||
|
||||
var isOk = await _repository.AsUpdateable().SetColumns(it => new SystemEntity()
|
||||
{
|
||||
FullName = input.fullName,
|
||||
EnCode = input.enCode,
|
||||
Icon = input.icon,
|
||||
SortCode = input.sortCode,
|
||||
Description = input.description,
|
||||
EnabledMark = input.enabledMark,
|
||||
LastModifyUserId = _userManager.UserId,
|
||||
LastModifyTime = SqlFunc.GetDate(),
|
||||
}).Where(it => it.Id.Equals(id)).ExecuteCommandAsync();
|
||||
if (!(isOk > 0))
|
||||
throw Oops.Oh(ErrorCode.COM1001);
|
||||
|
||||
// 当用户的子系统被禁用时,更换成其他未被禁用的系统.
|
||||
if (!input.id.Equals(mainSystem.Id) && input.enabledMark.Equals(0))
|
||||
{
|
||||
var systemUser = await _repository.AsSugarClient().Queryable<UserEntity>()
|
||||
.Where(it => it.DeleteMark == null && input.id.Equals(it.SystemId))
|
||||
.Select(x => new UserEntity()
|
||||
{
|
||||
Id = x.Id,
|
||||
SystemId = x.SystemId
|
||||
}).ToListAsync();
|
||||
|
||||
// 获取用户所有角色id.
|
||||
var userRoleIdList = await _repository.AsSugarClient().Queryable<UserRelationEntity>()
|
||||
.Where(it => systemUser.Select(s => s.Id).ToList().Contains(it.UserId) && it.ObjectType.Equals("Role"))
|
||||
.Select(x => x.ObjectId)
|
||||
.ToListAsync();
|
||||
var authorizeList = await _repository.AsSugarClient().Queryable<AuthorizeEntity>()
|
||||
.Where(it => it.ItemType.Equals("module") && it.ObjectType.Equals("Role"))
|
||||
.ToListAsync();
|
||||
var moduleList = await _repository.AsSugarClient().Queryable<ModuleEntity>()
|
||||
.Where(it => !it.SystemId.Equals(mainSystem.Id) && !it.SystemId.Equals(input.id) && it.DeleteMark == null)
|
||||
.ToListAsync();
|
||||
|
||||
systemUser.ForEach(async item =>
|
||||
{
|
||||
// 获取用户所有角色的菜单.
|
||||
var moduleIdList = authorizeList
|
||||
.Where(x => userRoleIdList.Contains(x.ObjectId))
|
||||
.Select(s => s.ItemId);
|
||||
|
||||
// 获取用户所有有权限的系统id.
|
||||
var systemId = moduleList
|
||||
.Where(x => moduleIdList.Contains(x.Id))
|
||||
.Select(s => s.SystemId).FirstOrDefault();
|
||||
|
||||
if (systemId == null)
|
||||
systemId = mainSystem.Id;
|
||||
|
||||
// 更新用户的系统id.
|
||||
var res = await _repository.AsSugarClient().Updateable<UserEntity>()
|
||||
.Where(x => item.Id.Equals(x.Id))
|
||||
.SetColumns(x => new UserEntity()
|
||||
{
|
||||
SystemId = systemId
|
||||
}).ExecuteCommandAsync();
|
||||
|
||||
if (!(res > 0))
|
||||
throw Oops.Oh(ErrorCode.COM1001);
|
||||
});
|
||||
|
||||
var tenantId = _userManager.TenantId;
|
||||
var cacheKey = string.Format("{0}{1}", CommonConst.CACHEKEYONLINEUSER, tenantId);
|
||||
var allUserOnlineList = await _cacheManager.GetAsync<List<UserOnlineModel>>(cacheKey);
|
||||
|
||||
var userOnlineList = allUserOnlineList.FindAll(it => systemUser.Select(s => s.Id).ToList().Contains(it.userId));
|
||||
userOnlineList.ForEach(async item =>
|
||||
{
|
||||
await _imHandler.SendMessageAsync(item.connectionId, new { method = "logout", msg = "此系统已被禁用" }.ToJsonString());
|
||||
|
||||
// 删除在线用户ID.
|
||||
allUserOnlineList.RemoveAll((x) => x.connectionId == item.connectionId);
|
||||
|
||||
// 删除用户登录信息缓存.
|
||||
var mCacheKey = string.Format("{0}{1}_{2}", CommonConst.CACHEKEYUSER, tenantId, item.userId);
|
||||
await _cacheManager.DelAsync(mCacheKey);
|
||||
});
|
||||
await _cacheManager.SetAsync(cacheKey, allUserOnlineList);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user