同步代码

This commit is contained in:
lxj 2025-08-04 20:00:51 +08:00
parent 291f9e7ffa
commit 58971070e9
4 changed files with 47 additions and 23 deletions

View File

@ -27,7 +27,7 @@ public interface RemoteFileService {
* @return 结果
* @throws ServiceException
*/
RemoteFile upload(byte[] file) throws ServiceException;
RemoteFile uploadImg(byte[] file) throws ServiceException;
/**
* 通过ossId查询对应的url

View File

@ -30,7 +30,13 @@ public enum ContentTypeEnum {
/**
* 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 contentType;
@ -41,13 +47,13 @@ public enum ContentTypeEnum {
* @param extension 文件扩展名
* @return 对应的内容类型如果未找到则返回null
*/
public static String getContentType(String extension) {
public static ContentTypeEnum ContentTypeEnum(String extension) {
for (ContentTypeEnum type : values()) {
if (type.extension.equalsIgnoreCase(extension)) {
return type.contentType;
return type;
}
}
return null;
return JPG;
}
/**

View File

@ -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.TableDataInfo;
import org.dromara.resource.api.RemoteFileService;
import org.dromara.resource.api.domain.RemoteFile;
import org.dromara.sis.domain.SisAlarmEvents;
import org.dromara.sis.domain.bo.SisAlarmEventsBo;
import org.dromara.sis.domain.vo.SisAlarmEventsVo;
@ -41,6 +42,7 @@ public class SisAlarmEventsServiceImpl implements ISisAlarmEventsService {
@DubboReference
private RemoteFileService remoteFileService;
/**
* 查询告警
*
@ -48,7 +50,7 @@ public class SisAlarmEventsServiceImpl implements ISisAlarmEventsService {
* @return 告警
*/
@Override
public SisAlarmEventsVo queryById(Long id){
public SisAlarmEventsVo queryById(Long 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 做一些数据校验,如唯一约束
}
@ -138,7 +140,7 @@ public class SisAlarmEventsServiceImpl implements ISisAlarmEventsService {
*/
@Override
public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
if(isValid){
if (isValid) {
//TODO 做一些业务上的校验,判断是否需要校验
}
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) {
// 校验设备信息
SisDeviceManageVo sisDeviceManageVo = deviceManageService.queryVoByDeviceIp(deviceIp);
if(sisDeviceManageVo == null){
if (sisDeviceManageVo == null) {
log.error("设备信息不存在,放弃此条告警记录。");
return;
}
// 上传图片
remoteFileService.upload(smallImg);
RemoteFile small = remoteFileService.uploadImg(smallImg);
RemoteFile big = remoteFileService.uploadImg(bigImg);
}

View File

@ -5,6 +5,7 @@ import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
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.utils.Base64Utils;
import org.dromara.common.core.utils.MapstructUtils;
@ -68,16 +69,33 @@ public class RemoteFileServiceImpl implements RemoteFileService {
}
@Override
public RemoteFile upload(byte[] file) throws ServiceException {
// 计算文件类型
String type = Base64Utils.getType(file);
// 获contentType
return null;
public RemoteFile uploadImg(byte[] file) throws ServiceException {
try {
// 计算文件类型
String type = Base64Utils.getType(file);
// 获contentType
ContentTypeEnum contentTypeEnum = ContentTypeEnum.ContentTypeEnum(type);
OssClient storage = OssFactory.instance();
UploadResult uploadResult = storage.uploadSuffix(file, type, contentTypeEnum.getContentType());
// 保存文件信息
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("上传文件失败");
}
}
/**