Browse Source

版本回退

This reverts commit 3012a47dd1eab393b9488ebea641abb1d0a93947.
chenw 6 years ago
parent
commit
c873780d56

+ 146 - 0
bi-core/src/main/java/com/usoftchina/bi/core/utils/CollectionUtils.java

@@ -0,0 +1,146 @@
+package com.usoftchina.bi.core.utils;
+
+import com.google.common.collect.HashBasedTable;
+import com.google.common.collect.Lists;
+import com.google.common.collect.Sets;
+import com.google.common.collect.Table;
+
+import java.util.*;
+import java.util.function.Function;
+
+/**
+ * @author ChenWei
+ * @date 2019/04/22
+ */
+public abstract class CollectionUtils extends org.springframework.util.CollectionUtils {
+    /**
+     * 按指定方法,将list分组返回map
+     *
+     * @param sources
+     * @param keyGetter
+     * @param <K>
+     * @param <V>
+     * @return
+     */
+    public static <K, V> Map<K, List<V>> groupBy(List<V> sources, Function<V, K> keyGetter) {
+        Map<K, List<V>> map = new HashMap<>(1);
+        if (!isEmpty(sources)) {
+            sources.forEach(source -> {
+                K key = keyGetter.apply(source);
+                if (map.containsKey(key)) {
+                    map.get(key).add(source);
+                } else {
+                    List<V> childList = new ArrayList<>();
+                    childList.add(source);
+                    map.put(key, childList);
+                }
+            });
+        }
+        return map;
+    }
+
+    /**
+     * 按两个指定方法,将list分组返回复合键map
+     *
+     * @param sources
+     * @param rKeyGetter
+     * @param cKeyGetter
+     * @param <R>
+     * @param <C>
+     * @param <V>
+     * @return
+     */
+    public static <R, C, V> Table<R, C, List<V>> groupBy(List<V> sources, Function<V, R> rKeyGetter, Function<V, C> cKeyGetter) {
+        Table<R, C, List<V>> table = HashBasedTable.create();
+        if (!isEmpty(sources)) {
+            sources.forEach(source -> {
+                R r = rKeyGetter.apply(source);
+                C c = cKeyGetter.apply(source);
+                if (table.contains(r, c)) {
+                    table.get(r, c).add(source);
+                } else {
+                    List<V> childList = new ArrayList<>();
+                    childList.add(source);
+                    table.put(r, c, childList);
+                }
+            });
+        }
+        return table;
+    }
+
+    /**
+     * 按三个指定方法,将list分组返回复合键map
+     *
+     * @param sources
+     * @param rKeyGetter
+     * @param cKeyGetter
+     * @param valueGetter
+     * @param <R>
+     * @param <C>
+     * @param <V>
+     * @param <S>
+     * @return
+     */
+    public static <R, C, V, S> Map<R, Map<C, List<V>>> groupBy(List<S> sources, Function<S, R> rKeyGetter, Function<S, C> cKeyGetter, Function<S, V> valueGetter) {
+        Map<R, Map<C, List<V>>> table = new HashMap<>(1);
+        if (!isEmpty(sources)) {
+            sources.forEach(source -> {
+                R r = rKeyGetter.apply(source);
+                C c = cKeyGetter.apply(source);
+                V v = valueGetter.apply(source);
+
+                if (table.containsKey(r)) {
+                    Map<C, List<V>> rows = table.get(r);
+                    if (rows.containsKey(c)) {
+                        rows.get(c).add(v);
+                    } else {
+                        rows.put(c, Lists.newArrayList(v));
+                    }
+                } else {
+                    Map<C, List<V>> rows = new HashMap<>(1);
+                    rows.put(c, Lists.newArrayList(v));
+                    table.put(r, rows);
+                }
+            });
+        }
+        return table;
+    }
+
+    /**
+     * 按三个指定方法,将list分组返回复合键map
+     *
+     * @param sources
+     * @param rKeyGetter
+     * @param cKeyGetter
+     * @param valueGetter
+     * @param <R>
+     * @param <C>
+     * @param <V>
+     * @param <S>
+     * @return
+     */
+    public static <R, C, V, S> Map<R, Map<C, Set<V>>> distinctBy(List<S> sources, Function<S, R> rKeyGetter, Function<S, C> cKeyGetter, Function<S, V> valueGetter) {
+        Map<R, Map<C, Set<V>>> table = new HashMap<>(1);
+        if (!isEmpty(sources)) {
+            sources.forEach(source -> {
+                R r = rKeyGetter.apply(source);
+                C c = cKeyGetter.apply(source);
+                V v = valueGetter.apply(source);
+
+                if (table.containsKey(r)) {
+                    Map<C, Set<V>> rows = table.get(r);
+                    if (rows.containsKey(c)) {
+                        rows.get(c).add(v);
+                    } else {
+                        rows.put(c, Sets.newHashSet(v));
+                    }
+                } else {
+                    Map<C, Set<V>> rows = new HashMap<>(1);
+                    rows.put(c, Sets.newHashSet(v));
+                    table.put(r, rows);
+                }
+            });
+        }
+        return table;
+    }
+}

