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.LowHeightRisk;
import com.ruoyi.cai.dto.admin.vo.LowHeightRiskAdminVo;
import com.ruoyi.cai.service.LowHeightRiskService;
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/lowHeightRisk")
public class LowHeightRiskController extends BaseController {

    private final LowHeightRiskService lowHeightRiskService;

    /**
     * 查询高风险用户记录列表
     */
    @SaCheckPermission("cai:lowHeightRisk:list")
    @GetMapping("/list")
    public TableDataInfo<LowHeightRiskAdminVo> list(LowHeightRiskAdminVo bo, PageQuery pageQuery) {
        Page<LowHeightRiskAdminVo> page = lowHeightRiskService.pageAdmin(pageQuery, bo);
        return TableDataInfo.build(page);
    }


    /**
     * 获取高风险用户记录详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("cai:lowHeightRisk:query")
    @GetMapping("/{id}")
    public R<LowHeightRisk> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(lowHeightRiskService.getById(id));
    }

    /**
     * 新增高风险用户记录
     */
    @SaCheckPermission("cai:lowHeightRisk:add")
    @Log(title = "高风险用户记录", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody LowHeightRisk bo) {
        return toAjax(lowHeightRiskService.save(bo));
    }

    /**
     * 修改高风险用户记录
     */
    @SaCheckPermission("cai:lowHeightRisk:edit")
    @Log(title = "高风险用户记录", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody LowHeightRisk bo) {
        return toAjax(lowHeightRiskService.updateById(bo));
    }

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