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.ZbfProjectSubcontractingQueryBo;
import com.ruoyi.zbf.domain.ZbfProjectSubcontracting;
import com.ruoyi.zbf.service.IZbfProjectSubcontractingService;
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/subcontracting")
public class ZbfProjectSubcontractingController extends BaseController {

    private final IZbfProjectSubcontractingService iZbfProjectSubcontractingService;

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

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

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

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

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

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