package com.yida.data.system.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.yida.data.common.core.common.ResultBean;
import com.yida.data.common.core.entity.system.EduPayWxConfig;
import com.yida.data.common.core.utils.Asserts;
import com.yida.data.system.service.EduPayWxConfigService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Api(tags = "微信支付配置信息")
@RestController
@RequestMapping("/payWxConfig")
@AllArgsConstructor
public class EduPayWxConfigController {

    private final EduPayWxConfigService eduPayWxConfigService;

    @ApiOperation("获取学校的微支付主体appId")
    @GetMapping("/getAppIdBySchool")
    public ResultBean<String> getAppIdBySchool(Long schoolId) {
        EduPayWxConfig payWxConfig = eduPayWxConfigService.getOne(Wrappers.<EduPayWxConfig>lambdaQuery()
            .eq(EduPayWxConfig::getSchoolId, schoolId)
            .select(EduPayWxConfig::getWxPublicId));
        Asserts.isNotNull(payWxConfig, "未查询到学校微支付");
        return ResultBean.buildSuccess(payWxConfig.getWxPublicId());
    }
}
