|
@@ -1,128 +1,128 @@
|
|
|
-package org.springblade.producer.bean;
|
|
|
-
|
|
|
-import com.alibaba.fastjson.JSON;
|
|
|
-import org.apache.logging.log4j.LogManager;
|
|
|
-import org.apache.logging.log4j.Logger;
|
|
|
-import org.aspectj.lang.JoinPoint;
|
|
|
-import org.aspectj.lang.annotation.AfterReturning;
|
|
|
-import org.aspectj.lang.annotation.Aspect;
|
|
|
-import org.aspectj.lang.annotation.Pointcut;
|
|
|
-import org.aspectj.lang.reflect.MethodSignature;
|
|
|
-import org.springblade.business.feign.BusinessWebSocketClient;
|
|
|
-import org.springblade.core.tool.api.R;
|
|
|
-import org.springblade.feign.ArchiveWebSocketClient;
|
|
|
-import org.springblade.manager.feign.ManagerWebSocketClient;
|
|
|
-import org.springblade.meter.feign.MeterWebSocketClient;
|
|
|
-import org.springblade.common.constant.ClientIdConstant;
|
|
|
-
|
|
|
-import org.springblade.producer.feign.RabbitMqProducerServiceClient;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.stereotype.Component;
|
|
|
-import org.springframework.util.StringUtils;
|
|
|
-
|
|
|
-import java.lang.reflect.Method;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.Map;
|
|
|
-import java.util.Set;
|
|
|
-
|
|
|
-@Aspect
|
|
|
-@Component
|
|
|
-public class PushMessageAspect {
|
|
|
-
|
|
|
- private static final Logger logger = LogManager.getLogger(PushMessageAspect.class);
|
|
|
-
|
|
|
- private final RabbitMqProducerServiceClient rabbitMqProducerServiceClient;
|
|
|
- private final ArchiveWebSocketClient archiveWebSocketClient;
|
|
|
- private final BusinessWebSocketClient businessWebSocketClient;
|
|
|
- private final ManagerWebSocketClient managerWebSocketClient;
|
|
|
- private final MeterWebSocketClient meterWebSocketClient;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- public PushMessageAspect(RabbitMqProducerServiceClient rabbitMqProducerServiceClient, ArchiveWebSocketClient archiveWebSocketClient, BusinessWebSocketClient businessWebSocketClient, ManagerWebSocketClient managerWebSocketClient, MeterWebSocketClient meterWebSocketClient) {
|
|
|
- this.rabbitMqProducerServiceClient = rabbitMqProducerServiceClient;
|
|
|
- this.archiveWebSocketClient = archiveWebSocketClient;
|
|
|
- this.businessWebSocketClient = businessWebSocketClient;
|
|
|
- this.managerWebSocketClient = managerWebSocketClient;
|
|
|
- this.meterWebSocketClient = meterWebSocketClient;
|
|
|
- }
|
|
|
-
|
|
|
- @Pointcut("@annotation(org.springblade.producer.bean.PushMessage)")
|
|
|
- public void pushMessagePointcut() {
|
|
|
- }
|
|
|
-
|
|
|
- @AfterReturning(value = "pushMessagePointcut()", returning = "result")
|
|
|
- public void pushMessageAfterMethod(JoinPoint joinPoint, Object result) {
|
|
|
- logger.info("=========================================== push message start ======================================");
|
|
|
- if (result instanceof R) {
|
|
|
- R<?> r = (R<?>) result;
|
|
|
- Object objSet = r.getData();
|
|
|
- if (objSet instanceof Set) {
|
|
|
- MethodSignature signature = (MethodSignature) joinPoint.getSignature();
|
|
|
- Method method = signature.getMethod();
|
|
|
- PushMessage pushMessage = method.getAnnotation(PushMessage.class);
|
|
|
- String clientIds = pushMessage.clientId();
|
|
|
- if (StringUtils.hasText(clientIds)) {
|
|
|
- for (String clientId : clientIds.split(",")) {
|
|
|
- Set<?> rawSet = (Set<?>) objSet;
|
|
|
- for (Object element : rawSet) {
|
|
|
- if (element instanceof String) {
|
|
|
- String param = (String) element;
|
|
|
- String userId = param.split(",")[0];
|
|
|
- String projectId = param.split(",")[1];
|
|
|
- String contractId = param.split(",")[2];
|
|
|
- this.pushMessageToMqQueue(clientId, userId, projectId, contractId);
|
|
|
- }
|
|
|
- }
|
|
|
- logger.info("=========================================== push message end ========================================");
|
|
|
- }
|
|
|
- } else {
|
|
|
- logger.info("=========================================== clientId is null ========================================");
|
|
|
- }
|
|
|
- } else {
|
|
|
- logger.info("=========================================== data is null ========================================");
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private void pushMessageToMqQueue(String clientId, String userId, String projectId, String contractId) {
|
|
|
- Map<String, String> stringMap = this.getTaskStringMapData(projectId, contractId, userId, clientId);
|
|
|
- if (stringMap.size() > 0) {
|
|
|
- switch (clientId) {
|
|
|
- case ClientIdConstant.ARCHIVE_CLIENT_ID:
|
|
|
- rabbitMqProducerServiceClient.sendMessageToArchiveQueue(JSON.toJSONString(stringMap));
|
|
|
- break;
|
|
|
- case ClientIdConstant.MANAGER_CLIENT_ID:
|
|
|
- rabbitMqProducerServiceClient.sendMessageToManagerQueue(JSON.toJSONString(stringMap));
|
|
|
- break;
|
|
|
- case ClientIdConstant.BUSINESS_CLIENT_ID:
|
|
|
- rabbitMqProducerServiceClient.sendMessageToBusinessQueue(JSON.toJSONString(stringMap));
|
|
|
- break;
|
|
|
- case ClientIdConstant.METER_CLIENT_ID:
|
|
|
- rabbitMqProducerServiceClient.sendMessageToMeterQueue(JSON.toJSONString(stringMap));
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private Map<String, String> getTaskStringMapData(String projectId, String contractId, String userId, String clientId) {
|
|
|
- Map<String, String> stringMap = new HashMap<>();
|
|
|
- if (StringUtils.hasText(clientId)) {
|
|
|
- switch (clientId) {
|
|
|
- case ClientIdConstant.ARCHIVE_CLIENT_ID:
|
|
|
- stringMap = archiveWebSocketClient.getWebsocketMsg(projectId, contractId, userId);
|
|
|
- break;
|
|
|
- case ClientIdConstant.MANAGER_CLIENT_ID:
|
|
|
- stringMap = managerWebSocketClient.getWebsocketMsg(projectId, contractId, userId);
|
|
|
- break;
|
|
|
- case ClientIdConstant.BUSINESS_CLIENT_ID:
|
|
|
- stringMap = businessWebSocketClient.getWebsocketMsg(projectId, contractId, userId);
|
|
|
- break;
|
|
|
- case ClientIdConstant.METER_CLIENT_ID:
|
|
|
- // TODO stringMap = meterWebSocketClient.getWebsocketMsg(projectId, contractId, userId);
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- return stringMap;
|
|
|
- }
|
|
|
-
|
|
|
-}
|
|
|
+//package org.springblade.producer.bean;
|
|
|
+//
|
|
|
+//import com.alibaba.fastjson.JSON;
|
|
|
+//import org.apache.logging.log4j.LogManager;
|
|
|
+//import org.apache.logging.log4j.Logger;
|
|
|
+//import org.aspectj.lang.JoinPoint;
|
|
|
+//import org.aspectj.lang.annotation.AfterReturning;
|
|
|
+//import org.aspectj.lang.annotation.Aspect;
|
|
|
+//import org.aspectj.lang.annotation.Pointcut;
|
|
|
+//import org.aspectj.lang.reflect.MethodSignature;
|
|
|
+//import org.springblade.business.feign.BusinessWebSocketClient;
|
|
|
+//import org.springblade.core.tool.api.R;
|
|
|
+//import org.springblade.feign.ArchiveWebSocketClient;
|
|
|
+//import org.springblade.manager.feign.ManagerWebSocketClient;
|
|
|
+//import org.springblade.meter.feign.MeterWebSocketClient;
|
|
|
+//import org.springblade.common.constant.ClientIdConstant;
|
|
|
+//
|
|
|
+//import org.springblade.producer.feign.RabbitMqProducerServiceClient;
|
|
|
+//import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+//import org.springframework.stereotype.Component;
|
|
|
+//import org.springframework.util.StringUtils;
|
|
|
+//
|
|
|
+//import java.lang.reflect.Method;
|
|
|
+//import java.util.HashMap;
|
|
|
+//import java.util.Map;
|
|
|
+//import java.util.Set;
|
|
|
+//
|
|
|
+//@Aspect
|
|
|
+//@Component
|
|
|
+//public class PushMessageAspect {
|
|
|
+//
|
|
|
+// private static final Logger logger = LogManager.getLogger(PushMessageAspect.class);
|
|
|
+//
|
|
|
+// private final RabbitMqProducerServiceClient rabbitMqProducerServiceClient;
|
|
|
+// private final ArchiveWebSocketClient archiveWebSocketClient;
|
|
|
+// private final BusinessWebSocketClient businessWebSocketClient;
|
|
|
+// private final ManagerWebSocketClient managerWebSocketClient;
|
|
|
+// private final MeterWebSocketClient meterWebSocketClient;
|
|
|
+//
|
|
|
+// @Autowired
|
|
|
+// public PushMessageAspect(RabbitMqProducerServiceClient rabbitMqProducerServiceClient, ArchiveWebSocketClient archiveWebSocketClient, BusinessWebSocketClient businessWebSocketClient, ManagerWebSocketClient managerWebSocketClient, MeterWebSocketClient meterWebSocketClient) {
|
|
|
+// this.rabbitMqProducerServiceClient = rabbitMqProducerServiceClient;
|
|
|
+// this.archiveWebSocketClient = archiveWebSocketClient;
|
|
|
+// this.businessWebSocketClient = businessWebSocketClient;
|
|
|
+// this.managerWebSocketClient = managerWebSocketClient;
|
|
|
+// this.meterWebSocketClient = meterWebSocketClient;
|
|
|
+// }
|
|
|
+//
|
|
|
+// @Pointcut("@annotation(org.springblade.producer.bean.PushMessage)")
|
|
|
+// public void pushMessagePointcut() {
|
|
|
+// }
|
|
|
+//
|
|
|
+// @AfterReturning(value = "pushMessagePointcut()", returning = "result")
|
|
|
+// public void pushMessageAfterMethod(JoinPoint joinPoint, Object result) {
|
|
|
+// logger.info("=========================================== push message start ======================================");
|
|
|
+// if (result instanceof R) {
|
|
|
+// R<?> r = (R<?>) result;
|
|
|
+// Object objSet = r.getData();
|
|
|
+// if (objSet instanceof Set) {
|
|
|
+// MethodSignature signature = (MethodSignature) joinPoint.getSignature();
|
|
|
+// Method method = signature.getMethod();
|
|
|
+// PushMessage pushMessage = method.getAnnotation(PushMessage.class);
|
|
|
+// String clientIds = pushMessage.clientId();
|
|
|
+// if (StringUtils.hasText(clientIds)) {
|
|
|
+// for (String clientId : clientIds.split(",")) {
|
|
|
+// Set<?> rawSet = (Set<?>) objSet;
|
|
|
+// for (Object element : rawSet) {
|
|
|
+// if (element instanceof String) {
|
|
|
+// String param = (String) element;
|
|
|
+// String userId = param.split(",")[0];
|
|
|
+// String projectId = param.split(",")[1];
|
|
|
+// String contractId = param.split(",")[2];
|
|
|
+// this.pushMessageToMqQueue(clientId, userId, projectId, contractId);
|
|
|
+// }
|
|
|
+// }
|
|
|
+// logger.info("=========================================== push message end ========================================");
|
|
|
+// }
|
|
|
+// } else {
|
|
|
+// logger.info("=========================================== clientId is null ========================================");
|
|
|
+// }
|
|
|
+// } else {
|
|
|
+// logger.info("=========================================== data is null ========================================");
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// private void pushMessageToMqQueue(String clientId, String userId, String projectId, String contractId) {
|
|
|
+// Map<String, String> stringMap = this.getTaskStringMapData(projectId, contractId, userId, clientId);
|
|
|
+// if (stringMap.size() > 0) {
|
|
|
+// switch (clientId) {
|
|
|
+// case ClientIdConstant.ARCHIVE_CLIENT_ID:
|
|
|
+// rabbitMqProducerServiceClient.sendMessageToArchiveQueue(JSON.toJSONString(stringMap));
|
|
|
+// break;
|
|
|
+// case ClientIdConstant.MANAGER_CLIENT_ID:
|
|
|
+// rabbitMqProducerServiceClient.sendMessageToManagerQueue(JSON.toJSONString(stringMap));
|
|
|
+// break;
|
|
|
+// case ClientIdConstant.BUSINESS_CLIENT_ID:
|
|
|
+// rabbitMqProducerServiceClient.sendMessageToBusinessQueue(JSON.toJSONString(stringMap));
|
|
|
+// break;
|
|
|
+// case ClientIdConstant.METER_CLIENT_ID:
|
|
|
+// rabbitMqProducerServiceClient.sendMessageToMeterQueue(JSON.toJSONString(stringMap));
|
|
|
+// break;
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// private Map<String, String> getTaskStringMapData(String projectId, String contractId, String userId, String clientId) {
|
|
|
+// Map<String, String> stringMap = new HashMap<>();
|
|
|
+// if (StringUtils.hasText(clientId)) {
|
|
|
+// switch (clientId) {
|
|
|
+// case ClientIdConstant.ARCHIVE_CLIENT_ID:
|
|
|
+// stringMap = archiveWebSocketClient.getWebsocketMsg(projectId, contractId, userId);
|
|
|
+// break;
|
|
|
+// case ClientIdConstant.MANAGER_CLIENT_ID:
|
|
|
+// stringMap = managerWebSocketClient.getWebsocketMsg(projectId, contractId, userId);
|
|
|
+// break;
|
|
|
+// case ClientIdConstant.BUSINESS_CLIENT_ID:
|
|
|
+// stringMap = businessWebSocketClient.getWebsocketMsg(projectId, contractId, userId);
|
|
|
+// break;
|
|
|
+// case ClientIdConstant.METER_CLIENT_ID:
|
|
|
+// // TODO stringMap = meterWebSocketClient.getWebsocketMsg(projectId, contractId, userId);
|
|
|
+// break;
|
|
|
+// }
|
|
|
+// }
|
|
|
+// return stringMap;
|
|
|
+// }
|
|
|
+//
|
|
|
+//}
|