添加获取最新5个版本接口
This commit is contained in:
parent
157894a8a6
commit
b9ffbdb088
6
pom.xml
6
pom.xml
|
@ -152,6 +152,12 @@
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-mail</artifactId>
|
<artifactId>spring-boot-starter-mail</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.minio</groupId>
|
||||||
|
<artifactId>minio</artifactId>
|
||||||
|
<version>8.4.5</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
|
|
@ -0,0 +1,26 @@
|
||||||
|
package com.example.catchTheLetters.config;
|
||||||
|
|
||||||
|
import io.minio.MinioClient;
|
||||||
|
import lombok.Data;
|
||||||
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
//@Data
|
||||||
|
//@Configuration
|
||||||
|
//@ConfigurationProperties(prefix = "minio")
|
||||||
|
//public class MinioConfig {
|
||||||
|
// private String endpoint;
|
||||||
|
// private String bucket;
|
||||||
|
// private String accessKey;
|
||||||
|
// private String secretKey;
|
||||||
|
//
|
||||||
|
// @Bean
|
||||||
|
// public MinioClient minioClient(){
|
||||||
|
// return MinioClient.builder()
|
||||||
|
// .endpoint(endpoint)
|
||||||
|
// .credentials(accessKey, secretKey)
|
||||||
|
// .build();
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
//}
|
|
@ -1,10 +1,7 @@
|
||||||
package com.example.catchTheLetters.controller;
|
package com.example.catchTheLetters.controller;
|
||||||
|
|
||||||
import com.example.catchTheLetters.entity.Level;
|
import com.example.catchTheLetters.entity.*;
|
||||||
import com.example.catchTheLetters.entity.Page;
|
|
||||||
import com.example.catchTheLetters.entity.ScoreInfoPage;
|
|
||||||
import com.example.catchTheLetters.model.vo.RankVo;
|
import com.example.catchTheLetters.model.vo.RankVo;
|
||||||
import com.example.catchTheLetters.entity.ScoreInfo;
|
|
||||||
import com.example.catchTheLetters.service.LevelService;
|
import com.example.catchTheLetters.service.LevelService;
|
||||||
import com.example.catchTheLetters.service.VersionService;
|
import com.example.catchTheLetters.service.VersionService;
|
||||||
import com.example.catchTheLetters.utils.R;
|
import com.example.catchTheLetters.utils.R;
|
||||||
|
@ -107,4 +104,8 @@ public class LevelController {
|
||||||
public R<ScoreInfoPage> getScores(@RequestBody Page page) {
|
public R<ScoreInfoPage> getScores(@RequestBody Page page) {
|
||||||
return R.ok(levelService.getScoreInfo( page.getLevelId(),page.getPage(), page.getSize()));
|
return R.ok(levelService.getScoreInfo( page.getLevelId(),page.getPage(), page.getSize()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public R<List<VersionDownload>> getNewVersion(){
|
||||||
|
return versionService.getNewDownloads();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,17 @@
|
||||||
|
package com.example.catchTheLetters.entity;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class VersionDownload implements Serializable {
|
||||||
|
private String id;
|
||||||
|
private Long time;
|
||||||
|
private String version;
|
||||||
|
private String url;
|
||||||
|
}
|
|
@ -1,5 +1,10 @@
|
||||||
package com.example.catchTheLetters.service;
|
package com.example.catchTheLetters.service;
|
||||||
|
|
||||||
|
import com.example.catchTheLetters.entity.VersionDownload;
|
||||||
|
import com.example.catchTheLetters.utils.R;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 版本服务接口
|
* 版本服务接口
|
||||||
*
|
*
|
||||||
|
@ -21,4 +26,18 @@ public interface VersionService {
|
||||||
* @param version 版本号
|
* @param version 版本号
|
||||||
*/
|
*/
|
||||||
void setVersion(String tableName, Long version);
|
void setVersion(String tableName, Long version);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 添加下载文件版本
|
||||||
|
* @param time 时间
|
||||||
|
* @param version 版本号
|
||||||
|
* @param url 地址
|
||||||
|
*/
|
||||||
|
R<String> addVersionDownload(Long time, String version, String url);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取最新的5个版本
|
||||||
|
* @return 版本集合
|
||||||
|
*/
|
||||||
|
R<List<VersionDownload>> getNewDownloads();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,13 +1,18 @@
|
||||||
package com.example.catchTheLetters.service.impl;
|
package com.example.catchTheLetters.service.impl;
|
||||||
|
|
||||||
import com.example.catchTheLetters.entity.Version;
|
import com.example.catchTheLetters.entity.Version;
|
||||||
|
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 jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
|
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 java.util.List;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class VersionServiceImpl implements VersionService {
|
public class VersionServiceImpl implements VersionService {
|
||||||
|
|
||||||
|
@ -30,4 +35,27 @@ public class VersionServiceImpl implements VersionService {
|
||||||
mongoTemplate.save(res);
|
mongoTemplate.save(res);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public R<String> addVersionDownload(Long time, String version, String url) {
|
||||||
|
VersionDownload versionDownload = new VersionDownload();
|
||||||
|
versionDownload.setUrl(url);
|
||||||
|
versionDownload.setTime(time);
|
||||||
|
versionDownload.setVersion(version);
|
||||||
|
VersionDownload insert = mongoTemplate.insert(versionDownload);
|
||||||
|
if (insert.getId() == null){
|
||||||
|
return R.fail("添加数据库失败");
|
||||||
|
}
|
||||||
|
//TODO
|
||||||
|
return R.ok(insert.getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public R<List<VersionDownload>> getNewDownloads() {
|
||||||
|
Query query = new Query()
|
||||||
|
.with(Sort.by(Sort.Direction.DESC,"time"))
|
||||||
|
.limit(5);
|
||||||
|
List<VersionDownload> list = mongoTemplate.find(query, VersionDownload.class);
|
||||||
|
return R.ok(list);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,5 +21,11 @@ spring:
|
||||||
host: 1.14.105.160
|
host: 1.14.105.160
|
||||||
port: 6379
|
port: 6379
|
||||||
password: spynsql
|
password: spynsql
|
||||||
|
|
||||||
server:
|
server:
|
||||||
port: 3536
|
port: 3536
|
||||||
|
#minio:
|
||||||
|
# endpoint: http://1.14.105.160:9000
|
||||||
|
# bucketName:
|
||||||
|
# accessKey:
|
||||||
|
# secretKey:
|
||||||
|
|
|
@ -3,12 +3,15 @@ package com.example.catchTheLetters;
|
||||||
import com.example.catchTheLetters.controller.LevelController;
|
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.utils.R;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
import org.junit.jupiter.api.Disabled;
|
import org.junit.jupiter.api.Disabled;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
import org.springframework.data.domain.PageRequest;
|
import org.springframework.data.domain.PageRequest;
|
||||||
import org.springframework.data.domain.Pageable;
|
import org.springframework.data.domain.Pageable;
|
||||||
|
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;
|
||||||
|
@ -101,4 +104,14 @@ class TestInsertLevel {
|
||||||
List<ScoreInfo> scores = mongoTemplate.find(new Query(Criteria.where("levelId").is("0")).with(pageable), ScoreInfo.class);
|
List<ScoreInfo> scores = mongoTemplate.find(new Query(Criteria.where("levelId").is("0")).with(pageable), ScoreInfo.class);
|
||||||
System.out.println(scores);
|
System.out.println(scores);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Disabled
|
||||||
|
void newTest(){
|
||||||
|
Query query = new Query()
|
||||||
|
.with(Sort.by(Sort.Direction.DESC,"time"))
|
||||||
|
.limit(5);
|
||||||
|
var list = mongoTemplate.find(query, VersionDownload.class);
|
||||||
|
System.out.println(list);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue