Commit f1d1382b by Future

性能优化部分

parent beb96394
......@@ -101,10 +101,6 @@ public class NormalChatAction {
// 查询imApplication
ImApplication imApplication = imApplicationService.getCacheById(imClientSender.getFkAppid());
if (imApplication == null) {
log.warn("根据appId: {} 查找不到 imApplication!", imClientSender.getFkAppid());
return;
}
// 给所有人(在线+离线)遍历发送
// 先查询该会话所有成员
......
......@@ -99,8 +99,8 @@ public class MqSender {
messageDTO.setSubTitle(pushVO.getSubTitle());
messageDTO.setData(pushVO.getData());
// 统计未读消息数量
int badge = imInboxService.countMyNotReadCount(imClientReceiver.getId());
messageDTO.setBadge(badge);
// int badge = imInboxService.countMyNotReadCount(imClientReceiver.getId());
// messageDTO.setBadge(badge);
ClientDTO clientDTO = new ClientDTO();
clientDTO.setClientId(imClientReceiver.getClientId());
List<ImClientDevice> clientDeviceList = imClientDeviceService.list(
......
package com.wecloud.im.service;
import com.wecloud.im.entity.ImApplication;
import com.wecloud.im.param.ImApplicationPageParam;
import com.wecloud.im.param.ImApplicationQueryVo;
import io.geekidea.springbootplus.framework.common.service.BaseService;
import io.geekidea.springbootplus.framework.core.pagination.Paging;
import io.geekidea.springbootplus.framework.shiro.signature.Application;
/**
* 第三方应用表 服务类
......@@ -23,22 +21,6 @@ public interface ImApplicationService extends BaseService<ImApplication> {
*/
ImApplication getCacheById(Long id);
/**
* 删除缓存
*
* @param id
*/
void deleteCacheById(Long id);
/**
* 删除缓存
*
* @param appKey
*/
void deleteCacheByAppKey(String appKey);
/**
* 根据appKey查询application
*
......@@ -48,48 +30,9 @@ public interface ImApplicationService extends BaseService<ImApplication> {
ImApplication getCacheAppByAppKey(String appKey);
/**
* 保存
*
* @param imApplication
* @return
* @throws Exception
*/
boolean saveImApplication(ImApplication imApplication) throws Exception;
// /**
// * 修改
// *
// * @param imApplication
// * @return
// * @throws Exception
// */
// boolean updateImApplication(ImApplication imApplication) throws Exception;
//
// /**
// * 删除
// *
// * @param id
// * @return
// * @throws Exception
// */
// boolean deleteImApplication(Long id) throws Exception;
/**
* 根据ID获取查询对象
*
* @param id
* @return
* @throws Exception
*/
ImApplicationQueryVo getImApplicationById(Long id) throws Exception;
/**
* 获取分页对象
*
* @param imApplicationPageParam
* 本地构造
* @return
* @throws Exception
*/
Paging<ImApplicationQueryVo> getImApplicationPageList(ImApplicationPageParam imApplicationPageParam) throws Exception;
ImApplication getByLocal();
}
package com.wecloud.im.service.impl;
import com.wecloud.im.entity.ImApplication;
import com.wecloud.im.mapper.ImApplicationMapper;
import com.wecloud.im.service.ImApplicationService;
import io.geekidea.springbootplus.framework.common.service.impl.BaseServiceImpl;
import io.geekidea.springbootplus.framework.core.pagination.PageInfo;
import io.geekidea.springbootplus.framework.core.pagination.Paging;
import io.geekidea.springbootplus.framework.shiro.signature.Application;
import io.geekidea.springbootplus.framework.shiro.signature.ApplicationService;
import lombok.extern.slf4j.Slf4j;
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;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wecloud.im.entity.ImApplication;
import com.wecloud.im.mapper.ImApplicationMapper;
import com.wecloud.im.param.ImApplicationPageParam;
import com.wecloud.im.param.ImApplicationQueryVo;
import com.wecloud.im.service.ImApplicationService;
/**
* 第三方应用表 服务实现类
*
* @author wei
* @since 2021-04-27
* @Author Future
* @Date 2022/9/27 13:45
* @Description 不在落库取,本地构造
*/
@Slf4j
@Service
@CacheConfig(cacheNames = "appl")
public class ImApplicationServiceImpl extends BaseServiceImpl<ImApplicationMapper, ImApplication> implements ImApplicationService, ApplicationService {
@Autowired
private ImApplicationMapper imApplicationMapper;
@Override
// @Cacheable(key = "'id_'+#p0")
public ImApplication getCacheById(Long id) {
return super.getById(id);
}
@Override
@CacheEvict(key = "'id_'+#p0")
public void deleteCacheById(Long id) {
return this.getByLocal();
}
@Override
@CacheEvict(key = "'appKey_'+#p0")
public void deleteCacheByAppKey(String appKey) {
}
@Override
@Cacheable(key = "'appKey_'+#p0")
public ImApplication getCacheAppByAppKey(String appKey) {
ImApplication imApplication = this.getOne(
new QueryWrapper<ImApplication>().lambda()
.eq(ImApplication::getAppKey, appKey)
);
return getByLocal();
}
@Override
public ImApplication getByLocal() {
ImApplication imApplication = new ImApplication();
imApplication.setId(1L);
imApplication.setAppKey("QizKVHcILRWp6Td2");
imApplication.setAppSecret("287d04828099fb7de871e9dda845fa8b6b2302faf2ab3737");
imApplication.setAppName("遇乐圈");
imApplication.setIosPushChannel(1);
imApplication.setAndroidPushChannel(1);
imApplication.setUmengKey("62b43a6d88ccdf4b7ea76bfd");
imApplication.setUmengSecret("ekcdlz2jivhddwsva7i47pkhywk0tmrm");
imApplication.setIosUmengKey("62b43ad388ccdf4b7ea76c2e");
imApplication.setIosUmengSecret("1rokfrxpidqnm3nywm2wsrcmbfg0f1ln");
imApplication.setRepeatSessionStatus(0);
imApplication.setContrastExtendedFieldStatus(0);
imApplication.setOnlineStatusSubscribeUrl("http://xiaohudou:8080/callback/clientOnlineStatusChange");
imApplication.setFullMessageSubscribeUrl("http://xiaohudou:8080/message/sync");
return imApplication;
}
@Transactional(rollbackFor = Exception.class)
@Override
public boolean saveImApplication(ImApplication imApplication) throws Exception {
return super.save(imApplication);
}
// @Transactional(rollbackFor = Exception.class)
// @Override
// public boolean updateImApplication(ImApplication imApplication) throws Exception {
// return super.updateById(imApplication);
// }
//
// @Transactional(rollbackFor = Exception.class)
// @Override
// public boolean deleteImApplication(Long id) throws Exception {
// return super.removeById(id);
// }
@Override
public ImApplicationQueryVo getImApplicationById(Long id) throws Exception {
return imApplicationMapper.getImApplicationById(id);
}
@Override
public Paging<ImApplicationQueryVo> getImApplicationPageList(ImApplicationPageParam imApplicationPageParam) throws Exception {
Page<ImApplicationQueryVo> page = new PageInfo<>(imApplicationPageParam, OrderItem.desc(getLambdaColumn(ImApplication::getCreateTime)));
IPage<ImApplicationQueryVo> iPage = imApplicationMapper.getImApplicationPageList(page, imApplicationPageParam);
return new Paging<ImApplicationQueryVo>(iPage);
}
@Override
public Application getApplication(String appKey) {
return getCacheAppByAppKey(appKey);
return getByLocal();
}
}
......@@ -132,8 +132,6 @@ public class ImInboxServiceImpl extends BaseServiceImpl<ImInboxMapper, ImInbox>
*/
@Override
public Integer countMyNotReadCount(Long clientId) {
return imInboxMapper.countMyNotReadCount(clientId);
}
......
......@@ -45,8 +45,9 @@
<include refid="Base_Column_List"/>
from im_Inbox
</select>
<select id="countMyNotReadCount" resultType="java.lang.Integer">
SELECT COUNT(id)
SELECT COUNT(*)
FROM im_inbox
WHERE receiver = #{clientId}
AND receiver_msg_status = 0
......
-- 在feature-cluster 2021年12月22日之后,需要执行的的sql增量脚本
-- 在feature-cluster 2021年12月22日之后,需要执行的的sql增量脚本
......@@ -203,3 +203,6 @@ ALTER TABLE im_application
ALTER TABLE im_application
ADD COLUMN `ios_umeng_secret` varchar(500) DEFAULT NULL COMMENT '友盟推送密钥';
ALTER TABLE `im_inbox`
ADD INDEX `idx_create_time`(`create_time`);
package io.geekidea.springbootplus.scheduled;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.wecloud.im.entity.ImInbox;
import com.wecloud.im.service.ImInboxService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.time.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.util.Date;
/**
* @Author Future
* @Date 2022/9/27 14:29
* @Description 离线消息
*/
@Slf4j
@Component
public class InboxScheduled {
@Autowired
private ImInboxService imInboxService;
/**
* 离线消息处理定时器
* 一个月之前的离线消息直接删除
* 一星期前的已读消息 删除
* 一天执行一次 凌晨3点执行
*/
@Scheduled(cron = "* */10 * * * ?")
public void callingTimeout() {
log.info("离线消息处理定时器处理开始...");
// 30天之前数据, 直接删除
Date allDeleteTime = DateUtils.addDays(new Date(), -30);
imInboxService.remove(new QueryWrapper<ImInbox>().lambda()
.lt(ImInbox::getCreateTime, allDeleteTime));
// 7天之前数据, 删除已读消息
Date readTime = DateUtils.addDays(new Date(), -7);
imInboxService.remove(new QueryWrapper<ImInbox>().lambda()
.eq(ImInbox::getReadMsgStatus, 1)
.lt(ImInbox::getCreateTime, readTime));
}
}
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