作者 陈志颖

feat:增加订单领域服务

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":1617354279378526449}
\ No newline at end of file
{"/Users/steve/go/src/partner01/pkg/port/beego":1617679552608984079}
\ No newline at end of file
... ...
... ... @@ -6,10 +6,26 @@ 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)
}
... ...
... ... @@ -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 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
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 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
}
}
... ...
... ... @@ -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)
}
... ...