Browse Source

去掉模板中没用代码,增加状态机示例。

master
刘忱 2 years ago
parent
commit
f3e02eb0f0
  1. 1
      win-module-infra/win-module-infra-biz/src/main/resources/codegen/java/dal/do.vm
  2. 45
      win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/enums/order/OrderStatusEnum.java
  3. 70
      win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/enums/order/OrderStatusState.java
  4. 4
      win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/enums/package-info.java

1
win-module-infra/win-module-infra-biz/src/main/resources/codegen/java/dal/do.vm

@ -19,7 +19,6 @@ import ${BaseDOClassName};
* @author ${table.author}
*/
@TableName("${table.tableName.toLowerCase()}")
@KeySequence("${table.tableName.toLowerCase()}_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)

45
win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/enums/order/OrderStatusEnum.java

@ -0,0 +1,45 @@
package com.win.module.wms.enums.order;
/**
* 订单状态枚举
*/
public enum OrderStatusEnum {
CREATED(1, "待支付"),
PAID(2, "已支付"),
SHIPPED(3, "已发货"),
COMPLETED(4, "已完成"),
CANCELLING(5, "取消中"),
CANCELLED(6, "已取消");
private final int code;
private final String info;
OrderStatusEnum(int code, String info) {
this.code = code;
this.info = info;
}
public int getCode() {
return code;
}
public String getInfo() {
return info;
}
/**
* 用状态值获取枚举
* @param status
* @return
*/
static OrderStatusEnum getOrderStatusEnum(int status) {
for (OrderStatusEnum orderStatusEnum : values()) {
if (orderStatusEnum.getCode() == status) {
return orderStatusEnum;
}
}
return CREATED;
}
}

70
win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/enums/order/OrderStatusState.java

@ -0,0 +1,70 @@
package com.win.module.wms.enums.order;
/**
* 订单状态机
*/
public class OrderStatusState {
/**
* 当前状态枚举
*/
private OrderStatusEnum orderStatusEnum;
/**
* 构造函数默认创建
*/
public OrderStatusState() {
this.orderStatusEnum = OrderStatusEnum.CREATED;
}
/**
* 构造函数当前状态
* @param status
*/
public OrderStatusState(int status) {
this.orderStatusEnum = OrderStatusEnum.getOrderStatusEnum(status);
}
/**
* 构造函数当前状态枚举
* @param orderStatusEnum
*/
public OrderStatusState(OrderStatusEnum orderStatusEnum) {
this.orderStatusEnum = orderStatusEnum;
}
/**
* 当前状态是否允许支付
* @return
*/
public boolean pay() {
if(this.orderStatusEnum.getCode() == OrderStatusEnum.CREATED.getCode()) {
this.orderStatusEnum = OrderStatusEnum.PAID;
return Boolean.TRUE;
} else {
return Boolean.FALSE;
}
}
/**
* 当前状态是否允许发货
* @return
*/
public boolean ship() {
if(this.orderStatusEnum.getCode() == OrderStatusEnum.PAID.getCode()) {
this.orderStatusEnum = OrderStatusEnum.SHIPPED;
return Boolean.TRUE;
} else {
return Boolean.FALSE;
}
}
/**
* 获取可执行的状态机
* @return
*/
public OrderStatusEnum getState() {
return orderStatusEnum;
}
}

4
win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/enums/package-info.java

@ -0,0 +1,4 @@
/**
* System API 定义暴露给其它模块的 API
*/
package com.win.module.wms.enums;
Loading…
Cancel
Save