mongodb基本接口封装

pull/8/head
huziyang 2021-03-22 15:45:42 +08:00
parent 215ea52f8b
commit 9f0df66419
14 changed files with 367 additions and 0 deletions

View File

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>kernel-d-mongodb</artifactId>
<groupId>cn.stylefeng.roses</groupId>
<version>7.0.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>mongodb-api</artifactId>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
</project>

View File

@ -0,0 +1,46 @@
package cn.stylefeng.roses.kernel.mongodb.api;
import java.util.List;
import java.util.Optional;
/**
* @author huziyang
* @create 2021-03-20 16:24
*/
public interface MongodbApi<T,ID> {
/**
*
* @param gunsMapEntity
* @return
*/
T insert(T gunsMapEntity);
/**
*
* @param gunsMapEntity
* @return
*/
T update(T gunsMapEntity);
/**
* id
* @param id
*/
void deleteById(ID id);
/**
* id
* @param id
* @return
*/
Optional<T> findById(ID id);
/**
*
* @return
*/
List<T> findAll();
}

View File

@ -0,0 +1,19 @@
package cn.stylefeng.roses.kernel.mongodb.api.constants;
/**
* @author huziyang
* @create 2021-03-20 16:24
*/
public interface MongodbConstants {
/**
* mongodb
*/
String MONGODB_MODULE_NAME = "kernel-d-mongodb";
/**
*
*/
String MONGODB_EXCEPTION_STEP_CODE = "70";
}

View File

@ -0,0 +1,19 @@
package cn.stylefeng.roses.kernel.mongodb.api.exception;
import cn.stylefeng.roses.kernel.mongodb.api.constants.MongodbConstants;
import cn.stylefeng.roses.kernel.rule.exception.AbstractExceptionEnum;
import cn.stylefeng.roses.kernel.rule.exception.base.ServiceException;
/**
*
*
* @author fengshuonan
* @date 2021/13/17 23:59
*/
public class MongodbException extends ServiceException {
public MongodbException(AbstractExceptionEnum exception) {
super(MongodbConstants.MONGODB_MODULE_NAME, exception);
}
}

View File

@ -0,0 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>kernel-d-mongodb</artifactId>
<groupId>cn.stylefeng.roses</groupId>
<version>7.0.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>mongodb-sdk-springboot</artifactId>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
<dependencies>
<!--MongoDB模块的api-->
<dependency>
<groupId>cn.stylefeng.roses</groupId>
<artifactId>mongodb-api</artifactId>
<version>7.0.2</version>
</dependency>
<!--SpringBoot 与 MongoDB 整合-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,27 @@
package cn.stylefeng.roses.kernel.mongodb.entity;
import lombok.AllArgsConstructor;
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;
/**
* @author huziyang
* @create 2021-03-20 16:24
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
@Document(collection = "guns_map")
public class GunsMapEntity {
@Id
private String _id;
private Map<String,Object> data = new HashMap<>();
}

View File

@ -0,0 +1,13 @@
package cn.stylefeng.roses.kernel.mongodb.mapper;
import cn.stylefeng.roses.kernel.mongodb.entity.GunsMapEntity;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.mongodb.repository.MongoRepository;
/**
* @author huziyang
* @create 2021-03-20 16:24
*/
@Configuration
public interface GunsMapRepository extends MongoRepository<GunsMapEntity,String> {
}

View File

@ -0,0 +1,47 @@
package cn.stylefeng.roses.kernel.mongodb.service;
import cn.stylefeng.roses.kernel.mongodb.entity.GunsMapEntity;
import java.util.List;
import java.util.Optional;
/**
* @author huziyang
* @create 2021-03-20 16:24
*/
public interface GunsMapService {
/**
*
* @param gunsMapEntity
* @return
*/
GunsMapEntity insert(GunsMapEntity gunsMapEntity);
/**
*
* @param gunsMapEntity
* @return
*/
GunsMapEntity update(GunsMapEntity gunsMapEntity);
/**
* id
* @param id
*/
void deleteById(String id);
/**
* id
* @param id
* @return
*/
Optional<GunsMapEntity> findById(String id);
/**
*
* @return
*/
List<GunsMapEntity> findAll();
}

View File

@ -0,0 +1,49 @@
package cn.stylefeng.roses.kernel.mongodb.service.impl;
import cn.stylefeng.roses.kernel.mongodb.api.MongodbApi;
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;
/**
* @author huziyang
* @create 2021-03-20 16:24
*/
@Service
public class GunsMapServiceImpl implements GunsMapService, MongodbApi<GunsMapEntity,String> {
@Resource
private GunsMapRepository gunsMapRepository;
@Override
public GunsMapEntity insert(GunsMapEntity gunsMapEntity){
return gunsMapRepository.insert(gunsMapEntity);
}
@Override
public GunsMapEntity update(GunsMapEntity gunsMapEntity){
return gunsMapRepository.save(gunsMapEntity);
}
@Override
public void deleteById(String id){
gunsMapRepository.deleteById(id);
}
@Override
public Optional<GunsMapEntity> findById(String id){
return gunsMapRepository.findById(id);
}
@Override
public List<GunsMapEntity> findAll(){
return gunsMapRepository.findAll();
}
}

View File

@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>kernel-d-mongodb</artifactId>
<groupId>cn.stylefeng.roses</groupId>
<version>7.0.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>mongodb-spring-boot-starter</artifactId>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
<dependencies>
<!--MongoDB模块的sdk-->
<dependency>
<groupId>cn.stylefeng.roses</groupId>
<artifactId>mongodb-sdk-springboot</artifactId>
<version>7.0.2</version>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,23 @@
package cn.stylefeng.roses.kernel.mongodb.starter;
import cn.stylefeng.roses.kernel.mongodb.api.MongodbApi;
import cn.stylefeng.roses.kernel.mongodb.service.impl.GunsMapServiceImpl;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* @author huziyang
* @create 2021-03-20 16:24
*/
@Configuration
public class GunsMongodbAutoConfiguration {
@Bean
public MongodbApi mongodbApi() {
return new GunsMapServiceImpl();
}
}

View File

@ -0,0 +1,2 @@
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
cn.stylefeng.roses.kernel.mongodb.starter.GunsMongodbAutoConfiguration

36
kernel-d-mongodb/pom.xml Normal file
View File

@ -0,0 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>roses-kernel</artifactId>
<groupId>cn.stylefeng.roses</groupId>
<version>7.0.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>kernel-d-mongodb</artifactId>
<packaging>pom</packaging>
<modules>
<module>mongodb-api</module>
<module>mongodb-sdk-springboot</module>
<module>mongodb-spring-boot-starter</module>
</modules>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
<dependencies>
<!-- 开发规则 -->
<dependency>
<groupId>cn.stylefeng.roses</groupId>
<artifactId>kernel-a-rule</artifactId>
<version>7.0.2</version>
</dependency>
</dependencies>
</project>

View File

@ -91,6 +91,9 @@
<!--系统消息模块-->
<module>kernel-s-message</module>
<!--mongodb模块-->
<module>kernel-d-mongodb</module>
<!--系统管理基础业务-->
<module>kernel-s-system</module>