This commit is contained in:
zhou-hao 2020-05-13 13:51:04 +08:00
parent 1fb802195a
commit a19b668e8f
3 changed files with 48 additions and 4 deletions

View File

@ -72,6 +72,9 @@ public class DeviceDetail {
//设备配置信息
private Map<String, Object> configuration = new HashMap<>();
//设备单独的配置信息
private boolean aloneConfiguration;
//标签
private List<DeviceTagEntity> tags = new ArrayList<>();
@ -151,6 +154,7 @@ public class DeviceDetail {
if (!CollectionUtils.isEmpty(device.getConfiguration())) {
setConfiguration(device.getConfiguration());
setAloneConfiguration(true);
}
if (StringUtils.hasText(device.getDeriveMetadata())) {
setMetadata(device.getDeriveMetadata());

View File

@ -7,6 +7,7 @@ import com.alibaba.fastjson.JSON;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.MapUtils;
import org.hswebframework.ezorm.core.dsl.Query;
import org.hswebframework.ezorm.core.param.QueryParam;
import org.hswebframework.ezorm.core.param.TermType;
@ -64,10 +65,7 @@ import java.io.OutputStream;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.time.Duration;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
@ -101,6 +99,41 @@ public class LocalDeviceInstanceService extends GenericReactiveCrudService<Devic
.as(super::save);
}
/**
* 重置设备配置
*
* @param deviceId 设备ID
* @return 重置后的配置
* @since 1.2
*/
public Mono<Map<String, Object>> resetConfiguration(String deviceId) {
return findById(deviceId)
.flatMap(device ->
Mono.defer(() -> {
if (!MapUtils.isEmpty(device.getConfiguration())) {
//重置注册中心里的配置
return registry.getDevice(deviceId)
.flatMap(opts -> opts.removeConfigs(device.getConfiguration().keySet()))
.then();
}
return Mono.empty();
}).then(
//更新数据库
createUpdate()
.set(DeviceInstanceEntity::getConfiguration, new HashMap<>())
.where(DeviceInstanceEntity::getId, deviceId)
.execute()
).then(
//获取产品信息的配置
deviceProductService
.findById(device.getProductId())
.flatMap(product -> Mono.justOrEmpty(product.getConfiguration()))
))
.defaultIfEmpty(Collections.emptyMap())
;
}
/**
* 发布设备到设备注册中心
*

View File

@ -99,6 +99,13 @@ public class DeviceInstanceController implements
return service.getDeviceDetail(id);
}
//重置配置信息
@PutMapping("/{deviceId:.+}/configuration/_reset")
@SaveAction
public Mono<Map<String,Object>> resetConfiguration(@PathVariable String deviceId){
return service.resetConfiguration(deviceId);
}
//获取设备运行状态
@GetMapping("/{id:.+}/state")
@QueryAction