添加项目文件。

This commit is contained in:
zel
2025-03-05 19:42:01 +08:00
parent 659f1a2ad9
commit 47dcdeb55d
582 changed files with 242004 additions and 0 deletions

View File

@@ -0,0 +1,93 @@
using SqlSugar;
using System.Collections.Generic;
using System.Threading.Tasks;
using WaterCloud.Code;
using WaterCloud.DataBase;
using WaterCloud.Domain.SystemManage;
using WaterCloud.Domain.SystemOrganize;
namespace WaterCloud.Service.SystemOrganize
{
/// <summary>
/// 创 建:超级管理员
/// 日 期2020-06-01 09:44
/// 描 述:数据权限服务类
/// </summary>
public class DataPrivilegeRuleService : BaseService<DataPrivilegeRuleEntity>, IDenpendency
{
public DataPrivilegeRuleService(ISqlSugarClient context) : base(context)
{
}
//获取类名
#region
public async Task<List<DataPrivilegeRuleEntity>> GetList(string keyword = "")
{
var list = repository.IQueryable();
if (!string.IsNullOrEmpty(keyword))
{
list = list.Where(a => a.F_ModuleCode.Contains(keyword) || a.F_Description.Contains(keyword));
}
return await list.Where(a => a.F_DeleteMark == false).OrderBy(a => a.F_Id, OrderByType.Desc).ToListAsync();
}
public async Task<List<DataPrivilegeRuleEntity>> GetLookList(SoulPage<DataPrivilegeRuleEntity> pagination, string keyword = "")
{
//反格式化显示只能用"等于",其他不支持
Dictionary<string, Dictionary<string, string>> dic = new Dictionary<string, Dictionary<string, string>>();
Dictionary<string, string> enabledTemp = new Dictionary<string, string>();
enabledTemp.Add("1", "有效");
enabledTemp.Add("0", "无效");
dic.Add("F_EnabledMark", enabledTemp);
pagination = ChangeSoulData(dic, pagination);
var query = repository.IQueryable().Where(a => a.F_DeleteMark == false);
if (!string.IsNullOrEmpty(keyword))
{
query = query.Where(a => a.F_ModuleCode.Contains(keyword) || a.F_Description.Contains(keyword));
}
query = GetDataPrivilege("a", "", query);
return await query.ToPageListAsync(pagination);
}
public async Task<DataPrivilegeRuleEntity> GetLookForm(string keyValue)
{
var data = await repository.FindEntity(keyValue);
return GetFieldsFilterData(data);
}
public async Task<DataPrivilegeRuleEntity> GetForm(string keyValue)
{
var data = await repository.FindEntity(keyValue);
return data;
}
#endregion
#region
public async Task SubmitForm(DataPrivilegeRuleEntity entity, string keyValue)
{
entity.F_ModuleCode = repository.Db.Queryable<ModuleEntity>().InSingle(entity.F_ModuleId).F_EnCode;
if (string.IsNullOrEmpty(keyValue))
{
entity.F_DeleteMark = false;
entity.Create();
await repository.Insert(entity);
}
else
{
entity.Modify(keyValue);
await repository.Update(entity);
}
}
public async Task DeleteForm(string keyValue)
{
await repository.Delete(a => a.F_Id == keyValue);
}
#endregion
}
}

View File

@@ -0,0 +1,173 @@
/*******************************************************************************
* Copyright © 2020 WaterCloud.Framework 版权所有
* Author: WaterCloud
* Description: WaterCloud快速开发平台
* Website
*********************************************************************************/
using MiniExcelLibs;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using WaterCloud.Code;
using WaterCloud.DataBase;
using WaterCloud.Domain.SystemOrganize;
namespace WaterCloud.Service.SystemOrganize
{
public class DutyService : BaseService<RoleEntity>, IDenpendency
{
public SystemSetService setApp { get; set; }
public DutyService(ISqlSugarClient context) : base(context)
{
}
public async Task<List<RoleEntity>> GetList(string keyword = "")
{
var query = repository.IQueryable();
query = query.Where(a => a.F_Category == 2 && a.F_DeleteMark == false);
if (!string.IsNullOrEmpty(keyword))
{
query = query.Where(a => a.F_FullName.Contains(keyword) || a.F_EnCode.Contains(keyword));
}
return await query.OrderBy(a => a.F_SortCode).ToListAsync();
}
public async Task<List<RoleExtend>> GetLookList(SoulPage<RoleExtend> pagination, string keyword = "")
{
//反格式化显示只能用"等于",其他不支持
Dictionary<string, Dictionary<string, string>> dic = new Dictionary<string, Dictionary<string, string>>();
Dictionary<string, string> enabledTemp = new Dictionary<string, string>();
enabledTemp.Add("1", "有效");
enabledTemp.Add("0", "无效");
dic.Add("F_EnabledMark", enabledTemp);
var setList = await setApp.GetList();
Dictionary<string, string> orgizeTemp = new Dictionary<string, string>();
foreach (var item in setList)
{
orgizeTemp.Add(item.F_Id, item.F_CompanyName);
}
dic.Add("F_CompanyId", orgizeTemp);
pagination = ChangeSoulData(dic, pagination);
var query = GetQuery();
if (!string.IsNullOrEmpty(keyword))
{
query = query.Where(a => a.F_FullName.Contains(keyword) || a.F_EnCode.Contains(keyword));
}
query = query.Where(a => a.F_DeleteMark == false && a.F_Category == 2);
query = GetDataPrivilege("a", "", query);
return await query.ToPageListAsync(pagination);
}
public async Task<RoleEntity> GetLookForm(string keyValue)
{
var data = await repository.FindEntity(keyValue);
return GetFieldsFilterData(data);
}
public async Task<RoleEntity> GetForm(string keyValue)
{
var data = await repository.FindEntity(keyValue);
return data;
}
private ISugarQueryable<RoleExtend> GetQuery()
{
var query = repository.Db.Queryable<RoleEntity, SystemSetEntity>((a, b) => new JoinQueryInfos(
JoinType.Left, a.F_CompanyId == b.F_Id
)).Where(a => a.F_DeleteMark == false && a.F_Category == 2)
.Select((a, b) => new RoleExtend
{
F_Id = a.F_Id.SelectAll(),
F_CompanyName = b.F_CompanyName,
}).MergeTable();
return query;
}
public async Task DeleteForm(string keyValue)
{
if (await repository.Db.Queryable<UserEntity>().Where(a => a.F_DutyId == keyValue).AnyAsync())
{
throw new Exception("岗位使用中,无法删除");
}
await repository.Delete(a => a.F_Id == keyValue);
}
public async Task SubmitForm(RoleEntity roleEntity, string keyValue)
{
if (!string.IsNullOrEmpty(keyValue))
{
roleEntity.Modify(keyValue);
await repository.Update(roleEntity);
}
else
{
roleEntity.F_DeleteMark = false;
roleEntity.F_AllowEdit = false;
roleEntity.F_AllowDelete = false;
roleEntity.Create();
roleEntity.F_Category = 2;
await repository.Insert(roleEntity);
}
}
public async Task<List<RoleExtend>> CheckFile(string fileFullName)
{
if (!FileHelper.IsExcel(fileFullName))
{
throw new Exception("文件不是有效的Excel文件!");
}
//文件解析
var list = MiniExcel.Query<RoleExtend>(fileFullName).ToList(); ;
//删除文件
File.Delete(fileFullName);
foreach (var item in list)
{
item.F_Id = Utils.GuId();
item.F_EnabledMark = true;
item.F_DeleteMark = false;
item.F_CompanyId = currentuser.CompanyId;
item.F_SortCode = 1;
item.F_Category = 2;
item.F_AllowEdit = false;
item.F_AllowDelete = false;
List<string> str = new List<string>();
if (string.IsNullOrEmpty(item.F_EnCode))
{
item.F_EnabledMark = false;
item.ErrorMsg = "编号不存在";
continue;
}
else if (await repository.IQueryable(a => a.F_EnCode == item.F_EnCode).AnyAsync() || list.Where(a => a.F_EnCode == item.F_EnCode).Count() > 1)
{
str.Add("编号重复");
item.F_EnabledMark = false;
}
if (string.IsNullOrEmpty(item.F_FullName))
{
str.Add("名称不存在");
item.F_EnabledMark = false;
}
if (item.F_EnabledMark == false)
{
item.ErrorMsg = string.Join(',', str.ToArray());
}
}
return list;
}
public async Task ImportForm(List<RoleEntity> filterList)
{
foreach (var item in filterList)
{
item.Create();
}
await repository.Db.Insertable(filterList).ExecuteCommandAsync();
}
}
}

View File

