From 668ee2ab779191c91b3aed0c9a7ea33a725e1d90 Mon Sep 17 00:00:00 2001 From: wxd <123@qq.com> Date: Fri, 14 Jun 2024 15:25:17 +0800 Subject: [PATCH] =?UTF-8?q?=E9=97=AE=E5=8D=B7=E7=AD=94=E6=A1=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CreateQuestionAnswerDto.cs | 71 ++++++ .../QuestionAnswers/QuestionAnswerDto.cs | 80 +++++++ .../QuestionAnswerIdInputDto.cs | 11 + .../QuestionAnswerTreeListDto.cs | 82 +++++++ .../UpdateQuestionAnswerDto.cs | 68 ++++++ .../Questions/CreateQuestionDto.cs | 5 +- .../Questions/UpdateQuestionDto.cs | 4 - .../QuestionAnswerAppService.cs | 223 ++++++++++++++++++ .../Questions/QuestionAppService.cs | 1 + .../WebPeisApplicationAutoMapperProfile.cs | 17 ++ .../Models/AsbitemRecommendLevel.cs | 2 +- .../Models/DiseaseRisk.cs | 2 +- .../Models/DiseaseRiskLevel.cs | 6 +- .../Models/QuestionAnswer.cs | 13 +- .../QuestionAnswers/QuestionAnswerManager.cs | 208 ++++++++++++++++ .../UpdateQuestionAnswerSortDragDto.cs | 21 ++ ...teQuestionAnswerSortTopOrBottomInputDto.cs | 18 ++ .../Questions/QuestionManager.cs | 1 - 18 files changed, 815 insertions(+), 18 deletions(-) create mode 100644 src/Shentun.WebPeis.Application.Contracts/QuestionAnswers/CreateQuestionAnswerDto.cs create mode 100644 src/Shentun.WebPeis.Application.Contracts/QuestionAnswers/QuestionAnswerDto.cs create mode 100644 src/Shentun.WebPeis.Application.Contracts/QuestionAnswers/QuestionAnswerIdInputDto.cs create mode 100644 src/Shentun.WebPeis.Application.Contracts/QuestionAnswers/QuestionAnswerTreeListDto.cs create mode 100644 src/Shentun.WebPeis.Application.Contracts/QuestionAnswers/UpdateQuestionAnswerDto.cs create mode 100644 src/Shentun.WebPeis.Application/QuestionAnswers/QuestionAnswerAppService.cs create mode 100644 src/Shentun.WebPeis.Domain/QuestionAnswers/QuestionAnswerManager.cs create mode 100644 src/Shentun.WebPeis.Domain/QuestionAnswers/UpdateQuestionAnswerSortDragDto.cs create mode 100644 src/Shentun.WebPeis.Domain/QuestionAnswers/UpdateQuestionAnswerSortTopOrBottomInputDto.cs diff --git a/src/Shentun.WebPeis.Application.Contracts/QuestionAnswers/CreateQuestionAnswerDto.cs b/src/Shentun.WebPeis.Application.Contracts/QuestionAnswers/CreateQuestionAnswerDto.cs new file mode 100644 index 0000000..a5ce447 --- /dev/null +++ b/src/Shentun.WebPeis.Application.Contracts/QuestionAnswers/CreateQuestionAnswerDto.cs @@ -0,0 +1,71 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Shentun.WebPeis.QuestionAnswers +{ + public class CreateQuestionAnswerDto + { + + /// + /// 答案 + /// + + public string QuestionAnswerName { get; set; } = null!; + /// + /// 问卷ID + /// + + public Guid QuestionId { get; set; } + + + + /// + /// 子答案类别 + /// + + public char? ChildAnswerType { get; set; } + /// + /// 答案结果类别 + /// + + public char? AnswerResultType { get; set; } + /// + /// 别名 + /// + + public string? Aliases { get; set; } + + /// + /// 概述 + /// + + public string? Overview { get; set; } + /// + /// 可能原因 + /// + public string? Reason { get; set; } + /// + /// 健康指导 + /// + public string? HealthGuidance { get; set; } + + /// + /// 父答案ID + /// + + public Guid? ParentId { get; set; } + + /// + /// 子答案标题 + /// + public string? ChildAnswerTitle { get; set; } + /// + /// 无,和其它答案排斥 + /// + public char IsNone { get; set; } + + + + } +} diff --git a/src/Shentun.WebPeis.Application.Contracts/QuestionAnswers/QuestionAnswerDto.cs b/src/Shentun.WebPeis.Application.Contracts/QuestionAnswers/QuestionAnswerDto.cs new file mode 100644 index 0000000..5809d69 --- /dev/null +++ b/src/Shentun.WebPeis.Application.Contracts/QuestionAnswers/QuestionAnswerDto.cs @@ -0,0 +1,80 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Shentun.WebPeis.QuestionAnswers +{ + public class QuestionAnswerDto: AuditedEntityDtoName + { + /// + /// 主键 + /// + public Guid QuestionAnswerId { get; set; } + /// + /// 答案 + /// + + public string QuestionAnswerName { get; set; } = null!; + /// + /// 问卷ID + /// + + public Guid QuestionId { get; set; } + + + + /// + /// 子答案类别 + /// + + public char? ChildAnswerType { get; set; } + /// + /// 答案结果类别 + /// + + public char? AnswerResultType { get; set; } + /// + /// 别名 + /// + + public string? Aliases { get; set; } + + /// + /// 概述 + /// + + public string? Overview { get; set; } + /// + /// 可能原因 + /// + public string? Reason { get; set; } + /// + /// 健康指导 + /// + public string? HealthGuidance { get; set; } + + /// + /// 父答案ID + /// + + public Guid? ParentId { get; set; } + /// + /// 编码路径 + /// + + public string? PathCode { get; set; } + /// + /// 子答案标题 + /// + public string? ChildAnswerTitle { get; set; } + /// + /// 无,和其它答案排斥 + /// + public char IsNone { get; set; } + + + public string SimpleCode { get; set; } = null!; + + public int DisplayOrder { get; set; } + } +} diff --git a/src/Shentun.WebPeis.Application.Contracts/QuestionAnswers/QuestionAnswerIdInputDto.cs b/src/Shentun.WebPeis.Application.Contracts/QuestionAnswers/QuestionAnswerIdInputDto.cs new file mode 100644 index 0000000..212151f --- /dev/null +++ b/src/Shentun.WebPeis.Application.Contracts/QuestionAnswers/QuestionAnswerIdInputDto.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Shentun.WebPeis.QuestionAnswers +{ + public class QuestionAnswerIdInputDto + { + public Guid QuestionAnswerId { get; set; } + } +} diff --git a/src/Shentun.WebPeis.Application.Contracts/QuestionAnswers/QuestionAnswerTreeListDto.cs b/src/Shentun.WebPeis.Application.Contracts/QuestionAnswers/QuestionAnswerTreeListDto.cs new file mode 100644 index 0000000..30c167b --- /dev/null +++ b/src/Shentun.WebPeis.Application.Contracts/QuestionAnswers/QuestionAnswerTreeListDto.cs @@ -0,0 +1,82 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Shentun.WebPeis.QuestionAnswers +{ + public class QuestionAnswerTreeListDto: AuditedEntityDtoName + { + /// + /// 主键 + /// + public Guid QuestionAnswerId { get; set; } + /// + /// 答案 + /// + + public string QuestionAnswerName { get; set; } = null!; + /// + /// 问卷ID + /// + + public Guid QuestionId { get; set; } + + + + /// + /// 子答案类别 + /// + + public char? ChildAnswerType { get; set; } + /// + /// 答案结果类别 + /// + + public char? AnswerResultType { get; set; } + /// + /// 别名 + /// + + public string? Aliases { get; set; } + + /// + /// 概述 + /// + + public string? Overview { get; set; } + /// + /// 可能原因 + /// + public string? Reason { get; set; } + /// + /// 健康指导 + /// + public string? HealthGuidance { get; set; } + + /// + /// 父答案ID + /// + + public Guid? ParentId { get; set; } + /// + /// 编码路径 + /// + + public string? PathCode { get; set; } + /// + /// 子答案标题 + /// + public string? ChildAnswerTitle { get; set; } + /// + /// 无,和其它答案排斥 + /// + public char IsNone { get; set; } + + + public string SimpleCode { get; set; } = null!; + + public int DisplayOrder { get; set; } + + public List TreeChildren { get; set; } + } +} diff --git a/src/Shentun.WebPeis.Application.Contracts/QuestionAnswers/UpdateQuestionAnswerDto.cs b/src/Shentun.WebPeis.Application.Contracts/QuestionAnswers/UpdateQuestionAnswerDto.cs new file mode 100644 index 0000000..0e2237b --- /dev/null +++ b/src/Shentun.WebPeis.Application.Contracts/QuestionAnswers/UpdateQuestionAnswerDto.cs @@ -0,0 +1,68 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Shentun.WebPeis.QuestionAnswers +{ + public class UpdateQuestionAnswerDto + { + /// + /// 主键 + /// + public Guid QuestionAnswerId { get; set; } + + /// + /// 答案 + /// + + public string QuestionAnswerName { get; set; } = null!; + /// + /// 问卷ID + /// + + public Guid QuestionId { get; set; } + + + + /// + /// 子答案类别 + /// + + public char? ChildAnswerType { get; set; } + /// + /// 答案结果类别 + /// + + public char? AnswerResultType { get; set; } + /// + /// 别名 + /// + + public string? Aliases { get; set; } + + /// + /// 概述 + /// + + public string? Overview { get; set; } + /// + /// 可能原因 + /// + public string? Reason { get; set; } + /// + /// 健康指导 + /// + public string? HealthGuidance { get; set; } + + + + /// + /// 子答案标题 + /// + public string? ChildAnswerTitle { get; set; } + /// + /// 无,和其它答案排斥 + /// + public char IsNone { get; set; } + } +} diff --git a/src/Shentun.WebPeis.Application.Contracts/Questions/CreateQuestionDto.cs b/src/Shentun.WebPeis.Application.Contracts/Questions/CreateQuestionDto.cs index ec02167..e7a3994 100644 --- a/src/Shentun.WebPeis.Application.Contracts/Questions/CreateQuestionDto.cs +++ b/src/Shentun.WebPeis.Application.Contracts/Questions/CreateQuestionDto.cs @@ -6,10 +6,7 @@ namespace Shentun.WebPeis.Questions { public class CreateQuestionDto { - /// - /// 主键 - /// - public Guid QuestionId { get; set; } + /// /// 题目 /// diff --git a/src/Shentun.WebPeis.Application.Contracts/Questions/UpdateQuestionDto.cs b/src/Shentun.WebPeis.Application.Contracts/Questions/UpdateQuestionDto.cs index fada274..4d2779b 100644 --- a/src/Shentun.WebPeis.Application.Contracts/Questions/UpdateQuestionDto.cs +++ b/src/Shentun.WebPeis.Application.Contracts/Questions/UpdateQuestionDto.cs @@ -37,11 +37,7 @@ namespace Shentun.WebPeis.Questions /// public char? IsActive { get; set; } - /// - /// 父问卷ID - /// - public Guid? ParentId { get; set; } } } diff --git a/src/Shentun.WebPeis.Application/QuestionAnswers/QuestionAnswerAppService.cs b/src/Shentun.WebPeis.Application/QuestionAnswers/QuestionAnswerAppService.cs new file mode 100644 index 0000000..ed6c53e --- /dev/null +++ b/src/Shentun.WebPeis.Application/QuestionAnswers/QuestionAnswerAppService.cs @@ -0,0 +1,223 @@ +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; +using Shentun.WebPeis.Models; +using Shentun.WebPeis.Questions; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Volo.Abp.Application.Services; +using Volo.Abp.Domain.Repositories; + +namespace Shentun.WebPeis.QuestionAnswers +{ + + /// + /// 问卷答案 + /// + [ApiExplorerSettings(GroupName = "Work")] + [Authorize] + public class QuestionAnswerAppService : ApplicationService + { + + private readonly IRepository _questionAnswerRepository; + private readonly QuestionAnswerManager _questionAnswerManager; + private readonly CacheService _cacheService; + + public QuestionAnswerAppService( + CacheService cacheService, + IRepository questionAnswerRepository, + QuestionAnswerManager questionAnswerManager) + { + _cacheService = cacheService; + _questionAnswerRepository = questionAnswerRepository; + _questionAnswerManager = questionAnswerManager; + } + + ///// + ///// 获取列表 + ///// + ///// + //[HttpPost("api/app/QuestionAnswer/GetList")] + //public async Task> GetListAsync() + //{ + // var entlist = await _questionRepository.GetQueryableAsync(); + + // var entdto = entlist.Select(s => new QuestionDto + // { + // CreationTime = s.CreationTime, + // CreatorId = s.CreatorId, + // DisplayOrder = s.DisplayOrder, + // LastModificationTime = s.LastModificationTime, + // LastModifierId = s.LastModifierId, + // SimpleCode = s.SimpleCode, + // QuestionTypeId = s.QuestionTypeId, + // QuestionSubjectTypeId = s.QuestionSubjectTypeId, + // QuestionName = s.QuestionName, + // QuestionId = s.QuestionId, + // PathCode = s.PathCode, + // ParentId = s.ParentId, + // IsActive = s.IsActive, + // AnswerType = s.AnswerType, + // CreatorName = _cacheService.GetSurnameAsync(s.CreatorId).Result, + // LastModifierName = _cacheService.GetSurnameAsync(s.LastModifierId).Result + // }).OrderBy(o => o.DisplayOrder).ToList(); + + // return entdto; + + + //} + + + /// + /// 获取问卷答案树型列表 根据问卷ID + /// + /// + /// + [HttpPost("api/app/QuestionAnswer/GetQuestionTreeList")] + public async Task> GetQuestionAnswerTreeListAsync(QuestionIdInputDto input) + { + var dataList = await _questionAnswerRepository.GetListAsync(m => m.QuestionId == input.QuestionId); + var items = from p in dataList.OrderBy(o => o.DisplayOrder) + select new QuestionAnswerTreeListDto() + { + ParentId = p.ParentId, + QuestionId = p.QuestionId, + CreationTime = p.CreationTime, + CreatorId = p.CreatorId, + CreatorName = _cacheService.GetSurnameAsync(p.CreatorId).Result, + LastModificationTime = p.LastModificationTime, + LastModifierId = p.LastModifierId, + LastModifierName = _cacheService.GetSurnameAsync(p.LastModifierId).Result, + PathCode = p.PathCode, + SimpleCode = p.SimpleCode, + DisplayOrder = p.DisplayOrder, + ChildAnswerType = p.ChildAnswerType, + QuestionAnswerId = p.QuestionAnswerId, + Reason = p.Reason, + QuestionAnswerName = p.QuestionAnswerName, + Aliases = p.Aliases, + AnswerResultType = p.AnswerResultType, + ChildAnswerTitle = p.ChildAnswerTitle, + HealthGuidance = p.HealthGuidance, + IsNone = p.IsNone, + Overview = p.Overview + }; + return GetTree(items.ToList(), 0, ""); + } + + + + /// + /// 创建 + /// + /// + [HttpPost("api/app/QuestionAnswer/Create")] + public async Task CreateAsync(CreateQuestionAnswerDto input) + { + var createEntity = ObjectMapper.Map(input); + createEntity.QuestionAnswerId = GuidGenerator.Create(); + var entity = await _questionAnswerManager.CreateAsync(createEntity); + entity = await _questionAnswerRepository.InsertAsync(entity); + var dto = ObjectMapper.Map(entity); + dto.CreatorName = await _cacheService.GetSurnameAsync(dto.CreatorId); + dto.LastModifierName = await _cacheService.GetSurnameAsync(dto.LastModifierId); + return dto; + } + + /// + /// 更新 + /// + /// + /// + [HttpPost("api/app/QuestionAnswer/Update")] + public async Task UpdateAsync(UpdateQuestionAnswerDto input) + { + var entity = await _questionAnswerRepository.GetAsync(f => f.QuestionAnswerId == input.QuestionAnswerId); + var sourceEntity = ObjectMapper.Map(input); + _questionAnswerManager.UpdateAsync(sourceEntity, entity); + entity = await _questionAnswerRepository.UpdateAsync(entity); + var dto = ObjectMapper.Map(entity); + dto.CreatorName = await _cacheService.GetSurnameAsync(dto.CreatorId); + dto.LastModifierName = await _cacheService.GetSurnameAsync(dto.LastModifierId); + return dto; + } + + /// + /// 删除 + /// + /// + /// + [HttpPost("api/app/QuestionAnswer/Delete")] + public async Task DeleteAsync(QuestionAnswerIdInputDto input) + { + await _questionAnswerManager.CheckAndDeleteAsync(input.QuestionAnswerId); + } + + /// + /// 修改排序 置顶,置底 + /// + /// + /// + [HttpPost("api/app/QuestionAnswer/UpdateSortTopOrBottom")] + public async Task UpdateSortTopOrBottomAsync(UpdateQuestionAnswerSortTopOrBottomInputDto input) + { + await _questionAnswerManager.UpdateSortTopOrBottomAsync(input.QuestionAnswerId, input.SortType); + } + + /// + /// 修改排序 拖拽 + /// + /// + /// + [HttpPost("api/app/QuestionAnswer/UpdateSortDragAsync")] + public async Task UpdateSortDragAsync(UpdateQuestionAnswerSortDragDto input) + { + await _questionAnswerManager.UpdateSortDragAsync(input); + } + + + /// + /// 使用Code进行递归 + /// + /// + /// + /// + /// + private List GetTree(List items, int deep, string prefix) + { + return (from p in items + where p.PathCode.StartsWith(prefix) && p.PathCode.Count(a => a == '.') == deep + orderby p.DisplayOrder ascending + let subs = GetTree(items, deep + 1, p.PathCode) + select new QuestionAnswerTreeListDto() + { + ParentId = p.ParentId, + QuestionId = p.QuestionId, + CreationTime = p.CreationTime, + CreatorId = p.CreatorId, + CreatorName = _cacheService.GetSurnameAsync(p.CreatorId).Result, + LastModificationTime = p.LastModificationTime, + LastModifierId = p.LastModifierId, + LastModifierName = _cacheService.GetSurnameAsync(p.LastModifierId).Result, + PathCode = p.PathCode, + SimpleCode = p.SimpleCode, + DisplayOrder = p.DisplayOrder, + ChildAnswerType = p.ChildAnswerType, + QuestionAnswerId = p.QuestionAnswerId, + Reason = p.Reason, + QuestionAnswerName = p.QuestionAnswerName, + Aliases = p.Aliases, + AnswerResultType = p.AnswerResultType, + ChildAnswerTitle = p.ChildAnswerTitle, + HealthGuidance = p.HealthGuidance, + IsNone = p.IsNone, + Overview = p.Overview, + TreeChildren = subs.ToList() + } + ).ToList(); + } + + } +} diff --git a/src/Shentun.WebPeis.Application/Questions/QuestionAppService.cs b/src/Shentun.WebPeis.Application/Questions/QuestionAppService.cs index bcbe74d..8965ac5 100644 --- a/src/Shentun.WebPeis.Application/Questions/QuestionAppService.cs +++ b/src/Shentun.WebPeis.Application/Questions/QuestionAppService.cs @@ -110,6 +110,7 @@ namespace Shentun.WebPeis.Questions public async Task CreateAsync(CreateQuestionDto input) { var createEntity = ObjectMapper.Map(input); + createEntity.QuestionId= GuidGenerator.Create(); var entity = await _questionManager.CreateAsync(createEntity); entity = await _questionRepository.InsertAsync(entity); var dto = ObjectMapper.Map(entity); diff --git a/src/Shentun.WebPeis.Application/WebPeisApplicationAutoMapperProfile.cs b/src/Shentun.WebPeis.Application/WebPeisApplicationAutoMapperProfile.cs index 854c313..d6999c0 100644 --- a/src/Shentun.WebPeis.Application/WebPeisApplicationAutoMapperProfile.cs +++ b/src/Shentun.WebPeis.Application/WebPeisApplicationAutoMapperProfile.cs @@ -12,6 +12,9 @@ using Shentun.WebPeis.Models; using Shentun.WebPeis.Nations; using Shentun.WebPeis.OrganizationUnits; using Shentun.WebPeis.Persons; +using Shentun.WebPeis.QuestionAnswers; +using Shentun.WebPeis.Questions; +using Shentun.WebPeis.QuestionTypes; using Shentun.WebPeis.Sexs; using Shentun.WebPeis.ThirdInterfaces; using Volo.Abp.Identity; @@ -82,5 +85,19 @@ public class WebPeisApplicationAutoMapperProfile : Profile CreateMap(); CreateMap(); CreateMap(); + + + CreateMap(); + CreateMap(); + CreateMap(); + + CreateMap(); + CreateMap(); + CreateMap(); + + + CreateMap(); + CreateMap(); + CreateMap(); } } diff --git a/src/Shentun.WebPeis.Domain/Models/AsbitemRecommendLevel.cs b/src/Shentun.WebPeis.Domain/Models/AsbitemRecommendLevel.cs index 686eebf..8db57cc 100644 --- a/src/Shentun.WebPeis.Domain/Models/AsbitemRecommendLevel.cs +++ b/src/Shentun.WebPeis.Domain/Models/AsbitemRecommendLevel.cs @@ -8,7 +8,7 @@ using Volo.Abp.Domain.Entities.Auditing; namespace Shentun.WebPeis.Models { - public class AsbitemRecommendLevel : AuditedEntity, IHasConcurrencyStamp + public class AsbitemRecommendLevel : AuditedEntity, IHasConcurrencyStamp, IDisplayOrder { public short AsbitemRecommendLevelId { get; set; } diff --git a/src/Shentun.WebPeis.Domain/Models/DiseaseRisk.cs b/src/Shentun.WebPeis.Domain/Models/DiseaseRisk.cs index 698f5ac..7bce782 100644 --- a/src/Shentun.WebPeis.Domain/Models/DiseaseRisk.cs +++ b/src/Shentun.WebPeis.Domain/Models/DiseaseRisk.cs @@ -9,7 +9,7 @@ namespace Shentun.WebPeis.Models; /// /// 疾病风险 /// -public partial class DiseaseRisk : AuditedEntity, IHasConcurrencyStamp +public partial class DiseaseRisk : AuditedEntity, IHasConcurrencyStamp,IDisplayOrder { /// /// 主键 diff --git a/src/Shentun.WebPeis.Domain/Models/DiseaseRiskLevel.cs b/src/Shentun.WebPeis.Domain/Models/DiseaseRiskLevel.cs index 3cd0b99..6e5a8cb 100644 --- a/src/Shentun.WebPeis.Domain/Models/DiseaseRiskLevel.cs +++ b/src/Shentun.WebPeis.Domain/Models/DiseaseRiskLevel.cs @@ -8,7 +8,7 @@ namespace Shentun.WebPeis.Models; /// /// 疾病风险级别 /// -public partial class DiseaseRiskLevel : AuditedEntity, IHasConcurrencyStamp +public partial class DiseaseRiskLevel : AuditedEntity, IHasConcurrencyStamp, IDisplayOrder { /// /// 风险级别ID @@ -29,7 +29,7 @@ public partial class DiseaseRiskLevel : AuditedEntity, IHasConcurrencyStamp public int DisplayOrder { get; set; } - + /// /// 风险标准级别ID,暂时废弃 /// @@ -45,7 +45,7 @@ public partial class DiseaseRiskLevel : AuditedEntity, IHasConcurrencyStamp public string? Suggestion { get; set; } - public string DiagnosisFunction { get; set; } + public string DiagnosisFunction { get; set; } public virtual DiseaseRisk DiseaseRisk { get; set; } = null!; diff --git a/src/Shentun.WebPeis.Domain/Models/QuestionAnswer.cs b/src/Shentun.WebPeis.Domain/Models/QuestionAnswer.cs index 840f437..ecc88ec 100644 --- a/src/Shentun.WebPeis.Domain/Models/QuestionAnswer.cs +++ b/src/Shentun.WebPeis.Domain/Models/QuestionAnswer.cs @@ -8,7 +8,7 @@ namespace Shentun.WebPeis.Models; /// /// 问卷答案 /// -public partial class QuestionAnswer : AuditedEntity, IHasConcurrencyStamp +public partial class QuestionAnswer : AuditedEntity, IHasConcurrencyStamp, IDisplayOrder { /// /// 主键 @@ -25,9 +25,7 @@ public partial class QuestionAnswer : AuditedEntity, IHasConcurrencyStamp public Guid QuestionId { get; set; } - public string SimpleCode { get; set; } = null!; - public int DisplayOrder { get; set; } /// /// 子答案类别 @@ -49,7 +47,7 @@ public partial class QuestionAnswer : AuditedEntity, IHasConcurrencyStamp /// 概述 /// - public string? Overview { get; set; } + public string? Overview { get; set; } /// /// 可能原因 /// @@ -77,6 +75,13 @@ public partial class QuestionAnswer : AuditedEntity, IHasConcurrencyStamp /// 无,和其它答案排斥 /// public char IsNone { get; set; } + + + public string SimpleCode { get; set; } = null!; + + public int DisplayOrder { get; set; } + + public virtual ICollection QuestionRegisterAnswers { get; set; } = new List(); public string? ConcurrencyStamp { get; set; } diff --git a/src/Shentun.WebPeis.Domain/QuestionAnswers/QuestionAnswerManager.cs b/src/Shentun.WebPeis.Domain/QuestionAnswers/QuestionAnswerManager.cs new file mode 100644 index 0000000..d1bfd2a --- /dev/null +++ b/src/Shentun.WebPeis.Domain/QuestionAnswers/QuestionAnswerManager.cs @@ -0,0 +1,208 @@ +using NPOI.POIFS.Properties; +using Shentun.Utilities; +using Shentun.WebPeis.Models; +using Shentun.WebPeis.Questions; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.CompilerServices; +using System.Text; +using System.Threading.Tasks; +using Volo.Abp.Domain.Entities; +using Volo.Abp.Domain.Repositories; +using Volo.Abp.Domain.Services; + +namespace Shentun.WebPeis.QuestionAnswers +{ + public class QuestionAnswerManager : DomainService + { + private readonly IRepository _questionAnswerRepository; + + public QuestionAnswerManager( + IRepository questionAnswerRepository + ) + { + _questionAnswerRepository = questionAnswerRepository; + } + + /// + /// 创建 + /// + /// + public async Task CreateAsync(QuestionAnswer entity) + { + DataHelper.CheckEntityIsNull(entity); + //DataHelper.CheckStringIsNull(entity.QuestionTypeName, "名称"); + + return new QuestionAnswer + { + HealthGuidance = entity.HealthGuidance, + Aliases = entity.Aliases, + IsNone = entity.IsNone, + Overview = entity.Overview, + ChildAnswerTitle = entity.ChildAnswerTitle, + AnswerResultType = entity.AnswerResultType, + ChildAnswerType = entity.ChildAnswerType, + QuestionAnswerId = entity.QuestionAnswerId, + QuestionAnswerName = entity.QuestionAnswerName, + QuestionRegisterAnswers = entity.QuestionRegisterAnswers, + Reason = entity.Reason, + ParentId = entity.ParentId, + PathCode = await CreatePathCode(entity.ParentId), + QuestionId = entity.QuestionId, + SimpleCode = LanguageConverter.GetPYSimpleCode(entity.QuestionAnswerName), + DisplayOrder = await EntityHelper.CreateMaxDisplayOrder(_questionAnswerRepository) + }; + } + + + /// + /// 更新 + /// + /// + /// + /// + public void UpdateAsync( + QuestionAnswer sourceEntity, + QuestionAnswer targetEntity + ) + { + DataHelper.CheckEntityIsNull(sourceEntity); + DataHelper.CheckEntityIsNull(targetEntity); + //DataHelper.CheckStringIsNull(sourceEntity.QuestionTypeName, "名称"); + + + + targetEntity.HealthGuidance = sourceEntity.HealthGuidance; + targetEntity.Aliases = sourceEntity.Aliases; + targetEntity.IsNone = sourceEntity.IsNone; + targetEntity.Overview = sourceEntity.Overview; + targetEntity.ChildAnswerTitle = sourceEntity.ChildAnswerTitle; + targetEntity.AnswerResultType = sourceEntity.AnswerResultType; + targetEntity.ChildAnswerType = sourceEntity.ChildAnswerType; + targetEntity.QuestionAnswerName = sourceEntity.QuestionAnswerName; + targetEntity.QuestionRegisterAnswers = sourceEntity.QuestionRegisterAnswers; + targetEntity.Reason = sourceEntity.Reason; + targetEntity.QuestionId = sourceEntity.QuestionId; + targetEntity.SimpleCode = LanguageConverter.GetPYSimpleCode(sourceEntity.QuestionAnswerName); + + } + + + + /// + /// 删除 + /// + /// + /// + /// + public async Task CheckAndDeleteAsync(Guid QuestionAnswerId) + { + + //var questionEnt = await _questionRepository.FirstOrDefaultAsync(m => m.QuestionTypeId == QuestionTypeId); + //if (questionEnt != null) + //{ + // throw new UserFriendlyException($"问卷类别已被使用,不能删除"); + //} + + await _questionAnswerRepository.DeleteAsync(d => d.QuestionAnswerId == QuestionAnswerId); + + } + + + /// + /// 修改排序 置顶,置底 + /// + /// 需要修改的ID + /// 修改方式:1 置顶 2 置底 + /// + public async Task UpdateSortTopOrBottomAsync(Guid QuestionAnswerId, int SortType) + { + var entity = await _questionAnswerRepository.GetAsync(f => f.QuestionAnswerId == QuestionAnswerId); + await EntityHelper.UpdateSortTopOrBottomAsync(_questionAnswerRepository, entity, SortType); + } + + + + /// + /// 修改排序 拖拽 + /// + /// + /// + /// + /// + public async Task UpdateSortDragAsync(UpdateQuestionAnswerSortDragDto input) + { + var entitylist = await _questionAnswerRepository.GetListAsync(o => input.ItemList.Select(s => s.QuestionAnswerId).Contains(o.QuestionAnswerId)); + + foreach (var entity in entitylist) + { + foreach (var item in input.ItemList) + { + if (item.QuestionAnswerId == entity.QuestionAnswerId) + entity.DisplayOrder = item.DisplayOrder; + } + } + + await _questionAnswerRepository.UpdateManyAsync(entitylist); + } + + + /// + /// 自动生成pathcode + /// + /// + /// + public async Task CreatePathCode(Guid? parentId) + { + string PathCode = "00001"; + //一级 + if (parentId == null || parentId == Guid.Empty) + { + //最大pathcode + var LastPathCode = (await _questionAnswerRepository.GetListAsync(o => o.ParentId == Guid.Empty || o.ParentId == null)) + .OrderByDescending(o => + { + var sortCode = o.PathCode.Replace(".", ""); + return Convert.ToInt32(sortCode); + }).FirstOrDefault(); + if (LastPathCode != null) + { + PathCode = (Convert.ToInt32(LastPathCode.PathCode) + 1).ToString().PadLeft(5, '0'); + } + else + { + PathCode = "00001"; + } + } + else + { + //二级以及以上 + + + //上级pathcode + var ParentPathCode = (await _questionAnswerRepository.GetListAsync(o => o.QuestionAnswerId == parentId)).FirstOrDefault().PathCode; + + //最大pathcode + var LastPathCode = (await _questionAnswerRepository.GetListAsync(o => o.ParentId == parentId)) + .OrderByDescending(o => + { + var sortCode = o.PathCode.Replace(".", ""); + return Convert.ToInt32(sortCode); + }).Select(s => s.PathCode).FirstOrDefault(); + + if (!string.IsNullOrEmpty(LastPathCode)) + { + var MaxCode = LastPathCode.Split('.').Last(); + PathCode = ParentPathCode + "." + (Convert.ToInt32(MaxCode) + 1).ToString().PadLeft(5, '0'); + } + else + { + PathCode = ParentPathCode + ".00001"; + } + } + + return PathCode; + } + } +} diff --git a/src/Shentun.WebPeis.Domain/QuestionAnswers/UpdateQuestionAnswerSortDragDto.cs b/src/Shentun.WebPeis.Domain/QuestionAnswers/UpdateQuestionAnswerSortDragDto.cs new file mode 100644 index 0000000..ec9c18f --- /dev/null +++ b/src/Shentun.WebPeis.Domain/QuestionAnswers/UpdateQuestionAnswerSortDragDto.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Shentun.WebPeis.QuestionAnswers +{ + + public class UpdateQuestionAnswerSortDragDto + { + public List ItemList { get; set; } + } + + + public class UpdateQuestionAnswerSortDragDetail + { + public Guid QuestionAnswerId { get; set; } + public int DisplayOrder { get; set; } + } +} diff --git a/src/Shentun.WebPeis.Domain/QuestionAnswers/UpdateQuestionAnswerSortTopOrBottomInputDto.cs b/src/Shentun.WebPeis.Domain/QuestionAnswers/UpdateQuestionAnswerSortTopOrBottomInputDto.cs new file mode 100644 index 0000000..288babf --- /dev/null +++ b/src/Shentun.WebPeis.Domain/QuestionAnswers/UpdateQuestionAnswerSortTopOrBottomInputDto.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Shentun.WebPeis.QuestionAnswers +{ + public class UpdateQuestionAnswerSortTopOrBottomInputDto + { + public Guid QuestionAnswerId { get; set; } + + /// + /// 修改方式:1 置顶 2 置底 + /// + public int SortType { get; set; } + } +} diff --git a/src/Shentun.WebPeis.Domain/Questions/QuestionManager.cs b/src/Shentun.WebPeis.Domain/Questions/QuestionManager.cs index 2868f78..c0b7df1 100644 --- a/src/Shentun.WebPeis.Domain/Questions/QuestionManager.cs +++ b/src/Shentun.WebPeis.Domain/Questions/QuestionManager.cs @@ -69,7 +69,6 @@ namespace Shentun.WebPeis.Questions targetEntity.AnswerType = sourceEntity.AnswerType; targetEntity.IsActive = sourceEntity.IsActive; - targetEntity.ParentId = sourceEntity.ParentId; targetEntity.QuestionName = sourceEntity.QuestionName; targetEntity.QuestionSubjectTypeId = sourceEntity.QuestionSubjectTypeId; targetEntity.SimpleCode = LanguageConverter.GetPYSimpleCode(sourceEntity.QuestionName);