From 0465d8d3e232fa404142fb6bffb595bcb995e4a4 Mon Sep 17 00:00:00 2001 From: Raod <1130305001@qq.com> Date: Wed, 18 Aug 2021 16:45:21 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8A=A5=E8=A1=A8=E5=88=86=E4=BA=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gaea/business/enums/DeleteFlagEnum.java | 47 ++++++ .../gaea/business/enums/EnableFlagEnum.java | 47 ++++++ .../controller/ReportShareController.java | 34 +++- .../controller/dto/ReportShareDto.java | 6 + .../service/ReportShareService.java | 4 + .../service/impl/ReportShareServiceImpl.java | 37 ++++- .../template/gaea/business/util/AESUtil.java | 152 ++++++++++++++++++ .../src/views/report/bigscreen/index.vue | 5 +- .../views/report/report/components/share.vue | 71 +++++++- 9 files changed, 385 insertions(+), 18 deletions(-) create mode 100644 report-core/src/main/java/com/anjiplus/template/gaea/business/enums/DeleteFlagEnum.java create mode 100644 report-core/src/main/java/com/anjiplus/template/gaea/business/enums/EnableFlagEnum.java create mode 100644 report-core/src/main/java/com/anjiplus/template/gaea/business/util/AESUtil.java diff --git a/report-core/src/main/java/com/anjiplus/template/gaea/business/enums/DeleteFlagEnum.java b/report-core/src/main/java/com/anjiplus/template/gaea/business/enums/DeleteFlagEnum.java new file mode 100644 index 00000000..a883408d --- /dev/null +++ b/report-core/src/main/java/com/anjiplus/template/gaea/business/enums/DeleteFlagEnum.java @@ -0,0 +1,47 @@ +package com.anjiplus.template.gaea.business.enums; +public enum DeleteFlagEnum { + DELETED(1,"已删除"), + UNDELETED(0,"未删除"), + ; + + private int codeValue; + private String codeDesc; + + private DeleteFlagEnum(int codeValue, String codeDesc) { + this.codeValue = codeValue; + this.codeDesc = codeDesc; + } + + public int getCodeValue(){ return this.codeValue;} + + public String getCodeDesc(){ return this.codeDesc;} + + //根据codeValue获取枚举 + public static DeleteFlagEnum parseFromCodeValue(int codeValue){ + for (DeleteFlagEnum e : DeleteFlagEnum.values()){ + if(e.codeValue == codeValue){ return e;} + } + return null; + } + + //根据codeValue获取描述 + public static String getCodeDescByCodeValue(int codeValue){ + DeleteFlagEnum enumItem = parseFromCodeValue(codeValue); + return enumItem == null ? "" : enumItem.getCodeDesc(); + } + + //验证codeValue是否有效 + public static boolean validateCodeValue(int codeValue){ return parseFromCodeValue(codeValue)!=null;} + + //列出所有值字符串 + public static String getString(){ + StringBuffer buffer = new StringBuffer(); + for (DeleteFlagEnum e : DeleteFlagEnum.values()){ + buffer.append(e.codeValue).append("--").append(e.getCodeDesc()).append(", "); + } + buffer.deleteCharAt(buffer.lastIndexOf(",")); + return buffer.toString().trim(); + } + + +} diff --git a/report-core/src/main/java/com/anjiplus/template/gaea/business/enums/EnableFlagEnum.java b/report-core/src/main/java/com/anjiplus/template/gaea/business/enums/EnableFlagEnum.java new file mode 100644 index 00000000..5d4b207b --- /dev/null +++ b/report-core/src/main/java/com/anjiplus/template/gaea/business/enums/EnableFlagEnum.java @@ -0,0 +1,47 @@ +package com.anjiplus.template.gaea.business.enums; +public enum EnableFlagEnum { + ENABLE(1,"启用"), + DISABLE(0,"禁用"), + ; + + private int codeValue; + private String codeDesc; + + private EnableFlagEnum(int codeValue, String codeDesc) { + this.codeValue = codeValue; + this.codeDesc = codeDesc; + } + + public int getCodeValue(){ return this.codeValue;} + + public String getCodeDesc(){ return this.codeDesc;} + + //根据codeValue获取枚举 + public static EnableFlagEnum parseFromCodeValue(int codeValue){ + for (EnableFlagEnum e : EnableFlagEnum.values()){ + if(e.codeValue == codeValue){ return e;} + } + return null; + } + + //根据codeValue获取描述 + public static String getCodeDescByCodeBalue(int codeValue){ + EnableFlagEnum enumItem = parseFromCodeValue(codeValue); + return enumItem == null ? "" : enumItem.getCodeDesc(); + } + + //验证codeValue是否有效 + public static boolean validateCodeValue(int codeValue){ return parseFromCodeValue(codeValue)!=null;} + + //列出所有值字符串 + public static String getString(){ + StringBuffer buffer = new StringBuffer(); + for (EnableFlagEnum e : EnableFlagEnum.values()){ + buffer.append(e.codeValue).append("--").append(e.getCodeDesc()).append(", "); + } + buffer.deleteCharAt(buffer.lastIndexOf(",")); + return buffer.toString().trim(); + } + + +} diff --git a/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/reportshare/controller/ReportShareController.java b/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/reportshare/controller/ReportShareController.java index 1b8ff5ee..9040ee96 100644 --- a/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/reportshare/controller/ReportShareController.java +++ b/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/reportshare/controller/ReportShareController.java @@ -3,6 +3,7 @@ package com.anjiplus.template.gaea.business.modules.reportshare.controller; import com.anji.plus.gaea.annotation.AccessKey; import com.anji.plus.gaea.annotation.Permission; +import com.anji.plus.gaea.annotation.log.GaeaAuditLog; import com.anji.plus.gaea.bean.ResponseBean; import com.anji.plus.gaea.curd.controller.GaeaBaseController; import com.anji.plus.gaea.curd.service.GaeaBaseService; @@ -14,16 +15,14 @@ import com.anjiplus.template.gaea.business.modules.reportshare.dao.entity.Report import com.anjiplus.template.gaea.business.modules.reportshare.service.ReportShareService; import io.swagger.annotations.Api; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; /** -* @desc 报表分享 controller -* @author Raod -* @date 2021-08-18 13:37:26.663 -**/ + * @author Raod + * @desc 报表分享 controller + * @date 2021-08-18 13:37:26.663 + **/ @RestController @Api(tags = "报表分享管理") @RequestMapping("/reportShare") @@ -63,4 +62,23 @@ public class ReportShareController extends GaeaBaseController wrapper = Wrappers.lambdaQuery(); + wrapper.eq(ReportShare::getShareCode, shareCode); + wrapper.eq(ReportShare::getEnableFlag, EnableFlagEnum.ENABLE.getCodeDesc()); + return selectOne(wrapper); + } + @Override public void processBeforeOperation(ReportShare entity, BaseOperationEnum operationEnum) throws BusinessException { switch (operationEnum) { @@ -48,9 +73,11 @@ public class ReportShareServiceImpl implements ReportShareService { //http://127.0.0.1:9095/reportDashboard/getData String shareCode = UUID.randomUUID().toString(); entity.setShareCode(shareCode); - if (StringUtils.isNotBlank(entity.getShareUrl())) { + if (entity.getShareUrl().contains(SHARE_URL)) { String prefix = entity.getShareUrl().substring(0, entity.getShareUrl().indexOf("#")); - entity.setShareUrl(prefix + "#/bigscreen/viewer?reportCode=" + entity.getReportCode()); + entity.setShareUrl(prefix + SHARE_FLAG + shareCode); + } else { + entity.setShareUrl(entity.getShareUrl() + SHARE_FLAG + shareCode); } entity.setShareValidTime(DateUtil.getFutureDateTmdHms(entity.getShareValidType())); break; diff --git a/report-core/src/main/java/com/anjiplus/template/gaea/business/util/AESUtil.java b/report-core/src/main/java/com/anjiplus/template/gaea/business/util/AESUtil.java new file mode 100644 index 00000000..9a488dd5 --- /dev/null +++ b/report-core/src/main/java/com/anjiplus/template/gaea/business/util/AESUtil.java @@ -0,0 +1,152 @@ +/* + *Copyright © 2018 anji-plus + *安吉加加信息技术有限公司 + *http://www.anji-plus.com + *All rights reserved. + */ +package com.anjiplus.template.gaea.business.util; + + +import org.apache.commons.lang3.StringUtils; + +import javax.crypto.Cipher; +import javax.crypto.KeyGenerator; +import javax.crypto.spec.SecretKeySpec; +import java.math.BigInteger; +import java.util.Base64; + + +public class AESUtil { + //算法 + private static final String ALGORITHMSTR = "AES/ECB/PKCS5Padding"; + + private static final String AES_KEY = "AnjiPLUSAjReport"; + + + /** + * 获取随机key + * + * @return + */ + public static String getKey() { + return AES_KEY; + } + + + /** + * 将byte[]转为各种进制的字符串 + * + * @param bytes byte[] + * @param radix 可以转换进制的范围,从Character.MIN_RADIX到Character.MAX_RADIX,超出范围后变为10进制 + * @return 转换后的字符串 + */ + public static String binary(byte[] bytes, int radix) { + return new BigInteger(1, bytes).toString(radix);// 这里的1代表正数 + } + + /** + * base 64 encode + * + * @param bytes 待编码的byte[] + * @return 编码后的base 64 code + */ + public static String base64Encode(byte[] bytes) { + //return Base64.encodeBase64String(bytes); + return Base64.getEncoder().encodeToString(bytes); + } + + /** + * base 64 decode + * + * @param base64Code 待解码的base 64 code + * @return 解码后的byte[] + * @throws Exception + */ + public static byte[] base64Decode(String base64Code) throws Exception { + Base64.Decoder decoder = Base64.getDecoder(); + return StringUtils.isEmpty(base64Code) ? null : decoder.decode(base64Code); + } + + + /** + * AES加密 + * + * @param content 待加密的内容 + * @param encryptKey 加密密钥 + * @return 加密后的byte[] + * @throws Exception + */ + public static byte[] aesEncryptToBytes(String content, String encryptKey) throws Exception { + KeyGenerator kgen = KeyGenerator.getInstance("AES"); + kgen.init(128); + Cipher cipher = Cipher.getInstance(ALGORITHMSTR); + cipher.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(encryptKey.getBytes(), "AES")); + + return cipher.doFinal(content.getBytes("utf-8")); + } + + + /** + * AES加密为base 64 code + * + * @param content 待加密的内容 + * @param encryptKey 加密密钥 + * @return 加密后的base 64 code + * @throws Exception + */ + public static String aesEncrypt(String content, String encryptKey) throws Exception { + if (StringUtils.isBlank(encryptKey)) { + return content; + } + return base64Encode(aesEncryptToBytes(content, encryptKey)); + } + + /** + * AES解密 + * + * @param encryptBytes 待解密的byte[] + * @param decryptKey 解密密钥 + * @return 解密后的String + * @throws Exception + */ + public static String aesDecryptByBytes(byte[] encryptBytes, String decryptKey) throws Exception { + KeyGenerator kgen = KeyGenerator.getInstance("AES"); + kgen.init(128); + + Cipher cipher = Cipher.getInstance(ALGORITHMSTR); + cipher.init(Cipher.DECRYPT_MODE, new SecretKeySpec(decryptKey.getBytes(), "AES")); + byte[] decryptBytes = cipher.doFinal(encryptBytes); + return new String(decryptBytes); + } + + + /** + * 将base 64 code AES解密 + * + * @param encryptStr 待解密的base 64 code + * @param decryptKey 解密密钥 + * @return 解密后的string + * @throws Exception + */ + public static String aesDecrypt(String encryptStr, String decryptKey) throws Exception { + if (StringUtils.isBlank(decryptKey)) { + return encryptStr; + } + return StringUtils.isEmpty(encryptStr) ? null : aesDecryptByBytes(base64Decode(encryptStr), decryptKey); + } + + /** + * 测试 + */ + public static void main(String[] args) throws Exception { + String randomString = getKey(); + String content = "report"; + System.out.println("加密前:" + content); + System.out.println("加密密钥和解密密钥:" + randomString); + String encrypt = aesEncrypt(content, randomString); + System.out.println("加密后:" + encrypt); + String decrypt = aesDecrypt(encrypt, randomString); + System.out.println("解密后:" + decrypt); + } + +} diff --git a/report-ui/src/views/report/bigscreen/index.vue b/report-ui/src/views/report/bigscreen/index.vue index 2afc90e4..27e30bd3 100644 --- a/report-ui/src/views/report/bigscreen/index.vue +++ b/report-ui/src/views/report/bigscreen/index.vue @@ -99,6 +99,7 @@ @@ -127,7 +128,8 @@ export default { }, // 分享 visibleForShareDialog: false, - reportCodeForShareDialog: "" + reportCodeForShareDialog: "", + reportNameForShareDialog: "" }; }, mounted() {}, @@ -172,6 +174,7 @@ export default { // 分享 share(val) { this.reportCodeForShareDialog = val.reportCode; + this.reportNameForShareDialog = val.reportName; this.visibleForShareDialog = true; }, openDesign(val) { diff --git a/report-ui/src/views/report/report/components/share.vue b/report-ui/src/views/report/report/components/share.vue index 8bbff3ec..92c060ab 100644 --- a/report-ui/src/views/report/report/components/share.vue +++ b/report-ui/src/views/report/report/components/share.vue @@ -1,14 +1,32 @@