Kaynağa Gözat

预案库修改

libin 3 ay önce
ebeveyn
işleme
64d2e32057

+ 3 - 3
src/Hotline.Api/Controllers/PlanController.cs

@@ -151,13 +151,13 @@ namespace Hotline.Api.Controllers
             return await _planTypeRepository.Queryable()
                 .WhereIF(IsEnable.HasValue, x => x.IsEnable == IsEnable)
                 .Where(x => SqlFunc.Subqueryable<PlanTypeOrg>().Where(to => to.TypeId == x.Id).Any() ||
-                SqlFunc.Subqueryable<PlanTypeOrg>().Where(to => to.TypeId == x.Id).NotAny()
+                            SqlFunc.Subqueryable<PlanTypeOrg>().Where(to => to.TypeId == x.Id).NotAny()
                 )
                 .Select(x => new PlanTypeDto()
                 {
                     Id = x.Id.SelectAll(),
                     PlanNum = SqlFunc.Subqueryable<PlanRelationType>().LeftJoin<PlanList>((kr, k) => kr.PlanId == k.Id)
-                         .Where((kr, k) => kr.PlanTypeSpliceName.StartsWith(x.SpliceName))
+                         .Where((kr, k) => kr.PlanTypeId == x.Id)
                          .DistinctCount(kr => kr.PlanId)
                 }
                 )
