|
|
|
@ -25,6 +25,7 @@ namespace Shentun.WebPeis.QuestionRegisters |
|
|
|
private readonly IRepository<QuestionRegisterAnswer> _questionRegisterAnswerRrepository; |
|
|
|
private readonly IRepository<Question> _questionRepository; |
|
|
|
private readonly IRepository<QuestionAnswer> _questionAnswerRepository; |
|
|
|
private readonly IRepository<QuestionSubjectType> _questionSubjectTypeRepository; |
|
|
|
private readonly QuestionRegisterManager _questionRegisterManager; |
|
|
|
private readonly IUnitOfWorkManager _unitOfWorkManager; |
|
|
|
public QuestionRegisterAppService(IRepository<QuestionRegister> repository, |
|
|
|
@ -33,7 +34,8 @@ namespace Shentun.WebPeis.QuestionRegisters |
|
|
|
IRepository<Question> questionRepository, |
|
|
|
IRepository<QuestionAnswer> questionAnswerRepository, |
|
|
|
QuestionRegisterManager questionRegisterManager, |
|
|
|
IUnitOfWorkManager unitOfWorkManager) |
|
|
|
IUnitOfWorkManager unitOfWorkManager, |
|
|
|
IRepository<QuestionSubjectType> questionSubjectTypeRepository) |
|
|
|
{ |
|
|
|
_repository = repository; |
|
|
|
_questionRegisterItemRepository = questionRegisterItemRepository; |
|
|
|
@ -42,7 +44,10 @@ namespace Shentun.WebPeis.QuestionRegisters |
|
|
|
_questionAnswerRepository = questionAnswerRepository; |
|
|
|
_questionRegisterManager = questionRegisterManager; |
|
|
|
_unitOfWorkManager = unitOfWorkManager; |
|
|
|
_questionSubjectTypeRepository = questionSubjectTypeRepository; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 获取人员问卷
|
|
|
|
/// </summary>
|
|
|
|
@ -64,13 +69,13 @@ namespace Shentun.WebPeis.QuestionRegisters |
|
|
|
if (questionRegister == null) |
|
|
|
{ |
|
|
|
//没有登记过
|
|
|
|
questionRegister = new QuestionRegister(); |
|
|
|
questionRegister.PersonId = input.PersonId; |
|
|
|
questionRegister = await _questionRegisterManager.CreateAsync(questionRegister); |
|
|
|
await _repository.InsertAsync(questionRegister); |
|
|
|
questionRegisterDto.QuestionRegisterId = questionRegister.QuestionRegisterId; |
|
|
|
await _unitOfWorkManager.Current.SaveChangesAsync(); |
|
|
|
//return questionRegisterDto;
|
|
|
|
//questionRegister = new QuestionRegister();
|
|
|
|
//questionRegister.PersonId = input.PersonId;
|
|
|
|
//questionRegister = await _questionRegisterManager.CreateAsync(questionRegister);
|
|
|
|
//await _repository.InsertAsync(questionRegister);
|
|
|
|
//questionRegisterDto.QuestionRegisterId = questionRegister.QuestionRegisterId;
|
|
|
|
//await _unitOfWorkManager.Current.SaveChangesAsync();
|
|
|
|
return questionRegisterDto; |
|
|
|
} |
|
|
|
questionRegisterDto.QuestionRegisterId = questionRegister.QuestionRegisterId; |
|
|
|
//已登记过
|
|
|
|
@ -96,7 +101,7 @@ namespace Shentun.WebPeis.QuestionRegisters |
|
|
|
foreach (var questionRegisterAnswer in questionRegisterItemDto.QuestionRegisterAnswers) |
|
|
|
{ |
|
|
|
var answer = questionRegisterItems.Where( |
|
|
|
o => o.questionRegisterAnswer.QuestionRegisterAnswerId == questionRegisterAnswer.QuestionRegisterAnswerId) |
|
|
|
o => o.questionRegisterAnswer.QuestionAnswerId == questionRegisterAnswer.QuestionAnswerId) |
|
|
|
.SingleOrDefault(); |
|
|
|
if (answer != null) |
|
|
|
{ |
|
|
|
@ -107,7 +112,7 @@ namespace Shentun.WebPeis.QuestionRegisters |
|
|
|
foreach (var childQuestionRegisterAnswer in questionRegisterAnswer.Childs) |
|
|
|
{ |
|
|
|
answer = questionRegisterItems.Where( |
|
|
|
o => o.questionRegisterAnswer.QuestionRegisterAnswerId == childQuestionRegisterAnswer.QuestionRegisterAnswerId) |
|
|
|
o => o.questionRegisterAnswer.QuestionAnswerId == childQuestionRegisterAnswer.QuestionAnswerId) |
|
|
|
.SingleOrDefault(); |
|
|
|
if (answer != null) |
|
|
|
{ |
|
|
|
@ -122,6 +127,147 @@ namespace Shentun.WebPeis.QuestionRegisters |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
///
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="input"></param>
|
|
|
|
/// <returns></returns>
|
|
|
|
[HttpPost("api/app/QuestionRegister/GetSubjectTypeListByPersonId")] |
|
|
|
public async Task<List<PersonSubjectTypeDto>> GetSubjectTypeListByPersonIdAsync(PersonIdInputDto input) |
|
|
|
{ |
|
|
|
var questionRegister = (await _repository.GetQueryableAsync()) |
|
|
|
.Where(o => o.PersonId == input.PersonId) |
|
|
|
.OrderByDescending(o => o.CreationTime) |
|
|
|
.FirstOrDefault(); |
|
|
|
if (questionRegister == null) |
|
|
|
{ |
|
|
|
return null; |
|
|
|
} |
|
|
|
|
|
|
|
var questionRegisterItems = (from questionRegisterItem in await _questionRegisterItemRepository.GetQueryableAsync() |
|
|
|
join questionRegisterAnswer in await _questionRegisterAnswerRrepository.GetQueryableAsync() |
|
|
|
on questionRegisterItem.QuestionRegisterItemId equals questionRegisterAnswer.QuestionRegisterItemId |
|
|
|
join questionAnswer in await _questionAnswerRepository.GetQueryableAsync() |
|
|
|
on questionRegisterAnswer.QuestionAnswerId equals questionAnswer.QuestionAnswerId |
|
|
|
join question in await _questionRepository.GetQueryableAsync() |
|
|
|
on questionRegisterItem.QuestionId equals question.QuestionId |
|
|
|
join questionSubjectType in await _questionSubjectTypeRepository.GetQueryableAsync() |
|
|
|
on question.QuestionSubjectTypeId equals questionSubjectType.QuestionSubjectTypeId |
|
|
|
where questionRegisterItem.QuestionRegisterId == questionRegister.QuestionRegisterId |
|
|
|
select new |
|
|
|
{ |
|
|
|
questionSubjectType, |
|
|
|
questionRegisterItem, |
|
|
|
questionRegisterAnswer, |
|
|
|
questionAnswer |
|
|
|
}).ToList(); |
|
|
|
|
|
|
|
var personSubjectTypeDtos = questionRegisterItems.GroupBy(o=>o.questionSubjectType) |
|
|
|
.Select(o=>new PersonSubjectTypeDto() |
|
|
|
{ |
|
|
|
QuestionSubjectTypeId = o.Key.QuestionSubjectTypeId, |
|
|
|
QuestionSubjectTypeName = o.Key.QuestionSubjectTypeName, |
|
|
|
DisplayOrder = o.Key.DisplayOrder |
|
|
|
}).ToList(); |
|
|
|
foreach (var personSubjectTypeDto in personSubjectTypeDtos) |
|
|
|
{ |
|
|
|
questionRegisterItems.Where(o => o.questionSubjectType.QuestionSubjectTypeId == personSubjectTypeDto.QuestionSubjectTypeId |
|
|
|
).ToList(); |
|
|
|
foreach(var questionRegisterItem in questionRegisterItems) |
|
|
|
{ |
|
|
|
string answer; |
|
|
|
if(questionRegisterItem.questionAnswer.AnswerResultType == AnswerResultTypeFlag.Choice) |
|
|
|
{ |
|
|
|
if(string.IsNullOrWhiteSpace(questionRegisterItem.questionAnswer.Aliases)) |
|
|
|
{ |
|
|
|
answer = questionRegisterItem.questionAnswer.QuestionAnswerName; |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
answer = questionRegisterItem.questionAnswer.Aliases; |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
answer = questionRegisterItem.questionRegisterAnswer.Content; |
|
|
|
} |
|
|
|
personSubjectTypeDto.Answers.Add(new PersonSubjectTypeQuestionAnswer() |
|
|
|
{ |
|
|
|
QuestionAnswerName = answer, |
|
|
|
DisplayOrder = questionRegisterItem.questionAnswer.DisplayOrder, |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return personSubjectTypeDtos; |
|
|
|
} |
|
|
|
/// <summary>
|
|
|
|
///
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="input"></param>
|
|
|
|
/// <returns></returns>
|
|
|
|
[HttpPost("api/app/QuestionRegister/Create")] |
|
|
|
public async Task CreateAsync(QuestionRegisterDto input) |
|
|
|
{ |
|
|
|
|
|
|
|
var questionRegister = new QuestionRegister(); |
|
|
|
questionRegister.PersonId = input.PersonId; |
|
|
|
questionRegister = await _questionRegisterManager.CreateAsync(questionRegister); |
|
|
|
|
|
|
|
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 = GuidGenerator.Create(), |
|
|
|
QuestionRegisterItemId = questionRegisterItem.QuestionRegisterItemId, |
|
|
|
QuestionAnswerId = questionRegisterAnswerDto.QuestionAnswerId, |
|
|
|
Content = questionRegisterAnswerDto.Content, |
|
|
|
|
|
|
|
}; |
|
|
|
questionRegisterItem.QuestionRegisterAnswers.Add(questionRegisterAnswer); |
|
|
|
|
|
|
|
foreach (var childQuestionRegisterAnswer in questionRegisterAnswerDto.Childs) |
|
|
|
{ |
|
|
|
if(childQuestionRegisterAnswer.IsSelected == 'Y') |
|
|
|
{ |
|
|
|
questionRegisterAnswer = new QuestionRegisterAnswer() |
|
|
|
{ |
|
|
|
QuestionRegisterAnswerId = GuidGenerator.Create(), |
|
|
|
QuestionRegisterItemId = questionRegisterItem.QuestionRegisterItemId, |
|
|
|
QuestionAnswerId = childQuestionRegisterAnswer.QuestionAnswerId, |
|
|
|
Content = childQuestionRegisterAnswer.Content, |
|
|
|
|
|
|
|
}; |
|
|
|
questionRegisterItem.QuestionRegisterAnswers.Add(questionRegisterAnswer); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
await _repository.InsertAsync(questionRegister); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 更新
|
|
|
|
/// </summary>
|
|
|
|
@ -181,7 +327,7 @@ namespace Shentun.WebPeis.QuestionRegisters |
|
|
|
} |
|
|
|
var questionRegisterAnswer = new QuestionRegisterAnswer() |
|
|
|
{ |
|
|
|
QuestionRegisterAnswerId = Guid.NewGuid(), |
|
|
|
QuestionRegisterAnswerId = GuidGenerator.Create(), |
|
|
|
QuestionRegisterItemId = questionRegisterItem.QuestionRegisterItemId, |
|
|
|
QuestionAnswerId = questionRegisterAnswerDto.QuestionAnswerId, |
|
|
|
Content = questionRegisterAnswerDto.Content, |
|
|
|
@ -190,10 +336,12 @@ namespace Shentun.WebPeis.QuestionRegisters |
|
|
|
questionRegisterItem.QuestionRegisterAnswers.Add(questionRegisterAnswer); |
|
|
|
|
|
|
|
foreach (var childQuestionRegisterAnswer in questionRegisterAnswerDto.Childs) |
|
|
|
{ |
|
|
|
if (childQuestionRegisterAnswer.IsSelected == 'Y') |
|
|
|
{ |
|
|
|
questionRegisterAnswer = new QuestionRegisterAnswer() |
|
|
|
{ |
|
|
|
QuestionRegisterAnswerId = Guid.NewGuid(), |
|
|
|
QuestionRegisterAnswerId = GuidGenerator.Create(), |
|
|
|
QuestionRegisterItemId = questionRegisterItem.QuestionRegisterItemId, |
|
|
|
QuestionAnswerId = childQuestionRegisterAnswer.QuestionAnswerId, |
|
|
|
Content = childQuestionRegisterAnswer.Content, |
|
|
|
@ -203,6 +351,8 @@ namespace Shentun.WebPeis.QuestionRegisters |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
await _repository.UpdateAsync(questionRegister); |
|
|
|
@ -213,7 +363,7 @@ namespace Shentun.WebPeis.QuestionRegisters |
|
|
|
var questionAnswers = await _questionAnswerRepository.GetListAsync(); |
|
|
|
var questionRegisterDto = new QuestionRegisterDto() |
|
|
|
{ |
|
|
|
QuestionRegisterId = Guid.NewGuid(), |
|
|
|
QuestionRegisterId = GuidGenerator.Create(), |
|
|
|
PersonId = input.PersonId, |
|
|
|
}; |
|
|
|
//问卷
|
|
|
|
|