From c5b8f41a1c396d0f1a445599701a982d807fff4f Mon Sep 17 00:00:00 2001
From: "DESKTOP-G961P6V\\Zhh" <839860190@qq.com>
Date: Sat, 15 Jun 2024 23:59:18 +0800
Subject: [PATCH] =?UTF-8?q?=E9=A2=84=E7=BA=A6?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../Persons/PersonDto.cs | 2 +
.../QuestionRegisters/PersonSubjectTypeDto.cs | 30 +++
.../Persons/PersonAppService.cs | 2 +-
.../QuestionRegisterAppService.cs | 188 ++++++++++++++++--
.../PersonAppServiceTest.cs | 58 +++++-
.../QuestionRegisterAppServiceTest.cs | 44 +++-
6 files changed, 298 insertions(+), 26 deletions(-)
create mode 100644 src/Shentun.WebPeis.Application.Contracts/QuestionRegisters/PersonSubjectTypeDto.cs
diff --git a/src/Shentun.WebPeis.Application.Contracts/Persons/PersonDto.cs b/src/Shentun.WebPeis.Application.Contracts/Persons/PersonDto.cs
index 2415a50..ddd69c8 100644
--- a/src/Shentun.WebPeis.Application.Contracts/Persons/PersonDto.cs
+++ b/src/Shentun.WebPeis.Application.Contracts/Persons/PersonDto.cs
@@ -97,6 +97,8 @@ namespace Shentun.WebPeis.Persons
public char IsHaveQuestionRegister { get; set; }
+
+
}
}
diff --git a/src/Shentun.WebPeis.Application.Contracts/QuestionRegisters/PersonSubjectTypeDto.cs b/src/Shentun.WebPeis.Application.Contracts/QuestionRegisters/PersonSubjectTypeDto.cs
new file mode 100644
index 0000000..89542ee
--- /dev/null
+++ b/src/Shentun.WebPeis.Application.Contracts/QuestionRegisters/PersonSubjectTypeDto.cs
@@ -0,0 +1,30 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace Shentun.WebPeis.QuestionRegisters
+{
+ public class PersonSubjectTypeDto
+ {
+ ///
+ /// 题目类别ID
+ ///
+ public string QuestionSubjectTypeId { get; set; }
+ ///
+ /// 名称
+ ///
+
+ public string QuestionSubjectTypeName { get; set; } = null!;
+
+ public int DisplayOrder { get; set; }
+
+ public List Answers { get; set; } = new List();
+
+ }
+
+ public class PersonSubjectTypeQuestionAnswer
+ {
+ public string QuestionAnswerName { get; set; }
+ public int DisplayOrder { get; set; }
+ }
+}
diff --git a/src/Shentun.WebPeis.Application/Persons/PersonAppService.cs b/src/Shentun.WebPeis.Application/Persons/PersonAppService.cs
index ca60d24..32d1ebe 100644
--- a/src/Shentun.WebPeis.Application/Persons/PersonAppService.cs
+++ b/src/Shentun.WebPeis.Application/Persons/PersonAppService.cs
@@ -371,7 +371,7 @@ namespace Shentun.WebPeis.Persons
MaritalStatusName = _cacheService.GetMaritalStatusNameAsync(person.MaritalStatusId).Result,
IdNo = person.IdNo,
MobileTelephone = user.PhoneNumber,
- IsHaveQuestionRegister = haveQuestionRegister.QuestionRegisterId == Guid.Empty ? 'N':'Y'
+ IsHaveQuestionRegister = haveQuestionRegister == null ? 'N':'Y'
}).Distinct().ToList();
diff --git a/src/Shentun.WebPeis.Application/QuestionRegisters/QuestionRegisterAppService.cs b/src/Shentun.WebPeis.Application/QuestionRegisters/QuestionRegisterAppService.cs
index 2c3aba2..4a1efd0 100644
--- a/src/Shentun.WebPeis.Application/QuestionRegisters/QuestionRegisterAppService.cs
+++ b/src/Shentun.WebPeis.Application/QuestionRegisters/QuestionRegisterAppService.cs
@@ -25,6 +25,7 @@ namespace Shentun.WebPeis.QuestionRegisters
private readonly IRepository _questionRegisterAnswerRrepository;
private readonly IRepository _questionRepository;
private readonly IRepository _questionAnswerRepository;
+ private readonly IRepository _questionSubjectTypeRepository;
private readonly QuestionRegisterManager _questionRegisterManager;
private readonly IUnitOfWorkManager _unitOfWorkManager;
public QuestionRegisterAppService(IRepository repository,
@@ -33,7 +34,8 @@ namespace Shentun.WebPeis.QuestionRegisters
IRepository questionRepository,
IRepository questionAnswerRepository,
QuestionRegisterManager questionRegisterManager,
- IUnitOfWorkManager unitOfWorkManager)
+ IUnitOfWorkManager unitOfWorkManager,
+ IRepository questionSubjectTypeRepository)
{
_repository = repository;
_questionRegisterItemRepository = questionRegisterItemRepository;
@@ -42,7 +44,10 @@ namespace Shentun.WebPeis.QuestionRegisters
_questionAnswerRepository = questionAnswerRepository;
_questionRegisterManager = questionRegisterManager;
_unitOfWorkManager = unitOfWorkManager;
+ _questionSubjectTypeRepository = questionSubjectTypeRepository;
}
+
+
///
/// 获取人员问卷
///
@@ -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
}
+ ///
+ ///
+ ///
+ ///
+ ///
+ [HttpPost("api/app/QuestionRegister/GetSubjectTypeListByPersonId")]
+ public async Task> 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;
+ }
+ ///
+ ///
+ ///
+ ///
+ ///
+ [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();
+
+ 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);
+ }
+
///
/// 更新
///
@@ -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,
@@ -191,15 +337,19 @@ namespace Shentun.WebPeis.QuestionRegisters
foreach (var childQuestionRegisterAnswer in questionRegisterAnswerDto.Childs)
{
- questionRegisterAnswer = new QuestionRegisterAnswer()
+ if (childQuestionRegisterAnswer.IsSelected == 'Y')
{
- QuestionRegisterAnswerId = Guid.NewGuid(),
- QuestionRegisterItemId = questionRegisterItem.QuestionRegisterItemId,
- QuestionAnswerId = childQuestionRegisterAnswer.QuestionAnswerId,
- Content = childQuestionRegisterAnswer.Content,
+ questionRegisterAnswer = new QuestionRegisterAnswer()
+ {
+ QuestionRegisterAnswerId = GuidGenerator.Create(),
+ QuestionRegisterItemId = questionRegisterItem.QuestionRegisterItemId,
+ QuestionAnswerId = childQuestionRegisterAnswer.QuestionAnswerId,
+ Content = childQuestionRegisterAnswer.Content,
- };
- questionRegisterItem.QuestionRegisterAnswers.Add(questionRegisterAnswer);
+ };
+ questionRegisterItem.QuestionRegisterAnswers.Add(questionRegisterAnswer);
+ }
+
}
}
@@ -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,
};
//问卷
diff --git a/test/Shentun.WebPeis.Application.Tests/PersonAppServiceTest.cs b/test/Shentun.WebPeis.Application.Tests/PersonAppServiceTest.cs
index 154af41..1855538 100644
--- a/test/Shentun.WebPeis.Application.Tests/PersonAppServiceTest.cs
+++ b/test/Shentun.WebPeis.Application.Tests/PersonAppServiceTest.cs
@@ -9,8 +9,10 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.Domain.Repositories;
+using Volo.Abp.Identity;
using Volo.Abp.Modularity;
using Volo.Abp.Uow;
+using Volo.Abp.Users;
using Xunit;
using Xunit.Abstractions;
@@ -23,13 +25,21 @@ namespace Shentun.WebPeis
private readonly PersonAppService _appService;
private readonly ITestOutputHelper _output;
private readonly IUnitOfWorkManager _unitOfWorkManager;
+ private readonly IRepository _identityUserRepository;
+ private readonly IRepository _questionRegisterRepository;
+ private readonly IRepository _personKinshipRepository;
public PersonAppServiceTest(ITestOutputHelper output)
{
//ITestOutputHelper testOutputHelper
//_output = testOutputHelper;
_unitOfWorkManager = GetRequiredService();
_repository = GetRequiredService>();
- _appService = GetRequiredService();
+ //_appService = GetRequiredService();
+
+ _identityUserRepository = GetRequiredService>();
+ _questionRegisterRepository = GetRequiredService>();
+ _personKinshipRepository = GetRequiredService>();
+
_output = output;
}
[Fact]
@@ -87,6 +97,52 @@ namespace Shentun.WebPeis
await unitOfWork.CompleteAsync();
}
}
+
+ [Fact]
+ public async Task GetPersonKinshipListByEfcore()
+ {
+ using (var unitOfWork = _unitOfWorkManager.Begin(isTransactional: true))
+ {
+ var personId = new Guid("3a12d72c-19d9-e8b2-71f6-cf283103e191");
+ var personKinshipIds = (await _personKinshipRepository.GetQueryableAsync())
+ .Where(o => o.ParentPersonId == personId)
+ .Select(o => o.PersonId).ToList();
+ personKinshipIds.Add(personId);
+
+ var personList = (from user in await _identityUserRepository.GetQueryableAsync()
+ join person in await _repository.GetQueryableAsync()
+ on user.Id equals person.PersonId
+ join questionRegister in await _questionRegisterRepository.GetQueryableAsync()
+ on person.PersonId equals questionRegister.PersonId into emptyQuestionRegister
+ from haveQuestionRegister in emptyQuestionRegister.DefaultIfEmpty()
+ where personKinshipIds.Contains(user.Id)
+ orderby user.CreationTime
+ select new PersonDto
+ {
+ PersonId = user.Id,
+ PersonName = user.Name,
+ SexId = person.SexId,
+
+ MaritalStatusId = person.MaritalStatusId,
+
+ IdNo = person.IdNo,
+ MobileTelephone = user.PhoneNumber,
+ IsHaveQuestionRegister = haveQuestionRegister == null? 'N' : 'Y'
+
+
+ }).Distinct().ToList();
+
+ foreach (var person in personList)
+ {
+ _output.WriteLine(person.PersonName + "," + person.IsHaveQuestionRegister );
+ var cnt = (await _questionRegisterRepository.GetQueryableAsync()).Where(o=>o.PersonId == personId).Count();
+ _output.WriteLine(cnt.ToString());
+ }
+
+ await unitOfWork.CompleteAsync();
+ }
+
+ }
[Fact]
public async Task SendVerifySms()
{
diff --git a/test/Shentun.WebPeis.Application.Tests/QuestionRegisterAppServiceTest.cs b/test/Shentun.WebPeis.Application.Tests/QuestionRegisterAppServiceTest.cs
index be86b73..65d01b8 100644
--- a/test/Shentun.WebPeis.Application.Tests/QuestionRegisterAppServiceTest.cs
+++ b/test/Shentun.WebPeis.Application.Tests/QuestionRegisterAppServiceTest.cs
@@ -45,16 +45,50 @@ namespace Shentun.WebPeis
_output.WriteLine("-----------" + item.QuestionName + "-" + item.AnswerType );
foreach (var answer in item.QuestionRegisterAnswers)
{
- _output.WriteLine(answer.QuestionAnswerName + "-" + answer.ChildAnswerType );
- answer.IsSelected = 'Y';
+ _output.WriteLine(answer.QuestionAnswerName + "-" + answer.ChildAnswerType + answer.IsSelected);
+ //answer.IsSelected = 'Y';
foreach(var childAnswer in answer.Childs)
{
- _output.WriteLine("----"+childAnswer.QuestionAnswerName );
- childAnswer.IsSelected = 'Y';
+ _output.WriteLine("----"+childAnswer.QuestionAnswerName + childAnswer.IsSelected);
+ //childAnswer.IsSelected = 'Y';
}
}
}
- await _appService.UpdateAsync( entity );
+ //var questionRegister = await _repository.FindAsync(o=>o.QuestionRegisterId == entity.QuestionRegisterId);
+ //if(questionRegister == null)
+ //{
+ // await _appService.CreateAsync(entity);
+ //}
+ //else
+ //{
+ // await _appService.UpdateAsync(entity);
+ //}
+
+ await unitOfWork.CompleteAsync();
+ }
+ }
+
+ [Fact]
+ public async Task GetSubjectTypeListByPersonIdAsync()
+ {
+ using (var unitOfWork = _unitOfWorkManager.Begin(isTransactional: true))
+ {
+
+ var entity = await _appService.GetSubjectTypeListByPersonIdAsync(new PersonIdInputDto()
+ {
+ PersonId = new Guid("3a12d72c-19d9-e8b2-71f6-cf283103e191") // 3a12d7fa-63f1-d549-c2f8-01123e5b7a8a
+ });
+ foreach (var item in entity)
+ {
+ _output.WriteLine("-----------" + item.QuestionSubjectTypeName );
+ foreach (var answer in item.Answers)
+ {
+ _output.WriteLine(answer.QuestionAnswerName );
+
+ }
+ }
+
+
await unitOfWork.CompleteAsync();
}
}