新增物料类别下拉框接口及相关DTO优化

本次提交主要包括以下内容:

- 新增 GetMmMaterialCategoryOptions 接口,支持获取物料类别下拉框数据,允许匿名访问。
- 移除 MmMaterialCategoryController 相关冗余代码,接口合并至 MmMaterialController。
- MmMaterialCategoryDto 移除部分 Required 校验,新增 MmMaterialCategoryOptionsDto 用于下拉框数据传输。
- IMmMaterialService 接口调整,删除旧的列表方法,新增下拉框查询方法。
- MmMaterialService 实现下拉框数据查询逻辑,支持动态条件过滤并异常处理。

本次改动提升了接口的灵活性和代码可维护性,满足前端下拉框数据需求。
This commit is contained in:
2025-12-26 14:53:50 +08:00
parent ce56838fd7
commit 310967603a
4 changed files with 50 additions and 25 deletions

View File

@@ -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
/// <summary>
/// 获取物料表类别下拉框
/// </summary>
/// <returns></returns>
[HttpPost("GetMmMaterialCategoryOptions")]
[AllowAnonymous]
public IActionResult GetMmMaterialCategoryOptions([FromBody] MmMaterialCategoryDto parm)
{
private readonly IMmMaterialService _service;
public MmMaterialCategoryController(IMmMaterialService service)
{
_service = service;
var response = _MmMaterialService.GetMmMaterialCategoryOptions(parm);
return SUCCESS(response);
}
[HttpGet("list")]
public IActionResult GetCategoryList([FromQuery] MmMaterialCategoryQueryDto parm)
{
var response = _service.GetMmMaterialCategoryList(parm);
return Ok(response);
}
}
}
}

View File

@@ -13,13 +13,8 @@ namespace DOAN.Model.BZFM.Dto
/// </summary>
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; }
}
/// <summary>
/// 物料类别下拉框对象
/// </summary>
public class MmMaterialCategoryOptionsDto
{
public string Label { get; set; }
public string Value { get; set; }
}
}

View File

@@ -15,10 +15,10 @@ namespace DOAN.Service.BZFM.IBZFMService
MmMaterial AddMmMaterial(MmMaterial parm);
PagedInfo<MmMaterialDto> GetMmMaterialCategoryList(MmMaterialCategoryQueryDto parm);
int UpdateMmMaterial(MmMaterial parm);
// 查询物料类别下拉框
List<MmMaterialCategoryOptionsDto> GetMmMaterialCategoryOptions(MmMaterialCategoryDto parm);
}
}

View File

@@ -79,5 +79,33 @@ namespace DOAN.Service.BZFM
.AndIF(!string.IsNullOrEmpty(parm.Status), m => m.Status == parm.Status);
return predicate;
}
/// <summary>
/// 获取物料类别下拉框
/// </summary>
/// <param name="parm"></param>
/// <returns></returns>
/// <exception cref="NotImplementedException"></exception>
public List<MmMaterialCategoryOptionsDto> GetMmMaterialCategoryOptions(MmMaterialCategoryDto parm)
{
try
{
return Context.Queryable<MmMaterialCategory>()
.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;
}
}
}
}