package com.cf.imes.module.system.api.datasource;

import com.cf.imes.framework.common.exception.ErrorCode;
import com.cf.imes.framework.common.pojo.CommonResult;
import com.cf.imes.module.system.api.dataSource.DataSourceApi;
import com.cf.imes.module.system.dal.dataobject.datasource.DataSourceDO;
import com.cf.imes.module.system.dal.mysql.datasource.DataSourceMapper;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Objects;

import static com.cf.imes.framework.common.exception.util.ServiceExceptionUtil.exception;

@RestController
public class DataSourceApiImpl implements DataSourceApi {

    @Resource
    private DataSourceMapper dataSourceMapper;

    @Override
    public CommonResult<String> getSqlById(Long id) {
        DataSourceDO dataSourceDO = dataSourceMapper.selectById(id);
        if(Objects.isNull(dataSourceDO)) {
            throw exception(new ErrorCode(2133,"数据源不存在"));
        }
        return CommonResult.success(dataSourceDO.getSqlStr()) ;
    }
}