+ 1 - 5
bi-core/src/main/java/com/usoftchina/bi/core/utils/GetTokenDataUtil.java

@@ -11,7 +11,6 @@ import org.springframework.stereotype.Component;
 import java.io.UnsupportedEncodingException;
 import java.util.HashMap;
 import java.util.Map;
-import java.util.Set;
 
 public class GetTokenDataUtil {
     //公共密钥
@@ -34,10 +33,7 @@ public class GetTokenDataUtil {
         }
         Map<String, Claim> claimMap = jwt.getClaims();
         Map<String, String> resultMap = new HashMap<String, String>();
-        Set<String> keySet = claimMap.keySet();
-        for (String key : keySet) {
-            resultMap.put(key, String.valueOf(claimMap.get(key)));
-        }
+        claimMap.forEach((k,v) -> resultMap.put(k, v.asString()));
         return resultMap;
     }
 }

+ 2 - 2
bi-server/src/main/java/com/usoftchina/bi/server/service/chart/ChartsConfigService.java

@@ -262,7 +262,7 @@ public class ChartsConfigService {
         List<GroupInfo> addGroupInfoList = new ArrayList<>();
         List<GroupInfo> deleteGroupInfoList = new ArrayList<>();
         List<GroupInfo> updateGroupInfoList = new ArrayList<>();
-        for (GroupInfo groupInfo : groupInfoList) {
+        groupInfoList.forEach(groupInfo -> {
             if ("add".equals(groupInfo.getOperate())) {
                 addGroupInfoList.add(groupInfo);
             }else if ("delete".equals(groupInfo.getOperate())) {
@@ -270,7 +270,7 @@ public class ChartsConfigService {
             }else if ("update".equals(groupInfo.getOperate())) {
                 updateGroupInfoList.add(groupInfo);
             }
-        }
+        });
         if (addGroupInfoList.size() > 0) {
             messageLogService.save("图表分组", null, username, "批量创建图表分组");
             chartsConfigMapper.batchInsertCharts(addGroupInfoList);

+ 7 - 25
bi-server/src/main/java/com/usoftchina/bi/server/service/chart/ShowLineService.java

@@ -3,6 +3,7 @@ package com.usoftchina.bi.server.service.chart;
 import com.usoftchina.bi.core.base.RepCode;
 import com.usoftchina.bi.core.base.RepEntity;
 import com.usoftchina.bi.core.utils.CalculationJudgeUtil;
+import com.usoftchina.bi.core.utils.CollectionUtils;
 import com.usoftchina.bi.server.dao.chart.ChartsConfigMapper;
 import com.usoftchina.bi.server.dao.chart.ShowChartsMapper;
 import com.usoftchina.bi.server.model.bo.*;
@@ -10,11 +11,14 @@ import com.usoftchina.bi.server.model.vo.configVo.LineConfigInfo;
 import com.usoftchina.bi.server.model.vo.dataVo.ChartsDataInfo;
 import com.usoftchina.bi.core.jdbc.DynamicDataSourceContextHolder;
 import com.usoftchina.bi.server.utils.ScreenUtil;
+import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
-import org.springframework.util.CollectionUtils;
 
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
 
 @Service
 public class ShowLineService {
@@ -141,7 +145,7 @@ public class ShowLineService {
                 String groupsName = (String)itGroupsData.next();
 
                 List<LineSeriesGroupMap> lineSeriesGroupMapList = showChartsMapper.getGroupsValuesTime(yAxisType, yColumn, tableName, groupByName, groupsName, xColumn, "'YYYY-MM-DD'");
-                Map<String, List<LineSeriesGroupMap>> lineSeriesGroupMap = groupBy(lineSeriesGroupMapList);
+                Map<String, List<LineSeriesGroupMap>> lineSeriesGroupMap = CollectionUtils.groupBy(lineSeriesGroupMapList, LineSeriesGroupMap::getGroup);
                 Iterator<Map.Entry<String, List<LineSeriesGroupMap>>> it = lineSeriesGroupMap.entrySet().iterator();
                 List<LineSeriesMap> lineSeriesMapList = null;
                 while (it.hasNext()) {
@@ -168,28 +172,6 @@ public class ShowLineService {
         return new RepEntity(RepCode.success, chartsDataInfo);
     }
 
-    /**
-     * 分组
-     * @param sources
-     * @return
-     */
-    private Map<String, List<LineSeriesGroupMap>> groupBy(List<LineSeriesGroupMap> sources){
-        Map<String, List<LineSeriesGroupMap>> map = new HashMap<>(1);
-        if (!CollectionUtils.isEmpty(sources)) {
-            for (LineSeriesGroupMap source : sources) {
-                String key = source.getGroup();
-                if (map.containsKey(key)) {
-                    map.get(key).add(source);
-                }else {
-                    List<LineSeriesGroupMap> childList = new ArrayList<>();
-                    childList.add(source);
-                    map.put(key, childList);
-                }
-            }
-        }
-        return map;
-    }
-
     /**
      * LineSeriesGroupMap 转 LineSeriesMap
      * @param source

+ 2 - 2
bi-server/src/main/java/com/usoftchina/bi/server/service/dataSource/DataConnectorService.java

@@ -278,7 +278,7 @@ public class DataConnectorService {
         List<GroupInfo> addGroupInfoList = new ArrayList<>();
         List<GroupInfo> deleteGroupInfoList = new ArrayList<>();
         List<GroupInfo> updateGroupInfoList = new ArrayList<>();
-        for (GroupInfo groupInfo : groupInfoList) {
+        groupInfoList.forEach(groupInfo -> {
             if ("add".equals(groupInfo.getOperate())) {
                 addGroupInfoList.add(groupInfo);
             }else if ("delete".equals(groupInfo.getOperate())) {
@@ -286,7 +286,7 @@ public class DataConnectorService {
             }else if ("update".equals(groupInfo.getOperate())) {
                 updateGroupInfoList.add(groupInfo);
             }
-        }
+        });
         if (addGroupInfoList.size() > 0) {
             messageLogService.save("数据源分组", null, username, "批量新增数据源分组");
             dataConnectorMapper.batchInsertDataConnector(addGroupInfoList);

+ 26 - 55
bi-server/src/main/java/com/usoftchina/bi/server/utils/ScreenUtil.java

@@ -8,13 +8,11 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
 import java.io.IOException;
-import java.text.SimpleDateFormat;
 import java.time.DayOfWeek;
 import java.time.LocalDate;
 import java.time.format.DateTimeFormatter;
 import java.time.temporal.TemporalAdjusters;
 import java.util.ArrayList;
-import java.util.Calendar;
 import java.util.Iterator;
 import java.util.List;
 
@@ -176,75 +174,50 @@ public class ScreenUtil {
      */
     private String TimeFormat(String value){
         String formatValue = "";
-        Calendar calendar = Calendar.getInstance();
-        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
+        LocalDate localDate = LocalDate.now();
         switch (value) {
             case "today" :
-                formatValue = simpleDateFormat.format(calendar.getTime());
+                formatValue = localDate.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
                 break;
             case "yesterday" :
-                calendar.add(Calendar.DAY_OF_MONTH, -1);
-                formatValue = simpleDateFormat.format(calendar.getTime());
+                formatValue = localDate.plusDays(-1).format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
                 break;
             case "week" :
-                calendar.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
-                formatValue = simpleDateFormat.format(calendar.getTime()) + ",";
-                calendar.set(Calendar.DAY_OF_WEEK, Calendar.SATURDAY);
-                formatValue += simpleDateFormat.format(calendar.getTime());
+                formatValue = localDate.plusWeeks(0).with(DayOfWeek.MONDAY).format(DateTimeFormatter.ofPattern("yyyy-MM-dd")) + ","
+                        + localDate.plusWeeks(0).with(DayOfWeek.SUNDAY).format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
                 break;
             case "lastweek" :
-                calendar.add(Calendar.WEEK_OF_YEAR, -1);
-                calendar.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
-                formatValue = simpleDateFormat.format(calendar.getTime()) + ",";
-                calendar.set(Calendar.DAY_OF_WEEK, Calendar.SATURDAY);
-                formatValue += simpleDateFormat.format(calendar.getTime());
+                formatValue = localDate.plusWeeks(-1).with(DayOfWeek.MONDAY).format(DateTimeFormatter.ofPattern("yyyy-MM-dd")) + ","
+                        + localDate.plusWeeks(-1).with(DayOfWeek.SUNDAY).format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
                 break;
             case "month" :
-                calendar.set(Calendar.DAY_OF_MONTH, 1);
-                formatValue = simpleDateFormat.format(calendar.getTime()) + ",";
-                calendar.add(Calendar.MONTH, 1);
-                calendar.set(Calendar.DAY_OF_MONTH, 0);
-                formatValue += simpleDateFormat.format(calendar.getTime());
+                formatValue = localDate.plusMonths(0).with(TemporalAdjusters.firstDayOfMonth()).format(DateTimeFormatter.ofPattern("yyyy-MM-dd")) + ","
+                        + localDate.plusWeeks(0).with(TemporalAdjusters.lastDayOfMonth()).format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
                 break;
             case "lastmonth" :
-                calendar.add(Calendar.MONTH, -1);
-                calendar.set(Calendar.DAY_OF_MONTH, 1);
-                formatValue = simpleDateFormat.format(calendar.getTime()) + ",";
-                calendar.add(Calendar.MONTH, 1);
-                calendar.set(Calendar.DAY_OF_MONTH, 0);
-                formatValue += simpleDateFormat.format(calendar.getTime());
+                formatValue = localDate.plusMonths(-1).with(TemporalAdjusters.firstDayOfMonth()).format(DateTimeFormatter.ofPattern("yyyy-MM-dd")) + ","
+                        + localDate.plusMonths(-1).with(TemporalAdjusters.lastDayOfMonth()).format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
                 break;
             case "quarter" :
-                formatValue = simpleDateFormat.format(quarterStart(0).getTime()) + ",";
-                Calendar c1 = quarterStart(0);
-                c1.add(Calendar.MONTH, 2);
-                formatValue += simpleDateFormat.format(c1.getTime());
+                formatValue = quarterStart(0).format(DateTimeFormatter.ofPattern("yyyy-MM-dd")) + ","
+                        + quarterStart(0).plusMonths(2).with(TemporalAdjusters.lastDayOfMonth()).format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
                 break;
             case "lastquarter" :
-                formatValue = simpleDateFormat.format(quarterStart(-2).getTime()) + ",";
-                Calendar c2 = quarterStart(0);
-                c2.add(Calendar.MONTH, 2);
-                formatValue += simpleDateFormat.format(c2.getTime());
+                formatValue = quarterStart(-1).format(DateTimeFormatter.ofPattern("yyyy-MM-dd")) + ","
+                        + quarterStart(-1).plusMonths(2).with(TemporalAdjusters.lastDayOfMonth()).format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
+                formatValue = "";
                 break;
             case "halfyear" :
-                calendar.add(Calendar.MONTH, -6);
-                calendar.set(Calendar.DAY_OF_MONTH, 1);
-                formatValue = simpleDateFormat.format(calendar.getTime()) + ",";
-                calendar = Calendar.getInstance();
-                formatValue += simpleDateFormat.format(calendar.getTime());
+                formatValue = localDate.plusMonths(-6).format(DateTimeFormatter.ofPattern("yyyy-MM-dd")) + ","
+                        + localDate.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
                 break;
             case "year" :
-                calendar.set(Calendar.DAY_OF_YEAR, 1);
-                formatValue = simpleDateFormat.format(calendar.getTime()) + ",";
-                calendar.roll(Calendar.DAY_OF_YEAR, -1);
-                formatValue += calendar.getTime();
+                formatValue = localDate.plusYears(0).with(TemporalAdjusters.firstDayOfYear()).format(DateTimeFormatter.ofPattern("yyyy-MM-dd")) + ","
+                        + localDate.plusWeeks(0).with(TemporalAdjusters.firstDayOfYear()).format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
                 break;
             case "lastyear" :
-                calendar.set(Calendar.YEAR, calendar.get(Calendar.YEAR) - 1);
-                calendar.set(Calendar.DAY_OF_YEAR, 1);
-                formatValue = simpleDateFormat.format(calendar.getTime()) + ",";
-                calendar.roll(Calendar.DAY_OF_YEAR, -1);
-                formatValue += calendar.getTime();
+                formatValue = localDate.plusYears(-1).with(TemporalAdjusters.firstDayOfYear()).format(DateTimeFormatter.ofPattern("yyyy-MM-dd")) + ","
+                        + localDate.plusWeeks(-1).with(TemporalAdjusters.firstDayOfYear()).format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
                 break;
             default:
                 formatValue = value;
@@ -253,9 +226,9 @@ public class ScreenUtil {
         return formatValue;
     }
 
-    private static Calendar quarterStart(int offset) {
-        final Calendar calendar = Calendar.getInstance();
-        int month = calendar.get(Calendar.MONTH);//当月
+    private static LocalDate quarterStart(int offset) {
+        final LocalDate date = LocalDate.now().plusMonths(offset * 3);
+        int month = date.getMonth().getValue();//当月
         int start = 0;
         if (month >= 1 && month <= 3) {//第一季度
             start = 1;
@@ -269,8 +242,6 @@ public class ScreenUtil {
             start = 12;
             month = 14;
         }
-        calendar.add(Calendar.MONTH,start - month);
-        calendar.set(Calendar.DAY_OF_MONTH, 1);
-        return calendar;
+        return date.plusMonths(start - month).with(TemporalAdjusters.firstDayOfMonth());
     }
 }

+ 1 - 1
pom.xml

@@ -26,7 +26,7 @@
 
   <properties>
     <project.release.version>2.0.0-SNAPSHOT</project.release.version>
-    <java.version>1.7</java.version>
+    <java.version>1.8</java.version>
     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
     <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
     <spring.boot.version>2.0.4.RELEASE</spring.boot.version>