package com.njcn.cloud.controller.task;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.date.LocalDateTimeUtil;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.njcn.cloud.pojo.dto.*;
import com.njcn.cloud.service.*;
import com.njcn.device.pq.api.GeneralDeviceInfoClient;
import com.njcn.device.pq.pojo.param.OnlineRateParam;
import com.njcn.device.pq.pojo.po.TopMsgPO;
import com.njcn.event.api.EventDetailFeignClient;
import com.njcn.event.pojo.param.EventCountParam;
import com.njcn.event.pojo.po.RmpEventDetailPO;
import com.njcn.harmonic.api.HarmDataFeignClient;
import com.njcn.harmonic.pojo.param.StatSubstationBizBaseParam;
import com.njcn.harmonic.pojo.po.day.RStatLimitRateDPO;
import com.njcn.user.api.UserFeignClient;
import com.njcn.user.pojo.po.User;
import lombok.RequiredArgsConstructor;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.stream.Collectors;

@Component
@RequiredArgsConstructor
public class SteadyMsgTask {

    private final UserFeignClient userFeignClient;
    private final GeneralDeviceInfoClient generalDeviceInfoClient;
    private final HarmDataFeignClient harmDataFeignClient;
    private final MsgService msgService;
    private final IAppSteadyUrlService appSteadyUrlService;
    private final IAppSteadyAssService appSteadyAssService;
    private final IAppDevMsgService appDevMsgService;
    private final EventDetailFeignClient eventDetailFeignClient;
    private final IAppStatisticsService appStatisticsService;
    private final IAppEventInfoService appEventInfoService;

    @Scheduled(cron = "0 0 10 * * ?")
    public void timer() {
        System.out.println("开始执行++++++++++++++++++++++++" + new Date());
        Date date = DateUtil.offsetDay(new Date(), -1);
        String time = DateUtil.format(date, DatePattern.NORM_DATE_PATTERN);

        //开始时间
        String startTime = DateUtil.beginOfDay(date).toString();
        //结束时间
        String endTime = DateUtil.endOfDay(date).toString();

        //执行稳态消息推送
        steadyMsg(time, startTime, endTime);
        //终端消息推送
        devDegree(time, startTime, endTime);
        //统计消息推送
        statisticsData(time, startTime, endTime);
    }

    /**
     * @Description: 稳态消息
     * @Date: 2023/11/17 15:07
     */
    public void steadyMsg(String time, String startTime, String endTime) {
        List<User> users = userFeignClient.getUserByIdList(new ArrayList<>()).getData();
//        List<User> users = userFeignClient.getUserByIdList(Arrays.asList("5434cc08dc9d4b7cba5e856de52f0dda")).getData();
        if (CollUtil.isNotEmpty(users)) {
            StatSubstationBizBaseParam param;
            for (User user : users) {
                //根据单位获取投运监测点
                List<String> lineIds = generalDeviceInfoClient.deptGetRunLine(user.getDeptId()).getData();
                param = new StatSubstationBizBaseParam();
                param.setIds(lineIds);
                param.setStartTime(startTime);
                param.setEndTime(endTime);
                List<String> linesTargets = harmDataFeignClient.getLinesTarget(param).getData();
                if (CollUtil.isNotEmpty(linesTargets)) {
                    param.setIds(linesTargets);
                    List<RStatLimitRateDPO> limitRates = harmDataFeignClient.getLinesRate(param).getData();
                    //获取稳态消息guid
                    String msgIndex = msgService.sendSteadyMsg(user.getId(), time, linesTargets.size());
                    LocalDateTime date = LocalDateTimeUtil.parse(time, DatePattern.NORM_DATE_PATTERN);
                    AppSteadyAss steadyAss;
                    for (RStatLimitRateDPO line : limitRates) {
                        steadyAss = new AppSteadyAss();
                        steadyAss.setSteadyIndex(msgIndex);
                        steadyAss.setLineIndex(line.getLineId());
                        steadyAss.setTimeId(date);
                        appSteadyAssService.save(steadyAss);
                        saveSteadyUrl(line, date);
                    }
                }

            }
        }
    }

