package com.shining.cloud.task;

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

import javax.annotation.Resource;
import javax.security.auth.login.AccountException;

import cn.hutool.core.collection.CollectionUtil;
import com.njcn.utils.PubUtils;
import com.shining.cloud.mapper.information.*;
import com.shining.cloud.pojo.information.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;

import com.njcn.mapper.configuration.DeviceMapper;
import com.njcn.mapper.data.LimitRateMapper;
import com.njcn.mapper.user.AppUserMapper;
import com.njcn.pojo.data.LimitRate;
import com.njcn.pojo.user.AppUser;
import com.njcn.utils.UserUtil;
import com.shining.cloud.mapper.statistics.StatisticsMapper;
import com.shining.cloud.pojo.statistics.Statistics;
import com.shining.cloud.service.information.EventMsgService;

import tk.mybatis.mapper.entity.Example;

@Component
public class SteadyMsgTask {
    private static final Logger logger = LoggerFactory.getLogger(SteadyMsgTask.class);
    @Autowired
    private UserUtil userUtil;
    @Autowired
    private EventMsgService eventMsgService;
    @Resource
    private SteadyAssMapper steadyAssMapper;
    @Resource
    private SteadyUrlMapper steadyUrlMapper;
    @Resource
    private AppUserMapper appUserMapper;
    @Resource
    private LimitRateMapper limitRateMapper;
    @Resource
    private DeviceMapper deviceMapper;
    @Resource
    private MonFlowMapper monFlowMapper;
    @Resource
    private DevMsgAssMapper devMsgAssMapper;
    @Resource
    private StatisticsMapper statisticsMapper;
    @Resource
    private EventInfoMapper eventInfoMapper;
    @Resource
    private TopMapper topMapper;
    @Resource
    private DevMsgMapper devMsgMapper;

    private Date startTime;
    private Date endTime;
    private String day;
    private Long timeId;
    private String month;
    private String dayend;

    @Scheduled(cron = "* * 10 * * ?")
    public void timer() throws Exception {
        System.out.println("开始执行++++++++++++++++++++++++"+new Date());
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(new Date());
        this.endTime = calendar.getTime();

        calendar.add(Calendar.DATE, -1);
        this.startTime = calendar.getTime();

        Calendar calendar1 = Calendar.getInstance();
        calendar1.setTime(new Date());


        SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd");
        calendar1.add(Calendar.MONTH, 0);
        calendar1.set(Calendar.DAY_OF_MONTH, 1);
        this.month = sdf1.format(calendar1.getTime())+" 00:00:00";

        this.dayend = sdf1.format(this.startTime)+" 23:59:59";

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        this.day = sdf.format(startTime);

        try {
            this.timeId = sdf.parse(this.day).getTime();
        } catch (ParseException e) {

        }

        steadyMsg();

        statisticsData();

       // sendTargetMsg();

        devDegree();
    }

    public void steadyMsg() {
        List<AppUser> users = appUserMapper.selectAll();

        if (users != null && users.size() > 0) {
            for (AppUser user : users) {
                List<Integer> indexs = userUtil.ApplistLine(user.getUserIndex());
                List<Integer> lineIndexs = new ArrayList<>();

                if (indexs == null) {
                    continue;
                }

                for (Integer index : indexs) {
                    if (userUtil.judgeLimit(index, this.timeId)) {
                        lineIndexs.add(index);
                    }
                }

                int num = lineIndexs.size();

                if (!StringUtils.isEmpty(user.getUserIndex()) && !StringUtils.isEmpty(this.timeId) && !StringUtils.isEmpty(num) && num > 0) {
                    try {
                        String msgIndex = eventMsgService.sendSteadyMsg(user.getUserIndex(), this.timeId, num);

                        for (Integer lineIndex : lineIndexs) {
                            SteadyAss ass = new SteadyAss();
                            ass.setSteadyIndex(msgIndex);
                            ass.setLineIndex(lineIndex);

                            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
                            ass.setTimeID(sdf.parse(this.day));

                            List<SteadyAss> TMP = steadyAssMapper.select(ass);
                            if(TMP.size() > 0){

                            }else{
                                steadyAssMapper.insert(ass);
                                saveSteadyUrl(lineIndex,sdf.parse(this.day));
                            }
                        }
                    } catch (AccountException |ParseException e) {
                        logger.error("发送消息发生异常，异常是"+e.getMessage());
                    }
                }
            }
        }

    }

