This commit is contained in:
gcw_MV9p2JJN 2025-11-19 11:49:05 +08:00
parent 204d04eb22
commit a293df3710
78 changed files with 84 additions and 31 deletions

View File

@ -47,7 +47,7 @@
<ProjectReference Include="..\DOAN.Model\DOAN.Model.csproj" /> <ProjectReference Include="..\DOAN.Model\DOAN.Model.csproj" />
<ProjectReference Include="..\DOAN.Service\DOAN.Service.csproj" /> <ProjectReference Include="..\DOAN.Service\DOAN.Service.csproj" />
<ProjectReference Include="..\DOAN.Tasks\DOAN.Tasks.csproj" /> <ProjectReference Include="..\DOAN.Tasks\DOAN.Tasks.csproj" />
<ProjectReference Include="..\MES_Model\MDM.csproj" /> <ProjectReference Include="..\MDM\MDM.csproj" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

View File

@ -14,6 +14,10 @@ using MDM.Model.Material.Dto;
using MDM.Model.Material; using MDM.Model.Material;
using MDM.Repository; using MDM.Repository;
using DOAN.Model.MES.base_.Dto; 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 //创建时间2025-11-15
namespace MDM.Controllers.Material namespace MDM.Controllers.Material
@ -130,6 +134,54 @@ namespace MDM.Controllers.Material
return SUCCESS(response); 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
);
}
} }
} }

View File

@ -15,6 +15,7 @@ using MDM.Model.Material;
using MDM.Services.Material; using MDM.Services.Material;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Hosting;
//创建时间2025-11-15 //创建时间2025-11-15
namespace MDM.Controllers.Material namespace MDM.Controllers.Material
@ -120,10 +121,11 @@ namespace MDM.Controllers.Material
[AllowAnonymous] [AllowAnonymous]
public IActionResult ImportTemplateExcel() public IActionResult ImportTemplateExcel()
{ {
string path = "./Assets/ImportTemplate"; IWebHostEnvironment webHostEnvironment = (IWebHostEnvironment)App.ServiceProvider.GetService(typeof(IWebHostEnvironment));
string sFileName = $"MaterialMODEL.xlsx"; // 使用Path.Combine构建正确的路径避免硬编码的路径分隔符
string fullPath = Path.Combine(path, sFileName); string fullPath = Path.Combine(webHostEnvironment.ContentRootPath, "..\\MDM", "Assets", "ImportTemplate", "MaterialMODEL.xlsx");
(string, string) result = (sFileName, fullPath);
(string, string) result = ("MaterialMODEL.xlsx", fullPath);
return ExportExcel(result.Item2, result.Item1); return ExportExcel(result.Item2, result.Item1);
} }

View File

@ -123,10 +123,10 @@ namespace MDM.Controllers.Material
public IActionResult ImportTemplateExcel() public IActionResult ImportTemplateExcel()
{ {
IWebHostEnvironment webHostEnvironment = (IWebHostEnvironment)App.ServiceProvider.GetService(typeof(IWebHostEnvironment)); IWebHostEnvironment webHostEnvironment = (IWebHostEnvironment)App.ServiceProvider.GetService(typeof(IWebHostEnvironment));
string path= "Assets/ImportTemplate"; // 使用Path.Combine构建正确的路径避免硬编码的路径分隔符
string sFileName = $"MaterialMODEL.xlsx"; string fullPath = Path.Combine(webHostEnvironment.ContentRootPath, "..\\MDM", "Assets", "ImportTemplate", "MaterialMODEL.xlsx");
string fullPath = Path.Combine(webHostEnvironment.ContentRootPath,path, sFileName);
(string, string) result = (sFileName,fullPath); (string, string) result = ("MaterialMODEL.xlsx", fullPath);
return ExportExcel(result.Item2, result.Item1); return ExportExcel(result.Item2, result.Item1);
} }

View File

@ -11,11 +11,12 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Resource Include="Assets\ImportTemplate\MaterialMODEL.xlsx"> <!-- 配置整个Assets目录确保所有资源文件都能被复制 -->
<None Include="Assets\**\*">
<ExcludeFromSingleFile>true</ExcludeFromSingleFile> <ExcludeFromSingleFile>true</ExcludeFromSingleFile>
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory> <CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
<CopyToOutputDirectory>Always</CopyToOutputDirectory> <CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Resource> </None>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

View File

