package com.ruoyi.cai.controller.admin;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.cai.domain.UserRiskLog;
import com.ruoyi.cai.service.UserRiskLogService;
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.AddGroup;
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.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Arrays;

/**
 * 高风险操作日志
 *
 * @author 77
 * @date 2023-12-22
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/cai/userRiskLog")
public class UserRiskLogController extends BaseController {

    private final UserRiskLogService userRiskLogService;

    /**
     * 查询高风险操作日志列表
     */
    @SaCheckPermission("cai:userRiskLog:list")
    @GetMapping("/list")
    public TableDataInfo<UserRiskLog> list(UserRiskLog bo, PageQuery pageQuery) {
        Page<UserRiskLog> page = userRiskLogService.page(pageQuery.build(), Wrappers.lambdaQuery(bo));
        return TableDataInfo.build(page);
    }


    /**
     * 获取高风险操作日志详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("cai:userRiskLog:query")
    @GetMapping("/{id}")
    public R<UserRiskLog> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(userRiskLogService.getById(id));
    }

    /**
     * 新增高风险操作日志
     */
    @SaCheckPermission("cai:userRiskLog:add")
    @Log(title = "高风险操作日志", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody UserRiskLog bo) {
        return toAjax(userRiskLogService.save(bo));
    }

    /**
     * 修改高风险操作日志
     */
    @SaCheckPermission("cai:userRiskLog:edit")
    @Log(title = "高风险操作日志", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody UserRiskLog bo) {
        return toAjax(userRiskLogService.updateById(bo));
    }

    /**
     * 删除高风险操作日志
     *
     * @param ids 主键串
     */
    @SaCheckPermission("cai:userRiskLog:remove")
    @Log(title = "高风险操作日志", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(userRiskLogService.removeBatchByIds(Arrays.asList(ids)));
    }
}
