|
|
@ -1,6 +1,7 @@ |
|
|
|
package com.storeroom.modules.system.service.impl; |
|
|
|
|
|
|
|
|
|
|
|
import com.storeroom.exception.BaseException; |
|
|
|
import com.storeroom.modules.device.domain.DeviceInfo; |
|
|
|
import com.storeroom.modules.device.repository.DeviceInfoRepository; |
|
|
|
import com.storeroom.modules.system.domain.Notice; |
|
|
@ -12,11 +13,12 @@ import com.storeroom.modules.system.repository.NoticeUsersRepository; |
|
|
|
import com.storeroom.modules.system.service.NoticeService; |
|
|
|
import com.storeroom.modules.system.service.dto.NoticeDto; |
|
|
|
import com.storeroom.modules.system.service.dto.NoticeQueryCriteria; |
|
|
|
import com.storeroom.modules.system.service.dto.NoticeUserCriteria; |
|
|
|
import com.storeroom.utils.*; |
|
|
|
import lombok.RequiredArgsConstructor; |
|
|
|
import lombok.SneakyThrows; |
|
|
|
import org.hibernate.validator.constraints.UniqueElements; |
|
|
|
import org.springframework.data.domain.Page; |
|
|
|
import org.springframework.data.domain.PageImpl; |
|
|
|
import org.springframework.data.domain.Pageable; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
@ -41,14 +43,18 @@ public class NoticeServiceImpl implements NoticeService { |
|
|
|
@Override |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public void createNotice(NoticeDto noticeDto) { |
|
|
|
noticeDto.setId(NanoIdUtils.randomNanoId()); |
|
|
|
Notice noticeEntity = new Notice(); |
|
|
|
noticeEntity.setId(noticeDto.getId()); |
|
|
|
if (StringUtils.isEmpty(noticeDto.getId())) { |
|
|
|
noticeDto.setId(NanoIdUtils.randomNanoId()); |
|
|
|
noticeEntity.setId(noticeDto.getId()); |
|
|
|
} else { |
|
|
|
noticeEntity.setId(noticeDto.getId()); |
|
|
|
} |
|
|
|
noticeEntity.setNoticeContent(noticeDto.getNoticeContent()); |
|
|
|
noticeEntity.setNoticeTitle(noticeDto.getNoticeTitle()); |
|
|
|
//noticeEntity.setNoticeTitle(noticeDto.getNoticeTitle()); |
|
|
|
noticeEntity.setStatus(false); |
|
|
|
noticeEntity.setPushType(noticeDto.getPushType()); |
|
|
|
|
|
|
|
noticeEntity.setNoticeType(noticeDto.getNoticeType()); |
|
|
|
Set<Long> deviceInfos = noticeDto.getUserId(); |
|
|
|
|
|
|
|
String pushUser = SecurityUtils.getCurrentUsername(); |
|
|
@ -81,7 +87,7 @@ public class NoticeServiceImpl implements NoticeService { |
|
|
|
Notice noticeEntity = new Notice(); |
|
|
|
noticeEntity.setId(noticeDto.getId()); |
|
|
|
noticeEntity.setNoticeContent(noticeDto.getNoticeContent()); |
|
|
|
noticeEntity.setNoticeTitle(noticeDto.getNoticeTitle()); |
|
|
|
//noticeEntity.setNoticeTitle(noticeDto.getNoticeTitle()); |
|
|
|
noticeEntity.setStatus(false); |
|
|
|
noticeEntity.setPushType(noticeDto.getPushType()); |
|
|
|
Set<String> deviceInfos = noticeDto.getDeviceInfoId(); |
|
|
@ -112,20 +118,38 @@ public class NoticeServiceImpl implements NoticeService { |
|
|
|
return PageUtil.toPage(page); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void updateNotice(Notice notice) { |
|
|
|
|
|
|
|
@Override |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public void deleteByIds(Set<String> ids) { |
|
|
|
noticeRepository.deleteAllById(ids); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public void deleteNotice(Notice notice) { |
|
|
|
noticeRepository.delete(notice); |
|
|
|
public Object queryNoticeUser(NoticeUserCriteria criteria, Pageable pageable) { |
|
|
|
List<NoticeUsers> noticeUsersList = noticeUsersRepository.findByUserId(criteria.getUserId()); |
|
|
|
noticeUsersList.sort(Comparator.comparing(NoticeUsers::getIsRead)); |
|
|
|
List<Notice> noticeList = new ArrayList<>(); |
|
|
|
for (NoticeUsers noticeUsers : noticeUsersList) { |
|
|
|
Notice notice = noticeRepository.findById(noticeUsers.getNoticeId()).orElseGet(Notice::new); |
|
|
|
noticeList.add(notice); |
|
|
|
} |
|
|
|
int start = (int) pageable.getOffset(); |
|
|
|
int end = Math.min((start + pageable.getPageSize()), noticeList.size()); |
|
|
|
Page<Notice> objectPage = new PageImpl<>(noticeList.subList(start, end), pageable, noticeList.size()); |
|
|
|
return PageUtil.toPage(objectPage); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public void deleteByIds(Set<String> ids) { |
|
|
|
noticeRepository.deleteAllById(ids); |
|
|
|
public void updateNoticeUserState(Set<String> ids) { |
|
|
|
for (String id : ids) { |
|
|
|
NoticeUsers noticeUsers = noticeUsersRepository.findById(id).orElseGet(NoticeUsers::new); |
|
|
|
if (!noticeUsers.getIsRead()) { |
|
|
|
noticeUsers.setIsRead(true); |
|
|
|
} |
|
|
|
noticeUsersRepository.save(noticeUsers); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |