package com.ruoyi.web.controller.bgt;

import com.ruoyi.bgt.bo.BgtProjectTaskProgressQueryBo;
import com.ruoyi.bgt.domain.BgtProjectTaskProgress;
import com.ruoyi.bgt.service.IBgtProjectTaskProgressService;
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/progress")
public class BgtProjectTaskProgressController extends BaseController {

    private final IBgtProjectTaskProgressService iBgtProjectTaskProgressService;

    /**
     * 查询包工头项目任务进度列表
     */
    @ApiOperation("查询包工头项目任务进度列表")
    @PreAuthorize("@ss.hasPermi('bgt:progress:list')")
    @GetMapping("/list")
    public TableDataInfo<BgtProjectTaskProgress> list(@Validated BgtProjectTaskProgressQueryBo bo) {
        return iBgtProjectTaskProgressService.queryPageList(bo);
    }

    /**
     * 导出包工头项目任务进度列表
     */
    @ApiOperation("导出包工头项目任务进度列表")
    @PreAuthorize("@ss.hasPermi('bgt:progress:export')")
    @Log(title = "包工头项目任务进度", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<BgtProjectTaskProgress> export(@Validated BgtProjectTaskProgressQueryBo bo) {
        List<BgtProjectTaskProgress> list = iBgtProjectTaskProgressService.queryList(bo);
        ExcelUtil<BgtProjectTaskProgress> util = new ExcelUtil<BgtProjectTaskProgress>(BgtProjectTaskProgress.class);
        return util.exportExcel(list, "包工头项目任务进度");
    }

    /**
     * 获取包工头项目任务进度详细信息
     */
    @ApiOperation("获取包工头项目任务进度详细信息")
    @PreAuthorize("@ss.hasPermi('bgt:progress:query')")
    @GetMapping("/{id}")
    public AjaxResult<BgtProjectTaskProgress> getInfo(@NotNull(message = "主键不能为空")
                                                  @PathVariable("id") Long id) {
        return AjaxResult.success(iBgtProjectTaskProgressService.queryById(id));
    }

    /**
     * 新增包工头项目任务进度
     */
    @ApiOperation("新增包工头项目任务进度")
    @PreAuthorize("@ss.hasPermi('bgt:progress:add')")
    @Log(title = "包工头项目任务进度", businessType = BusinessType.INSERT)
    @RepeatSubmit
    @PostMapping()
    public AjaxResult<Void> add(@Validated @RequestBody BgtProjectTaskProgress bo) {
        return toAjax(iBgtProjectTaskProgressService.insert(bo) ? 1 : 0);
    }

    /**
     * 修改包工头项目任务进度
     */
    @ApiOperation("修改包工头项目任务进度")
    @PreAuthorize("@ss.hasPermi('bgt:progress:edit')")
    @Log(title = "包工头项目任务进度", businessType = BusinessType.UPDATE)
    @RepeatSubmit
    @PutMapping()
    public AjaxResult<Void> edit(@Validated @RequestBody BgtProjectTaskProgress bo) {
        return toAjax(iBgtProjectTaskProgressService.update(bo) ? 1 : 0);
    }

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