123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232 |
- package com.sinosoft.lz.system.right.role.dao;
- import java.sql.Connection;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.sql.Statement;
- import java.util.ArrayList;
- import java.util.Collection;
- import java.util.Iterator;
- import java.util.List;
- import org.apache.log4j.Logger;
- import com.persistence.DbConnection;
- import com.persistence.service.PersistenceFactory;
- import com.persistence.service.SysPersistence;
- import com.persistence.service.assitant.generator.IdentityGenerator;
- import com.persistence.service.exception.PersistenceException;
- import com.sinosoft.lz.system.right.role.vo.RoleVO;
- import com.sysmodel.datamodel.xmlmodel.ModelFactory;
- import com.sysmodel.datamodel.xmlmodel.able.SysModel;
- public class RoleDAO{
- private static SysModel sysmodel = ModelFactory.getSysmodel();
- private static SysPersistence persistence = PersistenceFactory.getInstance(sysmodel);
- private Logger log = Logger.getLogger(RoleDAO.class);
- public boolean addSysRole(RoleVO VO) throws ClassNotFoundException {
- Connection conn = null;
- PreparedStatement st = null;
- DbConnection db = new DbConnection();
- try {
- 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 (?,?,?,?,?,?,?,?,?,?,?,?)";
- conn = db.getConnection();
- st = conn.prepareStatement(sql);
- st.setString(1, IdentityGenerator.getIdentityGenerator().gerenalPrimaryKey(conn, "881"));
- st.setString(2, VO.getRoleId());
- /* st.setString(3, VO.getParentId());
- st.setString(4, VO.getRoleType());
- st.setString(5, VO.getRoleName());
- st.setString(6, VO.getRoleDescription());
- st.setInt(7, VO.getRoleState());
- st.setString(8, VO.getCreateUnit());
- st.setString(9, VO.getCreatorId());
- st.setTimestamp(10, VO.getCreateTime());
- st.setString(11, VO.getLastModifierId());
- st.setTimestamp(12, VO.getLastModifyTime());*/
- return st.execute();
- } catch (SQLException e) {
- this.log.error(e.getMessage(), e);
- throw new ClassNotFoundException("DAO Layou: 新增", e);
- } finally {
- db.close(st);
- db.close(conn);
- }
- }
- public int[] addSysRole(ArrayList<RoleVO> voList) throws ClassNotFoundException {
- Connection conn = null;
- PreparedStatement st = null;
- DbConnection db = new DbConnection();
- try {
- 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 (?,?,?,?,?,?,?,?,?,?,?,?)";
- conn = db.getConnection();
- st = conn.prepareStatement(sql);
- RoleVO VO = null;
- for (int i = 0; i < voList.size(); i++) {
- VO = voList.get(i);
- st.setString(1, VO.getFdObjectid());
- st.setString(2, VO.getRoleId());
- /* st.setString(3, VO.getParentId());
- st.setString(4, VO.getRoleType());
- st.setString(5, VO.getRoleName());
- st.setString(6, VO.getRoleDescription());
- st.setInt(7, VO.getRoleState());
- st.setString(8, VO.getCreateUnit());
- st.setString(9, VO.getCreatorId());
- st.setTimestamp(10, VO.getCreateTime());
- st.setString(11, VO.getLastModifierId());
- st.setTimestamp(12, VO.getLastModifyTime());*/
- st.addBatch();
- }
- return st.executeBatch();
- } catch (SQLException e) {
- this.log.error(e.getMessage(), e);
- throw new ClassNotFoundException("DAO Layou: 新增", e);
- } finally {
- db.close(st);
- db.close(conn);
- }
- }
- public boolean modifySysRole(RoleVO VO) throws ClassNotFoundException {
- Connection conn = null;
- PreparedStatement st = null;
- DbConnection db = new DbConnection();
- try {
- String sql = "update SYS_ROLE set FD_OBJECTID = ?, ROLE_ID = ?, ROLE_CODE = ?, ROLE_NAME = ?, ROLE_DUTY = ?, IS_DEL = ?, MOD_DATE = ? where FD_OBJECTID = ?";
- conn = db.getConnection();
- st = conn.prepareStatement(sql);
- st.setString(1, VO.getFdObjectid());
- st.setString(2, VO.getRoleId());
- /* st.setString(3, VO.getParentId());
- st.setString(4, VO.getRoleType());
- st.setString(5, VO.getRoleName());
- st.setString(6, VO.getRoleDescription());
- st.setInt(7, VO.getRoleState());
- st.setString(8, VO.getCreateUnit());
- st.setString(9, VO.getCreatorId());
- st.setTimestamp(10, VO.getCreateTime());
- st.setString(11, VO.getLastModifierId());
- st.setTimestamp(12, VO.getLastModifyTime());
- st.setString(13, VO.getFdObjectid());
- st.executeUpdate();*/
- return true;
- } catch (SQLException e) {
- this.log.error(e.getMessage(), e);
- throw new ClassNotFoundException("DAO Layou: 修改", e);
- } finally {
- db.close(st);
- db.close(conn);
- }
- }
- @SuppressWarnings("unused")
- public boolean delSysRole(String roleId) throws ClassNotFoundException {
- Connection conn = null;
- Statement stat = null;
- DbConnection db = new DbConnection();
- String sql = "delete from SYS_ROLE where FD_OBJECTID=?";
- try {
- conn = db.getConnection();
- // stat = conn.prepareStatement(sql);
- // stat.setString(1, FD_OBJECTID);
- // conn = db.getConnection();
- stat = conn.createStatement();
- stat.addBatch("delete from SYS_ROLE where role_id='" + roleId + "'");
- stat.addBatch("delete from SYS_ROLE_RIGHT_REL where role_id='" + roleId + "'");
- stat.executeBatch();
- return true;
- } catch (SQLException e) {
- this.log.error(e.getMessage(), e);
- throw new ClassNotFoundException("DAO Layou: 删除", e);
- } finally {
- db.close(stat);
- db.close(conn);
- }
- }
- @SuppressWarnings("rawtypes")
- public RoleVO getRoleVO(String FD_OBJECTID) throws ClassNotFoundException {
- String sql = "select * from SYS_ROLE where FD_OBJECTID='" + FD_OBJECTID + "'";
- Collection coll = getSysRole(sql);
- Iterator it = coll.iterator();
- if (it.hasNext())
- return (RoleVO) it.next();
- return null;
- }
- @SuppressWarnings({ "unchecked", "rawtypes" })
- public Collection getSysRole(String sql) throws ClassNotFoundException {
- Connection conn = null;
- Statement stat = null;
- ResultSet rs = null;
- DbConnection db = new DbConnection();
- try {
- conn = db.getConnection();
- stat = conn.createStatement();
- rs = stat.executeQuery(sql);
- ArrayList result = new ArrayList();
- while (rs.next()) {
- result.add(getRoleVO(rs));
- }
- return result;
- } catch (SQLException e) {
- this.log.error(e.getMessage(), e);
- throw new ClassNotFoundException("DAO Layou: 取得RoleVO集合" + sql, e);
- } finally {
- db.close(rs);
- db.close(stat);
- db.close(conn);
- }
- }
- private RoleVO getRoleVO(ResultSet rs) {
- RoleVO VO = new RoleVO();
- try {
- VO.setFdObjectid(rs.getString("FD_OBJECTID"));
- VO.setRoleId(rs.getString("ROLE_ID"));
- /* VO.setParentId(rs.getString("PARENT_ID"));
- VO.setRoleType(rs.getString("ROLE_TYPE"));
- VO.setRoleName(rs.getString("ROLE_NAME"));
- VO.setRoleDescription(rs.getString("ROLE_DESCRIPTION"));
- VO.setRoleState(rs.getInt("ROLE_STATE"));
- VO.setCreateUnit(rs.getString("CREATE_UNIT"));
- VO.setCreatorId(rs.getString("CREATOR_ID"));
- VO.setCreateTime(rs.getTimestamp("CREATE_TIME"));
- VO.setLastModifierId(rs.getString("LAST_MODIFIER_ID"));
- VO.setLastModifyTime(rs.getTimestamp("LAST_MODIFY_TIME"));*/
- } catch (SQLException e) {
- this.log.error(e.getMessage(), e);
- }
- return VO;
- }
- /**
- * 功能:根据条件查询角色信息
- *
- * @param type
- * 角色类型
- * @param deptId
- * 部门id
- */
- @SuppressWarnings("rawtypes")
- public List loadRoleInfoByCondition() {
- String sql = "select * from SYS_ROLE ";
- List list = null;
- try {
- list = persistence.getSearchResultToMap(99, sql);
- } catch (PersistenceException e) {
- log.error(e.getMessage());
- }
- return list;
- }
- }
|