package org.dromara.zhishu.controller;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.web.core.BaseController;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.zhishu.domain.vo.TBookAuditVo;
import org.dromara.zhishu.domain.bo.TBookAuditBo;
import org.dromara.zhishu.service.ITBookAuditService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 图书审核管理
 *
 * @author Lion Li
 * @date 2025-04-18
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/zhishu/bookAudit")
public class TBookAuditController extends BaseController {

    private final ITBookAuditService tBookAuditService;

    /**
     * 查询图书审核管理列表
     */
    @SaCheckPermission("zhishu:bookAudit:list")
    @GetMapping("/list")
    public TableDataInfo<TBookAuditVo> list(TBookAuditBo bo, PageQuery pageQuery) {
        return tBookAuditService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出图书审核管理列表
     */
    @SaCheckPermission("zhishu:bookAudit:export")
    @Log(title = "图书审核管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(TBookAuditBo bo, HttpServletResponse response) {
        List<TBookAuditVo> list = tBookAuditService.queryList(bo);
        ExcelUtil.exportExcel(list, "图书审核管理", TBookAuditVo.class, response);
    }

    /**
     * 获取图书审核管理详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("zhishu:bookAudit:query")
    @GetMapping("/{id}")
    public R<TBookAuditVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(tBookAuditService.queryById(id));
    }

    /**
     * 新增图书审核管理
     */
    @SaCheckPermission("zhishu:bookAudit:add")
    @Log(title = "图书审核管理", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody TBookAuditBo bo) {
        return toAjax(tBookAuditService.insertByBo(bo));
    }

    /**
     * 修改图书审核管理
     */
    @SaCheckPermission("zhishu:bookAudit:edit")
    @Log(title = "图书审核管理", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody TBookAuditBo bo) {
        return toAjax(tBookAuditService.updateByBo(bo));
    }

    /**
     * 删除图书审核管理
     * @param ids 主键串
     */
    @SaCheckPermission("zhishu:bookAudit:remove")
    @Log(title = "图书审核管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(tBookAuditService.deleteWithValidByIds(List.of(ids), true));
    }


    /**
     * 修改图书审核状态
     */
    @Log(title = "图书审核管理", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping("/updateStatus")
    public R<Void> updateStatus(@Validated(EditGroup.class) @RequestBody TBookAuditBo bo) {
        return toAjax(tBookAuditService.updateStatus(bo));
    }
}
