xiang 1 месяц назад
Родитель
Сommit
c8ef4380aa

+ 1 - 0
.idea/compiler.xml

@@ -8,6 +8,7 @@
         <outputRelativeToContentRoot value="true" />
         <module name="search" />
         <module name="auth" />
+        <module name="media" />
         <module name="content" />
         <module name="gateway" />
         <module name="base" />

+ 14 - 0
.idea/dataSources.xml

@@ -8,5 +8,19 @@
       <jdbc-url>jdbc:mysql://117.72.120.45:3306</jdbc-url>
       <working-dir>$ProjectFileDir$</working-dir>
     </data-source>
+    <data-source source="LOCAL" name="@8.130.157.179" uuid="16f5f15d-c9d9-4ebc-985f-52f4ad0608f9">
+      <driver-ref>mysql.8</driver-ref>
+      <synchronize>true</synchronize>
+      <jdbc-driver>com.mysql.cj.jdbc.Driver</jdbc-driver>
+      <jdbc-url>jdbc:mysql://8.130.157.179:3306</jdbc-url>
+      <working-dir>$ProjectFileDir$</working-dir>
+    </data-source>
+    <data-source source="LOCAL" name="@154.8.183.35" uuid="0c654844-6ca5-4704-9840-0fc3300a767e">
+      <driver-ref>mysql.8</driver-ref>
+      <synchronize>true</synchronize>
+      <jdbc-driver>com.mysql.cj.jdbc.Driver</jdbc-driver>
+      <jdbc-url>jdbc:mysql://154.8.183.35:3306</jdbc-url>
+      <working-dir>$ProjectFileDir$</working-dir>
+    </data-source>
   </component>
 </project>

+ 2 - 0
.idea/encodings.xml

@@ -9,6 +9,8 @@
     <file url="file://$PROJECT_DIR$/content/src/main/resources" charset="UTF-8" />
     <file url="file://$PROJECT_DIR$/gateway/src/main/java" charset="UTF-8" />
     <file url="file://$PROJECT_DIR$/gateway/src/main/resources" charset="UTF-8" />
+    <file url="file://$PROJECT_DIR$/media/src/main/java" charset="UTF-8" />
+    <file url="file://$PROJECT_DIR$/media/src/main/resources" charset="UTF-8" />
     <file url="file://$PROJECT_DIR$/order/src/main/java" charset="UTF-8" />
     <file url="file://$PROJECT_DIR$/order/src/main/resources" charset="UTF-8" />
     <file url="file://$PROJECT_DIR$/parent/src/main/java" charset="UTF-8" />

+ 1 - 0
.idea/misc.xml

@@ -14,6 +14,7 @@
         <option value="$PROJECT_DIR$/gateway/pom.xml" />
         <option value="$PROJECT_DIR$/parent/pom.xml" />
         <option value="$PROJECT_DIR$/search/pom.xml" />
+        <option value="$PROJECT_DIR$/media/pom.xml" />
       </list>
     </option>
   </component>

+ 1 - 0
.idea/modules.xml

@@ -5,6 +5,7 @@
       <module fileurl="file://$PROJECT_DIR$/auth/auth.iml" filepath="$PROJECT_DIR$/auth/auth.iml" />
       <module fileurl="file://$PROJECT_DIR$/content/content.iml" filepath="$PROJECT_DIR$/content/content.iml" />
       <module fileurl="file://$PROJECT_DIR$/gateway/gateway.iml" filepath="$PROJECT_DIR$/gateway/gateway.iml" />
+      <module fileurl="file://$PROJECT_DIR$/media/media.iml" filepath="$PROJECT_DIR$/media/media.iml" />
       <module fileurl="file://$PROJECT_DIR$/order/order.iml" filepath="$PROJECT_DIR$/order/order.iml" />
       <module fileurl="file://$PROJECT_DIR$/parent/parent.iml" filepath="$PROJECT_DIR$/parent/parent.iml" />
       <module fileurl="file://$PROJECT_DIR$/search/search.iml" filepath="$PROJECT_DIR$/search/search.iml" />

+ 43 - 0
auth/pom.xml

