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;
|
}
|
|
|
}
|