添加minio相关接口
This commit is contained in:
parent
b9ffbdb088
commit
64afc10223
|
@ -6,21 +6,21 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
//@Data
|
@Data
|
||||||
//@Configuration
|
@Configuration
|
||||||
//@ConfigurationProperties(prefix = "minio")
|
@ConfigurationProperties(prefix = "minio")
|
||||||
//public class MinioConfig {
|
public class MinioConfig {
|
||||||
// private String endpoint;
|
private String endpoint;
|
||||||
// private String bucket;
|
private String bucket;
|
||||||
// private String accessKey;
|
private String accessKey;
|
||||||
// private String secretKey;
|
private String secretKey;
|
||||||
//
|
|
||||||
// @Bean
|
@Bean
|
||||||
// public MinioClient minioClient(){
|
public MinioClient minioClient(){
|
||||||
// return MinioClient.builder()
|
return MinioClient.builder()
|
||||||
// .endpoint(endpoint)
|
.endpoint(endpoint)
|
||||||
// .credentials(accessKey, secretKey)
|
.credentials(accessKey, secretKey)
|
||||||
// .build();
|
.build();
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
//}
|
}
|
||||||
|
|
|
@ -24,4 +24,6 @@ public interface CommonConstant {
|
||||||
String USERNAME = "username";
|
String USERNAME = "username";
|
||||||
|
|
||||||
String STATUS = "status";
|
String STATUS = "status";
|
||||||
|
|
||||||
|
String BUCKET = "catchtheletters";
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,9 @@ import io.swagger.annotations.ApiParam;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -105,7 +107,14 @@ public class LevelController {
|
||||||
return R.ok(levelService.getScoreInfo( page.getLevelId(),page.getPage(), page.getSize()));
|
return R.ok(levelService.getScoreInfo( page.getLevelId(),page.getPage(), page.getSize()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ApiOperation(value = "获取最新5个版本")
|
||||||
|
@GetMapping("/new-version")
|
||||||
public R<List<VersionDownload>> getNewVersion(){
|
public R<List<VersionDownload>> getNewVersion(){
|
||||||
return versionService.getNewDownloads();
|
return versionService.getNewDownloads();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
@PostMapping("/test")
|
||||||
|
public R<String> testMinio(MultipartFile file) throws Exception {
|
||||||
|
return R.ok(versionService.testMinIO(file));
|
||||||
|
}
|
||||||
|
}
|
|
@ -2,7 +2,9 @@ package com.example.catchTheLetters.service;
|
||||||
|
|
||||||
import com.example.catchTheLetters.entity.VersionDownload;
|
import com.example.catchTheLetters.entity.VersionDownload;
|
||||||
import com.example.catchTheLetters.utils.R;
|
import com.example.catchTheLetters.utils.R;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -33,11 +35,13 @@ public interface VersionService {
|
||||||
* @param version 版本号
|
* @param version 版本号
|
||||||
* @param url 地址
|
* @param url 地址
|
||||||
*/
|
*/
|
||||||
R<String> addVersionDownload(Long time, String version, String url);
|
R<String> addVersionDownload(Long time, String version, String url, MultipartFile file);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取最新的5个版本
|
* 获取最新的5个版本
|
||||||
* @return 版本集合
|
* @return 版本集合
|
||||||
*/
|
*/
|
||||||
R<List<VersionDownload>> getNewDownloads();
|
R<List<VersionDownload>> getNewDownloads();
|
||||||
|
|
||||||
|
String testMinIO(MultipartFile file) throws Exception;
|
||||||
}
|
}
|
||||||
|
|
|
@ -91,11 +91,8 @@ public class LevelServiceImpl implements LevelService {
|
||||||
public RankVo getRankInfo(String levelId, String token) {
|
public RankVo getRankInfo(String levelId, String token) {
|
||||||
// 在ScoreInfo表当中,查询levelId为levelId的所有数据,按照分数降序排列,取前10条数据
|
// 在ScoreInfo表当中,查询levelId为levelId的所有数据,按照分数降序排列,取前10条数据
|
||||||
var info = mongoTemplate.find(new Query(Criteria.where("levelId").is(levelId)).limit(10), ScoreInfo.class);
|
var info = mongoTemplate.find(new Query(Criteria.where("levelId").is(levelId)).limit(10), ScoreInfo.class);
|
||||||
|
|
||||||
var rankVo = new RankVo();
|
var rankVo = new RankVo();
|
||||||
rankVo.setScoreInfos(info);
|
rankVo.setScoreInfos(info);
|
||||||
|
|
||||||
|
|
||||||
// 如果有token,就查自己的分数数据
|
// 如果有token,就查自己的分数数据
|
||||||
if (token != null) {
|
if (token != null) {
|
||||||
var map = JwtUtil.getPayload(token);
|
var map = JwtUtil.getPayload(token);
|
||||||
|
|
|
@ -1,16 +1,27 @@
|
||||||
package com.example.catchTheLetters.service.impl;
|
package com.example.catchTheLetters.service.impl;
|
||||||
|
|
||||||
|
import com.example.catchTheLetters.config.MinioConfig;
|
||||||
|
import com.example.catchTheLetters.constant.CommonConstant;
|
||||||
import com.example.catchTheLetters.entity.Version;
|
import com.example.catchTheLetters.entity.Version;
|
||||||
import com.example.catchTheLetters.entity.VersionDownload;
|
import com.example.catchTheLetters.entity.VersionDownload;
|
||||||
import com.example.catchTheLetters.service.VersionService;
|
import com.example.catchTheLetters.service.VersionService;
|
||||||
import com.example.catchTheLetters.utils.R;
|
import com.example.catchTheLetters.utils.R;
|
||||||
|
import io.minio.*;
|
||||||
|
import io.minio.errors.*;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.data.domain.Sort;
|
import org.springframework.data.domain.Sort;
|
||||||
import org.springframework.data.mongodb.core.MongoTemplate;
|
import org.springframework.data.mongodb.core.MongoTemplate;
|
||||||
import org.springframework.data.mongodb.core.query.Criteria;
|
import org.springframework.data.mongodb.core.query.Criteria;
|
||||||
import org.springframework.data.mongodb.core.query.Query;
|
import org.springframework.data.mongodb.core.query.Query;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.security.InvalidKeyException;
|
||||||
|
import java.security.NoSuchAlgorithmException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
|
@ -19,6 +30,11 @@ public class VersionServiceImpl implements VersionService {
|
||||||
@Resource
|
@Resource
|
||||||
private MongoTemplate mongoTemplate;
|
private MongoTemplate mongoTemplate;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private MinioClient minioClient;
|
||||||
|
@Autowired
|
||||||
|
private MinioConfig minioConfig;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Long getVersion(String tableName) {
|
public Long getVersion(String tableName) {
|
||||||
var res = mongoTemplate.findOne(new Query(Criteria.where("table").is(tableName)), Version.class);
|
var res = mongoTemplate.findOne(new Query(Criteria.where("table").is(tableName)), Version.class);
|
||||||
|
@ -37,7 +53,7 @@ public class VersionServiceImpl implements VersionService {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public R<String> addVersionDownload(Long time, String version, String url) {
|
public R<String> addVersionDownload(Long time, String version, String url, MultipartFile file) {
|
||||||
VersionDownload versionDownload = new VersionDownload();
|
VersionDownload versionDownload = new VersionDownload();
|
||||||
versionDownload.setUrl(url);
|
versionDownload.setUrl(url);
|
||||||
versionDownload.setTime(time);
|
versionDownload.setTime(time);
|
||||||
|
@ -47,6 +63,7 @@ public class VersionServiceImpl implements VersionService {
|
||||||
return R.fail("添加数据库失败");
|
return R.fail("添加数据库失败");
|
||||||
}
|
}
|
||||||
//TODO
|
//TODO
|
||||||
|
|
||||||
return R.ok(insert.getId());
|
return R.ok(insert.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,4 +75,12 @@ public class VersionServiceImpl implements VersionService {
|
||||||
List<VersionDownload> list = mongoTemplate.find(query, VersionDownload.class);
|
List<VersionDownload> list = mongoTemplate.find(query, VersionDownload.class);
|
||||||
return R.ok(list);
|
return R.ok(list);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String testMinIO(MultipartFile file) throws Exception {
|
||||||
|
System.out.println(minioConfig.getBucket());
|
||||||
|
minioClient.makeBucket(MakeBucketArgs.builder().bucket(minioConfig.getBucket()).build());
|
||||||
|
// boolean bucketFound = minioClient.bucketExists(BucketExistsArgs.builder().bucket(minioConfig.getBucket()).build());
|
||||||
|
return "未找到";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,8 +24,8 @@ spring:
|
||||||
|
|
||||||
server:
|
server:
|
||||||
port: 3536
|
port: 3536
|
||||||
#minio:
|
minio:
|
||||||
# endpoint: http://1.14.105.160:9000
|
endpoint: http://1.14.105.160:9000
|
||||||
# bucketName:
|
bucket: catchtheletters
|
||||||
# accessKey:
|
accessKey: spyn
|
||||||
# secretKey:
|
secretKey: pengjunda1
|
||||||
|
|
|
@ -4,6 +4,7 @@ import com.example.catchTheLetters.controller.LevelController;
|
||||||
import com.example.catchTheLetters.entity.Level;
|
import com.example.catchTheLetters.entity.Level;
|
||||||
import com.example.catchTheLetters.entity.ScoreInfo;
|
import com.example.catchTheLetters.entity.ScoreInfo;
|
||||||
import com.example.catchTheLetters.entity.VersionDownload;
|
import com.example.catchTheLetters.entity.VersionDownload;
|
||||||
|
import com.example.catchTheLetters.service.VersionService;
|
||||||
import com.example.catchTheLetters.utils.R;
|
import com.example.catchTheLetters.utils.R;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
import org.junit.jupiter.api.Disabled;
|
import org.junit.jupiter.api.Disabled;
|
||||||
|
@ -29,6 +30,9 @@ class TestInsertLevel {
|
||||||
@Resource
|
@Resource
|
||||||
private MongoTemplate mongoTemplate;
|
private MongoTemplate mongoTemplate;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private VersionService versionService;
|
||||||
|
|
||||||
private final List<String> words = new ArrayList<>() {
|
private final List<String> words = new ArrayList<>() {
|
||||||
{
|
{
|
||||||
add("apple");
|
add("apple");
|
||||||
|
@ -114,4 +118,9 @@ class TestInsertLevel {
|
||||||
var list = mongoTemplate.find(query, VersionDownload.class);
|
var list = mongoTemplate.find(query, VersionDownload.class);
|
||||||
System.out.println(list);
|
System.out.println(list);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Disabled
|
||||||
|
void minIOTest(){
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue