Authored by FengRuwei

javapp 搜索

@@ -2,6 +2,7 @@ package com.monitor.influxdb.mapper; @@ -2,6 +2,7 @@ package com.monitor.influxdb.mapper;
2 2
3 import com.alibaba.fastjson.JSONObject; 3 import com.alibaba.fastjson.JSONObject;
4 import com.monitor.model.domain.JavaApiStaticsModel; 4 import com.monitor.model.domain.JavaApiStaticsModel;
  5 +import com.monitor.model.request.JavaApiHisReq;
5 import com.monitor.model.request.JavaApiStatusReq; 6 import com.monitor.model.request.JavaApiStatusReq;
6 7
7 import java.util.List; 8 import java.util.List;
@@ -19,9 +20,9 @@ public interface IJavaApiStaticsMapper { @@ -19,9 +20,9 @@ public interface IJavaApiStaticsMapper {
19 public List<JavaApiStaticsModel> selectlatestJavaApiStaticsList(String influxDBName, List<JavaApiStatusReq> query); 20 public List<JavaApiStaticsModel> selectlatestJavaApiStaticsList(String influxDBName, List<JavaApiStatusReq> query);
20 21
21 22
22 - public List<JavaApiStaticsModel> selectJavaApiStaticHis(String influxDBName, int api_id, int mobj_id, String timeStart, String timeEnd, int limitCount, int offsetCount); 23 + public List<JavaApiStaticsModel> selectJavaApiStaticHis(String influxDBName, JavaApiHisReq req );
23 24
24 - public int countJavaApiStaticHis(String influxDBName, int api_id, int mobj_id, String timeStart, String timeEnd); 25 + public int countJavaApiStaticHis(String influxDBName, JavaApiHisReq req );
25 26
26 27
27 } 28 }
@@ -7,6 +7,7 @@ import com.monitor.common.util.QueryResultUtil; @@ -7,6 +7,7 @@ import com.monitor.common.util.QueryResultUtil;
7 import com.monitor.influxdb.InluxDBSingle; 7 import com.monitor.influxdb.InluxDBSingle;
8 import com.monitor.influxdb.mapper.IJavaApiStaticsMapper; 8 import com.monitor.influxdb.mapper.IJavaApiStaticsMapper;
9 import com.monitor.model.domain.JavaApiStaticsModel; 9 import com.monitor.model.domain.JavaApiStaticsModel;
  10 +import com.monitor.model.request.JavaApiHisReq;
