package com.ruoyi.web.controller.bgt;

import com.ruoyi.bgt.bo.BgtProjectRecruitApplyQueryBo;
import com.ruoyi.bgt.domain.BgtProjectRecruitApply;
import com.ruoyi.bgt.service.IBgtProjectRecruitApplyService;
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.common.utils.poi.ExcelUtil;
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.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Arrays;
import java.util.List;

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

    private final IBgtProjectRecruitApplyService iBgtProjectRecruitApplyService;

    /**
     * 查询包工头招工申请列表
     */
    @ApiOperation("查询包工头招工申请列表")
    @PreAuthorize("@ss.hasPermi('bgt:apply:list')")
    @GetMapping("/list")
    public TableDataInfo<BgtProjectRecruitApply> list(@Validated BgtProjectRecruitApplyQueryBo bo) {
        return iBgtProjectRecruitApplyService.queryPageList(bo);
    }

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

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

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

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

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