diff --git a/src/main/java/com/mobile_education_platform/controller/NoticeController.java b/src/main/java/com/mobile_education_platform/controller/NoticeController.java
index 641587cd0698c2f6f480da2c0d6701d713b75921..f166ac6c0b1c2edcd32536163200df26241ef07d 100644
--- a/src/main/java/com/mobile_education_platform/controller/NoticeController.java
+++ b/src/main/java/com/mobile_education_platform/controller/NoticeController.java
@@ -1,14 +1,24 @@
package com.mobile_education_platform.controller;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.mobile_education_platform.common.R;
+import com.mobile_education_platform.pojo.*;
+import com.mobile_education_platform.pojo.Class;
+import com.mobile_education_platform.service.*;
import io.swagger.annotations.Api;
-import org.springframework.web.bind.annotation.RequestMapping;
+import io.swagger.annotations.ApiImplicitParam;
+import io.swagger.annotations.ApiImplicitParams;
+import io.swagger.annotations.ApiOperation;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
-import org.springframework.web.bind.annotation.RestController;
+import java.text.SimpleDateFormat;
+import java.util.*;
/**
*
- * 前端控制器
+ * 前端控制器
*
*
* @author 元架構
@@ -16,8 +26,163 @@ import org.springframework.web.bind.annotation.RestController;
*/
@RestController
@RequestMapping("/notice")
-@Api(tags = "")
+@Api(tags = "前台通知模块接口")
public class NoticeController {
+ @Autowired
+ public StudentClassService studentClassService;
+
+ @Autowired
+ public NoticeService noticeService;
+
+ @Autowired
+ public UserService userService;
+
+ @Autowired
+ public TeacherService teacherService;
+
+ @Autowired
+ public TeacherClassSubjectService teacherClassSubjectService;
+
+ @Autowired
+ public ClassNoticeService classNoticeService;
+
+ @Autowired
+ public GradeService gradeService;
+
+ @Autowired
+ public ClassService classService;
+
+ @ApiOperation(value = "系统消息-查询接口", notes = "查询本人参与的逻辑删除字段不为0的班级的通知,以学期为条件来排序查询。")
+ @RequestMapping(value = "/notices/{schoolSemester}/{id}", method = RequestMethod.GET)
+ public R inNotice(@PathVariable("id") String id,
+ @PathVariable("schoolSemester") String schoolSemester) {
+ Map data = new HashMap<>();
+ //根据学年学期来确定grade
+ Date date = new Date();
+ SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy");
+ String schoolYear = dateFormat.format(date);
+ QueryWrapper gradeQueryWrapper = new QueryWrapper<>();
+ gradeQueryWrapper.like("school_year", schoolYear + "-");
+ gradeQueryWrapper.eq("school_semester", schoolSemester);
+ //判断身份,根据身份不同来确定查询的方法
+ User user = userService.getOne(new QueryWrapper().eq("user_number", id));
+ if (user==null){
+ return R.error("请检查用户是否存在!");
+ }
+ Integer userRole = user.getRole();
+ if (userRole == 1) {
+ //身份为教师
+ List classIds = teacherClassSubjectService.list(new QueryWrapper().eq("teacher_id", id));
+ for (TeacherClassSubject classId : classIds) {
+ //一条classId只存在于一个class_id_group中
+ gradeQueryWrapper.like("class_id_group", classId.getClassId());
+ Grade grade = gradeService.getOne(gradeQueryWrapper);
+ if (grade == null) {
+ return R.error("该学期无数据!");
+ }
+ QueryWrapper classQueryWrapper = new QueryWrapper<>();
+ classQueryWrapper.eq("id", classId.getClassId());
+ classQueryWrapper.eq("grade_id", grade.getId());
+ Class teacherClass = classService.getOne(classQueryWrapper);
+ List noticeIds = classNoticeService.list(new QueryWrapper().eq("class_id", teacherClass.getId()));
+ for (ClassNotice noticeId : noticeIds) {
+ Notice notice = noticeService.getById(noticeId);
+ if (notice.getIsDeleted()!=1){
+ continue;
+ }
+ Map noticeInfo = new LinkedHashMap<>();
+ noticeInfo.put("title", notice.getTitle());
+ noticeInfo.put("content", notice.getContent());
+ noticeInfo.put("create_time", notice.getCreateTime());
+ data.put(notice.getTitle(), noticeInfo);
+ }
+ }
+ return R.ok("查询成功!", data);
+ } else if (userRole == 2) {
+ //身份为学生
+ StudentClass student = studentClassService.getOne(new QueryWrapper().eq("student_id", id));
+ if (student == null) {
+ return R.error("请检查资料是否有误!");
+ }
+ String classId = student.getClassId();
+ gradeQueryWrapper.like("class_id_group", classId);
+ Grade grade = gradeService.getOne(gradeQueryWrapper);
+ if (grade == null) {
+ return R.error("该学期无数据!");
+ }
+ QueryWrapper classQueryWrapper = new QueryWrapper<>();
+ classQueryWrapper.eq("id", classId);
+ classQueryWrapper.eq("grade_id", grade.getId());
+ Class studentClass = classService.getOne(classQueryWrapper);
+ if (studentClass == null) {
+ return R.error("请检查是否有误!");
+ }
+ List noticeIds = classNoticeService.list(new QueryWrapper().eq("class_id", studentClass.getId()));
+ for (ClassNotice noticeId : noticeIds) {
+ Notice notice = noticeService.getById(noticeId);
+ if (notice.getIsDeleted()!=1){
+ continue;
+ }
+ Map noticeInfo = new LinkedHashMap<>();
+ noticeInfo.put("title", notice.getTitle());
+ noticeInfo.put("content", notice.getContent());
+ noticeInfo.put("create_time", notice.getCreateTime());
+ data.put(notice.getTitle(), noticeInfo);
+ }
+ return R.ok("查询成功!", data);
+ }
+ return R.error("查询失败!请检查资料是否关联!");
+ }
+
+ @ApiOperation(value = "发送通知-添加接口")
+ @RequestMapping(value = "/notice/{classId}", method = RequestMethod.POST)
+ public R addNotice(@RequestBody Notice notice,
+ @PathVariable("classId") String classId) {
+ boolean saveNotice = noticeService.save(notice);
+ if (!saveNotice) {
+ return R.error("保存通知失败!请检查是否有误!");
+ }
+ ClassNotice classNotice = new ClassNotice();
+ classNotice.setNoticeId(notice.getId());
+ classNotice.setClassId(classId);
+ boolean saveClassNotice = classNoticeService.save(classNotice);
+ if (!saveClassNotice) {
+ return R.error("请检查班级是否有误!");
+ }
+ List studentClassList = studentClassService.list((new QueryWrapper().eq("class_id", classId)));
+ List studentIds = new ArrayList<>();
+ for (StudentClass studentClass : studentClassList) {
+ studentIds.add(studentClass.getStudentId());
+ }
+ //调用后台
+ //******
+ return R.ok("新发布通知已完成群发。");
+ }
+
+ @ApiOperation(value = "发送通知-查询接口")
+ @ApiImplicitParam(name = "待查询的通知ID", value = "id", required = true, paramType = "string")
+ @RequestMapping(value = "/notice/{id}", method = RequestMethod.GET)
+ public R selectNotice(String id) {
+ List notices = noticeService.list(new QueryWrapper().eq("promulgator_id", id));
+ Map data = new HashMap<>();
+ for (Notice notice : notices) {
+ Map noticeInfo = new LinkedHashMap<>();
+ noticeInfo.put("title", notice.getTitle());
+ noticeInfo.put("content", notice.getContent());
+ noticeInfo.put("create_time", notice.getCreateTime());
+ data.put(notice.getTitle(), noticeInfo);
+ }
+ return R.ok("成功查询本用户所有发布通知!", data);
+ }
+
+ @ApiOperation(value = "发送通知-删除接口")
+ @ApiImplicitParam(name = "待删除的通知ID", value = "id", required = true, paramType = "string")
+ @RequestMapping(value = "/notice/{id}", method = RequestMethod.DELETE)
+ public R deleteNotice(@PathVariable("id") String id) {
+ Notice notice = noticeService.getById(id);
+ notice.setIsDeleted(0);
+ return R.ok("删除文章成功!");
+ }
}