    /**
     * @Description: 新增终端异常通告
     * @Date: 2023/11/17 15:08
     */
    public void devDegree(String time, String startTime, String endTime) {
        LocalDateTime date = LocalDateTimeUtil.parse(time, DatePattern.NORM_DATE_PATTERN);
        List<User> users = userFeignClient.getUserByIdList(new ArrayList<>()).getData();
        if (CollUtil.isNotEmpty(users)) {
            for (User user : users) {
                List<String> devIds = generalDeviceInfoClient.deptGetRunDev(user.getDeptId()).getData();
                //获取消息信息
                OnlineRateParam top = new OnlineRateParam();
                top.setIds(devIds);
                top.setType(1);
                top.setStartTime(startTime);
                top.setEndTime(endTime);
                List<TopMsgPO> topMsgList = generalDeviceInfoClient.getTopMsgInfoByIds(top).getData();
                AppDevMsg appDevMsg;
                for (TopMsgPO topMsgPO : topMsgList) {
                    appDevMsg = new AppDevMsg();
                    appDevMsg.setDevmsgIndex(IdUtil.simpleUUID());
                    appDevMsg.setTopId(topMsgPO.getTopId());
                    appDevMsg.setUserIndex(user.getId());
                    appDevMsg.setTimeId(date);
                    appDevMsg.setState(0);
                    appDevMsgService.save(appDevMsg);
                    msgService.sendTerminalMsg(user.getId(), user.getDevCode(), time,
                            topMsgPO.getDeviceAbnormalNum(),
                            topMsgPO.getAlarmCount(),
                            topMsgPO.getComOutCount()
                    );
                }

            }
        }
    }

    /**
     * @param
     * @Description: 统计数据
     * @Author: wr
     * @Date: 2024/1/4 13:48
     */
    public void statisticsData(String time, String startTime, String endTime) {
        LocalDateTime timeDay = LocalDateTimeUtil.parse(time, DatePattern.NORM_DATE_PATTERN);
//        List<User> users = userFeignClient.getUserByIdList(new ArrayList<>()).getData();
        List<User> users = userFeignClient.getUserByIdList(Arrays.asList("5434cc08dc9d4b7cba5e856de52f0dda")).getData();
        if (CollUtil.isNotEmpty(users)) {
            for (User user : users) {
                //根据单位获取投运监测点
                List<String> lineIds = generalDeviceInfoClient.deptGetRunLine(user.getDeptId()).getData();
                //1.根据监测点层级进行统计数据
                for (String lineId : lineIds) {
                    List<AppStatistics> list = appStatisticsService.list(new LambdaQueryWrapper<AppStatistics>()
                            .eq(AppStatistics::getLineIndex, lineId)
                    );
                    List<String> eventIndexS = new ArrayList<>();
                    //2.查询数据库中是否有统计数据，没有则进行补录
                    if (CollUtil.isNotEmpty(list)) {
                        eventIndexS.addAll(statisticsMethod(startTime, endTime, timeDay, lineId));
                    } else {
                        List<String> dates = getListDate(lineId);
                        for (String date : dates) {
                            LocalDateTime dateDay = LocalDateTimeUtil.parse(date, DatePattern.NORM_DATE_PATTERN);
                            String startDate = DateUtil.beginOfDay(DateUtil.parse(date)).toString();
                            String endDate = DateUtil.endOfDay(DateUtil.parse(date)).toString();
                            eventIndexS.addAll(statisticsMethod(startDate, endDate, dateDay, lineId));
                        }
                    }
                    saveEventInfo(eventIndexS);
                }
            }
        }
    }

