package cn.fateverse.query.service.impl;

import cn.fateverse.common.core.result.Result;
import cn.fateverse.common.decrypt.service.EncryptService;
import cn.fateverse.query.entity.UniQuery;
import cn.fateverse.query.entity.vo.UniQueryVo;
import cn.fateverse.query.entity.dto.UniQueryDto;
import cn.fateverse.query.mapper.UniQueryMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;


/**
 * sql自定义查询实现类
 *
 * @author Clay
 * @date 2023-08-09
 */
@Slf4j
@Service
public class SqlUniQueryServiceImpl extends AbstractUniQueryService {

    public SqlUniQueryServiceImpl(UniQueryMapper uniQueryMapper, EncryptService encryptService) {
        super(uniQueryMapper,encryptService);
    }


    @Override
    public Result<UniQueryVo> save(UniQueryDto dto) {
        UniQuery uniQuery = new UniQuery();
        uniQuery.setUqName(dto.getUqName());
        uniQuery.setDataSourceId(dto.getDataSourceId());
        uniQuery.setUqDescribe(dto.getUqDescribe());
        uniQuery.setPublish(Boolean.FALSE);
        uniQuery.setPreview(Boolean.FALSE);
        uniQuery.setType(1);
        uniQueryMapper.insert(uniQuery);
        return Result.ok(UniQueryVo.toUniQueryVo(uniQuery));
    }

}
