163 lines
5.4 KiB
C#
163 lines
5.4 KiB
C#
using Microsoft.AspNetCore.Mvc;
|
||
using RIZO.Model.Mes.Dto.Material;
|
||
using RIZO.Model.Mes.Dto.Process;
|
||
using RIZO.Model.Mes.Material;
|
||
using RIZO.Service.Mes.IMesService.Material;
|
||
|
||
//创建时间:2025-11-05
|
||
namespace RIZO.Admin.WebApi.Controllers.Mes.Material
|
||
{
|
||
/// <summary>
|
||
/// 物料表
|
||
/// </summary>
|
||
[AllowAnonymous]//先跳过验证
|
||
[Route("mes/MaterialInfo")]
|
||
public class MaterialInfoController : BaseController
|
||
{
|
||
/// <summary>
|
||
/// 物料表接口
|
||
/// </summary>
|
||
private readonly IMaterialInfoService _MaterialInfoService;
|
||
|
||
public MaterialInfoController(IMaterialInfoService MaterialInfoService)
|
||
{
|
||
_MaterialInfoService = MaterialInfoService;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 1.查询物料清单(模糊查询)*
|
||
/// </summary>
|
||
/// <param name="parm"></param>
|
||
/// <returns></returns>
|
||
[HttpGet("list")]
|
||
[ActionPermissionFilter(Permission = "materialinfo:list")]
|
||
public IActionResult QueryMaterialInfo([FromQuery] MaterialInfoQueryDto parm)
|
||
{
|
||
var response = _MaterialInfoService.GetList(parm);
|
||
return SUCCESS(response);
|
||
}
|
||
|
||
|
||
|
||
/// <summary>
|
||
/// 2.添加物料清单
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
[HttpPost]
|
||
[ActionPermissionFilter(Permission = "materialinfo:add")]
|
||
[Log(Title = "物料表", BusinessType = BusinessType.INSERT)]
|
||
public IActionResult AddMaterialInfo([FromBody] MaterialInfoDto parm)
|
||
{
|
||
var modal = parm.Adapt<MaterialInfo>().ToCreate(HttpContext);
|
||
|
||
var response = _MaterialInfoService.AddMaterialInfo(modal);
|
||
|
||
return SUCCESS(response);
|
||
}
|
||
|
||
|
||
|
||
/// <summary>
|
||
/// 3.更新物料清单
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
[HttpPut]
|
||
[ActionPermissionFilter(Permission = "materialinfo:edit")]
|
||
[Log(Title = "物料表", BusinessType = BusinessType.UPDATE)]
|
||
public IActionResult UpdateMaterialInfo([FromBody] MaterialInfoDto parm)
|
||
{
|
||
var modal = parm.Adapt<MaterialInfo>().ToUpdate(HttpContext);
|
||
var response = _MaterialInfoService.UpdateMaterialInfo(modal);
|
||
|
||
return ToResponse(response);
|
||
}
|
||
|
||
|
||
|
||
/// <summary>
|
||
/// 4.导入物料清单
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
[HttpPost("ImportMaterialInfo")]
|
||
//[ActionPermissionFilter(Permission = "materialinfo:import")]
|
||
[Log(Title = "导入保存物料清单", BusinessType = BusinessType.IMPORT)]
|
||
public IActionResult ImportMaterialInfo([FromQuery] string userId, [FromQuery] string userName, [FromForm] IFormFile file)
|
||
{
|
||
var stream = file.OpenReadStream();
|
||
var fileName = file.FileName;
|
||
var response = _MaterialInfoService.ImportMaterialInfo(stream, userId, userName);
|
||
return ToResponse(response);
|
||
}
|
||
|
||
|
||
|
||
|
||
/// <summary>
|
||
/// 5.通过物料编码批量删除物料清单
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
[HttpPost("deleteByMaterialCode")]
|
||
[ActionPermissionFilter(Permission = "materialinfo:delete")]
|
||
[Log(Title = "物料清单", BusinessType = BusinessType.DELETE)]
|
||
public IActionResult DeleteByMaterialCode([FromBody] string[] materialCodeArr)
|
||
{
|
||
return ToResponse(_MaterialInfoService.DeleteByMaterialCode(materialCodeArr));
|
||
}
|
||
|
||
|
||
|
||
/// <summary>
|
||
/// 6.导出物料清单
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
[HttpGet("export")]
|
||
//[ActionPermissionFilter(Permission = "materialinfo:export")]
|
||
[Log(Title = "工艺路线详情", BusinessType = BusinessType.EXPORT)]
|
||
public IActionResult Export()
|
||
{
|
||
MaterialInfoQueryDto parm = new MaterialInfoQueryDto
|
||
{
|
||
PageNum = 1,
|
||
PageSize = 100000
|
||
};
|
||
var list = _MaterialInfoService.GetList(parm).Result;
|
||
if (list == null || list.Count <= 0)
|
||
{
|
||
return ToResponse(ResultCode.FAIL, "没有要导出的数据");
|
||
}
|
||
|
||
var formatConfig = new Dictionary<string, string>
|
||
{
|
||
{ "CreateTime", "yyyy-MM-dd HH:mm:ss" },
|
||
{ "UpdateTime", "yyyy-MM-dd HH:mm:ss" }
|
||
};
|
||
|
||
var (sFileName, sFilePath) = ExportExcelMini(list, "物料清单详情", "物料清单详情");
|
||
if (string.IsNullOrWhiteSpace(sFilePath))
|
||
{
|
||
return ToResponse(ResultCode.FAIL, "Excel生成失败");
|
||
}
|
||
return PhysicalFile(
|
||
sFilePath,
|
||
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
||
sFileName,
|
||
true
|
||
);
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// 7.物料清单导入模板
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
[HttpGet("importTemplate")]
|
||
[Log(Title = "物料清单导入模板", BusinessType = BusinessType.EXPORT, IsSaveRequestData = true, IsSaveResponseData = false)]
|
||
[AllowAnonymous]
|
||
public IActionResult ImportTemplateExcel()
|
||
{
|
||
(string, string) result = DownloadImportTemplate("物料清单导入模板");
|
||
return ExportExcel(result.Item2, result.Item1);
|
||
}
|
||
|
||
}
|
||
} |