Quellcode durchsuchen

完成 工单导入;

qinchaoyue vor 8 Monaten
Ursprung
Commit
29978146ba

+ 127 - 121
src/Hotline.Api/Controllers/OrderController.cs

@@ -57,6 +57,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;
@@ -599,7 +603,7 @@ public class OrderController : BaseController
         return res;
     }
 
-  
+
     /// <summary>
     /// 已发布列表
     /// </summary>
@@ -958,7 +962,7 @@ public class OrderController : BaseController
         }
 
         //_mapper.Map(dto.VisitDetails,visit.OrderVisitDetails);
-        for (int i = 0; i < visit.OrderVisitDetails.Count; i++)
+        for (int i = 0;i < visit.OrderVisitDetails.Count;i++)
         {
             var detail = visit.OrderVisitDetails[i];
             var detaildto = dto.VisitDetails.FirstOrDefault(x => x.Id == detail.Id);
@@ -4371,7 +4375,7 @@ public class OrderController : BaseController
         model.Status = order.Status;
 
         var audit = true;
-		var specialAduit = _systemSettingCacheManager.GetSetting(SettingConstants.SpecialAduit);
+        var specialAduit = _systemSettingCacheManager.GetSetting(SettingConstants.SpecialAduit);
         if (bool.Parse(specialAduit?.SettingValue[0]))
         {
             //if (!dto.Audit) model.State = 1;
@@ -4384,10 +4388,11 @@ public class OrderController : BaseController
                 if (roles != null && roles.Contains(item)) audit = false;
             }
         }
-        else {
+        else
+        {
             audit = false;
-		}
-		if (!audit) model.State = 1;
+        }
+        if (!audit) model.State = 1;
 
         model.InitId();
         if (dto.Files.Any())
@@ -5835,159 +5840,160 @@ 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())
+                    //if (item.Source < ESource.MLSQ || item.Source > ESource.WZSC)
+                    {
+                        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 == (ESource)SourceCode,
+                        HttpContext.RequestAborted) ?? new Orders.Order();
 
-                        order = _mapper.Map<Orders.Order>(item);
+                    item.Source = SourceCode.ToString();
+                    order = _mapper.Map(item, order);
 
-                        #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.Address = $"{order.Province}{order.City}{order.County}{order.Town}";
-                        order.FullAddress = $"{order.Address}{order.Street}";
+                    //处理地址
+                    // order.Address = $"{order.Province}{order.City}{order.County}{order.Town}";
+                    order.FullAddress = $"{order.Address}{order.Street}";
 
-                        #endregion
+                    #endregion
 
-                        if (order is null)
+                    if (order.Id.IsNullOrEmpty())
+                    {
+                        //order.Source = item;
+                        var id = await _orderRepository.AddAsync(order, 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() };
         }
     }
 

+ 4 - 0
src/Hotline.Application/Mappers/MapperConfigs.cs

@@ -1,4 +1,5 @@
 using Hotline.CallCenter.BlackLists;
+using Hotline.Import;
 using Hotline.JudicialManagement;
 using Hotline.Orders;
 using Hotline.Push.FWMessage;
@@ -20,6 +21,9 @@ namespace Hotline.Application.Mappers
     {
         public void Register(TypeAdapterConfig config)
         {
+            config.ForType<ExcelContent, Order>()
+                .IgnoreNullValues(true);
+
             config.ForType<TimeLimitSettingInventory, TimeConfig>()
                 .Map(d => d.Count, m => m.TimeValue);
             config.ForType<TimeResult, ExpiredTimeWithConfig>()

+ 25 - 0
src/Hotline.Share/Tools/ObjectExtensions.cs

@@ -1,5 +1,6 @@
 using System;
 using System.Collections.Generic;
+using System.ComponentModel.DataAnnotations;
 using System.Linq;
 using System.Reflection;
 using System.Text;
@@ -26,4 +27,28 @@ public static class ObjectExtensions
             if (result == false) break;
         }
     }
+
+    /// <summary>
+    /// 扩展方法用于手动验证对象,并返回验证结果。
+    /// </summary>
+    /// <param name="obj">需要验证的对象</param>
+    /// <returns>如果验证成功返回 string.Empty,否则返回错误信息</returns>
+    public static string ValidateObject(this object obj)
+    {
+        var validationResults = new List<ValidationResult>();
+        var validationContext = new ValidationContext(obj);
+
+        // 验证对象
+        bool isValid = Validator.TryValidateObject(obj, validationContext, validationResults, true);
+
+        if (isValid)
+        {
+            return string.Empty;
+        }
+        else
+        {
+            // 如果验证失败,返回所有错误信息的拼接
+            return string.Join("; ", validationResults.Select(result => result.ErrorMessage));
+        }
+    }
 }

