导入导出

This commit is contained in:
2026-01-07 16:38:07 +08:00
parent cf20bb845a
commit a68ee7969e
4 changed files with 45 additions and 96 deletions

View File

@@ -27,7 +27,7 @@ namespace DOAN.Service.BZFM.IBZFMService
/// </summary>
/// <param name="material"></param>
/// <returns></returns>
ImportResultDto Importmaterial(List<MmMaterialExcelDto2> material);
ImportResultDto Importmaterial(List<MmMaterialExcelDto> material);
public PagedInfo<MmMaterialExcelDto> SelectMaterialList(MmMaterialQueryDto material, PagerInfo pager);

View File

@@ -138,33 +138,33 @@ namespace DOAN.Service.BZFM
/// </summary>
/// <param name="material"></param>
/// <returns></returns>
public ImportResultDto Importmaterial(List<MmMaterialExcelDto2> material)
public ImportResultDto Importmaterial(List<MmMaterialExcelDto> material)
{
// normalize and set defaults, do not overwrite provided values
//material.ForEach(x =>
//{
// if (x.CreatedTime == null)
// {
// x.CreatedTime = DateTime.Now;
// }
// if (string.IsNullOrWhiteSpace(x.Status))
// {
// x.Status = "启用";
// }
// if (!string.IsNullOrWhiteSpace(x.MaterialCode))
// {
// x.MaterialCode = x.MaterialCode.Trim();
// }
// if (!string.IsNullOrWhiteSpace(x.MaterialName))
// {
// x.MaterialName = x.MaterialName.Trim();
// }
// x.Description = x.Description.IsEmpty() ? "数据导入" : x.Description;
//});
material.ForEach(x =>
{
if (x.CreatedTime == null)
{
x.CreatedTime = DateTime.Now;
}
if (string.IsNullOrWhiteSpace(x.Status))
{
x.Status = "启用";
}
if (!string.IsNullOrWhiteSpace(x.MaterialCode))
{
x.MaterialCode = x.MaterialCode.Trim();
}
if (!string.IsNullOrWhiteSpace(x.MaterialName))
{
x.MaterialName = x.MaterialName.Trim();
}
x.Description = x.Description.IsEmpty() ? "数据导入" : x.Description;
});
var x = Context
.Storageable(material)
.SplitInsert(it => !it.Any())
.WhereColumns(it => new { it.Id, it. }) //如果不是主键可以这样实现多字段it=>new{it.x1,it.x2}
.WhereColumns(it => new { it.Id, it.MaterialCode }) //如果不是主键可以这样实现多字段it=>new{it.x1,it.x2}
.ToStorage();
var result = x.AsInsertable.ExecuteCommand(); //插入可插入部分;
@@ -182,26 +182,26 @@ namespace DOAN.Service.BZFM
Console.WriteLine(importResult);
// 收集错误与忽略信息
//foreach (var item in x.ErrorList)
//{
// importResult.Errors.Add(
// new ImportErrorDto
// {
// MaterialCode = item.Item.MaterialCode,
// Message = item.StorageMessage,
// }
// );
//}
//foreach (var item in x.IgnoreList)
//{
// importResult.Ignored.Add(
// new ImportErrorDto
// {
// MaterialCode = item.Item.MaterialCode,
// Message = item.StorageMessage,
// }
// );
//}
foreach (var item in x.ErrorList)
{
importResult.Errors.Add(
new ImportErrorDto
{
MaterialCode = item.Item.MaterialCode,
Message = item.StorageMessage,
}
);
}
foreach (var item in x.IgnoreList)
{
importResult.Ignored.Add(
new ImportErrorDto
{
MaterialCode = item.Item.MaterialCode,
Message = item.StorageMessage,
}
);
}
return importResult;
}