派生自 projectDept/qhighschool

EricsHu
2022-12-05 068fc7f2e81178e55fa191a13709af64b1a163f6
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
package com.qxueyou.scc.admin.notice.service.impl;
 
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Map;
 
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import com.qxueyou.scc.admin.notice.dao.NoticeDAO;
import com.qxueyou.scc.admin.notice.service.INoticeService;
import com.qxueyou.scc.base.model.Pager;
import com.qxueyou.scc.base.model.Result;
import com.qxueyou.scc.base.service.impl.CommonAppService;
import com.qxueyou.scc.base.util.CollectionUtils;
import com.qxueyou.scc.base.util.TraceUtils;
import com.qxueyou.scc.msg.model.MsgInfo;
import com.qxueyou.scc.msg.service.IMsgInfoService;
import com.qxueyou.scc.notice.model.Notice;
 
@Service
public class NoticeService extends CommonAppService implements INoticeService {
 
    @Autowired
    NoticeDAO dao;
    
    @Autowired
    IMsgInfoService msgInfoService;
 
    @Override
    public Result add(String name, String content, String type, List<String> classIds) {
 
        Notice notice = new Notice();
        TraceUtils.setCreateTrace(notice);
 
        notice.setTitle(name);
        notice.setContent(content);
        notice.setNoticeTypeName(type);
        notice.setStatus(Notice.STATUS_DRAFT);
 
        save(notice);
 
        dao.saveNoticeClasses(notice.getNoticeId(), classIds);
 
        return new  Result(true,"",notice.getNoticeId());
    }
 
    @Override
    public Result update(String noticeId, String name, String content, String type, List<String> classIds) {
 
        Notice notice = read(noticeId);
        TraceUtils.setUpdateTrace(notice);
 
        notice.setTitle(name);
        notice.setContent(content);
        notice.setNoticeTypeName(type);
 
        save(notice);
 
        dao.saveNoticeClasses(notice.getNoticeId(), classIds);
 
        return Result.SUCCESS;
    }
 
    @Override
    public Notice read(String noticeId) {
        return read(Notice.class, noticeId);
    }
 
    @Override
    public List<Notice> readByStatus(Collection<String> noticeIdLst, short status) {
        if (noticeIdLst.isEmpty()) {
            noticeIdLst.add("noticeId");
        }
        String hql = "from Notice where  noticeId in (:noticeId) and status =:status order by createTime desc";
        return findByComplexHql(hql, CollectionUtils.newObjectMap("noticeId", noticeIdLst, "status", status),
                Notice.class);
    }
 
    @Override
    public List<Notice> list(String keyword, Integer pageNum, Integer pageSize, String createId, String sort) {
        String hql = "from Notice where deleteFlag is false and title like ? and createId=? ";
        if (sort.equals("desc")) {
            hql = hql.concat("order by createTime desc");
        } else {
            hql = hql.concat("order by createTime asc");
        }
 
        return findList(hql, new Pager(pageSize, pageNum), CollectionUtils.newList(keyword + "%", createId),
                Notice.class);
    }
 
    @Override
    public int listCount(String keyword, String createId) {
        String hql = "from Notice where deleteFlag is false and title like ? and createId=?";
 
        return findCount(hql, CollectionUtils.newList(keyword + "%", createId));
    }
 
    @SuppressWarnings("unchecked")
    @Override
    public Result delete(String noticeId) {
        Notice notice = read(noticeId);
        TraceUtils.setUpdateTrace(notice);
        notice.setDeleteFlag(true);
        save(notice);
 
        dao.saveNoticeClasses(noticeId, Collections.EMPTY_LIST);
 
        return Result.SUCCESS;
    }
 
    @Override
    public Result delete(String[] noticeIds) {
        for (String noticeId : noticeIds) {
            delete(noticeId);
            dao.deleteNoticeForCache(noticeId);
        }
        return Result.SUCCESS;
    }
 
    @Override
    public Result doIssue(String noticeId) {
        Notice notice = read(noticeId);
 
        TraceUtils.setUpdateTrace(notice);
        notice.setStatus(Notice.STATUS_ISSUED);
        notice.setIssuedTime(new Date());
 
        save(notice);
        return Result.SUCCESS;
    }
 
    @Override
    public Result doIssue(String[] noticeIds) {
        for (String noticeId : noticeIds) {
            doIssue(noticeId);
            doSendhMsg(noticeId);
        }
        return Result.SUCCESS;
    }
    
    
    private void doSendhMsg(String noticeId){
        Notice  notice = this.read(noticeId);
        List<String> lstClassIds= dao.getLiveClasses(noticeId);
        
        if(lstClassIds == null || lstClassIds.size()==0){
            return ;
        }
        //查询直播关联的班级
        String hql = "select userId from StuStudent  where classId in (:classIds) and deleteFlag is false ";
        
        List<String> lstUserIds = this.findByComplexHql(hql, CollectionUtils.newObjectMap("classIds",lstClassIds.toArray(new String[lstClassIds.size()])), String.class);
        
        if(lstUserIds!=null && lstUserIds.size()>0){
            Map<String,String> attrs = CollectionUtils.newStringMap("noticeId",notice.getNoticeId(),"title",notice.getTitle(),
                    "creator",notice.getCreator(),"noticeTypeName",notice.getNoticeTypeName());
                
            msgInfoService.doSendTextMsgToUsers(lstUserIds.toArray(new String[lstUserIds.size()]), 
                                            MsgInfo.TYPE_NOTICE," 发布了公告", attrs);
        }
    }
    
    @Override
    public Result doCancel(String noticeId) {
        return status(noticeId, Notice.STATUS_DRAFT);
    }
 
    @Override
    public Result doCancel(String[] noticeIds) {
        for (String noticeId : noticeIds) {
            doCancel(noticeId);
        }
        return Result.SUCCESS;
    }
 
    @Override
    public List<String> getNoticeClasses(String noticeId) {
        return dao.getLiveClasses(noticeId);
    }
 
    private Result status(String noticeId, short status) {
        Notice notice = read(noticeId);
        TraceUtils.setUpdateTrace(notice);
        notice.setStatus(status);
        save(notice);
        return Result.SUCCESS;
    }
 
    @Override
    public Result view(String noticeId) {
        return Result.SUCCESS;
    }
 
}