作者 陈志颖

fix:代码错误xiugai

... ... @@ -4,6 +4,7 @@ import (
"fmt"
"github.com/beego/beego/v2/server/web"
_ "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg"
_ "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/port/beego"
)
func main() {
... ...
... ... @@ -111,9 +111,6 @@ func (dividendsOrder *DividendsOrder) Update(data map[string]interface{}) error
if userType, ok := data["userType"]; ok {
dividendsOrder.OrderSalesman.UserType = userType.(int32)
}
if status, ok := data["status"]; ok {
dividendsOrder.OrderSalesman.Status = status.(int32)
}
if orderTime, ok := data["orderTime"]; ok {
dividendsOrder.OrderTime = orderTime.(time.Time)
}
... ...
... ... @@ -2,6 +2,10 @@ package domain
// Relevant 共创合约相关人值对象
type Relevant struct {
// 相关人id
RelevantId int64 `json:"relevantId"`
// 共创合约编号
CooperationContractNumber string `json:"cooperationContractNumber"`
// 用户ID,通过集成REST上下文获取,可翻译成发起人、承接人、推荐人、业务员
UserId int64 `json:"userId,string"`
// 用户基本id
... ...
... ... @@ -16,7 +16,7 @@ type ContractUndertakerFeedback struct {
// 共创合约编号
CooperationContractNumber string `comment:"共创合约编号"`
// 共创合约承接人
ContractUndertaker *domain.User `comment:"共创合约承接人"`
ContractUndertaker *domain.Undertaker `comment:"共创合约承接人"`
// 共创模式编号
CooperationModeNumber string `comment:"共创模式编号"`
// 数据所属组织机构
... ...
... ... @@ -11,8 +11,26 @@ type CooperationContractRelevant struct {
CooperationContractRelevantId int64 `comment:"共创合约相关人id" pg:"pk:cooperation_contract_relevant_id"`
// 共创合约编号
CooperationContractNumber string `comment:"共创合约编号"`
// 相关人
Relevant *domain.Relevant `comment:"相关人"`
// 合约人userId
UserId int64 `comment:"合约人userId"`
//合约人userBaseId
UserBaseId int64 `comment:"合约人userBaseId"`
//合约人所属组织机构
Org *domain.Org `comment:"合约人所属组织机构"`
//合约人关联的组织机构
Orgs []*domain.Org `comment:"合约人关联的组织机构"`
//合约人所属部门
Department *domain.Department `comment:"合约人所属部门"`
//合约人角色
Role *domain.Role `comment:"合约人角色"`
//合约人用户信息
UserInfo *domain.UserInfo `comment:"合约人用户信息"`
//合约人用户类型
UserType int32 `comment:"合约人用户类型"`
//合约人状态
Status int32 `comment:"合约人状态"`
//合约人公司
Company *domain.Company `comment:"合约人公司"`
// 更新时间
UpdatedAt time.Time `comment:"更新时间"`
// 删除时间
... ...
... ... @@ -16,7 +16,7 @@ type DividendsOrder struct {
// 分红订单金额
DividendsOrderAmount float64 `comment:"分红订单金额"`
// 订单业务员
OrderSalesman *domain.User `comment:"订单业务员"`
OrderSalesman *domain.Salesman `comment:"订单业务员"`
// 订单产生时间
OrderTime time.Time `comment:"订单产生时间"`
// 分红订单分红时间
... ...
... ... @@ -55,16 +55,16 @@ func TransformToCooperationContractDomainModelFromPgModels(
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,
UserId: relevant.UserId,
UserBaseId: relevant.UserBaseId,
Org: relevant.Org,
Orgs: relevant.Orgs,
Department: relevant.Department,
Role: relevant.Role,
UserInfo: relevant.UserInfo,
UserType: relevant.UserType,
Status: relevant.Status,
Company: relevant.Company,
})
}
// 承接人列表
... ...
... ... @@ -9,9 +9,22 @@ func TransformToCooperationContractRelevantDomainModelFromPgModels(cooperationCo
return &domain.CooperationContractRelevant{
CooperationContractRelevantId: cooperationContractRelevantModel.CooperationContractRelevantId,
CooperationContractNumber: cooperationContractRelevantModel.CooperationContractNumber,
Relevant: cooperationContractRelevantModel.Relevant,
UpdatedAt: cooperationContractRelevantModel.UpdatedAt,
DeletedAt: cooperationContractRelevantModel.DeletedAt,
CreatedAt: cooperationContractRelevantModel.CreatedAt,
Relevant: &domain.Relevant{
RelevantId: cooperationContractRelevantModel.CooperationContractRelevantId,
CooperationContractNumber: cooperationContractRelevantModel.CooperationContractNumber,
UserId: cooperationContractRelevantModel.UserId,
UserBaseId: cooperationContractRelevantModel.UserBaseId,
Org: cooperationContractRelevantModel.Org,
Orgs: cooperationContractRelevantModel.Orgs,
Department: cooperationContractRelevantModel.Department,
Role: cooperationContractRelevantModel.Role,
UserInfo: cooperationContractRelevantModel.UserInfo,
UserType: cooperationContractRelevantModel.UserType,
Status: cooperationContractRelevantModel.Status,
Company: cooperationContractRelevantModel.Company,
},
UpdatedAt: cooperationContractRelevantModel.UpdatedAt,
DeletedAt: cooperationContractRelevantModel.DeletedAt,
CreatedAt: cooperationContractRelevantModel.CreatedAt,
}, nil
}
... ...
... ... @@ -5,10 +5,7 @@ import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg/models"
)
func TransformToDividendsOrderDomainModelFromPgModels(
dividendsOrderModel *models.DividendsOrder,
goods []*models.OrderGood,
) (*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{
... ...
... ... @@ -138,7 +138,13 @@ func (repository *ContractUndertakerFeedbackRepository) FindOne(queryOptions map
if contractUndertakerFeedbackModel.FeedbackId == 0 {
return nil, nil
} else {
return transform.TransformToContractUndertakerFeedbackDomainModelFromPgModels(contractUndertakerFeedbackModel)
// 获取共创模式
cooperationModeModel := new(models.CooperationMode)
cooperationModeQuery := tx.Model(cooperationModeModel)
if err := cooperationModeQuery.Where("cooperation_mode_number = ?", contractUndertakerFeedbackModel.CooperationModeNumber).First(); err != nil {
return nil, err
}
return transform.TransformToContractUndertakerFeedbackDomainModelFromPgModels(contractUndertakerFeedbackModel, cooperationModeModel)
}
}
func (repository *ContractUndertakerFeedbackRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.ContractUndertakerFeedback, error) {
... ... @@ -152,7 +158,13 @@ func (repository *ContractUndertakerFeedbackRepository) Find(queryOptions map[st
return 0, contractUndertakerFeedbacks, err
} else {
for _, contractUndertakerFeedbackModel := range contractUndertakerFeedbackModels {
if contractUndertakerFeedback, err := transform.TransformToContractUndertakerFeedbackDomainModelFromPgModels(contractUndertakerFeedbackModel); err != nil {
// 获取共创模式
cooperationModeModel := new(models.CooperationMode)
cooperationModeQuery := tx.Model(cooperationModeModel)
if err := cooperationModeQuery.Where("cooperation_mode_number = ?", contractUndertakerFeedbackModel.CooperationModeNumber).First(); err != nil {
return 0, nil, err
}
if contractUndertakerFeedback, err := transform.TransformToContractUndertakerFeedbackDomainModelFromPgModels(contractUndertakerFeedbackModel, cooperationModeModel); err != nil {
return 0, contractUndertakerFeedbacks, err
} else {
contractUndertakerFeedbacks = append(contractUndertakerFeedbacks, contractUndertakerFeedback)
... ...
... ... @@ -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"
... ... @@ -157,7 +158,13 @@ func (repository *CooperationApplicationRepository) FindOne(queryOptions map[str
if cooperationApplicationModel.CooperationApplicationId == 0 {
return nil, nil
} else {
return transform.TransformToCooperationApplicationDomainModelFromPgModels(cooperationApplicationModel)
// 获取共创项目
cooperationProjectModel := new(models.CooperationProject)
cooperationProjectQuery := tx.Model(cooperationProjectModel)
if err := cooperationProjectQuery.Where("cooperation_project_number = ?", cooperationApplicationModel.CooperationProjectNumber).First(); err != nil {
return nil, err
}
return transform.TransformToCooperationApplicationDomainModelFromPgModels(cooperationApplicationModel, cooperationProjectModel)
}
}
func (repository *CooperationApplicationRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.CooperationApplication, error) {
... ... @@ -171,7 +178,13 @@ func (repository *CooperationApplicationRepository) Find(queryOptions map[string
return 0, cooperationApplications, err
} else {
for _, cooperationApplicationModel := range cooperationApplicationModels {
if cooperationApplication, err := transform.TransformToCooperationApplicationDomainModelFromPgModels(cooperationApplicationModel); err != nil {
// 获取共创项目
cooperationProjectModel := new(models.CooperationProject)
cooperationProjectQuery := tx.Model(cooperationProjectModel)
if err := cooperationProjectQuery.Where("cooperation_project_number = ?", cooperationApplicationModel.CooperationProjectNumber).First(); err != nil {
return 0, nil, err
}
if cooperationApplication, err := transform.TransformToCooperationApplicationDomainModelFromPgModels(cooperationApplicationModel, cooperationProjectModel); err != nil {
return 0, cooperationApplications, err
} else {
cooperationApplications = append(cooperationApplications, cooperationApplication)
... ...
... ... @@ -3,14 +3,13 @@ package repository
import (
"fmt"
"github.com/go-pg/pg/v10"
"time"
"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"
"time"
)
type CooperationContractRepository struct {
... ... @@ -98,80 +97,88 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
cooperationContract.UpdatedAt,
); err != nil {
return cooperationContract, err
} else {
// 新增相关人
var relevantPeopleModel []*models.CooperationContractRelevant
for _, relevant := range cooperationContract.RelevantPeople {
relevantPeopleModel = append(relevantPeopleModel, &models.CooperationContractRelevant{
CooperationContractNumber: cooperationContract.CooperationContractNumber,
Relevant: relevant,
UpdatedAt: time.Time{},
DeletedAt: time.Time{},
CreatedAt: time.Now(),
})
}
if _, err := tx.Model(&relevantPeopleModel).Insert(); err != nil {
return nil, err
}
}
// 新增相关人
var relevantPeopleModel []*models.CooperationContractRelevant
for _, relevant := range cooperationContract.RelevantPeople {
relevantPeopleModel = append(relevantPeopleModel, &models.CooperationContractRelevant{
CooperationContractNumber: cooperationContract.CooperationContractNumber,
UserId: relevant.UserId,
UserBaseId: relevant.UserBaseId,
Org: relevant.Org,
Orgs: relevant.Orgs,
Department: relevant.Department,
Role: relevant.Role,
UserInfo: relevant.UserInfo,
UserType: relevant.UserType,
Status: relevant.Status,
Company: relevant.Company,
UpdatedAt: time.Now(),
DeletedAt: time.Time{},
CreatedAt: time.Time{},
})
}
if _, err := tx.Model(&relevantPeopleModel).Insert(); err != nil {
return nil, err
}
// 新增承接人
var undertakersModel []*models.CooperationContractUndertaker
for _, undertaker := range cooperationContract.Undertakers {
undertakersModel = append(undertakersModel, &models.CooperationContractUndertaker{
CooperationContractNumber: cooperationContract.CooperationContractNumber,
Undertaker: undertaker,
CreatedAt: time.Time{},
UpdatedAt: time.Time{},
DeletedAt: time.Now(),
})
}
if _, err := tx.Model(&undertakersModel).Insert(); err != nil {
return nil, err
}
// 新增承接人
var undertakersModel []*models.CooperationContractUndertaker
for _, undertaker := range cooperationContract.Undertakers {
undertakersModel = append(undertakersModel, &models.CooperationContractUndertaker{
CooperationContractNumber: cooperationContract.CooperationContractNumber,
Undertaker: undertaker,
CreatedAt: time.Time{},
UpdatedAt: time.Time{},
DeletedAt: time.Now(),
})
}
if _, err := tx.Model(&undertakersModel).Insert(); err != nil {
return nil, err
}
// 新增分红激励规则
var dividendsIncentivesRulesModel []*models.DividendsIncentivesRule
for _, rule := range cooperationContract.DividendsIncentivesRules {
dividendsIncentivesRulesModel = append(dividendsIncentivesRulesModel, &models.DividendsIncentivesRule{
CooperationContractNumber: cooperationContract.CooperationContractNumber,
ReferrerPercentage: rule.ReferrerPercentage,
SalesmanPercentage: rule.SalesmanPercentage,
DividendsIncentivesPercentage: rule.DividendsIncentivesPercentage,
DividendsIncentivesStage: rule.DividendsIncentivesStage,
DividendsIncentivesStageStart: rule.DividendsIncentivesStageStart,
DividendsIncentivesStageEnd: rule.DividendsIncentivesStageEnd,
Org: rule.Org,
Company: rule.Company,
UpdatedAt: time.Time{},
DeletedAt: time.Time{},
CreatedAt: time.Now(),
})
}
if _, err := tx.Model(&dividendsIncentivesRulesModel).Insert(); err != nil {
return nil, err
}
// 新增金额激励规则
var moneyIncentivesRulesModel []*models.MoneyIncentivesRule
for _, rule := range cooperationContract.MoneyIncentivesRules {
moneyIncentivesRulesModel = append(moneyIncentivesRulesModel, &models.MoneyIncentivesRule{
CooperationContractNumber: cooperationContract.CooperationContractNumber,
MoneyIncentivesAmount: rule.MoneyIncentivesAmount,
MoneyIncentivesStage: rule.MoneyIncentivesStage,
MoneyIncentivesStageStart: rule.MoneyIncentivesStageStart,
MoneyIncentivesStageEnd: rule.MoneyIncentivesStageEnd,
MoneyIncentivesTime: rule.MoneyIncentivesTime,
ReferrerPercentage: rule.ReferrerPercentage,
SalesmanPercentage: rule.SalesmanPercentage,
Org: rule.Org,
Company: rule.Company,
UpdatedAt: time.Time{},
DeletedAt: time.Time{},
CreatedAt: time.Now(),
})
}
if _, err := tx.Model(&moneyIncentivesRulesModel).Insert(); err != nil {
return nil, err
}
// 新增分红激励规则
var dividendsIncentivesRulesModel []*models.DividendsIncentivesRule
for _, rule := range cooperationContract.DividendsIncentivesRules {
dividendsIncentivesRulesModel = append(dividendsIncentivesRulesModel, &models.DividendsIncentivesRule{
CooperationContractNumber: cooperationContract.CooperationContractNumber,
ReferrerPercentage: rule.ReferrerPercentage,
SalesmanPercentage: rule.SalesmanPercentage,
DividendsIncentivesPercentage: rule.DividendsIncentivesPercentage,
DividendsIncentivesStage: rule.DividendsIncentivesStage,
DividendsIncentivesStageStart: rule.DividendsIncentivesStageStart,
DividendsIncentivesStageEnd: rule.DividendsIncentivesStageEnd,
Org: rule.Org,
Company: rule.Company,
UpdatedAt: time.Time{},
DeletedAt: time.Time{},
CreatedAt: time.Now(),
})
}
if _, err := tx.Model(&dividendsIncentivesRulesModel).Insert(); err != nil {
return nil, err
}
// 新增金额激励规则
var moneyIncentivesRulesModel []*models.MoneyIncentivesRule
for _, rule := range cooperationContract.MoneyIncentivesRules {
moneyIncentivesRulesModel = append(moneyIncentivesRulesModel, &models.MoneyIncentivesRule{
CooperationContractNumber: cooperationContract.CooperationContractNumber,
MoneyIncentivesAmount: rule.MoneyIncentivesAmount,
MoneyIncentivesStage: rule.MoneyIncentivesStage,
MoneyIncentivesStageStart: rule.MoneyIncentivesStageStart,
MoneyIncentivesStageEnd: rule.MoneyIncentivesStageEnd,
MoneyIncentivesTime: rule.MoneyIncentivesTime,
ReferrerPercentage: rule.ReferrerPercentage,
SalesmanPercentage: rule.SalesmanPercentage,
Org: rule.Org,
Company: rule.Company,
UpdatedAt: time.Time{},
DeletedAt: time.Time{},
CreatedAt: time.Now(),
})
}
if _, err := tx.Model(&moneyIncentivesRulesModel).Insert(); err != nil {
return nil, err
}
} else {
if _, err := tx.QueryOne(
... ... @@ -215,53 +222,80 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
cooperationContract.Identify(),
); err != nil {
return cooperationContract, err
} else {
// 获取相关人列表
var cooperationContractRelevantModels []*models.CooperationContractRelevant
cooperationContractRelevantQuery := tx.Model(&cooperationContractRelevantModels)
if err := cooperationContractRelevantQuery.Where("cooperation_contract_number = ?", cooperationContract.CooperationContractNumber).Select(); err != nil {
return nil, err
}
}
// 获取相关人列表
var cooperationContractRelevantModels []*models.CooperationContractRelevant
cooperationContractRelevantQuery := tx.Model(&cooperationContractRelevantModels)
if err := cooperationContractRelevantQuery.Where("cooperation_contract_number = ?", cooperationContract.CooperationContractNumber).Select(); err != nil {
return nil, err
}
//var cooperationContractRelevantModelsUpdate []*models.CooperationContractRelevant // 待更新的相关人
//var cooperationContractRelevantModelsDelete []*models.CooperationContractRelevant // 待删除的相关人
//var cooperationContractRelevantModelsCreate []*models.CooperationContractRelevant // 待增加的相关人
//
//for _, cooperationContractRelevantModels := range cooperationContractRelevantModels {
// for _, cooperationContractRelevantDomain := range cooperationContract.RelevantPeople {
//
// }
//}
//var cooperationContractRelevantModelsUpdate []*models.CooperationContractRelevant // 待更新的相关人
//var cooperationContractRelevantModelsDelete []*models.CooperationContractRelevant // 待删除的相关人
//var cooperationContractRelevantModelsCreate []*models.CooperationContractRelevant // 待增加的相关人
// 更新的相关人
var relevantIdsHave []int64
var relevantIdsModify []int64
//var relevantIdsUpdate []int64
// 删除的相关人
for _, cooperationContractRelevantModel := range cooperationContractRelevantModels {
relevantIdsHave = append(relevantIdsHave, cooperationContractRelevantModel.CooperationContractRelevantId)
}
// 新增的相关人
for _, cooperationContractRelevantDomain := range cooperationContract.RelevantPeople {
relevantIdsModify = append(relevantIdsModify, cooperationContractRelevantDomain.RelevantId)
}
//TODO 更新承接人
// 获取承接人列表
var cooperationContractUndertakerModels []*models.CooperationContractUndertaker
cooperationContractUndertakerQuery := tx.Model(&cooperationContractUndertakerModels)
if err := cooperationContractUndertakerQuery.Where("cooperation_contract_number = ?", cooperationContract.CooperationContractNumber).Select(); err != nil {
return nil, err
}
// 待更新的相关人
//relevantIdsUpdate := utils.Intersect(relevantIdsHave, relevantIdsModify)
//TODO 更新分红激励规则
// 获取分红激励规则列表
var dividendsIncentivesRuleModels []*models.DividendsIncentivesRule
dividendsIncentivesRuleQuery := tx.Model(&dividendsIncentivesRuleModels)
if err := dividendsIncentivesRuleQuery.Where("cooperation_contract_number = ?", cooperationContract.CooperationContractNumber).Select(); err != nil {
return nil, err
}
var relevantPeopleModelUpdate []*models.CooperationContractRelevant
for _, cooperationContractRelevantDomain := range cooperationContract.RelevantPeople {
relevantPeopleModelUpdate = append(relevantPeopleModelUpdate, &models.CooperationContractRelevant{
CooperationContractRelevantId: cooperationContractRelevantDomain.RelevantId,
CooperationContractNumber: cooperationContractRelevantDomain.CooperationContractNumber,
UserId: cooperationContractRelevantDomain.UserId,
UserBaseId: cooperationContractRelevantDomain.UserBaseId,
Org: cooperationContractRelevantDomain.Org,
Orgs: cooperationContractRelevantDomain.Orgs,
Department: cooperationContractRelevantDomain.Department,
Role: cooperationContractRelevantDomain.Role,
UserInfo: cooperationContractRelevantDomain.UserInfo,
UserType: cooperationContractRelevantDomain.UserType,
Status: cooperationContractRelevantDomain.Status,
Company: cooperationContractRelevantDomain.Company,
UpdatedAt: time.Now(),
DeletedAt: time.Time{},
CreatedAt: time.Time{},
})
}
//TODO 更新金额激励规则
// 获取金额激励规则列表
var moneyIncentivesRuleModels []*models.MoneyIncentivesRule
moneyIncentivesRuleQuery := tx.Model(&moneyIncentivesRuleModels)
if err := moneyIncentivesRuleQuery.Where("cooperation_contract_number = ?", cooperationContract.CooperationContractNumber).Select(); err != nil {
return nil, err
}
// 待删除的相关人
// 待新增的相关人
//TODO 更新承接人
// 获取承接人列表
var cooperationContractUndertakerModels []*models.CooperationContractUndertaker
cooperationContractUndertakerQuery := tx.Model(&cooperationContractUndertakerModels)
if err := cooperationContractUndertakerQuery.Where("cooperation_contract_number = ?", cooperationContract.CooperationContractNumber).Select(); err != nil {
return nil, err
}
//TODO 更新分红激励规则
// 获取分红激励规则列表
var dividendsIncentivesRuleModels []*models.DividendsIncentivesRule
dividendsIncentivesRuleQuery := tx.Model(&dividendsIncentivesRuleModels)
if err := dividendsIncentivesRuleQuery.Where("cooperation_contract_number = ?", cooperationContract.CooperationContractNumber).Select(); err != nil {
return nil, err
}
//TODO 更新金额激励规则
// 获取金额激励规则列表
var moneyIncentivesRuleModels []*models.MoneyIncentivesRule
moneyIncentivesRuleQuery := tx.Model(&moneyIncentivesRuleModels)
if err := moneyIncentivesRuleQuery.Where("cooperation_contract_number = ?", cooperationContract.CooperationContractNumber).Select(); err != nil {
return nil, err
}
}
return cooperationContract, nil
... ... @@ -343,8 +377,8 @@ func (repository *CooperationContractRepository) Find(queryOptions map[string]in
} else {
for _, cooperationContractModel := range cooperationContractModels {
// 获取共创模式
cooperationModeModels := new(models.CooperationMode)
cooperationModeQuery := tx.Model(cooperationModeModels)
cooperationModeModel := new(models.CooperationMode)
cooperationModeQuery := tx.Model(cooperationModeModel)
if err := cooperationModeQuery.Where("cooperation_mode_number = ?", cooperationContractModel.CooperationModeNumber).First(); err != nil {
return 0, nil, err
}
... ... @@ -374,7 +408,7 @@ func (repository *CooperationContractRepository) Find(queryOptions map[string]in
}
if cooperationContract, err := transform.TransformToCooperationContractDomainModelFromPgModels(
cooperationContractModel,
cooperationModeModels,
cooperationModeModel,
dividendsIncentivesRuleModels,
moneyIncentivesRuleModels,
cooperationContractRelevantModels,
... ...
... ... @@ -3,6 +3,7 @@ package repository
import (
"fmt"
"github.com/go-pg/pg/v10"
"time"
"github.com/linmadan/egglib-go/persistent/pg/sqlbuilder"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
... ... @@ -98,6 +99,26 @@ func (repository *DividendsOrderRepository) Save(dividendsOrder *domain.Dividend
); err != nil {
return dividendsOrder, err
}
// 新增分红订单产品
var orderGoodsModel []*models.OrderGood
for _, good := range dividendsOrder.Goods {
orderGoodsModel = append(orderGoodsModel, &models.OrderGood{
OrderGoodAmount: good.OrderGoodAmount,
OrderGoodName: good.OrderGoodName,
OrderGoodPrice: good.OrderGoodPrice,
OrderGoodQuantity: good.OrderGoodQuantity,
DividendsOrderNumber: good.DividendsOrderNumber,
DividendsReturnedOrderNumber: good.DividendsReturnedOrderNumber,
CooperationContractNumber: good.CooperationContractNumber,
OrderGoodExpense: good.OrderGoodExpense,
CreatedAt: time.Now(),
DeletedAt: time.Time{},
UpdatedAt: time.Time{},
})
}
if _, err := tx.Model(&orderGoodsModel).Insert(); err != nil {
return nil, err
}
} else {
if _, err := tx.QueryOne(
pg.Scan(
... ... @@ -141,6 +162,8 @@ func (repository *DividendsOrderRepository) Save(dividendsOrder *domain.Dividend
); err != nil {
return dividendsOrder, err
}
//TODO 新增、更新、删除分红订单产品
}
return dividendsOrder, nil
}
... ...
... ... @@ -3,6 +3,7 @@ package repository
import (
"fmt"
"github.com/go-pg/pg/v10"
"time"
"github.com/linmadan/egglib-go/persistent/pg/sqlbuilder"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
... ... @@ -101,6 +102,26 @@ func (repository *DividendsReturnedOrderRepository) Save(dividendsReturnedOrder
); err != nil {
return dividendsReturnedOrder, err
}
// 新增订单产品
var orderGoodsModel []*models.OrderGood
for _, good := range dividendsReturnedOrder.Goods {
orderGoodsModel = append(orderGoodsModel, &models.OrderGood{
OrderGoodAmount: good.OrderGoodAmount,
OrderGoodName: good.OrderGoodName,
OrderGoodPrice: good.OrderGoodPrice,
OrderGoodQuantity: good.OrderGoodQuantity,
DividendsOrderNumber: good.DividendsOrderNumber,
DividendsReturnedOrderNumber: good.DividendsReturnedOrderNumber,
CooperationContractNumber: good.CooperationContractNumber,
OrderGoodExpense: good.OrderGoodExpense,
CreatedAt: time.Now(),
DeletedAt: time.Time{},
UpdatedAt: time.Time{},
})
}
if _, err := tx.Model(&orderGoodsModel).Insert(); err != nil {
return nil, err
}
} else {
if _, err := tx.QueryOne(
pg.Scan(
... ... @@ -146,6 +167,7 @@ func (repository *DividendsReturnedOrderRepository) Save(dividendsReturnedOrder
); err != nil {
return dividendsReturnedOrder, err
}
//TODO 新增、更新、删除分红退货单产品
}
return dividendsReturnedOrder, 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"
... ... @@ -55,7 +56,7 @@ func (repository *MoneyIncentivesRuleRepository) Save(moneyIncentivesRule *domai
}
if _, err := tx.QueryOne(
pg.Scan(
&moneyIncentivesRule.MoneyIcentivesRuleId,
&moneyIncentivesRule.MoneyIncentivesRuleId,
&moneyIncentivesRule.CooperationContractNumber,
&moneyIncentivesRule.MoneyIncentivesAmount,
&moneyIncentivesRule.MoneyIncentivesStage,
... ... @@ -71,7 +72,7 @@ func (repository *MoneyIncentivesRuleRepository) Save(moneyIncentivesRule *domai
&moneyIncentivesRule.CreatedAt,
),
fmt.Sprintf("INSERT INTO money_incentives_rules (%s) VALUES (%s) RETURNING %s", insertFieldsSnippet, insertPlaceHoldersSnippet, returningFieldsSnippet),
moneyIncentivesRule.MoneyIcentivesRuleId,
moneyIncentivesRule.MoneyIncentivesRuleId,
moneyIncentivesRule.CooperationContractNumber,
moneyIncentivesRule.MoneyIncentivesAmount,
moneyIncentivesRule.MoneyIncentivesStage,
... ... @@ -91,7 +92,7 @@ func (repository *MoneyIncentivesRuleRepository) Save(moneyIncentivesRule *domai
} else {
if _, err := tx.QueryOne(
pg.Scan(
&moneyIncentivesRule.MoneyIcentivesRuleId,
&moneyIncentivesRule.MoneyIncentivesRuleId,
&moneyIncentivesRule.CooperationContractNumber,
&moneyIncentivesRule.MoneyIncentivesAmount,
&moneyIncentivesRule.MoneyIncentivesStage,
... ... @@ -107,7 +108,7 @@ func (repository *MoneyIncentivesRuleRepository) Save(moneyIncentivesRule *domai
&moneyIncentivesRule.CreatedAt,
),
fmt.Sprintf("UPDATE money_incentives_rules SET %s WHERE money_incentives_rule_id=? RETURNING %s", updateFieldsSnippet, returningFieldsSnippet),
moneyIncentivesRule.MoneyIcentivesRuleId,
moneyIncentivesRule.MoneyIncentivesRuleId,
moneyIncentivesRule.CooperationContractNumber,
moneyIncentivesRule.MoneyIncentivesAmount,
moneyIncentivesRule.MoneyIncentivesStage,
... ...
package utils
func Intersect(nums1 []int64, nums2 []int64) []int64 {
if len(nums1) > len(nums2) {
return Intersect(nums2, nums1)
}
m := map[int64]int64{}
for _, num := range nums1 {
m[num]++
}
var intersection []int64
for _, num := range nums2 {
if m[num] > 0 {
intersection = append(intersection, num)
m[num]--
}
}
return intersection
}
... ...