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

/**
 * 服务商变动记录
 * 前端访问路由地址为:/payment/sydLog
 *
 * @author LionLi
 * @date 2024-03-26
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/sydLog")
public class SysSydLogController extends BaseController {

    private final ISysSydLogService sysSydLogService;

    /**
     * 查询服务商变动记录列表
     */
    @SaCheckPermission("payment:sydLog:list")
    @GetMapping("/list")
    public TableDataInfo<SysSydLogVo> list(SysSydLogBo bo, PageQuery pageQuery) {
        return sysSydLogService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出服务商变动记录列表
     */
    @SaCheckPermission("payment:sydLog:export")
    @Log(title = "服务商变动记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(SysSydLogBo bo, HttpServletResponse response) {
        List<SysSydLogVo> list = sysSydLogService.queryList(bo);
        ExcelUtil.exportExcel(list, "服务商变动记录", SysSydLogVo.class, response);
    }

    /**
     * 获取服务商变动记录详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("payment:sydLog:query")
    @GetMapping("/{id}")
    public R<SysSydLogVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(sysSydLogService.queryById(id));
    }

    /**
     * 新增服务商变动记录
     */
    @SaCheckPermission("payment:sydLog:add")
    @Log(title = "服务商变动记录", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody SysSydLogBo bo) {
        return toAjax(sysSydLogService.insertByBo(bo));
    }

    /**
     * 修改服务商变动记录
     */
    @SaCheckPermission("payment:sydLog:edit")
    @Log(title = "服务商变动记录", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody SysSydLogBo bo) {
        return toAjax(sysSydLogService.updateByBo(bo));
    }

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