using APT.BaseData.Domain.ApiModel; using APT.BaseData.Domain.Entities; using APT.BaseData.Domain.Entities.FM; using APT.BaseData.Domain.Enums.PF; using APT.BaseData.Domain.IServices; using APT.BaseData.Domain.IServices.AE; using APT.BaseData.Domain.IServices.FM; using APT.Infrastructure.Core; using APT.MS.Domain.Entities.HM; using APT.MS.Domain.Entities.OH; using APT.MS.Domain.Entities.PF; using APT.MS.Domain.Entities.SC; using APT.MS.Domain.Entities.TI; using APT.MS.Domain.Enums; using APT.Utility; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Primitives; using System; using System.Collections.Generic; using System.Data; using System.IO; using System.Linq; using System.Linq.Expressions; namespace APT.SC.WebApi.Controllers.Api.OH { [Route("api/OH/OHHealthExamResult")] public class OHHealthExamResultController : AuthorizeApiController { IFMFlowPermitService MFlowPermitService { get; set; } IPFApproveCallBackService ApproveCallBackService { get; set; } IAEAccidentEventReportService AccidentEventReportService { get; set; } IFMNotificationTaskService NotificationTaskService { get; set; } IFMUserService UserService { get; set; } IFMDepartmentService DepartmentService { get; set; } public readonly int beforeMonth = -3;//提前月数 public readonly int afterDays = 1;//推迟天数 public OHHealthExamResultController(IFMFlowPermitService mFlowPermitService, IPFApproveCallBackService approveCallBackService, IAEAccidentEventReportService accidentEventReportService, IFMNotificationTaskService notificationTaskService, IFMUserService userService, IFMDepartmentService departmentService) { MFlowPermitService = mFlowPermitService; ApproveCallBackService = approveCallBackService; AccidentEventReportService = accidentEventReportService; NotificationTaskService = notificationTaskService; UserService = userService; DepartmentService = departmentService; } /// /// 排序分页查询数据 /// /// 分页过滤实体 /// [HttpPost, Route("OrderPagedBatch")] public PagedActionResult OrderPagedBatch([FromBody] KeywordPageFilter pageFilter) { return SafeGetPagedData(delegate (PagedActionResult result) { DateTime dtNow = DateTime.Now.Date.AddDays(afterDays); DateTime dtMin = dtNow.AddMonths(beforeMonth); PagedActionResult orderPageEntities = GetOrderPageEntities(e => dtMin < e.START_TIME && e.END_TIME <= dtNow, pageFilter, null); result.Data = orderPageEntities.Data.OrderByDescending(e => e.END_TIME); result.TotalCount = orderPageEntities.TotalCount; }); } /// /// 排序分页查询数据 体检批次的人员 /// /// 分页过滤实体 /// [HttpPost, Route("OrderPagedBatchUser")] public PagedActionResult OrderPagedBatchUser([FromBody] KeywordPageFilter pageFilter) { return SafeGetPagedData(delegate (PagedActionResult result) { Guid EXAM_BATCH_ID = Guid.Empty; if (pageFilter.FilterGroup.Rules.Count > 0) { foreach (var item in pageFilter.FilterGroup.Rules) { if (item.Field == "EXAM_BATCH_ID") { EXAM_BATCH_ID = new Guid(item.Value.ToString()); pageFilter.FilterGroup.Rules.Remove(item); break; } } } if (EXAM_BATCH_ID != Guid.Empty) { Expression> expression = e => e.USER_ID.HasValue && e.EXAM_BATCH_ID == EXAM_BATCH_ID; pageFilter.Sort = null; PagedActionResult orderPageEntities = GetOrderPageEntities(expression, pageFilter, null); result.Data = orderPageEntities.Data; result.TotalCount = orderPageEntities.TotalCount; } else { result.Data = new List(); result.TotalCount = 0; } }); } ///// ///// 排序分页查询数据 体检批次的人员 ///// ///// 分页过滤实体 ///// //[HttpPost, Route("OrderPagedBatchUser")] //public PagedActionResult OrderPagedBatchUser([FromBody] KeywordPageFilter pageFilter) //{ // return SafeGetPagedData(delegate (PagedActionResult result) // { // Guid EXAM_BATCH_ID = Guid.Empty; // if (pageFilter.FilterGroup.Rules.Count > 0) // { // foreach (var item in pageFilter.FilterGroup.Rules) // { // if (item.Field == "EXAM_BATCH_ID") // { // EXAM_BATCH_ID = new Guid(item.Value.ToString()); // pageFilter.FilterGroup.Rules.Remove(item); // break; // } // } // } // if (EXAM_BATCH_ID != Guid.Empty) // { // Expression> expression = e => e.USER_ID.HasValue && e.EXAM_BATCH_ID == EXAM_BATCH_ID; // PagedActionResult orderPageEntities = GetOrderPageEntities(expression, pageFilter, null); // result.Data = orderPageEntities.Data.Select(e => e.Nav_User).OrderBy(e => e.NAME).ToList(); // result.TotalCount = orderPageEntities.TotalCount; // } // else // { // result.Data = new List(); // result.TotalCount = 0; // } // }); //} /// /// 体检周期表 修改 /// /// /// [HttpPost, Route("FullUpdate")] public JsonActionResult FullUpdate([FromBody] T_OH_HEALTH_EXAM_RESULT entity) { return SafeExecute(() => { //保存并发送的时候 发送给各个部门(负责人 或者安全员) //如果有待办 去除待办 if (!entity.NOTICE_REGISTER_ID.HasValue) { throw new Exception("请选择体检批次对应体检人员"); } var check = GetEntity(e => e.ID != entity.ID && e.NOTICE_REGISTER_ID == entity.NOTICE_REGISTER_ID); if (check != null) { throw new Exception("该体检批次体检人意见录入体检结果!"); } if (entity.STATUS == OHHealthExamResultStatus.Finish) { if (entity.RESULT_ENUM == OHHealthExamResult.NotSign) { throw new Exception("请选择体检结论!"); } if (string.IsNullOrEmpty(entity.DESCRIPTION)) { throw new Exception("请填写结果描述!"); } else if (entity.DESCRIPTION.Length > 500) { throw new Exception("结果描述不能超过500字!"); } } var listOccDisease = entity.Nav_OccDiseaseList; entity.Nav_OccDiseaseList = null; List listFiles = new List(); if (listOccDisease != null && listOccDisease.Any()) { foreach (var item in listOccDisease) { if (item.Nav_Files != null && item.Nav_Files.Any()) { listFiles.AddRange(item.Nav_Files); item.Nav_Files = null; } } } if (entity.RESULT_ENUM != OHHealthExamResult.Disease) { //非职业病 没有职业病信息 //直接清理 if (listOccDisease != null && listOccDisease.Any()) { listOccDisease.Clear(); listFiles.Clear(); } } if (entity.STATUS == OHHealthExamResultStatus.WaitSign) { //草稿 this.UnifiedCommit(() => { if (entity != null) UpdateEntityNoCommit(entity); //体检结果 if (listOccDisease != null && listOccDisease.Any()) BantchSaveEntityNoCommit(listOccDisease);//职业病 if (listFiles != null && listFiles.Any()) BantchSaveEntityNoCommit(listFiles);//附件 }); } else { //如果数据库中 已经是 待写入职业病信息 或者 已完成 状态 不需要发送 调岗 或者会议通知 bool isNotice = true; if (entity.RESULT_ENUM == OHHealthExamResult.Disease) { var resultCheck = GetEntity(entity.ID); if (resultCheck != null && (resultCheck.STATUS == OHHealthExamResultStatus.WaitSignDisease || resultCheck.STATUS == OHHealthExamResultStatus.Finish)) { //如果是导入数据 保存、保存并发送 //导入的时候已经发送了 调岗信息 不需要再次通知 isNotice = false; } } if (entity.RESULT_ENUM == OHHealthExamResult.Disease && (listOccDisease == null || !listOccDisease.Any())) { throw new Exception("请填写职业病信息后再保存!"); } //OHHealthExamResultStatus.WaitSignDisease 也会进来 if (entity.STATUS == OHHealthExamResultStatus.Finish) { int rowIndex = 1; foreach (var item in listOccDisease) { if (!item.OCC_DISEASE_ID.HasValue) { throw new Exception("请选择行:" + rowIndex + "的职业病"); } if (!item.OCC_DISEASE_SEVERITY_ID.HasValue) { throw new Exception("请选择行:" + rowIndex + "的职业病严重程度"); } if (string.IsNullOrEmpty(item.DESCRIPTION)) { throw new Exception("请选择行:" + rowIndex + "的病状描述"); } rowIndex++; } } //5、体检结论结果为职业病触发今日提醒给安环部负责人;消息类型为:召开会议;消息内容为:请召开职业危害防治措施的有效性评估会 //6、体检结论结果为职业病同时触发今日提醒给体检结论结果为职业病的员工的上级部门负责人;消息类型为:其他;消息内容为:请给“员工姓名”调岗。 //上级部门负责人,例如: 班组人员 =》 班长 班长 =》车间级负责人 T_FM_NOTIFICATION_TASK taskUserMaster = null; T_FM_NOTIFICATION_TASK taskSafe = null; T_FM_NOTIFICATION_TASK taskEnd = null; if (entity.TaskID != Guid.Empty) { taskEnd = NotificationTaskService.GetEntityTask(entity.TaskID, "OH012_SHOWPRINT"); } #region 职业病 今日提醒 if (entity.RESULT_ENUM == OHHealthExamResult.Disease && isNotice) { T_FM_USER userMaster = null;//上级负责人 //职业病 var user = GetEntity(e => e.ID == entity.USER_ID, new string[] { "Nav_ApproveRole", "Nav_Department.Nav_User" }); if (user.Nav_ApproveRole == null || !user.Nav_ApproveRole.NAME.Contains("负责人")) { userMaster = user.Nav_Department.Nav_User; } else { //上一级部门的负责人 if (user.Nav_Department.PARENT_ID.HasValue) { T_FM_DEPARTMENT dep = GetEntity(e => e.ID == user.Nav_Department.PARENT_ID, new string[] { "Nav_User" }); userMaster = dep.Nav_User; } else { //没有上级部门 } } if (userMaster != null) { T_FM_USER userResult = GetEntity(entity.USER_ID.Value); taskUserMaster = NotificationTaskService.InsertUserNoticeTaskModel("请给【" + userResult.NAME + "】调岗", Guid.Empty, entity.ORG_ID, userMaster.ID, userMaster.NAME, DateTime.Now, DateTime.Now.AddDays(1), (int)FMNoticeTypeEnum.今日提醒, ""); } string Msg = string.Empty; T_FM_USER userSafe = UserService.GetRoleUser(ref Msg, "安环部负责人", null, null); if (userSafe == null || string.IsNullOrEmpty(userSafe.NAME)) { if (!string.IsNullOrEmpty(Msg)) { throw new Exception(Msg); } else { throw new Exception("获取安环部负责人失败"); } } else { taskSafe = NotificationTaskService.InsertUserNoticeTaskModel("请召开职业危害防治措施的有效性评估会", Guid.Empty, entity.ORG_ID, userSafe.ID, userSafe.NAME, DateTime.Now, DateTime.Now.AddDays(1), (int)FMNoticeTypeEnum.今日提醒, ""); } } #endregion this.UnifiedCommit(() => { if (entity != null) UpdateEntityNoCommit(entity); //体检结果 if (listOccDisease != null && listOccDisease.Any()) BantchSaveEntityNoCommit(listOccDisease);//职业病 if (listFiles != null && listFiles.Any()) BantchSaveEntityNoCommit(listFiles);//附件 if (taskUserMaster != null) UpdateEntityNoCommit(taskUserMaster); //上级领导 调岗 if (taskSafe != null) UpdateEntityNoCommit(taskSafe); //安环部 召开会议 if (taskEnd != null) UpdateEntityNoCommit(taskEnd); //结束待办 }); } return true; }); } /// /// 知识库 超级管理员修改体检结果 /// /// /// [HttpPost, Route("FullUpdateResult")] public JsonActionResult FullUpdateResult([FromBody] T_OH_HEALTH_EXAM_RESULT entity) { return SafeExecute(() => { if (APT.Infrastructure.Api.AppContext.CurrentSession.UserName != "admin") { throw new Exception("只有超级管理员才能修改此体检结果"); } //保存并发送的时候 发送给各个部门(负责人 或者安全员) //如果有待办 去除待办 if (!entity.NOTICE_REGISTER_ID.HasValue) { throw new Exception("请选择体检批次对应体检人员"); } if (entity.RESULT_ENUM == OHHealthExamResult.NotSign) { throw new Exception("请选择体检结论!"); } if (string.IsNullOrEmpty(entity.DESCRIPTION)) { throw new Exception("请填写结果描述!"); } else if (entity.DESCRIPTION.Length > 500) { throw new Exception("结果描述不能超过500字!"); } var listOccDisease = entity.Nav_OccDiseaseList; entity.Nav_OccDiseaseList = null; List listFiles = new List(); if (entity.RESULT_ENUM == OHHealthExamResult.Disease && (listOccDisease == null || !listOccDisease.Any())) { throw new Exception("请填写职业病信息后再保存!"); } if (listOccDisease != null && listOccDisease.Any()) { foreach (var item in listOccDisease) { if (entity.RESULT_ENUM != OHHealthExamResult.Disease) { item.IS_DELETED = true; } if (item.Nav_Files != null && item.Nav_Files.Any()) { listFiles.AddRange(item.Nav_Files); item.Nav_Files = null; } } } if (entity.RESULT_ENUM != OHHealthExamResult.Disease) { foreach (var item in listFiles) { item.IS_DELETED = true; } } int rowIndex = 1; foreach (var item in listOccDisease) { if (item.IS_DELETED) { continue; } if (!item.OCC_DISEASE_ID.HasValue) { throw new Exception("请选择行:" + rowIndex + "的职业病"); } if (!item.OCC_DISEASE_SEVERITY_ID.HasValue) { throw new Exception("请选择行:" + rowIndex + "的职业病严重程度"); } if (string.IsNullOrEmpty(item.DESCRIPTION)) { throw new Exception("请选择行:" + rowIndex + "的病状描述"); } rowIndex++; } //草稿 this.UnifiedCommit(() => { if (entity != null) UpdateEntityNoCommit(entity); //体检结果 if (listOccDisease != null && listOccDisease.Any()) BantchSaveEntityNoCommit(listOccDisease);//职业病 if (listFiles != null && listFiles.Any()) BantchSaveEntityNoCommit(listFiles);//附件 }); return true; }); } [HttpPost, Route("ImportShow2")] public PagedActionResult ImportShow2() { return null; } /// /// 获取导入的初始数据 /// /// /// /// [HttpPost, Route("GetImportIni")] public JsonActionResult GetImportIni([FromBody] KeywordFilter filter) { return SafeExecute(() => { Guid ID = Guid.Empty; if (filter.FilterGroup.Rules.Count > 0) { foreach (var item in filter.FilterGroup.Rules) { if (item.Field == "ID") { ID = new Guid(item.Value.ToString()); } } filter.FilterGroup.Rules.Clear(); } if (ID == Guid.Empty) { throw new Exception("获取信息失败!"); } List listNotice = new List(); T_OH_HEALTH_EXAM_RESULT_IMPORT result = GetImports(ID, ref listNotice); #region 方法提取 //T_OH_HEALTH_EXAM_RESULT_IMPORT result = GetEntity(e => e.ID == ID, new string[] { "Nav_ExamNotice" }); //Guid? PARENTID = result.Nav_ExamNotice.PARENTID; //var listNotice = GetEntities(e => e.PARENTID == PARENTID, null, null); //List listNoticeID = listNotice.Select(e => e.ID).ToList(); //var listNoticeRegist = GetEntities(e => listNoticeID.Contains(e.NOTICE_ID.Value), null, new string[] { "Nav_User", "Nav_ExamBatch" }); //e.NOTICE_ID == result.NOTICE_ID //List listResult = new List(); //if (listNoticeRegist != null && listNoticeRegist.Any()) //{ // foreach (var item in listNoticeRegist) // { // listResult.Add(new T_OH_HEALTH_EXAM_RESULT() // { // ID = Guid.NewGuid(), // NOTICE_REGISTER_ID = item.ID, // Nav_NoticeRegister = item, // USER_ID = item.USER_ID, // Nav_User = item.Nav_User, // RESULT_ENUM = OHHealthExamResult.NotSign, // DESCRIPTION = "", // SUGGESTION = "", // STATUS = OHHealthExamResultStatus.WaitSign, // IS_DELETED = false, // ORG_ID = item.ORG_ID, // //ENTITY_ORG_TPYE // //FORM_ID // //FLOW_STATUS // //FLOW_SEND_STATUS // //FLOW_ID // //CREATE_TIME // //MODIFY_TIME // //CREATER_ID // //MODIFIER_ID // }); // } //} //result.Nav_ListResult = listResult; #endregion return result; }); } /// /// 获取导入数据 /// /// /// /// public T_OH_HEALTH_EXAM_RESULT_IMPORT GetImports(Guid ID, ref List listNotice) { T_OH_HEALTH_EXAM_RESULT_IMPORT result = GetEntity(e => e.ID == ID, new string[] { "Nav_ExamNotice" }); Guid? PARENTID = result.Nav_ExamNotice.PARENTID; listNotice = GetEntities(e => e.PARENTID == PARENTID, null, null).ToList(); List listNoticeID = listNotice.Select(e => e.ID).ToList(); var listNoticeRegist = GetEntities(e => listNoticeID.Contains(e.NOTICE_ID.Value) && e.STATUS != OHHealthExamNoticeRegisterStatus.NoticeResult, null, new string[] { "Nav_User", "Nav_ExamBatch" }); //e.NOTICE_ID == result.NOTICE_ID List listResult = new List(); if (listNoticeRegist != null && listNoticeRegist.Any()) { foreach (var item in listNoticeRegist) { listResult.Add(new T_OH_HEALTH_EXAM_RESULT() { ID = Guid.NewGuid(), NOTICE_REGISTER_ID = item.ID, Nav_NoticeRegister = item, USER_ID = item.USER_ID, Nav_User = item.Nav_User, RESULT_ENUM = OHHealthExamResult.NotSign, DESCRIPTION = "", SUGGESTION = "", STATUS = OHHealthExamResultStatus.WaitSign, IS_DELETED = false, ORG_ID = item.ORG_ID, //ENTITY_ORG_TPYE //FORM_ID //FLOW_STATUS //FLOW_SEND_STATUS //FLOW_ID //CREATE_TIME //MODIFY_TIME //CREATER_ID //MODIFIER_ID }); } } result.Nav_ListResult = listResult; return result; } /// /// 显示批量导入数据 /// /// /// [HttpPost, Route("ImportShow")] public PagedActionResult ImportShow(IFormCollection filer) { StringValues taskID = string.Empty; StringValues id = string.Empty; filer.TryGetValue("TaskID", out taskID); try { filer.TryGetValue("id", out id); if (string.IsNullOrEmpty(id.ToString())) { throw new Exception("获取传参失败!"); } } catch { throw new Exception("获取传参失败!"); throw; } return SafeGetPagedData(delegate (PagedActionResult result) { var httpRequest = this.HttpContext.Request; string orgIdStr = httpRequest.Form["OrgId"];// 获取 组织 Guid? orgId = null; result.IsSuccessful = true; if (!string.IsNullOrEmpty(orgIdStr)) { orgId = new Guid(orgIdStr); var dic = Path.Combine(System.AppContext.BaseDirectory, "tempImportFiles"); if (!Directory.Exists(dic)) Directory.CreateDirectory(dic); foreach (var key in httpRequest.Form.Files) // 文件键 { var postedFile = key; // 获取文件键对应的文件对象 string filePath = Path.Combine(dic, DateTime.Now.ToString("yyyy_MM_dd_hh_mm_ss") + "_" + postedFile.FileName); Byte[] fileData = new Byte[postedFile.Length]; Stream sr = postedFile.OpenReadStream();//创建数据流对象 sr.Read(fileData, 0, (int)postedFile.Length); using (FileStream fs = new FileStream(filePath, FileMode.CreateNew)) { fs.Write(fileData, 0, fileData.Length); fs.Flush(); fs.Close(); } //获取数据 Dictionary startRowIndexs = new Dictionary(); startRowIndexs.Add(0, 2);//根据Excel格式数据赋值 var dataTables = FileUtils.ReadExcelByOledb(filePath, startRowIndexs); //bool isOK = InsertModel(dataTables.Tables[0], orgId.Value, ref Msg); //try //{ // System.IO.File.Delete(filePath); //} //catch { } #region 提取数据 DataTable dtInfo = dataTables.Tables[0]; int rowCount = dtInfo.Rows.Count; int colunCount = dtInfo.Columns.Count; if (rowCount < 1) { result.ErrorMessage = "获取导入数据失败!"; result.IsSuccessful = false; //return result; } else if (colunCount != 6) { result.ErrorMessage = "获取导入数据异常!"; result.IsSuccessful = false; } else { //体检批次 体检人员 身份证号 体检结论 结果描述 处理意见 //T_OH_HEALTH_EXAM_NOTICE_REGISTER Dictionary> listEmptyInfo = new Dictionary>(); Dictionary dicErrorRowResult = new Dictionary(); List listEmptyRowColum = null; List listName = new List();//姓名 List listBatch = new List(); string strBatch = string.Empty; List listExamResult = new List(); OHHealthExamResult[] HealthResult = Enum.GetValues(); foreach (var item in HealthResult) { listExamResult.Add(item.GetDescription()); } for (int i = 0; i < rowCount; i++) { #region 不能为空 listEmptyRowColum = null; for (int j = 0; j < 4; j++) { if (j != 2) { if (dtInfo.Rows[i][j] == null || string.IsNullOrEmpty(dtInfo.Rows[i][j].ToString())) { if (listEmptyRowColum == null) { listEmptyRowColum = new List(); } listEmptyRowColum.Add(j); } else if (j == 3) { if (!listExamResult.Contains(dtInfo.Rows[i][j].ToString().Trim())) { dicErrorRowResult.Add(i, dtInfo.Rows[i][j].ToString().Trim()); } } } if (listEmptyInfo.Count == 0) { //姓名 listName.Add(dtInfo.Rows[i][1].ToString().Trim()); //批次 strBatch = dtInfo.Rows[i][0].ToString().Trim(); if (!listBatch.Contains(strBatch)) { listBatch.Add(dtInfo.Rows[i][0].ToString().Trim()); } } } //数据不能为空 if (listEmptyRowColum != null) { listEmptyInfo.Add(i, listEmptyRowColum); } #endregion } if (listEmptyInfo.Count > 0 || dicErrorRowResult.Count > 0) { string Msg = string.Empty; if (listEmptyInfo.Count > 0) { foreach (var item in listEmptyInfo) { Msg += (Msg.Length == 0 ? "" : ";") + "行:" + item.Key + " 列【" + string.Join(',', item.Value) + "】"; } Msg += "信息不能为空!"; } if (dicErrorRowResult.Count > 0) { string errorResult = "体检结论有误,"; foreach (var item in dicErrorRowResult) { errorResult += "行:" + item.Key + " 【" + item.Value + "】"; } errorResult += "!"; Msg += (Msg.Length > 0 ? "\r\n" : "") + errorResult; } result.ErrorMessage = Msg; result.IsSuccessful = false; //return result; } else { Guid ID = new Guid(id); T_OH_HEALTH_EXAM_RESULT_IMPORT resultImport = GetEntity(e => e.ID == ID, new string[] { "Nav_ExamNotice" }); Guid? PARENTID = resultImport.Nav_ExamNotice.PARENTID; List listNotice = GetEntities(e => e.PARENTID == PARENTID, null, null).ToList(); var listBatchId = listNotice.Where(e => e.EXAM_BATCH_ID.HasValue).Select(e => e.EXAM_BATCH_ID.Value); //3个月之前结束 到 2天后结束 //DateTime dtMin = DateTime.Now.AddMonths(beforeMonth); //DateTime dtMax = DateTime.Now.AddDays(afterDays); ////姓名 //List listModelUser = GetEntities(e => listName.Contains(e.NAME), null, null).ToList(); //批次 如果名称一样 怎么分辨 //List listModelBatch = GetEntities(e => listBatch.Contains(e.BATCH) && e.END_TIME > dtMin && e.END_TIME < dtMax, null, null).ToList(); List listModelBatch = GetEntities(e => listBatchId.Contains(e.ID), null, null).ToList(); //体检人员安排 T_OH_HEALTH_EXAM_NOTICE_REGISTER T_OH_HEALTH_EXAM_BATCH modelCheck = null; //有 批次信息 数据库 没找到 foreach (var item in listBatch) { modelCheck = listModelBatch.Find(e => e.BATCH == item);// listBatch.Contains(e.BATCH) if (result.IsSuccessful && modelCheck == null) { result.ErrorMessage = "未找到批次【" + item + "】信息"; result.IsSuccessful = false; break; } } if (result.IsSuccessful) { List listBatchID = listModelBatch.Select(e => e.ID).ToList(); //导入数据 是已经通知过的 未通知体检结果的 var listNoticeRegister = GetEntities(e => e.EXAM_BATCH_ID.HasValue && listBatchID.Contains(e.EXAM_BATCH_ID.Value) && e.STATUS != OHHealthExamNoticeRegisterStatus.WaitNotice && e.STATUS != OHHealthExamNoticeRegisterStatus.NoticeResult, null, new string[] { "Nav_ExamBatch", "Nav_User" }); //rowCount colunCount string strName = string.Empty; string CardID = string.Empty; Dictionary dicRowNameNone = new Dictionary(); List listResult = new List(); T_OH_HEALTH_EXAM_RESULT modelShow = null; T_OH_HEALTH_EXAM_NOTICE_REGISTER modelSearch = null; List listNoticeRegisterChange = new List(); Dictionary dicIUser = new Dictionary(); Dictionary dicIRegister = new Dictionary(); #region 数据组装 for (int i = 0; i < rowCount; i++) { //批次 strBatch = dtInfo.Rows[i][0].ToString().Trim(); //姓名 strName = dtInfo.Rows[i][1].ToString().Trim(); var listRegister = listNoticeRegister.Where(e => !e.IS_DELETED && e.USER_ID.HasValue && e.Nav_User.NAME == strName && e.EXAM_BATCH_ID.HasValue && e.Nav_ExamBatch.BATCH == strBatch); if (listRegister == null || !listRegister.Any()) { dicRowNameNone.Add(i, strName); } else { if (listRegister.Count() > 1) { //身份证号 CardID = dtInfo.Rows[i][2].ToString().Trim(); //过滤 //判断身份证 //提示问题 if (!string.IsNullOrEmpty(CardID)) { modelSearch = listRegister.FirstOrDefault(e => e.Nav_User.ID_CARD == CardID); } } else { modelSearch = listRegister.ToList()[0]; } if (modelSearch == null) { dicRowNameNone.Add(i, strName); } else { //体检批次 体检人员 身份证号 体检结论 结果描述 处理意见 if (dicRowNameNone.Count == 0) { modelShow = new T_OH_HEALTH_EXAM_RESULT(); modelShow.ID = Guid.NewGuid(); modelShow.NOTICE_REGISTER_ID = modelSearch.ID; modelShow.USER_ID = modelSearch.USER_ID; dicIUser.Add(i, modelSearch.Nav_User); dicIRegister.Add(i, modelSearch); //modelShow.Nav_User = modelSearch.Nav_User; modelShow.RESULT_ENUM = GetResult(dtInfo.Rows[i][3].ToString(), listExamResult, HealthResult).Value;//体检结论 modelShow.DESCRIPTION = dtInfo.Rows[i][4].ToString().Trim(); modelShow.SUGGESTION = dtInfo.Rows[i][5].ToString().Trim(); //modelShow.STATUS = OHHealthExamResultStatus.WaitSign; //直接显示在页面 //直接插入数据库 if (modelShow.RESULT_ENUM == OHHealthExamResult.Disease) { //职业病 待填写职业病信息 modelShow.STATUS = OHHealthExamResultStatus.WaitSignDisease; } else { //非职业病 导入数据完成 modelShow.STATUS = OHHealthExamResultStatus.Finish; } modelShow.IS_DELETED = false; modelShow.ORG_ID = orgId; //modelShow.ENTITY_ORG_TPYE =; //modelShow.FORM_ID =; //modelShow.FLOW_STATUS =; //modelShow.FLOW_SEND_STATUS =; //modelShow.FLOW_ID =; //modelShow.CREATE_TIME =; //modelShow.MODIFY_TIME =; //modelShow.CREATER_ID =; //modelShow.MODIFIER_ID =; listResult.Add(modelShow); //体检通知 状态修改 modelSearch.STATUS = OHHealthExamNoticeRegisterStatus.NoticeResult; listNoticeRegisterChange.Add(modelSearch); } } } } //var notInt = resultImport.Nav_ListResult.Where(e => e.RESULT_ENUM != OHHealthExamResult.NoException); //T_FM_NOTIFICATION_TASK taskEnd = null; //if (notInt == null || !notInt.Any()) //{ // if (!string.IsNullOrEmpty(taskID.ToString())) // { // //结束待办 // taskEnd = NotificationTaskService.GetEntityTask(new Guid(taskID.ToString())); // } //} #endregion if (dicRowNameNone.Count > 0) { string Msg = string.Empty; foreach (var item in dicRowNameNone) { Msg += (Msg.Length > 0 ? ";" : "") + "行" + item.Key + "【" + item.Value + "】"; } result.ErrorMessage = "未找到人员批次未上报结果信息【" + Msg + "】信息"; result.IsSuccessful = false; } if (result.IsSuccessful) { if (listResult.Count > 0) { //不能清空 否则值不对 //foreach (var item in listNoticeRegisterChange) //{ // item.Nav_User // item.Nav_ExamBatch //} #region 职业病 T_FM_NOTIFICATION_TASK taskSafe = null; List listTaskMaster = new List(); var listDise = listResult.FindAll(e => e.RESULT_ENUM == OHHealthExamResult.Disease); if (listDise != null && listDise.Count > 0) { string MsgWarming = string.Empty; #region 安环部会议通知 T_FM_USER userSafe = UserService.GetRoleUser(ref MsgWarming, "安环部负责人", null, null); if (userSafe == null || string.IsNullOrEmpty(userSafe.NAME)) { if (!string.IsNullOrEmpty(MsgWarming)) { throw new Exception(MsgWarming); } else { throw new Exception("获取安环部负责人失败"); } } else { taskSafe = NotificationTaskService.InsertUserNoticeTaskModel("请召开职业危害防治措施的有效性评估会", Guid.Empty, orgId, userSafe.ID, userSafe.NAME, DateTime.Now, DateTime.Now.AddDays(1), (int)FMNoticeTypeEnum.今日提醒, ""); } #endregion #region 给职业病 上级部门负责人发送调岗通知 List listUserID = listDise.Select(e => e.USER_ID.Value).ToList(); List listUserDise = GetEntities(e => listUserID.Contains(e.ID), null, new string[] { "Nav_ApproveRole", "Nav_Department.Nav_User" }).ToList(); T_FM_USER userMaster = null;//上级负责人 //职业病 foreach (var item in listDise) { userMaster = null; var user = listUserDise.FirstOrDefault(e => e.ID == item.USER_ID); if (user.Nav_ApproveRole == null || !user.Nav_ApproveRole.NAME.Contains("负责人")) { userMaster = user.Nav_Department.Nav_User; } else { //上一级部门的负责人 if (user.Nav_Department.PARENT_ID.HasValue) { T_FM_DEPARTMENT dep = GetEntity(e => e.ID == user.Nav_Department.PARENT_ID, new string[] { "Nav_User" }); userMaster = dep.Nav_User; } else { //没有上级部门 } } if (userMaster != null) { T_FM_USER userResult = GetEntity(item.USER_ID.Value); var taskUserMaster = NotificationTaskService.InsertUserNoticeTaskModel("体检结果为职业病,请给【" + userResult.NAME + "】调岗", Guid.Empty, item.ORG_ID, userMaster.ID, userMaster.NAME, DateTime.Now, DateTime.Now.AddDays(1), (int)FMNoticeTypeEnum.今日提醒, ""); listTaskMaster.Add(taskUserMaster); } } #endregion } #endregion this.UnifiedCommit(() => { if (listResult != null && listResult.Any()) BantchSaveEntityNoCommit(listResult);//体检信息 if (listNoticeRegisterChange != null && listNoticeRegisterChange.Any()) BantchSaveEntityNoCommit(listNoticeRegisterChange);//体检 通知状态修改 if (taskSafe != null) UpdateEntityNoCommit(taskSafe); //职业病给安环部发送通知 if (listTaskMaster != null && listTaskMaster.Any()) BantchSaveEntityNoCommit(listTaskMaster);//调岗通知 }); //数据库 查找是否 还有未导入审批结果的 如果没有 结束待办 if (!string.IsNullOrEmpty(taskID.ToString())) { T_FM_NOTIFICATION_TASK taskEnd = null; var listNoticeRegisterCheck = GetEntities(e => e.EXAM_BATCH_ID.HasValue && listBatchID.Contains(e.EXAM_BATCH_ID.Value) && e.STATUS != OHHealthExamNoticeRegisterStatus.WaitNotice && e.STATUS != OHHealthExamNoticeRegisterStatus.NoticeResult, null, null); if (listNoticeRegisterCheck == null || !listNoticeRegisterCheck.Any()) { this.UnifiedCommit(() => { if (taskEnd != null) UpdateEntityNoCommit(taskEnd);//全部人都填写结束待办(人事专员) }); } } #region 返回数据导航属性处理 for (int i = 0; i < listResult.Count; i++) { listResult[i].Nav_User = dicIUser[i];//用户信息 listResult[i].Nav_NoticeRegister = dicIRegister[i]; } #endregion } result.Data = listResult; result.TotalCount = listResult.Count; } } } } try { System.IO.File.Delete(filePath); } catch { } #endregion } } else { result.Data = null;//dataTables.Tables[0] result.TotalCount = 0; } //return result; }); } /// /// 获取体检结论 /// /// /// /// /// public OHHealthExamResult? GetResult(string strResult, List listExamResult, OHHealthExamResult[] HealthResult) { strResult = strResult.Trim(); if (listExamResult.Contains(strResult.Trim())) { foreach (var item in HealthResult) { if (item.GetDescription() == strResult) { return item; } } } return null; } ///// ///// 显示批量导入数据 ///// ///// ///// //[HttpPost, Route("ImportShow")] //public PagedActionResult ImportShow([FromBody] KeywordPageFilter pageFilter) //{ // //return WitOrderPaged(null, pageFilter); // return SafeGetPagedData(delegate (PagedActionResult result) // { // var httpRequest = this.HttpContext.Request; // string orgIdStr = httpRequest.Form["OrgId"];// 获取 组织 // Guid? orgId = null; // if (!string.IsNullOrEmpty(orgIdStr)) // orgId = new Guid(orgIdStr); // else // { // result.Data = null;//dataTables.Tables[0] // result.TotalCount = 0; // } // var dic = Path.Combine(System.AppContext.BaseDirectory, "tempImportFiles"); // if (!Directory.Exists(dic)) // Directory.CreateDirectory(dic); // foreach (var key in httpRequest.Form.Files) // 文件键 // { // var postedFile = key; // 获取文件键对应的文件对象 // string filePath = Path.Combine(dic, DateTime.Now.ToString("yyyy_MM_dd_hh_mm_ss") + "_" + postedFile.FileName); // Byte[] fileData = new Byte[postedFile.Length]; // Stream sr = postedFile.OpenReadStream();//创建数据流对象 // sr.Read(fileData, 0, (int)postedFile.Length); // using (FileStream fs = new FileStream(filePath, FileMode.CreateNew)) // { // fs.Write(fileData, 0, fileData.Length); // fs.Flush(); // fs.Close(); // } // //获取数据 // Dictionary startRowIndexs = new Dictionary(); // startRowIndexs.Add(0, 2);//根据Excel格式数据赋值 // var dataTables = FileUtils.ReadExcelByOledb(filePath, startRowIndexs); // //bool isOK = InsertModel(dataTables.Tables[0], orgId.Value, ref Msg); // //try // //{ // // System.IO.File.Delete(filePath); // //} // //catch { } // //result.Data = orderPageEntities.Data;//dataTables.Tables[0] // result.TotalCount = dataTables.Tables[0].Rows.Count; // } // //return result; // }); //}OrderPagedUser /// /// 排序分页查询数据 /// /// 分页过滤实体 /// [HttpPost, Route("OrderPagedUser")] public PagedActionResult OrderPagedUser([FromBody] KeywordPageFilter pageFilter) { return SafeGetPagedData(delegate (PagedActionResult result) { string Name = string.Empty; string DEPARTMENTNAME = string.Empty; string POSTNAME = string.Empty; OHHealthExamResult? RESULT_ENUM = null; if (pageFilter.FilterGroup.Rules.Count > 0) { foreach (var item in pageFilter.FilterGroup.Rules) { if (item.Field == "NAME") { Name = item.Value.ToString(); } else if (item.Field == "DEPARTMENTNAME") { DEPARTMENTNAME = item.Value.ToString(); } else if (item.Field == "POSTNAME") { POSTNAME = item.Value.ToString(); } else if (item.Field == "RESULT_ENUM") { try { RESULT_ENUM = (OHHealthExamResult)int.Parse(item.Value.ToString()); } catch { } } } pageFilter.FilterGroup.Rules.Clear(); } Expression> expressionU = e => e.ORG_ID == pageFilter.OrgId; if (!string.IsNullOrEmpty(Name)) { expressionU = expressionU.And(e => e.NAME.Contains(Name)); } if (!string.IsNullOrEmpty(DEPARTMENTNAME)) { expressionU = expressionU.And(e => e.DEPARTMENT_ID.HasValue && e.Nav_Department.NAME.Contains(DEPARTMENTNAME)); } if (!string.IsNullOrEmpty(POSTNAME)) { expressionU = expressionU.And(e => e.PERSON_ID.HasValue && e.Nav_Person.POST_ID.HasValue && e.Nav_Person.Nav_Post.NAME.Contains(POSTNAME)); } #region 自定义查询 List listResult = GetEntities(e => e.USER_ID.HasValue, null, null).ToList(); List listDis = GetEntities(e => e.RESULT_ID.HasValue, null, new string[] { "Nav_Files.Nav_ImgFile.Nav_File" }).ToList(); List listUser = GetEntities(expressionU, null, "Nav_Department", "Nav_Person.Nav_Post").ToList(); List listDiseaseSeverityLevel = GetEntities(null, null, null).ToList(); List listDisease = GetEntities(null, null, null).ToList(); if (listResult.Count < 1) { result.Data = null; result.TotalCount = 0; } var query = from resultQ in listResult join user in listUser on resultQ.USER_ID equals user.ID join detail1 in listDis on resultQ.ID equals detail1.RESULT_ID into temp from detail in temp.DefaultIfEmpty() join dise1 in listDisease on detail?.OCC_DISEASE_ID equals dise1.ID into tempDis from dise in tempDis.DefaultIfEmpty() join diseLevel1 in listDiseaseSeverityLevel on detail?.OCC_DISEASE_SEVERITY_ID equals diseLevel1.ID into tempLevelDis from diseLevel in tempLevelDis.DefaultIfEmpty() select new HealthResult { ID = resultQ.ID, CODE = user.CODE, ORG_ID = resultQ.ORG_ID, USER_ID = resultQ.USER_ID.Value, RESULT_ENUM = resultQ.RESULT_ENUM, //DESCRIPTION = resultQ.DESCRIPTION, //SUGGESTION = resultQ.SUGGESTION, CREATE_TIME = resultQ.CREATE_TIME, NAME = user.NAME, ID_CARD = user.ID_CARD, ENTRYTIME = user.ENTRYTIME == DateTime.MinValue ? null : user.ENTRYTIME, DEPARTMENT_ID = user.DEPARTMENT_ID, DEPARTMENTNAME = user.Nav_Department.NAME, POSTNAME = user.Nav_Person.Nav_Post.NAME, PERSON_ID = user.PERSON_ID, DEPARTURETIME = user.DEPARTURETIME == DateTime.MinValue ? null : user.DEPARTURETIME, //DIAGNOSE_AGENCY = detail == null ? null : detail.DIAGNOSE_AGENCY, //DIAGNOSE_METHOD = detail == null ? null : detail.DIAGNOSE_METHOD, //DisDESCRIPTION = detail == null ? null : detail.DESCRIPTION, //OCC_HISTORY = detail == null ? null : detail.OCC_HISTORY, OCC_DISEASE_SEVERITY_ID = detail == null ? null : detail.OCC_DISEASE_SEVERITY_ID, OCC_DISEASE_ID = detail == null ? null : detail.OCC_DISEASE_ID, //disName = dise == null ? "" : dise.NAME, disLevelName = diseLevel == null ? "" : diseLevel.NAME, //Nav_Files = detail == null ? null : detail.Nav_Files }; #region 查询条件 if (!string.IsNullOrEmpty(Name)) { query = query.Where(e => e.NAME.Contains(Name)); } if (!string.IsNullOrEmpty(DEPARTMENTNAME)) { query = query.Where(e => e.DEPARTMENTNAME != null && e.DEPARTMENTNAME.Contains(DEPARTMENTNAME)); } if (!string.IsNullOrEmpty(POSTNAME)) { query = query.Where(e => e.POSTNAME != null && e.POSTNAME.Contains(POSTNAME)); } if (RESULT_ENUM.HasValue) { query = query.Where(e => e.RESULT_ENUM == RESULT_ENUM.Value); } #endregion var listResultTemp = query.OrderBy(e => e.NAME).ThenByDescending(e => e.CREATE_TIME).Skip((pageFilter.PageIndex - 1) * pageFilter.Limit).Take(pageFilter.Limit).ToList(); result.Data = listResultTemp; result.TotalCount = query.Count(); #endregion #region 旧版 不满足需求 //pageFilter.Sort = "Nav_User.NAME"; //pageFilter.Include.Remove("Nav_User.Nav_Department"); //pageFilter.Include.Remove("Nav_User.Nav_Person.Nav_Post"); //pageFilter.Include.Remove("Nav_OccDiseaseList.Nav_OccDisease"); //pageFilter.Include.Remove("Nav_OccDiseaseList.Nav_OccDiseaseSeverity"); //pageFilter.Include.Remove("Nav_OccDiseaseList.Nav_Files.Nav_ImgFile.Nav_File"); //pageFilter.SelectField = new List { "ID", "USER_ID", "RESULT_ENUM", "DESCRIPTION", "SUGGESTION", "RESULT_ENUM", "Nav_User.NAME", "Nav_User.ID_CARD", "Nav_User.ENTRYTIME", "Nav_User.DEPARTMENT_ID", "Nav_User.PERSON_ID", "Nav_User.DEPARTURETIME", "Nav_OccDiseaseList.OCC_DISEASE_SEVERITY_ID", "Nav_OccDiseaseList.OCC_DISEASE_ID" }; //PagedActionResult orderPageEntities = GetOrderPageEntities(e => e.USER_ID.HasValue, pageFilter, null); //result.Data = orderPageEntities.Data; //if (result.Data != null && result.Data.Any()) //{ // #region 岗位 // var listPersonID = result.Data.Where(e => e.Nav_User.PERSON_ID.HasValue).Select(e => e.Nav_User.PERSON_ID); // var listPerson = GetEntities(e => listPersonID.Contains(e.ID), null, "Nav_Post"); // T_FM_PERSON personTemp = null; // #endregion // #region 部门 // var listDepID = result.Data.Select(e => e.Nav_User.DEPARTMENT_ID); // var listDep = GetEntities(e => listDepID.Contains(e.ID), null, null); // T_FM_DEPARTMENT depTemp = null; // #endregion // #region 职业病 严重等级 // List listDiseaseSeverityLevel = GetEntities(e => e.ORG_ID == pageFilter.OrgId, null, "").ToList(); // List listDisease = GetEntities(e => e.ORG_ID == pageFilter.OrgId, null, "").ToList(); // T_OH_HEALTH_EXAM_OCC_DISEASE_SEVERITY_LEVEL levelTemp = null; // T_OH_HEALTH_EXAM_OCC_DISEASE diseaseTemp = null; // #endregion // foreach (var item in result.Data) // { // #region 入职离职日期 // if (item.Nav_User.ENTRYTIME != DateTime.MinValue) // item.ENTRYTIME = item.Nav_User.ENTRYTIME; // if (item.Nav_User.DEPARTURETIME != DateTime.MinValue) // item.DEPARTURETIME = item.Nav_User.DEPARTURETIME; // #endregion // #region 人员岗位 // if (item.Nav_User.PERSON_ID.HasValue) // { // personTemp = listPerson.FirstOrDefault(e => e.ID == item.Nav_User.PERSON_ID); // if (personTemp != null) // { // item.Nav_User.Nav_Person = personTemp; // } // } // #endregion // #region 部门 // if (item.Nav_User.DEPARTMENT_ID.HasValue) // { // depTemp = listDep.FirstOrDefault(e => e.ID == item.Nav_User.DEPARTMENT_ID.Value); // if (depTemp != null) // { // item.Nav_User.Nav_Department = depTemp; // } // } // #endregion // //pageFilter.Include.Remove("Nav_OccDiseaseList.Nav_OccDisease"); // //pageFilter.Include.Remove("Nav_OccDiseaseList.Nav_OccDiseaseSeverity"); // //pageFilter.Include.Remove("Nav_OccDiseaseList.Nav_Files.Nav_ImgFile.Nav_File"); // if (item.Nav_OccDiseaseList != null && item.Nav_OccDiseaseList.Any()) // { // foreach (var itemOcc in item.Nav_OccDiseaseList) // { // if (itemOcc.OCC_DISEASE_SEVERITY_ID.HasValue) // { // levelTemp = listDiseaseSeverityLevel.FirstOrDefault(e => e.ID == itemOcc.OCC_DISEASE_SEVERITY_ID.Value); // if (levelTemp != null) // { // itemOcc.Nav_OccDiseaseSeverity = levelTemp; // } // } // if (itemOcc.OCC_DISEASE_ID.HasValue) // { // diseaseTemp = listDisease.FirstOrDefault(e => e.ID == itemOcc.OCC_DISEASE_ID.Value); // if (diseaseTemp != null) // { // itemOcc.Nav_OccDisease = diseaseTemp; // } // } // } // } // } //} //result.TotalCount = orderPageEntities.TotalCount; #endregion }); } } /// /// 员工健康监护档案 /// public class HealthResult { public Guid ID { get; set; } public Guid? ORG_ID { get; set; } public string CODE { get; set; } public Guid? USER_ID { get; set; } public OHHealthExamResult RESULT_ENUM { get; set; } public string DESCRIPTION { get; set; } public string SUGGESTION { get; set; } public DateTime? CREATE_TIME { get; set; } public string NAME { get; set; } public string ID_CARD { get; set; } public DateTime? ENTRYTIME { get; set; } public Guid? DEPARTMENT_ID { get; set; } public string DEPARTMENTNAME { get; set; } public string POSTNAME { get; set; } public Guid? PERSON_ID { get; set; } public DateTime? DEPARTURETIME { get; set; } public Guid? OCC_DISEASE_SEVERITY_ID { get; set; } public Guid? OCC_DISEASE_ID { get; set; } public string disName { get; set; } public string disLevelName { get; set; } public string DIAGNOSE_AGENCY { get; set; } public string DisDESCRIPTION { get; set; } public string DIAGNOSE_METHOD { get; set; } public string OCC_HISTORY { get; set; } public ICollection Nav_Files { get; set; } } }