namespace Tiobon.Core.Api.Controllers;

/// <summary>
/// 人力需求维护(Controller)
/// </summary>
[Route("api/[controller]")]
[ApiController, GlobalActionFilter]
[Authorize(Permissions.Name), ApiExplorerSettings(GroupName = Grouping.GroupName_Ghrh)]
public class Ghrh_HumanRequestController : BaseController<IGhrh_HumanRequestServices, Ghrh_HumanRequest, Ghrh_HumanRequestDto, InsertGhrh_HumanRequestInput, EditGhrh_HumanRequestInput>
{
    public Ghrh_HumanRequestController(IGhrh_HumanRequestServices 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<Ghrh_HumanRequestDto>> QueryByStatus([FromBody] QueryBody body, string status)
    {
        if (status == "Active")
            return await _service.QueryFilterPage(body, $"(Status ='{status}' 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");
    }

    [HttpPost, Route("QuerySummary")]
    public async Task<ServicePageResult<Ghrh_HumanRequestDto>> QueryFilterSummaryPage([FromBody] QueryBody body)
    {
        return await _service.QueryFilterSummaryPage(body);
    }
    #endregion

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

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

    #region Excel导出
    /// <summary>
    /// Excel导出
    /// </summary>
    /// <param name="body"></param>
    /// <returns></returns>
    [HttpPost, Route("ExportSummaryExcel")]
    public virtual async Task<ServiceResult<ExcelData>> ExportSummaryExcel([FromBody] QueryExport body)
    {
        return await _service.ExportSummaryExcel(body);
    }
    #endregion



    [HttpPost, Route("QueryComplete")]
    public async Task<ServicePageResult<Ghrh_HumanRequestDto>> QueryFilterCompletePage([FromBody] QueryBody body)
    {
        return await _service.QueryFilterCompletePage(body);
    }

    [HttpPost, Route("ExportCompleteExcel")]
    public virtual async Task<ServiceResult<ExcelData>> ExportCompleteExcel([FromBody] QueryExport body)
    {
        return await _service.ExportCompleteExcel(body);
    }
}