package com.ruoyi.scientific.controller;

import java.util.List;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.validate.QueryGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.scientific.domain.vo.ProjectHandbookVo;
import com.ruoyi.scientific.domain.bo.ProjectHandbookBo;
import com.ruoyi.scientific.service.IProjectHandbookService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 项目申报v2
 *
 * @author ruoyi
 * @date 2024-07-23
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/scientific/handbook")
public class ProjectHandbookController extends BaseController {

    private final IProjectHandbookService iProjectHandbookService;

    /**
     * 查询项目申报v2列表
     */
    @SaCheckPermission("scientific:handbook:list")
    @GetMapping("/list")
    public TableDataInfo<ProjectHandbookVo> list(ProjectHandbookBo bo, PageQuery pageQuery) {
        return iProjectHandbookService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出项目申报v2列表
     */
    @SaCheckPermission("scientific:handbook:export")
    @Log(title = "项目申报v2", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(ProjectHandbookBo bo, HttpServletResponse response) {
        List<ProjectHandbookVo> list = iProjectHandbookService.queryList(bo);
        ExcelUtil.exportExcel(list, "项目申报v2", ProjectHandbookVo.class, response);
    }

    /**
     * 获取项目申报v2详细信息
     *
     * @param handbookId 主键
     */
    @SaCheckPermission("scientific:handbook:query")
    @GetMapping("/{handbookId}")
    public R<ProjectHandbookVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long handbookId) {
        return R.ok(iProjectHandbookService.queryById(handbookId));
    }

    /**
     * 新增项目申报v2
     */
    @SaCheckPermission("scientific:handbook:add")
    @Log(title = "项目申报v2", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody ProjectHandbookBo bo) {
        return toAjax(iProjectHandbookService.insertByBo(bo));
    }

    /**
     * 修改项目申报v2
     */
    @SaCheckPermission("scientific:handbook:edit")
    @Log(title = "项目申报v2", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody ProjectHandbookBo bo) {
        return toAjax(iProjectHandbookService.updateByBo(bo));
    }

    /**
     * 删除项目申报v2
     *
     * @param handbookIds 主键串
     */
    @SaCheckPermission("scientific:handbook:remove")
    @Log(title = "项目申报v2", businessType = BusinessType.DELETE)
    @DeleteMapping("/{handbookIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] handbookIds) {
        return toAjax(iProjectHandbookService.deleteWithValidByIds(Arrays.asList(handbookIds), true));
    }
}
