diff --git a/APT.MS.Domain/Enums/BS/BSEnums.cs b/APT.MS.Domain/Enums/BS/BSEnums.cs index 13296aa..12b1db7 100644 --- a/APT.MS.Domain/Enums/BS/BSEnums.cs +++ b/APT.MS.Domain/Enums/BS/BSEnums.cs @@ -564,9 +564,9 @@ namespace APT.MS.Domain.Enums Empty = 15, // - /// 与问题描述一致 20 + /// 不符合规定 20 /// - [Description("检查与问题描述一致")] + [Description("不符合规定")] Same = 20, // diff --git a/APT.MicroApi/APT.BS.WebApi/Controllers/Api/BSSafeCheckController.cs b/APT.MicroApi/APT.BS.WebApi/Controllers/Api/BSSafeCheckController.cs index af2271e..398750f 100644 --- a/APT.MicroApi/APT.BS.WebApi/Controllers/Api/BSSafeCheckController.cs +++ b/APT.MicroApi/APT.BS.WebApi/Controllers/Api/BSSafeCheckController.cs @@ -15,8 +15,11 @@ using APT.MS.Domain.Enums; using APT.Utility; using APT.WebApi.Models; using Microsoft.AspNetCore.Mvc; +using NPOI.SS.UserModel; +using NPOI.XSSF.UserModel; using System; using System.Collections.Generic; +using System.IO; using System.Linq; using System.Linq.Expressions; using System.Reflection; @@ -415,7 +418,7 @@ namespace APT.BS.WebApi.Controllers.Api //此人 此单 前面 2 天 检查信息都一样 人员也一样 自动加载检查人员 - if (safecheck.PLAN_SET_ID.HasValue && safecheck.DEPARTMENTID.HasValue) + if (safecheck.PLAN_SET_ID.HasValue && safecheck.DEPARTMENTID.HasValue && safecheck.Nav_ListSafeCheckDetail != null && safecheck.Nav_ListSafeCheckDetail.Any()) { BasePageFilter basePageFilter = new BasePageFilter(1, 2); basePageFilter.IgnoreDataRule = true; @@ -8780,6 +8783,485 @@ namespace APT.BS.WebApi.Controllers.Api return true; }); } + + + /// + /// 获取导出检查记录导出数据 + /// + /// + /// + [HttpPost, Route("GetOutPutDataLM")] + public JsonActionResult GetOutPutDataLM([FromBody] KeywordFilter Search) + { + return SafeExecute(() => + { + DateTime dtStart = DateTime.Now; + DateTime dtEnd = DateTime.Now; + string fileName = dtStart.ToString("yyyyMMddHHmmss") + "_" + APT.Infrastructure.Api.AppContext.CurrentSession.UserName + "_" + new Random().Next(100, 999) + ".xlsx"; + + #region 数据搜索 + List listIDs = new List(); + + if (string.IsNullOrEmpty(Search.Keyword)) + { + throw new Exception("请选择导出数据!"); + } + + try + { + var listCheckID = Search.Keyword.Split(',', StringSplitOptions.RemoveEmptyEntries); + if (listCheckID != null && listCheckID.Any()) + { + foreach (var item in listCheckID) + { + if (!string.IsNullOrEmpty(item)) + { + listIDs.Add(new Guid(item)); + } + } + } + } + catch { } + + if (listIDs == null || !listIDs.Any()) + { + throw new Exception("请选择导出数据!"); + } + //组织 安全检查记录 时间 + Expression> expressionCheck = e => e.ENABLE_STATUS == 0 && !e.IS_DELETED && listIDs.Contains(e.ID) && e.DEPARTMENTID.HasValue && e.STATECHECK == STATECHECK.Archived; + + var listSafeCheck = GetEntities(expressionCheck, null, "Nav_ListSafeCheckDetail"); + if (listSafeCheck == null || !listSafeCheck.Any()) + { + throw new Exception("未获取到导出数据(特别提示:未归档的数据不能导出)!"); + } + + var listDetailQ = GetEntities(e => listIDs.Contains(e.SAFE_CHECK_ID), null, "Nav_Question"); + T_BS_SAFE_CHECK_DETAIL_QUESTION modelDelQ = null; + + #endregion + + #region 样式 全局 + + IWorkbook workbook = new XSSFWorkbook(); + ISheet sheet = workbook.CreateSheet("检查记录"); + sheet.DefaultRowHeight = 330; + + //表头样式 + ICellStyle cellStyleHead = workbook.CreateCellStyle(); + // 设置字体 + IFont fontHead = workbook.CreateFont(); + fontHead.FontName = "Arial"; + fontHead.FontHeightInPoints = 20; + fontHead.Boldweight = (short)FontBoldWeight.Bold; + cellStyleHead.SetFont(fontHead); + + // 设置对齐方式 + cellStyleHead.Alignment = HorizontalAlignment.Center; + cellStyleHead.VerticalAlignment = VerticalAlignment.Center; + + ICellStyle cellStyleTop = workbook.CreateCellStyle(); + cellStyleTop.BorderBottom = BorderStyle.Thin; + cellStyleTop.BorderLeft = BorderStyle.Thin; + cellStyleTop.BorderRight = BorderStyle.Thin; + cellStyleTop.BorderTop = BorderStyle.Thin; + cellStyleTop.WrapText = true; + cellStyleTop.VerticalAlignment = VerticalAlignment.Top; + + + ICellStyle cellStyle = workbook.CreateCellStyle(); + // 设置字体 + IFont font = workbook.CreateFont(); + font.FontName = "Arial"; + font.FontHeightInPoints = 11; + //font.Boldweight = (short)FontBoldWeight.Bold; + cellStyle.SetFont(font); + + // 设置边框 + cellStyle.BorderBottom = BorderStyle.Thin; + cellStyle.BorderLeft = BorderStyle.Thin; + cellStyle.BorderRight = BorderStyle.Thin; + cellStyle.BorderTop = BorderStyle.Thin; + cellStyle.WrapText = true; + + //cellStyle.BottomBorderColor = HSSFColor.Black.Index; + //cellStyle.LeftBorderColor = HSSFColor.Black.Index; + //cellStyle.RightBorderColor = HSSFColor.Black.Index; + //cellStyle.TopBorderColor = HSSFColor.Black.Index; + + //// 设置背景色 + //cellStyle.FillForegroundColor = IndexedColors.LightYellow.Index; + //cellStyle.FillPattern = FillPattern.SolidForeground; + + // 设置对齐方式 + cellStyle.Alignment = HorizontalAlignment.Center; + cellStyle.VerticalAlignment = VerticalAlignment.Center; + + + ICellStyle cellStyleTitle = workbook.CreateCellStyle(); + // 设置字体 + IFont fontB = workbook.CreateFont(); + fontB.FontName = "Arial"; + fontB.FontHeightInPoints = 11; + fontB.Boldweight = (short)FontBoldWeight.Bold; + cellStyleTitle.SetFont(fontB); + + // 设置边框 + cellStyleTitle.BorderBottom = BorderStyle.Thin; + cellStyleTitle.BorderLeft = BorderStyle.Thin; + cellStyleTitle.BorderRight = BorderStyle.Thin; + cellStyleTitle.BorderTop = BorderStyle.Thin; + cellStyleTitle.WrapText = true; + + //cellStyle.BottomBorderColor = HSSFColor.Black.Index; + //cellStyle.LeftBorderColor = HSSFColor.Black.Index; + //cellStyle.RightBorderColor = HSSFColor.Black.Index; + //cellStyle.TopBorderColor = HSSFColor.Black.Index; + + //// 设置背景色 + //cellStyle.FillForegroundColor = IndexedColors.LightYellow.Index; + //cellStyle.FillPattern = FillPattern.SolidForeground; + + // 设置对齐方式 + cellStyleTitle.Alignment = HorizontalAlignment.Center; + cellStyleTitle.VerticalAlignment = VerticalAlignment.Center; + + + + + + //检查内容样式 + ICellStyle cellStyleLeft = workbook.CreateCellStyle(); + // 设置字体 + IFont fontLeft = workbook.CreateFont(); + fontLeft.FontName = "Arial"; + fontLeft.FontHeightInPoints = 11; + fontLeft.Boldweight = (short)FontBoldWeight.Bold; + cellStyleLeft.SetFont(fontLeft); + + // 设置边框 + cellStyleLeft.BorderBottom = BorderStyle.Thin; + cellStyleLeft.BorderLeft = BorderStyle.Thin; + cellStyleLeft.BorderRight = BorderStyle.Thin; + cellStyleLeft.BorderTop = BorderStyle.Thin; + + cellStyleLeft.WrapText = true; + //// 设置背景色 + //cellStyle.FillForegroundColor = IndexedColors.LightYellow.Index; + //cellStyle.FillPattern = FillPattern.SolidForeground; + + // 设置对齐方式 + cellStyleLeft.Alignment = HorizontalAlignment.Left; + cellStyleLeft.VerticalAlignment = VerticalAlignment.Center; + + + + + ////检查内容样式 + //ICellStyle cellStyleRotation = workbook.CreateCellStyle(); + + //// 设置边框 + //cellStyleRotation.BorderBottom = BorderStyle.Thin; + //cellStyleRotation.BorderLeft = BorderStyle.Thin; + //cellStyleRotation.BorderRight = BorderStyle.Thin; + //cellStyleRotation.BorderTop = BorderStyle.Thin; + + ////cellStyleRotation.WrapText = true; + ////// 设置背景色 + ////cellStyle.FillForegroundColor = IndexedColors.LightYellow.Index; + ////cellStyle.FillPattern = FillPattern.SolidForeground; + + //// 设置对齐方式 + //cellStyleRotation.Alignment = HorizontalAlignment.Left; + //cellStyleRotation.VerticalAlignment = VerticalAlignment.Center; + + //cellStyleRotation.SetRotation((short)90); + + #endregion + + #region 填充数据 处理 与 填充 + + int rowIndex = 0; + int colCount = 4 - 1;// 序号 检查内容 检查意见 备注 + sheet.SetColumnWidth(0, 9 * 256); + sheet.SetColumnWidth(1, 50 * 256); + sheet.SetColumnWidth(2, 15 * 256); + sheet.SetColumnWidth(3, 18 * 256); + sheet.DefaultRowHeight = 330; + var listCheckArea = GetEntities(e => listIDs.Contains(e.SAFE_CHECK_ID), null, null).ToList(); + if (listCheckArea == null || !listCheckArea.Any()) + { + throw new Exception("未获取到检查区域数据!"); + } + var listAreaIDAll = listCheckArea.Select(e => e.RISK_AREA_ID).Distinct(); + var listArea = GetEntities(e => listAreaIDAll.Contains(e.ID), null, null); + T_HM_RISK_AREA area = null; + + ICollection listCheckDetail = null; + int RowNO_Content = 1; + string Remark = ""; + // 检查单 按区域 拆分导出 + //检查人员 获取 + + var listDetailUser = GetEntities(e => listIDs.Contains(e.SAFE_CHECK_ID), null, null).OrderByDescending(e=>e.ISMAINCHECK); + var listUserID = listDetailUser.Select(e => e.USER_ID).Distinct().ToList(); + var listUser = GetEntities(e => listUserID.Contains(e.ID), null, null); + + List listDetailID = null; + List listUserIDArea = null; + List listUserArea = null; + string UserNameShow = ""; + foreach (var item in listSafeCheck) + { + var listAreaID = item.Nav_ListSafeCheckDetail.Where(e => e.RISK_AREA_ID.HasValue).Select(e => e.RISK_AREA_ID.Value).Distinct(); + foreach (var itemAID in listAreaID) + { + listCheckDetail = item.Nav_ListSafeCheckDetail.Where(e => e.RISK_AREA_ID.Value == itemAID).OrderBy(e => e.ROW_NO).ToList(); + listDetailID = listCheckDetail.Select(e => e.ID).ToList(); + + #region 表头 1行 + + IRow row = sheet.CreateRow(rowIndex); + sheet.AddMergedRegion(new NPOI.SS.Util.CellRangeAddress(rowIndex, rowIndex, 0, colCount)); + ICell cell = row.CreateCell(0); // 在合并区域的左上角单元格写入数据 + + row.Height = 800; + cell.SetCellValue(item.NAME); + cell.CellStyle = cellStyleHead; + + #endregion + + #region 第2行 检查区域 检查时间 + + rowIndex++; + + IRow row2 = sheet.CreateRow(rowIndex); + ICell cell10 = row2.CreateCell(0); + cell10.SetCellValue("检查区域"); + + area = listArea.FirstOrDefault(e => e.ID == itemAID); + ICell cell11 = row2.CreateCell(1); + cell11.SetCellValue(area == null ? "" : area.NAME); + + ICell cell12 = row2.CreateCell(2); + cell12.SetCellValue("检查时间"); + + ICell cell13 = row2.CreateCell(3); + cell13.SetCellValue(item.CHECKTIME.Value.ToString("yyyy-MM-dd HH:mm")); + + #endregion + + #region 第3行 文本说明 + + rowIndex++; + sheet.AddMergedRegion(new NPOI.SS.Util.CellRangeAddress(rowIndex, rowIndex, 0, colCount)); + IRow row3 = sheet.CreateRow(rowIndex); + row3.Height = (short)(sheet.DefaultRowHeight * 4); + ICell cell30 = row3.CreateCell(0); + cell30.CellStyle = cellStyleTop; + cell30.SetCellValue("说明:1、主要负责人应在组织各分管副矿长和各专业技术人员在现场检查的基础上如实填写检查意见;\r\n2、检查结束后,检查人员应在检查意见一栏中填写“符合规定”或“不符合规定”,对不符合规定的,须在“备注”栏目简要写明理由并汇总;\r\n3、 每个检查项目至少2名人员参加并签字;主要负责人应对检查情况进行汇总确认并加盖骑缝公章;"); + + for (int i = 1; i < 4; i++) + { + ICell cell3iE = row3.CreateCell(i); + cell3iE.CellStyle = cellStyle; + } + + #endregion + + #region 第4行 表头: 序号 检查内容 检查意见 备注 + + rowIndex++; + IRow row4 = sheet.CreateRow(rowIndex); + + ICell cell40 = row4.CreateCell(0); + cell40.CellStyle = cellStyleTitle; + cell40.SetCellValue("序号"); + + ICell cell41 = row4.CreateCell(1); + cell41.CellStyle = cellStyleTitle; + cell41.SetCellValue("检查内容"); + + ICell cell42 = row4.CreateCell(2); + cell42.CellStyle = cellStyleTitle; + cell42.SetCellValue("检查意见"); + + ICell cell43 = row4.CreateCell(3); + cell43.CellStyle = cellStyleTitle; + cell43.SetCellValue("备注"); + + #endregion + + #region 第5组 循环加载加 检查内容 + + + RowNO_Content = 1; + foreach (var itemDetail in listCheckDetail) + { + rowIndex++; + IRow row5 = sheet.CreateRow(rowIndex); + + ICell cell50 = row5.CreateCell(0); + cell50.CellStyle = cellStyle; + cell50.SetCellValue(RowNO_Content); + + ICell cell51 = row5.CreateCell(1); + cell51.CellStyle = cellStyle; + cell51.SetCellValue(itemDetail.CHECKCONTENT); + + ICell cell52 = row5.CreateCell(2); + cell52.CellStyle = cellStyle; + Remark = ""; + if (itemDetail.CHECKRESULT.HasValue) + { + try + { + // 符合要求 10 缺项 15 不符合规定 20 其它 30 + cell52.SetCellValue(((CHECKRESULTEnum)(itemDetail.CHECKRESULT.Value)).GetDescription()); + + //Remark = ""; + modelDelQ = listDetailQ.First(e => e.SAFE_CHECK_DETAIL_ID == itemDetail.ID); + if (modelDelQ != null && modelDelQ.Nav_Question != null) + { + Remark = modelDelQ.Nav_Question.DESCREPTION; + } + } + catch { } + } + else + { + cell52.SetCellValue(""); + } + + ICell cell53 = row5.CreateCell(3); + cell53.CellStyle = cellStyle; + cell53.SetCellValue(Remark); + + RowNO_Content++; + } + + #endregion + + #region 第6行 汇总 + + rowIndex++; + IRow row6 = sheet.CreateRow(rowIndex); + row6.Height = (short)(sheet.DefaultRowHeight * 5); + sheet.AddMergedRegion(new NPOI.SS.Util.CellRangeAddress(rowIndex, rowIndex, 0, colCount)); + ICell cell60 = row6.CreateCell(0); // 在合并区域的左上角单元格写入数据 + cell60.SetCellValue("本次检查共发现重大隐患____项,还发现一般问题____项,具体情况如下:"); + cell60.CellStyle = cellStyleTop; + + + ICell cell63E = row6.CreateCell(3); + cell63E.CellStyle = cellStyle; + + #endregion + + #region 第7行 整改意见 + + rowIndex++; + IRow row7 = sheet.CreateRow(rowIndex); + row7.Height = (short)(sheet.DefaultRowHeight * 5); + sheet.AddMergedRegion(new NPOI.SS.Util.CellRangeAddress(rowIndex, rowIndex, 1, colCount)); + + ICell cell70 = row7.CreateCell(0); // 在合并区域的左上角单元格写入数据 + cell70.CellStyle = cellStyle; + cell70.SetCellValue("整改意见"); + + for (int i = 1; i < 4; i++) + { + ICell cell7iE = row7.CreateCell(i); + cell7iE.CellStyle = cellStyle; + } + + #endregion + + #region 第8行 检查人员签字 图片不好做合并显示 + + rowIndex++; + IRow row8 = sheet.CreateRow(rowIndex); + row8.Height = 1000; + ICell cell80 = row8.CreateCell(0); // 在合并区域的左上角单元格写入数据 + cell80.CellStyle = cellStyle; + cell80.SetCellValue("检查人员签字"); + sheet.AddMergedRegion(new NPOI.SS.Util.CellRangeAddress(rowIndex, rowIndex, 1, colCount)); + + #region 检查人员姓名处理 + + listUserIDArea = listDetailUser.Where(e => listDetailID.Contains(e.SAFE_CHECK_DETAIL_ID)).Select(e => e.USER_ID).Distinct().ToList(); + listUserArea = listUser.Where(e => listUserIDArea.Contains(e.ID)).ToList(); + UserNameShow = ""; + for (int i = 0; i < listUserArea.Count; i++) + { + UserNameShow += listUserArea[i].NAME + "、"; + } + if (!string.IsNullOrEmpty(UserNameShow)) + { + UserNameShow = UserNameShow.Substring(0, UserNameShow.Length - 1); + } + for (int i = 1; i < 4; i++) + { + ICell cell8iE = row8.CreateCell(i); + cell8iE.CellStyle = cellStyle; + if (i == 1) + { + cell8iE.SetCellValue(UserNameShow); + } + } + #endregion + + #endregion + + rowIndex += 5; + + } + } + + #endregion + + #region 表格数据填充 + + var fileP = ConfigurationManager.AppSettings["Img_Local"]; + var fileNameP = ConfigurationManager.AppSettings["File_DownLoad"]; + + var fullFilePart = $"{fileP}{fileNameP}"; + var fullFilePath = $"{fileP}{fileNameP}{fileName}"; + + //如果没有文件夹 创建 + //如果文件夹下有超过10个文件 按时间 删除多余的 + if (!Directory.Exists(fullFilePart)) + { + Directory.CreateDirectory(fullFilePart); + } + else + { + FileInfo[] files = new DirectoryInfo(fullFilePart).GetFiles(); + if (files.Length > 10) + { + var listFilesOrder = files.OrderBy(e => e.CreationTime).ToList(); + for (int i = 0; i < files.Length - 10; i++) + { + listFilesOrder[i].Delete(); + } + } + } + + // 写入到文件 + using (FileStream file = new FileStream(fullFilePath, FileMode.Create, FileAccess.Write)) + { + workbook.Write(file); + } + + // 关闭工作簿资源 + workbook.Close(); + + #endregion + + return $"{fileNameP}{fileName}"; ; + + }); + } } /// diff --git a/APT.MicroApi/APT.BS.WebApi/appsettings.Production.json b/APT.MicroApi/APT.BS.WebApi/appsettings.Production.json index 69a6e62..27f9a15 100644 --- a/APT.MicroApi/APT.BS.WebApi/appsettings.Production.json +++ b/APT.MicroApi/APT.BS.WebApi/appsettings.Production.json @@ -21,8 +21,8 @@ "AllConnApiUrl": "http://172.26.13.0:3116/api/OP/TenantInfo/GetAllDbConn", "ConnDataKey": "MHKSAQ1212010101", "TenantConnKey": "MHSMS", - "Img_Local": "C:\\release\\img\\", - "File_DownLoad": "downLoad\\" + "Img_Local": "C:\\sms\\uploadFile\\", + "File_DownLoad": "downLoad\\" }, "RedisConfig": { "RedisConnectionString": "172.26.13.0:6379,password=mhsaferedis,defaultDatabase=15", diff --git a/APT.MicroApi/APT.BS.WebApi/appsettings.Test.json b/APT.MicroApi/APT.BS.WebApi/appsettings.Test.json index 217e130..c304687 100644 --- a/APT.MicroApi/APT.BS.WebApi/appsettings.Test.json +++ b/APT.MicroApi/APT.BS.WebApi/appsettings.Test.json @@ -15,7 +15,7 @@ "AllConnApiUrl": "http://localhost:3116/api/OP/TenantInfo/GetAllDbConn", "ConnDataKey": "MHKSAQ1212010101", "TenantConnKey": "MHSMS", - "Img_Local": "C:\\release\\img\\", + "Img_Local": "D:\\uploadFile\\", "File_DownLoad": "downLoad\\" }, "RedisConfig": {