Skip to content

Commit

Permalink
concept cloud plugin template
Browse files Browse the repository at this point in the history
  • Loading branch information
tanghanzheng committed Jun 8, 2023
1 parent 31d4c86 commit fcfd8d5
Show file tree
Hide file tree
Showing 13 changed files with 131 additions and 60 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
server:
port: 9999
spring:
application:
name: $ARTIFACT$-application-boot
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

@Tag(name = "示例")
@RestController
@RequestMapping("/sample")
@RequestMapping("sample")
public class SampleController {

@Autowired
Expand Down Expand Up @@ -46,7 +46,7 @@ public void delete(@RequestBody SampleDeleteCommand delete, @Login User user) {
}

@Operation(summary = "详情")
@GetMapping("/{id}")
@GetMapping("{id}")
public SampleVO get(@Parameter(description = "ID") @PathVariable String id) {
return sampleSearcher.get(id);
}
Expand All @@ -58,7 +58,7 @@ public List<SampleVO> list(SampleQuery query) {
}

@Operation(summary = "分页查询")
@GetMapping("/page")
@GetMapping("page")
public Pages<SampleVO> page(SampleQuery query, Pages.Args page) {
return sampleSearcher.page(query, page);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import $PACKAGE$.domain.sample.Sample;
import $PACKAGE$.domain.sample.SampleImpl;
import $PACKAGE$.domain.user.User;
import $PACKAGE$.domain.user.Users;
import $PACKAGE$.module.sample.domain.sample.view.SampleCreateCommand;
import $PACKAGE$.module.sample.domain.sample.view.SampleUpdateCommand;
import $PACKAGE$.module.sample.domain.sample.view.SampleQuery;
Expand All @@ -15,6 +16,8 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.stream.Collectors;

/**
* 领域模型转换适配器实现
*/
Expand All @@ -36,7 +39,7 @@ public Sample from(SampleCreateCommand create) {
return new SampleImpl.Builder()
.id(id)
.user(null)
.users(factory.createEmptyCollection(Users.class))
.users(factory.emptyCollection(Users.class))
.build(validator);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Set;
import java.util.*;
import java.util.stream.Collectors;

/**
Expand Down Expand Up @@ -113,9 +112,6 @@ public Collection<Sample> pos2dos(Collection<? extends SamplePO> pos) {
* 如果有关联表
* <p>
* 可以重写该方法添加关联关系
*
* @see com.github.linyuzai.domain.core.DomainRepository#create(DomainObject)
* @see com.github.linyuzai.domain.core.DomainRepository#create(DomainCollection)
*/
@Transactional
@Override
Expand All @@ -134,9 +130,6 @@ public void create(Sample sample) {
* 如果有关联表
* <p>
* 可以重写该方法删除关联关系
*
* @see com.github.linyuzai.domain.core.DomainRepository#delete(DomainObject)
* @see com.github.linyuzai.domain.core.DomainRepository#delete(DomainCollection)
*/
@Transactional
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@

@Tag(name = "用户")
@RestController
@RequestMapping("/user")
@RequestMapping("user")
public class UserController {

@Autowired
private UserSearcher userSearcher;

@Operation(summary = "用户详情")
@GetMapping("/{id}")
@GetMapping("{id}")
public UserVO get(@Parameter(description = "用户ID") @PathVariable String id) {
return userSearcher.get(id);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,21 @@
import $PACKAGE$.domain.user.User;
import $PACKAGE$.domain.user.UserRepository;
import $PACKAGE$.domain.user.Users;
import $PACKAGE$.rpc.ConditionsRO;
import $PACKAGE$.rpc.user.RPCUserFacadeAdapter;
import $PACKAGE$.rpc.user.UserRO;
import com.github.linyuzai.domain.core.condition.Conditions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;

/**
* 提供给 Feign 调用的用户接口
*/
@RestController
@RequestMapping("/feign/user")
@RequestMapping("feign/user")
public class FeignUserController {

@Autowired
Expand All @@ -28,7 +29,7 @@ public class FeignUserController {
/**
* 根据用户 id 获得用户信息
*/
@GetMapping("/{id}")
@GetMapping("{id}")
public UserRO get(@PathVariable String id) {
User user = userRepository.get(id);
if (user == null) {
Expand All @@ -38,13 +39,38 @@ public UserRO get(@PathVariable String id) {
}

/**
* 根据条件获得用户信息
* 根据用户条件获得用户信息
* <p>
* 避免过长用 POST
* 避免参数过长用 POST
*/
@PostMapping("/conditions")
public List<UserRO> conditions(ConditionsRO ro) {
Users users = userRepository.select(rpcUserFacadeAdapter.ro2conditions(ro));
@PostMapping("conditions")
public UserRO get(@RequestBody Conditions conditions) {
User user = userRepository.get(conditions);
if (user == null) {
return null;
}
return rpcUserFacadeAdapter.do2ro(user);
}

/**
* 根据 id 列表获得用户信息列表
* <p>
* 避免参数过长用 POST
*/
@PostMapping("list/ids")
public List<UserRO> list(@RequestBody Collection<String> ids) {
Users users = userRepository.select(ids);
return users.stream().map(rpcUserFacadeAdapter::do2ro).collect(Collectors.toList());
}

/**
* 根据条件获得用户信息列表
* <p>
* 避免参数过长用 POST
*/
@PostMapping("list/conditions")
public List<UserRO> conditions(@RequestBody Conditions conditions) {
Users users = userRepository.select(conditions);
return users.stream().map(rpcUserFacadeAdapter::do2ro).collect(Collectors.toList());
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package $PACKAGE$.rpc.feign.user;

import $PACKAGE$.rpc.ConditionsRO;
import $PACKAGE$.rpc.Response;
import $PACKAGE$.rpc.user.RPCUserFacadeAdapter;
import $PACKAGE$.rpc.user.UserRO;
Expand Down Expand Up @@ -48,18 +47,25 @@ protected UserRO doGet(String id) {

@Override
protected Collection<UserRO> doSelect(Collection<String> ids) {
throw new UnsupportedOperationException();
Response<List<UserRO>> response = userFeignClient.list(ids);
if (response.getResult()) {
return response.getObject();
}
throw new RuntimeException(response.getMessage());
}

@Override
protected UserRO doGet(Conditions conditions) {
throw new UnsupportedOperationException();
Response<UserRO> response = userFeignClient.get(conditions);
if (response.getResult()) {
return response.getObject();
}
throw new RuntimeException(response.getMessage());
}

@Override
protected Collection<UserRO> doSelect(Conditions conditions) {
ConditionsRO ro = rpcUserFacadeAdapter.conditions2ro(conditions);
Response<List<UserRO>> response = userFeignClient.list(ro);
Response<List<UserRO>> response = userFeignClient.list(conditions);
if (response.getResult()) {
return response.getObject();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package $PACKAGE$.rpc.feign.user;

import $PACKAGE$.rpc.ConditionsRO;
import $PACKAGE$.rpc.Response;
import $PACKAGE$.rpc.user.UserRO;
import com.github.linyuzai.domain.core.condition.Conditions;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;

import java.util.Collection;
import java.util.List;

/**
Expand All @@ -20,12 +21,24 @@ public interface UserFeignClient {
/**
* 根据 id 获得用户信息
*/
@GetMapping("/feign/user/{id}")
@GetMapping("feign/user/{id}")
Response<UserRO> get(@PathVariable String id);

/**
* 根据条件获得用户信息
*/
@PostMapping("/feign/user/conditions")
Response<List<UserRO>> list(@RequestBody ConditionsRO ro);
@PostMapping("feign/user/conditions")
Response<UserRO> get(@RequestBody Conditions conditions);

/**
* 根据 id 列表获得用户信息
*/
@PostMapping("/feign/user/list/ids")
Response<List<UserRO>> list(@RequestBody Collection<String> ids);

/**
* 根据条件获得用户信息列表
*/
@PostMapping("feign/user/list/conditions")
Response<List<UserRO>> list(@RequestBody Conditions conditions);
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.github.linyuzai.domain.core.DomainObject;
import com.github.linyuzai.domain.core.Identifiable;
import com.github.linyuzai.domain.core.condition.Conditions;

/**
* 远程对象转换适配器
Expand All @@ -21,18 +20,4 @@ public interface RemoteObjectFacadeAdapter<T extends DomainObject, R extends Ide
* 远程对象转领域模型
*/
T ro2do(R ro);

/**
* 条件转远程对象
*/
default ConditionsRO conditions2ro(Conditions conditions) {
return new ConditionsRO();
}

/**
* 远程对象转条件
*/
default Conditions ro2conditions(ConditionsRO ro) {
return new Conditions();
}
}
57 changes: 57 additions & 0 deletions concept-cloud/pluginew/java/1.0.0/sql/sample.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
begin;

create table t_user
(
id varchar(64) not null
primary key,
username varchar(255) not null,
password varchar(255) not null,
nickname varchar(255) not null,
avatar varchar(255) null,
enabled tinyint(1) default 1 not null,
create_time datetime not null
);

INSERT INTO t_user (id, username, password, nickname, avatar, enabled, create_time)
VALUES ('user1', 'user1', 'user1', 'user1', null, 1, '2001-01-01 00:00:00');
INSERT INTO t_user (id, username, password, nickname, avatar, enabled, create_time)
VALUES ('user2', 'user2', 'user2', 'user2', null, 1, '2002-02-02 00:00:00');
INSERT INTO t_user (id, username, password, nickname, avatar, enabled, create_time)
VALUES ('user3', 'user3', 'user3', 'user3', null, 1, '2003-03-03 00:00:00');
INSERT INTO t_user (id, username, password, nickname, avatar, enabled, create_time)
VALUES ('user4', 'user4', 'user4', 'user4', null, 1, '2004-04-04 00:00:00');
INSERT INTO t_user (id, username, password, nickname, avatar, enabled, create_time)
VALUES ('user5', 'user5', 'user5', 'user5', null, 1, '2005-05-05 00:00:00');

create table t_sample
(
id varchar(64) not null
primary key,
sample varchar(255) not null,
user_id varchar(64) null,
deleted tinyint(1) default 0 not null
);

INSERT INTO t_sample (id, sample, user_id, deleted)
VALUES ('sample1', 'sample1', 'user1', 0);
INSERT INTO t_sample (id, sample, user_id, deleted)
VALUES ('sample2', 'sample2', 'user2', 0);

create table t_sample_user
(
id bigint auto_increment
primary key,
sample_id varchar(64) not null,
user_id varchar(64) not null
);

INSERT INTO t_sample_user (id, sample_id, user_id)
VALUES (1, 'sample1', 'user3');
INSERT INTO t_sample_user (id, sample_id, user_id)
VALUES (2, 'sample1', 'user4');
INSERT INTO t_sample_user (id, sample_id, user_id)
VALUES (3, 'sample2', 'user3');
INSERT INTO t_sample_user (id, sample_id, user_id)
VALUES (4, 'sample2', 'user5');

commit;
Binary file modified concept-cloud/pluginew/java/1.0.0/template.zip
Binary file not shown.
3 changes: 2 additions & 1 deletion concept-cloud/pluginew/starter_new.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
".gitignore",
"gradlew",
"gradlew.bat",
"HELP.md"
"HELP.md",
"sql/sample.sql"
],
"versions": {
"gradle": "7.4-bin",
Expand Down

0 comments on commit fcfd8d5

Please sign in to comment.