commit d13dd95ceaec2f147e7ba177673b1ec27a5688b8 Author: shikong <919411476@qq.com> Date: Mon Apr 15 01:52:44 2024 +0800 项目起手式 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5ff6309 --- /dev/null +++ b/.gitignore @@ -0,0 +1,38 @@ +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### IntelliJ IDEA ### +.idea/modules.xml +.idea/jarRepositories.xml +.idea/compiler.xml +.idea/libraries/ +*.iws +*.iml +*.ipr + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..35410ca --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# 默认忽略的文件 +/shelf/ +/workspace.xml +# 基于编辑器的 HTTP 客户端请求 +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/dataSources.xml b/.idea/dataSources.xml new file mode 100644 index 0000000..02b5175 --- /dev/null +++ b/.idea/dataSources.xml @@ -0,0 +1,18 @@ + + + + + mysql.8 + true + true + com.mysql.cj.jdbc.Driver + jdbc:mysql://10.10.10.200:3306/wv-official-v2?createDatabaseIfNotExist=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai + + + + + + $ProjectFileDir$ + + + \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..1b228b4 --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..31c8b05 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,19 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/sqldialects.xml b/.idea/sqldialects.xml new file mode 100644 index 0000000..56782ca --- /dev/null +++ b/.idea/sqldialects.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml new file mode 100644 index 0000000..2b63946 --- /dev/null +++ b/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..83c0d78 --- /dev/null +++ b/pom.xml @@ -0,0 +1,240 @@ + + + 4.0.0 + + + org.springframework.boot + spring-boot-starter-parent + 3.2.4 + + + + cn.skcks.wx.official + wx-official + 0.1.0-SNAPSHOT + pom + + wx-official-orm + wx-official-starter + wx-official-api + wx-official-service + wx-official-common + + + + 17 + 17 + UTF-8 + + UTF-8 + UTF-8 + + 17 + + 3.2.4 + + + 1.5.3.Final + 1.18.24 + + + 2.2.0 + + + 5.8.11 + + + 1.4.13 + + + + + jar + + true + + + true + + + + + docker + + false + + + false + + + + + + + + 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.mapstruct + mapstruct + ${org.mapstruct.version} + + + org.mapstruct + mapstruct-processor + ${org.mapstruct.version} + compile + + + + + org.projectlombok + lombok + ${lombok.version} + provided + + + + + cn.hutool + hutool-all + ${hutool.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.projectlombok + lombok-mapstruct-binding + 0.2.0 + + + + org.springframework.boot + spring-boot-configuration-processor + ${springboot.version} + + + + + + + + org.apache.maven.plugins + maven-resources-plugin + ${maven-resources-plugin.version} + + + @ + + false + + + + + org.apache.maven.plugins + maven-surefire-plugin + ${maven-surefire-plugin.version} + + true + + + + + + com.spotify + dockerfile-maven-plugin + ${docker.maven.plugin.version} + + + default + + build + push + + + + + ${skip.docker} + skcks.cn/wx-official-accounts-v2 + ${project.version} + + ${project.build.finalName}.jar + + + + + + + + src/main/resources + + **/** + + true + + + + + + src/test/resources + + **/** + + true + + + + diff --git a/wx-official-api/pom.xml b/wx-official-api/pom.xml new file mode 100644 index 0000000..b374c6f --- /dev/null +++ b/wx-official-api/pom.xml @@ -0,0 +1,58 @@ + + + 4.0.0 + + cn.skcks.wx.official + wx-official + 0.1.0-SNAPSHOT + + + wx-official-api + + + 17 + 17 + UTF-8 + + + + + cn.skcks.wx.official + wx-official-service + ${project.version} + + + + cn.skcks.wx.official + wx-official-common + ${project.version} + + + + org.springdoc + springdoc-openapi-starter-webmvc-ui + ${springdoc.version} + + + + org.springdoc + springdoc-openapi-starter-common + + + + org.springframework.boot + spring-boot-starter-web + + + org.projectlombok + lombok + compile + + + jakarta.servlet + jakarta.servlet-api + + + diff --git a/wx-official-api/src/main/java/cn/skcks/wx/official/api/config/SwaggerConfig.java b/wx-official-api/src/main/java/cn/skcks/wx/official/api/config/SwaggerConfig.java new file mode 100644 index 0000000..eeeafd8 --- /dev/null +++ b/wx-official-api/src/main/java/cn/skcks/wx/official/api/config/SwaggerConfig.java @@ -0,0 +1,53 @@ +package cn.skcks.wx.official.api.config; + +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("微信公众号平台 API") + .description("微信公众号平台") + .version("0.1.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/wx-official-api/src/main/java/cn/skcks/wx/official/api/config/WebConfig.java b/wx-official-api/src/main/java/cn/skcks/wx/official/api/config/WebConfig.java new file mode 100644 index 0000000..cbb896f --- /dev/null +++ b/wx-official-api/src/main/java/cn/skcks/wx/official/api/config/WebConfig.java @@ -0,0 +1,22 @@ +package cn.skcks.wx.official.api.config; + +import cn.skcks.wx.official.api.interceptor.RequestInterceptor; +import jakarta.validation.constraints.NotNull; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.servlet.config.annotation.InterceptorRegistry; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; + +@Slf4j +@Configuration +@RequiredArgsConstructor +public class WebConfig implements WebMvcConfigurer { + private final RequestInterceptor requestInterceptor; + @Override + public void addInterceptors(@NotNull InterceptorRegistry registry) { + registry.addInterceptor(requestInterceptor) + .excludePathPatterns("/swagger-ui/**","/v3/api-docs/**") + .addPathPatterns("/**"); + } +} diff --git a/wx-official-api/src/main/java/cn/skcks/wx/official/api/interceptor/RequestInterceptor.java b/wx-official-api/src/main/java/cn/skcks/wx/official/api/interceptor/RequestInterceptor.java new file mode 100644 index 0000000..df7cd62 --- /dev/null +++ b/wx-official-api/src/main/java/cn/skcks/wx/official/api/interceptor/RequestInterceptor.java @@ -0,0 +1,20 @@ +package cn.skcks.wx.official.api.interceptor; + +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; +import org.springframework.web.servlet.HandlerInterceptor; + +@Slf4j +@Component +@SuppressWarnings({"unused"}) +@RequiredArgsConstructor +public class RequestInterceptor implements HandlerInterceptor { + @Override + public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { + log.info("{} 访问 {}",request.getRemoteHost(), request.getRequestURI()); + return true; + } +} diff --git a/wx-official-common/pom.xml b/wx-official-common/pom.xml new file mode 100644 index 0000000..f3f77af --- /dev/null +++ b/wx-official-common/pom.xml @@ -0,0 +1,44 @@ + + + 4.0.0 + + cn.skcks.wx.official + wx-official + 0.1.0-SNAPSHOT + + + wx-official-common + + + 17 + 17 + UTF-8 + + + + + org.projectlombok + lombok + + + + org.mapstruct + mapstruct + + + + org.apache.commons + commons-lang3 + + + org.springframework + spring-core + + + org.springframework + spring-web + + + diff --git a/wx-official-common/src/main/java/cn/skcks/wx/official/common/annotation/web/JsonMapping.java b/wx-official-common/src/main/java/cn/skcks/wx/official/common/annotation/web/JsonMapping.java new file mode 100644 index 0000000..7899aaf --- /dev/null +++ b/wx-official-common/src/main/java/cn/skcks/wx/official/common/annotation/web/JsonMapping.java @@ -0,0 +1,64 @@ +package cn.skcks.wx.official.common.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/wx-official-common/src/main/java/cn/skcks/wx/official/common/annotation/web/methods/DeleteJson.java b/wx-official-common/src/main/java/cn/skcks/wx/official/common/annotation/web/methods/DeleteJson.java new file mode 100644 index 0000000..00db156 --- /dev/null +++ b/wx-official-common/src/main/java/cn/skcks/wx/official/common/annotation/web/methods/DeleteJson.java @@ -0,0 +1,54 @@ +package cn.skcks.wx.official.common.annotation.web.methods; + +import cn.skcks.wx.official.common.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/wx-official-common/src/main/java/cn/skcks/wx/official/common/annotation/web/methods/GetJson.java b/wx-official-common/src/main/java/cn/skcks/wx/official/common/annotation/web/methods/GetJson.java new file mode 100644 index 0000000..43ac743 --- /dev/null +++ b/wx-official-common/src/main/java/cn/skcks/wx/official/common/annotation/web/methods/GetJson.java @@ -0,0 +1,54 @@ +package cn.skcks.wx.official.common.annotation.web.methods; + +import cn.skcks.wx.official.common.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/wx-official-common/src/main/java/cn/skcks/wx/official/common/annotation/web/methods/HeadJson.java b/wx-official-common/src/main/java/cn/skcks/wx/official/common/annotation/web/methods/HeadJson.java new file mode 100644 index 0000000..323c59e --- /dev/null +++ b/wx-official-common/src/main/java/cn/skcks/wx/official/common/annotation/web/methods/HeadJson.java @@ -0,0 +1,55 @@ +package cn.skcks.wx.official.common.annotation.web.methods; + + +import cn.skcks.wx.official.common.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/wx-official-common/src/main/java/cn/skcks/wx/official/common/annotation/web/methods/OptionsJson.java b/wx-official-common/src/main/java/cn/skcks/wx/official/common/annotation/web/methods/OptionsJson.java new file mode 100644 index 0000000..5afa497 --- /dev/null +++ b/wx-official-common/src/main/java/cn/skcks/wx/official/common/annotation/web/methods/OptionsJson.java @@ -0,0 +1,55 @@ +package cn.skcks.wx.official.common.annotation.web.methods; + + +import cn.skcks.wx.official.common.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/wx-official-common/src/main/java/cn/skcks/wx/official/common/annotation/web/methods/PatchJson.java b/wx-official-common/src/main/java/cn/skcks/wx/official/common/annotation/web/methods/PatchJson.java new file mode 100644 index 0000000..15ddb18 --- /dev/null +++ b/wx-official-common/src/main/java/cn/skcks/wx/official/common/annotation/web/methods/PatchJson.java @@ -0,0 +1,54 @@ +package cn.skcks.wx.official.common.annotation.web.methods; + +import cn.skcks.wx.official.common.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/wx-official-common/src/main/java/cn/skcks/wx/official/common/annotation/web/methods/PostJson.java b/wx-official-common/src/main/java/cn/skcks/wx/official/common/annotation/web/methods/PostJson.java new file mode 100644 index 0000000..d68581c --- /dev/null +++ b/wx-official-common/src/main/java/cn/skcks/wx/official/common/annotation/web/methods/PostJson.java @@ -0,0 +1,54 @@ +package cn.skcks.wx.official.common.annotation.web.methods; + +import cn.skcks.wx.official.common.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/wx-official-common/src/main/java/cn/skcks/wx/official/common/annotation/web/methods/PutJson.java b/wx-official-common/src/main/java/cn/skcks/wx/official/common/annotation/web/methods/PutJson.java new file mode 100644 index 0000000..b2599e7 --- /dev/null +++ b/wx-official-common/src/main/java/cn/skcks/wx/official/common/annotation/web/methods/PutJson.java @@ -0,0 +1,54 @@ +package cn.skcks.wx.official.common.annotation.web.methods; + +import cn.skcks.wx.official.common.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/wx-official-common/src/main/java/cn/skcks/wx/official/common/annotation/web/methods/TraceJson.java b/wx-official-common/src/main/java/cn/skcks/wx/official/common/annotation/web/methods/TraceJson.java new file mode 100644 index 0000000..e5a422b --- /dev/null +++ b/wx-official-common/src/main/java/cn/skcks/wx/official/common/annotation/web/methods/TraceJson.java @@ -0,0 +1,54 @@ +package cn.skcks.wx.official.common.annotation.web.methods; + +import cn.skcks.wx.official.common.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/wx-official-orm/pom.xml b/wx-official-orm/pom.xml new file mode 100644 index 0000000..b5f2fe9 --- /dev/null +++ b/wx-official-orm/pom.xml @@ -0,0 +1,158 @@ + + + 4.0.0 + + cn.skcks.wx.official + wx-official + 0.1.0-SNAPSHOT + + + wx-official-orm + + + 17 + 17 + UTF-8 + + 1.8.7 + + + + + + com.mybatis-flex + mybatis-flex-dependencies + ${mybatis-flex.version} + pom + import + + + + + + + org.projectlombok + lombok + + + + org.mapstruct + mapstruct + + + + com.mybatis-flex + mybatis-flex-spring-boot3-starter + + + com.mybatis-flex + mybatis-flex-processor + provided + + + + com.mybatis-flex + mybatis-flex-codegen + + + + com.zaxxer + HikariCP + + + + com.mysql + mysql-connector-j + + + + org.liquibase + liquibase-core + test + + + + org.springframework.boot + spring-boot-test + test + + + + + + + src/main/java + + **/** + + + + src/main/resources + + **/** + + + + + + + src/test/resources + + **/** + + true + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + 1.8 + 1.8 + + + org.mapstruct + mapstruct-processor + ${org.mapstruct.version} + + + + org.projectlombok + lombok + ${lombok.version} + + + + org.projectlombok + lombok-mapstruct-binding + 0.2.0 + + + org.mapstruct + mapstruct-processor + ${org.mapstruct.version} + + + com.mybatis-flex + mybatis-flex-processor + ${mybatis-flex.version} + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + true + + + + + diff --git a/wx-official-orm/src/main/java/cn/skcks/wx/official/orm/entity/WxOfficialAccount.java b/wx-official-orm/src/main/java/cn/skcks/wx/official/orm/entity/WxOfficialAccount.java new file mode 100644 index 0000000..8614a3e --- /dev/null +++ b/wx-official-orm/src/main/java/cn/skcks/wx/official/orm/entity/WxOfficialAccount.java @@ -0,0 +1,57 @@ +package cn.skcks.wx.official.orm.entity; + +import com.mybatisflex.annotation.Id; +import com.mybatisflex.annotation.KeyType; +import com.mybatisflex.annotation.Table; +import java.io.Serializable; +import java.math.BigInteger; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; +import java.io.Serial; + +/** + * 设备通道信息 实体类。 + * + * @author shikong + * @since 2024-04-15 + */ +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +@Table(value = "wx_official_account", dataSource = "mysql") +public class WxOfficialAccount implements Serializable { + + @Serial + private static final long serialVersionUID = 1L; + + /** + * 主键id + */ + @Id(keyType = KeyType.Auto) + private BigInteger id; + + /** + * 微信公众号appid + */ + private String appId; + + /** + * 公众号账号 + */ + private String account; + + /** + * 第三方用户唯一凭证密钥 + */ + private String secret; + + /** + * 授权类型 + */ + private String grantType; + +} diff --git a/wx-official-orm/src/main/java/cn/skcks/wx/official/orm/mapper/WxOfficialAccountMapper.java b/wx-official-orm/src/main/java/cn/skcks/wx/official/orm/mapper/WxOfficialAccountMapper.java new file mode 100644 index 0000000..bf30291 --- /dev/null +++ b/wx-official-orm/src/main/java/cn/skcks/wx/official/orm/mapper/WxOfficialAccountMapper.java @@ -0,0 +1,14 @@ +package cn.skcks.wx.official.orm.mapper; + +import com.mybatisflex.core.BaseMapper; +import cn.skcks.wx.official.orm.entity.WxOfficialAccount; + +/** + * 设备通道信息 映射层。 + * + * @author shikong + * @since 2024-04-15 + */ +public interface WxOfficialAccountMapper extends BaseMapper { + +} diff --git a/wx-official-orm/src/main/resources/db/changelog.xml b/wx-official-orm/src/main/resources/db/changelog.xml new file mode 100644 index 0000000..eccf87d --- /dev/null +++ b/wx-official-orm/src/main/resources/db/changelog.xml @@ -0,0 +1,40 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/wx-official-orm/src/test/java/cn/skcks/wx/official/orm/OrmGenerator.java b/wx-official-orm/src/test/java/cn/skcks/wx/official/orm/OrmGenerator.java new file mode 100644 index 0000000..7ca75a2 --- /dev/null +++ b/wx-official-orm/src/test/java/cn/skcks/wx/official/orm/OrmGenerator.java @@ -0,0 +1,68 @@ +package cn.skcks.wx.official.orm; + +import com.mybatisflex.codegen.Generator; +import com.mybatisflex.codegen.config.GlobalConfig; +import com.mybatisflex.core.FlexGlobalConfig; +import com.mybatisflex.core.datasource.FlexDataSource; +import lombok.SneakyThrows; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.WebApplicationType; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +import javax.sql.DataSource; +import java.io.BufferedReader; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.util.Map; + +@SpringBootApplication +public class OrmGenerator { + public static void main(String[] args) { + SpringApplication springApplication = new SpringApplication(OrmGenerator.class); + springApplication.setAdditionalProfiles("generator"); + springApplication.setWebApplicationType(WebApplicationType.NONE); + springApplication.run(args); + generate(); + } + + @SneakyThrows + private static String getGitUserName() { + InputStream inputStream = Runtime.getRuntime().exec("git config user.name").getInputStream(); + BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream)); + return reader.readLine(); + } + + private static void generate() { + FlexDataSource flexDataSource = FlexGlobalConfig.getDefaultConfig().getDataSource(); + Map dataSourceMap = flexDataSource.getDataSourceMap(); + + generateByDataSource(dataSourceMap); + + } + + private static void generateByDataSource(Map dataSourceMap) { + DataSource mysql = dataSourceMap.get("mysql"); + //创建配置内容 + GlobalConfig globalConfig = new GlobalConfig(); + globalConfig.setBasePackage("cn.skcks.wx.official.orm"); + globalConfig.setSourceDir("./wx-official-orm/src/main/java"); + globalConfig.setAuthor(getGitUserName()); + + globalConfig.setEntityDataSource("mysql"); + globalConfig.setEntityGenerateEnable(true); + globalConfig.setEntityWithLombok(true); + globalConfig.setEntityGenerateEnable(true); + //设置生成 mapper + globalConfig.setMapperGenerateEnable(true); + //设置项目的JDK版本,项目的JDK为14及以上时建议设置该项,小于14则可以不设置 + globalConfig.setEntityJdkVersion(17); + // 是否覆盖已存在的文件 + globalConfig.setEntityOverwriteEnable(true); + + // 不生成的表 + globalConfig.setUnGenerateTable("DATABASECHANGELOG", "DATABASECHANGELOGLOCK"); + + Generator generator = new Generator(mysql, globalConfig); + generator.generate(); + } +} diff --git a/wx-official-orm/src/test/java/cn/skcks/wx/official/schema/SchemaGenerator.java b/wx-official-orm/src/test/java/cn/skcks/wx/official/schema/SchemaGenerator.java new file mode 100644 index 0000000..a46efb8 --- /dev/null +++ b/wx-official-orm/src/test/java/cn/skcks/wx/official/schema/SchemaGenerator.java @@ -0,0 +1,15 @@ +package cn.skcks.wx.official.schema; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.WebApplicationType; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class SchemaGenerator { + public static void main(String[] args) { + SpringApplication springApplication = new SpringApplication(SchemaGenerator.class); + springApplication.setAdditionalProfiles("schema"); + springApplication.setWebApplicationType(WebApplicationType.NONE); + springApplication.run(args); + } +} diff --git a/wx-official-orm/src/test/resources/application-generator.yml b/wx-official-orm/src/test/resources/application-generator.yml new file mode 100644 index 0000000..9d69894 --- /dev/null +++ b/wx-official-orm/src/test/resources/application-generator.yml @@ -0,0 +1,17 @@ +spring: + config: + activate: + on-profile: generator + liquibase: + enabled: false + +mybatis-flex: + datasource: + mysql: + type: com.zaxxer.hikari.HikariDataSource + driver-class-name: com.mysql.cj.jdbc.Driver + username: root + password: 12341234 + url: jdbc:mysql://10.10.10.200:3306/wv-official-v2?createDatabaseIfNotExist=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai + + diff --git a/wx-official-orm/src/test/resources/application-schema.yml b/wx-official-orm/src/test/resources/application-schema.yml new file mode 100644 index 0000000..bbb1a5c --- /dev/null +++ b/wx-official-orm/src/test/resources/application-schema.yml @@ -0,0 +1,16 @@ +spring: + config: + activate: + on-profile: schema + + datasource: + type: com.zaxxer.hikari.HikariDataSource + driver-class-name: com.mysql.cj.jdbc.Driver + username: root + password: 12341234 + url: jdbc:mysql://10.10.10.200:3306/wv-official-v2?createDatabaseIfNotExist=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai + + liquibase: + enabled: true + change-log: classpath:/db/changelog.xml + driver-class-name: com.mysql.cj.jdbc.Driver diff --git a/wx-official-service/pom.xml b/wx-official-service/pom.xml new file mode 100644 index 0000000..6074d38 --- /dev/null +++ b/wx-official-service/pom.xml @@ -0,0 +1,53 @@ + + + 4.0.0 + + cn.skcks.wx.official + wx-official + 0.1.0-SNAPSHOT + + + wx-official-service + + + 17 + 17 + UTF-8 + + + + + cn.skcks.wx.official + wx-official-common + ${project.version} + + + + org.springframework.boot + spring-boot-starter-web + + + + org.springdoc + springdoc-openapi-starter-webmvc-ui + ${springdoc.version} + + + + org.springdoc + springdoc-openapi-starter-common + + + + cn.hutool + hutool-all + + + + org.apache.commons + commons-lang3 + + + diff --git a/wx-official-starter/pom.xml b/wx-official-starter/pom.xml new file mode 100644 index 0000000..f601c04 --- /dev/null +++ b/wx-official-starter/pom.xml @@ -0,0 +1,146 @@ + + + 4.0.0 + + cn.skcks.wx.official + wx-official + 0.1.0-SNAPSHOT + + + wx-official-starter + + + MMddHHmm + 17 + 17 + UTF-8 + + + + + cn.skcks.wx.official + wx-official-api + ${project.version} + + + + cn.skcks.wx.official + wx-official-service + ${project.version} + + + + org.springframework.boot + spring-boot-starter + + + + org.springframework.boot + spring-boot-starter-test + test + + + + org.springframework.boot + spring-boot-starter-web + + + + org.springframework.boot + spring-boot-starter-undertow + + + + org.springframework.boot + spring-boot-devtools + runtime + true + + + com.mysql + mysql-connector-j + runtime + + + org.springframework.boot + spring-boot-configuration-processor + true + + + org.projectlombok + lombok + true + + + + org.junit.jupiter + junit-jupiter-api + test + + + + + ${project.artifactId} + + + org.springframework.boot + spring-boot-maven-plugin + + false + + + org.projectlombok + lombok + + + + + + repackage + + repackage + + + + + + + org.apache.maven.plugins + maven-surefire-plugin + + true + + + + + com.spotify + dockerfile-maven-plugin + + ${project.version} + + + + + + + src/main/resources + + **/** + + true + + + + + + src/test/resources + + **/** + + true + + + + diff --git a/wx-official-starter/src/main/java/cn/skcks/wx/official/WxOfficialStarter.java b/wx-official-starter/src/main/java/cn/skcks/wx/official/WxOfficialStarter.java new file mode 100644 index 0000000..1759d66 --- /dev/null +++ b/wx-official-starter/src/main/java/cn/skcks/wx/official/WxOfficialStarter.java @@ -0,0 +1,10 @@ +package cn.skcks.wx.official; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class WxOfficialStarter { + public static void main(String[] args) { + SpringApplication.run(WxOfficialStarter.class, args); + } +} diff --git a/wx-official-starter/src/test/java/official/WxOfficialStarterTest.java b/wx-official-starter/src/test/java/official/WxOfficialStarterTest.java new file mode 100644 index 0000000..333d174 --- /dev/null +++ b/wx-official-starter/src/test/java/official/WxOfficialStarterTest.java @@ -0,0 +1,11 @@ +package official; +import cn.skcks.wx.official.WxOfficialStarter; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class WxOfficialStarterTest { + public static void main(String[] args) { + SpringApplication.run(WxOfficialStarter.class, args); + } +}