@Override public List<Z_User_Power_User> getZUPUList(int currentPage, int pageSize, Map<String, Object> m) { try { Connection conn = DBUtils.createConn(); String sql = " select * from Z_USER_POWER_USER where 1=1 "; Set<Entry<String, Object>> set = m.entrySet(); Iterator io = set.iterator(); while (io.hasNext()) { Map.Entry<String, Object> me = (Map.Entry<String, Object>) io.next(); if ("account_source".equals(me.getKey()) && !"".equals(me.getValue())) { sql += " and " + me.getKey() + " = '" + me.getValue() + "'"; } if ("account_source_type".equals(me.getKey()) && !"".equals(me.getValue())) { sql += " and " + me.getKey() + " = '" + me.getValue() + "'"; } if ("account_target".equals(me.getKey()) && !"".equals(me.getValue())) { sql += " and " + me.getKey() + " = '" + me.getValue() + "'"; } if ("account_target_type".equals(me.getKey()) && !"".equals(me.getValue())) { sql += " and " + me.getKey() + " = '" + me.getValue() + "'"; } if ("sort".equals(me.getKey()) && !"".equals(me.getValue())) { sql += " order by " + me.getValue(); } if ("order".equals(me.getKey()) && !"".equals(me.getValue())) { sql += " " + me.getValue(); } } if (currentPage > 0 && pageSize > 0) { sql = sql + " limit " + (currentPage - 1) * pageSize + " , " + pageSize; } PreparedStatement ps = DBUtils.getPs(conn, sql); ResultSet rs = ps.executeQuery(); List<Z_User_Power_User> ulist = new ArrayList<Z_User_Power_User>(); while (rs.next()) { Z_User_Power_User mp = new Z_User_Power_User(); mp.setAccount_source(rs.getString("account_source")); mp.setAccount_source_type(rs.getString("account_source_type")); mp.setAccount_target(rs.getString("account_target")); mp.setAccount_target_type(rs.getString("account_target_type")); ulist.add(mp); } return ulist; } catch (Exception e) { return null; } }
@Override public boolean saveZ_User_Power_User( String account_source, String account_source_type, String account_target, String account_target_type) { try { if (StringUtil.isNotEmpty(account_source) && StringUtil.isNotEmpty(account_source_type) && StringUtil.isNotEmpty(account_target) && StringUtil.isNotEmpty(account_target_type)) { Connection conn = DBUtils.createConn(); String sql = "insert into Z_USER_POWER_USER (account_source, account_source_type, account_target,account_target_type)" + " values('" + account_source + "','" + account_source_type + "','" + account_target + "','" + account_target_type + "')"; Statement st = conn.createStatement(); int ds = st.executeUpdate(sql); DBUtils.close(conn); if (st != null) { st.close(); } if (ds > 0) { return true; } else { return false; } } else { return false; } } catch (Exception e) { e.printStackTrace(); return false; } }
@Override public boolean deleteZ_User_Power_User( String account_source, String account_source_type, String account_target, String account_target_type) { try { Connection conn = DBUtils.createConn(); String sql = " delete from Z_USER_POWER_USER where 1=1"; if (StringUtil.isNotEmpty(account_target)) { sql += " and account_target ='" + account_target + "' "; } if (StringUtil.isNotEmpty(account_source_type)) { sql += " and account_source_type ='" + account_source_type + "' "; } if (StringUtil.isNotEmpty(account_target_type)) { sql += " and account_target_type ='" + account_target_type + "' "; } if (StringUtil.isNotEmpty(account_source)) { sql += " and account_source ='" + account_source + "' "; PreparedStatement ps = DBUtils.getPs(conn, sql); int isok = ps.executeUpdate(sql); DBUtils.close(ps); DBUtils.close(conn); if (isok > 0) { return true; } else { return false; } } else { return false; } } catch (Exception e) { e.printStackTrace(); return false; } }
@Override public int getTotal(Map<String, Object> m) throws Exception { Connection conn = DBUtils.createConn(); String sql = " select count(*) from Z_USER_POWER_USER where 1=1 "; Set<Entry<String, Object>> set = m.entrySet(); Iterator io = set.iterator(); while (io.hasNext()) { Map.Entry<String, Object> me = (Map.Entry<String, Object>) io.next(); if ("account_source".equals(me.getKey()) && !"".equals(me.getValue())) { sql += " and " + me.getKey() + " = '" + me.getValue() + "'"; } if ("account_source_type".equals(me.getKey()) && !"".equals(me.getValue())) { sql += " and " + me.getKey() + " = '" + me.getValue() + "'"; } if ("account_target".equals(me.getKey()) && !"".equals(me.getValue())) { sql += " and " + me.getKey() + " = '" + me.getValue() + "'"; } if ("account_target_type".equals(me.getKey()) && !"".equals(me.getValue())) { sql += " and " + me.getKey() + " = '" + me.getValue() + "'"; } if ("sort".equals(me.getKey()) && !"".equals(me.getValue())) { sql += " order by " + me.getValue(); } if ("order".equals(me.getKey()) && !"".equals(me.getValue())) { sql += " " + me.getValue(); } } PreparedStatement ps = DBUtils.getPs(conn, sql); ResultSet rs = ps.executeQuery(); int count = 0; if (rs.next()) { count = rs.getInt(1); } return count; }