Showing
1 changed file
with
22 additions
and
4 deletions
@@ -20,11 +20,9 @@ import org.springframework.beans.factory.annotation.Autowired; | @@ -20,11 +20,9 @@ import org.springframework.beans.factory.annotation.Autowired; | ||
20 | import org.springframework.stereotype.Service; | 20 | import org.springframework.stereotype.Service; |
21 | import org.springframework.util.CollectionUtils; | 21 | import org.springframework.util.CollectionUtils; |
22 | 22 | ||
23 | +import java.math.BigDecimal; | ||
23 | import java.sql.*; | 24 | import java.sql.*; |
24 | -import java.util.ArrayList; | ||
25 | -import java.util.HashMap; | ||
26 | -import java.util.List; | ||
27 | -import java.util.Map; | 25 | +import java.util.*; |
28 | 26 | ||
29 | /** | 27 | /** |
30 | * Created by craig.qin on 2017/6/26. | 28 | * Created by craig.qin on 2017/6/26. |
@@ -147,6 +145,7 @@ public class SqlOperateServiceImpl implements SqlOperateService { | @@ -147,6 +145,7 @@ public class SqlOperateServiceImpl implements SqlOperateService { | ||
147 | BaseResponse res=null; | 145 | BaseResponse res=null; |
148 | Map<String,Object> rtnList=new HashMap<String,Object>(); | 146 | Map<String,Object> rtnList=new HashMap<String,Object>(); |
149 | String queryDescr=""; | 147 | String queryDescr=""; |
148 | + long compareTs=-1; | ||
150 | String hasNext="no";//分页,是否存在下一页 | 149 | String hasNext="no";//分页,是否存在下一页 |
151 | boolean showSeqNOColumn=false; | 150 | boolean showSeqNOColumn=false; |
152 | String seqNOColumnName="_seqno_column_numberIndex"; | 151 | String seqNOColumnName="_seqno_column_numberIndex"; |
@@ -196,6 +195,10 @@ public class SqlOperateServiceImpl implements SqlOperateService { | @@ -196,6 +195,10 @@ public class SqlOperateServiceImpl implements SqlOperateService { | ||
196 | rtnList.put("showPi",false); | 195 | rtnList.put("showPi",false); |
197 | } | 196 | } |
198 | 197 | ||
198 | + // | ||
199 | + Calendar beginCal = Calendar.getInstance(); | ||
200 | + long beginTs = beginCal.getTime().getTime(); | ||
201 | + | ||
199 | st = con.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); | 202 | st = con.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); |
200 | st.setFetchSize(SqlQueryConstant.FETCH_COUNT_FROM_MYSQL); | 203 | st.setFetchSize(SqlQueryConstant.FETCH_COUNT_FROM_MYSQL); |
201 | //不是desc的查询需要限定数量了 | 204 | //不是desc的查询需要限定数量了 |
@@ -205,6 +208,18 @@ public class SqlOperateServiceImpl implements SqlOperateService { | @@ -205,6 +208,18 @@ public class SqlOperateServiceImpl implements SqlOperateService { | ||
205 | } | 208 | } |
206 | 209 | ||
207 | rs = st.executeQuery(sql); | 210 | rs = st.executeQuery(sql); |
211 | + | ||
212 | + //计算耗时 | ||
213 | + Calendar endCal = Calendar.getInstance(); | ||
214 | + long endTs = endCal.getTime().getTime(); | ||
215 | + compareTs = endTs - beginTs; | ||
216 | + | ||
217 | + int test =rs.getRow(); | ||
218 | + System.out.println("==**"+test); | ||
219 | + rs.last(); | ||
220 | + test = rs.getRow(); | ||
221 | + System.out.println("==**"+test); | ||
222 | + | ||
208 | rs.beforeFirst(); | 223 | rs.beforeFirst(); |
209 | rs.relative(SqlQueryConstant.MAX_QUERY_RESULT_COUNT*sqlOperateModel.getCurrentPage()); | 224 | rs.relative(SqlQueryConstant.MAX_QUERY_RESULT_COUNT*sqlOperateModel.getCurrentPage()); |
210 | JSONArray ja_column=new JSONArray(); | 225 | JSONArray ja_column=new JSONArray(); |
@@ -373,6 +388,9 @@ public class SqlOperateServiceImpl implements SqlOperateService { | @@ -373,6 +388,9 @@ public class SqlOperateServiceImpl implements SqlOperateService { | ||
373 | } | 388 | } |
374 | } | 389 | } |
375 | rtnList.put("queryDescr", StringUtils.isBlank(queryDescr)?("本页共查询到"+count+"条数据"):queryDescr); | 390 | rtnList.put("queryDescr", StringUtils.isBlank(queryDescr)?("本页共查询到"+count+"条数据"):queryDescr); |
391 | + if(compareTs>=0){ | ||
392 | + rtnList.put("queryDescr",rtnList.get("queryDescr")+",总耗时 " + compareTs+"ms "); | ||
393 | + } | ||
376 | rtnList.put("queryCount",count); | 394 | rtnList.put("queryCount",count); |
377 | rtnList.put("hasNext",hasNext); | 395 | rtnList.put("hasNext",hasNext); |
378 | res=new BaseResponse(); | 396 | res=new BaseResponse(); |
-
Please register or login to post a comment