|
@@ -2,17 +2,24 @@ package com.idiot.operationbackend.service.impl;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+import com.idiot.operationbackend.entity.*;
|
|
|
|
+import com.idiot.operationbackend.handler.ScanQrHandler;
|
|
import com.idiot.operationbackend.handler.WeChatMessageFactory;
|
|
import com.idiot.operationbackend.handler.WeChatMessageFactory;
|
|
-import com.idiot.operationbackend.service.facade.WeChatMessageService;
|
|
|
|
|
|
+import com.idiot.operationbackend.service.facade.*;
|
|
import com.idiot.operationbackend.support.Constants;
|
|
import com.idiot.operationbackend.support.Constants;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
import org.springframework.util.StringUtils;
|
|
import org.springframework.util.StringUtils;
|
|
|
|
|
|
|
|
+import java.time.LocalTime;
|
|
import java.util.HashMap;
|
|
import java.util.HashMap;
|
|
|
|
+import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
|
|
+import java.util.Objects;
|
|
import java.util.function.Function;
|
|
import java.util.function.Function;
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -24,28 +31,28 @@ import java.util.function.Function;
|
|
public class EventMessageServiceImpl implements WeChatMessageService {
|
|
public class EventMessageServiceImpl implements WeChatMessageService {
|
|
|
|
|
|
|
|
|
|
|
|
+ private final Logger logger = LoggerFactory.getLogger(EventMessageServiceImpl.class);
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
+ private QrCodeService qrCodeService;
|
|
|
|
|
|
- private final Logger logger = LoggerFactory.getLogger(EventMessageServiceImpl.class);
|
|
|
|
|
|
+ @Autowired
|
|
|
|
+ private ScanQrHandler scanQrHandler;
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
+ private FollowReplyService followReplyService;
|
|
|
|
|
|
- @Override
|
|
|
|
- public void afterPropertiesSet() {
|
|
|
|
|
|
+ @Autowired
|
|
|
|
+ private FansActionStatService fansActionStatService;
|
|
|
|
|
|
- logger.info("微信消息,事件处理类--------------->正在初始化");
|
|
|
|
- synchronized (eventMap) {
|
|
|
|
- eventMap.put("subscribe",this::subscribeEvent);
|
|
|
|
- eventMap.put("SCAN",this::scanEvent);
|
|
|
|
- eventMap.put("LOCATION",this::locationEvent);
|
|
|
|
- eventMap.put("CLICK",this::clickEvent);
|
|
|
|
- eventMap.put("VIEW",this::viewEvent);
|
|
|
|
- }
|
|
|
|
- logger.info("微信消息,事件处理类--------------->初始化完成");
|
|
|
|
- WeChatMessageFactory.addService("event",this);
|
|
|
|
|
|
+ @Autowired
|
|
|
|
+ private WeChatService weChatService;
|
|
|
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
+ private AccountFansService fansService;
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
public String processMessage(Map<String, String> param) {
|
|
public String processMessage(Map<String, String> param) {
|
|
String eventType = param.get("Event");
|
|
String eventType = param.get("Event");
|
|
@@ -70,14 +77,34 @@ public class EventMessageServiceImpl implements WeChatMessageService {
|
|
private String subscribeEvent (Map<String,String> param) {
|
|
private String subscribeEvent (Map<String,String> param) {
|
|
logger.info("********************* param is {}*****************",param.toString());
|
|
logger.info("********************* param is {}*****************",param.toString());
|
|
String key = param.get("EventKey");
|
|
String key = param.get("EventKey");
|
|
- if (StringUtils.isEmpty(key)) {
|
|
|
|
- param.put("Content","欢迎关注中德智慧教育科技");
|
|
|
|
- return unSupportedMessage(param);
|
|
|
|
|
|
+ String accountId = param.get("accountId");
|
|
|
|
+ String openId = param.get("FromUserName");
|
|
|
|
+ if (!StringUtils.isEmpty(key)) {
|
|
|
|
+ logger.info("********************* 扫描二维码 关注 *****************");
|
|
|
|
+ key = key.replace("qrscene_","");
|
|
|
|
+ QrCode qrCode = qrCodeService.getById(key);
|
|
|
|
+ if (Objects.nonNull(qrCode)) {
|
|
|
|
+ qrCode.setNewNum(qrCode.getNewNum()+1);
|
|
|
|
+ qrCode.setTotalNum(qrCode.getTotalNum()+1);
|
|
|
|
+ qrCodeService.updateById(qrCode);
|
|
|
|
+ scanQrHandler.addElement(accountId,openId,key,qrCode.getContent());
|
|
|
|
+ }
|
|
|
|
+ return Constants.SUCCESS;
|
|
}
|
|
}
|
|
- key = key.replace("qrscene_","");
|
|
|
|
- logger.info("************** subscribe Received weChat event key : {} ****************",key);
|
|
|
|
-
|
|
|
|
|
|
+ FansActionStat var2 = new FansActionStat(accountId,openId,2);
|
|
|
|
+ fansActionStatService.saveBatchFansActionStat(var2);
|
|
|
|
+ // 关注事件
|
|
|
|
+ FollowReply followReply = followReplyService.queryFollowReplyByAccountId(accountId);
|
|
|
|
+ if (Objects.nonNull(followReply)) {
|
|
|
|
+ // 设置了关注回复
|
|
|
|
+ logger.info("********************* 设置了关注回复 *****************");
|
|
|
|
+ weChatService.sendMessage(accountId,openId,"",followReply.getContents());
|
|
|
|
+ return Constants.SUCCESS;
|
|
|
|
+ }
|
|
|
|
+ // 是否有智能推送
|
|
|
|
+ weChatService.sendPushMessage(accountId,openId,0);
|
|
return Constants.SUCCESS;
|
|
return Constants.SUCCESS;
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -91,10 +118,17 @@ public class EventMessageServiceImpl implements WeChatMessageService {
|
|
*/
|
|
*/
|
|
private String scanEvent (Map<String,String> param) {
|
|
private String scanEvent (Map<String,String> param) {
|
|
String key = param.get("EventKey");
|
|
String key = param.get("EventKey");
|
|
- if (StringUtils.isEmpty(key)) {
|
|
|
|
- return unSupportedMessage(param);
|
|
|
|
|
|
+ String accountId = param.get("accountId");
|
|
|
|
+ String openId = param.get("FromUserName");
|
|
|
|
+ if (!StringUtils.isEmpty(key)) {
|
|
|
|
+ logger.info("************** SCAN Received weChat event key : {} ****************",key);
|
|
|
|
+ QrCode qrCode = qrCodeService.getById(key);
|
|
|
|
+ qrCode.setFollowNum(qrCode.getFollowNum()+1);
|
|
|
|
+ qrCode.setTotalNum(qrCode.getTotalNum()+1);
|
|
|
|
+ qrCodeService.updateById(qrCode);
|
|
|
|
+ scanQrHandler.addElement(accountId,openId,key,qrCode.getContent());
|
|
|
|
+ return Constants.SUCCESS;
|
|
}
|
|
}
|
|
- logger.info("************** SCAN Received weChat event key : {} ****************",key);
|
|
|
|
return Constants.SUCCESS;
|
|
return Constants.SUCCESS;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -124,6 +158,11 @@ public class EventMessageServiceImpl implements WeChatMessageService {
|
|
private String clickEvent (Map<String,String> param) {
|
|
private String clickEvent (Map<String,String> param) {
|
|
String key = param.get("EventKey");
|
|
String key = param.get("EventKey");
|
|
logger.info("************** CLICK Received weChat event key : {} ****************",key);
|
|
logger.info("************** CLICK Received weChat event key : {} ****************",key);
|
|
|
|
+ String accountId = param.get("accountId");
|
|
|
|
+ String openId = param.get("FromUserName");
|
|
|
|
+ FansActionStat var2 = new FansActionStat(accountId,openId,5);
|
|
|
|
+ fansActionStatService.saveBatchFansActionStat(var2);
|
|
|
|
+ weChatService.sendPushMessage(accountId,openId,2);
|
|
return Constants.SUCCESS;
|
|
return Constants.SUCCESS;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -138,7 +177,48 @@ public class EventMessageServiceImpl implements WeChatMessageService {
|
|
private String viewEvent (Map<String,String> param) {
|
|
private String viewEvent (Map<String,String> param) {
|
|
String key = param.get("EventKey");
|
|
String key = param.get("EventKey");
|
|
logger.info("************** VIEW Received weChat event key : {} ****************",key);
|
|
logger.info("************** VIEW Received weChat event key : {} ****************",key);
|
|
|
|
+ String accountId = param.get("accountId");
|
|
|
|
+ String openId = param.get("FromUserName");
|
|
|
|
+ FansActionStat var2 = new FansActionStat(accountId,openId,5);
|
|
|
|
+ fansActionStatService.saveBatchFansActionStat(var2);
|
|
|
|
+ return Constants.SUCCESS;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 取关事件
|
|
|
|
+ * @author wangxiao
|
|
|
|
+ * @date 20:17 2020/9/24
|
|
|
|
+ * @param param param
|
|
|
|
+ * @return java.lang.String
|
|
|
|
+ */
|
|
|
|
+ private String unsubscribeEvent(Map<String,String> param) {
|
|
|
|
+ logger.info("************** unsubscribe Received weChat ****************");
|
|
|
|
+ String accountId = param.get("accountId");
|
|
|
|
+ String openId = param.get("FromUserName");
|
|
|
|
+ FansActionStat var2 = new FansActionStat(accountId,openId,3);
|
|
|
|
+ fansActionStatService.saveBatchFansActionStat(var2);
|
|
|
|
+ fansService.unsubscribe(accountId,openId);
|
|
return Constants.SUCCESS;
|
|
return Constants.SUCCESS;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void afterPropertiesSet() {
|
|
|
|
+ logger.info("微信消息,事件处理类--------------->正在初始化");
|
|
|
|
+ synchronized (eventMap) {
|
|
|
|
+ eventMap.put("subscribe",this::subscribeEvent);
|
|
|
|
+ eventMap.put("SCAN",this::scanEvent);
|
|
|
|
+ eventMap.put("LOCATION",this::locationEvent);
|
|
|
|
+ eventMap.put("CLICK",this::clickEvent);
|
|
|
|
+ eventMap.put("VIEW",this::viewEvent);
|
|
|
|
+ eventMap.put("unsubscribe",this::unsubscribeEvent);
|
|
|
|
+ }
|
|
|
|
+ logger.info("微信消息,事件处理类--------------->初始化完成");
|
|
|
|
+ WeChatMessageFactory.addService("event",this);
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
}
|
|
}
|