@@ -10,5 +10,7 @@ namespace BPA.SAAS.Manage.Application.Org.Interface | |||
public interface IRoleService | |||
{ | |||
Task<bool> Add(RoleDtoInput input); | |||
Task<List<QueryRoleMenuListDto>> GetMenuRole(string RoleId); | |||
Task<bool> AddOrUpdateMenuRole(RoleMenuDtoInput input); | |||
} | |||
} |
@@ -2,12 +2,15 @@ | |||
using BPA.SAAS.Manage.Application.Org.Dtos.Role; | |||
using BPA.SAAS.Manage.Application.Org.Dtos.Users; | |||
using BPA.SAAS.Manage.Application.Org.Interface; | |||
using BPA.SAAS.Manage.Comm.Const; | |||
using BPA.SAAS.Manage.Comm.Enum; | |||
using BPA.SAAS.Manage.Core.Base; | |||
using BPA.SAAS.Manage.Core.Org; | |||
using BPA.SAAS.Manage.Core.System; | |||
using Furion.LinqBuilder; | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Data; | |||
using System.Linq; | |||
using System.Text; | |||
using System.Threading.Tasks; | |||
@@ -17,13 +20,9 @@ namespace BPA.SAAS.Manage.Application.Org.Services | |||
public class CompanyService: ICompanyService, ITransient | |||
{ | |||
private readonly ISqlSugarClient _db; | |||
IUserService _UserService; | |||
IRoleService _RoleService; | |||
public CompanyService(ISqlSugarClient db, IUserService userService, IRoleService roleService) | |||
public CompanyService(ISqlSugarClient db) | |||
{ | |||
_db = db; | |||
_UserService = userService; | |||
_RoleService = roleService; | |||
} | |||
/// <summary> | |||
/// 查询企业信息 | |||
@@ -63,34 +62,36 @@ namespace BPA.SAAS.Manage.Application.Org.Services | |||
/// <returns></returns> | |||
public async Task<bool> AddCompany(CompanyDtoInput input) | |||
{ | |||
_db.Ado.BeginTran(); | |||
var company = input.Adapt<BPA_Company>(); | |||
var Companycheck = _db.Queryable<BPA_Company>().Where(x => x.IsDeleted == 0).First(x => x.Email == company.Email); | |||
if (Companycheck != null) | |||
throw Oops.Oh($"账号已存在"); | |||
var res =await _db.Insertable(company).ExecuteReturnEntityAsync(); | |||
var res =await _db.Insertable(company).CallEntityMethod(t => t.Create()).ExecuteReturnEntityAsync(); | |||
input.Email = input.Email.IsNullOrEmpty() ? input.Phone : input.Email; | |||
//创建企业,管理员用户,管理员角色 | |||
bool adduser =await _UserService.AddUser(new UserDtoInput | |||
var adduser = await _db.Insertable(new BPA_Users() | |||
{ | |||
GroupId = res.Id, | |||
Account = input.Email, | |||
AdminType = AdminEnums.Admin, | |||
AdminType = 2, | |||
Name = input.Name, | |||
}); | |||
Password = MD5Encryption.Encrypt("123456").ToLower() | |||
}).CallEntityMethod(t => t.Create()).ExecuteCommandAsync()>0; | |||
if (adduser) | |||
{ | |||
var addrole = _RoleService.Add(new RoleDtoInput | |||
var addrole =await _db.Insertable(new BPA_Roles | |||
{ | |||
Id= Guid.NewGuid().ToString(), | |||
GroupId = res.Id, | |||
Name = input.Name + "管理员", | |||
Remark = "系统默认创建管理员角色不允许修改", | |||
Code = "sys_manager_role", | |||
}); | |||
RoleType=1 | |||
}).CallEntityMethod(t => t.Create()).ExecuteCommandAsync() > 0; | |||
// 查询用户 | |||
var UserRes = _db.Queryable<BPA_Users>().Filter(null, true).Where(a => a.GroupId == res.Id && a.Account == input.Email).ToList(); | |||
////查询角色 | |||
@@ -104,10 +105,12 @@ namespace BPA.SAAS.Manage.Application.Org.Services | |||
userRole.SysRoleId = RoleRes.First().Id; | |||
_db.Insertable(userRole).ExecuteReturnEntity(); | |||
} | |||
_db.Ado.CommitTran(); | |||
} | |||
else | |||
{ | |||
_db.Deleteable(res).ExecuteCommand(); | |||
_db.Ado.RollbackTran(); | |||
//_db.Deleteable(res).ExecuteCommand(); | |||
return false; | |||
} | |||
@@ -147,6 +150,17 @@ namespace BPA.SAAS.Manage.Application.Org.Services | |||
{ | |||
x.IsDeleted = 1; | |||
}); | |||
//删除加盟商下面的角色和用户以及相关的菜单权限 | |||
var Roles=_db.Queryable<BPA_Roles>().Where(x=> inputList.Contains(x.GroupId)).ToList(); | |||
var Roleids= Roles.Select(x=>x.Id).ToList(); | |||
var Users = _db.Queryable<BPA_Users>().Where(x => inputList.Contains(x.GroupId)).ToList(); | |||
var Usersids = Users.Select(x => x.Id).ToList(); | |||
var UserRole=_db.Queryable<BPA_UserRole>().Where(x => Usersids.Contains(x.SysUserId)).ToList(); | |||
var RoleMenu = _db.Queryable<BPA_RoleMenu>().Where(x => Roleids.Contains(x.SysRoleId)).ToList(); | |||
await _db.Deleteable(Roles).ExecuteCommandAsync(); | |||
await _db.Deleteable(Users).ExecuteCommandAsync(); | |||
await _db.Deleteable(UserRole).ExecuteCommandAsync(); | |||
await _db.Deleteable(RoleMenu).ExecuteCommandAsync(); | |||
var res = await _db.Updateable(resEntitites).ExecuteCommandAsync(); | |||
_db.Ado.CommitTran(); | |||
return true; | |||
@@ -2,6 +2,7 @@ | |||
using BPA.SAAS.Manage.Application.Org.Interface; | |||
using BPA.SAAS.Manage.Comm.Const; | |||
using BPA.SAAS.Manage.Core.Org; | |||
using BPA.SAAS.Manage.Core.System; | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Linq; | |||
@@ -29,11 +30,71 @@ namespace BPA.SAAS.Manage.Application.Org.Services | |||
} | |||
} | |||
var role = input.Adapt<BPA_Roles>(); | |||
role.Id = Guid.NewGuid().ToString(); | |||
role.CreateAt=DateTime.Now; | |||
role.CreateBy = App.User?.FindFirst(ClaimConst.CLAINM_USERID)?.Value; | |||
// role.DataScopeType = DataScopeType.ALL; | |||
return await _db.Insertable(role).ExecuteCommandAsync() > 0; | |||
return await _db.Insertable(role).CallEntityMethod(t => t.Create()).ExecuteCommandAsync() > 0; | |||
} | |||
/// <summary> | |||
/// 根据角色查询角色菜单 | |||
/// </summary> | |||
/// <param name="RoleId"></param> | |||
/// <returns></returns> | |||
public async Task<List<QueryRoleMenuListDto>> GetMenuRole(string RoleId) | |||
{ | |||
var MenuName =await _db.Queryable<BPA_RoleMenu>().LeftJoin<BPA_Menu>((t, x) => t.SysMenuId == x.Id) | |||
.Where(t => t.SysRoleId == RoleId).OrderBy((t, x) => x.CreateAt).Select((t, x) => new QueryRoleMenuListDto() | |||
{ | |||
Name = x.Name, | |||
Id = x.Id, | |||
IsParentMenu = string.IsNullOrWhiteSpace(x.Pid) | |||
}).ToListAsync(); | |||
return MenuName; | |||
} | |||
/// <summary> | |||
/// 编辑角色菜单 | |||
/// </summary> | |||
/// <param name="input"></param> | |||
/// <returns></returns> | |||
public async Task<bool> AddOrUpdateMenuRole(RoleMenuDtoInput input) | |||
{ | |||
List<BPA_RoleMenu> models = new List<BPA_RoleMenu>(); | |||
List<string> NewMenuId = new List<string>(); | |||
if (input.SysMenuId != null) | |||
{ | |||
var Menus = _db.Queryable<BPA_Menu>().ToList(); | |||
foreach (var item in input.SysMenuId) | |||
{ | |||
var Pid = Menus.FirstOrDefault(t => t.Id == item).Pid; | |||
if (Pid != null && Pid != "") | |||
{ | |||
var Pid2 = Menus.FirstOrDefault(t => t.Id == Pid).Pid; | |||
if (Pid2 != null) | |||
{ | |||
NewMenuId.Add(Pid2); | |||
} | |||
NewMenuId.Add(Pid); | |||
} | |||
NewMenuId.Add(item); | |||
} | |||
NewMenuId.Distinct().ToList().ForEach(item => | |||
{ | |||
models.Add(new BPA_RoleMenu | |||
{ | |||
Id = Guid.NewGuid().ToString(), | |||
SysMenuId = item, | |||
SysRoleId = input.SysRoleId | |||
}); | |||
}); | |||
} | |||
if (models.Count <= 0) | |||
return true; | |||
_db.Deleteable<BPA_RoleMenu>(t => t.SysRoleId == input.SysRoleId).ExecuteCommandHasChange(); | |||
return await _db.Insertable(models).ExecuteCommandAsync() > 0; | |||
} | |||
} | |||
} |
@@ -21,14 +21,11 @@ namespace BPA.SAAS.Manage.Application.Org.Services | |||
public async Task<bool> AddUser(UserDtoInput input) | |||
{ | |||
var user = input.Adapt<BPA_Users>(); | |||
user.Id= Guid.NewGuid().ToString(); | |||
user.Password = MD5Encryption.Encrypt("123456").ToLower(); | |||
user.CreateAt=DateTime.Now; | |||
user.CreateBy = App.User?.FindFirst(ClaimConst.CLAINM_USERID)?.Value; | |||
var check = _db.Queryable<BPA_Users>().First(t => t.Account == user.Account); | |||
if (check != null) | |||
return false; | |||
return await _db.Insertable(user).ExecuteCommandAsync()> 0; | |||
return await _db.Insertable(user).CallEntityMethod(t => t.Create()).ExecuteCommandAsync()> 0; | |||
} | |||
} | |||
} |
@@ -105,7 +105,7 @@ namespace BPA.SAAS.Manage.Application | |||
Code = dto.Code, | |||
Remark = dto.Remark, | |||
}; | |||
var res =await _db.Insertable(dictData).ExecuteCommandAsync(); | |||
var res =await _db.Insertable(dictData).CallEntityMethod(t => t.Create()).ExecuteCommandAsync(); | |||
_db.Ado.CommitTran(); | |||
return res>0; | |||
} | |||
@@ -85,14 +85,11 @@ namespace BPA.SAAS.Manage.Application.System.Services | |||
_db.Ado.BeginTran(); | |||
var dictType = new BPA_DictType | |||
{ | |||
Id = Guid.NewGuid().ToString(), | |||
Code = dto.Code, | |||
Name = dto.Name, | |||
Remark = dto.Remark, | |||
CreateAt = DateTime.Now, | |||
CreateBy = App.User?.FindFirst(ClaimConst.CLAINM_USERID)?.Value | |||
Remark = dto.Remark | |||
}; | |||
var res =await _db.Insertable(dictType).ExecuteCommandAsync(); | |||
var res =await _db.Insertable(dictType).CallEntityMethod(t => t.Create()).ExecuteCommandAsync(); | |||
_db.Ado.CommitTran(); | |||
return true; | |||
} | |||
@@ -85,10 +85,7 @@ namespace BPA.SAAS.Manage.Application.System.Services | |||
public async Task<bool> Add(MenuDtoInput input) | |||
{ | |||
var menu = input.Adapt<BPA_Menu>(); | |||
menu.Id= Guid.NewGuid().ToString(); | |||
menu.CreateAt= DateTime.Now; | |||
menu.CreateBy= App.User?.FindFirst(ClaimConst.CLAINM_USERID)?.Value; | |||
return await _db.Insertable(menu).ExecuteCommandAsync()> 0; | |||
return await _db.Insertable(menu).CallEntityMethod(t => t.Create()).ExecuteCommandAsync()> 0; | |||
} | |||
/// <summary> | |||
@@ -98,9 +95,16 @@ namespace BPA.SAAS.Manage.Application.System.Services | |||
/// <returns></returns> | |||
public async Task<bool> Update(MenuDtoInput input) | |||
{ | |||
var menu = input.Adapt<BPA_Menu>(); | |||
menu.CreateAt = DateTime.Now; | |||
menu.CreateBy = App.User?.FindFirst(ClaimConst.CLAINM_USERID)?.Value; | |||
var menu = await _db.Queryable< BPA_Menu >().Where(x=>x.Id== input.Id).FirstAsync(); | |||
//menu = input.Adapt<BPA_Menu>(); | |||
menu.Code = input.Code; | |||
menu.Component = input.Component; | |||
menu.Name= input.Name; | |||
menu.Pid= input.Pid; | |||
menu.Router = input.Router; | |||
menu.Remark= input.Remark; | |||
menu.Sort = input.Sort; | |||
menu.Icon = input.Icon; | |||
return await _db.Updateable(menu).ExecuteCommandAsync()>0; | |||
} | |||
@@ -1,4 +1,6 @@ | |||
using SqlSugar; | |||
using BPA.SAAS.Manage.Comm.Const; | |||
using Furion; | |||
using SqlSugar; | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Linq; | |||
@@ -20,5 +22,24 @@ namespace BPA.SAAS.Manage.Core.Base | |||
/// 是否删除 | |||
/// </summary> | |||
public int IsDeleted { get; set; } = 0; | |||
/// <summary> | |||
/// 新增 | |||
/// </summary> | |||
public virtual void Create() | |||
{ | |||
var userId = App.User?.FindFirst(ClaimConst.CLAINM_USERID)?.Value; | |||
this.Id = Guid.NewGuid().ToString(); | |||
this.CreateAt = DateTime.Now; | |||
if (!string.IsNullOrEmpty(userId)) | |||
{ | |||
this.CreateBy = userId; | |||
} | |||
else | |||
{ | |||
this.CreateBy = "admin"; | |||
} | |||
} | |||
} | |||
} |
@@ -26,7 +26,7 @@ namespace BPA.SAAS.Manage.Core.Org | |||
/// <summary> | |||
/// 类型 默认 机构 | |||
/// </summary> | |||
public string Type { get; set; } | |||
public int Type { get; set; } | |||
/// <summary> | |||
/// 上级ID集合 | |||
/// </summary> | |||
@@ -36,13 +36,9 @@ namespace BPA.SAAS.Manage.Core.Org | |||
/// </summary> | |||
public string Remark { get; set; } | |||
/// <summary> | |||
/// 店铺地址 | |||
/// 电话 | |||
/// </summary> | |||
public string Store_Addr { get; set; } | |||
/// <summary> | |||
/// 店铺坐标 | |||
/// </summary> | |||
public string Store_Loc { get; set; } | |||
public string Tel { get; set; } | |||
/// <summary> | |||
/// AutoKey 唯一值 | |||
/// </summary> | |||
@@ -55,5 +51,6 @@ namespace BPA.SAAS.Manage.Core.Org | |||
/// 加盟商id | |||
/// </summary> | |||
public string GroupId { get; set; } | |||
public int Sort { get; set; } | |||
} | |||
} |
@@ -11,7 +11,7 @@ namespace BPA.SAAS.Manage.Core.Org | |||
/// <summary> | |||
/// 角色 | |||
/// </summary> | |||
[SugarTable("bpa_role")] | |||
[SugarTable("bpa_roles")] | |||
public class BPA_Roles:IBaseEntity | |||
{ | |||
/// <summary> | |||
@@ -25,7 +25,7 @@ namespace BPA.SAAS.Manage.Core.Org | |||
/// <summary> | |||
/// 排序 | |||
/// </summary> | |||
public string Sort { get; set; } | |||
public int Sort { get; set; } | |||
/// <summary> | |||
/// 备注 | |||
/// </summary> | |||
@@ -33,7 +33,7 @@ namespace BPA.SAAS.Manage.Core.Org | |||
/// <summary> | |||
/// 角色类型-集团角色_0、加盟商角色_1、门店角色_2 | |||
/// </summary> | |||
public string RoleType { get; set; } | |||
public int RoleType { get; set; } | |||
/// <summary> | |||
/// 加盟商id | |||
/// </summary> | |||