package com.nantian.cloud.dbcapp.service.impl;


import com.alibaba.fastjson.JSONArray;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.nantian.cloud.dbcapp.entity.BigScreenModel;
import com.nantian.cloud.dbcapp.mapper.record.BigScreenMapper;
import com.nantian.cloud.dbcapp.mapper.record.EnergyMapper;
import com.nantian.cloud.dbcapp.service.ElectricityService;
import com.nantian.cloud.dbcapp.service.EnergyService;
import com.nantian.cloud.dbcapp.vo.AreaAndIndustryVo;
import com.nantian.cloud.dbcapp.vo.BigScreenVo;
import com.nantian.cloud.dbcapp.vo.CoalVo;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;


/**
 * <p>
 * 大屏显示 服务实现类 2021-08-02 改为每日算一次
 * 2022-11-09 禁用老服务实现类
 * </p>
 *
 * @author zfw
 * @since 2020-08-05
 */
//@Service("bigScreenService")
public class BigScreenImpl {

    //@Autowired
    private EnergyMapper energyMapper;

    //@Autowired
    private BigScreenMapper bigScreenMapper;

    //@Autowired
    private ElectricityService electricityService;

    //@Autowired
    private EnergyService energyService;

    /**
    * @Description: 删除本年统计值(每个月3号执行 0:10) 0 30 9 1 * ? 每月1号上午9点半执行
    * @Param: []
    * @return: java.lang.Integer
    * @Author: zfw
    * @Date: 2021/3/4
    * @Date: 14:52
    */
    //@Override
    //@Scheduled(cron = "0 00 23 * * ?")
    public Integer deleteThisYearAll() {
        String time =getLastMonthAgo();
        time =time.substring(0,4);
       int row= bigScreenMapper.delete(new QueryWrapper<BigScreenModel>().eq(BigScreenModel.YEAR, time));
        return row;
    }

    /**
    * @Description: 删除近6个月数据 每月3号 0:40执行
    * @Param: []
    * @return: java.lang.Integer
    * @Author: zfw
    * @Date: 2021/3/4
    * @Date: 14:53
    */
    //@Override
    //@Scheduled(cron = "0 00 0 * * ?")
    public Integer deleteThisYearAll6(){
        int row= bigScreenMapper.delete(new QueryWrapper<BigScreenModel>().eq(BigScreenModel.YEAR, "近六个月"));
        return row;

    }

    //@Override
    //@Scheduled(cron = "0 30 09 * * ?")
    public Integer getAllEnergyZxjcYear() {
        int row= bigScreenMapper.delete(new QueryWrapper<BigScreenModel>().eq(BigScreenModel.TYPE, 2));
        String[] area = {"云南", "昆明", "曲靖", "玉溪", "保山", "昭通", "丽江", "普洱", "临沧", "楚雄", "红河", "文山", "版纳", "大理", "德宏", "怒江", "迪庆"};
        String industry = "全部";
        List<BigScreenVo> listArea=bigScreenMapper.getAllArea();
       // List<String> list =new ArrayList<>();
        for (int i = 0; i < area.length; i++) {
            HashMap<String, String> areaAndIndustryCode = energyService.getAreaAndIndustryCode(area[i], industry);
            String areaName = areaAndIndustryCode.get("地区");
            String industryName = areaAndIndustryCode.get("行业");
            Integer  num = electricityService.getTotal(areaName, industryName , null);
            BigScreenModel big = new BigScreenModel();
            big.setType(2);
            // big.setYear(time.substring(0, 4));
            big.setCity("云南");
            big.setCounty(area[i].substring(0,2));
             big.setValue(num);
            bigScreenMapper.insert(big);
            System.out.println(big);
        }

        for (int i = 0; i < listArea.size(); i++) {
            HashMap<String, String> areaAndIndustryCode = energyService.getAreaAndIndustryCode(listArea.get(i).getCode(), industry);
            String areaName = areaAndIndustryCode.get("地区");
            Integer  num = electricityService.getTotal(areaName, null , null);
            BigScreenModel big = new BigScreenModel();
            big.setType(2);
            //big.setYear(time.substring(0, 4));
            big.setCity(listArea.get(i).getName().substring(0,2));
            big.setCounty(listArea.get(i).getName().substring(0,2));
            big.setValue(num);
            bigScreenMapper.insert(big);
            System.out.println(big);
        }
        return null;
    }
    /**
    * @Description: 电力关口
    * @Param: []
    * @return: java.lang.Integer
    * @Author: zfw
    * @Date: 2021/8/11
    * @Date: 21:08
    */
    //@Override
    //@Scheduled(cron = "0 00 10 * * ?")
    public Integer getAllEnergyDlgkYear() {
        int row= bigScreenMapper.delete(new QueryWrapper<BigScreenModel>().eq(BigScreenModel.TYPE, 9));
        String[] area = {"云南", "昆明", "曲靖", "玉溪", "保山", "昭通", "丽江", "普洱", "临沧", "楚雄", "红河", "文山", "版纳", "大理", "德宏", "怒江", "迪庆"};
        String industry = "全部";
        List<BigScreenVo> listArea=bigScreenMapper.getAllArea();
        List<String> list =new ArrayList<>();


        for (int i = 0; i < area.length; i++) {
            HashMap<String, String> areaAndIndustryCode = energyService.getAreaAndIndustryCode(area[i], industry);
            String areaName = areaAndIndustryCode.get("地区");
            String industryName = areaAndIndustryCode.get("行业");
            list = this.getElectricityCompanyList(areaName, null , null);
            BigScreenModel big = new BigScreenModel();
            big.setType(9);
           // big.setYear(time.substring(0, 4));
            big.setCity("云南");
            big.setCounty(area[i].substring(0,2));
            if(list!=null && list.size()>0){
                big.setValue(list.size());
            }else{
                big.setValue(0);
            }
            bigScreenMapper.insert(big);
            System.out.println(big);
        }

        for (int i = 0; i < listArea.size(); i++) {
            HashMap<String, String> areaAndIndustryCode = energyService.getAreaAndIndustryCode(listArea.get(i).getCode(), industry);
            String areaName = areaAndIndustryCode.get("地区");
            list = this.getElectricityCompanyList(areaName, null, null);
            BigScreenModel big = new BigScreenModel();
            big.setType(9);
            //big.setYear(time.substring(0, 4));
            big.setCity(listArea.get(i).getName().substring(0,2));
            big.setCounty(listArea.get(i).getName().substring(0,2));
            if(list!=null && list.size()>0){
                big.setValue(list.size());
            }else{
                big.setValue(0);
            }
            bigScreenMapper.insert(big);
            System.out.println(big);
        }

        return null;
    }

    public List<String> getElectricityCompanyList(String area, String industry, String cmpName) {
        String areaName =area;
        areaName = areaName+"%";
        String industryName = industry;
        if("".equals(cmpName)||cmpName==null){
            cmpName=null;
        }else {
            cmpName ="%"+cmpName+"%";
        }
        List<String> companyList= energyMapper.selectCompanyListByAreaAndIndustryElectricity(areaName,industryName,cmpName);
        if(companyList.size()==0){
            companyList.add("");
        }
        return companyList;
    }

    //@Override
    public Integer getAllEnergyDjgjYear() {
        String[] area = {"云南", "昆明", "曲靖", "玉溪", "保山", "昭通", "丽江", "普洱", "临沧", "楚雄", "红河", "文山", "版纳", "大理", "德宏", "怒江", "迪庆"};
        String industry = "全部";
        List<BigScreenVo> listArea=bigScreenMapper.getAllArea();

        //州市
        for (int i = 0; i < area.length; i++) {
            HashMap<String, String> areaAndIndustryCode = energyService.getAreaAndIndustryCode(area[i], industry);
            String areaName = areaAndIndustryCode.get("地区");
            String industryName = areaAndIndustryCode.get("行业");
            Integer maxSuccdess =  energyMapper.selectMaxSuccess(areaName,industryName);
            BigScreenModel big = new BigScreenModel();
            big.setType(10);
            //big.setYear(time.substring(0, 4));
            big.setCity("云南");
            big.setCounty(area[i].substring(0,2));
            big.setValue(maxSuccdess);
            bigScreenMapper.insert(big);
            System.out.println(big);
        }

        for (int i = 0; i < listArea.size(); i++) {
            HashMap<String, String> areaAndIndustryCode = energyService.getAreaAndIndustryCode(listArea.get(i).getCode(), industry);
            String areaName = areaAndIndustryCode.get("地区");
            Integer maxSuccdess =  energyMapper.selectMaxSuccess(areaName,null);
            BigScreenModel big = new BigScreenModel();
            big.setType(10);
            //big.setYear(time.substring(0, 4));
            big.setCity(listArea.get(i).getName().substring(0,2));
            big.setCounty(listArea.get(i).getName().substring(0,2));
            big.setValue(maxSuccdess);
            bigScreenMapper.insert(big);
            System.out.println(big);
        }
        return null;
    }

