Skip to content

Commit

Permalink
Merge pull request #7 from ClearXs/0.1.x
Browse files Browse the repository at this point in the history
0.1.x
  • Loading branch information
ClearXs committed Feb 23, 2024
2 parents 8585049 + 4513b07 commit 847aa95
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 60 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

<groupId>cc.allio</groupId>
<artifactId>Turbo</artifactId>
<version>0.1.0-beta.1.RELEASE</version>
<version>0.1.0</version>
<name>Turbo</name>
<description>Turbo快速开发平台</description>
<url>https://github.com/ClearXs/Turbo.git</url>
Expand All @@ -25,7 +25,7 @@

<properties>
<java.version>21</java.version>
<uno.version>1.1.6-beta.1</uno.version>
<uno.version>1.1.6</uno.version>
<maven-source-plugin.version>3.3.0</maven-source-plugin.version>
<maven-plugin.version>3.11.0</maven-plugin.version>
<knife4j.version>4.3.0</knife4j.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import cc.allio.uno.core.function.lambda.MethodBiConsumer;
import cc.allio.uno.data.orm.dsl.Operator;
import cc.allio.uno.data.orm.dsl.Table;
import cc.allio.uno.data.orm.dsl.dml.InsertOperator;
import cc.allio.uno.data.orm.dsl.dml.QueryOperator;
import cc.allio.uno.data.orm.dsl.dml.UpdateOperator;
import cc.allio.uno.data.orm.executor.CommandExecutor;
Expand Down Expand Up @@ -32,6 +33,19 @@ public class TenantInterceptor implements Interceptor {
public void onQueryBefore(CommandExecutor commandExecutor, Operator<?> operator) {
if (operator instanceof QueryOperator queryOperator) {
Table table = queryOperator.getTable();
allowTenant(table, queryOperator::eq);
}
}

/**
* @param commandExecutor commandExecutor
* @param operator operator
*/
@Override
public void onSaveBefore(CommandExecutor commandExecutor, Operator<?> operator) {
if (operator instanceof InsertOperator insertOperator) {
Table table = insertOperator.getTable();
allowTenant(table, insertOperator::strictFill);
}
}

Expand All @@ -43,7 +57,7 @@ public void onQueryBefore(CommandExecutor commandExecutor, Operator<?> operator)
public void onUpdateBefore(CommandExecutor commandExecutor, Operator<?> operator) {
if (operator instanceof UpdateOperator updateOperator) {
Table table = updateOperator.getTable();
allowTenant(table, updateOperator::eq);
allowTenant(table, updateOperator::strictFill);
}
}

Expand Down
12 changes: 0 additions & 12 deletions src/main/java/cc/allio/turbo/common/web/TurboCrudController.java
Original file line number Diff line number Diff line change
Expand Up @@ -166,18 +166,6 @@ public void export(@RequestBody QueryParam<T> params, HttpServletResponse respon
interceptor.onExportAfter(service, response, ds);
}

/**
* 导出
*/
@Operation(summary = "导出")
@PostMapping("/export")
public void export(HttpServletResponse response, @RequestBody QueryParam<T> params) {
Class<T> clazz = getEntityType();
QueryWrapper<T> queryWrapper = Conditions.entityQuery(params, clazz);
List<T> list = service.list(queryWrapper);
ExcelUtil.export(response, list, clazz);
}

/**
* 导入
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public R<DomainEntity> details(@PathVariable("boId") Long boId, @PathVariable("i
public R<List<DomainEntity>> list(@PathVariable("boId") Long boId, @RequestBody QueryParam<DomainEntity> params) throws BizException {
QueryWrapper<DomainEntity> wrapper = Wrappers.query();
domainService.getBoRepositoryOrThrow(boId)
.inspectOn("list", context ->
.aspectOn("list", context ->
Optionals.withBoth(context.getTypeFirst(QueryWrapper.class), context.getTypeFirst(BoSchema.class))
.ifPresent(pair -> {
QueryWrapper<DomainEntity> queryWrapper = pair.getFirst();
Expand All @@ -101,7 +101,7 @@ public R<List<DomainEntity>> list(@PathVariable("boId") Long boId, @RequestBody
public R<IPage<DomainEntity>> page(@PathVariable("boId") Long boId, @RequestBody QueryParam<DomainEntity> params) throws BizException {
QueryWrapper<DomainEntity> wrapper = Wrappers.query();
domainService.getBoRepositoryOrThrow(boId)
.inspectOn("page", context ->
.aspectOn("page", context ->
Optionals.withBoth(context.getTypeFirst(QueryWrapper.class), context.getTypeFirst(BoSchema.class))
.ifPresent(pair -> {
QueryWrapper<DomainEntity> queryWrapper = pair.getFirst();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -580,75 +580,75 @@ default <Z extends TreeDomain<DomainEntity, Z>> List<Z> tree(Long boId, Wrapper<
interface IDomainCrudTreeRepositoryService extends ITurboCrudTreeRepositoryService<DomainEntity> {

/**
* @see #inspectOn(String, ThrowingMethodConsumer)
* @see #aspectOn(String, ThrowingMethodConsumer)
*/
default <T> void inspectOn(ThrowingMethodConsumer<T> domainMethod, ThrowingMethodConsumer<OptionalContext> callback) {
default <T> void aspectOn(ThrowingMethodConsumer<T> domainMethod, ThrowingMethodConsumer<OptionalContext> callback) {
String domainMethodName = domainMethod.getMethodName();
inspectOn(domainMethodName, callback);
aspectOn(domainMethodName, callback);
}

/**
* @see #inspectOn(String, ThrowingMethodConsumer)
* @see #aspectOn(String, ThrowingMethodConsumer)
*/
default <T> void inspectOn(ThrowingMethodSupplier<T> domainMethod, ThrowingMethodConsumer<OptionalContext> callback) {
default <T> void aspectOn(ThrowingMethodSupplier<T> domainMethod, ThrowingMethodConsumer<OptionalContext> callback) {
String domainMethodName = domainMethod.getMethodName();
inspectOn(domainMethodName, callback);
aspectOn(domainMethodName, callback);
}

/**
* @see #inspectOn(String, ThrowingMethodConsumer)
* @see #aspectOn(String, ThrowingMethodConsumer)
*/
default <T, R> void inspectOn(ThrowingMethodFunction<T, R> domainMethod, ThrowingMethodConsumer<OptionalContext> callback) {
default <T, R> void aspectOn(ThrowingMethodFunction<T, R> domainMethod, ThrowingMethodConsumer<OptionalContext> callback) {
String domainMethodName = domainMethod.getMethodName();
inspectOn(domainMethodName, callback);
aspectOn(domainMethodName, callback);
}

/**
* @see #inspectOn(String, ThrowingMethodConsumer)
* @see #aspectOn(String, ThrowingMethodConsumer)
*/
default <T1, T2> void inspectOn(ThrowingMethodBiConsumer<T1, T2> domainMethod, ThrowingMethodConsumer<OptionalContext> callback) {
default <T1, T2> void aspectOn(ThrowingMethodBiConsumer<T1, T2> domainMethod, ThrowingMethodConsumer<OptionalContext> callback) {
String domainMethodName = domainMethod.getMethodName();
inspectOn(domainMethodName, callback);
aspectOn(domainMethodName, callback);
}

/**
* @see #inspectOn(String, ThrowingMethodConsumer)
* @see #aspectOn(String, ThrowingMethodConsumer)
*/
default <T1, T2, R> void inspectOn(ThrowingMethodBiFunction<T1, T2, R> domainMethod, ThrowingMethodConsumer<OptionalContext> callback) {
default <T1, T2, R> void aspectOn(ThrowingMethodBiFunction<T1, T2, R> domainMethod, ThrowingMethodConsumer<OptionalContext> callback) {
String domainMethodName = domainMethod.getMethodName();
inspectOn(domainMethodName, callback);
aspectOn(domainMethodName, callback);
}

/**
* @see #inspectOn(String, ThrowingMethodConsumer)
* @see #aspectOn(String, ThrowingMethodConsumer)
*/
default <T1, T2, T3> void inspectOn(ThrowingMethodTerConsumer<T1, T2, T3> domainMethod, ThrowingMethodConsumer<OptionalContext> callback) {
default <T1, T2, T3> void aspectOn(ThrowingMethodTerConsumer<T1, T2, T3> domainMethod, ThrowingMethodConsumer<OptionalContext> callback) {
String domainMethodName = domainMethod.getMethodName();
inspectOn(domainMethodName, callback);
aspectOn(domainMethodName, callback);
}

/**
* @see #inspectOn(String, ThrowingMethodConsumer)
* @see #aspectOn(String, ThrowingMethodConsumer)
*/
default <T1, T2, T3, R> void inspectOn(ThrowingMethodTerFunction<T1, T2, T3, R> domainMethod, ThrowingMethodConsumer<OptionalContext> callback) {
default <T1, T2, T3, R> void aspectOn(ThrowingMethodTerFunction<T1, T2, T3, R> domainMethod, ThrowingMethodConsumer<OptionalContext> callback) {
String domainMethodName = domainMethod.getMethodName();
inspectOn(domainMethodName, callback);
aspectOn(domainMethodName, callback);
}

/**
* @see #inspectOn(String, ThrowingMethodConsumer)
* @see #aspectOn(String, ThrowingMethodConsumer)
*/
default <T1, T2, T3, T4> void inspectOn(ThrowingMethodQueConsumer<T1, T2, T3, T4> domainMethod, ThrowingMethodConsumer<OptionalContext> callback) {
default <T1, T2, T3, T4> void aspectOn(ThrowingMethodQueConsumer<T1, T2, T3, T4> domainMethod, ThrowingMethodConsumer<OptionalContext> callback) {
String domainMethodName = domainMethod.getMethodName();
inspectOn(domainMethodName, callback);
aspectOn(domainMethodName, callback);
}

/**
* @see #inspectOn(String, ThrowingMethodConsumer)
* @see #aspectOn(String, ThrowingMethodConsumer)
*/
default <T1, T2, T3, T4, R> void inspectOn(ThrowingMethodQueFunction<T1, T2, T3, T4, R> domainMethod, ThrowingMethodConsumer<OptionalContext> callback) {
default <T1, T2, T3, T4, R> void aspectOn(ThrowingMethodQueFunction<T1, T2, T3, T4, R> domainMethod, ThrowingMethodConsumer<OptionalContext> callback) {
String domainMethodName = domainMethod.getMethodName();
inspectOn(domainMethodName, callback);
aspectOn(domainMethodName, callback);
}

/**
Expand All @@ -663,18 +663,18 @@ default <T1, T2, T3, T4, R> void inspectOn(ThrowingMethodQueFunction<T1, T2, T3,
* @param domainMethod 领域行为
* @param callback 当给定领域行为发生时的回调
*/
void inspectOn(String domainMethod, ThrowingMethodConsumer<OptionalContext> callback);
void aspectOn(String domainMethod, ThrowingMethodConsumer<OptionalContext> callback);

/**
* 获取领域切面的队列
*/
Queue<DomainInspect> getDomainInspects();
Queue<DomainAspect> getDomainAspects();
}

/**
* 领域对象切面
*/
interface DomainInspect {
interface DomainAspect {

/**
* 获取领域行为
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,27 +133,27 @@ IDomainCrudTreeRepositoryService createAopRepository(CommandExecutor commandExec

public static class BoDomainCrudTreeRepositoryServiceImpl extends SimpleTurboCrudTreeRepositoryServiceImpl<DomainEntity> implements IDomainCrudTreeRepositoryService {

private final Queue<DomainInspect> domainInspects;
private final Queue<DomainAspect> domainAspects;

public BoDomainCrudTreeRepositoryServiceImpl(CommandExecutor commandExecutor) {
super(commandExecutor, DomainEntity.class);
this.domainInspects = Queues.newConcurrentLinkedQueue();
this.domainAspects = Queues.newConcurrentLinkedQueue();
}

@Override
public void inspectOn(String domainMethod, ThrowingMethodConsumer<OptionalContext> callback) {
this.domainInspects.offer(new DomainInspectImpl(domainMethod, callback));
public void aspectOn(String domainMethod, ThrowingMethodConsumer<OptionalContext> callback) {
this.domainAspects.offer(new DomainInspectImpl(domainMethod, callback));
}

@Override
public Queue<DomainInspect> getDomainInspects() {
return domainInspects;
public Queue<DomainAspect> getDomainAspects() {
return domainAspects;
}
}

@AllArgsConstructor
@Getter
public static class DomainInspectImpl implements DomainInspect {
public static class DomainInspectImpl implements DomainAspect {

private final String domainMethod;
private final ThrowingMethodConsumer<OptionalContext> callback;
Expand All @@ -164,8 +164,8 @@ public static class BoDomainLockRepositoryMethodInterceptor extends LockReposito

public BoDomainLockRepositoryMethodInterceptor(BoSchema schema) {
this.schema = schema;
addIgnoreMethod("inspectOn");
addIgnoreMethod("getDomainInspects");
addIgnoreMethod("aspectOn");
addIgnoreMethod("getDomainAspects");
}

@Override
Expand All @@ -175,11 +175,11 @@ protected Object doInvoke(MethodInvocation invocation, OptionalContext lockConte
Object theThis = invocation.getThis();
Method method = invocation.getMethod();
if (theThis instanceof IDomainCrudTreeRepositoryService domainCrudTreeRepositoryService) {
Queue<DomainInspect> domainInspects = domainCrudTreeRepositoryService.getDomainInspects();
DomainInspect domainInspect = domainInspects.poll();
Queue<DomainAspect> domainAspects = domainCrudTreeRepositoryService.getDomainAspects();
DomainAspect domainInspect = domainAspects.poll();
if (domainInspect != null && isMatch(domainInspect.getDomainMethod(), method)) {
if (log.isDebugEnabled()) {
log.debug("domain object [{}] inspect domain method [{}]", schema.getName(), domainInspect.getDomainMethod());
log.debug("domain object [{}] aspect domain method [{}]", schema.getName(), domainInspect.getDomainMethod());
}
// 存入参数
Object[] arguments = invocation.getArguments();
Expand All @@ -189,7 +189,7 @@ protected Object doInvoke(MethodInvocation invocation, OptionalContext lockConte
callback.accept(immutableContext);
} catch (Throwable ex) {
// ignore
log.warn("domain object [{}] inspect domain method {} encounter error, now just log error and ignore", schema.getName(), domainInspect.getDomainMethod(), ex);
log.warn("domain object [{}] aspect domain method {} encounter error, now just log error and ignore", schema.getName(), domainInspect.getDomainMethod(), ex);
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
server:
port: 8600
undertow:
threads:
io: 100
worker: 10

spring:
application:
Expand Down

0 comments on commit 847aa95

Please sign in to comment.