package com.vci.server.framework.systemConfig.stafforgmanage.combination; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import org.hibernate.HibernateException; import org.hibernate.type.Type; import com.vci.server.base.persistence.dao.BaseService; import com.vci.server.base.persistence.dao.HibernateCallback; import com.vci.server.base.persistence.dao.HibernateTemplate; import com.vci.server.framework.systemConfig.stafforgmanage.passwordStrategy.PasswordStrategyDaoImpl; import com.vci.server.framework.systemConfig.stafforgmanage.role.RoleDAOImpl; public class CombinationService extends BaseService { /** * 获取所有密码组合方式 *

Description:

* * @author wangxl * @time 2013-1-3 * @return */ @SuppressWarnings("rawtypes") public List getAllList() { return (List)new HibernateTemplate().run(new HibernateCallback() { public Object execute() throws HibernateException { CombinationDAOImpl impl = new CombinationDAOImpl(); return impl.loadAll(); } }); } @SuppressWarnings("rawtypes") public List fetchCombinationsByPstId(final String pstId) { return (List)new HibernateTemplate().run(new HibernateCallback() { public Object execute() throws HibernateException { CombinationDAOImpl impl = new CombinationDAOImpl(); String sql = "select c.* from PLCOMBINATION c where c.PLUID in " + "(select t.PLCOMBINATIONUID " + "from PLCOMBINATIONPASSWORDSTRATEGY t " + "where t.PLPASSWORDSTRATEGYUID = '"+pstId+"')"; Object[] values = new Object[0]; List list = impl.findEntites(sql, values, "c", Combination.class); return list; } }); } /** * 分页查询组合方式 */ public List fetchCombinationsToPage(final int pageIndex, final int pageSize){ return (List)new HibernateTemplate().run(new HibernateCallback() { public Object execute() throws HibernateException { CombinationDAOImpl impl = new CombinationDAOImpl(); String hsql = "select * from plcombination p order by p.PLNAME"; String sql = getPageSQL(hsql,pageSize,pageIndex); Object [] o = {}; return impl.findEntites(sql,o, "", Combination.class); //return impl.loadAll(); } }); } public List getCombinationsObjById(final String id) { return (List)new HibernateTemplate().run(new HibernateCallback() { public Object execute() throws HibernateException { PasswordStrategyDaoImpl impl = new PasswordStrategyDaoImpl(); String sql = " select * from plcombination u where u.pluid = '"+id+"' "; Object [] o = {}; return impl.findEntites(sql,o, "", Combination.class); } }); } /** * 添加密码组合方式 *

Description:

* * @author wangxl * @time 2013-1-3 * @param comb */ public void saveCombination(final Combination comb){ new HibernateTemplate().run(new HibernateCallback() { public Object execute() throws HibernateException { CombinationDAOImpl impl = new CombinationDAOImpl(); comb.setUserEntity(userEntity); impl.save(comb); return comb; } }); } public boolean updateCombination(final Combination comb){ return (Boolean)new HibernateTemplate().run(new HibernateCallback() { public Object execute() throws HibernateException { CombinationDAOImpl impl = new CombinationDAOImpl(); Combination cComb = impl.getById(comb.getId()); if (cComb == null) { comb.setUserEntity(userEntity); impl.saveOrUpdate(comb); } else { cComb.setName(comb.getName()); cComb.setDesc(comb.getDesc()); cComb.setUpdateTime(comb.getUpdateTime() ); cComb.setUpdateUser(comb.getUpdateUser()); cComb.setUserEntity(userEntity); impl.saveOrUpdate(cComb); } return true; } }); } public boolean deleteCombinationByMQL(final String[] ids) { return (Boolean)new HibernateTemplate().run(new HibernateCallback() { public Object execute() throws HibernateException { int len = ids.length; String inStr = ""; for (int i = 0; i < len; i++) { inStr += "?"; if (i != len - 1) { inStr += ","; } } CombinationDAOImpl impl = new CombinationDAOImpl(); String hql = "delete Combination c where c.id in (" + inStr + ")"; impl.deleteQueryObject(hql, ids, userEntity); CombinationValueDAOImpl valIImpl = new CombinationValueDAOImpl(); String shql = "delete CombinationValue cv where cv.parentId in (" + inStr + ")"; valIImpl.deleteQueryObject(shql, ids, userEntity); return true; } }); } //分页查询 public String getPageSQL(String sql, int pageSize, int pageIndex ){ if(pageIndex <= 0){ pageIndex = 1; } int startRownum = (pageIndex - 1) * pageSize + 1; int endRownum = pageIndex * pageSize; String partionSql = "" + "SELECT * FROM( " + " SELECT A.*,ROWNUM RN FROM( " + sql + " ) A " + ") WHERE RN <= " + String.valueOf(endRownum) + " AND RN >= " + String.valueOf(startRownum); return partionSql; } public int checkCombinationIsquotedCount(final String id ){ return (Integer)new HibernateTemplate().run(new HibernateCallback() { public Object execute() throws HibernateException { int count = 0; RoleDAOImpl impl = new RoleDAOImpl(); String hsql = "select count(*) from plcombinationpasswordstrategy u where u.PLCOMBINATIONUID = '"+id+"'" ; List list = new ArrayList(); Object[] values = new Object[0]; Map map = new HashMap(); list = impl.findEntitesBySQL(hsql, values,map); if (list != null){ count = Integer.valueOf(String.valueOf(list.get(0))).intValue(); } return count; } }); } }