package com.shining.cloud.serviceImpl.information;

import java.awt.Transparency;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Properties;
import java.util.Random;

import javax.annotation.Resource;
import javax.imageio.ImageIO;
import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang3.StringUtils;
import org.apache.http.client.ClientProtocolException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.njcn.enums.SeparatorEnum;
import com.njcn.mapper.configuration.LineDetailMapper;
import com.njcn.mapper.configuration.OverLimitMapper;
import com.njcn.mapper.data.LimitRateMapper;
import com.njcn.pojo.commons.WaveData;
import com.njcn.pojo.configuration.LineDetail;
import com.njcn.pojo.configuration.OverLimit;
import com.njcn.pojo.wave.WaveDataDetail;
import com.njcn.service.commons.IWaveService;
import com.njcn.utils.AppConfig;
import com.njcn.utils.PubUtils;
import com.njcn.utils.UserUtil;
import com.shining.cloud.enums.information.TypeCodeEnum;
import com.shining.cloud.mapper.common.SteadyUrlDataMapper;
import com.shining.cloud.mapper.information.SteadyAssMapper;
import com.shining.cloud.mapper.information.SteadyMsgMapper;
import com.shining.cloud.mapper.information.SteadyUrlMapper;
import com.shining.cloud.pojo.common.SteadyUrlData;
import com.shining.cloud.pojo.information.SteadyAss;
import com.shining.cloud.pojo.information.SteadyMsg;
import com.shining.cloud.pojo.information.SteadyMsgDetail;
import com.shining.cloud.pojo.information.SteadyTarget;
import com.shining.cloud.pojo.information.SteadyUrl;
import com.shining.cloud.service.information.SteadyAssService;
import com.shining.cloud.util.EchartsUtil;
import com.shining.cloud.util.FreemarkerUtil;

import freemarker.template.TemplateException;
import net.sf.json.JSONArray;
import sun.awt.image.BufferedImageGraphicsConfig;
import sun.misc.BASE64Decoder;

/**
 * @description: 稳态消息详情ServiceImpl
 * @author: denghuajun
 * @time: 2019-10-17 14:13:17
 **/
@Service
public class SteadyAssServiceImpl implements SteadyAssService {
    private static final Logger logger = LoggerFactory.getLogger(SteadyAssServiceImpl.class);
    @Autowired
    private AppConfig appConfig;
    @Resource
    private SteadyMsgMapper steadyMsgMapper;
    @Autowired
    private LimitRateMapper limitRateMapper;
    @Resource
    private SteadyAssMapper steadyAssMapper;
    @Resource
    private SteadyUrlDataMapper steadyUrlDataMapper;
    @Resource
    private SteadyUrlMapper steadyUrlMapper;
    @Resource
    private OverLimitMapper overLimitMapper;
    @Resource
    private LineDetailMapper lineDetailMapper;
    @Autowired
    private IWaveService iWaveService;

    @Resource
    private UserUtil userUtil;


    @Override
    public List<SteadyMsg> getSteadyState(String userId, int page, int num) {
        List<SteadyMsg> msgs = new ArrayList<>();

        PageHelper.offsetPage((page - 1) * num, num);
        msgs = steadyMsgMapper.getSteadyState(userId);
//        steadyMsgMapper.updateSteadyState(userId);

        return msgs;
    }

    @Override
    public List<SteadyMsgDetail> getSteadyDetail(String steadyIndex) {
        List<SteadyMsgDetail> msgs = new ArrayList<>();
        SteadyAss one = new SteadyAss();
        one.setSteadyIndex(steadyIndex);
        List<SteadyAss> msg = steadyAssMapper.queryByIndex(steadyIndex);
        if (msg == null && msg.size() == 0) {
            return null;
        }

        for (int i = 0; i < msg.size(); i++) {
            String describe = "";
            SteadyMsgDetail tmp = new SteadyMsgDetail();
            tmp = steadyMsgMapper.getName(msg.get(i).getLineIndex());
            tmp.setSteadyIndex(msg.get(i).getSteadyIndex());
            tmp.setTimeID(msg.get(i).getTimeID());

            List<SteadyUrl> ass = new ArrayList<>();
            SteadyUrl oneass = new SteadyUrl();

            LineDetail lineInfo = lineDetailMapper.selectByPrimaryKey(Long.valueOf(msg.get(i).getLineIndex()));
            oneass.setLineIndex(msg.get(i).getLineIndex());
            oneass.setTimeID(msg.get(i).getTimeID());
            ass = steadyUrlMapper.queryList(msg.get(i).getLineIndex(), msg.get(i).getTimeID());
            int limitnum = 0;
            if (ass != null && ass.size() > 0) {
                for (int n = 0; n < ass.size(); n++) {

                    String typename = TypeCodeEnum.getMsgByCode(ass.get(n).getTypeCode());
                    if (ass.get(n).getTypeCode() == 5) {
                        describe = describe + typename + ass.get(n).getLimitNum() * 120 + "分钟,";
                    } else {
                        describe = describe + typename + ass.get(n).getLimitNum() * lineInfo.getTInterval() + "分钟,";
                    }
                    limitnum = limitnum + ass.get(n).getLimitNum();
                }
            }

            if (describe.length() > 0) {
                describe = describe.substring(0, describe.length() - 1);
            }
            tmp.setLimitNum(limitnum);
            tmp.setDescribe(describe);
            msgs.add(tmp);
        }

        steadyMsgMapper.updateSteadyState(steadyIndex);
        return msgs;
    }

    @Override
    public List<SteadyTarget> getSteadyTarget(int lineIndex, Date timeID) {
        List<SteadyTarget> result = new ArrayList<>();

        List<SteadyUrl> ass = new ArrayList<>();
        SteadyUrl oneass = new SteadyUrl();
        oneass.setLineIndex(lineIndex);
        oneass.setTimeID(timeID);
        ass = steadyUrlMapper.queryList(lineIndex, timeID);
        if (ass != null && ass.size() > 0) {
            for (int n = 0; n < ass.size(); n++) {
                SteadyTarget tmp = new SteadyTarget();
                String typename = TypeCodeEnum.getMsgByCode(ass.get(n).getTypeCode());
                tmp.setTypeCode(Integer.valueOf(ass.get(n).getTypeCode()));
                tmp.setTypeName(typename);
                tmp.setLimieNum(ass.get(n).getLimitNum());

                result.add(tmp);
            }
        }

        return result;
    }

    @Override
    public SteadyUrl getSteadyTargetUrl(int lineIndex, Date timeID, int typeCode) {
//		List<SteadyTargetUrl> result = new ArrayList<>();
        SteadyUrl ass = new SteadyUrl();
        ass = steadyUrlMapper.queryData(lineIndex, timeID, typeCode);

        if (ass != null && ass.getSteadyPath() != null) {
            String url = ass.getSteadyPath();
            File file = new File(url);
            if (!file.exists()) {
                return null;
            }
        } else {
            return null;
        }

        return ass;
    }

    @Override
    public SteadyUrl getUrl(HttpServletRequest request, int lineIndex, Date timeID, int typeCode) {
        List<List<SteadyUrlData>> result = new ArrayList<>();
        List<SteadyUrlData> data = new ArrayList<>();
        List<SteadyUrlData> dataa = new ArrayList<>();
        List<SteadyUrlData> datab = new ArrayList<>();
        List<SteadyUrlData> datac = new ArrayList<>();
        SteadyUrl ass = new SteadyUrl();
        String type = "";
        float limit = 0;

        Calendar calendar1 = Calendar.getInstance();
        //获取某一天的0点0分0秒 或者 23点59分59秒
        calendar1.setTime(timeID);
        calendar1.set(calendar1.get(Calendar.YEAR), calendar1.get(Calendar.MONTH), calendar1.get(Calendar.DAY_OF_MONTH),
                0, 0, 0);
        Date startTime = calendar1.getTime();

        Calendar calendar2 = Calendar.getInstance();
        calendar2.setTime(timeID);
        calendar2.set(calendar2.get(Calendar.YEAR), calendar2.get(Calendar.MONTH), calendar2.get(Calendar.DAY_OF_MONTH),
                23, 59, 59);
        Date endTime = calendar2.getTime();

        OverLimit overLimit = overLimitMapper.selectByPrimaryKey(Long.valueOf(lineIndex));
        if (typeCode == TypeCodeEnum.FREQ_DEV_OVERTIME.getCode()) {
            data = steadyUrlDataMapper.getFreqDev(lineIndex, startTime, endTime);
            type = "频率偏差";
            limit = overLimit.getFreqDev();
            result.add(data);
        } else if (typeCode == TypeCodeEnum.VOLTAGE_DEV_OVERTIME.getCode()) {
            dataa = steadyUrlDataMapper.getVUDev(lineIndex, startTime, endTime, "A");
            datab = steadyUrlDataMapper.getVUDev(lineIndex, startTime, endTime, "B");
            datac = steadyUrlDataMapper.getVUDev(lineIndex, startTime, endTime, "C");
            type = "电压偏差";
            limit = overLimit.getVoltageDev();
            result.add(dataa);
            result.add(datab);
            result.add(datac);
        } else if (typeCode == TypeCodeEnum.UBALANCE_OVERTIME.getCode()) {
            data = steadyUrlDataMapper.getVUnbalance(lineIndex, startTime, endTime);
            type = "电压不平衡";
            limit = overLimit.getUbalance();
            result.add(data);
        } else if (typeCode == TypeCodeEnum.FLICKER_OVERTIME.getCode()) {
            dataa = steadyUrlDataMapper.getPLT(lineIndex, startTime, endTime, "A");
            datab = steadyUrlDataMapper.getPLT(lineIndex, startTime, endTime, "B");
            datac = steadyUrlDataMapper.getPLT(lineIndex, startTime, endTime, "C");
            type = "长闪";
            limit = overLimit.getFlicker();
            result.add(dataa);
            result.add(datab);
            result.add(datac);
        } else if (typeCode == TypeCodeEnum.UABERRANCE_OVERTIME.getCode()) {
            dataa = steadyUrlDataMapper.getVTHD(lineIndex, startTime, endTime, "A");
            datab = steadyUrlDataMapper.getVTHD(lineIndex, startTime, endTime, "B");
            datac = steadyUrlDataMapper.getVTHD(lineIndex, startTime, endTime, "C");
            type = "电压谐波畸变率";
            limit = overLimit.getUaberrance();
            result.add(dataa);
            result.add(datab);
            result.add(datac);
        } else if (typeCode == TypeCodeEnum.UHARM_2_OVERTIME.getCode()) {
            dataa = steadyUrlDataMapper.getVHarmRate(lineIndex, startTime, endTime, "2", "A");
            datab = steadyUrlDataMapper.getVHarmRate(lineIndex, startTime, endTime, "2", "B");
            datac = steadyUrlDataMapper.getVHarmRate(lineIndex, startTime, endTime, "2", "C");
            type = "2次电压谐波含有率";
            limit = overLimit.getUharm_2();
            result.add(dataa);
            result.add(datab);
            result.add(datac);
        } else if (typeCode == TypeCodeEnum.UHARM_3_OVERTIME.getCode()) {
            dataa = steadyUrlDataMapper.getVHarmRate(lineIndex, startTime, endTime, "3", "A");
            datab = steadyUrlDataMapper.getVHarmRate(lineIndex, startTime, endTime, "3", "B");
            datac = steadyUrlDataMapper.getVHarmRate(lineIndex, startTime, endTime, "3", "C");
            type = "3次电压谐波含有率";
            limit = overLimit.getUharm_3();
            result.add(dataa);
            result.add(datab);
            result.add(datac);
        } else if (typeCode == TypeCodeEnum.UHARM_4_OVERTIME.getCode()) {
            dataa = steadyUrlDataMapper.getVHarmRate(lineIndex, startTime, endTime, "4", "A");
            datab = steadyUrlDataMapper.getVHarmRate(lineIndex, startTime, endTime, "4", "B");
            datac = steadyUrlDataMapper.getVHarmRate(lineIndex, startTime, endTime, "4", "C");
            type = "4次电压谐波含有率";
            limit = overLimit.getUharm_4();
            result.add(dataa);
            result.add(datab);
            result.add(datac);
        } else if (typeCode == TypeCodeEnum.UHARM_5_OVERTIME.getCode()) {
            dataa = steadyUrlDataMapper.getVHarmRate(lineIndex, startTime, endTime, "5", "A");
            datab = steadyUrlDataMapper.getVHarmRate(lineIndex, startTime, endTime, "5", "B");
            datac = steadyUrlDataMapper.getVHarmRate(lineIndex, startTime, endTime, "5", "C");
            type = "5次电压谐波含有率";
            limit = overLimit.getUharm_5();
            result.add(dataa);
            result.add(datab);
            result.add(datac);
        } else if (typeCode == TypeCodeEnum.UHARM_6_OVERTIME.getCode()) {
            dataa = steadyUrlDataMapper.getVHarmRate(lineIndex, startTime, endTime, "6", "A");
            datab = steadyUrlDataMapper.getVHarmRate(lineIndex, startTime, endTime, "6", "B");
            datac = steadyUrlDataMapper.getVHarmRate(lineIndex, startTime, endTime, "6", "C");
            type = "6次电压谐波含有率";
            limit = overLimit.getUharm_6();
            result.add(dataa);
            result.add(datab);
            result.add(datac);
        } else if (typeCode == TypeCodeEnum.UHARM_7_OVERTIME.getCode()) {
            dataa = steadyUrlDataMapper.getVHarmRate(lineIndex, startTime, endTime, "7", "A");
            datab = steadyUrlDataMapper.getVHarmRate(lineIndex, startTime, endTime, "7", "B");
            datac = steadyUrlDataMapper.getVHarmRate(lineIndex, startTime, endTime, "7", "C");
            type = "7次电压谐波含有率";
            limit = overLimit.getUharm_7();
            result.add(dataa);
            result.add(datab);
            result.add(datac);
        } else if (typeCode == TypeCodeEnum.UHARM_8_OVERTIME.getCode()) {
            dataa = steadyUrlDataMapper.getVHarmRate(lineIndex, startTime, endTime, "8", "A");
            datab = steadyUrlDataMapper.getVHarmRate(lineIndex, startTime, endTime, "8", "B");
            datac = steadyUrlDataMapper.getVHarmRate(lineIndex, startTime, endTime, "8", "C");
            type = "8次电压谐波含有率";
            limit = overLimit.getUharm_8();
            result.add(dataa);
            result.add(datab);
            result.add(datac);
        } else if (typeCode == TypeCodeEnum.UHARM_9_OVERTIME.getCode()) {
            dataa = steadyUrlDataMapper.getVHarmRate(lineIndex, startTime, endTime, "9", "A");
            datab = steadyUrlDataMapper.getVHarmRate(lineIndex, startTime, endTime, "9", "B");
            datac = steadyUrlDataMapper.getVHarmRate(lineIndex, startTime, endTime, "9", "C");
            type = "9次电压谐波含有率";
            limit = overLimit.getUharm_9();
            result.add(dataa);
            result.add(datab);
            result.add(datac);
        } else if (typeCode == TypeCodeEnum.UHARM_10_OVERTIME.getCode()) {
            dataa = steadyUrlDataMapper.getVHarmRate(lineIndex, startTime, endTime, "10", "A");
            datab = steadyUrlDataMapper.getVHarmRate(lineIndex, startTime, endTime, "10", "B");
            datac = steadyUrlDataMapper.getVHarmRate(lineIndex, startTime, endTime, "10", "C");
            type = "10次电压谐波含有率";
            limit = overLimit.getUharm_10();
            result.add(dataa);
            result.add(datab);
            result.add(datac);
        } else if (typeCode == TypeCodeEnum.UHARM_11_OVERTIME.getCode()) {
            dataa = steadyUrlDataMapper.getVHarmRate(lineIndex, startTime, endTime, "11", "A");
            datab = steadyUrlDataMapper.getVHarmRate(lineIndex, startTime, endTime, "11", "B");
            datac = steadyUrlDataMapper.getVHarmRate(lineIndex, startTime, endTime, "11", "C");
            type = "11次电压谐波含有率";
            limit = overLimit.getUharm_11();
            result.add(dataa);
            result.add(datab);
            result.add(datac);
        } else if (typeCode == TypeCodeEnum.UHARM_12_OVERTIME.getCode()) {
            dataa = steadyUrlDataMapper.getVHarmRate(lineIndex, startTime, endTime, "12", "A");
            datab = steadyUrlDataMapper.getVHarmRate(lineIndex, startTime, endTime, "12", "B");
            datac = steadyUrlDataMapper.getVHarmRate(lineIndex, startTime, endTime, "12", "C");
            type = "12次电压谐波含有率";
            limit = overLimit.getUharm_12();
            result.add(dataa);
            result.add(datab);
            result.add(datac);
        } else if (typeCode == TypeCodeEnum.UHARM_13_OVERTIME.getCode()) {
            dataa = steadyUrlDataMapper.getVHarmRate(lineIndex, startTime, endTime, "13", "A");
            datab = steadyUrlDataMapper.getVHarmRate(lineIndex, startTime, endTime, "13", "B");
            datac = steadyUrlDataMapper.getVHarmRate(lineIndex, startTime, endTime, "13", "C");
            type = "13次电压谐波含有率";
            limit = overLimit.getUharm_13();
            result.add(dataa);
            result.add(datab);
            result.add(datac);
        } else if (typeCode == TypeCodeEnum.UHARM_14_OVERTIME.getCode()) {
            dataa = steadyUrlDataMapper.getVHarmRate(lineIndex, startTime, endTime, "14", "A");
            datab = steadyUrlDataMapper.getVHarmRate(lineIndex, startTime, endTime, "14", "B");
            datac = steadyUrlDataMapper.getVHarmRate(lineIndex, startTime, endTime, "14", "C");
            type = "14次电压谐波含有率";
            limit = overLimit.getUharm_14();
            result.add(dataa);
            result.add(datab);
            result.add(datac);
        } else if (typeCode == TypeCodeEnum.UHARM_15_OVERTIME.getCode()) {
            dataa = steadyUrlDataMapper.getVHarmRate(lineIndex, startTime, endTime, "15", "A");
            datab = steadyUrlDataMapper.getVHarmRate(lineIndex, startTime, endTime, "15", "B");
            datac = steadyUrlDataMapper.getVHarmRate(lineIndex, startTime, endTime, "15", "C");
            type = "15次电压谐波含有率";
            limit = overLimit.getUharm_15();
            result.add(dataa);
            result.add(datab);
            result.add(datac);
        } else if (typeCode == TypeCodeEnum.UHARM_16_OVERTIME.getCode()) {
            dataa = steadyUrlDataMapper.getVHarmRate(lineIndex, startTime, endTime, "16", "A");
            datab = steadyUrlDataMapper.getVHarmRate(lineIndex, startTime, endTime, "16", "B");
            datac = steadyUrlDataMapper.getVHarmRate(lineIndex, startTime, endTime, "16", "C");
            type = "16次电压谐波含有率";
            limit = overLimit.getUharm_16();
            result.add(dataa);
            result.add(datab);
            result.add(datac);
        } else if (typeCode == TypeCodeEnum.UHARM_17_OVERTIME.getCode()) {
            dataa = steadyUrlDataMapper.getVHarmRate(lineIndex, startTime, endTime, "17", "A");
            datab = steadyUrlDataMapper.getVHarmRate(lineIndex, startTime, endTime, "17", "B");
            datac = steadyUrlDataMapper.getVHarmRate(lineIndex, startTime, endTime, "17", "C");
            type = "17次电压谐波含有率";
            limit = overLimit.getUharm_17();
            result.add(dataa);
            result.add(datab);
            result.add(datac);
        } else if (typeCode == TypeCodeEnum.UHARM_18_OVERTIME.getCode()) {
            dataa = steadyUrlDataMapper.getVHarmRate(lineIndex, startTime, endTime, "18", "A");
            datab = steadyUrlDataMapper.getVHarmRate(lineIndex, startTime, endTime, "18", "B");
            datac = steadyUrlDataMapper.getVHarmRate(lineIndex, startTime, endTime, "18", "C");
            type = "18次电压谐波含有率";
            limit = overLimit.getUharm_18();
            result.add(dataa);
            result.add(datab);
            result.add(datac);
        } else if (typeCode == TypeCodeEnum.UHARM_19_OVERTIME.getCode()) {
            dataa = steadyUrlDataMapper.getVHarmRate(lineIndex, startTime, endTime, "19", "A");
            datab = steadyUrlDataMapper.getVHarmRate(lineIndex, startTime, endTime, "19", "B");
            datac = steadyUrlDataMapper.getVHarmRate(lineIndex, startTime, endTime, "19", "C");
            type = "19次电压谐波含有率";
            limit = overLimit.getUharm_19();
            result.add(dataa);
            result.add(datab);
            result.add(datac);
        } else if (typeCode == TypeCodeEnum.UHARM_20_OVERTIME.getCode()) {
            dataa = steadyUrlDataMapper.getVHarmRate(lineIndex, startTime, endTime, "20", "A");
            datab = steadyUrlDataMapper.getVHarmRate(lineIndex, startTime, endTime, "20", "B");
            datac = steadyUrlDataMapper.getVHarmRate(lineIndex, startTime, endTime, "20", "C");
            type = "20次电压谐波含有率";
            limit = overLimit.getUharm_20();
            result.add(dataa);
            result.add(datab);
            result.add(datac);
        } else if (typeCode == TypeCodeEnum.UHARM_21_OVERTIME.getCode()) {
            dataa = steadyUrlDataMapper.getVHarmRate(lineIndex, startTime, endTime, "21", "A");
            datab = steadyUrlDataMapper.getVHarmRate(lineIndex, startTime, endTime, "21", "B");
            datac = steadyUrlDataMapper.getVHarmRate(lineIndex, startTime, endTime, "21", "C");
            type = "21次电压谐波含有率";
            limit = overLimit.getUharm_21();
            result.add(dataa);
            result.add(datab);
            result.add(datac);
        } else if (typeCode == TypeCodeEnum.UHARM_22_OVERTIME.getCode()) {
            dataa = steadyUrlDataMapper.getVHarmRate(lineIndex, startTime, endTime, "22", "A");
            datab = steadyUrlDataMapper.getVHarmRate(lineIndex, startTime, endTime, "22", "B");
            datac = steadyUrlDataMapper.getVHarmRate(lineIndex, startTime, endTime, "22", "C");
            type = "22次电压谐波含有率";
            limit = overLimit.getUharm_22();
            result.add(dataa);
            result.add(datab);
            result.add(datac);
        } else if (typeCode == TypeCodeEnum.UHARM_23_OVERTIME.getCode()) {
            dataa = steadyUrlDataMapper.getVHarmRate(lineIndex, startTime, endTime, "23", "A");
            datab = steadyUrlDataMapper.getVHarmRate(lineIndex, startTime, endTime, "23", "B");
            datac = steadyUrlDataMapper.getVHarmRate(lineIndex, startTime, endTime, "23", "C");
            type = "23次电压谐波含有率";
            limit = overLimit.getUharm_23();
            result.add(dataa);
            result.add(datab);
            result.add(datac);
        } else if (typeCode == TypeCodeEnum.UHARM_24_OVERTIME.getCode()) {
            dataa = steadyUrlDataMapper.getVHarmRate(lineIndex, startTime, endTime, "24", "A");
            datab = steadyUrlDataMapper.getVHarmRate(lineIndex, startTime, endTime, "24", "B");
            datac = steadyUrlDataMapper.getVHarmRate(lineIndex, startTime, endTime, "24", "C");
            type = "24次电压谐波含有率";
            limit = overLimit.getUharm_24();
            result.add(dataa);
            result.add(datab);
            result.add(datac);
        } else if (typeCode == TypeCodeEnum.UHARM_25_OVERTIME.getCode()) {
            dataa = steadyUrlDataMapper.getVHarmRate(lineIndex, startTime, endTime, "25", "A");
            datab = steadyUrlDataMapper.getVHarmRate(lineIndex, startTime, endTime, "25", "B");
            datac = steadyUrlDataMapper.getVHarmRate(lineIndex, startTime, endTime, "25", "C");
            type = "25次电压谐波含有率";
            limit = overLimit.getUharm_25();
            result.add(dataa);
            result.add(datab);
            result.add(datac);
        } else if (typeCode == TypeCodeEnum.IHARM_2_OVERTIME.getCode()) {
            dataa = steadyUrlDataMapper.getIHarmPhasic(lineIndex, startTime, endTime, "2", "A");
            datab = steadyUrlDataMapper.getIHarmPhasic(lineIndex, startTime, endTime, "2", "B");
            datac = steadyUrlDataMapper.getIHarmPhasic(lineIndex, startTime, endTime, "2", "C");
            type = "2次电流谐波幅值";
            limit = overLimit.getIharm_2();
            result.add(dataa);
            result.add(datab);
            result.add(datac);
        } else if (typeCode == TypeCodeEnum.IHARM_3_OVERTIME.getCode()) {
            dataa = steadyUrlDataMapper.getIHarmPhasic(lineIndex, startTime, endTime, "3", "A");
            datab = steadyUrlDataMapper.getIHarmPhasic(lineIndex, startTime, endTime, "3", "B");
            datac = steadyUrlDataMapper.getIHarmPhasic(lineIndex, startTime, endTime, "3", "C");
            type = "3次电流谐波幅值";
            limit = overLimit.getIharm_3();
            result.add(dataa);
            result.add(datab);
            result.add(datac);
        } else if (typeCode == TypeCodeEnum.IHARM_4_OVERTIME.getCode()) {
            dataa = steadyUrlDataMapper.getIHarmPhasic(lineIndex, startTime, endTime, "4", "A");
            datab = steadyUrlDataMapper.getIHarmPhasic(lineIndex, startTime, endTime, "4", "B");
            datac = steadyUrlDataMapper.getIHarmPhasic(lineIndex, startTime, endTime, "4", "C");
            type = "4次电流谐波幅值";
            limit = overLimit.getIharm_4();
            result.add(dataa);
            result.add(datab);
            result.add(datac);
        } else if (typeCode == TypeCodeEnum.IHARM_5_OVERTIME.getCode()) {
            dataa = steadyUrlDataMapper.getIHarmPhasic(lineIndex, startTime, endTime, "5", "A");
            datab = steadyUrlDataMapper.getIHarmPhasic(lineIndex, startTime, endTime, "5", "B");
            datac = steadyUrlDataMapper.getIHarmPhasic(lineIndex, startTime, endTime, "5", "C");
            type = "5次电流谐波幅值";
            limit = overLimit.getIharm_5();
            result.add(dataa);
            result.add(datab);
            result.add(datac);
        } else if (typeCode == TypeCodeEnum.IHARM_6_OVERTIME.getCode()) {
            dataa = steadyUrlDataMapper.getIHarmPhasic(lineIndex, startTime, endTime, "6", "A");
            datab = steadyUrlDataMapper.getIHarmPhasic(lineIndex, startTime, endTime, "6", "B");
            datac = steadyUrlDataMapper.getIHarmPhasic(lineIndex, startTime, endTime, "6", "C");
            type = "6次电流谐波幅值";
            limit = overLimit.getIharm_6();
            result.add(dataa);
            result.add(datab);
            result.add(datac);
        } else if (typeCode == TypeCodeEnum.IHARM_7_OVERTIME.getCode()) {
            dataa = steadyUrlDataMapper.getIHarmPhasic(lineIndex, startTime, endTime, "7", "A");
            datab = steadyUrlDataMapper.getIHarmPhasic(lineIndex, startTime, endTime, "7", "B");
            datac = steadyUrlDataMapper.getIHarmPhasic(lineIndex, startTime, endTime, "7", "C");
            type = "7次电流谐波幅值";
            limit = overLimit.getIharm_7();
            result.add(dataa);
            result.add(datab);
            result.add(datac);
        } else if (typeCode == TypeCodeEnum.IHARM_8_OVERTIME.getCode()) {
            dataa = steadyUrlDataMapper.getIHarmPhasic(lineIndex, startTime, endTime, "8", "A");
            datab = steadyUrlDataMapper.getIHarmPhasic(lineIndex, startTime, endTime, "8", "B");
            datac = steadyUrlDataMapper.getIHarmPhasic(lineIndex, startTime, endTime, "8", "C");
            type = "8次电流谐波幅值";
            limit = overLimit.getIharm_8();
            result.add(dataa);
            result.add(datab);
            result.add(datac);
        } else if (typeCode == TypeCodeEnum.IHARM_9_OVERTIME.getCode()) {
            dataa = steadyUrlDataMapper.getIHarmPhasic(lineIndex, startTime, endTime, "9", "A");
            datab = steadyUrlDataMapper.getIHarmPhasic(lineIndex, startTime, endTime, "9", "B");
            datac = steadyUrlDataMapper.getIHarmPhasic(lineIndex, startTime, endTime, "9", "C");
            type = "9次电流谐波幅值";
            limit = overLimit.getIharm_9();
            result.add(dataa);
            result.add(datab);
            result.add(datac);
        } else if (typeCode == TypeCodeEnum.IHARM_10_OVERTIME.getCode()) {
            dataa = steadyUrlDataMapper.getIHarmPhasic(lineIndex, startTime, endTime, "10", "A");
            datab = steadyUrlDataMapper.getIHarmPhasic(lineIndex, startTime, endTime, "10", "B");
            datac = steadyUrlDataMapper.getIHarmPhasic(lineIndex, startTime, endTime, "10", "C");
            type = "10次电流谐波幅值";
            limit = overLimit.getIharm_10();
            result.add(dataa);
            result.add(datab);
            result.add(datac);
        } else if (typeCode == TypeCodeEnum.IHARM_11_OVERTIME.getCode()) {
            dataa = steadyUrlDataMapper.getIHarmPhasic(lineIndex, startTime, endTime, "11", "A");
            datab = steadyUrlDataMapper.getIHarmPhasic(lineIndex, startTime, endTime, "11", "B");
            datac = steadyUrlDataMapper.getIHarmPhasic(lineIndex, startTime, endTime, "11", "C");
            type = "11次电流谐波幅值";
            limit = overLimit.getIharm_11();
            result.add(dataa);
            result.add(datab);
            result.add(datac);
        } else if (typeCode == TypeCodeEnum.IHARM_12_OVERTIME.getCode()) {
            dataa = steadyUrlDataMapper.getIHarmPhasic(lineIndex, startTime, endTime, "12", "A");
            datab = steadyUrlDataMapper.getIHarmPhasic(lineIndex, startTime, endTime, "12", "B");
            datac = steadyUrlDataMapper.getIHarmPhasic(lineIndex, startTime, endTime, "12", "C");
            type = "12次电流谐波幅值";
            limit = overLimit.getIharm_12();
            result.add(dataa);
            result.add(datab);
            result.add(datac);
        } else if (typeCode == TypeCodeEnum.IHARM_13_OVERTIME.getCode()) {
            dataa = steadyUrlDataMapper.getIHarmPhasic(lineIndex, startTime, endTime, "13", "A");
            datab = steadyUrlDataMapper.getIHarmPhasic(lineIndex, startTime, endTime, "13", "B");
            datac = steadyUrlDataMapper.getIHarmPhasic(lineIndex, startTime, endTime, "13", "C");
            type = "13次电流谐波幅值";
            limit = overLimit.getIharm_13();
            result.add(dataa);
            result.add(datab);
            result.add(datac);
        } else if (typeCode == TypeCodeEnum.IHARM_14_OVERTIME.getCode()) {
            dataa = steadyUrlDataMapper.getIHarmPhasic(lineIndex, startTime, endTime, "14", "A");
            datab = steadyUrlDataMapper.getIHarmPhasic(lineIndex, startTime, endTime, "14", "B");
            datac = steadyUrlDataMapper.getIHarmPhasic(lineIndex, startTime, endTime, "14", "C");
            type = "14次电流谐波幅值";
            limit = overLimit.getIharm_14();
            result.add(dataa);
            result.add(datab);
            result.add(datac);
        } else if (typeCode == TypeCodeEnum.IHARM_15_OVERTIME.getCode()) {
            dataa = steadyUrlDataMapper.getIHarmPhasic(lineIndex, startTime, endTime, "15", "A");
            datab = steadyUrlDataMapper.getIHarmPhasic(lineIndex, startTime, endTime, "15", "B");
            datac = steadyUrlDataMapper.getIHarmPhasic(lineIndex, startTime, endTime, "15", "C");
            type = "15次电流谐波幅值";
            limit = overLimit.getIharm_15();
            result.add(dataa);
            result.add(datab);
            result.add(datac);
        } else if (typeCode == TypeCodeEnum.IHARM_16_OVERTIME.getCode()) {
            dataa = steadyUrlDataMapper.getIHarmPhasic(lineIndex, startTime, endTime, "16", "A");
            datab = steadyUrlDataMapper.getIHarmPhasic(lineIndex, startTime, endTime, "16", "B");
            datac = steadyUrlDataMapper.getIHarmPhasic(lineIndex, startTime, endTime, "16", "C");
            type = "16次电流谐波幅值";
            limit = overLimit.getIharm_16();
            result.add(dataa);
            result.add(datab);
            result.add(datac);
        } else if (typeCode == TypeCodeEnum.IHARM_17_OVERTIME.getCode()) {
            dataa = steadyUrlDataMapper.getIHarmPhasic(lineIndex, startTime, endTime, "17", "A");
            datab = steadyUrlDataMapper.getIHarmPhasic(lineIndex, startTime, endTime, "17", "B");
            datac = steadyUrlDataMapper.getIHarmPhasic(lineIndex, startTime, endTime, "17", "C");
            type = "17次电流谐波幅值";
            limit = overLimit.getIharm_17();
            result.add(dataa);
            result.add(datab);
            result.add(datac);
        } else if (typeCode == TypeCodeEnum.IHARM_18_OVERTIME.getCode()) {
            dataa = steadyUrlDataMapper.getIHarmPhasic(lineIndex, startTime, endTime, "18", "A");
            datab = steadyUrlDataMapper.getIHarmPhasic(lineIndex, startTime, endTime, "18", "B");
            datac = steadyUrlDataMapper.getIHarmPhasic(lineIndex, startTime, endTime, "18", "C");
            type = "18次电流谐波幅值";
            limit = overLimit.getIharm_18();
            result.add(dataa);
            result.add(datab);
            result.add(datac);
        } else if (typeCode == TypeCodeEnum.IHARM_19_OVERTIME.getCode()) {
            dataa = steadyUrlDataMapper.getIHarmPhasic(lineIndex, startTime, endTime, "19", "A");
            datab = steadyUrlDataMapper.getIHarmPhasic(lineIndex, startTime, endTime, "19", "B");
            datac = steadyUrlDataMapper.getIHarmPhasic(lineIndex, startTime, endTime, "19", "C");
            type = "19次电流谐波幅值";
            limit = overLimit.getIharm_19();
            result.add(dataa);
            result.add(datab);
            result.add(datac);
        } else if (typeCode == TypeCodeEnum.IHARM_20_OVERTIME.getCode()) {
            dataa = steadyUrlDataMapper.getIHarmPhasic(lineIndex, startTime, endTime, "20", "A");
            datab = steadyUrlDataMapper.getIHarmPhasic(lineIndex, startTime, endTime, "20", "B");
            datac = steadyUrlDataMapper.getIHarmPhasic(lineIndex, startTime, endTime, "20", "C");
            type = "20次电流谐波幅值";
            limit = overLimit.getIharm_20();
            result.add(dataa);
            result.add(datab);
            result.add(datac);
        } else if (typeCode == TypeCodeEnum.IHARM_21_OVERTIME.getCode()) {
            dataa = steadyUrlDataMapper.getIHarmPhasic(lineIndex, startTime, endTime, "21", "A");
            datab = steadyUrlDataMapper.getIHarmPhasic(lineIndex, startTime, endTime, "21", "B");
            datac = steadyUrlDataMapper.getIHarmPhasic(lineIndex, startTime, endTime, "21", "C");
            type = "21次电流谐波幅值";
            limit = overLimit.getIharm_21();
            result.add(dataa);
            result.add(datab);
            result.add(datac);
        } else if (typeCode == TypeCodeEnum.IHARM_22_OVERTIME.getCode()) {
            dataa = steadyUrlDataMapper.getIHarmPhasic(lineIndex, startTime, endTime, "22", "A");
            datab = steadyUrlDataMapper.getIHarmPhasic(lineIndex, startTime, endTime, "22", "B");
            datac = steadyUrlDataMapper.getIHarmPhasic(lineIndex, startTime, endTime, "22", "C");
            type = "22次电流谐波幅值";
            limit = overLimit.getIharm_22();
            result.add(dataa);
            result.add(datab);
            result.add(datac);
        } else if (typeCode == TypeCodeEnum.IHARM_23_OVERTIME.getCode()) {
            dataa = steadyUrlDataMapper.getIHarmPhasic(lineIndex, startTime, endTime, "23", "A");
            datab = steadyUrlDataMapper.getIHarmPhasic(lineIndex, startTime, endTime, "23", "B");
            datac = steadyUrlDataMapper.getIHarmPhasic(lineIndex, startTime, endTime, "23", "C");
            type = "23次电流谐波幅值";
            limit = overLimit.getIharm_23();
            result.add(dataa);
            result.add(datab);
            result.add(datac);
        } else if (typeCode == TypeCodeEnum.IHARM_24_OVERTIME.getCode()) {
            dataa = steadyUrlDataMapper.getIHarmPhasic(lineIndex, startTime, endTime, "24", "A");
            datab = steadyUrlDataMapper.getIHarmPhasic(lineIndex, startTime, endTime, "24", "B");
            datac = steadyUrlDataMapper.getIHarmPhasic(lineIndex, startTime, endTime, "24", "C");
            type = "24次电流谐波幅值";
            limit = overLimit.getIharm_24();
            result.add(dataa);
            result.add(datab);
            result.add(datac);
        } else if (typeCode == TypeCodeEnum.IHARM_25_OVERTIME.getCode()) {
            dataa = steadyUrlDataMapper.getIHarmPhasic(lineIndex, startTime, endTime, "25", "A");
            datab = steadyUrlDataMapper.getIHarmPhasic(lineIndex, startTime, endTime, "25", "B");
            datac = steadyUrlDataMapper.getIHarmPhasic(lineIndex, startTime, endTime, "25", "C");
            type = "25次电流谐波幅值";
            limit = overLimit.getIharm_25();
            result.add(dataa);
            result.add(datab);
            result.add(datac);
        }

        String url = "";
        if (result != null && result.size() > 0) {
            try {
                url = saveimg(request, result, String.valueOf(typeCode), timeID, lineIndex, type, limit);
            } catch (Exception e) {
                logger.error("获取url时发生异常，异常是" + e.getMessage());
            }
            ass = steadyUrlMapper.queryData(lineIndex, timeID, typeCode);
            ass.setSteadyPath(url);

            steadyUrlMapper.updateUrl(lineIndex, timeID, typeCode, url);
        }
        return ass;

    }

