From 310967603a605852968c2ac50cb1216094116978 Mon Sep 17 00:00:00 2001 From: git_rabbit Date: Fri, 26 Dec 2025 14:53:50 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E7=89=A9=E6=96=99=E7=B1=BB?= =?UTF-8?q?=E5=88=AB=E4=B8=8B=E6=8B=89=E6=A1=86=E6=8E=A5=E5=8F=A3=E5=8F=8A?= =?UTF-8?q?=E7=9B=B8=E5=85=B3DTO=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 本次提交主要包括以下内容: - 新增 GetMmMaterialCategoryOptions 接口,支持获取物料类别下拉框数据,允许匿名访问。 - 移除 MmMaterialCategoryController 相关冗余代码,接口合并至 MmMaterialController。 - MmMaterialCategoryDto 移除部分 Required 校验,新增 MmMaterialCategoryOptionsDto 用于下拉框数据传输。 - IMmMaterialService 接口调整,删除旧的列表方法,新增下拉框查询方法。 - MmMaterialService 实现下拉框数据查询逻辑,支持动态条件过滤并异常处理。 本次改动提升了接口的灵活性和代码可维护性,满足前端下拉框数据需求。 --- .../MmMaterialController.cs | 26 ++++++++--------- .../MES/Material/Dto/MmMaterialCategoryDto.cs | 17 +++++------ .../Material/IService/IMmMaterialService.cs | 4 +-- .../MES/Material/MmMaterialService.cs | 28 +++++++++++++++++++ 4 files changed, 50 insertions(+), 25 deletions(-) diff --git a/DOAN.Admin.WebApi/Controllers/MES/Material/productionMaterial/MmMaterialController.cs b/DOAN.Admin.WebApi/Controllers/MES/Material/productionMaterial/MmMaterialController.cs index 84e5aaa..36e89a2 100644 --- a/DOAN.Admin.WebApi/Controllers/MES/Material/productionMaterial/MmMaterialController.cs +++ b/DOAN.Admin.WebApi/Controllers/MES/Material/productionMaterial/MmMaterialController.cs @@ -99,22 +99,18 @@ namespace DOAN.Admin.WebApi.Controllers.BZFM return ToResponse(_MmMaterialService.Delete(idArr)); } - [ApiController] - [Route("api/mm-material-category")] - public class MmMaterialCategoryController : ControllerBase + /// + /// 获取物料表类别下拉框 + /// + /// + [HttpPost("GetMmMaterialCategoryOptions")] + [AllowAnonymous] + public IActionResult GetMmMaterialCategoryOptions([FromBody] MmMaterialCategoryDto parm) { - private readonly IMmMaterialService _service; - public MmMaterialCategoryController(IMmMaterialService service) - { - _service = service; - } - - [HttpGet("list")] - public IActionResult GetCategoryList([FromQuery] MmMaterialCategoryQueryDto parm) - { - var response = _service.GetMmMaterialCategoryList(parm); - return Ok(response); - } + var response = _MmMaterialService.GetMmMaterialCategoryOptions(parm); + return SUCCESS(response); } + + } } \ No newline at end of file diff --git a/DOAN.Model/MES/Material/Dto/MmMaterialCategoryDto.cs b/DOAN.Model/MES/Material/Dto/MmMaterialCategoryDto.cs index 9b37b42..3943d70 100644 --- a/DOAN.Model/MES/Material/Dto/MmMaterialCategoryDto.cs +++ b/DOAN.Model/MES/Material/Dto/MmMaterialCategoryDto.cs @@ -13,13 +13,8 @@ namespace DOAN.Model.BZFM.Dto /// public class MmMaterialCategoryDto { - [Required(ErrorMessage = "主键ID不能为空")] public int Id { get; set; } - - [Required(ErrorMessage = "分类编码不能为空")] public string CategoryCode { get; set; } - - [Required(ErrorMessage = "分类名称不能为空")] public string CategoryName { get; set; } public string ParentCode { get; set; } @@ -33,10 +28,16 @@ namespace DOAN.Model.BZFM.Dto public DateTime? CreatedTime { get; set; } public DateTime? UpdatedTime { get; set; } - - - [ExcelColumn(Name = "状态(0/1)")] public string StatusLabel { get; set; } } + + /// + /// 物料类别下拉框对象 + /// + public class MmMaterialCategoryOptionsDto + { + public string Label { get; set; } + public string Value { get; set; } + } } \ No newline at end of file diff --git a/DOAN.Service/MES/Material/IService/IMmMaterialService.cs b/DOAN.Service/MES/Material/IService/IMmMaterialService.cs index 250b5a4..40fa3d4 100644 --- a/DOAN.Service/MES/Material/IService/IMmMaterialService.cs +++ b/DOAN.Service/MES/Material/IService/IMmMaterialService.cs @@ -15,10 +15,10 @@ namespace DOAN.Service.BZFM.IBZFMService MmMaterial AddMmMaterial(MmMaterial parm); - PagedInfo GetMmMaterialCategoryList(MmMaterialCategoryQueryDto parm); - int UpdateMmMaterial(MmMaterial parm); + // 查询物料类别下拉框 + List GetMmMaterialCategoryOptions(MmMaterialCategoryDto parm); } } diff --git a/DOAN.Service/MES/Material/MmMaterialService.cs b/DOAN.Service/MES/Material/MmMaterialService.cs index 94f99d5..d73c2f4 100644 --- a/DOAN.Service/MES/Material/MmMaterialService.cs +++ b/DOAN.Service/MES/Material/MmMaterialService.cs @@ -79,5 +79,33 @@ namespace DOAN.Service.BZFM .AndIF(!string.IsNullOrEmpty(parm.Status), m => m.Status == parm.Status); return predicate; } + + /// + /// 获取物料类别下拉框 + /// + /// + /// + /// + public List GetMmMaterialCategoryOptions(MmMaterialCategoryDto parm) + { + try + { + return Context.Queryable() + .WhereIF(!string.IsNullOrEmpty(parm.CategoryCode),it => it.CategoryCode.Contains(parm.CategoryCode)) + .WhereIF(!string.IsNullOrEmpty(parm.CategoryName), it => it.CategoryName.Contains(parm.CategoryName)) + .Select(it => new MmMaterialCategoryOptionsDto + { + Label = it.CategoryName, + Value = it.CategoryCode + } + ).ToList(); + } + catch (Exception) + { + // TODO 处理错误日志 + + throw; + } + } } } \ No newline at end of file