1. 修改 项目结构, oss 添加是否添加水印相关
This commit is contained in:
parent
88b5dfc714
commit
5073453f18
|
|
@ -1,5 +1,7 @@
|
||||||
package com.chushang.common.core.util;
|
package com.chushang.common.core.util;
|
||||||
|
|
||||||
|
import cn.hutool.core.collection.CollectionUtil;
|
||||||
|
import cn.hutool.core.img.Img;
|
||||||
import cn.hutool.core.io.FileUtil;
|
import cn.hutool.core.io.FileUtil;
|
||||||
import cn.hutool.crypto.SecureUtil;
|
import cn.hutool.crypto.SecureUtil;
|
||||||
import cn.hutool.crypto.digest.MD5;
|
import cn.hutool.crypto.digest.MD5;
|
||||||
|
|
@ -9,15 +11,17 @@ import org.apache.commons.io.IOUtils;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import javax.imageio.ImageIO;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.awt.*;
|
||||||
|
import java.awt.image.BufferedImage;
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.security.MessageDigest;
|
import java.util.List;
|
||||||
import java.security.NoSuchAlgorithmException;
|
|
||||||
|
|
||||||
public class FileUtils extends FileUtil {
|
public class FileUtils extends FileUtil {
|
||||||
private static final Logger log = LoggerFactory.getLogger(FileUtils.class);
|
private static final Logger log = LoggerFactory.getLogger(FileUtils.class);
|
||||||
|
|
@ -269,5 +273,23 @@ public class FileUtils extends FileUtil {
|
||||||
return IOUtils.toString(() -> Files.newInputStream(file.toPath()), Charsets.toCharset(charsetName));
|
return IOUtils.toString(() -> Files.newInputStream(file.toPath()), Charsets.toCharset(charsetName));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// /**
|
||||||
|
// * 添加水印
|
||||||
|
// *
|
||||||
|
// * @param formats 水印名
|
||||||
|
// * @param img 图片
|
||||||
|
// */
|
||||||
|
public static InputStream waterSeal(List<String> formats, InputStream inputStream) {
|
||||||
|
try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
|
||||||
|
for (int i = 0; i < formats.size(); i++) {
|
||||||
|
Img.from(ImageIO.read(inputStream)).setPositionBaseCentre(true)
|
||||||
|
.pressText(formats.get(i), Color.red, new Font("微软雅黑", Font.BOLD, 45), 0, (i + 1) * 30, 0.8f)
|
||||||
|
.write(outputStream);
|
||||||
|
}
|
||||||
|
outputStream.flush();
|
||||||
|
return new ByteArrayInputStream(outputStream.toByteArray());
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -228,7 +228,6 @@ public class IPUtils {
|
||||||
log.debug("request.getRemoteAddr() ==>" + ip);
|
log.debug("request.getRemoteAddr() ==>" + ip);
|
||||||
}
|
}
|
||||||
|
|
||||||
log.info("RealRemoteIP ==>" + ip);
|
|
||||||
return "0:0:0:0:0:0:0:1".equals(ip) ? "127.0.0.1" : ip;
|
return "0:0:0:0:0:0:0:1".equals(ip) ? "127.0.0.1" : ip;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -274,7 +273,6 @@ public class IPUtils {
|
||||||
log.debug("request.getRemoteAddr() ==>" + ip);
|
log.debug("request.getRemoteAddr() ==>" + ip);
|
||||||
}
|
}
|
||||||
|
|
||||||
log.info("RealRemoteIP ==>" + ip);
|
|
||||||
return "0:0:0:0:0:0:0:1".equals(ip) ? "127.0.0.1" : ip;
|
return "0:0:0:0:0:0:0:1".equals(ip) ? "127.0.0.1" : ip;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -51,11 +51,60 @@
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
<plugins>
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-jar-plugin</artifactId>
|
||||||
|
<version>3.3.0</version>
|
||||||
|
<configuration>
|
||||||
|
<excludes>
|
||||||
|
<exclude>**/application.yml</exclude>
|
||||||
|
<exclude>**/bootstrap.yml</exclude>
|
||||||
|
<exclude>**/logback-nacos.xml</exclude>
|
||||||
|
</excludes>
|
||||||
|
<archive>
|
||||||
|
<manifest>
|
||||||
|
<addClasspath>true</addClasspath>
|
||||||
|
<!-- MANIFEST.MF 中 Class-Path 加入前缀 -->
|
||||||
|
<classpathPrefix>lib/</classpathPrefix>
|
||||||
|
<!-- jar包不包含唯一版本标识 -->
|
||||||
|
<useUniqueVersions>false</useUniqueVersions>
|
||||||
|
<!--指定入口类 -->
|
||||||
|
<mainClass>com.chushang.AuthApplication</mainClass>
|
||||||
|
</manifest>
|
||||||
|
<manifestEntries>
|
||||||
|
<!--MANIFEST.MF 中 Class-Path 加入资源文件目录 -->
|
||||||
|
<Class-Path>./config/</Class-Path>
|
||||||
|
</manifestEntries>
|
||||||
|
</archive>
|
||||||
|
<outputDirectory>${project.build.directory}</outputDirectory>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-surefire-plugin</artifactId>
|
||||||
|
<configuration>
|
||||||
|
<skipTests>true</skipTests>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||||
|
<configuration>
|
||||||
|
<finalName>${project.build.finalName}</finalName>
|
||||||
|
<layers>
|
||||||
|
<enabled>true</enabled>
|
||||||
|
</layers>
|
||||||
|
</configuration>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<goals>
|
||||||
|
<goal>repackage</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
</plugin>
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
|
<finalName>${project.artifactId}</finalName>
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
|
|
||||||
|
|
@ -76,11 +76,60 @@
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
<plugins>
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-jar-plugin</artifactId>
|
||||||
|
<version>3.3.0</version>
|
||||||
|
<configuration>
|
||||||
|
<excludes>
|
||||||
|
<exclude>**/application.yml</exclude>
|
||||||
|
<exclude>**/bootstrap.yml</exclude>
|
||||||
|
<exclude>**/logback-nacos.xml</exclude>
|
||||||
|
</excludes>
|
||||||
|
<archive>
|
||||||
|
<manifest>
|
||||||
|
<addClasspath>true</addClasspath>
|
||||||
|
<!-- MANIFEST.MF 中 Class-Path 加入前缀 -->
|
||||||
|
<classpathPrefix>lib/</classpathPrefix>
|
||||||
|
<!-- jar包不包含唯一版本标识 -->
|
||||||
|
<useUniqueVersions>false</useUniqueVersions>
|
||||||
|
<!--指定入口类 -->
|
||||||
|
<mainClass>com.chushang.GatewayApplication</mainClass>
|
||||||
|
</manifest>
|
||||||
|
<manifestEntries>
|
||||||
|
<!--MANIFEST.MF 中 Class-Path 加入资源文件目录 -->
|
||||||
|
<Class-Path>./config/</Class-Path>
|
||||||
|
</manifestEntries>
|
||||||
|
</archive>
|
||||||
|
<outputDirectory>${project.build.directory}</outputDirectory>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-surefire-plugin</artifactId>
|
||||||
|
<configuration>
|
||||||
|
<skipTests>true</skipTests>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||||
|
<configuration>
|
||||||
|
<finalName>${project.build.finalName}</finalName>
|
||||||
|
<layers>
|
||||||
|
<enabled>true</enabled>
|
||||||
|
</layers>
|
||||||
|
</configuration>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<goals>
|
||||||
|
<goal>repackage</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
</plugin>
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
|
<finalName>${project.artifactId}</finalName>
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
|
|
||||||
|
|
@ -26,10 +26,59 @@
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
<plugins>
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-jar-plugin</artifactId>
|
||||||
|
<version>3.3.0</version>
|
||||||
|
<configuration>
|
||||||
|
<excludes>
|
||||||
|
<exclude>**/application.yml</exclude>
|
||||||
|
<exclude>**/bootstrap.yml</exclude>
|
||||||
|
<exclude>**/logback-nacos.xml</exclude>
|
||||||
|
</excludes>
|
||||||
|
<archive>
|
||||||
|
<manifest>
|
||||||
|
<addClasspath>true</addClasspath>
|
||||||
|
<!-- MANIFEST.MF 中 Class-Path 加入前缀 -->
|
||||||
|
<classpathPrefix>lib/</classpathPrefix>
|
||||||
|
<!-- jar包不包含唯一版本标识 -->
|
||||||
|
<useUniqueVersions>false</useUniqueVersions>
|
||||||
|
<!--指定入口类 -->
|
||||||
|
<mainClass>com.chushang.OssApplication</mainClass>
|
||||||
|
</manifest>
|
||||||
|
<manifestEntries>
|
||||||
|
<!--MANIFEST.MF 中 Class-Path 加入资源文件目录 -->
|
||||||
|
<Class-Path>./config/</Class-Path>
|
||||||
|
</manifestEntries>
|
||||||
|
</archive>
|
||||||
|
<outputDirectory>${project.build.directory}</outputDirectory>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-surefire-plugin</artifactId>
|
||||||
|
<configuration>
|
||||||
|
<skipTests>true</skipTests>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||||
|
<configuration>
|
||||||
|
<finalName>${project.build.finalName}</finalName>
|
||||||
|
<layers>
|
||||||
|
<enabled>true</enabled>
|
||||||
|
</layers>
|
||||||
|
</configuration>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<goals>
|
||||||
|
<goal>repackage</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
</plugin>
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
|
<finalName>${project.artifactId}</finalName>
|
||||||
</build>
|
</build>
|
||||||
</project>
|
</project>
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package com.chushang.oss;
|
package com.chushang;
|
||||||
|
|
||||||
import com.chushang.common.core.enums.AppStartType;
|
import com.chushang.common.core.enums.AppStartType;
|
||||||
import com.chushang.common.feign.annotation.EnableOnnFeignClients;
|
import com.chushang.common.feign.annotation.EnableOnnFeignClients;
|
||||||
|
|
@ -40,11 +40,13 @@ public class FileController {
|
||||||
@SysLog(value = "文件上传", businessType = BusinessType.INSERT)
|
@SysLog(value = "文件上传", businessType = BusinessType.INSERT)
|
||||||
@PostMapping(value = "/upload")
|
@PostMapping(value = "/upload")
|
||||||
public AjaxResult uploadFile(@RequestParam(value = "files") MultipartFile[] files,
|
public AjaxResult uploadFile(@RequestParam(value = "files") MultipartFile[] files,
|
||||||
@RequestParam(value = "ocrType", required = false) String ocrType)
|
@RequestParam(value = "ocrType", required = false) String ocrType,
|
||||||
|
@RequestParam(value = "sealFlag", required = false, defaultValue= "false") Boolean sealFlag,
|
||||||
|
@RequestParam(value = "formats", required = false) String formats)
|
||||||
{
|
{
|
||||||
List<FileSourceVo> result = new ArrayList<>();
|
List<FileSourceVo> result = new ArrayList<>();
|
||||||
for (MultipartFile file : files) {
|
for (MultipartFile file : files) {
|
||||||
FileSourceVo info = fileSourceService.addFile(file);
|
FileSourceVo info = fileSourceService.addFile(file, sealFlag, formats);
|
||||||
if (StrUtil.isNotEmpty(ocrType)) {
|
if (StrUtil.isNotEmpty(ocrType)) {
|
||||||
OcrDTO ocr = new OcrDTO();
|
OcrDTO ocr = new OcrDTO();
|
||||||
OcrTypeEnum ocrTypeEnum = OcrTypeEnum.findByCode(ocrType);
|
OcrTypeEnum ocrTypeEnum = OcrTypeEnum.findByCode(ocrType);
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,6 @@ import com.chushang.common.core.util.FileUtils;
|
||||||
import com.chushang.common.core.util.IPUtils;
|
import com.chushang.common.core.util.IPUtils;
|
||||||
import com.chushang.common.core.util.ServletUtils;
|
import com.chushang.common.core.util.ServletUtils;
|
||||||
import com.chushang.common.mybatis.enums.Operator;
|
import com.chushang.common.mybatis.enums.Operator;
|
||||||
import com.chushang.oss.config.UploadConfig;
|
|
||||||
import com.chushang.oss.entity.FileSourceInfo;
|
import com.chushang.oss.entity.FileSourceInfo;
|
||||||
import com.chushang.oss.entity.vo.FileSourceVo;
|
import com.chushang.oss.entity.vo.FileSourceVo;
|
||||||
import com.chushang.oss.mapper.FileSourceMapper;
|
import com.chushang.oss.mapper.FileSourceMapper;
|
||||||
|
|
@ -32,7 +31,6 @@ import javax.annotation.Resource;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.time.ZonedDateTime;
|
import java.time.ZonedDateTime;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -61,9 +59,11 @@ public class FileSourceService
|
||||||
/**
|
/**
|
||||||
* 上传 到minio 或者 oss 服务中
|
* 上传 到minio 或者 oss 服务中
|
||||||
*
|
*
|
||||||
* @param file 文件
|
* @param file 文件
|
||||||
|
* @param sealFlag
|
||||||
|
* @param formats
|
||||||
*/
|
*/
|
||||||
public FileSourceVo addFile(MultipartFile file) {
|
public FileSourceVo addFile(MultipartFile file, Boolean sealFlag, String formats) {
|
||||||
String ip = IPUtils.clientIp(ServletUtils.getRequest());
|
String ip = IPUtils.clientIp(ServletUtils.getRequest());
|
||||||
String fid = generateFid();
|
String fid = generateFid();
|
||||||
String fName = file.getOriginalFilename();
|
String fName = file.getOriginalFilename();
|
||||||
|
|
@ -94,7 +94,7 @@ public class FileSourceService
|
||||||
info.setStorage(storage);
|
info.setStorage(storage);
|
||||||
info.setUploadIp(ip);
|
info.setUploadIp(ip);
|
||||||
// 上传到 oss 或者 minio
|
// 上传到 oss 或者 minio
|
||||||
String realPath = ossService.upload(file.getInputStream(), info);
|
String realPath = ossService.upload(file.getBytes(), info, sealFlag, formats);
|
||||||
// 带https 的路径
|
// 带https 的路径
|
||||||
info.setRealPath(realPath);
|
info.setRealPath(realPath);
|
||||||
RMap<String, FileSourceInfo> map = redissonClient.getMap("OSS-Cache");
|
RMap<String, FileSourceInfo> map = redissonClient.getMap("OSS-Cache");
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,14 @@
|
||||||
package com.chushang.oss.service;
|
package com.chushang.oss.service;
|
||||||
|
|
||||||
|
import com.chushang.common.core.exception.ResultException;
|
||||||
|
import com.chushang.common.core.util.FileUtils;
|
||||||
import com.chushang.common.core.util.IdUtils;
|
import com.chushang.common.core.util.IdUtils;
|
||||||
|
import com.chushang.common.core.util.StringUtils;
|
||||||
import com.chushang.oss.entity.FileSourceInfo;
|
import com.chushang.oss.entity.FileSourceInfo;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public interface OssService {
|
public interface OssService {
|
||||||
|
|
@ -20,16 +24,23 @@ public interface OssService {
|
||||||
* @param info 文件信息
|
* @param info 文件信息
|
||||||
* @return 返回http地址
|
* @return 返回http地址
|
||||||
*/
|
*/
|
||||||
default String upload(byte[] data, FileSourceInfo info){
|
default String upload(byte[] data, FileSourceInfo info, Boolean sealFlag, String formats){
|
||||||
return upload(new ByteArrayInputStream(data), info);
|
InputStream inputStream = new ByteArrayInputStream(data);
|
||||||
|
// 为true 时 添加水印
|
||||||
|
if (sealFlag){
|
||||||
|
if (StringUtils.isEmpty(formats)) throw new ResultException("添加水印时, 水印内容不能为空");
|
||||||
|
inputStream = FileUtils.waterSeal(Arrays.stream(formats.split(",")).toList(), inputStream);
|
||||||
|
}
|
||||||
|
return upload(inputStream, info);
|
||||||
}
|
}
|
||||||
String getPrefixPath(String prefix, String filename);
|
String getPrefixPath(String prefix, String filename);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 文件上传
|
* 文件上传
|
||||||
* @param inputStream 文件字节数组
|
*
|
||||||
* @param info 文件信息
|
* @param inputStream 文件字节数组
|
||||||
* @return 返回http地址
|
* @param info 文件信息
|
||||||
|
* @return 返回http地址
|
||||||
*/
|
*/
|
||||||
String upload(InputStream inputStream, FileSourceInfo info);
|
String upload(InputStream inputStream, FileSourceInfo info);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,12 +7,10 @@ import com.aliyun.oss.model.DeleteObjectsRequest;
|
||||||
import com.aliyun.oss.model.DeleteObjectsResult;
|
import com.aliyun.oss.model.DeleteObjectsResult;
|
||||||
import com.aliyun.oss.model.OSSObject;
|
import com.aliyun.oss.model.OSSObject;
|
||||||
import com.aliyun.oss.model.Payer;
|
import com.aliyun.oss.model.Payer;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
||||||
import com.chushang.common.core.exception.ResultException;
|
import com.chushang.common.core.exception.ResultException;
|
||||||
import com.chushang.common.core.util.StringUtils;
|
import com.chushang.common.core.util.StringUtils;
|
||||||
import com.chushang.oss.config.UploadConfig;
|
import com.chushang.oss.config.UploadConfig;
|
||||||
import com.chushang.oss.entity.FileSourceInfo;
|
import com.chushang.oss.entity.FileSourceInfo;
|
||||||
import com.chushang.oss.mapper.FileSourceMapper;
|
|
||||||
import com.chushang.oss.service.OssService;
|
import com.chushang.oss.service.OssService;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
|
||||||
|
|
@ -20,9 +18,7 @@ import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import javax.annotation.PostConstruct;
|
import javax.annotation.PostConstruct;
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.io.ByteArrayInputStream;
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.OutputStream;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,15 @@
|
||||||
package com.chushang.oss.service.impl;
|
package com.chushang.oss.service.impl;
|
||||||
|
|
||||||
|
import cn.hutool.core.io.IoUtil;
|
||||||
|
import cn.hutool.core.io.resource.ResourceUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import com.chushang.common.core.exception.ResultException;
|
import com.chushang.common.core.exception.ResultException;
|
||||||
|
import com.chushang.common.core.util.FileUtils;
|
||||||
import com.chushang.common.core.util.StringUtils;
|
import com.chushang.common.core.util.StringUtils;
|
||||||
import com.chushang.oss.config.UploadConfig;
|
import com.chushang.oss.config.UploadConfig;
|
||||||
import com.chushang.oss.entity.FileSourceInfo;
|
import com.chushang.oss.entity.FileSourceInfo;
|
||||||
import com.chushang.oss.service.OssService;
|
import com.chushang.oss.service.OssService;
|
||||||
import io.minio.*;
|
import io.minio.*;
|
||||||
import io.minio.errors.*;
|
|
||||||
import io.minio.messages.Bucket;
|
import io.minio.messages.Bucket;
|
||||||
import io.minio.messages.DeleteError;
|
import io.minio.messages.DeleteError;
|
||||||
import io.minio.messages.DeleteObject;
|
import io.minio.messages.DeleteObject;
|
||||||
|
|
@ -18,14 +20,12 @@ import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import javax.annotation.PostConstruct;
|
import javax.annotation.PostConstruct;
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
import java.awt.*;
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.OutputStream;
|
|
||||||
import java.lang.module.ResolutionException;
|
|
||||||
import java.security.InvalidKeyException;
|
|
||||||
import java.security.NoSuchAlgorithmException;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -40,22 +40,27 @@ public class MinioServiceImpl implements OssService {
|
||||||
private MinioClient minio;
|
private MinioClient minio;
|
||||||
@Resource
|
@Resource
|
||||||
private UploadConfig config;
|
private UploadConfig config;
|
||||||
|
|
||||||
@PostConstruct
|
@PostConstruct
|
||||||
public void init() {
|
public void init() {
|
||||||
minio = MinioClient.builder().endpoint(config.getEndPoint())
|
minio = MinioClient.builder().endpoint(config.getEndPoint())
|
||||||
.credentials(config.getAccessKey(), config.getSecretKey()).build();
|
.credentials(config.getAccessKey(), config.getSecretKey()).build();
|
||||||
try {
|
try {
|
||||||
if (!minio.bucketExists(BucketExistsArgs.builder().bucket(config.getBucketName()).build())) {
|
if (!minio.bucketExists(BucketExistsArgs.builder().bucket(config.getBucketName()).build())) {
|
||||||
|
log.info("createBucket {}", config.getBucketName());
|
||||||
createBucket();
|
createBucket();
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("MinIO Storage Connection Fail");
|
log.error("MinIO Storage Connection Fail");
|
||||||
}
|
}
|
||||||
|
log.info("createFont ");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建minio bucket
|
||||||
|
*/
|
||||||
@SneakyThrows
|
@SneakyThrows
|
||||||
private void createBucket(){
|
private void createBucket()
|
||||||
|
{
|
||||||
String bucketName = config.getBucketName();
|
String bucketName = config.getBucketName();
|
||||||
|
|
||||||
// 注意 minio通过nginx代理后无法判断桶是否存在 需要通过查询所有桶的形式
|
// 注意 minio通过nginx代理后无法判断桶是否存在 需要通过查询所有桶的形式
|
||||||
|
|
|
||||||
|
|
@ -30,11 +30,60 @@
|
||||||
</dependencies>
|
</dependencies>
|
||||||
<build>
|
<build>
|
||||||
<plugins>
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-jar-plugin</artifactId>
|
||||||
|
<version>3.3.0</version>
|
||||||
|
<configuration>
|
||||||
|
<excludes>
|
||||||
|
<exclude>**/application.yml</exclude>
|
||||||
|
<exclude>**/bootstrap.yml</exclude>
|
||||||
|
<exclude>**/logback-nacos.xml</exclude>
|
||||||
|
</excludes>
|
||||||
|
<archive>
|
||||||
|
<manifest>
|
||||||
|
<addClasspath>true</addClasspath>
|
||||||
|
<!-- MANIFEST.MF 中 Class-Path 加入前缀 -->
|
||||||
|
<classpathPrefix>lib/</classpathPrefix>
|
||||||
|
<!-- jar包不包含唯一版本标识 -->
|
||||||
|
<useUniqueVersions>false</useUniqueVersions>
|
||||||
|
<!--指定入口类 -->
|
||||||
|
<mainClass>com.chushang.SystemApplication</mainClass>
|
||||||
|
</manifest>
|
||||||
|
<manifestEntries>
|
||||||
|
<!--MANIFEST.MF 中 Class-Path 加入资源文件目录 -->
|
||||||
|
<Class-Path>./config/</Class-Path>
|
||||||
|
</manifestEntries>
|
||||||
|
</archive>
|
||||||
|
<outputDirectory>${project.build.directory}</outputDirectory>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-surefire-plugin</artifactId>
|
||||||
|
<configuration>
|
||||||
|
<skipTests>true</skipTests>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||||
|
<configuration>
|
||||||
|
<finalName>${project.build.finalName}</finalName>
|
||||||
|
<layers>
|
||||||
|
<enabled>true</enabled>
|
||||||
|
</layers>
|
||||||
|
</configuration>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<goals>
|
||||||
|
<goal>repackage</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
</plugin>
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
|
<finalName>${project.artifactId}</finalName>
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package com.chushang.system;
|
package com.chushang;
|
||||||
|
|
||||||
import com.chushang.common.core.enums.AppStartType;
|
import com.chushang.common.core.enums.AppStartType;
|
||||||
import com.chushang.common.feign.annotation.EnableOnnFeignClients;
|
import com.chushang.common.feign.annotation.EnableOnnFeignClients;
|
||||||
|
|
@ -1,11 +1,8 @@
|
||||||
import cn.hutool.core.collection.CollectionUtil;
|
|
||||||
import cn.hutool.json.JSONUtil;
|
import cn.hutool.json.JSONUtil;
|
||||||
import com.chushang.common.core.util.StringUtils;
|
|
||||||
import com.chushang.security.service.TokenService;
|
import com.chushang.security.service.TokenService;
|
||||||
import com.chushang.system.SystemApplication;
|
import com.chushang.SystemApplication;
|
||||||
import com.chushang.system.entity.po.SysMenu;
|
import com.chushang.system.entity.po.SysMenu;
|
||||||
import com.chushang.system.entity.po.SysUser;
|
import com.chushang.system.entity.po.SysUser;
|
||||||
import com.chushang.security.entity.vo.LoginUser;
|
|
||||||
import com.chushang.system.entity.vo.RouterVo;
|
import com.chushang.system.entity.vo.RouterVo;
|
||||||
import com.chushang.system.service.*;
|
import com.chushang.system.service.*;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
|
||||||
21
pom.xml
21
pom.xml
|
|
@ -569,6 +569,20 @@
|
||||||
<resource>
|
<resource>
|
||||||
<directory>src/main/resources</directory>
|
<directory>src/main/resources</directory>
|
||||||
<filtering>true</filtering>
|
<filtering>true</filtering>
|
||||||
|
<excludes>
|
||||||
|
<exclude>application*.yml</exclude>
|
||||||
|
<exclude>bootstrap*.yml</exclude>
|
||||||
|
<exclude>logback*.xml</exclude>
|
||||||
|
</excludes>
|
||||||
|
</resource>
|
||||||
|
<resource>
|
||||||
|
<directory>src/main/resources</directory>
|
||||||
|
<filtering>true</filtering>
|
||||||
|
<includes>
|
||||||
|
<include>application*.yml</include>
|
||||||
|
<include>bootstrap*.yml</include>
|
||||||
|
<include>logback*.xml</include>
|
||||||
|
</includes>
|
||||||
</resource>
|
</resource>
|
||||||
</resources>
|
</resources>
|
||||||
<pluginManagement>
|
<pluginManagement>
|
||||||
|
|
@ -586,11 +600,13 @@
|
||||||
<target>17</target>
|
<target>17</target>
|
||||||
<encoding>${project.build.sourceEncoding}</encoding>
|
<encoding>${project.build.sourceEncoding}</encoding>
|
||||||
</configuration>
|
</configuration>
|
||||||
|
<version>${maven-compiler-plugin.version}</version>
|
||||||
</plugin>
|
</plugin>
|
||||||
<!-- 跳过单元测试 -->
|
<!-- 跳过单元测试 -->
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-surefire-plugin</artifactId>
|
<artifactId>maven-surefire-plugin</artifactId>
|
||||||
|
<version>${maven-surefire-plugin.version}</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<skipTests>${maven.test.skip}</skipTests>
|
<skipTests>${maven.test.skip}</skipTests>
|
||||||
</configuration>
|
</configuration>
|
||||||
|
|
@ -619,6 +635,11 @@
|
||||||
<artifactId>spring-javaformat-maven-plugin</artifactId>
|
<artifactId>spring-javaformat-maven-plugin</artifactId>
|
||||||
<version>${spring.checkstyle.plugin}</version>
|
<version>${spring.checkstyle.plugin}</version>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-resources-plugin</artifactId>
|
||||||
|
<version>${maven-resources-plugin.version}</version>
|
||||||
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</pluginManagement>
|
</pluginManagement>
|
||||||
</build>
|
</build>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue