Search in sources :

Example 1 with CommandResponse

use of com.akaxin.common.command.CommandResponse in project openzaly by akaxincom.

the class ApiDeviceService method profile.

public CommandResponse profile(Command command) {
    CommandResponse commandResponse = new CommandResponse();
    ErrorCode2 errCode = ErrorCode2.ERROR;
    try {
        ApiDeviceProfileProto.ApiDeviceProfileRequest request = ApiDeviceProfileProto.ApiDeviceProfileRequest.parseFrom(command.getParams());
        String siteUserId = command.getSiteUserId();
        String deviceId = request.getDeviceId();
        LogUtils.requestDebugLog(logger, command, request.toString());
        if (StringUtils.isNotBlank(siteUserId) && StringUtils.isNotBlank(deviceId)) {
            UserDeviceBean deviceBean = UserDeviceDao.getInstance().getDeviceDetails(siteUserId, deviceId);
            DeviceProto.SimpleDeviceProfile deviceProfile = DeviceProto.SimpleDeviceProfile.newBuilder().setDeviceId(String.valueOf(deviceBean.getDeviceId())).setDeviceName(String.valueOf(deviceBean.getDeviceName())).setLastLoginTime(deviceBean.getLoginTime()).build();
            ApiDeviceProfileProto.ApiDeviceProfileResponse response = ApiDeviceProfileProto.ApiDeviceProfileResponse.newBuilder().setDeviceProfile(deviceProfile).setLoginIp(String.valueOf(deviceBean.getDeviceIp())).setLastActiveTime(deviceBean.getActiveTime()).build();
            commandResponse.setParams(response.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) UserDeviceBean(com.akaxin.site.storage.bean.UserDeviceBean) ApiDeviceProfileProto(com.akaxin.proto.site.ApiDeviceProfileProto) CommandResponse(com.akaxin.common.command.CommandResponse) DeviceProto(com.akaxin.proto.core.DeviceProto)

Example 2 with CommandResponse

use of com.akaxin.common.command.CommandResponse in project openzaly by akaxincom.

the class ApiDeviceService method boundList.

/**
 * 获取用户在该站点所有关联设备号
 *
 * @param command
 * @return
 */
public CommandResponse boundList(Command command) {
    CommandResponse commandResponse = new CommandResponse();
    ErrorCode2 errCode = ErrorCode2.ERROR;
    try {
        ApiDeviceBoundListProto.ApiDeviceBoundListRequest request = ApiDeviceBoundListProto.ApiDeviceBoundListRequest.parseFrom(command.getParams());
        String currentUserId = command.getSiteUserId();
        String siteUserId = request.getSiteUserId();
        LogUtils.requestDebugLog(logger, command, request.toString());
        if (StringUtils.isNotBlank(currentUserId) && currentUserId.equals(siteUserId)) {
            ApiDeviceBoundListProto.ApiDeviceBoundListResponse.Builder responseBuilder = ApiDeviceBoundListProto.ApiDeviceBoundListResponse.newBuilder();
            List<UserDeviceBean> deviceList = UserDeviceDao.getInstance().getBoundDevices(siteUserId);
            for (UserDeviceBean device : deviceList) {
                DeviceProto.SimpleDeviceProfile deviceProfile = DeviceProto.SimpleDeviceProfile.newBuilder().setDeviceId(String.valueOf(device.getDeviceId())).setDeviceName(String.valueOf(device.getDeviceName())).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) UserDeviceBean(com.akaxin.site.storage.bean.UserDeviceBean) ApiDeviceBoundListProto(com.akaxin.proto.site.ApiDeviceBoundListProto) CommandResponse(com.akaxin.common.command.CommandResponse) DeviceProto(com.akaxin.proto.core.DeviceProto)

Example 3 with CommandResponse

use of com.akaxin.common.command.CommandResponse in project openzaly by akaxincom.

the class ApiFileService method download.

public CommandResponse download(Command command) {
    CommandResponse commandResponse = new CommandResponse();
    ErrorCode2 errCode = ErrorCode2.ERROR;
    try {
        ApiFileDownloadProto.ApiFileDownloadRequest request = ApiFileDownloadProto.ApiFileDownloadRequest.parseFrom(command.getParams());
        String fileId = request.getFileId();
        LogUtils.requestDebugLog(logger, command, request.toString());
        if (StringUtils.isNotBlank(fileId) && !"null".equals(fileId)) {
            byte[] imageBytes = FileServerUtils.fileToBinary(FilePathUtils.getPicPath(), fileId);
            if (imageBytes != null && imageBytes.length > 0) {
                FileProto.File file = FileProto.File.newBuilder().setFileId(fileId).setFileContent(ByteString.copyFrom(imageBytes)).build();
                ApiFileDownloadProto.ApiFileDownloadResponse response = ApiFileDownloadProto.ApiFileDownloadResponse.newBuilder().setFile(file).build();
                commandResponse.setParams(response.toByteArray());
                errCode = ErrorCode2.SUCCESS;
            } else {
                // 获取文件资源失败,文件可能不存在,此时需要抛出异常
                errCode = ErrorCode2.ERROR2_FILE_DOWNLOAD;
            }
        } else {
            errCode = ErrorCode2.ERROR_PARAMETER;
        }
    } catch (Exception e) {
        errCode = ErrorCode2.ERROR_SYSTEMERROR;
        LogUtils.requestErrorLog(logger, command, e);
    }
    return commandResponse.setErrCode2(errCode);
}
Also used : FileProto(com.akaxin.proto.core.FileProto) ErrorCode2(com.akaxin.common.constant.ErrorCode2) CommandResponse(com.akaxin.common.command.CommandResponse) ApiFileDownloadProto(com.akaxin.proto.site.ApiFileDownloadProto) ByteString(com.google.protobuf.ByteString)

Example 4 with CommandResponse

use of com.akaxin.common.command.CommandResponse in project openzaly by akaxincom.

the class ApiFriendService method applyCount.

public CommandResponse applyCount(Command command) {
    CommandResponse commandResponse = new CommandResponse().setAction(CommandConst.ACTION_RES);
    ErrorCode2 errCode = ErrorCode2.ERROR;
    try {
        String siteUserId = command.getSiteUserId();
        LogUtils.requestDebugLog(logger, command, "");
        if (StringUtils.isNotBlank(siteUserId)) {
            int applyCount = UserFriendDao.getInstance().getApplyCount(siteUserId);
            ApiFriendApplyCountProto.ApiFriendApplyCountResponse response = ApiFriendApplyCountProto.ApiFriendApplyCountResponse.newBuilder().setApplyCount(applyCount).build();
            commandResponse.setParams(response.toByteArray());
            errCode = ErrorCode2.SUCCESS;
        }
    } catch (Exception e) {
        errCode = ErrorCode2.ERROR_SYSTEMERROR;
        LogUtils.requestErrorLog(logger, command, e);
    }
    return commandResponse.setErrCode2(errCode);
}
Also used : ErrorCode2(com.akaxin.common.constant.ErrorCode2) CommandResponse(com.akaxin.common.command.CommandResponse) ApiFriendApplyCountProto(com.akaxin.proto.site.ApiFriendApplyCountProto)

Example 5 with CommandResponse

use of com.akaxin.common.command.CommandResponse in project openzaly by akaxincom.

the class ApiFriendService method profile.

/**
 * 查询好友的个人资料
 *
 * @param command
 * @return
 */
public CommandResponse profile(Command command) {
    CommandResponse commandResponse = new CommandResponse().setAction(CommandConst.ACTION_RES);
    ErrorCode2 errCode = ErrorCode2.ERROR;
    try {
        ApiFriendProfileProto.ApiFriendProfileRequest request = ApiFriendProfileProto.ApiFriendProfileRequest.parseFrom(command.getParams());
        String siteUserId = command.getSiteUserId();
        // 等待查询的站点用户ID || globalUserId
        String globalOrSiteFriendId = request.getSiteUserId();
        // 等待查询的用户公钥,优先级高
        String userIdPubk = request.getUserIdPubk();
        LogUtils.requestDebugLog(logger, command, request.toString());
        if (StringUtils.isAllEmpty(userIdPubk, globalOrSiteFriendId)) {
            errCode = ErrorCode2.ERROR_PARAMETER;
            return commandResponse.setErrCode2(errCode);
        }
        UserProfileBean userBean = UserProfileDao.getInstance().getUserProfileById(globalOrSiteFriendId);
        if (null == userBean || StringUtils.isBlank(userBean.getSiteUserId())) {
            // 直接复用之前的接口了。
            userBean = UserProfileDao.getInstance().getUserProfileByGlobalUserId(globalOrSiteFriendId);
        }
        if (userBean != null && StringUtils.isNotBlank(userBean.getSiteUserId())) {
            UserProto.UserProfile userProfileProto = UserProto.UserProfile.newBuilder().setSiteUserId(String.valueOf(userBean.getSiteUserId())).setUserName(String.valueOf(userBean.getUserName())).setUserPhoto(String.valueOf(userBean.getUserPhoto())).setUserStatusValue(userBean.getUserStatus()).build();
            UserProto.UserRelation userRelation = UserFriendDao.getInstance().getUserRelation(siteUserId, userBean.getSiteUserId());
            ApiFriendProfileProto.ApiFriendProfileResponse response = ApiFriendProfileProto.ApiFriendProfileResponse.newBuilder().setProfile(userProfileProto).setRelation(userRelation).setUserIdPubk(userBean.getUserIdPubk()).build();
            commandResponse.setParams(response.toByteArray());
            errCode = ErrorCode2.SUCCESS;
        }
    } catch (Exception e) {
        errCode = ErrorCode2.ERROR_SYSTEMERROR;
        LogUtils.requestErrorLog(logger, command, e);
    }
    return commandResponse.setErrCode2(errCode);
}
Also used : ErrorCode2(com.akaxin.common.constant.ErrorCode2) UserProto(com.akaxin.proto.core.UserProto) CommandResponse(com.akaxin.common.command.CommandResponse) ApiFriendProfileProto(com.akaxin.proto.site.ApiFriendProfileProto) UserProfileBean(com.akaxin.site.storage.bean.UserProfileBean)

Aggregations

CommandResponse (com.akaxin.common.command.CommandResponse)82 ErrorCode2 (com.akaxin.common.constant.ErrorCode2)68 UserProto (com.akaxin.proto.core.UserProto)12 PluginBean (com.akaxin.site.storage.bean.PluginBean)7 ByteString (com.google.protobuf.ByteString)7 GroupProto (com.akaxin.proto.core.GroupProto)6 GroupProfileBean (com.akaxin.site.storage.bean.GroupProfileBean)6 SimpleUserBean (com.akaxin.site.storage.bean.SimpleUserBean)6 UserProfileBean (com.akaxin.site.storage.bean.UserProfileBean)6 UserDeviceBean (com.akaxin.site.storage.bean.UserDeviceBean)5 Command (com.akaxin.common.command.Command)4 DeviceProto (com.akaxin.proto.core.DeviceProto)4 ProtocolStringList (com.google.protobuf.ProtocolStringList)4 ConfigProto (com.akaxin.proto.core.ConfigProto)3 GroupMemberBean (com.akaxin.site.storage.bean.GroupMemberBean)3 UserGroupBean (com.akaxin.site.storage.bean.UserGroupBean)3 RedisCommand (com.akaxin.common.command.RedisCommand)2 ImStcPsnProto (com.akaxin.proto.client.ImStcPsnProto)2 CoreProto (com.akaxin.proto.core.CoreProto)2 FileProto (com.akaxin.proto.core.FileProto)2