package com.ruoyi.web.controller.zbf;

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.zbf.bo.ZbfProjectQueryBo;
import com.ruoyi.zbf.domain.ZbfProject;
import com.ruoyi.zbf.service.IZbfProjectService;
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("/zbf/project")
public class ZbfProjectController extends BaseController {

    private final IZbfProjectService iZbfProjectService;

    /**
     * 查询总包方项目列表
     */
    @ApiOperation("查询总包方项目列表")
    @PreAuthorize("@ss.hasPermi('common:project:list')")
    @GetMapping("/list")
    public TableDataInfo<ZbfProject> list(@Validated ZbfProjectQueryBo bo) {
        return iZbfProjectService.queryPageList(bo);
    }

    /**
     * 导出总包方项目列表
     */
    @ApiOperation("导出总包方项目列表")
    @PreAuthorize("@ss.hasPermi('common:project:export')")
    @Log(title = "总包方项目", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<ZbfProject> export(@Validated ZbfProjectQueryBo bo) {
        List<ZbfProject> list = iZbfProjectService.queryList(bo);
        ExcelUtil<ZbfProject> util = new ExcelUtil<ZbfProject>(ZbfProject.class);
        return util.exportExcel(list, "总包方项目");
    }

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

    /**
     * 新增总包方项目
     */
    @ApiOperation("新增总包方项目")
    @PreAuthorize("@ss.hasPermi('common:project:add')")
    @Log(title = "总包方项目", businessType = BusinessType.INSERT)
    @RepeatSubmit
    @PostMapping()
    public AjaxResult<Void> add(@Validated @RequestBody ZbfProject bo) {
        return toAjax(iZbfProjectService.insert(bo) ? 1 : 0);
    }

    /**
     * 修改总包方项目
     */
    @ApiOperation("修改总包方项目")
    @PreAuthorize("@ss.hasPermi('common:project:edit')")
    @Log(title = "总包方项目", businessType = BusinessType.UPDATE)
    @RepeatSubmit
    @PutMapping()
    public AjaxResult<Void> edit(@Validated @RequestBody ZbfProject bo) {
        return toAjax(iZbfProjectService.update(bo) ? 1 : 0);
    }

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