站内信通知异常
This commit is contained in:
parent
aad70245d8
commit
20b7a2dccd
|
@ -21,6 +21,8 @@ import io.renren.modules.sys.service.SysUserService;
|
|||
import io.renren.websocket.WebSocketServer;
|
||||
import io.renren.websocket.data.MessageData;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
@ -29,12 +31,16 @@ import java.util.ArrayList;
|
|||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
/**
|
||||
* 通知管理
|
||||
*/
|
||||
@Service
|
||||
public class SysNoticeServiceImpl extends CrudServiceImpl<SysNoticeDao, SysNoticeEntity, SysNoticeDTO> implements SysNoticeService {
|
||||
private static final ExecutorService executor = Executors.newWorkStealingPool();
|
||||
private static final Logger logger = LoggerFactory.getLogger(SysNoticeServiceImpl.class);
|
||||
@Autowired
|
||||
private SysNoticeUserService sysNoticeUserService;
|
||||
@Autowired
|
||||
|
@ -85,22 +91,26 @@ public class SysNoticeServiceImpl extends CrudServiceImpl<SysNoticeDao, SysNotic
|
|||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void save(SysNoticeDTO dto) {
|
||||
SysNoticeEntity entity = ConvertUtils.sourceToTarget(dto, SysNoticeEntity.class);
|
||||
if (StringUtils.isEmpty(entity.getFrom())) {
|
||||
entity.setFrom("其它"); // 站内信通知来源 (通知、评论、其它)
|
||||
try {
|
||||
SysNoticeEntity entity = ConvertUtils.sourceToTarget(dto, SysNoticeEntity.class);
|
||||
if (StringUtils.isEmpty(entity.getFrom())) {
|
||||
entity.setFrom("其它"); // 站内信通知来源 (通知、评论、其它)
|
||||
}
|
||||
|
||||
//更新发送者信息
|
||||
if (dto.getStatus() == NoticeStatusEnum.SEND.value() && StringUtils.isEmpty(dto.getSenderName())) {
|
||||
entity.setSenderName(SecurityUser.getUser().getRealName());
|
||||
entity.setSenderDate(new Date());
|
||||
}
|
||||
|
||||
baseDao.insert(entity);
|
||||
|
||||
//发送通知
|
||||
dto.setId(entity.getId());
|
||||
sendNotice(dto);
|
||||
} catch (Exception exception) {
|
||||
logger.error("发送站内信异常", exception);
|
||||
}
|
||||
|
||||
//更新发送者信息
|
||||
if (dto.getStatus() == NoticeStatusEnum.SEND.value() && StringUtils.isEmpty(dto.getSenderName())) {
|
||||
entity.setSenderName(SecurityUser.getUser().getRealName());
|
||||
entity.setSenderDate(new Date());
|
||||
}
|
||||
|
||||
baseDao.insert(entity);
|
||||
|
||||
//发送通知
|
||||
dto.setId(entity.getId());
|
||||
sendNotice(dto);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -131,12 +141,16 @@ public class SysNoticeServiceImpl extends CrudServiceImpl<SysNoticeDao, SysNotic
|
|||
|
||||
//全部用户
|
||||
if (notice.getReceiverType() == ReceiverTypeEnum.ALL.value()) {
|
||||
//发送给全部用户
|
||||
sendAllUser(notice);
|
||||
executor.execute(() -> {
|
||||
//发送给全部用户
|
||||
sendAllUser(notice);
|
||||
});
|
||||
|
||||
//通过WebSocket,提示全部用户,有新通知
|
||||
MessageData<String> message = new MessageData<String>().msg(notice.getTitle());
|
||||
webSocketServer.sendMessageAll(message);
|
||||
executor.execute(() -> {
|
||||
//通过WebSocket,提示全部用户,有新通知
|
||||
MessageData<String> message = new MessageData<String>().msg(notice.getTitle());
|
||||
webSocketServer.sendMessageAll(message);
|
||||
});
|
||||
|
||||
} else { //选中用户
|
||||
List<Long> userIdList = new ArrayList<>();
|
||||
|
@ -152,12 +166,17 @@ public class SysNoticeServiceImpl extends CrudServiceImpl<SysNoticeDao, SysNotic
|
|||
return;
|
||||
}
|
||||
|
||||
//发送给选中用户
|
||||
sendUser(notice, userIdList);
|
||||
List<Long> finalUserIdList = userIdList;
|
||||
executor.execute(() -> {
|
||||
//发送给选中用户
|
||||
sendUser(notice, finalUserIdList);
|
||||
});
|
||||
|
||||
//通过WebSocket,提示选中用户,有新通知
|
||||
MessageData<String> message = new MessageData<String>().msg(notice.getTitle());
|
||||
webSocketServer.sendMessage(userIdList, message);
|
||||
executor.execute(() -> {
|
||||
//通过WebSocket,提示选中用户,有新通知
|
||||
MessageData<String> message = new MessageData<String>().msg(notice.getTitle());
|
||||
webSocketServer.sendMessage(finalUserIdList, message);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -63,6 +63,9 @@ spring:
|
|||
baseline-on-migrate: true
|
||||
baseline-version: 0
|
||||
validate-on-migrate: true
|
||||
jackson:
|
||||
parser:
|
||||
allow-unquoted-control-chars: true
|
||||
|
||||
|
||||
fdfs:
|
||||
|
|
Loading…
Reference in New Issue