派生自 projectDept/qhighschool

胡仁荣
2022-11-03 68408ba6f0ff9c4e7978735818ab12990c957c1a
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;
    }
 
 
}