mirror of
https://github.com/qaiu/netdisk-fast-download.git
synced 2025-12-16 04:13:03 +00:00
Merge remote-tracking branch 'origin/main'
# Conflicts: # lz-cow-api-web/src/main/java/cn/qaiu/lz/common/util/LzTool.java # lz-cow-api-web/src/main/resources/logback.xml
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
@echo off && @chcp 65001 > nul
|
||||
pushd %~dp0
|
||||
set LIB_DIR=%~dp0
|
||||
for /f "delims=X" %%i in ('dir /b %LIB_DIR%\web-*.jar') do set LAUNCH_JAR=%LIB_DIR%\%%i
|
||||
"%JAVA_HOME%\bin\java.exe" -Xmx512M -Dfile.encoding=utf8 -jar %LAUNCH_JAR% %*
|
||||
for /f "delims=X" %%i in ('dir /b %LIB_DIR%\lz-cow-api-web-*.jar') do set LAUNCH_JAR=%LIB_DIR%\%%i
|
||||
"%JAVA_HOME%\bin\java.exe" -Xmx512M -Dfile.encoding=utf8 -jar %LAUNCH_JAR% %*
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#!/bin/sh
|
||||
# set -x
|
||||
LAUNCH_JAR="web-*.jar"
|
||||
LAUNCH_JAR="lz-cow-api-web-*.jar"
|
||||
nohup java -Xmx512M -jar "$LAUNCH_JAR" "$@" >startup.log 2>&1 &
|
||||
tail -f startup.log
|
||||
tail -f startup.log
|
||||
|
||||
65
core-database/pom.xml
Normal file
65
core-database/pom.xml
Normal file
@@ -0,0 +1,65 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>lz-cow-api</artifactId>
|
||||
<groupId>cn.qaiu</groupId>
|
||||
<version>0.0.1</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>core-database</artifactId>
|
||||
|
||||
<properties>
|
||||
<java.version>17</java.version>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<slf4j.version>2.0.5</slf4j.version>
|
||||
<commons-lang3.version>3.12.0</commons-lang3.version>
|
||||
<vertx.version>4.4.1</vertx.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>cn.qaiu</groupId>
|
||||
<artifactId>core</artifactId>
|
||||
<version>1.0.8</version>
|
||||
</dependency>
|
||||
|
||||
<!-- https://mvnrepository.com/artifact/com.h2database/h2 -->
|
||||
<dependency>
|
||||
<groupId>com.h2database</groupId>
|
||||
<artifactId>h2</artifactId>
|
||||
<version>2.1.214</version>
|
||||
</dependency>
|
||||
|
||||
<!-- https://mvnrepository.com/artifact/com.zaxxer/HikariCP -->
|
||||
<dependency>
|
||||
<groupId>com.zaxxer</groupId>
|
||||
<artifactId>HikariCP</artifactId>
|
||||
<version>5.0.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
<version>3.12.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.vertx</groupId>
|
||||
<artifactId>vertx-codegen</artifactId>
|
||||
<scope>compile</scope>
|
||||
<version>${vertx.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.vertx</groupId>
|
||||
<artifactId>vertx-sql-client-templates</artifactId>
|
||||
<version>${vertx.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.vertx</groupId>
|
||||
<artifactId>vertx-jdbc-client</artifactId>
|
||||
<version>${vertx.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,7 @@
|
||||
package cn.qaiu;
|
||||
|
||||
public class StartH2DatabaseServer {
|
||||
public static void main(String[] args) {
|
||||
System.out.println("Hello world!");
|
||||
}
|
||||
}
|
||||
45
core-database/src/main/java/cn/qaiu/db/ddl/Constraint.java
Normal file
45
core-database/src/main/java/cn/qaiu/db/ddl/Constraint.java
Normal file
@@ -0,0 +1,45 @@
|
||||
package cn.qaiu.db.ddl;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
|
||||
/**
|
||||
* 建表约束类型
|
||||
*
|
||||
* <br>Create date 2021/7/22 0:42
|
||||
* @author <a href="https://qaiu.top">QAIU</a>
|
||||
*/
|
||||
@Documented
|
||||
@Inherited
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target({ElementType.TYPE, ElementType.FIELD})
|
||||
public @interface Constraint {
|
||||
|
||||
/**
|
||||
* 非空约束
|
||||
* @return false 可以为空
|
||||
*/
|
||||
boolean notNull() default false;
|
||||
|
||||
/**
|
||||
* 唯一键约束 TODO 待实现
|
||||
* @return 唯一键约束
|
||||
*/
|
||||
String uniqueKey() default "";
|
||||
|
||||
/**
|
||||
* 默认值约束
|
||||
* @return 默认值约束
|
||||
*/
|
||||
String defaultValue() default "";
|
||||
/**
|
||||
* 默认值是否是函数
|
||||
* @return false 不是函数
|
||||
*/
|
||||
boolean defaultValueIsFunction() default false;
|
||||
|
||||
/**
|
||||
* 是否自增 只能用于int或long类型上
|
||||
* @return false 不自增
|
||||
*/
|
||||
boolean autoIncrement() default false;
|
||||
}
|
||||
170
core-database/src/main/java/cn/qaiu/db/ddl/CreateTable.java
Normal file
170
core-database/src/main/java/cn/qaiu/db/ddl/CreateTable.java
Normal file
@@ -0,0 +1,170 @@
|
||||
package cn.qaiu.db.ddl;
|
||||
|
||||
import cn.qaiu.vx.core.util.ReflectionUtil;
|
||||
import io.vertx.codegen.format.CamelCase;
|
||||
import io.vertx.codegen.format.Case;
|
||||
import io.vertx.codegen.format.LowerCamelCase;
|
||||
import io.vertx.codegen.format.SnakeCase;
|
||||
import io.vertx.jdbcclient.JDBCPool;
|
||||
import io.vertx.sqlclient.templates.annotations.Column;
|
||||
import io.vertx.sqlclient.templates.annotations.RowMapped;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* 创建表
|
||||
*
|
||||
* @author <a href="https://qaiu.top">QAIU</a>
|
||||
*/
|
||||
public class CreateTable {
|
||||
public static Map<Class<?>, String> javaProperty2SqlColumnMap = new HashMap<>();
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(CreateTable.class);
|
||||
|
||||
static {
|
||||
javaProperty2SqlColumnMap.put(Integer.class, "INT");
|
||||
javaProperty2SqlColumnMap.put(Short.class, "SMALLINT");
|
||||
javaProperty2SqlColumnMap.put(Byte.class, "TINYINT");
|
||||
javaProperty2SqlColumnMap.put(Long.class, "BIGINT");
|
||||
javaProperty2SqlColumnMap.put(java.math.BigDecimal.class, "DECIMAL");
|
||||
javaProperty2SqlColumnMap.put(Double.class, "DOUBLE");
|
||||
javaProperty2SqlColumnMap.put(Float.class, "REAL");
|
||||
javaProperty2SqlColumnMap.put(Boolean.class, "BOOLEAN");
|
||||
javaProperty2SqlColumnMap.put(String.class, "VARCHAR");
|
||||
javaProperty2SqlColumnMap.put(java.util.Date.class, "TIMESTAMP");
|
||||
javaProperty2SqlColumnMap.put(java.sql.Timestamp.class, "TIMESTAMP");
|
||||
javaProperty2SqlColumnMap.put(java.sql.Date.class, "DATE");
|
||||
javaProperty2SqlColumnMap.put(java.sql.Time.class, "TIME");
|
||||
|
||||
javaProperty2SqlColumnMap.put(int.class, "INT");
|
||||
javaProperty2SqlColumnMap.put(short.class, "SMALLINT");
|
||||
javaProperty2SqlColumnMap.put(byte.class, "TINYINT");
|
||||
javaProperty2SqlColumnMap.put(long.class, "BIGINT");
|
||||
javaProperty2SqlColumnMap.put(double.class, "DOUBLE");
|
||||
javaProperty2SqlColumnMap.put(float.class, "REAL");
|
||||
javaProperty2SqlColumnMap.put(boolean.class, "BOOLEAN");
|
||||
}
|
||||
|
||||
private static Case getCase(Class<?> clz) {
|
||||
switch (clz.getName()) {
|
||||
case "io.vertx.codegen.format.CamelCase":
|
||||
return CamelCase.INSTANCE;
|
||||
case "io.vertx.codegen.format.SnakeCase":
|
||||
return SnakeCase.INSTANCE;
|
||||
case "io.vertx.codegen.format.LowerCamelCase":
|
||||
return LowerCamelCase.INSTANCE;
|
||||
default:
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
|
||||
public static String getCreateTableSQL(Class<?> clz) {
|
||||
// 判断类上是否有次注解
|
||||
String primaryKey = null; // 主键
|
||||
String tableName = null; // 表名
|
||||
Case caseFormat = SnakeCase.INSTANCE;
|
||||
if (clz.isAnnotationPresent(RowMapped.class)) {
|
||||
RowMapped annotation = clz.getAnnotation(RowMapped.class);
|
||||
Class<? extends Case> formatter = annotation.formatter();
|
||||
caseFormat = getCase(formatter);
|
||||
}
|
||||
|
||||
if (clz.isAnnotationPresent(Table.class)) {
|
||||
// 获取类上的注解
|
||||
Table annotation = clz.getAnnotation(Table.class);
|
||||
// 输出注解上的类名
|
||||
String tableNameAnnotation = annotation.value();
|
||||
if (StringUtils.isNotEmpty(tableNameAnnotation)) {
|
||||
tableName = tableNameAnnotation;
|
||||
} else {
|
||||
tableName = LowerCamelCase.INSTANCE.to(caseFormat, clz.getSimpleName());
|
||||
}
|
||||
primaryKey = annotation.keyFields();
|
||||
}
|
||||
Field[] fields = clz.getDeclaredFields();
|
||||
String column;
|
||||
int[] decimalSize = {22, 2};
|
||||
int varcharSize = 255;
|
||||
StringBuilder sb = new StringBuilder(50);
|
||||
sb.append("CREATE TABLE IF NOT EXISTS \"").append(tableName).append("\" ( \r\n ");
|
||||
boolean firstId = true;
|
||||
for (Field f : fields) {
|
||||
Class<?> paramType = f.getType();
|
||||
String sqlType = javaProperty2SqlColumnMap.get(paramType);
|
||||
if (f.getName().equals("serialVersionUID") || StringUtils.isEmpty(sqlType) || f.isAnnotationPresent(TableGenIgnore.class)) {
|
||||
continue;
|
||||
}
|
||||
column = LowerCamelCase.INSTANCE.to(caseFormat, f.getName());
|
||||
if (f.isAnnotationPresent(Column.class)) {
|
||||
Column columnAnnotation = f.getAnnotation(Column.class);
|
||||
//输出注解属性
|
||||
if (StringUtils.isNotBlank(columnAnnotation.name())) {
|
||||
column = columnAnnotation.name();
|
||||
}
|
||||
}
|
||||
if (f.isAnnotationPresent(Length.class)) {
|
||||
Length fieldAnnotation = f.getAnnotation(Length.class);
|
||||
decimalSize = fieldAnnotation.decimalSize();
|
||||
varcharSize = fieldAnnotation.varcharSize();
|
||||
}
|
||||
sb.append("\"").append(column).append("\"");
|
||||
sb.append(" ").append(sqlType);
|
||||
// 添加类型长度
|
||||
if (sqlType.equals("DECIMAL")) {
|
||||
sb.append("(").append(decimalSize[0]).append(",").append(decimalSize[1]).append(")");
|
||||
}
|
||||
if (sqlType.equals("VARCHAR")) {
|
||||
sb.append("(").append(varcharSize).append(")");
|
||||
}
|
||||
if (f.isAnnotationPresent(Constraint.class)) {
|
||||
Constraint constraintAnnotation = f.getAnnotation(Constraint.class);
|
||||
if (constraintAnnotation.notNull()) {
|
||||
//非空约束
|
||||
sb.append(" NOT NULL");
|
||||
}
|
||||
String apostrophe = constraintAnnotation.defaultValueIsFunction() ? "" : "'";
|
||||
if (StringUtils.isNotEmpty(constraintAnnotation.defaultValue())) {
|
||||
//默认值约束
|
||||
sb.append(" DEFAULT ").append(apostrophe).append(constraintAnnotation.defaultValue()).append(apostrophe);
|
||||
}
|
||||
if (constraintAnnotation.autoIncrement() && paramType.equals(Integer.class) || paramType.equals(Long.class)) {
|
||||
////自增
|
||||
sb.append(" AUTO_INCREMENT");
|
||||
}
|
||||
}
|
||||
if (StringUtils.isEmpty(primaryKey)) {
|
||||
if (firstId) {//类型转换
|
||||
sb.append(" PRIMARY KEY");
|
||||
firstId = false;
|
||||
}
|
||||
} else {
|
||||
if (primaryKey.equals(column.toLowerCase())) {
|
||||
sb.append(" PRIMARY KEY");
|
||||
}
|
||||
}
|
||||
sb.append(",\n ");
|
||||
}
|
||||
String sql = sb.toString();
|
||||
//去掉最后一个逗号
|
||||
int lastIndex = sql.lastIndexOf(",");
|
||||
sql = sql.substring(0, lastIndex) + sql.substring(lastIndex + 1);
|
||||
return sql.substring(0, sql.length() - 1) + ");\r\n";
|
||||
}
|
||||
|
||||
public static void createTable(JDBCPool pool, String tableClassPath) {
|
||||
Set<Class<?>> tableClassList = ReflectionUtil.getReflections(tableClassPath).getTypesAnnotatedWith(Table.class);
|
||||
if (tableClassList.isEmpty()) LOGGER.info("Table model class not fount");
|
||||
tableClassList.forEach(clazz -> {
|
||||
String createTableSQL = getCreateTableSQL(clazz);
|
||||
pool.query(createTableSQL).execute().onSuccess(
|
||||
rs -> LOGGER.info("\n" + createTableSQL + "create table --> ok")
|
||||
).onFailure(Throwable::printStackTrace);
|
||||
});
|
||||
}
|
||||
}
|
||||
16
core-database/src/main/java/cn/qaiu/db/ddl/Length.java
Normal file
16
core-database/src/main/java/cn/qaiu/db/ddl/Length.java
Normal file
@@ -0,0 +1,16 @@
|
||||
package cn.qaiu.db.ddl;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
|
||||
/**
|
||||
* 字段长度属性
|
||||
* @author <a href="https://qaiu.top">QAIU</a>
|
||||
*/
|
||||
@Documented
|
||||
@Inherited
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target({ElementType.TYPE, ElementType.FIELD})
|
||||
public @interface Length {
|
||||
int[] decimalSize() default {22,2}; //bigDecimal精度
|
||||
int varcharSize() default 255; //varchar大小
|
||||
}
|
||||
17
core-database/src/main/java/cn/qaiu/db/ddl/Table.java
Normal file
17
core-database/src/main/java/cn/qaiu/db/ddl/Table.java
Normal file
@@ -0,0 +1,17 @@
|
||||
package cn.qaiu.db.ddl;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
|
||||
/**
|
||||
* 标注建表的实体类和主键字段
|
||||
*
|
||||
* @author <a href="https://qaiu.top">QAIU</a>
|
||||
*/
|
||||
@Documented
|
||||
@Inherited
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target({ElementType.TYPE, ElementType.FIELD})//次注解作用于类和字段上
|
||||
public @interface Table {
|
||||
String value() default ""; //默认表名为空
|
||||
String keyFields() default "id"; //默认主键为id
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package cn.qaiu.db.ddl;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
|
||||
/**
|
||||
* 建表时忽略字段
|
||||
* <br>Create date 2021/8/27 15:49
|
||||
*
|
||||
* @author <a href="https://qaiu.top">QAIU</a>
|
||||
*/
|
||||
@Documented
|
||||
@Inherited
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target({ElementType.TYPE, ElementType.FIELD})
|
||||
public @interface TableGenIgnore {
|
||||
}
|
||||
140
core-database/src/main/java/cn/qaiu/db/pool/JDBCPoolInit.java
Normal file
140
core-database/src/main/java/cn/qaiu/db/pool/JDBCPoolInit.java
Normal file
@@ -0,0 +1,140 @@
|
||||
package cn.qaiu.db.pool;
|
||||
|
||||
import cn.qaiu.db.ddl.CreateTable;
|
||||
import cn.qaiu.db.server.H2ServerHolder;
|
||||
import cn.qaiu.vx.core.util.VertxHolder;
|
||||
import io.vertx.core.Promise;
|
||||
import io.vertx.core.Vertx;
|
||||
import io.vertx.core.json.JsonObject;
|
||||
import io.vertx.jdbcclient.JDBCPool;
|
||||
import org.h2.tools.Server;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.sql.SQLException;
|
||||
|
||||
/**
|
||||
* 初始化JDBC
|
||||
* <br>Create date 2021/8/10 12:04
|
||||
*
|
||||
* @author <a href="https://qaiu.top">QAIU</a>
|
||||
*/
|
||||
public class JDBCPoolInit {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(JDBCPoolInit.class);
|
||||
private JDBCPool pool = null;
|
||||
JsonObject dbConfig;
|
||||
Vertx vertx = VertxHolder.getVertxInstance();
|
||||
String url;
|
||||
|
||||
private static JDBCPoolInit instance;
|
||||
|
||||
public JDBCPoolInit(Builder builder) {
|
||||
this.dbConfig = builder.dbConfig;
|
||||
this.url = builder.url;
|
||||
}
|
||||
|
||||
public static Builder builder() {
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
public static JDBCPoolInit instance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
private JsonObject dbConfig;
|
||||
private String url;
|
||||
|
||||
public Builder config(JsonObject dbConfig) {
|
||||
this.dbConfig = dbConfig;
|
||||
this.url = dbConfig.getString("jdbcUrl");
|
||||
return this;
|
||||
}
|
||||
|
||||
public JDBCPoolInit build() {
|
||||
if (JDBCPoolInit.instance == null) {
|
||||
JDBCPoolInit.instance = new JDBCPoolInit(this);
|
||||
}
|
||||
return JDBCPoolInit.instance;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* init h2db<br>
|
||||
* 这个方法只允许调用一次
|
||||
*/
|
||||
public void initPool() {
|
||||
if (pool != null) {
|
||||
LOGGER.error("pool 重复初始化");
|
||||
return;
|
||||
}
|
||||
|
||||
// 异步启动H2服务
|
||||
vertx.createSharedWorkerExecutor("h2-server", 1, Long.MAX_VALUE)
|
||||
.executeBlocking(this::h2serverExecute)
|
||||
.onSuccess(LOGGER::info)
|
||||
.onFailure(Throwable::printStackTrace);
|
||||
|
||||
// 初始化数据库连接
|
||||
vertx.createSharedWorkerExecutor("sql-pool-init")
|
||||
.executeBlocking(this::poolInitExecute)
|
||||
.onSuccess(LOGGER::info)
|
||||
.onFailure(Throwable::printStackTrace);
|
||||
|
||||
}
|
||||
|
||||
private void poolInitExecute(Promise<String> promise) {
|
||||
// 初始化H2db, 创建本地db文件
|
||||
LOGGER.info("init sql start");
|
||||
String[] path = url.split("\\./");
|
||||
path[1] = path[1].split(";")[0];
|
||||
path[1] += ".mv.db";
|
||||
File file = new File(path[1]);
|
||||
if (!file.exists()) {
|
||||
if (!file.getParentFile().exists()) {
|
||||
if (file.getParentFile().mkdirs()) {
|
||||
LOGGER.info("mkdirs -> {}", file.getParentFile().getAbsolutePath());
|
||||
}
|
||||
}
|
||||
try {
|
||||
if (file.createNewFile()) {
|
||||
LOGGER.info("create file -> {}", file.getAbsolutePath());
|
||||
}
|
||||
} catch (IOException e) {
|
||||
LOGGER.error(e.getMessage());
|
||||
throw new RuntimeException("file create failed");
|
||||
}
|
||||
}
|
||||
// 初始化连接池
|
||||
pool = JDBCPool.pool(vertx, dbConfig);
|
||||
CreateTable.createTable(pool, dbConfig.getString("tableClassPath"));
|
||||
promise.complete("init jdbc pool success");
|
||||
|
||||
}
|
||||
|
||||
private void h2serverExecute(Promise<String> promise) {
|
||||
try {
|
||||
String url = dbConfig.getString("jdbcUrl");
|
||||
String[] portStr = url.split(":");
|
||||
String port = portStr[portStr.length - 1].split("[/\\\\]")[0];
|
||||
LOGGER.info("H2server listen port to {}", port);
|
||||
H2ServerHolder.init(Server.createTcpServer("-tcp", "-tcpAllowOthers", "-tcpPort", port).start());
|
||||
promise.complete("Start h2Server success");
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException("Start h2Server failed: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取连接池
|
||||
*
|
||||
* @return pool
|
||||
*/
|
||||
public JDBCPool getPool() {
|
||||
return pool;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package cn.qaiu.db.server;
|
||||
|
||||
import org.h2.tools.Server;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* h2db server
|
||||
* <br>Create date 2021/7/23 2:44
|
||||
*
|
||||
* @author <a href="https://qaiu.top">QAIU</a>
|
||||
*/
|
||||
public class H2ServerHolder {
|
||||
|
||||
private static Server h2Server;
|
||||
|
||||
public static synchronized void init(Server server) {
|
||||
Objects.requireNonNull(server, "未初始化h2Server");
|
||||
h2Server = server;
|
||||
}
|
||||
|
||||
public static Server getH2Server() {
|
||||
Objects.requireNonNull(h2Server, "等待h2Server初始化");
|
||||
return h2Server;
|
||||
}
|
||||
}
|
||||
@@ -3,12 +3,11 @@ package cn.qaiu.vx.core;
|
||||
import cn.qaiu.vx.core.util.ConfigUtil;
|
||||
import cn.qaiu.vx.core.util.VertxHolder;
|
||||
import cn.qaiu.vx.core.verticle.ReverseProxyVerticle;
|
||||
import cn.qaiu.vx.core.verticle.ServiceVerticle;
|
||||
import cn.qaiu.vx.core.verticle.RouterVerticle;
|
||||
import cn.qaiu.vx.core.verticle.ServiceVerticle;
|
||||
import io.vertx.core.*;
|
||||
import io.vertx.core.json.JsonObject;
|
||||
import io.vertx.core.shareddata.LocalMap;
|
||||
import io.vertx.core.shareddata.SharedData;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@@ -53,7 +52,7 @@ public final class Deploy {
|
||||
|
||||
private void readConf(JsonObject conf) {
|
||||
outLogo(conf);
|
||||
String activeMode = conf.getString("active");
|
||||
var activeMode = conf.getString("active");
|
||||
if ("dev".equals(activeMode)) {
|
||||
LOGGER.info("---------------> development environment <--------------\n");
|
||||
System.setProperty("vertxweb.environment","dev");
|
||||
@@ -67,7 +66,7 @@ public final class Deploy {
|
||||
* 打印logo
|
||||
*/
|
||||
private void outLogo(JsonObject conf) {
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
var calendar = Calendar.getInstance();
|
||||
calendar.setTime(new Date());
|
||||
var year = calendar.get(Calendar.YEAR);
|
||||
var logoTemplete = """
|
||||
@@ -101,20 +100,20 @@ public final class Deploy {
|
||||
LOGGER.info("配置读取成功");
|
||||
customConfig = globalConfig.getJsonObject("custom");
|
||||
|
||||
VertxOptions vertxOptions = new VertxOptions(globalConfig.getJsonObject("vertx"));
|
||||
Vertx vertx = Vertx.vertx(vertxOptions);
|
||||
var vertxOptions = new VertxOptions(globalConfig.getJsonObject("vertx"));
|
||||
var vertx = Vertx.vertx(vertxOptions);
|
||||
VertxHolder.init(vertx);
|
||||
//配置保存在共享数据中
|
||||
SharedData sharedData = vertx.sharedData();
|
||||
var sharedData = vertx.sharedData();
|
||||
LocalMap<String, Object> localMap = sharedData.getLocalMap("local");
|
||||
localMap.put("globalConfig", globalConfig);
|
||||
localMap.put("customConfig", customConfig);
|
||||
localMap.put("server", globalConfig.getJsonObject("server"));
|
||||
handle.handle(globalConfig);
|
||||
|
||||
Future<String> future1 = vertx.deployVerticle(RouterVerticle.class, getWorkDeploymentOptions("Router"));
|
||||
Future<String> future2 = vertx.deployVerticle(ServiceVerticle.class, getWorkDeploymentOptions("Service"));
|
||||
Future<String> future3 = vertx.deployVerticle(ReverseProxyVerticle.class, getWorkDeploymentOptions("proxy"));
|
||||
var future1 = vertx.deployVerticle(RouterVerticle.class, getWorkDeploymentOptions("Router"));
|
||||
var future2 = vertx.deployVerticle(ServiceVerticle.class, getWorkDeploymentOptions("Service"));
|
||||
var future3 = vertx.deployVerticle(ReverseProxyVerticle.class, getWorkDeploymentOptions("proxy"));
|
||||
|
||||
CompositeFuture.all(future1, future2, future3)
|
||||
.onSuccess(this::deployWorkVerticalSuccess)
|
||||
@@ -137,8 +136,8 @@ public final class Deploy {
|
||||
* @param compositeFuture future wraps a list
|
||||
*/
|
||||
private void deployWorkVerticalSuccess(CompositeFuture compositeFuture) {
|
||||
double t1 = ((double) (System.currentTimeMillis() - startTime)) / 1000;
|
||||
double t2 = ((double) System.currentTimeMillis() - ManagementFactory.getRuntimeMXBean().getStartTime()) / 1000;
|
||||
var t1 = ((double) (System.currentTimeMillis() - startTime)) / 1000;
|
||||
var t2 = ((double) System.currentTimeMillis() - ManagementFactory.getRuntimeMXBean().getStartTime()) / 1000;
|
||||
LOGGER.info("web服务启动成功 -> 用时: {}s, jvm启动用时: {}s", t1, t2);
|
||||
}
|
||||
|
||||
|
||||
@@ -53,6 +53,12 @@
|
||||
<artifactId>jsoup</artifactId>
|
||||
<version>1.15.4</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cn.qaiu</groupId>
|
||||
<artifactId>core-database</artifactId>
|
||||
<version>0.0.1</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
|
||||
</dependencies>
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
package cn.qaiu.lz;
|
||||
|
||||
import cn.qaiu.vx.core.Deploy;
|
||||
import cn.qaiu.vx.core.util.VertxHolder;
|
||||
import io.vertx.core.json.JsonObject;
|
||||
import lombok.val;
|
||||
|
||||
|
||||
/**
|
||||
@@ -15,15 +13,16 @@ import lombok.val;
|
||||
public class AppMain {
|
||||
|
||||
public static void main(String[] args) {
|
||||
// 注册枚举类型转换器
|
||||
Deploy.instance().start(args, AppMain::exec);
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化数据库
|
||||
*
|
||||
* @param jsonObject 配置
|
||||
*/
|
||||
private static void exec(JsonObject jsonObject) {
|
||||
// JDBCPoolInit.builder().config(jsonObject.getJsonObject("dataSource")).build().initPool();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -46,29 +46,19 @@ public class LzTool {
|
||||
.attr("src");
|
||||
|
||||
//第二次请求得到js里的json数据里的sign
|
||||
/*
|
||||
data : { 'action':'downprocess','signs':ajaxdata,
|
||||
'sign':'UDZSbAg5BDUIAQE_bAjJVaQBrVGAAbVRlADBRYAVrVmUFNFcmCyIEbQdgAWFWOldkBm8OM1A_bU2AANQYy',
|
||||
'websign':ws_sign,'websignkey':wsk_sign,'ves':1 },
|
||||
*/
|
||||
result = Jsoup.connect(url + result)
|
||||
.headers(header)
|
||||
.userAgent(userAgent)
|
||||
.get()
|
||||
.html();
|
||||
// System.out.println(result);
|
||||
Matcher matcher = Pattern.compile("\\s+data\\s*:\\s*.*(\\{.*})").matcher(result);
|
||||
// 'sign':'AWcGOFprUGFWX1BvBTVXawdrBDZTOAU_bV2FTZFU7W2sBJ1t4DW0FYFIyBmgDZVJgUjAFNV41UGQFNg_c_c' 改下正则TMD 最近上传竟然没_c_c
|
||||
Matcher matcher = Pattern.compile("'sign'\s*:\s*'([0-9a-zA-Z_]+)'").matcher(result);
|
||||
Map<String, String> params = new LinkedHashMap<>();
|
||||
if (matcher.find()) {
|
||||
Map<String, String> ov1 = new ObjectMapper().readValue(
|
||||
matcher.group(matcher.groupCount()).replaceAll("'","\""), new TypeReference<Map<String, String>>() {
|
||||
});
|
||||
// { 'action':'downprocess','signs':ajaxdata,
|
||||
// 'sign':'VzFWaAg5U2JSW1FuV2ddYVA7BDBTPgEwCzsAMVc5ATIENVQlWXAFbFUyBGRQPFNgAGlUaQRoBDZXYlRg','websign':ws_sign,
|
||||
// 'websignkey':wsk_sign,'ves':1 }
|
||||
|
||||
String sn = matcher.group(1).replace("'", "");
|
||||
params.put("action", "downprocess");
|
||||
params.put("sign", ov1.get("sign"));
|
||||
params.put("sign", sn);
|
||||
params.put("ves", "1");
|
||||
// System.out.println(sn);
|
||||
|
||||
|
||||
@@ -66,7 +66,7 @@ public class ServerApi {
|
||||
|
||||
@RouteMapping(value = "/json/lz/:id", method = RouteMethod.GET)
|
||||
public JsonResult<String> lzParseJson(HttpServerResponse response, String id) throws Exception {
|
||||
var url = "https://wwa.lanzoux.com/" + id;
|
||||
var url = "https://wwsd.lanzoue.com/" + id;
|
||||
var urlDownload = LzTool.parse(url);
|
||||
log.info("url = {}", urlDownload);
|
||||
return JsonResult.data(urlDownload);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package cn.qaiu.lz.web.model;
|
||||
|
||||
import cn.qaiu.db.ddl.Table;
|
||||
import cn.qaiu.lz.common.ToJson;
|
||||
import io.vertx.codegen.annotations.DataObject;
|
||||
import io.vertx.core.json.JsonObject;
|
||||
@@ -11,7 +12,10 @@ import lombok.NoArgsConstructor;
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@DataObject
|
||||
@Table("t_user")
|
||||
public class RealUser implements ToJson {
|
||||
private String id;
|
||||
|
||||
private String username;
|
||||
private String password;
|
||||
|
||||
|
||||
@@ -35,4 +35,8 @@ https://cowtransfer.com/core/api/transfer/share/download?transferGuid=e4f41b51-b
|
||||
|
||||
//https://download.cowcs.com/cowtransfer/cowtransfer/29188/db32e132e69f490eb4a343b398990f4b.docx?auth_key=1682111861-7b9579fbebb84aaba6bca368d083ab12-0-cbf009f3ffbcbb86191b8cdbc103abce&biz_type=1&business_code=COW_TRANSFER&channel_code=COW_CN_WEB&response-content-disposition=attachment%3B%20filename%3D05-CGB-DB-MENU-V1.02.docx%3Bfilename*%3Dutf-8%27%2705-CGB-DB-MENU-V1.02.docx&user_id=1023860921943729188&x-verify=1
|
||||
|
||||
#V2 api
|
||||
###
|
||||
https://cowtransfer.com/core/api/dam/asset/files/download/23890683765739569/url/v2
|
||||
authorization: eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJndWlkIjoiMDc1OTMwNGItMDEwZS00MGJiLTlhNDUtZTczY2Q5ODYzMDQwIiwiZXhwIjoxNjgzNzkzOTExfQ.rE9z0vhogPjUC0I92MqU8U_PKe4j_mGn7lGgPFMGt5c
|
||||
|
||||
|
||||
@@ -1,29 +1,37 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<configuration debug="false">
|
||||
<!--定义日志文件的存储地址 勿在 LogBack 的配置中使用相对路径-->
|
||||
<property name="LOG_HOME" value="logs" />
|
||||
<!-- 控制台输出 -->
|
||||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
|
||||
<!--格式化输出:%d表示日期,%thread表示线程名,%-5level:级别从左显示5个字符宽度%msg:日志消息,%n是换行符-->
|
||||
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} %highlight(%-5level) -> %magenta([%15.15thread]) %cyan(%-40.40logger{39}) : %msg%n</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
<!-- 按照每天生成日志文件 -->
|
||||
<configuration>
|
||||
|
||||
<!-- 日志自定义颜色 -->
|
||||
<!-- https://logback.qos.ch/manual/layouts.html#coloring -->
|
||||
|
||||
<!--日志文件主目录:这里${user.home}为当前服务器用户主目录-->
|
||||
<property name="LOG_HOME" value="logs"/>
|
||||
<!--日志文件名称:这里spring.application.name表示工程名称-->
|
||||
|
||||
<property name="LOGBACK_DEFAULT" value="%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n"/>
|
||||
<property name="CUSTOMER_PATTERN" value="%d{yyyy-MM-dd HH:mm:ss.SSS} %magenta([%t]) %highlight(%-5p) %yellow(${PID:-}) %cyan(%-40.40logger{39}) : %green(%m%n)"/>
|
||||
<property name="CUSTOMER_PATTERN2" value="%d{yyyy-MM-dd HH:mm:ss.SSS} %highlight(%-5level) -> %magenta([%15.15thread]) %cyan(%-40.40logger{39}) : %msg%n"/>
|
||||
|
||||
<!--配置日志文件(File)-->
|
||||
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<!--设置策略-->
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||
<!--日志文件输出的文件名-->
|
||||
<FileNamePattern>${LOG_HOME}/LzApiWeb.%d{yyyy-MM-dd}.log</FileNamePattern>
|
||||
<!--日志文件保留天数-->
|
||||
<MaxHistory>30</MaxHistory>
|
||||
<!--日志文件路径:这里%d{yyyyMMdd}表示按天分类日志-->
|
||||
<FileNamePattern>${LOG_HOME}/%d{yyyyMMdd}/run.log</FileNamePattern>
|
||||
<!--日志保留天数-->
|
||||
<MaxHistory>15</MaxHistory>
|
||||
</rollingPolicy>
|
||||
<!--设置格式-->
|
||||
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
|
||||
<!--格式化输出:%d表示日期,%thread表示线程名,%-5level:级别从左显示5个字符宽度%msg:日志消息,%n是换行符-->
|
||||
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n</pattern>
|
||||
<!-- 或者使用默认配置 -->
|
||||
<!--<pattern>${FILE_LOG_PATTERN}</pattern>-->
|
||||
<charset>utf8</charset>
|
||||
</encoder>
|
||||
<!--日志文件最大的大小-->
|
||||
<triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
|
||||
<MaxFileSize>10MB</MaxFileSize>
|
||||
<MaxFileSize>100MB</MaxFileSize>
|
||||
</triggeringPolicy>
|
||||
</appender>
|
||||
|
||||
@@ -37,9 +45,16 @@
|
||||
<appender-ref ref="FILE"/>
|
||||
</appender>
|
||||
|
||||
<!-- 日志输出级别 -->
|
||||
<root level="INFO">
|
||||
<appender-ref ref="FILE" />
|
||||
<appender-ref ref="STDOUT" />
|
||||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder>
|
||||
<!--格式化输出:%d表示日期,%thread表示线程名,%-5level:级别从左显示5个字符宽度%msg:日志消息,%n是换行符-->
|
||||
<pattern>${CUSTOMER_PATTERN2}</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
<logger name="io.netty" level="warn"/>
|
||||
<logger name="io.vertx" level="info"/>
|
||||
<root level="debug">
|
||||
<appender-ref ref="STDOUT"/>
|
||||
<!-- <appender-ref ref="FILE"/>-->
|
||||
</root>
|
||||
</configuration>
|
||||
|
||||
Reference in New Issue
Block a user