TG.WXCRM.V4/BLL/Csvr/CSVR_FAVORITECUSTOMER_HIS_B...

74 lines
3.2 KiB
C#

using System.Collections.Generic;
using WX.CRM.BLL.Util;
using WX.CRM.Common;
using WX.CRM.IBLL.Csvr;
using WX.CRM.Model.Entity;
using System.Linq;
namespace WX.CRM.BLL.Csvr
{
public class CSVR_FAVORITECUSTOMER_HIS_BL : DbContextRepository<CSVR_FAVORITECUSTOMER_HIS>, ICSVR_FAVORITECUSTOMER_HIS
{
private CACHE_BL cache_BL = new CACHE_BL();
public List<CSVR_FAVORITECUSTOMER_HIS_View> GetHisList(Pager pager, string groupId, decimal? userId, string subcomgroupId, string resId, int? deptlineid)
{
var deptList = cache_BL.GetDeptNameMapList();
using (var db = new crmContext())
{
var queryData = from a in db.CSVR_FAVORITECUSTOMER_HIS
join b in db.BAS_INNERUSER on a.SALESID equals b.PKID
join c in db.RES_CUSTOMER on a.RESID equals c.RESID
select new CSVR_FAVORITECUSTOMER_HIS_View
{
ACTION = a.ACTION,
ACTIONTIME = a.ACTIONTIME,
CTIME = a.CTIME,
MEMO = a.MEMO,
NAME = a.NAME,
OPERATOR = a.OPERATOR,
PARAKEY = a.PARAKEY,
PKID = a.PKID,
REMARK = a.REMARK,
RESID = c.UMID,
SALESID = a.SALESID,
DeptId = b.DEPTID,
};
if (userId.HasValue)
{
queryData = queryData.Where(p => p.SALESID == userId);
}
else if (!string.IsNullOrEmpty(groupId))
{
decimal[] _groupids = OperationUtil.ConvertToDecimal(groupId.Split(','));
var group = cache_BL.GetList_InnerUserGroup();
var uIds = group.Where(p => p.GID != null && _groupids.Contains(p.GID.Value)).Select(p => p.INNERUSERID);
queryData = queryData.Where(m => uIds.Contains(m.SALESID));
}
if (!string.IsNullOrEmpty(subcomgroupId) && subcomgroupId != "0")
{
queryData = queryData.Where(p => p.PARAKEY == subcomgroupId);
}
if (!string.IsNullOrEmpty(resId))
{
queryData = queryData.Where(p => p.RESID == resId);
}
if (deptlineid.HasValue)
{
queryData = queryData.Where(p => p.DeptId == deptlineid);
}
queryData = queryData.OrderByDescending(p => p.PKID);
PagerUtil.SetPager<CSVR_FAVORITECUSTOMER_HIS_View>(ref queryData, ref pager);
var res = queryData.ToList();
foreach (var item in res)
{
item.DeptName = deptList.FirstOrDefault(n => n.id == item.DeptId)?.title;
}
return res;
}
}
}
}