mirror of
https://gitee.com/durcframework/SOP.git
synced 2025-08-11 12:56:28 +08:00
5.0
This commit is contained in:
@@ -5,6 +5,8 @@ import com.gitee.sop.storyweb.open.resp.StoryResponse;
|
||||
import com.gitee.sop.support.annotation.Open;
|
||||
import com.gitee.sop.support.request.FileData;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import javax.validation.constraints.Size;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -14,11 +16,18 @@ import java.util.List;
|
||||
*/
|
||||
public interface OpenStory {
|
||||
|
||||
@Open("story.save")
|
||||
Integer save(StorySaveDTO storySaveDTO);
|
||||
|
||||
@Open("story.update")
|
||||
Integer update(Integer id, StorySaveDTO storySaveDTO);
|
||||
|
||||
StoryResponse getById(Integer id);
|
||||
@Open("story.get")
|
||||
StoryResponse getById(@NotNull(message = "id必填") Integer id);
|
||||
|
||||
@Open(value = "story.get", version = "2.0")
|
||||
StoryResponse getByIdV2(Long id);
|
||||
|
||||
|
||||
// 默认方法,注解放在这里也有效
|
||||
@Open("story.find")
|
||||
@@ -30,12 +39,20 @@ public interface OpenStory {
|
||||
}
|
||||
|
||||
// 演示单文件上传
|
||||
@Open("story.upload")
|
||||
StoryResponse upload(StorySaveDTO storySaveDTO, FileData file);
|
||||
|
||||
// 演示多文件上传
|
||||
StoryResponse upload2(StorySaveDTO storySaveDTO, FileData idCardFront, FileData idCardBack);
|
||||
@Open("story.upload.more")
|
||||
StoryResponse upload2(StorySaveDTO storySaveDTO,
|
||||
@NotNull(message = "身份证正面必填") FileData idCardFront,
|
||||
@NotNull(message = "身份证背面必填") FileData idCardBack);
|
||||
|
||||
// 演示多文件上传
|
||||
StoryResponse upload3(StorySaveDTO storySaveDTO, List<FileData> files);
|
||||
@Open("story.upload.list")
|
||||
StoryResponse upload3(StorySaveDTO storySaveDTO, @Size(min = 2, message = "最少上传2个文件") List<FileData> files);
|
||||
|
||||
// 下载
|
||||
@Open("story.download")
|
||||
FileData download(Integer id);
|
||||
}
|
||||
|
@@ -5,15 +5,25 @@ 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.context.OpenContext;
|
||||
import com.gitee.sop.support.request.CommonFileData;
|
||||
import com.gitee.sop.support.request.FileData;
|
||||
import org.apache.dubbo.config.annotation.DubboService;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import javax.validation.constraints.Min;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import javax.validation.constraints.Min;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.dubbo.config.annotation.DubboService;
|
||||
import org.apache.dubbo.validation.MethodValidated;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
@@ -24,7 +34,7 @@ import java.util.List;
|
||||
@DubboService(validation = "true")
|
||||
public class OpenStoryImpl implements OpenStory {
|
||||
|
||||
@Open("story.save")
|
||||
|
||||
@Override
|
||||
public Integer save(StorySaveDTO storySaveDTO) {
|
||||
System.out.println("save storySaveDTO:" + storySaveDTO);
|
||||
@@ -44,23 +54,32 @@ public class OpenStoryImpl implements OpenStory {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Open("story.update")
|
||||
|
||||
@Override
|
||||
public Integer update(Integer id, StorySaveDTO storySaveDTO) {
|
||||
System.out.println("update, id:" + id + ", storySaveDTO=" + storySaveDTO);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Open("story.get")
|
||||
|
||||
@Override
|
||||
public StoryResponse getById(@NotNull(message = "id必填") Integer id) {
|
||||
public StoryResponse getById(Integer id) {
|
||||
StoryResponse storyResponse = new StoryResponse();
|
||||
storyResponse.setId(id);
|
||||
storyResponse.setName("乌鸦喝水");
|
||||
return storyResponse;
|
||||
}
|
||||
|
||||
@Open("story.upload")
|
||||
|
||||
@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);
|
||||
@@ -72,7 +91,7 @@ public class OpenStoryImpl implements OpenStory {
|
||||
return storyResponse;
|
||||
}
|
||||
|
||||
@Open("story.upload.more")
|
||||
|
||||
@Override
|
||||
public StoryResponse upload2(StorySaveDTO storySaveDTO, FileData idCardFront, FileData idCardBack) {
|
||||
List<String> list = new ArrayList<>();
|
||||
@@ -85,10 +104,8 @@ public class OpenStoryImpl implements OpenStory {
|
||||
return storyResponse;
|
||||
}
|
||||
|
||||
|
||||
@Open("story.upload.list")
|
||||
@Override
|
||||
public StoryResponse upload3(StorySaveDTO storySaveDTO, @Min(value = 2,message = "最少上传2个文件") List<FileData> files) {
|
||||
public StoryResponse upload3(StorySaveDTO storySaveDTO, List<FileData> files) {
|
||||
List<String> list = new ArrayList<>();
|
||||
list.add("upload:" + storySaveDTO);
|
||||
checkFile(files);
|
||||
@@ -99,6 +116,19 @@ public class OpenStoryImpl implements OpenStory {
|
||||
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());
|
||||
|
1
sop-example/sop-story/src/main/resources/download.txt
Normal file
1
sop-example/sop-story/src/main/resources/download.txt
Normal file
@@ -0,0 +1 @@
|
||||
abc,你好~!@#
|
Reference in New Issue
Block a user