Valeo_Line_MES_backend/MDM/Controllers/Material/MaterialListController.cs

179 lines
5.9 KiB
C#
Raw Normal View History

2026-01-10 13:47:54 +08:00
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>
2026-01-15 15:14:19 +08:00
[AllowAnonymous]
2026-01-10 13:47:54 +08:00
[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")]
2026-01-16 10:40:58 +08:00
public IActionResult GetMaterialList(string Id)
2026-01-10 13:47:54 +08:00
{
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")]
2026-01-15 15:14:19 +08:00
[Log(Title = "物料清单模板", BusinessType = BusinessType.EXPORT, IsSaveRequestData = true, IsSaveResponseData = false)]
2026-01-10 13:47:54 +08:00
[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")]
2026-01-15 15:14:19 +08:00
[Log(Title = "物料清单导入", BusinessType = BusinessType.IMPORT, IsSaveRequestData = false, IsSaveResponseData = true)]
2026-01-10 13:47:54 +08:00
[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")]
2026-01-15 15:14:19 +08:00
[Log(Title = "物料清单导出", BusinessType = BusinessType.EXPORT, IsSaveRequestData = true, IsSaveResponseData = false)]
2026-01-10 13:47:54 +08:00
[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
);
}
2026-01-15 15:14:19 +08:00
[HttpGet("getMaterialTypePullDown")]
public ApiResult GetMaterialTypePullDown()
{
var response = _MaterialListService.GetMaterialTypePullDown();
return response;
}
2026-01-10 13:47:54 +08:00
2026-01-13 16:40:35 +08:00
2026-01-10 13:47:54 +08:00
}
}