226 lines
9.7 KiB
C#
226 lines
9.7 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using WX.CRM.BLL.Util;
|
|
using WX.CRM.Common;
|
|
using WX.CRM.IBLL.Util;
|
|
using WX.CRM.Model.Entity;
|
|
|
|
namespace WX.CRM.BLL.Application.UserComBox
|
|
{
|
|
public class UserServices : IUserServices
|
|
{
|
|
private ICACHE_Q _cache;
|
|
|
|
public UserServices(ICACHE_Q cache = null)
|
|
{
|
|
this._cache = cache;
|
|
if (_cache == null)
|
|
_cache = new CACHE_BL();
|
|
}
|
|
/// <summary>
|
|
/// 对接SSO后拿取的数据
|
|
/// </summary>
|
|
/// <param name="companyId"></param>
|
|
/// <param name="deptId"></param>
|
|
/// <param name="groupId"></param>
|
|
/// <param name="userId"></param>
|
|
/// <returns></returns>
|
|
public List<UserComBoDto> GetUserComBoSSO(string deptId, string groupId, decimal? userId)
|
|
{
|
|
var salesDeptList = _cache.GetList_SalesDepartMent();
|
|
var groupList = _cache.GetGroupList();
|
|
var userGroup = _cache.GetList_InnerUserGroup();
|
|
var users = _cache.GetUserList();
|
|
List<decimal> deptIDS = new List<decimal>();
|
|
List<decimal> gidS = new List<decimal>();
|
|
if (!string.IsNullOrWhiteSpace(deptId))
|
|
{
|
|
var deptids = deptId.Split(',');
|
|
foreach(var id in deptids)
|
|
{
|
|
GetAllDeptIDOrGid(salesDeptList, groupList,Convert.ToDecimal(id), ref deptIDS, ref gidS);//获取所有的子部门和销售组
|
|
}
|
|
deptIDS = deptIDS.Distinct().ToList();
|
|
gidS = gidS.Distinct().ToList();
|
|
}
|
|
var query = from a in users
|
|
join m in userGroup on a.PKID equals m.INNERUSERID
|
|
select new UserComBoDto()
|
|
{
|
|
UserId = a.PKID,
|
|
Eid = a.EID,
|
|
UName = a.UNAME,
|
|
IsDimiss = a.ISDISMISS,
|
|
DeptId = m.DEPTID,
|
|
GroupId = m.GID
|
|
};
|
|
List<decimal> mygids = new List<decimal>();
|
|
if (!string.IsNullOrEmpty(groupId))
|
|
{
|
|
var gids = groupId.Split(',');
|
|
mygids = gids.Select(m => Convert.ToDecimal(m)).ToList();
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(deptId))
|
|
{
|
|
gidS.AddRange(mygids);
|
|
query = query.Where(p => deptIDS.Contains(p.DeptId.Value) || (p.GroupId != null && gidS.Contains(p.GroupId.Value)));
|
|
}
|
|
if (!string.IsNullOrEmpty(groupId))
|
|
{
|
|
query = query.Where(p => p.GroupId != null && mygids.Contains(p.GroupId.Value));
|
|
}
|
|
if (userId.HasValue)
|
|
{
|
|
query = query.Where(p => p.UserId == userId.Value);
|
|
}
|
|
|
|
return query.ToList();
|
|
}
|
|
|
|
public void GetAllDeptIDOrGidByDeptStr(string deptstr, ref List<decimal> ALLdeptIDS, ref List<decimal> ALLgidS)
|
|
{
|
|
var depts = OperationUtil.ConvertToDecimal(deptstr.Split(','));
|
|
foreach (var item in depts)
|
|
{
|
|
List<decimal> deptIDS = new List<decimal>();
|
|
List<decimal> gidS = new List<decimal>();
|
|
GetAllDeptIDOrGidByDeptId(item, ref deptIDS, ref gidS);//获取所有的组别和gid
|
|
ALLdeptIDS.AddRange(deptIDS);
|
|
ALLgidS.AddRange(gidS);
|
|
}
|
|
ALLdeptIDS = ALLdeptIDS.Distinct().ToList();
|
|
ALLgidS = ALLgidS.Distinct().ToList();
|
|
}
|
|
public void GetAllDeptIDOrGidByDeptId(decimal deptId, ref List<decimal> deptIDS, ref List<decimal> gidS)
|
|
{
|
|
var salesDeptList = _cache.GetList_SalesDepartMent();
|
|
var groupList = _cache.GetGroupList();
|
|
var userGroup = _cache.GetList_InnerUserGroup();
|
|
var users = _cache.GetUserList();
|
|
GetAllDeptIDOrGid(salesDeptList, groupList, deptId, ref deptIDS, ref gidS);//获取所有的子部门和销售组
|
|
}
|
|
private void GetAllDeptIDOrGid(List<BAS_SALESDEPARTMENT> salesDeptList, List<BAS_INNERGROUP> groupList, decimal deptId, ref List<decimal> deptIDS, ref List<decimal> gidS)
|
|
{
|
|
var dept = salesDeptList.FirstOrDefault(m => m.SALEDEPTID == deptId);
|
|
if (dept != null)
|
|
{
|
|
deptIDS.Add(deptId);//本ID也是需要加入
|
|
List<BAS_SALESDEPARTMENT> list = salesDeptList.Where(n => n.DEPARTMENT_PARENTID == dept.DEPARTMENT_ID && n.IS_DELETED == 0 && n.SALEDEPTID != dept.SALEDEPTID).OrderBy(m => m.DEPARTMENT_SORT).ToList();
|
|
foreach (var item in list)
|
|
{
|
|
deptIDS.Add(item.SALEDEPTID);
|
|
GetAllDeptIDOrGid(salesDeptList, groupList, item.SALEDEPTID, ref deptIDS, ref gidS);
|
|
}
|
|
}
|
|
gidS.AddRange(groupList.Where(m => m.SALEDEPTID == deptId).Select(m => m.GID));
|
|
gidS.AddRange(groupList.Where(m => m.GID == deptId).Select(m => m.GID));
|
|
}
|
|
public List<BAS_INNERUSER> GetAllUserByDeptOrGroup(List<decimal> deptIdList,List<decimal> groupIdList)
|
|
{
|
|
var ALLdeptIDS = new List<decimal>();
|
|
var ALLgidS = new List<decimal>();
|
|
foreach (var item in deptIdList)
|
|
{
|
|
List<decimal> deptIDS = new List<decimal>();
|
|
List<decimal> gidS = new List<decimal>();
|
|
GetAllDeptIDOrGidByDeptId(item, ref deptIDS, ref gidS);//获取所有的组别和gid
|
|
ALLdeptIDS.AddRange(deptIDS);
|
|
ALLgidS.AddRange(gidS);
|
|
}
|
|
ALLgidS.AddRange(groupIdList);
|
|
ALLdeptIDS = ALLdeptIDS.Distinct().ToList();
|
|
ALLgidS = ALLgidS.Distinct().ToList();
|
|
|
|
var userGroup = _cache.GetList_InnerUserGroup();
|
|
var users = _cache.GetUserList().Where(n=>n.ISDISMISS == 0).ToList();
|
|
var deptUser = userGroup.Where(n => n.DEPTID.HasValue && ALLdeptIDS.Contains(n.DEPTID.Value)).Select(n=>n.INNERUSERID).ToList();
|
|
var groupUser = userGroup.Where(n => n.GID.HasValue && ALLgidS.Contains(n.GID.Value)).Select(n => n.INNERUSERID).ToList();
|
|
deptUser.AddRange(groupUser);
|
|
deptUser = deptUser.Distinct().ToList();
|
|
return users.Where(n => deptUser.Contains(n.PKID)).ToList();
|
|
|
|
}
|
|
|
|
public List<UserComBoDto> GetUserComBo(decimal? companyId, decimal? deptId, string groupId, decimal? userId)
|
|
{
|
|
var companyList = _cache.GetList_innerCompany();
|
|
var salesDeptList = _cache.GetList_SalesDepartMent();
|
|
var groupList = _cache.GetGroupList();
|
|
var userGroup = _cache.GetList_InnerUserGroup();
|
|
var users = _cache.GetUserList();
|
|
var query = from c in companyList
|
|
join d in salesDeptList on c.COMPANYID equals d.COMPANYID
|
|
join g in groupList on d.SALEDEPTID equals g.SALEDEPTID
|
|
join ug in userGroup on g.GID equals ug.GID
|
|
join u in users on ug.INNERUSERID equals u.PKID
|
|
select new UserComBoDto()
|
|
{
|
|
UserId = u.PKID,
|
|
Eid = u.EID,
|
|
UName = u.UNAME,
|
|
IsDimiss = u.ISDISMISS,
|
|
CompanyId = c.COMPANYID,
|
|
DeptId = d.SALEDEPTID,
|
|
GroupId = g.GID
|
|
};
|
|
|
|
if (companyId.HasValue)
|
|
{
|
|
query = query.Where(p => p.CompanyId == companyId.Value);
|
|
}
|
|
if (deptId.HasValue)
|
|
{
|
|
query = query.Where(p => p.DeptId == deptId.Value);
|
|
}
|
|
if (!string.IsNullOrEmpty(groupId))
|
|
{
|
|
var gids = groupId.Split(',');
|
|
var mygids = gids.Select(m => Convert.ToDecimal(m)).ToArray();
|
|
query = query.Where(p => mygids.Contains(p.GroupId.Value));
|
|
}
|
|
if (userId.HasValue)
|
|
{
|
|
query = query.Where(p => p.UserId == userId.Value);
|
|
}
|
|
|
|
return query.ToList();
|
|
}
|
|
/// <summary>
|
|
/// 获取上级部门id
|
|
/// </summary>
|
|
/// <param name="deptId"></param>
|
|
/// <returns></returns>
|
|
public List<decimal> GetParentDeptId(decimal? deptId)
|
|
{
|
|
List<decimal> res = new List<decimal> { };
|
|
var salesDeptList = _cache.GetList_SalesDepartMent();
|
|
var dept = salesDeptList.FirstOrDefault(b => b.SALEDEPTID == deptId);
|
|
BuildParentDept(dept, salesDeptList, res);
|
|
return res;
|
|
}
|
|
public void BuildParentDept(BAS_SALESDEPARTMENT dept, List<BAS_SALESDEPARTMENT> deptList, List<decimal> res)
|
|
{
|
|
if (dept != null)
|
|
{
|
|
res.Add(dept.SALEDEPTID);
|
|
if (dept.DEPARTMENT_PARENTID.HasValue)
|
|
{
|
|
var parDept = deptList.FirstOrDefault(n => n.DEPARTMENT_ID == dept.DEPARTMENT_PARENTID);
|
|
BuildParentDept(parDept, deptList, res);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public interface IUserServices
|
|
{
|
|
List<UserComBoDto> GetUserComBo(decimal? companyId, decimal? deptId, string groupId, decimal? userId);
|
|
List<UserComBoDto> GetUserComBoSSO(string deptId, string groupId, decimal? userId);
|
|
void GetAllDeptIDOrGidByDeptId(decimal deptId, ref List<decimal> deptIDS, ref List<decimal> gidS);
|
|
List<decimal> GetParentDeptId(decimal? deptId);
|
|
}
|
|
}
|