set = new HashSet<>();
50 |
51 | // 冲突率计算公式:
52 | // conflictRate=冲突个数/元素总数:
53 | // 对于 set 集合,不会存储 重复元数-> cr = (总数-set集合个数)/总数
54 |
55 | // 生产 1000000 百万数据
56 | int sum = 1000000;
57 | // 随机产生模拟
58 | RandomStringProvider provider = new RandomStringProvider();
59 | // 测试长度
60 | int length = 12;
61 |
62 | for (int i = 0; i < sum; i++) {
63 | String shotUrl = provider.createWithRandom(length);
64 | //System.out.println(withSnowFlake);
65 | set.add(shotUrl);
66 | //TimeUnit.MILLISECONDS.sleep(random.nextInt(1000));
67 |
68 | }
69 |
70 | System.out.println("元素总数:1000000(一百万)");
71 | System.out.println("set 集合中个数: " +set.size());
72 | System.out.println("重复元素出现次数:"+(sum-set.size()));
73 | // 计算冲突率
74 | double cr = (double)(sum-set.size())/sum;
75 | System.out.println("冲突率: " + cr);
76 |
77 |
78 | }
79 |
80 |
81 |
82 |
83 | }
84 |
--------------------------------------------------------------------------------
/url-core/src/test/java/com/hk/surl/ShortUrlTest.java:
--------------------------------------------------------------------------------
1 | package com.hk.surl;
2 |
3 | import com.hk.surl.core.generator.ShortUrlGenerator;
4 | import com.hk.surl.core.generator.builder.ShortUrlGeneratorBuilder;
5 | import com.hk.surl.core.enums.strategy.EncryptStrategy;
6 | import com.hk.surl.core.provider.random.RandomStringProvider;
7 | import com.hk.surl.domain.entity.ShortUrl;
8 | import com.hk.surl.entity.ShortUrlExt;
9 | import org.junit.Test;
10 |
11 | /**
12 | * @author : HK意境
13 | * @ClassName : ShortUrlTest
14 | * @date : 2022/4/18 21:33
15 | * @description :
16 | * @Todo :
17 | * @Bug :
18 | * @Modified :
19 | * @Version : 1.0
20 | */
21 | public class ShortUrlTest {
22 |
23 | // builder 构造器 V1.0.0 版本
24 | @Test
25 | public void testBuilderApiV1_0_0(){
26 |
27 | /*// 获取 generator 生成器
28 | ShortUrlGenerator generator = new ShortUrlGeneratorBuilder(new ShortUrlExt("https://www.github.com/hk-hub"))
29 | .length(6)
30 | .generateStrategy(new RandomStringProvider())
31 | .enableCache(false)
32 | .encryptStrategy(EncryptStrategy.NONE)
33 | .build();
34 |
35 | // 使用生成器进行链接生成
36 | ShortUrl shortURL = generator.generate();
37 |
38 | System.out.println(shortURL);*/
39 | }
40 |
41 |
42 | // builder 构造器 V1.0.1 版本
43 | @Test
44 | public void testBuilderApiV1_0_1(){
45 |
46 |
47 | }
48 |
49 |
50 | }
51 |
--------------------------------------------------------------------------------
/url-core/src/test/java/com/hk/surl/v2/core/generator/AbstractShortUrlGeneratorTest.java:
--------------------------------------------------------------------------------
1 | package com.hk.surl.v2.core.generator;
2 |
3 | import cn.hutool.core.date.StopWatch;
4 | import com.hk.surl.v2.core.generator.simple.DefaultShortUrlGenerator;
5 | import lombok.extern.slf4j.Slf4j;
6 | import org.junit.jupiter.api.Test;
7 |
8 |
9 | /**
10 | * @author : HK意境
11 | * @ClassName : AbstractShortUrlGeneratorTest
12 | * @date : 2023/6/4 18:08
13 | * @description :
14 | * @Todo :
15 | * @Bug :
16 | * @Modified :
17 | * @Version : 1.0
18 | */
19 | @Slf4j
20 | class AbstractShortUrlGeneratorTest {
21 |
22 | @Test
23 | void generate() {
24 | DefaultShortUrlGenerator generator = new DefaultShortUrlGenerator();
25 | StopWatch stopWatch = new StopWatch();
26 | stopWatch.start();
27 | for (int i = 0; i < 1000000; i++) {
28 | generator.generate(null);
29 | }
30 | stopWatch.stop();
31 |
32 | long totalTimeMillis = stopWatch.getTotalTimeMillis();
33 | log.info("Total time: {}", totalTimeMillis);
34 | }
35 | }
--------------------------------------------------------------------------------
/url-core/src/test/java/com/hk/surl/v2/util/HashUtilTest.java:
--------------------------------------------------------------------------------
1 | package com.hk.surl.v2.util;
2 |
3 | import org.junit.jupiter.api.Test;
4 |
5 | import static org.junit.jupiter.api.Assertions.*;
6 |
7 | /**
8 | * @author : HK意境
9 | * @ClassName : HashUtilTest
10 | * @date : 2023/6/5 19:27
11 | * @description :
12 | * @Todo :
13 | * @Bug :
14 | * @Modified :
15 | * @Version : 1.0
16 | */
17 | class HashUtilTest {
18 |
19 | @Test
20 | void md5() {
21 |
22 | System.out.println(HashUtil.md5("个仍俄国i看图软32件后343467果i具体oh给!gerthytrh"));
23 |
24 | }
25 | }
--------------------------------------------------------------------------------
/url-domain/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | Short-URL
7 | com.hk.surl
8 | 1.0.0-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | url-domain
13 |
14 |
15 |
16 | cn.hutool
17 | hutool-crypto
18 | 5.7.15
19 |
20 |
21 | com.hk.surl
22 | url-common
23 | 0.1.0
24 | compile
25 |
26 |
27 |
28 | com.github.jeffreyning
29 | mybatisplus-plus
30 | 1.5.1-RELEASE
31 |
32 |
33 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/url-domain/src/main/java/com/hk/surl/domain/entity/AnonymousUser.java:
--------------------------------------------------------------------------------
1 | package com.hk.surl.domain.entity;
2 |
3 |
4 | import com.baomidou.mybatisplus.annotation.*;
5 | import com.fasterxml.jackson.annotation.JsonFormat;
6 | import io.swagger.annotations.ApiModel;
7 | import io.swagger.annotations.ApiModelProperty;
8 | import lombok.Data;
9 | import lombok.EqualsAndHashCode;
10 | import lombok.NoArgsConstructor;
11 | import org.springframework.format.annotation.DateTimeFormat;
12 |
13 | import java.io.Serializable;
14 | import java.time.LocalDateTime;
15 |
16 | /**
17 | *
18 | * 匿名用户,临时用户
19 | *
20 | *
21 | * @author HK意境
22 | * @since 2022-05-26
23 | */
24 | @Data
25 | @EqualsAndHashCode(callSuper = false)
26 | @TableName("tb_anonymous_user")
27 | @ApiModel(value="AnonymousUser对象", description="匿名用户,临时用户")
28 | @NoArgsConstructor
29 | public class AnonymousUser implements Serializable {
30 |
31 | private static final long serialVersionUID = 1L;
32 |
33 | @ApiModelProperty(value = "密钥")
34 | private String secretKey;
35 |
36 | @ApiModelProperty(value = "短链接")
37 | private String shortUrl;
38 |
39 | @ApiModelProperty(value = "长链接,可能带有参数")
40 | private String longUrl;
41 |
42 | @ApiModelProperty(value = "匿名用户创建时间")
43 | @TableField(fill = FieldFill.INSERT)
44 | @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
45 | @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss")
46 | private LocalDateTime createTime = LocalDateTime.now();
47 |
48 | @ApiModelProperty(value = "更新时间")
49 | @TableField(fill = FieldFill.INSERT_UPDATE)
50 | @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
51 | @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss")
52 | private LocalDateTime updateTime = this.createTime;
53 |
54 | @ApiModelProperty(value = "逻辑删除")
55 | @TableLogic
56 | private Boolean deleted;
57 |
58 |
59 | public AnonymousUser(String shortUrl, String longUrl, String secretKey) {
60 | this.shortUrl = shortUrl ;
61 | this.longUrl = longUrl ;
62 | this.secretKey = secretKey ;
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/url-domain/src/main/java/com/hk/surl/domain/entity/AppUser.java:
--------------------------------------------------------------------------------
1 | package com.hk.surl.domain.entity;
2 |
3 | import com.baomidou.mybatisplus.annotation.*;
4 | import com.fasterxml.jackson.annotation.JsonFormat;
5 | import io.swagger.annotations.ApiModel;
6 | import io.swagger.annotations.ApiModelProperty;
7 | import lombok.Data;
8 | import lombok.EqualsAndHashCode;
9 | import org.springframework.format.annotation.DateTimeFormat;
10 |
11 | import java.io.Serializable;
12 | import java.time.LocalDateTime;
13 |
14 | /**
15 | *
16 | * 用户User,Sass对外提供接口的使用用户
17 | *
18 | *
19 | * @author HK意境
20 | * @since 2022-05-26
21 | */
22 | @Data
23 | @EqualsAndHashCode(callSuper = false)
24 | @TableName("tb_app_user")
25 | @ApiModel(value="AppUser对象", description="用户User,Sass对外提供接口的使用用户")
26 | public class AppUser implements Serializable {
27 |
28 | private static final long serialVersionUID = 1L;
29 |
30 | @ApiModelProperty(value = "id 号")
31 | @TableId(type = IdType.ASSIGN_ID)
32 | private String id ;
33 |
34 | @ApiModelProperty(value = "用户名")
35 | private String username;
36 |
37 | @ApiModelProperty(value = "密码")
38 | private String password;
39 |
40 | @ApiModelProperty(value = "注册邮箱:日后进行数据报表发送")
41 | private String email;
42 |
43 | @ApiModelProperty(value = "是否为会员")
44 | private Boolean vip;
45 |
46 | @ApiModelProperty(value = "密钥,用户哪来获取报表数据信息的验证")
47 | private String secretKey;
48 |
49 | @ApiModelProperty(value = "可见性")
50 | private Boolean visible;
51 |
52 | @ApiModelProperty(value = "创建时间")
53 | @TableField(fill = FieldFill.INSERT)
54 | @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss")
55 | @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
56 | private LocalDateTime createTime;
57 |
58 | @ApiModelProperty(value = "更新时间")
59 | @TableField(fill = FieldFill.INSERT_UPDATE)
60 | @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
61 | @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss")
62 | private LocalDateTime updateTime;
63 |
64 | @ApiModelProperty(value = "逻辑删除")
65 | @TableLogic
66 | private Boolean deleted;
67 |
68 |
69 | }
70 |
--------------------------------------------------------------------------------
/url-domain/src/main/java/com/hk/surl/domain/entity/LogTrance.java:
--------------------------------------------------------------------------------
1 | package com.hk.surl.domain.entity;
2 |
3 | import com.baomidou.mybatisplus.annotation.FieldFill;
4 | import com.baomidou.mybatisplus.annotation.TableField;
5 | import com.baomidou.mybatisplus.annotation.TableId;
6 | import com.baomidou.mybatisplus.annotation.TableName;
7 | import java.io.Serializable;
8 | import java.time.LocalDateTime;
9 |
10 | import com.fasterxml.jackson.annotation.JsonFormat;
11 | import com.hk.surl.common.util.TranceIdUtil;
12 | import lombok.Data;
13 | import lombok.ToString;
14 | import org.springframework.format.annotation.DateTimeFormat;
15 |
16 | /**
17 | * 系统调用链路日志
18 | * @TableName tb_log_trance
19 | */
20 | @ToString
21 | @Data
22 | @TableName(value ="tb_log_trance")
23 | public class LogTrance implements Serializable {
24 |
25 | @TableField(exist = false)
26 | private static final long serialVersionUID = 1L;
27 |
28 |
29 | /**
30 | * 链路追踪id
31 | */
32 | @TableId(value = "trance_id")
33 | private String tranceId = TranceIdUtil.getTraceId();
34 |
35 | /**
36 | * 业务类型
37 | */
38 | @TableField(value = "business_type")
39 | private String businessType;
40 |
41 | @TableField(value = "business_method")
42 | private String businessMethod ;
43 |
44 | /**
45 | * 业务日志级别
46 | * 0 紧急, 1 重要, 2普通
47 | */
48 | @TableField(value = "level")
49 | private String level;
50 |
51 | /**
52 | * 请求路径
53 | */
54 | @TableField(value = "path")
55 | private String path;
56 |
57 | /**
58 | * ipv4 的客户端ip 地址
59 | */
60 | @TableField(value = "ip_address")
61 | private String ipAddress;
62 |
63 | /**
64 | * 客户端浏览器,操作系统
65 | */
66 | @TableField(value = "user_agent")
67 | private String userAgent;
68 |
69 | /**
70 | * 客户端地址:国家,省份,城市
71 | */
72 | @TableField(value = "location")
73 | private String location;
74 |
75 | /**
76 | * 请求参数
77 | */
78 | @TableField(value = "parameters")
79 | private String parameters;
80 |
81 | /**
82 | * 请求方法
83 | */
84 | @TableField(value = "request_method")
85 | private String requestMethod;
86 |
87 | /**
88 | * 执行的操作
89 | */
90 | @TableField(value = "operate")
91 | private String operate;
92 |
93 | /**
94 | * 操作用户
95 | */
96 | @TableField(value = "operator")
97 | private String operator;
98 |
99 | /**
100 | * 响应结果
101 | */
102 | @TableField(value = "result")
103 | private String result;
104 |
105 | /**
106 | * 响应状态码
107 | */
108 | @TableField(value = "code")
109 | private Integer code;
110 |
111 | /**
112 | * 请求备注,出错原因
113 | */
114 | @TableField(value = "msg")
115 | private String msg;
116 |
117 | /**
118 | * 请求创建时间
119 | */
120 | @TableField(value = "create_time", fill = FieldFill.INSERT)
121 | private LocalDateTime createTime;
122 |
123 | /**
124 | * 请求调用链路执行时间
125 | */
126 | @TableField(value = "execute_time")
127 | private String executeTime;
128 |
129 | /**
130 | * 结束时间
131 | */
132 | @TableField(value = "end_time")
133 | private LocalDateTime endTime;
134 |
135 | @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
136 | @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss")
137 | public LocalDateTime getCreateTime() {
138 | return createTime;
139 | }
140 |
141 |
142 | @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
143 | @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss")
144 | public LocalDateTime getEndTime() {
145 | return endTime;
146 | }
147 | }
--------------------------------------------------------------------------------
/url-domain/src/main/java/com/hk/surl/domain/entity/LongUrl.java:
--------------------------------------------------------------------------------
1 | package com.hk.surl.domain.entity;
2 |
3 | import cn.hutool.http.Method;
4 | import com.baomidou.mybatisplus.annotation.*;
5 | import com.fasterxml.jackson.annotation.JsonFormat;
6 | import io.swagger.annotations.ApiModel;
7 | import io.swagger.annotations.ApiModelProperty;
8 | import lombok.Data;
9 | import lombok.EqualsAndHashCode;
10 | import lombok.NoArgsConstructor;
11 | import org.springframework.format.annotation.DateTimeFormat;
12 |
13 | import java.io.Serializable;
14 | import java.net.URL;
15 | import java.time.LocalDateTime;
16 |
17 | /**
18 | *
19 | * 长链接
20 | *
21 | *
22 | * @author HK意境
23 | * @since 2022-05-26
24 | */
25 | @Data
26 | @EqualsAndHashCode(callSuper = false)
27 | @TableName("tb_long_url")
28 | @ApiModel(value="LongUrl对象", description="长链接")
29 | @NoArgsConstructor
30 | public class LongUrl implements Serializable {
31 |
32 | private static final long serialVersionUID = 1L;
33 |
34 | @ApiModelProperty(value = "id 号")
35 | @TableId(type = IdType.ASSIGN_ID)
36 | private String id ;
37 |
38 | @ApiModelProperty(value = "完整的URL链接,可以是普通http 请求url ,qrcode ,base64等")
39 | private String url;
40 |
41 | @ApiModelProperty(value = "URI 统一资源标识符,url 最后一部分")
42 | private String uri;
43 |
44 | @ApiModelProperty(value = "url 资源类型: request 请求类型,二维码类型,base64类型")
45 | private Integer type;
46 |
47 | @ApiModelProperty(value = "调用协议类型:HHTP,RPC")
48 | private String protocol;
49 |
50 | @ApiModelProperty(value = "远端调用,长链接的请求协议版本")
51 | private String callerVersion;
52 |
53 | @ApiModelProperty(value = "长链接主机地址")
54 | private String host;
55 |
56 | @ApiModelProperty(value = "长链接的端口")
57 | private Integer port;
58 |
59 | @ApiModelProperty(value = "长链接的请求端口")
60 | private String method;
61 |
62 | @ApiModelProperty(value = "url 链接地址请求参数,? 分割")
63 | private String params;
64 |
65 | @ApiModelProperty(value = "是否可见1可见,0不可见")
66 | private Boolean visible;
67 |
68 | @ApiModelProperty(value = "乐观锁")
69 | private Integer version;
70 |
71 | @ApiModelProperty(value = "创建时间")
72 | @TableField(fill = FieldFill.INSERT)
73 | @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss")
74 | @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
75 | private LocalDateTime createTime;
76 |
77 | @ApiModelProperty(value = "更新时间")
78 | @TableField(fill = FieldFill.INSERT_UPDATE)
79 | @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
80 | @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss")
81 | private LocalDateTime updateTime;
82 |
83 | @ApiModelProperty(value = "逻辑删除:0未删除,1已删除 ")
84 | @TableLogic
85 | private Boolean deleted;
86 |
87 |
88 | // 通过 URL 类对象 建立 longUrl 对象
89 | public LongUrl(String content ,URL url){
90 | // 设置长链接
91 | this.setUrl(content);
92 | this.setHost(url.getHost());
93 | this.setParams(url.getQuery());
94 | this.setMethod(Method.GET.name());
95 | this.setPort(url.getPort());
96 | this.setProtocol(url.getProtocol());
97 | this.setUri(url.getPath());
98 | }
99 |
100 |
101 | }
102 |
--------------------------------------------------------------------------------
/url-domain/src/main/java/com/hk/surl/domain/entity/ShortUrl.java:
--------------------------------------------------------------------------------
1 | package com.hk.surl.domain.entity;
2 |
3 | import com.baomidou.mybatisplus.annotation.*;
4 | import com.fasterxml.jackson.annotation.JsonFormat;
5 | import io.swagger.annotations.ApiModel;
6 | import io.swagger.annotations.ApiModelProperty;
7 | import lombok.Data;
8 | import lombok.EqualsAndHashCode;
9 | import lombok.NoArgsConstructor;
10 | import org.springframework.format.annotation.DateTimeFormat;
11 |
12 | import java.io.Serializable;
13 | import java.time.LocalDateTime;
14 |
15 | /**
16 | *
17 | * 短链接表
18 | *
19 | *
20 | * @author HK意境
21 | * @since 2022-05-26
22 | */
23 | @Data
24 | @NoArgsConstructor
25 | @EqualsAndHashCode(callSuper = false)
26 | @TableName("tb_short_url")
27 | @ApiModel(value="ShortUrl对象", description="短链接表")
28 | public class ShortUrl implements Serializable {
29 |
30 | private static final long serialVersionUID = 1L;
31 |
32 | @ApiModelProperty(value = "id 号")
33 | @TableId(type = IdType.ASSIGN_ID)
34 | private String id ;
35 |
36 | @ApiModelProperty(value = "生成后的短链接")
37 | private String shortUrl;
38 |
39 | @ApiModelProperty(value = "短链接类型: http 请求链接,二维码,base64")
40 | private Integer type;
41 |
42 | @ApiModelProperty(value = "编号:目前作用未知")
43 | private String no;
44 |
45 | @ApiModelProperty(value = "可见性:1可见,0不可见")
46 | private Boolean visible = true;
47 |
48 | @ApiModelProperty(value = "创建时间")
49 | private LocalDateTime createTime;
50 |
51 | @ApiModelProperty(value = "过期时间:表示短链接从创建经过到使用到消亡的时间,是指失效的时间: expiration_time=create_time+有效时间")
52 | @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss")
53 | @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
54 | private LocalDateTime expirationTime;
55 |
56 | @ApiModelProperty(value = "乐观锁")
57 | private Integer version;
58 |
59 | @ApiModelProperty(value = "跟新时间 ")
60 | @TableField(fill = FieldFill.INSERT_UPDATE)
61 | @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
62 | @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss")
63 | private LocalDateTime updateTime;
64 |
65 | @ApiModelProperty(value = "是否删除:1可见,0不可见")
66 | @TableLogic
67 | @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
68 | @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss")
69 | private Boolean deleted = false;
70 |
71 |
72 | public ShortUrl(String shortUrl) {
73 | this.shortUrl = shortUrl;
74 | }
75 |
76 |
77 | @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone="GMT+8")
78 | public LocalDateTime getCreateTime() {
79 | return createTime;
80 | }
81 |
82 |
83 | @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone="GMT+8")
84 | public LocalDateTime getExpirationTime() {
85 | return expirationTime;
86 | }
87 |
88 | @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone="GMT+8")
89 | public LocalDateTime getUpdateTime() {
90 | return updateTime;
91 | }
92 | }
93 |
--------------------------------------------------------------------------------
/url-domain/src/main/java/com/hk/surl/domain/entity/VisitLog.java:
--------------------------------------------------------------------------------
1 | package com.hk.surl.domain.entity;
2 |
3 | import com.baomidou.mybatisplus.annotation.*;
4 | import com.fasterxml.jackson.annotation.JsonFormat;
5 | import io.swagger.annotations.ApiModel;
6 | import io.swagger.annotations.ApiModelProperty;
7 | import lombok.Data;
8 | import lombok.EqualsAndHashCode;
9 |
10 | import java.io.Serializable;
11 | import java.time.LocalDateTime;
12 |
13 | /**
14 | *
15 | * 短链接访问日志
16 | *
17 | *
18 | * @author HK意境
19 | * @since 2022-05-26
20 | */
21 | @Data
22 | @EqualsAndHashCode(callSuper = false)
23 | @TableName("tb_visit_log")
24 | @ApiModel(value="VisitLog对象", description="短链接访问日志")
25 | public class VisitLog implements Serializable {
26 |
27 | private static final long serialVersionUID = 1L;
28 |
29 | @ApiModelProperty(value = "id 号")
30 | @TableId(type = IdType.ASSIGN_ID)
31 | private String id ;
32 |
33 | @ApiModelProperty(value = "短链接")
34 | private String shortUrl;
35 |
36 | @ApiModelProperty(value = "长链接")
37 | private String longUrl;
38 |
39 | @ApiModelProperty(value = "访问者的IP地址")
40 | private String visitorIp;
41 |
42 | @ApiModelProperty(value = "请求者refer")
43 | private String referrer = "direct to access";
44 |
45 | @ApiModelProperty(value = "请求的域名")
46 | private String requestHost;
47 |
48 | @ApiModelProperty(value = "长链接(目标链接)域名")
49 | private String targetHost;
50 |
51 | @ApiModelProperty(value = "访问设备:操作系统类型,浏览器类型")
52 | private String equipment;
53 |
54 | @ApiModelProperty(value = "访问地区:国家,省份,市级,区级")
55 | private String visitorArea;
56 |
57 | @ApiModelProperty(value = "访问方法")
58 | private String method;
59 |
60 | @ApiModelProperty(value = "访问时间")
61 | @TableField(fill = FieldFill.INSERT)
62 | @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss")
63 | private LocalDateTime createTime;
64 |
65 | @ApiModelProperty(value = "跟新时间")
66 | @TableField(fill = FieldFill.INSERT_UPDATE)
67 | @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss")
68 | private LocalDateTime updateTime;
69 |
70 | @ApiModelProperty(value = "逻辑删除:1删除,0未删除")
71 | @TableLogic
72 | private Boolean deleted;
73 |
74 |
75 | @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone="GMT+8")
76 | public LocalDateTime getCreateTime() {
77 | return createTime;
78 | }
79 |
80 | @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone="GMT+8")
81 | public LocalDateTime getUpdateTime() {
82 | return updateTime;
83 | }
84 | }
85 |
--------------------------------------------------------------------------------
/url-domain/src/main/java/com/hk/surl/domain/mapper/AnonymousUserMapper.java:
--------------------------------------------------------------------------------
1 | package com.hk.surl.domain.mapper;
2 |
3 | import com.baomidou.mybatisplus.core.mapper.BaseMapper;
4 | import com.hk.surl.domain.entity.AnonymousUser;
5 | import com.hk.surl.domain.entity.ShortUrl;
6 | import org.apache.ibatis.annotations.Mapper;
7 | import org.apache.ibatis.annotations.Param;
8 | import org.apache.ibatis.annotations.Select;
9 |
10 | import java.time.LocalDateTime;
11 | import java.util.List;
12 |
13 |
14 | /**
15 | *
16 | * 匿名用户,临时用户 Mapper 接口
17 | *
18 | *
19 | * @author HK意境
20 | * @since 2022-05-26
21 | */
22 | @Mapper
23 | public interface AnonymousUserMapper extends BaseMapper {
24 |
25 |
26 | // 匿名用户登录
27 | AnonymousUser anonymousUserLogin(@Param("shortUrl") String shortUrl, @Param("secretKey") String secretKey);
28 |
29 |
30 | // 根据短链接查询
31 | @Select("select * from tb_anonymous_user where short_url = #{shortUrl} and deleted = false")
32 | AnonymousUser selectOneByShortUrl(ShortUrl shortUrl);
33 | }
34 |
--------------------------------------------------------------------------------
/url-domain/src/main/java/com/hk/surl/domain/mapper/AppUserMapper.java:
--------------------------------------------------------------------------------
1 | package com.hk.surl.domain.mapper;
2 |
3 |
4 | import com.baomidou.mybatisplus.core.mapper.BaseMapper;
5 | import com.hk.surl.domain.entity.AppUser;
6 | import org.apache.ibatis.annotations.Mapper;
7 |
8 | /**
9 | *
10 | * 用户User,Sass对外提供接口的使用用户 Mapper 接口
11 | *
12 | *
13 | * @author HK意境
14 | * @since 2022-05-26
15 | */
16 | @Mapper
17 | public interface AppUserMapper extends BaseMapper {
18 |
19 | }
20 |
--------------------------------------------------------------------------------
/url-domain/src/main/java/com/hk/surl/domain/mapper/LogTranceMapper.java:
--------------------------------------------------------------------------------
1 | package com.hk.surl.domain.mapper;
2 |
3 | import com.baomidou.mybatisplus.core.mapper.BaseMapper;
4 | import com.hk.surl.domain.entity.LogTrance;
5 | import org.apache.ibatis.annotations.Mapper;
6 |
7 |
8 | /**
9 | * @Entity com.hk.surl.common.log.LogTrance
10 | */
11 | @Mapper
12 | public interface LogTranceMapper extends BaseMapper {
13 |
14 | }
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/url-domain/src/main/java/com/hk/surl/domain/mapper/LongUrlMapper.java:
--------------------------------------------------------------------------------
1 | package com.hk.surl.domain.mapper;
2 |
3 | import com.baomidou.mybatisplus.core.mapper.BaseMapper;
4 | import com.hk.surl.domain.entity.LongUrl;
5 | import org.apache.ibatis.annotations.Mapper;
6 | import org.apache.ibatis.annotations.Select;
7 |
8 | import java.util.List;
9 |
10 |
11 | /**
12 | *
13 | * 长链接 Mapper 接口
14 | *
15 | *
16 | * @author HK意境
17 | * @since 2022-05-26
18 | */
19 | @Mapper
20 | public interface LongUrlMapper extends BaseMapper {
21 |
22 | /**
23 | * @methodName : selectListByIds
24 | * @author : HK意境
25 | * @date : 2022/6/10 21:26
26 | * @description : 使用 xml 方式 in 集合查询,速度由于 mybatis plus 的批量查询
27 | * @Todo :
28 | * @apiNote : 根据 id 集合查询长链接对象集合
29 | * @params :
30 | * @param ids 长链接对象 id 集合列表
31 | * @return List
32 | * @throws:
33 | * @Bug :
34 | * @Modified :
35 | * @Version : 1.0.0
36 | */
37 | List selectLongUrlListByIds(List ids);
38 |
39 | // 通过 长链接字符串获取长链接字符串
40 | @Select("select * from tb_long_url where url = #{longUrl} limit 1")
41 | LongUrl selectOneByLongUrl(String longUrl);
42 |
43 |
44 | }
45 |
--------------------------------------------------------------------------------
/url-domain/src/main/java/com/hk/surl/domain/mapper/ShortUrlMapper.java:
--------------------------------------------------------------------------------
1 | package com.hk.surl.domain.mapper;
2 |
3 |
4 | import com.baomidou.mybatisplus.core.mapper.BaseMapper;
5 | import com.hk.surl.domain.entity.LongUrl;
6 | import com.hk.surl.domain.entity.ShortUrl;
7 | import org.apache.ibatis.annotations.Mapper;
8 | import org.apache.ibatis.annotations.Param;
9 | import org.apache.ibatis.annotations.Select;
10 |
11 | import java.time.LocalDateTime;
12 | import java.util.List;
13 |
14 | /**
15 | *
16 | * 短链接表 Mapper 接口
17 | *
18 | *
19 | * @author HK意境
20 | * @since 2022-05-26
21 | */
22 | @Mapper
23 | public interface ShortUrlMapper extends BaseMapper {
24 |
25 | // 因为这里,一个长链接只能生成对应的唯一的一个短链接,但是我们的一个短链接对象是可以对应多个长链接对象的
26 | // 根据 根据长链接对象 id 关联查询 url_map 表,获取对应 短链接 id
27 | // select su.* from tb_short_url as su where su.id in (
28 | // select m.short_url_id from tn_url_map as m where m.long_url = #{longUrl} and m.visible = true ;
29 | // )
30 | ShortUrl selectShortUrlByLongUrl(@Param(value = "longUrl") LongUrl longUrl);
31 |
32 |
33 | // 查询指定短链接字符串的链接对象
34 | @Select("select * from tb_short_url where short_url = #{shortUrlStr} " + "and visible = true")
35 | ShortUrl selectByShortUrl(String shortUrlStr);
36 |
37 | // 查询指定时间内新增的短链接
38 | /**
39 | * @methodName : selectAllByCreateTime
40 | * @author : HK意境
41 | * @date : 2022/6/11 21:35
42 | * @description :
43 | * @Todo :
44 | * @apiNote :
45 | * @params :
46 | * @param startTime 开始时间
47 | * @param endTime 结束时间
48 | * @return List
49 | * @throws:
50 | * @Bug :
51 | * @Modified :
52 | * @Version : 1.0.0
53 | */
54 | @Select("select * from tb_short_url where create_time between(#{startTime},#{endTime})")
55 | List selectAllByCreateTime(LocalDateTime startTime , LocalDateTime endTime);
56 |
57 | // 查询指定有效期内的短链接对象
58 | /**
59 | * @methodName : selectAllByExpirationTime
60 | * @author : HK意境
61 | * @date : 2022/6/11 21:37
62 | * @description : 查询过期时间在指定范围的短链接数量
63 | * @Todo :
64 | * @apiNote :
65 | * @params :
66 | * @param startTime 开始时间
67 | * @param expirationTime 结束时间,过期时间
68 | * @return List
69 | * @throws:
70 | * @Bug :
71 | * @Modified :
72 | * @Version : 1.0.0
73 | */
74 | @Select("select * from tb_short_url where expiration_time between(#{startTime}, #{expirationTime}")
75 | List selectAllByExpirationTime(LocalDateTime startTime ,LocalDateTime expirationTime);
76 |
77 |
78 |
79 |
80 |
81 |
82 | }
83 |
--------------------------------------------------------------------------------
/url-domain/src/main/java/com/hk/surl/domain/mapper/UrlMapMapper.java:
--------------------------------------------------------------------------------
1 | package com.hk.surl.domain.mapper;
2 |
3 | import com.baomidou.mybatisplus.core.mapper.BaseMapper;
4 | import com.hk.surl.domain.entity.UrlMap;
5 | import org.apache.ibatis.annotations.Mapper;
6 | import org.apache.ibatis.annotations.Select;
7 |
8 | import java.time.LocalDateTime;
9 | import java.util.List;
10 | import java.util.Map;
11 |
12 | /**
13 | *
14 | * 长链接和短链接的映射关系 Mapper 接口
15 | *
16 | *
17 | * @author HK意境
18 | * @since 2022-05-26
19 | */
20 | @Mapper
21 | public interface UrlMapMapper extends BaseMapper {
22 |
23 | // 查询短链接id 对应的长链接 id 集合
24 | // select m.long_id from tb_url_map as m where m.short_id = #{shortId}
25 | List selectLongIdByShortId(String shortId);
26 |
27 |
28 | // 通过 短链接id 值查询所有
29 | @Select("select * from tb_url_map where short_id = #{shortId} "+ "and visible = true")
30 | List selectAllByShortId(String shortId);
31 |
32 | // 通过短链接字符串查询所有
33 | @Select("select * from tb_url_map where short_url = #{shortUrl} "+ "and visible = true")
34 | List selectByShortUrl(String shortUrl);
35 |
36 | // 通过长链接id 查询所有,但是其实是长链接对短链接是多对一的,所有查询出来也只有一个
37 | @Select("select * from tb_url_map where long_id = #{longId} "+ "and visible = true")
38 | List selectAllByLongId(String longId);
39 |
40 | // 通过长链接字符串查询所有, 但是这里其实一个长链接只对应一个短链接,所有也就相当于查询一个
41 | @Select("select * from tb_url_map where long_url = #{longUrl} "+ "and visible = true")
42 | List selectAllByLongUrl(String longUrl);
43 |
44 | // 通过长链接id, 短链接id 唯一查询一个映射对象
45 | @Select("select * from tb_url_map where short_id = #{shortId} and long_id = #{longId} " + "and visible = true")
46 | UrlMap selectByShortIdAndLongId(String shortId, String longId);
47 |
48 | // 通过长链接字符串,短链接字符串查询唯一一个映射对象
49 | @Select("select * from tb_url_mao where short_url = #{shortUrl} and long_url = #{longUrl} "+ "and visible = true" )
50 | UrlMap selectByShortUrlAndShortUrl(String shortUrl, String longUrl);
51 |
52 | // 通过长链接MD5值 查询映射对象
53 | @Select("select * from tb_url_map where long_md = #{md} " + "and visible = true")
54 | UrlMap selectByLongMd(String md);
55 |
56 | // 查询所有,包括不可见和逻辑删除的
57 | @Select("select * from tb_url_map where deleted=true or deleted = false")
58 | List selectAllIgnoreVisibleAndDeleted();
59 |
60 | // 查询所有,包括不可见的
61 | @Select("select * from tb_url_map where deleted = false")
62 | List selectAllIgnoreVisible();
63 |
64 |
65 | /**
66 | * @methodName :
67 | * @author : HK意境
68 | * @date : 2022/6/11 21:17
69 | * @description : 查询指定时间内的新增映射对象,也就为指定时间内新增的短链接
70 | * @Todo :
71 | * @apiNote :
72 | * @params :
73 | * @param startTime 开始时间点
74 | * @param endTime 结束时间点
75 | * @return List
76 | * @throws:
77 | * @Bug :
78 | * @Modified :
79 | * @Version : 1.0.0
80 | */
81 | @Select("select * from tb_url_map where create_time between(#{startTime}, #{endTime}) " + "and visible = true")
82 | List selectAllByCreateTime(LocalDateTime startTime, LocalDateTime endTime);
83 |
84 |
85 |
86 | }
87 |
--------------------------------------------------------------------------------
/url-domain/src/main/java/com/hk/surl/domain/mapper/VisitLogMapper.java:
--------------------------------------------------------------------------------
1 | package com.hk.surl.domain.mapper;
2 |
3 |
4 | import com.baomidou.mybatisplus.core.mapper.BaseMapper;
5 | import com.hk.surl.domain.entity.VisitLog;
6 | import org.apache.ibatis.annotations.Mapper;
7 | import org.apache.ibatis.annotations.Param;
8 | import org.apache.ibatis.annotations.Select;
9 |
10 | import java.time.LocalDateTime;
11 | import java.util.List;
12 | import java.util.Map;
13 |
14 | /**
15 | *
16 | * 短链接访问日志 Mapper 接口
17 | *
18 | *
19 | * @author HK意境
20 | * @since 2022-05-26
21 | */
22 | @Mapper
23 | public interface VisitLogMapper extends BaseMapper {
24 |
25 |
26 | // 查询指定短链接的访问数据
27 | @Select("select * from tb_visit_log where short_url = #{shortUrl} order by create_time desc")
28 | List selectListByShortUrl(@Param(value = "shortUrl") String shortUrl);
29 |
30 | // 查询指定日期内的访问数据
31 | List selectListByAccessTimeOrShortUrl(@Param(value = "shortUrl")String shortUrl ,
32 | @Param(value = "startTime")LocalDateTime startTime ,
33 | @Param(value = "endTime")LocalDateTime endTime);
34 |
35 | // 指定时间内新增的访问用户
36 | // 查询指定时间内的访问记录,投影取出ip 地址, 判断不属于指定时间以前的ip 地址
37 | List getNewVisitDataByDatetime(@Param("shortUrl") String shortUrl,
38 | @Param("startTime")LocalDateTime startTime, @Param("endTime")LocalDateTime endTime);
39 |
40 | // 查询指定短链接创建以来的每天的访问数据
41 | List