    public void statisticsData() {
        List<AppUser> users = appUserMapper.selectAll();

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        if (users != null && users.size() > 0) {
            for (AppUser user : users) {
                List<Integer> indexs = userUtil.ApplistLine(user.getUserIndex());
                List<Integer> lineIndexs = new ArrayList<>();

                if (indexs == null) {
                    continue;
                }

                for (Integer index : indexs) {
                    List<Statistics> staData = statisticsMapper.queryByLineIndex(index);
                    List<String> eventIndexs = new ArrayList<>();
                    if (staData.size() > 0) {
                        try {
                            Long counts = statisticsMapper.queryEventCount(index, this.day);
                            eventIndexs = statisticsMapper.queryEventIndexList(index, this.day);
                            LimitRate rate = statisticsMapper.queryLimit(index, sdf.parse(this.day));
                            saveStatistics(index, sdf.parse(this.day), counts, rate);
                        } catch (ParseException e) {
                            logger.error("统计数据发生异常，异常是"+e.getMessage());
                        }
                    } else {
                        List<String> dates = statisticsMapper.queryEventDate(index);
                        List<String> list = new ArrayList<>();
                        for (String date : dates) {
                            try {
                                Long counts = statisticsMapper.queryEventCount(index, date);
                                list = statisticsMapper.queryEventIndexList(index, date);
                                LimitRate rate = statisticsMapper.queryLimit(index, sdf.parse(date));
                                eventIndexs.addAll(list);
                                saveStatistics(index, sdf.parse(date), counts, rate);
                            } catch (ParseException e) {
                                logger.error("统计数据发生异常，异常是"+e.getMessage());
                            }
                        }
                    }
                    saveEventInfo(eventIndexs);
                }

            }
        }
    }

