Raod 3 tahun lalu
induk
melakukan
7259593066

+ 5 - 0
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;
+
 }

+ 10 - 3
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;
+
 
 }

+ 16 - 1
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()));
     }
 }

+ 17 - 0
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;
+    }
+
 }

+ 22 - 1
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));
         }
+
     }
 }

+ 50 - 6
report-ui/src/views/report/aj/index.vue

@@ -6,6 +6,18 @@
  !-->
 <template>
 <div>
+  <el-dialog
+    title="请输入分享码"
+    :visible.sync="dialogVisible"
+    width="30%"
+    :close-on-click-modal="false"
+    :before-close="handleClose">
+    <el-input v-model="password" placeholder="请输入分享码"></el-input>
+    <span slot="footer" class="dialog-footer">
+    <el-button @click="dialogVisible = false">取 消</el-button>
+    <el-button type="primary" @click="checkPassword()">确 定</el-button>
+  </span>
+  </el-dialog>
 
 </div>
 </template>
@@ -18,7 +30,11 @@ export default {
   },
   data() {
     return {
-
+      password: '',
+      sharePassword: '',
+      dialogVisible: false,
+      reportCode: '',
+      shareToken: ''
     };
   },
 
@@ -33,18 +49,46 @@ export default {
 
       const {code, data} = await reportShareDetailByCode(shareCode)
       if (code != '200') return
-      setShareToken(data.shareToken)
-      //将shareToken缓存在浏览器
-      //跳转至大屏预览页面
+      console.log(data)
+      this.reportCode = data.reportCode
+      this.sharePassword = data.sharePassword
+      this.shareToken = data.shareToken
+      if (this.sharePassword) {
+        console.log(this.sharePassword)
+        this.dialogVisible = true
+      }else {
+        this.pushAj()
+      }
+    },
+    checkPassword(){
+      const md5 = require('js-md5')
+      const inputPassword = md5(this.password);
+      console.log(this.password +'--------------'+inputPassword + "--------" + this.sharePassword)
+      if (inputPassword == this.sharePassword) {
+        this.pushAj()
+      }else {
+        this.$message.error('分享码输入不正确')
+      }
+
+    },
+    pushAj(){
+      setShareToken(this.shareToken)
       this.$router.push({
         path: '/bigscreen/viewer',
         query: {
-          reportCode: data.reportCode
+          reportCode: this.reportCode
         },
       })
-
     },
+    handleClose(done) {
+      this.$confirm('确认关闭?')
+        .then(_ => {
+          done();
+        })
+        .catch(_ => {});
+    }
 
   }
+
 };
 </script>

+ 43 - 11
report-ui/src/views/report/report/components/share.vue

@@ -11,19 +11,40 @@
             </el-form-item>
           </el-col>
         </el-row>
+        <el-row :gutter="10">
+          <el-col :xs="24" :sm="20" :md="6" :lg="6" :xl="6">
+            <el-form-item label="分享码" prop="sharePasswordFlag">
+              <el-switch
+                v-model="dialogForm.sharePasswordFlag">
+              </el-switch>
+            </el-form-item>
+
+          </el-col>
+        </el-row>
       </el-form>
       <el-button type="primary" plain @click="createShare">创建链接</el-button>
     </div>
     <div v-else>
-      <el-row :gutter="10">
-      <el-col :xs="24" :sm="20" :md="20" :lg="20" :xl="16">
-        <el-input v-model="reportShareUrl" :disabled="true"/>
-      </el-col>
-      </el-row>
-      <el-row :gutter="10">
-        <el-button type="primary" plain @click="copyShare">复制链接</el-button>
+      <el-form ref="userForm" :model="dialogForm" :rules="rules" size="small" label-width="100px">
+        <el-row :gutter="10">
+        <el-col :xs="24" :sm="20" :md="20" :lg="20" :xl="16">
+          <el-form-item label="链接" prop="reportShareUrl">
+            <el-input v-model="reportShareUrl" :disabled="true"/>
+          </el-form-item>
+        </el-col>
+        </el-row>
+        <el-row :gutter="10" v-if="dialogForm.sharePassword != ''">
+          <el-col :xs="24" :sm="20" :md="6" :lg="6" :xl="6">
+            <el-form-item label="分享码" prop="sharePassword">
+              <el-input v-model="dialogForm.sharePassword" :disabled="true"/>
+            </el-form-item>
+          </el-col>
+        </el-row>
+        <el-row :gutter="10">
+        <el-button v-if="dialogForm.sharePassword == ''" type="primary" plain @click="copyShare">复制链接</el-button>
+        <el-button v-if="dialogForm.sharePassword != ''" type="primary" plain @click="copyShare">复制链接和分享码</el-button>
       </el-row>
-
+      </el-form>
     </div>
 
     <div slot="footer" style="text-align: center">
@@ -71,6 +92,8 @@ export default {
         reportCode: '',
         shareUrl: '',
         shareCode: '',
+        sharePassword: '',
+        sharePasswordFlag: false,
       },
       shareLinkFlag1: true,
       rules: {
@@ -103,24 +126,33 @@ export default {
       if (code != '200') return
       this.shareValidTypeOptions = data
       this.dialogForm.shareValidType = this.shareValidTypeOptions[0].id
+      this.dialogForm.sharePasswordFlag = false
+      this.dialogForm.sharePassword = ''
     },
     async createShare() {
       this.dialogForm.reportCode = this.reportCode
       this.dialogForm.shareUrl = window.location.href
-      console.log(this.dialogForm)
+      // console.log(this.dialogForm)
       const {code, data} = await reportShareAdd(this.dialogForm)
       if (code != '200') return
-      console.log(data)
+      // console.log(data)
       this.shareLinkFlag1 = false
       this.$message({
         message: '创建链接成功!',
         type: 'success',
       })
       this.reportShareUrl = data.shareUrl
+      this.dialogForm.sharePassword = data.sharePassword
     },
 
     copyShare(){
-      this.copyToClip(this.reportShareUrl)
+      let content = ''
+      if (this.dialogForm.sharePassword == '') {
+        content = 'AJ-Report分享链接:' + this.reportShareUrl
+      }else {
+        content = 'AJ-Report分享链接:' + this.reportShareUrl + '  分享码:' + this.dialogForm.sharePassword;
+      }
+      this.copyToClip(content)
       this.$message({
         message: '复制链接成功!',
         type: 'success',