diff --git a/talkonlineweb/src/main/java/com/lyms/talkonlineweb/domain/LymsPushMessages.java b/talkonlineweb/src/main/java/com/lyms/talkonlineweb/domain/LymsPushMessages.java index d044620..ecaa040 100644 --- a/talkonlineweb/src/main/java/com/lyms/talkonlineweb/domain/LymsPushMessages.java +++ b/talkonlineweb/src/main/java/com/lyms/talkonlineweb/domain/LymsPushMessages.java @@ -34,6 +34,18 @@ public class LymsPushMessages implements Serializable { private String pname; /** + * 患者手机号码,也是登录小程序账号 + */ + @TableField(value = "mobile") + private String mobile; + + /** + * 患者身份证号码 + */ + @TableField(value = "idno") + private String idno; + + /** * 医院id */ @TableField(value = "hid") @@ -148,10 +160,10 @@ public class LymsPushMessages implements Serializable { private Integer pushedartId; /** - * 计划推送日期 + * 推送时间 */ - @TableField(value = "plan_time") - private Date planTime; + @TableField(value = "push_time") + private Date pushTime; /** * 列表筛选条件startDate @@ -165,6 +177,23 @@ public class LymsPushMessages implements Serializable { @TableField(exist = false) private String endDate; + /** + * 推送状态:0待推送(9点开始推送) 1成功 2失败。(在备注写失败原因) + */ + @TableField(value = "state") + private Integer state; + /** + * 备注 + */ + @TableField(value = "remark") + private String remark; + + /** + * 创建时间 + */ + @TableField(value = "created_time") + private Date createdTime; + @TableField(exist = false) private static final long serialVersionUID = 1L; @@ -201,7 +230,7 @@ public class LymsPushMessages implements Serializable { && (this.getWeixTextTwo() == null ? other.getWeixTextTwo() == null : this.getWeixTextTwo().equals(other.getWeixTextTwo())) && (this.getIsweixinOne() == null ? other.getIsweixinOne() == null : this.getIsweixinOne().equals(other.getIsweixinOne())) && (this.getIsweixinTwo() == null ? other.getIsweixinTwo() == null : this.getIsweixinTwo().equals(other.getIsweixinTwo())) - && (this.getPlanTime() == null ? other.getPlanTime() == null : this.getPlanTime().equals(other.getPlanTime())); + && (this.getPushTime() == null ? other.getPushTime() == null : this.getPushTime().equals(other.getPushTime())); } @Override @@ -229,7 +258,7 @@ public class LymsPushMessages implements Serializable { result = prime * result + ((getWeixTextTwo() == null) ? 0 : getWeixTextTwo().hashCode()); result = prime * result + ((getIsweixinOne() == null) ? 0 : getIsweixinOne().hashCode()); result = prime * result + ((getIsweixinTwo() == null) ? 0 : getIsweixinTwo().hashCode()); - result = prime * result + ((getPlanTime() == null) ? 0 : getPlanTime().hashCode()); + result = prime * result + ((getPushTime() == null) ? 0 : getPushTime().hashCode()); return result; } @@ -260,7 +289,7 @@ public class LymsPushMessages implements Serializable { sb.append(", weixTextTwo=").append(weixTextTwo); sb.append(", isweixinOne=").append(isweixinOne); sb.append(", isweixinTwo=").append(isweixinTwo); - sb.append(", planTime=").append(planTime); + sb.append(", planTime=").append(pushTime); sb.append(", serialVersionUID=").append(serialVersionUID); sb.append("]"); return sb.toString(); diff --git a/talkonlineweb/src/main/java/com/lyms/talkonlineweb/domain/LymsPushedart.java b/talkonlineweb/src/main/java/com/lyms/talkonlineweb/domain/LymsPushedart.java index b9b5ab9..9216778 100644 --- a/talkonlineweb/src/main/java/com/lyms/talkonlineweb/domain/LymsPushedart.java +++ b/talkonlineweb/src/main/java/com/lyms/talkonlineweb/domain/LymsPushedart.java @@ -52,13 +52,13 @@ public class LymsPushedart implements Serializable { private Date readtime; /** - * 是否推送短消息1(0否,1是) + * 是否推送短消息1(0否,1是 2推送失败) */ @TableField(value = "isweixin_one") private Integer isweixinone; /** - * 是否推送短消息2(0否,1是) + * 是否推送短消息2(0否,1是 2推送失败) */ @TableField(value = "isweixin_two") private Integer isweixintwo; diff --git a/talkonlineweb/src/main/java/com/lyms/talkonlineweb/task/PushArticleTask.java b/talkonlineweb/src/main/java/com/lyms/talkonlineweb/task/PushArticleTask.java index 80731f9..8dc9840 100644 --- a/talkonlineweb/src/main/java/com/lyms/talkonlineweb/task/PushArticleTask.java +++ b/talkonlineweb/src/main/java/com/lyms/talkonlineweb/task/PushArticleTask.java @@ -52,7 +52,7 @@ public class PushArticleTask { log.debug("开始给患者推送文章>>>>>>"); //从LymsPushMessages记录表查询今天0点筛选出要推送的文章 QueryWrapper queryWrapper = new QueryWrapper<>(); - queryWrapper.apply("TO_DAYS(plan_time) = TO_DAYS(NOW())"); + queryWrapper.apply("TO_DAYS(created_time) = TO_DAYS(NOW())"); List lymsPushMessages=lymsPushMessagesService.list(queryWrapper); for (LymsPushMessages lymsPushMessage : lymsPushMessages) { //推送的文章在LymsPushedart做记录。用于患者读取推送的文章 @@ -63,11 +63,37 @@ public class PushArticleTask { pushedart.setIsread((byte) 0); //PushedartId(如果null表示需要推送文章,否则需要推送短消息) if(null!=lymsPushMessage.getPushedartId()){ + //获取token失败 if(StringUtil.isEmpty(token)){ - log.info("推送短消息1,获取token失败。。。"); + //更新到LymsPushMessages记录 + lymsPushMessage.setState(2);//推送状态:0待推送(9点开始推送) 1成功 2失败。(在备注写失败原因) + lymsPushMessage.setRemark("推送短消息"+(lymsPushMessage.getIsweixinOne()==1?"1":"2")+",获取token失败。。。"); + lymsPushMessage.setPushTime(new Date()); + lymsPushMessagesService.updateById(lymsPushMessage); + //更新到LymsPushedart记录 + if(lymsPushMessage.getIsweixinOne()==1){ + pushedart.setIsweixinone(2);//是否推送短消息1(0否,1是 2推送失败) + }else { + pushedart.setIsweixintwo(2);//是否推送短消息2(0否,1是 2推送失败) + } + lymsPushedartService.updateById(pushedart); + log.info("推送短消息"+(lymsPushMessage.getIsweixinOne()==1?"1":"2")+",获取token失败。。。"); continue; } + //公众号openId为空 if(StringUtil.isEmpty(lymsPushMessage.getGzopenid())){ + //更新到LymsPushMessages记录 + lymsPushMessage.setState(2);//推送状态:0待推送(9点开始推送) 1成功 2失败。(在备注写失败原因) + lymsPushMessage.setRemark(lymsPushMessage.getPname()+":公众号openId为空。。。"); + lymsPushMessage.setPushTime(new Date()); + lymsPushMessagesService.updateById(lymsPushMessage); + //更新到LymsPushedart记录 + if(lymsPushMessage.getIsweixinOne()==1){ + pushedart.setIsweixinone(2);//是否推送短消息1(0否,1是 2推送失败) + }else { + pushedart.setIsweixintwo(2);//是否推送短消息2(0否,1是 2推送失败) + } + lymsPushedartService.updateById(pushedart); log.info(lymsPushMessage.getPname()+":公众号openId为空。。。"); continue; } @@ -83,11 +109,19 @@ public class PushArticleTask { map.put("remark",new DataEntity("预祝您早日康复","#173177")); Integer code= WeiXinUtil.SendWeChatMsg(token,lymsPushMessage.getGzopenid(),template_id,map); if(null==code||code!=0){ + //更新到LymsPushMessages记录 + lymsPushMessage.setState(2);//推送状态:0待推送(9点开始推送) 1成功 2失败。(在备注写失败原因) + lymsPushMessage.setRemark("推送短消息1失败。。。"+lymsPushMessage.getPname()+"; code:"+code); + lymsPushMessage.setPushTime(new Date()); + lymsPushMessagesService.updateById(lymsPushMessage); + //更新到LymsPushedart记录 + pushedart.setIsweixinone(2);//是否推送短消息1(0否,1是 2推送失败) + lymsPushedartService.updateById(pushedart); log.info("推送短消息1失败。。。"+lymsPushMessage.getPname()+"; code:"+code); continue; } //成功标记记录1 - pushedart.setIsweixinone(1);//0未推送1已推送 + pushedart.setIsweixinone(1);//是否推送短消息1(0否,1是 2推送失败) }else if(lymsPushMessage.getIsweixinTwo()==1){ //推送微信消息2 Map map=new HashMap<>(); @@ -98,25 +132,27 @@ public class PushArticleTask { map.put("remark",new DataEntity("预祝您早日康复","#173177")); Integer code= WeiXinUtil.SendWeChatMsg(token,lymsPushMessage.getGzopenid(),template_id,map); if(null==code||code!=0){ + //更新到LymsPushMessages记录 + lymsPushMessage.setState(2);//推送状态:0待推送(9点开始推送) 1成功 2失败。(在备注写失败原因) + lymsPushMessage.setRemark("推送短消息2失败。。。"+lymsPushMessage.getPname()+"; code:"+code); + lymsPushMessage.setPushTime(new Date()); + lymsPushMessagesService.updateById(lymsPushMessage); + //更新到LymsPushedart记录 + pushedart.setIsweixintwo(2);//是否推送短消息2(0否,1是 2推送失败) + lymsPushedartService.updateById(pushedart); log.info("推送短消息2失败。。。"+lymsPushMessage.getPname()+"; code:"+code); continue; } //成功标记记录2 - pushedart.setIsweixintwo(1);//0未推送1已推送 + pushedart.setIsweixintwo(1);//是否推送短消息1(0否,1是 2推送失败) } } //插入or更新到LymsPushedart记录 - boolean b = lymsPushedartService.saveOrUpdate(pushedart); - if (b) { - if(null!=pushedart.getIsweixinone()&&pushedart.getIsweixinone()==1){ - log.info("推送短文字1给:" + lymsPushMessage.getPname() + "成功!"); - }else if(null!=pushedart.getIsweixintwo()&&pushedart.getIsweixintwo()==1){ - log.info("推送短文字2给:" + lymsPushMessage.getPname() + "成功!"); - } - log.info("推送文章给:" + lymsPushMessage.getPname() + "成功!"); - } else { - log.info("推送文章给:" + lymsPushMessage.getPname() + "失败:插入or更新到LymsPushedart记录返回false>>>>>>>>>"); - } + lymsPushedartService.saveOrUpdate(pushedart); + //更新到LymsPushMessages记录 + lymsPushMessage.setState(1);//推送状态:0待推送(9点开始推送) 1成功 2失败。(在备注写失败原因) + lymsPushMessage.setPushTime(new Date()); + lymsPushMessagesService.updateById(lymsPushMessage); } } } diff --git a/talkonlineweb/src/main/java/com/lyms/talkonlineweb/task/PushArticleTaskData.java b/talkonlineweb/src/main/java/com/lyms/talkonlineweb/task/PushArticleTaskData.java index 8f3b008..c68d70e 100644 --- a/talkonlineweb/src/main/java/com/lyms/talkonlineweb/task/PushArticleTaskData.java +++ b/talkonlineweb/src/main/java/com/lyms/talkonlineweb/task/PushArticleTaskData.java @@ -12,6 +12,7 @@ import com.lyms.talkonlineweb.util.WeiXinUtil; import lombok.Data; import lombok.extern.log4j.Log4j2; import org.springframework.beans.BeanUtils; +import org.springframework.beans.BeansException; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; @@ -53,30 +54,34 @@ public class PushArticleTaskData { //筛选出需要推送的文章信息-(逻辑详见视图) List pushArticleList=pushArticleService.list(); for (PushArticle article : pushArticleList) { - //需要推送文章的对象 - LymsPushMessages lymsPushMessages=new LymsPushMessages(); - BeanUtils.copyProperties(article,lymsPushMessages); - //查询推已推送的文章(如果null表示需要推送文章,否则需要推送短消息) - QueryWrapper queryWrapper=new QueryWrapper<>(); - queryWrapper.eq("pid", lymsPushMessages.getPid()); - queryWrapper.eq("aid", lymsPushMessages.getAid()); - LymsPushedart lymsPushedart = lymsPushedartService.getOne(queryWrapper); - if(null!=lymsPushedart){ - //每次只推送一条短消息,判断推送短消息1还是2 - if(lymsPushedart.getIsweixinone()==0){//0未推送1已推送 - //标记要推送的记录需要推送短消息1 - lymsPushMessages.setIsweixinOne(1); - //存入已推送文章列表id - lymsPushMessages.setPushedartId(lymsPushedart.getId()); - }else if (lymsPushedart.getIsweixintwo()==0){//0未推送1已推送 - //标记要推送的记录需要推送短消息2 - lymsPushMessages.setIsweixinTwo(1); - //存入已推送文章列表id - lymsPushMessages.setPushedartId(lymsPushedart.getId()); + try { + //需要推送文章的对象 + LymsPushMessages lymsPushMessages=new LymsPushMessages(); + BeanUtils.copyProperties(article,lymsPushMessages); + //查询推已推送的文章(如果null表示需要推送文章,否则需要推送短消息) + QueryWrapper queryWrapper=new QueryWrapper<>(); + queryWrapper.eq("pid", lymsPushMessages.getPid()); + queryWrapper.eq("aid", lymsPushMessages.getAid()); + LymsPushedart lymsPushedart = lymsPushedartService.getOne(queryWrapper); + if(null!=lymsPushedart){ + //每次只推送一条短消息,判断推送短消息1还是2 + if(lymsPushedart.getIsweixinone()==0){//0未推送1已推送 + //标记要推送的记录需要推送短消息1 + lymsPushMessages.setIsweixinOne(1); + //存入已推送文章列表id + lymsPushMessages.setPushedartId(lymsPushedart.getId()); + }else if (lymsPushedart.getIsweixintwo()==0){//0未推送1已推送 + //标记要推送的记录需要推送短消息2 + lymsPushMessages.setIsweixinTwo(1); + //存入已推送文章列表id + lymsPushMessages.setPushedartId(lymsPushedart.getId()); + } } + //保存到要推送的表lyms_push_messages + lymsPushMessagesService.save(lymsPushMessages); + } catch (BeansException e) { + e.printStackTrace(); } - //保存到要推送的表lyms_push_messages - lymsPushMessagesService.save(lymsPushMessages); } } } diff --git a/talkonlineweb/src/main/java/com/lyms/talkonlineweb/util/Constant.java b/talkonlineweb/src/main/java/com/lyms/talkonlineweb/util/Constant.java index a24206e..4c2757d 100644 --- a/talkonlineweb/src/main/java/com/lyms/talkonlineweb/util/Constant.java +++ b/talkonlineweb/src/main/java/com/lyms/talkonlineweb/util/Constant.java @@ -54,4 +54,17 @@ public class Constant { * 公众号AppSecret */ public static final String GZ_SECRET ="fc80b5dd03a581a088adcd2c65a7e10a"; + /** + * 公众号authorization_code + */ + public static final String GZ_AUTH ="authorization_code"; + /** + * 公众号的appid 测试 + */ + public static final String GZ_APP_ID_CS ="wx7ef7bf809a93b616"; + + /** + * 公众号AppSecret 测试 + */ + public static final String GZ_SECRET_CS ="1c4b5543a54c74dd363a6655ca1cbffe"; } diff --git a/talkonlineweb/src/main/java/com/lyms/talkonlineweb/util/WeiXinUtil.java b/talkonlineweb/src/main/java/com/lyms/talkonlineweb/util/WeiXinUtil.java index 4ed2178..fbdd9de 100644 --- a/talkonlineweb/src/main/java/com/lyms/talkonlineweb/util/WeiXinUtil.java +++ b/talkonlineweb/src/main/java/com/lyms/talkonlineweb/util/WeiXinUtil.java @@ -95,9 +95,9 @@ public class WeiXinUtil { } try { // 接口地址 - 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"; + 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; log.info(reqUrl); - String result = repeatDoGetPost(reqUrl, "GET", null); + String result = HttpUtil.getData(reqUrl); log.info("result :" + result); if (StringUtils.isEmpty(result)) { log.info("取微信用户的公众号openid : 请求返回null..." ); diff --git a/talkonlineweb/src/main/resources/mapper/LymsPushMessagesMapper.xml b/talkonlineweb/src/main/resources/mapper/LymsPushMessagesMapper.xml index 741c079..4277a8c 100644 --- a/talkonlineweb/src/main/resources/mapper/LymsPushMessagesMapper.xml +++ b/talkonlineweb/src/main/resources/mapper/LymsPushMessagesMapper.xml @@ -26,7 +26,12 @@ - + + + + + + @@ -37,6 +42,6 @@ gzopenid,aid,atitle, acontent,serialNumber,weix_text_one, weix_text_two,isweixin_one,isweixin_two, - plan_time + push_time,state,remark,idno,mobile,created_time