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.ArFileImageVo;
import com.ruoyi.biz.domain.bo.ArFileImageBo;
import com.ruoyi.biz.service.IArFileImageService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 相册
 *
 * @author gwd
 * @date 2023-07-11
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/biz/fileImage")
public class ArFileImageController extends BaseController {

    private final IArFileImageService iArFileImageService;

    /**
     * 查询相册列表
     */
//    @SaCheckPermission("biz:fileImage:list")
    @GetMapping("/list")
    public TableDataInfo<ArFileImageVo> list(ArFileImageBo bo, PageQuery pageQuery) {
        return iArFileImageService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出相册列表
     */
//    @SaCheckPermission("biz:fileImage:export")
    @Log(title = "相册", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(ArFileImageBo bo, HttpServletResponse response) {
        List<ArFileImageVo> list = iArFileImageService.queryList(bo);
        ExcelUtil.exportExcel(list, "相册", ArFileImageVo.class, response);
    }

    /**
     * 获取相册详细信息
     *
     * @param id 主键
     */
//    @SaCheckPermission("biz:fileImage:query")
    @GetMapping("/{id}")
    public R<ArFileImageVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(iArFileImageService.queryById(id));
    }

    /**
     * 新增相册
     */
//    @SaCheckPermission("biz:fileImage:add")
    @Log(title = "相册", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody ArFileImageBo bo) {
        return toAjax(iArFileImageService.insertByBo(bo) ? 1 : 0);
    }

    /**
     * 修改相册
     */
//    @SaCheckPermission("biz:fileImage:edit")
    @Log(title = "相册", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody ArFileImageBo bo) {
        return toAjax(iArFileImageService.updateByBo(bo) ? 1 : 0);
    }

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