From 0b5626382a4b77472192153ceb551d8e923f0e91 Mon Sep 17 00:00:00 2001 From: Y1-zd Date: Wed, 27 Oct 2021 19:20:25 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E5=AE=8C=E6=88=90=E5=89=8D=E5=8F=B0?= =?UTF-8?q?=E9=80=9A=E7=9F=A5=E6=A8=A1=E5=9D=97=E7=9A=84=E7=BC=96=E5=86=99?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/NoticeController.java | 24 +++++++++++++--- .../service/NoticeService.java | 8 ++++++ .../service/UserService.java | 10 +++++++ .../service/impl/NoticeServiceImpl.java | 8 ++++++ .../service/impl/UserServiceImpl.java | 28 ++++++++++++++----- ...bileEducationPlatformApplicationTests.java | 18 ++++++++++++ 6 files changed, 85 insertions(+), 11 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 8897e54..9d158d6 100644 --- a/src/main/java/com/mobile_education_platform/controller/NoticeController.java +++ b/src/main/java/com/mobile_education_platform/controller/NoticeController.java @@ -1,8 +1,11 @@ package com.mobile_education_platform.controller; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.hazelcast.internal.json.Json; import com.mobile_education_platform.common.R; import com.mobile_education_platform.pojo.*; import com.mobile_education_platform.pojo.Class; @@ -137,7 +140,7 @@ public class NoticeController { @ApiOperation(value = "发送通知-添加接口") @RequestMapping(value = "/notice/{classId}", method = RequestMethod.POST) public R addNotice(@RequestBody Notice notice, - @PathVariable("classId") String classId) { + @PathVariable("classId") String classId) throws IOException { boolean saveNotice = noticeService.save(notice); if (!saveNotice) { return R.error("保存通知失败!请检查是否有误!"); @@ -154,8 +157,11 @@ public class NoticeController { for (StudentClass studentClass : studentClassList) { studentIds.add(studentClass.getStudentId()); } - //调用后台 - //****** + //调用群发功能,需要根据学生们的student_id来获取wechat_id进行单发(通知只支持一对一发送) + List studentWechatIds= userService.listWechatIdByUserNumber(studentIds); + for (String wechatId:studentWechatIds){ + publishMsg(wechatId); + } return R.ok("新发布通知已完成群发。"); } @@ -222,7 +228,17 @@ public class NoticeController { dataList.add(new TemplateDataVO(new Date().toString())); dataList.add(new TemplateDataVO("该教师发布了新通知,请及时查看。")); msgVo.setParams(dataList); - String s = noticeService.sendSubscribeMessage(msgVo); + String result = noticeService.sendSubscribeMessage(msgVo); + JSONObject sendResult= JSON.parseObject(result); + Integer errcode = (Integer) sendResult.get("errcode"); + switch (errcode){ + case 40003: + return R.error("openid不正确!"); + case 43101: + return R.error("用户取消了订阅!"); + default: + break; + } return R.ok("发布成功!"); } } 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 b05fe17..32ce288 100644 --- a/src/main/java/com/mobile_education_platform/service/NoticeService.java +++ b/src/main/java/com/mobile_education_platform/service/NoticeService.java @@ -39,5 +39,13 @@ public interface NoticeService extends IService { */ Page getNoticePage(int pageNum,int pageCount,String classId); + /** + * 功能: 根据传入的通知请求封装对象发送请求来群发通知 + * @author: 陈梓康 + * @Created: 2021/10/27 18:20 + * @param vo 通知请求封装对象 + * @return 请求是否成功的字符串(可以转为JSON) + * @throws IOException + */ String sendSubscribeMessage(WxMsgVO vo) throws IOException; } diff --git a/src/main/java/com/mobile_education_platform/service/UserService.java b/src/main/java/com/mobile_education_platform/service/UserService.java index 894d1e2..49d2a0c 100644 --- a/src/main/java/com/mobile_education_platform/service/UserService.java +++ b/src/main/java/com/mobile_education_platform/service/UserService.java @@ -4,6 +4,7 @@ import com.mobile_education_platform.pojo.User; import com.baomidou.mybatisplus.extension.service.IService; import com.mobile_education_platform.pojo.vo.UserVO; +import java.util.List; import java.util.Map; /** @@ -51,4 +52,13 @@ public interface UserService extends IService { * @Date: 2021/10/27 9:01 **/ Boolean hasUserInfo(Integer role,String userNumber); + + /** + * 功能: 根据userNumber的List来获取WechatId的List + * @author: 陈梓康 + * @Created: 2021/10/27 18:46 + * @param userNumbers userNumber的List + * @return WechatId的List + */ + List listWechatIdByUserNumber(List userNumbers); } 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 41a6b19..abf2935 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 @@ -65,6 +65,14 @@ public class NoticeServiceImpl extends ServiceImpl impleme return baseMapper.selectPage(page,queryWrapper); } + /** + * 功能: 根据传入的通知请求封装对象发送请求来群发通知 + * @author: 陈梓康 + * @Created: 2021/10/27 18:20 + * @param vo 通知请求封装对象 + * @return 请求是否成功的字符串(可以转为JSON) + * @throws IOException + */ @Override public String sendSubscribeMessage(WxMsgVO vo) throws IOException { String info=""; diff --git a/src/main/java/com/mobile_education_platform/service/impl/UserServiceImpl.java b/src/main/java/com/mobile_education_platform/service/impl/UserServiceImpl.java index e68efe4..460fe53 100644 --- a/src/main/java/com/mobile_education_platform/service/impl/UserServiceImpl.java +++ b/src/main/java/com/mobile_education_platform/service/impl/UserServiceImpl.java @@ -4,10 +4,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.mobile_education_platform.mapper.ParentMapper; import com.mobile_education_platform.mapper.StudentMapper; import com.mobile_education_platform.mapper.TeacherMapper; -import com.mobile_education_platform.pojo.Parent; -import com.mobile_education_platform.pojo.Student; -import com.mobile_education_platform.pojo.Teacher; -import com.mobile_education_platform.pojo.User; +import com.mobile_education_platform.pojo.*; import com.mobile_education_platform.mapper.UserMapper; import com.mobile_education_platform.pojo.vo.UserVO; import com.mobile_education_platform.service.UserService; @@ -15,9 +12,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import org.springframework.stereotype.Service; import javax.annotation.Resource; -import java.util.HashMap; -import java.util.Map; -import java.util.Optional; +import java.util.*; /** *

@@ -177,4 +172,23 @@ public class UserServiceImpl extends ServiceImpl implements Us throw new RuntimeException("用户身份异常,请联系管理员"); } } + + /** + * 功能: 根据usernumber的List来获取WechatId的List + * @author: 陈梓康 + * @Created: 2021/10/27 18:46 + * @param userNumbers usernumber的List + * @return WechatId的List + */ + @Override + public List listWechatIdByUserNumber(List userNumbers) { + List wechatId=new ArrayList<>(); + for(String userNumber:userNumbers){ + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.eq("user_number",userNumber); + User user = baseMapper.selectOne(queryWrapper); + wechatId.add(user.getWechatId()); + } + return wechatId; + } } diff --git a/src/test/java/com/mobile_education_platform/MobileEducationPlatformApplicationTests.java b/src/test/java/com/mobile_education_platform/MobileEducationPlatformApplicationTests.java index 1cf187f..74c2450 100644 --- a/src/test/java/com/mobile_education_platform/MobileEducationPlatformApplicationTests.java +++ b/src/test/java/com/mobile_education_platform/MobileEducationPlatformApplicationTests.java @@ -1,13 +1,31 @@ package com.mobile_education_platform; +import com.mobile_education_platform.pojo.User; +import com.mobile_education_platform.service.UserService; import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; +import java.util.ArrayList; +import java.util.List; + @SpringBootTest class MobileEducationPlatformApplicationTests { + @Autowired + public UserService userService; + @Test void contextLoads() { + List userNumber=new ArrayList<>(); + userNumber.add("012020005"); + userNumber.add("012020008"); + userNumber.add("012020009"); + userNumber.add("012020010"); + List strings = userService.listWechatIdByUserNumber(userNumber); + for(String usernumber:strings){ + System.out.println(usernumber); + } } } -- Gitee From c92c1436e5166d11db953f21f04bffa039f43b90 Mon Sep 17 00:00:00 2001 From: czk Date: Thu, 28 Oct 2021 08:32:43 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=B3=A8=E9=87=8A?= =?UTF-8?q?=EF=BC=8C=E5=B9=B6=E7=BB=99=E3=80=90=E6=B7=BB=E5=8A=A0=E9=80=9A?= =?UTF-8?q?=E7=9F=A5=E5=90=8E=E7=BE=A4=E5=8F=91=E3=80=91=E8=AE=BE=E7=BD=AE?= =?UTF-8?q?=E4=B8=BA=E6=89=B9=E9=87=8F=E7=8F=AD=E7=BA=A7=E8=BD=AC=E5=8F=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/NoticeController.java | 89 +++++++++++++++---- 1 file changed, 70 insertions(+), 19 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 9d158d6..5f67daf 100644 --- a/src/main/java/com/mobile_education_platform/controller/NoticeController.java +++ b/src/main/java/com/mobile_education_platform/controller/NoticeController.java @@ -64,7 +64,19 @@ public class NoticeController { @Autowired public LoginService loginService; + /** + * 功能: 对系统消息进行查询,通过userNumber和学期来进行筛选,最终返回与其所关联的班级的通知 + * @author: ChenZiKang + * @Created: 2021/10/28 8:09 + * @param id userNumber + * @param schoolSemester 学期 + * @return R + */ @ApiOperation(value = "系统消息-查询接口", notes = "查询本人参与的逻辑删除字段不为0的班级的通知,以学期为条件来排序查询。") + @ApiImplicitParams({ + @ApiImplicitParam(name = "用户ID",value = "id",paramType = "string"), + @ApiImplicitParam(name = "学期",value = "schoolSemester",paramType = "string") + }) @RequestMapping(value = "/notices/{schoolSemester}/{id}", method = RequestMethod.GET) public R inNotice(@PathVariable("id") String id, @PathVariable("schoolSemester") String schoolSemester) { @@ -137,36 +149,60 @@ public class NoticeController { return R.error("查询失败!请检查资料是否关联!"); } + /** + * 功能: 当教师发送通知后,对通知所关联的班级(支持批量)进行学生群发 + * @author: ChenZiKang + * @Created: 2021/10/28 8:13 + * @param notice 通知 + * @param classIds 班级ID + * @return R + */ @ApiOperation(value = "发送通知-添加接口") @RequestMapping(value = "/notice/{classId}", method = RequestMethod.POST) public R addNotice(@RequestBody Notice notice, - @PathVariable("classId") String classId) throws IOException { + List classIds) throws IOException { 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.listByClassId(classId); - List studentIds = new ArrayList<>(); - for (StudentClass studentClass : studentClassList) { - studentIds.add(studentClass.getStudentId()); - } - //调用群发功能,需要根据学生们的student_id来获取wechat_id进行单发(通知只支持一对一发送) - List studentWechatIds= userService.listWechatIdByUserNumber(studentIds); - for (String wechatId:studentWechatIds){ - publishMsg(wechatId); + for(String classId:classIds){ + ClassNotice classNotice = new ClassNotice(); + classNotice.setNoticeId(notice.getId()); + classNotice.setClassId(classId); + boolean saveClassNotice = classNoticeService.save(classNotice); + if (!saveClassNotice) { + return R.error("请检查班级是否有误!"); + } + List studentClassList = studentClassService.listByClassId(classId); + List studentIds = new ArrayList<>(); + for (StudentClass studentClass : studentClassList) { + studentIds.add(studentClass.getStudentId()); + } + //调用群发功能,需要根据学生们的student_id来获取wechat_id进行单发(通知只支持一对一发送) + List studentWechatIds= userService.listWechatIdByUserNumber(studentIds); + for (String wechatId:studentWechatIds){ + publishMsg(wechatId); + } } return R.ok("新发布通知已完成群发。"); } + /** + * 功能: 根据班级ID进行通知的查询,并进行分页 + * @author: ChenZiKang + * @Created: 2021/10/28 8:19 + * @param classId 班级ID + * @param pageNum 分页的页数 + * @param pageCount 分页的每页通知数量 + * @return R + */ @ApiOperation(value = "发送通知-查询接口") - @RequestMapping(value = "/notice/{id}/", method = RequestMethod.GET) + @ApiImplicitParams({ + @ApiImplicitParam(name = "班级ID",value = "classId",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, @PathVariable("pageNum") Integer pageNum, @PathVariable("pageCount") Integer pageCount) { @@ -185,8 +221,15 @@ public class NoticeController { return R.ok("查询成功!",data); } + /** + * 功能: 根据通知ID进行逻辑删除 + * @author: ChenZiKang + * @Created: 2021/10/28 8:22 + * @param id 通知ID + * @return R + */ @ApiOperation(value = "发送通知-删除接口") - @ApiImplicitParam(name = "待删除的通知ID", value = "id", required = true, paramType = "string") + @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); @@ -208,6 +251,14 @@ public class NoticeController { return data; } + /** + * 功能: 对单个用户进行消息的发送(小程序不支持群发) + * @author: ChenZiKang + * @Created: 2021/10/28 8:23 + * @param openId 用户的识别凭证 + * @return R + * @throws IOException + */ @ApiOperation("订阅消息群发") @ApiImplicitParam(name = "用户openId",value = "openId",paramType = "string") @RequestMapping(value = "/publishMsg",method = RequestMethod.GET) -- Gitee