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.ZbfProjectSectionQueryBo;
import com.ruoyi.zbf.domain.ZbfProjectSection;
import com.ruoyi.zbf.service.IZbfProjectSectionService;
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/section")
public class ZbfProjectSectionController extends BaseController {

    private final IZbfProjectSectionService iZbfProjectSectionService;

    /**
     * 查询总包方项目标段列表
     */
    @ApiOperation("查询总包方项目标段列表")
    @PreAuthorize("@ss.hasPermi('common:section:list')")
    @GetMapping("/list")
    public TableDataInfo<ZbfProjectSection> list(@Validated ZbfProjectSectionQueryBo bo) {
        return iZbfProjectSectionService.queryPageList(bo);
    }

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

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

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

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

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