177 lines
7.6 KiB
C#
177 lines
7.6 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(decimal? 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 (deptId.HasValue)
|
|
{
|
|
GetAllDeptIDOrGid(salesDeptList, groupList, deptId.Value, ref deptIDS, ref gidS);//获取所有的子部门和销售组
|
|
}
|
|
//var query = from d in salesDeptList
|
|
// 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,
|
|
// DeptId = d.SALEDEPTID,
|
|
// GroupId = g.GID
|
|
// };
|
|
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
|
|
};
|
|
if (deptId.HasValue)
|
|
{
|
|
query = query.Where(p => deptIDS.Contains(p.DeptId.Value) || (p.GroupId != null && gidS.Contains(p.GroupId.Value)));
|
|
}
|
|
if (!string.IsNullOrEmpty(groupId))
|
|
{
|
|
var gids = groupId.Split(',');
|
|
var mygids = gids.Select(m => Convert.ToDecimal(m)).ToArray();
|
|
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).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<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();
|
|
}
|
|
}
|
|
|
|
public interface IUserServices
|
|
{
|
|
List<UserComBoDto> GetUserComBo(decimal? companyId, decimal? deptId, string groupId, decimal? userId);
|
|
List<UserComBoDto> GetUserComBoSSO(decimal? deptId, string groupId, decimal? userId);
|
|
void GetAllDeptIDOrGidByDeptId(decimal deptId, ref List<decimal> deptIDS, ref List<decimal> gidS);
|
|
}
|
|
}
|