Commit 4fa74834d33454c8fbb4e1a5d0c9fc1ad2e60f6f

Authored by shiyang
1 parent 6d30345631
Exists in master and in 1 other branch dev

0点推送的文章开始筛选存入记录。9点筛选的文章记录开始推送

Showing 14 changed files with 646 additions and 103 deletions

talkonlineweb/src/main/java/com/lyms/talkonlineweb/controller/TestController.java View file @ 4fa7483
1 1 package com.lyms.talkonlineweb.controller;
2 2  
3 3  
4   -import com.lyms.talkonlineweb.annotation.TokenRequired;
5   -import com.lyms.talkonlineweb.domain.LymsUser;
6   -import com.lyms.talkonlineweb.service.LymsUserService;
  4 +import com.lyms.talkonlineweb.task.PushArticleTask;
  5 +import com.lyms.talkonlineweb.task.PushArticleTaskData;
7 6 import lombok.extern.java.Log;
8 7 import org.springframework.beans.factory.annotation.Autowired;
9 8 import org.springframework.web.bind.annotation.GetMapping;
10 9 import org.springframework.web.bind.annotation.RestController;
11 10  
12   -import java.util.List;
13   -
14 11 @RestController
15 12 @Log
16 13 public class TestController {
  14 + @Autowired
  15 + public PushArticleTask pushArticleTask;
  16 + @Autowired
  17 + public PushArticleTaskData pushArticleTaskMySql;
  18 + @GetMapping("test0")
  19 + public void test0() {
  20 + pushArticleTask.pushArtcle();
  21 + }
  22 + @GetMapping("test9")
  23 + public void test9() {
  24 + pushArticleTaskMySql.pushArtcleData();
  25 + }
17 26  
18 27  
19 28 // @Autowired
talkonlineweb/src/main/java/com/lyms/talkonlineweb/domain/LymsPushMessages.java View file @ 4fa7483
  1 +package com.lyms.talkonlineweb.domain;
  2 +
  3 +import com.baomidou.mybatisplus.annotation.IdType;
  4 +import com.baomidou.mybatisplus.annotation.TableField;
  5 +import com.baomidou.mybatisplus.annotation.TableId;
  6 +import com.baomidou.mybatisplus.annotation.TableName;
  7 +import java.io.Serializable;
  8 +import java.util.Date;
  9 +import lombok.Data;
  10 +
  11 +/**
  12 + * 每天0点存入9点要推送的信息
  13 + * @TableName lyms_push_messages
  14 + */
  15 +@TableName(value ="lyms_push_messages")
  16 +@Data
  17 +public class LymsPushMessages implements Serializable {
  18 + /**
  19 + *
  20 + */
  21 + @TableId(value = "id", type = IdType.AUTO)
  22 + private Integer id;
  23 +
  24 + /**
  25 + * 患者id
  26 + */
  27 + @TableField(value = "pid")
  28 + private Integer pid;
  29 +
  30 + /**
  31 + * 患者名称
  32 + */
  33 + @TableField(value = "pname")
  34 + private String pname;
  35 +
  36 + /**
  37 + * 医院id
  38 + */
  39 + @TableField(value = "hid")
  40 + private Integer hid;
  41 +
  42 + /**
  43 + * 医院名称
  44 + */
  45 + @TableField(value = "hname")
  46 + private String hname;
  47 +
  48 + /**
  49 + * 科室id
  50 + */
  51 + @TableField(value = "did")
  52 + private Integer did;
  53 +
  54 + /**
  55 + * 科室名称
  56 + */
  57 + @TableField(value = "dname")
  58 + private String dname;
  59 +
  60 + /**
  61 + * 医生id
  62 + */
  63 + @TableField(value = "dtid")
  64 + private Integer dtid;
  65 +
  66 + /**
  67 + * 医生名称
  68 + */
  69 + @TableField(value = "dtname")
  70 + private String dtname;
  71 +
  72 + /**
  73 + * 疾病id
  74 + */
  75 + @TableField(value = "iid")
  76 + private Integer iid;
  77 +
  78 + /**
  79 + * 疾病名称
  80 + */
  81 + @TableField(value = "iname")
  82 + private String iname;
  83 +
  84 + /**
  85 + * 病例id
  86 + */
  87 + @TableField(value = "ilid")
  88 + private Integer ilid;
  89 +
  90 + /**
  91 + * 患者关注公众号openid
  92 + */
  93 + @TableField(value = "gzopenid")
  94 + private String gzopenid;
  95 +
  96 + /**
  97 + * 推送文章id
  98 + */
  99 + @TableField(value = "aid")
  100 + private Integer aid;
  101 +
  102 + /**
  103 + * 推送文章标题
  104 + */
  105 + @TableField(value = "atitle")
  106 + private String atitle;
  107 +
  108 + /**
  109 + * 推送文章内容
  110 + */
  111 + @TableField(value = "acontent")
  112 + private String acontent;
  113 +
  114 + /**
  115 + * 推送文章的序号
  116 + */
  117 + @TableField(value = "serialNumber")
  118 + private Integer serialnumber;
  119 +
  120 + /**
  121 + * 推送短文字1的内容
  122 + */
  123 + @TableField(value = "weix_text_one")
  124 + private String weixTextOne;
  125 +
  126 + /**
  127 + * 推送短文字2的内容
  128 + */
  129 + @TableField(value = "weix_text_two")
  130 + private String weixTextTwo;
  131 +
  132 + /**
  133 + * 是否推送短文字1内容:0不推送 1推送
  134 + */
  135 + @TableField(value = "isweixin_one")
  136 + private Integer isweixinOne;
  137 +
  138 + /**
  139 + * 是否推送短文字2内容:0不推送 1推送
  140 + */
  141 + @TableField(value = "isweixin_two")
  142 + private Integer isweixinTwo;
  143 +
  144 + /**
  145 + * 已推送列表id(lyms_pushedart表)
  146 + */
  147 + @TableField(value = "pushedart_id")
  148 + private Integer pushedartId;
  149 +
  150 + /**
  151 + * 计划推送日期
  152 + */
  153 + @TableField(value = "plan_time")
  154 + private Date planTime;
  155 +
  156 + @TableField(exist = false)
  157 + private static final long serialVersionUID = 1L;
  158 +
  159 + @Override
  160 + public boolean equals(Object that) {
  161 + if (this == that) {
  162 + return true;
  163 + }
  164 + if (that == null) {
  165 + return false;
  166 + }
  167 + if (getClass() != that.getClass()) {
  168 + return false;
  169 + }
  170 + LymsPushMessages other = (LymsPushMessages) that;
  171 + return (this.getId() == null ? other.getId() == null : this.getId().equals(other.getId()))
  172 + && (this.getPid() == null ? other.getPid() == null : this.getPid().equals(other.getPid()))
  173 + && (this.getPname() == null ? other.getPname() == null : this.getPname().equals(other.getPname()))
  174 + && (this.getHid() == null ? other.getHid() == null : this.getHid().equals(other.getHid()))
  175 + && (this.getHname() == null ? other.getHname() == null : this.getHname().equals(other.getHname()))
  176 + && (this.getDid() == null ? other.getDid() == null : this.getDid().equals(other.getDid()))
  177 + && (this.getDname() == null ? other.getDname() == null : this.getDname().equals(other.getDname()))
  178 + && (this.getDtid() == null ? other.getDtid() == null : this.getDtid().equals(other.getDtid()))
  179 + && (this.getDtname() == null ? other.getDtname() == null : this.getDtname().equals(other.getDtname()))
  180 + && (this.getIid() == null ? other.getIid() == null : this.getIid().equals(other.getIid()))
  181 + && (this.getIname() == null ? other.getIname() == null : this.getIname().equals(other.getIname()))
  182 + && (this.getIlid() == null ? other.getIlid() == null : this.getIlid().equals(other.getIlid()))
  183 + && (this.getGzopenid() == null ? other.getGzopenid() == null : this.getGzopenid().equals(other.getGzopenid()))
  184 + && (this.getAid() == null ? other.getAid() == null : this.getAid().equals(other.getAid()))
  185 + && (this.getAtitle() == null ? other.getAtitle() == null : this.getAtitle().equals(other.getAtitle()))
  186 + && (this.getAcontent() == null ? other.getAcontent() == null : this.getAcontent().equals(other.getAcontent()))
  187 + && (this.getSerialnumber() == null ? other.getSerialnumber() == null : this.getSerialnumber().equals(other.getSerialnumber()))
  188 + && (this.getWeixTextOne() == null ? other.getWeixTextOne() == null : this.getWeixTextOne().equals(other.getWeixTextOne()))
  189 + && (this.getWeixTextTwo() == null ? other.getWeixTextTwo() == null : this.getWeixTextTwo().equals(other.getWeixTextTwo()))
  190 + && (this.getIsweixinOne() == null ? other.getIsweixinOne() == null : this.getIsweixinOne().equals(other.getIsweixinOne()))
  191 + && (this.getIsweixinTwo() == null ? other.getIsweixinTwo() == null : this.getIsweixinTwo().equals(other.getIsweixinTwo()))
  192 + && (this.getPlanTime() == null ? other.getPlanTime() == null : this.getPlanTime().equals(other.getPlanTime()));
  193 + }
  194 +
  195 + @Override
  196 + public int hashCode() {
  197 + final int prime = 31;
  198 + int result = 1;
  199 + result = prime * result + ((getId() == null) ? 0 : getId().hashCode());
  200 + result = prime * result + ((getPid() == null) ? 0 : getPid().hashCode());
  201 + result = prime * result + ((getPname() == null) ? 0 : getPname().hashCode());
  202 + result = prime * result + ((getHid() == null) ? 0 : getHid().hashCode());
  203 + result = prime * result + ((getHname() == null) ? 0 : getHname().hashCode());
  204 + result = prime * result + ((getDid() == null) ? 0 : getDid().hashCode());
  205 + result = prime * result + ((getDname() == null) ? 0 : getDname().hashCode());
  206 + result = prime * result + ((getDtid() == null) ? 0 : getDtid().hashCode());
  207 + result = prime * result + ((getDtname() == null) ? 0 : getDtname().hashCode());
  208 + result = prime * result + ((getIid() == null) ? 0 : getIid().hashCode());
  209 + result = prime * result + ((getIname() == null) ? 0 : getIname().hashCode());
  210 + result = prime * result + ((getIlid() == null) ? 0 : getIlid().hashCode());
  211 + result = prime * result + ((getGzopenid() == null) ? 0 : getGzopenid().hashCode());
  212 + result = prime * result + ((getAid() == null) ? 0 : getAid().hashCode());
  213 + result = prime * result + ((getAtitle() == null) ? 0 : getAtitle().hashCode());
  214 + result = prime * result + ((getAcontent() == null) ? 0 : getAcontent().hashCode());
  215 + result = prime * result + ((getSerialnumber() == null) ? 0 : getSerialnumber().hashCode());
  216 + result = prime * result + ((getWeixTextOne() == null) ? 0 : getWeixTextOne().hashCode());
  217 + result = prime * result + ((getWeixTextTwo() == null) ? 0 : getWeixTextTwo().hashCode());
  218 + result = prime * result + ((getIsweixinOne() == null) ? 0 : getIsweixinOne().hashCode());
  219 + result = prime * result + ((getIsweixinTwo() == null) ? 0 : getIsweixinTwo().hashCode());
  220 + result = prime * result + ((getPlanTime() == null) ? 0 : getPlanTime().hashCode());
  221 + return result;
  222 + }
  223 +
  224 + @Override
  225 + public String toString() {
  226 + StringBuilder sb = new StringBuilder();
  227 + sb.append(getClass().getSimpleName());
  228 + sb.append(" [");
  229 + sb.append("Hash = ").append(hashCode());
  230 + sb.append(", id=").append(id);
  231 + sb.append(", pid=").append(pid);
  232 + sb.append(", pname=").append(pname);
  233 + sb.append(", hid=").append(hid);
  234 + sb.append(", hname=").append(hname);
  235 + sb.append(", did=").append(did);
  236 + sb.append(", dname=").append(dname);
  237 + sb.append(", dtid=").append(dtid);
  238 + sb.append(", dtname=").append(dtname);
  239 + sb.append(", iid=").append(iid);
  240 + sb.append(", iname=").append(iname);
  241 + sb.append(", ilid=").append(ilid);
  242 + sb.append(", gzopenid=").append(gzopenid);
  243 + sb.append(", aid=").append(aid);
  244 + sb.append(", atitle=").append(atitle);
  245 + sb.append(", acontent=").append(acontent);
  246 + sb.append(", serialnumber=").append(serialnumber);
  247 + sb.append(", weixTextOne=").append(weixTextOne);
  248 + sb.append(", weixTextTwo=").append(weixTextTwo);
  249 + sb.append(", isweixinOne=").append(isweixinOne);
  250 + sb.append(", isweixinTwo=").append(isweixinTwo);
  251 + sb.append(", planTime=").append(planTime);
  252 + sb.append(", serialVersionUID=").append(serialVersionUID);
  253 + sb.append("]");
  254 + return sb.toString();
  255 + }
  256 +}
talkonlineweb/src/main/java/com/lyms/talkonlineweb/domain/LymsPushedart.java View file @ 4fa7483
... ... @@ -54,13 +54,13 @@
54 54 /**
55 55 * 是否推送短消息1(0否,1是)
56 56 */
57   - @TableField(value = "isweixinone")
  57 + @TableField(value = "isweixin_one")
58 58 private Integer isweixinone;
59 59  
60 60 /**
61 61 * 是否推送短消息2(0否,1是)
62 62 */
63   - @TableField(value = "isweixintwo")
  63 + @TableField(value = "isweixin_two")
64 64 private Integer isweixintwo;
65 65  
66 66 @TableField(exist = false)
talkonlineweb/src/main/java/com/lyms/talkonlineweb/domain/PushArticle.java View file @ 4fa7483
... ... @@ -18,8 +18,8 @@
18 18 /**
19 19 * 患者id
20 20 */
21   - @TableField(value = "id")
22   - private Integer id;
  21 + @TableField(value = "pid")
  22 + private Integer pid;
23 23  
24 24 /**
25 25 * 患者姓名
... ... @@ -165,6 +165,30 @@
165 165 @TableField(value = "weixTextTwo")
166 166 private String weixTextTwo;
167 167  
  168 + /**
  169 + * 患者关注公众号openid
  170 + */
  171 + @TableField(value = "gzopenid")
  172 + private String gzopenid;
  173 +
  174 + /**
  175 + * 推送文章标题
  176 + */
  177 + @TableField(value = "atitle")
  178 + private String atitle;
  179 +
  180 + /**
  181 + * 推送文章内容
  182 + */
  183 + @TableField(value = "acontent")
  184 + private String acontent;
  185 +
  186 + /**
  187 + * 推送文章的序号
  188 + */
  189 + @TableField(value = "serialNumber")
  190 + private Integer serialnumber;
  191 +
168 192 @TableField(exist = false)
169 193 private static final long serialVersionUID = 1L;
170 194  
... ... @@ -180,7 +204,7 @@
180 204 return false;
181 205 }
182 206 PushArticle other = (PushArticle) that;
183   - return (this.getId() == null ? other.getId() == null : this.getId().equals(other.getId()))
  207 + return (this.getPid() == null ? other.getPid() == null : this.getPid().equals(other.getPid()))
