作者 陈志颖

feat:修改共创合约仓储

... ... @@ -33,7 +33,7 @@ type CreateCooperationContractCommand struct {
// 承接方列表
Undertakers []*domain.Undertaker `cname:"承接方列表" json:"undertakers,omitempty"`
// 相关人列表
Relevants []*domain.Relevant `cname:"相关人列表" json:"relevants,omitempty"`
RelevantPeople []*domain.Relevant `cname:"相关人列表" json:"relevantPeople,omitempty"`
// 公司ID,通过集成REST上下文获取
CompanyId int64 `cname:"公司ID,通过集成REST上下文获取" json:"companyId,string" valid:"Required"`
// 组织机构ID
... ... @@ -43,7 +43,7 @@ type CreateCooperationContractCommand struct {
}
func (createCooperationContractCommand *CreateCooperationContractCommand) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (createCooperationContractCommand *CreateCooperationContractCommand) ValidateCommand() error {
... ...
... ... @@ -20,7 +20,7 @@ type RemoveCooperationContractCommand struct {
}
func (removeCooperationContractCommand *RemoveCooperationContractCommand) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (removeCooperationContractCommand *RemoveCooperationContractCommand) ValidateCommand() error {
... ...
... ... @@ -36,7 +36,7 @@ type UpdateCooperationContractCommand struct {
}
func (updateCooperationContractCommand *UpdateCooperationContractCommand) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (updateCooperationContractCommand *UpdateCooperationContractCommand) ValidateCommand() error {
... ...
... ... @@ -22,7 +22,7 @@ type GetCooperationContractQuery struct {
}
func (getCooperationContractQuery *GetCooperationContractQuery) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (getCooperationContractQuery *GetCooperationContractQuery) ValidateQuery() error {
... ...
... ... @@ -13,10 +13,6 @@ type ListCooperationContractQuery struct {
PageNumber int32 `cname:"页面大小" json:"pageNumber,omitempty"`
// 页面大小
PageSize int32 `cname:"页面大小" json:"pageSize,omitempty"`
// 查询偏离量
Offset int `cname:"查询偏离量" json:"offset" valid:"Required"`
// 查询限制
Limit int `cname:"查询限制" json:"limit" valid:"Required"`
// 公司ID,通过集成REST上下文获取
CompanyId int64 `cname:"公司ID,通过集成REST上下文获取" json:"companyId,string" valid:"Required"`
// 组织机构ID
... ... @@ -26,7 +22,7 @@ type ListCooperationContractQuery struct {
}
func (listCooperationContractQuery *ListCooperationContractQuery) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (listCooperationContractQuery *ListCooperationContractQuery) ValidateQuery() error {
... ...
... ... @@ -26,7 +26,7 @@ type SearchCooperationContractQuery struct {
}
func (searchCooperationContractQuery *SearchCooperationContractQuery) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (searchCooperationContractQuery *SearchCooperationContractQuery) ValidateQuery() error {
... ...
... ... @@ -26,7 +26,7 @@ type SearchCooperationContractByUndertakerQuery struct {
}
func (searchCooperationContractByUndertakerQuery *SearchCooperationContractByUndertakerQuery) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (searchCooperationContractByUndertakerQuery *SearchCooperationContractByUndertakerQuery) ValidateQuery() error {
... ...
... ... @@ -50,11 +50,13 @@ func (cooperationContractService *CooperationContractService) CreateCooperationC
//DividendsIncentivesRules: createCooperationContractCommand.DividendsIncentivesRules,
//MoneyIncentivesRules: createCooperationContractCommand.MoneyIncentivesRules,
//Undertakers: createCooperationContractCommand.Undertakers,
//Relevants: createCooperationContractCommand.Relevants,
//RelevantPeople: createCooperationContractCommand.RelevantPeople,
//CompanyId: createCooperationContractCommand.CompanyId,
//OrgId: createCooperationContractCommand.OrgId,
//UserId: createCooperationContractCommand.UserId,
}
// 共创合约仓储初始化
var cooperationContractRepository domain.CooperationContractRepository
if value, err := factory.CreateCooperationContractRepository(map[string]interface{}{
"transactionContext": transactionContext,
... ... @@ -63,9 +65,51 @@ func (cooperationContractService *CooperationContractService) CreateCooperationC
} else {
cooperationContractRepository = value
}
//// 共创合约承接人仓储初始化
//var cooperationContractUndertakerRepository domain.CooperationContractUndertakerRepository
//if value, err := factory.CreateCooperationContractUndertakerRepository(map[string]interface{}{
// "transactionContext": transactionContext,
//}); err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
//} else {
// cooperationContractUndertakerRepository = value
//}
//// 共创合约相关人仓储初始化
//var cooperationContractRelevantRepository domain.CooperationContractRelevantRepository
//if value, err := factory.CreateCooperationContractRelevantRepository(map[string]interface{}{
// "transactionContext": transactionContext,
//}); err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
//} else {
// cooperationContractRelevantRepository = value
//}
//// 分红激励规则仓储初始化
//var dividendsIncentivesRuleRepository domain.DividendsIncentivesRuleRepository
//if value, err := factory.CreateDividendsIncentivesRuleRepository(map[string]interface{}{
// "transactionContext": transactionContext,
//}); err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
//} else {
// dividendsIncentivesRuleRepository = value
//}
//// 金额激励规则仓储初始化
//var moneyIncentivesRuleRepository domain.MoneyIncentivesRuleRepository
//if value, err := factory.CreateMoneyIncentivesRuleRepository(map[string]interface{}{
// "transactionContext": transactionContext,
//}); err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
//} else {
// moneyIncentivesRuleRepository = value
//}
if cooperationContract, err := cooperationContractRepository.Save(newCooperationContract); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
//
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
... ...
... ... @@ -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"
... ...
... ... @@ -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"
... ... @@ -34,7 +35,7 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
"cooperation_contract_salesman",
"cooperation_contract_undertaker_type",
"cooperation_contract_sponsor",
"cooperation_mode",
"cooperation_mode_number",
"status",
"org",
"company",
... ... @@ -67,7 +68,7 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
&cooperationContract.CooperationContractSalesman,
pg.Array(&cooperationContract.CooperationContractUndertakerType),
&cooperationContract.CooperationContractSponsor,
&cooperationContract.CooperationMode,
&cooperationContract.CooperationMode.CooperationModeNumber,
&cooperationContract.Status,
&cooperationContract.Org,
&cooperationContract.Company,
... ... @@ -86,7 +87,7 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
cooperationContract.CooperationContractSalesman,
pg.Array(cooperationContract.CooperationContractUndertakerType),
cooperationContract.CooperationContractSponsor,
cooperationContract.CooperationMode,
cooperationContract.CooperationMode.CooperationModeNumber,
cooperationContract.Status,
cooperationContract.Org,
cooperationContract.Company,
... ... @@ -97,6 +98,80 @@ 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 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
}
}
} else {
if _, err := tx.QueryOne(
... ... @@ -109,7 +184,7 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
&cooperationContract.CooperationContractSalesman,
pg.Array(&cooperationContract.CooperationContractUndertakerType),
&cooperationContract.CooperationContractSponsor,
&cooperationContract.CooperationMode,
&cooperationContract.CooperationMode.CooperationModeNumber,
&cooperationContract.Status,
&cooperationContract.Org,
&cooperationContract.Company,
... ... @@ -128,7 +203,7 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
cooperationContract.CooperationContractSalesman,
pg.Array(cooperationContract.CooperationContractUndertakerType),
cooperationContract.CooperationContractSponsor,
cooperationContract.CooperationMode,
cooperationContract.CooperationMode.CooperationModeNumber,
cooperationContract.Status,
cooperationContract.Org,
cooperationContract.Company,
... ... @@ -140,6 +215,11 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
cooperationContract.Identify(),
); err != nil {
return cooperationContract, err
} else {
//TODO 更新相关人
//TODO 更新承接人
//TODO 更新分红激励规则
//TODO 更新金额激励规则
}
}
return cooperationContract, nil
... ... @@ -150,6 +230,8 @@ func (repository *CooperationContractRepository) Remove(cooperationContract *dom
cooperationContractModel.CooperationContractId = cooperationContract.Identify().(int64)
if _, err := tx.Model(cooperationContractModel).WherePK().Delete(); err != nil {
return cooperationContract, err
} else {
//TODO 删除关联数据
}
return cooperationContract, nil
}
... ...