From 8fab15d4525d2795bd5c0091dd547d6f7f0fb497 Mon Sep 17 00:00:00 2001 From: DengMin <16679070171@qq.com> Date: Mon, 28 Feb 2022 14:41:51 +0800 Subject: [PATCH] 班级通知 添加短信模版 --- src/main/java/com/subsidy/common/constant/CourseNotification.java | 6 ------ src/main/java/com/subsidy/common/constant/SmsCode.java | 23 +++++++++++++++++++++++ src/main/java/com/subsidy/jobs/CourseNotificationJob.java | 29 ++++++++++++++++++----------- src/main/java/com/subsidy/service/impl/ClassNoticeServiceImpl.java | 15 ++++++++------- 4 files changed, 49 insertions(+), 24 deletions(-) create mode 100644 src/main/java/com/subsidy/common/constant/SmsCode.java diff --git a/src/main/java/com/subsidy/common/constant/CourseNotification.java b/src/main/java/com/subsidy/common/constant/CourseNotification.java index 449a57a..0111f35 100644 --- a/src/main/java/com/subsidy/common/constant/CourseNotification.java +++ b/src/main/java/com/subsidy/common/constant/CourseNotification.java @@ -5,10 +5,4 @@ public class CourseNotification { public static final String UNSENT = "待发送"; public static final String SENT = "已发送"; - - public static final String ALL = "全部成员"; - - public static final String NOT_SIGNED_IN = "未签到成员"; - - public static final String UNFINISHED = "未完课成员"; } diff --git a/src/main/java/com/subsidy/common/constant/SmsCode.java b/src/main/java/com/subsidy/common/constant/SmsCode.java new file mode 100644 index 0000000..af4b353 --- /dev/null +++ b/src/main/java/com/subsidy/common/constant/SmsCode.java @@ -0,0 +1,23 @@ +package com.subsidy.common.constant; + +import lombok.Getter; + +@Getter +public enum SmsCode { + + SIGN_IN("SMS_234409992", "签到通知"), + TEST("SMS_234414789", "测试通知"), + CLASS_START("SMS_228017725", "开课通知"), + ALL("SMS_228137810", "全部成员"), + NOT_SIGNED_IN("SMS_234409992","未签到成员"), + UNFINISHED("SMS_234414789","未完课成员"); + + private String type; + + private String code; + + SmsCode(String code, String type) { + this.code = code; + this.type = type; + } +} diff --git a/src/main/java/com/subsidy/jobs/CourseNotificationJob.java b/src/main/java/com/subsidy/jobs/CourseNotificationJob.java index 3388b6b..2a01b57 100644 --- a/src/main/java/com/subsidy/jobs/CourseNotificationJob.java +++ b/src/main/java/com/subsidy/jobs/CourseNotificationJob.java @@ -1,6 +1,7 @@ package com.subsidy.jobs; import com.subsidy.common.constant.CourseNotification; +import com.subsidy.common.constant.SmsCode; import com.subsidy.mapper.ClassNoticeMapper; import com.subsidy.mapper.MemberMapper; import com.subsidy.model.ClassNoticeDO; @@ -12,8 +13,10 @@ import org.quartz.JobExecutionException; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import java.util.Arrays; import java.util.List; import java.util.Map; +import java.util.stream.Collectors; /** *

@@ -36,22 +39,26 @@ public class CourseNotificationJob implements Job { private SMSUtils smsUtils; @Override - public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException { + public void execute(JobExecutionContext jobExecutionContext) { Map map = jobExecutionContext.getJobDetail().getJobDataMap(); Map params = (Map) map.get("params"); if(params != null) { - List list = memberMapper.getMemberList((Long) params.get("classId")); - if(list != null && list.size() > 0) { - for (MemberDO memberDO : list) { - if(memberDO != null) { - // smsUtils.send(memberDO.getTelephone(), ""); + ClassNoticeDO classNoticeDO = classNoticeMapper.selectById((Long) params.get("id")); + if(classNoticeDO != null) { + List list = memberMapper.getMemberList((Long) params.get("classId")); + if(list != null && list.size() > 0) { + for (MemberDO memberDO : list) { + if(memberDO != null) { + Map data = Arrays.stream(SmsCode.values()).collect(Collectors.toMap(SmsCode::getType, SmsCode::getCode)); + smsUtils.send(memberDO.getTelephone(), data.get(classNoticeDO.getNoticeType())); + } } - } - ClassNoticeDO classNoticeDO = new ClassNoticeDO(); - classNoticeDO.setId((Long) params.get("id")); - classNoticeDO.setStatus(CourseNotification.SENT); - classNoticeMapper.updateById(classNoticeDO); + ClassNoticeDO classNotice = new ClassNoticeDO(); + classNotice.setId(classNoticeDO.getId()); + classNotice.setStatus(CourseNotification.SENT); + classNoticeMapper.updateById(classNotice); + } } } } diff --git a/src/main/java/com/subsidy/service/impl/ClassNoticeServiceImpl.java b/src/main/java/com/subsidy/service/impl/ClassNoticeServiceImpl.java index 98805da..62b7c25 100644 --- a/src/main/java/com/subsidy/service/impl/ClassNoticeServiceImpl.java +++ b/src/main/java/com/subsidy/service/impl/ClassNoticeServiceImpl.java @@ -2,6 +2,7 @@ package com.subsidy.service.impl; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.subsidy.common.constant.CourseNotification; +import com.subsidy.common.constant.SmsCode; import com.subsidy.common.exception.HttpException; import com.subsidy.dto.classNotice.SendNotificationDTO; import com.subsidy.jobs.CourseNotificationJob; @@ -60,7 +61,7 @@ public class ClassNoticeServiceImpl extends ServiceImpl params = new HashMap<>(); - //params.put("classId", classNoticeDO.getClassId()); + params.put("classId", classNoticeDO.getClassId()); params.put("id", classNoticeDO.getId()); String name = classDictDO.getClassName()+"-"+classNoticeDO.getNoticeType()+"-"+classNoticeDO.getNoticeTime(); quartzUtil.addSimpleJob(CourseNotificationJob.class,DateFormatUtil.parse(classNoticeDO.getNoticeTime(), "yyyy-MM-dd") , params, name, "CourseNotificationJob"); @@ -93,25 +94,25 @@ public class ClassNoticeServiceImpl extends ServiceImpl list = memberMapper.getMemberList(sendNotificationDTO.getClassId()); if(list != null) { for (MemberDO memberDO : list) { - smsUtils.send(memberDO.getTelephone(), ""); + smsUtils.send(memberDO.getTelephone(), SmsCode.ALL.getCode()); } } - } else if(sendNotificationDTO.getSendType().equals(CourseNotification.NOT_SIGNED_IN)) { + } else if(sendNotificationDTO.getSendType().equals(SmsCode.NOT_SIGNED_IN.getType())) { List list = memberMapper.getMemberListBySignInRecord(sendNotificationDTO.getClassId()); if(list != null) { for (MemberDO memberDO : list) { - smsUtils.send(memberDO.getTelephone(), ""); + smsUtils.send(memberDO.getTelephone(), SmsCode.NOT_SIGNED_IN.getCode()); } } - } else if(sendNotificationDTO.getSendType().equals(CourseNotification.UNFINISHED)) { + } else if(sendNotificationDTO.getSendType().equals(SmsCode.UNFINISHED.getType())) { List list = memberMapper.getUnfinishedMemberList(sendNotificationDTO.getClassId()); if(list != null) { for (MemberDO memberDO : list) { - smsUtils.send(memberDO.getTelephone(), ""); + smsUtils.send(memberDO.getTelephone(), SmsCode.UNFINISHED.getCode()); } } } -- libgit2 0.25.0