From 49283a7433315e3bdf16a19cf9978a50c2d28b5f Mon Sep 17 00:00:00 2001 From: 10191 <506754232@qq.com> Date: Sun, 31 Mar 2024 11:01:00 +0800 Subject: [PATCH] =?UTF-8?q?=E8=80=83=E8=AF=95=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SGGL/BLL/HSSE/EduTrain/TestRecordService.cs | 54 +++++++++---------- .../Controllers/HSSE/TestPlanController.cs | 45 +++++++++++----- .../Controllers/HSSE/TestRecordController.cs | 2 +- .../HSSE/TrainingPlanController.cs | 31 ++++++++--- .../HSSE/TrainingTaskController.cs | 2 +- 5 files changed, 84 insertions(+), 50 deletions(-) diff --git a/SGGL/BLL/HSSE/EduTrain/TestRecordService.cs b/SGGL/BLL/HSSE/EduTrain/TestRecordService.cs index 7336dfea..588e40ae 100644 --- a/SGGL/BLL/HSSE/EduTrain/TestRecordService.cs +++ b/SGGL/BLL/HSSE/EduTrain/TestRecordService.cs @@ -52,38 +52,38 @@ namespace BLL db.Training_TestRecord.InsertOnSubmit(newTestRecord); db.SubmitChanges(); - } - public static void AddTestRecordForApi(Model.Training_TestRecord testRecord) + } + public static void AddTestRecordForApi(Model.Training_TestRecord testRecord) + { + using (Model.SGGLDB db = new Model.SGGLDB(Funs.ConnString)) { - using (Model.SGGLDB db = new Model.SGGLDB(Funs.ConnString)) - { - Model.Training_TestRecord newTestRecord = new Model.Training_TestRecord - { - TestRecordId = testRecord.TestRecordId, - ProjectId = testRecord.ProjectId, - TestPlanId = testRecord.TestPlanId, - TestManId = testRecord.TestManId, - TestType = testRecord.TestType, - }; + Model.Training_TestRecord newTestRecord = new Model.Training_TestRecord + { + TestRecordId = testRecord.TestRecordId, + ProjectId = testRecord.ProjectId, + TestPlanId = testRecord.TestPlanId, + TestManId = testRecord.TestManId, + TestType = testRecord.TestType, + }; - if (string.IsNullOrEmpty(newTestRecord.TestType)) - { - var getTrainTypeName = (from x in db.Training_TestPlan - join y in db.Training_Plan on x.PlanId equals y.PlanId - join z in db.Base_TrainType on y.TrainTypeId equals z.TrainTypeId - where x.TestPlanId == testRecord.TestPlanId - select z).FirstOrDefault(); + if (string.IsNullOrEmpty(newTestRecord.TestType)) + { + var getTrainTypeName = (from x in db.Training_TestPlan + join y in db.Training_Plan on x.PlanId equals y.PlanId + join z in db.Base_TrainType on y.TrainTypeId equals z.TrainTypeId + where x.TestPlanId == testRecord.TestPlanId + select z).FirstOrDefault(); - if (getTrainTypeName != null) - { - testRecord.TestType = getTrainTypeName.TrainTypeName; - } - } + if (getTrainTypeName != null) + { + testRecord.TestType = getTrainTypeName.TrainTypeName; + } + } - db.Training_TestRecord.InsertOnSubmit(newTestRecord); - db.SubmitChanges(); - } + db.Training_TestRecord.InsertOnSubmit(newTestRecord); + db.SubmitChanges(); } + } /// /// 修改考试记录信息 /// diff --git a/SGGL/WebAPI/Controllers/HSSE/TestPlanController.cs b/SGGL/WebAPI/Controllers/HSSE/TestPlanController.cs index 53a7b4b4..e970f786 100644 --- a/SGGL/WebAPI/Controllers/HSSE/TestPlanController.cs +++ b/SGGL/WebAPI/Controllers/HSSE/TestPlanController.cs @@ -79,24 +79,41 @@ namespace WebAPI.Controllers var responeData = new Model.ResponeData(); try { - var getTasks = new Model.SGGLDB(Funs.ConnString).Training_Task.FirstOrDefault(x => x.PlanId == trainingPlanId); - if (getTasks != null) + using (Model.SGGLDB db = new Model.SGGLDB(Funs.ConnString)) { - if (CommonService.IsMainUnitOrAdmin(userId)) + var getTasks =db.Training_Task.FirstOrDefault(x => x.PlanId == trainingPlanId); + if (getTasks != null) { - responeData.data = APITestPlanService.SaveTestPlanByTrainingPlanId(trainingPlanId, 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 == Const.UnitId_CD) + { + result = true; + } + } + if ( result) + //if (CommonService.IsMainUnitOrAdmin(userId)) + { + responeData.data = APITestPlanService.SaveTestPlanByTrainingPlanId(trainingPlanId, userId); + } + else + { + responeData.code = 0; + responeData.message = "非本单位用户,不能生成考试计划!"; + } } else { responeData.code = 0; - responeData.message = "非本单位用户,不能生成考试计划!"; + responeData.message = "培训计划下没有培训人员,不能生成考试计划!"; } } - else - { - responeData.code = 0; - responeData.message = "培训计划下没有培训人员,不能生成考试计划!"; - } } catch (Exception ex) { @@ -201,11 +218,11 @@ namespace WebAPI.Controllers Model.SitePerson_Person person; if (user != null) { - person = Funs.DB.SitePerson_Person.FirstOrDefault(e => (e.PersonId == personId || e.IdentityCard == user.IdentityCard) && e.ProjectId == getTestPlan.ProjectId);// PersonService.GetPersonByUserId(personId, getTestPlan.ProjectId); + person = db.SitePerson_Person.FirstOrDefault(e => (e.PersonId == personId || e.IdentityCard == user.IdentityCard) && e.ProjectId == getTestPlan.ProjectId);// PersonService.GetPersonByUserId(personId, getTestPlan.ProjectId); } else { - person = Funs.DB.SitePerson_Person.FirstOrDefault(e => e.PersonId == personId && e.ProjectId == getTestPlan.ProjectId);// PersonService.GetPersonByUserId(personId, getTestPlan.ProjectId); + person = db.SitePerson_Person.FirstOrDefault(e => e.PersonId == personId && e.ProjectId == getTestPlan.ProjectId);// PersonService.GetPersonByUserId(personId, getTestPlan.ProjectId); } if (person != null || user != null) @@ -246,7 +263,7 @@ namespace WebAPI.Controllers TestPlanId = getTestPlan.TestPlanId, TestManId = personId, }; - TestRecordService.AddTestRecord(newTestRecord); + TestRecordService.AddTestRecordForApi(newTestRecord); responeData.code = 3; responeData.message = "您已加入考试计划!"; } @@ -265,7 +282,7 @@ namespace WebAPI.Controllers TestPlanId = getTestPlan.TestPlanId, TestManId = personId, }; - TestRecordService.AddTestRecord(newTestRecord); + TestRecordService.AddTestRecordForApi(newTestRecord); responeData.code = 3; responeData.message = "您已加入考试计划!"; } diff --git a/SGGL/WebAPI/Controllers/HSSE/TestRecordController.cs b/SGGL/WebAPI/Controllers/HSSE/TestRecordController.cs index 6216a58d..05560f08 100644 --- a/SGGL/WebAPI/Controllers/HSSE/TestRecordController.cs +++ b/SGGL/WebAPI/Controllers/HSSE/TestRecordController.cs @@ -164,7 +164,7 @@ namespace WebAPI.Controllers var responeData = new Model.ResponeData(); try { - personId = PersonService.GetPersonIdByUserId(personId); + personId = PersonService.GetPersonIdByUserIdForApi(personId); var getDataLists = APITestRecordService.getTrainingTestRecordListByProjectIdPersonId(projectId, personId); int pageCount = getDataLists.Count; if (pageCount > 0 && pageIndex > 0) diff --git a/SGGL/WebAPI/Controllers/HSSE/TrainingPlanController.cs b/SGGL/WebAPI/Controllers/HSSE/TrainingPlanController.cs index c79ec021..2ea94610 100644 --- a/SGGL/WebAPI/Controllers/HSSE/TrainingPlanController.cs +++ b/SGGL/WebAPI/Controllers/HSSE/TrainingPlanController.cs @@ -101,14 +101,31 @@ namespace WebAPI.Controllers var responeData = new Model.ResponeData(); try { - if (CommonService.IsMainUnitOrAdmin(trainingPlan.DesignerId)) + using (Model.SGGLDB db = new Model.SGGLDB(Funs.ConnString)) { - APITrainingPlanService.SaveTrainingPlan(trainingPlan); - } - else - { - responeData.code = 0; - responeData.message = "非本单位用户,不能制定培训计划!"; + bool result = false; + if (trainingPlan.DesignerId == Const.sysglyId || trainingPlan.DesignerId == Const.hfnbdId) + { + result = true; + } + else + { + var user = db.Sys_User.FirstOrDefault(e => e.UserId == trainingPlan.DesignerId); + if (user != null && user.UnitId == Const.UnitId_CD) + { + result = true; + } + } + if (result) + // if (CommonService.IsMainUnitOrAdmin(trainingPlan.DesignerId)) + { + APITrainingPlanService.SaveTrainingPlan(trainingPlan); + } + else + { + responeData.code = 0; + responeData.message = "非本单位用户,不能制定培训计划!"; + } } } catch (Exception ex) diff --git a/SGGL/WebAPI/Controllers/HSSE/TrainingTaskController.cs b/SGGL/WebAPI/Controllers/HSSE/TrainingTaskController.cs index 3df33a61..0c10ebf7 100644 --- a/SGGL/WebAPI/Controllers/HSSE/TrainingTaskController.cs +++ b/SGGL/WebAPI/Controllers/HSSE/TrainingTaskController.cs @@ -86,7 +86,7 @@ namespace WebAPI.Controllers var responeData = new Model.ResponeData(); try { - string newPersonId = PersonService.GetPersonIdByUserId(personId); + string newPersonId = PersonService.GetPersonIdByUserIdForApi(personId); responeData.message = APITrainingTaskService.getTrainingTaskByPlanIdPersonIdCondition(planId, newPersonId); if (string.IsNullOrEmpty(responeData.message)) {