xf 3 mēneši atpakaļ
vecāks
revīzija
327bca8fb6

+ 43 - 188
src/Hotline.Api/Controllers/KnowledgeController.cs

@@ -970,193 +970,48 @@ namespace Hotline.Api.Controllers
             }, "知识模板.xlsx");
         }
 
-        //[HttpPost("import-knowledge")]
-        //public async Task<object> ImportKnowledge(IFormFile file)
-        //{
-        //    using (var stream = new MemoryStream())
-        //    {
-        //        file.CopyTo(stream);
-        //        var list = MiniExcel.Query<KnowledgeImportTemplate>(stream).ToList();
-        //        int count = 0;
-        //        int errorCount = 0;
-        //        int addCount = 0;
-        //        int modifyCount = 0;
-        //        var allowSources = new Dictionary<string, string>
-        //    {
-        //        { "麻辣社区", "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
-        //            {
-        //                var validationResult = item.ValidateObject(false);
-        //                if (validationResult.NotNullOrEmpty())
-        //                {
-        //                    errorMessage.Append($"第{i + 1}行: {validationResult}\r\n");
-        //                    errorCount++;
-        //                    continue;
-        //                }
-
-        //                var allowSource = allowSources.FirstOrDefault(m => m.Key == item.Source).Value;
-        //                if (allowSource.IsNullOrEmpty())
-        //                {
-        //                    errorCount++;
-        //                    continue;
-        //                }
-
-        //                var SourceCode = (ESource)Enum.Parse(typeof(ESource), allowSource);
-        //                var acceptType = _sysDicDataCacheManager.AcceptType
-        //                    .FirstOrDefault(m => m.DicDataName == item.AcceptType);
-
-        //                if (acceptType == null)
-        //                {
-        //                    errorMessage.Append($"第{i + 1}行: 不能通过受理类型 {item.AcceptType} 查询到对应的受理类型Code\r\n");
-        //                    continue;
-        //                }
-
-        //                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.AcceptTypeCode = acceptType.DicDataValue;
-        //                order.SourceChannel = SourceCode.GetDescription();
-        //                order.SourceChannelCode = ((int)SourceCode).ToString();
-        //                order.Status = EOrderStatus.Visited;
-        //                #region 处理数据开始
-
-        //                // 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)
-        //                {
-        //                    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 = 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 = 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;
-        //                                }
-        //                            }
-        //                        }
-        //                    }
-        //                }
-
-        //                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)
-        //                {
-        //                    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;
-        //                    }
-        //                }
-
-        //                //承办部门
-        //                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.FirstVisitResultCode = _sysDicDataCacheManager
-        //                                                 .GetSysDicDataCache(SysDicTypeConsts.VisitSatisfaction)
-        //                                                 .FirstOrDefault(m => m.DicDataName == item.VisitResult)?.DicDataValue
-        //                                             ?? order.FirstVisitResultCode;
-
-        //                #endregion
-
-        //                if (order.Id.IsNullOrEmpty())
-        //                {
-        //                    //order.Source = item;
-        //                    var id = await _orderDomainService.AddAsync(order, false, HttpContext.RequestAborted);
-        //                    if (!string.IsNullOrEmpty(id))
-        //                    {
-        //                        addCount++;
-        //                    }
-        //                    else
-        //                    {
-        //                        errorCount++;
-        //                    }
-        //                }
-        //                else
-        //                {
-        //                    // _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,
-        //            ErrorMessage = errorMessage.ToString()
-        //        };
-        //    }
-        //}
+        [HttpPost("import-knowledge")]
+        public async Task<object> ImportKnowledge(IFormFile file)
+        {
+            using (var stream = new MemoryStream())
+            {
+                await file.CopyToAsync(stream);
+                var items = stream.Query<KnowledgeImportTemplate>().ToList();
+                if (items == null || !items.Any()) return "未读取到数据";
+
+                if (items.Any(d => d.Attribution != "中心知识库" && d.Attribution != "部门知识库"))
+                    return "请正确输入知识归属";
+                if (items.Any(d => d.IsPublic != "是" && d.IsPublic != "否"))
+                    return "请正确输入是否公开";
+                if (items.Any(d => string.IsNullOrEmpty(d.Title)))
+                    return "请输入标题";
+                if (items.Any(d => string.IsNullOrEmpty(d.Content)))
+                    return "请输入内容";
+
+                var titles = items.Select(d => d.Title).ToList();
+                var exists = await _knowledgeRepository.Queryable()
+                    .Where(d => titles.Contains(d.Title))
+                    .ToListAsync(HttpContext.RequestAborted);
+                if (exists.Any())
+                    return $"标题重复:{string.Join(',', exists.Select(d => d.Title))}";
+
+                var levelOneTypes = items.Select(d => d.KnowledgeTypeLevelOne).ToList();
+                _knowledgeTypeRepository.Queryable()
+                    .Where(d => d.IsEnable);//todo
+
+                foreach (var item in items)
+                {
+                    var kn = _mapper.Map<Knowledge>(item);
+
+                }
+
+                return new
+                {
+
+                };
+            }
+        }
+
 
         #endregion
 
@@ -1982,7 +1837,7 @@ namespace Hotline.Api.Controllers
         public async Task<PagedDto<KnowledgeApproveDto>> QueryKnowledgeApprovePaged([FromQuery] QueryKnowledgeApprovePagedRequest request)
         {
             var query = _knowledgeApproRepository.Queryable()
-                .Includes(d => d.Knowledge)
+                .Includes(d => d.Knowledge, s => s.KnowledgeTypes)
                 .WhereIF(request.KnowledgeApproveType.HasValue, d => d.KnowledgeApproveType == request.KnowledgeApproveType)
                 .WhereIF(request.IsPublic.HasValue, d => d.Knowledge.IsPublic == request.IsPublic)
                 .WhereIF(!string.IsNullOrEmpty(request.Keyword), d => d.CreatorName == request.Keyword

+ 5 - 12
src/Hotline/KnowledgeBase/KnowledgeImportTemplate.cs

@@ -1,11 +1,4 @@
 using MiniExcelLibs.Attributes;
-using SqlSugar;
-using System;
-using System.Collections.Generic;
-using System.ComponentModel.DataAnnotations;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
 
 namespace Hotline.KnowledgeBase
 {
@@ -14,7 +7,7 @@ namespace Hotline.KnowledgeBase
         /// <summary>
         /// 知识归属
         /// </summary>
-        [ExcelColumnName("知识归属")]
+        [ExcelColumnName("知识归属(中心知识库/部门知识库)")]
         public string? Attribution { get; set; }
 
         [ExcelColumnName("一级分类")]
@@ -32,11 +25,11 @@ namespace Hotline.KnowledgeBase
         /// <summary>
         /// 是否公开
         /// </summary>
-        [ExcelColumnName("失效时间")]
-        public bool IsPublic { get; set; }
+        [ExcelColumnName("是否公开(是/否)")]
+        public string IsPublic { get; set; }
 
         [ExcelColumnName("热点分类")]
-        public string? HotspotId { get; set; }
+        public string? HotspotName { get; set; }
 
         /// <summary>
         /// 标题
@@ -50,4 +43,4 @@ namespace Hotline.KnowledgeBase
         [ExcelColumnName("内容")]
         public string Content { get; set; }
     }
-}
+}