    /** 综合能耗
    * @Description: 综合能耗 (每个月1好1:00执行)
    * @Param: []
    * @return: java.util.List<com.nantian.cloud.dbcapp.vo.AreaAndIndustryVo>
    * @Author: zfw
    * @Date: 2021/3/1
    * @Date: 23:41
    */
    //@Override
    //@Scheduled(cron = "0 00 1 * * ?")
    public List<AreaAndIndustryVo> getAllTce() {
        String time =getLastMonthAgo();
        String[] area = {"云南", "昆明", "曲靖", "玉溪", "保山", "昭通", "丽江", "普洱", "临沧", "楚雄", "红河", "文山", "版纳", "大理", "德宏", "怒江", "迪庆"};
        String industry = "全部";
        List<BigScreenVo> listArea=bigScreenMapper.getAllArea();
        List<AreaAndIndustryVo> list = new ArrayList<>();

            for (int i = 0; i < area.length; i++) {
              Float num=  energyService.getTotal(area[i], industry, time);
                    BigScreenModel big = new BigScreenModel();
                    big.setType(0);
                    big.setYear(time.substring(0, 4));
                    big.setCity("云南");
                    big.setCounty(area[i]);
                    if(i>8){
                        big.setDepartmentName(area[i]+"州管理员");
                    }else{
                        big.setDepartmentName(area[i]+"市管理员");
                    }
                    if(num!=null){
                        big.setValue(num);
                    }else{
                        big.setValue(0);
                    }
                    bigScreenMapper.insert(big);
                    System.out.println(big);
                }

            for (int i = 0; i < listArea.size(); i++) {
              Float num=  energyService.getTotal(listArea.get(i).getCode(), industry, time);
                    BigScreenModel big = new BigScreenModel();
                    big.setType(0);
                    big.setYear(time.substring(0, 4));
                    big.setCity(listArea.get(i).getName());
                    big.setCounty(listArea.get(i).getName());
                    if(Integer.valueOf(listArea.get(i).getPcode().substring(0,4))>5309){
                        big.setDepartmentName(listArea.get(i).getPname()+"州管理员");
                    }else{
                        big.setDepartmentName(listArea.get(i).getPname()+"市管理员");
                    }
                    if(num!=null){
                        big.setValue(num);
                    }else{
                        big.setValue(0);
                    }
                    bigScreenMapper.insert(big);
                    System.out.println(big);
                }
            //计量院
            for (int i = 0; i < area.length; i++) {
              Float num=  energyService.getTotal(area[i], industry, time);
                    BigScreenModel big = new BigScreenModel();
                    big.setType(0);
                    big.setYear(time.substring(0, 4));
                    big.setCity("云南");
                    big.setCounty(area[i]);
                    big.setDepartmentName("云南省计量测试技术研究院");
                    if(num!=null){
                        big.setValue(num);
                    }else{
                        big.setValue(0);
                    }
                    bigScreenMapper.insert(big);
                    System.out.println(big);
                }

            for (int i = 0; i < listArea.size(); i++) {
              Float num=  energyService.getTotal(listArea.get(i).getCode(), industry, time);
                    BigScreenModel big = new BigScreenModel();
                    big.setType(0);
                    big.setYear(time.substring(0, 4));
                    big.setCity(listArea.get(i).getName());
                    big.setCounty(listArea.get(i).getName());
                    big.setDepartmentName("云南省计量测试技术研究院");
                    if(num!=null){
                        big.setValue(num);
                    }else{
                        big.setValue(0);
                    }
                    bigScreenMapper.insert(big);
                    System.out.println(big);
                }
        //System.out.println();
        return list;
    }
    /**
    * @Description: 336家企业
    * @Param: []
    * @return: java.util.List<com.nantian.cloud.dbcapp.vo.AreaAndIndustryVo>
    * @Author: zfw
    * @Date: 2021/3/4
    * @Date: 14:33
    */
    //@Override
    //@Scheduled(cron = "0 30 1 * * ?")
    public Integer getAllEnergyNameYear() {
        String[] area = {"云南", "昆明", "曲靖", "玉溪", "保山", "昭通", "丽江", "普洱", "临沧", "楚雄", "红河", "文山", "版纳", "大理", "德宏", "怒江", "迪庆"};
        String industry = "全部";
        bigScreenMapper.delete(new QueryWrapper<BigScreenModel>().eq(BigScreenModel.TYPE, 8));
        List<AreaAndIndustryVo> list = new ArrayList<>();
        List<BigScreenVo> listArea=bigScreenMapper.getAllArea();

            for (int i = 0; i < area.length; i++) {
              Integer num=  this.getTotal(area[i], industry, "");
                    BigScreenModel big = new BigScreenModel();
                    big.setType(8);
                    //big.setYear(Integer.valueOf(time[a].substring(0, 4)));
                    big.setCity("云南");
                    big.setCounty(area[i]);
                    if(i>8){
                        big.setDepartmentName(area[i]+"州管理员");
                    }else{
                        big.setDepartmentName(area[i]+"市管理员");
                    }
                    if(num!=null){
                        big.setValue(num);
                    }else{
                        big.setValue(0);
                    }
                   bigScreenMapper.insert(big);
                    System.out.println(big);
                }

        for (int i = 0; i < listArea.size(); i++) {
            Integer num=  this.getTotal(listArea.get(i).getCode(), industry, "");
            BigScreenModel big = new BigScreenModel();
            big.setType(8);
            //big.setYear(Integer.valueOf(time[a].substring(0, 4)));
            big.setCity(listArea.get(i).getName());
            big.setCounty(listArea.get(i).getName());
            if(Integer.valueOf(listArea.get(i).getPcode().substring(0,4))>5309){
                big.setDepartmentName(listArea.get(i).getPname()+"州管理员");
            }else{
                big.setDepartmentName(listArea.get(i).getPname()+"市管理员");
            }
            if(num!=null){
                big.setValue(num);
            }else{
                big.setValue(0);
            }
            bigScreenMapper.insert(big);
            System.out.println(big);

        }

        for (int i = 0; i < area.length; i++) {
              Integer num=  this.getTotal(area[i], industry, "");
                    BigScreenModel big = new BigScreenModel();
                    big.setType(8);
                    //big.setYear(Integer.valueOf(time[a].substring(0, 4)));
                    big.setCity("云南");
                    big.setCounty(area[i]);
                    big.setDepartmentName("云南省计量测试技术研究院");
                    if(num!=null){
                        big.setValue(num);
                    }else{
                        big.setValue(0);
                    }
                   bigScreenMapper.insert(big);
                    System.out.println(big);
                }

        for (int i = 0; i < listArea.size(); i++) {
            Integer num=  this.getTotal(listArea.get(i).getCode(), industry, "");
            BigScreenModel big = new BigScreenModel();
            big.setType(8);
            //big.setYear(Integer.valueOf(time[a].substring(0, 4)));
            big.setCity(listArea.get(i).getName());
            big.setCounty(listArea.get(i).getName());
            big.setDepartmentName("云南省计量测试技术研究院");
            if(num!=null){
                big.setValue(num);
            }else{
                big.setValue(0);
            }
            bigScreenMapper.insert(big);
            System.out.println(big);

        }



        //System.out.println();
        return 0;
    }
    
    
    
    /***
     * @Description: 查询所有地区, get大屏地区能耗提供接口 每月3号 1:30执行
     * @Param: []
     * @return: java.util.List<com.nantian.cloud.dbcapp.vo.AreaAndIndustryVo>
     * @Author: zfw
     * @Date: 2021/2/28
     * @Date: 10:33
     */
    //@Override
    //@Scheduled(cron = "0 00 2 * * ?")
    public List<AreaAndIndustryVo> getAllAreaByYear() {
        String time =getLastMonthAgo();
        String industry = "全部";
        List<BigScreenVo> listArea=bigScreenMapper.getAllArea();
        List<AreaAndIndustryVo> list = new ArrayList<>();
        String[] area = {"云南", "昆明", "曲靖", "玉溪", "保山", "昭通", "丽江", "普洱", "临沧", "楚雄", "红河", "文山", "版纳", "大理", "德宏", "怒江", "迪庆"};

        for (int i = 0; i < listArea.size(); i++) {
                list = energyService.getEnergyByAreaList(listArea.get(i).getCode(), industry, time);
                for (int j = 0; j < list.size(); j++) {
                    BigScreenModel big = new BigScreenModel();
                    big.setType(1);
                    big.setYear(time.substring(0, 4));
                    big.setCity(listArea.get(i).getName());
                    big.setCounty(listArea.get(i).getName());
                    if(Integer.valueOf(listArea.get(i).getPcode().substring(0,4))>5309){
                        big.setDepartmentName(listArea.get(i).getPname()+"州管理员");
                    }else{
                        big.setDepartmentName(listArea.get(i).getPname()+"市管理员");
                    }
                    if(list.get(j).getEnergyValue()!=null){
                        big.setValue(Float.valueOf(list.get(j).getEnergyValue())/10000);
                    }else{
                        big.setValue(0);
                    }
                    bigScreenMapper.insert(big);
                    System.out.println(big);
                }

            }
        //州市
        for (int i = 0; i < area.length; i++) {
            list = energyService.getEnergyByAreaList(area[i], industry, time);
            for (int j = 0; j < list.size(); j++) {
                BigScreenModel big = new BigScreenModel();
                big.setType(1);
                big.setYear(time.substring(0, 4));
                big.setCity(area[i]);
                big.setCounty(list.get(j).getName());
                if(i>8){
                    big.setDepartmentName(area[i]+"州管理员");
                }else{
                    big.setDepartmentName(area[i]+"市管理员");
                }
                if(list.get(j).getEnergyValue()!=null){
                    big.setValue(Float.valueOf(list.get(j).getEnergyValue())/10000);
                }else{
                    big.setValue(0);
                }
               bigScreenMapper.insert(big);
                System.out.println(big);
            }

        }


        for (int i = 0; i < listArea.size(); i++) {
                list = energyService.getEnergyByAreaList(listArea.get(i).getCode(), industry, time);
                for (int j = 0; j < list.size(); j++) {
                    BigScreenModel big = new BigScreenModel();
                    big.setType(1);
                    big.setYear(time.substring(0, 4));
                    big.setCity(listArea.get(i).getName());
                    big.setCounty(listArea.get(i).getName());
                    big.setDepartmentName("云南省计量测试技术研究院");
                    if(list.get(j).getEnergyValue()!=null){
                        big.setValue(Float.valueOf(list.get(j).getEnergyValue())/10000);
                    }else{
                        big.setValue(0);
                    }
                    bigScreenMapper.insert(big);
                    System.out.println(big);
                }

            }
        //州市
        for (int i = 0; i < area.length; i++) {
            list = energyService.getEnergyByAreaList(area[i], industry, time);
            for (int j = 0; j < list.size(); j++) {
                BigScreenModel big = new BigScreenModel();
                big.setType(1);
                big.setYear(time.substring(0, 4));
                big.setCity(area[i]);
                big.setCounty(list.get(j).getName());
                big.setDepartmentName("云南省计量测试技术研究院");
                if(list.get(j).getEnergyValue()!=null){
                    big.setValue(Float.valueOf(list.get(j).getEnergyValue())/10000);
                }else{
                    big.setValue(0);
                }
               bigScreenMapper.insert(big);
                System.out.println(big);
            }

        }


        //System.out.println();
        return list;
    }