@@ -0,0 +1,89 @@
//-----------------------------------------------------------------------
// <copyright file=" Notice.cs" company="JR">
// * Copyright (C) WaterCloud.Framework All Rights Reserved
// * version : 1.0
// * author : WaterCloud.Framework
// * FileName: Notice.cs
// * history : Created by T4 04/13/2020 16:51:21
// </copyright>
//-----------------------------------------------------------------------
using SqlSugar;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using WaterCloud.Code;
using WaterCloud.DataBase;
using WaterCloud.Domain.SystemOrganize;
namespace WaterCloud.Service.SystemOrganize
{
public class NoticeService : BaseService<NoticeEntity>, IDenpendency
{
public NoticeService(ISqlSugarClient context) : base(context)
{
}
public async Task<List<NoticeEntity>> GetList(string keyword)
{
var query = repository.IQueryable();
if (!string.IsNullOrEmpty(keyword))
{
query = query.Where(a => a.F_Title.Contains(keyword) || a.F_Content.Contains(keyword));
}
return await query.Where(a => a.F_DeleteMark == false).ToListAsync();
}
public async Task<List<NoticeEntity>> GetLookList(SoulPage<NoticeEntity> pagination, string keyword = "")
{
//反格式化显示只能用"等于",其他不支持
Dictionary<string, Dictionary<string, string>> dic = new Dictionary<string, Dictionary<string, string>>();
Dictionary<string, string> enabledDic = new Dictionary<string, string>();
enabledDic.Add("1", "有效");
enabledDic.Add("0", "无效");
dic.Add("F_EnabledMark", enabledDic);
pagination = ChangeSoulData(dic, pagination);
var query = repository.IQueryable().Where(a => a.F_DeleteMark == false);
if (!string.IsNullOrEmpty(keyword))
{
query = query.Where(a => a.F_Title.Contains(keyword) || a.F_Content.Contains(keyword));
}
//权限过滤(保证分页参数存在)
query = GetDataPrivilege("a", "", query);
return await query.ToPageListAsync(pagination);
}
public async Task<NoticeEntity> GetLookForm(string keyValue)
{
var data = await repository.FindEntity(keyValue);
return GetFieldsFilterData(data);
}
public async Task<NoticeEntity> GetForm(string keyValue)
{
var data = await repository.FindEntity(keyValue);
return data;
}
public async Task SubmitForm(NoticeEntity entity, string keyValue)
{
if (!string.IsNullOrEmpty(keyValue))
{
entity.Modify(keyValue);
await repository.Update(entity);
}
else
{
entity.F_CreatorUserName = currentuser.UserName;
entity.F_DeleteMark = false;
entity.Create();
await repository.Insert(entity);
}
}
public async Task DeleteForm(string keyValue)
{
var ids = keyValue.Split(',');
await repository.Delete(a => ids.Contains(a.F_Id));
}
}
}

View File

@@ -0,0 +1,94 @@
/*******************************************************************************
* Copyright © 2020 WaterCloud.Framework 版权所有
* Author: WaterCloud
* Description: WaterCloud快速开发平台
* Website
*********************************************************************************/
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using WaterCloud.Domain.SystemOrganize;
namespace WaterCloud.Service.SystemOrganize
{
public class OrganizeService : BaseService<OrganizeEntity>, IDenpendency
{
public OrganizeService(ISqlSugarClient context) : base(context)
{
}
public async Task<List<OrganizeExtend>> GetList()
{
var query = GetQuery();
return await query.Where(a => a.F_DeleteMark == false).ToListAsync();
}
public async Task<List<OrganizeExtend>> GetLookList()
{
var query = GetQuery().Where(a => a.F_DeleteMark == false);
query = GetDataPrivilege("a", "", query);
return await query.OrderBy(a => a.F_SortCode).ToListAsync();
}
public async Task<OrganizeExtend> GetLookForm(string keyValue)
{
var data = await GetQuery().FirstAsync(a => a.F_Id == keyValue);
return GetFieldsFilterData(data);
}
public async Task<OrganizeExtend> GetForm(string keyValue)
{
var data = await GetQuery().FirstAsync(a => a.F_Id == keyValue);
return data;
}
private ISugarQueryable<OrganizeExtend> GetQuery()
{
var query = repository.Db.Queryable<OrganizeEntity, UserEntity>((a, b) => new JoinQueryInfos(
JoinType.Left, a.F_ManagerId == b.F_Id
)).Where(a => a.F_DeleteMark == false)
.Select((a, b) => new OrganizeExtend
{
F_Id = a.F_Id.SelectAll(),
F_ManagerName = b.F_RealName
}).MergeTable();
return query;
}
public async Task DeleteForm(string keyValue)
{
if (await repository.IQueryable(a => a.F_ParentId.Equals(keyValue)).AnyAsync())
{
throw new Exception("删除失败!操作的对象包含了下级数据。");
}
else
{
if (await repository.Db.Queryable<UserEntity>().Where(a => a.F_CompanyId == keyValue).AnyAsync() || await repository.Db.Queryable<UserEntity>().Where(a => a.F_OrganizeId == keyValue).AnyAsync())
{
throw new Exception("组织使用中,无法删除");
}
await repository.Delete(a => a.F_Id == keyValue);
}
}
public async Task SubmitForm(OrganizeEntity organizeEntity, string keyValue)
{
if (!string.IsNullOrEmpty(keyValue))
{
organizeEntity.Modify(keyValue);
await repository.Update(organizeEntity);
}
else
{
organizeEntity.F_AllowDelete = false;
organizeEntity.F_AllowEdit = false;
organizeEntity.F_DeleteMark = false;
organizeEntity.Create();
await repository.Insert(organizeEntity);
}
}
}
}

View File