@@ -325,7 +325,7 @@ namespace Hotline.Api.Controllers
                 if (planDto.ApplyStatus == EPlanApplyStatus.Add)
                 {
                     planDto.Status = EPlanStatus.OnShelf;
-                    planDto.OnShelfTime = DateTime.Now; 
+                    planDto.OnShelfTime = DateTime.Now;
                 }
                 if (planDto.ApplyStatus == EPlanApplyStatus.Update)
                 {

+ 30 - 30
src/Hotline.Application/Planlibrary/PlanApplication.cs

@@ -15,11 +15,7 @@ using Hotline.Application.Bulletin;
 using Hotline.Share.Tools;
 using Hotline.Application.Tools;
 using SqlSugar;
-using Hotline.KnowledgeBase;
-using Hotline.Repository.SqlSugar.Knowledge;
-using Hotline.Share.Enums.KnowledgeBase;
-using Microsoft.AspNetCore.Http;
-using Hotline.Share.Enums.Caselibrary;
+using System.Numerics;
 
 namespace Hotline.Application.Planlibrary
 {
@@ -32,7 +28,6 @@ namespace Hotline.Application.Planlibrary
         #region 注册
 
         private readonly IRepository<PlanList> _planListRepository;                      //预案库列表
-        private readonly IRepository<PlanRelationType> _planRelationTypeRepository;      //预案库关联类型
         private readonly IRepository<PlanType> _planTypeRepository;                      //预案库分类管理
         private readonly IRepository<PlanTypeOrg> _planTypeOrgRepository;                //预案库分类关联机构
         private readonly IRepository<PlanCollect> _planCollectRepository;                //预案库收藏评分
@@ -44,7 +39,6 @@ namespace Hotline.Application.Planlibrary
 
         public PlanApplication(
             IRepository<PlanList> planListRepository,
-            IRepository<PlanRelationType> planRelationTypeRepository,
             IRepository<PlanType> planTypeRepository,
             IRepository<PlanTypeOrg> planTypeOrgRepository,
             ISessionContext sessionContext,
@@ -55,7 +49,6 @@ namespace Hotline.Application.Planlibrary
             IRepository<PlanCollect> planCollectRepository)
         {
             _planListRepository = planListRepository;
-            _planRelationTypeRepository = planRelationTypeRepository;
             _planTypeRepository = planTypeRepository;
             _planTypeOrgRepository = planTypeOrgRepository;
             _sessionContext = sessionContext;
@@ -169,7 +162,7 @@ namespace Hotline.Application.Planlibrary
                 throw UserFriendlyException.SameMessage("存在子级分类!");
 
             //查询是否有预案分类
-            var checkKnowledge = await _planListRepository.CountAsync(p => p.PlanTypes.Any(t => t.PlanId == Id), cancellationToken);
+            var checkKnowledge = await _planListRepository.CountAsync(p => p.PlanTypes.Any(t => t.Id == Id), cancellationToken);
             if (checkKnowledge > 0)
                 throw UserFriendlyException.SameMessage("分类存在预案!");
 
@@ -248,7 +241,7 @@ namespace Hotline.Application.Planlibrary
                                                                                               (x.Status == EPlanStatus.Revert && x.CreatorId == _sessionContext.UserId) ||
                                                                                               (x.Status == EPlanStatus.NewDrafts && x.CreatorId == _sessionContext.UserId))
 
-                .WhereIF(!string.IsNullOrEmpty(typeSpliceName), x => x.PlanTypes.Any(t => t.PlanTypeSpliceName.StartsWith(typeSpliceName)))
+                .WhereIF(!string.IsNullOrEmpty(typeSpliceName), x => x.PlanTypes.Any(t => t.SpliceName.StartsWith(typeSpliceName)))
                 .WhereIF(!string.IsNullOrEmpty(hotspotHotSpotFullName), x => x.HotspotType.HotSpotFullName.EndsWith(hotspotHotSpotFullName!))
 
                 .WhereIF(pagedDto.CreationTimeStart.HasValue, x => x.CreationTime >= pagedDto.CreationTimeStart)
@@ -298,14 +291,17 @@ namespace Hotline.Application.Planlibrary
 
             if (dto.Files != null && dto.Files.Count > 0)
                 pList.FileJson = await _fileRepository.AddFileAsync(dto.Files, pList.Id, "", cancellationToken);
-            await _planListRepository.AddAsync(pList, cancellationToken);
 
             if (dto.PlanTypes.Any())
             {
-                List<PlanRelationType> types = _mapper.Map<List<PlanRelationType>>(dto.PlanTypes);
-                types.ForEach(x => x.PlanId = pList.Id);
-                await _planRelationTypeRepository.AddRangeAsync(types, cancellationToken);
+                pList.PlanTypes = dto.PlanTypes.Select(d => new PlanType
+                {
+                    Id = d.PlanTypeId,
+                }).ToList();
             }
+            await _planListRepository.AddNav(pList)
+                                     .Include(d => d.PlanTypes)
+                                     .ExecuteCommandAsync();
 
             return pList.Id;
         }
@@ -353,19 +349,23 @@ namespace Hotline.Application.Planlibrary
                     plan.FileJson = new List<Share.Dtos.File.FileJson>();
             }
 
-            await _planListRepository.UpdateNullAsync(plan, cancellationToken);
-
-            if (dto.ApplyStatus != EPlanApplyStatus.Delete)
+            if (dto.PlanTypes.Any())
             {
-                if (dto.PlanTypes.Any())
+                plan.PlanTypes = dto.PlanTypes.Select(d => new PlanType
                 {
-                    var anyRelationTypes = await _planRelationTypeRepository.Queryable().Where(x => x.PlanId == plan.Id).ToListAsync();
-                    if (anyRelationTypes.Any())
-                        await _planRelationTypeRepository.RemoveRangeAsync(anyRelationTypes);
-                    List<PlanRelationType> types = _mapper.Map<List<PlanRelationType>>(dto.PlanTypes);
-                    types.ForEach(x => x.PlanId = dto.Id);
-                    await _planRelationTypeRepository.AddRangeAsync(types, cancellationToken);
-                }
+                    Id = d.PlanTypeId,
+                }).ToList();
+
+                await _planListRepository.UpdateNav(plan)
+                    .Include(d => d.PlanTypes, new UpdateNavOptions
+                    {
+                        ManyToManyIsUpdateA = true
+                    })
+                    .ExecuteCommandAsync();
+            }
+            else
+            {
+                await _planListRepository.UpdateAsync(plan, cancellationToken);
             }
         }
 
