package com.ruoyi.web.controller.bgt;

import com.ruoyi.bgt.domain.BgtWageApplication;
import com.ruoyi.bgt.domain.dto.BgtWageApplicationQueryDTO;
import com.ruoyi.bgt.domain.vo.BgtWageApplicationDetailVO;
import com.ruoyi.bgt.domain.vo.BgtWageApplicationVO;
import com.ruoyi.bgt.service.IBgtWageApplicationService;
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 io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;

/**
 * 包工头工资申请Controller
 *
 * @author ruoyi
 * @date 2025-02-20
 */
@Api(value = "App包工头工资申请控制器", tags = {"App包工头工资申请管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/app/bgt/application")
public class AppBgtWageApplicationController extends BaseController {

    private final IBgtWageApplicationService iBgtWageApplicationService;

    /**
     * 查询包工头工资申请列表
     */
    @ApiOperation("App查询包工头工资申请列表")
    @GetMapping("/list")
    public TableDataInfo<BgtWageApplicationVO> list(@Validated BgtWageApplicationQueryDTO dto) {
        return iBgtWageApplicationService.appQueryPageList(dto);
    }

    /**
     * 获取包工头工资申请详细信息
     */
    @ApiOperation("App获取包工头工资申请详细信息")
    @GetMapping("/{id}")
    public AjaxResult<BgtWageApplicationDetailVO> getInfo(@NotNull(message = "主键不能为空")
                                                  @PathVariable("id") Long id) {
        return AjaxResult.success(iBgtWageApplicationService.appQueryById(id));
    }

    /**
     * 新增包工头工资申请
     */
    @ApiOperation("新增包工头工资申请")
    @PreAuthorize("@ss.hasPermi('bgt:application:add')")
    @Log(title = "包工头工资申请", businessType = BusinessType.INSERT)
    @RepeatSubmit
    @PostMapping()
    public AjaxResult<Void> add(@Validated @RequestBody BgtWageApplication bo) {
        return toAjax(iBgtWageApplicationService.insert(bo) ? 1 : 0);
    }

}
