61dd24a8a44a74d89ada151fa3c113b36555db21.svn-base 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. package com.sinosoft.lz.system.department;
  2. import java.util.*;
  3. import javax.ws.rs.POST;
  4. import javax.ws.rs.Path;
  5. import javax.ws.rs.ProduceMime;
  6. import org.apache.log4j.Logger;
  7. import com.formaction.Utils;
  8. import com.sinosoft.common.excel.JsonPluginsUtil;
  9. public class DepartmentExcelServise {
  10. private final static Logger log = Logger.getLogger(DepartmentExcelServise.class);
  11. /**
  12. * 查询所有模块
  13. * @param params
  14. * @return
  15. */
  16. @ProduceMime("application/json")
  17. @POST
  18. @Path("/getAllDepartment/")
  19. public String getAllDepartment(String params){
  20. String parent_id = Utils.getParameter("parent_id", params) == null ? "" : Utils.getParameter("parent_id", params);
  21. if("".equals(parent_id)){
  22. parent_id = "BBD3C37F68094363AABC3CAD5FEE0AF8";
  23. }
  24. String outerStr = "{\"state\":\"ok\",\"length\":0}";
  25. StringBuffer json = new StringBuffer();
  26. DepartmentExcelDao deptdao = new DepartmentExcelDao();
  27. List<Map<String, Object>> result = getDeptById(deptdao , parent_id);
  28. String resultStr = JsonPluginsUtil.listToJson(result);
  29. log.info("用户习惯使用模块查询::"+resultStr);
  30. return resultStr;
  31. }
  32. public List<Map<String, Object>> getDeptById(DepartmentExcelDao deptdao,String id){
  33. List<Map<String, Object>> result = deptdao.getDeptByID(id);
  34. List<Map<String, Object>> depts = new ArrayList<Map<String,Object>>();
  35. if(!result.isEmpty()){
  36. for(int i=0;i<result.size();i++){
  37. Map<String, Object> resultMap = result.get(i);
  38. String dept_level = resultMap.get("dept_level")+"";
  39. String dept_id = resultMap.get("dept_id")+"";
  40. if(dept_level!=null&&!"null".equals(dept_level)&&!"".equals(dept_level)){
  41. List<Map<String, Object>> childDept = getDeptById(deptdao,dept_id);
  42. //resultMap.put("hasDept", true);
  43. if("BBD3C37F68094363AABC3CAD5FEE0AF8".equals(id)){
  44. resultMap.put("open", true);
  45. }else{
  46. resultMap.put("open", false);
  47. }
  48. resultMap.put("children", childDept);
  49. depts.add(resultMap);
  50. }else{
  51. //resultMap.put("hasDept", false);
  52. resultMap.put("open", false);
  53. resultMap.put("children", null);
  54. depts.add(resultMap);
  55. }
  56. }
  57. }
  58. return depts;
  59. }
  60. }