use of com.akaxin.site.storage.bean.U2MessageBean in project openzaly by akaxincom.
the class SQLiteU2MessageDao method getU2Message.
public List<U2MessageBean> getU2Message(String userId, String deviceId, long start, long limit) throws SQLException {
long startTime = System.currentTimeMillis();
List<U2MessageBean> msgList = new ArrayList<U2MessageBean>();
String sql = "SELECT id,site_user_id,msg_id,send_user_id,msg_type,content,device_id,ts_key,msg_time FROM " + USER2_MESSAGE_TABLE + " WHERE site_user_id=? AND id>? LIMIT ?;";
long pointer = queryU2MessagePointer(userId, deviceId);
start = start > pointer ? start : pointer;
PreparedStatement statement = SQLiteJDBCManager.getConnection().prepareStatement(sql);
statement.setString(1, userId);
statement.setLong(2, start);
statement.setLong(3, limit);
ResultSet rs = statement.executeQuery();
while (rs.next()) {
U2MessageBean u2MsgBean = new U2MessageBean();
u2MsgBean.setId(rs.getInt(1));
u2MsgBean.setSiteUserId(rs.getString(2));
u2MsgBean.setMsgId(rs.getString(3));
u2MsgBean.setSendUserId(rs.getString(4));
u2MsgBean.setMsgType(rs.getInt(5));
u2MsgBean.setContent(rs.getString(6));
u2MsgBean.setDeviceId(rs.getString(7));
u2MsgBean.setTsKey(rs.getString(8));
u2MsgBean.setMsgTime(rs.getLong(9));
msgList.add(u2MsgBean);
}
LogUtils.dbDebugLog(logger, startTime, msgList.size(), sql, userId, start, limit);
return msgList;
}
use of com.akaxin.site.storage.bean.U2MessageBean in project openzaly by akaxincom.
the class SyncU2MessageHandler method handle.
public Boolean handle(Command command) {
ChannelSession channelSession = command.getChannelSession();
try {
ImSyncMessageProto.ImSyncMessageRequest syncRequest = ImSyncMessageProto.ImSyncMessageRequest.parseFrom(command.getParams());
String siteUserId = command.getSiteUserId();
String deviceId = command.getDeviceId();
LogUtils.requestDebugLog(logger, command, syncRequest.toString());
long clientU2Pointer = syncRequest.getU2Pointer();
long u2Pointer = syncDao.queryU2Pointer(siteUserId, deviceId);
long startPointer = NumUtils.getMax(clientU2Pointer, u2Pointer);
int syncTotalCount = 0;
while (true) {
// 批量一次查询100条U2消息
List<U2MessageBean> u2MessageList = syncDao.queryU2Message(siteUserId, deviceId, startPointer, SYNC_MAX_MESSAGE_COUNT);
// 有二人消息才会发送给客户端,同时返回最大的游标
if (u2MessageList != null && u2MessageList.size() > 0) {
startPointer = u2MessageToClient(channelSession.getChannel(), u2MessageList);
syncTotalCount += u2MessageList.size();
}
// 判断跳出循环的条件
if (u2MessageList == null || u2MessageList.size() < SYNC_MAX_MESSAGE_COUNT) {
break;
}
}
logger.debug("client={} siteUserId={} deviceId={} sync u2-msg from pointer={} count={}.", command.getClientIp(), siteUserId, deviceId, startPointer, syncTotalCount);
} catch (Exception e) {
logger.error("sync u2 message error", e);
}
return true;
}
use of com.akaxin.site.storage.bean.U2MessageBean in project openzaly by akaxincom.
the class U2MessageImageHandler method handle.
public Boolean handle(Command command) {
try {
ImCtsMessageProto.ImCtsMessageRequest request = ImCtsMessageProto.ImCtsMessageRequest.parseFrom(command.getParams());
int type = request.getType().getNumber();
if (CoreProto.MsgType.IMAGE_VALUE == type) {
String siteUserId = command.getSiteUserId();
String siteFriendId = command.getSiteFriendId();
String msgId = request.getImage().getMsgId();
String imageId = request.getImage().getImageId();
U2MessageBean u2Bean = new U2MessageBean();
u2Bean.setMsgId(msgId);
u2Bean.setMsgType(type);
u2Bean.setSendUserId(siteUserId);
u2Bean.setSiteUserId(siteFriendId);
u2Bean.setContent(imageId);
long msgTime = System.currentTimeMillis();
u2Bean.setMsgTime(msgTime);
LogUtils.requestDebugLog(logger, command, u2Bean.toString());
boolean success = messageDao.saveU2Message(u2Bean);
msgStatusResponse(command, msgId, msgTime, success);
return success;
}
return true;
} catch (Exception e) {
LogUtils.requestErrorLog(logger, command, this.getClass(), e);
}
return false;
}
use of com.akaxin.site.storage.bean.U2MessageBean in project openzaly by akaxincom.
the class U2MessageNoticeHandler method handle.
@Override
public Boolean handle(Command command) {
try {
ImCtsMessageProto.ImCtsMessageRequest request = ImCtsMessageProto.ImCtsMessageRequest.parseFrom(command.getParams());
int type = request.getType().getNumber();
if (CoreProto.MsgType.U2_NOTICE_VALUE == type) {
String siteUserId = command.getSiteUserId();
String siteFriendId = command.getSiteFriendId();
String text = request.getU2MsgNotice().getText().toStringUtf8();
String msgId = request.getU2MsgNotice().getMsgId();
long msgTime = System.currentTimeMillis();
U2MessageBean u2Bean = new U2MessageBean();
u2Bean.setMsgId(msgId);
u2Bean.setMsgType(type);
u2Bean.setSendUserId(siteUserId);
u2Bean.setSiteUserId(siteFriendId);
u2Bean.setContent(text);
u2Bean.setMsgTime(msgTime);
LogUtils.requestDebugLog(logger, command, u2Bean.toString());
return messageDao.saveU2Message(u2Bean);
}
return true;
} catch (Exception e) {
LogUtils.requestErrorLog(logger, command, this.getClass(), e);
}
return false;
}
use of com.akaxin.site.storage.bean.U2MessageBean in project openzaly by akaxincom.
the class U2MessageVoiceHandler method handle.
public Boolean handle(Command command) {
try {
ImCtsMessageProto.ImCtsMessageRequest request = ImCtsMessageProto.ImCtsMessageRequest.parseFrom(command.getParams());
int type = request.getType().getNumber();
if (CoreProto.MsgType.VOICE_VALUE == type) {
String siteUserId = command.getSiteUserId();
String siteFriendId = command.getSiteFriendId();
String msgId = request.getVoice().getMsgId();
String voiceId = request.getVoice().getVoiceId();
U2MessageBean u2Bean = new U2MessageBean();
u2Bean.setMsgId(msgId);
u2Bean.setMsgType(type);
u2Bean.setSendUserId(siteUserId);
u2Bean.setSiteUserId(siteFriendId);
u2Bean.setContent(voiceId);
long msgTime = System.currentTimeMillis();
u2Bean.setMsgTime(msgTime);
LogUtils.requestDebugLog(logger, command, u2Bean.toString());
boolean success = messageDao.saveU2Message(u2Bean);
msgStatusResponse(command, msgId, msgTime, success);
return success;
}
return true;
} catch (Exception e) {
logger.error("U2 Message Voice error!", e);
}
return false;
}
Aggregations