18 changed files with 815 additions and 18 deletions
-
71src/Shentun.WebPeis.Application.Contracts/QuestionAnswers/CreateQuestionAnswerDto.cs
-
80src/Shentun.WebPeis.Application.Contracts/QuestionAnswers/QuestionAnswerDto.cs
-
11src/Shentun.WebPeis.Application.Contracts/QuestionAnswers/QuestionAnswerIdInputDto.cs
-
82src/Shentun.WebPeis.Application.Contracts/QuestionAnswers/QuestionAnswerTreeListDto.cs
-
68src/Shentun.WebPeis.Application.Contracts/QuestionAnswers/UpdateQuestionAnswerDto.cs
-
5src/Shentun.WebPeis.Application.Contracts/Questions/CreateQuestionDto.cs
-
4src/Shentun.WebPeis.Application.Contracts/Questions/UpdateQuestionDto.cs
-
223src/Shentun.WebPeis.Application/QuestionAnswers/QuestionAnswerAppService.cs
-
1src/Shentun.WebPeis.Application/Questions/QuestionAppService.cs
-
17src/Shentun.WebPeis.Application/WebPeisApplicationAutoMapperProfile.cs
-
2src/Shentun.WebPeis.Domain/Models/AsbitemRecommendLevel.cs
-
2src/Shentun.WebPeis.Domain/Models/DiseaseRisk.cs
-
2src/Shentun.WebPeis.Domain/Models/DiseaseRiskLevel.cs
-
11src/Shentun.WebPeis.Domain/Models/QuestionAnswer.cs
-
208src/Shentun.WebPeis.Domain/QuestionAnswers/QuestionAnswerManager.cs
-
21src/Shentun.WebPeis.Domain/QuestionAnswers/UpdateQuestionAnswerSortDragDto.cs
-
18src/Shentun.WebPeis.Domain/QuestionAnswers/UpdateQuestionAnswerSortTopOrBottomInputDto.cs
-
1src/Shentun.WebPeis.Domain/Questions/QuestionManager.cs
@ -0,0 +1,71 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Text; |
||||
|
|
||||
|
namespace Shentun.WebPeis.QuestionAnswers |
||||
|
{ |
||||
|
public class CreateQuestionAnswerDto |
||||
|
{ |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 答案
|
||||
|
/// </summary>
|
||||
|
|
||||
|
public string QuestionAnswerName { get; set; } = null!; |
||||
|
/// <summary>
|
||||
|
/// 问卷ID
|
||||
|
/// </summary>
|
||||
|
|
||||
|
public Guid QuestionId { get; set; } |
||||
|
|
||||
|
|
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 子答案类别
|
||||
|
/// </summary>
|
||||
|
|
||||
|
public char? ChildAnswerType { get; set; } |
||||
|
/// <summary>
|
||||
|
/// 答案结果类别
|
||||
|
/// </summary>
|
||||
|
|
||||
|
public char? AnswerResultType { get; set; } |
||||
|
/// <summary>
|
||||
|
/// 别名
|
||||
|
/// </summary>
|
||||
|
|
||||
|
public string? Aliases { get; set; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 概述
|
||||
|
/// </summary>
|
||||
|
|
||||
|
public string? Overview { get; set; } |
||||
|
/// <summary>
|
||||
|
/// 可能原因
|
||||
|
/// </summary>
|
||||
|
public string? Reason { get; set; } |
||||
|
/// <summary>
|
||||
|
/// 健康指导
|
||||
|
/// </summary>
|
||||
|
public string? HealthGuidance { get; set; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 父答案ID
|
||||
|
/// </summary>
|
||||
|
|
||||
|
public Guid? ParentId { get; set; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 子答案标题
|
||||
|
/// </summary>
|
||||
|
public string? ChildAnswerTitle { get; set; } |
||||
|
/// <summary>
|
||||
|
/// 无,和其它答案排斥
|
||||
|
/// </summary>
|
||||
|
public char IsNone { get; set; } |
||||
|
|
||||
|
|
||||
|
|
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,80 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Text; |
||||
|
|
||||
|
namespace Shentun.WebPeis.QuestionAnswers |
||||
|
{ |
||||
|
public class QuestionAnswerDto: AuditedEntityDtoName |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// 主键
|
||||
|
/// </summary>
|
||||
|
public Guid QuestionAnswerId { get; set; } |
||||
|
/// <summary>
|
||||
|
/// 答案
|
||||
|
/// </summary>
|
||||
|
|
||||
|
public string QuestionAnswerName { get; set; } = null!; |
||||
|
/// <summary>
|
||||
|
/// 问卷ID
|
||||
|
/// </summary>
|
||||
|
|
||||
|
public Guid QuestionId { get; set; } |
||||
|
|
||||
|
|
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 子答案类别
|
||||
|
/// </summary>
|
||||
|
|
||||
|
public char? ChildAnswerType { get; set; } |
||||
|
/// <summary>
|
||||
|
/// 答案结果类别
|
||||
|
/// </summary>
|
||||
|
|
||||
|
public char? AnswerResultType { get; set; } |
||||
|
/// <summary>
|
||||
|
/// 别名
|
||||
|
/// </summary>
|
||||
|
|
||||
|
public string? Aliases { get; set; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 概述
|
||||
|
/// </summary>
|
||||
|
|
||||
|
public string? Overview { get; set; } |
||||
|
/// <summary>
|
||||
|
/// 可能原因
|
||||
|
/// </summary>
|
||||
|
public string? Reason { get; set; } |
||||
|
/// <summary>
|
||||
|
/// 健康指导
|
||||
|
/// </summary>
|
||||
|
public string? HealthGuidance { get; set; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 父答案ID
|
||||
|
/// </summary>
|
||||
|
|
||||
|
public Guid? ParentId { get; set; } |
||||
|
/// <summary>
|
||||
|
/// 编码路径
|
||||
|
/// </summary>
|
||||
|
|
||||
|
public string? PathCode { get; set; } |
||||
|
/// <summary>
|
||||
|
/// 子答案标题
|
||||
|
/// </summary>
|
||||
|
public string? ChildAnswerTitle { get; set; } |
||||
|
/// <summary>
|
||||
|
/// 无,和其它答案排斥
|
||||
|
/// </summary>
|
||||
|
public char IsNone { get; set; } |
||||
|
|
||||
|
|
||||
|
public string SimpleCode { get; set; } = null!; |
||||
|
|
||||
|
public int DisplayOrder { get; set; } |
||||
|
} |
||||
|
} |
||||
@ -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; } |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,82 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Text; |
||||
|
|
||||
|
namespace Shentun.WebPeis.QuestionAnswers |
||||
|
{ |
||||
|
public class QuestionAnswerTreeListDto: AuditedEntityDtoName |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// 主键
|
||||
|
/// </summary>
|
||||
|
public Guid QuestionAnswerId { get; set; } |
||||
|
/// <summary>
|
||||
|
/// 答案
|
||||
|
/// </summary>
|
||||
|
|
||||
|
public string QuestionAnswerName { get; set; } = null!; |
||||
|
/// <summary>
|
||||
|
/// 问卷ID
|
||||
|
/// </summary>
|
||||
|
|
||||
|
public Guid QuestionId { get; set; } |
||||
|
|
||||
|
|
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 子答案类别
|
||||
|
/// </summary>
|
||||
|
|
||||
|
public char? ChildAnswerType { get; set; } |
||||
|
/// <summary>
|
||||
|
/// 答案结果类别
|
||||
|
/// </summary>
|
||||
|
|
||||
|
public char? AnswerResultType { get; set; } |
||||
|
/// <summary>
|
||||
|
/// 别名
|
||||
|
/// </summary>
|
||||
|
|
||||
|
public string? Aliases { get; set; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 概述
|
||||
|
/// </summary>
|
||||
|
|
||||
|
public string? Overview { get; set; } |
||||
|
/// <summary>
|
||||
|
/// 可能原因
|
||||
|
/// </summary>
|
||||
|
public string? Reason { get; set; } |
||||
|
/// <summary>
|
||||
|
/// 健康指导
|
||||
|
/// </summary>
|
||||
|
public string? HealthGuidance { get; set; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 父答案ID
|
||||
|
/// </summary>
|
||||
|
|
||||
|
public Guid? ParentId { get; set; } |
||||
|
/// <summary>
|
||||
|
/// 编码路径
|
||||
|
/// </summary>
|
||||
|
|
||||
|
public string? PathCode { get; set; } |
||||
|
/// <summary>
|
||||
|
/// 子答案标题
|
||||
|
/// </summary>
|
||||
|
public string? ChildAnswerTitle { get; set; } |
||||
|
/// <summary>
|
||||
|
/// 无,和其它答案排斥
|
||||
|
/// </summary>
|
||||
|
public char IsNone { get; set; } |
||||
|
|
||||
|
|
||||
|
public string SimpleCode { get; set; } = null!; |
||||
|
|
||||
|
public int DisplayOrder { get; set; } |
||||
|
|
||||
|
public List<QuestionAnswerTreeListDto> TreeChildren { get; set; } |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,68 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Text; |
||||
|
|
||||
|
namespace Shentun.WebPeis.QuestionAnswers |
||||
|
{ |
||||
|
public class UpdateQuestionAnswerDto |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// 主键
|
||||
|
/// </summary>
|
||||
|
public Guid QuestionAnswerId { get; set; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 答案
|
||||
|
/// </summary>
|
||||
|
|
||||
|
public string QuestionAnswerName { get; set; } = null!; |
||||
|
/// <summary>
|
||||
|
/// 问卷ID
|
||||
|
/// </summary>
|
||||
|
|
||||
|
public Guid QuestionId { get; set; } |
||||
|
|
||||
|
|
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 子答案类别
|
||||
|
/// </summary>
|
||||
|
|
||||
|
public char? ChildAnswerType { get; set; } |
||||
|
/// <summary>
|
||||
|
/// 答案结果类别
|
||||
|
/// </summary>
|
||||
|
|
||||
|
public char? AnswerResultType { get; set; } |
||||
|
/// <summary>
|
||||
|
/// 别名
|
||||
|
/// </summary>
|
||||
|
|
||||
|
public string? Aliases { get; set; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 概述
|
||||
|
/// </summary>
|
||||
|
|
||||
|
public string? Overview { get; set; } |
||||
|
/// <summary>
|
||||
|
/// 可能原因
|
||||
|
/// </summary>
|
||||
|
public string? Reason { get; set; } |
||||
|
/// <summary>
|
||||
|
/// 健康指导
|
||||
|
/// </summary>
|
||||
|
public string? HealthGuidance { get; set; } |
||||
|
|
||||
|
|
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 子答案标题
|
||||
|
/// </summary>
|
||||
|
public string? ChildAnswerTitle { get; set; } |
||||
|
/// <summary>
|
||||
|
/// 无,和其它答案排斥
|
||||
|
/// </summary>
|
||||
|
public char IsNone { get; set; } |
||||
|
} |
||||
|
} |
||||
@ -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 |
||||
|
{ |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 问卷答案
|
||||
|
/// </summary>
|
||||
|
[ApiExplorerSettings(GroupName = "Work")] |
||||
|
[Authorize] |
||||
|
public class QuestionAnswerAppService : ApplicationService |
||||
|
{ |
||||
|
|
||||
|
private readonly IRepository<QuestionAnswer> _questionAnswerRepository; |
||||
|
private readonly QuestionAnswerManager _questionAnswerManager; |
||||
|
private readonly CacheService _cacheService; |
||||
|
|
||||
|
public QuestionAnswerAppService( |
||||
|
CacheService cacheService, |
||||
|
IRepository<QuestionAnswer> questionAnswerRepository, |
||||
|
QuestionAnswerManager questionAnswerManager) |
||||
|
{ |
||||
|
_cacheService = cacheService; |
||||
|
_questionAnswerRepository = questionAnswerRepository; |
||||
|
_questionAnswerManager = questionAnswerManager; |
||||
|
} |
||||
|
|
||||
|
///// <summary>
|
||||
|
///// 获取列表
|
||||
|
///// </summary>
|
||||
|
///// <returns></returns>
|
||||
|
//[HttpPost("api/app/QuestionAnswer/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>
|
||||
|
/// 获取问卷答案树型列表 根据问卷ID
|
||||
|
/// </summary>
|
||||
|
/// <param name="input"></param>
|
||||
|
/// <returns></returns>
|
||||
|
[HttpPost("api/app/QuestionAnswer/GetQuestionTreeList")] |
||||
|
public async Task<List<QuestionAnswerTreeListDto>> 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, ""); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 创建
|
||||
|
/// </summary>
|
||||
|
/// <returns></returns>
|
||||
|
[HttpPost("api/app/QuestionAnswer/Create")] |
||||
|
public async Task<QuestionAnswerDto> CreateAsync(CreateQuestionAnswerDto input) |
||||
|
{ |
||||
|
var createEntity = ObjectMapper.Map<CreateQuestionAnswerDto, QuestionAnswer>(input); |
||||
|
createEntity.QuestionAnswerId = GuidGenerator.Create(); |
||||
|
var entity = await _questionAnswerManager.CreateAsync(createEntity); |
||||
|
entity = await _questionAnswerRepository.InsertAsync(entity); |
||||
|
var dto = ObjectMapper.Map<QuestionAnswer, QuestionAnswerDto>(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/QuestionAnswer/Update")] |
||||
|
public async Task<QuestionAnswerDto> UpdateAsync(UpdateQuestionAnswerDto input) |
||||
|
{ |
||||
|
var entity = await _questionAnswerRepository.GetAsync(f => f.QuestionAnswerId == input.QuestionAnswerId); |
||||
|
var sourceEntity = ObjectMapper.Map<UpdateQuestionAnswerDto, QuestionAnswer>(input); |
||||
|
_questionAnswerManager.UpdateAsync(sourceEntity, entity); |
||||
|
entity = await _questionAnswerRepository.UpdateAsync(entity); |
||||
|
var dto = ObjectMapper.Map<QuestionAnswer, QuestionAnswerDto>(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/QuestionAnswer/Delete")] |
||||
|
public async Task DeleteAsync(QuestionAnswerIdInputDto input) |
||||
|
{ |
||||
|
await _questionAnswerManager.CheckAndDeleteAsync(input.QuestionAnswerId); |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 修改排序 置顶,置底
|
||||
|
/// </summary>
|
||||
|
/// <param name="input"></param>
|
||||
|
/// <returns></returns>
|
||||
|
[HttpPost("api/app/QuestionAnswer/UpdateSortTopOrBottom")] |
||||
|
public async Task UpdateSortTopOrBottomAsync(UpdateQuestionAnswerSortTopOrBottomInputDto input) |
||||
|
{ |
||||
|
await _questionAnswerManager.UpdateSortTopOrBottomAsync(input.QuestionAnswerId, input.SortType); |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 修改排序 拖拽
|
||||
|
/// </summary>
|
||||
|
/// <param name="input"></param>
|
||||
|
/// <returns></returns>
|
||||
|
[HttpPost("api/app/QuestionAnswer/UpdateSortDragAsync")] |
||||
|
public async Task UpdateSortDragAsync(UpdateQuestionAnswerSortDragDto input) |
||||
|
{ |
||||
|
await _questionAnswerManager.UpdateSortDragAsync(input); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 使用Code进行递归
|
||||
|
/// </summary>
|
||||
|
/// <param name="items"></param>
|
||||
|
/// <param name="deep"></param>
|
||||
|
/// <param name="prefix"></param>
|
||||
|
/// <returns></returns>
|
||||
|
private List<QuestionAnswerTreeListDto> GetTree(List<QuestionAnswerTreeListDto> 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(); |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
} |
||||
@ -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<QuestionAnswer> _questionAnswerRepository; |
||||
|
|
||||
|
public QuestionAnswerManager( |
||||
|
IRepository<QuestionAnswer> questionAnswerRepository |
||||
|
) |
||||
|
{ |
||||
|
_questionAnswerRepository = questionAnswerRepository; |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 创建
|
||||
|
/// </summary>
|
||||
|
/// <returns></returns>
|
||||
|
public async Task<QuestionAnswer> 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<QuestionAnswer>(_questionAnswerRepository) |
||||
|
}; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 更新
|
||||
|
/// </summary>
|
||||
|
/// <param name="sourceEntity"></param>
|
||||
|
/// <param name="targetEntity"></param>
|
||||
|
/// <returns></returns>
|
||||
|
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); |
||||
|
|
||||
|
} |
||||
|
|
||||
|
|
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 删除
|
||||
|
/// </summary>
|
||||
|
/// <param name="QuestionAnswerId"></param>
|
||||
|
/// <returns></returns>
|
||||
|
/// <exception cref="UserFriendlyException"></exception>
|
||||
|
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); |
||||
|
|
||||
|
} |
||||
|
|
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 修改排序 置顶,置底
|
||||
|
/// </summary>
|
||||
|
/// <param name="id">需要修改的ID</param>
|
||||
|
/// <param name="SortType">修改方式:1 置顶 2 置底</param>
|
||||
|
/// <returns></returns>
|
||||
|
public async Task UpdateSortTopOrBottomAsync(Guid QuestionAnswerId, int SortType) |
||||
|
{ |
||||
|
var entity = await _questionAnswerRepository.GetAsync(f => f.QuestionAnswerId == QuestionAnswerId); |
||||
|
await EntityHelper.UpdateSortTopOrBottomAsync(_questionAnswerRepository, entity, SortType); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 修改排序 拖拽
|
||||
|
/// </summary>
|
||||
|
/// <typeparam name="TEntity"></typeparam>
|
||||
|
/// <param name="repository"></param>
|
||||
|
/// <param name="input"></param>
|
||||
|
/// <returns></returns>
|
||||
|
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); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
/// <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 _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; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -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<UpdateQuestionAnswerSortDragDetail> ItemList { get; set; } |
||||
|
} |
||||
|
|
||||
|
|
||||
|
public class UpdateQuestionAnswerSortDragDetail |
||||
|
{ |
||||
|
public Guid QuestionAnswerId { get; set; } |
||||
|
public int DisplayOrder { get; set; } |
||||
|
} |
||||
|
} |
||||
@ -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; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 修改方式:1 置顶 2 置底
|
||||
|
/// </summary>
|
||||
|
public int SortType { get; set; } |
||||
|
} |
||||
|
} |
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue