培训考试

This commit is contained in:
2026-04-21 16:55:59 +08:00
parent d16907d32b
commit caa62a9aeb
6 changed files with 195 additions and 16 deletions
+182 -6
View File
@@ -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
/// <summary>
/// 生成考试试卷【只取培训教材对应题库的题目】
/// </summary>
/// <param name="getCompanyTraining"></param>
/// <param name="testRecordId"></param>
/// <param name="person"></param>
/// <param name="user"></param>
/// <returns></returns>
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<Model.Training_TestTrainingItem> getTestTrainingItemList = new List<Model.Training_TestTrainingItem>();
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;
}
/// <summary>
/// 生成考试试卷【不满25题自动补充,不满足考试规则配置的题目数自动补足】
/// </summary>
/// <param name="getCompanyTraining"></param>
/// <param name="testRecordId"></param>
/// <param name="person"></param>
/// <param name="user"></param>
/// <returns></returns>
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 PersonIdTestPlanId生成试卷
/// <summary>
@@ -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
/// </summary>
/// <param name="testRecordItemId"></param>
/// <param name="answerItems"></param>
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
/// <summary>
/// 根据TestRecordId 提交试卷
/// 根据TestRecordId 提交试卷,获取考试分数
/// </summary>
/// <param name="testRecordId"></param>
public static decimal getSubmitTestRecord(Model.Training_TestRecord testRecord)
@@ -769,7 +915,37 @@ namespace BLL
db.SubmitChanges();
getCode = getTestRecord.TestScores ?? 0;
}
}
return getCode;
}
/// <summary>
/// 根据答题正确数计算考试得分
/// </summary>
/// <param name="testRecord"></param>
/// <returns></returns>
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;