184 208 && (this.getPname() == null ? other.getPname() == null : this.getPname().equals(other.getPname()))
185 209 && (this.getIdno() == null ? other.getIdno() == null : this.getIdno().equals(other.getIdno()))
186 210 && (this.getPpasswd() == null ? other.getPpasswd() == null : this.getPpasswd().equals(other.getPpasswd()))
... ... @@ -209,7 +233,7 @@
209 233 public int hashCode() {
210 234 final int prime = 31;
211 235 int result = 1;
212   - result = prime * result + ((getId() == null) ? 0 : getId().hashCode());
  236 + result = prime * result + ((getPid() == null) ? 0 : getPid().hashCode());
213 237 result = prime * result + ((getPname() == null) ? 0 : getPname().hashCode());
214 238 result = prime * result + ((getIdno() == null) ? 0 : getIdno().hashCode());
215 239 result = prime * result + ((getPpasswd() == null) ? 0 : getPpasswd().hashCode());
... ... @@ -241,7 +265,7 @@
241 265 sb.append(getClass().getSimpleName());
242 266 sb.append(" [");
243 267 sb.append("Hash = ").append(hashCode());
244   - sb.append(", id=").append(id);
  268 + sb.append(", pid=").append(pid);
245 269 sb.append(", pname=").append(pname);
246 270 sb.append(", idno=").append(idno);
247 271 sb.append(", ppasswd=").append(ppasswd);
talkonlineweb/src/main/java/com/lyms/talkonlineweb/mapper/LymsPushMessagesMapper.java View file @ 4fa7483
  1 +package com.lyms.talkonlineweb.mapper;
  2 +
  3 +import com.lyms.talkonlineweb.domain.LymsPushMessages;
  4 +import com.baomidou.mybatisplus.core.mapper.BaseMapper;
  5 +
  6 +/**
  7 + * @Entity com.lyms.talkonlineweb.domain.LymsPushMessages
  8 + */
  9 +public interface LymsPushMessagesMapper extends BaseMapper<LymsPushMessages> {
  10 +
  11 +}
talkonlineweb/src/main/java/com/lyms/talkonlineweb/service/LymsPushMessagesService.java View file @ 4fa7483
  1 +package com.lyms.talkonlineweb.service;
  2 +
  3 +import com.lyms.talkonlineweb.domain.LymsPushMessages;
  4 +import com.baomidou.mybatisplus.extension.service.IService;
  5 +
  6 +/**
  7 + *
  8 + */
  9 +public interface LymsPushMessagesService extends IService<LymsPushMessages> {
  10 +
  11 +}
talkonlineweb/src/main/java/com/lyms/talkonlineweb/service/impl/LymsPushMessagesServiceImpl.java View file @ 4fa7483
  1 +package com.lyms.talkonlineweb.service.impl;
  2 +
  3 +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  4 +import com.lyms.talkonlineweb.domain.LymsPushMessages;
  5 +import com.lyms.talkonlineweb.service.LymsPushMessagesService;
  6 +import com.lyms.talkonlineweb.mapper.LymsPushMessagesMapper;
  7 +import org.springframework.stereotype.Service;
  8 +
  9 +/**
  10 + *
  11 + */
  12 +@Service
  13 +public class LymsPushMessagesServiceImpl extends ServiceImpl<LymsPushMessagesMapper, LymsPushMessages>
  14 + implements LymsPushMessagesService{
  15 +
  16 +}
talkonlineweb/src/main/java/com/lyms/talkonlineweb/task/AccessTokenServlet.java View file @ 4fa7483
1 1 package com.lyms.talkonlineweb.task;
2 2  
  3 +import com.alibaba.fastjson.JSONObject;
  4 +import com.lyms.talkonlineweb.util.HttpUtil;
  5 +import com.lyms.talkonlineweb.util.StringUtil;
  6 +import com.lyms.talkonlineweb.util.WeiXinUtil;
3 7 import org.springframework.stereotype.Component;
4 8  
5 9 import javax.annotation.PostConstruct;
6 10 import javax.servlet.ServletException;
7 11 import javax.servlet.http.HttpServlet;
8 12  
  13 +/**
  14 + * 获取到access_token
  15 + * 每1小时59获取一次token,保证长期有效。
  16 + * (微信公众号规定2小时token失效,每天只能获取2000次。)
  17 + */
9 18 @Component
10   -public class AccessTokenServlet extends HttpServlet {
11   - final String appId ="wxd3c36244d006cb90";//公众号appid
12   - final String appSecret ="fc80b5dd03a581a088adcd2c65a7e10a";//公众号AppSecret
  19 +public class AccessTokenServlet extends HttpServlet implements Runnable {
  20 + private final String appId ="wxd3c36244d006cb90";//公众号appid
  21 + private final String appSecret ="fc80b5dd03a581a088adcd2c65a7e10a";//公众号AppSecret
  22 + public static String accessToken = null;
13 23  
14 24 /**
15   - * 启动后开启线程每1小时59获取一次token,保证长期有效。(微信公众号规定2小时token失效,每天只能获取2000次。)
  25 + * 启动后开启线程每1小时59获取一次token
16 26 * @throws ServletException
17 27 */
18   - @PostConstruct//部署后启动方法
  28 + @PostConstruct//部署时开启注释,启动线程
19 29 public void init() throws ServletException {
20   - TokenThread.appId = appId;
21   - TokenThread.appSecret = appSecret;
22   - new Thread(new TokenThread()).start(); //启动进程
  30 + new Thread(new AccessTokenServlet()).start(); //启动线程
  31 + }
  32 + public void run(){
  33 + while (true){
  34 + try{
  35 + accessToken = this.getToken();
  36 + if(null!=accessToken){
  37 + Thread.sleep(1000 * 7000); //获取到access_token 休眠7000秒
  38 + }else{
  39 + Thread.sleep(1000 * 3); //获取的access_token为空 休眠3秒
  40 + }
  41 + }catch(Exception e){
  42 + System.out.println("发生异常:"+e.getMessage());
  43 + e.printStackTrace();
  44 + try{
  45 + Thread.sleep(1000 * 10); //发生异常休眠1秒
  46 + }catch (Exception e1){
  47 +
  48 + }
  49 + }
  50 + }
  51 + }
  52 +
  53 + /**
  54 + * 获取token
  55 + * 微信公众号
  56 + * @return token
  57 + */
  58 + public String getToken() {
  59 + // 授予形式
  60 + String grant_type = "client_credential";
  61 + // 接口地址拼接参数
  62 + String getTokenApi = "https://api.weixin.qq.com/cgi-bin/token?grant_type=" + grant_type + "&appid=" + appId
  63 + + "&secret=" + appSecret;
  64 + String tokenJsonStr = WeiXinUtil.repeatDoGetPost(getTokenApi, "GET", null);
  65 + if(StringUtil.isEmpty(tokenJsonStr)){
  66 + System.out.println("获取TOKEN :失败,repeatDoGetPost返回值为空>>>>>>>");
  67 + return null;
  68 + }
  69 + JSONObject tokenJson = JSONObject.parseObject(tokenJsonStr);
  70 + String token = tokenJson.get("access_token").toString();
  71 + System.out.println("获取到的TOKEN : " + token);
  72 + return token;
23 73 }
24 74 }
talkonlineweb/src/main/java/com/lyms/talkonlineweb/task/PushArticleTask.java View file @ 4fa7483
... ... @@ -2,14 +2,20 @@
2 2  
3 3 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
4 4 import com.lyms.talkonlineweb.domain.*;
  5 +import com.lyms.talkonlineweb.result.BaseResponse;
5 6 import com.lyms.talkonlineweb.service.*;
  7 +import com.lyms.talkonlineweb.util.DateUtil;
6 8 import com.lyms.talkonlineweb.util.StringUtil;
7 9 import com.lyms.talkonlineweb.util.WeiXinUtil;
  10 +import lombok.Data;
8 11 import lombok.extern.log4j.Log4j2;
9 12 import org.springframework.beans.factory.annotation.Autowired;
  13 +import org.springframework.scheduling.annotation.Scheduled;
10 14 import org.springframework.stereotype.Component;
11 15 import java.util.*;
12 16  
  17 +import static com.lyms.talkonlineweb.util.DateUtil.YYYY_MM_DD;
  18 +
13 19 /**
14 20 * 推送文章任务
15 21 */
16 22  
17 23  
18 24  
19 25  
20 26  
21 27  
22 28  
23 29  
24 30  
25 31  
26 32  
27 33  
... ... @@ -28,58 +34,104 @@
28 34 private PushArticleService pushArticleService;//推送文章新逻辑shiy改
29 35  
30 36 @Autowired
  37 + LymsPushMessagesService lymsPushMessagesService;
  38 +
  39 + @Autowired
31 40 private LymsDictService lymsDictService;
32   - final String gzopenid ="oQEmP6uq2pUQ80NctiX3GnFxDMn8";//测试:公众号关注的微信openId
33   - final String template_id ="";//测试:公众号模板id
34 41  
35   -// @Scheduled(initialDelay=10000, fixedRate=30000)
  42 + final String gzopenid ="oQEmP6rFmf0lOb--mUf4_MAZPXEQ";//测试:公众号关注的微信openId
  43 + final String template_id ="ZDxcRDJ3okC9Lbzpfhr_v4e8W1VWrho-f5uHW_VZHTg";//公众号模板:诊后注意事项id
  44 +
  45 + @Scheduled(cron = "0 0 9 * * ?")//每天上午9点执行文章推送
36 46 public void pushArtcle(){
  47 + String token= AccessTokenServlet.accessToken;
37 48 Map<String,Object> param=new HashMap<>();
38 49 param.put("vtype",999);
39 50 List<LymsDict> dcLst=lymsDictService.listByMap(param);
40 51 if (dcLst.size()>0 && dcLst.get(0).getCode()==1){
41 52 log.debug("开始给患者推送文章>>>>>>");
42   - List<PushArticle> pushArticle=pushArticleService.list();
43   - for (PushArticle article : pushArticle) {
  53 + //从LymsPushMessages记录表查询今天0点筛选出要推送的文章
  54 + QueryWrapper<LymsPushMessages> queryWrapper = new QueryWrapper<>();
  55 + queryWrapper.apply("TO_DAYS(plan_time) = TO_DAYS(NOW())");
  56 + List<LymsPushMessages> lymsPushMessages=lymsPushMessagesService.list(queryWrapper);
  57 + for (LymsPushMessages lymsPushMessage : lymsPushMessages) {
  58 + //推送的文章在LymsPushedart做记录。用于患者读取推送的文章
44 59 LymsPushedart pushedart=new LymsPushedart();
45   - pushedart.setPid(article.getId());
46   - pushedart.setAid(article.getAid());
  60 + pushedart.setPid(lymsPushMessage.getPid());
  61 + pushedart.setAid(lymsPushMessage.getAid());
47 62 pushedart.setCreatedtime(new Date());
48 63 pushedart.setIsread((byte) 0);
49   - //查询推送文章后短文字推送状态
50   - QueryWrapper<LymsPushedart> queryWrapper=new QueryWrapper<>();
51   - queryWrapper.eq("pid", article.getId());
52   - queryWrapper.eq("aid", article.getAid());
53   - LymsPushedart lymsPushedart = lymsPushedartService.getOne(queryWrapper);
54   - if(null!=lymsPushedart){
55   - pushedart.setId(lymsPushedart.getId());
56   - if(lymsPushedart.getIsweixinone()==0){
57   - if(StringUtil.isEmpty(TokenThread.accessToken)){
58   - log.info("获取token失败。。。"+article.getDtname()+":短消息1推送失败");
  64 + //PushedartId(如果null表示需要推送文章,否则需要推送短消息)
  65 + if(null!=lymsPushMessage.getPushedartId()){
  66 + pushedart.setId(lymsPushMessage.getPushedartId());
  67 + if(lymsPushMessage.getIsweixinOne()==1){
  68 + if(StringUtil.isEmpty(token)){
  69 + log.info("推送短消息1,获取token失败。。。");
59 70 continue;
60 71 }
61 72 //推送微信消息1
62 73 Map<String,Object> map=new HashMap<>();
63   - map.put("data", article.getWeixTextOne());
64   - WeiXinUtil.SendWeChatMsg(TokenThread.accessToken, gzopenid, template_id,map);
  74 + map.put("first",new DataEntity(lymsPushMessage.getWeixTextOne(),"#173177"));
  75 + map.put("keyword1",new DataEntity(lymsPushMessage.getPname(),"#173177"));
  76 + map.put("keyword2",new DataEntity(lymsPushMessage.getHname(),"#173177"));
  77 + map.put("keyword3",new DataEntity(lymsPushMessage.getDname(),"#173177"));
  78 + map.put("remark",new DataEntity("预祝您早日康复","#173177"));
  79 + Integer code= WeiXinUtil.SendWeChatMsg(token,gzopenid,template_id,map);
  80 + if(null==code||code!=0){
  81 + log.info("推送短消息1失败。。。"+lymsPushMessage.getPname()+"; code:"+code);
  82 + continue;
  83 + }
65 84 //成功标记记录1
66   - pushedart.setIsweixinone(1);
67   - }else if (lymsPushedart.getIsweixintwo()==0){
68   - if(StringUtil.isEmpty(TokenThread.accessToken)){
69   - log.info("获取token失败。。。"+article.getDtname()+":短消息2推送失败");
  85 + pushedart.setIsweixinone(1);//0未推送1已推送
  86 + }else if(lymsPushMessage.getIsweixinTwo()==1){
  87 + if(StringUtil.isEmpty(token)){
  88 + log.info("推送短消息2,获取token失败。。。");
70 89 continue;
71 90 }
72 91 //推送微信消息2
73 92 Map<String,Object> map=new HashMap<>();
74   - map.put("data", article.getWeixTextTwo());
75   - WeiXinUtil.SendWeChatMsg(TokenThread.accessToken, gzopenid, template_id,map);
  93 + map.put("first",new DataEntity(lymsPushMessage.getWeixTextTwo(),"#173177"));
  94 + map.put("keyword1",new DataEntity(lymsPushMessage.getPname(),"#173177"));
  95 + map.put("keyword2",new DataEntity(lymsPushMessage.getHname(),"#173177"));
  96 + map.put("keyword3",new DataEntity(lymsPushMessage.getDname(),"#173177"));
  97 + map.put("remark",new DataEntity("预祝您早日康复","#173177"));
  98 + Integer code= WeiXinUtil.SendWeChatMsg(token,gzopenid,template_id,map);
  99 + if(null==code||code!=0){
  100 + log.info("推送短消息2失败。。。"+lymsPushMessage.getPname()+"; code:"+code);
  101 + continue;
  102 + }
76 103 //成功标记记录2
77   - pushedart.setIsweixintwo(1);
  104 + pushedart.setIsweixintwo(1);//0未推送1已推送
78 105 }
79 106 }
80   - lymsPushedartService.saveOrUpdate(pushedart);//插入到提送记录
  107 + //插入or更新到LymsPushedart记录
  108 + boolean b = lymsPushedartService.saveOrUpdate(pushedart);
  109 + if (b) {
  110 + if(null!=pushedart.getIsweixinone()&&pushedart.getIsweixinone()==1){
  111 + log.info("推送短文字1给:" + lymsPushMessage.getPname() + "成功!");
  112 + }else if(null!=pushedart.getIsweixintwo()&&pushedart.getIsweixintwo()==1){
  113 + log.info("推送短文字2给:" + lymsPushMessage.getPname() + "成功!");
  114 + }
  115 + log.info("推送文章给:" + lymsPushMessage.getPname() + "成功!");
  116 + } else {
  117 + log.info("推送文章给:" + lymsPushMessage.getPname() + "失败:插入or更新到LymsPushedart记录返回false>>>>>>>>>");
  118 + }
81 119 }
82 120 }
  121 + }
  122 +
  123 +
  124 +}
  125 +@Data
  126 +class DataEntity {
  127 + //内容
  128 + private String value;
  129 + //字体颜色
  130 + private String color;
  131 +
  132 + public DataEntity(String value ,String color){
  133 + this.value = value;
  134 + this.color = color;
83 135 }
84 136 }
talkonlineweb/src/main/java/com/lyms/talkonlineweb/task/PushArticleTaskData.java View file @ 4fa7483
  1 +package com.lyms.talkonlineweb.task;
  2 +
  3 +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  4 +import com.lyms.talkonlineweb.domain.LymsDict;
  5 +import com.lyms.talkonlineweb.domain.LymsPushMessages;
  6 +import com.lyms.talkonlineweb.domain.LymsPushedart;
  7 +import com.lyms.talkonlineweb.domain.PushArticle;
  8 +import com.lyms.talkonlineweb.service.*;
  9 +import com.lyms.talkonlineweb.util.DateUtil;
  10 +import com.lyms.talkonlineweb.util.StringUtil;
  11 +import com.lyms.talkonlineweb.util.WeiXinUtil;
  12 +import lombok.Data;
  13 +import lombok.extern.log4j.Log4j2;
  14 +import org.springframework.beans.BeanUtils;
  15 +import org.springframework.beans.factory.annotation.Autowired;
  16 +import org.springframework.scheduling.annotation.Scheduled;
  17 +import org.springframework.stereotype.Component;
  18 +import org.springframework.util.unit.DataUnit;
  19 +
  20 +import java.util.*;
  21 +
  22 +import static com.lyms.talkonlineweb.util.DateUtil.YYYY_MM_DD;
  23 +
  24 +/**
  25 + * 推送文章任务
  26 + */
  27 +
  28 +@Component
  29 +@Log4j2
  30 +public class PushArticleTaskData {
  31 +
  32 + @Autowired
  33 + private LymsArticleService lymsArticleService;
  34 + @Autowired
  35 + private PatientInfoService patientInfoService;
  36 + @Autowired
  37 + private LymsPushedartService lymsPushedartService;//推送的历史记录
  38 + @Autowired
  39 + private PushArticleService pushArticleService;//推送文章新逻辑shiy改
  40 + @Autowired
  41 + LymsPushMessagesService lymsPushMessagesService;
  42 + @Autowired
  43 + private LymsDictService lymsDictService;
  44 +
  45 +
  46 + @Scheduled(cron = "0 0 0 * * ?")//每天0点执行-要推送的文章存到数据库
  47 + public void pushArtcleData(){
  48 + Map<String,Object> param=new HashMap<>();
  49 + param.put("vtype",999);
  50 + List<LymsDict> dcLst=lymsDictService.listByMap(param);
  51 + if (dcLst.size()>0 && dcLst.get(0).getCode()==1){
  52 + log.info("开始筛选"+(DateUtil.getDateTime(new Date(), YYYY_MM_DD))+"要推送的文章存入mysql>>>>>>");
  53 + //筛选出需要推送的文章信息-(逻辑详见视图)
  54 + List<PushArticle> pushArticleList=pushArticleService.list();
  55 + 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());
  76 + }
  77 + }
  78 + //保存到要推送的表lyms_push_messages
  79 + lymsPushMessagesService.save(lymsPushMessages);
  80 + }
  81 + }
  82 + }
  83 +
  84 +}
talkonlineweb/src/main/java/com/lyms/talkonlineweb/task/TokenThread.java View file @ 4fa7483
1   -package com.lyms.talkonlineweb.task;
2   -
3   -import com.alibaba.fastjson.JSONObject;
4   -import com.lyms.talkonlineweb.util.HttpUtil;
5   -
6   -public class TokenThread implements Runnable{
7   - public static String appId = "wxd3c36244d006cb90";
8   -
9   - public static String appSecret= "fc80b5dd03a581a088adcd2c65a7e10a";
10   -
11   - public static String accessToken = null;
12   -
13   - public void run(){
14   - while (true){
15   - try{
16   - accessToken = this.getToken();
17   - if(null!=accessToken){
18   - System.out.println(accessToken);
19   - Thread.sleep(7000 * 1000); //获取到access_token 休眠7000秒
20   -
21   - }else{
22   - Thread.sleep(1000*3); //获取的access_token为空 休眠3秒
23   - }
24   - }catch(Exception e){
25   - System.out.println("发生异常:"+e.getMessage());
26   - e.printStackTrace();
27   - try{
28   - Thread.sleep(1000*10); //发生异常休眠1秒
29   - }catch (Exception e1){
30   -
31   - }
32   - }
33   - }
34   - }
35   -
36   -
37   - /**
38   - * 获取token
39   - * 微信公众号
40   - * @return token
41   - */
42   - public String getToken() {
43   - // 授予形式
44   - String grant_type = "client_credential";
45   - // 接口地址拼接参数
46   - String getTokenApi = "https://api.weixin.qq.com/cgi-bin/token?grant_type=" + grant_type + "&appid=" + this.appId
47   - + "&secret=" + this.appSecret;
48   - String tokenJsonStr = HttpUtil.doGetPost(getTokenApi, "GET", null);
49   - JSONObject tokenJson = JSONObject.parseObject(tokenJsonStr);
50   - String token = tokenJson.get("access_token").toString();
51   - System.out.println("获取到的TOKEN : " + token);
52   - return token;
53   - }
54   -}
talkonlineweb/src/main/java/com/lyms/talkonlineweb/util/DateUtil.java View file @ 4fa7483
... ... @@ -3,6 +3,7 @@
3 3 import lombok.extern.slf4j.Slf4j;
4 4  
5 5 import java.text.DateFormat;
  6 +import java.text.ParsePosition;
6 7 import java.text.SimpleDateFormat;
7 8 import java.util.Date;
8 9 import java.util.concurrent.ConcurrentHashMap;
... ... @@ -75,5 +76,6 @@
75 76 SimpleDateFormat fm = new SimpleDateFormat("yyMMddHHmmss");
76 77 return fm.format(new Date());
77 78 }
  79 +
78 80 }
talkonlineweb/src/main/java/com/lyms/talkonlineweb/util/WeiXinUtil.java View file @ 4fa7483
1 1 package com.lyms.talkonlineweb.util;
2 2  
  3 +import com.alibaba.fastjson.JSON;
