bf8a4be90166ac7c840a094969939ae038f0bc77.svn-base 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  1. package com.cockpit.dao;
  2. import java.sql.SQLException;
  3. import java.util.Calendar;
  4. import java.util.Collections;
  5. import java.util.Date;
  6. import java.util.HashMap;
  7. import java.util.HashSet;
  8. import java.util.Iterator;
  9. import java.util.Map;
  10. import java.util.Set;
  11. import java.text.ParseException;
  12. import java.text.SimpleDateFormat;
  13. import java.util.List;
  14. import com.sinosoft.cm.common.ArrayList;
  15. public class TyphoonDao extends ConnDaoImpl {
  16. public String getDateAxis(String sql, String fd_id){
  17. List<Date> date = new ArrayList<Date>();
  18. rs = executeQuerySetPs(sql,fd_id);
  19. try{
  20. while(rs.next()){
  21. date.add(rs.getDate("CREATE_TIME"));
  22. }
  23. return listTransitionStrbuf(date);
  24. }catch(SQLException e){ e.printStackTrace(); }
  25. return null;
  26. }
  27. /**
  28. * 变电站历史添加
  29. * @param sql
  30. * @param obj
  31. * @return
  32. */
  33. public int addSmootFloddsAxis(String sql, Object...obj){
  34. return executeUpdate(sql,obj);
  35. }
  36. /**
  37. * 变电站历史记录查询
  38. * @param sql
  39. * @param fd_id
  40. * @return
  41. */
  42. public String getSmootFloddsAxis(String sql, String fd_id){
  43. StringBuffer sb = new StringBuffer();
  44. sb.append("[");
  45. rs = executeQuerySetPs(sql,fd_id);
  46. try{
  47. while(rs.next()){
  48. sb.append("{\"count\":\"" + rs.getString("RECORDDISC") +
  49. "\",\"data\":\"" + rs.getString("CREATE_TIME") +
  50. "\",\"fd_id\":\"" + rs.getString("FD_OBJECTID") + "\"},");
  51. }
  52. }catch(SQLException e){ e.printStackTrace(); }
  53. sb.deleteCharAt(sb.length()-1);
  54. if(sb.length()==0){ return null ; }
  55. sb.append("]") ;
  56. return sb.toString() ;
  57. }
  58. public String getHistoryPath(String sql, String sid){
  59. StringBuffer sb = new StringBuffer();
  60. StringBuffer tempX = new StringBuffer() ;
  61. StringBuffer tempY = new StringBuffer() ;
  62. sb.append("[");
  63. rs = executeQuerySetPs(sql,sid) ;
  64. // rs = executeQueryBySt(sql);
  65. /* try{
  66. if(rs.next()){
  67. sb.append("{\"FD_ID\":\"" + rs.getString("FD_ID") + "\",\"LONGITUDE\":" + rs.getDouble("LONGITUDE") +
  68. ",\"LATITUDE\":" + rs.getDouble("LATITUDE") + "\"," );
  69. if(rs.next()){
  70. sb.append("\"nextX\":" + rs.getDouble("LONGITUDE") + ",\"nextY\":" + rs.getDouble("LATITUDE") + ",");
  71. rs.previous();
  72. }else{
  73. sb.append("\"nextX\":" + rs.getDouble("LONGITUDE") + ",\"nextY\":" + rs.getDouble("LATITUDE") + ",");
  74. }
  75. sb.append("\"SEVEN_RADIUS\":\"" + rs.getString("SEVEN_RADIUS") +
  76. "\",\"TEN_RADIUS\":\"" + rs.getString("TEN_RADIUS") + "\",\"TWELVE_RADIUS\":\"" +
  77. rs.getString("TWELVE_RADIUS") + "\",\"MAX_STRENGTH\":\"" + rs.getString("MAX_STRENGTH") +
  78. "\",\"MAX_SPEED\":\"" + rs.getString("MAX_SPEED") + "\",\"MOVEMENT_SPEED\":\"" +
  79. rs.getString("MOVEMENT_SPEED") + "\",\"CENTRAL_PRESSURE\":\"" + rs.getString("CENTRAL_PRESSURE") +
  80. "\",\"ORIENTATION\":\"" + rs.getString("ORIENTATION") + "\",\"CREATE_TIME\":\"" +
  81. rs.getString("CREATE_TIME") + "\"},");
  82. }
  83. while(rs.next()){
  84. sb.append("{\"FD_ID\":\"" + rs.getString("FD_ID") + "\",\"LONGITUDE\":" + rs.getDouble("LONGITUDE") +
  85. ",\"LATITUDE\":" + rs.getDouble("LATITUDE") + "\"," );
  86. if(rs.next()){
  87. sb.append("\"nextX\":" + rs.getDouble("LONGITUDE") + ",\"nextY\":" + rs.getDouble("LATITUDE") + ",");
  88. rs.previous();
  89. }else{
  90. sb.append("\"nextX\":" + rs.getDouble("LONGITUDE") + ",\"nextY\":" + rs.getDouble("LATITUDE") + ",");
  91. }
  92. sb.append("\"SEVEN_RADIUS\":\"" + rs.getString("SEVEN_RADIUS") +
  93. "\",\"TEN_RADIUS\":\"" + rs.getString("TEN_RADIUS") + "\",\"TWELVE_RADIUS\":\"" +
  94. rs.getString("TWELVE_RADIUS") + "\",\"MAX_STRENGTH\":\"" + rs.getString("MAX_STRENGTH") +
  95. "\",\"MAX_SPEED\":\"" + rs.getString("MAX_SPEED") + "\",\"MOVEMENT_SPEED\":\"" +
  96. rs.getString("MOVEMENT_SPEED") + "\",\"CENTRAL_PRESSURE\":\"" + rs.getString("CENTRAL_PRESSURE") +
  97. "\",\"ORIENTATION\":\"" + rs.getString("ORIENTATION") + "\",\"CREATE_TIME\":\"" +
  98. rs.getString("CREATE_TIME") + "\"},");
  99. }
  100. } catch(SQLException e){ e.printStackTrace(); }*/
  101. try{
  102. if(rs.next()){
  103. sb.append("{\"FD_ID\":\"" + rs.getString("FD_ID") + "\",\"afterX\":\"" + rs.getString("LONGITUDE") +
  104. "\",\"afterY\":\"" + rs.getString("LATITUDE") + "\",\"LONGITUDE\":" + rs.getDouble("LONGITUDE") +
  105. ",\"LATITUDE\":" + rs.getDouble("LATITUDE") + ",\"SEVEN_RADIUS\":\"" + rs.getString("SEVEN_RADIUS") +
  106. "\",\"TEN_RADIUS\":\"" + rs.getString("TEN_RADIUS") + "\",\"TWELVE_RADIUS\":\"" +
  107. rs.getString("TWELVE_RADIUS") + "\",\"MAX_STRENGTH\":\"" + rs.getString("MAX_STRENGTH") +
  108. "\",\"MAX_SPEED\":\"" + rs.getString("MAX_SPEED") + "\",\"MOVEMENT_SPEED\":\"" +
  109. rs.getString("MOVEMENT_SPEED") + "\",\"CENTRAL_PRESSURE\":\"" + rs.getString("CENTRAL_PRESSURE") +
  110. "\",\"ORIENTATION\":\"" + rs.getString("ORIENTATION") + "\",\"CREATE_TIME\":\"" +
  111. rs.getString("CREATE_TIME") + "\",\"addIcon\":\"true\"},");
  112. tempX.append(rs.getString("LONGITUDE")) ;
  113. tempY.append(rs.getString("LATITUDE")) ;
  114. }
  115. while(rs.next()){
  116. double x1 = Double.parseDouble(tempX.toString());
  117. // double y1 = Double.parseDouble(tempY.toString());
  118. double x2 = rs.getDouble("LONGITUDE");
  119. // double y2 = rs.getDouble("LATITUDE");
  120. if(x1 > x2){
  121. sb.append(getPointStraightLineRightQuadrant(Double.parseDouble(tempX.toString()), Double.parseDouble(tempY.toString()),
  122. rs.getDouble("LONGITUDE"), rs.getDouble("LATITUDE"),
  123. rs.getString("FD_ID"), rs.getString("SEVEN_RADIUS"), rs.getString("TEN_RADIUS"),
  124. rs.getString("TWELVE_RADIUS"), rs.getString("MAX_STRENGTH"),rs.getString("MAX_SPEED"),
  125. rs.getString("MOVEMENT_SPEED"),rs.getString("CENTRAL_PRESSURE"),
  126. rs.getString("ORIENTATION"),rs.getString("CREATE_TIME")));
  127. }else{
  128. sb.append(getPointStraightLineLeftQuadrant(Double.parseDouble(tempX.toString()), Double.parseDouble(tempY.toString()),
  129. rs.getDouble("LONGITUDE"), rs.getDouble("LATITUDE"),
  130. rs.getString("FD_ID"), rs.getString("SEVEN_RADIUS"), rs.getString("TEN_RADIUS"),
  131. rs.getString("TWELVE_RADIUS"), rs.getString("MAX_STRENGTH"),rs.getString("MAX_SPEED"),
  132. rs.getString("MOVEMENT_SPEED"),rs.getString("CENTRAL_PRESSURE"),
  133. rs.getString("ORIENTATION"),rs.getString("CREATE_TIME")));
  134. }
  135. sb.append("{\"FD_ID\":\"" + rs.getString("FD_ID") + "\",\"afterX\":\"" + tempX + "\",\"afterY\":\"" + tempY +
  136. "\",\"LONGITUDE\":" + rs.getDouble("LONGITUDE") + ",\"LATITUDE\":" + rs.getDouble("LATITUDE") +
  137. ",\"SEVEN_RADIUS\":\"" + rs.getString("SEVEN_RADIUS") + "\",\"TEN_RADIUS\":\"" +
  138. rs.getString("TEN_RADIUS") + "\",\"TWELVE_RADIUS\":\"" + rs.getString("TWELVE_RADIUS") +
  139. "\",\"MAX_STRENGTH\":\"" + rs.getString("MAX_STRENGTH") + "\",\"MAX_SPEED\":\"" +
  140. rs.getString("MAX_SPEED") + "\",\"MOVEMENT_SPEED\":\"" + rs.getString("MOVEMENT_SPEED") +
  141. "\",\"CENTRAL_PRESSURE\":\"" + rs.getString("CENTRAL_PRESSURE") + "\",\"ORIENTATION\":\"" +
  142. rs.getString("ORIENTATION") + "\",\"CREATE_TIME\":\"" + rs.getString("CREATE_TIME") + "\",\"addIcon\":\"true\"},");
  143. tempX.delete(0, tempX.length()) ;
  144. tempY.delete(0, tempY.length()) ;
  145. tempX.append(rs.getString("LONGITUDE")) ;
  146. tempY.append(rs.getString("LATITUDE")) ;
  147. }
  148. } catch(SQLException e){ e.printStackTrace(); }
  149. sb.deleteCharAt(sb.length()-1);
  150. if(sb.length()==0){ return null ; }
  151. sb.append("]") ;
  152. return sb.toString() ;
  153. }
  154. public StringBuffer getPointStraightLineLeftQuadrant(double x1, double y1, double x2, double y2, String fd_id, String sev, String ten,
  155. String twe, String strength, String speed, String mspe, String central, String orie,
  156. String time){
  157. StringBuffer sb = new StringBuffer();
  158. double tempX = x1;
  159. double tempY = y1;
  160. double k = (y2-y1)/(x2-x1);
  161. double b = y1 - k*x1;
  162. double posX, posY;
  163. for(double i = x1 + .03; i < x2; i += .03){
  164. posX = i;
  165. posY = (k*i+b);
  166. sb.append("{\"FD_ID\":\"" + fd_id + "\",\"afterX\":\"" + tempX + "\",\"afterY\":\"" + tempY + "\",\"LONGITUDE\":" + posX +
  167. ",\"LATITUDE\":" + posY + ",\"SEVEN_RADIUS\":\"" + sev + "\",\"TEN_RADIUS\":\"" + ten +
  168. "\",\"TWELVE_RADIUS\":\"" + twe + "\",\"MAX_STRENGTH\":\"" + strength + "\",\"MAX_SPEED\":\"" + speed +
  169. "\",\"MOVEMENT_SPEED\":\"" + mspe + "\",\"CENTRAL_PRESSURE\":\"" + central + "\",\"ORIENTATION\":\"" + orie +
  170. "\",\"CREATE_TIME\":\"" + time + "\",\"addIcon\":\"false\"},");
  171. tempX = posX;
  172. tempY = posY;
  173. };
  174. return sb;
  175. }
  176. public StringBuffer getPointStraightLineRightQuadrant(double x1, double y1, double x2, double y2, String fd_id, String sev, String ten,
  177. String twe, String strength, String speed, String mspe, String central, String orie, String time){
  178. StringBuffer sb = new StringBuffer();
  179. double tempX = x1;
  180. double tempY = y1;
  181. double k = (y2-y1)/(x2-x1);
  182. double b = y1 - k*x1;
  183. double posX, posY;
  184. boolean flg = y1>=y2;// true:向下 false:向上
  185. for(double i = x1 + .03; i > x2; i -= .03){
  186. posX = i;
  187. posY = (k*i+b);
  188. if(flg){
  189. if(posY <= y1 && posY >= y2){
  190. sb.append("{\"FD_ID\":\"" + fd_id + "\",\"afterX\":\"" + tempX + "\",\"afterY\":\"" + tempY + "\",\"LONGITUDE\":" + posX +
  191. ",\"LATITUDE\":" + posY + ",\"SEVEN_RADIUS\":\"" + sev + "\",\"TEN_RADIUS\":\"" + ten +
  192. "\",\"TWELVE_RADIUS\":\"" + twe + "\",\"MAX_STRENGTH\":\"" + strength + "\",\"MAX_SPEED\":\"" + speed +
  193. "\",\"MOVEMENT_SPEED\":\"" + mspe + "\",\"CENTRAL_PRESSURE\":\"" + central + "\",\"ORIENTATION\":\"" + orie +
  194. "\",\"CREATE_TIME\":\"" + time + "\",\"addIcon\":\"false\"},");
  195. }
  196. }else{
  197. if(posY <= y2 && posY >= y1){
  198. sb.append("{\"FD_ID\":\"" + fd_id + "\",\"afterX\":\"" + tempX + "\",\"afterY\":\"" + tempY + "\",\"LONGITUDE\":" + posX +
  199. ",\"LATITUDE\":" + posY + ",\"SEVEN_RADIUS\":\"" + sev + "\",\"TEN_RADIUS\":\"" + ten +
  200. "\",\"TWELVE_RADIUS\":\"" + twe + "\",\"MAX_STRENGTH\":\"" + strength + "\",\"MAX_SPEED\":\"" + speed +
  201. "\",\"MOVEMENT_SPEED\":\"" + mspe + "\",\"CENTRAL_PRESSURE\":\"" + central + "\",\"ORIENTATION\":\"" + orie +
  202. "\",\"CREATE_TIME\":\"" + time + "\",\"addIcon\":\"false\"},");
  203. }
  204. }
  205. tempX = posX;
  206. tempY = posY;
  207. };
  208. return sb;
  209. }
  210. public String listTransitionStrbuf(List<Date> list){
  211. StringBuffer sb = new StringBuffer();
  212. sb.append("[");
  213. Calendar cal = Calendar.getInstance();
  214. Set<Integer> year = new HashSet<Integer>();
  215. Set<Integer> month = new HashSet<Integer>();
  216. ArrayList<Integer> yearo = new ArrayList<Integer>();
  217. ArrayList<Integer> montho = new ArrayList<Integer>();
  218. Map<Integer,ArrayList<Integer>> ym = new HashMap<Integer, ArrayList<Integer>>();
  219. for(Date key : list){
  220. cal.setTime(key);
  221. year.add(cal.get(Calendar.YEAR));
  222. }
  223. for(Integer key : year){
  224. yearo.add(key);
  225. }
  226. Collections.sort(yearo,Collections.reverseOrder());
  227. for(Integer keys : yearo){
  228. month = new HashSet<Integer>();
  229. for(Date key : list){
  230. cal.setTime(key);
  231. if(keys == cal.get(Calendar.YEAR)){
  232. month.add(cal.get(Calendar.MONTH) + 1);
  233. }
  234. }
  235. for(Integer key : month){
  236. montho.add(key);
  237. }
  238. Collections.sort(montho,Collections.reverseOrder());
  239. ym.put(keys, montho);
  240. }
  241. for(Integer key : yearo){
  242. sb.append("{\"year\":\"" + key + "\",\"mone\":[");
  243. for(Integer mo : ym.get(key)){
  244. sb.append("\"" + mo + "月\",");
  245. }
  246. sb.deleteCharAt(sb.length()-1);
  247. sb.append("]},");
  248. }
  249. sb.deleteCharAt(sb.length()-1);
  250. if(sb.length()==0){ return null ; }
  251. sb.append("]");
  252. return sb.toString();
  253. }
  254. }