Merge remote-tracking branch 'origin/master'
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
This commit is contained in:
@@ -123,17 +123,23 @@
|
||||
<artifactId>examples</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.hik</groupId>
|
||||
<artifactId>jna</artifactId>
|
||||
<version>4.5.2_1</version>
|
||||
</dependency>
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>com.hik</groupId>-->
|
||||
<!-- <artifactId>jna</artifactId>-->
|
||||
<!-- <version>4.5.2_1</version>-->
|
||||
<!-- </dependency>-->
|
||||
|
||||
<dependency>
|
||||
<groupId>com.ghgande</groupId>
|
||||
<artifactId>j2mod</artifactId>
|
||||
<version>3.0.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.java.dev.jna</groupId>
|
||||
<artifactId>jna</artifactId>
|
||||
<version>5.17.0</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
|
@@ -36,7 +36,7 @@ public class SisAlarmEventAttachments extends TenantEntity {
|
||||
/**
|
||||
* 时间图片id
|
||||
*/
|
||||
private String ossId;
|
||||
private Long ossId;
|
||||
|
||||
/**
|
||||
* 1:图片,2:文件;3视频
|
||||
|
@@ -77,4 +77,7 @@ public class SisDeviceManage extends BaseEntity {
|
||||
* 设备组id
|
||||
*/
|
||||
private Long groupId;
|
||||
|
||||
private String tenantId;
|
||||
|
||||
}
|
||||
|
@@ -35,7 +35,7 @@ public class SisAlarmEventAttachmentsBo extends BaseEntity {
|
||||
/**
|
||||
* 时间图片id
|
||||
*/
|
||||
private String ossId;
|
||||
private Long ossId;
|
||||
|
||||
/**
|
||||
* 1:图片,2:文件;3视频
|
||||
|
@@ -40,7 +40,7 @@ public class SisAlarmEventAttachmentsVo implements Serializable {
|
||||
* 时间图片id
|
||||
*/
|
||||
@ExcelProperty(value = "时间图片id")
|
||||
private String ossId;
|
||||
private Long ossId;
|
||||
|
||||
/**
|
||||
* 1:图片,2:文件;3视频
|
||||
|
@@ -0,0 +1,35 @@
|
||||
package org.dromara.sis.dubbo;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.dubbo.config.annotation.DubboService;
|
||||
import org.dromara.sis.api.RemotePrecautionary;
|
||||
import org.dromara.sis.api.domain.RemotePrecautionaryVo;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
@Slf4j
|
||||
@DubboService
|
||||
@RequiredArgsConstructor
|
||||
public class RemotePrecautionaryImpl implements RemotePrecautionary {
|
||||
private final PrecautionaryMapper precautionaryMapper;
|
||||
|
||||
@Override
|
||||
public List<RemotePrecautionaryVo> getList() {
|
||||
Page<Precautionary> Page = new Page<>(1, 10);
|
||||
QueryWrapper<Precautionary> wrapper = new QueryWrapper<>();
|
||||
wrapper.orderByAsc("time");
|
||||
return precautionaryMapper.selectVoPage(Page, wrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map count() {
|
||||
List<Precautionary> precautionaries = precautionaryMapper.selectList();
|
||||
Stream<Long> longStream = precautionaries.stream().map(Precautionary::getType);
|
||||
return Map.of();
|
||||
}
|
||||
}
|
@@ -0,0 +1,49 @@
|
||||
package org.dromara.sis.dubbo;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.dubbo.config.annotation.DubboService;
|
||||
import org.dromara.sis.api.RemoteSos;
|
||||
import org.dromara.sis.api.domain.RemoteAlarmRecord;
|
||||
import org.dromara.sis.domain.AlarmRecord;
|
||||
import org.dromara.sis.service.AlarmRecordService;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Slf4j
|
||||
@DubboService
|
||||
@RequiredArgsConstructor
|
||||
public class RemoteSosImpl implements RemoteSos {
|
||||
private final AlarmRecordService alarmRecordService;
|
||||
|
||||
@Override
|
||||
public List<RemoteAlarmRecord> getSoslist() {
|
||||
QueryWrapper<AlarmRecord> startTime = new QueryWrapper<AlarmRecord>();
|
||||
Page<AlarmRecord> page = alarmRecordService.page(new Page<>(1, 10));
|
||||
List<AlarmRecord> records = page.getRecords();
|
||||
List<RemoteAlarmRecord> remoteAlarmRecordList = new ArrayList<>();
|
||||
records.forEach(alarmRecord -> {
|
||||
RemoteAlarmRecord remoteAlarmRecord = new RemoteAlarmRecord();
|
||||
BeanUtils.copyProperties(alarmRecord, remoteAlarmRecord);
|
||||
remoteAlarmRecordList.add(remoteAlarmRecord);
|
||||
});
|
||||
return remoteAlarmRecordList;
|
||||
};
|
||||
|
||||
@Override
|
||||
public Map sosCount() {
|
||||
List<AlarmRecord> list = alarmRecordService.list();
|
||||
//进行中
|
||||
long inprogress = list.stream().filter(alarmRecord -> alarmRecord.getState().equals("inprogress")).count();
|
||||
//已结束
|
||||
long finished = list.stream().filter(alarmRecord -> alarmRecord.getState().equals("finished")).count();
|
||||
//未接通
|
||||
long noAnswer = list.stream().filter(alarmRecord -> alarmRecord.getState().equals("noAnswer")).count();
|
||||
return Map.of("进行中", inprogress, "已结束", finished, "未接通", noAnswer,"总计", list.size());
|
||||
}
|
||||
}
|
@@ -29,5 +29,5 @@ public interface AlarmRecordService extends IService<AlarmRecord> {
|
||||
* @param operatorMap 操作记录映射,键为报警记录ID,值为对应操作记录列表
|
||||
* @return 成功保存的记录数
|
||||
*/
|
||||
int saveNewRecords(List<AlarmRecord> records, Map<Long, List<Map<String, Object>>> operatorMap);
|
||||
// int saveNewRecords(List<AlarmRecord> records, Map<Long, List<Map<String, Object>>> operatorMap);
|
||||
}
|
||||
|
@@ -2,6 +2,7 @@ package org.dromara.sis.service;
|
||||
|
||||
import org.dromara.common.mybatis.core.page.PageQuery;
|
||||
import org.dromara.common.mybatis.core.page.TableDataInfo;
|
||||
import org.dromara.sis.domain.SisAlarmEventAttachments;
|
||||
import org.dromara.sis.domain.bo.SisAlarmEventAttachmentsBo;
|
||||
import org.dromara.sis.domain.vo.SisAlarmEventAttachmentsVo;
|
||||
|
||||
@@ -65,4 +66,13 @@ public interface ISisAlarmEventAttachmentsService {
|
||||
* @return 是否删除成功
|
||||
*/
|
||||
Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid);
|
||||
|
||||
/**
|
||||
* 批量写入事件附件表
|
||||
*
|
||||
* @param ls 附件数据
|
||||
* @return 返回写入数量
|
||||
*/
|
||||
Boolean batchInsert(List<SisAlarmEventAttachments> ls);
|
||||
|
||||
}
|
||||
|
@@ -76,6 +76,7 @@ public interface ISisDeviceManageService {
|
||||
*/
|
||||
SisDeviceManageVo queryVoByDeviceIp(String deviceIp);
|
||||
|
||||
SisDeviceManage queryByDeviceIp(String deviceId);
|
||||
/**
|
||||
* 查询设备数
|
||||
*
|
||||
|
@@ -27,6 +27,7 @@ public class AlarmRecordServiceImpl extends ServiceImpl<AlarmRecordMapper, Alarm
|
||||
@Autowired
|
||||
private AlarmTaskOperatorService taskOperatorService;
|
||||
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@Override
|
||||
public int saveOrUpdateRecords(List<AlarmRecord> records, Map<Long, List<Map<String, Object>>> operatorMap) {
|
||||
@@ -58,6 +59,7 @@ public class AlarmRecordServiceImpl extends ServiceImpl<AlarmRecordMapper, Alarm
|
||||
} else {
|
||||
// 新记录
|
||||
newRecords.add(record);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,10 +70,8 @@ public class AlarmRecordServiceImpl extends ServiceImpl<AlarmRecordMapper, Alarm
|
||||
if (this.saveBatch(newRecords)) {
|
||||
result += newRecords.size();
|
||||
// 保存关联的操作记录
|
||||
saveRelatedOperators(newRecords, operatorMap);
|
||||
}
|
||||
}
|
||||
|
||||
// 批量更新修改过的记录
|
||||
if (!updateRecords.isEmpty()) {
|
||||
if (this.updateBatchById(updateRecords)) {
|
||||
@@ -125,38 +125,38 @@ public class AlarmRecordServiceImpl extends ServiceImpl<AlarmRecordMapper, Alarm
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public int saveNewRecords(List<AlarmRecord> records, Map<Long, List<Map<String, Object>>> operatorMap) {
|
||||
if (records == null || records.isEmpty()) return 0;
|
||||
|
||||
// 提取待插入记录的ID列表
|
||||
List<Long> ids = records.stream().map(AlarmRecord::getId).collect(Collectors.toList());
|
||||
|
||||
// 查询数据库中已存在的记录
|
||||
LambdaQueryWrapper<AlarmRecord> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.in(AlarmRecord::getId, ids);
|
||||
List<AlarmRecord> existingRecords = this.list(queryWrapper);
|
||||
List<Long> existingIds = existingRecords.stream().map(AlarmRecord::getId).collect(Collectors.toList());
|
||||
|
||||
// 过滤出新增记录
|
||||
List<AlarmRecord> newRecords = records.stream()
|
||||
.filter(record -> !existingIds.contains(record.getId()))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
// 批量插入新记录
|
||||
int savedCount = 0;
|
||||
if (!newRecords.isEmpty()) {
|
||||
if (this.saveBatch(newRecords)) {
|
||||
savedCount = newRecords.size();
|
||||
|
||||
// 保存关联的操作记录
|
||||
saveRelatedOperators(newRecords, operatorMap);
|
||||
}
|
||||
}
|
||||
return savedCount;
|
||||
}
|
||||
//
|
||||
// @Override
|
||||
// @Transactional(rollbackFor = Exception.class)
|
||||
// public int saveNewRecords(List<AlarmRecord> records, Map<Long, List<Map<String, Object>>> operatorMap) {
|
||||
// if (records == null || records.isEmpty()) return 0;
|
||||
//
|
||||
// // 提取待插入记录的ID列表
|
||||
// List<Long> ids = records.stream().map(AlarmRecord::getId).collect(Collectors.toList());
|
||||
//
|
||||
// // 查询数据库中已存在的记录
|
||||
// LambdaQueryWrapper<AlarmRecord> queryWrapper = new LambdaQueryWrapper<>();
|
||||
// queryWrapper.in(AlarmRecord::getId, ids);
|
||||
// List<AlarmRecord> existingRecords = this.list(queryWrapper);
|
||||
// List<Long> existingIds = existingRecords.stream().map(AlarmRecord::getId).collect(Collectors.toList());
|
||||
//
|
||||
// // 过滤出新增记录
|
||||
// List<AlarmRecord> newRecords = records.stream()
|
||||
// .filter(record -> !existingIds.contains(record.getId()))
|
||||
// .collect(Collectors.toList());
|
||||
//
|
||||
// // 批量插入新记录
|
||||
// int savedCount = 0;
|
||||
// if (!newRecords.isEmpty()) {
|
||||
// if (this.saveBatch(newRecords)) {
|
||||
// savedCount = newRecords.size();
|
||||
//
|
||||
// // 保存关联的操作记录
|
||||
// saveRelatedOperators(newRecords, operatorMap);
|
||||
// }
|
||||
// }
|
||||
// return savedCount;
|
||||
// }
|
||||
|
||||
private void saveRelatedOperators(List<AlarmRecord> newRecords, Map<Long, List<Map<String, Object>>> operatorMap) {
|
||||
if (operatorMap == null || operatorMap.isEmpty()) return;
|
||||
|
@@ -6,7 +6,6 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.dromara.common.core.utils.MapstructUtils;
|
||||
import org.dromara.common.core.utils.StringUtils;
|
||||
import org.dromara.common.mybatis.core.page.PageQuery;
|
||||
import org.dromara.common.mybatis.core.page.TableDataInfo;
|
||||
import org.dromara.sis.domain.SisAlarmEventAttachments;
|
||||
@@ -40,7 +39,7 @@ public class SisAlarmEventAttachmentsServiceImpl implements ISisAlarmEventAttach
|
||||
* @return 【请填写功能名称】
|
||||
*/
|
||||
@Override
|
||||
public SisAlarmEventAttachmentsVo queryById(Long id){
|
||||
public SisAlarmEventAttachmentsVo queryById(Long id) {
|
||||
return baseMapper.selectVoById(id);
|
||||
}
|
||||
|
||||
@@ -75,7 +74,7 @@ public class SisAlarmEventAttachmentsServiceImpl implements ISisAlarmEventAttach
|
||||
LambdaQueryWrapper<SisAlarmEventAttachments> lqw = Wrappers.lambdaQuery();
|
||||
lqw.orderByAsc(SisAlarmEventAttachments::getId);
|
||||
lqw.eq(bo.getEventId() != null, SisAlarmEventAttachments::getEventId, bo.getEventId());
|
||||
lqw.eq(StringUtils.isNotBlank(bo.getOssId()), SisAlarmEventAttachments::getOssId, bo.getOssId());
|
||||
lqw.eq(bo.getOssId() != null, SisAlarmEventAttachments::getOssId, bo.getOssId());
|
||||
lqw.eq(bo.getType() != null, SisAlarmEventAttachments::getType, bo.getType());
|
||||
return lqw;
|
||||
}
|
||||
@@ -113,7 +112,7 @@ public class SisAlarmEventAttachmentsServiceImpl implements ISisAlarmEventAttach
|
||||
/**
|
||||
* 保存前的数据校验
|
||||
*/
|
||||
private void validEntityBeforeSave(SisAlarmEventAttachments entity){
|
||||
private void validEntityBeforeSave(SisAlarmEventAttachments entity) {
|
||||
//TODO 做一些数据校验,如唯一约束
|
||||
}
|
||||
|
||||
@@ -126,9 +125,14 @@ public class SisAlarmEventAttachmentsServiceImpl implements ISisAlarmEventAttach
|
||||
*/
|
||||
@Override
|
||||
public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
|
||||
if(isValid){
|
||||
if (isValid) {
|
||||
//TODO 做一些业务上的校验,判断是否需要校验
|
||||
}
|
||||
return baseMapper.deleteByIds(ids) > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean batchInsert(List<SisAlarmEventAttachments> ls) {
|
||||
return baseMapper.insertBatch(ls);
|
||||
}
|
||||
}
|
||||
|
@@ -12,19 +12,20 @@ import org.dromara.common.mybatis.core.page.PageQuery;
|
||||
import org.dromara.common.mybatis.core.page.TableDataInfo;
|
||||
import org.dromara.resource.api.RemoteFileService;
|
||||
import org.dromara.resource.api.domain.RemoteFile;
|
||||
import org.dromara.sis.domain.SisAlarmEventAttachments;
|
||||
import org.dromara.sis.domain.SisAlarmEvents;
|
||||
import org.dromara.sis.domain.SisDeviceManage;
|
||||
import org.dromara.sis.domain.bo.SisAlarmEventsBo;
|
||||
import org.dromara.sis.domain.vo.SisAlarmEventsVo;
|
||||
import org.dromara.sis.domain.vo.SisDeviceManageVo;
|
||||
import org.dromara.sis.mapper.SisAlarmEventsMapper;
|
||||
import org.dromara.sis.service.ISisAlarmEventAttachmentsService;
|
||||
import org.dromara.sis.service.ISisAlarmEventsService;
|
||||
import org.dromara.sis.service.ISisDeviceManageService;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* 告警Service业务层处理
|
||||
@@ -39,6 +40,7 @@ public class SisAlarmEventsServiceImpl implements ISisAlarmEventsService {
|
||||
|
||||
private final SisAlarmEventsMapper baseMapper;
|
||||
private final ISisDeviceManageService deviceManageService;
|
||||
private final ISisAlarmEventAttachmentsService alarmEventAttachmentsService;
|
||||
|
||||
@DubboReference
|
||||
private RemoteFileService remoteFileService;
|
||||
@@ -148,17 +150,49 @@ public class SisAlarmEventsServiceImpl implements ISisAlarmEventsService {
|
||||
|
||||
@Async
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void createAlarmRecord(String deviceIp, Integer level, Integer type, byte[] smallImg, byte[] bigImg) {
|
||||
// 校验设备信息
|
||||
SisDeviceManageVo sisDeviceManageVo = deviceManageService.queryVoByDeviceIp(deviceIp);
|
||||
if (sisDeviceManageVo == null) {
|
||||
SisDeviceManage sisDeviceManage = deviceManageService.queryByDeviceIp(deviceIp);
|
||||
if (sisDeviceManage == null) {
|
||||
log.error("设备信息不存在,放弃此条告警记录。");
|
||||
return;
|
||||
}
|
||||
// 生成时间信息
|
||||
SisAlarmEvents alarmEvents = new SisAlarmEvents();
|
||||
alarmEvents.setType(1L);
|
||||
alarmEvents.setLevel(Long.valueOf(level));
|
||||
alarmEvents.setDeviceIp(deviceIp);
|
||||
alarmEvents.setDeviceName(sisDeviceManage.getDeviceName());
|
||||
alarmEvents.setDeviceGroupId(sisDeviceManage.getId());
|
||||
alarmEvents.setReportTime(new Date());
|
||||
alarmEvents.setState(1);
|
||||
alarmEvents.setTenantId(sisDeviceManage.getTenantId());
|
||||
alarmEvents.setCreateDept(sisDeviceManage.getCreateDept());
|
||||
int insert = this.baseMapper.insert(alarmEvents);
|
||||
log.info("写入报警事件表完成,num={}", insert);
|
||||
// 写入附件表
|
||||
// 上传图片
|
||||
RemoteFile small = remoteFileService.uploadImg(smallImg);
|
||||
RemoteFile big = remoteFileService.uploadImg(bigImg);
|
||||
|
||||
List<SisAlarmEventAttachments> ls = new ArrayList<>();
|
||||
if (smallImg != null && smallImg.length > 0) {
|
||||
ls.add(createEventAttachments(smallImg, alarmEvents, sisDeviceManage));
|
||||
}
|
||||
if (bigImg != null && bigImg.length > 0) {
|
||||
ls.add(createEventAttachments(bigImg, alarmEvents, sisDeviceManage));
|
||||
}
|
||||
Boolean flag = alarmEventAttachmentsService.batchInsert(ls);
|
||||
log.info("写入告警事件附件表完成, reslut={}, size={}", flag, ls.size());
|
||||
|
||||
}
|
||||
|
||||
public SisAlarmEventAttachments createEventAttachments(byte[] img, SisAlarmEvents alarmEvents, SisDeviceManage sisDeviceManage) {
|
||||
RemoteFile result = remoteFileService.uploadImg(img);
|
||||
SisAlarmEventAttachments attachments = new SisAlarmEventAttachments();
|
||||
attachments.setEventId(alarmEvents.getId());
|
||||
attachments.setOssId(result.getOssId());
|
||||
attachments.setType(1L);
|
||||
attachments.setTenantId(sisDeviceManage.getTenantId());
|
||||
attachments.setCreateDept(sisDeviceManage.getCreateDept());
|
||||
return attachments;
|
||||
}
|
||||
}
|
||||
|
@@ -178,7 +178,14 @@ public class SisDeviceManageServiceImpl implements ISisDeviceManageService {
|
||||
public SisDeviceManageVo queryVoByDeviceIp(String deviceIp) {
|
||||
LambdaQueryWrapper<SisDeviceManage> lqw = Wrappers.lambdaQuery();
|
||||
lqw.eq(SisDeviceManage::getDeviceIp, deviceIp);
|
||||
return baseMapper.selectVoById(lqw);
|
||||
return baseMapper.selectVoOne(lqw);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SisDeviceManage queryByDeviceIp(String deviceId) {
|
||||
LambdaQueryWrapper<SisDeviceManage> lqw = Wrappers.lambdaQuery();
|
||||
lqw.eq(SisDeviceManage::getDeviceIp, deviceId);
|
||||
return baseMapper.selectOne(lqw);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Reference in New Issue
Block a user