完善基础数据
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
using F9WebAiTest.Application.Common;
|
||||
using F9WebAiTest.Application.Common.Exceptions;
|
||||
using F9WebAiTest.Application.CQRS.SYS.WuziMulus.Commands;
|
||||
using F9WebAiTest.Application.CQRS.SYS.WuziMulus.Queries;
|
||||
using MediatR;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace F9WebAiTest.Api.Controllers;
|
||||
|
||||
/// <summary>物资目录管理(按分组维护物资)</summary>
|
||||
[ApiController]
|
||||
[Route("api/sys/wuzimulu")]
|
||||
[Authorize]
|
||||
public class SysWuziMuluController : ControllerBase
|
||||
{
|
||||
private readonly IMediator _mediator;
|
||||
public SysWuziMuluController(IMediator mediator) => _mediator = mediator;
|
||||
|
||||
/// <summary>按分组分页查询(groupId=0 表示全部分组)</summary>
|
||||
[HttpGet]
|
||||
public async Task<IActionResult> GetPaged([FromQuery] long groupId = 0, [FromQuery] string keyword = "",
|
||||
[FromQuery] int pageIndex = 1, [FromQuery] int pageSize = 20)
|
||||
=> Ok(ApiResult<object>.Ok(await _mediator.Send(new GetWuziMuluPagedQuery(groupId, keyword ?? string.Empty, pageIndex, pageSize))));
|
||||
|
||||
/// <summary>物资选项(供其它模块选择物资,如原料庄口选茧别)</summary>
|
||||
[HttpGet("options")]
|
||||
public async Task<IActionResult> GetOptions([FromQuery] string keyword = "", [FromQuery] int limit = 200)
|
||||
=> Ok(ApiResult<object>.Ok(await _mediator.Send(new GetWuziMuluOptionsQuery(keyword ?? string.Empty, limit))));
|
||||
|
||||
/// <summary>生成新编号(按所属分组)</summary>
|
||||
[HttpGet("new-code")]
|
||||
public async Task<IActionResult> GetNewCode([FromQuery] long groupId)
|
||||
=> Ok(ApiResult<object>.Ok(await _mediator.Send(new GetWuziMuluNewCodeQuery(groupId))));
|
||||
|
||||
[HttpGet("{id}")]
|
||||
public async Task<IActionResult> GetById(long id)
|
||||
{
|
||||
var result = await _mediator.Send(new GetWuziMuluByIdQuery(id));
|
||||
return result == null
|
||||
? NotFound(ApiResult<object>.Fail("物资不存在", 404))
|
||||
: Ok(ApiResult<object>.Ok(result));
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> Create([FromBody] WuziMulu_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] WuziMulu_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 WuziMulu_DelCommand(id)), "删除成功")); }
|
||||
catch (F9NotFoundException ex) { return NotFound(ApiResult<object>.Fail(ex.Message, 404)); }
|
||||
catch (F9OperationException ex) { return BadRequest(ApiResult<object>.Fail(ex.Message, 400)); }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user