@@ -0,0 +1,392 @@
/*******************************************************************************
* Copyright © 2020 WaterCloud.Framework 版权所有
* Author: WaterCloud
* Description: WaterCloud快速开发平台
* Website
*********************************************************************************/
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using WaterCloud.Code;
using WaterCloud.Domain.SystemManage;
using WaterCloud.Domain.SystemOrganize;
using WaterCloud.Domain.ViewModel;
using WaterCloud.Service.SystemManage;
namespace WaterCloud.Service.SystemOrganize
{
public class RoleAuthorizeService : BaseService<RoleAuthorizeEntity>, IDenpendency
{
public ModuleService moduleApp { get; set; }
public ModuleButtonService moduleButtonApp { get; set; }
public ModuleFieldsService moduleFieldsApp { get; set; }
public UserService userApp { get; set; }
public RoleService roleApp { get; set; }
/// <summary>
/// 缓存操作类
/// </summary>
private string cacheKey = GlobalContext.SystemConfig.ProjectPrefix + "_authorizeurldata_";// +权限
public RoleAuthorizeService(ISqlSugarClient context) : base(context)
{
}
public async Task<List<RoleAuthorizeEntity>> GetList(string ObjectId)
{
var query = repository.IQueryable();
query = query.Where(a => a.F_ObjectId == ObjectId);
return await query.ToListAsync();
}
public async Task<List<ModuleEntity>> GetMenuList(string roleId)
{
var data = new List<ModuleEntity>();
if (currentuser.IsAdmin)
{
data = await moduleApp.GetList();
data = data.Where(a => a.F_IsMenu == true && a.F_EnabledMark == true).ToList();
}
else
{
var rolelist = roleId.Split(',');
var moduledata = await moduleApp.GetList();
moduledata = moduledata.Where(a => a.F_IsMenu == true && a.F_EnabledMark == true).ToList();
var role = repository.Db.Queryable<RoleEntity>().Where(a => rolelist.Contains(a.F_Id) && a.F_EnabledMark == true).ToList();
if (role.Count == 0)
{
return data;
}
var authorizedata = repository.IQueryable().Where(a => rolelist.Contains(a.F_ObjectId) && a.F_ItemType == 1).Distinct().ToList();
foreach (var item in authorizedata)
{
ModuleEntity moduleEntity = moduledata.Find(a => a.F_Id == item.F_ItemId && a.F_IsPublic == false);
if (moduleEntity != null && data.Find(a => a.F_Id == moduleEntity.F_Id) == null)
{
data.Add(moduleEntity);
}
}
data.AddRange(moduledata.Where(a => a.F_IsPublic == true));
}
return data.OrderBy(a => a.F_SortCode).ToList();
}
public async Task<List<ModuleButtonEntity>> GetButtonList(string roleId)
{
var data = new List<ModuleButtonEntity>();
if (currentuser.IsAdmin)
{
data = await moduleButtonApp.GetListNew();
}
else
{
var buttondata = await moduleButtonApp.GetListNew();
var role = await roleApp.GetForm(roleId);
if (role == null || role.F_EnabledMark == false)
{
return data;
}
var authorizedata = repository.IQueryable().Where(a => a.F_ObjectId == roleId && a.F_ItemType == 2).ToList();
foreach (var item in authorizedata)
{
ModuleButtonEntity moduleButtonEntity = buttondata.Find(a => a.F_Id == item.F_ItemId && a.F_IsPublic == false);
if (moduleButtonEntity != null)
{
data.Add(moduleButtonEntity);
}
}
data.AddRange(buttondata.Where(a => a.F_IsPublic == true));
}
return data.OrderBy(a => a.F_SortCode).ToList();
}
public async Task<List<ModuleFieldsEntity>> GetFieldsList(string roleId)
{
var data = new List<ModuleFieldsEntity>();
if (currentuser.IsAdmin)
{
data = await moduleFieldsApp.GetListNew();
}
else
{
var fieldsdata = await moduleFieldsApp.GetListNew();
var role = await roleApp.GetForm(roleId);
if (role == null || role.F_EnabledMark == false)
{
return data;
}
var authorizedata = repository.IQueryable().Where(a => a.F_ObjectId == roleId && a.F_ItemType == 3).ToList();
foreach (var item in authorizedata)
{
ModuleFieldsEntity moduleFieldsEntity = fieldsdata.Where(a => a.F_Id == item.F_ItemId && a.F_IsPublic == false).FirstOrDefault();
if (moduleFieldsEntity != null)
{
data.Add(moduleFieldsEntity);
}
}
data.AddRange(fieldsdata.Where(a => a.F_IsPublic == true));
}
return data.OrderByDescending(a => a.F_CreatorTime).ToList();
}
public async Task<bool> ActionValidate(string action, bool isAuthorize = false)
{
var user = await userApp.GetForm(currentuser.UserId);
var temps = isAuthorize ? action.Split(',') : new string[0];
if (user == null || user.F_EnabledMark == false)
{
return false;
}
var authorizeurldata = new List<AuthorizeActionModel>();
var cachedata = await CacheHelper.GetAsync<Dictionary<string, List<AuthorizeActionModel>>>(cacheKey + repository.Db.CurrentConnectionConfig.ConfigId + "_list");
if (cachedata == null)
{
cachedata = new Dictionary<string, List<AuthorizeActionModel>>();
}
if (user.F_IsAdmin == true)
{
if (await repository.Db.Queryable<ModuleEntity>().Where(a => a.F_UrlAddress == action || temps.Contains(a.F_Authorize)).AnyAsync()
|| await repository.Db.Queryable<ModuleButtonEntity>().Where(a => a.F_UrlAddress == action || temps.Contains(a.F_Authorize)).AnyAsync())
{
return true;
}
return false;
}
else
{
var rolelist = user.F_RoleId.Split(',');
foreach (var roles in rolelist)
{
if (!cachedata.ContainsKey(roles))
{
var moduledata = await moduleApp.GetList();
moduledata = moduledata.Where(a => a.F_EnabledMark == true).ToList();
var buttondata = await moduleButtonApp.GetList();
buttondata = buttondata.Where(a => a.F_EnabledMark == true).ToList();
var role = await roleApp.GetForm(roles);
if (role != null && role.F_EnabledMark == true)
{
var authdata = new List<AuthorizeActionModel>();
var authorizedata = await GetList(roles);
foreach (var item in authorizedata)
{
try
{
if (item.F_ItemType == 1)
{
ModuleEntity moduleEntity = moduledata.Where(a => a.F_Id == item.F_ItemId && a.F_IsPublic == false).FirstOrDefault();
if (moduleEntity != null)
{
authdata.Add(new AuthorizeActionModel { F_Id = moduleEntity.F_Id, F_UrlAddress = moduleEntity.F_UrlAddress, F_Authorize = moduleEntity.F_Authorize });
}
}
else if (item.F_ItemType == 2)
{
ModuleButtonEntity moduleButtonEntity = buttondata.Where(a => a.F_Id == item.F_ItemId && a.F_IsPublic == false).FirstOrDefault();
if (moduleButtonEntity != null)
{
authdata.Add(new AuthorizeActionModel { F_Id = moduleButtonEntity.F_ModuleId, F_UrlAddress = moduleButtonEntity.F_UrlAddress, F_Authorize = moduleButtonEntity.F_Authorize });
}
}
}
catch (Exception ex)
{
string e = ex.Message;
continue;
}
}
authdata.AddRange(moduledata.Where(a => a.F_IsPublic == true).Select(a => new AuthorizeActionModel { F_Id = a.F_Id, F_UrlAddress = a.F_UrlAddress, F_Authorize = a.F_Authorize }).ToList());
authdata.AddRange(buttondata.Where(a => a.F_IsPublic == true).Select(a => new AuthorizeActionModel { F_Id = a.F_ModuleId, F_UrlAddress = a.F_UrlAddress, F_Authorize = a.F_Authorize }).ToList());
cachedata.Add(roles, authdata);
authorizeurldata.AddRange(authdata);
await CacheHelper.RemoveAsync(cacheKey + repository.Db.CurrentConnectionConfig.ConfigId + "_list");
await CacheHelper.SetAsync(cacheKey + repository.Db.CurrentConnectionConfig.ConfigId + "_list", cachedata);
}
}
else
{
authorizeurldata.AddRange(cachedata[roles]);
}
}
}
var module = authorizeurldata.Find(a => a.F_UrlAddress == action || temps.Contains(a.F_Authorize));
if (module != null)
{
return true;
}
return false;
}
public async Task<bool> CheckReturnUrl(string userId, string url, bool isAll = false)
{
var user = await userApp.GetForm(userId);
if (isAll == false && (user == null || user.F_EnabledMark == false))
{
return false;
}
if (isAll == true || user.F_IsAdmin == true)
{
if (repository.Db.Queryable<ModuleEntity>().Where(a => a.F_UrlAddress == url).Any() || repository.Db.Queryable<ModuleButtonEntity>().Where(a => a.F_UrlAddress == url).Any())
{
return true;
}
return false;
}
else
{
var authorizeurldata = new List<AuthorizeActionModel>();
var rolelist = user.F_RoleId.Split(',');
var cachedata = await CacheHelper.GetAsync<Dictionary<string, List<AuthorizeActionModel>>>(cacheKey + repository.Db.CurrentConnectionConfig.ConfigId + "_list");
if (cachedata == null)
{
cachedata = new Dictionary<string, List<AuthorizeActionModel>>();
}
foreach (var roles in rolelist)
{
if (!cachedata.ContainsKey(roles))
{
var moduledata = await moduleApp.GetList();
moduledata = moduledata.Where(a => a.F_EnabledMark == true).ToList();
var buttondata = await moduleButtonApp.GetList();
buttondata = buttondata.Where(a => a.F_EnabledMark == true).ToList();
var role = await roleApp.GetForm(roles);
if (role != null && role.F_EnabledMark == true)
{
var authdata = new List<AuthorizeActionModel>();
var authorizedata = await GetList(roles);
foreach (var item in authorizedata)
{
try
{
if (item.F_ItemType == 1)
{
ModuleEntity moduleEntity = moduledata.Where(a => a.F_Id == item.F_ItemId && a.F_IsPublic == false).FirstOrDefault();
if (moduleEntity != null)
{
authdata.Add(new AuthorizeActionModel { F_Id = moduleEntity.F_Id, F_UrlAddress = moduleEntity.F_UrlAddress, F_Authorize = moduleEntity.F_Authorize });
}
}
else if (item.F_ItemType == 2)
{
ModuleButtonEntity moduleButtonEntity = buttondata.Where(a => a.F_Id == item.F_ItemId && a.F_IsPublic == false).FirstOrDefault();
if (moduleButtonEntity != null)
{
authdata.Add(new AuthorizeActionModel { F_Id = moduleButtonEntity.F_ModuleId, F_UrlAddress = moduleButtonEntity.F_UrlAddress, F_Authorize = moduleButtonEntity.F_Authorize });
}
}
}
catch (Exception ex)
{
string e = ex.Message;
continue;
}
}
authdata.AddRange(moduledata.Where(a => a.F_IsPublic == true).Select(a => new AuthorizeActionModel { F_Id = a.F_Id, F_UrlAddress = a.F_UrlAddress, F_Authorize = a.F_Authorize }).ToList());
authdata.AddRange(buttondata.Where(a => a.F_IsPublic == true).Select(a => new AuthorizeActionModel { F_Id = a.F_ModuleId, F_UrlAddress = a.F_UrlAddress, F_Authorize = a.F_Authorize }).ToList());
cachedata.Add(roles, authdata);
authorizeurldata.AddRange(authdata);
await CacheHelper.RemoveAsync(cacheKey + repository.Db.CurrentConnectionConfig.ConfigId + "_list");
await CacheHelper.SetAsync(cacheKey + repository.Db.CurrentConnectionConfig.ConfigId + "_list", cachedata);
}
}
else
{
authorizeurldata.AddRange(cachedata[roles]);
}
}
var module = authorizeurldata.Find(a => a.F_UrlAddress == url);
if (module != null)
{
return true;
}
return false;
}
}
public async Task<bool> RoleValidate()
{
var current = OperatorProvider.Provider.GetCurrent();
if (current == null || string.IsNullOrEmpty(current.UserId))
{
return false;
}
var user = await userApp.GetForm(current.UserId);
if (user == null || user.F_EnabledMark == false)
{
return false;
}
if (user.F_IsAdmin == true)
{
return true;
}
var authorizeurldata = new List<AuthorizeActionModel>();
var rolelist = user.F_RoleId.Split(',');
var cachedata = await CacheHelper.GetAsync<Dictionary<string, List<AuthorizeActionModel>>>(cacheKey + repository.Db.CurrentConnectionConfig.ConfigId + "_list");
if (cachedata == null)
{
cachedata = new Dictionary<string, List<AuthorizeActionModel>>();
}
foreach (var roles in rolelist)
{
if (!cachedata.ContainsKey(roles))
{
var moduledata = await moduleApp.GetList();
moduledata = moduledata.Where(a => a.F_EnabledMark == true).ToList();
var buttondata = await moduleButtonApp.GetList();
buttondata = buttondata.Where(a => a.F_EnabledMark == true).ToList();
var role = await roleApp.GetForm(roles);
if (role != null && role.F_EnabledMark == true)
{
var authdata = new List<AuthorizeActionModel>();
var authorizedata = await GetList(roles);
foreach (var item in authorizedata)
{
try
{
if (item.F_ItemType == 1)
{
ModuleEntity moduleEntity = moduledata.Where(a => a.F_Id == item.F_ItemId && a.F_IsPublic == false).FirstOrDefault();
if (moduleEntity != null)
{
authdata.Add(new AuthorizeActionModel { F_Id = moduleEntity.F_Id, F_UrlAddress = moduleEntity.F_UrlAddress, F_Authorize = moduleEntity.F_Authorize });
}
}
else if (item.F_ItemType == 2)
{
ModuleButtonEntity moduleButtonEntity = buttondata.Where(a => a.F_Id == item.F_ItemId && a.F_IsPublic == false).FirstOrDefault();
if (moduleButtonEntity != null)
{
authdata.Add(new AuthorizeActionModel { F_Id = moduleButtonEntity.F_ModuleId, F_UrlAddress = moduleButtonEntity.F_UrlAddress, F_Authorize = moduleButtonEntity.F_Authorize });
}
}
}
catch (Exception ex)
{
string e = ex.Message;
continue;
}
}
authdata.AddRange(moduledata.Where(a => a.F_IsPublic == true).Select(a => new AuthorizeActionModel { F_Id = a.F_Id, F_UrlAddress = a.F_UrlAddress, F_Authorize = a.F_Authorize }).ToList());
authdata.AddRange(buttondata.Where(a => a.F_IsPublic == true).Select(a => new AuthorizeActionModel { F_Id = a.F_ModuleId, F_UrlAddress = a.F_UrlAddress, F_Authorize = a.F_Authorize }).ToList());
cachedata.Add(roles, authdata);
authorizeurldata.AddRange(authdata);
await CacheHelper.RemoveAsync(cacheKey + repository.Db.CurrentConnectionConfig.ConfigId + "_list");
await CacheHelper.SetAsync(cacheKey + repository.Db.CurrentConnectionConfig.ConfigId + "_list", cachedata);
}
}
else
{
authorizeurldata.AddRange(cachedata[roles]);
}
}
if (authorizeurldata.Count > 0)
{
return true;
}
return false;
}
}
}

