From 4b30ebe974089b8626dbaa004b0e27543dab2233 Mon Sep 17 00:00:00 2001 From: xiaochanghai Date: Tue, 18 Jun 2024 16:15:03 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AF=95=E5=8D=B7=E5=88=87=E6=8D=A2=E8=AF=BE?= =?UTF-8?q?=E7=A8=8B=E9=80=89=E6=8B=A9=20=E5=8F=96=E6=B6=88=E8=AF=BE?= =?UTF-8?q?=E7=A8=8B=E4=B8=8E=E8=AF=95=E5=8D=B7=E5=85=B3=E7=B3=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Ghre/Ghre_ExamPaperServices.cs | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/Tiobon.Core.Services/Ghre/Ghre_ExamPaperServices.cs b/Tiobon.Core.Services/Ghre/Ghre_ExamPaperServices.cs index 127190b5..628c5058 100644 --- a/Tiobon.Core.Services/Ghre/Ghre_ExamPaperServices.cs +++ b/Tiobon.Core.Services/Ghre/Ghre_ExamPaperServices.cs @@ -5,10 +5,12 @@ 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; using Tiobon.Core.Common.Caches; +using Tiobon.Core.Common.Helper; using Tiobon.Core.Common.UserManager; using Tiobon.Core.IRepository.Base; using Tiobon.Core.IServices; @@ -663,7 +665,7 @@ namespace Tiobon.Core.Services delete from Ghre_ExamPaperQuestion WHERE ExamPaperId='{id}';"); var insert = new EditGhre_ExamPaperInput(); - + var paper = await base.QueryById(id); insert = Mapper.Map(insertModel.baseData).ToANew(); insert.PaperNo = await GenerateContinuousSequence("Ghre_ExamPaper", "PaperNo", "P"); insert.LinkId = insertModel.baseData.LinkType == "CourseId" ? insertModel.baseData.CourseId : insertModel.baseData.CourseSceneId; @@ -673,6 +675,24 @@ delete from Ghre_ExamPaperQuestion WHERE ExamPaperId='{id}';"); insert.SetMethod = insertModel.examPaperSetType; insert.Status = "Draft"; + + #region 串联试卷和课程关系 + if ( + (insert.LinkType == "CourseId" && insert.LinkType == paper.LinkType && paper.LinkId != insert.LinkId) || + (insert.LinkType == "CourseSceneId" && insert.LinkType != paper.LinkType) + ) + { + var courses = await _ghre_CourseServices.Query(x =>x.Id == paper.LinkId && x.ExamPaperId.Contains(id.ObjToString())); + courses.ForEach(async x => + { + var ids = JsonHelper.JsonToObj>(x.ExamPaperId); + ids = ids.Where(o => o != id).ToList(); + x.ExamPaperId = JsonHelper.ObjToJson(ids); + await Db.Updateable(x).UpdateColumns(it => new { it.ExamPaperId }).ExecuteCommandAsync(); + }); + } + #endregion + await Update(id, insert); var configs = Mapper.Map(insertModel.examPaperSetData).ToANew>(); configs.ForEach(x => x.ExamPaperId = id);