Explorar o código

feat:完善代码

ChenGanBin %!s(int64=2) %!d(string=hai) anos
pai
achega
69879f6ca4

+ 17 - 0
README.md

@@ -2,6 +2,23 @@
 
 ```commandline
 java -jar xx.jar -Dspring.profiles.active=环境 -Djasypt.encryptor.password=密钥
+
+jdbc:h2:file:/ot-service/db/online_tool_service
+
+docker rm -f ot-service && docker run -d \
+--name ot-service \
+-p 18080:8080 \
+-v /home/zkpk/ots/lib:/ot-service/lib \
+-v /home/zkpk/ots/online-tool-service-0.0.1-SNAPSHOT.jar:/ot-service/online-tool-service-0.0.1-SNAPSHOT.jar \
+-v /home/zkpk/ots/logs:/ot-service/logs \
+-v /home/zkpk/ots/tmp:/ot-service/tmp \
+-v /home/zkpk/ots/db:/ot-service/db \
+openjdk:17 \
+java -Dspring.profiles.active=prod -Djasypt.encryptor.password=密码 -jar /ot-service/online-tool-service-0.0.1-SNAPSHOT.jar 
+
+docker logs -f ot-service
+
+docker exec -it ot-service bash
 ```
 
 待办列表

+ 265 - 186
pom.xml

@@ -1,197 +1,276 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-  xmlns="http://maven.apache.org/POM/4.0.0"
-  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
-  <modelVersion>4.0.0</modelVersion>
-  <parent>
-    <groupId>org.springframework.boot</groupId>
-    <artifactId>spring-boot-starter-parent</artifactId>
-    <version>3.1.1</version>
-    <relativePath/> <!-- lookup parent from repository -->
-  </parent>
-  <groupId>com.zhixinghe1</groupId>
-  <artifactId>online-tool-service</artifactId>
-  <version>0.0.1-SNAPSHOT</version>
-  <name>OnlineToolService</name>
-  <description>a online tool service</description>
-  <properties>
-    <java.version>17</java.version>
-    <mapstruct.version>1.5.5.Final</mapstruct.version>
-    <thumbnailator.version>0.4.20</thumbnailator.version>
-    <lombok.mapstruct.binding.version>0.2.0</lombok.mapstruct.binding.version>
-    <spring-cloud.version>2022.0.3</spring-cloud.version>
-    <jasypt.version>3.0.5</jasypt.version>
-    <jwt.version>4.4.0</jwt.version>
-    <mybatis.mapper.version>2.0.0</mybatis.mapper.version>
-    <mybatis.springboot.starter.version>3.0.2</mybatis.springboot.starter.version>
-  </properties>
+         xmlns="http://maven.apache.org/POM/4.0.0"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <groupId>org.springframework.boot</groupId>
+        <artifactId>spring-boot-starter-parent</artifactId>
+        <version>3.1.1</version>
+        <relativePath/> <!-- lookup parent from repository -->
+    </parent>
+    <groupId>com.zhixinghe1</groupId>
+    <artifactId>online-tool-service</artifactId>
+    <version>0.0.1-SNAPSHOT</version>
+    <name>OnlineToolService</name>
+    <description>a online tool service</description>
+    <properties>
+        <java.version>17</java.version>
+        <mapstruct.version>1.5.5.Final</mapstruct.version>
+        <thumbnailator.version>0.4.20</thumbnailator.version>
+        <lombok.mapstruct.binding.version>0.2.0</lombok.mapstruct.binding.version>
+        <spring-cloud.version>2022.0.3</spring-cloud.version>
+        <jasypt.version>3.0.5</jasypt.version>
+        <jwt.version>4.4.0</jwt.version>
+        <mybatis.mapper.version>2.0.0</mybatis.mapper.version>
+        <mybatis.springboot.starter.version>3.0.2</mybatis.springboot.starter.version>
+    </properties>
+
+    <dependencyManagement>
+        <dependencies>
+            <dependency>
+                <groupId>org.springframework.cloud</groupId>
+                <artifactId>spring-cloud-dependencies</artifactId>
+                <version>${spring-cloud.version}</version>
+                <type>pom</type>
+                <scope>import</scope>
+            </dependency>
+        </dependencies>
+    </dependencyManagement>
 
-  <dependencyManagement>
     <dependencies>
-      <dependency>
-        <groupId>org.springframework.cloud</groupId>
-        <artifactId>spring-cloud-dependencies</artifactId>
-        <version>${spring-cloud.version}</version>
-        <type>pom</type>
-        <scope>import</scope>
-      </dependency>
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-cache</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>com.github.ben-manes.caffeine</groupId>
+            <artifactId>caffeine</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-validation</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-web</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-aop</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework.cloud</groupId>
+            <artifactId>spring-cloud-starter-openfeign</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework</groupId>
+            <artifactId>spring-tx</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>com.h2database</groupId>
+            <artifactId>h2</artifactId>
+            <scope>runtime</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.projectlombok</groupId>
+            <artifactId>lombok</artifactId>
+            <optional>true</optional>
+        </dependency>
+        <dependency>
+            <groupId>org.projectlombok</groupId>
+            <artifactId>lombok-mapstruct-binding</artifactId>
+            <version>${lombok.mapstruct.binding.version}</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-test</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>net.coobird</groupId>
+            <artifactId>thumbnailator</artifactId>
+            <version>${thumbnailator.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.mybatis.spring.boot</groupId>
+            <artifactId>mybatis-spring-boot-starter</artifactId>
+            <version>${mybatis.springboot.starter.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>io.mybatis</groupId>
+            <artifactId>mybatis-mapper</artifactId>
+            <version>${mybatis.mapper.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.mapstruct</groupId>
+            <artifactId>mapstruct</artifactId>
+            <version>${mapstruct.version}</version>
+            <scope>compile</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.mapstruct</groupId>
+            <artifactId>mapstruct-processor</artifactId>
+            <version>${mapstruct.version}</version>
+            <scope>compile</scope>
+        </dependency>
+        <!--  加解密  -->
+        <dependency>
+            <groupId>com.github.ulisesbocchio</groupId>
+            <artifactId>jasypt-spring-boot-starter</artifactId>
+            <version>${jasypt.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>com.auth0</groupId>
+            <artifactId>java-jwt</artifactId>
+            <version>${jwt.version}</version>
+        </dependency>
     </dependencies>
-  </dependencyManagement>
 
-  <dependencies>
-    <dependency>
-      <groupId>org.springframework.boot</groupId>
-      <artifactId>spring-boot-starter-cache</artifactId>
-    </dependency>
-    <dependency>
-      <groupId>com.github.ben-manes.caffeine</groupId>
-      <artifactId>caffeine</artifactId>
-    </dependency>
-    <dependency>
-      <groupId>org.springframework.boot</groupId>
-      <artifactId>spring-boot-starter-validation</artifactId>
-    </dependency>
-    <dependency>
-      <groupId>org.springframework.boot</groupId>
-      <artifactId>spring-boot-starter-web</artifactId>
-    </dependency>
-    <dependency>
-      <groupId>org.springframework.boot</groupId>
-      <artifactId>spring-boot-starter-aop</artifactId>
-    </dependency>
-    <dependency>
-      <groupId>org.springframework.cloud</groupId>
-      <artifactId>spring-cloud-starter-openfeign</artifactId>
-    </dependency>
-    <dependency>
-      <groupId>org.springframework</groupId>
-      <artifactId>spring-tx</artifactId>
-    </dependency>
-    <dependency>
-      <groupId>com.h2database</groupId>
-      <artifactId>h2</artifactId>
-      <scope>runtime</scope>
-    </dependency>
-    <dependency>
-      <groupId>org.projectlombok</groupId>
-      <artifactId>lombok</artifactId>
-      <optional>true</optional>
-    </dependency>
-    <dependency>
-      <groupId>org.projectlombok</groupId>
-      <artifactId>lombok-mapstruct-binding</artifactId>
-      <version>${lombok.mapstruct.binding.version}</version>
-    </dependency>
+    <!-- 配置阿里云仓库 -->
+    <repositories>
+        <repository>
+            <id>aliyun-repos</id>
+            <url>https://maven.aliyun.com/repository/public</url>
+            <releases>
+                <enabled>true</enabled>
+            </releases>
+            <snapshots>
+                <enabled>false</enabled>
+            </snapshots>
+        </repository>
+    </repositories>
+    <pluginRepositories>
+        <pluginRepository>
+            <id>aliyun-repos</id>
+            <url>https://maven.aliyun.com/repository/public</url>
+            <releases>
+                <enabled>true</enabled>
+            </releases>
+            <snapshots>
+                <enabled>false</enabled>
+            </snapshots>
+        </pluginRepository>
+    </pluginRepositories>
 
-    <dependency>
-      <groupId>org.springframework.boot</groupId>
-      <artifactId>spring-boot-starter-test</artifactId>
-      <scope>test</scope>
-    </dependency>
-    <dependency>
-      <groupId>net.coobird</groupId>
-      <artifactId>thumbnailator</artifactId>
-      <version>${thumbnailator.version}</version>
-    </dependency>
-    <dependency>
-      <groupId>org.mybatis.spring.boot</groupId>
-      <artifactId>mybatis-spring-boot-starter</artifactId>
-      <version>${mybatis.springboot.starter.version}</version>
-    </dependency>
-    <dependency>
-      <groupId>io.mybatis</groupId>
-      <artifactId>mybatis-mapper</artifactId>
-      <version>${mybatis.mapper.version}</version>
-    </dependency>
-    <dependency>
-      <groupId>org.mapstruct</groupId>
-      <artifactId>mapstruct</artifactId>
-      <version>${mapstruct.version}</version>
-      <scope>compile</scope>
-    </dependency>
-    <dependency>
-      <groupId>org.mapstruct</groupId>
-      <artifactId>mapstruct-processor</artifactId>
-      <version>${mapstruct.version}</version>
-      <scope>compile</scope>
-    </dependency>
-    <!--  加解密  -->
-    <dependency>
-      <groupId>com.github.ulisesbocchio</groupId>
-      <artifactId>jasypt-spring-boot-starter</artifactId>
-      <version>${jasypt.version}</version>
-    </dependency>
-    <dependency>
-      <groupId>com.auth0</groupId>
-      <artifactId>java-jwt</artifactId>
-      <version>${jwt.version}</version>
-    </dependency>
-  </dependencies>
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.springframework.boot</groupId>
+                <artifactId>spring-boot-maven-plugin</artifactId>
+                <configuration>
+                    <!--引入第三方jar包时,不添加则引入的第三方jar不会被打入jar包中-->
+                    <includeSystemScope>true</includeSystemScope>
+                    <!--排除第三方jar文件-->
+                    <includes>
+                        <include>
+                            <groupId>nothing</groupId>
+                            <artifactId>nothing</artifactId>
+                        </include>
+                    </includes>
+                    <excludes>
+                        <exclude>
+                            <groupId>org.projectlombok</groupId>
+                            <artifactId>lombok</artifactId>
+                        </exclude>
+                    </excludes>
+                </configuration>
+                <executions>
+                    <execution>
+                        <goals>
+                            <goal>repackage</goal>
+                        </goals>
+                    </execution>
+                </executions>
+            </plugin>
 
-  <!-- 配置阿里云仓库 -->
-  <repositories>
-    <repository>
-      <id>aliyun-repos</id>
-      <url>https://maven.aliyun.com/repository/public</url>
-      <releases>
-        <enabled>true</enabled>
-      </releases>
-      <snapshots>
-        <enabled>false</enabled>
-      </snapshots>
-    </repository>
-  </repositories>
-  <pluginRepositories>
-    <pluginRepository>
-      <id>aliyun-repos</id>
-      <url>https://maven.aliyun.com/repository/public</url>
-      <releases>
-        <enabled>true</enabled>
-      </releases>
-      <snapshots>
-        <enabled>false</enabled>
-      </snapshots>
-    </pluginRepository>
-  </pluginRepositories>
+            <!-- 2、完成对Java代码的编译,可以指定项目源码的jdk版本,编译后的jdk版本,以及编码 -->
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-compiler-plugin</artifactId>
+                <configuration>
+                    <!-- 源代码使用的JDK版本 -->
+                    <source>${java.version}</source>
+                    <!-- 需要生成的目标class文件的编译版本 -->
+                    <target>${java.version}</target>
+                    <!-- 字符集编码 -->
+                    <encoding>UTF-8</encoding>
+                    <!-- 用来传递编译器自身不包含但是却支持的参数选项 -->
+                    <!--                    <compilerArguments>-->
+                    <!--                        <verbose/>-->
+                    <!--                        &lt;!&ndash; windwos环境(二选一) &ndash;&gt;-->
+                    <!--                        <bootclasspath>${java.home}/lib/rt.jar:${java.home}/lib/jce.jar</bootclasspath>-->
+                    <!--                        &lt;!&ndash; Linux环境(二选一) &ndash;&gt;-->
+                    <!--                        <bootclasspath>${java.home}/lib/rt.jar:${java.home}/lib/jce.jar</bootclasspath>-->
+                    <!--                    </compilerArguments>-->
+                    <annotationProcessorPaths>
+                        <path>
+                            <groupId>org.projectlombok</groupId>
+                            <artifactId>lombok</artifactId>
+                            <version>${lombok.version}</version>
+                        </path>
+                        <path>
+                            <groupId>org.mapstruct</groupId>
+                            <artifactId>mapstruct-processor</artifactId>
+                            <version>${mapstruct.version}</version>
+                        </path>
+                        <path>
+                            <groupId>org.projectlombok</groupId>
+                            <artifactId>lombok-mapstruct-binding</artifactId>
+                            <version>${lombok.mapstruct.binding.version}</version>
+                        </path>
+                    </annotationProcessorPaths>
+                </configuration>
+            </plugin>
 
-  <build>
-    <plugins>
-      <plugin>
-        <groupId>org.springframework.boot</groupId>
-        <artifactId>spring-boot-maven-plugin</artifactId>
-        <configuration>
-          <excludes>
-            <exclude>
-              <groupId>org.projectlombok</groupId>
-              <artifactId>lombok</artifactId>
-            </exclude>
-          </excludes>
-        </configuration>
-      </plugin>
-      <plugin>
-        <groupId>org.apache.maven.plugins</groupId>
-        <artifactId>maven-compiler-plugin</artifactId>
-        <configuration>
-          <annotationProcessorPaths>
-            <path>
-              <groupId>org.projectlombok</groupId>
-              <artifactId>lombok</artifactId>
-              <version>${lombok.version}</version>
-            </path>
-            <path>
-              <groupId>org.mapstruct</groupId>
-              <artifactId>mapstruct-processor</artifactId>
-              <version>${mapstruct.version}</version>
-            </path>
-            <path>
-              <groupId>org.projectlombok</groupId>
-              <artifactId>lombok-mapstruct-binding</artifactId>
-              <version>${lombok.mapstruct.binding.version}</version>
-            </path>
-          </annotationProcessorPaths>
-        </configuration>
-      </plugin>
-    </plugins>
-  </build>
+            <!-- 3、将所有依赖的jar文件复制到target/lib目录 -->
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-dependency-plugin</artifactId>
+                <executions>
+                    <execution>
+                        <id>copy-dependencies</id>
+                        <phase>prepare-package</phase>
+                        <goals>
+                            <goal>copy-dependencies</goal>
+                        </goals>
+                        <configuration>
+                            <!--复制到哪个路径,${project.build.directory} 缺醒为 target,其他内置参数见下面解释-->
+                            <outputDirectory>${project.build.directory}/lib</outputDirectory>
+                            <overWriteReleases>false</overWriteReleases>
+                            <overWriteSnapshots>false</overWriteSnapshots>
+                            <overWriteIfNewer>true</overWriteIfNewer>
+                        </configuration>
+                    </execution>
+                </executions>
+            </plugin>
+
+            <!-- 4、指定启动类,指定配置文件,将依赖打成外部jar包 -->
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-jar-plugin</artifactId>
+                <configuration>
+                    <archive>
+                        <manifest>
+                            <!-- 是否要把第三方jar加入到类构建路径 -->
+                            <addClasspath>true</addClasspath>
+                            <!-- 外部依赖jar包的最终位置 -->
+                            <classpathPrefix>lib/</classpathPrefix>
+                            <!-- 项目启动类 -->
+                            <mainClass>com.zhixinghe1.ots.OnlineToolServiceApplication</mainClass>
+                        </manifest>
+                    </archive>
+                    <!--资源文件不打进jar包中,做到配置跟项目分离的效果-->
+                    <!--                    <excludes>-->
+                    <!--                        &lt;!&ndash; 业务jar中过滤application.properties/yml文件,在jar包外控制 &ndash;&gt;-->
+                    <!--                        <exclude>*.properties</exclude>-->
+                    <!--                        <exclude>*.xml</exclude>-->
+                    <!--                        <exclude>*.yml</exclude>-->
+                    <!--                    </excludes>-->
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
 
 </project>

+ 18 - 26
src/main/java/com/zhixinghe1/ots/interceptor/AuthInterceptor.java

@@ -1,18 +1,10 @@
 package com.zhixinghe1.ots.interceptor;
 
-import java.util.Map;
-
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
-import org.springframework.util.StringUtils;
 import org.springframework.web.servlet.HandlerInterceptor;
 
-import com.auth0.jwt.interfaces.Claim;
 import com.zhixinghe1.ots.atomic.service.IWechatUserService;
-import com.zhixinghe1.ots.common.exception.BusinessException;
-import com.zhixinghe1.ots.common.exception.LoginException;
-import com.zhixinghe1.ots.domain.dto.WechatUserDto;
-import com.zhixinghe1.ots.utiis.TokenUtils;
 
 import jakarta.servlet.http.HttpServletRequest;
 import jakarta.servlet.http.HttpServletResponse;
@@ -36,24 +28,24 @@ public class AuthInterceptor implements HandlerInterceptor {
     public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
         throws Exception {
 
-        String token = request.getHeader("Authorization");
-        if (!StringUtils.hasText(token)) {
-            throw LoginException.fail("登录校验异常,原因:没有token凭据");
-        }
-
-        Long userId = null;
-        try {
-            Map<String, Claim> verify = TokenUtils.verify(token);
-            userId = verify.get("userId").asLong();
-        } catch (Exception e) {
-            log.error("登录校验异常,token:{}", token, e);
-            throw LoginException.fail("登录校验异常");
-        }
-
-        WechatUserDto wechatUserDto = wechatUserService.getById(userId);
-        if (wechatUserDto == null) {
-            throw BusinessException.fail("不存在的用户");
-        }
+        // String token = request.getHeader("Authorization");
+        // if (!StringUtils.hasText(token)) {
+        // throw LoginException.fail("登录校验异常,原因:没有token凭据");
+        // }
+        //
+        // Long userId = null;
+        // try {
+        // Map<String, Claim> verify = TokenUtils.verify(token);
+        // userId = verify.get("userId").asLong();
+        // } catch (Exception e) {
+        // log.error("登录校验异常,token:{}", token, e);
+        // throw LoginException.fail("登录校验异常");
+        // }
+        //
+        // WechatUserDto wechatUserDto = wechatUserService.getById(userId);
+        // if (wechatUserDto == null) {
+        // throw BusinessException.fail("不存在的用户");
+        // }
 
         return true;
     }

+ 24 - 0
src/main/java/com/zhixinghe1/ots/service/controller/HealthController.java

@@ -0,0 +1,24 @@
+package com.zhixinghe1.ots.service.controller;
+
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+/**
+ * 健康检查
+ * 
+ * @author ChenYL
+ * @version V1.0
+ * @className HealthController
+ * @description
+ * @date 2023/10/04 16:21
+ **/
+@RestController
+@RequestMapping("/health")
+public class HealthController {
+
+    @GetMapping("/info")
+    public String info() {
+        return "在线工具服务类 正在运行";
+    }
+}

+ 1 - 0
src/main/resources/application-dev.yml

@@ -2,6 +2,7 @@ spring:
   datasource:
     username: root
     password: test
+    url: ENC(YSlhmFY8Ty5gIOg8OTv16AZP51FQCPy3XwZB+b3tKpcUpnOTxpY7/Qr+QEAWIkm7OSeb6mj+6DOfBkNDLa8FyGTniNuJ6g41)
 
 biz:
   file:

+ 2 - 1
src/main/resources/application-prod.yml

@@ -2,8 +2,9 @@ spring:
   datasource:
     username: ENC(fgSVI73C7ZtE1pUKfNdaOPBBWSF1MQRj)
     password: ENC(cfGCqQPxy2bICMy0seNdxM8YuN0f3Mt0/mml5LrCTzbdjyo25QL3Wg==)
+    url: ENC(5QAsP/XhRKgcJgc7KudxYuFb3LqwRlbaR/CavwO/ZrQ0QbSy00pGlYsxo7Qqx2yyskkPzchEvV5JTFttEdFKXCoHw6sCq3urHoTNns3nHBY=)
 
 biz:
   file:
     tmp:
-      dir: ./tmp/
+      dir: /ot-service/tmp/

+ 2 - 1
src/main/resources/application.yml

@@ -3,12 +3,13 @@ spring:
     active: dev
   datasource:
     driver-class-name: org.h2.Driver
-    url: ENC(YSlhmFY8Ty5gIOg8OTv16AZP51FQCPy3XwZB+b3tKpcUpnOTxpY7/Qr+QEAWIkm7OSeb6mj+6DOfBkNDLa8FyGTniNuJ6g41)
   cache:
     type: caffeine
   h2:
     console:
       enabled: true
+      settings:
+        web-allow-others: true
 
 logging:
   config: classpath:logback-spring.xml