mirror of
https://gitee.com/durcframework/SOP.git
synced 2025-08-11 21:57:56 +08:00
5.0
This commit is contained in:
25
sop-example/example-story/.gitignore
vendored
Normal file
25
sop-example/example-story/.gitignore
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
target/
|
||||
!.mvn/wrapper/maven-wrapper.jar
|
||||
|
||||
### STS ###
|
||||
.apt_generated
|
||||
.classpath
|
||||
.factorypath
|
||||
.project
|
||||
.settings
|
||||
.springBeans
|
||||
|
||||
### IntelliJ IDEA ###
|
||||
.idea
|
||||
*.iws
|
||||
*.iml
|
||||
*.ipr
|
||||
|
||||
### NetBeans ###
|
||||
nbproject/private/
|
||||
build/
|
||||
nbbuild/
|
||||
dist/
|
||||
nbdist/
|
||||
.nb-gradle/
|
||||
/local-config/
|
118
sop-example/example-story/pom.xml
Normal file
118
sop-example/example-story/pom.xml
Normal file
@@ -0,0 +1,118 @@
|
||||
<?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">
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>2.6.15</version>
|
||||
<relativePath/> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
|
||||
<groupId>com.gitee.sop</groupId>
|
||||
<artifactId>example-story</artifactId>
|
||||
<version>5.0.0-SNAPSHOT</version>
|
||||
<name>example-story</name>
|
||||
|
||||
<properties>
|
||||
<java.version>1.8</java.version>
|
||||
<!-- dubbo版本 -->
|
||||
<dubbo.version>3.2.10</dubbo.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.gitee.sop</groupId>
|
||||
<artifactId>sop-spring-boot-starter</artifactId>
|
||||
<version>5.0.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.dubbo</groupId>
|
||||
<artifactId>dubbo-spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- nacos注册中心 -->
|
||||
<dependency>
|
||||
<groupId>org.apache.dubbo</groupId>
|
||||
<artifactId>dubbo-nacos-spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-validation</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- 仅在开发中使用 -->
|
||||
<dependency>
|
||||
<groupId>org.apache.dubbo</groupId>
|
||||
<artifactId>dubbo-dependencies-zookeeper-curator5</artifactId>
|
||||
<version>${dubbo.version}</version>
|
||||
<type>pom</type>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.18.34</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.apache.dubbo</groupId>
|
||||
<artifactId>dubbo-bom</artifactId>
|
||||
<version>${dubbo.version}</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<!-- 打包时跳过测试 -->
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>2.12.4</version>
|
||||
<configuration>
|
||||
<skipTests>true</skipTests>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>spring-milestones</id>
|
||||
<name>Spring Milestones</name>
|
||||
<url>https://repo.spring.io/milestone</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
</project>
|
@@ -0,0 +1,16 @@
|
||||
package com.gitee.sop.storyweb;
|
||||
|
||||
import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
@EnableDubbo
|
||||
public class ExampleStoryApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(ExampleStoryApplication.class, args);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -0,0 +1,58 @@
|
||||
package com.gitee.sop.storyweb.open;
|
||||
|
||||
import com.gitee.sop.storyweb.open.req.StorySaveDTO;
|
||||
import com.gitee.sop.storyweb.open.resp.StoryResponse;
|
||||
import com.gitee.sop.support.annotation.Open;
|
||||
import com.gitee.sop.support.dto.FileData;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import javax.validation.constraints.Size;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 开放接口定义
|
||||
*
|
||||
* @author 六如
|
||||
*/
|
||||
public interface OpenStory {
|
||||
|
||||
@Open("story.save")
|
||||
Integer save(StorySaveDTO storySaveDTO);
|
||||
|
||||
@Open("story.update")
|
||||
Integer update(Integer id, StorySaveDTO storySaveDTO);
|
||||
|
||||
@Open("story.get")
|
||||
StoryResponse getById(@NotNull(message = "id必填") Integer id);
|
||||
|
||||
@Open(value = "story.get", version = "2.0")
|
||||
StoryResponse getByIdV2(Long id);
|
||||
|
||||
|
||||
// 默认方法,注解放在这里也有效
|
||||
@Open("story.find")
|
||||
default StoryResponse getById(Integer id, String name) {
|
||||
StoryResponse storyResponse = new StoryResponse();
|
||||
storyResponse.setId(id);
|
||||
storyResponse.setName(name);
|
||||
return storyResponse;
|
||||
}
|
||||
|
||||
// 演示单文件上传
|
||||
@Open("story.upload")
|
||||
StoryResponse upload(StorySaveDTO storySaveDTO, FileData file);
|
||||
|
||||
// 演示多文件上传
|
||||
@Open("story.upload.more")
|
||||
StoryResponse upload2(StorySaveDTO storySaveDTO,
|
||||
@NotNull(message = "身份证正面必填") FileData idCardFront,
|
||||
@NotNull(message = "身份证背面必填") FileData idCardBack);
|
||||
|
||||
// 演示多文件上传
|
||||
@Open("story.upload.list")
|
||||
StoryResponse upload3(StorySaveDTO storySaveDTO, @Size(min = 2, message = "最少上传2个文件") List<FileData> files);
|
||||
|
||||
// 下载
|
||||
@Open("story.download")
|
||||
FileData download(Integer id);
|
||||
}
|
@@ -0,0 +1,132 @@
|
||||
package com.gitee.sop.storyweb.open.impl;
|
||||
|
||||
import com.gitee.sop.storyweb.open.OpenStory;
|
||||
import com.gitee.sop.storyweb.open.req.StorySaveDTO;
|
||||
import com.gitee.sop.storyweb.open.resp.StoryResponse;
|
||||
import com.gitee.sop.support.context.OpenContext;
|
||||
import com.gitee.sop.support.dto.CommonFileData;
|
||||
import com.gitee.sop.support.dto.FileData;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.dubbo.config.annotation.DubboService;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
|
||||
/**
|
||||
* 开放接口实现
|
||||
*
|
||||
* @author 六如
|
||||
*/
|
||||
@DubboService(validation = "true")
|
||||
public class OpenStoryImpl implements OpenStory {
|
||||
|
||||
|
||||
@Override
|
||||
public Integer save(StorySaveDTO storySaveDTO) {
|
||||
System.out.println("save storySaveDTO:" + storySaveDTO);
|
||||
System.out.println("appId:" + OpenContext.getAppId());
|
||||
System.out.println("apiName:" + OpenContext.getApiName());
|
||||
System.out.println("version:" + OpenContext.getVersion());
|
||||
System.out.println("token:" + OpenContext.getAppAuthToken());
|
||||
System.out.println("ip:" + OpenContext.getClientIp());
|
||||
System.out.println("traceId:" + OpenContext.getTraceId());
|
||||
|
||||
Assert.notNull(OpenContext.getAppId());
|
||||
Assert.notNull(OpenContext.getApiName());
|
||||
Assert.notNull(OpenContext.getVersion());
|
||||
Assert.notNull(OpenContext.getClientIp());
|
||||
Assert.notNull(OpenContext.getTraceId());
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Integer update(Integer id, StorySaveDTO storySaveDTO) {
|
||||
System.out.println("update, id:" + id + ", storySaveDTO=" + storySaveDTO);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public StoryResponse getById(Integer id) {
|
||||
StoryResponse storyResponse = new StoryResponse();
|
||||
storyResponse.setId(id);
|
||||
storyResponse.setName("乌鸦喝水");
|
||||
return storyResponse;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public StoryResponse getByIdV2(Long id) {
|
||||
StoryResponse storyResponse = new StoryResponse();
|
||||
storyResponse.setId(2);
|
||||
storyResponse.setName("乌鸦喝水2.0");
|
||||
return storyResponse;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public StoryResponse upload(StorySaveDTO storySaveDTO, FileData file) {
|
||||
System.out.println("upload:" + storySaveDTO);
|
||||
checkFile(Arrays.asList(file));
|
||||
|
||||
StoryResponse storyResponse = new StoryResponse();
|
||||
storyResponse.setId(1);
|
||||
storyResponse.setName(storySaveDTO.getStoryName());
|
||||
return storyResponse;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public StoryResponse upload2(StorySaveDTO storySaveDTO, FileData idCardFront, FileData idCardBack) {
|
||||
List<String> list = new ArrayList<>();
|
||||
System.out.println("upload:" + storySaveDTO);
|
||||
checkFile(Arrays.asList(idCardFront, idCardBack));
|
||||
|
||||
StoryResponse storyResponse = new StoryResponse();
|
||||
storyResponse.setId(1);
|
||||
storyResponse.setName(storySaveDTO.getStoryName());
|
||||
return storyResponse;
|
||||
}
|
||||
|
||||
@Override
|
||||
public StoryResponse upload3(StorySaveDTO storySaveDTO, List<FileData> files) {
|
||||
List<String> list = new ArrayList<>();
|
||||
list.add("upload:" + storySaveDTO);
|
||||
checkFile(files);
|
||||
|
||||
StoryResponse storyResponse = new StoryResponse();
|
||||
storyResponse.setId(1);
|
||||
storyResponse.setName(storySaveDTO.getStoryName());
|
||||
return storyResponse;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileData download(Integer id) {
|
||||
CommonFileData fileData = new CommonFileData();
|
||||
ClassPathResource resource = new ClassPathResource("download.txt");
|
||||
fileData.setOriginalFilename(resource.getFilename());
|
||||
try {
|
||||
fileData.setData(IOUtils.toByteArray(resource.getInputStream()));
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return fileData;
|
||||
}
|
||||
|
||||
private void checkFile(List<FileData> fileDataList) {
|
||||
for (FileData file : fileDataList) {
|
||||
Assert.notNull(file.getName());
|
||||
Assert.notNull(file.getOriginalFilename());
|
||||
Assert.notNull(file.getBytes());
|
||||
Assert.isTrue(!file.isEmpty());
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,23 @@
|
||||
package com.gitee.sop.storyweb.open.req;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @author 六如
|
||||
*/
|
||||
@Data
|
||||
public class StorySaveDTO implements Serializable {
|
||||
private static final long serialVersionUID = -1214422742659231037L;
|
||||
|
||||
@NotBlank(message = "故事名称必填")
|
||||
private String storyName;
|
||||
|
||||
@NotNull(message = "添加时间必填")
|
||||
private Date addTime;
|
||||
|
||||
}
|
@@ -0,0 +1,18 @@
|
||||
package com.gitee.sop.storyweb.open.resp;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author 六如
|
||||
*/
|
||||
@Data
|
||||
public class StoryResponse implements Serializable {
|
||||
private static final long serialVersionUID = -3743413007549072654L;
|
||||
|
||||
private Integer id;
|
||||
|
||||
private String name;
|
||||
|
||||
}
|
@@ -0,0 +1 @@
|
||||
dubbo.registry.address=zookeeper://localhost:2181
|
@@ -0,0 +1,2 @@
|
||||
|
||||
dubbo.registry.address=nacos://localhost:8848
|
@@ -0,0 +1,9 @@
|
||||
spring.profiles.active=dev
|
||||
|
||||
server.port=7071
|
||||
spring.application.name=story-service
|
||||
|
||||
dubbo.protocol.name=dubbo
|
||||
dubbo.protocol.port=-1
|
||||
dubbo.application.qos-enable=false
|
||||
dubbo.registry.address=zookeeper://localhost:2181
|
@@ -0,0 +1 @@
|
||||
abc,你好~!@#
|
@@ -0,0 +1,10 @@
|
||||
# 错误配置
|
||||
|
||||
# 系统配置
|
||||
isp.error_isv.common-error=The system is busy.
|
||||
isp.error_isv.invalid-parameter=Invalid parameter, {0}
|
||||
|
||||
# ==== 参数配置 ====
|
||||
|
||||
goods.remark.notNull=The goods_remark can not be null
|
||||
goods.comment.length=The goods_comment length must >= {0} and <= {1}
|
@@ -0,0 +1,14 @@
|
||||
# 错误配置
|
||||
|
||||
# 系统繁忙
|
||||
isp.error_isv.common-error=\u7cfb\u7edf\u7e41\u5fd9
|
||||
# 参数无效
|
||||
isp.error_isv.invalid-parameter=\u53c2\u6570\u65e0\u6548, {0}
|
||||
|
||||
# ==== 参数配置 ====
|
||||
|
||||
# 商品备注不能为空
|
||||
goods.remark.notNull=\u5546\u54c1\u5907\u6ce8\u4e0d\u80fd\u4e3a\u7a7a
|
||||
# 商品评论长度必须在{0}和{1}之间
|
||||
goods.comment.length=\u5546\u54c1\u8bc4\u8bba\u957f\u5ea6\u5fc5\u987b\u5728{0}\u548c{1}\u4e4b\u95f4
|
||||
|
@@ -0,0 +1,2 @@
|
||||
isp.goods_error_100=the goods_name can NOT be null
|
||||
isp.goods_error_101=the goods_name must bigger than {0}
|
@@ -0,0 +1,5 @@
|
||||
# 商品名字不能为空
|
||||
isp.goods_error_100=\u5546\u54C1\u540D\u79F0\u4E0D\u80FD\u4E3A\u7A7A
|
||||
|
||||
# 商品名称太短,不能小于{0}个字
|
||||
isp.goods_error_101=\u5546\u54C1\u540D\u79F0\u592A\u77ED\uFF0C\u4E0D\u80FD\u5C0F\u4E8E{0}\u4E2A\u5B57
|
Reference in New Issue
Block a user