package com.sinosoft.em.gps.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 com.sinosoft.am.org.jdbcUtil.ORGTemplate; //生成dept_path_name @Path("/TestService/") public class TestService { @POST @ProduceMime("application/json") @Path("/test/") public Map getAll() throws Exception { Mapmap=new HashMap(); String sql="select dept_id,dept_name,parent_id,dept_type from sys_department WHERE '1'=?"; List>list=new ORGTemplate().query(sql, "1"); for(int i=0;itempMap=list.get(i); String PARENT_ID=tempMap.get("PARENT_ID"); String DEPT_TYPE = tempMap.get("DEPT_TYPE"); String dept_name=tempMap.get("DEPT_NAME"); String dept_id=tempMap.get("DEPT_ID"); // String dept_path="_/_"+dept_id; String dept_path_name="/"+dept_name; if(DEPT_TYPE.equals("1")){ updateCorpId(dept_path_name,dept_id); }else{ Mapmap1=getCorpInfo(PARENT_ID,dept_path_name); updateCorpId(map1.get("DEPT_PATH_NAME"),dept_id); } } return map; } public void updateCorpId(String dept_path_name,String dept_id){ String sql="update sys_department set dept_path_name=? where dept_id=?"; try { new ORGTemplate().update(sql, dept_path_name,dept_id); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } public MapgetCorpInfo(String dept_id,String dept_path_name){ Mapmap=new HashMap(); String sql="select dept_id,dept_type,parent_id,dept_name from sys_department where dept_id=?"; try { List>list=new ORGTemplate().query(sql, dept_id); MaptempMap=list.get(0); String PARENT_ID=tempMap.get("PARENT_ID"); String DEPT_TYPE = tempMap.get("DEPT_TYPE"); String dept_name=tempMap.get("DEPT_NAME"); //dept_path="_/_"+dept_id+dept_path; dept_path_name="/"+dept_name+dept_path_name; if(DEPT_TYPE.equals("1")){ //map.put("DEPT_PATH", dept_path); map.put("DEPT_PATH_NAME", dept_path_name); return map; }else{ map=getCorpInfo(PARENT_ID,dept_path_name); } } catch (SQLException e) { e.printStackTrace(); } return map; } }