    /**
     * 获取暂态时间和谐波时间
     *
     * @param lineId
     * @return
     */
    private List<String> getListDate(String lineId) {
        EventCountParam param;
        StatSubstationBizBaseParam baseParam;
        List<String> dates = new ArrayList<>();
        baseParam = new StatSubstationBizBaseParam();
        baseParam.setIds(Collections.singletonList(lineId));
        //获取谐波数据
        List<RStatLimitRateDPO> limitRates = harmDataFeignClient.getLinesRate(baseParam).getData();
        if (CollUtil.isNotEmpty(limitRates)) {
            dates.addAll(limitRates.stream().map(x -> x.getTime().format(DateTimeFormatter.ofPattern(DatePattern.NORM_DATE_PATTERN)))
                    .distinct().collect(Collectors.toList()));
        }
        param = new EventCountParam();
        param.setIds(Collections.singletonList(lineId));
        List<RmpEventDetailPO> detailPOList = eventDetailFeignClient.getAppEventDetailLtAmplitude(param).getData();
        if (CollUtil.isNotEmpty(detailPOList)) {
            dates.addAll(detailPOList.stream().map(x -> x.getStartTime().format(DateTimeFormatter.ofPattern(DatePattern.NORM_DATE_PATTERN)))
                    .distinct().collect(Collectors.toList()));
        }
        return dates;
    }

    /**
     * 查询方法信息
     *
     * @param startTime
     * @param endTime
     * @param timeDay
     * @param lineId
     */
    private List<String> statisticsMethod(String startTime, String endTime, LocalDateTime timeDay, String lineId) {
        EventCountParam param;
        StatSubstationBizBaseParam baseParam;
        //获取谐波数据
        baseParam = new StatSubstationBizBaseParam();
        baseParam.setIds(Collections.singletonList(lineId));
        baseParam.setStartTime(startTime);
        baseParam.setEndTime(endTime);
        List<RStatLimitRateDPO> limitRates = harmDataFeignClient.getLinesRate(baseParam).getData();
        //获取暂态数据
        param = new EventCountParam();
        param.setIds(Collections.singletonList(lineId));
        param.setStartTime(startTime);
        param.setEndTime(endTime);
        //获取特征增幅小于0.9的暂态信息
        List<RmpEventDetailPO> detailPOList = eventDetailFeignClient.getAppEventDetailLtAmplitude(param).getData();
        saveStatistics(lineId, timeDay, detailPOList.size(), CollUtil.isNotEmpty(limitRates)?limitRates.get(0):null);
        return detailPOList.stream().map(RmpEventDetailPO::getEventId).distinct().collect(Collectors.toList());
    }

