DESKTOP-G961P6V\Zhh 1 year ago
parent
commit
f6fd2bf8bd
  1. 19
      src/Shentun.WebPeis.Application.Contracts/QuestionTypes/CreateQuestionTypeDto.cs
  2. 23
      src/Shentun.WebPeis.Application.Contracts/QuestionTypes/QuestionTypeDto.cs
  3. 11
      src/Shentun.WebPeis.Application.Contracts/QuestionTypes/QuestionTypeIdInputDto.cs
  4. 19
      src/Shentun.WebPeis.Application.Contracts/QuestionTypes/UpdateQuestionTypeDto.cs
  5. 48
      src/Shentun.WebPeis.Application.Contracts/Questions/CreateQuestionDto.cs
  6. 55
      src/Shentun.WebPeis.Application.Contracts/Questions/QuestionDto.cs
  7. 11
      src/Shentun.WebPeis.Application.Contracts/Questions/QuestionIdInputDto.cs
  8. 58
      src/Shentun.WebPeis.Application.Contracts/Questions/QuestionTreeListDto.cs
  9. 47
      src/Shentun.WebPeis.Application.Contracts/Questions/UpdateQuestionDto.cs
  10. 135
      src/Shentun.WebPeis.Application/QuestionTypes/QuestionTypeAppService.cs
  11. 208
      src/Shentun.WebPeis.Application/Questions/QuestionAppService.cs
  12. 4
      src/Shentun.WebPeis.Domain/AppointScheduleTemplates/AppointScheduleTemplateManager.cs
  13. 4
      src/Shentun.WebPeis.Domain/EntityHelper.cs
  14. 16
      src/Shentun.WebPeis.Domain/Models/Question.cs
  15. 4
      src/Shentun.WebPeis.Domain/Models/QuestionType.cs
  16. 137
      src/Shentun.WebPeis.Domain/QuestionTypes/QuestionTypeManager.cs
  17. 17
      src/Shentun.WebPeis.Domain/QuestionTypes/UpdateQuestionTypeSortDragDto.cs
  18. 16
      src/Shentun.WebPeis.Domain/QuestionTypes/UpdateQuestionTypeSortTopOrBottomInputDto.cs
  19. 197
      src/Shentun.WebPeis.Domain/Questions/QuestionManager.cs
  20. 20
      src/Shentun.WebPeis.Domain/Questions/UpdateQuestionSortDragDto.cs
  21. 18
      src/Shentun.WebPeis.Domain/Questions/UpdateQuestionSortTopOrBottomInputDto.cs
  22. 2
      src/Shentun.WebPeis.HttpApi.Host/Shentun.WebPeis.HttpApi.Host.csproj

19
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
{
/// <summary>
/// 主键
/// </summary>
public string QuestionTypeId { get; set; }
/// <summary>
/// 名称
/// </summary>
public string QuestionTypeName { get; set; }
}
}

23
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
{
/// <summary>
/// 主键
/// </summary>
public string QuestionTypeId { get; set; }
/// <summary>
/// 名称
/// </summary>
public string QuestionTypeName { get; set; }
public string SimpleCode { get; set; }
public int DisplayOrder { get; set; }
}
}

11
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; }
}
}

19
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
{
/// <summary>
/// 主键
/// </summary>
public string QuestionTypeId { get; set; }
/// <summary>
/// 名称
/// </summary>
public string QuestionTypeName { get; set; }
}
}

48
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
{
/// <summary>
/// 主键
/// </summary>
public Guid QuestionId { get; set; }
/// <summary>
/// 题目
/// </summary>
public string QuestionName { get; set; } = null!;
/// <summary>
/// 问卷类别ID
/// </summary>
public string QuestionTypeId { get; set; }
/// <summary>
/// 答案类别 0-单选 1-多选
/// </summary>
public char? AnswerType { get; set; }
/// <summary>
/// 问卷题目类别 01-生育 ,02-不适症状,03-危险因素,04-所患疾病
/// </summary>
public string QuestionSubjectTypeId { get; set; }
/// <summary>
/// 启用
/// </summary>
public char? IsActive { get; set; }
/// <summary>
/// 父问卷ID
/// </summary>
public Guid? ParentId { get; set; }
}
}

