Przeglądaj źródła

0821 麻了 不想写了 订正了一些bug

allen 3 lat temu
rodzic
commit
b55cc5a834

+ 19 - 1
src/main/java/io/renren/modules/dataSet/controller/DynamicSystemController.java

@@ -1,5 +1,6 @@
 package io.renren.modules.dataSet.controller;
 
+import com.alibaba.fastjson.JSON;
 import io.renren.common.utils.R;
 import io.renren.modules.dataSet.entity.PreviewData;
 import io.renren.modules.dataSet.service.DynamicSystemService;
@@ -7,6 +8,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.web.bind.annotation.*;
 
+import java.util.Date;
 import java.util.List;
 import java.util.Map;
 
@@ -29,18 +31,34 @@ public class DynamicSystemController {
 
         return R.ok().put("hbaseTableHeaders",hbaseTableHeaders);
     }
+
     @PostMapping("/getContent")
     public  R getContent(@RequestBody Map map){
         final List equmentAll = dynamicSystemService.getEqumentLimit( map.get("hbaseTableName").toString(),100);
         return R.ok().put("equmentAll",equmentAll);
     }
+
     @RequestMapping("getprecontent")
     public R getPrecontent(@RequestBody List<PreviewData> subeqpments){
         final List preContent = dynamicSystemService.getPreContent(subeqpments,100);
-        preContent.forEach(System.out::println);
+//        preContent.forEach(System.out::println);
+        return R.ok().put("preContent",preContent);
+    }
+
+    @RequestMapping("getprecontentlimit")
+    public R getPrecontentTimeLimit(@RequestBody Map<String, Object> map){
+        List<PreviewData> subeqpments = (List<PreviewData>) map.get("data");
+        String s = JSON.toJSONString(subeqpments);
+        subeqpments = JSON.parseArray(s, PreviewData.class);
+
+        Long start  = (Long) map.getOrDefault("start",0l);
+        Long end  = (Long) map.getOrDefault("end",new Date().getTime());
+        final List preContent = dynamicSystemService.getPreContentTimeLimit(subeqpments,100,start,end);;
         return R.ok().put("preContent",preContent);
     }
 