    /**
     * @param type
     * @param timeID
     * @return
     * @throws ClientProtocolException
     * @throws IOException
     * @throws TemplateException
     * @description:生成图片
     */
    public String saveimg(HttpServletRequest request, List<List<SteadyUrlData>> result, String type, Date timeID, int lineIndex, String typeName, float limit)
            throws Exception {
        // 变量
        List<Date> categories = new ArrayList<>();
        List<List<Float>> values = new ArrayList<>();
        List<List<Float>> valuea = new ArrayList<>();
        List<List<Float>> valueb = new ArrayList<>();
        List<List<Float>> valuec = new ArrayList<>();
        List<List<Float>> limits = new ArrayList<>();

        LineDetail detail = lineDetailMapper.selectByPrimaryKey((long) lineIndex);
        Integer pttype = detail.getPtType();

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        SimpleDateFormat sdff = new SimpleDateFormat("yyyyMMdd");
        String option = "";
        if (result.size() == 1) {
            for (SteadyUrlData tmp : result.get(0)) {
                List<Float> a = new ArrayList() {{
                    add(tmp.getTimeID().getTime());
                    add(tmp.getValue());
                }};
                values.add(a);
                List<Float> aa = new ArrayList() {{
                    add(tmp.getTimeID().getTime());
                    add(limit);
                }};
                limits.add(aa);
            }

            // 模板参数
            HashMap<String, Object> datas = new HashMap<>();
//            datas.put("categories", JSON.toJSONString(categories));
//            datas.put("values", JSON.toJSONString(values));
            datas.put("values", JSONArray.fromObject(values).toString());
            datas.put("title", typeName);
//            datas.put("limits", JSON.toJSONString(limits));
            datas.put("limits", JSONArray.fromObject(limits).toString());
            datas.put("limitname", "'限值(" + String.valueOf(limit) + ")'");

            // 生成option字符串
            option = FreemarkerUtil.generateString("option.ftl", "com/shining/cloud/template", datas);
        } else {
            for (SteadyUrlData tmpa : result.get(0)) {
                List<Float> a = new ArrayList() {{
                    add(tmpa.getTimeID().getTime());
                    add(tmpa.getValue());
                }};
                valuea.add(a);
                List<Float> aa = new ArrayList() {{
                    add(tmpa.getTimeID().getTime());
                    add(limit);
                }};
                limits.add(aa);
            }

            for (SteadyUrlData tmpb : result.get(1)) {
                List<Float> b = new ArrayList() {{
                    add(tmpb.getTimeID().getTime());
                    add(tmpb.getValue());
                }};
                valueb.add(b);
            }

            for (SteadyUrlData tmpc : result.get(2)) {
                List<Float> c = new ArrayList() {{
                    add(tmpc.getTimeID().getTime());
                    add(tmpc.getValue());
                }};
                valuec.add(c);
            }

            // 模板参数
            HashMap<String, Object> datas = new HashMap<>();
//            datas.put("categories", JSON.toJSONString(categories));
//            datas.put("valuea", JSON.toJSONString(valuea));
//            datas.put("valueb", JSON.toJSONString(valueb));
//            datas.put("valuec", JSON.toJSONString(valuec));
            datas.put("valuea", JSONArray.fromObject(valuea).toString());
            datas.put("valueb", JSONArray.fromObject(valueb).toString());
            datas.put("valuec", JSONArray.fromObject(valuec).toString());
            datas.put("title", typeName);
//            datas.put("limits", JSON.toJSONString(limits));
            datas.put("limits", JSONArray.fromObject(limits).toString());
            datas.put("limitname", "'限值(" + String.valueOf(limit) + ")'");

            // 生成option字符串
            if (typeName.lastIndexOf("电流谐波幅值") != -1) {
                option = FreemarkerUtil.generateString("option2.ftl", "com/shining/cloud/template", datas);
            } else if (pttype == 0) {
                option = FreemarkerUtil.generateString("option2.ftl", "com/shining/cloud/template", datas);
            } else if (pttype == 1) {
                option = FreemarkerUtil.generateString("option3.ftl", "com/shining/cloud/template", datas);
            } else if (pttype == 2) {
                option = FreemarkerUtil.generateString("option4.ftl", "com/shining/cloud/template", datas);
            }
        }

        // 根据option参数
        String base64 = EchartsUtil.generateEchartsBase64(option, "3003");

        String url = "";

        Properties pros = PubUtils.readProperties(getClass().getClassLoader(), "java.properties");
        url = pros.get("REPORT_PATH").toString();
        url = url + "steadyUrl";

        String path = request.getSession().getServletContext().getRealPath("/appfiles");
        path = path + File.separator + "steadyUrl";
        File tmpfile = new File(path);
        if (!tmpfile.exists()) {
            tmpfile.mkdir();
        }

        path = path + File.separator + String.valueOf(lineIndex) + "_" + sdff.format(timeID) + "_" + type + ".png";
        generateImage(base64, path);

        url = url + "/" + String.valueOf(lineIndex) + "_" + sdff.format(timeID) + "_" + type + ".png";
        return url;
    }

