package com.vci.server.framework.systemConfig.stafforgmanage.user; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Timestamp; import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; import org.hibernate.HibernateException; import org.hibernate.type.Type; import com.vci.common.objects.UserEntity; import com.vci.common.resource.CommonProperties; import com.vci.server.base.persistence.dao.BaseService; import com.vci.server.base.persistence.dao.HibernateCallback; import com.vci.server.base.persistence.dao.HibernateCallbackExt; import com.vci.server.base.persistence.dao.HibernateTemplate; import com.vci.server.base.persistence.dao.JDBCCallback; import com.vci.server.base.persistence.dao.JDBCRunType; import com.vci.server.base.persistence.dao.JDBCTemplate; import com.vci.server.framework.timer.TimeService; public class UserService extends BaseService { public UserService() {} public UserService(UserEntity userEntity) { super(userEntity); } /** * *

Description:创建人员

* * @author wangxl * @time 2012-5-11 * @param user */ public void saveUser(final User user) { new HibernateTemplate().run(new HibernateCallback() { public Object execute() throws HibernateException { UserDAOImpl impl = new UserDAOImpl(); user.setUserEntity(userEntity); impl.save(user); UserLogonDAOImpl userLogonDAOImpl = new UserLogonDAOImpl(); UserLogon userLogon = new UserLogon(); userLogon.setPluserOid(user.getId()); userLogon.setPlWrongNum((short)0); userLogon.setPlLogonTime(new Timestamp(System.currentTimeMillis())); userLogon.setUserEntity(userEntity); userLogonDAOImpl.save(userLogon); return user; } }); } /** *

Description:

* * @author wangxl * @time 2012-5-11 * @param User */ public void updateUser(final User user) { new HibernateTemplate().run(new HibernateCallback() { public Object execute() throws HibernateException { UserDAOImpl impl = new UserDAOImpl(); User cUser = impl.getById(user.getId()); if (cUser == null) { user.setUserEntity(userEntity); impl.saveOrUpdate(user); return user; } else { cUser.setUserName(user.getUserName()); if (cUser.getPassword().equals(user.getPassword())) { cUser.setPwdUpdateTime(user.getPwdUpdateTime()); } else { cUser.setPwdUpdateTime(new Timestamp(System.currentTimeMillis())); } cUser.setPassword(user.getPassword()); cUser.setTrueName(user.getTrueName()); cUser.setSpecialties(user.getSpecialties()); cUser.setEmail(user.getEmail()); cUser.setDesc(user.getDesc()); cUser.setUserEntity(userEntity); cUser.setUpdateTime(new Timestamp(System.currentTimeMillis())); cUser.setUpdateUser(user.getUpdateUser()); cUser.setGrantor(user.getGrantor()); cUser.setStatus(user.getStatus()); cUser.setIsDeptLeader(user.getIsDeptLeader()); cUser.setSecretGrade(user.getSecretGrade()); impl.saveOrUpdate(cUser); return cUser; } } }); } public List getAllUser() { return (List)new HibernateTemplate().run(new HibernateCallback() { public Object execute() throws HibernateException { UserDAOImpl impl = new UserDAOImpl(); String hsql = " from User"; return impl.findEntities(hsql); } }); } public List getUserList() { return (List)new HibernateTemplate().run(new HibernateCallback() { public Object execute() throws HibernateException { UserDAOImpl impl = new UserDAOImpl(); String hsql = " from User u where u.userName <> 'admin' and u.userType > 0 order by u.trueName"; return impl.findEntities(hsql); } }); } /** *

Description:

* @author liujw * @time 2013-5-7 */ public List getUserListWithOutSanYuan() { return (List)new HibernateTemplate().run(new HibernateCallback() { public Object execute() throws HibernateException { UserDAOImpl impl = new UserDAOImpl(); String sql = " select * from pluser u where u.plusername " + " in (select u.plusername from pluser u inner join pluserrole ur on u.plusername <> 'admin' and u.plusertype > 0 and u.pluid = ur.pluseruid and ur.plroleuid " + " in (select r.pluid from plrole r where r.plname <> 'sysAdmin' and r.plname <> 'securityAdmin' and r.plname <> 'auditAdmin' )) order by u.pltruename " ; Object[] values = new Object[0]; List list = impl.findEntites(sql, values, "u", User.class); return list; } }); } /** * 按条件查询用户 * @param name * @param userName * @param deptId * @param roleId * @param groupId * @param loginName * @param pageNo * @param pageSize * @return */ public List getUserListByCondition(final String name, final String userName, final String deptId, final String roleId,final String loginName,final int pageNo,final int pageSize,final boolean filterUserType) { return (List)new HibernateTemplate().run(new HibernateCallback() { public Object execute() throws HibernateException { UserDAOImpl impl = new UserDAOImpl(); // String hsql = "from User user where user.userName = :name"; // User user = impl.findEntity(hsql, "name", loginName); // int type = user.getUserType(); // if (type<2){ // type = type + 1; // } int V_PAGE_ROWNUM_START = (pageNo - 1) * pageSize; int V_PAGE_ROWNUM_END = (pageNo ) * pageSize; StringBuffer sb = new StringBuffer(); sb.append(" SELECT * "); sb.append(" FROM (SELECT ROW_.*, ROWNUM RN "); sb.append(" FROM ("); // sb.append(" select u.* from pluser u where u.pluserType = "); // sb.append(type); // sb.append(" select u.* from pluser u where u.pluserType IN(1,2)"); if(filterUserType){ sb.append(" select u.* from pluser u where u.pluserType > 1 "); }else{ sb.append(" select u.* from pluser u where u.pluserType > 0 "); } if (!"".equals(name)){ sb.append(" and u.PLTRUENAME like '%"+name+"%' "); } if (!"".equals(userName)){ sb.append(" and u.plusername like '%"+userName+"%' "); } if (!"".equals(deptId)){ sb.append(" and u.pluid in (select ud.pluseruid from pluserdept ud where ud.pldeptuid = '"+deptId+"' ) "); } if (!"".equals(roleId)){ sb.append("and u.pluid in (select ur.pluseruid from PLUSERROLE ur where ur.plroleuid = '"+roleId+"') "); } sb.append(" order by u.PLTRUENAME "); sb.append(" )ROW_)"); sb.append(" WHERE RN <= "); sb.append( V_PAGE_ROWNUM_END); sb.append(" AND RN > "); sb.append(V_PAGE_ROWNUM_START); Object[] values = new Object[0]; List list = impl.findEntites(sb.toString(), values, "u", User.class); return list; } }); } //add by caill 2016.9.26 public List getUserListByConditionUnited(final String name, final String userName, final String deptId, final String roleId,final String loginName,final int pageNo,final int pageSize,final boolean filterUserType) { return (List)new HibernateTemplate().run(new HibernateCallback() { public Object execute() throws HibernateException { UserDAOImpl impl = new UserDAOImpl(); // String hsql = "from User user where user.userName = :name"; // User user = impl.findEntity(hsql, "name", loginName); // int type = user.getUserType(); // if (type<2){ // type = type + 1; // } int V_PAGE_ROWNUM_START = (pageNo - 1) * pageSize; int V_PAGE_ROWNUM_END = (pageNo ) * pageSize; StringBuffer sb = new StringBuffer(); sb.append(" SELECT * "); sb.append(" FROM (SELECT ROW_.*, ROWNUM RN "); sb.append(" FROM ("); // sb.append(" select u.* from pluser u where u.pluserType = "); // sb.append(type); // sb.append(" select u.* from pluser u where u.pluserType IN(1,2)"); if(filterUserType){ sb.append(" select u.* from pluser u where u.pluserType > 1 "); }else{ sb.append(" select u.* from pluser u where u.pluserType > 0 "); } if (!"".equals(name)){ sb.append(" and u.PLTRUENAME like '%"+name+"%' "); } if (!"".equals(userName)){ sb.append(" and u.plusername like '%"+userName+"%' "); } //add by caill 2016.9.26此处做了级联查询 if (!"".equals(deptId)){ sb.append(" and u.pluid in (select ud.pluseruid from pluserdept ud where ud.pldeptuid in( select d.pluid from pldept d start with d.pluid = '"+deptId+"' connect by prior d.pluid = d.plparentuid)) "); } if (!"".equals(roleId)){ sb.append("and u.pluid in (select ur.pluseruid from PLUSERROLE ur where ur.plroleuid = '"+roleId+"') "); } sb.append(" order by u.PLTRUENAME "); sb.append(" )ROW_)"); sb.append(" WHERE RN <= "); sb.append( V_PAGE_ROWNUM_END); sb.append(" AND RN > "); sb.append(V_PAGE_ROWNUM_START); Object[] values = new Object[0]; List list = impl.findEntites(sb.toString(), values, "u", User.class); return list; } }); } //add by caill end public int getUserTotalByCondition(final String name, final String userName, final String deptId, final String roleId,final String loginName,final boolean filterUserType ) { UserDAOImpl impl = new UserDAOImpl(); String hsql = "from User user where user.userName = :name"; User user = impl.findEntity(hsql, "name", loginName); int type = user.getUserType(); if (type<2){ type = type + 1; } int res = 0; StringBuffer sb = new StringBuffer(); sb.append(" SELECT COUNT(*) "); sb.append(" FROM ("); //不考虑用户级别 --2013-10-29 by liudi start // sb.append(" select u.* from pluser u where u.pluserType = "); // sb.append(type); if(filterUserType){ sb.append(" select u.* from pluser u where u.pluserType >1 "); }else{ sb.append(" select u.* from pluser u where u.pluserType >0 "); } //2013-10-29 by liudi end if (!"".equals(name)){ sb.append(" and u.PLTRUENAME like '%"+name+"%' "); } if (!"".equals(userName)){ sb.append(" and u.plusername like '%"+userName+"%' "); } if (!"".equals(deptId)){ sb.append(" and u.pluid in (select ud.pluseruid from pluserdept ud where ud.pldeptuid = '"+deptId+"' ) "); } if (!"".equals(roleId)){ sb.append("and u.pluid in (select ur.pluseruid from PLUSERROLE ur where ur.plroleuid = '"+roleId+"') "); } sb.append(" order by u.PLTRUENAME "); sb.append(" )"); res = (Integer)new JDBCTemplate().run(new JDBCCallback( new HibernateTemplate().getSessionConnection(), sb.toString(), JDBCRunType.SQL, 0, false, false,new Object[]{}) { @Override public Object execute(ResultSet rst) throws SQLException { int ress = 0; while(rst.next()){ ress = rst.getInt(1); } return ress; } }); return res; } public List getUserInfoList(final String id) { UserDAOImpl impl = new UserDAOImpl(); String hsql = " from User u where u.id = '"+id+"' order by u.trueName"; return impl.findEntities(hsql); } public List getUserListByType(final int type) { return (List)new HibernateTemplate().run(new HibernateCallback() { public Object execute() throws HibernateException { UserDAOImpl impl = new UserDAOImpl(); String hsql = " from User u where u.userName <> 'admin' and u.userName <> 'developer' and u.userName <> 'root' and u.userType = ? order by u.trueName"; int a = type; if (a<2){ a = a + 1; } Object[] values = {a}; return impl.findEntites(hsql, values); } }); } public List fetchUserInfoByRoleId(final String roleId , final int type) { return (List)new HibernateTemplate().run(new HibernateCallback() { public Object execute() throws HibernateException { UserDAOImpl impl = new UserDAOImpl(); int a = type; if (a<2){ a = a + 1; } //and u.pluserType = "+ a +" String hsql = " select * from pluser u where u.plusername <> 'admin' and u.PLUID in " + " (select ur.pluseruid from pluserrole ur where ur.plroleuid = '"+roleId+"') order by u.pltrueName "; Object[] values = new Object[0]; List list = impl.findEntites(hsql, values, "u", User.class); return list; } }); } public List fetchUsersByRoleId(final String roleId) { return (List)new HibernateTemplate().run(new HibernateCallback() { public Object execute() throws HibernateException { UserDAOImpl impl = new UserDAOImpl(); String hsql = " select * from pluser u where u.plusername <> 'admin' and u.PLUID in " + " (select ur.pluseruid from pluserrole ur where ur.plroleuid = '"+roleId+"') order by u.pltrueName "; Object[] values = new Object[0]; List list = impl.findEntites(hsql, values, "u", User.class); return list; } }); } public List selectUserByRoleId(final String roleId) { return (List)new HibernateTemplate().run(new HibernateCallback() { public Object execute() throws HibernateException { UserDAOImpl impl = new UserDAOImpl(); String hsql = " select * from pluser u where u.plusername <> 'admin' and u.PLUID in " + " (select ur.pluseruid from pluserrole ur where ur.plroleuid = '"+roleId+"') order by u.pltrueName "; Object[] values = new Object[0]; List list = impl.findEntites(hsql, values, "u", User.class); return list; } }); } /** * 获取部门下的成员 * @param deptId * @return */ @SuppressWarnings("rawtypes") public List getUserByDeptId(final String deptId) { return (List)new HibernateTemplate().run(new HibernateCallback() { public Object execute() throws HibernateException { UserDAOImpl impl = new UserDAOImpl(); String hsql = " select * from pluser u where u.plusername <> 'admin' and u.PLUID in " + " (select ud.pluseruid from pluserdept ud where ud.pldeptuid = '"+deptId+"') order by u.pltrueName "; Object[] values = new Object[0]; List list = impl.findEntites(hsql, values, "u", User.class); return list; } }); } /** * *

获取信号下的所有型号总师:

* * @time 2013-3-28 * @param modelId 型号ID * @return */ @SuppressWarnings("rawtypes") public List fetchUserInfoByModelId(final String modelId) { return (List)new HibernateTemplate().run(new HibernateCallback() { public Object execute() throws HibernateException { UserDAOImpl impl = new UserDAOImpl(); String hsql = " select * from pluser u where u.plusername <> 'admin' and u.PLUID in " + " (select ud.PLUSERID from PLMODELUSER ud where ud.PLMODELID = '"+modelId+"') order by u.pltrueName "; Object[] values = new Object[0]; List list = impl.findEntites(hsql, values, "u", User.class); return list; } }); } @SuppressWarnings("rawtypes") public List fetchUserInfoByModel(final String model) { return (List)new HibernateTemplate().run(new HibernateCallback() { public Object execute() throws HibernateException { UserDAOImpl impl = new UserDAOImpl(); String hsql = " select * from pluser u where u.plusername <> 'admin' and u.PLUID in " + " (select ud.PLUSERID from PLMODELUSER ud where ud.PLMODELID in (" + " select m.PLoid from plmodelconfig m where m .plname = '"+model+"'))"; Object[] values = new Object[0]; List list = impl.findEntites(hsql, values, "u", User.class); return list; } }); } @SuppressWarnings("rawtypes") public List fetchUserInfoByDeptAndRole(final String[] deptIds , final String[] roleIds) { return (List)new HibernateTemplate().run(new HibernateCallback() { public Object execute() throws HibernateException { UserDAOImpl impl = new UserDAOImpl(); String hsql = " select * from pluser u where u.plusername <> 'admin' and u.PLUID in " + " (select ud.pluseruid from pluserdept ud where ud.pldeptuid = '"+deptIds[0]+"')" + " and u.PLUID in (select ur.pluseruid from PLUSERROLE ur where ur.plroleuid = '"+roleIds[0]+"')" ; Object[] values = new Object[0]; List list = impl.findEntites(hsql, values, "u", User.class); return list; } }); } public List fetchUserInfoByPvolumeId(final String pvolumeId , final int type) { return (List)new HibernateTemplate().run(new HibernateCallback() { public Object execute() throws HibernateException { UserDAOImpl impl = new UserDAOImpl(); int a = type; if (a<2){ a = a + 1; } String hsql = " select * from pluser u where u.plusername <> 'admin' and u.pluserType = "+ a +" and u.PLUID in " + " (select up.pluseruid from pluserpvolume up where up.plpvolumeuid = '"+pvolumeId+"') order by u.pltrueName "; Object[] values = new Object[0]; List list = impl.findEntites(hsql, values, "u", User.class); return list; } }); } public boolean deleteUser(final String id) { return (Boolean)new HibernateTemplate().run(new HibernateCallback() { public Object execute() throws HibernateException { UserDAOImpl impl = new UserDAOImpl(); User User = impl.loadById(id); User.setUserEntity(userEntity); impl.delete(User); UserLogonDAOImpl userLogonDAOImpl = new UserLogonDAOImpl(); UserLogon userLogon = new UserLogon(); userLogon = userLogonDAOImpl.loadById(id); userLogon.setUserEntity(userEntity); userLogonDAOImpl.delete(userLogon); return true; } }); } /** * 按照id 删除成员 * @param id * @return */ public boolean deleteUserByHQL(final String id) { return (Boolean)new HibernateTemplate().run(new HibernateCallback() { public Object execute() throws HibernateException { UserDAOImpl impl = new UserDAOImpl(); String hql = "delete User u where u.id=:id"; impl.deleteQueryObject(hql, "id", id, userEntity); return true; } }); } public boolean stopUsers(final String id , final boolean flag) { return (Boolean)new HibernateTemplate().run(new HibernateCallback() { public Object execute() throws HibernateException { UserDAOImpl impl = new UserDAOImpl(); String hql = ""; if (flag){//停用 hql = "update User u set u.status = 1 where u.id=:id"; }else { hql = "update User u set u.status = 0 where u.id=:id"; } impl.deleteQueryObject(hql, "id", id, userEntity); return true; } }); } /** * 删除指定数组的成员 * @param ids * @return */ public boolean deleteUserByHQL(final String[] ids) { return (Boolean)new HibernateTemplate().run(new HibernateCallback() { public Object execute() throws HibernateException { UserDAOImpl impl = new UserDAOImpl(); String hql = "delete User u where u.id in ("; int len = ids.length; for (int i = 0; i < len; i++) { hql += "?"; if (i != len - 1) { hql += ","; } } hql += ")"; impl.deleteQueryObject(hql, ids, userEntity); return true; } }); } public User selectUserByName(final String name) { return (User)new HibernateTemplate().run(new HibernateCallback() { public Object execute() throws HibernateException { UserDAOImpl impl = new UserDAOImpl(); String hsql = "from User user where user.userName = :name order by user.trueName"; return impl.findEntity(hsql, "name", name); } }); } /** * 根据用户名返回用户对象 * * @param userName * @param password * @return */ public User getUserObjectByUserName(final String userName) { return (User) new HibernateTemplate().run(new HibernateCallback() { public Object execute() throws HibernateException { UserDAOImpl impl = new UserDAOImpl(); String hsql = " from User u where u.userName = ?"; Object[] values = { userName, }; List list = impl.findEntites(hsql, values); if (list.size() != 0) { return (User) list.get(0); } return null; } }); } /** * 验证用户登录 * @param userName * @param password * @return */ public User checkLogin(final String userName, final String password){ return (User)new HibernateTemplate().run(new HibernateCallback() { public Object execute() throws HibernateException { UserDAOImpl impl = new UserDAOImpl(); String hsql = " from User u where u.userName = ?"; Object[] values = {userName}; List list = impl.findEntites(hsql, values); if(list.size() != 0){ User user = (User)list.get(0); if (user.getPassword().equals(password)) return user; else return null; //return (User)list.get(0); } return null; } }); } public int getPwModifyTime(final String userOid){ return (Integer)new HibernateTemplate().run(new HibernateCallback() { public Object execute() throws HibernateException { int validity = -1; UserDAOImpl impl = new UserDAOImpl(); String hsql = " select p.PLPWMODTIME from PLUSEROPERATION p where p.PLUSEROID = '"+userOid+"'"; List list = new ArrayList(); Object[] values = new Object[0]; Map map = new HashMap(); list = impl.findEntitesBySQL(hsql, values,map); if (list.size() != 0 &&list.get(0)!=null){ String pwModifyTime = list.get(0).toString(); int betweenDay = compare_date(pwModifyTime,new Date()); int storagelife = Integer.parseInt(CommonProperties.getStringProperty("logon.pwd.storagelife")); validity = storagelife - betweenDay; } return validity; } }); } //两个日期间隔多少天 private int compare_date(String DATE1, Date DATE2) { DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); long nd = 1000*24*60*60;//一天的毫秒数 Date dt1 = null; try { dt1 = df.parse(DATE1); } catch (ParseException e) { e.printStackTrace(); } Date dt2 = DATE2; return (int) ((dt2.getTime() - dt1.getTime()+1000000)/nd); } // public int getPwPromptDate(){ // return Integer.parseInt(CommonProperties.getStringProperty("logon.pwd.promptdate")); // } /** * *

保存型号和型号总师之间的关系:

* * @time 2013-3-28 * @param modelIds * @param userId * @return */ public boolean saveUserModel(final String[] modelIds , final String[] userIds ){ return (Boolean)new HibernateTemplate().runExt(new HibernateCallbackExt() { public Object execute(Connection conn) throws HibernateException, SQLException { String sql = "delete PLMODELUSER ur where ur.PLMODELID = ? "; PreparedStatement pstmt = null; PreparedStatement pstmt1 = null; try { pstmt = conn.prepareStatement(sql); for(String modelId :modelIds ){ pstmt.setString(1, modelId); pstmt.execute(); } } catch (SQLException e1) { e1.printStackTrace(); } finally { if (pstmt != null){ pstmt.close(); } } try { for(String modelId :modelIds ){ for (int i = 0 ; i < userIds.length ; i ++){ String hql = "insert into PLMODELUSER values (? , ?)"; pstmt1 = conn.prepareStatement(hql); pstmt1.setString(1, userIds[i]); pstmt1.setString(2, modelId); pstmt1.execute(); } } }catch (SQLException e1) { e1.printStackTrace(); } finally { if (pstmt1 != null){ pstmt1.close(); } } return true; } }); } public boolean saveRights(final String[] roleIds , final String userId ){ return (Boolean)new HibernateTemplate().runExt(new HibernateCallbackExt() { public Object execute(Connection conn) throws HibernateException, SQLException { String sql = "delete pluserrole ur where ur.pluseruid = ? "; PreparedStatement pstmt = null; PreparedStatement pstmt1 = null; try { pstmt = conn.prepareStatement(sql); pstmt.setString(1, userId); pstmt.execute(); } catch (SQLException e1) { e1.printStackTrace(); } finally { if (pstmt != null){ pstmt.close(); } } try { for (int i = 0 ; i < roleIds.length ; i ++){ String hql = "insert into pluserrole values (? , ?)"; pstmt1 = conn.prepareStatement(hql); pstmt1.setString(1, userId); pstmt1.setString(2, roleIds[i]); pstmt1.execute(); } }catch (SQLException e1) { e1.printStackTrace(); } finally { if (pstmt1 != null){ pstmt1.close(); } } return true; } }); } public boolean saveUserDept(final String userId , final String deptId ){ return (Boolean)new HibernateTemplate().runExt(new HibernateCallbackExt() { public Object execute(Connection conn) throws HibernateException, SQLException { String sql = "delete pluserdept ud where ud.pluseruid = ?"; PreparedStatement pstmt = null; PreparedStatement pstmt1 = null; try { pstmt = conn.prepareStatement(sql); pstmt.setString(1, userId); pstmt.execute(); } catch (SQLException e1) { e1.printStackTrace(); } finally { if (pstmt != null){ pstmt.close(); } } if (!"".equals(deptId)){ try { String hql = "insert into pluserdept values (? , ?)"; pstmt1 = conn.prepareStatement(hql); pstmt1.setString(1, userId); pstmt1.setString(2, deptId); pstmt1.execute(); }catch (SQLException e1) { e1.printStackTrace(); } finally { if (pstmt1 != null){ pstmt1.close(); } } } return true; } }); } public boolean saveUserPasswordStrateg(final String userId , final String passwordStrategId ){ return (Boolean)new HibernateTemplate().runExt(new HibernateCallbackExt() { public Object execute(Connection conn) throws HibernateException, SQLException { String sql = "delete PLUSERPASSWORDSTRATEGY ud where ud.pluseruid = ?"; PreparedStatement pstmt = null; PreparedStatement pstmt1 = null; try { pstmt = conn.prepareStatement(sql); pstmt.setString(1, userId); pstmt.execute(); } catch (SQLException e1) { e1.printStackTrace(); } finally { if (pstmt != null){ pstmt.close(); } } if (!"".equals(passwordStrategId)){ try { String hql = "insert into PLUSERPASSWORDSTRATEGY values (? , ?)"; pstmt1 = conn.prepareStatement(hql); pstmt1.setString(1, passwordStrategId); pstmt1.setString(2, userId); pstmt1.execute(); }catch (SQLException e1) { e1.printStackTrace(); } finally { if (pstmt1 != null){ pstmt1.close(); } } } return true; } }); } public void deleteRights(final String userId){ new HibernateTemplate().runExt(new HibernateCallbackExt() { public Object execute(Connection conn) throws HibernateException, SQLException { PreparedStatement pstmt = null; String hql1 = "delete from plusercompany uc where uc.pluseruid = ?"; String hql2 = "delete from pluserrole ur where ur.pluseruid = ?"; String hql3 = "delete from pluserdept ud where ud.pluseruid = ?"; String hql4 = "delete from PLUSERPASSWORDSTRATEGY us where us.pluseruid = ?"; // try { // pstmt = conn.prepareStatement(hql1); // pstmt.setString(1, userId); // pstmt.execute(); // } catch (SQLException e1) { // e1.printStackTrace(); // } finally{ // pstmt.close(); // } try { pstmt = conn.prepareStatement(hql2); pstmt.setString(1, userId); pstmt.execute(); } catch (SQLException e1) { e1.printStackTrace(); } finally{ pstmt.close(); } try { pstmt = conn.prepareStatement(hql3); pstmt.setString(1, userId); pstmt.execute(); } catch (SQLException e1) { e1.printStackTrace(); } finally{ pstmt.close(); } try { pstmt = conn.prepareStatement(hql4); pstmt.setString(1, userId); pstmt.execute(); } catch (SQLException e1) { e1.printStackTrace(); } finally{ pstmt.close(); } return null; } }); } public UserLogon getUserLogonObj(final String userId){ return (UserLogon)new HibernateTemplate().run(new HibernateCallback() { public Object execute() throws HibernateException { UserLogonDAOImpl impl = new UserLogonDAOImpl(); String hsql = " from UserLogon u where u.pluserOid = ? "; Object[] values = {userId}; List list = impl.findEntites(hsql, values); if(list.size() != 0){ return (UserLogon)list.get(0); } else { UserLogon userLogon = new UserLogon(); userLogon.setPluserOid(userId); userLogon.setPlWrongNum((short)0); userLogon.setPlLogonTime(new Timestamp(System.currentTimeMillis())); userLogon.setUserEntity(userEntity); impl.save(userLogon); return userLogon; } //return null; } }); } public long getSystemTime(){ return new TimeService().getDBTime(); } public void updateLogonInfo(final String userId,final boolean flag){ new HibernateTemplate().runExt(new HibernateCallbackExt() { public Object execute(Connection conn) throws HibernateException, SQLException { UserLogonDAOImpl impl = new UserLogonDAOImpl(); String hql = ""; if (flag){ hql = "Update UserLogon u set u.plWrongNum = 0 where u.pluserOid = '"+userId+"'" ; impl.createQuery(hql); }else{ hql = "Update PLLOGONINFO u set u.PLWRONGNUM = u.PLWRONGNUM+1 ,u.PLLOGONTIME = ? where u.PLUSERID = '"+userId+"'" ; PreparedStatement pstmt = null; try { pstmt = conn.prepareStatement(hql); pstmt.setTimestamp(1, new Timestamp(System.currentTimeMillis())); pstmt.executeUpdate(); } catch (SQLException e1) { e1.printStackTrace(); } finally{ pstmt.close(); } } return ""; } }); } public void deblock(final String[] ids){ new HibernateTemplate().run(new HibernateCallback() { public Object execute() throws HibernateException { UserLogonDAOImpl impl = new UserLogonDAOImpl(); String hql = ""; for (int i = 0 ; i < ids.length ; i ++){ hql = "Update UserLogon u set u.plWrongNum = 0 where u.pluserOid = '"+ids[i]+"'"; impl.createQuery(hql); } return ""; } }); } @SuppressWarnings("unchecked") public List fetchUserInfoByFilterString(final String filterString,final int pageNo, final int pageSize) { // TODO Auto-generated method stub return (List)new HibernateTemplate().run(new HibernateCallback() { public Object execute() throws HibernateException { int V_PAGE_ROWNUM_START = (pageNo - 1) * pageSize; int V_PAGE_ROWNUM_END = (pageNo ) * pageSize; UserDAOImpl impl = new UserDAOImpl(); StringBuffer sb=new StringBuffer(); sb.append(" select * from ( "); sb.append(" select pluser.*, ROWNUM rn from pluser "); sb.append(" where pluid in( "); sb.append(" select pluser.pluid from pluser "); sb.append(" left join pluserrole on pluser.pluid = pluserrole.pluseruid "); sb.append(" left join plrole on plrole.pluid = pluserrole.plroleuid "); sb.append(" left join pluserdept on pluser.pluid = pluserdept.pluseruid"); sb.append(" left join pldept on pluserdept.pldeptuid = pldept.pluid "); sb.append(" where pluser.plusername not in ('admin', 'secAdmin', 'developer', 'auditAdmin') "); sb.append(" and pluser.plusertype > 0 "); //加查询条件 // sb.append(" and pluser.plstatus = 0 "); sb.append( filterString ); sb.append(" ) "); sb.append(" ) WHERE RN >"); sb.append(V_PAGE_ROWNUM_START); sb.append(" and RN <= "); sb.append(V_PAGE_ROWNUM_END); Object[] values = new Object[0]; List list = impl.findEntites(sb.toString(), values, "u", User.class); return list; } } ); } public int fetchUserInfoByFilterStringCount(final String filterString) { StringBuffer sb=new StringBuffer(); sb.append(" select count(*) from pluser "); sb.append(" where pluid in( "); sb.append(" select pluser.pluid from pluser "); sb.append(" left join pluserrole on pluser.pluid = pluserrole.pluseruid "); sb.append(" left join plrole on plrole.pluid = pluserrole.plroleuid "); sb.append(" left join pluserdept on pluser.pluid = pluserdept.pluseruid"); sb.append(" left join pldept on pluserdept.pldeptuid = pldept.pluid "); sb.append(" where pluser.plusername not in ('admin', 'secAdmin', 'developer', 'auditAdmin') "); sb.append(" and pluser.plusertype > 0 "); ////加查询条件 //sb.append(" and pluser.plstatus = 0 "); sb.append( filterString ); sb.append(" ) "); int res=0; res = (Integer)new JDBCTemplate().run(new JDBCCallback( new HibernateTemplate().getSessionConnection(), sb.toString(), JDBCRunType.SQL, 0, false, false,new Object[]{}) { @Override public Object execute(ResultSet rst) throws SQLException { int ress = 0; while(rst.next()){ ress = rst.getInt(1); } return ress; } }); return res; } public List fetchUserInfosByFilterStringsql(String filterString){ // TODO Auto-generated method stub UserDAOImpl impl = new UserDAOImpl(); StringBuffer sb=new StringBuffer(); sb.append(" select * from pluser "); sb.append(" where pluid in( "); sb.append(" select pluser.pluid from pluser "); sb.append(" left join pluserrole on pluser.pluid = pluserrole.pluseruid "); sb.append(" left join plrole on plrole.pluid = pluserrole.plroleuid "); sb.append(" left join pluserdept on pluser.pluid = pluserdept.pluseruid"); sb.append(" left join pldept on pluserdept.pldeptuid = pldept.pluid "); sb.append(" where pluser.plusername not in ('admin', 'secAdmin', 'developer', 'auditAdmin') "); sb.append(" and pluser.plusertype > 0 "); //加查询条件 // sb.append(" and pluser.plstatus = 0 "); sb.append( filterString ); sb.append(" ) "); Object[] values = new Object[0]; List list = impl.findEntites(sb.toString(), values, "u", User.class); return list; } @SuppressWarnings("unchecked") public List fetchUserInfoByNames(final String[] names) { return (List)new HibernateTemplate().run(new HibernateCallback() { public Object execute() throws HibernateException { UserDAOImpl impl = new UserDAOImpl(); StringBuffer sb=new StringBuffer(); sb.append(" from User u where 1=1 "); String userOidstr=""; for (String userOid : names) { userOidstr+="".equals(userOidstr)?"'"+userOid+"'":",'"+userOid+"'"; } sb.append(" and u.userName in ( "); sb.append(userOidstr); sb.append(")"); sb.append("order by u.trueName"); Object[] values ={}; List list = impl.findEntites(sb.toString(), values); return list; } }); } public User getUserObjectByoid(final String userOid) { return (User)new HibernateTemplate().run(new HibernateCallback() { public Object execute() throws HibernateException { UserDAOImpl impl = new UserDAOImpl(); String hsql = "from User user where user.id = :id order by user.trueName"; return impl.findEntity(hsql, "id", userOid); } }); } @SuppressWarnings("unchecked") public List getUserObjectByoids(final String[] userOids) { return (List)new HibernateTemplate().run(new HibernateCallback() { public Object execute() throws HibernateException { UserDAOImpl impl = new UserDAOImpl(); StringBuffer sb=new StringBuffer(); sb.append(" from User u where 1=1 "); String userOidstr=""; for (String userOid : userOids) { userOidstr+="".equals(userOidstr)?"'"+userOid+"'":",'"+userOid+"'"; } sb.append(" and u.id in ( "); sb.append(userOidstr); sb.append(")"); sb.append("order by u.trueName"); Object[] values ={}; List list =impl.findEntites(sb.toString() , values); return list; } }); } public boolean chanageUserPassword(final String idUser, final String pw) { return (Boolean) new HibernateTemplate().run(new HibernateCallback() { public Object execute() throws HibernateException { UserDAOImpl impl = new UserDAOImpl(); String hql = ""; hql = "update User u set u.password=:pw where u.id=:id"; impl.updateQueryObject(hql, idUser, new String[] {"pw", "id"}, new String[] {pw, idUser}, userEntity); return true; } }); } }