出入库功能模块
This commit is contained in:
@@ -1,11 +1,15 @@
|
||||
using DOAN.Admin.WebApi.Filters;
|
||||
using DOAN.Model;
|
||||
using DOAN.Model.BZFM;
|
||||
using DOAN.Model.BZFM.Dto;
|
||||
using DOAN.Model.System;
|
||||
using DOAN.Model.System.Dto;
|
||||
using DOAN.Service.BZFM;
|
||||
using DOAN.Service.BZFM.IBZFMService;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using MiniExcelLibs;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
|
||||
//创建时间:2025-12-25
|
||||
namespace DOAN.Admin.WebApi.Controllers.BZFM
|
||||
@@ -123,13 +127,65 @@ namespace DOAN.Admin.WebApi.Controllers.BZFM
|
||||
[ActionPermissionFilter(Permission = "mmmaterial:import")]
|
||||
public IActionResult ImportData([FromForm(Name = "file")] IFormFile formFile)
|
||||
{
|
||||
List<MmMaterialQueryDto> material = new();
|
||||
List<MmMaterial> material = new();
|
||||
using (var stream = formFile.OpenReadStream())
|
||||
{
|
||||
material = stream.Query<MmMaterialQueryDto>(startCell: "A2").ToList();
|
||||
material = stream.Query<MmMaterial>(startCell: "A2").ToList();
|
||||
}
|
||||
|
||||
return SUCCESS(_MmMaterialService.Importmaterial(material));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 下载物料导入模板
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet("importTemplate")]
|
||||
[Log(Title = "物料模板", BusinessType = BusinessType.EXPORT)]
|
||||
[AllowAnonymous]
|
||||
public IActionResult ImportTemplateExcel()
|
||||
{
|
||||
// create an empty sample list of export DTO to generate header row
|
||||
var sample = new List<MmMaterialQueryDto>();
|
||||
var result = DownloadImportTemplate(sample, "material");
|
||||
return ExportExcel(result.Item2, result.Item1);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 用户导出
|
||||
/// </summary>
|
||||
/// <param name="material"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("export")]
|
||||
[Log(Title = "物料清单导出", BusinessType = BusinessType.EXPORT)]
|
||||
[ActionPermissionFilter(Permission = "mmmaterial:export")]
|
||||
public IActionResult MaterialExport([FromQuery] MmMaterialQueryDto material)
|
||||
{
|
||||
var list = _MmMaterialService.SelectMaterialList(material, new PagerInfo(1, 10000));
|
||||
|
||||
var data = (list?.Result ?? new List<MmMaterial>());
|
||||
|
||||
// Build list of dictionaries to control column titles and format dates
|
||||
var exportList = data.Select(x => new Dictionary<string, object>
|
||||
{
|
||||
["物料编码"] = x.MaterialCode,
|
||||
["物料名称"] = x.MaterialName,
|
||||
["规格"] = x.Specification,
|
||||
["物料分类编码"] = x.CategoryCode,
|
||||
["物料分类名称"] = x.CategoryName,
|
||||
["计量单位"] = x.Unit,
|
||||
["物料类型"] = x.Type,
|
||||
["供应商编码"] = x.SupplierCode,
|
||||
["供应商名称"] = x.SupplierName,
|
||||
["安全库存"] = x.SafetyStock,
|
||||
["状态"] = x.Status,
|
||||
["创建时间"] = x.CreatedTime.HasValue ? x.CreatedTime.Value.ToString("yyyy-MM-dd HH:mm:ss") : string.Empty,
|
||||
["更新时间"] = x.UpdatedTime.HasValue ? x.UpdatedTime.Value.ToString("yyyy-MM-dd HH:mm:ss") : string.Empty,
|
||||
["描述"] = x.Description
|
||||
}).ToList();
|
||||
|
||||
var result = ExportExcelMini(exportList, "material", "物料清单");
|
||||
return ExportExcel(result.Item2, result.Item1);
|
||||
}
|
||||
}
|
||||
}
|
||||
BIN
DOAN.Admin.WebApi/wwwroot/ImportTemplate/material.xlsx
Normal file
BIN
DOAN.Admin.WebApi/wwwroot/ImportTemplate/material.xlsx
Normal file
Binary file not shown.
21
DOAN.Model/MES/Material/Dto/ImportResultDto.cs
Normal file
21
DOAN.Model/MES/Material/Dto/ImportResultDto.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
namespace DOAN.Model.BZFM.Dto
|
||||
{
|
||||
public class ImportErrorDto
|
||||
{
|
||||
public string MaterialCode { get; set; }
|
||||
public string Message { get; set; }
|
||||
}
|
||||
|
||||
public class ImportResultDto
|
||||
{
|
||||
public string Message { get; set; }
|
||||
public int Inserted { get; set; }
|
||||
public int Updated { get; set; }
|
||||
public int ErrorCount { get; set; }
|
||||
public int IgnoredCount { get; set; }
|
||||
public int Deleted { get; set; }
|
||||
public int Total { get; set; }
|
||||
public List<ImportErrorDto> Errors { get; set; } = new List<ImportErrorDto>();
|
||||
public List<ImportErrorDto> Ignored { get; set; } = new List<ImportErrorDto>();
|
||||
}
|
||||
}
|
||||
@@ -17,6 +17,8 @@ namespace DOAN.Model.BZFM.Dto
|
||||
public string Type { get; set; }
|
||||
public string Status { get; set; }
|
||||
public DateTime? CreatedTime { get; set; }
|
||||
|
||||
public int Id { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using DOAN.Model.BZFM;
|
||||
using DOAN.Model.BZFM.Dto;
|
||||
using DOAN.Model.System;
|
||||
using DOAN.Model.System.Dto;
|
||||
|
||||
namespace DOAN.Service.BZFM.IBZFMService
|
||||
{
|
||||
@@ -26,7 +27,9 @@ namespace DOAN.Service.BZFM.IBZFMService
|
||||
/// </summary>
|
||||
/// <param name="material"></param>
|
||||
/// <returns></returns>
|
||||
(string, object, object) Importmaterial(List<MmMaterial> material);
|
||||
ImportResultDto Importmaterial(List<MmMaterial> material);
|
||||
|
||||
public PagedInfo<MmMaterial> SelectMaterialList(MmMaterialQueryDto material, PagerInfo pager);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ using DOAN.Common;
|
||||
using DOAN.Model.BZFM;
|
||||
using DOAN.Model.BZFM.Dto;
|
||||
using DOAN.Model.System;
|
||||
using DOAN.Model.System.Dto;
|
||||
using DOAN.Repository;
|
||||
using DOAN.Service.BZFM.IBZFMService;
|
||||
using Infrastructure;
|
||||
@@ -118,14 +119,27 @@ namespace DOAN.Service.BZFM
|
||||
/// </summary>
|
||||
/// <param name="material"></param>
|
||||
/// <returns></returns>
|
||||
public (string, object, object) Importmaterial(List<MmMaterialQueryDto> material)
|
||||
public ImportResultDto Importmaterial(List<MmMaterial> 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 = "启用";
|
||||
x.MaterialCode = "";
|
||||
x.MaterialName = "E10ADC3949BA59ABBE56E057F20F883E";
|
||||
}
|
||||
if (!string.IsNullOrWhiteSpace(x.MaterialCode))
|
||||
{
|
||||
x.MaterialCode = x.MaterialCode.Trim();
|
||||
}
|
||||
if (!string.IsNullOrWhiteSpace(x.MaterialName))
|
||||
{
|
||||
x.MaterialName = x.MaterialName.Trim();
|
||||
}
|
||||
//x.Remark = x.Remark.IsEmpty() ? "数据导入" : x.Remark;
|
||||
});
|
||||
var x = Context.Storageable(material)
|
||||
@@ -137,27 +151,45 @@ namespace DOAN.Service.BZFM
|
||||
.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);
|
||||
var importResult = new ImportResultDto
|
||||
{
|
||||
Message = "导入完成",
|
||||
Inserted = x.InsertList.Count,
|
||||
Updated = x.UpdateList.Count,
|
||||
ErrorCount = x.ErrorList.Count,
|
||||
IgnoredCount = x.IgnoreList.Count,
|
||||
Deleted = x.DeleteList.Count,
|
||||
Total = x.TotalList.Count
|
||||
};
|
||||
//输出统计
|
||||
Console.WriteLine(msg);
|
||||
Console.WriteLine(importResult);
|
||||
|
||||
//输出错误信息
|
||||
// 收集错误与忽略信息
|
||||
foreach (var item in x.ErrorList)
|
||||
{
|
||||
Console.WriteLine("MaterialCode为" + item.Item.MaterialCode + " : " + item.StorageMessage);
|
||||
importResult.Errors.Add(new ImportErrorDto { MaterialCode = item.Item.MaterialCode, Message = item.StorageMessage });
|
||||
}
|
||||
foreach (var item in x.IgnoreList)
|
||||
{
|
||||
Console.WriteLine("MaterialCode为" + item.Item.MaterialCode + " : " + item.StorageMessage);
|
||||
importResult.Ignored.Add(new ImportErrorDto { MaterialCode = item.Item.MaterialCode, Message = item.StorageMessage });
|
||||
}
|
||||
|
||||
return (msg, x.ErrorList, x.IgnoreList);
|
||||
return importResult;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 导出物料表列表
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public PagedInfo<MmMaterial> SelectMaterialList(MmMaterialQueryDto material, PagerInfo pager)
|
||||
{
|
||||
// Use the same predicate builder as GetList to support consistent filtering
|
||||
var predicate = QueryExp(material);
|
||||
|
||||
var query = Queryable()
|
||||
.Where(predicate.ToExpression());
|
||||
|
||||
return query.ToPage(pager);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user