package org.king.modules.ad.service.impl;


import com.baomidou.dynamic.datasource.annotation.DS;
import org.king.modules.ad.entity.*;
import org.king.modules.ad.mapper.AdChargingRecordMapper;
import org.king.modules.ad.mapper.AdDeviceFaultReportMapper;
import org.king.modules.ad.mapper.AdDeviceMapper;
import org.king.modules.ad.service.StaticalService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service
@DS("multi-datasource1")
public class StaticalServiceImpl implements StaticalService {

    @Resource
    private AdDeviceMapper adDeviceMapper;

    @Resource
    private AdChargingRecordMapper adChargingRecordMapper;

    @Resource
    private AdDeviceFaultReportMapper adDeviceFaultReportMapper;

    @Override
    public AdDeviceCount getDeviceCount(){
        AdDeviceCount count = new AdDeviceCount();
        List<AdDevice> countList = adDeviceMapper.getDeviceCount();
        for(AdDevice adDevice:countList){
            if(adDevice.getType().equals("100000")){
                count.setZnCount(adDevice.getCount());
            }else if(adDevice.getType().equals("300000")){
                count.setFznCount(adDevice.getCount());
            }else if(adDevice.getType().equals("200000")){
                count.setBznCount(adDevice.getCount());
            }
        }
        count.setTotal(count.getZnCount()+count.getBznCount()+count.getFznCount());
        return count;
    }

    public List<ChargeCount> getChargeData(){
        List<ChargeCount> list = adChargingRecordMapper.getChargeByFive();
        ChargeCount chargeCount = adChargingRecordMapper.getChargeData();
        chargeCount.setStartTime("合计");
        list.add(chargeCount);
        return list;
    }

    public  List<AdDeviceFaultReport> getlist(){
        List<AdDeviceFaultReport> list = adDeviceFaultReportMapper.getlist();
        return list;
    }

}
