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.FbsProjectTaskQueryBo;
import com.ruoyi.fbs.domain.FbsProjectTask;
import com.ruoyi.fbs.service.IFbsProjectTaskService;
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/task")
public class FbsProjectTaskController extends BaseController {

    private final IFbsProjectTaskService iFbsProjectTaskService;

    /**
     * 查询分包商项目任务列表
     */
    @ApiOperation("查询分包商项目任务列表")
    @PreAuthorize("@ss.hasPermi('common:task:list')")
    @GetMapping("/list")
    public TableDataInfo<FbsProjectTask> list(@Validated FbsProjectTaskQueryBo bo) {
        return iFbsProjectTaskService.queryPageList(bo);
    }

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

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

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

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

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