package com.njcn.prepare.harmonic.service.oracle.Impl;

import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.njcn.prepare.harmonic.mapper.oracle.LimitRateOracleMapper;
import com.njcn.prepare.harmonic.pojo.oracle.LimitRateOracle;
import com.njcn.prepare.harmonic.service.oracle.LimitRateOracleService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * LimitRate service层
 *
 * @author qijian
 * @version 1.0.0
 * @createTime 2022/12/05 - 10:09
 */
@Service
@RequiredArgsConstructor
@Slf4j
@DS("oracle")
public class LimitRateOracleServiceImpl implements LimitRateOracleService {

    private final LimitRateOracleMapper limitRateOracleMapper;

    /**
     * 根据条件获取单条数据
     * @author qijian
     * @date 2022/12/05
     */
    @Override
    public LimitRateOracle getOneByData(String date, Integer lineIndex) {
        DateTime parseDate = DateUtil.parse(date + " 00:00:00", "yyyy-MM-dd HH:mm:ss");
        LambdaQueryWrapper<LimitRateOracle> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(LimitRateOracle::getTimeid, parseDate)
                .eq(LimitRateOracle::getMyindex, lineIndex)
                .eq(LimitRateOracle::getPhasicType, "T");
        return limitRateOracleMapper.selectOne(lambdaQueryWrapper);
    }
}
