保存信息修改

This commit is contained in:
yiyan 2019-05-26 15:30:52 +08:00
parent 7b2c9f46a0
commit 22aa395392
20 changed files with 235 additions and 148 deletions

View File

@ -155,6 +155,12 @@
<version>${mybatis-spring.version}</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-pool2</artifactId>
<version>2.6.2</version>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>

View File

@ -38,13 +38,13 @@ public class TblPushList {
private String pushContext;
private LocalDateTime createTime;
private LocalDateTime createTime = LocalDateTime.now();
private String pushLink;
private String jpushStatus;
private String neteaseStatus;
private String neteaseStatus = "1";
private Integer reportId;
@ -58,5 +58,5 @@ public class TblPushList {
private Integer number5;
private Integer isRead;
}

View File

@ -0,0 +1,50 @@
package com.ifish7.mq.business.user.entity;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import lombok.experimental.Accessors;
import java.time.LocalTime;
/**
* <p>
*
* </p>
*
* @author yan.y
* @since 2019-04-13
*/
@Data
@Accessors(chain = true)
@TableName("tbl_push_user_device")
public class TblPushUserDevice {
private static final long serialVersionUID = 1L;
/**
* 主键
*/
private Integer pushId;
/**
* 用户ID
*/
private Integer pushUserId;
/**
* 设备ID
*/
private String pushDeviceId;
/**
* 设备绑定时间
*/
private LocalTime pushBindTime;
/**
* 设备绑定类型
*/
private String pushBindType;
}

View File

@ -75,6 +75,4 @@ public class TblUser {
private Double latitude;
private Double longitude;
}

View File

@ -0,0 +1,16 @@
package com.ifish7.mq.business.user.mapper;
import com.ifish7.mq.business.user.entity.TblPushUserDevice;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
/**
* <p>
* Mapper 接口
* </p>
*
* @author yan.y
* @since 2019-04-13
*/
public interface TblPushUserDeviceMapper extends BaseMapper<TblPushUserDevice> {
}

View File

@ -0,0 +1,16 @@
package com.ifish7.mq.business.user.service;
import com.ifish7.mq.business.user.entity.TblPushUserDevice;
import com.baomidou.mybatisplus.extension.service.IService;
/**
* <p>
* 服务类
* </p>
*
* @author yan.y
* @since 2019-04-13
*/
public interface ITblPushUserDeviceService extends IService<TblPushUserDevice> {
}

View File

@ -1,18 +1,23 @@
package com.ifish7.mq.push;
import com.alibaba.fastjson.JSONObject;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.http.FormatType;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.push.model.v20160801.PushRequest;
import com.aliyuncs.push.model.v20160801.PushResponse;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ifish7.mq.business.user.entity.TblPushList;
import com.ifish7.mq.business.user.entity.TblPushUserDevice;
import com.ifish7.mq.business.user.entity.TblUser;
import com.ifish7.mq.business.user.service.ITblPushListService;
import com.ifish7.mq.business.user.service.ITblPushUserDeviceService;
import com.ifish7.mq.business.user.service.ITblUserService;
import lombok.extern.log4j.Log4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import java.time.LocalDateTime;
import java.util.List;
/**
* @author: yan.y
@ -31,7 +36,9 @@ public class AliyunPushApi {
//推送target类型
private static final String TARGET_TYPE = "DEVICE";
//推送类型
private static final String PUSH_TYPE = "MESSAGE";
private static final String PUSH_TYPE = "NOTICE";
//推送类型 ALL
private static final String PHONE_TYPE = "ALL";
@Autowired
private PushRequest pushRequest;
@ -39,54 +46,67 @@ public class AliyunPushApi {
@Autowired
private ITblPushListService pushListService;
public void advancedPush(JSONObject json){
@Autowired
private ITblUserService userService;
//推送目标
//DEVICE:根据设备推送
//ACCOUNT:根据账号推送
//ALIAS:根据别名推送
//TAG:根据标签推送
//ALL:推送给全部设备
pushRequest.setTarget(TARGET_TYPE);
@Autowired
private ITblPushUserDeviceService pushUserDeviceService;
public void advancedPush(TblPushList pushList){
pushRequest.setAcceptFormat(FormatType.JSON);
//根据Target来设定多个值使用逗号分隔
//此处应该查询出用户所对应的deviceId
pushRequest.setTargetValue(json.getString("deviceId"));
//推送类型
pushRequest.setPushType(PUSH_TYPE);
//推送设备类型
pushRequest.setDeviceType(json.getString("phoneType"));
// 消息的标题
pushRequest.setTitle(json.getString("title"));
// 消息的内容
pushRequest.setBody(json.getString("body"));
// 离线消息是否保存,若保存, 在推送时候用户即使不在线下一次上线则会收到
pushRequest.setStoreOffline(true);
String deviceIds = getUserDevices(String.valueOf(pushList.getUserId()));
//如果次用户未绑定设备 不推送
if (StringUtils.isNotBlank(deviceIds)) {
//推送目标
//DEVICE:根据设备推送
//ACCOUNT:根据账号推送
//ALIAS:根据别名推送
//TAG:根据标签推送
//ALL:推送给全部设备
pushRequest.setTarget(TARGET_TYPE);
//响应数据
pushRequest.setAcceptFormat(FormatType.JSON);
pushRequest.setTargetValue(deviceIds);
//推送类型
pushRequest.setPushType(PUSH_TYPE);
//推送设备类型
pushRequest.setDeviceType(PHONE_TYPE);
// 消息的标题
pushRequest.setTitle(pushList.getPushTitle());
// 消息的内容
pushRequest.setBody(pushList.getPushContext());
// 离线消息是否保存,若保存, 在推送时候用户即使不在线下一次上线则会收到
pushRequest.setStoreOffline(true);
try {
PushResponse response = client.getAcsResponse(pushRequest);
TblPushList pushList = new TblPushList();
pushList.setUserId(json.getInteger("userId"));
pushList.setDeviceId(json.getInteger("deviceId"));
pushList.setShowName(json.getString("showName"));
pushList.setPhoneType(json.getString("phoneType"));
pushList.setPushType(json.getString("pushType"));
pushList.setPushTitle(json.getString("title"));
pushList.setPushContext(json.getString("body"));
pushList.setJpushStatus(response.getMessageId());
pushList.setNeteaseStatus("1");
pushList.setCreateTime(LocalDateTime.now());
pushList.setNumber1(json.getInteger("number1"));
pushList.setNumber2(json.getInteger("number2"));
pushList.setNumber3(json.getInteger("number3"));
pushList.setNumber4(json.getInteger("number4"));
pushList.setNumber5(json.getInteger("number5"));
pushListService.save(pushList);
} catch (ClientException e) {
log.error(e.getMessage(),e);
//android通知设置
pushRequest.setAndroidOpenType("APPLICATION");
pushRequest.setAndroidNotifyType("BOTH");
pushRequest.setAndroidNotificationChannel("1");
try {
PushResponse response = client.getAcsResponse(pushRequest);
pushList.setReportId(Integer.parseInt(response.getMessageId()));
//未读
pushList.setIsRead(1);
pushListService.save(pushList);
} catch (ClientException e) {
log.error(e.getMessage(),e);
}
} else {
log.info(String.format("user : '%s' not bind device ",pushList.getUserId()));
}
}
private String getUserDevices(String userId){
//查询出userId所对应的所有的deviceId
List<TblPushUserDevice> pushUserDevices = pushUserDeviceService.list(new QueryWrapper<TblPushUserDevice>().lambda().eq(TblPushUserDevice::getPushUserId, userId));
StringBuilder deviceIds = new StringBuilder();
for (TblPushUserDevice pushUserDevice : pushUserDevices) {
deviceIds.append(pushUserDevice.getPushDeviceId()).append(",");
}
return deviceIds.toString();
}
}

View File

@ -1,8 +1,9 @@
package com.ifish7.mq.queues.event;
import com.alibaba.fastjson.JSONObject;
import com.ifish7.mq.business.user.entity.TblPushList;
import com.ifish7.mq.push.AliyunPushApi;
import com.ifish7.mq.utils.AppBeans;
import lombok.extern.log4j.Log4j;
/**
* @author: yan.y
@ -10,14 +11,17 @@ import com.ifish7.mq.utils.AppBeans;
* @Date: Created in 15:23 2019-04-10
* @Modified by:
*/
@Log4j
public class PushNotifcationEvent {
/**
* 设备通知增强版
* @param eventBody 事件体
* @param eventEntity 事件体
*/
private void deviceNotifcationPlus(JSONObject eventBody){
private void deviceNotifcationPlus(Object eventEntity){
log.info("deviceNotifcationPlus eventEntity : " + eventEntity);
TblPushList pushList= (TblPushList) eventEntity;
AliyunPushApi aliyunPushApi = AppBeans.getBean(AliyunPushApi.class);
aliyunPushApi.advancedPush(eventBody);
aliyunPushApi.advancedPush(pushList);
}
}

View File

@ -2,28 +2,30 @@ package com.ifish7.mq.queues.event.support;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import lombok.Data;
import lombok.extern.log4j.Log4j;
import java.lang.reflect.Method;
/**
* @author: yan.y
* @Description: 数据事件总线处理
* @Description: 事件总线处理
* @Date: Created in 22:15 2019/4/9
*/
@Log4j
public class DataEventSupport {
@Data
public class EventSupport {
//事件处理类型
protected String eventProcess;
private String eventProcess;
//事件名称
protected String eventName;
private String eventName;
//事件体
protected String eventBody;
private String eventBody;
//事件体对象
protected Object eventEntity;
private Object eventEntity;
//事件处理
public void process() {
@ -46,8 +48,6 @@ public class DataEventSupport {
} catch (Exception e) {
log.error(e.getMessage(),e);
}
}
}

View File

@ -1,36 +0,0 @@
package com.ifish7.mq.queues.event.support;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.log4j.Log4j;
import java.lang.reflect.Method;
/**
* @author: yan.y
* @Description: 推送事件总线处理
* @Date: Created in 23:24 2019/4/10
*/
@Log4j
public class PushEventSupport {
//事件处理类型
protected String eventProcess;
//事件名称
protected String eventName;
//事件体
protected JSONObject eventBody;
//事件处理
public void process() {
try {
Class<?> eventClazz = Class.forName(this.eventName);
Method method = eventClazz.getDeclaredMethod(this.eventProcess,Object.class);
method.setAccessible(true);
method.invoke(eventClazz.newInstance(),this.eventBody);
} catch (Exception e) {
log.info(e.getMessage(),e);
}
}
}

View File

@ -1,7 +1,7 @@
package com.ifish7.mq.queues.listener;
import com.alibaba.fastjson.JSON;
import com.ifish7.mq.queues.event.support.DataEventSupport;
import com.ifish7.mq.queues.event.support.EventSupport;
import lombok.extern.log4j.Log4j;
import javax.jms.JMSException;
@ -23,8 +23,8 @@ public class IfishDataQueueMessageListener implements MessageListener{
TextMessage tm = (TextMessage) message;
try {
log.info("Ifish7 - Data : " + tm.getText());
DataEventSupport dataEventSupport = JSON.parseObject(tm.getText(), DataEventSupport.class);
dataEventSupport.process();
EventSupport eventSupport = JSON.parseObject(tm.getText(), EventSupport.class);
eventSupport.process();
} catch (JMSException e) {
log.error(e);
}

View File

@ -1,5 +1,7 @@
package com.ifish7.mq.queues.listener;
import com.alibaba.fastjson.JSON;
import com.ifish7.mq.queues.event.support.EventSupport;
import lombok.extern.log4j.Log4j;
import javax.jms.JMSException;
@ -20,8 +22,10 @@ public class IfishPushQueueMessageListener implements MessageListener {
TextMessage tm = (TextMessage) message;
try {
log.info("Ifish7 - Push : " + tm.getText());
EventSupport eventSupport = JSON.parseObject(tm.getText(), EventSupport.class);
eventSupport.process();
} catch (JMSException e) {
log.error(e);
log.error(e.getMessage(),e);
}
}
}

View File

@ -54,11 +54,11 @@ public class MybatisCodeGenerator {
// 数据源配置
DataSourceConfig dsc = new DataSourceConfig();
dsc.setUrl("jdbc:mysql://localhost:3306/myfishdb?useUnicode=true&useSSL=false&characterEncoding=utf8");
dsc.setUrl("jdbc:mysql://139.196.24.156:3306/myfishdb?useUnicode=true&useSSL=false&characterEncoding=utf8");
// dsc.setSchemaName("public");
dsc.setDriverName("com.mysql.jdbc.Driver");
dsc.setUsername("root");
dsc.setPassword("123456");
dsc.setPassword("ifish7mysql");
mpg.setDataSource(dsc);
// 包配置

View File

@ -5,7 +5,6 @@ log4j.appender.Console.Target=System.out
#\u53EF\u4EE5\u7075\u6D3B\u5730\u6307\u5B9A\u65E5\u5FD7\u8F93\u51FA\u683C\u5F0F\uFF0C\u4E0B\u9762\u4E00\u884C\u662F\u6307\u5B9A\u5177\u4F53\u7684\u683C\u5F0F
log4j.appender.Console.layout = org.apache.log4j.PatternLayout
log4j.appender.Console.layout.ConversionPattern=[ifishMQ][%c] - %m%n
#\u6587\u4EF6\u5927\u5C0F\u5230\u8FBE\u6307\u5B9A\u5C3A\u5BF8\u7684\u65F6\u5019\u4EA7\u751F\u4E00\u4E2A\u65B0\u7684\u6587\u4EF6
log4j.appender.File = org.apache.log4j.RollingFileAppender
#\u6307\u5B9A\u8F93\u51FA\u76EE\u5F55
@ -16,3 +15,5 @@ log4j.appender.File.MaxFileSize = 100
log4j.appender.File.Threshold = ALL
log4j.appender.File.layout = org.apache.log4j.PatternLayout
log4j.appender.File.layout.ConversionPattern =[ifishMQ][%p] [%d{yyyy-MM-dd HH\:mm\:ss}][%c]%m%n
log4j.logger.org.apache.activemq=INFO

View File

@ -0,0 +1,5 @@
<?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.ifish7.mq.business.user.mapper.TblPushUserDeviceMapper">
</mapper>

View File

@ -1,5 +1,6 @@
broker_url=tcp://localhost:61616
broker_url=tcp://test.ifish7.com:61616
username=admin
password=admin
#password=admin
password=adminifish7
queue_data_name=ifishDataMq
queue_push_name=ifishPushMq

View File

@ -1,6 +1,6 @@
accessKeyId= LTAIfZaosFH5IWlD
accessKeySecret = dvlE8eFii31BcGb8HzkGz3eSaJ6Y94
appKey = 23252055
appKey = 26023230
#\u76EE\u524D\u8BE5\u503C\u56FA\u5B9A\uFF0C\u4E0D\u7528\u52A8
regionId = cn-hangzhou

View File

@ -1,22 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:amq="http://activemq.apache.org/schema/core"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.1.xsd
http://activemq.apache.org/schema/core
http://activemq.apache.org/schema/core/activemq-core-5.14.1.xsd">
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.1.xsd">
<amq:connectionFactory id="amqConnectionFactory"
brokerURL="${broker_url}"
userName="${username}"
password="${password}" />
<bean id="connectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory" >
<property name="brokerURL" value="${broker_url}" />
<property name="userName" value="${username}" />
<property name="password" value="${password}" />
</bean>
<!-- 配置JMS连接工长 -->
<bean id="connectionFactory"
class="org.springframework.jms.connection.CachingConnectionFactory">
<constructor-arg ref="amqConnectionFactory" />
<property name="sessionCacheSize" value="100" />
<bean id="jmsFactory" class="org.apache.activemq.pool.PooledConnectionFactory"
destroy-method="stop">
<property name="connectionFactory" ref="connectionFactory"/>
<property name="maxConnections" value="100"></property>
</bean>
<!--使用缓存可以提升效率-->
<bean id="cachingConnectionFactory" class="org.springframework.jms.connection.CachingConnectionFactory">
<property name="targetConnectionFactory" ref="jmsFactory"/>
<property name="sessionCacheSize" value="1"/>
</bean>
<bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate">
<property name="connectionFactory" ref="cachingConnectionFactory"/>
<property name="messageConverter">
<bean class="org.springframework.jms.support.converter.SimpleMessageConverter"/>
</property>
</bean>
<!-- 定义数据存储消息队列Queue -->
@ -41,29 +49,17 @@
<!-- 监听 -->
<bean id="queueDataListenerContainer"
class="org.springframework.jms.listener.DefaultMessageListenerContainer">
<property name="connectionFactory" ref="connectionFactory" />
<property name="connectionFactory" ref="cachingConnectionFactory" />
<property name="destination" ref="ifish7DataQueueDestination" />
<property name="messageListener" ref="ifishDataQueueMessageListener" />
</bean>
<bean id="queuePushListenerContainer"
class="org.springframework.jms.listener.DefaultMessageListenerContainer">
<property name="connectionFactory" ref="connectionFactory" />
<property name="connectionFactory" ref="cachingConnectionFactory" />
<property name="destination" ref="ifish7PushQueueDestination" />
<property name="messageListener" ref="ifishPushQueueMessageListener" />
</bean>
<!-- topics -->
<bean id="topicDestination" class="org.apache.activemq.command.ActiveMQTopic">
<constructor-arg value="ruixin/2a"/>
</bean>
<bean id="consumerSessionAwareMessageListener" class="com.ifish7.mq.mqtt.client.ClientMqttMessageListener"/>
<bean id="sessionAwareListenerContainer" class="org.springframework.jms.listener.DefaultMessageListenerContainer">
<property name="connectionFactory" ref="connectionFactory" />
<property name="destination" ref="topicDestination" />
<property name="messageListener" ref="consumerSessionAwareMessageListener" />
</bean>
</beans>

View File

@ -50,7 +50,7 @@
<bean id="sqlSessionFactory" class="com.ifish7.mq.utils.MybatisSqlSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<!-- 自动扫描mapping.xml文件 -->
<property name="mapperLocations" value="classpath:mapper/*/*.xml"></property>
<!--<property name="mapperLocations" value="classpath:mapper/*/*.xml"></property>-->
</bean>
<!-- DAO接口所在包名Spring会自动查找其下的类 -->

View File

@ -27,7 +27,7 @@ public class AliyunPushApiTest {
IClientProfile profile = DefaultProfile.getProfile("cn-hangzhou", "LTAIfZaosFH5IWlD", "dvlE8eFii31BcGb8HzkGz3eSaJ6Y94");
DefaultAcsClient client = new DefaultAcsClient(profile);
PushRequest pushRequest = new PushRequest();
pushRequest.setAppKey(23252055l);
pushRequest.setAppKey(26023230l);
pushRequest.setSysProtocol(ProtocolType.HTTPS);
pushRequest.setSysMethod(MethodType.POST);
pushRequest.setStoreOffline(true);
@ -45,15 +45,21 @@ public class AliyunPushApiTest {
pushRequest.setAcceptFormat(FormatType.JSON);
//根据Target来设定多个值使用逗号分隔
//此处应该查询出用户所对应的deviceId
pushRequest.setTargetValue("18aujhs872ysgd6tx7329oaliygx7432");
pushRequest.setTargetValue("c17c0590e8254b6b977b8fd7706fa8c2");
//推送类型
pushRequest.setPushType("MESSAGE");
pushRequest.setPushType("NOTICE");
//推送设备类型
pushRequest.setDeviceType("ANDROID");
// 消息的标题
pushRequest.setTitle("温度报警");
// 消息的内容
pushRequest.setBody("[温度报警]你的水族箱\"鱼缸1234\"在2019-04-10 23:40:00,温度达到29℃,已高于28℃,请及时查看!");
// 推送配置: Android
pushRequest.setAndroidNotifyType("BOTH");//通知的提醒方式 "VIBRATE" : 震动 "SOUND" : 声音 "BOTH" : 声音和震动 NONE : 静音
pushRequest.setAndroidOpenType("APPLICATION"); //点击通知后动作 "APPLICATION" : 打开应用 "ACTIVITY" : 打开AndroidActivity "URL" : 打开URL "NONE" : 无跳转
// 指定notificaitonchannel id
pushRequest.setAndroidNotificationChannel("1");
try {
PushResponse response = client.getAcsResponse(pushRequest);
log.info(response);