From caa62a9aeb52e31fe3c7ee3e126fa74b88565005 Mon Sep 17 00:00:00 2001 From: xiaju <1784803958@qq.com> Date: Tue, 21 Apr 2026 16:55:59 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9F=B9=E8=AE=AD=E8=80=83=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SGGL/BLL/API/HSSE/APITestRecordService.cs | 188 +++++++++++++++++- .../HSSE/EduTrain/TestRecord.aspx | 6 +- .../HSSE/EduTrain/TestRecord.aspx.cs | 9 +- .../HSSE/EduTrain/TestRecordItem.aspx | 2 +- .../Controllers/HSSE/TestPlanController.cs | 4 +- .../HSSE/TrainingTaskController.cs | 2 +- 6 files changed, 195 insertions(+), 16 deletions(-) diff --git a/SGGL/BLL/API/HSSE/APITestRecordService.cs b/SGGL/BLL/API/HSSE/APITestRecordService.cs index 20f9aa31..812f397d 100644 --- a/SGGL/BLL/API/HSSE/APITestRecordService.cs +++ b/SGGL/BLL/API/HSSE/APITestRecordService.cs @@ -1,5 +1,8 @@ using EmitMapper; using EmitMapper.MappingConfiguration; +using FastReport.Data; +using Microsoft.SqlServer.Dts.Runtime; +using Model; using System; using System.Collections.Generic; using System.Linq; @@ -76,7 +79,16 @@ namespace BLL } #endregion + #region 生成考试试卷 + /// + /// 生成考试试卷【只取培训教材对应题库的题目】 + /// + /// + /// + /// + /// + /// public static string CreateTestRecordItem(Model.Training_CompanyTrainingItem getCompanyTraining, string testRecordId, Model.SitePerson_Person person, Model.Sys_User user) { using (Model.CNPCDB db = new Model.CNPCDB(Funs.ConnString)) @@ -92,6 +104,75 @@ namespace BLL db.SubmitChanges(); } + ////当前人考试记录 未加入考试计划的 当考试开始扫码时 不允许再参与考试 + var item = db.Training_TestRecordItem.FirstOrDefault(x => x.TestRecordId == getTestRecord.TestRecordId); + if (item == null) + { + List getTestTrainingItemList = new List(); + foreach (var itemT in testTrainings) + { + //// 获取类型下的题目 + var getTestTrainingItems = db.Training_TestTrainingItem.Where(x => x.TrainingId == itemT.TrainingId).ToList(); + if (getTestTrainingItems.Count() > 0) + { + getTestTrainingItemList.AddRange(getTestTrainingItems); + } + } + double totalScore = 100;//试卷满分 + if (getTestTrainingItemList.Count() > 0) + { + var getItems = from x in getTestTrainingItemList + select new Model.Training_TestRecordItem + { + TestRecordItemId = SQLHelper.GetNewID(), + TestRecordId = getTestRecord.TestRecordId, + TrainingItemName = x.TrainingItemName, + TrainingItemCode = x.TrainingItemCode, + Abstracts = x.Abstracts, + AttachUrl = x.AttachUrl, + TestType = x.TestType, + AItem = x.AItem, + BItem = x.BItem, + CItem = x.CItem, + DItem = x.DItem, + EItem = x.EItem, + AnswerItems = x.AnswerItems, + Score = (int)Math.Floor(totalScore / getTestTrainingItemList.Count()), + }; + + db.Training_TestRecordItem.InsertAllOnSubmit(getItems); + db.SubmitChanges(); + BLL.RedisHelper redis = new BLL.RedisHelper(); + redis.SetObjString(testRecordId, getItems); + } + } + } + return testRecordId; + } + + /// + /// 生成考试试卷【不满25题自动补充,不满足考试规则配置的题目数自动补足】 + /// + /// + /// + /// + /// + /// + public static string CreateTestRecordItemOld(Model.Training_CompanyTrainingItem getCompanyTraining, string testRecordId, Model.SitePerson_Person person, Model.Sys_User user) + { + using (Model.CNPCDB db = new Model.CNPCDB(Funs.ConnString)) + { + var trainingIds = getCompanyTraining.TestTrainingIds.Split(','); + var testTrainings = db.Training_TestTraining.Where(x => trainingIds.Contains(x.TrainingId)); + var getTestRecord = db.Training_TestRecord.FirstOrDefault(x => x.TestRecordId == testRecordId); + if (getTestRecord != null && !getTestRecord.TestStartTime.HasValue) + { + ////考试时长 + getTestRecord.Duration = 120; + getTestRecord.TestStartTime = DateTime.Now; + db.SubmitChanges(); + } + ////当前人考试记录 未加入考试计划的 当考试开始扫码时 不允许再参与考试 var item = db.Training_TestRecordItem.FirstOrDefault(x => x.TestRecordId == getTestRecord.TestRecordId); if (item == null) @@ -227,6 +308,7 @@ namespace BLL return testRecordId; } + #endregion #region 根据PersonId、TestPlanId生成试卷 扫码生成试卷 /// @@ -504,8 +586,12 @@ namespace BLL using (Model.CNPCDB db = new Model.CNPCDB(Funs.ConnString)) { var getDataLists = (from x in db.Training_TestRecord - join y in db.Training_TestPlan on x.TestPlanId equals y.TestPlanId into yGroup - from y in yGroup.DefaultIfEmpty() + //join y in db.Training_TestPlan on x.TestPlanId equals y.TestPlanId into yGroup + //from y in yGroup.DefaultIfEmpty() + join z in db.Training_CompanyTrainingItem on x.CompanyTrainingItemId equals z.CompanyTrainingItemId into zGroup + from z in zGroup.DefaultIfEmpty() + join w in db.Training_CompanyTraining on z.CompanyTrainingId equals w.CompanyTrainingId into wGroup + from w in wGroup.DefaultIfEmpty() where x.ProjectId == projectId && x.TestManId == personId && x.TestStartTime.HasValue orderby x.TestStartTime descending select new Model.TestRecordItem @@ -513,14 +599,16 @@ namespace BLL TestRecordId = x.TestRecordId, ProjectId = x.ProjectId, TestPlanId = x.TestPlanId, - TestPlanName = y.PlanName, + TestPlanName = $"{w.CompanyTrainingName}——{z.CompanyTrainingItemName}", + //TestPlanName = y.PlanName, TestManId = x.TestManId, TestManName = db.SitePerson_Person.FirstOrDefault(p => p.PersonId == x.TestManId).PersonName, TestStartTime = string.Format("{0:yyyy-MM-dd HH:mm}", x.TestStartTime), TestEndTime = string.Format("{0:yyyy-MM-dd HH:mm}", x.TestEndTime), Duration = x.Duration, TestPlanEndTime = string.Format("{0:yyyy-MM-dd HH:mm}", x.TestStartTime.Value.AddMinutes(x.Duration)), - TotalScore = y.TotalScore ?? 0, + TotalScore = 100, + //TotalScore = y.TotalScore ?? 0, TestScores = x.TestScores ?? 0, TestType = x.TestType, TemporaryUser = x.TemporaryUser, @@ -696,7 +784,7 @@ namespace BLL /// /// /// - public static void getTestRecordItemAnswerBySelectedItem(Model.Training_TestRecordItem getTItemT, string selectedItem) + public static void getTestRecordItemAnswerBySelectedItemOld(Model.Training_TestRecordItem getTItemT, string selectedItem) { using (Model.CNPCDB db = new Model.CNPCDB(Funs.ConnString)) { @@ -744,11 +832,69 @@ namespace BLL } } } + + + + + public static void getTestRecordItemAnswerBySelectedItem(Model.Training_TestRecordItem getTItemT, string selectedItem) + { + using (Model.CNPCDB db = new Model.CNPCDB(Funs.ConnString)) + { + var getTItem = db.Training_TestRecordItem.FirstOrDefault(x => x.TestRecordItemId == getTItemT.TestRecordItemId); + if (getTItem != null) + { + selectedItem = selectedItem.ToUpper(); + getTItem.AnswerItems = getTItem.AnswerItems.ToUpper(); + getTItem.SubjectScore = 0; + getTItem.SelectedItem = selectedItem; + if (!string.IsNullOrEmpty(selectedItem)) + { + if (getTItem.AnswerItems == selectedItem) + { + getTItem.SubjectScore = getTItem.Score ?? 0; + } + else + { + var listA = Funs.GetStrListByStr(getTItem.AnswerItems, ','); + var listS = Funs.GetStrListByStr(selectedItem, ','); + if (getTItem.TestType == "2" && listA.Count >= listS.Count) + { + int i = 0; + foreach (var item in listS) + { + if (listA.Contains(item)) + { + i++; + } + } + if (i > 0) + { + if (listA.Count == listS.Count) + { + getTItem.SubjectScore = getTItem.Score ?? 0; + } + else + { + //getTItem.SubjectScore = Convert.ToDecimal((getTItem.Score ?? 0) * 1.0 / 2); + + var result = (double)((double)i / (double)listA.Count) * getTItem.Score; + getTItem.SubjectScore = Math.Round((decimal)result, 2); + } + } + } + } + } + db.SubmitChanges(); + } + } + } + + #endregion #region 根据TestRecordId 提交试卷 /// - /// 根据TestRecordId 提交试卷 + /// 根据TestRecordId 提交试卷,获取考试分数 /// /// public static decimal getSubmitTestRecord(Model.Training_TestRecord testRecord) @@ -769,7 +915,37 @@ namespace BLL db.SubmitChanges(); getCode = getTestRecord.TestScores ?? 0; + } + } + return getCode; + } + /// + /// 根据答题正确数计算考试得分 + /// + /// + /// + public static decimal getSubmitTestRecordByAnswer(Model.Training_TestRecord testRecord) + { + decimal getCode = 0; + using (Model.CNPCDB db = new Model.CNPCDB(Funs.ConnString)) + { + var getTestRecord = db.Training_TestRecord.FirstOrDefault(e => e.TestRecordId == testRecord.TestRecordId); + /////试卷 + if (getTestRecord.TestStartTime.HasValue) + { + getTestRecord.TestEndTime = DateTime.Now; + var getRItem = db.Training_TestRecordItem.Where(x => x.TestRecordId == getTestRecord.TestRecordId); + var getROKItem = db.Training_TestRecordItem.Where(x => x.TestRecordId == getTestRecord.TestRecordId && x.AnswerItems == x.SelectedItem); + if (getRItem.Count() > 0) + { + //getTestRecord.TestScores = getRItem.Sum(x => x.SubjectScore); + decimal result = (decimal)(getROKItem.Count() / getRItem.Count()); + getTestRecord.TestScores = Math.Round(result, 2); + } + db.SubmitChanges(); + + getCode = getTestRecord.TestScores ?? 0; } } return getCode; diff --git a/SGGL/FineUIPro.Web/HSSE/EduTrain/TestRecord.aspx b/SGGL/FineUIPro.Web/HSSE/EduTrain/TestRecord.aspx index 49503b09..3adeddf8 100644 --- a/SGGL/FineUIPro.Web/HSSE/EduTrain/TestRecord.aspx +++ b/SGGL/FineUIPro.Web/HSSE/EduTrain/TestRecord.aspx @@ -82,7 +82,7 @@ - - - + --%> <%-- --%> diff --git a/SGGL/FineUIPro.Web/HSSE/EduTrain/TestRecord.aspx.cs b/SGGL/FineUIPro.Web/HSSE/EduTrain/TestRecord.aspx.cs index 3c9b91de..f18fa768 100644 --- a/SGGL/FineUIPro.Web/HSSE/EduTrain/TestRecord.aspx.cs +++ b/SGGL/FineUIPro.Web/HSSE/EduTrain/TestRecord.aspx.cs @@ -115,12 +115,15 @@ namespace FineUIPro.Web.HSSE.EduTrain return; } string strSql = @"SELECT TestRecord.TestRecordId,TestRecord.TestPlanId, TestRecord.TestManId,TestRecord.TestStartTime,TestRecord.TestEndTime, TestRecord.TestScores, - (CASE WHEN TestPlan.PlanName IS NULL THEN Training.TrainingName ELSE TestPlan.PlanName END) AS PlanName, - ISNULL(TestPlan.Duration,90) AS Duration,ISNULL(TestPlan.TotalScore,100) AS TotalScore,TestPlan.TestPalce,ISNULL(TestPlan.QuestionCount,95) AS QuestionCount,TestRecord.TemporaryUser,Person.PersonName AS TestManName + --(CASE WHEN TestPlan.PlanName IS NULL THEN Training.TrainingName ELSE TestPlan.PlanName END) AS PlanName, + TC.CompanyTrainingName +'——'+TCItem.CompanyTrainingItemName AS PlanName, + ISNULL(TestPlan.Duration,120) AS Duration,ISNULL(TestPlan.TotalScore,100) AS TotalScore,TestPlan.TestPalce,ISNULL(TestPlan.QuestionCount,95) AS QuestionCount,TestRecord.TemporaryUser,Person.PersonName AS TestManName ,Unit.UnitName" + @" FROM dbo.Training_TestRecord AS TestRecord" + @" LEFT JOIN dbo.Training_TestPlan AS TestPlan ON TestPlan.TestPlanId=TestRecord.TestPlanId" - + @" LEFT JOIN dbo.Training_TestTraining AS Training ON Training.TrainingId = TestRecord.TestType" + //+ @" LEFT JOIN dbo.Training_TestTraining AS Training ON Training.TrainingId = TestRecord.TestType" + + @" LEFT JOIN dbo.Training_CompanyTrainingItem AS TCItem ON TCItem.CompanyTrainingItemId = TestRecord.CompanyTrainingItemId" + + @" LEFT JOIN dbo.Training_CompanyTraining AS TC ON TC.CompanyTrainingId = TCItem.CompanyTrainingId" + @" LEFT JOIN dbo.SitePerson_Person AS Person ON Person.PersonId = TestRecord.TestManId " + @" LEFT JOIN dbo.Base_Unit AS Unit ON Person.UnitId=Unit.UnitId" + @" WHERE TestRecord.TestStartTime is not null and (isFiled IS NULL OR isFiled = 0) "; diff --git a/SGGL/FineUIPro.Web/HSSE/EduTrain/TestRecordItem.aspx b/SGGL/FineUIPro.Web/HSSE/EduTrain/TestRecordItem.aspx index f4d1bebc..a378737d 100644 --- a/SGGL/FineUIPro.Web/HSSE/EduTrain/TestRecordItem.aspx +++ b/SGGL/FineUIPro.Web/HSSE/EduTrain/TestRecordItem.aspx @@ -77,7 +77,7 @@ - diff --git a/SGGL/WebAPI/Controllers/HSSE/TestPlanController.cs b/SGGL/WebAPI/Controllers/HSSE/TestPlanController.cs index 5959e74e..cf137b7d 100644 --- a/SGGL/WebAPI/Controllers/HSSE/TestPlanController.cs +++ b/SGGL/WebAPI/Controllers/HSSE/TestPlanController.cs @@ -294,9 +294,9 @@ namespace WebAPI.Controllers #endregion /// - /// companyTrainingItemCode、personId、projectId获取考试记录id + /// 根据companyTrainingItemCode、personId、projectId生成、获取考试记录id /// - /// + /// 培训课程教材Code /// /// /// diff --git a/SGGL/WebAPI/Controllers/HSSE/TrainingTaskController.cs b/SGGL/WebAPI/Controllers/HSSE/TrainingTaskController.cs index 12739596..cdc84403 100644 --- a/SGGL/WebAPI/Controllers/HSSE/TrainingTaskController.cs +++ b/SGGL/WebAPI/Controllers/HSSE/TrainingTaskController.cs @@ -31,7 +31,7 @@ namespace WebAPI.Controllers int pageCount = getQualityLists.Count; if (pageCount > 0 && pageIndex > 0) { - var getdata = from x in getQualityLists.OrderByDescending(u => u.TrainStartDate).Skip(BLL.Funs.PageSize * (pageIndex - 1)).Take(BLL.Funs.PageSize) + var getdata = from x in getQualityLists.OrderByDescending(u => u.TrainStartDate).OrderBy(u => u.TrainingItemCode).Skip(BLL.Funs.PageSize * (pageIndex - 1)).Take(BLL.Funs.PageSize) select x; responeData.data = new { pageCount, getdata }; }