|
@@ -9,8 +9,8 @@ import cn.reghao.oss.sdk.model.dto.media.ImageInfo;
|
|
|
import cn.reghao.oss.sdk.model.rest.UploadFileRet;
|
|
import cn.reghao.oss.sdk.model.rest.UploadFileRet;
|
|
|
import cn.reghao.oss.sdk.OssConsoleClient;
|
|
import cn.reghao.oss.sdk.OssConsoleClient;
|
|
|
import cn.reghao.oss.sdk.OssStoreClient;
|
|
import cn.reghao.oss.sdk.OssStoreClient;
|
|
|
|
|
+import cn.reghao.tnb.file.app.config.AppProperties;
|
|
|
import cn.reghao.tnb.file.app.config.OssConsoleClientFactory;
|
|
import cn.reghao.tnb.file.app.config.OssConsoleClientFactory;
|
|
|
-import cn.reghao.tnb.file.app.config.OssProperties;
|
|
|
|
|
import cn.reghao.tnb.file.app.db.mapper.JobDetailMapper;
|
|
import cn.reghao.tnb.file.app.db.mapper.JobDetailMapper;
|
|
|
import cn.reghao.tnb.file.app.model.po.JobDetail;
|
|
import cn.reghao.tnb.file.app.model.po.JobDetail;
|
|
|
import cn.reghao.tnb.file.app.service.ConvertService;
|
|
import cn.reghao.tnb.file.app.service.ConvertService;
|
|
@@ -18,6 +18,7 @@ import cn.reghao.tnb.file.app.util.ImageUtil;
|
|
|
import cn.reghao.tnb.file.app.model.constant.OssType;
|
|
import cn.reghao.tnb.file.app.model.constant.OssType;
|
|
|
import org.apache.commons.io.FileUtils;
|
|
import org.apache.commons.io.FileUtils;
|
|
|
import org.apache.dubbo.config.annotation.DubboService;
|
|
import org.apache.dubbo.config.annotation.DubboService;
|
|
|
|
|
+import org.springframework.boot.autoconfigure.web.ServerProperties;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
import java.io.ByteArrayOutputStream;
|
|
import java.io.ByteArrayOutputStream;
|
|
@@ -36,30 +37,34 @@ public class FileServiceImpl implements FileService {
|
|
|
private final OssConsoleClientFactory ossConsoleClientFactory;
|
|
private final OssConsoleClientFactory ossConsoleClientFactory;
|
|
|
private final int ossType;
|
|
private final int ossType;
|
|
|
private final ConvertService convertService;
|
|
private final ConvertService convertService;
|
|
|
- private JobDetailMapper jobDetailMapper;
|
|
|
|
|
|
|
+ private final JobDetailMapper jobDetailMapper;
|
|
|
|
|
+ private final String baseDir;
|
|
|
|
|
+ private final AppProperties appProperties;
|
|
|
|
|
|
|
|
- private FileServiceImpl(OssProperties ossProperties, OssConsoleClientFactory ossConsoleClientFactory,
|
|
|
|
|
- ConvertService convertService, JobDetailMapper jobDetailMapper) {
|
|
|
|
|
|
|
+ private FileServiceImpl(OssConsoleClientFactory ossConsoleClientFactory, ConvertService convertService,
|
|
|
|
|
+ JobDetailMapper jobDetailMapper, ServerProperties serverProperties,
|
|
|
|
|
+ AppProperties appProperties) {
|
|
|
this.ossConsoleClientFactory = ossConsoleClientFactory;
|
|
this.ossConsoleClientFactory = ossConsoleClientFactory;
|
|
|
- this.ossType = ossProperties.getOssType();
|
|
|
|
|
|
|
+ this.ossType = appProperties.getOssType();
|
|
|
this.convertService = convertService;
|
|
this.convertService = convertService;
|
|
|
this.jobDetailMapper = jobDetailMapper;
|
|
this.jobDetailMapper = jobDetailMapper;
|
|
|
|
|
+ this.baseDir = serverProperties.getTomcat().getBasedir().getAbsolutePath();
|
|
|
|
|
+ this.appProperties = appProperties;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public String getAccountAvatar(long userId) {
|
|
public String getAccountAvatar(long userId) {
|
|
|
- String avatarUrl = "//picx.zhimg.com/v2-abed1a8c04700ba7d72b45195223e0ff_xl.jpg";
|
|
|
|
|
- String text = String.format("https://tnb.reghao.cn/user/%s", userId);
|
|
|
|
|
|
|
+ String text = String.format("%s/user/%s", appProperties.getSiteAddress(), userId);
|
|
|
int width = 256;
|
|
int width = 256;
|
|
|
int height = 256;
|
|
int height = 256;
|
|
|
- String filePath = String.format("/opt/tmp/%s.jpg", userId);
|
|
|
|
|
|
|
+ String filePath = String.format("%s/%s.jpg", baseDir, userId);
|
|
|
|
|
+ String avatarUrl = "";
|
|
|
try {
|
|
try {
|
|
|
ByteArrayOutputStream baos = ImageUtil.createQRCode(text, width, height);
|
|
ByteArrayOutputStream baos = ImageUtil.createQRCode(text, width, height);
|
|
|
- int channelId = 103;
|
|
|
|
|
-
|
|
|
|
|
|
|
+ int channelCode = appProperties.getAvatarChannelCode();
|
|
|
File file = new File(filePath);
|
|
File file = new File(filePath);
|
|
|
FileUtils.writeByteArrayToFile(file, baos.toByteArray());
|
|
FileUtils.writeByteArrayToFile(file, baos.toByteArray());
|
|
|
if (ossType == OssType.localOss.getCode()) {
|
|
if (ossType == OssType.localOss.getCode()) {
|
|
|
- avatarUrl = getImageUrl(channelId, file);
|
|
|
|
|
|
|
+ avatarUrl = getImageUrl(channelCode, file);
|
|
|
}
|
|
}
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
@@ -70,9 +75,9 @@ public class FileServiceImpl implements FileService {
|
|
|
return avatarUrl;
|
|
return avatarUrl;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- private String getImageUrl(int channelId, File file) throws Exception {
|
|
|
|
|
|
|
+ private String getImageUrl(int channelCode, File file) throws Exception {
|
|
|
OssConsoleClient ossConsoleClient = ossConsoleClientFactory.getOssConsoleClient();
|
|
OssConsoleClient ossConsoleClient = ossConsoleClientFactory.getOssConsoleClient();
|
|
|
- ServerInfo serverInfo = ossConsoleClient.getUploadStore(channelId);
|
|
|
|
|
|
|
+ ServerInfo serverInfo = ossConsoleClient.getUploadStore(channelCode);
|
|
|
if (serverInfo == null) {
|
|
if (serverInfo == null) {
|
|
|
return null;
|
|
return null;
|
|
|
}
|
|
}
|
|
@@ -80,10 +85,10 @@ public class FileServiceImpl implements FileService {
|
|
|
String ossUrl = serverInfo.getOssUrl();
|
|
String ossUrl = serverInfo.getOssUrl();
|
|
|
String token = serverInfo.getToken();
|
|
String token = serverInfo.getToken();
|
|
|
OssStoreClient ossStoreClient = new OssStoreClient(ossUrl);
|
|
OssStoreClient ossStoreClient = new OssStoreClient(ossUrl);
|
|
|
- UploadFileRet uploadFileRet = ossStoreClient.postObject(file, channelId, token);
|
|
|
|
|
|
|
+ UploadFileRet uploadFileRet = ossStoreClient.postObject(file, channelCode, token);
|
|
|
if (uploadFileRet != null) {
|
|
if (uploadFileRet != null) {
|
|
|
String uploadId = uploadFileRet.getUploadId();
|
|
String uploadId = uploadFileRet.getUploadId();
|
|
|
- ImageInfo imageInfo = ossConsoleClient.getImageInfo(channelId, uploadId);
|
|
|
|
|
|
|
+ ImageInfo imageInfo = ossConsoleClient.getImageInfo(channelCode, uploadId);
|
|
|
if (imageInfo != null) {
|
|
if (imageInfo != null) {
|
|
|
return imageInfo.getUrl();
|
|
return imageInfo.getUrl();
|
|
|
}
|
|
}
|