|
|
|
@ -1,4 +1,7 @@ |
|
|
|
|
namespace Tiobon.Core.Api.Controllers; |
|
|
|
|
using Consul.Filtering; |
|
|
|
|
using SkyWalking.NetworkProtocol.V3; |
|
|
|
|
|
|
|
|
|
namespace Tiobon.Core.Api.Controllers; |
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
|
/// 题目(Controller) |
|
|
|
@ -8,7 +11,106 @@ |
|
|
|
|
[Authorize(Permissions.Name), ApiExplorerSettings(GroupName = Grouping.GroupName_Ghre)] |
|
|
|
|
public class Ghre_QuestionController : BaseController<IGhre_QuestionServices, Ghre_Question, Ghre_QuestionDto, InsertGhre_QuestionInput, EditGhre_QuestionInput> |
|
|
|
|
{ |
|
|
|
|
public Ghre_QuestionController(IGhre_QuestionServices service) : base(service) |
|
|
|
|
|
|
|
|
|
IGhre_QuestionAnswerServices _ghre_QuestionAnswerServices; |
|
|
|
|
public Ghre_QuestionController(IGhre_QuestionServices service, IGhre_QuestionAnswerServices ghre_QuestionAnswerServices) : base(service) |
|
|
|
|
{ |
|
|
|
|
_ghre_QuestionAnswerServices = ghre_QuestionAnswerServices; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#region 基础接口 |
|
|
|
|
|
|
|
|
|
#region 查询 |
|
|
|
|
/// <summary> |
|
|
|
|
/// 根据条件查询数据 |
|
|
|
|
/// </summary> |
|
|
|
|
/// <param name="filter">条件</param> |
|
|
|
|
/// <returns></returns> |
|
|
|
|
[HttpGet] |
|
|
|
|
public override async Task<ServicePageResult<Ghre_QuestionDto>> QueryByFilter([FromFilter] QueryFilter filter) |
|
|
|
|
{ |
|
|
|
|
var data = await _service.QueryFilterPage(filter); |
|
|
|
|
return data; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
|
/// 根据Id查询数据 |
|
|
|
|
/// </summary> |
|
|
|
|
/// <param name="Id">主键ID</param> |
|
|
|
|
/// <returns></returns> |
|
|
|
|
[HttpGet("{Id}")] |
|
|
|
|
public override async Task<ServiceResult<Ghre_QuestionDto>> QueryById(long Id) |
|
|
|
|
{ |
|
|
|
|
var entity = await _service.QueryById(Id); |
|
|
|
|
if (entity == null) |
|
|
|
|
return Failed<Ghre_QuestionDto>("获取失败"); |
|
|
|
|
else |
|
|
|
|
return Success(entity, "获取成功"); |
|
|
|
|
} |
|
|
|
|
#endregion |
|
|
|
|
|
|
|
|
|
#region 新增 |
|
|
|
|
/// <summary> |
|
|
|
|
/// 新增数据 |
|
|
|
|
/// </summary> |
|
|
|
|
/// <param name="insertModel"></param> |
|
|
|
|
/// <returns></returns> |
|
|
|
|
[HttpPost] |
|
|
|
|
public override async Task<ServiceResult<string>> Insert([FromBody] InsertGhre_QuestionInput insertModel) |
|
|
|
|
{ |
|
|
|
|
insertModel.CourseIds = string.Join(";", insertModel.CourseId.Select(x => x)); |
|
|
|
|
var id = await _service.Add(insertModel); |
|
|
|
|
var answers = insertModel.Answers; |
|
|
|
|
if (answers.Any()) |
|
|
|
|
{ |
|
|
|
|
int i = 100; |
|
|
|
|
answers.ForEach(x => |
|
|
|
|
{ |
|
|
|
|
x.TaxisNo = i; |
|
|
|
|
x.QuestionId = id; |
|
|
|
|
}); |
|
|
|
|
i = i + 100; |
|
|
|
|
await _ghre_QuestionAnswerServices.Add(answers); |
|
|
|
|
} |
|
|
|
|
var data = Success<string>(null, "新增成功"); |
|
|
|
|
data.Success = id > 0; |
|
|
|
|
if (data.Success) |
|
|
|
|
data.Data = id.ObjToString(); |
|
|
|
|
else |
|
|
|
|
return Failed<string>("新增失败"); |
|
|
|
|
return data; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#endregion |
|
|
|
|
|
|
|
|
|
#region 更新 |
|
|
|
|
/// <summary> |
|
|
|
|
/// 更新数据 |
|
|
|
|
/// </summary> |
|
|
|
|
/// <param name="Id">主键ID</param> |
|
|
|
|
/// <param name="editModel"></param> |
|
|
|
|
/// <returns></returns> |
|
|
|
|
[HttpPut("{Id}")] |
|
|
|
|
public override async Task<ServiceResult> Put(long Id, [FromBody] EditGhre_QuestionInput editModel) |
|
|
|
|
{ |
|
|
|
|
var answers1 = await _ghre_QuestionAnswerServices.Query(d => d.QuestionId == Id); |
|
|
|
|
var answerIds = answers1.Select(x => x.Id).ToList(); |
|
|
|
|
await _ghre_QuestionAnswerServices.DeleteByIds1(answerIds.ToArray()); |
|
|
|
|
var answers = editModel.Answers; |
|
|
|
|
if (answers.Any()) |
|
|
|
|
{ |
|
|
|
|
int i = 100; |
|
|
|
|
answers.ForEach(x => |
|
|
|
|
{ |
|
|
|
|
x.TaxisNo = i; |
|
|
|
|
x.QuestionId = Id; |
|
|
|
|
}); |
|
|
|
|
i = i + 100; |
|
|
|
|
await _ghre_QuestionAnswerServices.Add(answers); |
|
|
|
|
} |
|
|
|
|
return await base.Put(Id, editModel); |
|
|
|
|
} |
|
|
|
|
#endregion |
|
|
|
|
|
|
|
|
|
#endregion |
|
|
|
|
} |