feat:额外返回审核标记

This commit is contained in:
wangyu 2021-12-10 23:26:21 +08:00
parent 58395fad39
commit b08fab9c4a
6 changed files with 64 additions and 8 deletions

View File

@ -71,7 +71,8 @@ public class ApprovalController {
*/ */
@PostMapping("submit") @PostMapping("submit")
public Mono<Result<ApprovalDomain>> submit(@Valid @RequestBody ApprovalSubmitDto body) { public Mono<Result<ApprovalDomain>> submit(@Valid @RequestBody ApprovalSubmitDto body) {
return moduleDelegateService.submit(body).map(Result::ok); return moduleDelegateService.submit(body).map(Result::ok)
.onErrorResume(e -> Mono.just(Result.error(e.getMessage())));
} }

View File

@ -4,7 +4,8 @@ import com.flyfish.framework.annotations.EnumValue;
import com.flyfish.framework.annotations.Order; import com.flyfish.framework.annotations.Order;
import com.flyfish.framework.annotations.Property; import com.flyfish.framework.annotations.Property;
import com.flyfish.framework.approval.enums.ApproveStatus; import com.flyfish.framework.approval.enums.ApproveStatus;
import com.flyfish.framework.domain.authorized.AuthorizedDomain; import com.flyfish.framework.builder.CriteriaBuilder;
import com.flyfish.framework.domain.authorized.AuthorizedQo;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
@ -15,10 +16,15 @@ import lombok.Setter;
*/ */
@Getter @Getter
@Setter @Setter
public class ApprovalDomainQo extends AuthorizedDomain { public class ApprovalDomainQo<T extends ApprovalDomain> extends AuthorizedQo<T> {
@Property("审批状态") @Property("审批状态")
@Order(50) @Order(50)
@EnumValue(ApproveStatus.class) @EnumValue(ApproveStatus.class)
private String status; private String status;
@Override
public CriteriaBuilder<T> criteriaBuilder() {
return super.criteriaBuilder().with("status", "approveStatus");
}
} }

View File

@ -0,0 +1,35 @@
package com.flyfish.framework.approval.domain;
import com.flyfish.framework.approval.enums.ApproveStatus;
import com.flyfish.framework.domain.base.Vo;
import lombok.Data;
import java.util.Optional;
/**
* 包装的审批实体
*
* @author wangyu
*/
@Data
public abstract class ApprovalDomainVo<T extends ApprovalDomain> implements Vo<T> {
// 审批状态
private String approveStatusName;
// 审批状态编码
private String approveStatus;
// 下一审批人
private String nextApprover;
@Override
public Vo<T> from(T po) {
this.setApproveStatusName(Optional.ofNullable(po.getApproveStatus()).map(ApproveStatus::getName)
.orElse(ApproveStatus.DRAFT.getName()));
this.setApproveStatus(Optional.ofNullable(po.getApproveStatus()).map(ApproveStatus::name)
.orElse(ApproveStatus.DRAFT.name()));
if (po.getNext() != -1) {
this.setNextApprover(po.getApprovers().get(po.getNext()));
}
return this;
}
}

View File

@ -10,14 +10,17 @@ import com.flyfish.framework.beans.meta.RestBean;
import com.flyfish.framework.domain.base.DomainService; import com.flyfish.framework.domain.base.DomainService;
import com.flyfish.framework.exception.biz.InvalidBusinessException; import com.flyfish.framework.exception.biz.InvalidBusinessException;
import com.flyfish.framework.service.BaseReactiveService; import com.flyfish.framework.service.BaseReactiveService;
import com.flyfish.framework.utils.ReflectionUtils;
import org.apache.commons.lang3.ClassUtils;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.annotation.AnnotationUtils; import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.data.util.CastUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import reactor.core.publisher.Mono; import reactor.core.publisher.Mono;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Optional; import java.util.Optional;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -37,9 +40,14 @@ public class ModuleDelegateService {
// 审批的服务们 // 审批的服务们
private Map<String, BaseReactiveService<ApprovalDomain>> approvalServices; private Map<String, BaseReactiveService<ApprovalDomain>> approvalServices;
@Autowired(required = false) @Autowired
public void setApprovalServices(List<BaseReactiveService<ApprovalDomain>> services) { @SuppressWarnings("all")
public void setApprovalServices(ObjectProvider<BaseReactiveService> services) {
this.approvalServices = services.stream() this.approvalServices = services.stream()
.filter(service -> ReflectionUtils.getGenericType(service.getClass())
.map(clazz -> ClassUtils.isAssignable(clazz, ApprovalDomain.class))
.orElse(false))
.map(service -> (BaseReactiveService<ApprovalDomain>) service)
.collect(Collectors.toMap(DomainService::getCollectionName, s -> s)); .collect(Collectors.toMap(DomainService::getCollectionName, s -> s));
} }
@ -50,7 +58,7 @@ public class ModuleDelegateService {
* @return 结果 * @return 结果
*/ */
public BaseReactiveService<ApprovalDomain> getService(String module) { public BaseReactiveService<ApprovalDomain> getService(String module) {
return approvalServices.get(module); return CastUtils.cast(approvalServices.get(module));
} }
/** /**
@ -150,6 +158,9 @@ public class ModuleDelegateService {
BaseReactiveService<ApprovalDomain> service = getService(data.getModule()); BaseReactiveService<ApprovalDomain> service = getService(data.getModule());
return service.getById(data.getId()) return service.getById(data.getId())
.flatMap(domain -> { .flatMap(domain -> {
if (ApproveStatus.DRAFT != domain.getApproveStatus() && ApproveStatus.REJECTED != domain.getApproveStatus()) {
return Mono.error(new InvalidBusinessException("该数据已经提交审批,请勿重复提交!"));
}
domain.setApprovers(data.getApprovers()); domain.setApprovers(data.getApprovers());
domain.setApproveStatus(ApproveStatus.PENDING); domain.setApproveStatus(ApproveStatus.PENDING);
domain.setNext(0); domain.setNext(0);

View File

@ -74,7 +74,7 @@ public class BeanController {
BeanInfo info = new BeanInfo(); BeanInfo info = new BeanInfo();
if (clazz.isAnnotationPresent(RestBean.class)) { if (clazz.isAnnotationPresent(RestBean.class)) {
RestBean annotation = clazz.getAnnotation(RestBean.class); RestBean annotation = clazz.getAnnotation(RestBean.class);
info.setType(clazz.getSuperclass().getSimpleName()); info.setSuperType(clazz.getSuperclass().getSimpleName());
info.setName(annotation.name()); info.setName(annotation.name());
info.setCode(annotation.value()); info.setCode(annotation.value());
info.setSearch(BeanProperty.from(annotation.queryClass())); info.setSearch(BeanProperty.from(annotation.queryClass()));

View File

@ -23,6 +23,9 @@ public class BeanInfo {
// bean的类型 // bean的类型
private String type; private String type;
// 父类
private String superType;
// 默认layout // 默认layout
private String layout; private String layout;