From b7d72b2199cf5c2dd67b46bd30cede4d22412ec5 Mon Sep 17 00:00:00 2001 From: czk Date: Wed, 27 Oct 2021 09:42:54 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E6=8E=A5=E5=85=A5=E6=B6=88=E6=81=AF?= =?UTF-8?q?=E7=BE=A4=E5=8F=91=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...bileEducationPlatformApplicationTests.java | 39 ++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/src/test/java/com/mobile_education_platform/MobileEducationPlatformApplicationTests.java b/src/test/java/com/mobile_education_platform/MobileEducationPlatformApplicationTests.java index 1cf187f..f591e4a 100644 --- a/src/test/java/com/mobile_education_platform/MobileEducationPlatformApplicationTests.java +++ b/src/test/java/com/mobile_education_platform/MobileEducationPlatformApplicationTests.java @@ -1,13 +1,50 @@ package com.mobile_education_platform; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.mobile_education_platform.pojo.vo.TemplateDataVO; +import com.mobile_education_platform.pojo.vo.WxMsgVO; +import com.mobile_education_platform.service.LoginService; +import com.mobile_education_platform.service.NoticeService; +import com.mobile_education_platform.util.HttpClientUtil; import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; +import java.io.IOException; +import java.util.*; + @SpringBootTest class MobileEducationPlatformApplicationTests { + @Autowired + public LoginService loginService; + + @Autowired + public NoticeService noticeService; + + @Test + void contextLoads() throws IOException { + Map map = loginService.getAccessToken(); + System.out.println(map.get("access_token")); + } + @Test - void contextLoads() { + void test01() throws IOException { + Map token = loginService.getAccessToken(); + String accessToken = (String)token.get("access_token"); + String url="https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token="+accessToken; + WxMsgVO msgVo = new WxMsgVO(); + msgVo.setAccess_token(accessToken); + msgVo.setTemplate_id("tkHjDhvUgu5kf9X_DFLsZt3IeHwjgH_YuBOYCUtvCKk"); + msgVo.setRequest_url(url); + msgVo.setTouser(""); + List dataList=new ArrayList<>(); + dataList.add(new TemplateDataVO("教师")); + dataList.add(new TemplateDataVO(new Date().toString())); + dataList.add(new TemplateDataVO("该教师发布了新通知,请及时查看。")); + msgVo.setParams(dataList); + System.out.println(noticeService.sendSubscribeMessage(msgVo)); } } -- Gitee From 2558523d7b773e31e13f6200b13536b055abb733 Mon Sep 17 00:00:00 2001 From: czk Date: Mon, 1 Nov 2021 10:31:52 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E9=83=A8=E5=88=86?= =?UTF-8?q?=E9=80=9A=E7=9F=A5=E6=96=B9=E5=BC=8F=EF=BC=88=E5=AE=B6=E5=BA=AD?= =?UTF-8?q?=E4=BD=9C=E4=B8=9A=EF=BC=8C=E6=A0=A1=E5=86=85=E5=85=AC=E5=91=8A?= =?UTF-8?q?=EF=BC=8C=E5=AD=A6=E6=A0=A1=E5=85=AC=E5=91=8A=EF=BC=89=EF=BC=8C?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=83=A8=E5=88=86=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/NoticeController.java | 84 +++++++------------ .../pojo/vo/TemplateDataVO.java | 46 ++++++++++ .../pojo/vo/WxMsgVO.java | 35 ++++++++ .../service/ClassNoticeService.java | 1 + .../service/GradeService.java | 2 +- .../service/NoticeService.java | 6 +- .../service/StudentService.java | 9 ++ .../service/TeacherService.java | 8 ++ .../service/impl/GradeServiceImpl.java | 4 +- .../service/impl/NoticeServiceImpl.java | 8 +- .../service/impl/StudentServiceImpl.java | 15 ++++ .../service/impl/TeacherServiceImpl.java | 14 ++++ 12 files changed, 170 insertions(+), 62 deletions(-) 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 89eec57..8b53b82 100644 --- a/src/main/java/com/mobile_education_platform/controller/NoticeController.java +++ b/src/main/java/com/mobile_education_platform/controller/NoticeController.java @@ -10,6 +10,7 @@ import com.mobile_education_platform.pojo.Class; import com.mobile_education_platform.pojo.vo.TemplateDataVO; import com.mobile_education_platform.pojo.vo.WxMsgVO; import com.mobile_education_platform.service.*; +import com.mobile_education_platform.util.DateUtil; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; @@ -61,47 +62,47 @@ public class NoticeController { @Autowired public LoginService loginService; + @Autowired + public StudentService studentService; + /** * 功能: 对系统消息进行查询,通过userNumber和学期来进行筛选,最终返回与其所关联的班级的通知 * @author: ChenZiKang * @Created: 2021/10/28 8:09 - * @param id userNumber - * @param schoolSemester 学期 + * @param number userNumber * @return R */ @ApiOperation(value = "系统消息-查询接口", notes = "查询本人参与的逻辑删除字段不为0的班级的通知,以学期为条件来排序查询。") @ApiImplicitParams({ - @ApiImplicitParam(name = "用户ID",value = "id",paramType = "string"), - @ApiImplicitParam(name = "学期",value = "schoolSemester",paramType = "string") + @ApiImplicitParam(name = "用户编号",value = "number",paramType = "string") }) - @RequestMapping(value = "/notices/{schoolSemester}/{id}", method = RequestMethod.GET) - public R inNotice(@PathVariable("id") String id, - @PathVariable("schoolSemester") String schoolSemester) { + @RequestMapping(value = "/notices/{number}", method = RequestMethod.GET) + public R inNotice(@PathVariable("number") String number) { Map data = new HashMap<>(); //根据学年学期来确定grade - Date date = new Date(); - SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy"); - String schoolYear = dateFormat.format(date); + String schoolYear = DateUtil.getSchoolYear(); + Integer schoolSemester = DateUtil.getSchoolSemester(); //判断身份,根据身份不同来确定查询的方法 - User user = userService.getByUserNumber(id); + User user = userService.getByUserNumber(number); if (user==null){ return R.error("请检查用户是否存在!"); } Integer userRole = user.getRole(); if (userRole == 1) { //身份为教师 + String id = teacherService.getIdByNumber(number); List teachClasses = teacherClassSubjectService.listByTeacherId(id); for (TeacherClassSubject teachClass : teachClasses) { //一条classId只存在于一个class_id_group中 String classId=teachClass.getClassId(); Grade grade = gradeService.getByConditions(schoolYear,schoolSemester,classId); if (grade == null) { - return R.error("该学期无数据!"); + continue; } String gradeId=grade.getId(); Class teacherClass = classService.getClassByIdAndGradeId(classId, gradeId); - List noticeIds = classNoticeService.listByClassId(teacherClass.getId()); - for (ClassNotice noticeId : noticeIds) { + List noticeIds = classNoticeService.listNoticeIdsByClassId(teacherClass.getId()); + for (String noticeId : noticeIds) { Notice notice = noticeService.getById(noticeId); if (notice.getIsDeleted()!=1){ continue; @@ -116,6 +117,7 @@ public class NoticeController { return R.ok("查询成功!", data); } else if (userRole == 2) { //身份为学生 + String id = studentService.getIdByNumber(number); StudentClass student = studentClassService.getByStudentId(id); if (student == null) { return R.error("请检查资料是否有误!"); @@ -129,8 +131,8 @@ public class NoticeController { if (studentClass == null) { return R.error("请检查是否有误!"); } - List noticeIds = classNoticeService.listByClassId(classId); - for (ClassNotice noticeId : noticeIds) { + List noticeIds = classNoticeService.listNoticeIdsByClassId(classId); + for (String noticeId : noticeIds) { Notice notice = noticeService.getById(noticeId); if (notice.getIsDeleted()!=1){ continue; @@ -187,30 +189,30 @@ public class NoticeController { } /** - * 功能: 根据班级ID进行通知的查询,并进行分页 + * 功能: 查看自己所发布的通知 * @author: ChenZiKang * @Created: 2021/10/28 8:19 - * @param classId 班级ID + * @param teacherId 教师ID * @param pageNum 分页的页数 * @param pageCount 分页的每页通知数量 * @return R */ - @ApiOperation(value = "发送通知-查询接口") + @ApiOperation(value = "发送通知-查询接口",notes = "查询自己所发布的通知") @ApiImplicitParams({ - @ApiImplicitParam(name = "班级ID",value = "classId",paramType = "string"), + @ApiImplicitParam(name = "教师ID",value = "teacherId",paramType = "string"), @ApiImplicitParam(name = "页数总数",value = "pageNum",paramType = "integer"), @ApiImplicitParam(name = "每页中通知数量",value = "pageCount",paramType = "integer") }) - @RequestMapping(value = "/notice/{pageNum}/{pageCount}/{classId}", method = RequestMethod.GET) - public R selectNotice(@PathVariable("classId") String classId, + @RequestMapping(value = "/notice/{teacherId}/{pageNum}/{pageCount}", method = RequestMethod.GET) + public R selectNotice(@PathVariable("teacherId") String teacherId, @PathVariable("pageNum") Integer pageNum, @PathVariable("pageCount") Integer pageCount) { Map data=new HashMap<>(); if (pageNum<=0) { - return R.error(404, "页数错误!"); + return R.error("页数错误!"); } - List noticeIds = classNoticeService.listNoticeIdsByClassId(classId); - Page noticePage = noticeService.getNoticePage(pageNum, pageCount, classId); + Page noticePage = noticeService.getNoticePage(pageNum, pageCount, teacherId); + data.put("page",noticePage); if (noticePage.getRecords().size()<=0){ return R.error("查询失败!请检查当前页数是否超出范围!"); } @@ -236,29 +238,15 @@ public class NoticeController { return R.ok("删除文章成功!"); } - public Map putNoticeInfo(List noticeIds){ - Map data=new HashMap<>(); - Map noticesInfo=new HashMap<>(); - int count=0; - List notices = noticeService.listByNoticeList(noticeIds); - for(Notice notice:notices){ - noticesInfo.put("title",notice.getTitle()); - noticesInfo.put("content",notice.getContent()); - noticesInfo.put("create_time",notice.getCreateTime()); - data.put(Integer.toString(++count),noticesInfo); - } - return data; - } - /** - * 功能: 对单个用户进行消息的发送(小程序不支持群发) + * 功能: 对单个用户进行家庭通知的发送 * @author: ChenZiKang * @Created: 2021/10/28 8:23 * @param openId 用户的识别凭证 * @return R * @throws IOException */ - @ApiOperation("订阅消息群发") + @ApiOperation("订阅消息群发-家庭作业") @ApiImplicitParam(name = "用户openId",value = "openId",paramType = "string") @RequestMapping(value = "/publishMsg",method = RequestMethod.GET) public R publishMsg(String openId) throws IOException { @@ -268,16 +256,7 @@ public class NoticeController { Map token = loginService.getAccessToken(); String accessToken = (String)token.get("access_token"); String url="https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token="+accessToken; - WxMsgVO msgVo = new WxMsgVO(); - msgVo.setAccess_token(accessToken); - msgVo.setTemplate_id("tkHjDhvUgu5kf9X_DFLsZt3IeHwjgH_YuBOYCUtvCKk"); - msgVo.setRequest_url(url); - msgVo.setTouser(openId); - List dataList=new ArrayList<>(); - dataList.add(new TemplateDataVO("教师")); - dataList.add(new TemplateDataVO(new Date().toString())); - dataList.add(new TemplateDataVO("该教师发布了新通知,请及时查看。")); - msgVo.setParams(dataList); + WxMsgVO msgVo = WxMsgVO.getHomeWorkMsgVo(accessToken, url, openId); String result = noticeService.sendSubscribeMessage(msgVo); JSONObject sendResult= JSON.parseObject(result); Integer errcode = (Integer) sendResult.get("errcode"); @@ -289,7 +268,8 @@ public class NoticeController { default: break; } - return R.ok("发布成功!"); + System.out.println(errcode); + return null; } } diff --git a/src/main/java/com/mobile_education_platform/pojo/vo/TemplateDataVO.java b/src/main/java/com/mobile_education_platform/pojo/vo/TemplateDataVO.java index 0d4cb9e..d024bf5 100644 --- a/src/main/java/com/mobile_education_platform/pojo/vo/TemplateDataVO.java +++ b/src/main/java/com/mobile_education_platform/pojo/vo/TemplateDataVO.java @@ -4,6 +4,10 @@ import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + /** * 用于微信小程序发送模板信息时的data * @Author: ChenZikang @@ -20,4 +24,46 @@ public class TemplateDataVO { public TemplateDataVO(String value) { this.value = value; } + + /** + * 功能: 返回家庭作业模板 + * @author: ChenZiKang + * @Created: 2021/11/1 8:42 + * @return 家庭作业模板 + */ + public static List getHomeWorkTemplate(){ + List dataList=new ArrayList<>(); + dataList.add(new TemplateDataVO("教师")); + dataList.add(new TemplateDataVO(new Date().toString())); + dataList.add(new TemplateDataVO("该教师发布了新作业,请及时查看。")); + return dataList; + } + + /** + * 功能: 返回学校通知模板 + * @author: ChenZiKang + * @Created: 2021/11/1 8:44 + * @return 学校通知模板 + */ + public static List getSchoolNoticeTemplate(){ + List dataList=new ArrayList<>(); + dataList.add(new TemplateDataVO("校方")); + dataList.add(new TemplateDataVO(new Date().toString())); + dataList.add(new TemplateDataVO("校方发布了新通知,请及时查看。")); + return dataList; + } + + /** + * 功能: 获取学校公告模板 + * @author: ChenZiKang + * @Created: 2021/11/1 8:45 + * @return 学校公告模板 + */ + public static List getSchoolBulletinTemplate(){ + List dataList=new ArrayList<>(); + dataList.add(new TemplateDataVO("校方")); + dataList.add(new TemplateDataVO(new Date().toString())); + dataList.add(new TemplateDataVO("校方发布了新公告,请及时查看。")); + return dataList; + } } diff --git a/src/main/java/com/mobile_education_platform/pojo/vo/WxMsgVO.java b/src/main/java/com/mobile_education_platform/pojo/vo/WxMsgVO.java index 54b7c55..a6624bb 100644 --- a/src/main/java/com/mobile_education_platform/pojo/vo/WxMsgVO.java +++ b/src/main/java/com/mobile_education_platform/pojo/vo/WxMsgVO.java @@ -3,8 +3,10 @@ package com.mobile_education_platform.pojo.vo; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; +import org.apache.tomcat.util.descriptor.web.WebXml; import java.util.ArrayList; +import java.util.Date; import java.util.List; /** @@ -23,4 +25,37 @@ public class WxMsgVO { private String access_token; private String request_url; private List params = new ArrayList<>(); + + public static WxMsgVO getHomeWorkMsgVo(String accessToken,String url,String openId){ + WxMsgVO msgVO = new WxMsgVO(); + msgVO.setAccess_token(accessToken); + msgVO.setTemplate_id("tkHjDhvUgu5kf9X_DFLsZt3IeHwjgH_YuBOYCUtvCKk"); + msgVO.setRequest_url(url); + msgVO.setTouser(openId); + List dataList = TemplateDataVO.getHomeWorkTemplate(); + msgVO.setParams(dataList); + return msgVO; + } + + public static WxMsgVO getSchoolNoticeMsgVo(String accessToken,String url,String openId){ + WxMsgVO msgVO = new WxMsgVO(); + msgVO.setAccess_token(accessToken); + msgVO.setTemplate_id("tkHjDhvUgu5kf9X_DFLsZt3IeHwjgH_YuBOYCUtvCKk"); + msgVO.setRequest_url(url); + msgVO.setTouser(openId); + List dataList = TemplateDataVO.getSchoolNoticeTemplate(); + msgVO.setParams(dataList); + return msgVO; + } + + public static WxMsgVO getSchoolBulletinMsgVo(String accessToken,String url,String openId){ + WxMsgVO msgVO = new WxMsgVO(); + msgVO.setAccess_token(accessToken); + msgVO.setTemplate_id("tkHjDhvUgu5kf9X_DFLsZt3IeHwjgH_YuBOYCUtvCKk"); + msgVO.setRequest_url(url); + msgVO.setTouser(openId); + List dataList = TemplateDataVO.getSchoolBulletinTemplate(); + msgVO.setParams(dataList); + return msgVO; + } } \ No newline at end of file diff --git a/src/main/java/com/mobile_education_platform/service/ClassNoticeService.java b/src/main/java/com/mobile_education_platform/service/ClassNoticeService.java index c1fb50b..09d3fa3 100644 --- a/src/main/java/com/mobile_education_platform/service/ClassNoticeService.java +++ b/src/main/java/com/mobile_education_platform/service/ClassNoticeService.java @@ -1,5 +1,6 @@ package com.mobile_education_platform.service; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.mobile_education_platform.pojo.ClassNotice; import com.baomidou.mybatisplus.extension.service.IService; diff --git a/src/main/java/com/mobile_education_platform/service/GradeService.java b/src/main/java/com/mobile_education_platform/service/GradeService.java index 60187fa..09fd992 100644 --- a/src/main/java/com/mobile_education_platform/service/GradeService.java +++ b/src/main/java/com/mobile_education_platform/service/GradeService.java @@ -25,7 +25,7 @@ public interface GradeService extends IService { * @param classId 班级ID(模糊查询) * @return Grade对象 */ - Grade getByConditions(String schoolYear,String schoolSemester,String classId); + Grade getByConditions(String schoolYear,Integer schoolSemester,String classId); /** * @Description: 根据学年+学期查询年级 diff --git a/src/main/java/com/mobile_education_platform/service/NoticeService.java b/src/main/java/com/mobile_education_platform/service/NoticeService.java index 1251f90..a0476bc 100644 --- a/src/main/java/com/mobile_education_platform/service/NoticeService.java +++ b/src/main/java/com/mobile_education_platform/service/NoticeService.java @@ -29,15 +29,15 @@ public interface NoticeService extends IService { List listByNoticeList(List noticeIds); /** - * 功能: 根据班级ID给通知分页 + * 功能: 根据教师ID给通知分页 * @author: 陈梓康 * @Created: 2021/10/26 22:08 * @param pageNum 分页的通知总数 * @param pageCount 分页的页数 - * @param classId 班级ID + * @param teacherId 教师ID * @return Page对象 */ - Page getNoticePage(int pageNum,int pageCount,String classId); + Page getNoticePage(int pageNum,int pageCount,String teacherId); /** * 功能: 根据传入的通知请求封装对象发送请求来群发通知 diff --git a/src/main/java/com/mobile_education_platform/service/StudentService.java b/src/main/java/com/mobile_education_platform/service/StudentService.java index 228afe5..a4c23cf 100644 --- a/src/main/java/com/mobile_education_platform/service/StudentService.java +++ b/src/main/java/com/mobile_education_platform/service/StudentService.java @@ -13,4 +13,13 @@ import com.baomidou.mybatisplus.extension.service.IService; */ public interface StudentService extends IService { + /** + * 功能: 根据用户编号获取学生ID + * @author: ChenZiKang + * @Created: 2021/11/1 8:18 + * @param number 用户编号 + * @return 学生ID + */ + String getIdByNumber(String number); + } diff --git a/src/main/java/com/mobile_education_platform/service/TeacherService.java b/src/main/java/com/mobile_education_platform/service/TeacherService.java index fd60eae..9b806b0 100644 --- a/src/main/java/com/mobile_education_platform/service/TeacherService.java +++ b/src/main/java/com/mobile_education_platform/service/TeacherService.java @@ -32,4 +32,12 @@ public interface TeacherService extends IService { */ int updateTeacher(TeacherDTO teacherDto); + /** + * 功能: 通过用户编号得到教师ID + * @author: ChenZiKang + * @Created: 2021/11/1 8:14 + * @param number 用户编号 + * @return 教师表ID + */ + String getIdByNumber(String number); } diff --git a/src/main/java/com/mobile_education_platform/service/impl/GradeServiceImpl.java b/src/main/java/com/mobile_education_platform/service/impl/GradeServiceImpl.java index 9b13cff..e420169 100644 --- a/src/main/java/com/mobile_education_platform/service/impl/GradeServiceImpl.java +++ b/src/main/java/com/mobile_education_platform/service/impl/GradeServiceImpl.java @@ -30,9 +30,9 @@ public class GradeServiceImpl extends ServiceImpl implements * @return Grade对象 */ @Override - public Grade getByConditions(String schoolYear, String schoolSemester, String classId) { + public Grade getByConditions(String schoolYear, Integer schoolSemester, String classId) { QueryWrapper gradeQueryWrapper = new QueryWrapper<>(); - gradeQueryWrapper.like("school_year", schoolYear + "-"); + gradeQueryWrapper.like("school_year", schoolYear); gradeQueryWrapper.eq("school_semester", schoolSemester); gradeQueryWrapper.like("class_id_group", classId); return baseMapper.selectOne(gradeQueryWrapper); diff --git a/src/main/java/com/mobile_education_platform/service/impl/NoticeServiceImpl.java b/src/main/java/com/mobile_education_platform/service/impl/NoticeServiceImpl.java index 0d346fc..c65dc3f 100644 --- a/src/main/java/com/mobile_education_platform/service/impl/NoticeServiceImpl.java +++ b/src/main/java/com/mobile_education_platform/service/impl/NoticeServiceImpl.java @@ -49,19 +49,19 @@ public class NoticeServiceImpl extends ServiceImpl impleme } /** - * 功能: 根据班级ID给通知分页 + * 功能: 根据教师ID给通知分页 * @author: 陈梓康 * @Created: 2021/10/26 22:08 * @param pageNum 分页的通知总数 * @param pageCount 分页的页数 - * @param classId 班级ID + * @param teacherId 教师ID * @return Page对象 */ @Override - public Page getNoticePage(int pageNum, int pageCount, String classId) { + public Page getNoticePage(int pageNum, int pageCount, String teacherId) { Page page=new Page<>(pageNum,pageCount); QueryWrapper queryWrapper = new QueryWrapper<>(); - queryWrapper.eq("class_id",classId); + queryWrapper.eq("promulgator_id",teacherId); return baseMapper.selectPage(page,queryWrapper); } diff --git a/src/main/java/com/mobile_education_platform/service/impl/StudentServiceImpl.java b/src/main/java/com/mobile_education_platform/service/impl/StudentServiceImpl.java index e8c7e10..4ed0e51 100644 --- a/src/main/java/com/mobile_education_platform/service/impl/StudentServiceImpl.java +++ b/src/main/java/com/mobile_education_platform/service/impl/StudentServiceImpl.java @@ -1,10 +1,12 @@ package com.mobile_education_platform.service.impl; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.mobile_education_platform.pojo.Student; import com.mobile_education_platform.mapper.StudentMapper; import com.mobile_education_platform.service.StudentService; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import org.springframework.stereotype.Service; +import sun.misc.BASE64Decoder; /** *

@@ -17,4 +19,17 @@ import org.springframework.stereotype.Service; @Service public class StudentServiceImpl extends ServiceImpl implements StudentService { + /** + * 功能: 根据用户编号获取学生ID + * @author: ChenZiKang + * @Created: 2021/11/1 8:18 + * @param number 用户编号 + * @return 学生ID + */ + @Override + public String getIdByNumber(String number) { + QueryWrapper queryWrapper=new QueryWrapper().eq("number",number); + Student student = baseMapper.selectOne(queryWrapper); + return student.getId(); + } } diff --git a/src/main/java/com/mobile_education_platform/service/impl/TeacherServiceImpl.java b/src/main/java/com/mobile_education_platform/service/impl/TeacherServiceImpl.java index 6734b48..71271d8 100644 --- a/src/main/java/com/mobile_education_platform/service/impl/TeacherServiceImpl.java +++ b/src/main/java/com/mobile_education_platform/service/impl/TeacherServiceImpl.java @@ -52,4 +52,18 @@ public class TeacherServiceImpl extends ServiceImpl impl return baseMapper.updateById(teacher); } + /** + * 功能: 通过用户编号得到教师ID + * @author: ChenZiKang + * @Created: 2021/11/1 8:14 + * @param number 用户编号 + * @return 教师表ID + */ + @Override + public String getIdByNumber(String number) { + QueryWrapper queryWrapper=new QueryWrapper().eq("number",number); + Teacher teacher = baseMapper.selectOne(queryWrapper); + return teacher.getId(); + } + } -- Gitee From 62dd5b4cf93b6be7d970754abba36d419fdca4db Mon Sep 17 00:00:00 2001 From: Y1-zd Date: Mon, 1 Nov 2021 16:04:45 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E6=94=B9BUG=EF=BC=8C=E5=AE=8C=E6=88=90?= =?UTF-8?q?=E6=89=80=E6=9C=89=E5=8A=9F=E8=83=BD=E7=9A=84=E6=95=B4=E6=94=B9?= =?UTF-8?q?=E5=8F=8A=E6=B5=8B=E8=AF=95=EF=BC=8C=E5=AE=8C=E6=88=90=E5=89=8D?= =?UTF-8?q?=E5=8F=B0=E9=80=9A=E7=9F=A5=E6=A8=A1=E5=9D=97=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../config/TomcatConfig.java | 26 ++++ .../controller/NoticeController.java | 121 +++++++++--------- .../service/GradeService.java | 14 +- .../service/NoticeService.java | 20 ++- .../service/StudentClassService.java | 6 +- .../service/impl/GradeServiceImpl.java | 27 +++- .../service/impl/NoticeServiceImpl.java | 39 ++++-- .../service/impl/StudentClassServiceImpl.java | 14 +- 8 files changed, 180 insertions(+), 87 deletions(-) create mode 100644 src/main/java/com/mobile_education_platform/config/TomcatConfig.java diff --git a/src/main/java/com/mobile_education_platform/config/TomcatConfig.java b/src/main/java/com/mobile_education_platform/config/TomcatConfig.java new file mode 100644 index 0000000..327eaf9 --- /dev/null +++ b/src/main/java/com/mobile_education_platform/config/TomcatConfig.java @@ -0,0 +1,26 @@ +package com.mobile_education_platform.config; + +import org.apache.catalina.connector.Connector; +import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +/** + * 使RequestParam在URL中可以解析特殊字符 + * + * @Author 陈梓康 + * @create 2021/11/1 15:15 + */ +@Configuration +public class TomcatConfig { + + @Bean + public TomcatServletWebServerFactory webServerFactory() { + TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory(); + factory.addConnectorCustomizers((Connector connector) -> { + connector.setProperty("relaxedPathChars", "\"<>[\\]^`{|}"); + connector.setProperty("relaxedQueryChars", "\"<>[\\]^`{|}"); + }); + return factory; + } +} \ No newline at end of file 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 8b53b82..75cd115 100644 --- a/src/main/java/com/mobile_education_platform/controller/NoticeController.java +++ b/src/main/java/com/mobile_education_platform/controller/NoticeController.java @@ -7,7 +7,6 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page; 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.pojo.vo.TemplateDataVO; import com.mobile_education_platform.pojo.vo.WxMsgVO; import com.mobile_education_platform.service.*; import com.mobile_education_platform.util.DateUtil; @@ -19,7 +18,6 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import java.io.IOException; -import java.text.SimpleDateFormat; import java.util.*; /** @@ -73,9 +71,7 @@ public class NoticeController { * @return R */ @ApiOperation(value = "系统消息-查询接口", notes = "查询本人参与的逻辑删除字段不为0的班级的通知,以学期为条件来排序查询。") - @ApiImplicitParams({ - @ApiImplicitParam(name = "用户编号",value = "number",paramType = "string") - }) + @ApiImplicitParam(name = "用户编号",value = "number",paramType = "string") @RequestMapping(value = "/notices/{number}", method = RequestMethod.GET) public R inNotice(@PathVariable("number") String number) { Map data = new HashMap<>(); @@ -88,23 +84,55 @@ public class NoticeController { return R.error("请检查用户是否存在!"); } Integer userRole = user.getRole(); - if (userRole == 1) { - //身份为教师 - String id = teacherService.getIdByNumber(number); - List teachClasses = teacherClassSubjectService.listByTeacherId(id); - for (TeacherClassSubject teachClass : teachClasses) { - //一条classId只存在于一个class_id_group中 - String classId=teachClass.getClassId(); - Grade grade = gradeService.getByConditions(schoolYear,schoolSemester,classId); + switch (userRole){ + case 1: + //身份为教师 + //根据teacher_id来获得该教师参与的班级,再通过遍历各个班级来看是否对应上学年学期,如若是则查找notice + String teacherId = teacherService.getIdByNumber(number); + List teachClasses = teacherClassSubjectService.listByTeacherId(teacherId); + for (TeacherClassSubject teachClass : teachClasses) { + //一条classId只存在于一个class_id_group中 + String classId=teachClass.getClassId(); + Grade grade = gradeService.getByConditions(schoolYear,schoolSemester,classId); + if (grade == null) { + continue; + } + String gradeId=grade.getId(); + Class teacherClass = classService.getClassByIdAndGradeId(classId, gradeId); + List noticeIds = classNoticeService.listNoticeIdsByClassId(teacherClass.getId()); + for (String noticeId : noticeIds) { + Notice notice=noticeService.getNormalStateNotice(noticeId); + if (notice==null){ + 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); + + case 2: + //身份为学生 + //通过student_id来获得该学生与班级的联系(3条),根据学年学期和联系来找到对应年级 + String studentId = studentService.getIdByNumber(number); + List classIds = studentClassService.listClassIdByStudentId(studentId); + //区分对应的是该学年学期哪一个年级,同时也得获得班级ID + String classId = gradeService.getClassIdByConditions(schoolYear, schoolSemester, classIds); + Grade grade=gradeService.getByConditions(schoolYear,schoolSemester,classId); if (grade == null) { - continue; + return R.error("该学期无数据!"); } - String gradeId=grade.getId(); - Class teacherClass = classService.getClassByIdAndGradeId(classId, gradeId); - List noticeIds = classNoticeService.listNoticeIdsByClassId(teacherClass.getId()); + Class studentClass = classService.getClassByIdAndGradeId(classId,grade.getId()); + if (studentClass == null) { + return R.error("请检查是否有误!"); + } + List noticeIds = classNoticeService.listNoticeIdsByClassId(classId); for (String noticeId : noticeIds) { - Notice notice = noticeService.getById(noticeId); - if (notice.getIsDeleted()!=1){ + Notice notice=noticeService.getNormalStateNotice(noticeId); + if (notice==null){ continue; } Map noticeInfo = new LinkedHashMap<>(); @@ -113,39 +141,11 @@ public class NoticeController { noticeInfo.put("create_time", notice.getCreateTime()); data.put(notice.getTitle(), noticeInfo); } - } - return R.ok("查询成功!", data); - } else if (userRole == 2) { - //身份为学生 - String id = studentService.getIdByNumber(number); - StudentClass student = studentClassService.getByStudentId(id); - if (student == null) { - return R.error("请检查资料是否有误!"); - } - String classId = student.getClassId(); - Grade grade = gradeService.getByConditions(schoolYear,schoolSemester,classId); - if (grade == null) { - return R.error("该学期无数据!"); - } - Class studentClass = classService.getClassByIdAndGradeId(classId,grade.getId()); - if (studentClass == null) { - return R.error("请检查是否有误!"); - } - List noticeIds = classNoticeService.listNoticeIdsByClassId(classId); - for (String 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.ok("查询成功!", data); + default: + break; } - return R.error("查询失败!请检查资料是否关联!"); + return R.error("查询失败!"); } /** @@ -157,15 +157,16 @@ public class NoticeController { * @return R */ @ApiOperation(value = "发送通知-添加接口") - @RequestMapping(value = "/notice/{classId}", method = RequestMethod.POST) + @RequestMapping(value = "/notice", method = RequestMethod.POST) public R addNotice(@RequestBody Notice notice, - List classIds) throws IOException { + @RequestParam List classIds) throws IOException { + notice.setIsDeleted(1); boolean saveNotice = noticeService.save(notice); if (!saveNotice) { return R.error("保存通知失败!请检查是否有误!"); } - //对刚保存的通知,获取生成的ID - String noticeId = noticeService.getAddNoticeId(notice); + //save方法保存后能够通过getId来获取刚生成的ID + String noticeId = notice.getId(); for(String classId:classIds){ ClassNotice classNotice = new ClassNotice(); classNotice.setNoticeId(noticeId); @@ -229,17 +230,19 @@ public class NoticeController { * @param id 通知ID * @return R */ - @ApiOperation(value = "发送通知-删除接口") + @ApiOperation(value = "发送通知-删除接口",notes ="修改通知记录的逻辑删除状态") @ApiImplicitParam(name = "待删除的通知ID", value = "id",paramType = "string") @RequestMapping(value = "/notice/{id}", method = RequestMethod.DELETE) public R deleteNotice(@PathVariable("id") String id) { - Notice notice = noticeService.getById(id); - notice.setIsDeleted(0); + Integer update = noticeService.updateDeletedState(id); + if (update!=1){ + return R.error("文章删除失败!请检查文章是否存在!"); + } return R.ok("删除文章成功!"); } /** - * 功能: 对单个用户进行家庭通知的发送 + * 功能: 对单个用户进行家庭通知的发送(教师端) * @author: ChenZiKang * @Created: 2021/10/28 8:23 * @param openId 用户的识别凭证 diff --git a/src/main/java/com/mobile_education_platform/service/GradeService.java b/src/main/java/com/mobile_education_platform/service/GradeService.java index 09fd992..34a3b8c 100644 --- a/src/main/java/com/mobile_education_platform/service/GradeService.java +++ b/src/main/java/com/mobile_education_platform/service/GradeService.java @@ -1,6 +1,5 @@ package com.mobile_education_platform.service; -import com.mobile_education_platform.pojo.Class; import com.mobile_education_platform.pojo.Grade; import com.baomidou.mybatisplus.extension.service.IService; @@ -17,7 +16,7 @@ import java.util.List; public interface GradeService extends IService { /** - * 功能: 根据学年,学期和classId进行查询 + * 功能: 根据学年,学期和classId进行查询(用于通知查询,身份为教师时) * @author: 陈梓康 * @Created: 2021/10/26 20:15 * @param schoolYear 学年 @@ -27,6 +26,17 @@ public interface GradeService extends IService { */ Grade getByConditions(String schoolYear,Integer schoolSemester,String classId); + /** + * 功能: 根据学年,学期和classIds进行查询来获得班级ID(用于通知查询,身份为学生时) + * @author: 陈梓康 + * @Created: 2021/11/1 13:52 + * @param schoolYear 学年 + * @param schoolSemester 学期 + * @param classIds 班级ID List + * @return Grade对象 + */ + String getClassIdByConditions(String schoolYear,Integer schoolSemester,List classIds); + /** * @Description: 根据学年+学期查询年级 * @param schoolYear 学年 diff --git a/src/main/java/com/mobile_education_platform/service/NoticeService.java b/src/main/java/com/mobile_education_platform/service/NoticeService.java index a0476bc..764bc23 100644 --- a/src/main/java/com/mobile_education_platform/service/NoticeService.java +++ b/src/main/java/com/mobile_education_platform/service/NoticeService.java @@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.mobile_education_platform.pojo.Notice; import com.baomidou.mybatisplus.extension.service.IService; import com.mobile_education_platform.pojo.vo.WxMsgVO; +import io.swagger.models.auth.In; import java.io.IOException; import java.util.List; @@ -50,12 +51,19 @@ public interface NoticeService extends IService { String sendSubscribeMessage(WxMsgVO vo) throws IOException; /** - * 功能: 刚保存的通知生成ID后,对ID进行获取 - * @author: ChenZiKang - * @Created: 2021/10/28 9:09 - * @param notice 通知 - * @return 通知ID + * 功能: 根据未删除状态和id查询通知 + * @author: 陈梓康 + * @Created: 2021/11/1 14:39 + * @param id 通知ID + * @return 通知对象 */ - String getAddNoticeId(Notice notice); + Notice getNormalStateNotice(String id); + /** + * 功能: 根据通知ID进行逻辑删除 + * @author: 陈梓康 + * @Created: 2021/11/1 15:39 + * @param id 通知ID + */ + Integer updateDeletedState(String id); } diff --git a/src/main/java/com/mobile_education_platform/service/StudentClassService.java b/src/main/java/com/mobile_education_platform/service/StudentClassService.java index bb91f12..05bb662 100644 --- a/src/main/java/com/mobile_education_platform/service/StudentClassService.java +++ b/src/main/java/com/mobile_education_platform/service/StudentClassService.java @@ -34,11 +34,11 @@ public interface StudentClassService extends IService { List listByClassId(String classId); /** - * 功能: 根据学生ID得到一个StudentClass对象 + * 功能: 根据学生ID得到一个学生多个年级的班级ID * @author: 陈梓康 * @Created: 2021/10/26 20:34 * @param studentId 学生ID - * @return StudentClass对象 + * @return 个学生多个年级的班级ID */ - StudentClass getByStudentId(String studentId); + List listClassIdByStudentId(String studentId); } diff --git a/src/main/java/com/mobile_education_platform/service/impl/GradeServiceImpl.java b/src/main/java/com/mobile_education_platform/service/impl/GradeServiceImpl.java index e420169..40141d0 100644 --- a/src/main/java/com/mobile_education_platform/service/impl/GradeServiceImpl.java +++ b/src/main/java/com/mobile_education_platform/service/impl/GradeServiceImpl.java @@ -32,12 +32,37 @@ public class GradeServiceImpl extends ServiceImpl implements @Override public Grade getByConditions(String schoolYear, Integer schoolSemester, String classId) { QueryWrapper gradeQueryWrapper = new QueryWrapper<>(); - gradeQueryWrapper.like("school_year", schoolYear); + gradeQueryWrapper.eq("school_year", schoolYear); gradeQueryWrapper.eq("school_semester", schoolSemester); gradeQueryWrapper.like("class_id_group", classId); return baseMapper.selectOne(gradeQueryWrapper); } + /** + * 功能: 根据学年,学期和classIds进行查询来获得班级ID(用于通知查询,身份为学生时) + * @author: 陈梓康 + * @Created: 2021/11/1 13:52 + * @param schoolYear 学年 + * @param schoolSemester 学期 + * @param classIds 班级ID List + * @return Grade对象 + */ + @Override + public String getClassIdByConditions(String schoolYear, Integer schoolSemester, List classIds) { + String result = null; + for (String classId:classIds){ + QueryWrapper queryWrapper=new QueryWrapper<>(); + queryWrapper.eq("school_year", schoolYear); + queryWrapper.eq("school_semester", schoolSemester); + queryWrapper.like("class_id_group", classId); + Grade grade = baseMapper.selectOne(queryWrapper); + if (grade!=null){ + result=classId; + } + } + return result; + } + /** * @Description: 根据学年+学期查询年级 * @param schoolYear 学年 diff --git a/src/main/java/com/mobile_education_platform/service/impl/NoticeServiceImpl.java b/src/main/java/com/mobile_education_platform/service/impl/NoticeServiceImpl.java index c65dc3f..78ec5fa 100644 --- a/src/main/java/com/mobile_education_platform/service/impl/NoticeServiceImpl.java +++ b/src/main/java/com/mobile_education_platform/service/impl/NoticeServiceImpl.java @@ -2,6 +2,7 @@ package com.mobile_education_platform.service.impl; import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.mobile_education_platform.pojo.Notice; import com.mobile_education_platform.mapper.NoticeMapper; @@ -130,20 +131,34 @@ public class NoticeServiceImpl extends ServiceImpl impleme } /** - * 功能: 刚保存的通知生成ID后,对ID进行获取 - * @author: ChenZiKang - * @Created: 2021/10/28 9:09 - * @param notice 通知 - * @return 通知ID + * 功能: 根据未删除状态和id查询通知 + * @author: 陈梓康 + * @Created: 2021/11/1 14:39 + * @param id 通知ID + * @return 通知对象 */ @Override - public String getAddNoticeId(Notice notice) { + public Notice getNormalStateNotice(String id) { QueryWrapper queryWrapper=new QueryWrapper<>(); - queryWrapper.eq("title",notice.getTitle()); - queryWrapper.eq("content",notice.getContent()); - queryWrapper.eq("promulgator_id",notice.getPromulgatorId()); - queryWrapper.eq("is_deleted",notice.getIsDeleted()); - Notice result = baseMapper.selectOne(queryWrapper); - return result.getId(); + queryWrapper.eq("is_deleted","1"); + queryWrapper.eq("id",id); + return baseMapper.selectOne(queryWrapper); + } + + /** + * 功能: 根据通知ID进行逻辑删除 + * @author: 陈梓康 + * @Created: 2021/11/1 15:39 + * @param id 通知ID + */ + @Override + public Integer updateDeletedState(String id) { + Notice notice = baseMapper.selectById(id); + notice.setId(id); + UpdateWrapper updateWrapper=new UpdateWrapper<>(); + updateWrapper.set("is_deleted",0); + updateWrapper.eq("is_deleted",1); + updateWrapper.eq("id",id); + return baseMapper.update(notice, updateWrapper); } } diff --git a/src/main/java/com/mobile_education_platform/service/impl/StudentClassServiceImpl.java b/src/main/java/com/mobile_education_platform/service/impl/StudentClassServiceImpl.java index 937b36c..4d10f2c 100644 --- a/src/main/java/com/mobile_education_platform/service/impl/StudentClassServiceImpl.java +++ b/src/main/java/com/mobile_education_platform/service/impl/StudentClassServiceImpl.java @@ -9,6 +9,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import java.util.ArrayList; import java.util.List; /** @@ -56,16 +57,21 @@ public class StudentClassServiceImpl extends ServiceImpl listClassIdByStudentId(String studentId) { QueryWrapper queryWrapper = new QueryWrapper<>(); queryWrapper.eq("student_id", studentId); - return baseMapper.selectOne(queryWrapper); + List studentClasses = baseMapper.selectList(queryWrapper); + List classIds=new ArrayList<>(); + for (StudentClass studentClass:studentClasses){ + classIds.add(studentClass.getClassId()); + } + return classIds; } } -- Gitee