采购订单 导入导出

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

@ -5,6 +5,10 @@ using DOAN.Service.MES.order.IService;
using DOAN.Admin.WebApi.Filters;
using DOAN.Model.MES.order.Dto;
using DOAN.Model.MES.order;
using DOAN.Model.System.Dto;
using DOAN.Model;
using DOAN.Model.System;
using MiniExcelLibs;
//创建时间2025-02-17
namespace DOAN.Admin.WebApi.Controllers
@ -100,5 +104,59 @@ namespace DOAN.Admin.WebApi.Controllers
return ToResponse(_OrderPurchaseService.Delete(idArr));
}
//TODO 下载模版
/// <summary>
/// 导入模板下载
/// </summary>
/// <returns></returns>
[HttpGet("importTemplate")]
[Log(Title = "订单模板", BusinessType = BusinessType.EXPORT, IsSaveRequestData = true, IsSaveResponseData = false)]
[AllowAnonymous]
public IActionResult ImportTemplateExcel()
{
(string, string) result = DownloadImportTemplate("order");
return ExportExcel(result.Item2, result.Item1);
}
/// <summary>
/// 采购导入
/// </summary>
/// <param name="formFile">使用IFromFile必须使用name属性否则获取不到文件</param>
/// <returns></returns>
[HttpPost("importData")]
[Log(Title = "采购导入", BusinessType = BusinessType.IMPORT, IsSaveRequestData = false, IsSaveResponseData = true)]
[ActionPermissionFilter(Permission = "system:user:import")]
public IActionResult ImportData([FromForm(Name = "file")] IFormFile formFile)
{
if (formFile == null)
{
return SUCCESS(null);
}
int response = _OrderPurchaseService.ImportData(formFile, HttpContext.GetName());
return SUCCESS(response);
}
/// <summary>
/// 采购订单excel导出
/// </summary>
/// <param name="user"></param>
/// <returns></returns>
[HttpGet("export")]
[Log(Title = "用户导出", BusinessType = BusinessType.EXPORT)]
[ActionPermissionFilter(Permission = "system:user:export")]
public IActionResult UserExport([FromQuery] OrderPurchaseQueryDto order)
{
var list = _OrderPurchaseService.SelectOrderList(order);
var result = ExportExcelMini(list, "order", "采购订单列表");
return ExportExcel(result.Item2, result.Item1);
}
}
}

Binary file not shown.

View File

@ -26,7 +26,7 @@ namespace DOAN.Model.MES.order.Dto
public string Variety { get; set; }
public string Specordindicator { get; set; }
public int Specordindicator { get; set; }
public string KdType { get; set; }
@ -50,7 +50,7 @@ namespace DOAN.Model.MES.order.Dto
public DateTime? EndDate { get; set; }
public string Orderindicator { get; set; }
public int Orderindicator { get; set; }
public string RouteCode { get; set; }

View File

@ -44,7 +44,7 @@ namespace DOAN.Model.MES.order
/// <summary>
/// 是否非标
/// </summary>
public string Specordindicator { get; set; }
public int Specordindicator { get; set; }
/// <summary>
/// 类型
@ -114,7 +114,7 @@ namespace DOAN.Model.MES.order
/// <summary>
/// 订单是否完成
/// </summary>
public string Orderindicator { get; set; }
public int Orderindicator { get; set; }
/// <summary>
/// 短描述(所属产线)

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;
}
}
}