package com.ruoyi.web.controller.bgt;

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

import com.ruoyi.bgt.domain.BgtProjectRecruit;
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.BgtProjectRecruitQueryBo;
import com.ruoyi.bgt.service.IBgtProjectRecruitService;
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-17
 */
@Api(value = "包工头招工控制器", tags = {"包工头招工管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/bgt/recruit")
public class BgtProjectRecruitController extends BaseController {

    private final IBgtProjectRecruitService iBgtProjectRecruitService;

    /**
     * 查询包工头招工列表
     */
    @ApiOperation("查询包工头招工列表")
    @PreAuthorize("@ss.hasPermi('bgt:recruit:list')")
    @GetMapping("/list")
    public TableDataInfo<BgtProjectRecruit> list(@Validated BgtProjectRecruitQueryBo bo) {
        return iBgtProjectRecruitService.queryPageList(bo);
    }

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

    /**
     * 获取包工头招工详细信息
     */
    @ApiOperation("获取包工头招工详细信息")
    @PreAuthorize("@ss.hasPermi('bgt:recruit:query')")
    @GetMapping("/{id}")
    public AjaxResult<BgtProjectRecruit> getInfo(@NotNull(message = "主键不能为空")
                                                  @PathVariable("id") Long id) {
        return AjaxResult.success(iBgtProjectRecruitService.queryById(id));
    }

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

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

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