Commit 79c50c8d by Future

异常不抛出

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