package com.sky.ioc.service.energy.impl;

import com.alibaba.fastjson.JSONObject;
import com.sky.ioc.entity.Indeicator;
import com.sky.ioc.entity.Label;
import com.sky.ioc.entity.Cake;
import com.sky.ioc.service.energy.EnergyService;
import com.sky.ioc.tool.DateUtil;
import com.sky.ioc.tool.GeneralMethod;
import com.sky.ioc.tool.ReturnMsg;
import org.springframework.stereotype.Service;

import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ThreadLocalRandom;

/**
 * TODO
 * @Description  能源实现类
 * @Author LunCe
 * @Date 2023/2/23 11:24
 **/
@Service
public class EnergyServiceImpl implements EnergyService {
    @Override
    public ReturnMsg getElectricityCoreIndicators() {
        Indeicator indeicator = new Indeicator();
        List<JSONObject> objects = indeicator.getList();
        ThreadLocalRandom random = ThreadLocalRandom.current();
       /* int todayElec = random.nextInt(8000, 11000);//今日用电
        int personElec = random.nextInt(120,250);//人均
        int top = random.nextInt(0,20);//同比上升
        int totalElec = random.nextInt(100000, 300000);*/
        float compare = 0.6f;
     /*   DecimalFormat decimalFormat = new DecimalFormat("#.0");
        compare = Float.parseFloat(decimalFormat.format(compare));*/

        objects.get(0).put("value",257116.3);
        objects.get(0).put("compare",compare);

        objects.get(1).put("value",13532.4);
        objects.get(1).put("compare",compare);

        objects.get(2).put("value",-5.1);

        objects.get(3).put("value",10.4);
        objects.get(3).put("compare",compare);
        indeicator.setWorthAttention("⼈均⽤电量过⾼");
        indeicator.setList(objects);
        return ReturnMsg.ok(indeicator);
    }

    @Override
    public ReturnMsg getElectricityInfoList() {
        String[] param = {"powerConsumption"};
        //String[] labKey = {"1月","2月","3月","4月","5月","6月","7月","8月","9月","10月","11月","12月"};
        List<String> lists = DateUtil.getBetweenDays("2023/03/01", "2023/03/31");
        String[] labKey = lists.toArray(new String[0]);
        List<Label> labels1 = new ArrayList<>();
        //GeneralMethod.getInstance().dataGeneration(param, labKey);
        ThreadLocalRandom random = ThreadLocalRandom.current();
        for (int i = 0; i < labKey.length; i++) {
            Label label = new Label();
            JSONObject jsonObject = new JSONObject();
            int i1 = random.nextInt(8000, 9000);
            jsonObject.put(param[0],i1);
            label.setJsonObject(jsonObject);
            label.setLabel(labKey[i]);
            labels1.add(label);
        }
        return ReturnMsg.ok(labels1);
    }

    @Override
    public ReturnMsg getElectricityCircleInfoList() {
        List<Cake> list = new ArrayList<>();
        list.add(new Cake("其他用电"));
        list.add(new Cake("公共用电"));
        list.add(new Cake("信息机房用电"));
        list.add(new Cake("照明用电"));
        list.add(new Cake("动力用电"));
        return ReturnMsg.ok(list);
    }

    @Override
    public ReturnMsg getWaterCoreIndicators() {
        Indeicator indeicator = new Indeicator();
        List<JSONObject> objects = indeicator.getList();
        ThreadLocalRandom random = ThreadLocalRandom.current();
        /*int todayWater = random.nextInt(25, 300);//今日
        int personWater = random.nextInt(10,50);//人均
        int top = random.nextInt(0,100);//同比上升
        int totalWater = random.nextInt(500, 3000);*/
        float compare = 0.3f;
      /*  DecimalFormat decimalFormat = new DecimalFormat("#.0");
        compare = Float.parseFloat(decimalFormat.format(compare));*/
        objects.get(0).put("value",376.9);
        objects.get(0).put("compare",compare);

        objects.get(1).put("value",19.8);
        objects.get(1).put("compare",compare);

        objects.get(2).put("value",-3.5);

        objects.get(3).put("value",1.2);
        objects.get(3).put("compare",compare);
        indeicator.setWorthAttention("建议合理搭配智慧场景调整⽤⽔策略");
        indeicator.setList(objects);
        return ReturnMsg.ok(indeicator);
    }

    @Override
    public ReturnMsg getWaterInfoList() {
        String[] param = {"water"};
      /*  String[] labKey = {"1月","2月","3月","4月","5月","6月","7月","8月","9月","10月","11月","12月"};*/
        List<String> lists = DateUtil.getBetweenDays("2023/03/01", "2023/03/31");
        String[] labKey = lists.toArray(new String[0]);
        List<Label> labels1 = new ArrayList<>();
        //GeneralMethod.getInstance().dataGeneration(param, labKey);
        ThreadLocalRandom random = ThreadLocalRandom.current();
        for (int i = 0; i < labKey.length; i++) {
            Label label = new Label();
            JSONObject jsonObject = new JSONObject();
            int i1 = random.nextInt(10, 15);
            jsonObject.put(param[0],i1);
            label.setJsonObject(jsonObject);
            label.setLabel(labKey[i]);
            labels1.add(label);
        }
        return ReturnMsg.ok(labels1);
    }