@@ -28,5 +28,48 @@
             <groupId>org.springframework.boot</groupId>
             <artifactId>spring-boot-starter-web</artifactId>
         </dependency>
+        <dependency>
+            <groupId>org.springframework.cloud</groupId>
+            <artifactId>spring-cloud-starter-security</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework.cloud</groupId>
+            <artifactId>spring-cloud-starter-oauth2</artifactId>
+        </dependency>
+        <!-- mybatis plus的依赖 -->
+        <dependency>
+            <groupId>com.baomidou</groupId>
+            <artifactId>mybatis-plus-boot-starter</artifactId>
+        </dependency>
+        <!-- MySQL 驱动 -->
+        <dependency>
+            <groupId>mysql</groupId>
+            <artifactId>mysql-connector-java</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>com.alibaba</groupId>
+            <artifactId>fastjson</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>javax.xml.bind</groupId>
+            <artifactId>jaxb-api</artifactId>
+            <version>2.3.1</version>
+        </dependency>
+        <dependency>
+            <groupId>org.glassfish.jaxb</groupId>
+            <artifactId>jaxb-runtime</artifactId>
+            <version>2.3.3</version>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework.cloud</groupId>
+            <artifactId>spring-cloud-starter-oauth2</artifactId>
+            <exclusions>
+                <exclusion>
+                    <groupId>com.sun.xml.bind</groupId>
+                    <artifactId>jaxb-impl</artifactId>
+                </exclusion>
+            </exclusions>
+        </dependency>
+
     </dependencies>
 </project>

+ 1 - 6
auth/src/main/java/com/auth/AuthApplication.java

@@ -1,14 +1,9 @@
 package com.auth;
-
-
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
-
 @SpringBootApplication
 public class AuthApplication {
-
     public static void main(String[] args) {
         SpringApplication.run(AuthApplication.class, args);
     }
-
-}
+}

+ 20 - 20
base/src/main/java/com/base/exception/GlobalExceptionHandler.java

@@ -1,31 +1,31 @@
+// base/src/main/java/com/base/exception/GlobalExceptionHandler.java
 package com.base.exception;
+
+import com.base.utils.Result;
 import lombok.extern.slf4j.Slf4j;
+import org.springframework.web.bind.annotation.ExceptionHandler;
+import org.springframework.web.bind.annotation.ResponseBody;
+import org.springframework.web.bind.annotation.ResponseStatus;
+import org.springframework.web.bind.annotation.RestControllerAdvice;
 import org.springframework.http.HttpStatus;
-import org.springframework.web.bind.annotation.*;
 
-/**
- * @description 全局异常处理器
- * @author Mr.M
- * @date 2022/9/6 11:29
- * @version 1.0
- */
 @Slf4j
-@RestControllerAdvice
+@RestControllerAdvice(basePackages = "com") // 确保能扫描到所有模块
 public class GlobalExceptionHandler {
-    //项目的自定义异常
-    @ResponseBody   //json返回
-    @ExceptionHandler(WyMusicException.class)  //XueChengPlusException.class异常
-    @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)//返回异常码状态code500
-    public RestErrorResponse customException(WyMusicException e) {
-        log.error("【系统异常】{}",e.getErrMessage(),e);
-        return new RestErrorResponse(e.getErrMessage());
+
+    @ResponseBody
+    @ExceptionHandler(WyMusicException.class)
+    @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
+    public Result<String> customException(WyMusicException e) {
+        log.error("【业务异常】{}", e.getErrMessage(), e);
+        return Result.fail(e.getErrMessage());
     }
-    //非自定义异常
+
     @ResponseBody
     @ExceptionHandler(Exception.class)
     @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
-    public RestErrorResponse exception(Exception e) {
-        log.error("【系统异常】{}",e.getMessage(),e);
-        throw new WyMusicException("自定义错误信息");
+    public Result<String> exception(Exception e) {
+        log.error("【系统异常】{}", e.getMessage(), e);
+        return Result.fail( e.getMessage());
     }
-}
+}

+ 37 - 0
content/pom.xml

@@ -43,5 +43,42 @@
             <groupId>com.spring4all</groupId>
             <artifactId>swagger-spring-boot-starter</artifactId>
         </dependency>
+        <!--认证相关-->
+        <dependency>
+            <groupId>org.springframework.cloud</groupId>
+            <artifactId>spring-cloud-starter-security</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework.cloud</groupId>
+            <artifactId>spring-cloud-starter-oauth2</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>javax.xml.bind</groupId>
+            <artifactId>jaxb-api</artifactId>
+            <version>2.3.1</version>
+        </dependency>
+        <dependency>
+            <groupId>org.glassfish.jaxb</groupId>
+            <artifactId>jaxb-runtime</artifactId>
+            <version>2.3.3</version>
+        </dependency>
+        <dependency>
+            <groupId>com.alibaba</groupId>
+            <artifactId>fastjson</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-validation</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework.cloud</groupId>
+            <artifactId>spring-cloud-starter-oauth2</artifactId>
+            <exclusions>
+                <exclusion>
+                    <groupId>com.sun.xml.bind</groupId>
+                    <artifactId>jaxb-impl</artifactId>
+                </exclusion>
+            </exclusions>
+        </dependency>
     </dependencies>
 </project>

+ 2 - 5
content/src/main/java/com/content/ContentApplication.java

@@ -1,14 +1,11 @@
 package com.content;
-
 import com.spring4all.swagger.EnableSwagger2Doc;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
 @EnableSwagger2Doc
-@SpringBootApplication
+@SpringBootApplication(scanBasePackages = {"com.content", "com.base"})
 public class ContentApplication {
-
     public static void main(String[] args) {
         SpringApplication.run(ContentApplication.class, args);
     }
-
-}
+}

+ 22 - 4
content/src/main/java/com/content/controller/SwipperController.java

@@ -1,8 +1,13 @@
 package com.content.controller;
 import com.base.exception.WyMusicException;
+import com.base.utils.Result;
+import com.content.config.SecurityUtil;
+import com.content.domain.po.ShopSwipper;
 import com.content.domain.po.Swipper;
+import com.content.service.IShopSwipperService;
 import com.content.service.ISwipperService;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.security.core.context.SecurityContextHolder;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
@@ -18,17 +23,30 @@ import java.util.List;
  */
 
 @RestController
-@RequestMapping("/swipper")
+@RequestMapping("/content/swipper")
 public class SwipperController {
     @Autowired
     private ISwipperService swipperService;
-    @GetMapping("/content")
-    public List<Swipper> content(){
-        return swipperService.list();
+
+    @Autowired
+    private IShopSwipperService iShopSwipperService;
+    @GetMapping("/find/recommend")
+    public Result<List<Swipper>> findRecommend(){
+        return Result.success(swipperService.list());
+    }
+    @GetMapping("/shop")
+    public Result<List<ShopSwipper>> Shop(){
+        return Result.success(iShopSwipperService.list());
     }
     @GetMapping("/test")
     public List<Swipper> test() {
         WyMusicException.cast("账号或密码错误");
         return null;
     }
+    @GetMapping("/test1")
+    public String test1() {
+        Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
+        System.out.println(principal);
+        return principal.toString();
+    }
 }

+ 19 - 2
gateway/pom.xml

@@ -30,13 +30,30 @@
         </dependency>
         <dependency>
             <groupId>org.springframework.boot</groupId>
-            <artifactId>spring-boot-starter</artifactId>
+            <artifactId>spring-boot-starter-web</artifactId>
+            <!-- Maven整个生命周期内排除内置容器,排除内置容器导出成war包可以让外部容器运行spring-boot项目-->
             <exclusions>
                 <exclusion>
                     <groupId>org.springframework.boot</groupId>
-                    <artifactId>spring-boot-starter-web</artifactId>
+                    <artifactId>spring-boot-starter-tomcat</artifactId>
                 </exclusion>
             </exclusions>
         </dependency>
+        <dependency>
+            <groupId>org.springframework.cloud</groupId>
+            <artifactId>spring-cloud-starter-security</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework.cloud</groupId>
+            <artifactId>spring-cloud-starter-oauth2</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.projectlombok</groupId>
+            <artifactId>lombok</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>com.alibaba</groupId>
+            <artifactId>fastjson</artifactId>
+        </dependency>
     </dependencies>
 </project>

+ 1 - 3
gateway/src/main/java/com/gateway/GatewayApplication.java

@@ -5,9 +5,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
 
 @SpringBootApplication
 public class GatewayApplication {
-
     public static void main(String[] args) {
         SpringApplication.run(GatewayApplication.class, args);
     }
-
-}
+}

