299 lines
13 KiB
C#
299 lines
13 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.Res;
|
|
using WX.CRM.IBLL.Res;
|
|
using WX.CRM.Model.Entity;
|
|
using WX.CRM.Model.QueryMap;
|
|
using System.Data;
|
|
using WX.CRM.DAL.Res;
|
|
using WX.CRM.BLL.Base;
|
|
using WX.CRM.BLL.Util;
|
|
using WX.CRM.Model.MAP;
|
|
using WX.CRM.BLL.Application.UserComBox;
|
|
|
|
namespace WX.CRM.BLL.Res
|
|
{
|
|
public class RES_ALLOCATESTRATEGY_BL : IRES_ALLOCATESTRATEGY, IRES_ALLOCATESTRATEGY_Q
|
|
{
|
|
private CACHE_BL cache_BL = new CACHE_BL();
|
|
|
|
public bool Create_AllocateStrategy(ref ValidationErrors errors, RES_ALLOCATESTRATEGY model)
|
|
{
|
|
try
|
|
{
|
|
using (var db = new crmContext())
|
|
{
|
|
RES_ALLOCATESTRATEGY entity = db.RES_ALLOCATESTRATEGY.FirstOrDefault(m => m.STRATEGYNAME == model.STRATEGYNAME);
|
|
if (entity == null)
|
|
{
|
|
model.STRATEGYID = new SEQUENCES_BL().Seq_base_get();
|
|
model.SALESGROUPID = model.SALESGROUPID;
|
|
db.RES_ALLOCATESTRATEGY.Add(model);
|
|
return db.SaveChanges().GetResult();
|
|
}
|
|
else
|
|
{
|
|
errors.Add("添加的分配策略名已存在!");
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
errors.Add(ex.Message);
|
|
return false;
|
|
}
|
|
}
|
|
|
|
public bool Update_AllocateStrategy(ref ValidationErrors errors, WX.CRM.Model.Entity.RES_ALLOCATESTRATEGY model)
|
|
{
|
|
try
|
|
{
|
|
using (var db = new crmContext())
|
|
{
|
|
RES_ALLOCATESTRATEGY entity = db.RES_ALLOCATESTRATEGY.FirstOrDefault(m => m.STRATEGYID == model.STRATEGYID);
|
|
if (entity != null)
|
|
{
|
|
entity.STRATEGYNAME = model.STRATEGYNAME;
|
|
entity.SALESGROUPID = model.SALESGROUPID;
|
|
entity.RECYCLEPROCEDURE = model.RECYCLEPROCEDURE;
|
|
entity.VIEWPROCEDURE = model.VIEWPROCEDURE;
|
|
entity.ALLCOTEPROCEDURE = model.ALLCOTEPROCEDURE;
|
|
entity.CHECKPROCEDURE = model.CHECKPROCEDURE;
|
|
entity.MEMO = model.MEMO;
|
|
db.SaveChanges();
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
errors.Add("待修改的分配策略数据不存在!");
|
|
return false;
|
|
}
|
|
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
errors.Add(ex.Message);
|
|
return false;
|
|
}
|
|
}
|
|
|
|
public bool Delete_AllocateStrategy(ref ValidationErrors errors, decimal id)
|
|
{
|
|
try
|
|
{
|
|
using (var db = new crmContext())
|
|
{
|
|
RES_ALLOCATESTRATEGY entity = db.RES_ALLOCATESTRATEGY.FirstOrDefault(m => m.STRATEGYID == id);
|
|
if (entity == null)
|
|
{
|
|
errors.Add("数据不存在!");
|
|
return false;
|
|
}
|
|
db.RES_ALLOCATESTRATEGY.Remove(entity);
|
|
return db.SaveChanges().GetResult();
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
errors.Add(ex.Message);
|
|
return false;
|
|
}
|
|
}
|
|
|
|
public RES_ALLOCATESTRATEGY GetModel_AllocateStrategy(decimal id)
|
|
{
|
|
using (var db = new crmContext())
|
|
{
|
|
return db.RES_ALLOCATESTRATEGY.FirstOrDefault(m => m.STRATEGYID == id);
|
|
}
|
|
}
|
|
|
|
public List<RES_ALLOCATESTRATEGY> GetList()
|
|
{
|
|
using (var db = new crmContext())
|
|
{
|
|
return db.RES_ALLOCATESTRATEGY.ToList<RES_ALLOCATESTRATEGY>();
|
|
}
|
|
}
|
|
|
|
public List<RES_ALLOCATESTRATEGY> GetList_AllocateStrategy(ref Pager pg, string name, decimal salesgroupId, string checkProc, string allocateProc, string recyleProc, string viewProc, string stime, string etime)
|
|
{
|
|
using (var db = new crmContext())
|
|
{
|
|
IQueryable<RES_ALLOCATESTRATEGY> data = db.RES_ALLOCATESTRATEGY.AsQueryable<RES_ALLOCATESTRATEGY>();
|
|
if (!string.IsNullOrEmpty(name))
|
|
data = data.Where(m => m.STRATEGYNAME.Contains(name));
|
|
if (!string.IsNullOrEmpty(checkProc))
|
|
data = data.Where(m => m.CHECKPROCEDURE.Contains(checkProc));
|
|
if (!string.IsNullOrEmpty(allocateProc))
|
|
data = data.Where(m => m.ALLCOTEPROCEDURE.Contains(allocateProc));
|
|
if (!string.IsNullOrEmpty(recyleProc))
|
|
data = data.Where(m => m.RECYCLEPROCEDURE.Contains(recyleProc));
|
|
if (!string.IsNullOrEmpty(viewProc))
|
|
data = data.Where(m => m.VIEWPROCEDURE.Contains(viewProc));
|
|
if (salesgroupId > 0)
|
|
data = data.Where(m => m.SALESGROUPID == salesgroupId);
|
|
|
|
DateTime _stime;
|
|
DateTime _etime;
|
|
if (!string.IsNullOrEmpty(stime) && DateTime.TryParse(stime, out _stime))
|
|
data = data.Where(m => m.CTIME >= _stime);
|
|
if (!string.IsNullOrEmpty(etime) && DateTime.TryParse(etime, out _etime))
|
|
{
|
|
_etime = _etime.AddDays(1);
|
|
data = data.Where(m => m.CTIME < _etime);
|
|
}
|
|
|
|
if (pg.order == "desc")
|
|
{
|
|
switch (pg.sort)
|
|
{
|
|
case "STRATEGYNAME":
|
|
data = data.OrderByDescending(c => c.STRATEGYNAME);
|
|
break;
|
|
case "CTIME":
|
|
data = data.OrderByDescending(c => c.CTIME);
|
|
break;
|
|
default:
|
|
data = data.OrderByDescending(c => c.CTIME);
|
|
break;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
switch (pg.sort)
|
|
{
|
|
case "STRATEGYNAME":
|
|
data = data.OrderBy(c => c.STRATEGYNAME);
|
|
break;
|
|
case "CTIME":
|
|
data = data.OrderBy(c => c.CTIME);
|
|
break;
|
|
default:
|
|
data = data.OrderBy(c => c.CTIME); break;
|
|
}
|
|
}
|
|
PagerUtil.SetPager<RES_ALLOCATESTRATEGY>(ref data, ref pg);//分页
|
|
return data.ToList();
|
|
}
|
|
}
|
|
|
|
#region 我的分配资源查询
|
|
|
|
|
|
|
|
public List<AllocateResourceNotice> GetMyAllocateResList(ref Pager pg, string resid, decimal inneruserid, string resourcetag, decimal resourcetypeid, decimal isview, decimal isnew, DateTime? stime, DateTime? etime, string groupId, string pkids = null)
|
|
{
|
|
|
|
|
|
string cacheKey = "cache_GetMyAllocateResList";
|
|
if (CacheHelper.Exists(cacheKey))
|
|
return CacheHelper.Get<List<AllocateResourceNotice>>(cacheKey);
|
|
using (var db = new crmContext())
|
|
{
|
|
DataSet ds = new RES_ALLOCATE_DAL().GetMyAllocateResList(ref pg, resid, inneruserid, resourcetag, resourcetypeid, isview, isnew, stime, etime, groupId, pkids);
|
|
var list = ds.Tables[0].ToList<AllocateResourceNotice>();
|
|
|
|
CacheHelper.Set(cacheKey, list, DateTime.Now.AddSeconds(30), true);
|
|
//LogHelper.Info("load:30");
|
|
return list;
|
|
}
|
|
|
|
}
|
|
public List<MyAllocatedRes2> GetMyAllocateResList2(ref Pager pg, string resid, QueryUserComboDto querydto, string resourcetag, decimal resourcetypeid, decimal isview, decimal isnew, DateTime? stime, DateTime? etime, decimal? productId, decimal? subproductId, DateTime? stimeTH, DateTime? etimeTH, string pkids, string category, DateTime? stimeGD, DateTime? etimeGD, DateTime? stimeKT, DateTime? etimeKT, DateTime? stimeFP, DateTime? etimeFP, decimal? hasTH, decimal? hasGD, decimal? isFP, string extxml,string deptid, decimal? midproductid = null)
|
|
{
|
|
string groupId = querydto.groupIds;
|
|
List<decimal> ALLdeptIDS = new List<decimal>();
|
|
List<decimal> ALLgidS = new List<decimal>();
|
|
if (string.IsNullOrEmpty(querydto.groupIds) && !string.IsNullOrEmpty(querydto.deptId))
|
|
{
|
|
var depts = OperationUtil.ConvertToDecimal(querydto.deptId.Split(','));
|
|
|
|
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);
|
|
}
|
|
ALLdeptIDS.AddRange(ALLgidS);
|
|
groupId = string.Join(",", ALLdeptIDS);//所有的部门ID和销售组ID
|
|
}
|
|
|
|
if(string.IsNullOrWhiteSpace(deptid))
|
|
{
|
|
var deptList = cache_BL.GetList_BusinessLines().ToList();
|
|
deptid = string.Join(",", deptList.Select(x => x.BUSINESSID));
|
|
}
|
|
|
|
var ds = new RES_ALLOCATE_DAL().GetMyAllocateResList2(ref pg, resid, querydto.userId, resourcetag, resourcetypeid, isview, isnew, stime, etime, groupId, productId, subproductId, stimeTH, etimeTH, pkids, category, stimeGD, etimeGD, stimeKT, etimeKT, stimeFP, etimeFP, hasTH, hasGD, isFP, extxml, midproductid, deptid);
|
|
var list = ds.Tables[0].ToList<MyAllocatedRes2>();
|
|
var model = list.FirstOrDefault(p => p.PKID == 0);
|
|
pg.totalRows = Convert.ToInt32(model.rn);
|
|
list.Remove(model);
|
|
list = list.OrderByDescending(p => p.distime).OrderByDescending(p => p.PKID).ToList();
|
|
return list;
|
|
}
|
|
public List<MyAllocatedRes> GetMyZhenGuResList(ref Pager pg, string resid, decimal inneruserid, string resourcetag, decimal resourcetypeid, decimal isview, decimal isnew, DateTime? stime, DateTime? etime, string groupId, string pkids = null)
|
|
{
|
|
DataSet ds = new RES_ALLOCATE_DAL().GetMyZhenGuResList(ref pg, resid, inneruserid, resourcetag, resourcetypeid, isview, isnew, stime, etime, groupId, pkids);
|
|
List<MyAllocatedRes> list = ds.Tables[0].ToList<MyAllocatedRes>();
|
|
MyAllocatedRes model = list.FirstOrDefault(p => p.PKID == 0);
|
|
pg.totalRows = Convert.ToInt32(model.rn);
|
|
list.Remove(model);
|
|
return list;
|
|
}
|
|
#endregion
|
|
|
|
|
|
/// <summary>
|
|
/// 获取分配资源的手机号码
|
|
/// </summary>
|
|
/// <param name="DISTRIBUTEID">资源分配ID</param>
|
|
/// <returns></returns>
|
|
public List<string> GetFBMobile(ref Pager pg, string resid, decimal inneruserid, string resourcetag, decimal resourcetypeid, decimal isview, decimal isnew, DateTime? stime, DateTime? etime, string groupId)
|
|
{
|
|
using (var db = new WX.CRM.Model.Entity.crmContext())
|
|
{
|
|
WX.CRM.IBLL.Util.ISecurityHelper sHelper = new SecurityHelper();
|
|
string clientid = Utility.GetSettingByKey("CRMClientKey");
|
|
DataTable data = new RES_ALLOCATE_DAL().GetMyAllocateResList(ref pg, resid, inneruserid, resourcetag, resourcetypeid, isview, isnew, stime, etime, groupId, null).Tables[0];
|
|
List<string> phoneList = new List<string>();
|
|
foreach (DataRow item in data.Rows)
|
|
{
|
|
string phone = item["mobile"].ToString();
|
|
|
|
if (!string.IsNullOrEmpty(phone))
|
|
{
|
|
phone = sHelper.decyptData(clientid, item["mobile"].ToString());
|
|
phoneList.Add(phone);
|
|
}
|
|
|
|
else
|
|
continue;
|
|
//if (item["resid"] != null)
|
|
//{
|
|
// phoneList.Add(item["resid"].ToString());
|
|
//}
|
|
//LogHelper.Info(item["mobile"].ToString() + "====" + phone+"===");
|
|
}
|
|
return phoneList;
|
|
}
|
|
}
|
|
|
|
public void ViewMyRes(string customerid, decimal inneruserid)
|
|
{
|
|
new RES_ALLOCATE_DAL().ViewMyRes(customerid, inneruserid);
|
|
}
|
|
}
|
|
}
|