feat: 测温区分大华和海康,拆分开分别处理
parent
d06a31a75e
commit
84ea1ae9f3
@ -0,0 +1,83 @@
|
|||||||
|
package com.xydl.cac.thermal;
|
||||||
|
|
||||||
|
import com.netsdk.lib.NetSDKLib;
|
||||||
|
import com.netsdk.module.LoginModule;
|
||||||
|
import com.netsdk.module.ThermalCameraModule;
|
||||||
|
import com.xydl.cac.entity.NSensor;
|
||||||
|
import com.xydl.cac.entity.ThermalConfig;
|
||||||
|
import com.xydl.cac.model.StaticVariable;
|
||||||
|
import com.xydl.cac.service.DataService;
|
||||||
|
import com.xydl.cac.util.DateUtil;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import javax.annotation.PreDestroy;
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
@Slf4j
|
||||||
|
public class DahuaThermalService {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
DataService dataService;
|
||||||
|
|
||||||
|
int shutdown = 0;
|
||||||
|
|
||||||
|
@PreDestroy
|
||||||
|
private void preDestroy() {
|
||||||
|
shutdown = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void collectAndSave(List<NSensor> list, ThermalConfig config) {
|
||||||
|
if (shutdown == 1) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
LoginModule.init(null, null);
|
||||||
|
NSensor sensor = list.get(0);
|
||||||
|
boolean r = LoginModule.login(sensor.getIp(), sensor.getPort(), sensor.getUsername(), sensor.getPasswd());
|
||||||
|
if (r) {
|
||||||
|
log.info("登入成功" + sensor.getIp() + ":" + sensor.getPort() + ", 用户名:" + sensor.getUsername());
|
||||||
|
} else {
|
||||||
|
log.error("登入失败" + sensor.getIp() + ":" + sensor.getPort() + ", 用户名:" + sensor.getUsername());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
String time = DateUtil.format(new Date());
|
||||||
|
for (NSensor item : list) {
|
||||||
|
NetSDKLib.NET_RADIOMETRYINFO data = ThermalCameraModule.queryItemTemper(0, 0, sensor.getTmId(), sensor.getTmType());
|
||||||
|
if (data == null) {
|
||||||
|
log.warn("没有采集到数据, 序号" + item.getTmId() + "测量项目" + sensor.getTmType());
|
||||||
|
} else {
|
||||||
|
log.info("采集到序号" + item.getTmId() + "测量项目" + sensor.getTmType() + "的max="
|
||||||
|
+ data.fTemperMax + ", min=" + data.fTemperMin + ", aver=" + data.fTemperAver);
|
||||||
|
if (StringUtils.isNotBlank(config.getMaxtemp())) {
|
||||||
|
String value = String.valueOf(data.fTemperMax);
|
||||||
|
dataService.insertData(item.getTableName(), item.getDevId(), time, config.getMaxtemp(), value);
|
||||||
|
// 更新最新数据缓存
|
||||||
|
StaticVariable.updateLastData(item.getDevId(), config.getMaxtemp(), value, time);
|
||||||
|
}
|
||||||
|
if (StringUtils.isNotBlank(config.getMintemp())) {
|
||||||
|
String value = String.valueOf(data.fTemperMin);
|
||||||
|
dataService.insertData(item.getTableName(), item.getDevId(), time, config.getMintemp(), value);
|
||||||
|
// 更新最新数据缓存
|
||||||
|
StaticVariable.updateLastData(item.getDevId(), config.getMintemp(), value, time);
|
||||||
|
}
|
||||||
|
if (StringUtils.isNotBlank(config.getAvertemp())) {
|
||||||
|
String value = String.valueOf(data.fTemperAver);
|
||||||
|
dataService.insertData(item.getTableName(), item.getDevId(), time, config.getAvertemp(), value);
|
||||||
|
// 更新最新数据缓存
|
||||||
|
StaticVariable.updateLastData(item.getDevId(), config.getAvertemp(), value, time);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
LoginModule.logout();
|
||||||
|
} catch (Exception ex) {
|
||||||
|
log.error("大华热成像测温采集异常, " + ex.getMessage(), ex);
|
||||||
|
} finally {
|
||||||
|
LoginModule.cleanup();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,32 @@
|
|||||||
|
package com.xydl.cac.thermal;
|
||||||
|
|
||||||
|
import com.xydl.cac.entity.NSensor;
|
||||||
|
import com.xydl.cac.entity.ThermalConfig;
|
||||||
|
import com.xydl.cac.service.DataService;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import javax.annotation.PreDestroy;
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
@Slf4j
|
||||||
|
public class HikThermalService {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
DataService dataService;
|
||||||
|
|
||||||
|
int shutdown = 0;
|
||||||
|
|
||||||
|
@PreDestroy
|
||||||
|
private void preDestroy() {
|
||||||
|
shutdown = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void collectAndSave(List<NSensor> list, ThermalConfig config) {
|
||||||
|
if (shutdown == 1) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,73 +1,80 @@
|
|||||||
package com.xydl.cac.thermal;
|
package com.xydl.cac.thermal;
|
||||||
|
|
||||||
import com.netsdk.lib.NetSDKLib;
|
|
||||||
import com.netsdk.module.LoginModule;
|
|
||||||
import com.netsdk.module.ThermalCameraModule;
|
|
||||||
import com.xydl.cac.entity.NSensor;
|
import com.xydl.cac.entity.NSensor;
|
||||||
import com.xydl.cac.entity.ThermalConfig;
|
import com.xydl.cac.entity.ThermalConfig;
|
||||||
import com.xydl.cac.model.StaticVariable;
|
|
||||||
import com.xydl.cac.service.DataService;
|
|
||||||
import com.xydl.cac.util.DateUtil;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.util.CollectionUtils;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.util.Date;
|
import java.util.*;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class ThermalCollectService {
|
public class ThermalCollectService {
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
DataService dataService;
|
DahuaThermalService dahuaThermalService;
|
||||||
|
@Resource
|
||||||
|
HikThermalService hikThermalService;
|
||||||
|
|
||||||
public void collectAndSave(List<NSensor> list, ThermalConfig config) {
|
public void collectAndSave(List<NSensor> list, ThermalConfig config) {
|
||||||
try {
|
List<NSensor> dahuaList = new ArrayList<>();
|
||||||
LoginModule.init(null, null);
|
List<NSensor> hikList = new ArrayList<>();
|
||||||
NSensor sensor = list.get(0);
|
for (NSensor sensor : list) {
|
||||||
boolean r = LoginModule.login(sensor.getIp(), sensor.getPort(), sensor.getUsername(), sensor.getPasswd());
|
if (sensor.getSdkType() != null && sensor.getSdkType().intValue() == 2) {
|
||||||
if (r) {
|
hikList.add(sensor);
|
||||||
log.info("登入成功" + sensor.getIp() + ":" + sensor.getPort() + ", 用户名:" + sensor.getUsername());
|
|
||||||
} else {
|
|
||||||
log.error("登入失败" + sensor.getIp() + ":" + sensor.getPort() + ", 用户名:" + sensor.getUsername());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
String time = DateUtil.format(new Date());
|
|
||||||
for (NSensor item : list) {
|
|
||||||
NetSDKLib.NET_RADIOMETRYINFO data = ThermalCameraModule.queryItemTemper(0, 0, sensor.getTmId(), sensor.getTmType());
|
|
||||||
if (data == null) {
|
|
||||||
log.warn("没有采集到数据, 序号" + item.getTmId() + "测量项目" + sensor.getTmType());
|
|
||||||
} else {
|
} else {
|
||||||
log.info("采集到序号" + item.getTmId() + "测量项目" + sensor.getTmType() + "的max="
|
dahuaList.add(sensor);
|
||||||
+ data.fTemperMax + ", min=" + data.fTemperMin + ", aver=" + data.fTemperAver);
|
|
||||||
if (StringUtils.isNotBlank(config.getMaxtemp())) {
|
|
||||||
String value = String.valueOf(data.fTemperMax);
|
|
||||||
dataService.insertData(item.getTableName(), item.getDevId(), time, config.getMaxtemp(), value);
|
|
||||||
// 更新最新数据缓存
|
|
||||||
StaticVariable.updateLastData(item.getDevId(), config.getMaxtemp(), value, time);
|
|
||||||
}
|
}
|
||||||
if (StringUtils.isNotBlank(config.getMintemp())) {
|
|
||||||
String value = String.valueOf(data.fTemperMin);
|
|
||||||
dataService.insertData(item.getTableName(), item.getDevId(), time, config.getMintemp(), value);
|
|
||||||
// 更新最新数据缓存
|
|
||||||
StaticVariable.updateLastData(item.getDevId(), config.getMintemp(), value, time);
|
|
||||||
}
|
}
|
||||||
if (StringUtils.isNotBlank(config.getAvertemp())) {
|
if (!CollectionUtils.isEmpty(dahuaList)) {
|
||||||
String value = String.valueOf(data.fTemperAver);
|
this.collectAndSaveDahua(dahuaList, config);
|
||||||
dataService.insertData(item.getTableName(), item.getDevId(), time, config.getAvertemp(), value);
|
|
||||||
// 更新最新数据缓存
|
|
||||||
StaticVariable.updateLastData(item.getDevId(), config.getAvertemp(), value, time);
|
|
||||||
}
|
}
|
||||||
|
if (!CollectionUtils.isEmpty(hikList)) {
|
||||||
|
this.collectAndSaveHik(hikList, config);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
LoginModule.logout();
|
private void collectAndSaveDahua(List<NSensor> list, ThermalConfig config) {
|
||||||
} catch (Exception ex) {
|
HashMap<String, List<NSensor>> map = new HashMap<>();
|
||||||
log.error("热成像测温采集异常, " + ex.getMessage(), ex);
|
for (NSensor sensor : list) {
|
||||||
} finally {
|
if (sensor.canTempMeasure()) {
|
||||||
LoginModule.cleanup();
|
String key = sensor.getIp() + sensor.getPort() + sensor.getUsername();
|
||||||
|
List<NSensor> sub = map.get(key);
|
||||||
|
if (sub == null) {
|
||||||
|
sub = new ArrayList<>();
|
||||||
|
map.put(key, sub);
|
||||||
|
}
|
||||||
|
sub.add(sensor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Iterator<String> it = map.keySet().iterator();
|
||||||
|
while (it.hasNext()) {
|
||||||
|
String key = it.next();
|
||||||
|
List<NSensor> sub = map.get(key);
|
||||||
|
dahuaThermalService.collectAndSave(sub, config);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void collectAndSaveHik(List<NSensor> list, ThermalConfig config) {
|
||||||
|
HashMap<String, List<NSensor>> map = new HashMap<>();
|
||||||
|
for (NSensor sensor : list) {
|
||||||
|
if (sensor.canTempMeasure()) {
|
||||||
|
String key = sensor.getIp() + sensor.getPort() + sensor.getUsername();
|
||||||
|
List<NSensor> sub = map.get(key);
|
||||||
|
if (sub == null) {
|
||||||
|
sub = new ArrayList<>();
|
||||||
|
map.put(key, sub);
|
||||||
|
}
|
||||||
|
sub.add(sensor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Iterator<String> it = map.keySet().iterator();
|
||||||
|
while (it.hasNext()) {
|
||||||
|
String key = it.next();
|
||||||
|
List<NSensor> sub = map.get(key);
|
||||||
|
hikThermalService.collectAndSave(sub, config);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue