|
@@ -1,836 +1,836 @@
|
|
|
-package com.nokia.hb.utils;
|
|
|
-
|
|
|
-import com.nokia.hb.Pojo.Col;
|
|
|
-import com.nokia.hb.Pojo.RetData;
|
|
|
-import com.nokia.hb.Pojo.TreeNode;
|
|
|
-import org.slf4j.Logger;
|
|
|
-import org.slf4j.LoggerFactory;
|
|
|
-import org.springframework.util.StringUtils;
|
|
|
-
|
|
|
-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 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://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);
|
|
|
- } catch (SQLException e) {
|
|
|
- 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"));
|
|
|
- }
|
|
|
- } catch (SQLException e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- 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)));
|
|
|
- }
|
|
|
- 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();
|
|
|
- }
|
|
|
- return new RetData(cols, datas);
|
|
|
- }
|
|
|
-
|
|
|
- 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);
|
|
|
- log.debug("ttype: {}", ttype);
|
|
|
- log.debug("sdate: {}", sdate);
|
|
|
- // 获取城市数组
|
|
|
- String[] cityArray = StringUtils.delete(citys, "'").split(",");
|
|
|
- // 获取拥有的城市权限
|
|
|
- Map<String, String> areas = (Map<String, String>) session.getAttribute("areas");
|
|
|
- log.debug("{} areas: {}", areas.keySet().size(), areas.keySet());
|
|
|
- log.debug("{} cityArray: {}", cityArray.length, Arrays.toString(cityArray));
|
|
|
- // 地区权限校验
|
|
|
- for (String t : cityArray) {
|
|
|
- if (!areas.containsKey(t)) {
|
|
|
- log.debug("没有权限的city: {}", t);
|
|
|
- return new RetData(null, null, "没有" + t + "的权限");
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- String[] timeArray = sdate.split(" - ");
|
|
|
- String startTime = timeArray[0];
|
|
|
- String endTime = timeArray[1];
|
|
|
-
|
|
|
- String sql = "select b.* from \n" +
|
|
|
- "(select eci from pm_parse.per_cfg_cell where quxian in (" + quxians + ")) a\n" +
|
|
|
- "inner join \n" +
|
|
|
- "(select eci," + indicators + " from pm_parse.pm_4g_" + ttype +
|
|
|
- " where sdate>='" + startTime +
|
|
|
- "' and sdate <= '" + endTime + "') b\n" +
|
|
|
- "on a.eci=b.eci";
|
|
|
-
|
|
|
- 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 +
|
|
|
- " 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(60 * 10);
|
|
|
- ResultSet rs = psmt.executeQuery();
|
|
|
- ResultSetMetaData rsmd = rs.getMetaData();
|
|
|
- List<String> heads = new ArrayList<>();
|
|
|
-
|
|
|
- for (int i = 1; i <= rsmd.getColumnCount(); i++) {
|
|
|
- String columnName = rsmd.getColumnName(i);
|
|
|
- heads.add(columnName);
|
|
|
- cols.add(new Col(columnName, 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();
|
|
|
- }
|
|
|
- return new RetData(cols, datas);
|
|
|
- }
|
|
|
-
|
|
|
- public static List<TreeNode> initTreeCitys() {
|
|
|
- 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;
|
|
|
- try {
|
|
|
- psmt = conn.prepareStatement(sql);
|
|
|
- psmt.setQueryTimeout(60 * 10);
|
|
|
- ResultSet rs = psmt.executeQuery();
|
|
|
- Map<String, List<TreeNode>> m = new HashMap<>();
|
|
|
-
|
|
|
- while (rs.next()) {
|
|
|
- String city = rs.getString("city");
|
|
|
- String quxian = rs.getString("quxian");
|
|
|
- String id = city + quxian;
|
|
|
- TreeNode t = new TreeNode(quxian, id, null);
|
|
|
- if (m.keySet().contains(city)) {
|
|
|
- m.get(city).add(t);
|
|
|
- } else {
|
|
|
- List<TreeNode> l = new ArrayList<>();
|
|
|
- l.add(t);
|
|
|
- m.put(city, l);
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- for (String s : m.keySet()) {
|
|
|
- allTree.getChildren().add(new TreeNode(s, s, m.get(s)));
|
|
|
- }
|
|
|
- } catch (SQLException e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- List<TreeNode> res = new ArrayList<>();
|
|
|
- allTree.setSpread(true);
|
|
|
- res.add(allTree);
|
|
|
- log.debug("initTreeCitys: {}", res);
|
|
|
- return res;
|
|
|
- }
|
|
|
-
|
|
|
- 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_id,indicator_type,indicator_cn,indicator_en";
|
|
|
- PreparedStatement psmt = null;
|
|
|
- TreeNode allTree = new TreeNode("指标选择", "指标选择", new ArrayList<>());
|
|
|
- try {
|
|
|
- psmt = conn.prepareStatement(sql);
|
|
|
- psmt.setQueryTimeout(60 * 10);
|
|
|
- ResultSet rs = psmt.executeQuery();
|
|
|
- Map<String, List<TreeNode>> m = new HashMap<>();
|
|
|
-
|
|
|
- while (rs.next()) {
|
|
|
- String indicator_type = rs.getString("indicator_type");
|
|
|
- String indicator_cn = rs.getString("indicator_cn");
|
|
|
- String indicator_id = rs.getString("indicator_id");
|
|
|
- TreeNode t = new TreeNode(indicator_cn, indicator_id, null);
|
|
|
- if (m.keySet().contains(indicator_type)) {
|
|
|
- m.get(indicator_type).add(t);
|
|
|
- } else {
|
|
|
- List<TreeNode> l = new ArrayList<>();
|
|
|
- l.add(t);
|
|
|
- m.put(indicator_type, l);
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- // int i = 0;
|
|
|
- for (String s : m.keySet()) {
|
|
|
- allTree.getChildren().add(new TreeNode(s, s, m.get(s)));
|
|
|
- }
|
|
|
- } catch (SQLException e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- List<TreeNode> res = new ArrayList<>();
|
|
|
- allTree.setSpread(true);
|
|
|
- res.add(allTree);
|
|
|
- log.debug("initTreeIndicator: {}", res);
|
|
|
- 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 Object userLogin(String username, String password, HttpSession session) {
|
|
|
- log.debug("username: {}, password: {}", username, password);
|
|
|
- // 查询用户信息
|
|
|
- String sql = "select * from pm_parse.user where username='" + username + "'";
|
|
|
- PreparedStatement psmt;
|
|
|
- try {
|
|
|
- psmt = conn.prepareStatement(sql);
|
|
|
- psmt.setQueryTimeout(60 * 10);
|
|
|
- ResultSet rs = psmt.executeQuery();
|
|
|
- // 没有查到数据
|
|
|
- if (!rs.next()) {
|
|
|
- return "用户名或密码错误!";
|
|
|
- }
|
|
|
-
|
|
|
- String passwordStore = rs.getString("password");
|
|
|
- log.debug("passwordStore: {}", passwordStore);
|
|
|
- // 密码错误
|
|
|
- if (!password.equals(passwordStore)) {
|
|
|
- return "用户名或密码错误!";
|
|
|
- }
|
|
|
-
|
|
|
- // 查询地区权限
|
|
|
- sql = "select area from pm_parse.user_area where username='" + username + "'";
|
|
|
- psmt = conn.prepareStatement(sql);
|
|
|
- psmt.setQueryTimeout(60 * 10);
|
|
|
- rs = psmt.executeQuery();
|
|
|
- Map<String, String> map = new HashMap<>();
|
|
|
- while (rs.next()) {
|
|
|
- String area = rs.getString("area");
|
|
|
- map.put(area, "");
|
|
|
- }
|
|
|
-
|
|
|
- log.debug("areas: {}", map.keySet());
|
|
|
- // 保存session
|
|
|
- session.setMaxInactiveInterval(30 * 60);
|
|
|
- session.setAttribute("username", username);
|
|
|
- session.setAttribute("areas", map);
|
|
|
- return null;
|
|
|
- } catch (SQLException e) {
|
|
|
- e.printStackTrace();
|
|
|
- return "数据库异常!";
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- public static Object addTemplate(String templateName, String indicators, HttpSession session) {
|
|
|
- log.debug("templateName: {}", templateName);
|
|
|
- log.debug("indicators: {}", indicators);
|
|
|
- String username = (String) session.getAttribute("username");
|
|
|
- long id = System.currentTimeMillis();
|
|
|
- String sql = "insert into pm_parse.indicator_template (id, template_name, username) values (?, ?, ?)";
|
|
|
- PreparedStatement psmt;
|
|
|
- try {
|
|
|
- conn.setAutoCommit(false);
|
|
|
- psmt = conn.prepareStatement(sql);
|
|
|
- psmt.setObject(1, id);
|
|
|
- psmt.setObject(2, templateName);
|
|
|
- psmt.setObject(3, username);
|
|
|
- int rs = psmt.executeUpdate();
|
|
|
- if (rs < 1) {
|
|
|
- conn.rollback();
|
|
|
- return "添加失败";
|
|
|
- }
|
|
|
-
|
|
|
- String[] indicatorArray = StringUtils.delete(indicators, "'").split(",");
|
|
|
- sql = "insert into pm_parse.indicator_template_item (template_id, indicator_id) values (?, ?)";
|
|
|
- psmt = conn.prepareStatement(sql);
|
|
|
- for (String s : indicatorArray) {
|
|
|
- psmt.setObject(1, id);
|
|
|
- psmt.setObject(2, Integer.valueOf(s));
|
|
|
- rs = psmt.executeUpdate();
|
|
|
- if (rs < 1) {
|
|
|
- conn.rollback();
|
|
|
- return "添加失败";
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- conn.commit();
|
|
|
- } catch (SQLException e) {
|
|
|
- e.printStackTrace();
|
|
|
- try {
|
|
|
- conn.rollback();
|
|
|
- } catch (SQLException ex) {
|
|
|
- e.printStackTrace();
|
|
|
- return "添加失败";
|
|
|
- }
|
|
|
- return "添加失败";
|
|
|
- }
|
|
|
-
|
|
|
- return null;
|
|
|
- }
|
|
|
-
|
|
|
- public static List<TreeNode> initTreeIndicatorTemplate(HttpSession session) {
|
|
|
- // 查询用户指标模板
|
|
|
- String username = (String) session.getAttribute("username");
|
|
|
- String sql = "select id, template_name from pm_parse.indicator_template where username = ?";
|
|
|
- PreparedStatement psmt = null;
|
|
|
- TreeNode allTree = new TreeNode("指标模板选择", "指标模板选择", true, new ArrayList<>());
|
|
|
- try {
|
|
|
- psmt = conn.prepareStatement(sql);
|
|
|
- psmt.setQueryTimeout(60 * 10);
|
|
|
- psmt.setObject(1, username);
|
|
|
- ResultSet rs = psmt.executeQuery();
|
|
|
- while (rs.next()) {
|
|
|
- String id = rs.getString("id");
|
|
|
- String templateName = rs.getString("template_name");
|
|
|
- TreeNode t = new TreeNode(templateName, id, new ArrayList<>());
|
|
|
- allTree.getChildren().add(t);
|
|
|
- // 查询模板下的指标
|
|
|
- sql = "select x.indicator_cn, x.indicator_en from pm_parse.per_cfg_indicator x where x.indicator_id " +
|
|
|
- "in (select indicator_id from pm_parse.indicator_template_item where template_id = ?)";
|
|
|
- psmt = conn.prepareStatement(sql);
|
|
|
- psmt.setQueryTimeout(60 * 10);
|
|
|
- psmt.setObject(1, Long.valueOf(id));
|
|
|
- ResultSet r = psmt.executeQuery();
|
|
|
- while (r.next()) {
|
|
|
- String indicatorCn = r.getString("indicator_cn");
|
|
|
- String indicatorEn = r.getString("indicator_en");
|
|
|
- t.getChildren().add(new TreeNode(indicatorCn, indicatorEn));
|
|
|
- }
|
|
|
- }
|
|
|
- } catch (SQLException e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- List<TreeNode> res = new ArrayList<>();
|
|
|
- res.add(allTree);
|
|
|
- log.debug("initTreeIndicatorTemplate: {}", res);
|
|
|
- return res;
|
|
|
- }
|
|
|
-
|
|
|
- public static Object deleteTemplate(String ids) {
|
|
|
- log.debug("ids: {}", ids);
|
|
|
- String sql = "delete from pm_parse.indicator_template where id in (" + ids + ")";
|
|
|
- PreparedStatement psmt;
|
|
|
- try {
|
|
|
- conn.setAutoCommit(false);
|
|
|
- psmt = conn.prepareStatement(sql);
|
|
|
- int rs = psmt.executeUpdate();
|
|
|
- if (rs < 1) {
|
|
|
- conn.rollback();
|
|
|
- return "删除失败";
|
|
|
- }
|
|
|
-
|
|
|
- sql = "delete from pm_parse.indicator_template_item where template_id in (" + ids + ")";
|
|
|
- psmt = conn.prepareStatement(sql);
|
|
|
- rs = psmt.executeUpdate();
|
|
|
- if (rs < 1) {
|
|
|
- conn.rollback();
|
|
|
- return "删除失败";
|
|
|
- }
|
|
|
-
|
|
|
- conn.commit();
|
|
|
- } catch (SQLException e) {
|
|
|
- e.printStackTrace();
|
|
|
- try {
|
|
|
- conn.rollback();
|
|
|
- } catch (SQLException ex) {
|
|
|
- e.printStackTrace();
|
|
|
- return "删除失败";
|
|
|
- }
|
|
|
- return "删除失败";
|
|
|
- }
|
|
|
-
|
|
|
- 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;
|
|
|
- // }
|
|
|
-
|
|
|
-}
|
|
|
+package com.nokia.hb.utils;
|
|
|
+
|
|
|
+import com.nokia.hb.Pojo.Col;
|
|
|
+import com.nokia.hb.Pojo.RetData;
|
|
|
+import com.nokia.hb.Pojo.TreeNode;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
+import org.springframework.util.StringUtils;
|
|
|
+
|
|
|
+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 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://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);
|
|
|
+ } catch (SQLException e) {
|
|
|
+ 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"));
|
|
|
+ }
|
|
|
+ } catch (SQLException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ 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)));
|
|
|
+ }
|
|
|
+ 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();
|
|
|
+ }
|
|
|
+ return new RetData(cols, datas);
|
|
|
+ }
|
|
|
+
|
|
|
+ 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);
|
|
|
+ log.debug("ttype: {}", ttype);
|
|
|
+ log.debug("sdate: {}", sdate);
|
|
|
+ // 获取城市数组
|
|
|
+ String[] cityArray = StringUtils.delete(citys, "'").split(",");
|
|
|
+ // 获取拥有的城市权限
|
|
|
+ Map<String, String> areas = (Map<String, String>) session.getAttribute("areas");
|
|
|
+ log.debug("{} areas: {}", areas.keySet().size(), areas.keySet());
|
|
|
+ log.debug("{} cityArray: {}", cityArray.length, Arrays.toString(cityArray));
|
|
|
+ // 地区权限校验
|
|
|
+ for (String t : cityArray) {
|
|
|
+ if (!areas.containsKey(t)) {
|
|
|
+ log.debug("没有权限的city: {}", t);
|
|
|
+ return new RetData(null, null, "没有" + t + "的权限");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ String[] timeArray = sdate.split(" - ");
|
|
|
+ String startTime = timeArray[0];
|
|
|
+ String endTime = timeArray[1];
|
|
|
+
|
|
|
+ String sql = "select b.* from \n" +
|
|
|
+ "(select eci from pm_parse.per_cfg_cell where quxian in (" + quxians + ")) a\n" +
|
|
|
+ "inner join \n" +
|
|
|
+ "(select eci," + indicators + " from pm_parse.pm_4g_" + ttype +
|
|
|
+ " where sdate>='" + startTime +
|
|
|
+ "' and sdate <= '" + endTime + "') b\n" +
|
|
|
+ "on a.eci=b.eci";
|
|
|
+
|
|
|
+ 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 +
|
|
|
+ " 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(60 * 10);
|
|
|
+ ResultSet rs = psmt.executeQuery();
|
|
|
+ ResultSetMetaData rsmd = rs.getMetaData();
|
|
|
+ List<String> heads = new ArrayList<>();
|
|
|
+
|
|
|
+ for (int i = 1; i <= rsmd.getColumnCount(); i++) {
|
|
|
+ String columnName = rsmd.getColumnName(i);
|
|
|
+ heads.add(columnName);
|
|
|
+ cols.add(new Col(columnName, 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();
|
|
|
+ }
|
|
|
+ return new RetData(cols, datas);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static List<TreeNode> initTreeCitys() {
|
|
|
+ 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;
|
|
|
+ try {
|
|
|
+ psmt = conn.prepareStatement(sql);
|
|
|
+ psmt.setQueryTimeout(60 * 10);
|
|
|
+ ResultSet rs = psmt.executeQuery();
|
|
|
+ Map<String, List<TreeNode>> m = new HashMap<>();
|
|
|
+
|
|
|
+ while (rs.next()) {
|
|
|
+ String city = rs.getString("city");
|
|
|
+ String quxian = rs.getString("quxian");
|
|
|
+ String id = city + quxian;
|
|
|
+ TreeNode t = new TreeNode(quxian, id, null);
|
|
|
+ if (m.keySet().contains(city)) {
|
|
|
+ m.get(city).add(t);
|
|
|
+ } else {
|
|
|
+ List<TreeNode> l = new ArrayList<>();
|
|
|
+ l.add(t);
|
|
|
+ m.put(city, l);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ for (String s : m.keySet()) {
|
|
|
+ allTree.getChildren().add(new TreeNode(s, s, m.get(s)));
|
|
|
+ }
|
|
|
+ } catch (SQLException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ List<TreeNode> res = new ArrayList<>();
|
|
|
+ allTree.setSpread(true);
|
|
|
+ res.add(allTree);
|
|
|
+ log.debug("initTreeCitys: {}", res);
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+
|
|
|
+ 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_id,indicator_type,indicator_cn,indicator_en";
|
|
|
+ PreparedStatement psmt = null;
|
|
|
+ TreeNode allTree = new TreeNode("指标选择", "指标选择", new ArrayList<>());
|
|
|
+ try {
|
|
|
+ psmt = conn.prepareStatement(sql);
|
|
|
+ psmt.setQueryTimeout(60 * 10);
|
|
|
+ ResultSet rs = psmt.executeQuery();
|
|
|
+ Map<String, List<TreeNode>> m = new HashMap<>();
|
|
|
+
|
|
|
+ while (rs.next()) {
|
|
|
+ String indicator_type = rs.getString("indicator_type");
|
|
|
+ String indicator_cn = rs.getString("indicator_cn");
|
|
|
+ String indicator_id = rs.getString("indicator_id");
|
|
|
+ TreeNode t = new TreeNode(indicator_cn, indicator_id, null);
|
|
|
+ if (m.keySet().contains(indicator_type)) {
|
|
|
+ m.get(indicator_type).add(t);
|
|
|
+ } else {
|
|
|
+ List<TreeNode> l = new ArrayList<>();
|
|
|
+ l.add(t);
|
|
|
+ m.put(indicator_type, l);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ // int i = 0;
|
|
|
+ for (String s : m.keySet()) {
|
|
|
+ allTree.getChildren().add(new TreeNode(s, s, m.get(s)));
|
|
|
+ }
|
|
|
+ } catch (SQLException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ List<TreeNode> res = new ArrayList<>();
|
|
|
+ allTree.setSpread(true);
|
|
|
+ res.add(allTree);
|
|
|
+ log.debug("initTreeIndicator: {}", res);
|
|
|
+ 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 Object userLogin(String username, String password, HttpSession session) {
|
|
|
+ log.debug("username: {}, password: {}", username, password);
|
|
|
+ // 查询用户信息
|
|
|
+ String sql = "select * from pm_parse.user where username='" + username + "'";
|
|
|
+ PreparedStatement psmt;
|
|
|
+ try {
|
|
|
+ psmt = conn.prepareStatement(sql);
|
|
|
+ psmt.setQueryTimeout(60 * 10);
|
|
|
+ ResultSet rs = psmt.executeQuery();
|
|
|
+ // 没有查到数据
|
|
|
+ if (!rs.next()) {
|
|
|
+ return "用户名或密码错误!";
|
|
|
+ }
|
|
|
+
|
|
|
+ String passwordStore = rs.getString("password");
|
|
|
+ log.debug("passwordStore: {}", passwordStore);
|
|
|
+ // 密码错误
|
|
|
+ if (!password.equals(passwordStore)) {
|
|
|
+ return "用户名或密码错误!";
|
|
|
+ }
|
|
|
+
|
|
|
+ // 查询地区权限
|
|
|
+ sql = "select area from pm_parse.user_area where username='" + username + "'";
|
|
|
+ psmt = conn.prepareStatement(sql);
|
|
|
+ psmt.setQueryTimeout(60 * 10);
|
|
|
+ rs = psmt.executeQuery();
|
|
|
+ Map<String, String> map = new HashMap<>();
|
|
|
+ while (rs.next()) {
|
|
|
+ String area = rs.getString("area");
|
|
|
+ map.put(area, "");
|
|
|
+ }
|
|
|
+
|
|
|
+ log.debug("areas: {}", map.keySet());
|
|
|
+ // 保存session
|
|
|
+ session.setMaxInactiveInterval(30 * 60);
|
|
|
+ session.setAttribute("username", username);
|
|
|
+ session.setAttribute("areas", map);
|
|
|
+ return null;
|
|
|
+ } catch (SQLException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ return "数据库异常!";
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static Object addTemplate(String templateName, String indicators, HttpSession session) {
|
|
|
+ log.debug("templateName: {}", templateName);
|
|
|
+ log.debug("indicators: {}", indicators);
|
|
|
+ String username = (String) session.getAttribute("username");
|
|
|
+ long id = System.currentTimeMillis();
|
|
|
+ String sql = "insert into pm_parse.indicator_template (id, template_name, username) values (?, ?, ?)";
|
|
|
+ PreparedStatement psmt;
|
|
|
+ try {
|
|
|
+ conn.setAutoCommit(false);
|
|
|
+ psmt = conn.prepareStatement(sql);
|
|
|
+ psmt.setObject(1, id);
|
|
|
+ psmt.setObject(2, templateName);
|
|
|
+ psmt.setObject(3, username);
|
|
|
+ int rs = psmt.executeUpdate();
|
|
|
+ if (rs < 1) {
|
|
|
+ conn.rollback();
|
|
|
+ return "添加失败";
|
|
|
+ }
|
|
|
+
|
|
|
+ String[] indicatorArray = StringUtils.delete(indicators, "'").split(",");
|
|
|
+ sql = "insert into pm_parse.indicator_template_item (template_id, indicator_id) values (?, ?)";
|
|
|
+ psmt = conn.prepareStatement(sql);
|
|
|
+ for (String s : indicatorArray) {
|
|
|
+ psmt.setObject(1, id);
|
|
|
+ psmt.setObject(2, Integer.valueOf(s));
|
|
|
+ rs = psmt.executeUpdate();
|
|
|
+ if (rs < 1) {
|
|
|
+ conn.rollback();
|
|
|
+ return "添加失败";
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ conn.commit();
|
|
|
+ } catch (SQLException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ try {
|
|
|
+ conn.rollback();
|
|
|
+ } catch (SQLException ex) {
|
|
|
+ e.printStackTrace();
|
|
|
+ return "添加失败";
|
|
|
+ }
|
|
|
+ return "添加失败";
|
|
|
+ }
|
|
|
+
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static List<TreeNode> initTreeIndicatorTemplate(HttpSession session) {
|
|
|
+ // 查询用户指标模板
|
|
|
+ String username = (String) session.getAttribute("username");
|
|
|
+ String sql = "select id, template_name from pm_parse.indicator_template where username = ?";
|
|
|
+ PreparedStatement psmt = null;
|
|
|
+ TreeNode allTree = new TreeNode("指标模板选择", "指标模板选择", true, new ArrayList<>());
|
|
|
+ try {
|
|
|
+ psmt = conn.prepareStatement(sql);
|
|
|
+ psmt.setQueryTimeout(60 * 10);
|
|
|
+ psmt.setObject(1, username);
|
|
|
+ ResultSet rs = psmt.executeQuery();
|
|
|
+ while (rs.next()) {
|
|
|
+ String id = rs.getString("id");
|
|
|
+ String templateName = rs.getString("template_name");
|
|
|
+ TreeNode t = new TreeNode(templateName, id, new ArrayList<>());
|
|
|
+ allTree.getChildren().add(t);
|
|
|
+ // 查询模板下的指标
|
|
|
+ sql = "select x.indicator_cn, x.indicator_en from pm_parse.per_cfg_indicator x where x.indicator_id " +
|
|
|
+ "in (select indicator_id from pm_parse.indicator_template_item where template_id = ?)";
|
|
|
+ psmt = conn.prepareStatement(sql);
|
|
|
+ psmt.setQueryTimeout(60 * 10);
|
|
|
+ psmt.setObject(1, Long.valueOf(id));
|
|
|
+ ResultSet r = psmt.executeQuery();
|
|
|
+ while (r.next()) {
|
|
|
+ String indicatorCn = r.getString("indicator_cn");
|
|
|
+ String indicatorEn = r.getString("indicator_en");
|
|
|
+ t.getChildren().add(new TreeNode(indicatorCn, indicatorEn));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (SQLException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ List<TreeNode> res = new ArrayList<>();
|
|
|
+ res.add(allTree);
|
|
|
+ log.debug("initTreeIndicatorTemplate: {}", res);
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static Object deleteTemplate(String ids) {
|
|
|
+ log.debug("ids: {}", ids);
|
|
|
+ String sql = "delete from pm_parse.indicator_template where id in (" + ids + ")";
|
|
|
+ PreparedStatement psmt;
|
|
|
+ try {
|
|
|
+ conn.setAutoCommit(false);
|
|
|
+ psmt = conn.prepareStatement(sql);
|
|
|
+ int rs = psmt.executeUpdate();
|
|
|
+ if (rs < 1) {
|
|
|
+ conn.rollback();
|
|
|
+ return "删除失败";
|
|
|
+ }
|
|
|
+
|
|
|
+ sql = "delete from pm_parse.indicator_template_item where template_id in (" + ids + ")";
|
|
|
+ psmt = conn.prepareStatement(sql);
|
|
|
+ rs = psmt.executeUpdate();
|
|
|
+ if (rs < 1) {
|
|
|
+ conn.rollback();
|
|
|
+ return "删除失败";
|
|
|
+ }
|
|
|
+
|
|
|
+ conn.commit();
|
|
|
+ } catch (SQLException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ try {
|
|
|
+ conn.rollback();
|
|
|
+ } catch (SQLException ex) {
|
|
|
+ e.printStackTrace();
|
|
|
+ return "删除失败";
|
|
|
+ }
|
|
|
+ return "删除失败";
|
|
|
+ }
|
|
|
+
|
|
|
+ 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;
|
|
|
+ // }
|
|
|
+
|
|
|
+}
|