284 lines
15 KiB
C#
284 lines
15 KiB
C#
using Exceptionless.Models;
|
|
using Hg.Core.Entity.HgCrm;
|
|
using Hg.Core.Entity.Views.DNG8;
|
|
using Hg.Core.Entity.Views.DNZZ;
|
|
using Hg.Core.Entity.Views.HGBM;
|
|
using Hg.Core.Entity.Views.PTD2;
|
|
using Hg.Core.Entity.Views.SHZZ;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using OfficeOpenXml.FormulaParsing.LexicalAnalysis;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Net.Http.Headers;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using static Microsoft.EntityFrameworkCore.DbLoggerCategory;
|
|
|
|
namespace Hg.Internal.Domain
|
|
{
|
|
internal class CsvrCallRecordDomain : ICsvrCallRecordDomain
|
|
{
|
|
private readonly IBaseRepository<HgCrmInternalDbContext> _hgCrmRepository;
|
|
private readonly IServiceProvider _serviceProvider;
|
|
private readonly IHttpClient _httpClient;
|
|
private readonly IMapper _mapper;
|
|
private readonly IConfiguration _configuration;
|
|
private readonly IRedisManager _redisManager;
|
|
private readonly SystemConfig _systemConfig;
|
|
|
|
public CsvrCallRecordDomain(IConfiguration configuration,
|
|
IServiceProvider serviceProvider,
|
|
IBaseRepository<HgCrmInternalDbContext> hgCrmRepository,
|
|
IHttpClient httpClient,
|
|
IMapper mapper,
|
|
IRedisManager redisManager
|
|
)
|
|
{
|
|
_systemConfig = configuration.GetSection("SystemConfig").Get<SystemConfig>();
|
|
_serviceProvider = serviceProvider;
|
|
_configuration = configuration;
|
|
_hgCrmRepository = hgCrmRepository;
|
|
_httpClient = httpClient;
|
|
_mapper = mapper;
|
|
_redisManager = redisManager;
|
|
}
|
|
|
|
public async Task<dynamic> CsvrCallRecordPage(CsvrCallRecordSearchPageDto search)
|
|
{
|
|
var query = CreateQuery<CsvrCallrecordHGBM, BasInneruserHGBM, CacheOrdMemoHGBM, OrdMemoContentHGBM, RES_CUSTOMER_HGBM>();
|
|
|
|
|
|
if (string.IsNullOrEmpty(search.CompanyCode))
|
|
{
|
|
var queryDNBB = CreateQuery<CsvrCallrecordDNBB, BasInneruserDNBB, CacheOrdMemoDNBB, OrdMemoContentDNBB, RES_CUSTOMER_DNBB>();
|
|
var queryDNG8 = CreateQuery<CsvrCallrecordDNG8, BasInneruserDNG8, CacheOrdMemoDNG8, OrdMemoContentDNG8, RES_CUSTOMER_DNG8>();
|
|
var queryDNYY = CreateQuery<CsvrCallrecordDNYY, BasInneruserDNYY, CacheOrdMemoDNYY, OrdMemoContentDNYY, RES_CUSTOMER_DNYY>();
|
|
var queryDNZZ = CreateQuery<CsvrCallrecordDNZZ, BasInneruserDNZZ, CacheOrdMemoDNZZ, OrdMemoContentDNZZ, RES_CUSTOMER_DNZZ>();
|
|
var queryPTD2 = CreateQuery<CsvrCallrecordPTD2, BasInneruserPTD2, CacheOrdMemoPTD2, OrdMemoContentPTD2, RES_CUSTOMER_PTD2>();
|
|
var querySHZZ = CreateQuery<CsvrCallrecordSHZZ, BasInneruserSHZZ, CacheOrdMemoSHZZ, OrdMemoContentSHZZ, RES_CUSTOMER_SHZZ>();
|
|
var queryQBJZ = CreateQuery<CsvrCallrecordQBJZ, BasInneruserQBJZ, CacheOrdMemoQBJZ, OrdMemoContentQBJZ, RES_CUSTOMER_QBJZ>();
|
|
var queryQBJX = CreateQuery<CsvrCallrecordQBJX, BasInneruserQBJX, CacheOrdMemoQBJX, OrdMemoContentQBJX, RES_CUSTOMER_QBJX>();
|
|
|
|
query = query.Concat(queryDNBB)
|
|
.Concat(queryDNG8)
|
|
.Concat(queryDNYY)
|
|
.Concat(queryDNZZ)
|
|
.Concat(queryPTD2)
|
|
.Concat(querySHZZ)
|
|
.Concat(queryQBJZ)
|
|
.Concat(queryQBJX);
|
|
}
|
|
else
|
|
{
|
|
query = search.CompanyCode == CompanyList.DNBB.GetDescription() ? CreateQuery<CsvrCallrecordDNBB, BasInneruserDNBB, CacheOrdMemoDNBB, OrdMemoContentDNBB,RES_CUSTOMER_DNBB > ()
|
|
: search.CompanyCode == CompanyList.DNG8.GetDescription() ? CreateQuery<CsvrCallrecordDNG8, BasInneruserDNG8, CacheOrdMemoDNG8, OrdMemoContentDNG8, RES_CUSTOMER_DNG8>()
|
|
: search.CompanyCode == CompanyList.DNYY.GetDescription() ? CreateQuery<CsvrCallrecordDNYY, BasInneruserDNYY, CacheOrdMemoDNYY, OrdMemoContentDNYY, RES_CUSTOMER_DNYY>()
|
|
: search.CompanyCode == CompanyList.DNZZ.GetDescription() ? CreateQuery<CsvrCallrecordDNZZ, BasInneruserDNZZ, CacheOrdMemoDNZZ, OrdMemoContentDNZZ, RES_CUSTOMER_DNZZ>()
|
|
: search.CompanyCode == CompanyList.PTD2.GetDescription() ? CreateQuery<CsvrCallrecordPTD2, BasInneruserPTD2, CacheOrdMemoPTD2, OrdMemoContentPTD2, RES_CUSTOMER_PTD2>()
|
|
: search.CompanyCode == CompanyList.SHZZ.GetDescription() ? CreateQuery<CsvrCallrecordSHZZ, BasInneruserSHZZ, CacheOrdMemoSHZZ, OrdMemoContentSHZZ, RES_CUSTOMER_SHZZ>()
|
|
: search.CompanyCode == CompanyList.QBJZ.GetDescription() ? CreateQuery<CsvrCallrecordQBJZ, BasInneruserQBJZ, CacheOrdMemoQBJZ, OrdMemoContentQBJZ, RES_CUSTOMER_QBJZ>()
|
|
: search.CompanyCode == CompanyList.QBJX.GetDescription() ? CreateQuery<CsvrCallrecordQBJX, BasInneruserQBJX, CacheOrdMemoQBJX, OrdMemoContentQBJX, RES_CUSTOMER_QBJX>()
|
|
: CreateQuery<CsvrCallrecordHGBM, BasInneruserHGBM, CacheOrdMemoHGBM, OrdMemoContentHGBM, RES_CUSTOMER_HGBM>();
|
|
|
|
}
|
|
|
|
query = query
|
|
.If(search.RecordId != null, x => x.Where(x => x.Id == search.RecordId))
|
|
.If(search.Eid != null && int.TryParse(search.Eid, out int eid), x => x.Where(x => x.Eid == int.Parse(search.Eid)))
|
|
.If(search.Eid != null && !int.TryParse(search.Eid, out int eid2), x => x.Where(x => x.Uname.Contains(search.Eid)))
|
|
.If(!string.IsNullOrEmpty(search.Resid), x => x.Where(x => x.Resid == search.Resid))
|
|
.If(!string.IsNullOrEmpty(search.UMID), x => x.Where(x => x.UmId == search.UMID))
|
|
.If(search.IsListened == IsListenType.未听, x => x.Where(x => x.ISCHECKED == (int)search.IsListened))
|
|
.If(search.IsListened == IsListenType.已听, x => x.Where(x => x.ISCHECKED == (int)search.IsListened))
|
|
.If(search.CallType.HasValue, x => x.Where(x => x.CallType == (int)search.CallType))
|
|
.If(!string.IsNullOrEmpty(search.CompanyCode), x => x.Where(x => x.CompanyCode == search.CompanyCode))
|
|
.If(search.LengthFrom != null, x => x.Where(x => x.TimeLength >= search.LengthFrom))
|
|
.If(search.LengthTo != null, x => x.Where(x => x.TimeLength <= search.LengthTo))
|
|
.If(search.TimeFrom != null, x => x.Where(x => x.Ctime >= search.TimeFrom))
|
|
.If(search.TimeTo != null, x => x.Where(x => x.Ctime <= search.TimeTo.Value.AddDays(1).AddMilliseconds(-1)))
|
|
.OrderByDescending(x => x.Ctime);
|
|
|
|
var total = await query.CountAsync();
|
|
|
|
if (search.Export.GetValueOrDefault())
|
|
{
|
|
// todo 导出逻辑
|
|
var end = DateTime.Now.AddMonths(-1);
|
|
if (total > 10000)
|
|
{
|
|
throw new ApiException("最多只能导出10000条录音数据");
|
|
}
|
|
var exportData = await query.ToListAsync();
|
|
exportData = InitCsvrCallRecord(exportData);
|
|
var folder = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "tmp");
|
|
if (!Directory.Exists(folder))
|
|
{
|
|
Directory.CreateDirectory(folder);
|
|
}
|
|
|
|
var fileName = $"人工录音列表 {DateTimeOffset.Now.ToUnixTimeMilliseconds()}.xlsx";
|
|
var fullName = Path.Combine(folder, fileName);
|
|
ExcelHelper.Export(fullName, exportData);
|
|
var tokenResult = await _httpClient.GetAsync(_systemConfig.GetFileServerToken());
|
|
|
|
var headers = new Dictionary<string, string>
|
|
{
|
|
{ "Authorization", $"Bearer {tokenResult}" }
|
|
};
|
|
|
|
var result = await _httpClient.UploadFileAsync<UploadFileResult>(_systemConfig.UploadFileServer(), fileName, fullName, headers);
|
|
|
|
if (result.Success)
|
|
{
|
|
return ApiResult.Succeed(result.Url);
|
|
}
|
|
}
|
|
|
|
var data = await query
|
|
.Skip((search.PageIndex - 1) * search.PageSize)
|
|
.Take(search.PageSize)
|
|
.ToListAsync();
|
|
|
|
data = InitCsvrCallRecord(data);
|
|
|
|
return new PageResult<CsvrCallRecordDto>(search.PageIndex, search.PageSize, total, data);
|
|
}
|
|
|
|
private static List<CsvrCallRecordDto> InitCsvrCallRecord(List<CsvrCallRecordDto> data)
|
|
{
|
|
data.ForEach(x =>
|
|
{
|
|
x.FileName = x.VideoUrl + x.FileName;
|
|
var strIsTran = "";
|
|
if (x.IsTran.ToString() == "1")
|
|
{
|
|
strIsTran = "(转接)";
|
|
}
|
|
if (x.CallType.ToString() == "1")//呼出
|
|
{
|
|
x.Type = "呼出" + strIsTran;
|
|
x.ServiceNumber = x.ServiceNumber;//主叫
|
|
x.TelNumberLast4 = x.TelNumberLast4;//被叫
|
|
}
|
|
else
|
|
{
|
|
x.Type = "呼入" + strIsTran;
|
|
x.ServiceNumber = x.TelNumberLast4;//被叫
|
|
x.TelNumberLast4 = x.ServiceNumber;//主叫
|
|
}
|
|
});
|
|
return data;
|
|
}
|
|
|
|
private IQueryable<CsvrCallRecordDto> CreateQuery<TCsvrCallrecord, TBasInneruser, TCacheOrdMemo, TOrdMemoContent, TResCustomer>()
|
|
where TCsvrCallrecord : CsvrCallrecord
|
|
where TBasInneruser : BAS_INNERUSER
|
|
where TCacheOrdMemo : CacheOrdMemo
|
|
where TOrdMemoContent : OrdMemoContent
|
|
where TResCustomer:RES_CUSTOMER
|
|
{
|
|
var videoUrl = "";
|
|
var deptName = "";
|
|
var companyCode = "";
|
|
if (typeof(TCsvrCallrecord) == typeof(CsvrCallrecordHGBM))
|
|
{
|
|
videoUrl = _systemConfig.GetCompanyVideoUrl(CompanyList.HGBM);
|
|
deptName = _systemConfig.GetCompanyName(CompanyList.HGBM);
|
|
companyCode = _systemConfig.GetCompanyCode(CompanyList.HGBM);
|
|
}
|
|
else if (typeof(TCsvrCallrecord) == typeof(CsvrCallrecordDNBB))
|
|
{
|
|
videoUrl = _systemConfig.GetCompanyVideoUrl(CompanyList.DNBB);
|
|
deptName = _systemConfig.GetCompanyName(CompanyList.DNBB);
|
|
companyCode = _systemConfig.GetCompanyCode(CompanyList.DNBB);
|
|
}
|
|
else if (typeof(TCsvrCallrecord) == typeof(CsvrCallrecordDNG8))
|
|
{
|
|
videoUrl = _systemConfig.GetCompanyVideoUrl(CompanyList.DNG8);
|
|
deptName = _systemConfig.GetCompanyName(CompanyList.DNG8);
|
|
companyCode = _systemConfig.GetCompanyCode(CompanyList.DNG8);
|
|
}
|
|
else if (typeof(TCsvrCallrecord) == typeof(CsvrCallrecordDNYY))
|
|
{
|
|
videoUrl = _systemConfig.GetCompanyVideoUrl(CompanyList.DNYY);
|
|
deptName = _systemConfig.GetCompanyName(CompanyList.DNYY);
|
|
companyCode = _systemConfig.GetCompanyCode(CompanyList.DNYY);
|
|
}
|
|
else if (typeof(TCsvrCallrecord) == typeof(CsvrCallrecordDNZZ))
|
|
{
|
|
videoUrl = _systemConfig.GetCompanyVideoUrl(CompanyList.DNZZ);
|
|
deptName = _systemConfig.GetCompanyName(CompanyList.DNZZ);
|
|
companyCode = _systemConfig.GetCompanyCode(CompanyList.DNZZ);
|
|
}
|
|
else if (typeof(TCsvrCallrecord) == typeof(CsvrCallrecordPTD2))
|
|
{
|
|
videoUrl = _systemConfig.GetCompanyVideoUrl(CompanyList.PTD2);
|
|
deptName = _systemConfig.GetCompanyName(CompanyList.PTD2);
|
|
companyCode = _systemConfig.GetCompanyCode(CompanyList.PTD2);
|
|
}
|
|
else if (typeof(TCsvrCallrecord) == typeof(CsvrCallrecordSHZZ))
|
|
{
|
|
videoUrl = _systemConfig.GetCompanyVideoUrl(CompanyList.SHZZ);
|
|
deptName = _systemConfig.GetCompanyName(CompanyList.SHZZ);
|
|
companyCode = _systemConfig.GetCompanyCode(CompanyList.SHZZ);
|
|
}
|
|
else if (typeof(TCsvrCallrecord) == typeof(CsvrCallrecordQBJZ))
|
|
{
|
|
videoUrl = _systemConfig.GetCompanyVideoUrl(CompanyList.QBJZ);
|
|
deptName = _systemConfig.GetCompanyName(CompanyList.QBJZ);
|
|
companyCode = _systemConfig.GetCompanyCode(CompanyList.QBJZ);
|
|
}
|
|
else if (typeof(TCsvrCallrecord) == typeof(CsvrCallrecordQBJX))
|
|
{
|
|
videoUrl = _systemConfig.GetCompanyVideoUrl(CompanyList.QBJX);
|
|
deptName = _systemConfig.GetCompanyName(CompanyList.QBJX);
|
|
companyCode = _systemConfig.GetCompanyCode(CompanyList.QBJX);
|
|
}
|
|
var query = from x in _hgCrmRepository.GetRepository<TCsvrCallrecord>().Query()
|
|
join y in _hgCrmRepository.GetRepository<TBasInneruser>().Query() on x.SALESEID equals y.EID into xy
|
|
from y in xy.DefaultIfEmpty()
|
|
join b in _hgCrmRepository.GetRepository <TCacheOrdMemo>().Query() on x.COID equals b.COID into xb
|
|
from b in xb.DefaultIfEmpty()
|
|
join c in _hgCrmRepository.GetRepository<TOrdMemoContent>().Query() on b.MEMOCONTENTID equals c.CONTENTID into xc
|
|
from c in xc.DefaultIfEmpty()
|
|
join u in _hgCrmRepository.GetRepository<TResCustomer>().Query() on x.RESID equals u.RESID into um
|
|
from u in um.DefaultIfEmpty()
|
|
select new CsvrCallRecordDto
|
|
{
|
|
Id = x.PKID,
|
|
RecordId = x.RECORDID,
|
|
Resid = x.RESID,
|
|
UmId= u.UMID,
|
|
TimeLength = x.TIMELENGTH,
|
|
TimeStart = x.TIMESTART,
|
|
TimeEnd = x.TIMEEND,
|
|
TelNumberLast4 = x.TELNUMBERLAST4,
|
|
IsTran = x.ISTRAN,
|
|
ServiceNumber = x.SERVICENUMBER,
|
|
CallType = x.CALLTYPE,
|
|
Uname = y.UNAME,
|
|
Eid = y.EID,
|
|
VideoUrl = videoUrl,
|
|
FileName = x.FILENAME,
|
|
Ctime = x.CTIME,
|
|
ISCHECKED = x.ISCHECKED,
|
|
DeptName = deptName,
|
|
CompanyCode = companyCode,
|
|
MemoContent = c.STRCONTENT
|
|
};
|
|
|
|
return query;
|
|
}
|
|
|
|
public async Task<List<Company>> GetCompanyList()
|
|
{
|
|
return await Task.Run(() =>
|
|
{
|
|
return _systemConfig.CompanyList;
|
|
});
|
|
}
|
|
}
|
|
}
|