package com.ruoyi.biz.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.biz.domain.vo.ArFileIndexVo;
import com.ruoyi.biz.domain.bo.ArFileIndexBo;
import com.ruoyi.biz.service.IArFileIndexService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 展示图
 *
 * @author gwd
 * @date 2023-11-10
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/biz/fileIndex")
public class ArFileIndexController extends BaseController {

    private final IArFileIndexService iArFileIndexService;

    /**
     * 查询展示图列表
     */
    @SaCheckPermission("biz:fileIndex:list")
    @GetMapping("/list")
    public TableDataInfo<ArFileIndexVo> list(ArFileIndexBo bo, PageQuery pageQuery) {
        return iArFileIndexService.queryPageList(bo, pageQuery);
    }

//    /**
//     * 导出展示图列表
//     */
//    @SaCheckPermission("biz:fileIndex:export")
//    @Log(title = "展示图", businessType = BusinessType.EXPORT)
//    @PostMapping("/export")
//    public void export(ArFileIndexBo bo, HttpServletResponse response) {
//        List<ArFileIndexVo> list = iArFileIndexService.queryList(bo);
//        ExcelUtil.exportExcel(list, "展示图", ArFileIndexVo.class, response);
//    }

//    /**
//     * 获取展示图详细信息
//     *
//     * @param id 主键
//     */
//    @SaCheckPermission("biz:fileIndex:query")
//    @GetMapping("/{id}")
//    public R<ArFileIndexVo> getInfo(@NotNull(message = "主键不能为空")
//                                     @PathVariable Long id) {
//        return R.ok(iArFileIndexService.queryById(id));
//    }

    /**
     * 新增展示图
     */
    @SaCheckPermission("biz:fileIndex:add")
    @Log(title = "展示图", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody ArFileIndexBo bo) {
        return toAjax(iArFileIndexService.insertByBo(bo) ? 1 : 0);
    }

    /**
     * 修改展示图
     */
    @SaCheckPermission("biz:fileIndex:edit")
    @Log(title = "展示图", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody ArFileIndexBo bo) {
        return toAjax(iArFileIndexService.updateByBo(bo) ? 1 : 0);
    }

    /**
     * 删除展示图
     *
     * @param ids 主键串
     */
    @SaCheckPermission("biz:fileIndex:remove")
    @Log(title = "展示图", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(iArFileIndexService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
    }

    /**
     * 随机添加
     *
     * @param count 数量
     */
    @SaCheckPermission("biz:fileIndex:randomAdd")
    @GetMapping("/randomAdd")
    public R<Void> randomAdd(int count) {
        return toAjax(iArFileIndexService.randomAdd(count) ? 1 : 0);
    }
}
