-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
75022d8
commit 108999c
Showing
9 changed files
with
161 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -143,4 +143,7 @@ OAuth 中有四个主要参与者: | |
Aviator 表达式 | ||
Guava maps表达式 | ||
|
||
代码精简 | ||
https://juejin.cn/post/7347905080508547099 | ||
|
||
``` |
24 changes: 24 additions & 0 deletions
24
data-cleaning/src/main/java/com/platform/migrate/dto/UserDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
||
|
||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
data-cleaning/src/main/java/com/platform/migrate/utils/ShortUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
|
||
|
||
|
||
|
||
} | ||
|
||
|
||
|
||
|
||
|
||
} |
21 changes: 21 additions & 0 deletions
21
data-cleaning/src/main/java/com/platform/migrate/web/IndexController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
|
||
|
||
} |
38 changes: 38 additions & 0 deletions
38
data-cleaning/src/main/java/com/platform/migrate/web/ShortController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
server: | ||
port: 9098 | ||
port: 9099 | ||
spring: | ||
profiles: | ||
active: dev | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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); | ||
|
||
|
||
|
||
} | ||
|
||
|