作者 陈志颖

fix:数据模型增加唯一约束

... ... @@ -8,7 +8,7 @@ import (
type CooperationContractUndertaker struct {
tableName string `comment:"共创合约承接人" pg:"cooperation_contract_undertakers,alias:cooperation_contract_undertaker"`
// 共创合约承接人id
CooperationContractUndertakerId int64 `comment:"共创合约承接人id" pg:",pk"`
CooperationContractUndertakerId int64 `comment:"共创合约承接人id" pg:",pk,unique"`
// 共创合约编号
CooperationContractNumber string `comment:"共创合约编号"`
// 共创合约承接人uid
... ...
... ... @@ -8,7 +8,7 @@ import (
type DividendsIncentivesRule struct {
tableName string `comment:"金额激励规则实体" pg:"dividends_incentives_rules,alias:dividends_incentives_rule"`
// 分红规则ID
DividendsIncentivesRuleId int64 `comment:"分红规则ID" pg:",pk"`
DividendsIncentivesRuleId int64 `comment:"分红规则ID" pg:",pk,unique"`
// 关联的项目合约编号
CooperationContractNumber string `comment:"关联的项目合约编号"`
// 推荐人抽成比例
... ...
... ... @@ -8,7 +8,7 @@ import (
type MoneyIncentivesRule struct {
tableName string `comment:"金额激励规则实体" pg:"money_incentives_rules,alias:money_incentives_rule"`
// 金额激励规则ID
MoneyIncentivesRuleId int64 `comment:"金额激励规则ID" pg:",pk"`
MoneyIncentivesRuleId int64 `comment:"金额激励规则ID" pg:",pk,unique"`
// 关联的共创合约编号
CooperationContractNumber string `comment:"关联的共创合约编号"`
// 激励金额
... ...
... ... @@ -265,13 +265,21 @@ func (repository *CooperationApplicationRepository) Find(queryOptions map[string
// 获取共创项目
cooperationProjectModel := new(models.CooperationProject)
cooperationProjectQuery := tx.Model(cooperationProjectModel)
if err := cooperationProjectQuery.Where("cooperation_project_number = ?", cooperationApplicationModel.CooperationProjectNumber).First(); err != nil {
if err := cooperationProjectQuery.
Where("company->>'companyId' = '?'", cooperationApplicationModel.Company.CompanyId).
Where("org->>'orgId' = '?'", cooperationApplicationModel.Org.OrgId).
Where("cooperation_project_number = ?", cooperationApplicationModel.CooperationProjectNumber).
First(); err != nil {
return 0, nil, err
}
// 获取共创模式
cooperationModeModel := new(models.CooperationMode)
cooperationModeQuery := tx.Model(cooperationModeModel)
if err := cooperationModeQuery.Where("cooperation_mode_number = ?", cooperationProjectModel.CooperationModeNumber).First(); err != nil {
if err := cooperationModeQuery.
Where("company->>'companyId' = '?'", cooperationApplicationModel.Company.CompanyId).
Where("org->>'orgId' = '?'", cooperationApplicationModel.Org.OrgId).
Where("cooperation_mode_number = ?", cooperationProjectModel.CooperationModeNumber).
First(); err != nil {
return 0, nil, err
}
if cooperationApplication, err := transform.TransformToCooperationApplicationDomainModelFromPgModels(cooperationApplicationModel, cooperationProjectModel, cooperationModeModel); err != nil {
... ...
... ... @@ -125,10 +125,10 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
CreatedAt: time.Now(),
})
}
log.Logger.Info("新增的相关人", map[string]interface{}{
"relevantPeopleModel": relevantPeopleModel,
})
if len(relevantPeopleModel) > 0 {
log.Logger.Info("新增的相关人", map[string]interface{}{
"relevantPeopleModel": relevantPeopleModel,
})
if _, err := tx.Model(&relevantPeopleModel).Insert(); err != nil {
return nil, err
}
... ... @@ -158,6 +158,9 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
})
}
if len(undertakersModel) > 0 {
log.Logger.Info("新增的承接人", map[string]interface{}{
"undertakersModel": undertakersModel,
})
if _, err := tx.Model(&undertakersModel).Insert(); err != nil {
return nil, err
}
... ... @@ -183,6 +186,9 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
})
}
if len(dividendsIncentivesRulesModel) > 0 {
log.Logger.Info("新增分红激励规则", map[string]interface{}{
"dividendsIncentivesRulesModel": dividendsIncentivesRulesModel,
})
if _, err := tx.Model(&dividendsIncentivesRulesModel).Insert(); err != nil {
return nil, err
}
... ... @@ -209,6 +215,9 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
})
}
if len(moneyIncentivesRulesModel) > 0 {
log.Logger.Info("新增金额激励规则", map[string]interface{}{
"moneyIncentivesRulesModel": moneyIncentivesRulesModel,
})
if _, err := tx.Model(&moneyIncentivesRulesModel).Insert(); err != nil {
return nil, err
}
... ... @@ -1018,31 +1027,51 @@ func (repository *CooperationContractRepository) Find(queryOptions map[string]in
// 获取共创模式
cooperationModeModel := new(models.CooperationMode)
cooperationModeQuery := tx.Model(cooperationModeModel)
if err := cooperationModeQuery.Where("cooperation_mode_number = ?", cooperationContractModel.CooperationModeNumber).First(); err != nil {
if err := cooperationModeQuery.
Where("company->>'companyId' = '?'", cooperationContractModel.Company.CompanyId).
Where("org->>'orgId' = '?'", cooperationContractModel.Org.OrgId).
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 {
if err := dividendsIncentivesRuleQuery.
Where("company->>'companyId' = '?'", cooperationContractModel.Company.CompanyId).
Where("org->>'orgId' = '?'", cooperationContractModel.Org.OrgId).
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 {
if err := moneyIncentivesRuleQuery.
Where("company->>'companyId' = '?'", cooperationContractModel.Company.CompanyId).
Where("org->>'orgId' = '?'", cooperationContractModel.Org.OrgId).
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 {
if err := cooperationContractUndertakerQuery.
Where("company->>'companyId' = '?'", cooperationContractModel.Company.CompanyId).
Where("org->>'orgId' = '?'", cooperationContractModel.Org.OrgId).
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 {
if err := cooperationContractRelevantQuery.
Where("company->>'companyId' = '?'", cooperationContractModel.Company.CompanyId).
Where("org->>'orgId' = '?'", cooperationContractModel.Org.OrgId).
Where("cooperation_contract_number = ?", cooperationContractModel.CooperationContractNumber).
Select(); err != nil {
return 0, nil, err
}
if cooperationContract, err := transform.TransformToCooperationContractDomainModelFromPgModels(
... ...
... ... @@ -279,7 +279,11 @@ func (repository *CooperationProjectRepository) Find(queryOptions map[string]int
// 获取共创模式
cooperationModeModel := new(models.CooperationMode)
cooperationModeQuery := tx.Model(cooperationModeModel)
if err := cooperationModeQuery.Where("cooperation_mode_number = ?", cooperationProjectModel.CooperationModeNumber).First(); err != nil {
if err := cooperationModeQuery.
Where("company->>'companyId' = '?'", cooperationProjectModel.Company.CompanyId).
Where("org->>'orgId' = '?'", cooperationProjectModel.Org.OrgId).
Where("cooperation_mode_number = ?", cooperationProjectModel.CooperationModeNumber).
First(); err != nil {
return 0, nil, err
}
if cooperationProject, err := transform.TransformToCooperationProjectDomainModelFromPgModels(cooperationProjectModel, cooperationModeModel); err != nil {
... ...
... ... @@ -433,7 +433,11 @@ func (repository *DividendsOrderRepository) Find(queryOptions map[string]interfa
//获取订单产品
var orderGoodModels []*models.OrderGood
orderGoodModelQuery := tx.Model(&orderGoodModels)
if err := orderGoodModelQuery.Where("dividends_order_number = ?", dividendsOrderModel.DividendsOrderNumber).Select(); err != nil {
if err := orderGoodModelQuery.
Where("company->>'companyId' = '?'", dividendsOrderModel.Company.CompanyId).
Where("org->>'orgId' = '?'", dividendsOrderModel.Org.OrgId).
Where("dividends_order_number = ?", dividendsOrderModel.DividendsOrderNumber).
Select(); err != nil {
return 0, nil, err
}
// 聚合分红订单
... ...
... ... @@ -435,7 +435,11 @@ func (repository *DividendsReturnedOrderRepository) Find(queryOptions map[string
// 获取订单产品
var orderGoodModels []*models.OrderGood
orderGoodModelQuery := tx.Model(&orderGoodModels)
if err := orderGoodModelQuery.Where("dividends_returned_order_number = ?", dividendsReturnedOrderModel.DividendsReturnedOrderNumber).Select(); err != nil {
if err := orderGoodModelQuery.
Where("company->>'companyId' = '?'", dividendsReturnedOrderModel.Company.CompanyId).
Where("org->>'orgId' = '?'", dividendsReturnedOrderModel.Org.OrgId).
Where("dividends_returned_order_number = ?", dividendsReturnedOrderModel.DividendsReturnedOrderNumber).
Select(); err != nil {
return 0, nil, err
}
if dividendsReturnedOrder, err := transform.TransformToDividendsReturnedOrderDomainModelFromPgModels(dividendsReturnedOrderModel, orderGoodModels); err != nil {
... ...
... ... @@ -26,6 +26,7 @@ func (repository *OrderGoodRepository) nextIdentify() (int64, error) {
id, err := IdWorker.NextId()
return id, err
}
func (repository *OrderGoodRepository) Save(orderGood *domain.OrderGood) (*domain.OrderGood, error) {
sqlBuildFields := []string{
"order_good_id",
... ...