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

import cn.hutool.core.date.DateTime;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.njcn.prepare.harmonic.mapper.oracle.DataFlickerOracleMapper;
import com.njcn.prepare.harmonic.pojo.vo.DataFlickerOracleVO;
import com.njcn.prepare.harmonic.service.oracle.DataFlickerOracleService;
import com.njcn.prepare.harmonic.utils.PublicUtil;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.Map;

/**
 * DataFlicker service层
 *
 * @author qijian
 * @version 1.0.0
 * @createTime 2022/12/01 - 10:09
 */
@Service
@RequiredArgsConstructor
@Slf4j
@DS("oracle")
public class DataFlickerOracleServiceImpl implements DataFlickerOracleService {

    private final DataFlickerOracleMapper dataFlickerOracleMapper;

    /**
     * 取两项闪变指标数量（数据完整性）
     * @author qijian
     * @date 2022/12/01
     */
    @Override
    public DataFlickerOracleVO getTwoCountForDataIntegrityRate(Integer lineId, Date date, Integer type) {
        //根据类型获取日期的开始和结束
        Map<String, DateTime> beginAndEndByDate = PublicUtil.getBeginAndEndByDate(type, date);
        DateTime startTime = beginAndEndByDate.get("startTime");
        DateTime endTime = beginAndEndByDate.get("endTime");
        DataFlickerOracleVO dataFlickerOracleVO = dataFlickerOracleMapper.getTwoCountForDataIntegrityRate(lineId,startTime,endTime);
        return dataFlickerOracleVO;
    }
}