+ 52 - 0
media/src/test/java/com/media/FileUploadDownloadTests.java

@@ -0,0 +1,52 @@
+//package com.media;
+//import io.minio.MinioClient;
+//import org.junit.jupiter.api.Test;
+//import org.springframework.beans.factory.annotation.Autowired;
+//import org.springframework.boot.test.context.SpringBootTest;
+//import org.springframework.mock.web.MockMultipartFile;
+//import org.springframework.web.multipart.MultipartFile;
+//import java.io.IOException;
+//@SpringBootTest
+//public class FileUploadDownloadTests {
+//    @Autowired
+//    private MinioClient minioClient;
+//    @Test
+//    public void testFileUpload() throws IOException {
+//        // 创建模拟文件
+//        String fileName = "test.txt";
+//        String content = "Hello, this is a test file.";
+//        MultipartFile multipartFile = new MockMultipartFile(
+//                fileName,
+//                fileName,
+//                "text/plain",
+//                content.getBytes()
+//        );
+//
+//        // 上传文件到 MinIO
+//        String bucketName = "mediafiles";
+//        minioClient.putObject(
+//                putObjectArgs -> putObjectArgs
+//                        .bucket(bucketName)
+//                        .object(fileName)
+//                        .stream(multipartFile.getInputStream(), multipartFile.getSize(), -1)
+//        );
+//        System.out.println("文件上传成功:" + fileName);
+//    }
+//    @Test
+//    public void testFileDownload() throws IOException {
+//        String bucketName = "mediafiles";
+//        String objectName = "test.txt";
+//
+//        // 下载文件
+//        byte[] downloadedBytes = minioClient.getObject(
+//                getObjectArgs -> getObjectArgs
+//                        .bucket(bucketName)
+//                        .object(objectName)
+//        ).readAllBytes();
+//
+//        String content = new String(downloadedBytes);
+//        System.out.println("下载内容:" + content);
+//
+//        assert content.equals("Hello, this is a test file.");
+//    }
+//}

+ 34 - 0
order/pom.xml

@@ -27,5 +27,39 @@
             <groupId>org.springframework.boot</groupId>
             <artifactId>spring-boot-starter-web</artifactId>
         </dependency>
+        <!-- 支付宝SDK -->
+        <dependency>
+            <groupId>com.alipay.sdk</groupId>
+            <artifactId>alipay-sdk-java</artifactId>
+            <version>3.7.73.ALL</version>
+        </dependency>
+
+        <!-- 支付宝SDK依赖的日志 -->
+        <dependency>
+            <groupId>commons-logging</groupId>
+            <artifactId>commons-logging</artifactId>
+            <version>1.2</version>
+        </dependency>
+
+        <!--认证相关-->
+        <dependency>
+            <groupId>org.springframework.cloud</groupId>
+            <artifactId>spring-cloud-starter-security</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework.cloud</groupId>
+            <artifactId>spring-cloud-starter-oauth2</artifactId>
+        </dependency>
+
+        <!-- mybatis plus的依赖 -->
+        <dependency>
+            <groupId>com.baomidou</groupId>
+            <artifactId>mybatis-plus-boot-starter</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>com.alibaba</groupId>
+            <artifactId>fastjson</artifactId>
+        </dependency>
     </dependencies>
 </project>

+ 1 - 0
parent/pom.xml

@@ -19,6 +19,7 @@
         <module>../content</module>
         <module>../search</module>
         <module>../order</module>
+        <module>../media</module>
     </modules>
 
     <!-- 版本属性定义 -->