chenhj
16 小时以前 455b965c6435b5359bb5c25f2b6810dbc06f5481
src/main/java/com/ruoyi/collaborativeApproval/service/impl/NoticeServiceImpl.java
@@ -1,6 +1,5 @@
package com.ruoyi.collaborativeApproval.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@@ -10,10 +9,13 @@
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
@@ -24,22 +26,41 @@
    @Override
    public IPage<NoticeDTO> listPage(Page page, NoticeDTO noticeDTO) {
        return noticeMapper.listPage(page, 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<>();
        NoticeDTO notice = new NoticeDTO();
        notice.setType(1);
        notice.setCount(noticeMapper.selectCount(new LambdaQueryWrapper<Notice>().eq(Notice::getType, 1)));
        result.add(notice);
        NoticeDTO notice1 = new NoticeDTO();
        notice1.setType(2);
        notice1.setCount(noticeMapper.selectCount(new LambdaQueryWrapper<Notice>().eq(Notice::getType, 2)));
        result.add(notice1);
        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;
    }
}