1
This commit is contained in:
parent
204d04eb22
commit
a293df3710
@ -47,7 +47,7 @@
|
||||
<ProjectReference Include="..\DOAN.Model\DOAN.Model.csproj" />
|
||||
<ProjectReference Include="..\DOAN.Service\DOAN.Service.csproj" />
|
||||
<ProjectReference Include="..\DOAN.Tasks\DOAN.Tasks.csproj" />
|
||||
<ProjectReference Include="..\MES_Model\MDM.csproj" />
|
||||
<ProjectReference Include="..\MDM\MDM.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@ -14,6 +14,10 @@ using MDM.Model.Material.Dto;
|
||||
using MDM.Model.Material;
|
||||
using MDM.Repository;
|
||||
using DOAN.Model.MES.base_.Dto;
|
||||
using MDM.Services.Material;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
|
||||
//创建时间:2025-11-15
|
||||
namespace MDM.Controllers.Material
|
||||
@ -130,6 +134,54 @@ namespace MDM.Controllers.Material
|
||||
return SUCCESS(response);
|
||||
}
|
||||
|
||||
//TODO 导出模板
|
||||
[HttpGet("importTemplate")]
|
||||
[Log(Title = "物料类型模板", BusinessType = BusinessType.EXPORT, IsSaveRequestData = true, IsSaveResponseData = false)]
|
||||
[AllowAnonymous]
|
||||
public IActionResult ImportTemplateExcel()
|
||||
{
|
||||
IWebHostEnvironment webHostEnvironment = (IWebHostEnvironment)App.ServiceProvider.GetService(typeof(IWebHostEnvironment));
|
||||
// 使用Path.Combine构建正确的路径,避免硬编码的路径分隔符
|
||||
string fullPath = Path.Combine(webHostEnvironment.ContentRootPath, "..\\MDM", "Assets", "ImportTemplate", "MaterialMODEL.xlsx");
|
||||
|
||||
(string, string) result = ("MaterialMODEL.xlsx", fullPath);
|
||||
return ExportExcel(result.Item2, result.Item1);
|
||||
}
|
||||
|
||||
|
||||
//TODO 导入excel
|
||||
[HttpPost("importData")]
|
||||
[Log(Title = "物料类型导入", BusinessType = BusinessType.IMPORT, IsSaveRequestData = false, IsSaveResponseData = true)]
|
||||
[AllowAnonymous]
|
||||
public IActionResult ImportData([FromForm(Name = "file")] IFormFile formFile)
|
||||
{
|
||||
|
||||
if (formFile == null)
|
||||
{
|
||||
return SUCCESS(null);
|
||||
}
|
||||
int response = _MaterialBomService.ImportData(formFile, HttpContext.GetName());
|
||||
|
||||
return SUCCESS(response);
|
||||
}
|
||||
|
||||
//TODO 导出excel
|
||||
[HttpGet("exportData")]
|
||||
[Log(Title = "物料类型导出", BusinessType = BusinessType.EXPORT, IsSaveRequestData = true, IsSaveResponseData = false)]
|
||||
[AllowAnonymous]
|
||||
public IActionResult ExportData()
|
||||
{
|
||||
|
||||
var excelBytes = _MaterialBomService.ExportData();
|
||||
string fileName = $"PlanAchievementRate_{DateTime.Now.Date:yyyyMMdd}.xlsx";
|
||||
return File(
|
||||
excelBytes,
|
||||
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
||||
fileName
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@ -15,6 +15,7 @@ using MDM.Model.Material;
|
||||
using MDM.Services.Material;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
|
||||
//创建时间:2025-11-15
|
||||
namespace MDM.Controllers.Material
|
||||
@ -120,10 +121,11 @@ namespace MDM.Controllers.Material
|
||||
[AllowAnonymous]
|
||||
public IActionResult ImportTemplateExcel()
|
||||
{
|
||||
string path = "./Assets/ImportTemplate";
|
||||
string sFileName = $"MaterialMODEL.xlsx";
|
||||
string fullPath = Path.Combine(path, sFileName);
|
||||
(string, string) result = (sFileName, fullPath);
|
||||
IWebHostEnvironment webHostEnvironment = (IWebHostEnvironment)App.ServiceProvider.GetService(typeof(IWebHostEnvironment));
|
||||
// 使用Path.Combine构建正确的路径,避免硬编码的路径分隔符
|
||||
string fullPath = Path.Combine(webHostEnvironment.ContentRootPath, "..\\MDM", "Assets", "ImportTemplate", "MaterialMODEL.xlsx");
|
||||
|
||||
(string, string) result = ("MaterialMODEL.xlsx", fullPath);
|
||||
return ExportExcel(result.Item2, result.Item1);
|
||||
}
|
||||
|
||||
@ -123,10 +123,10 @@ namespace MDM.Controllers.Material
|
||||
public IActionResult ImportTemplateExcel()
|
||||
{
|
||||
IWebHostEnvironment webHostEnvironment = (IWebHostEnvironment)App.ServiceProvider.GetService(typeof(IWebHostEnvironment));
|
||||
string path= "Assets/ImportTemplate";
|
||||
string sFileName = $"MaterialMODEL.xlsx";
|
||||
string fullPath = Path.Combine(webHostEnvironment.ContentRootPath,path, sFileName);
|
||||
(string, string) result = (sFileName,fullPath);
|
||||
// 使用Path.Combine构建正确的路径,避免硬编码的路径分隔符
|
||||
string fullPath = Path.Combine(webHostEnvironment.ContentRootPath, "..\\MDM", "Assets", "ImportTemplate", "MaterialMODEL.xlsx");
|
||||
|
||||
(string, string) result = ("MaterialMODEL.xlsx", fullPath);
|
||||
return ExportExcel(result.Item2, result.Item1);
|
||||
}
|
||||
|
||||
@ -11,11 +11,12 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Resource Include="Assets\ImportTemplate\MaterialMODEL.xlsx">
|
||||
<!-- 配置整个Assets目录,确保所有资源文件都能被复制 -->
|
||||
<None Include="Assets\**\*">
|
||||
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
|
||||
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</Resource>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
@ -9,6 +9,7 @@ using MDM.Model.Material.Dto;
|
||||
using MDM.Repository;
|
||||
using MDM.Service;
|
||||
using MDM.Services.IMaterialService;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using NPOI.SS.UserModel;
|
||||
using NPOI.XSSF.UserModel;
|
||||
@ -216,12 +217,10 @@ namespace MDM.Services.Material
|
||||
|
||||
public byte[] ExportData()
|
||||
{
|
||||
string templatePath = Path.Combine(
|
||||
Directory.GetCurrentDirectory(),
|
||||
"wwwroot",
|
||||
"ImportTemplate",
|
||||
"MaterialMODEL.xlsx"
|
||||
);
|
||||
IWebHostEnvironment webHostEnvironment = (IWebHostEnvironment)App.ServiceProvider.GetService(typeof(IWebHostEnvironment));
|
||||
// 使用Path.Combine构建正确的路径,避免硬编码的路径分隔符
|
||||
string templatePath = Path.Combine(webHostEnvironment.ContentRootPath, "..\\MDM", "Assets", "ImportTemplate", "MaterialMODEL.xlsx");
|
||||
|
||||
|
||||
if (!global::System.IO.File.Exists(templatePath))
|
||||
{
|
||||
@ -6,6 +6,7 @@ using MDM.Model.Material.Dto;
|
||||
using MDM.Repository;
|
||||
using MDM.Service;
|
||||
using MDM.Services.IMaterialService;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using NPOI.SS.UserModel;
|
||||
using NPOI.XSSF.UserModel;
|
||||
@ -103,7 +104,7 @@ namespace MDM.Services.Material
|
||||
try
|
||||
{
|
||||
IWorkbook workbook = new XSSFWorkbook(stream);
|
||||
ISheet sheet = workbook.GetSheet("物料列表");
|
||||
ISheet sheet = workbook.GetSheet("物料类型");
|
||||
List<MaterialList> materialLists = new List<MaterialList>();
|
||||
// 遍历每一行
|
||||
for (int row = 1; row <= sheet.LastRowNum; row++)
|
||||
@ -225,12 +226,10 @@ namespace MDM.Services.Material
|
||||
|
||||
public byte[] ExportData()
|
||||
{
|
||||
string templatePath = Path.Combine(
|
||||
Directory.GetCurrentDirectory(),
|
||||
"Assets",
|
||||
"ImportTemplate",
|
||||
"MaterialMODEL.xlsx"
|
||||
);
|
||||
IWebHostEnvironment webHostEnvironment = (IWebHostEnvironment)App.ServiceProvider.GetService(typeof(IWebHostEnvironment));
|
||||
// 使用Path.Combine构建正确的路径,避免硬编码的路径分隔符
|
||||
string templatePath = Path.Combine(webHostEnvironment.ContentRootPath, "..\\MDM", "Assets", "ImportTemplate", "MaterialMODEL.xlsx");
|
||||
|
||||
|
||||
if (!global::System.IO.File.Exists(templatePath))
|
||||
{
|
||||
@ -11,6 +11,7 @@ using Infrastructure;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using NPOI.SS.UserModel;
|
||||
using NPOI.XSSF.UserModel;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
namespace MDM.Services.Material
|
||||
{
|
||||
/// <summary>
|
||||
@ -169,12 +170,11 @@ namespace MDM.Services.Material
|
||||
|
||||
public byte[] ExportData()
|
||||
{
|
||||
string templatePath = Path.Combine(
|
||||
Directory.GetCurrentDirectory(),
|
||||
"wwwroot",
|
||||
"ImportTemplate",
|
||||
"MaterialMODEL.xlsx"
|
||||
);
|
||||
|
||||
|
||||
IWebHostEnvironment webHostEnvironment = (IWebHostEnvironment)App.ServiceProvider.GetService(typeof(IWebHostEnvironment));
|
||||
// 使用Path.Combine构建正确的路径,避免硬编码的路径分隔符
|
||||
string templatePath = Path.Combine(webHostEnvironment.ContentRootPath, "..\\MDM", "Assets", "ImportTemplate", "MaterialMODEL.xlsx");
|
||||
|
||||
if (!global::System.IO.File.Exists(templatePath))
|
||||
{
|
||||
@ -21,7 +21,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DOAN.CodeGenerator", "DOAN.
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DOAN.ServiceCore", "DOAN.ServiceCore\DOAN.ServiceCore.csproj", "{4E2CC4E4-F109-4876-8498-912E13905765}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MDM", "MES_Model\MDM.csproj", "{95026B00-9C87-4175-AAC4-6B46DE5AD2A5}"
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MDM", "MDM\MDM.csproj", "{95026B00-9C87-4175-AAC4-6B46DE5AD2A5}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user