TG.WXCRM.V4/BLL/Res/RES_SHAREDPOOL_BL.cs

103 lines
5.3 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using WX.CRM.Common;
using WX.CRM.DAL.Res;
using WX.CRM.IBLL.Res;
using WX.CRM.Model.DTO;
using WX.CRM.Model.Entity;
namespace WX.CRM.BLL.Res
{
public class RES_SHAREDPOOL_BL : DbContextRepository<RES_SHAREDPOOL>, IRES_SHAREDPOOL
{
private readonly RES_SHAREDPOOL_DAL _dal = new RES_SHAREDPOOL_DAL();
public int GetCount(string resTypeCode)
{
var code = new List<string>() { "Q0009", "Q0015", "Q2002", "Q2007", "Q2012" };
using (var db = new crmContext())
{
var count = 0;
if (!string.IsNullOrEmpty(resTypeCode))
{
if (resTypeCode == "other")
{
//count = (from a in db.RES_SHAREDPOOL
// join b in db.RES_CUSTOMERUSER on a.RESID equals b.RESID into abTmp
// from ab in abTmp.DefaultIfEmpty()
// where ab.RESID == null
// select ab
// ).Count();
count = (from a in db.RES_SHAREDPOOL
join b in db.RES_POOLLOG on a.RESID equals b.RESID into abTmp
from ab in abTmp.DefaultIfEmpty()
join c in db.RES_RESOURCETYPE on ab.RESTYPEID equals c.RESTYPEID into bcTmp
from bc in bcTmp.DefaultIfEmpty()
join d in db.RES_CUSTOMERUSER on a.RESID equals d.RESID into adTmp
from ad in adTmp.DefaultIfEmpty()
where !code.Contains(bc.RESTYPECODE) && ad.RESID == null
select a.RESID).Distinct().Count();
}
else if (resTypeCode == "Q0009" || resTypeCode == "Q2002")//注册
{
//count = (from a in db.RES_SHAREDPOOL
// join b in db.RES_CUSTOMERUSER on a.RESID equals b.RESID into abTmp
// from ab in abTmp.DefaultIfEmpty()
// where ab.RESID != null
// select ab
// ).Count();
count = (from a in db.RES_SHAREDPOOL
join b in db.RES_POOLLOG on a.RESID equals b.RESID into abTmp
from ab in abTmp.DefaultIfEmpty()
join c in db.RES_RESOURCETYPE on ab.RESTYPEID equals c.RESTYPEID into bcTmp
from bc in bcTmp.DefaultIfEmpty()
join d in db.RES_CUSTOMERUSER on a.RESID equals d.RESID into adTmp
from ad in adTmp.DefaultIfEmpty()
//where bc.RESTYPECODE == resTypeCode || bc.RESTYPECODE == null || ad.RESID != null
where bc.RESTYPECODE == resTypeCode && ad.RESID != null
select a.RESID).Distinct().Count();
}
else if (resTypeCode == "Q0015" || resTypeCode == "Q2007" || resTypeCode == "Q2012")//推广
{
count = (from a in db.RES_SHAREDPOOL
join b in db.RES_POOLLOG on a.RESID equals b.RESID into abTmp
from ab in abTmp.DefaultIfEmpty()
join c in db.RES_RESOURCETYPE on ab.RESTYPEID equals c.RESTYPEID into bcTmp
from bc in bcTmp.DefaultIfEmpty()
join d in db.RES_CUSTOMERUSER on a.RESID equals d.RESID into adTmp
from ad in adTmp.DefaultIfEmpty()
where bc.RESTYPECODE == resTypeCode
select a.RESID).Distinct().Count();
}
}
else
{
count = db.RES_SHAREDPOOL.Count();
}
return count;
}
}
public List<Res_SharedPool_View> GetList(ref Pager pg, string resid, DateTime? sTime, DateTime? eTime, DateTime? aTime, DateTime? bTime, string cName, string resTypeCode, string noContact, string memoType, decimal? labeltype, DateTime? loginstime, DateTime? loginetime)
{
var ds = _dal.GetList(ref pg, resid, sTime, eTime, aTime, bTime, cName, resTypeCode, noContact, memoType, labeltype, loginstime, loginetime);
//LogHelper.Info(ds.Tables[0].Rows.Count.ToString());
var list = ds.Tables[0].ToList<Res_SharedPool_View>();
if (list.Any())
pg.totalRows = Convert.ToInt32(list.Select(p => p.rowcount).First());
else pg.totalRows = 0;
return list;
}
public string FindSharedPoolRes(decimal userId, decimal eid, string resTypeCode)
{
var ds = _dal.FindSharedPoolRes(userId, eid, resTypeCode);
var dt = ds.Tables[0];
if (dt.Rows.Count > 0)
{
return dt.Rows[0][0].ToString();
}
return string.Empty;
}
}
}