package com.ruoyi.frequency.refereeuser.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.frequency.refereeuser.entity.RefereeUser;
import com.ruoyi.frequency.refereeuser.service.RefereeUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 用户邀请Controller
 * 
 * @author liwenlong
 * @date 2023-07-20
 */
@RestController
@RequestMapping("/frequency/refereeuser")
public class RefereeUserController extends BaseController
{
    @Autowired
    private RefereeUserService refereeUserService;

    /**
     * 查询用户邀请列表
     */
    @PreAuthorize("@ss.hasPermi('frequency:refereeuser:list')")
    @PostMapping("/list")
    public TableDataInfo<RefereeUser> list(@RequestBody RefereeUser refereeUser)
    {
        startPage();
        List<RefereeUser> list = refereeUserService.selectRefereeUserList(refereeUser);
        return getDataTable(list);
    }

    /**
     * 导出用户邀请列表
     */
    @PreAuthorize("@ss.hasPermi('frequency:refereeuser:export')")
    @Log(title = "用户邀请", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(RefereeUser refereeUser)
    {
        List<RefereeUser> list = refereeUserService.selectRefereeUserList(refereeUser);
        ExcelUtil<RefereeUser> util = new ExcelUtil<RefereeUser>(RefereeUser.class);
        return util.exportExcel(list, "用户邀请数据");
    }

    /**
     * 获取用户邀请详细信息
     */
    @PreAuthorize("@ss.hasPermi('frequency:refereeuser:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(refereeUserService.selectRefereeUserById(id));
    }

    /**
     * 新增用户邀请
     */
    @PreAuthorize("@ss.hasPermi('frequency:refereeuser:add')")
    @Log(title = "用户邀请", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RefereeUser refereeUser)
    {
        return toAjax(refereeUserService.insertRefereeUser(refereeUser));
    }

    /**
     * 修改用户邀请
     */
    @PreAuthorize("@ss.hasPermi('frequency:refereeuser:edit')")
    @Log(title = "用户邀请", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RefereeUser refereeUser)
    {
        return toAjax(refereeUserService.updateRefereeUser(refereeUser));
    }

    /**
     * 删除用户邀请
     */
    @PreAuthorize("@ss.hasPermi('frequency:refereeuser:remove')")
    @Log(title = "用户邀请", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(refereeUserService.deleteRefereeUserByIds(ids));
    }
}
