mahao 1 year ago
parent
commit
fb8bb5fa75
  1. 26
      code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/MaterialRelationships/MaterialRelationshipAppService.cs

26
code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/MaterialRelationships/MaterialRelationshipAppService.cs

@ -54,15 +54,15 @@ public class MaterialRelationshipAppService : SettleAccountApplicationBase<Mater
[HttpPost] [HttpPost]
public async Task<IActionResult> ImportAsync([FromForm] MaterialRelationshipImportRequestDto materialRelationshipImportRequestDto) public async Task<IActionResult> ImportAsync([FromForm] MaterialRelationshipImportRequestDto materialRelationshipImportRequestDto)
{ {
var _exportImporter = new ExportImporter(); var exportImporter = new ExportImporter();
var result = await _exportImporter.UploadExcelImport<MaterialRelationshipImportDto>(materialRelationshipImportRequestDto.Files, _excelImportService).ConfigureAwait(false); var inportDatas = await exportImporter.UploadExcelImport<MaterialRelationshipImportDto>(materialRelationshipImportRequestDto.Files, _excelImportService).ConfigureAwait(false);
var _ls = ObjectMapper.Map<List<MaterialRelationshipImportDto>, List<MaterialRelationship>>(result); var entitys = ObjectMapper.Map<List<MaterialRelationshipImportDto>, List<MaterialRelationship>>(inportDatas);
List<string> _errorList = new List<string>(); var errorList = new List<string>();
var checkList = new List<ErrorExportDto>(); var checkList = new List<ErrorExportDto>();
if (_ls.Count > 0) if (entitys.Count > 0)
{ {
var query = from arc in _ls var query = from arc in entitys
group arc by new { arc.SettleMaterialCode } group arc by new { arc.SettleMaterialCode }
into g into g
where g.Count() > 1 where g.Count() > 1
@ -77,18 +77,18 @@ public class MaterialRelationshipAppService : SettleAccountApplicationBase<Mater
string fileName = await ExportErrorReportAsync(checkList).ConfigureAwait(false); string fileName = await ExportErrorReportAsync(checkList).ConfigureAwait(false);
return new JsonResult(new { Code = ApplicationConsts.ImportFailCode, Message = "错误提示文件已下载,请打开文件查看", fileName = fileName }); return new JsonResult(new { Code = ApplicationConsts.ImportFailCode, Message = "错误提示文件已下载,请打开文件查看", fileName = fileName });
} }
foreach (var itm in _ls) foreach (var item in entitys)
{ {
var _first = _repository.FirstOrDefault(p => p.ErpMaterialCode == itm.ErpMaterialCode && p.BusinessType == EnumBusinessType.BeiJian); var entity = _repository.FirstOrDefault(p => p.ErpMaterialCode == item.ErpMaterialCode && p.BusinessType == EnumBusinessType.BeiJian);
if (_first != null) if (entity != null)
{ {
_first.Update(itm.MaterialDesc, itm.SettleMaterialCode); entity.Update(item.MaterialDesc, item.SettleMaterialCode);
await _repository.UpdateAsync(_first).ConfigureAwait(false); await _repository.UpdateAsync(entity).ConfigureAwait(false);
} }
else else
{ {
itm.BusinessType = EnumBusinessType.BeiJian; item.BusinessType = EnumBusinessType.BeiJian;
await _repository.InsertAsync(itm).ConfigureAwait(false); await _repository.InsertAsync(item).ConfigureAwait(false);
} }
} }
return new JsonResult(new { Code = 200, Message = "导入成功" }); return new JsonResult(new { Code = 200, Message = "导入成功" });

Loading…
Cancel
Save