派生自 projectDept/qhighschool

胡仁荣
2023-03-29 a666398b496513f1fe56a44195247c254a861656
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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
package com.qxueyou.scc.controller;
 
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
 
import com.qxueyou.scc.admin.classes.dao.ClassDAO;
import com.qxueyou.scc.admin.classes.model.ClsClass;
import com.qxueyou.scc.admin.classes.service.IClassService;
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.util.ClientUtils;
import com.qxueyou.scc.base.util.CollectionUtils;
import com.qxueyou.scc.base.util.QBeanUtils;
import com.qxueyou.scc.notice.model.Notice;
 
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
 
@Api(tags = "公告接口-教师端")
@RestController
@RequestMapping(value = "/admin/notice")
public class NoticeController {
 
    @Autowired
    IClassService classService;
 
    @Autowired
    INoticeService noticeService;
 
    @Autowired
    NoticeDAO dao;
 
    @Autowired
    ClassDAO classDao;
 
    /**
     * 显示 公告列表
     *
     * @param keyword
     * @param pageNum
     * @param pageSize
     * @return
     */
    @ApiOperation(value = "公告列表", notes = "获取班级列表及班级所在公告列表")
    @GetMapping(value = "list")
    public Result list(String keyword, Integer pageNum, Integer pageSize) {
        if (!ClientUtils.isAdmin()) {
            // 获取班级列表及班级所在公告列表
            List<String> noticeIds = new ArrayList<String>(10);
            List<ClsClass> clsLst = classService.getClassLstByTeacherId();
            for (ClsClass cls : clsLst) {
                noticeIds.addAll(dao.getClassNotices(cls.getClassId()));
            }
            List<Notice> notices = noticeService.readByStatus(noticeIds, Notice.STATUS_ISSUED);
 
            List<Map<String, Object>> lst = QBeanUtils.listBean2ListMap(notices, CollectionUtils.newStringMap(
                    "noticeId", "noticeId", "title", "name", "noticeTypeName", "type", "issuedTime", "releaseTime"));
 
            if(lst == null) {
                return new Result(true, "success",
                        CollectionUtils.newObjectMap("noticeCount", 0, "noticeLst", new ArrayList<>()));
            }
            
            for (Map<String, Object> map : lst) {
                map.put("isView", dao.isView((String) map.get("noticeId"), ClientUtils.getUserId()));
                map.put("classCount", dao.getLiveClasses((String) map.get("noticeId")).size());
                map.put("noticeTypeName", this.getTypeName((String)map.get("type")));
            }
 
            return new Result(true, "success",
                    CollectionUtils.newObjectMap("noticeCount", lst.size(), "noticeLst", lst));
 
        } else {
            return new Result(true, "success", CollectionUtils.newObjectMap("noticeLst", Collections.EMPTY_LIST));
        }
    }
 
    /**
       *   显示 公告管理列表
     * @param keyword
     * @param pageNum
     * @param pageSize
     * @return
     */
    @ApiOperation(value = "公告管理列表", notes = "")
    @GetMapping(value = "managerLst")
    public Result managerLst(String keyword, Pager pager, @RequestParam(defaultValue = "desc") String sort) {
        String keyword_ = StringUtils.isBlank(keyword) ? "" : keyword;
        List<Notice> notices = noticeService.list(keyword_, pager.getPageNum(), pager.getPageSize(), ClientUtils.getUserId(), sort);
 
        int count = noticeService.listCount(keyword_, ClientUtils.getUserId());
 
        List<Map<String, Object>> lst = QBeanUtils.listBean2ListMap(notices, CollectionUtils.newStringMap(
                "noticeId", "noticeId",
                "title", "name",
                "status", "status",
                "noticeTypeName", "type",
                "issuedTime", "releaseTime"
        ));
 
        for (Map<String, Object> map : lst) {
            List<String> classIds = dao.getLiveClasses((String) map.get("noticeId"));
            map.put("classCount", classIds.size());
            map.put("studentCount", classIds.size() > 0?classDao.getStudentCount(classIds):0);
            map.put("readCount", dao.getReadCount((String) map.get("noticeId")));
            map.put("noticeTypeName", this.getTypeName((String)map.get("type")));
        }
 
        return new Result(true, "success", CollectionUtils.newObjectMap("noticeCount", count, "noticeLst", lst
        ));
    }
    
    private String getTypeName(String key) {
        Map<String, String> typeMap = new HashMap<>();
        typeMap.put("homework", "作业公告");
        typeMap.put("exam", "考试公告");
        typeMap.put("other", "其他公告");
        typeMap.put("class", "上课公告");
        
        return typeMap.get(key);
    }
 
    /**
     * 发布公告/多个id已逗号隔开
     *
     * @param noticeIds 公告ids
     * @return
     */
    @ApiOperation(value = "发布公告", notes = "多个id已逗号隔开")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "noticeIds", value = "多个id已逗号隔开", required = true, paramType="query", dataType = "String")
    })
    @PostMapping(value = "release")
    public Result release(String noticeIds) {
        return noticeService.doIssue(noticeIds.split(","));
    }
 
    /**
     * 取消发布/多个id已逗号隔开
     *
     * @param noticeIds 公告ids
     * @return
     */
    @ApiOperation(value = "取消发布", notes = "多个id已逗号隔开")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "noticeIds", value = "多个id已逗号隔开", required = true, paramType="query", dataType = "String"),
    })
    @PostMapping(value = "cancel")
    public Result cancel(String noticeIds) {
        return noticeService.doCancel(noticeIds.split(","));
    }
 
    /**
     * 删除 公告/多个id已逗号隔开
     *
     * @param noticeIds 公告ids
     * @return
     */
    @ApiOperation(value = "删除公告", notes = "多个id已逗号隔开")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "noticeIds", value = "多个id已逗号隔开", required = true, paramType="query", dataType = "String"),
    })
    @PostMapping(value = "delete")
    public Result delete(String noticeIds) {
        return noticeService.delete(noticeIds.split(","));
    }
 
    /**
     * 新增/更新
     *
     * @param noticeId
     * @param name
     * @param content
     * @param type
     * @param classIds
     * @param pathUrl
     * @return
     */
    @ApiOperation(value = "新增/更新公告", notes = "noticeId存在则更新,否则新增")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name", value = "公告标题", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "content", value = "公告内容", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "type", value = "公告类型名称", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "classIds", value = "关联的班级id,逗号组装", required = true, paramType = "query", dataType = "String") })
    @PostMapping(value = "addOrUpdate")
    public Result addOrUpdate(String noticeId, String name, String content, String type, String classIds,
            String pathUrl) {
        if (StringUtils.isEmpty(noticeId)) {
            return noticeService.add(name, content, type, CollectionUtils.newList(String.class, classIds.split(",")));
        } else {
            return noticeService.update(noticeId, name, content, type,
                    CollectionUtils.newList(String.class, classIds.split(",")));
        }
    }
 
    /**
     * 获取公告详情
     *
     * @param noticeId
     * @return
     */
    @ApiOperation(value = "获取公告详情", notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "noticeId", value = "公告id", required = true, paramType = "query", dataType = "String")
    })
    @GetMapping(value = "detail")
    public Result detail(String noticeId) {
        Notice notice = noticeService.read(noticeId);
        List<String> classIds = dao.getLiveClasses(noticeId);
        
        String [] classNames = null;
        if(classIds!=null && classIds.size()>0){
            classNames= classService.queryClassNamesByIds(classIds.toArray(new String [classIds.size()]));
        }
        
        return new Result(true, "success",
                CollectionUtils.newObjectMap(
                        "noticeName", notice.getTitle(),
                        "type", notice.getNoticeTypeName(),
                        "createTime", notice.getCreateTime(),
                        "remark", notice.getContent(),
                        "fullPath", notice.getImgPath(),
                        "creator", notice.getCreator(),
                        "classIds", classIds,
                        "classNames", classNames
        ));
    }
 
    @ApiOperation(value = "获取班级列表", notes = "")
    @GetMapping(value = "findClassLst")
    public Result findClassLst() {
        if (ClientUtils.isAdmin()) {
            List<Map<String, Object>> clsLst = classService.getAllClassLst().getDataT("classLst");
            return new Result(true, "操作成功", QBeanUtils.listBean2ListMap(clsLst, CollectionUtils.newStringMap(
                    "classId", "classId",
                    "className", "className"
            )));
        } else {
            List<ClsClass> clsLst = classService.getClassLstByTeacherId();
            return new Result(true, "操作成功", QBeanUtils.listBean2ListMap(clsLst, CollectionUtils.newStringMap(
                    "classId", "classId",
                    "name", "className"
            )));
        }
    }
 
    @ApiOperation(value = "更新公告查看次数", notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "noticeId", value = "公告id", required = false, paramType = "query", dataType = "String")
    })
    @GetMapping(value = "view")
    public Result view(String noticeId) {
        dao.view(noticeId, ClientUtils.getUserId());
        return Result.SUCCESS;
    }
 
}