46a7584fb561e8f186c1d9e572d609c554559078.svn-base 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /***************************************************
  2. * Copyright 2009-11-25, -sun,All rights reserved.
  3. * Create date : 2009-11-25
  4. * Author : sun
  5. **************************************************/
  6. package com.sinosoft.lz.system.right.role;
  7. import java.util.ArrayList;
  8. import java.util.List;
  9. import org.apache.commons.logging.Log;
  10. import org.apache.commons.logging.LogFactory;
  11. import com.persistence.service.PersistenceFactory;
  12. import com.persistence.service.SysPersistence;
  13. import com.persistence.service.exception.PersistenceException;
  14. import com.sysmodel.datamodel.xmlmodel.ModelFactory;
  15. import com.sysmodel.datamodel.xmlmodel.able.MdpConstant;
  16. import com.sysmodel.datamodel.xmlmodel.able.SysModel;
  17. // TODO: Auto-generated Javadoc
  18. /**
  19. * The Class RoleImpl.
  20. */
  21. public class RoleImpl implements Roleable{
  22. /*
  23. * (non-Javadoc)
  24. *
  25. * @see
  26. * com.sinosoft.lz.system.right.role.Roleable#getAllRoleByUserId(java.lang
  27. * .String, boolean)
  28. */
  29. public ArrayList<String[]> getAllRoleByUserId(String userId, boolean isAssign)
  30. throws PersistenceException {
  31. StringBuffer sbsql = new StringBuffer(
  32. "SELECT Role_ID,Role_Name,Role_Type FROM SYS_ROLE where 1=1 ");
  33. if (!userId.equals("")) {
  34. if (isAssign) {
  35. sbsql.append(" and Role_ID in (select t.Role_ID from SYS_USER_ROLE_REL t ");
  36. sbsql.append(" where t.User_ID='" + userId + "')");
  37. } else if (!isAssign) {
  38. sbsql.append(" and Role_ID not in (select t.Role_ID from SYS_USER_ROLE_REL t ");
  39. sbsql.append(" where t.User_ID='" + userId + "')");
  40. }
  41. }
  42. sbsql.append(" ORDER BY Role_Type");
  43. ArrayList<String[]> rs = persistence.getSearchResult(886, sbsql.toString());
  44. // 1 没有选中的 2选中的
  45. StringBuffer strList = new StringBuffer();
  46. String[] element = null;
  47. for (int i = 0; i < rs.size(); i++) {
  48. element = rs.get(i);
  49. element[2] = element[2] == null ? "" : element[2].trim();
  50. // log.info("Role_Type = " + element[2]);
  51. if (element[2].equals("0"))
  52. element[1] = "『菜单模块角色』" + element[1];
  53. if (element[2].equals("1"))
  54. element[1] = "(事件查看角色)" + element[1];
  55. if (element[2].equals("2"))
  56. element[1] = "《路网监控角色》" + element[1];
  57. if (element[2].equals("3"))
  58. element[1] = "【对象操作角色】" + element[1];
  59. if (element[2].equals("4"))
  60. element[1] = "<病害处理角色>" + element[1];
  61. strList.append(" <option value=\"").append(element[0]).append("\">").append(element[1])
  62. .append("</option>\n");
  63. element = null;
  64. }
  65. return rs;
  66. }
  67. /*
  68. * (non-Javadoc)
  69. *
  70. * @see
  71. * com.sinosoft.lz.system.right.role.Roleable#getRoleByType(java.lang.String
  72. * )
  73. */
  74. public List<String[]> getRoleByType(String type) throws PersistenceException {
  75. String strSql = "SELECT Role_ID,Role_Name FROM SYS_ROLE where Role_Type = '" + type
  76. + "' ORDER BY FD_OBJECTID";
  77. log.info("根据角色类型获得所有角色对象集合" + strSql);
  78. return persistence.getSearchResult(886, strSql);
  79. }
  80. /*
  81. * (non-Javadoc)
  82. *
  83. * @see
  84. * com.sinosoft.lz.system.right.role.Roleable#getRoleFunctionByType(java
  85. * .lang.String)
  86. */
  87. public List<String[]> getRoleFunctionByType(String type) {
  88. log.info("角色类型" + type);
  89. List<String[]> result = new ArrayList<String[]>();
  90. // "2" 监控服务
  91. if (type.equals("2")) {
  92. MdpConstant constant = sysmodel.getMdpConstantByName("BM$_MonitorService");
  93. result = constant.getAllNode();
  94. }
  95. return result;
  96. }
  97. /*
  98. * (non-Javadoc)
  99. *
  100. * @see
  101. * com.sinosoft.lz.system.right.role.Roleable#isFunctionInRole(java.lang
  102. * .String, java.lang.String)
  103. */
  104. public boolean isFunctionInRole(String roleId, String functionId) throws PersistenceException {
  105. String sql = "select count(*) from SYS_ROLE_RIGHT_REL t where t.Role_ID='" + roleId
  106. + "' and t.Right_ID='" + functionId + "'";
  107. // log.info(sql);
  108. int i = persistence.getFunctionNumber(99, sql);
  109. if (i > 0) {
  110. return true;
  111. }
  112. return false;
  113. }
  114. /** The sysmodel. */
  115. private static SysModel sysmodel = ModelFactory.getSysmodel();
  116. /** The persistence. */
  117. private static SysPersistence persistence = PersistenceFactory.getInstance(sysmodel);
  118. /** The log. */
  119. private static Log log = LogFactory.getLog(RoleImpl.class);
  120. /**
  121. * 为了构造JUNIT单元测试
  122. *
  123. * @param persistence
  124. */
  125. @SuppressWarnings("static-access")
  126. public void setPersistence(SysPersistence persistence) {
  127. this.persistence = persistence;
  128. }
  129. }