|
@@ -22,7 +22,10 @@ import com.fdkankan.scene.mapper.ISceneUploadMapper;
|
|
|
import com.fdkankan.scene.service.ISceneProService;
|
|
|
import com.fdkankan.scene.service.ISceneUploadService;
|
|
|
import com.fdkankan.scene.vo.DeleteFileParamVO;
|
|
|
+import com.fdkankan.scene.vo.UploadContentParamVO;
|
|
|
import java.io.IOException;
|
|
|
+import java.nio.charset.Charset;
|
|
|
+import java.nio.charset.StandardCharsets;
|
|
|
import java.util.HashSet;
|
|
|
import java.util.Set;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
@@ -63,6 +66,9 @@ public class SceneUploadServiceImpl extends ServiceImpl<ISceneUploadMapper, Scen
|
|
|
@Value("${oss.bucket:4dkankan}")
|
|
|
private String bucket;
|
|
|
|
|
|
+ @Value("${oss.prefix.url}")
|
|
|
+ private String ossUrlPrefix;
|
|
|
+
|
|
|
@Autowired
|
|
|
private SSOLoginHelper ssoLoginHelper;
|
|
|
|
|
@@ -188,4 +194,24 @@ public class SceneUploadServiceImpl extends ServiceImpl<ISceneUploadMapper, Scen
|
|
|
this.save(sceneUpload);
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public String uploadContent(UploadContentParamVO param) throws Exception {
|
|
|
+
|
|
|
+ String ossPath = param.getOssPath();
|
|
|
+ String fileName = ossPath.substring(ossPath.lastIndexOf("/") + 1);
|
|
|
+ if(StrUtil.isEmpty(fileName)){
|
|
|
+ throw new BusinessException(ErrorCode.FAILURE_CODE_7012);
|
|
|
+ }
|
|
|
+ String suffix = fileName.substring(fileName.lastIndexOf("."));
|
|
|
+ if(StrUtil.isEmpty(suffix)){
|
|
|
+ throw new BusinessException(ErrorCode.FAILURE_CODE_7012);
|
|
|
+ }
|
|
|
+
|
|
|
+ File tempFile = File.createTempFile(UUID.randomUUID().toString(), suffix);
|
|
|
+ cn.hutool.core.io.FileUtil.writeString(param.getContent(), tempFile, StandardCharsets.UTF_8);
|
|
|
+ uploadToOssUtil.upload(tempFile.getPath(), param.getOssPath());
|
|
|
+ tempFile.deleteOnExit();
|
|
|
+
|
|
|
+ return this.ossUrlPrefix + param.getOssPath();
|
|
|
+ }
|
|
|
}
|