同步代码

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;
/**
* 查询告警
*
@ -154,10 +156,8 @@ public class SisAlarmEventsServiceImpl implements ISisAlarmEventsService {
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 {
public RemoteFile uploadImg(byte[] file) throws ServiceException {
try {
// 计算文件类型
String type = Base64Utils.getType(file);
// 获contentType
return null;
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("上传文件失败");
}
}
/**