55
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
{
/// <summary>
/// 主键
/// </summary>
public Guid QuestionId { get; set; }
/// <summary>
/// 题目
/// </summary>
public string QuestionName { get; set; } = null!;
/// <summary>
/// 问卷类别ID
/// </summary>
public string QuestionTypeId { get; set; }
/// <summary>
/// 答案类别 0-单选 1-多选
/// </summary>
public char? AnswerType { get; set; }
/// <summary>
/// 问卷题目类别 01-生育 ,02-不适症状,03-危险因素,04-所患疾病
/// </summary>
public string QuestionSubjectTypeId { get; set; }
/// <summary>
/// 启用
/// </summary>
public char? IsActive { get; set; }
/// <summary>
/// 父问卷ID
/// </summary>
public Guid? ParentId { get; set; }
/// <summary>
/// 编码路径
/// </summary>
public string? PathCode { get; set; }
public string SimpleCode { get; set; } = null!;
public int DisplayOrder { get; set; }
}
}

11
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; }
}
}

58
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
{
/// <summary>
/// 主键
/// </summary>
public Guid QuestionId { get; set; }
/// <summary>
/// 题目
/// </summary>
public string QuestionName { get; set; } = null!;
/// <summary>
/// 问卷类别ID
/// </summary>
public string QuestionTypeId { get; set; }
/// <summary>
/// 答案类别 0-单选 1-多选
/// </summary>
public char? AnswerType { get; set; }
/// <summary>
/// 问卷题目类别 01-生育 ,02-不适症状,03-危险因素,04-所患疾病
/// </summary>
public string QuestionSubjectTypeId { get; set; }
/// <summary>
/// 启用
/// </summary>
public char? IsActive { get; set; }
/// <summary>
/// 父问卷ID
/// </summary>
public Guid? ParentId { get; set; }
/// <summary>
/// 编码路径
/// </summary>
public string? PathCode { get; set; }
public string SimpleCode { get; set; } = null!;
public int DisplayOrder { get; set; }
public List<QuestionTreeListDto> TreeChildren { get; set; }
}
}

47
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
{
/// <summary>
/// 主键
/// </summary>
public Guid QuestionId { get; set; }
/// <summary>
/// 题目
/// </summary>
public string QuestionName { get; set; } = null!;
/// <summary>
/// 问卷类别ID
/// </summary>
public string QuestionTypeId { get; set; }
/// <summary>
/// 答案类别 0-单选 1-多选
/// </summary>
public char? AnswerType { get; set; }
/// <summary>
/// 问卷题目类别 01-生育 ,02-不适症状,03-危险因素,04-所患疾病
/// </summary>
public string QuestionSubjectTypeId { get; set; }
/// <summary>
/// 启用
/// </summary>
public char? IsActive { get; set; }
/// <summary>
/// 父问卷ID
/// </summary>
public Guid? ParentId { get; set; }
}
}

135
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
{
/// <summary>
/// 问卷类型
/// </summary>
[ApiExplorerSettings(GroupName = "Work")]
[Authorize]
public class QuestionTypeAppService : ApplicationService
{
private readonly IRepository<QuestionType> _questionTypeRepository;
private readonly QuestionTypeManager _questionTypeManager;
private readonly CacheService _cacheService;
public QuestionTypeAppService(
IRepository<QuestionType> questionTypeRepository,
QuestionTypeManager questionTypeManager,
CacheService cacheService)
{
_questionTypeRepository = questionTypeRepository;
_questionTypeManager = questionTypeManager;
_cacheService = cacheService;
}
/// <summary>
/// 获取列表
/// </summary>
/// <returns></returns>
[HttpPost("api/app/QuestionType/GetList")]
public async Task<List<QuestionTypeDto>> 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;
}
/// <summary>
/// 创建
/// </summary>
/// <returns></returns>
[HttpPost("api/app/QuestionType/Create")]
public async Task<QuestionTypeDto> CreateAsync(CreateQuestionTypeDto input)
{
var createEntity = ObjectMapper.Map<CreateQuestionTypeDto, QuestionType>(input);
var entity = await _questionTypeManager.CreateAsync(createEntity);
entity = await _questionTypeRepository.InsertAsync(entity);
var dto = ObjectMapper.Map<QuestionType, QuestionTypeDto>(entity);
dto.CreatorName = await _cacheService.GetSurnameAsync(dto.CreatorId);
dto.LastModifierName = await _cacheService.GetSurnameAsync(dto.LastModifierId);
return dto;
}
/// <summary>
/// 更新
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost("api/app/QuestionType/Update")]
public async Task<QuestionTypeDto> UpdateAsync(UpdateQuestionTypeDto input)
{
var entity = await _questionTypeRepository.GetAsync(f => f.QuestionTypeId == input.QuestionTypeId);
var sourceEntity = ObjectMapper.Map<UpdateQuestionTypeDto, QuestionType>(input);
await _questionTypeManager.UpdateAsync(sourceEntity, entity);
entity = await _questionTypeRepository.UpdateAsync(entity);
var dto = ObjectMapper.Map<QuestionType, QuestionTypeDto>(entity);
dto.CreatorName = await _cacheService.GetSurnameAsync(dto.CreatorId);
dto.LastModifierName = await _cacheService.GetSurnameAsync(dto.LastModifierId);
return dto;
}
/// <summary>
/// 删除
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost("api/app/QuestionType/Delete")]
public async Task DeleteAsync(QuestionTypeIdInputDto input)
{
await _questionTypeManager.CheckAndDeleteAsync(input.QuestionTypeId);
}
/// <summary>
/// 修改排序 置顶,置底
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost("api/app/QuestionType/UpdateSortTopOrBottom")]
public async Task UpdateSortTopOrBottomAsync(UpdateQuestionTypeSortTopOrBottomInputDto input)
{
await _questionTypeManager.UpdateSortTopOrBottomAsync(input.QuestionTypeId, input.SortType);
}
/// <summary>
/// 修改排序 拖拽
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost("api/app/QuestionType/UpdateSortDragAsync")]
public async Task UpdateSortDragAsync(UpdateQuestionTypeSortDragDto input)
{
await _questionTypeManager.UpdateSortDragAsync(input);
}
}
}

