|
@@ -59,7 +59,10 @@ using MiniExcelLibs;
|
|
|
using MongoDB.Driver;
|
|
|
using SqlSugar;
|
|
|
using StackExchange.Redis;
|
|
|
+using System;
|
|
|
+using System.ComponentModel.DataAnnotations;
|
|
|
using System.Text;
|
|
|
+using Wex.Sdk.Tel;
|
|
|
using XF.Domain.Authentications;
|
|
|
using XF.Domain.Cache;
|
|
|
using XF.Domain.Entities;
|
|
@@ -6029,8 +6032,12 @@ public class OrderController : BaseController
|
|
|
return _exportApplication.ExportData(list, "demo.xlsx");
|
|
|
}
|
|
|
|
|
|
- /// <summary>ExternalId
|
|
|
+ /// <summary>
|
|
|
/// 导入工单
|
|
|
+ /// TODO 回访信息需要写回访表?
|
|
|
+ /// TODO 工单是否需要写发布表?
|
|
|
+ /// TODO 是否自动签收工单?
|
|
|
+ /// TODO SourceChannel 是否和 Source 相同?
|
|
|
/// </summary>
|
|
|
/// <param name="file"></param>
|
|
|
/// <returns></returns>
|
|
@@ -6045,159 +6052,165 @@ public class OrderController : BaseController
|
|
|
int errorCount = 0;
|
|
|
int addCount = 0;
|
|
|
int modifyCount = 0;
|
|
|
- if (list != null && list.Count > 0)
|
|
|
+ var allowSources = new Dictionary<string, string>
|
|
|
{
|
|
|
- count = list.Count;
|
|
|
- foreach (var item in list)
|
|
|
+ { "麻辣社区", "MLSQ" }, {"人民网", "RMW" }, {"省长信箱", "SZXX" }, {"问政四川", "WZSC"}
|
|
|
+ };
|
|
|
+ var errorMessage = new StringBuilder();
|
|
|
+ if (list == null || list.Count == 0)
|
|
|
+ {
|
|
|
+ return new { Count = count, ErrorCount = errorCount, AddCount = addCount, ModifyCount = modifyCount, ErrorMessage = "数据为空" };
|
|
|
+ }
|
|
|
+
|
|
|
+ count = list.Count;
|
|
|
+ var i = 0;
|
|
|
+ foreach (var item in list)
|
|
|
+ {
|
|
|
+ i++;
|
|
|
+ try
|
|
|
{
|
|
|
- try
|
|
|
+ var validationResult = item.ValidateObject();
|
|
|
+ if (validationResult.NotNullOrEmpty())
|
|
|
{
|
|
|
- if (item.Source != "麻辣社区" || item.Source != "人民网" || item.Source != "省长信箱" || item.Source != "问政四川")
|
|
|
- //if (item.Source < ESource.MLSQ || item.Source > ESource.WZSC)
|
|
|
- {
|
|
|
- errorCount++;
|
|
|
- continue;
|
|
|
- }
|
|
|
+ errorMessage.Append($"第{i + 1}行: {validationResult}\r\n");
|
|
|
+ errorCount++;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
|
|
|
- int SourceCode = 0;
|
|
|
+ var allowSource = allowSources.FirstOrDefault(m => m.Key == item.Source).Value;
|
|
|
+ if (allowSource.IsNullOrEmpty())
|
|
|
+ {
|
|
|
+ errorCount++;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
|
|
|
- switch (item.Source)
|
|
|
- {
|
|
|
- case "麻辣社区":
|
|
|
- SourceCode = 500;
|
|
|
- break;
|
|
|
- case "人民网":
|
|
|
- SourceCode = 501;
|
|
|
- break;
|
|
|
- case "省长信箱":
|
|
|
- SourceCode = 502;
|
|
|
- break;
|
|
|
- case "问政四川":
|
|
|
- SourceCode = 529;
|
|
|
- break;
|
|
|
- default:
|
|
|
- break;
|
|
|
- }
|
|
|
+ var SourceCode = (ESource)Enum.Parse(typeof(ESource), allowSource);
|
|
|
|
|
|
- var order = await _orderRepository.GetAsync(x => x.ExternalId == item.ExternalId && x.Source == (ESource)SourceCode,
|
|
|
- HttpContext.RequestAborted);
|
|
|
+ var order = await _orderRepository.GetAsync(x => x.ExternalId == item.ExternalId && x.Source == SourceCode,
|
|
|
+ HttpContext.RequestAborted) ?? new Orders.Order();
|
|
|
+ item.Source = SourceCode.ToString();
|
|
|
+ order = _mapper.Map(item, order);
|
|
|
|
|
|
- order = _mapper.Map<Orders.Order>(item);
|
|
|
+ order.SourceChannel = SourceCode.GetDescription();
|
|
|
+ order.SourceChannelCode = ((int)SourceCode).ToString();
|
|
|
|
|
|
- #region 处理数据开始
|
|
|
+ #region 处理数据开始
|
|
|
|
|
|
- order.Source = (ESource)SourceCode; //来源
|
|
|
+ // order.Source = SourceCode; //来源
|
|
|
|
|
|
- //处理热点
|
|
|
- //处理一级热点
|
|
|
- string hotspotId = "";
|
|
|
- string hotspotName = "";
|
|
|
- string hotspotFullName = "";
|
|
|
- var hotspotOne = await _hotspotTypeRepository.Queryable()
|
|
|
- .FirstAsync(x => x.HotSpotName == item.HotspotNameOne, HttpContext.RequestAborted);
|
|
|
- if (hotspotOne != null)
|
|
|
+ //处理热点
|
|
|
+ //处理一级热点
|
|
|
+ string hotspotId = "";
|
|
|
+ string hotspotName = "";
|
|
|
+ string hotspotFullName = "";
|
|
|
+ var hotspotOne = await _hotspotTypeRepository.Queryable()
|
|
|
+ .FirstAsync(x => x.HotSpotName == item.HotspotNameOne, HttpContext.RequestAborted);
|
|
|
+ if (hotspotOne != null)
|
|
|
+ {
|
|
|
+ hotspotId = hotspotOne.Id;
|
|
|
+ hotspotName = hotspotOne.HotSpotName;
|
|
|
+ hotspotFullName = hotspotOne.HotSpotFullName;
|
|
|
+ var hotspotTwo = await _hotspotTypeRepository.Queryable()
|
|
|
+ .FirstAsync(x => x.HotSpotName == item.HotspotNameTwo && x.ParentId == hotspotId, HttpContext.RequestAborted);
|
|
|
+ if (hotspotTwo != null)
|
|
|
{
|
|
|
- hotspotId = hotspotOne.Id;
|
|
|
- hotspotName = hotspotOne.HotSpotName;
|
|
|
- hotspotFullName = hotspotOne.HotSpotFullName;
|
|
|
- var hotspotTwo = await _hotspotTypeRepository.Queryable()
|
|
|
- .FirstAsync(x => x.HotSpotName == item.HotspotNameTwo && x.ParentId == hotspotId, HttpContext.RequestAborted);
|
|
|
- if (hotspotTwo != null)
|
|
|
+ hotspotId = hotspotTwo.Id;
|
|
|
+ hotspotName = hotspotTwo.HotSpotName;
|
|
|
+ hotspotFullName = hotspotTwo.HotSpotFullName;
|
|
|
+ var hotspotThree = await _hotspotTypeRepository.Queryable()
|
|
|
+ .FirstAsync(x => x.HotSpotName == item.HotspotNameThree && x.ParentId == hotspotId, HttpContext.RequestAborted);
|
|
|
+ if (hotspotThree != null)
|
|
|
{
|
|
|
- hotspotId = hotspotTwo.Id;
|
|
|
- hotspotName = hotspotTwo.HotSpotName;
|
|
|
- hotspotFullName = hotspotTwo.HotSpotFullName;
|
|
|
- var hotspotThree = await _hotspotTypeRepository.Queryable()
|
|
|
- .FirstAsync(x => x.HotSpotName == item.HotspotNameThree && x.ParentId == hotspotId, HttpContext.RequestAborted);
|
|
|
- if (hotspotThree != null)
|
|
|
+ hotspotId = hotspotThree.Id;
|
|
|
+ hotspotName = hotspotThree.HotSpotName;
|
|
|
+ hotspotFullName = hotspotThree.HotSpotFullName;
|
|
|
+ var hotspotFour = await _hotspotTypeRepository.Queryable()
|
|
|
+ .FirstAsync(x => x.HotSpotName == item.HotspotNameFour && x.ParentId == hotspotId,
|
|
|
+ HttpContext.RequestAborted);
|
|
|
+ if (hotspotFour != null)
|
|
|
{
|
|
|
- hotspotId = hotspotThree.Id;
|
|
|
- hotspotName = hotspotThree.HotSpotName;
|
|
|
- hotspotFullName = hotspotThree.HotSpotFullName;
|
|
|
- var hotspotFour = await _hotspotTypeRepository.Queryable()
|
|
|
- .FirstAsync(x => x.HotSpotName == item.HotspotNameFour && x.ParentId == hotspotId,
|
|
|
+ hotspotId = hotspotFour.Id;
|
|
|
+ hotspotName = hotspotFour.HotSpotName;
|
|
|
+ hotspotFullName = hotspotFour.HotSpotFullName;
|
|
|
+ var hotspotFive = await _hotspotTypeRepository.Queryable()
|
|
|
+ .FirstAsync(x => x.HotSpotName == item.HotspotNameFive && x.ParentId == hotspotId,
|
|
|
HttpContext.RequestAborted);
|
|
|
- if (hotspotFour != null)
|
|
|
+ if (hotspotFive != null)
|
|
|
{
|
|
|
- hotspotId = hotspotFour.Id;
|
|
|
- hotspotName = hotspotFour.HotSpotName;
|
|
|
- hotspotFullName = hotspotFour.HotSpotFullName;
|
|
|
- var hotspotFive = await _hotspotTypeRepository.Queryable()
|
|
|
- .FirstAsync(x => x.HotSpotName == item.HotspotNameFive && x.ParentId == hotspotId,
|
|
|
- HttpContext.RequestAborted);
|
|
|
- if (hotspotFive != null)
|
|
|
- {
|
|
|
- hotspotId = hotspotFive.Id;
|
|
|
- hotspotName = hotspotFive.HotSpotName;
|
|
|
- hotspotFullName = hotspotFive.HotSpotFullName;
|
|
|
- }
|
|
|
+ hotspotId = hotspotFive.Id;
|
|
|
+ hotspotName = hotspotFive.HotSpotName;
|
|
|
+ hotspotFullName = hotspotFive.HotSpotFullName;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
- order.HotspotId = hotspotId;
|
|
|
- order.HotspotName = hotspotName;
|
|
|
- order.HotspotSpliceName = hotspotFullName;
|
|
|
+ order.HotspotId = hotspotId;
|
|
|
+ order.HotspotName = hotspotName;
|
|
|
+ order.HotspotSpliceName = hotspotFullName;
|
|
|
|
|
|
- //处理部门
|
|
|
- var orgOne = await _organizeRepository.Queryable()
|
|
|
- .FirstAsync(x => x.Name == item.OrgLevelOneName, HttpContext.RequestAborted);
|
|
|
- if (orgOne != null)
|
|
|
+ //处理部门
|
|
|
+ var orgOne = await _organizeRepository.Queryable()
|
|
|
+ .FirstAsync(x => x.Name == item.OrgLevelOneName, HttpContext.RequestAborted);
|
|
|
+ if (orgOne != null)
|
|
|
+ {
|
|
|
+ order.OrgLevelOneCode = orgOne.Id;
|
|
|
+ order.OrgLevelOneName = orgOne.Name;
|
|
|
+ var orgTwo = await _organizeRepository.Queryable()
|
|
|
+ .FirstAsync(x => x.Name == item.OrgLevelTwoName && x.ParentId == order.OrgLevelOneCode, HttpContext.RequestAborted);
|
|
|
+ if (orgTwo != null)
|
|
|
{
|
|
|
- order.OrgLevelOneCode = orgOne.Id;
|
|
|
- order.OrgLevelOneName = orgOne.Name;
|
|
|
- var orgTwo = await _organizeRepository.Queryable()
|
|
|
- .FirstAsync(x => x.Name == item.OrgLevelTwoName && x.ParentId == order.OrgLevelOneCode, HttpContext.RequestAborted);
|
|
|
- if (orgTwo != null)
|
|
|
- {
|
|
|
- order.OrgLevelTwoCode = orgTwo.Id;
|
|
|
- order.OrgLevelTwoName = orgTwo.Name;
|
|
|
- }
|
|
|
+ order.OrgLevelTwoCode = orgTwo.Id;
|
|
|
+ order.OrgLevelTwoName = orgTwo.Name;
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
- //承办部门
|
|
|
- var ActualHandleOrg = await _organizeRepository.Queryable()
|
|
|
- .FirstAsync(x => x.Name == item.ActualHandleOrgName, HttpContext.RequestAborted);
|
|
|
- if (ActualHandleOrg != null)
|
|
|
- {
|
|
|
- order.ActualHandleOrgCode = ActualHandleOrg.Id;
|
|
|
- }
|
|
|
+ //承办部门
|
|
|
+ var ActualHandleOrg = await _organizeRepository.Queryable()
|
|
|
+ .FirstAsync(x => x.Name == item.ActualHandleOrgName, HttpContext.RequestAborted);
|
|
|
+ if (ActualHandleOrg != null)
|
|
|
+ {
|
|
|
+ order.ActualHandleOrgCode = ActualHandleOrg.Id;
|
|
|
+ }
|
|
|
+
|
|
|
+ //处理地址
|
|
|
+ order.FullAddress = $"{order.Address}{order.Street}";
|
|
|
|
|
|
- //处理地址
|
|
|
- order.Address = $"{order.Province}{order.City}{order.County}{order.Town}";
|
|
|
- order.FullAddress = $"{order.Address}{order.Street}";
|
|
|
+ order.FirstVisitResultCode = _sysDicDataCacheManager
|
|
|
+ .GetSysDicDataCache(SysDicTypeConsts.VisitSatisfaction)
|
|
|
+ .FirstOrDefault(m => m.DicDataName == item.VisitResult)?.DicDataValue
|
|
|
+ ?? order.FirstVisitResultCode;
|
|
|
|
|
|
- #endregion
|
|
|
+ #endregion
|
|
|
|
|
|
- if (order is null)
|
|
|
+ if (order.Id.IsNullOrEmpty())
|
|
|
+ {
|
|
|
+ //order.Source = item;
|
|
|
+ var id = await _orderDomainService.AddAsync(order,false, HttpContext.RequestAborted);
|
|
|
+ if (!string.IsNullOrEmpty(id))
|
|
|
{
|
|
|
- //order.Source = item;
|
|
|
- var id = await _orderRepository.AddAsync(order, HttpContext.RequestAborted);
|
|
|
- if (!string.IsNullOrEmpty(id))
|
|
|
- {
|
|
|
- addCount++;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- errorCount++;
|
|
|
- }
|
|
|
+ addCount++;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- _mapper.Map(item, order);
|
|
|
- await _orderRepository.UpdateAsync(order, HttpContext.RequestAborted);
|
|
|
- modifyCount++;
|
|
|
+ errorCount++;
|
|
|
}
|
|
|
}
|
|
|
- catch (Exception ex)
|
|
|
+ else
|
|
|
{
|
|
|
- errorCount++;
|
|
|
+ // _mapper.Map(item, order);
|
|
|
+ await _orderRepository.UpdateAsync(order, HttpContext.RequestAborted);
|
|
|
+ modifyCount++;
|
|
|
}
|
|
|
}
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ errorCount++;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- return new { Count = count, ErrorCount = errorCount, AddCount = addCount, ModifyCount = modifyCount };
|
|
|
+ return new { Count = count, ErrorCount = errorCount, AddCount = addCount, ModifyCount = modifyCount, ErrorMessage = errorMessage.ToString() };
|
|
|
}
|
|
|
}
|
|
|
|