Commit d73ff806 by giaogiao

添加imClient的redis缓存;

添加apns的redis缓存;
parent e822867b
......@@ -52,7 +52,7 @@ public class ImClientController extends BaseController {
@PostMapping("/addDeviceInfo")
@ApiOperation(value = "添加或修改推送设备信息(每次请求都会覆盖之前的数据)")
public ApiResult<Boolean> addDeviceInfo(@Validated(Add.class) @RequestBody ImClientDeviceInfoAdd imClientDevice) throws Exception {
boolean flag = imClientService.addDeviceInfo(imClientDevice);
boolean flag = imClientService.updateDeviceInfo(imClientDevice);
return ApiResult.result(flag);
}
......
......@@ -30,7 +30,7 @@ public interface ImClientService extends BaseService<ImClient> {
* @param imClientDevice
* @return
*/
boolean addDeviceInfo(ImClientDeviceInfoAdd imClientDevice);
boolean updateDeviceInfo(ImClientDeviceInfoAdd imClientDevice);
/**
* 修改
......@@ -76,4 +76,8 @@ public interface ImClientService extends BaseService<ImClient> {
*/
ImClient getCurentClient();
ImClient getCacheImClient(Long applicationId, String clientId);
void deleteCacheImClient(Long applicationId, String clientId);
}
......@@ -20,6 +20,9 @@ import io.geekidea.springbootplus.framework.shiro.util.JwtUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
......@@ -31,6 +34,7 @@ import org.springframework.transaction.annotation.Transactional;
*/
@Slf4j
@Service
@CacheConfig(cacheNames = "client")
public class ImClientServiceImpl extends BaseServiceImpl<ImClientMapper, ImClient> implements ImClientService {
@Autowired
......@@ -46,18 +50,22 @@ public class ImClientServiceImpl extends BaseServiceImpl<ImClientMapper, ImClien
@Override
@Transactional(rollbackFor = Exception.class)
public boolean addDeviceInfo(ImClientDeviceInfoAdd imClientDevice) {
public boolean updateDeviceInfo(ImClientDeviceInfoAdd imClientDevice) {
ImClient client = getCurentClient();
ImClient clientNew = new ImClient();
BeanUtils.copyProperties(imClientDevice, clientNew);
clientNew.setId(client.getId());
return this.saveOrUpdate(clientNew);
// 清楚缓存
deleteCacheImClient(client.getFkAppid(), client.getClientId());
// 修改
return this.updateImClient(clientNew);
}
@Transactional(rollbackFor = Exception.class)
@Override
public boolean updateImClient(ImClient imClient) throws Exception {
public boolean updateImClient(ImClient imClient) {
return super.updateById(imClient);
}
......@@ -76,7 +84,7 @@ public class ImClientServiceImpl extends BaseServiceImpl<ImClientMapper, ImClien
public Paging<ImClientQueryVo> getImClientPageList(ImClientPageParam imClientPageParam) throws Exception {
Page<ImClientQueryVo> page = new PageInfo<>(imClientPageParam, OrderItem.desc(getLambdaColumn(ImClient::getCreateTime)));
IPage<ImClientQueryVo> iPage = imClientMapper.getImClientPageList(page, imClientPageParam);
return new Paging<ImClientQueryVo>(iPage);
return new Paging<>(iPage);
}
@Override
......@@ -84,13 +92,22 @@ public class ImClientServiceImpl extends BaseServiceImpl<ImClientMapper, ImClien
// shiro线程中获取当前token
JwtToken curentJwtToken = JwtUtil.getCurentJwtToken();
// 根据appKey查询appid
ImApplication imApplication = imApplicationService.getOneByAppKey(curentJwtToken.getAppKey());
return getCacheImClient(imApplication.getId(), curentJwtToken.getClientId());
}
@Override
@Cacheable(key = "#p0+#p1")
public ImClient getCacheImClient(Long applicationId, String clientId) {
return this.getOne(new QueryWrapper<ImClient>().lambda()
.eq(ImClient::getFkAppid, imApplication.getId())
.eq(ImClient::getClientId, curentJwtToken.getClientId()));
.eq(ImClient::getFkAppid, applicationId)
.eq(ImClient::getClientId, clientId));
}
@Override
@CacheEvict(key = "#p0+#p1")
public void deleteCacheImClient(Long applicationId, String clientId) {
}
}
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