/* * @see com.beike.dao.background.guest.GuestDao#queryGuestCountByConditions(com.beike.form.background.guest.GuestForm) */ public int queryGuestCountByConditions(GuestForm guestForm) throws Exception { int totalRows = 0; StringBuilder sql = new StringBuilder(); sql.append( "SELECT COUNT(1) FROM beiker_guest_info c LEFT JOIN beiker_brand b ON b.brand_id = c.brand_id WHERE 1=1 "); if (guestForm.getGuestId() > 0) { sql.append(" AND c.guest_id = ").append(guestForm.getGuestId()); } if (StringUtils.validNull(guestForm.getGuestCnName())) { sql.append(" AND c.guest_cn_name LIKE ") .append("'%" + guestForm.getGuestCnName().trim() + "%'"); } if (StringUtils.validNull(guestForm.getBrandName())) { sql.append(" AND b.brand_name LIKE ").append("'%" + guestForm.getBrandName().trim() + "%'"); } if (StringUtils.validNull(guestForm.getGuestAddress())) { sql.append(" AND c.guest_address LIKE ") .append("'%" + guestForm.getGuestAddress().trim() + "%'"); } if (guestForm.getBrandId() > 0) { sql.append(" AND c.brand_id = ").append(guestForm.getBrandId()); } totalRows = this.getJdbcTemplate().queryForInt(sql.toString()); return totalRows; }
/* * @see com.beike.dao.background.guest.GuestDao#queryGuestByConditions(com.beike.form.background.guest.GuestForm, int, int) */ @SuppressWarnings("unchecked") public List<Guest> queryGuestByConditions(GuestForm guestForm, int startRow, int pageSize) throws Exception { List tempList = null; List<Guest> guestList = new ArrayList<Guest>(); StringBuilder sql = new StringBuilder(); sql.append( "SELECT c.guest_id guest_id,c.guest_cn_name guest_cn_name,b.brand_name brand_name,c.guest_address guest_address,c.guest_status guest_status,c.brand_id brand_id FROM beiker_guest_info c "); sql.append("LEFT JOIN beiker_brand b ON b.brand_id = c.brand_id WHERE 1=1 "); if (guestForm.getGuestId() > 0) { sql.append(" AND c.guest_id = ").append(guestForm.getGuestId()); } if (StringUtils.validNull(guestForm.getGuestCnName())) { sql.append(" AND c.guest_cn_name LIKE ") .append("'%" + guestForm.getGuestCnName().trim() + "%'"); } if (StringUtils.validNull(guestForm.getBrandName())) { sql.append(" AND b.brand_name LIKE ").append("'%" + guestForm.getBrandName().trim() + "%'"); } if (StringUtils.validNull(guestForm.getGuestAddress())) { sql.append(" AND c.guest_address LIKE ") .append("'%" + guestForm.getGuestAddress().trim() + "%'"); } if (guestForm.getBrandId() > 0) { sql.append(" AND c.brand_id = ").append(guestForm.getBrandId()); } sql.append(" ORDER BY guest_id DESC LIMIT ?,? "); Object[] params = new Object[] {startRow, pageSize}; int[] types = new int[] {Types.INTEGER, Types.INTEGER}; tempList = this.getJdbcTemplate().queryForList(sql.toString(), params, types); if (null != tempList && tempList.size() > 0) { guestList = this.convertResultToObjectList(tempList); } return guestList; }