View File

@@ -0,0 +1,188 @@
/*******************************************************************************
* Copyright © 2020 WaterCloud.Framework 版权所有
* Author: WaterCloud
* Description: WaterCloud快速开发平台
* Website
*********************************************************************************/
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using WaterCloud.Code;
using WaterCloud.DataBase;
using WaterCloud.Domain.SystemOrganize;
using WaterCloud.Service.SystemManage;
namespace WaterCloud.Service.SystemOrganize
{
public class RoleService : BaseService<RoleEntity>, IDenpendency
{
public ModuleService moduleApp { get; set; }
public ModuleButtonService moduleButtonApp { get; set; }
public ModuleFieldsService moduleFieldsApp { get; set; }
public ItemsDataService itemsApp { get; set; }
/// <summary>
/// 缓存操作类
/// </summary>
private string authorizecacheKey = GlobalContext.SystemConfig.ProjectPrefix + "_authorizeurldata_";// +权限
//获取类名
public RoleService(ISqlSugarClient context) : base(context)
{
}
public async Task<List<RoleExtend>> GetList(string keyword = "")
{
var query = GetQuery();
if (!string.IsNullOrEmpty(keyword))
{
query = query.Where(a => a.F_FullName.Contains(keyword) || a.F_EnCode.Contains(keyword));
}
return await query.ToListAsync();
}
public async Task<List<RoleExtend>> GetLookList(SoulPage<RoleExtend> pagination, string keyword = "")
{
//反格式化显示只能用"等于",其他不支持
Dictionary<string, Dictionary<string, string>> dic = new Dictionary<string, Dictionary<string, string>>();
Dictionary<string, string> enabledTemp = new Dictionary<string, string>();
enabledTemp.Add("1", "有效");
enabledTemp.Add("0", "无效");
dic.Add("F_EnabledMark", enabledTemp);
var setList = await itemsApp.GetItemList("RoleType");
Dictionary<string, string> messageTypeTemp = new Dictionary<string, string>();
foreach (var item in setList)
{
messageTypeTemp.Add(item.F_ItemCode, item.F_ItemName);
}
dic.Add("F_Type", messageTypeTemp);
pagination = ChangeSoulData(dic, pagination);
//获取数据权限
var query = GetQuery();
if (!string.IsNullOrEmpty(keyword))
{
query = query.Where(a => a.F_FullName.Contains(keyword) || a.F_EnCode.Contains(keyword));
}
query = GetDataPrivilege("a", "", query);
return await query.ToPageListAsync(pagination);
}
public async Task<RoleEntity> GetForm(string keyValue)
{
var data = await repository.FindEntity(keyValue);
return data;
}
public async Task<RoleEntity> GetLookForm(string keyValue)
{
var data = await repository.FindEntity(keyValue);
return GetFieldsFilterData(data);
}
private ISugarQueryable<RoleExtend> GetQuery()
{
var query = repository.Db.Queryable<RoleEntity, SystemSetEntity>((a, b) => new JoinQueryInfos(
JoinType.Left, a.F_CompanyId == b.F_Id
)).Where(a => a.F_DeleteMark == false && a.F_Category == 1)
.Select((a, b) => new RoleExtend
{
F_Id = a.F_Id,
F_AllowDelete = a.F_AllowDelete,
F_AllowEdit = a.F_AllowEdit,
F_Category = a.F_Category,
F_CreatorTime = a.F_CreatorTime,
F_CreatorUserId = a.F_CreatorUserId,
F_Description = a.F_Description,
F_DeleteMark = a.F_DeleteMark,
F_EnabledMark = a.F_EnabledMark,
F_EnCode = a.F_EnCode,
F_FullName = a.F_FullName,
F_CompanyId = a.F_CompanyId,
F_SortCode = a.F_SortCode,
F_Type = a.F_Type,
F_CompanyName = b.F_CompanyName,
}).MergeTable();
return query;
}
public async Task DeleteForm(string keyValue)
{
if (await repository.Db.Queryable<UserEntity>().Where(a => a.F_RoleId.Contains(keyValue)).AnyAsync())
{
throw new Exception("角色使用中,无法删除");
}
repository.Db.Ado.BeginTran();
await repository.Delete(a => a.F_Id == keyValue);
await repository.Db.Deleteable<RoleAuthorizeEntity>(a => a.F_ObjectId == keyValue).ExecuteCommandAsync();
repository.Db.Ado.CommitTran();
await CacheHelper.RemoveAsync(authorizecacheKey + repository.Db.CurrentConnectionConfig.ConfigId + "_list");
}
public async Task SubmitForm(RoleEntity roleEntity, string[] permissionIds, string[] permissionfieldsIds, string keyValue)
{
if (!string.IsNullOrEmpty(keyValue))
{
roleEntity.F_Id = keyValue;
}
else
{
roleEntity.F_DeleteMark = false;
roleEntity.F_AllowEdit = false;
roleEntity.F_AllowDelete = false;
roleEntity.Create();
}
var moduledata = await moduleApp.GetList();
var buttondata = await moduleButtonApp.GetList();
var fieldsdata = await moduleFieldsApp.GetList();
List<RoleAuthorizeEntity> roleAuthorizeEntitys = new List<RoleAuthorizeEntity>();
foreach (var itemId in permissionIds)
{
RoleAuthorizeEntity roleAuthorizeEntity = new RoleAuthorizeEntity();
roleAuthorizeEntity.F_Id = Utils.GuId();
roleAuthorizeEntity.F_ObjectType = 1;
roleAuthorizeEntity.F_ObjectId = roleEntity.F_Id;
roleAuthorizeEntity.F_ItemId = itemId;
if (moduledata.Find(a => a.F_Id == itemId) != null)
{
roleAuthorizeEntity.F_ItemType = 1;
roleAuthorizeEntitys.Add(roleAuthorizeEntity);
}
if (buttondata.Find(a => a.F_Id == itemId) != null)
{
roleAuthorizeEntity.F_ItemType = 2;
roleAuthorizeEntitys.Add(roleAuthorizeEntity);
}
}
foreach (var itemId in permissionfieldsIds)
{
RoleAuthorizeEntity roleAuthorizeEntity = new RoleAuthorizeEntity();
roleAuthorizeEntity.F_Id = Utils.GuId();
roleAuthorizeEntity.F_ObjectType = 1;
roleAuthorizeEntity.F_ObjectId = roleEntity.F_Id;
roleAuthorizeEntity.F_ItemId = itemId;
if (fieldsdata.Find(a => a.F_Id == itemId) != null)
{
roleAuthorizeEntity.F_ItemType = 3;
roleAuthorizeEntitys.Add(roleAuthorizeEntity);
}
}
repository.Db.Ado.BeginTran();
if (!string.IsNullOrEmpty(keyValue))
{
await repository.Update(roleEntity);
}
else
{
roleEntity.F_Category = 1;
await repository.Insert(roleEntity);
}
await repository.Db.Deleteable<RoleAuthorizeEntity>(a => a.F_ObjectId == roleEntity.F_Id).ExecuteCommandAsync();
await repository.Db.Insertable(roleAuthorizeEntitys).ExecuteCommandAsync();
repository.Db.Ado.CommitTran();
await CacheHelper.RemoveAsync(authorizecacheKey + repository.Db.CurrentConnectionConfig.ConfigId + "_list");
}
}
}

View File

