作者 陈志颖

feat:增加共创合约承接人和相关人模型

正在显示 22 个修改的文件 包含 325 行增加1 行删除
version: v1
kind: HttpApi
metadata:
service: cooperationContractUndertaker
path: /cooperation-contract-undertakers
endpoints:
- method: createCooperationContractUndertaker
route:
post: /
- method: updateCooperationContractUndertaker
route:
put: /{cooperationContractUndertakerId}
- method: getCooperationContractUndertaker
route:
get: /{cooperationContractUndertakerId}
- method: removeCooperationContractUndertaker
route:
delete: /{cooperationContractUndertakerId}
- method: listCooperationContractUndertaker
route:
get: /
params:
- name: offset
- name: limit
... ...
version: v1
kind: Attribute
metadata:
name: cooperationContractRelevantId
description: 共创合约相关人id
type:
primitive: int64
... ...
version: v1
kind: Attribute
metadata:
name: relevant
description: 相关人
type:
schema: relevant
... ...
version: v1
kind: Attribute
metadata:
name: cooperationContractUndertakerId
description: 共创合约承接人id
type:
primitive: int64
... ...
version: v1
kind: Attribute
metadata:
name: undertaker
description: 共创合约承接人
type:
schema: undertaker
... ...
... ... @@ -4,4 +4,4 @@ metadata:
name: dividendsOrderNumber
description: 分红订单号
type:
primitive: int64
primitive: string
... ...
func CreateCooperationContractUndertakerRepository(options map[string]interface{}) (domain.CooperationContractUndertakerRepository, error) {
var transactionContext *pg.TransactionContext
if value, ok := options["transactionContext"]; ok {
transactionContext = value.(*pg.TransactionContext)
}
return repository.NewCooperationContractUndertakerRepository(transactionContext)
}
\ No newline at end of file
... ...
package domain
// 共创合约承接人
type CooperationContractUndertaker struct {
}
type CooperationContractUndertakerRepository interface {
Save(cooperationContractUndertaker *CooperationContractUndertaker) (*CooperationContractUndertaker, error)
Remove(cooperationContractUndertaker *CooperationContractUndertaker) (*CooperationContractUndertaker, error)
FindOne(queryOptions map[string]interface{}) (*CooperationContractUndertaker, error)
Find(queryOptions map[string]interface{}) (int64, []*CooperationContractUndertaker, error)
}
func (cooperationContractUndertaker *CooperationContractUndertaker) Identify() interface{} {
if cooperationContractUndertaker.cooperationContractUndertakerId == 0 {
return nil
}
return cooperationContractUndertaker.cooperationContractUndertakerId
}
func (cooperationContractUndertaker *CooperationContractUndertaker) Update(data map[string]interface{}) error {
return nil
}
... ...
package models
type CooperationContractUndertaker struct {
tableName string `comment:"共创合约承接人" pg:"cooperation_contract_undertakers,alias:cooperation_contract_undertaker"`
}
... ...
package transform
import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg/models"
)
func TransformToCooperationContractUndertakerDomainModelFromPgModels(cooperationContractUndertakerModel *models.CooperationContractUndertaker) (*domain.CooperationContractUndertaker, error) {
return &domain.CooperationContractUndertaker{}, nil
}
... ...
package repository
import (
"fmt"
"github.com/linmadan/egglib-go/persistent/pg/sqlbuilder"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
"github.com/linmadan/egglib-go/utils/snowflake"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg/models"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg/transform"
)
type CooperationContractUndertakerRepository struct {
transactionContext *pgTransaction.TransactionContext
}
func (repository *CooperationContractUndertakerRepository) nextIdentify() (int64, error) {
IdWorker, err := snowflake.NewIdWorker(1)
if err != nil {
return 0, err
}
id, err := IdWorker.NextId()
return id, err
}
func (repository *CooperationContractUndertakerRepository) Save(cooperationContractUndertaker *domain.CooperationContractUndertaker) (*domain.CooperationContractUndertaker, error) {
sqlBuildFields := []string{}
insertFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlBuildFields)
insertPlaceHoldersSnippet := sqlbuilder.SqlPlaceHoldersSnippet(sqlBuildFields)
returningFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlBuildFields)
updateFields := sqlbuilder.RemoveSqlFields(sqlBuildFields, "cooperationContractUndertaker_id")
updateFieldsSnippet := sqlbuilder.SqlUpdateFieldsSnippet(updateFields)
tx := repository.transactionContext.PgTx
if cooperationContractUndertaker.Identify() == nil {
cooperationContractUndertakerId, err := repository.nextIdentify()
if err != nil {
return cooperationContractUndertaker, err
} else {
cooperationContractUndertaker.CooperationContractUndertakerId = cooperationContractUndertakerId
}
if _, err := tx.QueryOne(
pg.Scan(),
fmt.Sprintf("INSERT INTO cooperation_contract_undertakers (%s) VALUES (%s) RETURNING %s", insertFieldsSnippet, insertPlaceHoldersSnippet, returningFieldsSnippet),
); err != nil {
return cooperationContractUndertaker, err
}
} else {
if _, err := tx.QueryOne(
pg.Scan(),
fmt.Sprintf("UPDATE cooperation_contract_undertakers SET %s WHERE cooperation_contract_undertaker_id=? RETURNING %s", updateFieldsSnippet, returningFieldsSnippet),
cooperationContractUndertaker.Identify(),
); err != nil {
return cooperationContractUndertaker, err
}
}
return cooperationContractUndertaker, nil
}
func (repository *CooperationContractUndertakerRepository) Remove(cooperationContractUndertaker *domain.CooperationContractUndertaker) (*domain.CooperationContractUndertaker, error) {
tx := repository.transactionContext.PgTx
cooperationContractUndertakerModel := new(models.CooperationContractUndertaker)
cooperationContractUndertakerModel.CooperationContractUndertakerId = cooperationContractUndertaker.Identify().(int64)
if _, err := tx.Model(cooperationContractUndertakerModel).WherePK().Delete(); err != nil {
return cooperationContractUndertaker, err
}
return cooperationContractUndertaker, nil
}
func (repository *CooperationContractUndertakerRepository) FindOne(queryOptions map[string]interface{}) (*domain.CooperationContractUndertaker, error) {
tx := repository.transactionContext.PgTx
cooperationContractUndertakerModel := new(models.CooperationContractUndertaker)
query := sqlbuilder.BuildQuery(tx.Model(cooperationContractUndertakerModel), queryOptions)
query.SetWhereByQueryOption("cooperation_contract_undertaker.cooperation_contract_undertaker_id = ?", "cooperationContractUndertakerId")
if err := query.First(); err != nil {
if err.Error() == "pg: no rows in result set" {
return nil, fmt.Errorf("没有此资源")
} else {
return nil, err
}
}
if cooperationContractUndertakerModel.CooperationContractUndertakerId == 0 {
return nil, nil
} else {
return transform.TransformToCooperationContractUndertakerDomainModelFromPgModels(cooperationContractUndertakerModel)
}
}
func (repository *CooperationContractUndertakerRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.CooperationContractUndertaker, error) {
tx := repository.transactionContext.PgTx
var cooperationContractUndertakerModels []*models.CooperationContractUndertaker
cooperationContractUndertakers := make([]*domain.CooperationContractUndertaker, 0)
query := sqlbuilder.BuildQuery(tx.Model(&cooperationContractUndertakerModels), queryOptions)
query.SetOffsetAndLimit(20)
query.SetOrderDirect("cooperation_contract_undertaker_id", "DESC")
if count, err := query.SelectAndCount(); err != nil {
return 0, cooperationContractUndertakers, err
} else {
for _, cooperationContractUndertakerModel := range cooperationContractUndertakerModels {
if cooperationContractUndertaker, err := transform.TransformToCooperationContractUndertakerDomainModelFromPgModels(cooperationContractUndertakerModel); err != nil {
return 0, cooperationContractUndertakers, err
} else {
cooperationContractUndertakers = append(cooperationContractUndertakers, cooperationContractUndertaker)
}
}
return int64(count), cooperationContractUndertakers, nil
}
}
func NewCooperationContractUndertakerRepository(transactionContext *pgTransaction.TransactionContext) (*CooperationContractUndertakerRepository, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
} else {
return &CooperationContractUndertakerRepository{
transactionContext: transactionContext,
}, nil
}
}
... ...
version: v1
kind: Schema
metadata:
name: cooperationContractRelevant
description: 共创合约相关人
attributes:
- ref: cooperationContractRelevantId
required: true
- ref: cooperationContractNumber
required: true
- ref: relevant
required: true
- ref: updatedAt
required: true
- ref: deletedAt
required: true
- ref: createdAt
required: true
... ...
version: v1
kind: Schema
metadata:
name: cooperationContractUndertaker
description: 共创合约承接人
attributes:
- ref: cooperationContractUndertakerId
required: true
- ref: cooperationContractNumber
required: true
- ref: undertaker
required: true
- ref: createdAt
required: true
- ref: updatedAt
required: true
- ref: deletedAt
required: true
... ...
version: v1
kind: Method
metadata:
name: createCooperationContractUndertaker
type: command
description: 创建
result:
- name: cooperationContractUndertaker
type:
schema: cooperationContractUndertaker
required: true
... ...
version: v1
kind: Method
metadata:
name: getCooperationContractUndertaker
type: query
description: 返回
payload:
- ref: cooperationContractUndertakerId
required: true
result:
- name: cooperationContractUndertaker
type:
schema: cooperationContractUndertaker
required: true
... ...
version: v1
kind: Method
metadata:
name: listCooperationContractUndertaker
type: query
description: 返回列表
payload:
- ref: offset
required: true
- ref: limit
required: true
result:
- ref: count
required: true
- name: cooperationContractUndertakers
type:
array: cooperationContractUndertaker
required: true
... ...
version: v1
kind: Method
metadata:
name: removeCooperationContractUndertaker
type: command
description: 移除
payload:
- ref: cooperationContractUndertakerId
required: true
result:
- name: cooperationContractUndertaker
type:
schema: cooperationContractUndertaker
required: true
... ...
version: v1
kind: Method
metadata:
name: updateCooperationContractUndertaker
type: command
description: 更新
payload:
- ref: cooperationContractUndertakerId
required: true
result:
- name: cooperationContractUndertaker
type:
schema: cooperationContractUndertaker
required: true
... ...
version: v1
kind: Service
metadata:
name: cooperationContractUndertaker
description:
... ...
... ... @@ -20,3 +20,4 @@ metadata:
type:
schema: creditAccount
required: true
\ No newline at end of file
... ...