Pu Zhibing
2024-12-24 d09284975427910441eeaf59d34a4d50d2fd5fdc
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
package com.stylefeng.guns.modular.system.service.impl;
 
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.stylefeng.guns.modular.system.dao.SystemNoticeMapper;
import com.stylefeng.guns.modular.system.dao.TNoticesMapper;
import com.stylefeng.guns.modular.system.model.SystemNotice;
import com.stylefeng.guns.modular.system.model.TNotices;
import com.stylefeng.guns.modular.system.service.ISystemNoticeService;
import org.springframework.stereotype.Service;
 
import javax.annotation.Resource;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
 
@Service
public class SystemNoticeServiceImpl extends ServiceImpl<SystemNoticeMapper, SystemNotice> implements ISystemNoticeService {
 
    @Resource
    private SystemNoticeMapper systemNoticeMapper;
 
    @Resource
    private TNoticesMapper tNoticesMapper;
 
 
    /**
     * 添加系统消息
     * @param userType
     * @param content
     * @param userId
     * @throws Exception
     */
    @Override
    public void addSystemNotice(Integer userType, String content, Integer userId, Integer noticeType) throws Exception {
        SystemNotice systemNotice = new SystemNotice();
        systemNotice.setContent(content);
        systemNotice.setInsertTime(new Date());
        systemNotice.setRead(1);
        systemNotice.setType(2);
        systemNotice.setNoticeType(noticeType);
        systemNotice.setUserId(userId);
        systemNotice.setUserType(userType);
        this.insert(systemNotice);
    }
 
    /**
     * 获取未阅读数据
     * @param uid
     * @return
     * @throws Exception
     */
    @Override
    public int queryNoReadNoticeNum(Integer uid) throws Exception {
        return systemNoticeMapper.queryNoReadNoticeNum(uid);
    }
 
    /**
     * 获取消息列表
     * @param type
     * @param pageNum
     * @param size
     * @param uid
     * @return
     */
    @Override
    public List<Map<String, Object>> queryList(Integer type, Integer pageNum, Integer size, Integer uid) {
        pageNum = (pageNum - 1) * size;
        List<Map<String, Object>> list = null;
        if(type == 1){//系统公告
            list = tNoticesMapper.queryList(pageNum, size, uid);
        }
        if(type == 2){//系统消息
            list = systemNoticeMapper.queryList(type, pageNum, size, uid);
            for(Map<String, Object> map : list){
                systemNoticeMapper.readSystemNotice(Integer.valueOf(String.valueOf(map.get("id"))), uid);
            }
        }
        return list;
    }
    
    
    /**
     * 获取系统消息详情
     * @param type
     * @param id
     * @return
     */
    @Override
    public Map<String, Object> queryNoticesInfo(Integer type, Integer id) {
        Map<String, Object> map = new HashMap<>();
        if(type == 1){//系统公告
            SystemNotice systemNotice = systemNoticeMapper.selectById(id);
            TNotices tNotices = tNoticesMapper.selectById(systemNotice.getNoticesId());
            map.put("id", id);
            map.put("title", tNotices.getTitle());
            map.put("img", tNotices.getImgUrl());
            map.put("content", tNotices.getContent());
        }
        if(type == 2){//系统消息
            SystemNotice systemNotice = systemNoticeMapper.selectById(id);
            map.put("id", id);
            map.put("content", systemNotice.getContent());
        }
        return map;
    }
    
    /**
     * 阅读操作
     * @param id
     * @param uid
     * @throws Exception
     */
    @Override
    public void readSystemNotice(Integer id, Integer uid) throws Exception {
        systemNoticeMapper.readSystemNotice(id, uid);
    }
 
 
    /**
     * 删除公告或消息
     * @param id
     * @param uid
     * @throws Exception
     */
    @Override
    public void delSystemNotice(Integer id, Integer uid) throws Exception {
        systemNoticeMapper.delSystemNotice(id, uid);
    }
 
 
    /**
     * 清空消息或公告
     * @param uid
     * @throws Exception
     */
    @Override
    public void clearSystemNotice(Integer uid) throws Exception {
        systemNoticeMapper.delSystemNotice(null, uid);
    }
}