同步代码
This commit is contained in:
parent
291f9e7ffa
commit
58971070e9
@ -27,7 +27,7 @@ public interface RemoteFileService {
|
|||||||
* @return 结果
|
* @return 结果
|
||||||
* @throws ServiceException
|
* @throws ServiceException
|
||||||
*/
|
*/
|
||||||
RemoteFile upload(byte[] file) throws ServiceException;
|
RemoteFile uploadImg(byte[] file) throws ServiceException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 通过ossId查询对应的url
|
* 通过ossId查询对应的url
|
||||||
|
@ -30,7 +30,13 @@ public enum ContentTypeEnum {
|
|||||||
/**
|
/**
|
||||||
* GIF图片类型
|
* GIF图片类型
|
||||||
*/
|
*/
|
||||||
GIF("gif", "image/gif");
|
GIF("gif", "image/gif"),
|
||||||
|
|
||||||
|
WEBP("webp", "image/webp"),
|
||||||
|
|
||||||
|
SVG("svg", "image/svg+xml"),
|
||||||
|
|
||||||
|
;
|
||||||
|
|
||||||
private final String extension;
|
private final String extension;
|
||||||
private final String contentType;
|
private final String contentType;
|
||||||
@ -41,13 +47,13 @@ public enum ContentTypeEnum {
|
|||||||
* @param extension 文件扩展名
|
* @param extension 文件扩展名
|
||||||
* @return 对应的内容类型,如果未找到则返回null
|
* @return 对应的内容类型,如果未找到则返回null
|
||||||
*/
|
*/
|
||||||
public static String getContentType(String extension) {
|
public static ContentTypeEnum ContentTypeEnum(String extension) {
|
||||||
for (ContentTypeEnum type : values()) {
|
for (ContentTypeEnum type : values()) {
|
||||||
if (type.extension.equalsIgnoreCase(extension)) {
|
if (type.extension.equalsIgnoreCase(extension)) {
|
||||||
return type.contentType;
|
return type;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return JPG;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -11,6 +11,7 @@ import org.dromara.common.core.utils.StringUtils;
|
|||||||
import org.dromara.common.mybatis.core.page.PageQuery;
|
import org.dromara.common.mybatis.core.page.PageQuery;
|
||||||
import org.dromara.common.mybatis.core.page.TableDataInfo;
|
import org.dromara.common.mybatis.core.page.TableDataInfo;
|
||||||
import org.dromara.resource.api.RemoteFileService;
|
import org.dromara.resource.api.RemoteFileService;
|
||||||
|
import org.dromara.resource.api.domain.RemoteFile;
|
||||||
import org.dromara.sis.domain.SisAlarmEvents;
|
import org.dromara.sis.domain.SisAlarmEvents;
|
||||||
import org.dromara.sis.domain.bo.SisAlarmEventsBo;
|
import org.dromara.sis.domain.bo.SisAlarmEventsBo;
|
||||||
import org.dromara.sis.domain.vo.SisAlarmEventsVo;
|
import org.dromara.sis.domain.vo.SisAlarmEventsVo;
|
||||||
@ -41,6 +42,7 @@ public class SisAlarmEventsServiceImpl implements ISisAlarmEventsService {
|
|||||||
|
|
||||||
@DubboReference
|
@DubboReference
|
||||||
private RemoteFileService remoteFileService;
|
private RemoteFileService remoteFileService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询告警
|
* 查询告警
|
||||||
*
|
*
|
||||||
@ -48,7 +50,7 @@ public class SisAlarmEventsServiceImpl implements ISisAlarmEventsService {
|
|||||||
* @return 告警
|
* @return 告警
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public SisAlarmEventsVo queryById(Long id){
|
public SisAlarmEventsVo queryById(Long id) {
|
||||||
return baseMapper.selectVoById(id);
|
return baseMapper.selectVoById(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -125,7 +127,7 @@ public class SisAlarmEventsServiceImpl implements ISisAlarmEventsService {
|
|||||||
/**
|
/**
|
||||||
* 保存前的数据校验
|
* 保存前的数据校验
|
||||||
*/
|
*/
|
||||||
private void validEntityBeforeSave(SisAlarmEvents entity){
|
private void validEntityBeforeSave(SisAlarmEvents entity) {
|
||||||
//TODO 做一些数据校验,如唯一约束
|
//TODO 做一些数据校验,如唯一约束
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -138,7 +140,7 @@ public class SisAlarmEventsServiceImpl implements ISisAlarmEventsService {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
|
public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
|
||||||
if(isValid){
|
if (isValid) {
|
||||||
//TODO 做一些业务上的校验,判断是否需要校验
|
//TODO 做一些业务上的校验,判断是否需要校验
|
||||||
}
|
}
|
||||||
return baseMapper.deleteByIds(ids) > 0;
|
return baseMapper.deleteByIds(ids) > 0;
|
||||||
@ -149,15 +151,13 @@ public class SisAlarmEventsServiceImpl implements ISisAlarmEventsService {
|
|||||||
public void createAlarmRecord(String deviceIp, Integer level, Integer type, byte[] smallImg, byte[] bigImg) {
|
public void createAlarmRecord(String deviceIp, Integer level, Integer type, byte[] smallImg, byte[] bigImg) {
|
||||||
// 校验设备信息
|
// 校验设备信息
|
||||||
SisDeviceManageVo sisDeviceManageVo = deviceManageService.queryVoByDeviceIp(deviceIp);
|
SisDeviceManageVo sisDeviceManageVo = deviceManageService.queryVoByDeviceIp(deviceIp);
|
||||||
if(sisDeviceManageVo == null){
|
if (sisDeviceManageVo == null) {
|
||||||
log.error("设备信息不存在,放弃此条告警记录。");
|
log.error("设备信息不存在,放弃此条告警记录。");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// 上传图片
|
// 上传图片
|
||||||
remoteFileService.upload(smallImg);
|
RemoteFile small = remoteFileService.uploadImg(smallImg);
|
||||||
|
RemoteFile big = remoteFileService.uploadImg(bigImg);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@ import jakarta.servlet.http.HttpServletResponse;
|
|||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.dubbo.config.annotation.DubboService;
|
import org.apache.dubbo.config.annotation.DubboService;
|
||||||
|
import org.dromara.common.core.enums.ContentTypeEnum;
|
||||||
import org.dromara.common.core.exception.ServiceException;
|
import org.dromara.common.core.exception.ServiceException;
|
||||||
import org.dromara.common.core.utils.Base64Utils;
|
import org.dromara.common.core.utils.Base64Utils;
|
||||||
import org.dromara.common.core.utils.MapstructUtils;
|
import org.dromara.common.core.utils.MapstructUtils;
|
||||||
@ -68,16 +69,33 @@ public class RemoteFileServiceImpl implements RemoteFileService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public RemoteFile upload(byte[] file) throws ServiceException {
|
public RemoteFile uploadImg(byte[] file) throws ServiceException {
|
||||||
// 计算文件类型
|
try {
|
||||||
String type = Base64Utils.getType(file);
|
// 计算文件类型
|
||||||
// 获contentType
|
String type = Base64Utils.getType(file);
|
||||||
|
// 获contentType
|
||||||
|
ContentTypeEnum contentTypeEnum = ContentTypeEnum.ContentTypeEnum(type);
|
||||||
|
OssClient storage = OssFactory.instance();
|
||||||
|
UploadResult uploadResult = storage.uploadSuffix(file, type, contentTypeEnum.getContentType());
|
||||||
|
// 保存文件信息
|
||||||
return null;
|
SysOssBo oss = new SysOssBo();
|
||||||
|
oss.setUrl(uploadResult.getUrl());
|
||||||
|
oss.setFileSuffix(type);
|
||||||
|
oss.setFileName(uploadResult.getFilename());
|
||||||
|
oss.setOriginalName(uploadResult.getFilename());
|
||||||
|
oss.setService(storage.getConfigKey());
|
||||||
|
sysOssService.insertByBo(oss);
|
||||||
|
RemoteFile sysFile = new RemoteFile();
|
||||||
|
sysFile.setOssId(oss.getOssId());
|
||||||
|
sysFile.setName(uploadResult.getFilename());
|
||||||
|
sysFile.setUrl(uploadResult.getUrl());
|
||||||
|
sysFile.setOriginalName(uploadResult.getFilename());
|
||||||
|
sysFile.setFileSuffix(type);
|
||||||
|
return sysFile;
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("上传文件失败", e);
|
||||||
|
throw new ServiceException("上传文件失败");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user