提交 3f20e23b authored 作者: fit2cloud-chenyw's avatar fit2cloud-chenyw

feat: 公共链接使用8位随机字符后缀,兼容老版本数字后缀

上级 e00785a3
...@@ -11,5 +11,7 @@ public class PanelLinkMapping implements Serializable { ...@@ -11,5 +11,7 @@ public class PanelLinkMapping implements Serializable {
private Long userId; private Long userId;
private String uuid;
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
} }
\ No newline at end of file
...@@ -293,6 +293,76 @@ public class PanelLinkMappingExample { ...@@ -293,6 +293,76 @@ public class PanelLinkMappingExample {
addCriterion("user_id not between", value1, value2, "userId"); addCriterion("user_id not between", value1, value2, "userId");
return (Criteria) this; return (Criteria) this;
} }
public Criteria andUuidIsNull() {
addCriterion("uuid is null");
return (Criteria) this;
}
public Criteria andUuidIsNotNull() {
addCriterion("uuid is not null");
return (Criteria) this;
}
public Criteria andUuidEqualTo(String value) {
addCriterion("uuid =", value, "uuid");
return (Criteria) this;
}
public Criteria andUuidNotEqualTo(String value) {
addCriterion("uuid <>", value, "uuid");
return (Criteria) this;
}
public Criteria andUuidGreaterThan(String value) {
addCriterion("uuid >", value, "uuid");
return (Criteria) this;
}
public Criteria andUuidGreaterThanOrEqualTo(String value) {
addCriterion("uuid >=", value, "uuid");
return (Criteria) this;
}
public Criteria andUuidLessThan(String value) {
addCriterion("uuid <", value, "uuid");
return (Criteria) this;
}
public Criteria andUuidLessThanOrEqualTo(String value) {
addCriterion("uuid <=", value, "uuid");
return (Criteria) this;
}
public Criteria andUuidLike(String value) {
addCriterion("uuid like", value, "uuid");
return (Criteria) this;
}
public Criteria andUuidNotLike(String value) {
addCriterion("uuid not like", value, "uuid");
return (Criteria) this;
}
public Criteria andUuidIn(List<String> values) {
addCriterion("uuid in", values, "uuid");
return (Criteria) this;
}
public Criteria andUuidNotIn(List<String> values) {
addCriterion("uuid not in", values, "uuid");
return (Criteria) this;
}
public Criteria andUuidBetween(String value1, String value2) {
addCriterion("uuid between", value1, value2, "uuid");
return (Criteria) this;
}
public Criteria andUuidNotBetween(String value1, String value2) {
addCriterion("uuid not between", value1, value2, "uuid");
return (Criteria) this;
}
} }
public static class Criteria extends GeneratedCriteria { public static class Criteria extends GeneratedCriteria {
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
<id column="id" jdbcType="BIGINT" property="id" /> <id column="id" jdbcType="BIGINT" property="id" />
<result column="resource_id" jdbcType="VARCHAR" property="resourceId" /> <result column="resource_id" jdbcType="VARCHAR" property="resourceId" />
<result column="user_id" jdbcType="BIGINT" property="userId" /> <result column="user_id" jdbcType="BIGINT" property="userId" />
<result column="uuid" jdbcType="VARCHAR" property="uuid" />
</resultMap> </resultMap>
<sql id="Example_Where_Clause"> <sql id="Example_Where_Clause">
<where> <where>
...@@ -65,7 +66,7 @@ ...@@ -65,7 +66,7 @@
</where> </where>
</sql> </sql>
<sql id="Base_Column_List"> <sql id="Base_Column_List">
id, resource_id, user_id id, resource_id, user_id, uuid
</sql> </sql>
<select id="selectByExample" parameterType="io.dataease.base.domain.PanelLinkMappingExample" resultMap="BaseResultMap"> <select id="selectByExample" parameterType="io.dataease.base.domain.PanelLinkMappingExample" resultMap="BaseResultMap">
select select
...@@ -98,10 +99,10 @@ ...@@ -98,10 +99,10 @@
</if> </if>
</delete> </delete>
<insert id="insert" parameterType="io.dataease.base.domain.PanelLinkMapping"> <insert id="insert" parameterType="io.dataease.base.domain.PanelLinkMapping">
insert into panel_link_mapping (id, resource_id, user_id insert into panel_link_mapping (id, resource_id, user_id,
) uuid)
values (#{id,jdbcType=BIGINT}, #{resourceId,jdbcType=VARCHAR}, #{userId,jdbcType=BIGINT} values (#{id,jdbcType=BIGINT}, #{resourceId,jdbcType=VARCHAR}, #{userId,jdbcType=BIGINT},
) #{uuid,jdbcType=VARCHAR})
</insert> </insert>
<insert id="insertSelective" parameterType="io.dataease.base.domain.PanelLinkMapping"> <insert id="insertSelective" parameterType="io.dataease.base.domain.PanelLinkMapping">
insert into panel_link_mapping insert into panel_link_mapping
...@@ -115,6 +116,9 @@ ...@@ -115,6 +116,9 @@
<if test="userId != null"> <if test="userId != null">
user_id, user_id,
</if> </if>
<if test="uuid != null">
uuid,
</if>
</trim> </trim>
<trim prefix="values (" suffix=")" suffixOverrides=","> <trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null"> <if test="id != null">
...@@ -126,6 +130,9 @@ ...@@ -126,6 +130,9 @@
<if test="userId != null"> <if test="userId != null">
#{userId,jdbcType=BIGINT}, #{userId,jdbcType=BIGINT},
</if> </if>
<if test="uuid != null">
#{uuid,jdbcType=VARCHAR},
</if>
</trim> </trim>
</insert> </insert>
<select id="countByExample" parameterType="io.dataease.base.domain.PanelLinkMappingExample" resultType="java.lang.Long"> <select id="countByExample" parameterType="io.dataease.base.domain.PanelLinkMappingExample" resultType="java.lang.Long">
...@@ -146,6 +153,9 @@ ...@@ -146,6 +153,9 @@
<if test="record.userId != null"> <if test="record.userId != null">
user_id = #{record.userId,jdbcType=BIGINT}, user_id = #{record.userId,jdbcType=BIGINT},
</if> </if>
<if test="record.uuid != null">
uuid = #{record.uuid,jdbcType=VARCHAR},
</if>
</set> </set>
<if test="_parameter != null"> <if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" /> <include refid="Update_By_Example_Where_Clause" />
...@@ -155,7 +165,8 @@ ...@@ -155,7 +165,8 @@
update panel_link_mapping update panel_link_mapping
set id = #{record.id,jdbcType=BIGINT}, set id = #{record.id,jdbcType=BIGINT},
resource_id = #{record.resourceId,jdbcType=VARCHAR}, resource_id = #{record.resourceId,jdbcType=VARCHAR},
user_id = #{record.userId,jdbcType=BIGINT} user_id = #{record.userId,jdbcType=BIGINT},
uuid = #{record.uuid,jdbcType=VARCHAR}
<if test="_parameter != null"> <if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" /> <include refid="Update_By_Example_Where_Clause" />
</if> </if>
...@@ -169,13 +180,17 @@ ...@@ -169,13 +180,17 @@
<if test="userId != null"> <if test="userId != null">
user_id = #{userId,jdbcType=BIGINT}, user_id = #{userId,jdbcType=BIGINT},
</if> </if>
<if test="uuid != null">
uuid = #{uuid,jdbcType=VARCHAR},
</if>
</set> </set>
where id = #{id,jdbcType=BIGINT} where id = #{id,jdbcType=BIGINT}
</update> </update>
<update id="updateByPrimaryKey" parameterType="io.dataease.base.domain.PanelLinkMapping"> <update id="updateByPrimaryKey" parameterType="io.dataease.base.domain.PanelLinkMapping">
update panel_link_mapping update panel_link_mapping
set resource_id = #{resourceId,jdbcType=VARCHAR}, set resource_id = #{resourceId,jdbcType=VARCHAR},
user_id = #{userId,jdbcType=BIGINT} user_id = #{userId,jdbcType=BIGINT},
uuid = #{uuid,jdbcType=VARCHAR}
where id = #{id,jdbcType=BIGINT} where id = #{id,jdbcType=BIGINT}
</update> </update>
</mapper> </mapper>
\ No newline at end of file
...@@ -7,6 +7,7 @@ import javax.crypto.*; ...@@ -7,6 +7,7 @@ import javax.crypto.*;
import javax.crypto.spec.IvParameterSpec; import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec; import javax.crypto.spec.SecretKeySpec;
import java.security.MessageDigest; import java.security.MessageDigest;
import java.util.UUID;
/** /**
* 加密解密工具 * 加密解密工具
...@@ -19,6 +20,13 @@ public class CodingUtil { ...@@ -19,6 +20,13 @@ public class CodingUtil {
private static final char[] HEX_DIGITS = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'}; private static final char[] HEX_DIGITS = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
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" };
/** /**
* MD5加密 * MD5加密
* *
...@@ -165,4 +173,26 @@ public class CodingUtil { ...@@ -165,4 +173,26 @@ public class CodingUtil {
} }
} }
public static boolean isNumeric(String str){
for (int i = str.length();--i>=0;){
if (!Character.isDigit(str.charAt(i))){
return false;
}
}
return true;
}
public static String shortUuid() {
StringBuffer shortBuffer = new StringBuffer();
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);
shortBuffer.append(chars[x % 0x3E]);
}
return shortBuffer.toString();
}
} }
...@@ -3,6 +3,7 @@ package io.dataease.controller; ...@@ -3,6 +3,7 @@ package io.dataease.controller;
import io.dataease.commons.exception.DEException; import io.dataease.commons.exception.DEException;
import io.dataease.commons.license.DefaultLicenseService; import io.dataease.commons.license.DefaultLicenseService;
import io.dataease.commons.license.F2CLicenseResponse; import io.dataease.commons.license.F2CLicenseResponse;
import io.dataease.commons.utils.CodingUtil;
import io.dataease.commons.utils.LogUtil; import io.dataease.commons.utils.LogUtil;
import io.dataease.commons.utils.ServletUtils; import io.dataease.commons.utils.ServletUtils;
import io.dataease.service.panel.PanelLinkService; import io.dataease.service.panel.PanelLinkService;
...@@ -48,8 +49,13 @@ public class IndexController { ...@@ -48,8 +49,13 @@ public class IndexController {
} }
@GetMapping("/link/{index}") @GetMapping("/link/{index}")
public void link(@PathVariable(value = "index", required = true) Long index) { public void link(@PathVariable(value = "index", required = true) String index) {
String url = panelLinkService.getUrlByIndex(index); String url;
if (CodingUtil.isNumeric(index)) {
url = panelLinkService.getUrlByIndex(Long.parseLong(index));
}else {
url = panelLinkService.getUrlByUuid(index);
}
HttpServletResponse response = ServletUtils.response(); HttpServletResponse response = ServletUtils.response();
try { try {
response.sendRedirect(url); response.sendRedirect(url);
...@@ -59,6 +65,8 @@ public class IndexController { ...@@ -59,6 +65,8 @@ public class IndexController {
} }
} }
@GetMapping("/tempMobileLink/{id}/{token}") @GetMapping("/tempMobileLink/{id}/{token}")
public void tempMobileLink(@PathVariable("id") String id, @PathVariable("token") String token) { public void tempMobileLink(@PathVariable("id") String id, @PathVariable("token") String token) {
String url = "/#preview/" + id; String url = "/#preview/" + id;
......
...@@ -8,7 +8,9 @@ import io.dataease.base.mapper.PanelGroupMapper; ...@@ -8,7 +8,9 @@ import io.dataease.base.mapper.PanelGroupMapper;
import io.dataease.base.mapper.PanelLinkMapper; import io.dataease.base.mapper.PanelLinkMapper;
import io.dataease.base.mapper.PanelLinkMappingMapper; import io.dataease.base.mapper.PanelLinkMappingMapper;
import io.dataease.base.mapper.ext.ExtPanelLinkMapper; import io.dataease.base.mapper.ext.ExtPanelLinkMapper;
import io.dataease.commons.exception.DEException;
import io.dataease.commons.utils.AuthUtils; import io.dataease.commons.utils.AuthUtils;
import io.dataease.commons.utils.CodingUtil;
import io.dataease.commons.utils.ServletUtils; import io.dataease.commons.utils.ServletUtils;
import io.dataease.controller.request.panel.link.EnablePwdRequest; import io.dataease.controller.request.panel.link.EnablePwdRequest;
import io.dataease.controller.request.panel.link.LinkRequest; import io.dataease.controller.request.panel.link.LinkRequest;
...@@ -114,7 +116,13 @@ public class PanelLinkService { ...@@ -114,7 +116,13 @@ public class PanelLinkService {
PanelLinkMapping mapping = new PanelLinkMapping(); PanelLinkMapping mapping = new PanelLinkMapping();
mapping.setResourceId(resourceId); mapping.setResourceId(resourceId);
mapping.setUserId(AuthUtils.getUser().getUserId()); mapping.setUserId(AuthUtils.getUser().getUserId());
mapping.setUuid(CodingUtil.shortUuid());
panelLinkMappingMapper.insert(mapping); panelLinkMappingMapper.insert(mapping);
}else {
mappings.stream().filter(mapping -> StringUtils.isBlank(mapping.getUuid())).forEach(item -> {
item.setUuid(CodingUtil.shortUuid());
panelLinkMappingMapper.updateByPrimaryKey(item);
});
} }
return convertDto(one); return convertDto(one);
} }
...@@ -206,7 +214,7 @@ public class PanelLinkService { ...@@ -206,7 +214,7 @@ public class PanelLinkService {
example.createCriteria().andResourceIdEqualTo(resourceId).andUserIdEqualTo(AuthUtils.getUser().getUserId()); example.createCriteria().andResourceIdEqualTo(resourceId).andUserIdEqualTo(AuthUtils.getUser().getUserId());
List<PanelLinkMapping> mappings = panelLinkMappingMapper.selectByExample(example); List<PanelLinkMapping> mappings = panelLinkMappingMapper.selectByExample(example);
PanelLinkMapping mapping = mappings.get(0); PanelLinkMapping mapping = mappings.get(0);
return SHORT_URL_PREFIX + mapping.getId(); return SHORT_URL_PREFIX + mapping.getUuid();
} }
public String getUrlByIndex(Long index) { public String getUrlByIndex(Long index) {
...@@ -216,4 +224,18 @@ public class PanelLinkService { ...@@ -216,4 +224,18 @@ public class PanelLinkService {
PanelLink one = findOne(resourceId, userId); PanelLink one = findOne(resourceId, userId);
return convertDto(one).getUri(); return convertDto(one).getUri();
} }
public String getUrlByUuid(String uuid) {
PanelLinkMappingExample example = new PanelLinkMappingExample();
example.createCriteria().andUuidEqualTo(uuid);
List<PanelLinkMapping> mappings = panelLinkMappingMapper.selectByExample(example);
if (CollectionUtils.isEmpty(mappings)) {
DEException.throwException("link is not exist");
}
PanelLinkMapping mapping = mappings.get(0);
String resourceId = mapping.getResourceId();
Long userId = mapping.getUserId();
PanelLink one = findOne(resourceId, userId);
return convertDto(one).getUri();
}
} }
...@@ -197,3 +197,6 @@ SELECT ...@@ -197,3 +197,6 @@ SELECT
`plugin_sys_menu`.`i_frame` <> 1 `plugin_sys_menu`.`i_frame` <> 1
) )
OR isnull( `plugin_sys_menu`.`i_frame` )); OR isnull( `plugin_sys_menu`.`i_frame` ));
ALTER TABLE `panel_link_mapping`
ADD COLUMN `uuid` varchar(8) NULL COMMENT 'uuid' AFTER `user_id`;
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论