From 8e0ce28453460c5c8f4ec86c743b86337117df4f Mon Sep 17 00:00:00 2001 From: 陈杰 <504987307@qq.com> Date: Wed, 18 Dec 2019 11:00:37 +0800 Subject: [PATCH] 关注绑定 --- cloud/common/src/main/java/com/sincere/common/dto/smartCampus/BindPushDto.java | 23 +++++++++++++++++------ cloud/common/src/main/java/com/sincere/common/dto/smartCampus/ParentDto.java | 9 --------- cloud/quartz/src/main/java/com/sincere/quartz/job/BindPushJob.java | 69 ++++++++++++++++++++++++++++++++++++++++----------------------------- cloud/quartz/src/main/java/com/sincere/quartz/mapper/SmsMapper.java | 3 +++ cloud/quartz/src/main/java/com/sincere/quartz/model/ShortMsg.java | 47 +++++++++++++++++++++++++++++++++++++++++++++++ cloud/quartz/src/main/resources/mapper/SmsMapper.xml | 5 +++++ cloud/search_smartCampus/src/main/java/com/sincere/smartSearch/controller/RegisterPushController.java | 5 ----- cloud/search_smartCampus/src/main/java/com/sincere/smartSearch/mapper/RegisterPushMapper.java | 2 -- cloud/search_smartCampus/src/main/java/com/sincere/smartSearch/service/RegisterPushService.java | 2 -- cloud/search_smartCampus/src/main/java/com/sincere/smartSearch/service/impl/RegisterPushServiceImpl.java | 5 ----- cloud/search_smartCampus/src/main/resources/mapper/RegisterPushMapper.xml | 35 ++++++++++++----------------------- 11 files changed, 124 insertions(+), 81 deletions(-) create mode 100644 cloud/quartz/src/main/java/com/sincere/quartz/model/ShortMsg.java diff --git a/cloud/common/src/main/java/com/sincere/common/dto/smartCampus/BindPushDto.java b/cloud/common/src/main/java/com/sincere/common/dto/smartCampus/BindPushDto.java index eebd08b..719e8e5 100644 --- a/cloud/common/src/main/java/com/sincere/common/dto/smartCampus/BindPushDto.java +++ b/cloud/common/src/main/java/com/sincere/common/dto/smartCampus/BindPushDto.java @@ -1,5 +1,7 @@ package com.sincere.common.dto.smartCampus; +import java.util.Date; + /** * @author chen * @version 1.0 @@ -8,9 +10,10 @@ package com.sincere.common.dto.smartCampus; public class BindPushDto { private int schoolId ; + private String schoolName ; private int type ; // 0是企业号,1是钉钉 - private String beginDate ; - private String endDate ; + private Date beginDate ; + private Date endDate ; private int intervalDays ; private String pushTime ; private String msg ; @@ -23,6 +26,14 @@ public class BindPushDto { this.schoolId = schoolId; } + public String getSchoolName() { + return schoolName; + } + + public void setSchoolName(String schoolName) { + this.schoolName = schoolName; + } + public int getType() { return type; } @@ -31,19 +42,19 @@ public class BindPushDto { this.type = type; } - public String getBeginDate() { + public Date getBeginDate() { return beginDate; } - public void setBeginDate(String beginDate) { + public void setBeginDate(Date beginDate) { this.beginDate = beginDate; } - public String getEndDate() { + public Date getEndDate() { return endDate; } - public void setEndDate(String endDate) { + public void setEndDate(Date endDate) { this.endDate = endDate; } diff --git a/cloud/common/src/main/java/com/sincere/common/dto/smartCampus/ParentDto.java b/cloud/common/src/main/java/com/sincere/common/dto/smartCampus/ParentDto.java index faef716..69bad44 100644 --- a/cloud/common/src/main/java/com/sincere/common/dto/smartCampus/ParentDto.java +++ b/cloud/common/src/main/java/com/sincere/common/dto/smartCampus/ParentDto.java @@ -8,7 +8,6 @@ package com.sincere.common.dto.smartCampus; public class ParentDto { private int schoolId ; - private int parentId ; private String mobile ; public int getSchoolId() { @@ -19,14 +18,6 @@ public class ParentDto { this.schoolId = schoolId; } - public int getParentId() { - return parentId; - } - - public void setParentId(int parentId) { - this.parentId = parentId; - } - public String getMobile() { return mobile; } diff --git a/cloud/quartz/src/main/java/com/sincere/quartz/job/BindPushJob.java b/cloud/quartz/src/main/java/com/sincere/quartz/job/BindPushJob.java index cf9b4f5..d813650 100644 --- a/cloud/quartz/src/main/java/com/sincere/quartz/job/BindPushJob.java +++ b/cloud/quartz/src/main/java/com/sincere/quartz/job/BindPushJob.java @@ -5,7 +5,11 @@ import com.sincere.common.dto.smartCampus.ParentDto; import com.sincere.common.enums.PushTypeEnums; import com.sincere.common.util.DateUtils; import com.sincere.quartz.feign.ScFeign; +import com.sincere.quartz.mapper.SmsMapper; +import com.sincere.quartz.model.ShortMsg; import org.apache.commons.lang3.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Service; @@ -21,26 +25,24 @@ import java.util.*; @Service public class BindPushJob { + private Logger logger = LoggerFactory.getLogger(KQJob.class); + + @Autowired ScFeign scFeign; - private static String date ; - private static List schoolList = new ArrayList<>(); - private static Map intervalDaysMap = new HashMap<>(); + @Autowired + SmsMapper smsMapper; + + private static Map intervalDaysMap = new HashMap<>(); //redis 持久化 替换 可避免重启导致间隔的错误 @Scheduled(cron = "0 0-59 * * * ? ") public void bindPush(){ Date nowDate = new Date(); - String now = DateUtils.date2String(nowDate,DateUtils.format1) ; - if(StringUtils.isBlank(date) || !date.equals(now)){ - initMap(now); - } + List schoolList = scFeign.selectBindPushSchool(); for(BindPushDto school : schoolList){ - int i =DateUtils.string2Date(school.getBeginDate(),DateUtils.format1).compareTo(nowDate) ; - int j = DateUtils.string2Date(school.getEndDate(),DateUtils.format1).compareTo(nowDate) ; - if(DateUtils.string2Date(school.getBeginDate(),DateUtils.format1).compareTo(nowDate) <= 0 - && DateUtils.string2Date(school.getEndDate(),DateUtils.format1).compareTo(nowDate) >= 0){ - String lastDate = intervalDaysMap.get(school.getSchoolId()); + if(school.getBeginDate().compareTo(nowDate) <= 0 && school.getEndDate().compareTo(nowDate) >= 0){ + String lastDate = intervalDaysMap.get(school.getSchoolId()+"_"+school.getType()); if(StringUtils.isBlank(lastDate)){ //下发推送 bindPush(school,nowDate); @@ -57,33 +59,42 @@ public class BindPushJob { private void bindPush(BindPushDto bindPushDto , Date nowDate){ if(bindPushDto.getPushTime().equals(DateUtils.date2String(nowDate,DateUtils.format4))){ + intervalDaysMap.put(bindPushDto.getSchoolId()+"_"+bindPushDto.getType(),DateUtils.date2String(nowDate,DateUtils.format1)); + //未关注 List unFollowList = scFeign.selectNotFollow(bindPushDto.getSchoolId()); + logger.info(bindPushDto.getSchoolName()+"未关注人数"+unFollowList.size()); + for(ParentDto parentDto : unFollowList){ + sendMessage(parentDto,bindPushDto.getMsg()); + } + //未绑定 List unBindList =scFeign.selectNotBind(bindPushDto.getSchoolId(),getThirdType(bindPushDto.getType())); - - intervalDaysMap.put(bindPushDto.getSchoolId(),DateUtils.date2String(nowDate,DateUtils.format1)); + logger.info(bindPushDto.getSchoolName()+"未绑定人数"+unBindList.size()); + for(ParentDto parentDto : unBindList){ + sendMessage(parentDto,bindPushDto.getMsg()); + } } } - private void initMap(String now){ - date = now ; - //schoolList = scFeign.selectBindPushSchool(); - BindPushDto bindPushDto = new BindPushDto(); - bindPushDto.setSchoolId(16); - bindPushDto.setBeginDate("2019-12-04"); - bindPushDto.setEndDate("2019-12-30"); - bindPushDto.setIntervalDays(1); - bindPushDto.setPushTime("11:04"); - bindPushDto.setType(0); - bindPushDto.setMsg(""); - schoolList = new ArrayList<>(); - schoolList.add(bindPushDto); + private void sendMessage(ParentDto parentDto , String message){ + //手机号为空 + if(StringUtils.isNotBlank(parentDto.getMobile())){ + String tableSuffix = DateUtils.date2String(new Date(), DateUtils.format); + ShortMsg shortMsg = new ShortMsg(); + shortMsg.setTableName("smsNew"+tableSuffix); + shortMsg.setSchoolId(parentDto.getSchoolId()); + shortMsg.setMobile(parentDto.getMobile()); + shortMsg.setMsg(message); + //smsMapper.insertSMS(shortMsg); + logger.info("----学校Id---"+parentDto.getSchoolId() + "----手机号----"+parentDto.getMobile()+"---"+message); + } } + // 0是企业号,1是钉钉 private int getThirdType(int type){ if(type == 0){ - return PushTypeEnums.DING.getType() ; - }else { return PushTypeEnums.QIYEHAO.getType() ; + }else { + return PushTypeEnums.DING.getType() ; } } diff --git a/cloud/quartz/src/main/java/com/sincere/quartz/mapper/SmsMapper.java b/cloud/quartz/src/main/java/com/sincere/quartz/mapper/SmsMapper.java index 27ecb3a..0aaf032 100644 --- a/cloud/quartz/src/main/java/com/sincere/quartz/mapper/SmsMapper.java +++ b/cloud/quartz/src/main/java/com/sincere/quartz/mapper/SmsMapper.java @@ -1,6 +1,7 @@ package com.sincere.quartz.mapper; import com.sincere.quartz.model.DingSms; +import com.sincere.quartz.model.ShortMsg; import com.sincere.quartz.model.WeChatSms; /** @@ -13,4 +14,6 @@ public interface SmsMapper { int insertDing(DingSms dingSms); int insertWeChat(WeChatSms weChatSms); + + int insertSMS(ShortMsg shortMsg); } diff --git a/cloud/quartz/src/main/java/com/sincere/quartz/model/ShortMsg.java b/cloud/quartz/src/main/java/com/sincere/quartz/model/ShortMsg.java new file mode 100644 index 0000000..4d30394 --- /dev/null +++ b/cloud/quartz/src/main/java/com/sincere/quartz/model/ShortMsg.java @@ -0,0 +1,47 @@ +package com.sincere.quartz.model; + +/** + * @author chen + * @version 1.0 + * @date 2019/12/13 0013 13:54 + */ +public class ShortMsg { + + private String tableName ; + + private int schoolId ; + private String mobile ; + private String msg ; + + public String getTableName() { + return tableName; + } + + public void setTableName(String tableName) { + this.tableName = tableName; + } + + public int getSchoolId() { + return schoolId; + } + + public void setSchoolId(int schoolId) { + this.schoolId = schoolId; + } + + public String getMobile() { + return mobile; + } + + public void setMobile(String mobile) { + this.mobile = mobile; + } + + public String getMsg() { + return msg; + } + + public void setMsg(String msg) { + this.msg = msg; + } +} diff --git a/cloud/quartz/src/main/resources/mapper/SmsMapper.xml b/cloud/quartz/src/main/resources/mapper/SmsMapper.xml index 8cd5a99..d958f48 100644 --- a/cloud/quartz/src/main/resources/mapper/SmsMapper.xml +++ b/cloud/quartz/src/main/resources/mapper/SmsMapper.xml @@ -11,4 +11,9 @@ insert into ${tableName} (SchoolID,MsgID,Guid,WapUrl,Status,intime,sendTime,SendUserName,ReceiveUserID,QiYeHaoUserId,AppID,Secret,tdtype,Remark) values (#{schoolId},-1,#{msg},#{msgUrl},0,GETDATE(),GETDATE(),'智能校卫',#{receiveUserId},#{qiYeHaoUserId},#{appId},#{secret},#{tdType},#{name}) + + + insert into ${tableName} (SchoolID,Mobile,Msg,tdtype,Status,IsNeedSend,SendTime,intime) + values (#{schoolId},#{mobile},#{msg},1,0,1,GETDATE(),GETDATE()) + diff --git a/cloud/search_smartCampus/src/main/java/com/sincere/smartSearch/controller/RegisterPushController.java b/cloud/search_smartCampus/src/main/java/com/sincere/smartSearch/controller/RegisterPushController.java index 20d2fea..c948896 100644 --- a/cloud/search_smartCampus/src/main/java/com/sincere/smartSearch/controller/RegisterPushController.java +++ b/cloud/search_smartCampus/src/main/java/com/sincere/smartSearch/controller/RegisterPushController.java @@ -35,11 +35,6 @@ public class RegisterPushController { return registerPushService.selectNotFollow(schoolId); } - @RequestMapping(value = "selectFollow",method = RequestMethod.GET) - List selectFollow(@RequestParam("schoolId") int schoolId){ - return registerPushService.selectFollow(schoolId); - } - @RequestMapping(value = "selectNotBind",method = RequestMethod.GET) List selectNotBind(@RequestParam("schoolId") int schoolId , @RequestParam("type") int type){ Map map = new HashMap<>(); diff --git a/cloud/search_smartCampus/src/main/java/com/sincere/smartSearch/mapper/RegisterPushMapper.java b/cloud/search_smartCampus/src/main/java/com/sincere/smartSearch/mapper/RegisterPushMapper.java index 5d6004f..13de594 100644 --- a/cloud/search_smartCampus/src/main/java/com/sincere/smartSearch/mapper/RegisterPushMapper.java +++ b/cloud/search_smartCampus/src/main/java/com/sincere/smartSearch/mapper/RegisterPushMapper.java @@ -17,7 +17,5 @@ public interface RegisterPushMapper { List selectNotFollow(int schoolId) ; - List selectFollow(int schoolId) ; - List selectNotBind(Map map); } diff --git a/cloud/search_smartCampus/src/main/java/com/sincere/smartSearch/service/RegisterPushService.java b/cloud/search_smartCampus/src/main/java/com/sincere/smartSearch/service/RegisterPushService.java index 85f411e..9cd4fa8 100644 --- a/cloud/search_smartCampus/src/main/java/com/sincere/smartSearch/service/RegisterPushService.java +++ b/cloud/search_smartCampus/src/main/java/com/sincere/smartSearch/service/RegisterPushService.java @@ -17,7 +17,5 @@ public interface RegisterPushService { List selectNotFollow(int schoolId) ; - List selectFollow(int schoolId) ; - List selectNotBind(Map map); } diff --git a/cloud/search_smartCampus/src/main/java/com/sincere/smartSearch/service/impl/RegisterPushServiceImpl.java b/cloud/search_smartCampus/src/main/java/com/sincere/smartSearch/service/impl/RegisterPushServiceImpl.java index 579a290..aa41e22 100644 --- a/cloud/search_smartCampus/src/main/java/com/sincere/smartSearch/service/impl/RegisterPushServiceImpl.java +++ b/cloud/search_smartCampus/src/main/java/com/sincere/smartSearch/service/impl/RegisterPushServiceImpl.java @@ -32,11 +32,6 @@ public class RegisterPushServiceImpl implements RegisterPushService { } @Override - public List selectFollow(int schoolId) { - return registerPushMapper.selectFollow(schoolId); - } - - @Override public List selectNotBind(Map map) { return registerPushMapper.selectNotBind(map); } diff --git a/cloud/search_smartCampus/src/main/resources/mapper/RegisterPushMapper.xml b/cloud/search_smartCampus/src/main/resources/mapper/RegisterPushMapper.xml index 3faa5b1..6d88799 100644 --- a/cloud/search_smartCampus/src/main/resources/mapper/RegisterPushMapper.xml +++ b/cloud/search_smartCampus/src/main/resources/mapper/RegisterPushMapper.xml @@ -4,6 +4,7 @@ + @@ -13,44 +14,32 @@ - - + - - - + SELECT SZ_V_School_Parent.school_id , SZ_V_School_Parent.mobile FROM SZ_V_School_Parent + WHERE school_id = #{schoolId} and ( DingUserId is null or DingUserId = '' ) -- libgit2 0.21.0