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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations