package com.pqs9900.serviceImpl.DataInfo;

import cn.hutool.core.collection.CollectionUtil;
import com.pqs9900.mapper.State.MonthYearDayFlowMapper;
import com.pqs9900.pojo.State.MonthYearDayFlow;
import com.pqs9900.service.DataInfo.FlowService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.YearMonth;
import java.util.ArrayList;
import java.util.List;

/** @Author denghuajun
 * @Description //TODO 终端流量impl
 * @Date  2019/3/15 13:42
 **/
@Service
public class FlowServiceImpl implements FlowService {

    private Logger logger = LoggerFactory.getLogger(FlowServiceImpl.class);

    @Autowired
    private MonthYearDayFlowMapper monthYearDayFlowMapper;


    @Override
    public List<MonthYearDayFlow> getFlowDayDetail(Long devIndex,String yearmonth) {
        List<MonthYearDayFlow> monthYearDayFlows = new ArrayList<>();
        try {
            monthYearDayFlows = monthYearDayFlowMapper.dayByMonth(devIndex, yearmonth);
            if(CollectionUtil.isNotEmpty(monthYearDayFlows)){
                Float avg = monthYearDayFlowMapper.getAvgFlow(devIndex,yearmonth);
                for(MonthYearDayFlow monthYearDayFlow:monthYearDayFlows){
                    monthYearDayFlow.setAvgFlow(avg);
                }
            }
        }catch (Exception e){
            logger.error(e.getMessage());
        }
        return monthYearDayFlows;
    }
}
