package org.jeecg.modules.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.modules.system.entity.SysThirdAppConfig;
import org.jeecg.modules.system.mapper.SysThirdAppConfigMapper;
import org.jeecg.modules.system.service.ISysThirdAppConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Description: 第三方配置表
 * @Author: jeecg-boot
 * @Date: 2023-02-03
 * @Version: V1.0
 */
@Service
@Slf4j
public class SysThirdAppConfigServiceImpl extends ServiceImpl<SysThirdAppConfigMapper, SysThirdAppConfig> implements ISysThirdAppConfigService {


    @Value("${justauth.type.DINGTALK.client-id:}")
    private String dingTalkClientId;
    @Autowired
    private SysThirdAppConfigMapper configMapper;

    @Override
    public SysThirdAppConfig getThirdConfigByThirdType(String thirdType) {
        List<SysThirdAppConfig> list = getThirdAppConfigByClientId(dingTalkClientId);
        if (list == null || list.isEmpty())
            return null;
        return list.get(0);
    }

    @Override
    public List<SysThirdAppConfig> getThirdAppConfigByClientId(String clientId) {
        LambdaQueryWrapper<SysThirdAppConfig> query = new LambdaQueryWrapper<>();
        query.eq(SysThirdAppConfig::getClientId, clientId);
        List<SysThirdAppConfig> sysThirdAppConfigs = configMapper.selectList(query);
        return sysThirdAppConfigs;
    }
}
