作者 陈志颖

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

正在显示 22 个修改的文件 包含 325 行增加1 行删除
  1 +version: v1
  2 +kind: HttpApi
  3 +metadata:
  4 + service: cooperationContractUndertaker
  5 + path: /cooperation-contract-undertakers
  6 + endpoints:
  7 + - method: createCooperationContractUndertaker
  8 + route:
  9 + post: /
  10 + - method: updateCooperationContractUndertaker
  11 + route:
  12 + put: /{cooperationContractUndertakerId}
  13 + - method: getCooperationContractUndertaker
  14 + route:
  15 + get: /{cooperationContractUndertakerId}
  16 + - method: removeCooperationContractUndertaker
  17 + route:
  18 + delete: /{cooperationContractUndertakerId}
  19 + - method: listCooperationContractUndertaker
  20 + route:
  21 + get: /
  22 + params:
  23 + - name: offset
  24 + - name: limit
  1 +version: v1
  2 +kind: Attribute
  3 +metadata:
  4 + name: cooperationContractRelevantId
  5 + description: 共创合约相关人id
  6 + type:
  7 + primitive: int64
  1 +version: v1
  2 +kind: Attribute
  3 +metadata:
  4 + name: relevant
  5 + description: 相关人
  6 + type:
  7 + schema: relevant
  1 +version: v1
  2 +kind: Attribute
  3 +metadata:
  4 + name: cooperationContractUndertakerId
  5 + description: 共创合约承接人id
  6 + type:
  7 + primitive: int64
  1 +version: v1
  2 +kind: Attribute
  3 +metadata:
  4 + name: undertaker
  5 + description: 共创合约承接人
  6 + type:
  7 + schema: undertaker