+ 47 - 10
src/Hotline/Import/ExcelContent.cs

@@ -1,85 +1,122 @@
 using Hotline.Share.Enums.Order;
 using MiniExcelLibs.Attributes;
 using SqlSugar;
+using System.ComponentModel.DataAnnotations;
 
 
 namespace Hotline.Import
 {
     public class ExcelContent
     {
+        [Required(ErrorMessage = "来源 不能为空")]
         [ExcelColumnName("来源")]
         public string Source { get; set; }
 
+        [Required(ErrorMessage = "编号 不能为空")]
         [ExcelColumnName("编号")]
         public string ExternalId { get; set; }
 
+        [Required(ErrorMessage = "受理时间 不能为空")]
         [ExcelColumnName("受理时间")]
         public DateTime StartTime { get; set; }
 
+        [Required(ErrorMessage = "标题 不能为空")]
         [ExcelColumnName("标题")]
         public string Title { get; set; }
 
+        [Required(ErrorMessage = "期满时间 不能为空")]
         [ExcelColumnName("期满时间")]
         public DateTime ExpiredTime { get; set; }
+
         /// <summary>
         /// 一级部门名称
         /// </summary>
         [ExcelColumnName("一级部门")]
         public string? OrgLevelOneName { get; set; }
+
         /// <summary>
         /// 二级部门名称
         /// </summary>
         [ExcelColumnName("二级部门")]
         public string? OrgLevelTwoName { get; set; }
 
+        [Required(ErrorMessage = "承办部门 不能为空")]
         [ExcelColumnName("承办部门")]
         public string ActualHandleOrgName { get; set; }
+
+        [Required(ErrorMessage = "办结时间 不能为空")]
         [ExcelColumnName("办结时间")]
         public DateTime ActualHandleTime { get; set; }
+
+        [Required(ErrorMessage = "受理类型 不能为空")]
         [ExcelColumnName("受理类型")]
         public string AcceptType { get; set; }
+
+        [Required(ErrorMessage = "一级热点 不能为空")]
         [ExcelColumnName("一级热点")]
         public string HotspotNameOne { get; set; }
 
         [ExcelColumnName("二级热点")]
         public string HotspotNameTwo { get; set; }
+
         [ExcelColumnName("三级热点")]
         public string HotspotNameThree { get; set; }
 
         [ExcelColumnName("四级热点")]
-        public string HotspotNameFour { get; set;}
+        public string HotspotNameFour { get; set; }
 
         [ExcelColumnName("五级热点")]
         public string HotspotNameFive { get; set; }
 
-        [ExcelColumnName("市")]
-        public string City { get; set; }
-
-        [ExcelColumnName("区")]
-        public string County { get; set; }
-
-        [ExcelColumnName("乡镇")]
-        public string? Town { get; set; }
+        /// <summary>
+        /// 区域名称
+        /// </summary>
+        [Required(ErrorMessage = "区域 不能为空")]
+        [ExcelColumnName("区域")]
+        public string Address { get; set; }
 
         [ExcelColumnName("事发地址")]
         public string Street { get; set; }
 
+        [Required(ErrorMessage = "来电人姓名 不能为空")]
         [ExcelColumnName("来电人姓名")]
         public string FromName { get; set; }
 
+        [Required(ErrorMessage = "联系电话 不能为空")]
         [ExcelColumnName("联系电话")]
         public string Contact { get; set; }
-        
+
+        /// <summary>
+        /// 是否超期
+        /// "是" or "否"
+        /// </summary>
+        [ExcelColumnName("是否超期(是或否)")]
+        public string IsExpired { get; set; }
+
+        /// <summary>
+        /// 默认 0
+        /// </summary>
+        [Required(ErrorMessage = "重办次数 不能为空")]
         [ExcelColumnName("重办次数")]
         public int ReTransactNum { get; set; }
+
+        [Required(ErrorMessage = "信件满意度 不能为空")]
         [ExcelColumnName("信件满意度")]
         public string VisitResult { get; set; }
 
+        [Required(ErrorMessage = "受理内容 不能为空")]
         [ExcelColumnName("受理内容")]
         public string Content { get; set; }
 
+        [Required(ErrorMessage = "承办意见 不能为空")]
         [ExcelColumnName("承办意见")]
         public string ActualOpinion { get; set; }
 
+        /// <summary>
+        /// 链接
+        /// TODO 没有存
+        /// </summary>
+        [ExcelColumnName("链接")]
+        public string Link { get; set; }
     }
 }