030b1ed4d192dd19edbd70f31bf04fe1d10e0e05.svn-base 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. package com.sinosoft.nwyj.integration.hessian;
  2. import java.net.MalformedURLException;
  3. import java.util.ArrayList;
  4. import java.util.HashMap;
  5. import java.util.List;
  6. import java.util.Map;
  7. import javax.ws.rs.POST;
  8. import javax.ws.rs.Path;
  9. import javax.ws.rs.ProduceMime;
  10. import org.apache.log4j.Logger;
  11. import org.jfree.util.Log;
  12. import com.caucho.hessian.client.HessianProxyFactory;
  13. import com.formaction.Utils;
  14. import com.persistence.service.JDBCHelper;
  15. import com.persistence.service.PersistenceFactory;
  16. import com.persistence.service.SysPersistence;
  17. import com.persistence.service.exception.PersistenceException;
  18. import com.sinosoft.common.excel.JsonPluginsUtil;
  19. import com.sinosoft.em.event.dao.EventDaoImpl;
  20. import com.sinosoft.nwyj.integration.fault.DateFormateException;
  21. import com.sysmodel.datamodel.xmlmodel.ModelFactory;
  22. import com.sysmodel.datamodel.xmlmodel.able.SysModel;
  23. import net.sf.json.JSONArray;
  24. /**
  25. * 气象预警查询服务
  26. * @author zhuanghuiliang
  27. * @date 2016-03-16
  28. */
  29. @Path("/WeatherQueryService/")
  30. public class WeatherQueryService{
  31. private static final Logger log = Logger.getLogger(WeatherQueryService.class);
  32. /**
  33. * 根据上次预警/响应单号查询上次预警/响应信息
  34. *
  35. * @param params
  36. * @return
  37. * @throws DateFormateException
  38. */
  39. @POST
  40. @ProduceMime("application/json")
  41. @Path("/getWeatherInfo/")
  42. public String getWeatherInfo(String params) throws DateFormateException{
  43. String startDate = Utils.getParameter("startDate", params) == null ? "" : Utils.getParameter("startDate", params);
  44. String endDate = Utils.getParameter("endDate", params) == null ? "" : Utils.getParameter("endDate", params);
  45. String cityId = Utils.getParameter("cityId", params) == null ? "" : Utils.getParameter("cityId", params);
  46. List<String> list = new ArrayList<String>();
  47. list.add(cityId);
  48. //标识,0:精确查询 1:模糊查询
  49. String sign = Utils.getParameter("sign", params) == null ? "" : Utils.getParameter("sign", params);
  50. String url = GpsTaskWebService.getPath("path") + "/hessian/hessianService";
  51. HessianProxyFactory factory = new HessianProxyFactory();
  52. HessianService hs;
  53. //返回值结构参考MeteorologicalWarning类
  54. List<Map<String, String>>newList=new ArrayList<Map<String,String>>();
  55. String result = "";
  56. try {
  57. hs = (HessianService) factory.create(HessianService.class, url);
  58. result = hs.queryMeteorologicalWarning(startDate+" 00:00:00",endDate+" 23:59:59",list,sign);
  59. // Map<String, String>testMap=new HashMap<String, String>();
  60. // testMap.put("cityCountyNum", "1012802");
  61. // testMap.put("title", "广东省湛江市气象台发布雷雨大风黄色预警");
  62. // testMap.put("typeName", "雷雨大风");
  63. // testMap.put("level", "黄色");
  64. // testMap.put("describe", "湛江市气象台于03月23日22时37分将雷雨大风蓝色预警升级为黄色预警,请注意加强防御。");
  65. // testMap.put("status", "发布");
  66. // testMap.put("publishDate", "");
  67. // result=JSONArray.fromObject(testMap).toString();
  68. Map<String, String>cityMap=new HashMap<String, String>();
  69. cityMap=cityIdMap();
  70. if(result.length()>1){
  71. List<Map<String, String>>jsonList=new ArrayList<Map<String,String>>();
  72. jsonList=JsonPluginsUtil.jsonToMapList(result);
  73. for(int i=0;i<jsonList.size();i++){
  74. Map<String, String>map=jsonList.get(i);
  75. map.put("cityName", cityMap.get(map.get("cityCountyNum")));
  76. newList.add(map);
  77. }
  78. }
  79. } catch (Exception e) {
  80. // TODO Auto-generated catch block
  81. e.printStackTrace();
  82. }
  83. // try {
  84. //// list = stringToList(cityId);
  85. // list = getChildCityCodeList(cityId);
  86. // result = getTestData(startDate,endDate,list,sign);
  87. // } catch (PersistenceException e) {
  88. // // TODO Auto-generated catch block
  89. // e.printStackTrace();
  90. // }
  91. result=JSONArray.fromObject(newList).toString();
  92. log.info("getWeatherInfo.result===="+result);
  93. result = "{\"rows\":"+result+"}";
  94. return result;
  95. }
  96. //将字符串按逗号分隔后存入list
  97. public List<String> stringToList(String str){
  98. if("".equals(str)){
  99. return null;
  100. }
  101. List<String> list = new ArrayList<String>();
  102. for(int i=0;i<str.split(",").length;i++){
  103. list.add(str.split(",")[i]);
  104. }
  105. return list;
  106. }
  107. //根据城市编码查询城市名称
  108. public Map<String,String> getCityName() throws PersistenceException{
  109. SysModel sysmodel = ModelFactory.getSysmodel();
  110. SysPersistence persistence = PersistenceFactory.getInstance(sysmodel);
  111. Map<String,String> map = new HashMap<String,String>();
  112. String sql = "select COUNTY_ID,PROVINCE_ID,CITY_ID,PROVINCE,CITY,COUNTY from WEATHER_COUNTY_DATA";
  113. ArrayList<String[]> list = persistence.getSearchResult(380, sql);
  114. for(String[] s:list){
  115. map.put(s[0], s[5]);
  116. map.put(s[1], s[3]);
  117. map.put(s[2], s[4]);
  118. }
  119. return map;
  120. }
  121. //查询所有直属下级城市编码,返回list
  122. public List<String> getChildCityCodeList(String cityCode) throws PersistenceException{
  123. SysModel sysmodel = ModelFactory.getSysmodel();
  124. SysPersistence persistence = PersistenceFactory.getInstance(sysmodel);
  125. List<String> list = new ArrayList<String>();
  126. if(cityCode==null||cityCode.equals("")){
  127. return null;
  128. }
  129. //将本级城市编码存入list
  130. list.add(cityCode);
  131. if(cityCode.length()==9){
  132. return list;
  133. }
  134. String sql = "select COUNTY_ID,PROVINCE_ID,CITY_ID,PROVINCE,CITY,COUNTY from WEATHER_COUNTY_DATA";
  135. if(cityCode.length()==5){
  136. sql += " where PROVINCE_ID='"+cityCode+"'";
  137. }
  138. if(cityCode.length()==7){
  139. sql += " where CITY_ID='"+cityCode+"'";
  140. }
  141. List<Map<String, String>> resultList = persistence.getSearchResultToMap(380, sql);
  142. for(Map<String,String> map : resultList){
  143. if(cityCode.length()==5){
  144. list.add(map.get("CITY_ID"));
  145. }
  146. if(cityCode.length()==7){
  147. list.add(map.get("COUNTY_ID"));
  148. }
  149. }
  150. return list;
  151. }
  152. //本地数据库模拟测试使用,海量数据接口实现后直接调用接口服务
  153. public String getTestData(String startDate,String endDate,List<String> list,String sign) throws PersistenceException{
  154. SysModel sysmodel = ModelFactory.getSysmodel();
  155. SysPersistence persistence = PersistenceFactory.getInstance(sysmodel);
  156. String sql = "select PRO_CITY_COUNTY_NUM,TITLE,ATYPE,ALEVEL,DES,ASTATUS,PUBDATE from WEATHER_DATA where 1=1";
  157. if(!"".equals(startDate)){
  158. sql += " and PUBDATE >=to_date('" + startDate + " 00:00:00')";
  159. }
  160. if(!"".equals(endDate)){
  161. sql += " and PUBDATE <=to_date('" + endDate + " 23:59:59')";
  162. }
  163. String citys = "";
  164. if(list!=null){
  165. for(String s:list){
  166. citys += "'"+s+"',";
  167. }
  168. citys = citys.substring(0,citys.length()-1);
  169. }
  170. if(!"".equals(citys)){
  171. sql += " and PRO_CITY_COUNTY_NUM in("+citys+")";
  172. }
  173. log.info(sql);
  174. List<Map<String, String>> resultList = persistence.getSearchResultToMap(380, sql);
  175. List<Map<String, String>> list1 = new ArrayList<Map<String, String>>();
  176. Map<String,String> cityMap = getCityName();
  177. for(Map<String,String> map:resultList){
  178. map.put("CITYNAME", cityMap.get(map.get("PRO_CITY_COUNTY_NUM")));
  179. list1.add(map);
  180. }
  181. String result = "{\"pager.pageNo\":" + 1 + ",\"pager.totalRows\":"
  182. + 2 + ",\"rows\":" + JSONArray.fromObject(list1) + "}";
  183. log.info(result);
  184. return result;
  185. }
  186. /**
  187. * 根据上次预警/响应单号查询上次预警/响应信息
  188. *
  189. * @param params
  190. * @return
  191. */
  192. @POST
  193. @ProduceMime("application/json")
  194. @Path("/getCityItem/")
  195. public String getCityItem(String params){
  196. SysModel sysmodel = ModelFactory.getSysmodel();
  197. SysPersistence persistence = PersistenceFactory.getInstance(sysmodel);
  198. //省份
  199. String provinceId = Utils.getParameter("provinceId", params) == null ? "" : Utils.getParameter("provinceId", params);
  200. String sql = "select distinct CITY_ID,CITY from WEATHER_COUNTY_DATA";
  201. sql += " where PROVINCE_ID='"+provinceId+"'";
  202. List<Map<String, String>> resultList = new ArrayList<Map<String,String>>();
  203. try {
  204. resultList = persistence.getSearchResultToMap(380, sql);
  205. } catch (PersistenceException e) {
  206. // TODO Auto-generated catch block
  207. e.printStackTrace();
  208. }
  209. return JSONArray.fromObject(resultList).toString();
  210. }
  211. public Map<String, String>cityIdMap(){
  212. Map<String, String>nameMap=new HashMap<String, String>();
  213. SysModel sysmodel = ModelFactory.getSysmodel();
  214. SysPersistence persistence = PersistenceFactory.getInstance(sysmodel);
  215. String sql="";
  216. sql="select distinct province_id,province from WEATHER_COUNTY_DATA union select distinct city_id,city from WEATHER_COUNTY_DATA union select county_id,county from WEATHER_COUNTY_DATA";
  217. try {
  218. List<String[]>resultList=persistence.getSearchResult(99, sql);
  219. if(resultList!=null&&resultList.size()>0){
  220. for(int i=0;i<resultList.size();i++){
  221. nameMap.put(resultList.get(i)[0],resultList.get(i)[1]);
  222. }
  223. }
  224. } catch (PersistenceException e) {
  225. // TODO Auto-generated catch block
  226. e.printStackTrace();
  227. }
  228. return nameMap;
  229. }
  230. }