Showing
1 changed file
with
24 additions
and
12 deletions
@@ -66,21 +66,33 @@ public class MonitorAlarmServiceImpl { | @@ -66,21 +66,33 @@ public class MonitorAlarmServiceImpl { | ||
66 | List<String> idcList = JSONArray.parseArray(idcs, String.class); | 66 | List<String> idcList = JSONArray.parseArray(idcs, String.class); |
67 | int pageSize = req.getPageSize(); | 67 | int pageSize = req.getPageSize(); |
68 | int currentPage = req.getCurrentPage() - 1; | 68 | int currentPage = req.getCurrentPage() - 1; |
69 | - String querySql = "SELECT sms_content, info, send_status,type,idc FROM monitor_alarm WHERE event = 'alarm' "; | ||
70 | - String countSql = "SELECT COUNT(sms_content) FROM monitor_alarm WHERE event = 'alarm' "; | ||
71 | - StringBuilder conditionBuilder = new StringBuilder(" "); | ||
72 | - if (CollectionUtils.isEmpty(idcList)) {//默认查询所有的 | ||
73 | - conditionBuilder.append(" and type != 'work_system' "); | ||
74 | - }else{ | ||
75 | - String s = ""; | 69 | + |
70 | + String whereSql= " WHERE event = 'alarm' and type != 'work_system' "; | ||
71 | + | ||
72 | + StringBuilder conditionBuilder = new StringBuilder(); | ||
73 | + if (!CollectionUtils.isEmpty(idcList)) { | ||
76 | for(String item : idcList ){ | 74 | for(String item : idcList ){ |
77 | - s = s.concat("idc=\'").concat(item).concat("\'").concat(" or "); | 75 | + if(conditionBuilder.length()>0){ |
76 | + conditionBuilder.append(" or "); | ||
77 | + } | ||
78 | + conditionBuilder.append(" idc='").append(item).append("' "); | ||
78 | } | 79 | } |
79 | - s = StringUtils.stripEnd(s, " or "); | ||
80 | - conditionBuilder.append(" and ( ").append(s).append(" ) "); | 80 | + if(conditionBuilder.length()>0){ |
81 | + conditionBuilder.insert(0," and ( ").append(" ) "); | ||
82 | + whereSql += conditionBuilder.toString(); | ||
83 | + } | ||
84 | + | ||
81 | } | 85 | } |
82 | - querySql += conditionBuilder.toString() + " ORDER BY time DESC LIMIT " + pageSize + " OFFSET " + pageSize * currentPage; | ||
83 | - countSql += conditionBuilder.toString(); | 86 | + |
87 | + | ||
88 | + | ||
89 | + String querySql = "SELECT sms_content, info, send_status,type,idc FROM monitor_alarm " | ||
90 | + +whereSql | ||
91 | + + " ORDER BY time DESC LIMIT " + pageSize + " OFFSET " + pageSize * currentPage; | ||
92 | + | ||
93 | + String countSql = "SELECT COUNT(sms_content) FROM monitor_alarm " | ||
94 | + +whereSql; | ||
95 | + | ||
84 | LOGGER.info("getAlarmMsgPageList -- querySql is {} ", querySql); | 96 | LOGGER.info("getAlarmMsgPageList -- querySql is {} ", querySql); |
85 | QueryResult queryResult = influxDataReporter.queryResult(influxDBName, querySql, YOMO_MONITOR); | 97 | QueryResult queryResult = influxDataReporter.queryResult(influxDBName, querySql, YOMO_MONITOR); |
86 | List<AlarmMsgModel> alarmMsgList = getAlarmMsgModelFromQR(queryResult); | 98 | List<AlarmMsgModel> alarmMsgList = getAlarmMsgModelFromQR(queryResult); |
-
Please register or login to post a comment