123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- 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<String, String> getAll() throws Exception {
- Map<String, String>map=new HashMap<String, String>();
- String sql="select dept_id,dept_name,parent_id,dept_type from sys_department WHERE '1'=?";
-
- List<Map<String, String>>list=new ORGTemplate().query(sql, "1");
- for(int i=0;i<list.size();i++){
- System.out.println("++++++++++++dept_path_name+++++++++++++++="+list.size() + "****" + i);
- Map<String, String>tempMap=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{
- Map<String, String>map1=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 Map<String, String>getCorpInfo(String dept_id,String dept_path_name){
- Map<String, String>map=new HashMap<String, String>();
- String sql="select dept_id,dept_type,parent_id,dept_name from sys_department where dept_id=?";
- try {
- List<Map<String, String>>list=new ORGTemplate().query(sql, dept_id);
- Map<String, String>tempMap=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;
- }
- }
|