diff --git a/dc3-api/dc3-api-manager/src/main/java/com/dc3/api/center/manager/feign/DictionaryClient.java b/dc3-api/dc3-api-manager/src/main/java/com/dc3/api/center/manager/feign/DictionaryClient.java index 465ab07c6..0c496a991 100644 --- a/dc3-api/dc3-api-manager/src/main/java/com/dc3/api/center/manager/feign/DictionaryClient.java +++ b/dc3-api/dc3-api-manager/src/main/java/com/dc3/api/center/manager/feign/DictionaryClient.java @@ -68,11 +68,10 @@ public interface DictionaryClient { /** * 查询设备 Dictionary * - * @param parent group/driver/profile * @return List */ - @GetMapping("/device/{parent}") - R> deviceDictionary(@NotNull @PathVariable("parent") String parent, @RequestHeader(value = Common.Service.DC3_AUTH_TENANT_ID, defaultValue = "-1") Long tenantId); + @GetMapping("/device") + R> deviceDictionary(@RequestHeader(value = Common.Service.DC3_AUTH_TENANT_ID, defaultValue = "-1") Long tenantId); /** * 查询位号 Dictionary diff --git a/dc3-api/dc3-api-manager/src/main/java/com/dc3/api/center/manager/hystrix/DictionaryClientHystrix.java b/dc3-api/dc3-api-manager/src/main/java/com/dc3/api/center/manager/hystrix/DictionaryClientHystrix.java index 9d2abed6a..bd6343011 100644 --- a/dc3-api/dc3-api-manager/src/main/java/com/dc3/api/center/manager/hystrix/DictionaryClientHystrix.java +++ b/dc3-api/dc3-api-manager/src/main/java/com/dc3/api/center/manager/hystrix/DictionaryClientHystrix.java @@ -59,7 +59,7 @@ public class DictionaryClientHystrix implements FallbackFactory> deviceDictionary(String parent, Long tenantId) { + public R> deviceDictionary(Long tenantId) { return R.fail(message); } diff --git a/dc3-center/dc3-data/pom.xml b/dc3-center/dc3-data/pom.xml index f2ec163a2..1a5d64b8a 100644 --- a/dc3-center/dc3-data/pom.xml +++ b/dc3-center/dc3-data/pom.xml @@ -17,7 +17,7 @@ com.dc3 dc3-center - 1.3.1.SR + 1.3.2.SR dc3-data diff --git a/dc3-center/dc3-data/src/main/java/com/dc3/center/data/config/WebMvcConfig.java b/dc3-center/dc3-data/src/main/java/com/dc3/center/data/config/WebMvcConfig.java new file mode 100644 index 000000000..53a369ec9 --- /dev/null +++ b/dc3-center/dc3-data/src/main/java/com/dc3/center/data/config/WebMvcConfig.java @@ -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> 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); + } +} \ No newline at end of file diff --git a/dc3-center/dc3-data/src/main/java/com/dc3/center/data/service/impl/PointValueServiceImpl.java b/dc3-center/dc3-data/src/main/java/com/dc3/center/data/service/impl/PointValueServiceImpl.java index 6d26bc5a3..a686bfbef 100644 --- a/dc3-center/dc3-data/src/main/java/com/dc3/center/data/service/impl/PointValueServiceImpl.java +++ b/dc3-center/dc3-data/src/main/java/com/dc3/center/data/service/impl/PointValueServiceImpl.java @@ -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> future = threadPoolExecutor.submit(() -> { - pointValues.forEach(pointValue -> pointValue.setCreateTime(System.currentTimeMillis())); + pointValues.forEach(pointValue -> pointValue.setCreateTime(new Date())); return pointValues; }); diff --git a/dc3-center/dc3-manager/pom.xml b/dc3-center/dc3-manager/pom.xml index 9a6bc5862..5e387c2b7 100644 --- a/dc3-center/dc3-manager/pom.xml +++ b/dc3-center/dc3-manager/pom.xml @@ -17,7 +17,7 @@ com.dc3 dc3-center - 1.3.1.SR + 1.3.2.SR dc3-manager diff --git a/dc3-center/dc3-manager/src/main/java/com/dc3/center/manager/api/DictionaryApi.java b/dc3-center/dc3-manager/src/main/java/com/dc3/center/manager/api/DictionaryApi.java index 87c3384c5..d55a80f97 100644 --- a/dc3-center/dc3-manager/src/main/java/com/dc3/center/manager/api/DictionaryApi.java +++ b/dc3-center/dc3-manager/src/main/java/com/dc3/center/manager/api/DictionaryApi.java @@ -89,9 +89,9 @@ public class DictionaryApi implements DictionaryClient { } @Override - public R> deviceDictionary(String parent, Long tenantId) { + public R> deviceDictionary(Long tenantId) { try { - List dictionaryList = dictionaryService.deviceDictionary(parent, tenantId); + List dictionaryList = dictionaryService.deviceDictionary(tenantId); if (null != dictionaryList) { return R.ok(dictionaryList); } diff --git a/dc3-center/dc3-manager/src/main/java/com/dc3/center/manager/config/WebMvcConfig.java b/dc3-center/dc3-manager/src/main/java/com/dc3/center/manager/config/WebMvcConfig.java new file mode 100644 index 000000000..5829c2e79 --- /dev/null +++ b/dc3-center/dc3-manager/src/main/java/com/dc3/center/manager/config/WebMvcConfig.java @@ -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> 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); + } +} \ No newline at end of file diff --git a/dc3-center/dc3-manager/src/main/java/com/dc3/center/manager/service/DictionaryService.java b/dc3-center/dc3-manager/src/main/java/com/dc3/center/manager/service/DictionaryService.java index 645ac3fb2..27d54f4ca 100644 --- a/dc3-center/dc3-manager/src/main/java/com/dc3/center/manager/service/DictionaryService.java +++ b/dc3-center/dc3-manager/src/main/java/com/dc3/center/manager/service/DictionaryService.java @@ -56,10 +56,9 @@ public interface DictionaryService { * 获取设备字典 * group/driver/profile * - * @param parent * @return */ - List deviceDictionary(String parent, Long tenantId); + List deviceDictionary(Long tenantId); /** * 获取位号字典 diff --git a/dc3-center/dc3-manager/src/main/java/com/dc3/center/manager/service/ProfileBindService.java b/dc3-center/dc3-manager/src/main/java/com/dc3/center/manager/service/ProfileBindService.java index 3551010b5..fcad458d8 100644 --- a/dc3-center/dc3-manager/src/main/java/com/dc3/center/manager/service/ProfileBindService.java +++ b/dc3-center/dc3-manager/src/main/java/com/dc3/center/manager/service/ProfileBindService.java @@ -26,13 +26,28 @@ import java.util.Set; */ public interface ProfileBindService extends Service { + /** + * 根据 设备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 selectByProfileId(Long profileId); + Set selectDeviceIdByProfileId(Long profileId); /** * 根据 设备ID 查询关联的 模版ID 集合 @@ -40,6 +55,6 @@ public interface ProfileBindService extends Service * @param deviceId Device Id * @return Profile Id Set */ - Set selectByDeviceId(Long deviceId); + Set selectProfileIdByDeviceId(Long deviceId); } diff --git a/dc3-center/dc3-manager/src/main/java/com/dc3/center/manager/service/impl/BatchServiceImpl.java b/dc3-center/dc3-manager/src/main/java/com/dc3/center/manager/service/impl/BatchServiceImpl.java index 930839dc1..37c1fdc4c 100644 --- a/dc3-center/dc3-manager/src/main/java/com/dc3/center/manager/service/impl/BatchServiceImpl.java +++ b/dc3-center/dc3-manager/src/main/java/com/dc3/center/manager/service/impl/BatchServiceImpl.java @@ -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> driverInfoMap = getDriverInfoMap(deviceIds, driverAttributeMap); driverMetadata.setDriverInfoMap(driverInfoMap); - Map deviceMap = new ConcurrentHashMap<>(16); - devices.forEach(device -> deviceMap.put(device.getId(), device)); + Map deviceMap = getDeviceMap(devices); driverMetadata.setDeviceMap(deviceMap); - Map> profilePointMap = getProfileMap(devices); - driverMetadata.setPointMap(profilePointMap); + Map> profilePointMap = getProfileMap(deviceIds); + driverMetadata.setProfileMap(profilePointMap); Map>> devicePointInfoMap = getPointInfoMap(devices, profilePointMap, pointAttributeMap); driverMetadata.setPointInfoMap(devicePointInfoMap); @@ -609,30 +610,47 @@ public class BatchServiceImpl implements BatchService { Map> attributeInfoMap = new ConcurrentHashMap<>(16); device.getProfileIds().forEach(profileId -> profilePointMap.get(profileId).keySet() .forEach(pointId -> { - List pointInfos = pointInfoService.selectByDeviceIdAndPointId(device.getId(), pointId); - Map 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 pointInfos = pointInfoService.selectByDeviceIdAndPointId(device.getId(), pointId); + Map 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 getDeviceMap(List devices) { + Map 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> getProfileMap(List devices) { + public Map> getProfileMap(Set deviceIds) { Map> pointMap = new ConcurrentHashMap<>(16); - devices.forEach(device -> device.getProfileIds().forEach(profileId -> pointMap.put(profileId, getPointMap(profileId)))); + deviceIds.forEach(deviceId -> { + Set 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 getPointMap(Long profileId) { Map 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; } - } diff --git a/dc3-center/dc3-manager/src/main/java/com/dc3/center/manager/service/impl/DeviceServiceImpl.java b/dc3-center/dc3-manager/src/main/java/com/dc3/center/manager/service/impl/DeviceServiceImpl.java index 2a3acbdbc..fc4e60ad9 100644 --- a/dc3-center/dc3-manager/src/main/java/com/dc3/center/manager/service/impl/DeviceServiceImpl.java +++ b/dc3-center/dc3-manager/src/main/java/com/dc3/center/manager/service/impl/DeviceServiceImpl.java @@ -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 newProfileIds = device.getProfileIds(); + Set oldProfileIds = profileBindService.selectProfileIdByDeviceId(device.getId()); + Set add = new HashSet<>(newProfileIds); + add.removeAll(oldProfileIds); + Set 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 selectByIds(Set ids) { - return deviceMapper.selectBatchIds(ids); + List 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 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; } diff --git a/dc3-center/dc3-manager/src/main/java/com/dc3/center/manager/service/impl/DictionaryServiceImpl.java b/dc3-center/dc3-manager/src/main/java/com/dc3/center/manager/service/impl/DictionaryServiceImpl.java index 30be0d844..cc49974ba 100644 --- a/dc3-center/dc3-manager/src/main/java/com/dc3/center/manager/service/impl/DictionaryServiceImpl.java +++ b/dc3-center/dc3-manager/src/main/java/com/dc3/center/manager/service/impl/DictionaryServiceImpl.java @@ -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 deviceDictionary(String parent, Long tenantId) { - List dictionaries = new ArrayList<>(16); - switch (parent) { - case "driver": - List driverDictionaryList = driverDictionary(tenantId); - driverDictionaryList.forEach(driverDictionary -> { - LambdaQueryWrapper queryWrapper = Wrappers.query().lambda(); - queryWrapper.eq(Device::getDriverId, driverDictionary.getValue()); - queryWrapper.eq(Device::getTenantId, tenantId); - List deviceList = deviceMapper.selectList(queryWrapper); - List 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 deviceDictionary(Long tenantId) { + List dictionaries = driverDictionary(tenantId); + dictionaries.forEach(driverDictionary -> { + LambdaQueryWrapper queryWrapper = Wrappers.query().lambda(); + queryWrapper.eq(Device::getDriverId, driverDictionary.getValue()); + queryWrapper.eq(Device::getTenantId, tenantId); + List deviceList = deviceMapper.selectList(queryWrapper); + List 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; } diff --git a/dc3-center/dc3-manager/src/main/java/com/dc3/center/manager/service/impl/DriverServiceImpl.java b/dc3-center/dc3-manager/src/main/java/com/dc3/center/manager/service/impl/DriverServiceImpl.java index dc987f41d..806796ec9 100644 --- a/dc3-center/dc3-manager/src/main/java/com/dc3/center/manager/service/impl/DriverServiceImpl.java +++ b/dc3-center/dc3-manager/src/main/java/com/dc3/center/manager/service/impl/DriverServiceImpl.java @@ -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 selectByProfileId(Long profileId) { - Set deviceIds = profileBindService.selectByProfileId(profileId); + Set deviceIds = profileBindService.selectDeviceIdByProfileId(profileId); if (null != deviceIds && deviceIds.size() > 0) { List devices = deviceService.selectByIds(deviceIds); Set 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; } diff --git a/dc3-center/dc3-manager/src/main/java/com/dc3/center/manager/service/impl/GroupServiceImpl.java b/dc3-center/dc3-manager/src/main/java/com/dc3/center/manager/service/impl/GroupServiceImpl.java index 85e545dbf..732dc4c3d 100644 --- a/dc3-center/dc3-manager/src/main/java/com/dc3/center/manager/service/impl/GroupServiceImpl.java +++ b/dc3-center/dc3-manager/src/main/java/com/dc3/center/manager/service/impl/GroupServiceImpl.java @@ -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; } diff --git a/dc3-center/dc3-manager/src/main/java/com/dc3/center/manager/service/impl/LabelServiceImpl.java b/dc3-center/dc3-manager/src/main/java/com/dc3/center/manager/service/impl/LabelServiceImpl.java index 28df180b1..990b45270 100644 --- a/dc3-center/dc3-manager/src/main/java/com/dc3/center/manager/service/impl/LabelServiceImpl.java +++ b/dc3-center/dc3-manager/src/main/java/com/dc3/center/manager/service/impl/LabelServiceImpl.java @@ -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; } diff --git a/dc3-center/dc3-manager/src/main/java/com/dc3/center/manager/service/impl/PointServiceImpl.java b/dc3-center/dc3-manager/src/main/java/com/dc3/center/manager/service/impl/PointServiceImpl.java index 5825efec2..bfb36b23f 100644 --- a/dc3-center/dc3-manager/src/main/java/com/dc3/center/manager/service/impl/PointServiceImpl.java +++ b/dc3-center/dc3-manager/src/main/java/com/dc3/center/manager/service/impl/PointServiceImpl.java @@ -148,7 +148,7 @@ public class PointServiceImpl implements PointService { @Override public List selectByDeviceId(Long deviceId) { - Set profileIds = profileBindService.selectByDeviceId(deviceId); + Set 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; } diff --git a/dc3-center/dc3-manager/src/main/java/com/dc3/center/manager/service/impl/ProfileBindServiceImpl.java b/dc3-center/dc3-manager/src/main/java/com/dc3/center/manager/service/impl/ProfileBindServiceImpl.java index ba070bb7d..3c973914b 100644 --- a/dc3-center/dc3-manager/src/main/java/com/dc3/center/manager/service/impl/ProfileBindServiceImpl.java +++ b/dc3-center/dc3-manager/src/main/java/com/dc3/center/manager/service/impl/ProfileBindServiceImpl.java @@ -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 selectByProfileId(Long profileId) { + public Set selectDeviceIdByProfileId(Long profileId) { ProfileBindDto profileBindDto = new ProfileBindDto(); profileBindDto.setProfileId(profileId); List 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 selectByDeviceId(Long deviceId) { + public Set selectProfileIdByDeviceId(Long deviceId) { ProfileBindDto profileBindDto = new ProfileBindDto(); profileBindDto.setDeviceId(deviceId); List profileBinds = profileBindMapper.selectList(fuzzyQuery(profileBindDto)); diff --git a/dc3-center/dc3-manager/src/main/java/com/dc3/center/manager/service/impl/ProfileServiceImpl.java b/dc3-center/dc3-manager/src/main/java/com/dc3/center/manager/service/impl/ProfileServiceImpl.java index 87f814896..fd01eccf9 100644 --- a/dc3-center/dc3-manager/src/main/java/com/dc3/center/manager/service/impl/ProfileServiceImpl.java +++ b/dc3-center/dc3-manager/src/main/java/com/dc3/center/manager/service/impl/ProfileServiceImpl.java @@ -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; } diff --git a/dc3-center/pom.xml b/dc3-center/pom.xml index ca4f785e8..68883f3a3 100644 --- a/dc3-center/pom.xml +++ b/dc3-center/pom.xml @@ -17,7 +17,7 @@ com.dc3 iot-dc3 - 1.3.1.SR + 1.3.2.SR dc3-center diff --git a/dc3-common/dc3-config/pom.xml b/dc3-common/dc3-config/pom.xml index c9d416dae..b2d7c44a9 100644 --- a/dc3-common/dc3-config/pom.xml +++ b/dc3-common/dc3-config/pom.xml @@ -20,7 +20,7 @@ com.dc3 dc3-common - 1.3.1.SR + 1.3.2.SR dc3-config diff --git a/dc3-common/dc3-config/src/main/resources/banner.txt b/dc3-common/dc3-config/src/main/resources/banner.txt index 6366fa74a..75de91e11 100644 --- a/dc3-common/dc3-config/src/main/resources/banner.txt +++ b/dc3-common/dc3-config/src/main/resources/banner.txt @@ -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 diff --git a/dc3-common/dc3-core/pom.xml b/dc3-common/dc3-core/pom.xml index a69bcd3f3..007fc3dfe 100644 --- a/dc3-common/dc3-core/pom.xml +++ b/dc3-common/dc3-core/pom.xml @@ -20,7 +20,7 @@ com.dc3 dc3-common - 1.3.1.SR + 1.3.2.SR dc3-core diff --git a/dc3-common/pom.xml b/dc3-common/pom.xml index d9ba9992a..70efd8844 100644 --- a/dc3-common/pom.xml +++ b/dc3-common/pom.xml @@ -20,7 +20,7 @@ com.dc3 iot-dc3 - 1.3.1.SR + 1.3.2.SR dc3-common diff --git a/dc3-driver/dc3-driver-listening-virtual/pom.xml b/dc3-driver/dc3-driver-listening-virtual/pom.xml index 1ccd2888f..5aa9e1c5c 100644 --- a/dc3-driver/dc3-driver-listening-virtual/pom.xml +++ b/dc3-driver/dc3-driver-listening-virtual/pom.xml @@ -17,7 +17,7 @@ com.dc3 dc3-driver - 1.3.1.SR + 1.3.2.SR dc3-driver-listening-virtual diff --git a/dc3-driver/dc3-driver-modbus-tcp/pom.xml b/dc3-driver/dc3-driver-modbus-tcp/pom.xml index 4cce63890..6f2422045 100644 --- a/dc3-driver/dc3-driver-modbus-tcp/pom.xml +++ b/dc3-driver/dc3-driver-modbus-tcp/pom.xml @@ -17,7 +17,7 @@ com.dc3 dc3-driver - 1.3.1.SR + 1.3.2.SR dc3-driver-modbus-tcp diff --git a/dc3-driver/dc3-driver-mqtt/pom.xml b/dc3-driver/dc3-driver-mqtt/pom.xml index 83c33b32a..f8864c803 100644 --- a/dc3-driver/dc3-driver-mqtt/pom.xml +++ b/dc3-driver/dc3-driver-mqtt/pom.xml @@ -17,7 +17,7 @@ com.dc3 dc3-driver - 1.3.1.SR + 1.3.2.SR dc3-driver-mqtt diff --git a/dc3-driver/dc3-driver-mqtt/src/main/java/com/dc3/driver/bean/DevicePayLoad.java b/dc3-driver/dc3-driver-mqtt/src/main/java/com/dc3/driver/bean/DevicePayLoad.java index bc171b352..2b8aa9984 100644 --- a/dc3-driver/dc3-driver-mqtt/src/main/java/com/dc3/driver/bean/DevicePayLoad.java +++ b/dc3-driver/dc3-driver-mqtt/src/main/java/com/dc3/driver/bean/DevicePayLoad.java @@ -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; } diff --git a/dc3-driver/dc3-driver-opc-da/pom.xml b/dc3-driver/dc3-driver-opc-da/pom.xml index 3803555b5..29ded0168 100644 --- a/dc3-driver/dc3-driver-opc-da/pom.xml +++ b/dc3-driver/dc3-driver-opc-da/pom.xml @@ -17,7 +17,7 @@ com.dc3 dc3-driver - 1.3.1.SR + 1.3.2.SR dc3-driver-opc-da diff --git a/dc3-driver/dc3-driver-opc-ua/pom.xml b/dc3-driver/dc3-driver-opc-ua/pom.xml index 9ae53f2e0..f028cf24f 100644 --- a/dc3-driver/dc3-driver-opc-ua/pom.xml +++ b/dc3-driver/dc3-driver-opc-ua/pom.xml @@ -17,7 +17,7 @@ com.dc3 dc3-driver - 1.3.1.SR + 1.3.2.SR dc3-driver-opc-ua diff --git a/dc3-driver/dc3-driver-plcs7/pom.xml b/dc3-driver/dc3-driver-plcs7/pom.xml index 32df0e2b2..0427ccb11 100644 --- a/dc3-driver/dc3-driver-plcs7/pom.xml +++ b/dc3-driver/dc3-driver-plcs7/pom.xml @@ -17,7 +17,7 @@ com.dc3 dc3-driver - 1.3.1.SR + 1.3.2.SR dc3-driver-plcs7 diff --git a/dc3-driver/dc3-driver-virtual/pom.xml b/dc3-driver/dc3-driver-virtual/pom.xml index 1a904afd3..27a316514 100644 --- a/dc3-driver/dc3-driver-virtual/pom.xml +++ b/dc3-driver/dc3-driver-virtual/pom.xml @@ -17,7 +17,7 @@ com.dc3 dc3-driver - 1.3.1.SR + 1.3.2.SR dc3-driver-virtual diff --git a/dc3-driver/pom.xml b/dc3-driver/pom.xml index 330c10845..f2d548fa9 100644 --- a/dc3-driver/pom.xml +++ b/dc3-driver/pom.xml @@ -17,7 +17,7 @@ com.dc3 iot-dc3 - 1.3.1.SR + 1.3.2.SR dc3-driver diff --git a/dc3-gateway/pom.xml b/dc3-gateway/pom.xml index 9ded4b374..6ffa771da 100644 --- a/dc3-gateway/pom.xml +++ b/dc3-gateway/pom.xml @@ -20,7 +20,7 @@ iot-dc3 com.dc3 - 1.3.1.SR + 1.3.2.SR dc3-gateway