新增物料清单Excel导入功能及相关接口
新增物料清单批量导入接口,支持Excel文件上传,自动设置创建时间和状态,完善DTO字段。实现批量插入、校验物料编码、统计导入结果。补充相关依赖和命名空间。
This commit is contained in:
@@ -1,9 +1,11 @@
|
|||||||
using DOAN.Admin.WebApi.Filters;
|
using DOAN.Admin.WebApi.Filters;
|
||||||
using DOAN.Model.BZFM;
|
using DOAN.Model.BZFM;
|
||||||
using DOAN.Model.BZFM.Dto;
|
using DOAN.Model.BZFM.Dto;
|
||||||
|
using DOAN.Model.System;
|
||||||
using DOAN.Service.BZFM;
|
using DOAN.Service.BZFM;
|
||||||
using DOAN.Service.BZFM.IBZFMService;
|
using DOAN.Service.BZFM.IBZFMService;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using MiniExcelLibs;
|
||||||
|
|
||||||
//创建时间:2025-12-25
|
//创建时间:2025-12-25
|
||||||
namespace DOAN.Admin.WebApi.Controllers.BZFM
|
namespace DOAN.Admin.WebApi.Controllers.BZFM
|
||||||
@@ -111,6 +113,23 @@ namespace DOAN.Admin.WebApi.Controllers.BZFM
|
|||||||
return SUCCESS(response);
|
return SUCCESS(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 导入
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="formFile">使用IFromFile必须使用name属性否则获取不到文件</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpPost("importData")]
|
||||||
|
[Log(Title = "物料清单导入", BusinessType = BusinessType.IMPORT, IsSaveRequestData = false, IsSaveResponseData = true)]
|
||||||
|
[ActionPermissionFilter(Permission = "mmmaterial:import")]
|
||||||
|
public IActionResult ImportData([FromForm(Name = "file")] IFormFile formFile)
|
||||||
|
{
|
||||||
|
List<MmMaterialQueryDto> material = new();
|
||||||
|
using (var stream = formFile.OpenReadStream())
|
||||||
|
{
|
||||||
|
material = stream.Query<MmMaterialQueryDto>(startCell: "A2").ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
return SUCCESS(_MmMaterialService.Importmaterial(material));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -9,6 +9,8 @@ namespace DOAN.Model.BZFM.Dto
|
|||||||
public string CategoryCode { get; set; }
|
public string CategoryCode { get; set; }
|
||||||
public string CategoryName { get; set; }
|
public string CategoryName { get; set; }
|
||||||
public string Status { get; set; }
|
public string Status { get; set; }
|
||||||
|
|
||||||
|
public DateTime? CreatedTime { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ namespace DOAN.Model.BZFM.Dto
|
|||||||
public string TypeLabel { get; set; }
|
public string TypeLabel { get; set; }
|
||||||
public string Type { get; set; }
|
public string Type { get; set; }
|
||||||
public string Status { get; set; }
|
public string Status { get; set; }
|
||||||
|
public DateTime? CreatedTime { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using DOAN.Model.BZFM.Dto;
|
|
||||||
using DOAN.Model.BZFM;
|
using DOAN.Model.BZFM;
|
||||||
|
using DOAN.Model.BZFM.Dto;
|
||||||
|
using DOAN.Model.System;
|
||||||
|
|
||||||
namespace DOAN.Service.BZFM.IBZFMService
|
namespace DOAN.Service.BZFM.IBZFMService
|
||||||
{
|
{
|
||||||
@@ -20,5 +21,12 @@ namespace DOAN.Service.BZFM.IBZFMService
|
|||||||
// 查询物料类别下拉框
|
// 查询物料类别下拉框
|
||||||
List<MmMaterialCategoryOptionsDto> GetMmMaterialCategoryOptions(MmMaterialCategoryDto parm);
|
List<MmMaterialCategoryOptionsDto> GetMmMaterialCategoryOptions(MmMaterialCategoryDto parm);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 导入
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="material"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
(string, object, object) Importmaterial(List<MmMaterial> material);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,12 @@
|
|||||||
using Infrastructure.Attribute;
|
using DOAN.Common;
|
||||||
using Infrastructure.Extensions;
|
|
||||||
using DOAN.Model.BZFM.Dto;
|
|
||||||
using DOAN.Model.BZFM;
|
using DOAN.Model.BZFM;
|
||||||
|
using DOAN.Model.BZFM.Dto;
|
||||||
|
using DOAN.Model.System;
|
||||||
using DOAN.Repository;
|
using DOAN.Repository;
|
||||||
using DOAN.Service.BZFM.IBZFMService;
|
using DOAN.Service.BZFM.IBZFMService;
|
||||||
|
using Infrastructure;
|
||||||
|
using Infrastructure.Attribute;
|
||||||
|
using Infrastructure.Extensions;
|
||||||
|
|
||||||
namespace DOAN.Service.BZFM
|
namespace DOAN.Service.BZFM
|
||||||
{
|
{
|
||||||
@@ -109,5 +112,52 @@ namespace DOAN.Service.BZFM
|
|||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 导入数据
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="material"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public (string, object, object) Importmaterial(List<MmMaterialQueryDto> material)
|
||||||
|
{
|
||||||
|
material.ForEach(x =>
|
||||||
|
{
|
||||||
|
x.CreatedTime = DateTime.Now;
|
||||||
|
x.Status = "启用";
|
||||||
|
x.MaterialCode = "";
|
||||||
|
x.MaterialName = "E10ADC3949BA59ABBE56E057F20F883E";
|
||||||
|
//x.Remark = x.Remark.IsEmpty() ? "数据导入" : x.Remark;
|
||||||
|
});
|
||||||
|
var x = Context.Storageable(material)
|
||||||
|
.SplitInsert(it => !it.Any())
|
||||||
|
.SplitIgnore(it => it.Item.MaterialCode == GlobalConstant.AdminRole)
|
||||||
|
.SplitError(x => x.Item.MaterialCode.IsEmpty(), "物料编码不能为空")
|
||||||
|
.SplitError(x => !Tools.CheckUserName(x.Item.MaterialCode), "物料编码不符合规范")
|
||||||
|
.WhereColumns(it => it.MaterialCode)//如果不是主键可以这样实现(多字段it=>new{it.x1,it.x2})
|
||||||
|
.ToStorage();
|
||||||
|
var result = x.AsInsertable.ExecuteCommand();//插入可插入部分;
|
||||||
|
|
||||||
|
string msg = string.Format(" 插入{0} 更新{1} 错误数据{2} 不计算数据{3} 删除数据{4} 总共{5}",
|
||||||
|
x.InsertList.Count,
|
||||||
|
x.UpdateList.Count,
|
||||||
|
x.ErrorList.Count,
|
||||||
|
x.IgnoreList.Count,
|
||||||
|
x.DeleteList.Count,
|
||||||
|
x.TotalList.Count);
|
||||||
|
//输出统计
|
||||||
|
Console.WriteLine(msg);
|
||||||
|
|
||||||
|
//输出错误信息
|
||||||
|
foreach (var item in x.ErrorList)
|
||||||
|
{
|
||||||
|
Console.WriteLine("MaterialCode为" + item.Item.MaterialCode + " : " + item.StorageMessage);
|
||||||
|
}
|
||||||
|
foreach (var item in x.IgnoreList)
|
||||||
|
{
|
||||||
|
Console.WriteLine("MaterialCode为" + item.Item.MaterialCode + " : " + item.StorageMessage);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (msg, x.ErrorList, x.IgnoreList);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user