@ -9,6 +9,7 @@ using MDM.Model.Material.Dto;
using MDM.Repository; using MDM.Repository;
using MDM.Service; using MDM.Service;
using MDM.Services.IMaterialService; using MDM.Services.IMaterialService;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using NPOI.SS.UserModel; using NPOI.SS.UserModel;
using NPOI.XSSF.UserModel; using NPOI.XSSF.UserModel;
@ -216,12 +217,10 @@ namespace MDM.Services.Material
public byte[] ExportData() public byte[] ExportData()
{ {
string templatePath = Path.Combine( IWebHostEnvironment webHostEnvironment = (IWebHostEnvironment)App.ServiceProvider.GetService(typeof(IWebHostEnvironment));
Directory.GetCurrentDirectory(), // 使用Path.Combine构建正确的路径避免硬编码的路径分隔符
"wwwroot", string templatePath = Path.Combine(webHostEnvironment.ContentRootPath, "..\\MDM", "Assets", "ImportTemplate", "MaterialMODEL.xlsx");
"ImportTemplate",
"MaterialMODEL.xlsx"
);
if (!global::System.IO.File.Exists(templatePath)) if (!global::System.IO.File.Exists(templatePath))
{ {

View File

@ -6,6 +6,7 @@ using MDM.Model.Material.Dto;
using MDM.Repository; using MDM.Repository;
using MDM.Service; using MDM.Service;
using MDM.Services.IMaterialService; using MDM.Services.IMaterialService;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using NPOI.SS.UserModel; using NPOI.SS.UserModel;
using NPOI.XSSF.UserModel; using NPOI.XSSF.UserModel;
@ -103,7 +104,7 @@ namespace MDM.Services.Material
try try
{ {
IWorkbook workbook = new XSSFWorkbook(stream); IWorkbook workbook = new XSSFWorkbook(stream);
ISheet sheet = workbook.GetSheet("物料列表"); ISheet sheet = workbook.GetSheet("物料类型");
List<MaterialList> materialLists = new List<MaterialList>(); List<MaterialList> materialLists = new List<MaterialList>();
// 遍历每一行 // 遍历每一行
for (int row = 1; row <= sheet.LastRowNum; row++) for (int row = 1; row <= sheet.LastRowNum; row++)
@ -225,12 +226,10 @@ namespace MDM.Services.Material
public byte[] ExportData() public byte[] ExportData()
{ {
string templatePath = Path.Combine( IWebHostEnvironment webHostEnvironment = (IWebHostEnvironment)App.ServiceProvider.GetService(typeof(IWebHostEnvironment));
Directory.GetCurrentDirectory(), // 使用Path.Combine构建正确的路径避免硬编码的路径分隔符
"Assets", string templatePath = Path.Combine(webHostEnvironment.ContentRootPath, "..\\MDM", "Assets", "ImportTemplate", "MaterialMODEL.xlsx");
"ImportTemplate",
"MaterialMODEL.xlsx"
);
if (!global::System.IO.File.Exists(templatePath)) if (!global::System.IO.File.Exists(templatePath))
{ {

View File

@ -11,6 +11,7 @@ using Infrastructure;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using NPOI.SS.UserModel; using NPOI.SS.UserModel;
using NPOI.XSSF.UserModel; using NPOI.XSSF.UserModel;
using Microsoft.AspNetCore.Hosting;
namespace MDM.Services.Material namespace MDM.Services.Material
{ {
/// <summary> /// <summary>
@ -169,12 +170,11 @@ namespace MDM.Services.Material
public byte[] ExportData() public byte[] ExportData()
{ {
string templatePath = Path.Combine(
Directory.GetCurrentDirectory(),
"wwwroot", IWebHostEnvironment webHostEnvironment = (IWebHostEnvironment)App.ServiceProvider.GetService(typeof(IWebHostEnvironment));
"ImportTemplate", // 使用Path.Combine构建正确的路径避免硬编码的路径分隔符
"MaterialMODEL.xlsx" string templatePath = Path.Combine(webHostEnvironment.ContentRootPath, "..\\MDM", "Assets", "ImportTemplate", "MaterialMODEL.xlsx");
);
if (!global::System.IO.File.Exists(templatePath)) if (!global::System.IO.File.Exists(templatePath))
{ {

View File

@ -21,7 +21,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DOAN.CodeGenerator", "DOAN.
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DOAN.ServiceCore", "DOAN.ServiceCore\DOAN.ServiceCore.csproj", "{4E2CC4E4-F109-4876-8498-912E13905765}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DOAN.ServiceCore", "DOAN.ServiceCore\DOAN.ServiceCore.csproj", "{4E2CC4E4-F109-4876-8498-912E13905765}"
EndProject 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 EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution