From c902174f9f4b3c23dc76b5dd03e3bf941443bdfb Mon Sep 17 00:00:00 2001
From: zhaoy <137053305@qq.com>
Date: Fri, 5 Jan 2024 09:42:02 +0800
Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E6=96=B0=E6=8F=90=E4=BA=A4?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.gitignore | 1 -
.../Org/Dtos/Organize/DeleteOrgInput.cs | 13 ++
.../Org/Dtos/Organize/OrgAddInput.cs | 30 +++
.../Org/Dtos/Organize/OrgListInput.cs | 13 ++
.../Org/Dtos/Organize/OrgOutput.cs | 51 +++++
.../Org/Dtos/Organize/OrgPageInput.cs | 24 +++
.../Org/Dtos/Organize/OrgTreeNode.cs | 62 ++++++
.../Org/Dtos/Organize/UpdateOrgInput.cs | 30 +++
.../Org/Dtos/Role/QueryRoleMenuListDto.cs | 16 ++
.../Org/Dtos/Role/RoleDtoInput.cs | 2 +-
.../Org/Dtos/Role/RoleDtoOutput.cs | 40 ++++
.../Org/Dtos/Role/RoleDtoPageInput.cs | 22 +++
.../Org/Dtos/Role/RoleMenuDtoInput.cs | 21 ++
.../Org/Interface/IOrganizeService.cs | 20 ++
.../Org/Interface/IRoleService.cs | 2 +
.../Org/OrganizeServices.cs | 80 ++++++++
.../Org/RolesServices.cs | 101 ++++++++++
.../Org/Services/OrganizeService.cs | 185 ++++++++++++++++++
.../Org/Services/RoleService.cs | 58 ++++++
BPA.SAAS.Manage.Comm/Util/ITreeNode.cs | 81 ++++++++
20 files changed, 850 insertions(+), 2 deletions(-)
create mode 100644 BPA.SAAS.Manage.Application/Org/Dtos/Organize/DeleteOrgInput.cs
create mode 100644 BPA.SAAS.Manage.Application/Org/Dtos/Organize/OrgAddInput.cs
create mode 100644 BPA.SAAS.Manage.Application/Org/Dtos/Organize/OrgListInput.cs
create mode 100644 BPA.SAAS.Manage.Application/Org/Dtos/Organize/OrgOutput.cs
create mode 100644 BPA.SAAS.Manage.Application/Org/Dtos/Organize/OrgPageInput.cs
create mode 100644 BPA.SAAS.Manage.Application/Org/Dtos/Organize/OrgTreeNode.cs
create mode 100644 BPA.SAAS.Manage.Application/Org/Dtos/Organize/UpdateOrgInput.cs
create mode 100644 BPA.SAAS.Manage.Application/Org/Dtos/Role/QueryRoleMenuListDto.cs
create mode 100644 BPA.SAAS.Manage.Application/Org/Dtos/Role/RoleDtoOutput.cs
create mode 100644 BPA.SAAS.Manage.Application/Org/Dtos/Role/RoleDtoPageInput.cs
create mode 100644 BPA.SAAS.Manage.Application/Org/Dtos/Role/RoleMenuDtoInput.cs
create mode 100644 BPA.SAAS.Manage.Application/Org/Interface/IOrganizeService.cs
create mode 100644 BPA.SAAS.Manage.Application/Org/OrganizeServices.cs
create mode 100644 BPA.SAAS.Manage.Application/Org/RolesServices.cs
create mode 100644 BPA.SAAS.Manage.Application/Org/Services/OrganizeService.cs
create mode 100644 BPA.SAAS.Manage.Comm/Util/ITreeNode.cs
diff --git a/.gitignore b/.gitignore
index 857671e..6b01279 100644
--- a/.gitignore
+++ b/.gitignore
@@ -20,7 +20,6 @@
*.props
/BPA.SAAS.Manage.Web.Entry/obj/Debug/net6.0/BPA.SAAS.Manage.Web.Entry.csproj.AssemblyReference.cache
/BPA.SAAS.Manage.Web.Entry/obj/Debug/net6.0/staticwebassets.build.json
-*.cs
/BPA.SAAS.Manage.Web.Core/obj/Debug/net6.0/BPA.SAAS.Manage.Web.Core.csproj.AssemblyReference.cache
/BPA.SAAS.Manage.Web.Entry/obj/Debug/net6.0/apphost.exe
/BPA.SAAS.Manage.Core/BPA.SAAS.Manage.Core.xml
diff --git a/BPA.SAAS.Manage.Application/Org/Dtos/Organize/DeleteOrgInput.cs b/BPA.SAAS.Manage.Application/Org/Dtos/Organize/DeleteOrgInput.cs
new file mode 100644
index 0000000..ce6c436
--- /dev/null
+++ b/BPA.SAAS.Manage.Application/Org/Dtos/Organize/DeleteOrgInput.cs
@@ -0,0 +1,13 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace BPA.SAAS.Manage.Application.Org.Dtos.Organize
+{
+ public class DeleteOrgInput
+ {
+ public string Id { get; set; }
+ }
+}
diff --git a/BPA.SAAS.Manage.Application/Org/Dtos/Organize/OrgAddInput.cs b/BPA.SAAS.Manage.Application/Org/Dtos/Organize/OrgAddInput.cs
new file mode 100644
index 0000000..e33304c
--- /dev/null
+++ b/BPA.SAAS.Manage.Application/Org/Dtos/Organize/OrgAddInput.cs
@@ -0,0 +1,30 @@
+using BPA.SAAS.Manage.Comm.Enum;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace BPA.SAAS.Manage.Application.Org.Dtos.Organize
+{
+ public class OrgAddInput
+ {
+ ///
+ /// 机构名称
+ ///
+ public string Name { get; set; }
+ ///
+ /// 上级id
+ ///
+ public string PID { get; set; }
+ ///
+ /// 备注
+ ///
+ public string Remark { get; set; }
+ ///
+ /// 电话
+ ///
+ public string Tel { get; set; }
+ public int Sort { get; set; }
+ }
+}
diff --git a/BPA.SAAS.Manage.Application/Org/Dtos/Organize/OrgListInput.cs b/BPA.SAAS.Manage.Application/Org/Dtos/Organize/OrgListInput.cs
new file mode 100644
index 0000000..ba56b16
--- /dev/null
+++ b/BPA.SAAS.Manage.Application/Org/Dtos/Organize/OrgListInput.cs
@@ -0,0 +1,13 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace BPA.SAAS.Manage.Application.Org.Dtos.Organize
+{
+ public class OrgListInput
+ {
+ public string Pid { get; set; }
+ }
+}
diff --git a/BPA.SAAS.Manage.Application/Org/Dtos/Organize/OrgOutput.cs b/BPA.SAAS.Manage.Application/Org/Dtos/Organize/OrgOutput.cs
new file mode 100644
index 0000000..1a34bf9
--- /dev/null
+++ b/BPA.SAAS.Manage.Application/Org/Dtos/Organize/OrgOutput.cs
@@ -0,0 +1,51 @@
+using BPA.SAAS.Manage.Comm.Enum;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace BPA.SAAS.Manage.Application.Org.Dtos.Organize
+{
+ public class OrgOutput
+ {
+ public string Id { get; set; }
+ ///
+ /// 机构名称
+ ///
+ public string Name { get; set; }
+ ///
+ /// 上级id
+ ///
+ public string PID { get; set; }
+ ///
+ /// 类型 默认 机构
+ ///
+ public int Type { get; set; }
+ ///
+ /// 上级ID集合
+ ///
+ public string Pids { get; set; }
+ ///
+ /// 备注
+ ///
+ public string Remark { get; set; }
+ ///
+ /// 电话
+ ///
+ public string Tel { get; set; }
+ ///
+ /// AutoKey 唯一值
+ ///
+ public string AutoKey { get; set; }
+ ///
+ /// 状态 【正常 停用】默认 正常
+ ///
+ public CommonStatus Status { get; set; } = CommonStatus.ENABLE;
+ ///
+ /// 加盟商id
+ ///
+ public string GroupId { get; set; }
+ public DateTime CreateAt { get; set; }
+ }
+}
diff --git a/BPA.SAAS.Manage.Application/Org/Dtos/Organize/OrgPageInput.cs b/BPA.SAAS.Manage.Application/Org/Dtos/Organize/OrgPageInput.cs
new file mode 100644
index 0000000..f48382d
--- /dev/null
+++ b/BPA.SAAS.Manage.Application/Org/Dtos/Organize/OrgPageInput.cs
@@ -0,0 +1,24 @@
+using BPA.SAAS.Manage.Core.Base;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace BPA.SAAS.Manage.Application.Org.Dtos.Organize
+{
+ public class OrgPageInput: PageInputBase
+ {
+ public string Id { get; set; }
+
+ ///
+ /// 父Id
+ ///
+ public string Pid { get; set; }
+
+ ///
+ /// 名称
+ ///
+ public string Name { get; set; }
+ }
+}
diff --git a/BPA.SAAS.Manage.Application/Org/Dtos/Organize/OrgTreeNode.cs b/BPA.SAAS.Manage.Application/Org/Dtos/Organize/OrgTreeNode.cs
new file mode 100644
index 0000000..140b13c
--- /dev/null
+++ b/BPA.SAAS.Manage.Application/Org/Dtos/Organize/OrgTreeNode.cs
@@ -0,0 +1,62 @@
+using BPA.SAAS.Manage.Comm.Util;
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace BPA.SAAS.Manage.Application.Org.Dtos.Organize
+{
+ public class OrgTreeNode : ITreeNode
+ {
+
+ public int Type { get; set; }
+
+ ///
+ /// Id
+ ///
+ public string key { get; set; }
+
+ ///
+ /// 父Id
+ ///
+ public string parentId { get; set; }
+
+ ///
+ /// 名称
+ ///
+ public string title { get; set; }
+
+ ///
+ /// 值
+ ///
+ public string value { get; set; }
+
+ ///
+ /// 排序,越小优先级越高
+ ///
+ public int weight { get; set; }
+
+ ///
+ /// 子节点
+ ///
+ public List Children { get; set; } = new List();
+
+
+ public string GetId()
+ {
+ return key;
+ }
+
+ public string GetPid()
+ {
+ return parentId;
+ }
+
+ public void SetChildren(IList children)
+ {
+ Children = (List)children;
+ }
+ }
+}
diff --git a/BPA.SAAS.Manage.Application/Org/Dtos/Organize/UpdateOrgInput.cs b/BPA.SAAS.Manage.Application/Org/Dtos/Organize/UpdateOrgInput.cs
new file mode 100644
index 0000000..fd1fc7a
--- /dev/null
+++ b/BPA.SAAS.Manage.Application/Org/Dtos/Organize/UpdateOrgInput.cs
@@ -0,0 +1,30 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace BPA.SAAS.Manage.Application.Org.Dtos.Organize
+{
+ public class UpdateOrgInput
+ {
+ public string Id { get; set; }
+ ///
+ /// 机构名称
+ ///
+ public string Name { get; set; }
+ ///
+ /// 上级id
+ ///
+ public string Pid { get; set; }
+ ///
+ /// 备注
+ ///
+ public string Remark { get; set; }
+ ///
+ /// 电话
+ ///
+ public string Tel { get; set; }
+ public int Sort { get; set; }
+ }
+}
diff --git a/BPA.SAAS.Manage.Application/Org/Dtos/Role/QueryRoleMenuListDto.cs b/BPA.SAAS.Manage.Application/Org/Dtos/Role/QueryRoleMenuListDto.cs
new file mode 100644
index 0000000..2a99624
--- /dev/null
+++ b/BPA.SAAS.Manage.Application/Org/Dtos/Role/QueryRoleMenuListDto.cs
@@ -0,0 +1,16 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace BPA.SAAS.Manage.Application.Org.Dtos.Role
+{
+ public class QueryRoleMenuListDto
+ {
+ public string Name { get; set; }
+ public string Id { get; set; }
+
+ public bool IsParentMenu { get; set; }
+ }
+}
diff --git a/BPA.SAAS.Manage.Application/Org/Dtos/Role/RoleDtoInput.cs b/BPA.SAAS.Manage.Application/Org/Dtos/Role/RoleDtoInput.cs
index 87f606a..ef1f4e2 100644
--- a/BPA.SAAS.Manage.Application/Org/Dtos/Role/RoleDtoInput.cs
+++ b/BPA.SAAS.Manage.Application/Org/Dtos/Role/RoleDtoInput.cs
@@ -20,7 +20,7 @@ namespace BPA.SAAS.Manage.Application.Org.Dtos.Role
///
/// 排序
///
- public string Sort { get; set; }
+ public int Sort { get; set; }
///
/// 备注
///
diff --git a/BPA.SAAS.Manage.Application/Org/Dtos/Role/RoleDtoOutput.cs b/BPA.SAAS.Manage.Application/Org/Dtos/Role/RoleDtoOutput.cs
new file mode 100644
index 0000000..9e34ade
--- /dev/null
+++ b/BPA.SAAS.Manage.Application/Org/Dtos/Role/RoleDtoOutput.cs
@@ -0,0 +1,40 @@
+using BPA.SAAS.Manage.Comm.Enum;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace BPA.SAAS.Manage.Application.Org.Dtos.Role
+{
+ public class RoleDtoOutput
+ {
+ public string Id { get; set; }
+ //
+ /// 角色名称
+ ///
+ public string Name { get; set; }
+ ///
+ /// 编码
+ ///
+ public string Code { get; set; }
+ ///
+ /// 排序
+ ///
+ public int Sort { get; set; }
+ ///
+ /// 备注
+ ///
+ public string Remark { get; set; }
+ ///
+ /// 角色类型-集团角色_0、加盟商角色_1、门店角色_2
+ ///
+ public int RoleType { get; set; }
+ public DateTime? CreateAt { get; set; }
+ ///
+ /// 状态 【正常 停用】默认 正常
+ ///
+ public CommonStatus Status { get; set; }
+
+ }
+}
diff --git a/BPA.SAAS.Manage.Application/Org/Dtos/Role/RoleDtoPageInput.cs b/BPA.SAAS.Manage.Application/Org/Dtos/Role/RoleDtoPageInput.cs
new file mode 100644
index 0000000..b059b22
--- /dev/null
+++ b/BPA.SAAS.Manage.Application/Org/Dtos/Role/RoleDtoPageInput.cs
@@ -0,0 +1,22 @@
+using BPA.SAAS.Manage.Core.Base;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace BPA.SAAS.Manage.Application.Org.Dtos.Role
+{
+ public class RoleDtoPageInput: PageInputBase
+ {
+ ///
+ /// 名称
+ ///
+ public string Name { get; set; }
+
+ ///
+ /// 编码
+ ///
+ public string Code { get; set; }
+ }
+}
diff --git a/BPA.SAAS.Manage.Application/Org/Dtos/Role/RoleMenuDtoInput.cs b/BPA.SAAS.Manage.Application/Org/Dtos/Role/RoleMenuDtoInput.cs
new file mode 100644
index 0000000..c0f825d
--- /dev/null
+++ b/BPA.SAAS.Manage.Application/Org/Dtos/Role/RoleMenuDtoInput.cs
@@ -0,0 +1,21 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace BPA.SAAS.Manage.Application.Org.Dtos.Role
+{
+ public class RoleMenuDtoInput
+ {
+ ///
+ /// 角色Id
+ ///
+ public string SysRoleId { get; set; }
+
+ ///
+ /// 菜单Id
+ ///
+ public List SysMenuId { get; set; }
+ }
+}
diff --git a/BPA.SAAS.Manage.Application/Org/Interface/IOrganizeService.cs b/BPA.SAAS.Manage.Application/Org/Interface/IOrganizeService.cs
new file mode 100644
index 0000000..178cb72
--- /dev/null
+++ b/BPA.SAAS.Manage.Application/Org/Interface/IOrganizeService.cs
@@ -0,0 +1,20 @@
+using BPA.SAAS.Manage.Application.Org.Dtos.Organize;
+using BPA.SAAS.Manage.Core.Base;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace BPA.SAAS.Manage.Application.Org.Interface
+{
+ public interface IOrganizeService
+ {
+ Task QueryOrgPageList(OrgPageInput input);
+ Task> GetOrgList(OrgListInput input);
+ Task AddOrg(OrgAddInput input);
+ Task DeleteOrg(DeleteOrgInput input);
+ Task UpdateOrg(UpdateOrgInput input);
+ Task GetOrgTree();
+ }
+}
diff --git a/BPA.SAAS.Manage.Application/Org/Interface/IRoleService.cs b/BPA.SAAS.Manage.Application/Org/Interface/IRoleService.cs
index 14f4ade..54bdeab 100644
--- a/BPA.SAAS.Manage.Application/Org/Interface/IRoleService.cs
+++ b/BPA.SAAS.Manage.Application/Org/Interface/IRoleService.cs
@@ -12,6 +12,8 @@ namespace BPA.SAAS.Manage.Application.Org.Interface
{
Task Page(RoleDtoPageInput input);
Task Add(RoleDtoInput input);
+ Task Update(RoleDtoInput input);
+ Task Delete(List input);
Task> GetMenuRole(string RoleId);
Task AddOrUpdateMenuRole(RoleMenuDtoInput input);
Task Disable(string Id);
diff --git a/BPA.SAAS.Manage.Application/Org/OrganizeServices.cs b/BPA.SAAS.Manage.Application/Org/OrganizeServices.cs
new file mode 100644
index 0000000..8c570e6
--- /dev/null
+++ b/BPA.SAAS.Manage.Application/Org/OrganizeServices.cs
@@ -0,0 +1,80 @@
+using BPA.SAAS.Manage.Application.Org.Dtos.Organize;
+using BPA.SAAS.Manage.Application.Org.Interface;
+using BPA.SAAS.Manage.Core.Base;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace BPA.SAAS.Manage.Application.Org
+{
+ [ApiDescriptionSettings("Org", Tag = "组织机构管理")]
+ public class OrganizeServices: IDynamicApiController
+ {
+ IOrganizeService _organizeService;
+ public OrganizeServices(IOrganizeService organizeService)
+ {
+ _organizeService=organizeService;
+ }
+ ///
+ /// 分页查询
+ ///
+ ///
+ ///
+ [HttpPost("/api/organize/page")]
+ public async Task QueryOrgPageList([FromBody]OrgPageInput input)
+ {
+ return await _organizeService.QueryOrgPageList(input);
+ }
+ ///
+ /// 获取列表
+ ///
+ ///
+ ///
+ [HttpPost("/api/organize/getorglist")]
+ public async Task> GetOrgList(OrgListInput input)
+ {
+ return await _organizeService.GetOrgList(input);
+ }
+ ///
+ /// 添加
+ ///
+ ///
+ ///
+ [HttpPost("/api/organize/addorg")]
+ public async Task AddOrg(OrgAddInput input)
+ {
+ return await _organizeService.AddOrg(input);
+ }
+ ///
+ /// 删除
+ ///
+ ///
+ ///
+ [HttpPost("/api/organize/deleteorg")]
+ public async Task DeleteOrg(DeleteOrgInput input)
+ {
+ return await _organizeService.DeleteOrg(input);
+ }
+ ///
+ /// 修改
+ ///
+ ///
+ ///
+ [HttpPost("/api/organize/updateorg")]
+ public async Task UpdateOrg(UpdateOrgInput input)
+ {
+ return await _organizeService.UpdateOrg(input);
+ }
+ ///
+ /// 获取组织机构树
+ ///
+ ///
+ [HttpGet("/api/organize/tree")]
+ public async Task GetOrgTree()
+ {
+ return await _organizeService.GetOrgTree();
+ }
+ }
+}
diff --git a/BPA.SAAS.Manage.Application/Org/RolesServices.cs b/BPA.SAAS.Manage.Application/Org/RolesServices.cs
new file mode 100644
index 0000000..e3c1edf
--- /dev/null
+++ b/BPA.SAAS.Manage.Application/Org/RolesServices.cs
@@ -0,0 +1,101 @@
+using BPA.SAAS.Manage.Application.Org.Dtos.Role;
+using BPA.SAAS.Manage.Application.Org.Interface;
+using BPA.SAAS.Manage.Core.Base;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace BPA.SAAS.Manage.Application.Org
+{
+ [ApiDescriptionSettings("SYS", Tag = "角色信息")]
+ public class RolesServices: IDynamicApiController
+ {
+ IRoleService _roleService;
+ public RolesServices(IRoleService roleService)
+ {
+ _roleService=roleService;
+ }
+ ///
+ /// 分页查询
+ ///
+ ///
+ ///
+ [HttpPost("/api/roles/page")]
+ public async Task Page(RoleDtoPageInput input)
+ {
+ return await _roleService.Page(input);
+ }
+ ///
+ /// 根据角色查询角色菜单
+ ///
+ ///
+ ///
+ [HttpGet("/api/roles/getmenurole")]
+ public async Task> GetMenuRole(string RoleId)
+ {
+ return await _roleService.GetMenuRole(RoleId);
+ }
+ ///
+ /// 添加
+ ///
+ ///
+ ///
+ [HttpPost("/api/roles/add")]
+ public async Task Add(RoleDtoInput input)
+ {
+ return await _roleService.Add(input);
+ }
+ ///
+ /// 更新
+ ///
+ ///
+ ///
+ [HttpPost("/api/roles/update")]
+ public async Task Update(RoleDtoInput input)
+ {
+ return await _roleService.Update(input);
+ }
+ ///
+ /// 删除
+ ///
+ ///
+ ///
+ [HttpPost("/api/roles/delete")]
+ public async Task Delete(List input)
+ {
+ return await _roleService.Delete(input);
+ }
+ ///
+ /// 编辑角色菜单
+ ///
+ ///
+ ///
+ [HttpPost("/api/roles/addorupdatemenurole")]
+ public async Task AddOrUpdateMenuRole(RoleMenuDtoInput input)
+ {
+ return await _roleService.AddOrUpdateMenuRole(input);
+ }
+ ///
+ /// 启用
+ ///
+ ///
+ ///
+ [HttpGet("/api/roles/enable")]
+ public async Task Enable(string Id)
+ {
+ return await _roleService.Enable(Id);
+ }
+ ///
+ /// 禁用
+ ///
+ ///
+ ///
+ [HttpGet("/api/roles/disable")]
+ public async Task Disable(string Id)
+ {
+ return await _roleService.Disable(Id);
+ }
+ }
+}
diff --git a/BPA.SAAS.Manage.Application/Org/Services/OrganizeService.cs b/BPA.SAAS.Manage.Application/Org/Services/OrganizeService.cs
new file mode 100644
index 0000000..3c765ab
--- /dev/null
+++ b/BPA.SAAS.Manage.Application/Org/Services/OrganizeService.cs
@@ -0,0 +1,185 @@
+using BPA.SAAS.Manage.Application.Org.Dtos.Organize;
+using BPA.SAAS.Manage.Application.Org.Interface;
+using BPA.SAAS.Manage.Comm.Enum;
+using BPA.SAAS.Manage.Comm.Util;
+using BPA.SAAS.Manage.Core.Base;
+using BPA.SAAS.Manage.Core.Org;
+using Furion.DatabaseAccessor;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Text.RegularExpressions;
+using System.Threading.Tasks;
+using System.Xml.Linq;
+
+namespace BPA.SAAS.Manage.Application.Org.Services
+{
+ public class OrganizeService : IOrganizeService, ITransient
+ {
+ private readonly ISqlSugarClient _db;
+ public OrganizeService(ISqlSugarClient db)
+ {
+ _db = db;
+ }
+ ///
+ /// 分页获取组织机构列表
+ ///
+ ///
+ ///
+ public async Task QueryOrgPageList(OrgPageInput input)
+ {
+ RefAsync total = 0;
+ var name = !string.IsNullOrEmpty(input.Name?.Trim());
+ var id = !string.IsNullOrEmpty(input.Id?.Trim());
+ var pId = !string.IsNullOrEmpty(input.Pid?.Trim());
+ var data = await _db.Queryable()
+ .WhereIF(!string.IsNullOrWhiteSpace(input.Name), u => u.Name.Contains(input.Name.Trim()))
+ .WhereIF(!string.IsNullOrWhiteSpace(input.Pid), u => u.Pids.Contains(input.Pid.Trim()) || u.Id == input.Pid.Trim())
+ .Select()
+ .OrderBy(a => a.CreateAt, OrderByType.Asc)
+ .ToPageListAsync(input.Current, input.PageSize, total);
+ PageUtil util = new PageUtil()
+ {
+ Total = total,
+ Data = data
+
+ };
+ return util;
+ }
+ ///
+ /// 获取组织机构列表
+ ///
+ ///
+ ///
+ public async Task> GetOrgList(OrgListInput input)
+ {
+ var pId = !string.IsNullOrEmpty(input.Pid?.Trim());
+ var orgs = await _db.Queryable()
+ .WhereIF(pId, u => u.PID == input.Pid)
+ .Where(u => u.Status != CommonStatus.DELETED).ToListAsync();
+ return orgs.Adapt>();
+ }
+ ///
+ /// 新增组织
+ ///
+ ///
+ ///
+ public async Task AddOrg(OrgAddInput input)
+ {
+ if (!string.IsNullOrEmpty(input.Tel))
+ {
+ var tel = Regex.IsMatch(input.Tel, "^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\\d{8}$");
+ if (tel == false) throw Oops.Oh("手机号错误");
+ }
+ var sysOrg = input.Adapt();
+ await FillPids(sysOrg);
+ return await _db.Insertable(sysOrg).CallEntityMethod(m => m.Create()).ExecuteCommandAsync()>0;
+ }
+ ///
+ /// 删除组织机构
+ ///
+ ///
+ ///
+ public async Task DeleteOrg(DeleteOrgInput input)
+ {
+ var sysOrg = await _db.Queryable().FirstAsync(u => u.Id == input.Id);
+ // 级联删除子节点
+ var childIdList = await GetChildIdListWithSelfById(sysOrg.Id);
+ var orgs = await _db.Queryable().Where(u => childIdList.Contains(u.Id)).ToListAsync();
+ return await _db.Deleteable(orgs).ExecuteCommandAsync()>0;
+ }
+
+ ///
+ /// 更新组织机构
+ ///
+ ///
+ ///
+ public async Task UpdateOrg(UpdateOrgInput input)
+ {
+ if (input.Pid != Guid.Empty.ToString() && !string.IsNullOrEmpty(input.Pid) && input.Pid != "0")
+ {
+ var org = await _db.Queryable().FirstAsync(u => u.Id == input.Pid);
+ _ = org ?? throw Oops.Oh("父机构不存在");
+ }
+
+ if (!string.IsNullOrEmpty(input.Tel))
+ {
+ var tel = Regex.IsMatch(input.Tel, "^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\\d{8}$");
+ if (tel == false) throw Oops.Oh("手机号错误");
+ }
+
+ if (input.Id == input.Pid)
+ throw Oops.Oh("当前机构Id不能与父机构Id相同");
+
+ // 如果是编辑,父id不能为自己的子节点
+ var childIdListById = await GetChildIdListWithSelfById(input.Id);
+ if (childIdListById.Contains(input.Pid))
+ throw Oops.Oh("当前机构Id不能与父机构Id相同");
+
+ var sysOrg = await _db.Queryable().FirstAsync(u => u.Id == input.Id);
+ sysOrg.Name=input.Name;
+ sysOrg.Tel = input.Tel;
+ sysOrg.Remark = input.Remark;
+ sysOrg.Sort= input.Sort;
+ await FillPids(sysOrg);
+ return await _db.Updateable(sysOrg).IgnoreColumns(ignoreAllNullColumns: true)
+ .ExecuteCommandAsync()>0;
+
+ }
+ ///
+ /// 获取组织机构树
+ ///
+ ///
+ public async Task GetOrgTree()
+ {
+ var dataScopeList = new List();
+
+ var orgs = await _db.Queryable().WhereIF(dataScopeList.Count > 0, u => dataScopeList.Contains(u.Id))
+ .Where(u => u.Status == CommonStatus.ENABLE).OrderBy(u => u.Sort)
+ .Select(u => new OrgTreeNode
+ {
+ key = u.Id,
+ parentId = u.PID,
+ title = u.Name,
+ value = u.Id.ToString(),
+ weight = u.Sort,
+ Type = u.Type,
+ }).ToListAsync();
+
+ return new TreeBuildUtil().Build(orgs);
+
+ }
+ ///
+ /// 填充父Ids字段
+ ///
+ ///
+ ///
+ private async Task FillPids(BPA_Organize sysOrg)
+ {
+ if (string.IsNullOrWhiteSpace(sysOrg.PID) || sysOrg.PID == "0")
+ {
+ sysOrg.Pids = "[0],";
+ sysOrg.PID = "0";
+ }
+ else
+ {
+ var t = await _db.Queryable().FirstAsync(u => u.Id == sysOrg.PID);
+ sysOrg.Pids = t.Pids + "[" + t.Id + "],";
+ }
+ }
+ ///
+ /// 根据节点Id获取所有子节点Id集合,包含自己
+ ///
+ ///
+ ///
+ private async Task> GetChildIdListWithSelfById(string id)
+ {
+ var childIdList = await _db.Queryable()
+ .Where(u => u.Pids.Contains(id.ToString()))
+ .Select(u => u.Id).ToListAsync();
+ childIdList.Add(id);
+ return childIdList;
+ }
+ }
+}
diff --git a/BPA.SAAS.Manage.Application/Org/Services/RoleService.cs b/BPA.SAAS.Manage.Application/Org/Services/RoleService.cs
index e4a6891..f73eb3a 100644
--- a/BPA.SAAS.Manage.Application/Org/Services/RoleService.cs
+++ b/BPA.SAAS.Manage.Application/Org/Services/RoleService.cs
@@ -48,6 +48,11 @@ namespace BPA.SAAS.Manage.Application.Org.Services
};
return util;
}
+ ///
+ /// 添加
+ ///
+ ///
+ ///
public async Task Add(RoleDtoInput input)
{
@@ -64,6 +69,59 @@ namespace BPA.SAAS.Manage.Application.Org.Services
return await _db.Insertable(role).CallEntityMethod(t => t.Create()).ExecuteCommandAsync() > 0;
}
///
+ /// 修改
+ ///
+ ///
+ ///
+ public async Task Update(RoleDtoInput input)
+ {
+ var BPA_Roles = await _db.Queryable().Where(a => a.Code == input.Code).FirstAsync();
+ var code = BPA_Roles.Code;
+ if (code != input.Code)
+ {
+ throw Oops.Oh("角色编码不能进行修改");
+ }
+ var Roles = await _db.Queryable().Where(a => a.Id == input.Id).FirstAsync();
+ Roles.Name= input.Name;
+ Roles.Code= input.Code;
+ Roles.Remark= input.Remark;
+ Roles.Sort = input.Sort;
+ return _db.Updateable(Roles).ExecuteCommandHasChange();
+
+ }
+ ///
+ /// 删除
+ ///
+ ///
+ ///
+ public async Task Delete(List input)
+ {
+ try
+ {
+ _db.Ado.BeginTran();
+ // 查询数据库中是否存在未删除的活动信息
+ var resEntitites = _db.Queryable().In(input).ToList();
+ var ids = resEntitites.Select(a => a.Id).ToArray();
+ //校验用户
+ var dara = _db.Queryable().Where(x => ids.Contains(x.SysRoleId)).ToList();
+ if (dara.Count() <= 0)
+ {
+ var res =await _db.Deleteable(resEntitites).ExecuteCommandAsync();
+ _db.Ado.CommitTran();
+ return res > 0;
+ }
+ else
+ {
+ throw Oops.Oh("删除失败, 请检查用户是否关联该角色");
+ }
+ }
+ catch (Exception)
+ {
+ _db.Ado.RollbackTran();
+ throw Oops.Oh("删除失败");
+ }
+ }
+ ///
/// 根据角色查询角色菜单
///
///
diff --git a/BPA.SAAS.Manage.Comm/Util/ITreeNode.cs b/BPA.SAAS.Manage.Comm/Util/ITreeNode.cs
new file mode 100644
index 0000000..937f1f1
--- /dev/null
+++ b/BPA.SAAS.Manage.Comm/Util/ITreeNode.cs
@@ -0,0 +1,81 @@
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace BPA.SAAS.Manage.Comm.Util
+{
+ ///
+ /// 树基类
+ ///
+ public interface ITreeNode
+ {
+ ///
+ /// 获取节点id
+ ///
+ ///
+ string GetId();
+
+ ///
+ /// 获取节点父id
+ ///
+ ///
+ string GetPid();
+
+ ///
+ /// 设置Children
+ ///
+ ///
+ void SetChildren(IList children);
+ }
+ ///
+ /// 递归工具类,用于遍历有父子关系的节点,例如菜单树,字典树等等
+ ///
+ ///
+ public class TreeBuildUtil where T : ITreeNode
+ {
+ ///
+ /// 顶级节点的父节点Id(默认00000000-0000-0000-0000-000000000000)
+ ///
+ private readonly string _rootParentId = "0";
+
+ ///
+ /// 构造树节点
+ ///
+ ///
+ ///
+ public List Build(List nodes)
+ {
+ nodes.ForEach(u => BuildChildNodes(nodes, u, new List()));
+
+ var result = new List();
+ nodes.ForEach(u =>
+ {
+ if (_rootParentId == u.GetPid())
+ result.Add(u);
+ });
+ return result;
+ }
+
+ ///
+ /// 构造子节点集合
+ ///
+ ///
+ ///
+ ///
+ private void BuildChildNodes(List totalNodes, T node, List childNodeList)
+ {
+ var nodeSubList = new List();
+ totalNodes.ForEach(u =>
+ {
+ if (u.GetPid().Equals(node.GetId()))
+ nodeSubList.Add(u);
+ });
+ nodeSubList.ForEach(u => BuildChildNodes(totalNodes, u, new List()));
+ childNodeList.AddRange(nodeSubList);
+ node.SetChildren(childNodeList);
+ }
+ }
+}