feat:规范化代码

This commit is contained in:
wangyu 2021-12-07 20:22:57 +08:00
parent 23b89d8c56
commit 72550ab68e
16 changed files with 71 additions and 50 deletions

View File

@ -1,7 +1,7 @@
package com.flyfish.framework.dict.controller; package com.flyfish.framework.dict.controller;
import com.flyfish.framework.beans.annotations.RestMapping; import com.flyfish.framework.beans.annotations.RestMapping;
import com.flyfish.framework.controller.ReactiveBaseController; import com.flyfish.framework.controller.reactive.ReactiveBaseController;
import com.flyfish.framework.dict.domain.AutoComplete; import com.flyfish.framework.dict.domain.AutoComplete;
import com.flyfish.framework.domain.base.NameLikeQo; import com.flyfish.framework.domain.base.NameLikeQo;

View File

@ -2,7 +2,7 @@ package com.flyfish.framework.dict.controller;
import com.flyfish.framework.beans.annotations.RestMapping; import com.flyfish.framework.beans.annotations.RestMapping;
import com.flyfish.framework.controller.ReactiveBaseController; import com.flyfish.framework.controller.reactive.ReactiveBaseController;
import com.flyfish.framework.dict.domain.Dictionary; import com.flyfish.framework.dict.domain.Dictionary;
import com.flyfish.framework.dict.domain.DictionaryQo; import com.flyfish.framework.dict.domain.DictionaryQo;

View File

@ -1,7 +1,7 @@
package com.flyfish.framework.file.controller; package com.flyfish.framework.file.controller;
import com.flyfish.framework.controller.ReactiveBaseController; import com.flyfish.framework.controller.reactive.ReactiveBaseController;
import com.flyfish.framework.file.domain.Attachment; import com.flyfish.framework.file.domain.Attachment;
import com.flyfish.framework.file.domain.AttachmentQo; import com.flyfish.framework.file.domain.AttachmentQo;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;

View File

@ -1,6 +1,6 @@
package com.flyfish.framework.form.controller; package com.flyfish.framework.form.controller;
import com.flyfish.framework.controller.ReactiveBaseController; import com.flyfish.framework.controller.reactive.ReactiveBaseController;
import com.flyfish.framework.domain.base.NameLikeQo; import com.flyfish.framework.domain.base.NameLikeQo;
import com.flyfish.framework.form.domain.OnlineForm; import com.flyfish.framework.form.domain.OnlineForm;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;

View File

