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 { /// /// 物料清单 /// [AllowAnonymous] [Route("MasterDataManagement/Material/MaterialList")] public class MaterialListController : BaseController { /// /// 物料清单接口 /// private readonly IMaterialListService _MaterialListService; public MaterialListController(IMaterialListService MaterialListService) { _MaterialListService = MaterialListService; } /// /// 查询物料清单列表 /// /// /// [HttpGet("list")] [ActionPermissionFilter(Permission = "business:materiallist:list")] public IActionResult QueryMaterialList([FromQuery] MaterialListQueryDto parm) { var response = _MaterialListService.GetList(parm); return SUCCESS(response); } /// /// 查询物料清单详情 /// /// /// [HttpGet("{Id}")] [ActionPermissionFilter(Permission = "business:materiallist:query")] public IActionResult GetMaterialList(int Id) { var response = _MaterialListService.GetInfo(Id); var info = response.Adapt(); return SUCCESS(info); } /// /// 添加物料清单 /// /// [HttpPost] [ActionPermissionFilter(Permission = "business:materiallist:add")] [Log(Title = "物料清单", BusinessType = BusinessType.INSERT)] public IActionResult AddMaterialList([FromBody] MaterialListDto parm) { var modal = parm.Adapt().ToCreate(HttpContext); var response = _MaterialListService.AddMaterialList(modal); return SUCCESS(response); } /// /// 更新物料清单 /// /// [HttpPut] [ActionPermissionFilter(Permission = "business:materiallist:edit")] [Log(Title = "物料清单", BusinessType = BusinessType.UPDATE)] public IActionResult UpdateMaterialList([FromBody] MaterialListDto parm) { var modal = parm.Adapt().ToUpdate(HttpContext); var response = _MaterialListService.UpdateMaterialList(modal); return ToResponse(response); } /// /// 删除物料清单 /// /// [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; } } }