作者 陈志颖

feat:共创合约仓储调整

... ... @@ -109,3 +109,19 @@ func CreateOrderGoodRepository(options map[string]interface{}) (domain.OrderGood
}
return repository.NewOrderGoodRepository(transactionContext)
}
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)
}
func CreateCooperationContractRelevantRepository(options map[string]interface{}) (domain.CooperationContractRelevantRepository, error) {
var transactionContext *pg.TransactionContext
if value, ok := options["transactionContext"]; ok {
transactionContext = value.(*pg.TransactionContext)
}
return repository.NewCooperationContractRelevantRepository(transactionContext)
}
... ...
... ... @@ -36,6 +36,10 @@ type CooperationContract struct {
DividendsIncentivesRules []*DividendsIncentivesRule `json:"dividendsIncentivesRules"`
// 金额激励规则
MoneyIncentivesRules []*MoneyIncentivesRule `json:"moneyIncentivesRules"`
// 共创合约相关人列表
RelevantPeople []*Relevant `json:"relevantPeople"`
// 共创承接人列表
Undertakers []*Undertaker `json:"undertakers"`
// 操作时间
OperateTime time.Time `json:"operateTime"`
// 创建时间
... ...
package domain
import "time"
// CooperationContractRelevant 共创合约相关人
type CooperationContractRelevant struct {
// 共创合约相关人id
CooperationContractRelevantId int64 `json:"cooperationContractRelevantId,string"`
// 共创合约编号
CooperationContractNumber string `json:"cooperationContractNumber"`
// 相关人
Relevant *Relevant `json:"relevant"`
// 更新时间
UpdatedAt time.Time `json:"updatedAt"`
// 删除时间
DeletedAt time.Time `json:"deletedAt"`
// 创建时间
CreatedAt time.Time `json:"createdAt"`
}
type CooperationContractRelevantRepository interface {
Save(cooperationContractRelevant *CooperationContractRelevant) (*CooperationContractRelevant, error)
Remove(cooperationContractRelevant *CooperationContractRelevant) (*CooperationContractRelevant, error)
FindOne(queryOptions map[string]interface{}) (*CooperationContractRelevant, error)
Find(queryOptions map[string]interface{}) (int64, []*CooperationContractRelevant, error)
}
func (cooperationContractRelevant *CooperationContractRelevant) Identify() interface{} {
if cooperationContractRelevant.CooperationContractRelevantId == 0 {
return nil
}
return cooperationContractRelevant.CooperationContractRelevantId
}
func (cooperationContractRelevant *CooperationContractRelevant) Update(data map[string]interface{}) error {
if cooperationContractRelevantId, ok := data["cooperationContractRelevantId"]; ok {
cooperationContractRelevant.CooperationContractRelevantId = cooperationContractRelevantId.(int64)
}
if cooperationContractNumber, ok := data["cooperationContractNumber"]; ok {
cooperationContractRelevant.CooperationContractNumber = cooperationContractNumber.(string)
}
if userId, ok := data["userId"]; ok {
cooperationContractRelevant.Relevant.UserId = userId.(int64)
}
if userBaseId, ok := data["userBaseId"]; ok {
cooperationContractRelevant.Relevant.UserBaseId = userBaseId.(int64)
}
if orgId, ok := data["orgId"]; ok {
cooperationContractRelevant.Relevant.Org.OrgId = orgId.(int64)
}
if orgName, ok := data["orgName"]; ok {
cooperationContractRelevant.Relevant.Org.OrgName = orgName.(string)
}
if companyId, ok := data["companyId"]; ok {
cooperationContractRelevant.Relevant.Org.Company.CompanyId = companyId.(int64)
}
if companyLogo, ok := data["companyLogo"]; ok {
cooperationContractRelevant.Relevant.Org.Company.CompanyLogo = companyLogo.(string)
}
if companyName, ok := data["companyName"]; ok {
cooperationContractRelevant.Relevant.Org.Company.CompanyName = companyName.(string)
}
if roleId, ok := data["roleId"]; ok {
cooperationContractRelevant.Relevant.Role.RoleId = roleId.(int64)
}
if roleName, ok := data["roleName"]; ok {
cooperationContractRelevant.Relevant.Role.RoleName = roleName.(string)
}
if userAvatar, ok := data["userAvatar"]; ok {
cooperationContractRelevant.Relevant.UserInfo.UserAvatar = userAvatar.(string)
}
if userEmail, ok := data["userEmail"]; ok {
cooperationContractRelevant.Relevant.UserInfo.UserEmail = userEmail.(string)
}
if userName, ok := data["userName"]; ok {
cooperationContractRelevant.Relevant.UserInfo.UserName = userName.(string)
}
if userPhone, ok := data["userPhone"]; ok {
cooperationContractRelevant.Relevant.UserInfo.UserPhone = userPhone.(string)
}
if userAccount, ok := data["userAccount"]; ok {
cooperationContractRelevant.Relevant.UserInfo.UserAccount = userAccount.(string)
}
if userType, ok := data["userType"]; ok {
cooperationContractRelevant.Relevant.UserType = userType.(int32)
}
if status, ok := data["status"]; ok {
cooperationContractRelevant.Relevant.Status = status.(int32)
}
return nil
}
... ...
package domain
import "time"
// CooperationContractUndertaker 共创合约承接人
type CooperationContractUndertaker struct {
// 共创合约承接人id
CooperationContractUndertakerId int64 `json:"cooperationContractUndertakerId,string"`
// 共创合约编号
CooperationContractNumber string `json:"cooperationContractNumber"`
// 共创合约承接人
Undertaker *Undertaker `json:"undertaker"`
// 创建时间
CreatedAt time.Time `json:"createdAt"`
// 更新时间
UpdatedAt time.Time `json:"updatedAt"`
// 删除时间
DeletedAt time.Time `json:"deletedAt"`
}
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 {
if cooperationContractNumber, ok := data["cooperationContractNumber"]; ok {
cooperationContractUndertaker.CooperationContractNumber = cooperationContractNumber.(string)
}
if userId, ok := data["userId"]; ok {
cooperationContractUndertaker.Undertaker.UserId = userId.(int64)
}
if userBaseId, ok := data["userBaseId"]; ok {
cooperationContractUndertaker.Undertaker.UserBaseId = userBaseId.(int64)
}
return nil
}
... ...
... ... @@ -24,6 +24,8 @@ type DividendsOrder struct {
Region *RegionInfo `json:"region"`
// 客户姓名
CustomerName string `json:"customerName"`
// 订单产品列表
Goods []*OrderGood `json:"goods"`
// 数据所属组织机构
Org *Org `json:"org"`
// 公司
... ...
... ... @@ -20,6 +20,8 @@ type DividendsReturnedOrder struct {
DividendsReturnedDate time.Time `json:"dividendsReturnedDate"`
// 退货区域
Region *RegionInfo `json:"region"`
// 退货单产品列表
Goods []*OrderGood `json:"goods"`
// 备注
Remarks string `json:"remarks"`
// 分红订单分红状态,1待分红,2已分红,3部分分红
... ...
... ... @@ -15,7 +15,9 @@ type OrderGood struct {
// 订单产品数量
OrderGoodQuantity int64 `json:"orderGoodQuantity,string"`
// 关联分红订单号
DividendsOrderNumber int64 `json:"dividendsOrderNumber,string"`
DividendsOrderNumber string `json:"dividendsOrderNumber"`
// 关联的分红退货单号
DividendsReturnedOrderNumber string `json:"dividendsReturnedOrderNumber"`
// 关联的共创合约编号
CooperationContractNumber string `json:"cooperationContractNumber"`
// 订单产品费用
... ... @@ -55,9 +57,6 @@ func (orderGood *OrderGood) Update(data map[string]interface{}) error {
if orderGoodQuantity, ok := data["orderGoodQuantity"]; ok {
orderGood.OrderGoodQuantity = orderGoodQuantity.(int64)
}
if dividendsOrderNumber, ok := data["dividendsOrderNumber"]; ok {
orderGood.DividendsOrderNumber = dividendsOrderNumber.(int64)
}
if cooperationContractNumber, ok := data["cooperationContractNumber"]; ok {
orderGood.CooperationContractNumber = cooperationContractNumber.(string)
}
... ...
package models
import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
"time"
)
type CooperationContractRelevant struct {
tableName string `comment:"共创合约相关人" pg:"cooperation_contract_relevants,alias:cooperation_contract_relevant"`
// 共创合约相关人id
CooperationContractRelevantId int64 `comment:"共创合约相关人id" pg:"pk:cooperation_contract_relevant_id"`
// 共创合约编号
CooperationContractNumber string `comment:"共创合约编号"`
// 相关人
Relevant *domain.Relevant `comment:"相关人"`
// 更新时间
UpdatedAt time.Time `comment:"更新时间"`
// 删除时间
DeletedAt time.Time `comment:"删除时间"`
// 创建时间
CreatedAt time.Time `comment:"创建时间"`
}
... ...
package models
import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
"time"
)
type CooperationContractUndertaker struct {
tableName string `comment:"共创合约承接人" pg:"cooperation_contract_undertakers,alias:cooperation_contract_undertaker"`
// 共创合约承接人id
CooperationContractUndertakerId int64 `comment:"共创合约承接人id" pg:"pk:cooperation_contract_undertaker_id"`
// 共创合约编号
CooperationContractNumber string `comment:"共创合约编号"`
// 共创合约承接人
Undertaker *domain.Undertaker `comment:"共创合约承接人"`
// 创建时间
CreatedAt time.Time `comment:"创建时间"`
// 更新时间
UpdatedAt time.Time `comment:"更新时间"`
// 删除时间
DeletedAt time.Time `comment:"删除时间"`
}
... ...
... ... @@ -10,7 +10,7 @@ type DividendsOrder struct {
// 分红订单ID
DividendsOrderId int64 `comment:"分红订单ID" pg:"pk:dividends_order_id"`
// 分红订单号
DividendsOrderNumber int64 `comment:"分红订单号"`
DividendsOrderNumber string `comment:"分红订单号"`
// 分红订单原单号
DividendsOriginalOrderNum string `comment:"分红订单原单号"`
// 分红订单金额
... ...
... ... @@ -15,7 +15,9 @@ type OrderGood struct {
// 订单产品数量
OrderGoodQuantity int64 `comment:"订单产品数量"`
// 关联分红订单号
DividendsOrderNumber int64 `comment:"关联分红订单号"`
DividendsOrderNumber string `comment:"关联分红订单号"`
// 关联的分红退货单号
DividendsReturnedOrderNumber string `comment:"关联的分红退货单号"`
// 关联的共创合约编号
CooperationContractNumber string `comment:"关联的共创合约编号"`
// 订单产品费用
... ...
... ... @@ -9,8 +9,10 @@ func TransformToCooperationContractDomainModelFromPgModels(
cooperationContractModel *models.CooperationContract,
cooperationMode *models.CooperationMode,
dividendsIncentivesRules []*models.DividendsIncentivesRule,
moneyIncentivesRules []*models.MoneyIncentivesRule) (*domain.CooperationContract, error) {
moneyIncentivesRules []*models.MoneyIncentivesRule,
relevantPeople []*models.CooperationContractRelevant,
undertakers []*models.CooperationContractUndertaker) (*domain.CooperationContract, error) {
// 分红激励规则
var dividendsIncentivesRulesDomain []*domain.DividendsIncentivesRule
for _, rule := range dividendsIncentivesRules {
dividendsIncentivesRulesDomain = append(dividendsIncentivesRulesDomain, &domain.DividendsIncentivesRule{
... ... @@ -29,7 +31,7 @@ func TransformToCooperationContractDomainModelFromPgModels(
CreatedAt: rule.CreatedAt,
})
}
// 金额激励规则
var moneyIncentivesRulesDomain []*domain.MoneyIncentivesRule
for _, rule := range moneyIncentivesRules {
moneyIncentivesRulesDomain = append(moneyIncentivesRulesDomain, &domain.MoneyIncentivesRule{
... ... @@ -49,7 +51,39 @@ func TransformToCooperationContractDomainModelFromPgModels(
CreatedAt: rule.CreatedAt,
})
}
// 相关人列表
var relevantPeopleDomain []*domain.Relevant
for _, relevant := range relevantPeople {
relevantPeopleDomain = append(relevantPeopleDomain, &domain.Relevant{
UserId: relevant.Relevant.UserId,
UserBaseId: relevant.Relevant.UserBaseId,
Org: relevant.Relevant.Org,
Orgs: relevant.Relevant.Orgs,
Department: relevant.Relevant.Department,
Role: relevant.Relevant.Role,
UserInfo: relevant.Relevant.UserInfo,
UserType: relevant.Relevant.UserType,
Status: relevant.Relevant.Status,
Company: relevant.Relevant.Company,
})
}
// 承接人列表
var undertakersDomain []*domain.Undertaker
for _, undertaker := range undertakers {
undertakersDomain = append(undertakersDomain, &domain.Undertaker{
UserId: undertaker.Undertaker.UserId,
UserBaseId: undertaker.Undertaker.UserBaseId,
Org: undertaker.Undertaker.Org,
Orgs: undertaker.Undertaker.Orgs,
Department: undertaker.Undertaker.Department,
Role: undertaker.Undertaker.Role,
UserInfo: undertaker.Undertaker.UserInfo,
UserType: undertaker.Undertaker.UserType,
Status: undertaker.Undertaker.Status,
Company: undertaker.Undertaker.Company,
ContractAttachment: undertaker.Undertaker.ContractAttachment,
})
}
return &domain.CooperationContract{
CooperationContractId: cooperationContractModel.CooperationContractId,
CooperationContractDescription: cooperationContractModel.CooperationContractDescription,
... ... @@ -75,6 +109,8 @@ func TransformToCooperationContractDomainModelFromPgModels(
},
DividendsIncentivesRules: dividendsIncentivesRulesDomain,
MoneyIncentivesRules: moneyIncentivesRulesDomain,
RelevantPeople: relevantPeopleDomain,
Undertakers: undertakersDomain,
Status: cooperationContractModel.Status,
Org: cooperationContractModel.Org,
Company: cooperationContractModel.Company,
... ...
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 TransformToCooperationContractRelevantDomainModelFromPgModels(cooperationContractRelevantModel *models.CooperationContractRelevant) (*domain.CooperationContractRelevant, error) {
return &domain.CooperationContractRelevant{
CooperationContractRelevantId: cooperationContractRelevantModel.CooperationContractRelevantId,
CooperationContractNumber: cooperationContractRelevantModel.CooperationContractNumber,
Relevant: cooperationContractRelevantModel.Relevant,
UpdatedAt: cooperationContractRelevantModel.UpdatedAt,
DeletedAt: cooperationContractRelevantModel.DeletedAt,
CreatedAt: cooperationContractRelevantModel.CreatedAt,
}, nil
}
... ...
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{
CooperationContractUndertakerId: cooperationContractUndertakerModel.CooperationContractUndertakerId,
CooperationContractNumber: cooperationContractUndertakerModel.CooperationContractNumber,
Undertaker: cooperationContractUndertakerModel.Undertaker,
CreatedAt: cooperationContractUndertakerModel.CreatedAt,
UpdatedAt: cooperationContractUndertakerModel.UpdatedAt,
DeletedAt: cooperationContractUndertakerModel.DeletedAt,
}, nil
}
... ...
... ... @@ -5,7 +5,27 @@ import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg/models"
)
func TransformToDividendsOrderDomainModelFromPgModels(dividendsOrderModel *models.DividendsOrder) (*domain.DividendsOrder, error) {
func TransformToDividendsOrderDomainModelFromPgModels(
dividendsOrderModel *models.DividendsOrder,
goods []*models.OrderGood,
) (*domain.DividendsOrder, error) {
var orderGoods []*domain.OrderGood
for _, good := range goods {
orderGoods = append(orderGoods, &domain.OrderGood{
OrderGoodId: good.OrderGoodId,
OrderGoodAmount: good.OrderGoodAmount,
OrderGoodName: good.OrderGoodName,
OrderGoodPrice: good.OrderGoodPrice,
OrderGoodQuantity: good.OrderGoodQuantity,
DividendsOrderNumber: good.DividendsReturnedOrderNumber,
DividendsReturnedOrderNumber: good.DividendsOrderNumber,
CooperationContractNumber: good.CooperationContractNumber,
OrderGoodExpense: good.OrderGoodExpense,
CreatedAt: good.CreatedAt,
DeletedAt: good.DeletedAt,
UpdatedAt: good.UpdatedAt,
})
}
return &domain.DividendsOrder{
DividendsOrderId: dividendsOrderModel.DividendsOrderId,
DividendsOrderNumber: dividendsOrderModel.DividendsOrderNumber,
... ... @@ -18,6 +38,7 @@ func TransformToDividendsOrderDomainModelFromPgModels(dividendsOrderModel *model
Region: dividendsOrderModel.Region,
CustomerName: dividendsOrderModel.CustomerName,
Org: dividendsOrderModel.Org,
Goods: orderGoods,
Company: dividendsOrderModel.Company,
CreatedAt: dividendsOrderModel.CreatedAt,
DeletedAt: dividendsOrderModel.DeletedAt,
... ...
... ... @@ -5,7 +5,26 @@ import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg/models"
)
func TransformToDividendsReturnedOrderDomainModelFromPgModels(dividendsReturnedOrderModel *models.DividendsReturnedOrder) (*domain.DividendsReturnedOrder, error) {
func TransformToDividendsReturnedOrderDomainModelFromPgModels(
dividendsReturnedOrderModel *models.DividendsReturnedOrder,
goods []*models.OrderGood) (*domain.DividendsReturnedOrder, error) {
var orderGoods []*domain.OrderGood
for _, good := range goods {
orderGoods = append(orderGoods, &domain.OrderGood{
OrderGoodId: good.OrderGoodId,
OrderGoodAmount: good.OrderGoodAmount,
OrderGoodName: good.OrderGoodName,
OrderGoodPrice: good.OrderGoodPrice,
OrderGoodQuantity: good.OrderGoodQuantity,
DividendsOrderNumber: good.DividendsReturnedOrderNumber,
DividendsReturnedOrderNumber: good.DividendsOrderNumber,
CooperationContractNumber: good.CooperationContractNumber,
OrderGoodExpense: good.OrderGoodExpense,
CreatedAt: good.CreatedAt,
DeletedAt: good.DeletedAt,
UpdatedAt: good.UpdatedAt,
})
}
return &domain.DividendsReturnedOrder{
DividendsReturnedOrderId: dividendsReturnedOrderModel.DividendsReturnedOrderId,
DividendsReturnedOrderNumber: dividendsReturnedOrderModel.DividendsReturnedOrderNumber,
... ... @@ -18,6 +37,7 @@ func TransformToDividendsReturnedOrderDomainModelFromPgModels(dividendsReturnedO
Remarks: dividendsReturnedOrderModel.Remarks,
DividendStatus: dividendsReturnedOrderModel.DividendStatus,
DividendTime: dividendsReturnedOrderModel.DividendTime,
Goods: orderGoods,
Org: dividendsReturnedOrderModel.Org,
Company: dividendsReturnedOrderModel.Company,
CreatedAt: dividendsReturnedOrderModel.CreatedAt,
... ...
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 CooperationContractRelevantRepository struct {
transactionContext *pgTransaction.TransactionContext
}
func (repository *CooperationContractRelevantRepository) nextIdentify() (int64, error) {
IdWorker, err := snowflake.NewIdWorker(1)
if err != nil {
return 0, err
}
id, err := IdWorker.NextId()
return id, err
}
func (repository *CooperationContractRelevantRepository) Save(cooperationContractRelevant *domain.CooperationContractRelevant) (*domain.CooperationContractRelevant, error) {
sqlBuildFields := []string{
"cooperation_contract_relevant_id",
"cooperation_contract_number",
"relevant",
"updated_at",
"deleted_at",
"created_at",
}
insertFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlBuildFields)
insertPlaceHoldersSnippet := sqlbuilder.SqlPlaceHoldersSnippet(sqlBuildFields)
returningFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlBuildFields)
updateFields := sqlbuilder.RemoveSqlFields(sqlBuildFields, "cooperationContractRelevant_id")
updateFieldsSnippet := sqlbuilder.SqlUpdateFieldsSnippet(updateFields)
tx := repository.transactionContext.PgTx
if cooperationContractRelevant.Identify() == nil {
cooperationContractRelevantId, err := repository.nextIdentify()
if err != nil {
return cooperationContractRelevant, err
} else {
cooperationContractRelevant.CooperationContractRelevantId = cooperationContractRelevantId
}
if _, err := tx.QueryOne(
pg.Scan(
&cooperationContractRelevant.CooperationContractRelevantId,
&cooperationContractRelevant.CooperationContractNumber,
&cooperationContractRelevant.Relevant,
&cooperationContractRelevant.UpdatedAt,
&cooperationContractRelevant.DeletedAt,
&cooperationContractRelevant.CreatedAt,
),
fmt.Sprintf("INSERT INTO cooperation_contract_relevants (%s) VALUES (%s) RETURNING %s", insertFieldsSnippet, insertPlaceHoldersSnippet, returningFieldsSnippet),
cooperationContractRelevant.CooperationContractRelevantId,
cooperationContractRelevant.CooperationContractNumber,
cooperationContractRelevant.Relevant,
cooperationContractRelevant.UpdatedAt,
cooperationContractRelevant.DeletedAt,
cooperationContractRelevant.CreatedAt,
); err != nil {
return cooperationContractRelevant, err
}
} else {
if _, err := tx.QueryOne(
pg.Scan(
&cooperationContractRelevant.CooperationContractRelevantId,
&cooperationContractRelevant.CooperationContractNumber,
&cooperationContractRelevant.Relevant,
&cooperationContractRelevant.UpdatedAt,
&cooperationContractRelevant.DeletedAt,
&cooperationContractRelevant.CreatedAt,
),
fmt.Sprintf("UPDATE cooperation_contract_relevants SET %s WHERE cooperation_contract_relevant_id=? RETURNING %s", updateFieldsSnippet, returningFieldsSnippet),
cooperationContractRelevant.CooperationContractRelevantId,
cooperationContractRelevant.CooperationContractNumber,
cooperationContractRelevant.Relevant,
cooperationContractRelevant.UpdatedAt,
cooperationContractRelevant.DeletedAt,
cooperationContractRelevant.CreatedAt,
cooperationContractRelevant.Identify(),
); err != nil {
return cooperationContractRelevant, err
}
}
return cooperationContractRelevant, nil
}
func (repository *CooperationContractRelevantRepository) Remove(cooperationContractRelevant *domain.CooperationContractRelevant) (*domain.CooperationContractRelevant, error) {
tx := repository.transactionContext.PgTx
cooperationContractRelevantModel := new(models.CooperationContractRelevant)
cooperationContractRelevantModel.CooperationContractRelevantId = cooperationContractRelevant.Identify().(int64)
if _, err := tx.Model(cooperationContractRelevantModel).WherePK().Delete(); err != nil {
return cooperationContractRelevant, err
}
return cooperationContractRelevant, nil
}
func (repository *CooperationContractRelevantRepository) FindOne(queryOptions map[string]interface{}) (*domain.CooperationContractRelevant, error) {
tx := repository.transactionContext.PgTx
cooperationContractRelevantModel := new(models.CooperationContractRelevant)
query := sqlbuilder.BuildQuery(tx.Model(cooperationContractRelevantModel), queryOptions)
query.SetWhereByQueryOption("cooperation_contract_relevant.cooperation_contract_relevant_id = ?", "cooperationContractRelevantId")
if err := query.First(); err != nil {
if err.Error() == "pg: no rows in result set" {
return nil, fmt.Errorf("没有此资源")
} else {
return nil, err
}
}
if cooperationContractRelevantModel.CooperationContractRelevantId == 0 {
return nil, nil
} else {
return transform.TransformToCooperationContractRelevantDomainModelFromPgModels(cooperationContractRelevantModel)
}
}
func (repository *CooperationContractRelevantRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.CooperationContractRelevant, error) {
tx := repository.transactionContext.PgTx
var cooperationContractRelevantModels []*models.CooperationContractRelevant
cooperationContractRelevants := make([]*domain.CooperationContractRelevant, 0)
query := sqlbuilder.BuildQuery(tx.Model(&cooperationContractRelevantModels), queryOptions)
query.SetOffsetAndLimit(20)
query.SetOrderDirect("cooperation_contract_relevant_id", "DESC")
if count, err := query.SelectAndCount(); err != nil {
return 0, cooperationContractRelevants, err
} else {
for _, cooperationContractRelevantModel := range cooperationContractRelevantModels {
if cooperationContractRelevant, err := transform.TransformToCooperationContractRelevantDomainModelFromPgModels(cooperationContractRelevantModel); err != nil {
return 0, cooperationContractRelevants, err
} else {
cooperationContractRelevants = append(cooperationContractRelevants, cooperationContractRelevant)
}
}
return int64(count), cooperationContractRelevants, nil
}
}
func NewCooperationContractRelevantRepository(transactionContext *pgTransaction.TransactionContext) (*CooperationContractRelevantRepository, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
} else {
return &CooperationContractRelevantRepository{
transactionContext: transactionContext,
}, nil
}
}
... ...
... ... @@ -2,6 +2,7 @@ package repository
import (
"fmt"
"github.com/go-pg/pg/v10"
"github.com/linmadan/egglib-go/persistent/pg/sqlbuilder"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
... ... @@ -167,7 +168,43 @@ func (repository *CooperationContractRepository) FindOne(queryOptions map[string
if cooperationContractModel.CooperationContractId == 0 {
return nil, nil
} else {
return transform.TransformToCooperationContractDomainModelFromPgModels(cooperationContractModel)
// 获取共创模式
cooperationModeModels := new(models.CooperationMode)
cooperationModeQuery := tx.Model(cooperationModeModels)
if err := cooperationModeQuery.Where("cooperation_mode_number = ?", cooperationContractModel.CooperationModeNumber).First(); err != nil {
return nil, err
}
// 获取分红激励规则列表
var dividendsIncentivesRuleModels []*models.DividendsIncentivesRule
dividendsIncentivesRuleQuery := tx.Model(&dividendsIncentivesRuleModels)
if err := dividendsIncentivesRuleQuery.Where("cooperation_contract_number = ?", cooperationContractModel.CooperationContractNumber).Select(); err != nil {
return nil, err
}
// 获取金额激励规则列表
var moneyIncentivesRuleModels []*models.MoneyIncentivesRule
moneyIncentivesRuleQuery := tx.Model(&moneyIncentivesRuleModels)
if err := moneyIncentivesRuleQuery.Where("cooperation_contract_number = ?", cooperationContractModel.CooperationContractNumber).Select(); err != nil {
return nil, err
}
// 获取承接人列表
var cooperationContractUndertakerModels []*models.CooperationContractUndertaker
cooperationContractUndertakerQuery := tx.Model(&cooperationContractUndertakerModels)
if err := cooperationContractUndertakerQuery.Where("cooperation_contract_number = ?", cooperationContractModel.CooperationContractNumber).Select(); err != nil {
return nil, err
}
// 获取相关人列表
var cooperationContractRelevantModels []*models.CooperationContractRelevant
cooperationContractRelevantQuery := tx.Model(&cooperationContractRelevantModels)
if err := cooperationContractRelevantQuery.Where("cooperation_contract_number = ?", cooperationContractModel.CooperationContractNumber).Select(); err != nil {
return nil, err
}
return transform.TransformToCooperationContractDomainModelFromPgModels(
cooperationContractModel,
cooperationModeModels,
dividendsIncentivesRuleModels,
moneyIncentivesRuleModels,
cooperationContractRelevantModels,
cooperationContractUndertakerModels)
}
}
func (repository *CooperationContractRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.CooperationContract, error) {
... ... @@ -181,7 +218,43 @@ func (repository *CooperationContractRepository) Find(queryOptions map[string]in
return 0, cooperationContracts, err
} else {
for _, cooperationContractModel := range cooperationContractModels {
if cooperationContract, err := transform.TransformToCooperationContractDomainModelFromPgModels(cooperationContractModel); err != nil {
// 获取共创模式
cooperationModeModels := new(models.CooperationMode)
cooperationModeQuery := tx.Model(cooperationModeModels)
if err := cooperationModeQuery.Where("cooperation_mode_number = ?", cooperationContractModel.CooperationModeNumber).First(); err != nil {
return 0, nil, err
}
// 获取分红激励规则列表
var dividendsIncentivesRuleModels []*models.DividendsIncentivesRule
dividendsIncentivesRuleQuery := tx.Model(&dividendsIncentivesRuleModels)
if err := dividendsIncentivesRuleQuery.Where("cooperation_contract_number = ?", cooperationContractModel.CooperationContractNumber).Select(); err != nil {
return 0, nil, err
}
// 获取金额激励规则列表
var moneyIncentivesRuleModels []*models.MoneyIncentivesRule
moneyIncentivesRuleQuery := tx.Model(&moneyIncentivesRuleModels)
if err := moneyIncentivesRuleQuery.Where("cooperation_contract_number = ?", cooperationContractModel.CooperationContractNumber).Select(); err != nil {
return 0, nil, err
}
// 获取承接人列表
var cooperationContractUndertakerModels []*models.CooperationContractUndertaker
cooperationContractUndertakerQuery := tx.Model(&cooperationContractUndertakerModels)
if err := cooperationContractUndertakerQuery.Where("cooperation_contract_number = ?", cooperationContractModel.CooperationContractNumber).Select(); err != nil {
return 0, nil, err
}
// 获取相关人列表
var cooperationContractRelevantModels []*models.CooperationContractRelevant
cooperationContractRelevantQuery := tx.Model(&cooperationContractRelevantModels)
if err := cooperationContractRelevantQuery.Where("cooperation_contract_number = ?", cooperationContractModel.CooperationContractNumber).Select(); err != nil {
return 0, nil, err
}
if cooperationContract, err := transform.TransformToCooperationContractDomainModelFromPgModels(
cooperationContractModel,
cooperationModeModels,
dividendsIncentivesRuleModels,
moneyIncentivesRuleModels,
cooperationContractRelevantModels,
cooperationContractUndertakerModels); err != nil {
return 0, cooperationContracts, err
} else {
cooperationContracts = append(cooperationContracts, cooperationContract)
... ...
package repository
import (
"fmt"
"github.com/go-pg/pg/v10"
"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{
"cooperation_contract_undertaker_id",
"cooperation_contract_number",
"undertaker",
"created_at",
"updated_at",
"deleted_at",
}
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(
&cooperationContractUndertaker.CooperationContractUndertakerId,
&cooperationContractUndertaker.CooperationContractNumber,
&cooperationContractUndertaker.Undertaker,
&cooperationContractUndertaker.CreatedAt,
&cooperationContractUndertaker.UpdatedAt,
&cooperationContractUndertaker.DeletedAt,
),
fmt.Sprintf("INSERT INTO cooperation_contract_undertakers (%s) VALUES (%s) RETURNING %s", insertFieldsSnippet, insertPlaceHoldersSnippet, returningFieldsSnippet),
cooperationContractUndertaker.CooperationContractUndertakerId,
cooperationContractUndertaker.CooperationContractNumber,
cooperationContractUndertaker.Undertaker,
cooperationContractUndertaker.CreatedAt,
cooperationContractUndertaker.UpdatedAt,
cooperationContractUndertaker.DeletedAt,
); err != nil {
return cooperationContractUndertaker, err
}
} else {
if _, err := tx.QueryOne(
pg.Scan(
&cooperationContractUndertaker.CooperationContractUndertakerId,
&cooperationContractUndertaker.CooperationContractNumber,
&cooperationContractUndertaker.Undertaker,
&cooperationContractUndertaker.CreatedAt,
&cooperationContractUndertaker.UpdatedAt,
&cooperationContractUndertaker.DeletedAt,
),
fmt.Sprintf("UPDATE cooperation_contract_undertakers SET %s WHERE cooperation_contract_undertaker_id=? RETURNING %s", updateFieldsSnippet, returningFieldsSnippet),
cooperationContractUndertaker.CooperationContractUndertakerId,
cooperationContractUndertaker.CooperationContractNumber,
cooperationContractUndertaker.Undertaker,
cooperationContractUndertaker.CreatedAt,
cooperationContractUndertaker.UpdatedAt,
cooperationContractUndertaker.DeletedAt,
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
}
}
... ...