sdf 接口

This commit is contained in:
liulu
2024-11-08 09:00:03 +08:00
parent b13a9f54ac
commit db484a070d
14 changed files with 541 additions and 1 deletions
@@ -123,6 +123,7 @@ public class DeviceServiceImpl implements DeviceService {
Assert.isTrue(manufacturerModel.getManufacturer() == manufacturer, "设备厂商和型号不匹配");
checkName(save.getName());
checkIpPort(save.getServiceIp(), save.getServicePort());
Device device = new Device();
BeanUtils.copyProperties(save, device);
@@ -136,6 +137,14 @@ public class DeviceServiceImpl implements DeviceService {
return device.getId();
}
private void checkIpPort(String serviceIp, Integer servicePort) {
LambdaQueryWrapper<Device> wrapper = new LambdaQueryWrapper<Device>()
.eq(Device::getServiceIp, serviceIp)
.eq(Device::getServicePort, servicePort);
Device exist = spDeviceMapper.selectOne(wrapper);
Assert.isNull(exist, "设备IP和端口已存在");
}
@Override
public void update(DeviceDTO.DeviceSave update) {
Assert.notNull(update.getId(), "id不能为空");
@@ -145,13 +154,16 @@ public class DeviceServiceImpl implements DeviceService {
if (!Objects.equals(exist.getName(), update.getName())) {
checkName(update.getName());
}
if (!Objects.equals(exist.getServiceIp(), update.getServiceIp())
|| !Objects.equals(exist.getServicePort(), update.getServicePort())) {
checkIpPort(update.getServiceIp(), update.getServicePort());
}
Device up = new Device();
BeanUtils.copyProperties(update, up);
up.setUpdateTime(LocalDateTime.now());
spDeviceMapper.updateById(up);
}
@Override
@@ -0,0 +1,61 @@
package com.sunyard.chsm.task;
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 org.springframework.beans.factory.InitializingBean;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import javax.annotation.Resource;
import java.time.Duration;
import java.util.List;
/**
* @author liulu
* @since 2024/11/4
*/
@Component
public class DeviceTask implements InitializingBean {
@Resource
private SpDeviceMapper spDeviceMapper;
@Resource
private ThreadPoolTaskScheduler threadPoolTaskScheduler;
@Resource
private ThreadPoolTaskExecutor threadPoolTaskExecutor;
private void checkDeviceStatus() {
for (int i = 1; i < 500; i++) {
Page<Device> devicePage = spDeviceMapper.selectPage(
new Page<>(i, 100L),
new LambdaQueryWrapper<Device>().orderByAsc(Device::getId)
);
List<Device> records = devicePage.getRecords();
if (CollectionUtils.isEmpty(records)) {
break;
}
for (Device record : records) {
}
}
}
@Override
public void afterPropertiesSet() throws Exception {
threadPoolTaskScheduler.scheduleWithFixedDelay(this::checkDeviceStatus, Duration.ofMinutes(5L));
}
}