chenhj
12 小时以前 dcfaf0d7c20aec3ae32c14ce65a5584689398640
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
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;
    }
}