diff --git a/bin/run.bat b/bin/run.bat index bf1e123..21d188e 100644 --- a/bin/run.bat +++ b/bin/run.bat @@ -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% %* \ No newline at end of file +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% %* diff --git a/bin/run.sh b/bin/run.sh index 3d3f13c..45f81b8 100644 --- a/bin/run.sh +++ b/bin/run.sh @@ -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 \ No newline at end of file +tail -f startup.log diff --git a/core-database/pom.xml b/core-database/pom.xml new file mode 100644 index 0000000..c2b4c47 --- /dev/null +++ b/core-database/pom.xml @@ -0,0 +1,65 @@ + + + + lz-cow-api + cn.qaiu + 0.0.1 + + 4.0.0 + + core-database + + + 17 + UTF-8 + 2.0.5 + 3.12.0 + 4.4.1 + + + + + cn.qaiu + core + 1.0.8 + + + + + com.h2database + h2 + 2.1.214 + + + + + com.zaxxer + HikariCP + 5.0.1 + + + org.apache.commons + commons-lang3 + 3.12.0 + + + io.vertx + vertx-codegen + compile + ${vertx.version} + + + io.vertx + vertx-sql-client-templates + ${vertx.version} + + + io.vertx + vertx-jdbc-client + ${vertx.version} + + + + diff --git a/core-database/src/main/java/cn/qaiu/StartH2DatabaseServer.java b/core-database/src/main/java/cn/qaiu/StartH2DatabaseServer.java new file mode 100644 index 0000000..5c52135 --- /dev/null +++ b/core-database/src/main/java/cn/qaiu/StartH2DatabaseServer.java @@ -0,0 +1,7 @@ +package cn.qaiu; + +public class StartH2DatabaseServer { + public static void main(String[] args) { + System.out.println("Hello world!"); + } +} diff --git a/core-database/src/main/java/cn/qaiu/db/ddl/Constraint.java b/core-database/src/main/java/cn/qaiu/db/ddl/Constraint.java new file mode 100644 index 0000000..3b234bf --- /dev/null +++ b/core-database/src/main/java/cn/qaiu/db/ddl/Constraint.java @@ -0,0 +1,45 @@ +package cn.qaiu.db.ddl; + +import java.lang.annotation.*; + +/** + * 建表约束类型 + * + *
Create date 2021/7/22 0:42 + * @author QAIU + */ +@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; +} diff --git a/core-database/src/main/java/cn/qaiu/db/ddl/CreateTable.java b/core-database/src/main/java/cn/qaiu/db/ddl/CreateTable.java new file mode 100644 index 0000000..063ad69 --- /dev/null +++ b/core-database/src/main/java/cn/qaiu/db/ddl/CreateTable.java @@ -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 QAIU + */ +public class CreateTable { + public static Map, 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 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> 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); + }); + } +} diff --git a/core-database/src/main/java/cn/qaiu/db/ddl/Length.java b/core-database/src/main/java/cn/qaiu/db/ddl/Length.java new file mode 100644 index 0000000..7962ee0 --- /dev/null +++ b/core-database/src/main/java/cn/qaiu/db/ddl/Length.java @@ -0,0 +1,16 @@ +package cn.qaiu.db.ddl; + +import java.lang.annotation.*; + +/** + * 字段长度属性 + * @author QAIU + */ +@Documented +@Inherited +@Retention(RetentionPolicy.RUNTIME) +@Target({ElementType.TYPE, ElementType.FIELD}) +public @interface Length { + int[] decimalSize() default {22,2}; //bigDecimal精度 + int varcharSize() default 255; //varchar大小 +} diff --git a/core-database/src/main/java/cn/qaiu/db/ddl/Table.java b/core-database/src/main/java/cn/qaiu/db/ddl/Table.java new file mode 100644 index 0000000..ba1836d --- /dev/null +++ b/core-database/src/main/java/cn/qaiu/db/ddl/Table.java @@ -0,0 +1,17 @@ +package cn.qaiu.db.ddl; + +import java.lang.annotation.*; + +/** + * 标注建表的实体类和主键字段 + * + * @author QAIU + */ +@Documented +@Inherited +@Retention(RetentionPolicy.RUNTIME) +@Target({ElementType.TYPE, ElementType.FIELD})//次注解作用于类和字段上 +public @interface Table { + String value() default ""; //默认表名为空 + String keyFields() default "id"; //默认主键为id +} diff --git a/core-database/src/main/java/cn/qaiu/db/ddl/TableGenIgnore.java b/core-database/src/main/java/cn/qaiu/db/ddl/TableGenIgnore.java new file mode 100644 index 0000000..2f4af30 --- /dev/null +++ b/core-database/src/main/java/cn/qaiu/db/ddl/TableGenIgnore.java @@ -0,0 +1,16 @@ +package cn.qaiu.db.ddl; + +import java.lang.annotation.*; + +/** + * 建表时忽略字段 + *
Create date 2021/8/27 15:49 + * + * @author QAIU + */ +@Documented +@Inherited +@Retention(RetentionPolicy.RUNTIME) +@Target({ElementType.TYPE, ElementType.FIELD}) +public @interface TableGenIgnore { +} diff --git a/core-database/src/main/java/cn/qaiu/db/pool/JDBCPoolInit.java b/core-database/src/main/java/cn/qaiu/db/pool/JDBCPoolInit.java new file mode 100644 index 0000000..ce32f56 --- /dev/null +++ b/core-database/src/main/java/cn/qaiu/db/pool/JDBCPoolInit.java @@ -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 + *
Create date 2021/8/10 12:04 + * + * @author QAIU + */ +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
+ * 这个方法只允许调用一次 + */ + 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 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 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; + } +} diff --git a/core-database/src/main/java/cn/qaiu/db/server/H2ServerHolder.java b/core-database/src/main/java/cn/qaiu/db/server/H2ServerHolder.java new file mode 100644 index 0000000..5e2bb00 --- /dev/null +++ b/core-database/src/main/java/cn/qaiu/db/server/H2ServerHolder.java @@ -0,0 +1,26 @@ +package cn.qaiu.db.server; + +import org.h2.tools.Server; + +import java.util.Objects; + +/** + * h2db server + *
Create date 2021/7/23 2:44 + * + * @author QAIU + */ +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; + } +} diff --git a/core/src/main/java/cn/qaiu/vx/core/Deploy.java b/core/src/main/java/cn/qaiu/vx/core/Deploy.java index aae1198..e152e66 100644 --- a/core/src/main/java/cn/qaiu/vx/core/Deploy.java +++ b/core/src/main/java/cn/qaiu/vx/core/Deploy.java @@ -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 localMap = sharedData.getLocalMap("local"); localMap.put("globalConfig", globalConfig); localMap.put("customConfig", customConfig); localMap.put("server", globalConfig.getJsonObject("server")); handle.handle(globalConfig); - Future future1 = vertx.deployVerticle(RouterVerticle.class, getWorkDeploymentOptions("Router")); - Future future2 = vertx.deployVerticle(ServiceVerticle.class, getWorkDeploymentOptions("Service")); - Future 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); } diff --git a/lz-cow-api-web/pom.xml b/lz-cow-api-web/pom.xml index 4de1019..0053f51 100644 --- a/lz-cow-api-web/pom.xml +++ b/lz-cow-api-web/pom.xml @@ -53,6 +53,12 @@ jsoup 1.15.4 + + cn.qaiu + core-database + 0.0.1 + compile + diff --git a/lz-cow-api-web/src/main/java/cn/qaiu/lz/AppMain.java b/lz-cow-api-web/src/main/java/cn/qaiu/lz/AppMain.java index c47f966..a7f5acd 100644 --- a/lz-cow-api-web/src/main/java/cn/qaiu/lz/AppMain.java +++ b/lz-cow-api-web/src/main/java/cn/qaiu/lz/AppMain.java @@ -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(); } diff --git a/lz-cow-api-web/src/main/java/cn/qaiu/lz/common/util/LzTool.java b/lz-cow-api-web/src/main/java/cn/qaiu/lz/common/util/LzTool.java index 24d4eef..c9f5325 100644 --- a/lz-cow-api-web/src/main/java/cn/qaiu/lz/common/util/LzTool.java +++ b/lz-cow-api-web/src/main/java/cn/qaiu/lz/common/util/LzTool.java @@ -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 params = new LinkedHashMap<>(); if (matcher.find()) { - Map ov1 = new ObjectMapper().readValue( - matcher.group(matcher.groupCount()).replaceAll("'","\""), new TypeReference>() { - }); - // { '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); diff --git a/lz-cow-api-web/src/main/java/cn/qaiu/lz/web/http/ServerApi.java b/lz-cow-api-web/src/main/java/cn/qaiu/lz/web/http/ServerApi.java index 8791fa6..4dabeb7 100644 --- a/lz-cow-api-web/src/main/java/cn/qaiu/lz/web/http/ServerApi.java +++ b/lz-cow-api-web/src/main/java/cn/qaiu/lz/web/http/ServerApi.java @@ -66,7 +66,7 @@ public class ServerApi { @RouteMapping(value = "/json/lz/:id", method = RouteMethod.GET) public JsonResult 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); diff --git a/lz-cow-api-web/src/main/java/cn/qaiu/lz/web/model/RealUser.java b/lz-cow-api-web/src/main/java/cn/qaiu/lz/web/model/RealUser.java index 61e07ef..16db7e4 100644 --- a/lz-cow-api-web/src/main/java/cn/qaiu/lz/web/model/RealUser.java +++ b/lz-cow-api-web/src/main/java/cn/qaiu/lz/web/model/RealUser.java @@ -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; diff --git a/lz-cow-api-web/src/main/resources/1.http b/lz-cow-api-web/src/main/resources/1.http index 555b552..1b29e34 100644 --- a/lz-cow-api-web/src/main/resources/1.http +++ b/lz-cow-api-web/src/main/resources/1.http @@ -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 diff --git a/lz-cow-api-web/src/main/resources/logback.xml b/lz-cow-api-web/src/main/resources/logback.xml index 48c2245..3745f53 100644 --- a/lz-cow-api-web/src/main/resources/logback.xml +++ b/lz-cow-api-web/src/main/resources/logback.xml @@ -1,29 +1,37 @@ - - - - - - - - %d{yyyy-MM-dd HH:mm:ss.SSS} %highlight(%-5level) -> %magenta([%15.15thread]) %cyan(%-40.40logger{39}) : %msg%n - - - + + + + + + + + + + + + + + + - - ${LOG_HOME}/LzApiWeb.%d{yyyy-MM-dd}.log - - 30 + + ${LOG_HOME}/%d{yyyyMMdd}/run.log + + 15 + %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n + + + utf8 - 10MB + 100MB @@ -37,9 +45,16 @@ - - - - + + + + ${CUSTOMER_PATTERN2} + + + + + + + diff --git a/pom.xml b/pom.xml index 52eece4..15c4ba2 100644 --- a/pom.xml +++ b/pom.xml @@ -12,6 +12,7 @@ core lz-cow-api-web + core-database