|
|
@ -4,6 +4,8 @@ using System.ComponentModel.DataAnnotations; |
|
|
|
using System.IO; |
|
|
|
using System.Linq; |
|
|
|
using System.Threading.Tasks; |
|
|
|
using DocumentFormat.OpenXml.Bibliography; |
|
|
|
using DocumentFormat.OpenXml.Office2016.Excel; |
|
|
|
using Microsoft.AspNetCore.Http; |
|
|
|
using Microsoft.AspNetCore.Mvc; |
|
|
|
using Microsoft.EntityFrameworkCore; |
|
|
@ -82,7 +84,6 @@ public class UnplannedIssueRequestForDongyangAppService : UnplannedIssueRequestA |
|
|
|
entity.AutoAgree = true; |
|
|
|
entity.AutoHandle = true; |
|
|
|
entity.DirectCreateNote = false; |
|
|
|
|
|
|
|
|
|
|
|
await _unplannedIssueRequestManager.CreateAsync(entity).ConfigureAwait(false); |
|
|
|
|
|
|
@ -96,55 +97,98 @@ public class UnplannedIssueRequestForDongyangAppService : UnplannedIssueRequestA |
|
|
|
/// <param name="file"></param>
|
|
|
|
/// <returns></returns>
|
|
|
|
/// <exception cref="UserFriendlyException"></exception>
|
|
|
|
[HttpPost("import-dongyang")] |
|
|
|
public async Task<IActionResult> ImportDYAsync([FromForm] SfsImportRequestInput requestInput, [Required] IFormFile file) |
|
|
|
{ |
|
|
|
|
|
|
|
try |
|
|
|
{ |
|
|
|
//[HttpPost("import-dongyang")]
|
|
|
|
//public async Task<IActionResult> ImportDYAsync([FromForm] SfsImportRequestInput requestInput, [Required] IFormFile file)
|
|
|
|
//{
|
|
|
|
// try
|
|
|
|
// {
|
|
|
|
// using var ms = new MemoryStream();
|
|
|
|
// await file.OpenReadStream().CopyToAsync(ms).ConfigureAwait(false);
|
|
|
|
// var inputFileBytes = ms.GetAllBytes();
|
|
|
|
// var importList = _excelService.Import<UnplannedIssueRequestImportDto>(inputFileBytes).ToList();
|
|
|
|
// await CreateByDYOAsync(importList).ConfigureAwait(false);
|
|
|
|
// List<UnplannedIssueRequestImportDto> errorsList = new List<UnplannedIssueRequestImportDto>();
|
|
|
|
// foreach (var itm in importList)
|
|
|
|
// {
|
|
|
|
// if (string.IsNullOrEmpty(itm.CaseCode)
|
|
|
|
// || string.IsNullOrEmpty(itm.ItemCode)
|
|
|
|
// || itm.Qty == 0
|
|
|
|
// || string.IsNullOrEmpty(itm.ProjCapacityCode)
|
|
|
|
// || string.IsNullOrEmpty(itm.FromLocationErpCode)
|
|
|
|
|
|
|
|
// )
|
|
|
|
// {
|
|
|
|
// itm.Explain = "此项错误";
|
|
|
|
// errorsList.Add(itm);
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
|
|
|
|
// if (errorsList.Count > 0)
|
|
|
|
// {
|
|
|
|
// var fileContent = _excelService.Export(errorsList);
|
|
|
|
// return new TestResult(fileContent.FileContents, ExportImportService.ContentType) { FileDownloadName = fileContent.FileDownloadName };
|
|
|
|
// }
|
|
|
|
|
|
|
|
// var fileContent1 = _excelService.Export(importList);
|
|
|
|
|
|
|
|
// return new JsonResult(new { Code = 200, FileDownloadName = fileContent1.FileDownloadName });
|
|
|
|
// }
|
|
|
|
// catch (Exception e)
|
|
|
|
// {
|
|
|
|
// throw new UserFriendlyException(e.Message);
|
|
|
|
// }
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
|
|
//[HttpPost("import")]
|
|
|
|
//[Consumes("multipart/form-data")]
|
|
|
|
////[UnitOfWork]
|
|
|
|
//public override async Task<IActionResult> ImportAsync([FromForm] SfsImportRequestInput requestInput, [Required] IFormFile file)
|
|
|
|
//{
|
|
|
|
// try
|
|
|
|
// {
|
|
|
|
// using var ms = new MemoryStream();
|
|
|
|
// await file.OpenReadStream().CopyToAsync(ms).ConfigureAwait(false);
|
|
|
|
// var inputFileBytes = ms.GetAllBytes();
|
|
|
|
// var importList = _excelService.Import<UnplannedIssueRequestImportInput>(inputFileBytes).ToList();
|
|
|
|
// await CreateByDYOAsync(importList).ConfigureAwait(false);
|
|
|
|
// List<UnplannedIssueRequestImportInput> errorsList = new List<UnplannedIssueRequestImportInput>();
|
|
|
|
// foreach (var itm in importList)
|
|
|
|
// {
|
|
|
|
// if (string.IsNullOrEmpty(itm.CaseCode)
|
|
|
|
// || string.IsNullOrEmpty(itm.ItemCode)
|
|
|
|
// || itm.Qty == 0
|
|
|
|
// || string.IsNullOrEmpty(itm.ProjCapacityCode)
|
|
|
|
// || string.IsNullOrEmpty(itm.FromErpLocationCode)
|
|
|
|
|
|
|
|
// )
|
|
|
|
// {
|
|
|
|
// itm.Explain = "此项错误";
|
|
|
|
// errorsList.Add(itm);
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
|
|
|
|
// if (errorsList.Count > 0)
|
|
|
|
// {
|
|
|
|
// var fileContent = _excelService.Export(errorsList);
|
|
|
|
// return new TestResult(fileContent.FileContents, ExportImportService.ContentType) { FileDownloadName = fileContent.FileDownloadName };
|
|
|
|
// }
|
|
|
|
|
|
|
|
// var fileContent1 = _excelService.Export(importList);
|
|
|
|
|
|
|
|
// return new JsonResult(new { Code = 200, FileDownloadName = fileContent1.FileDownloadName });
|
|
|
|
// }
|
|
|
|
// catch (Exception e)
|
|
|
|
// {
|
|
|
|
// throw new UserFriendlyException(e.Message);
|
|
|
|
// }
|
|
|
|
//}
|
|
|
|
|
|
|
|
using var ms = new MemoryStream(); |
|
|
|
await file.OpenReadStream().CopyToAsync(ms).ConfigureAwait(false); |
|
|
|
var inputFileBytes = ms.GetAllBytes(); |
|
|
|
var importList = _excelService.Import<UnplannedIssueRequestImportDto>(inputFileBytes).ToList(); |
|
|
|
await CreateByDYOAsync(importList, EnumUnplannedIssueType.IMPORT).ConfigureAwait(false); |
|
|
|
|
|
|
|
|
|
|
|
List<UnplannedIssueRequestImportDto> errorsList = new List<UnplannedIssueRequestImportDto>(); |
|
|
|
|
|
|
|
foreach (var itm in importList) |
|
|
|
{ |
|
|
|
if (string.IsNullOrEmpty(itm.CaseCode) |
|
|
|
|| string.IsNullOrEmpty(itm.ItemCode) |
|
|
|
|| itm.Qty == 0 |
|
|
|
|| string.IsNullOrEmpty(itm.ProjCapacityCode) |
|
|
|
|| string.IsNullOrEmpty(itm.LocationErpCode) |
|
|
|
|
|
|
|
) |
|
|
|
{ |
|
|
|
itm.Explain = "此项错误"; |
|
|
|
errorsList.Add(itm); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (errorsList.Count > 0) |
|
|
|
{ |
|
|
|
var fileContent = _excelService.Export(errorsList); |
|
|
|
return new TestResult(fileContent.FileContents, ExportImportService.ContentType) { FileDownloadName =fileContent.FileDownloadName }; |
|
|
|
} |
|
|
|
|
|
|
|
var fileContent1 = _excelService.Export(importList); |
|
|
|
|
|
|
|
return new JsonResult(new { Code = 200, FileDownloadName = fileContent1.FileDownloadName }); |
|
|
|
} |
|
|
|
catch (Exception e) |
|
|
|
{ |
|
|
|
throw new UserFriendlyException(e.Message); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -189,7 +233,7 @@ public class UnplannedIssueRequestForDongyangAppService : UnplannedIssueRequestA |
|
|
|
UnplannedIssueRequestDTO request = new UnplannedIssueRequestDTO(); |
|
|
|
try |
|
|
|
{ |
|
|
|
return await CreateByDYOAsync(p_list, EnumUnplannedIssueType.OA, true).ConfigureAwait(false); |
|
|
|
return await CreateByDYOAsync(p_list, true).ConfigureAwait(false); |
|
|
|
} |
|
|
|
catch (Exception e) |
|
|
|
{ |
|
|
@ -202,17 +246,16 @@ public class UnplannedIssueRequestForDongyangAppService : UnplannedIssueRequestA |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected async Task<UnplannedIssueRequestDTO> CreateByDYOAsync(List<UnplannedIssueRequestImportDto> p_list, EnumUnplannedIssueType type, bool isAutoSubmit=false) |
|
|
|
protected async Task<UnplannedIssueRequestDTO> CreateByDYOAsync(List<UnplannedIssueRequestImportDto> p_list, bool isAutoSubmit = false) |
|
|
|
{ |
|
|
|
UnplannedIssueRequest request = new UnplannedIssueRequest(); |
|
|
|
if (p_list.Count == 0) |
|
|
|
{ |
|
|
|
throw new UserFriendlyException("导入内容为空请填写!"); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var first = p_list.FirstOrDefault(); |
|
|
|
request.UnplannedIssueType = type; |
|
|
|
|
|
|
|
request.SetId(GuidGenerator.Create()); |
|
|
|
request.AutoCompleteJob = false; |
|
|
|
request.AutoSubmit = isAutoSubmit; |
|
|
@ -221,8 +264,60 @@ public class UnplannedIssueRequestForDongyangAppService : UnplannedIssueRequestA |
|
|
|
request.DirectCreateNote = false; |
|
|
|
request.DeptCode = first.DeptCode; |
|
|
|
request.DeptName = first.DeptName; |
|
|
|
request.BuildDate = DateTime.Now; |
|
|
|
request.OANumber = first.OANumber; |
|
|
|
|
|
|
|
await SetEntityPropertiesAsync(request).ConfigureAwait(false); |
|
|
|
List<UnplannedIssueRequestDetail> detailList = new List<UnplannedIssueRequestDetail>(); |
|
|
|
foreach (var itm in p_list) |
|
|
|
{ |
|
|
|
var detail = new UnplannedIssueRequestDetail(); |
|
|
|
detail.ItemCode = itm.ItemCode; |
|
|
|
detail.Qty = itm.Qty; |
|
|
|
|
|
|
|
detail.LocationErpCode = itm.FromLocationErpCode; |
|
|
|
detail.LocationCode = "Random"; |
|
|
|
detail.WarehouseCode = "Random"; |
|
|
|
detail.LocationGroup = "Random"; |
|
|
|
detail.LocationArea = "Random"; |
|
|
|
detail.CaseCode = first.CaseCode; |
|
|
|
detail.ProjCapacityCode = first.ProjCapacityCode; |
|
|
|
detail.OnceBusiCode = first.OnceBusiCode; |
|
|
|
detail.Explain = first.Explain; |
|
|
|
detail.ExpireDate = DateTime.MaxValue; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await SetDetailPropertiesAsync(detail).ConfigureAwait(false); |
|
|
|
detailList.Add(detail); |
|
|
|
} |
|
|
|
|
|
|
|
request.Details = detailList; |
|
|
|
await _unplannedIssueRequestManager.CreateAsync(request).ConfigureAwait(false); |
|
|
|
var dto = ObjectMapper.Map<UnplannedIssueRequest, UnplannedIssueRequestDTO>(request); |
|
|
|
return dto; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
protected async Task<UnplannedIssueRequestDTO> CreateByDYOAsync(List<UnplannedIssueRequestImportInput> p_list, bool isAutoSubmit=false) |
|
|
|
{ |
|
|
|
UnplannedIssueRequest request = new UnplannedIssueRequest(); |
|
|
|
if (p_list.Count == 0) |
|
|
|
{ |
|
|
|
throw new UserFriendlyException("导入内容为空请填写!"); |
|
|
|
} |
|
|
|
|
|
|
|
var first = p_list.FirstOrDefault(); |
|
|
|
|
|
|
|
request.SetId(GuidGenerator.Create()); |
|
|
|
request.AutoCompleteJob = false; |
|
|
|
request.AutoSubmit = isAutoSubmit; |
|
|
|
request.AutoAgree = false; |
|
|
|
request.AutoHandle = false; |
|
|
|
request.DirectCreateNote = false; |
|
|
|
|
|
|
|
request.BuildDate= DateTime.Now; |
|
|
|
request.OANumber=first.OANumber; |
|
|
|
|
|
|
|
|
|
|
|
await SetEntityPropertiesAsync(request).ConfigureAwait(false); |
|
|
|
List<UnplannedIssueRequestDetail> detailList = new List<UnplannedIssueRequestDetail>(); |
|
|
@ -232,7 +327,7 @@ public class UnplannedIssueRequestForDongyangAppService : UnplannedIssueRequestA |
|
|
|
detail.ItemCode = itm.ItemCode; |
|
|
|
detail.Qty = itm.Qty; |
|
|
|
|
|
|
|
detail.LocationErpCode = itm.LocationErpCode; |
|
|
|
detail.LocationErpCode = itm.FromErpLocationCode; |
|
|
|
detail.LocationCode = "Random"; |
|
|
|
detail.WarehouseCode ="Random"; |
|
|
|
detail.LocationGroup ="Random"; |
|
|
@ -241,9 +336,7 @@ public class UnplannedIssueRequestForDongyangAppService : UnplannedIssueRequestA |
|
|
|
detail.ProjCapacityCode = first.ProjCapacityCode; |
|
|
|
detail.OnceBusiCode = first.OnceBusiCode; |
|
|
|
detail.Explain = first.Explain; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await SetDetailPropertiesAsync(detail).ConfigureAwait(false); |
|
|
|
detailList.Add(detail); |
|
|
|
} |
|
|
@ -314,11 +407,27 @@ public class UnplannedIssueRequestForDongyangAppService : UnplannedIssueRequestA |
|
|
|
// $"不是{EnumUnplannedReceiptType.Wip.GetDisplayName()}" +
|
|
|
|
// $"或{EnumUnplannedReceiptType.Raw.GetDisplayName()}】");
|
|
|
|
//}
|
|
|
|
//unplannedReceiptRequest.UnplannedIssueType = type;
|
|
|
|
|
|
|
|
unplannedReceiptRequest.AutoCompleteJob = false; |
|
|
|
unplannedReceiptRequest.AutoSubmit = true; |
|
|
|
unplannedReceiptRequest.AutoAgree = false; |
|
|
|
unplannedReceiptRequest.AutoHandle = false; |
|
|
|
unplannedReceiptRequest.DirectCreateNote = false; |
|
|
|
unplannedReceiptRequest.BuildDate = DateTime.Now; |
|
|
|
await SetRequestAutoPropertiesAsync(unplannedReceiptRequest).ConfigureAwait(false); |
|
|
|
await SetEntityPropertiesAsync(unplannedReceiptRequest).ConfigureAwait(false); |
|
|
|
|
|
|
|
foreach (var detail in unplannedReceiptRequest.Details) |
|
|
|
{ |
|
|
|
detail.LocationErpCode = unplannedReceiptRequest.FromErpLocationCode; |
|
|
|
detail.LocationCode = "Random"; |
|
|
|
detail.WarehouseCode = "Random"; |
|
|
|
detail.LocationGroup = "Random"; |
|
|
|
detail.LocationArea = "Random"; |
|
|
|
//detail.CaseCode = unplannedReceiptRequest.CaseCode;
|
|
|
|
//detail.ProjCapacityCode = first.ProjCapacityCode;
|
|
|
|
//detail.OnceBusiCode = first.OnceBusiCode;
|
|
|
|
//detail.Explain = first.Explain;
|
|
|
|
await SetDetailPropertiesAsync(detail).ConfigureAwait(false); |
|
|
|
} |
|
|
|
} |
|
|
@ -386,74 +495,7 @@ public class UnplannedIssueRequestForDongyangAppService : UnplannedIssueRequestA |
|
|
|
detail.LocationArea = location.AreaCode; |
|
|
|
detail.LocationCode = location.Code; |
|
|
|
} |
|
|
|
//string packingcode = string.Empty;
|
|
|
|
//if(type!= EnumUnplannedIssueType.Wip)
|
|
|
|
//{
|
|
|
|
// packingcode = detail.PackingCode;
|
|
|
|
//}
|
|
|
|
//var balance = await _balanceAppService.GetByItemLocationAndPackingAsync(
|
|
|
|
// packingcode,
|
|
|
|
// detail.ItemCode,
|
|
|
|
// detail.LocationCode).ConfigureAwait(false);
|
|
|
|
|
|
|
|
//if (balance != null)
|
|
|
|
//{
|
|
|
|
// detail.SupplierBatch = balance.SupplierBatch;
|
|
|
|
// detail.ArriveDate = balance.ArriveDate;
|
|
|
|
// detail.ProduceDate = balance.ProduceDate;
|
|
|
|
// detail.ExpireDate = balance.ExpireDate;
|
|
|
|
|
|
|
|
// detail.Lot = balance.Lot;
|
|
|
|
// detail.ContainerCode = balance.ContainerCode;
|
|
|
|
// detail.PackingCode = balance.PackingCode;
|
|
|
|
// detail.Qty = detail.Qty;
|
|
|
|
// detail.Status = balance.Status;
|
|
|
|
//}
|
|
|
|
|
|
|
|
//if (!string.IsNullOrEmpty(detail))
|
|
|
|
//{
|
|
|
|
// var dict = await DictAppService.GetByCodeAsync(nameof(input.OnceBusiCode)).ConfigureAwait(false);
|
|
|
|
|
|
|
|
// if (dict.Items != null && dict.Items.Count > 0)
|
|
|
|
// {
|
|
|
|
// var item = dict.Items.FirstOrDefault(t => t.Code == input.OnceBusiCode);
|
|
|
|
|
|
|
|
// Check.NotNull(item, "次交易码", "次交易码不存在");
|
|
|
|
|
|
|
|
// detail.SetProperty("OnceBusiCode", item.Code);
|
|
|
|
// detail.SetProperty("OnceBusiName", item.Name);
|
|
|
|
// }
|
|
|
|
//}
|
|
|
|
|
|
|
|
//if (!string.IsNullOrEmpty(input.CaseCode))
|
|
|
|
//{
|
|
|
|
// var dict = await DictAppService.GetByCodeAsync(nameof(input.CaseCode)).ConfigureAwait(false);
|
|
|
|
|
|
|
|
// if (dict.Items != null && dict.Items.Count > 0)
|
|
|
|
// {
|
|
|
|
// var item = dict.Items.FirstOrDefault(t => t.Code == input.CaseCode);
|
|
|
|
|
|
|
|
// Check.NotNull(item, "专案代码", "专案代码不存在");
|
|
|
|
|
|
|
|
// detail.SetProperty("CaseCode", item.Code);
|
|
|
|
// detail.SetProperty("CaseName", item.Name);
|
|
|
|
// }
|
|
|
|
//}
|
|
|
|
|
|
|
|
//if (!string.IsNullOrEmpty(input.ProjCapacityCode))
|
|
|
|
//{
|
|
|
|
// var dict = await DictAppService.GetByCodeAsync(nameof(input.ProjCapacityCode)).ConfigureAwait(false);
|
|
|
|
|
|
|
|
// if (dict.Items != null && dict.Items.Count > 0)
|
|
|
|
// {
|
|
|
|
// var item = dict.Items.FirstOrDefault(t => t.Code == input.ProjCapacityCode);
|
|
|
|
|
|
|
|
// Check.NotNull(item, "项目分类代码", "项目分类代码不存在");
|
|
|
|
|
|
|
|
// detail.SetProperty("ProjCapacityCode", item.Code);
|
|
|
|
// detail.SetProperty("ProjCapacityName", item.Name);
|
|
|
|
// }
|
|
|
|
//}
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -511,16 +553,19 @@ public class UnplannedIssueRequestForDongyangAppService : UnplannedIssueRequestA |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected async Task<BalanceDTO> CheckBalanceAsync(UnplannedIssueRequestImportInput importInput, List<ValidationResult> validationRresult) |
|
|
|
{ |
|
|
|
var balance = await BalanceAclService.GetByItemLocationAndPackingAsync( |
|
|
|
string.Empty, |
|
|
|
importInput.ItemCode, |
|
|
|
importInput.LocationErpCode).ConfigureAwait(false); |
|
|
|
importInput.FromErpLocationCode).ConfigureAwait(false); |
|
|
|
|
|
|
|
if (balance == null) |
|
|
|
{ |
|
|
|
validationRresult.Add(new ValidationResult($"ERP料号{importInput.ItemCode}在库位{importInput.LocationErpCode}没有库存记录", new string[] { "库存余额" })); |
|
|
|
validationRresult.Add(new ValidationResult($"ERP料号{importInput.ItemCode}在库位{importInput.FromErpLocationCode}没有库存记录", new string[] { "库存余额" })); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
@ -568,7 +613,7 @@ public class UnplannedIssueRequestForDongyangAppService : UnplannedIssueRequestA |
|
|
|
protected override async Task ValidateImportModelAsync(UnplannedIssueRequestImportInput model, List<ValidationResult> validationRresult) |
|
|
|
{ |
|
|
|
_ = await CheckItemBasicAsync(model, validationRresult).ConfigureAwait(false); |
|
|
|
await CheckErpLocationAsync(model.LocationErpCode, validationRresult).ConfigureAwait(false); |
|
|
|
await CheckErpLocationAsync(model.FromErpLocationCode, validationRresult).ConfigureAwait(false); |
|
|
|
|
|
|
|
await CheckOnceBusiCodeAsync(model, validationRresult).ConfigureAwait(false);//次交易码
|
|
|
|
//await CheckCaseCodeAsync(model, validationRresult).ConfigureAwait(false);//专案代码
|
|
|
|