更新数据
This commit is contained in:
parent
0d454a2046
commit
f0347efc9c
@ -337,7 +337,7 @@ namespace DOAN.Service.MES.product
|
||||
}
|
||||
}
|
||||
const int BATCH_SIZE = 500;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 处理一行Excel数据
|
||||
/// </summary>
|
||||
@ -554,37 +554,52 @@ namespace DOAN.Service.MES.product
|
||||
|
||||
public int UpdateActualAssemblyProgress(int year, int week)
|
||||
{
|
||||
int result = 0;
|
||||
//获取周的日期开始到结束
|
||||
DateTime? WeekStartDate = Context.Queryable<ProWeeklyDate>()
|
||||
.Where(it => it.FkWeeklyId == SqlFunc.Subqueryable<ProWeeklyPlan>().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<ProWeeklyDate>()
|
||||
.Where(it => it.FkWeeklyId == SqlFunc.Subqueryable<ProWeeklyPlan>().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<ProWeeklyPlan>().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<ProWorkorder>()
|
||||
.LeftJoin<ProReportwork>((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<ProWeeklyPlan> proWeeklyPlans = Context.Queryable<ProWeeklyPlan>().Where(it => it.PlanYear == year && it.PlanWeek == week).ToList();
|
||||
|
||||
if (proWeeklyPlans.Count > 0)
|
||||
{
|
||||
foreach (var plan in proWeeklyPlans)
|
||||
{
|
||||
//计算实际装配数
|
||||
var workorderData = Context
|
||||
.Queryable<ProWorkorder>()
|
||||
.LeftJoin<ProReportwork>((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");
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user