@@ -4,4 +4,4 @@ metadata: @@ -4,4 +4,4 @@ metadata:
4 name: dividendsOrderNumber 4 name: dividendsOrderNumber
5 description: 分红订单号 5 description: 分红订单号
6 type: 6 type:
7 - primitive: int64 7 + primitive: string
  1 +
  2 +func CreateCooperationContractUndertakerRepository(options map[string]interface{}) (domain.CooperationContractUndertakerRepository, error) {
  3 + var transactionContext *pg.TransactionContext
  4 + if value, ok := options["transactionContext"]; ok {
  5 + transactionContext = value.(*pg.TransactionContext)
  6 + }
  7 + return repository.NewCooperationContractUndertakerRepository(transactionContext)
  8 +}
  1 +package domain
  2 +
  3 +// 共创合约承接人
  4 +type CooperationContractUndertaker struct {
  5 +}
  6 +
  7 +type CooperationContractUndertakerRepository interface {
  8 + Save(cooperationContractUndertaker *CooperationContractUndertaker) (*CooperationContractUndertaker, error)
  9 + Remove(cooperationContractUndertaker *CooperationContractUndertaker) (*CooperationContractUndertaker, error)
  10 + FindOne(queryOptions map[string]interface{}) (*CooperationContractUndertaker, error)
  11 + Find(queryOptions map[string]interface{}) (int64, []*CooperationContractUndertaker, error)
  12 +}
  13 +
  14 +func (cooperationContractUndertaker *CooperationContractUndertaker) Identify() interface{} {
  15 + if cooperationContractUndertaker.cooperationContractUndertakerId == 0 {
  16 + return nil
  17 + }
  18 + return cooperationContractUndertaker.cooperationContractUndertakerId
  19 +}
  20 +
  21 +func (cooperationContractUndertaker *CooperationContractUndertaker) Update(data map[string]interface{}) error {
  22 + return nil
  23 +}
  1 +package models
  2 +
  3 +type CooperationContractUndertaker struct {
  4 + tableName string `comment:"共创合约承接人" pg:"cooperation_contract_undertakers,alias:cooperation_contract_undertaker"`
  5 +}
  1 +package transform
  2 +
  3 +import (
  4 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
  5 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg/models"
  6 +)
  7 +
  8 +func TransformToCooperationContractUndertakerDomainModelFromPgModels(cooperationContractUndertakerModel *models.CooperationContractUndertaker) (*domain.CooperationContractUndertaker, error) {
  9 + return &domain.CooperationContractUndertaker{}, nil
  10 +}
  1 +package repository
  2 +
  3 +import (
  4 + "fmt"
  5 +
  6 + "github.com/linmadan/egglib-go/persistent/pg/sqlbuilder"
  7 + pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
  8 + "github.com/linmadan/egglib-go/utils/snowflake"
  9 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
  10 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg/models"
  11 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg/transform"
  12 +)
  13 +
  14 +type CooperationContractUndertakerRepository struct {
  15 + transactionContext *pgTransaction.TransactionContext
  16 +}
  17 +
  18 +func (repository *CooperationContractUndertakerRepository) nextIdentify() (int64, error) {
  19 + IdWorker, err := snowflake.NewIdWorker(1)
  20 + if err != nil {
  21 + return 0, err
  22 + }
  23 + id, err := IdWorker.NextId()
  24 + return id, err
  25 +}
  26 +func (repository *CooperationContractUndertakerRepository) Save(cooperationContractUndertaker *domain.CooperationContractUndertaker) (*domain.CooperationContractUndertaker, error) {
  27 + sqlBuildFields := []string{}
  28 + insertFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlBuildFields)
  29 + insertPlaceHoldersSnippet := sqlbuilder.SqlPlaceHoldersSnippet(sqlBuildFields)
  30 + returningFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlBuildFields)
  31 + updateFields := sqlbuilder.RemoveSqlFields(sqlBuildFields, "cooperationContractUndertaker_id")
  32 + updateFieldsSnippet := sqlbuilder.SqlUpdateFieldsSnippet(updateFields)
  33 + tx := repository.transactionContext.PgTx
  34 + if cooperationContractUndertaker.Identify() == nil {
  35 + cooperationContractUndertakerId, err := repository.nextIdentify()
  36 + if err != nil {
  37 + return cooperationContractUndertaker, err
  38 + } else {
  39 + cooperationContractUndertaker.CooperationContractUndertakerId = cooperationContractUndertakerId
  40 + }
  41 + if _, err := tx.QueryOne(
  42 + pg.Scan(),
  43 + fmt.Sprintf("INSERT INTO cooperation_contract_undertakers (%s) VALUES (%s) RETURNING %s", insertFieldsSnippet, insertPlaceHoldersSnippet, returningFieldsSnippet),
  44 + ); err != nil {
  45 + return cooperationContractUndertaker, err
  46 + }
  47 + } else {
  48 + if _, err := tx.QueryOne(
  49 + pg.Scan(),
  50 + fmt.Sprintf("UPDATE cooperation_contract_undertakers SET %s WHERE cooperation_contract_undertaker_id=? RETURNING %s", updateFieldsSnippet, returningFieldsSnippet),
  51 + cooperationContractUndertaker.Identify(),
  52 + ); err != nil {
  53 + return cooperationContractUndertaker, err
  54 + }
  55 + }
  56 + return cooperationContractUndertaker, nil
  57 +}
  58 +func (repository *CooperationContractUndertakerRepository) Remove(cooperationContractUndertaker *domain.CooperationContractUndertaker) (*domain.CooperationContractUndertaker, error) {
  59 + tx := repository.transactionContext.PgTx
  60 + cooperationContractUndertakerModel := new(models.CooperationContractUndertaker)
  61 + cooperationContractUndertakerModel.CooperationContractUndertakerId = cooperationContractUndertaker.Identify().(int64)
  62 + if _, err := tx.Model(cooperationContractUndertakerModel).WherePK().Delete(); err != nil {
  63 + return cooperationContractUndertaker, err
  64 + }
  65 + return cooperationContractUndertaker, nil
  66 +}
  67 +func (repository *CooperationContractUndertakerRepository) FindOne(queryOptions map[string]interface{}) (*domain.CooperationContractUndertaker, error) {
  68 + tx := repository.transactionContext.PgTx
  69 + cooperationContractUndertakerModel := new(models.CooperationContractUndertaker)
  70 + query := sqlbuilder.BuildQuery(tx.Model(cooperationContractUndertakerModel), queryOptions)
  71 + query.SetWhereByQueryOption("cooperation_contract_undertaker.cooperation_contract_undertaker_id = ?", "cooperationContractUndertakerId")
  72 + if err := query.First(); err != nil {
  73 + if err.Error() == "pg: no rows in result set" {
  74 + return nil, fmt.Errorf("没有此资源")
  75 + } else {
  76 + return nil, err
  77 + }
  78 + }
  79 + if cooperationContractUndertakerModel.CooperationContractUndertakerId == 0 {
  80 + return nil, nil
  81 + } else {
  82 + return transform.TransformToCooperationContractUndertakerDomainModelFromPgModels(cooperationContractUndertakerModel)
  83 + }
  84 +}
  85 +func (repository *CooperationContractUndertakerRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.CooperationContractUndertaker, error) {
  86 + tx := repository.transactionContext.PgTx
  87 + var cooperationContractUndertakerModels []*models.CooperationContractUndertaker
  88 + cooperationContractUndertakers := make([]*domain.CooperationContractUndertaker, 0)
  89 + query := sqlbuilder.BuildQuery(tx.Model(&cooperationContractUndertakerModels), queryOptions)
  90 + query.SetOffsetAndLimit(20)
  91 + query.SetOrderDirect("cooperation_contract_undertaker_id", "DESC")
  92 + if count, err := query.SelectAndCount(); err != nil {
  93 + return 0, cooperationContractUndertakers, err
  94 + } else {
  95 + for _, cooperationContractUndertakerModel := range cooperationContractUndertakerModels {
  96 + if cooperationContractUndertaker, err := transform.TransformToCooperationContractUndertakerDomainModelFromPgModels(cooperationContractUndertakerModel); err != nil {
  97 + return 0, cooperationContractUndertakers, err
  98 + } else {
  99 + cooperationContractUndertakers = append(cooperationContractUndertakers, cooperationContractUndertaker)
  100 + }
  101 + }
  102 + return int64(count), cooperationContractUndertakers, nil
  103 + }
  104 +}
  105 +func NewCooperationContractUndertakerRepository(transactionContext *pgTransaction.TransactionContext) (*CooperationContractUndertakerRepository, error) {
  106 + if transactionContext == nil {
  107 + return nil, fmt.Errorf("transactionContext参数不能为nil")
  108 + } else {
  109 + return &CooperationContractUndertakerRepository{
  110 + transactionContext: transactionContext,
  111 + }, nil
  112 + }
  113 +}
  1 +version: v1
  2 +kind: Schema
  3 +metadata:
  4 + name: cooperationContractRelevant
  5 + description: 共创合约相关人
  6 + attributes:
  7 + - ref: cooperationContractRelevantId
  8 + required: true
  9 + - ref: cooperationContractNumber
  10 + required: true
  11 + - ref: relevant
  12 + required: true
  13 + - ref: updatedAt
  14 + required: true
  15 + - ref: deletedAt
  16 + required: true
  17 + - ref: createdAt
  18 + required: true
  1 +version: v1
  2 +kind: Schema
  3 +metadata:
  4 + name: cooperationContractUndertaker
  5 + description: 共创合约承接人
  6 + attributes:
  7 + - ref: cooperationContractUndertakerId
  8 + required: true
  9 + - ref: cooperationContractNumber
  10 + required: true
  11 + - ref: undertaker
  12 + required: true
  13 + - ref: createdAt
  14 + required: true
  15 + - ref: updatedAt
  16 + required: true
  17 + - ref: deletedAt
  18 + required: true
  1 +version: v1
  2 +kind: Method
  3 +metadata:
  4 + name: createCooperationContractUndertaker
  5 + type: command
  6 + description: 创建
  7 + result:
  8 + - name: cooperationContractUndertaker
  9 + type:
  10 + schema: cooperationContractUndertaker
  11 + required: true
  1 +version: v1
  2 +kind: Method
  3 +metadata:
  4 + name: getCooperationContractUndertaker
  5 + type: query
  6 + description: 返回
  7 + payload:
  8 + - ref: cooperationContractUndertakerId
  9 + required: true
  10 + result:
  11 + - name: cooperationContractUndertaker
  12 + type:
  13 + schema: cooperationContractUndertaker
  14 + required: true
  1 +version: v1
  2 +kind: Method
  3 +metadata:
  4 + name: listCooperationContractUndertaker
  5 + type: query
  6 + description: 返回列表
  7 + payload:
  8 + - ref: offset
  9 + required: true
  10 + - ref: limit
  11 + required: true
  12 + result:
  13 + - ref: count
  14 + required: true
  15 + - name: cooperationContractUndertakers
  16 + type:
  17 + array: cooperationContractUndertaker
  18 + required: true
  1 +version: v1
  2 +kind: Method
  3 +metadata:
  4 + name: removeCooperationContractUndertaker
  5 + type: command
  6 + description: 移除
  7 + payload:
  8 + - ref: cooperationContractUndertakerId
  9 + required: true
  10 + result:
  11 + - name: cooperationContractUndertaker
  12 + type:
  13 + schema: cooperationContractUndertaker
  14 + required: true
  1 +version: v1
  2 +kind: Method
  3 +metadata:
  4 + name: updateCooperationContractUndertaker
  5 + type: command
  6 + description: 更新
  7 + payload:
  8 + - ref: cooperationContractUndertakerId
  9 + required: true
  10 + result:
  11 + - name: cooperationContractUndertaker
  12 + type:
  13 + schema: cooperationContractUndertaker
  14 + required: true
  1 +version: v1
  2 +kind: Service
  3 +metadata:
  4 + name: cooperationContractUndertaker
  5 + description:
@@ -20,3 +20,4 @@ metadata: @@ -20,3 +20,4 @@ metadata:
20 type: 20 type:
21 schema: creditAccount 21 schema: creditAccount
22 required: true 22 required: true
  23 +