    public static void generateImage(String base64, String path) throws IOException {
        BASE64Decoder decoder = new BASE64Decoder();
        try (OutputStream out = new FileOutputStream(path)) {
            // 解密
            byte[] b = decoder.decodeBuffer(base64);
            for (int i = 0; i < b.length; ++i) {
                if (b[i] < 0) {
                    b[i] += 256;
                }
            }
            out.write(b);
            out.flush();
        }
    }

    // 解码base64图片，并保存
    public static String encode64Image(String imageBase64, String diskPath) {
        if (StringUtils.isBlank(imageBase64)) {
            return null;
        }
        String fileName = getRandomString(15);
        byte[] decode = org.apache.commons.codec.binary.Base64.decodeBase64(imageBase64);
        int length = decode.length;
        for (int i = 0; i < length; ++i) {
            if (decode[i] < 0) {
                decode[i] += 256;
            }
        }
        OutputStream out = null;
        try {
            out = new FileOutputStream(new File(diskPath + fileName));
            try {
                out.write(decode);
                out.flush();
            } catch (IOException e) {
                e.printStackTrace();
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } finally {
            try {
                out.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return diskPath + fileName;

    }

    // 生成图片临时文件名
    public static String getRandomString(int length) { //length表示生成字符串的长度
        String base = "abcdefghijklmnopqrstuvwxyz0123456789";
        Random random = new Random();
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < length; i++) {
            int number = random.nextInt(base.length());
            sb.append(base.charAt(number));
        }
        return sb.toString() + ".png";
    }


    @Override
    public void generateImageShun(WaveData waveData, List<WaveDataDetail> waveDataDetails, String path, String sunpath) throws Exception {
        String time = waveData.getTime();
        time = time.replace(" ", "%20");
        String title = "监测点名称：" + waveData.getLineName() + "%20发生时刻：" + time + "%20特征幅值：" + waveData.getEventValue() + "%25%20持续时间：" + waveData.getPersistTime() + "s";
        String firstPic = iWaveService.createShunTitle(title, waveDataDetails.get(0));
        String secondPic;
        if (waveDataDetails.size() == 1) {
            generateImage(firstPic, sunpath);
        } else if (waveDataDetails.size() == 2) {
            //绘制第二个电压瞬时波形图
            secondPic = iWaveService.createShun(waveDataDetails.get(1));
            String tempPath = path + File.separator;
            String picPathOne = encode64Image(firstPic, tempPath);
            String picPathTwo = encode64Image(secondPic, tempPath);
            composeImage(picPathOne, picPathTwo, sunpath);
        }
    }

    @Override
    public void generateImageRMS(WaveData waveData, List<WaveDataDetail> waveDataDetails, String path, String rmspath) throws Exception {
        String time = waveData.getTime();
        time = time.replace(" ", "%20");
        String title = "监测点名称：" + waveData.getLineName() + "%20发生时刻：" + time + "%20特征幅值：" + waveData.getEventValue() + "%25%20持续时间：" + waveData.getPersistTime() + "s";
        String firstPic = iWaveService.createRMSTitle(title, waveDataDetails.get(0));
        String secondPic;
        if (waveDataDetails.size() == 1) {
            generateImage(firstPic, rmspath);
        } else if (waveDataDetails.size() == 2) {
            //绘制第二个电压瞬时波形图
            secondPic = iWaveService.createRMS(waveDataDetails.get(1));
            String tempPath = path + File.separator;
            String picPathOne = encode64Image(firstPic, tempPath);
            String picPathTwo = encode64Image(secondPic, tempPath);
            composeImage(picPathOne, picPathTwo, rmspath);
        }
    }

    // 合成图片
    private String composeImage(String img1Path, String img2Path, String targetPath) {
        try {
            //第一张图片
            File fileOne = new File(img1Path);
            BufferedImage imageOne = ImageIO.read(fileOne);
            int width = imageOne.getWidth();
            int height = imageOne.getHeight();
            int[] imageArrayOne = new int[width * height];
            imageArrayOne = imageOne.getRGB(0, 0, width, height, imageArrayOne, 0, width);

            //第二张图片
            File fileTwo = new File(img2Path);
            BufferedImage imageTwo = ImageIO.read(fileTwo);
            int width2 = imageTwo.getWidth();
            int height2 = imageTwo.getHeight();
            int[] ImageArrayTwo = new int[width2 * height2];
            ImageArrayTwo = imageTwo.getRGB(0, 0, width, height, ImageArrayTwo, 0, width);

            //新图片
            BufferedImage imageNew = new BufferedImage(width, height * 2, BufferedImage.TYPE_INT_RGB);
            BufferedImageGraphicsConfig config = BufferedImageGraphicsConfig.getConfig(imageNew);
            imageNew = config.createCompatibleImage(width, height * 2, Transparency.TRANSLUCENT);
            imageNew.setRGB(0, 0, width, height, imageArrayOne, 0, width);
            imageNew.setRGB(0, height, width, height, ImageArrayTwo, 0, width);

            File outFile = new File(targetPath);
            ImageIO.write(imageNew, "png", outFile);
            //合成完毕后删除临时图片
            fileOne.delete();
            fileTwo.delete();
            return targetPath;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

}
