package com.seer.teach.openapi.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.seer.teach.common.utils.SignUtils;
import com.seer.teach.openapi.entity.AppKeySecretsEntity;
import com.seer.teach.openapi.mapper.AppKeySecretsMapper;
import com.seer.teach.openapi.service.AppKeySecretsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;


/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author Wang
 * @since 2025-10-31 16:29:36
 */
@Slf4j
@Service
public class AppKeySecretsServiceImpl extends ServiceImpl<AppKeySecretsMapper, AppKeySecretsEntity> implements AppKeySecretsService {

    @Override
    public AppKeySecretsEntity getAppKeySecretsByAppId(String appId) {
        return getOne(new LambdaQueryWrapper<AppKeySecretsEntity>()
                .eq(AppKeySecretsEntity::getAppId, appId));
    }

    @Override
    public Boolean sign(String appId, String sign, String timestamp) {
        try {
            AppKeySecretsEntity appKeySecrets = getAppKeySecretsByAppId(appId);
            String signServer = SignUtils.generateSign(appKeySecrets.getKey(), appKeySecrets.getSecret(), timestamp);
            return signServer.equals(sign);
        } catch (Exception e) {
            log.info("Sign 成功 :{}",e.getMessage());
            return false;
        }
    }

}
