using Consul.Filtering;

namespace Tiobon.Core.Api.Controllers;

/// <summary>
/// 培训需求(Controller)
/// </summary>
[Route("api/[controller]")]
[ApiController, GlobalActionFilter]
[Authorize(Permissions.Name), ApiExplorerSettings(GroupName = Grouping.GroupName_Ghre)]
public class Ghre_RequestController : BaseController<IGhre_RequestServices, Ghre_Request, Ghre_RequestDto, InsertGhre_RequestInput, EditGhre_RequestInput>
{
    public Ghre_RequestController(IGhre_RequestServices service) : base(service)
    {
    }

    #region 查询
    /// <summary>
    /// 根据条件查询数据
    /// </summary>
    /// <param name="body">条件</param>
    /// <param name="status">status</param>
    /// <returns></returns>
    [HttpPost, Route("QueryList/{status}")]
    public async Task<ServicePageResult<Ghre_RequestDto>> QueryByStatus([FromBody] QueryBody body, string status)
    {
        if (status == "Active")
            return await _service.QueryFilterPage(body, $"(Status ='Active' OR Status ='Wait' OR (WorkID IS NOT NULL AND WorkState IN (0,1)))");
        else if (status == "Disable")
            return await _service.QueryFilterPage(body, null, false);
        else
            return await _service.QueryFilterPage(body, $"Status ='{status}' AND WorkID IS NULL");
    }
    #endregion

    #region 状态修改 
    [HttpPost("UpdateStatus/{status}")]
    public async Task<ServiceResult> UpdateStatus(string status, [FromBody] InsertGhre_RequestInput input)
    {
        return await _service.UpdateStatus(input, status);
    }
    #endregion 

    #region 新增 
    [HttpPost("Insert/{status}")]
    public async Task<ServiceResult<long>> InsertByStatus([FromBody] InsertGhre_RequestInput insertModel, string status)
    {
        return await _service.InsertByStatus(insertModel, status);
    }
    #endregion 

    #region 新增 
    [HttpPost("QueryGroup/{type}")]
    public async Task<ServicePageResult<Ghre_RequestDto>> QueryGroup([FromBody] QueryBody filter, string type)
    {
        return await _service.QueryGroup(filter, type);
    }
    #endregion 

    #region 新增 
    [HttpPost("ExportExcel/{type}")]
    public async Task<ServiceResult<ExcelData>> ExportExcel([FromBody] QueryExport filter, string type)
    {
        return await _service.ExportExcel(filter, type);
    }
    #endregion

    #region 新增 
    [HttpPost("ExportGroupExcel/{type}")]
    public async Task<ServiceResult<ExcelData>> ExportGroupExcel([FromBody] QueryExport filter, string type)
    {
        return await _service.ExportGroupExcel(filter, type);
    }
    #endregion 

    /// <summary>
    ///  查询菜单表单信息
    /// </summary>
    /// <param name="body">body</param>
    /// <returns></returns>
    [HttpPost("QueryForm/{status}")]
    public async Task<ServiceFormResult<Ghre_RequestDto>> QueryFormByStatus([FromBody] QueryForm body)
    {
        return await _service.QueryForm(body);

    }


    #region 新增 
    [HttpGet("Ushio_Sync"), AllowAnonymous]
    public async Task Ushio_Sync()
    {
        await _service.Ushio_Sync();
    }
    #endregion 
}