/*
* Copyright 2016-present the original author or authors.
*
* 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
*
* https://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 io.github.pnoker.center.manager.service.impl;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.text.CharSequenceUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.github.pnoker.center.manager.entity.query.DevicePageQuery;
import io.github.pnoker.center.manager.mapper.DeviceMapper;
import io.github.pnoker.center.manager.service.*;
import io.github.pnoker.common.constant.driver.StorageConstant;
import io.github.pnoker.common.entity.base.Base;
import io.github.pnoker.common.entity.common.Pages;
import io.github.pnoker.common.enums.MetadataCommandTypeEnum;
import io.github.pnoker.common.exception.*;
import io.github.pnoker.common.model.*;
import io.github.pnoker.common.utils.JsonUtil;
import io.github.pnoker.common.utils.PoiUtil;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
/**
* DeviceService Impl
*
* @author pnoker
* @since 2022.1.0
*/
@Slf4j
@Service
public class DeviceServiceImpl implements DeviceService {
@Resource
private DeviceMapper deviceMapper;
@Resource
private DriverAttributeService driverAttributeService;
@Resource
private DriverAttributeConfigService driverAttributeConfigService;
@Resource
private PointAttributeService pointAttributeService;
@Resource
private PointAttributeConfigService pointAttributeConfigService;
@Resource
private ProfileService profileService;
@Resource
private PointService pointService;
@Resource
private ProfileBindService profileBindService;
@Resource
private NotifyService notifyService;
@Resource
private MongoTemplate mongoTemplate;
/**
* {@inheritDoc}
*/
@Override
public void add(Device entityDO) {
if (deviceMapper.insert(entityDO) < 1) {
throw new AddException("The device {} add failed", entityDO.getDeviceName());
}
addProfileBind(entityDO.getId(), entityDO.getProfileIds());
// 通知驱动新增
Device device = deviceMapper.selectById(entityDO.getId());
List<Profile> profiles = profileService.selectByDeviceId(entityDO.getId());
// ?/pnoker 同步给驱动的设备需要profile id set吗
device.setProfileIds(profiles.stream().map(Profile::getId).collect(Collectors.toSet()));
notifyService.notifyDriverDevice(MetadataCommandTypeEnum.ADD, device);
}
/**
* {@inheritDoc}
*/
@Override
@Transactional
public void delete(String id) {
Device device = selectById(id);
if (ObjectUtil.isNull(device)) {
throw new NotFoundException("The device does not exist");
}
if (!profileBindService.deleteByDeviceId(id)) {
throw new DeleteException("The profile bind delete failed");
}
if (deviceMapper.deleteById(id) < 1) {
throw new DeleteException("The device delete failed");
}
// 通知驱动删除设备
notifyService.notifyDriverDevice(MetadataCommandTypeEnum.DELETE, device);
}
/**
* {@inheritDoc}
*/
@Override
public void update(Device entityDO) {
selectById(entityDO.getId());
Set<String> newProfileIds = ObjectUtil.isNotNull(entityDO.getProfileIds()) ? entityDO.getProfileIds() : new HashSet<>();
Set<String> oldProfileIds = profileBindService.selectProfileIdsByDeviceId(entityDO.getId());
// 新增的模板
Set<String> add = new HashSet<>(newProfileIds);
add.removeAll(oldProfileIds);
// 删除的模板
Set<String> delete = new HashSet<>(oldProfileIds);
delete.removeAll(newProfileIds);
addProfileBind(entityDO.getId(), add);
delete.forEach(profileId -> profileBindService.deleteByDeviceIdAndProfileId(entityDO.getId(), profileId));
entityDO.setOperateTime(null);
if (deviceMapper.updateById(entityDO) < 1) {
throw new UpdateException("The device update failed");
}
Device select = deviceMapper.selectById(entityDO.getId());
select.setProfileIds(newProfileIds);
entityDO.setDeviceName(select.getDeviceName());
// 通知驱动更新设备
notifyService.notifyDriverDevice(MetadataCommandTypeEnum.UPDATE, select);
}
/**
* {@inheritDoc}
*/
@Override
public Device selectById(String id) {
Device device = deviceMapper.selectById(id);
if (ObjectUtil.isNull(device)) {
throw new NotFoundException();
}
device.setProfileIds(profileBindService.selectProfileIdsByDeviceId(id));
return device;
}
/**
* {@inheritDoc}
*/
@Override
public Device selectByName(String name, String tenantId) {
LambdaQueryWrapper<Device> queryWrapper = Wrappers.<Device>query().lambda();
queryWrapper.eq(Device::getDeviceName, name);
queryWrapper.eq(Device::getTenantId, tenantId);
queryWrapper.last("limit 1");
Device device = deviceMapper.selectOne(queryWrapper);
if (ObjectUtil.isNull(device)) {
throw new NotFoundException();
}
device.setProfileIds(profileBindService.selectProfileIdsByDeviceId(device.getId()));
return device;
}
/**
* {@inheritDoc}
*/
@Override
public List<Device> selectByDriverId(String driverId) {
DevicePageQuery devicePageQuery = new DevicePageQuery();
devicePageQuery.setDriverId(driverId);
List<Device> devices = deviceMapper.selectList(fuzzyQuery(devicePageQuery));
if (ObjectUtil.isNull(devices) || devices.isEmpty()) {
throw new NotFoundException();
}
devices.forEach(device -> device.setProfileIds(profileBindService.selectProfileIdsByDeviceId(device.getId())));
return devices;
}
/**
* {@inheritDoc}
*/
@Override
public List<Device> selectByProfileId(String profileId) {
return selectByIds(profileBindService.selectDeviceIdsByProfileId(profileId));
}
/**
* {@inheritDoc}
*/
@Override
public List<Device> selectByIds(Set<String> ids) {
List<Device> devices = deviceMapper.selectBatchIds(ids);
if (CollUtil.isEmpty(devices)) {
throw new NotFoundException();
}
devices.forEach(device ->
没有合适的资源?快使用搜索试试~ 我知道了~
IoTDC3是一个基于Spring Cloud的 100% 完全开源的、分布式的物联网(IoT)平台,是一整套物联系统解决方案
共682个文件
java:510个
yml:67个
xml:24个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 188 浏览量
2023-12-27
09:36:45
上传
评论
收藏 14.02MB ZIP 举报
温馨提示
IoT DC3 是一个基于 Spring Cloud 的 100% 完全开源的、分布式的物联网(IoT)平台,用于快速开发物联网项目和管理物联设备,是一整套物联系统解决方案。
资源推荐
资源详情
资源评论
收起资源包目录
IoTDC3是一个基于Spring Cloud的 100% 完全开源的、分布式的物联网(IoT)平台,是一整套物联系统解决方案 (682个子文件)
redis.conf 92KB
rabbitmq.conf 2KB
maven.config 27B
jvm.config 17B
ca.crt 1KB
server.crt 1KB
dc3_proxy_dev_darwin 7.3MB
dc3_proxy_dev_linux 7.37MB
Dockerfile 2KB
Dockerfile 2KB
Dockerfile 2KB
Dockerfile 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 1022B
Dockerfile 922B
Dockerfile 880B
Dockerfile 869B
.dockerignore 110B
dc3_proxy_dev_windows.exe 7.48MB
.gitignore 113B
dc3-gateway.http 7KB
point.http 4KB
driver.http 3KB
device.http 2KB
driver_attrubute.http 2KB
driver_info.http 2KB
user.http 2KB
black_ip.http 2KB
profile.http 2KB
token.http 2KB
group.http 2KB
opc_da.http 2KB
point_value.http 2KB
dictionary.http 1KB
listening_virtual.http 1KB
edge_gateway.http 1KB
modbus_tcp.http 1KB
virtual.http 1KB
opc_ua.http 1KB
plc_s7.http 1KB
point_value_command.http 1KB
batch.http 1006B
mqtt.http 856B
DeviceServiceImpl.java 24KB
NumericLocator.java 21KB
ModbusMaster.java 20KB
ByteQueue.java 19KB
BasicProcessImage.java 17KB
StreamUtils.java 17KB
PDU.java 17KB
Server.java 14KB
TcpListener.java 14KB
Group.java 13KB
Nodave.java 13KB
S7Connection.java 12KB
TcpMaster.java 12KB
DriverCustomServiceImpl.java 11KB
DriverCustomServiceImpl.java 11KB
BatchServiceImpl.java 11KB
PointValueServiceImpl.java 10KB
OPCDataCallback.java 10KB
DriverCustomServiceImpl.java 10KB
ArrayUtils.java 10KB
Lwm2mServer.java 10KB
MessageControl.java 10KB
BatchRead.java 10KB
ModbusUtils.java 10KB
PointServiceImpl.java 10KB
DriverSyncServiceImpl.java 10KB
DriverCustomServiceImpl.java 9KB
PointAttributeConfigServiceImpl.java 9KB
DataType.java 9KB
BaseLocator.java 9KB
OPCItemMgt.java 9KB
TokenServiceImpl.java 8KB
AccessBase.java 8KB
TreeBrowser.java 8KB
DriverAttributeConfigServiceImpl.java 8KB
S7SerializerImpl.java 8KB
AsciiMessage.java 8KB
AuthenticGatewayFilterFactory.java 7KB
ProfileServiceImpl.java 7KB
UserServiceImpl.java 7KB
OPCGroupStateMgt.java 7KB
DictionaryServiceImpl.java 7KB
PointController.java 7KB
StringLocator.java 7KB
RtuMaster.java 7KB
PointAttributeConfigController.java 7KB
共 682 条
- 1
- 2
- 3
- 4
- 5
- 6
- 7
资源评论
Java程序员-张凯
- 粉丝: 1w+
- 资源: 6713
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- ACM(Association for Computing Machinery,计算机协会)相关的资源.txt
- 个能够从 YouTube 上抓取信息的 Python 网络爬虫,你可以使用 Python 的 Requests 库来进行网络请求
- 学生管理系统示例代码.rar
- music search and download. - 全网音乐搜索和下载
- Maven项目管理分析实列教程.txt
- VBA代码实现excel自动导出到PPT
- 硬件开发常用工具以及案列加基础知识.rar
- 用C语言写的一个直接插入排序
- 八大排序算法(手撕):冒泡排序、选择排序、插入排序、基数排序、堆排序、希尔排序、快速排序(单排)、归并排序
- 这是直接插入排序的代码
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功