作者 陈志颖

feat:修改共创合约仓储

@@ -33,7 +33,7 @@ type CreateCooperationContractCommand struct { @@ -33,7 +33,7 @@ type CreateCooperationContractCommand struct {
33 // 承接方列表 33 // 承接方列表
34 Undertakers []*domain.Undertaker `cname:"承接方列表" json:"undertakers,omitempty"` 34 Undertakers []*domain.Undertaker `cname:"承接方列表" json:"undertakers,omitempty"`
35 // 相关人列表 35 // 相关人列表
36 - Relevants []*domain.Relevant `cname:"相关人列表" json:"relevants,omitempty"` 36 + RelevantPeople []*domain.Relevant `cname:"相关人列表" json:"relevantPeople,omitempty"`
37 // 公司ID,通过集成REST上下文获取 37 // 公司ID,通过集成REST上下文获取
38 CompanyId int64 `cname:"公司ID,通过集成REST上下文获取" json:"companyId,string" valid:"Required"` 38 CompanyId int64 `cname:"公司ID,通过集成REST上下文获取" json:"companyId,string" valid:"Required"`
39 // 组织机构ID 39 // 组织机构ID
@@ -43,7 +43,7 @@ type CreateCooperationContractCommand struct { @@ -43,7 +43,7 @@ type CreateCooperationContractCommand struct {
43 } 43 }
44 44
45 func (createCooperationContractCommand *CreateCooperationContractCommand) Valid(validation *validation.Validation) { 45 func (createCooperationContractCommand *CreateCooperationContractCommand) Valid(validation *validation.Validation) {
46 - validation.SetError("CustomValid", "未实现的自定义认证") 46 + //validation.SetError("CustomValid", "未实现的自定义认证")
47 } 47 }
48 48
49 func (createCooperationContractCommand *CreateCooperationContractCommand) ValidateCommand() error { 49 func (createCooperationContractCommand *CreateCooperationContractCommand) ValidateCommand() error {
@@ -20,7 +20,7 @@ type RemoveCooperationContractCommand struct { @@ -20,7 +20,7 @@ type RemoveCooperationContractCommand struct {
20 } 20 }
21 21
22 func (removeCooperationContractCommand *RemoveCooperationContractCommand) Valid(validation *validation.Validation) { 22 func (removeCooperationContractCommand *RemoveCooperationContractCommand) Valid(validation *validation.Validation) {
23 - validation.SetError("CustomValid", "未实现的自定义认证") 23 + //validation.SetError("CustomValid", "未实现的自定义认证")
24 } 24 }
25 25
26 func (removeCooperationContractCommand *RemoveCooperationContractCommand) ValidateCommand() error { 26 func (removeCooperationContractCommand *RemoveCooperationContractCommand) ValidateCommand() error {
@@ -36,7 +36,7 @@ type UpdateCooperationContractCommand struct { @@ -36,7 +36,7 @@ type UpdateCooperationContractCommand struct {
36 } 36 }
37 37
38 func (updateCooperationContractCommand *UpdateCooperationContractCommand) Valid(validation *validation.Validation) { 38 func (updateCooperationContractCommand *UpdateCooperationContractCommand) Valid(validation *validation.Validation) {
39 - validation.SetError("CustomValid", "未实现的自定义认证") 39 + //validation.SetError("CustomValid", "未实现的自定义认证")
40 } 40 }
41 41
42 func (updateCooperationContractCommand *UpdateCooperationContractCommand) ValidateCommand() error { 42 func (updateCooperationContractCommand *UpdateCooperationContractCommand) ValidateCommand() error {
@@ -22,7 +22,7 @@ type GetCooperationContractQuery struct { @@ -22,7 +22,7 @@ type GetCooperationContractQuery struct {
22 } 22 }
23 23
24 func (getCooperationContractQuery *GetCooperationContractQuery) Valid(validation *validation.Validation) { 24 func (getCooperationContractQuery *GetCooperationContractQuery) Valid(validation *validation.Validation) {
25 - validation.SetError("CustomValid", "未实现的自定义认证") 25 + //validation.SetError("CustomValid", "未实现的自定义认证")
26 } 26 }
27 27
28 func (getCooperationContractQuery *GetCooperationContractQuery) ValidateQuery() error { 28 func (getCooperationContractQuery *GetCooperationContractQuery) ValidateQuery() error {
@@ -13,10 +13,6 @@ type ListCooperationContractQuery struct { @@ -13,10 +13,6 @@ type ListCooperationContractQuery struct {
13 PageNumber int32 `cname:"页面大小" json:"pageNumber,omitempty"` 13 PageNumber int32 `cname:"页面大小" json:"pageNumber,omitempty"`
14 // 页面大小 14 // 页面大小
15 PageSize int32 `cname:"页面大小" json:"pageSize,omitempty"` 15 PageSize int32 `cname:"页面大小" json:"pageSize,omitempty"`
16 - // 查询偏离量  
17 - Offset int `cname:"查询偏离量" json:"offset" valid:"Required"`  
18 - // 查询限制  
19 - Limit int `cname:"查询限制" json:"limit" valid:"Required"`  
20 // 公司ID,通过集成REST上下文获取 16 // 公司ID,通过集成REST上下文获取
21 CompanyId int64 `cname:"公司ID,通过集成REST上下文获取" json:"companyId,string" valid:"Required"` 17 CompanyId int64 `cname:"公司ID,通过集成REST上下文获取" json:"companyId,string" valid:"Required"`
22 // 组织机构ID 18 // 组织机构ID
@@ -26,7 +22,7 @@ type ListCooperationContractQuery struct { @@ -26,7 +22,7 @@ type ListCooperationContractQuery struct {
26 } 22 }
27 23
28 func (listCooperationContractQuery *ListCooperationContractQuery) Valid(validation *validation.Validation) { 24 func (listCooperationContractQuery *ListCooperationContractQuery) Valid(validation *validation.Validation) {
29 - validation.SetError("CustomValid", "未实现的自定义认证") 25 + //validation.SetError("CustomValid", "未实现的自定义认证")
30 } 26 }
31 27
32 func (listCooperationContractQuery *ListCooperationContractQuery) ValidateQuery() error { 28 func (listCooperationContractQuery *ListCooperationContractQuery) ValidateQuery() error {
@@ -26,7 +26,7 @@ type SearchCooperationContractQuery struct { @@ -26,7 +26,7 @@ type SearchCooperationContractQuery struct {
26 } 26 }
27 27
28 func (searchCooperationContractQuery *SearchCooperationContractQuery) Valid(validation *validation.Validation) { 28 func (searchCooperationContractQuery *SearchCooperationContractQuery) Valid(validation *validation.Validation) {
29 - validation.SetError("CustomValid", "未实现的自定义认证") 29 + //validation.SetError("CustomValid", "未实现的自定义认证")
30 } 30 }
31 31
32 func (searchCooperationContractQuery *SearchCooperationContractQuery) ValidateQuery() error { 32 func (searchCooperationContractQuery *SearchCooperationContractQuery) ValidateQuery() error {
@@ -26,7 +26,7 @@ type SearchCooperationContractByUndertakerQuery struct { @@ -26,7 +26,7 @@ type SearchCooperationContractByUndertakerQuery struct {
26 } 26 }
27 27
28 func (searchCooperationContractByUndertakerQuery *SearchCooperationContractByUndertakerQuery) Valid(validation *validation.Validation) { 28 func (searchCooperationContractByUndertakerQuery *SearchCooperationContractByUndertakerQuery) Valid(validation *validation.Validation) {
29 - validation.SetError("CustomValid", "未实现的自定义认证") 29 + //validation.SetError("CustomValid", "未实现的自定义认证")
30 } 30 }
31 31
32 func (searchCooperationContractByUndertakerQuery *SearchCooperationContractByUndertakerQuery) ValidateQuery() error { 32 func (searchCooperationContractByUndertakerQuery *SearchCooperationContractByUndertakerQuery) ValidateQuery() error {
@@ -50,11 +50,13 @@ func (cooperationContractService *CooperationContractService) CreateCooperationC @@ -50,11 +50,13 @@ func (cooperationContractService *CooperationContractService) CreateCooperationC
50 //DividendsIncentivesRules: createCooperationContractCommand.DividendsIncentivesRules, 50 //DividendsIncentivesRules: createCooperationContractCommand.DividendsIncentivesRules,
51 //MoneyIncentivesRules: createCooperationContractCommand.MoneyIncentivesRules, 51 //MoneyIncentivesRules: createCooperationContractCommand.MoneyIncentivesRules,
52 //Undertakers: createCooperationContractCommand.Undertakers, 52 //Undertakers: createCooperationContractCommand.Undertakers,
53 - //Relevants: createCooperationContractCommand.Relevants, 53 + //RelevantPeople: createCooperationContractCommand.RelevantPeople,
54 //CompanyId: createCooperationContractCommand.CompanyId, 54 //CompanyId: createCooperationContractCommand.CompanyId,
55 //OrgId: createCooperationContractCommand.OrgId, 55 //OrgId: createCooperationContractCommand.OrgId,
56 //UserId: createCooperationContractCommand.UserId, 56 //UserId: createCooperationContractCommand.UserId,
57 } 57 }
  58 +
  59 + // 共创合约仓储初始化
58 var cooperationContractRepository domain.CooperationContractRepository 60 var cooperationContractRepository domain.CooperationContractRepository
59 if value, err := factory.CreateCooperationContractRepository(map[string]interface{}{ 61 if value, err := factory.CreateCooperationContractRepository(map[string]interface{}{
60 "transactionContext": transactionContext, 62 "transactionContext": transactionContext,
@@ -63,9 +65,51 @@ func (cooperationContractService *CooperationContractService) CreateCooperationC @@ -63,9 +65,51 @@ func (cooperationContractService *CooperationContractService) CreateCooperationC
63 } else { 65 } else {
64 cooperationContractRepository = value 66 cooperationContractRepository = value
65 } 67 }
  68 +
  69 + //// 共创合约承接人仓储初始化
  70 + //var cooperationContractUndertakerRepository domain.CooperationContractUndertakerRepository
  71 + //if value, err := factory.CreateCooperationContractUndertakerRepository(map[string]interface{}{
  72 + // "transactionContext": transactionContext,
  73 + //}); err != nil {
  74 + // return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  75 + //} else {
  76 + // cooperationContractUndertakerRepository = value
  77 + //}
  78 +
  79 + //// 共创合约相关人仓储初始化
  80 + //var cooperationContractRelevantRepository domain.CooperationContractRelevantRepository
  81 + //if value, err := factory.CreateCooperationContractRelevantRepository(map[string]interface{}{
  82 + // "transactionContext": transactionContext,
  83 + //}); err != nil {
  84 + // return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  85 + //} else {
  86 + // cooperationContractRelevantRepository = value
  87 + //}
  88 +
  89 + //// 分红激励规则仓储初始化
  90 + //var dividendsIncentivesRuleRepository domain.DividendsIncentivesRuleRepository
  91 + //if value, err := factory.CreateDividendsIncentivesRuleRepository(map[string]interface{}{
  92 + // "transactionContext": transactionContext,
  93 + //}); err != nil {
  94 + // return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  95 + //} else {
  96 + // dividendsIncentivesRuleRepository = value
  97 + //}
  98 +
  99 + //// 金额激励规则仓储初始化
  100 + //var moneyIncentivesRuleRepository domain.MoneyIncentivesRuleRepository
  101 + //if value, err := factory.CreateMoneyIncentivesRuleRepository(map[string]interface{}{
  102 + // "transactionContext": transactionContext,
  103 + //}); err != nil {
  104 + // return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  105 + //} else {
  106 + // moneyIncentivesRuleRepository = value
  107 + //}
  108 +
66 if cooperationContract, err := cooperationContractRepository.Save(newCooperationContract); err != nil { 109 if cooperationContract, err := cooperationContractRepository.Save(newCooperationContract); err != nil {
67 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 110 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
68 } else { 111 } else {
  112 + //
69 if err := transactionContext.CommitTransaction(); err != nil { 113 if err := transactionContext.CommitTransaction(); err != nil {
70 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 114 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
71 } 115 }
@@ -2,6 +2,7 @@ package repository @@ -2,6 +2,7 @@ package repository
2 2
3 import ( 3 import (
4 "fmt" 4 "fmt"
  5 + "github.com/go-pg/pg/v10"
5 6
6 "github.com/linmadan/egglib-go/persistent/pg/sqlbuilder" 7 "github.com/linmadan/egglib-go/persistent/pg/sqlbuilder"
7 pgTransaction "github.com/linmadan/egglib-go/transaction/pg" 8 pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
@@ -3,6 +3,7 @@ package repository @@ -3,6 +3,7 @@ package repository
3 import ( 3 import (
4 "fmt" 4 "fmt"
5 "github.com/go-pg/pg/v10" 5 "github.com/go-pg/pg/v10"
  6 + "time"
6 7
7 "github.com/linmadan/egglib-go/persistent/pg/sqlbuilder" 8 "github.com/linmadan/egglib-go/persistent/pg/sqlbuilder"
8 pgTransaction "github.com/linmadan/egglib-go/transaction/pg" 9 pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
@@ -34,7 +35,7 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai @@ -34,7 +35,7 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
34 "cooperation_contract_salesman", 35 "cooperation_contract_salesman",
35 "cooperation_contract_undertaker_type", 36 "cooperation_contract_undertaker_type",
36 "cooperation_contract_sponsor", 37 "cooperation_contract_sponsor",
37 - "cooperation_mode", 38 + "cooperation_mode_number",
38 "status", 39 "status",
39 "org", 40 "org",
40 "company", 41 "company",
@@ -67,7 +68,7 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai @@ -67,7 +68,7 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
67 &cooperationContract.CooperationContractSalesman, 68 &cooperationContract.CooperationContractSalesman,
68 pg.Array(&cooperationContract.CooperationContractUndertakerType), 69 pg.Array(&cooperationContract.CooperationContractUndertakerType),
69 &cooperationContract.CooperationContractSponsor, 70 &cooperationContract.CooperationContractSponsor,
70 - &cooperationContract.CooperationMode, 71 + &cooperationContract.CooperationMode.CooperationModeNumber,
71 &cooperationContract.Status, 72 &cooperationContract.Status,
72 &cooperationContract.Org, 73 &cooperationContract.Org,
73 &cooperationContract.Company, 74 &cooperationContract.Company,
@@ -86,7 +87,7 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai @@ -86,7 +87,7 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
86 cooperationContract.CooperationContractSalesman, 87 cooperationContract.CooperationContractSalesman,
87 pg.Array(cooperationContract.CooperationContractUndertakerType), 88 pg.Array(cooperationContract.CooperationContractUndertakerType),
88 cooperationContract.CooperationContractSponsor, 89 cooperationContract.CooperationContractSponsor,
89 - cooperationContract.CooperationMode, 90 + cooperationContract.CooperationMode.CooperationModeNumber,
90 cooperationContract.Status, 91 cooperationContract.Status,
91 cooperationContract.Org, 92 cooperationContract.Org,
92 cooperationContract.Company, 93 cooperationContract.Company,
@@ -97,6 +98,80 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai @@ -97,6 +98,80 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
97 cooperationContract.UpdatedAt, 98 cooperationContract.UpdatedAt,
98 ); err != nil { 99 ); err != nil {
99 return cooperationContract, err 100 return cooperationContract, err
  101 + } else {
  102 + // 新增相关人
  103 + var relevantPeopleModel []*models.CooperationContractRelevant
  104 + for _, relevant := range cooperationContract.RelevantPeople {
  105 + relevantPeopleModel = append(relevantPeopleModel, &models.CooperationContractRelevant{
  106 + CooperationContractNumber: cooperationContract.CooperationContractNumber,
  107 + Relevant: relevant,
  108 + UpdatedAt: time.Time{},
  109 + DeletedAt: time.Time{},
  110 + CreatedAt: time.Now(),
  111 + })
  112 + }
  113 + if _, err := tx.Model(&relevantPeopleModel).Insert(); err != nil {
  114 + return nil, err
  115 + }
  116 +
  117 + // 新增承接人
  118 + var undertakersModel []*models.CooperationContractUndertaker
  119 + for _, undertaker := range cooperationContract.Undertakers {
  120 + undertakersModel = append(undertakersModel, &models.CooperationContractUndertaker{
  121 + CooperationContractNumber: cooperationContract.CooperationContractNumber,
  122 + Undertaker: undertaker,
  123 + CreatedAt: time.Time{},
  124 + UpdatedAt: time.Time{},
  125 + DeletedAt: time.Now(),
  126 + })
  127 + }
  128 + if _, err := tx.Model(&undertakersModel).Insert(); err != nil {
  129 + return nil, err
  130 + }
  131 +
  132 + // 新增分红激励规则
  133 + var dividendsIncentivesRulesModel []*models.DividendsIncentivesRule
  134 + for _, rule := range cooperationContract.DividendsIncentivesRules {
  135 + dividendsIncentivesRulesModel = append(dividendsIncentivesRulesModel, &models.DividendsIncentivesRule{
  136 + CooperationContractNumber: cooperationContract.CooperationContractNumber,
  137 + ReferrerPercentage: rule.ReferrerPercentage,
  138 + SalesmanPercentage: rule.SalesmanPercentage,
  139 + DividendsIncentivesPercentage: rule.DividendsIncentivesPercentage,
  140 + DividendsIncentivesStage: rule.DividendsIncentivesStage,
  141 + DividendsIncentivesStageStart: rule.DividendsIncentivesStageStart,
  142 + DividendsIncentivesStageEnd: rule.DividendsIncentivesStageEnd,
  143 + Org: rule.Org,
  144 + Company: rule.Company,
  145 + UpdatedAt: time.Time{},
  146 + DeletedAt: time.Time{},
  147 + CreatedAt: time.Now(),
  148 + })
  149 + }
  150 + if _, err := tx.Model(&dividendsIncentivesRulesModel).Insert(); err != nil {
  151 + return nil, err
  152 + }
  153 + // 新增金额激励规则
  154 + var moneyIncentivesRulesModel []*models.MoneyIncentivesRule
  155 + for _, rule := range cooperationContract.MoneyIncentivesRules {
  156 + moneyIncentivesRulesModel = append(moneyIncentivesRulesModel, &models.MoneyIncentivesRule{
  157 + CooperationContractNumber: cooperationContract.CooperationContractNumber,
  158 + MoneyIncentivesAmount: rule.MoneyIncentivesAmount,
  159 + MoneyIncentivesStage: rule.MoneyIncentivesStage,
  160 + MoneyIncentivesStageStart: rule.MoneyIncentivesStageStart,
  161 + MoneyIncentivesStageEnd: rule.MoneyIncentivesStageEnd,
  162 + MoneyIncentivesTime: rule.MoneyIncentivesTime,
  163 + ReferrerPercentage: rule.ReferrerPercentage,
  164 + SalesmanPercentage: rule.SalesmanPercentage,
  165 + Org: rule.Org,
  166 + Company: rule.Company,
  167 + UpdatedAt: time.Time{},
  168 + DeletedAt: time.Time{},
  169 + CreatedAt: time.Now(),
  170 + })
  171 + }
  172 + if _, err := tx.Model(&moneyIncentivesRulesModel).Insert(); err != nil {
  173 + return nil, err
  174 + }
100 } 175 }
101 } else { 176 } else {
102 if _, err := tx.QueryOne( 177 if _, err := tx.QueryOne(
@@ -109,7 +184,7 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai @@ -109,7 +184,7 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
109 &cooperationContract.CooperationContractSalesman, 184 &cooperationContract.CooperationContractSalesman,
110 pg.Array(&cooperationContract.CooperationContractUndertakerType), 185 pg.Array(&cooperationContract.CooperationContractUndertakerType),
111 &cooperationContract.CooperationContractSponsor, 186 &cooperationContract.CooperationContractSponsor,
112 - &cooperationContract.CooperationMode, 187 + &cooperationContract.CooperationMode.CooperationModeNumber,
113 &cooperationContract.Status, 188 &cooperationContract.Status,
114 &cooperationContract.Org, 189 &cooperationContract.Org,
115 &cooperationContract.Company, 190 &cooperationContract.Company,
@@ -128,7 +203,7 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai @@ -128,7 +203,7 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
128 cooperationContract.CooperationContractSalesman, 203 cooperationContract.CooperationContractSalesman,
129 pg.Array(cooperationContract.CooperationContractUndertakerType), 204 pg.Array(cooperationContract.CooperationContractUndertakerType),
130 cooperationContract.CooperationContractSponsor, 205 cooperationContract.CooperationContractSponsor,
131 - cooperationContract.CooperationMode, 206 + cooperationContract.CooperationMode.CooperationModeNumber,
132 cooperationContract.Status, 207 cooperationContract.Status,
133 cooperationContract.Org, 208 cooperationContract.Org,
134 cooperationContract.Company, 209 cooperationContract.Company,
@@ -140,6 +215,11 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai @@ -140,6 +215,11 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
140 cooperationContract.Identify(), 215 cooperationContract.Identify(),
141 ); err != nil { 216 ); err != nil {
142 return cooperationContract, err 217 return cooperationContract, err
  218 + } else {
  219 + //TODO 更新相关人
  220 + //TODO 更新承接人
  221 + //TODO 更新分红激励规则
  222 + //TODO 更新金额激励规则
143 } 223 }
144 } 224 }
145 return cooperationContract, nil 225 return cooperationContract, nil
@@ -150,6 +230,8 @@ func (repository *CooperationContractRepository) Remove(cooperationContract *dom @@ -150,6 +230,8 @@ func (repository *CooperationContractRepository) Remove(cooperationContract *dom
150 cooperationContractModel.CooperationContractId = cooperationContract.Identify().(int64) 230 cooperationContractModel.CooperationContractId = cooperationContract.Identify().(int64)
151 if _, err := tx.Model(cooperationContractModel).WherePK().Delete(); err != nil { 231 if _, err := tx.Model(cooperationContractModel).WherePK().Delete(); err != nil {
152 return cooperationContract, err 232 return cooperationContract, err
  233 + } else {
  234 + //TODO 删除关联数据
153 } 235 }
154 return cooperationContract, nil 236 return cooperationContract, nil
155 } 237 }