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.ActProjectVo;
import com.ruoyi.scientific.domain.bo.ActProjectBo;
import com.ruoyi.scientific.service.IActProjectService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 科研管理
 *
 * @author zqjia
 * @date 2024-07-14
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/scientific/project")
public class ActProjectController extends BaseController {

    private final IActProjectService iActProjectService;

    /**
     * 查询科研管理列表
     */
    @SaCheckPermission("scientific:project:list")
    @GetMapping("/list")
    public TableDataInfo<ActProjectVo> list(ActProjectBo bo, PageQuery pageQuery) {
        return iActProjectService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出科研管理列表
     */
    @SaCheckPermission("scientific:project:export")
    @Log(title = "科研管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(ActProjectBo bo, HttpServletResponse response) {
        List<ActProjectVo> list = iActProjectService.queryList(bo);
        ExcelUtil.exportExcel(list, "科研管理", ActProjectVo.class, response);
    }

    /**
     * 获取科研管理详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("scientific:project:query")
    @GetMapping("/{id}")
    public R<ActProjectVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable String id) {
        return R.ok(iActProjectService.queryById(id));
    }

    /**
     * 新增科研管理
     */
    @SaCheckPermission("scientific:project:add")
    @Log(title = "科研管理", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody ActProjectBo bo) {
        return toAjax(iActProjectService.insertByBo(bo));
    }

    /**
     * 修改科研管理
     */
    @SaCheckPermission("scientific:project:edit")
    @Log(title = "科研管理", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody ActProjectBo bo) {
        return toAjax(iActProjectService.updateByBo(bo));
    }

    /**
     * 删除科研管理
     *
     * @param ids 主键串
     */
    @SaCheckPermission("scientific:project:remove")
    @Log(title = "科研管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable String[] ids) {
        return toAjax(iActProjectService.deleteWithValidByIds(Arrays.asList(ids), true));
    }
}
