|
|
|
@ -12,6 +12,7 @@ using System.Threading.Tasks; |
|
|
|
using Volo.Abp.Application.Services; |
|
|
|
using Volo.Abp.Domain.Entities; |
|
|
|
using Volo.Abp.Domain.Repositories; |
|
|
|
using Volo.Abp.Uow; |
|
|
|
|
|
|
|
namespace Shentun.WebPeis.QuestionRegisters |
|
|
|
{ |
|
|
|
@ -25,12 +26,14 @@ namespace Shentun.WebPeis.QuestionRegisters |
|
|
|
private readonly IRepository<Question> _questionRepository; |
|
|
|
private readonly IRepository<QuestionAnswer> _questionAnswerRepository; |
|
|
|
private readonly QuestionRegisterManager _questionRegisterManager; |
|
|
|
private readonly IUnitOfWorkManager _unitOfWorkManager; |
|
|
|
public QuestionRegisterAppService(IRepository<QuestionRegister> repository, |
|
|
|
IRepository<QuestionRegisterItem> questionRegisterItemRepository, |
|
|
|
IRepository<QuestionRegisterAnswer> questionRegisterAnswerRrepository, |
|
|
|
IRepository<Question> questionRepository, |
|
|
|
IRepository<QuestionAnswer> questionAnswerRepository, |
|
|
|
QuestionRegisterManager questionRegisterManager) |
|
|
|
QuestionRegisterManager questionRegisterManager, |
|
|
|
IUnitOfWorkManager unitOfWorkManager) |
|
|
|
{ |
|
|
|
_repository = repository; |
|
|
|
_questionRegisterItemRepository = questionRegisterItemRepository; |
|
|
|
@ -38,6 +41,7 @@ namespace Shentun.WebPeis.QuestionRegisters |
|
|
|
_questionRepository = questionRepository; |
|
|
|
_questionAnswerRepository = questionAnswerRepository; |
|
|
|
_questionRegisterManager = questionRegisterManager; |
|
|
|
_unitOfWorkManager = unitOfWorkManager; |
|
|
|
} |
|
|
|
/// <summary>
|
|
|
|
/// 获取人员问卷
|
|
|
|
@ -59,13 +63,17 @@ namespace Shentun.WebPeis.QuestionRegisters |
|
|
|
questionRegisterDto = await GetBasicDataAsync(input); |
|
|
|
if (questionRegister == null) |
|
|
|
{ |
|
|
|
//没有登记过
|
|
|
|
var questionRegisterEntity = new QuestionRegister(); |
|
|
|
questionRegisterEntity.PersonId = input.PersonId; |
|
|
|
questionRegisterEntity = await _questionRegisterManager.CreateAsync(questionRegisterEntity); |
|
|
|
await _repository.InsertAsync(questionRegisterEntity); |
|
|
|
questionRegisterDto.QuestionRegisterId = questionRegisterEntity.QuestionRegisterId; |
|
|
|
return questionRegisterDto; |
|
|
|
await _unitOfWorkManager.Current.SaveChangesAsync(); |
|
|
|
//return questionRegisterDto;
|
|
|
|
} |
|
|
|
|
|
|
|
questionRegisterDto.QuestionRegisterId = questionRegister.QuestionRegisterId; |
|
|
|
//已登记过
|
|
|
|
var questionRegisterItems = (from questionRegisterItem in await _questionRegisterItemRepository.GetQueryableAsync() |
|
|
|
join questionRegisterAnswer in await _questionRegisterAnswerRrepository.GetQueryableAsync() |
|
|
|
on questionRegisterItem.QuestionRegisterItemId equals questionRegisterAnswer.QuestionRegisterItemId |
|
|
|
@ -77,24 +85,128 @@ namespace Shentun.WebPeis.QuestionRegisters |
|
|
|
}).ToList(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var questionRegisterItem in questionRegisterDto.QuestionRegisterItems) |
|
|
|
foreach (var questionRegisterItemDto in questionRegisterDto.QuestionRegisterItems) |
|
|
|
{ |
|
|
|
foreach (var questionRegisterAnswer in questionRegisterItem.QuestionRegisterAnswers) |
|
|
|
var questionRegisterItemEntity = questionRegisterItems.Where(o => |
|
|
|
o.questionRegisterItem.QuestionId == questionRegisterItemDto.QuestionId).FirstOrDefault(); |
|
|
|
if (questionRegisterItemEntity != null) |
|
|
|
{ |
|
|
|
var answer = questionRegisterItems.Where( |
|
|
|
o=>o.questionRegisterAnswer.QuestionRegisterAnswerId == questionRegisterAnswer.QuestionRegisterAnswerId) |
|
|
|
.SingleOrDefault(); |
|
|
|
if(answer != null) |
|
|
|
questionRegisterItemDto.QuestionRegisterItemId = questionRegisterItemEntity.questionRegisterItem.QuestionRegisterItemId; |
|
|
|
} |
|
|
|
foreach (var questionRegisterAnswer in questionRegisterItemDto.QuestionRegisterAnswers) |
|
|
|
{ |
|
|
|
var answer = questionRegisterItems.Where( |
|
|
|
o => o.questionRegisterAnswer.QuestionRegisterAnswerId == questionRegisterAnswer.QuestionRegisterAnswerId) |
|
|
|
.SingleOrDefault(); |
|
|
|
if (answer != null) |
|
|
|
{ |
|
|
|
questionRegisterAnswer.IsSelected = 'Y'; |
|
|
|
questionRegisterAnswer.Content = answer.questionRegisterAnswer.Content; |
|
|
|
|
|
|
|
} |
|
|
|
foreach (var childQuestionRegisterAnswer in questionRegisterAnswer.Childs) |
|
|
|
{ |
|
|
|
answer = questionRegisterItems.Where( |
|
|
|
o => o.questionRegisterAnswer.QuestionRegisterAnswerId == childQuestionRegisterAnswer.QuestionRegisterAnswerId) |
|
|
|
.SingleOrDefault(); |
|
|
|
if (answer != null) |
|
|
|
{ |
|
|
|
childQuestionRegisterAnswer.IsSelected = 'Y'; |
|
|
|
childQuestionRegisterAnswer.Content = answer.questionRegisterAnswer.Content; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
return questionRegisterDto; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 更新
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="input"></param>
|
|
|
|
/// <returns></returns>
|
|
|
|
[HttpPost("api/app/QuestionRegister/Update")] |
|
|
|
public async Task UpdateAsync(QuestionRegisterDto input) |
|
|
|
{ |
|
|
|
var questionRegister = await _repository.GetAsync(o => o.QuestionRegisterId == input.QuestionRegisterId); |
|
|
|
var questionRegisterItemList = (from questionRegisterItem in await _questionRegisterItemRepository.GetQueryableAsync() |
|
|
|
join questionRegisterAnswer in await _questionRegisterAnswerRrepository.GetQueryableAsync() |
|
|
|
on questionRegisterItem.QuestionRegisterItemId equals questionRegisterAnswer.QuestionRegisterItemId |
|
|
|
where questionRegisterItem.QuestionRegisterId == questionRegister.QuestionRegisterId |
|
|
|
select new |
|
|
|
{ |
|
|
|
questionRegisterItem, |
|
|
|
questionRegisterAnswer, |
|
|
|
}).ToList(); |
|
|
|
//删除所有答案和项目
|
|
|
|
|
|
|
|
var questionRegisterItems = questionRegisterItemList |
|
|
|
.GroupBy(o => o.questionRegisterItem) |
|
|
|
.Select(x => x.FirstOrDefault().questionRegisterItem) |
|
|
|
.ToList(); |
|
|
|
foreach (var questionRegisterItem in questionRegisterItems) |
|
|
|
{ |
|
|
|
//删除答案
|
|
|
|
var questionRegisterAnswers = questionRegisterItemList. |
|
|
|
Where(o => o.questionRegisterItem.QuestionRegisterItemId == questionRegisterItem.QuestionRegisterItemId) |
|
|
|
.Select(x => x.questionRegisterAnswer) |
|
|
|
.ToList(); |
|
|
|
await _questionRegisterAnswerRrepository.DeleteManyAsync(questionRegisterAnswers); |
|
|
|
} |
|
|
|
//删除问题
|
|
|
|
await _questionRegisterItemRepository.DeleteManyAsync(questionRegisterItems); |
|
|
|
//重新设置
|
|
|
|
questionRegister.QuestionRegisterItems = new List<QuestionRegisterItem>(); |
|
|
|
|
|
|
|
foreach (var questionRegisterItemDto in input.QuestionRegisterItems) |
|
|
|
{ |
|
|
|
foreach (var questionRegisterAnswerDto in questionRegisterItemDto.QuestionRegisterAnswers) |
|
|
|
{ |
|
|
|
if (questionRegisterAnswerDto.IsSelected == 'Y') |
|
|
|
{ |
|
|
|
var questionRegisterItem = questionRegister.QuestionRegisterItems |
|
|
|
.Where(o => o.QuestionId == questionRegisterItemDto.QuestionId).FirstOrDefault(); |
|
|
|
if (questionRegisterItem == null) |
|
|
|
{ |
|
|
|
questionRegisterItem = new QuestionRegisterItem() |
|
|
|
{ |
|
|
|
QuestionRegisterItemId = questionRegisterItemDto.QuestionRegisterItemId, |
|
|
|
QuestionRegisterId = questionRegister.QuestionRegisterId, |
|
|
|
QuestionId = questionRegisterItemDto.QuestionId, |
|
|
|
}; |
|
|
|
questionRegister.QuestionRegisterItems.Add(questionRegisterItem); |
|
|
|
// await _questionRegisterItemRepository.InsertAsync(questionRegisterItem);
|
|
|
|
} |
|
|
|
var questionRegisterAnswer = new QuestionRegisterAnswer() |
|
|
|
{ |
|
|
|
QuestionRegisterAnswerId = Guid.NewGuid(), |
|
|
|
QuestionRegisterItemId = questionRegisterItem.QuestionRegisterItemId, |
|
|
|
QuestionAnswerId = questionRegisterAnswerDto.QuestionAnswerId, |
|
|
|
Content = questionRegisterAnswerDto.Content, |
|
|
|
|
|
|
|
}; |
|
|
|
questionRegisterItem.QuestionRegisterAnswers.Add(questionRegisterAnswer); |
|
|
|
|
|
|
|
foreach (var childQuestionRegisterAnswer in questionRegisterAnswerDto.Childs) |
|
|
|
{ |
|
|
|
questionRegisterAnswer = new QuestionRegisterAnswer() |
|
|
|
{ |
|
|
|
QuestionRegisterAnswerId = Guid.NewGuid(), |
|
|
|
QuestionRegisterItemId = questionRegisterItem.QuestionRegisterItemId, |
|
|
|
QuestionAnswerId = childQuestionRegisterAnswer.QuestionAnswerId, |
|
|
|
Content = childQuestionRegisterAnswer.Content, |
|
|
|
|
|
|
|
}; |
|
|
|
questionRegisterItem.QuestionRegisterAnswers.Add(questionRegisterAnswer); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
await _repository.UpdateAsync(questionRegister); |
|
|
|
} |
|
|
|
private async Task<QuestionRegisterDto> GetBasicDataAsync(PersonIdInputDto input) |
|
|
|
{ |
|
|
|
var questions = await _questionRepository.GetListAsync(o => o.IsActive == 'Y'); |
|
|
|
@ -127,11 +239,14 @@ namespace Shentun.WebPeis.QuestionRegisters |
|
|
|
var questionRegisterAnswer = new QuestionRegisterAnswerDto() |
|
|
|
{ |
|
|
|
QuestionRegisterAnswerId = GuidGenerator.Create(), |
|
|
|
QuestionId = question.QuestionId, |
|
|
|
QuestionAnswerId = questionAnswer.QuestionAnswerId, |
|
|
|
QuestionAnswerName = questionAnswer.QuestionAnswerName, |
|
|
|
ChildAnswerType = questionAnswer.ChildAnswerType, |
|
|
|
AnswerResultType = questionAnswer.AnswerResultType, |
|
|
|
IsSelected = 'N', |
|
|
|
ChildAnswerTitle = questionAnswer.ChildAnswerTitle, |
|
|
|
IsNone = questionAnswer.IsNone, |
|
|
|
DisplayOrder = questionAnswer.DisplayOrder, |
|
|
|
ParentId = questionAnswer.ParentId, |
|
|
|
PathCode = questionAnswer.PathCode, |
|
|
|
@ -144,14 +259,17 @@ namespace Shentun.WebPeis.QuestionRegisters |
|
|
|
var childQuestionRegisterAnswer = new QuestionRegisterAnswerDto() |
|
|
|
{ |
|
|
|
QuestionRegisterAnswerId = GuidGenerator.Create(), |
|
|
|
QuestionId = question.QuestionId, |
|
|
|
QuestionAnswerId = ChilduestionAnswer.QuestionAnswerId, |
|
|
|
QuestionAnswerName = ChilduestionAnswer.QuestionAnswerName, |
|
|
|
ChildAnswerType = ChilduestionAnswer.ChildAnswerType, |
|
|
|
AnswerResultType = ChilduestionAnswer.AnswerResultType, |
|
|
|
IsSelected = 'N', |
|
|
|
ChildAnswerTitle = questionAnswer.ChildAnswerTitle, |
|
|
|
IsNone = questionAnswer.IsNone, |
|
|
|
DisplayOrder = ChilduestionAnswer.DisplayOrder, |
|
|
|
ParentId = ChilduestionAnswer.ParentId, |
|
|
|
PathCode= ChilduestionAnswer.PathCode, |
|
|
|
PathCode = ChilduestionAnswer.PathCode, |
|
|
|
|
|
|
|
|
|
|
|
}; |
|
|
|
|