导入导出
This commit is contained in:
@@ -127,10 +127,10 @@ namespace DOAN.Admin.WebApi.Controllers.BZFM
|
|||||||
[ActionPermissionFilter(Permission = "mmmaterial:import")]
|
[ActionPermissionFilter(Permission = "mmmaterial:import")]
|
||||||
public IActionResult ImportData([FromForm(Name = "file")] IFormFile formFile)
|
public IActionResult ImportData([FromForm(Name = "file")] IFormFile formFile)
|
||||||
{
|
{
|
||||||
List<MmMaterialExcelDto2> material = new();
|
List<MmMaterialExcelDto> material = new();
|
||||||
using (var stream = formFile.OpenReadStream())
|
using (var stream = formFile.OpenReadStream())
|
||||||
{
|
{
|
||||||
material = stream.Query<MmMaterialExcelDto2>(startCell: "A2").ToList();
|
material = stream.Query<MmMaterialExcelDto>(startCell: "A2").ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
return SUCCESS(_MmMaterialService.Importmaterial(material));
|
return SUCCESS(_MmMaterialService.Importmaterial(material));
|
||||||
|
|||||||
@@ -126,55 +126,4 @@ namespace DOAN.Model.BZFM.Dto
|
|||||||
[ExcelColumn(Name = "描述")]
|
[ExcelColumn(Name = "描述")]
|
||||||
public string Description { get; set; }
|
public string Description { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
// <summary>
|
|
||||||
/// 物料清单导入导出
|
|
||||||
/// </summary>
|
|
||||||
public class MmMaterialExcelDto2
|
|
||||||
{
|
|
||||||
[ExcelColumn(Name = "id")]
|
|
||||||
public int Id { get; set; }
|
|
||||||
|
|
||||||
[ExcelColumn(Name = "物料标号")]
|
|
||||||
public string 物料标号 { get; set; }
|
|
||||||
|
|
||||||
[ExcelColumn(Name = "物料编码")]
|
|
||||||
public string 物料编码 { get; set; }
|
|
||||||
|
|
||||||
[ExcelColumn(Name = "物料名称")]
|
|
||||||
public string 物料名称 { get; set; }
|
|
||||||
|
|
||||||
[ExcelColumn(Name = "规格")]
|
|
||||||
public string 规格 { get; set; }
|
|
||||||
|
|
||||||
[ExcelColumn(Name = "物料分类编码")]
|
|
||||||
public string 物料分类编码 { get; set; }
|
|
||||||
|
|
||||||
[ExcelColumn(Name = "物料分类名称")]
|
|
||||||
public string 物料分类名称 { get; set; }
|
|
||||||
|
|
||||||
[ExcelColumn(Name = "计量单位")]
|
|
||||||
public string 计量单位 { get; set; }
|
|
||||||
|
|
||||||
[ExcelColumn(Name = "供应商编码")]
|
|
||||||
public string 供应商编码 { get; set; }
|
|
||||||
|
|
||||||
[ExcelColumn(Name = "供应商名称")]
|
|
||||||
public string 供应商名称 { get; set; }
|
|
||||||
|
|
||||||
[ExcelColumn(Name = "安全库存")]
|
|
||||||
public decimal 安全库存 { get; set; }
|
|
||||||
|
|
||||||
[ExcelColumn(Name = "状态")]
|
|
||||||
public string 状态 { get; set; }
|
|
||||||
|
|
||||||
[ExcelColumn(Name = "创建时间")]
|
|
||||||
public DateTime? 创建时间 { get; set; }
|
|
||||||
|
|
||||||
[ExcelColumn(Name = "更新时间")]
|
|
||||||
public DateTime? 更新时间 { get; set; }
|
|
||||||
|
|
||||||
[ExcelColumn(Name = "描述")]
|
|
||||||
public string 描述 { get; set; }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -27,7 +27,7 @@ namespace DOAN.Service.BZFM.IBZFMService
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="material"></param>
|
/// <param name="material"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
ImportResultDto Importmaterial(List<MmMaterialExcelDto2> material);
|
ImportResultDto Importmaterial(List<MmMaterialExcelDto> material);
|
||||||
|
|
||||||
public PagedInfo<MmMaterialExcelDto> SelectMaterialList(MmMaterialQueryDto material, PagerInfo pager);
|
public PagedInfo<MmMaterialExcelDto> SelectMaterialList(MmMaterialQueryDto material, PagerInfo pager);
|
||||||
|
|
||||||
|
|||||||
@@ -138,33 +138,33 @@ namespace DOAN.Service.BZFM
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="material"></param>
|
/// <param name="material"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public ImportResultDto Importmaterial(List<MmMaterialExcelDto2> material)
|
public ImportResultDto Importmaterial(List<MmMaterialExcelDto> material)
|
||||||
{
|
{
|
||||||
// normalize and set defaults, do not overwrite provided values
|
// normalize and set defaults, do not overwrite provided values
|
||||||
//material.ForEach(x =>
|
material.ForEach(x =>
|
||||||
//{
|
{
|
||||||
// if (x.CreatedTime == null)
|
if (x.CreatedTime == null)
|
||||||
// {
|
{
|
||||||
// x.CreatedTime = DateTime.Now;
|
x.CreatedTime = DateTime.Now;
|
||||||
// }
|
}
|
||||||
// if (string.IsNullOrWhiteSpace(x.Status))
|
if (string.IsNullOrWhiteSpace(x.Status))
|
||||||
// {
|
{
|
||||||
// x.Status = "启用";
|
x.Status = "启用";
|
||||||
// }
|
}
|
||||||
// if (!string.IsNullOrWhiteSpace(x.MaterialCode))
|
if (!string.IsNullOrWhiteSpace(x.MaterialCode))
|
||||||
// {
|
{
|
||||||
// x.MaterialCode = x.MaterialCode.Trim();
|
x.MaterialCode = x.MaterialCode.Trim();
|
||||||
// }
|
}
|
||||||
// if (!string.IsNullOrWhiteSpace(x.MaterialName))
|
if (!string.IsNullOrWhiteSpace(x.MaterialName))
|
||||||
// {
|
{
|
||||||
// x.MaterialName = x.MaterialName.Trim();
|
x.MaterialName = x.MaterialName.Trim();
|
||||||
// }
|
}
|
||||||
// x.Description = x.Description.IsEmpty() ? "数据导入" : x.Description;
|
x.Description = x.Description.IsEmpty() ? "数据导入" : x.Description;
|
||||||
//});
|
});
|
||||||
var x = Context
|
var x = Context
|
||||||
.Storageable(material)
|
.Storageable(material)
|
||||||
.SplitInsert(it => !it.Any())
|
.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();
|
.ToStorage();
|
||||||
var result = x.AsInsertable.ExecuteCommand(); //插入可插入部分;
|
var result = x.AsInsertable.ExecuteCommand(); //插入可插入部分;
|
||||||
|
|
||||||
@@ -182,26 +182,26 @@ namespace DOAN.Service.BZFM
|
|||||||
Console.WriteLine(importResult);
|
Console.WriteLine(importResult);
|
||||||
|
|
||||||
// 收集错误与忽略信息
|
// 收集错误与忽略信息
|
||||||
//foreach (var item in x.ErrorList)
|
foreach (var item in x.ErrorList)
|
||||||
//{
|
{
|
||||||
// importResult.Errors.Add(
|
importResult.Errors.Add(
|
||||||
// new ImportErrorDto
|
new ImportErrorDto
|
||||||
// {
|
{
|
||||||
// MaterialCode = item.Item.MaterialCode,
|
MaterialCode = item.Item.MaterialCode,
|
||||||
// Message = item.StorageMessage,
|
Message = item.StorageMessage,
|
||||||
// }
|
}
|
||||||
// );
|
);
|
||||||
//}
|
}
|
||||||
//foreach (var item in x.IgnoreList)
|
foreach (var item in x.IgnoreList)
|
||||||
//{
|
{
|
||||||
// importResult.Ignored.Add(
|
importResult.Ignored.Add(
|
||||||
// new ImportErrorDto
|
new ImportErrorDto
|
||||||
// {
|
{
|
||||||
// MaterialCode = item.Item.MaterialCode,
|
MaterialCode = item.Item.MaterialCode,
|
||||||
// Message = item.StorageMessage,
|
Message = item.StorageMessage,
|
||||||
// }
|
}
|
||||||
// );
|
);
|
||||||
//}
|
}
|
||||||
|
|
||||||
return importResult;
|
return importResult;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user