using System.Text;
using System.Text.Json;
using DotNetCore.CAP;
using Hotline.Ai.Quality;
using Hotline.Application.CallCenter;
using Hotline.Application.ExportExcel;
using Hotline.Application.FlowEngine;
using Hotline.Application.JudicialManagement;
using Hotline.Application.OrderApp;
using Hotline.Application.Quality;
using Hotline.Application.StatisticalReport;
using Hotline.Caching.Interfaces;
using Hotline.CallCenter.BlackLists;
using Hotline.CallCenter.Calls;
using Hotline.CallCenter.Configs;
using Hotline.CallCenter.Ivrs;
using Hotline.CallCenter.Tels;
using Hotline.Configurations;
using Hotline.ContingencyManagement;
using Hotline.FlowEngine.WorkflowModules;
using Hotline.FlowEngine.Workflows;
using Hotline.Import;
using Hotline.JudicialManagement;
using Hotline.Orders;
using Hotline.Realtimes;
using Hotline.Repository.SqlSugar;
using Hotline.Repository.SqlSugar.Ts;
using Hotline.Settings;
using Hotline.Settings.Hotspots;
using Hotline.Settings.TimeLimitDomain;
using Hotline.Settings.TimeLimits;
using Hotline.Share.Dtos;
using Hotline.Share.Dtos.FlowEngine.Workflow;
using Hotline.Share.Dtos.Home;
using Hotline.Share.Dtos.Identity;
using Hotline.Share.Dtos.Order;
using Hotline.Share.Dtos.Realtime;
using Hotline.Share.Dtos.Snapshot;
using Hotline.Share.Dtos.TrCallCenter;
using Hotline.Share.Enums.CallCenter;
using Hotline.Share.Enums.FlowEngine;
using Hotline.Share.Enums.JudicialManagement;
using Hotline.Share.Enums.Order;
using Hotline.Share.Mq;
using Hotline.ThirdAccountDomainServices.Interfaces;
using Hotline.Users;
using Mapster;
using MapsterMapper;
using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;
using MiniExcelLibs;
using NETCore.Encrypt;
using NETCore.Encrypt.Internal;
using SqlSugar;
using XC.RSAUtil;
using XF.Domain.Authentications;
using XF.Domain.Cache;
using XF.Domain.Constants;
using XF.Domain.Filters;
using XF.Domain.Locks;
using XF.Domain.Queues;
using XF.Domain.Repository;
using Order = Hotline.Orders.Order;
using OrderDto = Hotline.Share.Dtos.Order.OrderDto;
namespace Hotline.Api.Controllers;
///
///
///
//[AllowAnonymous]
public class TestController : BaseController
{
private readonly ILogger _logger;
private readonly IOptionsSnapshot _options;
private readonly ISessionContext _sessionContext;
private readonly IRepository _userRepository;
private readonly ITypedCache _cache;
private readonly IRealtimeService _realtimeService;
private readonly IBlacklistDomainService _blacklistDomainService;
private readonly IIvrDomainService _ivrDomainService;
private readonly ISugarUnitOfWork _uow;
private readonly IRepository _roleRepository;
private readonly IMediator _mediator;
private readonly IDistributedLock _distributedLock;
private readonly IRepository _orderUrgeRepository;
private readonly IRepositoryTextSearch _repositoryts;
private readonly ITimeLimitDomainService _timeLimitDomainService;
private readonly IWfModuleDomainService _wfModuleDomainService;
private readonly IDaySettingRepository _daySettingRepository;
private readonly ICapPublisher _capPublisher;
private readonly IQueue _queue;
private readonly IExportApplication _exportApplication;
private readonly IRepository _workflowTraceRepository;
private readonly IRepository _workflowStepRepository;
private readonly IWorkflowRepository _workflowRepository;
private readonly IRepository _systemOrganizeRepository;
private readonly IOrderRepository _orderRepository;
private readonly IRepository _trCallRecordRepository;
private readonly IQualityApplication _qualityApplication;
private readonly IEnforcementApplication _enforcementApplication;
private readonly IWorkflowDomainService _workflowDomainService;
private readonly IMapper _mapper;
private readonly IOrderReportApplication _orderReportApplication;
private readonly IRepository _enforcementOrdersRepository;
private readonly IRepository _judicialManagementOrdersRepository;
private readonly IRepository _enforcementOrdersHandlerRepository;
private readonly IWorkflowApplication _workflowApplication;
private readonly IRepository _contingencyManagementHotspotRepository;
private readonly IRepository _hotspotRepository;
private readonly IOrderApplication _orderApplication;
private readonly IRepository _telRepository;
private readonly IOrderDomainService _orderDomainService;
private readonly ICallApplication _callApplication;
private readonly IOptionsSnapshot _appOptions;
private readonly ISystemSettingCacheManager _systemSettingCacheManager;
private readonly ICalcExpireTime _expireTime;
private readonly ICallNativeRepository _callNativeRepository;
private readonly IRepository _oldSendProDataRepository;
private readonly IOrderScreenRepository _orderScreenRepository;
private readonly IRepository _orderVisitRepository;
private readonly IThirdIdentiyService _thirdIdentiyService;
private readonly IServiceProvider _serviceProvider;
private readonly IRepository _orderDelayRepository;
private readonly IRepository _orderSecondaryHandlingRepository;
public TestController(
//INewRockClient client,
ILogger logger,
//IAuthorizeGenerator authorizeGenerator,
IOptionsSnapshot options,
ISessionContext sessionContext,
IRepository userRepository,
//ICacheManager cache
//ITypedCache> cache
ITypedCache cache,
IRealtimeService realtimeService,
IBlacklistDomainService blacklistDomainService,
IIvrDomainService ivrDomainService,
ISugarUnitOfWork uow,
IRepository roleRepository,
IMediator mediator,
IDistributedLock distributedLock,
IRepository orderUrgeRepository,
IRepositoryTextSearch repositoryts,
ITimeLimitDomainService timeLimitDomainService,
IWfModuleDomainService wfModuleDomainService,
IDaySettingRepository daySettingRepository,
ICapPublisher capPublisher,
IQueue queue,
IExportApplication exportApplication,
IRepository workflowTraceRepository,
IRepository workflowStepRepository,
IWorkflowRepository workflowRepository,
IRepository systemOrganizeRepository,
IOrderRepository orderRepository,
IRepository trCallRecordRepository,
IQualityApplication qualityApplication,
IEnforcementApplication enforcementApplication,
IWorkflowDomainService workflowDomainService,
IMapper mapper,
IOrderApplication orderApplication,
IRepository telRepository,
IOrderReportApplication orderReportApplication,
IRepository enforcementOrdersRepository,
IRepository judicialManagementOrdersRepository,
IRepository enforcementOrdersHandlerRepository,
IRepository contingencyManagementHotspotRepository,
IRepository hotspotRepository,
IOrderDomainService orderDomainService,
ICallApplication callApplication,
IOptionsSnapshot appOptions,
ISystemSettingCacheManager systemSettingCacheManager,
ICalcExpireTime expireTime,
IRepository orderDelayRepository,
ICallNativeRepository callNativeRepository,
IRepository oldSendProDataRepository,
IThirdIdentiyService thirdIdentiyService,
IOrderScreenRepository orderScreenRepository,
IRepository orderVisitRepository,
IServiceProvider serviceProvider,
IRepository orderSecondaryHandlingRepository
)
{
_logger = logger;
_options = options;
_sessionContext = sessionContext;
_userRepository = userRepository;
_cache = cache;
_realtimeService = realtimeService;
_blacklistDomainService = blacklistDomainService;
_ivrDomainService = ivrDomainService;
_uow = uow;
_roleRepository = roleRepository;
_mediator = mediator;
_distributedLock = distributedLock;
_orderUrgeRepository = orderUrgeRepository;
_repositoryts = repositoryts;
_timeLimitDomainService = timeLimitDomainService;
_wfModuleDomainService = wfModuleDomainService;
_daySettingRepository = daySettingRepository;
_capPublisher = capPublisher;
_queue = queue;
_exportApplication = exportApplication;
_workflowTraceRepository = workflowTraceRepository;
_workflowStepRepository = workflowStepRepository;
_workflowRepository = workflowRepository;
_systemOrganizeRepository = systemOrganizeRepository;
_orderRepository = orderRepository;
_trCallRecordRepository = trCallRecordRepository;
_qualityApplication = qualityApplication;
_enforcementApplication = enforcementApplication;
_workflowDomainService = workflowDomainService;
_mapper = mapper;
_orderReportApplication = orderReportApplication;
_enforcementOrdersRepository = enforcementOrdersRepository;
_judicialManagementOrdersRepository = judicialManagementOrdersRepository;
_enforcementOrdersHandlerRepository = enforcementOrdersHandlerRepository;
_contingencyManagementHotspotRepository = contingencyManagementHotspotRepository;
_hotspotRepository = hotspotRepository;
_orderApplication = orderApplication;
_telRepository = telRepository;
_orderDomainService = orderDomainService;
_callApplication = callApplication;
_appOptions = appOptions;
_systemSettingCacheManager = systemSettingCacheManager;
_expireTime = expireTime;
_callNativeRepository = callNativeRepository;
_oldSendProDataRepository = oldSendProDataRepository;
_thirdIdentiyService = thirdIdentiyService;
_orderScreenRepository = orderScreenRepository;
_orderVisitRepository = orderVisitRepository;
_serviceProvider = serviceProvider;
_orderDelayRepository = orderDelayRepository;
_orderSecondaryHandlingRepository = orderSecondaryHandlingRepository;
}
///
/// 测试获取电话号码
///
///
[HttpGet("phonenumber_test")]
[AllowAnonymous]
public async Task GetPhoneNumberTest()
{
var order = await _orderRepository.Queryable().Includes(d => d.Workflow).FirstAsync(d => d.ReceiveProvinceNo == "");
var order1 = await _orderRepository.Queryable().Includes(d => d.Workflow).FirstAsync(d => d.ReceiveProvinceNo == "20202020202020");
var order2 = await _orderRepository.Queryable().Includes(d => d.Workflow).FirstAsync(d => d.ReceiveProvinceNo == "ZMHD995100002024111101317");
var inDto = new ThirdTokenDto
{
AppId = _systemSettingCacheManager.WxOpenAppId,
Secret = _systemSettingCacheManager.WxOpenAppSecret
};
return await _thirdIdentiyService.GetPhoneNumberAsync(inDto, CancellationToken.None);
}
///
/// 修改泸州省工单编码区域
///
///
[HttpPost("updateoldsendprodata")]
[AllowAnonymous]
public async Task UpdateOldSendProData()
{
var list = await _oldSendProDataRepository.Queryable().Where(p => p.ProvinceNo.Contains("99511500")).ToListAsync();
if (list != null && list.Any())
{
foreach (var item in list)
{
var prono = item.ProvinceNo;
prono = prono.Replace("99511500", "99510500");
item.NewProvinceNo = prono;
await _oldSendProDataRepository.UpdateAsync(item);
}
}
}
///
/// 修改工单省编号
///
///
[HttpPost("updatesendprodata")]
[AllowAnonymous]
public async Task UpdateSendProData()
{
var list = await _oldSendProDataRepository.Queryable().Where(p => p.ProvinceNo.Contains("99511500")).ToListAsync();
if (list != null && list.Any())
{
foreach (var item in list)
{
var data = await _orderRepository.GetAsync(p => p.Id == item.Id, HttpContext.RequestAborted);
if (data != null)
{
data.ProvinceNo = item.NewProvinceNo;
await _orderRepository.Updateable(data).UpdateColumns(d => d.ProvinceNo).ExecuteCommandAsync(HttpContext.RequestAborted);
}
}
}
}
///
/// 从新推送省上数据
///
///
[HttpGet("sendpushprodata")]
[AllowAnonymous]
public async Task SendPushProData(string provinceNo)
{
//推送 受理信息、结果信息、过程信息、话务信息、回访信息
var list = await _oldSendProDataRepository.Queryable()
.Where(p => p.CreatorName == null)
.WhereIF(!string.IsNullOrEmpty(provinceNo), p => p.ProvinceNo == provinceNo).ToListAsync();
if (list != null && list.Any())
{
foreach (var item in list)
{
var order = await _orderRepository.GetAsync(p => p.Id == item.Id, HttpContext.RequestAborted);
if (order != null)
{
item.CreatorName = item.NewProvinceNo;
await _oldSendProDataRepository.Updateable(item).UpdateColumns(d => d.CreatorName).ExecuteCommandAsync(HttpContext.RequestAborted);
//受理信息
#region 受理信息
//var publishCallRecordDto = new PublishCallRecrodDto() { };
//if (order.SourceChannelCode == AppDefaults.SourceChannel.DianHua &&
// !string.IsNullOrEmpty(order.CallId))
//{
// if (_appOptions.Value.GetDefaultAppScopeConfiguration().CallCenterType == AppDefaults.CallCenterType.TianRun)
// {
// var callRecord = await _callApplication.GetTianrunCallAsync(order?.CallId, HttpContext.RequestAborted);
// if (callRecord != null)
// {
// publishCallRecordDto.TrCallRecordDto = _mapper.Map(callRecord);
// }
// }
// else if (_appOptions.Value.GetDefaultAppScopeConfiguration().CallCenterType == AppDefaults.CallCenterType.XingTang)
// {
// var call = await _callApplication.GetCallAsync(order?.CallId, HttpContext.RequestAborted);
// if (call is not null)
// {
// publishCallRecordDto.TrCallRecordDto = _mapper.Map(call);
// // 工单开始办理如果获取的通话记录是呼出并且录音文件是空就不推送通话记录
// // 如果 通话记录是呼入, 并且没有录音文件
// if (_systemSettingCacheManager.OrderStartHandlerPushCallIsNull && call.Direction == ECallDirection.Out && !string.IsNullOrEmpty(call.AudioFile))
// {
// publishCallRecordDto.TrCallRecordDto = null;
// }
// }
// }
//}
//publishCallRecordDto.Order = _mapper.Map(order);
//await _capPublisher.PublishAsync(EventNames.HotlineOrderFlowStarted, publishCallRecordDto,
// cancellationToken: HttpContext.RequestAborted);
#endregion
//结果信息
#region 受理信息、话务信息、结果信息
if (order != null)
{
var trace = await _workflowTraceRepository.Queryable()
.FirstAsync(d => d.WorkflowId == order.WorkflowId && d.StepType == EStepType.End, HttpContext.RequestAborted);
var orderFlowDto = new OrderFlowDto
{
Order = _mapper.Map(order),
WorkflowTrace = _mapper.Map(trace)
};
if (order.SourceChannelCode == AppDefaults.SourceChannel.DianHua &&
!string.IsNullOrEmpty(order.CallId))
{
if (_appOptions.Value.GetDefaultAppScopeConfiguration().CallCenterType == AppDefaults.CallCenterType.TianRun)
{
var callRecord = await _callApplication.GetTianrunCallAsync(order?.CallId, HttpContext.RequestAborted);
if (callRecord != null)
{
orderFlowDto.TrCallRecordDto = _mapper.Map(callRecord);
}
}
else if (_appOptions.Value.GetDefaultAppScopeConfiguration().CallCenterType == AppDefaults.CallCenterType.XingTang)
{
var call = await _callApplication.GetCallAsync(order?.CallId, HttpContext.RequestAborted);
if (call is not null)
{
orderFlowDto.TrCallRecordDto = _mapper.Map(call);
// 工单开始办理如果获取的通话记录是呼出并且录音文件是空就不推送通话记录
// 如果 通话记录是呼入, 并且没有录音文件
if (_systemSettingCacheManager.OrderStartHandlerPushCallIsNull && call.Direction == ECallDirection.Out && !string.IsNullOrEmpty(call.AudioFile))
{
orderFlowDto.TrCallRecordDto = null;
}
}
}
}
//这里需要判断是否是警情退回
orderFlowDto.IsNonPoliceReturn = false;
await _capPublisher.PublishAsync(Hotline.Share.Mq.EventNames.HotlineOrderFiled, orderFlowDto, cancellationToken: HttpContext.RequestAborted);
//_logger.LogWarning($"推送完成: {order.ProvinceNo}");
}
#endregion
//过程信息
#region 过程信息
//查询过程数据
if (order != null)
{
var listStep = await _workflowTraceRepository.Queryable()
.Where(p => p.WorkflowId == order.WorkflowId && p.TraceState == EWorkflowTraceState.Normal).ToListAsync();
if (listStep != null && listStep.Any())
{
foreach (var itemStep in listStep)
{
var orderDto = _mapper.Map(order);
var flowDto = new OrderFlowDto
{
Order = orderDto,
WorkflowTrace = _mapper.Map(itemStep),
ExpiredTimeChanged = false,
HandlerOrgLevel = itemStep.HandlerOrgId.CalcOrgLevel()
};
await _capPublisher.PublishAsync(Hotline.Share.Mq.EventNames.HotlineOrderFlowHandled, flowDto, cancellationToken: HttpContext.RequestAborted);
}
}
}
#endregion
//话务信息
//回访信息
#region 回访信息
if (order != null && order.Status == EOrderStatus.Visited)
{
var listVist = await _orderRepository.Queryable()
.Includes(x => x.OrderVisits.Where(q => q.VisitState == EVisitState.Visited).ToList(), d => d.OrderVisitDetails)
.Where(x => x.Id == item.Id && x.Status == EOrderStatus.Visited).ToListAsync();
foreach (var itemVisit in listVist)
{
try
{
var visit = itemVisit.OrderVisits.FirstOrDefault();
if (visit != null)
{
var visitRemark = visit.OrderVisitDetails.Where(q => q.VisitTarget == EVisitTarget.Org).FirstOrDefault()?.VisitContent;
//推省上
await _capPublisher.PublishAsync(Hotline.Share.Mq.EventNames.HotlineOrderVisited,
new PublishVisitDto()
{
Order = _mapper.Map(itemVisit),
No = visit.No,
VisitType = visit.VisitType,
VisitName = visit.CreatorName,
VisitTime = visit.VisitTime,
VisitRemark = string.IsNullOrEmpty(visitRemark) == true ? "满意" : visitRemark,
AreaCode = itemVisit.AreaCode!,
SubjectResultSatifyCode = visit.NowEvaluate.Key,
FirstSatisfactionCode = itemVisit.FirstVisitResultCode,
ClientGuid = ""
}, cancellationToken: HttpContext.RequestAborted);
}
}
catch { }
}
}
#endregion
}
}
}
}
[HttpGet("time")]
[AllowAnonymous]
public async Task GetTime(string batchId, string taskId)
{
//await _repositoryts.AddVectorAsync("f595e730-909a-45e4-9138-a84bf15f4662", DateTime.Now,
// new List { "xx", "bb" }, HttpContext.RequestAborted);
//await _repositoryts.AddVectorAsync("f595e730-909a-45e4-9138-a84bf15f4663", DateTime.Now,
// new List { "aa", "bb", "cc" }, HttpContext.RequestAborted);
//var result0 = await _repositoryts.SearchAsync(new List { "xx", "aa" }, HttpContext.RequestAborted);
//var result = await _repositoryts.SearchAsync(new List { "bb" }, HttpContext.RequestAborted);
//var result1 = await _repositoryts.SearchAsync(new List { "cc", "bb" }, HttpContext.RequestAborted);
//var result2 = await _repositoryts.SearchAsync(new List { "cc", "xx" }, HttpContext.RequestAborted);
//var result3 = await _repositoryts.SearchAsync(new List { "aa", "bb", "ss" }, HttpContext.RequestAborted);
//await _orderDomainService.SendOverTimeSms(HttpContext.RequestAborted);
//await _repositoryts.UpdateVectorAsync("f595e730-909a-45e4-9138-a84bf15f4662",
// new List { "ss", "bb" }, HttpContext.RequestAborted);
//_uow.Db.Ado.SqlQueryAsync("SELECT to_tsvector('fat cats ate fat rats') @@ to_tsquery('fat & rat')")
//var tests = _uowWex.Db.Ado.SqlQuery("select * from view_telinfo_full where IsSynch=@IsSynch", new { IsSynch = 0 });
//var a = _uowWex.Db.Ado.ExecuteCommand("update telinfo set IsSynch=1 where GUID=@CallId", new { CallId = "b1f97f3c-88b6-4f42-b8de-83ed448854b0" });
//var rsp = await _wexClient.QueryTelsAsync(new QueryTelRequest { }, HttpContext.RequestAborted);
//int a = _timeLimitDomainService.CalcWorkTime(DateTime.Now, DateTime.Parse("2023-09-11 16:21:00"));
//int m = _timeLimitDomainService.CalcWorkTime(DateTime.Parse("2023-09-19 12:00:00"), DateTime.Parse("2023-09-20 18:00:00"), false);
//var r = _timeLimitDomainService.CalcEndTime(DateTime.Parse("2024-6-06 14:32:47"),"40");
//var r = _timeLimitDomainService.CalcExpiredTime(DateTime.Parse("2024-02-29 10:12:33"), Share.Enums.FlowEngine.EFlowDirection.OrgToCenter, "10");
//await _wfModuleDomainService.PersistenceModulesAsync(HttpContext.RequestAborted);
//var rsp = await _daprClient.InvokeMethodAsync>(HttpMethod.Get, "identity", "api/v1/Test/time", HttpContext.RequestAborted);
//var rsp1 = await _daprClient.InvokeMethodAsync>(HttpMethod.Post, "identity", "api/v1/Test/time1", 222, HttpContext.RequestAborted);
//var a = await _trClient.QueryTelsAsync(new Tr.Sdk.Tels.QueryTelRequest() { }, HttpContext.RequestAborted);
//await _daySettingRepository.IsWorkDay(DateTime.Now);
//var r = _timeLimitDomainService.CalcWorkTime(DateTime.Parse("2024-6-06 14:32:47"), DateTime.Parse("2024-3-22 06:00:00"), false);
//var r = _timeLimitDomainService.CalcWorkTime(DateTime.Parse("2024-3-24 17:20:00"), DateTime.Parse("2024-3-24 17:21:00"), false);
//await _aiVisitService.QueryAiVisitTask(batchId, taskId, HttpContext.RequestAborted);
//var r = _timeLimitDomainService.CalcWorkTimeReduce(DateTime.Now, 5);
//var r = _timeLimitDomainService.CalcWorkTimeToDecimal(DateTime.Parse("2024-07-09 14:57:51"), DateTime.Parse("2024-07-10 14:20:42"), false);
//var endTime = _timeLimitDomainService
//.CalcEndTime(DateTime.Parse("2024-07-09 14:57:51"), ETimeType.WorkDay, -3, 0, 0);///.EndTime;
//var timeResult = _timeLimitDomainService.CalcEndTime(DateTime.Now, ETimeType.WorkDay, 3, 80, 50);
//var t = _timeLimitDomainService.CalcWorkTimeEx(DateTime.Parse("2024-07-22 11:30:00"), DateTime.Parse("2024-07-23 14:00:00"), false);
//var r = await _aiVisitService.QueryAiVisitTaskEx("MTAwMDAx173ASS0kSUAqK2rl2sFGME", "", HttpContext.RequestAborted);
//var r = await _aiVisitService.QueryAiVisitTaskResult(batchId, DateTime.Parse("2024-07-28"), DateTime.Parse("2024-08-01"), HttpContext.RequestAborted);
//var r = _timeLimitDomainService.CalcExpiredTime(DateTime.Now, EFlowDirection.CenterToCenter, batchId);
//var r = _timeLimitDomainService.CalcEndTime(DateTime.Parse("2024-09-12 14:45:47"), Share.Enums.Settings.ETimeType.WorkDay, 2, 80, 50);
//_capPublisher.PublishDelay((DateTime.Now.AddMinutes(2) - DateTime.Now), EventNames.OrderRelateCall, "123");
//var times = await _expireTime.CalcExpiredTime(DateTime.Parse("2025-01-14 09:45:00"), DateTime.Parse("2025-01-07 09:16:53.691249"), EFlowDirection.CenterToOrg, new OrderTimeClacInfo() { AcceptTypeCode = "20" });
//await _expireTime.CalcWorkTimeToDecimal(visit.VisitTime.Value, DateTime.Now, false);
//var times = await _expireTime.CalcWorkTimeToDecimal(DateTime.Parse("2024-12-16 21:36:27"), DateTime.Parse("2024-12-17 12:47:05"), false);
//var query = _userRepository.Queryable().Where(x => false);
//await _capPublisher.PublishDelay(EventNames.OrderRelateCall, "123", cancellationToken: HttpContext.RequestAborted);
var times = await _expireTime.CalcWorkTimeEx(
DateTime.Parse("2025-02-21 16:00:11.154098"), DateTime.Parse("2025-02-28 11:27:11.441577"), false);
return OpenResponse.Ok(times);
}
///
/// 通过工单号重推回访到省上
///
///
///
[HttpPost("publish-visit-province-no")]
[AllowAnonymous]
public async Task PublishVisitToProvinceByNo(string Nos)
{
Nos = Nos.Trim();
string[] no = Nos.Split(',');
for (int i = 0; i < no.Length; i++)
{
no[i] = no[i].Trim();
}
var list = await _orderRepository.Queryable()
.Includes(x => x.OrderVisits.Where(q => q.VisitState == EVisitState.Visited).ToList(), d => d.OrderVisitDetails)
.Where(x => no.Contains(x.No) && x.Status == EOrderStatus.Visited).ToListAsync();
foreach (var item in list)
{
try
{
var visit = item.OrderVisits.FirstOrDefault();
if (visit != null)
{
var visitRemark = visit.OrderVisitDetails.Where(q => q.VisitTarget == EVisitTarget.Org).FirstOrDefault()?.VisitContent;
//推省上
await _capPublisher.PublishAsync(Hotline.Share.Mq.EventNames.HotlineOrderVisited,
new PublishVisitDto()
{
Order = _mapper.Map(item),
No = visit.No,
VisitType = visit.VisitType,
VisitName = visit.CreatorName,
VisitTime = visit.VisitTime,
VisitRemark = string.IsNullOrEmpty(visitRemark) == true ? "满意" : visitRemark,
AreaCode = item.AreaCode!,
SubjectResultSatifyCode = visit.NowEvaluate.Key,
FirstSatisfactionCode = item.FirstVisitResultCode,
ClientGuid = ""
}, cancellationToken: HttpContext.RequestAborted);
}
}
catch { }
}
}
///
/// 市场监管局数据处理
///
///
///
[HttpPost("importmarketsupervision")]
[AllowAnonymous]
public async Task> ImportMarketSupervision(IFormFile file)
{
using (var stream = new MemoryStream())
{
file.CopyTo(stream);
var list = MiniExcel.Query(stream).ToList();
//Directory.Delete(filePath, true);
return list;
}
}
///
/// 推送回访到省上
///
///
[HttpPost("publishVisitToProvince")]
[AllowAnonymous]
public async Task PublsihVisitToProvince([FromBody] DateTime date)
{
//查询需要推送的数据
var list = await _orderRepository.Queryable()
.Includes(x => x.OrderVisits.Where(q => q.VisitState == EVisitState.Visited).ToList())
.Where(x => x.CreationTime.Date == date.Date && x.Status == EOrderStatus.Visited && x.ProcessType == EProcessType.Zhiban && x.CounterSignType == null).ToListAsync();
foreach (var item in list)
{
var visit = item.OrderVisits.FirstOrDefault();
if (visit != null)
{
//推省上
await _capPublisher.PublishAsync(Hotline.Share.Mq.EventNames.HotlineOrderVisited,
new PublishVisitDto()
{
Order = _mapper.Map(item),
No = visit.No,
VisitType = visit.VisitType,
VisitName = visit.CreatorName,
VisitTime = visit.VisitTime,
VisitRemark = "满意",
AreaCode = item.AreaCode!,
SubjectResultSatifyCode = "4",
FirstSatisfactionCode = "4",
ClientGuid = ""
}, cancellationToken: HttpContext.RequestAborted);
}
}
}
[HttpGet("addcontingencymanagementhotspot")]
[AllowAnonymous]
public async Task AddContingencyManagementHotspot([FromQuery] string? Id, string? ParentId)
{
if (!string.IsNullOrWhiteSpace(Id))
{
var data = await _hotspotRepository.GetAsync(Id, HttpContext.RequestAborted);
if (data != null)
{
var newdata = _mapper.Map(data);
newdata.Id = data.Id;
await _contingencyManagementHotspotRepository.AddAsync(newdata, HttpContext.RequestAborted);
}
}
if (!string.IsNullOrEmpty(ParentId))
{
var data = await _hotspotRepository.Queryable().Where(p => p.ParentId == ParentId).ToListAsync();
if (data != null && data.Count > 0)
{
foreach (var item in data)
{
var newdata = _mapper.Map(item);
newdata.Id = item.Id;
await _contingencyManagementHotspotRepository.AddAsync(newdata, HttpContext.RequestAborted);
}
}
}
}
///
/// 处理司法工单数据
///
///
///
///
[HttpGet("addjudicial_management_orders")]
[AllowAnonymous]
public async Task AddJudicialManagementOrders(DateTime StartTime, DateTime? EndTime)
{
var list = await _enforcementOrdersRepository.Queryable()
.Includes(x => x.Order)
.Where(x => x.CreationTime >= StartTime && x.CreationTime <= EndTime && x.Order.AcceptTypeCode == "35")
.ToListAsync();
foreach (var item in list)
{
var order = item.Order;
if (order != null)
{
var orderData = await _judicialManagementOrdersRepository.GetAsync(p => p.Id == order.Id, HttpContext.RequestAborted);
if (orderData == null)
{
orderData = new JudicialManagementOrders();
//处理工单
_mapper.Map(order, orderData);
orderData.Id = order.Id;
orderData.IsEnforcementOrder = order.IsEnforcementOrder.HasValue ? order.IsEnforcementOrder.Value : false;
orderData.IsTheClueTrue = item.IsTheClueTrue;
orderData.IsPassTheBuckOrder = item.IsPassTheBuckOrder;
orderData.OrderSoure = EOrderSoure.Hotline;
orderData.CreationTime = item.CreationTime;
if (item.EventTypeId == "04" || item.EventTypeId == "05" || item.EventTypeId == "06" || item.EventTypeId == "07" || item.EventTypeId == "08" ||
item.EventTypeId == "0401" || item.EventTypeId == "0501" || item.EventTypeId == "0601" || item.EventTypeId == "0701" || item.EventTypeId == "0801")
{
orderData.EventTypeId = "0901";
orderData.EventTypeName = "其他情形";
orderData.EventTypeSpliceName = "其他类-其他情形";
orderData.EventTypeOneLevelId = "09";
}
else
{
orderData.EventTypeId = item.EventTypeId;
orderData.EventTypeName = item.EventTypeName;
orderData.EventTypeSpliceName = item.EventTypeSpliceName;
orderData.EventTypeOneLevelId = item.EventTypeOneLevelId;
}
List kvs = new List
{
new Kv { Key = order.OrgLevelOneName, Value = order.OrgLevelOneCode }
};
orderData.EnforcementOrdersHandler = kvs;
await _judicialManagementOrdersRepository.AddAsync(orderData, HttpContext.RequestAborted);
//处理部门
EnforcementOrdersHandler enforcementOrdersHandler = new EnforcementOrdersHandler()
{
OrderId = order.Id,
OrderNo = order.No,
OrderSoure = EOrderSoure.Hotline,
OrgCode = order.OrgLevelOneCode,
OrgName = order.OrgLevelOneName,
CreationTime = order.CreationTime
};
await _enforcementOrdersHandlerRepository.AddAsync(enforcementOrdersHandler, HttpContext.RequestAborted);
}
}
}
}
///
/// 计算工单的办理时长
///
///
///
///
[HttpGet("update_order_handle_time")]
[AllowAnonymous]
public async Task UpdateOrderHandleTime(DateTime StartTime, DateTime? EndTime)
{
var list = await _orderRepository.Queryable()
.Where(p => p.CreationTime >= StartTime && p.CreationTime <= EndTime && p.Status >= EOrderStatus.Filed)
.Where(p => p.CreationTimeHandleDuration == null || p.CenterToOrgHandleDuration == null)
.ToListAsync();
if (list.Any())
{
foreach (var item in list)
{
var creationTimeHandleDurationWorkday = item.FiledTime.HasValue
?
//_timeLimitDomainService.CalcWorkTimeEx(
await _expireTime.CalcWorkTimeEx(
item.CreationTime, item.FiledTime.Value,
item.ProcessType is EProcessType.Zhiban)
: 0;
var centerToOrgHandleDurationWorkday = item.FiledTime.HasValue && item.CenterToOrgTime.HasValue
?
//_timeLimitDomainService.CalcWorkTimeEx(
await _expireTime.CalcWorkTimeEx(
item.CenterToOrgTime.Value, item.FiledTime.Value,
item.ProcessType is EProcessType.Zhiban)
: 0;
item.CreationTimeHandleDurationWorkday = creationTimeHandleDurationWorkday;
item.CenterToOrgHandleDurationWorkday = centerToOrgHandleDurationWorkday;
if (item.FiledTime.HasValue)
{
var count = Math.Round((item.FiledTime - item.CreationTime).Value.TotalSeconds);
item.CreationTimeHandleDuration = count <= 0 ? 1 : count;
}
else
item.CreationTimeHandleDuration = 0;
if (item.FiledTime.HasValue && item.CenterToOrgTime.HasValue)
{
var count = Math.Round((item.FiledTime - item.CenterToOrgTime).Value.TotalSeconds);
item.CenterToOrgHandleDuration = count <= 0 ? 1 : count;
}
else
item.CenterToOrgHandleDuration = 0;
await _orderRepository.UpdateAsync(item, HttpContext.RequestAborted);
}
}
}
[HttpGet("testo")]
[AllowAnonymous]
public async Task TestOrigin()
{
var now = DateTime.Now.ToString();
return OpenResponse.Ok(now);
}
[HttpGet("init-orgname")]
[AllowAnonymous]
public async Task InitUserOrgFullName()
{
var list = await _userRepository.Queryable().Where(x => 1 == 1 && string.IsNullOrEmpty(x.FullOrgName)).ToListAsync();
foreach (var item in list)
{
var orgFullName = "";
var orgFullCode = "";
var orgId = item.OrgId;
int strLength = orgId.Length;
int segmentsCount = strLength / 3;
List strings = new List();
for (int i = 0; i < segmentsCount; i++)
{
int startIndex = i * 3;
int length = Math.Min(3, strLength - startIndex);
strings.Add(orgId.Substring(startIndex, length));
}
if (strLength > 3)
{
orgFullCode = strings[0];
strings.Remove(orgFullCode);
}
foreach (var str in strings)
{
orgFullCode = orgFullCode + str;
var org = await _systemOrganizeRepository.GetAsync(orgFullCode);
if (org != null)
{
orgFullName = orgFullName + org.Name + "/";
}
}
if (orgFullName.Length > 0)
{
orgFullName = orgFullName.Remove(orgFullName.Length - 1);
}
item.FullOrgName = orgFullName;
await _userRepository.UpdateAsync(item);
}
}
[HttpPost("import")]
[AllowAnonymous]
public async Task> Import(IFormFile file)
{
//var FileName = file.FileName;
//var fileExtension = Path.GetExtension(FileName);
////新文件名
//var newFileName = DateTime.Now.ToString("yyyyMMddhhmmss");
////文件保存路径
//var filePath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "Upload", newFileName);
////判断路径是否存在
//if (!Directory.Exists(filePath))
//{
// //创建路径
// Directory.CreateDirectory(filePath);
//}
//filePath = Path.Combine(filePath, newFileName+ fileExtension);
using (var stream = new MemoryStream())
{
file.CopyTo(stream);
var list = MiniExcel.Query(stream).ToList();
//Directory.Delete(filePath, true);
return list;
}
}
[AllowAnonymous]
[HttpGet("export")]
public async Task