package com.ruoyi.web.controller.bgt;

import com.ruoyi.bgt.domain.dto.BgtPayCalculationListDTO;
import com.ruoyi.bgt.domain.dto.BgtPayCalculationUpdateDTO;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.wgz.bo.res.WgzAppApplyForPayrollSettlementListRes;
import com.ruoyi.wgz.service.IWgzPayCalculationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;

/**
 * 工资结算Controller
 *
 * @author ruoyi
 * @date 2025-02-21
 */
@Api(value = "App包工头工资结算审核控制器", tags = {"App包工头工资结算审核"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/app/bgt/calculation")
public class AppBgtPayCalculationController extends BaseController {

    private final IWgzPayCalculationService iWgzPayCalculationService;

    /**
     * 查询工资结算列表
     */
    @ApiOperation("查询工资结算审核列表")
    @GetMapping("/list")
    public TableDataInfo<WgzAppApplyForPayrollSettlementListRes> list(@Validated BgtPayCalculationListDTO dto) {
        return iWgzPayCalculationService.appQueryPageList(dto);
    }

    /**
     * 获取工资结算详细信息
     */
    @ApiOperation("获取工资结算详细信息")
    @GetMapping("/{id}")
    public AjaxResult<WgzAppApplyForPayrollSettlementListRes> getInfo(@NotNull(message = "主键不能为空")
                                                  @PathVariable("id") Long id) {
        return AjaxResult.success(iWgzPayCalculationService.appQueryById(id));
    }

    /**
     * 修改工资结算
     */
    @ApiOperation("审核工资结算")
    @Log(title = "审核工资结算", businessType = BusinessType.UPDATE)
    @RepeatSubmit
    @PutMapping()
    public AjaxResult<Void> edit(@Validated @RequestBody BgtPayCalculationUpdateDTO dto) {
        return toAjax(iWgzPayCalculationService.appUpdate(dto) ? 1 : 0);
    }


}
