using Model; using System; using System.Collections.Generic; using System.Linq; using System.Numerics; namespace BLL { /// /// 培训计划 /// public static class TrainingPlanService { public static Model.SGGLDB db = Funs.DB; /// /// 根据主键获取培训计划 /// /// /// public static Model.Training_Plan GetPlanById(string planId) { return db.Training_Plan.FirstOrDefault(e => e.PlanId == planId); } /// /// 根据检查Id获取培训计划 /// /// /// public static Model.Training_Plan GetPlanByCheckId(string checkId) { return db.Training_Plan.FirstOrDefault(e => e.CheckId == checkId && e.IsRetakeCourse == 1); } /// /// 根据培训教材Id获取今年培训计划 /// /// /// /// /// public static List GetThisYearPlanByCompanyTrainingItemId(string projectId, string itemId, int year) { return db.Training_Plan.Where(e => e.ProjectId == projectId && e.CompanyTrainingItemId == itemId && e.IsRetakeCourse != 1 && ((DateTime)e.DesignerDate).Year == year).ToList(); } /// /// 添加培训计划 /// /// public static void AddPlan(Model.Training_Plan model) { Model.Training_Plan newModel = new Model.Training_Plan { PlanId = model.PlanId, PlanCode = model.PlanCode, ProjectId = model.ProjectId, DesignerId = model.DesignerId, PlanName = model.PlanName, TrainContent = model.TrainContent, TrainStartDate = model.TrainStartDate, TrainEndDate = model.TrainEndDate, TeachHour = model.TeachHour, TeachMan = model.TeachMan, TeachAddress = model.TeachAddress, TrainTypeId = model.TrainTypeId, TrainLevelId = model.TrainLevelId, DesignerDate = model.DesignerDate, UnitIds = model.UnitIds, WorkPostId = model.WorkPostId, States = model.States, Cycle = model.Cycle, IsRetakeCourse = model.IsRetakeCourse, CheckType = model.CheckType, CheckId = model.CheckId, CompanyTrainingItemId = model.CompanyTrainingItemId }; db.Training_Plan.InsertOnSubmit(newModel); db.SubmitChanges(); } /// /// 修改培训计划 /// /// public static void UpdatePlan(Model.Training_Plan model) { Model.Training_Plan isUpdate = Funs.DB.Training_Plan.FirstOrDefault(e => e.PlanId == model.PlanId); if (isUpdate != null) { isUpdate.PlanName = model.PlanName; isUpdate.TrainContent = model.TrainContent; isUpdate.TrainStartDate = model.TrainStartDate; isUpdate.TrainEndDate = model.TrainEndDate; isUpdate.TeachHour = model.TeachHour; isUpdate.TeachMan = model.TeachMan; isUpdate.TeachAddress = model.TeachAddress; isUpdate.TrainTypeId = model.TrainTypeId; isUpdate.TrainLevelId = model.TrainLevelId; isUpdate.DesignerDate = model.DesignerDate; isUpdate.UnitIds = model.UnitIds; isUpdate.WorkPostId = model.WorkPostId; isUpdate.States = model.States; isUpdate.Cycle = model.Cycle; isUpdate.IsRetakeCourse = model.IsRetakeCourse; isUpdate.CheckType = model.CheckType; isUpdate.CheckId = model.CheckId; isUpdate.CompanyTrainingItemId = model.CompanyTrainingItemId; db.SubmitChanges(); } } /// /// 根据主键删除培训计划信息 /// /// public static void DeletePlanById(string planId) { Model.Training_Plan plan = db.Training_Plan.FirstOrDefault(e => e.PlanId == planId); if (plan != null) { db.Training_Plan.DeleteOnSubmit(plan); db.SubmitChanges(); } } /// /// 获取培训计划列 /// /// public static List GetPlanList() { return (from x in db.Training_Plan orderby x.PlanCode select x).ToList(); } /// /// 获取某一岗位今年入场培训计划 /// /// /// /// public static List GetPlanListByWorkPostId(string projectId, string workPostId) { var list = (from x in db.Training_Plan where x.ProjectId == projectId && (x.WorkPostId == null || x.WorkPostId.Contains(workPostId)) && x.CompanyTrainingItemId != null && x.IsRetakeCourse == null && Convert.ToDateTime(x.DesignerDate).Year == DateTime.Now.Year select x).ToList(); return list; } /// /// 检查重修,并生成培训计划、任务 /// /// public static void RetakeCourseProducePlan(ProducePlanInfo info) { var plan = GetPlanByCheckId(info.CheckId); var person = PersonService.GetPersonById(info.PersonId); var companyTrainingItem = CompanyTrainingItemService.GetCompanyTrainingItemById(info.CompanyTrainingItemId); var teachHour = companyTrainingItem.LearningTime / 3600; string planId = string.Empty; if (plan != null) {//编辑培训计划 planId = plan.PlanId; Model.Training_Plan planModel = new Model.Training_Plan { ProjectId = info.CurrProjectId, PlanName = info.CheckTypeName, TrainContent = info.CheckTypeName, TeachHour = teachHour, UnitIds = person.UnitId, WorkPostId = person.WorkPostId, TrainStartDate = plan.TrainStartDate, TrainEndDate = info.TrainEndDate, TeachMan = plan.TeachMan, TeachAddress = plan.TeachAddress, TrainTypeId = Const.RetakeCourseTrainTypeId, TrainLevelId = Const.OtherTrainLevelId, States = "1", Cycle = "", IsRetakeCourse = 1, CheckType = plan.CheckType, CheckId = plan.CheckId, CompanyTrainingItemId = info.CompanyTrainingItemId }; UpdatePlan(planModel); } else {//生成培训计划 planId = SQLHelper.GetNewID(); string code = ProjectService.GetProjectByProjectId(info.CurrProjectId).ProjectCode + "-"; string planCode = BLL.SQLHelper.RunProcNewId("SpGetNewCode5ByProjectId", "dbo.Training_Plan", "PlanCode", info.CurrProjectId, code); Model.Training_Plan planModel = new Model.Training_Plan { PlanId = planId, PlanCode = planCode, ProjectId = info.CurrProjectId, DesignerId = info.CurrUserId, DesignerDate = DateTime.Now, PlanName = info.CheckTypeName, TrainContent = info.CheckTypeName, TrainStartDate = DateTime.Now, TrainEndDate = info.TrainEndDate, TeachHour = teachHour, //TeachMan = model.TeachMan, //TeachAddress = model.TeachAddress, TrainTypeId = Const.RetakeCourseTrainTypeId, TrainLevelId = Const.OtherTrainLevelId, UnitIds = person.UnitId, WorkPostId = person.WorkPostId, States = "1", Cycle = "", IsRetakeCourse = 1, CheckType = info.CheckType.ToString(), CheckId = info.CheckId, CompanyTrainingItemId = info.CompanyTrainingItemId }; AddPlan(planModel); } //删除培训明细 TrainingPlanItemService.DeletePlanItemByPlanId(planId); //删除任务 TrainingTaskService.DeleteTaskByPlanId(planId); string taskId = SQLHelper.GetNewID(); //新增培训任务 Model.Training_Task newTrainDetail = new Model.Training_Task { TaskId = taskId, ProjectId = info.CurrProjectId, PlanId = planId, UserId = info.PersonId, TaskDate = DateTime.Now, States = Const.State_1, }; TrainingTaskService.AddTask(newTrainDetail); //新增培训任务明细 Model.Training_TaskItem newTaskItem = new Model.Training_TaskItem { TaskItemId = SQLHelper.GetNewID(), TaskId = taskId, PlanId = planId, PersonId = info.PersonId, TrainingItemCode = companyTrainingItem.CompanyTrainingItemCode, TrainingItemName = companyTrainingItem.CompanyTrainingItemName, AttachUrl = companyTrainingItem.AttachUrl, CompanyTrainingItemId = info.CompanyTrainingItemId, //LearnTime = trainingItem.LearningTime, //VideoProgress = 0, }; db.Training_TaskItem.InsertOnSubmit(newTaskItem); db.SubmitChanges(); //新增培训明细 Model.Training_PlanItem newPlanItem = new Model.Training_PlanItem { PlanItemId = SQLHelper.GetNewID(), PlanId = planId, CompanyTrainingItemId = info.CompanyTrainingItemId, CompanyTrainingId = companyTrainingItem.CompanyTrainingId }; TrainingPlanItemService.AddPlanItem(newPlanItem); } /// /// 选择教材生成培训计划 /// /// public static void SelectCompanyTrainingItemProducePlan(ProducePlanInfo info) { var companyTrainingItem = CompanyTrainingItemService.GetCompanyTrainingItemById(info.CompanyTrainingItemId); var teachHour = companyTrainingItem.LearningTime / 3600; //1、根据教材id查询适用岗位下相关人员; var workPostIds = !string.IsNullOrWhiteSpace(companyTrainingItem.WorkPostIds) ? companyTrainingItem.WorkPostIds.Split(',').ToList() : new List(); var workPostPersons = PersonService.GetPersonListByWorkPostIds(info.CurrProjectId, workPostIds); //人员单位 var unitIds = workPostPersons.Any() ? String.Join(", ", workPostPersons.Select(x => x.UnitId).Distinct()) : string.Empty; //2、根据教材id查询今年是否有相关培训计划(排除重修培训计划),如果有先删除; var plans = GetThisYearPlanByCompanyTrainingItemId(info.CurrProjectId, info.CompanyTrainingItemId, DateTime.Now.Year); if (plans.Any()) {//删除今年的培训计划 foreach (var plan in plans) { //删除培训明细 TrainingPlanItemService.DeletePlanItemByPlanId(plan.PlanId); //删除任务 TrainingTaskService.DeleteTaskByPlanId(plan.PlanId); DeletePlanById(plan.PlanId); } } //生成培训计划 string planId = SQLHelper.GetNewID(); string code = ProjectService.GetProjectByProjectId(info.CurrProjectId).ProjectCode + "-"; string planCode = BLL.SQLHelper.RunProcNewId("SpGetNewCode5ByProjectId", "dbo.Training_Plan", "PlanCode", info.CurrProjectId, code); Model.Training_Plan planModel = new Model.Training_Plan { PlanId = planId, PlanCode = planCode, ProjectId = info.CurrProjectId, DesignerId = info.CurrUserId, DesignerDate = DateTime.Now, PlanName = companyTrainingItem.CompanyTrainingItemName, TrainContent = companyTrainingItem.CompanyTrainingItemName, TrainStartDate = DateTime.Now, TrainEndDate = info.TrainEndDate, TeachHour = teachHour, //TeachMan = companyTrainingItem., //TeachAddress = model.TeachAddress, TrainTypeId = Const.EntryTrainTypeId, TrainLevelId = Const.OtherTrainLevelId, UnitIds = unitIds, WorkPostId = companyTrainingItem.WorkPostIds, States = "1", Cycle = "", //IsRetakeCourse = 0, //CheckType = info.CheckType.ToString(), //CheckId = info.CheckId, CompanyTrainingItemId = info.CompanyTrainingItemId }; AddPlan(planModel); //新增培训明细 Model.Training_PlanItem newPlanItem = new Model.Training_PlanItem { PlanItemId = SQLHelper.GetNewID(), PlanId = planId, CompanyTrainingItemId = info.CompanyTrainingItemId, CompanyTrainingId = companyTrainingItem.CompanyTrainingId }; TrainingPlanItemService.AddPlanItem(newPlanItem); List newTasks = new List(); List newTaskItems = new List(); //循环给人员添加任务 foreach (var person in workPostPersons) { string taskId = SQLHelper.GetNewID(); //新增培训任务 Model.Training_Task newTask = new Model.Training_Task { TaskId = taskId, ProjectId = info.CurrProjectId, PlanId = planId, UserId = person.PersonId, TaskDate = DateTime.Now, States = Const.State_1, }; newTasks.Add(newTask); //新增培训任务明细 Model.Training_TaskItem newTaskItem = new Model.Training_TaskItem { TaskItemId = SQLHelper.GetNewID(), TaskId = taskId, PlanId = planId, PersonId = person.PersonId, TrainingItemCode = companyTrainingItem.CompanyTrainingItemCode, TrainingItemName = companyTrainingItem.CompanyTrainingItemName, AttachUrl = companyTrainingItem.AttachUrl, CompanyTrainingItemId = info.CompanyTrainingItemId, //LearnTime = trainingItem.LearningTime, //VideoProgress = 0, }; newTaskItems.Add(newTaskItem); } db.Training_Task.InsertAllOnSubmit(newTasks); db.Training_TaskItem.InsertAllOnSubmit(newTaskItems); db.SubmitChanges(); } /// /// 选择人员生成培训计划 /// /// public static bool SelectPersonProducePlan(ProducePlanInfo info) { //1、根据人员获取人员基本信息 var person = PersonService.GetPersonById(info.PersonId); if (string.IsNullOrWhiteSpace(person.WorkPostId)) { return false; } //2、根据人员岗位Id查询今年入场培训计划 var lstPlan = GetPlanListByWorkPostId(info.CurrProjectId, person.WorkPostId); foreach (var plan in lstPlan) { var task = (from x in db.Training_Task where x.ProjectId == info.CurrProjectId && x.PlanId == plan.PlanId && x.UserId == person.PersonId select x).ToList(); if (task.Any()) { continue; } var companyTrainingItem = CompanyTrainingItemService.GetCompanyTrainingItemById(plan.CompanyTrainingItemId); string taskId = SQLHelper.GetNewID(); //新增培训任务 Model.Training_Task newTask = new Model.Training_Task { TaskId = taskId, ProjectId = info.CurrProjectId, PlanId = plan.PlanId, UserId = person.PersonId, TaskDate = DateTime.Now, States = Const.State_1, }; //新增培训任务明细 Model.Training_TaskItem newTaskItem = new Model.Training_TaskItem { TaskItemId = SQLHelper.GetNewID(), TaskId = taskId, PlanId = plan.PlanId, PersonId = person.PersonId, TrainingItemCode = companyTrainingItem.CompanyTrainingItemCode, TrainingItemName = companyTrainingItem.CompanyTrainingItemName, AttachUrl = companyTrainingItem.AttachUrl, CompanyTrainingItemId = info.CompanyTrainingItemId, //LearnTime = trainingItem.LearningTime, //VideoProgress = 0, }; db.Training_Task.InsertOnSubmit(newTask); db.Training_TaskItem.InsertOnSubmit(newTaskItem); db.SubmitChanges(); } return true; } } }