package com.ruoyi.alarm.service.impl;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.ruoyi.alarm.dto.AlarmCollectionInterfaceDto;
|
import com.ruoyi.alarm.dto.AlarmPointDto;
|
import com.ruoyi.alarm.mapper.AlarmCollectionInterfaceMapper;
|
import com.ruoyi.alarm.mapper.AlarmPointMapper;
|
import com.ruoyi.alarm.pojo.AlarmCollectionInterface;
|
import com.ruoyi.alarm.pojo.AlarmPoint;
|
import com.ruoyi.alarm.service.IAlarmCollectionService;
|
import com.ruoyi.alarm.vo.AlarmCollectionInterfaceVo;
|
import com.ruoyi.alarm.vo.AlarmPointLedgerVo;
|
import com.ruoyi.alarm.vo.AlarmStatisticsVo;
|
import com.ruoyi.common.utils.bean.BeanUtils;
|
import lombok.AllArgsConstructor;
|
import org.springframework.stereotype.Service;
|
|
import java.time.LocalDateTime;
|
import java.util.ArrayList;
|
import java.util.List;
|
|
@Service
|
@AllArgsConstructor
|
public class AlarmCollectionServiceImpl extends ServiceImpl<AlarmPointMapper, AlarmPoint> implements IAlarmCollectionService {
|
|
private AlarmPointMapper alarmPointMapper;
|
private AlarmCollectionInterfaceMapper alarmCollectionInterfaceMapper;
|
|
@Override
|
public AlarmStatisticsVo getStatistics() {
|
AlarmStatisticsVo vo = new AlarmStatisticsVo();
|
LambdaQueryWrapper<AlarmPoint> wrapper = new LambdaQueryWrapper<>();
|
wrapper.eq(AlarmPoint::getStatus, 1);
|
Long totalPoints = alarmPointMapper.selectCount(wrapper);
|
vo.setTotalPoints(totalPoints.intValue());
|
vo.setConnectedDevices((int) (totalPoints * 0.7));
|
vo.setTodayDataVolume(245.6);
|
vo.setParseSuccessRate(99.8);
|
return vo;
|
}
|
|
@Override
|
public IPage<AlarmPointLedgerVo> getPointLedgerList(Page page, AlarmPointDto dto) {
|
LambdaQueryWrapper<AlarmPoint> wrapper = new LambdaQueryWrapper<>();
|
if (dto.getPointName() != null && !dto.getPointName().isEmpty()) {
|
wrapper.like(AlarmPoint::getPointName, dto.getPointName());
|
}
|
if (dto.getDeviceType() != null && !dto.getDeviceType().isEmpty()) {
|
wrapper.eq(AlarmPoint::getDeviceType, dto.getDeviceType());
|
}
|
wrapper.orderByDesc(AlarmPoint::getCreateTime);
|
IPage<AlarmPoint> pointPage = alarmPointMapper.selectPage(page, wrapper);
|
return pointPage.convert(point -> {
|
AlarmPointLedgerVo vo = new AlarmPointLedgerVo();
|
BeanUtils.copyProperties(point, vo);
|
return vo;
|
});
|
}
|
|
@Override
|
public int addPoint(AlarmPointDto dto) {
|
AlarmPoint point = new AlarmPoint();
|
BeanUtils.copyProperties(dto, point);
|
point.setCreateTime(LocalDateTime.now());
|
point.setUpdateTime(LocalDateTime.now());
|
return alarmPointMapper.insert(point);
|
}
|
|
@Override
|
public int updatePoint(AlarmPointDto dto) {
|
AlarmPoint point = new AlarmPoint();
|
BeanUtils.copyProperties(dto, point);
|
point.setUpdateTime(LocalDateTime.now());
|
return alarmPointMapper.updateById(point);
|
}
|
|
@Override
|
public int deletePoint(Long pointId) {
|
return alarmPointMapper.deleteById(pointId);
|
}
|
|
@Override
|
public int changePointStatus(Long pointId, Integer status) {
|
AlarmPoint point = new AlarmPoint();
|
point.setPointId(pointId);
|
point.setStatus(status);
|
point.setUpdateTime(LocalDateTime.now());
|
return alarmPointMapper.updateById(point);
|
}
|
|
@Override
|
public List<AlarmPointLedgerVo> getPointOptions() {
|
LambdaQueryWrapper<AlarmPoint> wrapper = new LambdaQueryWrapper<>();
|
wrapper.eq(AlarmPoint::getStatus, 1);
|
wrapper.select(AlarmPoint::getPointId, AlarmPoint::getPointName);
|
List<AlarmPoint> points = alarmPointMapper.selectList(wrapper);
|
return points.stream().map(point -> {
|
AlarmPointLedgerVo vo = new AlarmPointLedgerVo();
|
vo.setPointId(point.getPointId());
|
vo.setPointName(point.getPointName());
|
return vo;
|
}).collect(java.util.stream.Collectors.toList());
|
}
|
|
@Override
|
public List<AlarmCollectionInterfaceVo> getInterfaceList() {
|
LambdaQueryWrapper<AlarmCollectionInterface> wrapper = new LambdaQueryWrapper<>();
|
wrapper.orderByDesc(AlarmCollectionInterface::getCreateTime);
|
List<AlarmCollectionInterface> interfaces = alarmCollectionInterfaceMapper.selectList(wrapper);
|
|
if (interfaces.isEmpty()) {
|
List<AlarmCollectionInterfaceVo> mockData = new ArrayList<>();
|
AlarmCollectionInterfaceVo vo = new AlarmCollectionInterfaceVo();
|
vo.setInterfaceId(1L);
|
vo.setInterfaceName("OPC UA数据采集");
|
vo.setInterfaceType("OPC UA");
|
vo.setServerAddress("opc.tcp://192.168.1.100:4840");
|
vo.setCollectFreq("1秒");
|
vo.setConnectStatus("connected");
|
mockData.add(vo);
|
return mockData;
|
}
|
|
return interfaces.stream().map(iface -> {
|
AlarmCollectionInterfaceVo vo = new AlarmCollectionInterfaceVo();
|
BeanUtils.copyProperties(iface, vo);
|
return vo;
|
}).collect(java.util.stream.Collectors.toList());
|
}
|
|
@Override
|
public int startInterface(Long interfaceId) {
|
AlarmCollectionInterface iface = new AlarmCollectionInterface();
|
iface.setInterfaceId(interfaceId);
|
iface.setConnectStatus("connected");
|
iface.setUpdateTime(LocalDateTime.now());
|
return alarmCollectionInterfaceMapper.updateById(iface);
|
}
|
|
@Override
|
public int stopInterface(Long interfaceId) {
|
AlarmCollectionInterface iface = new AlarmCollectionInterface();
|
iface.setInterfaceId(interfaceId);
|
iface.setConnectStatus("disconnected");
|
iface.setUpdateTime(LocalDateTime.now());
|
return alarmCollectionInterfaceMapper.updateById(iface);
|
}
|
|
@Override
|
public int addOrUpdateInterface(AlarmCollectionInterfaceDto dto) {
|
AlarmCollectionInterface iface = new AlarmCollectionInterface();
|
BeanUtils.copyProperties(dto, iface);
|
iface.setUpdateTime(LocalDateTime.now());
|
|
if (dto.getInterfaceId() == null) {
|
// 新增
|
iface.setCreateTime(LocalDateTime.now());
|
return alarmCollectionInterfaceMapper.insert(iface);
|
} else {
|
// 更新
|
return alarmCollectionInterfaceMapper.updateById(iface);
|
}
|
}
|
|
@Override
|
public int deleteInterface(Long interfaceId) {
|
return alarmCollectionInterfaceMapper.deleteById(interfaceId);
|
}
|
}
|