package com.sinosoft.cm.service; import java.sql.SQLException; 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 nl.justobjects.pushlet.util.Sys; import org.apache.log4j.Logger; import com.formaction.Utils; import com.persistence.service.exception.PersistenceException; import com.sinosoft.cm.common.StringUtils; import com.sinosoft.cm.common.vo.ResultState; import com.sinosoft.cm.dao.MaticDao; import com.sinosoft.cm.ex.SQLStringException; import com.sinosoft.cm.impl.LayerMaticDaoImpl; import com.sinosoft.cm.impl.MaticDaoImpl; import com.sinosoft.cm.matic.service.MaticServiceImpl; import com.sinosoft.cm.vo.Matic; import com.sinosoft.cm.vo.Result; import com.sinosoft.common.excel.JsonPluginsUtil; import flex.messaging.io.ArrayList; @Path("/MaticService/") public class MaticService { private final Logger log = Logger.getLogger(getClass()); public MaticService() {} @ProduceMime("application/json") @POST @Path("/getMaticInfo") public String getMaticInfo() throws PersistenceException { MaticDao dao=new MaticDaoImpl(); Result res=null; List list=null; try { list=dao.findAll(); res=new Result(JsonPluginsUtil.beanListToJson(list), Result.STATE_SUCCESS, 0, 0); } catch (SQLException e) { log.error(e); } return res.toJSONString().replace("\\\"", "\"").replace("\"[", "[").replace("]\"", "]"); } /** * 获取视图列表信息 * @return * @throws PersistenceException */ @ProduceMime("application/json") @POST @Path("/getMaticMapInfo") public String getMaticMapInfo(String params) throws PersistenceException{ MaticServiceImpl msi=new MaticServiceImpl(); //LayerMaticDaoImpl dao=new LayerMaticDaoImpl(); String comId=Utils.getParameter("comId", params) == null ? "" : Utils.getParameter("comId", params); List> list=null; String result=null; //List> list=msi.findAllByNameAndIN("getMatic",(List)null,"785F409051A84412A75E8E44FE3F5C6E"); Map>> mapList=new HashMap>>(); try { list=msi.findAllByNameAndIN("getMatic",(List)null,comId); // list=dao.findAll("getMaticMap"); for(Map map:list){ if(!mapList.containsKey(map.get("AREA_NAME"))){ mapList.put(map.get("AREA_NAME"), new ArrayList()); /* mapList.get(map.get("AREA_NAME")).*/ /* mapList.get(map.get("AREA_NAME")),map.get("TM_BEX"));*/ } mapList.get(map.get("AREA_NAME")).add(map); } List strList=StringUtils.MapToJson(mapList); result=StringUtils.resultToJSON(ResultState.SUCCESS, list.size(), JsonPluginsUtil.beanListToJson(strList)); } catch (SQLStringException e) { log.info(e.getMessage()); result=StringUtils.resultToJSON(ResultState.FAILURE, 0, null); e.printStackTrace(); }finally{ log.info("===getMaticMapInfo()===返回前台结果===result==="+result); return result; } } /** * 获取视图列表信息 * @return * @throws PersistenceException */ @ProduceMime("application/json") @POST @Path("/getMaticMapInfoThroughLikeInfo") public String getMaticMapInfoThroughLikeInfo(String params) throws PersistenceException{ MaticServiceImpl msi=new MaticServiceImpl(); //LayerMaticDaoImpl dao=new LayerMaticDaoImpl(); String comId=Utils.getParameter("comId", params) == null ? "" : Utils.getParameter("comId", params); String like=Utils.getParameter("like", params) == null ? "" : Utils.getParameter("like", params); List> list=null; String result=null; //List> list=msi.findAllByNameAndIN("getMatic",(List)null,"785F409051A84412A75E8E44FE3F5C6E"); Map>> mapList=new HashMap>>(); try { System.out.println(comId); System.out.println(like); list=msi.findAllByNameAndIN("getLikeMatic",(List)null,comId,"%"+like+"%"); // list=dao.findAll("getMaticMap"); /* for(Map map:list){ if(!mapList.containsKey(map.get("AREA_NAME"))){ mapList.put(map.get("AREA_NAME"), new ArrayList()); } mapList.get(map.get("AREA_NAME")).add(map); }*/ List strList=StringUtils.MapToJson(mapList); result=StringUtils.resultToJSON(ResultState.SUCCESS, list.size(), JsonPluginsUtil.beanListToJson(list)); } catch (SQLStringException e) { log.info(e.getMessage()); result=StringUtils.resultToJSON(ResultState.FAILURE, 0, null); e.printStackTrace(); }finally{ log.info("===getMaticMapInfo()===返回前台结果===result==="+result); return result; } } /* public static void main(String[] args) { MaticService ms=new MaticService(); String str=null; try { str=ms.getMaticMapInfoThroughLike("comId=785F409051A84412A75E8E44FE3F5C6E&&like=台区"); System.out.println("str="+str); } catch (PersistenceException e) { e.printStackTrace(); } }*/ /** * 根据名字模糊查询 * @return * @throws PersistenceException */ @ProduceMime("application/json") @POST @Path("/getMaticMapByNameInfo") public String getMaticMapByNameInfo() throws PersistenceException{ LayerMaticDaoImpl dao=new LayerMaticDaoImpl(); List> list=null; String result=null; Map>> mapList=new HashMap>>(); try { list=dao.findAll("getMaticMap"); for(Map map:list){ if(!mapList.containsKey(map.get("AREA_NAME"))){ mapList.put(map.get("AREA_NAME"), new ArrayList()); } mapList.get(map.get("AREA_NAME")).add(map); } List strList=StringUtils.MapToJson(mapList); result=StringUtils.resultToJSON(ResultState.SUCCESS, strList.size(), JsonPluginsUtil.beanListToJson(strList)); } catch (SQLStringException e) { log.info(e.getMessage()); result=StringUtils.resultToJSON(ResultState.FAILURE, 0, null); e.printStackTrace(); }finally{ log.info("===getMaticMapInfo()===返回前台结果===result==="+result); return result; } } }