lllgodenough 1 год назад
Родитель
Сommit
4d2c6494a4

+ 17 - 0
application.yaml

@@ -56,6 +56,16 @@ aliyun:
     accessKeySecret: 3tUk8w5HdIFDw1weOwBurLsUuqcWcCIGE8pfQySR
     bucketName: eai-files
 
+
+
+ecloud:
+  eos:
+    endpoint: eos.suzhou-6.cmecloud.cn
+    access-key: 8VFJRXS67COZ8Z34D1JE
+    secret-key: 3tUk8w5HdIFDw1weOwBurLsUuqcWcCIGE8pfQySR
+    region: suzhou6
+    bucket-name: eai-files
+
 logging:
   config: classpath:log4j2-dev.xml
 
@@ -90,6 +100,13 @@ xunfei:
     api-key: 9d44aad124b15562cd36f1c69f907c23
     api-secret: MWZkZTM5ZjMwMGJkNjJkM2NmNjJjMjI3
 
+deepseek:
+  api:
+    key: E-OYKpcDb_L5WjdVPw2sZ-08ds4Vv-hBRe-lAV9tnqI
+    base-url: https://zhenze-huhehaote.cmecloud.cn/v1/chat/completions
+    model: deepseek-v3
+    temperature: 0.7
+
 proxy:
   enabled: false
   host: 20.111.54.16

+ 12 - 0
pom.xml

@@ -217,6 +217,18 @@
             <artifactId>stanford-corenlp</artifactId>
             <version>4.5.8</version>
         </dependency>
+        <!--提供 EOS S3 相关功能,必须-->
+        <dependency>
+            <groupId>com.ecloud.eos</groupId>
+            <artifactId>eos-java-sdk-s3</artifactId>
+            <version>1.12.378</version>
+        </dependency>
+        <!--提供 EOS 临时认证功能,可选-->
+        <dependency>
+            <groupId>com.ecloud.eos</groupId>
+            <artifactId>eos-java-sdk-sts</artifactId>
+            <version>1.12.378</version>
+        </dependency>
 
     </dependencies>
 

+ 6 - 0
settings.xml

@@ -21,6 +21,12 @@
             <name>阿里云阿帕奇仓库</name>
             <url>https://maven.aliyun.com/repository/apache-snapshots</url>
         </mirror>
+        <mirror>
+            <id>nexus-ecloud</id>
+            <name>Nexus ecloud</name>
+            <url>https://ecloud.10086.cn/api/query/developer/nexus/repository/eCloudSDK/</url>
+            <mirrorOf>*</mirrorOf> <!-- 注意:这会拦截所有仓库请求 -->
+        </mirror>
     </mirrors>
     <proxies/>
     <activeProfiles/>

+ 64 - 0
src/main/java/com/njuzr/eaibackend/config/ECloudEosConfig.java

@@ -0,0 +1,64 @@
+package com.njuzr.eaibackend.config;
+
+import com.amazonaws.auth.AWSCredentials;
+import com.amazonaws.auth.AWSCredentialsProvider;
+import com.amazonaws.auth.AWSStaticCredentialsProvider;
+import com.amazonaws.auth.BasicAWSCredentials;
+import com.amazonaws.client.builder.AwsClientBuilder;
+import com.amazonaws.services.s3.AmazonS3;
+import com.amazonaws.services.s3.AmazonS3ClientBuilder;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+/**
+ * @author Liululin
+ * @date 2025/9/14 - 14:31
+ */
+@Configuration
+public class ECloudEosConfig {
+    public String getBucketName() {
+        return bucketName;
+    }
+
+    @Value("${ecloud.eos.endpoint}")
+    private String endpoint;
+    @Value("${ecloud.eos.region}")
+    private String region;
+    @Value("${ecloud.eos.access-key}")
+    private String accessKey;
+    @Value("${ecloud.eos.secret-key}")
+    private String secretKey;
+    @Value("${ecloud.eos.bucket-name}")
+    private String bucketName;
+
+    @Bean
+    public AmazonS3 EosClient() {
+        // 配置端点
+        AwsClientBuilder.EndpointConfiguration endpointConfiguration =
+                new AwsClientBuilder.EndpointConfiguration(
+                        this.endpoint,
+                        this.region
+                );
+
+        // 创建认证信息
+        AWSCredentials credentials = new BasicAWSCredentials(
+                this.accessKey,
+                this.secretKey
+        );
+
+        AWSCredentialsProvider credentialsProvider =
+                new AWSStaticCredentialsProvider(credentials);
+
+        // 创建并返回S3客户端
+        return AmazonS3ClientBuilder.standard()
+                .withEndpointConfiguration(endpointConfiguration)
+                .withCredentials(credentialsProvider)
+                .build();
+    }
+
+    public String getEndpoint() {
+        return this.endpoint;
+    }
+}

+ 27 - 15
src/main/java/com/njuzr/eaibackend/controller/FileController.java

@@ -1,5 +1,10 @@
 package com.njuzr.eaibackend.controller;
 
+import com.amazonaws.services.s3.model.ObjectListing;
+import com.amazonaws.services.s3.model.ObjectMetadata;
+import com.amazonaws.services.s3.model.PutObjectResult;
+import com.njuzr.eaibackend.config.ECloudEosConfig;
+import com.njuzr.eaibackend.exception.MyException;
 import com.njuzr.eaibackend.utils.OssUtil;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -7,6 +12,9 @@ import org.springframework.web.bind.annotation.*;
 import org.springframework.web.multipart.MultipartFile;
 
 import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.List;
 import java.util.concurrent.CompletableFuture;
 import java.util.concurrent.TimeUnit;
 
