|
|
@@ -5,10 +5,14 @@ import cn.hutool.json.JSONUtil;
|
|
|
import com.google.gson.JsonObject;
|
|
|
import com.zswl.dataservice.dao.mqtt.DeviceInfoDao;
|
|
|
import com.zswl.dataservice.dao.mqtt.OperationMessageDao;
|
|
|
+import com.zswl.dataservice.dao.other.ExecuteMethodInfoDao;
|
|
|
import com.zswl.dataservice.domain.mqtt.DeviceInfo;
|
|
|
import com.zswl.dataservice.domain.mqtt.OperationMessage;
|
|
|
+import com.zswl.dataservice.domain.other.ExecuteMethodInfo;
|
|
|
+import com.zswl.dataservice.helper.ApplicationContextHolder;
|
|
|
import com.zswl.dataservice.model.hxz.ConsumTransactionsModel;
|
|
|
import com.zswl.dataservice.model.mqtt.*;
|
|
|
+import com.zswl.dataservice.service.base.SuperService;
|
|
|
import com.zswl.dataservice.service.mqtt.DeviceInfoService;
|
|
|
import com.zswl.dataservice.service.mqtt.GateWayInfoService;
|
|
|
import com.zswl.dataservice.service.payment.HxzService;
|
|
|
@@ -21,10 +25,12 @@ import com.zswl.dataservice.utils.result.ResultContent;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang3.ObjectUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.context.ApplicationContext;
|
|
|
import org.springframework.data.domain.Page;
|
|
|
import org.springframework.data.domain.Pageable;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import java.lang.reflect.Method;
|
|
|
import java.util.Date;
|
|
|
import java.util.UUID;
|
|
|
|
|
|
@@ -59,6 +65,12 @@ public class OperationMessageService {
|
|
|
// 保存90天
|
|
|
private Long ttlMill = 90 * 24L * 60 * 60 * 1000L;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private ExecuteMethodInfoDao executeMethodInfoDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ApplicationContext applicationContext;
|
|
|
+
|
|
|
/**
|
|
|
* 给设备下发指令
|
|
|
*
|
|
|
@@ -119,14 +131,17 @@ public class OperationMessageService {
|
|
|
public ResultContent addOperationMessage(OperationMessage entity) {
|
|
|
entity.setTime(DateUtils.paresTime(System.currentTimeMillis(), DateUtils.patternyyyySSS));
|
|
|
entity.setTtl(new Date(System.currentTimeMillis() + ttlMill));
|
|
|
- if(entity.getIsTimeOut()) {
|
|
|
+ if (entity.getIsTimeOut()) {
|
|
|
entity.setHandleMsg("超时不处理");
|
|
|
}
|
|
|
- operationMessageDao.save(entity);
|
|
|
boolean isTimeOut = entity.getIsTimeOut();
|
|
|
- if(!isTimeOut) {
|
|
|
- // 处理消息
|
|
|
+ // TODO
|
|
|
+ if (isTimeOut) {
|
|
|
+ // 未超时,处理消息
|
|
|
handleOperationMessage(entity);
|
|
|
+ } else {
|
|
|
+ // 超时
|
|
|
+ operationMessageDao.save(entity);
|
|
|
}
|
|
|
return ResultContent.buildSuccess();
|
|
|
}
|
|
|
@@ -142,21 +157,31 @@ public class OperationMessageService {
|
|
|
JSONObject json = (JSONObject) entity.getData();
|
|
|
if (json.containsKey("data")) {
|
|
|
Object result = null;
|
|
|
- String dataStr = json.getStr("data");
|
|
|
|
|
|
boolean isHandleSuccess = true;
|
|
|
String handleMsg = "处理成功";
|
|
|
try {
|
|
|
- // 判断那个业务处理
|
|
|
- if (event.equals("consum")) {
|
|
|
- ConsumTransactionsModel model = JSONUtil.toBean(dataStr, ConsumTransactionsModel.class);
|
|
|
- ResultContent<Object> resultContent = hxzService.consumTransactions(model);
|
|
|
+ ExecuteMethodInfo executeMethodInfo = executeMethodInfoDao.findTopByEvent(event);
|
|
|
+ if (ObjectUtils.isNotEmpty(executeMethodInfo)) {
|
|
|
+ String dataStr = json.getStr("data");
|
|
|
+
|
|
|
+ String beanName = executeMethodInfo.getBeanName();
|
|
|
+ String methodName = executeMethodInfo.getMethodName();
|
|
|
+ Class c = applicationContext.getBean(beanName).getClass();
|
|
|
+ SuperService t = (SuperService) applicationContext.getBean(beanName);
|
|
|
+ Method method = c.getMethod(methodName, String.class);
|
|
|
+ ResultContent<Object> resultContent = (ResultContent<Object>) method.invoke(t, dataStr);
|
|
|
if (resultContent.isSuccess()) {
|
|
|
result = resultContent.getContent();
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
isHandleSuccess = false;
|
|
|
handleMsg = resultContent.getMsg();
|
|
|
}
|
|
|
+ entity.setBeanName(beanName);
|
|
|
+ entity.setMethodName(methodName);
|
|
|
+ } else {
|
|
|
+ isHandleSuccess = false;
|
|
|
+ handleMsg = "消息处理方法未找到";
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
@@ -172,7 +197,8 @@ public class OperationMessageService {
|
|
|
if (isHandleSuccess) {
|
|
|
// 处理成功,返回响应
|
|
|
responseMessage(entity);
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
+ // 处理失败,记录数据
|
|
|
entity.setReTime(System.currentTimeMillis());
|
|
|
entity.setReTimeStr(DateUtils.paresTime(System.currentTimeMillis(), DateUtils.patternyyyySSS));
|
|
|
operationMessageDao.save(entity);
|