/*
* 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.service.impl;
import cn.hutool.core.util.StrUtil;
import com.dc3.center.manager.service.*;
import com.dc3.common.bean.batch.*;
import com.dc3.common.bean.driver.AttributeInfo;
import com.dc3.common.bean.driver.DriverMetadata;
import com.dc3.common.constant.Common;
import com.dc3.common.exception.NotFoundException;
import com.dc3.common.exception.ServiceException;
import com.dc3.common.model.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;
/**
* <p>BatchService Impl
*
* @author pnoker
*/
@Slf4j
@Service
public class BatchServiceImpl implements BatchService {
@Resource
private DriverService driverService;
@Resource
private DriverAttributeService driverAttributeService;
@Resource
private DriverInfoService driverInfoService;
@Resource
private ProfileService profileService;
@Resource
private ProfileBindService profileBindService;
@Resource
private GroupService groupService;
@Resource
private DeviceService deviceService;
@Resource
private PointService pointService;
@Resource
private PointAttributeService pointAttributeService;
@Resource
private PointInfoService pointInfoService;
@Resource
private NotifyService notifyService;
@Override
@Transactional
public void batchImport(List<BatchDriver> batchDrivers) {
batchDrivers.forEach(batchDriver -> {
if (StrUtil.isBlank(batchDriver.getServiceName())) {
throw new ServiceException("Driver service name is blank");
}
Driver driver = driverService.selectByServiceName(batchDriver.getServiceName());
if (null == driver) {
throw new ServiceException("Driver service does not exist: " + batchDriver.getServiceName());
}
batchDriver.getProfiles().forEach(batchProfile -> {
// import Profile
Profile profile = importProfile(driver, batchProfile);
// import Driver Info Array
// todo bug
importDriverInfo(driver, null, batchProfile.getDriverConfig());
// import Point Array
importPoint(profile, batchProfile.getPoints());
// import Device Array
importDevice(driver, profile, batchProfile.getGroups(), batchProfile.getPointConfig());
});
});
}
@Override
public BatchDriver batchExport(String serviceName) {
Driver driver = driverService.selectByServiceName(serviceName);
BatchDriver batchDriver = new BatchDriver();
batchDriver.setServiceName(serviceName);
// export profile
List<BatchProfile> profiles = exportProfile(driver.getId());
if (profiles.size() > 0) {
batchDriver.setProfiles(profiles);
}
return batchDriver;
}
@Override
public DriverMetadata batchDriverMetadata(String serviceName) {
DriverMetadata driverMetadata = new DriverMetadata();
Driver driver = driverService.selectByServiceName(serviceName);
try {
Map<Long, DriverAttribute> driverAttributeMap = getDriverAttributeMap(driver.getId());
driverMetadata.setDriverAttributeMap(driverAttributeMap);
Map<Long, PointAttribute> pointAttributeMap = getPointAttributeMap(driver.getId());
driverMetadata.setPointAttributeMap(pointAttributeMap);
List<Device> devices = deviceService.selectByDriverId(driver.getId());
Set<Long> deviceIds = devices.stream().map(Description::getId).collect(Collectors.toSet());
Map<Long, Map<String, AttributeInfo>> driverInfoMap = getDriverInfoMap(deviceIds, driverAttributeMap);
driverMetadata.setDriverInfoMap(driverInfoMap);
Map<Long, Device> deviceMap = getDeviceMap(devices);
driverMetadata.setDeviceMap(deviceMap);
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);
return driverMetadata;
} catch (NotFoundException ignored) {
}
return driverMetadata;
}
/**
* 导入 Profile
*
* @param driver Driver
* @param batchProfile BatchProfile
*/
private Profile importProfile(Driver driver, BatchProfile batchProfile) {
if (StrUtil.isBlank(batchProfile.getName())) {
throw new ServiceException("Profile name is blank");
}
Profile profile;
try {
profile = profileService.selectByName(batchProfile.getName(), driver.getTenantId());
profile.setShare(batchProfile.getShare());
profile.setDescription("批量导入:更新操作");
profile = profileService.update(profile);
notifyService.notifyDriverProfile(Common.Driver.Profile.UPDATE, profile);
} catch (NotFoundException notFoundException) {
profile = new Profile(batchProfile.getName(), batchProfile.getShare(), driver.getId(), driver.getTenantId());
profile.setDescription("批量导入:新增操作");
profile = profileService.add(profile);
notifyService.notifyDriverProfile(Common.Driver.Profile.ADD, profile);
}
return profile;
}
/**
* 导入 Driver Info 列表
*
* @param driver Driver
* @param device Device
* @param driverConfig Driver Config
*/
private void importDriverInfo(Driver driver, Device device, final Map<String, String> driverConfig) {
List<String> driverInfoList = new ArrayList<>(16);
if (null == driverConfig) {
return;
}
driverConfig.forEach((name, value) -> {
DriverAttribute driverAttribute = driverAttributeService.selectByNameAndDriverId(name, driver.getId());
if (driverInfoList.contains(name)) {
throw new ServiceException("Repeatedly driver info: " + name);
}
driverInfoList.add(name);
try {
DriverInfo driverInfo = driverInfoService.selectByAttributeIdAndDeviceId(driverAttribute.getId(), device.getId());
driverInfo.setDescription("批量导入:更新操作");
driverInfo = driverInfoService.update(driverInfo.setValue(value));
notifyService.notifyDriverDriverInfo(Common.Driver.DriverInfo.UPDATE, driverInfo);
} catch (NotFoundException notFoundException) {
DriverInfo driverInfo = new DriverInfo(driverAttribute.getId(), value, device.getId());
driverInfo.setDescription("批量导入:新增操作");
driverInfo = driverInfoService.add(driverInfo);
notifyService.notifyDriverDriverInfo(Common.Driver.DriverInfo.ADD, driverInfo);
没有合适的资源?快使用搜索试试~ 我知道了~
基于Spring Cloud分布式物联网(IOT)平台源码.zip
共828个文件
java:422个
png:126个
xml:36个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 125 浏览量
2023-08-29
11:18:18
上传
评论
收藏 23.1MB ZIP 举报
温馨提示
基于Spring Cloud分布式物联网(IOT)平台源码.zip
资源推荐
资源详情
资源评论
收起资源包目录
基于Spring Cloud分布式物联网(IOT)平台源码.zip (828个子文件)
CNAME 12B
redis.conf 61KB
emqx.conf 58KB
emqx_exproto.conf 10KB
emqx_lwm2m.conf 6KB
emqx_bridge_mqtt.conf 5KB
emqx_auth_http.conf 5KB
emqx_auth_mongo.conf 5KB
emqx_dashboard.conf 5KB
emqx_stomp.conf 4KB
emqx_coap.conf 4KB
emqx_auth_mysql.conf 3KB
emqx_management.conf 3KB
emqx_web_hook.conf 3KB
emqx_auth_pgsql.conf 3KB
emqx_auth_redis.conf 3KB
emqx_rule_engine.conf 2KB
emqx_sn.conf 2KB
emqx_auth_ldap.conf 2KB
emqx_retainer.conf 2KB
emqx_auth_jwt.conf 1KB
emqx_telemetry.conf 1KB
emqx_auth_clientid.conf 1KB
emqx_extension_hook.conf 1KB
emqx_auth_username.conf 1KB
emqx_auth_mnesia.conf 1KB
emqx_prometheus.conf 1KB
emqx_reloader.conf 998B
rabbitmq.conf 830B
emqx_lua_hook.conf 773B
emqx_recon.conf 771B
emqx_psk_file.conf 662B
emqx_sasl.conf 612B
bootstrap.min.css 152KB
font-awesome.css 37KB
templatemo-art-factory.css 27KB
flex-slider.css 7KB
owl-carousel.css 5KB
dc3-group.db 156KB
dc3-listening-virtual 2KB
dc3-modbus 2KB
dc3-mqtt 2KB
dc3-opcda 2KB
dc3-opcua 2KB
dc3-plcs7 2KB
dc3-virtual 2KB
Dockerfile 2KB
Dockerfile 2KB
Dockerfile 2KB
Dockerfile 2KB
Dockerfile 2KB
Dockerfile 2KB
Dockerfile 2KB
Dockerfile 2KB
Dockerfile 2KB
Dockerfile 2KB
Dockerfile 2KB
Dockerfile 1KB
Dockerfile 1KB
Dockerfile 1KB
Dockerfile 999B
Dockerfile 947B
Dockerfile 899B
Dockerfile 880B
Dockerfile 857B
Dockerfile 840B
.dockerignore 110B
fontawesome-webfont.eot 59KB
flexslider-icon.eot 2KB
slick.eot 2KB
spring.factories 319B
spring.factories 114B
spring.factories 108B
status.ftlh 4KB
lastn.ftlh 3KB
navbar.ftlh 2KB
header.ftlh 909B
import-dc3.gif 593KB
.gitignore 68B
index.html 6KB
index.html 1KB
dc3-gateway.http 7KB
dc3-manager-point.http 5KB
dc3-manager-driver.http 3KB
dc3-auth-user.http 2KB
dc3-auth-blackIp.http 2KB
dc3-manager-device.http 2KB
dc3-manager-driver-attrubute.http 2KB
dc3-transfer-rtmp.http 2KB
dc3-manager-driver-info.http 2KB
dc3-manager-profile.http 2KB
dc3-auth-token.http 2KB
dc3-manager-group.http 2KB
dc3-data.http 2KB
dc3-driver-opcda.http 2KB
dc3-manager-dictionary.http 2KB
dc3-driver-modbus-tcp.http 1KB
dc3-driver-opcua.http 1KB
dc3-manager-batch.http 1003B
dc3-driver-mqtt.http 837B
共 828 条
- 1
- 2
- 3
- 4
- 5
- 6
- 9
资源评论
栾还是恋
- 粉丝: 29
- 资源: 4993
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功