Skip to content

Commit

Permalink
short data
Browse files Browse the repository at this point in the history
  • Loading branch information
thedestiny committed Mar 28, 2024
1 parent 75022d8 commit 108999c
Show file tree
Hide file tree
Showing 9 changed files with 161 additions and 13 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,4 +143,7 @@ OAuth 中有四个主要参与者:
Aviator 表达式
Guava maps表达式

代码精简
https://juejin.cn/post/7347905080508547099

```
24 changes: 24 additions & 0 deletions data-cleaning/src/main/java/com/platform/migrate/dto/UserDto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.platform.migrate.dto;

import lombok.Data;

import java.io.Serializable;

/**
* @Description
* @Author kaiyang
* @Date 2024-03-27 5:25 PM
*/

@Data
public class UserDto implements Serializable {


private String username;

private String password;




}
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,17 @@ public void run(String... args) throws Exception {
.serverTimeZone("Asia/Shanghai")
.build();

final StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();

// 设置 3s 的 checkpoint 间隔
env.enableCheckpointing(3000);
DataStreamSource<String> streamSource = env.fromSource(mySqlSource, WatermarkStrategy.noWatermarks(), "MySQL Source")
// 设置 source 节点的并行度为 1
.setParallelism(1);

// 设置 sink 节点并行度为 1
streamSource.addSink(customSink).setParallelism(1);

env.execute("Print MySQL Snapshot + Binlog");
// final StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
//
// // 设置 3s 的 checkpoint 间隔
// env.enableCheckpointing(3000);
// DataStreamSource<String> streamSource = env.fromSource(mySqlSource, WatermarkStrategy.noWatermarks(), "MySQL Source")
// // 设置 source 节点的并行度为 1
// .setParallelism(1);
//
// // 设置 sink 节点并行度为 1
// streamSource.addSink(customSink).setParallelism(1);
// env.execute("Print MySQL Snapshot + Binlog");
}


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package com.platform.migrate.utils;

import com.google.common.hash.HashFunction;
import com.google.common.hash.Hashing;
import lombok.extern.slf4j.Slf4j;

import java.nio.charset.StandardCharsets;

/**
* @Description
* @Author kaiyang
* @Date 2024-03-28 5:14 PM
*/

@Slf4j
public class ShortUtils {


private static final String BASE62 = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";

public static String toBase62(int value) {
StringBuilder sb = new StringBuilder();
while (value > 0) {
sb.insert(0, BASE62.charAt(value % 62));
value /= 62;
}
return sb.toString();
}

public static void main(String[] args) {

// 长链
String input = "https://hostname/short-link-system/design?code=xsd&page=1";

// 长链利用 MurmurHash算法生成 32位 10进制数
HashFunction hashFunction = Hashing.murmur3_32_fixed();
int hash = hashFunction.hashString(input, StandardCharsets.UTF_8).asInt();
if (hash < 0) {
hash = hash & 0x7fffffff; // Convert to positive by dropping the sign bit
}
// 将 32位 10进制数 转换成 62进制
String base62Hash = toBase62(hash);
System.out.println("base62Hash:" + base62Hash);




}





}
Original file line number Diff line number Diff line change
@@ -1,4 +1,25 @@
package com.platform.migrate.web;


import com.alibaba.fastjson.JSONObject;
import com.platform.migrate.dto.UserDto;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RequestMapping(value = "api")
@RestController
public class IndexController {


@PostMapping(value = "index")
public String index(@RequestBody UserDto dto) {
log.info("information {} ", JSONObject.toJSONString(dto));
return dto.toString();
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.platform.migrate.web;

import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.servlet.view.RedirectView;

/**
* @Description
* @Author kaiyang
* @Date 2024-03-28 5:03 PM
*/

@Slf4j
@Controller
public class ShortController {


/**
* 短链跳转
* 302,代表临时重定向,同样的请求再次访问不会被浏览器缓存,
* 301, 代表永久重定向,同样的请求再次访问会被浏览器缓存
* @param shortCode
* @return
*/
@GetMapping("/{shortCode}")
public RedirectView redirect(@PathVariable String shortCode) {
String destUrl = "https://baidu.com";
// todo some business 统计打开次数
RedirectView view = new RedirectView(destUrl + "/" + shortCode);
view.setStatusCode(HttpStatus.MOVED_PERMANENTLY); // 301
view.setStatusCode(HttpStatus.MOVED_TEMPORARILY); // 302
return view;
}

}
2 changes: 1 addition & 1 deletion data-cleaning/src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
server:
port: 9098
port: 9099
spring:
profiles:
active: dev
Expand Down
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
<module>sandbox-message</module>
<module>sandbox-stock</module>
<module>sandbox-desen</module>
<module>data-cleaning</module>

</modules>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ public static void main(String[] args) {
BigDecimal execute3 = (BigDecimal) AviatorEvaluator.execute("a /b ", env1);
log.info("execute3 is {} ", execute3);

String email = "[email protected]";
Map<String, Object> env2 = new HashMap<>();
env2.put("email", email);
String username =
(String) AviatorEvaluator.execute("email=~/([\\w0-8]+)@\\w+[\\.\\w+]+/ ? $1:'unknow'", env2);
System.out.println(username);



}

Expand Down

0 comments on commit 108999c

Please sign in to comment.