|
|
@ -1,19 +1,29 @@ |
|
|
|
using System; |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.ComponentModel.DataAnnotations; |
|
|
|
using System.IO; |
|
|
|
using System.Linq; |
|
|
|
using System.Threading.Tasks; |
|
|
|
using EFCore.BulkExtensions; |
|
|
|
using Microsoft.AspNetCore.Authorization; |
|
|
|
using Microsoft.AspNetCore.Http; |
|
|
|
using Microsoft.AspNetCore.Mvc; |
|
|
|
using Microsoft.EntityFrameworkCore; |
|
|
|
using NUglify.Helpers; |
|
|
|
using Omu.ValueInjecter; |
|
|
|
using Volo.Abp; |
|
|
|
using Volo.Abp.Caching; |
|
|
|
using Volo.Abp.Domain.Entities; |
|
|
|
using Volo.Abp.Domain.Repositories; |
|
|
|
using Volo.Abp.ObjectMapping; |
|
|
|
using Volo.Abp.Uow; |
|
|
|
using Win_in.Sfs.Basedata.Application.Contracts; |
|
|
|
using Win_in.Sfs.Basedata.Domain; |
|
|
|
using Win_in.Sfs.Basedata.Domain.Shared; |
|
|
|
using Win_in.Sfs.Basedata.Kittings.Inputs; |
|
|
|
using Win_in.Sfs.Shared; |
|
|
|
using Win_in.Sfs.Shared.Application.Contracts; |
|
|
|
using Win_in.Sfs.Shared.Application.Contracts.ExportAndImport; |
|
|
|
|
|
|
|
|
|
|
|
namespace Win_in.Sfs.Basedata.Application; |
|
|
@ -25,13 +35,15 @@ public class KittingAppService : SfsBaseDataWithCodeAppServiceBase<Kitting, Kitt |
|
|
|
{ |
|
|
|
private new readonly IKittingRepository _repository; |
|
|
|
|
|
|
|
|
|
|
|
private readonly IExportImportService _excelService; |
|
|
|
|
|
|
|
private readonly IKittingManager _manager; |
|
|
|
|
|
|
|
public KittingAppService(IKittingRepository repository, IDistributedCache<KittingDTO> cache, IKittingManager manager) : base(repository,cache) |
|
|
|
public KittingAppService(IKittingRepository repository, IDistributedCache<KittingDTO> cache, IKittingManager manager, IExportImportService excelService) : base(repository,cache) |
|
|
|
{ |
|
|
|
_repository = repository; |
|
|
|
_manager = manager; |
|
|
|
_excelService = excelService; |
|
|
|
//base.CreatePolicyName = KittingPermissions.Create;
|
|
|
|
//base.UpdatePolicyName = KittingPermissions.Update;
|
|
|
|
//base.DeletePolicyName = KittingPermissions.Delete;
|
|
|
@ -62,7 +74,6 @@ public class KittingAppService : SfsBaseDataWithCodeAppServiceBase<Kitting, Kitt |
|
|
|
// first.AddDetails(itm);
|
|
|
|
//}
|
|
|
|
//var entity= await _repository.UpdateAsync(first).ConfigureAwait(false);
|
|
|
|
|
|
|
|
//return ObjectMapper.Map<Kitting, KittingDTO>(entity);
|
|
|
|
} |
|
|
|
else |
|
|
@ -98,23 +109,13 @@ public class KittingAppService : SfsBaseDataWithCodeAppServiceBase<Kitting, Kitt |
|
|
|
//var ids=input.Details.Select(p => p.Id);
|
|
|
|
//first.Details.Where(p =>ids.Contains(p.Id));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return base.UpdateAsync(id, input); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//var entity = ObjectMapper.Map<KittingEditInput, Kitting>(input);
|
|
|
|
////entity.SetId(id);
|
|
|
|
////entity.Code = first.Code;
|
|
|
|
//await _repository.UpsertAsync(entity).ConfigureAwait(false);
|
|
|
|
//var firstEntity = detailquery.FirstOrDefault(p => p.Id == id);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//return ObjectMapper.Map<Kitting, KittingDTO>(first);
|
|
|
|
|
|
|
|
|
|
|
@ -139,11 +140,208 @@ public class KittingAppService : SfsBaseDataWithCodeAppServiceBase<Kitting, Kitt |
|
|
|
{ |
|
|
|
var entity = ObjectMapper.Map<KittingEditInput, Kitting>(input); |
|
|
|
await _repository.UpsertAsync(entity).ConfigureAwait(false); |
|
|
|
} |
|
|
|
[HttpPost("import")] |
|
|
|
[Consumes("multipart/form-data")] |
|
|
|
|
|
|
|
public override async Task<IActionResult> ImportAsync([FromForm] SfsImportRequestInput requestInput, [Required] IFormFile file) |
|
|
|
{ |
|
|
|
var query= _repository.WithDetails().AsNoTracking(); |
|
|
|
using var ms = new MemoryStream(); |
|
|
|
await file.OpenReadStream().CopyToAsync(ms).ConfigureAwait(false); |
|
|
|
var inputFileBytes = ms.GetAllBytes(); |
|
|
|
var importList= _excelService.Import<KittingImportInput>(inputFileBytes).ToList(); |
|
|
|
var checklist=importList.GroupBy(p => new { p.Code, p.PartCode }).Where(g => g.Count() > 1).Select(p => new { Code = p.Key.Code, PartCode = p.Key.PartCode });//导入重复报错
|
|
|
|
//检测是否导入重复
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var codeList=importList.Select(p=>p.Code).Distinct().ToList(); |
|
|
|
var includeList = query.Where(p => codeList.Contains(p.Code)).ToList(); |
|
|
|
var existCodeList = includeList.Select(p => p.Code).ToList(); |
|
|
|
var newCodeList = from itm in codeList |
|
|
|
join itm1 in existCodeList on itm equals itm1 |
|
|
|
into temp |
|
|
|
from tm in temp.DefaultIfEmpty() |
|
|
|
where tm == null |
|
|
|
select itm; |
|
|
|
if(newCodeList.Any()) |
|
|
|
{ |
|
|
|
#region 新KITTING
|
|
|
|
var newKittingList = importList.Where(p => newCodeList.Contains(p.Code)).ToList();//新Kitting
|
|
|
|
List<KittingEditInput> newKittingInputList = new List<KittingEditInput>(); |
|
|
|
List<Kitting> newMainList = new List<Kitting>(); |
|
|
|
List<KittingDetail> newdetailList = new List<KittingDetail>(); |
|
|
|
foreach (var itm in newCodeList) |
|
|
|
{ |
|
|
|
var newDetail = newKittingList.Where(p => p.Code == itm).ToList(); |
|
|
|
var first = newDetail.FirstOrDefault(); |
|
|
|
var kitting = new KittingEditInput(); |
|
|
|
kitting.InjectFrom(first); |
|
|
|
foreach (var detail in newDetail) |
|
|
|
{ |
|
|
|
var inputdetail = new KittingDetailInput(); |
|
|
|
inputdetail.InjectFrom(detail); |
|
|
|
kitting.Details.Add(inputdetail); |
|
|
|
} |
|
|
|
newKittingInputList.Add(kitting); |
|
|
|
} |
|
|
|
var kittingList = ObjectMapper.Map<List<KittingEditInput>, List<Kitting>>(newKittingInputList); |
|
|
|
foreach (var itm in kittingList) |
|
|
|
{ |
|
|
|
var id = Guid.NewGuid(); |
|
|
|
itm.SetId(id); |
|
|
|
//newMainList.Add(itm);
|
|
|
|
foreach (var detail in itm.Details) |
|
|
|
{ |
|
|
|
detail.SetId(Guid.NewGuid()); |
|
|
|
detail.MasterId = id; |
|
|
|
//newdetailList.Add(detail);
|
|
|
|
} |
|
|
|
} |
|
|
|
await _repository.InsertManyAsync(kittingList).ConfigureAwait(false); |
|
|
|
|
|
|
|
//await _repository.GetDbContext().BulkInsertAsync(newMainList).ConfigureAwait(false);
|
|
|
|
//await _repository.GetDbContext().BulkInsertAsync<KittingDetail>(newdetailList).ConfigureAwait(false);
|
|
|
|
#endregion
|
|
|
|
} |
|
|
|
if (existCodeList.Any()) |
|
|
|
{ |
|
|
|
var existKittingList = importList.Where(p => existCodeList.Contains(p.Code)).ToList();//新Kitting
|
|
|
|
List<KittingEditInput> existKittingInputList = new List<KittingEditInput>(); |
|
|
|
List<KittingDetail> existKittingDetailList = new List<KittingDetail>(); |
|
|
|
List<KittingDetail> newKittingDetailList = new List<KittingDetail>(); |
|
|
|
foreach (var include in includeList) |
|
|
|
{ |
|
|
|
var newDetail = existKittingList.Where(p => p.Code == include.Code).ToList(); |
|
|
|
var innerExist = from itm in newDetail |
|
|
|
join itm1 in include.Details on itm.PartCode equals itm1.PartCode |
|
|
|
select itm; |
|
|
|
if (innerExist.Any()) |
|
|
|
{ |
|
|
|
var list = innerExist.ToList(); |
|
|
|
foreach (var itm in include.Details) |
|
|
|
{ |
|
|
|
var entity = list.FirstOrDefault(p => p.PartCode == itm.PartCode); |
|
|
|
itm.Desc1 = entity.Desc1; |
|
|
|
itm.Desc2 = entity.Desc2; |
|
|
|
itm.Qty = entity.Qty; |
|
|
|
itm.Conf = entity.Conf; |
|
|
|
//existKittingDetailList.Add(itm);
|
|
|
|
} |
|
|
|
} |
|
|
|
//var leftExist = from itm in newDetail
|
|
|
|
// join itm1 in include.Details on itm.PartCode equals itm1.PartCode
|
|
|
|
// into temp
|
|
|
|
// from tm in temp.DefaultIfEmpty()
|
|
|
|
// where tm == null
|
|
|
|
// select itm;
|
|
|
|
//if (leftExist.Any())
|
|
|
|
//{
|
|
|
|
// var list = leftExist.ToList();
|
|
|
|
// foreach (var itm in list)
|
|
|
|
// {
|
|
|
|
// var detail = new KittingDetail();
|
|
|
|
// detail.InjectFrom(itm);
|
|
|
|
// detail.SetId(Guid.NewGuid());
|
|
|
|
// detail.MasterId = include.Id;
|
|
|
|
// //newKittingDetailList.Add(detail);
|
|
|
|
|
|
|
|
// }
|
|
|
|
//}
|
|
|
|
|
|
|
|
//var entity = new KittingEditInput();
|
|
|
|
//entity.InjectFrom(include);
|
|
|
|
|
|
|
|
//foreach (var detail in include.Details)
|
|
|
|
//{
|
|
|
|
// var detailInput = new KittingDetailInput();
|
|
|
|
// detailInput.InjectFrom(detail);
|
|
|
|
// entity.Details.Add(detailInput);
|
|
|
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
//var newDetail = existKittingList.Where(p => p.Code == entity.Code).ToList();
|
|
|
|
//var innerExist = from itm in newDetail
|
|
|
|
// join itm1 in entity.Details on itm.PartCode equals itm1.PartCode
|
|
|
|
// select itm;
|
|
|
|
//if (innerExist.Any())
|
|
|
|
//{
|
|
|
|
// var list = innerExist.ToList();
|
|
|
|
// foreach (var itm in entity.Details)
|
|
|
|
// {
|
|
|
|
// var l = list.FirstOrDefault(p => p.PartCode == itm.PartCode);
|
|
|
|
// itm.Desc1 = l.Desc1;
|
|
|
|
// itm.Desc2 = l.Desc2;
|
|
|
|
// itm.Qty = l.Qty;
|
|
|
|
// itm.Conf = l.Conf;
|
|
|
|
// }
|
|
|
|
//}
|
|
|
|
//var leftExist = from itm in newDetail
|
|
|
|
// join itm1 in entity.Details on itm.PartCode equals itm1.PartCode
|
|
|
|
// into temp
|
|
|
|
// from tm in temp.DefaultIfEmpty()
|
|
|
|
// where tm == null
|
|
|
|
// select itm;
|
|
|
|
//if (leftExist.Any())
|
|
|
|
//{
|
|
|
|
// var list = leftExist.ToList();
|
|
|
|
// foreach (var itm in list)
|
|
|
|
// {
|
|
|
|
// var detail = new KittingDetailInput();
|
|
|
|
// detail.InjectFrom(itm);
|
|
|
|
// detail.Id = Guid.NewGuid();
|
|
|
|
// detail.MasterId = entity.Id;
|
|
|
|
// entity.Details.Add(detail);
|
|
|
|
|
|
|
|
// }
|
|
|
|
//}
|
|
|
|
//existKittingInputList.Add(entity);
|
|
|
|
} |
|
|
|
|
|
|
|
// List<Kitting> list1 = new List<Kitting>();
|
|
|
|
// foreach (var itm in existKittingInputList)
|
|
|
|
// {
|
|
|
|
// Kitting kitting = new Kitting();
|
|
|
|
// kitting.InjectFrom(itm);
|
|
|
|
// kitting.SetId(itm.Id);
|
|
|
|
// foreach (var detail in itm.Details)
|
|
|
|
// {
|
|
|
|
// KittingDetail kittingDetail = new KittingDetail();
|
|
|
|
// kittingDetail.InjectFrom(detail);
|
|
|
|
// kittingDetail.SetId(detail.Id);
|
|
|
|
// kitting.AddDetails(kittingDetail);
|
|
|
|
// }
|
|
|
|
// list1.Add(kitting);
|
|
|
|
|
|
|
|
// }
|
|
|
|
//var details= list1.Select(p => p.Details).ToList();
|
|
|
|
|
|
|
|
|
|
|
|
// //await _repository.GetDbContext().BulkInsertAsync(newKittingDetailList).ConfigureAwait(continueOnCapturedContext: false);
|
|
|
|
// //await _repository.GetDbContext().BulkUpdateAsync(existKittingDetailList).ConfigureAwait(continueOnCapturedContext: false);
|
|
|
|
// // var ls= ObjectMapper.Map< List<KittingEditInput> ,List <Kitting>>(existKittingInputList);
|
|
|
|
|
|
|
|
|
|
|
|
// //await _repository.UpdateManyAsync(list1,true).ConfigureAwait(continueOnCapturedContext: false);
|
|
|
|
|
|
|
|
|
|
|
|
// await _manager.ImportDataAsync(includeList).ConfigureAwait(false);
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return new JsonResult(new { Code = 200, Message = "" }); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected override async Task<KittingDTO> GetFromRepositoryAsync(string code) |
|
|
|