    public void saveSteadyUrl(RStatLimitRateDPO limit, LocalDateTime timeId) {
        String lineIndex = limit.getLineId();
        if (limit.getFreqDevOvertime() > 0) {
            insertUrlDate(lineIndex, timeId, 2, limit.getFreqDevOvertime());
        }
        if (limit.getVoltageDevOvertime() > 0) {
            insertUrlDate(lineIndex, timeId, 3, limit.getVoltageDevOvertime());
        }
        if (limit.getUbalanceOvertime() > 0) {
            insertUrlDate(lineIndex, timeId, 4, limit.getUbalanceOvertime());
        }
        if (limit.getFlickerOvertime() > 0) {
            insertUrlDate(lineIndex, timeId, 5, limit.getFlickerOvertime());
        }
        if (limit.getUaberranceOvertime() > 0) {
            insertUrlDate(lineIndex, timeId, 6, limit.getUaberranceOvertime());
        }
        if (limit.getUharm2Overtime() > 0) {
            insertUrlDate(lineIndex, timeId, 7, limit.getUharm2Overtime());
        }
        if (limit.getUharm3Overtime() > 0) {
            insertUrlDate(lineIndex, timeId, 8, limit.getUharm3Overtime());
        }
        if (limit.getUharm4Overtime() > 0) {
            insertUrlDate(lineIndex, timeId, 9, limit.getUharm4Overtime());
        }
        if (limit.getUharm5Overtime() > 0) {
            insertUrlDate(lineIndex, timeId, 10, limit.getUharm5Overtime());
        }
        if (limit.getUharm6Overtime() > 0) {
            insertUrlDate(lineIndex, timeId, 11, limit.getUharm6Overtime());
        }
        if (limit.getUharm7Overtime() > 0) {
            insertUrlDate(lineIndex, timeId, 12, limit.getUharm7Overtime());
        }
        if (limit.getUharm8Overtime() > 0) {
            insertUrlDate(lineIndex, timeId, 13, limit.getUharm8Overtime());
        }
        if (limit.getUharm9Overtime() > 0) {
            insertUrlDate(lineIndex, timeId, 14, limit.getUharm9Overtime());
        }
        if (limit.getUharm10Overtime() > 0) {
            insertUrlDate(lineIndex, timeId, 15, limit.getUharm10Overtime());
        }
        if (limit.getUharm11Overtime() > 0) {
            insertUrlDate(lineIndex, timeId, 16, limit.getUharm11Overtime());
        }
        if (limit.getUharm12Overtime() > 0) {
            insertUrlDate(lineIndex, timeId, 17, limit.getUharm12Overtime());
        }
        if (limit.getUharm13Overtime() > 0) {
            insertUrlDate(lineIndex, timeId, 18, limit.getUharm13Overtime());
        }
        if (limit.getUharm14Overtime() > 0) {
            insertUrlDate(lineIndex, timeId, 19, limit.getUharm14Overtime());
        }
        if (limit.getUharm15Overtime() > 0) {
            insertUrlDate(lineIndex, timeId, 20, limit.getUharm15Overtime());
        }
        if (limit.getUharm16Overtime() > 0) {
            insertUrlDate(lineIndex, timeId, 21, limit.getUharm16Overtime());
        }
        if (limit.getUharm17Overtime() > 0) {
            insertUrlDate(lineIndex, timeId, 22, limit.getUharm17Overtime());
        }
        if (limit.getUharm18Overtime() > 0) {
            insertUrlDate(lineIndex, timeId, 23, limit.getUharm18Overtime());
        }
        if (limit.getUharm19Overtime() > 0) {
            insertUrlDate(lineIndex, timeId, 24, limit.getUharm19Overtime());
        }
        if (limit.getUharm20Overtime() > 0) {
            insertUrlDate(lineIndex, timeId, 25, limit.getUharm20Overtime());
        }
        if (limit.getUharm21Overtime() > 0) {
            insertUrlDate(lineIndex, timeId, 26, limit.getUharm21Overtime());
        }
        if (limit.getUharm22Overtime() > 0) {
            insertUrlDate(lineIndex, timeId, 27, limit.getUharm22Overtime());
        }
        if (limit.getUharm23Overtime() > 0) {
            insertUrlDate(lineIndex, timeId, 28, limit.getUharm23Overtime());
        }
        if (limit.getUharm24Overtime() > 0) {
            insertUrlDate(lineIndex, timeId, 29, limit.getUharm24Overtime());
        }
        if (limit.getUharm25Overtime() > 0) {
            insertUrlDate(lineIndex, timeId, 30, limit.getUharm25Overtime());
        }
        if (limit.getIharm2Overtime() > 0) {
            insertUrlDate(lineIndex, timeId, 31, limit.getIharm2Overtime());
        }
        if (limit.getIharm3Overtime() > 0) {
            insertUrlDate(lineIndex, timeId, 32, limit.getIharm3Overtime());
        }
        if (limit.getIharm4Overtime() > 0) {
            insertUrlDate(lineIndex, timeId, 33, limit.getIharm4Overtime());
        }
        if (limit.getIharm5Overtime() > 0) {
            insertUrlDate(lineIndex, timeId, 34, limit.getIharm5Overtime());
        }
        if (limit.getIharm6Overtime() > 0) {
            insertUrlDate(lineIndex, timeId, 35, limit.getIharm6Overtime());
        }
        if (limit.getIharm7Overtime() > 0) {
            insertUrlDate(lineIndex, timeId, 36, limit.getIharm7Overtime());
        }
        if (limit.getIharm8Overtime() > 0) {
            insertUrlDate(lineIndex, timeId, 37, limit.getIharm8Overtime());
        }
        if (limit.getIharm9Overtime() > 0) {
            insertUrlDate(lineIndex, timeId, 38, limit.getIharm9Overtime());
        }
        if (limit.getIharm10Overtime() > 0) {
            insertUrlDate(lineIndex, timeId, 39, limit.getIharm10Overtime());
        }
        if (limit.getIharm11Overtime() > 0) {
            insertUrlDate(lineIndex, timeId, 40, limit.getIharm11Overtime());
        }
        if (limit.getIharm12Overtime() > 0) {
            insertUrlDate(lineIndex, timeId, 41, limit.getIharm12Overtime());
        }
        if (limit.getIharm13Overtime() > 0) {
            insertUrlDate(lineIndex, timeId, 42, limit.getIharm13Overtime());
        }
        if (limit.getIharm14Overtime() > 0) {
            insertUrlDate(lineIndex, timeId, 43, limit.getIharm14Overtime());
        }
        if (limit.getIharm15Overtime() > 0) {
            insertUrlDate(lineIndex, timeId, 44, limit.getIharm15Overtime());
        }
        if (limit.getIharm16Overtime() > 0) {
            insertUrlDate(lineIndex, timeId, 45, limit.getIharm16Overtime());
        }
        if (limit.getIharm17Overtime() > 0) {
            insertUrlDate(lineIndex, timeId, 46, limit.getIharm17Overtime());
        }
        if (limit.getIharm18Overtime() > 0) {
            insertUrlDate(lineIndex, timeId, 47, limit.getIharm18Overtime());
        }
        if (limit.getIharm19Overtime() > 0) {
            insertUrlDate(lineIndex, timeId, 48, limit.getIharm19Overtime());
        }
        if (limit.getIharm20Overtime() > 0) {
            insertUrlDate(lineIndex, timeId, 49, limit.getIharm20Overtime());
        }
        if (limit.getIharm21Overtime() > 0) {
            insertUrlDate(lineIndex, timeId, 50, limit.getIharm21Overtime());
        }
        if (limit.getIharm22Overtime() > 0) {
            insertUrlDate(lineIndex, timeId, 51, limit.getIharm22Overtime());
        }
        if (limit.getIharm23Overtime() > 0) {
            insertUrlDate(lineIndex, timeId, 52, limit.getIharm23Overtime());
        }
        if (limit.getIharm24Overtime() > 0) {
            insertUrlDate(lineIndex, timeId, 53, limit.getIharm24Overtime());
        }
        if (limit.getIharm25Overtime() > 0) {
            insertUrlDate(lineIndex, timeId, 54, limit.getIharm25Overtime());
        }
    }

