修改版本为发布版,新增图片压缩

This commit is contained in:
wenc000 2019-09-08 21:54:19 +08:00
parent 8ce8c0db08
commit b96f87b82f
9 changed files with 114 additions and 70 deletions

View File

@ -5,19 +5,20 @@
<parent> <parent>
<artifactId>cm-cloud</artifactId> <artifactId>cm-cloud</artifactId>
<groupId>com.cm</groupId> <groupId>com.cm</groupId>
<version>1.0.0-SNAPSHOT</version> <version>1.0.0.RELEASE</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<description>单点登录客户端使用的通用jar包</description> <description>单点登录客户端使用的通用jar包</description>
<artifactId>cloud-common-plugin-oauth</artifactId> <artifactId>cloud-common-plugin-oauth</artifactId>
<version>1.0.0.RELEASE</version>
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>com.cm</groupId> <groupId>com.cm</groupId>
<artifactId>cloud-common-plugin</artifactId> <artifactId>cloud-common-plugin</artifactId>
<version>1.0.0-SNAPSHOT</version> <version>1.0.0.RELEASE</version>
</dependency> </dependency>
</dependencies> </dependencies>

View File

@ -5,17 +5,18 @@
<parent> <parent>
<artifactId>cm-cloud</artifactId> <artifactId>cm-cloud</artifactId>
<groupId>com.cm</groupId> <groupId>com.cm</groupId>
<version>1.0.0-SNAPSHOT</version> <version>1.0.0.RELEASE</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<artifactId>cloud-common-plugin</artifactId> <artifactId>cloud-common-plugin</artifactId>
<version>1.0.0.RELEASE</version>
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>com.cm</groupId> <groupId>com.cm</groupId>
<artifactId>cloud-common</artifactId> <artifactId>cloud-common</artifactId>
<version>1.0.0-SNAPSHOT</version> <version>1.0.0.RELEASE</version>
</dependency> </dependency>
</dependencies> </dependencies>

View File

