package com.ruoyi.gysl.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.gysl.entity.GyslProjectHandbook;
import com.ruoyi.gysl.entity.request.HandbookRequest;
import com.ruoyi.gysl.service.GyslProjectHandbookService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.io.Serializable;
import java.util.List;

import static com.ruoyi.common.core.domain.AjaxResult.success;

/**
 * 项目手册(GyslProjectHandbook)表控制层
 *
 * @author makejava
 * @since 2025-04-14 13:56:59
 */
@Api(tags = "项目手册")
@RestController
@RequestMapping("/gysl/handbook")
public class GyslProjectHandbookController {


    /**
     * 服务对象
     */
    @Resource
    private GyslProjectHandbookService gyslProjectHandbookService;


    /**
     * 分页查询所有数据
     *
     * @param g 查询实体
     * @return 所有数据
     */
    @GetMapping("/page")
    @ApiOperation(value = "分页查询所有数据", response = GyslProjectHandbook.class)
    public AjaxResult selectAll(HandbookRequest g) {
        Page<GyslProjectHandbook> a1 = new Page<>();
        a1.setCurrent(g.getCurrent());
        a1.setSize(g.getSize());
        return success(gyslProjectHandbookService.page(a1,g));
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("/{id}")
    @ApiOperation(value = "通过主键查询单条数据", response = GyslProjectHandbook.class)
    public AjaxResult selectOne(@PathVariable Serializable id) {
        return success(gyslProjectHandbookService.getData(id));
    }

    /**
     * 新增数据
     *
     * @param gyslProjectHandbook 实体对象
     * @return 新增结果
     */
    @PostMapping("/add")
    @ApiOperation(value = "新增数据")
    public AjaxResult insert(@RequestBody @Valid GyslProjectHandbook gyslProjectHandbook) {
        return success(gyslProjectHandbookService.save(gyslProjectHandbook));
    }

    /**
     * 修改数据
     *
     * @param gyslProjectHandbook 实体对象
     * @return 修改结果
     */
    @PostMapping("/edit")
    @ApiOperation("修改数据")
    public AjaxResult update(@RequestBody @Valid GyslProjectHandbook gyslProjectHandbook) {
        return success(gyslProjectHandbookService.updateById(gyslProjectHandbook));
    }

    /**
     * 删除数据
     *
     * @param idList 主键结合
     * @return 删除结果
     */
    @ApiOperation("删除数据")
    @DeleteMapping("/delete")
    public AjaxResult delete(@RequestParam("idList") java.util.List<Long> idList) {
        return success(gyslProjectHandbookService.removeByIds(idList));
    }


    /**
     * 导出项目手册
     */
    @ApiOperation(value = "导出项目手册")
    @PostMapping(value = "/export")
    public void export(HttpServletResponse response, @RequestParam Integer id)
            throws Exception {
        gyslProjectHandbookService.generatePdfs(response,id);
    }
}

