mirror of
https://gitee.com/pnoker/iot-dc3.git
synced 2026-11-02 19:21:51 +08:00
refactor(manager): update dictionary device API and profile-bind service logic
This commit is contained in:
+2
-3
@@ -68,11 +68,10 @@ public interface DictionaryClient {
|
||||
/**
|
||||
* 查询设备 Dictionary
|
||||
*
|
||||
* @param parent group/driver/profile
|
||||
* @return List<Dictionary>
|
||||
*/
|
||||
@GetMapping("/device/{parent}")
|
||||
R<List<Dictionary>> deviceDictionary(@NotNull @PathVariable("parent") String parent, @RequestHeader(value = Common.Service.DC3_AUTH_TENANT_ID, defaultValue = "-1") Long tenantId);
|
||||
@GetMapping("/device")
|
||||
R<List<Dictionary>> deviceDictionary(@RequestHeader(value = Common.Service.DC3_AUTH_TENANT_ID, defaultValue = "-1") Long tenantId);
|
||||
|
||||
/**
|
||||
* 查询位号 Dictionary
|
||||
|
||||
+1
-1
@@ -59,7 +59,7 @@ public class DictionaryClientHystrix implements FallbackFactory<DictionaryClient
|
||||
}
|
||||
|
||||
@Override
|
||||
public R<List<Dictionary>> deviceDictionary(String parent, Long tenantId) {
|
||||
public R<List<Dictionary>> deviceDictionary(Long tenantId) {
|
||||
return R.fail(message);
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
<parent>
|
||||
<groupId>com.dc3</groupId>
|
||||
<artifactId>dc3-center</artifactId>
|
||||
<version>1.3.1.SR</version>
|
||||
<version>1.3.2.SR</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>dc3-data</artifactId>
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright 2016-2021 Pnoker. All Rights Reserved.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.dc3.center.data.config;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.module.SimpleModule;
|
||||
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.http.converter.HttpMessageConverter;
|
||||
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
|
||||
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author pnoker
|
||||
*/
|
||||
@Slf4j
|
||||
@EnableWebMvc
|
||||
@Configuration
|
||||
public class WebMvcConfig implements WebMvcConfigurer {
|
||||
|
||||
@Override
|
||||
public void configureMessageConverters(List<HttpMessageConverter<?>> list) {
|
||||
MappingJackson2HttpMessageConverter jsonConverter = new MappingJackson2HttpMessageConverter();
|
||||
ObjectMapper objectMapper = jsonConverter.getObjectMapper();
|
||||
SimpleModule simpleModule = new SimpleModule();
|
||||
simpleModule.addSerializer(Long.class, ToStringSerializer.instance);
|
||||
simpleModule.addSerializer(Long.TYPE, ToStringSerializer.instance);
|
||||
objectMapper.registerModule(simpleModule);
|
||||
list.add(jsonConverter);
|
||||
}
|
||||
}
|
||||
+3
-6
@@ -36,10 +36,7 @@ import org.springframework.data.mongodb.core.query.Query;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -67,7 +64,7 @@ public class PointValueServiceImpl implements PointValueService {
|
||||
@Override
|
||||
public void savePointValue(PointValue pointValue) {
|
||||
if (null != pointValue) {
|
||||
pointValue.setCreateTime(System.currentTimeMillis());
|
||||
pointValue.setCreateTime(new Date());
|
||||
threadPoolExecutor.execute(() -> dataCustomService.postHandle(pointValue));
|
||||
threadPoolExecutor.execute(() -> savePointValueToMongo(pointValue));
|
||||
threadPoolExecutor.execute(() -> savePointValueToRedis(pointValue));
|
||||
@@ -79,7 +76,7 @@ public class PointValueServiceImpl implements PointValueService {
|
||||
if (null != pointValues) {
|
||||
if (pointValues.size() > 0) {
|
||||
Future<List<PointValue>> future = threadPoolExecutor.submit(() -> {
|
||||
pointValues.forEach(pointValue -> pointValue.setCreateTime(System.currentTimeMillis()));
|
||||
pointValues.forEach(pointValue -> pointValue.setCreateTime(new Date()));
|
||||
return pointValues;
|
||||
});
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
<parent>
|
||||
<groupId>com.dc3</groupId>
|
||||
<artifactId>dc3-center</artifactId>
|
||||
<version>1.3.1.SR</version>
|
||||
<version>1.3.2.SR</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>dc3-manager</artifactId>
|
||||
|
||||
@@ -89,9 +89,9 @@ public class DictionaryApi implements DictionaryClient {
|
||||
}
|
||||
|
||||
@Override
|
||||
public R<List<Dictionary>> deviceDictionary(String parent, Long tenantId) {
|
||||
public R<List<Dictionary>> deviceDictionary(Long tenantId) {
|
||||
try {
|
||||
List<Dictionary> dictionaryList = dictionaryService.deviceDictionary(parent, tenantId);
|
||||
List<Dictionary> dictionaryList = dictionaryService.deviceDictionary(tenantId);
|
||||
if (null != dictionaryList) {
|
||||
return R.ok(dictionaryList);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright 2016-2021 Pnoker. All Rights Reserved.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.dc3.center.manager.config;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.module.SimpleModule;
|
||||
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.http.converter.HttpMessageConverter;
|
||||
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
|
||||
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author pnoker
|
||||
*/
|
||||
@Slf4j
|
||||
@EnableWebMvc
|
||||
@Configuration
|
||||
public class WebMvcConfig implements WebMvcConfigurer {
|
||||
|
||||
@Override
|
||||
public void configureMessageConverters(List<HttpMessageConverter<?>> list) {
|
||||
MappingJackson2HttpMessageConverter jsonConverter = new MappingJackson2HttpMessageConverter();
|
||||
ObjectMapper objectMapper = jsonConverter.getObjectMapper();
|
||||
SimpleModule simpleModule = new SimpleModule();
|
||||
simpleModule.addSerializer(Long.class, ToStringSerializer.instance);
|
||||
simpleModule.addSerializer(Long.TYPE, ToStringSerializer.instance);
|
||||
objectMapper.registerModule(simpleModule);
|
||||
list.add(jsonConverter);
|
||||
}
|
||||
}
|
||||
+1
-2
@@ -56,10 +56,9 @@ public interface DictionaryService {
|
||||
* 获取设备字典
|
||||
* group/driver/profile
|
||||
*
|
||||
* @param parent
|
||||
* @return
|
||||
*/
|
||||
List<Dictionary> deviceDictionary(String parent, Long tenantId);
|
||||
List<Dictionary> deviceDictionary(Long tenantId);
|
||||
|
||||
/**
|
||||
* 获取位号字典
|
||||
|
||||
+17
-2
@@ -26,13 +26,28 @@ import java.util.Set;
|
||||
*/
|
||||
public interface ProfileBindService extends Service<ProfileBind, ProfileBindDto> {
|
||||
|
||||
/**
|
||||
* 根据 设备Id 删除关联的模版映射
|
||||
*
|
||||
* @param deviceId Device Id
|
||||
*/
|
||||
boolean deleteByDeviceId(Long deviceId);
|
||||
|
||||
/**
|
||||
* 根据 模版ID和设备Id 删除关联的模版映射
|
||||
*
|
||||
* @param profileId Profile Id
|
||||
* @param deviceId Device Id
|
||||
*/
|
||||
boolean deleteByProfileIdAndDeviceId(Long profileId, Long deviceId);
|
||||
|
||||
/**
|
||||
* 根据 模版ID 查询关联的 设备ID 集合
|
||||
*
|
||||
* @param profileId Profile Id
|
||||
* @return Device Id Set
|
||||
*/
|
||||
Set<Long> selectByProfileId(Long profileId);
|
||||
Set<Long> selectDeviceIdByProfileId(Long profileId);
|
||||
|
||||
/**
|
||||
* 根据 设备ID 查询关联的 模版ID 集合
|
||||
@@ -40,6 +55,6 @@ public interface ProfileBindService extends Service<ProfileBind, ProfileBindDto>
|
||||
* @param deviceId Device Id
|
||||
* @return Profile Id Set
|
||||
*/
|
||||
Set<Long> selectByDeviceId(Long deviceId);
|
||||
Set<Long> selectProfileIdByDeviceId(Long deviceId);
|
||||
|
||||
}
|
||||
|
||||
+37
-17
@@ -50,6 +50,8 @@ public class BatchServiceImpl implements BatchService {
|
||||
@Resource
|
||||
private ProfileService profileService;
|
||||
@Resource
|
||||
private ProfileBindService profileBindService;
|
||||
@Resource
|
||||
private GroupService groupService;
|
||||
@Resource
|
||||
private DeviceService deviceService;
|
||||
@@ -127,12 +129,11 @@ public class BatchServiceImpl implements BatchService {
|
||||
Map<Long, Map<String, AttributeInfo>> driverInfoMap = getDriverInfoMap(deviceIds, driverAttributeMap);
|
||||
driverMetadata.setDriverInfoMap(driverInfoMap);
|
||||
|
||||
Map<Long, Device> deviceMap = new ConcurrentHashMap<>(16);
|
||||
devices.forEach(device -> deviceMap.put(device.getId(), device));
|
||||
Map<Long, Device> deviceMap = getDeviceMap(devices);
|
||||
driverMetadata.setDeviceMap(deviceMap);
|
||||
|
||||
Map<Long, Map<Long, Point>> profilePointMap = getProfileMap(devices);
|
||||
driverMetadata.setPointMap(profilePointMap);
|
||||
Map<Long, Map<Long, Point>> profilePointMap = getProfileMap(deviceIds);
|
||||
driverMetadata.setProfileMap(profilePointMap);
|
||||
|
||||
Map<Long, Map<Long, Map<String, AttributeInfo>>> devicePointInfoMap = getPointInfoMap(devices, profilePointMap, pointAttributeMap);
|
||||
driverMetadata.setPointInfoMap(devicePointInfoMap);
|
||||
@@ -609,30 +610,47 @@ public class BatchServiceImpl implements BatchService {
|
||||
Map<Long, Map<String, AttributeInfo>> attributeInfoMap = new ConcurrentHashMap<>(16);
|
||||
device.getProfileIds().forEach(profileId -> profilePointMap.get(profileId).keySet()
|
||||
.forEach(pointId -> {
|
||||
List<PointInfo> pointInfos = pointInfoService.selectByDeviceIdAndPointId(device.getId(), pointId);
|
||||
Map<String, AttributeInfo> infoMap = new ConcurrentHashMap<>(16);
|
||||
pointInfos.forEach(pointInfo -> {
|
||||
PointAttribute attribute = pointAttributeMap.get(pointInfo.getPointAttributeId());
|
||||
infoMap.put(attribute.getName(), new AttributeInfo(pointInfo.getValue(), attribute.getType()));
|
||||
});
|
||||
try {
|
||||
List<PointInfo> pointInfos = pointInfoService.selectByDeviceIdAndPointId(device.getId(), pointId);
|
||||
Map<String, AttributeInfo> infoMap = new ConcurrentHashMap<>(16);
|
||||
pointInfos.forEach(pointInfo -> {
|
||||
PointAttribute attribute = pointAttributeMap.get(pointInfo.getPointAttributeId());
|
||||
infoMap.put(attribute.getName(), new AttributeInfo(pointInfo.getValue(), attribute.getType()));
|
||||
});
|
||||
|
||||
if (infoMap.size() > 0) {
|
||||
attributeInfoMap.put(pointId, infoMap);
|
||||
if (infoMap.size() > 0) {
|
||||
attributeInfoMap.put(pointId, infoMap);
|
||||
}
|
||||
} catch (NotFoundException ignored) {
|
||||
}
|
||||
}));
|
||||
return attributeInfoMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get device map
|
||||
*
|
||||
* @param devices Device Array
|
||||
* @return map(pointId, point)
|
||||
*/
|
||||
public Map<Long, Device> getDeviceMap(List<Device> devices) {
|
||||
Map<Long, Device> deviceMap = new ConcurrentHashMap<>(16);
|
||||
devices.forEach(device -> deviceMap.put(device.getId(), device));
|
||||
return deviceMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get profile map
|
||||
*
|
||||
* @param devices Device Array
|
||||
* @param deviceIds Device Id Set
|
||||
* @return map(profileId ( pointId, point))
|
||||
*/
|
||||
public Map<Long, Map<Long, Point>> getProfileMap(List<Device> devices) {
|
||||
public Map<Long, Map<Long, Point>> getProfileMap(Set<Long> deviceIds) {
|
||||
Map<Long, Map<Long, Point>> pointMap = new ConcurrentHashMap<>(16);
|
||||
devices.forEach(device -> device.getProfileIds().forEach(profileId -> pointMap.put(profileId, getPointMap(profileId))));
|
||||
deviceIds.forEach(deviceId -> {
|
||||
Set<Long> profileIds = profileBindService.selectProfileIdByDeviceId(deviceId);
|
||||
profileIds.forEach(profileId -> pointMap.put(profileId, getPointMap(profileId)));
|
||||
});
|
||||
return pointMap;
|
||||
}
|
||||
|
||||
@@ -644,9 +662,11 @@ public class BatchServiceImpl implements BatchService {
|
||||
*/
|
||||
public Map<Long, Point> getPointMap(Long profileId) {
|
||||
Map<Long, Point> pointMap = new ConcurrentHashMap<>(16);
|
||||
pointService.selectByProfileId(profileId).forEach(point -> pointMap.put(point.getId(), point));
|
||||
try {
|
||||
pointService.selectByProfileId(profileId).forEach(point -> pointMap.put(point.getId(), point));
|
||||
} catch (NotFoundException ignored) {
|
||||
}
|
||||
return pointMap;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
+33
-8
@@ -19,6 +19,7 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.dc3.center.manager.mapper.DeviceMapper;
|
||||
import com.dc3.center.manager.service.DeviceService;
|
||||
import com.dc3.center.manager.service.ProfileBindService;
|
||||
import com.dc3.common.bean.Pages;
|
||||
import com.dc3.common.constant.Common;
|
||||
import com.dc3.common.dto.DeviceDto;
|
||||
@@ -26,6 +27,7 @@ import com.dc3.common.exception.DuplicateException;
|
||||
import com.dc3.common.exception.NotFoundException;
|
||||
import com.dc3.common.exception.ServiceException;
|
||||
import com.dc3.common.model.Device;
|
||||
import com.dc3.common.model.ProfileBind;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
import org.springframework.cache.annotation.CachePut;
|
||||
@@ -34,6 +36,7 @@ import org.springframework.cache.annotation.Caching;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
@@ -49,6 +52,8 @@ public class DeviceServiceImpl implements DeviceService {
|
||||
|
||||
@Resource
|
||||
private DeviceMapper deviceMapper;
|
||||
@Resource
|
||||
private ProfileBindService profileBindService;
|
||||
|
||||
@Override
|
||||
@Caching(
|
||||
@@ -68,7 +73,13 @@ public class DeviceServiceImpl implements DeviceService {
|
||||
throw new DuplicateException("The device already exists");
|
||||
} catch (NotFoundException notFoundException) {
|
||||
if (deviceMapper.insert(device) > 0) {
|
||||
return deviceMapper.selectById(device.getId());
|
||||
device.getProfileIds().forEach(profileId -> {
|
||||
ProfileBind profileBind = new ProfileBind(profileId, device.getId());
|
||||
profileBindService.add(profileBind);
|
||||
});
|
||||
Device select = deviceMapper.selectById(device.getId());
|
||||
select.setProfileIds(device.getProfileIds());
|
||||
return select;
|
||||
}
|
||||
throw new ServiceException("The device add failed");
|
||||
}
|
||||
@@ -86,6 +97,7 @@ public class DeviceServiceImpl implements DeviceService {
|
||||
)
|
||||
public boolean delete(Long id) {
|
||||
selectById(id);
|
||||
profileBindService.deleteByDeviceId(id);
|
||||
return deviceMapper.deleteById(id) > 0;
|
||||
}
|
||||
|
||||
@@ -104,8 +116,17 @@ public class DeviceServiceImpl implements DeviceService {
|
||||
public Device update(Device device) {
|
||||
selectById(device.getId());
|
||||
device.setUpdateTime(null);
|
||||
Set<Long> newProfileIds = device.getProfileIds();
|
||||
Set<Long> oldProfileIds = profileBindService.selectProfileIdByDeviceId(device.getId());
|
||||
Set<Long> add = new HashSet<>(newProfileIds);
|
||||
add.removeAll(oldProfileIds);
|
||||
Set<Long> delete = new HashSet<>(oldProfileIds);
|
||||
delete.removeAll(newProfileIds);
|
||||
add.forEach(id -> profileBindService.add(new ProfileBind(id, device.getId())));
|
||||
delete.forEach(id -> profileBindService.deleteByProfileIdAndDeviceId(id, device.getId()));
|
||||
if (deviceMapper.updateById(device) > 0) {
|
||||
Device select = deviceMapper.selectById(device.getId());
|
||||
select.setProfileIds(newProfileIds);
|
||||
device.setName(select.getName()).setGroupId(select.getGroupId());
|
||||
return select;
|
||||
}
|
||||
@@ -119,7 +140,7 @@ public class DeviceServiceImpl implements DeviceService {
|
||||
if (null == device) {
|
||||
throw new NotFoundException("The device does not exist");
|
||||
}
|
||||
return device;
|
||||
return device.setProfileIds(profileBindService.selectProfileIdByDeviceId(id));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -132,7 +153,7 @@ public class DeviceServiceImpl implements DeviceService {
|
||||
if (null == device) {
|
||||
throw new NotFoundException("The device does not exist");
|
||||
}
|
||||
return device;
|
||||
return device.setProfileIds(profileBindService.selectProfileIdByDeviceId(device.getId()));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -144,13 +165,16 @@ public class DeviceServiceImpl implements DeviceService {
|
||||
if (null == devices || devices.size() < 1) {
|
||||
throw new NotFoundException("The devices does not exist");
|
||||
}
|
||||
devices.forEach(device -> device.setProfileIds(profileBindService.selectProfileIdByDeviceId(device.getId())));
|
||||
return devices;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Cacheable(value = Common.Cache.DEVICE + Common.Cache.LIST, keyGenerator = "commonKeyGenerator", unless = "#result==null")
|
||||
public List<Device> selectByIds(Set<Long> ids) {
|
||||
return deviceMapper.selectBatchIds(ids);
|
||||
List<Device> devices = deviceMapper.selectBatchIds(ids);
|
||||
devices.forEach(device -> device.setProfileIds(profileBindService.selectProfileIdByDeviceId(device.getId())));
|
||||
return devices;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -159,7 +183,9 @@ public class DeviceServiceImpl implements DeviceService {
|
||||
if (!Optional.ofNullable(deviceDto.getPage()).isPresent()) {
|
||||
deviceDto.setPage(new Pages());
|
||||
}
|
||||
return deviceMapper.selectPage(deviceDto.getPage().convert(), fuzzyQuery(deviceDto));
|
||||
Page<Device> page = deviceMapper.selectPage(deviceDto.getPage().convert(), fuzzyQuery(deviceDto));
|
||||
page.getRecords().forEach(device -> device.setProfileIds(profileBindService.selectProfileIdByDeviceId(device.getId())));
|
||||
return page;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -172,10 +198,9 @@ public class DeviceServiceImpl implements DeviceService {
|
||||
if (null != deviceDto.getDriverId()) {
|
||||
queryWrapper.eq(Device::getDriverId, deviceDto.getDriverId());
|
||||
}
|
||||
if (null != deviceDto.getGroupId()) {
|
||||
queryWrapper.eq(Device::getGroupId, deviceDto.getGroupId());
|
||||
if (null != deviceDto.getTenantId()) {
|
||||
queryWrapper.eq(Device::getTenantId, deviceDto.getTenantId());
|
||||
}
|
||||
queryWrapper.eq(Device::getTenantId, deviceDto.getTenantId());
|
||||
}
|
||||
return queryWrapper;
|
||||
}
|
||||
|
||||
+14
-22
@@ -107,30 +107,22 @@ public class DictionaryServiceImpl implements DictionaryService {
|
||||
}
|
||||
|
||||
@Override
|
||||
@Cacheable(value = Common.Cache.DEVICE + Common.Cache.DIC, key = "'dic.'+#parent+'.'+#tenantId", unless = "#result==null")
|
||||
public List<Dictionary> deviceDictionary(String parent, Long tenantId) {
|
||||
List<Dictionary> dictionaries = new ArrayList<>(16);
|
||||
switch (parent) {
|
||||
case "driver":
|
||||
List<Dictionary> driverDictionaryList = driverDictionary(tenantId);
|
||||
driverDictionaryList.forEach(driverDictionary -> {
|
||||
LambdaQueryWrapper<Device> queryWrapper = Wrappers.<Device>query().lambda();
|
||||
queryWrapper.eq(Device::getDriverId, driverDictionary.getValue());
|
||||
queryWrapper.eq(Device::getTenantId, tenantId);
|
||||
List<Device> deviceList = deviceMapper.selectList(queryWrapper);
|
||||
List<Dictionary> deviceDictionaryList = new ArrayList<>(16);
|
||||
deviceList.forEach(device -> deviceDictionaryList.add(new Dictionary().setLabel(device.getName()).setValue(device.getId())));
|
||||
@Cacheable(value = Common.Cache.DEVICE + Common.Cache.DIC, key = "'dic.'+#tenantId", unless = "#result==null")
|
||||
public List<Dictionary> deviceDictionary(Long tenantId) {
|
||||
List<Dictionary> dictionaries = driverDictionary(tenantId);
|
||||
dictionaries.forEach(driverDictionary -> {
|
||||
LambdaQueryWrapper<Device> queryWrapper = Wrappers.<Device>query().lambda();
|
||||
queryWrapper.eq(Device::getDriverId, driverDictionary.getValue());
|
||||
queryWrapper.eq(Device::getTenantId, tenantId);
|
||||
List<Device> deviceList = deviceMapper.selectList(queryWrapper);
|
||||
List<Dictionary> deviceDictionaryList = new ArrayList<>(16);
|
||||
deviceList.forEach(device -> deviceDictionaryList.add(new Dictionary().setLabel(device.getName()).setValue(device.getId())));
|
||||
|
||||
driverDictionary.setDisabled(true);
|
||||
driverDictionary.setValue(RandomUtil.randomLong());
|
||||
driverDictionary.setChildren(deviceDictionaryList);
|
||||
});
|
||||
driverDictionary.setDisabled(true);
|
||||
driverDictionary.setValue(RandomUtil.randomLong());
|
||||
driverDictionary.setChildren(deviceDictionaryList);
|
||||
});
|
||||
|
||||
dictionaries = driverDictionaryList;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return dictionaries;
|
||||
}
|
||||
|
||||
|
||||
+4
-2
@@ -177,7 +177,7 @@ public class DriverServiceImpl implements DriverService {
|
||||
@Override
|
||||
@Cacheable(value = Common.Cache.DRIVER + Common.Cache.PROFILE_ID, key = "#profileId", unless = "#result==null")
|
||||
public List<Driver> selectByProfileId(Long profileId) {
|
||||
Set<Long> deviceIds = profileBindService.selectByProfileId(profileId);
|
||||
Set<Long> deviceIds = profileBindService.selectDeviceIdByProfileId(profileId);
|
||||
if (null != deviceIds && deviceIds.size() > 0) {
|
||||
List<Device> devices = deviceService.selectByIds(deviceIds);
|
||||
Set<Long> driverIds = devices.stream().map(Device::getDriverId).collect(Collectors.toSet());
|
||||
@@ -211,7 +211,9 @@ public class DriverServiceImpl implements DriverService {
|
||||
if (null != driverDto.getPort()) {
|
||||
queryWrapper.eq(Driver::getPort, driverDto.getPort());
|
||||
}
|
||||
queryWrapper.eq(Driver::getTenantId, driverDto.getTenantId());
|
||||
if (null != driverDto.getTenantId()) {
|
||||
queryWrapper.eq(Driver::getTenantId, driverDto.getTenantId());
|
||||
}
|
||||
}
|
||||
return queryWrapper;
|
||||
}
|
||||
|
||||
+3
-1
@@ -147,7 +147,9 @@ public class GroupServiceImpl implements GroupService {
|
||||
if (StrUtil.isNotBlank(groupDto.getName())) {
|
||||
queryWrapper.like(Group::getName, groupDto.getName());
|
||||
}
|
||||
queryWrapper.eq(Group::getTenantId, groupDto.getTenantId());
|
||||
if (null != groupDto.getTenantId()) {
|
||||
queryWrapper.eq(Group::getTenantId, groupDto.getTenantId());
|
||||
}
|
||||
}
|
||||
return queryWrapper;
|
||||
}
|
||||
|
||||
+3
-1
@@ -158,7 +158,9 @@ public class LabelServiceImpl implements LabelService {
|
||||
if (StrUtil.isNotBlank(labelDto.getColor())) {
|
||||
queryWrapper.eq(Label::getColor, labelDto.getColor());
|
||||
}
|
||||
queryWrapper.eq(Label::getTenantId, labelDto.getTenantId());
|
||||
if (null != labelDto.getTenantId()) {
|
||||
queryWrapper.eq(Label::getTenantId, labelDto.getTenantId());
|
||||
}
|
||||
}
|
||||
return queryWrapper;
|
||||
}
|
||||
|
||||
+4
-2
@@ -148,7 +148,7 @@ public class PointServiceImpl implements PointService {
|
||||
|
||||
@Override
|
||||
public List<Point> selectByDeviceId(Long deviceId) {
|
||||
Set<Long> profileIds = profileBindService.selectByDeviceId(deviceId);
|
||||
Set<Long> profileIds = profileBindService.selectProfileIdByDeviceId(deviceId);
|
||||
return selectByProfileIds(profileIds);
|
||||
}
|
||||
|
||||
@@ -210,7 +210,9 @@ public class PointServiceImpl implements PointService {
|
||||
if (null != pointDto.getProfileId()) {
|
||||
queryWrapper.eq(Point::getProfileId, pointDto.getProfileId());
|
||||
}
|
||||
queryWrapper.eq(Point::getTenantId, pointDto.getTenantId());
|
||||
if (null != pointDto.getTenantId()) {
|
||||
queryWrapper.eq(Point::getTenantId, pointDto.getTenantId());
|
||||
}
|
||||
}
|
||||
return queryWrapper;
|
||||
}
|
||||
|
||||
+35
-2
@@ -81,6 +81,39 @@ public class ProfileBindServiceImpl implements ProfileBindService {
|
||||
return profileBindMapper.deleteById(id) > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Caching(
|
||||
evict = {
|
||||
@CacheEvict(value = Common.Cache.PROFILE_BIND + Common.Cache.ID, allEntries = true, condition = "#result==true"),
|
||||
@CacheEvict(value = Common.Cache.PROFILE_BIND + Common.Cache.PROFILE_ID, allEntries = true, condition = "#result==true"),
|
||||
@CacheEvict(value = Common.Cache.PROFILE_BIND + Common.Cache.DEVICE_ID, allEntries = true, condition = "#result==true"),
|
||||
@CacheEvict(value = Common.Cache.PROFILE_BIND + Common.Cache.DIC, allEntries = true, condition = "#result==true"),
|
||||
@CacheEvict(value = Common.Cache.PROFILE_BIND + Common.Cache.LIST, allEntries = true, condition = "#result==true")
|
||||
}
|
||||
)
|
||||
public boolean deleteByDeviceId(Long deviceId) {
|
||||
ProfileBindDto profileBindDto = new ProfileBindDto();
|
||||
profileBindDto.setDeviceId(deviceId);
|
||||
return profileBindMapper.delete(fuzzyQuery(profileBindDto)) > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Caching(
|
||||
evict = {
|
||||
@CacheEvict(value = Common.Cache.PROFILE_BIND + Common.Cache.ID, allEntries = true, condition = "#result==true"),
|
||||
@CacheEvict(value = Common.Cache.PROFILE_BIND + Common.Cache.PROFILE_ID, allEntries = true, condition = "#result==true"),
|
||||
@CacheEvict(value = Common.Cache.PROFILE_BIND + Common.Cache.DEVICE_ID, allEntries = true, condition = "#result==true"),
|
||||
@CacheEvict(value = Common.Cache.PROFILE_BIND + Common.Cache.DIC, allEntries = true, condition = "#result==true"),
|
||||
@CacheEvict(value = Common.Cache.PROFILE_BIND + Common.Cache.LIST, allEntries = true, condition = "#result==true")
|
||||
}
|
||||
)
|
||||
public boolean deleteByProfileIdAndDeviceId(Long profileId, Long deviceId) {
|
||||
ProfileBindDto profileBindDto = new ProfileBindDto();
|
||||
profileBindDto.setProfileId(profileId);
|
||||
profileBindDto.setDeviceId(deviceId);
|
||||
return profileBindMapper.delete(fuzzyQuery(profileBindDto)) > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Caching(
|
||||
put = {@CachePut(value = Common.Cache.PROFILE_BIND + Common.Cache.ID, key = "#profileBind.id", condition = "#result!=null")},
|
||||
@@ -112,7 +145,7 @@ public class ProfileBindServiceImpl implements ProfileBindService {
|
||||
|
||||
@Override
|
||||
@Cacheable(value = Common.Cache.PROFILE_BIND + Common.Cache.PROFILE_ID, key = "#profileId", unless = "#result==null")
|
||||
public Set<Long> selectByProfileId(Long profileId) {
|
||||
public Set<Long> selectDeviceIdByProfileId(Long profileId) {
|
||||
ProfileBindDto profileBindDto = new ProfileBindDto();
|
||||
profileBindDto.setProfileId(profileId);
|
||||
List<ProfileBind> profileBinds = profileBindMapper.selectList(fuzzyQuery(profileBindDto));
|
||||
@@ -121,7 +154,7 @@ public class ProfileBindServiceImpl implements ProfileBindService {
|
||||
|
||||
@Override
|
||||
@Cacheable(value = Common.Cache.PROFILE_BIND + Common.Cache.DEVICE_ID, key = "#deviceId", unless = "#result==null")
|
||||
public Set<Long> selectByDeviceId(Long deviceId) {
|
||||
public Set<Long> selectProfileIdByDeviceId(Long deviceId) {
|
||||
ProfileBindDto profileBindDto = new ProfileBindDto();
|
||||
profileBindDto.setDeviceId(deviceId);
|
||||
List<ProfileBind> profileBinds = profileBindMapper.selectList(fuzzyQuery(profileBindDto));
|
||||
|
||||
+3
-1
@@ -166,7 +166,9 @@ public class ProfileServiceImpl implements ProfileService {
|
||||
if (null != profileDto.getShare()) {
|
||||
queryWrapper.eq(Profile::getShare, profileDto.getShare());
|
||||
}
|
||||
queryWrapper.eq(Profile::getTenantId, profileDto.getTenantId());
|
||||
if (null != profileDto.getTenantId()) {
|
||||
queryWrapper.eq(Profile::getTenantId, profileDto.getTenantId());
|
||||
}
|
||||
}
|
||||
return queryWrapper;
|
||||
}
|
||||
|
||||
+1
-1
@@ -17,7 +17,7 @@
|
||||
<parent>
|
||||
<groupId>com.dc3</groupId>
|
||||
<artifactId>iot-dc3</artifactId>
|
||||
<version>1.3.1.SR</version>
|
||||
<version>1.3.2.SR</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>dc3-center</artifactId>
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
<parent>
|
||||
<groupId>com.dc3</groupId>
|
||||
<artifactId>dc3-common</artifactId>
|
||||
<version>1.3.1.SR</version>
|
||||
<version>1.3.2.SR</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>dc3-config</artifactId>
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
| ( <_> ) | / /_/ \ \___ / \
|
||||
|__|\____/|__| \____ |\___ >______ /
|
||||
\/ \/ \/
|
||||
https://doc.dc3.site
|
||||
开发文档:https://doc.dc3.site
|
||||
https://gitee.com/pnoker/iot-dc3
|
||||
https://github.com/pnoker/iot-dc3
|
||||
${AnsiColor.BRIGHT_CYAN}DC3 IOT Platform V1.3.1.SR ${AnsiColor.BRIGHT_YELLOW}Pnoker${AnsiColor.BRIGHT_CYAN} Authors
|
||||
${AnsiColor.BRIGHT_CYAN}DC3 IOT Platform V1.3.2.SR ${AnsiColor.BRIGHT_YELLOW}Pnoker${AnsiColor.BRIGHT_CYAN} Authors
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
<parent>
|
||||
<groupId>com.dc3</groupId>
|
||||
<artifactId>dc3-common</artifactId>
|
||||
<version>1.3.1.SR</version>
|
||||
<version>1.3.2.SR</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>dc3-core</artifactId>
|
||||
|
||||
+1
-1
@@ -20,7 +20,7 @@
|
||||
<parent>
|
||||
<groupId>com.dc3</groupId>
|
||||
<artifactId>iot-dc3</artifactId>
|
||||
<version>1.3.1.SR</version>
|
||||
<version>1.3.2.SR</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>dc3-common</artifactId>
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
<parent>
|
||||
<groupId>com.dc3</groupId>
|
||||
<artifactId>dc3-driver</artifactId>
|
||||
<version>1.3.1.SR</version>
|
||||
<version>1.3.2.SR</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>dc3-driver-listening-virtual</artifactId>
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
<parent>
|
||||
<groupId>com.dc3</groupId>
|
||||
<artifactId>dc3-driver</artifactId>
|
||||
<version>1.3.1.SR</version>
|
||||
<version>1.3.2.SR</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>dc3-driver-modbus-tcp</artifactId>
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
<parent>
|
||||
<groupId>com.dc3</groupId>
|
||||
<artifactId>dc3-driver</artifactId>
|
||||
<version>1.3.1.SR</version>
|
||||
<version>1.3.2.SR</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>dc3-driver-mqtt</artifactId>
|
||||
|
||||
@@ -13,8 +13,6 @@
|
||||
|
||||
package com.dc3.driver.bean;
|
||||
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
@@ -28,11 +26,7 @@ import lombok.experimental.Accessors;
|
||||
@AllArgsConstructor
|
||||
@Accessors(chain = true)
|
||||
public class DevicePayLoad {
|
||||
@JsonSerialize(using = ToStringSerializer.class)
|
||||
private Long deviceId;
|
||||
|
||||
@JsonSerialize(using = ToStringSerializer.class)
|
||||
private Long pointId;
|
||||
|
||||
private String value;
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
<parent>
|
||||
<groupId>com.dc3</groupId>
|
||||
<artifactId>dc3-driver</artifactId>
|
||||
<version>1.3.1.SR</version>
|
||||
<version>1.3.2.SR</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>dc3-driver-opc-da</artifactId>
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
<parent>
|
||||
<groupId>com.dc3</groupId>
|
||||
<artifactId>dc3-driver</artifactId>
|
||||
<version>1.3.1.SR</version>
|
||||
<version>1.3.2.SR</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>dc3-driver-opc-ua</artifactId>
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
<parent>
|
||||
<groupId>com.dc3</groupId>
|
||||
<artifactId>dc3-driver</artifactId>
|
||||
<version>1.3.1.SR</version>
|
||||
<version>1.3.2.SR</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>dc3-driver-plcs7</artifactId>
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
<parent>
|
||||
<groupId>com.dc3</groupId>
|
||||
<artifactId>dc3-driver</artifactId>
|
||||
<version>1.3.1.SR</version>
|
||||
<version>1.3.2.SR</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>dc3-driver-virtual</artifactId>
|
||||
|
||||
+1
-1
@@ -17,7 +17,7 @@
|
||||
<parent>
|
||||
<groupId>com.dc3</groupId>
|
||||
<artifactId>iot-dc3</artifactId>
|
||||
<version>1.3.1.SR</version>
|
||||
<version>1.3.2.SR</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>dc3-driver</artifactId>
|
||||
|
||||
+1
-1
@@ -20,7 +20,7 @@
|
||||
<parent>
|
||||
<artifactId>iot-dc3</artifactId>
|
||||
<groupId>com.dc3</groupId>
|
||||
<version>1.3.1.SR</version>
|
||||
<version>1.3.2.SR</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>dc3-gateway</artifactId>
|
||||
|
||||
Reference in New Issue
Block a user