|
|
@ -1,4 +1,6 @@ |
|
|
|
|
|
|
|
using System.Collections.Generic; |
|
|
|
using System.Linq; |
|
|
|
using System.Threading.Tasks; |
|
|
|
using Microsoft.EntityFrameworkCore; |
|
|
|
using Volo.Abp.EntityFrameworkCore; |
|
|
@ -13,66 +15,201 @@ public class KittingEfCoreRepository : SfsBaseDataEfCoreRepositoryBase<BasedataD |
|
|
|
{ |
|
|
|
} |
|
|
|
|
|
|
|
public virtual async Task UpsertAsync(Kitting entity) |
|
|
|
public virtual async Task UpsertAsync(Kitting newData) |
|
|
|
{ |
|
|
|
var main=DbContext.Set<Kitting>(); |
|
|
|
var detail=DbContext.Set<KittingDetail>(); |
|
|
|
|
|
|
|
var dbSet = await GetDbSetAsync().ConfigureAwait(false); |
|
|
|
var exist = await dbSet.FirstOrDefaultAsync(p => p.Code == entity.Code).ConfigureAwait(false); |
|
|
|
|
|
|
|
|
|
|
|
var exist = await main.FirstOrDefaultAsync(p => p.Code == newData.Code).ConfigureAwait(false); |
|
|
|
if (exist == null) |
|
|
|
{ |
|
|
|
var insRet = await InsertAsync(entity).ConfigureAwait(false); |
|
|
|
newData.SetId(GuidGenerator.Create()); |
|
|
|
await InsertAsync(newData).ConfigureAwait(false); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
var detailList= detail.Where(p => p.MasterId == exist.Id).ToList(); |
|
|
|
|
|
|
|
var left=from itm in newData.Details join itm1 in detailList on |
|
|
|
itm.PartCode equals itm1.PartCode |
|
|
|
into temp |
|
|
|
from tm in temp.DefaultIfEmpty() |
|
|
|
where tm == null |
|
|
|
select itm; |
|
|
|
var inner = from itm in detailList |
|
|
|
join itm1 in newData.Details on |
|
|
|
itm.PartCode equals itm1.PartCode |
|
|
|
select itm1; |
|
|
|
//await detail.AddRangeAsync(left.ToList()).ConfigureAwait(false);
|
|
|
|
|
|
|
|
List<KittingDetail> insert = new List<KittingDetail>(); |
|
|
|
List<KittingDetail> update = new List<KittingDetail>(); |
|
|
|
foreach (var itm in inner.ToList()) |
|
|
|
{ |
|
|
|
var first=newData.Details.FirstOrDefault(p=>p.PartCode==itm.PartCode); |
|
|
|
itm.Qty = first.Qty; |
|
|
|
itm.Desc1= first.Desc1; |
|
|
|
itm.Desc2=first.Desc2; |
|
|
|
update.Add(itm); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
foreach (var itm in left.ToList()) |
|
|
|
{ |
|
|
|
itm.SetId(GuidGenerator.Create()); |
|
|
|
itm.MasterId = exist.Id; |
|
|
|
insert.Add(itm); |
|
|
|
} |
|
|
|
|
|
|
|
detail.AddRange(insert.ToArray()); |
|
|
|
|
|
|
|
detail.UpdateRange(update.ToArray()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DbContext.SaveChanges(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//exist.Code = entity.Code;
|
|
|
|
exist.Name = entity.Name; |
|
|
|
//exist.Address = entity.Address;
|
|
|
|
//exist.Country = entity.Country;
|
|
|
|
//exist.City = entity.City;
|
|
|
|
//exist.Phone = entity.Phone;
|
|
|
|
//exist.Fax = entity.Fax;
|
|
|
|
//exist.PostID = entity.PostID;
|
|
|
|
//exist.Contacts = entity.Contacts;
|
|
|
|
//exist.Currency = entity.Currency;
|
|
|
|
//exist.IsActive = entity.IsActive;
|
|
|
|
//exist.Type = entity.Type;
|
|
|
|
exist.TenantId = entity.TenantId; |
|
|
|
exist.Remark = entity.Remark; |
|
|
|
//foreach (var itm in detail)
|
|
|
|
//{
|
|
|
|
// var existDetail =
|
|
|
|
// detailList.FirstOrDefault(p => p.PartCode == newDetail.PartCode);
|
|
|
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
|
|
//detailRep.Where(p=>p.PartCode==);
|
|
|
|
|
|
|
|
|
|
|
|
//exist.Name = newData.Name;
|
|
|
|
|
|
|
|
//UpsertDetail(newData, exist);
|
|
|
|
|
|
|
|
//await UpdateAsync(exist).ConfigureAwait(false);
|
|
|
|
} |
|
|
|
// var context = await GetDbContextAsync();
|
|
|
|
// await context.SingleMergeAsync(entity, options =>
|
|
|
|
// {
|
|
|
|
// //业务主键,可以是联合主键
|
|
|
|
// options.ColumnPrimaryKeyExpression = c => new
|
|
|
|
// {
|
|
|
|
// c.Company,
|
|
|
|
// c.Code
|
|
|
|
// };
|
|
|
|
// //需要在更新时忽略的属性
|
|
|
|
// options.IgnoreOnMergeUpdateExpression = c => new
|
|
|
|
// {
|
|
|
|
// c.Id,
|
|
|
|
// };
|
|
|
|
// });
|
|
|
|
} |
|
|
|
|
|
|
|
//private void UpsertDetail(List<KittingDetail> newData, List<KittingDetail> exist)
|
|
|
|
//{
|
|
|
|
// foreach (var newDetail in newData)
|
|
|
|
// {
|
|
|
|
// var existDetail =
|
|
|
|
// exist.FirstOrDefault(p =>p.PartCode==newDetail.PartCode);
|
|
|
|
// if (existDetail == null)
|
|
|
|
// {
|
|
|
|
// newDetail.SetId(GuidGenerator.Create());
|
|
|
|
// newDetail.MasterId = exist.Id;
|
|
|
|
// exist.Details.Add(newDetail);
|
|
|
|
// }
|
|
|
|
// else
|
|
|
|
// {
|
|
|
|
// existDetail.Desc1= newDetail.Desc1;
|
|
|
|
// existDetail.Desc2= newDetail.Desc2;
|
|
|
|
// existDetail.Qty= newDetail.Qty;
|
|
|
|
// existDetail.Remark= newDetail.Remark;
|
|
|
|
|
|
|
|
// //existDetail.SupplierPackUom = newDetail.SupplierPackUom;
|
|
|
|
// //existDetail.SupplierPackQty = newDetail.SupplierPackQty;
|
|
|
|
// //existDetail.ConvertRate = newDetail.ConvertRate;
|
|
|
|
// //existDetail.IsConsignment = newDetail.IsConsignment;
|
|
|
|
// //existDetail.LineStatus = newDetail.LineStatus;
|
|
|
|
// //existDetail.Uom = newDetail.Uom;
|
|
|
|
// //existDetail.Qty = newDetail.Qty;
|
|
|
|
// //existDetail.StdPackQty = newDetail.StdPackQty;
|
|
|
|
// //existDetail.ItemName = newDetail.ItemName;
|
|
|
|
// //existDetail.ItemDesc1 = newDetail.ItemDesc1;
|
|
|
|
// //existDetail.ItemDesc2 = newDetail.ItemDesc2;
|
|
|
|
// //existDetail.ItemCode = newDetail.ItemCode;
|
|
|
|
// //existDetail.Remark = newDetail.Remark;
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
//}
|
|
|
|
|
|
|
|
public virtual async Task UpsertAsyncByInterface(Kitting entity) |
|
|
|
{ |
|
|
|
//var dbSet = await GetDbSetAsync().ConfigureAwait(false);
|
|
|
|
//var exist = await dbSet.FirstOrDefaultAsync(p => p.Code == entity.Code).ConfigureAwait(false);
|
|
|
|
//if (exist == null)
|
|
|
|
//{
|
|
|
|
// var insRet = await InsertAsync(entity).ConfigureAwait(false);
|
|
|
|
//}
|
|
|
|
//else
|
|
|
|
//{
|
|
|
|
// exist.Name = entity.Name;
|
|
|
|
// exist.ShortName = entity.ShortName;
|
|
|
|
// exist.LastModificationTime = DateTime.Now;
|
|
|
|
//}
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//public virtual async Task UpsertAsync(Kitting entity)
|
|
|
|
//{
|
|
|
|
// var dbSet = await GetDbSetAsync().ConfigureAwait(false);
|
|
|
|
// var exist = await dbSet.FirstOrDefaultAsync(p => p.Code == entity.Code).ConfigureAwait(false);
|
|
|
|
// if (exist == null)
|
|
|
|
// {
|
|
|
|
// var insRet = await InsertAsync(entity).ConfigureAwait(false);
|
|
|
|
// }
|
|
|
|
// else
|
|
|
|
// {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// //exist.Code = entity.Code;
|
|
|
|
// exist.Name = entity.Name;
|
|
|
|
// //exist.Address = entity.Address;
|
|
|
|
// //exist.Country = entity.Country;
|
|
|
|
// //exist.City = entity.City;
|
|
|
|
// //exist.Phone = entity.Phone;
|
|
|
|
// //exist.Fax = entity.Fax;
|
|
|
|
// //exist.PostID = entity.PostID;
|
|
|
|
// //exist.Contacts = entity.Contacts;
|
|
|
|
// //exist.Currency = entity.Currency;
|
|
|
|
// //exist.IsActive = entity.IsActive;
|
|
|
|
// //exist.Type = entity.Type;
|
|
|
|
// exist.TenantId = entity.TenantId;
|
|
|
|
// exist.Remark = entity.Remark;
|
|
|
|
|
|
|
|
// }
|
|
|
|
// // var context = await GetDbContextAsync();
|
|
|
|
// // await context.SingleMergeAsync(entity, options =>
|
|
|
|
// // {
|
|
|
|
// // //业务主键,可以是联合主键
|
|
|
|
// // options.ColumnPrimaryKeyExpression = c => new
|
|
|
|
// // {
|
|
|
|
// // c.Company,
|
|
|
|
// // c.Code
|
|
|
|
// // };
|
|
|
|
// // //需要在更新时忽略的属性
|
|
|
|
// // options.IgnoreOnMergeUpdateExpression = c => new
|
|
|
|
// // {
|
|
|
|
// // c.Id,
|
|
|
|
// // };
|
|
|
|
// // });
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
|
|
//public virtual async Task UpsertAsyncByInterface(Kitting entity)
|
|
|
|
//{
|
|
|
|
// //var dbSet = await GetDbSetAsync().ConfigureAwait(false);
|
|
|
|
// //var exist = await dbSet.FirstOrDefaultAsync(p => p.Code == entity.Code).ConfigureAwait(false);
|
|
|
|
// //if (exist == null)
|
|
|
|
// //{
|
|
|
|
// // var insRet = await InsertAsync(entity).ConfigureAwait(false);
|
|
|
|
// //}
|
|
|
|
// //else
|
|
|
|
// //{
|
|
|
|
// // exist.Name = entity.Name;
|
|
|
|
// // exist.ShortName = entity.ShortName;
|
|
|
|
// // exist.LastModificationTime = DateTime.Now;
|
|
|
|
// //}
|
|
|
|
//}
|
|
|
|
} |
|
|
|