|
@@ -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://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<>());
|
|
|
-
|
|
|
- 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_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);
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- for (String s : m.keySet()) {
|
|
|
- allTree.getChildren().add(new TreeNode(s, s, m.get(s)));
|
|
|
- }
|
|
|
- } catch (SQLException e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|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|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- 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.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;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-}
|
|
|
+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://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<>());
|
|
|
+
|
|
|
+ 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_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);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+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
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ 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.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;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+}
|