Valeo_Line_MES_backend/MDM/Controllers/Material/MaterialBomController.cs
2026-01-10 13:47:54 +08:00

187 lines
6.1 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.Repository;
using MDM.Services.Material;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
//创建时间2025-11-15
namespace MDM.Controllers.Material
{
/// <summary>
/// BOM清单
/// </summary>
[Verify]
[Route("MasterDataManagement/Material/MaterialBom")]
public class MaterialBomController : BaseController
{
/// <summary>
/// 接口
/// </summary>
private readonly IMaterialBomService _MaterialBomService;
public MaterialBomController(IMaterialBomService MaterialBomService)
{
_MaterialBomService = MaterialBomService;
}
/// <summary>
/// 查询列表
/// </summary>
/// <param name="parm"></param>
/// <returns></returns>
[HttpGet("list")]
[ActionPermissionFilter(Permission = "business:materialbom:list")]
public IActionResult QueryMaterialBom([FromQuery] MaterialBomQueryDto parm)
{
var response = _MaterialBomService.GetList(parm);
return SUCCESS(response);
}
/// <summary>
/// 查询详情
/// </summary>
/// <param name="Id"></param>
/// <returns></returns>
[HttpGet("{Id}")]
[ActionPermissionFilter(Permission = "business:materialbom:query")]
public IActionResult GetMaterialBom(string Id)
{
var response = _MaterialBomService.GetInfo(Id);
var info = response.Adapt<MaterialBom>();
return SUCCESS(info);
}
/// <summary>
/// 添加
/// </summary>
/// <returns></returns>
[HttpPost]
[ActionPermissionFilter(Permission = "business:materialbom:add")]
[Log(Title = "", BusinessType = BusinessType.INSERT)]
public IActionResult AddMaterialBom([FromBody] MaterialBomDto parm)
{
var modal = parm.Adapt<MaterialBom>().ToCreate(HttpContext);
var response = _MaterialBomService.AddMaterialBom(modal);
return SUCCESS(response);
}
/// <summary>
/// 更新
/// </summary>
/// <returns></returns>
[HttpPut]
[ActionPermissionFilter(Permission = "business:materialbom:edit")]
[Log(Title = "", BusinessType = BusinessType.UPDATE)]
public IActionResult UpdateMaterialBom([FromBody] MaterialBomDto parm)
{
var modal = parm.Adapt<MaterialBom>().ToUpdate(HttpContext);
var response = _MaterialBomService.UpdateMaterialBom(modal);
return ToResponse(response);
}
/// <summary>
/// 删除
/// </summary>
/// <returns></returns>
[HttpDelete("{ids}")]
[ActionPermissionFilter(Permission = "business:materialbom:delete")]
[Log(Title = "", BusinessType = BusinessType.DELETE)]
public IActionResult DeleteMaterialBom(string ids)
{
int[] idsArr = Tools.SpitIntArrary(ids);
if (idsArr.Length <= 0) { return ToResponse(ApiResult.Error($"删除失败Id 不能为空")); }
var response = _MaterialBomService.Delete(idsArr);
return ToResponse(response);
}
//TODO 获取母件
[HttpPost("get_monter_inv")]
public IActionResult GetMonterInvList([FromBody] MaterialBomQueryDto parm)
{
var response = _MaterialBomService.GetMonterInvList(parm);
return SUCCESS(response);
}
//TODO 获取子件
[HttpPost("get_son_inv")]
public IActionResult GetSonInvList([FromBody] MaterialBomQueryDto parm)
{
var response = _MaterialBomService.GetSonInvList(parm);
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
);
}
}
}