177 lines
6.3 KiB
C#
177 lines
6.3 KiB
C#
using CRM.Core.BLL.Util;
|
|
using CRM.Core.BLL.Wx;
|
|
using CRM.Core.Common.Layui;
|
|
using CRM.Core.Model.Entity;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace CRM.Core.BLL.BlackNumber
|
|
{
|
|
public class BlackNumber_BL : DbContextRepository<CSVR_BLACKNUMBER>
|
|
{
|
|
public List<CSVR_BLACKNUMBER_View> GetList(ref Laypage pager, OrderQueryDto dto)
|
|
{
|
|
//读取配置
|
|
CACHE_BL cache_BL = new CACHE_BL();
|
|
|
|
|
|
var config = cache_BL.GetAICallTaskConfigList().FirstOrDefault();
|
|
var recall = config.ReCallMins.Count() > 0 ? true : false;
|
|
using (var db = new zxdContext())
|
|
{
|
|
#region UMID转RESID
|
|
if (!string.IsNullOrEmpty(dto.UMID) && string.IsNullOrEmpty(dto.resId))
|
|
{
|
|
var UMIDMain = db.RES_CUSTOMER.AsQueryable().FirstOrDefault(m => m.UMID == dto.UMID);
|
|
if (UMIDMain != null)
|
|
{
|
|
dto.resId = UMIDMain.RESID;
|
|
}
|
|
else {
|
|
dto.resId = "NULL_RESID";
|
|
}
|
|
}
|
|
#endregion
|
|
var queryData = db.CSVR_BLACKNUMBER.AsQueryable();
|
|
if (!string.IsNullOrWhiteSpace(dto.resId))
|
|
{
|
|
queryData = queryData.Where(m => m.RESID == dto.resId);
|
|
}
|
|
|
|
if (!string.IsNullOrWhiteSpace(dto.reason))
|
|
{
|
|
queryData = queryData.Where(m => m.REASON.Contains(dto.reason));
|
|
}
|
|
|
|
var queryList = queryData;
|
|
queryList = queryList.OrderByDescending(m => m.CTIME);
|
|
|
|
PagerUtil.SetPager(ref queryList, ref pager);
|
|
|
|
var list = queryList.ToList();
|
|
var resIds = list.Select(o => o.RESID).Distinct().ToList();
|
|
var cnames = db.WX_SZZYORDER.AsQueryable().Where(w => (w.ORDERSTATUS == "220" || w.ORDERSTATUS == "80") && resIds.Contains(w.RESID)).GroupBy(g => g.RESID).ToList();
|
|
var cur = db.RES_CUSTOMER.AsQueryable().Where(m => resIds.Contains(m.RESID)).ToList();
|
|
//var list = queryData.ToList();
|
|
var data = new List<CSVR_BLACKNUMBER_View>();
|
|
foreach(var item in list)
|
|
{
|
|
var cname = default(string);
|
|
var group = cnames.Where(w => w.Key==item.RESID).FirstOrDefault();
|
|
if (group != null)
|
|
{
|
|
cname = group.OrderByDescending(g => g.CTIME).FirstOrDefault().CNAME;
|
|
}
|
|
CSVR_BLACKNUMBER_View newModel = new CSVR_BLACKNUMBER_View
|
|
{
|
|
PKID = item.PKID,
|
|
RESID = item.RESID,
|
|
REASON = item.REASON,
|
|
CTIME = item.CTIME,
|
|
BlackTypeName = "禁止下单",
|
|
ChannelName = item.ChannelName,
|
|
CREATEUSERNAME = item.CREATEUSERNAME,
|
|
CName = cname,
|
|
UMID = cur.FirstOrDefault(m => m.RESID == item.RESID)?.UMID
|
|
};
|
|
data.Add(newModel);
|
|
}
|
|
return data;
|
|
}
|
|
}
|
|
|
|
public List<string> ChangeToResids(List<string> umids)
|
|
{
|
|
using (var db = new zxdContext())
|
|
{
|
|
var resids = db.RES_CUSTOMER.AsQueryable().Where(m => umids.Contains(m.UMID)).Select(x => x.RESID).ToList();
|
|
return resids;
|
|
}
|
|
}
|
|
|
|
public List<string> ChangeToumids(List<string> resids)
|
|
{
|
|
using (var db = new zxdContext())
|
|
{
|
|
var umids = db.RES_CUSTOMER.AsQueryable().Where(m => resids.Contains(m.RESID)).Select(x => x.UMID).ToList();
|
|
return umids;
|
|
}
|
|
}
|
|
|
|
public CSVR_BLACKNUMBER GetByResId(string resId, string blackType)
|
|
{
|
|
using (var db = new zxdContext())
|
|
{
|
|
return db.CSVR_BLACKNUMBER.FirstOrDefault(m => m.BLACKTYPE == blackType && resId == m.RESID);
|
|
}
|
|
}
|
|
public List<CSVR_BLACKNUMBER> GetByResIds(string[] resId, string blackType)
|
|
{
|
|
using (var db = new zxdContext())
|
|
{
|
|
return db.CSVR_BLACKNUMBER.Where(m => m.BLACKTYPE == blackType).Where(p => resId.Contains(p.RESID)).ToList();
|
|
}
|
|
}
|
|
public bool RemoveEntity(decimal id)
|
|
{
|
|
using (var db = new zxdContext())
|
|
{
|
|
var model = db.CSVR_BLACKNUMBER.FirstOrDefault(n => n.PKID == id);
|
|
if (model == null)
|
|
{
|
|
throw new Exception("找不到对应的实体");
|
|
}
|
|
db.CSVR_BLACKNUMBER.Remove(model);
|
|
db.SaveChanges();
|
|
return true;
|
|
}
|
|
}
|
|
public bool CreateEntities(List<CSVR_BLACKNUMBER> entities)
|
|
{
|
|
try
|
|
{
|
|
using (var db = new zxdContext())
|
|
{
|
|
//批量报错
|
|
|
|
db.CSVR_BLACKNUMBER.AddRange(entities);
|
|
|
|
bool result = db.SaveChanges().GetResult(); ;
|
|
return result;
|
|
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
//errors.Add(ex.Message);
|
|
throw ex;
|
|
}
|
|
}
|
|
public CSVR_BLACKNUMBER GetCSVR_BLACKNUMBER(decimal id)
|
|
{
|
|
using (var db = new zxdContext())
|
|
{
|
|
var model = db.CSVR_BLACKNUMBER.FirstOrDefault(n => n.PKID == id);
|
|
if (model == null)
|
|
{
|
|
throw new Exception("找不到对应的实体");
|
|
}
|
|
return model;
|
|
}
|
|
}
|
|
}
|
|
public class CSVR_BLACKNUMBER_View: CSVR_BLACKNUMBER
|
|
{
|
|
public string UMID { get; set; }
|
|
public string BlackTypeName { get; set; }
|
|
public string DeptName { get; set; }
|
|
|
|
/// <summary>
|
|
/// 客户姓名
|
|
/// </summary>
|
|
public string CName { get; set; }
|
|
}
|
|
} |