+
+
     @RequestMapping("makeDyDataSet")
     public  String makeDyDataSet(@RequestBody Map map){
 //        System.out.println("===================");

+ 12 - 4
src/main/java/io/renren/modules/dataSet/service/DynamicSystemService.java

@@ -12,15 +12,23 @@ public interface DynamicSystemService {
 
     public List getEqumentAll(String hbaseTableName);
 
-    public List getEqumentLimit(String hbaseTableName,Integer limit);
+    public List getEqumentLimit(String hbaseTableName, Integer limit);
 
-    public Map<String, List<String>> getEqumentOneColumn(String hbaseTableName,String[] needFileds);
+    public Map<String, List<String>> getEqumentOneColumn(String hbaseTableName, String[] needFileds);
 
-    public Map<String, List<String>> getEqumentOneColumn(String hbaseTableName,String[] needFileds,Integer limit);
+    public Map<String, List<String>> getEqumentOneColumn(String hbaseTableName, String[] needFileds, Integer limit);
 
-    public List getPreContent(List<PreviewData> subeqpments,Integer limit);
+    public Map<String, List<String>> getEqumentOneColumnTimeLimit(String hbaseTableName, String[] needFileds, Integer limit,Long start,Long end);
+
+    public List getPreContent(List<PreviewData> subeqpments, Integer limit);
+
+    public List getPreContentTimeLimit(List<PreviewData> subeqpments, Integer limit,Long start,Long end);
 
     public String runSave(Map map);
 
     public String dySubmit(Map map);
+
+    public List getContentTimeLimit(String hbaseName, Long start, Long end);
+
+    public List getContentTimeLimit(String hbaseName, Integer limit, Long start, Long end);
 }

+ 3 - 0
src/main/java/io/renren/modules/dataSet/service/StaticSystemService.java

@@ -1,7 +1,9 @@
 package io.renren.modules.dataSet.service;
 
+import io.renren.modules.dataSet.entity.PreviewData;
 import org.springframework.stereotype.Service;
 
+import java.util.List;
 import java.util.Map;
 
 
@@ -9,4 +11,5 @@ import java.util.Map;
 public interface StaticSystemService {
     public String runStaticSave(Map map);
     public Boolean stSubmit(Map map);
+
 }

+ 287 - 124
src/main/java/io/renren/modules/dataSet/service/impl/DynamicSystemServiceImpl.java

@@ -24,6 +24,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
 import java.io.*;
+import java.text.ParseException;
 import java.text.SimpleDateFormat;
 import java.util.*;
 
@@ -32,6 +33,9 @@ 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<>();
@@ -45,7 +49,7 @@ public class DynamicSystemServiceImpl implements DynamicSystemService {
                 Cell[] var8 = subEquip.rawCells();
                 int var9 = var8.length;
 
-                for(int var10 = 0; var10 < var9; ++var10) {
+                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));
@@ -54,8 +58,8 @@ public class DynamicSystemServiceImpl implements DynamicSystemService {
             }
         } catch (IOException e) {
             e.printStackTrace();
-        }finally {
-            if(table != null){
+        } finally {
+            if (table != null) {
                 try {
                     table.close();
                 } catch (IOException e) {
@@ -72,15 +76,115 @@ public class DynamicSystemServiceImpl implements DynamicSystemService {
     @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.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 getEqumentHead_InMysql(Integer equipmentId) {
         System.out.println("getEqumentHead_InMysql");
-        final List<Map<String,String>> getcolumns = subsystemService.getcolumns(equipmentId);
-        for (Map<String,String> getcolumn : getcolumns) {
+        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("key:" + o + "             value : " + getcolumn.get(o));
             }
         }
         System.out.println(equipmentId);
@@ -89,26 +193,26 @@ public class DynamicSystemServiceImpl implements DynamicSystemService {
     }
 
     @Override
-    public List  getEqumentAll(String hbaseTableName){
+    public List getEqumentAll(String hbaseTableName) {
         Connection connection = null;
         Table table = null;
         System.out.println(hbaseTableName);
-        List<Map<String,String>> equmentContextLists = new ArrayList();
+        List<Map<String, String>> equmentContextLists = new ArrayList();
         try {
-            connection= hBaseTemplate.getConnection();
+            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();
+                HashMap<String, String> map = new HashMap();
                 Cell[] var8 = subEquip.rawCells();
                 int var9 = var8.length;
 
-                for(int var10 = 0; var10 < var9; ++var10) {
+                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")){
+                    if (key.contains("after")) {
                         map.put(key, value);
                     }
 
@@ -117,8 +221,8 @@ public class DynamicSystemServiceImpl implements DynamicSystemService {
             }
         } catch (IOException e) {
             e.printStackTrace();
-        }finally {
-            if(table != null){
+        } finally {
+            if (table != null) {
                 try {
                     table.close();
                 } catch (IOException e) {
@@ -131,38 +235,44 @@ public class DynamicSystemServiceImpl implements DynamicSystemService {
         return equmentContextLists;
     }
 
+
     @Override
-    public List  getEqumentLimit(String hbaseTableName,Integer limit){
+    public List getEqumentLimit(String hbaseTableName, Integer limit) {
         Connection connection = null;
         Table table = null;
 //        System.out.println(hbaseTableName);
-        List<Map<String,String>> equmentContextLists = new ArrayList();
+        List<Map<String, String>> equmentContextLists = new ArrayList();
         try {
-            connection= hBaseTemplate.getConnection();
+            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();
+                HashMap<String, String> map = new HashMap();
                 Cell[] var8 = subEquip.rawCells();
                 int var9 = var8.length;
-
-                for(int var10 = 0; var10 < var9; ++var10) {
+                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")){
+                    if (key.contains("after")) {
                         map.put(key, value);
                     }
+                    if (!map.containsKey("time")){
+                        timestamp = cell.getTimestamp();
+                        String s = format.format(timestamp);
+                        map.put("time",s);
+                    }
 
                 }
                 equmentContextLists.add(map);
             }
         } catch (IOException e) {
             e.printStackTrace();
-        }finally {
-            if(table != null){
+        } finally {
+            if (table != null) {
                 try {
                     table.close();
                 } catch (IOException e) {
@@ -174,24 +284,25 @@ public class DynamicSystemServiceImpl implements DynamicSystemService {
 //        equmentContextLists.forEach(System.out::println);
         return equmentContextLists;
     }
+
     @Override
-    public Map<String, List<String>> getEqumentOneColumn(String hbaseTableName,String[] needFileds){
+    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<>();
+        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 = map.get(filed).toString();
+                } catch (Exception exception) {
                     s = "NUll";
                 }
 
                 needOneLists.add(s);
             }
-            needColumnMap.put(filed,needOneLists);
+            needColumnMap.put(filed, needOneLists);
         }
 //        for (String s : needColumnMap.keySet()) {
 //            final List<String> strings = needColumnMap.get(s);
@@ -205,35 +316,51 @@ public class DynamicSystemServiceImpl implements DynamicSystemService {
 
 
     @Override
-    public Map<String, List<String>> getEqumentOneColumn(String hbaseTableName,String[] needFileds,Integer limit){
+    public Map<String, List<String>> getEqumentOneColumnTimeLimit(String hbaseTableName, String[] needFileds, Integer limit,Long start,Long end) {
         String[] fileds = needFileds;
-        final List<Map> equmentAll = getEqumentLimit(hbaseTableName,limit);
-        Map<String,List<String>> needColumnMap = new HashMap<>();
+        final List<Map> equmentAll = getContentTimeLimit(hbaseTableName, limit,start,end);
+        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 = map.get(filed).toString();
+                } catch (Exception exception) {
                     s = "NUll";
                 }
 
                 needOneLists.add(s);
             }
-            needColumnMap.put(filed,needOneLists);
+            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);
         }
-//        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 List getPreContent(List<PreviewData> subeqpments,Integer limit) {
+    public List getPreContent(List<PreviewData> subeqpments, Integer limit) {
         Integer sign = 0;
         List<Map> listMapSum = new ArrayList<>();
         for (PreviewData subeqpment : subeqpments) {
@@ -241,19 +368,50 @@ public class DynamicSystemServiceImpl implements DynamicSystemService {
             String hbaseTableName = subeqpment.getHbaseTableName();
             final String[] chosedatas = subeqpment.getChosedata();
 
-            final Map<String, List<String>> equmentOneColumn = getEqumentOneColumn(hbaseTableName, chosedatas,limit);
+            final Map<String, List<String>> equmentOneColumn = getEqumentOneColumn(hbaseTableName, chosedatas, limit);
             for (String chosedata : chosedatas) {
                 final List<String> strings = equmentOneColumn.get(chosedata);
                 for (int i = 0; i < 10; i++) {
                     final String s = strings.get(i);
                     final HashMap<String, Object> clumData = new HashMap<>();
-                    clumData.put(subEquipmentID+ "_" +chosedata ,s);
-                    if(sign<10){
+                    clumData.put(subEquipmentID + "_" + chosedata, s);
+                    if (sign < 10) {
                         listMapSum.add(clumData);
-                    }else {
+                    } else {
                         final Map map = listMapSum.get(sign % 10);
                         map.putAll(clumData);
-                        listMapSum.set(sign%10,map);
+                        listMapSum.set(sign % 10, 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);
+                for (int i = 0; i < 10; i++) {
+                    final String s = strings.get(i);
+                    final HashMap<String, Object> clumData = new HashMap<>();
+                    clumData.put(subEquipmentID + "_" + chosedata, s);
+                    if (sign < 10) {
+                        listMapSum.add(clumData);
+                    } else {
+                        final Map map = listMapSum.get(sign % 10);
+                        map.putAll(clumData);
+                        listMapSum.set(sign % 10, map);
                     }
                     sign++;
                 }
@@ -270,36 +428,38 @@ public class DynamicSystemServiceImpl implements DynamicSystemService {
         SimpleDateFormat ft = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
         String info = ft.format(date) + "  设备名称 :" + (String) map.get("equipment") + "." + map.get("subEquipment")
                 + "  抽取字段:" + map.get("chosedata") + "  抽取成功!!";
-        Map<String,String> redata  =new HashMap<>();
-        redata.put("info",info);
+        Map<String, String> redata = new HashMap<>();
+        redata.put("info", info);
         return JSON.toJSONString(redata);
     }
 
     public void runSave_coal(Map map) {
         String hbaseTableName = (String) map.get("hbaseTableName");
         List choosedatas = (List<String>) map.get("chosedata");
-        String newFileName  = (String) map.get("newFileName") ;
-        String oldFileName = (String)map.get("oldFileName");
+        String newFileName = (String) map.get("newFileName");
+        String oldFileName = (String) map.get("oldFileName");
 //        System.out.println(oldFileName+"--->"+newFileName);
-        final String userID =  map.get("userID").toString();
+        final String userID = map.get("userID").toString();
         // path 文件保存路径 需要改四次  本类三次  StaticSystemServiceImpl 一次
-        String path  = System.getProperty("user.dir")+ File.separator+"csv" + File.separator + userID;  // 文件路径  记得后面的dySubmit也要改
+        String path = System.getProperty("user.dir") + File.separator + "csv" + File.separator + userID;  // 文件路径  记得后面的dySubmit也要改
         // 判断上传路径是否存在
-        if (!FileUtil.exist(path)){
+        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()]);
-        final Map<String, List<String>> equmentOneColumn = getEqumentOneColumn(hbaseTableName, chooseDates,1000);
+        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);
         for (int i = 0; i < choosedatas.size(); i++) {
             filed = (String) choosedatas.get(i);
             // 添加表头
-            if(i==0){
+            if (i == 0) {
                 fileds.add(filed);
-            }else {
-                fileds.set(0,fileds.get(0) +","+ filed);
+            } else {
+                fileds.set(0, fileds.get(0) + "," + filed);
             }
             final List<String> columns = equmentOneColumn.get(filed);
 //            List<Subeqpdemo> subeqpdemos = subeqpdemoMapper.getSelectFiled(hbaseTableName, filed);
@@ -308,17 +468,17 @@ public class DynamicSystemServiceImpl implements DynamicSystemService {
                 String str = JSON.toJSONString(columns.get(j)).replaceAll("\\{|\\}", "");
                 // 判断数据库中的数据是否为空
                 if (str != null && !str.isEmpty()) {
-                    if(i==0){
+                    if (i == 0) {
                         fileds.add(str);
-                    }else {
-                        fileds.set(j+1,fileds.get(j+1) +","+ str);
+                    } else {
+                        fileds.set(j + 1, fileds.get(j + 1) + "," + str);
                     }
 
                 } else {
-                    if(i==0){
+                    if (i == 0) {
                         fileds.add("null");
-                    }else {
-                        fileds.set(j+1,fileds.get(j+1) +","+ "null");
+                    } else {
+                        fileds.set(j + 1, fileds.get(j + 1) + "," + "null");
                     }
                 }
             }
@@ -327,29 +487,30 @@ public class DynamicSystemServiceImpl implements DynamicSystemService {
 
 
         final File file = new File(path);
-        if(!file.isDirectory() && !file.exists()){
+        if (!file.isDirectory() && !file.exists()) {
             file.mkdirs();
         }
 
-        File creatFileName = new File(path,oldFileName+ ".csv");
+        File creatFileName = new File(path, oldFileName + ".csv");
         if (!creatFileName.exists()) {
             try {
                 creatCSV(creatFileName, fileds);
             } catch (IOException e) {
                 e.printStackTrace();
             }
-        }else {
+        } else {
             try {
-                addColumn(creatFileName,fileds,newFileName+ ".csv",userID);
+                addColumn(creatFileName, fileds, newFileName + ".csv", userID);
             } catch (IOException e) {
                 e.printStackTrace();
             }
         }
     }
+
     // 首次创建csv文件
-    public String creatCSV(File creatFileName,List<String> fileds )throws IOException{
-        BufferedWriter bw=null;
-        final String lineSep=System.getProperty("line.separator");
+    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)));
@@ -357,83 +518,83 @@ public class DynamicSystemServiceImpl implements DynamicSystemService {
                 bw.write(filed + lineSep);
             }
 
-        }catch (Exception e){
+        } catch (Exception e) {
             System.out.println(e);
-        }finally {
-            if(bw!=null)
+        } 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");
+    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))) ;
+            br = new BufferedReader(new InputStreamReader(new FileInputStream(oldfileName)));
             bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(newFile)));
             String line = "";
-            int i=0;
+            int i = 0;
             Integer maxlen = 0; // 补齐前面的数据
             Integer addlenMax = 0;
 
-            for ( line = br.readLine(); line != null || i < fileds.size(); line = br.readLine(),i++)
-            {
+            for (line = br.readLine(); line != null || i < fileds.size(); line = br.readLine(), i++) {
                 String addedColumn = "";
                 Integer addlen = 0;
-                if(i >= fileds.size()){
+                if (i >= fileds.size()) {
                     for (Integer iteger = 0; iteger < addlenMax; iteger++) {
-                        if(iteger == 0){
+                        if (iteger == 0) {
                             addedColumn = "null";
-                        }else {
-                            addedColumn = addedColumn+","+ "null";
+                        } else {
+                            addedColumn = addedColumn + "," + "null";
                         }
 
                     }
-                }else {
+                } else {
                     addedColumn = String.valueOf(fileds.get(i));
                     addlen = addedColumn.split(",").length;
-                    if(addlen>addlenMax){
+                    if (addlen > addlenMax) {
                         addlenMax = addlen;
                     }
                 }
 
                 String newColumn = "";
                 Integer len = 0;
-                if(line != null){
+                if (line != null) {
                     len = line.split(",").length;
-                    if(len > maxlen){
+                    if (len > maxlen) {
                         maxlen = len;    // 解决行数不足问题
                     }
-                    if(len<maxlen){
-                        for (Integer integer = len; integer < maxlen-1; integer++) {
-                            line = line +","+ "null";
+                    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";
+                } else {
+                    if (len < maxlen) {
+                        for (Integer integer = len; integer < maxlen - 1; integer++) {
+                            line = line + "," + "null";
                         }
                     }
                 }
 
-                newColumn = line+","+addedColumn+lineSep;
+                newColumn = line + "," + addedColumn + lineSep;
 
                 bw.write(newColumn);
             }
 
-        }catch(Exception e){
+        } catch (Exception e) {
             System.out.println(e);
-        }finally  {
-            if(br!=null)
+        } finally {
+            if (br != null)
                 br.close();
-            if(bw!=null)
+            if (bw != null)
                 bw.close();
         }
         oldfileName.delete();
@@ -441,34 +602,34 @@ public class DynamicSystemServiceImpl implements DynamicSystemService {
     }
 
     @Override
-    public String dySubmit(Map map){
+    public String dySubmit(Map map) {
         //文件重命名
-        String oldname =(String) map.get("oldname");
-        String datasetName =(String) map.get("datasetName");
+        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();
+        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){
+        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){
+            } 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);
+                MinIoUtils.uploadLocalFile("dydataset", newFileName.getName(), newFileName.getAbsolutePath(), putObjectOptions);
                 //  删除本地数据文件
                 FileUtil.del(newFileName);
-            }catch (Exception e){
+            } catch (Exception e) {
                 System.out.println(e);
             }
 
         }
-        List<Map> list = (ArrayList)map.get("imsql");
+        List<Map> list = (ArrayList) map.get("imsql");
 
         /*
         第一步:保存用户选择的字段,返回保存后的ID dySubmit_sava_choosedateSQL
@@ -480,13 +641,13 @@ public class DynamicSystemServiceImpl implements DynamicSystemService {
         // 存储动态数据集合定时文物
         Long jobID = dySubmit_sava_jobSQL(map, chooseDataSavaID);
 
-        dySubmit_sava(map,chooseDataSavaID,jobID);
+        dySubmit_sava(map, chooseDataSavaID, jobID);
         return "111";
     }
 
-    private void dySubmit_sava(Map map, Integer chooseDataSavaID,Long jobID) {
+    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());
+        Long userID = Long.parseLong(map.get("userID").toString());
 
         DataSetDy dataSetDy = new DataSetDy();
         dataSetDy.setDatasetName((String) map.get("datasetName"));
@@ -506,9 +667,10 @@ public class DynamicSystemServiceImpl implements DynamicSystemService {
     private ScheduleJobService scheduleJobService;
     @Autowired
     DataSetDyMapper dataSetDyMapper;
-    public Long dySubmit_sava_jobSQL(Map map, Integer chooseDataSavaID){
 
-        String extractionPeriod =(String) map.get("extractionPeriod");
+    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);
@@ -521,6 +683,7 @@ public class DynamicSystemServiceImpl implements DynamicSystemService {
 
     @Autowired
     DataSetDychoosedataMapper dataSetDychoosedataMapper;
+
     private Integer dySubmit_sava_choosedateSQL(List<Map> list) {
 
         /*
@@ -534,13 +697,13 @@ public class DynamicSystemServiceImpl implements DynamicSystemService {
             sumChooseFiled = sumChooseFiled + hbaseTableName + ":";
             List<String> chosedata = (List<String>) map1.get("chosedata");
             for (int i = 0; i < chosedata.size(); i++) {
-                if(i == chosedata.size() -1){
+                if (i == chosedata.size() - 1) {
                     sumChooseFiled = sumChooseFiled + chosedata.get(i);
-                }else {
-                    sumChooseFiled = sumChooseFiled + chosedata.get(i)+ ",";
+                } else {
+                    sumChooseFiled = sumChooseFiled + chosedata.get(i) + ",";
                 }
             }
-            sumChooseFiled = sumChooseFiled+ ";";
+            sumChooseFiled = sumChooseFiled + ";";
         }
         DataSetDychoosedata dataSetDychoosedata = new DataSetDychoosedata();
 

+ 34 - 25
src/main/java/io/renren/modules/dataSet/service/impl/StaticSystemServiceImpl.java

@@ -5,17 +5,25 @@ import com.alibaba.excel.EasyExcel;
 import com.alibaba.fastjson.JSON;
 import io.minio.PutObjectOptions;
 import io.renren.common.utils.MinIoUtils;
+import io.renren.modules.dataSet.entity.PreviewData;
 import io.renren.modules.dataSet.service.StaticSystemService;
 import io.renren.modules.dataSet.upload.NoModelDataListener_pre;
 import io.renren.modules.dataSet.upload.UpLoadService;
 import io.renren.modules.sys.dao.dataset.DataSetMapper;
 import io.renren.modules.sys.entity.dataset.DataSet;
+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.checkerframework.checker.units.qual.A;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
 import java.io.File;
 import java.io.IOException;
+import java.text.ParseException;
 import java.text.SimpleDateFormat;
 import java.util.*;
 
@@ -28,22 +36,23 @@ public class StaticSystemServiceImpl implements StaticSystemService {
 
     @Autowired
     UpLoadService upLoadService;
+
     @Override
-    public String runStaticSave(Map onemap)   {
+    public String runStaticSave(Map onemap) {
         Map onemap1 = (Map) onemap.get("st_imsql");
         System.out.println(onemap1);
 //        {oldname=1_stsum, choosedata={id=0, userID=1, sql=[string_title, number_title], upUrl=E:\test\615\renren-fast\aupload\demo 1.xlsx}}
         Boolean onlyStatic = (Boolean) onemap.get("onlyStatic");
         final String id = onemap1.get("id").toString();
         final String userID = onemap1.get("userID").toString();
-        final String[] sqls = onemap1.get("sql").toString().replaceAll("\\[|\\]","").split(", ");
+        final String[] sqls = onemap1.get("sql").toString().replaceAll("\\[|\\]", "").split(", ");
         final String upUrl = onemap1.get("upUrl").toString();
         final String oldname = onemap1.get("oldFileName").toString();
         final String lastNewFileName = onemap1.get("newFileName").toString();
         final String type = onemap1.get("type").toString();
-        String path  = System.getProperty("user.dir")+ File.separator+"csv" + File.separator + userID;
+        String path = System.getProperty("user.dir") + File.separator + "csv" + File.separator + userID;
         // 判断上传路径是否存在
-        if (!FileUtil.exist(path)){
+        if (!FileUtil.exist(path)) {
             FileUtil.mkdir(path);
         }
 
@@ -53,16 +62,14 @@ public class StaticSystemServiceImpl implements StaticSystemService {
             EasyExcel.read(upUrl, noModelDataListener_pre).doReadAll();
             allList = noModelDataListener_pre.getAllList();
         } else if ("word".equals(type)) {
-            allList = upLoadService.readWithCsvMapReaderColumns(upUrl,sqls,false);
+            allList = upLoadService.readWithCsvMapReaderColumns(upUrl, sqls, false);
         } else {
             allList = new ArrayList<>();
         }
 
 
-
-
-        String oldFileName =path+   File.separator + oldname+".csv";
-        String newFileName ="";
+        String oldFileName = path + File.separator + oldname + ".csv";
+        String newFileName = "";
         for (String sql : sqls) {
             List<String> fileds = new ArrayList<>();
             newFileName = userID + sql; // 不需要设置根路径 已经在 addColumn 中设置了
@@ -74,37 +81,38 @@ public class StaticSystemServiceImpl implements StaticSystemService {
 
             // 数据集不使用系统数据
             final File oldFileNamefile = new File(oldFileName);
-            if (onlyStatic){
+            if (onlyStatic) {
                 try {
-                    dynamicSystemService.creatCSV(oldFileNamefile,fileds);
+                    dynamicSystemService.creatCSV(oldFileNamefile, fileds);
                     onlyStatic = false;
                 } catch (IOException e) {
                     e.printStackTrace();
                 }
-            }else {
+            } else {
                 // 数据集使用系统数据
                 try {
-                    dynamicSystemService.addColumn(oldFileNamefile,fileds,newFileName,userID);
+                    dynamicSystemService.addColumn(oldFileNamefile, fileds, newFileName, userID);
                 } catch (IOException e) {
                     e.printStackTrace();
                 }
-                oldFileName = path + File.separator+newFileName;
+                oldFileName = path + File.separator + newFileName;
             }
 
 
         }
 
-        new File(oldFileName).renameTo(new File(path ,lastNewFileName + ".csv" ));
+        new File(oldFileName).renameTo(new File(path, lastNewFileName + ".csv"));
         Date date = new Date();
         SimpleDateFormat ft = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
-        String info = ft.format(date) + "  本地文件 :" +  onemap1.get("fileName").toString() + "   "
-                + "  抽取字段:" + onemap1.get("sql") .toString()+ "  抽取成功!!";
+        String info = ft.format(date) + "  本地文件 :" + onemap1.get("fileName").toString() + "   "
+                + "  抽取字段:" + onemap1.get("sql").toString() + "  抽取成功!!";
         return info;
     }
 
 
     @Autowired
     DataSetMapper dataSetMapper;
+
     @Override
     public Boolean stSubmit(Map map) {
         System.out.println(map);
@@ -112,13 +120,13 @@ public class StaticSystemServiceImpl implements StaticSystemService {
         final String userId = map.get("userId").toString();
         final String datasetName = map.get("datasetName").toString();
 
-        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){
+        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 {
-                 oldFileName.renameTo(newFileName);
-            }catch (Exception e){
+                oldFileName.renameTo(newFileName);
+            } catch (Exception e) {
                 System.out.println(e);
             }
         }
@@ -135,13 +143,14 @@ public class StaticSystemServiceImpl implements StaticSystemService {
 
         try {
             PutObjectOptions putObjectOptions = new PutObjectOptions(newFileName.length(), PutObjectOptions.MIN_MULTIPART_SIZE);
-            MinIoUtils.uploadLocalFile("dataset",newFileName.getName(),newFileName.getAbsolutePath(),putObjectOptions);
+            MinIoUtils.uploadLocalFile("dataset", newFileName.getName(), newFileName.getAbsolutePath(), putObjectOptions);
             //  删除本地数据文件
             FileUtil.del(newFileName);
-        }catch (Exception e){
+        } catch (Exception e) {
             System.out.println(e);
         }
         return true;
     }
 
+
 }

+ 4 - 4
src/main/resources/application-dev.yml

@@ -5,8 +5,8 @@ spring:
             driver-class-name: com.mysql.cj.jdbc.Driver
             url: jdbc:mysql://localhost:3306/renren_fast?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&useSSL=false&allowPublicKeyRetrieval=true
             username: root
-            password: 123456
-#            password: root
+#            password: 123456
+            password: root
             initial-size: 10
             max-active: 100
             min-idle: 10
@@ -44,8 +44,8 @@ dynamic:
         url: jdbc:mysql://localhost:3306/hebing?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&useSSL=false&allowPublicKeyRetrieval=true
         username: root
 #      password: XDUbdm520Mysql
-#        password: root
-        password: 123456
+        password: root
+#        password: 123456
         driver-class-name: com.mysql.jdbc.Driver # 3.2.0开始支持SPI可省略此配置
 server:
     port: 8082

+ 19 - 8
src/test/java/io/renren/DynamicDataSourceTest.java

@@ -8,6 +8,7 @@
 
 package io.renren;
 
+import io.renren.modules.dataSet.service.StaticSystemService;
 import io.renren.service.DynamicDataSourceTestService;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -15,6 +16,10 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.test.context.SpringBootTest;
 import org.springframework.test.context.junit4.SpringRunner;
 
+import javax.xml.crypto.Data;
+import java.util.Date;
+import java.util.List;
+
 /**
  * 多数据源测试
  *
@@ -23,16 +28,22 @@ import org.springframework.test.context.junit4.SpringRunner;
 @RunWith(SpringRunner.class)
 @SpringBootTest
 public class DynamicDataSourceTest {
-    @Autowired
-    private DynamicDataSourceTestService dynamicDataSourceTestService;
+//    @Autowired
+//    private DynamicDataSourceTestService dynamicDataSourceTestService;
+//
+//    @Test
+//    public void test(){
+//        Long id = 1L;
+//
+//        dynamicDataSourceTestService.updateUser(id);
+//        dynamicDataSourceTestService.updateUserBySlave1(id);
+//        dynamicDataSourceTestService.updateUserBySlave2(id);
+//    }
 
+    @Autowired
+    StaticSystemService staticSystemService;
     @Test
-    public void test(){
-        Long id = 1L;
+    public void text(){
 
-        dynamicDataSourceTestService.updateUser(id);
-        dynamicDataSourceTestService.updateUserBySlave1(id);
-        dynamicDataSourceTestService.updateUserBySlave2(id);
     }
-
 }