From 1637edb33d2ba27fe0f9dfb1f552a36684627306 Mon Sep 17 00:00:00 2001 From: shiyang <316555390@qq.com> Date: Mon, 11 Apr 2022 16:51:37 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=8F=E7=A8=8B=E5=BA=8F=E5=A4=9A=E4=BA=BA?= =?UTF-8?q?=E5=85=B3=E6=B3=A8=E4=B8=80=E4=B8=AA=E7=97=85=E4=BA=BA=E7=9F=AD?= =?UTF-8?q?=E6=B6=88=E6=81=AF=E6=8E=A8=E9=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/LymsPushAttentionRecord.java | 134 +++++++++++++++++++++ .../mapper/LymsPushAttentionRecordMapper.java | 15 +++ .../service/LymsPushAttentionRecordService.java | 11 ++ .../impl/LymsPushAttentionRecordServiceImpl.java | 20 +++ .../lyms/talkonlineweb/task/PushArticleTask.java | 67 ++++++++--- .../talkonlineweb/task/PushArticleTaskData.java | 49 ++++++-- .../mapper/LymsPushAttentionRecordMapper.xml | 26 ++++ 7 files changed, 296 insertions(+), 26 deletions(-) create mode 100644 talkonlineweb/src/main/java/com/lyms/talkonlineweb/domain/LymsPushAttentionRecord.java create mode 100644 talkonlineweb/src/main/java/com/lyms/talkonlineweb/mapper/LymsPushAttentionRecordMapper.java create mode 100644 talkonlineweb/src/main/java/com/lyms/talkonlineweb/service/LymsPushAttentionRecordService.java create mode 100644 talkonlineweb/src/main/java/com/lyms/talkonlineweb/service/impl/LymsPushAttentionRecordServiceImpl.java create mode 100644 talkonlineweb/src/main/resources/mapper/LymsPushAttentionRecordMapper.xml diff --git a/talkonlineweb/src/main/java/com/lyms/talkonlineweb/domain/LymsPushAttentionRecord.java b/talkonlineweb/src/main/java/com/lyms/talkonlineweb/domain/LymsPushAttentionRecord.java new file mode 100644 index 0000000..496cfee --- /dev/null +++ b/talkonlineweb/src/main/java/com/lyms/talkonlineweb/domain/LymsPushAttentionRecord.java @@ -0,0 +1,134 @@ +package com.lyms.talkonlineweb.domain; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import java.io.Serializable; +import java.util.Date; +import lombok.Data; + +/** + * 子女关注患者推送短文字记录 + * @TableName lyms_push_attention_record + */ +@TableName(value ="lyms_push_attention_record") +@Data +public class LymsPushAttentionRecord implements Serializable { + /** + * + */ + @TableId(value = "id", type = IdType.AUTO) + private Integer id; + + /** + * 推送子女的小程序用户id + */ + @TableField(value = "pid") + private Integer pid; + + /** + * 推送子女的公众号id + */ + @TableField(value = "p_gzopenid") + private String pGzopenid; + + /** + * 被关注患者id + */ + @TableField(value = "pa_id") + private Integer paId; + + /** + * 推送类型:1:短文字一,2:短文字二 + */ + @TableField(value = "pa_isweixin_type") + private Integer paIsweixinType; + + /** + * 被关注患者推送的短文字内容 + */ + @TableField(value = "pa_weix_text") + private String paWeixText; + + /** + * 推送状态 0待推送 1成功 2失败(在备注写失败原因) + */ + @TableField(value = "isweixin_state") + private Integer isweixinState; + + /** + * 备注。失败原因 + */ + @TableField(value = "remark") + private String remark; + + /** + * 推送时间 + */ + @TableField(value = "push_time") + private Date pushTime; + + + @TableField(exist = false) + private static final long serialVersionUID = 1L; + + @Override + public boolean equals(Object that) { + if (this == that) { + return true; + } + if (that == null) { + return false; + } + if (getClass() != that.getClass()) { + return false; + } + LymsPushAttentionRecord other = (LymsPushAttentionRecord) that; + return (this.getId() == null ? other.getId() == null : this.getId().equals(other.getId())) + && (this.getPid() == null ? other.getPid() == null : this.getPid().equals(other.getPid())) + && (this.getPGzopenid() == null ? other.getPGzopenid() == null : this.getPGzopenid().equals(other.getPGzopenid())) + && (this.getPaId() == null ? other.getPaId() == null : this.getPaId().equals(other.getPaId())) + && (this.getPaIsweixinType() == null ? other.getPaIsweixinType() == null : this.getPaIsweixinType().equals(other.getPaIsweixinType())) + && (this.getPaWeixText() == null ? other.getPaWeixText() == null : this.getPaWeixText().equals(other.getPaWeixText())) + && (this.getIsweixinState() == null ? other.getIsweixinState() == null : this.getIsweixinState().equals(other.getIsweixinState())) + && (this.getRemark() == null ? other.getRemark() == null : this.getRemark().equals(other.getRemark())) + && (this.getPushTime() == null ? other.getPushTime() == null : this.getPushTime().equals(other.getPushTime())); + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((getId() == null) ? 0 : getId().hashCode()); + result = prime * result + ((getPid() == null) ? 0 : getPid().hashCode()); + result = prime * result + ((getPGzopenid() == null) ? 0 : getPGzopenid().hashCode()); + result = prime * result + ((getPaId() == null) ? 0 : getPaId().hashCode()); + result = prime * result + ((getPaIsweixinType() == null) ? 0 : getPaIsweixinType().hashCode()); + result = prime * result + ((getPaWeixText() == null) ? 0 : getPaWeixText().hashCode()); + result = prime * result + ((getIsweixinState() == null) ? 0 : getIsweixinState().hashCode()); + result = prime * result + ((getRemark() == null) ? 0 : getRemark().hashCode()); + result = prime * result + ((getPushTime() == null) ? 0 : getPushTime().hashCode()); + return result; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append(getClass().getSimpleName()); + sb.append(" ["); + sb.append("Hash = ").append(hashCode()); + sb.append(", id=").append(id); + sb.append(", pid=").append(pid); + sb.append(", pGzopenid=").append(pGzopenid); + sb.append(", paId=").append(paId); + sb.append(", paIsweixinType=").append(paIsweixinType); + sb.append(", paWeixText=").append(paWeixText); + sb.append(", isweixinState=").append(isweixinState); + sb.append(", remark=").append(remark); + sb.append(", pushTime=").append(pushTime); + sb.append(", serialVersionUID=").append(serialVersionUID); + sb.append("]"); + return sb.toString(); + } +} \ No newline at end of file diff --git a/talkonlineweb/src/main/java/com/lyms/talkonlineweb/mapper/LymsPushAttentionRecordMapper.java b/talkonlineweb/src/main/java/com/lyms/talkonlineweb/mapper/LymsPushAttentionRecordMapper.java new file mode 100644 index 0000000..e74f3bf --- /dev/null +++ b/talkonlineweb/src/main/java/com/lyms/talkonlineweb/mapper/LymsPushAttentionRecordMapper.java @@ -0,0 +1,15 @@ +package com.lyms.talkonlineweb.mapper; + +import com.lyms.talkonlineweb.domain.LymsPushAttentionRecord; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; + +/** + * @Entity com.lyms.talkonlineweb.domain.LymsPushAttentionRecord + */ +public interface LymsPushAttentionRecordMapper extends BaseMapper { + +} + + + + diff --git a/talkonlineweb/src/main/java/com/lyms/talkonlineweb/service/LymsPushAttentionRecordService.java b/talkonlineweb/src/main/java/com/lyms/talkonlineweb/service/LymsPushAttentionRecordService.java new file mode 100644 index 0000000..c240fab --- /dev/null +++ b/talkonlineweb/src/main/java/com/lyms/talkonlineweb/service/LymsPushAttentionRecordService.java @@ -0,0 +1,11 @@ +package com.lyms.talkonlineweb.service; + +import com.lyms.talkonlineweb.domain.LymsPushAttentionRecord; +import com.baomidou.mybatisplus.extension.service.IService; + +/** + * + */ +public interface LymsPushAttentionRecordService extends IService { + +} diff --git a/talkonlineweb/src/main/java/com/lyms/talkonlineweb/service/impl/LymsPushAttentionRecordServiceImpl.java b/talkonlineweb/src/main/java/com/lyms/talkonlineweb/service/impl/LymsPushAttentionRecordServiceImpl.java new file mode 100644 index 0000000..635f955 --- /dev/null +++ b/talkonlineweb/src/main/java/com/lyms/talkonlineweb/service/impl/LymsPushAttentionRecordServiceImpl.java @@ -0,0 +1,20 @@ +package com.lyms.talkonlineweb.service.impl; + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.lyms.talkonlineweb.domain.LymsPushAttentionRecord; +import com.lyms.talkonlineweb.service.LymsPushAttentionRecordService; +import com.lyms.talkonlineweb.mapper.LymsPushAttentionRecordMapper; +import org.springframework.stereotype.Service; + +/** + * + */ +@Service +public class LymsPushAttentionRecordServiceImpl extends ServiceImpl + implements LymsPushAttentionRecordService{ + +} + + + + 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 6f612ce..e5bb6c0 100644 --- a/talkonlineweb/src/main/java/com/lyms/talkonlineweb/task/PushArticleTask.java +++ b/talkonlineweb/src/main/java/com/lyms/talkonlineweb/task/PushArticleTask.java @@ -14,6 +14,8 @@ import lombok.extern.log4j.Log4j2; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; +import org.springframework.transaction.annotation.Transactional; + import java.util.*; import static com.lyms.talkonlineweb.util.DateUtil.YYYY_MM_DD; @@ -41,12 +43,15 @@ public class PushArticleTask { @Autowired private LymsDictService lymsDictService; + @Autowired + public LymsPushAttentionRecordService lymsPushAttentionRecordService; /** * 每天18点执行文章推送 */ @Scheduled(cron = "0 0 18 * * ?") // @Scheduled(cron = "0 15 17 * * ?")//测试用 下午5点15 + @Transactional(rollbackFor = Exception.class) public void pushArtcle(){ Map param=new HashMap<>(); param.put("vtype",999); @@ -132,7 +137,7 @@ public class PushArticleTask { map.put("keyword3",new DataEntity(lymsPushMessage.getDname(),"#173177")); map.put("remark",new DataEntity("预祝您早日康复!","#173177")); //公众号跳转小程序需要的登录信息 - Map mapInfo =pLoginInfo(lymsPushMessage); + Map mapInfo =pLoginInfo(lymsPushMessage.getPid()); Integer code= WeiXinUtil.SendWeChatMsg(lymsPushMessage.getGzopenid(), Constant.GZ_TEMPLATE_ID,map,mapInfo); if(null==code||code!=0){ //更新到LymsPushMessages记录 @@ -156,6 +161,8 @@ public class PushArticleTask { lymsPushMessage.setState(1);//推送状态:0待推送 1成功 2失败。(在备注写失败原因) lymsPushMessage.setPushTime(new Date()); lymsPushMessagesService.updateById(lymsPushMessage); + //子女关注的患者推送短消息 + pushPatientAttention(lymsPushMessage,map); }else if(lymsPushMessage.getIsweixinTwo()==1){ //LymsPushedart的主键id赋值,表示修改。找到以前的推送记录,修改短文字的推送状态 pushedart.setId(lymsPushMessage.getPushedartId()); @@ -167,7 +174,7 @@ public class PushArticleTask { map.put("keyword3",new DataEntity(lymsPushMessage.getDname(),"#173177")); map.put("remark",new DataEntity("预祝您早日康复!","#173177")); //公众号跳转小程序需要的登录信息 - Map mapInfo =pLoginInfo(lymsPushMessage); + Map mapInfo =pLoginInfo(lymsPushMessage.getPid()); Integer code= WeiXinUtil.SendWeChatMsg(lymsPushMessage.getGzopenid(),Constant.GZ_TEMPLATE_ID,map,mapInfo); if(null==code||code!=0){ //更新到LymsPushMessages记录 @@ -189,6 +196,8 @@ public class PushArticleTask { lymsPushMessage.setState(1);//推送状态:0待推送 1成功 2失败。(在备注写失败原因) lymsPushMessage.setPushTime(new Date()); lymsPushMessagesService.updateById(lymsPushMessage); + //子女关注的患者推送短消息 + pushPatientAttention(lymsPushMessage,map); } } //更新到LymsPushMessages记录(推送的是文章的情况IsweixinOne和IsweixinTwo都是0的时候) @@ -201,28 +210,48 @@ public class PushArticleTask { } } } -public Map pLoginInfo(LymsPushMessages lymsPushMessage){ - //获取登录信息 - Map map=new HashMap<>(); - String plogin=null; - LymsPatient lymsPatient = lymsPatientService.getById(lymsPushMessage.getPid()); - if(StringUtil.isNotEmpty(lymsPatient.getEnrolmentPhone())){ + //用户登录id + public Map pLoginInfo(Integer pid){ + //获取登录信息 + Map map=new HashMap<>(); + String plogin=null; + LymsPatient lymsPatient = lymsPatientService.getById(pid); if(StringUtil.isNotEmpty(lymsPatient.getEnrolmentPhone())){ - plogin=lymsPatient.getEnrolmentPhone(); + if(StringUtil.isNotEmpty(lymsPatient.getEnrolmentPhone())){ + plogin=lymsPatient.getEnrolmentPhone(); + } + }else { + List pLst=patientInfoService.list(new QueryWrapper().eq("id", lymsPatient.getId())); + if(CollectionUtils.isNotEmpty(pLst)){ + plogin=pLst.get(0).getMobile(); + } } - - }else { - List pLst=patientInfoService.list(new QueryWrapper().eq("id", lymsPatient.getId()) - .eq("iid", lymsPushMessage.getIid())); - if(CollectionUtils.isNotEmpty(pLst)){ - plogin=pLst.get(0).getMobile(); + map.put("plogin", plogin); + map.put("passwd", lymsPatient.getPpasswd()); + return map; + } + //子女关注的患者推送短消息 + public void pushPatientAttention(LymsPushMessages lymsPushMessage,Map map){ + QueryWrapper queryWrapper=new QueryWrapper<>(); + queryWrapper.apply("TO_DAYS(created_time) = TO_DAYS(NOW()) and isweixin_state=0");//今天需要推送的消息 + final List pushAttentionRecords = lymsPushAttentionRecordService.list(queryWrapper); + for (LymsPushAttentionRecord pushAttentionRecord : pushAttentionRecords) { + Map mapInfo =pLoginInfo(pushAttentionRecord.getPid()); + Integer code= WeiXinUtil.SendWeChatMsg(pushAttentionRecord.getPGzopenid(),Constant.GZ_TEMPLATE_ID,map,mapInfo); + if(null==code||code!=0){ + //更新到 lyms_push_attention_record 记录 + pushAttentionRecord.setIsweixinState(2);//推送状态:0待推送 1成功 2失败。(在备注写失败原因) + pushAttentionRecord.setRemark("推送短消息"+pushAttentionRecord.getPaIsweixinType()+"失败!"+lymsPushMessage.getPname()+"; code:"+code); + pushAttentionRecord.setPushTime(new Date()); + lymsPushAttentionRecordService.updateById(pushAttentionRecord); + continue; + } + pushAttentionRecord.setIsweixinState(1);//推送状态:0待推送 1成功 2失败。(在备注写失败原因) + pushAttentionRecord.setPushTime(new Date()); + lymsPushAttentionRecordService.updateById(pushAttentionRecord); } } - map.put("plogin", plogin); - map.put("passwd", lymsPatient.getPpasswd()); - return map; -} } 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 832bb68..6452ee1 100644 --- a/talkonlineweb/src/main/java/com/lyms/talkonlineweb/task/PushArticleTaskData.java +++ b/talkonlineweb/src/main/java/com/lyms/talkonlineweb/task/PushArticleTaskData.java @@ -1,14 +1,14 @@ package com.lyms.talkonlineweb.task; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; -import com.lyms.talkonlineweb.domain.LymsDict; -import com.lyms.talkonlineweb.domain.LymsPushMessages; -import com.lyms.talkonlineweb.domain.LymsPushedart; -import com.lyms.talkonlineweb.domain.PushArticle; +import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.lyms.talkonlineweb.domain.*; import com.lyms.talkonlineweb.service.*; import com.lyms.talkonlineweb.util.DateUtil; import com.lyms.talkonlineweb.util.StringUtil; import com.lyms.talkonlineweb.util.WeiXinUtil; +import com.mysql.cj.Query; import lombok.Data; import lombok.extern.log4j.Log4j2; import org.springframework.beans.BeanUtils; @@ -16,7 +16,7 @@ import org.springframework.beans.BeansException; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; -import org.springframework.util.CollectionUtils; +import org.springframework.transaction.annotation.Transactional; import org.springframework.util.unit.DataUnit; import java.util.*; @@ -45,6 +45,13 @@ public class PushArticleTaskData { private LymsDictService lymsDictService; @Autowired public PushArticleTask pushArticleTask; + @Autowired + public LymsPushAttentionRecordService lymsPushAttentionRecordService; + @Autowired + private LymsPatientAttentionService lymsPatientAttentionService; + @Autowired + private LymsPatientService lymsPatientService;//患者 + /** @@ -52,6 +59,7 @@ public class PushArticleTaskData { */ @Scheduled(cron = "0 0 17 * * ?") // @Scheduled(cron = "0 */3 * * * ?")//测试用 + @Transactional(rollbackFor = Exception.class) public void pushArtcleData(){ Map param=new HashMap<>(); param.put("vtype",999); @@ -82,30 +90,57 @@ public class PushArticleTaskData { log.info("数据不同步,不需要推送>>>>>>"); return; } - if(!CollectionUtils.isEmpty(lymsPushedartList)){ + if(CollectionUtils.isNotEmpty(lymsPushedartList)){ //标记要推送的记录需要推送短消息2 lymsPushMessages.setIsweixinTwo(1); //存入已推送文章列表id lymsPushMessages.setPushedartId(lymsPushedartList.get(0).getId()); + //子女关注的患者要推送的短消息 + pushPatientAttention(lymsPushMessages); }else { //标记要推送的记录需要推送短消息1 lymsPushMessages.setIsweixinOne(1); //需要推送的短消息1 lymsPushMessagesService.save(lymsPushMessages); + //子女关注的患者要推送的短消息 + pushPatientAttention(lymsPushMessages); } //标记要推送的文章-短消息1标记为0说明这是推送的文章 lymsPushMessages.setIsweixinOne(0); //保存到要推送的表lyms_push_messages需要推送的文章 lymsPushMessagesService.save(lymsPushMessages); - } catch (BeansException e) { e.printStackTrace(); } } } // pushArticleTask.pushArtcle();//测试用 + } + //子女关注的患者要推送的短消息,数据构建 + public void pushPatientAttention(LymsPushMessages lymsPushMessages){ + if (null!=lymsPushMessages.getPid()) { + final List lymsPatientAttentions = lymsPatientAttentionService.list(new QueryWrapper().eq("attention_id", lymsPushMessages.getPid())); + for (LymsPatientAttention lymsPatientAttention : lymsPatientAttentions) { + final LymsPatient patient = lymsPatientService.getOne(new QueryWrapper().eq("id", lymsPatientAttention.getPid())); + if (null!=patient.getId()) { + LymsPushAttentionRecord attentionRecord=new LymsPushAttentionRecord(); + attentionRecord.setPid(patient.getId()); + attentionRecord.setPGzopenid(patient.getGzopenid()); + attentionRecord.setPaId(lymsPushMessages.getPid()); + if(null!=lymsPushMessages.getIsweixinOne() && 1==lymsPushMessages.getIsweixinOne()) { + attentionRecord.setPaIsweixinType(1); + attentionRecord.setPaWeixText(lymsPushMessages.getWeixTextOne()); + }else { + attentionRecord.setPaIsweixinType(2); + attentionRecord.setPaWeixText(lymsPushMessages.getWeixTextTwo()); + } + lymsPushAttentionRecordService.save(attentionRecord); + } + } + } + } } diff --git a/talkonlineweb/src/main/resources/mapper/LymsPushAttentionRecordMapper.xml b/talkonlineweb/src/main/resources/mapper/LymsPushAttentionRecordMapper.xml new file mode 100644 index 0000000..de214a0 --- /dev/null +++ b/talkonlineweb/src/main/resources/mapper/LymsPushAttentionRecordMapper.xml @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + id,pid,p_gzopenid, + pa_id,pa_isweixin_type,pa_weix_text, + isweixin_state,remark,push_time, + created_time + + -- 1.8.3.1