Commit 8e0ce28453460c5c8f4ec86c743b86337117df4f
1 parent
fd11d1a7
Exists in
master
关注绑定
Showing
11 changed files
with
124 additions
and
81 deletions
Show diff stats
cloud/common/src/main/java/com/sincere/common/dto/smartCampus/BindPushDto.java
1 | 1 | package com.sincere.common.dto.smartCampus; |
2 | 2 | |
3 | +import java.util.Date; | |
4 | + | |
3 | 5 | /** |
4 | 6 | * @author chen |
5 | 7 | * @version 1.0 |
... | ... | @@ -8,9 +10,10 @@ package com.sincere.common.dto.smartCampus; |
8 | 10 | public class BindPushDto { |
9 | 11 | |
10 | 12 | private int schoolId ; |
13 | + private String schoolName ; | |
11 | 14 | private int type ; // 0是企业号,1是钉钉 |
12 | - private String beginDate ; | |
13 | - private String endDate ; | |
15 | + private Date beginDate ; | |
16 | + private Date endDate ; | |
14 | 17 | private int intervalDays ; |
15 | 18 | private String pushTime ; |
16 | 19 | private String msg ; |
... | ... | @@ -23,6 +26,14 @@ public class BindPushDto { |
23 | 26 | this.schoolId = schoolId; |
24 | 27 | } |
25 | 28 | |
29 | + public String getSchoolName() { | |
30 | + return schoolName; | |
31 | + } | |
32 | + | |
33 | + public void setSchoolName(String schoolName) { | |
34 | + this.schoolName = schoolName; | |
35 | + } | |
36 | + | |
26 | 37 | public int getType() { |
27 | 38 | return type; |
28 | 39 | } |
... | ... | @@ -31,19 +42,19 @@ public class BindPushDto { |
31 | 42 | this.type = type; |
32 | 43 | } |
33 | 44 | |
34 | - public String getBeginDate() { | |
45 | + public Date getBeginDate() { | |
35 | 46 | return beginDate; |
36 | 47 | } |
37 | 48 | |
38 | - public void setBeginDate(String beginDate) { | |
49 | + public void setBeginDate(Date beginDate) { | |
39 | 50 | this.beginDate = beginDate; |
40 | 51 | } |
41 | 52 | |
42 | - public String getEndDate() { | |
53 | + public Date getEndDate() { | |
43 | 54 | return endDate; |
44 | 55 | } |
45 | 56 | |
46 | - public void setEndDate(String endDate) { | |
57 | + public void setEndDate(Date endDate) { | |
47 | 58 | this.endDate = endDate; |
48 | 59 | } |
49 | 60 | ... | ... |
cloud/common/src/main/java/com/sincere/common/dto/smartCampus/ParentDto.java
... | ... | @@ -8,7 +8,6 @@ package com.sincere.common.dto.smartCampus; |
8 | 8 | public class ParentDto { |
9 | 9 | |
10 | 10 | private int schoolId ; |
11 | - private int parentId ; | |
12 | 11 | private String mobile ; |
13 | 12 | |
14 | 13 | public int getSchoolId() { |
... | ... | @@ -19,14 +18,6 @@ public class ParentDto { |
19 | 18 | this.schoolId = schoolId; |
20 | 19 | } |
21 | 20 | |
22 | - public int getParentId() { | |
23 | - return parentId; | |
24 | - } | |
25 | - | |
26 | - public void setParentId(int parentId) { | |
27 | - this.parentId = parentId; | |
28 | - } | |
29 | - | |
30 | 21 | public String getMobile() { |
31 | 22 | return mobile; |
32 | 23 | } | ... | ... |
cloud/quartz/src/main/java/com/sincere/quartz/job/BindPushJob.java
... | ... | @@ -5,7 +5,11 @@ import com.sincere.common.dto.smartCampus.ParentDto; |
5 | 5 | import com.sincere.common.enums.PushTypeEnums; |
6 | 6 | import com.sincere.common.util.DateUtils; |
7 | 7 | import com.sincere.quartz.feign.ScFeign; |
8 | +import com.sincere.quartz.mapper.SmsMapper; | |
9 | +import com.sincere.quartz.model.ShortMsg; | |
8 | 10 | import org.apache.commons.lang3.StringUtils; |
11 | +import org.slf4j.Logger; | |
12 | +import org.slf4j.LoggerFactory; | |
9 | 13 | import org.springframework.beans.factory.annotation.Autowired; |
10 | 14 | import org.springframework.scheduling.annotation.Scheduled; |
11 | 15 | import org.springframework.stereotype.Service; |
... | ... | @@ -21,26 +25,24 @@ import java.util.*; |
21 | 25 | @Service |
22 | 26 | public class BindPushJob { |
23 | 27 | |
28 | + private Logger logger = LoggerFactory.getLogger(KQJob.class); | |
29 | + | |
30 | + | |
24 | 31 | @Autowired |
25 | 32 | ScFeign scFeign; |
26 | 33 | |
27 | - private static String date ; | |
28 | - private static List<BindPushDto> schoolList = new ArrayList<>(); | |
29 | - private static Map<Integer , String> intervalDaysMap = new HashMap<>(); | |
34 | + @Autowired | |
35 | + SmsMapper smsMapper; | |
36 | + | |
37 | + private static Map<String , String> intervalDaysMap = new HashMap<>(); //redis 持久化 替换 可避免重启导致间隔的错误 | |
30 | 38 | |
31 | 39 | @Scheduled(cron = "0 0-59 * * * ? ") |
32 | 40 | public void bindPush(){ |
33 | 41 | Date nowDate = new Date(); |
34 | - String now = DateUtils.date2String(nowDate,DateUtils.format1) ; | |
35 | - if(StringUtils.isBlank(date) || !date.equals(now)){ | |
36 | - initMap(now); | |
37 | - } | |
42 | + List<BindPushDto> schoolList = scFeign.selectBindPushSchool(); | |
38 | 43 | for(BindPushDto school : schoolList){ |
39 | - int i =DateUtils.string2Date(school.getBeginDate(),DateUtils.format1).compareTo(nowDate) ; | |
40 | - int j = DateUtils.string2Date(school.getEndDate(),DateUtils.format1).compareTo(nowDate) ; | |
41 | - if(DateUtils.string2Date(school.getBeginDate(),DateUtils.format1).compareTo(nowDate) <= 0 | |
42 | - && DateUtils.string2Date(school.getEndDate(),DateUtils.format1).compareTo(nowDate) >= 0){ | |
43 | - String lastDate = intervalDaysMap.get(school.getSchoolId()); | |
44 | + if(school.getBeginDate().compareTo(nowDate) <= 0 && school.getEndDate().compareTo(nowDate) >= 0){ | |
45 | + String lastDate = intervalDaysMap.get(school.getSchoolId()+"_"+school.getType()); | |
44 | 46 | if(StringUtils.isBlank(lastDate)){ |
45 | 47 | //下发推送 |
46 | 48 | bindPush(school,nowDate); |
... | ... | @@ -57,33 +59,42 @@ public class BindPushJob { |
57 | 59 | |
58 | 60 | private void bindPush(BindPushDto bindPushDto , Date nowDate){ |
59 | 61 | if(bindPushDto.getPushTime().equals(DateUtils.date2String(nowDate,DateUtils.format4))){ |
62 | + intervalDaysMap.put(bindPushDto.getSchoolId()+"_"+bindPushDto.getType(),DateUtils.date2String(nowDate,DateUtils.format1)); | |
63 | + //未关注 | |
60 | 64 | List<ParentDto> unFollowList = scFeign.selectNotFollow(bindPushDto.getSchoolId()); |
65 | + logger.info(bindPushDto.getSchoolName()+"未关注人数"+unFollowList.size()); | |
66 | + for(ParentDto parentDto : unFollowList){ | |
67 | + sendMessage(parentDto,bindPushDto.getMsg()); | |
68 | + } | |
69 | + //未绑定 | |
61 | 70 | List<ParentDto> unBindList =scFeign.selectNotBind(bindPushDto.getSchoolId(),getThirdType(bindPushDto.getType())); |
62 | - | |
63 | - intervalDaysMap.put(bindPushDto.getSchoolId(),DateUtils.date2String(nowDate,DateUtils.format1)); | |
71 | + logger.info(bindPushDto.getSchoolName()+"未绑定人数"+unBindList.size()); | |
72 | + for(ParentDto parentDto : unBindList){ | |
73 | + sendMessage(parentDto,bindPushDto.getMsg()); | |
74 | + } | |
64 | 75 | } |
65 | 76 | } |
66 | 77 | |
67 | - private void initMap(String now){ | |
68 | - date = now ; | |
69 | - //schoolList = scFeign.selectBindPushSchool(); | |
70 | - BindPushDto bindPushDto = new BindPushDto(); | |
71 | - bindPushDto.setSchoolId(16); | |
72 | - bindPushDto.setBeginDate("2019-12-04"); | |
73 | - bindPushDto.setEndDate("2019-12-30"); | |
74 | - bindPushDto.setIntervalDays(1); | |
75 | - bindPushDto.setPushTime("11:04"); | |
76 | - bindPushDto.setType(0); | |
77 | - bindPushDto.setMsg(""); | |
78 | - schoolList = new ArrayList<>(); | |
79 | - schoolList.add(bindPushDto); | |
78 | + private void sendMessage(ParentDto parentDto , String message){ | |
79 | + //手机号为空 | |
80 | + if(StringUtils.isNotBlank(parentDto.getMobile())){ | |
81 | + String tableSuffix = DateUtils.date2String(new Date(), DateUtils.format); | |
82 | + ShortMsg shortMsg = new ShortMsg(); | |
83 | + shortMsg.setTableName("smsNew"+tableSuffix); | |
84 | + shortMsg.setSchoolId(parentDto.getSchoolId()); | |
85 | + shortMsg.setMobile(parentDto.getMobile()); | |
86 | + shortMsg.setMsg(message); | |
87 | + //smsMapper.insertSMS(shortMsg); | |
88 | + logger.info("----学校Id---"+parentDto.getSchoolId() + "----手机号----"+parentDto.getMobile()+"---"+message); | |
89 | + } | |
80 | 90 | } |
81 | 91 | |
92 | + // 0是企业号,1是钉钉 | |
82 | 93 | private int getThirdType(int type){ |
83 | 94 | if(type == 0){ |
84 | - return PushTypeEnums.DING.getType() ; | |
85 | - }else { | |
86 | 95 | return PushTypeEnums.QIYEHAO.getType() ; |
96 | + }else { | |
97 | + return PushTypeEnums.DING.getType() ; | |
87 | 98 | } |
88 | 99 | } |
89 | 100 | ... | ... |
cloud/quartz/src/main/java/com/sincere/quartz/mapper/SmsMapper.java
1 | 1 | package com.sincere.quartz.mapper; |
2 | 2 | |
3 | 3 | import com.sincere.quartz.model.DingSms; |
4 | +import com.sincere.quartz.model.ShortMsg; | |
4 | 5 | import com.sincere.quartz.model.WeChatSms; |
5 | 6 | |
6 | 7 | /** |
... | ... | @@ -13,4 +14,6 @@ public interface SmsMapper { |
13 | 14 | int insertDing(DingSms dingSms); |
14 | 15 | |
15 | 16 | int insertWeChat(WeChatSms weChatSms); |
17 | + | |
18 | + int insertSMS(ShortMsg shortMsg); | |
16 | 19 | } | ... | ... |
cloud/quartz/src/main/java/com/sincere/quartz/model/ShortMsg.java
0 → 100644
... | ... | @@ -0,0 +1,47 @@ |
1 | +package com.sincere.quartz.model; | |
2 | + | |
3 | +/** | |
4 | + * @author chen | |
5 | + * @version 1.0 | |
6 | + * @date 2019/12/13 0013 13:54 | |
7 | + */ | |
8 | +public class ShortMsg { | |
9 | + | |
10 | + private String tableName ; | |
11 | + | |
12 | + private int schoolId ; | |
13 | + private String mobile ; | |
14 | + private String msg ; | |
15 | + | |
16 | + public String getTableName() { | |
17 | + return tableName; | |
18 | + } | |
19 | + | |
20 | + public void setTableName(String tableName) { | |
21 | + this.tableName = tableName; | |
22 | + } | |
23 | + | |
24 | + public int getSchoolId() { | |
25 | + return schoolId; | |
26 | + } | |
27 | + | |
28 | + public void setSchoolId(int schoolId) { | |
29 | + this.schoolId = schoolId; | |
30 | + } | |
31 | + | |
32 | + public String getMobile() { | |
33 | + return mobile; | |
34 | + } | |
35 | + | |
36 | + public void setMobile(String mobile) { | |
37 | + this.mobile = mobile; | |
38 | + } | |
39 | + | |
40 | + public String getMsg() { | |
41 | + return msg; | |
42 | + } | |
43 | + | |
44 | + public void setMsg(String msg) { | |
45 | + this.msg = msg; | |
46 | + } | |
47 | +} | ... | ... |
cloud/quartz/src/main/resources/mapper/SmsMapper.xml
... | ... | @@ -11,4 +11,9 @@ |
11 | 11 | insert into ${tableName} (SchoolID,MsgID,Guid,WapUrl,Status,intime,sendTime,SendUserName,ReceiveUserID,QiYeHaoUserId,AppID,Secret,tdtype,Remark) |
12 | 12 | values (#{schoolId},-1,#{msg},#{msgUrl},0,GETDATE(),GETDATE(),'智能校卫',#{receiveUserId},#{qiYeHaoUserId},#{appId},#{secret},#{tdType},#{name}) |
13 | 13 | </insert> |
14 | + | |
15 | + <insert id="insertSMS" parameterType="com.sincere.quartz.model.ShortMsg"> | |
16 | + insert into ${tableName} (SchoolID,Mobile,Msg,tdtype,Status,IsNeedSend,SendTime,intime) | |
17 | + values (#{schoolId},#{mobile},#{msg},1,0,1,GETDATE(),GETDATE()) | |
18 | + </insert> | |
14 | 19 | </mapper> | ... | ... |
cloud/search_smartCampus/src/main/java/com/sincere/smartSearch/controller/RegisterPushController.java
... | ... | @@ -35,11 +35,6 @@ public class RegisterPushController { |
35 | 35 | return registerPushService.selectNotFollow(schoolId); |
36 | 36 | } |
37 | 37 | |
38 | - @RequestMapping(value = "selectFollow",method = RequestMethod.GET) | |
39 | - List<ParentDto> selectFollow(@RequestParam("schoolId") int schoolId){ | |
40 | - return registerPushService.selectFollow(schoolId); | |
41 | - } | |
42 | - | |
43 | 38 | @RequestMapping(value = "selectNotBind",method = RequestMethod.GET) |
44 | 39 | List<ParentDto> selectNotBind(@RequestParam("schoolId") int schoolId , @RequestParam("type") int type){ |
45 | 40 | Map<String , Integer> map = new HashMap<>(); | ... | ... |
cloud/search_smartCampus/src/main/java/com/sincere/smartSearch/mapper/RegisterPushMapper.java
cloud/search_smartCampus/src/main/java/com/sincere/smartSearch/service/RegisterPushService.java
cloud/search_smartCampus/src/main/java/com/sincere/smartSearch/service/impl/RegisterPushServiceImpl.java
... | ... | @@ -32,11 +32,6 @@ public class RegisterPushServiceImpl implements RegisterPushService { |
32 | 32 | } |
33 | 33 | |
34 | 34 | @Override |
35 | - public List<ParentDto> selectFollow(int schoolId) { | |
36 | - return registerPushMapper.selectFollow(schoolId); | |
37 | - } | |
38 | - | |
39 | - @Override | |
40 | 35 | public List<ParentDto> selectNotBind(Map<String, Integer> map) { |
41 | 36 | return registerPushMapper.selectNotBind(map); |
42 | 37 | } | ... | ... |
cloud/search_smartCampus/src/main/resources/mapper/RegisterPushMapper.xml
... | ... | @@ -4,6 +4,7 @@ |
4 | 4 | |
5 | 5 | <resultMap id="BindPushDto" type="com.sincere.common.dto.smartCampus.BindPushDto" > |
6 | 6 | <result column="SchoolId" property="schoolId" /> |
7 | + <result column="SchoolName" property="schoolName" /> | |
7 | 8 | <result column="type" property="type" /> |
8 | 9 | <result column="BeginDate" property="beginDate" /> |
9 | 10 | <result column="EndDate" property="endDate" /> |
... | ... | @@ -13,44 +14,32 @@ |
13 | 14 | </resultMap> |
14 | 15 | |
15 | 16 | <select id="selectBindPushSchool" resultType="java.lang.Integer" resultMap="BindPushDto"> |
16 | - select SchoolId , type , BeginDate , EndDate , IntervalDays. PushTime , Msg from EM_QYHID where isPush = 1 | |
17 | + select SchoolId , SchoolName , type , BeginDate , EndDate , IntervalDays , PushTime , Msg from EM_QYHID where isPush = 1 | |
17 | 18 | </select> |
18 | 19 | |
19 | 20 | |
20 | 21 | <resultMap id="ParentMap" type="com.sincere.common.dto.smartCampus.ParentDto"> |
21 | - <result column="parent_id" property="parentId"/> | |
22 | 22 | <result column="school_id" property="schoolId"/> |
23 | - <result column="mobile" property="mobile"/> | |
23 | + <result column="ParentMobile" property="mobile"/> | |
24 | 24 | </resultMap> |
25 | 25 | |
26 | 26 | <select id="selectNotFollow" parameterType="java.lang.Integer" resultMap="ParentMap"> |
27 | - SELECT SZ_V_School_Parent.parent_id , SZ_V_School_Parent.school_id , SZ_V_School_Parent.mobile FROM SZ_V_School_Parent WHERE not EXISTS | |
27 | + SELECT SZ_V_School_Student.school_id , SZ_V_School_Student.ParentMobile FROM SZ_V_School_Student WHERE not EXISTS | |
28 | 28 | (SELECT NULL |
29 | - FROM SZ_V_School_Student | |
29 | + FROM SZ_V_School_Parent | |
30 | 30 | WHERE SZ_V_School_Parent.class_id = SZ_V_School_Student.class_id |
31 | 31 | AND SZ_V_School_Parent.parent_mobile = SZ_V_School_Student.ParentMobile |
32 | 32 | ) |
33 | 33 | and school_id = #{schoolId} |
34 | 34 | </select> |
35 | 35 | |
36 | - <select id="selectFollow" parameterType="java.lang.Integer" resultMap="ParentMap"> | |
37 | - SELECT SZ_V_School_Parent.parent_id , SZ_V_School_Parent.school_id , SZ_V_School_Parent.mobile FROM SZ_V_School_Parent WHERE EXISTS | |
38 | - (SELECT NULL | |
39 | - FROM SZ_V_School_Student | |
40 | - WHERE SZ_V_School_Parent.class_id = SZ_V_School_Student.class_id | |
41 | - AND SZ_V_School_Parent.parent_mobile = SZ_V_School_Student.ParentMobile | |
42 | - ) | |
43 | - and school_id = #{schoolId} | |
44 | - </select> | |
45 | - | |
46 | - <select id="selectNotBind" parameterType="java.util.Map" resultMap="ParentMap"> | |
47 | - SELECT SZ_V_School_Parent.parent_id , SZ_V_School_Parent.school_id , SZ_V_School_Parent.mobile FROM SZ_V_School_Parent WHERE EXISTS | |
48 | - (SELECT NULL | |
49 | - FROM SZ_V_School_Student | |
50 | - WHERE SZ_V_School_Parent.class_id = SZ_V_School_Student.class_id | |
51 | - AND SZ_V_School_Parent.parent_mobile = SZ_V_School_Student.ParentMobile | |
52 | - ) | |
53 | - and school_id = #{schoolId} | |
36 | + <resultMap id="ParentMap2" type="com.sincere.common.dto.smartCampus.ParentDto"> | |
37 | + <result column="school_id" property="schoolId"/> | |
38 | + <result column="mobile" property="mobile"/> | |
39 | + </resultMap> | |
40 | + <select id="selectNotBind" parameterType="java.util.Map" resultMap="ParentMap2"> | |
41 | + SELECT SZ_V_School_Parent.school_id , SZ_V_School_Parent.mobile FROM SZ_V_School_Parent | |
42 | + WHERE school_id = #{schoolId} | |
54 | 43 | <if test="type == 4"> |
55 | 44 | and ( DingUserId is null or DingUserId = '' ) |
56 | 45 | </if> | ... | ... |