diff --git a/backend/java/sk-matrix-service/.gitignore b/backend/java/sk-matrix-service/.gitignore new file mode 100644 index 0000000..455256d --- /dev/null +++ b/backend/java/sk-matrix-service/.gitignore @@ -0,0 +1,98 @@ +### Maven template +target/ +pom.xml.tag +pom.xml.releaseBackup +pom.xml.versionsBackup +pom.xml.next +release.properties +dependency-reduced-pom.xml +buildNumber.properties +.mvn/timing.properties +# https://github.com/takari/maven-wrapper#usage-without-binary-jar +.mvn/wrapper/maven-wrapper.jar + +# Eclipse m2e generated files +# Eclipse Core +.project +# JDT-specific (Eclipse Java Development Tools) +.classpath + +### JetBrains template +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# User-specific stuff +.idea/**/workspace.xml +.idea/**/tasks.xml +.idea/**/usage.statistics.xml +.idea/**/dictionaries +.idea/**/shelf + +# AWS User-specific +.idea/**/aws.xml + +# Generated files +.idea/**/contentModel.xml + +# Sensitive or high-churn files +.idea/**/dataSources/ +.idea/**/dataSources.ids +.idea/**/dataSources.local.xml +.idea/**/sqlDataSources.xml +.idea/**/dynamic.xml +.idea/**/uiDesigner.xml +.idea/**/dbnavigator.xml + +# Gradle +.idea/**/gradle.xml +.idea/**/libraries + +# Gradle and Maven with auto-import +# When using Gradle or Maven with auto-import, you should exclude module files, +# since they will be recreated, and may cause churn. Uncomment if using +# auto-import. +# .idea/artifacts +# .idea/compiler.xml +# .idea/jarRepositories.xml +# .idea/modules.xml +# .idea/*.iml +# .idea/modules +# *.iml +# *.ipr + +# CMake +cmake-build-*/ + +# Mongo Explorer plugin +.idea/**/mongoSettings.xml + +# File-based project format +*.iws + +# IntelliJ +out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Cursive Clojure plugin +.idea/replstate.xml + +# SonarLint plugin +.idea/sonarlint/ + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties + +# Editor-based Rest Client +.idea/httpRequests + +# Android studio 3.1+ serialized cache file +.idea/caches/build_file_checksums.ser + diff --git a/backend/java/sk-matrix-service/.idea/.gitignore b/backend/java/sk-matrix-service/.idea/.gitignore new file mode 100644 index 0000000..ad38804 --- /dev/null +++ b/backend/java/sk-matrix-service/.idea/.gitignore @@ -0,0 +1,10 @@ +# 默认忽略的文件 +/shelf/ +/workspace.xml +# 基于编辑器的 HTTP 客户端请求 +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml +# Zeppelin ignored files +/ZeppelinRemoteNotebooks/ diff --git a/backend/java/sk-matrix-service/.idea/compiler.xml b/backend/java/sk-matrix-service/.idea/compiler.xml new file mode 100644 index 0000000..bf94b3e --- /dev/null +++ b/backend/java/sk-matrix-service/.idea/compiler.xml @@ -0,0 +1,41 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/backend/java/sk-matrix-service/.idea/encodings.xml b/backend/java/sk-matrix-service/.idea/encodings.xml new file mode 100644 index 0000000..f945c86 --- /dev/null +++ b/backend/java/sk-matrix-service/.idea/encodings.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/backend/java/sk-matrix-service/.idea/git_toolbox_prj.xml b/backend/java/sk-matrix-service/.idea/git_toolbox_prj.xml new file mode 100644 index 0000000..02b915b --- /dev/null +++ b/backend/java/sk-matrix-service/.idea/git_toolbox_prj.xml @@ -0,0 +1,15 @@ + + + + + + + \ No newline at end of file diff --git a/backend/java/sk-matrix-service/.idea/jarRepositories.xml b/backend/java/sk-matrix-service/.idea/jarRepositories.xml new file mode 100644 index 0000000..fa37ca3 --- /dev/null +++ b/backend/java/sk-matrix-service/.idea/jarRepositories.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/backend/java/sk-matrix-service/.idea/misc.xml b/backend/java/sk-matrix-service/.idea/misc.xml new file mode 100644 index 0000000..463551f --- /dev/null +++ b/backend/java/sk-matrix-service/.idea/misc.xml @@ -0,0 +1,14 @@ + + + + + + + + + + \ No newline at end of file diff --git a/backend/java/sk-matrix-service/.idea/vcs.xml b/backend/java/sk-matrix-service/.idea/vcs.xml new file mode 100644 index 0000000..c2365ab --- /dev/null +++ b/backend/java/sk-matrix-service/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/backend/java/sk-matrix-service/annotation/pom.xml b/backend/java/sk-matrix-service/annotation/pom.xml new file mode 100644 index 0000000..a66f6d7 --- /dev/null +++ b/backend/java/sk-matrix-service/annotation/pom.xml @@ -0,0 +1,45 @@ + + + + sk-matrix-service + cn.skcks.matrix.v2 + 1.0-SNAPSHOT + + 4.0.0 + + annotation + + + UTF-8 + + + + + org.springframework + spring-beans + + + + org.springframework + spring-context + + + + com.fasterxml.jackson.core + jackson-annotations + + + + org.springframework + spring-web + + + org.springframework + spring-beans + + + + + diff --git a/backend/java/sk-matrix-service/annotation/src/main/java/cn/skcks/matrix/annotation/web/JsonMapping.java b/backend/java/sk-matrix-service/annotation/src/main/java/cn/skcks/matrix/annotation/web/JsonMapping.java new file mode 100644 index 0000000..2f8de2e --- /dev/null +++ b/backend/java/sk-matrix-service/annotation/src/main/java/cn/skcks/matrix/annotation/web/JsonMapping.java @@ -0,0 +1,64 @@ +package cn.skcks.matrix.v2.annotation.web; + +import org.springframework.core.annotation.AliasFor; +import org.springframework.http.MediaType; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.ResponseBody; + +import java.lang.annotation.*; + +/** + * @author Shikong + */ +@Inherited +@Target({ElementType.TYPE, ElementType.METHOD}) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@RequestMapping(produces = MediaType.APPLICATION_JSON_VALUE) +@ResponseBody +public @interface JsonMapping { + /** + * Alias for {@link RequestMapping#method}. + */ + @AliasFor(annotation = RequestMapping.class) + RequestMethod[] method() default {}; + + /** + * Alias for {@link RequestMapping#name}. + */ + @AliasFor(annotation = RequestMapping.class) + String name() default ""; + + /** + * Alias for {@link RequestMapping#value}. + */ + @AliasFor(annotation = RequestMapping.class) + String[] value() default {}; + + /** + * Alias for {@link RequestMapping#path}. + */ + @AliasFor(annotation = RequestMapping.class) + String[] path() default {}; + + /** + * Alias for {@link RequestMapping#params}. + */ + @AliasFor(annotation = RequestMapping.class) + String[] params() default {}; + + /** + * Alias for {@link RequestMapping#headers}. + */ + @AliasFor(annotation = RequestMapping.class) + String[] headers() default {}; + + /** + * Alias for {@link RequestMapping#consumes}. + * @since 4.3.5 + */ + @AliasFor(annotation = RequestMapping.class) + String[] consumes() default {}; +} + diff --git a/backend/java/sk-matrix-service/annotation/src/main/java/cn/skcks/matrix/annotation/web/auth/Auth.java b/backend/java/sk-matrix-service/annotation/src/main/java/cn/skcks/matrix/annotation/web/auth/Auth.java new file mode 100644 index 0000000..0ffa084 --- /dev/null +++ b/backend/java/sk-matrix-service/annotation/src/main/java/cn/skcks/matrix/annotation/web/auth/Auth.java @@ -0,0 +1,16 @@ +package cn.skcks.matrix.v2.annotation.web.auth; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * @author Shikong + */ +@Target({ElementType.METHOD,ElementType.TYPE}) +@Retention(RetentionPolicy.RUNTIME) +@SuppressWarnings({"unused"}) +public @interface Auth { + boolean required() default true; +} diff --git a/backend/java/sk-matrix-service/annotation/src/main/java/cn/skcks/matrix/annotation/web/auth/UnAuth.java b/backend/java/sk-matrix-service/annotation/src/main/java/cn/skcks/matrix/annotation/web/auth/UnAuth.java new file mode 100644 index 0000000..80a74e1 --- /dev/null +++ b/backend/java/sk-matrix-service/annotation/src/main/java/cn/skcks/matrix/annotation/web/auth/UnAuth.java @@ -0,0 +1,16 @@ +package cn.skcks.matrix.v2.annotation.web.auth; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * @author Shikong + */ +@Target({ElementType.METHOD,ElementType.TYPE}) +@Retention(RetentionPolicy.RUNTIME) +@SuppressWarnings({"unused"}) +public @interface UnAuth { + boolean required() default true; +} diff --git a/backend/java/sk-matrix-service/annotation/src/main/java/cn/skcks/matrix/annotation/web/methods/DeleteJson.java b/backend/java/sk-matrix-service/annotation/src/main/java/cn/skcks/matrix/annotation/web/methods/DeleteJson.java new file mode 100644 index 0000000..dd0d233 --- /dev/null +++ b/backend/java/sk-matrix-service/annotation/src/main/java/cn/skcks/matrix/annotation/web/methods/DeleteJson.java @@ -0,0 +1,54 @@ +package cn.skcks.matrix.v2.annotation.web.methods; + +import cn.skcks.matrix.v2.annotation.web.JsonMapping; +import org.springframework.core.annotation.AliasFor; +import org.springframework.web.bind.annotation.RequestMethod; + +import java.lang.annotation.*; + +/** + * @author Shikong + */ +@Inherited +@Target(ElementType.METHOD) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@JsonMapping(method = RequestMethod.DELETE) +public @interface DeleteJson { + /** + * Alias for {@link JsonMapping#name}. + */ + @AliasFor(annotation = JsonMapping.class) + String name() default ""; + + /** + * Alias for {@link JsonMapping#value}. + */ + @AliasFor(annotation = JsonMapping.class) + String[] value() default {}; + + /** + * Alias for {@link JsonMapping#path}. + */ + @AliasFor(annotation = JsonMapping.class) + String[] path() default {}; + + /** + * Alias for {@link JsonMapping#params}. + */ + @AliasFor(annotation = JsonMapping.class) + String[] params() default {}; + + /** + * Alias for {@link JsonMapping#headers}. + */ + @AliasFor(annotation = JsonMapping.class) + String[] headers() default {}; + + /** + * Alias for {@link JsonMapping#consumes}. + * @since 4.3.5 + */ + @AliasFor(annotation = JsonMapping.class) + String[] consumes() default {}; +} diff --git a/backend/java/sk-matrix-service/annotation/src/main/java/cn/skcks/matrix/annotation/web/methods/GetJson.java b/backend/java/sk-matrix-service/annotation/src/main/java/cn/skcks/matrix/annotation/web/methods/GetJson.java new file mode 100644 index 0000000..2e29f1a --- /dev/null +++ b/backend/java/sk-matrix-service/annotation/src/main/java/cn/skcks/matrix/annotation/web/methods/GetJson.java @@ -0,0 +1,54 @@ +package cn.skcks.matrix.v2.annotation.web.methods; + +import cn.skcks.matrix.v2.annotation.web.JsonMapping; +import org.springframework.core.annotation.AliasFor; +import org.springframework.web.bind.annotation.RequestMethod; + +import java.lang.annotation.*; + +/** + * @author Shikong + */ +@Inherited +@Target(ElementType.METHOD) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@JsonMapping(method = RequestMethod.GET) +public @interface GetJson { + /** + * Alias for {@link JsonMapping#name}. + */ + @AliasFor(annotation = JsonMapping.class) + String name() default ""; + + /** + * Alias for {@link JsonMapping#value}. + */ + @AliasFor(annotation = JsonMapping.class) + String[] value() default {}; + + /** + * Alias for {@link JsonMapping#path}. + */ + @AliasFor(annotation = JsonMapping.class) + String[] path() default {}; + + /** + * Alias for {@link JsonMapping#params}. + */ + @AliasFor(annotation = JsonMapping.class) + String[] params() default {}; + + /** + * Alias for {@link JsonMapping#headers}. + */ + @AliasFor(annotation = JsonMapping.class) + String[] headers() default {}; + + /** + * Alias for {@link JsonMapping#consumes}. + * @since 4.3.5 + */ + @AliasFor(annotation = JsonMapping.class) + String[] consumes() default {}; +} diff --git a/backend/java/sk-matrix-service/annotation/src/main/java/cn/skcks/matrix/annotation/web/methods/HeadJson.java b/backend/java/sk-matrix-service/annotation/src/main/java/cn/skcks/matrix/annotation/web/methods/HeadJson.java new file mode 100644 index 0000000..f53030b --- /dev/null +++ b/backend/java/sk-matrix-service/annotation/src/main/java/cn/skcks/matrix/annotation/web/methods/HeadJson.java @@ -0,0 +1,55 @@ +package cn.skcks.matrix.v2.annotation.web.methods; + + +import cn.skcks.matrix.v2.annotation.web.JsonMapping; +import org.springframework.core.annotation.AliasFor; +import org.springframework.web.bind.annotation.RequestMethod; + +import java.lang.annotation.*; + +/** + * @author Shikong + */ +@Inherited +@Target(ElementType.METHOD) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@JsonMapping(method = RequestMethod.HEAD) +public @interface HeadJson { + /** + * Alias for {@link JsonMapping#name}. + */ + @AliasFor(annotation = JsonMapping.class) + String name() default ""; + + /** + * Alias for {@link JsonMapping#value}. + */ + @AliasFor(annotation = JsonMapping.class) + String[] value() default {}; + + /** + * Alias for {@link JsonMapping#path}. + */ + @AliasFor(annotation = JsonMapping.class) + String[] path() default {}; + + /** + * Alias for {@link JsonMapping#params}. + */ + @AliasFor(annotation = JsonMapping.class) + String[] params() default {}; + + /** + * Alias for {@link JsonMapping#headers}. + */ + @AliasFor(annotation = JsonMapping.class) + String[] headers() default {}; + + /** + * Alias for {@link JsonMapping#consumes}. + * @since 4.3.5 + */ + @AliasFor(annotation = JsonMapping.class) + String[] consumes() default {}; +} diff --git a/backend/java/sk-matrix-service/annotation/src/main/java/cn/skcks/matrix/annotation/web/methods/OptionsJson.java b/backend/java/sk-matrix-service/annotation/src/main/java/cn/skcks/matrix/annotation/web/methods/OptionsJson.java new file mode 100644 index 0000000..baefbdd --- /dev/null +++ b/backend/java/sk-matrix-service/annotation/src/main/java/cn/skcks/matrix/annotation/web/methods/OptionsJson.java @@ -0,0 +1,55 @@ +package cn.skcks.matrix.v2.annotation.web.methods; + + +import cn.skcks.matrix.v2.annotation.web.JsonMapping; +import org.springframework.core.annotation.AliasFor; +import org.springframework.web.bind.annotation.RequestMethod; + +import java.lang.annotation.*; + +/** + * @author Shikong + */ +@Inherited +@Target(ElementType.METHOD) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@JsonMapping(method = RequestMethod.OPTIONS) +public @interface OptionsJson { + /** + * Alias for {@link JsonMapping#name}. + */ + @AliasFor(annotation = JsonMapping.class) + String name() default ""; + + /** + * Alias for {@link JsonMapping#value}. + */ + @AliasFor(annotation = JsonMapping.class) + String[] value() default {}; + + /** + * Alias for {@link JsonMapping#path}. + */ + @AliasFor(annotation = JsonMapping.class) + String[] path() default {}; + + /** + * Alias for {@link JsonMapping#params}. + */ + @AliasFor(annotation = JsonMapping.class) + String[] params() default {}; + + /** + * Alias for {@link JsonMapping#headers}. + */ + @AliasFor(annotation = JsonMapping.class) + String[] headers() default {}; + + /** + * Alias for {@link JsonMapping#consumes}. + * @since 4.3.5 + */ + @AliasFor(annotation = JsonMapping.class) + String[] consumes() default {}; +} diff --git a/backend/java/sk-matrix-service/annotation/src/main/java/cn/skcks/matrix/annotation/web/methods/PatchJson.java b/backend/java/sk-matrix-service/annotation/src/main/java/cn/skcks/matrix/annotation/web/methods/PatchJson.java new file mode 100644 index 0000000..19692bb --- /dev/null +++ b/backend/java/sk-matrix-service/annotation/src/main/java/cn/skcks/matrix/annotation/web/methods/PatchJson.java @@ -0,0 +1,54 @@ +package cn.skcks.matrix.v2.annotation.web.methods; + +import cn.skcks.matrix.v2.annotation.web.JsonMapping; +import org.springframework.core.annotation.AliasFor; +import org.springframework.web.bind.annotation.RequestMethod; + +import java.lang.annotation.*; + +/** + * @author Shikong + */ +@Inherited +@Target(ElementType.METHOD) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@JsonMapping(method = RequestMethod.PATCH) +public @interface PatchJson { + /** + * Alias for {@link JsonMapping#name}. + */ + @AliasFor(annotation = JsonMapping.class) + String name() default ""; + + /** + * Alias for {@link JsonMapping#value}. + */ + @AliasFor(annotation = JsonMapping.class) + String[] value() default {}; + + /** + * Alias for {@link JsonMapping#path}. + */ + @AliasFor(annotation = JsonMapping.class) + String[] path() default {}; + + /** + * Alias for {@link JsonMapping#params}. + */ + @AliasFor(annotation = JsonMapping.class) + String[] params() default {}; + + /** + * Alias for {@link JsonMapping#headers}. + */ + @AliasFor(annotation = JsonMapping.class) + String[] headers() default {}; + + /** + * Alias for {@link JsonMapping#consumes}. + * @since 4.3.5 + */ + @AliasFor(annotation = JsonMapping.class) + String[] consumes() default {}; +} diff --git a/backend/java/sk-matrix-service/annotation/src/main/java/cn/skcks/matrix/annotation/web/methods/PostJson.java b/backend/java/sk-matrix-service/annotation/src/main/java/cn/skcks/matrix/annotation/web/methods/PostJson.java new file mode 100644 index 0000000..f70293e --- /dev/null +++ b/backend/java/sk-matrix-service/annotation/src/main/java/cn/skcks/matrix/annotation/web/methods/PostJson.java @@ -0,0 +1,54 @@ +package cn.skcks.matrix.v2.annotation.web.methods; + +import cn.skcks.matrix.v2.annotation.web.JsonMapping; +import org.springframework.core.annotation.AliasFor; +import org.springframework.web.bind.annotation.RequestMethod; + +import java.lang.annotation.*; + +/** + * @author Shikong + */ +@Inherited +@Target(ElementType.METHOD) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@JsonMapping(method = RequestMethod.POST) +public @interface PostJson { + /** + * Alias for {@link JsonMapping#name}. + */ + @AliasFor(annotation = JsonMapping.class) + String name() default ""; + + /** + * Alias for {@link JsonMapping#value}. + */ + @AliasFor(annotation = JsonMapping.class) + String[] value() default {}; + + /** + * Alias for {@link JsonMapping#path}. + */ + @AliasFor(annotation = JsonMapping.class) + String[] path() default {}; + + /** + * Alias for {@link JsonMapping#params}. + */ + @AliasFor(annotation = JsonMapping.class) + String[] params() default {}; + + /** + * Alias for {@link JsonMapping#headers}. + */ + @AliasFor(annotation = JsonMapping.class) + String[] headers() default {}; + + /** + * Alias for {@link JsonMapping#consumes}. + * @since 4.3.5 + */ + @AliasFor(annotation = JsonMapping.class) + String[] consumes() default {}; +} diff --git a/backend/java/sk-matrix-service/annotation/src/main/java/cn/skcks/matrix/annotation/web/methods/PutJson.java b/backend/java/sk-matrix-service/annotation/src/main/java/cn/skcks/matrix/annotation/web/methods/PutJson.java new file mode 100644 index 0000000..ac2af00 --- /dev/null +++ b/backend/java/sk-matrix-service/annotation/src/main/java/cn/skcks/matrix/annotation/web/methods/PutJson.java @@ -0,0 +1,54 @@ +package cn.skcks.matrix.v2.annotation.web.methods; + +import cn.skcks.matrix.v2.annotation.web.JsonMapping; +import org.springframework.core.annotation.AliasFor; +import org.springframework.web.bind.annotation.RequestMethod; + +import java.lang.annotation.*; + +/** + * @author Shikong + */ +@Inherited +@Target(ElementType.METHOD) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@JsonMapping(method = RequestMethod.PUT) +public @interface PutJson { + /** + * Alias for {@link JsonMapping#name}. + */ + @AliasFor(annotation = JsonMapping.class) + String name() default ""; + + /** + * Alias for {@link JsonMapping#value}. + */ + @AliasFor(annotation = JsonMapping.class) + String[] value() default {}; + + /** + * Alias for {@link JsonMapping#path}. + */ + @AliasFor(annotation = JsonMapping.class) + String[] path() default {}; + + /** + * Alias for {@link JsonMapping#params}. + */ + @AliasFor(annotation = JsonMapping.class) + String[] params() default {}; + + /** + * Alias for {@link JsonMapping#headers}. + */ + @AliasFor(annotation = JsonMapping.class) + String[] headers() default {}; + + /** + * Alias for {@link JsonMapping#consumes}. + * @since 4.3.5 + */ + @AliasFor(annotation = JsonMapping.class) + String[] consumes() default {}; +} diff --git a/backend/java/sk-matrix-service/annotation/src/main/java/cn/skcks/matrix/annotation/web/methods/TraceJson.java b/backend/java/sk-matrix-service/annotation/src/main/java/cn/skcks/matrix/annotation/web/methods/TraceJson.java new file mode 100644 index 0000000..bf24a8b --- /dev/null +++ b/backend/java/sk-matrix-service/annotation/src/main/java/cn/skcks/matrix/annotation/web/methods/TraceJson.java @@ -0,0 +1,54 @@ +package cn.skcks.matrix.v2.annotation.web.methods; + +import cn.skcks.matrix.v2.annotation.web.JsonMapping; +import org.springframework.core.annotation.AliasFor; +import org.springframework.web.bind.annotation.RequestMethod; + +import java.lang.annotation.*; + +/** + * @author Shikong + */ +@Inherited +@Target(ElementType.METHOD) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@JsonMapping(method = RequestMethod.TRACE) +public @interface TraceJson { + /** + * Alias for {@link JsonMapping#name}. + */ + @AliasFor(annotation = JsonMapping.class) + String name() default ""; + + /** + * Alias for {@link JsonMapping#value}. + */ + @AliasFor(annotation = JsonMapping.class) + String[] value() default {}; + + /** + * Alias for {@link JsonMapping#path}. + */ + @AliasFor(annotation = JsonMapping.class) + String[] path() default {}; + + /** + * Alias for {@link JsonMapping#params}. + */ + @AliasFor(annotation = JsonMapping.class) + String[] params() default {}; + + /** + * Alias for {@link JsonMapping#headers}. + */ + @AliasFor(annotation = JsonMapping.class) + String[] headers() default {}; + + /** + * Alias for {@link JsonMapping#consumes}. + * @since 4.3.5 + */ + @AliasFor(annotation = JsonMapping.class) + String[] consumes() default {}; +} diff --git a/backend/java/sk-matrix-service/api/pom.xml b/backend/java/sk-matrix-service/api/pom.xml new file mode 100644 index 0000000..812017e --- /dev/null +++ b/backend/java/sk-matrix-service/api/pom.xml @@ -0,0 +1,96 @@ + + + 4.0.0 + + cn.skcks.matrix.v2 + sk-matrix-service + 1.0-SNAPSHOT + + + api + + + 17 + 17 + UTF-8 + + + + + cn.skcks.matrix.v2 + annotation + ${project.version} + + + + cn.skcks.matrix.v2 + common + ${project.version} + + + + org.projectlombok + lombok + + + + org.springframework.boot + spring-boot-starter-validation + + + + + org.springframework.boot + spring-boot-starter-web + + + + org.springframework.boot + spring-boot-starter-undertow + + + + org.springdoc + springdoc-openapi-starter-webmvc-ui + + + + + org.springframework.boot + spring-boot-devtools + runtime + true + + + + org.springframework.boot + spring-boot-starter-test + test + + + + + org.mapstruct + mapstruct + + + org.mapstruct + mapstruct-processor + compile + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + true + + + + + diff --git a/backend/java/sk-matrix-service/api/src/main/java/cn/skcks/matrix/v2/advice/ExceptionAdvice.java b/backend/java/sk-matrix-service/api/src/main/java/cn/skcks/matrix/v2/advice/ExceptionAdvice.java new file mode 100644 index 0000000..540467b --- /dev/null +++ b/backend/java/sk-matrix-service/api/src/main/java/cn/skcks/matrix/v2/advice/ExceptionAdvice.java @@ -0,0 +1,75 @@ +package cn.skcks.matrix.v2.advice; + +import cn.skcks.matrix.v2.utils.json.JsonResponse; +import jakarta.validation.ConstraintViolationException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.http.converter.HttpMessageNotReadableException; +import org.springframework.validation.BindException; +import org.springframework.web.HttpMediaTypeNotAcceptableException; +import org.springframework.web.HttpMediaTypeNotSupportedException; +import org.springframework.web.bind.MethodArgumentNotValidException; +import org.springframework.web.bind.MissingServletRequestParameterException; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.RestControllerAdvice; + +import java.util.Objects; + +/** + * 全局异常处理类 + * + * @author Shikong + */ +@RestControllerAdvice +public class ExceptionAdvice { + private final static Logger logger = LoggerFactory.getLogger(ExceptionAdvice.class); + + @ExceptionHandler(MissingServletRequestParameterException.class) + public JsonResponse MissingServletRequestParameterException(MissingServletRequestParameterException e) { + return JsonResponse.error(e.getMessage()); + } + + @ExceptionHandler(HttpMediaTypeNotSupportedException.class) + public JsonResponse unsupportedMediaTypeException(Exception e) { + e.printStackTrace(); + return JsonResponse.error(e.getMessage()); + } + + @ExceptionHandler(HttpMediaTypeNotAcceptableException.class) + public JsonResponse httpMediaTypeNotAcceptableException(HttpMediaTypeNotAcceptableException e){ + return JsonResponse.error(e.getMessage()); + } + + @ExceptionHandler(RuntimeException.class) + public JsonResponse runtimeException(RuntimeException e) { + e.printStackTrace(); + return JsonResponse.error(e.getMessage()); + } + + @ExceptionHandler(BindException.class) + public JsonResponse handleValidationBindException(BindException e) { + return JsonResponse.error(Objects.requireNonNull(e.getBindingResult().getFieldError()).getDefaultMessage()); + } + + @ExceptionHandler(MethodArgumentNotValidException.class) + public JsonResponse handleMethodArgumentNotValidException(MethodArgumentNotValidException e) { + return JsonResponse.error(Objects.requireNonNull(e.getBindingResult().getFieldError()).getDefaultMessage()); + } + + @ExceptionHandler(ConstraintViolationException.class) + public JsonResponse handleConstraintViolationException(ConstraintViolationException e) { + return JsonResponse.error(Objects.requireNonNull(e.getMessage())); + } + + @ExceptionHandler(HttpMessageNotReadableException.class) + public JsonResponse handleHttpMessageNotReadableException(HttpMessageNotReadableException e){ + logger.warn("{}", e.getMessage()); + return JsonResponse.error("参数异常"); + } + + @ExceptionHandler(Exception.class) + public JsonResponse exception(Exception e) { + e.printStackTrace(); + return JsonResponse.error(e.getMessage()); + } +} diff --git a/backend/java/sk-matrix-service/api/src/main/java/cn/skcks/matrix/v2/config/json/JsonConfig.java b/backend/java/sk-matrix-service/api/src/main/java/cn/skcks/matrix/v2/config/json/JsonConfig.java new file mode 100644 index 0000000..6606522 --- /dev/null +++ b/backend/java/sk-matrix-service/api/src/main/java/cn/skcks/matrix/v2/config/json/JsonConfig.java @@ -0,0 +1,14 @@ +package cn.skcks.matrix.v2.config.json; + +import cn.skcks.matrix.v2.utils.json.JsonUtils; +import com.fasterxml.jackson.databind.ObjectMapper; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration +public class JsonConfig { + @Bean + public ObjectMapper jacksonObjectMapper(){ + return JsonUtils.mapper; + } +} diff --git a/backend/java/sk-matrix-service/api/src/main/java/cn/skcks/matrix/v2/config/swagger/SwaggerConfig.java b/backend/java/sk-matrix-service/api/src/main/java/cn/skcks/matrix/v2/config/swagger/SwaggerConfig.java new file mode 100644 index 0000000..91edc19 --- /dev/null +++ b/backend/java/sk-matrix-service/api/src/main/java/cn/skcks/matrix/v2/config/swagger/SwaggerConfig.java @@ -0,0 +1,53 @@ +package cn.skcks.matrix.v2.config.swagger; + +import io.swagger.v3.oas.models.info.Info; +import io.swagger.v3.oas.models.info.License; +import io.swagger.v3.oas.models.security.SecurityRequirement; +import io.swagger.v3.oas.models.security.SecurityScheme; +import lombok.Data; +import org.springdoc.core.customizers.OpenApiCustomizer; +import org.springdoc.core.models.GroupedOpenApi; +import org.springframework.context.annotation.Configuration; + +import static org.springdoc.core.utils.Constants.ALL_PATTERN; + + +@Configuration +@Data +public class SwaggerConfig { + public static final Info INFO; + private static final License LICENSE; + + static { + INFO = new Info() + .title("Matrix API") + .description("Matrix API description") + .version("2.0"); + LICENSE = new License() + .name("Apache 2.0") + .url("http://www.apache.org/licenses/LICENSE-2.0.html"); + INFO.license(LICENSE); + } + + public static GroupedOpenApi api(String group, String path) { + return GroupedOpenApi.builder() + .group(group) + .pathsToMatch(path + ALL_PATTERN) + .addOpenApiCustomizer(openApi -> openApi.info(SwaggerConfig.INFO)) + .addOpenApiCustomizer(authOpenApiDocs()) + .build(); + } + + private static OpenApiCustomizer authOpenApiDocs(){ + return openApi -> { + // swagger 全局添加 token 认证选项 + openApi.addSecurityItem(new SecurityRequirement().addList("token")); + openApi.getComponents() + .addSecuritySchemes("token", + new SecurityScheme() + .type(SecurityScheme.Type.APIKEY) + .in(SecurityScheme.In.HEADER) + .name("token")); + }; + } +} diff --git a/backend/java/sk-matrix-service/api/src/main/java/cn/skcks/matrix/v2/config/undertow/UndertowWebSocketConfig.java b/backend/java/sk-matrix-service/api/src/main/java/cn/skcks/matrix/v2/config/undertow/UndertowWebSocketConfig.java new file mode 100644 index 0000000..60f0dda --- /dev/null +++ b/backend/java/sk-matrix-service/api/src/main/java/cn/skcks/matrix/v2/config/undertow/UndertowWebSocketConfig.java @@ -0,0 +1,19 @@ +package cn.skcks.matrix.v2.config.undertow; + +import io.undertow.server.DefaultByteBufferPool; +import io.undertow.websockets.jsr.WebSocketDeploymentInfo; +import org.springframework.boot.web.embedded.undertow.UndertowServletWebServerFactory; +import org.springframework.boot.web.server.WebServerFactoryCustomizer; +import org.springframework.stereotype.Component; + +@Component +public class UndertowWebSocketConfig implements WebServerFactoryCustomizer { + @Override + public void customize(UndertowServletWebServerFactory factory) { + factory.addDeploymentInfoCustomizers(deploymentInfo -> { + WebSocketDeploymentInfo webSocketDeploymentInfo = new WebSocketDeploymentInfo(); + webSocketDeploymentInfo.setBuffers(new DefaultByteBufferPool(false, 1024)); + deploymentInfo.addServletContextAttribute("io.undertow.websockets.jsr.WebSocketDeploymentInfo", webSocketDeploymentInfo); + }); + } +} diff --git a/backend/java/sk-matrix-service/casbin/pom.xml b/backend/java/sk-matrix-service/casbin/pom.xml new file mode 100644 index 0000000..0027e9e --- /dev/null +++ b/backend/java/sk-matrix-service/casbin/pom.xml @@ -0,0 +1,76 @@ + + + + cn.skcks.matrix.v2 + sk-matrix-service + 1.0-SNAPSHOT + + 4.0.0 + + casbin + + + UTF-8 + + + + + org.projectlombok + lombok + + + + org.casbin + casbin-spring-boot-starter + + + org.casbin + jcasbin + + + + + + org.casbin + jcasbin + 1.31.4 + + + + + org.casbin + jdbc-adapter + + + org.casbin + jcasbin + + + + + + org.springframework + spring-context + + + + org.springframework.boot + spring-boot-autoconfigure + + + + org.apache.shardingsphere + shardingsphere-jdbc-core + ${shardingsphere.version} + provided + + + + cn.hutool + hutool-all + + + + diff --git a/backend/java/sk-matrix-service/casbin/src/main/java/cn/skcks/matrix/v2/casbin/adapter/CustomJDBCAdapter.java b/backend/java/sk-matrix-service/casbin/src/main/java/cn/skcks/matrix/v2/casbin/adapter/CustomJDBCAdapter.java new file mode 100644 index 0000000..f0c6300 --- /dev/null +++ b/backend/java/sk-matrix-service/casbin/src/main/java/cn/skcks/matrix/v2/casbin/adapter/CustomJDBCAdapter.java @@ -0,0 +1,218 @@ +package cn.skcks.matrix.v2.casbin.adapter; + +import cn.hutool.core.util.IdUtil; +import dev.failsafe.Failsafe; +import org.apache.commons.collections4.CollectionUtils; +import org.casbin.adapter.JDBCAdapter; +import org.casbin.jcasbin.model.Assertion; +import org.casbin.jcasbin.model.Model; + +import javax.sql.DataSource; +import java.sql.*; +import java.util.List; +import java.util.Map; + +public class CustomJDBCAdapter extends JDBCAdapter { + static class CasbinRule { + int id; // Fields reserved for compatibility with other adapters, and the primary key is automatically incremented. + String ptype; + String v0; + String v1; + String v2; + String v3; + String v4; + String v5; + + public String[] toStringArray() { + return new String[]{ptype, v0, v1, v2, v3, v4, v5}; + } + } + + private final int batchSize = 1000; + + public CustomJDBCAdapter(DataSource dataSource, boolean removePolicyFailed, String tableName, boolean autoCreateTable) throws Exception { + super(dataSource, removePolicyFailed, tableName, autoCreateTable); + } + + @Override + protected void migrate() throws SQLException { + Statement stmt = conn.createStatement(); + String sql = renderActualSql("CREATE TABLE IF NOT EXISTS casbin_rule(id bigint NOT NULL PRIMARY KEY auto_increment, ptype VARCHAR(100) NOT NULL, v0 VARCHAR(100), v1 VARCHAR(100), v2 VARCHAR(100), v3 VARCHAR(100), v4 VARCHAR(100), v5 VARCHAR(100))"); + String productName = conn.getMetaData().getDatabaseProductName(); + + switch (productName) { + case "MySQL": + String hasTableSql = renderActualSql("SHOW TABLES LIKE 'casbin_rule';"); + ResultSet rs = stmt.executeQuery(hasTableSql); + if (rs.next()) { + return; + } + break; + } + + stmt.executeUpdate(sql); + } + + private CasbinRule savePolicyLine(String ptype, List rule) { + CasbinRule line = new CasbinRule(); + + line.ptype = ptype; + if (rule.size() > 0) { + line.v0 = rule.get(0); + } + if (rule.size() > 1) { + line.v1 = rule.get(1); + } + if (rule.size() > 2) { + line.v2 = rule.get(2); + } + if (rule.size() > 3) { + line.v3 = rule.get(3); + } + if (rule.size() > 4) { + line.v4 = rule.get(4); + } + if (rule.size() > 5) { + line.v5 = rule.get(5); + } + + return line; + } + + @Override + public void addPolicies(String sec, String ptype, List> rules) { + if (CollectionUtils.isEmpty(rules)) { + return; + } + + try (Connection conn = dataSource.getConnection()) { + String sql = renderActualSql("INSERT INTO casbin_rule (ptype,v0,v1,v2,v3,v4,v5,id) VALUES(?,?,?,?,?,?,?,?)"); + + Failsafe.with(retryPolicy).run(ctx -> { + if (ctx.isRetry()) { + retry(ctx); + } + conn.setAutoCommit(false); + int count = 0; + try (PreparedStatement ps = conn.prepareStatement(sql)) { + for (List rule : rules) { + CasbinRule line = savePolicyLine(ptype, rule); + + ps.setString(1, line.ptype); + ps.setString(2, line.v0); + ps.setString(3, line.v1); + ps.setString(4, line.v2); + ps.setString(5, line.v3); + ps.setString(6, line.v4); + ps.setString(7, line.v5); + ps.setString(8, IdUtil.getSnowflakeNextIdStr()); + ps.addBatch(); + if (++count == batchSize) { + count = 0; + ps.executeBatch(); + ps.clearBatch(); + } + } + if (count != 0) { + ps.executeBatch(); + } + conn.commit(); + } catch (SQLException e) { + conn.rollback(); + + e.printStackTrace(); + throw e; + } finally { + conn.setAutoCommit(true); + } + }); + } catch (SQLException e) { + throw new RuntimeException(e); + } + + } + + @Override + public void savePolicy(Model model) { + String cleanSql = renderActualSql("delete from casbin_rule"); + String addSql = renderActualSql("INSERT INTO casbin_rule (ptype,v0,v1,v2,v3,v4,v5,id) VALUES(?,?,?,?,?,?,?,?)"); + + try (Connection conn = dataSource.getConnection()) { + Failsafe.with(retryPolicy).run(ctx -> { + if (ctx.isRetry()) { + retry(ctx); + } + conn.setAutoCommit(false); + + int count = 0; + + try (Statement statement = conn.createStatement(); PreparedStatement ps = conn.prepareStatement(addSql)) { + statement.execute(cleanSql); + for (Map.Entry entry : model.model.get("p").entrySet()) { + String ptype = entry.getKey(); + Assertion ast = entry.getValue(); + + for (List rule : ast.policy) { + CasbinRule line = savePolicyLine(ptype, rule); + + ps.setString(1, line.ptype); + ps.setString(2, line.v0); + ps.setString(3, line.v1); + ps.setString(4, line.v2); + ps.setString(5, line.v3); + ps.setString(6, line.v4); + ps.setString(7, line.v5); + ps.setString(8, IdUtil.getSnowflakeNextIdStr()); + ps.addBatch(); + if (++count == batchSize) { + count = 0; + ps.executeBatch(); + ps.clearBatch(); + } + } + } + + for (Map.Entry entry : model.model.get("g").entrySet()) { + String ptype = entry.getKey(); + Assertion ast = entry.getValue(); + + for (List rule : ast.policy) { + CasbinRule line = savePolicyLine(ptype, rule); + + ps.setString(1, line.ptype); + ps.setString(2, line.v0); + ps.setString(3, line.v1); + ps.setString(4, line.v2); + ps.setString(5, line.v3); + ps.setString(6, line.v4); + ps.setString(7, line.v5); + ps.setString(8, IdUtil.getSnowflakeNextIdStr()); + + ps.addBatch(); + if (++count == batchSize) { + count = 0; + ps.executeBatch(); + ps.clearBatch(); + } + } + } + + if (count != 0) { + ps.executeBatch(); + } + + conn.commit(); + } catch (SQLException e) { + conn.rollback(); + + e.printStackTrace(); + throw e; + } finally { + conn.setAutoCommit(true); + } + }); + } catch (SQLException e) { + throw new RuntimeException(e); + } + } +} diff --git a/backend/java/sk-matrix-service/casbin/src/main/java/cn/skcks/matrix/v2/casbin/config/CasbinConfig.java b/backend/java/sk-matrix-service/casbin/src/main/java/cn/skcks/matrix/v2/casbin/config/CasbinConfig.java new file mode 100644 index 0000000..4d65366 --- /dev/null +++ b/backend/java/sk-matrix-service/casbin/src/main/java/cn/skcks/matrix/v2/casbin/config/CasbinConfig.java @@ -0,0 +1,31 @@ +package cn.skcks.matrix.v2.casbin.config; + +import cn.skcks.matrix.v2.casbin.adapter.CustomJDBCAdapter; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.apache.shardingsphere.driver.jdbc.core.datasource.ShardingSphereDataSource; +import org.casbin.jcasbin.persist.Adapter; +import org.casbin.spring.boot.autoconfigure.properties.CasbinDataSourceInitializationMode; +import org.casbin.spring.boot.autoconfigure.properties.CasbinExceptionProperties; +import org.casbin.spring.boot.autoconfigure.properties.CasbinProperties; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Primary; +import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; + +@Slf4j +@Configuration +@RequiredArgsConstructor +@ConditionalOnClass(ShardingSphereDataSource.class) +public class CasbinConfig { + private final ShardingSphereDataSource dataSource; + + @Primary + @Bean + public Adapter autoConfigJdbcAdapter(CasbinProperties properties, CasbinExceptionProperties exceptionProperties) throws Exception { + CasbinDataSourceInitializationMode initializeSchema = properties.getInitializeSchema(); + boolean autoCreateTable = initializeSchema == CasbinDataSourceInitializationMode.CREATE; + String tableName = properties.getTableName(); + return new CustomJDBCAdapter(dataSource,exceptionProperties.isRemovePolicyFailed(),tableName, autoCreateTable); + } +} diff --git a/backend/java/sk-matrix-service/casbin/src/main/resources/casbin/model.conf b/backend/java/sk-matrix-service/casbin/src/main/resources/casbin/model.conf new file mode 100644 index 0000000..7b8bb0f --- /dev/null +++ b/backend/java/sk-matrix-service/casbin/src/main/resources/casbin/model.conf @@ -0,0 +1,14 @@ +[request_definition] +r = identity, system, api, act + +[policy_definition] +p = identity, system, api, act + +[role_definition] +g = _, _, _ + +[policy_effect] +e = some(where (p.eft == allow)) + +[matchers] +m = g(r.identity, p.identity, r.system) && r.system == p.system && keyMatch3(r.api, p.api) && regexMatch(r.act, p.act) \ No newline at end of file diff --git a/backend/java/sk-matrix-service/common/pom.xml b/backend/java/sk-matrix-service/common/pom.xml new file mode 100644 index 0000000..cc40bc1 --- /dev/null +++ b/backend/java/sk-matrix-service/common/pom.xml @@ -0,0 +1,82 @@ + + + 4.0.0 + + cn.skcks.matrix.v2 + sk-matrix-service + 1.0-SNAPSHOT + + + common + + + 17 + 17 + UTF-8 + + + + + + com.github.pagehelper + pagehelper-spring-boot-starter + + + + cn.hutool + hutool-all + + + + org.junit.jupiter + junit-jupiter-api + test + + + + com.fasterxml.jackson.core + jackson-core + + + com.fasterxml.jackson.core + jackson-databind + + + com.fasterxml.jackson.core + jackson-annotations + + + + org.springframework.boot + spring-boot-starter-logging + test + + + + org.springdoc + springdoc-openapi-starter-common + + + + org.projectlombok + lombok + + + + org.springframework.data + spring-data-redis + + + lettuce-core + io.lettuce + + + + + redis.clients + jedis + + + diff --git a/backend/java/sk-matrix-service/common/src/main/java/cn/skcks/matrix/v2/utils/base91/Base91.java b/backend/java/sk-matrix-service/common/src/main/java/cn/skcks/matrix/v2/utils/base91/Base91.java new file mode 100644 index 0000000..225fe0e --- /dev/null +++ b/backend/java/sk-matrix-service/common/src/main/java/cn/skcks/matrix/v2/utils/base91/Base91.java @@ -0,0 +1,106 @@ +package cn.skcks.matrix.v2.utils.base91; + +import java.io.ByteArrayOutputStream; +import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; +import java.util.Arrays; + +public class Base91 { + private static final float AVERAGE_ENCODING_RATIO = 1.2297f; + private static final int BASE = 91; + private static final char[] ENCODING_TABLE = { + 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', + 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', + 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', + 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', + '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', + '!', '#', '$', '%', '&', '(', ')', '*', '+', ',', '.', '/', ':', ';', + '<', '=', '>', '?', '@', '[', ']', '^', '_', '`', '{', '|', '}', '~', + '"'}; + + private static final int[] DECODING_TABLE; + + static { + int[] charts = new int[255]; + Arrays.fill(charts, -1); + for (int i = 0; i < ENCODING_TABLE.length; i++) { + charts[ENCODING_TABLE[i]] = i; + } + DECODING_TABLE = charts; + } + + public static String encodeString(String str, Charset charset) { + return encode(str.getBytes(charset)); + } + + public static String encodeString(String str) { + return encode(str.getBytes(StandardCharsets.UTF_8)); + } + + public static String encode(byte[] bytes) { + int ebq = 0; + int en = 0; + StringBuilder buffer = new StringBuilder(); + for (int b : bytes) { + ebq |= (b & 255) << en; + en += 8; + if (en > 13) { + int ev = ebq & 8191; + + if (ev > 88) { + ebq >>= 13; + en -= 13; + } else { + ev = ebq & 16383; + ebq >>= 14; + en -= 14; + } + buffer.append(ENCODING_TABLE[ev % BASE]); + buffer.append(ENCODING_TABLE[ev / BASE]); + } + } + + if (en > 0) { + buffer.append(ENCODING_TABLE[ebq % BASE]); + if (en > 7 || ebq > 90) { + buffer.append(ENCODING_TABLE[ebq / BASE]); + } + } + + return buffer.toString(); + } + + public static byte[] decode(String str) { + byte[] data = str.getBytes(StandardCharsets.UTF_8); + int dbq = 0, dn = 0, dv = -1; + int estimatedSize = Math.round(data.length / AVERAGE_ENCODING_RATIO); + ByteArrayOutputStream buffer = new ByteArrayOutputStream(estimatedSize); + for (byte datum : data) { + if (dv == -1) + dv = DECODING_TABLE[datum]; + else { + dv += DECODING_TABLE[datum] * BASE; + dbq |= dv << dn; + dn += (dv & 8191) > 88 ? 13 : 14; + do { + buffer.write(dbq); + dbq >>= 8; + dn -= 8; + } while (dn > 7); + dv = -1; + } + } + if (dv != -1) { + buffer.write((dbq | dv << dn)); + } + return buffer.toByteArray(); + } + + public static String decodeString(String str) { + return new String(decode(str), StandardCharsets.UTF_8); + } + + public static String decodeString(String str, Charset charset) { + return new String(decode(str), charset); + } +} diff --git a/backend/java/sk-matrix-service/common/src/main/java/cn/skcks/matrix/v2/utils/json/JsonResponse.java b/backend/java/sk-matrix-service/common/src/main/java/cn/skcks/matrix/v2/utils/json/JsonResponse.java new file mode 100644 index 0000000..59ea51a --- /dev/null +++ b/backend/java/sk-matrix-service/common/src/main/java/cn/skcks/matrix/v2/utils/json/JsonResponse.java @@ -0,0 +1,48 @@ +package cn.skcks.matrix.v2.utils.json; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +@Data +@SuppressWarnings("unused") +@Schema(title = "返回结果") +public class JsonResponse { + @Schema(title = "状态码") + private int code; + + @Schema(title = "响应消息") + private String msg; + + @Schema(title = "响应数据") + private T data; + + public JsonResponse(int code, String msg, T data) { + this.code = code; + this.msg = msg; + this.data = data; + } + + public static JsonResponse success(T data) { + return JsonResponse.build(data, ResponseStatus.OK); + } + + public static JsonResponse success(T data, String message) { + return JsonResponse.build(data, ResponseStatus.OK.getCode(), message); + } + + public static JsonResponse error(T data) { + return JsonResponse.build(data, ResponseStatus.INTERNAL_SERVER_ERROR); + } + + public static JsonResponse error(T data, String message) { + return JsonResponse.build(data, ResponseStatus.INTERNAL_SERVER_ERROR.getCode(), message); + } + + public static JsonResponse build(T data, ResponseStatus status) { + return new JsonResponse<>(status.getCode(), status.getMessage(), data); + } + + public static JsonResponse build(T data, int status, String msg) { + return new JsonResponse<>(status, msg, data); + } +} diff --git a/backend/java/sk-matrix-service/common/src/main/java/cn/skcks/matrix/v2/utils/json/JsonUtils.java b/backend/java/sk-matrix-service/common/src/main/java/cn/skcks/matrix/v2/utils/json/JsonUtils.java new file mode 100644 index 0000000..27ce963 --- /dev/null +++ b/backend/java/sk-matrix-service/common/src/main/java/cn/skcks/matrix/v2/utils/json/JsonUtils.java @@ -0,0 +1,81 @@ +package cn.skcks.matrix.v2.utils.json; + +import com.fasterxml.jackson.core.json.JsonReadFeature; +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.SerializationFeature; + +@SuppressWarnings("unused") +public class JsonUtils { + public static final ObjectMapper mapper; + public static final ObjectMapper compressMapper; + + static { + mapper = new ObjectMapper(); + compressMapper = new ObjectMapper(); + + mapper.enable(SerializationFeature.INDENT_OUTPUT); + compressMapper.disable(SerializationFeature.INDENT_OUTPUT); + + // 返回内容中 不含 值为 null 的字段 + // mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); + mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false); + compressMapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false); + + // 如果json中有新增的字段并且是实体类类中不存在的,不报错 + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + mapper.configure(DeserializationFeature.FAIL_ON_IGNORED_PROPERTIES, false); + + compressMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + compressMapper.configure(DeserializationFeature.FAIL_ON_IGNORED_PROPERTIES, false); + + // 允许出现特殊字符和转义符 + mapper.configure(JsonReadFeature.ALLOW_UNESCAPED_CONTROL_CHARS.mappedFeature(), true); + compressMapper.configure(JsonReadFeature.ALLOW_UNESCAPED_CONTROL_CHARS.mappedFeature(), true); + + // 允许出现单引号 + mapper.configure(JsonReadFeature.ALLOW_SINGLE_QUOTES.mappedFeature(), true); + compressMapper.configure(JsonReadFeature.ALLOW_SINGLE_QUOTES.mappedFeature(), true); + } + + public static T parse(String json, Class clazz) { + try { + return mapper.readValue(json, clazz); + } catch (Exception e) { + e.printStackTrace(); + return null; + } + } + + public static T parse(String json, TypeReference clazz) { + try { + return mapper.readValue(json, clazz); + } catch (Exception e) { + e.printStackTrace(); + return null; + } + } + + public static String toCompressJson(Object obj) { + try { + return compressMapper.writeValueAsString(obj); + } catch (Exception e) { + e.printStackTrace(); + return null; + } + } + + public static String toJson(Object obj) { + try { + return mapper.writeValueAsString(obj); + } catch (Exception e) { + e.printStackTrace(); + return null; + } + } + + public static T convert(Object object, Class clazz) { + return JsonUtils.parse(JsonUtils.toJson(object), clazz); + } +} diff --git a/backend/java/sk-matrix-service/common/src/main/java/cn/skcks/matrix/v2/utils/json/ResponseStatus.java b/backend/java/sk-matrix-service/common/src/main/java/cn/skcks/matrix/v2/utils/json/ResponseStatus.java new file mode 100644 index 0000000..b9ee58a --- /dev/null +++ b/backend/java/sk-matrix-service/common/src/main/java/cn/skcks/matrix/v2/utils/json/ResponseStatus.java @@ -0,0 +1,60 @@ +package cn.skcks.matrix.v2.utils.json; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +@Getter +@AllArgsConstructor +@SuppressWarnings("unused") +public enum ResponseStatus { + UNKNOWN(-1, "Unknown"), + UNDEFINED(0, "Undefined"), + OK(200, "OK"), + CREATED(201, "Created"), + ACCEPTED(202, "Accepted"), + NO_CONTENT(204, "No Content"), + MOVED_PERMANENTLY(301, "Moved Permanently"), + FOUND(302, "Found"), + SEE_OTHER(303, "See Other"), + NOT_MODIFIED(304, "Not Modified"), + TEMPORARY_REDIRECT(307, "Temporary Redirect"), + BAD_REQUEST(400, "Bad Request"), + UNAUTHORIZED(401, "Unauthorized"), + FORBIDDEN(403, "Forbidden"), + NOT_FOUND(404, "Not Found"), + METHOD_NOT_ALLOWED(405, "Method Not Allowed"), + NOT_ACCEPTABLE(406, "Not Acceptable"), + REQUEST_TIMEOUT(408, "Request Timeout"), + CONFLICT(409, "Conflict"), + GONE(410, "Gone"), + LENGTH_REQUIRED(411, "Length Required"), + PRECONDITION_FAILED(412, "Precondition Failed"), + PAYLOAD_TOO_LARGE(413, "Payload Too Large"), + URI_TOO_LONG(414, "URI Too Long"), + UNSUPPORTED_MEDIA_TYPE(415, "Unsupported Media Type"), + RANGE_NOT_SATISFIABLE(416, "Range Not Satisfiable"), + EXPECTATION_FAILED(417, "Expectation Failed"), + TOO_MANY_REQUESTS(429, "Too Many Requests"), + INTERNAL_SERVER_ERROR(500, "Internal Server Error"), + NOT_IMPLEMENTED(501, "Not Implemented"), + BAD_GATEWAY(502, "Bad Gateway"), + SERVICE_UNAVAILABLE(503, "Service Unavailable"); + + + private final int code; + private final String message; + + public static ResponseStatus getByCode(int code) { + for (ResponseStatus status : values()) { + if (status.getCode() == code) { + return status; + } + } + return null; + } + + public static ResponseStatus valueOf(int code) { + return getByCode(code); + } +} + diff --git a/backend/java/sk-matrix-service/common/src/main/java/cn/skcks/matrix/v2/utils/page/PageWrapper.java b/backend/java/sk-matrix-service/common/src/main/java/cn/skcks/matrix/v2/utils/page/PageWrapper.java new file mode 100644 index 0000000..aa7b931 --- /dev/null +++ b/backend/java/sk-matrix-service/common/src/main/java/cn/skcks/matrix/v2/utils/page/PageWrapper.java @@ -0,0 +1,39 @@ +package cn.skcks.matrix.v2.utils.page; + +import com.github.pagehelper.PageInfo; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.Collection; + +@AllArgsConstructor +@NoArgsConstructor +@Data +@SuppressWarnings({"unused"}) +@Schema(title = "分页数据") +public class PageWrapper { + @Schema(title = "数据") + private Collection data; + @Schema(title = "页码") + private long page; + @Schema(title = "每页大小") + private long pageSize; + @Schema(title = "总页数") + private long pageTotal; + @Schema(title = "数据总数") + private long total; + + public static PageWrapper of(Collection data, long page, long pageSize, long pageTotal, long total) { + return new PageWrapper<>(data, page, pageSize, pageTotal, total); + } + + public static PageWrapper of(PageInfo pageInfo) { + return new PageWrapper<>(pageInfo.getList(), + pageInfo.getPageNum(), + pageInfo.getPageSize(), + pageInfo.getPages(), + pageInfo.getTotal()); + } +} diff --git a/backend/java/sk-matrix-service/common/src/main/java/cn/skcks/matrix/v2/utils/redis/RedisUtil.java b/backend/java/sk-matrix-service/common/src/main/java/cn/skcks/matrix/v2/utils/redis/RedisUtil.java new file mode 100644 index 0000000..281acd2 --- /dev/null +++ b/backend/java/sk-matrix-service/common/src/main/java/cn/skcks/matrix/v2/utils/redis/RedisUtil.java @@ -0,0 +1,2781 @@ +package cn.skcks.matrix.v2.utils.redis; + +import cn.hutool.json.JSONUtil; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.BeansException; +import org.springframework.context.ApplicationContext; +import org.springframework.context.ApplicationContextAware; +import org.springframework.data.redis.RedisSystemException; +import org.springframework.data.redis.connection.DataType; +import org.springframework.data.redis.connection.RedisConnection; +import org.springframework.data.redis.connection.RedisStringCommands; +import org.springframework.data.redis.connection.ReturnType; +import org.springframework.data.redis.connection.jedis.JedisConnection; +import org.springframework.data.redis.connection.lettuce.LettuceConnection; +import org.springframework.data.redis.core.*; +import org.springframework.data.redis.core.ZSetOperations.TypedTuple; +import org.springframework.data.redis.core.types.Expiration; +import org.springframework.stereotype.Component; + +import java.nio.charset.StandardCharsets; +import java.time.Instant; +import java.util.*; +import java.util.Map.Entry; +import java.util.concurrent.TimeUnit; + +/** + * Redis工具类 + *

