Compare commits

...

2 Commits

Author SHA1 Message Date
lvzb 015f8d9cbd 合并代码 10 months ago
lvzb 67558d1610 添加模板导入功能 10 months ago
  1. 39
      src/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.Application.Contracts/MsgBaseData/AssemblyCfgs/Dtos/ImportErpAssemblyGroupDto.cs
  2. 20
      src/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.Application.Contracts/WY.NewJit.Application.Contracts.xml
  3. 162
      src/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.Application/MsgBaseData/AssemblyCfgs/AssemblyCfgErpAppService.cs
  4. 16
      src/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.Application/WY.NewJit.Application.xml

39
src/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.Application.Contracts/MsgBaseData/AssemblyCfgs/Dtos/ImportErpAssemblyGroupDto.cs

@ -0,0 +1,39 @@
using Magicodes.ExporterAndImporter.Core;
using Magicodes.ExporterAndImporter.Excel;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Text;
namespace WY.NewJit.MsgBaseData
{
/// <summary>
/// 总成组
/// </summary>
[ExcelExporter(Name = "总成组表", AutoFitAllColumn = true, MaxRowNumberOnASheet = 50000)] //一个Sheet最大允许的行数,设置了之后将输出多个Sheet
[Serializable]
public class ImportErpAssemblyGroupDto
{
/// <summary>
/// 规格说明
/// </summary>
[ExporterHeader(DisplayName = "规格说明")]
[ImporterHeader(Name = "规格说明")]
[Required(ErrorMessage = "{0}是必填项")]
public virtual string SpecExplain { get; set; }
/// <summary>
/// 颜色说明
/// </summary>
[ExporterHeader(DisplayName = "颜色说明")]
[ImporterHeader(Name = "颜色说明")]
[Required(ErrorMessage = "{0}是必填项")]
public virtual string ColorExplain { get; set; }
/// <summary>
/// 物料号
/// </summary>
[ExporterHeader(DisplayName = "物料号")]
[ImporterHeader(Name = "物料号")]
[Required(ErrorMessage = "{0}是必填项")]
public virtual string MaterialNum { get; set; }
}
}

20
src/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.Application.Contracts/WY.NewJit.Application.Contracts.xml

@ -1403,6 +1403,26 @@
创建时间
</summary>
</member>
<member name="T:WY.NewJit.MsgBaseData.ImportErpAssemblyGroupDto">
<summary>
总成组
</summary>
</member>
<member name="P:WY.NewJit.MsgBaseData.ImportErpAssemblyGroupDto.SpecExplain">
<summary>
规格说明
</summary>
</member>
<member name="P:WY.NewJit.MsgBaseData.ImportErpAssemblyGroupDto.ColorExplain">
<summary>
颜色说明
</summary>
</member>
<member name="P:WY.NewJit.MsgBaseData.ImportErpAssemblyGroupDto.MaterialNum">
<summary>
物料号
</summary>
</member>
<member name="P:WY.NewJit.MsgBaseData.QueryAssemblyCfgErpDto.ErpAssemblyCode">
<summary>
ERP总成编码

162
src/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.Application/MsgBaseData/AssemblyCfgs/AssemblyCfgErpAppService.cs

@ -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")]

16
src/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.Application/WY.NewJit.Application.xml

@ -49,7 +49,7 @@
错误信息前缀
</summary>
</member>
<member name="M:WY.NewJit.EdiReceive.ImportRecordAppService.#ctor(Volo.Abp.Domain.Repositories.IRepository{WY.NewJit.EdiReceive.Entitys.ImportRecord,System.Guid},Microsoft.Extensions.Logging.ILogger{WY.NewJit.EdiReceive.ImportRecordAppService},WY.NewJit.EntityFrameworkCore.NewJitDapperRepository,Volo.Abp.BlobStoring.IBlobContainer{WY.NewJit.Common.OurFileContainer},WY.NewJit.MsgBaseData.DicDomainService,WY.NewJit.EdiReceive.Services.EdiParseDomainService,Microsoft.Extensions.Configuration.IConfiguration)">
<member name="M:WY.NewJit.EdiReceive.ImportRecordAppService.#ctor(Volo.Abp.Domain.Repositories.IRepository{WY.NewJit.EdiReceive.Entitys.ImportRecord,System.Guid},Microsoft.Extensions.Logging.ILogger{WY.NewJit.EdiReceive.ImportRecordAppService},WY.NewJit.EntityFrameworkCore.NewJitDapperRepository,Volo.Abp.BlobStoring.IBlobContainer{WY.NewJit.Common.OurFileContainer},WY.NewJit.MsgBaseData.DicDomainService,Microsoft.Extensions.Configuration.IConfiguration)">
<summary>
构造函数
</summary>
@ -277,6 +277,11 @@
总成配置应用服务实现
</summary>
</member>
<member name="F:WY.NewJit.MsgBaseData.AssemblyCfgErpAppService._assemblyCfgGroupRepository">
<summary>
总成组
</summary>
</member>
<member name="F:WY.NewJit.MsgBaseData.AssemblyCfgErpAppService._assemblyCfgErpRepository">
<summary>
ERP总成仓储
@ -327,7 +332,7 @@
错误信息前缀
</summary>
</member>
<member name="M:WY.NewJit.MsgBaseData.AssemblyCfgErpAppService.#ctor(Volo.Abp.Domain.Repositories.IRepository{WY.NewJit.MsgBaseData.AssemblyCfgErp,System.Guid},Microsoft.Extensions.Logging.ILogger{WY.NewJit.MsgBaseData.AssemblyCfgErpAppService},WY.NewJit.EntityFrameworkCore.NewJitDapperRepository,Volo.Abp.Domain.Repositories.IRepository{WY.NewJit.MsgBaseData.AssemblyCfgPart,System.Guid},Volo.Abp.BlobStoring.IBlobContainer{WY.NewJit.Common.OurFileContainer},WY.NewJit.MsgBaseData.AssemblyDomainService,Volo.Abp.Domain.Repositories.IRepository{WY.NewJit.MsgBaseData.PartCfg,System.Guid},Volo.Abp.Domain.Repositories.IRepository{WY.NewJit.Extends.PaiGe.MaterialExt,System.Guid},WY.NewJit.MsgBaseData.GlobalSettingsDomainService)">
<member name="M:WY.NewJit.MsgBaseData.AssemblyCfgErpAppService.#ctor(Volo.Abp.Domain.Repositories.IRepository{WY.NewJit.MsgBaseData.AssemblyCfgErp,System.Guid},Microsoft.Extensions.Logging.ILogger{WY.NewJit.MsgBaseData.AssemblyCfgErpAppService},WY.NewJit.EntityFrameworkCore.NewJitDapperRepository,Volo.Abp.Domain.Repositories.IRepository{WY.NewJit.MsgBaseData.AssemblyCfgPart,System.Guid},Volo.Abp.BlobStoring.IBlobContainer{WY.NewJit.Common.OurFileContainer},WY.NewJit.MsgBaseData.AssemblyDomainService,Volo.Abp.Domain.Repositories.IRepository{WY.NewJit.MsgBaseData.PartCfg,System.Guid},Volo.Abp.Domain.Repositories.IRepository{WY.NewJit.Extends.PaiGe.MaterialExt,System.Guid},WY.NewJit.MsgBaseData.GlobalSettingsDomainService,Volo.Abp.Domain.Repositories.IRepository{WY.NewJit.MsgBaseData.AssemblyCfgGroup,System.Guid})">
<summary>
构造函数
</summary>
@ -402,6 +407,13 @@
<param name="files">导入文件</param>
<returns>执行成功返回真</returns>
</member>
<member name="M:WY.NewJit.MsgBaseData.AssemblyCfgErpAppService.ImportErpAssemblyGroupAsync(Microsoft.AspNetCore.Http.IFormFileCollection)">
<summary>
导入
</summary>
<param name="files">导入文件</param>
<returns>执行成功返回真</returns>
</member>
<member name="M:WY.NewJit.MsgBaseData.AssemblyCfgErpAppService.RemoveRepeatErpAssembly(System.Int32)">
<summary>
系统初始化时使用,去掉重复的ERP总成

Loading…
Cancel
Save