同步代码
This commit is contained in:
parent
1d474d735e
commit
1f4e168b56
@ -1,6 +1,5 @@
|
||||
package org.dromara.resource.api;
|
||||
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import org.dromara.common.core.exception.ServiceException;
|
||||
import org.dromara.resource.api.domain.RemoteFile;
|
||||
|
||||
@ -22,6 +21,14 @@ public interface RemoteFileService {
|
||||
*/
|
||||
RemoteFile upload(String name, String originalFilename, String contentType, byte[] file) throws ServiceException;
|
||||
|
||||
/**
|
||||
* 文件上传
|
||||
* @param file 文件信息
|
||||
* @return 结果
|
||||
* @throws ServiceException
|
||||
*/
|
||||
RemoteFile upload(byte[] file) throws ServiceException;
|
||||
|
||||
/**
|
||||
* 通过ossId查询对应的url
|
||||
*
|
||||
|
@ -0,0 +1,70 @@
|
||||
package org.dromara.common.core.enums;
|
||||
|
||||
/**
|
||||
* 常用文件的文件头如下:(以前六位为准)
|
||||
* JPEG (jpg),文件头:FFD8FF
|
||||
* PNG (png),文件头:89504E47
|
||||
* GIF (gif),文件头:47494638
|
||||
* TIFF (tif),文件头:49492A00
|
||||
* Windows Bitmap (bmp),文件头:424D
|
||||
* CAD (dwg),文件头:41433130
|
||||
* Adobe Photoshop (psd),文件头:38425053
|
||||
* Rich Text Format (rtf),文件头:7B5C727466
|
||||
* XML (xml),文件头:3C3F786D6C
|
||||
* HTML (html),文件头:68746D6C3E
|
||||
* Email [thorough only] (eml),文件头:44656C69766572792D646174653A
|
||||
* Outlook Express (dbx),文件头:CFAD12FEC5FD746F
|
||||
* Outlook (pst),文件头:2142444E
|
||||
* MS Word/Excel (xls.or.doc),文件头:D0CF11E0
|
||||
* MS Access (mdb),文件头:5374616E64617264204A
|
||||
* WordPerfect (wpd),文件头:FF575043
|
||||
* Postscript (eps.or.ps),文件头:252150532D41646F6265
|
||||
* Adobe Acrobat (pdf),文件头:255044462D312E
|
||||
* Quicken (qdf),文件头:AC9EBD8F
|
||||
* Windows Password (pwl),文件头:E3828596
|
||||
* ZIP Archive (zip),文件头:504B0304
|
||||
* RAR Archive (rar),文件头:52617221
|
||||
* Wave (wav),文件头:57415645
|
||||
* AVI (avi),文件头:41564920
|
||||
* Real Audio (ram),文件头:2E7261FD
|
||||
* Real Media (rm),文件头:2E524D46
|
||||
* MPEG (mpg),文件头:000001BA
|
||||
* MPEG (mpg),文件头:000001B3
|
||||
* Quicktime (mov),文件头:6D6F6F76
|
||||
* Windows Media (asf),文件头:3026B2758E66CF11
|
||||
* MIDI (mid),文件头:4D546864
|
||||
*/
|
||||
public enum ImageType {
|
||||
JPEG("jpg", "FFD8FF"),
|
||||
PNG("png","89504E47"),
|
||||
Windows_Bitmap("bmp","424D"),
|
||||
|
||||
GIF("gif","47494638"),
|
||||
TIFF("tif","49492A00"),
|
||||
CAD("dwg","41433130"),
|
||||
Adobe_Photoshop("psd","38425053"),
|
||||
XML("xml","3C3F786D6C"),
|
||||
HTML("html","68746D6C3E"),
|
||||
Adobe_Acrobat("pdf","255044462D312E"),
|
||||
ZIP_Archive("zip","504B0304"),
|
||||
RAR_Archive("rar","52617221"),
|
||||
Wave("wav","57415645"),
|
||||
AVI("avi","41564920");
|
||||
|
||||
private final String suffix;
|
||||
private final String headCode;
|
||||
|
||||
ImageType(String suffix, String headCode) {
|
||||
this.suffix = suffix;
|
||||
this.headCode = headCode;
|
||||
}
|
||||
|
||||
public String getSuffix() {
|
||||
return suffix;
|
||||
}
|
||||
|
||||
public String getHeadCode() {
|
||||
return headCode;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,147 @@
|
||||
package org.dromara.common.core.utils;
|
||||
|
||||
import cn.hutool.core.io.IoUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.dromara.common.core.enums.ImageType;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Base64;
|
||||
|
||||
/**
|
||||
* [base64 加密解密工具类]
|
||||
*
|
||||
* @author : [lxj]
|
||||
* @version : [v1.0]
|
||||
* @createTime : [2021/4/27 12:54]
|
||||
*/
|
||||
@Slf4j
|
||||
public class Base64Utils {
|
||||
|
||||
|
||||
public Base64Utils(){}
|
||||
/**
|
||||
* 文件路径转base64
|
||||
* @param path 文件路径
|
||||
* @return 如果成功返回base64 字符串,否则返回null
|
||||
*/
|
||||
public static String file2Base64(String path){
|
||||
File f = new File(path);
|
||||
if(f.exists()){
|
||||
return file2Base64(f);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 文件转base64
|
||||
* @param filePath 文件对象
|
||||
* @return 如果成功返回base64 字符串,否则返回null
|
||||
*/
|
||||
public static String file2Base64(File filePath){
|
||||
return file2Base64(filePath.toPath());
|
||||
}
|
||||
|
||||
/**
|
||||
* 文件转base64
|
||||
* @param p Path 对象
|
||||
* @return 如果成功返回base64 字符串,否则返回null
|
||||
*/
|
||||
public static String file2Base64(Path p) {
|
||||
try {
|
||||
byte[] b = Files.readAllBytes(p);
|
||||
return byte2Base64(b);
|
||||
} catch (IOException e) {
|
||||
log.error("文件转base64失败, msg:" + e.getMessage());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 输入流转base64
|
||||
* @param inputStream 输入流
|
||||
* @return 如果成功返回base64 字符串,否则返回null
|
||||
*/
|
||||
public static String stream2Base64(InputStream inputStream){
|
||||
try {
|
||||
byte [] b = IoUtil.readBytes(inputStream);
|
||||
return byte2Base64(b);
|
||||
} catch (Exception e) {
|
||||
log.error("输入流转base64失败, msg:" + e.getMessage());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 字节数组转base64
|
||||
* @param b 字节数组
|
||||
* @return
|
||||
*/
|
||||
public static String byte2Base64(byte [] b){
|
||||
assert b != null && b.length > 0;
|
||||
return Base64.getEncoder().encodeToString(b);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过文件的base计算文件的格式
|
||||
* @param base64 文件的base64
|
||||
* @return
|
||||
*/
|
||||
public static String getType(String base64){
|
||||
byte[] b = Base64.getDecoder().decode(base64);
|
||||
return getType(b);
|
||||
}
|
||||
|
||||
public static String getType(byte [] b){
|
||||
try {
|
||||
String xxx = bytesToHexString(b);
|
||||
assert xxx != null && !xxx.isEmpty();
|
||||
ImageType[] types = ImageType.values();
|
||||
String suffix = null;
|
||||
for (ImageType type: types) {
|
||||
if(xxx.toUpperCase().startsWith(type.getHeadCode())){
|
||||
suffix = type.getSuffix();
|
||||
break;
|
||||
}
|
||||
}
|
||||
return suffix;
|
||||
}catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 判断文件格式 取前6个字符来进行判断
|
||||
* @param src 文件字节数组
|
||||
* @return 返回文件字节数组前6位编码
|
||||
*/
|
||||
public static String bytesToHexString(byte[] src) {
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
int pifNum = 10;
|
||||
if (src == null || src.length <= pifNum) {
|
||||
return null;
|
||||
}
|
||||
for (int i = 0; i < pifNum; i ++) {
|
||||
int v = src[i] & 0xFF;
|
||||
String hv = Integer.toHexString(v);
|
||||
if (hv.length() < 2) {
|
||||
stringBuilder.append(0);
|
||||
}
|
||||
stringBuilder.append(hv);
|
||||
}
|
||||
return stringBuilder.toString();
|
||||
}
|
||||
|
||||
public static String handleBase64Header(String webBase64Code){
|
||||
String [] s = webBase64Code.split("base64,");
|
||||
if(s.length == 2){
|
||||
return s[1];
|
||||
}
|
||||
return webBase64Code;
|
||||
}
|
||||
|
||||
}
|
@ -1,13 +1,13 @@
|
||||
package org.dromara.sis.domain;
|
||||
|
||||
import org.dromara.common.tenant.core.TenantEntity;
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import java.util.Date;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import org.dromara.common.tenant.core.TenantEntity;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 告警对象 sis_alarm_events
|
||||
@ -64,5 +64,14 @@ public class SisAlarmEvents extends TenantEntity {
|
||||
*/
|
||||
private Date reportTime;
|
||||
|
||||
/**
|
||||
* 事件状态
|
||||
*/
|
||||
private Integer state;
|
||||
|
||||
/**
|
||||
* 工单id
|
||||
*/
|
||||
private Long workOrderId;
|
||||
|
||||
}
|
||||
|
@ -1,15 +1,15 @@
|
||||
package org.dromara.sis.domain.bo;
|
||||
|
||||
import org.dromara.sis.domain.SisAlarmEvents;
|
||||
import org.dromara.common.mybatis.core.domain.BaseEntity;
|
||||
import org.dromara.common.core.validate.AddGroup;
|
||||
import org.dromara.common.core.validate.EditGroup;
|
||||
import io.github.linpeilie.annotations.AutoMapper;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import jakarta.validation.constraints.*;
|
||||
import org.dromara.common.core.validate.AddGroup;
|
||||
import org.dromara.common.core.validate.EditGroup;
|
||||
import org.dromara.common.mybatis.core.domain.BaseEntity;
|
||||
import org.dromara.sis.domain.SisAlarmEvents;
|
||||
|
||||
import java.util.Date;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
|
||||
/**
|
||||
* 告警业务对象 sis_alarm_events
|
||||
@ -66,5 +66,14 @@ public class SisAlarmEventsBo extends BaseEntity {
|
||||
@NotNull(message = "设备告警时间不能为空", groups = {AddGroup.class, EditGroup.class})
|
||||
private Date reportTime;
|
||||
|
||||
/**
|
||||
* 事件状态
|
||||
*/
|
||||
private Integer state;
|
||||
|
||||
/**
|
||||
* 工单id
|
||||
*/
|
||||
private Long workOrderId;
|
||||
|
||||
}
|
||||
|
@ -78,5 +78,13 @@ public class SisAlarmEventsVo implements Serializable {
|
||||
@ExcelProperty(value = "设备告警时间")
|
||||
private Date reportTime;
|
||||
|
||||
/**
|
||||
* 事件状态
|
||||
*/
|
||||
private Integer state;
|
||||
|
||||
/**
|
||||
* 工单id
|
||||
*/
|
||||
private Long workOrderId;
|
||||
}
|
||||
|
@ -1,10 +1,9 @@
|
||||
package org.dromara.sis.service;
|
||||
|
||||
import org.dromara.sis.domain.SisAlarmEvents;
|
||||
import org.dromara.sis.domain.vo.SisAlarmEventsVo;
|
||||
import org.dromara.sis.domain.bo.SisAlarmEventsBo;
|
||||
import org.dromara.common.mybatis.core.page.TableDataInfo;
|
||||
import org.dromara.common.mybatis.core.page.PageQuery;
|
||||
import org.dromara.common.mybatis.core.page.TableDataInfo;
|
||||
import org.dromara.sis.domain.bo.SisAlarmEventsBo;
|
||||
import org.dromara.sis.domain.vo.SisAlarmEventsVo;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
@ -66,4 +65,10 @@ public interface ISisAlarmEventsService {
|
||||
* @return 是否删除成功
|
||||
*/
|
||||
Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid);
|
||||
|
||||
/**
|
||||
* 异步生成告警记录
|
||||
*/
|
||||
void createAlarmRecord(String deviceIp, Integer level, Integer type, byte[] smallImg, byte[] bigImg);
|
||||
|
||||
}
|
||||
|
@ -71,10 +71,10 @@ public interface ISisDeviceManageService {
|
||||
/**
|
||||
* 通过设备ip查询设备信息
|
||||
*
|
||||
* @param deviceCode 设备编码
|
||||
* @param deviceIp 设备编码
|
||||
* @return 设备信息
|
||||
*/
|
||||
SisDeviceManageVo queryVoByDeviceIp(Integer deviceCode);
|
||||
SisDeviceManageVo queryVoByDeviceIp(String deviceIp);
|
||||
|
||||
/**
|
||||
* 查询设备数
|
||||
|
@ -1,24 +1,29 @@
|
||||
package org.dromara.sis.service.impl;
|
||||
|
||||
import org.dromara.common.core.utils.MapstructUtils;
|
||||
import org.dromara.common.core.utils.StringUtils;
|
||||
import org.dromara.common.mybatis.core.page.TableDataInfo;
|
||||
import org.dromara.common.mybatis.core.page.PageQuery;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.apache.dubbo.config.annotation.DubboReference;
|
||||
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.resource.api.RemoteFileService;
|
||||
import org.dromara.sis.domain.SisAlarmEvents;
|
||||
import org.dromara.sis.domain.bo.SisAlarmEventsBo;
|
||||
import org.dromara.sis.domain.vo.SisAlarmEventsVo;
|
||||
import org.dromara.sis.domain.SisAlarmEvents;
|
||||
import org.dromara.sis.domain.vo.SisDeviceManageVo;
|
||||
import org.dromara.sis.mapper.SisAlarmEventsMapper;
|
||||
import org.dromara.sis.service.ISisAlarmEventsService;
|
||||
import org.dromara.sis.service.ISisDeviceManageService;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* 告警Service业务层处理
|
||||
@ -32,7 +37,10 @@ import java.util.Collection;
|
||||
public class SisAlarmEventsServiceImpl implements ISisAlarmEventsService {
|
||||
|
||||
private final SisAlarmEventsMapper baseMapper;
|
||||
private final ISisDeviceManageService deviceManageService;
|
||||
|
||||
@DubboReference
|
||||
private RemoteFileService remoteFileService;
|
||||
/**
|
||||
* 查询告警
|
||||
*
|
||||
@ -134,5 +142,23 @@ public class SisAlarmEventsServiceImpl implements ISisAlarmEventsService {
|
||||
//TODO 做一些业务上的校验,判断是否需要校验
|
||||
}
|
||||
return baseMapper.deleteByIds(ids) > 0;
|
||||
}
|
||||
|
||||
@Async
|
||||
@Override
|
||||
public void createAlarmRecord(String deviceIp, Integer level, Integer type, byte[] smallImg, byte[] bigImg) {
|
||||
// 校验设备信息
|
||||
SisDeviceManageVo sisDeviceManageVo = deviceManageService.queryVoByDeviceIp(deviceIp);
|
||||
if(sisDeviceManageVo == null){
|
||||
log.error("设备信息不存在,放弃此条告警记录。");
|
||||
return;
|
||||
}
|
||||
// 上传图片
|
||||
remoteFileService.upload(smallImg);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -175,9 +175,9 @@ public class SisDeviceManageServiceImpl implements ISisDeviceManageService {
|
||||
|
||||
|
||||
@Override
|
||||
public SisDeviceManageVo queryVoByDeviceIp(Integer deviceCode) {
|
||||
public SisDeviceManageVo queryVoByDeviceIp(String deviceIp) {
|
||||
LambdaQueryWrapper<SisDeviceManage> lqw = Wrappers.lambdaQuery();
|
||||
lqw.eq(SisDeviceManage::getDeviceIp, deviceCode);
|
||||
lqw.eq(SisDeviceManage::getDeviceIp, deviceIp);
|
||||
return baseMapper.selectVoById(lqw);
|
||||
}
|
||||
|
||||
|
@ -109,9 +109,8 @@ public class ZeroSensationPassageServiceImpl implements IZeroSensationPassageSer
|
||||
/**
|
||||
* 生成告警事件
|
||||
*/
|
||||
public void createAlarmRecord() {
|
||||
|
||||
|
||||
public void createAlarmRecord(String deviceIp, Integer level, Integer type, byte[] smallImg, byte[] bigImg) {
|
||||
alarmEventsService.createAlarmRecord(deviceIp, level, type, smallImg, bigImg);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -6,6 +6,7 @@ import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.dubbo.config.annotation.DubboService;
|
||||
import org.dromara.common.core.exception.ServiceException;
|
||||
import org.dromara.common.core.utils.Base64Utils;
|
||||
import org.dromara.common.core.utils.MapstructUtils;
|
||||
import org.dromara.common.core.utils.StringUtils;
|
||||
import org.dromara.common.oss.core.OssClient;
|
||||
@ -66,6 +67,19 @@ public class RemoteFileServiceImpl implements RemoteFileService {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public RemoteFile upload(byte[] file) throws ServiceException {
|
||||
// 计算文件类型
|
||||
String type = Base64Utils.getType(file);
|
||||
// 获contentType
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过ossId查询对应的url
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user