package com.yongqi.xinrenli.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.yongqi.xinrenli.domain.vo.DbInviterVo;
import com.yongqi.xinrenli.domain.bo.DbInviterBo;
import com.yongqi.xinrenli.service.IDbInviterService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 邀请
 *
 * @author zyf
 * @date 2023-03-09
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/xinrenli/Inviter")
public class DbInviterController extends BaseController {

    private final IDbInviterService iDbInviterService;

    /**
     * 查询邀请列表
     */
    @SaCheckPermission("xinrenli:Inviter:list")
    @GetMapping("/list")
    public TableDataInfo<DbInviterVo> list(DbInviterBo bo, PageQuery pageQuery) {
        return iDbInviterService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出邀请列表
     */
    @SaCheckPermission("xinrenli:Inviter:export")
    @Log(title = "邀请", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(DbInviterBo bo, HttpServletResponse response) {
        List<DbInviterVo> list = iDbInviterService.queryList(bo);
        ExcelUtil.exportExcel(list, "邀请", DbInviterVo.class, response);
    }

    /**
     * 获取邀请详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("xinrenli:Inviter:query")
    @GetMapping("/{id}")
    public R<DbInviterVo> getInfo(@NotNull(message = "主键不能为空")
                                  @PathVariable Long id) {
        return R.ok(iDbInviterService.queryById(id));
    }

    /**
     * 新增邀请
     */
    @SaCheckPermission("xinrenli:Inviter:add")
    @Log(title = "邀请", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody DbInviterBo bo) {
        return toAjax(iDbInviterService.insertByBo(bo));
    }

    /**
     * 修改邀请
     */
    @SaCheckPermission("xinrenli:Inviter:edit")
    @Log(title = "邀请", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody DbInviterBo bo) {
        return toAjax(iDbInviterService.updateByBo(bo));
    }

    /**
     * 删除邀请
     *
     * @param ids 主键串
     */
    @SaCheckPermission("xinrenli:Inviter:remove")
    @Log(title = "邀请", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(iDbInviterService.deleteWithValidByIds(Arrays.asList(ids), true));
    }
}
