87cc1aa8729c04fdfe03e3e3550ea6d21c8b3876.svn-base 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. package com.sinosoft.em.gps.service;
  2. import java.sql.SQLException;
  3. import java.util.HashMap;
  4. import java.util.List;
  5. import java.util.Map;
  6. import javax.ws.rs.POST;
  7. import javax.ws.rs.Path;
  8. import javax.ws.rs.ProduceMime;
  9. import com.sinosoft.am.org.jdbcUtil.ORGTemplate;
  10. //生成dept_path_name
  11. @Path("/TestService/")
  12. public class TestService {
  13. @POST
  14. @ProduceMime("application/json")
  15. @Path("/test/")
  16. public Map<String, String> getAll() throws Exception {
  17. Map<String, String>map=new HashMap<String, String>();
  18. String sql="select dept_id,dept_name,parent_id,dept_type from sys_department WHERE '1'=?";
  19. List<Map<String, String>>list=new ORGTemplate().query(sql, "1");
  20. for(int i=0;i<list.size();i++){
  21. System.out.println("++++++++++++dept_path_name+++++++++++++++="+list.size() + "****" + i);
  22. Map<String, String>tempMap=list.get(i);
  23. String PARENT_ID=tempMap.get("PARENT_ID");
  24. String DEPT_TYPE = tempMap.get("DEPT_TYPE");
  25. String dept_name=tempMap.get("DEPT_NAME");
  26. String dept_id=tempMap.get("DEPT_ID");
  27. // String dept_path="_/_"+dept_id;
  28. String dept_path_name="/"+dept_name;
  29. if(DEPT_TYPE.equals("1")){
  30. updateCorpId(dept_path_name,dept_id);
  31. }else{
  32. Map<String, String>map1=getCorpInfo(PARENT_ID,dept_path_name);
  33. updateCorpId(map1.get("DEPT_PATH_NAME"),dept_id);
  34. }
  35. }
  36. return map;
  37. }
  38. public void updateCorpId(String dept_path_name,String dept_id){
  39. String sql="update sys_department set dept_path_name=? where dept_id=?";
  40. try {
  41. new ORGTemplate().update(sql, dept_path_name,dept_id);
  42. } catch (SQLException e) {
  43. // TODO Auto-generated catch block
  44. e.printStackTrace();
  45. }
  46. }
  47. public Map<String, String>getCorpInfo(String dept_id,String dept_path_name){
  48. Map<String, String>map=new HashMap<String, String>();
  49. String sql="select dept_id,dept_type,parent_id,dept_name from sys_department where dept_id=?";
  50. try {
  51. List<Map<String, String>>list=new ORGTemplate().query(sql, dept_id);
  52. Map<String, String>tempMap=list.get(0);
  53. String PARENT_ID=tempMap.get("PARENT_ID");
  54. String DEPT_TYPE = tempMap.get("DEPT_TYPE");
  55. String dept_name=tempMap.get("DEPT_NAME");
  56. //dept_path="_/_"+dept_id+dept_path;
  57. dept_path_name="/"+dept_name+dept_path_name;
  58. if(DEPT_TYPE.equals("1")){
  59. //map.put("DEPT_PATH", dept_path);
  60. map.put("DEPT_PATH_NAME", dept_path_name);
  61. return map;
  62. }else{
  63. map=getCorpInfo(PARENT_ID,dept_path_name);
  64. }
  65. } catch (SQLException e) {
  66. e.printStackTrace();
  67. }
  68. return map;
  69. }
  70. }