puzhibing
2023-12-04 be8545029b0dfc76a7b74c57098d74672bbdaf95
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
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.service.ISystemNoticeService;
import com.stylefeng.guns.modular.system.util.DateUtil;
import org.springframework.stereotype.Service;
 
import javax.annotation.Resource;
import java.util.Date;
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, Integer language) {
        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){
                map.put("title", language == 1 ? "系统提示" : language == 2 ? "Message" : "Rappel du système");
                systemNoticeMapper.readSystemNotice(Integer.valueOf(String.valueOf(map.get("id"))), uid);
            }
        }
        for (Map<String, Object> map : list) {
            if(null != map.get("time")){
                String time = map.get("time").toString();
                map.put("time", DateUtil.conversionFormat(language, time));
            }
        }
 
        return list;
    }
 
 
    /**
     * 阅读操作
     * @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);
    }
}