You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
248 lines
12 KiB
248 lines
12 KiB
using EFCore.BulkExtensions;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using OfficeOpenXml.FormulaParsing.Excel.Functions.Text;
|
|
using Omu.ValueInjecter;
|
|
using Org.BouncyCastle.Crypto;
|
|
using System.Collections.Generic;
|
|
using System.Data.Common;
|
|
using TaskManager.Contracts.Dtos;
|
|
using TaskManager.Controllers;
|
|
using TaskManager.Entity;
|
|
using TaskManager.Entity.Entitys;
|
|
using TaskManager.EntityFramework;
|
|
using TaskManager.EntityFramework;
|
|
using TaskManager.EntityFramework.Repository;
|
|
|
|
namespace TaskManager.Controllers
|
|
{
|
|
|
|
/// <summary>
|
|
/// 日物料需求计划
|
|
/// </summary>
|
|
public class CherySupplierMrpDataService : CheryRecurringJobOutPageController<SUPPLIER_MRP_DATE, SUPPLIER_MRP_DATE_DETAIL_DTO, SUPPLIER_MRP_DATE_LOGS>
|
|
{
|
|
public CherySupplierMrpDataService(HttpClient httpClient, JobDbContext jobDbContext, LogController log, IRepository<SUPPLIER_MRP_DATE> repository) : base(httpClient, jobDbContext, log, repository)
|
|
{
|
|
}
|
|
protected override async Task ConfirmDataInsertAsync(List<SUPPLIER_MRP_DATE> plist, JobDbContext dbContext, DbTransaction dbTransaction)
|
|
{
|
|
if (plist.Count > 0)
|
|
{
|
|
var requestDate = plist.First().RequestDate;
|
|
//List<SUPPLIER_CON_DATE> list = new List<SUPPLIER_CON_DATE>();
|
|
//plist.ForEach(p =>
|
|
//{
|
|
// var con = new SUPPLIER_CON_DATE();
|
|
|
|
// con.Id=p.Id;
|
|
// con.SupplierCode = "8EG";
|
|
// con.ReleaseEdition = p.ReleaseEdition;
|
|
// con.MaterialCode = p.MaterialCode;
|
|
// con.PlantId = p.PlantId;
|
|
// con.FeedbackResults = "0";
|
|
// con.VentureType = "";
|
|
// con.VentureSpecific = "";
|
|
// con.Measures = "";
|
|
// con.StartDate = p.StartDate;
|
|
// con.QuantityMeet1 =p.QuantityDemand1==null? p.QuantityDemand1.Value : 0 ;
|
|
// con.QuantityMeet2 = p.QuantityDemand2 == null ? p.QuantityDemand2.Value : 0;
|
|
// con.QuantityMeet3 =p.QuantityDemand3 ;
|
|
// con.QuantityMeet4 =p.QuantityDemand4 ;
|
|
// con.QuantityMeet5 =p.QuantityDemand5 ;
|
|
// con.QuantityMeet6 =p.QuantityDemand6 ;
|
|
// con.QuantityMeet7 =p.QuantityDemand7 ;
|
|
// con.QuantityMeet8 =p.QuantityDemand8 ;
|
|
// con.QuantityMeet9 =p.QuantityDemand9 ;
|
|
// con.QuantityMeet10 =p.QuantityDemand10 ;
|
|
// con.QuantityMeet11 =p.QuantityDemand11 ;
|
|
// con.QuantityMeet12 =p.QuantityDemand12 ;
|
|
// con.QuantityMeet13 =p.QuantityDemand13 ;
|
|
// con.QuantityMeet14 =p.QuantityDemand14 ;
|
|
// con.QuantityMeet15 =p.QuantityDemand15 ;
|
|
// con.QuantityMeet16 =p.QuantityDemand16 ;
|
|
// con.QuantityMeet17 =p.QuantityDemand17 ;
|
|
// con.QuantityMeet18 =p.QuantityDemand18 ;
|
|
// con.QuantityMeet19 =p.QuantityDemand19 ;
|
|
// con.QuantityMeet20 =p.QuantityDemand20 ;
|
|
// con.QuantityMeet21 =p.QuantityDemand21 ;
|
|
// con.QuantityMeet22 =p.QuantityDemand22 ;
|
|
// con.QuantityMeet23 =p.QuantityDemand23 ;
|
|
// con.QuantityMeet24 =p.QuantityDemand24 ;
|
|
// con.QuantityMeet25 =p.QuantityDemand25 ;
|
|
// con.QuantityMeet26 =p.QuantityDemand26 ;
|
|
// con.QuantityMeet27 =p.QuantityDemand27 ;
|
|
// con.QuantityMeet28 =p.QuantityDemand28 ;
|
|
// con.QuantityMeet29 =p.QuantityDemand29 ;
|
|
// con.QuantityMeet30 =p.QuantityDemand30 ;
|
|
// con.QuantityMeet31 = p.QuantityDemand31;
|
|
// con.CreationTime = DateTime.Now;
|
|
// list.Add(con);
|
|
//});
|
|
|
|
var ids=plist.Select(p => p.Id);
|
|
var existList = await _jobDbContext.Set<SUPPLIER_CON_DATE>().Where(p => ids.Contains(p.Id) && p.ReadState==false).ToListAsync();
|
|
if (existList.Any())
|
|
{
|
|
foreach (var itm in existList)
|
|
{
|
|
var first = plist.FirstOrDefault(p => p.Id == itm.Id);
|
|
if (first != null)
|
|
{
|
|
|
|
itm.Id = first.Id;
|
|
itm.SupplierCode = "8EG";
|
|
itm.ReleaseEdition = first.ReleaseEdition;
|
|
itm.MaterialCode = first.MaterialCode;
|
|
itm.PlantId = first.PlantId;
|
|
itm.FeedbackResults = "0";
|
|
itm.VentureType = "";
|
|
itm.VentureSpecific = "";
|
|
itm.Measures = "";
|
|
itm.StartDate = first.StartDate;
|
|
itm.QuantityMeet1 = first.QuantityDemand1 != null ? first.QuantityDemand1.Value : 0;
|
|
itm.QuantityMeet2 = first.QuantityDemand2 != null ? first.QuantityDemand2.Value : 0;
|
|
itm.QuantityMeet3 = first.QuantityDemand3;
|
|
itm.QuantityMeet4 = first.QuantityDemand4;
|
|
itm.QuantityMeet5 = first.QuantityDemand5;
|
|
itm.QuantityMeet6 = first.QuantityDemand6;
|
|
itm.QuantityMeet7 = first.QuantityDemand7;
|
|
itm.QuantityMeet8 = first.QuantityDemand8;
|
|
itm.QuantityMeet9 = first.QuantityDemand9;
|
|
itm.QuantityMeet10 = first.QuantityDemand10;
|
|
itm.QuantityMeet11 = first.QuantityDemand11;
|
|
itm.QuantityMeet12 = first.QuantityDemand12;
|
|
itm.QuantityMeet13 = first.QuantityDemand13;
|
|
itm.QuantityMeet14 = first.QuantityDemand14;
|
|
itm.QuantityMeet15 = first.QuantityDemand15;
|
|
itm.QuantityMeet16 = first.QuantityDemand16;
|
|
itm.QuantityMeet17 = first.QuantityDemand17;
|
|
itm.QuantityMeet18 = first.QuantityDemand18;
|
|
itm.QuantityMeet19 = first.QuantityDemand19;
|
|
itm.QuantityMeet20 = first.QuantityDemand20;
|
|
itm.QuantityMeet21 = first.QuantityDemand21;
|
|
itm.QuantityMeet22 = first.QuantityDemand22;
|
|
itm.QuantityMeet23 = first.QuantityDemand23;
|
|
itm.QuantityMeet24 = first.QuantityDemand24;
|
|
itm.QuantityMeet25 = first.QuantityDemand25;
|
|
itm.QuantityMeet26 = first.QuantityDemand26;
|
|
itm.QuantityMeet27 = first.QuantityDemand27;
|
|
itm.QuantityMeet28 = first.QuantityDemand28;
|
|
itm.QuantityMeet29 = first.QuantityDemand29;
|
|
itm.QuantityMeet30 = first.QuantityDemand30;
|
|
itm.QuantityMeet31 = first.QuantityDemand31;
|
|
itm.CreationTime = DateTime.Now;
|
|
itm.RequestDate = requestDate;
|
|
|
|
}
|
|
}
|
|
}
|
|
if(existList.Any())
|
|
{
|
|
_jobDbContext.BulkUpdate(existList.ToList());
|
|
}
|
|
|
|
var query = from item in plist
|
|
join existItem in existList
|
|
on item.Id equals existItem.Id into gj
|
|
from subItem in gj.DefaultIfEmpty()
|
|
where subItem == null
|
|
select item;
|
|
List < SUPPLIER_CON_DATE > list = new List<SUPPLIER_CON_DATE>();
|
|
foreach (var p in query)
|
|
{
|
|
var con = new SUPPLIER_CON_DATE();
|
|
|
|
con.Id = p.Id;
|
|
con.SupplierCode = "8EG";
|
|
con.ReleaseEdition = p.ReleaseEdition;
|
|
con.MaterialCode = p.MaterialCode;
|
|
con.PlantId = p.PlantId;
|
|
con.FeedbackResults = "0";
|
|
con.VentureType = "";
|
|
con.VentureSpecific = "";
|
|
con.Measures = "";
|
|
con.StartDate = p.StartDate;
|
|
con.QuantityMeet1 = p.QuantityDemand1 != null ? p.QuantityDemand1.Value : 0;
|
|
con.QuantityMeet2 = p.QuantityDemand2 != null ? p.QuantityDemand2.Value : 0;
|
|
con.QuantityMeet3 = p.QuantityDemand3;
|
|
con.QuantityMeet4 = p.QuantityDemand4;
|
|
con.QuantityMeet5 = p.QuantityDemand5;
|
|
con.QuantityMeet6 = p.QuantityDemand6;
|
|
con.QuantityMeet7 = p.QuantityDemand7;
|
|
con.QuantityMeet8 = p.QuantityDemand8;
|
|
con.QuantityMeet9 = p.QuantityDemand9;
|
|
con.QuantityMeet10 = p.QuantityDemand10;
|
|
con.QuantityMeet11 = p.QuantityDemand11;
|
|
con.QuantityMeet12 = p.QuantityDemand12;
|
|
con.QuantityMeet13 = p.QuantityDemand13;
|
|
con.QuantityMeet14 = p.QuantityDemand14;
|
|
con.QuantityMeet15 = p.QuantityDemand15;
|
|
con.QuantityMeet16 = p.QuantityDemand16;
|
|
con.QuantityMeet17 = p.QuantityDemand17;
|
|
con.QuantityMeet18 = p.QuantityDemand18;
|
|
con.QuantityMeet19 = p.QuantityDemand19;
|
|
con.QuantityMeet20 = p.QuantityDemand20;
|
|
con.QuantityMeet21 = p.QuantityDemand21;
|
|
con.QuantityMeet22 = p.QuantityDemand22;
|
|
con.QuantityMeet23 = p.QuantityDemand23;
|
|
con.QuantityMeet24 = p.QuantityDemand24;
|
|
con.QuantityMeet25 = p.QuantityDemand25;
|
|
con.QuantityMeet26 = p.QuantityDemand26;
|
|
con.QuantityMeet27 = p.QuantityDemand27;
|
|
con.QuantityMeet28 = p.QuantityDemand28;
|
|
con.QuantityMeet29 = p.QuantityDemand29;
|
|
con.QuantityMeet30 = p.QuantityDemand30;
|
|
con.QuantityMeet31 = p.QuantityDemand31;
|
|
con.CreationTime = DateTime.Now;
|
|
con.RequestDate = requestDate;
|
|
list.Add(con);
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
_jobDbContext.BulkInsert(list);
|
|
|
|
//else
|
|
//{
|
|
// existList = new List<SUPPLIER_CON_DATE>();
|
|
//}
|
|
|
|
//var query = from item in list
|
|
// join existItem in existList
|
|
// on item.Id equals existItem.Id into gj
|
|
// from subItem in gj.DefaultIfEmpty()
|
|
// where subItem == null
|
|
// select item;
|
|
//_jobDbContext.BulkUpdate(existList.ToList());
|
|
//_jobDbContext.BulkInsert(query.ToList());
|
|
|
|
|
|
|
|
|
|
|
|
//dbContext.BulkInsert(list);
|
|
|
|
//dbContext.BulkMerge(list,
|
|
// p=> p.Id,
|
|
// p=> p.ReadState
|
|
|
|
|
|
// );
|
|
|
|
//await dbContext.BulkMergeAsync(list, options => { options.Transaction = dbTransaction; options.UseTableLock = false;
|
|
|
|
// options.ColumnPrimaryKeyExpression = p =>new { p.Id, p.ReadState} ;
|
|
|
|
|
|
|
|
//});
|
|
}
|
|
return;
|
|
}
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|