|
|
|
@ -5,7 +5,6 @@ using System.Text.RegularExpressions; |
|
|
|
|
using AgileObjects.AgileMapper; |
|
|
|
|
using Microsoft.AspNetCore.Http; |
|
|
|
|
using MongoDB.Driver.Linq; |
|
|
|
|
using Newtonsoft.Json; |
|
|
|
|
using Newtonsoft.Json.Linq; |
|
|
|
|
using SqlSugar; |
|
|
|
|
using Tiobon.Core.Common; |
|
|
|
@ -18,13 +17,13 @@ using Tiobon.Core.Model; |
|
|
|
|
using Tiobon.Core.Model.Models; |
|
|
|
|
using Tiobon.Core.Services.BASE; |
|
|
|
|
|
|
|
|
|
namespace Tiobon.Core.Services |
|
|
|
|
namespace Tiobon.Core.Services; |
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
|
/// 试卷 (服务) |
|
|
|
|
/// </summary> |
|
|
|
|
public class Ghre_ExamPaperServices : BaseServices<Ghre_ExamPaper, Ghre_ExamPaperDto, InsertGhre_ExamPaperInput, EditGhre_ExamPaperInput>, IGhre_ExamPaperServices |
|
|
|
|
{ |
|
|
|
|
/// <summary> |
|
|
|
|
/// 试卷 (服务) |
|
|
|
|
/// </summary> |
|
|
|
|
public class Ghre_ExamPaperServices : BaseServices<Ghre_ExamPaper, Ghre_ExamPaperDto, InsertGhre_ExamPaperInput, EditGhre_ExamPaperInput>, IGhre_ExamPaperServices |
|
|
|
|
{ |
|
|
|
|
private readonly IGhre_ExamPaperConfigServices _ghre_ExamPaperConfigServices; |
|
|
|
|
private readonly IGhre_ExamPaperQuestionServices _ghre_ExamPaperQuestionServices; |
|
|
|
|
private readonly IGhre_QuestionServices _ghre_QuestionServices; |
|
|
|
@ -32,6 +31,8 @@ namespace Tiobon.Core.Services |
|
|
|
|
private readonly IGhre_QuestionAnswerServices _ghre_QuestionAnswerServices; |
|
|
|
|
private readonly IGhre_CourseServices _ghre_CourseServices; |
|
|
|
|
private readonly IGhre_CourseSceneServices _ghre_CourseSceneServices; |
|
|
|
|
private readonly IGhre_ExamServices _ghre_ExamServices; |
|
|
|
|
private readonly IGhre_ExamRecordServices _ghre_ExamRecordServices; |
|
|
|
|
private readonly IBaseRepository<Ghre_ExamPaper> _dal; |
|
|
|
|
|
|
|
|
|
public Ghre_ExamPaperServices(IBaseRepository<Ghre_ExamPaper> dal, |
|
|
|
@ -41,6 +42,8 @@ namespace Tiobon.Core.Services |
|
|
|
|
IGhre_ExamPaperQuestionServices ghre_ExamPaperQuestionServices, |
|
|
|
|
IGhre_CourseServices ghre_CourseServices, |
|
|
|
|
IGhre_CourseSceneServices ghre_CourseSceneServices, |
|
|
|
|
IGhre_ExamServices ghre_ExamServices, |
|
|
|
|
IGhre_ExamRecordServices ghre_ExamRecordServices, |
|
|
|
|
ICaching caching, |
|
|
|
|
IGhrs_UserServices ghrs_UserServices) |
|
|
|
|
{ |
|
|
|
@ -54,6 +57,8 @@ namespace Tiobon.Core.Services |
|
|
|
|
_ghrs_UserServices = ghrs_UserServices; |
|
|
|
|
_ghre_CourseServices = ghre_CourseServices; |
|
|
|
|
_ghre_CourseSceneServices = ghre_CourseSceneServices; |
|
|
|
|
_ghre_ExamServices = ghre_ExamServices; |
|
|
|
|
_ghre_ExamRecordServices = ghre_ExamRecordServices; |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
public override async Task<Ghre_ExamPaperDto> QueryById(object objId) |
|
|
|
@ -682,7 +687,7 @@ delete from Ghre_ExamPaperQuestion WHERE ExamPaperId='{id}';"); |
|
|
|
|
(insert.LinkType == "CourseSceneId" && insert.LinkType != paper.LinkType) |
|
|
|
|
) |
|
|
|
|
{ |
|
|
|
|
var courses = await _ghre_CourseServices.Query(x =>x.Id == paper.LinkId && x.ExamPaperId.Contains(id.ObjToString())); |
|
|
|
|
var courses = await _ghre_CourseServices.Query(x => x.Id == paper.LinkId && x.ExamPaperId.Contains(id.ObjToString())); |
|
|
|
|
courses.ForEach(async x => |
|
|
|
|
{ |
|
|
|
|
var ids = JsonHelper.JsonToObj<List<long?>>(x.ExamPaperId); |
|
|
|
@ -738,13 +743,32 @@ delete from Ghre_ExamPaperQuestion WHERE ExamPaperId='{id}';"); |
|
|
|
|
var ip = GetUserIp(UserContext.Context); |
|
|
|
|
|
|
|
|
|
List<Ghre_ExamPaper> entities = new List<Ghre_ExamPaper>(); |
|
|
|
|
foreach (var id in ids) |
|
|
|
|
for (int i = 0; i < ids.Count(); i++) |
|
|
|
|
{ |
|
|
|
|
if (id == null || !BaseDal.Any(id)) |
|
|
|
|
|
|
|
|
|
var id = ids[i]; |
|
|
|
|
if (!BaseDal.Any(id)) |
|
|
|
|
continue; |
|
|
|
|
|
|
|
|
|
var entity = await BaseDal.QueryById(id); |
|
|
|
|
|
|
|
|
|
#region 校验数据是否被引用 |
|
|
|
|
if (entity.Status == "Released" && (status == "Draft" || status == "Disabled"))//取消发布-停用 |
|
|
|
|
{ |
|
|
|
|
if (await _ghre_ExamServices.AnyAsync(x => x.ExamPaperId == id && x.Status == "Released")) |
|
|
|
|
{ |
|
|
|
|
var exam = await _ghre_ExamServices.QuerySingleDto(x => x.ExamPaperId == id && x.Status == "Released"); |
|
|
|
|
return ServiceResult.OprateFailed($"试卷【{entity.PaperName}({entity.PaperNo})】已与考试【{exam.ExamName}({exam.ExamNo}】关联,暂不可{(status == "Draft" ? "取消发布" : "停用")}"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (await _ghre_ExamRecordServices.AnyAsync(x => x.ExamPaperId == id && x.Status == "UnderWay")) |
|
|
|
|
{ |
|
|
|
|
var exam = await _ghre_ExamRecordServices.QuerySingleDto(x => x.ExamPaperId == id && x.Status == "UnderWay"); |
|
|
|
|
return ServiceResult.OprateFailed($"试卷【{entity.PaperName}({entity.PaperNo})】,当前有学员正在考试中,暂不可{(status == "Draft" ? "取消发布" : "停用")}"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
#endregion |
|
|
|
|
|
|
|
|
|
BasePoco ent = entity; |
|
|
|
|
ent.UpdateIP = ip; |
|
|
|
|
ent.UpdateProg = api; |
|
|
|
@ -755,6 +779,8 @@ delete from Ghre_ExamPaperQuestion WHERE ExamPaperId='{id}';"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var result = await BaseDal.Update(entities); |
|
|
|
|
if (status == "Released") |
|
|
|
|
return ServiceResult.OprateSuccess("发布成功!"); |
|
|
|
@ -831,5 +857,4 @@ delete from Ghre_ExamPaperQuestion WHERE ExamPaperId='{id}';"); |
|
|
|
|
return new ServiceResult<CommonSelect>() { Success = true, Message = "查询成功", Data = result, }; |
|
|
|
|
} |
|
|
|
|
#endregion |
|
|
|
|
} |
|
|
|
|
} |