10 import com.monitor.model.request.JavaApiStatusReq; 11 import com.monitor.model.request.JavaApiStatusReq;
11 import org.influxdb.dto.BatchPoints; 12 import org.influxdb.dto.BatchPoints;
12 import org.influxdb.dto.Point; 13 import org.influxdb.dto.Point;
@@ -137,13 +138,34 @@ public class JavaApiStaticsMapper implements IJavaApiStaticsMapper { @@ -137,13 +138,34 @@ public class JavaApiStaticsMapper implements IJavaApiStaticsMapper {
137 } 138 }
138 139
139 @Override 140 @Override
140 - public List<JavaApiStaticsModel> selectJavaApiStaticHis(String influxDBName, int api_id, int mobj_id, String timeStart, String timeEnd, int limitCount, int offsetCount) { 141 + public List<JavaApiStaticsModel> selectJavaApiStaticHis(String influxDBName,JavaApiHisReq req ) {
  142 + int api_id=req.getApiId();
  143 + int mobj_id=req.getMobjId();
  144 + String timeStart=DateFormatUtil.influxDBTimeFormat(req.getStartTime());
  145 + String timeEnd=DateFormatUtil.influxDBTimeFormat(req.getEndTime());
  146 + int limitCount=req.getPageSize();
  147 + int offsetCount=req.getCurrentPage()*req.getPageSize();
  148 +
  149 + String mIp=req.getMIp();
  150 + int status=req.getStatus();
  151 +
  152 +
141 String sql = "select * from " + InfluxDBContants.YOMO_TB_JAVAAPI; 153 String sql = "select * from " + InfluxDBContants.YOMO_TB_JAVAAPI;
142 sql += " where time >= '" + timeStart + "' and time<= '" + timeEnd + "' "; 154 sql += " where time >= '" + timeStart + "' and time<= '" + timeEnd + "' ";
143 if (api_id > 0) 155 if (api_id > 0)
144 sql += " and api_id= " + api_id; 156 sql += " and api_id= " + api_id;
145 - if (mobj_id > 0) 157 + //有mid 直接使用mid检索 不考虑ip
  158 + if (mobj_id > 0) {
146 sql += " and mobj_id= " + mobj_id; 159 sql += " and mobj_id= " + mobj_id;
  160 + }else if(mIp!=null&&!mIp.equals("")){
  161 + sql += " and mobj_ip= '" + mIp+"' ";
  162 + }
  163 + //仅exception
  164 + if(status==0){
  165 + sql += " and is_exception= true ";
  166 + }else if(status==1){
  167 + sql += " and is_exception= false ";
  168 + }
147 sql += " order by time desc LIMIT " + limitCount + " OFFSET " + offsetCount; 169 sql += " order by time desc LIMIT " + limitCount + " OFFSET " + offsetCount;
148 log.info("sql:{}", sql); 170 log.info("sql:{}", sql);
149 Query query = new Query(sql, InfluxDBContants.APP_ALARM); 171 Query query = new Query(sql, InfluxDBContants.APP_ALARM);
@@ -206,13 +228,34 @@ public class JavaApiStaticsMapper implements IJavaApiStaticsMapper { @@ -206,13 +228,34 @@ public class JavaApiStaticsMapper implements IJavaApiStaticsMapper {
206 return list; 228 return list;
207 } 229 }
208 230
209 - public int countJavaApiStaticHis(String influxDBName, int api_id, int mobj_id, String timeStart, String timeEnd) { 231 + public int countJavaApiStaticHis(String influxDBName, JavaApiHisReq req) {
  232 + int api_id=req.getApiId();
  233 + int mobj_id=req.getMobjId();
  234 + String timeStart=DateFormatUtil.influxDBTimeFormat(req.getStartTime());
  235 + String timeEnd=DateFormatUtil.influxDBTimeFormat(req.getEndTime());
  236 + int limitCount=req.getPageSize();
  237 + int offsetCount=req.getCurrentPage()*req.getPageSize();
  238 +
  239 + String mIp=req.getMIp();
  240 + int status=req.getStatus();
  241 +
  242 +
210 String sql = "select count(api_id) from " + InfluxDBContants.YOMO_TB_JAVAAPI; 243 String sql = "select count(api_id) from " + InfluxDBContants.YOMO_TB_JAVAAPI;
211 sql += " where time >= '" + timeStart + "' and time<= '" + timeEnd + "' "; 244 sql += " where time >= '" + timeStart + "' and time<= '" + timeEnd + "' ";
212 if (api_id > 0) 245 if (api_id > 0)
213 sql += " and api_id= " + api_id; 246 sql += " and api_id= " + api_id;
214 - if (mobj_id > 0) 247 + //有mid 直接使用mid检索 不考虑ip
  248 + if (mobj_id > 0) {
215 sql += " and mobj_id= " + mobj_id; 249 sql += " and mobj_id= " + mobj_id;
  250 + }else if(mIp!=null&&!mIp.equals("")){
  251 + sql += " and mobj_ip= '" + mIp+"' ";
  252 + }
  253 + //仅exception
  254 + if(status==0){
  255 + sql += " and is_exception= true ";
  256 + }else if(status==1){
  257 + sql += " and is_exception= false ";
  258 + }
216 259
217 260
218 Query query = new Query(sql, InfluxDBContants.APP_ALARM); 261 Query query = new Query(sql, InfluxDBContants.APP_ALARM);
@@ -3,6 +3,7 @@ package com.monitor.javaserver.ctrl; @@ -3,6 +3,7 @@ package com.monitor.javaserver.ctrl;
3 import com.monitor.javaserver.client.JavaApiClient; 3 import com.monitor.javaserver.client.JavaApiClient;
4 import com.monitor.javaserver.service.IJavaApiStatusService; 4 import com.monitor.javaserver.service.IJavaApiStatusService;
5 import com.monitor.model.page.PageResponse; 5 import com.monitor.model.page.PageResponse;
  6 +import com.monitor.model.request.JavaApiHisReq;
6 import com.monitor.model.request.JavaApiStatusReq; 7 import com.monitor.model.request.JavaApiStatusReq;
7 import com.monitor.model.response.BaseResponse; 8 import com.monitor.model.response.BaseResponse;
8 import com.monitor.model.response.JavaApiStatusRep; 9 import com.monitor.model.response.JavaApiStatusRep;
@@ -23,9 +24,9 @@ import java.util.List; @@ -23,9 +24,9 @@ import java.util.List;
23 */ 24 */
24 @Controller 25 @Controller
25 @RequestMapping("javaApiStatus") 26 @RequestMapping("javaApiStatus")
26 -public class JavaAppInfoCtrl { 27 +public class JavaAppInfoStaticsCtrl {
27 28
28 - Logger log = LoggerFactory.getLogger(JavaAppInfoCtrl.class); 29 + Logger log = LoggerFactory.getLogger(JavaAppInfoStaticsCtrl.class);
29 @Autowired 30 @Autowired
30 IJavaApiStatusService javaApiStatusService; 31 IJavaApiStatusService javaApiStatusService;
31 32
@@ -98,34 +99,29 @@ public class JavaAppInfoCtrl { @@ -98,34 +99,29 @@ public class JavaAppInfoCtrl {
98 99
99 @RequestMapping("/queryhis") 100 @RequestMapping("/queryhis")
100 @ResponseBody 101 @ResponseBody
101 - public BaseResponse getJavaApiStatusHis(@RequestParam(required = false, defaultValue = "0") int api_id,  
102 - @RequestParam(required = false, defaultValue = "0") int mobj_id,  
103 - @RequestParam(required = false, defaultValue = "0") long start_time,  
104 - @RequestParam(required = false, defaultValue = "0") long end_time,  
105 - @RequestParam(required = false, defaultValue = "0") int page,  
106 - @RequestParam(required = false, defaultValue = "10") int pageSize) {  
107 - if (start_time == 0) {  
108 - return getJavaApiStatusHisLatest(api_id, mobj_id); 102 + public BaseResponse getJavaApiStatusHis(@RequestBody JavaApiHisReq req) {
  103 + if (req.getStartTime() == 0) {
  104 + return getJavaApiStatusHisLatest(req.getApiId(), req.getMobjId());
109 } 105 }
110 106
111 - if (end_time == 0)  
112 - end_time = System.currentTimeMillis(); 107 + if (req.getEndTime() == 0)
  108 + req.setEndTime( System.currentTimeMillis());
113 109
114 110
115 BaseResponse baseResponse = new BaseResponse(); 111 BaseResponse baseResponse = new BaseResponse();
116 PageResponse<JavaApiStatusRep> pageResponse = new PageResponse<JavaApiStatusRep>(); 112 PageResponse<JavaApiStatusRep> pageResponse = new PageResponse<JavaApiStatusRep>();
117 try { 113 try {
118 114
119 - int count = javaApiStatusService.countJavaApiStatusHisByTime(api_id, mobj_id, start_time, end_time); 115 + int count = javaApiStatusService.countJavaApiStatusHisByTime(req);
120 116
121 - List<JavaApiStatusRep> javaApiStatusRepList = javaApiStatusService.getJavaApiStatusHisByTime(api_id, mobj_id, start_time, end_time, page, pageSize); 117 + List<JavaApiStatusRep> javaApiStatusRepList = javaApiStatusService.getJavaApiStatusHisByTime(req);
122 pageResponse.setRows(javaApiStatusRepList); 118 pageResponse.setRows(javaApiStatusRepList);
123 - pageResponse.setCurrentPage(page);  
124 - pageResponse.setPageSize(pageSize); 119 + pageResponse.setCurrentPage(req.getCurrentPage());
  120 + pageResponse.setPageSize(req.getPageSize());
125 pageResponse.setTotal(count); 121 pageResponse.setTotal(count);
126 baseResponse.setData(pageResponse); 122 baseResponse.setData(pageResponse);
127 } catch (Exception e) { 123 } catch (Exception e) {
128 - log.warn("queryhis failed apiId :{} mobjId:{} start_time:{} endTime:{} ,page:{} ", api_id, mobj_id, start_time, end_time, page, e); 124 + log.warn("queryhis failed req {}", req, e);
129 baseResponse.setCode(400); 125 baseResponse.setCode(400);
130 baseResponse.setMessage(e.getMessage()); 126 baseResponse.setMessage(e.getMessage());
131 } 127 }
1 package com.monitor.javaserver.service; 1 package com.monitor.javaserver.service;
2 2
  3 +import com.monitor.model.request.JavaApiHisReq;
3 import com.monitor.model.request.JavaApiStatusReq; 4 import com.monitor.model.request.JavaApiStatusReq;
4 import com.monitor.model.response.JavaApiStatusRep; 5 import com.monitor.model.response.JavaApiStatusRep;
5 6
@@ -17,9 +18,9 @@ public interface IJavaApiStatusService { @@ -17,9 +18,9 @@ public interface IJavaApiStatusService {
17 18
18 public List<JavaApiStatusRep> getJavaApiStatusHisLatest(int api_id, int mobj_id); 19 public List<JavaApiStatusRep> getJavaApiStatusHisLatest(int api_id, int mobj_id);
19 20
20 - public List<JavaApiStatusRep> getJavaApiStatusHisByTime(int api_id, int mobj_id, long start, long end, int page,int pageSize); 21 + public List<JavaApiStatusRep> getJavaApiStatusHisByTime(JavaApiHisReq req);
21 22
22 - public int countJavaApiStatusHisByTime(int api_id, int mobj_id, long start, long end); 23 + public int countJavaApiStatusHisByTime(JavaApiHisReq req);
23 24
24 25
25 } 26 }
@@ -5,6 +5,7 @@ import com.monitor.common.util.DateFormatUtil; @@ -5,6 +5,7 @@ import com.monitor.common.util.DateFormatUtil;
5 import com.monitor.influxdb.mapper.impl.JavaApiStaticsMapper; 5 import com.monitor.influxdb.mapper.impl.JavaApiStaticsMapper;
6 import com.monitor.javaserver.service.IJavaApiStatusService; 6 import com.monitor.javaserver.service.IJavaApiStatusService;
7 import com.monitor.model.domain.JavaApiStaticsModel; 7 import com.monitor.model.domain.JavaApiStaticsModel;
  8 +import com.monitor.model.request.JavaApiHisReq;
8 import com.monitor.model.request.JavaApiStatusReq; 9 import com.monitor.model.request.JavaApiStatusReq;
9 import com.monitor.model.response.JavaApiStatusRep; 10 import com.monitor.model.response.JavaApiStatusRep;
10 import org.springframework.beans.factory.annotation.Autowired; 11 import org.springframework.beans.factory.annotation.Autowired;
@@ -81,18 +82,21 @@ public class JavaAppiStatusServiceImpl implements IJavaApiStatusService { @@ -81,18 +82,21 @@ public class JavaAppiStatusServiceImpl implements IJavaApiStatusService {
81 long start = System.currentTimeMillis(); 82 long start = System.currentTimeMillis();
82 long end = start; 83 long end = start;
83 start = start - 1000 * 60 * 60; //一小时之内 84 start = start - 1000 * 60 * 60; //一小时之内
84 - return this.getJavaApiStatusHisByTime(api_id, mobj_id, start, end, 0, 10); 85 + JavaApiHisReq req=new JavaApiHisReq();
  86 + req.setPageSize(10);
  87 + req.setApiId(api_id);
  88 + req.setMobjId(mobj_id);
  89 + req.setStartTime(start);
  90 + req.setEndTime(end);
  91 + req.setCurrentPage(0);
  92 + return this.getJavaApiStatusHisByTime(req);
85 } 93 }
86 94
87 @Override 95 @Override
88 - public List<JavaApiStatusRep> getJavaApiStatusHisByTime(int api_id, int mobj_id, long start, long end, int page, int pageSize) {  
89 - String startTime = DateFormatUtil.influxDBTimeFormat(start);  
90 - String endTime = DateFormatUtil.influxDBTimeFormat(end); 96 + public List<JavaApiStatusRep> getJavaApiStatusHisByTime(JavaApiHisReq req) {
91 97
92 98
93 - List<JavaApiStaticsModel> modelList = javaApiStaticsMapper.selectJavaApiStaticHis(null, api_id, mobj_id,  
94 - startTime, endTime, pageSize,  
95 - page * pageSize); 99 + List<JavaApiStaticsModel> modelList = javaApiStaticsMapper.selectJavaApiStaticHis(null, req);
96 List<JavaApiStatusRep> repList = new ArrayList<JavaApiStatusRep>(); 100 List<JavaApiStatusRep> repList = new ArrayList<JavaApiStatusRep>();
97 101
98 for (JavaApiStaticsModel model : modelList) { 102 for (JavaApiStaticsModel model : modelList) {
@@ -121,12 +125,9 @@ public class JavaAppiStatusServiceImpl implements IJavaApiStatusService { @@ -121,12 +125,9 @@ public class JavaAppiStatusServiceImpl implements IJavaApiStatusService {
121 } 125 }
122 126
123 @Override 127 @Override
124 - public int countJavaApiStatusHisByTime(int api_id, int mobj_id, long start, long end) {  
125 - String startTime = DateFormatUtil.influxDBTimeFormat(start);  
126 - String endTime = DateFormatUtil.influxDBTimeFormat(end); 128 + public int countJavaApiStatusHisByTime(JavaApiHisReq req) {
127 129
128 -  
129 - int count = javaApiStaticsMapper.countJavaApiStaticHis(null, api_id, mobj_id, startTime, endTime); 130 + int count = javaApiStaticsMapper.countJavaApiStaticHis(null, req);
130 return count; 131 return count;
131 } 132 }
132 133
  1 +package com.monitor.model.request;
  2 +
  3 +import com.monitor.model.page.PageRequest;
  4 +import lombok.Data;
  5 +
  6 +/**
  7 + * Created by fruwei on 2016/6/23.
  8 + */
  9 +@Data
  10 +public class JavaApiHisReq extends PageRequest {
  11 + int apiId = 0;
  12 + int mobjId = 0;
  13 + long startTime = 0;
  14 + long endTime = 0;
  15 + String mIp = "";
  16 + int status = 2;
  17 +
  18 +}
@@ -139,22 +139,22 @@ @@ -139,22 +139,22 @@
139 from java_api_info 139 from java_api_info
140 where 140 where
141 1=1 141 1=1
142 - <if test="params.serviceType != null"> 142 + <if test="params.serviceType != null and params.serviceType != 0">
143 and service_type = #{params.serviceType,jdbcType=INTEGER} 143 and service_type = #{params.serviceType,jdbcType=INTEGER}
144 </if> 144 </if>
145 - <if test="params.apiName != null">  
146 - and api_name = #{params.apiName,jdbcType=VARCHAR} 145 + <if test="params.apiName != null and params.apiName != ''">
  146 + and api_name like CONCAT('%',#{params.apiName,jdbcType=VARCHAR},'%' )
147 </if> 147 </if>
148 - <if test="params.apiUrl != null">  
149 - and api_url = #{params.apiUrl,jdbcType=VARCHAR} 148 + <if test="params.apiUrl != null and params.apiUrl != ''">
  149 + and api_url like CONCAT('%',#{params.apiUrl,jdbcType=VARCHAR},'%' )
150 </if> 150 </if>
151 <if test="params.apiData != null"> 151 <if test="params.apiData != null">
152 and api_data = #{params.apiData,jdbcType=VARCHAR} 152 and api_data = #{params.apiData,jdbcType=VARCHAR}
153 </if> 153 </if>
154 - <if test="params.apiToggle != null"> 154 + <if test="params.apiToggle != null ">
155 and api_toggle = #{params.apiToggle,jdbcType=INTEGER} 155 and api_toggle = #{params.apiToggle,jdbcType=INTEGER}
156 </if> 156 </if>
157 - <if test="params.apiReqMethod != null"> 157 + <if test="params.apiReqMethod != null and params.apiReqMethod !=2 ">
158 and api_req_method = #{params.apiReqMethod,jdbcType=INTEGER} 158 and api_req_method = #{params.apiReqMethod,jdbcType=INTEGER}
159 </if> 159 </if>
160 <if test="params.apiWarnTrigger != null"> 160 <if test="params.apiWarnTrigger != null">
@@ -168,14 +168,14 @@ @@ -168,14 +168,14 @@
168 from java_api_info 168 from java_api_info
169 where 169 where
170 1=1 170 1=1
171 - <if test="params.serviceType != null"> 171 + <if test="params.serviceType != null and params.serviceType != 0">
172 and service_type = #{params.serviceType,jdbcType=INTEGER} 172 and service_type = #{params.serviceType,jdbcType=INTEGER}
173 </if> 173 </if>
174 - <if test="params.apiName != null">  
175 - and api_name = #{params.apiName,jdbcType=VARCHAR} 174 + <if test="params.apiName != null and params.apiName != ''">
  175 + and api_name like CONCAT('%',#{params.apiName,jdbcType=VARCHAR},'%' )
176 </if> 176 </if>
177 - <if test="params.apiUrl != null">  
178 - and api_url = #{params.apiUrl,jdbcType=VARCHAR} 177 + <if test="params.apiUrl != null and params.apiUrl != ''">
  178 + and api_url like CONCAT('%',#{params.apiUrl,jdbcType=VARCHAR},'%' )
179 </if> 179 </if>
180 <if test="params.apiData != null"> 180 <if test="params.apiData != null">
181 and api_data = #{params.apiData,jdbcType=VARCHAR} 181 and api_data = #{params.apiData,jdbcType=VARCHAR}
@@ -183,7 +183,7 @@ @@ -183,7 +183,7 @@
183 <if test="params.apiToggle != null"> 183 <if test="params.apiToggle != null">
184 and api_toggle = #{params.apiToggle,jdbcType=INTEGER} 184 and api_toggle = #{params.apiToggle,jdbcType=INTEGER}
185 </if> 185 </if>
186 - <if test="params.apiReqMethod != null"> 186 + <if test="params.apiReqMethod != null and params.apiReqMethod !=2 ">
187 and api_req_method = #{params.apiReqMethod,jdbcType=INTEGER} 187 and api_req_method = #{params.apiReqMethod,jdbcType=INTEGER}
188 </if> 188 </if>
189 <if test="params.apiWarnTrigger != null"> 189 <if test="params.apiWarnTrigger != null">