327 lines
16 KiB
C#
327 lines
16 KiB
C#
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Linq;
|
|||
|
using System.Text;
|
|||
|
using System.Threading.Tasks;
|
|||
|
using EmitMapper;
|
|||
|
using EmitMapper.MappingConfiguration;
|
|||
|
|
|||
|
namespace BLL
|
|||
|
{
|
|||
|
public static class APITrainRecordService
|
|||
|
{
|
|||
|
#region 根据培训Id获取培训教材
|
|||
|
public class CompanyTrainingItemModel {
|
|||
|
public string CompanyTrainingItemId { get; set; }
|
|||
|
|
|||
|
public string CompanyTrainingItemName { get; set; }
|
|||
|
|
|||
|
public string trainRecordId { get; set; }
|
|||
|
}
|
|||
|
public static List<CompanyTrainingItemModel> getTraining_CompanyTrainingItemByPlanId(string trainRecordId) {
|
|||
|
using (Model.SUBQHSEDB db = new Model.SUBQHSEDB(Funs.ConnString)) {
|
|||
|
var getDataLists = (from x in db.Training_PlanItem
|
|||
|
where x.PlanId== trainRecordId
|
|||
|
select new CompanyTrainingItemModel() {
|
|||
|
CompanyTrainingItemId=x.CompanyTrainingItemId,
|
|||
|
CompanyTrainingItemName= getTrainingItemName(x.CompanyTrainingItemId),
|
|||
|
trainRecordId= trainRecordId
|
|||
|
}).ToList();
|
|||
|
return getDataLists;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public static string getTrainingItemName(string id) {
|
|||
|
var model = Funs.DB.Training_CompanyTrainingItem.FirstOrDefault(y => y.CompanyTrainingItemId == id);
|
|||
|
if (model != null)
|
|||
|
{
|
|||
|
return model.CompanyTrainingItemName;
|
|||
|
}
|
|||
|
else { return ""; }
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
#region 根据培训记录id、学生id、教材id来修改时长
|
|||
|
public static string updateDurations(string trainRecordId, string PersonId, string CompanyTrainingItemId,float Durations,string projectid) {
|
|||
|
using (Model.SUBQHSEDB db = new Model.SUBQHSEDB(Funs.ConnString)) {
|
|||
|
|
|||
|
//根据项目id和userid获取personid
|
|||
|
var userModel = db.Sys_User.FirstOrDefault(x => x.UserId == PersonId);
|
|||
|
if (userModel!=null)
|
|||
|
{
|
|||
|
PersonId = db.SitePerson_Person.FirstOrDefault(x => x.IdentityCard == userModel.IdentityCard && x.ProjectId == projectid).PersonId;
|
|||
|
}
|
|||
|
|
|||
|
var stuModel = db.EduTrain_TrainRecord_Study.FirstOrDefault(x => x.TrainingId == trainRecordId &&
|
|||
|
PersonId == x.PersonId&& x.CompanyTrainingItemId== CompanyTrainingItemId);
|
|||
|
if (stuModel != null)
|
|||
|
{
|
|||
|
//学习时长跟教材的时长做对比,如果大于教材的 则时长直接就是教材的时长
|
|||
|
double? textbookSc = 0.0;//教材时长(分钟)
|
|||
|
var Training_CompanyTrainingItemModel = db.Training_CompanyTrainingItem.FirstOrDefault(x => x.CompanyTrainingItemId == CompanyTrainingItemId);
|
|||
|
if (Training_CompanyTrainingItemModel!=null)
|
|||
|
{
|
|||
|
textbookSc = Training_CompanyTrainingItemModel.Durations*60;
|
|||
|
}
|
|||
|
//修改
|
|||
|
if (stuModel.Durations> textbookSc)
|
|||
|
{
|
|||
|
stuModel.Durations = textbookSc;
|
|||
|
db.SubmitChanges();
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
stuModel.Durations = Durations;
|
|||
|
db.SubmitChanges();
|
|||
|
|
|||
|
}
|
|||
|
}
|
|||
|
else {
|
|||
|
//添加
|
|||
|
var newModel = new Model.EduTrain_TrainRecord_Study();
|
|||
|
newModel.Id = Guid.NewGuid().ToString();
|
|||
|
newModel.TrainingId = trainRecordId;
|
|||
|
newModel.PersonId = PersonId;
|
|||
|
newModel.CompanyTrainingItemId = CompanyTrainingItemId;
|
|||
|
newModel.Durations = Durations;
|
|||
|
db.EduTrain_TrainRecord_Study.InsertOnSubmit(newModel);
|
|||
|
db.SubmitChanges();
|
|||
|
}
|
|||
|
return "修改成功";
|
|||
|
}
|
|||
|
}
|
|||
|
#endregion
|
|||
|
|
|||
|
#region 根据培训id、学生id、教材id获取时长
|
|||
|
public static string getDurations(string trainRecordId, string PersonId, string CompanyTrainingItemId) {
|
|||
|
var stuModel = Funs.DB.EduTrain_TrainRecord_Study.FirstOrDefault(x => x.TrainingId == trainRecordId &&
|
|||
|
PersonId == x.PersonId && x.CompanyTrainingItemId == CompanyTrainingItemId);
|
|||
|
if (stuModel!=null)
|
|||
|
{
|
|||
|
return stuModel.Durations.ToString();
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
return "0";
|
|||
|
}
|
|||
|
}
|
|||
|
#endregion
|
|||
|
|
|||
|
#region 根据projectId、trainTypeId、TrainStates获取培训记录列表
|
|||
|
/// <summary>
|
|||
|
/// 根据projectId、trainTypeId、TrainStates获取培训记录列表
|
|||
|
/// </summary>
|
|||
|
/// <param name="projectId"></param>
|
|||
|
/// <returns></returns>
|
|||
|
public static List<Model.TrainRecordItem> getTrainRecordListByProjectIdTrainTypeIdTrainStates(string projectId, string trainTypeId, string trainStates)
|
|||
|
{
|
|||
|
using (Model.SUBQHSEDB db = new Model.SUBQHSEDB(Funs.ConnString))
|
|||
|
{
|
|||
|
var getDataLists = (from x in db.EduTrain_TrainRecord
|
|||
|
where x.ProjectId == projectId && x.TrainTypeId == trainTypeId
|
|||
|
orderby x.TrainStartDate descending
|
|||
|
select new Model.TrainRecordItem
|
|||
|
{
|
|||
|
TrainRecordId = x.TrainingId,
|
|||
|
TrainingCode = x.TrainingCode,
|
|||
|
TrainTitle = x.TrainTitle,
|
|||
|
ProjectId = x.ProjectId,
|
|||
|
TrainTypeId = x.TrainTypeId,
|
|||
|
TrainTypeName = db.Base_TrainType.First(y => y.TrainTypeId == x.TrainTypeId).TrainTypeName,
|
|||
|
TrainLevelId = x.TrainLevelId,
|
|||
|
TrainLevelName = db.Base_TrainLevel.First(y => y.TrainLevelId == x.TrainLevelId).TrainLevelName,
|
|||
|
TeachHour = x.TeachHour ?? 0,
|
|||
|
TeachAddress = x.TeachAddress,
|
|||
|
TrainStartDate = string.Format("{0:yyyy-MM-dd HH:mm}", x.TrainStartDate),
|
|||
|
}).ToList();
|
|||
|
return getDataLists;
|
|||
|
}
|
|||
|
}
|
|||
|
#endregion
|
|||
|
|
|||
|
#region 根据培训ID获取培训记录详细
|
|||
|
/// <summary>
|
|||
|
/// 根据培训ID获取培训记录详细
|
|||
|
/// </summary>
|
|||
|
/// <param name="trainRecordId"></param>
|
|||
|
/// <returns></returns>
|
|||
|
public static Model.TrainRecordItem getTrainRecordByTrainingId(string trainRecordId)
|
|||
|
{
|
|||
|
using (Model.SUBQHSEDB db = new Model.SUBQHSEDB(Funs.ConnString))
|
|||
|
{
|
|||
|
var getDataLists = from x in db.EduTrain_TrainRecord
|
|||
|
where x.TrainingId == trainRecordId
|
|||
|
select new Model.TrainRecordItem
|
|||
|
{
|
|||
|
TrainRecordId = x.TrainingId,
|
|||
|
TrainingCode = x.TrainingCode,
|
|||
|
TrainTitle = x.TrainTitle,
|
|||
|
ProjectId = x.ProjectId,
|
|||
|
TrainTypeId = x.TrainTypeId,
|
|||
|
TrainTypeName = db.Base_TrainType.First(y => y.TrainTypeId == x.TrainTypeId).TrainTypeName,
|
|||
|
TrainLevelId = x.TrainLevelId,
|
|||
|
TrainLevelName = db.Base_TrainLevel.First(y => y.TrainLevelId == x.TrainLevelId).TrainLevelName,
|
|||
|
TeachHour = x.TeachHour ?? 0,
|
|||
|
TeachAddress = x.TeachAddress,
|
|||
|
TrainStartDate = string.Format("{0:yyyy-MM-dd HH:mm}", x.TrainStartDate),
|
|||
|
UnitIds = x.UnitIds,
|
|||
|
WorkPostIds = x.WorkPostIds,
|
|||
|
TrainContent = x.TrainContent,
|
|||
|
AttachUrl = db.AttachFile.First(y => y.ToKeyId == x.TrainingId).AttachUrl.Replace('\\', '/'),
|
|||
|
UnitNames = UnitService.getUnitNamesUnitIds(x.UnitIds),
|
|||
|
WorkPostNames = WorkPostService.getWorkPostNamesWorkPostIds(x.WorkPostIds),
|
|||
|
};
|
|||
|
return getDataLists.FirstOrDefault();
|
|||
|
}
|
|||
|
}
|
|||
|
#endregion
|
|||
|
|
|||
|
#region 根据考生计划结束时 将相关培训考生内容 写培训记录归档
|
|||
|
/// <summary>
|
|||
|
/// 根据考生计划结束时 将相关培训考生内容 写培训记录归档
|
|||
|
/// </summary>
|
|||
|
/// <param name="getTestPlan"></param>
|
|||
|
|
|||
|
public static void InsertTrainRecord(Model.Training_TestPlan getTestPlan)
|
|||
|
{
|
|||
|
using (Model.SUBQHSEDB db = new Model.SUBQHSEDB(Funs.ConnString))
|
|||
|
{
|
|||
|
////获取培训计划
|
|||
|
var getTrainingPlan = db.Training_Plan.FirstOrDefault(e => e.PlanId == getTestPlan.PlanId);
|
|||
|
var getTrainRecord = db.EduTrain_TrainRecord.FirstOrDefault(x => x.PlanId == getTestPlan.PlanId);
|
|||
|
if (getTrainingPlan != null && getTrainRecord == null)
|
|||
|
{
|
|||
|
getTrainingPlan.States = "3";
|
|||
|
db.SubmitChanges();
|
|||
|
|
|||
|
Model.EduTrain_TrainRecord newTrainRecord = new Model.EduTrain_TrainRecord
|
|||
|
{
|
|||
|
TrainingId = SQLHelper.GetNewID(),
|
|||
|
TrainingCode = getTrainingPlan.PlanCode,
|
|||
|
ProjectId = getTrainingPlan.ProjectId,
|
|||
|
TrainTitle = getTrainingPlan.PlanName,
|
|||
|
TrainContent = getTrainingPlan.TrainContent,
|
|||
|
TrainStartDate = getTrainingPlan.TrainStartDate,
|
|||
|
TeachHour = getTrainingPlan.TeachHour,
|
|||
|
TrainEndDate = getTrainingPlan.TrainEndDate,
|
|||
|
TeachMan = getTrainingPlan.TeachMan,
|
|||
|
TeachAddress = getTrainingPlan.TeachAddress,
|
|||
|
Remark = "来源:培训计划",
|
|||
|
TrainTypeId = getTrainingPlan.TrainTypeId,
|
|||
|
TrainLevelId = getTrainingPlan.TrainLevelId,
|
|||
|
UnitIds = getTrainingPlan.UnitIds,
|
|||
|
States = Const.State_2,
|
|||
|
WorkPostIds = getTrainingPlan.WorkPostId,
|
|||
|
PlanId = getTrainingPlan.PlanId,
|
|||
|
//新增公司级unitId
|
|||
|
UnitId= getTrainingPlan.UnitId
|
|||
|
};
|
|||
|
newTrainRecord.CompileMan = UserService.GetUserNameByUserId(getTrainingPlan.DesignerId);
|
|||
|
///获取培训人员
|
|||
|
var getTrainingTasks = from x in db.Training_Task
|
|||
|
where x.PlanId == getTrainingPlan.PlanId
|
|||
|
select x;
|
|||
|
newTrainRecord.TrainPersonNum = getTrainingTasks.Count();
|
|||
|
///新增培训记录
|
|||
|
try
|
|||
|
{
|
|||
|
db.EduTrain_TrainRecord.InsertOnSubmit(newTrainRecord);
|
|||
|
db.SubmitChanges();
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
|
|||
|
throw;
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
|
|||
|
////及格分数
|
|||
|
int passScore = 80;
|
|||
|
var testRule = db.Sys_TestRule.FirstOrDefault();
|
|||
|
if (testRule != null)
|
|||
|
{
|
|||
|
passScore = testRule.PassingScore;
|
|||
|
}
|
|||
|
|
|||
|
foreach (var item in getTrainingTasks)
|
|||
|
{
|
|||
|
decimal gScores = 0;
|
|||
|
bool result = false;
|
|||
|
////获取 考生试卷
|
|||
|
var getTestRecord = db.Training_TestRecord.Where(x => x.TestPlanId == getTestPlan.TestPlanId && x.TestManId == item.UserId);
|
|||
|
foreach (var itemR in getTestRecord)
|
|||
|
{
|
|||
|
if (itemR.TestScores > gScores)
|
|||
|
{
|
|||
|
gScores = itemR.TestScores ?? 0;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
if (gScores >= passScore)
|
|||
|
{
|
|||
|
result = true;
|
|||
|
}
|
|||
|
|
|||
|
Model.EduTrain_TrainRecordDetail newDetail = new Model.EduTrain_TrainRecordDetail
|
|||
|
{
|
|||
|
TrainDetailId = SQLHelper.GetNewID(),
|
|||
|
TrainingId = newTrainRecord.TrainingId,
|
|||
|
PersonId = item.UserId,
|
|||
|
CheckScore = gScores,
|
|||
|
CheckResult = result,
|
|||
|
};
|
|||
|
//修改日期2024-2-20 14:14:21
|
|||
|
//var uModel = db.Sys_User.FirstOrDefault(x => x.IdentityCard == db.SitePerson_Person.FirstOrDefault(b => b.PersonId == item.UserId).IdentityCard);
|
|||
|
//if (uModel!=null)
|
|||
|
//{
|
|||
|
// var uid = uModel.UserId;
|
|||
|
// var studyDurations = db.EduTrain_TrainRecord_Study.Where(x => x.TrainingId == getTestPlan.PlanId &&
|
|||
|
//x.PersonId == uid).Sum(x => x.Durations);
|
|||
|
// if (studyDurations == null)
|
|||
|
// {
|
|||
|
// studyDurations = 0;
|
|||
|
// }
|
|||
|
// newDetail.Durations = studyDurations;
|
|||
|
|
|||
|
// db.EduTrain_TrainRecordDetail.InsertOnSubmit(newDetail);
|
|||
|
// db.SubmitChanges();
|
|||
|
//}
|
|||
|
var studyDurations = db.EduTrain_TrainRecord_Study.Where(x => x.TrainingId == getTestPlan.PlanId &&
|
|||
|
x.PersonId == item.UserId).Sum(x => x.Durations);
|
|||
|
if (studyDurations == null)
|
|||
|
{
|
|||
|
studyDurations = 0;
|
|||
|
}
|
|||
|
newDetail.Durations = studyDurations;
|
|||
|
|
|||
|
db.EduTrain_TrainRecordDetail.InsertOnSubmit(newDetail);
|
|||
|
db.SubmitChanges();
|
|||
|
|
|||
|
|
|||
|
///// 培训考试 通过 更新卡号
|
|||
|
if (result)
|
|||
|
{
|
|||
|
var getPerson = db.SitePerson_Person.FirstOrDefault(e => e.PersonId == newDetail.PersonId);
|
|||
|
if (getPerson != null && string.IsNullOrEmpty(getPerson.CardNo))
|
|||
|
{
|
|||
|
getPerson.CardNo = SQLHelper.RunProcNewId("SpGetNewNumber", "SitePerson_Person", "CardNo", getPerson.ProjectId, UnitService.GetUnitCodeByUnitId(getPerson.UnitId));
|
|||
|
db.SubmitChanges();
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
////增加一条编码记录
|
|||
|
CodeRecordsService.InsertCodeRecordsByMenuIdProjectIdUnitId(Const.ProjectTrainRecordMenuId, newTrainRecord.ProjectId, null, newTrainRecord.TrainingId, newTrainRecord.TrainStartDate);
|
|||
|
CommonService.btnSaveData(newTrainRecord.ProjectId, Const.ProjectTrainRecordMenuId, newTrainRecord.TrainingId, getTrainingPlan.DesignerId, true, newTrainRecord.TrainTitle, "../EduTrain/TrainRecordView.aspx?TrainingId={0}");
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
#endregion
|
|||
|
}
|
|||
|
}
|