diff --git a/DOAN.Service/MES/product/ProweekplanManageService.cs b/DOAN.Service/MES/product/ProweekplanManageService.cs
index 3f77591..0ed9d60 100644
--- a/DOAN.Service/MES/product/ProweekplanManageService.cs
+++ b/DOAN.Service/MES/product/ProweekplanManageService.cs
@@ -337,7 +337,7 @@ namespace DOAN.Service.MES.product
}
}
const int BATCH_SIZE = 500;
-
+
///
/// 处理一行Excel数据
///
@@ -554,37 +554,52 @@ namespace DOAN.Service.MES.product
public int UpdateActualAssemblyProgress(int year, int week)
{
+ int result = 0;
//获取周的日期开始到结束
- DateTime? WeekStartDate = Context.Queryable()
- .Where(it => it.FkWeeklyId == SqlFunc.Subqueryable().Where(s => s.PlanWeek == week && s.PlanYear == year).Select(s => s.Id))
- .Where(it => it.DayOfWeek == "星期一")
- .Select(it => it.WeekDate)
- .First();
-
- DateTime? WeekEndDate = Context.Queryable()
- .Where(it => it.FkWeeklyId == SqlFunc.Subqueryable().Where(s => s.PlanWeek == week && s.PlanYear == year).Select(s => s.Id))
- .Where(it => it.DayOfWeek == "星期日")
- .Select(it => it.WeekDate)
- .First();
-
+ var WeekStartAndEnd = Context.Queryable().Where(it => it.PlanYear == year && it.PlanWeek == week)
+ .Select(it => new { it.PlanStartDate, it.PlanEndDate }).First();
+ DateTime WeekStartDate = WeekStartAndEnd.PlanStartDate;
+ DateTime WeekEndDate = WeekStartAndEnd.PlanEndDate;
//
if (WeekStartDate == null && WeekEndDate == null)
{
- Context
- .Queryable()
- .LeftJoin((w, r) => w.Id == r.Id)
- .Where((w, r) => w.WorkorderDate >= WeekStartDate && w.WorkorderDate <= WeekEndDate)
- .GroupBy(it => new { it.ProductionCode, it.Specification })
- .Select(it => new
- {
- it.ProductionCode,
- it.Specification,
- TotalDeliveryNum = SqlFunc.AggregateSum(it.DeliveryNum)
- }).ToList();
+ List proWeeklyPlans = Context.Queryable().Where(it => it.PlanYear == year && it.PlanWeek == week).ToList();
+
+ if (proWeeklyPlans.Count > 0)
+ {
+ foreach (var plan in proWeeklyPlans)
+ {
+ //计算实际装配数
+ var workorderData = Context
+ .Queryable()
+ .LeftJoin((w, r) => w.Id == r.Id)
+ .Where((w, r) => w.WorkorderDate >= WeekStartDate && w.WorkorderDate <= WeekEndDate && w.ProductionCode == plan.ProductCode && w.Specification == plan.Specification)
+ .GroupBy(it => new { it.ProductionCode, it.Specification })
+ .Select(it => new
+ {
+ it.ProductionCode,
+ it.Specification,
+ TotalDeliveryNum = SqlFunc.AggregateSum(it.DeliveryNum)
+ }).First();
+ if (workorderData != null)
+ {
+ plan.CompletedQty = workorderData.TotalDeliveryNum ?? 0;
+ plan.RemainingQty = plan.PlanQty - plan.CompletedQty;
+ plan.UpdatedBy = "system";
+ plan.UpdatedTime = DateTime.Now;
+ result+= Context.Updateable(plan).ExecuteCommand();
+ }
+ }
+
+
+
+ }
+
+
}
- return 0;
+ return result;
}
@@ -694,6 +709,7 @@ namespace DOAN.Service.MES.product
Id = SnowFlakeSingle.Instance.NextId().ToString(),
Workorder = string.Empty,
ProductionCode = item.ProductCode,
+ ProductionName = item.ProductName,
Specification = item.Specification,
DeliveryNum = item.PlanNum
};
@@ -736,16 +752,16 @@ namespace DOAN.Service.MES.product
{
IRow dataRow = sheet.GetRow(dataRowIndex) ?? sheet.CreateRow(dataRowIndex);
dataRow.CreateCell(0).SetCellValue(item.ProductionCode); // A列
- dataRow.CreateCell(1).SetCellValue(item.Workorder); // B列
+ dataRow.CreateCell(1).SetCellValue(item.ProductionName); // B列
dataRow.CreateCell(2).SetCellValue(item.Specification); // C列
- dataRow.CreateCell(3).SetCellValue((double)item.DeliveryNum); // D列
+ dataRow.CreateCell(4).SetCellValue((double)item.DeliveryNum); // D列
dataRowIndex++;
}
// 7. 写入到 MemoryStream(关键:不要用 using 包裹,否则流会被释放!)
var memoryStream = new MemoryStream();
workbook.Write(memoryStream);
-
+
// 8. 返回 byte[] 和文件名
return (memoryStream.ToArray(), "导出数据.xlsx");