Browse Source

20220722 lfq

lifuquan 2 years ago
parent
commit
aec6048e4e
5 changed files with 501 additions and 517 deletions
  1. 1 0
      .gitignore
  2. 0 17
      .project
  3. 4 18
      pom.xml
  4. 496 465
      src/main/java/com/nokia/hb/utils/DbUtil.java
  5. 0 17
      src/test/java/com/nokia/hb/Test.java

+ 1 - 0
.gitignore

@@ -132,6 +132,7 @@ local.properties
 .settings/
 .loadpath
 .recommenders
+.project
 
 # External tool builders
 .externalToolBuilders/

+ 0 - 17
.project

@@ -1,17 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<projectDescription>
-	<name>hb</name>
-	<comment></comment>
-	<projects>
-	</projects>
-	<buildSpec>
-		<buildCommand>
-			<name>org.eclipse.m2e.core.maven2Builder</name>
-			<arguments>
-			</arguments>
-		</buildCommand>
-	</buildSpec>
-	<natures>
-		<nature>org.eclipse.m2e.core.maven2Nature</nature>
-	</natures>
-</projectDescription>

+ 4 - 18
pom.xml

@@ -5,7 +5,7 @@
 	<parent>
 		<groupId>org.springframework.boot</groupId>
 		<artifactId>spring-boot-starter-parent</artifactId>
-		<version>2.5.4</version>
+		<version>2.6.9</version>
 		<relativePath/> <!-- lookup parent from repository -->
 	</parent>
 	<groupId>com.nokia</groupId>
@@ -16,22 +16,8 @@
 	<properties>
 		<java.version>1.8</java.version>
 	</properties>
-<!--	<pluginRepositories>-->
-<!--		<pluginRepository>-->
-<!--			<id>spring-snapshots</id>-->
-<!--			<url>https://repo.spring.io/snapshot</url>-->
-<!--		</pluginRepository>-->
-<!--		<pluginRepository>-->
-<!--			<id>spring-milestones</id>-->
-<!--			<url>https://repo.spring.io/milestone</url>-->
-<!--		</pluginRepository>-->
-<!--	</pluginRepositories>-->
+
 	<dependencies>
-<!--		<dependency>-->
-<!--			<groupId>net.sourceforge.nekohtml</groupId>-->
-<!--			<artifactId>nekohtml</artifactId>-->
-<!--			<version>1.9.22</version>-->
-<!--		</dependency>-->
 		<dependency>
 			<groupId>org.springframework.boot</groupId>
 			<artifactId>spring-boot-starter-jdbc</artifactId>
@@ -59,13 +45,13 @@
 		<dependency>
 			<groupId>org.postgresql</groupId>
 			<artifactId>postgresql</artifactId>
-			<version>42.1.3</version>
+			<version>42.3.5</version>
 		</dependency>
 		<!-- https://mvnrepository.com/artifact/com.alibaba/fastjson -->
 		<dependency>
 			<groupId>com.alibaba</groupId>
 			<artifactId>fastjson</artifactId>
-			<version>1.2.62</version>
+			<version>2.0.9.graal</version>
 		</dependency>
 
 	</dependencies>

+ 496 - 465
src/main/java/com/nokia/hb/utils/DbUtil.java

@@ -12,21 +12,20 @@ import javax.servlet.http.HttpSession;
 import java.sql.*;
 import java.util.*;
 