@@ -455,11 +455,11 @@ namespace Hotline.Application.Planlibrary
                 planInfoDto.HotspotName = hot.HotSpotFullName;
 
             // 分类
-            var relationType = await _planRelationTypeRepository.QueryAsync(x => x.PlanId == Id && x.CreatorId == _sessionContext.UserId);
-            if (relationType != null)
-            {
-                planInfoDto.PlanTypes = _mapper.Map<List<PlanRelationTypeDto>>(relationType);
-            }
+            //var relationType = await _planRelationTypeRepository.QueryAsync(x => x.PlanId == Id);
+            //if (relationType != null)
+            //{
+            //    planInfoDto.PlanTypes = _mapper.Map<List<PlanRelationTypeDto>>(relationType);
+            //}
 
             // 收藏
             var collect = await _planCollectRepository.GetAsync(x => x.PlanId == Id && x.CreatorId == _sessionContext.UserId);

+ 8 - 2
src/Hotline/Planlibrary/PlanList.cs

@@ -6,6 +6,7 @@ using System.ComponentModel;
 using XF.Domain.Repository;
 using Hotline.Share.Enums.Planlibrary;
 using Hotline.Share.Dtos.File;
+using Hotline.KnowledgeBase;
 
 namespace Hotline.Planlibrary;
 
@@ -175,8 +176,13 @@ public class PlanList : CreationEntity
     /// <summary>
 	/// 预案库类型关联ID
 	/// </summary>
-	[Navigate(NavigateType.OneToMany, nameof(PlanRelationType.PlanId))]
-    public List<PlanRelationType> PlanTypes { get; set; }
+	//[Navigate(NavigateType.OneToMany, nameof(PlanRelationType.PlanId))]
+    //public List<PlanRelationType> PlanTypes { get; set; }
+
+
+    [Navigate(typeof(PlanRelationType), nameof(PlanRelationType.PlanId), nameof(PlanRelationType.PlanTypeId))]
+    public List<PlanType> PlanTypes { get; set; }
+
 
     /// <summary>
     /// 附件

+ 4 - 22
src/Hotline/Planlibrary/PlanRelationType.cs

@@ -1,6 +1,6 @@
 using SqlSugar;
 using System.ComponentModel;
-using XF.Domain.Repository;
+using XF.Domain.Entities;
 
 namespace Hotline.Planlibrary;
 
@@ -8,35 +8,17 @@ namespace Hotline.Planlibrary;
 /// 预案库关联类型
 /// </summary>
 [Description("预案库关联类型")]
-[SugarIndex("index_planRelationType_planId", nameof(PlanRelationType.PlanId), OrderByType.Desc)]
-[SugarIndex("index_planRelationType_typeId", nameof(PlanRelationType.PlanTypeId), OrderByType.Desc)]
-[SugarIndex("index_planRelationType_spliceName", nameof(PlanRelationType.PlanTypeSpliceName), OrderByType.Desc)]
-public class PlanRelationType : FullStateEntity
+public class PlanRelationType : ITable, IEntity
 {
     /// <summary>
     /// 预案库ID
     /// </summary>
+    [SugarColumn(IsPrimaryKey = true)]
     public string PlanId { get; set; }
 
     /// <summary>
     /// 预案库类型ID
     /// </summary>
+    [SugarColumn(IsPrimaryKey = true)]
     public string PlanTypeId { get; set; }
-
-    /// <summary>
-    /// 预案库类型名称
-    /// </summary>
-    public string PlanTypeName { get; set; }
-
-    /// <summary>
-    /// 预案库类型名称
-    /// </summary>
-    public string PlanTypeSpliceName { get; set; }
-
-    /// <summary>
-    /// 预案库类型
-    /// </summary>
-    [Navigate(NavigateType.OneToOne, nameof(PlanTypeId))]
-    public PlanType PlanType { get; set; }
 }
-