    public void saveSteadyUrl(Integer lineIndex, Date timeId) {
        LimitRate limit = limitRateMapper.selectLimitRate(lineIndex, timeId);
        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(int lineIndex, Date timeId, int typeCode, int limitNum) {
        SteadyUrl url = new SteadyUrl();
        url.setLineIndex(lineIndex);
        url.setTimeID(timeId);
        url.setTypeCode(typeCode);
        url.setLimitNum(limitNum);
        SteadyUrl tmp = steadyUrlMapper.selectOne(url);

        if (tmp == null) {
            steadyUrlMapper.insert(url);
        }
    }

    public void sendTargetMsg()  {
        List<AppUser> users = appUserMapper.selectAll();

        if (users != null && users.size() > 0) {
            for (AppUser user : users) {

                List<Integer> devIndex = userUtil.ApplistDev(user.getUserIndex());

                if (devIndex.isEmpty()) {
                    continue;
                } else {
                    int alarmNum = 0;//告警次数
                    int comOutNum = 0;//通讯中断次数
                    float flowNum = 0;//流量超标
                    int hh = 0;
                    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
                    //int devNum = deviceMapper.getState(devIndex,sdf.format(new Date(this.timeId)));//通讯总共中断的台数
                    for (int i = 0; i < devIndex.size(); i++) {
                        flowNum = monFlowMapper.getMonFlows(devIndex.get(i), this.month,this.dayend);
                        comOutNum = deviceMapper.getStates(devIndex.get(i), sdf.format(new Date(this.timeId)));
                        if (comOutNum > 0 || flowNum > 94) {
                            hh++;
                        }
                    }
                    if (hh > 0) {
                        String devmsgIndex = null;
                        try {
                            devmsgIndex = eventMsgService.sendTargetMsg(user.getUserIndex(), this.timeId, hh, alarmNum, comOutNum, flowNum, 1);
                            if (devmsgIndex != null && devmsgIndex.length() != 0) {
                                for (int i = 0; i < devIndex.size(); i++) {
                                    flowNum = monFlowMapper.getMonFlows(devIndex.get(i), this.month,this.dayend);
                                    comOutNum = deviceMapper.getStates(devIndex.get(i), sdf.format(new Date(this.timeId)));
                                    if (comOutNum > 0 || flowNum > 94) {
                                        DevMsgAss devMsgAss = new DevMsgAss();
                                        devMsgAss.setDevMsgIndex(devmsgIndex);

                                        DevMsgAss devMsgAssint = new DevMsgAss();
                                        devMsgAssint.setDevMsgIndex(devmsgIndex);
                                        devMsgAssint.setDevIndex(devIndex.get(i));
                                        devMsgAssint.setAlarmNum(alarmNum);
                                        devMsgAssint.setComOutNum(comOutNum);
                                        devMsgAssint.setFlowNum(flowNum);
                                        devMsgAssint.setTimeId(new Date(this.timeId));
                                        devMsgAssMapper.insert(devMsgAssint);

                                    }
                                }
                            }
                        } catch (Exception e) {
                            logger.error("推送消息发生异常，异常是"+e.getMessage());
                        }
                    }

                }

            }
        }

    }


    //新增终端异常通告
    //app聚合
    public void devDegree(){
        Date startTime = new Date(this.timeId);

        /*SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        try {
            startTime = sdf.parse("2021-11-21 00:00:00");
        } catch (ParseException e) {
            e.printStackTrace();
        }*/

        int count = devMsgMapper.getCount(startTime);
        if(count>0){
            logger.error("运行时间："+new Date()+"存在多个运行的app项目,请检查!"+startTime);
            return;
        }
        List<AppUser> users = appUserMapper.selectAll();
        if(CollectionUtil.isNotEmpty(users)){
            for(AppUser user :users){
                List<Integer> devIndex = userUtil.ApplistDev(user.getUserIndex());
                if(CollectionUtil.isNotEmpty(devIndex)){
                    List<TopException> topList =  topMapper.getTopListByDevList(devIndex,startTime);
                    if(CollectionUtil.isNotEmpty(topList)){
                        int alarmNum = 0;//告警次数
                        int comOutNum = 0;//通讯中断次数
                        float flowNum = 0;//流量超标

                        String devmsgIndex = UUID.randomUUID().toString();
                        DevMsg devMsg = new DevMsg();
                        devMsg.setUserIndex(user.getUserIndex());
                        devMsg.setTimeId(startTime);
                        devMsg.setLimitNum(topList.size());
                        devMsg.setState(0);
                        devMsg.setDevMsgIndex(devmsgIndex);
                        devMsgMapper.insert(devMsg);


                        for(TopException topException:topList){
                            DevMsgAss devMsgAssint = new DevMsgAss();
                            devMsgAssint.setDevMsgIndex(devmsgIndex);
                            devMsgAssint.setDevIndex(topException.getDevIndex());
                            devMsgAssint.setAlarmNum(topException.getAlarmNum());
                            devMsgAssint.setComOutNum(topException.getComoutNum());
                            devMsgAssint.setFlowNum(topException.getFlowNum());
                            devMsgAssint.setTimeId(topException.getTimeId());
                            devMsgAssMapper.insert(devMsgAssint);

                            alarmNum+=topException.getAlarmNum();
                            comOutNum+=topException.getComoutNum();

                        }

                        try {
                            eventMsgService.sendTerminalMsg(startTime,user.getUserIndex(), topList.size(), alarmNum, comOutNum);
                        } catch (Exception e) {
                            logger.error("app用户消息接收配置异常，异常信息"+e.getMessage());
                        }


                    }
                }
            }
        }


    }

    public void saveStatistics(Integer lineIndex, Date date, Long count, LimitRate limit) {
        Example example = new Example(Statistics.class);
        example.createCriteria().andEqualTo("lineIndex", lineIndex).andEqualTo("timeID", date);
        List<Statistics> tmp = statisticsMapper.selectByExample(example);
        if (tmp.size() > 0) {
            return;
        }

        Statistics statistics = new Statistics();
        statistics.setLineIndex((long) lineIndex);
        statistics.setTimeID(date);
        statistics.setEventCount(count);

        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(lineIndex, date);
        }

        int flag = statisticsMapper.insert(statistics);
    }

    public void saveEventInfo(List<String> indexList) {
        if (indexList != null && indexList.size() > 0) {
            for (String eventDetail_index : indexList) {
                EventInfo eventInfo = eventInfoMapper.getEventInfoByUserIndex(eventDetail_index);

                if (eventInfo == null) {
                    eventInfoMapper.insertEventInfoData(eventDetail_index, 0, "", new Date(), "", "", 0, "");
                }
            }
        }
    }
}
