package org.dromara.payment.merchant.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.merchant.domain.vo.BusMerchantProductSydVo;
import org.dromara.payment.merchant.domain.bo.BusMerchantProductSydBo;
import org.dromara.payment.merchant.service.IBusMerchantProductSydService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 企业产品服务商
 * 前端访问路由地址为:/merchant/merchantProductSyd
 *
 * @author LionLi
 * @date 2024-04-25
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/merchantProductSyd")
public class BusMerchantProductSydController extends BaseController {

    private final IBusMerchantProductSydService busMerchantProductSydService;

    /**
     * 查询企业产品服务商列表
     */
    @SaCheckPermission("merchant:merchantProductSyd:list")
    @GetMapping("/list")
    public TableDataInfo<BusMerchantProductSydVo> list(BusMerchantProductSydBo bo, PageQuery pageQuery) {
        return busMerchantProductSydService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出企业产品服务商列表
     */
    @SaCheckPermission("merchant:merchantProductSyd:export")
    @Log(title = "企业产品服务商", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(BusMerchantProductSydBo bo, HttpServletResponse response) {
        List<BusMerchantProductSydVo> list = busMerchantProductSydService.queryList(bo);
        ExcelUtil.exportExcel(list, "企业产品服务商", BusMerchantProductSydVo.class, response);
    }

    /**
     * 获取企业产品服务商详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("merchant:merchantProductSyd:query")
    @GetMapping("/{id}")
    public R<BusMerchantProductSydVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(busMerchantProductSydService.queryById(id));
    }

    /**
     * 新增企业产品服务商
     */
//    @SaCheckPermission("merchant:merchantProductSyd:add")
    @Log(title = "企业产品服务商", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class)  BusMerchantProductSydBo bo) {
        return toAjax(busMerchantProductSydService.insertByBo(bo));
    }

    /**
     * 修改企业产品服务商
     */
    @SaCheckPermission("merchant:merchantProductSyd:edit")
    @Log(title = "企业产品服务商", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody BusMerchantProductSydBo bo) {
        return toAjax(busMerchantProductSydService.updateByBo(bo));
    }

    /**
     * 删除企业产品服务商
     *
     * @param ids 主键串
     */
    @SaCheckPermission("merchant:merchantProductSyd:remove")
    @Log(title = "企业产品服务商", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(busMerchantProductSydService.deleteWithValidByIds(List.of(ids), true));
    }
}
