ComplianceServer/code/Hg.Core.Domain/InComplaintDomain.cs

900 lines
43 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using DG.Core;
using Hg.Core.Domain.Dto.InComplaint;
using Hg.Core.Domain.Dto.OrderRefund;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Hg.Core.Domain
{
internal class InComplaintDomain : IInComplaintDomain
{
private readonly IBaseRepository<ZxdDbContext> _zxdRepository;
private readonly IRedisManager _redisManager;
private readonly IConfiguration _configuration;
private readonly IHttpClient _httpClient;
private readonly IMapper _mapper;
private readonly SystemConfig _systemConfig;
private readonly IInneruserDomain _inneruserDomain;
private readonly ICacheDomain _cacheDomain;
public InComplaintDomain(IBaseRepository<ZxdDbContext> zxdRepository,
IRedisManager redisManager,
IConfiguration configuration,
IMapper mapper,
IHttpClient httpClient,
IInneruserDomain inneruserDomain,
ICacheDomain cacheDomain)
{
_zxdRepository = zxdRepository;
_redisManager = redisManager;
_mapper = mapper;
_httpClient = httpClient;
_configuration = configuration;
_inneruserDomain = inneruserDomain;
_cacheDomain = cacheDomain;
_systemConfig = _configuration.GetSection("SystemConfig").Get<SystemConfig>();
}
public async Task<InComplaintDto> GetInComplaint(int id)
{
var query = from a in _zxdRepository.GetRepository<InComplaint>().Query()
select new InComplaintDto
{
Id = a.Id,
Deptid = a.Deptid,
DueStatus = a.DueStatus,
BusinessDeadline = a.BusinessDeadline,
InComplaintDate = a.InComplaintDate,
BusinessStatus = a.BusinessStatus,
Cname = a.Cname,
ComplaintId = a.ComplaintId,
Content = a.Content,
CreateTime = a.CreateTime,
Creator = a.Creator,
Eid = a.Eid,
Follow = a.Follow,
InComplaintChannel = a.InComplaintChannel,
InComplaintStatus = a.InComplaintStatus,
Reason = a.Reason,
Remark = a.Remark,
Resid = a.Resid,
Updater = a.Updater,
UpdateTime = a.UpdateTime,
RiskSituation = a.RiskSituation
};
var result = await query.FirstOrDefaultAsync(x => x.Id == id);
if (result == null) throw new ApiException("内诉数据不存在或已删除!");
return result;
}
public async Task<PageResult<InComplaintDto>> GetInComplaintPage(SearchInComplaintDto dto)
{
var eids = new List<int>();
if (!string.IsNullOrWhiteSpace(dto.Eids))
eids = dto.Eids.Split(",").Select(x => int.Parse(x)).ToList();
var deptList = await _cacheDomain.GetDeptments();
var departIds = new List<int>();
#region UMID转RESID
if (!string.IsNullOrEmpty(dto.UMID) && string.IsNullOrEmpty(dto.Resid))
{
var UMIDMain = _zxdRepository.GetRepository<RES_CUSTOMER>().Query().FirstOrDefault(m => dto.UMID == m.UMID);
if (UMIDMain != null)
{
dto.Resid = UMIDMain.RESID;
}
else
{
dto.Resid = "NULL_RESID";
}
}
#endregion
if (!string.IsNullOrWhiteSpace(dto.Channel))
{
var arr0 = dto.Channel.Split('|');
foreach (var item0 in arr0)
{
var arr1 = item0.Split(',');
foreach (var item in arr1)
{
//var dept = deptList.Where(y => y.DeptmentCampains.Any(a => "2500-2900" == $"{a.StartCampainId}-{a.EndCampainId}" || "3000-3900" == $"{a.StartCampainId}-{a.EndCampainId}"));
var a = item.Split(';');
var min = Convert.ToInt32(a[0]);
var max = Convert.ToInt32(a[1]);
var ids = deptList.Where(x => x.DeptmentCampains.Any(y => y.StartCampainId >= min && y.EndCampainId <= max)).Select(x => x.Id).ToList();
departIds.AddRange(ids);
}
}
}
var showDeptIds = new List<int>();
if (!string.IsNullOrWhiteSpace(dto.ShowDeptIds))
showDeptIds = dto.ShowDeptIds.Split(',').Select(x => int.Parse(x)).ToList();
var query = from a in _zxdRepository.GetRepository<InComplaint>().Query()
//join b in _zxdRepository.GetRepository<InComplaintRestore>().Query() on a.ComplaintId equals b.ComplaintId into ab
//from b in ab.DefaultIfEmpty()
select new InComplaintDto
{
Id = a.Id,
Deptid = a.Deptid,
DueStatus = a.DueStatus,
BusinessDeadline = a.BusinessDeadline,
InComplaintDate = a.InComplaintDate,
BusinessStatus = a.BusinessStatus,
Cname = a.Cname,
ComplaintId = a.ComplaintId,
Content = a.Content,
CreateTime = a.CreateTime,
Creator = a.Creator,
Eid = a.Eid,
Follow = a.Follow,
InComplaintChannel = a.InComplaintChannel,
InComplaintStatus = a.InComplaintStatus,
Reason = a.Reason,
Remark = a.Remark,
Resid = a.Resid,
Updater = a.Updater,
UpdateTime = a.UpdateTime,
//Restorer = b.FirstCreator,
//RestoreTime = b.FirstCreateTime,
//RefundStatus = _zxdRepository.GetRepository<OrderRefundApply>().Query().OrderByDescending(x => x.CreateTime).FirstOrDefault(x => x.ComplaintId == a.ComplaintId).RefundStatus,
Restorer = _zxdRepository.GetRepository<InComplaintRestore>().Query().OrderByDescending(x => x.CreateTime).FirstOrDefault(x => x.ComplaintId == a.ComplaintId && x.RestoreType == RestoreType.).Creator,
RestoreTime = _zxdRepository.GetRepository<InComplaintRestore>().Query().OrderByDescending(x => x.CreateTime).FirstOrDefault(x => x.ComplaintId == a.ComplaintId && x.RestoreType == RestoreType.).CreateTime,
HGRestorer = _zxdRepository.GetRepository<InComplaintRestore>().Query().OrderByDescending(x => x.CreateTime).FirstOrDefault(x => x.ComplaintId == a.ComplaintId && x.RestoreType == RestoreType.).Creator,
HGRestoreTime = _zxdRepository.GetRepository<InComplaintRestore>().Query().OrderByDescending(x => x.CreateTime).FirstOrDefault(x => x.ComplaintId == a.ComplaintId && x.RestoreType == RestoreType.).CreateTime,
DueCount = a.DueCount,
IsAdjustDeadline = a.IsAdjustDeadline,
//OrderList = _zxdRepository.GetRepository<InComplaintOrder>().Query().Where(x => x.ComplaintId == a.ComplaintId).Select(x => x.Orderid).ToList(),
//PriceList = _zxdRepository.GetRepository<InComplaintOrder>().Query().Where(x => x.ComplaintId == a.ComplaintId).Select(x => x.Price).ToList(),
RestoreCount = _zxdRepository.GetRepository<InComplaintRestore>().Query().Count(x => x.ComplaintId == a.ComplaintId),
FollowUpCount = _zxdRepository.GetRepository<InComplaintFollowUp>().Query().Count(x => x.ComplaintId == a.ComplaintId),
NeedRestoreCount = _zxdRepository.GetRepository<InComplaintRestore>().Query().Count(x => x.ComplaintId == a.ComplaintId),
TimeSort = a.UpdateTime.HasValue && a.CreateTime < a.UpdateTime ? a.UpdateTime.Value : a.CreateTime,
IsOutComplaint = _zxdRepository.GetRepository<OutComplaint>().Query().Count(x => x.Resid == a.Resid) > 0 ? "是" : "否",
Verifyier = a.Verifyier,
VerifyTime = a.VerifyTime,
RiskSituation = a.RiskSituation
};
if (!string.IsNullOrWhiteSpace(dto.Eid))
{
query = from a in query
join b in _zxdRepository.GetRepository<BAS_INNERUSER>().Query() on a.Eid equals b.EID
where (a.Eid.ToString() == dto.Eid || b.UNAME == dto.Eid)
select a;
}
if (dto.Orderid.HasValue)
{
query = from a in query
join b in _zxdRepository.GetRepository<WX_SZZYORDER>().Query() on a.Resid equals b.RESID
join c in _zxdRepository.GetRepository<WX_SzzyOrderRefund>().Query() on b.ORDERID equals c.orderid
where c.orderid == dto.Orderid && c.isdelete == 0 && c.auditstatus == 1
select a;
}
if (dto.RefundStatus.HasValue)
{
if(dto.RefundStatus == OrderRefundStatus.退)
{
query = from a in query
join b in _zxdRepository.GetRepository<WX_SZZYORDER>().Query() on a.Resid equals b.RESID
join c in _zxdRepository.GetRepository<WX_SzzyOrderRefund>().Query() on b.ORDERID equals c.orderid
where c.orderid == 0
select a;
}
else if (dto.RefundStatus == OrderRefundStatus.退)
{
query = from a in query
join b in _zxdRepository.GetRepository<WX_SZZYORDER>().Query() on a.Resid equals b.RESID
join c in _zxdRepository.GetRepository<WX_SzzyOrderRefund>().Query() on b.ORDERID equals c.orderid
where c.orderid > 0
select a;
}
}
query = query.If(dto.Deptid != null, x => x.Where(x => x.Deptid == dto.Deptid))
.If(departIds.Any(), x => x.Where(x => x.Deptid.HasValue && departIds.Contains(x.Deptid.Value)))
.If(showDeptIds.Any(), x => x.Where(x => x.Deptid.HasValue && showDeptIds.Contains(x.Deptid.Value)))
.If(dto.DueStatus != null, x => x.Where(x => x.DueStatus == dto.DueStatus))
.If(dto.BusinessStatus != null, x => x.Where(x => x.BusinessStatus == dto.BusinessStatus))
.If(dto.InComplaintChannel != null, x => x.Where(x => ((int)dto.InComplaintChannel & x.InComplaintChannel) > 0))
.If(dto.InComplaintStatus != null, x => x.Where(x => x.InComplaintStatus == dto.InComplaintStatus))
//.If(dto.RefundStatus != null, x => x.Where(x => x.RefundStatus == dto.RefundStatus))
.If(dto.Reason != null, x => x.Where(x => ((int)dto.Reason & x.Reason.Value) > 0))
.If(eids.Any(), x => x.Where(x => eids.Contains(x.Eid.Value)))
.If(!string.IsNullOrEmpty(dto.Resid), x => x.Where(x => x.Resid == dto.Resid))
.If(!string.IsNullOrEmpty(dto.Cname), x => x.Where(x => x.Cname == dto.Cname))
.If(!string.IsNullOrEmpty(dto.ComplaintId), x => x.Where(x => x.ComplaintId == dto.ComplaintId))
.If(!string.IsNullOrEmpty(dto.CreaetOrUpdateUser) && dto.PersonType == PersonTypeEnum., x => x.Where(x => x.Creator == dto.CreaetOrUpdateUser))
.If(!string.IsNullOrEmpty(dto.CreaetOrUpdateUser) && dto.PersonType == PersonTypeEnum., x => x.Where(x => x.Updater == dto.CreaetOrUpdateUser))
.If(!string.IsNullOrEmpty(dto.CreaetOrUpdateUser) && dto.PersonType == PersonTypeEnum., x => x.Where(x => x.Verifyier == dto.CreaetOrUpdateUser))
.If(!string.IsNullOrEmpty(dto.CreaetOrUpdateUser) && dto.PersonType == PersonTypeEnum., x => x.Where(x => x.Restorer == dto.CreaetOrUpdateUser))
.If(!string.IsNullOrEmpty(dto.CreaetOrUpdateUser) && dto.PersonType == PersonTypeEnum., x => x.Where(x => x.HGRestorer == dto.CreaetOrUpdateUser))
//.If(dto.Orderid != null, x => x.Where(x => x.OrderList.Contains(dto.Orderid)))
.If(dto.DateType == InComplaintDateType. && dto.DateFrom != null, x => x.Where(x => x.InComplaintDate >= dto.DateFrom.Value))
.If(dto.DateType == InComplaintDateType. && dto.DateFrom != null, x => x.Where(x => x.RestoreTime >= dto.DateFrom.Value))
.If(dto.DateType == InComplaintDateType. && dto.DateFrom != null, x => x.Where(x => x.HGRestoreTime >= dto.DateFrom.Value))
.If(dto.DateType == InComplaintDateType. && dto.DateFrom != null, x => x.Where(x => x.CreateTime >= dto.DateFrom.Value))
.If(dto.DateType == InComplaintDateType. && dto.DateFrom != null, x => x.Where(x => x.UpdateTime >= dto.DateFrom.Value))
.If(dto.DateType == InComplaintDateType. && dto.DateFrom != null, x => x.Where(x => x.VerifyTime >= dto.DateFrom.Value))
.If(dto.DateType == InComplaintDateType. && dto.DateTo != null, x => x.Where(x => x.InComplaintDate <= dto.DateTo.Value.AddDays(1).AddSeconds(-1)))
.If(dto.DateType == InComplaintDateType. && dto.DateTo != null, x => x.Where(x => x.RestoreTime <= dto.DateTo.Value.AddDays(1).AddSeconds(-1)))
.If(dto.DateType == InComplaintDateType. && dto.DateTo != null, x => x.Where(x => x.HGRestoreTime <= dto.DateTo.Value.AddDays(1).AddSeconds(-1)))
.If(dto.DateType == InComplaintDateType. && dto.DateTo != null, x => x.Where(x => x.CreateTime <= dto.DateTo.Value.AddDays(1).AddSeconds(-1)))
.If(dto.DateType == InComplaintDateType. && dto.DateTo != null, x => x.Where(x => x.UpdateTime <= dto.DateTo.Value.AddDays(1).AddSeconds(-1)))
.If(dto.DateType == InComplaintDateType. && dto.DateTo != null, x => x.Where(x => x.VerifyTime <= dto.DateTo.Value.AddDays(1).AddSeconds(-1)))
.OrderByDescending(x => x.TimeSort);
var total = await query.CountAsync();
var data = await query
.Skip((dto.PageIndex - 1) * dto.PageSize)
.Take(dto.PageSize)
.ToListAsync();
var now = DateTime.Now;
if (data.Any())
{
var eidStr = string.Join(",", data.Where(x => x.Eid != null).Select(x => x.Eid).ToList());
var innerUsers = await _inneruserDomain.GetInnerusers(eidStr);
var orderStatus = new List<string> { "220", "205", "80", "90" };
var orders = await _zxdRepository.GetRepository<WX_SZZYORDER>().Query().Where(x => data.Select(x => x.Resid).Contains(x.RESID) && orderStatus.Contains(x.ORDERSTATUS)).OrderByDescending(x => x.OTIME).ToListAsync();
var resIds = data.Select(x => x.Resid);
var refundOrders = await (from a in _zxdRepository.GetRepository<WX_SzzyOrderRefund>().Query()
join b in _zxdRepository.GetRepository<WX_SZZYORDER>().Query() on a.orderid equals b.ORDERID
where resIds.Contains(b.RESID) && a.isdelete == 0 && a.auditstatus == 1
select new { a.refundprice, a.orderid, b.RESID }).ToListAsync();
var rcu = _zxdRepository.GetRepository<RES_CUSTOMER>().Query().Where(m => resIds.Contains(m.RESID)).ToList();
foreach (var item in data)
{
var company = deptList.FirstOrDefault(y => y.Id == item.Deptid);
var itemOrders = orders.Where(x => x.RESID == item.Resid);
if (item.Resid == "224284360094995449")//该客户测试单号过多
itemOrders = itemOrders.Take(4);
var idCard = itemOrders.FirstOrDefault(x => !string.IsNullOrWhiteSpace(x.idcard))?.idcard;
var minOTime = itemOrders.Min(x => x.OTIME);
item.Age = _cacheDomain.GetAge(idCard);
//item.OrderInfo = itemOrders.Select(x => $"产品:{x.SUBPRODUCTNAME} 订单号:{x.ORDERID} 开通时间:{x.OTIME} 到账金额:{x.ARRIVALPAY} 权限到期状态:{(now > x.ARRIVALTIME ? "到期" : "未到期")}").ToList();
item.Products = itemOrders.Select(x => x.SUBPRODUCTNAME).ToList();
item.OrderIds = itemOrders.Select(x => x.ORDERID).ToList();
item.OTimes = itemOrders.Select(x => x.OTIME).ToList();
item.ArrivalPays = itemOrders.Select(x => x.ARRIVALPAY).ToList();
item.ArrivalStatus = itemOrders.Select(x => (x.OTIME.HasValue && x.OPENDAYS.HasValue && now < x.OTIME.Value.AddDays(x.OPENDAYS.Value) ? "未到期" : "到期")).ToList();
item.ComplaintCycle = minOTime.HasValue ? item.InComplaintDate.Value.Subtract(minOTime.Value).Days : null;
item.Deptname = company?.Title;
item.BusinessDeadlineSpan = $"{await _cacheDomain.GetWorkHours(now, item.BusinessDeadline)}小时";
var innerUser = innerUsers.FirstOrDefault(x => x.EId == item.Eid);
item.Euser = item.Eid.HasValue && innerUser != null ? $"{item.Eid}-{innerUser?.Name}-{(innerUser?.Status == 2 ? "" : "")}" : item.Eid.ToString();
item.OrderList = refundOrders.Where(x => x.RESID == item.Resid).Select(x => x.orderid).ToList();
item.PriceList = refundOrders.Where(x => x.RESID == item.Resid).Select(x => x.refundprice).ToList();
item.RefundStatus = refundOrders.Where(x => x.RESID == item.Resid).Any() ? OrderRefundStatus.退 : OrderRefundStatus.退;
item.UMID = rcu.FirstOrDefault(m => m.RESID == item.Resid)?.UMID;
};
}
return new PageResult<InComplaintDto>(dto.PageIndex, dto.PageSize, total, data);
}
public async Task<bool> CreateInComplaint(CreateInComplaintDto dto)
{
var date = DateTime.Now;
var complaintId = CreateInComplaintid();
var customer = await _zxdRepository.GetRepository<RES_CUSTOMER>().Query().FirstOrDefaultAsync(x => x.UMID == dto.Resid.Trim());
if (customer == null)
throw new Exception("客户ID不存在");
var order = await _zxdRepository.GetRepository<WX_SZZYORDER>().Query().OrderByDescending(x => x.CTIME)
.FirstOrDefaultAsync(x => x.RESID == customer.RESID && x.deptid == dto.Deptid);
var data = new InComplaint
{
Deptid = dto.Deptid,
DueStatus = InComplaintDueStatus.,
InComplaintDate = dto.InComplaintDate,
Cname = dto.Cname,
ComplaintId = complaintId,
BusinessDeadline = await _cacheDomain.AddWorkDays(date, 3),
BusinessStatus = InComplaintBusinessStatus.,
Content = dto.Content,
CreateTime = DateTime.Now,
Creator = dto.Operator,
Follow = dto.Follow,
InComplaintChannel = dto.InComplaintChannel,
Reason = dto.Reason,
InComplaintStatus = InComplaintStatus.,
Remark = dto.Remark,
//Resid = dto.Resid,
Resid = customer.RESID,
Eid = order?.eid,
CreateEid = dto.OperatorEid,
DueCount = 4,
IsAdjustDeadline = false,
VerifyEid = !string.IsNullOrWhiteSpace(dto.Remark) ? dto.OperatorEid : null,
Verifyier = !string.IsNullOrWhiteSpace(dto.Remark) ? dto.Operator : null,
VerifyTime = !string.IsNullOrWhiteSpace(dto.Remark) ? DateTime.Now : null,
RiskSituation = dto.RiskSituation
};
var InComplaintFollowUp = new InComplaintFollowUp
{
ComplaintId = complaintId,
Content = dto.Content,
CreateTime = DateTime.Now,
Creator = dto.Operator,
Follow = dto.Follow,
CreateEid = dto.OperatorEid
};
//var orders = await _zxdRepository.GetRepository<WX_SZZYORDER>().Query()
// .Where(x => x.RESID == dto.Resid)
// .Where(x => x.ORDERSTATUS == "90")
// .Select(x => new InComplaintOrder
// {
// Orderid = x.ORDERID,
// ComplaintId = complaintId,
// Price = x.NEEDPAY
// })
// .ToListAsync();
var transaction = await _zxdRepository.BeginTransactionAsync();
try
{
await _zxdRepository.GetRepository<InComplaint>().InsertAsync(data);
await _zxdRepository.GetRepository<InComplaintFollowUp>().InsertAsync(InComplaintFollowUp);
//发送消息
var sendMessage = new
{
Message = $"{dto.Operator}({dto.Resid})提交了内诉,投诉原因是:{dto.ReasonList}请在72小时内及时处理好。",
Eid = order?.eid,
Deptid = dto.Deptid,
Method = "ComplaintMessage",
IsDepartment = true,
};
//await _cacheDomain.SendCrmMessage(sendMessage);
//创建客户标签
await _cacheDomain.ComplaintLabel(dto.Resid, dto.Cname, order?.companycode, "内诉");
await transaction.CommitAsync();
return true;
}
catch
{
await transaction.RollbackAsync();
await transaction.DisposeAsync();
throw;
}
}
/// <summary>
/// 更新内诉记录
/// </summary>
/// <param name="dto"></param>
/// <returns></returns>
/// <exception cref="ApiException"></exception>
public async Task<bool> UpdateInComplaint(UpdateInComplaintDto dto)
{
var data = await _zxdRepository.GetRepository<InComplaint>().Query().FirstOrDefaultAsync(x => x.Id == dto.Id);
if (data == null) throw new ApiException("内诉数据不存在或已删除!");
data.Content = dto.Content;
data.Follow = dto.Follow;
data.Updater = dto.Operator;
data.UpdateTime = DateTime.Now;
data.UpdateEid = dto.OperatorEid;
data.RiskSituation = dto.RiskSituation;
if (data.Remark != dto.Remark)
{
data.Remark = dto.Remark;
data.VerifyTime = DateTime.Now;
data.VerifyEid = dto.OperatorEid;
data.Verifyier = dto.Operator;
}
await _zxdRepository.GetRepository<InComplaint>().UpdateAsync(data, x => new { x.Content, x.Follow, x.Remark, x.UpdateTime, x.Updater, x.UpdateEid,x.RiskSituation,x.VerifyTime,x.Verifyier,x.VerifyEid });
return true;
}
private static string CreateInComplaintid()
{
//return $"NS{DateTimeOffset.Now.ToUnixTimeMilliseconds()}";
return $"NS{DateTime.Now.ToString("yyyyMMddHHmmssffff")}";
}
/// <summary>
/// 添加跟进记录
/// </summary>
/// <param name="dto"></param>
/// <returns></returns>
public async Task<bool> CreateInComlpaintFollowUp(CreateInComplaintFollowUpDto dto)
{
var data = await _zxdRepository.GetRepository<InComplaint>().Query().FirstOrDefaultAsync(x => x.Id == dto.Id);
if (data == null) throw new ApiException("内诉数据不存在或已删除!");
var InComplaintFollowUp = new InComplaintFollowUp
{
ComplaintId = data.ComplaintId,
Content = dto.Content,
CreateTime = DateTime.Now,
Creator = dto.Operator,
Follow = dto.Follow
};
data.Updater = dto.Operator;
data.UpdateEid = dto.OperatorEid;
data.UpdateTime = DateTime.Now;
var transaction = await _zxdRepository.BeginTransactionAsync();
try
{
await _zxdRepository.GetRepository<InComplaint>().UpdateAsync(data, x => new { x.Updater, x.UpdateEid, x.UpdateTime });
await _zxdRepository.GetRepository<InComplaintFollowUp>().InsertAsync(InComplaintFollowUp);
await transaction.CommitAsync();
return true;
}
catch (Exception ex)
{
await transaction.RollbackAsync();
await transaction.DisposeAsync();
throw;
}
}
public async Task<bool> UpdateInComlpaintFollowUp(CreateInComplaintFollowUpDto dto)
{
var complaintFollowUp = await _zxdRepository.GetRepository<InComplaintFollowUp>().Query().FirstOrDefaultAsync(x => x.Id == dto.Id);
if (complaintFollowUp == null)
throw new ApiException("跟进数据不存在或已删除!");
complaintFollowUp.Content = dto.Content;
complaintFollowUp.Follow = dto.Follow;
complaintFollowUp.UpdateEid = dto.OperatorEid;
complaintFollowUp.Updater = dto.Operator;
complaintFollowUp.UpdateTime = DateTime.Now;
await _zxdRepository.GetRepository<InComplaintFollowUp>().UpdateAsync(complaintFollowUp);
return true;
}
/// <summary>
/// 获取用户信息
/// </summary>
/// <param name="resid"></param>
/// <returns></returns>
public async Task<ComplaintCustomerInfoDto> GetComplaintCustomerInfo(string? resid)
{
//var orderList = await _zxdRepository.GetRepository<WX_SZZYORDER>().Query()
// .Where(x => x.RESID == resid)
// .Where(x => x.ORDERSTATUS == "220").ToListAsync();
//var customerInfo = orderList.GroupBy(x => new { x.RESID, x.CNAME, x.eid })
// .Select(x => new ComplaintCustomerInfoDto
// {
// Resid = x.Key.RESID,
// Cname = x.Key.CNAME,
// Eid = x.Key.eid,
// DeptInfos = orderList.GroupBy(y => new { y.CHANNEL, y.companycode }).Select(y => new ComplaintCustomerDeptInfo
// {
// Channel = y.Key.CHANNEL,
// CompanyCode = y.Key.companycode
// }).ToList()
// }).FirstOrDefault();
//var customerInfo = await _zxdRepository.GetRepository<WX_SZZYORDER>().Query()
// .Where(x => x.RESID == resid)
// .Where(x => x.ORDERSTATUS == "220")
// .GroupBy(x => new
// {
// x.RESID,
// x.CNAME,
// x.eid,
// })
// .Select(x => new ComplaintCustomerInfoDto
// {
// Resid = x.Key.RESID,
// Cname = x.Key.CNAME,
// Eid = x.Key.eid,
// DeptInfos = x.Select(x => new ComplaintCustomerDeptInfo
// {
// Channel = x.CHANNEL,
// CompanyCode = x.companycode
// }).ToList()
// })
// .FirstOrDefaultAsync();
//var deptList = await _cacheDomain.GetDeptments();
//if (customerInfo != null && customerInfo.DeptInfos != null && customerInfo.DeptInfos.Any())
//{
// customerInfo.DeptInfos.ForEach(x =>
// {
// var dept = deptList.FirstOrDefault(y => y.DeptmentCampains.Any(a => x.Channel >= a.StartCampainId && x.Channel <= a.EndCampainId));
// x.Deptname = dept?.Title;
// x.Deptid = dept?.Id;
// });
//}
var customerInfo = new ComplaintCustomerInfoDto();
var orderStatus = new List<string> { "200", "220", "205", "80", "90" };
var customer = await _zxdRepository.GetRepository<RES_CUSTOMER>().Query().FirstOrDefaultAsync(x => x.UMID == resid);
if (customer == null)
return customerInfo;
var order = await _zxdRepository.GetRepository<WX_SZZYORDER>().Query().OrderByDescending(x => x.CTIME)
.FirstOrDefaultAsync(x => x.RESID == customer.RESID && orderStatus.Contains(x.ORDERSTATUS) && !string.IsNullOrWhiteSpace(x.CNAME));
if(order == null)
return customerInfo;
customerInfo.Resid = resid;
customerInfo.Eid = order.eid;
customerInfo.Cname = order.CNAME;
return customerInfo;
}
public async Task<InComplaintFollowUpDto> GetInComplaintFollowUp(int? id)
{
var query = from a in _zxdRepository.GetRepository<InComplaint>().Query()
where a.Id == id
select new InComplaintFollowUpDto
{
Id = a.Id,
Cname = a.Cname,
InComplaintStatus = a.InComplaintStatus,
ComplaintId = a.ComplaintId,
Resid = a.Resid
};
var data = await query.FirstOrDefaultAsync();
if (data == null) throw new ApiException("内诉数据不存在或已删除!");
data.Details = await _zxdRepository.GetRepository<InComplaintFollowUp>().Query()
.Where(x => x.ComplaintId == data.ComplaintId)
.Select(x => new InComplaintFollowUpDetailDto
{
Id = x.Id,
Content = x.Content,
CreateTime = x.CreateTime,
Creator = x.Creator,
Follow = x.Follow,
Updater = x.Updater,
UpdateTime = x.UpdateTime
}).ToListAsync();
var index = 1;
data.Details?.ForEach(x =>
{
x.Index = $"第{index}次投诉";
index++;
});
return data;
}
public async Task<bool> CreateInComplaintRestore(CreateInComplaintRestoreDto dto)
{
var data = await _zxdRepository.GetRepository<InComplaint>().Query().FirstOrDefaultAsync(x => x.Id == dto.Id);
if (data == null) throw new ApiException("内诉数据不存在或已删除!");
if (dto.RestoreType == RestoreType.)
{
data.BusinessStatus = dto.BusinessStatus;
}
else if(dto.RestoreType == RestoreType.)
{
data.Updater = dto.Creator;
data.UpdateEid = dto.CreatorEid;
data.UpdateTime = DateTime.Now;
}
var restore = new InComplaintRestore
{
ComplaintId = data.ComplaintId,
Content = dto.Content,
CreateTime = DateTime.Now,
Creator = dto.Creator,
CreatorEid = dto.CreatorEid,
Attachment = dto.Attachment,
RestoreType = dto.RestoreType
};
await _zxdRepository.GetRepository<InComplaintRestore>().InsertAsync(restore);
await _zxdRepository.GetRepository<InComplaint>().UpdateAsync(data, x => new { x.BusinessStatus, x.UpdateEid, x.Updater, x.UpdateTime });
return true;
}
public async Task<bool> UpdateInComplaintStatus(UpdateInComplaintStatusDto dto)
{
var data = await _zxdRepository.GetRepository<InComplaint>().Query().FirstOrDefaultAsync(x => x.Id == dto.Id);
if (data == null) throw new ApiException("内诉数据不存在或已删除!");
data.UpdateEid = dto.OperatorEid;
data.Updater = dto.Operator;
data.UpdateTime = DateTime.Now;
data.InComplaintStatus = dto.InComplaintStatus;
await _zxdRepository.GetRepository<InComplaint>().UpdateAsync(data, x => new
{
x.UpdateEid,
x.Updater,
x.InComplaintStatus,
x.UpdateTime,
x.BusinessStatus
});
return true;
}
public async Task SyncInComplaintStatus()
{
var now = DateTime.Now;
var data = await _zxdRepository.GetRepository<InComplaint>().Query()
.Where(x => x.DueStatus == InComplaintDueStatus.
//&& (x.BusinessDeadline <= now || x.ComplaintDeadline <= now))
&& x.BusinessDeadline <= now)
.ToListAsync();
foreach (var item in data)
{
item.DueStatus = InComplaintDueStatus.;
if (item.BusinessStatus == InComplaintBusinessStatus.)
{
item.BusinessStatus = InComplaintBusinessStatus.;
}
}
if (data.Any())
{
await _zxdRepository.GetRepository<InComplaint>().BatchUpdateAsync(data, x => new { x.DueStatus, x.BusinessStatus });
}
}
public async Task<InComplaintRestoreDto> GetRestore(int id)
{
var data = await _zxdRepository.GetRepository<InComplaint>().Query().FirstOrDefaultAsync(x => x.Id == id);
if (data == null) throw new ApiException("内诉数据不存在或已删除!");
var restore = await _zxdRepository.GetRepository<InComplaintRestore>().Query().Where(x => x.ComplaintId == data.ComplaintId).OrderBy(x=>x.CreateTime).ToListAsync();
var result = new InComplaintRestoreDto
{
Deptid = data.Deptid,
Cname = data.Cname,
ComplaintId = data.ComplaintId,
Resid = data.Resid,
InComplaintStatus = data.InComplaintStatus,
Id = data.Id,
InComplaintBusinessStatus = data.BusinessStatus,
Restores = restore.Select(x => new RestoreDto
{
Id = x.Id,
Content = x.Content,
Creator = x.Creator,
Attachment = x.Attachment,
ComplaintId = x.ComplaintId,
CreateTime = x.CreateTime,
CreatorEid = x.CreatorEid,
RestoreType = x.RestoreType
}).ToList()
};
var deptList = await _cacheDomain.GetDeptments();
var dept = deptList.FirstOrDefault(y => y.Id == data.Deptid);
result.Deptname = dept?.Title;
return result;
}
public async Task<bool> ProLong(InComplaintProLongDto dto)
{
var data = await _zxdRepository.GetRepository<InComplaint>().Query().FirstOrDefaultAsync(x => x.Id == dto.Id);
if (data == null) throw new ApiException("内诉数据不存在或已删除!");
var restore = await _zxdRepository.GetRepository<InComplaintRestore>().Query().FirstOrDefaultAsync(x => x.ComplaintId == data.ComplaintId);
if (restore != null)
throw new ApiException("已经处理回复,无需再延长期限!");
if (data.DueCount - 1 < 0)
throw new ApiException("延长期限次数已用完,无法再延长!");
if (data.IsAdjustDeadline)
throw new ApiException("已经调整过期限,无法再延长!");
data.BusinessDeadline = await _cacheDomain.AddWorkDays(data.BusinessDeadline, 3);
data.DueCount--;
data.UpdateEid = (int)dto.Eid;
data.Updater = dto.Name;
data.UpdateTime = DateTime.Now;
await _zxdRepository.GetRepository<InComplaint>().UpdateAsync(data, x => new
{
x.UpdateEid,
x.Updater,
x.UpdateTime,
x.BusinessDeadline,
x.DueCount,
});
return true;
}
public async Task<bool> Adjust(InComplaintAdjustDto dto)
{
var data = await _zxdRepository.GetRepository<InComplaint>().Query().FirstOrDefaultAsync(x => x.Id == dto.Id);
if (data == null) throw new ApiException("内诉数据不存在或已删除!");
if (data.IsAdjustDeadline)
throw new ApiException("已经调整过期限,无法再延长!");
data.UpdateEid = dto.Eid;
data.Updater = dto.UserName;
data.UpdateTime = DateTime.Now;
data.IsAdjustDeadline = true;
data.BusinessDeadline = await _cacheDomain.AddWorkDays(DateTime.Now, dto.Adjust);
await _zxdRepository.GetRepository<InComplaint>().UpdateAsync(data, x => new
{
x.UpdateEid,
x.Updater,
x.UpdateTime,
x.IsAdjustDeadline,
x.BusinessDeadline
});
return true;
}
public async Task<bool> Import(List<InComplaintImportDto> dtos)
{
dtos = dtos.Where(x => !string.IsNullOrWhiteSpace(x.Resid)).ToList();
dtos.ForEach(x => x.Resid = x.Resid.Replace("", "("));
dtos.ForEach(x => x.Resid = x.Resid.Contains("(") ? x.Resid.Substring(0, x.Resid.IndexOf("(")) : x.Resid);
dtos.ForEach(x => x.Resid = x.Resid.Contains("和") ? x.Resid.Substring(0, x.Resid.IndexOf("和")) : x.Resid);
var complaints = new List<InComplaint>();
var follows = new List<InComplaintFollowUp>();
var orderStatus = new List<string> { "220", "80", "90" };
var resIds = dtos.Select(x => x.Resid).ToList();
var orders = await _zxdRepository.GetRepository<WX_SZZYORDER>().Query().Where(x => resIds.Contains(x.RESID) && orderStatus.Contains(x.ORDERSTATUS)).OrderByDescending(x => x.CTIME).ToListAsync();
var deptList = await _cacheDomain.GetDeptments();
foreach (var dto in dtos)
{
var order = orders.FirstOrDefault(x => x.RESID == dto.Resid && x.ORDERSTATUS == "90");
if (order == null)
order = orders.FirstOrDefault(x => x.RESID == dto.Resid && x.ORDERSTATUS == "220");
if (order == null)
order = orders.FirstOrDefault(x => x.RESID == dto.Resid && x.ORDERSTATUS == "80");
//if (order == null)
// throw new Exception($"客户{dto.Resid}订单不存在");
var dept = deptList.FirstOrDefault(x => x.Title == dto.DeptName);
//if (dept == null)
// throw new Exception($"部门{dto.DeptName}不存在");
if (!System.Enum.TryParse(dto.ComplaintChannel, out InComplaintChannel complaintChannel))
{
if (dto.ComplaintChannel.Contains("400申诉热线"))
complaintChannel = InComplaintChannel.线400;
//else
//throw new Exception($"不存在:{dto.ComplaintChannel}内诉来源");
}
if (!System.Enum.TryParse(dto.Reasons, out InComplaintReason inComplaintReason))
{
if (dto.Reasons.Contains("5个工作日"))
inComplaintReason = InComplaintReason._5个工作日无理由;
//else
//throw new Exception($"不存在:{dto.Reasons}投诉原因");
}
if (!System.Enum.TryParse(dto.ComplaintStatus, out InComplaintStatus complaintStatus))
{
//throw new Exception($"不存在:{dto.ComplaintStatus}内诉状态");
}
var complaintId = CreateInComplaintid();
var data = new InComplaint
{
Deptid = dept?.Id,
DueStatus = await _cacheDomain.AddWorkDays(dto.ComplaintDate.Value, 3) > DateTime.Now ? InComplaintDueStatus. : InComplaintDueStatus.,
InComplaintDate = dto.ComplaintDate,
Cname = dto.Cname,
ComplaintId = complaintId,
BusinessDeadline = await _cacheDomain.AddWorkDays(dto.ComplaintDate.Value, 3),
BusinessStatus = InComplaintBusinessStatus.,
Content = dto.Content,
CreateTime = dto.ComplaintDate.Value,
Creator = "李冰华",
Follow = "",
InComplaintChannel = (int)complaintChannel == 0 ? null : (int)complaintChannel,
Reason = (int)inComplaintReason == 0 ? null : (int)inComplaintReason,
InComplaintStatus = complaintStatus == 0 ? null : complaintStatus,
Remark = dto.Remark,
Resid = dto.Resid,
Eid = order?.eid,
CreateEid = 6022,
DueCount = 4,
IsAdjustDeadline = false,
VerifyEid = !string.IsNullOrWhiteSpace(dto.Remark) ? 6022 : null,
Verifyier = !string.IsNullOrWhiteSpace(dto.Remark) ? "李冰华" : null,
VerifyTime = !string.IsNullOrWhiteSpace(dto.Remark) ? dto.ComplaintDate : null,
RiskSituation = ""
};
var InComplaintFollowUp = new InComplaintFollowUp
{
ComplaintId = complaintId,
Content = dto.Content,
CreateTime = dto.ComplaintDate,
Creator = "李冰华",
Follow = "",
CreateEid = 6022
};
complaints.Add(data);
follows.Add(InComplaintFollowUp);
//创建客户标签
if (dept != null)
await _cacheDomain.ComplaintLabel(dto.Resid, dto.Cname, dept.CompanyCode, "内诉");
}
await _zxdRepository.GetRepository<InComplaint>().BatchInsertAsync(complaints);
await _zxdRepository.GetRepository<InComplaintFollowUp>().BatchInsertAsync(follows);
return true;
}
}
}