+ * 声明: 此工具只简单包装了redisTemplate的大部分常用的api, 没有包装redisTemplate所有的api。 + * 如果对此工具类中的功能不太满意, 或对StringRedisTemplate提供的api不太满意, + * 那么可自行实现相应的{@link StringRedisTemplate}类中的对应execute方法, 以达 + * 到自己想要的效果; 至于如何实现,则可参考源码或{@link LockOps}中的方法。 + *

+ * 注: 此工具类依赖spring-boot-starter-data-redis类库、以及可选的lombok、fastjson + * 注: 更多javadoc细节,可详见{@link RedisOperations} + *

+ * 统一说明一: 方法中的key、 value都不能为null。 + * 统一说明二: 不能跨数据类型进行操作, 否者会操作失败/操作报错。 + * 如: 向一个String类型的做Hash操作,会失败/报错......等等 + * + * @author JustryDeng + */ +@Slf4j +@Component +@SuppressWarnings("all") +public class RedisUtil implements ApplicationContextAware { + + /** + * 使用StringRedisTemplate(,其是RedisTemplate的定制化升级) + */ + private static StringRedisTemplate redisTemplate; + + @Override + public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { + RedisUtil.redisTemplate = applicationContext.getBean(StringRedisTemplate.class); + } + + /** + * key相关操作 + * + * @author JustryDeng + */ + public static class KeyOps { + + /** + * 根据key, 删除redis中的对应key-value + *

+ * 注: 若删除失败, 则返回false。 + *

+ * 若redis中,不存在该key, 那么返回的也是false。 + * 所以,不能因为返回了false,就认为redis中一定还存 + * 在该key对应的key-value。 + * + * @param key 要删除的key + * @return 删除是否成功 + */ + public static boolean delete(String key) { + log.info("delete(...) => key -> {}", key); + // 返回值只可能为true/false, 不可能为null + Boolean result = redisTemplate.delete(key); + log.info("delete(...) => result -> {}", result); + if (result == null) { + throw new RedisOpsResultIsNullException(); + } + return result; + } + + /** + * 根据keys, 批量删除key-value + *

+ * 注: 若redis中,不存在对应的key, 那么计数不会加1, 即: + * redis中存在的key-value里,有名为a1、a2的key, + * 删除时,传的集合是a1、a2、a3,那么返回结果为2。 + * + * @param keys 要删除的key集合 + * @return 删除了的key-value个数 + */ + public static long delete(Collection keys) { + log.info("delete(...) => keys -> {}", keys); + Long count = redisTemplate.delete(keys); + log.info("delete(...) => count -> {}", count); + if (count == null) { + throw new RedisOpsResultIsNullException(); + } + return count; + } + + /** + * 将key对应的value值进行序列化,并返回序列化后的value值。 + *

+ * 注: 若不存在对应的key, 则返回null。 + * 注: dump时,并不会删除redis中的对应key-value。 + * 注: dump功能与restore相反。 + * + * @param key 要序列化的value的key + * @return 序列化后的value值 + */ + public static byte[] dump(String key) { + log.info("dump(...) =>key -> {}", key); + byte[] result = redisTemplate.dump(key); + log.info("dump(...) => result -> {}", result); + return result; + } + + /** + * 将给定的value值,反序列化到redis中, 形成新的key-value。 + * + * @param key value对应的key + * @param value 要反序列的value值。 + * 注: 这个值可以由{@link this#dump(String)}获得 + * @param timeToLive 反序列化后的key-value的存活时长 + * @param unit timeToLive的单位 + * @throws RedisSystemException 如果redis中已存在同样的key时,抛出此异常 + */ + public static void restore(String key, byte[] value, long timeToLive, TimeUnit unit) { + restore(key, value, timeToLive, unit, false); + } + + /** + * 将给定的value值,反序列化到redis中, 形成新的key-value。 + * + * @param key value对应的key + * @param value 要反序列的value值。 + * 注: 这个值可以由{@link this#dump(String)}获得 + * @param timeout 反序列化后的key-value的存活时长 + * @param unit timeout的单位 + * @param replace 若redis中已经存在了相同的key, 是否替代原来的key-value + * @throws RedisSystemException 如果redis中已存在同样的key, 且replace为false时,抛出此异常 + */ + public static void restore(String key, byte[] value, long timeout, TimeUnit unit, boolean replace) { + log.info("restore(...) => key -> {}, value -> {}, timeout -> {}, unit -> {}, replace -> {}", + key, value, timeout, unit, replace); + redisTemplate.restore(key, value, timeout, unit, replace); + } + + /** + * redis中是否存在,指定key的key-value + * + * @param key 指定的key + * @return 是否存在对应的key-value + */ + public static boolean hasKey(String key) { + log.info("hasKey(...) => key -> {}", key); + Boolean result = redisTemplate.hasKey(key); + log.info("hasKey(...) => result -> {}", result); + if (result == null) { + throw new RedisOpsResultIsNullException(); + } + return result; + } + + /** + * 给指定的key对应的key-value设置: 多久过时 + *

+ * 注:过时后,redis会自动删除对应的key-value。 + * 注:若key不存在,那么也会返回false。 + * + * @param key 指定的key + * @param timeout 过时时间 + * @param unit timeout的单位 + * @return 操作是否成功 + */ + public static boolean expire(String key, long timeout, TimeUnit unit) { + log.info("expire(...) => key -> {}, timeout -> {}, unit -> {}", key, timeout, unit); + Boolean result = redisTemplate.expire(key, timeout, unit); + log.info("expire(...) => result is -> {}", result); + if (result == null) { + throw new RedisOpsResultIsNullException(); + } + return result; + } + + /** + * 给指定的key对应的key-value设置: 什么时候过时 + *

+ * 注:过时后,redis会自动删除对应的key-value。 + * 注:若key不存在,那么也会返回false。 + * + * @param key 指定的key + * @param date 啥时候过时 + * @return 操作是否成功 + */ + public static boolean expireAt(String key, Date date) { + log.info("expireAt(...) => key -> {}, date -> {}", key, date); + Boolean result = redisTemplate.expireAt(key, date); + log.info("expireAt(...) => result is -> {}", result); + if (result == null) { + throw new RedisOpsResultIsNullException(); + } + return result; + } + + /** + * 找到所有匹配pattern的key,并返回该key的结合. + *

+ * 提示:若redis中键值对较多,此方法耗时相对较长,慎用!慎用!慎用! + * + * @param pattern 匹配模板。 + * 注: 常用的通配符有: + * ? 有且只有一个; + * * >=0哥; + * @return 匹配pattern的key的集合。 可能为null。 + */ + public static Set keys(String pattern) { + log.info("keys(...) => pattern -> {}", pattern); + Set keys = redisTemplate.keys(pattern); + log.info("keys(...) => keys -> {}", keys); + return keys; + } + + /** + * 将当前数据库中的key对应的key-value,移动到对应位置的数据库中。 + *

+ * 注:单机版的redis,默认将存储分为16个db, index为0 到 15。 + * 注:同一个db下,key唯一; 但是在不同db中,key可以相同。 + * 注:若目标db下,已存在相同的key, 那么move会失败,返回false。 + * + * @param key 定位要移动的key-value的key + * @param dbIndex 要移动到哪个db + * @return 移动是否成功。 + * 注: 若目标db下,已存在相同的key, 那么move会失败,返回false。 + */ + public static boolean move(String key, int dbIndex) { + log.info("move(...) => key -> {}, dbIndex -> {}", key, dbIndex); + Boolean result = redisTemplate.move(key, dbIndex); + log.info("move(...) =>result -> {}", result); + if (result == null) { + throw new RedisOpsResultIsNullException(); + } + return result; + } + + /** + * 移除key对应的key-value的过期时间, 使该key-value一直存在 + *

+ * 注: 若key对应的key-value,本身就是一直存在(无过期时间的), 那么persist方法会返回false; + * 若没有key对应的key-value存在,本那么persist方法会返回false; + * + * @param key 定位key-value的key + * @return 操作是否成功 + */ + public static boolean persist(String key) { + log.info("persist(...) => key -> {}", key); + Boolean result = redisTemplate.persist(key); + log.info("persist(...) => result -> {}", result); + if (result == null) { + throw new RedisOpsResultIsNullException(); + } + return result; + } + + /** + * 获取key对应的key-value的过期时间 + *

+ * 注: 若key-value永不过期, 那么返回的为-1。 + * 注: 若不存在key对应的key-value, 那么返回的为-2 + * 注:若存在零碎时间不足1 SECONDS,则(大体上)四舍五入到SECONDS级别。 + * + * @param key 定位key-value的key + * @return 过期时间(单位s) + */ + public static long getExpire(String key) { + Long result = getExpire(key, TimeUnit.SECONDS); + return result; + } + + /** + * 获取key对应的key-value的过期时间 + *

+ * 注: 若key-value永不过期, 那么返回的为-1。 + * 注: 若不存在key对应的key-value, 那么返回的为-2 + * 注:若存在零碎时间不足1 unit,则(大体上)四舍五入到unit别。 + * + * @param key 定位key-value的key + * @return 过期时间(单位unit) + */ + public static long getExpire(String key, TimeUnit unit) { + log.info("getExpire(...) =>key -> {}, unit is -> {}", key, unit); + Long result = redisTemplate.getExpire(key, unit); + log.info("getExpire(...) => result -> {}", result); + if (result == null) { + throw new RedisOpsResultIsNullException(); + } + return result; + } + + /** + * 从redis的所有key中,随机获取一个key + *

+ * 注: 若redis中不存在任何key-value, 那么这里返回null + * + * @return 随机获取到的一个key + */ + public static String randomKey() { + String result = redisTemplate.randomKey(); + log.info("randomKey(...) => result is -> {}", result); + return result; + } + + /** + * 重命名对应的oldKey为新的newKey + *

+ * 注: 若oldKey不存在, 则会抛出异常. + * 注: 若redis中已存在与newKey一样的key, + * 那么原key-value会被丢弃, + * 只留下新的key,以及原来的value + * 示例说明: 假设redis中已有 (keyAlpha, valueAlpha) 和 (keyBeta, valueBeat), + * 在使用rename(keyAlpha, keyBeta)替换后, redis中只会剩下(keyBeta, valueAlpha) + * + * @param oldKey 旧的key + * @param newKey 新的key + * @throws RedisSystemException 若oldKey不存在时, 抛出此异常 + */ + public static void rename(String oldKey, String newKey) { + log.info("rename(...) => oldKey -> {}, newKey -> {}", oldKey, newKey); + redisTemplate.rename(oldKey, newKey); + } + + /** + * 当redis中不存在newKey时, 重命名对应的oldKey为新的newKey。 + * 否者不进行重命名操作。 + *

+ * 注: 若oldKey不存在, 则会抛出异常. + * + * @param oldKey 旧的key + * @param newKey 新的key + * @throws RedisSystemException 若oldKey不存在时, 抛出此异常 + */ + public static boolean renameIfAbsent(String oldKey, String newKey) { + log.info("renameIfAbsent(...) => oldKey -> {}, newKey -> {}", oldKey, newKey); + Boolean result = redisTemplate.renameIfAbsent(oldKey, newKey); + log.info("renameIfAbsent(...) => result -> {}", result); + if (result == null) { + throw new RedisOpsResultIsNullException(); + } + return result; + } + + /** + * 获取key对应的value的数据类型 + *

+ * 注: 若redis中不存在该key对应的key-value, 那么这里返回NONE。 + * + * @param key 用于定位的key + * @return key对应的value的数据类型 + */ + public static DataType type(String key) { + log.info("type(...) => key -> {}", key); + DataType result = redisTemplate.type(key); + log.info("type(...) => result -> {}", result); + return result; + } + } + + /** + * string相关操作 + *

+ * 提示: redis中String的数据结构可参考resources/data-structure/String(字符串)的数据结构(示例一).png + * redis中String的数据结构可参考resources/data-structure/String(字符串)的数据结构(示例二).png + * + * @author JustryDeng + */ + public static class StringOps { + + /** + * 设置key-value + *

+ * 注: 若已存在相同的key, 那么原来的key-value会被丢弃。 + * + * @param key key + * @param value key对应的value + */ + public static void set(String key, String value) { + log.info("set(...) => key -> {}, value -> {}", key, value); + redisTemplate.opsForValue().set(key, value); + } + + /** + * 处理redis中key对应的value值, 将第offset位的值, 设置为1或0。 + *

+ * 说明: 在redis中,存储的字符串都是以二级制的进行存在的; 如存储的key-value里,值为abc,实际上, + * 在redis里面存储的是011000010110001001100011,前8为对应a,中间8为对应b,后面8位对应c。 + * 示例:这里如果setBit(key, 6, true)的话,就是将索引位置6的那个数,设置值为1,值就变成 + * 了011000110110001001100011 + * 追注:offset即index,从0开始。 + *

+ * 注: 参数value为true, 则设置为1;参数value为false, 则设置为0。 + *

+ * 注: 若redis中不存在对应的key,那么会自动创建新的。 + * 注: offset可以超过value在二进制下的索引长度。 + * + * @param key 定位value的key + * @param offset 要改变的bit的索引 + * @param value 改为1或0, true - 改为1, false - 改为0 + * @return set是否成功 + */ + public static boolean setBit(String key, long offset, boolean value) { + log.info("setBit(...) => key -> {}, offset -> {}, value -> {}", key, offset, value); + Boolean result = redisTemplate.opsForValue().setBit(key, offset, value); + log.info("setBit(...) => result -> {}", result); + if (result == null) { + throw new RedisOpsResultIsNullException(); + } + return result; + } + + /** + * 设置key-value + *

+ * 注: 若已存在相同的key, 那么原来的key-value会被丢弃 + * + * @param key key + * @param value key对应的value + * @param timeout 过时时长 + * @param unit timeout的单位 + */ + public static void setEx(String key, String value, long timeout, TimeUnit unit) { + log.info("setEx(...) => key -> {}, value -> {}, timeout -> {}, unit -> {}", + key, value, timeout, unit); + redisTemplate.opsForValue().set(key, value, timeout, unit); + } + + /** + * 若不存在key时, 向redis中添加key-value, 返回成功/失败。 + * 若存在,则不作任何操作, 返回false。 + * + * @param key key + * @param value key对应的value + * @return set是否成功 + */ + public static boolean setIfAbsent(String key, String value) { + log.info("setIfAbsent(...) => key -> {}, value -> {}", key, value); + Boolean result = redisTemplate.opsForValue().setIfAbsent(key, value); + log.info("setIfAbsent(...) => result -> {}", result); + if (result == null) { + throw new RedisOpsResultIsNullException(); + } + return result; + } + + /** + * 若不存在key时, 向redis中添加一个(具有超时时长的)key-value, 返回成功/失败。 + * 若存在,则不作任何操作, 返回false。 + * + * @param key key + * @param value key对应的value + * @param timeout 超时时长 + * @param unit timeout的单位 + * @return set是否成功 + */ + public static boolean setIfAbsent(String key, String value, long timeout, TimeUnit unit) { + log.info("setIfAbsent(...) => key -> {}, value -> {}, key -> {}, value -> {}", key, value, timeout, unit); + Boolean result = redisTemplate.opsForValue().setIfAbsent(key, value, timeout, unit); + log.info("setIfAbsent(...) => result -> {}", result); + if (result == null) { + throw new RedisOpsResultIsNullException(); + } + return result; + } + + /** + * 从(redis中key对应的)value的offset位置起(包含该位置),用replaceValue替换对应长度的值。 + *

+ * 举例说明: + * 1.假设redis中存在key-value ("ds", "0123456789"); 调 + * 用setRange("ds", "abcdefghijk", 3)后, redis中该value值就变为了[012abcdefghijk] + *

+ * 2.假设redis中存在key-value ("jd", "0123456789");调 + * 用setRange("jd", "xyz", 3)后, redis中该value值就变为了[012xyz6789] + *

+ * 3.假设redis中存在key-value ("ey", "0123456789");调 + * 用setRange("ey", "qwer", 15)后, redis中该value值就变为了[0123456789 qwer] + * 注:case3比较特殊,offset超过了原value的长度了, 中间就会有一些空格来填充,但是如果在程序 + * 中直接输出的话,中间那部分空格可能会出现乱码。 + * + * @param key 定位key-value的key + * @param replaceValue 要替换的值 + * @param offset 起始位置 + */ + public static void setRange(String key, String replaceValue, long offset) { + log.info("setRange(...) => key -> {}, replaceValue -> {}, offset -> {}", key, replaceValue, offset); + redisTemplate.opsForValue().set(key, replaceValue, offset); + } + + /** + * 获取到key对应的value的长度。 + *

+ * 注: 长度等于{@link String#length}。 + * 注: 若redis中不存在对应的key-value, 则返回值为0. + * + * @param key 定位value的key + * @return value的长度 + */ + public static long size(String key) { + log.info("size(...) => key -> {}", key); + Long result = redisTemplate.opsForValue().size(key); + log.info("size(...) => result -> {}", result); + if (result == null) { + throw new RedisOpsResultIsNullException(); + } + return result; + } + + /** + * 批量设置 key-value + *

+ * 注: 若存在相同的key, 则原来的key-value会被丢弃。 + * + * @param maps key-value 集 + */ + public static void multiSet(Map maps) { + log.info("multiSet(...) => maps -> {}", maps); + redisTemplate.opsForValue().multiSet(maps); + } + + /** + * 当redis中,不存在任何一个keys时, 才批量设置 key-value, 并返回成功/失败. + * 否者,不进行任何操作, 并返回false。 + *

+ * 即: 假设调用此方法时传入的参数map是这样的: {k1=v1, k2=v2, k3=v3} + * 那么redis中, k1、k2、k3都不存在时,才会批量设置key-value; + * 否则不会设置任何key-value。 + *

+ * 注: 若存在相同的key, 则原来的key-value会被丢弃。 + *

+ * 注: + * + * @param maps key-value 集 + * @return 操作是否成功 + */ + public static boolean multiSetIfAbsent(Map maps) { + log.info("multiSetIfAbsent(...) => maps -> {}", maps); + Boolean result = redisTemplate.opsForValue().multiSetIfAbsent(maps); + log.info("multiSetIfAbsent(...) => result -> {}", result); + if (result == null) { + throw new RedisOpsResultIsNullException(); + } + return result; + } + + /** + * 增/减 整数 + *

+ * 注: 负数则为减。 + * 注: 若key对应的value值不支持增/减操作(即: value不是数字), 那么会 + * 抛出org.springframework.data.redis.RedisSystemException + * + * @param key 用于定位value的key + * @param increment 增加多少 + * @return 增加后的总值。 + * @throws RedisSystemException key对应的value值不支持增/减操作时 + */ + public static long incrBy(String key, long increment) { + log.info("incrBy(...) => key -> {}, increment -> {}", key, increment); + Long result = redisTemplate.opsForValue().increment(key, increment); + log.info("incrBy(...) => result -> {}", result); + if (result == null) { + throw new RedisOpsResultIsNullException(); + } + return result; + } + + /** + * 增/减 浮点数 + *

+ * 注: 慎用浮点数,会有精度问题。 + * 如: 先 RedisUtil.StringOps.set("ds", "123"); + * 然后再RedisUtil.StringOps.incrByFloat("ds", 100.6); + * 就会看到精度问题。 + * 注: 负数则为减。 + * 注: 若key对应的value值不支持增/减操作(即: value不是数字), 那么会 + * 抛出org.springframework.data.redis.RedisSystemException + * + * @param key 用于定位value的key + * @param increment 增加多少 + * @return 增加后的总值。 + * @throws RedisSystemException key对应的value值不支持增/减操作时 + */ + public static double incrByFloat(String key, double increment) { + log.info("incrByFloat(...) => key -> {}, increment -> {}", key, increment); + Double result = redisTemplate.opsForValue().increment(key, increment); + log.info("incrByFloat(...) => result -> {}", result); + if (result == null) { + throw new RedisOpsResultIsNullException(); + } + return result; + } + + /** + * 追加值到末尾 + *

+ * 注: 当redis中原本不存在key时,那么(从效果上来看)此方法就等价于{@link this#set(String, String)} + * + * @param key 定位value的key + * @param value 要追加的value值 + * @return 追加后, 整个value的长度 + */ + public static int append(String key, String value) { + log.info("append(...) => key -> {}, value -> {}", key, value); + Integer result = redisTemplate.opsForValue().append(key, value); + log.info("append(...) => result -> {}", result); + if (result == null) { + throw new RedisOpsResultIsNullException(); + } + return result; + } + + /** + * 根据key,获取到对应的value值 + * + * @param key key-value对应的key + * @return 该key对应的值。 + * 注: 若key不存在, 则返回null。 + */ + public static String get(String key) { + log.info("get(...) => key -> {}", key); + String result = redisTemplate.opsForValue().get(key); + log.info("get(...) => result -> {} ", result); + return result; + } + + /** + * 对(key对应的)value进行截取, 截取范围为[start, end] + *

+ * 注: 若[start, end]的范围不在value的范围中,那么返回的是空字符串 "" + * 注: 若value只有一部分在[start, end]的范围中,那么返回的是value对应部分的内容(即:不足的地方,并不会以空来填充) + * + * @param key 定位value的key + * @param start 起始位置 (从0开始) + * @param end 结尾位置 (从0开始) + * @return 截取后的字符串 + */ + public static String getRange(String key, long start, long end) { + log.info("getRange(...) => kry -> {}", key); + String result = redisTemplate.opsForValue().get(key, start, end); + log.info("getRange(...) => result -> {} ", result); + return result; + } + + /** + * 给指定key设置新的value, 并返回旧的value + *

+ * 注: 若redis中不存在key, 那么此操作仍然可以成功, 不过返回的旧值是null + * + * @param key 定位value的key + * @param newValue 要为该key设置的新的value值 + * @return 旧的value值 + */ + public static String getAndSet(String key, String newValue) { + log.info("getAndSet(...) => key -> {}, value -> {}", key, newValue); + String oldValue = redisTemplate.opsForValue().getAndSet(key, newValue); + log.info("getAndSet(...) => oldValue -> {}", oldValue); + return oldValue; + } + + /** + * 获取(key对应的)value在二进制下,offset位置的bit值。 + *

+ * 注: 当offset的值在(二进制下的value的)索引范围外时, 返回的也是false。 + *

+ * 示例: + * RedisUtil.StringOps.set("akey", "a"); + * 字符串a, 转换为二进制为01100001 + * 那么getBit("akey", 6)获取到的结果为false。 + * + * @param key 定位value的key + * @param offset 定位bit的索引 + * @return offset位置对应的bit的值(true - 1, false - 0) + */ + public static boolean getBit(String key, long offset) { + log.info("getBit(...) => key -> {}, offset -> {}", key, offset); + Boolean result = redisTemplate.opsForValue().getBit(key, offset); + log.info("getBit(...) => result -> {}", result); + if (result == null) { + throw new RedisOpsResultIsNullException(); + } + return result; + } + + /** + * 批量获取value值 + *

+ * 注: 若redis中,对应的key不存在,那么该key对应的返回的value值为null + * + * @param keys key集 + * @return value值集合 + */ + public static List multiGet(Collection keys) { + log.info("multiGet(...) => keys -> {}", keys); + List result = redisTemplate.opsForValue().multiGet(keys); + log.info("multiGet(...) => result -> {}", result); + return result; + } + } + + /** + * hash相关操作 + *

+ * 提示: 简单的,可以将redis中hash的数据结构看作是 Map> + * 提示: redis中String的数据结构可参考resources/data-structure/Hash(散列)的数据结构(示例一).png + * redis中String的数据结构可参考resources/data-structure/Hash(散列)的数据结构(示例二).png + * + * @author JustryDeng + */ + public static class HashOps { + + /** + * 向key对应的hash中,增加一个键值对entryKey-entryValue + *

+ * 注: 同一个hash里面,若已存在相同的entryKey, 那么此操作将丢弃原来的entryKey-entryValue, + * 而使用新的entryKey-entryValue。 + * + * @param key 定位hash的key + * @param entryKey 要向hash中增加的键值对里的 键 + * @param entryValue 要向hash中增加的键值对里的 值 + */ + public static void hPut(String key, String entryKey, String entryValue) { + log.info("hPut(...) => key -> {}, entryKey -> {}, entryValue -> {}", key, entryKey, entryValue); + redisTemplate.opsForHash().put(key, entryKey, entryValue); + } + + /** + * 向key对应的hash中,增加maps(即: 批量增加entry集) + *

+ * 注: 同一个hash里面,若已存在相同的entryKey, 那么此操作将丢弃原来的entryKey-entryValue, + * 而使用新的entryKey-entryValue + * + * @param key 定位hash的key + * @param maps 要向hash中增加的键值对集 + */ + public static void hPutAll(String key, Map maps) { + log.info("hPutAll(...) => key -> {}, maps -> {}", key, maps); + redisTemplate.opsForHash().putAll(key, maps); + } + + /** + * 当key对应的hash中,不存在entryKey时,才(向key对应的hash中,)增加entryKey-entryValue + * 否者,不进行任何操作 + * + * @param key 定位hash的key + * @param entryKey 要向hash中增加的键值对里的 键 + * @param entryValue 要向hash中增加的键值对里的 值 + * @return 操作是否成功。 + */ + public static boolean hPutIfAbsent(String key, String entryKey, String entryValue) { + log.info("hPutIfAbsent(...) => key -> {}, entryKey -> {}, entryValue -> {}", + key, entryKey, entryValue); + Boolean result = redisTemplate.opsForHash().putIfAbsent(key, entryKey, entryValue); + log.info("hPutIfAbsent(...) => result -> {}", result); + if (result == null) { + throw new RedisOpsResultIsNullException(); + } + return result; + } + + /** + * 获取到key对应的hash里面的对应字段的值 + *

+ * 注: 若redis中不存在对应的key, 则返回null。 + * 若key对应的hash中不存在对应的entryKey, 也会返回null。 + * + * @param key 定位hash的key + * @param entryKey 定位hash里面的entryValue的entryKey + * @return key对应的hash里的entryKey对应的entryValue值 + */ + public static Object hGet(String key, String entryKey) { + log.info("hGet(...) => key -> {}, entryKey -> {}", key, entryKey); + Object entryValue = redisTemplate.opsForHash().get(key, entryKey); + log.info("hGet(...) => entryValue -> {}", entryValue); + return entryValue; + } + + /** + * 获取到key对应的hash(即: 获取到key对应的Map) + *

+ * 注: 若redis中不存在对应的key, 则返回一个没有任何entry的空的Map(,而不是返回null)。 + * + * @param key 定位hash的key + * @return key对应的hash。 + */ + public static Map hGetAll(String key) { + log.info("hGetAll(...) => key -> {}", key); + Map result = redisTemplate.opsForHash().entries(key); + log.info("hGetAll(...) => result -> {}", result); + return result; + } + + /** + * 批量获取(key对应的)hash中的entryKey的entryValue + *

+ * 注: 若hash中对应的entryKey不存在,那么返回的对应的entryValue值为null + * 注: redis中key不存在,那么返回的List中,每个元素都为null。 + * 追注: 这个List本身不为null, size也不为0, 只是每个list中的每个元素为null而已。 + * + * @param key 定位hash的key + * @param entryKeys 需要获取的hash中的字段集 + * @return hash中对应entryKeys的对应entryValue集 + */ + public static List hMultiGet(String key, Collection entryKeys) { + log.info("hMultiGet(...) => key -> {}, entryKeys -> {}", key, entryKeys); + List entryValues = redisTemplate.opsForHash().multiGet(key, entryKeys); + log.info("hMultiGet(...) => entryValues -> {}", entryValues); + return entryValues; + } + + /** + * (批量)删除(key对应的)hash中的对应entryKey-entryValue + *

+ * 注: 1、若redis中不存在对应的key, 则返回0; + * 2、若要删除的entryKey,在key对应的hash中不存在,在count不会+1, 如: + * RedisUtil.HashOps.hPut("ds", "name", "邓沙利文"); + * RedisUtil.HashOps.hPut("ds", "birthday", "1994-02-05"); + * RedisUtil.HashOps.hPut("ds", "hobby", "女"); + * 则调用RedisUtil.HashOps.hDelete("ds", "name", "birthday", "hobby", "non-exist-entryKey") + * 的返回结果为3 + * 注: 若(key对应的)hash中的所有entry都被删除了,那么该key也会被删除 + * + * @param key 定位hash的key + * @param entryKeys 定位要删除的entryKey-entryValue的entryKey + * @return 删除了对应hash中多少个entry + */ + public static long hDelete(String key, Object... entryKeys) { + log.info("hDelete(...) => key -> {}, entryKeys -> {}", key, entryKeys); + Long count = redisTemplate.opsForHash().delete(key, entryKeys); + log.info("hDelete(...) => count -> {}", count); + if (count == null) { + throw new RedisOpsResultIsNullException(); + } + return count; + } + + /** + * 查看(key对应的)hash中,是否存在entryKey对应的entry + *

+ * 注: 若redis中不存在key,则返回false。 + * 注: 若key对应的hash中不存在对应的entryKey, 也会返回false。 + * + * @param key 定位hash的key + * @param entryKey 定位hash中entry的entryKey + * @return hash中是否存在entryKey对应的entry. + */ + public static boolean hExists(String key, String entryKey) { + log.info("hDelete(...) => key -> {}, entryKeys -> {}", key, entryKey); + Boolean exist = redisTemplate.opsForHash().hasKey(key, entryKey); + log.info("hDelete(...) => exist -> {}", exist); + return exist; + } + + /** + * 增/减(hash中的某个entryValue值) 整数 + *

+ * 注: 负数则为减。 + * 注: 若key不存在,那么会自动创建对应的hash,并创建对应的entryKey、entryValue,entryValue的初始值为increment。 + * 注: 若entryKey不存在,那么会自动创建对应的entryValue,entryValue的初始值为increment。 + * 注: 若key对应的value值不支持增/减操作(即: value不是数字), 那么会 + * 抛出org.springframework.data.redis.RedisSystemException + * + * @param key 用于定位hash的key + * @param entryKey 用于定位entryValue的entryKey + * @param increment 增加多少 + * @return 增加后的总值。 + * @throws RedisSystemException key对应的value值不支持增/减操作时 + */ + public static long hIncrBy(String key, Object entryKey, long increment) { + log.info("hIncrBy(...) => key -> {}, entryKey -> {}, increment -> {}", + key, entryKey, increment); + Long result = redisTemplate.opsForHash().increment(key, entryKey, increment); + log.info("hIncrBy(...) => result -> {}", result); + if (result == null) { + throw new RedisOpsResultIsNullException(); + } + return result; + } + + /** + * 增/减(hash中的某个entryValue值) 浮点数 + *

+ * 注: 负数则为减。 + * 注: 若key不存在,那么会自动创建对应的hash,并创建对应的entryKey、entryValue,entryValue的初始值为increment。 + * 注: 若entryKey不存在,那么会自动创建对应的entryValue,entryValue的初始值为increment。 + * 注: 若key对应的value值不支持增/减操作(即: value不是数字), 那么会 + * 抛出org.springframework.data.redis.RedisSystemException + * 注: 因为是浮点数, 所以可能会和{@link StringOps#incrByFloat(String, double)}一样, 出现精度问题。 + * 追注: 本人简单测试了几组数据,暂未出现精度问题。 + * + * @param key 用于定位hash的key + * @param entryKey 用于定位entryValue的entryKey + * @param increment 增加多少 + * @return 增加后的总值。 + * @throws RedisSystemException key对应的value值不支持增/减操作时 + */ + public static double hIncrByFloat(String key, Object entryKey, double increment) { + log.info("hIncrByFloat(...) => key -> {}, entryKey -> {}, increment -> {}", + key, entryKey, increment); + Double result = redisTemplate.opsForHash().increment(key, entryKey, increment); + log.info("hIncrByFloat(...) => result -> {}", result); + if (result == null) { + throw new RedisOpsResultIsNullException(); + } + return result; + } + + /** + * 获取(key对应的)hash中的所有entryKey + *

+ * 注: 若key不存在,则返回的是一个空的Set(,而不是返回null) + * + * @param key 定位hash的key + * @return hash中的所有entryKey + */ + public static Set hKeys(String key) { + log.info("hKeys(...) => key -> {}", key); + Set entryKeys = redisTemplate.opsForHash().keys(key); + log.info("hKeys(...) => entryKeys -> {}", entryKeys); + return entryKeys; + } + + /** + * 获取(key对应的)hash中的所有entryValue + *

+ * 注: 若key不存在,则返回的是一个空的List(,而不是返回null) + * + * @param key 定位hash的key + * @return hash中的所有entryValue + */ + public static List hValues(String key) { + log.info("hValues(...) => key -> {}", key); + List entryValues = redisTemplate.opsForHash().values(key); + log.info("hValues(...) => entryValues -> {}", entryValues); + return entryValues; + } + + /** + * 获取(key对应的)hash中的所有entry的数量 + *

+ * 注: 若redis中不存在对应的key, 则返回值为0 + * + * @param key 定位hash的key + * @return (key对应的)hash中, entry的个数 + */ + public static long hSize(String key) { + log.info("hSize(...) => key -> {}", key); + Long count = redisTemplate.opsForHash().size(key); + log.info("hSize(...) => count -> {}", count); + if (count == null) { + throw new RedisOpsResultIsNullException(); + } + return count; + } + + /** + * 根据options匹配到(key对应的)hash中的对应的entryKey, 并返回对应的entry集 + *

+ *

+ * 注: ScanOptions实例的创建方式举例: + * 1、ScanOptions.NONE + * 2、ScanOptions.scanOptions().match("n??e").build() + * + * @param key 定位hash的key + * @param options 匹配entryKey的条件 + * 注: ScanOptions.NONE表示全部匹配。 + * 注: ScanOptions.scanOptions().match(pattern).build()表示按照pattern匹配, + * 其中pattern中可以使用通配符 * ? 等, + * * 表示>=0个字符 + * ? 表示有且只有一个字符 + * 此处的匹配规则与{@link KeyOps#keys(String)}处的一样。 + * @return 匹配到的(key对应的)hash中的entry + */ + public static Cursor> hScan(String key, ScanOptions options) { + log.info("hScan(...) => key -> {}, options -> {}", key, JSONUtil.toJsonStr(options)); + Cursor> cursor = redisTemplate.opsForHash().scan(key, options); + log.info("hScan(...) => cursor -> {}", JSONUtil.toJsonStr(cursor)); + return cursor; + } + } + + /** + * list相关操作 + *

+ * 提示: 列表中的元素,可以重复。 + *

+ * 提示: list是有序的。 + *

+ * 提示: redis中的list中的索引,可分为两类,这两类都可以用来定位list中元素: + * 类别一: 从left到right, 是从0开始依次增大: 0, 1, 2, 3... + * 类别二: 从right到left, 是从-1开始依次减小: -1, -2, -3, -4... + *

+ * 提示: redis中String的数据结构可参考resources/data-structure/List(列表)的数据结构(示例一).png + * redis中String的数据结构可参考resources/data-structure/List(列表)的数据结构(示例二).png + * + * @author JustryDeng + */ + public static class ListOps { + + /** + * 从左端推入元素进列表 + *

+ * 注: 若redis中不存在对应的key, 那么会自动创建 + * + * @param key 定位list的key + * @param item 要推入list的元素 + * @return 推入后,(key对应的)list的size + */ + public static long lLeftPush(String key, String item) { + log.info("lLeftPush(...) => key -> {}, item -> {}", key, item); + Long size = redisTemplate.opsForList().leftPush(key, item); + log.info("lLeftPush(...) => size -> {}", size); + if (size == null) { + throw new RedisOpsResultIsNullException(); + } + return size; + } + + /** + * 从左端批量推入元素进列表 + *

+ * 注: 若redis中不存在对应的key, 那么会自动创建 + * 注: 这一批item中,先push左侧的, 后push右侧的 + * + * @param key 定位list的key + * @param items 要批量推入list的元素集 + * @return 推入后,(key对应的)list的size + */ + public static long lLeftPushAll(String key, String... items) { + log.info("lLeftPushAll(...) => key -> {}, items -> {}", key, items); + Long size = redisTemplate.opsForList().leftPushAll(key, items); + log.info("lLeftPushAll(...) => size -> {}", size); + if (size == null) { + throw new RedisOpsResultIsNullException(); + } + return size; + } + + /** + * 从左端批量推入元素进列表 + *

+ * 注: 若redis中不存在对应的key, 那么会自动创建 + * 注: 这一批item中,那个item先从Collection取出来,就先push哪个 + * + * @param key 定位list的key + * @param items 要批量推入list的元素集 + * @return 推入后,(key对应的)list的size + */ + public static long lLeftPushAll(String key, Collection items) { + log.info("lLeftPushAll(...) => key -> {}, items -> {}", key, items); + Long size = redisTemplate.opsForList().leftPushAll(key, items); + log.info("lLeftPushAll(...) => size -> {}", size); + if (size == null) { + throw new RedisOpsResultIsNullException(); + } + return size; + } + + /** + * 如果redis中存在key, 则从左端批量推入元素进列表; + * 否则,不进行任何操作 + * + * @param key 定位list的key + * @param item 要推入list的项 + * @return 推入后,(key对应的)list的size + */ + public static long lLeftPushIfPresent(String key, String item) { + log.info("lLeftPushIfPresent(...) => key -> {}, item -> {}", key, item); + Long size = redisTemplate.opsForList().leftPushIfPresent(key, item); + log.info("lLeftPushIfPresent(...) => size -> {}", size); + if (size == null) { + throw new RedisOpsResultIsNullException(); + } + return size; + } + + /** + * 若key对应的list中存在pivot项, 那么将item放入第一个pivot项前(即:放在第一个pivot项左边); + * 若key对应的list中不存在pivot项, 那么不做任何操作, 直接返回-1。 + *

+ * 注: 若redis中不存在对应的key, 那么会自动创建 + * + * @param key 定位list的key + * @param item 要推入list的元素 + * @return 推入后,(key对应的)list的size + */ + public static long lLeftPush(String key, String pivot, String item) { + log.info("lLeftPush(...) => key -> {}, pivot -> {}, item -> {}", key, pivot, item); + Long size = redisTemplate.opsForList().leftPush(key, pivot, item); + log.info("lLeftPush(...) => size -> {}", size); + if (size == null) { + throw new RedisOpsResultIsNullException(); + } + return size; + } + + /** + * 与{@link ListOps#lLeftPush(String, String)}类比即可, 不过是从list右侧推入元素 + */ + public static long lRightPush(String key, String item) { + log.info("lRightPush(...) => key -> {}, item -> {}", key, item); + Long size = redisTemplate.opsForList().rightPush(key, item); + log.info("lRightPush(...) => size -> {}", size); + if (size == null) { + throw new RedisOpsResultIsNullException(); + } + return size; + } + + /** + * 与{@link ListOps#lLeftPushAll(String, String...)}类比即可, 不过是从list右侧推入元素 + */ + public static long lRightPushAll(String key, String... items) { + log.info("lRightPushAll(...) => key -> {}, items -> {}", key, items); + Long size = redisTemplate.opsForList().rightPushAll(key, items); + log.info("lRightPushAll(...) => size -> {}", size); + if (size == null) { + throw new RedisOpsResultIsNullException(); + } + return size; + } + + /** + * 与{@link ListOps#lLeftPushAll(String, Collection)}类比即可, 不过是从list右侧推入元素 + */ + public static long lRightPushAll(String key, Collection items) { + log.info("lRightPushAll(...) => key -> {}, items -> {}", key, items); + Long size = redisTemplate.opsForList().rightPushAll(key, items); + log.info("lRightPushAll(...) => size -> {}", size); + if (size == null) { + throw new RedisOpsResultIsNullException(); + } + return size; + } + + /** + * 与{@link ListOps#lLeftPushIfPresent(String, String)}类比即可, 不过是从list右侧推入元素 + */ + public static long lRightPushIfPresent(String key, String item) { + log.info("lRightPushIfPresent(...) => key -> {}, item -> {}", key, item); + Long size = redisTemplate.opsForList().rightPushIfPresent(key, item); + log.info("lRightPushIfPresent(...) => size -> {}", size); + if (size == null) { + throw new RedisOpsResultIsNullException(); + } + return size; + } + + /** + * 与{@link ListOps#lLeftPush(String, String, String)}类比即可, 不过是从list右侧推入元素 + */ + public static long lRightPush(String key, String pivot, String item) { + log.info("lLeftPush(...) => key -> {}, pivot -> {}, item -> {}", key, pivot, item); + Long size = redisTemplate.opsForList().rightPush(key, pivot, item); + log.info("lLeftPush(...) => size -> {}", size); + if (size == null) { + throw new RedisOpsResultIsNullException(); + } + return size; + } + + /** + * 【非阻塞队列】 从左侧移出(key对应的)list中的第一个元素, 并将该元素返回 + *

+ * 注: 此方法是非阻塞的, 即: 若(key对应的)list中的所有元素都被pop移出了,此时,再进行pop的话,会立即返回null + * 注: 此方法是非阻塞的, 即: 若redis中不存在对应的key,那么会立即返回null + * 注: 若将(key对应的)list中的所有元素都pop完了,那么该key会被删除 + * + * @param key 定位list的key + * @return 移出的那个元素 + */ + public static String lLeftPop(String key) { + log.info("lLeftPop(...) => key -> {}", key); + String item = redisTemplate.opsForList().leftPop(key); + log.info("lLeftPop(...) => item -> {}", item); + return item; + } + + /** + * 【阻塞队列】 从左侧移出(key对应的)list中的第一个元素, 并将该元素返回 + *

+ * 注: 此方法是阻塞的, 即: 若(key对应的)list中的所有元素都被pop移出了,此时,再进行pop的话, + * 会阻塞timeout这么久,然后返回null + * 注: 此方法是阻塞的, 即: 若redis中不存在对应的key,那么会阻塞timeout这么久,然后返回null + * 注: 若将(key对应的)list中的所有元素都pop完了,那么该key会被删除 + *

+ * 提示: 若阻塞过程中, 目标key-list出现了,且里面有item了,那么会立马停止阻塞, 进行元素移出并返回 + * + * @param key 定位list的key + * @param timeout 超时时间 + * @param unit timeout的单位 + * @return 移出的那个元素 + */ + public static String lLeftPop(String key, long timeout, TimeUnit unit) { + log.info("lLeftPop(...) => key -> {}, timeout -> {}, unit -> {}", key, timeout, unit); + String item = redisTemplate.opsForList().leftPop(key, timeout, unit); + log.info("lLeftPop(...) => item -> {}", item); + return item; + } + + /** + * 与{@link ListOps#lLeftPop(String)}类比即可, 不过是从list右侧移出元素 + */ + public static String lRightPop(String key) { + log.info("lRightPop(...) => key -> {}", key); + String item = redisTemplate.opsForList().rightPop(key); + log.info("lRightPop(...) => item -> {}", item); + return item; + } + + /** + * 与{@link ListOps#lLeftPop(String, long, TimeUnit)}类比即可, 不过是从list右侧移出元素 + */ + public static String lRightPop(String key, long timeout, TimeUnit unit) { + log.info("lRightPop(...) => key -> {}, timeout -> {}, unit -> {}", key, timeout, unit); + String item = redisTemplate.opsForList().rightPop(key, timeout, unit); + log.info("lRightPop(...) => item -> {}", item); + return item; + } + + /** + * 【非阻塞队列】 从sourceKey对应的sourceList右侧移出一个item, 并将这个item推 + * 入(destinationKey对应的)destinationList的左侧 + *

+ * 注: 若sourceKey对应的list中没有item了,则立马认为(从sourceKey对应的list中pop出来的)item为null, + * null并不会往destinationKey对应的list中push。 + * 追注: 此时,此方法的返回值是null。 + *

+ * 注: 若将(sourceKey对应的)list中的所有元素都pop完了,那么该sourceKey会被删除。 + * + * @param sourceKey 定位sourceList的key + * @param destinationKey 定位destinationList的key + * @return 移动的这个元素 + */ + public static String lRightPopAndLeftPush(String sourceKey, String destinationKey) { + log.info("lRightPopAndLeftPush(...) => sourceKey -> {}, destinationKey -> {}", + sourceKey, destinationKey); + String item = redisTemplate.opsForList().rightPopAndLeftPush(sourceKey, destinationKey); + log.info("lRightPopAndLeftPush(...) => item -> {}", item); + return item; + } + + /** + * 【阻塞队列】 从sourceKey对应的sourceList右侧移出一个item, 并将这个item推 + * 入(destinationKey对应的)destinationList的左侧 + *

+ * 注: 若sourceKey对应的list中没有item了,则阻塞等待, 直到能从sourceList中移出一个非null的item(或等待时长超时); + * case1: 等到了一个非null的item, 那么继续下面的push操作,并返回这个item。 + * case2: 超时了,还没等到非null的item, 那么pop出的结果就未null,此时并不会往destinationList进行push。 + * 此时,此方法的返回值是null。 + *

+ * 注: 若将(sourceKey对应的)list中的所有元素都pop完了,那么该sourceKey会被删除。 + * + * @param sourceKey 定位sourceList的key + * @param destinationKey 定位destinationList的key + * @param timeout 超时时间 + * @param unit timeout的单位 + * @return 移动的这个元素 + */ + public static String lRightPopAndLeftPush(String sourceKey, String destinationKey, long timeout, + TimeUnit unit) { + log.info("lRightPopAndLeftPush(...) => sourceKey -> {}, destinationKey -> {}, timeout -> {}," + + " unit -> {}", sourceKey, destinationKey, timeout, unit); + String item = redisTemplate.opsForList().rightPopAndLeftPush(sourceKey, destinationKey, timeout, unit); + log.info("lRightPopAndLeftPush(...) => item -> {}", item); + return item; + } + + /** + * 设置(key对应的)list中对应索引位置index处的元素为item + *

+ * 注: 若key不存在,则会抛出org.springframework.data.redis.RedisSystemException + * 注: 若索引越界,也会抛出org.springframework.data.redis.RedisSystemException + * + * @param key 定位list的key + * @param index 定位list中的元素的索引 + * @param item 要替换成的值 + */ + public static void lSet(String key, long index, String item) { + log.info("lSet(...) => key -> {}, index -> {}, item -> {}", key, index, item); + redisTemplate.opsForList().set(key, index, item); + } + + /** + * 通过索引index, 获取(key对应的)list中的元素 + *

+ * 注: 若key不存在 或 index超出(key对应的)list的索引范围,那么返回null + * + * @param key 定位list的key + * @param index 定位list中的item的索引 + * @return list中索引index对应的item + */ + public static String lIndex(String key, long index) { + log.info("lIndex(...) => key -> {}, index -> {}", key, index); + String item = redisTemplate.opsForList().index(key, index); + log.info("lIndex(...) => item -> {}", item); + return item; + } + + /** + * 获取(key对应的)list中索引在[start, end]之间的item集 + *

+ * 注: 含start、含end。 + * 注: 当key不存在时,获取到的是空的集合。 + * 注: 当获取的范围比list的范围还要大时,获取到的是这两个范围的交集。 + *

+ * 提示: 可通过RedisUtil.ListOps.lRange(key, 0, -1)来获取到该key对应的整个list + * + * @param key 定位list的key + * @param start 起始元素的index + * @param end 结尾元素的index + * @return 对应的元素集合 + */ + public static List lRange(String key, long start, long end) { + log.info("lRange(...) => key -> {}, start -> {}, end -> {}", key, start, end); + List result = redisTemplate.opsForList().range(key, start, end); + log.info("lRange(...) => result -> {}", result); + return result; + } + + /** + * 获取(key对应的)list + * + * @param key 定位list的key + * @return (key对应的)list + * @see ListOps#lRange(String, long, long) + */ + public static List lWholeList(String key) { + log.info("lWholeList(...) => key -> {}", key); + List result = redisTemplate.opsForList().range(key, 0, -1); + log.info("lWholeList(...) => result -> {}", result); + return result; + } + + /** + * 获取(key对应的)list的size + *

+ * 注: 当key不存在时,获取到的size为0. + * + * @param key 定位list的key + * @return list的size。 + */ + public static long lSize(String key) { + log.info("lSize(...) => key -> {}", key); + Long size = redisTemplate.opsForList().size(key); + log.info("lSize(...) => size -> {}", size); + if (size == null) { + throw new RedisOpsResultIsNullException(); + } + return size; + } + + /** + * 删除(key对应的)list中,前expectCount个值等于item的项 + *

+ * 注: 若expectCount == 0, 则表示删除list中所有的值等于item的项. + * 注: 若expectCount > 0, 则表示删除从左往右进行 + * 注: 若expectCount < 0, 则表示删除从右往左进行 + *

+ * 注: 若list中,值等于item的项的个数少于expectCount时,那么会删除list中所有的值等于item的项。 + * 注: 当key不存在时, 返回0。 + * 注: 若lRemove后, 将(key对应的)list中没有任何元素了,那么该key会被删除。 + * + * @param key 定位list的key + * @param expectCount 要删除的item的个数 + * @param item 要删除的item + * @return 实际删除了的item的个数 + */ + public static long lRemove(String key, long expectCount, String item) { + log.info("lRemove(...) => key -> {}, expectCount -> {}, item -> {}", key, expectCount, item); + Long actualCount = redisTemplate.opsForList().remove(key, expectCount, item); + log.info("lRemove(...) => actualCount -> {}", actualCount); + if (actualCount == null) { + throw new RedisOpsResultIsNullException(); + } + return actualCount; + } + + /** + * 裁剪(即: 对list中的元素取交集。) + *

+ * 举例说明: list中的元素索引范围是[0, 8], 而这个方法传入的[start, end]为 [3, 10], + * 那么裁剪就是对[0, 8]和[3, 10]进行取交集, 得到[3, 8], 那么裁剪后 + * 的list中,只剩下(原来裁剪前)索引在[3, 8]之间的元素了。 + *

+ * 注: 若裁剪后的(key对应的)list就是空的,那么该key会被删除。 + * + * @param key 定位list的key + * @param start 要删除的item集的起始项的索引 + * @param end 要删除的item集的结尾项的索引 + */ + public static void lTrim(String key, long start, long end) { + log.info("lTrim(...) => key -> {}, start -> {}, end -> {}", key, start, end); + redisTemplate.opsForList().trim(key, start, end); + } + + } + + /** + * set相关操作 + *

+ * 提示: set中的元素,不可以重复。 + * 提示: set是无序的。 + * 提示: redis中String的数据结构可参考resources/data-structure/Set(集合)的数据结构(示例一).png + * redis中String的数据结构可参考resources/data-structure/Set(集合)的数据结构(示例二).png + * + * @author JustryDeng + */ + public static class SetOps { + + /** + * 向(key对应的)set中添加items + *

+ * 注: 若key不存在,则会自动创建。 + * 注: set中的元素会去重。 + * + * @param key 定位set的key + * @param items 要向(key对应的)set中添加的items + * @return 此次添加操作, 添加到set中的元素的个数 + */ + public static long sAdd(String key, String... items) { + log.info("sAdd(...) => key -> {}, items -> {}", key, items); + Long count = redisTemplate.opsForSet().add(key, items); + log.info("sAdd(...) => count -> {}", count); + if (count == null) { + throw new RedisOpsResultIsNullException(); + } + return count; + } + + /** + * 从(key对应的)set中删除items + *

+ * 注: 若key不存在, 则返回0。 + * 注: 若已经将(key对应的)set中的项删除完了,那么对应的key也会被删除。 + * + * @param key 定位set的key + * @param items 要移除的items + * @return 实际删除了的个数 + */ + public static long sRemove(String key, Object... items) { + log.info("sRemove(...) => key -> {}, items -> {}", key, items); + Long count = redisTemplate.opsForSet().remove(key, items); + log.info("sRemove(...) => count -> {}", count); + if (count == null) { + throw new RedisOpsResultIsNullException(); + } + return count; + } + + /** + * 从(key对应的)set中随机移出一个item, 并返回这个item + *

+ * 注: 因为set是无序的,所以移出的这个item,是随机的; 并且,哪怕 + * 是数据一样的set,多次测试移出操作,移除的元素也是随机的。 + *

+ * 注: 若已经将(key对应的)set中的项pop完了,那么对应的key会被删除。 + * + * @param key 定位set的key + * @return 移出的项 + */ + public static String sPop(String key) { + log.info("sPop(...) => key -> {}", key); + String popItem = redisTemplate.opsForSet().pop(key); + log.info("sPop(...) => popItem -> {}", popItem); + return popItem; + } + + /** + * 将(sourceKey对应的)sourceSet中的元素item, 移动到(destinationKey对应的)destinationSet中 + *

+ * 注: 当sourceKey不存在时, 返回false + * 注: 当item不存在时, 返回false + * 注: 若destinationKey不存在, 那么在移动时会自动创建 + * 注: 若已经将(sourceKey对应的)set中的项move出去完了,那么对应的sourceKey会被删除。 + * + * @param sourceKey 定位sourceSet的key + * @param item 要移动的项目 + * @param destinationKey 定位destinationSet的key + * @return 移动成功与否 + */ + public static boolean sMove(String sourceKey, String item, String destinationKey) { + Boolean result = redisTemplate.opsForSet().move(sourceKey, item, destinationKey); + log.info("sMove(...) => sourceKey -> {}, destinationKey -> {}, item -> {}", + sourceKey, destinationKey, item); + log.info("sMove(...) => result -> {}", result); + if (result == null) { + throw new RedisOpsResultIsNullException(); + } + return result; + } + + /** + * 获取(key对应的)set中的元素个数 + *

+ * 注: 若key不存在,则返回0 + * + * @param key 定位set的key + * @return (key对应的)set中的元素个数 + */ + public static long sSize(String key) { + log.info("sSize(...) => key -> {}", key); + Long size = redisTemplate.opsForSet().size(key); + log.info("sSize(...) => size -> {}", size); + if (size == null) { + throw new RedisOpsResultIsNullException(); + } + return size; + } + + /** + * 判断(key对应的)set中是否含有item + *

+ * 注: 若key不存在,则返回false。 + * + * @param key 定位set的key + * @param item 被查找的项 + * @return (key对应的)set中是否含有item + */ + public static boolean sIsMember(String key, Object item) { + log.info("sSize(...) => key -> {}, size -> {}", key, item); + Boolean result = redisTemplate.opsForSet().isMember(key, item); + log.info("sSize(...) => result -> {}", result); + if (result == null) { + throw new RedisOpsResultIsNullException(); + } + return result; + } + + /** + * 获取两个(key对应的)Set的交集 + *

+ * 注: 若不存在任何交集,那么返回空的集合(, 而不是null) + * 注: 若其中一个key不存在(或两个key都不存在),那么返回空的集合(, 而不是null) + * + * @param key 定位其中一个set的键 + * @param otherKey 定位其中另一个set的键 + * @return item交集 + */ + public static Set sIntersect(String key, String otherKey) { + log.info("sIntersect(...) => key -> {}, otherKey -> {}", key, otherKey); + Set intersectResult = redisTemplate.opsForSet().intersect(key, otherKey); + log.info("sIntersect(...) => intersectResult -> {}", intersectResult); + return intersectResult; + } + + /** + * 获取多个(key对应的)Set的交集 + *

+ * 注: 若不存在任何交集,那么返回空的集合(, 而不是null) + * 注: 若>=1个key不存在,那么返回空的集合(, 而不是null) + * + * @param key 定位其中一个set的键 + * @param otherKeys 定位其它set的键集 + * @return item交集 + */ + public static Set sIntersect(String key, Collection otherKeys) { + log.info("sIntersect(...) => key -> {}, otherKeys -> {}", key, otherKeys); + Set intersectResult = redisTemplate.opsForSet().intersect(key, otherKeys); + log.info("sIntersect(...) => intersectResult -> {}", intersectResult); + return intersectResult; + } + + /** + * 获取两个(key对应的)Set的交集, 并将结果add到storeKey对应的Set中。 + *

+ * case1: 交集不为空, storeKey不存在, 则 会创建对应的storeKey,并将交集添加到(storeKey对应的)set中 + * case2: 交集不为空, storeKey已存在, 则 会清除原(storeKey对应的)set中所有的项,然后将交集添加到(storeKey对应的)set中 + * case3: 交集为空, 则不进行下面的操作, 直接返回0 + *

+ * 注: 求交集的部分,详见{@link SetOps#sIntersect(String, String)} + * + * @param key 定位其中一个set的键 + * @param otherKey 定位其中另一个set的键 + * @param storeKey 定位(要把交集添加到哪个)set的key + * @return add到(storeKey对应的)Set后, 该set对应的size + */ + public static long sIntersectAndStore(String key, String otherKey, String storeKey) { + log.info("sIntersectAndStore(...) => key -> {}, otherKey -> {}, storeKey -> {}", + key, otherKey, storeKey); + Long size = redisTemplate.opsForSet().intersectAndStore(key, otherKey, storeKey); + log.info("sIntersectAndStore(...) => size -> {}", size); + if (size == null) { + throw new RedisOpsResultIsNullException(); + } + return size; + } + + /** + * 获取多个(key对应的)Set的交集, 并将结果add到storeKey对应的Set中。 + *

+ * case1: 交集不为空, storeKey不存在, 则 会创建对应的storeKey,并将交集添加到(storeKey对应的)set中 + * case2: 交集不为空, storeKey已存在, 则 会清除原(storeKey对应的)set中所有的项,然后将交集添加到(storeKey对应的)set中 + * case3: 交集为空, 则不进行下面的操作, 直接返回0 + *

+ * 注: 求交集的部分,详见{@link SetOps#sIntersect(String, Collection)} + */ + public static long sIntersectAndStore(String key, Collection otherKeys, String storeKey) { + log.info("sIntersectAndStore(...) => key -> {}, otherKeys -> {}, storeKey -> {}", key, otherKeys, storeKey); + Long size = redisTemplate.opsForSet().intersectAndStore(key, otherKeys, storeKey); + log.info("sIntersectAndStore(...) => size -> {}", size); + if (size == null) { + throw new RedisOpsResultIsNullException(); + } + return size; + } + + /** + * 获取两个(key对应的)Set的并集 + *

+ * 注: 并集中的元素也是唯一的,这是Set保证的。 + * + * @param key 定位其中一个set的键 + * @param otherKey 定位其中另一个set的键 + * @return item并集 + */ + public static Set sUnion(String key, String otherKey) { + log.info("sUnion(...) => key -> {}, otherKey -> {}", key, otherKey); + Set unionResult = redisTemplate.opsForSet().union(key, otherKey); + log.info("sUnion(...) => unionResult -> {}", unionResult); + return unionResult; + } + + /** + * 获取两个(key对应的)Set的并集 + *

+ * 注: 并集中的元素也是唯一的,这是Set保证的。 + * + * @param key 定位其中一个set的键 + * @param otherKeys 定位其它set的键集 + * @return item并集 + */ + public static Set sUnion(String key, Collection otherKeys) { + log.info("sUnion(...) => key -> {}, otherKeys -> {}", key, otherKeys); + Set unionResult = redisTemplate.opsForSet().union(key, otherKeys); + log.info("sUnion(...) => unionResult -> {}", unionResult); + return unionResult; + } + + /** + * 获取两个(key对应的)Set的并集, 并将结果add到storeKey对应的Set中。 + *

+ * case1: 并集不为空, storeKey不存在, 则 会创建对应的storeKey,并将并集添加到(storeKey对应的)set中 + * case2: 并集不为空, storeKey已存在, 则 会清除原(storeKey对应的)set中所有的项,然后将并集添加到(storeKey对应的)set中 + * case3: 并集为空, 则不进行下面的操作, 直接返回0 + *

+ * 注: 求并集的部分,详见{@link SetOps#sUnion(String, String)} + * + * @param key 定位其中一个set的键 + * @param otherKey 定位其中另一个set的键 + * @param storeKey 定位(要把并集添加到哪个)set的key + * @return add到(storeKey对应的)Set后, 该set对应的size + */ + public static long sUnionAndStore(String key, String otherKey, String storeKey) { + log.info("sUnionAndStore(...) => key -> {}, otherKey -> {}, storeKey -> {}", + key, otherKey, storeKey); + Long size = redisTemplate.opsForSet().unionAndStore(key, otherKey, storeKey); + log.info("sUnionAndStore(...) => size -> {}", size); + if (size == null) { + throw new RedisOpsResultIsNullException(); + } + return size; + } + + /** + * 获取两个(key对应的)Set的并集, 并将结果add到storeKey对应的Set中。 + *

+ * case1: 并集不为空, storeKey不存在, 则 会创建对应的storeKey,并将并集添加到(storeKey对应的)set中 + * case2: 并集不为空, storeKey已存在, 则 会清除原(storeKey对应的)set中所有的项,然后将并集添加到(storeKey对应的)set中 + * case3: 并集为空, 则不进行下面的操作, 直接返回0 + *

+ * 注: 求并集的部分,详见{@link SetOps#sUnion(String, Collection)} + * + * @param key 定位其中一个set的键 + * @param otherKeys 定位其它set的键集 + * @param storeKey 定位(要把并集添加到哪个)set的key + * @return add到(storeKey对应的)Set后, 该set对应的size + */ + public static long sUnionAndStore(String key, Collection otherKeys, String storeKey) { + log.info("sUnionAndStore(...) => key -> {}, otherKeys -> {}, storeKey -> {}", + key, otherKeys, storeKey); + Long size = redisTemplate.opsForSet().unionAndStore(key, otherKeys, storeKey); + log.info("sUnionAndStore(...) => size -> {}", size); + if (size == null) { + throw new RedisOpsResultIsNullException(); + } + return size; + } + + /** + * 获取 (key对应的)Set 减去 (otherKey对应的)Set 的差集 + *

+ * 注: 如果被减数key不存在, 那么结果为空的集合(,而不是null) + * 注: 如果被减数key存在,但减数key不存在, 那么结果即为(被减数key对应的)Set + * + * @param key 定位"被减数set"的键 + * @param otherKey 定位"减数set"的键 + * @return item差集 + */ + public static Set sDifference(String key, String otherKey) { + log.info("sDifference(...) => key -> {}, otherKey -> {}", + key, otherKey); + Set differenceResult = redisTemplate.opsForSet().difference(key, otherKey); + log.info("sDifference(...) => differenceResult -> {}", differenceResult); + return differenceResult; + } + + /** + * 获取 (key对应的)Set 减去 (otherKeys对应的)Sets 的差集 + *

+ * 注: 如果被减数key不存在, 那么结果为空的集合(,而不是null) + * 注: 如果被减数key存在,但减数key不存在, 那么结果即为(被减数key对应的)Set + *

+ * 提示: 当有多个减数时, 被减数先减去哪一个减数,后减去哪一个减数,是无所谓的,是不影响最终结果的。 + * + * @param key 定位"被减数set"的键 + * @param otherKeys 定位"减数集sets"的键集 + * @return item差集 + */ + public static Set sDifference(String key, Collection otherKeys) { + log.info("sDifference(...) => key -> {}, otherKeys -> {}", key, otherKeys); + Set differenceResult = redisTemplate.opsForSet().difference(key, otherKeys); + log.info("sDifference(...) => differenceResult -> {}", differenceResult); + return differenceResult; + } + + /** + * 获取 (key对应的)Set 减去 (otherKey对应的)Set 的差集, 并将结果add到storeKey对应的Set中。 + *

+ * case1: 差集不为空, storeKey不存在, 则 会创建对应的storeKey,并将差集添加到(storeKey对应的)set中 + * case2: 差集不为空, storeKey已存在, 则 会清除原(storeKey对应的)set中所有的项,然后将差集添加到(storeKey对应的)set中 + * case3: 差集为空, 则不进行下面的操作, 直接返回0 + *

+ * 注: 求并集的部分,详见{@link SetOps#sDifference(String, String)} + * + * @param key 定位"被减数set"的键 + * @param otherKey 定位"减数set"的键 + * @param storeKey 定位(要把差集添加到哪个)set的key + * @return add到(storeKey对应的)Set后, 该set对应的size + */ + public static long sDifferenceAndStore(String key, String otherKey, String storeKey) { + log.info("sDifferenceAndStore(...) => key -> {}, otherKey -> {}, storeKey -> {}", + key, otherKey, storeKey); + Long size = redisTemplate.opsForSet().differenceAndStore(key, otherKey, storeKey); + log.info("sDifferenceAndStore(...) => size -> {}", size); + if (size == null) { + throw new RedisOpsResultIsNullException(); + } + return size; + } + + /** + * 获取 (key对应的)Set 减去 (otherKey对应的)Set 的差集, 并将结果add到storeKey对应的Set中。 + *

+ * case1: 差集不为空, storeKey不存在, 则 会创建对应的storeKey,并将差集添加到(storeKey对应的)set中 + * case2: 差集不为空, storeKey已存在, 则 会清除原(storeKey对应的)set中所有的项,然后将差集添加到(storeKey对应的)set中 + * case3: 差集为空, 则不进行下面的操作, 直接返回0 + *

+ * 注: 求并集的部分,详见{@link SetOps#sDifference(String, String)} + * + * @param key 定位"被减数set"的键 + * @param otherKeys 定位"减数集sets"的键集 + * @param storeKey 定位(要把差集添加到哪个)set的key + * @return add到(storeKey对应的)Set后, 该set对应的size + */ + public static long sDifferenceAndStore(String key, Collection otherKeys, String storeKey) { + log.info("sDifferenceAndStore(...) => key -> {}, otherKeys -> {}, storeKey -> {}", + key, otherKeys, storeKey); + Long size = redisTemplate.opsForSet().differenceAndStore(key, otherKeys, storeKey); + log.info("sDifferenceAndStore(...) => size -> {}", size); + if (size == null) { + throw new RedisOpsResultIsNullException(); + } + return size; + } + + /** + * 获取key对应的set + *

+ * 注: 若key不存在, 则返回的是空的set(, 而不是null) + * + * @param key 定位set的key + * @return (key对应的)set + */ + public static Set sMembers(String key) { + log.info("sMembers(...) => key -> {}", key); + Set members = redisTemplate.opsForSet().members(key); + log.info("sMembers(...) => members -> {}", members); + return members; + } + + /** + * 从key对应的set中随机获取一项 + * + * @param key 定位set的key + * @return 随机获取到的项 + */ + public static String sRandomMember(String key) { + log.info("sRandomMember(...) => key -> {}", key); + String randomItem = redisTemplate.opsForSet().randomMember(key); + log.info("sRandomMember(...) => randomItem -> {}", randomItem); + return randomItem; + } + + /** + * 从key对应的set中获取count次随机项(, set中的同一个项可能被多次获取) + *

+ * 注: count可大于set的size。 + * 注: 取出来的结果里可能存在相同的值。 + * + * @param key 定位set的key + * @param count 要取多少项 + * @return 随机获取到的项集 + */ + public static List sRandomMembers(String key, long count) { + log.info("sRandomMembers(...) => key -> {}, count -> {}", key, count); + List randomItems = redisTemplate.opsForSet().randomMembers(key, count); + log.info("sRandomMembers(...) => randomItems -> {}", randomItems); + return randomItems; + } + + /** + * 从key对应的set中随机获取count个项 + *

+ * 注: 若count >= set的size, 那么返回的即为这个key对应的set。 + * 注: 取出来的结果里没有重复的项。 + * + * @param key 定位set的key + * @param count 要取多少项 + * @return 随机获取到的项集 + */ + public static Set sDistinctRandomMembers(String key, long count) { + log.info("sDistinctRandomMembers(...) => key -> {}, count -> {}", key, count); + Set distinctRandomItems = redisTemplate.opsForSet().distinctRandomMembers(key, count); + log.info("sDistinctRandomMembers(...) => distinctRandomItems -> {}", distinctRandomItems); + return distinctRandomItems; + } + + /** + * 根据options匹配到(key对应的)set中的对应的item, 并返回对应的item集 + *

+ *

+ * 注: ScanOptions实例的创建方式举例: + * 1、ScanOptions.NONE + * 2、ScanOptions.scanOptions().match("n??e").build() + * + * @param key 定位set的key + * @param options 匹配set中的item的条件 + * 注: ScanOptions.NONE表示全部匹配。 + * 注: ScanOptions.scanOptions().match(pattern).build()表示按照pattern匹配, + * 其中pattern中可以使用通配符 * ? 等, + * * 表示>=0个字符 + * ? 表示有且只有一个字符 + * 此处的匹配规则与{@link KeyOps#keys(String)}处的一样。 + * @return 匹配到的(key对应的)set中的项 + */ + public static Cursor sScan(String key, ScanOptions options) { + log.info("sScan(...) => key -> {}, options -> {}", key, JSONUtil.toJsonStr(options)); + Cursor cursor = redisTemplate.opsForSet().scan(key, options); + log.info("sScan(...) => cursor -> {}", JSONUtil.toJsonStr(cursor)); + return cursor; + } + } + + /** + * ZSet相关操作 + *

+ * 特别说明: ZSet是有序的, + * 不仅体现在: redis中的存储上有序。 + * 还体现在: 此工具类ZSetOps中返回值类型为Set的方法, 实际返回类型是LinkedHashSet + *

+ * 提示: redis中的ZSet, 一定程度等于redis中的Set + redis中的Hash的结合体。 + * 提示: redis中String的数据结构可参考resources/data-structure/ZSet(有序集合)的数据结构(示例一).png + * redis中String的数据结构可参考resources/data-structure/ZSet(有序集合)的数据结构(示例二).png + * 提示: ZSet中的entryKey即为成员项, entryValue即为这个成员项的分值, ZSet根据成员的分值,来堆成员进行排序。 + * + * @author JustryDeng + */ + public static class ZSetOps { + + /** + * 向(key对应的)zset中添加(item, score) + *

+ * 注: item为entryKey成员项, score为entryValue分数值。 + *

+ * 注: 若(key对应的)zset中已存在(与此次要添加的项)相同的item项,那么此次添加操作会失败,返回false; + * 但是!!! zset中原item的score会被更新为此次add的相同item项的score。 + * 所以, 也可以通过zAdd达到更新item对应score的目的。 + *

+ * 注: score可为正、可为负、可为0; 总之, double范围内都可以。 + *

+ * 注: 若score的值一样,则按照item排序。 + * + * @param key 定位set的key + * @param item 要往(key对应的)zset中添加的成员项 + * @param score item的分值 + * @return 是否添加成功 + */ + public static boolean zAdd(String key, String item, double score) { + log.info("zAdd(...) => key -> {}, item -> {}, score -> {}", key, item, score); + Boolean result = redisTemplate.opsForZSet().add(key, item, score); + log.info("zAdd(...) => result -> {}", result); + if (result == null) { + throw new RedisOpsResultIsNullException(); + } + return result; + } + + /** + * 批量添加entry + *

+ * 注: 若entry集中存在item相同的项(, score不一样),那么redis在执行真正的批量add操作前,会 + * 将其中一个item过滤掉。 + * 注: 同样的,若(key对应的)zset中已存在(与此次要添加的项)相同的item项,那么此次批量添加操作中, + * 对该item项的添加会失败,会失败,成功计数器不会加1;但是!!! zset中原item的score会被更新为此 + * 次add的相同item项的score。所以, 也可以通过zAdd达到更新item对应score的目的。 + * + * @param key 定位set的key + * @param entries 要添加的entry集 + * @return 本次添加进(key对应的)zset中的entry的个数 + */ + public static long zAdd(String key, Set> entries) { + log.info("zAdd(...) => key -> {}, entries -> {}", key, JSONUtil.toJsonStr(entries)); + Long count = redisTemplate.opsForZSet().add(key, entries); + log.info("zAdd(...) => count -> {}", count); + if (count == null) { + throw new RedisOpsResultIsNullException(); + } + return count; + } + + /** + * 从(key对应的)zset中移除项 + *

+ * 注:若key不存在,则返回0 + * + * @param key 定位set的key + * @param items 要移除的项集 + * @return 实际移除了的项的个数 + */ + public static long zRemove(String key, Object... items) { + log.info("zRemove(...) => key -> {}, items -> {}", key, items); + Long count = redisTemplate.opsForZSet().remove(key, items); + log.info("zRemove(...) => count -> {}", count); + if (count == null) { + throw new RedisOpsResultIsNullException(); + } + return count; + } + + /** + * 移除(key对应的)zset中, 排名范围在[startIndex, endIndex]内的item + *

+ * 注:默认的,按score.item升序排名, 排名从0开始 + *

+ * 注: 类似于List中的索引, 排名可以分为多个方式: + * 从前到后(正向)的排名: 0、1、2... + * 从后到前(反向)的排名: -1、-2、-3... + *

+ * 注: 不论是使用正向排名,还是使用反向排名, 使用此方法时, 应保证 startRange代表的元素的位置 + * 在endRange代表的元素的位置的前面, 如: + * 示例一: RedisUtil.ZSetOps.zRemoveRange("name", 0, 2); + * 示例二: RedisUtil.ZSetOps.zRemoveRange("site", -2, -1); + * 示例三: RedisUtil.ZSetOps.zRemoveRange("foo", 0, -1); + *

+ * 注:若key不存在,则返回0 + * + * @param key 定位set的key + * @param startRange 开始项的排名 + * @param endRange 结尾项的排名 + * @return 实际移除了的项的个数 + */ + public static long zRemoveRange(String key, long startRange, long endRange) { + log.info("zRemoveRange(...) => key -> {}, startRange -> {}, endRange -> {}", + key, startRange, endRange); + Long count = redisTemplate.opsForZSet().removeRange(key, startRange, endRange); + log.info("zRemoveRange(...) => count -> {}", count); + if (count == null) { + throw new RedisOpsResultIsNullException(); + } + return count; + } + + /** + * 移除(key对应的)zset中, score范围在[minScore, maxScore]内的item + *

+ * 提示: 虽然删除范围包含两侧的端点(即:包含minScore和maxScore), 但是由于double存在精度问题,所以建议: + * 设置值时,minScore应该设置得比要删除的项里,最小的score还小一点 + * maxScore应该设置得比要删除的项里,最大的score还大一点 + * 追注: 本人简单测试了几组数据,暂未出现精度问题。 + *

+ * 注:若key不存在,则返回0 + * + * @param key 定位set的key + * @param minScore score下限(含这个值) + * @param maxScore score上限(含这个值) + * @return 实际移除了的项的个数 + */ + public static long zRemoveRangeByScore(String key, double minScore, double maxScore) { + log.info("zRemoveRangeByScore(...) => key -> {}, startIndex -> {}, startIndex -> {}", + key, minScore, maxScore); + Long count = redisTemplate.opsForZSet().removeRangeByScore(key, minScore, maxScore); + log.info("zRemoveRangeByScore(...) => count -> {}", count); + if (count == null) { + throw new RedisOpsResultIsNullException(); + } + return count; + } + + /** + * 增/减 (key对应的zset中,)item的分数值 + * + * @param key 定位zset的key + * @param item 项 + * @param delta 变化量(正 - 增, 负 - 减) + * @return 修改后的score值 + */ + public static double zIncrementScore(String key, String item, double delta) { + log.info("zIncrementScore(...) => key -> {}, item -> {}, delta -> {}", key, item, delta); + Double scoreValue = redisTemplate.opsForZSet().incrementScore(key, item, delta); + log.info("zIncrementScore(...) => scoreValue -> {}", scoreValue); + if (scoreValue == null) { + throw new RedisOpsResultIsNullException(); + } + return scoreValue; + } + + /** + * 返回item在(key对应的)zset中的(按score从小到大的)排名 + *

+ * 注: 排名从0开始。 即意味着,此方法等价于: 返回item在(key对应的)zset中的位置索引。 + * 注: 若key或item不存在, 返回null。 + * 注: 排序规则是score,item, 即:优先以score排序,若score相同,则再按item排序。 + * + * @param key 定位zset的key + * @param item 项 + * @return 排名(等价于 : 索引) + */ + public static long zRank(String key, Object item) { + log.info("zRank(...) => key -> {}, item -> {}", key, item); + Long rank = redisTemplate.opsForZSet().rank(key, item); + log.info("zRank(...) => rank -> {}", rank); + if (rank == null) { + throw new RedisOpsResultIsNullException(); + } + return rank; + } + + /** + * 返回item在(key对应的)zset中的(按score从大到小的)排名 + *

+ * 注: 排名从0开始。补充: 因为是按score从大到小排序的, 所以最大score对应的item的排名为0。 + * 注: 若key或item不存在, 返回null。 + * 注: 排序规则是score,item, 即:优先以score排序,若score相同,则再按item排序。 + * + * @param key 定位zset的key + * @param item 项 + * @return 排名(等价于 : 索引) + */ + public static long zReverseRank(String key, Object item) { + log.info("zReverseRank(...) => key -> {}, item -> {}", key, item); + Long reverseRank = redisTemplate.opsForZSet().reverseRank(key, item); + log.info("zReverseRank(...) => reverseRank -> {}", reverseRank); + if (reverseRank == null) { + throw new RedisOpsResultIsNullException(); + } + return reverseRank; + } + + /** + * 根据索引位置, 获取(key对应的)zset中排名处于[start, end]中的item项集 + *

+ * 注: 不论是使用正向排名,还是使用反向排名, 使用此方法时, 应保证 startIndex代表的元素的 + * 位置在endIndex代表的元素的位置的前面, 如: + * 示例一: RedisUtil.ZSetOps.zRange("name", 0, 2); + * 示例二: RedisUtil.ZSetOps.zRange("site", -2, -1); + * 示例三: RedisUtil.ZSetOps.zRange("foo", 0, -1); + *

+ * 注: 若key不存在, 则返回空的集合。 + *

+ * 注: 当[start, end]的范围比实际zset的范围大时, 返回范围上"交集"对应的项集合。 + * + * @param key 定位zset的key + * @param start 排名开始位置 + * @param end 排名结束位置 + * @return 对应的item项集 + */ + public static Set zRange(String key, long start, long end) { + log.info("zRange(...) => key -> {}, start -> {}, end -> {}", key, start, end); + Set result = redisTemplate.opsForZSet().range(key, start, end); + log.info("zRange(...) => result -> {}", result); + return result; + } + + /** + * 获取(key对应的)zset中的所有item项 + * + * @param key 定位zset的键 + * @return (key对应的)zset中的所有item项 + * @see ZSetOps#zRange(String, long, long) + */ + public static Set zWholeZSetItem(String key) { + log.info("zWholeZSetItem(...) => key -> {}", key); + Set result = redisTemplate.opsForZSet().range(key, 0, -1); + log.info("zWholeZSetItem(...) =>result -> {}", result); + return result; + } + + /** + * 根据索引位置, 获取(key对应的)zset中排名处于[start, end]中的entry集 + *

+ * 注: 不论是使用正向排名,还是使用反向排名, 使用此方法时, 应保证 startIndex代表的元素的 + * 位置在endIndex代表的元素的位置的前面, 如: + * 示例一: RedisUtil.ZSetOps.zRange("name", 0, 2); + * 示例二: RedisUtil.ZSetOps.zRange("site", -2, -1); + * 示例三: RedisUtil.ZSetOps.zRange("foo", 0, -1); + *

+ * 注: 若key不存在, 则返回空的集合。 + *

+ * 注: 当[start, end]的范围比实际zset的范围大时, 返回范围上"交集"对应的项集合。 + *

+ * 注: 此方法和{@link ZSetOps#zRange(String, long, long)}类似,不过此方法返回的不是item集, 而是entry集 + * + * @param key 定位zset的key + * @param start 排名开始位置 + * @param end 排名结束位置 + * @return 对应的entry集 + */ + public static Set> zRangeWithScores(String key, long start, long end) { + log.info("zRangeWithScores(...) => key -> {}, start -> {}, end -> {}", key, start, end); + Set> entries = redisTemplate.opsForZSet().rangeWithScores(key, start, end); + log.info("zRangeWithScores(...) => entries -> {}", JSONUtil.toJsonStr(entries)); + return entries; + } + + /** + * 获取(key对应的)zset中的所有entry + * + * @param key 定位zset的键 + * @return (key对应的)zset中的所有entry + * @see ZSetOps#zRangeWithScores(String, long, long) + */ + public static Set> zWholeZSetEntry(String key) { + log.info("zWholeZSetEntry(...) => key -> {}", key); + Set> entries = redisTemplate.opsForZSet().rangeWithScores(key, 0, -1); + log.info("zWholeZSetEntry(...) => entries -> {}", key, JSONUtil.toJsonStr(entries)); + return entries; + } + + /** + * 根据score, 获取(key对应的)zset中分数值处于[minScore, maxScore]中的item项集 + *

+ * 注: 若key不存在, 则返回空的集合。 + * 注: 当[minScore, maxScore]的范围比实际zset中score的范围大时, 返回范围上"交集"对应的项集合。 + *

+ * 提示: 虽然删除范围包含两侧的端点(即:包含minScore和maxScore), 但是由于double存在精度问题,所以建议: + * 设置值时,minScore应该设置得比要删除的项里,最小的score还小一点 + * maxScore应该设置得比要删除的项里,最大的score还大一点 + * 追注: 本人简单测试了几组数据,暂未出现精度问题。 + * + * @param key 定位zset的key + * @param minScore score下限 + * @param maxScore score上限 + * @return 对应的item项集 + */ + public static Set zRangeByScore(String key, double minScore, double maxScore) { + log.info("zRangeByScore(...) => key -> {}, minScore -> {}, maxScore -> {}", key, minScore, maxScore); + Set items = redisTemplate.opsForZSet().rangeByScore(key, minScore, maxScore); + log.info("zRangeByScore(...) => items -> {}", items); + return items; + } + + /** + * 根据score, 获取(key对应的)zset中分数值处于[minScore, maxScore]中的, score处于[minScore, + * 排名大于等于offset的count个item项 + *

+ * 特别注意: 对于不是特别熟悉redis的人来说, offset 和 count最好都使用正数, 避免引起理解上的歧义。 + *

+ * 注: 若key不存在, 则返回空的集合。 + *

+ * 提示: 虽然删除范围包含两侧的端点(即:包含minScore和maxScore), 但是由于double存在精度问题,所以建议: + * 设置值时,minScore应该设置得比要删除的项里,最小的score还小一点 + * maxScore应该设置得比要删除的项里,最大的score还大一点 + * 追注: 本人简单测试了几组数据,暂未出现精度问题。 + * + * @param key 定位zset的key + * @param minScore score下限 + * @param maxScore score上限 + * @param offset 偏移量(即:排名下限) + * @param count 期望获取到的元素个数 + * @return 对应的item项集 + */ + public static Set zRangeByScore(String key, double minScore, double maxScore, + long offset, long count) { + log.info("zRangeByScore(...) => key -> {}, minScore -> {}, maxScore -> {}, offset -> {}, " + + "count -> {}", key, minScore, maxScore, offset, count); + Set items = redisTemplate.opsForZSet().rangeByScore(key, minScore, maxScore, offset, count); + log.info("zRangeByScore(...) => items -> {}", items); + return items; + } + + /** + * 获取(key对应的)zset中的所有score处于[minScore, maxScore]中的entry + * + * @param key 定位zset的键 + * @param minScore score下限 + * @param maxScore score上限 + * @return (key对应的)zset中的所有score处于[minScore, maxScore]中的entry + * @see ZSetOps#zRangeByScore(String, double, double) + *

+ * 注: 若key不存在, 则返回空的集合。 + * 注: 当[minScore, maxScore]的范围比实际zset中score的范围大时, 返回范围上"交集"对应的项集合。 + */ + public static Set> zRangeByScoreWithScores(String key, double minScore, double maxScore) { + log.info("zRangeByScoreWithScores(...) => key -> {}, minScore -> {}, maxScore -> {}", + key, minScore, maxScore); + Set> entries = redisTemplate.opsForZSet().rangeByScoreWithScores(key, minScore, maxScore); + log.info("zRangeByScoreWithScores(...) => entries -> {}", JSONUtil.toJsonStr(entries)); + return entries; + } + + /** + * 获取(key对应的)zset中, score处于[minScore, maxScore]里的、排名大于等于offset的count个entry + *

+ * 特别注意: 对于不是特别熟悉redis的人来说, offset 和 count最好都使用正数, 避免引起理解上的歧义。 + * + * @param key 定位zset的键 + * @param minScore score下限 + * @param maxScore score上限 + * @param offset 偏移量(即:排名下限) + * @param count 期望获取到的元素个数 + * @return [startIndex, endIndex] & [minScore, maxScore]里的entry + */ + public static Set> zRangeByScoreWithScores(String key, double minScore, + double maxScore, long offset, + long count) { + log.info("zRangeByScoreWithScores(...) => key -> {}, minScore -> {}, maxScore -> {}," + + " offset -> {}, count -> {}", + key, minScore, maxScore, offset, count); + Set> entries = redisTemplate.opsForZSet().rangeByScoreWithScores(key, minScore, + maxScore, offset, count); + log.info("zRangeByScoreWithScores(...) => entries -> {}", JSONUtil.toJsonStr(entries)); + return entries; + } + + + /** + * 获取时, 先按score倒序, 然后根据索引位置, 获取(key对应的)zset中排名处于[start, end]中的item项集 + * + * @see ZSetOps#zRange(String, long, long)。 只是zReverseRange这里会提前多一个倒序。 + */ + public static Set zReverseRange(String key, long start, long end) { + log.info("zReverseRange(...) => key -> {}, start -> {}, end -> {}", key, start, end); + Set entries = redisTemplate.opsForZSet().reverseRange(key, start, end); + log.info("zReverseRange(...) => entries -> {}", entries); + return entries; + } + + /** + * 获取时, 先按score倒序, 然后根据索引位置, 获取(key对应的)zset中排名处于[start, end]中的entry集 + * + * @see ZSetOps#zRangeWithScores(String, long, long)。 只是zReverseRangeWithScores这里会提前多一个倒序。 + */ + public static Set> zReverseRangeWithScores(String key, long start, long end) { + log.info("zReverseRangeWithScores(...) => key -> {}, start -> {}, end -> {}", key, start, end); + Set> entries = redisTemplate.opsForZSet().reverseRangeWithScores(key, start, end); + log.info("zReverseRangeWithScores(...) => entries -> {}", JSONUtil.toJsonStr(entries)); + return entries; + } + + /** + * 获取时, 先按score倒序, 然后根据score, 获取(key对应的)zset中分数值处于[minScore, maxScore]中的item项集 + * + * @see ZSetOps#zRangeByScore(String, double, double)。 只是zReverseRangeByScore这里会提前多一个倒序。 + */ + public static Set zReverseRangeByScore(String key, double minScore, double maxScore) { + log.info("zReverseRangeByScore(...) => key -> {}, minScore -> {}, maxScore -> {}", + key, minScore, maxScore); + Set items = redisTemplate.opsForZSet().reverseRangeByScore(key, minScore, maxScore); + log.info("zReverseRangeByScore(...) => items -> {}", items); + return items; + } + + /** + * 获取时, 先按score倒序, 然后获取(key对应的)zset中的所有score处于[minScore, maxScore]中的entry + * + * @see ZSetOps#zRangeByScoreWithScores(String, double, double)。 只是zReverseRangeByScoreWithScores这里会提前多一个倒序。 + */ + public static Set> zReverseRangeByScoreWithScores(String key, double minScore, double maxScore) { + log.info("zReverseRangeByScoreWithScores(...) => key -> {}, minScore -> {}, maxScore -> {}", + key, minScore, maxScore); + Set> entries = redisTemplate.opsForZSet().reverseRangeByScoreWithScores(key, + minScore, maxScore); + log.info("zReverseRangeByScoreWithScores(...) => entries -> {}", JSONUtil.toJsonStr(entries)); + return entries; + } + + /** + * 获取时, 先按score倒序, 然后根据score, 获取(key对应的)zset中分数值处于[minScore, maxScore]中的, + * score处于[minScore,排名大于等于offset的count个item项 + * + * @see ZSetOps#zRangeByScore(String, double, double, long, long)。 只是zReverseRangeByScore这里会提前多一个倒序。 + */ + public static Set zReverseRangeByScore(String key, double minScore, double maxScore, long offset, long count) { + log.info("zReverseRangeByScore(...) => key -> {}, minScore -> {}, maxScore -> {}, offset -> {}, " + + "count -> {}", key, minScore, maxScore, offset, count); + Set items = redisTemplate.opsForZSet().reverseRangeByScore(key, minScore, maxScore, offset, count); + log.info("items -> {}", items); + return items; + } + + /** + * 统计(key对应的zset中)score处于[minScore, maxScore]中的item的个数 + * + * @param key 定位zset的key + * @param minScore score下限 + * @param maxScore score上限 + * @return [minScore, maxScore]中item的个数 + */ + public static long zCount(String key, double minScore, double maxScore) { + log.info("zCount(...) => key -> {}, minScore -> {}, maxScore -> {}", key, minScore, maxScore); + Long count = redisTemplate.opsForZSet().count(key, minScore, maxScore); + log.info("zCount(...) => count -> {}", count); + if (count == null) { + throw new RedisOpsResultIsNullException(); + } + return count; + } + + /** + * 统计(key对应的)zset中item的个数 + *

+ * 注: 此方法等价于{@link ZSetOps#zZCard(String)} + * + * @param key 定位zset的key + * @return zset中item的个数 + */ + public static long zSize(String key) { + log.info("zSize(...) => key -> {}", key); + Long size = redisTemplate.opsForZSet().size(key); + log.info("zSize(...) => size -> {}", size); + if (size == null) { + throw new RedisOpsResultIsNullException(); + } + return size; + } + + /** + * 统计(key对应的)zset中item的个数 + *

+ * 注: 此方法等价于{@link ZSetOps#zSize(String)} + * + * @param key 定位zset的key + * @return zset中item的个数 + */ + public static long zZCard(String key) { + log.info("zZCard(...) => key -> {}", key); + Long size = redisTemplate.opsForZSet().zCard(key); + log.info("zZCard(...) => size -> {}", size); + if (size == null) { + throw new RedisOpsResultIsNullException(); + } + return size; + } + + /** + * 统计(key对应的)zset中指定item的score + * + * @param key 定位zset的key + * @param item zset中的item + * @return item的score + */ + public static double zScore(String key, Object item) { + log.info("zScore(...) => key -> {}, item -> {}", key, item); + Double score = redisTemplate.opsForZSet().score(key, item); + log.info("zScore(...) => score -> {}", score); + if (score == null) { + throw new RedisOpsResultIsNullException(); + } + return score; + } + + /** + * 获取两个(key对应的)ZSet的并集, 并将结果add到storeKey对应的ZSet中。 + *

+ * 注: 和set一样,zset中item是唯一的, 在多个zset进行Union时, 处理相同的item时, score的值会变为对应的score之和,如: + * RedisUtil.ZSetOps.zAdd("name1", "a", 1);和RedisUtil.ZSetOps.zAdd("name2", "a", 2); + * 对(name1和name2对应的)zset进行zUnionAndStore之后,新的zset中的项a,对应的score值为3 + *

+ * case1: 交集不为空, storeKey不存在, 则 会创建对应的storeKey,并将并集添加到(storeKey对应的)ZSet中 + * case2: 交集不为空, storeKey已存在, 则 会清除原(storeKey对应的)ZSet中所有的项,然后将并集添加到(storeKey对应的)ZSet中 + * case3: 交集为空, 则不进行下面的操作, 直接返回0 + * + * @param key 定位其中一个zset的键 + * @param otherKey 定位另外的zset的键 + * @param storeKey 定位(要把交集添加到哪个)set的key + * @return add到(storeKey对应的)ZSet后, 该ZSet对应的size + */ + public static long zUnionAndStore(String key, String otherKey, String storeKey) { + log.info("zUnionAndStore(...) => key -> {}, otherKey -> {}, storeKey -> {}", key, otherKey, storeKey); + Long size = redisTemplate.opsForZSet().unionAndStore(key, otherKey, storeKey); + log.info("zUnionAndStore(...) => size -> {}", size); + if (size == null) { + throw new RedisOpsResultIsNullException(); + } + return size; + } + + /** + * 获取两个(key对应的)ZSet的并集, 并将结果add到storeKey对应的ZSet中。 + *

+ * 注: 和set一样,zset中item是唯一的, 在多个zset进行Union时, 处理相同的item时, score的值会变为对应的score之和,如: + * RedisUtil.ZSetOps.zAdd("name1", "a", 1);和RedisUtil.ZSetOps.zAdd("name2", "a", 2); + * 对(name1和name2对应的)zset进行zUnionAndStore之后,新的zset中的项a,对应的score值为3 + *

+ * case1: 并集不为空, storeKey不存在, 则 会创建对应的storeKey,并将并集添加到(storeKey对应的)ZSet中 + * case2: 并集不为空, storeKey已存在, 则 会清除原(storeKey对应的)ZSet中所有的项,然后将并集添加到(storeKey对应的)ZSet中 + * case3: 并集为空, 则不进行下面的操作, 直接返回0 + * + * @param key 定位其中一个set的键 + * @param otherKeys 定位其它set的键集 + * @param storeKey 定位(要把并集添加到哪个)set的key + * @return add到(storeKey对应的)ZSet后, 该ZSet对应的size + */ + public static long zUnionAndStore(String key, Collection otherKeys, String storeKey) { + log.info("zUnionAndStore(...) => key -> {}, otherKeys -> {}, storeKey -> {}", key, otherKeys, storeKey); + Long size = redisTemplate.opsForZSet().unionAndStore(key, otherKeys, storeKey); + log.info("zUnionAndStore(...) => size -> {}", size); + if (size == null) { + throw new RedisOpsResultIsNullException(); + } + return size; + } + + /** + * 获取两个(key对应的)ZSet的交集, 并将结果add到storeKey对应的ZSet中。 + *

+ * 注: 和set一样,zset中item是唯一的, 在多个zset进行Intersect时, 处理相同的item时, score的值会变为对应的score之和,如: + * RedisUtil.ZSetOps.zAdd("name1", "a", 1); + * RedisUtil.ZSetOps.zAdd("name1", "b", 100); + * 和R + * edisUtil.ZSetOps.zAdd("name2", "a", 2); + * edisUtil.ZSetOps.zAdd("name2", "c", 200); + * 对(name1和name2对应的)zset进行zIntersectAndStore之后,新的zset中的项a,对应的score值为3 + *

+ * case1: 交集不为空, storeKey不存在, 则 会创建对应的storeKey,并将交集添加到(storeKey对应的)ZSet中 + * case2: 交集不为空, storeKey已存在, 则 会清除原(storeKey对应的)ZSet中所有的项,然后将交集添加到(storeKey对应的)ZSet中 + * case3: 交集为空, 则不进行下面的操作, 直接返回0 + * + * @param key 定位其中一个ZSet的键 + * @param otherKey 定位其中另一个ZSet的键 + * @param storeKey 定位(要把交集添加到哪个)ZSet的key + * @return add到(storeKey对应的)ZSet后, 该ZSet对应的size + */ + public static long zIntersectAndStore(String key, String otherKey, String storeKey) { + log.info("zIntersectAndStore(...) => key -> {}, otherKey -> {}, storeKey -> {}", key, otherKey, storeKey); + Long size = redisTemplate.opsForZSet().intersectAndStore(key, otherKey, storeKey); + log.info("zIntersectAndStore(...) => size -> {}", size); + if (size == null) { + throw new RedisOpsResultIsNullException(); + } + return size; + } + + /** + * 获取多个(key对应的)ZSet的交集, 并将结果add到storeKey对应的ZSet中。 + *

+ * case1: 交集不为空, storeKey不存在, 则 会创建对应的storeKey,并将交集添加到(storeKey对应的)ZSet中 + * case2: 交集不为空, storeKey已存在, 则 会清除原(storeKey对应的)ZSet中所有的项,然后将交集添加到(storeKey对应的)ZSet中 + * case3: 交集为空, 则不进行下面的操作, 直接返回0 + * + * @param key 定位其中一个set的键 + * @param otherKeys 定位其它set的键集 + * @param storeKey 定位(要把并集添加到哪个)set的key + * @return add到(storeKey对应的)ZSet后, 该ZSet对应的size + */ + public static long zIntersectAndStore(String key, Collection otherKeys, String storeKey) { + log.info("zIntersectAndStore(...) => key -> {}, otherKeys -> {}, storeKey -> {}", + key, otherKeys, storeKey); + Long size = redisTemplate.opsForZSet().intersectAndStore(key, otherKeys, storeKey); + log.info("zIntersectAndStore(...) => size -> {}", size); + if (size == null) { + throw new RedisOpsResultIsNullException(); + } + return size; + } + } + + /** + * redis分布式锁. + *

+ * 使用方式(示例): + * boolean flag = false; + * String lockName = "sichuan:mianyang:fucheng:ds"; + * String lockValue = UUID.randomUUID().toString(); + * try { + * // 非阻塞获取(锁的最大存活时间采用默认值) + * flag = RedisUtil.LockOps.getLock(lockName, lockValue); + * // 非阻塞获取e.g. + * flag = RedisUtil.LockOps.getLock(lockName, lockValue, 3, TimeUnit.SECONDS); + * // 阻塞获取(锁的最大存活时间采用默认值) + * flag = RedisUtil.LockOps.getLockUntilTimeout(lockName, lockValue, 2000); + * // 阻塞获取e.g. + * flag = RedisUtil.LockOps.getLockUntilTimeout(lockName, lockValue, 2, TimeUnit.SECONDS, 2000); + * // your logic + * // ... + * } finally { + * if (flag) { + * RedisUtil.LockOps.releaseLock(lockName, lockValue); + * } + * } + * + * @author JustryDeng + */ + public static class LockOps { + + /** + * lua脚本, 保证 释放锁脚本 的原子性(以避免, 并发场景下, 释放了别人的锁) + */ + private static final String RELEASE_LOCK_LUA; + + /** + * 分布式锁默认(最大)存活时长 + */ + public static final long DEFAULT_LOCK_TIMEOUT = 3; + + /** + * DEFAULT_LOCK_TIMEOUT的单位 + */ + public static final TimeUnit DEFAULT_TIMEOUT_UNIT = TimeUnit.SECONDS; + + static { + // 不论lua中0是否代表失败; 对于java的Boolean而言, 返回0, 则会被解析为false + RELEASE_LOCK_LUA = "if redis.call('get',KEYS[1]) == ARGV[1] " + + "then " + + " return redis.call('del',KEYS[1]) " + + "else " + + " return 0 " + + "end "; + } + + /** + * 获取(分布式)锁. + *

+ * 注: 获取结果是即时返回的、是非阻塞的。 + * + * @see LockOps#getLock(String, String, long, TimeUnit) + */ + public static boolean getLock(final String key, final String value) { + return getLock(key, value, DEFAULT_LOCK_TIMEOUT, DEFAULT_TIMEOUT_UNIT); + } + + /** + * 获取(分布式)锁。 + * 若成功, 则直接返回; + * 若失败, 则进行重试, 直到成功 或 超时为止。 + *

+ * 注: 获取结果是阻塞的, 要么成功, 要么超时, 才返回。 + * + * @param retryTimeoutLimit 重试的超时时长(ms) + * 其它参数可详见: + * @return 是否成功 + * @see LockOps#getLock(String, String, long, TimeUnit) + */ + public static boolean getLockUntilTimeout(final String key, final String value, + final long retryTimeoutLimit) { + return getLockUntilTimeout(key, value, DEFAULT_LOCK_TIMEOUT, DEFAULT_TIMEOUT_UNIT, retryTimeoutLimit); + } + + /** + * 获取(分布式)锁。 + * 若成功, 则直接返回; + * 若失败, 则进行重试, 直到成功 或 超时为止。 + *

+ * 注: 获取结果是阻塞的, 要么成功, 要么超时, 才返回。 + * + * @param retryTimeoutLimit 重试的超时时长(ms) + * 其它参数可详见: + * @return 是否成功 + * @see LockOps#getLock(String, String, long, TimeUnit, boolean) + */ + public static boolean getLockUntilTimeout(final String key, final String value, + final long timeout, final TimeUnit unit, + final long retryTimeoutLimit) { + log.info("getLockUntilTimeout(...) => key -> {}, value -> {}, timeout -> {}, unit -> {}, " + + "retryTimeoutLimit -> {}ms", key, value, timeout, unit, retryTimeoutLimit); + long startTime = Instant.now().toEpochMilli(); + long now = startTime; + do { + try { + boolean alreadyGotLock = getLock(key, value, timeout, unit, false); + if (alreadyGotLock) { + log.info("getLockUntilTimeout(...) => consume time -> {}ms, result -> true", now - startTime); + return true; + } + } catch (Exception e) { + log.warn("getLockUntilTimeout(...) => try to get lock failure! e.getMessage -> {}", + e.getMessage()); + } + now = Instant.now().toEpochMilli(); + } while (now < startTime + retryTimeoutLimit); + log.info("getLockUntilTimeout(...) => consume time -> {}ms, result -> false", now - startTime); + return false; + } + + /** + * 获取(分布式)锁 + *

+ * 注: 获取结果是即时返回的、是非阻塞的。 + * + * @see LockOps#getLock(String, String, long, TimeUnit, boolean) + */ + public static boolean getLock(final String key, final String value, + final long timeout, final TimeUnit unit) { + return getLock(key, value, timeout, unit, true); + } + + /** + * 获取(分布式)锁 + *

+ * 注: 获取结果是即时返回的、是非阻塞的。 + * + * @param key 锁名 + * @param value 锁名对应的value + * 注: value一般采用全局唯一的值, 如: requestId、uuid等。 + * 这样, 释放锁的时候, 可以再次验证value值, + * 保证自己上的锁只能被自己释放, 而不会被别人释放。 + * 当然, 如果锁超时时, 会被redis自动删除释放。 + * @param timeout 锁的(最大)存活时长 + * 注: 一般的, 获取锁与释放锁 都是成对使用的, 在锁在达到(最大)存活时长之前,都会被主动释放。 + * 但是在某些情况下(如:程序获取锁后,释放锁前,崩了),锁得不到释放, 这时就需要等锁过 + * 了(最大)存活时长后,被redis自动删除清理了。这样就能保证redis中不会留下死数据。 + * @param unit timeout的单位 + * @param recordLog 是否记录日志 + * @return 是否成功 + */ + public static boolean getLock(final String key, final String value, + final long timeout, final TimeUnit unit, + boolean recordLog) { + if (recordLog) { + log.info("getLock(...) => key -> {}, value -> {}, timeout -> {}, unit -> {}, recordLog -> {}", + key, value, timeout, unit, recordLog); + } + Boolean result = redisTemplate.execute((RedisConnection connection) -> + connection.set(key.getBytes(StandardCharsets.UTF_8), + value.getBytes(StandardCharsets.UTF_8), + Expiration.seconds(unit.toSeconds(timeout)), + RedisStringCommands.SetOption.SET_IF_ABSENT) + ); + if (recordLog) { + log.info("getLock(...) => result -> {}", result); + } + if (result == null) { + throw new RedisOpsResultIsNullException(); + } + return result; + } + + /** + * 释放(分布式)锁 + *

+ * 注: 此方式能(通过value的唯一性)保证: 自己加的锁, 只能被自己释放。 + * 注: 锁超时时, 也会被redis自动删除释放。 + * + * @param key 锁名 + * @param value 锁名对应的value + * @return 释放锁是否成功 + */ + public static boolean releaseLock(final String key, final String value) { + log.info("releaseLock(...) => key -> {}, lockValue -> {}", key, value); + Boolean result = redisTemplate.execute((RedisConnection connection) -> + connection.eval(RELEASE_LOCK_LUA.getBytes(), + ReturnType.BOOLEAN, 1, + key.getBytes(StandardCharsets.UTF_8), value.getBytes(StandardCharsets.UTF_8)) + ); + log.info("releaseLock(...) => result -> {}", result); + if (result == null) { + throw new RedisOpsResultIsNullException(); + } + return result; + } + + /** + * 释放锁, 不校验该key对应的value值 + *

+ * 注: 此方式释放锁,可能导致: 自己加的锁, 结果被别人释放了。 + * 所以不建议使用此方式释放锁。 + * + * @param key 锁名 + */ + @Deprecated + public static void releaseLock(final String key) { + KeyOps.delete(key); + } + } + + /** + * 当使用Pipeline 或 Transaction操作redis时, (不论redis中实际操作是否成功, 这里)结果(都)会返回null。 + * 此时,如果试着将null转换为基本类型的数据时,会抛出此异常。 + *

+ * 即: 此工具类中的某些方法, 希望不要使用Pipeline或Transaction操作redis。 + *

+ * 注: Pipeline 或 Transaction默认是不启用的, 可详见源码: + * + * @author JustryDeng + * @see LettuceConnection#isPipelined() + * @see LettuceConnection#isQueueing() + * @see JedisConnection#isPipelined() + * @see JedisConnection#isQueueing() + */ + public static class RedisOpsResultIsNullException extends NullPointerException { + + public RedisOpsResultIsNullException() { + super(); + } + + public RedisOpsResultIsNullException(String message) { + super(message); + } + } + + /** + * 提供一些基础功能支持 + * + * @author JustryDeng + */ + public static class Helper { + + /** + * 默认拼接符 + */ + public static final String DEFAULT_SYMBOL = ":"; + + /** + * 拼接args + * + * @see Helper#joinBySymbol(String, String...) + */ + public static String join(String... args) { + return Helper.joinBySymbol(DEFAULT_SYMBOL, args); + } + + /** + * 使用symbol拼接args + * + * @param symbol 分隔符, 如: 【:】 + * @param args 要拼接的元素数组, 如: 【a b c】 + * @return 拼接后的字符串, 如 【a:b:c】 + */ + public static String joinBySymbol(String symbol, String... args) { + if (symbol == null || symbol.trim().length() == 0) { + throw new RuntimeException(" symbol must not be empty!"); + } + if (args == null || args.length == 0) { + throw new RuntimeException(" args must not be empty!"); + } + StringBuilder sb = new StringBuilder(16); + for (String arg : args) { + sb.append(arg).append(symbol); + } + sb.replace(sb.length() - symbol.length(), sb.length(), ""); + return sb.toString(); + } + + } +} diff --git a/backend/java/sk-matrix-service/common/src/main/resources/banner.txt b/backend/java/sk-matrix-service/common/src/main/resources/banner.txt new file mode 100644 index 0000000..6760f70 --- /dev/null +++ b/backend/java/sk-matrix-service/common/src/main/resources/banner.txt @@ -0,0 +1,9 @@ + _____ _ _ _ + / ____| | (_) | + | (___ | |__ _| | _____ _ __ __ _ ___ __ ___ __ _ ___ + \___ \| '_ \| | |/ / _ \| '_ \ / _` | / _/ / |/ /__ _/ /_____(_)_ __ / / + ____) | | | | | < (_) | | | | (_| | / / / /|_/ / _ `/ __/ __/ /\ \ / / / + |_____/|_| |_|_|_|\_\___/|_| |_|\__, | / / /_/ /_/\_,_/\__/_/ /_//_\_\ / / + __/ | /__/ /__/ + |___/ + \ No newline at end of file diff --git a/backend/java/sk-matrix-service/common/src/main/resources/logback.xml b/backend/java/sk-matrix-service/common/src/main/resources/logback.xml new file mode 100644 index 0000000..0f54536 --- /dev/null +++ b/backend/java/sk-matrix-service/common/src/main/resources/logback.xml @@ -0,0 +1,53 @@ + + + + + logback + + + + + + + + + + + + + %red(%d{yyyy-MM-dd HH:mm:ss.SSS}) %green([%thread]) %highlight(%-5level) %yellow(at %class.%method) (%file:%line\) - %cyan(%msg%n) + + UTF-8 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/backend/java/sk-matrix-service/orm/README.MD b/backend/java/sk-matrix-service/orm/README.MD new file mode 100644 index 0000000..dfbb3e5 --- /dev/null +++ b/backend/java/sk-matrix-service/orm/README.MD @@ -0,0 +1,2 @@ +### 从数据库生成 Java Bean +利用 mybatis-generator 插件实现 diff --git a/backend/java/sk-matrix-service/orm/pom.xml b/backend/java/sk-matrix-service/orm/pom.xml new file mode 100644 index 0000000..85492f4 --- /dev/null +++ b/backend/java/sk-matrix-service/orm/pom.xml @@ -0,0 +1,154 @@ + + + 4.0.0 + + cn.skcks.matrix.v2 + sk-matrix-service + 1.0-SNAPSHOT + + + orm + + + 17 + 17 + UTF-8 + + + + + cn.skcks.matrix.v2 + casbin + ${project.version} + + + + com.alibaba + druid + + + + + org.apache.tomcat + tomcat-dbcp + + + + + org.mybatis.spring.boot + mybatis-spring-boot-starter + + + + com.github.pagehelper + pagehelper-spring-boot-starter + + + + cn.hutool + hutool-all + + + + org.apache.shardingsphere + shardingsphere-jdbc-core-spring-boot-starter + + + + + + + + + + + org.mybatis.dynamic-sql + mybatis-dynamic-sql + + + + org.springframework.boot + spring-boot-starter + + + + com.mysql + mysql-connector-j + + + + + org.junit.jupiter + junit-jupiter-api + test + + + + org.springframework.boot + spring-boot-starter-test + test + + + + javax.annotation + javax.annotation-api + 1.3.2 + + + + + + + src/main/java + + **/** + + + + src/main/resources + + **/** + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + true + + + + + org.mybatis.generator + mybatis-generator-maven-plugin + ${mybatis-generator-maven-plugin.version} + + + src/main/resources/config/generatorConfig.xml + true + true + + + + Generate MyBatis Artifacts + + generate + + + + + + com.mysql + mysql-connector-j + ${mysql.version} + + + + + + diff --git a/backend/java/sk-matrix-service/orm/src/main/java/cn/skcks/matrix/v2/orm/mybatis/basic/mapper/CasbinRuleMapper.java b/backend/java/sk-matrix-service/orm/src/main/java/cn/skcks/matrix/v2/orm/mybatis/basic/mapper/CasbinRuleMapper.java new file mode 100644 index 0000000..ece528b --- /dev/null +++ b/backend/java/sk-matrix-service/orm/src/main/java/cn/skcks/matrix/v2/orm/mybatis/basic/mapper/CasbinRuleMapper.java @@ -0,0 +1,107 @@ +package cn.skcks.matrix.v2.orm.mybatis.basic.mapper; + +import cn.skcks.matrix.v2.orm.mybatis.basic.model.CasbinRule; +import java.util.List; +import org.apache.ibatis.annotations.Delete; +import org.apache.ibatis.annotations.Insert; +import org.apache.ibatis.annotations.Result; +import org.apache.ibatis.annotations.Results; +import org.apache.ibatis.annotations.Select; +import org.apache.ibatis.annotations.Update; +import org.apache.ibatis.type.JdbcType; + +public interface CasbinRuleMapper { + /** + * This method was generated by MyBatis Generator. + * This method corresponds to the database table casbin_rule + * + * @mbg.generated + */ + @Delete({ + "delete from casbin_rule", + "where id = #{id,jdbcType=INTEGER}" + }) + int deleteByPrimaryKey(Integer id); + + /** + * This method was generated by MyBatis Generator. + * This method corresponds to the database table casbin_rule + * + * @mbg.generated + */ + @Insert({ + "insert into casbin_rule (id, ptype, ", + "v0, v1, v2, ", + "v3, v4, v5)", + "values (#{id,jdbcType=INTEGER}, #{ptype,jdbcType=VARCHAR}, ", + "#{v0,jdbcType=VARCHAR}, #{v1,jdbcType=VARCHAR}, #{v2,jdbcType=VARCHAR}, ", + "#{v3,jdbcType=VARCHAR}, #{v4,jdbcType=VARCHAR}, #{v5,jdbcType=VARCHAR})" + }) + int insert(CasbinRule row); + + /** + * This method was generated by MyBatis Generator. + * This method corresponds to the database table casbin_rule + * + * @mbg.generated + */ + @Select({ + "select", + "id, ptype, v0, v1, v2, v3, v4, v5", + "from casbin_rule", + "where id = #{id,jdbcType=INTEGER}" + }) + @Results({ + @Result(column="id", property="id", jdbcType=JdbcType.INTEGER, id=true), + @Result(column="ptype", property="ptype", jdbcType=JdbcType.VARCHAR), + @Result(column="v0", property="v0", jdbcType=JdbcType.VARCHAR), + @Result(column="v1", property="v1", jdbcType=JdbcType.VARCHAR), + @Result(column="v2", property="v2", jdbcType=JdbcType.VARCHAR), + @Result(column="v3", property="v3", jdbcType=JdbcType.VARCHAR), + @Result(column="v4", property="v4", jdbcType=JdbcType.VARCHAR), + @Result(column="v5", property="v5", jdbcType=JdbcType.VARCHAR) + }) + CasbinRule selectByPrimaryKey(Integer id); + + /** + * This method was generated by MyBatis Generator. + * This method corresponds to the database table casbin_rule + * + * @mbg.generated + */ + @Select({ + "select", + "id, ptype, v0, v1, v2, v3, v4, v5", + "from casbin_rule" + }) + @Results({ + @Result(column="id", property="id", jdbcType=JdbcType.INTEGER, id=true), + @Result(column="ptype", property="ptype", jdbcType=JdbcType.VARCHAR), + @Result(column="v0", property="v0", jdbcType=JdbcType.VARCHAR), + @Result(column="v1", property="v1", jdbcType=JdbcType.VARCHAR), + @Result(column="v2", property="v2", jdbcType=JdbcType.VARCHAR), + @Result(column="v3", property="v3", jdbcType=JdbcType.VARCHAR), + @Result(column="v4", property="v4", jdbcType=JdbcType.VARCHAR), + @Result(column="v5", property="v5", jdbcType=JdbcType.VARCHAR) + }) + List selectAll(); + + /** + * This method was generated by MyBatis Generator. + * This method corresponds to the database table casbin_rule + * + * @mbg.generated + */ + @Update({ + "update casbin_rule", + "set ptype = #{ptype,jdbcType=VARCHAR},", + "v0 = #{v0,jdbcType=VARCHAR},", + "v1 = #{v1,jdbcType=VARCHAR},", + "v2 = #{v2,jdbcType=VARCHAR},", + "v3 = #{v3,jdbcType=VARCHAR},", + "v4 = #{v4,jdbcType=VARCHAR},", + "v5 = #{v5,jdbcType=VARCHAR}", + "where id = #{id,jdbcType=INTEGER}" + }) + int updateByPrimaryKey(CasbinRule row); +} diff --git a/backend/java/sk-matrix-service/orm/src/main/java/cn/skcks/matrix/v2/orm/mybatis/basic/mapper/LocationRecordMapper.java b/backend/java/sk-matrix-service/orm/src/main/java/cn/skcks/matrix/v2/orm/mybatis/basic/mapper/LocationRecordMapper.java new file mode 100644 index 0000000..07bbb0b --- /dev/null +++ b/backend/java/sk-matrix-service/orm/src/main/java/cn/skcks/matrix/v2/orm/mybatis/basic/mapper/LocationRecordMapper.java @@ -0,0 +1,166 @@ +package cn.skcks.matrix.v2.orm.mybatis.basic.mapper; + +import cn.skcks.matrix.v2.orm.mybatis.basic.model.LocationRecord; + +import java.util.List; + +import org.apache.ibatis.annotations.Delete; +import org.apache.ibatis.annotations.Insert; +import org.apache.ibatis.annotations.Result; +import org.apache.ibatis.annotations.Results; +import org.apache.ibatis.annotations.Select; +import org.apache.ibatis.annotations.Update; +import org.apache.ibatis.type.JdbcType; + +public interface LocationRecordMapper { + /** + * This method was generated by MyBatis Generator. + * This method corresponds to the database table location_record + * + * @mbg.generated + */ + @Delete({ + "delete from location_record", + "where id = #{id,jdbcType=VARCHAR}" + }) + int deleteByPrimaryKey(String id); + + /** + * This method was generated by MyBatis Generator. + * This method corresponds to the database table location_record + * + * @mbg.generated + */ + @Insert({ + "insert into location_record (id, callback_time, ", + "location_time, location_type, ", + "latitude, longitude, ", + "accuracy, altitude, ", + "bearing, speed, country, ", + "province, city, ", + "district, street, ", + "street_number, city_code, ", + "ad_code, address, ", + "description, user_id)", + "values (#{id,jdbcType=VARCHAR}, #{callbackTime,jdbcType=TIMESTAMP}, ", + "#{locationTime,jdbcType=TIMESTAMP}, #{locationType,jdbcType=INTEGER}, ", + "#{latitude,jdbcType=DOUBLE}, #{longitude,jdbcType=DOUBLE}, ", + "#{accuracy,jdbcType=DOUBLE}, #{altitude,jdbcType=DOUBLE}, ", + "#{bearing,jdbcType=DOUBLE}, #{speed,jdbcType=DOUBLE}, #{country,jdbcType=VARCHAR}, ", + "#{province,jdbcType=VARCHAR}, #{city,jdbcType=VARCHAR}, ", + "#{district,jdbcType=VARCHAR}, #{street,jdbcType=VARCHAR}, ", + "#{streetNumber,jdbcType=VARCHAR}, #{cityCode,jdbcType=VARCHAR}, ", + "#{adCode,jdbcType=VARCHAR}, #{address,jdbcType=VARCHAR}, ", + "#{description,jdbcType=VARCHAR}, #{userId,jdbcType=BIGINT})" + }) + int insert(LocationRecord row); + + /** + * This method was generated by MyBatis Generator. + * This method corresponds to the database table location_record + * + * @mbg.generated + */ + @Select({ + "select", + "id, callback_time, location_time, location_type, latitude, longitude, accuracy, ", + "altitude, bearing, speed, country, province, city, district, street, street_number, ", + "city_code, ad_code, address, description, user_id", + "from location_record", + "where id = #{id,jdbcType=VARCHAR}" + }) + @Results({ + @Result(column="id", property="id", jdbcType=JdbcType.VARCHAR, id=true), + @Result(column="callback_time", property="callbackTime", jdbcType=JdbcType.TIMESTAMP), + @Result(column="location_time", property="locationTime", jdbcType=JdbcType.TIMESTAMP), + @Result(column="location_type", property="locationType", jdbcType=JdbcType.INTEGER), + @Result(column="latitude", property="latitude", jdbcType=JdbcType.DOUBLE), + @Result(column="longitude", property="longitude", jdbcType=JdbcType.DOUBLE), + @Result(column="accuracy", property="accuracy", jdbcType=JdbcType.DOUBLE), + @Result(column="altitude", property="altitude", jdbcType=JdbcType.DOUBLE), + @Result(column="bearing", property="bearing", jdbcType=JdbcType.DOUBLE), + @Result(column="speed", property="speed", jdbcType=JdbcType.DOUBLE), + @Result(column="country", property="country", jdbcType=JdbcType.VARCHAR), + @Result(column="province", property="province", jdbcType=JdbcType.VARCHAR), + @Result(column="city", property="city", jdbcType=JdbcType.VARCHAR), + @Result(column="district", property="district", jdbcType=JdbcType.VARCHAR), + @Result(column="street", property="street", jdbcType=JdbcType.VARCHAR), + @Result(column="street_number", property="streetNumber", jdbcType=JdbcType.VARCHAR), + @Result(column="city_code", property="cityCode", jdbcType=JdbcType.VARCHAR), + @Result(column="ad_code", property="adCode", jdbcType=JdbcType.VARCHAR), + @Result(column="address", property="address", jdbcType=JdbcType.VARCHAR), + @Result(column="description", property="description", jdbcType=JdbcType.VARCHAR), + @Result(column="user_id", property="userId", jdbcType=JdbcType.BIGINT) + }) + LocationRecord selectByPrimaryKey(String id); + + /** + * This method was generated by MyBatis Generator. + * This method corresponds to the database table location_record + * + * @mbg.generated + */ + @Select({ + "select", + "id, callback_time, location_time, location_type, latitude, longitude, accuracy, ", + "altitude, bearing, speed, country, province, city, district, street, street_number, ", + "city_code, ad_code, address, description, user_id", + "from location_record" + }) + @Results({ + @Result(column="id", property="id", jdbcType=JdbcType.VARCHAR, id=true), + @Result(column="callback_time", property="callbackTime", jdbcType=JdbcType.TIMESTAMP), + @Result(column="location_time", property="locationTime", jdbcType=JdbcType.TIMESTAMP), + @Result(column="location_type", property="locationType", jdbcType=JdbcType.INTEGER), + @Result(column="latitude", property="latitude", jdbcType=JdbcType.DOUBLE), + @Result(column="longitude", property="longitude", jdbcType=JdbcType.DOUBLE), + @Result(column="accuracy", property="accuracy", jdbcType=JdbcType.DOUBLE), + @Result(column="altitude", property="altitude", jdbcType=JdbcType.DOUBLE), + @Result(column="bearing", property="bearing", jdbcType=JdbcType.DOUBLE), + @Result(column="speed", property="speed", jdbcType=JdbcType.DOUBLE), + @Result(column="country", property="country", jdbcType=JdbcType.VARCHAR), + @Result(column="province", property="province", jdbcType=JdbcType.VARCHAR), + @Result(column="city", property="city", jdbcType=JdbcType.VARCHAR), + @Result(column="district", property="district", jdbcType=JdbcType.VARCHAR), + @Result(column="street", property="street", jdbcType=JdbcType.VARCHAR), + @Result(column="street_number", property="streetNumber", jdbcType=JdbcType.VARCHAR), + @Result(column="city_code", property="cityCode", jdbcType=JdbcType.VARCHAR), + @Result(column="ad_code", property="adCode", jdbcType=JdbcType.VARCHAR), + @Result(column="address", property="address", jdbcType=JdbcType.VARCHAR), + @Result(column="description", property="description", jdbcType=JdbcType.VARCHAR), + @Result(column="user_id", property="userId", jdbcType=JdbcType.BIGINT) + }) + List selectAll(); + + /** + * This method was generated by MyBatis Generator. + * This method corresponds to the database table location_record + * + * @mbg.generated + */ + @Update({ + "update location_record", + "set callback_time = #{callbackTime,jdbcType=TIMESTAMP},", + "location_time = #{locationTime,jdbcType=TIMESTAMP},", + "location_type = #{locationType,jdbcType=INTEGER},", + "latitude = #{latitude,jdbcType=DOUBLE},", + "longitude = #{longitude,jdbcType=DOUBLE},", + "accuracy = #{accuracy,jdbcType=DOUBLE},", + "altitude = #{altitude,jdbcType=DOUBLE},", + "bearing = #{bearing,jdbcType=DOUBLE},", + "speed = #{speed,jdbcType=DOUBLE},", + "country = #{country,jdbcType=VARCHAR},", + "province = #{province,jdbcType=VARCHAR},", + "city = #{city,jdbcType=VARCHAR},", + "district = #{district,jdbcType=VARCHAR},", + "street = #{street,jdbcType=VARCHAR},", + "street_number = #{streetNumber,jdbcType=VARCHAR},", + "city_code = #{cityCode,jdbcType=VARCHAR},", + "ad_code = #{adCode,jdbcType=VARCHAR},", + "address = #{address,jdbcType=VARCHAR},", + "description = #{description,jdbcType=VARCHAR},", + "user_id = #{userId,jdbcType=BIGINT}", + "where id = #{id,jdbcType=VARCHAR}" + }) + int updateByPrimaryKey(LocationRecord row); +} diff --git a/backend/java/sk-matrix-service/orm/src/main/java/cn/skcks/matrix/v2/orm/mybatis/basic/mapper/RoleMapper.java b/backend/java/sk-matrix-service/orm/src/main/java/cn/skcks/matrix/v2/orm/mybatis/basic/mapper/RoleMapper.java new file mode 100644 index 0000000..932ea46 --- /dev/null +++ b/backend/java/sk-matrix-service/orm/src/main/java/cn/skcks/matrix/v2/orm/mybatis/basic/mapper/RoleMapper.java @@ -0,0 +1,100 @@ +package cn.skcks.matrix.v2.orm.mybatis.basic.mapper; + +import cn.skcks.matrix.v2.orm.mybatis.basic.model.Role; + +import java.util.List; + +import org.apache.ibatis.annotations.Delete; +import org.apache.ibatis.annotations.Insert; +import org.apache.ibatis.annotations.Result; +import org.apache.ibatis.annotations.Results; +import org.apache.ibatis.annotations.Select; +import org.apache.ibatis.annotations.Update; +import org.apache.ibatis.type.JdbcType; + +public interface RoleMapper { + /** + * This method was generated by MyBatis Generator. + * This method corresponds to the database table role + * + * @mbg.generated + */ + @Delete({ + "delete from role", + "where id = #{id,jdbcType=BIGINT}" + }) + int deleteByPrimaryKey(Long id); + + /** + * This method was generated by MyBatis Generator. + * This method corresponds to the database table role + * + * @mbg.generated + */ + @Insert({ + "insert into role (id, role, ", + "name, system_id, ", + "active)", + "values (#{id,jdbcType=BIGINT}, #{role,jdbcType=VARCHAR}, ", + "#{name,jdbcType=VARCHAR}, #{systemId,jdbcType=VARCHAR}, ", + "#{active,jdbcType=BIT})" + }) + int insert(Role row); + + /** + * This method was generated by MyBatis Generator. + * This method corresponds to the database table role + * + * @mbg.generated + */ + @Select({ + "select", + "id, role, name, system_id, active", + "from role", + "where id = #{id,jdbcType=BIGINT}" + }) + @Results({ + @Result(column="id", property="id", jdbcType=JdbcType.BIGINT, id=true), + @Result(column="role", property="role", jdbcType=JdbcType.VARCHAR), + @Result(column="name", property="name", jdbcType=JdbcType.VARCHAR), + @Result(column="system_id", property="systemId", jdbcType=JdbcType.VARCHAR), + @Result(column="active", property="active", jdbcType=JdbcType.BIT) + }) + Role selectByPrimaryKey(Long id); + + /** + * This method was generated by MyBatis Generator. + * This method corresponds to the database table role + * + * @mbg.generated + */ + @Select({ + "select", + "id, role, name, system_id, active", + "from role" + }) + @Results({ + @Result(column="id", property="id", jdbcType=JdbcType.BIGINT, id=true), + @Result(column="role", property="role", jdbcType=JdbcType.VARCHAR), + @Result(column="name", property="name", jdbcType=JdbcType.VARCHAR), + @Result(column="system_id", property="systemId", jdbcType=JdbcType.VARCHAR), + @Result(column="active", property="active", jdbcType=JdbcType.BIT) + }) + List selectAll(); + + /** + * This method was generated by MyBatis Generator. + * This method corresponds to the database table role + * + * @mbg.generated + */ + @Update({ + "update role", + "set role = #{role,jdbcType=VARCHAR},", + "name = #{name,jdbcType=VARCHAR},", + "system_id = #{systemId,jdbcType=VARCHAR},", + "active = #{active,jdbcType=BIT}", + "where id = #{id,jdbcType=BIGINT}" + }) + int updateByPrimaryKey(Role row); +} diff --git a/backend/java/sk-matrix-service/orm/src/main/java/cn/skcks/matrix/v2/orm/mybatis/basic/mapper/UserMapper.java b/backend/java/sk-matrix-service/orm/src/main/java/cn/skcks/matrix/v2/orm/mybatis/basic/mapper/UserMapper.java new file mode 100644 index 0000000..03a8583 --- /dev/null +++ b/backend/java/sk-matrix-service/orm/src/main/java/cn/skcks/matrix/v2/orm/mybatis/basic/mapper/UserMapper.java @@ -0,0 +1,118 @@ +package cn.skcks.matrix.v2.orm.mybatis.basic.mapper; + +import cn.skcks.matrix.v2.orm.mybatis.basic.model.User; + +import java.util.List; + +import org.apache.ibatis.annotations.Delete; +import org.apache.ibatis.annotations.Insert; +import org.apache.ibatis.annotations.Result; +import org.apache.ibatis.annotations.Results; +import org.apache.ibatis.annotations.Select; +import org.apache.ibatis.annotations.Update; +import org.apache.ibatis.type.JdbcType; + +public interface UserMapper { + /** + * This method was generated by MyBatis Generator. + * This method corresponds to the database table user + * + * @mbg.generated + */ + @Delete({ + "delete from user", + "where id = #{id,jdbcType=BIGINT}" + }) + int deleteByPrimaryKey(Long id); + + /** + * This method was generated by MyBatis Generator. + * This method corresponds to the database table user + * + * @mbg.generated + */ + @Insert({ + "insert into user (id, user_name, ", + "password, salt, ", + "email, phone_number, ", + "description, create_time, ", + "update_time)", + "values (#{id,jdbcType=BIGINT}, #{userName,jdbcType=VARCHAR}, ", + "#{password,jdbcType=VARCHAR}, #{salt,jdbcType=VARCHAR}, ", + "#{email,jdbcType=VARCHAR}, #{phoneNumber,jdbcType=VARCHAR}, ", + "#{description,jdbcType=VARCHAR}, #{createTime,jdbcType=TIMESTAMP}, ", + "#{updateTime,jdbcType=TIMESTAMP})" + }) + int insert(User row); + + /** + * This method was generated by MyBatis Generator. + * This method corresponds to the database table user + * + * @mbg.generated + */ + @Select({ + "select", + "id, user_name, password, salt, email, phone_number, description, create_time, ", + "update_time", + "from user", + "where id = #{id,jdbcType=BIGINT}" + }) + @Results({ + @Result(column="id", property="id", jdbcType=JdbcType.BIGINT, id=true), + @Result(column="user_name", property="userName", jdbcType=JdbcType.VARCHAR), + @Result(column="password", property="password", jdbcType=JdbcType.VARCHAR), + @Result(column="salt", property="salt", jdbcType=JdbcType.VARCHAR), + @Result(column="email", property="email", jdbcType=JdbcType.VARCHAR), + @Result(column="phone_number", property="phoneNumber", jdbcType=JdbcType.VARCHAR), + @Result(column="description", property="description", jdbcType=JdbcType.VARCHAR), + @Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP), + @Result(column="update_time", property="updateTime", jdbcType=JdbcType.TIMESTAMP) + }) + User selectByPrimaryKey(Long id); + + /** + * This method was generated by MyBatis Generator. + * This method corresponds to the database table user + * + * @mbg.generated + */ + @Select({ + "select", + "id, user_name, password, salt, email, phone_number, description, create_time, ", + "update_time", + "from user" + }) + @Results({ + @Result(column="id", property="id", jdbcType=JdbcType.BIGINT, id=true), + @Result(column="user_name", property="userName", jdbcType=JdbcType.VARCHAR), + @Result(column="password", property="password", jdbcType=JdbcType.VARCHAR), + @Result(column="salt", property="salt", jdbcType=JdbcType.VARCHAR), + @Result(column="email", property="email", jdbcType=JdbcType.VARCHAR), + @Result(column="phone_number", property="phoneNumber", jdbcType=JdbcType.VARCHAR), + @Result(column="description", property="description", jdbcType=JdbcType.VARCHAR), + @Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP), + @Result(column="update_time", property="updateTime", jdbcType=JdbcType.TIMESTAMP) + }) + List selectAll(); + + /** + * This method was generated by MyBatis Generator. + * This method corresponds to the database table user + * + * @mbg.generated + */ + @Update({ + "update user", + "set user_name = #{userName,jdbcType=VARCHAR},", + "password = #{password,jdbcType=VARCHAR},", + "salt = #{salt,jdbcType=VARCHAR},", + "email = #{email,jdbcType=VARCHAR},", + "phone_number = #{phoneNumber,jdbcType=VARCHAR},", + "description = #{description,jdbcType=VARCHAR},", + "create_time = #{createTime,jdbcType=TIMESTAMP},", + "update_time = #{updateTime,jdbcType=TIMESTAMP}", + "where id = #{id,jdbcType=BIGINT}" + }) + int updateByPrimaryKey(User row); +} diff --git a/backend/java/sk-matrix-service/orm/src/main/java/cn/skcks/matrix/v2/orm/mybatis/basic/model/CasbinRule.java b/backend/java/sk-matrix-service/orm/src/main/java/cn/skcks/matrix/v2/orm/mybatis/basic/model/CasbinRule.java new file mode 100644 index 0000000..2fdb84d --- /dev/null +++ b/backend/java/sk-matrix-service/orm/src/main/java/cn/skcks/matrix/v2/orm/mybatis/basic/model/CasbinRule.java @@ -0,0 +1,272 @@ +package cn.skcks.matrix.v2.orm.mybatis.basic.model; + +/** + * + * This class was generated by MyBatis Generator. + * This class corresponds to the database table casbin_rule + */ +public class CasbinRule { + /** + * + * This field was generated by MyBatis Generator. + * This field corresponds to the database column casbin_rule.id + * + * @mbg.generated + */ + private Integer id; + + /** + * + * This field was generated by MyBatis Generator. + * This field corresponds to the database column casbin_rule.ptype + * + * @mbg.generated + */ + private String ptype; + + /** + * + * This field was generated by MyBatis Generator. + * This field corresponds to the database column casbin_rule.v0 + * + * @mbg.generated + */ + private String v0; + + /** + * + * This field was generated by MyBatis Generator. + * This field corresponds to the database column casbin_rule.v1 + * + * @mbg.generated + */ + private String v1; + + /** + * + * This field was generated by MyBatis Generator. + * This field corresponds to the database column casbin_rule.v2 + * + * @mbg.generated + */ + private String v2; + + /** + * + * This field was generated by MyBatis Generator. + * This field corresponds to the database column casbin_rule.v3 + * + * @mbg.generated + */ + private String v3; + + /** + * + * This field was generated by MyBatis Generator. + * This field corresponds to the database column casbin_rule.v4 + * + * @mbg.generated + */ + private String v4; + + /** + * + * This field was generated by MyBatis Generator. + * This field corresponds to the database column casbin_rule.v5 + * + * @mbg.generated + */ + private String v5; + + /** + * This method was generated by MyBatis Generator. + * This method returns the value of the database column casbin_rule.id + * + * @return the value of casbin_rule.id + * + * @mbg.generated + */ + public Integer getId() { + return id; + } + + /** + * This method was generated by MyBatis Generator. + * This method sets the value of the database column casbin_rule.id + * + * @param id the value for casbin_rule.id + * + * @mbg.generated + */ + public void setId(Integer id) { + this.id = id; + } + + /** + * This method was generated by MyBatis Generator. + * This method returns the value of the database column casbin_rule.ptype + * + * @return the value of casbin_rule.ptype + * + * @mbg.generated + */ + public String getPtype() { + return ptype; + } + + /** + * This method was generated by MyBatis Generator. + * This method sets the value of the database column casbin_rule.ptype + * + * @param ptype the value for casbin_rule.ptype + * + * @mbg.generated + */ + public void setPtype(String ptype) { + this.ptype = ptype == null ? null : ptype.trim(); + } + + /** + * This method was generated by MyBatis Generator. + * This method returns the value of the database column casbin_rule.v0 + * + * @return the value of casbin_rule.v0 + * + * @mbg.generated + */ + public String getV0() { + return v0; + } + + /** + * This method was generated by MyBatis Generator. + * This method sets the value of the database column casbin_rule.v0 + * + * @param v0 the value for casbin_rule.v0 + * + * @mbg.generated + */ + public void setV0(String v0) { + this.v0 = v0 == null ? null : v0.trim(); + } + + /** + * This method was generated by MyBatis Generator. + * This method returns the value of the database column casbin_rule.v1 + * + * @return the value of casbin_rule.v1 + * + * @mbg.generated + */ + public String getV1() { + return v1; + } + + /** + * This method was generated by MyBatis Generator. + * This method sets the value of the database column casbin_rule.v1 + * + * @param v1 the value for casbin_rule.v1 + * + * @mbg.generated + */ + public void setV1(String v1) { + this.v1 = v1 == null ? null : v1.trim(); + } + + /** + * This method was generated by MyBatis Generator. + * This method returns the value of the database column casbin_rule.v2 + * + * @return the value of casbin_rule.v2 + * + * @mbg.generated + */ + public String getV2() { + return v2; + } + + /** + * This method was generated by MyBatis Generator. + * This method sets the value of the database column casbin_rule.v2 + * + * @param v2 the value for casbin_rule.v2 + * + * @mbg.generated + */ + public void setV2(String v2) { + this.v2 = v2 == null ? null : v2.trim(); + } + + /** + * This method was generated by MyBatis Generator. + * This method returns the value of the database column casbin_rule.v3 + * + * @return the value of casbin_rule.v3 + * + * @mbg.generated + */ + public String getV3() { + return v3; + } + + /** + * This method was generated by MyBatis Generator. + * This method sets the value of the database column casbin_rule.v3 + * + * @param v3 the value for casbin_rule.v3 + * + * @mbg.generated + */ + public void setV3(String v3) { + this.v3 = v3 == null ? null : v3.trim(); + } + + /** + * This method was generated by MyBatis Generator. + * This method returns the value of the database column casbin_rule.v4 + * + * @return the value of casbin_rule.v4 + * + * @mbg.generated + */ + public String getV4() { + return v4; + } + + /** + * This method was generated by MyBatis Generator. + * This method sets the value of the database column casbin_rule.v4 + * + * @param v4 the value for casbin_rule.v4 + * + * @mbg.generated + */ + public void setV4(String v4) { + this.v4 = v4 == null ? null : v4.trim(); + } + + /** + * This method was generated by MyBatis Generator. + * This method returns the value of the database column casbin_rule.v5 + * + * @return the value of casbin_rule.v5 + * + * @mbg.generated + */ + public String getV5() { + return v5; + } + + /** + * This method was generated by MyBatis Generator. + * This method sets the value of the database column casbin_rule.v5 + * + * @param v5 the value for casbin_rule.v5 + * + * @mbg.generated + */ + public void setV5(String v5) { + this.v5 = v5 == null ? null : v5.trim(); + } +} diff --git a/backend/java/sk-matrix-service/orm/src/main/java/cn/skcks/matrix/v2/orm/mybatis/basic/model/LocationRecord.java b/backend/java/sk-matrix-service/orm/src/main/java/cn/skcks/matrix/v2/orm/mybatis/basic/model/LocationRecord.java new file mode 100644 index 0000000..59af4ce --- /dev/null +++ b/backend/java/sk-matrix-service/orm/src/main/java/cn/skcks/matrix/v2/orm/mybatis/basic/model/LocationRecord.java @@ -0,0 +1,703 @@ +package cn.skcks.matrix.v2.orm.mybatis.basic.model; + +import java.util.Date; + +/** + * + * This class was generated by MyBatis Generator. + * This class corresponds to the database table location_record + */ +public class LocationRecord { + /** + * + * This field was generated by MyBatis Generator. + * This field corresponds to the database column location_record.id + * + * @mbg.generated + */ + private String id; + + /** + * + * This field was generated by MyBatis Generator. + * This field corresponds to the database column location_record.callback_time + * + * @mbg.generated + */ + private Date callbackTime; + + /** + * + * This field was generated by MyBatis Generator. + * This field corresponds to the database column location_record.location_time + * + * @mbg.generated + */ + private Date locationTime; + + /** + * + * This field was generated by MyBatis Generator. + * This field corresponds to the database column location_record.location_type + * + * @mbg.generated + */ + private Integer locationType; + + /** + * + * This field was generated by MyBatis Generator. + * This field corresponds to the database column location_record.latitude + * + * @mbg.generated + */ + private Double latitude; + + /** + * + * This field was generated by MyBatis Generator. + * This field corresponds to the database column location_record.longitude + * + * @mbg.generated + */ + private Double longitude; + + /** + * + * This field was generated by MyBatis Generator. + * This field corresponds to the database column location_record.accuracy + * + * @mbg.generated + */ + private Double accuracy; + + /** + * + * This field was generated by MyBatis Generator. + * This field corresponds to the database column location_record.altitude + * + * @mbg.generated + */ + private Double altitude; + + /** + * + * This field was generated by MyBatis Generator. + * This field corresponds to the database column location_record.bearing + * + * @mbg.generated + */ + private Double bearing; + + /** + * + * This field was generated by MyBatis Generator. + * This field corresponds to the database column location_record.speed + * + * @mbg.generated + */ + private Double speed; + + /** + * + * This field was generated by MyBatis Generator. + * This field corresponds to the database column location_record.country + * + * @mbg.generated + */ + private String country; + + /** + * + * This field was generated by MyBatis Generator. + * This field corresponds to the database column location_record.province + * + * @mbg.generated + */ + private String province; + + /** + * + * This field was generated by MyBatis Generator. + * This field corresponds to the database column location_record.city + * + * @mbg.generated + */ + private String city; + + /** + * + * This field was generated by MyBatis Generator. + * This field corresponds to the database column location_record.district + * + * @mbg.generated + */ + private String district; + + /** + * + * This field was generated by MyBatis Generator. + * This field corresponds to the database column location_record.street + * + * @mbg.generated + */ + private String street; + + /** + * + * This field was generated by MyBatis Generator. + * This field corresponds to the database column location_record.street_number + * + * @mbg.generated + */ + private String streetNumber; + + /** + * + * This field was generated by MyBatis Generator. + * This field corresponds to the database column location_record.city_code + * + * @mbg.generated + */ + private String cityCode; + + /** + * + * This field was generated by MyBatis Generator. + * This field corresponds to the database column location_record.ad_code + * + * @mbg.generated + */ + private String adCode; + + /** + * + * This field was generated by MyBatis Generator. + * This field corresponds to the database column location_record.address + * + * @mbg.generated + */ + private String address; + + /** + * + * This field was generated by MyBatis Generator. + * This field corresponds to the database column location_record.description + * + * @mbg.generated + */ + private String description; + + /** + * + * This field was generated by MyBatis Generator. + * This field corresponds to the database column location_record.user_id + * + * @mbg.generated + */ + private Long userId; + + /** + * This method was generated by MyBatis Generator. + * This method returns the value of the database column location_record.id + * + * @return the value of location_record.id + * + * @mbg.generated + */ + public String getId() { + return id; + } + + /** + * This method was generated by MyBatis Generator. + * This method sets the value of the database column location_record.id + * + * @param id the value for location_record.id + * + * @mbg.generated + */ + public void setId(String id) { + this.id = id == null ? null : id.trim(); + } + + /** + * This method was generated by MyBatis Generator. + * This method returns the value of the database column location_record.callback_time + * + * @return the value of location_record.callback_time + * + * @mbg.generated + */ + public Date getCallbackTime() { + return callbackTime; + } + + /** + * This method was generated by MyBatis Generator. + * This method sets the value of the database column location_record.callback_time + * + * @param callbackTime the value for location_record.callback_time + * + * @mbg.generated + */ + public void setCallbackTime(Date callbackTime) { + this.callbackTime = callbackTime; + } + + /** + * This method was generated by MyBatis Generator. + * This method returns the value of the database column location_record.location_time + * + * @return the value of location_record.location_time + * + * @mbg.generated + */ + public Date getLocationTime() { + return locationTime; + } + + /** + * This method was generated by MyBatis Generator. + * This method sets the value of the database column location_record.location_time + * + * @param locationTime the value for location_record.location_time + * + * @mbg.generated + */ + public void setLocationTime(Date locationTime) { + this.locationTime = locationTime; + } + + /** + * This method was generated by MyBatis Generator. + * This method returns the value of the database column location_record.location_type + * + * @return the value of location_record.location_type + * + * @mbg.generated + */ + public Integer getLocationType() { + return locationType; + } + + /** + * This method was generated by MyBatis Generator. + * This method sets the value of the database column location_record.location_type + * + * @param locationType the value for location_record.location_type + * + * @mbg.generated + */ + public void setLocationType(Integer locationType) { + this.locationType = locationType; + } + + /** + * This method was generated by MyBatis Generator. + * This method returns the value of the database column location_record.latitude + * + * @return the value of location_record.latitude + * + * @mbg.generated + */ + public Double getLatitude() { + return latitude; + } + + /** + * This method was generated by MyBatis Generator. + * This method sets the value of the database column location_record.latitude + * + * @param latitude the value for location_record.latitude + * + * @mbg.generated + */ + public void setLatitude(Double latitude) { + this.latitude = latitude; + } + + /** + * This method was generated by MyBatis Generator. + * This method returns the value of the database column location_record.longitude + * + * @return the value of location_record.longitude + * + * @mbg.generated + */ + public Double getLongitude() { + return longitude; + } + + /** + * This method was generated by MyBatis Generator. + * This method sets the value of the database column location_record.longitude + * + * @param longitude the value for location_record.longitude + * + * @mbg.generated + */ + public void setLongitude(Double longitude) { + this.longitude = longitude; + } + + /** + * This method was generated by MyBatis Generator. + * This method returns the value of the database column location_record.accuracy + * + * @return the value of location_record.accuracy + * + * @mbg.generated + */ + public Double getAccuracy() { + return accuracy; + } + + /** + * This method was generated by MyBatis Generator. + * This method sets the value of the database column location_record.accuracy + * + * @param accuracy the value for location_record.accuracy + * + * @mbg.generated + */ + public void setAccuracy(Double accuracy) { + this.accuracy = accuracy; + } + + /** + * This method was generated by MyBatis Generator. + * This method returns the value of the database column location_record.altitude + * + * @return the value of location_record.altitude + * + * @mbg.generated + */ + public Double getAltitude() { + return altitude; + } + + /** + * This method was generated by MyBatis Generator. + * This method sets the value of the database column location_record.altitude + * + * @param altitude the value for location_record.altitude + * + * @mbg.generated + */ + public void setAltitude(Double altitude) { + this.altitude = altitude; + } + + /** + * This method was generated by MyBatis Generator. + * This method returns the value of the database column location_record.bearing + * + * @return the value of location_record.bearing + * + * @mbg.generated + */ + public Double getBearing() { + return bearing; + } + + /** + * This method was generated by MyBatis Generator. + * This method sets the value of the database column location_record.bearing + * + * @param bearing the value for location_record.bearing + * + * @mbg.generated + */ + public void setBearing(Double bearing) { + this.bearing = bearing; + } + + /** + * This method was generated by MyBatis Generator. + * This method returns the value of the database column location_record.speed + * + * @return the value of location_record.speed + * + * @mbg.generated + */ + public Double getSpeed() { + return speed; + } + + /** + * This method was generated by MyBatis Generator. + * This method sets the value of the database column location_record.speed + * + * @param speed the value for location_record.speed + * + * @mbg.generated + */ + public void setSpeed(Double speed) { + this.speed = speed; + } + + /** + * This method was generated by MyBatis Generator. + * This method returns the value of the database column location_record.country + * + * @return the value of location_record.country + * + * @mbg.generated + */ + public String getCountry() { + return country; + } + + /** + * This method was generated by MyBatis Generator. + * This method sets the value of the database column location_record.country + * + * @param country the value for location_record.country + * + * @mbg.generated + */ + public void setCountry(String country) { + this.country = country == null ? null : country.trim(); + } + + /** + * This method was generated by MyBatis Generator. + * This method returns the value of the database column location_record.province + * + * @return the value of location_record.province + * + * @mbg.generated + */ + public String getProvince() { + return province; + } + + /** + * This method was generated by MyBatis Generator. + * This method sets the value of the database column location_record.province + * + * @param province the value for location_record.province + * + * @mbg.generated + */ + public void setProvince(String province) { + this.province = province == null ? null : province.trim(); + } + + /** + * This method was generated by MyBatis Generator. + * This method returns the value of the database column location_record.city + * + * @return the value of location_record.city + * + * @mbg.generated + */ + public String getCity() { + return city; + } + + /** + * This method was generated by MyBatis Generator. + * This method sets the value of the database column location_record.city + * + * @param city the value for location_record.city + * + * @mbg.generated + */ + public void setCity(String city) { + this.city = city == null ? null : city.trim(); + } + + /** + * This method was generated by MyBatis Generator. + * This method returns the value of the database column location_record.district + * + * @return the value of location_record.district + * + * @mbg.generated + */ + public String getDistrict() { + return district; + } + + /** + * This method was generated by MyBatis Generator. + * This method sets the value of the database column location_record.district + * + * @param district the value for location_record.district + * + * @mbg.generated + */ + public void setDistrict(String district) { + this.district = district == null ? null : district.trim(); + } + + /** + * This method was generated by MyBatis Generator. + * This method returns the value of the database column location_record.street + * + * @return the value of location_record.street + * + * @mbg.generated + */ + public String getStreet() { + return street; + } + + /** + * This method was generated by MyBatis Generator. + * This method sets the value of the database column location_record.street + * + * @param street the value for location_record.street + * + * @mbg.generated + */ + public void setStreet(String street) { + this.street = street == null ? null : street.trim(); + } + + /** + * This method was generated by MyBatis Generator. + * This method returns the value of the database column location_record.street_number + * + * @return the value of location_record.street_number + * + * @mbg.generated + */ + public String getStreetNumber() { + return streetNumber; + } + + /** + * This method was generated by MyBatis Generator. + * This method sets the value of the database column location_record.street_number + * + * @param streetNumber the value for location_record.street_number + * + * @mbg.generated + */ + public void setStreetNumber(String streetNumber) { + this.streetNumber = streetNumber == null ? null : streetNumber.trim(); + } + + /** + * This method was generated by MyBatis Generator. + * This method returns the value of the database column location_record.city_code + * + * @return the value of location_record.city_code + * + * @mbg.generated + */ + public String getCityCode() { + return cityCode; + } + + /** + * This method was generated by MyBatis Generator. + * This method sets the value of the database column location_record.city_code + * + * @param cityCode the value for location_record.city_code + * + * @mbg.generated + */ + public void setCityCode(String cityCode) { + this.cityCode = cityCode == null ? null : cityCode.trim(); + } + + /** + * This method was generated by MyBatis Generator. + * This method returns the value of the database column location_record.ad_code + * + * @return the value of location_record.ad_code + * + * @mbg.generated + */ + public String getAdCode() { + return adCode; + } + + /** + * This method was generated by MyBatis Generator. + * This method sets the value of the database column location_record.ad_code + * + * @param adCode the value for location_record.ad_code + * + * @mbg.generated + */ + public void setAdCode(String adCode) { + this.adCode = adCode == null ? null : adCode.trim(); + } + + /** + * This method was generated by MyBatis Generator. + * This method returns the value of the database column location_record.address + * + * @return the value of location_record.address + * + * @mbg.generated + */ + public String getAddress() { + return address; + } + + /** + * This method was generated by MyBatis Generator. + * This method sets the value of the database column location_record.address + * + * @param address the value for location_record.address + * + * @mbg.generated + */ + public void setAddress(String address) { + this.address = address == null ? null : address.trim(); + } + + /** + * This method was generated by MyBatis Generator. + * This method returns the value of the database column location_record.description + * + * @return the value of location_record.description + * + * @mbg.generated + */ + public String getDescription() { + return description; + } + + /** + * This method was generated by MyBatis Generator. + * This method sets the value of the database column location_record.description + * + * @param description the value for location_record.description + * + * @mbg.generated + */ + public void setDescription(String description) { + this.description = description == null ? null : description.trim(); + } + + /** + * This method was generated by MyBatis Generator. + * This method returns the value of the database column location_record.user_id + * + * @return the value of location_record.user_id + * + * @mbg.generated + */ + public Long getUserId() { + return userId; + } + + /** + * This method was generated by MyBatis Generator. + * This method sets the value of the database column location_record.user_id + * + * @param userId the value for location_record.user_id + * + * @mbg.generated + */ + public void setUserId(Long userId) { + this.userId = userId; + } +} diff --git a/backend/java/sk-matrix-service/orm/src/main/java/cn/skcks/matrix/v2/orm/mybatis/basic/model/Role.java b/backend/java/sk-matrix-service/orm/src/main/java/cn/skcks/matrix/v2/orm/mybatis/basic/model/Role.java new file mode 100644 index 0000000..6303617 --- /dev/null +++ b/backend/java/sk-matrix-service/orm/src/main/java/cn/skcks/matrix/v2/orm/mybatis/basic/model/Role.java @@ -0,0 +1,179 @@ +package cn.skcks.matrix.v2.orm.mybatis.basic.model; + +/** + * + * This class was generated by MyBatis Generator. + * This class corresponds to the database table role + */ +public class Role { + /** + * + * This field was generated by MyBatis Generator. + * This field corresponds to the database column role.id + * + * @mbg.generated + */ + private Long id; + + /** + * Database Column Remarks: + * 角色 + * + * This field was generated by MyBatis Generator. + * This field corresponds to the database column role.role + * + * @mbg.generated + */ + private String role; + + /** + * Database Column Remarks: + * 角色名 + * + * This field was generated by MyBatis Generator. + * This field corresponds to the database column role.name + * + * @mbg.generated + */ + private String name; + + /** + * Database Column Remarks: + * 所属系统 + * + * This field was generated by MyBatis Generator. + * This field corresponds to the database column role.system_id + * + * @mbg.generated + */ + private String systemId; + + /** + * + * This field was generated by MyBatis Generator. + * This field corresponds to the database column role.active + * + * @mbg.generated + */ + private Boolean active; + + /** + * This method was generated by MyBatis Generator. + * This method returns the value of the database column role.id + * + * @return the value of role.id + * + * @mbg.generated + */ + public Long getId() { + return id; + } + + /** + * This method was generated by MyBatis Generator. + * This method sets the value of the database column role.id + * + * @param id the value for role.id + * + * @mbg.generated + */ + public void setId(Long id) { + this.id = id; + } + + /** + * This method was generated by MyBatis Generator. + * This method returns the value of the database column role.role + * + * @return the value of role.role + * + * @mbg.generated + */ + public String getRole() { + return role; + } + + /** + * This method was generated by MyBatis Generator. + * This method sets the value of the database column role.role + * + * @param role the value for role.role + * + * @mbg.generated + */ + public void setRole(String role) { + this.role = role == null ? null : role.trim(); + } + + /** + * This method was generated by MyBatis Generator. + * This method returns the value of the database column role.name + * + * @return the value of role.name + * + * @mbg.generated + */ + public String getName() { + return name; + } + + /** + * This method was generated by MyBatis Generator. + * This method sets the value of the database column role.name + * + * @param name the value for role.name + * + * @mbg.generated + */ + public void setName(String name) { + this.name = name == null ? null : name.trim(); + } + + /** + * This method was generated by MyBatis Generator. + * This method returns the value of the database column role.system_id + * + * @return the value of role.system_id + * + * @mbg.generated + */ + public String getSystemId() { + return systemId; + } + + /** + * This method was generated by MyBatis Generator. + * This method sets the value of the database column role.system_id + * + * @param systemId the value for role.system_id + * + * @mbg.generated + */ + public void setSystemId(String systemId) { + this.systemId = systemId == null ? null : systemId.trim(); + } + + /** + * This method was generated by MyBatis Generator. + * This method returns the value of the database column role.active + * + * @return the value of role.active + * + * @mbg.generated + */ + public Boolean getActive() { + return active; + } + + /** + * This method was generated by MyBatis Generator. + * This method sets the value of the database column role.active + * + * @param active the value for role.active + * + * @mbg.generated + */ + public void setActive(Boolean active) { + this.active = active; + } +} diff --git a/backend/java/sk-matrix-service/orm/src/main/java/cn/skcks/matrix/v2/orm/mybatis/basic/model/User.java b/backend/java/sk-matrix-service/orm/src/main/java/cn/skcks/matrix/v2/orm/mybatis/basic/model/User.java new file mode 100644 index 0000000..0953b3b --- /dev/null +++ b/backend/java/sk-matrix-service/orm/src/main/java/cn/skcks/matrix/v2/orm/mybatis/basic/model/User.java @@ -0,0 +1,311 @@ +package cn.skcks.matrix.v2.orm.mybatis.basic.model; + +import java.util.Date; + +/** + * + * This class was generated by MyBatis Generator. + * This class corresponds to the database table user + */ +public class User { + /** + * + * This field was generated by MyBatis Generator. + * This field corresponds to the database column user.id + * + * @mbg.generated + */ + private Long id; + + /** + * + * This field was generated by MyBatis Generator. + * This field corresponds to the database column user.user_name + * + * @mbg.generated + */ + private String userName; + + /** + * Database Column Remarks: + * 加密后的密码 + * + * This field was generated by MyBatis Generator. + * This field corresponds to the database column user.password + * + * @mbg.generated + */ + private String password; + + /** + * Database Column Remarks: + * 加密密钥 + * + * This field was generated by MyBatis Generator. + * This field corresponds to the database column user.salt + * + * @mbg.generated + */ + private String salt; + + /** + * + * This field was generated by MyBatis Generator. + * This field corresponds to the database column user.email + * + * @mbg.generated + */ + private String email; + + /** + * + * This field was generated by MyBatis Generator. + * This field corresponds to the database column user.phone_number + * + * @mbg.generated + */ + private String phoneNumber; + + /** + * + * This field was generated by MyBatis Generator. + * This field corresponds to the database column user.description + * + * @mbg.generated + */ + private String description; + + /** + * + * This field was generated by MyBatis Generator. + * This field corresponds to the database column user.create_time + * + * @mbg.generated + */ + private Date createTime; + + /** + * + * This field was generated by MyBatis Generator. + * This field corresponds to the database column user.update_time + * + * @mbg.generated + */ + private Date updateTime; + + /** + * This method was generated by MyBatis Generator. + * This method returns the value of the database column user.id + * + * @return the value of user.id + * + * @mbg.generated + */ + public Long getId() { + return id; + } + + /** + * This method was generated by MyBatis Generator. + * This method sets the value of the database column user.id + * + * @param id the value for user.id + * + * @mbg.generated + */ + public void setId(Long id) { + this.id = id; + } + + /** + * This method was generated by MyBatis Generator. + * This method returns the value of the database column user.user_name + * + * @return the value of user.user_name + * + * @mbg.generated + */ + public String getUserName() { + return userName; + } + + /** + * This method was generated by MyBatis Generator. + * This method sets the value of the database column user.user_name + * + * @param userName the value for user.user_name + * + * @mbg.generated + */ + public void setUserName(String userName) { + this.userName = userName == null ? null : userName.trim(); + } + + /** + * This method was generated by MyBatis Generator. + * This method returns the value of the database column user.password + * + * @return the value of user.password + * + * @mbg.generated + */ + public String getPassword() { + return password; + } + + /** + * This method was generated by MyBatis Generator. + * This method sets the value of the database column user.password + * + * @param password the value for user.password + * + * @mbg.generated + */ + public void setPassword(String password) { + this.password = password == null ? null : password.trim(); + } + + /** + * This method was generated by MyBatis Generator. + * This method returns the value of the database column user.salt + * + * @return the value of user.salt + * + * @mbg.generated + */ + public String getSalt() { + return salt; + } + + /** + * This method was generated by MyBatis Generator. + * This method sets the value of the database column user.salt + * + * @param salt the value for user.salt + * + * @mbg.generated + */ + public void setSalt(String salt) { + this.salt = salt == null ? null : salt.trim(); + } + + /** + * This method was generated by MyBatis Generator. + * This method returns the value of the database column user.email + * + * @return the value of user.email + * + * @mbg.generated + */ + public String getEmail() { + return email; + } + + /** + * This method was generated by MyBatis Generator. + * This method sets the value of the database column user.email + * + * @param email the value for user.email + * + * @mbg.generated + */ + public void setEmail(String email) { + this.email = email == null ? null : email.trim(); + } + + /** + * This method was generated by MyBatis Generator. + * This method returns the value of the database column user.phone_number + * + * @return the value of user.phone_number + * + * @mbg.generated + */ + public String getPhoneNumber() { + return phoneNumber; + } + + /** + * This method was generated by MyBatis Generator. + * This method sets the value of the database column user.phone_number + * + * @param phoneNumber the value for user.phone_number + * + * @mbg.generated + */ + public void setPhoneNumber(String phoneNumber) { + this.phoneNumber = phoneNumber == null ? null : phoneNumber.trim(); + } + + /** + * This method was generated by MyBatis Generator. + * This method returns the value of the database column user.description + * + * @return the value of user.description + * + * @mbg.generated + */ + public String getDescription() { + return description; + } + + /** + * This method was generated by MyBatis Generator. + * This method sets the value of the database column user.description + * + * @param description the value for user.description + * + * @mbg.generated + */ + public void setDescription(String description) { + this.description = description == null ? null : description.trim(); + } + + /** + * This method was generated by MyBatis Generator. + * This method returns the value of the database column user.create_time + * + * @return the value of user.create_time + * + * @mbg.generated + */ + public Date getCreateTime() { + return createTime; + } + + /** + * This method was generated by MyBatis Generator. + * This method sets the value of the database column user.create_time + * + * @param createTime the value for user.create_time + * + * @mbg.generated + */ + public void setCreateTime(Date createTime) { + this.createTime = createTime; + } + + /** + * This method was generated by MyBatis Generator. + * This method returns the value of the database column user.update_time + * + * @return the value of user.update_time + * + * @mbg.generated + */ + public Date getUpdateTime() { + return updateTime; + } + + /** + * This method was generated by MyBatis Generator. + * This method sets the value of the database column user.update_time + * + * @param updateTime the value for user.update_time + * + * @mbg.generated + */ + public void setUpdateTime(Date updateTime) { + this.updateTime = updateTime; + } +} diff --git a/backend/java/sk-matrix-service/orm/src/main/java/cn/skcks/matrix/v2/orm/mybatis/dynamic/mapper/CasbinRuleDynamicSqlSupport.java b/backend/java/sk-matrix-service/orm/src/main/java/cn/skcks/matrix/v2/orm/mybatis/dynamic/mapper/CasbinRuleDynamicSqlSupport.java new file mode 100644 index 0000000..3feacc9 --- /dev/null +++ b/backend/java/sk-matrix-service/orm/src/main/java/cn/skcks/matrix/v2/orm/mybatis/dynamic/mapper/CasbinRuleDynamicSqlSupport.java @@ -0,0 +1,58 @@ +package cn.skcks.matrix.v2.orm.mybatis.dynamic.mapper; + +import java.sql.JDBCType; +import javax.annotation.Generated; +import org.mybatis.dynamic.sql.AliasableSqlTable; +import org.mybatis.dynamic.sql.SqlColumn; + +public final class CasbinRuleDynamicSqlSupport { + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: casbin_rule") + public static final CasbinRule casbinRule = new CasbinRule(); + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: casbin_rule.id") + public static final SqlColumn id = casbinRule.id; + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: casbin_rule.ptype") + public static final SqlColumn ptype = casbinRule.ptype; + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: casbin_rule.v0") + public static final SqlColumn v0 = casbinRule.v0; + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: casbin_rule.v1") + public static final SqlColumn v1 = casbinRule.v1; + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: casbin_rule.v2") + public static final SqlColumn v2 = casbinRule.v2; + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: casbin_rule.v3") + public static final SqlColumn v3 = casbinRule.v3; + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: casbin_rule.v4") + public static final SqlColumn v4 = casbinRule.v4; + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: casbin_rule.v5") + public static final SqlColumn v5 = casbinRule.v5; + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: casbin_rule") + public static final class CasbinRule extends AliasableSqlTable { + public final SqlColumn id = column("id", JDBCType.INTEGER); + + public final SqlColumn ptype = column("ptype", JDBCType.VARCHAR); + + public final SqlColumn v0 = column("v0", JDBCType.VARCHAR); + + public final SqlColumn v1 = column("v1", JDBCType.VARCHAR); + + public final SqlColumn v2 = column("v2", JDBCType.VARCHAR); + + public final SqlColumn v3 = column("v3", JDBCType.VARCHAR); + + public final SqlColumn v4 = column("v4", JDBCType.VARCHAR); + + public final SqlColumn v5 = column("v5", JDBCType.VARCHAR); + + public CasbinRule() { + super("casbin_rule", CasbinRule::new); + } + } +} diff --git a/backend/java/sk-matrix-service/orm/src/main/java/cn/skcks/matrix/v2/orm/mybatis/dynamic/mapper/CasbinRuleMapper.java b/backend/java/sk-matrix-service/orm/src/main/java/cn/skcks/matrix/v2/orm/mybatis/dynamic/mapper/CasbinRuleMapper.java new file mode 100644 index 0000000..6e796c8 --- /dev/null +++ b/backend/java/sk-matrix-service/orm/src/main/java/cn/skcks/matrix/v2/orm/mybatis/dynamic/mapper/CasbinRuleMapper.java @@ -0,0 +1,195 @@ +package cn.skcks.matrix.v2.orm.mybatis.dynamic.mapper; + +import static cn.skcks.matrix.v2.orm.mybatis.dynamic.mapper.CasbinRuleDynamicSqlSupport.*; +import static org.mybatis.dynamic.sql.SqlBuilder.isEqualTo; + +import cn.skcks.matrix.v2.orm.mybatis.dynamic.model.CasbinRule; + +import java.util.Collection; +import java.util.List; +import java.util.Optional; +import javax.annotation.Generated; + +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Result; +import org.apache.ibatis.annotations.ResultMap; +import org.apache.ibatis.annotations.Results; +import org.apache.ibatis.annotations.SelectProvider; +import org.apache.ibatis.type.JdbcType; +import org.mybatis.dynamic.sql.BasicColumn; +import org.mybatis.dynamic.sql.delete.DeleteDSLCompleter; +import org.mybatis.dynamic.sql.select.CountDSLCompleter; +import org.mybatis.dynamic.sql.select.SelectDSLCompleter; +import org.mybatis.dynamic.sql.select.render.SelectStatementProvider; +import org.mybatis.dynamic.sql.update.UpdateDSL; +import org.mybatis.dynamic.sql.update.UpdateDSLCompleter; +import org.mybatis.dynamic.sql.update.UpdateModel; +import org.mybatis.dynamic.sql.util.SqlProviderAdapter; +import org.mybatis.dynamic.sql.util.mybatis3.CommonCountMapper; +import org.mybatis.dynamic.sql.util.mybatis3.CommonDeleteMapper; +import org.mybatis.dynamic.sql.util.mybatis3.CommonInsertMapper; +import org.mybatis.dynamic.sql.util.mybatis3.CommonUpdateMapper; +import org.mybatis.dynamic.sql.util.mybatis3.MyBatis3Utils; + +@Mapper +public interface CasbinRuleMapper extends CommonCountMapper, CommonDeleteMapper, CommonInsertMapper, CommonUpdateMapper { + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: casbin_rule") + BasicColumn[] selectList = BasicColumn.columnList(id, ptype, v0, v1, v2, v3, v4, v5); + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: casbin_rule") + @SelectProvider(type=SqlProviderAdapter.class, method="select") + @Results(id="CasbinRuleResult", value = { + @Result(column="id", property="id", jdbcType=JdbcType.INTEGER, id=true), + @Result(column="ptype", property="ptype", jdbcType=JdbcType.VARCHAR), + @Result(column="v0", property="v0", jdbcType=JdbcType.VARCHAR), + @Result(column="v1", property="v1", jdbcType=JdbcType.VARCHAR), + @Result(column="v2", property="v2", jdbcType=JdbcType.VARCHAR), + @Result(column="v3", property="v3", jdbcType=JdbcType.VARCHAR), + @Result(column="v4", property="v4", jdbcType=JdbcType.VARCHAR), + @Result(column="v5", property="v5", jdbcType=JdbcType.VARCHAR) + }) + List selectMany(SelectStatementProvider selectStatement); + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: casbin_rule") + @SelectProvider(type=SqlProviderAdapter.class, method="select") + @ResultMap("CasbinRuleResult") + Optional selectOne(SelectStatementProvider selectStatement); + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: casbin_rule") + default long count(CountDSLCompleter completer) { + return MyBatis3Utils.countFrom(this::count, casbinRule, completer); + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: casbin_rule") + default int delete(DeleteDSLCompleter completer) { + return MyBatis3Utils.deleteFrom(this::delete, casbinRule, completer); + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: casbin_rule") + default int deleteByPrimaryKey(Integer id_) { + return delete(c -> + c.where(id, isEqualTo(id_)) + ); + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: casbin_rule") + default int insert(CasbinRule row) { + return MyBatis3Utils.insert(this::insert, row, casbinRule, c -> + c.map(id).toProperty("id") + .map(ptype).toProperty("ptype") + .map(v0).toProperty("v0") + .map(v1).toProperty("v1") + .map(v2).toProperty("v2") + .map(v3).toProperty("v3") + .map(v4).toProperty("v4") + .map(v5).toProperty("v5") + ); + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: casbin_rule") + default int insertMultiple(Collection records) { + return MyBatis3Utils.insertMultiple(this::insertMultiple, records, casbinRule, c -> + c.map(id).toProperty("id") + .map(ptype).toProperty("ptype") + .map(v0).toProperty("v0") + .map(v1).toProperty("v1") + .map(v2).toProperty("v2") + .map(v3).toProperty("v3") + .map(v4).toProperty("v4") + .map(v5).toProperty("v5") + ); + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: casbin_rule") + default int insertSelective(CasbinRule row) { + return MyBatis3Utils.insert(this::insert, row, casbinRule, c -> + c.map(id).toPropertyWhenPresent("id", row::getId) + .map(ptype).toPropertyWhenPresent("ptype", row::getPtype) + .map(v0).toPropertyWhenPresent("v0", row::getV0) + .map(v1).toPropertyWhenPresent("v1", row::getV1) + .map(v2).toPropertyWhenPresent("v2", row::getV2) + .map(v3).toPropertyWhenPresent("v3", row::getV3) + .map(v4).toPropertyWhenPresent("v4", row::getV4) + .map(v5).toPropertyWhenPresent("v5", row::getV5) + ); + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: casbin_rule") + default Optional selectOne(SelectDSLCompleter completer) { + return MyBatis3Utils.selectOne(this::selectOne, selectList, casbinRule, completer); + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: casbin_rule") + default List select(SelectDSLCompleter completer) { + return MyBatis3Utils.selectList(this::selectMany, selectList, casbinRule, completer); + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: casbin_rule") + default List selectDistinct(SelectDSLCompleter completer) { + return MyBatis3Utils.selectDistinct(this::selectMany, selectList, casbinRule, completer); + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: casbin_rule") + default Optional selectByPrimaryKey(Integer id_) { + return selectOne(c -> + c.where(id, isEqualTo(id_)) + ); + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: casbin_rule") + default int update(UpdateDSLCompleter completer) { + return MyBatis3Utils.update(this::update, casbinRule, completer); + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: casbin_rule") + static UpdateDSL updateAllColumns(CasbinRule row, UpdateDSL dsl) { + return dsl.set(id).equalTo(row::getId) + .set(ptype).equalTo(row::getPtype) + .set(v0).equalTo(row::getV0) + .set(v1).equalTo(row::getV1) + .set(v2).equalTo(row::getV2) + .set(v3).equalTo(row::getV3) + .set(v4).equalTo(row::getV4) + .set(v5).equalTo(row::getV5); + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: casbin_rule") + static UpdateDSL updateSelectiveColumns(CasbinRule row, UpdateDSL dsl) { + return dsl.set(id).equalToWhenPresent(row::getId) + .set(ptype).equalToWhenPresent(row::getPtype) + .set(v0).equalToWhenPresent(row::getV0) + .set(v1).equalToWhenPresent(row::getV1) + .set(v2).equalToWhenPresent(row::getV2) + .set(v3).equalToWhenPresent(row::getV3) + .set(v4).equalToWhenPresent(row::getV4) + .set(v5).equalToWhenPresent(row::getV5); + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: casbin_rule") + default int updateByPrimaryKey(CasbinRule row) { + return update(c -> + c.set(ptype).equalTo(row::getPtype) + .set(v0).equalTo(row::getV0) + .set(v1).equalTo(row::getV1) + .set(v2).equalTo(row::getV2) + .set(v3).equalTo(row::getV3) + .set(v4).equalTo(row::getV4) + .set(v5).equalTo(row::getV5) + .where(id, isEqualTo(row::getId)) + ); + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: casbin_rule") + default int updateByPrimaryKeySelective(CasbinRule row) { + return update(c -> + c.set(ptype).equalToWhenPresent(row::getPtype) + .set(v0).equalToWhenPresent(row::getV0) + .set(v1).equalToWhenPresent(row::getV1) + .set(v2).equalToWhenPresent(row::getV2) + .set(v3).equalToWhenPresent(row::getV3) + .set(v4).equalToWhenPresent(row::getV4) + .set(v5).equalToWhenPresent(row::getV5) + .where(id, isEqualTo(row::getId)) + ); + } +} diff --git a/backend/java/sk-matrix-service/orm/src/main/java/cn/skcks/matrix/v2/orm/mybatis/dynamic/mapper/LocationRecordDynamicSqlSupport.java b/backend/java/sk-matrix-service/orm/src/main/java/cn/skcks/matrix/v2/orm/mybatis/dynamic/mapper/LocationRecordDynamicSqlSupport.java new file mode 100644 index 0000000..eeac13a --- /dev/null +++ b/backend/java/sk-matrix-service/orm/src/main/java/cn/skcks/matrix/v2/orm/mybatis/dynamic/mapper/LocationRecordDynamicSqlSupport.java @@ -0,0 +1,124 @@ +package cn.skcks.matrix.v2.orm.mybatis.dynamic.mapper; + +import java.sql.JDBCType; +import java.util.Date; +import javax.annotation.Generated; +import org.mybatis.dynamic.sql.AliasableSqlTable; +import org.mybatis.dynamic.sql.SqlColumn; + +public final class LocationRecordDynamicSqlSupport { + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: location_record") + public static final LocationRecord locationRecord = new LocationRecord(); + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: location_record.id") + public static final SqlColumn id = locationRecord.id; + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: location_record.callback_time") + public static final SqlColumn callbackTime = locationRecord.callbackTime; + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: location_record.location_time") + public static final SqlColumn locationTime = locationRecord.locationTime; + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: location_record.location_type") + public static final SqlColumn locationType = locationRecord.locationType; + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: location_record.latitude") + public static final SqlColumn latitude = locationRecord.latitude; + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: location_record.longitude") + public static final SqlColumn longitude = locationRecord.longitude; + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: location_record.accuracy") + public static final SqlColumn accuracy = locationRecord.accuracy; + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: location_record.altitude") + public static final SqlColumn altitude = locationRecord.altitude; + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: location_record.bearing") + public static final SqlColumn bearing = locationRecord.bearing; + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: location_record.speed") + public static final SqlColumn speed = locationRecord.speed; + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: location_record.country") + public static final SqlColumn country = locationRecord.country; + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: location_record.province") + public static final SqlColumn province = locationRecord.province; + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: location_record.city") + public static final SqlColumn city = locationRecord.city; + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: location_record.district") + public static final SqlColumn district = locationRecord.district; + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: location_record.street") + public static final SqlColumn street = locationRecord.street; + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: location_record.street_number") + public static final SqlColumn streetNumber = locationRecord.streetNumber; + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: location_record.city_code") + public static final SqlColumn cityCode = locationRecord.cityCode; + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: location_record.ad_code") + public static final SqlColumn adCode = locationRecord.adCode; + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: location_record.address") + public static final SqlColumn address = locationRecord.address; + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: location_record.description") + public static final SqlColumn description = locationRecord.description; + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: location_record.user_id") + public static final SqlColumn userId = locationRecord.userId; + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: location_record") + public static final class LocationRecord extends AliasableSqlTable { + public final SqlColumn id = column("id", JDBCType.VARCHAR); + + public final SqlColumn callbackTime = column("callback_time", JDBCType.TIMESTAMP); + + public final SqlColumn locationTime = column("location_time", JDBCType.TIMESTAMP); + + public final SqlColumn locationType = column("location_type", JDBCType.INTEGER); + + public final SqlColumn latitude = column("latitude", JDBCType.DOUBLE); + + public final SqlColumn longitude = column("longitude", JDBCType.DOUBLE); + + public final SqlColumn accuracy = column("accuracy", JDBCType.DOUBLE); + + public final SqlColumn altitude = column("altitude", JDBCType.DOUBLE); + + public final SqlColumn bearing = column("bearing", JDBCType.DOUBLE); + + public final SqlColumn speed = column("speed", JDBCType.DOUBLE); + + public final SqlColumn country = column("country", JDBCType.VARCHAR); + + public final SqlColumn province = column("province", JDBCType.VARCHAR); + + public final SqlColumn city = column("city", JDBCType.VARCHAR); + + public final SqlColumn district = column("district", JDBCType.VARCHAR); + + public final SqlColumn street = column("street", JDBCType.VARCHAR); + + public final SqlColumn streetNumber = column("street_number", JDBCType.VARCHAR); + + public final SqlColumn cityCode = column("city_code", JDBCType.VARCHAR); + + public final SqlColumn adCode = column("ad_code", JDBCType.VARCHAR); + + public final SqlColumn address = column("address", JDBCType.VARCHAR); + + public final SqlColumn description = column("description", JDBCType.VARCHAR); + + public final SqlColumn userId = column("user_id", JDBCType.BIGINT); + + public LocationRecord() { + super("location_record", LocationRecord::new); + } + } +} diff --git a/backend/java/sk-matrix-service/orm/src/main/java/cn/skcks/matrix/v2/orm/mybatis/dynamic/mapper/LocationRecordMapper.java b/backend/java/sk-matrix-service/orm/src/main/java/cn/skcks/matrix/v2/orm/mybatis/dynamic/mapper/LocationRecordMapper.java new file mode 100644 index 0000000..8641a94 --- /dev/null +++ b/backend/java/sk-matrix-service/orm/src/main/java/cn/skcks/matrix/v2/orm/mybatis/dynamic/mapper/LocationRecordMapper.java @@ -0,0 +1,298 @@ +package cn.skcks.matrix.v2.orm.mybatis.dynamic.mapper; + +import static org.mybatis.dynamic.sql.SqlBuilder.isEqualTo; + +import cn.skcks.matrix.v2.orm.mybatis.dynamic.model.LocationRecord; + +import java.util.Collection; +import java.util.List; +import java.util.Optional; +import javax.annotation.Generated; + +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Result; +import org.apache.ibatis.annotations.ResultMap; +import org.apache.ibatis.annotations.Results; +import org.apache.ibatis.annotations.SelectProvider; +import org.apache.ibatis.type.JdbcType; +import org.mybatis.dynamic.sql.BasicColumn; +import org.mybatis.dynamic.sql.delete.DeleteDSLCompleter; +import org.mybatis.dynamic.sql.select.CountDSLCompleter; +import org.mybatis.dynamic.sql.select.SelectDSLCompleter; +import org.mybatis.dynamic.sql.select.render.SelectStatementProvider; +import org.mybatis.dynamic.sql.update.UpdateDSL; +import org.mybatis.dynamic.sql.update.UpdateDSLCompleter; +import org.mybatis.dynamic.sql.update.UpdateModel; +import org.mybatis.dynamic.sql.util.SqlProviderAdapter; +import org.mybatis.dynamic.sql.util.mybatis3.CommonCountMapper; +import org.mybatis.dynamic.sql.util.mybatis3.CommonDeleteMapper; +import org.mybatis.dynamic.sql.util.mybatis3.CommonInsertMapper; +import org.mybatis.dynamic.sql.util.mybatis3.CommonUpdateMapper; +import org.mybatis.dynamic.sql.util.mybatis3.MyBatis3Utils; + +@Mapper +public interface LocationRecordMapper extends CommonCountMapper, CommonDeleteMapper, CommonInsertMapper, CommonUpdateMapper { + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: location_record") + BasicColumn[] selectList = BasicColumn.columnList(LocationRecordDynamicSqlSupport.id, LocationRecordDynamicSqlSupport.callbackTime, LocationRecordDynamicSqlSupport.locationTime, LocationRecordDynamicSqlSupport.locationType, LocationRecordDynamicSqlSupport.latitude, LocationRecordDynamicSqlSupport.longitude, LocationRecordDynamicSqlSupport.accuracy, LocationRecordDynamicSqlSupport.altitude, LocationRecordDynamicSqlSupport.bearing, LocationRecordDynamicSqlSupport.speed, LocationRecordDynamicSqlSupport.country, LocationRecordDynamicSqlSupport.province, LocationRecordDynamicSqlSupport.city, LocationRecordDynamicSqlSupport.district, LocationRecordDynamicSqlSupport.street, LocationRecordDynamicSqlSupport.streetNumber, LocationRecordDynamicSqlSupport.cityCode, LocationRecordDynamicSqlSupport.adCode, LocationRecordDynamicSqlSupport.address, LocationRecordDynamicSqlSupport.description, LocationRecordDynamicSqlSupport.userId); + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: location_record") + @SelectProvider(type=SqlProviderAdapter.class, method="select") + @Results(id="LocationRecordResult", value = { + @Result(column="id", property="id", jdbcType=JdbcType.VARCHAR, id=true), + @Result(column="callback_time", property="callbackTime", jdbcType=JdbcType.TIMESTAMP), + @Result(column="location_time", property="locationTime", jdbcType=JdbcType.TIMESTAMP), + @Result(column="location_type", property="locationType", jdbcType=JdbcType.INTEGER), + @Result(column="latitude", property="latitude", jdbcType=JdbcType.DOUBLE), + @Result(column="longitude", property="longitude", jdbcType=JdbcType.DOUBLE), + @Result(column="accuracy", property="accuracy", jdbcType=JdbcType.DOUBLE), + @Result(column="altitude", property="altitude", jdbcType=JdbcType.DOUBLE), + @Result(column="bearing", property="bearing", jdbcType=JdbcType.DOUBLE), + @Result(column="speed", property="speed", jdbcType=JdbcType.DOUBLE), + @Result(column="country", property="country", jdbcType=JdbcType.VARCHAR), + @Result(column="province", property="province", jdbcType=JdbcType.VARCHAR), + @Result(column="city", property="city", jdbcType=JdbcType.VARCHAR), + @Result(column="district", property="district", jdbcType=JdbcType.VARCHAR), + @Result(column="street", property="street", jdbcType=JdbcType.VARCHAR), + @Result(column="street_number", property="streetNumber", jdbcType=JdbcType.VARCHAR), + @Result(column="city_code", property="cityCode", jdbcType=JdbcType.VARCHAR), + @Result(column="ad_code", property="adCode", jdbcType=JdbcType.VARCHAR), + @Result(column="address", property="address", jdbcType=JdbcType.VARCHAR), + @Result(column="description", property="description", jdbcType=JdbcType.VARCHAR), + @Result(column="user_id", property="userId", jdbcType=JdbcType.BIGINT) + }) + List selectMany(SelectStatementProvider selectStatement); + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: location_record") + @SelectProvider(type=SqlProviderAdapter.class, method="select") + @ResultMap("LocationRecordResult") + Optional selectOne(SelectStatementProvider selectStatement); + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: location_record") + default long count(CountDSLCompleter completer) { + return MyBatis3Utils.countFrom(this::count, LocationRecordDynamicSqlSupport.locationRecord, completer); + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: location_record") + default int delete(DeleteDSLCompleter completer) { + return MyBatis3Utils.deleteFrom(this::delete, LocationRecordDynamicSqlSupport.locationRecord, completer); + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: location_record") + default int deleteByPrimaryKey(String id_) { + return delete(c -> + c.where(LocationRecordDynamicSqlSupport.id, isEqualTo(id_)) + ); + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: location_record") + default int insert(LocationRecord row) { + return MyBatis3Utils.insert(this::insert, row, LocationRecordDynamicSqlSupport.locationRecord, c -> + c.map(LocationRecordDynamicSqlSupport.id).toProperty("id") + .map(LocationRecordDynamicSqlSupport.callbackTime).toProperty("callbackTime") + .map(LocationRecordDynamicSqlSupport.locationTime).toProperty("locationTime") + .map(LocationRecordDynamicSqlSupport.locationType).toProperty("locationType") + .map(LocationRecordDynamicSqlSupport.latitude).toProperty("latitude") + .map(LocationRecordDynamicSqlSupport.longitude).toProperty("longitude") + .map(LocationRecordDynamicSqlSupport.accuracy).toProperty("accuracy") + .map(LocationRecordDynamicSqlSupport.altitude).toProperty("altitude") + .map(LocationRecordDynamicSqlSupport.bearing).toProperty("bearing") + .map(LocationRecordDynamicSqlSupport.speed).toProperty("speed") + .map(LocationRecordDynamicSqlSupport.country).toProperty("country") + .map(LocationRecordDynamicSqlSupport.province).toProperty("province") + .map(LocationRecordDynamicSqlSupport.city).toProperty("city") + .map(LocationRecordDynamicSqlSupport.district).toProperty("district") + .map(LocationRecordDynamicSqlSupport.street).toProperty("street") + .map(LocationRecordDynamicSqlSupport.streetNumber).toProperty("streetNumber") + .map(LocationRecordDynamicSqlSupport.cityCode).toProperty("cityCode") + .map(LocationRecordDynamicSqlSupport.adCode).toProperty("adCode") + .map(LocationRecordDynamicSqlSupport.address).toProperty("address") + .map(LocationRecordDynamicSqlSupport.description).toProperty("description") + .map(LocationRecordDynamicSqlSupport.userId).toProperty("userId") + ); + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: location_record") + default int insertMultiple(Collection records) { + return MyBatis3Utils.insertMultiple(this::insertMultiple, records, LocationRecordDynamicSqlSupport.locationRecord, c -> + c.map(LocationRecordDynamicSqlSupport.id).toProperty("id") + .map(LocationRecordDynamicSqlSupport.callbackTime).toProperty("callbackTime") + .map(LocationRecordDynamicSqlSupport.locationTime).toProperty("locationTime") + .map(LocationRecordDynamicSqlSupport.locationType).toProperty("locationType") + .map(LocationRecordDynamicSqlSupport.latitude).toProperty("latitude") + .map(LocationRecordDynamicSqlSupport.longitude).toProperty("longitude") + .map(LocationRecordDynamicSqlSupport.accuracy).toProperty("accuracy") + .map(LocationRecordDynamicSqlSupport.altitude).toProperty("altitude") + .map(LocationRecordDynamicSqlSupport.bearing).toProperty("bearing") + .map(LocationRecordDynamicSqlSupport.speed).toProperty("speed") + .map(LocationRecordDynamicSqlSupport.country).toProperty("country") + .map(LocationRecordDynamicSqlSupport.province).toProperty("province") + .map(LocationRecordDynamicSqlSupport.city).toProperty("city") + .map(LocationRecordDynamicSqlSupport.district).toProperty("district") + .map(LocationRecordDynamicSqlSupport.street).toProperty("street") + .map(LocationRecordDynamicSqlSupport.streetNumber).toProperty("streetNumber") + .map(LocationRecordDynamicSqlSupport.cityCode).toProperty("cityCode") + .map(LocationRecordDynamicSqlSupport.adCode).toProperty("adCode") + .map(LocationRecordDynamicSqlSupport.address).toProperty("address") + .map(LocationRecordDynamicSqlSupport.description).toProperty("description") + .map(LocationRecordDynamicSqlSupport.userId).toProperty("userId") + ); + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: location_record") + default int insertSelective(LocationRecord row) { + return MyBatis3Utils.insert(this::insert, row, LocationRecordDynamicSqlSupport.locationRecord, c -> + c.map(LocationRecordDynamicSqlSupport.id).toPropertyWhenPresent("id", row::getId) + .map(LocationRecordDynamicSqlSupport.callbackTime).toPropertyWhenPresent("callbackTime", row::getCallbackTime) + .map(LocationRecordDynamicSqlSupport.locationTime).toPropertyWhenPresent("locationTime", row::getLocationTime) + .map(LocationRecordDynamicSqlSupport.locationType).toPropertyWhenPresent("locationType", row::getLocationType) + .map(LocationRecordDynamicSqlSupport.latitude).toPropertyWhenPresent("latitude", row::getLatitude) + .map(LocationRecordDynamicSqlSupport.longitude).toPropertyWhenPresent("longitude", row::getLongitude) + .map(LocationRecordDynamicSqlSupport.accuracy).toPropertyWhenPresent("accuracy", row::getAccuracy) + .map(LocationRecordDynamicSqlSupport.altitude).toPropertyWhenPresent("altitude", row::getAltitude) + .map(LocationRecordDynamicSqlSupport.bearing).toPropertyWhenPresent("bearing", row::getBearing) + .map(LocationRecordDynamicSqlSupport.speed).toPropertyWhenPresent("speed", row::getSpeed) + .map(LocationRecordDynamicSqlSupport.country).toPropertyWhenPresent("country", row::getCountry) + .map(LocationRecordDynamicSqlSupport.province).toPropertyWhenPresent("province", row::getProvince) + .map(LocationRecordDynamicSqlSupport.city).toPropertyWhenPresent("city", row::getCity) + .map(LocationRecordDynamicSqlSupport.district).toPropertyWhenPresent("district", row::getDistrict) + .map(LocationRecordDynamicSqlSupport.street).toPropertyWhenPresent("street", row::getStreet) + .map(LocationRecordDynamicSqlSupport.streetNumber).toPropertyWhenPresent("streetNumber", row::getStreetNumber) + .map(LocationRecordDynamicSqlSupport.cityCode).toPropertyWhenPresent("cityCode", row::getCityCode) + .map(LocationRecordDynamicSqlSupport.adCode).toPropertyWhenPresent("adCode", row::getAdCode) + .map(LocationRecordDynamicSqlSupport.address).toPropertyWhenPresent("address", row::getAddress) + .map(LocationRecordDynamicSqlSupport.description).toPropertyWhenPresent("description", row::getDescription) + .map(LocationRecordDynamicSqlSupport.userId).toPropertyWhenPresent("userId", row::getUserId) + ); + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: location_record") + default Optional selectOne(SelectDSLCompleter completer) { + return MyBatis3Utils.selectOne(this::selectOne, selectList, LocationRecordDynamicSqlSupport.locationRecord, completer); + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: location_record") + default List select(SelectDSLCompleter completer) { + return MyBatis3Utils.selectList(this::selectMany, selectList, LocationRecordDynamicSqlSupport.locationRecord, completer); + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: location_record") + default List selectDistinct(SelectDSLCompleter completer) { + return MyBatis3Utils.selectDistinct(this::selectMany, selectList, LocationRecordDynamicSqlSupport.locationRecord, completer); + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: location_record") + default Optional selectByPrimaryKey(String id_) { + return selectOne(c -> + c.where(LocationRecordDynamicSqlSupport.id, isEqualTo(id_)) + ); + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: location_record") + default int update(UpdateDSLCompleter completer) { + return MyBatis3Utils.update(this::update, LocationRecordDynamicSqlSupport.locationRecord, completer); + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: location_record") + static UpdateDSL updateAllColumns(LocationRecord row, UpdateDSL dsl) { + return dsl.set(LocationRecordDynamicSqlSupport.id).equalTo(row::getId) + .set(LocationRecordDynamicSqlSupport.callbackTime).equalTo(row::getCallbackTime) + .set(LocationRecordDynamicSqlSupport.locationTime).equalTo(row::getLocationTime) + .set(LocationRecordDynamicSqlSupport.locationType).equalTo(row::getLocationType) + .set(LocationRecordDynamicSqlSupport.latitude).equalTo(row::getLatitude) + .set(LocationRecordDynamicSqlSupport.longitude).equalTo(row::getLongitude) + .set(LocationRecordDynamicSqlSupport.accuracy).equalTo(row::getAccuracy) + .set(LocationRecordDynamicSqlSupport.altitude).equalTo(row::getAltitude) + .set(LocationRecordDynamicSqlSupport.bearing).equalTo(row::getBearing) + .set(LocationRecordDynamicSqlSupport.speed).equalTo(row::getSpeed) + .set(LocationRecordDynamicSqlSupport.country).equalTo(row::getCountry) + .set(LocationRecordDynamicSqlSupport.province).equalTo(row::getProvince) + .set(LocationRecordDynamicSqlSupport.city).equalTo(row::getCity) + .set(LocationRecordDynamicSqlSupport.district).equalTo(row::getDistrict) + .set(LocationRecordDynamicSqlSupport.street).equalTo(row::getStreet) + .set(LocationRecordDynamicSqlSupport.streetNumber).equalTo(row::getStreetNumber) + .set(LocationRecordDynamicSqlSupport.cityCode).equalTo(row::getCityCode) + .set(LocationRecordDynamicSqlSupport.adCode).equalTo(row::getAdCode) + .set(LocationRecordDynamicSqlSupport.address).equalTo(row::getAddress) + .set(LocationRecordDynamicSqlSupport.description).equalTo(row::getDescription) + .set(LocationRecordDynamicSqlSupport.userId).equalTo(row::getUserId); + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: location_record") + static UpdateDSL updateSelectiveColumns(LocationRecord row, UpdateDSL dsl) { + return dsl.set(LocationRecordDynamicSqlSupport.id).equalToWhenPresent(row::getId) + .set(LocationRecordDynamicSqlSupport.callbackTime).equalToWhenPresent(row::getCallbackTime) + .set(LocationRecordDynamicSqlSupport.locationTime).equalToWhenPresent(row::getLocationTime) + .set(LocationRecordDynamicSqlSupport.locationType).equalToWhenPresent(row::getLocationType) + .set(LocationRecordDynamicSqlSupport.latitude).equalToWhenPresent(row::getLatitude) + .set(LocationRecordDynamicSqlSupport.longitude).equalToWhenPresent(row::getLongitude) + .set(LocationRecordDynamicSqlSupport.accuracy).equalToWhenPresent(row::getAccuracy) + .set(LocationRecordDynamicSqlSupport.altitude).equalToWhenPresent(row::getAltitude) + .set(LocationRecordDynamicSqlSupport.bearing).equalToWhenPresent(row::getBearing) + .set(LocationRecordDynamicSqlSupport.speed).equalToWhenPresent(row::getSpeed) + .set(LocationRecordDynamicSqlSupport.country).equalToWhenPresent(row::getCountry) + .set(LocationRecordDynamicSqlSupport.province).equalToWhenPresent(row::getProvince) + .set(LocationRecordDynamicSqlSupport.city).equalToWhenPresent(row::getCity) + .set(LocationRecordDynamicSqlSupport.district).equalToWhenPresent(row::getDistrict) + .set(LocationRecordDynamicSqlSupport.street).equalToWhenPresent(row::getStreet) + .set(LocationRecordDynamicSqlSupport.streetNumber).equalToWhenPresent(row::getStreetNumber) + .set(LocationRecordDynamicSqlSupport.cityCode).equalToWhenPresent(row::getCityCode) + .set(LocationRecordDynamicSqlSupport.adCode).equalToWhenPresent(row::getAdCode) + .set(LocationRecordDynamicSqlSupport.address).equalToWhenPresent(row::getAddress) + .set(LocationRecordDynamicSqlSupport.description).equalToWhenPresent(row::getDescription) + .set(LocationRecordDynamicSqlSupport.userId).equalToWhenPresent(row::getUserId); + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: location_record") + default int updateByPrimaryKey(LocationRecord row) { + return update(c -> + c.set(LocationRecordDynamicSqlSupport.callbackTime).equalTo(row::getCallbackTime) + .set(LocationRecordDynamicSqlSupport.locationTime).equalTo(row::getLocationTime) + .set(LocationRecordDynamicSqlSupport.locationType).equalTo(row::getLocationType) + .set(LocationRecordDynamicSqlSupport.latitude).equalTo(row::getLatitude) + .set(LocationRecordDynamicSqlSupport.longitude).equalTo(row::getLongitude) + .set(LocationRecordDynamicSqlSupport.accuracy).equalTo(row::getAccuracy) + .set(LocationRecordDynamicSqlSupport.altitude).equalTo(row::getAltitude) + .set(LocationRecordDynamicSqlSupport.bearing).equalTo(row::getBearing) + .set(LocationRecordDynamicSqlSupport.speed).equalTo(row::getSpeed) + .set(LocationRecordDynamicSqlSupport.country).equalTo(row::getCountry) + .set(LocationRecordDynamicSqlSupport.province).equalTo(row::getProvince) + .set(LocationRecordDynamicSqlSupport.city).equalTo(row::getCity) + .set(LocationRecordDynamicSqlSupport.district).equalTo(row::getDistrict) + .set(LocationRecordDynamicSqlSupport.street).equalTo(row::getStreet) + .set(LocationRecordDynamicSqlSupport.streetNumber).equalTo(row::getStreetNumber) + .set(LocationRecordDynamicSqlSupport.cityCode).equalTo(row::getCityCode) + .set(LocationRecordDynamicSqlSupport.adCode).equalTo(row::getAdCode) + .set(LocationRecordDynamicSqlSupport.address).equalTo(row::getAddress) + .set(LocationRecordDynamicSqlSupport.description).equalTo(row::getDescription) + .set(LocationRecordDynamicSqlSupport.userId).equalTo(row::getUserId) + .where(LocationRecordDynamicSqlSupport.id, isEqualTo(row::getId)) + ); + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: location_record") + default int updateByPrimaryKeySelective(LocationRecord row) { + return update(c -> + c.set(LocationRecordDynamicSqlSupport.callbackTime).equalToWhenPresent(row::getCallbackTime) + .set(LocationRecordDynamicSqlSupport.locationTime).equalToWhenPresent(row::getLocationTime) + .set(LocationRecordDynamicSqlSupport.locationType).equalToWhenPresent(row::getLocationType) + .set(LocationRecordDynamicSqlSupport.latitude).equalToWhenPresent(row::getLatitude) + .set(LocationRecordDynamicSqlSupport.longitude).equalToWhenPresent(row::getLongitude) + .set(LocationRecordDynamicSqlSupport.accuracy).equalToWhenPresent(row::getAccuracy) + .set(LocationRecordDynamicSqlSupport.altitude).equalToWhenPresent(row::getAltitude) + .set(LocationRecordDynamicSqlSupport.bearing).equalToWhenPresent(row::getBearing) + .set(LocationRecordDynamicSqlSupport.speed).equalToWhenPresent(row::getSpeed) + .set(LocationRecordDynamicSqlSupport.country).equalToWhenPresent(row::getCountry) + .set(LocationRecordDynamicSqlSupport.province).equalToWhenPresent(row::getProvince) + .set(LocationRecordDynamicSqlSupport.city).equalToWhenPresent(row::getCity) + .set(LocationRecordDynamicSqlSupport.district).equalToWhenPresent(row::getDistrict) + .set(LocationRecordDynamicSqlSupport.street).equalToWhenPresent(row::getStreet) + .set(LocationRecordDynamicSqlSupport.streetNumber).equalToWhenPresent(row::getStreetNumber) + .set(LocationRecordDynamicSqlSupport.cityCode).equalToWhenPresent(row::getCityCode) + .set(LocationRecordDynamicSqlSupport.adCode).equalToWhenPresent(row::getAdCode) + .set(LocationRecordDynamicSqlSupport.address).equalToWhenPresent(row::getAddress) + .set(LocationRecordDynamicSqlSupport.description).equalToWhenPresent(row::getDescription) + .set(LocationRecordDynamicSqlSupport.userId).equalToWhenPresent(row::getUserId) + .where(LocationRecordDynamicSqlSupport.id, isEqualTo(row::getId)) + ); + } +} diff --git a/backend/java/sk-matrix-service/orm/src/main/java/cn/skcks/matrix/v2/orm/mybatis/dynamic/mapper/RoleDynamicSqlSupport.java b/backend/java/sk-matrix-service/orm/src/main/java/cn/skcks/matrix/v2/orm/mybatis/dynamic/mapper/RoleDynamicSqlSupport.java new file mode 100644 index 0000000..94256f5 --- /dev/null +++ b/backend/java/sk-matrix-service/orm/src/main/java/cn/skcks/matrix/v2/orm/mybatis/dynamic/mapper/RoleDynamicSqlSupport.java @@ -0,0 +1,48 @@ +package cn.skcks.matrix.v2.orm.mybatis.dynamic.mapper; + +import java.sql.JDBCType; +import javax.annotation.Generated; +import org.mybatis.dynamic.sql.AliasableSqlTable; +import org.mybatis.dynamic.sql.SqlColumn; + +public final class RoleDynamicSqlSupport { + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: role") + public static final Role role = new Role(); + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: role.id") + public static final SqlColumn id = role.id; + + /** + * Database Column Remarks: + * 角色名 + */ + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: role.name") + public static final SqlColumn name = role.name; + + /** + * Database Column Remarks: + * 所属系统 + */ + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: role.system_id") + public static final SqlColumn systemId = role.systemId; + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: role.active") + public static final SqlColumn active = role.active; + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: role") + public static final class Role extends AliasableSqlTable { + public final SqlColumn id = column("id", JDBCType.BIGINT); + + public final SqlColumn role = column("role", JDBCType.VARCHAR); + + public final SqlColumn name = column("name", JDBCType.VARCHAR); + + public final SqlColumn systemId = column("system_id", JDBCType.VARCHAR); + + public final SqlColumn active = column("active", JDBCType.BIT); + + public Role() { + super("role", Role::new); + } + } +} diff --git a/backend/java/sk-matrix-service/orm/src/main/java/cn/skcks/matrix/v2/orm/mybatis/dynamic/mapper/RoleMapper.java b/backend/java/sk-matrix-service/orm/src/main/java/cn/skcks/matrix/v2/orm/mybatis/dynamic/mapper/RoleMapper.java new file mode 100644 index 0000000..4e47dbd --- /dev/null +++ b/backend/java/sk-matrix-service/orm/src/main/java/cn/skcks/matrix/v2/orm/mybatis/dynamic/mapper/RoleMapper.java @@ -0,0 +1,170 @@ +package cn.skcks.matrix.v2.orm.mybatis.dynamic.mapper; + +import static org.mybatis.dynamic.sql.SqlBuilder.isEqualTo; + +import cn.skcks.matrix.v2.orm.mybatis.dynamic.model.Role; + +import java.util.Collection; +import java.util.List; +import java.util.Optional; +import javax.annotation.Generated; + +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Result; +import org.apache.ibatis.annotations.ResultMap; +import org.apache.ibatis.annotations.Results; +import org.apache.ibatis.annotations.SelectProvider; +import org.apache.ibatis.type.JdbcType; +import org.mybatis.dynamic.sql.BasicColumn; +import org.mybatis.dynamic.sql.delete.DeleteDSLCompleter; +import org.mybatis.dynamic.sql.select.CountDSLCompleter; +import org.mybatis.dynamic.sql.select.SelectDSLCompleter; +import org.mybatis.dynamic.sql.select.render.SelectStatementProvider; +import org.mybatis.dynamic.sql.update.UpdateDSL; +import org.mybatis.dynamic.sql.update.UpdateDSLCompleter; +import org.mybatis.dynamic.sql.update.UpdateModel; +import org.mybatis.dynamic.sql.util.SqlProviderAdapter; +import org.mybatis.dynamic.sql.util.mybatis3.CommonCountMapper; +import org.mybatis.dynamic.sql.util.mybatis3.CommonDeleteMapper; +import org.mybatis.dynamic.sql.util.mybatis3.CommonInsertMapper; +import org.mybatis.dynamic.sql.util.mybatis3.CommonUpdateMapper; +import org.mybatis.dynamic.sql.util.mybatis3.MyBatis3Utils; + +@Mapper +public interface RoleMapper extends CommonCountMapper, CommonDeleteMapper, CommonInsertMapper, CommonUpdateMapper { + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: role") + BasicColumn[] selectList = BasicColumn.columnList(RoleDynamicSqlSupport.id, RoleDynamicSqlSupport.role.role, RoleDynamicSqlSupport.name, RoleDynamicSqlSupport.systemId, RoleDynamicSqlSupport.active); + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: role") + @SelectProvider(type=SqlProviderAdapter.class, method="select") + @Results(id="RoleResult", value = { + @Result(column="id", property="id", jdbcType=JdbcType.BIGINT, id=true), + @Result(column="role", property="role", jdbcType=JdbcType.VARCHAR), + @Result(column="name", property="name", jdbcType=JdbcType.VARCHAR), + @Result(column="system_id", property="systemId", jdbcType=JdbcType.VARCHAR), + @Result(column="active", property="active", jdbcType=JdbcType.BIT) + }) + List selectMany(SelectStatementProvider selectStatement); + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: role") + @SelectProvider(type=SqlProviderAdapter.class, method="select") + @ResultMap("RoleResult") + Optional selectOne(SelectStatementProvider selectStatement); + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: role") + default long count(CountDSLCompleter completer) { + return MyBatis3Utils.countFrom(this::count, RoleDynamicSqlSupport.role, completer); + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: role") + default int delete(DeleteDSLCompleter completer) { + return MyBatis3Utils.deleteFrom(this::delete, RoleDynamicSqlSupport.role, completer); + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: role") + default int deleteByPrimaryKey(Long id_) { + return delete(c -> + c.where(RoleDynamicSqlSupport.id, isEqualTo(id_)) + ); + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: role") + default int insert(Role row) { + return MyBatis3Utils.insert(this::insert, row, RoleDynamicSqlSupport.role, c -> + c.map(RoleDynamicSqlSupport.id).toProperty("id") + .map(RoleDynamicSqlSupport.role.role).toProperty("role") + .map(RoleDynamicSqlSupport.name).toProperty("name") + .map(RoleDynamicSqlSupport.systemId).toProperty("systemId") + .map(RoleDynamicSqlSupport.active).toProperty("active") + ); + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: role") + default int insertMultiple(Collection records) { + return MyBatis3Utils.insertMultiple(this::insertMultiple, records, RoleDynamicSqlSupport.role, c -> + c.map(RoleDynamicSqlSupport.id).toProperty("id") + .map(RoleDynamicSqlSupport.role.role).toProperty("role") + .map(RoleDynamicSqlSupport.name).toProperty("name") + .map(RoleDynamicSqlSupport.systemId).toProperty("systemId") + .map(RoleDynamicSqlSupport.active).toProperty("active") + ); + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: role") + default int insertSelective(Role row) { + return MyBatis3Utils.insert(this::insert, row, RoleDynamicSqlSupport.role, c -> + c.map(RoleDynamicSqlSupport.id).toPropertyWhenPresent("id", row::getId) + .map(RoleDynamicSqlSupport.role.role).toPropertyWhenPresent("role", row::getRole) + .map(RoleDynamicSqlSupport.name).toPropertyWhenPresent("name", row::getName) + .map(RoleDynamicSqlSupport.systemId).toPropertyWhenPresent("systemId", row::getSystemId) + .map(RoleDynamicSqlSupport.active).toPropertyWhenPresent("active", row::getActive) + ); + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: role") + default Optional selectOne(SelectDSLCompleter completer) { + return MyBatis3Utils.selectOne(this::selectOne, selectList, RoleDynamicSqlSupport.role, completer); + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: role") + default List select(SelectDSLCompleter completer) { + return MyBatis3Utils.selectList(this::selectMany, selectList, RoleDynamicSqlSupport.role, completer); + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: role") + default List selectDistinct(SelectDSLCompleter completer) { + return MyBatis3Utils.selectDistinct(this::selectMany, selectList, RoleDynamicSqlSupport.role, completer); + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: role") + default Optional selectByPrimaryKey(Long id_) { + return selectOne(c -> + c.where(RoleDynamicSqlSupport.id, isEqualTo(id_)) + ); + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: role") + default int update(UpdateDSLCompleter completer) { + return MyBatis3Utils.update(this::update, RoleDynamicSqlSupport.role, completer); + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: role") + static UpdateDSL updateAllColumns(Role row, UpdateDSL dsl) { + return dsl.set(RoleDynamicSqlSupport.id).equalTo(row::getId) + .set(RoleDynamicSqlSupport.role.role).equalTo(row::getRole) + .set(RoleDynamicSqlSupport.name).equalTo(row::getName) + .set(RoleDynamicSqlSupport.systemId).equalTo(row::getSystemId) + .set(RoleDynamicSqlSupport.active).equalTo(row::getActive); + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: role") + static UpdateDSL updateSelectiveColumns(Role row, UpdateDSL dsl) { + return dsl.set(RoleDynamicSqlSupport.id).equalToWhenPresent(row::getId) + .set(RoleDynamicSqlSupport.role.role).equalToWhenPresent(row::getRole) + .set(RoleDynamicSqlSupport.name).equalToWhenPresent(row::getName) + .set(RoleDynamicSqlSupport.systemId).equalToWhenPresent(row::getSystemId) + .set(RoleDynamicSqlSupport.active).equalToWhenPresent(row::getActive); + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: role") + default int updateByPrimaryKey(Role row) { + return update(c -> + c.set(RoleDynamicSqlSupport.role.role).equalTo(row::getRole) + .set(RoleDynamicSqlSupport.name).equalTo(row::getName) + .set(RoleDynamicSqlSupport.systemId).equalTo(row::getSystemId) + .set(RoleDynamicSqlSupport.active).equalTo(row::getActive) + .where(RoleDynamicSqlSupport.id, isEqualTo(row::getId)) + ); + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: role") + default int updateByPrimaryKeySelective(Role row) { + return update(c -> + c.set(RoleDynamicSqlSupport.role.role).equalToWhenPresent(row::getRole) + .set(RoleDynamicSqlSupport.name).equalToWhenPresent(row::getName) + .set(RoleDynamicSqlSupport.systemId).equalToWhenPresent(row::getSystemId) + .set(RoleDynamicSqlSupport.active).equalToWhenPresent(row::getActive) + .where(RoleDynamicSqlSupport.id, isEqualTo(row::getId)) + ); + } +} diff --git a/backend/java/sk-matrix-service/orm/src/main/java/cn/skcks/matrix/v2/orm/mybatis/dynamic/mapper/UserDynamicSqlSupport.java b/backend/java/sk-matrix-service/orm/src/main/java/cn/skcks/matrix/v2/orm/mybatis/dynamic/mapper/UserDynamicSqlSupport.java new file mode 100644 index 0000000..cab4822 --- /dev/null +++ b/backend/java/sk-matrix-service/orm/src/main/java/cn/skcks/matrix/v2/orm/mybatis/dynamic/mapper/UserDynamicSqlSupport.java @@ -0,0 +1,72 @@ +package cn.skcks.matrix.v2.orm.mybatis.dynamic.mapper; + +import java.sql.JDBCType; +import java.util.Date; +import javax.annotation.Generated; +import org.mybatis.dynamic.sql.AliasableSqlTable; +import org.mybatis.dynamic.sql.SqlColumn; + +public final class UserDynamicSqlSupport { + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: user") + public static final User user = new User(); + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: user.id") + public static final SqlColumn id = user.id; + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: user.user_name") + public static final SqlColumn userName = user.userName; + + /** + * Database Column Remarks: + * 加密后的密码 + */ + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: user.password") + public static final SqlColumn password = user.password; + + /** + * Database Column Remarks: + * 加密密钥 + */ + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: user.salt") + public static final SqlColumn salt = user.salt; + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: user.email") + public static final SqlColumn email = user.email; + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: user.phone_number") + public static final SqlColumn phoneNumber = user.phoneNumber; + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: user.description") + public static final SqlColumn description = user.description; + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: user.create_time") + public static final SqlColumn createTime = user.createTime; + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: user.update_time") + public static final SqlColumn updateTime = user.updateTime; + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: user") + public static final class User extends AliasableSqlTable { + public final SqlColumn id = column("id", JDBCType.BIGINT); + + public final SqlColumn userName = column("user_name", JDBCType.VARCHAR); + + public final SqlColumn password = column("password", JDBCType.VARCHAR); + + public final SqlColumn salt = column("salt", JDBCType.VARCHAR); + + public final SqlColumn email = column("email", JDBCType.VARCHAR); + + public final SqlColumn phoneNumber = column("phone_number", JDBCType.VARCHAR); + + public final SqlColumn description = column("description", JDBCType.VARCHAR); + + public final SqlColumn createTime = column("create_time", JDBCType.TIMESTAMP); + + public final SqlColumn updateTime = column("update_time", JDBCType.TIMESTAMP); + + public User() { + super("user", User::new); + } + } +} diff --git a/backend/java/sk-matrix-service/orm/src/main/java/cn/skcks/matrix/v2/orm/mybatis/dynamic/mapper/UserMapper.java b/backend/java/sk-matrix-service/orm/src/main/java/cn/skcks/matrix/v2/orm/mybatis/dynamic/mapper/UserMapper.java new file mode 100644 index 0000000..8b51bb4 --- /dev/null +++ b/backend/java/sk-matrix-service/orm/src/main/java/cn/skcks/matrix/v2/orm/mybatis/dynamic/mapper/UserMapper.java @@ -0,0 +1,201 @@ +package cn.skcks.matrix.v2.orm.mybatis.dynamic.mapper; + +import static cn.skcks.matrix.v2.orm.mybatis.dynamic.mapper.UserDynamicSqlSupport.*; +import static org.mybatis.dynamic.sql.SqlBuilder.isEqualTo; + +import cn.skcks.matrix.v2.orm.mybatis.dynamic.model.User; +import java.util.Collection; +import java.util.List; +import java.util.Optional; +import javax.annotation.Generated; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Result; +import org.apache.ibatis.annotations.ResultMap; +import org.apache.ibatis.annotations.Results; +import org.apache.ibatis.annotations.SelectProvider; +import org.apache.ibatis.type.JdbcType; +import org.mybatis.dynamic.sql.BasicColumn; +import org.mybatis.dynamic.sql.delete.DeleteDSLCompleter; +import org.mybatis.dynamic.sql.select.CountDSLCompleter; +import org.mybatis.dynamic.sql.select.SelectDSLCompleter; +import org.mybatis.dynamic.sql.select.render.SelectStatementProvider; +import org.mybatis.dynamic.sql.update.UpdateDSL; +import org.mybatis.dynamic.sql.update.UpdateDSLCompleter; +import org.mybatis.dynamic.sql.update.UpdateModel; +import org.mybatis.dynamic.sql.util.SqlProviderAdapter; +import org.mybatis.dynamic.sql.util.mybatis3.CommonCountMapper; +import org.mybatis.dynamic.sql.util.mybatis3.CommonDeleteMapper; +import org.mybatis.dynamic.sql.util.mybatis3.CommonInsertMapper; +import org.mybatis.dynamic.sql.util.mybatis3.CommonUpdateMapper; +import org.mybatis.dynamic.sql.util.mybatis3.MyBatis3Utils; + +@Mapper +public interface UserMapper extends CommonCountMapper, CommonDeleteMapper, CommonInsertMapper, CommonUpdateMapper { + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: user") + BasicColumn[] selectList = BasicColumn.columnList(id, userName, password, salt, email, phoneNumber, description, createTime, updateTime); + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: user") + @SelectProvider(type=SqlProviderAdapter.class, method="select") + @Results(id="UserResult", value = { + @Result(column="id", property="id", jdbcType=JdbcType.BIGINT, id=true), + @Result(column="user_name", property="userName", jdbcType=JdbcType.VARCHAR), + @Result(column="password", property="password", jdbcType=JdbcType.VARCHAR), + @Result(column="salt", property="salt", jdbcType=JdbcType.VARCHAR), + @Result(column="email", property="email", jdbcType=JdbcType.VARCHAR), + @Result(column="phone_number", property="phoneNumber", jdbcType=JdbcType.VARCHAR), + @Result(column="description", property="description", jdbcType=JdbcType.VARCHAR), + @Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP), + @Result(column="update_time", property="updateTime", jdbcType=JdbcType.TIMESTAMP) + }) + List selectMany(SelectStatementProvider selectStatement); + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: user") + @SelectProvider(type=SqlProviderAdapter.class, method="select") + @ResultMap("UserResult") + Optional selectOne(SelectStatementProvider selectStatement); + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: user") + default long count(CountDSLCompleter completer) { + return MyBatis3Utils.countFrom(this::count, user, completer); + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: user") + default int delete(DeleteDSLCompleter completer) { + return MyBatis3Utils.deleteFrom(this::delete, user, completer); + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: user") + default int deleteByPrimaryKey(Long id_) { + return delete(c -> + c.where(id, isEqualTo(id_)) + ); + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: user") + default int insert(User row) { + return MyBatis3Utils.insert(this::insert, row, user, c -> + c.map(id).toProperty("id") + .map(userName).toProperty("userName") + .map(password).toProperty("password") + .map(salt).toProperty("salt") + .map(email).toProperty("email") + .map(phoneNumber).toProperty("phoneNumber") + .map(description).toProperty("description") + .map(createTime).toProperty("createTime") + .map(updateTime).toProperty("updateTime") + ); + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: user") + default int insertMultiple(Collection records) { + return MyBatis3Utils.insertMultiple(this::insertMultiple, records, user, c -> + c.map(id).toProperty("id") + .map(userName).toProperty("userName") + .map(password).toProperty("password") + .map(salt).toProperty("salt") + .map(email).toProperty("email") + .map(phoneNumber).toProperty("phoneNumber") + .map(description).toProperty("description") + .map(createTime).toProperty("createTime") + .map(updateTime).toProperty("updateTime") + ); + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: user") + default int insertSelective(User row) { + return MyBatis3Utils.insert(this::insert, row, user, c -> + c.map(id).toPropertyWhenPresent("id", row::getId) + .map(userName).toPropertyWhenPresent("userName", row::getUserName) + .map(password).toPropertyWhenPresent("password", row::getPassword) + .map(salt).toPropertyWhenPresent("salt", row::getSalt) + .map(email).toPropertyWhenPresent("email", row::getEmail) + .map(phoneNumber).toPropertyWhenPresent("phoneNumber", row::getPhoneNumber) + .map(description).toPropertyWhenPresent("description", row::getDescription) + .map(createTime).toPropertyWhenPresent("createTime", row::getCreateTime) + .map(updateTime).toPropertyWhenPresent("updateTime", row::getUpdateTime) + ); + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: user") + default Optional selectOne(SelectDSLCompleter completer) { + return MyBatis3Utils.selectOne(this::selectOne, selectList, user, completer); + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: user") + default List select(SelectDSLCompleter completer) { + return MyBatis3Utils.selectList(this::selectMany, selectList, user, completer); + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: user") + default List selectDistinct(SelectDSLCompleter completer) { + return MyBatis3Utils.selectDistinct(this::selectMany, selectList, user, completer); + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: user") + default Optional selectByPrimaryKey(Long id_) { + return selectOne(c -> + c.where(id, isEqualTo(id_)) + ); + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: user") + default int update(UpdateDSLCompleter completer) { + return MyBatis3Utils.update(this::update, user, completer); + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: user") + static UpdateDSL updateAllColumns(User row, UpdateDSL dsl) { + return dsl.set(id).equalTo(row::getId) + .set(userName).equalTo(row::getUserName) + .set(password).equalTo(row::getPassword) + .set(salt).equalTo(row::getSalt) + .set(email).equalTo(row::getEmail) + .set(phoneNumber).equalTo(row::getPhoneNumber) + .set(description).equalTo(row::getDescription) + .set(createTime).equalTo(row::getCreateTime) + .set(updateTime).equalTo(row::getUpdateTime); + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: user") + static UpdateDSL updateSelectiveColumns(User row, UpdateDSL dsl) { + return dsl.set(id).equalToWhenPresent(row::getId) + .set(userName).equalToWhenPresent(row::getUserName) + .set(password).equalToWhenPresent(row::getPassword) + .set(salt).equalToWhenPresent(row::getSalt) + .set(email).equalToWhenPresent(row::getEmail) + .set(phoneNumber).equalToWhenPresent(row::getPhoneNumber) + .set(description).equalToWhenPresent(row::getDescription) + .set(createTime).equalToWhenPresent(row::getCreateTime) + .set(updateTime).equalToWhenPresent(row::getUpdateTime); + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: user") + default int updateByPrimaryKey(User row) { + return update(c -> + c.set(userName).equalTo(row::getUserName) + .set(password).equalTo(row::getPassword) + .set(salt).equalTo(row::getSalt) + .set(email).equalTo(row::getEmail) + .set(phoneNumber).equalTo(row::getPhoneNumber) + .set(description).equalTo(row::getDescription) + .set(createTime).equalTo(row::getCreateTime) + .set(updateTime).equalTo(row::getUpdateTime) + .where(id, isEqualTo(row::getId)) + ); + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: user") + default int updateByPrimaryKeySelective(User row) { + return update(c -> + c.set(userName).equalToWhenPresent(row::getUserName) + .set(password).equalToWhenPresent(row::getPassword) + .set(salt).equalToWhenPresent(row::getSalt) + .set(email).equalToWhenPresent(row::getEmail) + .set(phoneNumber).equalToWhenPresent(row::getPhoneNumber) + .set(description).equalToWhenPresent(row::getDescription) + .set(createTime).equalToWhenPresent(row::getCreateTime) + .set(updateTime).equalToWhenPresent(row::getUpdateTime) + .where(id, isEqualTo(row::getId)) + ); + } +} diff --git a/backend/java/sk-matrix-service/orm/src/main/java/cn/skcks/matrix/v2/orm/mybatis/dynamic/model/CasbinRule.java b/backend/java/sk-matrix-service/orm/src/main/java/cn/skcks/matrix/v2/orm/mybatis/dynamic/model/CasbinRule.java new file mode 100644 index 0000000..3938c5f --- /dev/null +++ b/backend/java/sk-matrix-service/orm/src/main/java/cn/skcks/matrix/v2/orm/mybatis/dynamic/model/CasbinRule.java @@ -0,0 +1,114 @@ +package cn.skcks.matrix.v2.orm.mybatis.dynamic.model; + +import javax.annotation.Generated; + +/** + * + * This class was generated by MyBatis Generator. + * This class corresponds to the database table casbin_rule + */ +public class CasbinRule { + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: casbin_rule.id") + private Integer id; + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: casbin_rule.ptype") + private String ptype; + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: casbin_rule.v0") + private String v0; + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: casbin_rule.v1") + private String v1; + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: casbin_rule.v2") + private String v2; + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: casbin_rule.v3") + private String v3; + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: casbin_rule.v4") + private String v4; + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: casbin_rule.v5") + private String v5; + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: casbin_rule.id") + public Integer getId() { + return id; + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: casbin_rule.id") + public void setId(Integer id) { + this.id = id; + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: casbin_rule.ptype") + public String getPtype() { + return ptype; + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: casbin_rule.ptype") + public void setPtype(String ptype) { + this.ptype = ptype == null ? null : ptype.trim(); + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: casbin_rule.v0") + public String getV0() { + return v0; + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: casbin_rule.v0") + public void setV0(String v0) { + this.v0 = v0 == null ? null : v0.trim(); + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: casbin_rule.v1") + public String getV1() { + return v1; + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: casbin_rule.v1") + public void setV1(String v1) { + this.v1 = v1 == null ? null : v1.trim(); + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: casbin_rule.v2") + public String getV2() { + return v2; + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: casbin_rule.v2") + public void setV2(String v2) { + this.v2 = v2 == null ? null : v2.trim(); + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: casbin_rule.v3") + public String getV3() { + return v3; + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: casbin_rule.v3") + public void setV3(String v3) { + this.v3 = v3 == null ? null : v3.trim(); + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: casbin_rule.v4") + public String getV4() { + return v4; + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: casbin_rule.v4") + public void setV4(String v4) { + this.v4 = v4 == null ? null : v4.trim(); + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: casbin_rule.v5") + public String getV5() { + return v5; + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: casbin_rule.v5") + public void setV5(String v5) { + this.v5 = v5 == null ? null : v5.trim(); + } +} diff --git a/backend/java/sk-matrix-service/orm/src/main/java/cn/skcks/matrix/v2/orm/mybatis/dynamic/model/LocationRecord.java b/backend/java/sk-matrix-service/orm/src/main/java/cn/skcks/matrix/v2/orm/mybatis/dynamic/model/LocationRecord.java new file mode 100644 index 0000000..d8b5354 --- /dev/null +++ b/backend/java/sk-matrix-service/orm/src/main/java/cn/skcks/matrix/v2/orm/mybatis/dynamic/model/LocationRecord.java @@ -0,0 +1,284 @@ +package cn.skcks.matrix.v2.orm.mybatis.dynamic.model; + +import java.util.Date; +import javax.annotation.Generated; + +/** + * + * This class was generated by MyBatis Generator. + * This class corresponds to the database table location_record + */ +public class LocationRecord { + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: location_record.id") + private String id; + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: location_record.callback_time") + private Date callbackTime; + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: location_record.location_time") + private Date locationTime; + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: location_record.location_type") + private Integer locationType; + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: location_record.latitude") + private Double latitude; + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: location_record.longitude") + private Double longitude; + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: location_record.accuracy") + private Double accuracy; + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: location_record.altitude") + private Double altitude; + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: location_record.bearing") + private Double bearing; + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: location_record.speed") + private Double speed; + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: location_record.country") + private String country; + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: location_record.province") + private String province; + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: location_record.city") + private String city; + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: location_record.district") + private String district; + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: location_record.street") + private String street; + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: location_record.street_number") + private String streetNumber; + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: location_record.city_code") + private String cityCode; + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: location_record.ad_code") + private String adCode; + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: location_record.address") + private String address; + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: location_record.description") + private String description; + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: location_record.user_id") + private Long userId; + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: location_record.id") + public String getId() { + return id; + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: location_record.id") + public void setId(String id) { + this.id = id == null ? null : id.trim(); + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: location_record.callback_time") + public Date getCallbackTime() { + return callbackTime; + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: location_record.callback_time") + public void setCallbackTime(Date callbackTime) { + this.callbackTime = callbackTime; + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: location_record.location_time") + public Date getLocationTime() { + return locationTime; + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: location_record.location_time") + public void setLocationTime(Date locationTime) { + this.locationTime = locationTime; + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: location_record.location_type") + public Integer getLocationType() { + return locationType; + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: location_record.location_type") + public void setLocationType(Integer locationType) { + this.locationType = locationType; + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: location_record.latitude") + public Double getLatitude() { + return latitude; + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: location_record.latitude") + public void setLatitude(Double latitude) { + this.latitude = latitude; + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: location_record.longitude") + public Double getLongitude() { + return longitude; + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: location_record.longitude") + public void setLongitude(Double longitude) { + this.longitude = longitude; + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: location_record.accuracy") + public Double getAccuracy() { + return accuracy; + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: location_record.accuracy") + public void setAccuracy(Double accuracy) { + this.accuracy = accuracy; + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: location_record.altitude") + public Double getAltitude() { + return altitude; + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: location_record.altitude") + public void setAltitude(Double altitude) { + this.altitude = altitude; + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: location_record.bearing") + public Double getBearing() { + return bearing; + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: location_record.bearing") + public void setBearing(Double bearing) { + this.bearing = bearing; + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: location_record.speed") + public Double getSpeed() { + return speed; + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: location_record.speed") + public void setSpeed(Double speed) { + this.speed = speed; + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: location_record.country") + public String getCountry() { + return country; + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: location_record.country") + public void setCountry(String country) { + this.country = country == null ? null : country.trim(); + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: location_record.province") + public String getProvince() { + return province; + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: location_record.province") + public void setProvince(String province) { + this.province = province == null ? null : province.trim(); + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: location_record.city") + public String getCity() { + return city; + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: location_record.city") + public void setCity(String city) { + this.city = city == null ? null : city.trim(); + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: location_record.district") + public String getDistrict() { + return district; + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: location_record.district") + public void setDistrict(String district) { + this.district = district == null ? null : district.trim(); + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: location_record.street") + public String getStreet() { + return street; + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: location_record.street") + public void setStreet(String street) { + this.street = street == null ? null : street.trim(); + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: location_record.street_number") + public String getStreetNumber() { + return streetNumber; + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: location_record.street_number") + public void setStreetNumber(String streetNumber) { + this.streetNumber = streetNumber == null ? null : streetNumber.trim(); + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: location_record.city_code") + public String getCityCode() { + return cityCode; + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: location_record.city_code") + public void setCityCode(String cityCode) { + this.cityCode = cityCode == null ? null : cityCode.trim(); + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: location_record.ad_code") + public String getAdCode() { + return adCode; + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: location_record.ad_code") + public void setAdCode(String adCode) { + this.adCode = adCode == null ? null : adCode.trim(); + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: location_record.address") + public String getAddress() { + return address; + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: location_record.address") + public void setAddress(String address) { + this.address = address == null ? null : address.trim(); + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: location_record.description") + public String getDescription() { + return description; + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: location_record.description") + public void setDescription(String description) { + this.description = description == null ? null : description.trim(); + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: location_record.user_id") + public Long getUserId() { + return userId; + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: location_record.user_id") + public void setUserId(Long userId) { + this.userId = userId; + } +} diff --git a/backend/java/sk-matrix-service/orm/src/main/java/cn/skcks/matrix/v2/orm/mybatis/dynamic/model/Role.java b/backend/java/sk-matrix-service/orm/src/main/java/cn/skcks/matrix/v2/orm/mybatis/dynamic/model/Role.java new file mode 100644 index 0000000..f762211 --- /dev/null +++ b/backend/java/sk-matrix-service/orm/src/main/java/cn/skcks/matrix/v2/orm/mybatis/dynamic/model/Role.java @@ -0,0 +1,87 @@ +package cn.skcks.matrix.v2.orm.mybatis.dynamic.model; + +import javax.annotation.Generated; + +/** + * + * This class was generated by MyBatis Generator. + * This class corresponds to the database table role + */ +public class Role { + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: role.id") + private Long id; + + /** + * Database Column Remarks: + * 角色 + */ + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: role.role") + private String role; + + /** + * Database Column Remarks: + * 角色名 + */ + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: role.name") + private String name; + + /** + * Database Column Remarks: + * 所属系统 + */ + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: role.system_id") + private String systemId; + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: role.active") + private Boolean active; + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: role.id") + public Long getId() { + return id; + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: role.id") + public void setId(Long id) { + this.id = id; + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: role.role") + public String getRole() { + return role; + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: role.role") + public void setRole(String role) { + this.role = role == null ? null : role.trim(); + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: role.name") + public String getName() { + return name; + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: role.name") + public void setName(String name) { + this.name = name == null ? null : name.trim(); + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: role.system_id") + public String getSystemId() { + return systemId; + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: role.system_id") + public void setSystemId(String systemId) { + this.systemId = systemId == null ? null : systemId.trim(); + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: role.active") + public Boolean getActive() { + return active; + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: role.active") + public void setActive(Boolean active) { + this.active = active; + } +} diff --git a/backend/java/sk-matrix-service/orm/src/main/java/cn/skcks/matrix/v2/orm/mybatis/dynamic/model/User.java b/backend/java/sk-matrix-service/orm/src/main/java/cn/skcks/matrix/v2/orm/mybatis/dynamic/model/User.java new file mode 100644 index 0000000..e2928f5 --- /dev/null +++ b/backend/java/sk-matrix-service/orm/src/main/java/cn/skcks/matrix/v2/orm/mybatis/dynamic/model/User.java @@ -0,0 +1,136 @@ +package cn.skcks.matrix.v2.orm.mybatis.dynamic.model; + +import java.util.Date; +import javax.annotation.Generated; + +/** + * + * This class was generated by MyBatis Generator. + * This class corresponds to the database table user + */ +public class User { + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: user.id") + private Long id; + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: user.user_name") + private String userName; + + /** + * Database Column Remarks: + * 加密后的密码 + */ + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: user.password") + private String password; + + /** + * Database Column Remarks: + * 加密密钥 + */ + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: user.salt") + private String salt; + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: user.email") + private String email; + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: user.phone_number") + private String phoneNumber; + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: user.description") + private String description; + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: user.create_time") + private Date createTime; + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: user.update_time") + private Date updateTime; + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: user.id") + public Long getId() { + return id; + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: user.id") + public void setId(Long id) { + this.id = id; + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: user.user_name") + public String getUserName() { + return userName; + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: user.user_name") + public void setUserName(String userName) { + this.userName = userName == null ? null : userName.trim(); + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: user.password") + public String getPassword() { + return password; + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: user.password") + public void setPassword(String password) { + this.password = password == null ? null : password.trim(); + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: user.salt") + public String getSalt() { + return salt; + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: user.salt") + public void setSalt(String salt) { + this.salt = salt == null ? null : salt.trim(); + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: user.email") + public String getEmail() { + return email; + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: user.email") + public void setEmail(String email) { + this.email = email == null ? null : email.trim(); + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: user.phone_number") + public String getPhoneNumber() { + return phoneNumber; + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: user.phone_number") + public void setPhoneNumber(String phoneNumber) { + this.phoneNumber = phoneNumber == null ? null : phoneNumber.trim(); + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: user.description") + public String getDescription() { + return description; + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: user.description") + public void setDescription(String description) { + this.description = description == null ? null : description.trim(); + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: user.create_time") + public Date getCreateTime() { + return createTime; + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: user.create_time") + public void setCreateTime(Date createTime) { + this.createTime = createTime; + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: user.update_time") + public Date getUpdateTime() { + return updateTime; + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: user.update_time") + public void setUpdateTime(Date updateTime) { + this.updateTime = updateTime; + } +} diff --git a/backend/java/sk-matrix-service/orm/src/main/java/cn/skcks/matrix/v2/orm/mybatis/operation/OperateTableMapper.java b/backend/java/sk-matrix-service/orm/src/main/java/cn/skcks/matrix/v2/orm/mybatis/operation/OperateTableMapper.java new file mode 100644 index 0000000..e0fe28b --- /dev/null +++ b/backend/java/sk-matrix-service/orm/src/main/java/cn/skcks/matrix/v2/orm/mybatis/operation/OperateTableMapper.java @@ -0,0 +1,12 @@ +package cn.skcks.matrix.v2.orm.mybatis.operation; + +import org.apache.ibatis.annotations.Mapper; + +@Mapper +public interface OperateTableMapper { + // int createNewTable(@Param("tableName")String tableName); + void createUserTable(); + void createRoleTable(); + + void createLocationRecordTable(); +} diff --git a/backend/java/sk-matrix-service/orm/src/main/java/cn/skcks/matrix/v2/orm/mybatis/operation/OperateTableMapper.xml b/backend/java/sk-matrix-service/orm/src/main/java/cn/skcks/matrix/v2/orm/mybatis/operation/OperateTableMapper.xml new file mode 100644 index 0000000..efb0761 --- /dev/null +++ b/backend/java/sk-matrix-service/orm/src/main/java/cn/skcks/matrix/v2/orm/mybatis/operation/OperateTableMapper.xml @@ -0,0 +1,66 @@ + + + + + + CREATE TABLE IF NOT EXISTS `user` + ( + `id` bigint NOT NULL, + `user_name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL, + `password` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '加密后的密码', + `salt` varchar(255) COLLATE utf8mb4_general_ci NOT NULL COMMENT '加密密钥', + `email` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL, + `phone_number` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL, + `description` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL, + `create_time` datetime NOT NULL, + `update_time` datetime NOT NULL, + PRIMARY KEY (`id`) + ) ENGINE = InnoDB + DEFAULT CHARSET = utf8mb4 + COLLATE = utf8mb4_general_ci; + + + + CREATE TABLE IF NOT EXISTS `role` + ( + `id` bigint NOT NULL, + `role` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '角色', + `name` varchar(255) COLLATE utf8mb4_general_ci NOT NULL COMMENT '角色名', + `system_id` varchar(255) COLLATE utf8mb4_general_ci NOT NULL COMMENT '所属系统', + `active` tinyint(1) NOT NULL, + PRIMARY KEY (`id`) + ) ENGINE = InnoDB + DEFAULT CHARSET = utf8mb4 + COLLATE = utf8mb4_general_ci; + + + + CREATE TABLE IF NOT EXISTS `location_record` ( + `id` varchar(255) NOT NULL, + `callback_time` datetime DEFAULT NULL, + `location_time` datetime DEFAULT NULL, + `location_type` int DEFAULT NULL, + `latitude` double DEFAULT NULL, + `longitude` double DEFAULT NULL, + `accuracy` double DEFAULT NULL, + `altitude` double DEFAULT NULL, + `bearing` double DEFAULT NULL, + `speed` double DEFAULT NULL, + `country` varchar(255) DEFAULT NULL, + `province` varchar(255) DEFAULT NULL, + `city` varchar(255) DEFAULT NULL, + `district` varchar(255) DEFAULT NULL, + `street` varchar(255) DEFAULT NULL, + `street_number` varchar(255) DEFAULT NULL, + `city_code` varchar(255) DEFAULT NULL, + `ad_code` varchar(255) DEFAULT NULL, + `address` varchar(255) DEFAULT NULL, + `description` varchar(255) DEFAULT NULL, + `user_id` bigint NOT NULL, + PRIMARY KEY (`id`) + ) ENGINE=InnoDB + DEFAULT CHARSET = utf8mb4 + COLLATE = utf8mb4_general_ci; + + diff --git a/backend/java/sk-matrix-service/orm/src/main/resources/application.yaml b/backend/java/sk-matrix-service/orm/src/main/resources/application.yaml new file mode 100644 index 0000000..b212c69 --- /dev/null +++ b/backend/java/sk-matrix-service/orm/src/main/resources/application.yaml @@ -0,0 +1,76 @@ +spring: + profiles: + active: default + +--- +spring: + shardingsphere: + props: + sql-show: true + sql: + show: true + datasource: + names: ds + ds: +# type: com.zaxxer.hikari.HikariDataSource + type: com.alibaba.druid.pool.DruidDataSource + driver-class-name: com.mysql.cj.jdbc.Driver + username: root + password: 12341234 + url: jdbc:mysql://10.10.10.200:3306/matrix_v2?createDatabaseIfNotExist=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai +# jdbc-url: jdbc:mysql://10.10.10.100:3306/matrix?createDatabaseIfNotExist=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai + + rules: + sharding: +# tables: +# user: +# actual-data-nodes: ds.user_$->{0..2} +# table-strategy: +# standard: +# sharding-column: id +# sharding-algorithm-name: user-id + auto-tables: + user: + actual-data-sources: ds + sharding-strategy: + standard: + sharding-column: id + sharding-algorithm-name: user-id + sharding-algorithms: + user-id: +# 内置分片算法 + type: MOD + props: + sharding-count: 3 + config: + activate: + on-profile: default +# 行内表达式 +# type: INLINE +# props: +# algorithm-expression: user_$->{id % 3} +# mode: +# type: Standalone + +--- +spring: + config: + activate: + on-profile: pre-dev + + shardingsphere: + enabled: false + + datasource: + type: com.alibaba.druid.pool.DruidDataSource + driver-class-name: com.mysql.cj.jdbc.Driver + username: root + password: 12341234 + url: jdbc:mysql://10.10.10.200:3306/matrix_schema_v2?createDatabaseIfNotExist=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai + sql: + init: + mode: ALWAYS + schema-locations: + - classpath:schema/*.sql + username: root + password: 12341234 diff --git a/backend/java/sk-matrix-service/orm/src/main/resources/config/generatorConfig.xml b/backend/java/sk-matrix-service/orm/src/main/resources/config/generatorConfig.xml new file mode 100644 index 0000000..3fee4eb --- /dev/null +++ b/backend/java/sk-matrix-service/orm/src/main/resources/config/generatorConfig.xml @@ -0,0 +1,402 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + +
+
diff --git a/backend/java/sk-matrix-service/orm/src/main/resources/schema/location_record.sql b/backend/java/sk-matrix-service/orm/src/main/resources/schema/location_record.sql new file mode 100644 index 0000000..aea0b3c --- /dev/null +++ b/backend/java/sk-matrix-service/orm/src/main/resources/schema/location_record.sql @@ -0,0 +1,26 @@ +CREATE TABLE IF NOT EXISTS `location_record` ( + `id` varchar(255) NOT NULL, + `callback_time` datetime DEFAULT NULL, + `location_time` datetime DEFAULT NULL, + `location_type` int DEFAULT NULL, + `latitude` double DEFAULT NULL, + `longitude` double DEFAULT NULL, + `accuracy` double DEFAULT NULL, + `altitude` double DEFAULT NULL, + `bearing` double DEFAULT NULL, + `speed` double DEFAULT NULL, + `country` varchar(255) DEFAULT NULL, + `province` varchar(255) DEFAULT NULL, + `city` varchar(255) DEFAULT NULL, + `district` varchar(255) DEFAULT NULL, + `street` varchar(255) DEFAULT NULL, + `street_number` varchar(255) DEFAULT NULL, + `city_code` varchar(255) DEFAULT NULL, + `ad_code` varchar(255) DEFAULT NULL, + `address` varchar(255) DEFAULT NULL, + `description` varchar(255) DEFAULT NULL, + `user_id` bigint NOT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB +DEFAULT CHARSET = utf8mb4 +COLLATE = utf8mb4_general_ci; diff --git a/backend/java/sk-matrix-service/orm/src/main/resources/schema/role.sql b/backend/java/sk-matrix-service/orm/src/main/resources/schema/role.sql new file mode 100644 index 0000000..907e74b --- /dev/null +++ b/backend/java/sk-matrix-service/orm/src/main/resources/schema/role.sql @@ -0,0 +1,11 @@ +CREATE TABLE IF NOT EXISTS `role` +( + `id` bigint NOT NULL, + `role` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '角色', + `name` varchar(255) COLLATE utf8mb4_general_ci NOT NULL COMMENT '角色名', + `system_id` varchar(255) COLLATE utf8mb4_general_ci NOT NULL COMMENT '所属系统', + `active` tinyint(1) NOT NULL, + PRIMARY KEY (`id`) +) ENGINE = InnoDB + DEFAULT CHARSET = utf8mb4 + COLLATE = utf8mb4_general_ci; \ No newline at end of file diff --git a/backend/java/sk-matrix-service/orm/src/main/resources/schema/user.sql b/backend/java/sk-matrix-service/orm/src/main/resources/schema/user.sql new file mode 100644 index 0000000..17fde55 --- /dev/null +++ b/backend/java/sk-matrix-service/orm/src/main/resources/schema/user.sql @@ -0,0 +1,12 @@ +CREATE TABLE IF NOT EXISTS `user` ( + `id` bigint NOT NULL, + `user_name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL, + `password` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '加密后的密码', + `salt` varchar(255) COLLATE utf8mb4_general_ci NOT NULL COMMENT '加密密钥', + `email` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL, + `phone_number` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL, + `description` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL, + `create_time` datetime NOT NULL, + `update_time` datetime NOT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; \ No newline at end of file diff --git a/backend/java/sk-matrix-service/orm/src/test/java/cn/skcks/matrix/orm/mybatis/GenerateSchemaTest.java b/backend/java/sk-matrix-service/orm/src/test/java/cn/skcks/matrix/orm/mybatis/GenerateSchemaTest.java new file mode 100644 index 0000000..da05150 --- /dev/null +++ b/backend/java/sk-matrix-service/orm/src/test/java/cn/skcks/matrix/orm/mybatis/GenerateSchemaTest.java @@ -0,0 +1,18 @@ +package cn.skcks.matrix.v2.orm.mybatis; + +import org.apache.shardingsphere.spring.boot.ShardingSphereAutoConfiguration; +import org.junit.jupiter.api.Test; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.ActiveProfiles; + +// 生成 schema 元数据 表 +@ActiveProfiles("pre-dev") +@SpringBootApplication(exclude = ShardingSphereAutoConfiguration.class) +@SpringBootTest(classes = {GenerateSchemaTest.class}) +public class GenerateSchemaTest { + @Test + void contextLoads(){ + + } +} diff --git a/backend/java/sk-matrix-service/pom.xml b/backend/java/sk-matrix-service/pom.xml new file mode 100644 index 0000000..68c1b10 --- /dev/null +++ b/backend/java/sk-matrix-service/pom.xml @@ -0,0 +1,279 @@ + + + 4.0.0 + + cn.skcks.matrix.v2 + sk-matrix-service + 1.0-SNAPSHOT + pom + + + org.springframework.boot + spring-boot-starter-parent + 3.0.1 + + + + + common + annotation + starter + orm + casbin + api + + + + 17 + 17 + UTF-8 + 17 + + 3.10.1 + 2.22.2 + + 3.0.1 + 1.5.3.Final + 1.18.24 + 7.7.3 + 8.0.31 + 3.0.1 + 1.4.1 + 1.4.1 + 1.2.15 + 1.33 + 5.8.11 + 1.4.6 + 10.1.4 + 5.2.1 + 5.9.0 + 2.0.2 + 2.2.7 + 0.6.0 + 2.4.0 + 1.4.6 + + + + + + + org.apache.shardingsphere + shardingsphere-jdbc-core-spring-boot-starter + ${shardingsphere.version} + + + + org.apache.tomcat + tomcat-dbcp + ${tomcat-dbcp.version} + + + + com.github.pagehelper + pagehelper-spring-boot-starter + ${pagehelper.version} + + + + cn.hutool + hutool-all + ${hutool.version} + + + + org.yaml + snakeyaml + ${snakeyaml.version} + + + + org.mapstruct + mapstruct + ${org.mapstruct.version} + + + org.mapstruct + mapstruct-processor + ${org.mapstruct.version} + compile + + + + + org.projectlombok + lombok + ${lombok.version} + provided + + + + + org.mybatis.spring.boot + mybatis-spring-boot-starter + ${mybatis.version} + + + + + org.mybatis.dynamic-sql + mybatis-dynamic-sql + ${mybatis-dynamic.version} + + + + + com.alibaba + druid + ${druid.version} + + + + + org.junit.jupiter + junit-jupiter-api + ${junit.version} + + + + org.springframework.boot + spring-boot-starter-web + ${springboot.version} + + + org.springframework.boot + spring-boot-starter-tomcat + + + + + + org.springframework.boot + spring-boot-starter-undertow + ${springboot.version} + + + + + org.springdoc + springdoc-openapi-starter-common + ${springdoc.version} + + + + org.springdoc + springdoc-openapi-starter-webmvc-ui + ${springdoc.version} + + + + + org.casbin + casbin-spring-boot-starter + ${casbin.version} + + + + org.casbin + jdbc-adapter + ${casbin-jdbc-adapter.version} + + + + + + + + + org.mybatis.generator + mybatis-generator-maven-plugin + ${mybatis-generator-maven-plugin.version} + + + src/main/resources/config/generatorConfig.xml + true + true + + + + Generate MyBatis Artifacts + + generate + + + + + + mysql + mysql-connector-java + ${mysql.version} + + + + + + + + + + + + + + + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + ${maven-compiler-plugin.version} + + + + org.mapstruct + mapstruct-processor + ${org.mapstruct.version} + + + + org.projectlombok + lombok + ${lombok.version} + + + + org.springframework.boot + spring-boot-configuration-processor + ${springboot.version} + + + + + + + + org.apache.maven.plugins + maven-surefire-plugin + ${maven-surefire-plugin.version} + + true + + + + + + src/main/resources + + **/** + + true + + + + diff --git a/backend/java/sk-matrix-service/starter/pom.xml b/backend/java/sk-matrix-service/starter/pom.xml new file mode 100644 index 0000000..7d121dd --- /dev/null +++ b/backend/java/sk-matrix-service/starter/pom.xml @@ -0,0 +1,64 @@ + + + 4.0.0 + + cn.skcks.matrix.v2 + sk-matrix-service + 1.0-SNAPSHOT + + + starter + + + 17 + 17 + UTF-8 + + + + + cn.skcks.matrix.v2 + api + ${project.version} + + + + org.springframework.boot + spring-boot-starter + + + + org.springframework.boot + spring-boot-starter-web + + + + org.springframework.boot + spring-boot-starter-undertow + ${springboot.version} + + + + + org.springframework.boot + spring-boot-devtools + runtime + true + + + + + org.springframework + spring-context-indexer + true + + + + org.springframework.boot + spring-boot-starter-test + test + + + diff --git a/backend/java/sk-matrix-service/starter/src/main/java/cn/skcks/matrix/v2/Application.java b/backend/java/sk-matrix-service/starter/src/main/java/cn/skcks/matrix/v2/Application.java new file mode 100644 index 0000000..5f33fe5 --- /dev/null +++ b/backend/java/sk-matrix-service/starter/src/main/java/cn/skcks/matrix/v2/Application.java @@ -0,0 +1,12 @@ +package cn.skcks.matrix.v2; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; + +@SpringBootApplication(exclude= DataSourceAutoConfiguration.class) +public class Application { + public static void main(String[] args) { + SpringApplication.run(Application.class,args); + } +} diff --git a/backend/java/sk-matrix-service/starter/src/main/resources/application.yaml b/backend/java/sk-matrix-service/starter/src/main/resources/application.yaml new file mode 100644 index 0000000..6105b49 --- /dev/null +++ b/backend/java/sk-matrix-service/starter/src/main/resources/application.yaml @@ -0,0 +1,107 @@ +spring: + profiles: + active: default + +--- +server: + port: 45680 + +jwt: + generate-key-pair-every-time: false + expire: 24h +# publicCacheKey: jwt-public +# privateCacheKey: jwt-paivate + +spring: + h2: + console: + enabled: false + data: + redis: + database: 0 + host: 10.10.10.200 + port: 16379 + password: 12341234 + jedis: + pool: + min-idle: 0 + max-active: 8 + max-idle: 8 + max-wait: -1ms + connect-timeout: 30000ms + + shardingsphere: + props: + sql-simple: false + sql-show: true + datasource: + names: ds + ds: + # type: com.zaxxer.hikari.HikariDataSource + type: com.alibaba.druid.pool.DruidDataSource + driver-class-name: com.mysql.cj.jdbc.Driver + username: root + password: 12341234 + url: jdbc:mysql://10.10.10.200:3306/matrix?createDatabaseIfNotExist=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai + # jdbc-url: jdbc:mysql://10.10.10.100:3306/matrix?createDatabaseIfNotExist=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai + + rules: + sharding: + # tables: + # user: + # actual-data-nodes: ds.user_$->{0..2} + # table-strategy: + # standard: + # sharding-column: id + # sharding-algorithm-name: user-id + auto-tables: + user: + actual-data-sources: ds + sharding-strategy: + standard: + sharding-column: id + sharding-algorithm-name: general-id + casbin_rule: + actual-data-sources: ds + sharding-strategy: + standard: + sharding-column: id + sharding-algorithm-name: general-id + sharding-algorithms: + general-id: + # 内置分片算法 + type: MOD + props: + sharding-count: 3 + config: + activate: + on-profile: default +# 行内表达式 +# type: INLINE +# props: +# algorithm-expression: user_$->{id % 3} +# mode: +# type: Standalone +casbin: + enable-casbin: true + auto-save: true + initializeSchema: create + storeType: jdbc + model: classpath:casbin/model.conf + +springdoc: + api-docs: + # path: /api/docs + # 在线文档JSON格式数据 + enabled: true + groups: + enabled: true + swagger-ui: + # 在线 Swagger UI + enabled: true + # 默认访问路径 /swagger-ui.html + # path: /swagger-ui.html + # layout: BaseLayout + doc-expansion: list + layout: StandaloneLayout + filter: true