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

import com.lightinit.hsdatashow.dictionary.DicConsumeType;
import com.lightinit.hsdatashow.dictionary.DicWaterSupplyType;
import com.lightinit.hsdatashow.entity.GdpOccupationRatio;
import com.lightinit.hsdatashow.entity.StWaterConsumer;
import com.lightinit.hsdatashow.entity.StWaterConsumerConsumption;
import com.lightinit.hsdatashow.mapper.StWaterConsumerConsumptionMapper;
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.RegionAndConsumption;
import com.lightinit.hsdatashow.model.topic.water.STChartModel;
import com.lightinit.hsdatashow.service.topic.water.IWaterUserService;
import com.lightinit.hsdatashow.spring.DynamicDataContextHolder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

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

@Service
public class WaterUserServiceImpl implements IWaterUserService {
    @Autowired
    private StWaterConsumerMapper  stWaterConsumerMapper;
    @Override
    public ResultState getWaterUser() {
        ResultState resultState = new ResultState();
        DynamicDataContextHolder.setCustomerType(DynamicDataContextHolder.DEFAULT);
        Calendar cale = Calendar.getInstance();
        int year = cale.get(Calendar.YEAR);
        int month = cale.get(Calendar.MONTH)+1;
        List<RegionAndConsumption> list = stWaterConsumerMapper.getWaterUser(month,year);
        HashMap<String, Object> map = new HashMap<>();
        ArrayList<String> names = new ArrayList<>();
        if(list !=null && list.size()>0){
            for (RegionAndConsumption regionAndConsumption : list) {
                names.add(regionAndConsumption.getName());
            }
        }
        map.put("names",names);
        map.put("list",list);
        resultState.setData(map);
        return resultState;
    }

    @Override
    public List<RegionAndConsumption> getAreaWaterUser(String regionName) {
        DynamicDataContextHolder.setCustomerType(DynamicDataContextHolder.DEFAULT);
        Calendar cale = Calendar.getInstance();
        int year = cale.get(Calendar.YEAR);
        int month = cale.get(Calendar.MONTH)+1;
        return stWaterConsumerMapper.getAreaWaterUser(year,month,regionName);
    }

    @Override
    public ResultState getWaterUserConstitute() {
        DynamicDataContextHolder.setCustomerType(DynamicDataContextHolder.DEFAULT);
        ResultState<Object> resultState = new ResultState<>();
        List<NameAndValueModel> list =  stWaterConsumerMapper.getWaterUserConstitute();
        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;
    }
}
