123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240 |
- package com.sinosoft.nwyj.integration.hessian;
- import java.net.MalformedURLException;
- import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- import javax.ws.rs.POST;
- import javax.ws.rs.Path;
- import javax.ws.rs.ProduceMime;
- import org.apache.log4j.Logger;
- import org.jfree.util.Log;
- import com.caucho.hessian.client.HessianProxyFactory;
- import com.formaction.Utils;
- import com.persistence.service.JDBCHelper;
- import com.persistence.service.PersistenceFactory;
- import com.persistence.service.SysPersistence;
- import com.persistence.service.exception.PersistenceException;
- import com.sinosoft.common.excel.JsonPluginsUtil;
- import com.sinosoft.em.event.dao.EventDaoImpl;
- import com.sinosoft.nwyj.integration.fault.DateFormateException;
- import com.sysmodel.datamodel.xmlmodel.ModelFactory;
- import com.sysmodel.datamodel.xmlmodel.able.SysModel;
- import net.sf.json.JSONArray;
- /**
- * 气象预警查询服务
- * @author zhuanghuiliang
- * @date 2016-03-16
- */
- @Path("/WeatherQueryService/")
- public class WeatherQueryService{
- private static final Logger log = Logger.getLogger(WeatherQueryService.class);
- /**
- * 根据上次预警/响应单号查询上次预警/响应信息
- *
- * @param params
- * @return
- * @throws DateFormateException
- */
- @POST
- @ProduceMime("application/json")
- @Path("/getWeatherInfo/")
- public String getWeatherInfo(String params) throws DateFormateException{
- String startDate = Utils.getParameter("startDate", params) == null ? "" : Utils.getParameter("startDate", params);
- String endDate = Utils.getParameter("endDate", params) == null ? "" : Utils.getParameter("endDate", params);
- String cityId = Utils.getParameter("cityId", params) == null ? "" : Utils.getParameter("cityId", params);
- List<String> list = new ArrayList<String>();
- list.add(cityId);
- //标识,0:精确查询 1:模糊查询
- String sign = Utils.getParameter("sign", params) == null ? "" : Utils.getParameter("sign", params);
- String url = GpsTaskWebService.getPath("path") + "/hessian/hessianService";
- HessianProxyFactory factory = new HessianProxyFactory();
- HessianService hs;
- //返回值结构参考MeteorologicalWarning类
- List<Map<String, String>>newList=new ArrayList<Map<String,String>>();
- String result = "";
- try {
- hs = (HessianService) factory.create(HessianService.class, url);
- result = hs.queryMeteorologicalWarning(startDate+" 00:00:00",endDate+" 23:59:59",list,sign);
- // Map<String, String>testMap=new HashMap<String, String>();
- // testMap.put("cityCountyNum", "1012802");
- // testMap.put("title", "广东省湛江市气象台发布雷雨大风黄色预警");
- // testMap.put("typeName", "雷雨大风");
- // testMap.put("level", "黄色");
- // testMap.put("describe", "湛江市气象台于03月23日22时37分将雷雨大风蓝色预警升级为黄色预警,请注意加强防御。");
- // testMap.put("status", "发布");
- // testMap.put("publishDate", "");
- // result=JSONArray.fromObject(testMap).toString();
- Map<String, String>cityMap=new HashMap<String, String>();
- cityMap=cityIdMap();
- if(result.length()>1){
- List<Map<String, String>>jsonList=new ArrayList<Map<String,String>>();
- jsonList=JsonPluginsUtil.jsonToMapList(result);
- for(int i=0;i<jsonList.size();i++){
- Map<String, String>map=jsonList.get(i);
- map.put("cityName", cityMap.get(map.get("cityCountyNum")));
- newList.add(map);
- }
- }
- } catch (Exception e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- // try {
- //// list = stringToList(cityId);
- // list = getChildCityCodeList(cityId);
- // result = getTestData(startDate,endDate,list,sign);
- // } catch (PersistenceException e) {
- // // TODO Auto-generated catch block
- // e.printStackTrace();
- // }
- result=JSONArray.fromObject(newList).toString();
- log.info("getWeatherInfo.result===="+result);
- result = "{\"rows\":"+result+"}";
- return result;
- }
- //将字符串按逗号分隔后存入list
- public List<String> stringToList(String str){
- if("".equals(str)){
- return null;
- }
- List<String> list = new ArrayList<String>();
- for(int i=0;i<str.split(",").length;i++){
- list.add(str.split(",")[i]);
- }
- return list;
- }
- //根据城市编码查询城市名称
- public Map<String,String> getCityName() throws PersistenceException{
- SysModel sysmodel = ModelFactory.getSysmodel();
- SysPersistence persistence = PersistenceFactory.getInstance(sysmodel);
- Map<String,String> map = new HashMap<String,String>();
- String sql = "select COUNTY_ID,PROVINCE_ID,CITY_ID,PROVINCE,CITY,COUNTY from WEATHER_COUNTY_DATA";
- ArrayList<String[]> list = persistence.getSearchResult(380, sql);
- for(String[] s:list){
- map.put(s[0], s[5]);
- map.put(s[1], s[3]);
- map.put(s[2], s[4]);
- }
- return map;
- }
- //查询所有直属下级城市编码,返回list
- public List<String> getChildCityCodeList(String cityCode) throws PersistenceException{
- SysModel sysmodel = ModelFactory.getSysmodel();
- SysPersistence persistence = PersistenceFactory.getInstance(sysmodel);
- List<String> list = new ArrayList<String>();
- if(cityCode==null||cityCode.equals("")){
- return null;
- }
- //将本级城市编码存入list
- list.add(cityCode);
- if(cityCode.length()==9){
- return list;
- }
- String sql = "select COUNTY_ID,PROVINCE_ID,CITY_ID,PROVINCE,CITY,COUNTY from WEATHER_COUNTY_DATA";
- if(cityCode.length()==5){
- sql += " where PROVINCE_ID='"+cityCode+"'";
- }
- if(cityCode.length()==7){
- sql += " where CITY_ID='"+cityCode+"'";
- }
- List<Map<String, String>> resultList = persistence.getSearchResultToMap(380, sql);
- for(Map<String,String> map : resultList){
- if(cityCode.length()==5){
- list.add(map.get("CITY_ID"));
- }
- if(cityCode.length()==7){
- list.add(map.get("COUNTY_ID"));
- }
- }
- return list;
- }
- //本地数据库模拟测试使用,海量数据接口实现后直接调用接口服务
- public String getTestData(String startDate,String endDate,List<String> list,String sign) throws PersistenceException{
- SysModel sysmodel = ModelFactory.getSysmodel();
- SysPersistence persistence = PersistenceFactory.getInstance(sysmodel);
- String sql = "select PRO_CITY_COUNTY_NUM,TITLE,ATYPE,ALEVEL,DES,ASTATUS,PUBDATE from WEATHER_DATA where 1=1";
- if(!"".equals(startDate)){
- sql += " and PUBDATE >=to_date('" + startDate + " 00:00:00')";
- }
- if(!"".equals(endDate)){
- sql += " and PUBDATE <=to_date('" + endDate + " 23:59:59')";
- }
- String citys = "";
- if(list!=null){
- for(String s:list){
- citys += "'"+s+"',";
- }
- citys = citys.substring(0,citys.length()-1);
- }
- if(!"".equals(citys)){
- sql += " and PRO_CITY_COUNTY_NUM in("+citys+")";
- }
- log.info(sql);
- List<Map<String, String>> resultList = persistence.getSearchResultToMap(380, sql);
- List<Map<String, String>> list1 = new ArrayList<Map<String, String>>();
- Map<String,String> cityMap = getCityName();
- for(Map<String,String> map:resultList){
- map.put("CITYNAME", cityMap.get(map.get("PRO_CITY_COUNTY_NUM")));
- list1.add(map);
- }
- String result = "{\"pager.pageNo\":" + 1 + ",\"pager.totalRows\":"
- + 2 + ",\"rows\":" + JSONArray.fromObject(list1) + "}";
- log.info(result);
- return result;
- }
-
- /**
- * 根据上次预警/响应单号查询上次预警/响应信息
- *
- * @param params
- * @return
- */
- @POST
- @ProduceMime("application/json")
- @Path("/getCityItem/")
- public String getCityItem(String params){
- SysModel sysmodel = ModelFactory.getSysmodel();
- SysPersistence persistence = PersistenceFactory.getInstance(sysmodel);
- //省份
- String provinceId = Utils.getParameter("provinceId", params) == null ? "" : Utils.getParameter("provinceId", params);
- String sql = "select distinct CITY_ID,CITY from WEATHER_COUNTY_DATA";
- sql += " where PROVINCE_ID='"+provinceId+"'";
- List<Map<String, String>> resultList = new ArrayList<Map<String,String>>();
- try {
- resultList = persistence.getSearchResultToMap(380, sql);
- } catch (PersistenceException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- return JSONArray.fromObject(resultList).toString();
- }
-
- public Map<String, String>cityIdMap(){
- Map<String, String>nameMap=new HashMap<String, String>();
- SysModel sysmodel = ModelFactory.getSysmodel();
- SysPersistence persistence = PersistenceFactory.getInstance(sysmodel);
- String sql="";
- 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";
-
- try {
- List<String[]>resultList=persistence.getSearchResult(99, sql);
- if(resultList!=null&&resultList.size()>0){
- for(int i=0;i<resultList.size();i++){
- nameMap.put(resultList.get(i)[0],resultList.get(i)[1]);
- }
- }
- } catch (PersistenceException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- return nameMap;
- }
-
- }
|