配置场馆和管理员挂钩发送微信消息

This commit is contained in:
2023-07-25 22:59:42 +08:00
parent 4c09422a45
commit d1fbab35ac
10 changed files with 323 additions and 31 deletions

View File

@@ -0,0 +1,22 @@
package com.sv.mapper;
import com.ydd.oms.entity.sys.WxConfig;
import java.util.List;
public interface WxConfigMapper {
int deleteByPrimaryKey(Integer id);
int insert(WxConfig record);
int insertSelective(WxConfig record);
WxConfig selectByPrimaryKey(Integer id);
int updateByPrimaryKeySelective(WxConfig record);
int updateByPrimaryKey(WxConfig record);
List<WxConfig> list();
}

View File

@@ -403,7 +403,7 @@ public class MemberLessonTicketService extends BaseServiceImpl {
String lessonTime = DateUtilCard.getStrFromDate(venueLesson.getDate()) + " " + venueLesson.getStartTime().toString();
String typeName = VenueTypeEnum.getByValue(venue.getType()).name;
String url = Constants.VENUE_VIEW_URL + venueId;
AsyncTaskUtil.INSTANCE.submit(new NotifyAdminMsgThread(venue.getName(),venueLesson.getName(),lessonTime,typeName,url));
AsyncTaskUtil.INSTANCE.submit(new NotifyAdminMsgThread(venueId,venue.getName(),venueLesson.getName(),lessonTime,typeName,url));
}
}

View File

@@ -2,21 +2,25 @@ package com.sv.service.message;
import com.dw.ccm.wechat.base.utils.JsonUtils;
import com.sv.mapper.ConfigMapper;
import com.sv.mapper.WxConfigMapper;
import com.sv.service.utils.SpringUtils;
import com.ydd.oms.entity.sys.Config;
import com.ydd.oms.entity.sys.WxConfig;
import org.springframework.util.StringUtils;
import java.util.List;
public class NotifyAdminMsgThread extends Thread{
private Integer venueId = 0;
private String venueName = "";
private String lessonName = "";
private String lessonTime = "";
private String venueType = "";
private String url = "";
public NotifyAdminMsgThread(String venueName, String lessonName, String lessonTime, String venueType, String url) {
public NotifyAdminMsgThread(Integer venueId,String venueName, String lessonName, String lessonTime, String venueType, String url) {
this.venueId = venueId;
this.venueName = venueName;
this.lessonName = lessonName;
this.lessonTime = lessonTime;
@@ -24,6 +28,14 @@ public class NotifyAdminMsgThread extends Thread{
this.url = url;
}
public Integer getVenueId() {
return venueId;
}
public void setVenueId(Integer venueId) {
this.venueId = venueId;
}
public String getUrl() {
return url;
}
@@ -72,13 +84,9 @@ public class NotifyAdminMsgThread extends Thread{
if (all == null || all.size() <= 0 ){
return;
}
String openId = null;
String webHook = null;
String dingSecret = null;
for (Config config : all) {
if ("WX_ADMIN".equals(config.getKey())) {
openId = config.getValue();
}
if ("DING_WEBHOOK".equals(config.getKey())) {
webHook = config.getValue();
}
@@ -87,10 +95,12 @@ public class NotifyAdminMsgThread extends Thread{
}
}
SendMsg sendMsg = new SendMsg(venueName,lessonName,lessonTime,venueType,url);
if (!StringUtils.isEmpty(openId)) {
String[] split = openId.split(",");
for (String s : split) {
WeiXinSendUtils.sendCard(sendMsg,s);
WxConfigMapper wxConfigMapper = SpringUtils.getBean(WxConfigMapper.class);
List<WxConfig> configs = wxConfigMapper.list();
for (WxConfig config : configs) {
if (venueId == config.getVenueId()) {
WeiXinSendUtils xinSendUtils = SpringUtils.getBean(WeiXinSendUtils.class);
xinSendUtils.sendCard(sendMsg,config.getWxOpenId());
}
}
if (!StringUtils.isEmpty(webHook) && !StringUtils.isEmpty(dingSecret)) {

View File

@@ -3,30 +3,53 @@ package com.sv.service.message;
import com.dw.ccm.wechat.base.WeChat;
import com.dw.ccm.wechat.base.WeChatHelper;
import com.dw.ccm.wechat.base.message.response.AccessTokenResponse;
import com.dw.ccm.wechat.base.message.response.template.TemplateResponse;
import com.dw.ccm.wechat.base.message.template.Attribute;
import com.dw.ccm.wechat.base.message.template.TemplateMessage;
import org.springframework.util.StringUtils;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.util.HashMap;
public class WeiXinSendUtils {
@Component
public class WeiXinSendUtils implements InitializingBean {
public static void sendCard(SendMsg sendMsg,String openId){
AccessTokenResponse accessToken = WeChatHelper.getAccessToken("wx51d82eba3f5f4858", "d28320bcb885cc208b6fde2253d8663e");
String token = accessToken.getAccessToken();
if (!StringUtils.isEmpty(token)){
WeChat weChat = WeChatHelper.getWeChat(token);
TemplateMessage templateMessage = new TemplateMessage();
templateMessage.setTemplateId("vPRolOW7D3jnXhT4uqN4FOcIIuHcsHuresbZjlPBg9Y");
templateMessage.setToUser(openId);
templateMessage.setUrl(sendMsg.getViewUrl());
HashMap<String, Attribute> attr = new HashMap<>();
attr.put("thing2",new Attribute(sendMsg.getVenueName(),""));
attr.put("thing3",new Attribute(sendMsg.getLessonName(),""));
attr.put("time5",new Attribute(sendMsg.getLessonTime(),""));
attr.put("phrase7",new Attribute(sendMsg.getVenueType(),""));
templateMessage.setAttributes(attr);
private String token;
public void sendCard(SendMsg sendMsg,String openId){
WeChat weChat = WeChatHelper.getWeChat(token);
TemplateMessage templateMessage = new TemplateMessage();
templateMessage.setTemplateId("vPRolOW7D3jnXhT4uqN4FOcIIuHcsHuresbZjlPBg9Y");
templateMessage.setToUser(openId);
templateMessage.setUrl(sendMsg.getViewUrl());
HashMap<String, Attribute> attr = new HashMap<>();
attr.put("thing2",new Attribute(sendMsg.getVenueName(),""));
attr.put("thing3",new Attribute(sendMsg.getLessonName(),""));
attr.put("time5",new Attribute(sendMsg.getLessonTime(),""));
attr.put("phrase7",new Attribute(sendMsg.getVenueType(),""));
templateMessage.setAttributes(attr);
TemplateResponse templateResponse = weChat.sendTemplate(templateMessage);
if (templateResponse.getErrCode() == 42001) {
//access_token expired
getToken();
weChat.sendTemplate(templateMessage);
}
}
@Override
public void afterPropertiesSet() throws Exception {
getToken();
}
private void getToken() {
AccessTokenResponse accessToken = WeChatHelper.getAccessToken("wx51d82eba3f5f4858", "d28320bcb885cc208b6fde2253d8663e");
token = accessToken.getAccessToken();
}
@Scheduled(fixedDelay=60*60*1000)
public void refreshToken() {
getToken();
}
}

View File

@@ -621,7 +621,7 @@
<select id="getLessonTypes" resultType="string">
select DISTINCT start_time from sv_venue_lesson a
where DATE(a.date) <![CDATA[ >= ]]> CURRENT_DATE
AND DATE(a.date) <![CDATA[ <= ]]> DATE_ADD(CURRENT_DATE,INTERVAL 4 DAY)
AND DATE(a.date) <![CDATA[ <= ]]> DATE_ADD(CURRENT_DATE,INTERVAL 7 DAY)
and a.venue_id = #{venueId}
ORDER BY a.start_time
</select>

View File

@@ -0,0 +1,126 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.sv.mapper.WxConfigMapper" >
<resultMap id="BaseResultMap" type="com.ydd.oms.entity.sys.WxConfig" >
<constructor >
<idArg column="id" jdbcType="INTEGER" javaType="java.lang.Integer" />
<arg column="wx_open_id" jdbcType="VARCHAR" javaType="java.lang.String" />
<arg column="venue_id" jdbcType="INTEGER" javaType="java.lang.Integer" />
<arg column="created_id" jdbcType="INTEGER" javaType="java.lang.Integer" />
<arg column="modified_id" jdbcType="INTEGER" javaType="java.lang.Integer" />
<arg column="created_time" jdbcType="TIMESTAMP" javaType="java.util.Date" />
<arg column="modified_time" jdbcType="TIMESTAMP" javaType="java.util.Date" />
</constructor>
</resultMap>
<sql id="Base_Column_List" >
id, wx_open_id, venue_id, created_id, modified_id, created_time, modified_time
</sql>
<select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
select
<include refid="Base_Column_List" />
from sys_wx_config
where id = #{id,jdbcType=INTEGER}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
delete from sys_wx_config
where id = #{id,jdbcType=INTEGER}
</delete>
<insert id="insert" parameterType="com.ydd.oms.entity.sys.WxConfig" >
insert into sys_wx_config (id, wx_open_id, venue_id,
created_id, modified_id, created_time,
modified_time)
values (#{id,jdbcType=INTEGER}, #{wxOpenId,jdbcType=VARCHAR}, #{venueId,jdbcType=INTEGER},
#{createdId,jdbcType=INTEGER}, #{modifiedId,jdbcType=INTEGER}, #{createdTime,jdbcType=TIMESTAMP},
#{modifiedTime,jdbcType=TIMESTAMP})
</insert>
<insert id="insertSelective" parameterType="com.ydd.oms.entity.sys.WxConfig" >
insert into sys_wx_config
<trim prefix="(" suffix=")" suffixOverrides="," >
<if test="id != null" >
id,
</if>
<if test="wxOpenId != null" >
wx_open_id,
</if>
<if test="venueId != null" >
venue_id,
</if>
<if test="createdId != null" >
created_id,
</if>
<if test="modifiedId != null" >
modified_id,
</if>
<if test="createdTime != null" >
created_time,
</if>
<if test="modifiedTime != null" >
modified_time,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides="," >
<if test="id != null" >
#{id,jdbcType=INTEGER},
</if>
<if test="wxOpenId != null" >
#{wxOpenId,jdbcType=VARCHAR},
</if>
<if test="venueId != null" >
#{venueId,jdbcType=INTEGER},
</if>
<if test="createdId != null" >
#{createdId,jdbcType=INTEGER},
</if>
<if test="modifiedId != null" >
#{modifiedId,jdbcType=INTEGER},
</if>
<if test="createdTime != null" >
#{createdTime,jdbcType=TIMESTAMP},
</if>
<if test="modifiedTime != null" >
#{modifiedTime,jdbcType=TIMESTAMP},
</if>
</trim>
</insert>
<update id="updateByPrimaryKeySelective" parameterType="com.ydd.oms.entity.sys.WxConfig" >
update sys_wx_config
<set >
<if test="wxOpenId != null" >
wx_open_id = #{wxOpenId,jdbcType=VARCHAR},
</if>
<if test="venueId != null" >
venue_id = #{venueId,jdbcType=INTEGER},
</if>
<if test="createdId != null" >
created_id = #{createdId,jdbcType=INTEGER},
</if>
<if test="modifiedId != null" >
modified_id = #{modifiedId,jdbcType=INTEGER},
</if>
<if test="createdTime != null" >
created_time = #{createdTime,jdbcType=TIMESTAMP},
</if>
<if test="modifiedTime != null" >
modified_time = #{modifiedTime,jdbcType=TIMESTAMP},
</if>
</set>
where id = #{id,jdbcType=INTEGER}
</update>
<update id="updateByPrimaryKey" parameterType="com.ydd.oms.entity.sys.WxConfig" >
update sys_wx_config
set wx_open_id = #{wxOpenId,jdbcType=VARCHAR},
venue_id = #{venueId,jdbcType=INTEGER},
created_id = #{createdId,jdbcType=INTEGER},
modified_id = #{modifiedId,jdbcType=INTEGER},
created_time = #{createdTime,jdbcType=TIMESTAMP},
modified_time = #{modifiedTime,jdbcType=TIMESTAMP}
where id = #{id,jdbcType=INTEGER}
</update>
<select id="list" resultMap="BaseResultMap" >
select
<include refid="Base_Column_List" />
from sys_wx_config
</select>
</mapper>

View File

@@ -90,7 +90,7 @@
domainObjectName 给表对应的 model 起名字
注意:大小写敏感问题。
-->
<table tableName="sv_health_docs" domainObjectName="HealthDoc"
<table tableName="sys_wx_config" domainObjectName="WxConfig"
enableInsert="true"
enableDeleteByPrimaryKey="true"
enableSelectByPrimaryKey="true"