Search in sources :

Example 1 with UserAnnouncement

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;
}
Also used : UserAnnouncement(com.hccake.ballcat.notify.model.entity.UserAnnouncement)

Example 2 with 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);
}
Also used : SysUser(com.hccake.ballcat.system.model.entity.SysUser) ArrayList(java.util.ArrayList) UserAnnouncement(com.hccake.ballcat.notify.model.entity.UserAnnouncement)

Example 3 with UserAnnouncement

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);
        }
    }
}
Also used : Announcement(com.hccake.ballcat.notify.model.entity.Announcement) RequiredArgsConstructor(lombok.RequiredArgsConstructor) EventListener(org.springframework.context.event.EventListener) HashMap(java.util.HashMap) Collectors(java.util.stream.Collectors) AuthenticationSuccessEvent(org.springframework.security.authentication.event.AuthenticationSuccessEvent) NotifyChannelEnum(com.hccake.ballcat.notify.enums.NotifyChannelEnum) User(com.hccake.ballcat.common.security.userdetails.User) AnnouncementService(com.hccake.ballcat.notify.service.AnnouncementService) UserAnnouncement(com.hccake.ballcat.notify.model.entity.UserAnnouncement) Slf4j(lombok.extern.slf4j.Slf4j) Component(org.springframework.stereotype.Component) List(java.util.List) RecipientHandler(com.hccake.ballcat.notify.recipient.RecipientHandler) SysUser(com.hccake.ballcat.system.model.entity.SysUser) AbstractAuthenticationToken(org.springframework.security.authentication.AbstractAuthenticationToken) Map(java.util.Map) UserAnnouncementService(com.hccake.ballcat.notify.service.UserAnnouncementService) User(com.hccake.ballcat.common.security.userdetails.User) SysUser(com.hccake.ballcat.system.model.entity.SysUser) SysUser(com.hccake.ballcat.system.model.entity.SysUser) Announcement(com.hccake.ballcat.notify.model.entity.Announcement) UserAnnouncement(com.hccake.ballcat.notify.model.entity.UserAnnouncement) HashMap(java.util.HashMap) UserAnnouncement(com.hccake.ballcat.notify.model.entity.UserAnnouncement) AbstractAuthenticationToken(org.springframework.security.authentication.AbstractAuthenticationToken) EventListener(org.springframework.context.event.EventListener)

Aggregations

UserAnnouncement (com.hccake.ballcat.notify.model.entity.UserAnnouncement)3 SysUser (com.hccake.ballcat.system.model.entity.SysUser)2 User (com.hccake.ballcat.common.security.userdetails.User)1 NotifyChannelEnum (com.hccake.ballcat.notify.enums.NotifyChannelEnum)1 Announcement (com.hccake.ballcat.notify.model.entity.Announcement)1 RecipientHandler (com.hccake.ballcat.notify.recipient.RecipientHandler)1 AnnouncementService (com.hccake.ballcat.notify.service.AnnouncementService)1 UserAnnouncementService (com.hccake.ballcat.notify.service.UserAnnouncementService)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Collectors (java.util.stream.Collectors)1 RequiredArgsConstructor (lombok.RequiredArgsConstructor)1 Slf4j (lombok.extern.slf4j.Slf4j)1 EventListener (org.springframework.context.event.EventListener)1 AbstractAuthenticationToken (org.springframework.security.authentication.AbstractAuthenticationToken)1 AuthenticationSuccessEvent (org.springframework.security.authentication.event.AuthenticationSuccessEvent)1 Component (org.springframework.stereotype.Component)1