    public void insertUrlDate(String lineIndex, LocalDateTime timeId, Integer typeCode, Integer limitNum) {
        AppSteadyUrl url = new AppSteadyUrl();
        url.setLineIndex(lineIndex);
        url.setTimeId(timeId);
        url.setTypeCode(typeCode);
        url.setLimitNum(limitNum);
        AppSteadyUrl one = appSteadyUrlService.getOne(new LambdaQueryWrapper<AppSteadyUrl>()
                .eq(AppSteadyUrl::getLineIndex, lineIndex)
                .eq(AppSteadyUrl::getTimeId, timeId)
                .eq(AppSteadyUrl::getTypeCode, typeCode)
                .eq(AppSteadyUrl::getLimitNum, limitNum)
        );
        if (ObjectUtil.isNull(one)) {
            appSteadyUrlService.save(url);
        }
    }

    public void saveStatistics(String lineIndex, LocalDateTime time, Integer count, RStatLimitRateDPO limit) {
        List<AppStatistics> list = appStatisticsService.list(new LambdaQueryWrapper<AppStatistics>()
                .eq(AppStatistics::getLineIndex, lineIndex)
                .eq(AppStatistics::getTimeId, time)
        );
        if (CollUtil.isEmpty(list)) {
            AppStatistics statistics = new AppStatistics();
            statistics.setLineIndex(lineIndex);
            statistics.setTimeId(time);
            statistics.setEventCount(count);
            if (ObjectUtil.isNotNull(limit)) {
                if (limit.getAllTime() > 0) {
                    Integer times = limit.getAllTime();
                    statistics.setFreqDevRate((float) Math.round((times - limit.getFreqDevOvertime()) * 10000 / times) / 100);
                    statistics.setVoltageDevRate((float) Math.round((times - limit.getVoltageDevOvertime()) * 10000 / times) / 100);
                    statistics.setUbalanceRate((float) Math.round((times - limit.getUbalanceOvertime()) * 10000 / times) / 100);
                    statistics.setFlickerRate((float) Math.round((times - limit.getFlickerOvertime()) * 10000 / times) / 100);
                    statistics.setUaberranceRate((float) Math.round((times - limit.getUaberranceOvertime()) * 10000 / times) / 100);
                    statistics.setUharm2Rate((float) Math.round((times - limit.getUharm2Overtime()) * 10000 / times) / 100);
                    statistics.setUharm3Rate((float) Math.round((times - limit.getUharm3Overtime()) * 10000 / times) / 100);
                    statistics.setUharm4Rate((float) Math.round((times - limit.getUharm4Overtime()) * 10000 / times) / 100);
                    statistics.setUharm5Rate((float) Math.round((times - limit.getUharm5Overtime()) * 10000 / times) / 100);
                    statistics.setUharm6Rate((float) Math.round((times - limit.getUharm6Overtime()) * 10000 / times) / 100);
                    statistics.setUharm7Rate((float) Math.round((times - limit.getUharm7Overtime()) * 10000 / times) / 100);
                    statistics.setUharm8Rate((float) Math.round((times - limit.getUharm8Overtime()) * 10000 / times) / 100);
                    statistics.setUharm9Rate((float) Math.round((times - limit.getUharm9Overtime()) * 10000 / times) / 100);
                    statistics.setUharm10Rate((float) Math.round((times - limit.getUharm10Overtime()) * 10000 / times) / 100);
                    statistics.setUharm11Rate((float) Math.round((times - limit.getUharm11Overtime()) * 10000 / times) / 100);
                    statistics.setUharm12Rate((float) Math.round((times - limit.getUharm12Overtime()) * 10000 / times) / 100);
                    statistics.setUharm13Rate((float) Math.round((times - limit.getUharm13Overtime()) * 10000 / times) / 100);
                    statistics.setUharm14Rate((float) Math.round((times - limit.getUharm14Overtime()) * 10000 / times) / 100);
                    statistics.setUharm15Rate((float) Math.round((times - limit.getUharm15Overtime()) * 10000 / times) / 100);
                    statistics.setUharm16Rate((float) Math.round((times - limit.getUharm16Overtime()) * 10000 / times) / 100);
                    statistics.setUharm17Rate((float) Math.round((times - limit.getUharm17Overtime()) * 10000 / times) / 100);
                    statistics.setUharm18Rate((float) Math.round((times - limit.getUharm18Overtime()) * 10000 / times) / 100);
                    statistics.setUharm19Rate((float) Math.round((times - limit.getUharm19Overtime()) * 10000 / times) / 100);
                    statistics.setUharm20Rate((float) Math.round((times - limit.getUharm20Overtime()) * 10000 / times) / 100);
                    statistics.setUharm21Rate((float) Math.round((times - limit.getUharm21Overtime()) * 10000 / times) / 100);
                    statistics.setUharm22Rate((float) Math.round((times - limit.getUharm22Overtime()) * 10000 / times) / 100);
                    statistics.setUharm23Rate((float) Math.round((times - limit.getUharm23Overtime()) * 10000 / times) / 100);
                    statistics.setUharm24Rate((float) Math.round((times - limit.getUharm24Overtime()) * 10000 / times) / 100);
                    statistics.setUharm25Rate((float) Math.round((times - limit.getUharm25Overtime()) * 10000 / times) / 100);
                    statistics.setIharm2Rate((float) Math.round((times - limit.getIharm2Overtime()) * 10000 / times) / 100);
                    statistics.setIharm3Rate((float) Math.round((times - limit.getIharm3Overtime()) * 10000 / times) / 100);
                    statistics.setIharm4Rate((float) Math.round((times - limit.getIharm4Overtime()) * 10000 / times) / 100);
                    statistics.setIharm5Rate((float) Math.round((times - limit.getIharm5Overtime()) * 10000 / times) / 100);
                    statistics.setIharm6Rate((float) Math.round((times - limit.getIharm6Overtime()) * 10000 / times) / 100);
                    statistics.setIharm7Rate((float) Math.round((times - limit.getIharm7Overtime()) * 10000 / times) / 100);
                    statistics.setIharm8Rate((float) Math.round((times - limit.getIharm8Overtime()) * 10000 / times) / 100);
                    statistics.setIharm9Rate((float) Math.round((times - limit.getIharm9Overtime()) * 10000 / times) / 100);
                    statistics.setIharm10Rate((float) Math.round((times - limit.getIharm10Overtime()) * 10000 / times) / 100);
                    statistics.setIharm11Rate((float) Math.round((times - limit.getIharm11Overtime()) * 10000 / times) / 100);
                    statistics.setIharm12Rate((float) Math.round((times - limit.getIharm12Overtime()) * 10000 / times) / 100);
                    statistics.setIharm13Rate((float) Math.round((times - limit.getIharm13Overtime()) * 10000 / times) / 100);
                    statistics.setIharm14Rate((float) Math.round((times - limit.getIharm14Overtime()) * 10000 / times) / 100);
                    statistics.setIharm15Rate((float) Math.round((times - limit.getIharm15Overtime()) * 10000 / times) / 100);
                    statistics.setIharm16Rate((float) Math.round((times - limit.getIharm16Overtime()) * 10000 / times) / 100);
                    statistics.setIharm17Rate((float) Math.round((times - limit.getIharm17Overtime()) * 10000 / times) / 100);
                    statistics.setIharm18Rate((float) Math.round((times - limit.getIharm18Overtime()) * 10000 / times) / 100);
                    statistics.setIharm19Rate((float) Math.round((times - limit.getIharm19Overtime()) * 10000 / times) / 100);
                    statistics.setIharm20Rate((float) Math.round((times - limit.getIharm20Overtime()) * 10000 / times) / 100);
                    statistics.setIharm21Rate((float) Math.round((times - limit.getIharm21Overtime()) * 10000 / times) / 100);
                    statistics.setIharm22Rate((float) Math.round((times - limit.getIharm22Overtime()) * 10000 / times) / 100);
                    statistics.setIharm23Rate((float) Math.round((times - limit.getIharm23Overtime()) * 10000 / times) / 100);
                    statistics.setIharm24Rate((float) Math.round((times - limit.getIharm24Overtime()) * 10000 / times) / 100);
                    statistics.setIharm25Rate((float) Math.round((times - limit.getIharm25Overtime()) * 10000 / times) / 100);
                    saveSteadyUrl(limit, time);
                }
            }
            appStatisticsService.save(statistics);
        }
    }
    public void saveEventInfo(List<String> indexList) {
        if (indexList != null && indexList.size() > 0) {
            for (String eventDetail_index : indexList) {
                AppEventInfo byId = appEventInfoService.getById(eventDetail_index);
                if (ObjectUtil.isNull(byId)) {
                    AppEventInfo info=new AppEventInfo();
                    info.setEventdetailIndex(eventDetail_index);
                    info.setEvaluate(0);
                    info.setUpdateTime(LocalDateTime.now());
                    info.setReportState(0);
                    appEventInfoService.save(info);
                }
            }
        }
    }
}
