|
|
@@ -7,6 +7,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.google.common.collect.Lists;
|
|
|
+import com.google.common.collect.Sets;
|
|
|
import com.xunmei.common.core.constant.CacheConstants;
|
|
|
import com.xunmei.common.core.constant.SecurityConstants;
|
|
|
import com.xunmei.common.core.domain.iot.domain.IotDeviceDiagnoseThreshold;
|
|
|
@@ -26,6 +27,7 @@ import com.xunmei.iot.vo.sensor.DiagnoseThresholdAddVo;
|
|
|
import com.xunmei.iot.vo.sensor.DiagnoseThresholdBindVo;
|
|
|
import com.xunmei.iot.vo.sensor.DiagnoseThresholdExportVo;
|
|
|
import com.xunmei.iot.vo.sensor.DiagnoseThresholdPageVo;
|
|
|
+import com.xunmei.system.api.RemoteHostService;
|
|
|
import com.xunmei.system.api.RemoteOrgService;
|
|
|
import com.xunmei.system.api.domain.SysOrg;
|
|
|
import com.xunmei.system.api.vo.SysOrgVO;
|
|
|
@@ -33,19 +35,23 @@ import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.transaction.support.TransactionSynchronizationAdapter;
|
|
|
+import org.springframework.transaction.support.TransactionSynchronizationManager;
|
|
|
import org.springframework.util.DigestUtils;
|
|
|
import javax.annotation.Resource;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
import java.net.URLEncoder;
|
|
|
import java.util.Arrays;
|
|
|
import java.util.List;
|
|
|
+import java.util.Set;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@Service
|
|
|
public class DiagnoseThresholdServiceImpl implements DiagnoseThresholdService {
|
|
|
@Resource
|
|
|
private RemoteOrgService orgService;
|
|
|
-
|
|
|
+ @Autowired
|
|
|
+ private RemoteHostService hostService;
|
|
|
@Autowired
|
|
|
private DiagnoseThresholdChMapper diagnoseThresholdChMapper;
|
|
|
|
|
|
@@ -118,12 +124,15 @@ public class DiagnoseThresholdServiceImpl implements DiagnoseThresholdService {
|
|
|
List<DiagnoseThresholdBindVo> list = diagnoseThresholdChMapper.selectCamerasBind(req);
|
|
|
//获取要绑定的通道
|
|
|
List<IotDeviceDiagnoseThresholdCh> batchInserts = Lists.newArrayList();
|
|
|
+ Set<String> syncIotTokens = Sets.newHashSet();
|
|
|
|
|
|
List<String> bindThresholdCodes = req.getBindThresholdCodes();
|
|
|
if (bindThresholdCodes != null && !bindThresholdCodes.isEmpty()) {
|
|
|
for (String bindThresholdCode:bindThresholdCodes) {
|
|
|
for (DiagnoseThresholdBindVo info : list) {
|
|
|
String beanThresholdCodes = info.getThresholdCodes();
|
|
|
+ //添加需要同步到主机的token
|
|
|
+ syncIotTokens.add(info.getIotToken());
|
|
|
//避免重复绑定
|
|
|
if (StringUtils.isNotEmpty(beanThresholdCodes)
|
|
|
&&beanThresholdCodes.contains(bindThresholdCode)) {continue;}
|
|
|
@@ -147,9 +156,12 @@ public class DiagnoseThresholdServiceImpl implements DiagnoseThresholdService {
|
|
|
diagnoseThresholdChMapper.updateDiagnoseNumber(bindThresholdCode);
|
|
|
}
|
|
|
}
|
|
|
+ //下发同步主机
|
|
|
+ this.syncDiagnose(syncIotTokens);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
+ @Transactional
|
|
|
public void camerasUnbind(DiagnoseThresholdPageDto req){
|
|
|
final SysOrg sysOrg = orgService.selectOrgById(req.getOrgId(), SecurityConstants.INNER);
|
|
|
if (ObjectUtil.equal(Boolean.TRUE, req.getCheckSub())) {
|
|
|
@@ -164,7 +176,7 @@ public class DiagnoseThresholdServiceImpl implements DiagnoseThresholdService {
|
|
|
}
|
|
|
|
|
|
List<DiagnoseThresholdBindVo> list = diagnoseThresholdChMapper.selectCamerasBind(req);
|
|
|
-
|
|
|
+ Set<String> syncIotTokens = Sets.newHashSet();
|
|
|
//需要解除绑定的id集合
|
|
|
List<Long> unbindIds = Lists.newArrayList();
|
|
|
|
|
|
@@ -173,6 +185,8 @@ public class DiagnoseThresholdServiceImpl implements DiagnoseThresholdService {
|
|
|
for (String unbindThresholdCode:unbindThresholdCodes) {
|
|
|
for (DiagnoseThresholdBindVo info : list) {
|
|
|
String beanThresholdCodes = info.getThresholdCodes();
|
|
|
+ //添加需要同步到主机的token
|
|
|
+ syncIotTokens.add(info.getIotToken());
|
|
|
//通道是否有绑定阈值
|
|
|
if(StringUtils.isNotEmpty(beanThresholdCodes)) {
|
|
|
String[] beanThresholdCodeArr = beanThresholdCodes.split(",");
|
|
|
@@ -196,6 +210,8 @@ public class DiagnoseThresholdServiceImpl implements DiagnoseThresholdService {
|
|
|
diagnoseThresholdChMapper.updateDiagnoseNumber(bindThresholdCode);
|
|
|
}
|
|
|
}
|
|
|
+ //下发同步主机
|
|
|
+ this.syncDiagnose(syncIotTokens);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -397,6 +413,19 @@ public class DiagnoseThresholdServiceImpl implements DiagnoseThresholdService {
|
|
|
return list;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public void syncDiagnose(Set<String> iotCodes) {
|
|
|
+ TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronizationAdapter() {
|
|
|
+ @Override
|
|
|
+ public void afterCommit() {
|
|
|
+
|
|
|
+ hostService.syncDiagnoseToHost(iotCodes);
|
|
|
+
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
private String getThresholdGuid(IotDeviceDiagnoseThreshold threshold) {
|
|
|
StringBuffer sb = new StringBuffer();
|
|
|
String color = "@value>=150";
|