心跳入库 支持批量入库
This commit is contained in:
@@ -426,4 +426,36 @@ public interface DeviceMapper {
|
||||
"<foreach collection='offlineDevices' item='item' open='(' separator=',' close=')' > #{item.id}</foreach>" +
|
||||
" </script>"})
|
||||
void offlineByList(List<Device> offlineDevices);
|
||||
|
||||
|
||||
@Update({"<script>" +
|
||||
"<foreach collection='devices' item='item' separator=';'>" +
|
||||
" UPDATE" +
|
||||
" wvp_device" +
|
||||
" SET update_time=#{item.updateTime}" +
|
||||
", name=#{item.name}" +
|
||||
", manufacturer=#{item.manufacturer}" +
|
||||
", model=#{item.model}" +
|
||||
", firmware=#{item.firmware}" +
|
||||
", transport=#{item.transport}" +
|
||||
", ip=#{item.ip}" +
|
||||
", local_ip=#{item.localIp}" +
|
||||
", port=#{item.port}" +
|
||||
", host_address=#{item.hostAddress}" +
|
||||
", on_line=#{item.onLine}" +
|
||||
", register_time=#{item.registerTime}" +
|
||||
", keepalive_time=#{item.keepaliveTime}" +
|
||||
", heart_beat_interval=#{item.heartBeatInterval}" +
|
||||
", position_capability=#{item.positionCapability}" +
|
||||
", heart_beat_count=#{item.heartBeatCount}" +
|
||||
", subscribe_cycle_for_catalog=#{item.subscribeCycleForCatalog}" +
|
||||
", subscribe_cycle_for_mobile_position=#{item.subscribeCycleForMobilePosition}" +
|
||||
", mobile_position_submission_interval=#{item.mobilePositionSubmissionInterval}" +
|
||||
", subscribe_cycle_for_alarm=#{item.subscribeCycleForAlarm}" +
|
||||
", expires=#{item.expires}" +
|
||||
", server_id=#{item.serverId}" +
|
||||
" WHERE device_id=#{item.deviceId}"+
|
||||
"</foreach>" +
|
||||
"</script>"})
|
||||
void batchUpdate(List<Device> devices);
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import com.genersoft.iot.vmp.service.bean.ErrorCallback;
|
||||
import com.genersoft.iot.vmp.vmanager.bean.ResourceBaseInfo;
|
||||
import com.genersoft.iot.vmp.vmanager.bean.WVPResult;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -117,6 +118,9 @@ public interface IDeviceService {
|
||||
*/
|
||||
void updateDevice(Device device);
|
||||
|
||||
@Transactional
|
||||
void updateDeviceList(List<Device> deviceList);
|
||||
|
||||
/**
|
||||
* 检查设备编号是否已经存在
|
||||
* @param deviceId 设备编号
|
||||
|
||||
@@ -729,8 +729,6 @@ public class DeviceServiceImpl implements IDeviceService, CommandLineRunner {
|
||||
@Override
|
||||
public void updateDevice(Device device) {
|
||||
|
||||
String now = DateUtil.getNow();
|
||||
device.setUpdateTime(now);
|
||||
device.setCharset(device.getCharset() == null ? "" : device.getCharset().toUpperCase());
|
||||
device.setUpdateTime(DateUtil.getNow());
|
||||
if (deviceMapper.update(device) > 0) {
|
||||
@@ -738,6 +736,40 @@ public class DeviceServiceImpl implements IDeviceService, CommandLineRunner {
|
||||
}
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@Override
|
||||
public void updateDeviceList(List<Device> deviceList) {
|
||||
if (deviceList.isEmpty()){
|
||||
log.info("[批量更新设备] 列表为空,更细失败");
|
||||
return;
|
||||
}
|
||||
if (deviceList.size() == 1) {
|
||||
updateDevice(deviceList.get(0));
|
||||
}else {
|
||||
for (Device device : deviceList) {
|
||||
device.setCharset(device.getCharset() == null ? "" : device.getCharset().toUpperCase());
|
||||
device.setUpdateTime(DateUtil.getNow());
|
||||
}
|
||||
int limitCount = 300;
|
||||
if (!deviceList.isEmpty()) {
|
||||
if (deviceList.size() > limitCount) {
|
||||
for (int i = 0; i < deviceList.size(); i += limitCount) {
|
||||
int toIndex = i + limitCount;
|
||||
if (i + limitCount > deviceList.size()) {
|
||||
toIndex = deviceList.size();
|
||||
}
|
||||
deviceMapper.batchUpdate(deviceList.subList(i, toIndex));
|
||||
}
|
||||
}else {
|
||||
deviceMapper.batchUpdate(deviceList);
|
||||
}
|
||||
for (Device device : deviceList) {
|
||||
redisCatchStorage.updateDevice(device);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isExist(String deviceId) {
|
||||
return getDeviceByDeviceIdFromDb(deviceId) != null;
|
||||
|
||||
@@ -87,6 +87,7 @@ public class KeepaliveNotifyMessageHandler extends SIPRequestProcessorParent imp
|
||||
if (handlerCatchDataList.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
List<Device> deviceListForUpdate = new ArrayList<>();
|
||||
for (SipMsgInfo sipMsgInfo : handlerCatchDataList) {
|
||||
if (sipMsgInfo == null) {
|
||||
continue;
|
||||
@@ -113,7 +114,7 @@ public class KeepaliveNotifyMessageHandler extends SIPRequestProcessorParent imp
|
||||
device.setKeepaliveTime(DateUtil.getNow());
|
||||
|
||||
if (device.isOnLine()) {
|
||||
deviceService.updateDevice(device);
|
||||
deviceListForUpdate.add(device);
|
||||
long expiresTime = Math.min(device.getExpires(), device.getHeartBeatInterval() * device.getHeartBeatCount()) * 1000L;
|
||||
if (statusTaskRunner.containsKey(device.getDeviceId())) {
|
||||
statusTaskRunner.updateDelay(device.getDeviceId(), expiresTime + System.currentTimeMillis());
|
||||
@@ -125,6 +126,9 @@ public class KeepaliveNotifyMessageHandler extends SIPRequestProcessorParent imp
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!deviceListForUpdate.isEmpty()) {
|
||||
deviceService.updateDeviceList(deviceListForUpdate);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user