From 3da76d290abc716288938aa8665de39315e0f66c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A7=A6=E8=8B=B1=E6=9D=B0?= <327782001@qq.com> Date: Sat, 29 Jul 2023 19:23:03 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E8=AE=A2=E5=8D=95=E7=8A=B6=E6=80=81?= =?UTF-8?q?=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../design/order/OrderStateListener.java | 20 +++++++++---- .../order/config/OrderStateMachineConfig.java | 18 +++++++++-- .../com/study/design/order/pojo/Order.java | 19 ++++++++++-- .../study/design/order/pojo/OrderState.java | 30 +++++++++++++++---- .../order/pojo/OrderStateChangeAction.java | 23 ++++++++++++-- 5 files changed, 92 insertions(+), 18 deletions(-) diff --git a/src/main/java/com/study/design/order/OrderStateListener.java b/src/main/java/com/study/design/order/OrderStateListener.java index 2aea114..a4f4152 100644 --- a/src/main/java/com/study/design/order/OrderStateListener.java +++ b/src/main/java/com/study/design/order/OrderStateListener.java @@ -8,24 +8,34 @@ import org.springframework.statemachine.annotation.OnTransition; import org.springframework.statemachine.annotation.WithStateMachine; import org.springframework.stereotype.Component; -// 监听器是监听到 action 后进行状态的一个变更。 + +/** + * 监听器是监听到 action 后进行状态的一个变更。 + * + * @author : qinyingjie + * @version : 2.2.0 + * @date : 2023/7/29 19:18 + */ @Component("orderStateListener") -@WithStateMachine(name="orderStateMachine") +@WithStateMachine(name = "orderStateMachine") public class OrderStateListener { + @OnTransition(source = "ORDER_WAIT_PAY", target = "ORDER_WAIT_SEND") - public boolean payToSend(Message message){ + public boolean payToSend(Message message) { Order order = (Order) message.getHeaders().get("order"); order.setOrderState(OrderState.ORDER_WAIT_SEND); return true; } + @OnTransition(source = "ORDER_WAIT_SEND", target = "ORDER_WAIT_RECEIVE") - public boolean sendToReceive(Message message){ + public boolean sendToReceive(Message message) { Order order = (Order) message.getHeaders().get("order"); order.setOrderState(OrderState.ORDER_WAIT_RECEIVE); return true; } + @OnTransition(source = "ORDER_WAIT_RECEIVE", target = "ORDER_FINISH") - public boolean receiveToFinish(Message message){ + public boolean receiveToFinish(Message message) { Order order = (Order) message.getHeaders().get("order"); order.setOrderState(OrderState.ORDER_FINISH); return true; diff --git a/src/main/java/com/study/design/order/config/OrderStateMachineConfig.java b/src/main/java/com/study/design/order/config/OrderStateMachineConfig.java index 5f4575f..e80aa5c 100644 --- a/src/main/java/com/study/design/order/config/OrderStateMachineConfig.java +++ b/src/main/java/com/study/design/order/config/OrderStateMachineConfig.java @@ -16,14 +16,24 @@ import org.springframework.statemachine.support.DefaultStateMachineContext; import java.util.EnumSet; + +/** + * 订单状态配置类 + * + * @author : qinyingjie + * @version : 2.2.0 + * @date : 2023/7/29 19:22 + */ @Configuration -@EnableStateMachine(name="orderStateMachine") +@EnableStateMachine(name = "orderStateMachine") public class OrderStateMachineConfig extends StateMachineConfigurerAdapter { + @Override public void configure(StateMachineStateConfigurer states) throws Exception { states.withStates().initial(OrderState.ORDER_WAIT_PAY) .states(EnumSet.allOf(OrderState.class)); } + @Override public void configure(StateMachineTransitionConfigurer transitions) throws Exception { transitions.withExternal().source(OrderState.ORDER_WAIT_PAY) .target(OrderState.ORDER_WAIT_SEND) @@ -38,7 +48,11 @@ public class OrderStateMachineConfig extends StateMachineConfigurerAdapter(new StateMachinePersist() { diff --git a/src/main/java/com/study/design/order/pojo/Order.java b/src/main/java/com/study/design/order/pojo/Order.java index 46e0184..1eb4085 100644 --- a/src/main/java/com/study/design/order/pojo/Order.java +++ b/src/main/java/com/study/design/order/pojo/Order.java @@ -1,10 +1,23 @@ package com.study.design.order.pojo; -//状态转化的一个控制机。状态机:初始化状态;配置我们的所有状态之间的转化关系; -//一些持久化的工作(redis)。 + +/** + * 状态转化的一个控制机。状态机:初始化状态;配置我们的所有状态之间的转化关系; + * 一些持久化的工作(redis)。 + * + * @author : qinyingjie + * @version : 2.2.0 + * @date : 2023/7/29 19:18 + */ public class Order { + /** + * 订单id + */ private Integer orderId; - private OrderState orderState;//订单状态 + /** + * 订单状态 + */ + private OrderState orderState; public Integer getOrderId() { return orderId; diff --git a/src/main/java/com/study/design/order/pojo/OrderState.java b/src/main/java/com/study/design/order/pojo/OrderState.java index 0b95945..cb75fa8 100644 --- a/src/main/java/com/study/design/order/pojo/OrderState.java +++ b/src/main/java/com/study/design/order/pojo/OrderState.java @@ -1,8 +1,28 @@ package com.study.design.order.pojo; -public enum OrderState { - ORDER_WAIT_PAY, // 待支付 - ORDER_WAIT_SEND, // 待发货 - ORDER_WAIT_RECEIVE, // 待收货 - ORDER_FINISH; // 完成订单 + +/** + * 订单状态枚举类 + * + * @author : qinyingjie + * @version : 2.2.0 + * @date : 2023/7/29 19:19 + */ +public enum OrderState { + /** + * 待支付 + */ + ORDER_WAIT_PAY, + /** + * 待发货 + */ + ORDER_WAIT_SEND, + /** + * 待收货 + */ + ORDER_WAIT_RECEIVE, + /** + * 完成订单 + */ + ORDER_FINISH; } diff --git a/src/main/java/com/study/design/order/pojo/OrderStateChangeAction.java b/src/main/java/com/study/design/order/pojo/OrderStateChangeAction.java index dd7f65a..aec085c 100644 --- a/src/main/java/com/study/design/order/pojo/OrderStateChangeAction.java +++ b/src/main/java/com/study/design/order/pojo/OrderStateChangeAction.java @@ -1,7 +1,24 @@ package com.study.design.order.pojo; + +/** + * 操作动作枚举 + * + * @author : qinyingjie + * @version : 2.2.0 + * @date : 2023/7/29 19:20 + */ public enum OrderStateChangeAction { - PAY_ORDER, // 支付操作 - SEND_ORDER, // 发货操作 - RECEIVE_ORDER; // 收货操作 + /** + * 支付操作 + */ + PAY_ORDER, + /** + * 发货操作 + */ + SEND_ORDER, + /** + * 收货操作 + */ + RECEIVE_ORDER; } -- GitLab