package com.cockpit.dao; import java.sql.SQLException; import java.util.Calendar; import java.util.Collections; import java.util.Date; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.Map; import java.util.Set; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.List; import com.sinosoft.cm.common.ArrayList; public class TyphoonDao extends ConnDaoImpl { public String getDateAxis(String sql, String fd_id){ List date = new ArrayList(); rs = executeQuerySetPs(sql,fd_id); try{ while(rs.next()){ date.add(rs.getDate("CREATE_TIME")); } return listTransitionStrbuf(date); }catch(SQLException e){ e.printStackTrace(); } return null; } /** * 变电站历史添加 * @param sql * @param obj * @return */ public int addSmootFloddsAxis(String sql, Object...obj){ return executeUpdate(sql,obj); } /** * 变电站历史记录查询 * @param sql * @param fd_id * @return */ public String getSmootFloddsAxis(String sql, String fd_id){ StringBuffer sb = new StringBuffer(); sb.append("["); rs = executeQuerySetPs(sql,fd_id); try{ while(rs.next()){ sb.append("{\"count\":\"" + rs.getString("RECORDDISC") + "\",\"data\":\"" + rs.getString("CREATE_TIME") + "\",\"fd_id\":\"" + rs.getString("FD_OBJECTID") + "\"},"); } }catch(SQLException e){ e.printStackTrace(); } sb.deleteCharAt(sb.length()-1); if(sb.length()==0){ return null ; } sb.append("]") ; return sb.toString() ; } public String getHistoryPath(String sql, String sid){ StringBuffer sb = new StringBuffer(); StringBuffer tempX = new StringBuffer() ; StringBuffer tempY = new StringBuffer() ; sb.append("["); rs = executeQuerySetPs(sql,sid) ; // rs = executeQueryBySt(sql); /* try{ if(rs.next()){ sb.append("{\"FD_ID\":\"" + rs.getString("FD_ID") + "\",\"LONGITUDE\":" + rs.getDouble("LONGITUDE") + ",\"LATITUDE\":" + rs.getDouble("LATITUDE") + "\"," ); if(rs.next()){ sb.append("\"nextX\":" + rs.getDouble("LONGITUDE") + ",\"nextY\":" + rs.getDouble("LATITUDE") + ","); rs.previous(); }else{ sb.append("\"nextX\":" + rs.getDouble("LONGITUDE") + ",\"nextY\":" + rs.getDouble("LATITUDE") + ","); } sb.append("\"SEVEN_RADIUS\":\"" + rs.getString("SEVEN_RADIUS") + "\",\"TEN_RADIUS\":\"" + rs.getString("TEN_RADIUS") + "\",\"TWELVE_RADIUS\":\"" + rs.getString("TWELVE_RADIUS") + "\",\"MAX_STRENGTH\":\"" + rs.getString("MAX_STRENGTH") + "\",\"MAX_SPEED\":\"" + rs.getString("MAX_SPEED") + "\",\"MOVEMENT_SPEED\":\"" + rs.getString("MOVEMENT_SPEED") + "\",\"CENTRAL_PRESSURE\":\"" + rs.getString("CENTRAL_PRESSURE") + "\",\"ORIENTATION\":\"" + rs.getString("ORIENTATION") + "\",\"CREATE_TIME\":\"" + rs.getString("CREATE_TIME") + "\"},"); } while(rs.next()){ sb.append("{\"FD_ID\":\"" + rs.getString("FD_ID") + "\",\"LONGITUDE\":" + rs.getDouble("LONGITUDE") + ",\"LATITUDE\":" + rs.getDouble("LATITUDE") + "\"," ); if(rs.next()){ sb.append("\"nextX\":" + rs.getDouble("LONGITUDE") + ",\"nextY\":" + rs.getDouble("LATITUDE") + ","); rs.previous(); }else{ sb.append("\"nextX\":" + rs.getDouble("LONGITUDE") + ",\"nextY\":" + rs.getDouble("LATITUDE") + ","); } sb.append("\"SEVEN_RADIUS\":\"" + rs.getString("SEVEN_RADIUS") + "\",\"TEN_RADIUS\":\"" + rs.getString("TEN_RADIUS") + "\",\"TWELVE_RADIUS\":\"" + rs.getString("TWELVE_RADIUS") + "\",\"MAX_STRENGTH\":\"" + rs.getString("MAX_STRENGTH") + "\",\"MAX_SPEED\":\"" + rs.getString("MAX_SPEED") + "\",\"MOVEMENT_SPEED\":\"" + rs.getString("MOVEMENT_SPEED") + "\",\"CENTRAL_PRESSURE\":\"" + rs.getString("CENTRAL_PRESSURE") + "\",\"ORIENTATION\":\"" + rs.getString("ORIENTATION") + "\",\"CREATE_TIME\":\"" + rs.getString("CREATE_TIME") + "\"},"); } } catch(SQLException e){ e.printStackTrace(); }*/ try{ if(rs.next()){ sb.append("{\"FD_ID\":\"" + rs.getString("FD_ID") + "\",\"afterX\":\"" + rs.getString("LONGITUDE") + "\",\"afterY\":\"" + rs.getString("LATITUDE") + "\",\"LONGITUDE\":" + rs.getDouble("LONGITUDE") + ",\"LATITUDE\":" + rs.getDouble("LATITUDE") + ",\"SEVEN_RADIUS\":\"" + rs.getString("SEVEN_RADIUS") + "\",\"TEN_RADIUS\":\"" + rs.getString("TEN_RADIUS") + "\",\"TWELVE_RADIUS\":\"" + rs.getString("TWELVE_RADIUS") + "\",\"MAX_STRENGTH\":\"" + rs.getString("MAX_STRENGTH") + "\",\"MAX_SPEED\":\"" + rs.getString("MAX_SPEED") + "\",\"MOVEMENT_SPEED\":\"" + rs.getString("MOVEMENT_SPEED") + "\",\"CENTRAL_PRESSURE\":\"" + rs.getString("CENTRAL_PRESSURE") + "\",\"ORIENTATION\":\"" + rs.getString("ORIENTATION") + "\",\"CREATE_TIME\":\"" + rs.getString("CREATE_TIME") + "\",\"addIcon\":\"true\"},"); tempX.append(rs.getString("LONGITUDE")) ; tempY.append(rs.getString("LATITUDE")) ; } while(rs.next()){ double x1 = Double.parseDouble(tempX.toString()); // double y1 = Double.parseDouble(tempY.toString()); double x2 = rs.getDouble("LONGITUDE"); // double y2 = rs.getDouble("LATITUDE"); if(x1 > x2){ sb.append(getPointStraightLineRightQuadrant(Double.parseDouble(tempX.toString()), Double.parseDouble(tempY.toString()), rs.getDouble("LONGITUDE"), rs.getDouble("LATITUDE"), rs.getString("FD_ID"), rs.getString("SEVEN_RADIUS"), rs.getString("TEN_RADIUS"), rs.getString("TWELVE_RADIUS"), rs.getString("MAX_STRENGTH"),rs.getString("MAX_SPEED"), rs.getString("MOVEMENT_SPEED"),rs.getString("CENTRAL_PRESSURE"), rs.getString("ORIENTATION"),rs.getString("CREATE_TIME"))); }else{ sb.append(getPointStraightLineLeftQuadrant(Double.parseDouble(tempX.toString()), Double.parseDouble(tempY.toString()), rs.getDouble("LONGITUDE"), rs.getDouble("LATITUDE"), rs.getString("FD_ID"), rs.getString("SEVEN_RADIUS"), rs.getString("TEN_RADIUS"), rs.getString("TWELVE_RADIUS"), rs.getString("MAX_STRENGTH"),rs.getString("MAX_SPEED"), rs.getString("MOVEMENT_SPEED"),rs.getString("CENTRAL_PRESSURE"), rs.getString("ORIENTATION"),rs.getString("CREATE_TIME"))); } sb.append("{\"FD_ID\":\"" + rs.getString("FD_ID") + "\",\"afterX\":\"" + tempX + "\",\"afterY\":\"" + tempY + "\",\"LONGITUDE\":" + rs.getDouble("LONGITUDE") + ",\"LATITUDE\":" + rs.getDouble("LATITUDE") + ",\"SEVEN_RADIUS\":\"" + rs.getString("SEVEN_RADIUS") + "\",\"TEN_RADIUS\":\"" + rs.getString("TEN_RADIUS") + "\",\"TWELVE_RADIUS\":\"" + rs.getString("TWELVE_RADIUS") + "\",\"MAX_STRENGTH\":\"" + rs.getString("MAX_STRENGTH") + "\",\"MAX_SPEED\":\"" + rs.getString("MAX_SPEED") + "\",\"MOVEMENT_SPEED\":\"" + rs.getString("MOVEMENT_SPEED") + "\",\"CENTRAL_PRESSURE\":\"" + rs.getString("CENTRAL_PRESSURE") + "\",\"ORIENTATION\":\"" + rs.getString("ORIENTATION") + "\",\"CREATE_TIME\":\"" + rs.getString("CREATE_TIME") + "\",\"addIcon\":\"true\"},"); tempX.delete(0, tempX.length()) ; tempY.delete(0, tempY.length()) ; tempX.append(rs.getString("LONGITUDE")) ; tempY.append(rs.getString("LATITUDE")) ; } } catch(SQLException e){ e.printStackTrace(); } sb.deleteCharAt(sb.length()-1); if(sb.length()==0){ return null ; } sb.append("]") ; return sb.toString() ; } public StringBuffer getPointStraightLineLeftQuadrant(double x1, double y1, double x2, double y2, String fd_id, String sev, String ten, String twe, String strength, String speed, String mspe, String central, String orie, String time){ StringBuffer sb = new StringBuffer(); double tempX = x1; double tempY = y1; double k = (y2-y1)/(x2-x1); double b = y1 - k*x1; double posX, posY; for(double i = x1 + .03; i < x2; i += .03){ posX = i; posY = (k*i+b); sb.append("{\"FD_ID\":\"" + fd_id + "\",\"afterX\":\"" + tempX + "\",\"afterY\":\"" + tempY + "\",\"LONGITUDE\":" + posX + ",\"LATITUDE\":" + posY + ",\"SEVEN_RADIUS\":\"" + sev + "\",\"TEN_RADIUS\":\"" + ten + "\",\"TWELVE_RADIUS\":\"" + twe + "\",\"MAX_STRENGTH\":\"" + strength + "\",\"MAX_SPEED\":\"" + speed + "\",\"MOVEMENT_SPEED\":\"" + mspe + "\",\"CENTRAL_PRESSURE\":\"" + central + "\",\"ORIENTATION\":\"" + orie + "\",\"CREATE_TIME\":\"" + time + "\",\"addIcon\":\"false\"},"); tempX = posX; tempY = posY; }; return sb; } public StringBuffer getPointStraightLineRightQuadrant(double x1, double y1, double x2, double y2, String fd_id, String sev, String ten, String twe, String strength, String speed, String mspe, String central, String orie, String time){ StringBuffer sb = new StringBuffer(); double tempX = x1; double tempY = y1; double k = (y2-y1)/(x2-x1); double b = y1 - k*x1; double posX, posY; boolean flg = y1>=y2;// true:向下 false:向上 for(double i = x1 + .03; i > x2; i -= .03){ posX = i; posY = (k*i+b); if(flg){ if(posY <= y1 && posY >= y2){ sb.append("{\"FD_ID\":\"" + fd_id + "\",\"afterX\":\"" + tempX + "\",\"afterY\":\"" + tempY + "\",\"LONGITUDE\":" + posX + ",\"LATITUDE\":" + posY + ",\"SEVEN_RADIUS\":\"" + sev + "\",\"TEN_RADIUS\":\"" + ten + "\",\"TWELVE_RADIUS\":\"" + twe + "\",\"MAX_STRENGTH\":\"" + strength + "\",\"MAX_SPEED\":\"" + speed + "\",\"MOVEMENT_SPEED\":\"" + mspe + "\",\"CENTRAL_PRESSURE\":\"" + central + "\",\"ORIENTATION\":\"" + orie + "\",\"CREATE_TIME\":\"" + time + "\",\"addIcon\":\"false\"},"); } }else{ if(posY <= y2 && posY >= y1){ sb.append("{\"FD_ID\":\"" + fd_id + "\",\"afterX\":\"" + tempX + "\",\"afterY\":\"" + tempY + "\",\"LONGITUDE\":" + posX + ",\"LATITUDE\":" + posY + ",\"SEVEN_RADIUS\":\"" + sev + "\",\"TEN_RADIUS\":\"" + ten + "\",\"TWELVE_RADIUS\":\"" + twe + "\",\"MAX_STRENGTH\":\"" + strength + "\",\"MAX_SPEED\":\"" + speed + "\",\"MOVEMENT_SPEED\":\"" + mspe + "\",\"CENTRAL_PRESSURE\":\"" + central + "\",\"ORIENTATION\":\"" + orie + "\",\"CREATE_TIME\":\"" + time + "\",\"addIcon\":\"false\"},"); } } tempX = posX; tempY = posY; }; return sb; } public String listTransitionStrbuf(List list){ StringBuffer sb = new StringBuffer(); sb.append("["); Calendar cal = Calendar.getInstance(); Set year = new HashSet(); Set month = new HashSet(); ArrayList yearo = new ArrayList(); ArrayList montho = new ArrayList(); Map> ym = new HashMap>(); for(Date key : list){ cal.setTime(key); year.add(cal.get(Calendar.YEAR)); } for(Integer key : year){ yearo.add(key); } Collections.sort(yearo,Collections.reverseOrder()); for(Integer keys : yearo){ month = new HashSet(); for(Date key : list){ cal.setTime(key); if(keys == cal.get(Calendar.YEAR)){ month.add(cal.get(Calendar.MONTH) + 1); } } for(Integer key : month){ montho.add(key); } Collections.sort(montho,Collections.reverseOrder()); ym.put(keys, montho); } for(Integer key : yearo){ sb.append("{\"year\":\"" + key + "\",\"mone\":["); for(Integer mo : ym.get(key)){ sb.append("\"" + mo + "月\","); } sb.deleteCharAt(sb.length()-1); sb.append("]},"); } sb.deleteCharAt(sb.length()-1); if(sb.length()==0){ return null ; } sb.append("]"); return sb.toString(); } }