package com.ruoyi.cai.controller.admin;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.cai.domain.UserInfo;
import com.ruoyi.cai.dto.admin.vo.UserInfoAdminVo;
import com.ruoyi.cai.service.UserInfoService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.annotation.RepeatSubmit;
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.page.TableDataInfo;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.enums.BusinessType;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;

/**
 * 用户好友提成
 *
 * @author 77
 * @date 2024-01-04
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/cai/userInfo")
public class UserInfoController extends BaseController {

    private final UserInfoService userInfoService;

    @SaCheckPermission("cai:userInfo:list")
    @GetMapping("/list")
    public TableDataInfo<UserInfoAdminVo> list(UserInfoAdminVo bo, PageQuery pageQuery) {
        Page<UserInfoAdminVo> page = userInfoService.pageAdmin(pageQuery,bo);
        return TableDataInfo.build(page);
    }

    @SaCheckPermission("cai:userInfo:query")
    @GetMapping("/{id}")
    public R<UserInfo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(userInfoService.getById(id));
    }

    @SaCheckPermission("cai:userInfo:edit")
    @Log(title = "用户好友提成", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody UserInfo bo) {
        return toAjax(userInfoService.updateById(bo));
    }
}
