Commit 7238ef14 by 罗长华

1、增加ContextService 提供获取上下文client和application接口

parent ed711263
package com.wecloud.im.service;
import com.wecloud.dispatch.extend.ActionRequest;
import com.wecloud.im.entity.ImApplication;
import com.wecloud.im.entity.ImClient;
/**
* 请求上下文服务
* @Author luozh
* @Date 2022年04月02日 14:51
* @Version 1.0
*/
public interface ContextService {
/**
* 获取当前或指定clientId的ImClient 存在返回 不存在则抛出异常
* @Author luozh
* @Date 2022年04月02日 02:52:09
* @param request Ws请求
* @Return
*/
ImClient getImClientIfNotNullOrThrow(ActionRequest request);
/**
* 获取当前或指定appId的ImApplication 存在返回 不存在则抛出异常
* @Author luozh
* @Date 2022年04月02日 02:54:21
* @param appId 应用id
* @Return
*/
ImApplication getImApplicationIfNotNullOrThrow(Long appId);
}
package com.wecloud.im.service.impl;
import io.geekidea.springbootplus.framework.common.exception.BusinessException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import com.wecloud.dispatch.extend.ActionRequest;
import com.wecloud.im.entity.ImApplication;
import com.wecloud.im.entity.ImClient;
import com.wecloud.im.service.ContextService;
import com.wecloud.im.service.ImApplicationService;
import com.wecloud.im.service.ImClientService;
/**
* 请求上下文服务 impl
* @Author luozh
* @Date 2022年04月02日 14:56
* @Version 1.0
*/
@Service
public class ContextServiceImpl implements ContextService {
@Autowired
@Lazy
private ImClientService imClientService;
@Autowired
private ImApplicationService imApplicationService;
@Override
public ImClient getImClientIfNotNullOrThrow(ActionRequest request) {
ImClient currentClient;
if (request != null) {
currentClient = imClientService.getCacheImClient(request.getSenderClientId());
} else {
currentClient = imClientService.getCurrentClient();
}
if (currentClient == null) {
throw new BusinessException("当前用户登录信息失效");
}
return currentClient;
}
@Override
public ImApplication getImApplicationIfNotNullOrThrow(Long appId) {
ImApplication imApplication = imApplicationService.getCacheById(appId);
if (imApplication == null) {
throw new BusinessException("查无应用信息");
}
return imApplication;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment