package com.lightinit.hsdatashow.impl.topic.water;

import com.lightinit.hsdatashow.mapper.StWaterConsumerMapper;
import com.lightinit.hsdatashow.model.ResultState;
import com.lightinit.hsdatashow.model.topic.water.NameAndValueModel;
import com.lightinit.hsdatashow.model.topic.water.STChartModel;
import com.lightinit.hsdatashow.service.topic.water.IDayMonthYearService;
import com.lightinit.hsdatashow.spring.DynamicDataContextHolder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;

@Service
public class DayMonthYearServiceImpl implements IDayMonthYearService {
    @Autowired
    private StWaterConsumerMapper stWaterConsumerMapper;
    @Override
    public ResultState getYesterdayUsers() {
        DynamicDataContextHolder.setCustomerType(DynamicDataContextHolder.DEFAULT);
        ResultState<Object> resultState = new ResultState<>();
        Calendar cale = Calendar.getInstance();
        int year = cale.get(Calendar.YEAR);
        int month = cale.get(Calendar.MONTH)+1;
        int day = cale.get(Calendar.DATE)-1;
        List<NameAndValueModel> list =  stWaterConsumerMapper.getYesterdayUsers(year,month,day);
        ArrayList<String> names = new ArrayList<>();
        HashMap<String, Object> map = new HashMap<>();
        for (NameAndValueModel nameAndValueModel : list) {
            names.add(nameAndValueModel.getName());
        }
        map.put("names",names);
        map.put("list",list);
        resultState.setData(map);
        return resultState;
    }

    @Override
    public ResultState getYesterdayQXYSGC() {
        DynamicDataContextHolder.setCustomerType(DynamicDataContextHolder.DEFAULT);
        ResultState<Object> resultState = new ResultState<>();
        Calendar cale = Calendar.getInstance();
        int year = cale.get(Calendar.YEAR);
        int month = cale.get(Calendar.MONTH)+1;
        int day = cale.get(Calendar.DATE)-1;
        List<NameAndValueModel> list =  stWaterConsumerMapper.getYesterdayQXYSGC(year,month,day);
        ArrayList<String> names = new ArrayList<>();
        HashMap<String, Object> map = new HashMap<>();
        for (NameAndValueModel nameAndValueModel : list) {
            names.add(nameAndValueModel.getName());
        }
        map.put("names",names);
        map.put("list",list);
        resultState.setData(map);
        return resultState;
    }

    @Override
    public ResultState getYesterdayGHYYS() {
        DynamicDataContextHolder.setCustomerType(DynamicDataContextHolder.DEFAULT);
        ResultState<Object> resultState = new ResultState<>();
        Calendar cale = Calendar.getInstance();
        int year = cale.get(Calendar.YEAR);
        int month = cale.get(Calendar.MONTH)+1;
        int day = cale.get(Calendar.DATE)-1;
        List<STChartModel> list =  stWaterConsumerMapper.getYesterdayGHYYS(year,month,day);
        ArrayList<String> names = new ArrayList<>();
        ArrayList<Object> values = new ArrayList<>();
        HashMap<String, Object> map = new HashMap<>();
        for (STChartModel STChartModel : list) {
            names.add(STChartModel.getName());
            values.add(STChartModel.getValue());
        }
        map.put("names",names);
        map.put("values",values);
        map.put("list",list);
        resultState.setData(map);
        return resultState;
    }

    @Override
    public ResultState getLastMonthYS() {
        DynamicDataContextHolder.setCustomerType(DynamicDataContextHolder.DEFAULT);
        ResultState<Object> resultState = new ResultState<>();
        Calendar cale = Calendar.getInstance();
        int year = cale.get(Calendar.YEAR);
        /*上月*/
        int month = cale.get(Calendar.MONTH);
        List<NameAndValueModel> list =  stWaterConsumerMapper.getMonthYS(year,month);
        ArrayList<String> names = new ArrayList<>();
        HashMap<String, Object> map = new HashMap<>();
        for (NameAndValueModel nameAndValueModel : list) {
            names.add(nameAndValueModel.getName());
        }
        map.put("names",names);
        map.put("list",list);
        resultState.setData(map);
        return resultState;
    }

    @Override
    public ResultState getLastMonthQXYSGC() {
        DynamicDataContextHolder.setCustomerType(DynamicDataContextHolder.DEFAULT);
        ResultState<Object> resultState = new ResultState<>();
        Calendar cale = Calendar.getInstance();
        int year = cale.get(Calendar.YEAR);
        /*上月*/
        int month = cale.get(Calendar.MONTH);
        List<NameAndValueModel> list =  stWaterConsumerMapper.getMonthQXYSGC(year,month);
        ArrayList<String> names = new ArrayList<>();
        HashMap<String, Object> map = new HashMap<>();
        for (NameAndValueModel nameAndValueModel : list) {
            names.add(nameAndValueModel.getName());
        }
        map.put("names",names);
        map.put("list",list);
        resultState.setData(map);
        return resultState;
    }

