package org.dromara.payment.earlyWarn.controller;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.payment.earlyWarn.domain.bo.LgEarlyWarnDtlBo;
import org.dromara.payment.earlyWarn.domain.vo.LgEarlyWarnDtlVo;
import org.dromara.payment.earlyWarn.service.ILgEarlyWarnDtlService;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.web.core.BaseController;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.excel.utils.ExcelUtil;


/**
 * 风控预警设置明细
 * 前端访问路由地址为:/system/earlyWarnDtl
 *
 * @author LionLi
 * @date 2025-06-10
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/earlyWarnDtl")
public class LgEarlyWarnDtlController extends BaseController {

    private final ILgEarlyWarnDtlService lgEarlyWarnDtlService;

    /**
     * 查询风控预警设置明细列表
     */
    @SaCheckPermission("system:earlyWarnDtl:list")
    @GetMapping("/list")
    public TableDataInfo<LgEarlyWarnDtlVo> list(LgEarlyWarnDtlBo bo, PageQuery pageQuery) {
        return lgEarlyWarnDtlService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出风控预警设置明细列表
     */
    @SaCheckPermission("system:earlyWarnDtl:export")
    @Log(title = "风控预警设置明细", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(LgEarlyWarnDtlBo bo, HttpServletResponse response) {
        List<LgEarlyWarnDtlVo> list = lgEarlyWarnDtlService.queryList(bo);
        ExcelUtil.exportExcel(list, "风控预警设置明细", LgEarlyWarnDtlVo.class, response);
    }

    /**
     * 获取风控预警设置明细详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("system:earlyWarnDtl:query")
    @GetMapping("/{id}")
    public R<LgEarlyWarnDtlVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(lgEarlyWarnDtlService.queryById(id));
    }

    /**
     * 新增风控预警设置明细
     */
    @SaCheckPermission("system:earlyWarnDtl:add")
    @Log(title = "风控预警设置明细", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody LgEarlyWarnDtlBo bo) {
        return toAjax(lgEarlyWarnDtlService.insertByBo(bo));
    }

    /**
     * 修改风控预警设置明细
     */
    @SaCheckPermission("system:earlyWarnDtl:edit")
    @Log(title = "风控预警设置明细", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody LgEarlyWarnDtlBo bo) {
        return toAjax(lgEarlyWarnDtlService.updateByBo(bo));
    }

    /**
     * 删除风控预警设置明细
     *
     * @param ids 主键串
     */
    @SaCheckPermission("system:earlyWarnDtl:remove")
    @Log(title = "风控预警设置明细", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(lgEarlyWarnDtlService.deleteWithValidByIds(List.of(ids), true));
    }
}
