|
@@ -3,6 +3,9 @@ package com.yh.saas.platform.controller;
|
|
|
import ch.qos.logback.classic.Logger;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.alipay.sofa.runtime.api.annotation.SofaReference;
|
|
|
+import com.aliyun.oss.OSSClient;
|
|
|
+import com.aliyun.oss.model.ObjectMetadata;
|
|
|
+import com.aliyun.oss.model.PutObjectRequest;
|
|
|
import com.baomidou.mybatisplus.mapper.EntityWrapper;
|
|
|
import com.baomidou.mybatisplus.mapper.Wrapper;
|
|
|
import com.baomidou.mybatisplus.toolkit.CollectionUtils;
|
|
@@ -14,10 +17,13 @@ import com.winsea.svc.base.base.util.DateUtils;
|
|
|
import com.winsea.svc.base.base.view.CommonAppendixView;
|
|
|
import com.winsea.svc.base.security.util.AuthSecurityUtils;
|
|
|
import com.yh.saas.platform.util.GtAppendixUtil;
|
|
|
+import com.yh.saas.plugin.yiliangyiyun.util.GeneratorUtil;
|
|
|
import lombok.Getter;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.apache.tomcat.util.http.fileupload.util.Streams;
|
|
|
+import org.apache.velocity.shaded.commons.io.FilenameUtils;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
+import org.springframework.beans.factory.InitializingBean;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
@@ -44,7 +50,7 @@ import java.util.zip.ZipOutputStream;
|
|
|
*/
|
|
|
@RestController
|
|
|
@RequestMapping("/appendix")
|
|
|
-public class AppendixController {
|
|
|
+public class AppendixController implements InitializingBean {
|
|
|
|
|
|
private Logger log = (Logger) LoggerFactory.getLogger(this.getClass());
|
|
|
|
|
@@ -80,20 +86,27 @@ public class AppendixController {
|
|
|
|
|
|
static final String OSS_PERFIX_URL = "https://{0}.{1}/";
|
|
|
|
|
|
+ private String host;
|
|
|
+
|
|
|
+ @Getter
|
|
|
+ @Value("${oss.endpoint.internal:}")
|
|
|
+ private String baseUrl;
|
|
|
+ @Autowired
|
|
|
+ private OSSClient ossClient;
|
|
|
+ @Override
|
|
|
+ public void afterPropertiesSet() throws Exception {
|
|
|
+ host = "http://" + bucketName + "." + endpoint;
|
|
|
+ }
|
|
|
/**
|
|
|
* 查询附件
|
|
|
- *
|
|
|
- * @param billId
|
|
|
- * @param detailId
|
|
|
- * @param appendixType
|
|
|
* @return
|
|
|
*/
|
|
|
@GetMapping("/query/getFileList")
|
|
|
public List<CommonAppendix> getFileList(@RequestParam String appendixIds) {
|
|
|
List<CommonAppendix> list = appendixService.selectBatchIds(Arrays.asList(appendixIds.split(",")));
|
|
|
-// if (isOssUsed) {
|
|
|
-// addPrefix(list);
|
|
|
-// }
|
|
|
+ if (isOssUsed) {
|
|
|
+ addPrefix(list);
|
|
|
+ }
|
|
|
|
|
|
return list;
|
|
|
}
|
|
@@ -116,7 +129,6 @@ public class AppendixController {
|
|
|
/**
|
|
|
* 保存附件
|
|
|
*
|
|
|
- * @param ids
|
|
|
* @return
|
|
|
*/
|
|
|
@PostMapping("/api/saveFiles")
|
|
@@ -131,7 +143,6 @@ public class AppendixController {
|
|
|
/**
|
|
|
* 删除附件
|
|
|
*
|
|
|
- * @param ids
|
|
|
* @return
|
|
|
*/
|
|
|
@PostMapping("/api/deleteFiles")
|
|
@@ -233,25 +244,34 @@ public class AppendixController {
|
|
|
filePathSb.append(DateUtils.formatDate(new Date(), DateUtils.DATE_FMT_DATETIME));
|
|
|
// 添加后缀
|
|
|
filePathSb.append(file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf(".")));
|
|
|
- File dest = new File(fileRootPath + MessageFormat.format(filePathSb.toString(), fileName));
|
|
|
- if (!dest.getParentFile().exists()) { // 判断文件父目录是否存在
|
|
|
- dest.getParentFile().mkdirs();
|
|
|
- }
|
|
|
+// File dest = new File(fileRootPath + MessageFormat.format(filePathSb.toString(), fileName));
|
|
|
+// if (!dest.getParentFile().exists()) { // 判断文件父目录是否存在
|
|
|
+// dest.getParentFile().mkdirs();
|
|
|
+// }
|
|
|
try {
|
|
|
- Streams.copy(file.getInputStream(), new FileOutputStream(dest), true);
|
|
|
+// Streams.copy(file.getInputStream(), new FileOutputStream(dest), true);
|
|
|
+ ObjectMetadata objectMetadata = new ObjectMetadata();
|
|
|
+ objectMetadata.setContentLength(file.getSize());
|
|
|
+ objectMetadata.setContentType(file.getContentType());
|
|
|
+ String ext = FilenameUtils.getExtension(file.getOriginalFilename());
|
|
|
+ String uuid = GeneratorUtil.genFileName();
|
|
|
+ PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, "eliangeyun/" + uuid+"."+ext, file.getInputStream(), objectMetadata);
|
|
|
+ ossClient.putObject(putObjectRequest);
|
|
|
CommonAppendix appendix = new CommonAppendix();
|
|
|
appendix.setAppendixName(
|
|
|
fileName + file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf(".")));
|
|
|
- String path = MessageFormat.format(filePathSb.toString(),
|
|
|
- URLEncoder.encode(fileName, String.valueOf(StandardCharsets.UTF_8)));
|
|
|
+ String path = baseUrl + "eliangeyun/" + uuid +"."+ext;
|
|
|
appendix.setAppendixPath(path.replace("+", "%20"));
|
|
|
int size = (int) file.getSize();
|
|
|
appendix.setAppendixSize(GtAppendixUtil.getFileSize(size));
|
|
|
+ log.info("文件上传成功 地址:", path);
|
|
|
return appendix;
|
|
|
} catch (Exception e) {
|
|
|
- if (dest.delete()) {
|
|
|
- log.error("文件上传失败", e);
|
|
|
- }
|
|
|
+ log.error("文件上传失败", e);
|
|
|
+ }
|
|
|
+ finally {
|
|
|
+
|
|
|
+// dest.delete();
|
|
|
}
|
|
|
}
|
|
|
return null;
|
|
@@ -315,7 +335,6 @@ public class AppendixController {
|
|
|
* 查询要打包的附件
|
|
|
*
|
|
|
* @param billIds
|
|
|
- * @param detailId
|
|
|
* @return
|
|
|
*/
|
|
|
private List<CommonAppendix> selectAppendixList(String billIds) {
|