package com.ruoyi.web.controller.fbs;

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 com.ruoyi.fbs.bo.FbsProjectTaskApplyQueryBo;
import com.ruoyi.fbs.domain.FbsProjectTaskApply;
import com.ruoyi.fbs.service.IFbsProjectTaskApplyService;
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-17
 */
@Api(value = "分包商项目任务申请控制器", tags = {"分包商项目任务申请管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/fbs/apply")
public class FbsProjectTaskApplyController extends BaseController {

    private final IFbsProjectTaskApplyService iFbsProjectTaskApplyService;

    /**
     * 查询分包商项目任务申请列表
     */
    @ApiOperation("查询分包商项目任务申请列表")
    @PreAuthorize("@ss.hasPermi('fbs:apply:list')")
    @GetMapping("/list")
    public TableDataInfo<FbsProjectTaskApply> list(@Validated FbsProjectTaskApplyQueryBo bo) {
        return iFbsProjectTaskApplyService.queryPageList(bo);
    }

    /**
     * 导出分包商项目任务申请列表
     */
    @ApiOperation("导出分包商项目任务申请列表")
    @PreAuthorize("@ss.hasPermi('fbs:apply:export')")
    @Log(title = "分包商项目任务申请", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<FbsProjectTaskApply> export(@Validated FbsProjectTaskApplyQueryBo bo) {
        List<FbsProjectTaskApply> list = iFbsProjectTaskApplyService.queryList(bo);
        ExcelUtil<FbsProjectTaskApply> util = new ExcelUtil<FbsProjectTaskApply>(FbsProjectTaskApply.class);
        return util.exportExcel(list, "分包商项目任务申请");
    }

    /**
     * 获取分包商项目任务申请详细信息
     */
    @ApiOperation("获取分包商项目任务申请详细信息")
    @PreAuthorize("@ss.hasPermi('fbs:apply:query')")
    @GetMapping("/{id}")
    public AjaxResult<FbsProjectTaskApply> getInfo(@NotNull(message = "主键不能为空")
                                                  @PathVariable("id") Long id) {
        return AjaxResult.success(iFbsProjectTaskApplyService.queryById(id));
    }

    /**
     * 新增分包商项目任务申请
     */
    @ApiOperation("新增分包商项目任务申请")
    @PreAuthorize("@ss.hasPermi('fbs:apply:add')")
    @Log(title = "分包商项目任务申请", businessType = BusinessType.INSERT)
    @RepeatSubmit
    @PostMapping()
    public AjaxResult<Void> add(@Validated @RequestBody FbsProjectTaskApply bo) {
        return toAjax(iFbsProjectTaskApplyService.insert(bo) ? 1 : 0);
    }

    /**
     * 修改分包商项目任务申请
     */
    @ApiOperation("修改分包商项目任务申请")
    @PreAuthorize("@ss.hasPermi('fbs:apply:edit')")
    @Log(title = "分包商项目任务申请", businessType = BusinessType.UPDATE)
    @RepeatSubmit
    @PutMapping()
    public AjaxResult<Void> edit(@Validated @RequestBody FbsProjectTaskApply bo) {
        return toAjax(iFbsProjectTaskApplyService.update(bo) ? 1 : 0);
    }

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