Search in sources :

Example 6 with UserDeviceBean

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;
}
Also used : UserDeviceBean(com.akaxin.site.storage.bean.UserDeviceBean) ArrayList(java.util.ArrayList) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

Example 7 with UserDeviceBean

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);
}
Also used : ErrorCode2(com.akaxin.common.constant.ErrorCode2) ApiDeviceListProto(com.akaxin.proto.site.ApiDeviceListProto) UserDeviceBean(com.akaxin.site.storage.bean.UserDeviceBean) CommandResponse(com.akaxin.common.command.CommandResponse) DeviceProto(com.akaxin.proto.core.DeviceProto)

Example 8 with UserDeviceBean

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);
}
Also used : ApiSecretChatApplyU2Proto(com.akaxin.proto.site.ApiSecretChatApplyU2Proto) ErrorCode2(com.akaxin.common.constant.ErrorCode2) ConfigProto(com.akaxin.proto.core.ConfigProto) UserDeviceBean(com.akaxin.site.storage.bean.UserDeviceBean) CommandResponse(com.akaxin.common.command.CommandResponse) DeviceProto(com.akaxin.proto.core.DeviceProto)

Example 9 with UserDeviceBean

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;
}
Also used : UserDeviceBean(com.akaxin.site.storage.bean.UserDeviceBean) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

Aggregations

UserDeviceBean (com.akaxin.site.storage.bean.UserDeviceBean)9 CommandResponse (com.akaxin.common.command.CommandResponse)5 ErrorCode2 (com.akaxin.common.constant.ErrorCode2)5 DeviceProto (com.akaxin.proto.core.DeviceProto)4 PreparedStatement (java.sql.PreparedStatement)4 ResultSet (java.sql.ResultSet)4 ArrayList (java.util.ArrayList)2 ConfigProto (com.akaxin.proto.core.ConfigProto)1 ApiDeviceBoundListProto (com.akaxin.proto.site.ApiDeviceBoundListProto)1 ApiDeviceListProto (com.akaxin.proto.site.ApiDeviceListProto)1 ApiDeviceProfileProto (com.akaxin.proto.site.ApiDeviceProfileProto)1 ApiSecretChatApplyU2Proto (com.akaxin.proto.site.ApiSecretChatApplyU2Proto)1 ApiSiteLoginProto (com.akaxin.proto.site.ApiSiteLoginProto)1 SimpleUserBean (com.akaxin.site.storage.bean.SimpleUserBean)1 UserSessionBean (com.akaxin.site.storage.bean.UserSessionBean)1 PublicKey (java.security.PublicKey)1 Signature (java.security.Signature)1