public long getLastJoinTime(String uid, String activityId) { long lastTime = 0; Connection conn = null; PreparedStatement ps = null; ResultSet rs = null; try { conn = DBUtil.getConnection(); String sql = "select * from `ssyh_main`.`activity_join` where `uid` = ? and `activity_id`=? order by `create_time` desc;"; ps = conn.prepareStatement(sql); ps.setString(1, uid); ps.setString(2, activityId); rs = ps.executeQuery(); if (rs.next()) { lastTime = StringUtil.timestamp2long(rs.getTimestamp("create_time")); } } catch (SQLException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } finally { DBUtil.close(rs, ps, conn); } return lastTime; }
public boolean insertShiftJF(String uid, int jf_num) { boolean flag = false; Connection conn = null; PreparedStatement ps = null; try { conn = DBUtil.getConnection(); String sql = "insert into `ssyh_main`.`trade_mx_" + uid.substring(0, 1) + "` (`trade_id`,`uid`,`jf_num`,`type`,`status`) values(?,?,?,?,?) "; ps = conn.prepareStatement(sql); ps.setString(1, StringUtil.generateTradeId()); ps.setString(2, uid); ps.setInt(3, jf_num); ps.setInt(4, Value.trade_mx_type_shift); ps.setInt(5, Value.trade_mx_status_success); ps.executeUpdate(); flag = true; } catch (SQLException e) { logger.error("error stack", e); } finally { DBUtil.close(ps, conn); } return flag; }
public int join( Activity activity, String uid, int runningDay, int status, String activityUniqueId) { int ret = 0; Connection conn = null; PreparedStatement ps = null; ResultSet rs = null; try { conn = DBUtil.getConnection(); if (activity == null || activity.getId() == null || "".equals(activity.getId()) || uid == null || "".equals(uid)) { return ret; } if (isExsit(activity.getId(), activityUniqueId)) { ret = 2; return ret; } String sql = "insert into `ssyh_main`.`activity_join`(`id`,`uid`,`date`,`running_days`,`create_time`,`jf_num`,`activity_id`,`activity_name`,`status`,`activity_unique_id`) values(?,?,?,?,?,?,?,?,?,?)"; ps = conn.prepareStatement(sql); String today = ft.format(new Date()); int n = -1; int j = 0; String tradeId = null; while (n < 0 && j++ < 10) { tradeId = getTradeId(uid); ps.setString(1, tradeId); ps.setString(2, uid); ps.setString(3, today); ps.setInt(4, runningDay); ps.setTimestamp(5, StringUtil.long2timestamp(System.currentTimeMillis())); ps.setInt(6, activity.getJfNum()); ps.setString(7, activity.getId()); ps.setString(8, activity.getName()); ps.setInt(9, status); ps.setString(10, activityUniqueId); n = ps.executeUpdate(); if (n > 0) { ret = 1; } } } catch (SQLException e) { logger.error("error stack", e); } catch (Exception e) { logger.error("error stack", e); } finally { DBUtil.close(rs, ps, conn); } return ret; }
public List<TradeMx> getJFAddMX(String uid, int page, int pageSize) { List<TradeMx> tradeMxList = new ArrayList<TradeMx>(); Connection conn = null; PreparedStatement ps = null; ResultSet rs = null; try { conn = DBUtil.getConnection(); String sql = "select * from `ssyh_main`.`trade_mx_" + uid.substring(0, 1) + "` where `uid`=? and type in (1,2,3) limit ?,?"; ps = conn.prepareStatement(sql); ps.setString(1, uid); ps.setInt(2, (pageSize * (page - 1))); ps.setInt(3, pageSize); rs = ps.executeQuery(); while (rs.next()) { TradeMx tradeMx = new TradeMx(); tradeMx.setDescription(rs.getString("description")); tradeMx.setId(rs.getInt("id")); tradeMx.setInsert_time(StringUtil.timestamp2datetime(rs.getTimestamp("insert_time"))); tradeMx.setJf_num(rs.getInt("jf_num")); tradeMx.setStatus(rs.getInt("status")); tradeMx.setTrade_id(rs.getString("trade_id")); tradeMx.setType(rs.getInt("type")); tradeMx.setUid(uid); tradeMx.setIcon( "http://gi2.md.alicdn.com/bao/uploaded/i2/TB1ypNbHXXXXXc1XpXXXXXXXXXX_!!0-item_pic.jpg_430x430q90.jpg"); tradeMxList.add(tradeMx); } } catch (SQLException e) { logger.error("error stack", e); } finally { DBUtil.close(rs, ps, conn); } return tradeMxList; }