use of com.akaxin.site.storage.bean.UserDeviceBean in project openzaly by akaxincom.
the class SQLiteUserDeviceDao method queryActiveDeviceList.
public List<UserDeviceBean> queryActiveDeviceList(String siteUserId) throws SQLException {
List<UserDeviceBean> devicesBean = new ArrayList<UserDeviceBean>();
long startTime = System.currentTimeMillis();
String sql = "SELECT a.site_user_id,a.device_id,a.login_time,b.user_device_pubk,b.device_name,b.active_time FROM " + USER_SESSION_TABLE + " AS a LEFT JOIN " + USER_DEVICE_TABLE + " AS b WHERE a.device_id=b.device_id AND a.site_user_id=b.site_user_id AND a.site_user_id=? ORDER BY b.active_time DESC;";
PreparedStatement preStatement = SQLiteJDBCManager.getConnection().prepareStatement(sql);
preStatement.setString(1, siteUserId);
ResultSet rs = preStatement.executeQuery();
while (rs.next()) {
UserDeviceBean deviceBean = new UserDeviceBean();
deviceBean.setSiteUserId(rs.getString(1));
deviceBean.setDeviceId(rs.getString(2));
deviceBean.setLoginTime(rs.getLong(3));
deviceBean.setUserDevicePubk(rs.getString(4));
deviceBean.setDeviceName(rs.getString(5));
deviceBean.setActiveTime(rs.getLong(6));
devicesBean.add(deviceBean);
}
LogUtils.dbDebugLog(logger, startTime, devicesBean.size(), sql, siteUserId);
return devicesBean;
}
use of com.akaxin.site.storage.bean.UserDeviceBean in project openzaly by akaxincom.
the class ApiDeviceService method list.
public CommandResponse list(Command command) {
CommandResponse commandResponse = new CommandResponse();
ErrorCode2 errCode = ErrorCode2.ERROR;
try {
ApiDeviceListProto.DeviceListInfoRequest request = ApiDeviceListProto.DeviceListInfoRequest.parseFrom(command.getParams());
String siteFriendId = request.getSiteUserId();
LogUtils.requestDebugLog(logger, command, request.toString());
if (StringUtils.isNotBlank(siteFriendId)) {
ApiDeviceListProto.DeviceListInfoResponse.Builder responseBuilder = ApiDeviceListProto.DeviceListInfoResponse.newBuilder();
List<UserDeviceBean> deviceList = UserDeviceDao.getInstance().getActiveDeviceList(siteFriendId);
for (UserDeviceBean device : deviceList) {
DeviceProto.SimpleDeviceProfile deviceProfile = DeviceProto.SimpleDeviceProfile.newBuilder().setDeviceId(String.valueOf(device.getDeviceId())).setDeviceName(String.valueOf(device.getDeviceName())).setUserDevicePubk(String.valueOf(device.getUserDevicePubk())).setLastLoginTime(device.getActiveTime()).build();
responseBuilder.addList(deviceProfile);
}
commandResponse.setParams(responseBuilder.build().toByteArray());
errCode = ErrorCode2.SUCCESS;
} else {
errCode = ErrorCode2.ERROR_PARAMETER;
}
} catch (Exception e) {
errCode = ErrorCode2.ERROR_SYSTEMERROR;
LogUtils.requestErrorLog(logger, command, e);
}
return commandResponse.setErrCode2(errCode);
}
use of com.akaxin.site.storage.bean.UserDeviceBean in project openzaly by akaxincom.
the class ApiSecretChatService method applyU2.
/**
* 申请二人密聊
*
* @param command
* @return
*/
public CommandResponse applyU2(Command command) {
CommandResponse commandResponse = new CommandResponse().setAction(CommandConst.ACTION_RES);
ErrorCode2 errCode = ErrorCode2.ERROR;
try {
ApiSecretChatApplyU2Proto.ApiSecretChatApplyU2Request request = ApiSecretChatApplyU2Proto.ApiSecretChatApplyU2Request.parseFrom(command.getParams());
String siteUserId = command.getSiteUserId();
String siteFriendId = request.getSiteFriendId();
LogUtils.requestDebugLog(logger, command, request.toString());
if (StringUtils.isNoneBlank(siteUserId, siteFriendId) && !siteUserId.equals(siteFriendId)) {
ConfigProto.U2EncryptionStatus status = SiteConfig.getU2EncryStatus();
logger.debug("siteUserId={} apply encryption chat to siteFriendId={} status={}", siteUserId, siteFriendId, status);
if (ConfigProto.U2EncryptionStatus.U2_OPEN == status) {
UserDeviceBean deviceBean = userDeviceDao.getLatestDevice(siteFriendId);
logger.debug("get siteUserId:{} deviceInfo:{}", siteFriendId, deviceBean.toString());
DeviceProto.SimpleDeviceProfile deviceProfile = DeviceProto.SimpleDeviceProfile.newBuilder().setDeviceId(deviceBean.getDeviceId()).setDeviceName(String.valueOf(deviceBean.getDeviceName())).setUserDevicePubk(deviceBean.getUserDevicePubk()).setLastLoginTime(deviceBean.getActiveTime()).build();
ApiSecretChatApplyU2Proto.ApiSecretChatApplyU2Response response = ApiSecretChatApplyU2Proto.ApiSecretChatApplyU2Response.newBuilder().setDeviceProfile(deviceProfile).build();
commandResponse.setParams(response.toByteArray());
errCode = ErrorCode2.SUCCESS;
} else {
errCode = ErrorCode2.ERROR2_SECRETCHAT_CLOSE;
}
} else {
errCode = ErrorCode2.ERROR_PARAMETER;
}
} catch (Exception e) {
errCode = ErrorCode2.ERROR_SYSTEMERROR;
LogUtils.requestErrorLog(logger, command, e);
}
return commandResponse.setErrCode2(errCode);
}
use of com.akaxin.site.storage.bean.UserDeviceBean in project openzaly by akaxincom.
the class SQLiteUserDeviceDao method queryDeviceDetails.
public UserDeviceBean queryDeviceDetails(String siteUserId, String deviceId) throws SQLException {
long startTime = System.currentTimeMillis();
UserDeviceBean deviceBean = new UserDeviceBean();
String sql = "SELECT a.site_user_id,a.device_id,a.login_time,b.device_name,b.device_ip,b.active_time,b.add_time from " + USER_SESSION_TABLE + " AS a LEFT JOIN " + USER_DEVICE_TABLE + " AS b WHERE a.site_user_id=b.site_user_id AND a.device_id=b.device_id AND a.site_user_id=? AND a.device_id=?;";
PreparedStatement preStatement = SQLiteJDBCManager.getConnection().prepareStatement(sql);
preStatement.setString(1, siteUserId);
preStatement.setString(2, deviceId);
ResultSet rs = preStatement.executeQuery();
if (rs.next()) {
deviceBean.setSiteUserId(rs.getString(1));
deviceBean.setDeviceId(rs.getString(2));
deviceBean.setLoginTime(rs.getLong(3));
deviceBean.setDeviceName(rs.getString(4));
deviceBean.setDeviceIp(rs.getString(5));
deviceBean.setActiveTime(rs.getLong(6));
deviceBean.setAddTime(rs.getLong(7));
}
LogUtils.dbDebugLog(logger, startTime, deviceBean.toString(), sql, siteUserId, deviceId);
return deviceBean;
}
Aggregations