package com.huatek.busi.service.impl.cable;

import com.alibaba.dubbo.config.annotation.Service;
import com.huatek.busi.mapper.cable.CableCirculationStatisticsMapper;
import com.huatek.busi.service.cable.BusiOtherThresholdService;
import com.huatek.busi.service.cable.CableCirculationStatisticsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

@Slf4j
@Component
@Service(interfaceClass = CableCirculationStatisticsService.class)
@Transactional(rollbackFor = Exception.class)
public class CableCirculationStatisticsServiceImpl implements CableCirculationStatisticsService {

    @Autowired
    CableCirculationStatisticsMapper cableCirculationStatisticsMapper;
    @Override
    public int saveCableCirculationStatistics(LocalDate day) {

        LocalDateTime startTime = day.atStartOfDay();
        LocalDateTime endTime = day.plusDays(1).atStartOfDay();
        return  cableCirculationStatisticsMapper.aveCableCirculationStatistics(startTime,endTime);
    }

    @Override
    public Map<String, Object> getRecordBySensorCode(String sensorCode, LocalDateTime startTime, LocalDateTime endTime) {
        List< Map<String, Object>> list = cableCirculationStatisticsMapper.getRecordBySensorCode(sensorCode,startTime,endTime);
        if(!list.isEmpty())
        {
            return list.get(0);
        }
        return null;
    }

    @Override
    public Map<String, Object> getItem(String sensorCode, LocalDate day) {
       return cableCirculationStatisticsMapper.getItem(sensorCode,day);
    }
}
