package com.ruoyi.collaborativeApproval.service.impl;
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.ruoyi.collaborativeApproval.dto.NoticeDTO;
|
import com.ruoyi.collaborativeApproval.mapper.NoticeMapper;
|
import com.ruoyi.collaborativeApproval.pojo.Notice;
|
import com.ruoyi.collaborativeApproval.service.NoticeService;
|
import lombok.AllArgsConstructor;
|
import lombok.extern.slf4j.Slf4j;
|
import org.springframework.beans.BeanUtils;
|
import org.springframework.stereotype.Service;
|
|
import java.util.ArrayList;
|
import java.util.List;
|
import java.util.Map;
|
import java.util.stream.Collectors;
|
|
@Service
|
@Slf4j
|
@AllArgsConstructor
|
public class NoticeServiceImpl extends ServiceImpl<NoticeMapper, Notice> implements NoticeService {
|
|
private final NoticeMapper noticeMapper;
|
|
@Override
|
public IPage<NoticeDTO> listPage(Page page, NoticeDTO noticeDTO) {
|
IPage<NoticeDTO> noticeDTOIPage = noticeMapper.listPage(page, noticeDTO);
|
noticeDTOIPage.getRecords().forEach(item -> {
|
// 根据过期时间判断statusName
|
if (item.getExpirationDate() == null) {
|
item.setStatusName("未知");
|
}else if(item.getExpirationDate().getTime() < System.currentTimeMillis()){
|
item.setStatusName("已过期");
|
} else{
|
item.setStatusName("正常");
|
}
|
});
|
return noticeDTOIPage;
|
}
|
|
@Override
|
public List<NoticeDTO> selectCount() {
|
List<Notice> noticesList = noticeMapper.selectList(null);
|
Map<String, Notice> uniqueByType = noticesList.stream()
|
.collect(Collectors.toMap(
|
Notice::getType,
|
n -> n,
|
(existing, replacement) -> existing
|
));
|
|
List<Notice> notices = new ArrayList<>(uniqueByType.values());
|
Map<String, Long> countMap = noticesList.stream().collect(Collectors.groupingBy(Notice::getType, Collectors.counting()));
|
List<NoticeDTO> result = new ArrayList<>();
|
for (Notice notice : notices) {
|
NoticeDTO notice1 = new NoticeDTO();
|
BeanUtils.copyProperties(notice, notice1);
|
if (countMap.containsKey(notice.getType())) {
|
notice1.setCount(countMap.get(notice.getType()) == null ? 0 : countMap.get(notice.getType()));
|
}
|
result.add(notice1);
|
}
|
return result;
|
}
|
}
|