@ -19,6 +19,7 @@ import com.cm.common.utils.ResourceUtil;
import com.cm.common.utils.UUIDUtil; import com.cm.common.utils.UUIDUtil;
import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo; import com.github.pagehelper.PageInfo;
import net.coobird.thumbnailator.Thumbnails;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -88,6 +89,7 @@ public class FileServiceImpl extends AbstractService implements IFileService {
* @throws SystemException * @throws SystemException
*/ */
private void uploadFile(String token, MultipartFile uploadFile, UploadTypeEnum uploadTypeEnum, Map<String, Object> params) throws SystemException { private void uploadFile(String token, MultipartFile uploadFile, UploadTypeEnum uploadTypeEnum, Map<String, Object> params) throws SystemException {
String baseUploadPath = fileProperties.getUploadPath(); String baseUploadPath = fileProperties.getUploadPath();
if (StringUtils.isBlank(baseUploadPath)) { if (StringUtils.isBlank(baseUploadPath)) {
throw new SystemException("上传路径未配置"); throw new SystemException("上传路径未配置");
@ -104,10 +106,22 @@ public class FileServiceImpl extends AbstractService implements IFileService {
if (!uploadFile(uploadFile, uploadPath, uploadFileName)) { if (!uploadFile(uploadFile, uploadPath, uploadFileName)) {
throw new SaveException("文件上传失败"); 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("fileId", UUIDUtil.getUUID());
params.put("fileName", fileName); params.put("fileName", fileName);
params.put("filePath", String.format("%s/%s", uploadPath, uploadFileName)); params.put("filePath", fileFullPath);
params.put("fileUrl", String.format("files/%s/%s", uploadPath.replace(fileProperties.getUploadPath(), ""), uploadFileName)); params.put("fileUrl", String.format("files/%s/%s", fixPath, uploadFileName));
params.put("fileType", fileType); params.put("fileType", fileType);
params.put("fileSize", fileSize); params.put("fileSize", fileSize);
params.put("isBack", 0); 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 { private String getUploadPath(String baseUploadPath, UploadTypeEnum uploadTypeEnum, String fileType) throws FileException {
StringBuilder filePath = new StringBuilder(); StringBuilder filePath = new StringBuilder();
if (!baseUploadPath.endsWith("/")) { if (!baseUploadPath.endsWith(File.separator)) {
filePath.append(baseUploadPath).append("/"); filePath.append(baseUploadPath).append(File.separator);
} else { } else {
filePath.append(baseUploadPath); filePath.append(baseUploadPath);
} }
@ -342,24 +356,24 @@ public class FileServiceImpl extends AbstractService implements IFileService {
if (hasFileType && !isTypeCorrect(getImageTypes(), fileType)) { if (hasFileType && !isTypeCorrect(getImageTypes(), fileType)) {
throw new FileException("图片格式不支持上传"); throw new FileException("图片格式不支持上传");
} }
filePath.append("images/"); filePath.append("images");
} else if (uploadTypeEnum.getValue() == UploadTypeEnum.VIDEO.getValue()) { } else if (uploadTypeEnum.getValue() == UploadTypeEnum.VIDEO.getValue()) {
if (hasFileType && !isTypeCorrect(getVideoTypes(), fileType)) { if (hasFileType && !isTypeCorrect(getVideoTypes(), fileType)) {
throw new FileException("视频格式不支持上传"); throw new FileException("视频格式不支持上传");
} }
filePath.append("videos/"); filePath.append("videos");
} else if (uploadTypeEnum.getValue() == UploadTypeEnum.AUDIO.getValue()) { } else if (uploadTypeEnum.getValue() == UploadTypeEnum.AUDIO.getValue()) {
if (hasFileType && !isTypeCorrect(getAudioTypes(), fileType)) { if (hasFileType && !isTypeCorrect(getAudioTypes(), fileType)) {
throw new FileException("音频格式不支持上传"); throw new FileException("音频格式不支持上传");
} }
filePath.append("audios/"); filePath.append("audios");
} else { } else {
if (hasFileType && !isTypeCorrect(getFileTypes(), fileType)) { if (hasFileType && !isTypeCorrect(getFileTypes(), fileType)) {
throw new FileException("文件格式不支持上传"); throw new FileException("文件格式不支持上传");
} }
filePath.append("files/"); filePath.append("files");
} }
filePath.append(DateUtil.getDays()); filePath.append(File.separator).append(DateUtil.getDays());
return filePath.toString(); return filePath.toString();
} }
@ -484,4 +498,33 @@ public class FileServiceImpl extends AbstractService implements IFileService {
return contentType; 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);
}
}
} }

View File

@ -5,11 +5,12 @@
<parent> <parent>
<artifactId>cm-cloud</artifactId> <artifactId>cm-cloud</artifactId>
<groupId>com.cm</groupId> <groupId>com.cm</groupId>
<version>1.0.0-SNAPSHOT</version> <version>1.0.0.RELEASE</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<artifactId>cloud-common</artifactId> <artifactId>cloud-common</artifactId>
<version>1.0.0.RELEASE</version>
<dependencies> <dependencies>

View File

@ -5,11 +5,12 @@
<parent> <parent>
<artifactId>cm-cloud</artifactId> <artifactId>cm-cloud</artifactId>
<groupId>com.cm</groupId> <groupId>com.cm</groupId>
<version>1.0.0-SNAPSHOT</version> <version>1.0.0.RELEASE</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<artifactId>cloud-security</artifactId> <artifactId>cloud-security</artifactId>
<version>1.0.0.RELEASE</version>
<dependencies> <dependencies>
<dependency> <dependency>

View File

@ -5,12 +5,13 @@
<parent> <parent>
<artifactId>cm-cloud</artifactId> <artifactId>cm-cloud</artifactId>
<groupId>com.cm</groupId> <groupId>com.cm</groupId>
<version>1.0.0-SNAPSHOT</version> <version>1.0.0.RELEASE</version>
</parent> </parent>
<description>接收系统校验</description> <description>接收系统校验</description>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<artifactId>cloud-token-in</artifactId> <artifactId>cloud-token-in</artifactId>
<version>1.0.0.RELEASE</version>
<dependencies> <dependencies>
<dependency> <dependency>
@ -22,7 +23,7 @@
<dependency> <dependency>
<groupId>com.cm</groupId> <groupId>com.cm</groupId>
<artifactId>cloud-security</artifactId> <artifactId>cloud-security</artifactId>
<version>1.0</version> <version>1.0.0.RELEASE</version>
</dependency> </dependency>
</dependencies> </dependencies>

View File

@ -5,12 +5,13 @@
<parent> <parent>
<artifactId>cm-cloud</artifactId> <artifactId>cm-cloud</artifactId>
<groupId>com.cm</groupId> <groupId>com.cm</groupId>
<version>1.0.0-SNAPSHOT</version> <version>1.0.0.RELEASE</version>
</parent> </parent>
<description>发送系统校验</description> <description>发送系统校验</description>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<artifactId>cloud-token-out</artifactId> <artifactId>cloud-token-out</artifactId>
<version>1.0.0.RELEASE</version>
<dependencies> <dependencies>
<dependency> <dependency>

View File

@ -1,50 +1,45 @@
package com.cm; package com.cm;
import com.cm.params.ParamsOut; import com.cm.token.TokenEncoder;
import com.cm.token.TokenEncoder; import com.hazelcast.util.Base64;
import com.hazelcast.util.Base64;
import org.junit.Test; import javax.crypto.KeyGenerator;
import sun.misc.BASE64Encoder; import javax.crypto.SecretKey;
import java.security.SecureRandom;
import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey; /**
import java.security.SecureRandom; * @author Administrator
* @version 1.0
/** * @className EncodeTest
* @author Administrator * @description TODO
* @version 1.0 * @date 2018/12/7 17:31
* @className EncodeTest **/
* @description TODO public class EncodeTest {
* @date 2018/12/7 17:31
**/ public void tokenTest() throws Exception {
public class EncodeTest { String token1 = TokenEncoder.createToken().getToken();
System.out.println("token1: "+ token1);
@Test String token2 = TokenEncoder.createToken("this is content").getToken();
public void tokenTest() throws Exception { System.out.println("token2: "+ token2);
String token1 = TokenEncoder.createToken().getToken(); String token3 = TokenEncoder.createToken("zhangsan", "123456").getToken();
System.out.println("token1: "+ token1); System.out.println("token3: "+ token3);
String token2 = TokenEncoder.createToken("this is content").getToken(); }
System.out.println("token2: "+ token2);
String token3 = TokenEncoder.createToken("zhangsan", "123456").getToken(); public void paramsTest() throws Exception {
System.out.println("token3: "+ token3); // System.out.println(ParamsOut.paramsInDecoder("UjlBUXNXQkJvSG9ZRmlkR3hvYmhqM2phY2hBTFQzQTBJQUlhbmRRcEsrWT0="));
} // System.out.println(ParamsOut.paramsOutEncode("out -> in -> encoder"));
@Test String password = "cmxxParamsIn";//AES的密钥
public void paramsTest() throws Exception { KeyGenerator kgen = KeyGenerator.getInstance("AES");
// System.out.println(ParamsOut.paramsInDecoder("UjlBUXNXQkJvSG9ZRmlkR3hvYmhqM2phY2hBTFQzQTBJQUlhbmRRcEsrWT0=")); SecureRandom secureRandom = SecureRandom.getInstance("SHA1PRNG");
// System.out.println(ParamsOut.paramsOutEncode("out -> in -> encoder")); secureRandom.setSeed(password.getBytes());
kgen.init(128, secureRandom);
String password = "cmxxParamsIn";//AES的密钥
KeyGenerator kgen = KeyGenerator.getInstance("AES"); SecretKey secretKey = kgen.generateKey();
SecureRandom secureRandom = SecureRandom.getInstance("SHA1PRNG"); byte[] enCodeFormat = secretKey.getEncoded();//AES加密实际的Key值
secureRandom.setSeed(password.getBytes()); System.out.println(new String(Base64.encode(enCodeFormat)));
kgen.init(128, secureRandom);
SecretKey secretKey = kgen.generateKey(); }
byte[] enCodeFormat = secretKey.getEncoded();//AES加密实际的Key值
System.out.println(new String(Base64.encode(enCodeFormat))); }
}
}

View File

@ -6,7 +6,7 @@
<groupId>com.cm</groupId> <groupId>com.cm</groupId>
<artifactId>cm-cloud</artifactId> <artifactId>cm-cloud</artifactId>
<version>1.0.0-SNAPSHOT</version> <version>1.0.0.RELEASE</version>
<modules> <modules>
<module>cloud-common</module> <module>cloud-common</module>
<module>cloud-security</module> <module>cloud-security</module>
@ -40,7 +40,7 @@
<common-fileupload.version>1.3.1</common-fileupload.version> <common-fileupload.version>1.3.1</common-fileupload.version>
<common-codec.version>1.12</common-codec.version> <common-codec.version>1.12</common-codec.version>
<common-compress>1.18</common-compress> <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> <saaj.version>1.3.18</saaj.version>
<shiro.version>1.4.0</shiro.version> <shiro.version>1.4.0</shiro.version>
<poi.version>3.17</poi.version> <poi.version>3.17</poi.version>