Valeo_Line_MES_backend/MDM/Controllers/Material/MaterialListController.cs
2026-01-16 10:41:38 +08:00

179 lines
5.9 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using Microsoft.AspNetCore.Mvc;
using RIZO.Admin.WebApi.Filters;
using Infrastructure.Controllers;
using RIZO.ServiceCore.Middleware;
using Mapster;
using Infrastructure.Enums;
using Infrastructure;
using Infrastructure.Attribute;
using RIZO.Common;
using Infrastructure.Model;
using MDM.Services.IMaterialService;
using MDM.Model.Material.Dto;
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
{
/// <summary>
/// 物料清单
/// </summary>
[AllowAnonymous]
[Route("MasterDataManagement/Material/MaterialList")]
public class MaterialListController : BaseController
{
/// <summary>
/// 物料清单接口
/// </summary>
private readonly IMaterialListService _MaterialListService;
public MaterialListController(IMaterialListService MaterialListService)
{
_MaterialListService = MaterialListService;
}
/// <summary>
/// 查询物料清单列表
/// </summary>
/// <param name="parm"></param>
/// <returns></returns>
[HttpGet("list")]
[ActionPermissionFilter(Permission = "business:materiallist:list")]
public IActionResult QueryMaterialList([FromQuery] MaterialListQueryDto parm)
{
var response = _MaterialListService.GetList(parm);
return SUCCESS(response);
}
/// <summary>
/// 查询物料清单详情
/// </summary>
/// <param name="Id"></param>
/// <returns></returns>
[HttpGet("{Id}")]
[ActionPermissionFilter(Permission = "business:materiallist:query")]
public IActionResult GetMaterialList(string Id)
{
var response = _MaterialListService.GetInfo(Id);
var info = response.Adapt<MaterialList>();
return SUCCESS(info);
}
/// <summary>
/// 添加物料清单
/// </summary>
/// <returns></returns>
[HttpPost]
[ActionPermissionFilter(Permission = "business:materiallist:add")]
[Log(Title = "物料清单", BusinessType = BusinessType.INSERT)]
public IActionResult AddMaterialList([FromBody] MaterialListDto parm)
{
var modal = parm.Adapt<MaterialList>().ToCreate(HttpContext);
var response = _MaterialListService.AddMaterialList(modal);
return SUCCESS(response);
}
/// <summary>
/// 更新物料清单
/// </summary>
/// <returns></returns>
[HttpPut]
[ActionPermissionFilter(Permission = "business:materiallist:edit")]
[Log(Title = "物料清单", BusinessType = BusinessType.UPDATE)]
public IActionResult UpdateMaterialList([FromBody] MaterialListDto parm)
{
var modal = parm.Adapt<MaterialList>().ToUpdate(HttpContext);
var response = _MaterialListService.UpdateMaterialList(modal);
return ToResponse(response);
}
/// <summary>
/// 删除物料清单
/// </summary>
/// <returns></returns>
[HttpDelete("{ids}")]
[ActionPermissionFilter(Permission = "business:materiallist:delete")]
[Log(Title = "物料清单", BusinessType = BusinessType.DELETE)]
public IActionResult DeleteMaterialList(string ids)
{
int[] idsArr = Tools.SpitIntArrary(ids);
if (idsArr.Length <= 0) { return ToResponse(ApiResult.Error($"删除失败Id 不能为空")); }
var response = _MaterialListService.Delete(idsArr);
return ToResponse(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 = _MaterialListService.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 = _MaterialListService.ExportData();
string fileName = $"PlanAchievementRate_{DateTime.Now.Date:yyyyMMdd}.xlsx";
return File(
excelBytes,
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
fileName
);
}
[HttpGet("getMaterialTypePullDown")]
public ApiResult GetMaterialTypePullDown()
{
var response = _MaterialListService.GetMaterialTypePullDown();
return response;
}
}
}