    @Override
    public ReturnMsg getWaterCircleInfoList() {
        List<Cake> list = new ArrayList<>();
        list.add(new Cake("自来水"));
        list.add(new Cake("中水"));
        return ReturnMsg.ok(list);
    }

    @Override
    public ReturnMsg getUseColdCoreIndicators() {
        Indeicator indeicator = new Indeicator();
        List<JSONObject> objects = indeicator.getList();
        ThreadLocalRandom random = ThreadLocalRandom.current();
        int percentCold = random.nextInt(10, 100);
        int personCold = random.nextInt(10,50);
        int top = random.nextInt(0,100);//同比上升
        int totalCold = random.nextInt(500, 3000);
        float compare = (float) Math.random();
        DecimalFormat decimalFormat = new DecimalFormat("#.0");
        compare = Float.parseFloat(decimalFormat.format(compare));
        objects.get(0).put("value",totalCold);
        objects.get(0).put("compare",compare);

        objects.get(2).put("value",top);

        objects.get(3).put("value","一级（3.6）");
        objects.get(3).put("compare",compare);
        objects.get(1).put("value",personCold);
        objects.get(1).put("compare",compare);
        indeicator.setWorthAttention("建议合理搭配智慧场景调整⽤冷策略");
        indeicator.setList(objects);
        return ReturnMsg.ok(indeicator);
    }

    @Override
    public ReturnMsg getUseColdInfoList() {
        String[] param = {"coolingCapacity","temperature"};
       /* String[] labKey = {"1月","2月","3月","4月","5月","6月","7月","8月","9月","10月","11月","12月"};*/
        List<String> lists = DateUtil.getBetweenDays("2023/03/01", "2023/03/31");
        String[] labKey = lists.toArray(new String[0]);
       // List<Label> labels1 = GeneralMethod.getInstance().dataGeneration(param, labKey);
        List<Label> list = new ArrayList<>();
        ThreadLocalRandom random = ThreadLocalRandom.current();
        for (int i = 0; i < labKey.length; i++) {
            Label label = new Label();
            JSONObject jsonObject = new JSONObject();
            int i1 = random.nextInt(50, 150);
            int i2 = random.nextInt(0, 35);
            jsonObject.put(param[0],i1);
            jsonObject.put(param[1],i2);
            label.setJsonObject(jsonObject);
            label.setLabel(labKey[i]);
            list.add(label);
        }
        return ReturnMsg.ok(list);
    }

    @Override
    public ReturnMsg getUseHeatCoreIndicators() {
        Indeicator indeicator = new Indeicator();
        List<JSONObject> objects = indeicator.getList();
        ThreadLocalRandom random = ThreadLocalRandom.current();
        /*int percentHeat = random.nextInt(10, 100);
        int personHeat = random.nextInt(10,50);
        int top = random.nextInt(0,100);//同比上升
        int totalHeat = random.nextInt(500, 3000);*/
        float compare = 0.6f;
        /*DecimalFormat decimalFormat = new DecimalFormat("#.0");
        compare = Float.parseFloat(decimalFormat.format(compare));*/
        objects.get(0).put("value",243.8);
        objects.get(0).put("compare",compare);

        objects.get(2).put("value",-1.2);

        objects.get(3).put("value",8);
        objects.get(3).put("compare",compare);

        objects.get(1).put("value",16);
        objects.get(1).put("compare",compare);
        indeicator.setWorthAttention("建议合理搭配智慧场景调整⽤热策略");
        indeicator.setList(objects);
        return ReturnMsg.ok(indeicator);
    }

    @Override
    public ReturnMsg getUseHeatInfoList() {
        String[] param = {"heatConsumption","temperature"};
        List<String> lists = DateUtil.getBetweenDays("2023/03/01", "2023/03/31");
        String[] labKey = lists.toArray(new String[0]);
        List<Label> labels1 = new ArrayList<>();
                //GeneralMethod.getInstance().dataGeneration(param, labKey);
        ThreadLocalRandom random = ThreadLocalRandom.current();
        for (int i = 0; i < labKey.length; i++) {
            Label label = new Label();
            JSONObject jsonObject = new JSONObject();
            int i1 = random.nextInt(0, 10);
            int i2 = random.nextInt(5, 30);
            jsonObject.put(param[0],i1);
            jsonObject.put(param[1],i2);
            label.setJsonObject(jsonObject);
            label.setLabel(labKey[i]);
            labels1.add(label);
        }
        return ReturnMsg.ok(labels1);
    }
}
