|
@@ -6,13 +6,11 @@ import com.nokia.hb.Pojo.TreeNode;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.util.DigestUtils;
|
|
|
+import org.springframework.util.StringUtils;
|
|
|
|
|
|
import javax.servlet.http.HttpSession;
|
|
|
import java.sql.*;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
+import java.util.*;
|
|
|
|
|
|
|
|
|
public class DbUtil {
|
|
@@ -107,8 +105,23 @@ public class DbUtil {
|
|
|
}
|
|
|
|
|
|
|
|
|
- public static RetData renderTable(String citys, String indicators, String ttype, String sdate) {
|
|
|
+ public static RetData renderTable(String citys, String indicators, String ttype, String sdate, HttpSession session) {
|
|
|
+ log.debug("indicators: {}", indicators);
|
|
|
+ log.debug("citys: {}", citys);
|
|
|
+ String[] idArray = StringUtils.delete(citys, "'").split(",");
|
|
|
+ Map<String, String> areas = (Map<String, String>) session.getAttribute("areas");
|
|
|
+ log.debug("{} areas: {}", areas.keySet().size(), areas.keySet());
|
|
|
+ log.debug("{} idArray: {}", idArray.length, Arrays.toString(idArray));
|
|
|
+ // 地区权限校验
|
|
|
+ for (String t : idArray) {
|
|
|
+ if (!areas.containsKey(t)) {
|
|
|
+ log.debug("没有权限的地区编号: {}", t);
|
|
|
+ return new RetData(null, null, 1);
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
+ citys = getQuxiansByIds(citys);
|
|
|
+ log.debug("citys: {}", citys);
|
|
|
String sql = "select b.* from \n" +
|
|
|
"(select eci from pm_parse.per_cfg_cell where quxian in (" + citys + ")) a\n" +
|
|
|
"inner join \n" +
|
|
@@ -149,13 +162,34 @@ public class DbUtil {
|
|
|
} catch (SQLException e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
- return new RetData(cols, datas);
|
|
|
+ return new RetData(cols, datas, 0);
|
|
|
+ }
|
|
|
+
|
|
|
+ private static String getQuxiansByIds(String citys) {
|
|
|
+ String sql = "select distinct quxian from pm_parse.per_cfg_area where id in (" + citys + ")";
|
|
|
+ PreparedStatement psmt = null;
|
|
|
+ try {
|
|
|
+ psmt = conn.prepareStatement(sql);
|
|
|
+ psmt.setQueryTimeout(60 * 10);
|
|
|
+ ResultSet rs = psmt.executeQuery();
|
|
|
+ StringBuilder sb = new StringBuilder();
|
|
|
+ while (rs.next()) {
|
|
|
+ String quxian = rs.getString("quxian");
|
|
|
+ sb.append("'").append(quxian).append("'").append(",");
|
|
|
+ }
|
|
|
+
|
|
|
+ sb.deleteCharAt(sb.length() - 1);
|
|
|
+ return sb.toString();
|
|
|
+ } catch (SQLException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ return null;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
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("地市选择", "0", new ArrayList<>());
|
|
|
+ TreeNode allTree = new TreeNode("地市选择", "地市选择", new ArrayList<>());
|
|
|
int i = 0;
|
|
|
try {
|
|
|
psmt = conn.prepareStatement(sql);
|
|
@@ -164,9 +198,10 @@ public class DbUtil {
|
|
|
Map<String, List<TreeNode>> m = new HashMap<>();
|
|
|
|
|
|
while (rs.next()) {
|
|
|
+ String id = rs.getString("id");
|
|
|
String city = rs.getString("city");
|
|
|
String quxian = rs.getString("quxian");
|
|
|
- TreeNode t = new TreeNode(quxian, "country", null);
|
|
|
+ TreeNode t = new TreeNode(quxian, id, null);
|
|
|
if (m.keySet().contains(city)) {
|
|
|
m.get(city).add(t);
|
|
|
} else {
|
|
@@ -179,7 +214,7 @@ public class DbUtil {
|
|
|
|
|
|
|
|
|
for (String s : m.keySet()) {
|
|
|
- allTree.getChildren().add(new TreeNode(s, "city", m.get(s)));
|
|
|
+ allTree.getChildren().add(new TreeNode(s, s, m.get(s)));
|
|
|
}
|
|
|
} catch (SQLException e) {
|
|
|
e.printStackTrace();
|
|
@@ -187,6 +222,7 @@ public class DbUtil {
|
|
|
List<TreeNode> res = new ArrayList<>();
|
|
|
allTree.setSpread(true);
|
|
|
res.add(allTree);
|
|
|
+ log.debug("res: {}", res);
|
|
|
return res;
|
|
|
}
|
|
|
|
|
@@ -194,7 +230,7 @@ public class DbUtil {
|
|
|
// 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("指标选择", "0", new ArrayList<>());
|
|
|
+ TreeNode allTree = new TreeNode("指标选择", "指标选择", new ArrayList<>());
|
|
|
try {
|
|
|
psmt = conn.prepareStatement(sql);
|
|
|
psmt.setQueryTimeout(60 * 10);
|
|
@@ -217,7 +253,7 @@ public class DbUtil {
|
|
|
}
|
|
|
int i = 0;
|
|
|
for (String s : m.keySet()) {
|
|
|
- allTree.getChildren().add(new TreeNode(s, "" + i++, m.get(s)));
|
|
|
+ allTree.getChildren().add(new TreeNode(s, s, m.get(s)));
|
|
|
}
|
|
|
} catch (SQLException e) {
|
|
|
e.printStackTrace();
|
|
@@ -527,6 +563,7 @@ public class DbUtil {
|
|
|
public static Object userLogin(String username, String password, HttpSession session) {
|
|
|
String passwordMd5 = DigestUtils.md5DigestAsHex(password.getBytes());
|
|
|
log.debug("username: {}, password: {}, passwordMd5: {}", username, password, passwordMd5);
|
|
|
+ // 查询用户信息
|
|
|
String sql = "select * from pm_parse.user where username='" + username + "'";
|
|
|
PreparedStatement psmt = null;
|
|
|
try {
|
|
@@ -540,14 +577,27 @@ public class DbUtil {
|
|
|
|
|
|
String passwordStore = rs.getString("password");
|
|
|
log.debug("passwordStore: {}", passwordStore);
|
|
|
- // 密码正确
|
|
|
- if (passwordMd5.equals(passwordStore)) {
|
|
|
- session.setMaxInactiveInterval(30*60);
|
|
|
- session.setAttribute("username", username);
|
|
|
- return 1;
|
|
|
+ // 密码错误
|
|
|
+ if (!passwordMd5.equals(passwordStore)) {
|
|
|
+ return 0;
|
|
|
}
|
|
|
|
|
|
- return 0;
|
|
|
+ // 查询地区权限
|
|
|
+ sql = "select area_id 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 id = rs.getString("area_id");
|
|
|
+ map.put(id, "");
|
|
|
+ }
|
|
|
+
|
|
|
+ log.debug("areas: {}", map.keySet());
|
|
|
+ session.setMaxInactiveInterval(30*60);
|
|
|
+ session.setAttribute("username", username);
|
|
|
+ session.setAttribute("areas", map);
|
|
|
+ return 1;
|
|
|
} catch (SQLException e) {
|
|
|
e.printStackTrace();
|
|
|
return 0;
|