From 6dccb0ecad0af8536ce9d0e53a3063227fae1d6d Mon Sep 17 00:00:00 2001 From: lanyuanxiaoyao Date: Wed, 25 Dec 2024 18:38:00 +0800 Subject: [PATCH] =?UTF-8?q?feat(web):=20=E9=87=8D=E6=9E=84=E5=B7=A5?= =?UTF-8?q?=E5=8D=95=E6=B5=81=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gringotts-web/pom.xml | 5 + .../base/controller/CheckingController.java | 34 ----- .../base/entity/CheckingNeededEntity.java | 2 +- .../domain/base/service/CheckingService.java | 2 +- .../controller/AuthenticationController.java | 4 +- .../controller/CheckOrderController.java | 29 ++-- .../controller/ConfirmationController.java | 4 +- .../web/domain/controller/WareController.java | 4 +- .../domain/entity/{ => order}/CheckOrder.java | 67 +++------- .../entity/order/node/CheckOrderNode.java | 49 +++++++ .../entity/order/node/RoleCheckOrderNode.java | 38 ++++++ .../entity/order/node/UserCheckOrderNode.java | 41 ++++++ .../flowable/FlowDatabaseRepository.java | 126 ++++++++++++++++++ .../flowable/node/RoleCheckFlowNode.java | 19 +++ .../flowable/node/UserCheckFlowNode.java | 19 +++ .../repository/CheckOrderNodeRepository.java | 13 ++ .../repository/CheckOrderRepository.java | 2 +- .../domain/service/AuthenticationService.java | 118 +--------------- .../web/domain/service/CheckOrderService.java | 75 +++-------- .../domain/service/ConfirmationService.java | 113 +--------------- .../web/domain/service/WareService.java | 77 +---------- .../gringotts/web/helper/EntityHelper.java | 2 +- 22 files changed, 381 insertions(+), 462 deletions(-) delete mode 100644 gringotts-web/src/main/java/com/eshore/gringotts/web/domain/base/controller/CheckingController.java rename gringotts-web/src/main/java/com/eshore/gringotts/web/domain/entity/{ => order}/CheckOrder.java (60%) create mode 100644 gringotts-web/src/main/java/com/eshore/gringotts/web/domain/entity/order/node/CheckOrderNode.java create mode 100644 gringotts-web/src/main/java/com/eshore/gringotts/web/domain/entity/order/node/RoleCheckOrderNode.java create mode 100644 gringotts-web/src/main/java/com/eshore/gringotts/web/domain/entity/order/node/UserCheckOrderNode.java create mode 100644 gringotts-web/src/main/java/com/eshore/gringotts/web/domain/flowable/FlowDatabaseRepository.java create mode 100644 gringotts-web/src/main/java/com/eshore/gringotts/web/domain/flowable/node/RoleCheckFlowNode.java create mode 100644 gringotts-web/src/main/java/com/eshore/gringotts/web/domain/flowable/node/UserCheckFlowNode.java create mode 100644 gringotts-web/src/main/java/com/eshore/gringotts/web/domain/repository/CheckOrderNodeRepository.java diff --git a/gringotts-web/pom.xml b/gringotts-web/pom.xml index 5fad3e2..336c82a 100644 --- a/gringotts-web/pom.xml +++ b/gringotts-web/pom.xml @@ -12,6 +12,11 @@ gringotts-web + + com.lanyuanxiaoyao + flowable + 1.0-SNAPSHOT + com.eshore gringotts-configuration diff --git a/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/base/controller/CheckingController.java b/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/base/controller/CheckingController.java deleted file mode 100644 index fe4c78c..0000000 --- a/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/base/controller/CheckingController.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.eshore.gringotts.web.domain.base.controller; - -import com.eshore.gringotts.web.configuration.amis.AmisResponse; -import com.eshore.gringotts.web.domain.base.entity.CheckingNeededEntity; -import com.eshore.gringotts.web.domain.base.service.CheckingService; -import lombok.extern.slf4j.Slf4j; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; - -/** - * @author wn - * @version 20241224 - */ -@Slf4j -public abstract class CheckingController extends SimpleControllerSupport { - private final CheckingService checkingService; - - public CheckingController(CheckingService service) { - super(service); - this.checkingService = service; - } - - @GetMapping("/submit/{id}") - public AmisResponse submit(@PathVariable Long id) throws Exception { - checkingService.submit(id); - return AmisResponse.responseSuccess(); - } - - @GetMapping("/retract/{id}") - public AmisResponse retract(@PathVariable Long id) throws Exception { - checkingService.retract(id); - return AmisResponse.responseSuccess(); - } -} diff --git a/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/base/entity/CheckingNeededEntity.java b/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/base/entity/CheckingNeededEntity.java index f978ad5..ab77a97 100644 --- a/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/base/entity/CheckingNeededEntity.java +++ b/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/base/entity/CheckingNeededEntity.java @@ -1,6 +1,6 @@ package com.eshore.gringotts.web.domain.base.entity; -import com.eshore.gringotts.web.domain.entity.CheckOrder; +import com.eshore.gringotts.web.domain.entity.order.CheckOrder; import javax.persistence.CascadeType; import javax.persistence.Column; import javax.persistence.EntityListeners; diff --git a/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/base/service/CheckingService.java b/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/base/service/CheckingService.java index 14c22f8..b46ed72 100644 --- a/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/base/service/CheckingService.java +++ b/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/base/service/CheckingService.java @@ -2,7 +2,7 @@ package com.eshore.gringotts.web.domain.base.service; import com.eshore.gringotts.web.domain.base.entity.LogicDeleteEntity; import com.eshore.gringotts.web.domain.base.repository.SimpleRepository; -import com.eshore.gringotts.web.domain.entity.CheckOrder; +import com.eshore.gringotts.web.domain.entity.order.CheckOrder; import com.eshore.gringotts.web.domain.service.UserService; import javax.persistence.EntityManager; import org.eclipse.collections.api.map.ImmutableMap; diff --git a/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/controller/AuthenticationController.java b/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/controller/AuthenticationController.java index 3a4cc3f..f22a581 100644 --- a/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/controller/AuthenticationController.java +++ b/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/controller/AuthenticationController.java @@ -1,6 +1,6 @@ package com.eshore.gringotts.web.domain.controller; -import com.eshore.gringotts.web.domain.base.controller.CheckingController; +import com.eshore.gringotts.web.domain.base.controller.SimpleControllerSupport; import com.eshore.gringotts.web.domain.base.entity.FileInfo; import com.eshore.gringotts.web.domain.base.entity.SimpleListItem; import com.eshore.gringotts.web.domain.base.entity.SimpleSaveItem; @@ -25,7 +25,7 @@ import org.springframework.web.bind.annotation.RestController; @Slf4j @RestController @RequestMapping("authentication") -public class AuthenticationController extends CheckingController { +public class AuthenticationController extends SimpleControllerSupport { private final DataResourceService dataResourceService; private final DataFileService dataFileService; diff --git a/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/controller/CheckOrderController.java b/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/controller/CheckOrderController.java index 24dab6f..8cc6583 100644 --- a/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/controller/CheckOrderController.java +++ b/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/controller/CheckOrderController.java @@ -3,9 +3,9 @@ package com.eshore.gringotts.web.domain.controller; import com.eshore.gringotts.web.configuration.amis.AmisResponse; import com.eshore.gringotts.web.domain.base.controller.ListController; import com.eshore.gringotts.web.domain.base.controller.query.Query; -import com.eshore.gringotts.web.domain.entity.CheckOrder; +import com.eshore.gringotts.web.domain.entity.order.CheckOrder; +import com.eshore.gringotts.web.domain.entity.order.node.CheckOrderNode; import com.eshore.gringotts.web.domain.service.CheckOrderService; -import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; import java.time.LocalDateTime; @@ -52,13 +52,25 @@ public class CheckOrderController implements ListController approve(@PathVariable Long id) { + checkOrderService.approve(id); + return AmisResponse.responseSuccess(); + } + + @GetMapping("/reject/{id}") + public AmisResponse reject(@PathVariable Long id) { + checkOrderService.reject(id); + return AmisResponse.responseSuccess(); + } + @SneakyThrows private ListItem toListItem(CheckOrder order) { ListItem item = new ListItem(); item.setCheckOrderId(order.getId()); item.setDescription(order.getDescription()); - item.setType(order.getType()); - item.setParameters(mapper.readValue(order.getParameters(), new TypeReference<>() {})); + item.setCurrentNode(order.getCurrentNode()); + item.setParameters(mapper.readValue(order.getContext(), new TypeReference<>() {})); item.setState(order.getState()); item.setCreatedUsername(order.getCreatedUser().getUsername()); item.setCreatedTime(order.getCreatedTime()); @@ -67,18 +79,11 @@ public class CheckOrderController implements ListController operation(@PathVariable Long id, @PathVariable CheckOrder.Operation operation) throws JsonProcessingException { - log.info("id:{}, operation:{}", id, operation); - checkOrderService.operation(id, operation); - return AmisResponse.responseSuccess(); - } - @Data public static final class ListItem { private Long checkOrderId; private String description; - private CheckOrder.Type type; + private CheckOrderNode currentNode; private ImmutableMap parameters; private CheckOrder.State state; private LocalDateTime createdTime; diff --git a/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/controller/ConfirmationController.java b/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/controller/ConfirmationController.java index c8a262a..99798b1 100644 --- a/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/controller/ConfirmationController.java +++ b/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/controller/ConfirmationController.java @@ -1,6 +1,6 @@ package com.eshore.gringotts.web.domain.controller; -import com.eshore.gringotts.web.domain.base.controller.CheckingController; +import com.eshore.gringotts.web.domain.base.controller.SimpleControllerSupport; import com.eshore.gringotts.web.domain.base.entity.FileInfo; import com.eshore.gringotts.web.domain.base.entity.SimpleListItem; import com.eshore.gringotts.web.domain.base.entity.SimpleSaveItem; @@ -24,7 +24,7 @@ import org.springframework.web.bind.annotation.RestController; @Slf4j @RestController @RequestMapping("confirmation") -public class ConfirmationController extends CheckingController { +public class ConfirmationController extends SimpleControllerSupport { private final DataResourceService dataResourceService; private final DataFileService dataFileService; diff --git a/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/controller/WareController.java b/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/controller/WareController.java index 100657f..26e2b5f 100644 --- a/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/controller/WareController.java +++ b/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/controller/WareController.java @@ -3,7 +3,7 @@ package com.eshore.gringotts.web.domain.controller; import cn.hutool.core.util.StrUtil; import com.eshore.gringotts.web.configuration.HostConfiguration; import com.eshore.gringotts.web.configuration.amis.AmisResponse; -import com.eshore.gringotts.web.domain.base.controller.CheckingController; +import com.eshore.gringotts.web.domain.base.controller.SimpleControllerSupport; import com.eshore.gringotts.web.domain.base.entity.SimpleListItem; import com.eshore.gringotts.web.domain.base.entity.SimpleSaveItem; import com.eshore.gringotts.web.domain.entity.Ware; @@ -26,7 +26,7 @@ import org.springframework.web.bind.annotation.RestController; @Slf4j @RestController @RequestMapping("ware") -public class WareController extends CheckingController { +public class WareController extends SimpleControllerSupport { private final HostConfiguration hostConfiguration; private final WareService wareService; private final DataResourceService dataResourceService; diff --git a/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/entity/CheckOrder.java b/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/entity/order/CheckOrder.java similarity index 60% rename from gringotts-web/src/main/java/com/eshore/gringotts/web/domain/entity/CheckOrder.java rename to gringotts-web/src/main/java/com/eshore/gringotts/web/domain/entity/order/CheckOrder.java index 77e9ffb..094de74 100644 --- a/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/entity/CheckOrder.java +++ b/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/entity/order/CheckOrder.java @@ -1,7 +1,9 @@ -package com.eshore.gringotts.web.domain.entity; +package com.eshore.gringotts.web.domain.entity.order; import com.eshore.gringotts.core.Constants; import com.eshore.gringotts.web.domain.base.entity.SimpleEntity; +import com.eshore.gringotts.web.domain.entity.order.node.CheckOrderNode; +import java.util.List; import javax.persistence.Column; import javax.persistence.ConstraintMode; import javax.persistence.Entity; @@ -13,6 +15,7 @@ import javax.persistence.ForeignKey; import javax.persistence.JoinColumn; import javax.persistence.NamedAttributeNode; import javax.persistence.NamedEntityGraph; +import javax.persistence.OneToMany; import javax.persistence.OneToOne; import javax.persistence.Table; import lombok.Getter; @@ -38,74 +41,34 @@ import org.springframework.data.jpa.domain.support.AuditingEntityListener; @NamedAttributeNode(value = "modifiedUser"), }) @NamedEntityGraph(name = "check_order.detail", attributeNodes = { + @NamedAttributeNode(value = "nodes"), @NamedAttributeNode(value = "createdUser"), @NamedAttributeNode(value = "modifiedUser"), }) @NoArgsConstructor public class CheckOrder extends SimpleEntity { @Column(nullable = false) - private String keyword; + private String name; @Column(nullable = false) private String description; - @Column(nullable = false) - @Enumerated(EnumType.STRING) - private Type type; + + @OneToOne(fetch = FetchType.LAZY) + @JoinColumn(nullable = false, foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT)) + @ToString.Exclude + private CheckOrderNode currentNode; + @OneToMany(fetch = FetchType.LAZY, mappedBy = "order") + @ToString.Exclude + private List nodes; /** * JSON 结构 Map */ @Column(nullable = false) - private String parameters; - - @Column(nullable = false) - @Enumerated(EnumType.STRING) - private Target target; - @Column(nullable = false) - private String targetClass; - @OneToOne(fetch = FetchType.LAZY) - @JoinColumn(foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT)) - @ToString.Exclude - private User targetUser; - @Enumerated(EnumType.STRING) - private User.Role targetRole; + private String context; @Column(nullable = false) @Enumerated(EnumType.STRING) private State state = State.CHECKING; - public CheckOrder( - String keyword, - String description, - Type type, - String parameters, - String targetClass, - User targetUser - ) { - this.keyword = keyword; - this.description = description; - this.type = type; - this.parameters = parameters; - this.target = Target.USER; - this.targetClass = targetClass; - this.targetUser = targetUser; - } - - public CheckOrder( - String keyword, - String description, - Type type, - String parameters, - String targetClass, - User.Role targetRole - ) { - this.keyword = keyword; - this.description = description; - this.type = type; - this.parameters = parameters; - this.target = Target.ROLE; - this.targetClass = targetClass; - this.targetRole = targetRole; - } - public enum Operation { APPLY, REJECT, diff --git a/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/entity/order/node/CheckOrderNode.java b/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/entity/order/node/CheckOrderNode.java new file mode 100644 index 0000000..5efc651 --- /dev/null +++ b/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/entity/order/node/CheckOrderNode.java @@ -0,0 +1,49 @@ +package com.eshore.gringotts.web.domain.entity.order.node; + +import com.eshore.gringotts.core.Constants; +import com.eshore.gringotts.web.domain.base.entity.IdOnlyEntity; +import com.eshore.gringotts.web.domain.entity.order.CheckOrder; +import javax.persistence.Column; +import javax.persistence.ConstraintMode; +import javax.persistence.Entity; +import javax.persistence.EntityListeners; +import javax.persistence.FetchType; +import javax.persistence.ForeignKey; +import javax.persistence.Inheritance; +import javax.persistence.InheritanceType; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.Table; +import lombok.Getter; +import lombok.Setter; +import lombok.ToString; +import org.hibernate.annotations.DynamicUpdate; +import org.springframework.data.jpa.domain.support.AuditingEntityListener; + +/** + * @author lanyuanxiaoyao + * @version 20241225 + */ +@Getter +@Setter +@ToString +@Entity +@DynamicUpdate +@EntityListeners(AuditingEntityListener.class) +@Table(name = Constants.TABLE_PREFIX + "check_order_node") +@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS) +public abstract class CheckOrderNode extends IdOnlyEntity { + @Column(nullable = false) + private Integer sequence; + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(nullable = false, foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT)) + @ToString.Exclude + private CheckOrder order; + + public abstract Type getCheckType(); + + public enum Type { + USER, + ROLE, + } +} diff --git a/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/entity/order/node/RoleCheckOrderNode.java b/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/entity/order/node/RoleCheckOrderNode.java new file mode 100644 index 0000000..10b7225 --- /dev/null +++ b/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/entity/order/node/RoleCheckOrderNode.java @@ -0,0 +1,38 @@ +package com.eshore.gringotts.web.domain.entity.order.node; + +import com.eshore.gringotts.core.Constants; +import com.eshore.gringotts.web.domain.entity.User; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.EnumType; +import javax.persistence.Enumerated; +import javax.persistence.Table; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; + +/** + * 指定用户审核 + * + * @author lanyuanxiaoyao + * @version 20241225 + */ +@Getter +@Setter +@ToString +@AllArgsConstructor +@NoArgsConstructor +@Entity +@Table(name = Constants.TABLE_PREFIX + "check_order_node_role") +public class RoleCheckOrderNode extends CheckOrderNode { + @Column(nullable = false) + @Enumerated(EnumType.STRING) + private User.Role target; + + @Override + public Type getCheckType() { + return Type.ROLE; + } +} diff --git a/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/entity/order/node/UserCheckOrderNode.java b/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/entity/order/node/UserCheckOrderNode.java new file mode 100644 index 0000000..946c5c9 --- /dev/null +++ b/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/entity/order/node/UserCheckOrderNode.java @@ -0,0 +1,41 @@ +package com.eshore.gringotts.web.domain.entity.order.node; + +import com.eshore.gringotts.core.Constants; +import com.eshore.gringotts.web.domain.entity.User; +import javax.persistence.ConstraintMode; +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.ForeignKey; +import javax.persistence.JoinColumn; +import javax.persistence.OneToOne; +import javax.persistence.Table; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; + +/** + * 指定用户审核 + * + * @author lanyuanxiaoyao + * @version 20241225 + */ +@Getter +@Setter +@ToString +@AllArgsConstructor +@NoArgsConstructor +@Entity +@Table(name = Constants.TABLE_PREFIX + "check_order_node_user") +public class UserCheckOrderNode extends CheckOrderNode { + @OneToOne(fetch = FetchType.EAGER) + @JoinColumn(nullable = false, foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT)) + @ToString.Exclude + private User target; + + @Override + public Type getCheckType() { + return Type.USER; + } +} diff --git a/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/flowable/FlowDatabaseRepository.java b/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/flowable/FlowDatabaseRepository.java new file mode 100644 index 0000000..15f4f96 --- /dev/null +++ b/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/flowable/FlowDatabaseRepository.java @@ -0,0 +1,126 @@ +package com.eshore.gringotts.web.domain.flowable; + +import com.eshore.gringotts.web.domain.entity.order.CheckOrder; +import com.eshore.gringotts.web.domain.entity.order.node.CheckOrderNode; +import com.eshore.gringotts.web.domain.entity.order.node.RoleCheckOrderNode; +import com.eshore.gringotts.web.domain.entity.order.node.UserCheckOrderNode; +import com.eshore.gringotts.web.domain.flowable.node.RoleCheckFlowNode; +import com.eshore.gringotts.web.domain.flowable.node.UserCheckFlowNode; +import com.eshore.gringotts.web.domain.repository.CheckOrderNodeRepository; +import com.eshore.gringotts.web.domain.service.CheckOrderService; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.lanyuanxiaoyao.flowable.model.Flow; +import com.lanyuanxiaoyao.flowable.model.FlowStatus; +import com.lanyuanxiaoyao.flowable.node.FlowNode; +import com.lanyuanxiaoyao.flowable.repository.FlowRepository; +import java.util.stream.Collectors; +import lombok.SneakyThrows; +import org.eclipse.collections.api.factory.Lists; +import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder; +import org.springframework.stereotype.Service; + +/** + * @author lanyuanxiaoyao + * @version 20241225 + */ +@Service +public class FlowDatabaseRepository implements FlowRepository { + private final CheckOrderService checkOrderService; + private final CheckOrderNodeRepository checkOrderNodeRepository; + private final ObjectMapper mapper; + + public FlowDatabaseRepository(CheckOrderService checkOrderService, CheckOrderNodeRepository checkOrderNodeRepository, Jackson2ObjectMapperBuilder builder) { + this.checkOrderService = checkOrderService; + this.checkOrderNodeRepository = checkOrderNodeRepository; + this.mapper = builder.build(); + } + + private FlowNode mapTo(CheckOrderNode source) { + switch (source.getCheckType()) { + case USER: + return new UserCheckFlowNode(source.getId().toString(), ((UserCheckOrderNode) source).getTarget()); + case ROLE: + return new RoleCheckFlowNode(source.getId().toString(), ((RoleCheckOrderNode) source).getTarget()); + default: + throw new IllegalArgumentException("Unsupported check type: " + source.getCheckType()); + } + } + + private CheckOrderNode mapTo(FlowNode source) { + return checkOrderNodeRepository.findById(Long.valueOf(source.getNodeId())).orElseThrow(() -> new RuntimeException("")); + } + + private void mapTo(CheckOrder order, Flow flow) throws JsonProcessingException { + flow.setName(order.getName()); + flow.setDescription(order.getDescription()); + flow.setNodes(order.getNodes() + .stream() + .map(this::mapTo) + .collect(Collectors.toList()) + ); + flow.setCurrentNode(mapTo(order.getCurrentNode()).getNodeId()); + switch (order.getState()) { + case CHECKING: + flow.setStatus(FlowStatus.PENDING); + break; + case RETRACT: + flow.setStatus(FlowStatus.REJECTED); + break; + case OVER: + flow.setStatus(FlowStatus.APPROVED); + break; + } + flow.setContextVariables(mapper.readValue(order.getContext(), new TypeReference<>() {})); + flow.setCreateTime(order.getCreatedTime()); + flow.setUpdateTime(order.getModifiedTime()); + } + + private void mapTo(Flow flow, CheckOrder order) throws JsonProcessingException { + order.setName(flow.getName()); + order.setDescription(flow.getDescription()); + order.setNodes(Lists.mutable.ofAll(flow.getNodes()).collect(this::mapTo)); + order.setCurrentNode(mapTo(flow.getCurrentNodeObject())); + switch (flow.getStatus()) { + case APPROVED: + order.setState(CheckOrder.State.OVER); + break; + case PENDING: + order.setState(CheckOrder.State.CHECKING); + break; + case REJECTED: + order.setState(CheckOrder.State.RETRACT); + break; + } + order.setContext(mapper.writeValueAsString(flow.getContextVariables())); + } + + @SneakyThrows + @Override + public Flow save(Flow flow) { + CheckOrder order = new CheckOrder(); + mapTo(flow, order); + Long id = checkOrderService.save(order); + flow.setId(id.toString()); + return flow; + } + + @SneakyThrows + @Override + public Flow update(Flow flow) { + CheckOrder order = checkOrderService.detailOrThrow(Long.parseLong(flow.getId())); + mapTo(flow, order); + checkOrderService.save(order); + return flow; + } + + @SneakyThrows + @Override + public Flow findById(String id) { + CheckOrder order = checkOrderService.detailOrThrow(Long.parseLong(id)); + Flow flow = new Flow(); + mapTo(order, flow); + return flow; + } +} diff --git a/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/flowable/node/RoleCheckFlowNode.java b/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/flowable/node/RoleCheckFlowNode.java new file mode 100644 index 0000000..bc7d25d --- /dev/null +++ b/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/flowable/node/RoleCheckFlowNode.java @@ -0,0 +1,19 @@ +package com.eshore.gringotts.web.domain.flowable.node; + +import com.eshore.gringotts.web.domain.entity.User; +import com.lanyuanxiaoyao.flowable.node.AbstractFlowNode; +import lombok.Getter; + +/** + * @author lanyuanxiaoyao + * @version 20241225 + */ +@Getter +public class RoleCheckFlowNode extends AbstractFlowNode { + private final User.Role role; + + public RoleCheckFlowNode(String nodeId, User.Role role) { + super(nodeId); + this.role = role; + } +} diff --git a/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/flowable/node/UserCheckFlowNode.java b/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/flowable/node/UserCheckFlowNode.java new file mode 100644 index 0000000..79cfd9b --- /dev/null +++ b/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/flowable/node/UserCheckFlowNode.java @@ -0,0 +1,19 @@ +package com.eshore.gringotts.web.domain.flowable.node; + +import com.eshore.gringotts.web.domain.entity.User; +import com.lanyuanxiaoyao.flowable.node.AbstractFlowNode; +import lombok.Getter; + +/** + * @author lanyuanxiaoyao + * @version 20241225 + */ +@Getter +public class UserCheckFlowNode extends AbstractFlowNode { + private final User user; + + public UserCheckFlowNode(String nodeId, User user) { + super(nodeId); + this.user = user; + } +} diff --git a/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/repository/CheckOrderNodeRepository.java b/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/repository/CheckOrderNodeRepository.java new file mode 100644 index 0000000..070ba8b --- /dev/null +++ b/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/repository/CheckOrderNodeRepository.java @@ -0,0 +1,13 @@ +package com.eshore.gringotts.web.domain.repository; + +import com.eshore.gringotts.web.domain.base.repository.SimpleRepository; +import com.eshore.gringotts.web.domain.entity.order.node.CheckOrderNode; +import org.springframework.stereotype.Repository; + +/** + * @author lanyuanxiaoyao + * @version 20241225 + */ +@Repository +public interface CheckOrderNodeRepository extends SimpleRepository { +} diff --git a/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/repository/CheckOrderRepository.java b/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/repository/CheckOrderRepository.java index e95fd31..753d711 100644 --- a/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/repository/CheckOrderRepository.java +++ b/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/repository/CheckOrderRepository.java @@ -1,8 +1,8 @@ package com.eshore.gringotts.web.domain.repository; import com.eshore.gringotts.web.domain.base.repository.SimpleRepository; -import com.eshore.gringotts.web.domain.entity.CheckOrder; import com.eshore.gringotts.web.domain.entity.User; +import com.eshore.gringotts.web.domain.entity.order.CheckOrder; import java.util.List; import java.util.Optional; import javax.transaction.Transactional; diff --git a/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/service/AuthenticationService.java b/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/service/AuthenticationService.java index 3facfc2..9653d1f 100644 --- a/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/service/AuthenticationService.java +++ b/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/service/AuthenticationService.java @@ -1,29 +1,11 @@ package com.eshore.gringotts.web.domain.service; import cn.hutool.core.util.ObjectUtil; -import cn.hutool.core.util.StrUtil; -import com.eshore.gringotts.web.domain.base.entity.CheckingNeededEntity; -import com.eshore.gringotts.web.domain.base.service.CheckingService; +import com.eshore.gringotts.web.domain.base.service.LogicDeleteService; import com.eshore.gringotts.web.domain.entity.Authentication; -import com.eshore.gringotts.web.domain.entity.Authentication_; -import com.eshore.gringotts.web.domain.entity.CheckOrder; -import com.eshore.gringotts.web.domain.entity.CheckOrder_; -import com.eshore.gringotts.web.domain.entity.User; import com.eshore.gringotts.web.domain.repository.AuthenticationRepository; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectMapper; import javax.persistence.EntityManager; -import javax.persistence.criteria.CriteriaBuilder; -import javax.persistence.criteria.CriteriaQuery; -import javax.persistence.criteria.Predicate; -import javax.persistence.criteria.Root; -import javax.transaction.Transactional; import lombok.extern.slf4j.Slf4j; -import org.eclipse.collections.api.factory.Lists; -import org.eclipse.collections.api.factory.Maps; -import org.eclipse.collections.api.list.ImmutableList; -import org.eclipse.collections.api.map.ImmutableMap; -import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder; import org.springframework.stereotype.Service; /** @@ -31,38 +13,15 @@ import org.springframework.stereotype.Service; * @date 2024-12-02 */ @Slf4j -@Service("com.eshore.gringotts.web.domain.service.AuthenticationService") -public class AuthenticationService extends CheckingService { +@Service +public class AuthenticationService extends LogicDeleteService { private final AuthenticationRepository authenticationRepository; private final UserService userService; - private final CheckOrderService checkOrderService; - private final ObjectMapper mapper; - public AuthenticationService(AuthenticationRepository repository, UserService userService, EntityManager manager, CheckOrderService checkOrderService, Jackson2ObjectMapperBuilder builder) { + public AuthenticationService(AuthenticationRepository repository, UserService userService, EntityManager manager) { super(repository, userService, manager); this.authenticationRepository = repository; this.userService = userService; - this.checkOrderService = checkOrderService; - this.mapper = builder.build(); - } - - @Override - protected ImmutableList listPredicate(Root root, CriteriaQuery query, CriteriaBuilder builder) { - User loginUser = userService.currentLoginUser(); - if (User.isAdministrator(loginUser)) { - return Lists.immutable.empty(); - } - return Lists.immutable.of(builder.or( - builder.equal(root.get(Authentication_.createdUser), loginUser), - builder.and( - builder.equal(root.get(Authentication_.order).get(CheckOrder_.target), CheckOrder.Target.ROLE), - builder.equal(root.get(Authentication_.order).get(CheckOrder_.targetRole), loginUser.getRole()) - ), - builder.and( - builder.equal(root.get(Authentication_.order).get(CheckOrder_.target), CheckOrder.Target.USER), - builder.equal(root.get(Authentication_.order).get(CheckOrder_.targetUser), loginUser) - ) - )); } @Override @@ -82,75 +41,6 @@ public class AuthenticationService extends CheckingService { return super.save(entity); } - @Transactional(rollbackOn = Throwable.class) - @Override - public void submit(Long id) throws JsonProcessingException { - Authentication authentication = detailOrThrow(id); - authentication.setState(CheckingNeededEntity.State.OWNER_CHECKING); - Long orderId = checkOrderService.save(new CheckOrder( - "authentication_owner_check", - StrUtil.format("数据资源「{}」的授权申请", authentication.getTarget().getName()), - CheckOrder.Type.AUTHENTICATION, - mapper.writeValueAsString(Maps.immutable.of("authenticationId", authentication.getId())), - "com.eshore.gringotts.web.domain.service.AuthenticationService", - authentication.getCreatedUser() - )); - CheckOrder order = checkOrderService.detailOrThrow(orderId); - authentication.setOrder(order); - save(authentication); - } - - @Transactional(rollbackOn = Throwable.class) - @Override - public void retract(Long id) { - Authentication authentication = detailOrThrow(id); - authentication.setState(Authentication.State.DRAFT); - save(authentication); - - CheckOrder order = authentication.getOrder(); - order.setState(CheckOrder.State.RETRACT); - checkOrderService.save(order); - } - - @Override - @Transactional(rollbackOn = Throwable.class) - public void onChecked(CheckOrder order, CheckOrder.Operation operation, ImmutableMap parameters) { - Long id = (Long) parameters.get("authenticationId"); - Authentication authentication = detailOrThrow(id); - if (StrUtil.equals(order.getKeyword(), "authentication_owner_check")) { - switch (operation) { - case APPLY: - authentication.setState(Authentication.State.CHECKING); - order.setKeyword("authentication_checker_check"); - order.setTarget(CheckOrder.Target.ROLE); - order.setTargetRole(User.Role.CHECKER); - break; - case REJECT: - authentication.setState(Authentication.State.DRAFT); - order.setState(CheckOrder.State.OVER); - break; - } - } else if (StrUtil.equals(order.getKeyword(), "authentication_checker_check")) { - switch (operation) { - case APPLY: - authentication.setState(Authentication.State.NORMAL); - order.setState(CheckOrder.State.OVER); - break; - case REJECT: - authentication.setState(Authentication.State.DRAFT); - order.setState(CheckOrder.State.OVER); - break; - } - } - save(authentication); - checkOrderService.save(order); - } - - @Override - public ImmutableMap archive(Authentication authentication) { - return null; - } - public static final class AuthenticationDuplicatedException extends RuntimeException { public AuthenticationDuplicatedException() { super("数据资源已绑定该账号的授权申请,无法再次申请"); diff --git a/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/service/CheckOrderService.java b/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/service/CheckOrderService.java index 70714df..ca994ef 100644 --- a/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/service/CheckOrderService.java +++ b/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/service/CheckOrderService.java @@ -1,26 +1,12 @@ package com.eshore.gringotts.web.domain.service; -import cn.hutool.core.util.ObjectUtil; -import cn.hutool.core.util.StrUtil; -import com.eshore.gringotts.web.domain.base.service.CheckingService; import com.eshore.gringotts.web.domain.base.service.SimpleServiceSupport; -import com.eshore.gringotts.web.domain.entity.CheckOrder; -import com.eshore.gringotts.web.domain.entity.CheckOrder_; -import com.eshore.gringotts.web.domain.entity.User; +import com.eshore.gringotts.web.domain.entity.order.CheckOrder; +import com.eshore.gringotts.web.domain.flowable.FlowDatabaseRepository; import com.eshore.gringotts.web.domain.repository.CheckOrderRepository; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.core.type.TypeReference; -import com.fasterxml.jackson.databind.ObjectMapper; -import javax.persistence.criteria.CriteriaBuilder; -import javax.persistence.criteria.CriteriaQuery; -import javax.persistence.criteria.Predicate; -import javax.persistence.criteria.Root; +import com.lanyuanxiaoyao.flowable.service.FlowService; +import javax.transaction.Transactional; import lombok.extern.slf4j.Slf4j; -import org.eclipse.collections.api.factory.Lists; -import org.eclipse.collections.api.list.ImmutableList; -import org.eclipse.collections.api.map.ImmutableMap; -import org.springframework.context.ApplicationContext; -import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder; import org.springframework.stereotype.Service; /** @@ -30,53 +16,26 @@ import org.springframework.stereotype.Service; @Slf4j @Service public class CheckOrderService extends SimpleServiceSupport { - private final ApplicationContext applicationContext; - private final ObjectMapper mapper; - private final CheckOrderRepository checkOrderRepository; - private final UserService userService; + private final FlowService flowService; - public CheckOrderService(CheckOrderRepository repository, UserService userService, ApplicationContext applicationContext, Jackson2ObjectMapperBuilder builder) { + public CheckOrderService(CheckOrderRepository repository, UserService userService, FlowDatabaseRepository flowDatabaseRepository) { super(repository, userService); - this.applicationContext = applicationContext; - this.mapper = builder.build(); - this.checkOrderRepository = repository; - this.userService = userService; + this.flowService = new FlowService(flowDatabaseRepository); } - @Override - protected ImmutableList listPredicate(Root root, CriteriaQuery query, CriteriaBuilder builder) { - User user = userService.currentLoginUser(); - if (User.isAdministrator(user)) { - return Lists.immutable.empty(); - } - return Lists.immutable.of(builder.or( - builder.equal(root.get(CheckOrder_.createdUser), user), - builder.and( - builder.equal(root.get(CheckOrder_.target), CheckOrder.Target.USER), - builder.equal(root.get(CheckOrder_.targetUser), user) - ), - builder.and( - builder.equal(root.get(CheckOrder_.target), CheckOrder.Target.ROLE), - builder.equal(root.get(CheckOrder_.targetRole), user.getRole()) - ) - )); + @Transactional(rollbackOn = Throwable.class) + public void startFlow(CheckOrder order) { + Long id = save(order); + flowService.startFlow(id.toString()); } - public void operation(Long id, CheckOrder.Operation operation) throws JsonProcessingException { - CheckOrder order = detailOrThrow(id); - CheckingService service = applicationContext.getBean(order.getTargetClass(), CheckingService.class); - if (ObjectUtil.isNull(service)) { - throw new RuntimeException(StrUtil.format("名为「{}」的服务未找到", order.getTargetClass())); - } - ImmutableMap parameters = mapper.readValue(order.getParameters(), new TypeReference<>() {}); - service.onChecked(order, operation, parameters); + @Transactional(rollbackOn = Throwable.class) + public void approve(Long id) { + flowService.approve(id.toString()); } - public void retract(Long id) { - checkOrderRepository.overById(id, CheckOrder.State.RETRACT, userService.currentLoginUser()); - } - - public void over(Long id) { - checkOrderRepository.overById(id, CheckOrder.State.OVER, userService.currentLoginUser()); + @Transactional(rollbackOn = Throwable.class) + public void reject(Long id) { + flowService.reject(id.toString()); } } diff --git a/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/service/ConfirmationService.java b/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/service/ConfirmationService.java index 34e2a85..1892328 100644 --- a/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/service/ConfirmationService.java +++ b/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/service/ConfirmationService.java @@ -1,31 +1,11 @@ package com.eshore.gringotts.web.domain.service; import cn.hutool.core.util.ObjectUtil; -import cn.hutool.core.util.StrUtil; -import com.eshore.gringotts.web.domain.base.entity.CheckingNeededEntity; -import com.eshore.gringotts.web.domain.base.service.CheckingService; -import com.eshore.gringotts.web.domain.entity.CheckOrder; -import com.eshore.gringotts.web.domain.entity.CheckOrder_; +import com.eshore.gringotts.web.domain.base.service.LogicDeleteService; import com.eshore.gringotts.web.domain.entity.Confirmation; -import com.eshore.gringotts.web.domain.entity.Confirmation_; -import com.eshore.gringotts.web.domain.entity.User; import com.eshore.gringotts.web.domain.repository.ConfirmationRepository; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectMapper; import javax.persistence.EntityManager; -import javax.persistence.criteria.CriteriaBuilder; -import javax.persistence.criteria.CriteriaQuery; -import javax.persistence.criteria.Join; -import javax.persistence.criteria.JoinType; -import javax.persistence.criteria.Predicate; -import javax.persistence.criteria.Root; -import javax.transaction.Transactional; import lombok.extern.slf4j.Slf4j; -import org.eclipse.collections.api.factory.Lists; -import org.eclipse.collections.api.factory.Maps; -import org.eclipse.collections.api.list.ImmutableList; -import org.eclipse.collections.api.map.ImmutableMap; -import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder; import org.springframework.stereotype.Service; /** @@ -33,42 +13,13 @@ import org.springframework.stereotype.Service; * @date 2024-11-26 */ @Slf4j -@Service("com.eshore.gringotts.web.domain.service.ConfirmationService") -public class ConfirmationService extends CheckingService { +@Service +public class ConfirmationService extends LogicDeleteService { private final ConfirmationRepository confirmationRepository; - private final CheckOrderService checkOrderService; - private final ObjectMapper mapper; - public ConfirmationService(ConfirmationRepository confirmationRepository, UserService userService, EntityManager entityManager, CheckOrderService checkOrderService, Jackson2ObjectMapperBuilder builder) { + public ConfirmationService(ConfirmationRepository confirmationRepository, UserService userService, EntityManager entityManager) { super(confirmationRepository, userService, entityManager); this.confirmationRepository = confirmationRepository; - this.checkOrderService = checkOrderService; - this.mapper = builder.build(); - } - - @Override - protected ImmutableList listPredicate(Root root, CriteriaQuery query, CriteriaBuilder builder) { - User loginUser = userService.currentLoginUser(); - if (User.isAdministrator(loginUser)) { - return Lists.immutable.empty(); - } - Join orderJoin = root.join(Confirmation_.order, JoinType.LEFT); - return Lists.immutable.of(builder.or( - builder.equal(root.get(Confirmation_.createdUser), loginUser), - builder.and( - builder.isNotNull(orderJoin), - builder.or( - builder.and( - builder.equal(orderJoin.get(CheckOrder_.target), CheckOrder.Target.ROLE), - builder.equal(orderJoin.get(CheckOrder_.targetRole), loginUser.getRole()) - ), - builder.and( - builder.equal(orderJoin.get(CheckOrder_.target), CheckOrder.Target.USER), - builder.equal(orderJoin.get(CheckOrder_.targetUser), loginUser) - ) - ) - ) - )); } @Override @@ -79,62 +30,6 @@ public class ConfirmationService extends CheckingService { return super.save(entity); } - @Transactional(rollbackOn = Throwable.class) - @Override - public void submit(Long id) throws JsonProcessingException { - Confirmation confirmation = detailOrThrow(id); - confirmation.setState(Confirmation.State.CHECKING); - Long orderId = checkOrderService.save(new CheckOrder( - "confirmation_check", - StrUtil.format("数据资源「{}」的确权申请", confirmation.getTarget().getName()), - CheckOrder.Type.CONFIRMATION, - mapper.writeValueAsString(Maps.immutable.of("confirmationId", confirmation.getId())), - "com.eshore.gringotts.web.domain.service.ConfirmationService", - User.Role.CHECKER - )); - CheckOrder order = checkOrderService.detailOrThrow(orderId); - confirmation.setOrder(order); - save(confirmation); - } - - @Transactional(rollbackOn = Throwable.class) - @Override - public void retract(Long id) { - Confirmation confirmation = detailOrThrow(id); - confirmation.setState(CheckingNeededEntity.State.DRAFT); - save(confirmation); - - CheckOrder order = confirmation.getOrder(); - order.setState(CheckOrder.State.RETRACT); - checkOrderService.save(order); - } - - @Override - @Transactional(rollbackOn = Throwable.class) - public void onChecked(CheckOrder order, CheckOrder.Operation operation, ImmutableMap parameters) { - if (StrUtil.equals(order.getKeyword(), "confirmation_check")) { - Long id = (Long) parameters.get("confirmationId"); - Confirmation confirmation = detailOrThrow(id); - switch (operation) { - case APPLY: - confirmation.setState(Confirmation.State.NORMAL); - order.setState(CheckOrder.State.OVER); - break; - case REJECT: - confirmation.setState(Confirmation.State.DRAFT); - order.setState(CheckOrder.State.OVER); - break; - } - save(confirmation); - checkOrderService.save(order); - } - } - - @Override - public ImmutableMap archive(Confirmation confirmation) { - return null; - } - public static final class ConfirmationDuplicatedException extends RuntimeException { public ConfirmationDuplicatedException() { super("数据资源已绑定确权申请,无法再次申请"); diff --git a/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/service/WareService.java b/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/service/WareService.java index 4305326..370fc09 100644 --- a/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/service/WareService.java +++ b/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/service/WareService.java @@ -1,21 +1,12 @@ package com.eshore.gringotts.web.domain.service; -import cn.hutool.core.util.StrUtil; -import com.eshore.gringotts.web.domain.base.service.CheckingService; -import com.eshore.gringotts.web.domain.entity.CheckOrder; -import com.eshore.gringotts.web.domain.entity.User; +import com.eshore.gringotts.web.domain.base.service.LogicDeleteService; import com.eshore.gringotts.web.domain.entity.Ware; import com.eshore.gringotts.web.domain.repository.WareRepository; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectMapper; import javax.persistence.EntityManager; -import javax.transaction.Transactional; import lombok.extern.slf4j.Slf4j; import org.eclipse.collections.api.factory.Lists; -import org.eclipse.collections.api.factory.Maps; import org.eclipse.collections.api.list.ImmutableList; -import org.eclipse.collections.api.map.ImmutableMap; -import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder; import org.springframework.stereotype.Service; /** @@ -23,17 +14,13 @@ import org.springframework.stereotype.Service; * @date 2024-12-13 */ @Slf4j -@Service("com.eshore.gringotts.web.domain.service.WareService") -public class WareService extends CheckingService { +@Service +public class WareService extends LogicDeleteService { private final WareRepository wareRepository; - private final CheckOrderService checkOrderService; - private final ObjectMapper mapper; - public WareService(WareRepository repository, UserService userService, EntityManager entityManager, CheckOrderService checkOrderService, Jackson2ObjectMapperBuilder builder) { + public WareService(WareRepository repository, UserService userService, EntityManager entityManager) { super(repository, userService, entityManager); this.wareRepository = repository; - this.checkOrderService = checkOrderService; - this.mapper = builder.build(); } public ImmutableList listPublic() { @@ -41,60 +28,4 @@ public class WareService extends CheckingService { wareRepository.findAll((root, query, builder) -> builder.equal(root.get("state"), Ware.State.NORMAL)) ); } - - @Transactional(rollbackOn = Throwable.class) - @Override - public void onChecked(CheckOrder order, CheckOrder.Operation operation, ImmutableMap parameters) { - if (StrUtil.equals(order.getKeyword(), "ware_check")) { - Long wareId = (Long) parameters.get("wareId"); - Ware ware = detailOrThrow(wareId); - switch (operation) { - case APPLY: - ware.setState(Ware.State.NORMAL); - order.setState(CheckOrder.State.OVER); - break; - case REJECT: - ware.setState(Ware.State.DRAFT); - order.setState(CheckOrder.State.OVER); - break; - } - save(ware); - checkOrderService.save(order); - } - } - - @Override - public ImmutableMap archive(Ware ware) { - return null; - } - - @Transactional(rollbackOn = Throwable.class) - @Override - public void submit(Long id) throws JsonProcessingException { - Ware ware = detailOrThrow(id); - ware.setState(Ware.State.CHECKING); - Long orderId = checkOrderService.save(new CheckOrder( - "ware_check", - StrUtil.format("数据资源「{}」的上架申请", ware.getName()), - CheckOrder.Type.MARKET, - mapper.writeValueAsString(Maps.immutable.of("wareId", ware.getId())), - "com.eshore.gringotts.web.domain.service.WareService", - User.Role.CHECKER - )); - CheckOrder order = checkOrderService.detailOrThrow(orderId); - ware.setOrder(order); - save(ware); - } - - @Transactional(rollbackOn = Throwable.class) - @Override - public void retract(Long id) { - Ware ware = detailOrThrow(id); - ware.setState(Ware.State.DRAFT); - save(ware); - - CheckOrder order = ware.getOrder(); - order.setState(CheckOrder.State.RETRACT); - checkOrderService.save(order); - } } diff --git a/gringotts-web/src/main/java/com/eshore/gringotts/web/helper/EntityHelper.java b/gringotts-web/src/main/java/com/eshore/gringotts/web/helper/EntityHelper.java index 3df6380..86b9949 100644 --- a/gringotts-web/src/main/java/com/eshore/gringotts/web/helper/EntityHelper.java +++ b/gringotts-web/src/main/java/com/eshore/gringotts/web/helper/EntityHelper.java @@ -3,9 +3,9 @@ package com.eshore.gringotts.web.helper; import cn.hutool.core.util.ObjectUtil; import com.eshore.gringotts.web.domain.base.entity.CheckingNeededEntity; import com.eshore.gringotts.web.domain.base.entity.CheckingNeededEntity_; -import com.eshore.gringotts.web.domain.entity.CheckOrder; import com.eshore.gringotts.web.domain.entity.CheckOrder_; import com.eshore.gringotts.web.domain.entity.User; +import com.eshore.gringotts.web.domain.entity.order.CheckOrder; import java.util.function.Supplier; import javax.persistence.criteria.CriteriaBuilder; import javax.persistence.criteria.Predicate;