导入导出

This commit is contained in:
2026-01-07 15:25:05 +08:00
parent 82a49eab42
commit 2e3b0ea8ee
3 changed files with 5 additions and 8 deletions

View File

@@ -127,10 +127,10 @@ namespace DOAN.Admin.WebApi.Controllers.BZFM
[ActionPermissionFilter(Permission = "mmmaterial:import")]
public IActionResult ImportData([FromForm(Name = "file")] IFormFile formFile)
{
List<MmMaterial> material = new();
List<MmMaterialExcelDto> material = new();
using (var stream = formFile.OpenReadStream())
{
material = stream.Query<MmMaterial>(startCell: "A2").ToList();
material = stream.Query<MmMaterialExcelDto>(startCell: "A2").ToList();
}
return SUCCESS(_MmMaterialService.Importmaterial(material));

View File

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

View File

@@ -119,7 +119,7 @@ namespace DOAN.Service.BZFM
/// </summary>
/// <param name="material"></param>
/// <returns></returns>
public ImportResultDto Importmaterial(List<MmMaterial> material)
public ImportResultDto Importmaterial(List<MmMaterialExcelDto> material)
{
// normalize and set defaults, do not overwrite provided values
material.ForEach(x =>
@@ -140,13 +140,10 @@ namespace DOAN.Service.BZFM
{
x.MaterialName = x.MaterialName.Trim();
}
x.Remark = x.Remark.IsEmpty() ? "数据导入" : x.Remark;
x.Description = x.Description.IsEmpty() ? "数据导入" : x.Description;
});
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 => new { it.Id, it.MaterialCode })//如果不是主键可以这样实现多字段it=>new{it.x1,it.x2}
.ToStorage();
var result = x.AsInsertable.ExecuteCommand();//插入可插入部分;