208
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
{
/// <summary>
/// 问卷
/// </summary>
[ApiExplorerSettings(GroupName = "Work")]
[Authorize]
public class QuestionAppService : ApplicationService
{
private readonly IRepository<Question> _questionRepository;
private readonly QuestionManager _questionManager;
private readonly CacheService _cacheService;
public QuestionAppService(
IRepository<Question> questionRepository,
QuestionManager questionManager,
CacheService cacheService)
{
_questionRepository = questionRepository;
_questionManager = questionManager;
_cacheService = cacheService;
}
///// <summary>
///// 获取列表
///// </summary>
///// <returns></returns>
//[HttpPost("api/app/Question/GetList")]
//public async Task<List<QuestionDto>> 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;
//}
/// <summary>
/// 获取问卷树型列表
/// </summary>
/// <returns></returns>
[HttpPost("api/app/Question/GetQuestionTreeList")]
public async Task<List<QuestionTreeListDto>> 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, "");
}
/// <summary>
/// 创建
/// </summary>
/// <returns></returns>
[HttpPost("api/app/Question/Create")]
public async Task<QuestionDto> CreateAsync(CreateQuestionDto input)
{
var createEntity = ObjectMapper.Map<CreateQuestionDto, Question>(input);
var entity = await _questionManager.CreateAsync(createEntity);
entity = await _questionRepository.InsertAsync(entity);
var dto = ObjectMapper.Map<Question, QuestionDto>(entity);
dto.CreatorName = await _cacheService.GetSurnameAsync(dto.CreatorId);
dto.LastModifierName = await _cacheService.GetSurnameAsync(dto.LastModifierId);
return dto;
}
/// <summary>
/// 更新
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost("api/app/Question/Update")]
public async Task<QuestionDto> UpdateAsync(UpdateQuestionDto input)
{
var entity = await _questionRepository.GetAsync(f => f.QuestionTypeId == input.QuestionTypeId);
var sourceEntity = ObjectMapper.Map<UpdateQuestionDto, Question>(input);
_questionManager.UpdateAsync(sourceEntity, entity);
entity = await _questionRepository.UpdateAsync(entity);
var dto = ObjectMapper.Map<Question, QuestionDto>(entity);
dto.CreatorName = await _cacheService.GetSurnameAsync(dto.CreatorId);
dto.LastModifierName = await _cacheService.GetSurnameAsync(dto.LastModifierId);
return dto;
}
/// <summary>
/// 删除
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost("api/app/Question/Delete")]
public async Task DeleteAsync(QuestionIdInputDto input)
{
await _questionManager.CheckAndDeleteAsync(input.QuestionId);
}
/// <summary>
/// 修改排序 置顶,置底
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost("api/app/Question/UpdateSortTopOrBottom")]
public async Task UpdateSortTopOrBottomAsync(UpdateQuestionSortTopOrBottomInputDto input)
{
await _questionManager.UpdateSortTopOrBottomAsync(input.QuestionId, input.SortType);
}
/// <summary>
/// 修改排序 拖拽
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost("api/app/Question/UpdateSortDragAsync")]
public async Task UpdateSortDragAsync(UpdateQuestionSortDragDto input)
{
await _questionManager.UpdateSortDragAsync(input);
}
/// <summary>
/// 使用Code进行递归
/// </summary>
/// <param name="items"></param>
/// <param name="deep"></param>
/// <param name="prefix"></param>
/// <returns></returns>
private List<QuestionTreeListDto> GetTree(List<QuestionTreeListDto> 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();
}
}
}

