|
|
@ -23,6 +23,7 @@ using System.Data; |
|
|
|
using Microsoft.AspNetCore.Authorization; |
|
|
|
using WY.NewJit.Extends.PaiGe; |
|
|
|
using Volo.Abp; |
|
|
|
using Magicodes.ExporterAndImporter.Core.Models; |
|
|
|
|
|
|
|
namespace WY.NewJit.MsgBaseData |
|
|
|
{ |
|
|
@ -33,6 +34,10 @@ namespace WY.NewJit.MsgBaseData |
|
|
|
[ApiExplorerSettings(GroupName = SwaggerGroupConsts.基础数据)] |
|
|
|
public class AssemblyCfgErpAppService : ApplicationService, IAssemblyCfgErpAppService |
|
|
|
{ |
|
|
|
/// <summary>
|
|
|
|
/// 总成组
|
|
|
|
/// </summary>
|
|
|
|
private readonly IRepository<AssemblyCfgGroup, Guid> _assemblyCfgGroupRepository; |
|
|
|
/// <summary>
|
|
|
|
/// ERP总成仓储
|
|
|
|
/// </summary>
|
|
|
@ -112,7 +117,8 @@ SELECT top 1 v.Id |
|
|
|
AssemblyDomainService assemblyDomainService, |
|
|
|
IRepository<PartCfg, Guid> partCfgRepository, |
|
|
|
IRepository<MaterialExt, Guid> materialExtRepository, |
|
|
|
GlobalSettingsDomainService globalSettingsDomainService |
|
|
|
GlobalSettingsDomainService globalSettingsDomainService, |
|
|
|
IRepository<AssemblyCfgGroup, Guid> assemblyCfgGroupRepository |
|
|
|
) |
|
|
|
{ |
|
|
|
_assemblyCfgErpRepository = assemblyCfgErpRepository; |
|
|
@ -124,6 +130,7 @@ SELECT top 1 v.Id |
|
|
|
_partCfgRepository = partCfgRepository; |
|
|
|
_materialExtRepository = materialExtRepository; |
|
|
|
_globalSettingsDomainService = globalSettingsDomainService; |
|
|
|
_assemblyCfgGroupRepository = assemblyCfgGroupRepository; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
@ -668,11 +675,158 @@ SELECT top 1 v.Id |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 校验ERP总成:是否版本覆盖
|
|
|
|
/// 导入
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="input"></param>
|
|
|
|
/// <returns></returns>
|
|
|
|
/// <param name="files">导入文件</param>
|
|
|
|
/// <returns>执行成功返回真</returns>
|
|
|
|
[HttpPost] |
|
|
|
[Route("import-erp-assembly-group")] |
|
|
|
[DisableRequestSizeLimit] |
|
|
|
public virtual async Task<ObjectResultDto> ImportErpAssemblyGroupAsync([FromForm] IFormFileCollection files) |
|
|
|
{ |
|
|
|
|
|
|
|
_logger.LogDebug(_errorMessagePrefix + "ImportErpAssemblyGroupAsync 进入"); |
|
|
|
ObjectResultDto ret = new ObjectResultDto(); |
|
|
|
try |
|
|
|
{ |
|
|
|
#region 导入文件处理
|
|
|
|
ImportResult<ImportErpAssemblyGroupDto> impResult; |
|
|
|
using (var memoryStream = new MemoryStream()) |
|
|
|
{ |
|
|
|
//保存到内存流
|
|
|
|
IFormFile file = files[0]; |
|
|
|
await file.CopyToAsync(memoryStream); |
|
|
|
memoryStream.Seek(0, SeekOrigin.Begin); |
|
|
|
//StreamReader sr = new StreamReader(memoryStream, Encoding.Default);
|
|
|
|
IImporter importer = new ExcelImporter(); |
|
|
|
impResult = await importer.Import<ImportErpAssemblyGroupDto>(memoryStream); |
|
|
|
if (impResult.HasError) |
|
|
|
{ |
|
|
|
string rowErrStr = ""; |
|
|
|
foreach (var rowErr in impResult.RowErrors) |
|
|
|
{ |
|
|
|
string fieldErr = string.Concat(rowErr.FieldErrors.Select(itm => $"字段:{itm.Key},错误信息:{itm.Value}")); |
|
|
|
rowErrStr += $"行号:{rowErr.RowIndex},{fieldErr}\r\n"; |
|
|
|
} |
|
|
|
string templateErrStr = ""; |
|
|
|
foreach (var templateErr in impResult.TemplateErrors) |
|
|
|
{ |
|
|
|
string errorLevel = templateErr.ErrorLevel == ErrorLevels.Error ? "错误" : "警告"; |
|
|
|
templateErrStr += $"错误等级:{errorLevel},列名:{templateErr.ColumnName},需要列:{templateErr.RequireColumnName},错误消息:{templateErr.Message}\r\n"; |
|
|
|
} |
|
|
|
ret.Message = rowErrStr + templateErrStr; |
|
|
|
ret.Status = false; |
|
|
|
return ret; |
|
|
|
} |
|
|
|
} |
|
|
|
#endregion
|
|
|
|
#region 数据验证
|
|
|
|
var srcLst = impResult.Data.AsEnumerable().ToList(); |
|
|
|
List<MaterialExt> material3Lst = await _materialExtRepository.Where(itm => itm.MaterialType == "3").ToListAsync(); |
|
|
|
|
|
|
|
var error= CheckGroup(srcLst, material3Lst); |
|
|
|
if (!string.IsNullOrEmpty(error)) |
|
|
|
{ |
|
|
|
ret.Message = error; |
|
|
|
ret.Status = false; |
|
|
|
return ret; |
|
|
|
} |
|
|
|
#endregion
|
|
|
|
#region 插入数据
|
|
|
|
List<AssemblyCfgGroup> assemblyCfgGroups = new List<AssemblyCfgGroup>(); |
|
|
|
List<AssemblyCfgGroup> deleteAssemblyCfgGroups = new List<AssemblyCfgGroup>(); |
|
|
|
List<AssemblyCfgErp> assemblyCfgErps = new List<AssemblyCfgErp>(); |
|
|
|
var groups = srcLst.GroupBy(r => new { r.SpecExplain, r.ColorExplain }).ToList(); |
|
|
|
foreach (var group in groups) |
|
|
|
{ |
|
|
|
|
|
|
|
var olditem= await _assemblyCfgGroupRepository.FirstOrDefaultAsync(r=>r.IsDisable==true&&r.SpecExplain== group.Key.SpecExplain.Trim()&& r.ColorExplain == group.Key.ColorExplain.Trim()); |
|
|
|
if (olditem != null) |
|
|
|
{ |
|
|
|
olditem.IsDisable = false; |
|
|
|
deleteAssemblyCfgGroups.Add(olditem); |
|
|
|
} |
|
|
|
string groupCode = group.Key.SpecExplain + group.Key.ColorExplain; |
|
|
|
AssemblyCfgGroup assemblyCfgGroup = new AssemblyCfgGroup(GuidGenerator.Create() , groupCode,"",true); |
|
|
|
assemblyCfgGroup.SpecExplain = group.Key.SpecExplain.Trim(); |
|
|
|
assemblyCfgGroup.ColorExplain = group.Key.ColorExplain.Trim(); |
|
|
|
foreach (var item in group) |
|
|
|
{ |
|
|
|
var material3 = material3Lst.FirstOrDefault(r => r.MaterialNum == item.MaterialNum.Trim()); |
|
|
|
AssemblyCfgErp assemblyCfgErp = new AssemblyCfgErp(GuidGenerator.Create()); |
|
|
|
assemblyCfgErp.ErpAssemblyCode = item.MaterialNum.Trim(); |
|
|
|
assemblyCfgErp.ErpAssemblyName = material3.MaterialDescription; |
|
|
|
assemblyCfgErp.ErpAssemblyVersion = 1; |
|
|
|
assemblyCfgErp.GroupCode = groupCode; |
|
|
|
assemblyCfgErp.GroupId = assemblyCfgGroup.Id; |
|
|
|
assemblyCfgErp.SpecExplain = item.SpecExplain.Trim(); |
|
|
|
assemblyCfgErp.ColorExplain = item.ColorExplain.Trim(); |
|
|
|
assemblyCfgErps.Add(assemblyCfgErp); |
|
|
|
} |
|
|
|
assemblyCfgGroups.Add(assemblyCfgGroup); |
|
|
|
} |
|
|
|
|
|
|
|
//插入“导入记录表”
|
|
|
|
await _assemblyCfgGroupRepository.UpdateManyAsync(deleteAssemblyCfgGroups);//更新总成组
|
|
|
|
await _assemblyCfgGroupRepository.InsertManyAsync(assemblyCfgGroups); |
|
|
|
await _assemblyCfgErpRepository.InsertManyAsync(assemblyCfgErps); |
|
|
|
#endregion
|
|
|
|
ret.Status = true; |
|
|
|
return ret; |
|
|
|
} |
|
|
|
catch (Exception ex) |
|
|
|
{ |
|
|
|
ret.Status = false; |
|
|
|
ret.Message = _errorMessagePrefix + "ImportErpAssemblyGroupAsync 执行出错:" + ex.Message; |
|
|
|
_logger.LogError(ret.Message); |
|
|
|
return ret; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private string CheckGroup(List<ImportErpAssemblyGroupDto> srcLst, List<MaterialExt> material3Lst) |
|
|
|
{ |
|
|
|
//验证是否有重复项
|
|
|
|
string error = ""; |
|
|
|
var disitem = srcLst.Distinct(); |
|
|
|
if (disitem.Count() != srcLst.Count()) |
|
|
|
{ |
|
|
|
error = "导入数据有重复项,检查后在导入!"; |
|
|
|
} |
|
|
|
if (!string.IsNullOrEmpty(error)) return error; |
|
|
|
|
|
|
|
|
|
|
|
#region 验证分组是否符合分组规
|
|
|
|
|
|
|
|
var checkGroups = srcLst.GroupBy(r => new { r.SpecExplain, r.ColorExplain }).Select(r => new { SpecExplain = r.Key.SpecExplain, ColorExplain = r.Key.ColorExplain, Count = r.Count() }); |
|
|
|
var errorgroups = checkGroups.Where(r => r.Count != 4).ToList(); |
|
|
|
foreach (var item in errorgroups) |
|
|
|
{ |
|
|
|
error += $"规格说明【{item.SpecExplain}】,颜色说明【{item.ColorExplain}】,零件数【{item.Count}】不符合分组规则\r\n"; |
|
|
|
} |
|
|
|
if (!string.IsNullOrEmpty(error)) return error; |
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region 验证零件是否存在(门板)
|
|
|
|
|
|
|
|
|
|
|
|
var partdists = srcLst.Select(r => r.MaterialNum).Distinct(); |
|
|
|
foreach (var material in partdists) |
|
|
|
{ |
|
|
|
var material3 = material3Lst.FirstOrDefault(r => r.MaterialNum == material); |
|
|
|
if (material3 == null) |
|
|
|
{ |
|
|
|
error += $"零件编号【{material}】系统同不存在,请检查后再导入\r\n"; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
#endregion
|
|
|
|
return error; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//[UnitOfWork]
|
|
|
|
//[HttpPost]
|
|
|
|
//[Route("check")]
|
|
|
|