-
+@SuppressWarnings("unchecked")
 public class DbUtil {
-    private static final Logger log= LoggerFactory.getLogger(DbUtil.class);
+    private static final Logger log = LoggerFactory.getLogger(DbUtil.class);
     private static Connection conn = null;
 
-
-//    private final static String url = "jdbc:postgresql://127.0.0.1:5432/postgres";
-//    private final static String user = "postgres";
-//    private final static String password = "ava1234";
+    // private final static String url =
+    // "jdbc:postgresql://127.0.0.1:5432/postgres";
+    // private final static String user = "postgres";
+    // private final static String password = "ava1234";
 
     private final static String url = "jdbc:postgresql://10.100.68.195:5432/sqmmt";
     private final static String user = "pmparse";
     private final static String password = "abc123!";
 
-
     static {
         try {
             conn = DriverManager.getConnection(url, user, password);
@@ -34,82 +33,76 @@ public class DbUtil {
             e.printStackTrace();
         }
     }
-    
-    public static Map<String, String> initZnEnMap()
-    {
-      String sql = "select distinct indicator_en,indicator_cn from pm_parse.per_cfg_indicator;";
-      Map<String, String> m = new HashMap();
-      m.put("cellname", "小区中文名");
-      m.put("city", "地市");
-      m.put("quxian", "区县");
-      m.put("vendor", "厂家");
-      try
-      {
-        PreparedStatement psmt = null;
-        psmt = conn.prepareStatement(sql);
-        psmt.setQueryTimeout(600);
-        ResultSet rs = psmt.executeQuery();
-        while (rs.next()) {
-          m.put(rs.getString("indicator_en"), rs.getString("indicator_cn"));
+
+    public static Map<String, String> initZnEnMap() {
+        String sql = "select distinct indicator_en,indicator_cn from pm_parse.per_cfg_indicator;";
+        Map<String, String> m = new HashMap<>();
+        m.put("cellname", "小区中文名");
+        m.put("city", "地市");
+        m.put("quxian", "区县");
+        m.put("vendor", "厂家");
+        try {
+            PreparedStatement psmt = null;
+            psmt = conn.prepareStatement(sql);
+            psmt.setQueryTimeout(600);
+            ResultSet rs = psmt.executeQuery();
+            while (rs.next()) {
+                m.put(rs.getString("indicator_en"), rs.getString("indicator_cn"));
+            }
+        } catch (SQLException e) {
+            e.printStackTrace();
         }
-      }
-      catch (SQLException e)
-      {
-        e.printStackTrace();
-      }
-      return m;
+        return m;
     }
-    
-    
-    public static RetData conditionRenderTable(String condition, String searchType, String indicators, String ttype, String sdate)
-    {
-      Map<String, String> ezMap = initZnEnMap();
-      String[] timeArray = sdate.split(" - ");
-      String startTime = timeArray[0];
-      String endTime = timeArray[1];
-      String sql = "select a.cellname,a.city,a.quxian,a.vendor,b.* from \n(select eci,cellname,city,quxian,vendor from pm_parse.per_cfg_cell where " + searchType + " in (" + condition + ")) a\ninner join \n(select " + indicators + " from pm_parse.pm_4g_" + ttype + " where sdate>='" + startTime + "' and sdate <= '" + endTime + "') b\n" + "on a.eci=b.eci";
-      // 全网
-      if ("all".equals(searchType)) {
-          sql = "select a.cellname,a.city,a.quxian,a.vendor,b.* from pm_parse.per_cfg_cell a\ninner join \n(select " + indicators + " from pm_parse.pm_4g_" + ttype + " where sdate>='" + startTime + "' and sdate <= '" + endTime + "') b\n" + "on a.eci=b.eci";
-      }
-
-      List<Map<String, String>> datas = new ArrayList();
-      List<Col> cols = new ArrayList();
-      try
-      {
-        PreparedStatement psmt = null;
-        psmt = conn.prepareStatement(sql);
-        psmt.setQueryTimeout(600);
-        ResultSet rs = psmt.executeQuery();
-        ResultSetMetaData rsmd = rs.getMetaData();
-        List<String> heads = new ArrayList();
-        String columnName;
-        for (int i = 1; i <= rsmd.getColumnCount(); i++)
-        {
-          columnName = rsmd.getColumnName(i);
-          heads.add(columnName);
-          cols.add(new Col(columnName, (String)ezMap.get(columnName)));
+
+    public static RetData conditionRenderTable(String condition, String searchType, String indicators, String ttype,
+            String sdate) {
+        Map<String, String> ezMap = initZnEnMap();
+        String[] timeArray = sdate.split(" - ");
+        String startTime = timeArray[0];
+        String endTime = timeArray[1];
+        String sql = "select a.cellname,a.city,a.quxian,a.vendor,b.* from \n(select eci,cellname,city,quxian,vendor from pm_parse.per_cfg_cell where "
+                + searchType + " in (" + condition + ")) a\ninner join \n(select " + indicators
+                + " from pm_parse.pm_4g_" + ttype + " where sdate>='" + startTime + "' and sdate <= '" + endTime
+                + "') b\n" + "on a.eci=b.eci";
+        // 全网
+        if ("all".equals(searchType)) {
+            sql = "select a.cellname,a.city,a.quxian,a.vendor,b.* from pm_parse.per_cfg_cell a\ninner join \n(select "
+                    + indicators + " from pm_parse.pm_4g_" + ttype + " where sdate>='" + startTime + "' and sdate <= '"
+                    + endTime + "') b\n" + "on a.eci=b.eci";
         }
-        while (rs.next())
-        {
-          Map<String, String> m = new HashMap();
-          for (String head : heads)
-          {
-            String string = rs.getString(head);
-            m.put(head, string);
-          }
-          datas.add(m);
+
+        List<Map<String, String>> datas = new ArrayList<>();
+        List<Col> cols = new ArrayList<>();
+        try {
+            PreparedStatement psmt = null;
+            psmt = conn.prepareStatement(sql);
+            psmt.setQueryTimeout(600);
+            ResultSet rs = psmt.executeQuery();
+            ResultSetMetaData rsmd = rs.getMetaData();
+            List<String> heads = new ArrayList<>();
+            String columnName;
+            for (int i = 1; i <= rsmd.getColumnCount(); i++) {
+                columnName = rsmd.getColumnName(i);
+                heads.add(columnName);
+                cols.add(new Col(columnName, (String) ezMap.get(columnName)));
+            }
+            while (rs.next()) {
+                Map<String, String> m = new HashMap<>();
+                for (String head : heads) {
+                    String string = rs.getString(head);
+                    m.put(head, string);
+                }
+                datas.add(m);
+            }
+        } catch (SQLException e) {
+            e.printStackTrace();
         }
-      }
-      catch (SQLException e)
-      {
-        e.printStackTrace();
-      }
-      return new RetData(cols, datas);
+        return new RetData(cols, datas);
     }
-    
-    
-    public static RetData renderTable(String citys, String quxians, String indicators, String ttype, String sdate, HttpSession session) {
+
+    public static RetData renderTable(String citys, String quxians, String indicators, String ttype, String sdate,
+            HttpSession session) {
         log.debug("indicators: {}", indicators);
         log.debug("citys: {}", citys);
         log.debug("quxians: {}", quxians);
@@ -141,8 +134,8 @@ public class DbUtil {
                 "' and sdate <= '" + endTime + "') b\n" +
                 "on a.eci=b.eci";
 
-        if(indicators.contains("eci")){
-            sql="select b.* from \n" +
+        if (indicators.contains("eci")) {
+            sql = "select b.* from \n" +
                     "(select eci from pm_parse.per_cfg_cell where quxian in (" + quxians + ")) a\n" +
                     "inner join \n" +
                     "(select " + indicators + " from pm_parse.pm_4g_" + ttype +
@@ -160,8 +153,7 @@ public class DbUtil {
             ResultSetMetaData rsmd = rs.getMetaData();
             List<String> heads = new ArrayList<>();
 
-
-            for (int i = 1; i <=rsmd.getColumnCount(); i++) {
+            for (int i = 1; i <= rsmd.getColumnCount(); i++) {
                 String columnName = rsmd.getColumnName(i);
                 heads.add(columnName);
                 cols.add(new Col(columnName, columnName));
@@ -184,7 +176,7 @@ public class DbUtil {
         String sql = "select distinct * from pm_parse.per_cfg_area order by city,quxian";
         PreparedStatement psmt = null;
         TreeNode allTree = new TreeNode("地市选择", "地市选择", new ArrayList<>());
-        int i = 0;
+        // int i = 0;
         try {
             psmt = conn.prepareStatement(sql);
             psmt.setQueryTimeout(60 * 10);
@@ -206,7 +198,6 @@ public class DbUtil {
 
             }
 
-
             for (String s : m.keySet()) {
                 allTree.getChildren().add(new TreeNode(s, s, m.get(s)));
             }
@@ -221,7 +212,8 @@ public class DbUtil {
     }
 
     public static List<TreeNode> initTreeIndicator() {
-//        String sql = "select distinct * from pm_parse.per_cfg_indicator order by indicator_type,indicator_cn,indicator_en";
+        // String sql = "select distinct * from pm_parse.per_cfg_indicator order by
+        // indicator_type,indicator_cn,indicator_en";
         String sql = "select distinct * from pm_parse.per_cfg_indicator order by indicator_id,indicator_type,indicator_cn,indicator_en";
         PreparedStatement psmt = null;
         TreeNode allTree = new TreeNode("指标选择", "指标选择", new ArrayList<>());
@@ -245,7 +237,7 @@ public class DbUtil {
                 }
 
             }
-            int i = 0;
+            // int i = 0;
             for (String s : m.keySet()) {
                 allTree.getChildren().add(new TreeNode(s, s, m.get(s)));
             }
@@ -259,301 +251,329 @@ public class DbUtil {
         return res;
     }
 
-//    public static Map<String, List<Object>> searchRate(String from, String t1, String t2, String ttype, String provinces, String citys) {
-//
-//
-//        HashMap<String, List<Object>> res = new HashMap<>();
-//        PreparedStatement psmt = null;
-//        String pn = "province_name";
-//        String cn = "city_name";
-//        if ("roaming".equals(from)) {
-//            pn = "roaming_province_name";
-//            cn = "roaming_city_name";
-//        }
-//        String sql = "select a.sdate as dt,round(a.openusers/b.users,4) as num from \n" +
-//                "(select sdate,sum(user_count) as openusers from sqmdb_5g.user_terminal_status_5g_abstract where sdate between ? and ? and stype='打开5G开关用户数' and size_type='" + ttype + "天' and " + pn + " in (" + provinces + ") and " + cn + " in (" + citys + ") group by sdate ) a\n" +
-//                "inner join\n" +
-//                "(select sdate,sum(user_count) as users from sqmdb_5g.user_terminal_status_5g_abstract where sdate between ? and ? and stype='5G终端用户数' and size_type='" + ttype + "天' and " + pn + " in (" + provinces + ") and " + cn + " in (" + citys + ") group by sdate) b\n" +
-//                "on a.sdate=b.sdate\n" +
-//                "order by a.sdate";
-//        if ("".equals(citys)) {
-//            sql = "select a.sdate as dt,round(a.openusers/b.users,4) as num from \n" +
-//                    "(select sdate,sum(user_count) as openusers from sqmdb_5g.user_terminal_status_5g_abstract where sdate between ? and ? and stype='打开5G开关用户数' and size_type='" + ttype + "天' and " + pn + " in (" + provinces + ") group by sdate ) a\n" +
-//                    "inner join\n" +
-//                    "(select sdate,sum(user_count) as users from sqmdb_5g.user_terminal_status_5g_abstract where sdate between ? and ? and stype='5G终端用户数' and size_type='" + ttype + "天' and " + pn + " in (" + provinces + ") group by sdate) b\n" +
-//                    "on a.sdate=b.sdate\n" +
-//                    "order by a.sdate";
-//        }
-//
-//        List<Object> dtList = new ArrayList<>();
-//        List<Object> numList = new ArrayList<>();
-//        try {
-//            psmt = conn.prepareStatement(sql);
-//
-//            psmt.setQueryTimeout(60 * 10);
-//            psmt.setLong(1, Integer.valueOf(t1));
-//            psmt.setLong(2, Integer.valueOf(t2));
-//            psmt.setLong(3, Integer.valueOf(t1));
-//            psmt.setLong(4, Integer.valueOf(t2));
-//
-////            psmt.setString(5,provinces);
-////            psmt.setString(6,citys);
-//            ResultSet rs = psmt.executeQuery();
-//            while (rs.next()) {
-//                String dt = rs.getString("dt");
-//                Long num = rs.getLong("num");
-//                dtList.add(dt);
-//                numList.add(num);
-//            }
-//            res.put("dt", dtList);
-//            res.put("num", numList);
-//        } catch (SQLException e) {
-//            e.printStackTrace();
-//        }
-//        return res;
-//    }
-
-//    public static HashMap<String, List<Object>> search(String from, String t1, String t2, String stype, String ttype, String provinces, String citys) {
-//        HashMap<String, List<Object>> res = new HashMap<>();
-//        PreparedStatement psmt = null;
-//        String pn = "province_name";
-//        String cn = "city_name";
-//        if ("roaming".equals(from)) {
-//            pn = "roaming_province_name";
-//            cn = "roaming_city_name";
-//        }
-////        String sql = "select sdate,sum(user_count) from sqmdb_5g.user_terminal_status_5g_abstract where sdate between '20210720' and '20210727' and stype='5G终端用户数' and size_type='7天' and province_name in ('河北') and city_name in ('石家庄','唐山') group by sdate;";
-//        String sql = "select sdate as dt ,sum(user_count) as num from sqmdb_5g.user_terminal_status_5g_abstract where sdate between ? and ? and stype=? and size_type=? and " + pn + " in (" + provinces + ") and " + cn + " in (" + citys + ") group by sdate order by sdate;";
-//        if ("".equals(citys)) {
-//            sql = "select sdate as dt ,sum(user_count) as num from sqmdb_5g.user_terminal_status_5g_abstract where sdate between ? and ? and stype=? and size_type=? and " + pn + " in (" + provinces + ")  group by sdate order by sdate;";
-//        }
-//
-//        List<Object> dtList = new ArrayList<>();
-//        List<Object> numList = new ArrayList<>();
-//        try {
-//            psmt = conn.prepareStatement(sql);
-//
-//            psmt.setQueryTimeout(60 * 10);
-//            psmt.setLong(1, Integer.valueOf(t1));
-//            psmt.setLong(2, Integer.valueOf(t2));
-//            psmt.setString(3, stype);
-//            psmt.setString(4, ttype + "天");
-////            psmt.setString(5,provinces);
-////            psmt.setString(6,citys);
-//            ResultSet rs = psmt.executeQuery();
-//            while (rs.next()) {
-//                String dt = rs.getString("dt");
-//                Long num = rs.getLong("num");
-//                dtList.add(dt);
-//                numList.add(num);
-//            }
-//            res.put("dt", dtList);
-//            res.put("num", numList);
-//        } catch (SQLException e) {
-//            e.printStackTrace();
-//        }
-//        return res;
-//    }
-
-//    public static String typeExport(String from, String provinces, String citys, String ttype, String t1, String t2) {
-//        String res = "";
-//        String pn = "province_name";
-//        String cn = "city_name";
-//        String guishu = "归属地";
-//        String area = citys;
-//        if ("roaming".equals(from)) {
-//            pn = "roaming_province_name";
-//            cn = "roaming_city_name";
-//            guishu = "拜访地";
-//        }
-//        String sql = "with tab as (\n" +
-//                "select distinct\n" +
-//                "stype,\n" +
-//                "'" + guishu + "' as 维度, \n" +
-//                "size_type as 粒度,\n" +
-//                "'" + area + "' as 区域, \n" +
-//                "sdate as 日期,\n" +
-//                "sum(user_count) over(partition by stype,sdate,size_type) as user_count\n" +
-//                "from sqmdb_5g.user_terminal_status_5g_abstract\n" +
-//                "where sdate between ? and ? \n" +
-//                "and " + pn + " in ('" + provinces + "') and " + cn + " in ('" + citys + "') \n" +
-//                "and size_type = '" + ttype + "天'\n" +
-//                ") \n" +
-//                "\n" +
-//                "select \n" +
-//                "a.维度,\n" +
-//                "a.粒度,\n" +
-//                "a.区域,\n" +
-//                "a.日期,\n" +
-//                "sum(a.user_count) as 终端用户数,\n" +
-//                "sum(b.user_count) as 打开5G开关用户数,\n" +
-//                "sum(c.user_count) as 关闭5G开关用户数,\n" +
-//                "round(sum(b.user_count)/sum(a.user_count),4) as 开关打开率\n" +
-//                "from tab a\n" +
-//                "join tab b on b.日期=a.日期 and b.stype = '打开5G开关用户数'\n" +
-//                "join tab c on c.日期=a.日期 and c.stype = '关闭5G开关用户数'\n" +
-//                "where a.stype = '5G终端用户数'\n" +
-//                "group by \n" +
-//                "a.维度,\n" +
-//                "a.粒度,\n" +
-//                "a.区域,\n" +
-//                "a.日期\n" +
-//                "order by 日期";
-//
-//        if ("".equals(citys)) {
-//            area = provinces;
-//            sql = "with tab as (\n" +
-//                    "select distinct\n" +
-//                    "stype,\n" +
-//                    "'" + guishu + "' as 维度, \n" +
-//                    "size_type as 粒度,\n" +
-//                    "'" + area + "' as 区域, \n" +
-//                    "sdate as 日期,\n" +
-//                    "sum(user_count) over(partition by stype,sdate,size_type) as user_count\n" +
-//                    "from sqmdb_5g.user_terminal_status_5g_abstract\n" +
-//                    "where sdate between ? and ? \n" +
-//                    "and " + pn + " in ('" + provinces + "')  \n" +
-//                    "and size_type = '" + ttype + "天'\n" +
-//                    ") \n" +
-//                    "\n" +
-//                    "select \n" +
-//                    "a.维度,\n" +
-//                    "a.粒度,\n" +
-//                    "a.区域,\n" +
-//                    "a.日期,\n" +
-//                    "sum(a.user_count) as 终端用户数,\n" +
-//                    "sum(b.user_count) as 打开5G开关用户数,\n" +
-//                    "sum(c.user_count) as 关闭5G开关用户数,\n" +
-//                    "round(sum(b.user_count)/sum(a.user_count),4) as 开关打开率\n" +
-//                    "from tab a\n" +
-//                    "join tab b on b.日期=a.日期 and b.stype = '打开5G开关用户数'\n" +
-//                    "join tab c on c.日期=a.日期 and c.stype = '关闭5G开关用户数'\n" +
-//                    "where a.stype = '5G终端用户数'\n" +
-//                    "group by \n" +
-//                    "a.维度,\n" +
-//                    "a.粒度,\n" +
-//                    "a.区域,\n" +
-//                    "a.日期\n" +
-//                    "order by 日期";
-//        }
-//
-//
-//        PreparedStatement psmt = null;
-//
-//
-//        try {
-//            psmt = conn.prepareStatement(sql);
-//            psmt.setQueryTimeout(60 * 10);
-//
-//            psmt.setLong(1, Integer.valueOf(t1));
-//            psmt.setLong(2, Integer.valueOf(t2));
-//            ResultSet rs = psmt.executeQuery();
-//            res = rsprocess(rs);
-//        } catch (SQLException e) {
-//            e.printStackTrace();
-//        }
-//        return res;
-//    }
-
-//    public static String exportAll(String ttype, String sts, String ets, String smts, String emts) {
-//        String res = "";
-//        String range = smts + "-" + ets;
-//        PreparedStatement psmt = null;
-//        String sql = "select '" + ttype + "天' as \"粒度\",\n" +
-//                "'" + range + "' as \"开始(结束)时间\",\n" +
-//                "msisdn as \"号码\",\n" +
-//                "province_name as \"归属省\",\n" +
-//                "city_name as \"归属地市\",\n" +
-//                "roaming_province_name as \"拜访省\",\n" +
-//                "roaming_city_name as \"拜访地市\",\n" +
-//                "tml_brand as \"终端品牌\",\n" +
-//                "tml_name as \"终端型号\",\n" +
-//                "case when last_open_date >= ? then 1 else 0 end as \"开关是否打开\"  \n" +
-//                "from sqmdb_5g.user_terminal_status_5g_agg\n" +
-//                "where sdate=? \n" +
-//                "and last_chg_date >= ?  ";
-//
-//        try {
-//            psmt = conn.prepareStatement(sql);
-//            psmt.setQueryTimeout(60 * 10);
-//
-//            psmt.setLong(1, Integer.valueOf(emts));
-//            psmt.setLong(2, Integer.valueOf(ets));
-//            psmt.setLong(3, Integer.valueOf(emts));
-//
-//            ResultSet rs = psmt.executeQuery();
-//            res = rsprocess(rs);
-//        } catch (SQLException e) {
-//            e.printStackTrace();
-//        }
-//        return res;
-//    }
-
-//    public static String exportClose(String ttype, String sts, String ets, String smts, String emts) {
-//        String res = "";
-//        String range = smts + "-" + ets;
-//        PreparedStatement psmt = null;
-//        String sql = "select '" + ttype + "天' as \"粒度\",\n" +
-//                "'" + range + "' as \"开始(结束)时间\",\n" +
-//                "msisdn as \"号码\",\n" +
-//                "province_name as \"归属省\",\n" +
-//                "city_name as \"归属地市\",\n" +
-//                "roaming_province_name as \"拜访省\",\n" +
-//                "roaming_city_name as \"拜访地市\",\n" +
-//                "tml_brand as \"终端品牌\",\n" +
-//                "tml_name as \"终端型号\",\n" +
-//                "0 as \"开关是否打开\"\n" +
-//                "from sqmdb_5g.user_terminal_status_5g_agg\n" +
-//                "where sdate=? \n" +
-//                "and last_chg_date >= ? \n" +
-//                "and (last_open_date < ? or last_open_date is null) ";
-//
-//        try {
-//            psmt = conn.prepareStatement(sql);
-//            psmt.setQueryTimeout(60 * 10);
-//
-//            psmt.setLong(1, Integer.valueOf(ets));
-//            psmt.setLong(2, Integer.valueOf(emts));
-//            psmt.setLong(3, Integer.valueOf(emts));
-//
-//            ResultSet rs = psmt.executeQuery();
-//            res = rsprocess(rs);
-//        } catch (SQLException e) {
-//            e.printStackTrace();
-//        }
-//        return res;
-//    }
-
-//    public static String rsprocess(ResultSet rs) {
-//        List<String> heads = new ArrayList<>();
-//        String headStr = "";
-//        StringBuffer sb = new StringBuffer();
-//        try {
-//            ResultSetMetaData rsmd = rs.getMetaData();
-//            for (int i = 1; i <= rsmd.getColumnCount(); i++) {
-//                String columnName = rsmd.getColumnName(i);
-//                heads.add(columnName);
-//                headStr += columnName + ",";
-//
-//            }
-//
-//            headStr = headStr.substring(0, headStr.length() - 1);
-//            sb.append(headStr + "\n");
-//            while (rs.next()) {
-//                String line = "";
-//                for (String head : heads) {
-//                    line += rs.getString(head) + ",";
-//
-//                }
-//                line = line.substring(0, line.length() - 1);
-//                sb.append(line + "\n");
-//            }
-//
-//        } catch (SQLException throwables) {
-//            throwables.printStackTrace();
-//        }
-//        return sb.toString();
-//    }
+    // public static Map<String, List<Object>> searchRate(String from, String t1,
+    // String t2, String ttype, String provinces, String citys) {
+    //
+    //
+    // HashMap<String, List<Object>> res = new HashMap<>();
+    // PreparedStatement psmt = null;
+    // String pn = "province_name";
+    // String cn = "city_name";
+    // if ("roaming".equals(from)) {
+    // pn = "roaming_province_name";
+    // cn = "roaming_city_name";
+    // }
+    // String sql = "select a.sdate as dt,round(a.openusers/b.users,4) as num from
+    // \n" +
+    // "(select sdate,sum(user_count) as openusers from
+    // sqmdb_5g.user_terminal_status_5g_abstract where sdate between ? and ? and
+    // stype='打开5G开关用户数' and size_type='" + ttype + "天' and " + pn + " in (" +
+    // provinces + ") and " + cn + " in (" + citys + ") group by sdate ) a\n" +
+    // "inner join\n" +
+    // "(select sdate,sum(user_count) as users from
+    // sqmdb_5g.user_terminal_status_5g_abstract where sdate between ? and ? and
+    // stype='5G终端用户数' and size_type='" + ttype + "天' and " + pn + " in (" +
+    // provinces + ") and " + cn + " in (" + citys + ") group by sdate) b\n" +
+    // "on a.sdate=b.sdate\n" +
+    // "order by a.sdate";
+    // if ("".equals(citys)) {
+    // sql = "select a.sdate as dt,round(a.openusers/b.users,4) as num from \n" +
+    // "(select sdate,sum(user_count) as openusers from
+    // sqmdb_5g.user_terminal_status_5g_abstract where sdate between ? and ? and
+    // stype='打开5G开关用户数' and size_type='" + ttype + "天' and " + pn + " in (" +
+    // provinces + ") group by sdate ) a\n" +
+    // "inner join\n" +
+    // "(select sdate,sum(user_count) as users from
+    // sqmdb_5g.user_terminal_status_5g_abstract where sdate between ? and ? and
+    // stype='5G终端用户数' and size_type='" + ttype + "天' and " + pn + " in (" +
+    // provinces + ") group by sdate) b\n" +
+    // "on a.sdate=b.sdate\n" +
+    // "order by a.sdate";
+    // }
+    //
+    // List<Object> dtList = new ArrayList<>();
+    // List<Object> numList = new ArrayList<>();
+    // try {
+    // psmt = conn.prepareStatement(sql);
+    //
+    // psmt.setQueryTimeout(60 * 10);
+    // psmt.setLong(1, Integer.valueOf(t1));
+    // psmt.setLong(2, Integer.valueOf(t2));
+    // psmt.setLong(3, Integer.valueOf(t1));
+    // psmt.setLong(4, Integer.valueOf(t2));
+    //
+    //// psmt.setString(5,provinces);
+    //// psmt.setString(6,citys);
+    // ResultSet rs = psmt.executeQuery();
+    // while (rs.next()) {
+    // String dt = rs.getString("dt");
+    // Long num = rs.getLong("num");
+    // dtList.add(dt);
+    // numList.add(num);
+    // }
+    // res.put("dt", dtList);
+    // res.put("num", numList);
+    // } catch (SQLException e) {
+    // e.printStackTrace();
+    // }
+    // return res;
+    // }
+
+    // public static HashMap<String, List<Object>> search(String from, String t1,
+    // String t2, String stype, String ttype, String provinces, String citys) {
+    // HashMap<String, List<Object>> res = new HashMap<>();
+    // PreparedStatement psmt = null;
+    // String pn = "province_name";
+    // String cn = "city_name";
+    // if ("roaming".equals(from)) {
+    // pn = "roaming_province_name";
+    // cn = "roaming_city_name";
+    // }
+    //// String sql = "select sdate,sum(user_count) from
+    // sqmdb_5g.user_terminal_status_5g_abstract where sdate between '20210720' and
+    // '20210727' and stype='5G终端用户数' and size_type='7天' and province_name in ('河北')
+    // and city_name in ('石家庄','唐山') group by sdate;";
+    // String sql = "select sdate as dt ,sum(user_count) as num from
+    // sqmdb_5g.user_terminal_status_5g_abstract where sdate between ? and ? and
+    // stype=? and size_type=? and " + pn + " in (" + provinces + ") and " + cn + "
+    // in (" + citys + ") group by sdate order by sdate;";
+    // if ("".equals(citys)) {
+    // sql = "select sdate as dt ,sum(user_count) as num from
+    // sqmdb_5g.user_terminal_status_5g_abstract where sdate between ? and ? and
+    // stype=? and size_type=? and " + pn + " in (" + provinces + ") group by sdate
+    // order by sdate;";
+    // }
+    //
+    // List<Object> dtList = new ArrayList<>();
+    // List<Object> numList = new ArrayList<>();
+    // try {
+    // psmt = conn.prepareStatement(sql);
+    //
+    // psmt.setQueryTimeout(60 * 10);
+    // psmt.setLong(1, Integer.valueOf(t1));
+    // psmt.setLong(2, Integer.valueOf(t2));
+    // psmt.setString(3, stype);
+    // psmt.setString(4, ttype + "天");
+    //// psmt.setString(5,provinces);
+    //// psmt.setString(6,citys);
+    // ResultSet rs = psmt.executeQuery();
+    // while (rs.next()) {
+    // String dt = rs.getString("dt");
+    // Long num = rs.getLong("num");
+    // dtList.add(dt);
+    // numList.add(num);
+    // }
+    // res.put("dt", dtList);
+    // res.put("num", numList);
+    // } catch (SQLException e) {
+    // e.printStackTrace();
+    // }
+    // return res;
+    // }
+
+    // public static String typeExport(String from, String provinces, String citys,
+    // String ttype, String t1, String t2) {
+    // String res = "";
+    // String pn = "province_name";
+    // String cn = "city_name";
+    // String guishu = "归属地";
+    // String area = citys;
+    // if ("roaming".equals(from)) {
+    // pn = "roaming_province_name";
+    // cn = "roaming_city_name";
+    // guishu = "拜访地";
+    // }
+    // String sql = "with tab as (\n" +
+    // "select distinct\n" +
+    // "stype,\n" +
+    // "'" + guishu + "' as 维度, \n" +
+    // "size_type as 粒度,\n" +
+    // "'" + area + "' as 区域, \n" +
+    // "sdate as 日期,\n" +
+    // "sum(user_count) over(partition by stype,sdate,size_type) as user_count\n" +
+    // "from sqmdb_5g.user_terminal_status_5g_abstract\n" +
+    // "where sdate between ? and ? \n" +
+    // "and " + pn + " in ('" + provinces + "') and " + cn + " in ('" + citys + "')
+    // \n" +
+    // "and size_type = '" + ttype + "天'\n" +
+    // ") \n" +
+    // "\n" +
+    // "select \n" +
+    // "a.维度,\n" +
+    // "a.粒度,\n" +
+    // "a.区域,\n" +
+    // "a.日期,\n" +
+    // "sum(a.user_count) as 终端用户数,\n" +
+    // "sum(b.user_count) as 打开5G开关用户数,\n" +
+    // "sum(c.user_count) as 关闭5G开关用户数,\n" +
+    // "round(sum(b.user_count)/sum(a.user_count),4) as 开关打开率\n" +
+    // "from tab a\n" +
+    // "join tab b on b.日期=a.日期 and b.stype = '打开5G开关用户数'\n" +
+    // "join tab c on c.日期=a.日期 and c.stype = '关闭5G开关用户数'\n" +
+    // "where a.stype = '5G终端用户数'\n" +
+    // "group by \n" +
+    // "a.维度,\n" +
+    // "a.粒度,\n" +
+    // "a.区域,\n" +
+    // "a.日期\n" +
+    // "order by 日期";
+    //
+    // if ("".equals(citys)) {
+    // area = provinces;
+    // sql = "with tab as (\n" +
+    // "select distinct\n" +
+    // "stype,\n" +
+    // "'" + guishu + "' as 维度, \n" +
+    // "size_type as 粒度,\n" +
+    // "'" + area + "' as 区域, \n" +
+    // "sdate as 日期,\n" +
+    // "sum(user_count) over(partition by stype,sdate,size_type) as user_count\n" +
+    // "from sqmdb_5g.user_terminal_status_5g_abstract\n" +
+    // "where sdate between ? and ? \n" +
+    // "and " + pn + " in ('" + provinces + "') \n" +
+    // "and size_type = '" + ttype + "天'\n" +
+    // ") \n" +
+    // "\n" +
+    // "select \n" +
+    // "a.维度,\n" +
+    // "a.粒度,\n" +
+    // "a.区域,\n" +
+    // "a.日期,\n" +
+    // "sum(a.user_count) as 终端用户数,\n" +
+    // "sum(b.user_count) as 打开5G开关用户数,\n" +
+    // "sum(c.user_count) as 关闭5G开关用户数,\n" +
+    // "round(sum(b.user_count)/sum(a.user_count),4) as 开关打开率\n" +
+    // "from tab a\n" +
+    // "join tab b on b.日期=a.日期 and b.stype = '打开5G开关用户数'\n" +
+    // "join tab c on c.日期=a.日期 and c.stype = '关闭5G开关用户数'\n" +
+    // "where a.stype = '5G终端用户数'\n" +
+    // "group by \n" +
+    // "a.维度,\n" +
+    // "a.粒度,\n" +
+    // "a.区域,\n" +
+    // "a.日期\n" +
+    // "order by 日期";
+    // }
+    //
+    //
+    // PreparedStatement psmt = null;
+    //
+    //
+    // try {
+    // psmt = conn.prepareStatement(sql);
+    // psmt.setQueryTimeout(60 * 10);
+    //
+    // psmt.setLong(1, Integer.valueOf(t1));
+    // psmt.setLong(2, Integer.valueOf(t2));
+    // ResultSet rs = psmt.executeQuery();
+    // res = rsprocess(rs);
+    // } catch (SQLException e) {
+    // e.printStackTrace();
+    // }
+    // return res;
+    // }
+
+    // public static String exportAll(String ttype, String sts, String ets, String
+    // smts, String emts) {
+    // String res = "";
+    // String range = smts + "-" + ets;
+    // PreparedStatement psmt = null;
+    // String sql = "select '" + ttype + "天' as \"粒度\",\n" +
+    // "'" + range + "' as \"开始(结束)时间\",\n" +
+    // "msisdn as \"号码\",\n" +
+    // "province_name as \"归属省\",\n" +
+    // "city_name as \"归属地市\",\n" +
+    // "roaming_province_name as \"拜访省\",\n" +
+    // "roaming_city_name as \"拜访地市\",\n" +
+    // "tml_brand as \"终端品牌\",\n" +
+    // "tml_name as \"终端型号\",\n" +
+    // "case when last_open_date >= ? then 1 else 0 end as \"开关是否打开\" \n" +
+    // "from sqmdb_5g.user_terminal_status_5g_agg\n" +
+    // "where sdate=? \n" +
+    // "and last_chg_date >= ? ";
+    //
+    // try {
+    // psmt = conn.prepareStatement(sql);
+    // psmt.setQueryTimeout(60 * 10);
+    //
+    // psmt.setLong(1, Integer.valueOf(emts));
+    // psmt.setLong(2, Integer.valueOf(ets));
+    // psmt.setLong(3, Integer.valueOf(emts));
+    //
+    // ResultSet rs = psmt.executeQuery();
+    // res = rsprocess(rs);
+    // } catch (SQLException e) {
+    // e.printStackTrace();
+    // }
+    // return res;
+    // }
+
+    // public static String exportClose(String ttype, String sts, String ets, String
+    // smts, String emts) {
+    // String res = "";
+    // String range = smts + "-" + ets;
+    // PreparedStatement psmt = null;
+    // String sql = "select '" + ttype + "天' as \"粒度\",\n" +
+    // "'" + range + "' as \"开始(结束)时间\",\n" +
+    // "msisdn as \"号码\",\n" +
+    // "province_name as \"归属省\",\n" +
+    // "city_name as \"归属地市\",\n" +
+    // "roaming_province_name as \"拜访省\",\n" +
+    // "roaming_city_name as \"拜访地市\",\n" +
+    // "tml_brand as \"终端品牌\",\n" +
+    // "tml_name as \"终端型号\",\n" +
+    // "0 as \"开关是否打开\"\n" +
+    // "from sqmdb_5g.user_terminal_status_5g_agg\n" +
+    // "where sdate=? \n" +
+    // "and last_chg_date >= ? \n" +
+    // "and (last_open_date < ? or last_open_date is null) ";
+    //
+    // try {
+    // psmt = conn.prepareStatement(sql);
+    // psmt.setQueryTimeout(60 * 10);
+    //
+    // psmt.setLong(1, Integer.valueOf(ets));
+    // psmt.setLong(2, Integer.valueOf(emts));
+    // psmt.setLong(3, Integer.valueOf(emts));
+    //
+    // ResultSet rs = psmt.executeQuery();
+    // res = rsprocess(rs);
+    // } catch (SQLException e) {
+    // e.printStackTrace();
+    // }
+    // return res;
+    // }
+
+    // public static String rsprocess(ResultSet rs) {
+    // List<String> heads = new ArrayList<>();
+    // String headStr = "";
+    // StringBuffer sb = new StringBuffer();
+    // try {
+    // ResultSetMetaData rsmd = rs.getMetaData();
+    // for (int i = 1; i <= rsmd.getColumnCount(); i++) {
+    // String columnName = rsmd.getColumnName(i);
+    // heads.add(columnName);
+    // headStr += columnName + ",";
+    //
+    // }
+    //
+    // headStr = headStr.substring(0, headStr.length() - 1);
+    // sb.append(headStr + "\n");
+    // while (rs.next()) {
+    // String line = "";
+    // for (String head : heads) {
+    // line += rs.getString(head) + ",";
+    //
+    // }
+    // line = line.substring(0, line.length() - 1);
+    // sb.append(line + "\n");
+    // }
+    //
+    // } catch (SQLException throwables) {
+    // throwables.printStackTrace();
+    // }
+    // return sb.toString();
+    // }
 
     public static Object userLogin(String username, String password, HttpSession session) {
         // 计算密码md5
@@ -579,7 +599,7 @@ public class DbUtil {
             }
 
             // 查询地区权限
-            sql = "select area from pm_parse.user_area where username='" + username +"'";
+            sql = "select area from pm_parse.user_area where username='" + username + "'";
             psmt = conn.prepareStatement(sql);
             psmt.setQueryTimeout(60 * 10);
             rs = psmt.executeQuery();
@@ -591,7 +611,7 @@ public class DbUtil {
 
             log.debug("areas: {}", map.keySet());
             // 保存session
-            session.setMaxInactiveInterval(30*60);
+            session.setMaxInactiveInterval(30 * 60);
             session.setAttribute("username", username);
             session.setAttribute("areas", map);
             return 1;
@@ -722,87 +742,98 @@ public class DbUtil {
         return null;
     }
 
-//    public static List<String> initCitys(String type, String province) {
-//        PreparedStatement psmt = null;
-//        if (type == null) {
-//            type = "roaming";
-//        }
-//
-//        String sql = "select distinct roaming_city_name as city from sqmdb_5g.user_terminal_status_5g_abstract where roaming_province_name=? and roaming_city_name!='null' order by roaming_city_name";
-////        Map<String,List<String>>res = new HashMap<>();
-//        List<String> res = new ArrayList<>();
-//        if ("roaming".equals(type)) {
-//            sql = "select distinct roaming_city_name as city from sqmdb_5g.user_terminal_status_5g_abstract where roaming_province_name=? and roaming_city_name!='null' order by roaming_city_name";
-////            sql = "select distinct city from sqmdb_5g.roaming_area where province = ? order by city";
-//
-//        } else {
-//            sql = "select distinct city_name as city from sqmdb_5g.user_terminal_status_5g_abstract where province_name=? and roaming_city_name!='null' order by city_name";
-////            sql = "select distinct city from sqmdb_5g.local_area where province = ? order by city";
-//        }
-//        try {
-//            psmt = conn.prepareStatement(sql);
-//            psmt.setQueryTimeout(60 * 10);
-//            psmt.setString(1, province);
-//
-//            ResultSet rs = psmt.executeQuery();
-//            while (rs.next()) {
-//                String city = rs.getString("city");
-//                res.add(city);
-////                if(res.keySet().contains(province)){
-////                    List<String> ls = res.get(province);
-////                    ls.add(city);
-////                }else {
-////                    List<String>as = new ArrayList<>();
-////                    as.add(city);
-////                    res.put(province,as);
-////                }
-//            }
-//        } catch (SQLException e) {
-//            e.printStackTrace();
-//        }
-//        return res;
-//    }
-
-
-//    public static List<String> initProvince(String type) {
-//        PreparedStatement psmt = null;
-//        if (type == null) {
-//            type = "roaming";
-//        }
-//        String sql = "";
-////        String sql = "select distinct roaming_province_name as province from sqmdb_5g.user_terminal_status_5g_abstract order by roaming_province_name";
-//////        Map<String,List<String>>res = new HashMap<>();
-//        List<String> res = new ArrayList<>();
-//        if ("roaming".equals(type)) {
-//            sql = "select distinct roaming_province_name as province from sqmdb_5g.user_terminal_status_5g_abstract order by roaming_province_name";
-////            sql = "select distinct province from sqmdb_5g.roaming_area order by province";
-//
-//        } else {
-//            sql = "select distinct province_name as province from sqmdb_5g.user_terminal_status_5g_abstract order by province_name";
-////            sql = "select distinct province from sqmdb_5g.local_area order by province";
-//        }
-//        try {
-//            psmt = conn.prepareStatement(sql);
-//            psmt.setQueryTimeout(60 * 10);
-//
-//            ResultSet rs = psmt.executeQuery();
-//            while (rs.next()) {
-//                String province = rs.getString("province");
-//                res.add(province);
-////                if(res.keySet().contains(province)){
-////                    List<String> ls = res.get(province);
-////                    ls.add(city);
-////                }else {
-////                    List<String>as = new ArrayList<>();
-////                    as.add(city);
-////                    res.put(province,as);
-////                }
-//            }
-//        } catch (SQLException e) {
-//            e.printStackTrace();
-//        }
-//        return res;
-//    }
-
+    // public static List<String> initCitys(String type, String province) {
+    // PreparedStatement psmt = null;
+    // if (type == null) {
+    // type = "roaming";
+    // }
+    //
+    // String sql = "select distinct roaming_city_name as city from
+    // sqmdb_5g.user_terminal_status_5g_abstract where roaming_province_name=? and
+    // roaming_city_name!='null' order by roaming_city_name";
+    //// Map<String,List<String>>res = new HashMap<>();
+    // List<String> res = new ArrayList<>();
+    // if ("roaming".equals(type)) {
+    // sql = "select distinct roaming_city_name as city from
+    // sqmdb_5g.user_terminal_status_5g_abstract where roaming_province_name=? and
+    // roaming_city_name!='null' order by roaming_city_name";
+    //// sql = "select distinct city from sqmdb_5g.roaming_area where province = ?
+    // order by city";
+    //
+    // } else {
+    // sql = "select distinct city_name as city from
+    // sqmdb_5g.user_terminal_status_5g_abstract where province_name=? and
+    // roaming_city_name!='null' order by city_name";
+    //// sql = "select distinct city from sqmdb_5g.local_area where province = ?
+    // order by city";
+    // }
+    // try {
+    // psmt = conn.prepareStatement(sql);
+    // psmt.setQueryTimeout(60 * 10);
+    // psmt.setString(1, province);
+    //
+    // ResultSet rs = psmt.executeQuery();
+    // while (rs.next()) {
+    // String city = rs.getString("city");
+    // res.add(city);
+    //// if(res.keySet().contains(province)){
+    //// List<String> ls = res.get(province);
+    //// ls.add(city);
+    //// }else {
+    //// List<String>as = new ArrayList<>();
+    //// as.add(city);
+    //// res.put(province,as);
+    //// }
+    // }
+    // } catch (SQLException e) {
+    // e.printStackTrace();
+    // }
+    // return res;
+    // }
+
+    // public static List<String> initProvince(String type) {
+    // PreparedStatement psmt = null;
+    // if (type == null) {
+    // type = "roaming";
+    // }
+    // String sql = "";
+    //// String sql = "select distinct roaming_province_name as province from
+    // sqmdb_5g.user_terminal_status_5g_abstract order by roaming_province_name";
+    ////// Map<String,List<String>>res = new HashMap<>();
+    // List<String> res = new ArrayList<>();
+    // if ("roaming".equals(type)) {
+    // sql = "select distinct roaming_province_name as province from
+    // sqmdb_5g.user_terminal_status_5g_abstract order by roaming_province_name";
+    //// sql = "select distinct province from sqmdb_5g.roaming_area order by
+    // province";
+    //
+    // } else {
+    // sql = "select distinct province_name as province from
+    // sqmdb_5g.user_terminal_status_5g_abstract order by province_name";
+    //// sql = "select distinct province from sqmdb_5g.local_area order by
+    // province";
+    // }
+    // try {
+    // psmt = conn.prepareStatement(sql);
+    // psmt.setQueryTimeout(60 * 10);
+    //
+    // ResultSet rs = psmt.executeQuery();
+    // while (rs.next()) {
+    // String province = rs.getString("province");
+    // res.add(province);
+    //// if(res.keySet().contains(province)){
+    //// List<String> ls = res.get(province);
+    //// ls.add(city);
+    //// }else {
+    //// List<String>as = new ArrayList<>();
+    //// as.add(city);
+    //// res.put(province,as);
+    //// }
+    // }
+    // } catch (SQLException e) {
+    // e.printStackTrace();
+    // }
+    // return res;
+    // }
 
 }

+ 0 - 17
src/test/java/com/nokia/hb/Test.java

@@ -1,17 +0,0 @@
-package com.nokia.hb;
-
-import com.alibaba.fastjson.JSON;
-import com.nokia.hb.utils.DbUtil;
-import org.skyscreamer.jsonassert.JSONCompare;
-
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-public class Test {
-    public static void main(String[] args) {
-//        HashMap<String, List<Object>> hb = DbUtil.search("20210720", "20210722", "5G终端用户数", "30", "河北", "'石家庄','唐山'");
-//        System.out.println(hb);
-
-    }
-}