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.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")]
|
2026-01-13 18:49:46 +08:00
|
|
|
|
public IActionResult GetMaterialBom(int Id)
|
2026-01-10 13:47:54 +08:00
|
|
|
|
{
|
|
|
|
|
|
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
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|