Commit 79c50c8d by Future

异常不抛出

parent f4d9f105
...@@ -53,8 +53,10 @@ public class ImConversationController extends BaseController { ...@@ -53,8 +53,10 @@ public class ImConversationController extends BaseController {
*/ */
@PostMapping("/saveOrUpdateName") @PostMapping("/saveOrUpdateName")
@ApiOperation(value = "添加或修改会话名称", notes = "权限:目前只有创建者有权限操作") @ApiOperation(value = "添加或修改会话名称", notes = "权限:目前只有创建者有权限操作")
public ApiResult<Boolean> saveOrUpdateName(@RequestBody ImConversationNameUpdate imConversationNameUpdate) throws Exception { public ApiResult<Boolean> saveOrUpdateName(@RequestBody ImConversationNameUpdate param) {
return imConversationService.saveOrUpdateName(imConversationNameUpdate); log.info("添加或修改会话名称入参 {}", JSON.toJSONString(param));
imConversationService.saveOrUpdateName(param);
return ApiResult.ok();
} }
...@@ -63,8 +65,9 @@ public class ImConversationController extends BaseController { ...@@ -63,8 +65,9 @@ public class ImConversationController extends BaseController {
*/ */
@PostMapping("/saveOrUpdateAttr") @PostMapping("/saveOrUpdateAttr")
@ApiOperation(value = "添加或修改会话拓展字段", notes = "权限:所有client都权限操作") @ApiOperation(value = "添加或修改会话拓展字段", notes = "权限:所有client都权限操作")
public ApiResult<Boolean> saveOrUpdateAttr(@RequestBody ImConversationAttrUpdate imConversationAttrUpdate) throws Exception { public ApiResult<Boolean> saveOrUpdateAttr(@RequestBody ImConversationAttrUpdate imConversationAttrUpdate) {
return imConversationService.saveOrUpdateAttr(imConversationAttrUpdate); imConversationService.saveOrUpdateAttr(imConversationAttrUpdate);
return ApiResult.ok();
} }
...@@ -73,7 +76,7 @@ public class ImConversationController extends BaseController { ...@@ -73,7 +76,7 @@ public class ImConversationController extends BaseController {
*/ */
@PostMapping("/leave") @PostMapping("/leave")
@ApiOperation(value = "client退出会话", notes = "若是创建者退出,[创建者]权限将会转移给按加入会话时间排序的下一个client") @ApiOperation(value = "client退出会话", notes = "若是创建者退出,[创建者]权限将会转移给按加入会话时间排序的下一个client")
public ApiResult<Boolean> leaveConversation(@RequestBody ImClientLeaveConversation imClientToConversation) throws Exception { public ApiResult<Boolean> leaveConversation(@RequestBody ImClientLeaveConversation imClientToConversation) {
log.info("client退出会话入参 {}", JSON.toJSONString(imClientToConversation)); log.info("client退出会话入参 {}", JSON.toJSONString(imClientToConversation));
return imConversationService.leaveConversation(imClientToConversation); return imConversationService.leaveConversation(imClientToConversation);
} }
......
...@@ -79,7 +79,7 @@ public interface ImConversationService extends BaseService<ImConversation> { ...@@ -79,7 +79,7 @@ public interface ImConversationService extends BaseService<ImConversation> {
/** /**
* client退出会话 * client退出会话
*/ */
ApiResult<Boolean> leaveConversation(ImClientLeaveConversation imClientToConversation) throws Exception; ApiResult<Boolean> leaveConversation(ImClientLeaveConversation imClientToConversation);
/** /**
* 群主转让 * 群主转让
...@@ -121,12 +121,12 @@ public interface ImConversationService extends BaseService<ImConversation> { ...@@ -121,12 +121,12 @@ public interface ImConversationService extends BaseService<ImConversation> {
/** /**
* 添加或修改会话名称 * 添加或修改会话名称
*/ */
ApiResult<Boolean> saveOrUpdateName(ImConversationNameUpdate imConversationNameUpdate) throws Exception; ApiResult<Boolean> saveOrUpdateName(ImConversationNameUpdate imConversationNameUpdate);
/** /**
* 添加或修改会话拓展字段 * 添加或修改会话拓展字段
*/ */
ApiResult<Boolean> saveOrUpdateAttr(ImConversationAttrUpdate imConversationAttrUpdate) throws Exception; void saveOrUpdateAttr(ImConversationAttrUpdate imConversationAttrUpdate);
/** /**
* 修改 * 修改
...@@ -135,7 +135,7 @@ public interface ImConversationService extends BaseService<ImConversation> { ...@@ -135,7 +135,7 @@ public interface ImConversationService extends BaseService<ImConversation> {
* @return * @return
* @throws Exception * @throws Exception
*/ */
boolean updateImConversation(ImConversation imConversation) throws Exception; boolean updateImConversation(ImConversation imConversation);
/** /**
* 修改为 是否单向隐藏会话","云端聊天记录不删除;假设有A和B两个用户,A删会话,B还能发; 如果B发了消息,A这边要重新把会话显示出来,并能显示之前的聊天记录" * 修改为 是否单向隐藏会话","云端聊天记录不删除;假设有A和B两个用户,A删会话,B还能发; 如果B发了消息,A这边要重新把会话显示出来,并能显示之前的聊天记录"
...@@ -169,7 +169,7 @@ public interface ImConversationService extends BaseService<ImConversation> { ...@@ -169,7 +169,7 @@ public interface ImConversationService extends BaseService<ImConversation> {
* @return * @return
* @throws Exception * @throws Exception
*/ */
Paging<ImConversationQueryVo> getImConversationPageList(ImConversationPageParam imConversationPageParam) throws Exception; Paging<ImConversationQueryVo> getImConversationPageList(ImConversationPageParam imConversationPageParam);
/** /**
...@@ -178,14 +178,14 @@ public interface ImConversationService extends BaseService<ImConversation> { ...@@ -178,14 +178,14 @@ public interface ImConversationService extends BaseService<ImConversation> {
* @return * @return
* @throws Exception * @throws Exception
*/ */
List<ConversationVo> getMyImConversationListAndMsgCount() throws Exception; List<ConversationVo> getMyImConversationListAndMsgCount();
/** /**
* 根据会话id查询单个会话信息 与会话的未读条数 * 根据会话id查询单个会话信息 与会话的未读条数
* @param param * @param param
* @return * @return
*/ */
ConversationVo infoImConversationAndMsgCount(ImConversationQueryParam param) throws Exception; ConversationVo infoImConversationAndMsgCount(ImConversationQueryParam param);
/** /**
* 获取加入的所有会话 * 获取加入的所有会话
...@@ -193,7 +193,7 @@ public interface ImConversationService extends BaseService<ImConversation> { ...@@ -193,7 +193,7 @@ public interface ImConversationService extends BaseService<ImConversation> {
* @return * @return
* @throws Exception * @throws Exception
*/ */
List<ImConversation> getMyImConversationList() throws Exception; List<ImConversation> getMyImConversationList();
/** /**
* 判断重复会话中的Attributes是否一样 * 判断重复会话中的Attributes是否一样
......
...@@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; ...@@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.metadata.OrderItem; import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.google.common.collect.Maps;
import com.wecloud.im.entity.ImApplication; import com.wecloud.im.entity.ImApplication;
import com.wecloud.im.entity.ImClient; import com.wecloud.im.entity.ImClient;
import com.wecloud.im.entity.ImConversationMembers; import com.wecloud.im.entity.ImConversationMembers;
...@@ -129,9 +130,9 @@ public class ImConversationMembersServiceImpl extends BaseServiceImpl<ImConversa ...@@ -129,9 +130,9 @@ public class ImConversationMembersServiceImpl extends BaseServiceImpl<ImConversa
// 封装响应的实体 // 封装响应的实体
ImMessageOnlineSend imMessageOnlineSend = new ImMessageOnlineSend(); ImMessageOnlineSend imMessageOnlineSend = new ImMessageOnlineSend();
imMessageOnlineSend.setCreateTime(new Date()); imMessageOnlineSend.setCreateTime(new Date());
imMessageOnlineSend.setType(MsgTypeEnum.CONVERSATION_DISBAND.getUriCode()); imMessageOnlineSend.setType(MsgTypeEnum.CONVERSATION_MEMBER_NAME_MODIFY.getUriCode());
imMessageOnlineSend.setSender(currentClient.getClientId()); imMessageOnlineSend.setSender(currentClient.getClientId());
Map<String, Object> content = new HashMap<>(); Map<String, Object> content = Maps.newHashMap();
content.put("operator", currentClient.getClientId()); content.put("operator", currentClient.getClientId());
content.put("remarkName", param.getClientRemarkName()); content.put("remarkName", param.getClientRemarkName());
imMessageOnlineSend.setContent(content); imMessageOnlineSend.setContent(content);
......
...@@ -591,7 +591,7 @@ public class ImConversationServiceImpl extends BaseServiceImpl<ImConversationMap ...@@ -591,7 +591,7 @@ public class ImConversationServiceImpl extends BaseServiceImpl<ImConversationMap
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public ApiResult<Boolean> leaveConversation(ImClientLeaveConversation imClientToConversation) throws Exception { public ApiResult<Boolean> leaveConversation(ImClientLeaveConversation imClientToConversation) {
ImClient currentClient = imClientService.getCurrentClient(); ImClient currentClient = imClientService.getCurrentClient();
ImConversation imConversation = imConversationService.getById(imClientToConversation.getConversationId()); ImConversation imConversation = imConversationService.getById(imClientToConversation.getConversationId());
...@@ -622,7 +622,7 @@ public class ImConversationServiceImpl extends BaseServiceImpl<ImConversationMap ...@@ -622,7 +622,7 @@ public class ImConversationServiceImpl extends BaseServiceImpl<ImConversationMap
// 将client从会话移除 // 将client从会话移除
boolean b = imConversationMembersService.deleteImConversationMembers(members.getId()); boolean b = imConversationMembersService.deleteImConversationMembers(members.getId());
if (!b) { if (!b) {
throw new Exception("deleteImConversationMembers"); throw new BusinessException("退出群聊错误");
} }
// 将群成员数量减1 // 将群成员数量减1
...@@ -648,7 +648,7 @@ public class ImConversationServiceImpl extends BaseServiceImpl<ImConversationMap ...@@ -648,7 +648,7 @@ public class ImConversationServiceImpl extends BaseServiceImpl<ImConversationMap
imMessage.setFkConversationId(imClientToConversation.getConversationId()); imMessage.setFkConversationId(imClientToConversation.getConversationId());
boolean save = imMessageService.save(imMessage); boolean save = imMessageService.save(imMessage);
if (!save) { if (!save) {
throw new Exception("deleteImConversationMembers"); throw new BusinessException("退出群聊错误");
} }
// 遍历发送 // 遍历发送
...@@ -905,65 +905,43 @@ public class ImConversationServiceImpl extends BaseServiceImpl<ImConversationMap ...@@ -905,65 +905,43 @@ public class ImConversationServiceImpl extends BaseServiceImpl<ImConversationMap
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public ApiResult<Boolean> saveOrUpdateName(ImConversationNameUpdate imConversationNameUpdate) throws Exception { public ApiResult<Boolean> saveOrUpdateName(ImConversationNameUpdate param) {
ImClient currentClient = imClientService.getCurrentClient();
// shiro线程中获取当前token ImConversation imConversationById = imConversationService.getById(param.getConversationId());
JwtToken curentJwtToken = JwtUtil.getCurrentJwtToken(); if (!this.isBelongToRole(currentClient.getClientId(), param.getConversationId(),
// 根据appKey查询application Lists.newArrayList(GroupRoleEnum.OWNER.getCode(), GroupRoleEnum.ADMIN.getCode()))) {
ImApplication imApplication = imApplicationService.getCacheAppByAppKey(curentJwtToken.getAppKey()); throw new BusinessException("操作人既不是群主也不是群管理员,无权限操作");
ImClient imClientSender = imClientService.getCurrentClient();
ImConversation imConversationById = imConversationService.getById(imConversationNameUpdate.getConversationId());
// 判断是否为群主
if (imConversationById == null || !imConversationById.getCreator().equals(imClientSender.getId())) {
return ApiResult.result(false);
} }
// 查询该会话所有成员 // 查询该会话所有成员
List<ImConversationMembers> membersList = imConversationMembersService.list( List<ImConversationMembers> membersList = imConversationMembersService.list(
new QueryWrapper<ImConversationMembers>().lambda() new QueryWrapper<ImConversationMembers>().lambda()
.eq(ImConversationMembers::getFkConversationId, imConversationNameUpdate.getConversationId()) .eq(ImConversationMembers::getFkConversationId, param.getConversationId())
.ne(ImConversationMembers::getFkClientId, imClientSender.getId()) .ne(ImConversationMembers::getFkClientId, currentClient.getId())
); );
imConversationById.setName(param.getName());
imConversationById.setName(imConversationNameUpdate.getName());
boolean b = imConversationService.updateById(imConversationById); boolean b = imConversationService.updateById(imConversationById);
// 删除redis中该会话的缓存 // 删除redis中该会话的缓存
deleteCacheImConversationById(imConversationNameUpdate.getConversationId()); deleteCacheImConversationById(param.getConversationId());
if (b) { if (b) {
// 下发群名称变动事件
// ws下发群属性变动事件
// 内容 // 内容
HashMap<String, String> content = new HashMap<>(); HashMap<String, String> content = Maps.newHashMap();
content.put("name", imConversationById.getName()); content.put("name", imConversationById.getName());
// 遍历发送 // 遍历发送
for (ImConversationMembers conversationMembers : membersList) { for (ImConversationMembers conversationMembers : membersList) {
// 查询接收方 // 查询接收方
ImClient imClientReceiver = imClientService.getOne(new QueryWrapper<ImClient>().lambda() ImClient imClientReceiver = imClientService.getOne(new QueryWrapper<ImClient>().lambda()
.eq(ImClient::getFkAppid, imApplication.getId()) .eq(ImClient::getFkAppid, currentClient.getFkAppid())
.eq(ImClient::getId, conversationMembers.getFkClientId())); .eq(ImClient::getId, conversationMembers.getFkClientId()));
if (imClientReceiver == null) { if (imClientReceiver == null) {
continue; continue;
} }
// 封装响应的实体 // 封装响应的实体
ImMessageOnlineSend imMessageOnlineSend = new ImMessageOnlineSend(); ImMessageOnlineSend imMessageOnlineSend = new ImMessageOnlineSend();
imMessageOnlineSend.setSender(currentClient.getClientId());
// imMessageOnlineSend.setMsgId(null);
// imMessageOnlineSend.setSender(imClientSender.getClientId());
imMessageOnlineSend.setType(MsgTypeEnum.CONVERSATION_NAME_CHANGE.getUriCode()); imMessageOnlineSend.setType(MsgTypeEnum.CONVERSATION_NAME_CHANGE.getUriCode());
imMessageOnlineSend.setCreateTime(new Date()); imMessageOnlineSend.setCreateTime(new Date());
imMessageOnlineSend.setContent(content); imMessageOnlineSend.setContent(content);
imMessageOnlineSend.setConversationId(conversationMembers.getFkConversationId()); imMessageOnlineSend.setConversationId(conversationMembers.getFkConversationId());
// imMessageOnlineSend.setWithdraw(Boolean.FALSE);
imMessageOnlineSend.setEvent(Boolean.TRUE); imMessageOnlineSend.setEvent(Boolean.TRUE);
// 向接收方推送 // 向接收方推送
...@@ -976,19 +954,15 @@ public class ImConversationServiceImpl extends BaseServiceImpl<ImConversationMap ...@@ -976,19 +954,15 @@ public class ImConversationServiceImpl extends BaseServiceImpl<ImConversationMap
responseModel.setReqId(null); responseModel.setReqId(null);
channelSender.sendMsg(responseModel, imClientReceiver.getId()); channelSender.sendMsg(responseModel, imClientReceiver.getId());
} }
return ApiResult.ok(); return ApiResult.ok();
} else { } else {
return ApiResult.fail(); return ApiResult.fail();
} }
} }
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public ApiResult<Boolean> saveOrUpdateAttr(ImConversationAttrUpdate imConversationAttrUpdate) throws Exception { public void saveOrUpdateAttr(ImConversationAttrUpdate imConversationAttrUpdate) {
// shiro线程中获取当前token // shiro线程中获取当前token
JwtToken curentJwtToken = JwtUtil.getCurrentJwtToken(); JwtToken curentJwtToken = JwtUtil.getCurrentJwtToken();
...@@ -1064,18 +1038,15 @@ public class ImConversationServiceImpl extends BaseServiceImpl<ImConversationMap ...@@ -1064,18 +1038,15 @@ public class ImConversationServiceImpl extends BaseServiceImpl<ImConversationMap
} }
return ApiResult.ok();
} else { } else {
return ApiResult.fail(); throw new BusinessException("修改错误");
} }
} }
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
@Override @Override
public boolean updateImConversation(ImConversation imConversation) throws Exception { public boolean updateImConversation(ImConversation imConversation) {
return super.updateById(imConversation); return super.updateById(imConversation);
} }
...@@ -1113,59 +1084,68 @@ public class ImConversationServiceImpl extends BaseServiceImpl<ImConversationMap ...@@ -1113,59 +1084,68 @@ public class ImConversationServiceImpl extends BaseServiceImpl<ImConversationMap
} }
@Override @Override
public Paging<ImConversationQueryVo> getImConversationPageList(ImConversationPageParam imConversationPageParam) throws Exception { public Paging<ImConversationQueryVo> getImConversationPageList(ImConversationPageParam imConversationPageParam) {
Page<ImConversationQueryVo> page = new PageInfo<>(imConversationPageParam, OrderItem.desc(getLambdaColumn(ImConversation::getCreateTime))); Page<ImConversationQueryVo> page = new PageInfo<>(imConversationPageParam, OrderItem.desc(getLambdaColumn(ImConversation::getCreateTime)));
IPage<ImConversationQueryVo> iPage = imConversationMapper.getImConversationPageList(page, imConversationPageParam); IPage<ImConversationQueryVo> iPage = imConversationMapper.getImConversationPageList(page, imConversationPageParam);
return new Paging<ImConversationQueryVo>(iPage); return new Paging<ImConversationQueryVo>(iPage);
} }
@Override @Override
public List<ConversationVo> getMyImConversationListAndMsgCount() throws Exception { public List<ConversationVo> getMyImConversationListAndMsgCount() {
try {
ImClient currentClient = imClientService.getCurrentClient(); ImClient currentClient = imClientService.getCurrentClient();
// 查询用户加入的所有会话 与每个会话的未读条数 成员 // 查询用户加入的所有会话 与每个会话的未读条数 成员
List<ConversationVo> myImConversationListAndMsgCount = imConversationMapper.getMyImConversationListAndMsgCount(currentClient.getId(), null); List<ConversationVo> myImConversationListAndMsgCount = imConversationMapper.getMyImConversationListAndMsgCount(currentClient.getId(), null);
// 返回的 // 返回的
List<ConversationVo> myImConversationListAndMsgCountNew = new ArrayList<>(); List<ConversationVo> myImConversationListAndMsgCountNew = new ArrayList<>();
// 转换json格式 // 转换json格式
for (ConversationVo myconversationlistvo : myImConversationListAndMsgCount) { for (ConversationVo myconversationlistvo : myImConversationListAndMsgCount) {
HashMap attributess = JsonUtils.json2Map(myconversationlistvo.getAttribute()); HashMap attributess = JsonUtils.json2Map(myconversationlistvo.getAttribute());
myconversationlistvo.setAttributes(attributess); myconversationlistvo.setAttributes(attributess);
// 查询会话的最后一条消息 // 查询会话的最后一条消息
OfflineMsgDto lastMsg = imMessageService.getLastMsgByConversationId(myconversationlistvo.getId()); OfflineMsgDto lastMsg = imMessageService.getLastMsgByConversationId(myconversationlistvo.getId());
myconversationlistvo.setLastMsg(lastMsg); myconversationlistvo.setLastMsg(lastMsg);
myImConversationListAndMsgCountNew.add(myconversationlistvo); myImConversationListAndMsgCountNew.add(myconversationlistvo);
}
return myImConversationListAndMsgCountNew;
} catch (Exception e) {
log.info("查询所有会话异常 ", e);
throw new BusinessException("查询错误,稍后重试");
} }
return myImConversationListAndMsgCountNew;
} }
@Override @Override
public ConversationVo infoImConversationAndMsgCount(ImConversationQueryParam param) throws Exception { public ConversationVo infoImConversationAndMsgCount(ImConversationQueryParam param) {
ImClient client = imClientService.getCurrentClient(); try {
// 查询用户加入的所有会话 与每个会话的未读条数 成员 ImClient client = imClientService.getCurrentClient();
List<ConversationVo> conversationList = imConversationMapper.getMyImConversationListAndMsgCount(client.getId(), param.getId()); // 查询用户加入的所有会话 与每个会话的未读条数 成员
if (CollectionUtils.isEmpty(conversationList)) { List<ConversationVo> conversationList = imConversationMapper.getMyImConversationListAndMsgCount(client.getId(), param.getId());
return null; if (CollectionUtils.isEmpty(conversationList)) {
return null;
}
ConversationVo conversationVo = conversationList.get(0);
HashMap attributess = JsonUtils.json2Map(conversationVo.getAttribute());
conversationVo.setAttributes(attributess);
// 查询会话的最后一条消息
OfflineMsgDto lastMsg = imMessageService.getLastMsgByConversationId(conversationVo.getId());
conversationVo.setLastMsg(lastMsg);
return conversationVo;
} catch (Exception e) {
log.info("添加或修改会话名称异常 ", e);
throw new BusinessException("修改会话名称错误");
} }
ConversationVo conversationVo = conversationList.get(0);
HashMap attributess = JsonUtils.json2Map(conversationVo.getAttribute());
conversationVo.setAttributes(attributess);
// 查询会话的最后一条消息
OfflineMsgDto lastMsg = imMessageService.getLastMsgByConversationId(conversationVo.getId());
conversationVo.setLastMsg(lastMsg);
return conversationVo;
} }
@Override @Override
public List<ImConversation> getMyImConversationList() throws Exception { public List<ImConversation> getMyImConversationList() {
ImClient client = imClientService.getCurrentClient(); ImClient client = imClientService.getCurrentClient();
return imConversationMapper.getMyImConversationList(client.getId()); return imConversationMapper.getMyImConversationList(client.getId());
} }
......
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