    /***
     * @Description: 查询所有地区, get大屏地区能耗提供接口 每月3号 2:00执行
     * @Param: []
     * @return: java.util.List<com.nantian.cloud.dbcapp.vo.AreaAndIndustryVo>
     * @Author: zfw
     * @Date: 2021/2/28
     * @Date: 10:33
     */
    //@Override
    //@Scheduled(cron = "0 40 2 * * ?")
    public List<AreaAndIndustryVo> getAllHyByYear() {
        String time =getLastMonthAgo();
        String industry = "全部";
        List<BigScreenVo> listArea=bigScreenMapper.getAllArea();
        List<AreaAndIndustryVo> list = new ArrayList<>();
        String[] area = {"云南", "昆明", "曲靖", "玉溪", "保山", "昭通", "丽江", "普洱", "临沧", "楚雄", "红河", "文山", "版纳", "大理", "德宏", "怒江", "迪庆"};

            for (int i = 0; i < listArea.size(); i++) {
                list = energyService.getEnergyByIndustryList(listArea.get(i).getCode(), industry, time);
                for (int j = 0; j < list.size(); j++) {
                    BigScreenModel big = new BigScreenModel();
                    big.setType(3);
                    big.setYear(time.substring(0, 4));
                    big.setCity(listArea.get(i).getPname());
                    big.setCounty(listArea.get(i).getName());
                    if(Integer.valueOf(listArea.get(i).getPcode().substring(0,4))>5309){
                        big.setDepartmentName(listArea.get(i).getPname()+"州管理员");
                    }else{
                        big.setDepartmentName(listArea.get(i).getPname()+"市管理员");
                    }
                    if(list.get(j).getEnergyValue()!=null){
                        big.setValue(Float.valueOf(list.get(j).getEnergyValue())/10000);
                    }else{
                        big.setValue(0);
                    }
                    big.setName(list.get(j).getName());
                    bigScreenMapper.insert(big);
                    System.out.println(big);
                }


            }
            //州市
        for (int i = 0; i < area.length; i++) {
            list = energyService.getEnergyByIndustryList(area[i], industry, time);
            for (int j = 0; j < list.size(); j++) {
                BigScreenModel big = new BigScreenModel();
                big.setType(3);
                big.setYear(time.substring(0, 4));
                big.setCity("云南");
                big.setCounty(area[i]);
                big.setName(list.get(j).getName());
                if(i>8){
                    big.setDepartmentName(area[i]+"州管理员");
                }else{
                    big.setDepartmentName(area[i]+"市管理员");
                }
                if(list.get(j).getEnergyValue()!=null){
                    big.setValue(Float.valueOf(list.get(j).getEnergyValue())/10000);
                }else{
                    big.setValue(0);
                }
                bigScreenMapper.insert(big);
                System.out.println(big);
            }

        }

        for (int i = 0; i < listArea.size(); i++) {
                list = energyService.getEnergyByIndustryList(listArea.get(i).getCode(), industry, time);
                for (int j = 0; j < list.size(); j++) {
                    BigScreenModel big = new BigScreenModel();
                    big.setType(3);
                    big.setYear(time.substring(0, 4));
                    big.setCity(listArea.get(i).getPname());
                    big.setCounty(listArea.get(i).getName());
                    big.setDepartmentName("云南省计量测试技术研究院");
                    if(list.get(j).getEnergyValue()!=null){
                        big.setValue(Float.valueOf(list.get(j).getEnergyValue())/10000);
                    }else{
                        big.setValue(0);
                    }
                    big.setName(list.get(j).getName());
                    bigScreenMapper.insert(big);
                    System.out.println(big);
                }


            }
            //州市
        for (int i = 0; i < area.length; i++) {
            list = energyService.getEnergyByIndustryList(area[i], industry, time);
            for (int j = 0; j < list.size(); j++) {
                BigScreenModel big = new BigScreenModel();
                big.setType(3);
                big.setYear(time.substring(0, 4));
                big.setCity("云南");
                big.setCounty(area[i]);
                big.setName(list.get(j).getName());
                big.setDepartmentName("云南省计量测试技术研究院");
                if(list.get(j).getEnergyValue()!=null){
                    big.setValue(Float.valueOf(list.get(j).getEnergyValue())/10000);
                }else{
                    big.setValue(0);
                }
                bigScreenMapper.insert(big);
                System.out.println(big);
            }

        }
        //System.out.println();
        return list;
    }

    /***
    * @Description: 煤消耗 每月3号 2:30执行
    * @Param: []
    * @return: java.util.List<com.nantian.cloud.dbcapp.vo.AreaAndIndustryVo>
    * @Author: zfw
    * @Date: 2021/3/4
    * @Date: 15:11
    */
    //@Override
    ////@Scheduled(cron = "0 30 2 3 * ?")
    //@Scheduled(cron = "0 20 3 * * ?")
    public List<AreaAndIndustryVo> getAllMeiYear() {
        String time =getLastMonthAgo();
        String industry = "全部";
        List<BigScreenVo> listArea=bigScreenMapper.getAllArea();
        String[] area = {"云南", "昆明", "曲靖", "玉溪", "保山", "昭通", "丽江", "普洱", "临沧", "楚雄", "红河", "文山", "版纳", "大理", "德宏", "怒江", "迪庆"};


            for (int i = 0; i < listArea.size(); i++) {
                String startTime = null;
                String endTime = null;
                if (time.contains("&")) {
                    startTime = time.split("&")[0];
                    endTime = time.split("&")[1];
                    startTime = startTime.substring(0, 7);
                    endTime = endTime.substring(0, 7);

                }
                Map<String, Object> map = new HashMap<>();
                List<String> areaList = new ArrayList<>();
                List<String> dataValueList = new ArrayList<>();
                Float value = 0.0f;
                Integer timeStr = Integer.valueOf(startTime.substring(0, 4));
                Integer timeStr1 = Integer.valueOf(endTime.substring(0, 4));
                List<String> companyList = energyService.companyList(listArea.get(i).getCode(), industry, time);
                List<CoalVo> coalVosResult = new ArrayList<>();
                if (timeStr >= 2020) {
                    HashMap<String, String> areaAndIndustryCode = energyService.getAreaAndIndustryCode(listArea.get(i).getCode(), industry);
                    String areaName = areaAndIndustryCode.get("地区");
                    String industryName = areaAndIndustryCode.get("行业");
                    List<String> companyList2020 = energyService.getCompanyList2020(areaName, industryName, time, null);
                    List<CoalVo> coalVos = energyMapper.foundCoalByMonth2020(companyList2020, startTime, endTime);
                    coalVosResult = energyService.getMonthAndValue(startTime, endTime, coalVos);

                } else if (timeStr1 < 2020) {
                    //2019年数据
                    if(companyList!=null && companyList.size()>0){
                        List<Integer> list = energyService.getentIdByEnterpriseCode(companyList);
                        coalVosResult = energyMapper.foundCoalByMonth(list, startTime, endTime);
                    }

                }
                for (int j = 0; j < coalVosResult.size(); j++) {
                    BigScreenModel big = new BigScreenModel();
                    big.setType(5);
                    big.setYear(time.substring(0, 4));
                    big.setCity(listArea.get(i).getPname());
                    big.setCounty(listArea.get(i).getName());
                    if(Integer.valueOf(listArea.get(i).getPcode().substring(0,4))>5309){
                        big.setDepartmentName(listArea.get(i).getPname()+"州管理员");
                    }else{
                        big.setDepartmentName(listArea.get(i).getPname()+"市管理员");
                    }
                    if(coalVosResult.get(j).getValue()!=null){
                        big.setValue(Float.valueOf(coalVosResult.get(j).getValue()));
                    }else{
                        big.setValue(0);
                    }
                    big.setName(coalVosResult.get(j).getMonth());
                    bigScreenMapper.insert(big);
                    System.out.println(big);
                }


                for (int j = 0; j < coalVosResult.size(); j++) {
                    BigScreenModel big = new BigScreenModel();
                    big.setType(5);
                    big.setYear(time.substring(0, 4));
                    big.setCity(listArea.get(i).getPname());
                    big.setCounty(listArea.get(i).getName());
                    big.setDepartmentName("云南省计量测试技术研究院");
                    if(coalVosResult.get(j).getValue()!=null){
                        big.setValue(Float.valueOf(coalVosResult.get(j).getValue()));
                    }else{
                        big.setValue(0);
                    }
                    big.setName(coalVosResult.get(j).getMonth());
                    bigScreenMapper.insert(big);
                    System.out.println(big);
                }



        }
        //州市
        for (int i = 0; i <area.length; i++) {
            String startTime = null;
            String endTime = null;
            if (time.contains("&")) {
                startTime = time.split("&")[0];
                endTime = time.split("&")[1];
                startTime = startTime.substring(0, 7);
                endTime = endTime.substring(0, 7);

            }
            Map<String, Object> map = new HashMap<>();
            List<String> areaList = new ArrayList<>();
            List<String> dataValueList = new ArrayList<>();
            Float value = 0.0f;
            Integer timeStr = Integer.valueOf(startTime.substring(0, 4));
            Integer timeStr1 = Integer.valueOf(endTime.substring(0, 4));
            List<String> companyList = energyService.companyList(area[i], industry, time);
            List<CoalVo> coalVosResult = new ArrayList<>();
            if (timeStr >= 2020) {
                HashMap<String, String> areaAndIndustryCode = energyService.getAreaAndIndustryCode(area[i], industry);
                String areaName = areaAndIndustryCode.get("地区");
                String industryName = areaAndIndustryCode.get("行业");
                List<String> companyList2020 = energyService.getCompanyList2020(areaName, industryName, time, null);
                List<CoalVo> coalVos = energyMapper.foundCoalByMonth2020(companyList2020, startTime, endTime);
                coalVosResult = energyService.getMonthAndValue(startTime, endTime, coalVos);

            } else if (timeStr1 < 2020) {
                //2019年数据
                if(companyList!=null && companyList.size()>0){
                    List<Integer> list = energyService.getentIdByEnterpriseCode(companyList);
                    coalVosResult = energyMapper.foundCoalByMonth(list, startTime, endTime);
                }


            }
            for (int j = 0; j < coalVosResult.size(); j++) {
                BigScreenModel big = new BigScreenModel();
                big.setType(5);
                big.setYear(time.substring(0, 4));
                big.setCity("云南");
                big.setCounty(area[i]);
                if(i>8){
                    big.setDepartmentName(area[i]+"州管理员");
                }else{
                    big.setDepartmentName(area[i]+"市管理员");
                }
                if(coalVosResult.get(j).getValue()!=null){
                    big.setValue(Float.valueOf(coalVosResult.get(j).getValue()));
                }else{
                    big.setValue(0);
                }
                big.setName(coalVosResult.get(j).getMonth());
                bigScreenMapper.insert(big);
                System.out.println(big);
            }

            for (int j = 0; j < coalVosResult.size(); j++) {
                BigScreenModel big = new BigScreenModel();
                big.setType(5);
                big.setYear(time.substring(0, 4));
                big.setCity("云南");
                big.setCounty(area[i]);
                big.setDepartmentName("云南省计量测试技术研究院");
                if(coalVosResult.get(j).getValue()!=null){
                    big.setValue(Float.valueOf(coalVosResult.get(j).getValue()));
                }else{
                    big.setValue(0);
                }
                big.setName(coalVosResult.get(j).getMonth());
                bigScreenMapper.insert(big);
                System.out.println(big);
            }


        }
        return null;
    }
/**
* @Description: 水消耗号 每月3号 3:00执行
* @Param: []
* @return: java.util.List<com.nantian.cloud.dbcapp.vo.AreaAndIndustryVo>
* @Author: zfw
* @Date: 2021/3/4
* @Date: 15:11
*/
    //@Override
    ////@Scheduled(cron = "0 00 3 3 * ?")
    //@Scheduled(cron = "0 00 4 * * ?")
    public List<AreaAndIndustryVo> getAllWaterYear() {
        String time =getLastMonthAgo();
        String industry = "全部";
        List<BigScreenVo> listArea=bigScreenMapper.getAllArea();
        String[] area = {"云南", "昆明", "曲靖", "玉溪", "保山", "昭通", "丽江", "普洱", "临沧", "楚雄", "红河", "文山", "版纳", "大理", "德宏", "怒江", "迪庆"};


            for (int i = 0; i < listArea.size(); i++) {
                String startTime = null;
                String endTime = null;
                if (time.contains("&")) {
                    startTime = time.split("&")[0];
                    endTime = time.split("&")[1];
                    startTime = startTime.substring(0, 7);
                    endTime = endTime.substring(0, 7);

                }
                Map<String, Object> map = new HashMap<>();
                List<String> areaList = new ArrayList<>();
                List<String> dataValueList = new ArrayList<>();
                Float value = 0.0f;
                Integer timeStr = Integer.valueOf(startTime.substring(0, 4));
                Integer timeStr1 = Integer.valueOf(endTime.substring(0, 4));
                List<String> companyList = energyService.companyList(listArea.get(i).getCode(), industry, time);
                List<CoalVo> coalVosResult = new ArrayList<>();
                if (timeStr >= 2020) {
                    HashMap<String, String> areaAndIndustryCode = energyService.getAreaAndIndustryCode(listArea.get(i).getCode(), industry);
                    String areaName = areaAndIndustryCode.get("地区");
                    String industryName = areaAndIndustryCode.get("行业");
                    List<String> companyList2020 = energyService.getCompanyList2020(areaName, industryName, time, null);
                    List<CoalVo> coalVos = energyMapper.foundWaterByMonth2020(companyList2020, startTime, endTime);
                    coalVosResult = energyService.getMonthAndValue(startTime, endTime, coalVos);

                } else if (timeStr1 < 2020) {
                    //2019年数据
                    if(companyList!=null && companyList.size()>0){
                        List<Integer> list = energyService.getentIdByEnterpriseCode(companyList);
                        coalVosResult = energyMapper.foundWaterByMonth(list, startTime, endTime);
                    }

                }
                for (int j = 0; j < coalVosResult.size(); j++) {
                    BigScreenModel big = new BigScreenModel();
                    big.setType(6);
                    big.setYear(time.substring(0, 4));
                    big.setCity(listArea.get(i).getPname());
                    big.setCounty(listArea.get(i).getName());
                    if(Integer.valueOf(listArea.get(i).getPcode().substring(0,4))>5309){
                        big.setDepartmentName(listArea.get(i).getPname()+"州管理员");
                    }else{
                        big.setDepartmentName(listArea.get(i).getPname()+"市管理员");
                    }
                    if(coalVosResult.get(j).getValue()!=null){
                        big.setValue(Float.valueOf(coalVosResult.get(j).getValue()));
                    }else{
                        big.setValue(0);
                    }
                    big.setName(coalVosResult.get(j).getMonth());
                    bigScreenMapper.insert(big);
                    System.out.println(big);
                }

                for (int j = 0; j < coalVosResult.size(); j++) {
                    BigScreenModel big = new BigScreenModel();
                    big.setType(6);
                    big.setYear(time.substring(0, 4));
                    big.setCity(listArea.get(i).getPname());
                    big.setCounty(listArea.get(i).getName());
                    big.setDepartmentName("云南省计量测试技术研究院");
                    if(coalVosResult.get(j).getValue()!=null){
                        big.setValue(Float.valueOf(coalVosResult.get(j).getValue()));
                    }else{
                        big.setValue(0);
                    }
                    big.setName(coalVosResult.get(j).getMonth());
                    bigScreenMapper.insert(big);
                    System.out.println(big);
                }


            }
        //州市
        for (int i = 0; i <area.length; i++) {
            String startTime = null;
            String endTime = null;
            if (time.contains("&")) {
                startTime = time.split("&")[0];
                endTime = time.split("&")[1];
                startTime = startTime.substring(0, 7);
                endTime = endTime.substring(0, 7);

            }
            Map<String, Object> map = new HashMap<>();
            List<String> areaList = new ArrayList<>();
            List<String> dataValueList = new ArrayList<>();
            Float value = 0.0f;
            Integer timeStr = Integer.valueOf(startTime.substring(0, 4));
            Integer timeStr1 = Integer.valueOf(endTime.substring(0, 4));
            List<String> companyList = energyService.companyList(area[i], industry, time);
            List<CoalVo> coalVosResult = new ArrayList<>();
            if (timeStr >= 2020) {
                HashMap<String, String> areaAndIndustryCode = energyService.getAreaAndIndustryCode(area[i], industry);
                String areaName = areaAndIndustryCode.get("地区");
                String industryName = areaAndIndustryCode.get("行业");
                List<String> companyList2020 = energyService.getCompanyList2020(areaName, industryName, time, null);
                List<CoalVo> coalVos = energyMapper.foundWaterByMonth2020(companyList2020, startTime, endTime);
                coalVosResult = energyService.getMonthAndValue(startTime, endTime, coalVos);

            } else if (timeStr1 < 2020) {
                //2019年数据
                if(companyList!=null && companyList.size()>0){
                    List<Integer> list = energyService.getentIdByEnterpriseCode(companyList);
                    coalVosResult = energyMapper.foundWaterByMonth(list, startTime, endTime);
                }


            }
            for (int j = 0; j < coalVosResult.size(); j++) {
                BigScreenModel big = new BigScreenModel();
                big.setType(6);
                big.setYear(time.substring(0,4));
                big.setCity("云南");
                big.setCounty(area[i]);
                if(i>8){
                    big.setDepartmentName(area[i]+"州管理员");
                }else{
                    big.setDepartmentName(area[i]+"市管理员");
                }
                if(coalVosResult.get(j).getValue()!=null){
                    big.setValue(Float.valueOf(coalVosResult.get(j).getValue()));
                }else{
                    big.setValue(0);
                }
                big.setName(coalVosResult.get(j).getMonth());
                bigScreenMapper.insert(big);
                System.out.println(big);
            }
            for (int j = 0; j < coalVosResult.size(); j++) {
                BigScreenModel big = new BigScreenModel();
                big.setType(6);
                big.setYear(time.substring(0,4));
                big.setCity("云南");
                big.setDepartmentName("云南省计量测试技术研究院");
                big.setCounty(area[i]);
                if(coalVosResult.get(j).getValue()!=null){
                    big.setValue(Float.valueOf(coalVosResult.get(j).getValue()));
                }else{
                    big.setValue(0);
                }
                big.setName(coalVosResult.get(j).getMonth());
                bigScreenMapper.insert(big);
                System.out.println(big);
            }


        }

        return null;
    }

    /**
    * @Description: 电力 每月3号 3:30执行
    * @Param: []
    * @return: java.util.List<com.nantian.cloud.dbcapp.vo.AreaAndIndustryVo>
    * @Author: zfw
    * @Date: 2021/3/4
    * @Date: 15:12
    */

    //List<CoalVo> getCollectData
    //@Override
    ////@Scheduled(cron = "0 30 3 3 * ?")
    //@Scheduled(cron = "0 00 5 * * ?")
    public List<AreaAndIndustryVo> getAllElectricityYear() throws ParseException {
        String time = getLastMonthAgo();
        String[] area = {"云南","昆明", "曲靖", "玉溪", "保山", "昭通", "丽江", "普洱", "临沧", "楚雄", "红河", "文山", "版纳", "大理", "德宏", "怒江", "迪庆"};
        String industry = "全部";
        List<BigScreenVo> listArea=bigScreenMapper.getAllArea();

        //州市
        for (int i = 0; i < area.length; i++) {
            List<CoalVo> list =electricityService.getCollectData(area[i],industry,time);
            for (int j = 0; j < list.size(); j++) {
                BigScreenModel big = new BigScreenModel();
                big.setType(7);
                big.setYear(time.substring(0, 4));
                big.setCity("云南");
                big.setCounty(area[i]);
                if(i>8){
                    big.setDepartmentName(area[i]+"州管理员");
                }else{
                    big.setDepartmentName(area[i]+"市管理员");
                }
                big.setValue(Float.valueOf(list.get(j).getValue()));
                big.setName(list.get(j).getMonth());
                bigScreenMapper.insert(big);
                System.out.println(big);
            }
        }


            for (int i = 0; i < listArea.size(); i++) {
                List<CoalVo> list =electricityService.getCollectData(listArea.get(i).getCode(),industry,time);
                for (int j = 0; j < list.size(); j++) {
                    BigScreenModel big = new BigScreenModel();
                    big.setType(7);
                    big.setYear(time.substring(0, 4));
                    big.setCity(listArea.get(i).getPname());
                    big.setCounty(listArea.get(i).getName());
                    if(Integer.valueOf(listArea.get(i).getPcode().substring(0,4))>5309){
                        big.setDepartmentName(listArea.get(i).getPname()+"州管理员");
                    }else{
                        big.setDepartmentName(listArea.get(i).getPname()+"市管理员");
                    }
                    big.setValue(Float.valueOf(list.get(j).getValue()));
                    big.setName(list.get(j).getMonth());
                    bigScreenMapper.insert(big);
                    System.out.println(big);
                }



        }


            //计量院
        for (int i = 0; i < area.length; i++) {
            List<CoalVo> list =electricityService.getCollectData(area[i],industry,time);
            for (int j = 0; j < list.size(); j++) {
                BigScreenModel big = new BigScreenModel();
                big.setType(7);
                big.setYear(time.substring(0, 4));
                big.setCity("云南");
                big.setCounty(area[i]);
                big.setDepartmentName("云南省计量测试技术研究院");
                big.setValue(Float.valueOf(list.get(j).getValue()));
                big.setName(list.get(j).getMonth());
                bigScreenMapper.insert(big);
                System.out.println(big);
            }
        }


            for (int i = 0; i < listArea.size(); i++) {
                List<CoalVo> list =electricityService.getCollectData(listArea.get(i).getCode(),industry,time);
                for (int j = 0; j < list.size(); j++) {
                    BigScreenModel big = new BigScreenModel();
                    big.setType(7);
                    big.setYear(time.substring(0, 4));
                    big.setCity(listArea.get(i).getPname());
                    big.setCounty(listArea.get(i).getName());
                    big.setDepartmentName("云南省计量测试技术研究院");
                    big.setValue(Float.valueOf(list.get(j).getValue()));
                    big.setName(list.get(j).getMonth());
                    bigScreenMapper.insert(big);
                    System.out.println(big);
                }



        }
        return null;
    }

    //能源分类
    //@Override
    ////@Scheduled(cron = "0 00 6 4 * ?")
    //@Scheduled(cron = "0 30 5 * * ?")
    public Integer getAllXfjgYear() throws ParseException {
        String time = getLastMonthAgo();
        String[] area = {"云南","昆明", "曲靖", "玉溪", "保山", "昭通", "丽江", "普洱", "临沧", "楚雄", "红河", "文山", "版纳", "大理", "德宏", "怒江", "迪庆"};
        String industry = "全部";
        List<BigScreenVo> listArea = bigScreenMapper.getAllArea();


        for (int j = 0; j < area.length; j++) {
            JSONArray js = new JSONArray();
            js = energyService.getConsumption(area[j], industry, time);
            if (js.size() > 0 && js != null) {
                for (int k = 0; k < js.size(); k++) {

                    BigScreenModel big = new BigScreenModel();
                    big.setType(4);
                    big.setYear(time.substring(0, 4));
                    big.setCity("云南");
                    big.setCounty(area[j]);
                    if (j > 8) {
                        big.setDepartmentName(area[j] + "州管理员");
                    } else {
                        big.setDepartmentName(area[j] + "市管理员");
                    }
                    big.setName(js.getJSONObject(k).get("name").toString());
                    big.setValue(Double.valueOf(js.getJSONObject(k).get("value").toString()));
                    bigScreenMapper.insert(big);
                    System.out.println(big);
                }
            }

        }
            for (int j = 0; j < listArea.size(); j++) {
                JSONArray js = new JSONArray();
                js = energyService.getConsumption(listArea.get(j).getCode(), industry, time);
                if (js.size() > 0 && js != null) {
                    for (int k = 0; k < js.size(); k++) {
                        BigScreenModel big = new BigScreenModel();
                        big.setType(4);
                        big.setYear(time.substring(0, 4));
                        big.setCity(listArea.get(j).getPname());
                        big.setCounty(listArea.get(j).getName());
                        big.setName(js.getJSONObject(k).get("name").toString());
                        if (Integer.valueOf(listArea.get(j).getCode().substring(0, 4)) > 5309) {
                            big.setDepartmentName(listArea.get(j).getPname() + "州管理员");
                        } else {
                            big.setDepartmentName(listArea.get(j).getPname() + "市管理员");
                        }
                        big.setValue(Double.valueOf(js.getJSONObject(k).get("value").toString()));

                        bigScreenMapper.insert(big);
                        System.out.println(big);
                    }
                }


            }

            //州市
            for (int i = 0; i < area.length; i++) {
                JSONArray js = new JSONArray();
                js = energyService.getConsumption(area[i], industry, time);
                if (js.size() > 0 && js != null) {
                    for (int k = 0; k < js.size(); k++) {
                        BigScreenModel big = new BigScreenModel();
                        big.setType(4);
                        big.setYear(time.substring(0, 4));
                        big.setCity("云南");
                        big.setCounty(area[i]);
                        big.setName(js.getJSONObject(k).get("name").toString());
                        big.setDepartmentName("云南省计量测试技术研究院");
                        big.setValue(Double.valueOf(js.getJSONObject(k).get("value").toString()));
                        bigScreenMapper.insert(big);
                        System.out.println(big);
                    }
                }
            }

                for (int j = 0; j < listArea.size(); j++) {
                    JSONArray js = new JSONArray();
                    js = energyService.getConsumption(listArea.get(j).getCode(), industry, time);
                    if (js.size() > 0 && js != null) {
                        for (int k = 0; k < js.size(); k++) {
                            BigScreenModel big = new BigScreenModel();
                            big.setType(4);
                            big.setYear(time.substring(0, 4));
                            big.setCity(listArea.get(j).getPname());
                            big.setCounty(listArea.get(j).getName());
                            big.setName(js.getJSONObject(k).get("name").toString());
                            big.setDepartmentName("云南省计量测试技术研究院");
                            big.setValue(Double.valueOf(js.getJSONObject(k).get("value").toString()));
                            bigScreenMapper.insert(big);
                            System.out.println(big);
                        }
                    }


                }

            return 0;

    }


 ///   ======================================================近六个月======================================================================================




    /**     综合能耗
     * @Description: 重点用能单位(336) 每月3号 4:00执行
     * @Param: []
     * @return: java.util.List<com.nantian.cloud.dbcapp.vo.AreaAndIndustryVo>
     * @Author: zfw
     * @Date: 2021/3/1
     * @Date: 23:41
     */
    //@Override
    //@Scheduled(cron = "0 00 6 * * ?")
    public List<AreaAndIndustryVo> getAllTce6() {
        String time =this.getSixMonthAgo();
        String[] area = {"云南", "昆明", "曲靖", "玉溪", "保山", "昭通", "丽江", "普洱", "临沧", "楚雄", "红河", "文山", "版纳", "大理", "德宏", "怒江", "迪庆"};
        String industry = "全部";
        List<BigScreenVo> listArea=bigScreenMapper.getAllArea();
        List<AreaAndIndustryVo> list = new ArrayList<>();

        //州市管理员
        for (int i = 0; i < area.length; i++) {
            Float num=  energyService.getTotal(area[i], industry, time);
            BigScreenModel big = new BigScreenModel();
            big.setType(0);
            big.setYear("近六个月");
            big.setCity("云南");
            big.setCounty(area[i]);
            if(i>8){
                big.setDepartmentName(listArea.get(i).getPname()+"州管理员");
            }else{
                big.setDepartmentName(listArea.get(i).getPname()+"市管理员");
            }
            if(num!=null){
                big.setValue(num);
            }else{
                big.setValue(0);
            }
            bigScreenMapper.insert(big);
            //System.out.println(big);
        }

        for (int i = 0; i < listArea.size(); i++) {
            Float num=  energyService.getTotal(listArea.get(i).getCode(), industry, time);
            BigScreenModel big = new BigScreenModel();
            big.setType(0);
            big.setYear("近六个月");
            big.setCity(listArea.get(i).getPname());
            if(Integer.valueOf(listArea.get(i).getPcode().substring(0,4))>5309){
            big.setDepartmentName(listArea.get(i).getPname()+"州管理员");
            }else{
                big.setDepartmentName(listArea.get(i).getPname()+"市管理员");
            }

            big.setCounty(listArea.get(i).getName());
            if(num!=null){
                big.setValue(num);
            }else{
                big.setValue(0);
            }
            bigScreenMapper.insert(big);
           // System.out.println(big);
        }
        //计量院
        for (int i = 0; i < area.length; i++) {
            Float num=  energyService.getTotal(area[i], industry, time);
            BigScreenModel big = new BigScreenModel();
            big.setType(0);
            big.setYear("近六个月");
            big.setCity("云南");
            big.setCounty(area[i]);
            big.setDepartmentName("云南省计量测试技术研究院");
            if(num!=null){
                big.setValue(num);
            }else{
                big.setValue(0);
            }
            bigScreenMapper.insert(big);
            //System.out.println(big);
        }

        for (int i = 0; i < listArea.size(); i++) {
            Float num=  energyService.getTotal(listArea.get(i).getCode(), industry, time);
            BigScreenModel big = new BigScreenModel();
            big.setType(0);
            big.setYear("近六个月");
            big.setCity(listArea.get(i).getPname());
            big.setDepartmentName("云南省计量测试技术研究院");
            big.setCounty(listArea.get(i).getName());
            if(num!=null){
                big.setValue(num);
            }else{
                big.setValue(0);
            }
            bigScreenMapper.insert(big);
            // System.out.println(big);
        }



        //System.out.println();
        return list;
    }



    /***
     * @Description: 查询所有地区, get大屏地区能耗提供接口 每月3号 4:20执行
     * @Param: []
     * @return: java.util.List<com.nantian.cloud.dbcapp.vo.AreaAndIndustryVo>
     * @Author: zfw
     * @Date: 2021/2/28
     * @Date: 10:33
     */
    //@Override
    //@Scheduled(cron = "0 30 6 * * ?")
    public List<AreaAndIndustryVo> getAllAreaByYear6() {
        //近6个月
        String  time=this.getSixMonthAgo();
        String[] area = {"云南","昆明", "曲靖", "玉溪", "保山", "昭通", "丽江", "普洱", "临沧", "楚雄", "红河", "文山", "版纳", "大理", "德宏", "怒江", "迪庆"};
        String industry = "全部";
        List<BigScreenVo> listArea=bigScreenMapper.getAllArea();
        List<AreaAndIndustryVo> list = new ArrayList<>();
        //州市
            for (int i = 0; i < listArea.size(); i++) {
                list = energyService.getEnergyByAreaList(listArea.get(i).getCode(), industry, time);
                for (int j = 0; j < list.size(); j++) {
                    BigScreenModel big = new BigScreenModel();
                    big.setType(1);
                    big.setYear("近六个月");
                    big.setCity(listArea.get(i).getName());
                    big.setCounty(listArea.get(i).getName());
                    if(Integer.valueOf(listArea.get(i).getPcode().substring(0,4))>5309){
                        big.setDepartmentName(listArea.get(i).getPname()+"州管理员");
                    }else{
                        big.setDepartmentName(listArea.get(i).getPname()+"市管理员");
                    }
                    if(list.get(j).getEnergyValue()!=null){
                        big.setValue(Float.valueOf(list.get(j).getEnergyValue())/10000);
                    }else{
                        big.setValue(0);
                    }
                    bigScreenMapper.insert(big);
                    //System.out.println(big);
                }


        }
        for (int i = 0; i < area.length; i++) {
            list = energyService.getEnergyByAreaList(area[i], industry, time);
            for (int j = 0; j < list.size(); j++) {
                BigScreenModel big = new BigScreenModel();
                big.setType(1);
                big.setYear("近六个月");
                big.setCity(area[i]);
                big.setCounty(list.get(j).getName());
                if(i>8){
                    big.setDepartmentName(area[i]+"州管理员");
                }else{
                    big.setDepartmentName(area[i]+"市管理员");
                }
                if(list.get(j).getEnergyValue()!=null){
                    big.setValue(Float.valueOf(list.get(j).getEnergyValue())/10000);
                }else{
                    big.setValue(0);
                }
                bigScreenMapper.insert(big);
                //System.out.println(big);
            }

        }

        //计量院
        //州市
        for (int i = 0; i < listArea.size(); i++) {
            list = energyService.getEnergyByAreaList(listArea.get(i).getCode(), industry, time);
            for (int j = 0; j < list.size(); j++) {
                BigScreenModel big = new BigScreenModel();
                big.setType(1);
                big.setYear("近六个月");
                big.setCity(listArea.get(i).getName());
                big.setCounty(listArea.get(i).getName());
                big.setDepartmentName("云南省计量测试技术研究院");
                if(list.get(j).getEnergyValue()!=null){
                    big.setValue(Float.valueOf(list.get(j).getEnergyValue())/10000);
                }else{
                    big.setValue(0);
                }
                bigScreenMapper.insert(big);
                //System.out.println(big);
            }


        }
        for (int i = 0; i < area.length; i++) {
            list = energyService.getEnergyByAreaList(area[i], industry, time);
            for (int j = 0; j < list.size(); j++) {
                BigScreenModel big = new BigScreenModel();
                big.setType(1);
                big.setYear("近六个月");
                big.setCity(area[i]);
                big.setCounty(list.get(j).getName());
                big.setDepartmentName("云南省计量测试技术研究院");
                if(list.get(j).getEnergyValue()!=null){
                    big.setValue(Float.valueOf(list.get(j).getEnergyValue())/10000);
                }else{
                    big.setValue(0);
                }
                bigScreenMapper.insert(big);
                //System.out.println(big);
            }

        }
        //System.out.println();
        return list;
    }

    /***
     * @Description: 查询所有行业, get大屏地区能耗提供接口 每月3号 4:40执行
     * @Param: []
     * @return: java.util.List<com.nantian.cloud.dbcapp.vo.AreaAndIndustryVo>
     * @Author: zfw
     * @Date: 2021/2/28
     * @Date: 10:33
     */
    //@Override
    //@Scheduled(cron = "0 00 7 * * ?")
    public List<AreaAndIndustryVo> getAllHyByYear6() {
        //近6个月
        String  time=this.getSixMonthAgo();
        String[] area = {"云南","昆明", "曲靖", "玉溪", "保山", "昭通", "丽江", "普洱", "临沧", "楚雄", "红河", "文山", "版纳", "大理", "德宏", "怒江", "迪庆"};
        String industry = "全部";
        List<BigScreenVo> listArea=bigScreenMapper.getAllArea();
        List<AreaAndIndustryVo> list = new ArrayList<>();
        //州市
            for (int i = 0; i < listArea.size(); i++) {
                list = energyService.getEnergyByIndustryList(listArea.get(i).getCode(), industry, time);
                for (int j = 0; j < list.size(); j++) {
                    BigScreenModel big = new BigScreenModel();
                    big.setType(3);
                    big.setYear("近六个月");
                    big.setCity(listArea.get(i).getPname());
                    big.setCounty(listArea.get(i).getName());
                    if(Integer.valueOf(listArea.get(i).getPcode().substring(0,4))>5309){
                        big.setDepartmentName(listArea.get(i).getPname()+"州管理员");
                    }else{
                        big.setDepartmentName(listArea.get(i).getPname()+"市管理员");
                    }
                    if(list.get(j).getEnergyValue()!=null){
                        big.setValue(Float.valueOf(list.get(j).getEnergyValue())/10000);
                    }else{
                        big.setValue(0);
                    }
                    big.setName(list.get(j).getName());
                    bigScreenMapper.insert(big);
                    System.out.println(big);
                }


            }
        for (int i = 0; i < area.length; i++) {
            list = energyService.getEnergyByIndustryList(area[i], industry, time);
            for (int j = 0; j < list.size(); j++) {
                BigScreenModel big = new BigScreenModel();
                big.setType(3);
                big.setYear("近六个月");
                big.setCity("云南");
                big.setCounty(area[i]);
                big.setName(list.get(j).getName());
                if(i>8){
                    big.setDepartmentName(area[i]+"州管理员");
                }else{
                    big.setDepartmentName(area[i]+"市管理员");
                }
                if(list.get(j).getEnergyValue()!=null){
                    big.setValue(Float.valueOf(list.get(j).getEnergyValue())/10000);
                }else{
                    big.setValue(0);
                }
               bigScreenMapper.insert(big);
                System.out.println(big);
            }

        }

        //计量院
        for (int i = 0; i < listArea.size(); i++) {
            list = energyService.getEnergyByIndustryList(listArea.get(i).getCode(), industry, time);
            for (int j = 0; j < list.size(); j++) {
                BigScreenModel big = new BigScreenModel();
                big.setType(3);
                big.setYear("近六个月");
                big.setCity(listArea.get(i).getPname());
                big.setCounty(listArea.get(i).getName());
                big.setDepartmentName("云南省计量测试技术研究院");
                if(list.get(j).getEnergyValue()!=null){
                    big.setValue(Float.valueOf(list.get(j).getEnergyValue())/10000);
                }else{
                    big.setValue(0);
                }
                big.setName(list.get(j).getName());
                bigScreenMapper.insert(big);
                System.out.println(big);
            }


        }
        for (int i = 0; i < area.length; i++) {
            list = energyService.getEnergyByIndustryList(area[i], industry, time);
            for (int j = 0; j < list.size(); j++) {
                BigScreenModel big = new BigScreenModel();
                big.setType(3);
                big.setYear("近六个月");
                big.setCity("云南");
                big.setCounty(area[i]);
                big.setName(list.get(j).getName());
                big.setDepartmentName("云南省计量测试技术研究院");
                if(list.get(j).getEnergyValue()!=null){
                    big.setValue(Float.valueOf(list.get(j).getEnergyValue())/10000);
                }else{
                    big.setValue(0);
                }
                bigScreenMapper.insert(big);
                System.out.println(big);
            }

        }
        //System.out.println();
        return list;
    }

    /**
    * @Description: 煤  每月3号 5:00执行
    * @Param: []
    * @return: java.util.List<com.nantian.cloud.dbcapp.vo.AreaAndIndustryVo>
    * @Author: zfw
    * @Date: 2021/3/4
    * @Date: 15:13
    */
    //@Override
    //@Scheduled(cron = "0 30 7 * * ?")
    public List<AreaAndIndustryVo> getAllMeiYear6() {
        String time = this.getSixMonthAgo();
        String[] area = {"云南","昆明", "曲靖", "玉溪", "保山", "昭通", "丽江", "普洱", "临沧", "楚雄", "红河", "文山", "版纳", "大理", "德宏", "怒江", "迪庆"};
        String industry = "全部";
        List<BigScreenVo> listArea=bigScreenMapper.getAllArea();


            for (int i = 0; i < listArea.size(); i++) {
                String startTime = null;
                String endTime = null;
                if (time.contains("&")) {
                    startTime = time.split("&")[0];
                    endTime = time.split("&")[1];
                    startTime = startTime.substring(0, 7);
                    endTime = endTime.substring(0, 7);

                }
                Map<String, Object> map = new HashMap<>();
                List<String> areaList = new ArrayList<>();
                List<String> dataValueList = new ArrayList<>();
                Float value = 0.0f;
                Integer timeStr = Integer.valueOf(startTime.substring(0, 4));
                Integer timeStr1 = Integer.valueOf(endTime.substring(0, 4));
                List<String> companyList = energyService.companyList(listArea.get(i).getCode(), industry, time);
                List<CoalVo> coalVosResult = new ArrayList<>();
                if (timeStr >= 2020) {
                    HashMap<String, String> areaAndIndustryCode = energyService.getAreaAndIndustryCode(listArea.get(i).getCode(), industry);
                    String areaName = areaAndIndustryCode.get("地区");
                    String industryName = areaAndIndustryCode.get("行业");
                    List<String> companyList2020 = energyService.getCompanyList2020(areaName, industryName, time, null);
                    List<CoalVo> coalVos = energyMapper.foundCoalByMonth2020(companyList2020, startTime, endTime);
                    coalVosResult = energyService.getMonthAndValue(startTime, endTime, coalVos);

                } else if (timeStr1 < 2020) {
                    //2019年数据
                    if(companyList!=null && companyList.size()>0){
                        List<Integer> list = energyService.getentIdByEnterpriseCode(companyList);
                        coalVosResult = energyMapper.foundCoalByMonth(list, startTime, endTime);
                    }


                }

                for (int j = 0; j < coalVosResult.size(); j++) {
                    BigScreenModel big = new BigScreenModel();
                    big.setType(5);
                    big.setYear("近六个月");
                    big.setCity(listArea.get(i).getPname());
                    big.setCounty(listArea.get(i).getName());
                    if(Integer.valueOf(listArea.get(i).getPcode().substring(0,4))>5309){
                        big.setDepartmentName(listArea.get(i).getPname()+"州管理员");
                    }else{
                        big.setDepartmentName(listArea.get(i).getPname()+"市管理员");
                    }
                    if(coalVosResult.get(j).getValue()!=null){
                        big.setValue(Float.valueOf(coalVosResult.get(j).getValue()));
                    }else{
                        big.setValue(0);
                    }
                    big.setName(coalVosResult.get(j).getMonth());
                    bigScreenMapper.insert(big);
                    System.out.println(big);
                }

                for (int j = 0; j < coalVosResult.size(); j++) {
                    BigScreenModel big = new BigScreenModel();
                    big.setType(5);
                    big.setYear("近六个月");
                    big.setCity(listArea.get(i).getPname());
                    big.setCounty(listArea.get(i).getName());
                    big.setDepartmentName("云南省计量测试技术研究院");
                    if(coalVosResult.get(j).getValue()!=null){
                        big.setValue(Float.valueOf(coalVosResult.get(j).getValue()));
                    }else{
                        big.setValue(0);
                    }
                    big.setName(coalVosResult.get(j).getMonth());
                    bigScreenMapper.insert(big);
                    System.out.println(big);
                }


            }
            //州市
            for (int i = 0; i <area.length; i++) {
                String startTime = null;
                String endTime = null;
                if (time.contains("&")) {
                    startTime = time.split("&")[0];
                    endTime = time.split("&")[1];
                    startTime = startTime.substring(0, 7);
                    endTime = endTime.substring(0, 7);

                }
                Map<String, Object> map = new HashMap<>();
                List<String> areaList = new ArrayList<>();
                List<String> dataValueList = new ArrayList<>();
                Float value = 0.0f;
                Integer timeStr = Integer.valueOf(startTime.substring(0, 4));
                Integer timeStr1 = Integer.valueOf(endTime.substring(0, 4));
                List<String> companyList = energyService.companyList(area[i], industry, time);
                List<CoalVo> coalVosResult = new ArrayList<>();
                if (timeStr >= 2020) {
                    HashMap<String, String> areaAndIndustryCode = energyService.getAreaAndIndustryCode(area[i], industry);
                    String areaName = areaAndIndustryCode.get("地区");
                    String industryName = areaAndIndustryCode.get("行业");
                    List<String> companyList2020 = energyService.getCompanyList2020(areaName, industryName, time, null);
                    List<CoalVo> coalVos = energyMapper.foundCoalByMonth2020(companyList2020, startTime, endTime);
                    coalVosResult = energyService.getMonthAndValue(startTime, endTime, coalVos);

                } else if (timeStr1 < 2020) {
                    //2019年数据
                    if(companyList!=null && companyList.size()>0){
                        List<Integer> list = energyService.getentIdByEnterpriseCode(companyList);
                        coalVosResult = energyMapper.foundCoalByMonth(list, startTime, endTime);
                    }


                }
                for (int j = 0; j < coalVosResult.size(); j++) {
                    BigScreenModel big = new BigScreenModel();
                    big.setType(5);
                    big.setYear("近六个月");
                    big.setCity("云南");
                    big.setCounty(area[i]);
                    if(i>8){
                        big.setDepartmentName(area[i]+"州管理员");
                    }else{
                        big.setDepartmentName(area[i]+"市管理员");
                    }
                    if(coalVosResult.get(j).getValue()!=null){
                        big.setValue(Float.valueOf(coalVosResult.get(j).getValue()));
                    }else{
                        big.setValue(0);
                    }
                    big.setName(coalVosResult.get(j).getMonth());
                    bigScreenMapper.insert(big);
                    System.out.println(big);
                }

                for (int j = 0; j < coalVosResult.size(); j++) {
                    BigScreenModel big = new BigScreenModel();
                    big.setType(5);
                    big.setYear("近六个月");
                    big.setCity("云南");
                    big.setCounty(area[i]);
                    big.setDepartmentName("云南省计量测试技术研究院");
                    if(coalVosResult.get(j).getValue()!=null){
                        big.setValue(Float.valueOf(coalVosResult.get(j).getValue()));
                    }else{
                        big.setValue(0);
                    }
                    big.setName(coalVosResult.get(j).getMonth());
                    bigScreenMapper.insert(big);
                    System.out.println(big);
                }


            }

        return null;
    }

    /**
    * @Description: 水 每月3号 5:20执行
    * @Param: []
    * @return: java.util.List<com.nantian.cloud.dbcapp.vo.AreaAndIndustryVo>
    * @Author: zfw
    * @Date: 2021/3/4
    * @Date: 15:13
    */
    //@Override
    //@Scheduled(cron = "0 00 8 * * ?")
    public List<AreaAndIndustryVo> getAllWaterYear6() {
        String time = this.getSixMonthAgo();
        String[] area = {"云南","昆明", "曲靖", "玉溪", "保山", "昭通", "丽江", "普洱", "临沧", "楚雄", "红河", "文山", "版纳", "大理", "德宏", "怒江", "迪庆"};
        String industry = "全部";
        List<BigScreenVo> listArea=bigScreenMapper.getAllArea();


            for (int i = 0; i < listArea.size(); i++) {
                String startTime = null;
                String endTime = null;
                if (time.contains("&")) {
                    startTime = time.split("&")[0];
                    endTime = time.split("&")[1];
                    startTime = startTime.substring(0, 7);
                    endTime = endTime.substring(0, 7);

                }
                Map<String, Object> map = new HashMap<>();
                List<String> areaList = new ArrayList<>();
                List<String> dataValueList = new ArrayList<>();
                Float value = 0.0f;
                Integer timeStr = Integer.valueOf(startTime.substring(0, 4));
                Integer timeStr1 = Integer.valueOf(endTime.substring(0, 4));
                List<String> companyList = energyService.companyList(listArea.get(i).getCode(), industry, time);
                List<CoalVo> coalVosResult = new ArrayList<>();
                if (timeStr >= 2020) {
                    HashMap<String, String> areaAndIndustryCode = energyService.getAreaAndIndustryCode(listArea.get(i).getCode(), industry);
                    String areaName = areaAndIndustryCode.get("地区");
                    String industryName = areaAndIndustryCode.get("行业");
                    List<String> companyList2020 = energyService.getCompanyList2020(areaName, industryName, time, null);
                    List<CoalVo> coalVos = energyMapper.foundWaterByMonth2020(companyList2020, startTime, endTime);
                    coalVosResult = energyService.getMonthAndValue(startTime, endTime, coalVos);

                } else if (timeStr1 < 2020) {
                    //2019年数据
                    if(companyList!=null && companyList.size()>0){
                        List<Integer> list = energyService.getentIdByEnterpriseCode(companyList);
                        coalVosResult = energyMapper.foundWaterByMonth(list, startTime, endTime);
                    }

                    /*for(int i=0;i<coalVoList.size();i++){
                        areaList.add(coalVoList.get(i).getMonth());
                        dataValueList.add(coalVoList.get(i).getValue());
                    }*/
                }
                for (int j = 0; j < coalVosResult.size(); j++) {
                    BigScreenModel big = new BigScreenModel();
                    big.setType(6);
                    big.setYear("近六个月");
                    big.setCity(listArea.get(i).getPname());
                    big.setCounty(listArea.get(i).getName());
                    if(Integer.valueOf(listArea.get(i).getPcode().substring(0,4))>5309){
                        big.setDepartmentName(listArea.get(i).getPname()+"州管理员");
                    }else{
                        big.setDepartmentName(listArea.get(i).getPname()+"市管理员");
                    }
                    if(coalVosResult.get(j).getValue()!=null){
                        big.setValue(Float.valueOf(coalVosResult.get(j).getValue()));
                    }else{
                        big.setValue(0);
                    }
                    big.setName(coalVosResult.get(j).getMonth());
                    bigScreenMapper.insert(big);
                    System.out.println(big);
                }

                for (int j = 0; j < coalVosResult.size(); j++) {
                    BigScreenModel big = new BigScreenModel();
                    big.setType(6);
                    big.setYear("近六个月");
                    big.setCity(listArea.get(i).getPname());
                    big.setCounty(listArea.get(i).getName());
                    big.setDepartmentName("云南省计量测试技术研究院");
                    if(coalVosResult.get(j).getValue()!=null){
                        big.setValue(Float.valueOf(coalVosResult.get(j).getValue()));
                    }else{
                        big.setValue(0);
                    }
                    big.setName(coalVosResult.get(j).getMonth());
                    bigScreenMapper.insert(big);
                    System.out.println(big);
                }


            }


        //州市
        for (int i = 0; i <area.length; i++) {
            String startTime = null;
            String endTime = null;
            if (time.contains("&")) {
                startTime = time.split("&")[0];
                endTime = time.split("&")[1];
                startTime = startTime.substring(0, 7);
                endTime = endTime.substring(0, 7);

            }
            Map<String, Object> map = new HashMap<>();
            List<String> areaList = new ArrayList<>();
            List<String> dataValueList = new ArrayList<>();
            Float value = 0.0f;
            Integer timeStr = Integer.valueOf(startTime.substring(0, 4));
            Integer timeStr1 = Integer.valueOf(endTime.substring(0, 4));
            List<String> companyList = energyService.companyList(area[i], industry, time);
            List<CoalVo> coalVosResult = new ArrayList<>();
            if (timeStr >= 2020) {
                HashMap<String, String> areaAndIndustryCode = energyService.getAreaAndIndustryCode(area[i], industry);
                String areaName = areaAndIndustryCode.get("地区");
                String industryName = areaAndIndustryCode.get("行业");
                List<String> companyList2020 = energyService.getCompanyList2020(areaName, industryName, time, null);
                List<CoalVo> coalVos = energyMapper.foundWaterByMonth2020(companyList2020, startTime, endTime);
                coalVosResult = energyService.getMonthAndValue(startTime, endTime, coalVos);

            } else if (timeStr1 < 2020) {
                //2019年数据
                if(companyList!=null && companyList.size()>0){
                    List<Integer> list = energyService.getentIdByEnterpriseCode(companyList);
                    coalVosResult = energyMapper.foundWaterByMonth(list, startTime, endTime);
                }


            }
            for (int j = 0; j < coalVosResult.size(); j++) {
                BigScreenModel big = new BigScreenModel();
                big.setType(6);
                big.setYear("近六个月");
                big.setCity("云南");
                big.setCounty(area[i]);
                if(i>8){
                    big.setDepartmentName(area[i]+"州管理员");
                }else{
                    big.setDepartmentName(area[i]+"市管理员");
                }
                if(coalVosResult.get(j).getValue()!=null){
                    big.setValue(Float.valueOf(coalVosResult.get(j).getValue()));
                }else{
                    big.setValue(0);
                }
                big.setName(coalVosResult.get(j).getMonth());
                bigScreenMapper.insert(big);
                System.out.println(big);
            }

            for (int j = 0; j < coalVosResult.size(); j++) {
                BigScreenModel big = new BigScreenModel();
                big.setType(6);
                big.setYear("近六个月");
                big.setCity("云南");
                big.setCounty(area[i]);
                big.setDepartmentName("云南省计量测试技术研究院");
                if(coalVosResult.get(j).getValue()!=null){
                    big.setValue(Float.valueOf(coalVosResult.get(j).getValue()));
                }else{
                    big.setValue(0);
                }
                big.setName(coalVosResult.get(j).getMonth());
                bigScreenMapper.insert(big);
                System.out.println(big);
            }


        }

        return null;
    }