3 4 import com.alibaba.fastjson.JSONObject;
  5 +import com.lyms.talkonlineweb.result.BaseResponse;
4 6 import lombok.extern.log4j.Log4j2;
  7 +import org.springframework.util.CollectionUtils;
5 8  
6 9 import java.util.HashMap;
7 10 import java.util.Map;
... ... @@ -60,7 +63,7 @@
60 63 * @param template_id 公众号消息模板id
61 64 * @param dataMap 推送内容消息主题显示相关map
62 65 */
63   - public static void SendWeChatMsg(String token,String openid,String template_id,Map<String,Object> dataMap) {
  66 + public static Integer SendWeChatMsg(String token, String openid, String template_id, Map<String,Object> dataMap) {
64 67 // 接口地址
65 68 String sendMsgApi = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token="+token;
66 69 //整体参数map
... ... @@ -68,7 +71,33 @@
68 71 paramMap.put("touser", openid);
69 72 paramMap.put("template_id", template_id);
70 73 paramMap.put("data", dataMap);
71   - System.out.println(HttpUtil.doGetPost(sendMsgApi,"POST",paramMap));
  74 + String result= repeatDoGetPost(sendMsgApi,"POST",paramMap);
  75 + if(StringUtil.isEmpty(result)){
  76 + return null;
  77 + }
  78 + Map<String,Object> resultMap = JSON.parseObject(result, HashMap.class);
  79 + return Integer.parseInt(resultMap.get("errcode").toString());
  80 +
  81 + }
  82 +
  83 + /**
  84 + * 网络超时-重新发送3次
  85 + */
  86 + public static String repeatDoGetPost(String sendMsgApi,String type,Map<String,Object> paramMap) {
  87 + for (int i = 1; i <= 3; i++) {
  88 + String result=HttpUtil.doGetPost(sendMsgApi,type,paramMap);
  89 + if (StringUtil.isEmpty(result)) {
  90 + try{
  91 + Thread.sleep(1000);
  92 + } catch (Exception e){
  93 + e.printStackTrace();
  94 + }
  95 + continue;
  96 + } else {
  97 + return result;
  98 + }
  99 + }
  100 + return null;
72 101 }
73 102  
74 103 }
talkonlineweb/src/main/resources/mapper/LymsPushMessagesMapper.xml View file @ 4fa7483
  1 +<?xml version="1.0" encoding="UTF-8"?>
  2 +<!DOCTYPE mapper
  3 + PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  4 + "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  5 +<mapper namespace="com.lyms.talkonlineweb.mapper.LymsPushMessagesMapper">
  6 +
  7 + <resultMap id="BaseResultMap" type="com.lyms.talkonlineweb.domain.LymsPushMessages">
  8 + <id property="id" column="id" jdbcType="INTEGER"/>
  9 + <result property="pid" column="pid" jdbcType="INTEGER"/>
  10 + <result property="pname" column="pname" jdbcType="VARCHAR"/>
  11 + <result property="hid" column="hid" jdbcType="INTEGER"/>
  12 + <result property="hname" column="hname" jdbcType="VARCHAR"/>
  13 + <result property="did" column="did" jdbcType="INTEGER"/>
  14 + <result property="dname" column="dname" jdbcType="VARCHAR"/>
  15 + <result property="dtid" column="dtid" jdbcType="INTEGER"/>
  16 + <result property="dtname" column="dtname" jdbcType="VARCHAR"/>
  17 + <result property="iid" column="iid" jdbcType="INTEGER"/>
  18 + <result property="iname" column="iname" jdbcType="VARCHAR"/>
  19 + <result property="ilid" column="ilid" jdbcType="INTEGER"/>
  20 + <result property="gzopenid" column="gzopenid" jdbcType="VARCHAR"/>
  21 + <result property="aid" column="aid" jdbcType="INTEGER"/>
  22 + <result property="atitle" column="atitle" jdbcType="VARCHAR"/>
  23 + <result property="acontent" column="acontent" jdbcType="VARCHAR"/>
  24 + <result property="serialnumber" column="serialNumber" jdbcType="INTEGER"/>
  25 + <result property="weixTextOne" column="weix_text_one" jdbcType="VARCHAR"/>
  26 + <result property="weixTextTwo" column="weix_text_two" jdbcType="VARCHAR"/>
  27 + <result property="isweixinOne" column="isweixin_one" jdbcType="INTEGER"/>
  28 + <result property="isweixinTwo" column="isweixin_two" jdbcType="INTEGER"/>
  29 + <result property="planTime" column="plan_time" jdbcType="TIMESTAMP"/>
  30 + </resultMap>
  31 +
  32 + <sql id="Base_Column_List">
  33 + id,pid,pname,
  34 + hid,hname,did,
  35 + dname,dtid,dtname,
  36 + iid,iname,ilid,
  37 + gzopenid,aid,atitle,
  38 + acontent,serialNumber,weix_text_one,
  39 + weix_text_two,isweixin_one,isweixin_two,
  40 + plan_time
  41 + </sql>
  42 +</mapper>