rk
4 天以前 74b0af6814b96378201ea27d205e054bf01d0306
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
package com.doumee.service.business.impl;
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.doumee.core.constants.Constants;
import com.doumee.core.model.PageData;
import com.doumee.core.model.PageWrap;
import com.doumee.dao.business.NoticeMapper;
import com.doumee.dao.business.model.Notice;
import com.doumee.service.business.NoticeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import java.util.List;
import java.util.Objects;
 
/**
 * 消息通知信息Service实现
 * @author rk
 * @date 2026/04/20
 */
@Service
public class NoticeServiceImpl implements NoticeService {
 
    @Autowired
    private NoticeMapper noticeMapper;
 
    @Override
    public Integer create(Notice notice) {
        noticeMapper.insert(notice);
        return notice.getId();
    }
 
    @Override
    public void deleteById(Integer id) {
        noticeMapper.deleteById(id);
    }
 
    @Override
    public void delete(Notice notice) {
        QueryWrapper<Notice> deleteWrapper = new QueryWrapper<>(notice);
        noticeMapper.delete(deleteWrapper);
    }
 
    @Override
    public void deleteByIdInBatch(List<Integer> ids) {
        if (ids == null || ids.isEmpty()) {
            return;
        }
        noticeMapper.deleteBatchIds(ids);
    }
 
    @Override
    public void updateById(Notice notice) {
        noticeMapper.updateById(notice);
    }
 
    @Override
    public void updateByIdInBatch(List<Notice> notices) {
        if (notices == null || notices.isEmpty()) {
            return;
        }
        for (Notice notice : notices) {
            this.updateById(notice);
        }
    }
 
    @Override
    public Notice findById(Integer id) {
        return noticeMapper.selectById(id);
    }
 
    @Override
    public Notice findOne(Notice notice) {
        QueryWrapper<Notice> wrapper = new QueryWrapper<>(notice);
        return noticeMapper.selectOne(wrapper);
    }
 
    @Override
    public List<Notice> findList(Notice notice) {
        QueryWrapper<Notice> wrapper = new QueryWrapper<>(notice);
        return noticeMapper.selectList(wrapper);
    }
 
    @Override
    public PageData<Notice> findPage(PageWrap<Notice> pageWrap) {
        IPage<Notice> page = new Page<>(pageWrap.getPage(), pageWrap.getCapacity());
        QueryWrapper<Notice> queryWrapper = new QueryWrapper<>();
        if (pageWrap.getModel() != null) {
            Notice model = pageWrap.getModel();
            queryWrapper.lambda().eq(Notice::getIsdeleted,Constants.ZERO);
            queryWrapper.lambda().eq(Objects.nonNull(model.getUserId()),Notice::getUserId,model.getUserId());
            queryWrapper.lambda().eq(Objects.nonNull(model.getUserType()),Notice::getUserType,model.getUserType());
        }
        queryWrapper.lambda().orderByAsc(Notice::getStatus).orderByDesc(Notice::getCreateDate);
        return PageData.from(noticeMapper.selectPage(page, queryWrapper));
    }
 
    @Override
    public long count(Notice notice) {
        QueryWrapper<Notice> wrapper = new QueryWrapper<>(notice);
        return noticeMapper.selectCount(wrapper);
    }
 
    @Override
    public void readNotice(Integer id, Integer userId) {
        Notice notice = noticeMapper.selectById(id);
        if (notice != null && notice.getUserId().equals(userId)) {
            notice.setStatus(Constants.ONE);
            notice.setEditDate(new java.util.Date());
            noticeMapper.updateById(notice);
        }
    }
 
    @Override
    public void readAllNotice(Integer userType, Integer userId) {
        noticeMapper.update(new UpdateWrapper<Notice>().lambda()
                .set(Notice::getStatus, Constants.ONE)
                .set(Notice::getEditDate, new java.util.Date())
                .eq(Notice::getUserType, userType)
                .eq(Notice::getUserId, userId)
                .eq(Notice::getStatus, Constants.ZERO)
                .eq(Notice::getIsdeleted, Constants.ZERO));
    }
 
}