package com.ruoyi.web.controller.bgt;

import java.util.List;
import java.util.Arrays;

import com.ruoyi.bgt.domain.BgtWageApplication;
import lombok.RequiredArgsConstructor;
import javax.validation.constraints.*;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.bgt.bo.BgtWageApplicationQueryBo;
import com.ruoyi.bgt.service.IBgtWageApplicationService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

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

    private final IBgtWageApplicationService iBgtWageApplicationService;

    /**
     * 查询包工头工资申请列表
     */
    @ApiOperation("查询包工头工资申请列表")
    @PreAuthorize("@ss.hasPermi('bgt:application:list')")
    @GetMapping("/list")
    public TableDataInfo<BgtWageApplication> list(@Validated BgtWageApplicationQueryBo bo) {
        return iBgtWageApplicationService.queryPageList(bo);
    }

    /**
     * 导出包工头工资申请列表
     */
    @ApiOperation("导出包工头工资申请列表")
    @PreAuthorize("@ss.hasPermi('bgt:application:export')")
    @Log(title = "包工头工资申请", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<BgtWageApplication> export(@Validated BgtWageApplicationQueryBo bo) {
        List<BgtWageApplication> list = iBgtWageApplicationService.queryList(bo);
        ExcelUtil<BgtWageApplication> util = new ExcelUtil<BgtWageApplication>(BgtWageApplication.class);
        return util.exportExcel(list, "包工头工资申请");
    }

    /**
     * 获取包工头工资申请详细信息
     */
    @ApiOperation("获取包工头工资申请详细信息")
    @PreAuthorize("@ss.hasPermi('bgt:application:query')")
    @GetMapping("/{id}")
    public AjaxResult<BgtWageApplication> getInfo(@NotNull(message = "主键不能为空")
                                                  @PathVariable("id") Long id) {
        return AjaxResult.success(iBgtWageApplicationService.queryById(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);
    }

    /**
     * 修改包工头工资申请
     */
    @ApiOperation("修改包工头工资申请")
    @PreAuthorize("@ss.hasPermi('bgt:application:edit')")
    @Log(title = "包工头工资申请", businessType = BusinessType.UPDATE)
    @RepeatSubmit
    @PutMapping()
    public AjaxResult<Void> edit(@Validated @RequestBody BgtWageApplication bo) {
        return toAjax(iBgtWageApplicationService.update(bo) ? 1 : 0);
    }

    /**
     * 删除包工头工资申请
     */
    @ApiOperation("删除包工头工资申请")
    @PreAuthorize("@ss.hasPermi('bgt:application:remove')")
    @Log(title = "包工头工资申请" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult<Void> remove(@NotEmpty(message = "主键不能为空")
                                       @PathVariable Long[] ids) {
        return toAjax(iBgtWageApplicationService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
    }
}
