修改公司级培训
This commit is contained in:
@@ -29,7 +29,7 @@ namespace BLL
|
||||
ProjectId = x.ProjectId,
|
||||
TestPlanId = x.TestPlanId,
|
||||
TestManId = x.TestManId,
|
||||
TestManName = db.SitePerson_Person.FirstOrDefault(p => p.PersonId == x.TestManId).PersonName,
|
||||
TestManName = getPname(x.TestManId),
|
||||
TestStartTime = string.Format("{0:yyyy-MM-dd HH:mm}", x.TestStartTime),
|
||||
TestEndTime = string.Format("{0:yyyy-MM-dd HH:mm}", x.TestEndTime),
|
||||
TestScores = x.TestScores ?? 0,
|
||||
@@ -39,6 +39,26 @@ namespace BLL
|
||||
return getDataLists;
|
||||
}
|
||||
}
|
||||
|
||||
private static string getPname(string TestManId) {
|
||||
using (Model.SGGLDB db = new Model.SGGLDB(Funs.ConnString)) {
|
||||
var pname = "";
|
||||
var personModel = db.SitePerson_Person.FirstOrDefault(p => p.PersonId == TestManId);
|
||||
if (personModel==null)
|
||||
{
|
||||
var unameModel = db.Sys_User.FirstOrDefault(p=>p.UserId== TestManId);
|
||||
if (unameModel!=null)
|
||||
{
|
||||
pname = unameModel.UserName;
|
||||
}
|
||||
}
|
||||
else {
|
||||
pname = personModel.PersonName;
|
||||
}
|
||||
|
||||
return pname;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 根据试卷ID获取试卷记录详细
|
||||
@@ -81,7 +101,7 @@ namespace BLL
|
||||
/// </summary>
|
||||
/// <param name="testPlanId"></param>
|
||||
/// <returns></returns>
|
||||
public static string CreateTestRecordItem(Model.Training_TestPlan getTestPlan, string testRecordId, Model.SitePerson_Person person)
|
||||
public static string CreateTestRecordItem(Model.Training_TestPlan getTestPlan, string testRecordId, Model.SitePerson_Person person, Model.Sys_User user)
|
||||
{
|
||||
using (Model.SGGLDB db = new Model.SGGLDB(Funs.ConnString))
|
||||
{
|
||||
@@ -108,9 +128,22 @@ namespace BLL
|
||||
int sumTestType3Count = testPlanTrainings.Sum(x => x.TestType3Count) ?? 0;
|
||||
|
||||
////获取类型下适合岗位试题集合
|
||||
var getTestTrainingItemALLs = from x in db.Training_TestTrainingItem
|
||||
where x.TrainingId != null && (x.WorkPostIds == null || (x.WorkPostIds.Contains(person.WorkPostId) && person.WorkPostId != null))
|
||||
select x;
|
||||
List<Model.Training_TestTrainingItem> getTestTrainingItemALLs;
|
||||
string WorkPostId = "";
|
||||
string DepartId = "";
|
||||
if (person != null)
|
||||
{
|
||||
WorkPostId = person.WorkPostId;
|
||||
}
|
||||
if (user != null)
|
||||
{
|
||||
DepartId = user.DepartId;
|
||||
}
|
||||
|
||||
getTestTrainingItemALLs = (from x in db.Training_TestTrainingItem
|
||||
where x.TrainingId != null && (x.WorkPostIds == null || string.IsNullOrEmpty(WorkPostId) || x.WorkPostIds.Contains(WorkPostId)) || (x.DepartIds == null || string.IsNullOrEmpty(DepartId) || x.DepartIds.Contains(DepartId))
|
||||
|
||||
select x).ToList();
|
||||
foreach (var itemT in testPlanTrainings)
|
||||
{
|
||||
//// 获取类型下的题目
|
||||
@@ -201,12 +234,170 @@ namespace BLL
|
||||
|
||||
db.Training_TestRecordItem.InsertAllOnSubmit(getItems);
|
||||
db.SubmitChanges();
|
||||
BLL.RedisHelper redis = new BLL.RedisHelper();
|
||||
redis.SetObjString(testRecordId, getItems);
|
||||
}
|
||||
}
|
||||
}
|
||||
return testRecordId;
|
||||
}
|
||||
#endregion
|
||||
|
||||
public static string CreateTestRecordItem(Model.Training_CompanyTrainingItem getCompanyTraining, string testRecordId, Model.SitePerson_Person person, Model.Sys_User user)
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
using (Model.SGGLDB db = new Model.SGGLDB(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)
|
||||
{
|
||||
List<Model.Training_TestTrainingItem> getTestTrainingItemList = new List<Model.Training_TestTrainingItem>();
|
||||
//var testPlanTrainings = from x in db.Training_TestPlanTraining
|
||||
// where x.TestPlanId == getTestPlan.TestPlanId
|
||||
// select x;
|
||||
//// 计划考试中单选、多选、判断题总数
|
||||
var sysTestRule = Funs.DB.Sys_TestRule.FirstOrDefault();
|
||||
|
||||
int sumTestType1Count = 0;// testPlanTrainings.Sum(x => x.TestType1Count) ?? 0;
|
||||
int sumTestType2Count = 0;//testPlanTrainings.Sum(x => x.TestType2Count) ?? 0;
|
||||
int sumTestType3Count = 0;//testPlanTrainings.Sum(x => x.TestType3Count) ?? 0;
|
||||
if (sysTestRule != null)
|
||||
{
|
||||
|
||||
sumTestType1Count = sysTestRule.SCount;
|
||||
sumTestType2Count = sysTestRule.MCount;
|
||||
sumTestType3Count = sysTestRule.JCount;
|
||||
}
|
||||
////获取类型下适合岗位试题集合
|
||||
List<Model.Training_TestTrainingItem> getTestTrainingItemALLs;
|
||||
string WorkPostId = "";
|
||||
string DepartId = "";
|
||||
if (person != null)
|
||||
{
|
||||
WorkPostId = person.WorkPostId;
|
||||
}
|
||||
if (user != null)
|
||||
{
|
||||
DepartId = user.DepartId;
|
||||
}
|
||||
|
||||
getTestTrainingItemALLs = (from x in db.Training_TestTrainingItem
|
||||
where x.TrainingId != null && (x.WorkPostIds == null || string.IsNullOrEmpty(WorkPostId) || x.WorkPostIds.Contains(WorkPostId)) || (x.DepartIds == null || string.IsNullOrEmpty(DepartId) || x.DepartIds.Contains(DepartId))
|
||||
select x).ToList();
|
||||
foreach (var itemT in testTrainings)
|
||||
{
|
||||
//// 获取类型下的题目
|
||||
var getTestTrainingItems = getTestTrainingItemALLs.Where(x => x.TrainingId == itemT.TrainingId).ToList();
|
||||
if (getTestTrainingItems.Count() > 0)
|
||||
{
|
||||
////单选题
|
||||
var getSItem = getTestTrainingItems.Where(x => x.TestType == "1").OrderBy(x => Guid.NewGuid()).Take(sumTestType1Count);
|
||||
if (getSItem.Count() > 0)
|
||||
{
|
||||
getTestTrainingItemList.AddRange(getSItem);
|
||||
}
|
||||
///多选题
|
||||
var getMItem = getTestTrainingItems.Where(x => x.TestType == "2").OrderBy(x => Guid.NewGuid()).Take(sumTestType2Count);
|
||||
if (getMItem.Count() > 0)
|
||||
{
|
||||
getTestTrainingItemList.AddRange(getMItem);
|
||||
}
|
||||
///判断题
|
||||
var getJItem = getTestTrainingItems.Where(x => x.TestType == "3").OrderBy(x => Guid.NewGuid()).Take(sumTestType3Count);
|
||||
if (getJItem.Count() > 0)
|
||||
{
|
||||
getTestTrainingItemList.AddRange(getJItem);
|
||||
}
|
||||
}
|
||||
}
|
||||
//// 获取得到的单选题、多选题、判断题 数量
|
||||
int getDiffTestType1Count = sumTestType1Count - getTestTrainingItemList.Where(x => x.TestType == "1").Count();
|
||||
int getDiffTestType2Count = sumTestType2Count - getTestTrainingItemList.Where(x => x.TestType == "2").Count();
|
||||
int getDiffTestType3Count = sumTestType3Count - getTestTrainingItemList.Where(x => x.TestType == "3").Count();
|
||||
if (getDiffTestType1Count > 0 || getDiffTestType2Count > 0 || getDiffTestType3Count > 0)
|
||||
{
|
||||
var getTestTrainingItemNulls = getTestTrainingItemALLs.Where(x => x.WorkPostIds == null).ToList();
|
||||
if (getTestTrainingItemNulls.Count() > 0)
|
||||
{
|
||||
/// 通用且未选择的题目
|
||||
var getTestTrainingItemDiffs = getTestTrainingItemNulls.Except(getTestTrainingItemList).ToList();
|
||||
////单选题
|
||||
if (getDiffTestType1Count > 0)
|
||||
{
|
||||
var getSItemD = getTestTrainingItemDiffs.Where(x => x.TestType == "1").OrderBy(x => Guid.NewGuid()).Take(getDiffTestType1Count);
|
||||
if (getSItemD.Count() > 0)
|
||||
{
|
||||
getTestTrainingItemList.AddRange(getSItemD);
|
||||
}
|
||||
}
|
||||
///多选题
|
||||
if (getDiffTestType2Count > 0)
|
||||
{
|
||||
var getMItemD = getTestTrainingItemDiffs.Where(x => x.TestType == "2").OrderBy(x => Guid.NewGuid()).Take(getDiffTestType2Count);
|
||||
if (getMItemD.Count() > 0)
|
||||
{
|
||||
getTestTrainingItemList.AddRange(getMItemD);
|
||||
}
|
||||
}
|
||||
///判断题
|
||||
if (getDiffTestType3Count > 0)
|
||||
{
|
||||
var getJItemD = getTestTrainingItemDiffs.Where(x => x.TestType == "3").OrderBy(x => Guid.NewGuid()).Take(getDiffTestType3Count);
|
||||
if (getJItemD.Count() > 0)
|
||||
{
|
||||
getTestTrainingItemList.AddRange(getJItemD);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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 = x.TestType == "1" ? sysTestRule.SValue : (x.TestType == "2" ? sysTestRule.MValue : sysTestRule.JValue),
|
||||
};
|
||||
|
||||
db.Training_TestRecordItem.InsertAllOnSubmit(getItems);
|
||||
db.SubmitChanges();
|
||||
BLL.RedisHelper redis = new BLL.RedisHelper();
|
||||
redis.SetObjString(testRecordId, getItems);
|
||||
}
|
||||
}
|
||||
}
|
||||
return testRecordId;
|
||||
}
|
||||
|
||||
|
||||
#region 根据PersonId、TestPlanId生成试卷 扫码生成试卷
|
||||
/// <summary>
|
||||
/// 根据PersonId、TestPlanId生成试卷 扫码生成试卷
|
||||
@@ -673,28 +864,32 @@ namespace BLL
|
||||
/// <param name="testRecord"></param>
|
||||
public static string getResitTestRecord(Model.Training_TestRecord getTestRecord)
|
||||
{
|
||||
Model.Training_TestRecord newTestRecord = new Model.Training_TestRecord
|
||||
using (var db = new Model.SGGLDB(Funs.ConnString))
|
||||
{
|
||||
TestRecordId = SQLHelper.GetNewID(),
|
||||
ProjectId = getTestRecord.ProjectId,
|
||||
TestPlanId = getTestRecord.TestPlanId,
|
||||
TestManId = getTestRecord.TestManId,
|
||||
TestType = getTestRecord.TestType,
|
||||
TemporaryUser = getTestRecord.TemporaryUser,
|
||||
Duration = getTestRecord.Duration,
|
||||
// TestStartTime = DateTime.Now,
|
||||
};
|
||||
Model.Training_TestRecord newTestRecord = new Model.Training_TestRecord
|
||||
{
|
||||
TestRecordId = SQLHelper.GetNewID(),
|
||||
ProjectId = getTestRecord.ProjectId,
|
||||
TestPlanId = getTestRecord.TestPlanId,
|
||||
TestManId = getTestRecord.TestManId,
|
||||
TestType = getTestRecord.TestType,
|
||||
TemporaryUser = getTestRecord.TemporaryUser,
|
||||
Duration = getTestRecord.Duration,
|
||||
// TestStartTime = DateTime.Now,
|
||||
};
|
||||
|
||||
Funs.DB.Training_TestRecord.InsertOnSubmit(newTestRecord);
|
||||
Funs.DB.SubmitChanges();
|
||||
db.Training_TestRecord.InsertOnSubmit(newTestRecord);
|
||||
db.SubmitChanges();
|
||||
|
||||
var getTestPlan = Funs.DB.Training_TestPlan.FirstOrDefault(x => x.TestPlanId == newTestRecord.TestPlanId);
|
||||
var person = PersonService.GetPersonByUserId(newTestRecord.TestManId, getTestPlan.ProjectId);
|
||||
if (getTestPlan != null && person != null)
|
||||
{
|
||||
CreateTestRecordItem(getTestPlan, newTestRecord.TestRecordId, person);
|
||||
var getTestPlan = db.Training_TestPlan.FirstOrDefault(x => x.TestPlanId == newTestRecord.TestPlanId);
|
||||
var user = db.Sys_User.FirstOrDefault(x => x.UserId == newTestRecord.TestManId);
|
||||
var person = PersonService.GetPersonByUserIdForApi(newTestRecord.TestManId, getTestPlan.ProjectId);
|
||||
if (getTestPlan != null && person != null)
|
||||
{
|
||||
CreateTestRecordItem(getTestPlan, newTestRecord.TestRecordId, person, user);
|
||||
}
|
||||
return newTestRecord.TestRecordId;
|
||||
}
|
||||
return newTestRecord.TestRecordId;
|
||||
}
|
||||
#endregion
|
||||
|
||||
@@ -765,5 +960,7 @@ namespace BLL
|
||||
return getDataLists.ToList();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user