/** * 从Hbase中获取到指定deal的最后一次创意 * * @param uid * @param deal * @return */ public Long getLastCreative(String uid, String deal){ if (StringUtils.isBlank(uid) || StringUtils.isBlank(deal)) { returnnull; }
Table htable = null; try { // 对应的表 htable = connection.getTable(TableName.valueOf("lastExpose")); // 用户id作为rowkey Get get = new Get(Bytes.toBytes(uid)); // 列族 列名 get.addColumn(Bytes.toBytes("f"),Bytes.toBytes(deal));
Result result = htable.get(get); if (result != null && !result.isEmpty()) { // 内容 byte[] value = result.getValue(Bytes.toBytes("f"),Bytes.toBytes(deal));
String s = new String(value); Gson gson = new Gson(); // 最后一次曝光的创意 Long creative = gson.fromJson(s, Long.class); return creative; } } catch (IOException e) { LOGGER.error("get camp list failed: {}", uid); }finally { if (htable != null) { try { htable.close(); } catch (Exception closeExcption) { LOGGER.error("close connection failed: ", closeExcption); } } } returnnull; }