4
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);
}
}

4
src/Shentun.WebPeis.Domain/EntityHelper.cs

@ -34,7 +34,7 @@ namespace Shentun.WebPeis
/// <param name="SortType">修改方式:1 置顶 2 置底</param>
/// <param name="orderby">排序规则 0、升序 1、降序 (默认降序)</param>
/// <returns></returns>
public static async Task UpdateManySortAsync<TEntity>(IRepository<TEntity> repository, TEntity entity, int SortType)
public static async Task UpdateSortTopOrBottomAsync<TEntity>(IRepository<TEntity> repository, TEntity entity, int SortType)
where TEntity : class, IEntity, IDisplayOrder
{
@ -95,7 +95,7 @@ namespace Shentun.WebPeis
/// <param name="repository"></param>
/// <param name="input"></param>
/// <returns></returns>
public static async Task UpdateSortManyAsync<TEntity>(IRepository<TEntity> repository, List<TEntity> entitylist, UpdateSortManyDto input)
public static async Task UpdateSortDragAsync<TEntity>(IRepository<TEntity> repository, List<TEntity> entitylist, UpdateSortManyDto input)
where TEntity : class, IEntity, IDisplayOrder
{

16
src/Shentun.WebPeis.Domain/Models/Question.cs

@ -8,7 +8,7 @@ namespace Shentun.WebPeis.Models;
/// <summary>
/// 问卷
/// </summary>
public partial class Question : AuditedEntity, IHasConcurrencyStamp
public partial class Question : AuditedEntity, IHasConcurrencyStamp, IDisplayOrder
{
/// <summary>
/// 主键
@ -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; }
/// <summary>
/// 档案类别
/// 答案类别 0-单选 1-多选
/// </summary>
public char? AnswerType { get; set; }
/// <summary>
/// 问卷题目类别
/// 问卷题目类别 01-生育 ,02-不适症状,03-危险因素,04-所患疾病
/// </summary>
public string QuestionSubjectTypeId { get; set; }
@ -54,9 +51,10 @@ public partial class Question : AuditedEntity, IHasConcurrencyStamp
/// </summary>
public string? PathCode { get; set; }
/// <summary>
/// 问卷包含的项目
/// </summary>
public string SimpleCode { get; set; } = null!;
public int DisplayOrder { get; set; }
public string? ConcurrencyStamp { get; set; }
public virtual ICollection<QuestionRegisterItem> QuestionRegisterItems { get; set; } = new List<QuestionRegisterItem>();

4
src/Shentun.WebPeis.Domain/Models/QuestionType.cs

@ -8,7 +8,7 @@ namespace Shentun.WebPeis.Models;
/// <summary>
/// 问卷类别 01-小程序健康问卷
/// </summary>
public partial class QuestionType : AuditedEntity, IHasConcurrencyStamp
public partial class QuestionType : AuditedEntity, IHasConcurrencyStamp, IDisplayOrder
{
/// <summary>
/// 主键
@ -24,7 +24,7 @@ public partial class QuestionType : AuditedEntity, IHasConcurrencyStamp
public int DisplayOrder { get; set; }
public string? ConcurrencyStamp { get; set; }

137
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<QuestionType> _questionTypeRepository;
private readonly IRepository<Question> _questionRepository;
public QuestionTypeManager(
IRepository<QuestionType> questionTypeRepository,
IRepository<Question> questionRepository)
{
_questionTypeRepository = questionTypeRepository;
_questionRepository = questionRepository;
}
/// <summary>
/// 创建
/// </summary>
/// <returns></returns>
public async Task<QuestionType> 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<QuestionType>(_questionTypeRepository),
QuestionTypeId = entity.QuestionTypeId
};
}
/// <summary>
/// 更新
/// </summary>
/// <param name="sourceEntity"></param>
/// <param name="targetEntity"></param>
/// <returns></returns>
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);
}
}
/// <summary>
/// 删除
/// </summary>
/// <param name="QuestionTypeId"></param>
/// <returns></returns>
/// <exception cref="UserFriendlyException"></exception>
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);
}
/// <summary>
/// 修改排序 置顶,置底
/// </summary>
/// <param name="id">需要修改的ID</param>
/// <param name="SortType">修改方式:1 置顶 2 置底</param>
/// <returns></returns>
public async Task UpdateSortTopOrBottomAsync(string QuestionTypeId, int SortType)
{
var entity = await _questionTypeRepository.GetAsync(f => f.QuestionTypeId == QuestionTypeId);
await EntityHelper.UpdateSortTopOrBottomAsync(_questionTypeRepository, entity, SortType);
}
/// <summary>
/// 修改排序 拖拽
/// </summary>
/// <typeparam name="TEntity"></typeparam>
/// <param name="repository"></param>
/// <param name="input"></param>
/// <returns></returns>
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);
}
}
}

