ComplianceServer/oldcode/BLL/Res/RES_SHAREDCUSTOMER_BL.cs

178 lines
8.8 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 = db.RES_SHAREDCUSTOMER.AsQueryable();
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);
}
//if (userId.HasValue)
// query = query.Where(a => a.SHAREDINNERUSERID == 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.SHAREDINNERUSERID equals b.INNERUSERID
// where groupList.Contains(b.GID)
// select a;
// query = returnData;
// }
// }
//}
}
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>(ref query, ref pager);
var data = from a in query
join b in db.RES_CUSTOMERDETAIL on a.RESID equals b.RESID
select new Res_SharedCustomer_View()
{
ResId = a.RESID,
CName = b.CNAME,
InnerUserId = a.INNERUSERID,
EId = a.EID,
SharedInnerUserId = a.SHAREDINNERUSERID,
SharedEId = a.SHAREDEID,
CTime = a.CTIME
};
return data.ToList();
}
}
}
}