采购订单 导入导出

This commit is contained in:
qianhao.xu
2025-02-17 17:02:30 +08:00
parent 4c94e6f743
commit cbb6caf970
6 changed files with 176 additions and 5 deletions

View File

@@ -1,5 +1,6 @@
using DOAN.Model.MES.order.Dto;
using DOAN.Model.MES.order;
using Microsoft.AspNetCore.Http;
namespace DOAN.Service.MES.order.IService
{
@@ -12,10 +13,12 @@ namespace DOAN.Service.MES.order.IService
OrderPurchase GetInfo(string Id);
int ImportData(IFormFile formFile, string username);
OrderPurchase AddOrderPurchase(OrderPurchase parm);
int UpdateOrderPurchase(OrderPurchase parm);
List<OrderPurchaseDto> SelectOrderList(OrderPurchaseQueryDto orderPurchaseDto);
}
}

View File

@@ -4,6 +4,12 @@ using DOAN.Service.MES.order.IService;
using DOAN.Repository;
using DOAN.Model.MES.order.Dto;
using DOAN.Model.MES.order;
using Microsoft.AspNetCore.Http;
using NPOI.SS.UserModel;
using NPOI.XSSF.UserModel;
using NPOI.SS.Formula.Functions;
using Aliyun.OSS;
using Mapster;
namespace DOAN.Service.MES.order
{
@@ -75,5 +81,109 @@ namespace DOAN.Service.MES.order
return predicate;
}
public int ImportData(IFormFile formFile, string username)
{
List<OrderPurchase> orderPurchases = new List<OrderPurchase>();
DateTime importDate = DateTime.MinValue;
using (var stream = formFile.OpenReadStream())
{
try
{
IWorkbook workbook = new XSSFWorkbook(stream);
ISheet sheet = workbook.GetSheetAt(0);
IRow secondRow = sheet.GetRow(1);
NPOI.SS.UserModel.ICell cell = secondRow.GetCell(1);
// 将单元格的数字值转换为DateTime
importDate = cell.DateCellValue.Value;
// 遍历每一行
for (int row = 4; row <= sheet.LastRowNum; row++)
{
IRow currentRow = sheet.GetRow(row);
if (currentRow != null) // 确保行不为空
{
OrderPurchase model = new OrderPurchase();
model.Id = SnowFlakeSingle.Instance.NextId().ToString();
model.OrderNoMes = currentRow.GetCell(0)?.ToString();
model.PurchaseOrderErp = currentRow.GetCell(1)?.ToString();
model.Poitem = currentRow.GetCell(2)?.ToString();
model.Variety = currentRow.GetCell(3)?.ToString();
string specordindicator= currentRow.GetCell(4)?.ToString();
if(!string.IsNullOrEmpty(specordindicator)&&specordindicator=="是")
{
model.Specordindicator = 1;
}
else if(!string.IsNullOrEmpty(specordindicator) && specordindicator == "否")
{
model.Specordindicator = 0;
}
else
{
model.Specordindicator = -1;
}
model.KdType = currentRow.GetCell(5)?.ToString();
model.DocumentDate = currentRow.GetCell(6).DateCellValue.Value;
model.Seller = currentRow.GetCell(7)?.ToString();
model.SalesArea = currentRow.GetCell(8)?.ToString();
model.MaterialName = currentRow.GetCell(9)?.ToString();
model.MaterialCode = currentRow.GetCell(10)?.ToString();
model.DemandQuantity = (int)currentRow.GetCell(11).NumericCellValue;
model.DeliveryDate= currentRow.GetCell(12).DateCellValue.Value;
model.DeliveryQuantity = (int)currentRow.GetCell(13).NumericCellValue;
model.StartDate = currentRow.GetCell(14).DateCellValue.Value;
model.EndDate = currentRow.GetCell(15).DateCellValue.Value;
string Orderindicator = currentRow.GetCell(16)?.ToString();
if (!string.IsNullOrEmpty(Orderindicator) && Orderindicator == "是")
{
model.Orderindicator = 1;
}
else if (!string.IsNullOrEmpty(Orderindicator) && Orderindicator == "否")
{
model.Orderindicator = 0;
}
else
{
model.Orderindicator = -1;
}
model.RouteCode = currentRow.GetCell(17)?.ToString();
model.Remark = currentRow.GetCell(18)?.ToString();
model.ImportDate = importDate;
model.CreatedTime = importDate;
model.CreatedBy = username;
orderPurchases.Add(model);
}
}
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
if(orderPurchases.Count>0)
{
return Context.Insertable(orderPurchases).ExecuteCommand();
}
else
{
return 0;
}
}
public List<OrderPurchaseDto> SelectOrderList(OrderPurchaseQueryDto orderPurchaseDto)
{
var predicate = QueryExp(orderPurchaseDto);
var response = Queryable()
.Where(predicate.ToExpression()).Adapt<List<OrderPurchaseDto>>();
return response;
}
}
}