@@ -0,0 +1,371 @@
using SqlSugar;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
using WaterCloud.Code;
using WaterCloud.DataBase;
using WaterCloud.Domain.SystemManage;
using WaterCloud.Domain.SystemOrganize;
using WaterCloud.Service.SystemManage;
namespace WaterCloud.Service.SystemOrganize
{
/// <summary>
/// 创 建:超级管理员
/// 日 期2020-06-12 13:50
/// 描 述:系统设置服务类
/// </summary>
public class SystemSetService : BaseService<SystemSetEntity>, IDenpendency
{
private string cacheKeyOperator = GlobalContext.SystemConfig.ProjectPrefix + "_operator_";// +登录者token
private static string cacheKey = GlobalContext.SystemConfig.ProjectPrefix + "_dblist";// 数据库键
public ModuleService moduleApp { get; set; }
public ModuleButtonService moduleButtonApp { get; set; }
public ModuleFieldsService moduleFieldsApp { get; set; }
public SystemSetService(ISqlSugarClient context) : base(context)
{
}
#region
public async Task<List<SystemSetEntity>> GetList(string keyword = "")
{
var query = repository.IQueryable();
if (!string.IsNullOrEmpty(keyword))
{
query = query.Where(a => a.F_CompanyName.Contains(keyword) || a.F_ProjectName.Contains(keyword));
}
return await query.Where(a => a.F_DeleteMark == false).OrderBy(a => a.F_Id, OrderByType.Desc).ToListAsync();
}
public async Task<List<SystemSetEntity>> GetLookList(string keyword = "")
{
var query = repository.IQueryable().Where(a => a.F_DeleteMark == false);
if (!string.IsNullOrEmpty(keyword))
{
query = query.Where(a => a.F_CompanyName.Contains(keyword) || a.F_ProjectName.Contains(keyword));
}
query = GetDataPrivilege("a", "", query);
return await query.OrderBy(a => a.F_Id, OrderByType.Desc).ToListAsync();
}
public async Task<SystemSetEntity> GetFormByHost(string host)
{
repository.ChangeEntityDb(GlobalContext.SystemConfig.MainDbNumber);
var query = repository.IQueryable();
if (!string.IsNullOrEmpty(host))
{
//此处需修改
query = query.Where(a => a.F_HostUrl.Contains(host));
}
else
{
query = query.Where(a => a.F_DbNumber == "0");
}
if (!await query.Clone().AnyAsync())
{
query = repository.IQueryable();
query = query.Where(a => a.F_DbNumber == "0");
}
var data = await query.Where(a => a.F_DeleteMark == false).FirstAsync();
return data;
}
public async Task<List<SystemSetEntity>> GetLookList(Pagination pagination, string keyword = "")
{
var query = repository.IQueryable().Where(a => a.F_DeleteMark == false && a.F_DbNumber != "0");
if (!string.IsNullOrEmpty(keyword))
{
//此处需修改
query = query.Where(a => a.F_CompanyName.Contains(keyword) || a.F_ProjectName.Contains(keyword));
}
query = GetDataPrivilege("a", "", query);
return await query.ToPageListAsync(pagination);
}
public async Task<SystemSetEntity> GetForm(string keyValue)
{
var data = await repository.FindEntity(keyValue);
return data;
}
#endregion
public async Task<SystemSetEntity> GetLookForm(string keyValue)
{
var data = await repository.FindEntity(keyValue);
return GetFieldsFilterData(data);
}
#region
public async Task SubmitForm(SystemSetEntity entity, string keyValue, string[] permissionIds = null, string[] permissionfieldsIds = null)
{
repository.ChangeEntityDb(GlobalContext.SystemConfig.MainDbNumber);
List<RoleAuthorizeEntity> roleAuthorizeEntitys = new List<RoleAuthorizeEntity>();
List<ModuleEntity> modules = new List<ModuleEntity>();
List<ModuleButtonEntity> modulebtns = new List<ModuleButtonEntity>();
List<ModuleFieldsEntity> modulefileds = new List<ModuleFieldsEntity>();
//字典数据
var itemsTypes = await repository.Db.Queryable<ItemsEntity>().ToListAsync();
var itemsDetails = await repository.Db.Queryable<ItemsDetailEntity>().ToListAsync();
repository.Tenant.BeginTran();
if (string.IsNullOrEmpty(keyValue))
{
entity.F_DeleteMark = false;
entity.Create();
await repository.Insert(entity);
if (permissionIds != null)
{
var moduledata = await moduleApp.GetList();
var buttondata = await moduleButtonApp.GetList();
foreach (var itemId in permissionIds.Distinct())
{
RoleAuthorizeEntity roleAuthorizeEntity = new RoleAuthorizeEntity();
roleAuthorizeEntity.F_Id = Utils.GuId();
roleAuthorizeEntity.F_ObjectType = 2;
roleAuthorizeEntity.F_ObjectId = entity.F_Id;
roleAuthorizeEntity.F_ItemId = itemId;
if (moduledata.Find(a => a.F_Id == itemId) != null)
{
roleAuthorizeEntity.F_ItemType = 1;
roleAuthorizeEntitys.Add(roleAuthorizeEntity);
modules.Add(moduledata.Find(a => a.F_Id == itemId));
}
if (buttondata.Find(a => a.F_Id == itemId) != null)
{
roleAuthorizeEntity.F_ItemType = 2;
roleAuthorizeEntitys.Add(roleAuthorizeEntity);
modulebtns.Add(buttondata.Find(a => a.F_Id == itemId));
}
}
//排除租户
modules.AddRange(moduledata.Where(a => a.F_IsPublic == true && a.F_EnabledMark == true && a.F_DeleteMark == false && a.F_EnCode != "SystemSet"));
modulebtns.AddRange(buttondata.Where(a => a.F_IsPublic == true && a.F_EnabledMark == true && a.F_DeleteMark == false));
}
if (permissionfieldsIds != null)
{
var fieldsdata = await moduleFieldsApp.GetList();
foreach (var itemId in permissionfieldsIds.Distinct())
{
RoleAuthorizeEntity roleAuthorizeEntity = new RoleAuthorizeEntity();
roleAuthorizeEntity.F_Id = Utils.GuId();
roleAuthorizeEntity.F_ObjectType = 2;
roleAuthorizeEntity.F_ObjectId = entity.F_Id;
roleAuthorizeEntity.F_ItemId = itemId;
if (fieldsdata.Find(a => a.F_Id == itemId) != null)
{
roleAuthorizeEntity.F_ItemType = 3;
roleAuthorizeEntitys.Add(roleAuthorizeEntity);
modulefileds.Add(fieldsdata.Find(a => a.F_Id == itemId));
}
}
modulefileds.AddRange(fieldsdata.Where(a => a.F_IsPublic == true && a.F_EnabledMark == true && a.F_DeleteMark == false));
}
//新建租户权限
if (roleAuthorizeEntitys.Count > 0)
{
await repository.Db.Insertable(roleAuthorizeEntitys).ExecuteCommandAsync();
}
//新建数据库和表
using (var db = new SqlSugarClient(DBContexHelper.Contex(entity.F_DbString, entity.F_DBProvider)))
{
//判断数据库有没有被使用
db.DbMaintenance.CreateDatabase();
if (db.DbMaintenance.GetTableInfoList(false).Where(a => a.Name.ToLower() == "sys_module").Any())
throw new Exception("数据库已存在,请重新设置数据库");
var path = AppDomain.CurrentDomain.RelativeSearchPath ?? AppDomain.CurrentDomain.BaseDirectory;
//反射取指定前后缀的dll
var referencedAssemblies = Directory.GetFiles(path, "WaterCloud.Domain.dll").Select(Assembly.LoadFrom).ToArray();
var types = referencedAssemblies.SelectMany(a => a.GetTypes().ToArray());
var implementType = types.Where(x => x.IsClass);
//忽视类列表
var ignoreTables = new List<string> { "RoleExtend", "UserExtend" };
foreach (var item in implementType)
{
try
{
if (item.GetCustomAttributes(typeof(SugarTable), true).FirstOrDefault((x => x.GetType() == typeof(SugarTable))) is SugarTable sugarTable && !ignoreTables.Any(a => a == item.Name))
{
db.CodeFirst.SetStringDefaultLength(50).InitTables(item);
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
continue;
}
}
//新建账户,密码
UserEntity user = new UserEntity();
user.Create();
user.F_Account = entity.F_AdminAccount;
user.F_RealName = entity.F_CompanyName;
user.F_Gender = true;
user.F_CompanyId = entity.F_Id;
user.F_IsAdmin = true;
user.F_DeleteMark = false;
user.F_EnabledMark = true;
user.F_IsBoss = false;
user.F_IsLeaderInDepts = false;
user.F_SortCode = 0;
user.F_IsSenior = false;
UserLogOnEntity logon = new UserLogOnEntity();
logon.F_Id = user.F_Id;
logon.F_UserId = user.F_Id;
logon.F_UserSecretkey = Md5.md5(Utils.CreateNo(), 16).ToLower();
logon.F_UserPassword = Md5.md5(DESEncrypt.Encrypt(Md5.md5(entity.F_AdminPassword, 32).ToLower(), logon.F_UserSecretkey).ToLower(), 32).ToLower();
db.Insertable(user).ExecuteCommand();
db.Insertable(logon).ExecuteCommand();
await db.Insertable(roleAuthorizeEntitys).ExecuteCommandAsync();
await db.Insertable(entity).ExecuteCommandAsync();
//新建菜单
await db.Insertable(modules).ExecuteCommandAsync();
await db.Insertable(modulebtns).ExecuteCommandAsync();
await db.Insertable(modulefileds).ExecuteCommandAsync();
//同步字典
await db.Deleteable<ItemsEntity>().ExecuteCommandAsync();
await db.Deleteable<ItemsDetailEntity>().ExecuteCommandAsync();
await db.Insertable(itemsTypes).ExecuteCommandAsync();
await db.Insertable(itemsDetails).ExecuteCommandAsync();
}
}
else
{
entity.Modify(keyValue);
if (permissionIds != null)
{
var moduledata = await moduleApp.GetList();
var buttondata = await moduleButtonApp.GetList();
foreach (var itemId in permissionIds.Distinct())
{
RoleAuthorizeEntity roleAuthorizeEntity = new RoleAuthorizeEntity();
roleAuthorizeEntity.F_Id = Utils.GuId();
roleAuthorizeEntity.F_ObjectType = 2;
roleAuthorizeEntity.F_ObjectId = entity.F_Id;
roleAuthorizeEntity.F_ItemId = itemId;
if (moduledata.Find(a => a.F_Id == itemId) != null)
{
roleAuthorizeEntity.F_ItemType = 1;
roleAuthorizeEntitys.Add(roleAuthorizeEntity);
modules.Add(moduledata.Find(a => a.F_Id == itemId));
}
if (buttondata.Find(a => a.F_Id == itemId) != null)
{
roleAuthorizeEntity.F_ItemType = 2;
roleAuthorizeEntitys.Add(roleAuthorizeEntity);
modulebtns.Add(buttondata.Find(a => a.F_Id == itemId));
}
}
}
if (permissionfieldsIds != null)
{
var fieldsdata = await moduleFieldsApp.GetList();
foreach (var itemId in permissionfieldsIds.Distinct())
{
RoleAuthorizeEntity roleAuthorizeEntity = new RoleAuthorizeEntity();
roleAuthorizeEntity.F_Id = Utils.GuId();
roleAuthorizeEntity.F_ObjectType = 2;
roleAuthorizeEntity.F_ObjectId = entity.F_Id;
roleAuthorizeEntity.F_ItemId = itemId;
if (fieldsdata.Find(a => a.F_Id == itemId) != null)
{
roleAuthorizeEntity.F_ItemType = 3;
roleAuthorizeEntitys.Add(roleAuthorizeEntity);
modulefileds.Add(fieldsdata.Find(a => a.F_Id == itemId));
}
}
}
if (roleAuthorizeEntitys.Count > 0)
{
await repository.Db.Deleteable<RoleAuthorizeEntity>(a => a.F_ObjectId == entity.F_Id).ExecuteCommandAsync();
await repository.Db.Insertable(roleAuthorizeEntitys).ExecuteCommandAsync();
}
//更新主库
if (currentuser.IsSuperAdmin == true)
{
await repository.Db.Updateable(entity).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommandAsync();
}
else
{
entity.F_AdminAccount = null;
entity.F_AdminPassword = null;
await repository.Db.Updateable(entity).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommandAsync();
}
//更新租户库
if (GlobalContext.SystemConfig.SqlMode == Define.SQL_TENANT)
{
var tenant = await repository.Db.Queryable<SystemSetEntity>().InSingleAsync(entity.F_Id);
repository.ChangeEntityDb(tenant.F_DbNumber);
var user = repository.Db.Queryable<UserEntity>().First(a => a.F_CompanyId == entity.F_Id && a.F_IsAdmin == true);
var userinfo = repository.Db.Queryable<UserLogOnEntity>().First(a => a.F_UserId == user.F_Id);
userinfo.F_UserSecretkey = Md5.md5(Utils.CreateNo(), 16).ToLower();
userinfo.F_UserPassword = Md5.md5(DESEncrypt.Encrypt(Md5.md5(entity.F_AdminPassword, 32).ToLower(), userinfo.F_UserSecretkey).ToLower(), 32).ToLower();
await repository.Db.Updateable<UserEntity>(a => new UserEntity
{
F_Account = entity.F_AdminAccount
}).Where(a => a.F_Id == user.F_Id).ExecuteCommandAsync();
await repository.Db.Updateable<UserLogOnEntity>(a => new UserLogOnEntity
{
F_UserPassword = userinfo.F_UserPassword,
F_UserSecretkey = userinfo.F_UserSecretkey
}).Where(a => a.F_Id == userinfo.F_Id).ExecuteCommandAsync();
await repository.Db.Updateable(entity).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommandAsync();
//更新菜单
if (roleAuthorizeEntitys.Count > 0)
{
await repository.Db.Deleteable<ModuleEntity>().ExecuteCommandAsync();
await repository.Db.Deleteable<ModuleButtonEntity>().ExecuteCommandAsync();
await repository.Db.Deleteable<ModuleFieldsEntity>().ExecuteCommandAsync();
await repository.Db.Insertable(modules).ExecuteCommandAsync();
await repository.Db.Insertable(modulebtns).ExecuteCommandAsync();
await repository.Db.Insertable(modulefileds).ExecuteCommandAsync();
}
//同步字典
await repository.Db.Deleteable<ItemsEntity>().ExecuteCommandAsync();
await repository.Db.Deleteable<ItemsDetailEntity>().ExecuteCommandAsync();
await repository.Db.Insertable(itemsTypes).ExecuteCommandAsync();
await repository.Db.Insertable(itemsDetails).ExecuteCommandAsync();
}
else
{
var user = repository.Db.Queryable<UserEntity>().First(a => a.F_CompanyId == entity.F_Id && a.F_IsAdmin == true);
var userinfo = repository.Db.Queryable<UserLogOnEntity>().First(a => a.F_UserId == user.F_Id);
userinfo.F_UserSecretkey = Md5.md5(Utils.CreateNo(), 16).ToLower();
userinfo.F_UserPassword = Md5.md5(DESEncrypt.Encrypt(Md5.md5(entity.F_AdminPassword, 32).ToLower(), userinfo.F_UserSecretkey).ToLower(), 32).ToLower();
await repository.Db.Updateable<UserEntity>(a => new UserEntity
{
F_Account = entity.F_AdminAccount
}).Where(a => a.F_Id == user.F_Id).ExecuteCommandAsync();
await repository.Db.Updateable<UserLogOnEntity>(a => new UserLogOnEntity
{
F_UserPassword = userinfo.F_UserPassword,
F_UserSecretkey = userinfo.F_UserSecretkey
}).Where(a => a.F_Id == userinfo.F_Id).ExecuteCommandAsync();
}
var set = await repository.Db.Queryable<SystemSetEntity>().InSingleAsync(entity.F_Id);
var tempkey = repository.ChangeEntityDb(GlobalContext.SystemConfig.MainDbNumber).Queryable<UserEntity>().First(a => a.F_IsAdmin == true).F_Id;
await CacheHelper.RemoveAsync(cacheKeyOperator + "info_" + tempkey);
}
repository.Tenant.CommitTran();
//清空缓存,重新拉数据
DBInitialize.GetConnectionConfigs(true);
}
public async Task DeleteForm(string keyValue)
{
await repository.Update(a => a.F_Id == keyValue, a => new SystemSetEntity
{
F_DeleteMark = true,
F_EnabledMark = false,
F_DeleteUserId = currentuser.UserId
});
}
#endregion
}
}

View File

@@ -0,0 +1,93 @@
/*******************************************************************************
* Copyright © 2020 WaterCloud.Framework 版权所有
* Author: WaterCloud
* Description: WaterCloud快速开发平台
* Website
*********************************************************************************/
using SqlSugar;
using System.Threading.Tasks;
using WaterCloud.Code;
using WaterCloud.Domain.SystemOrganize;
namespace WaterCloud.Service.SystemOrganize
{
public class UserLogOnService : BaseService<UserLogOnEntity>, IDenpendency
{
/// <summary>
/// 缓存操作类
/// </summary>
private string cacheKeyOperator = GlobalContext.SystemConfig.ProjectPrefix + "_operator_";// +登录者token
public UserLogOnService(ISqlSugarClient context) : base(context)
{
}
public async Task<UserLogOnEntity> GetForm(string keyValue)
{
return await repository.FindEntity(keyValue);
}
public async Task RevisePassword(string userPassword, string keyValue)
{
UserLogOnEntity entity = new UserLogOnEntity();
entity = repository.IQueryable().InSingle(keyValue);
if (entity == null)
{
entity = new UserLogOnEntity();
entity.F_Id = keyValue;
entity.F_UserId = keyValue;
entity.F_LogOnCount = 0;
entity.F_UserOnLine = false;
entity.F_UserSecretkey = Md5.md5(Utils.CreateNo(), 16).ToLower();
entity.F_UserPassword = Md5.md5(DESEncrypt.Encrypt(Md5.md5(userPassword, 32).ToLower(), entity.F_UserSecretkey).ToLower(), 32).ToLower();
await repository.Insert(entity);
}
else
{
//userLogOnEntity = new UserLogOnEntity();
//userLogOnEntity.F_Id = keyValue;
entity.F_UserSecretkey = Md5.md5(Utils.CreateNo(), 16).ToLower();
entity.F_UserPassword = Md5.md5(DESEncrypt.Encrypt(Md5.md5(userPassword, 32).ToLower(), entity.F_UserSecretkey).ToLower(), 32).ToLower();
await repository.Update(entity);
}
//缓存用户账户信息
var userLogOnEntity = await CacheHelper.GetAsync<OperatorUserInfo>(cacheKeyOperator + "info_" + keyValue);
if (userLogOnEntity == null)
{
userLogOnEntity = new OperatorUserInfo();
userLogOnEntity.F_UserPassword = entity.F_UserPassword;
userLogOnEntity.F_UserSecretkey = entity.F_UserSecretkey;
userLogOnEntity.F_AllowEndTime = entity.F_AllowEndTime;
userLogOnEntity.F_AllowStartTime = entity.F_AllowStartTime;
userLogOnEntity.F_AnswerQuestion = entity.F_AnswerQuestion;
userLogOnEntity.F_ChangePasswordDate = entity.F_ChangePasswordDate;
userLogOnEntity.F_FirstVisitTime = entity.F_FirstVisitTime;
userLogOnEntity.F_LastVisitTime = entity.F_LastVisitTime;
userLogOnEntity.F_LockEndDate = entity.F_LockEndDate;
userLogOnEntity.F_LockStartDate = entity.F_LockStartDate;
userLogOnEntity.F_LogOnCount = entity.F_LogOnCount;
userLogOnEntity.F_PreviousVisitTime = entity.F_PreviousVisitTime;
userLogOnEntity.F_Question = entity.F_Question;
userLogOnEntity.F_Theme = entity.F_Theme;
}
userLogOnEntity.F_UserPassword = entity.F_UserPassword;
userLogOnEntity.F_UserSecretkey = entity.F_UserSecretkey;
await CacheHelper.RemoveAsync(cacheKeyOperator + "info_" + keyValue);
await CacheHelper.SetAsync(cacheKeyOperator + "info_" + keyValue, userLogOnEntity);
}
public async Task ReviseSelfPassword(string userPassword, string keyValue)
{
UserLogOnEntity entity = new UserLogOnEntity();
entity = repository.IQueryable().InSingle(keyValue);
entity.F_UserSecretkey = Md5.md5(Utils.CreateNo(), 16).ToLower();
entity.F_UserPassword = Md5.md5(DESEncrypt.Encrypt(Md5.md5(userPassword, 32).ToLower(), entity.F_UserSecretkey).ToLower(), 32).ToLower();
await repository.Update(entity);
var userLogOnEntity = await CacheHelper.GetAsync<OperatorUserInfo>(cacheKeyOperator + "info_" + keyValue);
userLogOnEntity.F_UserPassword = entity.F_UserPassword;
userLogOnEntity.F_UserSecretkey = entity.F_UserSecretkey;
await CacheHelper.SetAsync(cacheKeyOperator + "info_" + keyValue, userLogOnEntity);
}
}
}

View File

@@ -0,0 +1,394 @@
/*******************************************************************************
* Copyright © 2020 WaterCloud.Framework 版权所有
* Author: WaterCloud
* Description: WaterCloud快速开发平台
* Website
*********************************************************************************/
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using WaterCloud.Code;
using WaterCloud.DataBase;
using WaterCloud.Domain.SystemOrganize;
using WaterCloud.Domain.SystemSecurity;
using WaterCloud.Service.SystemManage;
using WaterCloud.Service.SystemSecurity;
namespace WaterCloud.Service.SystemOrganize
{
public class UserService : BaseService<UserEntity>, IDenpendency
{
public SystemSetService syssetApp { get; set; }
public FilterIPService ipApp { get; set; }
/// <summary>
/// 缓存操作类
/// </summary>
private string cacheKeyOperator = GlobalContext.SystemConfig.ProjectPrefix + "_operator_";// +登录者token
//获取类名
public UserService(ISqlSugarClient context) : base(context)
{
}
public async Task<List<UserExtend>> GetLookList(SoulPage<UserExtend> pagination, string keyword)
{
//反格式化显示只能用"等于",其他不支持
Dictionary<string, Dictionary<string, string>> dic = new Dictionary<string, Dictionary<string, string>>();
Dictionary<string, string> enabledTemp = new Dictionary<string, string>();
enabledTemp.Add("1", "有效");
enabledTemp.Add("0", "无效");
dic.Add("F_EnabledMark", enabledTemp);
Dictionary<string, string> sexTemp = new Dictionary<string, string>();
var sexList = await GlobalContext.GetService<ItemsDataService>().GetItemList("104");
foreach (var item in sexList)
{
sexTemp.Add(item.F_ItemCode, item.F_ItemName);
}
dic.Add("F_Gender", sexTemp);
pagination = ChangeSoulData(dic, pagination);
//获取数据权限
var query = GetQuery().Where(a => a.F_IsAdmin == false);
if (!string.IsNullOrEmpty(keyword))
{
query = query.Where(a => a.F_Account.Contains(keyword) || a.F_RealName.Contains(keyword) || a.F_MobilePhone.Contains(keyword));
}
query = GetDataPrivilege("a", "", query);
var data = await query.ToPageListAsync(pagination);
var roles = repository.Db.Queryable<RoleEntity>().ToList();
var orgs = repository.Db.Queryable<OrganizeEntity>().ToList();
foreach (var item in data)
{
string[] roleIds = item.F_RoleId.Split(',');
string[] departmentIds = item.F_OrganizeId.Split(',');
item.F_OrganizeName = string.Join(',', orgs.Where(a => departmentIds.Contains(a.F_Id)).Select(a => a.F_FullName).ToList());
item.F_RoleName = string.Join(',', roles.Where(a => roleIds.Contains(a.F_Id)).Select(a => a.F_FullName).ToList());
item.F_IsLeaderInDepts = orgs.Any(a => departmentIds.Contains(a.F_Id) && a.F_ManagerId == item.F_Id);
}
return data;
}
public async Task<List<UserExtend>> GetList(string keyword)
{
var cachedata = GetQuery().Where(a => a.F_IsAdmin == false);
if (!string.IsNullOrEmpty(keyword))
{
cachedata = cachedata.Where(a => a.F_Account.Contains(keyword) || a.F_RealName.Contains(keyword) || a.F_MobilePhone.Contains(keyword));
}
var data = await cachedata.OrderBy(a => a.F_Account).ToListAsync();
var roles = await repository.Db.Queryable<RoleEntity>().ToListAsync();
var orgs = await repository.Db.Queryable<OrganizeEntity>().ToListAsync();
foreach (var item in data)
{
string[] roleIds = item.F_RoleId.Split(',');
string[] departmentIds = item.F_OrganizeId.Split(',');
item.F_OrganizeName = string.Join(',', orgs.Where(a => departmentIds.Contains(a.F_Id)).Select(a => a.F_FullName).ToList());
item.F_RoleName = string.Join(',', roles.Where(a => roleIds.Contains(a.F_Id)).Select(a => a.F_FullName).ToList());
item.F_IsLeaderInDepts = orgs.Any(a => departmentIds.Contains(a.F_Id) && a.F_ManagerId == item.F_Id);
}
return data;
}
private ISugarQueryable<UserExtend> GetQuery()
{
var query = repository.Db.Queryable<UserEntity, RoleEntity, SystemSetEntity,UserEntity>((a, b, c,d) => new JoinQueryInfos(
JoinType.Left, a.F_DutyId == b.F_Id,
JoinType.Left, a.F_CompanyId == c.F_Id,
JoinType.Left, a.F_ManagerId == d.F_Id
)).Where(a => a.F_DeleteMark == false)
.Select((a, b, c, d) => new UserExtend
{
F_Id = a.F_Id,
F_IsSenior = a.F_IsSenior,
F_SecurityLevel = a.F_SecurityLevel,
F_Account = a.F_Account,
F_DingTalkAvatar = a.F_DingTalkAvatar,
F_IsAdmin = a.F_IsAdmin,
F_Birthday = a.F_Birthday,
F_CompanyName = c.F_CompanyName,
F_CreatorTime = a.F_CreatorTime,
F_CreatorUserId = a.F_CreatorUserId,
F_OrganizeId = a.F_OrganizeId,
F_Description = a.F_Description,
F_DingTalkUserId = a.F_DingTalkUserId,
F_DingTalkUserName = a.F_DingTalkUserName,
F_DutyId = a.F_DutyId,
F_DutyName = b.F_FullName,
F_Email = a.F_Email,
F_EnabledMark = a.F_EnabledMark,
F_Gender = a.F_Gender,
F_HeadIcon = a.F_HeadIcon,
F_HeadImgUrl = a.F_HeadImgUrl,
F_IsBoss = a.F_IsBoss,
F_ManagerId = a.F_ManagerId,
F_ManagerName = d.F_RealName,
F_MobilePhone = a.F_MobilePhone,
F_NickName = a.F_NickName,
F_CompanyId = a.F_CompanyId,
F_RealName = a.F_RealName,
F_Remark = a.F_RealName,
F_RoleId = a.F_RoleId,
F_Signature = a.F_Signature,
F_SortCode = a.F_SortCode,
F_WeChat = a.F_WeChat,
F_WxNickName = a.F_WxNickName,
F_WxOpenId = a.F_WxOpenId,
F_OrganizeName = "",
F_RoleName = ""
}).MergeTable();
return query;
}
public async Task SubmitUserForm(UserEntity userEntity)
{
await repository.Update(userEntity);
}
public async Task<List<UserEntity>> GetUserList(string keyword)
{
var query = repository.IQueryable();
if (!string.IsNullOrEmpty(keyword))
{
query = query.Where(a => a.F_Account.Contains(keyword) || a.F_RealName.Contains(keyword) || a.F_MobilePhone.Contains(keyword));
}
return await query.Where(a => a.F_EnabledMark == true && a.F_DeleteMark == false).OrderBy(a => a.F_Account).ToListAsync();
}
public async Task<UserExtend> GetForm(string keyValue)
{
var data = await GetQuery().FirstAsync(a => a.F_Id == keyValue);
return data;
}
public async Task<UserExtend> GetFormExtend(string keyValue)
{
var data = await GetQuery().FirstAsync(a => a.F_Id == keyValue);
string[] temp;
if (data.F_RoleId != null)
{
temp = data.F_RoleId.Split(',');
data.F_RoleName = string.Join(",", repository.Db.Queryable<RoleEntity>().Where(a => temp.Contains(a.F_Id)).Select(a => a.F_FullName).ToList().ToArray());
}
if (data.F_OrganizeId != null)
{
temp = data.F_OrganizeId.Split(',');
data.F_OrganizeName = string.Join(",", repository.Db.Queryable<OrganizeEntity>().Where(a => temp.Contains(a.F_Id)).Select(a => a.F_FullName).ToList().ToArray());
data.F_IsLeaderInDepts = repository.Db.Queryable<OrganizeEntity>().Any(a => temp.Contains(a.F_Id) && a.F_ManagerId == data.F_Id);
}
return data;
}
public async Task<UserExtend> GetLookForm(string keyValue)
{
var data = await GetQuery().FirstAsync(a => a.F_Id == keyValue);
string[] temp;
if (data.F_RoleId != null)
{
temp = data.F_RoleId.Split(',');
data.F_RoleName = string.Join(",", repository.Db.Queryable<RoleEntity>().Where(a => temp.Contains(a.F_Id)).Select(a => a.F_FullName).ToList().ToArray());
}
if (data.F_OrganizeId != null)
{
temp = data.F_OrganizeId.Split(',');
data.F_OrganizeName = string.Join(",", repository.Db.Queryable<OrganizeEntity>().Where(a => temp.Contains(a.F_Id)).Select(a => a.F_FullName).ToList().ToArray());
data.F_IsLeaderInDepts = repository.Db.Queryable<OrganizeEntity>().Any(a => temp.Contains(a.F_Id) && a.F_ManagerId == data.F_Id);
}
return GetFieldsFilterData(data);
}
public async Task DeleteForm(string keyValue)
{
repository.Db.Ado.BeginTran();
await repository.Delete(a => a.F_Id == keyValue);
await repository.Db.Deleteable<UserLogOnEntity>(a => a.F_UserId == keyValue).ExecuteCommandAsync();
repository.Db.Ado.CommitTran();
}
public async Task SubmitForm(UserEntity userEntity, UserLogOnEntity userLogOnEntity, string keyValue)
{
if (!string.IsNullOrEmpty(keyValue))
{
//自己不能作为自己的直属上级
if (keyValue == userEntity.F_ManagerId)
{
userEntity.F_ManagerId = null;
}
if (userEntity.F_ManagerId.Contains(","))
{
throw new Exception("只能选择一个直属上级");
}
userEntity.Modify(keyValue);
}
else
{
userEntity.Create();
userLogOnEntity.F_Id = Utils.GuId();
userLogOnEntity.F_UserId = userEntity.F_Id;
userLogOnEntity.F_ErrorNum = 0;
userLogOnEntity.F_UserOnLine = false;
userLogOnEntity.F_LogOnCount = 0;
}
repository.Db.Ado.BeginTran();
if (!string.IsNullOrEmpty(keyValue))
{
await repository.Update(userEntity);
}
else
{
userLogOnEntity.F_Id = userEntity.F_Id;
userLogOnEntity.F_UserId = userEntity.F_Id;
userLogOnEntity.F_UserSecretkey = Md5.md5(Utils.CreateNo(), 16).ToLower();
userLogOnEntity.F_UserPassword = Md5.md5(DESEncrypt.Encrypt(Md5.md5(userLogOnEntity.F_UserPassword, 32).ToLower(), userLogOnEntity.F_UserSecretkey).ToLower(), 32).ToLower();
await repository.Insert(userEntity);
await repository.Db.Insertable(userLogOnEntity).ExecuteCommandAsync();
}
repository.Db.Ado.CommitTran();
}
public async Task UpdateForm(UserEntity userEntity)
{
await repository.Update(userEntity);
}
/// <summary>
/// 登录判断
/// </summary>
/// <param name="username"></param>
/// <param name="password"></param>
/// <returns></returns>
public async Task<UserEntity> CheckLogin(string username, string password, string localurl)
{
//根据登录公司查找公司
if (GlobalContext.SystemConfig.SqlMode == Define.SQL_TENANT)
{
repository.ChangeEntityDb(GlobalContext.SystemConfig.MainDbNumber);
var setTemp = (await syssetApp.GetList()).Where(a => localurl.Contains(a.F_HostUrl)).FirstOrDefault();
if (setTemp != null)
{
if (setTemp.F_EndTime < DateTime.Now.Date)
{
throw new Exception("租户已到期,请联系供应商");
}
if (!_context.AsTenant().IsAnyConnection(setTemp.F_DbNumber))
{
var dblist = DBInitialize.GetConnectionConfigs(true);
_context.AsTenant().AddConnection(dblist.FirstOrDefault(a => a.ConfigId.ToString() == setTemp.F_DbNumber));
repository.ChangeEntityDb(setTemp.F_DbNumber);
repository.Db.DefaultConfig();
}
else
{
repository.ChangeEntityDb(setTemp.F_DbNumber);
}
}
}
if (!(await CheckIP()))
{
throw new Exception("IP受限");
}
UserEntity userEntity = await repository.IQueryable().SingleAsync(a => a.F_Account == username);
if (userEntity != null)
{
if (userEntity.F_EnabledMark == true)
{
//缓存用户账户信息
var userLogOnEntity = await CacheHelper.GetAsync<OperatorUserInfo>(cacheKeyOperator + "info_" + userEntity.F_Id);
if (userLogOnEntity == null)
{
userLogOnEntity = new OperatorUserInfo();
UserLogOnEntity entity = await repository.Db.Queryable<UserLogOnEntity>().InSingleAsync(userEntity.F_Id);
userLogOnEntity.F_UserPassword = entity.F_UserPassword;
userLogOnEntity.F_UserSecretkey = entity.F_UserSecretkey;
userLogOnEntity.F_AllowEndTime = entity.F_AllowEndTime;
userLogOnEntity.F_AllowStartTime = entity.F_AllowStartTime;
userLogOnEntity.F_AnswerQuestion = entity.F_AnswerQuestion;
userLogOnEntity.F_ChangePasswordDate = entity.F_ChangePasswordDate;
userLogOnEntity.F_FirstVisitTime = entity.F_FirstVisitTime;
userLogOnEntity.F_LastVisitTime = entity.F_LastVisitTime;
userLogOnEntity.F_LockEndDate = entity.F_LockEndDate;
userLogOnEntity.F_LockStartDate = entity.F_LockStartDate;
userLogOnEntity.F_LogOnCount = entity.F_LogOnCount;
userLogOnEntity.F_PreviousVisitTime = entity.F_PreviousVisitTime;
userLogOnEntity.F_Question = entity.F_Question;
userLogOnEntity.F_Theme = entity.F_Theme;
await CacheHelper.SetAsync(cacheKeyOperator + "info_" + userEntity.F_Id, userLogOnEntity);
}
if (userLogOnEntity == null)
{
throw new Exception("账户未初始化设置密码,请联系管理员");
}
string dbPassword = Md5.md5(DESEncrypt.Encrypt(password.ToLower(), userLogOnEntity.F_UserSecretkey).ToLower(), 32).ToLower();
if (dbPassword == userLogOnEntity.F_UserPassword)
{
if (userEntity.F_IsAdmin != true)
{
var list = userEntity.F_RoleId.Split(',');
var rolelist = repository.Db.Queryable<RoleEntity>().Where(a => list.Contains(a.F_Id) && a.F_EnabledMark == true).ToList();
if (!rolelist.Any())
{
throw new Exception("账户未设置权限,请联系管理员");
}
}
DateTime lastVisitTime = DateTime.Now;
int LogOnCount = (userLogOnEntity.F_LogOnCount).ToInt() + 1;
if (userLogOnEntity.F_LastVisitTime != null)
{
userLogOnEntity.F_PreviousVisitTime = userLogOnEntity.F_LastVisitTime.ToDate();
}
userLogOnEntity.F_LastVisitTime = lastVisitTime;
userLogOnEntity.F_LogOnCount = LogOnCount;
userLogOnEntity.F_UserOnLine = true;
await CacheHelper.RemoveAsync(cacheKeyOperator + "info_" + userEntity.F_Id);
await CacheHelper.SetAsync(cacheKeyOperator + "info_" + userEntity.F_Id, userLogOnEntity);
await OperatorProvider.Provider.ClearCurrentErrorNum();
return userEntity;
}
else
{
//登录错误不超过指定次数
int num = await OperatorProvider.Provider.AddCurrentErrorNum();
int errorcount = GlobalContext.SystemConfig.LoginErrorCount ?? 4;
string erornum = (errorcount - num).ToString();
if (num == errorcount)
{
FilterIPEntity ipentity = new FilterIPEntity();
ipentity.F_Id = Utils.GuId();
ipentity.F_StartIP = WebHelper.Ip;
ipentity.F_CreatorTime = DateTime.Now;
ipentity.F_DeleteMark = false;
ipentity.F_EnabledMark = true;
ipentity.F_Type = false;
//默认封禁12小时
ipentity.F_EndTime = DateTime.Now.AddHours(12);
await ipApp.SubmitForm(ipentity, null);
await OperatorProvider.Provider.ClearCurrentErrorNum();
throw new Exception("密码不正确IP被锁定");
}
else
{
throw new Exception("密码不正确,请重新输入,还有" + erornum + "次机会");
}
}
}
else
{
throw new Exception("账户被系统锁定,请联系管理员");
}
}
else
{
throw new Exception("账户不存在,请重新输入");
}
}
private async Task<bool> CheckIP()
{
string ip = WebHelper.Ip;
return await ipApp.CheckIP(ip);
}
}
}