package org.dromara.payment.sys.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.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;
import org.dromara.payment.sys.domain.vo.AccAccountsVo;
import org.dromara.payment.sys.domain.bo.AccAccountsBo;
import org.dromara.payment.sys.service.IAccAccountsService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 线下银行账户
 * 前端访问路由地址为:/payment/accounts
 *
 * @author LionLi
 * @date 2024-03-27
 */
@Validated
@RequiredArgsConstructor
@RestController
//@RequestMapping("/accounts")
public class AccAccountsController extends BaseController {

    private final IAccAccountsService accAccountsService;

    /**
     * 查询线下银行账户列表
     */
    @SaCheckPermission("payment:accounts:list")
    @GetMapping("/list")
    public TableDataInfo<AccAccountsVo> list(AccAccountsBo bo, PageQuery pageQuery) {
        return accAccountsService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出线下银行账户列表
     */
    @SaCheckPermission("payment:accounts:export")
    @Log(title = "线下银行账户", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(AccAccountsBo bo, HttpServletResponse response) {
        List<AccAccountsVo> list = accAccountsService.queryList(bo);
        ExcelUtil.exportExcel(list, "线下银行账户", AccAccountsVo.class, response);
    }

    /**
     * 获取线下银行账户详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("payment:accounts:query")
    @GetMapping("/{id}")
    public R<AccAccountsVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(accAccountsService.queryById(id));
    }

    /**
     * 新增线下银行账户
     */
    @SaCheckPermission("payment:accounts:add")
    @Log(title = "线下银行账户", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody AccAccountsBo bo) {
        return toAjax(accAccountsService.insertByBo(bo));
    }

    /**
     * 修改线下银行账户
     */
    @SaCheckPermission("payment:accounts:edit")
    @Log(title = "线下银行账户", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody AccAccountsBo bo) {
        return toAjax(accAccountsService.updateByBo(bo));
    }

    /**
     * 删除线下银行账户
     *
     * @param ids 主键串
     */
    @SaCheckPermission("payment:accounts:remove")
    @Log(title = "线下银行账户", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(accAccountsService.deleteWithValidByIds(List.of(ids), true));
    }
}