    /**
    * @Description: 电  每月3号 5:40执行
    * @Param: []
    * @return: java.util.List<com.nantian.cloud.dbcapp.vo.AreaAndIndustryVo>
    * @Author: zfw
    * @Date: 2021/3/4
    * @Date: 15:13
    */

    //List<CoalVo> getCollectData
    //@Override
    //@Scheduled(cron = "0 30 8 * * ?")
    public List<AreaAndIndustryVo> getAllElectricityYear6() throws ParseException {
        String time = this.getSixMonthAgo();
        String[] area = {"云南","昆明", "曲靖", "玉溪", "保山", "昭通", "丽江", "普洱", "临沧", "楚雄", "红河", "文山", "版纳", "大理", "德宏", "怒江", "迪庆"};
        String industry = "全部";
        List<BigScreenVo> listArea=bigScreenMapper.getAllArea();

             //州市
            for (int i = 0; i < area.length; i++) {
                List<CoalVo> list =electricityService.getCollectData(area[i],industry,time);
                for (int j = 0; j < list.size(); j++) {
                    BigScreenModel big = new BigScreenModel();
                    big.setType(7);
                    big.setYear("近六个月");
                    big.setCity("云南");
                    big.setCounty(area[i]);
                    if(i>8){
                        big.setDepartmentName(area[i]+"州管理员");
                    }else{
                        big.setDepartmentName(area[i]+"市管理员");
                    }
                    big.setValue(Float.valueOf(list.get(j).getValue()));
                    big.setName(list.get(j).getMonth());
                    bigScreenMapper.insert(big);
                    System.out.println(big);
                }
            }

            for (int i = 0; i < listArea.size(); i++) {
                List<CoalVo> list =electricityService.getCollectData(listArea.get(i).getCode(),industry,time);
                for (int j = 0; j < list.size(); j++) {
                    BigScreenModel big = new BigScreenModel();
                    big.setType(7);
                    big.setYear("近六个月");
                    big.setCity(listArea.get(i).getPname());
                    big.setCounty(listArea.get(i).getName());
                    if(Integer.valueOf(listArea.get(i).getPcode().substring(0,4))>5309){
                        big.setDepartmentName(listArea.get(i).getPname()+"州管理员");
                    }else{
                        big.setDepartmentName(listArea.get(i).getPname()+"市管理员");
                    }
                    big.setValue(Float.valueOf(list.get(j).getValue()));
                    big.setName(list.get(j).getMonth());
                    bigScreenMapper.insert(big);
                    System.out.println(big);
                }
            }

            //计量院
            for (int i = 0; i < area.length; i++) {
                List<CoalVo> list =electricityService.getCollectData(area[i],industry,time);
                for (int j = 0; j < list.size(); j++) {
                    BigScreenModel big = new BigScreenModel();
                    big.setType(7);
                    big.setYear("近六个月");
                    big.setCity("云南");
                    big.setCounty(area[i]);
                    big.setDepartmentName("云南省计量测试技术研究院");
                    big.setValue(Float.valueOf(list.get(j).getValue()));
                    big.setName(list.get(j).getMonth());
                    bigScreenMapper.insert(big);
                    System.out.println(big);
                }
            }

            for (int i = 0; i < listArea.size(); i++) {
                List<CoalVo> list =electricityService.getCollectData(listArea.get(i).getCode(),industry,time);
                for (int j = 0; j < list.size(); j++) {
                    BigScreenModel big = new BigScreenModel();
                    big.setType(7);
                    big.setYear("近六个月");
                    big.setCity(listArea.get(i).getPname());
                    big.setCounty(listArea.get(i).getName());
                    big.setDepartmentName("云南省计量测试技术研究院");
                    big.setValue(Float.valueOf(list.get(j).getValue()));
                    big.setName(list.get(j).getMonth());
                    bigScreenMapper.insert(big);
                    System.out.println(big);
                }
            }

        return null;
    }

    //能源分类  近六个月

    //@Scheduled(cron = "0 00 9 * * ?")
    public Integer getAllXfjgYear6() throws ParseException {
        String time = this.getSixMonthAgo();
        String[] area = {"云南","昆明", "曲靖", "玉溪", "保山", "昭通", "丽江", "普洱", "临沧", "楚雄", "红河", "文山", "版纳", "大理", "德宏", "怒江", "迪庆"};
        String industry = "全部";
        List<BigScreenVo> listArea = bigScreenMapper.getAllArea();


        for (int j = 0; j < area.length; j++) {
            JSONArray js = new JSONArray();
            js = energyService.getConsumption(area[j], industry, time);
            if (js.size() > 0 && js != null) {
                for (int k = 0; k < js.size(); k++) {

                    BigScreenModel big = new BigScreenModel();
                    big.setType(4);
                    big.setYear("近六个月");
                    big.setCity("云南");
                    big.setCounty(area[j]);
                    if (j > 8) {
                        big.setDepartmentName(area[j] + "州管理员");
                    } else {
                        big.setDepartmentName(area[j] + "市管理员");
                    }
                    big.setName(js.getJSONObject(k).get("name").toString());
                    big.setValue(Double.valueOf(js.getJSONObject(k).get("value").toString()));
                    bigScreenMapper.insert(big);
                    System.out.println(big);
                }
            }

        }
        for (int j = 0; j < listArea.size(); j++) {
            JSONArray js = new JSONArray();
            js = energyService.getConsumption(listArea.get(j).getCode(), industry, time);
            if (js.size() > 0 && js != null) {
                for (int k = 0; k < js.size(); k++) {
                    BigScreenModel big = new BigScreenModel();
                    big.setType(4);
                    big.setYear("近六个月");
                    big.setCity(listArea.get(j).getPname());
                    big.setCounty(listArea.get(j).getName());
                    big.setName(js.getJSONObject(k).get("name").toString());
                    if (Integer.valueOf(listArea.get(j).getCode().substring(0, 4)) > 5309) {
                        big.setDepartmentName(listArea.get(j).getPname() + "州管理员");
                    } else {
                        big.setDepartmentName(listArea.get(j).getPname() + "市管理员");
                    }
                    big.setValue(Double.valueOf(js.getJSONObject(k).get("value").toString()));

                    bigScreenMapper.insert(big);
                    System.out.println(big);
                }
            }


        }

        //州市
        for (int i = 0; i < area.length; i++) {
            JSONArray js = new JSONArray();
            js = energyService.getConsumption(area[i], industry, time);
            if (js.size() > 0 && js != null) {
                for (int k = 0; k < js.size(); k++) {
                    BigScreenModel big = new BigScreenModel();
                    big.setType(4);
                    big.setYear("近六个月");
                    big.setCity("云南");
                    big.setCounty(area[i]);
                    big.setName(js.getJSONObject(k).get("name").toString());
                    big.setDepartmentName("云南省计量测试技术研究院");
                    big.setValue(Double.valueOf(js.getJSONObject(k).get("value").toString()));
                    bigScreenMapper.insert(big);
                    System.out.println(big);
                }
            }
        }

        for (int j = 0; j < listArea.size(); j++) {
            JSONArray js = new JSONArray();
            js = energyService.getConsumption(listArea.get(j).getCode(), industry, time);
            if (js.size() > 0 && js != null) {
                for (int k = 0; k < js.size(); k++) {
                    BigScreenModel big = new BigScreenModel();
                    big.setType(4);
                    big.setYear("近六个月");
                    big.setCity(listArea.get(j).getPname());
                    big.setCounty(listArea.get(j).getName());
                    big.setName(js.getJSONObject(k).get("name").toString());
                    big.setDepartmentName("云南省计量测试技术研究院");
                    big.setValue(Double.valueOf(js.getJSONObject(k).get("value").toString()));
                    bigScreenMapper.insert(big);
                    System.out.println(big);
                }
            }


        }

        return 0;

    }


    /**
    * @Description: 得到当前时间的前6个月区间值 "2020-09-01&2021-02-28"
    * @Param: []
    * @return: java.lang.String
    * @Author: zfw
    * @Date: 2021/3/4
    * @Date: 14:15
    */
    public  String getSixMonthAgo(){
        //得到当前的年月
        GregorianCalendar now = new GregorianCalendar();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
        String n = sdf.format(now.getTime());
        now.add(GregorianCalendar.MONTH,-6);   //可以是天数或月数  数字自定 -6前6个月

        String l=sdf.format(now.getTime());
        GregorianCalendar now1 = new GregorianCalendar();
        now1.add(GregorianCalendar.MONTH,-1);   //可以是天数或月数  数字自定 -6前6个月
        String l1=sdf.format(now1.getTime());

        return l+"-01&"+l1+"-28";
    }

    /***
    * @Description: 得到前一个时间 现在时间为2021-03-01   得到时间为2021-02-01&2021-02-28
    * @Param: []
    * @return: java.lang.String
    * @Author: zfw
    * @Date: 2021/3/4
    * @Date: 14:17
    */
    public static String getLastMonthAgo(){

        //得到当前的年月
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

        //获取当前年
        Calendar calendar1 = Calendar.getInstance();
        String tmpYear = String.valueOf(calendar1.get(Calendar.YEAR));
        //获取前一个月最后一天
        Calendar calendar2 = Calendar.getInstance();
        calendar2.set(Calendar.DAY_OF_MONTH, 0);
        String lastDay = sdf.format(calendar2.getTime());


        return tmpYear+"-01-01&"+lastDay;
    }


    //重点用能单位 300 多家
    public Integer  getTotal(String area ,String industry,String time) {
        if ("".equals(time) || time == null) {
            time = "2020-01-01&2020-12-31";
        }
        //截取时间
        String startTime = time.split("&")[0];
        String endTime = time.split("&")[1];
        startTime.substring(0, 7);
        endTime.substring(0, 7);
        HashMap<String, String> areaAndIndustryCode = energyService.getAreaAndIndustryCode(area, industry);
        area = (area.trim().equals("53") || area.trim().equals("云南")) ? "53" : areaAndIndustryCode.get("地区");
        industry = industry.trim().equals("全部") ? null : areaAndIndustryCode.get("行业");
        return bigScreenMapper.getTotal(area, industry);
    }


}



