Commit 4eb6f04f by giaogiao

灵活配置该应用 创建会话时对比扩展字段;

ImApplication查询添加redis
parent 2a2c9c5a
......@@ -23,6 +23,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.ConfigurationPropertiesScan;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
......@@ -39,6 +40,7 @@ import org.springframework.transaction.annotation.EnableTransactionManagement;
@EnableTransactionManagement
@EnableConfigurationProperties
@ServletComponentScan
@EnableCaching
@ConfigurationPropertiesScan("com.wecloud.im.config")
@MapperScan({"io.geekidea.springbootplus.**.mapper", "com.wecloud.**.mapper"})
@SpringBootApplication(scanBasePackages = {"io.geekidea.springbootplus", "com.wecloud", "com.wecloud.im", "com.wecloud.im.config"})
......
......@@ -27,7 +27,9 @@ public class FirebaseTest {
System.setProperty("socksProxyPort", "7891");
// String to = "ck_oO93kR42WlkmzBVjzcA:APA91bGTcXlFq9_AOvGOJSIB4Z38EOqhP3_6HQ18_XIn3othxSWTeRr_IaQn-75AB9FvD5CiTig03Y56VtZDEEihismai0OOMPyxB7R4ajaFrQszEQRbCBw3iUgaAyjK7e1RFeq22tRC";
String to = "eLOQs869208Wq5_tQINUgl:APA91bEsiSt8_RBJYQ2bLDHJF4nuE6XS6bP-kdEAt463SpW2i0Q5wUcmma3ylszr698MUIkjkwV507EV7ao347pl0XwHTDgDM1kIL4WYfX28OznML2lefnYS7oMmlt5_uqvwDO1GWone";
// String to = "eLOQs869208Wq5_tQINUgl:APA91bEsiSt8_RBJYQ2bLDHJF4nuE6XS6bP-kdEAt463SpW2i0Q5wUcmma3ylszr698MUIkjkwV507EV7ao347pl0XwHTDgDM1kIL4WYfX28OznML2lefnYS7oMmlt5_uqvwDO1GWone";
String to = "cu7jc8tgd0Irh7VoMXGNz4:APA91bFnOP39EKSXUaTDqERlqyfLIovLPrGXA_U1pKLs5mJRPfbLPl6BvSlLUwsBAtprE0NoEeIiRwkTwN4RskUgh39IKSqcSJ14yXtEDIGMs8HqzaF4HrQqJ_zFFUX6S0r6WenUru_8";
String key = "AAAA7PNYwIg:APA91bG2PZlTpC9sxqeIxtKDJJGzGZlh1ca13_bR4c5qkv9pEvRxcDfgO8VQqV2g-7cCTZz3oDtpWAgcQ5TyMKGdlD7Zp3bEmFkpNYDJAIcshSbyW-BtjCbknT2R5px5THmEJrlTJuDi";
String jsonStr = null;
......
package com.wecloud.im.controller;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.wecloud.im.entity.ImApplication;
import com.wecloud.im.param.add.ImClientDeviceInfoAdd;
import com.wecloud.im.service.ImApplicationService;
......@@ -70,11 +69,7 @@ public class ImClientController extends BaseController {
JwtToken curentJwtToken = JwtUtil.getCurentJwtToken();
// 根据appKey查询appid
ImApplication imApplication = imApplicationService.getOne(
new QueryWrapper<ImApplication>().lambda()
.select(ImApplication::getId, ImApplication::getAppKey)
.eq(ImApplication::getAppKey, curentJwtToken.getAppKey())
);
ImApplication imApplication = imApplicationService.getOneByAppKey(curentJwtToken.getAppKey());
boolean onlineStatus = mangerChannelService.getOnlineStatus(imApplication.getAppKey(), clientId);
ImOnlineStatusVo imOnlineStatusVo = new ImOnlineStatusVo();
......
......@@ -62,4 +62,7 @@ public class ImApplication extends BaseEntity {
@ApiModelProperty("是否允许创建重复会话 0不允许 1允许")
private Integer repeatSessionStatus;
@ApiModelProperty("创建会话时对比扩展字段 0不 1是")
private Integer contrastExtendedFieldStatus;
}
......@@ -51,7 +51,7 @@ public class ImConversation extends BaseEntity {
private String name;
@ApiModelProperty("可选 自定义属性,供开发者扩展使用。")
private Object attributes;
private String attributes;
@ApiModelProperty("可选 对话类型标志,是否是系统对话,后面会说明。")
private Boolean system;
......
......@@ -14,6 +14,15 @@ import io.geekidea.springbootplus.framework.core.pagination.Paging;
*/
public interface ImApplicationService extends BaseService<ImApplication> {
/**
* 根据appKey查询application
*
* @param appKey
* @return
*/
ImApplication getOneByAppKey(String appKey);
/**
* 保存
*
......
......@@ -2,13 +2,10 @@ package com.wecloud.im.service;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.wecloud.im.entity.ImInbox;
import com.wecloud.im.param.ImInboxPageParam;
import com.wecloud.im.param.ImInboxQueryVo;
import com.wecloud.im.param.ImMsgReadStatusUpdate;
import com.wecloud.im.param.ImMsgReceivedStatusUpdate;
import io.geekidea.springbootplus.framework.common.api.ApiResult;
import io.geekidea.springbootplus.framework.common.service.BaseService;
import io.geekidea.springbootplus.framework.core.pagination.Paging;
/**
* 消息收件箱表 服务类
......@@ -18,50 +15,50 @@ import io.geekidea.springbootplus.framework.core.pagination.Paging;
*/
public interface ImInboxService extends BaseService<ImInbox> {
/**
* 保存
*
* @param imInbox
* @return
* @throws Exception
*/
boolean saveImInbox(ImInbox imInbox) throws Exception;
/**
* 修改
*
* @param imInbox
* @return
* @throws Exception
*/
boolean updateImInbox(ImInbox imInbox) throws Exception;
/**
* 删除
*
* @param id
* @return
* @throws Exception
*/
boolean deleteImInbox(Long id) throws Exception;
/**
* 根据ID获取查询对象
*
* @param id
* @return
* @throws Exception
*/
ImInboxQueryVo getImInboxById(Long id) throws Exception;
/**
* 获取分页对象
*
* @param imInboxPageParam
* @return
* @throws Exception
*/
Paging<ImInboxQueryVo> getImInboxPageList(ImInboxPageParam imInboxPageParam) throws Exception;
// /**
// * 保存
// *
// * @param imInbox
// * @return
// * @throws Exception
// */
// boolean saveImInbox(ImInbox imInbox) throws Exception;
//
// /**
// * 修改
// *
// * @param imInbox
// * @return
// * @throws Exception
// */
// boolean updateImInbox(ImInbox imInbox) throws Exception;
//
// /**
// * 删除
// *
// * @param id
// * @return
// * @throws Exception
// */
// boolean deleteImInbox(Long id) throws Exception;
//
// /**
// * 根据ID获取查询对象
// *
// * @param id
// * @return
// * @throws Exception
// */
// ImInboxQueryVo getImInboxById(Long id) throws Exception;
//
// /**
// * 获取分页对象
// *
// * @param imInboxPageParam
// * @return
// * @throws Exception
// */
// Paging<ImInboxQueryVo> getImInboxPageList(ImInboxPageParam imInboxPageParam) throws Exception;
/**
......
package com.wecloud.im.service.impl;
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;
......@@ -13,6 +14,8 @@ import io.geekidea.springbootplus.framework.core.pagination.PageInfo;
import io.geekidea.springbootplus.framework.core.pagination.Paging;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
......@@ -24,11 +27,22 @@ import org.springframework.transaction.annotation.Transactional;
*/
@Slf4j
@Service
@CacheConfig(cacheNames = "applic")
public class ImApplicationServiceImpl extends BaseServiceImpl<ImApplicationMapper, ImApplication> implements ImApplicationService {
@Autowired
private ImApplicationMapper imApplicationMapper;
@Override
@Cacheable(key = "#p0")
public ImApplication getOneByAppKey(String appKey) {
ImApplication imApplication = this.getOne(
new QueryWrapper<ImApplication>().lambda()
.eq(ImApplication::getAppKey, appKey)
);
return imApplication;
}
@Transactional(rollbackFor = Exception.class)
@Override
public boolean saveImApplication(ImApplication imApplication) throws Exception {
......
......@@ -59,9 +59,7 @@ public class ImClientLoginServiceImpl implements ImClientLoginService {
public ApiResult<TokenVo> verifySign(ImTokenVerify imTokenVerify) {
// 根据appKey从数据库查询密钥
ImApplication imApplication = imApplicationService.getOne(
new QueryWrapper<ImApplication>().lambda().eq(ImApplication::getAppKey, imTokenVerify.getAppKey())
);
ImApplication imApplication = imApplicationService.getOneByAppKey(imTokenVerify.getAppKey());
if (imApplication == null) {
log.error("imApplication == null,getAppKey:" + imTokenVerify.getAppKey());
......
......@@ -86,11 +86,7 @@ public class ImClientServiceImpl extends BaseServiceImpl<ImClientMapper, ImClien
JwtToken curentJwtToken = JwtUtil.getCurentJwtToken();
// 根据appKey查询appid
ImApplication imApplication = imApplicationService.getOne(
new QueryWrapper<ImApplication>().lambda()
.select(ImApplication::getId)
.eq(ImApplication::getAppKey, curentJwtToken.getAppKey())
);
ImApplication imApplication = imApplicationService.getOneByAppKey(curentJwtToken.getAppKey());
return this.getOne(new QueryWrapper<ImClient>().lambda()
.eq(ImClient::getFkAppid, imApplication.getId())
......
......@@ -96,11 +96,8 @@ public class ImConversationServiceImpl extends BaseServiceImpl<ImConversationMap
// shiro线程中获取当前token
JwtToken curentJwtToken = JwtUtil.getCurentJwtToken();
// 根据appKey查询appid
ImApplication imApplication = imApplicationService.getOne(
new QueryWrapper<ImApplication>().lambda()
.eq(ImApplication::getAppKey, curentJwtToken.getAppKey())
);
// 根据appKey查询application
ImApplication imApplication = imApplicationService.getOneByAppKey(curentJwtToken.getAppKey());
// 该应用 是否允许重复创建会话
if (imApplication.getRepeatSessionStatus() == 0) {
......@@ -125,8 +122,42 @@ public class ImConversationServiceImpl extends BaseServiceImpl<ImConversationMap
return ApiResult.ok(imConversationCreateVo);
}
}
} else {
//创建会话时对比扩展字段 0不 1是
if (imApplication.getContrastExtendedFieldStatus() == 1) {
ImClient client2 = imClientService.getOne(new QueryWrapper<ImClient>().lambda()
.eq(ImClient::getFkAppid, client.getFkAppid())
.eq(ImClient::getClientId, imConversationCreate.getClientIds().get(0)));
// 是否存在重复会话
Integer repetitionConversation = getRepetitionConversation(client.getId(), client2.getId());
if (repetitionConversation != 0) {
ImConversation repetitionConversationInfo = imConversationMapper.getRepetitionConversationInfo(client.getId(), client2.getId());
JsonMapper jsonMapper = new JsonMapper();
HashMap hashMap = null;
try {
hashMap = jsonMapper.readValue(repetitionConversationInfo.getAttributes(), HashMap.class);
} catch (JsonProcessingException e) {
e.printStackTrace();
}
if (imConversationCreate.getAttributes().equals(hashMap)) {
log.info(imConversationCreate.getAttributes() + "重复");
ImConversationCreateVo imConversationCreateVo = new ImConversationCreateVo();
imConversationCreateVo.setId(repetitionConversationInfo.getId());
// 为重复
return ApiResult.ok(imConversationCreateVo);
}
}
}
}
// 会话id
Long imConversationId = SnowflakeUtil.getId();
......
package com.wecloud.im.service.impl;
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.entity.ImClient;
import com.wecloud.im.entity.ImConversationMembers;
......@@ -10,8 +7,6 @@ import com.wecloud.im.entity.ImInbox;
import com.wecloud.im.entity.ImMessage;
import com.wecloud.im.entity.ImMessageOnlineSend;
import com.wecloud.im.mapper.ImInboxMapper;
import com.wecloud.im.param.ImInboxPageParam;
import com.wecloud.im.param.ImInboxQueryVo;
import com.wecloud.im.param.ImMsgReadStatusUpdate;
import com.wecloud.im.param.ImMsgReceivedStatusUpdate;
import com.wecloud.im.service.ImApplicationService;
......@@ -24,8 +19,6 @@ import com.wecloud.im.ws.service.WriteDataService;
import io.geekidea.springbootplus.framework.common.api.ApiCode;
import io.geekidea.springbootplus.framework.common.api.ApiResult;
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 lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -63,35 +56,35 @@ public class ImInboxServiceImpl extends BaseServiceImpl<ImInboxMapper, ImInbox>
private ImApplicationService imApplicationService;
@Transactional(rollbackFor = Exception.class)
@Override
public boolean saveImInbox(ImInbox imInbox) throws Exception {
return super.save(imInbox);
}
@Transactional(rollbackFor = Exception.class)
@Override
public boolean updateImInbox(ImInbox imInbox) throws Exception {
return super.updateById(imInbox);
}
@Transactional(rollbackFor = Exception.class)
@Override
public boolean deleteImInbox(Long id) throws Exception {
return super.removeById(id);
}
@Override
public ImInboxQueryVo getImInboxById(Long id) throws Exception {
return imInboxMapper.getImInboxById(id);
}
@Override
public Paging<ImInboxQueryVo> getImInboxPageList(ImInboxPageParam imInboxPageParam) throws Exception {
Page<ImInboxQueryVo> page = new PageInfo<>(imInboxPageParam, OrderItem.desc(getLambdaColumn(ImInbox::getCreateTime)));
IPage<ImInboxQueryVo> iPage = imInboxMapper.getImInboxPageList(page, imInboxPageParam);
return new Paging<ImInboxQueryVo>(iPage);
}
// @Transactional(rollbackFor = Exception.class)
// @Override
// public boolean saveImInbox(ImInbox imInbox) throws Exception {
// return super.save(imInbox);
// }
//
// @Transactional(rollbackFor = Exception.class)
// @Override
// public boolean updateImInbox(ImInbox imInbox) throws Exception {
// return super.updateById(imInbox);
// }
//
// @Transactional(rollbackFor = Exception.class)
// @Override
// public boolean deleteImInbox(Long id) throws Exception {
// return super.removeById(id);
// }
//
// @Override
// public ImInboxQueryVo getImInboxById(Long id) throws Exception {
// return imInboxMapper.getImInboxById(id);
// }
//
// @Override
// public Paging<ImInboxQueryVo> getImInboxPageList(ImInboxPageParam imInboxPageParam) throws Exception {
// Page<ImInboxQueryVo> page = new PageInfo<>(imInboxPageParam, OrderItem.desc(getLambdaColumn(ImInbox::getCreateTime)));
// IPage<ImInboxQueryVo> iPage = imInboxMapper.getImInboxPageList(page, imInboxPageParam);
// return new Paging<ImInboxQueryVo>(iPage);
// }
@Override
@Transactional(rollbackFor = Exception.class)
......
......@@ -37,7 +37,7 @@ import java.util.HashMap;
import java.util.List;
/**
* @Description 处理app单聊消息
* @Description 处理app数据消息
*/
@ReceiveTypeAnnotation(type = WsRequestCmdEnum.DATA)
@Service
......@@ -75,8 +75,7 @@ public class ImConcreteReceiveStrategy extends AbstractReceiveStrategy {
String clientUniId = ctx.channel().attr(MangerChannelService.CLIENT_ID).get();
// 查询imApplication
ImApplication imApplication = imApplicationService.getOne(new QueryWrapper<ImApplication>().lambda()
.eq(ImApplication::getAppKey, appKey));
ImApplication imApplication = imApplicationService.getOneByAppKey(appKey);
if (imApplication == null) {
log.error("imApplication为空");
return;
......
......@@ -5,7 +5,7 @@
<!-- 通用查询结果列 -->
<sql id="Base_Column_List">
id
, create_time, update_time, app_key, app_secret, app_name, ios_push_channel, android_push_channel,umeng_key,umeng_secret,firebase_secret,repeat_session_status
, create_time, update_time, app_key, app_secret, app_name, ios_push_channel, android_push_channel,umeng_key,umeng_secret,firebase_secret,repeat_session_status,contrast_extended_field_status
</sql>
......
......@@ -82,7 +82,7 @@
INNER JOIN im_conversation ON im_conversation.id = im_conversation_members.fk_conversation_id
WHERE im_conversation_members.fk_client_id = #{clientId1}
WHERE im_conversation_members.fk_client_id = #{clientId1} LIMIT 1
</select>
</mapper>
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