Commit 4ffbbe003de5c59bbdec7091bb2573ea0c56e594
1 parent
803c2371ea
Exists in
master
and in
1 other branch
文章推送优化
Showing 7 changed files with 137 additions and 49 deletions
- talkonlineweb/src/main/java/com/lyms/talkonlineweb/domain/LymsPushMessages.java
- talkonlineweb/src/main/java/com/lyms/talkonlineweb/domain/LymsPushedart.java
- talkonlineweb/src/main/java/com/lyms/talkonlineweb/task/PushArticleTask.java
- talkonlineweb/src/main/java/com/lyms/talkonlineweb/task/PushArticleTaskData.java
- talkonlineweb/src/main/java/com/lyms/talkonlineweb/util/Constant.java
- talkonlineweb/src/main/java/com/lyms/talkonlineweb/util/WeiXinUtil.java
- talkonlineweb/src/main/resources/mapper/LymsPushMessagesMapper.xml
talkonlineweb/src/main/java/com/lyms/talkonlineweb/domain/LymsPushMessages.java
View file @
4ffbbe0
... | ... | @@ -34,6 +34,18 @@ |
34 | 34 | private String pname; |
35 | 35 | |
36 | 36 | /** |
37 | + * 患者手机号码,也是登录小程序账号 | |
38 | + */ | |
39 | + @TableField(value = "mobile") | |
40 | + private String mobile; | |
41 | + | |
42 | + /** | |
43 | + * 患者身份证号码 | |
44 | + */ | |
45 | + @TableField(value = "idno") | |
46 | + private String idno; | |
47 | + | |
48 | + /** | |
37 | 49 | * 医院id |
38 | 50 | */ |
39 | 51 | @TableField(value = "hid") |
40 | 52 | |
... | ... | @@ -148,10 +160,10 @@ |
148 | 160 | private Integer pushedartId; |
149 | 161 | |
150 | 162 | /** |
151 | - * 计划推送日期 | |
163 | + * 推送时间 | |
152 | 164 | */ |
153 | - @TableField(value = "plan_time") | |
154 | - private Date planTime; | |
165 | + @TableField(value = "push_time") | |
166 | + private Date pushTime; | |
155 | 167 | |
156 | 168 | /** |
157 | 169 | * 列表筛选条件startDate |
... | ... | @@ -165,6 +177,23 @@ |
165 | 177 | @TableField(exist = false) |
166 | 178 | private String endDate; |
167 | 179 | |
180 | + /** | |
181 | + * 推送状态:0待推送(9点开始推送) 1成功 2失败。(在备注写失败原因) | |
182 | + */ | |
183 | + @TableField(value = "state") | |
184 | + private Integer state; | |
185 | + /** | |
186 | + * 备注 | |
187 | + */ | |
188 | + @TableField(value = "remark") | |
189 | + private String remark; | |
190 | + | |
191 | + /** | |
192 | + * 创建时间 | |
193 | + */ | |
194 | + @TableField(value = "created_time") | |
195 | + private Date createdTime; | |
196 | + | |
168 | 197 | @TableField(exist = false) |
169 | 198 | private static final long serialVersionUID = 1L; |
170 | 199 | |
... | ... | @@ -201,7 +230,7 @@ |
201 | 230 | && (this.getWeixTextTwo() == null ? other.getWeixTextTwo() == null : this.getWeixTextTwo().equals(other.getWeixTextTwo())) |
202 | 231 | && (this.getIsweixinOne() == null ? other.getIsweixinOne() == null : this.getIsweixinOne().equals(other.getIsweixinOne())) |
203 | 232 | && (this.getIsweixinTwo() == null ? other.getIsweixinTwo() == null : this.getIsweixinTwo().equals(other.getIsweixinTwo())) |
204 | - && (this.getPlanTime() == null ? other.getPlanTime() == null : this.getPlanTime().equals(other.getPlanTime())); | |
233 | + && (this.getPushTime() == null ? other.getPushTime() == null : this.getPushTime().equals(other.getPushTime())); | |
205 | 234 | } |
206 | 235 | |
207 | 236 | @Override |
... | ... | @@ -229,7 +258,7 @@ |
229 | 258 | result = prime * result + ((getWeixTextTwo() == null) ? 0 : getWeixTextTwo().hashCode()); |
230 | 259 | result = prime * result + ((getIsweixinOne() == null) ? 0 : getIsweixinOne().hashCode()); |
231 | 260 | result = prime * result + ((getIsweixinTwo() == null) ? 0 : getIsweixinTwo().hashCode()); |
232 | - result = prime * result + ((getPlanTime() == null) ? 0 : getPlanTime().hashCode()); | |
261 | + result = prime * result + ((getPushTime() == null) ? 0 : getPushTime().hashCode()); | |
233 | 262 | return result; |
234 | 263 | } |
235 | 264 | |
... | ... | @@ -260,7 +289,7 @@ |
260 | 289 | sb.append(", weixTextTwo=").append(weixTextTwo); |
261 | 290 | sb.append(", isweixinOne=").append(isweixinOne); |
262 | 291 | sb.append(", isweixinTwo=").append(isweixinTwo); |
263 | - sb.append(", planTime=").append(planTime); | |
292 | + sb.append(", planTime=").append(pushTime); | |
264 | 293 | sb.append(", serialVersionUID=").append(serialVersionUID); |
265 | 294 | sb.append("]"); |
266 | 295 | return sb.toString(); |
talkonlineweb/src/main/java/com/lyms/talkonlineweb/domain/LymsPushedart.java
View file @
4ffbbe0
... | ... | @@ -52,13 +52,13 @@ |
52 | 52 | private Date readtime; |
53 | 53 | |
54 | 54 | /** |
55 | - * 是否推送短消息1(0否,1是) | |
55 | + * 是否推送短消息1(0否,1是 2推送失败) | |
56 | 56 | */ |
57 | 57 | @TableField(value = "isweixin_one") |
58 | 58 | private Integer isweixinone; |
59 | 59 | |
60 | 60 | /** |
61 | - * 是否推送短消息2(0否,1是) | |
61 | + * 是否推送短消息2(0否,1是 2推送失败) | |
62 | 62 | */ |
63 | 63 | @TableField(value = "isweixin_two") |
64 | 64 | private Integer isweixintwo; |
talkonlineweb/src/main/java/com/lyms/talkonlineweb/task/PushArticleTask.java
View file @
4ffbbe0
... | ... | @@ -52,7 +52,7 @@ |
52 | 52 | log.debug("开始给患者推送文章>>>>>>"); |
53 | 53 | //从LymsPushMessages记录表查询今天0点筛选出要推送的文章 |
54 | 54 | QueryWrapper<LymsPushMessages> queryWrapper = new QueryWrapper<>(); |
55 | - queryWrapper.apply("TO_DAYS(plan_time) = TO_DAYS(NOW())"); | |
55 | + queryWrapper.apply("TO_DAYS(created_time) = TO_DAYS(NOW())"); | |
56 | 56 | List<LymsPushMessages> lymsPushMessages=lymsPushMessagesService.list(queryWrapper); |
57 | 57 | for (LymsPushMessages lymsPushMessage : lymsPushMessages) { |
58 | 58 | //推送的文章在LymsPushedart做记录。用于患者读取推送的文章 |
59 | 59 | |
60 | 60 | |
61 | 61 | |
... | ... | @@ -63,11 +63,37 @@ |
63 | 63 | pushedart.setIsread((byte) 0); |
64 | 64 | //PushedartId(如果null表示需要推送文章,否则需要推送短消息) |
65 | 65 | if(null!=lymsPushMessage.getPushedartId()){ |
66 | + //获取token失败 | |
66 | 67 | if(StringUtil.isEmpty(token)){ |
67 | - log.info("推送短消息1,获取token失败。。。"); | |
68 | + //更新到LymsPushMessages记录 | |
69 | + lymsPushMessage.setState(2);//推送状态:0待推送(9点开始推送) 1成功 2失败。(在备注写失败原因) | |
70 | + lymsPushMessage.setRemark("推送短消息"+(lymsPushMessage.getIsweixinOne()==1?"1":"2")+",获取token失败。。。"); | |
71 | + lymsPushMessage.setPushTime(new Date()); | |
72 | + lymsPushMessagesService.updateById(lymsPushMessage); | |
73 | + //更新到LymsPushedart记录 | |
74 | + if(lymsPushMessage.getIsweixinOne()==1){ | |
75 | + pushedart.setIsweixinone(2);//是否推送短消息1(0否,1是 2推送失败) | |
76 | + }else { | |
77 | + pushedart.setIsweixintwo(2);//是否推送短消息2(0否,1是 2推送失败) | |
78 | + } | |
79 | + lymsPushedartService.updateById(pushedart); | |
80 | + log.info("推送短消息"+(lymsPushMessage.getIsweixinOne()==1?"1":"2")+",获取token失败。。。"); | |
68 | 81 | continue; |
69 | 82 | } |
83 | + //公众号openId为空 | |
70 | 84 | if(StringUtil.isEmpty(lymsPushMessage.getGzopenid())){ |
85 | + //更新到LymsPushMessages记录 | |
86 | + lymsPushMessage.setState(2);//推送状态:0待推送(9点开始推送) 1成功 2失败。(在备注写失败原因) | |
87 | + lymsPushMessage.setRemark(lymsPushMessage.getPname()+":公众号openId为空。。。"); | |
88 | + lymsPushMessage.setPushTime(new Date()); | |
89 | + lymsPushMessagesService.updateById(lymsPushMessage); | |
90 | + //更新到LymsPushedart记录 | |
91 | + if(lymsPushMessage.getIsweixinOne()==1){ | |
92 | + pushedart.setIsweixinone(2);//是否推送短消息1(0否,1是 2推送失败) | |
93 | + }else { | |
94 | + pushedart.setIsweixintwo(2);//是否推送短消息2(0否,1是 2推送失败) | |
95 | + } | |
96 | + lymsPushedartService.updateById(pushedart); | |
71 | 97 | log.info(lymsPushMessage.getPname()+":公众号openId为空。。。"); |
72 | 98 | continue; |
73 | 99 | } |
74 | 100 | |
... | ... | @@ -83,11 +109,19 @@ |
83 | 109 | map.put("remark",new DataEntity("预祝您早日康复","#173177")); |
84 | 110 | Integer code= WeiXinUtil.SendWeChatMsg(token,lymsPushMessage.getGzopenid(),template_id,map); |
85 | 111 | if(null==code||code!=0){ |
112 | + //更新到LymsPushMessages记录 | |
113 | + lymsPushMessage.setState(2);//推送状态:0待推送(9点开始推送) 1成功 2失败。(在备注写失败原因) | |
114 | + lymsPushMessage.setRemark("推送短消息1失败。。。"+lymsPushMessage.getPname()+"; code:"+code); | |
115 | + lymsPushMessage.setPushTime(new Date()); | |
116 | + lymsPushMessagesService.updateById(lymsPushMessage); | |
117 | + //更新到LymsPushedart记录 | |
118 | + pushedart.setIsweixinone(2);//是否推送短消息1(0否,1是 2推送失败) | |
119 | + lymsPushedartService.updateById(pushedart); | |
86 | 120 | log.info("推送短消息1失败。。。"+lymsPushMessage.getPname()+"; code:"+code); |
87 | 121 | continue; |
88 | 122 | } |
89 | 123 | //成功标记记录1 |
90 | - pushedart.setIsweixinone(1);//0未推送1已推送 | |
124 | + pushedart.setIsweixinone(1);//是否推送短消息1(0否,1是 2推送失败) | |
91 | 125 | }else if(lymsPushMessage.getIsweixinTwo()==1){ |
92 | 126 | //推送微信消息2 |
93 | 127 | Map<String,Object> map=new HashMap<>(); |
94 | 128 | |
95 | 129 | |
... | ... | @@ -98,25 +132,27 @@ |
98 | 132 | map.put("remark",new DataEntity("预祝您早日康复","#173177")); |
99 | 133 | Integer code= WeiXinUtil.SendWeChatMsg(token,lymsPushMessage.getGzopenid(),template_id,map); |
100 | 134 | if(null==code||code!=0){ |
135 | + //更新到LymsPushMessages记录 | |
136 | + lymsPushMessage.setState(2);//推送状态:0待推送(9点开始推送) 1成功 2失败。(在备注写失败原因) | |
137 | + lymsPushMessage.setRemark("推送短消息2失败。。。"+lymsPushMessage.getPname()+"; code:"+code); | |
138 | + lymsPushMessage.setPushTime(new Date()); | |
139 | + lymsPushMessagesService.updateById(lymsPushMessage); | |
140 | + //更新到LymsPushedart记录 | |
141 | + pushedart.setIsweixintwo(2);//是否推送短消息2(0否,1是 2推送失败) | |
142 | + lymsPushedartService.updateById(pushedart); | |
101 | 143 | log.info("推送短消息2失败。。。"+lymsPushMessage.getPname()+"; code:"+code); |
102 | 144 | continue; |
103 | 145 | } |
104 | 146 | //成功标记记录2 |
105 | - pushedart.setIsweixintwo(1);//0未推送1已推送 | |
147 | + pushedart.setIsweixintwo(1);//是否推送短消息1(0否,1是 2推送失败) | |
106 | 148 | } |
107 | 149 | } |
108 | 150 | //插入or更新到LymsPushedart记录 |
109 | - boolean b = lymsPushedartService.saveOrUpdate(pushedart); | |
110 | - if (b) { | |
111 | - if(null!=pushedart.getIsweixinone()&&pushedart.getIsweixinone()==1){ | |
112 | - log.info("推送短文字1给:" + lymsPushMessage.getPname() + "成功!"); | |
113 | - }else if(null!=pushedart.getIsweixintwo()&&pushedart.getIsweixintwo()==1){ | |
114 | - log.info("推送短文字2给:" + lymsPushMessage.getPname() + "成功!"); | |
115 | - } | |
116 | - log.info("推送文章给:" + lymsPushMessage.getPname() + "成功!"); | |
117 | - } else { | |
118 | - log.info("推送文章给:" + lymsPushMessage.getPname() + "失败:插入or更新到LymsPushedart记录返回false>>>>>>>>>"); | |
119 | - } | |
151 | + lymsPushedartService.saveOrUpdate(pushedart); | |
152 | + //更新到LymsPushMessages记录 | |
153 | + lymsPushMessage.setState(1);//推送状态:0待推送(9点开始推送) 1成功 2失败。(在备注写失败原因) | |
154 | + lymsPushMessage.setPushTime(new Date()); | |
155 | + lymsPushMessagesService.updateById(lymsPushMessage); | |
120 | 156 | } |
121 | 157 | } |
122 | 158 | } |
talkonlineweb/src/main/java/com/lyms/talkonlineweb/task/PushArticleTaskData.java
View file @
4ffbbe0
... | ... | @@ -12,6 +12,7 @@ |
12 | 12 | import lombok.Data; |
13 | 13 | import lombok.extern.log4j.Log4j2; |
14 | 14 | import org.springframework.beans.BeanUtils; |
15 | +import org.springframework.beans.BeansException; | |
15 | 16 | import org.springframework.beans.factory.annotation.Autowired; |
16 | 17 | import org.springframework.scheduling.annotation.Scheduled; |
17 | 18 | import org.springframework.stereotype.Component; |
18 | 19 | |
19 | 20 | |
... | ... | @@ -53,30 +54,34 @@ |
53 | 54 | //筛选出需要推送的文章信息-(逻辑详见视图) |
54 | 55 | List<PushArticle> pushArticleList=pushArticleService.list(); |
55 | 56 | for (PushArticle article : pushArticleList) { |
56 | - //需要推送文章的对象 | |
57 | - LymsPushMessages lymsPushMessages=new LymsPushMessages(); | |
58 | - BeanUtils.copyProperties(article,lymsPushMessages); | |
59 | - //查询推已推送的文章(如果null表示需要推送文章,否则需要推送短消息) | |
60 | - QueryWrapper<LymsPushedart> queryWrapper=new QueryWrapper<>(); | |
61 | - queryWrapper.eq("pid", lymsPushMessages.getPid()); | |
62 | - queryWrapper.eq("aid", lymsPushMessages.getAid()); | |
63 | - LymsPushedart lymsPushedart = lymsPushedartService.getOne(queryWrapper); | |
64 | - if(null!=lymsPushedart){ | |
65 | - //每次只推送一条短消息,判断推送短消息1还是2 | |
66 | - if(lymsPushedart.getIsweixinone()==0){//0未推送1已推送 | |
67 | - //标记要推送的记录需要推送短消息1 | |
68 | - lymsPushMessages.setIsweixinOne(1); | |
69 | - //存入已推送文章列表id | |
70 | - lymsPushMessages.setPushedartId(lymsPushedart.getId()); | |
71 | - }else if (lymsPushedart.getIsweixintwo()==0){//0未推送1已推送 | |
72 | - //标记要推送的记录需要推送短消息2 | |
73 | - lymsPushMessages.setIsweixinTwo(1); | |
74 | - //存入已推送文章列表id | |
75 | - lymsPushMessages.setPushedartId(lymsPushedart.getId()); | |
57 | + try { | |
58 | + //需要推送文章的对象 | |
59 | + LymsPushMessages lymsPushMessages=new LymsPushMessages(); | |
60 | + BeanUtils.copyProperties(article,lymsPushMessages); | |
61 | + //查询推已推送的文章(如果null表示需要推送文章,否则需要推送短消息) | |
62 | + QueryWrapper<LymsPushedart> queryWrapper=new QueryWrapper<>(); | |
63 | + queryWrapper.eq("pid", lymsPushMessages.getPid()); | |
64 | + queryWrapper.eq("aid", lymsPushMessages.getAid()); | |
65 | + LymsPushedart lymsPushedart = lymsPushedartService.getOne(queryWrapper); | |
66 | + if(null!=lymsPushedart){ | |
67 | + //每次只推送一条短消息,判断推送短消息1还是2 | |
68 | + if(lymsPushedart.getIsweixinone()==0){//0未推送1已推送 | |
69 | + //标记要推送的记录需要推送短消息1 | |
70 | + lymsPushMessages.setIsweixinOne(1); | |
71 | + //存入已推送文章列表id | |
72 | + lymsPushMessages.setPushedartId(lymsPushedart.getId()); | |
73 | + }else if (lymsPushedart.getIsweixintwo()==0){//0未推送1已推送 | |
74 | + //标记要推送的记录需要推送短消息2 | |
75 | + lymsPushMessages.setIsweixinTwo(1); | |
76 | + //存入已推送文章列表id | |
77 | + lymsPushMessages.setPushedartId(lymsPushedart.getId()); | |
78 | + } | |
76 | 79 | } |
80 | + //保存到要推送的表lyms_push_messages | |
81 | + lymsPushMessagesService.save(lymsPushMessages); | |
82 | + } catch (BeansException e) { | |
83 | + e.printStackTrace(); | |
77 | 84 | } |
78 | - //保存到要推送的表lyms_push_messages | |
79 | - lymsPushMessagesService.save(lymsPushMessages); | |
80 | 85 | } |
81 | 86 | } |
82 | 87 | } |
talkonlineweb/src/main/java/com/lyms/talkonlineweb/util/Constant.java
View file @
4ffbbe0
... | ... | @@ -54,5 +54,18 @@ |
54 | 54 | * 公众号AppSecret |
55 | 55 | */ |
56 | 56 | public static final String GZ_SECRET ="fc80b5dd03a581a088adcd2c65a7e10a"; |
57 | + /** | |
58 | + * 公众号authorization_code | |
59 | + */ | |
60 | + public static final String GZ_AUTH ="authorization_code"; | |
61 | + /** | |
62 | + * 公众号的appid 测试 | |
63 | + */ | |
64 | + public static final String GZ_APP_ID_CS ="wx7ef7bf809a93b616"; | |
65 | + | |
66 | + /** | |
67 | + * 公众号AppSecret 测试 | |
68 | + */ | |
69 | + public static final String GZ_SECRET_CS ="1c4b5543a54c74dd363a6655ca1cbffe"; | |
57 | 70 | } |
talkonlineweb/src/main/java/com/lyms/talkonlineweb/util/WeiXinUtil.java
View file @
4ffbbe0
... | ... | @@ -95,9 +95,9 @@ |
95 | 95 | } |
96 | 96 | try { |
97 | 97 | // 接口地址 |
98 | - String reqUrl = "https://api.weixin.qq.com/sns/jscode2session?appid=" + Constant.GZ_APP_ID + "&secret=" + Constant.GZ_SECRET + "&js_code=" + code + "&grant_type=authorization_code"; | |
98 | + String reqUrl = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=" + Constant.GZ_APP_ID + "&secret=" + Constant.GZ_SECRET + "&code=" + code + "&grant_type="+Constant.GZ_AUTH; | |
99 | 99 | log.info(reqUrl); |
100 | - String result = repeatDoGetPost(reqUrl, "GET", null); | |
100 | + String result = HttpUtil.getData(reqUrl); | |
101 | 101 | log.info("result :" + result); |
102 | 102 | if (StringUtils.isEmpty(result)) { |
103 | 103 | log.info("取微信用户的公众号openid : 请求返回null..." ); |
talkonlineweb/src/main/resources/mapper/LymsPushMessagesMapper.xml
View file @
4ffbbe0
... | ... | @@ -26,7 +26,12 @@ |
26 | 26 | <result property="weixTextTwo" column="weix_text_two" jdbcType="VARCHAR"/> |
27 | 27 | <result property="isweixinOne" column="isweixin_one" jdbcType="INTEGER"/> |
28 | 28 | <result property="isweixinTwo" column="isweixin_two" jdbcType="INTEGER"/> |
29 | - <result property="planTime" column="plan_time" jdbcType="TIMESTAMP"/> | |
29 | + <result property="pushTime" column="push_time" jdbcType="TIMESTAMP"/> | |
30 | + <result property="state" column="state" jdbcType="INTEGER"/> | |
31 | + <result property="remark" column="remark" jdbcType="VARCHAR"/> | |
32 | + <result property="idno" column="remark" jdbcType="VARCHAR"/> | |
33 | + <result property="mobile" column="remark" jdbcType="VARCHAR"/> | |
34 | + <result property="createdTime" column="created_time" jdbcType="TIMESTAMP"/> | |
30 | 35 | </resultMap> |
31 | 36 | |
32 | 37 | <sql id="Base_Column_List"> |
... | ... | @@ -37,7 +42,7 @@ |
37 | 42 | gzopenid,aid,atitle, |
38 | 43 | acontent,serialNumber,weix_text_one, |
39 | 44 | weix_text_two,isweixin_one,isweixin_two, |
40 | - plan_time | |
45 | + push_time,state,remark,idno,mobile,created_time | |
41 | 46 | </sql> |
42 | 47 | </mapper> |