17
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<UpdateQuestionTypeSortDragDetail> ItemList { get; set; }
}
public class UpdateQuestionTypeSortDragDetail
{
public string QuestionTypeId { get; set; }
public int DisplayOrder { get; set; }
}
}

16
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; }
/// <summary>
/// 修改方式:1 置顶 2 置底
/// </summary>
public int SortType { get; set; }
}
}

197
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<Question> _questionRepository;
public QuestionManager(
IRepository<Question> questionRepository
)
{
_questionRepository = questionRepository;
}
/// <summary>
/// 创建
/// </summary>
/// <returns></returns>
public async Task<Question> 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<Question>(_questionRepository),
QuestionTypeId = entity.QuestionTypeId
};
}
/// <summary>
/// 更新
/// </summary>
/// <param name="sourceEntity"></param>
/// <param name="targetEntity"></param>
/// <returns></returns>
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;
}
/// <summary>
/// 删除
/// </summary>
/// <param name="QuestionId"></param>
/// <returns></returns>
/// <exception cref="UserFriendlyException"></exception>
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);
}
/// <summary>
/// 修改排序 置顶,置底
/// </summary>
/// <param name="id">需要修改的ID</param>
/// <param name="SortType">修改方式:1 置顶 2 置底</param>
/// <returns></returns>
public async Task UpdateSortTopOrBottomAsync(Guid QuestionId, int SortType)
{
var entity = await _questionRepository.GetAsync(f => f.QuestionId == QuestionId);
await EntityHelper.UpdateSortTopOrBottomAsync(_questionRepository, entity, SortType);
}
/// <summary>
/// 修改排序 拖拽
/// </summary>
/// <typeparam name="TEntity"></typeparam>
/// <param name="repository"></param>
/// <param name="input"></param>
/// <returns></returns>
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);
}
/// <summary>
/// 自动生成pathcode
/// </summary>
/// <param name="parentId"></param>
/// <returns></returns>
public async Task<string> 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;
}
}
}

20
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<UpdateQuestionSortDragDetail> ItemList { get; set; }
}
public class UpdateQuestionSortDragDetail
{
public Guid QuestionId { get; set; }
public int DisplayOrder { get; set; }
}
}

18
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; }
/// <summary>
/// 修改方式:1 置顶 2 置底
/// </summary>
public int SortType { get; set; }
}
}

2
src/Shentun.WebPeis.HttpApi.Host/Shentun.WebPeis.HttpApi.Host.csproj

@ -14,7 +14,7 @@
<PackageReference Include="Serilog.AspNetCore" Version="8.0.0" />
<PackageReference Include="Serilog.Sinks.Async" Version="1.5.0" />
<PackageReference Include="Serilog.Sinks.Postgresql.Alternative" Version="4.0.4" />
<PackageReference Include="Volo.Abp.AspNetCore.MultiTenancy" Version="8.1.3" />
<PackageReference Include="Volo.Abp.AspNetCore.MultiTenancy" Version="8.1.4" />
<PackageReference Include="Volo.Abp.Autofac" Version="8.1.3" />
<PackageReference Include="Volo.Abp.AspNetCore.Serilog" Version="8.1.3" />
<PackageReference Include="Volo.Abp.Swashbuckle" Version="8.1.3" />

Loading…
Cancel
Save