@@ -20,24 +28,27 @@ import java.util.concurrent.TimeUnit;
 @RestController
 @RequestMapping("/api/file")
 public class FileController {
-    private final OssUtil ossUtil;
 
     @Autowired
-    public FileController(OssUtil ossUtil) {
-        this.ossUtil = ossUtil;
-    }
+    ECloudEosConfig  eCloudEosConfig;
 
 
     @PostMapping
     public CompletableFuture<MyResponse> upload(@RequestParam("file") MultipartFile file) {
         return CompletableFuture.supplyAsync(() -> {
-            try {
-                String filePath = "uploads/" + file.getOriginalFilename();
-                String url = ossUtil.uploadFile(file.getInputStream(), filePath);
-                log.info("url:" + url);
+            String filePath = "uploads/" + file.getOriginalFilename();
+            ObjectMetadata metadata = new ObjectMetadata();
+            metadata.setContentLength(file.getSize());
+            metadata.setContentType(file.getContentType());
+            metadata.setHeader("original-filename", file.getOriginalFilename());
+
+            try (InputStream inputStream = file.getInputStream()) {
+                eCloudEosConfig.EosClient().putObject(eCloudEosConfig.getBucketName(), filePath, inputStream, metadata);
+                String url = String.format("%s/%s/%s", eCloudEosConfig.getEndpoint(), eCloudEosConfig.getBucketName(), file);
+                log.info("文件上传成功: {}, url: {}", filePath, url);
                 return MyResponse.success(url);
             } catch (IOException e) {
-                throw new RuntimeException("文件上传失败", e);
+                throw new MyException(500, "上传文件失败");
             }
         }).completeOnTimeout(
                 MyResponse.error(400,"文件上传超时,请稍后再试"),
@@ -48,13 +59,14 @@ public class FileController {
 
     @GetMapping
     public MyResponse getFiles() {
-        return MyResponse.success(ossUtil.listFiles());
+        // 列出存储桶中的对象
+        ObjectListing objectListing = eCloudEosConfig.EosClient().listObjects(eCloudEosConfig.getBucketName());
+        List<String> files = new ArrayList<>();
+        objectListing.getObjectSummaries().forEach(objectSummary -> {
+            files.add(objectSummary.getKey());
+        });
+        return MyResponse.success(files);
     }
 
-    @DeleteMapping
-    public MyResponse delete(@RequestParam String filePath) {
-        ossUtil.deleteFile(filePath);
-        return MyResponse.success("删除成功");
-    }
 
 }

+ 3 - 2
src/main/java/com/njuzr/eaibackend/service/DeepSeekService.java

@@ -40,11 +40,11 @@ public class DeepSeekService {
 
     public String chatCompletion(List<AIEntry> message) throws IOException {
         HttpPost httpPost = new HttpPost(deepSeekConfig.getBaseUrl());
-
+        System.out.println(httpPost.getURI());
         // 设置请求头
         httpPost.setHeader("Content-Type", "application/json");
         httpPost.setHeader("Authorization", "Bearer " + deepSeekConfig.getApiKey());
-
+        System.out.println(deepSeekConfig.getApiKey());
         // 构建请求体
         Map<String, Object> requestBody = new HashMap<>();
         requestBody.put("model", deepSeekConfig.getModel());
@@ -57,6 +57,7 @@ public class DeepSeekService {
         // 执行请求
         try (CloseableHttpResponse response = httpClient.execute(httpPost)) {
             String responseBody = EntityUtils.toString(response.getEntity());
+            System.out.println(responseBody);
             Map<String, Object> responseMap = objectMapper.readValue(responseBody, Map.class);
 
             // 解析响应

+ 32 - 0
src/test/java/com/njuzr/eaibackend/EaiBackendApplicationTests.java

@@ -1,12 +1,19 @@
 package com.njuzr.eaibackend;
 
+import com.amazonaws.services.s3.model.ObjectListing;
+import com.njuzr.eaibackend.config.ECloudEosConfig;
+import com.njuzr.eaibackend.controller.MyResponse;
+import com.njuzr.eaibackend.po.AIEntry;
 import com.njuzr.eaibackend.service.DeepSeekService;
 import com.njuzr.eaibackend.service.impl.CourseServiceImpl;
 import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.shadow.com.univocity.parsers.common.input.LineSeparatorDetector;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.test.context.SpringBootTest;
 
 import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
 
 @SpringBootTest
 class EaiBackendApplicationTests {
@@ -14,11 +21,36 @@ class EaiBackendApplicationTests {
     @Autowired
     private CourseServiceImpl courseServiceImpl;
 
+    @Autowired
+    DeepSeekService deepSeekService;
+
+    @Autowired
+    ECloudEosConfig eCloudEosConfig;
+
+
 
 
     @Test
     void contextLoads() {
+        List<AIEntry> list = new ArrayList<>();
+        list.add(new AIEntry("user","你好"));
+        try {
+            System.out.println(deepSeekService.chatCompletion(list));
+        } catch (IOException e) {
+            System.out.println(e.getMessage());
+        }
+
+        // 列出存储桶中的对象
+        ObjectListing objectListing = eCloudEosConfig.EosClient().listObjects(eCloudEosConfig.getBucketName());
+        List<String> files = new ArrayList<>();
+        objectListing.getObjectSummaries().forEach(objectSummary -> {
+            System.out.println(objectSummary.getKey());
+        });
 
     }
 
+
+
 }
+
+