[後端] 修改條件時間
This commit is contained in:
parent
02e032b201
commit
fa8238ffc7
@ -395,7 +395,7 @@ namespace FrontendWebApi.ApiControllers
|
||||
and d.device_building_tag = SUBSTRING_INDEX(SUBSTRING_INDEX(opr.fix_do_code, '_', 2), '_', -1) and d.device_floor_tag = SUBSTRING_INDEX(SUBSTRING_INDEX(opr.fix_do_code, '_', 5), '_', -1)
|
||||
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 and opr.created_at >= '{ee.startdate}' and opr.created_at <= '{ee.enddate}';";
|
||||
where opr.deleted = 0 and opr.work_type = 1 and opr.created_at >= '{ee.startdate.ToString().Split("_")[0] + "T00:00:00"}' and opr.created_at <= '{ee.enddate.ToString().Split("_")[0] + "T23:59:59"}';";
|
||||
var sheet = workbook.CreateSheet("廠商資料");
|
||||
var operation_record = backendRepository.GetAllAsync<Operation_Record>(sqlString);
|
||||
List<Operation_Record_File> operation_record_file = new List<Operation_Record_File>();
|
||||
@ -559,20 +559,13 @@ namespace FrontendWebApi.ApiControllers
|
||||
}
|
||||
else if (ee.work_type == 2)
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
var sqlString = $@"select opr.*, d.full_name 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(SUBSTRING_INDEX(opr.fix_do_code, '_', 2), '_', -1) and d.device_floor_tag = SUBSTRING_INDEX(SUBSTRING_INDEX(opr.fix_do_code, '_', 5), '_', -1)
|
||||
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 and opr.created_at >= '{ee.startdate}' and opr.created_at <= '{ee.enddate}';";
|
||||
where opr.deleted = 0 and opr.work_type = 2 and opr.created_at >= '{ee.startdate.ToString().Split("_")[0] + "T00:00:00"}' and opr.created_at <= '{ee.enddate.ToString().Split("_")[0] + "T23:59:59"}';";
|
||||
|
||||
var sheet = workbook.CreateSheet("廠商資料");
|
||||
var operation_record = backendRepository.GetAllAsync<Operation_Record>(sqlString);
|
||||
@ -581,170 +574,170 @@ namespace FrontendWebApi.ApiControllers
|
||||
if (operation_record.Result != null)
|
||||
{
|
||||
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<Operation_Record_File>(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
|
||||
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<Operation_Record_File>(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)
|
||||
{
|
||||
cell = row.CreateCell(i);
|
||||
if (i == 0)
|
||||
RowPosition += 1;
|
||||
row = sheet.CreateRow(RowPosition);
|
||||
for (var i = 0; i < 11; i++)//column
|
||||
{
|
||||
cell.SetCellValue(or.work_type_name == "null" ? "" : or.work_type_name);
|
||||
}
|
||||
if (i == 1)
|
||||
{
|
||||
cell.SetCellValue(or.location == "null" ? "" : or.location);
|
||||
}
|
||||
if (i == 2)
|
||||
{
|
||||
cell.SetCellValue(or.error_code == "null" ? "" : or.error_code);
|
||||
sheet.AutoSizeColumn(i);
|
||||
}
|
||||
if (i == 3)
|
||||
{
|
||||
cell.SetCellValue(or.formId == "null" ? "" : or.formId);
|
||||
}
|
||||
if (i == 4)
|
||||
{
|
||||
cell.SetCellValue(or.device_name == "null" ? "" : or.device_name);
|
||||
}
|
||||
if (i == 5)
|
||||
{
|
||||
cell.SetCellValue(or.status_name == "null" ? "" : or.status_name);
|
||||
}
|
||||
if (i == 6)
|
||||
{
|
||||
cell.SetCellValue(or.user_full_name == "null" ? "" : or.user_full_name);
|
||||
}
|
||||
if (i == 7)
|
||||
{
|
||||
cell.SetCellValue(or.start_time != null ? ((DateTime)or.start_time).ToString("yyyy/MM/dd HH:mm:ss") : null);
|
||||
}
|
||||
if (i == 8)//image
|
||||
{
|
||||
var imageNames = or.lorf.Count > 0 ? or.lorf.Where(x => x.ori_file_name.Contains("JPG") || x.ori_file_name.Contains("PNG")).Select(x => x.save_file_name).ToList() : null;
|
||||
if (imageNames != null)
|
||||
cell = row.CreateCell(i);
|
||||
if (i == 0)
|
||||
{
|
||||
//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.SetCellValue(or.work_type_name == "null" ? "" : or.work_type_name);
|
||||
}
|
||||
if (i == 1)
|
||||
{
|
||||
cell.SetCellValue(or.location == "null" ? "" : or.location);
|
||||
}
|
||||
if (i == 2)
|
||||
{
|
||||
cell.SetCellValue(or.error_code == "null" ? "" : or.error_code);
|
||||
sheet.AutoSizeColumn(i);
|
||||
}
|
||||
if (i == 3)
|
||||
{
|
||||
cell.SetCellValue(or.formId == "null" ? "" : or.formId);
|
||||
}
|
||||
if (i == 4)
|
||||
{
|
||||
cell.SetCellValue(or.device_name == "null" ? "" : or.device_name);
|
||||
}
|
||||
if (i == 5)
|
||||
{
|
||||
cell.SetCellValue(or.status_name == "null" ? "" : or.status_name);
|
||||
}
|
||||
if (i == 6)
|
||||
{
|
||||
cell.SetCellValue(or.user_full_name == "null" ? "" : or.user_full_name);
|
||||
}
|
||||
if (i == 7)
|
||||
{
|
||||
cell.SetCellValue(or.start_time != null ? ((DateTime)or.start_time).ToString("yyyy/MM/dd HH:mm:ss") : null);
|
||||
}
|
||||
if (i == 8)//image
|
||||
{
|
||||
var imageNames = or.lorf.Count > 0 ? or.lorf.Where(x => x.ori_file_name.Contains("JPG") || x.ori_file_name.Contains("PNG")).Select(x => x.save_file_name).ToList() : null;
|
||||
if (imageNames != null)
|
||||
{
|
||||
//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);
|
||||
//insert image process
|
||||
var dy1 = 10;
|
||||
var dx1 = 10;
|
||||
|
||||
//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)
|
||||
//image column
|
||||
sheet.SetColumnWidth(i, 16 * imageNames.Count * 256); //width: picture width(16:100), image total, per character(256)
|
||||
foreach (var ins in imageNames)
|
||||
{
|
||||
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();
|
||||
//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);
|
||||
|
||||
//add 105 each new pic
|
||||
dx1 += 105;
|
||||
//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 != null ? ((DateTime)or.finish_time).ToString("yyyy/MM/dd HH:mm:ss") : null);
|
||||
}
|
||||
if (i == 10)
|
||||
{
|
||||
cell.SetCellValue(or.Created_at == "null" ? "" : or.Created_at);
|
||||
}
|
||||
|
||||
j++;
|
||||
}
|
||||
if (i == 9)
|
||||
{
|
||||
cell.SetCellValue(or.finish_time != null ? ((DateTime)or.finish_time).ToString("yyyy/MM/dd HH:mm:ss") : null);
|
||||
}
|
||||
if (i == 10)
|
||||
{
|
||||
cell.SetCellValue(or.Created_at == "null" ? "" : or.Created_at);
|
||||
}
|
||||
|
||||
cell.CellStyle = style12;
|
||||
cell.CellStyle = style12;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
workbook.Write(fs);
|
||||
|
Loading…
Reference in New Issue
Block a user