修改版本为发布版,新增图片压缩
This commit is contained in:
parent
8ce8c0db08
commit
b96f87b82f
@ -5,19 +5,20 @@
|
||||
<parent>
|
||||
<artifactId>cm-cloud</artifactId>
|
||||
<groupId>com.cm</groupId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
<version>1.0.0.RELEASE</version>
|
||||
</parent>
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<description>单点登录客户端使用的通用jar包</description>
|
||||
|
||||
<artifactId>cloud-common-plugin-oauth</artifactId>
|
||||
<version>1.0.0.RELEASE</version>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.cm</groupId>
|
||||
<artifactId>cloud-common-plugin</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
<version>1.0.0.RELEASE</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
@ -5,17 +5,18 @@
|
||||
<parent>
|
||||
<artifactId>cm-cloud</artifactId>
|
||||
<groupId>com.cm</groupId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
<version>1.0.0.RELEASE</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>cloud-common-plugin</artifactId>
|
||||
<version>1.0.0.RELEASE</version>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.cm</groupId>
|
||||
<artifactId>cloud-common</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
<version>1.0.0.RELEASE</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
@ -19,6 +19,7 @@ import com.cm.common.utils.ResourceUtil;
|
||||
import com.cm.common.utils.UUIDUtil;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import net.coobird.thumbnailator.Thumbnails;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@ -88,6 +89,7 @@ public class FileServiceImpl extends AbstractService implements IFileService {
|
||||
* @throws SystemException
|
||||
*/
|
||||
private void uploadFile(String token, MultipartFile uploadFile, UploadTypeEnum uploadTypeEnum, Map<String, Object> params) throws SystemException {
|
||||
|
||||
String baseUploadPath = fileProperties.getUploadPath();
|
||||
if (StringUtils.isBlank(baseUploadPath)) {
|
||||
throw new SystemException("上传路径未配置");
|
||||
@ -104,10 +106,22 @@ public class FileServiceImpl extends AbstractService implements IFileService {
|
||||
if (!uploadFile(uploadFile, uploadPath, uploadFileName)) {
|
||||
throw new SaveException("文件上传失败");
|
||||
}
|
||||
String fixPath = uploadPath.replace(fileProperties.getUploadPath(), "");
|
||||
if ("\\".equals(File.separator)) {
|
||||
fixPath = fixPath.replace("\\", "/");
|
||||
}
|
||||
if (fixPath.startsWith("/")) {
|
||||
fixPath = fixPath.substring(1, fixPath.length() - 1);
|
||||
}
|
||||
String fileFullPath = String.format("%s%s%s", uploadPath, File.separator, uploadFileName);
|
||||
// 压缩图片
|
||||
if (isImageFile(fileType)) {
|
||||
compressImage(fileFullPath);
|
||||
}
|
||||
params.put("fileId", UUIDUtil.getUUID());
|
||||
params.put("fileName", fileName);
|
||||
params.put("filePath", String.format("%s/%s", uploadPath, uploadFileName));
|
||||
params.put("fileUrl", String.format("files/%s/%s", uploadPath.replace(fileProperties.getUploadPath(), ""), uploadFileName));
|
||||
params.put("filePath", fileFullPath);
|
||||
params.put("fileUrl", String.format("files/%s/%s", fixPath, uploadFileName));
|
||||
params.put("fileType", fileType);
|
||||
params.put("fileSize", fileSize);
|
||||
params.put("isBack", 0);
|
||||
@ -332,8 +346,8 @@ public class FileServiceImpl extends AbstractService implements IFileService {
|
||||
*/
|
||||
private String getUploadPath(String baseUploadPath, UploadTypeEnum uploadTypeEnum, String fileType) throws FileException {
|
||||
StringBuilder filePath = new StringBuilder();
|
||||
if (!baseUploadPath.endsWith("/")) {
|
||||
filePath.append(baseUploadPath).append("/");
|
||||
if (!baseUploadPath.endsWith(File.separator)) {
|
||||
filePath.append(baseUploadPath).append(File.separator);
|
||||
} else {
|
||||
filePath.append(baseUploadPath);
|
||||
}
|
||||
@ -342,24 +356,24 @@ public class FileServiceImpl extends AbstractService implements IFileService {
|
||||
if (hasFileType && !isTypeCorrect(getImageTypes(), fileType)) {
|
||||
throw new FileException("图片格式不支持上传");
|
||||
}
|
||||
filePath.append("images/");
|
||||
filePath.append("images");
|
||||
} else if (uploadTypeEnum.getValue() == UploadTypeEnum.VIDEO.getValue()) {
|
||||
if (hasFileType && !isTypeCorrect(getVideoTypes(), fileType)) {
|
||||
throw new FileException("视频格式不支持上传");
|
||||
}
|
||||
filePath.append("videos/");
|
||||
filePath.append("videos");
|
||||
} else if (uploadTypeEnum.getValue() == UploadTypeEnum.AUDIO.getValue()) {
|
||||
if (hasFileType && !isTypeCorrect(getAudioTypes(), fileType)) {
|
||||
throw new FileException("音频格式不支持上传");
|
||||
}
|
||||
filePath.append("audios/");
|
||||
filePath.append("audios");
|
||||
} else {
|
||||
if (hasFileType && !isTypeCorrect(getFileTypes(), fileType)) {
|
||||
throw new FileException("文件格式不支持上传");
|
||||
}
|
||||
filePath.append("files/");
|
||||
filePath.append("files");
|
||||
}
|
||||
filePath.append(DateUtil.getDays());
|
||||
filePath.append(File.separator).append(DateUtil.getDays());
|
||||
return filePath.toString();
|
||||
}
|
||||
|
||||
@ -484,4 +498,33 @@ public class FileServiceImpl extends AbstractService implements IFileService {
|
||||
return contentType;
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否是图片文件
|
||||
*
|
||||
* @param fileType
|
||||
* @return
|
||||
*/
|
||||
private boolean isImageFile(String fileType) {
|
||||
String imageTypes = fileProperties.getImageTypes();
|
||||
for (String imageType : imageTypes.split(",")) {
|
||||
if (StringUtils.equalsIgnoreCase(fileType, imageType)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 压缩图片
|
||||
*
|
||||
* @param fileFullPath
|
||||
*/
|
||||
private void compressImage(String fileFullPath) {
|
||||
try {
|
||||
Thumbnails.of(fileFullPath).scale(1.0f).outputQuality(0.4f).toFile(fileFullPath);
|
||||
} catch (IOException e) {
|
||||
LOG.error(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -5,11 +5,12 @@
|
||||
<parent>
|
||||
<artifactId>cm-cloud</artifactId>
|
||||
<groupId>com.cm</groupId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
<version>1.0.0.RELEASE</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>cloud-common</artifactId>
|
||||
<version>1.0.0.RELEASE</version>
|
||||
|
||||
<dependencies>
|
||||
|
||||
|
@ -5,11 +5,12 @@
|
||||
<parent>
|
||||
<artifactId>cm-cloud</artifactId>
|
||||
<groupId>com.cm</groupId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
<version>1.0.0.RELEASE</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>cloud-security</artifactId>
|
||||
<version>1.0.0.RELEASE</version>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
|
@ -5,12 +5,13 @@
|
||||
<parent>
|
||||
<artifactId>cm-cloud</artifactId>
|
||||
<groupId>com.cm</groupId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
<version>1.0.0.RELEASE</version>
|
||||
</parent>
|
||||
<description>接收系统校验</description>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>cloud-token-in</artifactId>
|
||||
<version>1.0.0.RELEASE</version>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
@ -22,7 +23,7 @@
|
||||
<dependency>
|
||||
<groupId>com.cm</groupId>
|
||||
<artifactId>cloud-security</artifactId>
|
||||
<version>1.0</version>
|
||||
<version>1.0.0.RELEASE</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
@ -5,12 +5,13 @@
|
||||
<parent>
|
||||
<artifactId>cm-cloud</artifactId>
|
||||
<groupId>com.cm</groupId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
<version>1.0.0.RELEASE</version>
|
||||
</parent>
|
||||
<description>发送系统校验</description>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>cloud-token-out</artifactId>
|
||||
<version>1.0.0.RELEASE</version>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
|
@ -1,50 +1,45 @@
|
||||
package com.cm;
|
||||
|
||||
import com.cm.params.ParamsOut;
|
||||
import com.cm.token.TokenEncoder;
|
||||
import com.hazelcast.util.Base64;
|
||||
import org.junit.Test;
|
||||
import sun.misc.BASE64Encoder;
|
||||
|
||||
import javax.crypto.KeyGenerator;
|
||||
import javax.crypto.SecretKey;
|
||||
import java.security.SecureRandom;
|
||||
|
||||
/**
|
||||
* @author Administrator
|
||||
* @version 1.0
|
||||
* @className EncodeTest
|
||||
* @description TODO
|
||||
* @date 2018/12/7 17:31
|
||||
**/
|
||||
public class EncodeTest {
|
||||
|
||||
@Test
|
||||
public void tokenTest() throws Exception {
|
||||
String token1 = TokenEncoder.createToken().getToken();
|
||||
System.out.println("token1: "+ token1);
|
||||
String token2 = TokenEncoder.createToken("this is content").getToken();
|
||||
System.out.println("token2: "+ token2);
|
||||
String token3 = TokenEncoder.createToken("zhangsan", "123456").getToken();
|
||||
System.out.println("token3: "+ token3);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void paramsTest() throws Exception {
|
||||
// System.out.println(ParamsOut.paramsInDecoder("UjlBUXNXQkJvSG9ZRmlkR3hvYmhqM2phY2hBTFQzQTBJQUlhbmRRcEsrWT0="));
|
||||
// System.out.println(ParamsOut.paramsOutEncode("out -> in -> encoder"));
|
||||
|
||||
String password = "cmxxParamsIn";//AES的密钥
|
||||
KeyGenerator kgen = KeyGenerator.getInstance("AES");
|
||||
SecureRandom secureRandom = SecureRandom.getInstance("SHA1PRNG");
|
||||
secureRandom.setSeed(password.getBytes());
|
||||
kgen.init(128, secureRandom);
|
||||
|
||||
SecretKey secretKey = kgen.generateKey();
|
||||
byte[] enCodeFormat = secretKey.getEncoded();//AES加密实际的Key值
|
||||
System.out.println(new String(Base64.encode(enCodeFormat)));
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
package com.cm;
|
||||
|
||||
import com.cm.token.TokenEncoder;
|
||||
import com.hazelcast.util.Base64;
|
||||
|
||||
import javax.crypto.KeyGenerator;
|
||||
import javax.crypto.SecretKey;
|
||||
import java.security.SecureRandom;
|
||||
|
||||
/**
|
||||
* @author Administrator
|
||||
* @version 1.0
|
||||
* @className EncodeTest
|
||||
* @description TODO
|
||||
* @date 2018/12/7 17:31
|
||||
**/
|
||||
public class EncodeTest {
|
||||
|
||||
public void tokenTest() throws Exception {
|
||||
String token1 = TokenEncoder.createToken().getToken();
|
||||
System.out.println("token1: "+ token1);
|
||||
String token2 = TokenEncoder.createToken("this is content").getToken();
|
||||
System.out.println("token2: "+ token2);
|
||||
String token3 = TokenEncoder.createToken("zhangsan", "123456").getToken();
|
||||
System.out.println("token3: "+ token3);
|
||||
}
|
||||
|
||||
public void paramsTest() throws Exception {
|
||||
// System.out.println(ParamsOut.paramsInDecoder("UjlBUXNXQkJvSG9ZRmlkR3hvYmhqM2phY2hBTFQzQTBJQUlhbmRRcEsrWT0="));
|
||||
// System.out.println(ParamsOut.paramsOutEncode("out -> in -> encoder"));
|
||||
|
||||
String password = "cmxxParamsIn";//AES的密钥
|
||||
KeyGenerator kgen = KeyGenerator.getInstance("AES");
|
||||
SecureRandom secureRandom = SecureRandom.getInstance("SHA1PRNG");
|
||||
secureRandom.setSeed(password.getBytes());
|
||||
kgen.init(128, secureRandom);
|
||||
|
||||
SecretKey secretKey = kgen.generateKey();
|
||||
byte[] enCodeFormat = secretKey.getEncoded();//AES加密实际的Key值
|
||||
System.out.println(new String(Base64.encode(enCodeFormat)));
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
4
pom.xml
4
pom.xml
@ -6,7 +6,7 @@
|
||||
|
||||
<groupId>com.cm</groupId>
|
||||
<artifactId>cm-cloud</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
<version>1.0.0.RELEASE</version>
|
||||
<modules>
|
||||
<module>cloud-common</module>
|
||||
<module>cloud-security</module>
|
||||
@ -40,7 +40,7 @@
|
||||
<common-fileupload.version>1.3.1</common-fileupload.version>
|
||||
<common-codec.version>1.12</common-codec.version>
|
||||
<common-compress>1.18</common-compress>
|
||||
<common-beanutils.version>1.9.3</common-beanutils.version>
|
||||
<common-beanutils.version>1.9.4</common-beanutils.version>
|
||||
<saaj.version>1.3.18</saaj.version>
|
||||
<shiro.version>1.4.0</shiro.version>
|
||||
<poi.version>3.17</poi.version>
|
||||
|
Loading…
Reference in New Issue
Block a user