123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296 |
- using Attribute;
- using Dto;
- using Extensions;
- using Infrastructure;
- using Model;
- using Service;
- using Vo;
- namespace Services
- {
-
-
-
- [AppService(ServiceType = typeof(ISysDeptService), ServiceLifetime = LifeTime.Transient)]
- public class SysDeptService : BaseService<SysDept>, ISysDeptService
- {
- public ISysRoleDeptService RoleDeptRepository;
- public SysDeptService(ISysRoleDeptService roleDeptRepository)
- {
- RoleDeptRepository = roleDeptRepository;
- }
-
-
-
-
-
- public List<SysDept> GetSysDepts(SysDeptQueryDto dept)
- {
- var predicate = Expressionable.Create<SysDept>();
- predicate = predicate.And(it => it.DelFlag == "0");
- predicate = predicate.AndIF(dept.deptName.IfNotEmpty(), it => it.name.Contains(dept.deptName));
- var response = GetList(predicate.ToExpression());
- return response;
- }
-
-
-
-
-
- public string CheckDeptNameUnique(SysDept dept)
- {
- long deptId = dept.deptId == 0 ? -1L : dept.deptId;
- SysDept info = GetFirst(it => it.name == dept.name && it.parentId == dept.parentId);
- if (info != null && info.deptId != deptId)
- {
- return UserConstants.NOT_UNIQUE;
- }
- return UserConstants.UNIQUE;
- }
-
-
-
-
-
- public int InsertDept(SysDept dept)
- {
-
-
-
-
-
-
-
-
-
-
-
- dept.CreateTime = DateTime.Now;
- dept.UpdateTime = DateTime.Now;
- return Add(dept);
- }
-
-
-
-
-
- public int UpdateDept(SysDept dept)
- {
- dept.UpdateTime = DateTime.Now;
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- int result = Update(dept, true);
- return result;
- }
-
-
-
-
- private void UpdateParentDeptStatusNormal(SysDept dept)
- {
-
-
-
-
- }
-
-
-
-
-
-
- public void UpdateDeptChildren(long deptId, string newAncestors, string oldAncestors)
- {
- List<SysDept> children = GetChildrenDepts(GetSysDepts(new SysDeptQueryDto()), deptId);
-
-
-
-
-
-
-
-
-
-
-
- }
-
-
-
-
-
-
- public List<SysDept> GetChildrenDepts(List<SysDept> depts, long deptId)
- {
-
-
-
-
-
- return new List<SysDept>();
- }
-
-
-
-
-
- public List<SysDept> BuildDeptTree(List<SysDept> depts)
- {
- List<SysDept> returnList = new List<SysDept>();
- List<long> tempList = depts.Select(f => f.deptId).ToList();
- foreach (var dept in depts)
- {
-
- if (!tempList.Contains(dept.parentId))
- {
- RecursionFn(depts, dept);
- returnList.Add(dept);
- }
- }
- if (!returnList.Any())
- {
- returnList = depts;
- }
- return returnList;
- }
-
-
-
-
-
- public List<TreeSelectVo> BuildDeptTreeSelect(List<SysDept> depts)
- {
- List<SysDept> menuTrees = BuildDeptTree(depts);
- List<TreeSelectVo> treeMenuVos = new List<TreeSelectVo>();
- foreach (var item in menuTrees)
- {
- treeMenuVos.Add(new TreeSelectVo(item));
- }
- return treeMenuVos;
- }
-
-
-
-
-
- private void RecursionFn(List<SysDept> list, SysDept t)
- {
-
- List<SysDept> childList = GetChildList(list, t);
- t.children = childList;
- foreach (var item in childList)
- {
- if (GetChildList(list, item).Count() > 0)
- {
- RecursionFn(list, item);
- }
- }
- }
-
-
-
-
-
-
- private List<SysDept> GetChildList(List<SysDept> list, SysDept dept)
- {
- return list.Where(p => p.parentId == dept.deptId).ToList();
- }
- #region 角色部门
-
-
-
-
-
- public List<SysRoleDept> SelectRoleDeptByRoleId(long roleId)
- {
- return RoleDeptRepository.SelectRoleDeptByRoleId(roleId);
- }
-
-
-
-
-
- public List<long> SelectRoleDepts(long roleId)
- {
- var list = SelectRoleDeptByRoleId(roleId);
- return list.Select(x => x.DeptId).Distinct().ToList();
- }
-
-
-
-
-
- public bool DeleteRoleDeptByRoleId(long roleId)
- {
- return RoleDeptRepository.Delete(f => f.RoleId == roleId);
- }
-
-
-
-
-
- public int InsertRoleDepts(SysRole role)
- {
- int rows = 1;
-
-
-
-
-
-
-
-
-
- return rows;
- }
- #endregion
- }
-
-
-
- [AppService(ServiceType = typeof(ISysRoleDeptService), ServiceLifetime = LifeTime.Transient)]
- public class SysRoleDeptService : BaseService<SysRoleDept>, ISysRoleDeptService
- {
- public List<SysRoleDept> SelectRoleDeptByRoleId(long roleId)
- {
- return GetList(it => it.RoleId == roleId).ToList();
- }
- }
- }
|