    @Override
    public ResultState getLastMonthGHYYS() {
        DynamicDataContextHolder.setCustomerType(DynamicDataContextHolder.DEFAULT);
        ResultState<Object> resultState = new ResultState<>();
        Calendar cale = Calendar.getInstance();
        int year = cale.get(Calendar.YEAR);
        /*上月*/
        int month = cale.get(Calendar.MONTH);
        List<STChartModel> list =  stWaterConsumerMapper.getMonthGHYYS(year,month);
        ArrayList<String> names = new ArrayList<>();
        ArrayList<Object> values = new ArrayList<>();
        HashMap<String, Object> map = new HashMap<>();
        for (STChartModel STChartModel : list) {
            names.add(STChartModel.getName());
            values.add(STChartModel.getValue());
        }
        map.put("names",names);
        map.put("values",values);
        map.put("list",list);
        resultState.setData(map);
        return resultState;
    }

    @Override
    public ResultState getMonthYS() {
        DynamicDataContextHolder.setCustomerType(DynamicDataContextHolder.DEFAULT);
        ResultState<Object> resultState = new ResultState<>();
        Calendar cale = Calendar.getInstance();
        int year = cale.get(Calendar.YEAR);
        /*本月*/
        int month = cale.get(Calendar.MONTH)+1;
        List<NameAndValueModel> list =  stWaterConsumerMapper.getMonthYS(year,month);
        ArrayList<String> names = new ArrayList<>();
        HashMap<String, Object> map = new HashMap<>();
        for (NameAndValueModel nameAndValueModel : list) {
            names.add(nameAndValueModel.getName());
        }
        map.put("names",names);
        map.put("list",list);
        resultState.setData(map);
        return resultState;
    }

    @Override
    public ResultState getMonthQXYSGC() {
        DynamicDataContextHolder.setCustomerType(DynamicDataContextHolder.DEFAULT);
        ResultState<Object> resultState = new ResultState<>();
        Calendar cale = Calendar.getInstance();
        int year = cale.get(Calendar.YEAR);
        /*本月*/
        int month = cale.get(Calendar.MONTH)+1;
        List<NameAndValueModel> list =  stWaterConsumerMapper.getMonthQXYSGC(year,month);
        ArrayList<String> names = new ArrayList<>();
        HashMap<String, Object> map = new HashMap<>();
        for (NameAndValueModel nameAndValueModel : list) {
            names.add(nameAndValueModel.getName());
        }
        map.put("names",names);
        map.put("list",list);
        resultState.setData(map);
        return resultState;
    }

    @Override
    public ResultState getMonthGHYYS() {
        DynamicDataContextHolder.setCustomerType(DynamicDataContextHolder.DEFAULT);
        ResultState<Object> resultState = new ResultState<>();
        Calendar cale = Calendar.getInstance();
        int year = cale.get(Calendar.YEAR);
        /*本月*/
        int month = cale.get(Calendar.MONTH)+1;
        List<STChartModel> list =  stWaterConsumerMapper.getMonthGHYYS(year,month);
        ArrayList<String> names = new ArrayList<>();
        ArrayList<Object> values = new ArrayList<>();
        HashMap<String, Object> map = new HashMap<>();
        for (STChartModel STChartModel : list) {
            names.add(STChartModel.getName());
            values.add(STChartModel.getValue());
        }
        map.put("names",names);
        map.put("values",values);
        map.put("list",list);
        resultState.setData(map);
        return resultState;
    }

    @Override
    public ResultState getYearYS() {
        DynamicDataContextHolder.setCustomerType(DynamicDataContextHolder.DEFAULT);
        ResultState<Object> resultState = new ResultState<>();
        Calendar cale = Calendar.getInstance();
        int year = cale.get(Calendar.YEAR);
        List<NameAndValueModel> list =  stWaterConsumerMapper.getMonthYS(year,0);
        ArrayList<String> names = new ArrayList<>();
        HashMap<String, Object> map = new HashMap<>();
        for (NameAndValueModel nameAndValueModel : list) {
            names.add(nameAndValueModel.getName());
        }
        map.put("names",names);
        map.put("list",list);
        resultState.setData(map);
        return resultState;
    }

    @Override
    public ResultState getYearQXYSGC() {
        DynamicDataContextHolder.setCustomerType(DynamicDataContextHolder.DEFAULT);
        ResultState<Object> resultState = new ResultState<>();
        Calendar cale = Calendar.getInstance();
        int year = cale.get(Calendar.YEAR);
        List<NameAndValueModel> list =  stWaterConsumerMapper.getMonthQXYSGC(year,0);
        ArrayList<String> names = new ArrayList<>();
        HashMap<String, Object> map = new HashMap<>();
        for (NameAndValueModel nameAndValueModel : list) {
            names.add(nameAndValueModel.getName());
        }
        map.put("names",names);
        map.put("list",list);
        resultState.setData(map);
        return resultState;
    }

    @Override
    public ResultState getYearGHYYS() {
        DynamicDataContextHolder.setCustomerType(DynamicDataContextHolder.DEFAULT);
        ResultState<Object> resultState = new ResultState<>();
        Calendar cale = Calendar.getInstance();
        int year = cale.get(Calendar.YEAR);
        List<STChartModel> list =  stWaterConsumerMapper.getMonthGHYYS(year,0);
        ArrayList<String> names = new ArrayList<>();
        ArrayList<Object> values = new ArrayList<>();
        HashMap<String, Object> map = new HashMap<>();
        for (STChartModel STChartModel : list) {
            names.add(STChartModel.getName());
            values.add(STChartModel.getValue());
        }
        map.put("names",names);
        map.put("values",values);
        map.put("list",list);
        resultState.setData(map);
        return resultState;
    }
}