@ -7,6 +7,9 @@ import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around; import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut; import org.aspectj.lang.annotation.Pointcut;
import org.reactivestreams.Publisher;
import org.reactivestreams.Subscriber;
import org.reactivestreams.Subscription;
import reactor.core.publisher.Flux; import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono; import reactor.core.publisher.Mono;
@ -64,10 +67,14 @@ public class LogAdvice {
private void handleResult(Object result, LogContext context) { private void handleResult(Object result, LogContext context) {
if (null != result) { if (null != result) {
// 判断结果是否是publisher // 判断结果是否是publisher
if (result instanceof Publisher) {
if (result instanceof Mono) { if (result instanceof Mono) {
((Mono<?>) result).subscribe(context::setResult, context::setError, context::end); ((Mono<?>) result).subscribe(context::setResult, context::setError, context::end);
} else if (result instanceof Flux) { } else if (result instanceof Flux) {
((Flux<?>) result).collectList().subscribe(context::setResult, context::setError, context::end); ((Flux<?>) result).collectList().subscribe(context::setResult, context::setError, context::end);
} else {
((Publisher<?>) result).subscribe(new LogSubscriber(context));
}
} else { } else {
context.setResult(result); context.setResult(result);
context.end(); context.end();
@ -77,4 +84,31 @@ public class LogAdvice {
context.end(); context.end();
} }
} }
@RequiredArgsConstructor
@SuppressWarnings("all")
private static class LogSubscriber implements Subscriber<Object> {
private final LogContext context;
@Override
public void onSubscribe(Subscription s) {
}
@Override
public void onNext(Object o) {
context.setResult(o);
}
@Override
public void onError(Throwable t) {
context.setError(t);
}
@Override
public void onComplete() {
context.end();
}
}
} }

View File

@ -1,7 +1,7 @@
package com.flyfish.framework.logging.controller; package com.flyfish.framework.logging.controller;
import com.flyfish.framework.beans.annotations.RestMapping; import com.flyfish.framework.beans.annotations.RestMapping;
import com.flyfish.framework.controller.ReactiveBaseController; import com.flyfish.framework.controller.reactive.ReactiveBaseController;
import com.flyfish.framework.logging.domain.Log; import com.flyfish.framework.logging.domain.Log;
import com.flyfish.framework.logging.domain.LogQo; import com.flyfish.framework.logging.domain.LogQo;

View File

@ -14,7 +14,7 @@ import com.flyfish.framework.handler.JsonLogoutSuccessHandler;
import com.flyfish.framework.initializer.UserInitializer; import com.flyfish.framework.initializer.UserInitializer;
import com.flyfish.framework.service.AuthenticationAuditor; import com.flyfish.framework.service.AuthenticationAuditor;
import com.flyfish.framework.service.AuthenticationLogger; import com.flyfish.framework.service.AuthenticationLogger;
import com.flyfish.framework.service.UserService; import com.flyfish.framework.service.ReactiveUserService;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.boot.context.properties.EnableConfigurationProperties;
@ -165,11 +165,14 @@ public class WebSecurityConfig {
*/ */
@Bean @Bean
@ConditionalOnMissingBean(UserInitializer.class) @ConditionalOnMissingBean(UserInitializer.class)
public UserInitializer userInitializer(UserService userService) { @SuppressWarnings("all")
public UserInitializer userInitializer(ReactiveUserService userService) {
return () -> { return () -> {
UserQo qo = new UserQo(); UserQo qo = new UserQo();
qo.setType(UserType.SUPER_ADMIN.name()); qo.setType(UserType.SUPER_ADMIN.name());
if (userService.count(qo) == 0) { userService.count(qo)
.filter(count -> count == 0)
.flatMap(count -> {
// 初始化用户 // 初始化用户
User user = new User(); User user = new User();
user.setUsername("admin"); user.setUsername("admin");
@ -181,8 +184,8 @@ public class WebSecurityConfig {
user.setPhone("10000000000"); user.setPhone("10000000000");
user.setName("超级管理员"); user.setName("超级管理员");
user.setCode("Administrator"); user.setCode("Administrator");
userService.createSelective(user); return userService.createSelective(user);
} }).subscribe();
}; };
} }
} }

View File

@ -1,5 +1,6 @@
package com.flyfish.framework.controller; package com.flyfish.framework.controller;
import com.flyfish.framework.controller.reactive.ReactiveTreeController;
import com.flyfish.framework.domain.DepartmentQo; import com.flyfish.framework.domain.DepartmentQo;
import com.flyfish.framework.domain.po.Department; import com.flyfish.framework.domain.po.Department;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;

View File

@ -1,5 +1,6 @@
package com.flyfish.framework.controller; package com.flyfish.framework.controller;
import com.flyfish.framework.controller.reactive.ReactiveTreeController;
import com.flyfish.framework.domain.PermissionQo; import com.flyfish.framework.domain.PermissionQo;
import com.flyfish.framework.domain.po.Permission; import com.flyfish.framework.domain.po.Permission;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;

View File

@ -1,5 +1,6 @@
package com.flyfish.framework.controller; package com.flyfish.framework.controller;
import com.flyfish.framework.controller.reactive.ReactiveBaseController;
import com.flyfish.framework.domain.RoleQo; import com.flyfish.framework.domain.RoleQo;
import com.flyfish.framework.domain.po.Role; import com.flyfish.framework.domain.po.Role;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;

View File

@ -3,6 +3,7 @@ package com.flyfish.framework.controller;
import com.flyfish.framework.annotations.Operation; import com.flyfish.framework.annotations.Operation;
import com.flyfish.framework.bean.Result; import com.flyfish.framework.bean.Result;
import com.flyfish.framework.configuration.annotations.CurrentUser; import com.flyfish.framework.configuration.annotations.CurrentUser;
import com.flyfish.framework.controller.reactive.ReactiveBaseController;
import com.flyfish.framework.domain.UserPasswordDto; import com.flyfish.framework.domain.UserPasswordDto;
import com.flyfish.framework.domain.UserQo; import com.flyfish.framework.domain.UserQo;
import com.flyfish.framework.domain.base.IUser; import com.flyfish.framework.domain.base.IUser;

View File

@ -1,15 +1,8 @@
package com.flyfish.framework.domain.authorized; package com.flyfish.framework.domain.authorized;
import com.flyfish.framework.annotations.Property; import com.flyfish.framework.annotations.Property;
import com.flyfish.framework.context.UserContext;
import com.flyfish.framework.domain.base.AuditDomain; import com.flyfish.framework.domain.base.AuditDomain;
import com.flyfish.framework.domain.po.Department;
import com.flyfish.framework.domain.po.User;
import com.flyfish.framework.exception.biz.InvalidBusinessException;
import lombok.Setter; import lombok.Setter;
import org.apache.commons.lang3.StringUtils;
import javax.validation.constraints.NotBlank;
/** /**
* 带鉴权的实体主要以部门隔绝 * 带鉴权的实体主要以部门隔绝
@ -18,19 +11,6 @@ import javax.validation.constraints.NotBlank;
public abstract class AuthorizedDomain extends AuditDomain { public abstract class AuthorizedDomain extends AuditDomain {
// 作用域id一般是部门用户存储时插入 // 作用域id一般是部门用户存储时插入
@NotBlank(message = "请选择当前部")
@Property(readonly = true) @Property(readonly = true)
private String authorizeId; private String authorizeId;
public String getAuthorizeId() {
if (StringUtils.isNotBlank(authorizeId)) {
return authorizeId;
} else {
return UserContext.sharedContext()
.map(UserContext::currentUser)
.map(User::getAuthority)
.filter(StringUtils::isNotBlank)
.orElse(Department.PUBLIC);
}
}
} }

View File

@ -1,8 +1,7 @@
package com.flyfish.framework.beans.excel; package com.flyfish.framework.beans.excel;
import com.flyfish.framework.controller.BaseController; import com.flyfish.framework.controller.reactive.ReactiveBaseController;
import com.flyfish.framework.controller.ReactiveBaseController;
import com.flyfish.framework.domain.base.NameLikeQo; import com.flyfish.framework.domain.base.NameLikeQo;
import com.flyfish.framework.domain.po.ExcelMapping; import com.flyfish.framework.domain.po.ExcelMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;

View File

@ -1,6 +1,6 @@
package com.flyfish.framework.beans.meta; package com.flyfish.framework.beans.meta;
import com.flyfish.framework.controller.ReactiveBaseController; import com.flyfish.framework.controller.reactive.ReactiveBaseController;
import com.flyfish.framework.controller.SafeController; import com.flyfish.framework.controller.SafeController;
import com.flyfish.framework.domain.base.NameLikeQo; import com.flyfish.framework.domain.base.NameLikeQo;
import com.flyfish.framework.domain.base.Qo; import com.flyfish.framework.domain.base.Qo;

View File

@ -1,10 +1,11 @@
package com.flyfish.framework.controller; package com.flyfish.framework.controller.reactive;
import com.flyfish.framework.annotations.Operation; import com.flyfish.framework.annotations.Operation;
import com.flyfish.framework.bean.Result; import com.flyfish.framework.bean.Result;
import com.flyfish.framework.bean.SyncVo; import com.flyfish.framework.bean.SyncVo;
import com.flyfish.framework.configuration.annotations.PagedQuery; import com.flyfish.framework.configuration.annotations.PagedQuery;
import com.flyfish.framework.configuration.annotations.ValidRequestBody; import com.flyfish.framework.configuration.annotations.ValidRequestBody;
import com.flyfish.framework.controller.SafeController;
import com.flyfish.framework.domain.base.Domain; import com.flyfish.framework.domain.base.Domain;
import com.flyfish.framework.domain.base.Qo; import com.flyfish.framework.domain.base.Qo;
import com.flyfish.framework.service.BaseReactiveService; import com.flyfish.framework.service.BaseReactiveService;

View File

@ -1,4 +1,4 @@
package com.flyfish.framework.controller; package com.flyfish.framework.controller.reactive;
import com.flyfish.framework.bean.Result; import com.flyfish.framework.bean.Result;
import com.flyfish.framework.domain.base.Qo; import com.flyfish.framework.domain.base.Qo;