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.
129 lines
4.8 KiB
129 lines
4.8 KiB
using EFCore.BulkExtensions;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using System.Data.Common;
|
|
using TaskManager.Contracts.Dtos;
|
|
using TaskManager.Controllers;
|
|
using TaskManager.Entity;
|
|
using TaskManager.Entity.Entitys;
|
|
using TaskManager.EntityFramework;
|
|
using TaskManager.EntityFramework.Repository;
|
|
|
|
|
|
namespace TaskManager.Controllers
|
|
{
|
|
/// <summary>
|
|
/// 采购订单
|
|
/// </summary>
|
|
public class CherySupplierPoService : CheryRecurringJobOutPageController<SUPPLIER_PO, SUPPLIER_PO_DETAIL_DTO, SUPPLIER_PO_LOGS>
|
|
{
|
|
public CherySupplierPoService(HttpClient httpClient, JobDbContext jobDbContext, LogController log, IRepository<SUPPLIER_PO> repository) : base(httpClient, jobDbContext, log, repository)
|
|
{
|
|
}
|
|
protected override async Task ConfirmDataInsertAsync(List<SUPPLIER_PO> plist, JobDbContext dbContext, DbTransaction dbTransaction)
|
|
{
|
|
if (plist.Count > 0)
|
|
{
|
|
var requestDate= plist.FirstOrDefault().RequestDate;
|
|
//List<SUPPLIER_CON_PO> list = new List<SUPPLIER_CON_PO>();
|
|
//plist.ForEach(p =>
|
|
//{
|
|
// var con = new SUPPLIER_CON_PO();
|
|
// con.Id = p.Id;
|
|
|
|
// con.SupplierCode = "8EG";
|
|
// con.PurchaseOrder =p.PurchaseOrder ;
|
|
// con.SerialNumber =p.SerialNumber ;
|
|
// con.QuantityMeet =p.QuantityDelivery==null? p.QuantityDelivery.Value : 0 ;
|
|
// con.FeedbackResults ="0" ;
|
|
// con.VentureType ="" ;
|
|
// con.VentureSpecific ="" ;
|
|
// con.Measures ="";
|
|
|
|
// con.CreationTime = DateTime.Now;
|
|
|
|
|
|
// list.Add(con);
|
|
//});
|
|
//dbContext.BulkInsert(list);
|
|
|
|
var ids = plist.Select(p => p.Id);
|
|
var existList = await _jobDbContext.Set<SUPPLIER_CON_PO>().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.PurchaseOrder = first.PurchaseOrder;
|
|
itm.SerialNumber =first.SerialNumber;
|
|
itm.QuantityMeet = first.QuantityDelivery != null ? first.QuantityDelivery.Value : 0;
|
|
itm.FeedbackResults = "0";
|
|
itm.VentureType = "";
|
|
itm.VentureSpecific = "";
|
|
itm.Measures = "";
|
|
|
|
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_PO> list = new List<SUPPLIER_CON_PO>();
|
|
foreach (var p in query)
|
|
{
|
|
var con = new SUPPLIER_CON_PO();
|
|
con.Id = p.Id;
|
|
|
|
con.SupplierCode = "8EG";
|
|
con.PurchaseOrder = p.PurchaseOrder;
|
|
con.SerialNumber = p.SerialNumber;
|
|
con.QuantityMeet = p.QuantityDelivery != null ? p.QuantityDelivery.Value : 0;
|
|
con.FeedbackResults = "0";
|
|
con.VentureType = "";
|
|
con.VentureSpecific = "";
|
|
con.Measures = "";
|
|
con.CreationTime = DateTime.Now;
|
|
con.RequestDate=requestDate; ;
|
|
list.Add(con);
|
|
}
|
|
_jobDbContext.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;
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|