后台数据处理超时,行列转换差不多2分多钟
public List<KPISupplierReportShow> GetKPIReport
(bool? purchaseStatus,List<string> facs, List<string> status, List<string> types, string searchKey, string startDate, string endDate)
{
using (SRMDatabaseEntities entity = new SRMDatabaseEntities())
{
DateTime start = string.IsNullOrEmpty(startDate) ? DateTime.MinValue : Convert.ToDateTime(startDate);
DateTime end = string.IsNullOrEmpty(endDate) ? DateTime.MaxValue : Convert.ToDateTime(endDate);
var model = from p in entity.KPISupplierReport
join q in entity.SupplierInfoReport on p.SupplierCode equals q.SupplierCode
join j in entity.SystemUser on p.CreatedUser.ToUpper() equals j.UserId.ToUpper() into temp
from k in temp.DefaultIfEmpty()
where
(
status.Contains(p.Status)
&& facs.Contains(p.FactoryCode)
&& types.Contains(p.ReportCycle)
&& (purchaseStatus == null || q.PurchaseStatus == purchaseStatus)
&& (p.CreatedDate > start && p.CreatedDate < end)
&&
(string.IsNullOrEmpty(searchKey)
|| p.SupplierCode.Contains(searchKey)
|| p.SupplierName.Contains(searchKey)
|| p.ReportNumber.Contains(searchKey)
|| k.UserName.Contains(searchKey)
|| p.CreatedUser.Contains(searchKey)
|| p.ReportName.Contains(searchKey)
)
)
orderby p.Id descending
select new
{
q.PurchaseStatus,
p.Id,
p.ApprovalStatus,
p.CreatedDate,
k.UserName,
p.FactoryCode,
p.FactoryName,
p.FeedbackDate,
p.KPIMonthEnd,
p.KPIMonthStart,
p.KPIYear,
p.MaterielCode,
p.ReportCycle,
p.ReportName,
p.ReportNumber,
p.Score,
p.SendDate,
p.Status,
p.SupplierCode,
p.SupplierName
};
var modelList = model.ToList();
var numberList = modelList.Select(i => i.ReportNumber).ToList();
var itemList = entity.KPISupplierItem.Where(i => numberList.Contains(i.ReportNumber)).ToList();
//上面部分取数都是很快的,就是下面这部分要进行行列转换,
//把明细里对应的列写到头的行里,测试用10000条记录,这个foreach大概要2分多钟,
//除了修改超时时间限制,还有别的办法么?
List<KPISupplierReportShow> reportList = new List<KPISupplierReportShow>();
KPISupplierReportShow rshow;
List<KPISupplierItem> tempItemList;
KPISupplierItem tempItem;
foreach (var kpi in modelList)
{
rshow = new KPISupplierReportShow()
{
PurchaseStatus=kpi.PurchaseStatus? "激活":"暂停",
ApprovalStatus = EnumHelper.GetEnumDescription<WorkflowStatus>(EnumHelper.GetEnum<WorkflowStatus>(kpi.ApprovalStatus)),
CreatedDate = kpi.CreatedDate.ToString("yyyy-MM-dd"),
CreatedUser = kpi.UserName,
FactoryCode = kpi.FactoryCode,
FactoryName = kpi.FactoryName,
FeedbackDate = kpi.FeedbackDate,
Id = kpi.Id,
KPIMonthEnd = kpi.KPIMonthEnd,
KPIMonthStart = kpi.KPIMonthStart,
KPIYear = kpi.KPIYear,
MaterielCode = kpi.MaterielCode,
ReportCycle = kpi.ReportCycle,
ReportName = kpi.ReportName,
ReportNumber = kpi.ReportNumber,
Score = kpi.Score,
SendDate = kpi.SendDate,
Status = EnumHelper.GetEnumDescription<ExaminationStatus>(EnumHelper.GetEnum<ExaminationStatus>(kpi.Status)),
SupplierCode = kpi.SupplierCode,
SupplierName = kpi.SupplierName
};
tempItemList = itemList.Where(t => t.ReportNumber == kpi.ReportNumber).ToList();
//品质
tempItem = tempItemList.FirstOrDefault(t => t.Title.Contains(KPISupplierReportShow.Key1));
if (tempItem != null)
{
rshow.Penalty1 = 0 - (tempItem.TargetScore - (tempItem.Score.HasValue ? tempItem.Score.Value : 0));
rshow.PenaltyRemark1 = tempItem.Reason;
}
//交付
tempItem = tempItemList.FirstOrDefault(t => t.Title.Contains(KPISupplierReportShow.Key2));
if (tempItem != null)
{
rshow.Penalty2 = 0 - (tempItem.TargetScore - (tempItem.Score.HasValue ? tempItem.Score.Value : 0));
rshow.PenaltyRemark2 = tempItem.Reason;
}
//服务
tempItem = tempItemList.FirstOrDefault(t => t.Title.Contains(KPISupplierReportShow.Key3));
if (tempItem != null)
{
rshow.Penalty3 = 0 - (tempItem.TargetScore - (tempItem.Score.HasValue ? tempItem.Score.Value : 0));
rshow.PenaltyRemark3 = tempItem.Reason;
}
//附加运费
tempItem = tempItemList.FirstOrDefault(t => t.Title.Contains(KPISupplierReportShow.Key4));
if (tempItem != null)
{
rshow.Penalty4 = 0 - (tempItem.TargetScore - (tempItem.Score.HasValue ? tempItem.Score.Value : 0));
rshow.PenaltyRemark4 = tempItem.Reason;
}
//体系
tempItem = tempItemList.FirstOrDefault(t => t.Title.Contains(KPISupplierReportShow.Key5));
if (tempItem != null)
{
rshow.Penalty5 = 0 - (tempItem.TargetScore - (tempItem.Score.HasValue ? tempItem.Score.Value : 0));
rshow.PenaltyRemark5 = tempItem.Reason;
}
//成本
tempItem = tempItemList.FirstOrDefault(t => t.Title.Contains(KPISupplierReportShow.Key6));
if (tempItem != null)
{
rshow.Penalty6 = 0 - (tempItem.TargetScore - (tempItem.Score.HasValue ? tempItem.Score.Value : 0));
rshow.PenaltyRemark6 = tempItem.Reason;
}
//技术
tempItem = tempItemList.FirstOrDefault(t => t.Title.Contains(KPISupplierReportShow.Key7));
if (tempItem != null)
{
rshow.Penalty7 = 0 - (tempItem.TargetScore - (tempItem.Score.HasValue ? tempItem.Score.Value : 0));
rshow.PenaltyRemark7 = tempItem.Reason;
}
//----add by chenyuyi on 2018-09-10 begin----
//加分项
tempItem = tempItemList.FirstOrDefault(t => t.Title.Contains(KPISupplierReportShow.Key8));
if (tempItem != null)
{
rshow.Penalty8 = 0 - (tempItem.TargetScore - (tempItem.Score.HasValue ? tempItem.Score.Value : 0));
rshow.PenaltyRemark8 = tempItem.Reason;
}
//风险
tempItem = tempItemList.FirstOrDefault(t => t.Title.Contains(KPISupplierReportShow.Key9));
if (tempItem != null)
{
rshow.PenaltyRemark9 = tempItem.Reason;
}
//红线
tempItem = tempItemList.FirstOrDefault(t => t.Title.Contains(KPISupplierReportShow.Key10));
if (tempItem != null)
{
rshow.PenaltyRemark10 = tempItem.Reason;
}
//----add by chenyuyi on 2018-09-10 end----
reportList.Add(rshow);
}
return reportList;
}
}
相关推荐
大数据量CSV高效读取:从Pandas调优到DuckDB与Parquet实战
在大数据处理中,CSV文件因其简单通用成为数据交换的常见格式,但当文件体积达到GB级别时,传统的读取方式往往因内存溢出和类型推断开销而卡顿。理解CSV底层解析原理——字符解码、行列切割与类型推断,是进行性能优化的基础。通过合理选型,如使用Pandas的dtype指定、usecols裁剪、分块读取等手段,可显著降低内存占用;而面向分析场景时,DuckDB的列式向量化执行能秒级完成聚合查询,转Parquet格式可让重复读取速度提升数倍。这些技术广泛适用于日志分析、批量导入和数据分析等场景。本文从原理到实践,系统
本地文件转换工具“飞鼠格式”:能力边界、实操流程与许可证解读
文件格式转换是日常办公与开发中的高频需求,但云端转换工具常伴随上传延迟与隐私顾虑。基于本地处理理念的工具,将文件转换逻辑置于设备内部,不依赖网络传输,既提升了敏感数据的防护等级,也规避了文件大小限制。这类工具的能力边界通常受底层依赖库和本机硬件制约,合理设置并发参数与理解格式生态尤为关键。在实际工程中,Markdown转PDF、CSV与Excel互转等批量任务可借助命令行高效完成,同时需关注项目的开源许可证条款,避免商业集成时的合规风险。“飞鼠格式”正是此类本地转换工具的一个典型实现,本文围绕其能力、实操与
fengmian123
fengmian123
QYR-18900-2026-2032全球与中国智能旋转导向钻井系统市场现状及未来发展趋势 Sample-shijunzhong.docx
QYR-18900-2026-2032全球与中国智能旋转导向钻井系统市场现状及未来发展趋势 Sample-shijunzhong.docx
XERJ 是一款受到社区信赖的本地 AI 搜索引擎
XERJ 是一款受到社区信赖的本地 AI 搜索引擎,能自动为任意文件夹建立索引,让编程智能体直接检索所需代码,省去逐个读取文件消耗的 token。它的主要用途是参考现有实现来写代码(reference coding):接到任务后,智能体下载与任务相关的开源仓库,建立索引,再查阅这些项目的解决方法。 在一项对照研究中,这种做法让智能体的输出 token 用量降至原来的约 1/2.7,同时保持 16/16 的任务完成率(案例研究)。用户在日常开发中报告的用量约为原来的 1/5(使用反馈)。有了可检索的参考实现,较小、较便宜的模型也可能胜过只凭记忆工作的昂贵模型,减少反复修改的次数。把下面这段提示词交给智能体即可开始


