1代码合并
This commit is contained in:
@@ -74,46 +74,29 @@ namespace WebAPI.Controllers
|
||||
/// <param name="trainingPlanId">培训计划ID</param>
|
||||
/// <param name="userId">用户ID</param>
|
||||
/// <returns></returns>
|
||||
public Model.ResponeData getSaveTestPlanByTrainingPlanId(string trainingPlanId, string userId)
|
||||
public Model.ResponeData getSaveTestPlanByTrainingPlanId(string trainingPlanId,string userId)
|
||||
{
|
||||
var responeData = new Model.ResponeData();
|
||||
try
|
||||
{
|
||||
using (Model.SGGLDB db = new Model.SGGLDB(Funs.ConnString))
|
||||
var getTasks = new Model.SGGLDB(Funs.ConnString).Training_Task.FirstOrDefault(x => x.PlanId == trainingPlanId);
|
||||
if (getTasks != null)
|
||||
{
|
||||
var getTasks = db.Training_Task.FirstOrDefault(x => x.PlanId == trainingPlanId);
|
||||
if (getTasks != null)
|
||||
if (CommonService.IsMainUnitOrAdmin(userId))
|
||||
{
|
||||
bool result = false;
|
||||
if (userId == Const.sysglyId || userId == Const.hfnbdId)
|
||||
{
|
||||
result = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
var user = db.Sys_User.FirstOrDefault(e => e.UserId == userId);
|
||||
if (user != null && user.UnitId == CommonService.GetThisUnitId())
|
||||
{
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
if (result)
|
||||
//if (CommonService.IsMainUnitOrAdmin(userId))
|
||||
{
|
||||
responeData.data = APITestPlanService.SaveTestPlanByTrainingPlanId(trainingPlanId, userId);
|
||||
}
|
||||
else
|
||||
{
|
||||
responeData.code = 0;
|
||||
responeData.message = "非本单位用户,不能生成考试计划!";
|
||||
}
|
||||
responeData.data = APITestPlanService.SaveTestPlanByTrainingPlanId(trainingPlanId, userId);
|
||||
}
|
||||
else
|
||||
{
|
||||
responeData.code = 0;
|
||||
responeData.message = "培训计划下没有培训人员,不能生成考试计划!";
|
||||
responeData.message = "非本单位用户,不能生成考试计划!";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
responeData.code = 0;
|
||||
responeData.message = "培训计划下没有培训人员,不能生成考试计划!";
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -209,89 +192,45 @@ namespace WebAPI.Controllers
|
||||
var responeData = new Model.ResponeData();
|
||||
try
|
||||
{
|
||||
using (var db = new Model.SGGLDB(Funs.ConnString))
|
||||
var getTestPlan = new Model.SGGLDB(Funs.ConnString).Training_TestPlan.FirstOrDefault(e => e.TestPlanId == testPlanId && e.States != "3" && e.TestStartTime <= DateTime.Now && e.TestEndTime >= DateTime.Now);
|
||||
if (getTestPlan != null)
|
||||
{
|
||||
var getTestPlan = db.Training_TestPlan.FirstOrDefault(e => e.TestPlanId == testPlanId && e.States != "3" && e.TestStartTime <= DateTime.Now && e.TestEndTime >= DateTime.Now);
|
||||
if (getTestPlan != null)
|
||||
var person = PersonService.GetPersonByUserId(personId, getTestPlan.ProjectId);
|
||||
if (person != null )
|
||||
{
|
||||
var user = db.Sys_User.FirstOrDefault(x => x.UserId == personId);
|
||||
Model.SitePerson_Person person;
|
||||
if (user != null)
|
||||
//2-考试中;生成考试试卷
|
||||
if (getTestPlan.States == "2" )
|
||||
{
|
||||
person = db.SitePerson_Person.FirstOrDefault(e => (e.PersonId == personId || e.IdentityCard == user.IdentityCard) && e.ProjectId == getTestPlan.ProjectId);// PersonService.GetPersonByUserId(personId, getTestPlan.ProjectId);
|
||||
var testRecord = new Model.SGGLDB(Funs.ConnString).Training_TestRecord.FirstOrDefault(x => x.TestPlanId == getTestPlan.TestPlanId && x.TestManId == person.PersonId && !x.TestEndTime.HasValue);
|
||||
if (testRecord != null)
|
||||
{
|
||||
string testRecordId = APITestRecordService.CreateTestRecordItem(getTestPlan, testRecord.TestRecordId, person);
|
||||
responeData.code = 2;
|
||||
responeData.data = new { testRecordId };
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
person = db.SitePerson_Person.FirstOrDefault(e => e.PersonId == personId && e.ProjectId == getTestPlan.ProjectId);// PersonService.GetPersonByUserId(personId, getTestPlan.ProjectId);
|
||||
|
||||
}
|
||||
if (person != null || user != null)
|
||||
{
|
||||
//2-考试中;生成考试试卷
|
||||
if (getTestPlan.States == "2")
|
||||
if (string.IsNullOrEmpty(getTestPlan.PlanId) && getTestPlan.UnitIds.Contains(person.UnitId) && (getTestPlan.WorkPostIds == null || getTestPlan.WorkPostIds.Contains(person.WorkPostId)))
|
||||
{
|
||||
var testRecord = db.Training_TestRecord.FirstOrDefault(x => x.TestPlanId == getTestPlan.TestPlanId && x.TestManId == personId && !x.TestEndTime.HasValue);
|
||||
if (testRecord != null)
|
||||
//0-待提交;1-已发布未考试 将人员添加进考试记录
|
||||
var testTRecord = new Model.SGGLDB(Funs.ConnString).Training_TestRecord.FirstOrDefault(x => x.TestPlanId == testPlanId && x.TestManId == personId);
|
||||
if ((getTestPlan.States == "0" || getTestPlan.States == "1") && testTRecord == null && !string.IsNullOrEmpty(personId))
|
||||
{
|
||||
string testRecordId = APITestRecordService.CreateTestRecordItem(getTestPlan, testRecord.TestRecordId, person, user);
|
||||
responeData.code = 2;
|
||||
responeData.data = new { testRecordId };
|
||||
}
|
||||
else if (person != null)
|
||||
{
|
||||
var testRecord2 = db.Training_TestRecord.FirstOrDefault(x => x.TestPlanId == getTestPlan.TestPlanId && x.TestManId == person.PersonId && !x.TestEndTime.HasValue);
|
||||
if (testRecord2 != null)
|
||||
Model.Training_TestRecord newTestRecord = new Model.Training_TestRecord
|
||||
{
|
||||
string testRecordId = APITestRecordService.CreateTestRecordItem(getTestPlan, testRecord2.TestRecordId, person, user);
|
||||
responeData.code = 2;
|
||||
responeData.data = new { testRecordId };
|
||||
}
|
||||
TestRecordId = SQLHelper.GetNewID(),
|
||||
ProjectId = getTestPlan.ProjectId,
|
||||
TestPlanId = getTestPlan.TestPlanId,
|
||||
TestManId = personId,
|
||||
};
|
||||
TestRecordService.AddTestRecord(newTestRecord);
|
||||
responeData.code = 3;
|
||||
responeData.message = "您已加入考试计划!";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (person != null && string.IsNullOrEmpty(getTestPlan.PlanId) && getTestPlan.UnitIds.Contains(person.UnitId) && (getTestPlan.WorkPostIds == null || getTestPlan.WorkPostIds.Contains(person.WorkPostId)))
|
||||
{
|
||||
//0-待提交;1-已发布未考试 将人员添加进考试记录
|
||||
var testTRecord = db.Training_TestRecord.FirstOrDefault(x => x.TestPlanId == testPlanId && x.TestManId == person.PersonId);
|
||||
if ((getTestPlan.States == "0" || getTestPlan.States == "1") && testTRecord == null && !string.IsNullOrEmpty(personId))
|
||||
{
|
||||
Model.Training_TestRecord newTestRecord = new Model.Training_TestRecord
|
||||
{
|
||||
TestRecordId = SQLHelper.GetNewID(),
|
||||
ProjectId = getTestPlan.ProjectId,
|
||||
TestPlanId = getTestPlan.TestPlanId,
|
||||
TestManId = personId,
|
||||
};
|
||||
TestRecordService.AddTestRecordForApi(newTestRecord);
|
||||
responeData.code = 3;
|
||||
responeData.message = "您已加入考试计划!";
|
||||
}
|
||||
}
|
||||
|
||||
if (user != null && string.IsNullOrEmpty(getTestPlan.PlanId) && getTestPlan.UnitIds.Contains(user.UnitId) && (getTestPlan.DepartIds == null || getTestPlan.DepartIds.Contains(user.DepartId)))
|
||||
{
|
||||
//0-待提交;1-已发布未考试 将人员添加进考试记录
|
||||
var testTRecord = db.Training_TestRecord.FirstOrDefault(x => x.TestPlanId == testPlanId && x.TestManId == personId);
|
||||
if ((getTestPlan.States == "0" || getTestPlan.States == "1") && testTRecord == null && !string.IsNullOrEmpty(personId))
|
||||
{
|
||||
Model.Training_TestRecord newTestRecord = new Model.Training_TestRecord
|
||||
{
|
||||
TestRecordId = SQLHelper.GetNewID(),
|
||||
ProjectId = getTestPlan.ProjectId,
|
||||
TestPlanId = getTestPlan.TestPlanId,
|
||||
TestManId = personId,
|
||||
};
|
||||
TestRecordService.AddTestRecordForApi(newTestRecord);
|
||||
responeData.code = 3;
|
||||
responeData.message = "您已加入考试计划!";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (responeData.code == 1)
|
||||
@@ -353,83 +292,6 @@ namespace WebAPI.Controllers
|
||||
}
|
||||
#endregion
|
||||
|
||||
public Model.ResponeData getTrainingPlanTestRecordItemByTestPlanIdPersonId(string companyTrainingItemCode, string personId, string projectId)
|
||||
{
|
||||
var responeData = new Model.ResponeData();
|
||||
try
|
||||
{
|
||||
using (var db = new Model.SGGLDB(Funs.ConnString))
|
||||
{
|
||||
var getCompanyTraining = db.Training_CompanyTrainingItem.FirstOrDefault(e => e.CompanyTrainingItemCode == companyTrainingItemCode);
|
||||
if (getCompanyTraining != null)
|
||||
{
|
||||
var user = db.Sys_User.FirstOrDefault(x => x.UserId == personId);
|
||||
Model.SitePerson_Person person;
|
||||
if (user != null)
|
||||
{
|
||||
person = db.SitePerson_Person.FirstOrDefault(e => (e.PersonId == personId || e.IdentityCard == user.IdentityCard) && e.ProjectId == projectId);// PersonService.GetPersonByUserId(personId, getTestPlan.ProjectId);
|
||||
}
|
||||
else
|
||||
{
|
||||
person = db.SitePerson_Person.FirstOrDefault(e => e.PersonId == personId && e.ProjectId == projectId);// PersonService.GetPersonByUserId(personId, getTestPlan.ProjectId);
|
||||
|
||||
}
|
||||
if (person != null || user != null)
|
||||
{
|
||||
var testRecord = db.Training_TestRecord.FirstOrDefault(x => x.CompanyTrainingItemId == getCompanyTraining.CompanyTrainingItemId && x.TestManId == personId && !x.TestEndTime.HasValue);
|
||||
if (testRecord != null)
|
||||
{
|
||||
string testRecordId = APITestRecordService.CreateTestRecordItem(getCompanyTraining, testRecord.TestRecordId, person, user);
|
||||
responeData.code = 2;
|
||||
responeData.data = new { testRecordId };
|
||||
}
|
||||
else if (person != null)
|
||||
{
|
||||
var testRecord2 = db.Training_TestRecord.FirstOrDefault(x => x.CompanyTrainingItemId == getCompanyTraining.CompanyTrainingItemId && x.TestManId == person.PersonId && !x.TestEndTime.HasValue);
|
||||
if (testRecord2 != null)
|
||||
{
|
||||
string testRecordId = APITestRecordService.CreateTestRecordItem(getCompanyTraining, testRecord2.TestRecordId, person, user);
|
||||
responeData.code = 2;
|
||||
responeData.data = new { testRecordId };
|
||||
}
|
||||
else
|
||||
{
|
||||
Model.Training_TestRecord training_TestRecord = new Model.Training_TestRecord();
|
||||
training_TestRecord.TestRecordId = Guid.NewGuid().ToString();
|
||||
training_TestRecord.ProjectId = projectId;
|
||||
training_TestRecord.CompanyTrainingItemId = getCompanyTraining.CompanyTrainingItemId;
|
||||
training_TestRecord.TestManId = person.PersonId;
|
||||
db.Training_TestRecord.InsertOnSubmit(training_TestRecord);
|
||||
db.SubmitChanges();
|
||||
string testRecordId = APITestRecordService.CreateTestRecordItem(getCompanyTraining, training_TestRecord.TestRecordId, person, user);
|
||||
responeData.code = 2;
|
||||
responeData.data = new { testRecordId };
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Model.Training_TestRecord training_TestRecord = new Model.Training_TestRecord();
|
||||
training_TestRecord.TestRecordId = Guid.NewGuid().ToString();
|
||||
training_TestRecord.ProjectId = projectId;
|
||||
training_TestRecord.CompanyTrainingItemId = getCompanyTraining.CompanyTrainingItemId;
|
||||
training_TestRecord.TestManId = user.UserId;
|
||||
db.Training_TestRecord.InsertOnSubmit(training_TestRecord);
|
||||
db.SubmitChanges();
|
||||
string testRecordId = APITestRecordService.CreateTestRecordItem(getCompanyTraining, training_TestRecord.TestRecordId, person, user);
|
||||
responeData.code = 2;
|
||||
responeData.data = new { testRecordId };
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
responeData.code = 0;
|
||||
responeData.message = ex.Message;
|
||||
}
|
||||
return responeData;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user