From 7259593066809bedf29fe2c174c50310ef10c64a Mon Sep 17 00:00:00 2001
From: Raod <1130305001@qq.com>
Date: Thu, 23 Sep 2021 14:50:50 +0800
Subject: [PATCH] =?UTF-8?q?=E5=88=86=E4=BA=AB=E7=A0=81?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../controller/dto/ReportShareDto.java | 5 ++
.../reportshare/dao/entity/ReportShare.java | 13 ++++-
.../service/impl/ReportShareServiceImpl.java | 17 +++++-
.../template/gaea/business/util/JwtUtil.java | 17 ++++++
.../template/gaea/business/util/UuidUtil.java | 23 +++++++-
report-ui/src/views/report/aj/index.vue | 56 +++++++++++++++++--
.../views/report/report/components/share.vue | 54 ++++++++++++++----
7 files changed, 163 insertions(+), 22 deletions(-)
diff --git a/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/reportshare/controller/dto/ReportShareDto.java b/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/reportshare/controller/dto/ReportShareDto.java
index 0b139d01..14690975 100644
--- a/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/reportshare/controller/dto/ReportShareDto.java
+++ b/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/reportshare/controller/dto/ReportShareDto.java
@@ -53,4 +53,9 @@ public class ReportShareDto extends GaeaBaseDTO implements Serializable {
@ApiModelProperty(value = "0--未删除 1--已删除 DIC_NAME=DELETE_FLAG")
private Integer deleteFlag;
+ /** 分享码 */
+ private String sharePassword;
+
+ private boolean sharePasswordFlag = false;
+
}
diff --git a/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/reportshare/dao/entity/ReportShare.java b/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/reportshare/dao/entity/ReportShare.java
index 59bd466d..b2d06a52 100644
--- a/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/reportshare/dao/entity/ReportShare.java
+++ b/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/reportshare/dao/entity/ReportShare.java
@@ -1,11 +1,11 @@
package com.anjiplus.template.gaea.business.modules.reportshare.dao.entity;
-import lombok.Data;
-import io.swagger.annotations.ApiModelProperty;
import com.anji.plus.gaea.curd.entity.GaeaBaseEntity;
+import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
-import javax.validation.constraints.*;
+import lombok.Data;
+
import java.util.Date;
/**
* @description 报表分享 entity
@@ -39,5 +39,12 @@ public class ReportShare extends GaeaBaseEntity {
/** 0--未删除 1--已删除 DIC_NAME=DELETE_FLAG */
private Integer deleteFlag;
+ /** 分享码 */
+ @TableField(exist = false)
+ private String sharePassword;
+
+ @TableField(exist = false)
+ private boolean sharePasswordFlag;
+
}
diff --git a/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/reportshare/service/impl/ReportShareServiceImpl.java b/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/reportshare/service/impl/ReportShareServiceImpl.java
index 60e165c8..5a1b9819 100644
--- a/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/reportshare/service/impl/ReportShareServiceImpl.java
+++ b/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/reportshare/service/impl/ReportShareServiceImpl.java
@@ -13,9 +13,11 @@ import com.anjiplus.template.gaea.business.modules.reportshare.dao.entity.Report
import com.anjiplus.template.gaea.business.modules.reportshare.service.ReportShareService;
import com.anjiplus.template.gaea.business.util.DateUtil;
import com.anjiplus.template.gaea.business.util.JwtUtil;
+import com.anjiplus.template.gaea.business.util.MD5Util;
import com.anjiplus.template.gaea.business.util.UuidUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
+import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@@ -51,12 +53,18 @@ public class ReportShareServiceImpl implements ReportShareService {
@Override
public ReportShareDto insertShare(ReportShareDto dto) {
+ //设置分享码
+ if (dto.isSharePasswordFlag()) {
+ dto.setSharePassword(UuidUtil.getRandomPwd(4));
+ }
+
ReportShareDto reportShareDto = new ReportShareDto();
ReportShare entity = new ReportShare();
BeanUtils.copyProperties(dto, entity);
insert(entity);
//将分享链接返回
reportShareDto.setShareUrl(entity.getShareUrl());
+ reportShareDto.setSharePassword(dto.getSharePassword());
return reportShareDto;
}
@@ -69,6 +77,12 @@ public class ReportShareServiceImpl implements ReportShareService {
if (null == reportShare) {
throw BusinessExceptionBuilder.build(ResponseCode.REPORT_SHARE_LINK_INVALID);
}
+ //解析jwt token,获取密码
+ String password = JwtUtil.getPassword(reportShare.getShareToken());
+ if (StringUtils.isNotBlank(password)) {
+ //md5加密返回
+ reportShare.setSharePassword(MD5Util.encrypt(password));
+ }
return reportShare;
}
@@ -101,7 +115,8 @@ public class ReportShareServiceImpl implements ReportShareService {
} else {
entity.setShareUrl(entity.getShareUrl() + SHARE_FLAG + shareCode);
}
+
entity.setShareValidTime(DateUtil.getFutureDateTmdHms(entity.getShareValidType()));
- entity.setShareToken(JwtUtil.createToken(entity.getReportCode(), shareCode, entity.getShareValidTime()));
+ entity.setShareToken(JwtUtil.createToken(entity.getReportCode(), shareCode, entity.getSharePassword(), entity.getShareValidTime()));
}
}
diff --git a/report-core/src/main/java/com/anjiplus/template/gaea/business/util/JwtUtil.java b/report-core/src/main/java/com/anjiplus/template/gaea/business/util/JwtUtil.java
index c2867eb6..753f4def 100644
--- a/report-core/src/main/java/com/anjiplus/template/gaea/business/util/JwtUtil.java
+++ b/report-core/src/main/java/com/anjiplus/template/gaea/business/util/JwtUtil.java
@@ -7,6 +7,7 @@ import com.auth0.jwt.JWTVerifier;
import com.auth0.jwt.algorithms.Algorithm;
import com.auth0.jwt.interfaces.Claim;
import com.auth0.jwt.interfaces.DecodedJWT;
+import org.apache.commons.lang3.StringUtils;
import java.util.Date;
import java.util.Map;
@@ -19,11 +20,16 @@ public class JwtUtil {
private static final String JWT_SECRET = "aj-report";
public static String createToken(String reportCode, String shareCode, Date expires) {
+ return createToken(reportCode, shareCode, null, expires);
+ }
+
+ public static String createToken(String reportCode, String shareCode, String password, Date expires) {
String token = JWT.create()
.withIssuedAt(new Date())
.withExpiresAt(expires)
.withClaim("reportCode", reportCode)
.withClaim("shareCode", shareCode)
+ .withClaim("sharePassword", password)
.sign(Algorithm.HMAC256(JWT_SECRET));
return token;
}
@@ -55,4 +61,15 @@ public class JwtUtil {
return claim.asString();
}
+ public static String getPassword(String token) {
+ Claim claim = getClaim(token).get("sharePassword");
+ if (null == claim) {
+ return null;
+ }
+ if (StringUtils.isNotBlank(claim.asString())) {
+ return claim.asString();
+ }
+ return null;
+ }
+
}
diff --git a/report-core/src/main/java/com/anjiplus/template/gaea/business/util/UuidUtil.java b/report-core/src/main/java/com/anjiplus/template/gaea/business/util/UuidUtil.java
index b152ea75..40031aab 100644
--- a/report-core/src/main/java/com/anjiplus/template/gaea/business/util/UuidUtil.java
+++ b/report-core/src/main/java/com/anjiplus/template/gaea/business/util/UuidUtil.java
@@ -1,5 +1,6 @@
package com.anjiplus.template.gaea.business.util;
+import java.security.SecureRandom;
import java.util.UUID;
/**
@@ -31,6 +32,24 @@ public class UuidUtil {
}
+ /**
+ * 获取随机小写密码
+ * @param num
+ * @return
+ */
+ public static String getRandomPwd(int num) {
+ StringBuilder builder = new StringBuilder();
+ // 因为已经把 4 种字符放进list了,所以 i 取值从 4开始
+ // 产生随机数用于随机调用生成字符的函数
+ for (int i = 0; i < num; i++) {
+ SecureRandom random = new SecureRandom();
+ int funNum = random.nextInt(chars.length);
+ builder.append(chars[funNum]);
+ }
+
+ return builder.toString().toLowerCase();
+ }
+
public static String generateUuid() {
return UUID.randomUUID().toString().replace("-", "");
@@ -38,7 +57,9 @@ public class UuidUtil {
public static void main(String[] args) {
for (int i = 0; i < 100; i++) {
- System.out.println(generateShortUuid());
+// System.out.println(generateShortUuid());
+ System.out.println(getRandomPwd(4));
}
+
}
}
diff --git a/report-ui/src/views/report/aj/index.vue b/report-ui/src/views/report/aj/index.vue
index 8474facb..369f9e62 100644
--- a/report-ui/src/views/report/aj/index.vue
+++ b/report-ui/src/views/report/aj/index.vue
@@ -6,6 +6,18 @@
!-->