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

import com.alibaba.fastjson.JSONObject;
import com.sky.ioc.entity.GiveAlarm;
import com.sky.ioc.entity.Indeicator;
import com.sky.ioc.entity.Label;
import com.sky.ioc.entity.Cake;
import com.sky.ioc.entity.params.IocParam;
import com.sky.ioc.service.security.SecurityService;
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/3/7 10:03
 **/


@Service
public class SecurityServiceImpl implements SecurityService {
    @Override
    public ReturnMsg getLinkageCoreIndicators(IocParam iocParam) {
        Indeicator indeicator = new Indeicator();
        List<JSONObject> objects = indeicator.getList();
        ThreadLocalRandom random = ThreadLocalRandom.current();
        DecimalFormat decimalFormat = new DecimalFormat("#.0");
        int totalThings = random.nextInt(100, 2000);
        int urgencyThings = random.nextInt(0, 10);
        int doneThings = random.nextInt(100, 2000);
        while (urgencyThings>totalThings){
            urgencyThings = random.nextInt(10, 100);
        }
        while (doneThings>totalThings){
            doneThings = random.nextInt(100, 2000);
        }
        float compare = (float) Math.random();
        compare = Float.parseFloat(decimalFormat.format(compare));
        objects.get(0).put("value",totalThings);
        objects.get(0).put("compare",compare);

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

        objects.get(2).put("value",doneThings);
        objects.get(2).put("compare",compare);

        objects.get(3).put("value","设备离线");
        objects.get(3).put("compare",compare);
        indeicator.setWorthAttention("摄像设备掉线啦，派⼈去维护⼀下吧");
        indeicator.setList(objects);
        return ReturnMsg.ok(indeicator);
    }

    @Override
    public ReturnMsg getAlarmTrend(IocParam iocParam) {
        String[] param = {"commonly","important","urgent"};
        String startStr = iocParam.getTimeRange().getStartDate();
        String endStr = iocParam.getTimeRange().getEndDate();
        List<String> lists = DateUtil.getBetweenDays(startStr, endStr);
        String[] labKey = lists.toArray(new String[0]);
        List<Label> labels1 = GeneralMethod.getInstance().dataGeneration(param, labKey);
        return ReturnMsg.ok(labels1);
    }

    @Override
    public ReturnMsg getAlarmClassification(IocParam iocParam) {
        String[] param = {"alarmNumber"};
        String startStr = iocParam.getTimeRange().getStartDate();
        String endStr = iocParam.getTimeRange().getEndDate();
        List<String> lists = DateUtil.getBetweenDays(startStr, endStr);
        String[] labKey = lists.toArray(new String[0]);
        List<Label> labels1 = GeneralMethod.getInstance().dataGeneration(param, labKey);
        return ReturnMsg.ok(labels1);
    }

    @Override
    public ReturnMsg getEquipmentOnline(IocParam iocParam) {
        String[] param = {"camera","waterImmersion"};
        String startStr = iocParam.getTimeRange().getStartDate();
        String endStr = iocParam.getTimeRange().getEndDate();
        List<String> lists = DateUtil.getBetweenDays(startStr, endStr);
        String[] labKey = lists.toArray(new String[0]);
        ThreadLocalRandom random = ThreadLocalRandom.current();
        List<Label> list = new ArrayList<>();
        for (int i = 0; i < labKey.length; i++) {
            Label label = new Label();
            JSONObject jsonObject = new JSONObject();
            int i2 = random.nextInt(70, 90);
            int i1 = random.nextInt(70,90);
            jsonObject.put(param[0],i1);
            jsonObject.put(param[1],i2);
            label.setJsonObject(jsonObject);
            label.setLabel(labKey[i]);
            list.add(label);
        }
      //  List<Label> labels1 = GeneralMethod.getInstance().dataGeneration(param, labKey);
        return ReturnMsg.ok(list);
    }

    @Override
    public ReturnMsg getFloorAlarmDistribution(IocParam iocParam) {
        List<Cake> list = new ArrayList<>();
        list.add(new Cake("B2"));
        list.add(new Cake("B1"));
        list.add(new Cake("1F"));
        return ReturnMsg.ok(list);
    }

    @Override
    public ReturnMsg getGiveAlarmList(IocParam iocParam) {
        List<GiveAlarm> list = new ArrayList<>();
        list.add(new GiveAlarm());
        list.add(new GiveAlarm());
        list.add(new GiveAlarm());
        list.add(new GiveAlarm());
        list.add(new GiveAlarm());
        list.add(new GiveAlarm());
        return ReturnMsg.ok(list);
    }
}
