From 898e19f89fc42f2199f624d4c99989d25fd32b76 Mon Sep 17 00:00:00 2001 From: wxd <123@qq.com> Date: Fri, 14 Jun 2024 00:50:29 +0800 Subject: [PATCH] =?UTF-8?q?=E9=97=AE=E5=8D=B7=E7=B1=BB=E5=88=AB=EF=BC=8C?= =?UTF-8?q?=E9=97=AE=E5=8D=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../QuestionTypes/CreateQuestionTypeDto.cs | 19 ++ .../QuestionTypes/QuestionTypeDto.cs | 23 ++ .../QuestionTypes/QuestionTypeIdInputDto.cs | 11 + .../QuestionTypes/UpdateQuestionTypeDto.cs | 19 ++ .../Questions/CreateQuestionDto.cs | 48 ++++ .../Questions/QuestionDto.cs | 55 +++++ .../Questions/QuestionIdInputDto.cs | 11 + .../Questions/QuestionTreeListDto.cs | 58 +++++ .../Questions/UpdateQuestionDto.cs | 47 ++++ .../QuestionTypes/QuestionTypeAppService.cs | 135 ++++++++++++ .../Questions/QuestionAppService.cs | 208 ++++++++++++++++++ .../AppointScheduleTemplateManager.cs | 4 +- src/Shentun.WebPeis.Domain/EntityHelper.cs | 4 +- src/Shentun.WebPeis.Domain/Models/Question.cs | 16 +- .../Models/QuestionType.cs | 4 +- .../QuestionTypes/QuestionTypeManager.cs | 137 ++++++++++++ .../UpdateQuestionTypeSortDragDto.cs | 17 ++ ...dateQuestionTypeSortTopOrBottomInputDto.cs | 16 ++ .../Questions/QuestionManager.cs | 197 +++++++++++++++++ .../Questions/UpdateQuestionSortDragDto.cs | 20 ++ .../UpdateQuestionSortTopOrBottomInputDto.cs | 18 ++ .../Shentun.WebPeis.HttpApi.Host.csproj | 2 +- 22 files changed, 1053 insertions(+), 16 deletions(-) create mode 100644 src/Shentun.WebPeis.Application.Contracts/QuestionTypes/CreateQuestionTypeDto.cs create mode 100644 src/Shentun.WebPeis.Application.Contracts/QuestionTypes/QuestionTypeDto.cs create mode 100644 src/Shentun.WebPeis.Application.Contracts/QuestionTypes/QuestionTypeIdInputDto.cs create mode 100644 src/Shentun.WebPeis.Application.Contracts/QuestionTypes/UpdateQuestionTypeDto.cs create mode 100644 src/Shentun.WebPeis.Application.Contracts/Questions/CreateQuestionDto.cs create mode 100644 src/Shentun.WebPeis.Application.Contracts/Questions/QuestionDto.cs create mode 100644 src/Shentun.WebPeis.Application.Contracts/Questions/QuestionIdInputDto.cs create mode 100644 src/Shentun.WebPeis.Application.Contracts/Questions/QuestionTreeListDto.cs create mode 100644 src/Shentun.WebPeis.Application.Contracts/Questions/UpdateQuestionDto.cs create mode 100644 src/Shentun.WebPeis.Application/QuestionTypes/QuestionTypeAppService.cs create mode 100644 src/Shentun.WebPeis.Application/Questions/QuestionAppService.cs create mode 100644 src/Shentun.WebPeis.Domain/QuestionTypes/QuestionTypeManager.cs create mode 100644 src/Shentun.WebPeis.Domain/QuestionTypes/UpdateQuestionTypeSortDragDto.cs create mode 100644 src/Shentun.WebPeis.Domain/QuestionTypes/UpdateQuestionTypeSortTopOrBottomInputDto.cs create mode 100644 src/Shentun.WebPeis.Domain/Questions/QuestionManager.cs create mode 100644 src/Shentun.WebPeis.Domain/Questions/UpdateQuestionSortDragDto.cs create mode 100644 src/Shentun.WebPeis.Domain/Questions/UpdateQuestionSortTopOrBottomInputDto.cs diff --git a/src/Shentun.WebPeis.Application.Contracts/QuestionTypes/CreateQuestionTypeDto.cs b/src/Shentun.WebPeis.Application.Contracts/QuestionTypes/CreateQuestionTypeDto.cs new file mode 100644 index 0000000..8dcd9a8 --- /dev/null +++ b/src/Shentun.WebPeis.Application.Contracts/QuestionTypes/CreateQuestionTypeDto.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Shentun.WebPeis.QuestionTypes +{ + public class CreateQuestionTypeDto + { + /// + /// 主键 + /// + public string QuestionTypeId { get; set; } + /// + /// 名称 + /// + + public string QuestionTypeName { get; set; } + } +} diff --git a/src/Shentun.WebPeis.Application.Contracts/QuestionTypes/QuestionTypeDto.cs b/src/Shentun.WebPeis.Application.Contracts/QuestionTypes/QuestionTypeDto.cs new file mode 100644 index 0000000..b76eb5d --- /dev/null +++ b/src/Shentun.WebPeis.Application.Contracts/QuestionTypes/QuestionTypeDto.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Shentun.WebPeis.QuestionTypes +{ + public class QuestionTypeDto:AuditedEntityDtoName + { + /// + /// 主键 + /// + public string QuestionTypeId { get; set; } + /// + /// 名称 + /// + + public string QuestionTypeName { get; set; } + + public string SimpleCode { get; set; } + + public int DisplayOrder { get; set; } + } +} diff --git a/src/Shentun.WebPeis.Application.Contracts/QuestionTypes/QuestionTypeIdInputDto.cs b/src/Shentun.WebPeis.Application.Contracts/QuestionTypes/QuestionTypeIdInputDto.cs new file mode 100644 index 0000000..6c43f36 --- /dev/null +++ b/src/Shentun.WebPeis.Application.Contracts/QuestionTypes/QuestionTypeIdInputDto.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Shentun.WebPeis.QuestionTypes +{ + public class QuestionTypeIdInputDto + { + public string QuestionTypeId { get; set; } + } +} diff --git a/src/Shentun.WebPeis.Application.Contracts/QuestionTypes/UpdateQuestionTypeDto.cs b/src/Shentun.WebPeis.Application.Contracts/QuestionTypes/UpdateQuestionTypeDto.cs new file mode 100644 index 0000000..ea3f621 --- /dev/null +++ b/src/Shentun.WebPeis.Application.Contracts/QuestionTypes/UpdateQuestionTypeDto.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Shentun.WebPeis.QuestionTypes +{ + public class UpdateQuestionTypeDto + { + /// + /// 主键 + /// + public string QuestionTypeId { get; set; } + /// + /// 名称 + /// + + public string QuestionTypeName { get; set; } + } +} diff --git a/src/Shentun.WebPeis.Application.Contracts/Questions/CreateQuestionDto.cs b/src/Shentun.WebPeis.Application.Contracts/Questions/CreateQuestionDto.cs new file mode 100644 index 0000000..ec02167 --- /dev/null +++ b/src/Shentun.WebPeis.Application.Contracts/Questions/CreateQuestionDto.cs @@ -0,0 +1,48 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Shentun.WebPeis.Questions +{ + public class CreateQuestionDto + { + /// + /// 主键 + /// + public Guid QuestionId { get; set; } + /// + /// 题目 + /// + + public string QuestionName { get; set; } = null!; + /// + /// 问卷类别ID + /// + + public string QuestionTypeId { get; set; } + + + /// + /// 答案类别 0-单选 1-多选 + /// + + public char? AnswerType { get; set; } + /// + /// 问卷题目类别 01-生育 ,02-不适症状,03-危险因素,04-所患疾病 + /// + + public string QuestionSubjectTypeId { get; set; } + /// + /// 启用 + /// + + public char? IsActive { get; set; } + /// + /// 父问卷ID + /// + + public Guid? ParentId { get; set; } + + + } +} diff --git a/src/Shentun.WebPeis.Application.Contracts/Questions/QuestionDto.cs b/src/Shentun.WebPeis.Application.Contracts/Questions/QuestionDto.cs new file mode 100644 index 0000000..9cd1253 --- /dev/null +++ b/src/Shentun.WebPeis.Application.Contracts/Questions/QuestionDto.cs @@ -0,0 +1,55 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Shentun.WebPeis.Questions +{ + public class QuestionDto: AuditedEntityDtoName + { + /// + /// 主键 + /// + public Guid QuestionId { get; set; } + /// + /// 题目 + /// + + public string QuestionName { get; set; } = null!; + /// + /// 问卷类别ID + /// + + public string QuestionTypeId { get; set; } + + + /// + /// 答案类别 0-单选 1-多选 + /// + + public char? AnswerType { get; set; } + /// + /// 问卷题目类别 01-生育 ,02-不适症状,03-危险因素,04-所患疾病 + /// + + public string QuestionSubjectTypeId { get; set; } + /// + /// 启用 + /// + + public char? IsActive { get; set; } + /// + /// 父问卷ID + /// + + public Guid? ParentId { get; set; } + /// + /// 编码路径 + /// + + public string? PathCode { get; set; } + + public string SimpleCode { get; set; } = null!; + + public int DisplayOrder { get; set; } + } +} diff --git a/src/Shentun.WebPeis.Application.Contracts/Questions/QuestionIdInputDto.cs b/src/Shentun.WebPeis.Application.Contracts/Questions/QuestionIdInputDto.cs new file mode 100644 index 0000000..06a40a8 --- /dev/null +++ b/src/Shentun.WebPeis.Application.Contracts/Questions/QuestionIdInputDto.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Shentun.WebPeis.Questions +{ + public class QuestionIdInputDto + { + public Guid QuestionId { get; set; } + } +} diff --git a/src/Shentun.WebPeis.Application.Contracts/Questions/QuestionTreeListDto.cs b/src/Shentun.WebPeis.Application.Contracts/Questions/QuestionTreeListDto.cs new file mode 100644 index 0000000..1e762fa --- /dev/null +++ b/src/Shentun.WebPeis.Application.Contracts/Questions/QuestionTreeListDto.cs @@ -0,0 +1,58 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Shentun.WebPeis.Questions +{ + public class QuestionTreeListDto : AuditedEntityDtoName + { + /// + /// 主键 + /// + public Guid QuestionId { get; set; } + /// + /// 题目 + /// + + public string QuestionName { get; set; } = null!; + /// + /// 问卷类别ID + /// + + public string QuestionTypeId { get; set; } + + + /// + /// 答案类别 0-单选 1-多选 + /// + + public char? AnswerType { get; set; } + /// + /// 问卷题目类别 01-生育 ,02-不适症状,03-危险因素,04-所患疾病 + /// + + public string QuestionSubjectTypeId { get; set; } + /// + /// 启用 + /// + + public char? IsActive { get; set; } + /// + /// 父问卷ID + /// + + public Guid? ParentId { get; set; } + /// + /// 编码路径 + /// + + public string? PathCode { 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/Questions/UpdateQuestionDto.cs b/src/Shentun.WebPeis.Application.Contracts/Questions/UpdateQuestionDto.cs new file mode 100644 index 0000000..fada274 --- /dev/null +++ b/src/Shentun.WebPeis.Application.Contracts/Questions/UpdateQuestionDto.cs @@ -0,0 +1,47 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Shentun.WebPeis.Questions +{ + public class UpdateQuestionDto + { + /// + /// 主键 + /// + public Guid QuestionId { get; set; } + /// + /// 题目 + /// + + public string QuestionName { get; set; } = null!; + /// + /// 问卷类别ID + /// + + public string QuestionTypeId { get; set; } + + + /// + /// 答案类别 0-单选 1-多选 + /// + + public char? AnswerType { get; set; } + /// + /// 问卷题目类别 01-生育 ,02-不适症状,03-危险因素,04-所患疾病 + /// + + public string QuestionSubjectTypeId { get; set; } + /// + /// 启用 + /// + + public char? IsActive { get; set; } + /// + /// 父问卷ID + /// + + public Guid? ParentId { get; set; } + + } +} diff --git a/src/Shentun.WebPeis.Application/QuestionTypes/QuestionTypeAppService.cs b/src/Shentun.WebPeis.Application/QuestionTypes/QuestionTypeAppService.cs new file mode 100644 index 0000000..0d6ca4e --- /dev/null +++ b/src/Shentun.WebPeis.Application/QuestionTypes/QuestionTypeAppService.cs @@ -0,0 +1,135 @@ +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; +using Shentun.WebPeis.AppointScheduleTemplates; +using Shentun.WebPeis.Models; +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.QuestionTypes +{ + /// + /// 问卷类型 + /// + [ApiExplorerSettings(GroupName = "Work")] + [Authorize] + public class QuestionTypeAppService : ApplicationService + { + + private readonly IRepository _questionTypeRepository; + private readonly QuestionTypeManager _questionTypeManager; + private readonly CacheService _cacheService; + + public QuestionTypeAppService( + IRepository questionTypeRepository, + QuestionTypeManager questionTypeManager, + CacheService cacheService) + { + _questionTypeRepository = questionTypeRepository; + _questionTypeManager = questionTypeManager; + _cacheService = cacheService; + } + + + + /// + /// 获取列表 + /// + /// + [HttpPost("api/app/QuestionType/GetList")] + public async Task> GetListAsync() + { + var entlist = await _questionTypeRepository.GetQueryableAsync(); + + var entdto = entlist.Select(s => new QuestionTypeDto + { + CreationTime = s.CreationTime, + CreatorId = s.CreatorId, + DisplayOrder = s.DisplayOrder, + LastModificationTime = s.LastModificationTime, + LastModifierId = s.LastModifierId, + SimpleCode = s.SimpleCode, + QuestionTypeId = s.QuestionTypeId, + QuestionTypeName = s.QuestionTypeName, + CreatorName = _cacheService.GetSurnameAsync(s.CreatorId).Result, + LastModifierName = _cacheService.GetSurnameAsync(s.LastModifierId).Result + }).OrderBy(o => o.DisplayOrder).ToList(); + + return entdto; + + + } + + /// + /// 创建 + /// + /// + [HttpPost("api/app/QuestionType/Create")] + public async Task CreateAsync(CreateQuestionTypeDto input) + { + var createEntity = ObjectMapper.Map(input); + var entity = await _questionTypeManager.CreateAsync(createEntity); + entity = await _questionTypeRepository.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/QuestionType/Update")] + public async Task UpdateAsync(UpdateQuestionTypeDto input) + { + var entity = await _questionTypeRepository.GetAsync(f => f.QuestionTypeId == input.QuestionTypeId); + var sourceEntity = ObjectMapper.Map(input); + await _questionTypeManager.UpdateAsync(sourceEntity, entity); + entity = await _questionTypeRepository.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/QuestionType/Delete")] + public async Task DeleteAsync(QuestionTypeIdInputDto input) + { + await _questionTypeManager.CheckAndDeleteAsync(input.QuestionTypeId); + } + + /// + /// 修改排序 置顶,置底 + /// + /// + /// + [HttpPost("api/app/QuestionType/UpdateSortTopOrBottom")] + public async Task UpdateSortTopOrBottomAsync(UpdateQuestionTypeSortTopOrBottomInputDto input) + { + await _questionTypeManager.UpdateSortTopOrBottomAsync(input.QuestionTypeId, input.SortType); + } + + /// + /// 修改排序 拖拽 + /// + /// + /// + [HttpPost("api/app/QuestionType/UpdateSortDragAsync")] + public async Task UpdateSortDragAsync(UpdateQuestionTypeSortDragDto input) + { + await _questionTypeManager.UpdateSortDragAsync(input); + } + + } +} diff --git a/src/Shentun.WebPeis.Application/Questions/QuestionAppService.cs b/src/Shentun.WebPeis.Application/Questions/QuestionAppService.cs new file mode 100644 index 0000000..bcbe74d --- /dev/null +++ b/src/Shentun.WebPeis.Application/Questions/QuestionAppService.cs @@ -0,0 +1,208 @@ +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; +using Shentun.WebPeis.Models; +using Shentun.WebPeis.QuestionTypes; +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.Questions +{ + /// + /// 问卷 + /// + [ApiExplorerSettings(GroupName = "Work")] + [Authorize] + public class QuestionAppService : ApplicationService + { + + private readonly IRepository _questionRepository; + private readonly QuestionManager _questionManager; + private readonly CacheService _cacheService; + + public QuestionAppService( + IRepository questionRepository, + QuestionManager questionManager, + CacheService cacheService) + { + _questionRepository = questionRepository; + _questionManager = questionManager; + _cacheService = cacheService; + } + + ///// + ///// 获取列表 + ///// + ///// + //[HttpPost("api/app/Question/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; + + + //} + + + /// + /// 获取问卷树型列表 + /// + /// + [HttpPost("api/app/Question/GetQuestionTreeList")] + public async Task> GetQuestionTreeListAsync() + { + var dataList = await _questionRepository.GetListAsync(); + var items = from p in dataList.OrderBy(o => o.DisplayOrder) + select new QuestionTreeListDto() + { + ParentId = p.ParentId, + AnswerType = p.AnswerType, + QuestionId = p.QuestionId, + CreationTime = p.CreationTime, + CreatorId = p.CreatorId, + CreatorName = _cacheService.GetSurnameAsync(p.CreatorId).Result, + IsActive = p.IsActive, + LastModificationTime = p.LastModificationTime, + LastModifierId = p.LastModifierId, + LastModifierName = _cacheService.GetSurnameAsync(p.LastModifierId).Result, + PathCode = p.PathCode, + QuestionName = p.QuestionName, + QuestionSubjectTypeId = p.QuestionSubjectTypeId, + QuestionTypeId = p.QuestionTypeId, + SimpleCode = p.SimpleCode, + DisplayOrder = p.DisplayOrder + }; + return GetTree(items.ToList(), 0, ""); + } + + + + /// + /// 创建 + /// + /// + [HttpPost("api/app/Question/Create")] + public async Task CreateAsync(CreateQuestionDto input) + { + var createEntity = ObjectMapper.Map(input); + var entity = await _questionManager.CreateAsync(createEntity); + entity = await _questionRepository.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/Question/Update")] + public async Task UpdateAsync(UpdateQuestionDto input) + { + var entity = await _questionRepository.GetAsync(f => f.QuestionTypeId == input.QuestionTypeId); + var sourceEntity = ObjectMapper.Map(input); + _questionManager.UpdateAsync(sourceEntity, entity); + entity = await _questionRepository.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/Question/Delete")] + public async Task DeleteAsync(QuestionIdInputDto input) + { + await _questionManager.CheckAndDeleteAsync(input.QuestionId); + } + + /// + /// 修改排序 置顶,置底 + /// + /// + /// + [HttpPost("api/app/Question/UpdateSortTopOrBottom")] + public async Task UpdateSortTopOrBottomAsync(UpdateQuestionSortTopOrBottomInputDto input) + { + await _questionManager.UpdateSortTopOrBottomAsync(input.QuestionId, input.SortType); + } + + /// + /// 修改排序 拖拽 + /// + /// + /// + [HttpPost("api/app/Question/UpdateSortDragAsync")] + public async Task UpdateSortDragAsync(UpdateQuestionSortDragDto input) + { + await _questionManager.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 QuestionTreeListDto() + { + ParentId = p.ParentId, + AnswerType = p.AnswerType, + QuestionId = p.QuestionId, + CreationTime = p.CreationTime, + CreatorId = p.CreatorId, + CreatorName = _cacheService.GetSurnameAsync(p.CreatorId).Result, + IsActive = p.IsActive, + LastModificationTime = p.LastModificationTime, + LastModifierId = p.LastModifierId, + LastModifierName = _cacheService.GetSurnameAsync(p.LastModifierId).Result, + PathCode = p.PathCode, + QuestionName = p.QuestionName, + QuestionSubjectTypeId = p.QuestionSubjectTypeId, + QuestionTypeId = p.QuestionTypeId, + SimpleCode = p.SimpleCode, + DisplayOrder = p.DisplayOrder, + TreeChildren = subs.ToList() + } + ).ToList(); + } + } +} diff --git a/src/Shentun.WebPeis.Domain/AppointScheduleTemplates/AppointScheduleTemplateManager.cs b/src/Shentun.WebPeis.Domain/AppointScheduleTemplates/AppointScheduleTemplateManager.cs index aa81830..dcaf3db 100644 --- a/src/Shentun.WebPeis.Domain/AppointScheduleTemplates/AppointScheduleTemplateManager.cs +++ b/src/Shentun.WebPeis.Domain/AppointScheduleTemplates/AppointScheduleTemplateManager.cs @@ -104,7 +104,7 @@ namespace Shentun.WebPeis.AppointScheduleTemplates public async Task UpdateManySortAsync(Guid appointScheduleTemplateId, int SortType) { var entity = await _appointScheduleTemplateRepository.GetAsync(f => f.AppointScheduleTemplateId == appointScheduleTemplateId); - await EntityHelper.UpdateManySortAsync(_appointScheduleTemplateRepository, entity, SortType); + await EntityHelper.UpdateSortTopOrBottomAsync(_appointScheduleTemplateRepository, entity, SortType); } @@ -121,7 +121,7 @@ namespace Shentun.WebPeis.AppointScheduleTemplates var entitylist = await _appointScheduleTemplateRepository.GetListAsync(o => input.ItemList.Select(s => s.Id).Contains(o.AppointScheduleTemplateId)); - await EntityHelper.UpdateSortManyAsync(_appointScheduleTemplateRepository, entitylist, input); + await EntityHelper.UpdateSortDragAsync(_appointScheduleTemplateRepository, entitylist, input); } } diff --git a/src/Shentun.WebPeis.Domain/EntityHelper.cs b/src/Shentun.WebPeis.Domain/EntityHelper.cs index 9c9ccad..74a6f2c 100644 --- a/src/Shentun.WebPeis.Domain/EntityHelper.cs +++ b/src/Shentun.WebPeis.Domain/EntityHelper.cs @@ -34,7 +34,7 @@ namespace Shentun.WebPeis /// 修改方式:1 置顶 2 置底 /// 排序规则 0、升序 1、降序 (默认降序) /// - public static async Task UpdateManySortAsync(IRepository repository, TEntity entity, int SortType) + public static async Task UpdateSortTopOrBottomAsync(IRepository repository, TEntity entity, int SortType) where TEntity : class, IEntity, IDisplayOrder { @@ -95,7 +95,7 @@ namespace Shentun.WebPeis /// /// /// - public static async Task UpdateSortManyAsync(IRepository repository, List entitylist, UpdateSortManyDto input) + public static async Task UpdateSortDragAsync(IRepository repository, List entitylist, UpdateSortManyDto input) where TEntity : class, IEntity, IDisplayOrder { diff --git a/src/Shentun.WebPeis.Domain/Models/Question.cs b/src/Shentun.WebPeis.Domain/Models/Question.cs index 3031fa5..dafb1ba 100644 --- a/src/Shentun.WebPeis.Domain/Models/Question.cs +++ b/src/Shentun.WebPeis.Domain/Models/Question.cs @@ -8,7 +8,7 @@ namespace Shentun.WebPeis.Models; /// /// 问卷 /// -public partial class Question : AuditedEntity, IHasConcurrencyStamp +public partial class Question : AuditedEntity, IHasConcurrencyStamp, IDisplayOrder { /// /// 主键 @@ -25,17 +25,14 @@ public partial class Question : AuditedEntity, IHasConcurrencyStamp public string QuestionTypeId { get; set; } - public string SimpleCode { get; set; } = null!; - - public int DisplayOrder { get; set; } /// - /// 档案类别 + /// 答案类别 0-单选 1-多选 /// public char? AnswerType { get; set; } /// - /// 问卷题目类别 + /// 问卷题目类别 01-生育 ,02-不适症状,03-危险因素,04-所患疾病 /// public string QuestionSubjectTypeId { get; set; } @@ -54,9 +51,10 @@ public partial class Question : AuditedEntity, IHasConcurrencyStamp /// public string? PathCode { get; set; } - /// - /// 问卷包含的项目 - /// + + public string SimpleCode { get; set; } = null!; + + public int DisplayOrder { get; set; } public string? ConcurrencyStamp { get; set; } public virtual ICollection QuestionRegisterItems { get; set; } = new List(); diff --git a/src/Shentun.WebPeis.Domain/Models/QuestionType.cs b/src/Shentun.WebPeis.Domain/Models/QuestionType.cs index 8fa21bd..884ecd9 100644 --- a/src/Shentun.WebPeis.Domain/Models/QuestionType.cs +++ b/src/Shentun.WebPeis.Domain/Models/QuestionType.cs @@ -8,7 +8,7 @@ namespace Shentun.WebPeis.Models; /// /// 问卷类别 01-小程序健康问卷 /// -public partial class QuestionType : AuditedEntity, IHasConcurrencyStamp +public partial class QuestionType : AuditedEntity, IHasConcurrencyStamp, IDisplayOrder { /// /// 主键 @@ -24,7 +24,7 @@ public partial class QuestionType : AuditedEntity, IHasConcurrencyStamp public int DisplayOrder { get; set; } - + public string? ConcurrencyStamp { get; set; } diff --git a/src/Shentun.WebPeis.Domain/QuestionTypes/QuestionTypeManager.cs b/src/Shentun.WebPeis.Domain/QuestionTypes/QuestionTypeManager.cs new file mode 100644 index 0000000..1822a17 --- /dev/null +++ b/src/Shentun.WebPeis.Domain/QuestionTypes/QuestionTypeManager.cs @@ -0,0 +1,137 @@ +using NPOI.SS.Formula.Functions; +using Shentun.Utilities; +using Shentun.WebPeis.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Volo.Abp; +using Volo.Abp.Domain.Entities; +using Volo.Abp.Domain.Repositories; +using Volo.Abp.Domain.Services; + +namespace Shentun.WebPeis.QuestionTypes +{ + public class QuestionTypeManager : DomainService + { + private readonly IRepository _questionTypeRepository; + private readonly IRepository _questionRepository; + + public QuestionTypeManager( + IRepository questionTypeRepository, + IRepository questionRepository) + { + _questionTypeRepository = questionTypeRepository; + _questionRepository = questionRepository; + } + + /// + /// 创建 + /// + /// + public async Task CreateAsync(QuestionType entity) + { + DataHelper.CheckEntityIsNull(entity); + DataHelper.CheckStringIsNull(entity.QuestionTypeName, "名称"); + + var isQuestionType = await _questionTypeRepository.FirstOrDefaultAsync(f => f.QuestionTypeName == entity.QuestionTypeName); + if (isQuestionType != null) + throw new UserFriendlyException($"问卷类别{entity.QuestionTypeName}已存在"); + return new QuestionType + { + QuestionTypeName = entity.QuestionTypeName, + SimpleCode = LanguageConverter.GetPYSimpleCode(entity.QuestionTypeName), + DisplayOrder = await EntityHelper.CreateMaxDisplayOrder(_questionTypeRepository), + QuestionTypeId = entity.QuestionTypeId + }; + } + + + /// + /// 更新 + /// + /// + /// + /// + public async Task UpdateAsync( + QuestionType sourceEntity, + QuestionType targetEntity + ) + { + DataHelper.CheckEntityIsNull(sourceEntity); + DataHelper.CheckEntityIsNull(targetEntity); + DataHelper.CheckStringIsNull(sourceEntity.QuestionTypeName, "名称"); + if (sourceEntity.QuestionTypeName != targetEntity.QuestionTypeName) + { + var isQuestionType = await _questionTypeRepository.FirstOrDefaultAsync(f => f.QuestionTypeId != sourceEntity.QuestionTypeId + && f.QuestionTypeName == sourceEntity.QuestionTypeName); + if (isQuestionType != null) + throw new UserFriendlyException($"问卷类别{sourceEntity.QuestionTypeName}已存在"); + targetEntity.QuestionTypeName = sourceEntity.QuestionTypeName; + targetEntity.SimpleCode = LanguageConverter.GetPYSimpleCode(targetEntity.QuestionTypeName); + + } + + } + + + + /// + /// 删除 + /// + /// + /// + /// + public async Task CheckAndDeleteAsync(string QuestionTypeId) + { + + var questionEnt = await _questionRepository.FirstOrDefaultAsync(m => m.QuestionTypeId == QuestionTypeId); + if (questionEnt != null) + { + throw new UserFriendlyException($"问卷类别已被使用,不能删除"); + } + + await _questionTypeRepository.DeleteAsync(d => d.QuestionTypeId == QuestionTypeId); + + } + + + /// + /// 修改排序 置顶,置底 + /// + /// 需要修改的ID + /// 修改方式:1 置顶 2 置底 + /// + public async Task UpdateSortTopOrBottomAsync(string QuestionTypeId, int SortType) + { + var entity = await _questionTypeRepository.GetAsync(f => f.QuestionTypeId == QuestionTypeId); + await EntityHelper.UpdateSortTopOrBottomAsync(_questionTypeRepository, entity, SortType); + } + + + + /// + /// 修改排序 拖拽 + /// + /// + /// + /// + /// + public async Task UpdateSortDragAsync(UpdateQuestionTypeSortDragDto input) + { + var entitylist = await _questionTypeRepository.GetListAsync(o => input.ItemList.Select(s => s.QuestionTypeId).Contains(o.QuestionTypeId)); + + foreach (var entity in entitylist) + { + foreach (var item in input.ItemList) + { + if (item.QuestionTypeId == entity.QuestionTypeId) + entity.DisplayOrder = item.DisplayOrder; + } + } + + await _questionTypeRepository.UpdateManyAsync(entitylist); + } + } +} diff --git a/src/Shentun.WebPeis.Domain/QuestionTypes/UpdateQuestionTypeSortDragDto.cs b/src/Shentun.WebPeis.Domain/QuestionTypes/UpdateQuestionTypeSortDragDto.cs new file mode 100644 index 0000000..bfff6b5 --- /dev/null +++ b/src/Shentun.WebPeis.Domain/QuestionTypes/UpdateQuestionTypeSortDragDto.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Shentun.WebPeis.QuestionTypes +{ + public class UpdateQuestionTypeSortDragDto + { + public List ItemList { get; set; } + } + + public class UpdateQuestionTypeSortDragDetail + { + public string QuestionTypeId { get; set; } + public int DisplayOrder { get; set; } + } +} diff --git a/src/Shentun.WebPeis.Domain/QuestionTypes/UpdateQuestionTypeSortTopOrBottomInputDto.cs b/src/Shentun.WebPeis.Domain/QuestionTypes/UpdateQuestionTypeSortTopOrBottomInputDto.cs new file mode 100644 index 0000000..8edce5e --- /dev/null +++ b/src/Shentun.WebPeis.Domain/QuestionTypes/UpdateQuestionTypeSortTopOrBottomInputDto.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Shentun.WebPeis.QuestionTypes +{ + public class UpdateQuestionTypeSortTopOrBottomInputDto + { + public string QuestionTypeId { 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 new file mode 100644 index 0000000..2868f78 --- /dev/null +++ b/src/Shentun.WebPeis.Domain/Questions/QuestionManager.cs @@ -0,0 +1,197 @@ +using NPOI.POIFS.Properties; +using Shentun.Utilities; +using Shentun.WebPeis.Models; +using Shentun.WebPeis.QuestionTypes; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Volo.Abp; +using Volo.Abp.Domain.Entities; +using Volo.Abp.Domain.Repositories; +using Volo.Abp.Domain.Services; + +namespace Shentun.WebPeis.Questions +{ + public class QuestionManager : DomainService + { + + private readonly IRepository _questionRepository; + + public QuestionManager( + IRepository questionRepository + ) + { + _questionRepository = questionRepository; + } + + /// + /// 创建 + /// + /// + public async Task CreateAsync(Question entity) + { + DataHelper.CheckEntityIsNull(entity); + //DataHelper.CheckStringIsNull(entity.QuestionTypeName, "名称"); + + return new Question + { + AnswerType = entity.AnswerType, + IsActive = entity.IsActive, + ParentId = entity.ParentId, + PathCode = await CreatePathCode(entity.ParentId), + QuestionId = entity.QuestionId, + QuestionName = entity.QuestionName, + QuestionSubjectTypeId = entity.QuestionSubjectTypeId, + SimpleCode = LanguageConverter.GetPYSimpleCode(entity.QuestionName), + DisplayOrder = await EntityHelper.CreateMaxDisplayOrder(_questionRepository), + QuestionTypeId = entity.QuestionTypeId + }; + } + + + /// + /// 更新 + /// + /// + /// + /// + public void UpdateAsync( + Question sourceEntity, + Question targetEntity + ) + { + DataHelper.CheckEntityIsNull(sourceEntity); + DataHelper.CheckEntityIsNull(targetEntity); + //DataHelper.CheckStringIsNull(sourceEntity.QuestionTypeName, "名称"); + + + 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); + targetEntity.QuestionTypeId = sourceEntity.QuestionTypeId; + + } + + + + /// + /// 删除 + /// + /// + /// + /// + public async Task CheckAndDeleteAsync(Guid QuestionId) + { + + //var questionEnt = await _questionRepository.FirstOrDefaultAsync(m => m.QuestionTypeId == QuestionTypeId); + //if (questionEnt != null) + //{ + // throw new UserFriendlyException($"问卷类别已被使用,不能删除"); + //} + + await _questionRepository.DeleteAsync(d => d.QuestionId == QuestionId); + + } + + + /// + /// 修改排序 置顶,置底 + /// + /// 需要修改的ID + /// 修改方式:1 置顶 2 置底 + /// + public async Task UpdateSortTopOrBottomAsync(Guid QuestionId, int SortType) + { + var entity = await _questionRepository.GetAsync(f => f.QuestionId == QuestionId); + await EntityHelper.UpdateSortTopOrBottomAsync(_questionRepository, entity, SortType); + } + + + + /// + /// 修改排序 拖拽 + /// + /// + /// + /// + /// + public async Task UpdateSortDragAsync(UpdateQuestionSortDragDto input) + { + var entitylist = await _questionRepository.GetListAsync(o => input.ItemList.Select(s => s.QuestionId).Contains(o.QuestionId)); + + foreach (var entity in entitylist) + { + foreach (var item in input.ItemList) + { + if (item.QuestionId == entity.QuestionId) + entity.DisplayOrder = item.DisplayOrder; + } + } + + await _questionRepository.UpdateManyAsync(entitylist); + } + + + /// + /// 自动生成pathcode + /// + /// + /// + public async Task CreatePathCode(Guid? parentId) + { + string PathCode = "00001"; + //一级 + if (parentId == null || parentId == Guid.Empty) + { + //最大pathcode + var LastPathCode = (await _questionRepository.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 _questionRepository.GetListAsync(o => o.QuestionId == parentId)).FirstOrDefault().PathCode; + + //最大pathcode + var LastPathCode = (await _questionRepository.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/Questions/UpdateQuestionSortDragDto.cs b/src/Shentun.WebPeis.Domain/Questions/UpdateQuestionSortDragDto.cs new file mode 100644 index 0000000..98868b7 --- /dev/null +++ b/src/Shentun.WebPeis.Domain/Questions/UpdateQuestionSortDragDto.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Shentun.WebPeis.Questions +{ + public class UpdateQuestionSortDragDto + { + public List ItemList { get; set; } + } + + + public class UpdateQuestionSortDragDetail + { + public Guid QuestionId { get; set; } + public int DisplayOrder { get; set; } + } +} diff --git a/src/Shentun.WebPeis.Domain/Questions/UpdateQuestionSortTopOrBottomInputDto.cs b/src/Shentun.WebPeis.Domain/Questions/UpdateQuestionSortTopOrBottomInputDto.cs new file mode 100644 index 0000000..be12f3c --- /dev/null +++ b/src/Shentun.WebPeis.Domain/Questions/UpdateQuestionSortTopOrBottomInputDto.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Shentun.WebPeis.Questions +{ + public class UpdateQuestionSortTopOrBottomInputDto + { + public Guid QuestionId { get; set; } + + /// + /// 修改方式:1 置顶 2 置底 + /// + public int SortType { get; set; } + } +} diff --git a/src/Shentun.WebPeis.HttpApi.Host/Shentun.WebPeis.HttpApi.Host.csproj b/src/Shentun.WebPeis.HttpApi.Host/Shentun.WebPeis.HttpApi.Host.csproj index 8240897..b0a0f12 100644 --- a/src/Shentun.WebPeis.HttpApi.Host/Shentun.WebPeis.HttpApi.Host.csproj +++ b/src/Shentun.WebPeis.HttpApi.Host/Shentun.WebPeis.HttpApi.Host.csproj @@ -14,7 +14,7 @@ - +