145 lines
7.4 KiB
C#
145 lines
7.4 KiB
C#
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using WX.CRM.BLL.Application.UserComBox;
|
|
using WX.CRM.BLL.Util;
|
|
using WX.CRM.Common;
|
|
using WX.CRM.IBLL.Res;
|
|
using WX.CRM.Model.DTO;
|
|
using WX.CRM.Model.Entity;
|
|
using WX.CRM.Model.MAP;
|
|
|
|
namespace WX.CRM.BLL.Res
|
|
{
|
|
public class RES_SHAREDCUSTOMER_BL : DbContextRepository<RES_SHAREDCUSTOMER>, IRES_SHAREDCUSTOMER
|
|
{
|
|
public List<Res_SharedCustomer_View> GetList(ref Pager pager, QueryUserComboDto usercomboDto, int? type, string resId)
|
|
{
|
|
using (var db = new crmContext())
|
|
{
|
|
var query = from a in db.RES_SHAREDCUSTOMER
|
|
join b in db.RES_CUSTOMERDETAIL on a.RESID equals b.RESID
|
|
select new Res_SharedCustomer_View()
|
|
{
|
|
ResId = b.UMID,
|
|
CName = b.CNAME,
|
|
InnerUserId = a.INNERUSERID,
|
|
EId = a.EID,
|
|
SharedInnerUserId = a.SHAREDINNERUSERID,
|
|
SharedEId = a.SHAREDEID,
|
|
CTime = a.CTIME
|
|
};
|
|
if (!string.IsNullOrEmpty(resId))
|
|
{
|
|
query = query.Where(p => p.ResId == resId);
|
|
}
|
|
if (type.HasValue)
|
|
{
|
|
if (type.Value == 1)
|
|
{
|
|
if (usercomboDto.userId.HasValue)
|
|
{
|
|
query = query.Where(m => m.SharedInnerUserId == usercomboDto.userId.Value);
|
|
}
|
|
else if (!string.IsNullOrEmpty(usercomboDto.groupIds))
|
|
{
|
|
var _groupids = OperationUtil.ConvertToDecimal(usercomboDto.groupIds.Split(','));
|
|
query = (from a in query
|
|
join b in db.BAS_INNERUSERGROUP on a.SharedInnerUserId equals b.INNERUSERID
|
|
where _groupids.Contains(b.GID.Value)
|
|
select a);
|
|
}
|
|
else if (!string.IsNullOrEmpty(usercomboDto.deptId))
|
|
{
|
|
var depts = OperationUtil.ConvertToDecimal(usercomboDto.deptId.Split(','));
|
|
List<decimal> ALLdeptIDS = new List<decimal>();
|
|
List<decimal> ALLgidS = new List<decimal>();
|
|
UserServices userservices = new UserServices();
|
|
foreach (var item in depts)
|
|
{
|
|
List<decimal> deptIDS = new List<decimal>();
|
|
List<decimal> gidS = new List<decimal>();
|
|
userservices.GetAllDeptIDOrGidByDeptId(item, ref deptIDS, ref gidS);//获取所有的组别和gid
|
|
ALLdeptIDS.AddRange(deptIDS);
|
|
ALLgidS.AddRange(gidS);
|
|
}
|
|
query = (from a in query
|
|
join b in db.BAS_INNERUSERGROUP on a.SharedInnerUserId equals b.INNERUSERID
|
|
//join g in db.BAS_INNERGROUP on b.GID equals g.GID
|
|
where ALLdeptIDS.Contains(b.DEPTID.Value) || ALLgidS.Contains(b.GID.Value)
|
|
select a);
|
|
}
|
|
}
|
|
else if (type.Value == 2)
|
|
{
|
|
if (usercomboDto.userId.HasValue)
|
|
{
|
|
query = query.Where(m => m.InnerUserId == usercomboDto.userId.Value);
|
|
}
|
|
else if (!string.IsNullOrEmpty(usercomboDto.groupIds))
|
|
{
|
|
var _groupids = OperationUtil.ConvertToDecimal(usercomboDto.groupIds.Split(','));
|
|
query = (from a in query
|
|
join b in db.BAS_INNERUSERGROUP on a.InnerUserId equals b.INNERUSERID
|
|
where _groupids.Contains(b.GID.Value)
|
|
select a);
|
|
}
|
|
else if (!string.IsNullOrEmpty(usercomboDto.deptId))
|
|
{
|
|
var depts = OperationUtil.ConvertToDecimal(usercomboDto.deptId.Split(','));
|
|
List<decimal> ALLdeptIDS = new List<decimal>();
|
|
List<decimal> ALLgidS = new List<decimal>();
|
|
UserServices userservices = new UserServices();
|
|
foreach (var item in depts)
|
|
{
|
|
List<decimal> deptIDS = new List<decimal>();
|
|
List<decimal> gidS = new List<decimal>();
|
|
userservices.GetAllDeptIDOrGidByDeptId(item, ref deptIDS, ref gidS);//获取所有的组别和gid
|
|
ALLdeptIDS.AddRange(deptIDS);
|
|
ALLgidS.AddRange(gidS);
|
|
}
|
|
query = (from a in query
|
|
join b in db.BAS_INNERUSERGROUP on a.InnerUserId equals b.INNERUSERID
|
|
//join g in db.BAS_INNERGROUP on b.GID equals g.GID
|
|
where ALLdeptIDS.Contains(b.DEPTID.Value) || ALLgidS.Contains(b.GID.Value)
|
|
select a);
|
|
}
|
|
//if (userId.HasValue)
|
|
// query = query.Where(a => a.INNERUSERID == userId.Value);
|
|
//else
|
|
//{
|
|
// if (!string.IsNullOrWhiteSpace(groupId))
|
|
// {
|
|
// var _groupids = OperationUtil.ConvertToDecimal(groupId.ToString().Split(','));
|
|
// List<decimal?> groupList = new List<decimal?>();
|
|
// if (_groupids != null)
|
|
// {
|
|
// foreach (var g in _groupids)
|
|
// {
|
|
// groupList.Add(g);
|
|
// }
|
|
// }
|
|
// if (groupList != null)
|
|
// {
|
|
// var returnData = from a in query
|
|
// join b in db.BAS_INNERUSERGROUP on a.INNERUSERID equals b.INNERUSERID
|
|
// where groupList.Contains(b.GID)
|
|
// select a;
|
|
|
|
// query = returnData;
|
|
// }
|
|
// }
|
|
//}
|
|
}
|
|
}
|
|
|
|
query = query.OrderByDescending(p => p.CTime);
|
|
|
|
PagerUtil.SetPager<Res_SharedCustomer_View>(ref query, ref pager);
|
|
|
|
return query.ToList();
|
|
}
|
|
}
|
|
}
|
|
} |