From eccd60a3a076fccffdeee8037d6499926a4c7bf5 Mon Sep 17 00:00:00 2001 From: yiyan Date: Sat, 1 Jun 2019 22:58:51 +0800 Subject: [PATCH] =?UTF-8?q?=E9=98=BF=E9=87=8C=E4=BA=91=E6=8E=A8=E9=80=81?= =?UTF-8?q?=E6=94=B9=E9=80=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 31 ++++++- .../com/ifish/action/UpdateUserAction.java | 15 +-- .../ifish/entity/event/QueueEventBody.java | 37 ++++++++ .../ifish/entity/event/QueueEventEntity.java | 40 ++++++++ .../java/com/ifish/helper/UserHelper.java | 78 +++++++++++----- .../java/com/ifish/service/UserService.java | 4 + .../ifish/serviceImpl/UserServiceImpl.java | 93 ++++++++++++++++--- src/main/resources/application-context.xml | 44 ++++++++- src/main/resources/jdbc.properties | 12 +-- src/main/resources/log4j.properties | 3 +- src/main/resources/mq.properties | 7 ++ src/main/resources/spring-mybatis.xml | 2 +- 12 files changed, 308 insertions(+), 58 deletions(-) create mode 100644 src/main/java/com/ifish/entity/event/QueueEventBody.java create mode 100644 src/main/java/com/ifish/entity/event/QueueEventEntity.java create mode 100644 src/main/resources/mq.properties diff --git a/pom.xml b/pom.xml index 69dcae7..5dd0120 100644 --- a/pom.xml +++ b/pom.xml @@ -15,13 +15,18 @@ 4.3.8.RELEASE jar - + org.springframework spring-context 4.1.6.RELEASE - + + org.springframework + spring-aop + 4.3.12.RELEASE + + org.springframework spring-orm @@ -64,6 +69,24 @@ 2.9.0 + + org.apache.activemq + activemq-all + 5.15.4 + + + + org.springframework + spring-jms + 4.1.6.RELEASE + + + + org.apache.xbean + xbean-spring + 3.16 + + org.hibernate hibernate-core @@ -268,8 +291,8 @@ maven-compiler-plugin 3.5.1 - 1.7 - 1.7 + 1.8 + 1.8 diff --git a/src/main/java/com/ifish/action/UpdateUserAction.java b/src/main/java/com/ifish/action/UpdateUserAction.java index 1a8d308..5a19a1e 100644 --- a/src/main/java/com/ifish/action/UpdateUserAction.java +++ b/src/main/java/com/ifish/action/UpdateUserAction.java @@ -1,10 +1,13 @@ package com.ifish.action; -import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; -import com.alibaba.fastjson.JSONObject; import com.ifish.entity.AliyunDeviceInfo; +import com.ifish.entity.User; +import com.ifish.enums.ResultEnum; +import com.ifish.service.BaseService; import com.ifish.service.PageListService; +import com.ifish.service.UserService; +import com.ifish.util.IfishUtil; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -15,11 +18,6 @@ import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.multipart.MultipartFile; -import com.ifish.entity.User; -import com.ifish.enums.ResultEnum; -import com.ifish.service.BaseService; -import com.ifish.util.IfishUtil; - import java.util.Date; /** @@ -35,6 +33,9 @@ public class UpdateUserAction { @Autowired private BaseService baseService; + @Autowired + private UserService userService; + @Autowired private PageListService pageListService; diff --git a/src/main/java/com/ifish/entity/event/QueueEventBody.java b/src/main/java/com/ifish/entity/event/QueueEventBody.java new file mode 100644 index 0000000..ba037a5 --- /dev/null +++ b/src/main/java/com/ifish/entity/event/QueueEventBody.java @@ -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; + } +} diff --git a/src/main/java/com/ifish/entity/event/QueueEventEntity.java b/src/main/java/com/ifish/entity/event/QueueEventEntity.java new file mode 100644 index 0000000..415509d --- /dev/null +++ b/src/main/java/com/ifish/entity/event/QueueEventEntity.java @@ -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; + } +} diff --git a/src/main/java/com/ifish/helper/UserHelper.java b/src/main/java/com/ifish/helper/UserHelper.java index b6189e7..229a2cb 100644 --- a/src/main/java/com/ifish/helper/UserHelper.java +++ b/src/main/java/com/ifish/helper/UserHelper.java @@ -5,32 +5,39 @@ */ package com.ifish.helper; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; import com.ifish.bean.DeviceUserBean; import com.ifish.dao.DeviceUserDao; import com.ifish.dao.PushListDao; import com.ifish.entity.*; -import com.ifish.enums.BooleanEnum; -import com.ifish.enums.GwellEnum; -import com.ifish.enums.NeteaseEnum; -import com.ifish.enums.ResultEnum; -import com.ifish.enums.SubDirectoryEnum; +import com.ifish.entity.event.QueueEventBody; +import com.ifish.entity.event.QueueEventEntity; +import com.ifish.enums.*; import com.ifish.gwell.GwellApi; import com.ifish.mapper.Tbl_Device_User_Mapper; import com.ifish.mapper.Tbl_User_Mapper; import com.ifish.netease.NeteaseIM; +import com.ifish.service.UserService; import com.ifish.util.IfishFilePath; import com.ifish.util.IfishUtil; import com.ifish.util.RedisKey; import com.ifish.util.StringUtil; +import java.time.Instant; +import java.time.ZoneId; import java.util.*; import java.util.concurrent.TimeUnit; import org.apache.commons.lang3.StringUtils; import org.hibernate.criterion.Criterion; import org.hibernate.criterion.Restrictions; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.jms.core.JmsTemplate; import org.springframework.stereotype.Component; +import javax.jms.Destination; +import javax.jms.Session; + /** * 用户管理所有接口方法 * @@ -74,6 +81,14 @@ public class UserHelper implements UserHelperI { @Autowired private PushListDao pushListDao; + + @Autowired + private UserService userService; + @Autowired + private JmsTemplate jmsTemplate; + @Autowired + private Destination ifish7PushQueueDestination; + /** * 登陆接口 * @@ -237,9 +252,28 @@ public class UserHelper implements UserHelperI { * @return */ private Map registUserNetease(User tmpUser, boolean isUpdate) throws Exception { + StringBuffer msg = new StringBuffer(); + msg.append("感谢您使用爱鱼奇,连接智能设备请查看下方说明书,内含操作视频:http://u.eqxiu.com/s/KmmVl87l\n"); + msg.append("摄像头售后:18667812003\n睿芯插排售后:15757401229\n绚多插排售后:18857689069\n松诺插排售后:13392205468"); + //如果当前设备用户未注册 if (tmpUser.getIsRegisterNetease().equals(BooleanEnum.NO.getKey())) { + PushList pushList = new PushList(); + pushList.setUserId(tmpUser.getUserId()); + pushList.setDeviceId(0); + pushList.setPhoneType("ALL"); + pushList.setShowName(""); + pushList.setPushType(PushTypeEnum.qu_reply.getKey()); + pushList.setPushTitle("系统通知"); + pushList.setPushContext(msg.toString()); + sendPushQueueMessage(pushList); + + //更新用户注册信息 + User user = userService.getUser(tmpUser.getUserId()); + user.setIsRegisterNetease(BooleanEnum.YES.getKey()); + userService.updateUser(user); + //注册云信 - Map map = neteaseIM.createAccid(tmpUser.getUserId().toString(), tmpUser.getNickName(), IfishFilePath.getPath(SubDirectoryEnum.headImage, tmpUser.getUserImg()), ""); + /*Map map = neteaseIM.createAccid(tmpUser.getUserId().toString(), tmpUser.getNickName(), IfishFilePath.getPath(SubDirectoryEnum.headImage, tmpUser.getUserImg()), ""); if (map != null) { String code = map.get("code"); if (code.equals(NeteaseEnum.status200.getKey())) { @@ -255,21 +289,7 @@ public class UserHelper implements UserHelperI { tmpUser.setIsRegisterNetease(BooleanEnum.YES.getKey()); isUpdate = true; } - } - } //已注册云信 - else if (tmpUser.getIsRegisterNetease().equals(BooleanEnum.YES.getKey())) { - //token为空 - if (tmpUser.getNeteaseToken().equals("")) { - //获取云信token - Map map = neteaseIM.refreshToken(tmpUser.getUserId().toString()); - if (map != null) { - String code = map.get("code"); - if (code.equals(NeteaseEnum.status200.getKey())) { - tmpUser.setNeteaseToken(map.get("token")); - isUpdate = true; - } - } - } + }*/ } Map resultMap = new HashMap(); resultMap.put("user", tmpUser); @@ -277,6 +297,22 @@ public class UserHelper implements UserHelperI { return resultMap; } + /** + * 推送Push消息队列 + * @param pushList 内容 + */ + private void sendPushQueueMessage(final PushList pushList) { + JSONObject data = JSON.parseObject(JSON.toJSONString(pushList)); + 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)); + } + + /** * 登录成功,返回给App数据 * diff --git a/src/main/java/com/ifish/service/UserService.java b/src/main/java/com/ifish/service/UserService.java index 8644488..782c15f 100644 --- a/src/main/java/com/ifish/service/UserService.java +++ b/src/main/java/com/ifish/service/UserService.java @@ -79,5 +79,9 @@ public interface UserService { * @return */ public JsonResult uploadUserImg(Integer userId,MultipartFile fileUpload); + + User getUser(Integer userId); + + void updateUser(User user); } diff --git a/src/main/java/com/ifish/serviceImpl/UserServiceImpl.java b/src/main/java/com/ifish/serviceImpl/UserServiceImpl.java index 1bd0d97..8a10d90 100644 --- a/src/main/java/com/ifish/serviceImpl/UserServiceImpl.java +++ b/src/main/java/com/ifish/serviceImpl/UserServiceImpl.java @@ -10,9 +10,13 @@ import java.util.List; import java.util.Map; import java.util.Random; +import com.alibaba.fastjson.JSON; +import com.ifish.entity.event.QueueEventBody; +import com.ifish.entity.event.QueueEventEntity; import org.apache.commons.lang3.StringUtils; import org.hibernate.criterion.Restrictions; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.jms.core.JmsTemplate; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.web.multipart.MultipartFile; @@ -83,8 +87,11 @@ import com.ifish.util.IfishUtil; import com.ifish.validator.LoginParam; import com.ifish.validator.RegisterParam; +import javax.jms.Destination; +import javax.jms.Session; + /** - * @ClassName: UserServiceImpl + * @ClassName: UserServiceImpl * @Description: TODO * @author ggw * @@ -127,6 +134,25 @@ public class UserServiceImpl implements UserService { private CacheService cacheService; @Autowired private GradeService gradeService; + @Autowired + private JmsTemplate jmsTemplate; + @Autowired + private Destination ifish7PushQueueDestination; + + /** + * 推送Push消息队列 + * @param pushList 内容 + */ + private void sendPushQueueMessage(final PushList pushList) { + JSONObject data = JSON.parseObject(JSON.toJSONString(pushList)); + 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 public JsonResult getVerificateCode(String phoneNumber, String sendType) { @@ -175,19 +201,32 @@ public class UserServiceImpl implements UserService { user.setP2PVerifyCode2(gwellParam.getP2PVerifyCode2()); user.setGwellUserID(gwellParam.getUserID()); } - //云信参数 - Integer userId = user.getUserId(); - NeteaseParamDto neteaseParam = GetNeteaseInfo(user.getIsRegisterNetease(), userId, user.getNickName(), user.getUserImg(), user.getNeteaseToken()); - if(neteaseParam!=null){ - user.setIsRegisterNetease(neteaseParam.getIsRegisterNetease()); - user.setNeteaseToken(neteaseParam.getNeteaseToken()); - } + StringBuffer msg = new StringBuffer(); + msg.append("感谢您使用爱鱼奇,连接智能设备请查看下方说明书,内含操作视频:http://u.eqxiu.com/s/KmmVl87l\n"); + msg.append("摄像头售后:18667812003\n睿芯插排售后:15757401229\n绚多插排售后:18857689069\n松诺插排售后:13392205468"); + Integer userId = user.getUserId(); + //如果当前设备用户未注册 + if (user.getIsRegisterNetease().equals(BooleanEnum.NO.getKey())) { + PushList pushList = new PushList(); + pushList.setUserId(userId); + pushList.setDeviceId(0); + pushList.setPhoneType("ALL"); + pushList.setShowName(""); + pushList.setPushType(PushTypeEnum.qu_reply.getKey()); + pushList.setPushTitle("系统通知"); + pushList.setPushContext(msg.toString()); + sendPushQueueMessage(pushList); + + //更新用户注册信息 + user.setIsRegisterNetease(BooleanEnum.YES.getKey()); + userDao.update(user); + } /** * 更新登陆参数 */ userDao.executeLoginUpdate(userId,loginParam.getLoginType()); //设备信息 - DeviceInfoDto deviceInfo = getDeviceInfo(userId); + DeviceInfoDto deviceInfo = getDeviceInfo(user.getUserId()); /** * 登录返回信息 */ @@ -253,11 +292,25 @@ public class UserServiceImpl implements UserService { } //云信参数 Integer userId = user.getUserId(); - NeteaseParamDto neteaseParam = GetNeteaseInfo(user.getIsRegisterNetease(), userId, user.getNickName(), user.getUserImg(), user.getNeteaseToken()); - if(neteaseParam!=null){ - user.setIsRegisterNetease(neteaseParam.getIsRegisterNetease()); - user.setNeteaseToken(neteaseParam.getNeteaseToken()); - } + StringBuffer msg = new StringBuffer(); + msg.append("感谢您使用爱鱼奇,连接智能设备请查看下方说明书,内含操作视频:http://u.eqxiu.com/s/KmmVl87l\n"); + msg.append("摄像头售后:18667812003\n睿芯插排售后:15757401229\n绚多插排售后:18857689069\n松诺插排售后:13392205468"); + //如果当前设备用户未注册 + if (user.getIsRegisterNetease().equals(BooleanEnum.NO.getKey())) { + PushList pushList = new PushList(); + pushList.setUserId(userId); + pushList.setDeviceId(0); + pushList.setPhoneType("ALL"); + pushList.setShowName(""); + pushList.setPushType(PushTypeEnum.qu_reply.getKey()); + pushList.setPushTitle("系统通知"); + pushList.setPushContext(msg.toString()); + sendPushQueueMessage(pushList); + + //更新用户注册信息 + user.setIsRegisterNetease(BooleanEnum.YES.getKey()); + userDao.update(user); + } //更新登陆参数 userDao.executeLoginUpdate(userId,loginParam.getLoginType()); //用户基本信息 @@ -595,6 +648,7 @@ public class UserServiceImpl implements UserService { * 第一次注册云信发送一条系统消息 * @param to */ + @Deprecated public void sendMsgByIM(String to){ //发送云信消息 User user = userDao.findUniqueByProperty(Restrictions.eq("phoneNumber", IfishFilePath.netease_phone)); @@ -844,6 +898,7 @@ public class UserServiceImpl implements UserService { * @param neteaseToken * @return */ + @Deprecated public NeteaseParamDto GetNeteaseInfo(String isRegisterNetease,Integer userId,String nickName,String userImg,String neteaseToken){ //未注册云信 if(!BooleanEnum.YES.getKey().equals(isRegisterNetease)){ @@ -1082,4 +1137,14 @@ public class UserServiceImpl implements UserService { } return goldTaskList; } + + @Override + public User getUser(Integer userId) { + return this.userDao.get(userId); + } + + @Override + public void updateUser(User user) { + this.userDao.update(user); + } } diff --git a/src/main/resources/application-context.xml b/src/main/resources/application-context.xml index b891eb4..de8d312 100644 --- a/src/main/resources/application-context.xml +++ b/src/main/resources/application-context.xml @@ -22,9 +22,17 @@ http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache.xsd" default-lazy-init="false"> - + - + + + + classpath:mq.properties + classpath:jdbc.properties + + + @@ -89,7 +97,6 @@ ${hibernate.dialect} ${hibernate.show_sql} ${hibernate.format_sql} - ${hibernate.hbm2ddl.auto} @@ -118,5 +125,36 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + ${queue_push_name} + + + \ No newline at end of file diff --git a/src/main/resources/jdbc.properties b/src/main/resources/jdbc.properties index 0cbf3ee..a5700c3 100644 --- a/src/main/resources/jdbc.properties +++ b/src/main/resources/jdbc.properties @@ -1,10 +1,10 @@ jdbc.driver=com.mysql.jdbc.Driver -#jdbc.url=jdbc\:mysql\://localhost\:3306/myfishdb?characterEncoding\=UTF-8 -jdbc.url=jdbc\:mysql\://139.196.24.156\:3306/myfishdb?characterEncoding\=UTF-8 -#jdbc.username=ifish -#jdbc.password=ifish7pwd -jdbc.username=root -jdbc.password=ifish7mysql +jdbc.url=jdbc\:mysql\://localhost\:3306/myfishdb?characterEncoding\=UTF-8 +#jdbc.url=jdbc\:mysql\://139.196.24.156\:3306/myfishdb?characterEncoding\=UTF-8 +jdbc.username=ifish +jdbc.password=ifish7pwd +#jdbc.username=root +#jdbc.password=ifish7mysql #jdbc.testWhileIdle=true jdbc.validationQuery=SELECT * FROM DUAL initialSize=1 diff --git a/src/main/resources/log4j.properties b/src/main/resources/log4j.properties index 159098c..3755e98 100644 --- a/src/main/resources/log4j.properties +++ b/src/main/resources/log4j.properties @@ -32,6 +32,5 @@ log4j.appender.ROLLING_FILE.layout=org.apache.log4j.PatternLayout log4j.appender.ROLLING_FILE.layout.ConversionPattern=[Ifish7][%-5p]%d - %c.%t(%F:%L) - %m%n log4j.logger.org.springframework=INFO -log4j.logger.com.hibernate=INFO +log4j.logger.com.hibernate=DEBUG log4j.logger.java.sql=ERROR - diff --git a/src/main/resources/mq.properties b/src/main/resources/mq.properties new file mode 100644 index 0000000..a5dcb67 --- /dev/null +++ b/src/main/resources/mq.properties @@ -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 \ No newline at end of file diff --git a/src/main/resources/spring-mybatis.xml b/src/main/resources/spring-mybatis.xml index 69543c3..4c6038e 100644 --- a/src/main/resources/spring-mybatis.xml +++ b/src/main/resources/spring-mybatis.xml @@ -8,7 +8,7 @@ "> - +