|
|
@@ -4,26 +4,23 @@ import com.alibaba.fastjson2.JSONObject;
|
|
|
import com.yunfeiyun.agmp.iot.common.constant.devicetype.IotDeviceDictConst;
|
|
|
import com.yunfeiyun.agmp.iot.common.constant.cmd.CmdStatus;
|
|
|
import com.yunfeiyun.agmp.iot.common.domain.IotDevice;
|
|
|
+import com.yunfeiyun.agmp.iots.config.TestConst;
|
|
|
import com.yunfeiyun.agmp.iots.core.cmd.core.CmdDispatcherService;
|
|
|
import com.yunfeiyun.agmp.iots.core.cmd.model.CmdExecModel;
|
|
|
-import com.yunfeiyun.agmp.iots.service.IIotDeviceService;
|
|
|
import com.yunfeiyun.agmp.iots.core.cmd.core.CmdCheckScheduledFuture;
|
|
|
import com.yunfeiyun.agmp.iots.core.cmd.core.CmdResultTimedout;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.http.util.TextUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
-import javax.annotation.Resource;
|
|
|
import java.util.concurrent.*;
|
|
|
|
|
|
@Slf4j
|
|
|
@Service
|
|
|
public class CmdResultCheckService {
|
|
|
|
|
|
- @Resource
|
|
|
- private IIotDeviceService iIotDeviceService;
|
|
|
-
|
|
|
- @Resource
|
|
|
+ @Autowired
|
|
|
private CmdDispatcherService cmdDispatcherService;
|
|
|
|
|
|
|
|
|
@@ -54,7 +51,7 @@ public class CmdResultCheckService {
|
|
|
|
|
|
String deviceID = cmdExecModel.getCmdModel().getDeviceId();
|
|
|
log.info("任务id【{}】Checker : 创建, 设备id:{}, 指令:{}", cmdExecModel.getTaskUuid(), deviceID, cmdExecModel.getCmdModel().getCmdDistribution());
|
|
|
-
|
|
|
+ //这里需要该,根据新的判断逻辑,创建对应的checker
|
|
|
CmdResultChecker cmdResultChecker = newChecker(iotDevice, cmdExecModel);
|
|
|
log.info("任务id【{}】,创建结果:{}", cmdExecModel.getTaskUuid(), cmdResultChecker);
|
|
|
|
|
|
@@ -62,14 +59,14 @@ public class CmdResultCheckService {
|
|
|
log.error("任务id【{}】,【指令结果检查器】创建异常!");
|
|
|
return;
|
|
|
}
|
|
|
-
|
|
|
- if (hmChecker.get(deviceID) != null) {
|
|
|
- hmChecker.get(deviceID).put(cmdExecModel.getCeBid(), cmdResultChecker);
|
|
|
+ ConcurrentHashMap<String, CmdResultChecker> checkerMap = hmChecker.get(deviceID);
|
|
|
+ if (checkerMap != null) {
|
|
|
+ checkerMap.put(cmdExecModel.getCeBid(), cmdResultChecker);
|
|
|
log.info("任务id【{}】,在已有list中添加item", cmdExecModel.getTaskUuid());
|
|
|
} else {
|
|
|
- ConcurrentHashMap<String, CmdResultChecker> list = new ConcurrentHashMap<>();
|
|
|
- list.put(cmdExecModel.getCeBid(), cmdResultChecker);
|
|
|
- hmChecker.put(deviceID, list);
|
|
|
+ checkerMap = new ConcurrentHashMap<>();
|
|
|
+ checkerMap.put(cmdExecModel.getCeBid(), cmdResultChecker);
|
|
|
+ hmChecker.put(deviceID, checkerMap);
|
|
|
log.info("任务id【{}】,新建list,在里面添加一个item", cmdExecModel.getTaskUuid());
|
|
|
}
|
|
|
|
|
|
@@ -80,12 +77,13 @@ public class CmdResultCheckService {
|
|
|
, TimeUnit.SECONDS
|
|
|
);
|
|
|
CmdCheckScheduledFuture future = new CmdCheckScheduledFuture(cmdExecModel, scheduledFuture);
|
|
|
- if (hmFuture.get(deviceID) != null) {
|
|
|
- hmFuture.get(deviceID).put(cmdExecModel.getCeBid(), future);
|
|
|
+ ConcurrentHashMap<String, CmdCheckScheduledFuture> checkScheduledFutureMap = hmFuture.get(deviceID);
|
|
|
+ if (checkScheduledFutureMap != null) {
|
|
|
+ checkScheduledFutureMap.put(cmdExecModel.getCeBid(), future);
|
|
|
} else {
|
|
|
- ConcurrentHashMap<String, CmdCheckScheduledFuture> list = new ConcurrentHashMap<>();
|
|
|
- list.put(cmdExecModel.getCeBid(), future);
|
|
|
- hmFuture.put(deviceID, list);
|
|
|
+ checkScheduledFutureMap = new ConcurrentHashMap<>();
|
|
|
+ checkScheduledFutureMap.put(cmdExecModel.getCeBid(), future);
|
|
|
+ hmFuture.put(deviceID, checkScheduledFutureMap);
|
|
|
}
|
|
|
log.debug("任务id【{}】,指令执行结果检查器 已添加 指令:{}", cmdExecModel.getTaskUuid(), cmdExecModel);
|
|
|
}
|
|
|
@@ -96,8 +94,8 @@ public class CmdResultCheckService {
|
|
|
* @param cmdExecModel
|
|
|
*/
|
|
|
public void onChecked(CmdExecModel cmdExecModel) {
|
|
|
- if(true){
|
|
|
- log.info("!!!!!!!!!!【看这里:临时测试】checker 因为iots直接下发指令测试,没有塞缓存task,先强制关闭,联调到iotm iots,再打开");
|
|
|
+ if (true) {
|
|
|
+ TestConst.printError("!!!!!!!!!!【看这里:临时测试】checker 因为iots直接下发指令测试,没有塞缓存task,先强制关闭,联调到iotm iots,再打开");
|
|
|
return;
|
|
|
}
|
|
|
if (cmdExecModel == null) {
|
|
|
@@ -197,15 +195,9 @@ public class CmdResultCheckService {
|
|
|
private void removeChecker(CmdExecModel cmdExecModel) {
|
|
|
CmdResultChecker findItem = null;
|
|
|
ConcurrentHashMap<String, CmdResultChecker> list = hmChecker.get(cmdExecModel.getCmdModel().getDeviceId());
|
|
|
- log.info("111遍历cheker{}", list);
|
|
|
if (list != null) {
|
|
|
- log.info("222遍历cheker{}", list);
|
|
|
for (CmdResultChecker item : list.values()) {
|
|
|
- log.info("设备标识{},当前指令执行bid{},当前检查器关联指令执行{}"
|
|
|
- , cmdExecModel.getCmdModel().getDeviceId()
|
|
|
- , cmdExecModel.getCeBid()
|
|
|
- , item.getCmdExecModel()
|
|
|
- );
|
|
|
+ log.info("设备标识{},当前指令执行bid{},当前检查器关联指令执行{}", cmdExecModel.getCmdModel().getDeviceId(), cmdExecModel.getCeBid(), item.getCmdExecModel());
|
|
|
if (cmdExecModel.getCeBid().equals(item.getCmdExecModel().getCeBid())) {
|
|
|
findItem = item;
|
|
|
break;
|
|
|
@@ -242,11 +234,10 @@ public class CmdResultCheckService {
|
|
|
* @return
|
|
|
*/
|
|
|
private CmdResultChecker newChecker(IotDevice iotDevice, CmdExecModel cmdExecModel) {
|
|
|
- //TODO 临时逻辑 ,需要机制缓存相关对应关系
|
|
|
if (IotDeviceDictConst.TYPE_YF_CBD.equals(iotDevice.getDevtypeBid()) || IotDeviceDictConst.TYPE_YF_GKCBD.equals(iotDevice.getDevtypeBid())) {
|
|
|
- return new YfCbdCmdResultChecker(cmdExecModel, this, cmdDispatcherService);
|
|
|
- } else if (IotDeviceDictConst.TYPE_YF_JKSB.equals(iotDevice.getDevtypeBid())) {
|
|
|
- return new EzvizCmdResultChecker(cmdExecModel, this, cmdDispatcherService);
|
|
|
+ return new YfCbdCmdResultChecker(cmdExecModel);
|
|
|
+ } else if (IotDeviceDictConst.TYPE_YF_JKSB.equals(iotDevice.getDevtypeBid())) {
|
|
|
+ return new EzvizCmdResultChecker(cmdExecModel);
|
|
|
}
|
|
|
return null;
|
|
|
}
|