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.dromara.payment.sys.domain.vo.SysSydAccountSynVo;
import org.dromara.payment.sys.service.ISysSydAccountSynService;
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.bo.SysSydAccountSynBo;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 服务商账户同步
 * 前端访问路由地址为:/payment/sydAccountSyn
 *
 * @author LionLi
 * @date 2024-03-26
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/sydAccountSyn")
public class SysSydAccountSynController extends BaseController {

    private final ISysSydAccountSynService sysSydAccountSynService;

    /**
     * 查询服务商账户同步列表
     */
    @SaCheckPermission("payment:sydAccountSyn:list")
    @GetMapping("/list")
    public TableDataInfo<SysSydAccountSynVo> list(SysSydAccountSynBo bo, PageQuery pageQuery) {
        return sysSydAccountSynService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出服务商账户同步列表
     */
    @SaCheckPermission("payment:sydAccountSyn:export")
    @Log(title = "服务商账户同步", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(SysSydAccountSynBo bo, HttpServletResponse response) {
        List<SysSydAccountSynVo> list = sysSydAccountSynService.queryList(bo);
        ExcelUtil.exportExcel(list, "服务商账户同步", SysSydAccountSynVo.class, response);
    }

    /**
     * 获取服务商账户同步详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("payment:sydAccountSyn:query")
    @GetMapping("/{id}")
    public R<SysSydAccountSynVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(sysSydAccountSynService.queryById(id));
    }

    /**
     * 新增服务商账户同步
     */
    @SaCheckPermission("payment:sydAccountSyn:add")
    @Log(title = "服务商账户同步", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody SysSydAccountSynBo bo) {
        return toAjax(sysSydAccountSynService.insertByBo(bo));
    }

    /**
     * 修改服务商账户同步
     */
    @SaCheckPermission("payment:sydAccountSyn:edit")
    @Log(title = "服务商账户同步", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody SysSydAccountSynBo bo) {
        return toAjax(sysSydAccountSynService.updateByBo(bo));
    }

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