完善基础数据

This commit is contained in:
yanpeng200212
2026-10-08 15:44:07 +08:00
parent 8430ba0452
commit 2ffb83830c
95 changed files with 37759 additions and 5 deletions
@@ -0,0 +1,63 @@
using F9WebAiTest.Application.Common;
using F9WebAiTest.Application.Common.Exceptions;
using F9WebAiTest.Application.CQRS.SYS.YuanliaoZhuangkous.Commands;
using F9WebAiTest.Application.CQRS.SYS.YuanliaoZhuangkous.Queries;
using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
namespace F9WebAiTest.Api.Controllers;
/// <summary>原料庄口管理(DDD + CQRS):按年度/产地/站点/季别维护原料庄口,编号自动生成</summary>
[ApiController]
[Route("api/sys/yuanliaozhuangkou")]
[Authorize]
public class SysYuanliaoZhuangkouController : ControllerBase
{
private readonly IMediator _mediator;
public SysYuanliaoZhuangkouController(IMediator mediator) => _mediator = mediator;
[HttpGet]
public async Task<IActionResult> GetPaged([FromQuery] int year = 0, [FromQuery] string chandi = "", [FromQuery] string zhandian = "",
[FromQuery] string jibie = "", [FromQuery] string like = "", [FromQuery] int pageIndex = 1, [FromQuery] int pageSize = 20)
=> Ok(ApiResult<object>.Ok(await _mediator.Send(new GetYuanliaoZhuangkouPagedQuery(year,
chandi ?? string.Empty, zhandian ?? string.Empty, jibie ?? string.Empty, like ?? string.Empty, pageIndex, pageSize))));
/// <summary>物资(茧别)下拉选项:物资目录中名称含"茧"的物资</summary>
[HttpGet("wuzi-options")]
public async Task<IActionResult> GetWuziOptions([FromQuery] string keyword = "")
=> Ok(ApiResult<object>.Ok(await _mediator.Send(new GetYuanliaoZhuangkouWuziOptionsQuery(keyword ?? string.Empty))));
[HttpGet("{id}")]
public async Task<IActionResult> GetById(long id)
{
var result = await _mediator.Send(new GetYuanliaoZhuangkouByIdQuery(id));
return result == null
? NotFound(ApiResult<object>.Fail("原料庄口不存在", 404))
: Ok(ApiResult<object>.Ok(result));
}
[HttpPost]
public async Task<IActionResult> Create([FromBody] YuanliaoZhuangkou_CreateCommand command)
{
try { return Ok(ApiResult<object>.Ok(new { id = await _mediator.Send(command) }, "新增成功")); }
catch (F9NotFoundException ex) { return NotFound(ApiResult<object>.Fail(ex.Message, 404)); }
catch (F9OperationException ex) { return BadRequest(ApiResult<object>.Fail(ex.Message, 400)); }
}
[HttpPut("{id}")]
public async Task<IActionResult> Update(long id, [FromBody] YuanliaoZhuangkou_UpdateCommand command)
{
try { return Ok(ApiResult<object>.Ok(await _mediator.Send(command with { Id = id }), "修改成功")); }
catch (F9NotFoundException ex) { return NotFound(ApiResult<object>.Fail(ex.Message, 404)); }
catch (F9OperationException ex) { return BadRequest(ApiResult<object>.Fail(ex.Message, 400)); }
}
[HttpDelete("{id}")]
public async Task<IActionResult> Delete(long id)
{
try { return Ok(ApiResult<object>.Ok(await _mediator.Send(new YuanliaoZhuangkou_DelCommand(id)), "删除成功")); }
catch (F9NotFoundException ex) { return NotFound(ApiResult<object>.Fail(ex.Message, 404)); }
catch (F9OperationException ex) { return BadRequest(ApiResult<object>.Fail(ex.Message, 400)); }
}
}