ComplianceServer/oldcode/BLL/Csvr/CSVR_CALLDATAREPORT_BL.cs

130 lines
5.3 KiB
C#

using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using WX.CRM.BLL.Base;
using WX.CRM.BLL.Util;
using WX.CRM.Common;
using WX.CRM.DAL.Csvr;
using WX.CRM.IBLL.Csvr;
using WX.CRM.Model.MAP;
using WX.CRM.BLL.Util;
using WX.CRM.BLL.Application.UserComBox;
using WX.CRM.Model.QueryMap;
namespace WX.CRM.BLL.Csvr
{
public class CSVR_CALLDATAREPORT_BL : ICSVR_CALLDATAREPORT
{
private CACHE_BL _cache = new CACHE_BL();
public DataSet GetCallReport(ref Pager pager, QueryUserComboDto usercomboDto, DateTime? V_STIME, DateTime? V_ETIME)
{
if (string.IsNullOrEmpty(usercomboDto.groupIds) && !string.IsNullOrEmpty(usercomboDto.deptId))
{
UserServices userservices = new UserServices();
List<decimal> ALLdeptIDS = new List<decimal>();
List<decimal> ALLgidS = new List<decimal>();
userservices.GetAllDeptIDOrGidByDeptStr(usercomboDto.deptId, ref ALLdeptIDS, ref ALLgidS);
usercomboDto.deptId = string.Join(",", ALLdeptIDS);//所有的部门ID和销售组ID
usercomboDto.groupIds = string.Join(",", ALLgidS);
}
return new CALLDATAREPORT_DAL().GetCallReport(ref pager, usercomboDto, V_STIME, V_ETIME);
}
public List<WD_CallReportModel> Get_UserCallReport(ref Pager pager, int eid)
{
All_WD_CallReportModel model = Get_WD_CallReport();
var list = model.list.Where(p => p.SALESEID == eid && p.WD != null).ToList();
return list;
}
public List<WD_CallReportModel> Get_CallReport(ref Pager pager, int wd, QueryUserComboDto usercomboDto, ref string date)
{
var users = _cache.GetUserList();
var groups = _cache.GetGroupList();
var userGroup = _cache.GetList_InnerUserGroup();
var dept = _cache.GetList_SalesDepartMent();
All_WD_CallReportModel model = Get_WD_CallReport();
var list = model.list.Where(p => p.WD == wd || p.WD == 0).ToList();
if (usercomboDto.userId.HasValue)
{
decimal eid = 0;
var user = new BAS_INNERUSER_BL().GetModel(usercomboDto.userId.Value);
if (user != null)
{
eid = user.EID;
}
list = list.Where(p => p.SALESEID == eid).ToList();
}
else if (!string.IsNullOrEmpty(usercomboDto.groupIds))
{
string[] gid = usercomboDto.groupIds.Split(',');
var glist = new BAS_INNERUSERGROUP_BL().GetList().Where(p => gid.Contains(p.GID.ToString())).ToList();
var userids = glist.Select(p => p.INNERUSERID).ToArray();
var InnerUser = new BAS_INNERUSER_BL().GetInnerUserByGroup(userids).Select(p => p.EID).ToArray();
list = list.Where(p => InnerUser.Contains(p.SALESEID)).ToList();
}
else if (!string.IsNullOrEmpty(usercomboDto.deptId))
{
UserServices userservices = new UserServices();
List<decimal> ALLdeptIDS = new List<decimal>();
List<decimal> ALLgidS = new List<decimal>();
userservices.GetAllDeptIDOrGidByDeptStr(usercomboDto.deptId, ref ALLdeptIDS, ref ALLgidS);
list = (from a in list
join u in users on a.SALESEID equals u.EID
join b in userGroup on u.PKID equals b.INNERUSERID
where ALLdeptIDS.Contains(b.DEPTID.Value) || ALLgidS.Contains(b.GID.Value)
select a).ToList();
}
else if (usercomboDto.companyId.HasValue)
{
list = (from a in list
join u in users on a.SALESEID equals u.EID
join ug in userGroup on u.PKID equals ug.INNERUSERID
join g in groups on ug.GID equals g.GID
join d in dept on g.SALEDEPTID equals d.SALEDEPTID
where d.COMPANYID == usercomboDto.companyId.Value
select a).ToList();
}
date = model.CreateDate.ToString("yyyy-MM-dd HH:mm:ss");
return list;
}
public All_WD_CallReportModel Get_WD_CallReport()
{
try
{
string cacheKey = "cache_WD_CallReport_getList";
if (CacheHelper.Exists(cacheKey))
{
return CacheHelper.Get<All_WD_CallReportModel>(cacheKey);
}
else
{
All_WD_CallReportModel theModel = new All_WD_CallReportModel();
DateTime expiresTime = DateTime.Now.AddMinutes(10);
var ds = new CALLDATAREPORT_DAL().Get_WD_CallReport();
List<WD_CallReportModel> list = ds.Tables[0].ToList<WD_CallReportModel>();
theModel.CreateDate = DateTime.Now;
theModel.list = list;
CacheHelper.Set<All_WD_CallReportModel>(cacheKey, theModel, expiresTime, false);
return theModel;
}
}
catch
{
throw;
}
}
}
}