diff --git a/cloud-common-plugin-oauth/pom.xml b/cloud-common-plugin-oauth/pom.xml index 439145c..de009a1 100644 --- a/cloud-common-plugin-oauth/pom.xml +++ b/cloud-common-plugin-oauth/pom.xml @@ -5,19 +5,20 @@ cm-cloud com.cm - 1.0.0-SNAPSHOT + 1.0.0.RELEASE 4.0.0 单点登录客户端使用的通用jar包 cloud-common-plugin-oauth + 1.0.0.RELEASE com.cm cloud-common-plugin - 1.0.0-SNAPSHOT + 1.0.0.RELEASE diff --git a/cloud-common-plugin/pom.xml b/cloud-common-plugin/pom.xml index b20ce90..9c53af4 100644 --- a/cloud-common-plugin/pom.xml +++ b/cloud-common-plugin/pom.xml @@ -5,17 +5,18 @@ cm-cloud com.cm - 1.0.0-SNAPSHOT + 1.0.0.RELEASE 4.0.0 cloud-common-plugin + 1.0.0.RELEASE com.cm cloud-common - 1.0.0-SNAPSHOT + 1.0.0.RELEASE diff --git a/cloud-common-plugin/src/main/java/com/cm/common/plugin/service/file/impl/FileServiceImpl.java b/cloud-common-plugin/src/main/java/com/cm/common/plugin/service/file/impl/FileServiceImpl.java index 20f4f1b..65edf9a 100644 --- a/cloud-common-plugin/src/main/java/com/cm/common/plugin/service/file/impl/FileServiceImpl.java +++ b/cloud-common-plugin/src/main/java/com/cm/common/plugin/service/file/impl/FileServiceImpl.java @@ -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 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); + } + } + } diff --git a/cloud-common/pom.xml b/cloud-common/pom.xml index e9db42d..d1352f2 100644 --- a/cloud-common/pom.xml +++ b/cloud-common/pom.xml @@ -5,11 +5,12 @@ cm-cloud com.cm - 1.0.0-SNAPSHOT + 1.0.0.RELEASE 4.0.0 cloud-common + 1.0.0.RELEASE diff --git a/cloud-security/pom.xml b/cloud-security/pom.xml index dfc6090..a92a02c 100644 --- a/cloud-security/pom.xml +++ b/cloud-security/pom.xml @@ -5,11 +5,12 @@ cm-cloud com.cm - 1.0.0-SNAPSHOT + 1.0.0.RELEASE 4.0.0 cloud-security + 1.0.0.RELEASE diff --git a/cloud-token-in/pom.xml b/cloud-token-in/pom.xml index d5474a8..d5f8a32 100644 --- a/cloud-token-in/pom.xml +++ b/cloud-token-in/pom.xml @@ -5,12 +5,13 @@ cm-cloud com.cm - 1.0.0-SNAPSHOT + 1.0.0.RELEASE 接收系统校验 4.0.0 cloud-token-in + 1.0.0.RELEASE @@ -22,7 +23,7 @@ com.cm cloud-security - 1.0 + 1.0.0.RELEASE diff --git a/cloud-token-out/pom.xml b/cloud-token-out/pom.xml index 796dcde..10ab231 100644 --- a/cloud-token-out/pom.xml +++ b/cloud-token-out/pom.xml @@ -5,12 +5,13 @@ cm-cloud com.cm - 1.0.0-SNAPSHOT + 1.0.0.RELEASE 发送系统校验 4.0.0 cloud-token-out + 1.0.0.RELEASE diff --git a/cloud-token-out/src/test/java/com/cm/EncodeTest.java b/cloud-token-out/src/test/java/com/cm/EncodeTest.java index 68be34e..b9ccecf 100644 --- a/cloud-token-out/src/test/java/com/cm/EncodeTest.java +++ b/cloud-token-out/src/test/java/com/cm/EncodeTest.java @@ -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))); + + + } + +} diff --git a/pom.xml b/pom.xml index 81ad12e..12b7041 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.cm cm-cloud - 1.0.0-SNAPSHOT + 1.0.0.RELEASE cloud-common cloud-security @@ -40,7 +40,7 @@ 1.3.1 1.12 1.18 - 1.9.3 + 1.9.4 1.3.18 1.4.0 3.17