use of com.hccake.ballcat.notify.model.entity.Announcement in project ballcat by ballcat-projects.
the class AnnouncementServiceImpl method updateAnnouncement.
/**
* 更新公告信息
* @param announcementDTO announcementDTO
* @return boolean
*/
@Override
@Transactional(rollbackFor = Exception.class)
public boolean updateAnnouncement(AnnouncementDTO announcementDTO) {
Announcement oldAnnouncement = baseMapper.selectById(announcementDTO.getId());
if (oldAnnouncement.getStatus() != AnnouncementStatusEnum.UNPUBLISHED.getValue()) {
throw new BusinessException(SystemResultCode.BAD_REQUEST.getCode(), "不允许修改已经发布过的公告!");
}
Announcement announcement = AnnouncementConverter.INSTANCE.dtoToPo(announcementDTO);
// 不允许修改为《发布中》以外的状态
boolean isPublishStatus = announcement.getStatus() == AnnouncementStatusEnum.ENABLED.getValue();
if (!isPublishStatus) {
announcement.setStatus(null);
}
// 保证当前状态未被修改过
boolean isUpdated = baseMapper.updateIfUnpublished(announcement);
// 公告发布事件
if (isUpdated && isPublishStatus) {
this.onAnnouncementPublish(announcement);
}
return isUpdated;
}
use of com.hccake.ballcat.notify.model.entity.Announcement in project ballcat by ballcat-projects.
the class AnnouncementServiceImpl method addAnnouncement.
/**
* 创建公告
* @param announcementDTO 公告信息
* @return boolean
*/
@Override
@Transactional(rollbackFor = Exception.class)
public boolean addAnnouncement(AnnouncementDTO announcementDTO) {
Announcement announcement = AnnouncementConverter.INSTANCE.dtoToPo(announcementDTO);
announcement.setId(null);
int flag = baseMapper.insert(announcement);
boolean inserted = SqlHelper.retBool(flag);
// 公告发布事件
boolean isPublishStatus = announcement.getStatus() == AnnouncementStatusEnum.ENABLED.getValue();
if (inserted && isPublishStatus) {
this.onAnnouncementPublish(announcement);
}
return inserted;
}
use of com.hccake.ballcat.notify.model.entity.Announcement in project ballcat by ballcat-projects.
the class AnnouncementServiceImpl method publish.
/**
* 发布公告信息
* @param announcementId 公告ID
* @return boolean
*/
@Override
@Transactional(rollbackFor = Exception.class)
public boolean publish(Long announcementId) {
Announcement announcement = baseMapper.selectById(announcementId);
if (announcement.getStatus() != AnnouncementStatusEnum.UNPUBLISHED.getValue()) {
throw new BusinessException(SystemResultCode.BAD_REQUEST.getCode(), "不允许修改已经发布过的公告!");
}
if (BooleanEnum.TRUE.getValue() != announcement.getImmortal() && LocalDateTime.now().isAfter(announcement.getDeadline())) {
throw new BusinessException(SystemResultCode.BAD_REQUEST.getCode(), "公告失效时间必须迟于当前时间!");
}
// 更新公共至发布状态
Announcement entity = new Announcement();
entity.setId(announcementId);
entity.setStatus(AnnouncementStatusEnum.ENABLED.getValue());
boolean isUpdated = baseMapper.updateIfUnpublished(entity);
if (isUpdated) {
announcement.setStatus(AnnouncementStatusEnum.ENABLED.getValue());
this.onAnnouncementPublish(announcement);
}
return isUpdated;
}
use of com.hccake.ballcat.notify.model.entity.Announcement 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);
}
}
}
use of com.hccake.ballcat.notify.model.entity.Announcement in project ballcat by ballcat-projects.
the class AnnouncementServiceImpl method close.
/**
* 关闭公告信息
* @param announcementId 公告ID
* @return boolean
*/
@Override
public boolean close(Long announcementId) {
Announcement announcement = new Announcement();
announcement.setId(announcementId);
announcement.setStatus(AnnouncementStatusEnum.DISABLED.getValue());
int flag = baseMapper.updateById(announcement);
boolean isUpdated = SqlHelper.retBool(flag);
if (isUpdated) {
publisher.publishEvent(new AnnouncementCloseEvent(announcementId));
}
return isUpdated;
}
Aggregations