作者 陈志颖

feat:添加分红订单

... ... @@ -10,7 +10,7 @@ import (
type GetDividendsEstimateQuery struct {
// 承接人分红预算记录ID
DividendsEstimateId int64 `cname:"承接人分红预算记录ID" json:"dividendsEstimateId,string" valid:"Required"`
DividendsEstimateId string `cname:"承接人分红预算记录ID" json:"dividendsEstimateId" valid:"Required"`
// 公司ID,通过集成REST上下文获取
CompanyId int64 `cname:"公司ID,通过集成REST上下文获取" json:"companyId,string" valid:"Required"`
// 组织机构ID
... ...
package command
import (
"fmt"
"reflect"
"strings"
"time"
"github.com/beego/beego/v2/core/validation"
)
type OrderGoods struct {
// 订单产品金额
OrderGoodAmount float64 `json:"orderGoodAmount"`
// 订单产品名称
OrderGoodName string `json:"orderGoodName"`
// 订单产品单价
OrderGoodPrice float64 `json:"orderGoodPrice"`
// 订单产品数量
OrderGoodQuantity int64 `json:"orderGoodQuantity,string"`
// 关联分红订单号
DividendsOrderNumber int64 `json:"dividendsOrderNumber,string"`
// 关联的共创合约编号
CooperationContractNumber string `json:"cooperationContractNumber"`
// 订单产品费用
OrderGoodExpense float64 `json:"orderGoodExpense"`
}
type CreateDividendsOrderCommand struct {
// 客户名称
CustomerName string `cname:"客户名称" json:"customerName" valid:"Required"`
// 分红订单金额
DividendsOrderAmount float64 `cname:"分红订单金额" json:"dividendsOrderAmount" valid:"Required"`
// 分红订单号
DividendsOrderNumber string `cname:"分红订单号" json:"dividendsOrderNumber,string" valid:"Required"`
// 分红订单原单号
DividendsOriginalOrderNum string `cname:"分红订单原单号" json:"dividendsOriginalOrderNum" valid:"Required"`
// 订单产生时间
OrderTime time.Time `cname:"订单产生时间" json:"orderTime" valid:"Required"`
// 备注
Remarks string `cname:"备注" json:"remarks" valid:"Required"`
// 订单业务员uid
SalesmanUid string `cname:"订单业务员uid" json:"salesmanUid,omitempty"`
// 订单操作人uid
OperatorUid string `cname:"订单操作人uid" json:"operatorUid,omitempty"`
// 订单产品列表
OrderGoods []*OrderGoods `cname:"订单产品列表" json:"orderGoods,omitempty"`
// 公司ID,通过集成REST上下文获取
CompanyId int64 `cname:"公司ID,通过集成REST上下文获取" json:"companyId,string" valid:"Required"`
// 组织机构ID
OrgId int64 `cname:"组织机构ID" json:"orgId,string" valid:"Required"`
// 用户ID,通过集成REST上下文获取,可翻译成发起人、承接人、推荐人、业务员
UserId int64 `cname:"用户ID,通过集成REST上下文获取,可翻译成发起人、承接人、推荐人、业务员" json:"userId,string" valid:"Required"`
}
func (createDividendsOrderCommand *CreateDividendsOrderCommand) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (createDividendsOrderCommand *CreateDividendsOrderCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(createDividendsOrderCommand)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(createDividendsOrderCommand).Elem()
for _, validErr := range valid.Errors {
field, isExist := elem.FieldByName(validErr.Field)
if isExist {
return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
} else {
return fmt.Errorf(validErr.Message)
}
}
}
return nil
}
... ...
package command
import (
"fmt"
"reflect"
"strings"
"github.com/beego/beego/v2/core/validation"
)
type RemoveDividendsOrderCommand struct {
// 分红订单ID
DividendsOrderId string `cname:"分红订单ID" json:"dividendsOrderId" valid:"Required"`
// 公司ID,通过集成REST上下文获取
CompanyId int64 `cname:"公司ID,通过集成REST上下文获取" json:"companyId,string" valid:"Required"`
// 组织机构ID
OrgId int64 `cname:"组织机构ID" json:"orgId,string" valid:"Required"`
// 用户ID,通过集成REST上下文获取,可翻译成发起人、承接人、推荐人、业务员
UserId int64 `cname:"用户ID,通过集成REST上下文获取,可翻译成发起人、承接人、推荐人、业务员" json:"userId,string" valid:"Required"`
}
func (removeDividendsOrderCommand *RemoveDividendsOrderCommand) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (removeDividendsOrderCommand *RemoveDividendsOrderCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(removeDividendsOrderCommand)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(removeDividendsOrderCommand).Elem()
for _, validErr := range valid.Errors {
field, isExist := elem.FieldByName(validErr.Field)
if isExist {
return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
} else {
return fmt.Errorf(validErr.Message)
}
}
}
return nil
}
... ...
package command
import (
"fmt"
"reflect"
"strings"
"time"
"github.com/beego/beego/v2/core/validation"
)
type UpdateDividendsOrderCommand struct {
// 分红订单ID
DividendsOrderId string `cname:"分红订单ID" json:"dividendsOrderId" valid:"Required"`
// 客户名称
CustomerName string `cname:"客户名称" json:"customerName" valid:"Required"`
// 分红订单金额
DividendsOrderAmount float64 `cname:"分红订单金额" json:"dividendsOrderAmount" valid:"Required"`
// 分红订单号
DividendsOrderNumber int64 `cname:"分红订单号" json:"dividendsOrderNumber,string" valid:"Required"`
// 分红订单原单号
DividendsOriginalOrderNum string `cname:"分红订单原单号" json:"dividendsOriginalOrderNum" valid:"Required"`
// 订单产生时间
OrderTime time.Time `cname:"订单产生时间" json:"orderTime" valid:"Required"`
// 备注
Remarks string `cname:"备注" json:"remarks" valid:"Required"`
// 业务员uid
SalesmanUid string `cname:"业务员uid" json:"salesmanUid,omitempty"`
// 操作人uid
OperatorUid string `cname:"操作人uid" json:"operatorUid,omitempty"`
// 公司ID,通过集成REST上下文获取
CompanyId int64 `cname:"公司ID,通过集成REST上下文获取" json:"companyId,string" valid:"Required"`
// 组织机构ID
OrgId int64 `cname:"组织机构ID" json:"orgId,string" valid:"Required"`
// 用户ID,通过集成REST上下文获取,可翻译成发起人、承接人、推荐人、业务员
UserId int64 `cname:"用户ID,通过集成REST上下文获取,可翻译成发起人、承接人、推荐人、业务员" json:"userId,string" valid:"Required"`
}
func (updateDividendsOrderCommand *UpdateDividendsOrderCommand) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (updateDividendsOrderCommand *UpdateDividendsOrderCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(updateDividendsOrderCommand)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(updateDividendsOrderCommand).Elem()
for _, validErr := range valid.Errors {
field, isExist := elem.FieldByName(validErr.Field)
if isExist {
return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
} else {
return fmt.Errorf(validErr.Message)
}
}
}
return nil
}
... ...
package query
import (
"fmt"
"reflect"
"strings"
"github.com/beego/beego/v2/core/validation"
)
type GetDividendsOrderQuery struct {
// 分红订单ID
DividendsOrderId int64 `cname:"分红订单ID" json:"dividendsOrderId,string" valid:"Required"`
// 公司ID,通过集成REST上下文获取
CompanyId int64 `cname:"公司ID,通过集成REST上下文获取" json:"companyId,string" valid:"Required"`
// 组织机构ID
OrgId int64 `cname:"组织机构ID" json:"orgId,string" valid:"Required"`
// 用户ID,通过集成REST上下文获取,可翻译成发起人、承接人、推荐人、业务员
UserId int64 `cname:"用户ID,通过集成REST上下文获取,可翻译成发起人、承接人、推荐人、业务员" json:"userId,string" valid:"Required"`
}
func (getDividendsOrderQuery *GetDividendsOrderQuery) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (getDividendsOrderQuery *GetDividendsOrderQuery) ValidateQuery() error {
valid := validation.Validation{}
b, err := valid.Valid(getDividendsOrderQuery)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(getDividendsOrderQuery).Elem()
for _, validErr := range valid.Errors {
field, isExist := elem.FieldByName(validErr.Field)
if isExist {
return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
} else {
return fmt.Errorf(validErr.Message)
}
}
}
return nil
}
... ...
package query
import (
"fmt"
"reflect"
"strings"
"github.com/beego/beego/v2/core/validation"
)
type ListDividendsOrdersQuery struct {
// 查询偏离量
Offset int `cname:"查询偏离量" json:"offset" valid:"Required"`
// 查询限制
Limit int `cname:"查询限制" json:"limit" valid:"Required"`
// 公司ID,通过集成REST上下文获取
CompanyId int64 `cname:"公司ID,通过集成REST上下文获取" json:"companyId,string" valid:"Required"`
// 组织机构ID
OrgId int64 `cname:"组织机构ID" json:"orgId,string" valid:"Required"`
// 用户ID,通过集成REST上下文获取,可翻译成发起人、承接人、推荐人、业务员
UserId int64 `cname:"用户ID,通过集成REST上下文获取,可翻译成发起人、承接人、推荐人、业务员" json:"userId,string" valid:"Required"`
}
func (listDividendsOrdersQuery *ListDividendsOrdersQuery) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (listDividendsOrdersQuery *ListDividendsOrdersQuery) ValidateQuery() error {
valid := validation.Validation{}
b, err := valid.Valid(listDividendsOrdersQuery)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(listDividendsOrdersQuery).Elem()
for _, validErr := range valid.Errors {
field, isExist := elem.FieldByName(validErr.Field)
if isExist {
return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
} else {
return fmt.Errorf(validErr.Message)
}
}
}
return nil
}
... ...
package query
import (
"fmt"
"reflect"
"strings"
"github.com/beego/beego/v2/core/validation"
)
type SearchDividendsOrderQuery struct {
// 分红订单号
DividendsOrderNumber string `cname:"分红订单号" json:"dividendsOrderNumber,omitempty"`
// 客户名称
CustomerName string `cname:"客户名称" json:"customerName,omitempty"`
// 页面大小
PageSize int32 `cname:"页面大小" json:"pageSize,omitempty"`
// 页面大小
PageNumber int32 `cname:"页面大小" json:"pageNumber,omitempty"`
// 公司ID,通过集成REST上下文获取
CompanyId int64 `cname:"公司ID,通过集成REST上下文获取" json:"companyId,string" valid:"Required"`
// 组织机构ID
OrgId int64 `cname:"组织机构ID" json:"orgId,string" valid:"Required"`
// 用户ID,通过集成REST上下文获取,可翻译成发起人、承接人、推荐人、业务员
UserId int64 `cname:"用户ID,通过集成REST上下文获取,可翻译成发起人、承接人、推荐人、业务员" json:"userId,string" valid:"Required"`
}
func (searchDividendsOrderQuery *SearchDividendsOrderQuery) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (searchDividendsOrderQuery *SearchDividendsOrderQuery) ValidateQuery() error {
valid := validation.Validation{}
b, err := valid.Valid(searchDividendsOrderQuery)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(searchDividendsOrderQuery).Elem()
for _, validErr := range valid.Errors {
field, isExist := elem.FieldByName(validErr.Field)
if isExist {
return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
} else {
return fmt.Errorf(validErr.Message)
}
}
}
return nil
}
... ...
package query
import (
"fmt"
"reflect"
"strings"
"github.com/beego/beego/v2/core/validation"
)
type SearchDividendsOrderNumberQuery struct {
// 分红订单号
DividendsOrderNumber string `cname:"分红订单号" json:"dividendsOrderNumber,omitempty"`
// 公司ID,通过集成REST上下文获取
CompanyId int64 `cname:"公司ID,通过集成REST上下文获取" json:"companyId,string" valid:"Required"`
// 组织机构ID
OrgId int64 `cname:"组织机构ID" json:"orgId,string" valid:"Required"`
// 用户ID,通过集成REST上下文获取,可翻译成发起人、承接人、推荐人、业务员
UserId int64 `cname:"用户ID,通过集成REST上下文获取,可翻译成发起人、承接人、推荐人、业务员" json:"userId,string" valid:"Required"`
}
func (searchDividendsOrderNumberQuery *SearchDividendsOrderNumberQuery) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (searchDividendsOrderNumberQuery *SearchDividendsOrderNumberQuery) ValidateQuery() error {
valid := validation.Validation{}
b, err := valid.Valid(searchDividendsOrderNumberQuery)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(searchDividendsOrderNumberQuery).Elem()
for _, validErr := range valid.Errors {
field, isExist := elem.FieldByName(validErr.Field)
if isExist {
return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
} else {
return fmt.Errorf(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/allied-creation/allied-creation-cooperation/pkg/application/dividendsOrder/command"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/application/dividendsOrder/query"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/application/factory"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
)
// DividendsOrderService 分红订单实体对象
type DividendsOrderService struct {
}
// CreateDividendsOrder 创建分红订单实体对象
func (dividendsOrderService *DividendsOrderService) CreateDividendsOrder(createDividendsOrderCommand *command.CreateDividendsOrderCommand) (interface{}, error) {
if err := createDividendsOrderCommand.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()
}()
newDividendsOrder := &domain.DividendsOrder{
CustomerName: createDividendsOrderCommand.CustomerName,
DividendsOrderAmount: createDividendsOrderCommand.DividendsOrderAmount,
DividendsOrderNumber: createDividendsOrderCommand.DividendsOrderNumber,
DividendsOriginalOrderNum: createDividendsOrderCommand.DividendsOriginalOrderNum,
OrderTime: createDividendsOrderCommand.OrderTime,
//Remarks: createDividendsOrderCommand.Remarks,
//SalesmanUid: createDividendsOrderCommand.SalesmanUid,
//OperatorUid: createDividendsOrderCommand.OperatorUid,
//OrderGoods: createDividendsOrderCommand.OrderGoods,
//CompanyId: createDividendsOrderCommand.CompanyId,
//OrgId: createDividendsOrderCommand.OrgId,
//UserId: createDividendsOrderCommand.UserId,
}
var dividendsOrderRepository domain.DividendsOrderRepository
if value, err := factory.CreateDividendsOrderRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
dividendsOrderRepository = value
}
if dividendsOrder, err := dividendsOrderRepository.Save(newDividendsOrder); 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 dividendsOrder, nil
}
}
// GetDividendsOrder 返回分红订单实体对象
func (dividendsOrderService *DividendsOrderService) GetDividendsOrder(getDividendsOrderQuery *query.GetDividendsOrderQuery) (interface{}, error) {
if err := getDividendsOrderQuery.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 dividendsOrderRepository domain.DividendsOrderRepository
if value, err := factory.CreateDividendsOrderRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
dividendsOrderRepository = value
}
dividendsOrder, err := dividendsOrderRepository.FindOne(map[string]interface{}{"dividendsOrderId": getDividendsOrderQuery.DividendsOrderId})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if dividendsOrder == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(getDividendsOrderQuery.DividendsOrderId)))
} else {
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return dividendsOrder, nil
}
}
// ListDividendsOrders 返回分红订单实体对象列表
func (dividendsOrderService *DividendsOrderService) ListDividendsOrders(listDividendsOrdersQuery *query.ListDividendsOrdersQuery) (interface{}, error) {
if err := listDividendsOrdersQuery.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()
}()
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return nil, nil
}
// RemoveDividendsOrder 移除分红订单实体对象
func (dividendsOrderService *DividendsOrderService) RemoveDividendsOrder(removeDividendsOrderCommand *command.RemoveDividendsOrderCommand) (interface{}, error) {
if err := removeDividendsOrderCommand.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 dividendsOrderRepository domain.DividendsOrderRepository
if value, err := factory.CreateDividendsOrderRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
dividendsOrderRepository = value
}
dividendsOrder, err := dividendsOrderRepository.FindOne(map[string]interface{}{"dividendsOrderId": removeDividendsOrderCommand.DividendsOrderId})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if dividendsOrder == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(removeDividendsOrderCommand.DividendsOrderId)))
}
if dividendsOrder, err := dividendsOrderRepository.Remove(dividendsOrder); 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 dividendsOrder, nil
}
}
// SearchDividendsOrder 查询分红订单方法
func (dividendsOrderService *DividendsOrderService) SearchDividendsOrder(searchDividendsOrderQuery *query.SearchDividendsOrderQuery) (interface{}, error) {
if err := searchDividendsOrderQuery.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()
}()
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return nil, nil
}
// SearchDividendsOrderNumber 查询分红订单方法
func (dividendsOrderService *DividendsOrderService) SearchDividendsOrderNumber(searchDividendsOrderNumberQuery *query.SearchDividendsOrderNumberQuery) (interface{}, error) {
if err := searchDividendsOrderNumberQuery.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()
}()
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return nil, nil
}
// UpdateDividendsOrder 更新分红订单实体对象
func (dividendsOrderService *DividendsOrderService) UpdateDividendsOrder(updateDividendsOrderCommand *command.UpdateDividendsOrderCommand) (interface{}, error) {
if err := updateDividendsOrderCommand.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 dividendsOrderRepository domain.DividendsOrderRepository
if value, err := factory.CreateDividendsOrderRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
dividendsOrderRepository = value
}
dividendsOrder, err := dividendsOrderRepository.FindOne(map[string]interface{}{"dividendsOrderId": updateDividendsOrderCommand.DividendsOrderId})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if dividendsOrder == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateDividendsOrderCommand.DividendsOrderId)))
}
if err := dividendsOrder.Update(tool_funs.SimpleStructToMap(updateDividendsOrderCommand)); err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
if dividendsOrder, err := dividendsOrderRepository.Save(dividendsOrder); 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 dividendsOrder, nil
}
}
func NewDividendsOrderService(options map[string]interface{}) *DividendsOrderService {
newDividendsOrderService := &DividendsOrderService{}
return newDividendsOrderService
}
... ...
... ... @@ -2,12 +2,12 @@ package domain
import "time"
// 分红订单实体
// DividendsOrder 分红订单实体
type DividendsOrder struct {
// 分红订单ID
DividendsOrderId int64 `json:"dividendsOrderId,string"`
// 分红订单号
DividendsOrderNumber int64 `json:"dividendsOrderNumber,string"`
DividendsOrderNumber string `json:"dividendsOrderNumber"`
// 分红订单原单号
DividendsOriginalOrderNum string `json:"dividendsOriginalOrderNum"`
// 分红订单金额
... ... @@ -56,7 +56,7 @@ func (dividendsOrder *DividendsOrder) Identify() interface{} {
func (dividendsOrder *DividendsOrder) Update(data map[string]interface{}) error {
if dividendsOrderNumber, ok := data["dividendsOrderNumber"]; ok {
dividendsOrder.DividendsOrderNumber = dividendsOrderNumber.(int64)
dividendsOrder.DividendsOrderNumber = dividendsOrderNumber.(string)
}
if dividendsOriginalOrderNum, ok := data["dividendsOriginalOrderNum"]; ok {
dividendsOrder.DividendsOriginalOrderNum = dividendsOriginalOrderNum.(string)
... ...
package controllers
import (
"github.com/linmadan/egglib-go/web/beego"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/application/dividendsOrder/command"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/application/dividendsOrder/query"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/application/dividendsOrder/service"
)
type DividendsOrderController struct {
beego.BaseController
}
func (controller *DividendsOrderController) CreateDividendsOrder() {
dividendsOrderService := service.NewDividendsOrderService(nil)
createDividendsOrderCommand := &command.CreateDividendsOrderCommand{}
controller.Unmarshal(createDividendsOrderCommand)
data, err := dividendsOrderService.CreateDividendsOrder(createDividendsOrderCommand)
controller.Response(data, err)
}
func (controller *DividendsOrderController) UpdateDividendsOrder() {
dividendsOrderService := service.NewDividendsOrderService(nil)
updateDividendsOrderCommand := &command.UpdateDividendsOrderCommand{}
controller.Unmarshal(updateDividendsOrderCommand)
dividendsOrderId := controller.GetString(":dividendsOrderId")
updateDividendsOrderCommand.DividendsOrderId = dividendsOrderId
data, err := dividendsOrderService.UpdateDividendsOrder(updateDividendsOrderCommand)
controller.Response(data, err)
}
func (controller *DividendsOrderController) GetDividendsOrder() {
dividendsOrderService := service.NewDividendsOrderService(nil)
getDividendsOrderQuery := &query.GetDividendsOrderQuery{}
dividendsOrderId, _ := controller.GetInt64(":dividendsOrderId")
getDividendsOrderQuery.DividendsOrderId = dividendsOrderId
data, err := dividendsOrderService.GetDividendsOrder(getDividendsOrderQuery)
controller.Response(data, err)
}
func (controller *DividendsOrderController) RemoveDividendsOrder() {
dividendsOrderService := service.NewDividendsOrderService(nil)
removeDividendsOrderCommand := &command.RemoveDividendsOrderCommand{}
controller.Unmarshal(removeDividendsOrderCommand)
dividendsOrderId := controller.GetString(":dividendsOrderId")
removeDividendsOrderCommand.DividendsOrderId = dividendsOrderId
data, err := dividendsOrderService.RemoveDividendsOrder(removeDividendsOrderCommand)
controller.Response(data, err)
}
func (controller *DividendsOrderController) SearchDividendsOrder() {
dividendsOrderService := service.NewDividendsOrderService(nil)
searchDividendsOrderQuery := &query.SearchDividendsOrderQuery{}
data, err := dividendsOrderService.SearchDividendsOrder(searchDividendsOrderQuery)
controller.Response(data, err)
}
func (controller *DividendsOrderController) SearchDividendsOrderNumber() {
dividendsOrderService := service.NewDividendsOrderService(nil)
searchDividendsOrderNumberQuery := &query.SearchDividendsOrderNumberQuery{}
data, err := dividendsOrderService.SearchDividendsOrderNumber(searchDividendsOrderNumberQuery)
controller.Response(data, err)
}
func (controller *DividendsOrderController) ListDividendsOrders() {
dividendsOrderService := service.NewDividendsOrderService(nil)
listDividendsOrdersQuery := &query.ListDividendsOrdersQuery{}
offset, _ := controller.GetInt("offset")
listDividendsOrdersQuery.Offset = offset
limit, _ := controller.GetInt("limit")
listDividendsOrdersQuery.Limit = limit
data, err := dividendsOrderService.ListDividendsOrders(listDividendsOrdersQuery)
controller.Response(data, err)
}
... ...
package routers
import (
"github.com/beego/beego/v2/server/web"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/port/beego/controllers"
)
func init() {
web.Router("/dividends-orders/", &controllers.DividendsOrderController{}, "Post:CreateDividendsOrder")
web.Router("/dividends-orders/:dividendsOrderId", &controllers.DividendsOrderController{}, "Put:UpdateDividendsOrder")
web.Router("/dividends-orders/:dividendsOrderId", &controllers.DividendsOrderController{}, "Get:GetDividendsOrder")
web.Router("/dividends-orders/:dividendsOrderId", &controllers.DividendsOrderController{}, "Delete:RemoveDividendsOrder")
web.Router("/dividends-orders/search", &controllers.DividendsOrderController{}, "Post:SearchDividendsOrder")
web.Router("/dividends-orders/search-order-number", &controllers.DividendsOrderController{}, "Post:SearchDividendsOrderNumber")
web.Router("/dividends-orders/", &controllers.DividendsOrderController{}, "Get:ListDividendsOrders")
}
... ...
package dividends_order
import (
"net/http"
"github.com/gavv/httpexpect"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
pG "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg"
)
var _ = Describe("创建分红订单实体对象", func() {
Describe("提交数据创建分红订单实体对象", func() {
Context("提交正确的新分红订单实体数据", func() {
It("返回分红订单实体数据", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
body := map[string]interface{}{
"customerName": "string",
"dividendsOrderAmount": "float64",
"dividendsOrderNumber": "string",
"dividendsOriginalOrderNum": "string",
"orderTime": "datetime",
"remarks": "string",
"salesmanUid": "string",
"operatorUid": "string",
"orderGoods": "array",
"companyId": "int64",
"orgId": "int64",
"userId": "int64",
}
httpExpect.POST("/dividends-orders/").
WithJSON(body).
Expect().
Status(http.StatusOK).
JSON().
Object().
ContainsKey("code").ValueEqual("code", 0).
ContainsKey("msg").ValueEqual("msg", "ok").
ContainsKey("data").Value("data").Object().
ContainsKey("dividendsOrderId").ValueNotEqual("dividendsOrderId", BeZero())
})
})
})
AfterEach(func() {
_, err := pG.DB.Exec("DELETE FROM dividends_orders WHERE true")
Expect(err).NotTo(HaveOccurred())
})
})
... ...
package dividends_order
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/allied-creation/allied-creation-cooperation/pkg/application"
_ "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg"
_ "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/port/beego"
)
func TestDividendsOrder(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Beego Port DividendsOrder 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 dividends_order
import (
"github.com/go-pg/pg/v10"
"net/http"
"github.com/gavv/httpexpect"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
pG "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg"
)
var _ = Describe("返回分红订单实体对象", func() {
var dividendsOrderId int64
BeforeEach(func() {
_, err := pG.DB.QueryOne(
pg.Scan(&dividendsOrderId),
"INSERT INTO dividends_orders (dividends_order_id, dividends_order_number, dividends_original_order_num, dividends_order_amount, order_salesman, order_time, dividend_time, dividend_status, region, customer_name, org, company, created_at, deleted_at, updated_at, operate_time, operator) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING dividends_order_id",
"testDividendsOrderId", "testDividendsOrderNumber", "testDividendsOriginalOrderNum", "testDividendsOrderAmount", "testOrderSalesman", "testOrderTime", "testDividendTime", "testDividendStatus", "testRegion", "testCustomerName", "testOrg", "testCompany", "testCreatedAt", "testDeletedAt", "testUpdatedAt", "testOperateTime", "testOperator")
Expect(err).NotTo(HaveOccurred())
})
Describe("根据dividendsOrderId参数返回分红订单实体", func() {
Context("传入有效的dividendsOrderId", func() {
It("返回分红订单实体数据", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
httpExpect.GET("/dividends-orders/{dividendsOrderId}").
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 dividends_orders WHERE true")
Expect(err).NotTo(HaveOccurred())
})
})
... ...
package dividends_order
import (
"github.com/go-pg/pg/v10"
"net/http"
"github.com/gavv/httpexpect"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
pG "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg"
)
var _ = Describe("返回分红订单实体对象列表", func() {
var dividendsOrderId int64
BeforeEach(func() {
_, err := pG.DB.QueryOne(
pg.Scan(&dividendsOrderId),
"INSERT INTO dividends_orders (dividends_order_id, dividends_order_number, dividends_original_order_num, dividends_order_amount, order_salesman, order_time, dividend_time, dividend_status, region, customer_name, org, company, created_at, deleted_at, updated_at, operate_time, operator) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING dividends_order_id",
"testDividendsOrderId", "testDividendsOrderNumber", "testDividendsOriginalOrderNum", "testDividendsOrderAmount", "testOrderSalesman", "testOrderTime", "testDividendTime", "testDividendStatus", "testRegion", "testCustomerName", "testOrg", "testCompany", "testCreatedAt", "testDeletedAt", "testUpdatedAt", "testOperateTime", "testOperator")
Expect(err).NotTo(HaveOccurred())
})
Describe("返回分红订单实体对象列表", func() {
Context("", func() {
It("", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
httpExpect.GET("/dividends-orders/").
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()
})
})
})
AfterEach(func() {
_, err := pG.DB.Exec("DELETE FROM dividends_orders WHERE true")
Expect(err).NotTo(HaveOccurred())
})
})
... ...
package dividends_order
import (
"github.com/go-pg/pg/v10"
"net/http"
"github.com/gavv/httpexpect"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
pG "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg"
)
var _ = Describe("移除分红订单实体对象", func() {
var dividendsOrderId int64
BeforeEach(func() {
_, err := pG.DB.QueryOne(
pg.Scan(&dividendsOrderId),
"INSERT INTO dividends_orders (dividends_order_id, dividends_order_number, dividends_original_order_num, dividends_order_amount, order_salesman, order_time, dividend_time, dividend_status, region, customer_name, org, company, created_at, deleted_at, updated_at, operate_time, operator) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING dividends_order_id",
"testDividendsOrderId", "testDividendsOrderNumber", "testDividendsOriginalOrderNum", "testDividendsOrderAmount", "testOrderSalesman", "testOrderTime", "testDividendTime", "testDividendStatus", "testRegion", "testCustomerName", "testOrg", "testCompany", "testCreatedAt", "testDeletedAt", "testUpdatedAt", "testOperateTime", "testOperator")
Expect(err).NotTo(HaveOccurred())
})
Describe("根据参数移除分红订单实体对象", func() {
Context("传入有效的dividendsOrderId", func() {
It("返回被移除分红订单实体的数据", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
httpExpect.DELETE("/dividends-orders/{dividendsOrderId}").
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 dividends_orders WHERE true")
Expect(err).NotTo(HaveOccurred())
})
})
... ...
package dividends_order
import (
"github.com/go-pg/pg/v10"
"net/http"
"github.com/gavv/httpexpect"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
pG "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg"
)
var _ = Describe("查询分红订单方法", func() {
var dividendsOrderId int64
BeforeEach(func() {
_, err := pG.DB.QueryOne(
pg.Scan(&dividendsOrderId),
"INSERT INTO dividends_orders (dividends_order_id, dividends_order_number, dividends_original_order_num, dividends_order_amount, order_salesman, order_time, dividend_time, dividend_status, region, customer_name, org, company, created_at, deleted_at, updated_at, operate_time, operator) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING dividends_order_id",
"testDividendsOrderId", "testDividendsOrderNumber", "testDividendsOriginalOrderNum", "testDividendsOrderAmount", "testOrderSalesman", "testOrderTime", "testDividendTime", "testDividendStatus", "testRegion", "testCustomerName", "testOrg", "testCompany", "testCreatedAt", "testDeletedAt", "testUpdatedAt", "testOperateTime", "testOperator")
Expect(err).NotTo(HaveOccurred())
})
Describe("查询分红订单方法", func() {
Context("", func() {
It("", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
body := map[string]interface{}{
"dividendsOrderNumber": "string",
"companyId": "int64",
"orgId": "int64",
"userId": "int64",
}
httpExpect.POST("/dividends-orders/search-order-number").
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 dividends_orders WHERE true")
Expect(err).NotTo(HaveOccurred())
})
})
... ...
package dividends_order
import (
"github.com/go-pg/pg/v10"
"net/http"
"github.com/gavv/httpexpect"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
pG "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg"
)
var _ = Describe("查询分红订单方法", func() {
var dividendsOrderId int64
BeforeEach(func() {
_, err := pG.DB.QueryOne(
pg.Scan(&dividendsOrderId),
"INSERT INTO dividends_orders (dividends_order_id, dividends_order_number, dividends_original_order_num, dividends_order_amount, order_salesman, order_time, dividend_time, dividend_status, region, customer_name, org, company, created_at, deleted_at, updated_at, operate_time, operator) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING dividends_order_id",
"testDividendsOrderId", "testDividendsOrderNumber", "testDividendsOriginalOrderNum", "testDividendsOrderAmount", "testOrderSalesman", "testOrderTime", "testDividendTime", "testDividendStatus", "testRegion", "testCustomerName", "testOrg", "testCompany", "testCreatedAt", "testDeletedAt", "testUpdatedAt", "testOperateTime", "testOperator")
Expect(err).NotTo(HaveOccurred())
})
Describe("查询分红订单方法", func() {
Context("", func() {
It("", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
body := map[string]interface{}{
"dividendsOrderNumber": "string",
"customerName": "string",
"pageSize": "int32",
"pageNumber": "int32",
"companyId": "int64",
"orgId": "int64",
"userId": "int64",
}
httpExpect.POST("/dividends-orders/search").
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 dividends_orders WHERE true")
Expect(err).NotTo(HaveOccurred())
})
})
... ...
package dividends_order
import (
"github.com/go-pg/pg/v10"
"net/http"
"github.com/gavv/httpexpect"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
pG "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg"
)
var _ = Describe("更新分红订单实体对象", func() {
var dividendsOrderId int64
BeforeEach(func() {
_, err := pG.DB.QueryOne(
pg.Scan(&dividendsOrderId),
"INSERT INTO dividends_orders (dividends_order_id, dividends_order_number, dividends_original_order_num, dividends_order_amount, order_salesman, order_time, dividend_time, dividend_status, region, customer_name, org, company, created_at, deleted_at, updated_at, operate_time, operator) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING dividends_order_id",
"testDividendsOrderId", "testDividendsOrderNumber", "testDividendsOriginalOrderNum", "testDividendsOrderAmount", "testOrderSalesman", "testOrderTime", "testDividendTime", "testDividendStatus", "testRegion", "testCustomerName", "testOrg", "testCompany", "testCreatedAt", "testDeletedAt", "testUpdatedAt", "testOperateTime", "testOperator")
Expect(err).NotTo(HaveOccurred())
})
Describe("提交数据更新分红订单实体对象", func() {
Context("提交正确的分红订单实体数据", func() {
It("返回更新后的分红订单实体数据", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
body := map[string]interface{}{
"customerName": "string",
"dividendsOrderAmount": "float64",
"dividendsOrderNumber": "string",
"dividendsOriginalOrderNum": "string",
"orderTime": "datetime",
"remarks": "string",
"salesmanUid": "string",
"operatorUid": "string",
"companyId": "int64",
"orgId": "int64",
"userId": "int64",
}
httpExpect.PUT("/dividends-orders/{dividendsOrderId}").
WithJSON(body).
Expect().
Status(http.StatusOK).
JSON().
Object().
ContainsKey("code").ValueEqual("code", 0).
ContainsKey("msg").ValueEqual("msg", "ok").
ContainsKey("data").Value("data").Object().
ContainsKey("dividendsOrderId").ValueEqual("dividendsOrderId", dividendsOrderId)
})
})
})
AfterEach(func() {
_, err := pG.DB.Exec("DELETE FROM dividends_orders WHERE true")
Expect(err).NotTo(HaveOccurred())
})
})
... ...