瀏覽代碼

feat: 地区权限改为校验city

weijianghai 2 年之前
父節點
當前提交
41580ed91e

+ 2 - 2
src/main/java/com/nokia/hb/Controller/TemplateController.java

@@ -39,9 +39,9 @@ public class TemplateController {
 
     @PostMapping("renderTable")
     @ResponseBody
-    public RetData renderTable(String citys, String indicators, String ttype, String sdate, HttpSession session) {
+    public RetData renderTable(String citys, String quxians, String indicators, String ttype, String sdate, HttpSession session) {
 
-        return DbUtil.renderTable(citys,indicators,ttype,sdate,session);
+        return DbUtil.renderTable(citys,quxians,indicators,ttype,sdate,session);
     }
     
     @PostMapping({"conditionRenderTable"})

+ 12 - 11
src/main/java/com/nokia/hb/Pojo/RetData.java

@@ -5,9 +5,9 @@ import java.util.Map;
 
 public class RetData {
     /**
-     * 0:有权限,1:无权限
+     * 错误信息
      */
-    Integer ban;
+    String msg;
     List<Col> cols;
     List<Map<String,String>> datas;
 
@@ -19,10 +19,10 @@ public class RetData {
         this.datas = datas;
     }
 
-    public RetData(List<Col> cols, List<Map<String, String>> datas, Integer ban) {
+    public RetData(List<Col> cols, List<Map<String, String>> datas, String msg) {
         this.cols = cols;
         this.datas = datas;
-        this.ban = ban;
+        this.msg = msg;
     }
 
     public List<Col> getCols() {
@@ -41,19 +41,20 @@ public class RetData {
         this.datas = datas;
     }
 
-    public Integer getBan() {
-        return ban;
+    public String getMsg() {
+        return msg;
     }
 
-    public void setBan(Integer ban) {
-        this.ban = ban;
+    public void setMsg(String msg) {
+        this.msg = msg;
     }
 
     @Override
     public String toString() {
-        return "{" +
-                "cols:" + cols +
-                ", datas:" + datas +
+        return "RetData{" +
+                "msg='" + msg + '\'' +
+                ", cols=" + cols +
+                ", datas=" + datas +
                 '}';
     }
 }

+ 18 - 36
src/main/java/com/nokia/hb/utils/DbUtil.java

@@ -105,32 +105,33 @@ public class DbUtil {
     }
     
     
-    public static RetData renderTable(String citys, String indicators, String ttype, String sdate, HttpSession session) {
+    public static RetData renderTable(String citys, String quxians, String indicators, String ttype, String sdate, HttpSession session) {
         log.debug("indicators: {}", indicators);
         log.debug("citys: {}", citys);
-        String[] idArray = StringUtils.delete(citys, "'").split(",");
+        log.debug("quxians: {}", quxians);
+        // 获取城市数组
+        String[] cityArrays = 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));
+        log.debug("{} cityArrays: {}", cityArrays.length, Arrays.toString(cityArrays));
         // 地区权限校验
-        for (String t : idArray) {
+        for (String t : cityArrays) {
             if (!areas.containsKey(t)) {
-                log.debug("没有权限的地区编号: {}", t);
-                return new RetData(null, null, 1);
+                log.debug("没有权限的city: {}", t);
+                return new RetData(null, null, "没有" + t + "的权限");
             }
         }
 
-        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" +
+                "(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='" + sdate + "') 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 (" + citys + ")) a\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='" + sdate + "') b\n" +
                     "on a.eci=b.eci";
@@ -162,28 +163,7 @@ public class DbUtil {
         } catch (SQLException e) {
             e.printStackTrace();
         }
-        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;
-        }
+        return new RetData(cols, datas);
     }
 
     public static List<TreeNode> initTreeCitys() {
@@ -198,9 +178,9 @@ 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");
+                String id = city + quxian;
                 TreeNode t = new TreeNode(quxian, id, null);
                 if (m.keySet().contains(city)) {
                     m.get(city).add(t);
@@ -561,6 +541,7 @@ public class DbUtil {
     }
 
     public static Object userLogin(String username, String password, HttpSession session) {
+        // 计算密码md5
         String passwordMd5 = DigestUtils.md5DigestAsHex(password.getBytes());
         log.debug("username: {}, password: {}, passwordMd5: {}", username, password, passwordMd5);
         // 查询用户信息
@@ -583,17 +564,18 @@ public class DbUtil {
             }
 
             // 查询地区权限
-            sql = "select area_id from pm_parse.user_area where username='" + username +"'";
+            sql = "select area from pm_parse.user_area where username='" + username +"'";
             psmt = conn.prepareStatement(sql);
             psmt.setQueryTimeout(60 * 10);
             rs = psmt.executeQuery();
             Map<String, String> map = new HashMap<>();
             while (rs.next()) {
-                String id = rs.getString("area_id");
-                map.put(id, "");
+                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);

+ 13 - 8
src/main/resources/templates/template.html

@@ -277,7 +277,7 @@
             });
 
         }
-        function renderTable(table, citys, indicators, ttype, sdate) {
+        function renderTable(table, citys, quxians, indicators, ttype, sdate) {
             console.log('renderTable')
 
             $.ajax({
@@ -286,14 +286,16 @@
                 async: false,
                 data: {
                     "citys": citys,
+                    "quxians": quxians,
                     "indicators": indicators,
                     "ttype": ttype,
                     "sdate": sdate
                 },
                 success: function (r) {
                     dataA = r;
-                    if (r.ban === 1) {
-                        layer.msg('没有权限');
+                    // 没有权限提示
+                    if (r?.msg && r.msg.length > 0) {
+                        layer.msg(r.msg);
                         return;
                     }
 
@@ -407,16 +409,19 @@
             console.log(checkData1)
             console.log(checkData2)
 
+            const quxianA = [];
             var citysA = new Array();
             checkData1.forEach(eee => {
+                citysA.push("'" + eee.title + "'")
                 eee.children.forEach(ee => {
-
-                    citysA.push("'" + ee.id + "'")
-
+                    quxianA.push("'" + ee.title + "'")
                 })
             });
+
+            const quxians = quxianA.join(',')
             citys = citysA.join(',')
-            console.log(citys)
+            console.log(`citys: ${citys}`)
+            console.log(`quxians: ${quxians}`)
             var indicatorsA = new Array();
             checkData2.forEach(eee => {
                 eee.children.forEach(ee => {
@@ -430,7 +435,7 @@
             let ttype = $('#timeType').val()
             let sdate = $('#time1').val()
 
-            renderTable(table, citys, indicators, ttype, sdate)
+            renderTable(table, citys, quxians,indicators, ttype, sdate)
 
             return false;
         }