作者 陈志颖
提交者 yangfu

feat:完善代码

正在显示 37 个修改的文件 包含 256 行增加266 行删除
version: v1
kind: Attribute
metadata:
name: goodsDetail
name: goodDetail
description: 商品详情
type:
schema: goodsDetail
schema: goodDetail
... ...
version: v1
kind: Attribute
metadata:
name: goodsDividend
name: goodDividend
description: 商品分红支付信息
type:
schema: dividend
... ...
version: v1
kind: Attribute
metadata:
name: goodsDividendStatus
name: goodDividendStatus
description: 商品分红支付状态
type:
primitive: int
... ...
version: v1
kind: Attribute
metadata:
name: goodsId
name: goodId
description: 商品id
type:
primitive: int64
... ...
version: v1
kind: Attribute
metadata:
name: goodsName
name: goodName
description: 商品名称
type:
primitive: string
... ...
version: v1
kind: Attribute
metadata:
name: goodsNum
name: goodNum
description: 预定的货品数量
type:
primitive: int
... ...
version: v1
kind: Attribute
metadata:
name: goodsTotalPrice
name: goodTotalPrice
description: 商品单价
type:
primitive: float64
... ...
version: v1
kind: Attribute
metadata:
name: actualNumber
name: actualNum
description: 调整后的实际货品数量
type:
primitive: int
... ...
version: v1
kind: Attribute
metadata:
name: goodsDetailId
name: goodDetailId
description: 商品详情id
type:
primitive: int64
... ...
... ... @@ -4,4 +4,4 @@ metadata:
name: orderGoods
description: 订单货品
type:
array: goods
array: good
... ...
version: v1
kind: Schema
metadata:
name: goods
name: good
description: 订单商品实体
attributes:
- ref: goodsId
- ref: goodId
required: true
- ref: goodsNum
- ref: goodNum
required: true
- ref: goodsDividend
- ref: goodDividend
required: true
- ref: goodsDividendStatus
- ref: goodDividendStatus
required: true
- ref: goodsName
- ref: goodName
required: true
- ref: goodsTotalPrice
- ref: goodTotalPrice
required: true
- ref: remarks
required: true
- ref: orderNo
required: true
- name: goodsDetail
- name: goodDetail
required: true
- ref: createAt
required: true
... ...
version: v1
kind: Schema
metadata:
name: goodsDetail
name: goodDetail
description: 商品详情值对象
attributes:
- ref: goodsDetailId
- ref: goodDetailId
required: true
- ref: adjustedNum
required: true
... ...
... ... @@ -10,7 +10,7 @@ metadata:
required: true
- ref: companyId
required: true
- ref: partnerId
- ref: userId
required: true
- ref: deliveryCode
required: true
... ...
version: v1
kind: Schema
metadata:
name: partner
description: 合伙人实体
attributes:
- ref: partnerId
required: true
- ref: cooperateTime
required: true
- ref: partnerCategory
required: true
- ref: partnerCategoryInfos
required: true
- ref: partnerInfo
required: true
- ref: salesman
required: true
- ref: status
required: true
... ... @@ -38,7 +38,7 @@ func CreateOrderRepository(options map[string]interface{}) (domain.OrderReposito
return repository.NewOrderRepository(transactionContext)
}
func CreateGoodsRepository(options map[string]interface{}) (domain.GoodsRepository, error) {
func CreateGoodsRepository(options map[string]interface{}) (domain.GoodRepository, error) {
var transactionContext *pg.TransactionContext
if value, ok := options["transactionContext"]; ok {
transactionContext = value.(*pg.TransactionContext)
... ...
... ... @@ -7,6 +7,8 @@ import (
)
type CreateOrderCommand struct {
// 订单ID
OrderId int64 `json:"orderId"`
// 订单编号
OrderNo string `json:"orderNo" valid:"Required"`
// 公司Id
... ... @@ -15,16 +17,24 @@ type CreateOrderCommand struct {
BuyerName string `json:"buyerName,omitempty"`
// 联系信息
ContactInfo string `json:"contactInfo,omitempty"`
// 货地址
// 货地址
ShippingAddress string `json:"shippingAddress,omitempty"`
// 买家备注
Remarks string `json:"remarks,omitempty"`
// 订单商品总数
OrderNum int64 `json:"orderNum" valid:"Required"`
// 订单总价
TotalPrice float64 `json:"totalPrice" valid:"Required"`
// 订单合伙人ID
PartnerId int64 `json:"partnerId"`
// 订单状态
OrderStatus int `json:"orderStatus"`
// 订单类型
OrderType int `json:"orderType"`
}
func (createOrderCommand *CreateOrderCommand) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (createOrderCommand *CreateOrderCommand) ValidateCommand() error {
... ...
... ... @@ -14,7 +14,7 @@ type DrawDividendsCommand struct {
}
func (drawDividendsCommand *DrawDividendsCommand) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (drawDividendsCommand *DrawDividendsCommand) ValidateCommand() error {
... ...
... ... @@ -2,40 +2,16 @@ package command
import (
"fmt"
"time"
"github.com/beego/beego/v2/core/validation"
)
type ReturnGoodsCommand struct {
// 订单ID
OrderId int64 `json:"orderId" valid:"Required"`
// 订单号
OrderNo string `json:"orderNo" valid:"Required"`
// 是否是公司负责人
IsPrincipal bool `json:"isPrincipal" valid:"Required"`
// 统一用户id
Uid int64 `json:"uid" valid:"Required"`
// 用户账号
UserAccount string `json:"userAccount" valid:"Required"`
// 用户头像URL
UserAvatarUrl string `json:"userAvatarUrl" valid:"Required"`
// 用户名称
UserName string `json:"userName" valid:"Required"`
// 邮件地址
Email string `json:"email" valid:"Required"`
// 性别
Gender int `json:"gender" valid:"Required"`
// 入职时间
EntryTime time.Time `json:"entryTime" valid:"Required"`
// 分机
Extension string `json:"extension" valid:"Required"`
// 工作地
Workplace string `json:"workplace" valid:"Required"`
// 私人电话
PrivateNumber string `json:"privateNumber" valid:"Required"`
// 工号
JobNumber string `json:"jobNumber" valid:"Required"`
// 公司id
CompanyId int64 `json:"companyId" valid:"Required"`
}
func (returnGoodsCommand *ReturnGoodsCommand) Valid(validation *validation.Validation) {
... ...
... ... @@ -9,10 +9,18 @@ import (
type UpdateOrderCommand struct {
// 订单id
OrderId int64 `json:"orderId" valid:"Required"`
// 发货地址
BuyerName string `json:"buyerName"`
// 订单商品总数
OrderNum string `json:"orderNum"`
// 订单总价
TotalPrice float64 `json:"totalPrice"`
// 收货地址
ShippingAddress string `json:"shippingAddress" valid:"omitempty"`
}
func (updateOrderCommand *UpdateOrderCommand) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (updateOrderCommand *UpdateOrderCommand) ValidateCommand() error {
... ...
... ... @@ -8,4 +8,6 @@ type BuyerInfo struct {
ContactInfo string `json:"contactInfo"`
// 发货地址
ShippingAddress string `json:"shippingAddress"`
// 买家备注
Remarks string `json:"remarks"`
}
... ...
... ... @@ -3,24 +3,25 @@ package domain
import "time"
// 订单商品实体
type Goods struct {
type Good struct {
// 商品id
GoodsId int64 `json:"goodsId"`
GoodId int64 `json:"goodId"`
// 预定的货品数量
GoodsNum int `json:"goodsNum"`
GoodNum int `json:"goodNum"`
// 商品分红支付信息
GoodsDividend *Dividend `json:"goodsDividend"`
GoodDividend *Dividend `json:"goodDividend"`
// 商品分红支付状态
GoodsDividendStatus int `json:"goodsDividendStatus"`
GoodDividendStatus int `json:"goodDividendStatus"`
// 商品名称
GoodsName string `json:"goodsName"`
GoodName string `json:"goodName"`
// 商品单价
GoodsTotalPrice float64 `json:"goodsTotalPrice"`
GoodTotalPrice float64 `json:"goodTotalPrice"`
// 备注
Remarks string `json:"remarks"`
// 订单编号
OrderNo string `json:"orderNo"`
GoodsDetail string `json:"goodsDetail"`
OrderNo string `json:"orderNo"`
// 商品详情
GoodDetail string `json:"goodDetail"`
// 创建时间
CreateAt time.Time `json:"createAt"`
// 更新时间
... ... @@ -29,80 +30,80 @@ type Goods struct {
DeleteAt time.Time `json:"deleteAt"`
}
type GoodsRepository interface {
Save(goods *Goods) (*Goods, error)
Remove(goods *Goods) (*Goods, error)
FindOne(queryOptions map[string]interface{}) (*Goods, error)
Find(queryOptions map[string]interface{}) (int64, []*Goods, error)
type GoodRepository interface {
Save(good *Good) (*Good, error)
Remove(good *Good) (*Good, error)
FindOne(queryOptions map[string]interface{}) (*Good, error)
Find(queryOptions map[string]interface{}) (int64, []*Good, error)
}
func (goods *Goods) Identify() interface{} {
if goods.GoodsId == 0 {
func (good *Good) Identify() interface{} {
if good.GoodId == 0 {
return nil
}
return goods.GoodsId
return good.GoodId
}
func (goods *Goods) Update(data map[string]interface{}) error {
if goodsId, ok := data["goodsId"]; ok {
goods.GoodsId = goodsId.(int64)
func (good *Good) Update(data map[string]interface{}) error {
if goodId, ok := data["goodId"]; ok {
good.GoodId = goodId.(int64)
}
if goodsNum, ok := data["goodsNum"]; ok {
goods.GoodsNum = goodsNum.(int)
if goodNum, ok := data["goodNum"]; ok {
good.GoodNum = goodNum.(int)
}
if planBonus, ok := data["planBonus"]; ok {
goods.GoodsDividend.PlanBonus = planBonus.(float64)
good.GoodDividend.PlanBonus = planBonus.(float64)
}
if useBonus, ok := data["useBonus"]; ok {
goods.GoodsDividend.UseBonus = useBonus.(float64)
good.GoodDividend.UseBonus = useBonus.(float64)
}
if bonusHas, ok := data["bonusHas"]; ok {
goods.GoodsDividend.BonusHas = bonusHas.(float64)
good.GoodDividend.BonusHas = bonusHas.(float64)
}
if bonusNot, ok := data["bonusNot"]; ok {
goods.GoodsDividend.BonusNot = bonusNot.(float64)
good.GoodDividend.BonusNot = bonusNot.(float64)
}
if bonusExpense, ok := data["bonusExpense"]; ok {
goods.GoodsDividend.BonusExpense = bonusExpense.(float64)
good.GoodDividend.BonusExpense = bonusExpense.(float64)
}
if bonusStatus, ok := data["bonusStatus"]; ok {
goods.GoodsDividend.BonusStatus = bonusStatus.(int)
good.GoodDividend.BonusStatus = bonusStatus.(int)
}
if partnerBonusPercent, ok := data["partnerBonusPercent"]; ok {
goods.GoodsDividend.PartnerBonusPercent = partnerBonusPercent.(float64)
good.GoodDividend.PartnerBonusPercent = partnerBonusPercent.(float64)
}
if salesmanBonusPercent, ok := data["salesmanBonusPercent"]; ok {
goods.GoodsDividend.SalesmanBonusPercent = salesmanBonusPercent.(float64)
good.GoodDividend.SalesmanBonusPercent = salesmanBonusPercent.(float64)
}
if salesmanBonus, ok := data["salesmanBonus"]; ok {
goods.GoodsDividend.SalesmanBonus = salesmanBonus.(float64)
good.GoodDividend.SalesmanBonus = salesmanBonus.(float64)
}
if goodsDividendStatus, ok := data["goodsDividendStatus"]; ok {
goods.GoodsDividendStatus = goodsDividendStatus.(int)
if goodDividendStatus, ok := data["goodDividendStatus"]; ok {
good.GoodDividendStatus = goodDividendStatus.(int)
}
if goodsName, ok := data["goodsName"]; ok {
goods.GoodsName = goodsName.(string)
if goodName, ok := data["goodName"]; ok {
good.GoodName = goodName.(string)
}
if goodsTotalPrice, ok := data["goodsTotalPrice"]; ok {
goods.GoodsTotalPrice = goodsTotalPrice.(float64)
if goodTotalPrice, ok := data["goodTotalPrice"]; ok {
good.GoodTotalPrice = goodTotalPrice.(float64)
}
if remarks, ok := data["remarks"]; ok {
goods.Remarks = remarks.(string)
good.Remarks = remarks.(string)
}
if orderNo, ok := data["orderNo"]; ok {
goods.OrderNo = orderNo.(string)
good.OrderNo = orderNo.(string)
}
if goodsDetail, ok := data["goodsDetail"]; ok {
goods.GoodsDetail = goodsDetail.(string)
if goodDetail, ok := data["goodDetail"]; ok {
good.GoodDetail = goodDetail.(string)
}
if createAt, ok := data["createAt"]; ok {
goods.CreateAt = createAt.(time.Time)
good.CreateAt = createAt.(time.Time)
}
if updateAt, ok := data["updateAt"]; ok {
goods.UpdateAt = updateAt.(time.Time)
good.UpdateAt = updateAt.(time.Time)
}
if deleteAt, ok := data["deleteAt"]; ok {
goods.DeleteAt = deleteAt.(time.Time)
good.DeleteAt = deleteAt.(time.Time)
}
return nil
}
... ...
... ... @@ -38,7 +38,7 @@ type Order struct {
// 发货时间
DeliveryTime time.Time `json:"deliveryTime"`
// 是否关闭订单标志
IsDisable int `json:"isDisable"`
IsDisable bool `json:"isDisable"`
// 订单编号
OrderNo string `json:"orderNo"`
// 订单详情
... ... @@ -48,7 +48,7 @@ type Order struct {
// 订单分红支付状态
OrderDividendStatus int `json:"orderDividendStatus"`
// 订单货品
OrderGoods []*Goods `json:"orderGoods"`
OrderGoods []*Good `json:"orderGoods"`
// 订单数据来源
OrderSource *OrderSource `json:"orderSource"`
// 订单类型(1.实际订单;2.意向订单)
... ... @@ -108,7 +108,7 @@ func (status *UnShippedStatus) Update(order *Order, data map[string]interface{})
order.DeliveryCode = deliveryCode.(string)
}
if isDisable, ok := data["isDisable"]; ok {
order.IsDisable = isDisable.(int)
order.IsDisable = isDisable.(bool)
}
if orderNo, ok := data["orderNo"]; ok {
order.OrderNo = orderNo.(string)
... ... @@ -162,7 +162,7 @@ func (status *UnShippedStatus) Update(order *Order, data map[string]interface{})
order.OrderDividendStatus = orderDividendStatus.(int)
}
if orderGoods, ok := data["orderGoods"]; ok {
order.OrderGoods = orderGoods.([]*Goods)
order.OrderGoods = orderGoods.([]*Good)
}
if dataSourceId, ok := data["dataSourceId"]; ok {
order.OrderSource.DataSourceId = dataSourceId.(int64)
... ... @@ -211,7 +211,7 @@ func (status *UnShippedStatus) Shipping(order *Order) error {
return nil
}
// 退货
// 待发货订单不能退货
func (status *UnShippedStatus) Return(order *Order) error {
return fmt.Errorf("待发货订单不能退货")
}
... ... @@ -222,7 +222,7 @@ func (status *UnShippedStatus) Cancel(order *Order) error {
return nil
}
// 收货
// 待发货订单不能收货
func (status *UnShippedStatus) Receive(order *Order) error {
return fmt.Errorf("待发货订单不能收货")
}
... ... @@ -293,6 +293,7 @@ func (status *ReceivedStatus) Receive(order *Order) error {
// 关闭订单
func (status *ReceivedStatus) Close(order *Order) error {
order.IsDisable = true
order.CurrentStatus = &ClosedStatus{}
return nil
}
... ... @@ -327,6 +328,7 @@ func (status *ReturnedStatus) Receive(order *Order) error {
// 关闭已退货订单
func (status *ReturnedStatus) Close(order *Order) error {
order.IsDisable = true
order.CurrentStatus = &ClosedStatus{}
return nil
}
... ... @@ -361,6 +363,7 @@ func (status *CanceledStatus) Receive(order *Order) error {
// 关闭订单
func (status *CanceledStatus) Close(order *Order) error {
order.IsDisable = true
order.CurrentStatus = &ClosedStatus{}
return nil
}
... ... @@ -425,6 +428,7 @@ func (status *CompletedStatus) Receive(order *Order) error {
// 关闭已完成订单
func (status *CompletedStatus) Close(order *Order) error {
order.IsDisable = true
order.CurrentStatus = &ClosedStatus{}
return nil
}
... ...
... ... @@ -15,7 +15,7 @@ type PartnerInfo struct {
// 合伙时间
CooperateTime time.Time `json:"cooperateTime"`
// 业务员
Salesmans []*Salesman `json:"salesmans"`
Salesmen []*Salesman `json:"salesmen"`
// 合伙人类型
PartnerCategorys []*PartnerCategory `json:"partnerCategorys"`
PartnerCategories []*PartnerCategory `json:"partnerCategories"`
}
... ...
... ... @@ -29,7 +29,7 @@ func init() {
&models.Permission{},
&models.PartnerCategory{},
&models.UserAuth{},
&models.Goods{},
&models.Good{},
&models.Order{},
&models.User{},
&models.Company{},
... ...
... ... @@ -5,30 +5,30 @@ import (
"time"
)
type Goods struct {
tableName string `pg:"goodss,alias:goods"`
type Good struct {
tableName string `pg:"goods,alias:good"`
// 商品id
GoodsId int64
GoodId int64 `pg:",pk"`
// 预定的货品数量
GoodsNum int
GoodNum int
// 商品分红支付信息
GoodsDividend *domain.Dividend
GoodDividend *domain.Dividend
// 商品分红支付状态
GoodsDividendStatus int
GoodDividendStatus int
// 商品名称
GoodsName string
GoodName string
// 商品单价
GoodsTotalPrice float64
GoodTotalPrice float64
// 备注
Remarks string
// 订单编号
OrderNo string
OrderNo string
// 商品详情
GoodsDetail string
GoodDetail string
// 创建时间
CreateAt time.Time
// 更新时间
UpdateAt time.Time
// 删除时间
DeleteAt time.Time
DeleteAt time.Time `pg:",soft_delete"`
}
... ...
... ... @@ -8,7 +8,7 @@ import (
type Order struct {
tableName string `pg:"orders,alias:order"`
// 订单id
OrderId int64
OrderId int64 `pg:",pk"`
// 买家信息
Buyer *domain.BuyerInfo
// 公司Id
... ... @@ -18,7 +18,7 @@ type Order struct {
// 发货单号
DeliveryCode string
// 是否关闭订单标志
IsDisable int
IsDisable bool
// 订单编号
OrderNo string
// 订单详情
... ... @@ -28,7 +28,7 @@ type Order struct {
// 订单分红支付状态
OrderDividendStatus int
// 订单货品
OrderGoods []*domain.Goods
OrderGoods []*domain.Good
// 订单数据来源
OrderSource *domain.OrderSource
// 订单类型(1.实际订单;2.意向订单)
... ... @@ -46,5 +46,5 @@ type Order struct {
// 更新时间
UpdateAt time.Time
// 软删
DeleteAt time.Time
DeleteAt time.Time `pg:",soft_delete"`
}
... ...
... ... @@ -32,5 +32,5 @@ type User struct {
// 更新时间
UpdateAt time.Time
// 删除时间
DeleteAt time.Time
DeleteAt time.Time `pg:",soft_delete"`
}
... ...
package transform
import (
"gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/domain"
"gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/infrastructure/pg/models"
)
func TransformToGoodDomainModelFromPgModels(goodModel *models.Good) (*domain.Good, error) {
return &domain.Good{
GoodId: goodModel.GoodId,
GoodNum: goodModel.GoodNum,
GoodDividend: goodModel.GoodDividend,
GoodDividendStatus: goodModel.GoodDividendStatus,
GoodName: goodModel.GoodName,
GoodTotalPrice: goodModel.GoodTotalPrice,
Remarks: goodModel.Remarks,
OrderNo: goodModel.OrderNo,
GoodDetail: goodModel.GoodDetail,
CreateAt: goodModel.CreateAt,
UpdateAt: goodModel.UpdateAt,
DeleteAt: goodModel.DeleteAt,
}, nil
}
... ...
package transform
import (
"gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/domain"
"gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/infrastructure/pg/models"
)
func TransformToGoodsDomainModelFromPgModels(goodsModel *models.Goods) (*domain.Goods, error) {
return &domain.Goods{
GoodsId: goodsModel.GoodsId,
GoodsNum: goodsModel.GoodsNum,
GoodsDividend: goodsModel.GoodsDividend,
GoodsDividendStatus: goodsModel.GoodsDividendStatus,
GoodsName: goodsModel.GoodsName,
GoodsTotalPrice: goodsModel.GoodsTotalPrice,
Remarks: goodsModel.Remarks,
OrderNo: goodsModel.OrderNo,
GoodsDetail: goodsModel.GoodsDetail,
CreateAt: goodsModel.CreateAt,
UpdateAt: goodsModel.UpdateAt,
DeleteAt: goodsModel.DeleteAt,
}, nil
}
... ... @@ -12,11 +12,11 @@ import (
"gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/infrastructure/pg/transform"
)
type GoodsRepository struct {
type GoodRepository struct {
transactionContext *pgTransaction.TransactionContext
}
func (repository *GoodsRepository) nextIdentify() (int64, error) {
func (repository *GoodRepository) nextIdentify() (int64, error) {
IdWorker, err := snowflake.NewIdWorker(1)
if err != nil {
return 0, err
... ... @@ -24,17 +24,17 @@ func (repository *GoodsRepository) nextIdentify() (int64, error) {
id, err := IdWorker.NextId()
return id, err
}
func (repository *GoodsRepository) Save(goods *domain.Goods) (*domain.Goods, error) {
func (repository *GoodRepository) Save(good *domain.Good) (*domain.Good, error) {
sqlBuildFields := []string{
"goods_id",
"goods_num",
"goods_dividend",
"goods_dividend_status",
"goods_name",
"goods_total_price",
"good_id",
"good_num",
"good_dividend",
"good_dividend_status",
"good_name",
"good_total_price",
"remarks",
"order_no",
"goods_detail",
"good_detail",
"create_at",
"update_at",
"delete_at",
... ... @@ -45,94 +45,94 @@ func (repository *GoodsRepository) Save(goods *domain.Goods) (*domain.Goods, err
updateFields := sqlbuilder.RemoveSqlFields(sqlBuildFields, "goods_id")
updateFieldsSnippet := sqlbuilder.SqlUpdateFieldsSnippet(updateFields)
tx := repository.transactionContext.PgTx
if goods.Identify() == nil {
goodsId, err := repository.nextIdentify()
if good.Identify() == nil {
goodId, err := repository.nextIdentify()
if err != nil {
return goods, err
return good, err
} else {
goods.GoodsId = goodsId
good.GoodId = goodId
}
if _, err := tx.QueryOne(
pg.Scan(
&goods.GoodsId,
&goods.GoodsNum,
&goods.GoodsDividend,
&goods.GoodsDividendStatus,
&goods.GoodsName,
&goods.GoodsTotalPrice,
&goods.Remarks,
&goods.OrderNo,
&goods.GoodsDetail,
&goods.CreateAt,
&goods.UpdateAt,
&goods.DeleteAt,
&good.GoodId,
&good.GoodNum,
&good.GoodDividend,
&good.GoodDividendStatus,
&good.GoodName,
&good.GoodTotalPrice,
&good.Remarks,
&good.OrderNo,
&good.GoodDetail,
&good.CreateAt,
&good.UpdateAt,
&good.DeleteAt,
),
fmt.Sprintf("INSERT INTO goodss (%s) VALUES (%s) RETURNING %s", insertFieldsSnippet, insertPlaceHoldersSnippet, returningFieldsSnippet),
goods.GoodsId,
goods.GoodsNum,
goods.GoodsDividend,
goods.GoodsDividendStatus,
goods.GoodsName,
goods.GoodsTotalPrice,
goods.Remarks,
goods.OrderNo,
goods.GoodsDetail,
goods.CreateAt,
goods.UpdateAt,
goods.DeleteAt,
fmt.Sprintf("INSERT INTO good (%s) VALUES (%s) RETURNING %s", insertFieldsSnippet, insertPlaceHoldersSnippet, returningFieldsSnippet),
good.GoodId,
good.GoodNum,
good.GoodDividend,
good.GoodDividendStatus,
good.GoodName,
good.GoodTotalPrice,
good.Remarks,
good.OrderNo,
good.GoodDetail,
good.CreateAt,
good.UpdateAt,
good.DeleteAt,
); err != nil {
return goods, err
return good, err
}
} else {
if _, err := tx.QueryOne(
pg.Scan(
&goods.GoodsId,
&goods.GoodsNum,
&goods.GoodsDividend,
&goods.GoodsDividendStatus,
&goods.GoodsName,
&goods.GoodsTotalPrice,
&goods.Remarks,
&goods.OrderNo,
&goods.GoodsDetail,
&goods.CreateAt,
&goods.UpdateAt,
&goods.DeleteAt,
&good.GoodId,
&good.GoodNum,
&good.GoodDividend,
&good.GoodDividendStatus,
&good.GoodName,
&good.GoodTotalPrice,
&good.Remarks,
&good.OrderNo,
&good.GoodDetail,
&good.CreateAt,
&good.UpdateAt,
&good.DeleteAt,
),
fmt.Sprintf("UPDATE goodss SET %s WHERE goods_id=? RETURNING %s", updateFieldsSnippet, returningFieldsSnippet),
goods.GoodsId,
goods.GoodsNum,
goods.GoodsDividend,
goods.GoodsDividendStatus,
goods.GoodsName,
goods.GoodsTotalPrice,
goods.Remarks,
goods.OrderNo,
goods.GoodsDetail,
goods.CreateAt,
goods.UpdateAt,
goods.DeleteAt,
goods.Identify(),
fmt.Sprintf("UPDATE good SET %s WHERE goods_id=? RETURNING %s", updateFieldsSnippet, returningFieldsSnippet),
good.GoodId,
good.GoodNum,
good.GoodDividend,
good.GoodDividendStatus,
good.GoodName,
good.GoodTotalPrice,
good.Remarks,
good.OrderNo,
good.GoodDetail,
good.CreateAt,
good.UpdateAt,
good.DeleteAt,
good.Identify(),
); err != nil {
return goods, err
return good, err
}
}
return goods, nil
return good, nil
}
func (repository *GoodsRepository) Remove(goods *domain.Goods) (*domain.Goods, error) {
func (repository *GoodRepository) Remove(good *domain.Good) (*domain.Good, error) {
tx := repository.transactionContext.PgTx
goodsModel := new(models.Goods)
goodsModel.GoodsId = goods.Identify().(int64)
if _, err := tx.Model(goodsModel).WherePK().Delete(); err != nil {
return goods, err
goodModel := new(models.Good)
goodModel.GoodId = good.Identify().(int64)
if _, err := tx.Model(goodModel).WherePK().Delete(); err != nil {
return good, err
}
return goods, nil
return good, nil
}
func (repository *GoodsRepository) FindOne(queryOptions map[string]interface{}) (*domain.Goods, error) {
func (repository *GoodRepository) FindOne(queryOptions map[string]interface{}) (*domain.Good, error) {
tx := repository.transactionContext.PgTx
goodsModel := new(models.Goods)
query := sqlbuilder.BuildQuery(tx.Model(goodsModel), queryOptions)
query.SetWhereByQueryOption("goods.goods_id = ?", "goodsId")
goodModel := new(models.Good)
query := sqlbuilder.BuildQuery(tx.Model(goodModel), queryOptions)
query.SetWhereByQueryOption("good.goods_id = ?", "goodsId")
if err := query.First(); err != nil {
if err.Error() == "pg: no rows in result set" {
return nil, fmt.Errorf("没有此资源")
... ... @@ -140,37 +140,37 @@ func (repository *GoodsRepository) FindOne(queryOptions map[string]interface{})
return nil, err
}
}
if goodsModel.GoodsId == 0 {
if goodModel.GoodId == 0 {
return nil, nil
} else {
return transform.TransformToGoodsDomainModelFromPgModels(goodsModel)
return transform.TransformToGoodDomainModelFromPgModels(goodModel)
}
}
func (repository *GoodsRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.Goods, error) {
func (repository *GoodRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.Good, error) {
tx := repository.transactionContext.PgTx
var goodsModels []*models.Goods
goodss := make([]*domain.Goods, 0)
query := sqlbuilder.BuildQuery(tx.Model(&goodsModels), queryOptions)
var goodModels []*models.Good
goods := make([]*domain.Good, 0)
query := sqlbuilder.BuildQuery(tx.Model(&goodModels), queryOptions)
query.SetOffsetAndLimit(20)
query.SetOrderDirect("goods_id", "DESC")
if count, err := query.SelectAndCount(); err != nil {
return 0, goodss, err
return 0, goods, err
} else {
for _, goodsModel := range goodsModels {
if goods, err := transform.TransformToGoodsDomainModelFromPgModels(goodsModel); err != nil {
return 0, goodss, err
for _, goodModel := range goodModels {
if good, err := transform.TransformToGoodDomainModelFromPgModels(goodModel); err != nil {
return 0, goods, err
} else {
goodss = append(goodss, goods)
goods = append(goods, good)
}
}
return int64(count), goodss, nil
return int64(count), goods, nil
}
}
func NewGoodsRepository(transactionContext *pgTransaction.TransactionContext) (*GoodsRepository, error) {
func NewGoodsRepository(transactionContext *pgTransaction.TransactionContext) (*GoodRepository, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
} else {
return &GoodsRepository{
return &GoodRepository{
transactionContext: transactionContext,
}, nil
}
... ...
... ... @@ -14,7 +14,7 @@ type OrderController struct {
func (controller *OrderController) CreateOrder() {
orderService := service.NewOrderService(nil)
createOrderCommand := &command.CreateOrderCommand{}
controller.Unmarshal(createOrderCommand)
_ = controller.Unmarshal(createOrderCommand)
data, err := orderService.CreateOrder(createOrderCommand)
controller.Response(data, err)
}
... ...
... ... @@ -16,12 +16,13 @@ var _ = FDescribe("创建订单增删改查", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
body := map[string]interface{}{
"orderNo": "string",
"companyId": "int64",
"companyId": 1,
"buyerName": "string",
"contactInfo": "string",
"shippingAddress": "string",
"orderNum": "int64",
"totalPrice": "float64",
"orderNum": 10,
"totalPrice": 10,
"partnerId": "1213",
}
httpExpect.POST("/orders/").
WithJSON(body).
... ...
... ... @@ -10,14 +10,21 @@ import (
pG "gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/infrastructure/pg"
)
var _ = Describe("返回订单增删改查", func() {
var _ = FDescribe("返回订单增删改查", func() {
var orderId int64
BeforeEach(func() {
_, err := pG.DB.QueryOne(
// 新增合伙人测试数据
_, err1 := pG.DB.QueryOne(
pg.Scan(),
"",
"")
Expect(err1).NotTo(HaveOccurred())
// 新增订单测试数据
_, err2 := pG.DB.QueryOne(
pg.Scan(&orderId),
"INSERT INTO orders (order_id, buyer, company_id, partner_id, delivery_code, is_disable, order_no, order_detail, order_dividend, order_dividend_status, order_goods, order_source, order_type, order_status, total_price, region_info, remarks, create_at, update_at, delete_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING order_id",
"testOrderId", "testBuyer", "testCompanyId", "testPartnerId", "testDeliveryCode", "testIsDisable", "testOrderNo", "testOrderDetail", "testOrderDividend", "testOrderDividendStatus", "testOrderGoods", "testOrderSource", "testOrderType", "testOrderStatus", "testTotalPrice", "testRegionInfo", "testRemarks", "testCreateAt", "testUpdateAt", "testDeleteAt")
Expect(err).NotTo(HaveOccurred())
"INSERT INTO orders ( buyer, company_id, partner_id, delivery_code, is_disable, order_no, order_detail, order_dividend, order_dividend_status, order_goods, order_source, order_type, order_status, total_price, region_info, remarks, create_at, update_at, delete_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING order_id",
"testBuyer", 1, "testPartnerId", "testDeliveryCode", false, "testOrderNo", "testOrderDetail", "testOrderDividend", "testOrderDividendStatus", "testOrderGoods", "testOrderSource", "testOrderType", "testOrderStatus", "testTotalPrice", "testRegionInfo", "testRemarks", "testCreateAt", "testUpdateAt", "testDeleteAt")
Expect(err2).NotTo(HaveOccurred())
})
Describe("根据orderId参数返回订单实体", func() {
Context("传入有效的orderId", func() {
... ...