namespace Tiobon.Core.Api.Controllers;

/// <summary>
/// Ghre_DaySalaryEntry_Boltone(Controller)
/// </summary>
[Route("api/[controller]")]
[ApiController, GlobalActionFilter]
[Authorize(Permissions.Name), ApiExplorerSettings(GroupName = Grouping.GroupName_Ghre)]
public class Ghre_DaySalaryEntry_BoltoneController : BaseController<IGhre_DaySalaryEntry_BoltoneServices, Ghre_DaySalaryEntry_Boltone, Ghre_DaySalaryEntry_BoltoneDto, InsertGhre_DaySalaryEntry_BoltoneInput, EditGhre_DaySalaryEntry_BoltoneInput>
{
    public Ghre_DaySalaryEntry_BoltoneController(IGhre_DaySalaryEntry_BoltoneServices service) : base(service)
    {
    }

    /// <summary>
    /// 新增数据
    /// </summary>
    /// <param name="insertModel"></param>
    /// <returns></returns>
    [HttpPost("Insert"), AllowAnonymous]
    public override async Task<ServiceResult<string>> Insert([FromBody] InsertGhre_DaySalaryEntry_BoltoneInput insertModel)
    {
        insertModel.SubmitDate = DateTime.Now;

        if (await _service.AnyAsync(x => x.IDNo == insertModel.IDNo && x.SubmitDate.Value.Date == DateTime.Now.Date))
            return Success<string>(null, "提交成功");
        var id = await _service.Add(insertModel);
        var data = Success<string>(null, "提交成功");
        data.Success = id > 0;
        if (data.Success)
            data.Data = id.ObjToString();
        else
            return Failed<string>("新增失败");

        return data;
    }
}