sdf
This commit is contained in:
@@ -4,6 +4,13 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.sunyard.chsm.mapper.SpDeviceMapper;
|
||||
import com.sunyard.chsm.model.entity.Device;
|
||||
import com.sunyard.chsm.sdf.adapter.SdfApiAdapter;
|
||||
import com.sunyard.chsm.sdf.adapter.SdfApiAdapterFactory;
|
||||
import com.sunyard.chsm.sdf.context.DeviceContext;
|
||||
import com.sunyard.chsm.sdf.model.DeviceInfo;
|
||||
import com.sunyard.chsm.sdf.model.EccPubKey;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.bouncycastle.util.encoders.Hex;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
|
||||
@@ -12,12 +19,14 @@ import org.springframework.util.CollectionUtils;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.time.Duration;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author liulu
|
||||
* @since 2024/11/4
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
public class DeviceTask implements InitializingBean {
|
||||
|
||||
@@ -34,7 +43,7 @@ public class DeviceTask implements InitializingBean {
|
||||
|
||||
for (int i = 1; i < 500; i++) {
|
||||
Page<Device> devicePage = spDeviceMapper.selectPage(
|
||||
new Page<>(i, 100L),
|
||||
new Page<>(i, 20L),
|
||||
new LambdaQueryWrapper<Device>().orderByAsc(Device::getId)
|
||||
);
|
||||
List<Device> records = devicePage.getRecords();
|
||||
@@ -43,15 +52,38 @@ public class DeviceTask implements InitializingBean {
|
||||
}
|
||||
|
||||
for (Device record : records) {
|
||||
DeviceContext context = new DeviceContext();
|
||||
context.setServiceIp(record.getServiceIp());
|
||||
context.setServicePort(record.getServicePort());
|
||||
context.setManufacturer(record.getManufacturer());
|
||||
context.setManufacturerModel(record.getManufacturerModel());
|
||||
boolean connected = false;
|
||||
try {
|
||||
SdfApiAdapter sdfApiAdapter = SdfApiAdapterFactory.newInstance(context);
|
||||
String dh = sdfApiAdapter.openDevice();
|
||||
String sh = sdfApiAdapter.openSession(dh);
|
||||
DeviceInfo info = sdfApiAdapter.getDeviceInfo(sh);
|
||||
log.info("get DeviceInfo: {}", info);
|
||||
EccPubKey eccPubKey = sdfApiAdapter.exportEncPublicKeyECC(sh, 2);
|
||||
log.info("exportEncPublicKeyECC: {}", Hex.toHexString(eccPubKey.getPubKeyBytes()));
|
||||
sdfApiAdapter.closeSession(sh);
|
||||
sdfApiAdapter.closeDevice(dh);
|
||||
connected = true;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
} catch (Exception ex) {
|
||||
log.warn("设备 {}:{} 连接异常", record.getServiceIp(), record.getServicePort(), ex);
|
||||
}
|
||||
Device up = new Device();
|
||||
up.setId(record.getId());
|
||||
up.setConnected(connected);
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
if (connected) {
|
||||
up.setLastConnectedTime(now);
|
||||
}
|
||||
up.setLastCheckTime(now);
|
||||
spDeviceMapper.updateById(up);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user