派生自 projectDept/qhighschool

EricsHu
2023-11-24 691f717df93c32d89b13f7f73f0678441d60c840
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
package com.qxueyou.scc.stucontroller;
 
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.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;
 
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.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
 
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
 
@Api(tags = "公告接口-学员端")
@RestController
@RequestMapping(value = "/stu/notice")
public class StuNoticeController {
 
    @Autowired
    IClassService classService;
 
    @Autowired
    INoticeService noticeService;
 
    @Autowired
    NoticeDAO dao;
 
    /**
     * @param pageNum
     * @param pageSize
     * @param classId
     * @return
     */
    @ApiOperation(value = "公告列表", notes = "获取班级列表及班级所在公告列表")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "classId", value = "班级id", required = false, paramType="query", dataType = "String")
    })
    @GetMapping(value = "list")
    public Result list(Integer pageNum, Integer pageSize, String classId) {
 
        //获取班级列表及班级所在通知列表
        List<String> noticeIds = dao.getClassNotices(StringUtils.isEmpty(classId)?ClientUtils.getClassId():classId);
        List<Notice> notices = noticeService.readByStatus(noticeIds, Notice.STATUS_ISSUED);
 
        List<Map<String, Object>> lst = QBeanUtils.listBean2ListMap(notices, CollectionUtils.newStringMap(
                "noticeId", "noticeId",
                "title", "name",
                "creator", "creator",
                "noticeTypeName", "type",
                "issuedTime", "releaseTime"
        ));
 
        if(lst!=null && lst.size()>0){
            for (Map<String, Object> map : lst) {
                map.put("isView", dao.isView((String) map.get("noticeId"), ClientUtils.getUserId()));
            }
        }
 
        return new Result(true, "success", CollectionUtils.newObjectMap("noticeCount", lst==null?0:lst.size(), "noticeLst", lst
        ));
    }
 
    /**
     * 获取未读消息总数
     *
     * @return
     */
    @ApiOperation(value = "获取未读消息总数")
    @GetMapping(value = "getCountToView")
    public Result getCountToView() {
 
        //获取班级列表及班级所在通知列表
        List<ClsClass> clsLst = classService.listMyClass();
        Set<String> noticeIdLst = new HashSet<String>(10);
 
        for (ClsClass cls : clsLst) {
            noticeIdLst.addAll(dao.getClassNotices(cls.getClassId()));
        }
 
        int total = 0;
        for (Notice notice : noticeService.readByStatus(noticeIdLst, Notice.STATUS_ISSUED)) {
            System.out.println(ClientUtils.getUserId());
            total += dao.isView(notice.getNoticeId(), ClientUtils.getUserId()) ? 0 : 1;
        }
 
        return new Result(true, "success", total);
    }
 
    /**
     * 获取通知详情
     *
     * @param noticeId
     * @return
     */
    @ApiOperation(value = "获取公告详情")
    @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);
        dao.addReadCount(noticeId, ClientUtils.getUserId());//记录学员已读通知的人数;
        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()
                ));
    }
 
    @ApiOperation(value = "更新公告查看次数", notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "noticeId", value = "公告id", required = true, paramType = "query", dataType = "String")
    })
    @GetMapping(value = "view")
    public Result view(String noticeId) {
        dao.view(noticeId, ClientUtils.getUserId());
        return Result.SUCCESS;
    }
 
 
}