作者 陈志颖

合并分支 '3-project-init-order' 到 'dev'

Resolve "project-init-order"

Closes #3

查看合并请求 !7
正在显示 25 个修改的文件 包含 418 行增加56 行删除
version: v1
kind: Method
metadata:
name: cancel
name: cancelOrder
type: command
description: 取消订单服务
payload:
- ref: orderId
description: 订单id
required: true
- ref: orderNo
description: 订单编号
required: true
... ...
version: v1
kind: Method
metadata:
name: receiving
name: receivingGoods
type: command
description: 订单收货服务
payload:
- ref: orderId
description: 订单id
required: true
- ref: orderNo
description: 订单号
required: true
... ...
version: v1
kind: Method
metadata:
name: return
name: returnGoods
type: command
description: 订单退货服务
payload:
... ...
version: v1
kind: Method
metadata:
name: shipping
name: shippingGoods
type: command
description: 订单发货服务
payload:
... ...
{"/Users/steve/go/src/partner01/pkg/port/beego":1617679552608984079}
\ No newline at end of file
... ...
不能预览此文件类型
... ... @@ -6,10 +6,34 @@ import (
"gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/infrastructure/domainService"
)
func CreateShippingService(options map[string]interface{}) (service.ShippingService, error) {
func CreateShippingService(options map[string]interface{}) (service.ShippingGoodsService, error) {
var transactionContext *pgTransaction.TransactionContext
if value, ok := options["transactionContext"]; ok {
transactionContext = value.(*pgTransaction.TransactionContext)
}
return domainService.NewShippingService(transactionContext)
return domainService.NewShippingGoodsService(transactionContext)
}
func CreateReceivingService(options map[string]interface{}) (service.ReceivingGoodsService, error) {
var transactionContext *pgTransaction.TransactionContext
if value, ok := options["transactionContext"]; ok {
transactionContext = value.(*pgTransaction.TransactionContext)
}
return domainService.NewReceivingGoodsService(transactionContext)
}
func CreateCancelOrderService(options map[string]interface{}) (service.CancelOrderService, error) {
var transactionContext *pgTransaction.TransactionContext
if value, ok := options["transactionContext"]; ok {
transactionContext = value.(*pgTransaction.TransactionContext)
}
return domainService.NewCancelOrderService(transactionContext)
}
func CreateReturnGoodsService(options map[string]interface{}) (service.ReturnGoodsService, error) {
var transactionContext *pgTransaction.TransactionContext
if value, ok := options["transactionContext"]; ok {
transactionContext = value.(*pgTransaction.TransactionContext)
}
return domainService.NewReturnGoodsService(transactionContext)
}
... ...
... ... @@ -7,7 +7,9 @@ import (
"github.com/beego/beego/v2/core/validation"
)
type CancelCommand struct {
type CancelOrderCommand struct {
// 订单ID
OrderId int64 `json:"orderId" valid:"Required"`
// 订单编号
OrderNo string `json:"orderNo" valid:"Required"`
// 公司id
... ... @@ -38,13 +40,13 @@ type CancelCommand struct {
JobNumber string `json:"jobNumber" valid:"Required"`
}
func (cancelCommand *CancelCommand) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
func (cancelOrderCommand *CancelOrderCommand) Valid(validation *validation.Validation) {
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (cancelCommand *CancelCommand) ValidateCommand() error {
func (cancelOrderCommand *CancelOrderCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(cancelCommand)
b, err := valid.Valid(cancelOrderCommand)
if err != nil {
return err
}
... ...
... ... @@ -7,7 +7,7 @@ import (
"github.com/beego/beego/v2/core/validation"
)
type ReturnCommand struct {
type ReceivingGoodsCommand struct {
// 订单号
OrderNo string `json:"orderNo" valid:"Required"`
// 是否是公司负责人
... ... @@ -38,13 +38,13 @@ type ReturnCommand struct {
CompanyId int64 `json:"companyId" valid:"Required"`
}
func (returnCommand *ReturnCommand) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
func (receivingGoodsCommand *ReceivingGoodsCommand) Valid(validation *validation.Validation) {
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (returnCommand *ReturnCommand) ValidateCommand() error {
func (receivingGoodsCommand *ReceivingGoodsCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(returnCommand)
b, err := valid.Valid(receivingGoodsCommand)
if err != nil {
return err
}
... ...
... ... @@ -7,7 +7,7 @@ import (
"github.com/beego/beego/v2/core/validation"
)
type ReceivingCommand struct {
type ReturnGoodsCommand struct {
// 订单号
OrderNo string `json:"orderNo" valid:"Required"`
// 是否是公司负责人
... ... @@ -38,13 +38,13 @@ type ReceivingCommand struct {
CompanyId int64 `json:"companyId" valid:"Required"`
}
func (receivingCommand *ReceivingCommand) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
func (returnGoodsCommand *ReturnGoodsCommand) Valid(validation *validation.Validation) {
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (receivingCommand *ReceivingCommand) ValidateCommand() error {
func (returnGoodsCommand *ReturnGoodsCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(receivingCommand)
b, err := valid.Valid(returnGoodsCommand)
if err != nil {
return err
}
... ...
... ... @@ -6,7 +6,9 @@ import (
"github.com/beego/beego/v2/core/validation"
)
type ShippingCommand struct {
type ShippingGoodsCommand struct {
// 订单ID
OrderId int `json:"orderId" valid:"Required"`
// 发货单号
DeliveryCode string `json:"deliveryCode" valid:"Required"`
// 订单编号
... ... @@ -15,13 +17,13 @@ type ShippingCommand struct {
OrderNum int64 `json:"orderNum" valid:"Required"`
}
func (shippingCommand *ShippingCommand) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
func (shippingGoodsCommand *ShippingGoodsCommand) Valid(validation *validation.Validation) {
//_ = validation.SetError("CustomValid", "未实现的自定义认证")
}
func (shippingCommand *ShippingCommand) ValidateCommand() error {
func (shippingGoodsCommand *ShippingGoodsCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(shippingCommand)
b, err := valid.Valid(shippingGoodsCommand)
if err != nil {
return err
}
... ...
... ... @@ -16,7 +16,7 @@ type OrderService struct {
}
// 取消订单服务
func (orderService *OrderService) Cancel(cancelCommand *command.CancelCommand) (interface{}, error) {
func (orderService *OrderService) Cancel(cancelCommand *command.CancelOrderCommand) (interface{}, error) {
if err := cancelCommand.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
... ... @@ -78,8 +78,8 @@ func (orderService *OrderService) CreateOrder(createOrderCommand *command.Create
}
// 订单分红服务
func (orderService *OrderService) DarwDividends(darwDividendsCommand *command.DrawDividendsCommand) (interface{}, error) {
if err := darwDividendsCommand.ValidateCommand(); err != nil {
func (orderService *OrderService) DrawDividends(drawDividendsCommand *command.DrawDividendsCommand) (interface{}, error) {
if err := drawDividendsCommand.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
... ... @@ -172,7 +172,7 @@ func (orderService *OrderService) ListOrder(listOrderQuery *query.ListOrderQuery
}
// 订单收货服务
func (orderService *OrderService) Receiving(receivingCommand *command.ReceivingCommand) (interface{}, error) {
func (orderService *OrderService) Receiving(receivingCommand *command.ReceivingGoodsCommand) (interface{}, error) {
if err := receivingCommand.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
... ... @@ -233,7 +233,7 @@ func (orderService *OrderService) RemoveOrder(removeOrderCommand *command.Remove
}
// 订单退货服务
func (orderService *OrderService) Return(returnCommand *command.ReturnCommand) (interface{}, error) {
func (orderService *OrderService) Return(returnCommand *command.ReturnGoodsCommand) (interface{}, error) {
if err := returnCommand.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
... ... @@ -254,7 +254,7 @@ func (orderService *OrderService) Return(returnCommand *command.ReturnCommand) (
}
// 订单发货服务
func (orderService *OrderService) Shipping(shippingCommand *command.ShippingCommand) (interface{}, error) {
func (orderService *OrderService) Shipping(shippingCommand *command.ShippingGoodsCommand) (interface{}, error) {
if err := shippingCommand.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
... ...
package domain
import "time"
import (
"fmt"
"time"
)
// 订单类型
const (
ORDER_TYPE_ACTUAL = iota + 1 //实际订单
ORDER_TYPE_INTENTION // 意向订单
)
// 订单状态
const (
ORDER_STATUS_UNSHIPPED = iota + 1 // 待发货
ORDER_STATUS_TRANSIT // 待收货(运输中)
ORDER_STATUS_RECEIVED // 已收货
ORDER_STATUS_RETURN // 退换货
ORDER_STATUS_CANCELED // 已取消(关闭)
ORDER_STATUS_COMPLETED // 已完成
)
// 订单实体
type Order struct {
... ... @@ -44,23 +63,24 @@ type Order struct {
UpdateAt time.Time `json:"updateAt"`
// 软删
DeleteAt time.Time `json:"deleteAt"`
// 当前状态
CurrentStatus OrderStatus `json:"-"`
}
type OrderRepository interface {
Save(order *Order) (*Order, error)
Remove(order *Order) (*Order, error)
FindOne(queryOptions map[string]interface{}) (*Order, error)
Find(queryOptions map[string]interface{}) (int64, []*Order, error)
// 订单状态机
type OrderStatus interface {
Update(order *Order, data map[string]interface{}) error // 更新订单
Checkout(order *Order) error // 下单
Return(order *Order) error // 退换货
Cancel(order *Order) error // 取消订单
Receive(order *Order) error // 收货
}
func (order *Order) Identify() interface{} {
if order.OrderId == 0 {
return nil
}
return order.OrderId
}
// 代发货状态
type UnShippedStatus struct{}
func (order *Order) Update(data map[string]interface{}) error {
// 编辑待发货订单
func (status *UnShippedStatus) Update(order *Order, data map[string]interface{}) error {
if orderId, ok := data["orderId"]; ok {
order.OrderId = orderId.(int64)
}
... ... @@ -174,3 +194,170 @@ func (order *Order) Update(data map[string]interface{}) error {
}
return nil
}
func (status *UnShippedStatus) Checkout(order *Order) error {
return nil
}
func (status *UnShippedStatus) Return(order *Order) error {
return fmt.Errorf("待发货订单不能退货")
}
func (status *UnShippedStatus) Cancel(order *Order) error {
return nil
}
func (status *UnShippedStatus) Receive(order *Order) error {
return fmt.Errorf("待发货订单不能收货")
}
// 待收货状态
type TransitStatus struct{}
// 待收货订单不允许编辑
func (status *TransitStatus) Update(order *Order, data map[string]interface{}) error {
return fmt.Errorf("已发货订单不允许编辑")
}
func (status *TransitStatus) Checkout(order *Order) error {
return fmt.Errorf("待收货订单不能重复发货")
}
func (status *TransitStatus) Return(order *Order) error {
return nil
}
func (status *TransitStatus) Cancel(order *Order) error {
return fmt.Errorf("待收货订单不能取消")
}
func (status *TransitStatus) Receive(order *Order) error {
return nil
}
// 收货状态
type ReceivedStatus struct{}
func (status *ReceivedStatus) Update(order *Order, data map[string]interface{}) error {
return fmt.Errorf("已收货订单不能编辑")
}
func (status *ReceivedStatus) Checkout(order *Order) error {
return fmt.Errorf("已收货订单不能重复发货")
}
func (status *ReceivedStatus) Return(order *Order) error {
return nil
}
func (status *ReceivedStatus) Cancel(order *Order) error {
return fmt.Errorf("已收货订单不能取消")
}
func (status *ReceivedStatus) Receive(order *Order) error {
return fmt.Errorf("已收货订单不能重复收货")
}
// 退货状态
type ReturnedStatus struct{}
func (status *ReturnedStatus) Update(order *Order, data map[string]interface{}) error {
return fmt.Errorf("已退货订单不允许编辑")
}
func (status *ReturnedStatus) Checkout(order *Order) error {
return fmt.Errorf("已退货订单不允许发货")
}
func (status *ReturnedStatus) Return(order *Order) error {
return fmt.Errorf("已退货订单不允许再次退货")
}
func (status *ReturnedStatus) Cancel(order *Order) error {
return fmt.Errorf("已退货订单不能取消")
}
func (status *ReturnedStatus) Receive(order *Order) error {
return fmt.Errorf("已退货订单不能收货")
}
// 取消状态
type CanceledStatus struct{}
func (status *CanceledStatus) Update(order *Order, dat map[string]interface{}) error {
return fmt.Errorf("已取消订单不能编辑")
}
func (status *CanceledStatus) Checkout(order *Order) error {
return fmt.Errorf("已取消订单不能发货")
}
func (status *CanceledStatus) Return(order *Order) error {
return fmt.Errorf("已取消订单不能退货")
}
func (status *CanceledStatus) Cancel(order *Order) error {
return fmt.Errorf("已取消订单不能再次取消")
}
func (status *CanceledStatus) Receive(order *Order) error {
return fmt.Errorf("已取消订单不能进行收货")
}
// 已完成状态
type CompletedStatus struct{}
func (status *CompletedStatus) Update(order *Order, data map[string]interface{}) error {
return nil
}
func (status *CompletedStatus) Checkout(order *Order) error {
return fmt.Errorf("已完成订单不能发货")
}
func (status *CompletedStatus) Return(order *Order) error {
return fmt.Errorf("已完成订单不能退货")
}
func (status *CompletedStatus) Cancel(order *Order) error {
return fmt.Errorf("已完成订单不能取消")
}
func (status *CompletedStatus) Receive(order *Order) error {
return fmt.Errorf("已完成订单不能收货")
}
// 订单仓储
type OrderRepository interface {
Save(order *Order) (*Order, error)
Remove(order *Order) (*Order, error)
FindOne(queryOptions map[string]interface{}) (*Order, error)
Find(queryOptions map[string]interface{}) (int64, []*Order, error)
}
func (order *Order) Identify() interface{} {
if order.OrderId == 0 {
return nil
}
return order.OrderId
}
func (order *Order) Update(data map[string]interface{}) error {
return order.CurrentStatus.Update(order, data)
}
func (order *Order) Checkout() error {
return order.CurrentStatus.Checkout(order)
}
func (order *Order) Return() error {
return order.CurrentStatus.Return(order)
}
func (order *Order) Receive() error {
return order.CurrentStatus.Receive(order)
}
func (order *Order) Cancel() error {
return order.CurrentStatus.Cancel(order)
}
... ...
package service
import (
coreDomain "github.com/linmadan/egglib-go/core/domain"
"gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/domain"
)
type CancelOrderService interface {
coreDomain.DomainEventPublisher
Cancel(orderId int64) (*domain.Order, error)
}
... ...
package service
import (
coreDomain "github.com/linmadan/egglib-go/core/domain"
"gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/domain"
)
type ReceivingGoodsService interface {
coreDomain.DomainEventPublisher
Receiving(orderId int64) (*domain.Order, error)
}
... ...
package service
import (
coreDomain "github.com/linmadan/egglib-go/core/domain"
"gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/domain"
)
type ReturnGoodsService interface {
coreDomain.DomainEventPublisher
Return(orderId int64) (*domain.Order, error)
}
... ...
package service
type ShippingService interface {
}
package service
import (
coreDomain "github.com/linmadan/egglib-go/core/domain"
"gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/domain"
)
type ShippingGoodsService interface {
coreDomain.DomainEventPublisher
Shipping(orderId int64) (*domain.Order, error)
}
... ...
... ... @@ -2,19 +2,26 @@ package domainService
import (
"fmt"
coreDomain "github.com/linmadan/egglib-go/core/domain"
"gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/domain"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
)
type ShippingService struct {
type CancelOrderService struct {
coreDomain.BaseEventPublisher
transactionContext *pgTransaction.TransactionContext
}
func NewShippingService(transactionContext *pgTransaction.TransactionContext) (*ShippingService, error) {
func (service *CancelOrderService) Cancel(orderId int64) (*domain.Order, error) {
return nil, nil
}
func NewCancelOrderService(transactionContext *pgTransaction.TransactionContext) (*CancelOrderService, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
} else {
return &ShippingService{
return &CancelOrderService{
transactionContext: transactionContext,
}, nil
}
... ...
package domainService
import (
"fmt"
coreDomain "github.com/linmadan/egglib-go/core/domain"
"gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/domain"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
)
type ReceivingGoodsService struct {
coreDomain.BaseEventPublisher
transactionContext *pgTransaction.TransactionContext
}
func (service *ReceivingGoodsService) Receiving(orderId int64) (*domain.Order, error) {
return nil, nil
}
func NewReceivingGoodsService(transactionContext *pgTransaction.TransactionContext) (*ReceivingGoodsService, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
} else {
return &ReceivingGoodsService{
transactionContext: transactionContext,
}, nil
}
}
... ...
package domainService
import (
"fmt"
coreDomain "github.com/linmadan/egglib-go/core/domain"
"gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/domain"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
)
type ReturnGoodsService struct {
coreDomain.BaseEventPublisher
transactionContext *pgTransaction.TransactionContext
}
func (service *ReceivingGoodsService) Return(orderId int64) (*domain.Order, error) {
return nil, nil
}
func NewReturnGoodsService(transactionContext *pgTransaction.TransactionContext) (*ReturnGoodsService, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
} else {
return &ReturnGoodsService{
transactionContext: transactionContext,
}, nil
}
}
... ...
package domainService
import (
"fmt"
coreDomain "github.com/linmadan/egglib-go/core/domain"
"gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/domain"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
)
type ShippingGoodsService struct {
coreDomain.BaseEventPublisher
transactionContext *pgTransaction.TransactionContext
}
func (service *ShippingGoodsService) Shipping(orderId int64) (*domain.Order, error) {
return nil, nil
}
func NewShippingGoodsService(transactionContext *pgTransaction.TransactionContext) (*ShippingGoodsService, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
} else {
return &ShippingGoodsService{
transactionContext: transactionContext,
}, nil
}
}
... ...
... ... @@ -7,7 +7,6 @@ import (
"gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/constant"
"gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/infrastructure/pg/models"
//_ "gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/infrastructure/pg/models"
"github.com/linmadan/egglib-go/persistent/pg/hooks"
)
... ...
... ... @@ -22,7 +22,7 @@ func (controller *OrderController) CreateOrder() {
func (controller *OrderController) UpdateOrder() {
orderService := service.NewOrderService(nil)
updateOrderCommand := &command.UpdateOrderCommand{}
controller.Unmarshal(updateOrderCommand)
_ = controller.Unmarshal(updateOrderCommand)
orderId, _ := controller.GetInt64(":orderId")
updateOrderCommand.OrderId = orderId
data, err := orderService.UpdateOrder(updateOrderCommand)
... ... @@ -41,7 +41,7 @@ func (controller *OrderController) GetOrder() {
func (controller *OrderController) RemoveOrder() {
orderService := service.NewOrderService(nil)
removeOrderCommand := &command.RemoveOrderCommand{}
controller.Unmarshal(removeOrderCommand)
_ = controller.Unmarshal(removeOrderCommand)
orderId, _ := controller.GetInt64(":orderId")
removeOrderCommand.OrderId = orderId
data, err := orderService.RemoveOrder(removeOrderCommand)
... ... @@ -58,3 +58,13 @@ func (controller *OrderController) ListOrder() {
data, err := orderService.ListOrder(listOrderQuery)
controller.Response(data, err)
}
func (controller *OrderController) Shipping() {
orderService := service.NewOrderService(nil)
shippingCmd := &command.ShippingGoodsCommand{}
_ = controller.Unmarshal(shippingCmd)
orderId, _ := controller.GetInt(":orderId")
shippingCmd.OrderId = orderId
data, err := orderService.Shipping(shippingCmd)
controller.Response(data, err)
}
... ...
... ... @@ -9,7 +9,7 @@ import (
pG "gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/infrastructure/pg"
)
var _ = Describe("创建订单增删改查", func() {
var _ = FDescribe("创建订单增删改查", func() {
Describe("提交数据创建订单增删改查", func() {
Context("提交正确的新订单实体数据", func() {
It("返回订单实体数据", func() {
... ...