use of com.hccake.ballcat.notify.model.entity.UserAnnouncement in project ballcat by ballcat-projects.
the class UserAnnouncementServiceImpl method prodUserAnnouncement.
/**
* 根据用户ID和公告id初始化一个新的用户公告关联对象
* @param userId 用户ID
* @param announcementId 公告ID
* @return UserAnnouncement
*/
@Override
public UserAnnouncement prodUserAnnouncement(Integer userId, Long announcementId) {
UserAnnouncement userAnnouncement = new UserAnnouncement();
userAnnouncement.setUserId(userId);
userAnnouncement.setAnnouncementId(announcementId);
userAnnouncement.setCreateTime(LocalDateTime.now());
userAnnouncement.setState(UserAnnouncementStateEnum.UNREAD.getValue());
return userAnnouncement;
}
use of com.hccake.ballcat.notify.model.entity.UserAnnouncement in project ballcat by ballcat-projects.
the class AnnouncementNotifyInfoHandler method persistMessage.
@Override
protected void persistMessage(List<SysUser> userList, AnnouncementNotifyInfo announcementNotifyInfo) {
List<UserAnnouncement> userAnnouncements = new ArrayList<>(userList.size());
// 向指定用户推送
for (SysUser sysUser : userList) {
Integer userId = sysUser.getUserId();
UserAnnouncement userAnnouncement = userAnnouncementService.prodUserAnnouncement(userId, announcementNotifyInfo.getId());
userAnnouncements.add(userAnnouncement);
}
userAnnouncementService.saveBatch(userAnnouncements);
}
use of com.hccake.ballcat.notify.model.entity.UserAnnouncement in project ballcat by ballcat-projects.
the class AnnouncementLoginEventListener method onAuthenticationSuccessEvent.
/**
* 登陆成功时间监听 用户未读公告生成
* @param event 登陆成功 event
*/
@EventListener(AuthenticationSuccessEvent.class)
public void onAuthenticationSuccessEvent(AuthenticationSuccessEvent event) throws InterruptedException {
AbstractAuthenticationToken source = (AbstractAuthenticationToken) event.getSource();
Object details = source.getDetails();
if (!(details instanceof HashMap)) {
return;
}
// https://github.com/spring-projects-experimental/spring-authorization-server
if ("password".equals(((HashMap) details).get("grant_type"))) {
User user = (User) source.getPrincipal();
SysUser sysUser = getSysUser(user);
// 获取当前用户未拉取过的公告信息
Integer userId = sysUser.getUserId();
List<Announcement> announcements = announcementService.listUnPulled(userId);
// 获取当前用户的各个过滤属性
Map<Integer, Object> filterAttrs = recipientHandler.getFilterAttrs(sysUser);
// 获取符合当前用户条件的,且接收类型包含站内的公告,保存其关联关系
List<UserAnnouncement> userAnnouncements = announcements.stream().filter(x -> x.getReceiveMode().contains(NotifyChannelEnum.STATION.getValue())).filter(x -> filterMatched(x, filterAttrs)).map(Announcement::getId).map(id -> userAnnouncementService.prodUserAnnouncement(userId, id)).collect(Collectors.toList());
try {
userAnnouncementService.saveBatch(userAnnouncements);
} catch (Exception exception) {
log.error("用户公告保存失败:[{}]", userAnnouncements, exception);
}
}
}
Aggregations