7199dac59313b2bc7ccd79778d13843da1a3b630.svn-base 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. package com.sinosoft.lz.system.right.role.dao;
  2. import java.sql.Connection;
  3. import java.sql.PreparedStatement;
  4. import java.sql.ResultSet;
  5. import java.sql.SQLException;
  6. import java.sql.Statement;
  7. import java.util.ArrayList;
  8. import java.util.Collection;
  9. import java.util.Iterator;
  10. import java.util.List;
  11. import org.apache.log4j.Logger;
  12. import com.persistence.DbConnection;
  13. import com.persistence.service.PersistenceFactory;
  14. import com.persistence.service.SysPersistence;
  15. import com.persistence.service.assitant.generator.IdentityGenerator;
  16. import com.persistence.service.exception.PersistenceException;
  17. import com.sinosoft.lz.system.right.role.vo.RoleVO;
  18. import com.sysmodel.datamodel.xmlmodel.ModelFactory;
  19. import com.sysmodel.datamodel.xmlmodel.able.SysModel;
  20. public class RoleDAO{
  21. private static SysModel sysmodel = ModelFactory.getSysmodel();
  22. private static SysPersistence persistence = PersistenceFactory.getInstance(sysmodel);
  23. private Logger log = Logger.getLogger(RoleDAO.class);
  24. public boolean addSysRole(RoleVO VO) throws ClassNotFoundException {
  25. Connection conn = null;
  26. PreparedStatement st = null;
  27. DbConnection db = new DbConnection();
  28. try {
  29. String sql = "insert into SYS_ROLE (FD_OBJECTID,ROLE_ID,PARENT_ID,ROLE_TYPE,ROLE_NAME,ROLE_DESCRIPTION,ROLE_STATE,CREATE_UNIT,CREATOR_ID,CREATE_TIME,LAST_MODIFIER_ID,LAST_MODIFY_TIME) values (?,?,?,?,?,?,?,?,?,?,?,?)";
  30. conn = db.getConnection();
  31. st = conn.prepareStatement(sql);
  32. st.setString(1, IdentityGenerator.getIdentityGenerator().gerenalPrimaryKey(conn, "881"));
  33. st.setString(2, VO.getRoleId());
  34. /* st.setString(3, VO.getParentId());
  35. st.setString(4, VO.getRoleType());
  36. st.setString(5, VO.getRoleName());
  37. st.setString(6, VO.getRoleDescription());
  38. st.setInt(7, VO.getRoleState());
  39. st.setString(8, VO.getCreateUnit());
  40. st.setString(9, VO.getCreatorId());
  41. st.setTimestamp(10, VO.getCreateTime());
  42. st.setString(11, VO.getLastModifierId());
  43. st.setTimestamp(12, VO.getLastModifyTime());*/
  44. return st.execute();
  45. } catch (SQLException e) {
  46. this.log.error(e.getMessage(), e);
  47. throw new ClassNotFoundException("DAO Layou: 新增", e);
  48. } finally {
  49. db.close(st);
  50. db.close(conn);
  51. }
  52. }
  53. public int[] addSysRole(ArrayList<RoleVO> voList) throws ClassNotFoundException {
  54. Connection conn = null;
  55. PreparedStatement st = null;
  56. DbConnection db = new DbConnection();
  57. try {
  58. String sql = "insert into SYS_ROLE (FD_OBJECTID,ROLE_ID,PARENT_ID,ROLE_TYPE,ROLE_NAME,ROLE_DESCRIPTION,ROLE_STATE,CREATE_UNIT,CREATOR_ID,CREATE_TIME,LAST_MODIFIER_ID,LAST_MODIFY_TIME) values (?,?,?,?,?,?,?,?,?,?,?,?)";
  59. conn = db.getConnection();
  60. st = conn.prepareStatement(sql);
  61. RoleVO VO = null;
  62. for (int i = 0; i < voList.size(); i++) {
  63. VO = voList.get(i);
  64. st.setString(1, VO.getFdObjectid());
  65. st.setString(2, VO.getRoleId());
  66. /* st.setString(3, VO.getParentId());
  67. st.setString(4, VO.getRoleType());
  68. st.setString(5, VO.getRoleName());
  69. st.setString(6, VO.getRoleDescription());
  70. st.setInt(7, VO.getRoleState());
  71. st.setString(8, VO.getCreateUnit());
  72. st.setString(9, VO.getCreatorId());
  73. st.setTimestamp(10, VO.getCreateTime());
  74. st.setString(11, VO.getLastModifierId());
  75. st.setTimestamp(12, VO.getLastModifyTime());*/
  76. st.addBatch();
  77. }
  78. return st.executeBatch();
  79. } catch (SQLException e) {
  80. this.log.error(e.getMessage(), e);
  81. throw new ClassNotFoundException("DAO Layou: 新增", e);
  82. } finally {
  83. db.close(st);
  84. db.close(conn);
  85. }
  86. }
  87. public boolean modifySysRole(RoleVO VO) throws ClassNotFoundException {
  88. Connection conn = null;
  89. PreparedStatement st = null;
  90. DbConnection db = new DbConnection();
  91. try {
  92. String sql = "update SYS_ROLE set FD_OBJECTID = ?, ROLE_ID = ?, ROLE_CODE = ?, ROLE_NAME = ?, ROLE_DUTY = ?, IS_DEL = ?, MOD_DATE = ? where FD_OBJECTID = ?";
  93. conn = db.getConnection();
  94. st = conn.prepareStatement(sql);
  95. st.setString(1, VO.getFdObjectid());
  96. st.setString(2, VO.getRoleId());
  97. /* st.setString(3, VO.getParentId());
  98. st.setString(4, VO.getRoleType());
  99. st.setString(5, VO.getRoleName());
  100. st.setString(6, VO.getRoleDescription());
  101. st.setInt(7, VO.getRoleState());
  102. st.setString(8, VO.getCreateUnit());
  103. st.setString(9, VO.getCreatorId());
  104. st.setTimestamp(10, VO.getCreateTime());
  105. st.setString(11, VO.getLastModifierId());
  106. st.setTimestamp(12, VO.getLastModifyTime());
  107. st.setString(13, VO.getFdObjectid());
  108. st.executeUpdate();*/
  109. return true;
  110. } catch (SQLException e) {
  111. this.log.error(e.getMessage(), e);
  112. throw new ClassNotFoundException("DAO Layou: 修改", e);
  113. } finally {
  114. db.close(st);
  115. db.close(conn);
  116. }
  117. }
  118. @SuppressWarnings("unused")
  119. public boolean delSysRole(String roleId) throws ClassNotFoundException {
  120. Connection conn = null;
  121. Statement stat = null;
  122. DbConnection db = new DbConnection();
  123. String sql = "delete from SYS_ROLE where FD_OBJECTID=?";
  124. try {
  125. conn = db.getConnection();
  126. // stat = conn.prepareStatement(sql);
  127. // stat.setString(1, FD_OBJECTID);
  128. // conn = db.getConnection();
  129. stat = conn.createStatement();
  130. stat.addBatch("delete from SYS_ROLE where role_id='" + roleId + "'");
  131. stat.addBatch("delete from SYS_ROLE_RIGHT_REL where role_id='" + roleId + "'");
  132. stat.executeBatch();
  133. return true;
  134. } catch (SQLException e) {
  135. this.log.error(e.getMessage(), e);
  136. throw new ClassNotFoundException("DAO Layou: 删除", e);
  137. } finally {
  138. db.close(stat);
  139. db.close(conn);
  140. }
  141. }
  142. @SuppressWarnings("rawtypes")
  143. public RoleVO getRoleVO(String FD_OBJECTID) throws ClassNotFoundException {
  144. String sql = "select * from SYS_ROLE where FD_OBJECTID='" + FD_OBJECTID + "'";
  145. Collection coll = getSysRole(sql);
  146. Iterator it = coll.iterator();
  147. if (it.hasNext())
  148. return (RoleVO) it.next();
  149. return null;
  150. }
  151. @SuppressWarnings({ "unchecked", "rawtypes" })
  152. public Collection getSysRole(String sql) throws ClassNotFoundException {
  153. Connection conn = null;
  154. Statement stat = null;
  155. ResultSet rs = null;
  156. DbConnection db = new DbConnection();
  157. try {
  158. conn = db.getConnection();
  159. stat = conn.createStatement();
  160. rs = stat.executeQuery(sql);
  161. ArrayList result = new ArrayList();
  162. while (rs.next()) {
  163. result.add(getRoleVO(rs));
  164. }
  165. return result;
  166. } catch (SQLException e) {
  167. this.log.error(e.getMessage(), e);
  168. throw new ClassNotFoundException("DAO Layou: 取得RoleVO集合" + sql, e);
  169. } finally {
  170. db.close(rs);
  171. db.close(stat);
  172. db.close(conn);
  173. }
  174. }
  175. private RoleVO getRoleVO(ResultSet rs) {
  176. RoleVO VO = new RoleVO();
  177. try {
  178. VO.setFdObjectid(rs.getString("FD_OBJECTID"));
  179. VO.setRoleId(rs.getString("ROLE_ID"));
  180. /* VO.setParentId(rs.getString("PARENT_ID"));
  181. VO.setRoleType(rs.getString("ROLE_TYPE"));
  182. VO.setRoleName(rs.getString("ROLE_NAME"));
  183. VO.setRoleDescription(rs.getString("ROLE_DESCRIPTION"));
  184. VO.setRoleState(rs.getInt("ROLE_STATE"));
  185. VO.setCreateUnit(rs.getString("CREATE_UNIT"));
  186. VO.setCreatorId(rs.getString("CREATOR_ID"));
  187. VO.setCreateTime(rs.getTimestamp("CREATE_TIME"));
  188. VO.setLastModifierId(rs.getString("LAST_MODIFIER_ID"));
  189. VO.setLastModifyTime(rs.getTimestamp("LAST_MODIFY_TIME"));*/
  190. } catch (SQLException e) {
  191. this.log.error(e.getMessage(), e);
  192. }
  193. return VO;
  194. }
  195. /**
  196. * 功能:根据条件查询角色信息
  197. *
  198. * @param type
  199. * 角色类型
  200. * @param deptId
  201. * 部门id
  202. */
  203. @SuppressWarnings("rawtypes")
  204. public List loadRoleInfoByCondition() {
  205. String sql = "select * from SYS_ROLE ";
  206. List list = null;
  207. try {
  208. list = persistence.getSearchResultToMap(99, sql);
  209. } catch (PersistenceException e) {
  210. log.error(e.getMessage());
  211. }
  212. return list;
  213. }
  214. }