作者 陈志颖

Merge branch 'feat/order-domain' into 6-order-domain-service

正在显示 66 个修改的文件 包含 1420 行增加326 行删除
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: companyAdmin
description: 公司管理员信息值对象
attributes:
- ref: userAccount
required: true
- ref: userName
required: true
\ No newline at end of file
... ...
... ... @@ -23,4 +23,4 @@ metadata:
- name: admin
description: 公司主管理员
type:
schema: userInfo
\ No newline at end of file
schema: companyAdmin
\ No newline at end of file
... ...
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
... ... @@ -13,13 +13,11 @@ metadata:
required: true
- ref: remarks
required: false
- name: adminId
description: 公司主管理员Id
type:
primitive: int64
result:
- ref: count
- ref: userAccount
required: true
- ref: userName
required: true
result:
- name: company
type:
schema: company
... ...
... ... @@ -8,8 +8,6 @@ metadata:
- ref: companyId
required: true
result:
- ref: count
required: true
- name: company
type:
schema: company
... ...
... ... @@ -7,7 +7,9 @@ metadata:
payload:
- ref: companyId
required: true
- ref: userId
- ref: userAccount
required: true
- ref: userName
required: true
result:
- name: company
... ...
... ... @@ -15,10 +15,9 @@ metadata:
required: false
- ref: remarks
required: false
- name: adminId
description: 公司主管理员Id
type:
primitive: int64
- ref: userAccount
required: false
- ref: userName
required: false
result:
- name: company
... ...
{"/Users/steve/go/src/partner01/pkg/port/beego":1617694648836700729}
\ No newline at end of file
{"/Users/steve/go/src/partner01/pkg/port/beego":1617954047976424824}
\ No newline at end of file
... ...
package command
import (
"fmt"
"github.com/beego/beego/v2/core/validation"
)
type ConvertCompanyStatusCommand struct {
// 公司Id
CompanyId int64 `json:"companyId" valid:"Required"`
// 状态 1正常 2禁用
Status int64 `json:"status" valid:"Required"`
}
func (convertCompanyStatusCommand *ConvertCompanyStatusCommand) Valid(validation *validation.Validation) {
// _ = validation.SetError("CustomValid", "未实现的自定义认证")
}
func (convertCompanyStatusCommand *ConvertCompanyStatusCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(convertCompanyStatusCommand)
if err != nil {
return err
}
if !b {
for _, validErr := range valid.Errors {
return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
}
}
return nil
}
... ...
package command
import (
"fmt"
"github.com/beego/beego/v2/core/validation"
)
type CreateCompanyCommand struct {
// 公司名称
Name string `json:"name" valid:"Required"`
// 公司简称
Abbreviation string `json:"abbreviation" valid:"Required"`
// 状态 1正常 2禁用
Status int64 `json:"status" valid:"Required"`
// 备注
Remarks string `json:"remarks,omitempty"`
// 公司主管理员账号
UserAccount string `json:"userAccount" valid:"Required"`
// 公司主管理员姓名
UserName string `json:"userName" valid:"Required"`
}
func (createCompanyCommand *CreateCompanyCommand) Valid(validation *validation.Validation) {
// _ = validation.SetError("CustomValid", "未实现的自定义认证")
}
func (createCompanyCommand *CreateCompanyCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(createCompanyCommand)
if err != nil {
return err
}
if !b {
for _, validErr := range valid.Errors {
return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
}
}
return nil
}
... ...
package command
import (
"fmt"
"github.com/beego/beego/v2/core/validation"
)
type RemoveCompanyCommand struct {
// 公司Id
CompanyId int64 `json:"companyId" valid:"Required"`
}
func (removeCompanyCommand *RemoveCompanyCommand) Valid(validation *validation.Validation) {
// _ = validation.SetError("CustomValid", "未实现的自定义认证")
}
func (removeCompanyCommand *RemoveCompanyCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(removeCompanyCommand)
if err != nil {
return err
}
if !b {
for _, validErr := range valid.Errors {
return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
}
}
return nil
}
... ...
package command
import (
"fmt"
"github.com/beego/beego/v2/core/validation"
)
type SetCompanyAdminCommand struct {
// 公司Id
CompanyId int64 `json:"companyId" valid:"Required"`
// 公司主管理员账号
UserAccount string `json:"userAccount" valid:"Required"`
// 公司主管理员姓名
UserName string `json:"userName" valid:"Required"`
}
func (setCompanyAdminCommand *SetCompanyAdminCommand) Valid(validation *validation.Validation) {
// _ = validation.SetError("CustomValid", "未实现的自定义认证")
}
func (setCompanyAdminCommand *SetCompanyAdminCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(setCompanyAdminCommand)
if err != nil {
return err
}
if !b {
for _, validErr := range valid.Errors {
return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
}
}
return nil
}
... ...
package command
import (
"fmt"
"github.com/beego/beego/v2/core/validation"
)
type UpdateCompanyCommand struct {
// 公司Id
CompanyId int64 `json:"companyId" valid:"Required"`
// 公司名称
Name string `json:"name,omitempty"`
// 公司简称
Abbreviation string `json:"abbreviation,omitempty"`
// 状态 1正常 2禁用
Status int64 `json:"status,omitempty"`
// 备注
Remarks string `json:"remarks,omitempty"`
// 公司主管理员账号
UserAccount string `json:"userAccount,omitempty"`
// 公司主管理员姓名
UserName string `json:"userName,omitempty"`
}
func (updateCompanyCommand *UpdateCompanyCommand) Valid(validation *validation.Validation) {
// _ = validation.SetError("CustomValid", "未实现的自定义认证")
}
func (updateCompanyCommand *UpdateCompanyCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(updateCompanyCommand)
if err != nil {
return err
}
if !b {
for _, validErr := range valid.Errors {
return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
}
}
return nil
}
... ...
package query
import (
"fmt"
"github.com/beego/beego/v2/core/validation"
)
type GetCompanyQuery struct {
// 公司Id
CompanyId int64 `json:"companyId" valid:"Required"`
}
func (getCompanyQuery *GetCompanyQuery) Valid(validation *validation.Validation) {
// _ = validation.SetError("CustomValid", "未实现的自定义认证")
}
func (getCompanyQuery *GetCompanyQuery) ValidateQuery() error {
valid := validation.Validation{}
b, err := valid.Valid(getCompanyQuery)
if err != nil {
return err
}
if !b {
for _, validErr := range valid.Errors {
return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
}
}
return nil
}
... ...
package query
import (
"fmt"
"github.com/beego/beego/v2/core/validation"
)
type ListCompanyQuery struct {
// 查询偏离量
Offset int `json:"offset" valid:"Required"`
// 查询限制
Limit int `json:"limit" valid:"Required"`
}
func (listCompanyQuery *ListCompanyQuery) Valid(validation *validation.Validation) {
// _ = validation.SetError("CustomValid", "未实现的自定义认证")
}
func (listCompanyQuery *ListCompanyQuery) ValidateQuery() error {
valid := validation.Validation{}
b, err := valid.Valid(listCompanyQuery)
if err != nil {
return err
}
if !b {
for _, validErr := range valid.Errors {
return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
}
}
return nil
}
... ...
package service
import (
"fmt"
"github.com/linmadan/egglib-go/core/application"
"github.com/linmadan/egglib-go/utils/tool_funs"
"gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/application/company/command"
"gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/application/company/query"
"gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/application/factory"
"gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/domain"
"time"
)
// 公司服务
type CompanyService struct {
}
// 公司状态转换 禁用、启用
func (companyService *CompanyService) ConvertCompanyStatus(convertCompanyStatusCommand *command.ConvertCompanyStatusCommand) (interface{}, error) {
if err := convertCompanyStatusCommand.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
var companyRepository domain.CompanyRepository
if value, err := factory.CreateCompanyRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
companyRepository = value
}
company, err := companyRepository.FindOne(map[string]interface{}{"companyId": convertCompanyStatusCommand.CompanyId})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if company == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(convertCompanyStatusCommand.CompanyId)))
}
if err := company.Update(tool_funs.SimpleStructToMap(convertCompanyStatusCommand)); err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
if company, err := companyRepository.Save(company); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return company, nil
}
}
// 创建
func (companyService *CompanyService) CreateCompany(createCompanyCommand *command.CreateCompanyCommand) (interface{}, error) {
if err := createCompanyCommand.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
newCompany := &domain.Company{
CompanyInfo: &domain.CompanyInfo{
Name: createCompanyCommand.Name, // 公司名称
Abbreviation: createCompanyCommand.Abbreviation, // 公司简称
Logo: "", // 公司logo
Phone: "", // 公司联系电话
Status: createCompanyCommand.Status, // 状态 1正常 2禁用
Remarks: createCompanyCommand.Remarks, // 备注
Enable: 1, // 是否有效【1:有效】【2:无效】
Admin: &domain.CompanyAdmin{
UserAccount: createCompanyCommand.UserAccount, // 用户手机号
UserName: createCompanyCommand.UserName, // 用户名称
}, // 公司主管理员
},
CreateAt: time.Now(),
UpdateAt: time.Now(),
}
var companyRepository domain.CompanyRepository
if value, err := factory.CreateCompanyRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
companyRepository = value
}
if company, err := companyRepository.Save(newCompany); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
// todo 新增公司管理员
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return company, nil
}
}
// 返回
func (companyService *CompanyService) GetCompany(getCompanyQuery *query.GetCompanyQuery) (interface{}, error) {
if err := getCompanyQuery.ValidateQuery(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
var companyRepository domain.CompanyRepository
if value, err := factory.CreateCompanyRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
companyRepository = value
}
company, err := companyRepository.FindOne(map[string]interface{}{"companyId": getCompanyQuery.CompanyId})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if company == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(getCompanyQuery.CompanyId)))
} else {
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return company, nil
}
}
// 返回列表
func (companyService *CompanyService) ListCompany(listCompanyQuery *query.ListCompanyQuery) (interface{}, error) {
if err := listCompanyQuery.ValidateQuery(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
var companyRepository domain.CompanyRepository
if value, err := factory.CreateCompanyRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
companyRepository = value
}
if count, companies, err := companyRepository.Find(tool_funs.SimpleStructToMap(listCompanyQuery)); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return map[string]interface{}{
"count": count,
"companies": companies,
}, nil
}
}
// 移除
func (companyService *CompanyService) RemoveCompany(removeCompanyCommand *command.RemoveCompanyCommand) (interface{}, error) {
if err := removeCompanyCommand.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
var companyRepository domain.CompanyRepository
if value, err := factory.CreateCompanyRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
companyRepository = value
}
company, err := companyRepository.FindOne(map[string]interface{}{"companyId": removeCompanyCommand.CompanyId})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if company == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(removeCompanyCommand.CompanyId)))
}
if company, err := companyRepository.Remove(company); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return company, nil
}
}
// 设置公司管理员
func (companyService *CompanyService) SetCompanyAdmin(setCompanyAdminCommand *command.SetCompanyAdminCommand) (interface{}, error) {
if err := setCompanyAdminCommand.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
var companyRepository domain.CompanyRepository
if value, err := factory.CreateCompanyRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
companyRepository = value
}
company, err := companyRepository.FindOne(map[string]interface{}{"companyId": setCompanyAdminCommand.CompanyId})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if company == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(setCompanyAdminCommand.CompanyId)))
}
newCompanyAdmin := &domain.CompanyAdmin{
UserAccount: setCompanyAdminCommand.UserAccount, // 用户手机号
UserName: setCompanyAdminCommand.UserName, // 用户名称
}
// 更改公司管理员信息
if err := company.SetCompanyAdmin(newCompanyAdmin); err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
if company, err := companyRepository.Save(company); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
// todo 更改公司管理员
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return company, nil
}
}
// 更新
func (companyService *CompanyService) UpdateCompany(updateCompanyCommand *command.UpdateCompanyCommand) (interface{}, error) {
if err := updateCompanyCommand.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
var companyRepository domain.CompanyRepository
if value, err := factory.CreateCompanyRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
companyRepository = value
}
company, err := companyRepository.FindOne(map[string]interface{}{"companyId": updateCompanyCommand.CompanyId})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if company == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateCompanyCommand.CompanyId)))
}
if err := company.Update(tool_funs.SimpleStructToMap(updateCompanyCommand)); err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
// 更改公司管理员信息
if updateCompanyCommand.UserAccount != "" || updateCompanyCommand.UserName != "" {
companyAdmin := company.CompanyInfo.Admin
if updateCompanyCommand.UserAccount != "" {
companyAdmin.UserAccount = updateCompanyCommand.UserAccount // 用户手机号
}
if updateCompanyCommand.UserName != "" {
companyAdmin.UserName = updateCompanyCommand.UserName // 用户名称
}
if err := company.SetCompanyAdmin(companyAdmin); err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
// todo 更改公司管理员
}
if company, err := companyRepository.Save(company); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return company, nil
}
}
func NewCompanyService(options map[string]interface{}) *CompanyService {
newCompanyService := &CompanyService{}
return newCompanyService
}
... ...
... ... @@ -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"`
}
... ...
... ... @@ -34,9 +34,6 @@ func (company *Company) Update(data map[string]interface{}) error {
if companyId, ok := data["companyId"]; ok {
company.CompanyId = companyId.(int64)
}
if companyId, ok := data["companyId"]; ok {
company.CompanyInfo.CompanyId = companyId.(int64)
}
if name, ok := data["name"]; ok {
company.CompanyInfo.Name = name.(string)
}
... ... @@ -58,5 +55,28 @@ func (company *Company) Update(data map[string]interface{}) error {
if enable, ok := data["enable"]; ok {
company.CompanyInfo.Enable = enable.(int64)
}
if userAccount, ok := data["userAccount"]; ok {
company.CompanyInfo.Admin.UserAccount = userAccount.(string)
}
if userName, ok := data["userName"]; ok {
company.CompanyInfo.Admin.UserName = userName.(string)
}
if createAt, ok := data["createAt"]; ok {
company.CreateAt = createAt.(time.Time)
}
if updateAt, ok := data["updateAt"]; ok {
company.UpdateAt = updateAt.(time.Time)
}
if deleteAt, ok := data["deleteAt"]; ok {
company.DeleteAt = deleteAt.(time.Time)
}
return nil
}
// 更改公司管理员信息
func (company *Company) SetCompanyAdmin(admin *CompanyAdmin) error {
company.CompanyInfo.Admin = admin
return nil
}
... ...
... ... @@ -2,22 +2,18 @@ package domain
// 公司信息
type CompanyInfo struct {
// 公司Id
CompanyId int64 `json:"companyId"`
// 公司名称
Name string `json:"name"`
// 公司简称
Abbreviation string `json:"abbreviation"`
// 公司logo
Logo string `json:"logo"`
// 公司联系电话
Phone string `json:"phone"`
// 状态 1正常 2禁用
Status int64 `json:"status"`
// 备注
Remarks string `json:"remarks"`
// 是否有效【1:有效】【2:无效】
Enable int64 `json:"enable"`
// 公司主管理员
Admin *UserInfo `json:"admin"`
Name string `json:"name"` // 公司名称
Abbreviation string `json:"abbreviation"` // 公司简称
Logo string `json:"logo"` // 公司logo
Phone string `json:"phone"` // 公司联系电话
Status int64 `json:"status"` // 状态 1正常 2禁用
Remarks string `json:"remarks"` // 备注
Enable int64 `json:"enable"` // 是否有效【1:有效】【2:无效】
Admin *CompanyAdmin `json:"admin"` // 公司主管理员
}
// 公司管理员信息值对象
type CompanyAdmin struct {
UserAccount string `json:"userPhone"` // 用户手机号
UserName string `json:"userName"` // 用户名称
}
... ...
... ... @@ -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"`
// 商品详情
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
}
... ...
... ... @@ -14,10 +14,11 @@ const (
// 订单状态
const (
ORDER_STATUS_UNSHIPPED = iota + 1 // 待发货
ORDER_STATUS_TRANSIT // 待收货(运输中)
ORDER_STATUS_SHIPPING // 已发货
ORDER_STATUS_PART_SHIPPING // 部分发货
ORDER_STATUS_RECEIVED // 已收货
ORDER_STATUS_RETURN // 退换货
ORDER_STATUS_CANCELED // 已取消(关闭)
ORDER_STATUS_CANCELED // 已取消
ORDER_STATUS_COMPLETED // 已完成
ORDER_STATUS_CLOSED // 已关闭
)
... ... @@ -37,7 +38,7 @@ type Order struct {
// 发货时间
DeliveryTime time.Time `json:"deliveryTime"`
// 是否关闭订单标志
IsDisable int `json:"isDisable"`
IsDisable bool `json:"isDisable"`
// 订单编号
OrderNo string `json:"orderNo"`
// 订单详情
... ... @@ -47,7 +48,7 @@ type Order struct {
// 订单分红支付状态
OrderDividendStatus int `json:"orderDividendStatus"`
// 订单货品
OrderGoods []*Goods `json:"orderGoods"`
OrderGoods []*Good `json:"orderGoods"`
// 订单数据来源
OrderSource *OrderSource `json:"orderSource"`
// 订单类型(1.实际订单;2.意向订单)
... ... @@ -73,8 +74,8 @@ type Order struct {
// 订单状态机
type OrderStatus interface {
Update(order *Order, data map[string]interface{}) error // 更新订单
Shipping(order *Order) error // 发货
Return(order *Order) error // 退换/货
Shipping(order *Order) error // 发货(全部发货,部分发货)
Return(order *Order) error // 退换货
Cancel(order *Order) error // 取消订单
Receive(order *Order) error // 收货
Close(order *Order) error // 关闭订单
... ... @@ -107,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)
... ... @@ -161,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)
... ... @@ -204,13 +205,13 @@ func (status *UnShippedStatus) Shipping(order *Order) error {
currentTime := time.Now()
order.DeliveryTime = currentTime
if order.OrderType == ORDER_TYPE_INTENTION {
order.OrderStatus = ORDER_STATUS_TRANSIT
order.OrderStatus = ORDER_STATUS_SHIPPING
order.CurrentStatus = &TransitStatus{}
}
return nil
}
// 退货
// 待发货订单不能退货
func (status *UnShippedStatus) Return(order *Order) error {
return fmt.Errorf("待发货订单不能退货")
}
... ... @@ -221,7 +222,7 @@ func (status *UnShippedStatus) Cancel(order *Order) error {
return nil
}
// 收货
// 待发货订单不能收货
func (status *UnShippedStatus) Receive(order *Order) error {
return fmt.Errorf("待发货订单不能收货")
}
... ... @@ -234,11 +235,6 @@ func (status *TransitStatus) Shipping(order *Order) error {
return fmt.Errorf("待收货订单不能重复发货")
}
// 待收货订单不能关闭
func (status *TransitStatus) Close(order *Order) error {
return fmt.Errorf("待收货订单不能关闭")
}
// 待收货订单不允许编辑
func (status *TransitStatus) Update(order *Order, data map[string]interface{}) error {
return fmt.Errorf("已发货订单不允许编辑")
... ... @@ -261,10 +257,15 @@ func (status *TransitStatus) Receive(order *Order) error {
return nil
}
// 待收货订单不能关闭
func (status *TransitStatus) Close(order *Order) error {
return fmt.Errorf("待收货订单不能关闭")
}
// 收货状态
type ReceivedStatus struct{}
// 编辑订单
// 已收货订单不能编辑
func (status *ReceivedStatus) Update(order *Order, data map[string]interface{}) error {
return fmt.Errorf("已收货订单不能编辑")
}
... ... @@ -292,6 +293,8 @@ func (status *ReceivedStatus) Receive(order *Order) error {
// 关闭订单
func (status *ReceivedStatus) Close(order *Order) error {
order.IsDisable = true
order.CurrentStatus = &ClosedStatus{}
return nil
}
... ... @@ -323,9 +326,10 @@ func (status *ReturnedStatus) Receive(order *Order) error {
return fmt.Errorf("已退货订单不能收货")
}
// 关闭订单
// 关闭已退货订单
func (status *ReturnedStatus) Close(order *Order) error {
order.IsDisable = true
order.CurrentStatus = &ClosedStatus{}
return nil
}
... ... @@ -359,6 +363,8 @@ func (status *CanceledStatus) Receive(order *Order) error {
// 关闭订单
func (status *CanceledStatus) Close(order *Order) error {
order.IsDisable = true
order.CurrentStatus = &ClosedStatus{}
return nil
}
... ... @@ -367,7 +373,36 @@ type CompletedStatus struct{}
// 编辑已完成订单分红
func (status *CompletedStatus) Update(order *Order, data map[string]interface{}) error {
if planBonus, ok := data["planBonus"]; ok {
order.OrderDividend.PlanBonus = planBonus.(float64)
}
if useBonus, ok := data["useBonus"]; ok {
order.OrderDividend.UseBonus = useBonus.(float64)
}
if bonusHas, ok := data["bonusHas"]; ok {
order.OrderDividend.BonusHas = bonusHas.(float64)
}
if bonusNot, ok := data["bonusNot"]; ok {
order.OrderDividend.BonusNot = bonusNot.(float64)
}
if bonusExpense, ok := data["bonusExpense"]; ok {
order.OrderDividend.BonusExpense = bonusExpense.(float64)
}
if bonusStatus, ok := data["bonusStatus"]; ok {
order.OrderDividend.BonusStatus = bonusStatus.(int)
}
if partnerBonusPercent, ok := data["partnerBonusPercent"]; ok {
order.OrderDividend.PartnerBonusPercent = partnerBonusPercent.(float64)
}
if salesmanBonusPercent, ok := data["salesmanBonusPercent"]; ok {
order.OrderDividend.SalesmanBonusPercent = salesmanBonusPercent.(float64)
}
if salesmanBonus, ok := data["salesmanBonus"]; ok {
order.OrderDividend.SalesmanBonus = salesmanBonus.(float64)
}
if orderDividendStatus, ok := data["orderDividendStatus"]; ok {
order.OrderDividendStatus = orderDividendStatus.(int)
}
return nil
}
... ... @@ -393,12 +428,47 @@ func (status *CompletedStatus) Receive(order *Order) error {
// 关闭已完成订单
func (status *CompletedStatus) Close(order *Order) error {
order.IsDisable = true
order.CurrentStatus = &ClosedStatus{}
return nil
}
// 关闭状态
type ClosedStatus struct{}
// 已关闭订单不能进行编辑
func (status *ClosedStatus) Update(order *Order, data map[string]interface{}) error {
return fmt.Errorf("已关闭订单不能进行编辑")
}
// 已关闭订单不能发货
func (status *ClosedStatus) Shipping(order *Order) error {
return fmt.Errorf("已关闭订单不能发货")
}
// 已关闭订单不能退货
func (status *ClosedStatus) Return(order *Order) error {
return fmt.Errorf("已关闭订单不能退货")
}
// 已关闭订单不能取消
func (status *ClosedStatus) Cancel(order *Order) error {
return fmt.Errorf("已关闭订单不能取消")
}
// 已关闭订单不能收货
func (status *ClosedStatus) Receive(order *Order) error {
return fmt.Errorf("已关闭订单不能收货")
}
// 已关闭订单不能再次关闭
func (status *ClosedStatus) Close(order *Order) error {
return fmt.Errorf("已关闭订单不能再次关闭")
}
// 订单仓储
type OrderRepository interface {
Save(order *Order) (*Order, error) // 下单/编辑订单
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)
... ...
... ... @@ -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"`
}
... ...
... ... @@ -27,7 +27,7 @@ func init() {
&models.Permission{},
&models.PartnerCategory{},
&models.UserAuth{},
&models.Goods{},
&models.Good{},
&models.Order{},
&models.User{},
&models.Company{},
... ...
... ... @@ -6,7 +6,7 @@ import (
)
type Company struct {
tableName string `pg:"companys,alias:company"`
tableName string `pg:"companies,alias:company"`
// 公司Id
CompanyId int64 `pg:",pk"`
// 公司信息
... ... @@ -16,5 +16,5 @@ type Company struct {
// 更新时间
UpdateAt time.Time
// 删除时间
DeleteAt time.Time
DeleteAt time.Time `pg:",soft_delete"`
}
... ...
... ... @@ -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
// 商品详情
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"`
}
... ...
... ... @@ -30,5 +30,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
}
... ... @@ -30,7 +30,6 @@ func (repository *CompanyRepository) Save(company *domain.Company) (*domain.Comp
"company_info",
"create_at",
"update_at",
"delete_at",
}
insertFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlBuildFields)
insertPlaceHoldersSnippet := sqlbuilder.SqlPlaceHoldersSnippet(sqlBuildFields)
... ... @@ -53,7 +52,9 @@ func (repository *CompanyRepository) Save(company *domain.Company) (*domain.Comp
&company.UpdateAt,
&company.DeleteAt,
),
fmt.Sprintf("INSERT INTO companys (%s) VALUES (%s) RETURNING %s", insertFieldsSnippet, insertPlaceHoldersSnippet, returningFieldsSnippet),
fmt.Sprintf("INSERT INTO companies (%s) VALUES (%s) RETURNING %s", insertFieldsSnippet, insertPlaceHoldersSnippet, returningFieldsSnippet),
company.CompanyId,
company.CompanyInfo,
company.CreateAt,
... ... @@ -71,8 +72,9 @@ func (repository *CompanyRepository) Save(company *domain.Company) (*domain.Comp
&company.UpdateAt,
&company.DeleteAt,
),
fmt.Sprintf("UPDATE companys SET %s WHERE company_id=? RETURNING %s", updateFieldsSnippet, returningFieldsSnippet),
company.CompanyId,
fmt.Sprintf("UPDATE companies SET %s WHERE company_id=? RETURNING %s", updateFieldsSnippet, returningFieldsSnippet),
company.CompanyInfo,
company.CreateAt,
company.UpdateAt,
... ... @@ -115,21 +117,23 @@ func (repository *CompanyRepository) FindOne(queryOptions map[string]interface{}
func (repository *CompanyRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.Company, error) {
tx := repository.transactionContext.PgTx
var companyModels []*models.Company
companys := make([]*domain.Company, 0)
companies := make([]*domain.Company, 0)
query := sqlbuilder.BuildQuery(tx.Model(&companyModels), queryOptions)
query.SetOffsetAndLimit(20)
query.SetOrderDirect("company_id", "DESC")
if count, err := query.SelectAndCount(); err != nil {
return 0, companys, err
return 0, companies, err
} else {
for _, companyModel := range companyModels {
if company, err := transform.TransformToCompanyDomainModelFromPgModels(companyModel); err != nil {
return 0, companys, err
return 0, companies, err
} else {
companys = append(companys, company)
companies = append(companies, company)
}
}
return int64(count), companys, nil
return int64(count), companies, nil
}
}
func NewCompanyRepository(transactionContext *pgTransaction.TransactionContext) (*CompanyRepository, error) {
... ...
... ... @@ -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
}
... ...
package controllers
import (
"github.com/linmadan/egglib-go/web/beego"
"gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/application/company/command"
"gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/application/company/query"
"gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/application/company/service"
)
type CompanyController struct {
beego.BaseController
}
func (controller *CompanyController) CreateCompany() {
companyService := service.NewCompanyService(nil)
createCompanyCommand := &command.CreateCompanyCommand{}
controller.Unmarshal(createCompanyCommand)
data, err := companyService.CreateCompany(createCompanyCommand)
controller.Response(data, err)
}
func (controller *CompanyController) UpdateCompany() {
companyService := service.NewCompanyService(nil)
updateCompanyCommand := &command.UpdateCompanyCommand{}
controller.Unmarshal(updateCompanyCommand)
companyId, _ := controller.GetInt64(":companyId")
updateCompanyCommand.CompanyId = companyId
data, err := companyService.UpdateCompany(updateCompanyCommand)
controller.Response(data, err)
}
func (controller *CompanyController) GetCompany() {
companyService := service.NewCompanyService(nil)
getCompanyQuery := &query.GetCompanyQuery{}
companyId, _ := controller.GetInt64(":companyId")
getCompanyQuery.CompanyId = companyId
data, err := companyService.GetCompany(getCompanyQuery)
controller.Response(data, err)
}
func (controller *CompanyController) RemoveCompany() {
companyService := service.NewCompanyService(nil)
removeCompanyCommand := &command.RemoveCompanyCommand{}
controller.Unmarshal(removeCompanyCommand)
companyId, _ := controller.GetInt64(":companyId")
removeCompanyCommand.CompanyId = companyId
data, err := companyService.RemoveCompany(removeCompanyCommand)
controller.Response(data, err)
}
func (controller *CompanyController) ListCompany() {
companyService := service.NewCompanyService(nil)
listCompanyQuery := &query.ListCompanyQuery{}
offset, _ := controller.GetInt("offset")
listCompanyQuery.Offset = offset
limit, _ := controller.GetInt("limit")
listCompanyQuery.Limit = limit
data, err := companyService.ListCompany(listCompanyQuery)
controller.Response(data, err)
}
func (controller *CompanyController) ConvertCompanyStatus() {
companyService := service.NewCompanyService(nil)
convertCompanyStatusCommand := &command.ConvertCompanyStatusCommand{}
controller.Unmarshal(convertCompanyStatusCommand)
data, err := companyService.ConvertCompanyStatus(convertCompanyStatusCommand)
controller.Response(data, err)
}
func (controller *CompanyController) SetCompanyAdmin() {
companyService := service.NewCompanyService(nil)
setCompanyAdminCommand := &command.SetCompanyAdminCommand{}
controller.Unmarshal(setCompanyAdminCommand)
data, err := companyService.SetCompanyAdmin(setCompanyAdminCommand)
controller.Response(data, err)
}
... ...
... ... @@ -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)
}
... ...
package routers
import (
"github.com/beego/beego/v2/server/web"
"gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/port/beego/controllers"
)
func init() {
web.Router("/companies/", &controllers.CompanyController{}, "Post:CreateCompany")
web.Router("/companies/:companyId", &controllers.CompanyController{}, "Put:UpdateCompany")
web.Router("/companies/:companyId", &controllers.CompanyController{}, "Get:GetCompany")
web.Router("/companies/:companyId", &controllers.CompanyController{}, "Delete:RemoveCompany")
web.Router("/companies/", &controllers.CompanyController{}, "Get:ListCompany")
web.Router("/companies/convertCompanyStatus", &controllers.CompanyController{}, "Post:ConvertCompanyStatus")
web.Router("/companies/setCompanyAdmin", &controllers.CompanyController{}, "Post:SetCompanyAdmin")
}
... ...
package company
import (
"net/http"
"net/http/httptest"
"testing"
"github.com/beego/beego/v2/server/web"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
_ "gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/infrastructure/pg"
_ "gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/port/beego"
)
func TestCompany(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Beego Port Company Correlations Test Case Suite")
}
var handler http.Handler
var server *httptest.Server
var _ = BeforeSuite(func() {
handler = web.BeeApp.Handlers
server = httptest.NewServer(handler)
})
var _ = AfterSuite(func() {
server.Close()
})
... ...
package company
import (
"net/http"
"github.com/gavv/httpexpect"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
pG "gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/infrastructure/pg"
)
var _ = Describe("公司状态转换 禁用、启用", func() {
var companyId int64
BeforeEach(func() {
_, err := pG.DB.QueryOne(
pg.Scan(&companyId),
"INSERT INTO companys (company_id, company_info, create_at, update_at, delete_at) VALUES (?, ?, ?, ?, ?) RETURNING company_id",
"testCompanyId", "testCompanyInfo", "testCreateAt", "testUpdateAt", "testDeleteAt")
Expect(err).NotTo(HaveOccurred())
})
Describe("公司状态转换 禁用、启用", func() {
Context("", func() {
It("", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
body := map[string]interface{}{
"companyId": "int64",
"status": "int64",
}
httpExpect.POST("/companys/convertCompanyStatus").
WithJSON(body).
Expect().
Status(http.StatusOK).
JSON().
Object().
ContainsKey("code").ValueEqual("code", 0).
ContainsKey("msg").ValueEqual("msg", "ok").
ContainsKey("data").Value("data").Object()
})
})
})
AfterEach(func() {
_, err := pG.DB.Exec("DELETE FROM companys WHERE true")
Expect(err).NotTo(HaveOccurred())
})
})
... ...
package company
import (
"net/http"
"github.com/gavv/httpexpect"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
pG "gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/infrastructure/pg"
)
var _ = Describe("创建", func() {
Describe("提交数据创建", func() {
Context("提交正确的新公司信息数据", func() {
It("返回公司信息数据", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
body := map[string]interface{}{
"name": "string",
"abbreviation": "string",
"status": "int64",
"remarks": "string",
"userAccount": "string",
"userName": "string",
}
httpExpect.POST("/companys/").
WithJSON(body).
Expect().
Status(http.StatusOK).
JSON().
Object().
ContainsKey("code").ValueEqual("code", 0).
ContainsKey("msg").ValueEqual("msg", "ok").
ContainsKey("data").Value("data").Object().
ContainsKey("companyId").ValueNotEqual("companyId", BeZero())
})
})
})
AfterEach(func() {
_, err := pG.DB.Exec("DELETE FROM companys WHERE true")
Expect(err).NotTo(HaveOccurred())
})
})
... ...
package company
import (
"net/http"
"github.com/gavv/httpexpect"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
pG "gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/infrastructure/pg"
)
var _ = Describe("返回", func() {
var companyId int64
BeforeEach(func() {
_, err := pG.DB.QueryOne(
pg.Scan(&companyId),
"INSERT INTO companys (company_id, company_info, create_at, update_at, delete_at) VALUES (?, ?, ?, ?, ?) RETURNING company_id",
"testCompanyId", "testCompanyInfo", "testCreateAt", "testUpdateAt", "testDeleteAt")
Expect(err).NotTo(HaveOccurred())
})
Describe("根据companyId参数返回公司信息", func() {
Context("传入有效的companyId", func() {
It("返回公司信息数据", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
httpExpect.GET("/companys/{companyId}").
Expect().
Status(http.StatusOK).
JSON().
Object().
ContainsKey("code").ValueEqual("code", 0).
ContainsKey("msg").ValueEqual("msg", "ok").
ContainsKey("data").Value("data").Object()
})
})
})
AfterEach(func() {
_, err := pG.DB.Exec("DELETE FROM companys WHERE true")
Expect(err).NotTo(HaveOccurred())
})
})
... ...
package company
import (
"net/http"
"github.com/gavv/httpexpect"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
pG "gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/infrastructure/pg"
)
var _ = Describe("返回列表", func() {
var companyId int64
BeforeEach(func() {
_, err := pG.DB.QueryOne(
pg.Scan(&companyId),
"INSERT INTO companys (company_id, company_info, create_at, update_at, delete_at) VALUES (?, ?, ?, ?, ?) RETURNING company_id",
"testCompanyId", "testCompanyInfo", "testCreateAt", "testUpdateAt", "testDeleteAt")
Expect(err).NotTo(HaveOccurred())
})
Describe("根据参数返回公司信息列表", func() {
Context("传入有效的参数", func() {
It("返回公司信息数据列表", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
httpExpect.GET("/companys/").
WithQuery("offset", "int").
WithQuery("limit", "int").
Expect().
Status(http.StatusOK).
JSON().
Object().
ContainsKey("code").ValueEqual("code", 0).
ContainsKey("msg").ValueEqual("msg", "ok").
ContainsKey("data").Value("data").Object().
ContainsKey("count").ValueEqual("count", 1).
ContainsKey("companys").Value("companys").Array()
})
})
})
AfterEach(func() {
_, err := pG.DB.Exec("DELETE FROM companys WHERE true")
Expect(err).NotTo(HaveOccurred())
})
})
... ...
package company
import (
"net/http"
"github.com/gavv/httpexpect"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
pG "gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/infrastructure/pg"
)
var _ = Describe("移除", func() {
var companyId int64
BeforeEach(func() {
_, err := pG.DB.QueryOne(
pg.Scan(&companyId),
"INSERT INTO companys (company_id, company_info, create_at, update_at, delete_at) VALUES (?, ?, ?, ?, ?) RETURNING company_id",
"testCompanyId", "testCompanyInfo", "testCreateAt", "testUpdateAt", "testDeleteAt")
Expect(err).NotTo(HaveOccurred())
})
Describe("根据参数移除", func() {
Context("传入有效的companyId", func() {
It("返回被移除公司信息的数据", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
httpExpect.DELETE("/companys/{companyId}").
Expect().
Status(http.StatusOK).
JSON().
Object().
ContainsKey("code").ValueEqual("code", 0).
ContainsKey("msg").ValueEqual("msg", "ok").
ContainsKey("data").Value("data").Object()
})
})
})
AfterEach(func() {
_, err := pG.DB.Exec("DELETE FROM companys WHERE true")
Expect(err).NotTo(HaveOccurred())
})
})
... ...
package company
import (
"net/http"
"github.com/gavv/httpexpect"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
pG "gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/infrastructure/pg"
)
var _ = Describe("设置公司管理员", func() {
var companyId int64
BeforeEach(func() {
_, err := pG.DB.QueryOne(
pg.Scan(&companyId),
"INSERT INTO companys (company_id, company_info, create_at, update_at, delete_at) VALUES (?, ?, ?, ?, ?) RETURNING company_id",
"testCompanyId", "testCompanyInfo", "testCreateAt", "testUpdateAt", "testDeleteAt")
Expect(err).NotTo(HaveOccurred())
})
Describe("设置公司管理员", func() {
Context("", func() {
It("", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
body := map[string]interface{}{
"companyId": "int64",
"userAccount": "string",
"userName": "string",
}
httpExpect.POST("/companys/setCompanyAdmin").
WithJSON(body).
Expect().
Status(http.StatusOK).
JSON().
Object().
ContainsKey("code").ValueEqual("code", 0).
ContainsKey("msg").ValueEqual("msg", "ok").
ContainsKey("data").Value("data").Object()
})
})
})
AfterEach(func() {
_, err := pG.DB.Exec("DELETE FROM companys WHERE true")
Expect(err).NotTo(HaveOccurred())
})
})
... ...
package company
import (
"net/http"
"github.com/gavv/httpexpect"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
pG "gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/infrastructure/pg"
)
var _ = Describe("更新", func() {
var companyId int64
BeforeEach(func() {
_, err := pG.DB.QueryOne(
pg.Scan(&companyId),
"INSERT INTO companys (company_id, company_info, create_at, update_at, delete_at) VALUES (?, ?, ?, ?, ?) RETURNING company_id",
"testCompanyId", "testCompanyInfo", "testCreateAt", "testUpdateAt", "testDeleteAt")
Expect(err).NotTo(HaveOccurred())
})
Describe("提交数据更新", func() {
Context("提交正确的公司信息数据", func() {
It("返回更新后的公司信息数据", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
body := map[string]interface{}{
"name": "string",
"abbreviation": "string",
"status": "int64",
"remarks": "string",
"userAccount": "string",
"userName": "string",
}
httpExpect.PUT("/companys/{companyId}").
WithJSON(body).
Expect().
Status(http.StatusOK).
JSON().
Object().
ContainsKey("code").ValueEqual("code", 0).
ContainsKey("msg").ValueEqual("msg", "ok").
ContainsKey("data").Value("data").Object().
ContainsKey("companyId").ValueEqual("companyId", companyId)
})
})
})
AfterEach(func() {
_, err := pG.DB.Exec("DELETE FROM companys WHERE true")
Expect(err).NotTo(HaveOccurred())
})
})
... ...
... ... @@ -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() {
... ...