├── README.md
├── pom.xml
└── src
├── main
├── java
│ └── com
│ │ └── lyxiang
│ │ ├── SquirrelApplication.java
│ │ ├── common
│ │ ├── OrderCondition.java
│ │ ├── OrderContext.java
│ │ ├── OrderEvent.java
│ │ └── OrderState.java
│ │ ├── controller
│ │ └── OrderController.java
│ │ ├── dao
│ │ └── OrderDTOMapper.java
│ │ ├── declarative
│ │ ├── DeclarativeOrderMachine.java
│ │ ├── Main.java
│ │ ├── OrderEventConverter.java
│ │ └── OrderStateConverter.java
│ │ ├── fluent
│ │ ├── Main.java
│ │ └── OrderStateMachine.java
│ │ ├── pojo
│ │ └── OrderDTO.java
│ │ ├── service
│ │ └── OrderService.java
│ │ └── spring
│ │ ├── AbstractOrderStatusMachineEngine.java
│ │ ├── AbstractUntypedStateMachine.java
│ │ ├── BaseOrderStateMachine.java
│ │ ├── OrderStateMachineEngineFactory.java
│ │ ├── SubmitOrderStateMachine.java
│ │ └── SubmitOrderStateMachineEngine.java
└── resources
│ ├── application.properties
│ └── mapper
│ └── OrderDTOMapper.xml
└── sql
└── order.sql
/README.md:
--------------------------------------------------------------------------------
1 | # squirrel-foundation-demo
2 | squirrel-foundation状态机的demo版本
3 |
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 | org.springframework.boot
7 | spring-boot-starter-parent
8 | 2.1.2.RELEASE
9 |
10 |
11 | com.lyxiang
12 | squirrel-foundation-demo
13 | 0.0.1-SNAPSHOT
14 | squirrel
15 | Demo project for Spring Boot
16 |
17 |
18 | 1.8
19 |
20 |
21 |
22 |
23 |
24 | org.springframework.boot
25 | spring-boot-starter
26 |
27 |
28 |
29 | org.springframework.boot
30 | spring-boot-starter-web
31 |
32 |
33 |
34 | org.springframework.boot
35 | spring-boot-starter-test
36 | test
37 |
38 |
39 |
40 | org.squirrelframework
41 | squirrel-foundation
42 | 0.3.8
43 |
44 |
45 |
46 | org.mybatis.spring.boot
47 | mybatis-spring-boot-starter
48 | 1.3.2
49 |
50 |
51 |
52 | com.alibaba
53 | druid-spring-boot-starter
54 | 1.1.1
55 |
56 |
57 |
58 | mysql
59 | mysql-connector-java
60 | runtime
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 | org.springframework.boot
69 | spring-boot-maven-plugin
70 |
71 |
72 |
73 |
74 |
75 |
--------------------------------------------------------------------------------
/src/main/java/com/lyxiang/SquirrelApplication.java:
--------------------------------------------------------------------------------
1 | package com.lyxiang;
2 |
3 | import org.mybatis.spring.annotation.MapperScan;
4 | import org.springframework.boot.SpringApplication;
5 | import org.springframework.boot.autoconfigure.SpringBootApplication;
6 | import org.springframework.context.annotation.ComponentScan;
7 |
8 | @SpringBootApplication
9 | @ComponentScan(basePackages = {"com.lyxiang"})
10 | @MapperScan(basePackages = "com.lyxiang.dao")
11 | public class SquirrelApplication {
12 |
13 | public static void main(String[] args) {
14 | SpringApplication.run(SquirrelApplication.class, args);
15 | }
16 |
17 | }
18 |
--------------------------------------------------------------------------------
/src/main/java/com/lyxiang/common/OrderCondition.java:
--------------------------------------------------------------------------------
1 | package com.lyxiang.common;
2 |
3 |
4 | import org.squirrelframework.foundation.fsm.Condition;
5 |
6 | /**
7 | * @author: liyuxiang
8 | * @create: 2019-01-23
9 | */
10 | public class OrderCondition implements Condition {
11 |
12 | @Override
13 | public boolean isSatisfied(Object context) {
14 | return true;
15 | }
16 |
17 | @Override
18 | public String name() {
19 | return "hahah";
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/src/main/java/com/lyxiang/common/OrderContext.java:
--------------------------------------------------------------------------------
1 | package com.lyxiang.common;
2 |
3 | import com.lyxiang.pojo.OrderDTO;
4 |
5 | /**
6 | * @author: liyuxiang
7 | * @create: 2019-01-23
8 | */
9 | public class OrderContext {
10 |
11 | public OrderContext(OrderDTO orderDTO) {
12 | this.orderDTO = orderDTO;
13 | }
14 |
15 | public OrderContext() {
16 | }
17 |
18 | public OrderDTO orderDTO;
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/src/main/java/com/lyxiang/common/OrderEvent.java:
--------------------------------------------------------------------------------
1 | package com.lyxiang.common;
2 |
3 | /**
4 | * @author: liyuxiang
5 | * @create: 2019-01-23
6 | */
7 | public enum OrderEvent {
8 |
9 | SUBMIT_ORDER,
10 | PAY,
11 | PART_SEND,
12 | SEND,
13 | COMPLETE
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/src/main/java/com/lyxiang/common/OrderState.java:
--------------------------------------------------------------------------------
1 | package com.lyxiang.common;
2 |
3 | /**
4 | * @author: liyuxiang
5 | * @create: 2019-01-23
6 | */
7 | public enum OrderState {
8 |
9 | INIT,
10 |
11 | WAIT_PAY,
12 |
13 | WAIT_SEND,
14 |
15 | PART_SEND,
16 |
17 | WAIT_RECEIVE,
18 |
19 | COMPLETE,
20 |
21 | CANCELED;
22 |
23 | public static OrderState getState(String state) {
24 | for (OrderState orderState : OrderState.values()) {
25 | if (orderState.name().equalsIgnoreCase(state)) {
26 | return orderState;
27 | }
28 | }
29 | return null;
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/src/main/java/com/lyxiang/controller/OrderController.java:
--------------------------------------------------------------------------------
1 | package com.lyxiang.controller;
2 |
3 | import com.google.common.collect.ImmutableMap;
4 | import com.lyxiang.service.OrderService;
5 | import org.springframework.beans.factory.annotation.Autowired;
6 | import org.springframework.web.bind.annotation.RequestMapping;
7 | import org.springframework.web.bind.annotation.RestController;
8 |
9 | import java.util.Map;
10 |
11 | /**
12 | * @author: liyuxiang
13 | * @create: 2019-01-29
14 | */
15 | @RestController
16 | @RequestMapping(value = "/order/")
17 | public class OrderController {
18 |
19 | @Autowired
20 | OrderService orderService;
21 |
22 | @RequestMapping(value = "submitOrder")
23 | public Map