using System;
using SqlSugar;
using Infrastructure.Attribute;
using Infrastructure.Extensions;
using RIZO.Model;
using RIZO.Model.Dto;
using RIZO.Model.MES.product;
using RIZO.Model.MES.product.Dto;
using RIZO.Repository;
using RIZO.Service.MES.product.IService;
using System.Linq;
using Microsoft.AspNetCore.Http;
using Infrastructure;
using static System.Runtime.InteropServices.JavaScript.JSType;
using Mapster;
using Microsoft.AspNetCore.Mvc;
using NPOI.SS.Formula.Functions;
using NPOI.SS.UserModel;
using NPOI.XSSF.UserModel;
using System.Globalization;
using NPOI.HSSF.Record;
using JinianNet.JNTemplate;
namespace RIZO.Service.MES.product
{
///
/// 日计划达成率Service业务层处理
///
[AppService(ServiceType = typeof(IProPlanAchievementrateService), ServiceLifetime = LifeTime.Transient)]
public class ProPlanAchievementrateService : BaseService, IProPlanAchievementrateService
{
///
/// 查询日计划达成率列表
///
///
///
public PagedInfo GetList(ProPlanAchievementrateQueryDto parm)
{
var predicate = Expressionable.Create()
.AndIF(!string.IsNullOrEmpty(parm.Project), it => it.Project.Contains(parm.Project))
.AndIF(parm.RecordDate > DateTime.MinValue, it => it.RecordDate == parm.RecordDate)
;
var response = Queryable()
.Where(predicate.ToExpression())
.ToPage(parm);
return response;
}
///
/// 生成每日的计划达成率
///
///
///
public bool DayofplanAchievementRate([FromBody] ProPlanAchievementrateQueryDto3 parm)
{
int result = 0;
List AproPlanAchievementrates = Context.Queryable()
.LeftJoin((w, r) => w.Workorder == r.FkWorkorder)
.Where((w, r) => w.WorkorderDate == parm.GenarateDate && w.AorBgroup == "A")
.GroupBy((w, r) => new { w.Project, w.AorBgroup })
.Select((w, r) => new ProPlanAchievementrate()
{
Project = w.Project,
AgroupProductNum = SqlFunc.AggregateSum(r.FinishedNum),
AgroupMonitor = SqlFunc.AggregateMax(w.Groupleader),
AgroupPlanNum = SqlFunc.AggregateSum(w.DeliveryNum),
AgroupCompletionRate = SqlFunc.Round((decimal)(SqlFunc.AggregateSum(r.FinishedNum) / SqlFunc.AggregateSum(w.DeliveryNum)), 2) * 100,
//BgroupProductNum = SqlFunc.AggregateSum(r.FinishedNum),
//BgroupPlanNum = SqlFunc.AggregateSum(w.DeliveryNum),
//BgroupCompletionRate = SqlFunc.Round((decimal)(SqlFunc.AggregateSum(r.FinishedNum) / SqlFunc.AggregateSum(w.DeliveryNum)), 2) * 100,
SummaryActualNum = SqlFunc.AggregateSum(r.FinishedNum),
SummaryPlanNum = SqlFunc.AggregateSum(w.DeliveryNum),
SummaryPlanAchievementRate = SqlFunc.Round((decimal)(SqlFunc.AggregateSum(r.FinishedNum) / SqlFunc.AggregateSum(w.DeliveryNum)), 2) * 100,
RecordDate = parm.GenarateDate
}).ToList();
List BproPlanAchievementrates = Context.Queryable()
.LeftJoin((w, r) => w.Workorder == r.FkWorkorder)
.Where((w, r) => w.WorkorderDate == parm.GenarateDate && w.AorBgroup == "B")
.GroupBy((w, r) => new { w.Project, w.AorBgroup, w.Groupleader })
.Select((w, r) => new ProPlanAchievementrate()
{
Project = w.Project,
//AgroupProductNum = SqlFunc.AggregateSum(r.FinishedNum),
//AgroupPlanNum = SqlFunc.AggregateSum(w.DeliveryNum),
//AgroupCompletionRate = SqlFunc.Round((decimal)(SqlFunc.AggregateSum(r.FinishedNum) / SqlFunc.AggregateSum(w.DeliveryNum)), 2) * 100,
BgroupProductNum = SqlFunc.AggregateSum(r.FinishedNum),
BgroupPlanNum = SqlFunc.AggregateSum(w.DeliveryNum),
BgroupMonitor = SqlFunc.AggregateMax(w.Groupleader),
BgroupCompletionRate = SqlFunc.Round((decimal)(SqlFunc.AggregateSum(r.FinishedNum) / SqlFunc.AggregateSum(w.DeliveryNum)), 2) * 100,
SummaryActualNum = SqlFunc.AggregateSum(r.FinishedNum),
SummaryPlanNum = SqlFunc.AggregateSum(w.DeliveryNum),
SummaryPlanAchievementRate = SqlFunc.Round((decimal)(SqlFunc.AggregateSum(r.FinishedNum) / SqlFunc.AggregateSum(w.DeliveryNum)), 2) * 100,
RecordDate = parm.GenarateDate
}).ToList();
if (AproPlanAchievementrates.Count > 0 && BproPlanAchievementrates.Count > 0)
{
var merged = AproPlanAchievementrates
.Join(
BproPlanAchievementrates,
a => a.Project, // A 的 key(用于 Join)
b => b.Project, // B 的 key(用于 Join)
(a, b) => new ProPlanAchievementrate
{
Project = a.Project,
// A 组数据
AgroupProductNum = a.AgroupProductNum,
AgroupPlanNum = a.AgroupPlanNum,
AgroupCompletionRate = a.AgroupCompletionRate,
AgroupMonitor = a.AgroupMonitor,
// B 组数据
BgroupProductNum = b.BgroupProductNum,
BgroupPlanNum = b.BgroupPlanNum,
BgroupCompletionRate = b.BgroupCompletionRate,
BgroupMonitor = b.BgroupMonitor,
// 汇总数据
SummaryActualNum = (a.SummaryActualNum ?? 0) + (b.SummaryActualNum ?? 0),
SummaryPlanNum = (a.SummaryPlanNum ?? 0) + (b.SummaryPlanNum ?? 0),
SummaryPlanAchievementRate = SqlFunc.Round(
(decimal)((a.SummaryActualNum ?? 0) + (b.SummaryActualNum ?? 0)) /
(decimal)((a.SummaryPlanNum ?? 0) + (b.SummaryPlanNum ?? 0)), 2) * 100,
RecordDate = a.RecordDate,
CreatedTime = DateTime.Now,
UpdatedTime = DateTime.Now,
}
);
List finalList = merged.ToList();
UseTran2(() =>
{
Context.Deleteable().Where(it => it.RecordDate == parm.GenarateDate);
result = Context.Insertable(finalList).ExecuteCommand();
});
}
return result > 0;
}
///
/// 查询月计划达成率列表
///
///
///
public PagedInfo GetListByMonth(ProPlanAchievementrateQueryDto2 parm)
{
(DateTime FirstDay, DateTime LastDay) Handlemonth = GetFirstAndLastDayOfMonth(parm.SearchYearMonth);
var predicate = Expressionable.Create()
.AndIF(!string.IsNullOrEmpty(parm.Project), it => it.Project.Contains(parm.Project))
.And(it => it.RecordDate >= Handlemonth.FirstDay && it.RecordDate <= Handlemonth.LastDay)
;
var response = Queryable()
.Where(predicate.ToExpression())
.GroupBy(it => it.Project)
.Select(it => new ProPlanAchievementrate()
{
Project = it.Project,
AgroupPlanNum = SqlFunc.AggregateSum(it.AgroupPlanNum ?? 0),
AgroupProductNum = SqlFunc.AggregateSum(it.AgroupProductNum ?? 0),
AgroupCompletionRate = SqlFunc.AggregateAvg(it.AgroupCompletionRate),
BgroupPlanNum = SqlFunc.AggregateSum(it.BgroupPlanNum ?? 0),
BgroupProductNum = SqlFunc.AggregateSum(it.BgroupProductNum ?? 0),
BgroupCompletionRate = SqlFunc.AggregateAvg(it.BgroupCompletionRate),
SummaryActualNum = SqlFunc.AggregateSum(it.SummaryActualNum ?? 0),
SummaryPlanNum = SqlFunc.AggregateSum(it.SummaryPlanNum ?? 0),
SummaryPlanAchievementRate = SqlFunc.AggregateAvg(it.SummaryPlanAchievementRate),
DownQuality = SqlFunc.AggregateSum(it.DownQuality ?? 0),
DownSuppler = SqlFunc.AggregateSum(it.DownSuppler ?? 0),
DownDeviceFailure = SqlFunc.AggregateSum(it.DownDeviceFailure ?? 0),
DownDeviceDebug = SqlFunc.AggregateSum(it.DownDeviceDebug ?? 0),
DownLogisticsWaitMaterial = SqlFunc.AggregateSum(it.DownLogisticsWaitMaterial ?? 0),
DownLackMaterial = SqlFunc.AggregateSum(it.DownLackMaterial ?? 0),
DownInjection = SqlFunc.AggregateSum(it.DownInjection ?? 0),
DownAssembly = SqlFunc.AggregateSum(it.DownAssembly ?? 0),
AllLineStopTime = SqlFunc.AggregateSum(it.AllLineStopTime ?? 0),
RecordDate = Handlemonth.FirstDay
})
.ToPage(parm);
return response;
}
private (DateTime FirstDay, DateTime LastDay) GetFirstAndLastDayOfMonth(DateTime date)
{
DateTime firstDay = new DateTime(date.Year, date.Month, 1);
int lastDay = DateTime.DaysInMonth(date.Year, date.Month);
DateTime lastDayDate = new DateTime(date.Year, date.Month, lastDay);
return (firstDay, lastDayDate);
}
///
/// 获取详情
///
///
///
public ProPlanAchievementrate GetInfo(int Id)
{
var response = Queryable()
.Where(x => x.Id == Id)
.First();
return response;
}
///
/// 添加日计划达成率
///
///
///
public ProPlanAchievementrate AddProPlanAchievementrate(ProPlanAchievementrate model)
{
return Context.Insertable(model).IgnoreColumns(it => new { it.Id }).ExecuteReturnEntity();
}
///
/// 修改日计划达成率
///
///
///
public int UpdateProPlanAchievementrate(ProPlanAchievementrate model)
{
//var response = Update(w => w.Id == model.Id, it => new ProPlanAchievementrate()
//{
// Project = model.Project,
// AgroupMonitor = model.AgroupMonitor,
// AgroupProductNum = model.AgroupProductNum,
// AgroupStandardYield = model.AgroupStandardYield,
// AgroupPlanNum = model.AgroupPlanNum,
// AgroupCompletionRate = model.AgroupCompletionRate,
// BgroupMonitor = model.BgroupMonitor,
// BgroupProductNum = model.BgroupProductNum,
// BgroupStandardYield = model.BgroupStandardYield,
// BgroupPlanNum = model.BgroupPlanNum,
// BgroupCompletionRate = model.BgroupCompletionRate,
// SummaryActualNum = model.SummaryActualNum,
// SummaryPlanNum = model.SummaryPlanNum,
// SummaryPlanAchievementRate = model.SummaryPlanAchievementRate,
// DownQuality = model.DownQuality,
// DownSuppler = model.DownSuppler,
// DownDeviceFailure = model.DownDeviceFailure,
// DownDeviceDebug = model.DownDeviceDebug,
// DownLogisticsWaitMaterial = model.DownLogisticsWaitMaterial,
// DownLackMaterial = model.DownLackMaterial,
// DownProject = model.DownProject,
// DownInjection = model.DownInjection,
// DownAssembly = model.DownAssembly,
// AllLineStopTime = model.AllLineStopTime,
// MainProblemDescription = model.MainProblemDescription,
// Strategy = model.Strategy,
// ResponsiblePerson = model.ResponsiblePerson,
// RecordDate = model.RecordDate,
// CreatedBy = model.CreatedBy,
// CreatedTime = model.CreatedTime,
// UpdatedBy = model.UpdatedBy,
// UpdatedTime = model.UpdatedTime,
//});
//return response;
return Update(model, true);
}
public List GetTodayList()
{
DateTime today = DateTime.Today;
var response = Queryable()
.Where(it => it.RecordDate == today)
.ToList()
.Adapt, List>()
;
return response;
}
public List GetTodayRealTimeList()
{
ProPlanAchievementrateQueryDto3 parm = new ProPlanAchievementrateQueryDto3();
parm.GenarateDate = DateTime.Today;
bool result = DayofplanAchievementRate(parm);
var response = Queryable()
.Where(it => it.RecordDate == parm.GenarateDate)
.ToList()
.Adapt, List>()
;
return response;
}
public List GetYesterdayList()
{
DateTime yesterday = DateTime.Today.AddDays(-1);
var response = Queryable()
.Where(it => it.RecordDate == yesterday)
.ToList()
.Adapt, List>()
;
return response;
}
public List GetListByMonth()
{
(DateTime FirstDay, DateTime LastDay) Handlemonth = GetFirstAndLastDayOfMonth(DateTime.Today);
var predicate = Expressionable.Create()
.And(it => it.RecordDate >= Handlemonth.FirstDay && it.RecordDate <= Handlemonth.LastDay)
;
var response = Queryable()
.Where(predicate.ToExpression())
.GroupBy(it => it.Project)
.Select(it => new ProPlanAchievementrate()
{
Project = it.Project,
AgroupPlanNum = SqlFunc.AggregateSum(it.AgroupPlanNum ?? 0),
AgroupProductNum = SqlFunc.AggregateSum(it.AgroupProductNum ?? 0),
AgroupCompletionRate = SqlFunc.AggregateAvg(it.AgroupCompletionRate),
BgroupPlanNum = SqlFunc.AggregateSum(it.BgroupPlanNum ?? 0),
BgroupProductNum = SqlFunc.AggregateSum(it.BgroupProductNum ?? 0),
BgroupCompletionRate = SqlFunc.AggregateAvg(it.BgroupCompletionRate),
SummaryActualNum = SqlFunc.AggregateSum(it.SummaryActualNum ?? 0),
SummaryPlanNum = SqlFunc.AggregateSum(it.SummaryPlanNum ?? 0),
SummaryPlanAchievementRate = SqlFunc.AggregateAvg(it.SummaryPlanAchievementRate),
DownQuality = SqlFunc.AggregateSum(it.DownQuality ?? 0),
DownSuppler = SqlFunc.AggregateSum(it.DownSuppler ?? 0),
DownDeviceFailure = SqlFunc.AggregateSum(it.DownDeviceFailure ?? 0),
DownDeviceDebug = SqlFunc.AggregateSum(it.DownDeviceDebug ?? 0),
DownLogisticsWaitMaterial = SqlFunc.AggregateSum(it.DownLogisticsWaitMaterial ?? 0),
DownLackMaterial = SqlFunc.AggregateSum(it.DownLackMaterial ?? 0),
DownInjection = SqlFunc.AggregateSum(it.DownInjection ?? 0),
DownAssembly = SqlFunc.AggregateSum(it.DownAssembly ?? 0),
AllLineStopTime = SqlFunc.AggregateSum(it.AllLineStopTime ?? 0),
RecordDate = Handlemonth.FirstDay
})
.ToList()
.Adapt, List>();
return response;
}
public int ImportData(IFormFile formFile, string name, DateTime RecordDate)
{
using (var stream = formFile.OpenReadStream())
{
try
{
IWorkbook workbook = new XSSFWorkbook(stream);
ISheet sheet = workbook.GetSheetAt(0);
List AchievementrateList = new List();
// 遍历每一行
for (int row = 4; row <= sheet.LastRowNum; row++)
{
IRow currentRow = sheet.GetRow(row);
if (currentRow != null && currentRow.GetCell(0) != null) // 确保行不为空
{
ProPlanAchievementrate achievementrate = new ProPlanAchievementrate();
//获取项目号
if (currentRow.GetCell(0) != null && currentRow.GetCell(0).CellType == CellType.String)
achievementrate.Project = currentRow.GetCell(0).ToString();
//A班班长
if (currentRow.GetCell(1) != null && currentRow.GetCell(1).CellType == CellType.String)
achievementrate.AgroupMonitor = currentRow.GetCell(1).ToString();
//A班生产数量
if (currentRow.GetCell(2) != null && currentRow.GetCell(2).CellType == CellType.Numeric)
achievementrate.AgroupProductNum = (int)currentRow.GetCell(2).NumericCellValue;
//A班标准班产
if (currentRow.GetCell(3) != null && currentRow.GetCell(3).CellType == CellType.Numeric)
achievementrate.AgroupStandardYield = (int)currentRow.GetCell(3).NumericCellValue;
//A班计划数量
if (currentRow.GetCell(4) != null && currentRow.GetCell(4).CellType == CellType.Numeric)
achievementrate.AgroupPlanNum = (int)currentRow.GetCell(4).NumericCellValue;
//A班完成率
if (currentRow.GetCell(5) != null && currentRow.GetCell(5).CellType == CellType.Numeric)
achievementrate.AgroupCompletionRate = (decimal)currentRow.GetCell(5).NumericCellValue;
//B班班长
if (currentRow.GetCell(6) != null && currentRow.GetCell(6).CellType == CellType.String)
achievementrate.BgroupMonitor = currentRow.GetCell(6).ToString();
//B班生产数量
if (currentRow.GetCell(7) != null && currentRow.GetCell(7).CellType == CellType.Numeric)
achievementrate.BgroupProductNum = (int)currentRow.GetCell(7).NumericCellValue;
//B班标准班产
if (currentRow.GetCell(8) != null && currentRow.GetCell(8).CellType == CellType.Numeric)
achievementrate.BgroupStandardYield = (int)currentRow.GetCell(8).NumericCellValue;
//B班计划数量
if (currentRow.GetCell(9) != null && currentRow.GetCell(9).CellType == CellType.Numeric)
achievementrate.BgroupPlanNum = (int)currentRow.GetCell(9).NumericCellValue;
//B班完成率
if (currentRow.GetCell(10) != null && currentRow.GetCell(10).CellType == CellType.Numeric)
achievementrate.BgroupCompletionRate = (decimal)currentRow.GetCell(10).NumericCellValue;
//汇总实际数量
if (currentRow.GetCell(11) != null && currentRow.GetCell(11).CellType == CellType.Numeric)
achievementrate.SummaryActualNum = (int)currentRow.GetCell(11).NumericCellValue;
//汇总计划数量
if (currentRow.GetCell(12) != null && currentRow.GetCell(12).CellType == CellType.Numeric)
achievementrate.SummaryPlanNum = (int)currentRow.GetCell(12).NumericCellValue;
//汇总计划达成率
if (currentRow.GetCell(13) != null && currentRow.GetCell(13).CellType == CellType.Numeric)
achievementrate.SummaryPlanAchievementRate = (decimal)currentRow.GetCell(13).NumericCellValue;
//记录日期
//if (currentRow.GetCell(14) != null && currentRow.GetCell(14).CellType == CellType.String)
// achievementrate.RecordDate = DateTime.ParseExact(currentRow.GetCell(14).ToString(), "yyyy-MM-dd", CultureInfo.InvariantCulture);
//质量问题
if (currentRow.GetCell(14) != null && currentRow.GetCell(14).CellType == CellType.Numeric)
achievementrate.DownQuality = (int)currentRow.GetCell(14).NumericCellValue;
//供应商问题
if (currentRow.GetCell(15) != null && currentRow.GetCell(15).CellType == CellType.Numeric)
achievementrate.DownSuppler = (int)currentRow.GetCell(15).NumericCellValue;
//设备故障
if (currentRow.GetCell(16) != null && currentRow.GetCell(16).CellType == CellType.Numeric)
achievementrate.DownDeviceFailure = (int)currentRow.GetCell(16).NumericCellValue;
//设备调试
if (currentRow.GetCell(17) != null && currentRow.GetCell(17).CellType == CellType.Numeric)
achievementrate.DownDeviceDebug = (int)currentRow.GetCell(17).NumericCellValue;
//物流等待物料
if (currentRow.GetCell(18) != null && currentRow.GetCell(18).CellType == CellType.Numeric)
achievementrate.DownLogisticsWaitMaterial = (int)currentRow.GetCell(18).NumericCellValue;
//物料短缺
if (currentRow.GetCell(19) != null && currentRow.GetCell(19).CellType == CellType.Numeric)
achievementrate.DownLackMaterial = (int)currentRow.GetCell(19).NumericCellValue;
//注塑异常
if (currentRow.GetCell(20) != null && currentRow.GetCell(20).CellType == CellType.Numeric)
achievementrate.DownInjection = (int)currentRow.GetCell(20).NumericCellValue;
//装配异常
if (currentRow.GetCell(21) != null && currentRow.GetCell(21).CellType == CellType.Numeric)
achievementrate.DownAssembly = (int)currentRow.GetCell(21).NumericCellValue;
//全线停机时间
if (currentRow.GetCell(22) != null && currentRow.GetCell(22).CellType == CellType.Numeric)
achievementrate.AllLineStopTime = (int)currentRow.GetCell(22).NumericCellValue;
//主要问题描述
if (currentRow.GetCell(23) != null && currentRow.GetCell(23).CellType == CellType.String)
achievementrate.MainProblemDescription = currentRow.GetCell(23).ToString();
//改善对策
if (currentRow.GetCell(24) != null && currentRow.GetCell(24).CellType == CellType.String)
achievementrate.Strategy = currentRow.GetCell(24).ToString();
//责任人
if (currentRow.GetCell(25) != null && currentRow.GetCell(25).CellType == CellType.String)
achievementrate.ResponsiblePerson = currentRow.GetCell(25).ToString();
achievementrate.RecordDate = RecordDate.Date;
AchievementrateList.Add(achievementrate);
}
}
if (AchievementrateList.Count == 0)
{
return 0;
}
UseTran2(() =>
{
Context.Deleteable().Where(it => it.RecordDate == RecordDate.Date).ExecuteCommand();
Context.Insertable(AchievementrateList).ExecuteCommand();
});
return AchievementrateList.Count;
}
catch (Exception ex)
{
throw new CustomException("excel文件异常,请详细核对");
}
}
}
public byte[] ExportData(DateTime exportDate)
{
string templatePath = Path.Combine(
Directory.GetCurrentDirectory(),
"wwwroot",
"ImportTemplate",
"PlanAchievementRate.xlsx"
);
if (!global::System.IO.File.Exists(templatePath))
{
throw new CustomException("Excel 模板文件不存在");
}
List dataList = Context.Queryable()
.Where(it => it.RecordDate.HasValue && it.RecordDate.Value.Date == exportDate.Date)
.ToList();
using (var fileStream = new FileStream(templatePath, FileMode.Open, FileAccess.Read))
{
IWorkbook workbook = WorkbookFactory.Create(fileStream);
ISheet sheet = workbook.GetSheetAt(0);
int startRowIndex = 4;
// 创建带边框的样式(只需创建一次,推荐提到循环外面)
ICellStyle borderedCellStyle = workbook.CreateCellStyle();
borderedCellStyle.BorderTop = BorderStyle.Thin;
borderedCellStyle.BorderBottom = BorderStyle.Thin;
borderedCellStyle.BorderLeft = BorderStyle.Thin;
borderedCellStyle.BorderRight = BorderStyle.Thin;
borderedCellStyle.TopBorderColor = IndexedColors.Black.Index;
borderedCellStyle.BottomBorderColor = IndexedColors.Black.Index;
borderedCellStyle.LeftBorderColor = IndexedColors.Black.Index;
borderedCellStyle.RightBorderColor = IndexedColors.Black.Index;
for (int i = 0; i < dataList.Count; i++)
{
var item = dataList[i];
IRow row = sheet.GetRow(startRowIndex + i) ?? sheet.CreateRow(startRowIndex + i);
row.CreateCell(1).SetCellValue(item.Project);
row.CreateCell(2).SetCellValue(item.AgroupMonitor);
row.CreateCell(3).SetCellValue((double)(item.AgroupProductNum ?? 0));
row.CreateCell(4).SetCellValue((double)(item.AgroupStandardYield ?? 0));
row.CreateCell(5).SetCellValue((double)(item.AgroupPlanNum ?? 0));
row.CreateCell(6).SetCellValue((double)item.AgroupCompletionRate);
row.CreateCell(7).SetCellValue(item.BgroupMonitor);
row.CreateCell(8).SetCellValue((double)(item.BgroupProductNum ?? 0));
row.CreateCell(9).SetCellValue((double)(item.BgroupStandardYield ?? 0));
row.CreateCell(10).SetCellValue((double)(item.BgroupPlanNum ?? 0));
row.CreateCell(11).SetCellValue((double)item.BgroupCompletionRate);
row.CreateCell(12).SetCellValue((double)(item.SummaryActualNum ?? 0));
row.CreateCell(13).SetCellValue((double)(item.SummaryPlanNum ?? 0));
row.CreateCell(14).SetCellValue((double)item.SummaryPlanAchievementRate);
row.CreateCell(15).SetCellValue((double)(item.DownQuality ?? 0));
row.CreateCell(16).SetCellValue((double)(item.DownSuppler ?? 0));
row.CreateCell(17).SetCellValue((double)(item.DownDeviceFailure ?? 0));
row.CreateCell(18).SetCellValue((double)(item.DownDeviceDebug ?? 0));
row.CreateCell(19).SetCellValue((double)(item.DownLogisticsWaitMaterial ?? 0));
row.CreateCell(20).SetCellValue((double)(item.DownLackMaterial ?? 0));
row.CreateCell(21).SetCellValue((double)(item.DownInjection ?? 0));
row.CreateCell(22).SetCellValue((double)(item.DownAssembly ?? 0));
row.CreateCell(23).SetCellValue((double)(item.AllLineStopTime ?? 0));
row.CreateCell(24).SetCellValue(item.MainProblemDescription);
row.CreateCell(25).SetCellValue(item.Strategy);
row.CreateCell(26).SetCellValue(item.ResponsiblePerson);
}
// 改为写入 MemoryStream 然后转成 byte[]
var memoryStream = new MemoryStream();
workbook.Write(memoryStream);
// memoryStream.Position = 0;
return memoryStream.ToArray(); // ✅ 直接返回 byte 数组
}
}
}
}