diff --git a/APT.MicroApi/APT.PP.WebApi/Controllers/Api/SEController.cs b/APT.MicroApi/APT.PP.WebApi/Controllers/Api/SEController.cs index 0e18677..4c52e60 100644 --- a/APT.MicroApi/APT.PP.WebApi/Controllers/Api/SEController.cs +++ b/APT.MicroApi/APT.PP.WebApi/Controllers/Api/SEController.cs @@ -221,85 +221,83 @@ namespace APT.PP.WebApi.Controllers.Api.PP //金源培训 9 ~ 15 可以触发一次 if (currTime.Hour == 8 || currTime.Hour == 9) { - return true; - } + var orgId = filter.GetOrgId(); + var newUsers = GetEntities(t => t.IS_SEND == 0, new BaseFilter(orgId)); + if (!newUsers.Any() || newUsers.Count() < 1) + { + return true; + } + //如果今天触发过三级安全教育 直接返回 + var NewCheck = GetEntity(e => !e.IS_DELETED && e.TRAIN_STATUS == SEThreeLevelSafeTrainType.公司级 && e.CREATE_TIME.HasValue && e.CREATE_TIME.Value.Date == currTime.Date); + if (NewCheck != null) + { + return true; + } - var orgId = filter.GetOrgId(); - var newUsers = GetEntities(t => t.IS_SEND == 0, new BaseFilter(orgId)); - if (!newUsers.Any() || newUsers.Count() < 1) - { - return true; - } - //如果今天触发过三级安全教育 直接返回 - var NewCheck = GetEntity(e => !e.IS_DELETED && e.TRAIN_STATUS == SEThreeLevelSafeTrainType.公司级 && e.CREATE_TIME.HasValue && e.CREATE_TIME.Value.Date == currTime.Date); - if (NewCheck != null) - { - return true; - } + T_SE_NEW_USERS eduCard = null; + List sendNotice = new List(); + List userDetails = new List(); - T_SE_NEW_USERS eduCard = null; - List sendNotice = new List(); - List userDetails = new List(); + var newUsersId = newUsers.Select(t => t.USER_ID); + var newAllUsers = GetEntities(t => newUsersId.Contains(t.ID), new BaseFilter(orgId)); + var sendUser = GetEntity(t => t.Nav_ApproveRole != null && t.Nav_ApproveRole.NAME == "安环部安全员" && t.IS_DELETED == false && t.ENABLE_STATUS == 0); + var train_contents = GetEntity(t => t.THREE_LEVEL_SAFE_TRAIN_TYPE == SEThreeLevelSafeTrainType.公司级); + eduCard = new T_SE_NEW_USERS(); + eduCard.ID = Guid.NewGuid(); + eduCard.DEPARTMENT_ID = sendUser.DEPARTMENT_ID; + eduCard.USER_ID = sendUser.ID; + eduCard.ORG_ID = orgId; + eduCard.TRAIN_STATUS = SEThreeLevelSafeTrainType.公司级; + eduCard.CREATE_TIME = currTime; + if (train_contents != null) + { + eduCard.CONTENT_ID = train_contents.ID; + } + foreach (var user in newAllUsers) + { + T_SE_NEW_USER_DETAIL userDetail = new T_SE_NEW_USER_DETAIL(); + userDetail.ID = Guid.NewGuid(); + userDetail.EDU_CARD_ID = eduCard.ID; + userDetail.USER_ID = user.ID; + userDetail.ID_CARD_NUMBER = user.ID_CARD; + userDetail.STATUS = 0; + userDetail.ORG_ID = eduCard.ORG_ID; + userDetail.IN_TIME = user.ENTRYTIME; + userDetails.Add(userDetail); + } + foreach (var item in newUsers) + { + item.IS_SEND = 1; + } + if (sendUser != null) + { + var endTime = DateTime.Now.AddDays(10); + var newEndTime = new DateTime(endTime.Year, endTime.Month, endTime.Day, 23, 59, 59); + sendNotice.Add(NotificationTaskService.InsertUserNoticeTaskModel(currTime.ToString("MMdd") + "-三级安全培训-" + eduCard.STATUS.GetDescription(), eduCard.ID, eduCard.ORG_ID, sendUser.ID, sendUser.NAME, DateTime.Now, newEndTime, 1, "SE062")); + } + T_FM_SYNC_TASK task = null; + if (!string.IsNullOrEmpty(filter.Parameter1) && eduCard != null) + { + task = GetEntity(filter.Keyword); + task.CURR_TASK_START_TIME = currTime;//上次同步结束时间 + task.UPDATE_SUCCES_TIME = DateTime.Now;//上次同步结束时间 + task.SYNC_PARAM = "";//清空参数 + } - var newUsersId = newUsers.Select(t => t.USER_ID); - var newAllUsers = GetEntities(t => newUsersId.Contains(t.ID), new BaseFilter(orgId)); - var sendUser = GetEntity(t => t.Nav_ApproveRole != null && t.Nav_ApproveRole.NAME == "安环部安全员" && t.IS_DELETED == false && t.ENABLE_STATUS == 0); - var train_contents = GetEntity(t => t.THREE_LEVEL_SAFE_TRAIN_TYPE == SEThreeLevelSafeTrainType.公司级); - eduCard = new T_SE_NEW_USERS(); - eduCard.ID = Guid.NewGuid(); - eduCard.DEPARTMENT_ID = sendUser.DEPARTMENT_ID; - eduCard.USER_ID = sendUser.ID; - eduCard.ORG_ID = orgId; - eduCard.TRAIN_STATUS = SEThreeLevelSafeTrainType.公司级; - eduCard.CREATE_TIME = currTime; - if (train_contents != null) - { - eduCard.CONTENT_ID = train_contents.ID; + UnifiedCommit(() => + { + if (eduCard != null) + AddEntityNoCommit(eduCard); + if (sendNotice != null && sendNotice.Any()) + BantchAddEntityNoCommit(sendNotice); + if (userDetails != null && sendNotice.Any()) + BantchAddEntityNoCommit(userDetails); + if (newUsers != null && newUsers.Any()) + BantchUpdateEntityNoCommit(newUsers); + if (task != null) + UpdateEntity(task); + }); } - foreach (var user in newAllUsers) - { - T_SE_NEW_USER_DETAIL userDetail = new T_SE_NEW_USER_DETAIL(); - userDetail.ID = Guid.NewGuid(); - userDetail.EDU_CARD_ID = eduCard.ID; - userDetail.USER_ID = user.ID; - userDetail.ID_CARD_NUMBER = user.ID_CARD; - userDetail.STATUS = 0; - userDetail.ORG_ID = eduCard.ORG_ID; - userDetail.IN_TIME = user.ENTRYTIME; - userDetails.Add(userDetail); - } - foreach (var item in newUsers) - { - item.IS_SEND = 1; - } - if (sendUser != null) - { - var endTime = DateTime.Now.AddDays(10); - var newEndTime = new DateTime(endTime.Year, endTime.Month, endTime.Day, 23, 59, 59); - sendNotice.Add(NotificationTaskService.InsertUserNoticeTaskModel(currTime.ToString("MMdd") + "-三级安全培训-" + eduCard.STATUS.GetDescription(), eduCard.ID, eduCard.ORG_ID, sendUser.ID, sendUser.NAME, DateTime.Now, newEndTime, 1, "SE062")); - } - T_FM_SYNC_TASK task = null; - if (!string.IsNullOrEmpty(filter.Parameter1) && eduCard != null) - { - task = GetEntity(filter.Keyword); - task.CURR_TASK_START_TIME = currTime;//上次同步结束时间 - task.UPDATE_SUCCES_TIME = DateTime.Now;//上次同步结束时间 - task.SYNC_PARAM = "";//清空参数 - } - - UnifiedCommit(() => - { - if (eduCard != null) - AddEntityNoCommit(eduCard); - if (sendNotice != null && sendNotice.Any()) - BantchAddEntityNoCommit(sendNotice); - if (userDetails != null && sendNotice.Any()) - BantchAddEntityNoCommit(userDetails); - if (newUsers != null && newUsers.Any()) - BantchUpdateEntityNoCommit(newUsers); - if (task != null) - UpdateEntity(task); - }); return true; }); } diff --git a/APT.MicroApi/APT.SC.WebApi/Controllers/Api/SEController/SENewUsers.cs b/APT.MicroApi/APT.SC.WebApi/Controllers/Api/SEController/SENewUsers.cs index 85fc114..d0ba3d2 100644 --- a/APT.MicroApi/APT.SC.WebApi/Controllers/Api/SEController/SENewUsers.cs +++ b/APT.MicroApi/APT.SC.WebApi/Controllers/Api/SEController/SENewUsers.cs @@ -302,17 +302,23 @@ namespace APT.SC.WebApi.Controllers.Api.SE testFilter.Include = new string[] { "Nav_Points" }; var currStatus = eduCard.TRAIN_STATUS; IEnumerable pointS = new List(); + string PointName = ""; if (eduCard.TRAIN_STATUS == SEThreeLevelSafeTrainType.公司级) { - pointS = GetEntities(t => t.NAME == "三级安全教育-公司级", new BaseFilter(orgId)); + PointName = "三级安全教育-公司级"; } else if (eduCard.TRAIN_STATUS == SEThreeLevelSafeTrainType.部门级) { - pointS = GetEntities(t => t.NAME == "三级安全教育-部门级", new BaseFilter(orgId)); + PointName = "三级安全教育-部门级"; } else if (eduCard.TRAIN_STATUS == SEThreeLevelSafeTrainType.班组级) { - pointS = GetEntities(t => t.NAME == "三级安全教育-班组级", new BaseFilter(orgId)); + PointName = "三级安全教育-班组级"; + } + pointS = GetEntities(t => t.NAME == PointName, new BaseFilter(orgId)); + if (pointS == null || pointS.Count() < 1) + { + throw new Exception("未找到试题知识点【" + PointName + "】的配置信息,请沟通管理员完善知识点和题库!"); } var pointIDS = pointS.Select(t => t.ID).ToList(); var allTests = GetEntities(st => st.Nav_Points.Any(pt => pointIDS.Contains((Guid)pt.POINT_ID)), testFilter).ToList(); @@ -324,12 +330,12 @@ namespace APT.SC.WebApi.Controllers.Api.SE CreateTestList(allTests, testidlist, pointIDS, (int)SETestTypeEnum.是非题, CCount); CreateTestList(allTests, testidlist, pointIDS, (int)SETestTypeEnum.单选题, SCount); CreateTestList(allTests, testidlist, pointIDS, (int)SETestTypeEnum.多选题, MCount); - if (testidlist.Count == 0) + + if (testidlist.Count == 0 || testidlist.Count < (SCount + MCount + CCount)) { - throw new Exception("当前题库数据不足,未能正常生成试卷!"); + throw new Exception("当前题库数据不足,未能正常生成试卷! 知识点:" + PointName + "是非题:" + CCount + "单选题:" + SCount + "多选题:" + MCount + ""); } Nav_Papers = new List(); - testidlist.ForEach(testid => { var p = new T_SE_NEW_USER_DETAIL_PAPER