package io.renren.modules.dataSet.service.impl;

import cn.hutool.core.io.FileUtil;
import com.alibaba.fastjson.JSON;
import io.minio.MinioClient;
import io.minio.PutObjectOptions;
import io.renren.common.utils.MinIoUtils;
import io.renren.datasource.annotation.DataSource;
import io.renren.modules.dataSet.entity.DataSetDychoosedata;
import io.renren.modules.dataSet.entity.PreviewData;
import io.renren.modules.dataSet.mapper.DataSetDychoosedataMapper;
import io.renren.modules.dataSet.service.DynamicSystemService;
import io.renren.modules.job.entity.ScheduleJobEntity;
import io.renren.modules.job.service.ScheduleJobService;
import io.renren.modules.sys.dao.dataset.DataSetDyMapper;
import io.renren.modules.sys.entity.dataset.DataSetDy;
import lgh.springboot.starter.hbase.template.HBaseTemplate;
import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.CellUtil;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.*;
import org.apache.hadoop.hbase.util.Bytes;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Conditional;
import org.springframework.stereotype.Service;

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

@Service
public class DynamicSystemServiceImpl implements DynamicSystemService {


    @Autowired
    HBaseTemplate hBaseTemplate;

    private SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    @Override
    public List getEqumentHead(String hbaseTableName) {
        Map<String, String> headMap = new HashMap<>();
        Table table = null;
        try {
            table = hBaseTemplate.getConnection().getTable(TableName.valueOf(hbaseTableName));
            final Scan scan = new Scan().setLimit(1);
            final ResultScanner scanner = table.getScanner(scan);

            for (Result subEquip : scanner) {
                Cell[] var8 = subEquip.rawCells();
                int var9 = var8.length;

                for (int var10 = 0; var10 < var9; ++var10) {
                    Cell cell = var8[var10];
                    String key = Bytes.toString(CellUtil.cloneQualifier(cell));
                    String value = Bytes.toString(CellUtil.cloneValue(cell));
                    headMap.put(key, value);
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (table != null) {
                try {
                    table.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        final Set<String> strings = headMap.keySet();
        List<String> list_1 = new ArrayList<>(strings);
//        list_1.forEach(System.out::println);
        return list_1;
    }

    @Autowired
    private SubsystemServiceImpl subsystemService;

    @Override
    public List getContentTimeLimit(String hbaseTableName, Long start, Long end) {
        Connection connection = null;
        Table table = null;
//        System.out.println(hbaseTableName);
        List<Map<String, String>> equmentContextLists = new ArrayList();
        try {
            connection = hBaseTemplate.getConnection();
            table = connection.getTable(TableName.valueOf(hbaseTableName));
            Scan scan = new Scan();
            scan.setTimeRange(start, end);
            final ResultScanner subEquips = table.getScanner(scan);
            long timestamp = 0L;
            for (Result subEquip : subEquips) {
                HashMap<String, String> map = new HashMap();
                Cell[] var8 = subEquip.rawCells();
                int var9 = var8.length;
                for (int var10 = 0; var10 < var9; ++var10) {
                    Cell cell = var8[var10];
                    String key = Bytes.toString(CellUtil.cloneQualifier(cell));
                    String value = Bytes.toString(CellUtil.cloneValue(cell));
                        if (key.contains("after")) {
                            map.put(key, value);
                        }
                        if (!map.containsKey("time")) {
                            timestamp = cell.getTimestamp();
                            String ss = format.format(timestamp);
                            map.put("time", ss);
                        }



                }
                equmentContextLists.add(map);
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (table != null) {
                try {
                    table.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }

//        equmentContextLists.forEach(System.out::println);
        return equmentContextLists;
    }

    @Override
    public List getContentTimeLimit(String hbaseTableName, Integer limit, Long start, Long end) {
        Connection connection = null;
        Table table = null;
//        System.out.println(hbaseTableName);
        List<Map<String, String>> equmentContextLists = new ArrayList();
        try {
            connection = hBaseTemplate.getConnection();
            table = connection.getTable(TableName.valueOf(hbaseTableName));
            Scan scan = new Scan();
            scan.setTimeRange(start, end);
            scan.setLimit(limit);
            scan.isReversed();
            final ResultScanner subEquips = table.getScanner(scan);
            long timestamp = 0L;
            for (Result subEquip : subEquips) {
                HashMap<String, String> map = new HashMap();
                Cell[] var8 = subEquip.rawCells();
                int var9 = var8.length;
                for (int var10 = 0; var10 < var9; ++var10) {
                    Cell cell = var8[var10];
                    String key = Bytes.toString(CellUtil.cloneQualifier(cell));
                    String value = Bytes.toString(CellUtil.cloneValue(cell));
                        if (key!=null && !key.isEmpty()) {
                            map.put(key, value);
                        }
                        if (!map.containsKey("time")) {
                            timestamp = cell.getTimestamp();
                            String ss = format.format(timestamp);
                            map.put("time", ss);
                        }



                }
                equmentContextLists.add(map);
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (table != null) {
                try {
                    table.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }

//        equmentContextLists.forEach(System.out::println);
        return equmentContextLists;
    }

    @Override
    public List getEqumentHead_InMysql(Integer equipmentId) {
//        System.out.println("getEqumentHead_InMysql");
        final List<Map<String, String>> getcolumns = subsystemService.getcolumns(equipmentId);
//        for (Map<String, String> getcolumn : getcolumns) {
//            for (String o : getcolumn.keySet()) {
//                System.out.println("key:" + o + "             value : " + getcolumn.get(o));
//            }
//        }
//        System.out.println(equipmentId);
        return getcolumns;

    }

    @Override
    public List getEqumentAll(String hbaseTableName) {
        Connection connection = null;
        Table table = null;
        System.out.println(hbaseTableName);
        List<Map<String, String>> equmentContextLists = new ArrayList();
        try {
            connection = hBaseTemplate.getConnection();
            table = connection.getTable(TableName.valueOf(hbaseTableName));
            Scan scan = new Scan();
            final ResultScanner subEquips = table.getScanner(scan);
            for (Result subEquip : subEquips) {
                HashMap<String, String> map = new HashMap();
                Cell[] var8 = subEquip.rawCells();
                int var9 = var8.length;

                for (int var10 = 0; var10 < var9; ++var10) {
                    Cell cell = var8[var10];
                    String key = Bytes.toString(CellUtil.cloneQualifier(cell));
                    String value = Bytes.toString(CellUtil.cloneValue(cell));
                    if (key.contains("after") ) {
                        map.put(key, value);
                    }

                }
                equmentContextLists.add(map);
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (table != null) {
                try {
                    table.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }

//        equmentContextLists.forEach(System.out::println);
        return equmentContextLists;
    }


    @Override
    public List getEqumentLimit(String hbaseTableName, Integer limit) {
        Connection connection = null;
        Table table = null;
//        System.out.println(hbaseTableName);
        List<Map<String, String>> equmentContextLists = new ArrayList();
        try {
            connection = hBaseTemplate.getConnection();
            table = connection.getTable(TableName.valueOf(hbaseTableName));
            Scan scan = new Scan();
            scan.setLimit(limit);
            final ResultScanner subEquips = table.getScanner(scan);
            long timestamp = 0L;
            for (Result subEquip : subEquips) {
                HashMap<String, String> map = new HashMap();
                Cell[] var8 = subEquip.rawCells();
                int var9 = var8.length;
                for (int var10 = 0; var10 < var9; ++var10) {
                    Cell cell = var8[var10];
                    String key = Bytes.toString(CellUtil.cloneQualifier(cell));
                    String value = Bytes.toString(CellUtil.cloneValue(cell));
                        if (key != null || !key.isEmpty()) {
                            map.put(key, value);
                        }
                        if (!map.containsKey("time")){
                            timestamp = cell.getTimestamp();
                            String s = format.format(timestamp);
                            map.put("time",s);
                        }



                }
                if (!map.isEmpty()) equmentContextLists.add(map);
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (table != null) {
                try {
                    table.close();

                } catch (IOException e) {
                    e.printStackTrace();
                }

            }
            return equmentContextLists;
        }


    }

    @Override
    public Map<String, List<String>> getEqumentOneColumn(String hbaseTableName, String[] needFileds) {
        String[] fileds = needFileds;
        final List<Map> equmentAll = getEqumentAll(hbaseTableName);
        Map<String, List<String>> needColumnMap = new HashMap<>();
        for (String filed : fileds) {
            List<String> needOneLists = new ArrayList();
            for (Map map : equmentAll) {
                String s = null;
                try {
                    s = map.get(filed).toString();
                } catch (Exception exception) {
                    s = "NUll";
                }

                needOneLists.add(s);
            }
            needColumnMap.put(filed, needOneLists);
        }
//        for (String s : needColumnMap.keySet()) {
//            final List<String> strings = needColumnMap.get(s);
//            System.out.println("key-->"+ s + "value --->");
//            for (String string : strings) {
//                System.out.println(string);
//            }
//        }
        return needColumnMap;
    }


    @Override
    public Map<String, List<String>> getEqumentOneColumnTimeLimit(String hbaseTableName, String[] needFileds, Integer limit,Long start,Long end) {
        String[] fileds = needFileds;
        final List<Map> equmentAll = getContentTimeLimit(hbaseTableName, limit,start,end);
        Map<String, List<String>> needColumnMap = new HashMap<>();
        if (equmentAll.size() == 0) return needColumnMap;
        for (String filed : fileds) {
            List<String> needOneLists = new ArrayList();
            for (Map map : equmentAll) {
                String s = null;
                try {
                    s = map.get(filed).toString();
                } catch (Exception exception) {
                    s = "NUll";
                }

                needOneLists.add(s);
            }
            needColumnMap.put(filed, needOneLists);
        }
        return needColumnMap;
    }

    @Override
    public Map<String, List<String>> getEqumentOneColumn(String hbaseTableName, String[] needFileds, Integer limit) {
        String[] fileds = needFileds;
        final List<Map> equmentAll = getEqumentLimit(hbaseTableName, limit);
        Map<String, List<String>> needColumnMap = new HashMap<>();
        for (String filed : fileds) {
            List<String> needOneLists = new ArrayList();
            for (Map map : equmentAll) {
                String s = null;
                try {
                    s = map.get(filed).toString();
                } catch (Exception exception) {
                    s = "NUll";
                }

                needOneLists.add(s);
            }
            needColumnMap.put(filed, needOneLists);
        }
        return needColumnMap;
    }

    @Override
    public List getPreContent(List<PreviewData> subeqpments, Integer limit) {
        Integer sign = 0;
        List<Map> listMapSum = new ArrayList<>();
        for (PreviewData subeqpment : subeqpments) {
            String subEquipmentID = subeqpment.getSubEquipmentID();
            String hbaseTableName = subeqpment.getHbaseTableName();
            final String[] chosedatas = subeqpment.getChosedata();

            final Map<String, List<String>> equmentOneColumn = getEqumentOneColumn(hbaseTableName, chosedatas, limit);
            for (String chosedata : chosedatas) {
                final List<String> strings = equmentOneColumn.get(chosedata);
                int max = Math.min(10,strings.size());
                for (int i = 0; i < max; i++) {
                    final String s = strings.get(i);
                    final HashMap<String, Object> clumData = new HashMap<>();
                    clumData.put(subEquipmentID + "_" + chosedata, s);
                    if (sign < max) {
                        listMapSum.add(clumData);
                    } else {
                        final Map map = listMapSum.get(sign % max);
                        map.putAll(clumData);
                        listMapSum.set(sign % max, map);
                    }
                    sign++;
                }
            }

        }
        return listMapSum;
    }

    @Override
    public List getPreContentTimeLimit(List<PreviewData> subeqpments, Integer limit,Long start,Long end) {
        Integer sign = 0;
        List<Map> listMapSum = new ArrayList<>();
        for (PreviewData subeqpment : subeqpments) {
            String subEquipmentID = subeqpment.getSubEquipmentID();
            String hbaseTableName = subeqpment.getHbaseTableName();
            final String[] chosedatas = subeqpment.getChosedata();

            final Map<String, List<String>> equmentOneColumn = getEqumentOneColumnTimeLimit(hbaseTableName, chosedatas, limit,start,end);
            for (String chosedata : chosedatas) {
                final List<String> strings = equmentOneColumn.get(chosedata);
                int max = Math.min(10,strings.size());
                for (int i = 0; i < max; i++) {
                    final String s = strings.get(i);
                    final HashMap<String, Object> clumData = new HashMap<>();
                    clumData.put(subEquipmentID + "_" + chosedata, s);
                    if (sign < max) {
                        listMapSum.add(clumData);
                    } else {
                        final Map map = listMapSum.get(sign % max);
                        map.putAll(clumData);
                        listMapSum.set(sign % max, map);
                    }
                    sign++;
                }
            }

        }
        return listMapSum;
    }

    @Override
    public String runSave(Map map) {
        String s = runSave_coal(map);
        Date date = new Date();
        SimpleDateFormat ft = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
        String info = "";
        if(s.equals("done")){
            info  = ft.format(date) + "  设备名称 ：" + (String) map.get("equipment") + "." + map.get("subEquipment")
                    + "  抽取字段：" + map.get("chosedata") + "  抽取成功!!";
        }else {
            info = s;
        }

        Map<String, String> redata = new HashMap<>();
        redata.put("info", info);
        return JSON.toJSONString(redata);
    }

    public String runSave_coal(Map map) {
        StringBuilder s = new StringBuilder();
        String hbaseTableName = (String) map.get("hbaseTableName");
        if (hbaseTableName.length()==0|| "".equals(hbaseTableName)) return "数据源为空！！！";
        List choosedatas = (List<String>) map.get("chosedata");
        if(choosedatas.size() ==0) return "请选择字段！！！";
        String newFileName = (String) map.get("newFileName");
        String oldFileName = (String) map.get("oldFileName");
//        System.out.println(oldFileName+"--->"+newFileName);
        final String userID = map.get("userID").toString();
        // path 文件保存路径 需要改四次  本类三次  StaticSystemServiceImpl 一次
        String path = System.getProperty("user.dir") + File.separator + "csv" + File.separator + userID;  // 文件路径  记得后面的dySubmit也要改
        // 判断上传路径是否存在
        if (!FileUtil.exist(path)) {
            FileUtil.mkdir(path);
        }
        String filed = new String();
        List<String> fileds = new ArrayList<>();

        String[] chooseDates = (String[]) choosedatas.toArray(new String[choosedatas.size()]);
        Long start = (Long) map.getOrDefault("start",0l);
        Long end = (Long) map.getOrDefault("end",new Date().getTime());
        final Map<String, List<String>> equmentOneColumn = getEqumentOneColumnTimeLimit(hbaseTableName, chooseDates, 1000,start,end);
        if (equmentOneColumn.isEmpty()) return "数据为空,请检查数据源中是否有数据！！";
        for (int i = 0; i < choosedatas.size(); i++) {
            filed = (String) choosedatas.get(i);
            // 添加表头
            if (i == 0) {
                fileds.add(filed);
            } else {
                fileds.set(0, fileds.get(0) + "," + filed);
            }
            final List<String> columns = equmentOneColumn.get(filed);
//            List<Subeqpdemo> subeqpdemos = subeqpdemoMapper.getSelectFiled(hbaseTableName, filed);
            int size = columns.size();
            for (int j = 0; j < size; j++) {
                String str = JSON.toJSONString(columns.get(j)).replaceAll("\\{|\\}", "");
                // 判断数据库中的数据是否为空
                if (str != null && !str.isEmpty()) {
                    if (i == 0) {
                        fileds.add(str);
                    } else {
                        fileds.set(j + 1, fileds.get(j + 1) + "," + str);
                    }

                } else {
                    if (i == 0) {
                        fileds.add("null");
                    } else {
                        fileds.set(j + 1, fileds.get(j + 1) + "," + "null");
                    }
                }
            }

        }


        final File file = new File(path);
        if (!file.isDirectory() && !file.exists()) {
            file.mkdirs();
        }

        File creatFileName = new File(path, oldFileName + ".csv");
        if (!creatFileName.exists()) {
            try {
                creatCSV(creatFileName, fileds);
            } catch (IOException e) {
                e.printStackTrace();
            }
        } else {
            try {
                addColumn(creatFileName, fileds, newFileName + ".csv", userID);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return "done";
    }

    // 首次创建csv文件
    public String creatCSV(File creatFileName, List<String> fileds) throws IOException {
        BufferedWriter bw = null;
        final String lineSep = System.getProperty("line.separator");
        try {

            bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(creatFileName)));
            for (String filed : fileds) {
                bw.write(filed + lineSep);
            }

        } catch (Exception e) {
            System.out.println(e);
        } finally {
            if (bw != null)
                bw.close();
        }
        return "666";

    }

    //向上一步制作的csv文件中添加列数据
    public String addColumn(File oldfileName, List<String> fileds, String newFileName, String userId) throws IOException {
        String path = System.getProperty("user.dir") + File.separator + "csv" + File.separator + userId;
        BufferedReader br = null;
        BufferedWriter bw = null;
        final String lineSep = System.getProperty("line.separator");
        File newFile = null;
        try {
            newFile = new File(path, newFileName);//so the names don't conflict or just use different folders
            br = new BufferedReader(new InputStreamReader(new FileInputStream(oldfileName)));
            bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(newFile)));
            String line = "";
            int i = 0;
            Integer maxlen = 0; // 补齐前面的数据
            Integer addlenMax = 0;

            for (line = br.readLine(); line != null || i < fileds.size(); line = br.readLine(), i++) {
                String addedColumn = "";
                Integer addlen = 0;
                if (i >= fileds.size()) {
                    for (Integer iteger = 0; iteger < addlenMax; iteger++) {
                        if (iteger == 0) {
                            addedColumn = "null";
                        } else {
                            addedColumn = addedColumn + "," + "null";
                        }

                    }
                } else {
                    addedColumn = String.valueOf(fileds.get(i));
                    addlen = addedColumn.split(",").length;
                    if (addlen > addlenMax) {
                        addlenMax = addlen;
                    }
                }

                String newColumn = "";
                Integer len = 0;
                if (line != null) {
                    len = line.split(",").length;
                    if (len > maxlen) {
                        maxlen = len;    // 解决行数不足问题
                    }
                    if (len < maxlen) {
                        for (Integer integer = len; integer < maxlen - 1; integer++) {
                            line = line + "," + "null";
                        }
                    }
                } else {
                    if (len < maxlen) {
                        for (Integer integer = len; integer < maxlen - 1; integer++) {
                            line = line + "," + "null";
                        }
                    }
                }

                newColumn = line + "," + addedColumn + lineSep;

                bw.write(newColumn);
            }

        } catch (Exception e) {
            System.out.println(e);
        } finally {
            if (br != null)
                br.close();
            if (bw != null)
                bw.close();
        }
        oldfileName.delete();
        return newFile.getAbsolutePath();
    }

    @Override
    public String dySubmit(Map map) {
        //文件重命名
        String oldname = (String) map.get("oldname");
        String datasetName = (String) map.get("datasetName");
//        String extractionPeriod =(String) map.get("extractionPeriod");
//        String extractioNumber =(String) map.get("extractioNumber");
        String userId = map.get("userID").toString();
//        Integer sign = (Integer)map.get("sign");
        String path = System.getProperty("user.dir") + File.separator + "csv" + File.separator + userId;
        File oldFileName = new File(path, oldname + ".csv");
        File newFileName = new File(path, datasetName + ".csv");
        if (newFileName != null || newFileName.toString().length() != 0) {
            try {
                boolean a = oldFileName.renameTo(newFileName);
            } catch (Exception e) {
                System.out.println(e);
            }
            try {
                PutObjectOptions putObjectOptions = new PutObjectOptions(newFileName.length(), PutObjectOptions.MIN_MULTIPART_SIZE);
                MinIoUtils.uploadLocalFile("dydataset", newFileName.getName(), newFileName.getAbsolutePath(), putObjectOptions);
                //  删除本地数据文件
                FileUtil.del(newFileName);
            } catch (Exception e) {
                System.out.println(e);
            }

        }
        List<Map> list = (ArrayList) map.get("imsql");

        /*
        第一步：保存用户选择的字段，返回保存后的ID dySubmit_sava_choosedateSQL
        第二步：保存CRON表达式，同时设置Params为上一步的ID，最后返回job添加完成后的ID dySubmit_sava_jobSQL
        第三部：保存数据集 dySubmit_sava
         */
        Integer chooseDataSavaID = dySubmit_sava_choosedateSQL(list);

        // 存储动态数据集合定时文物
        Long jobID = dySubmit_sava_jobSQL(map, chooseDataSavaID);

        dySubmit_sava(map, chooseDataSavaID, jobID);
        return "111";
    }

    private void dySubmit_sava(Map map, Integer chooseDataSavaID, Long jobID) {
        //        Integer extractioNumber =Integer.parseInt((String) map.get("extractioNumber") );
        Long userID = Long.parseLong(map.get("userID").toString());

        DataSetDy dataSetDy = new DataSetDy();
        dataSetDy.setDatasetName((String) map.get("datasetName"));
        dataSetDy.setDatasetStatus(2);
        dataSetDy.setCategoryId(Long.parseLong(map.get("classification").toString()));
//        dataSetDy.setRemark((String) map.get("remarks"));
//        dataSetDy.setExtractionTimes(extractioNumber);
        dataSetDy.setUid(userID);
        dataSetDy.setRemark(map.get("remarks").toString());
        dataSetDy.setCreateTime(new Date());
        dataSetDy.setJobId(jobID);
        dataSetDy.setChooseDataId(Long.parseLong(chooseDataSavaID.toString()));
        dataSetDyMapper.insert(dataSetDy);
    }

    @Autowired
    private ScheduleJobService scheduleJobService;
    @Autowired
    DataSetDyMapper dataSetDyMapper;

    public Long dySubmit_sava_jobSQL(Map map, Integer chooseDataSavaID) {

        String extractionPeriod = (String) map.get("extractionPeriod");
        ScheduleJobEntity scheduleJobEntity = new ScheduleJobEntity();
        scheduleJobEntity.setCronExpression(extractionPeriod);
//        scheduleJobEntity.setParams(choose);
        scheduleJobEntity.setBeanName("demo1");
        scheduleJobEntity.setParams(chooseDataSavaID.toString());
        scheduleJobService.saveJob(scheduleJobEntity);
        return scheduleJobEntity.getJobId();

    }

    @Autowired
    DataSetDychoosedataMapper dataSetDychoosedataMapper;

    private Integer dySubmit_sava_choosedateSQL(List<Map> list) {

        /*
         整理前台传输过来的数据
            整理前：imsql=[{id=0, coal=, system=, subsystem=, equipment=子系统1设备1, subEquipment=设备1子设备1, subEquipmentID=1, hbaseTableName=subeqpdemo, userID=, chosedata=[serialNumber, needMeasuringPoint], oldFileName=1_1_0, newFileName=1_1_0}, {id=1, coal=, system=, subsystem=, equipment=子系统1设备1, subEquipment=设备1子设备2, subEquipmentID=2, hbaseTableName=subeqpdemo1, userID=, chosedata=[serialNumber, equipment], oldFileName=1_1_0, newFileName=1_sum}]
            整理后：subeqpdemo:serialNumber,needMeasuringPoint;subeqpdemo1:serialNumber,equipment;
         */
        String sumChooseFiled = "";
        for (Map map1 : list) {
            String hbaseTableName = map1.get("hbaseTableName").toString();
            sumChooseFiled = sumChooseFiled + hbaseTableName + ":";
            List<String> chosedata = (List<String>) map1.get("chosedata");
            for (int i = 0; i < chosedata.size(); i++) {
                if (i == chosedata.size() - 1) {
                    sumChooseFiled = sumChooseFiled + chosedata.get(i);
                } else {
                    sumChooseFiled = sumChooseFiled + chosedata.get(i) + ",";
                }
            }
            sumChooseFiled = sumChooseFiled + ";";
        }
        DataSetDychoosedata dataSetDychoosedata = new DataSetDychoosedata();

        dataSetDychoosedata.setChooseData(sumChooseFiled);
        dataSetDychoosedata.setCreatTime(new Date());
        dataSetDychoosedataMapper.insert(dataSetDychoosedata);
//        dataSetDyMapper.insert()
        return dataSetDychoosedata.getId();
    }
}
