From 821c5ccab6e87d78ee4e4094f6644fdfc8c6765d Mon Sep 17 00:00:00 2001 From: Raod <1130305001@qq.com> Date: Thu, 19 Aug 2021 17:41:43 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=86=E4=BA=AB=E9=87=87=E7=94=A88=E4=BD=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/ReportShareServiceImpl.java | 5 +-- .../template/gaea/business/util/UuidUtil.java | 44 +++++++++++++++++++ 2 files changed, 46 insertions(+), 3 deletions(-) create mode 100644 report-core/src/main/java/com/anjiplus/template/gaea/business/util/UuidUtil.java 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 70b3cb51..60e165c8 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,14 +13,13 @@ 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.UuidUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; -import java.util.UUID; - /** * @desc ReportShare 报表分享服务实现 * @author Raod @@ -94,7 +93,7 @@ public class ReportShareServiceImpl implements ReportShareService { //截取#之前的内容 //http://localhost:9528/#/bigscreen/viewer?reportCode=bigScreen2 //http://127.0.0.1:9095/reportDashboard/getData - String shareCode = UUID.randomUUID().toString(); + String shareCode = UuidUtil.generateShortUuid(); entity.setShareCode(shareCode); if (entity.getShareUrl().contains(SHARE_URL)) { String prefix = entity.getShareUrl().substring(0, entity.getShareUrl().indexOf("#")); 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 new file mode 100644 index 00000000..b152ea75 --- /dev/null +++ b/report-core/src/main/java/com/anjiplus/template/gaea/business/util/UuidUtil.java @@ -0,0 +1,44 @@ +package com.anjiplus.template.gaea.business.util; + +import java.util.UUID; + +/** + * Created by raodeming on 2021/8/19. + */ +public class UuidUtil { + + public static String[] chars = new String[] { "a", "b", "c", "d", "e", "f", + "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", + "t", "u", "v", "w", "x", "y", "z", "0", "1", "2", "3", "4", "5", + "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G", "H", "I", + "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", + "W", "X", "Y", "Z" }; + + + /** + * 8位短id + * @return + */ + public static String generateShortUuid() { + StringBuilder builder = new StringBuilder(); + String uuid = UUID.randomUUID().toString().replace("-", ""); + for (int i = 0; i < 8; i++) { + String str = uuid.substring(i * 4, i * 4 + 4); + int x = Integer.parseInt(str, 16); + builder.append(chars[x % 0x3E]); + } + return builder.toString(); + + } + + + public static String generateUuid() { + return UUID.randomUUID().toString().replace("-", ""); + } + + public static void main(String[] args) { + for (int i = 0; i < 100; i++) { + System.out.println(generateShortUuid()); + } + } +}