mirror of https://gitee.com/stylefeng/roses
【7.0.3】整理mongodb模块代码
parent
e2f1b04ce3
commit
d34881696a
|
@ -26,6 +26,7 @@ package cn.stylefeng.roses.kernel.mongodb.api;
|
|||
|
||||
import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
|
@ -46,7 +47,6 @@ public interface MongoFileApi<T,ID> {
|
|||
*/
|
||||
T saveFile(MultipartFile file);
|
||||
|
||||
|
||||
/**
|
||||
* 根据id删除文件
|
||||
*
|
||||
|
@ -66,7 +66,6 @@ public interface MongoFileApi<T,ID> {
|
|||
*/
|
||||
Optional<T> getFileById(ID id);
|
||||
|
||||
|
||||
/**
|
||||
* 分页获取文件列表
|
||||
*
|
||||
|
@ -77,5 +76,4 @@ public interface MongoFileApi<T,ID> {
|
|||
*/
|
||||
PageResult<T> getFilesByPage(T fileDocument);
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -32,7 +32,6 @@ package cn.stylefeng.roses.kernel.mongodb.api.constants;
|
|||
*/
|
||||
public interface MongodbConstants {
|
||||
|
||||
|
||||
/**
|
||||
* mongodb模块的名称
|
||||
*/
|
||||
|
@ -42,4 +41,5 @@ public interface MongodbConstants {
|
|||
* 异常枚举的步进值
|
||||
*/
|
||||
String MONGODB_EXCEPTION_STEP_CODE = "70";
|
||||
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ import cn.stylefeng.roses.kernel.rule.exception.AbstractExceptionEnum;
|
|||
import cn.stylefeng.roses.kernel.rule.exception.base.ServiceException;
|
||||
|
||||
/**
|
||||
* 系统配置表的异常
|
||||
* Mongodb模块的异常
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @date 2021/13/17 23:59
|
||||
|
|
|
@ -38,7 +38,6 @@ import org.springframework.stereotype.Controller;
|
|||
@ApiResource(name = "MongoDB文件管理界面渲染控制器")
|
||||
public class ModelViewController {
|
||||
|
||||
|
||||
/**
|
||||
* 文件管理视图
|
||||
*
|
||||
|
|
|
@ -38,6 +38,7 @@ import org.springframework.web.bind.annotation.RequestParam;
|
|||
import org.springframework.web.bind.annotation.RequestPart;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLEncoder;
|
||||
|
|
|
@ -25,10 +25,7 @@
|
|||
package cn.stylefeng.roses.kernel.mongodb.file.entity;
|
||||
|
||||
import cn.stylefeng.roses.kernel.rule.pojo.request.BaseRequest;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.*;
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.mongodb.core.mapping.Document;
|
||||
|
||||
|
@ -40,12 +37,14 @@ import java.util.Date;
|
|||
* @author huziyang
|
||||
* @date 2021/03/26 17:23
|
||||
*/
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
@Document("mongo_file")
|
||||
public class MongoFileEntity extends BaseRequest {
|
||||
|
||||
@Id
|
||||
private String id;
|
||||
private String name;
|
||||
|
@ -59,4 +58,5 @@ public class MongoFileEntity extends BaseRequest {
|
|||
* 分页 响应字段
|
||||
*/
|
||||
private byte[] content;
|
||||
|
||||
}
|
||||
|
|
|
@ -27,6 +27,7 @@ package cn.stylefeng.roses.kernel.mongodb.file.service;
|
|||
import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult;
|
||||
import cn.stylefeng.roses.kernel.mongodb.file.entity.MongoFileEntity;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
|
@ -47,7 +48,6 @@ public interface MongoFileService {
|
|||
*/
|
||||
MongoFileEntity saveFile(MultipartFile file);
|
||||
|
||||
|
||||
/**
|
||||
* 根据id删除文件
|
||||
*
|
||||
|
@ -67,7 +67,6 @@ public interface MongoFileService {
|
|||
*/
|
||||
Optional<MongoFileEntity> getFileById(String id);
|
||||
|
||||
|
||||
/**
|
||||
* 分页获取文件列表
|
||||
*
|
||||
|
@ -78,5 +77,4 @@ public interface MongoFileService {
|
|||
*/
|
||||
PageResult<MongoFileEntity> getFilesByPage(MongoFileEntity fileDocument);
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -39,7 +39,6 @@ import com.mongodb.client.gridfs.GridFSDownloadStream;
|
|||
import com.mongodb.client.gridfs.model.GridFSFile;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.bson.types.ObjectId;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.*;
|
||||
import org.springframework.data.mongodb.core.query.Criteria;
|
||||
import org.springframework.data.mongodb.core.query.Query;
|
||||
|
@ -47,6 +46,8 @@ import org.springframework.data.mongodb.gridfs.GridFsResource;
|
|||
import org.springframework.data.mongodb.gridfs.GridFsTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.io.IOException;
|
||||
import java.util.Date;
|
||||
import java.util.Optional;
|
||||
|
@ -60,13 +61,15 @@ import java.util.Optional;
|
|||
@Slf4j
|
||||
@Service
|
||||
public class MongoFileServiceImpl implements MongoFileService, MongoFileApi<MongoFileEntity, String> {
|
||||
@Autowired
|
||||
private MongoFileMapper mongoFileMapper;
|
||||
@Autowired
|
||||
private GridFsTemplate gridFsTemplate;
|
||||
@Autowired
|
||||
private GridFSBucket gridFSBucket;
|
||||
|
||||
@Resource
|
||||
private MongoFileMapper mongoFileMapper;
|
||||
|
||||
@Resource
|
||||
private GridFsTemplate gridFsTemplate;
|
||||
|
||||
@Resource
|
||||
private GridFSBucket gridFSBucket;
|
||||
|
||||
@Override
|
||||
public MongoFileEntity saveFile(MultipartFile file) {
|
||||
|
|
|
@ -29,6 +29,7 @@ import lombok.Data;
|
|||
import lombok.NoArgsConstructor;
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.mongodb.core.mapping.Document;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
|
@ -49,5 +50,4 @@ public class GunsMapEntity {
|
|||
|
||||
private Map<String, Object> data = new HashMap<>();
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -29,6 +29,7 @@ import cn.stylefeng.roses.kernel.mongodb.entity.GunsMapEntity;
|
|||
import cn.stylefeng.roses.kernel.mongodb.mapper.GunsMapRepository;
|
||||
import cn.stylefeng.roses.kernel.mongodb.service.GunsMapService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
@ -42,11 +43,9 @@ import java.util.Optional;
|
|||
@Service
|
||||
public class GunsMapServiceImpl implements GunsMapService, MongodbApi<GunsMapEntity, String> {
|
||||
|
||||
|
||||
@Resource
|
||||
private GunsMapRepository gunsMapRepository;
|
||||
|
||||
|
||||
@Override
|
||||
public GunsMapEntity insert(GunsMapEntity gunsMapEntity) {
|
||||
return gunsMapRepository.insert(gunsMapEntity);
|
||||
|
|
|
@ -26,6 +26,8 @@ package cn.stylefeng.roses.kernel.mongodb.starter;
|
|||
|
||||
import cn.stylefeng.roses.kernel.mongodb.api.MongoFileApi;
|
||||
import cn.stylefeng.roses.kernel.mongodb.api.MongodbApi;
|
||||
import cn.stylefeng.roses.kernel.mongodb.entity.GunsMapEntity;
|
||||
import cn.stylefeng.roses.kernel.mongodb.file.entity.MongoFileEntity;
|
||||
import cn.stylefeng.roses.kernel.mongodb.file.service.impl.MongoFileServiceImpl;
|
||||
import cn.stylefeng.roses.kernel.mongodb.service.impl.GunsMapServiceImpl;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
|
@ -40,7 +42,6 @@ import org.springframework.context.annotation.Configuration;
|
|||
@Configuration
|
||||
public class GunsMongodbAutoConfiguration {
|
||||
|
||||
|
||||
/**
|
||||
* Mongodb 数据存储
|
||||
*
|
||||
|
@ -48,7 +49,7 @@ public class GunsMongodbAutoConfiguration {
|
|||
* @date 2021/03/20 16:24
|
||||
*/
|
||||
@Bean
|
||||
public MongodbApi mongodbApi() {
|
||||
public MongodbApi<GunsMapEntity, String> mongodbApi() {
|
||||
return new GunsMapServiceImpl();
|
||||
}
|
||||
|
||||
|
@ -59,10 +60,9 @@ public class GunsMongodbAutoConfiguration {
|
|||
* @date 2021/03/20 16:24
|
||||
*/
|
||||
@Bean
|
||||
public MongoFileApi mongoFileApi() {
|
||||
public MongoFileApi<MongoFileEntity, String> mongoFileApi() {
|
||||
return new MongoFileServiceImpl();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue