消息推送改造
This commit is contained in:
parent
aa3b3825b0
commit
d00b461151
21
pom.xml
21
pom.xml
|
|
@ -36,7 +36,11 @@
|
||||||
<artifactId>spring-context</artifactId>
|
<artifactId>spring-context</artifactId>
|
||||||
<version>4.1.6.RELEASE</version>
|
<version>4.1.6.RELEASE</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework</groupId>
|
||||||
|
<artifactId>spring-aop</artifactId>
|
||||||
|
<version>4.3.12.RELEASE</version>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework</groupId>
|
<groupId>org.springframework</groupId>
|
||||||
<artifactId>spring-orm</artifactId>
|
<artifactId>spring-orm</artifactId>
|
||||||
|
|
@ -48,7 +52,11 @@
|
||||||
<artifactId>aspectjweaver</artifactId>
|
<artifactId>aspectjweaver</artifactId>
|
||||||
<version>1.8.5</version>
|
<version>1.8.5</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.activemq</groupId>
|
||||||
|
<artifactId>activemq-all</artifactId>
|
||||||
|
<version>5.15.4</version>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework</groupId>
|
<groupId>org.springframework</groupId>
|
||||||
<artifactId>spring-webmvc</artifactId>
|
<artifactId>spring-webmvc</artifactId>
|
||||||
|
|
@ -141,6 +149,11 @@
|
||||||
<artifactId>commons-lang3</artifactId>
|
<artifactId>commons-lang3</artifactId>
|
||||||
<version>3.5</version>
|
<version>3.5</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.commons</groupId>
|
||||||
|
<artifactId>commons-pool2</artifactId>
|
||||||
|
<version>2.6.2</version>
|
||||||
|
</dependency>
|
||||||
<!-- commons-io -->
|
<!-- commons-io -->
|
||||||
<!-- <dependency>
|
<!-- <dependency>
|
||||||
<groupId>commons-io</groupId>
|
<groupId>commons-io</groupId>
|
||||||
|
|
@ -211,8 +224,8 @@
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
<version>3.5.1</version>
|
<version>3.5.1</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<source>1.7</source>
|
<source>1.8</source>
|
||||||
<target>1.7</target>
|
<target>1.8</target>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,37 @@
|
||||||
|
package com.ifish.entity.event;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author: yan.y
|
||||||
|
* @Description:
|
||||||
|
* @Date: Created in 16:58 2019-04-10
|
||||||
|
* @Modified by:
|
||||||
|
*/
|
||||||
|
public class QueueEventBody {
|
||||||
|
|
||||||
|
public QueueEventBody(String entity, JSONObject data) {
|
||||||
|
this.entity = entity;
|
||||||
|
this.data = data;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String entity;
|
||||||
|
|
||||||
|
private JSONObject data;
|
||||||
|
|
||||||
|
public String getEntity() {
|
||||||
|
return entity;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEntity(String entity) {
|
||||||
|
this.entity = entity;
|
||||||
|
}
|
||||||
|
|
||||||
|
public JSONObject getData() {
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setData(JSONObject data) {
|
||||||
|
this.data = data;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,40 @@
|
||||||
|
package com.ifish.entity.event;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author: yan.y
|
||||||
|
* @Description:
|
||||||
|
* @Date: Created in 16:46 2019-04-10
|
||||||
|
* @Modified by:
|
||||||
|
*/
|
||||||
|
public class QueueEventEntity {
|
||||||
|
|
||||||
|
private String eventProcess;
|
||||||
|
|
||||||
|
private String eventName;
|
||||||
|
|
||||||
|
private QueueEventBody eventBody;
|
||||||
|
|
||||||
|
public String getEventProcess() {
|
||||||
|
return eventProcess;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEventProcess(String eventProcess) {
|
||||||
|
this.eventProcess = eventProcess;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getEventName() {
|
||||||
|
return eventName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEventName(String eventName) {
|
||||||
|
this.eventName = eventName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public QueueEventBody getEventBody() {
|
||||||
|
return eventBody;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEventBody(QueueEventBody eventBody) {
|
||||||
|
this.eventBody = eventBody;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -13,11 +13,16 @@ import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
|
import com.ifish.entity.*;
|
||||||
|
import com.ifish.entity.event.QueueEventBody;
|
||||||
|
import com.ifish.entity.event.QueueEventEntity;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.hibernate.criterion.Criterion;
|
import org.hibernate.criterion.Criterion;
|
||||||
import org.hibernate.criterion.Order;
|
import org.hibernate.criterion.Order;
|
||||||
import org.hibernate.criterion.Restrictions;
|
import org.hibernate.criterion.Restrictions;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.jms.core.JmsTemplate;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
@ -60,35 +65,6 @@ import com.ifish.domain.HardwareTypeData;
|
||||||
import com.ifish.domain.JsonResult;
|
import com.ifish.domain.JsonResult;
|
||||||
import com.ifish.domain.RecordData;
|
import com.ifish.domain.RecordData;
|
||||||
import com.ifish.domain.VenderData;
|
import com.ifish.domain.VenderData;
|
||||||
import com.ifish.entity.Camera;
|
|
||||||
import com.ifish.entity.CameraActive;
|
|
||||||
import com.ifish.entity.CameraUser;
|
|
||||||
import com.ifish.entity.Device;
|
|
||||||
import com.ifish.entity.DeviceCamera;
|
|
||||||
import com.ifish.entity.DeviceUser;
|
|
||||||
import com.ifish.entity.FactoryList;
|
|
||||||
import com.ifish.entity.Grade;
|
|
||||||
import com.ifish.entity.HardwareType;
|
|
||||||
import com.ifish.entity.IfishDoctor;
|
|
||||||
import com.ifish.entity.LiveBanner;
|
|
||||||
import com.ifish.entity.LiveRoom;
|
|
||||||
import com.ifish.entity.LoginRecord;
|
|
||||||
import com.ifish.entity.Menu;
|
|
||||||
import com.ifish.entity.NeteaseUser;
|
|
||||||
import com.ifish.entity.OperateRecord;
|
|
||||||
import com.ifish.entity.PayBill;
|
|
||||||
import com.ifish.entity.PayeeInfo;
|
|
||||||
import com.ifish.entity.PushList;
|
|
||||||
import com.ifish.entity.QuestionsFeedback;
|
|
||||||
import com.ifish.entity.Role;
|
|
||||||
import com.ifish.entity.SecurityUser;
|
|
||||||
import com.ifish.entity.TmpPushRemind;
|
|
||||||
import com.ifish.entity.Ueditor;
|
|
||||||
import com.ifish.entity.UpgradeNotes;
|
|
||||||
import com.ifish.entity.User;
|
|
||||||
import com.ifish.entity.UserAsset;
|
|
||||||
import com.ifish.entity.VenderList;
|
|
||||||
import com.ifish.entity.Version;
|
|
||||||
import com.ifish.entity.id.PayBillId;
|
import com.ifish.entity.id.PayBillId;
|
||||||
import com.ifish.enums.BooleanEnum;
|
import com.ifish.enums.BooleanEnum;
|
||||||
import com.ifish.enums.GwellEnum;
|
import com.ifish.enums.GwellEnum;
|
||||||
|
|
@ -109,9 +85,11 @@ import com.ifish.service.AsyncTaskService;
|
||||||
import com.ifish.util.IfishFileDirectory;
|
import com.ifish.util.IfishFileDirectory;
|
||||||
import com.ifish.util.IfishUtil;
|
import com.ifish.util.IfishUtil;
|
||||||
import com.ifish.util.ResultUtil;
|
import com.ifish.util.ResultUtil;
|
||||||
import com.ifishNew.bean.Tbl_Push_List;
|
|
||||||
import com.ifishNew.mapper.Tbl_Push_List_Mapper;
|
import com.ifishNew.mapper.Tbl_Push_List_Mapper;
|
||||||
|
|
||||||
|
import javax.jms.Destination;
|
||||||
|
import javax.jms.Session;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ClassName: AdminServiceImpl
|
* @ClassName: AdminServiceImpl
|
||||||
* @Description: TODO
|
* @Description: TODO
|
||||||
|
|
@ -188,6 +166,10 @@ public class AdminServiceImpl implements AdminService {
|
||||||
private AsyncTaskService asyncTaskService;
|
private AsyncTaskService asyncTaskService;
|
||||||
@Autowired
|
@Autowired
|
||||||
private Tbl_Push_List_Mapper tbl_Push_List_Mapper;
|
private Tbl_Push_List_Mapper tbl_Push_List_Mapper;
|
||||||
|
@Autowired
|
||||||
|
private JmsTemplate jmsTemplate;
|
||||||
|
@Autowired
|
||||||
|
private Destination ifish7PushQueueDestination;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Role get(String roleCode) {
|
public Role get(String roleCode) {
|
||||||
|
|
@ -1840,22 +1822,57 @@ public class AdminServiceImpl implements AdminService {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public JsonResult pushAllUser(PushList pushList) {
|
public JsonResult pushAllUser(PushList pushList) {
|
||||||
//记录推送
|
Integer firstResult = 0;
|
||||||
pushList.setUser(null);
|
Integer maxResults = 500;
|
||||||
pushList.setDevice(null);
|
JSONObject data = new JSONObject();
|
||||||
pushList.setJpushStatus(BooleanEnum.NO.getKey());
|
String type = "ALL";
|
||||||
pushList.setNeteaseStatus(BooleanEnum.YES.getKey());
|
if (pushList.getPushType().equals("all_ios_push")) {
|
||||||
pushList.setCreateTime(new Date());
|
type = "iOS";
|
||||||
pushListDao.save(pushList);
|
} else if (pushList.getPushType().equals("all_android_push")) {
|
||||||
|
type = "ANDROID";
|
||||||
|
}
|
||||||
|
final String phoneType = type;
|
||||||
|
while(true){
|
||||||
|
List<Integer> list = userDao.getUserIds(pushList.getPushType(),firstResult, maxResults);
|
||||||
|
Integer size = list.size();
|
||||||
|
if(size<=0){
|
||||||
|
break;
|
||||||
|
} else{
|
||||||
|
firstResult+=size;
|
||||||
|
list.forEach(userId -> {
|
||||||
|
data.put("userId",userId);
|
||||||
|
data.put("deviceId",0);
|
||||||
|
data.put("phoneType",phoneType);
|
||||||
|
data.put("showName","");
|
||||||
|
data.put("pushType",PushTypeEnum.qu_reply.getKey());
|
||||||
|
data.put("pushTitle","系统通知");
|
||||||
|
data.put("pushContext",pushList.getPushContext());
|
||||||
|
sendPushQueueMessage(data);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
//推送类型和参数
|
//推送类型和参数
|
||||||
String pushType = pushList.getPushType();
|
String pushType = pushList.getPushType();
|
||||||
Map<String, String> map = new HashMap<String, String>();
|
Map<String, String> map = new HashMap<String, String>();
|
||||||
map.put("push_link", pushList.getPushLink());
|
map.put("push_link", pushList.getPushLink());
|
||||||
map.put("msg_type", pushType);
|
map.put("msg_type", pushType);
|
||||||
//异步推送云信消息
|
//异步推送云信消息
|
||||||
asyncTaskService.sendMsgToAll(pushType, "【" + pushList.getPushTitle() + "】" + pushList.getPushContext(), map);
|
// asyncTaskService.sendMsgToAll(pushType, "【" + pushList.getPushTitle() + "】" + pushList.getPushContext(), map);
|
||||||
return ResultUtil.success();
|
return ResultUtil.success();
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* 推送Push消息队列
|
||||||
|
* @param data 内容
|
||||||
|
*/
|
||||||
|
private void sendPushQueueMessage(JSONObject data) {
|
||||||
|
QueueEventEntity eventEntity = new QueueEventEntity();
|
||||||
|
eventEntity.setEventName("com.ifish7.mq.queues.event.PushNotifcationEvent");
|
||||||
|
eventEntity.setEventProcess("deviceNotifcationPlus");
|
||||||
|
QueueEventBody eventBody = new QueueEventBody("com.ifish7.mq.business.user.entity.TblPushList",data);
|
||||||
|
eventEntity.setEventBody(eventBody);
|
||||||
|
String json = JSONObject.toJSONString(eventEntity);
|
||||||
|
jmsTemplate.send(ifish7PushQueueDestination,(Session session) -> session.createTextMessage(json));
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Pagination<UpgradeNotes> getUpgradeNotesByPage(SearchFilter searchFilter) {
|
public Pagination<UpgradeNotes> getUpgradeNotesByPage(SearchFilter searchFilter) {
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,17 @@
|
||||||
default-lazy-init="true">
|
default-lazy-init="true">
|
||||||
|
|
||||||
<!-- 导入外部的properties文件-->
|
<!-- 导入外部的properties文件-->
|
||||||
<context:property-placeholder location="classpath*:jdbc.properties" ignore-unresolvable="true"/>
|
<!-- 导入外部的properties文件-->
|
||||||
|
<bean id="propertyConfigurer"
|
||||||
|
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
|
||||||
|
<property name="locations" >
|
||||||
|
<list>
|
||||||
|
<value>classpath:mq.properties</value>
|
||||||
|
<value>classpath:jdbc.properties</value>
|
||||||
|
<value>classpath:jPpush.properties</value>
|
||||||
|
</list>
|
||||||
|
</property>
|
||||||
|
</bean>
|
||||||
<!-- 注册识别注解 -->
|
<!-- 注册识别注解 -->
|
||||||
<context:component-scan base-package="com.ifish.converter,com.ifish.daoImpl,com.ifish.serviceImpl,com.ifishNew.help"/>
|
<context:component-scan base-package="com.ifish.converter,com.ifish.daoImpl,com.ifish.serviceImpl,com.ifishNew.help"/>
|
||||||
|
|
||||||
|
|
@ -55,9 +65,8 @@
|
||||||
<prop key="hibernate.dialect">${hibernate.dialect}</prop>
|
<prop key="hibernate.dialect">${hibernate.dialect}</prop>
|
||||||
<prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
|
<prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
|
||||||
<prop key="hibernate.format_sql">${hibernate.format_sql}</prop>
|
<prop key="hibernate.format_sql">${hibernate.format_sql}</prop>
|
||||||
<prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop>
|
|
||||||
<prop key="hibernate.query.substitutions">${hibernate.query.substitutions}</prop>
|
<prop key="hibernate.query.substitutions">${hibernate.query.substitutions}</prop>
|
||||||
<prop key="hibernate.jdbc.batch_size">${"hibernate.jdbc.batch_size"}</prop>
|
<prop key="hibernate.jdbc.batch_size">${hibernate.jdbc.batch_size}</prop>
|
||||||
</props>
|
</props>
|
||||||
</property>
|
</property>
|
||||||
</bean>
|
</bean>
|
||||||
|
|
@ -86,4 +95,35 @@
|
||||||
<value>${netease.appSecret}</value>
|
<value>${netease.appSecret}</value>
|
||||||
</constructor-arg>
|
</constructor-arg>
|
||||||
</bean>
|
</bean>
|
||||||
|
<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>
|
||||||
|
|
||||||
|
<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) -->
|
||||||
|
<bean id="ifish7PushQueueDestination" class="org.apache.activemq.command.ActiveMQQueue">
|
||||||
|
<!-- 设置消息队列的名字 -->
|
||||||
|
<constructor-arg>
|
||||||
|
<value>${queue_push_name}</value>
|
||||||
|
</constructor-arg>
|
||||||
|
</bean>
|
||||||
|
|
||||||
</beans>
|
</beans>
|
||||||
|
|
@ -0,0 +1,7 @@
|
||||||
|
#broker_url=tcp://test.ifish7.com:61616
|
||||||
|
broker_url=tcp://www.ifish7.com:61616
|
||||||
|
username=admin
|
||||||
|
#password=admin
|
||||||
|
password=adminifish7
|
||||||
|
queue_data_name=ifishDataMq
|
||||||
|
queue_push_name=ifishPushMq
|
||||||
Loading…
Reference in New Issue