diff --git a/Frontend/_historyData.html b/Frontend/_historyData.html index 9e6f02c..6734e0e 100644 --- a/Frontend/_historyData.html +++ b/Frontend/_historyData.html @@ -1,13 +1,13 @@
-
+
- +
-
@@ -18,15 +18,15 @@
- - - + + +
- - + +
@@ -49,13 +49,13 @@
-
+
-
+
@@ -84,7 +84,8 @@ initApp.buildNavigation($('#js_nested_list')); loadTable(null); - $(`[onclick="setDateType('today')"]`).click(); + $(`[onclick="setDateType('day', this)"]`).click(); + $(`[onclick="setDateType('today', this)"]`).click(); }); function initList() { @@ -101,7 +102,7 @@ $.each(res.data.history_Main_Systems, function (index, val) { if (pageAct.mainStatus) { strHtml += `
  • - + ${val.full_name}
  • diff --git a/Frontend/js/style.js b/Frontend/js/style.js index 013724d..586bdbc 100644 --- a/Frontend/js/style.js +++ b/Frontend/js/style.js @@ -1561,4 +1561,14 @@ YT.Loading = function (type, ele = null, text = null, delay = 0) { $(".yt-page-loading").fadeOut(); $(ele.ele).YTAlert().hide(delay); } +} + +//change css of clicked button +function btnSelCss(elem) { + $.each($(elem).parent().find('button'), function (i, v) { + $(v).removeClass('btn-dark'); + $(v).addClass('btn-secondary'); + }); + $(elem).removeClass('btn-secondary'); + $(elem).addClass('btn-dark'); } \ No newline at end of file diff --git a/FrontendWebApi/ApiControllers/HistoryController.cs b/FrontendWebApi/ApiControllers/HistoryController.cs index ee5d6a7..48d7b87 100644 --- a/FrontendWebApi/ApiControllers/HistoryController.cs +++ b/FrontendWebApi/ApiControllers/HistoryController.cs @@ -56,7 +56,7 @@ namespace FrontendWebApi.ApiControllers try { var fileDateName = lhe.FirstOrDefault().dateType == "month" ? lhe.FirstOrDefault().starttime.ToString("yyyy-MM") : lhe.FirstOrDefault().endtime == null ? lhe.FirstOrDefault().starttime.ToString("yyyy-MM-dd") : lhe.FirstOrDefault().starttime.ToString("yyyy-MM-dd") + "_" + ((DateTime)lhe.FirstOrDefault().endtime).ToString("yyyy-MM-dd"); - var fileName = "廠商資料_"+fileDateName+".xlsx"; + var fileName = "歷史資料_"+fileDateName+".xlsx"; var filePath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "excel", "history"); if (!System.IO.Directory.Exists(filePath)) @@ -136,13 +136,17 @@ namespace FrontendWebApi.ApiControllers cell = row.CreateCell(i); if (i == 0) { - cell.SetCellValue(he.deviceName); + cell.SetCellValue(he.type); } if (i == 1) { - cell.SetCellValue(he.value); + cell.SetCellValue(he.deviceName); } if (i == 2) + { + cell.SetCellValue(he.value); + } + if (i == 3) { cell.SetCellValue(he.timestamp.ToString("yyyy-MM-dd HH:mm") + ":00");// } diff --git a/FrontendWebApi/ApiControllers/OperationController.cs b/FrontendWebApi/ApiControllers/OperationController.cs index a0dc12c..38732c7 100644 --- a/FrontendWebApi/ApiControllers/OperationController.cs +++ b/FrontendWebApi/ApiControllers/OperationController.cs @@ -68,7 +68,7 @@ namespace FrontendWebApi.ApiControllers } [HttpPost] - public async Task>> SubSysList([FromBody] string main_system_tag) + public async Task>> SubSysList([FromBody] Find_Sub_List fsl) { ApiResult> apiResult = new ApiResult>(); List sub_system_list = new List(); @@ -78,10 +78,10 @@ namespace FrontendWebApi.ApiControllers var sqlString = @$"SELECT v2.* FROM variable v2 JOIN variable v1 ON v2.system_parent_id = v1.id AND v1.system_type = @main_system_type AND v1.deleted = 0 - WHERE v2.system_type = @sub_system_type AND v2.deleted = 0 AND v1.system_value = @main_system_tag + WHERE v2.system_type = @sub_system_type AND v2.deleted = 0 AND v1.system_value in @main_system_tag ORDER BY v2.system_priority, v2.created_at desc"; - var param = new { @main_system_type = main_system_type, @sub_system_type = sub_system_type, @main_system_tag = main_system_tag }; + var param = new { @main_system_type = main_system_type, @sub_system_type = sub_system_type, @main_system_tag = fsl.main_system_tag }; sub_system_list = await backendRepository.GetAllAsync(sqlString, param); apiResult.Code = "0000"; @@ -227,498 +227,523 @@ namespace FrontendWebApi.ApiControllers /// 汇出excel (work_type: null=廠商, 1=保養, 2=維修) /// /// - public FileResult OpeExportExcel([FromQuery] byte? work_type) + [HttpPost] + public ActionResult> OpeExportExcel([FromBody] ExportExcel ee) { - var j = 1;//row - var workbook = new XSSFWorkbook(); - #region excel設定 - IFont font12 = workbook.CreateFont(); - font12.FontName = "新細明體"; - font12.FontHeightInPoints = 12; - ICellStyle style12 = workbook.CreateCellStyle(); - style12.SetFont(font12); - style12.Alignment = HorizontalAlignment.Center; - style12.VerticalAlignment = VerticalAlignment.Center; - IFont font12Times = workbook.CreateFont(); - font12Times.FontName = "Times New Roman"; - font12Times.FontHeightInPoints = 12; - IFont font18 = workbook.CreateFont(); - font18.FontName = "新細明體"; - font18.FontHeightInPoints = 18; - font18.IsBold = true; - ICellStyle styleTitle18 = workbook.CreateCellStyle(); - styleTitle18.SetFont(font18); - styleTitle18.Alignment = HorizontalAlignment.Center; - styleTitle18.VerticalAlignment = VerticalAlignment.Center; - ICellStyle styleLeft12 = workbook.CreateCellStyle(); - styleLeft12.SetFont(font12); - styleLeft12.Alignment = HorizontalAlignment.Left; - styleLeft12.VerticalAlignment = VerticalAlignment.Center; - ICellStyle styleLine12 = workbook.CreateCellStyle(); - styleLine12.SetFont(font12); - styleLine12.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Center; - styleLine12.VerticalAlignment = VerticalAlignment.Center; - styleLine12.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin; - styleLine12.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin; - styleLine12.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin; - styleLine12.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin; - ICellStyle stylein12 = workbook.CreateCellStyle(); - stylein12.SetFont(font12Times); - stylein12.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Left; - stylein12.VerticalAlignment = VerticalAlignment.Center; - stylein12.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin; - stylein12.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin; - stylein12.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin; - stylein12.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin; - stylein12.WrapText = true; - #endregion - - if (string.IsNullOrEmpty(work_type.ToString())) + ApiResult apiResult = new ApiResult(); + if (ee.work_type > 2 || ee.work_type < 1) { - var sqlString = $@"select ofi.*, v2.system_key - from operation_firm ofi - left join variable v1 on ofi.device_system_category_layer2 = v1.system_value and v1.system_type = @main_system_type and v1.deleted = 0 - left join variable v2 on v1.id = v2.system_parent_id and ofi.device_system_category_layer3 = v2.system_value and v2.system_type = @sub_system_type and v2.deleted = 0 - where ofi.deleted = 0"; - var sheet = workbook.CreateSheet("廠商資料"); - var operation_firm = backendRepository.GetAllAsync(sqlString, new { @main_system_type = main_system_type, @sub_system_type = sub_system_type }); - int RowPosition = 0; - #region set cell - IRow row = sheet.CreateRow(RowPosition); - sheet.SetColumnWidth(0, 4 * 160 * 12); - sheet.SetColumnWidth(1, 4 * 160 * 12); - sheet.SetColumnWidth(2, 4 * 160 * 12); - sheet.SetColumnWidth(3, 4 * 160 * 12); - sheet.SetColumnWidth(4, 4 * 160 * 12); - sheet.SetColumnWidth(5, 4 * 160 * 12); - sheet.SetColumnWidth(6, 4 * 160 * 12); - sheet.SetColumnWidth(7, 4 * 160 * 12); - ICell cell = row.CreateCell(0); - cell.SetCellValue("廠商類別"); - cell.CellStyle = styleLine12; - cell = row.CreateCell(1); - cell.SetCellValue("廠商名稱"); - cell.CellStyle = styleLine12; - cell = row.CreateCell(2); - cell.SetCellValue("聯絡人"); - cell.CellStyle = styleLine12; - cell = row.CreateCell(3); - cell.SetCellValue("電話"); - cell.CellStyle = styleLine12; - cell = row.CreateCell(4); - cell.SetCellValue("郵箱"); - cell.CellStyle = styleLine12; - cell = row.CreateCell(5); - cell.SetCellValue("統一編號"); - cell.CellStyle = styleLine12; - cell = row.CreateCell(6); - cell.SetCellValue("備注"); - cell.CellStyle = styleLine12; - cell = row.CreateCell(7); - cell.SetCellValue("建立時間"); - cell.CellStyle = styleLine12; - #endregion - - if (operation_firm.Result.Count > 0) - { - foreach (var of in operation_firm.Result) - { - RowPosition += 1; - row = sheet.CreateRow(RowPosition); - for (var i = 0; i < 8; i++) - { - cell = row.CreateCell(i); - if (i == 0) - { - cell.SetCellValue(of.system_key); - } - if (i == 1) - { - cell.SetCellValue(of.name); - } - if (i == 2) - { - cell.SetCellValue(of.contact_person); - } - if (i == 3) - { - cell.SetCellValue(of.phone); - } - if (i == 4) - { - cell.SetCellValue(of.email); - } - if (i == 5) - { - cell.SetCellValue(of.tax_id_number); - } - if (i == 6) - { - cell.SetCellValue(of.remark); - } - if (i == 7) - { - cell.SetCellValue(of.Created_at); - } - - cell.CellStyle = style12; - } - } - } + apiResult.Code = "0001"; + apiResult.Msg = "沒有資料匯入"; + return apiResult; } - else if (work_type == 1) + + var fileDateName = ee.startdate == null ? "" : ee.enddate == null ? "_" + ((DateTime)ee.startdate).ToString("yyyy-MM-dd") : "_" + ((DateTime)ee.startdate).ToString("yyyy-MM-dd") + "_" + ((DateTime)ee.enddate).ToString("yyyy-MM-dd"); + var fileName = (ee.work_type == null ? "廠商資料" : ee.work_type == 1 ? "保養記錄" : ee.work_type == 2 ? "維修" : null) + fileDateName + ".xlsx"; + var filePath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "excel", "operation"); + + if (!System.IO.Directory.Exists(filePath)) + System.IO.Directory.CreateDirectory(filePath); + try { - var sqlString = $@"select opr.*, concat(d.device_floor_tag, ' ', d.device_last_name, ' ', d.device_serial_tag) as device_name, ui.full_name as user_full_name - from operation_record opr - left join device d on opr.fix_do_code = d.device_number and d.deleted = 0 and d.device_area_tag = SUBSTRING_INDEX(opr.fix_do_code, '_', 1) - and d.device_building_tag = SUBSTRING_INDEX(opr.fix_do_code, '_', 2) and d.device_floor_tag = SUBSTRING_INDEX(opr.fix_do_code, '_', 5) - and d.device_system_tag = opr.device_system_category_layer2 and d.device_name_tag = opr.device_system_category_layer3 - left join userinfo ui on opr.work_person_id = ui.userinfo_guid - where opr.deleted = 0 and opr.work_type = 1;"; - var sheet = workbook.CreateSheet("廠商資料"); - var operation_record = backendRepository.GetAllAsync(sqlString, null); - List operation_record_file = new List(); - - if (operation_record.Result.Count > 0) + using (var fs = new FileStream(Path.Combine(filePath, fileName), FileMode.Create, FileAccess.Write)) { - foreach (var or in operation_record.Result) - { - sqlString = $@"select * from operation_record_file where record_id = @record_id"; - var param = new { @record_id = or.id }; - operation_record_file = backendRepository.GetAllAsync(sqlString, param).Result; - or.lorf = operation_record_file; - } - - int RowPosition = 0; - #region set cell - IRow row = sheet.CreateRow(RowPosition); - sheet.SetColumnWidth(0, 4 * 160 * 12); - sheet.SetColumnWidth(1, 4 * 160 * 12); - sheet.SetColumnWidth(2, 4 * 160 * 12); - sheet.SetColumnWidth(3, 4 * 160 * 12); - sheet.SetColumnWidth(4, 4 * 160 * 12); - sheet.SetColumnWidth(5, 4 * 160 * 12); - sheet.SetColumnWidth(6, 4 * 160 * 12); - sheet.SetColumnWidth(7, 4 * 160 * 12); - sheet.SetColumnWidth(8, 4 * 160 * 12); - sheet.SetColumnWidth(9, 4 * 160 * 12); - ICell cell = row.CreateCell(0); - cell.SetCellValue("項目"); - cell.CellStyle = styleLine12; - cell = row.CreateCell(1); - cell.SetCellValue("位置"); - cell.CellStyle = styleLine12; - cell = row.CreateCell(2); - cell.SetCellValue("表單號"); - cell.CellStyle = styleLine12; - cell = row.CreateCell(3); - cell.SetCellValue("設備名稱"); - cell.CellStyle = styleLine12; - cell = row.CreateCell(4); - cell.SetCellValue("狀態"); - cell.CellStyle = styleLine12; - cell = row.CreateCell(5); - cell.SetCellValue("處理人員"); - cell.CellStyle = styleLine12; - cell = row.CreateCell(6); - cell.SetCellValue("預計施工時間"); - cell.CellStyle = styleLine12; - cell = row.CreateCell(7); - cell.SetCellValue("檔案上傳"); - cell.CellStyle = styleLine12; - cell = row.CreateCell(8); - cell.SetCellValue("完成時間"); - cell.CellStyle = styleLine12; - cell = row.CreateCell(9); - cell.SetCellValue("建立時間"); - cell.CellStyle = styleLine12; + var j = 1;//row + var workbook = new XSSFWorkbook(); + #region excel設定 + IFont font12 = workbook.CreateFont(); + font12.FontName = "新細明體"; + font12.FontHeightInPoints = 12; + ICellStyle style12 = workbook.CreateCellStyle(); + style12.SetFont(font12); + style12.Alignment = HorizontalAlignment.Center; + style12.VerticalAlignment = VerticalAlignment.Center; + IFont font12Times = workbook.CreateFont(); + font12Times.FontName = "Times New Roman"; + font12Times.FontHeightInPoints = 12; + IFont font18 = workbook.CreateFont(); + font18.FontName = "新細明體"; + font18.FontHeightInPoints = 18; + font18.IsBold = true; + ICellStyle styleTitle18 = workbook.CreateCellStyle(); + styleTitle18.SetFont(font18); + styleTitle18.Alignment = HorizontalAlignment.Center; + styleTitle18.VerticalAlignment = VerticalAlignment.Center; + ICellStyle styleLeft12 = workbook.CreateCellStyle(); + styleLeft12.SetFont(font12); + styleLeft12.Alignment = HorizontalAlignment.Left; + styleLeft12.VerticalAlignment = VerticalAlignment.Center; + ICellStyle styleLine12 = workbook.CreateCellStyle(); + styleLine12.SetFont(font12); + styleLine12.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Center; + styleLine12.VerticalAlignment = VerticalAlignment.Center; + styleLine12.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin; + styleLine12.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin; + styleLine12.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin; + styleLine12.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin; + ICellStyle stylein12 = workbook.CreateCellStyle(); + stylein12.SetFont(font12Times); + stylein12.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Left; + stylein12.VerticalAlignment = VerticalAlignment.Center; + stylein12.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin; + stylein12.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin; + stylein12.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin; + stylein12.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin; + stylein12.WrapText = true; #endregion - foreach (var or in operation_record.Result) + + if (string.IsNullOrEmpty(ee.work_type.ToString())) { - RowPosition += 1; - row = sheet.CreateRow(RowPosition); - for (var i = 0; i < 10; i++) + var sqlString = $@"select ofi.*, v2.system_key + from operation_firm ofi + left join variable v1 on ofi.device_system_category_layer2 = v1.system_value and v1.system_type = @main_system_type and v1.deleted = 0 + left join variable v2 on v1.id = v2.system_parent_id and ofi.device_system_category_layer3 = v2.system_value and v2.system_type = @sub_system_type and v2.deleted = 0 + where ofi.deleted = 0"; + var sheet = workbook.CreateSheet("廠商資料"); + var operation_firm = backendRepository.GetAllAsync(sqlString, new { @main_system_type = main_system_type, @sub_system_type = sub_system_type }); + int RowPosition = 0; + #region set cell + IRow row = sheet.CreateRow(RowPosition); + sheet.SetColumnWidth(0, 4 * 160 * 12); + sheet.SetColumnWidth(1, 4 * 160 * 12); + sheet.SetColumnWidth(2, 4 * 160 * 12); + sheet.SetColumnWidth(3, 4 * 160 * 12); + sheet.SetColumnWidth(4, 4 * 160 * 12); + sheet.SetColumnWidth(5, 4 * 160 * 12); + sheet.SetColumnWidth(6, 4 * 160 * 12); + sheet.SetColumnWidth(7, 4 * 160 * 12); + ICell cell = row.CreateCell(0); + cell.SetCellValue("廠商類別"); + cell.CellStyle = styleLine12; + cell = row.CreateCell(1); + cell.SetCellValue("廠商名稱"); + cell.CellStyle = styleLine12; + cell = row.CreateCell(2); + cell.SetCellValue("聯絡人"); + cell.CellStyle = styleLine12; + cell = row.CreateCell(3); + cell.SetCellValue("電話"); + cell.CellStyle = styleLine12; + cell = row.CreateCell(4); + cell.SetCellValue("郵箱"); + cell.CellStyle = styleLine12; + cell = row.CreateCell(5); + cell.SetCellValue("統一編號"); + cell.CellStyle = styleLine12; + cell = row.CreateCell(6); + cell.SetCellValue("備注"); + cell.CellStyle = styleLine12; + cell = row.CreateCell(7); + cell.SetCellValue("建立時間"); + cell.CellStyle = styleLine12; + #endregion + + if (operation_firm.Result.Count > 0) { - cell = row.CreateCell(i); - if (i == 0) + foreach (var of in operation_firm.Result) { - cell.SetCellValue(or.work_type_name); - } - if (i == 1) - { - cell.SetCellValue(or.location); - } - if (i == 2) - { - cell.SetCellValue(or.formId); - } - if (i == 3) - { - cell.SetCellValue(or.device_name); - } - if (i == 4) - { - cell.SetCellValue(or.status_name); - } - if (i == 5) - { - cell.SetCellValue(or.user_full_name); - } - if (i == 6) - { - cell.SetCellValue(or.start_time); - } - if (i == 7) - { - var imageNames = or.lorf.Count > 0 ? or.lorf.Select(x => x.save_file_name).ToList() : null; - if (imageNames != null) + RowPosition += 1; + row = sheet.CreateRow(RowPosition); + for (var i = 0; i < 8; i++) { - //insert image process - var dy1 = 10; - var dx1 = 10; - - //image column - sheet.SetColumnWidth(i, 16 * imageNames.Count * 256); //width: picture width(16:100), image total, per character(256) - foreach (var ins in imageNames) + cell = row.CreateCell(i); + if (i == 0) { - //image initial - var extName = ins.Split('.')[1].ToUpper().Equals("JPG") ? "PNG" : ins.Split('.')[1].ToUpper(); - var fullPath = Path.Combine(operationFileSaveAsPath, ins); - var img = Image.FromFile(fullPath); - - //compress image - decimal sizeRatio = ((decimal)img.Height / img.Width); - int thumbWidth = 100; - int thumbHeight = decimal.ToInt32(sizeRatio * thumbWidth); - var thumbStream = img.GetThumbnailImage(thumbWidth, thumbHeight, () => false, IntPtr.Zero); - var memoryStream = new MemoryStream(); - thumbStream.Save(memoryStream, ImageFormat.Jpeg); - - //setting pictureType enum - int format = 0; - var drawing = (XSSFDrawing)sheet.CreateDrawingPatriarch(); - format = Convert.ToInt32(Enum.Parse(typeof(PictureType), extName)); - - //set picture size and location - if (format != 0) - { - var pictureIds = workbook.AddPicture(memoryStream.ToArray(), format); - XSSFClientAnchor anchor = new XSSFClientAnchor(XSSFShape.EMU_PER_PIXEL * dx1, XSSFShape.EMU_PER_PIXEL * dy1, 0, 0, i, j, 0, 0); - anchor.AnchorType = AnchorType.DontMoveAndResize; - var picture = (XSSFPicture)drawing.CreatePicture(anchor, pictureIds); - var size = picture.GetImageDimension(); - row.HeightInPoints = size.Height; - picture.Resize(); - - //add 105 each new pic - dx1 += 105; - } + cell.SetCellValue(of.system_key); } + if (i == 1) + { + cell.SetCellValue(of.name); + } + if (i == 2) + { + cell.SetCellValue(of.contact_person); + } + if (i == 3) + { + cell.SetCellValue(of.phone); + } + if (i == 4) + { + cell.SetCellValue(of.email); + } + if (i == 5) + { + cell.SetCellValue(of.tax_id_number); + } + if (i == 6) + { + cell.SetCellValue(of.remark); + } + if (i == 7) + { + cell.SetCellValue(of.Created_at); + } + + cell.CellStyle = style12; } - - j++; } - if (i == 8) - { - cell.SetCellValue(or.finish_time); - } - if (i == 9) - { - cell.SetCellValue(or.Created_at); - } - - cell.CellStyle = style12; } } - } - } - else if (work_type == 2) - { - var sqlString = $@"select opr.*, concat(d.device_floor_tag, ' ', d.device_last_name, ' ', d.device_serial_tag) as device_name, ui.full_name as user_full_name - from operation_record opr - left join device d on opr.fix_do_code = d.device_number and d.deleted = 0 and d.device_area_tag = SUBSTRING_INDEX(opr.fix_do_code, '_', 1) - and d.device_building_tag = SUBSTRING_INDEX(opr.fix_do_code, '_', 2) and d.device_floor_tag = SUBSTRING_INDEX(opr.fix_do_code, '_', 5) - and d.device_system_tag = opr.device_system_category_layer2 and d.device_name_tag = opr.device_system_category_layer3 - left join userinfo ui on opr.work_person_id = ui.userinfo_guid - where opr.deleted = 0 and opr.work_type = 2"; - var sheet = workbook.CreateSheet("廠商資料"); - var operation_record = backendRepository.GetAllAsync(sqlString); - List operation_record_file = new List(); - - if (operation_record.Result.Count > 0) - { - foreach(var or in operation_record.Result) + else if (ee.work_type == 1) { - sqlString = $@"select * from operation_record_file where record_id = @record_id"; - var param = new { @record_id = or.id }; - operation_record_file = backendRepository.GetAllAsync(sqlString, param).Result; - or.lorf = operation_record_file; - } + var sqlString = $@"select opr.*, concat(d.device_floor_tag, ' ', d.device_last_name, ' ', d.device_serial_tag) as device_name, ui.full_name as user_full_name + from operation_record opr + left join device d on opr.fix_do_code = d.device_number and d.deleted = 0 and d.device_area_tag = SUBSTRING_INDEX(opr.fix_do_code, '_', 1) + and d.device_building_tag = SUBSTRING_INDEX(opr.fix_do_code, '_', 2) and d.device_floor_tag = SUBSTRING_INDEX(opr.fix_do_code, '_', 5) + and d.device_system_tag = opr.device_system_category_layer2 and d.device_name_tag = opr.device_system_category_layer3 + left join userinfo ui on opr.work_person_id = ui.userinfo_guid + where opr.deleted = 0 and opr.work_type = 1;"; + var sheet = workbook.CreateSheet("廠商資料"); + var operation_record = backendRepository.GetAllAsync(sqlString, null); + List operation_record_file = new List(); - int RowPosition = 0; - #region set cell - IRow row = sheet.CreateRow(RowPosition); - sheet.SetColumnWidth(0, 4 * 160 * 12); - sheet.SetColumnWidth(1, 4 * 160 * 12); - sheet.SetColumnWidth(2, 4 * 160 * 12); - sheet.SetColumnWidth(3, 4 * 160 * 12); - sheet.SetColumnWidth(4, 4 * 160 * 12); - sheet.SetColumnWidth(5, 4 * 160 * 12); - sheet.SetColumnWidth(6, 4 * 160 * 12); - sheet.SetColumnWidth(7, 4 * 160 * 12); - sheet.SetColumnWidth(8, 4 * 160 * 12); - sheet.SetColumnWidth(9, 4 * 160 * 12); - sheet.SetColumnWidth(10, 4 * 160 * 12); - ICell cell = row.CreateCell(0); - cell.SetCellValue("項目"); - cell.CellStyle = styleLine12; - cell = row.CreateCell(1); - cell.SetCellValue("位置"); - cell.CellStyle = styleLine12; - cell = row.CreateCell(2); - cell.SetCellValue("異常代號"); - cell.CellStyle = styleLine12; - cell = row.CreateCell(3); - cell.SetCellValue("表單號"); - cell.CellStyle = styleLine12; - cell = row.CreateCell(4); - cell.SetCellValue("設備名稱"); - cell.CellStyle = styleLine12; - cell = row.CreateCell(5); - cell.SetCellValue("狀態"); - cell.CellStyle = styleLine12; - cell = row.CreateCell(6); - cell.SetCellValue("處理人員"); - cell.CellStyle = styleLine12; - cell = row.CreateCell(7); - cell.SetCellValue("預計施工時間"); - cell.CellStyle = styleLine12; - cell = row.CreateCell(8); - cell.SetCellValue("檔案上傳"); - cell.CellStyle = styleLine12; - cell = row.CreateCell(9); - cell.SetCellValue("完成時間"); - cell.CellStyle = styleLine12; - cell = row.CreateCell(10); - cell.SetCellValue("建立時間"); - cell.CellStyle = styleLine12; - - #endregion - foreach (var or in operation_record.Result) - { - RowPosition += 1; - row = sheet.CreateRow(RowPosition); - for (var i = 0; i < 11; i++)//column + if (operation_record.Result.Count > 0) { - cell = row.CreateCell(i); - if (i == 0) + foreach (var or in operation_record.Result) { - cell.SetCellValue(or.work_type_name); + sqlString = $@"select * from operation_record_file where record_id = @record_id"; + var param = new { @record_id = or.id }; + operation_record_file = backendRepository.GetAllAsync(sqlString, param).Result; + or.lorf = operation_record_file; } - if (i == 1) + + int RowPosition = 0; + #region set cell + IRow row = sheet.CreateRow(RowPosition); + sheet.SetColumnWidth(0, 4 * 160 * 12); + sheet.SetColumnWidth(1, 4 * 160 * 12); + sheet.SetColumnWidth(2, 4 * 160 * 12); + sheet.SetColumnWidth(3, 4 * 160 * 12); + sheet.SetColumnWidth(4, 4 * 160 * 12); + sheet.SetColumnWidth(5, 4 * 160 * 12); + sheet.SetColumnWidth(6, 4 * 160 * 12); + sheet.SetColumnWidth(7, 4 * 160 * 12); + sheet.SetColumnWidth(8, 4 * 160 * 12); + sheet.SetColumnWidth(9, 4 * 160 * 12); + ICell cell = row.CreateCell(0); + cell.SetCellValue("項目"); + cell.CellStyle = styleLine12; + cell = row.CreateCell(1); + cell.SetCellValue("位置"); + cell.CellStyle = styleLine12; + cell = row.CreateCell(2); + cell.SetCellValue("表單號"); + cell.CellStyle = styleLine12; + cell = row.CreateCell(3); + cell.SetCellValue("設備名稱"); + cell.CellStyle = styleLine12; + cell = row.CreateCell(4); + cell.SetCellValue("狀態"); + cell.CellStyle = styleLine12; + cell = row.CreateCell(5); + cell.SetCellValue("處理人員"); + cell.CellStyle = styleLine12; + cell = row.CreateCell(6); + cell.SetCellValue("預計施工時間"); + cell.CellStyle = styleLine12; + cell = row.CreateCell(7); + cell.SetCellValue("檔案上傳"); + cell.CellStyle = styleLine12; + cell = row.CreateCell(8); + cell.SetCellValue("完成時間"); + cell.CellStyle = styleLine12; + cell = row.CreateCell(9); + cell.SetCellValue("建立時間"); + cell.CellStyle = styleLine12; + #endregion + foreach (var or in operation_record.Result) { - cell.SetCellValue(or.location); - } - if (i == 2) - { - cell.SetCellValue(or.error_code); - sheet.AutoSizeColumn(i); - } - if (i == 3) - { - cell.SetCellValue(or.formId); - } - if (i == 4) - { - cell.SetCellValue(or.device_name); - } - if (i == 5) - { - cell.SetCellValue(or.status_name); - } - if (i == 6) - { - cell.SetCellValue(or.user_full_name); - } - if (i == 7) - { - cell.SetCellValue(or.start_time.ToString("yyyy/MM/dd HH:mm:ss")); - } - if (i == 8)//image - { - var imageNames = or.lorf.Count > 0 ? or.lorf.Select(x => x.save_file_name).ToList() : null; - if (imageNames != null) + RowPosition += 1; + row = sheet.CreateRow(RowPosition); + for (var i = 0; i < 10; i++) { - //insert image process - var dy1 = 10; - var dx1 = 10; - - //image column - sheet.SetColumnWidth(i, 16 * imageNames.Count * 256); //width: picture width(16:100), image total, per character(256) - foreach (var ins in imageNames) + cell = row.CreateCell(i); + if (i == 0) { - //image initial - var extName = ins.Split('.')[1].ToUpper().Equals("JPG") ? "PNG" : ins.Split('.')[1].ToUpper(); - var fullPath = Path.Combine(operationFileSaveAsPath, ins); - var img = Image.FromFile(fullPath); - - //compress image - decimal sizeRatio = ((decimal)img.Height / img.Width); - int thumbWidth = 100; - int thumbHeight = decimal.ToInt32(sizeRatio * thumbWidth); - var thumbStream = img.GetThumbnailImage(thumbWidth, thumbHeight, () => false, IntPtr.Zero); - var memoryStream = new MemoryStream(); - thumbStream.Save(memoryStream, ImageFormat.Jpeg); - - //setting pictureType enum - int format = 0; - var drawing = (XSSFDrawing)sheet.CreateDrawingPatriarch(); - format = Convert.ToInt32(Enum.Parse(typeof(PictureType), extName)); - - //set picture size and location - if (format != 0) - { - var pictureIds = workbook.AddPicture(memoryStream.ToArray(), format); - XSSFClientAnchor anchor = new XSSFClientAnchor(XSSFShape.EMU_PER_PIXEL * dx1, XSSFShape.EMU_PER_PIXEL * dy1, 0, 0, i, j, 0, 0); - anchor.AnchorType = AnchorType.DontMoveAndResize; - var picture = (XSSFPicture)drawing.CreatePicture(anchor, pictureIds); - var size = picture.GetImageDimension(); - row.HeightInPoints = size.Height; - picture.Resize(); - - //add 105 each new pic - dx1 += 105; - } + cell.SetCellValue(or.work_type_name); } + if (i == 1) + { + cell.SetCellValue(or.location); + } + if (i == 2) + { + cell.SetCellValue(or.formId); + } + if (i == 3) + { + cell.SetCellValue(or.device_name); + } + if (i == 4) + { + cell.SetCellValue(or.status_name); + } + if (i == 5) + { + cell.SetCellValue(or.user_full_name); + } + if (i == 6) + { + cell.SetCellValue(or.start_time); + } + if (i == 7) + { + var imageNames = or.lorf.Count > 0 ? or.lorf.Select(x => x.save_file_name).ToList() : null; + if (imageNames != null) + { + //insert image process + var dy1 = 10; + var dx1 = 10; + + //image column + sheet.SetColumnWidth(i, 16 * imageNames.Count * 256); //width: picture width(16:100), image total, per character(256) + foreach (var ins in imageNames) + { + //image initial + var extName = ins.Split('.')[1].ToUpper().Equals("JPG") ? "PNG" : ins.Split('.')[1].ToUpper(); + var fullPath = Path.Combine(operationFileSaveAsPath, ins); + var img = Image.FromFile(fullPath); + + //compress image + decimal sizeRatio = ((decimal)img.Height / img.Width); + int thumbWidth = 100; + int thumbHeight = decimal.ToInt32(sizeRatio * thumbWidth); + var thumbStream = img.GetThumbnailImage(thumbWidth, thumbHeight, () => false, IntPtr.Zero); + var memoryStream = new MemoryStream(); + thumbStream.Save(memoryStream, ImageFormat.Jpeg); + + //setting pictureType enum + int format = 0; + var drawing = (XSSFDrawing)sheet.CreateDrawingPatriarch(); + format = Convert.ToInt32(Enum.Parse(typeof(PictureType), extName)); + + //set picture size and location + if (format != 0) + { + var pictureIds = workbook.AddPicture(memoryStream.ToArray(), format); + XSSFClientAnchor anchor = new XSSFClientAnchor(XSSFShape.EMU_PER_PIXEL * dx1, XSSFShape.EMU_PER_PIXEL * dy1, 0, 0, i, j, 0, 0); + anchor.AnchorType = AnchorType.DontMoveAndResize; + var picture = (XSSFPicture)drawing.CreatePicture(anchor, pictureIds); + var size = picture.GetImageDimension(); + row.HeightInPoints = size.Height; + picture.Resize(); + + //add 105 each new pic + dx1 += 105; + } + } + } + + j++; + } + if (i == 8) + { + cell.SetCellValue(or.finish_time); + } + if (i == 9) + { + cell.SetCellValue(or.Created_at); + } + + cell.CellStyle = style12; } - - j++; } - if (i == 9) - { - cell.SetCellValue(or.finish_time.ToString("yyyy/MM/dd HH:mm:ss")); - } - if (i == 10) - { - cell.SetCellValue(or.Created_at); - } - - cell.CellStyle = style12; - } } + else if (ee.work_type == 2) + { + var sqlString = $@"select opr.*, concat(d.device_floor_tag, ' ', d.device_last_name, ' ', d.device_serial_tag) as device_name, ui.full_name as user_full_name + from operation_record opr + left join device d on opr.fix_do_code = d.device_number and d.deleted = 0 and d.device_area_tag = SUBSTRING_INDEX(opr.fix_do_code, '_', 1) + and d.device_building_tag = SUBSTRING_INDEX(opr.fix_do_code, '_', 2) and d.device_floor_tag = SUBSTRING_INDEX(opr.fix_do_code, '_', 5) + and d.device_system_tag = opr.device_system_category_layer2 and d.device_name_tag = opr.device_system_category_layer3 + left join userinfo ui on opr.work_person_id = ui.userinfo_guid + where opr.deleted = 0 and opr.work_type = 2"; + var sheet = workbook.CreateSheet("廠商資料"); + var operation_record = backendRepository.GetAllAsync(sqlString); + List operation_record_file = new List(); + + if (operation_record.Result.Count > 0) + { + foreach (var or in operation_record.Result) + { + sqlString = $@"select * from operation_record_file where record_id = @record_id"; + var param = new { @record_id = or.id }; + operation_record_file = backendRepository.GetAllAsync(sqlString, param).Result; + or.lorf = operation_record_file; + } + + int RowPosition = 0; + #region set cell + IRow row = sheet.CreateRow(RowPosition); + sheet.SetColumnWidth(0, 4 * 160 * 12); + sheet.SetColumnWidth(1, 4 * 160 * 12); + sheet.SetColumnWidth(2, 4 * 160 * 12); + sheet.SetColumnWidth(3, 4 * 160 * 12); + sheet.SetColumnWidth(4, 4 * 160 * 12); + sheet.SetColumnWidth(5, 4 * 160 * 12); + sheet.SetColumnWidth(6, 4 * 160 * 12); + sheet.SetColumnWidth(7, 4 * 160 * 12); + sheet.SetColumnWidth(8, 4 * 160 * 12); + sheet.SetColumnWidth(9, 4 * 160 * 12); + sheet.SetColumnWidth(10, 4 * 160 * 12); + ICell cell = row.CreateCell(0); + cell.SetCellValue("項目"); + cell.CellStyle = styleLine12; + cell = row.CreateCell(1); + cell.SetCellValue("位置"); + cell.CellStyle = styleLine12; + cell = row.CreateCell(2); + cell.SetCellValue("異常代號"); + cell.CellStyle = styleLine12; + cell = row.CreateCell(3); + cell.SetCellValue("表單號"); + cell.CellStyle = styleLine12; + cell = row.CreateCell(4); + cell.SetCellValue("設備名稱"); + cell.CellStyle = styleLine12; + cell = row.CreateCell(5); + cell.SetCellValue("狀態"); + cell.CellStyle = styleLine12; + cell = row.CreateCell(6); + cell.SetCellValue("處理人員"); + cell.CellStyle = styleLine12; + cell = row.CreateCell(7); + cell.SetCellValue("預計施工時間"); + cell.CellStyle = styleLine12; + cell = row.CreateCell(8); + cell.SetCellValue("檔案上傳"); + cell.CellStyle = styleLine12; + cell = row.CreateCell(9); + cell.SetCellValue("完成時間"); + cell.CellStyle = styleLine12; + cell = row.CreateCell(10); + cell.SetCellValue("建立時間"); + cell.CellStyle = styleLine12; + + #endregion + foreach (var or in operation_record.Result) + { + RowPosition += 1; + row = sheet.CreateRow(RowPosition); + for (var i = 0; i < 11; i++)//column + { + cell = row.CreateCell(i); + if (i == 0) + { + cell.SetCellValue(or.work_type_name); + } + if (i == 1) + { + cell.SetCellValue(or.location); + } + if (i == 2) + { + cell.SetCellValue(or.error_code); + sheet.AutoSizeColumn(i); + } + if (i == 3) + { + cell.SetCellValue(or.formId); + } + if (i == 4) + { + cell.SetCellValue(or.device_name); + } + if (i == 5) + { + cell.SetCellValue(or.status_name); + } + if (i == 6) + { + cell.SetCellValue(or.user_full_name); + } + if (i == 7) + { + cell.SetCellValue(or.start_time.ToString("yyyy/MM/dd HH:mm:ss")); + } + if (i == 8)//image + { + var imageNames = or.lorf.Count > 0 ? or.lorf.Select(x => x.save_file_name).ToList() : null; + if (imageNames != null) + { + //insert image process + var dy1 = 10; + var dx1 = 10; + + //image column + sheet.SetColumnWidth(i, 16 * imageNames.Count * 256); //width: picture width(16:100), image total, per character(256) + foreach (var ins in imageNames) + { + //image initial + var extName = ins.Split('.')[1].ToUpper().Equals("JPG") ? "PNG" : ins.Split('.')[1].ToUpper(); + var fullPath = Path.Combine(operationFileSaveAsPath, ins); + var img = Image.FromFile(fullPath); + + //compress image + decimal sizeRatio = ((decimal)img.Height / img.Width); + int thumbWidth = 100; + int thumbHeight = decimal.ToInt32(sizeRatio * thumbWidth); + var thumbStream = img.GetThumbnailImage(thumbWidth, thumbHeight, () => false, IntPtr.Zero); + var memoryStream = new MemoryStream(); + thumbStream.Save(memoryStream, ImageFormat.Jpeg); + + //setting pictureType enum + int format = 0; + var drawing = (XSSFDrawing)sheet.CreateDrawingPatriarch(); + format = Convert.ToInt32(Enum.Parse(typeof(PictureType), extName)); + + //set picture size and location + if (format != 0) + { + var pictureIds = workbook.AddPicture(memoryStream.ToArray(), format); + XSSFClientAnchor anchor = new XSSFClientAnchor(XSSFShape.EMU_PER_PIXEL * dx1, XSSFShape.EMU_PER_PIXEL * dy1, 0, 0, i, j, 0, 0); + anchor.AnchorType = AnchorType.DontMoveAndResize; + var picture = (XSSFPicture)drawing.CreatePicture(anchor, pictureIds); + var size = picture.GetImageDimension(); + row.HeightInPoints = size.Height; + picture.Resize(); + + //add 105 each new pic + dx1 += 105; + } + } + } + + j++; + } + if (i == 9) + { + cell.SetCellValue(or.finish_time.ToString("yyyy/MM/dd HH:mm:ss")); + } + if (i == 10) + { + cell.SetCellValue(or.Created_at); + } + + cell.CellStyle = style12; + + } + } + } + } + + workbook.Write(fs); } + + apiResult.Code = "0000"; + apiResult.Data = fileName; + } + catch(Exception ex) + { + apiResult.Code = "9999"; + apiResult.Msg = "系統內部錯誤,請聯絡管理者。"; + Logger.LogError("【" + controllerName + "/" + actionName + "】" + ex.Message); + return Ok(apiResult); } - var ms = new NpoiMemoryStream - { - AllowClose = false - }; - workbook.Write(ms); - ms.Flush(); - ms.Seek(0, SeekOrigin.Begin); - - return File(ms, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "廠商資料.xlsx"); + return Ok(apiResult); } #region 廠商 @@ -749,9 +774,14 @@ namespace FrontendWebApi.ApiControllers // sWhere += $@" and convert(of.created_at, DATE) = convert(ADDDATE(NOW(), -1), DATE)"; //} - if (ofl.sub_system_tag != null || ofl.main_system_tag != null) + if (ofl.main_system_tag != null) { - sWhere += $@" and (ofi.device_system_category_layer2 = ifnull(@main_system_tag, device_system_category_layer2) AND ofi.device_system_category_layer3 = ifnull(@sub_system_tag, device_system_category_layer3))"; + sWhere += $@" and ofi.device_system_category_layer2 in @main_system_tag"; + + } + if (ofl.sub_system_tag != null) + { + sWhere += $@" and ofi.device_system_category_layer3 in @sub_system_tag"; } var sqlString = @$"select ofi.*, v2.system_key @@ -996,11 +1026,15 @@ namespace FrontendWebApi.ApiControllers // sWhere += $@" and convert(opr.created_at, DATE) = convert(ADDDATE(NOW(), -1), DATE)"; //} - if (ofl.sub_system_tag != null || ofl.main_system_tag != null) + if (ofl.main_system_tag != null) { - sWhere += $@" and (opr.device_system_category_layer2 = ifnull(@main_system_tag, opr.device_system_category_layer2) AND opr.device_system_category_layer3 = ifnull(@sub_system_tag, opr.device_system_category_layer3))"; + sWhere += $@" and opr.device_system_category_layer2 in @main_system_tag"; + + } + if (ofl.sub_system_tag != null) + { + sWhere += $@" and opr.device_system_category_layer3 in @sub_system_tag"; } - if (ofl.serial_number != null) { sWhere += $@" and opr.formId like '%@formId%'"; diff --git a/FrontendWebApi/Models/HistoryClass.cs b/FrontendWebApi/Models/HistoryClass.cs index d9a08b4..fd71eec 100644 --- a/FrontendWebApi/Models/HistoryClass.cs +++ b/FrontendWebApi/Models/HistoryClass.cs @@ -271,5 +271,6 @@ namespace FrontendWebApi.Models public DateTime starttime { get; set; } public DateTime? endtime { get; set; } public string dateType { get; set; } + public string type { get; set; } } } diff --git a/FrontendWebApi/Models/Operation.cs b/FrontendWebApi/Models/Operation.cs index 74c52fd..94712f0 100644 --- a/FrontendWebApi/Models/Operation.cs +++ b/FrontendWebApi/Models/Operation.cs @@ -44,8 +44,8 @@ namespace FrontendWebApi.Models public DateTime? end_created_at { get; set; }//结束建立时间 //public bool today { get; set; }//今天建立时间 //public bool yesterday { get; set; }//昨天建立时间 - public string main_system_tag { get; set; }//大类tag - public string sub_system_tag { get; set; }//小类tag + public List main_system_tag { get; set; }//大类tag + public List sub_system_tag { get; set; }//小类tag public byte? work_type { get; set; } // 1:保養, 2:維修 } @@ -125,4 +125,16 @@ namespace FrontendWebApi.Models public string ori_file_name { get; set; } public string save_file_name { get; set; } } + + public class Find_Sub_List + { + public List main_system_tag { get; set; } + } + + public class ExportExcel + { + public byte? work_type { get; set; } + public DateTime? startdate { get; set; } + public DateTime? enddate { get; set; } + } }