正在显示
19 个修改的文件
包含
697 行增加
和
14 行删除
@@ -109,3 +109,19 @@ func CreateOrderGoodRepository(options map[string]interface{}) (domain.OrderGood | @@ -109,3 +109,19 @@ func CreateOrderGoodRepository(options map[string]interface{}) (domain.OrderGood | ||
109 | } | 109 | } |
110 | return repository.NewOrderGoodRepository(transactionContext) | 110 | return repository.NewOrderGoodRepository(transactionContext) |
111 | } | 111 | } |
112 | + | ||
113 | +func CreateCooperationContractUndertakerRepository(options map[string]interface{}) (domain.CooperationContractUndertakerRepository, error) { | ||
114 | + var transactionContext *pg.TransactionContext | ||
115 | + if value, ok := options["transactionContext"]; ok { | ||
116 | + transactionContext = value.(*pg.TransactionContext) | ||
117 | + } | ||
118 | + return repository.NewCooperationContractUndertakerRepository(transactionContext) | ||
119 | +} | ||
120 | + | ||
121 | +func CreateCooperationContractRelevantRepository(options map[string]interface{}) (domain.CooperationContractRelevantRepository, error) { | ||
122 | + var transactionContext *pg.TransactionContext | ||
123 | + if value, ok := options["transactionContext"]; ok { | ||
124 | + transactionContext = value.(*pg.TransactionContext) | ||
125 | + } | ||
126 | + return repository.NewCooperationContractRelevantRepository(transactionContext) | ||
127 | +} |
@@ -36,6 +36,10 @@ type CooperationContract struct { | @@ -36,6 +36,10 @@ type CooperationContract struct { | ||
36 | DividendsIncentivesRules []*DividendsIncentivesRule `json:"dividendsIncentivesRules"` | 36 | DividendsIncentivesRules []*DividendsIncentivesRule `json:"dividendsIncentivesRules"` |
37 | // 金额激励规则 | 37 | // 金额激励规则 |
38 | MoneyIncentivesRules []*MoneyIncentivesRule `json:"moneyIncentivesRules"` | 38 | MoneyIncentivesRules []*MoneyIncentivesRule `json:"moneyIncentivesRules"` |
39 | + // 共创合约相关人列表 | ||
40 | + RelevantPeople []*Relevant `json:"relevantPeople"` | ||
41 | + // 共创承接人列表 | ||
42 | + Undertakers []*Undertaker `json:"undertakers"` | ||
39 | // 操作时间 | 43 | // 操作时间 |
40 | OperateTime time.Time `json:"operateTime"` | 44 | OperateTime time.Time `json:"operateTime"` |
41 | // 创建时间 | 45 | // 创建时间 |
pkg/domain/cooperation_contract_relevant.go
0 → 100644
1 | +package domain | ||
2 | + | ||
3 | +import "time" | ||
4 | + | ||
5 | +// CooperationContractRelevant 共创合约相关人 | ||
6 | +type CooperationContractRelevant struct { | ||
7 | + // 共创合约相关人id | ||
8 | + CooperationContractRelevantId int64 `json:"cooperationContractRelevantId,string"` | ||
9 | + // 共创合约编号 | ||
10 | + CooperationContractNumber string `json:"cooperationContractNumber"` | ||
11 | + // 相关人 | ||
12 | + Relevant *Relevant `json:"relevant"` | ||
13 | + // 更新时间 | ||
14 | + UpdatedAt time.Time `json:"updatedAt"` | ||
15 | + // 删除时间 | ||
16 | + DeletedAt time.Time `json:"deletedAt"` | ||
17 | + // 创建时间 | ||
18 | + CreatedAt time.Time `json:"createdAt"` | ||
19 | +} | ||
20 | + | ||
21 | +type CooperationContractRelevantRepository interface { | ||
22 | + Save(cooperationContractRelevant *CooperationContractRelevant) (*CooperationContractRelevant, error) | ||
23 | + Remove(cooperationContractRelevant *CooperationContractRelevant) (*CooperationContractRelevant, error) | ||
24 | + FindOne(queryOptions map[string]interface{}) (*CooperationContractRelevant, error) | ||
25 | + Find(queryOptions map[string]interface{}) (int64, []*CooperationContractRelevant, error) | ||
26 | +} | ||
27 | + | ||
28 | +func (cooperationContractRelevant *CooperationContractRelevant) Identify() interface{} { | ||
29 | + if cooperationContractRelevant.CooperationContractRelevantId == 0 { | ||
30 | + return nil | ||
31 | + } | ||
32 | + return cooperationContractRelevant.CooperationContractRelevantId | ||
33 | +} | ||
34 | + | ||
35 | +func (cooperationContractRelevant *CooperationContractRelevant) Update(data map[string]interface{}) error { | ||
36 | + if cooperationContractRelevantId, ok := data["cooperationContractRelevantId"]; ok { | ||
37 | + cooperationContractRelevant.CooperationContractRelevantId = cooperationContractRelevantId.(int64) | ||
38 | + } | ||
39 | + if cooperationContractNumber, ok := data["cooperationContractNumber"]; ok { | ||
40 | + cooperationContractRelevant.CooperationContractNumber = cooperationContractNumber.(string) | ||
41 | + } | ||
42 | + if userId, ok := data["userId"]; ok { | ||
43 | + cooperationContractRelevant.Relevant.UserId = userId.(int64) | ||
44 | + } | ||
45 | + if userBaseId, ok := data["userBaseId"]; ok { | ||
46 | + cooperationContractRelevant.Relevant.UserBaseId = userBaseId.(int64) | ||
47 | + } | ||
48 | + if orgId, ok := data["orgId"]; ok { | ||
49 | + cooperationContractRelevant.Relevant.Org.OrgId = orgId.(int64) | ||
50 | + } | ||
51 | + if orgName, ok := data["orgName"]; ok { | ||
52 | + cooperationContractRelevant.Relevant.Org.OrgName = orgName.(string) | ||
53 | + } | ||
54 | + if companyId, ok := data["companyId"]; ok { | ||
55 | + cooperationContractRelevant.Relevant.Org.Company.CompanyId = companyId.(int64) | ||
56 | + } | ||
57 | + if companyLogo, ok := data["companyLogo"]; ok { | ||
58 | + cooperationContractRelevant.Relevant.Org.Company.CompanyLogo = companyLogo.(string) | ||
59 | + } | ||
60 | + if companyName, ok := data["companyName"]; ok { | ||
61 | + cooperationContractRelevant.Relevant.Org.Company.CompanyName = companyName.(string) | ||
62 | + } | ||
63 | + if roleId, ok := data["roleId"]; ok { | ||
64 | + cooperationContractRelevant.Relevant.Role.RoleId = roleId.(int64) | ||
65 | + } | ||
66 | + if roleName, ok := data["roleName"]; ok { | ||
67 | + cooperationContractRelevant.Relevant.Role.RoleName = roleName.(string) | ||
68 | + } | ||
69 | + if userAvatar, ok := data["userAvatar"]; ok { | ||
70 | + cooperationContractRelevant.Relevant.UserInfo.UserAvatar = userAvatar.(string) | ||
71 | + } | ||
72 | + if userEmail, ok := data["userEmail"]; ok { | ||
73 | + cooperationContractRelevant.Relevant.UserInfo.UserEmail = userEmail.(string) | ||
74 | + } | ||
75 | + if userName, ok := data["userName"]; ok { | ||
76 | + cooperationContractRelevant.Relevant.UserInfo.UserName = userName.(string) | ||
77 | + } | ||
78 | + if userPhone, ok := data["userPhone"]; ok { | ||
79 | + cooperationContractRelevant.Relevant.UserInfo.UserPhone = userPhone.(string) | ||
80 | + } | ||
81 | + if userAccount, ok := data["userAccount"]; ok { | ||
82 | + cooperationContractRelevant.Relevant.UserInfo.UserAccount = userAccount.(string) | ||
83 | + } | ||
84 | + if userType, ok := data["userType"]; ok { | ||
85 | + cooperationContractRelevant.Relevant.UserType = userType.(int32) | ||
86 | + } | ||
87 | + if status, ok := data["status"]; ok { | ||
88 | + cooperationContractRelevant.Relevant.Status = status.(int32) | ||
89 | + } | ||
90 | + return nil | ||
91 | +} |
1 | +package domain | ||
2 | + | ||
3 | +import "time" | ||
4 | + | ||
5 | +// CooperationContractUndertaker 共创合约承接人 | ||
6 | +type CooperationContractUndertaker struct { | ||
7 | + // 共创合约承接人id | ||
8 | + CooperationContractUndertakerId int64 `json:"cooperationContractUndertakerId,string"` | ||
9 | + // 共创合约编号 | ||
10 | + CooperationContractNumber string `json:"cooperationContractNumber"` | ||
11 | + // 共创合约承接人 | ||
12 | + Undertaker *Undertaker `json:"undertaker"` | ||
13 | + // 创建时间 | ||
14 | + CreatedAt time.Time `json:"createdAt"` | ||
15 | + // 更新时间 | ||
16 | + UpdatedAt time.Time `json:"updatedAt"` | ||
17 | + // 删除时间 | ||
18 | + DeletedAt time.Time `json:"deletedAt"` | ||
19 | +} | ||
20 | + | ||
21 | +type CooperationContractUndertakerRepository interface { | ||
22 | + Save(cooperationContractUndertaker *CooperationContractUndertaker) (*CooperationContractUndertaker, error) | ||
23 | + Remove(cooperationContractUndertaker *CooperationContractUndertaker) (*CooperationContractUndertaker, error) | ||
24 | + FindOne(queryOptions map[string]interface{}) (*CooperationContractUndertaker, error) | ||
25 | + Find(queryOptions map[string]interface{}) (int64, []*CooperationContractUndertaker, error) | ||
26 | +} | ||
27 | + | ||
28 | +func (cooperationContractUndertaker *CooperationContractUndertaker) Identify() interface{} { | ||
29 | + if cooperationContractUndertaker.CooperationContractUndertakerId == 0 { | ||
30 | + return nil | ||
31 | + } | ||
32 | + return cooperationContractUndertaker.CooperationContractUndertakerId | ||
33 | +} | ||
34 | + | ||
35 | +func (cooperationContractUndertaker *CooperationContractUndertaker) Update(data map[string]interface{}) error { | ||
36 | + if cooperationContractNumber, ok := data["cooperationContractNumber"]; ok { | ||
37 | + cooperationContractUndertaker.CooperationContractNumber = cooperationContractNumber.(string) | ||
38 | + } | ||
39 | + if userId, ok := data["userId"]; ok { | ||
40 | + cooperationContractUndertaker.Undertaker.UserId = userId.(int64) | ||
41 | + } | ||
42 | + if userBaseId, ok := data["userBaseId"]; ok { | ||
43 | + cooperationContractUndertaker.Undertaker.UserBaseId = userBaseId.(int64) | ||
44 | + } | ||
45 | + return nil | ||
46 | +} |
@@ -24,6 +24,8 @@ type DividendsOrder struct { | @@ -24,6 +24,8 @@ type DividendsOrder struct { | ||
24 | Region *RegionInfo `json:"region"` | 24 | Region *RegionInfo `json:"region"` |
25 | // 客户姓名 | 25 | // 客户姓名 |
26 | CustomerName string `json:"customerName"` | 26 | CustomerName string `json:"customerName"` |
27 | + // 订单产品列表 | ||
28 | + Goods []*OrderGood `json:"goods"` | ||
27 | // 数据所属组织机构 | 29 | // 数据所属组织机构 |
28 | Org *Org `json:"org"` | 30 | Org *Org `json:"org"` |
29 | // 公司 | 31 | // 公司 |
@@ -20,6 +20,8 @@ type DividendsReturnedOrder struct { | @@ -20,6 +20,8 @@ type DividendsReturnedOrder struct { | ||
20 | DividendsReturnedDate time.Time `json:"dividendsReturnedDate"` | 20 | DividendsReturnedDate time.Time `json:"dividendsReturnedDate"` |
21 | // 退货区域 | 21 | // 退货区域 |
22 | Region *RegionInfo `json:"region"` | 22 | Region *RegionInfo `json:"region"` |
23 | + // 退货单产品列表 | ||
24 | + Goods []*OrderGood `json:"goods"` | ||
23 | // 备注 | 25 | // 备注 |
24 | Remarks string `json:"remarks"` | 26 | Remarks string `json:"remarks"` |
25 | // 分红订单分红状态,1待分红,2已分红,3部分分红 | 27 | // 分红订单分红状态,1待分红,2已分红,3部分分红 |
@@ -15,7 +15,9 @@ type OrderGood struct { | @@ -15,7 +15,9 @@ type OrderGood struct { | ||
15 | // 订单产品数量 | 15 | // 订单产品数量 |
16 | OrderGoodQuantity int64 `json:"orderGoodQuantity,string"` | 16 | OrderGoodQuantity int64 `json:"orderGoodQuantity,string"` |
17 | // 关联分红订单号 | 17 | // 关联分红订单号 |
18 | - DividendsOrderNumber int64 `json:"dividendsOrderNumber,string"` | 18 | + DividendsOrderNumber string `json:"dividendsOrderNumber"` |
19 | + // 关联的分红退货单号 | ||
20 | + DividendsReturnedOrderNumber string `json:"dividendsReturnedOrderNumber"` | ||
19 | // 关联的共创合约编号 | 21 | // 关联的共创合约编号 |
20 | CooperationContractNumber string `json:"cooperationContractNumber"` | 22 | CooperationContractNumber string `json:"cooperationContractNumber"` |
21 | // 订单产品费用 | 23 | // 订单产品费用 |
@@ -55,9 +57,6 @@ func (orderGood *OrderGood) Update(data map[string]interface{}) error { | @@ -55,9 +57,6 @@ func (orderGood *OrderGood) Update(data map[string]interface{}) error { | ||
55 | if orderGoodQuantity, ok := data["orderGoodQuantity"]; ok { | 57 | if orderGoodQuantity, ok := data["orderGoodQuantity"]; ok { |
56 | orderGood.OrderGoodQuantity = orderGoodQuantity.(int64) | 58 | orderGood.OrderGoodQuantity = orderGoodQuantity.(int64) |
57 | } | 59 | } |
58 | - if dividendsOrderNumber, ok := data["dividendsOrderNumber"]; ok { | ||
59 | - orderGood.DividendsOrderNumber = dividendsOrderNumber.(int64) | ||
60 | - } | ||
61 | if cooperationContractNumber, ok := data["cooperationContractNumber"]; ok { | 60 | if cooperationContractNumber, ok := data["cooperationContractNumber"]; ok { |
62 | orderGood.CooperationContractNumber = cooperationContractNumber.(string) | 61 | orderGood.CooperationContractNumber = cooperationContractNumber.(string) |
63 | } | 62 | } |
1 | +package models | ||
2 | + | ||
3 | +import ( | ||
4 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain" | ||
5 | + "time" | ||
6 | +) | ||
7 | + | ||
8 | +type CooperationContractRelevant struct { | ||
9 | + tableName string `comment:"共创合约相关人" pg:"cooperation_contract_relevants,alias:cooperation_contract_relevant"` | ||
10 | + // 共创合约相关人id | ||
11 | + CooperationContractRelevantId int64 `comment:"共创合约相关人id" pg:"pk:cooperation_contract_relevant_id"` | ||
12 | + // 共创合约编号 | ||
13 | + CooperationContractNumber string `comment:"共创合约编号"` | ||
14 | + // 相关人 | ||
15 | + Relevant *domain.Relevant `comment:"相关人"` | ||
16 | + // 更新时间 | ||
17 | + UpdatedAt time.Time `comment:"更新时间"` | ||
18 | + // 删除时间 | ||
19 | + DeletedAt time.Time `comment:"删除时间"` | ||
20 | + // 创建时间 | ||
21 | + CreatedAt time.Time `comment:"创建时间"` | ||
22 | +} |
1 | +package models | ||
2 | + | ||
3 | +import ( | ||
4 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain" | ||
5 | + "time" | ||
6 | +) | ||
7 | + | ||
8 | +type CooperationContractUndertaker struct { | ||
9 | + tableName string `comment:"共创合约承接人" pg:"cooperation_contract_undertakers,alias:cooperation_contract_undertaker"` | ||
10 | + // 共创合约承接人id | ||
11 | + CooperationContractUndertakerId int64 `comment:"共创合约承接人id" pg:"pk:cooperation_contract_undertaker_id"` | ||
12 | + // 共创合约编号 | ||
13 | + CooperationContractNumber string `comment:"共创合约编号"` | ||
14 | + // 共创合约承接人 | ||
15 | + Undertaker *domain.Undertaker `comment:"共创合约承接人"` | ||
16 | + // 创建时间 | ||
17 | + CreatedAt time.Time `comment:"创建时间"` | ||
18 | + // 更新时间 | ||
19 | + UpdatedAt time.Time `comment:"更新时间"` | ||
20 | + // 删除时间 | ||
21 | + DeletedAt time.Time `comment:"删除时间"` | ||
22 | +} |
@@ -10,7 +10,7 @@ type DividendsOrder struct { | @@ -10,7 +10,7 @@ type DividendsOrder struct { | ||
10 | // 分红订单ID | 10 | // 分红订单ID |
11 | DividendsOrderId int64 `comment:"分红订单ID" pg:"pk:dividends_order_id"` | 11 | DividendsOrderId int64 `comment:"分红订单ID" pg:"pk:dividends_order_id"` |
12 | // 分红订单号 | 12 | // 分红订单号 |
13 | - DividendsOrderNumber int64 `comment:"分红订单号"` | 13 | + DividendsOrderNumber string `comment:"分红订单号"` |
14 | // 分红订单原单号 | 14 | // 分红订单原单号 |
15 | DividendsOriginalOrderNum string `comment:"分红订单原单号"` | 15 | DividendsOriginalOrderNum string `comment:"分红订单原单号"` |
16 | // 分红订单金额 | 16 | // 分红订单金额 |
@@ -15,7 +15,9 @@ type OrderGood struct { | @@ -15,7 +15,9 @@ type OrderGood struct { | ||
15 | // 订单产品数量 | 15 | // 订单产品数量 |
16 | OrderGoodQuantity int64 `comment:"订单产品数量"` | 16 | OrderGoodQuantity int64 `comment:"订单产品数量"` |
17 | // 关联分红订单号 | 17 | // 关联分红订单号 |
18 | - DividendsOrderNumber int64 `comment:"关联分红订单号"` | 18 | + DividendsOrderNumber string `comment:"关联分红订单号"` |
19 | + // 关联的分红退货单号 | ||
20 | + DividendsReturnedOrderNumber string `comment:"关联的分红退货单号"` | ||
19 | // 关联的共创合约编号 | 21 | // 关联的共创合约编号 |
20 | CooperationContractNumber string `comment:"关联的共创合约编号"` | 22 | CooperationContractNumber string `comment:"关联的共创合约编号"` |
21 | // 订单产品费用 | 23 | // 订单产品费用 |
@@ -9,8 +9,10 @@ func TransformToCooperationContractDomainModelFromPgModels( | @@ -9,8 +9,10 @@ func TransformToCooperationContractDomainModelFromPgModels( | ||
9 | cooperationContractModel *models.CooperationContract, | 9 | cooperationContractModel *models.CooperationContract, |
10 | cooperationMode *models.CooperationMode, | 10 | cooperationMode *models.CooperationMode, |
11 | dividendsIncentivesRules []*models.DividendsIncentivesRule, | 11 | dividendsIncentivesRules []*models.DividendsIncentivesRule, |
12 | - moneyIncentivesRules []*models.MoneyIncentivesRule) (*domain.CooperationContract, error) { | ||
13 | - | 12 | + moneyIncentivesRules []*models.MoneyIncentivesRule, |
13 | + relevantPeople []*models.CooperationContractRelevant, | ||
14 | + undertakers []*models.CooperationContractUndertaker) (*domain.CooperationContract, error) { | ||
15 | + // 分红激励规则 | ||
14 | var dividendsIncentivesRulesDomain []*domain.DividendsIncentivesRule | 16 | var dividendsIncentivesRulesDomain []*domain.DividendsIncentivesRule |
15 | for _, rule := range dividendsIncentivesRules { | 17 | for _, rule := range dividendsIncentivesRules { |
16 | dividendsIncentivesRulesDomain = append(dividendsIncentivesRulesDomain, &domain.DividendsIncentivesRule{ | 18 | dividendsIncentivesRulesDomain = append(dividendsIncentivesRulesDomain, &domain.DividendsIncentivesRule{ |
@@ -29,7 +31,7 @@ func TransformToCooperationContractDomainModelFromPgModels( | @@ -29,7 +31,7 @@ func TransformToCooperationContractDomainModelFromPgModels( | ||
29 | CreatedAt: rule.CreatedAt, | 31 | CreatedAt: rule.CreatedAt, |
30 | }) | 32 | }) |
31 | } | 33 | } |
32 | - | 34 | + // 金额激励规则 |
33 | var moneyIncentivesRulesDomain []*domain.MoneyIncentivesRule | 35 | var moneyIncentivesRulesDomain []*domain.MoneyIncentivesRule |
34 | for _, rule := range moneyIncentivesRules { | 36 | for _, rule := range moneyIncentivesRules { |
35 | moneyIncentivesRulesDomain = append(moneyIncentivesRulesDomain, &domain.MoneyIncentivesRule{ | 37 | moneyIncentivesRulesDomain = append(moneyIncentivesRulesDomain, &domain.MoneyIncentivesRule{ |
@@ -49,7 +51,39 @@ func TransformToCooperationContractDomainModelFromPgModels( | @@ -49,7 +51,39 @@ func TransformToCooperationContractDomainModelFromPgModels( | ||
49 | CreatedAt: rule.CreatedAt, | 51 | CreatedAt: rule.CreatedAt, |
50 | }) | 52 | }) |
51 | } | 53 | } |
52 | - | 54 | + // 相关人列表 |
55 | + var relevantPeopleDomain []*domain.Relevant | ||
56 | + for _, relevant := range relevantPeople { | ||
57 | + relevantPeopleDomain = append(relevantPeopleDomain, &domain.Relevant{ | ||
58 | + UserId: relevant.Relevant.UserId, | ||
59 | + UserBaseId: relevant.Relevant.UserBaseId, | ||
60 | + Org: relevant.Relevant.Org, | ||
61 | + Orgs: relevant.Relevant.Orgs, | ||
62 | + Department: relevant.Relevant.Department, | ||
63 | + Role: relevant.Relevant.Role, | ||
64 | + UserInfo: relevant.Relevant.UserInfo, | ||
65 | + UserType: relevant.Relevant.UserType, | ||
66 | + Status: relevant.Relevant.Status, | ||
67 | + Company: relevant.Relevant.Company, | ||
68 | + }) | ||
69 | + } | ||
70 | + // 承接人列表 | ||
71 | + var undertakersDomain []*domain.Undertaker | ||
72 | + for _, undertaker := range undertakers { | ||
73 | + undertakersDomain = append(undertakersDomain, &domain.Undertaker{ | ||
74 | + UserId: undertaker.Undertaker.UserId, | ||
75 | + UserBaseId: undertaker.Undertaker.UserBaseId, | ||
76 | + Org: undertaker.Undertaker.Org, | ||
77 | + Orgs: undertaker.Undertaker.Orgs, | ||
78 | + Department: undertaker.Undertaker.Department, | ||
79 | + Role: undertaker.Undertaker.Role, | ||
80 | + UserInfo: undertaker.Undertaker.UserInfo, | ||
81 | + UserType: undertaker.Undertaker.UserType, | ||
82 | + Status: undertaker.Undertaker.Status, | ||
83 | + Company: undertaker.Undertaker.Company, | ||
84 | + ContractAttachment: undertaker.Undertaker.ContractAttachment, | ||
85 | + }) | ||
86 | + } | ||
53 | return &domain.CooperationContract{ | 87 | return &domain.CooperationContract{ |
54 | CooperationContractId: cooperationContractModel.CooperationContractId, | 88 | CooperationContractId: cooperationContractModel.CooperationContractId, |
55 | CooperationContractDescription: cooperationContractModel.CooperationContractDescription, | 89 | CooperationContractDescription: cooperationContractModel.CooperationContractDescription, |
@@ -75,6 +109,8 @@ func TransformToCooperationContractDomainModelFromPgModels( | @@ -75,6 +109,8 @@ func TransformToCooperationContractDomainModelFromPgModels( | ||
75 | }, | 109 | }, |
76 | DividendsIncentivesRules: dividendsIncentivesRulesDomain, | 110 | DividendsIncentivesRules: dividendsIncentivesRulesDomain, |
77 | MoneyIncentivesRules: moneyIncentivesRulesDomain, | 111 | MoneyIncentivesRules: moneyIncentivesRulesDomain, |
112 | + RelevantPeople: relevantPeopleDomain, | ||
113 | + Undertakers: undertakersDomain, | ||
78 | Status: cooperationContractModel.Status, | 114 | Status: cooperationContractModel.Status, |
79 | Org: cooperationContractModel.Org, | 115 | Org: cooperationContractModel.Org, |
80 | Company: cooperationContractModel.Company, | 116 | Company: cooperationContractModel.Company, |
1 | +package transform | ||
2 | + | ||
3 | +import ( | ||
4 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain" | ||
5 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg/models" | ||
6 | +) | ||
7 | + | ||
8 | +func TransformToCooperationContractRelevantDomainModelFromPgModels(cooperationContractRelevantModel *models.CooperationContractRelevant) (*domain.CooperationContractRelevant, error) { | ||
9 | + return &domain.CooperationContractRelevant{ | ||
10 | + CooperationContractRelevantId: cooperationContractRelevantModel.CooperationContractRelevantId, | ||
11 | + CooperationContractNumber: cooperationContractRelevantModel.CooperationContractNumber, | ||
12 | + Relevant: cooperationContractRelevantModel.Relevant, | ||
13 | + UpdatedAt: cooperationContractRelevantModel.UpdatedAt, | ||
14 | + DeletedAt: cooperationContractRelevantModel.DeletedAt, | ||
15 | + CreatedAt: cooperationContractRelevantModel.CreatedAt, | ||
16 | + }, nil | ||
17 | +} |
1 | +package transform | ||
2 | + | ||
3 | +import ( | ||
4 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain" | ||
5 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg/models" | ||
6 | +) | ||
7 | + | ||
8 | +func TransformToCooperationContractUndertakerDomainModelFromPgModels(cooperationContractUndertakerModel *models.CooperationContractUndertaker) (*domain.CooperationContractUndertaker, error) { | ||
9 | + return &domain.CooperationContractUndertaker{ | ||
10 | + CooperationContractUndertakerId: cooperationContractUndertakerModel.CooperationContractUndertakerId, | ||
11 | + CooperationContractNumber: cooperationContractUndertakerModel.CooperationContractNumber, | ||
12 | + Undertaker: cooperationContractUndertakerModel.Undertaker, | ||
13 | + CreatedAt: cooperationContractUndertakerModel.CreatedAt, | ||
14 | + UpdatedAt: cooperationContractUndertakerModel.UpdatedAt, | ||
15 | + DeletedAt: cooperationContractUndertakerModel.DeletedAt, | ||
16 | + }, nil | ||
17 | +} |
@@ -5,7 +5,27 @@ import ( | @@ -5,7 +5,27 @@ import ( | ||
5 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg/models" | 5 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg/models" |
6 | ) | 6 | ) |
7 | 7 | ||
8 | -func TransformToDividendsOrderDomainModelFromPgModels(dividendsOrderModel *models.DividendsOrder) (*domain.DividendsOrder, error) { | 8 | +func TransformToDividendsOrderDomainModelFromPgModels( |
9 | + dividendsOrderModel *models.DividendsOrder, | ||
10 | + goods []*models.OrderGood, | ||
11 | +) (*domain.DividendsOrder, error) { | ||
12 | + var orderGoods []*domain.OrderGood | ||
13 | + for _, good := range goods { | ||
14 | + orderGoods = append(orderGoods, &domain.OrderGood{ | ||
15 | + OrderGoodId: good.OrderGoodId, | ||
16 | + OrderGoodAmount: good.OrderGoodAmount, | ||
17 | + OrderGoodName: good.OrderGoodName, | ||
18 | + OrderGoodPrice: good.OrderGoodPrice, | ||
19 | + OrderGoodQuantity: good.OrderGoodQuantity, | ||
20 | + DividendsOrderNumber: good.DividendsReturnedOrderNumber, | ||
21 | + DividendsReturnedOrderNumber: good.DividendsOrderNumber, | ||
22 | + CooperationContractNumber: good.CooperationContractNumber, | ||
23 | + OrderGoodExpense: good.OrderGoodExpense, | ||
24 | + CreatedAt: good.CreatedAt, | ||
25 | + DeletedAt: good.DeletedAt, | ||
26 | + UpdatedAt: good.UpdatedAt, | ||
27 | + }) | ||
28 | + } | ||
9 | return &domain.DividendsOrder{ | 29 | return &domain.DividendsOrder{ |
10 | DividendsOrderId: dividendsOrderModel.DividendsOrderId, | 30 | DividendsOrderId: dividendsOrderModel.DividendsOrderId, |
11 | DividendsOrderNumber: dividendsOrderModel.DividendsOrderNumber, | 31 | DividendsOrderNumber: dividendsOrderModel.DividendsOrderNumber, |
@@ -18,6 +38,7 @@ func TransformToDividendsOrderDomainModelFromPgModels(dividendsOrderModel *model | @@ -18,6 +38,7 @@ func TransformToDividendsOrderDomainModelFromPgModels(dividendsOrderModel *model | ||
18 | Region: dividendsOrderModel.Region, | 38 | Region: dividendsOrderModel.Region, |
19 | CustomerName: dividendsOrderModel.CustomerName, | 39 | CustomerName: dividendsOrderModel.CustomerName, |
20 | Org: dividendsOrderModel.Org, | 40 | Org: dividendsOrderModel.Org, |
41 | + Goods: orderGoods, | ||
21 | Company: dividendsOrderModel.Company, | 42 | Company: dividendsOrderModel.Company, |
22 | CreatedAt: dividendsOrderModel.CreatedAt, | 43 | CreatedAt: dividendsOrderModel.CreatedAt, |
23 | DeletedAt: dividendsOrderModel.DeletedAt, | 44 | DeletedAt: dividendsOrderModel.DeletedAt, |
@@ -5,7 +5,26 @@ import ( | @@ -5,7 +5,26 @@ import ( | ||
5 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg/models" | 5 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg/models" |
6 | ) | 6 | ) |
7 | 7 | ||
8 | -func TransformToDividendsReturnedOrderDomainModelFromPgModels(dividendsReturnedOrderModel *models.DividendsReturnedOrder) (*domain.DividendsReturnedOrder, error) { | 8 | +func TransformToDividendsReturnedOrderDomainModelFromPgModels( |
9 | + dividendsReturnedOrderModel *models.DividendsReturnedOrder, | ||
10 | + goods []*models.OrderGood) (*domain.DividendsReturnedOrder, error) { | ||
11 | + var orderGoods []*domain.OrderGood | ||
12 | + for _, good := range goods { | ||
13 | + orderGoods = append(orderGoods, &domain.OrderGood{ | ||
14 | + OrderGoodId: good.OrderGoodId, | ||
15 | + OrderGoodAmount: good.OrderGoodAmount, | ||
16 | + OrderGoodName: good.OrderGoodName, | ||
17 | + OrderGoodPrice: good.OrderGoodPrice, | ||
18 | + OrderGoodQuantity: good.OrderGoodQuantity, | ||
19 | + DividendsOrderNumber: good.DividendsReturnedOrderNumber, | ||
20 | + DividendsReturnedOrderNumber: good.DividendsOrderNumber, | ||
21 | + CooperationContractNumber: good.CooperationContractNumber, | ||
22 | + OrderGoodExpense: good.OrderGoodExpense, | ||
23 | + CreatedAt: good.CreatedAt, | ||
24 | + DeletedAt: good.DeletedAt, | ||
25 | + UpdatedAt: good.UpdatedAt, | ||
26 | + }) | ||
27 | + } | ||
9 | return &domain.DividendsReturnedOrder{ | 28 | return &domain.DividendsReturnedOrder{ |
10 | DividendsReturnedOrderId: dividendsReturnedOrderModel.DividendsReturnedOrderId, | 29 | DividendsReturnedOrderId: dividendsReturnedOrderModel.DividendsReturnedOrderId, |
11 | DividendsReturnedOrderNumber: dividendsReturnedOrderModel.DividendsReturnedOrderNumber, | 30 | DividendsReturnedOrderNumber: dividendsReturnedOrderModel.DividendsReturnedOrderNumber, |
@@ -18,6 +37,7 @@ func TransformToDividendsReturnedOrderDomainModelFromPgModels(dividendsReturnedO | @@ -18,6 +37,7 @@ func TransformToDividendsReturnedOrderDomainModelFromPgModels(dividendsReturnedO | ||
18 | Remarks: dividendsReturnedOrderModel.Remarks, | 37 | Remarks: dividendsReturnedOrderModel.Remarks, |
19 | DividendStatus: dividendsReturnedOrderModel.DividendStatus, | 38 | DividendStatus: dividendsReturnedOrderModel.DividendStatus, |
20 | DividendTime: dividendsReturnedOrderModel.DividendTime, | 39 | DividendTime: dividendsReturnedOrderModel.DividendTime, |
40 | + Goods: orderGoods, | ||
21 | Org: dividendsReturnedOrderModel.Org, | 41 | Org: dividendsReturnedOrderModel.Org, |
22 | Company: dividendsReturnedOrderModel.Company, | 42 | Company: dividendsReturnedOrderModel.Company, |
23 | CreatedAt: dividendsReturnedOrderModel.CreatedAt, | 43 | CreatedAt: dividendsReturnedOrderModel.CreatedAt, |
1 | +package repository | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + | ||
6 | + "github.com/linmadan/egglib-go/persistent/pg/sqlbuilder" | ||
7 | + pgTransaction "github.com/linmadan/egglib-go/transaction/pg" | ||
8 | + "github.com/linmadan/egglib-go/utils/snowflake" | ||
9 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain" | ||
10 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg/models" | ||
11 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg/transform" | ||
12 | +) | ||
13 | + | ||
14 | +type CooperationContractRelevantRepository struct { | ||
15 | + transactionContext *pgTransaction.TransactionContext | ||
16 | +} | ||
17 | + | ||
18 | +func (repository *CooperationContractRelevantRepository) nextIdentify() (int64, error) { | ||
19 | + IdWorker, err := snowflake.NewIdWorker(1) | ||
20 | + if err != nil { | ||
21 | + return 0, err | ||
22 | + } | ||
23 | + id, err := IdWorker.NextId() | ||
24 | + return id, err | ||
25 | +} | ||
26 | +func (repository *CooperationContractRelevantRepository) Save(cooperationContractRelevant *domain.CooperationContractRelevant) (*domain.CooperationContractRelevant, error) { | ||
27 | + sqlBuildFields := []string{ | ||
28 | + "cooperation_contract_relevant_id", | ||
29 | + "cooperation_contract_number", | ||
30 | + "relevant", | ||
31 | + "updated_at", | ||
32 | + "deleted_at", | ||
33 | + "created_at", | ||
34 | + } | ||
35 | + insertFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlBuildFields) | ||
36 | + insertPlaceHoldersSnippet := sqlbuilder.SqlPlaceHoldersSnippet(sqlBuildFields) | ||
37 | + returningFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlBuildFields) | ||
38 | + updateFields := sqlbuilder.RemoveSqlFields(sqlBuildFields, "cooperationContractRelevant_id") | ||
39 | + updateFieldsSnippet := sqlbuilder.SqlUpdateFieldsSnippet(updateFields) | ||
40 | + tx := repository.transactionContext.PgTx | ||
41 | + if cooperationContractRelevant.Identify() == nil { | ||
42 | + cooperationContractRelevantId, err := repository.nextIdentify() | ||
43 | + if err != nil { | ||
44 | + return cooperationContractRelevant, err | ||
45 | + } else { | ||
46 | + cooperationContractRelevant.CooperationContractRelevantId = cooperationContractRelevantId | ||
47 | + } | ||
48 | + if _, err := tx.QueryOne( | ||
49 | + pg.Scan( | ||
50 | + &cooperationContractRelevant.CooperationContractRelevantId, | ||
51 | + &cooperationContractRelevant.CooperationContractNumber, | ||
52 | + &cooperationContractRelevant.Relevant, | ||
53 | + &cooperationContractRelevant.UpdatedAt, | ||
54 | + &cooperationContractRelevant.DeletedAt, | ||
55 | + &cooperationContractRelevant.CreatedAt, | ||
56 | + ), | ||
57 | + fmt.Sprintf("INSERT INTO cooperation_contract_relevants (%s) VALUES (%s) RETURNING %s", insertFieldsSnippet, insertPlaceHoldersSnippet, returningFieldsSnippet), | ||
58 | + cooperationContractRelevant.CooperationContractRelevantId, | ||
59 | + cooperationContractRelevant.CooperationContractNumber, | ||
60 | + cooperationContractRelevant.Relevant, | ||
61 | + cooperationContractRelevant.UpdatedAt, | ||
62 | + cooperationContractRelevant.DeletedAt, | ||
63 | + cooperationContractRelevant.CreatedAt, | ||
64 | + ); err != nil { | ||
65 | + return cooperationContractRelevant, err | ||
66 | + } | ||
67 | + } else { | ||
68 | + if _, err := tx.QueryOne( | ||
69 | + pg.Scan( | ||
70 | + &cooperationContractRelevant.CooperationContractRelevantId, | ||
71 | + &cooperationContractRelevant.CooperationContractNumber, | ||
72 | + &cooperationContractRelevant.Relevant, | ||
73 | + &cooperationContractRelevant.UpdatedAt, | ||
74 | + &cooperationContractRelevant.DeletedAt, | ||
75 | + &cooperationContractRelevant.CreatedAt, | ||
76 | + ), | ||
77 | + fmt.Sprintf("UPDATE cooperation_contract_relevants SET %s WHERE cooperation_contract_relevant_id=? RETURNING %s", updateFieldsSnippet, returningFieldsSnippet), | ||
78 | + cooperationContractRelevant.CooperationContractRelevantId, | ||
79 | + cooperationContractRelevant.CooperationContractNumber, | ||
80 | + cooperationContractRelevant.Relevant, | ||
81 | + cooperationContractRelevant.UpdatedAt, | ||
82 | + cooperationContractRelevant.DeletedAt, | ||
83 | + cooperationContractRelevant.CreatedAt, | ||
84 | + cooperationContractRelevant.Identify(), | ||
85 | + ); err != nil { | ||
86 | + return cooperationContractRelevant, err | ||
87 | + } | ||
88 | + } | ||
89 | + return cooperationContractRelevant, nil | ||
90 | +} | ||
91 | +func (repository *CooperationContractRelevantRepository) Remove(cooperationContractRelevant *domain.CooperationContractRelevant) (*domain.CooperationContractRelevant, error) { | ||
92 | + tx := repository.transactionContext.PgTx | ||
93 | + cooperationContractRelevantModel := new(models.CooperationContractRelevant) | ||
94 | + cooperationContractRelevantModel.CooperationContractRelevantId = cooperationContractRelevant.Identify().(int64) | ||
95 | + if _, err := tx.Model(cooperationContractRelevantModel).WherePK().Delete(); err != nil { | ||
96 | + return cooperationContractRelevant, err | ||
97 | + } | ||
98 | + return cooperationContractRelevant, nil | ||
99 | +} | ||
100 | +func (repository *CooperationContractRelevantRepository) FindOne(queryOptions map[string]interface{}) (*domain.CooperationContractRelevant, error) { | ||
101 | + tx := repository.transactionContext.PgTx | ||
102 | + cooperationContractRelevantModel := new(models.CooperationContractRelevant) | ||
103 | + query := sqlbuilder.BuildQuery(tx.Model(cooperationContractRelevantModel), queryOptions) | ||
104 | + query.SetWhereByQueryOption("cooperation_contract_relevant.cooperation_contract_relevant_id = ?", "cooperationContractRelevantId") | ||
105 | + if err := query.First(); err != nil { | ||
106 | + if err.Error() == "pg: no rows in result set" { | ||
107 | + return nil, fmt.Errorf("没有此资源") | ||
108 | + } else { | ||
109 | + return nil, err | ||
110 | + } | ||
111 | + } | ||
112 | + if cooperationContractRelevantModel.CooperationContractRelevantId == 0 { | ||
113 | + return nil, nil | ||
114 | + } else { | ||
115 | + return transform.TransformToCooperationContractRelevantDomainModelFromPgModels(cooperationContractRelevantModel) | ||
116 | + } | ||
117 | +} | ||
118 | +func (repository *CooperationContractRelevantRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.CooperationContractRelevant, error) { | ||
119 | + tx := repository.transactionContext.PgTx | ||
120 | + var cooperationContractRelevantModels []*models.CooperationContractRelevant | ||
121 | + cooperationContractRelevants := make([]*domain.CooperationContractRelevant, 0) | ||
122 | + query := sqlbuilder.BuildQuery(tx.Model(&cooperationContractRelevantModels), queryOptions) | ||
123 | + query.SetOffsetAndLimit(20) | ||
124 | + query.SetOrderDirect("cooperation_contract_relevant_id", "DESC") | ||
125 | + if count, err := query.SelectAndCount(); err != nil { | ||
126 | + return 0, cooperationContractRelevants, err | ||
127 | + } else { | ||
128 | + for _, cooperationContractRelevantModel := range cooperationContractRelevantModels { | ||
129 | + if cooperationContractRelevant, err := transform.TransformToCooperationContractRelevantDomainModelFromPgModels(cooperationContractRelevantModel); err != nil { | ||
130 | + return 0, cooperationContractRelevants, err | ||
131 | + } else { | ||
132 | + cooperationContractRelevants = append(cooperationContractRelevants, cooperationContractRelevant) | ||
133 | + } | ||
134 | + } | ||
135 | + return int64(count), cooperationContractRelevants, nil | ||
136 | + } | ||
137 | +} | ||
138 | +func NewCooperationContractRelevantRepository(transactionContext *pgTransaction.TransactionContext) (*CooperationContractRelevantRepository, error) { | ||
139 | + if transactionContext == nil { | ||
140 | + return nil, fmt.Errorf("transactionContext参数不能为nil") | ||
141 | + } else { | ||
142 | + return &CooperationContractRelevantRepository{ | ||
143 | + transactionContext: transactionContext, | ||
144 | + }, nil | ||
145 | + } | ||
146 | +} |
@@ -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" |
@@ -167,7 +168,43 @@ func (repository *CooperationContractRepository) FindOne(queryOptions map[string | @@ -167,7 +168,43 @@ func (repository *CooperationContractRepository) FindOne(queryOptions map[string | ||
167 | if cooperationContractModel.CooperationContractId == 0 { | 168 | if cooperationContractModel.CooperationContractId == 0 { |
168 | return nil, nil | 169 | return nil, nil |
169 | } else { | 170 | } else { |
170 | - return transform.TransformToCooperationContractDomainModelFromPgModels(cooperationContractModel) | 171 | + // 获取共创模式 |
172 | + cooperationModeModels := new(models.CooperationMode) | ||
173 | + cooperationModeQuery := tx.Model(cooperationModeModels) | ||
174 | + if err := cooperationModeQuery.Where("cooperation_mode_number = ?", cooperationContractModel.CooperationModeNumber).First(); err != nil { | ||
175 | + return nil, err | ||
176 | + } | ||
177 | + // 获取分红激励规则列表 | ||
178 | + var dividendsIncentivesRuleModels []*models.DividendsIncentivesRule | ||
179 | + dividendsIncentivesRuleQuery := tx.Model(÷ndsIncentivesRuleModels) | ||
180 | + if err := dividendsIncentivesRuleQuery.Where("cooperation_contract_number = ?", cooperationContractModel.CooperationContractNumber).Select(); err != nil { | ||
181 | + return nil, err | ||
182 | + } | ||
183 | + // 获取金额激励规则列表 | ||
184 | + var moneyIncentivesRuleModels []*models.MoneyIncentivesRule | ||
185 | + moneyIncentivesRuleQuery := tx.Model(&moneyIncentivesRuleModels) | ||
186 | + if err := moneyIncentivesRuleQuery.Where("cooperation_contract_number = ?", cooperationContractModel.CooperationContractNumber).Select(); err != nil { | ||
187 | + return nil, err | ||
188 | + } | ||
189 | + // 获取承接人列表 | ||
190 | + var cooperationContractUndertakerModels []*models.CooperationContractUndertaker | ||
191 | + cooperationContractUndertakerQuery := tx.Model(&cooperationContractUndertakerModels) | ||
192 | + if err := cooperationContractUndertakerQuery.Where("cooperation_contract_number = ?", cooperationContractModel.CooperationContractNumber).Select(); err != nil { | ||
193 | + return nil, err | ||
194 | + } | ||
195 | + // 获取相关人列表 | ||
196 | + var cooperationContractRelevantModels []*models.CooperationContractRelevant | ||
197 | + cooperationContractRelevantQuery := tx.Model(&cooperationContractRelevantModels) | ||
198 | + if err := cooperationContractRelevantQuery.Where("cooperation_contract_number = ?", cooperationContractModel.CooperationContractNumber).Select(); err != nil { | ||
199 | + return nil, err | ||
200 | + } | ||
201 | + return transform.TransformToCooperationContractDomainModelFromPgModels( | ||
202 | + cooperationContractModel, | ||
203 | + cooperationModeModels, | ||
204 | + dividendsIncentivesRuleModels, | ||
205 | + moneyIncentivesRuleModels, | ||
206 | + cooperationContractRelevantModels, | ||
207 | + cooperationContractUndertakerModels) | ||
171 | } | 208 | } |
172 | } | 209 | } |
173 | func (repository *CooperationContractRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.CooperationContract, error) { | 210 | func (repository *CooperationContractRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.CooperationContract, error) { |
@@ -181,7 +218,43 @@ func (repository *CooperationContractRepository) Find(queryOptions map[string]in | @@ -181,7 +218,43 @@ func (repository *CooperationContractRepository) Find(queryOptions map[string]in | ||
181 | return 0, cooperationContracts, err | 218 | return 0, cooperationContracts, err |
182 | } else { | 219 | } else { |
183 | for _, cooperationContractModel := range cooperationContractModels { | 220 | for _, cooperationContractModel := range cooperationContractModels { |
184 | - if cooperationContract, err := transform.TransformToCooperationContractDomainModelFromPgModels(cooperationContractModel); err != nil { | 221 | + // 获取共创模式 |
222 | + cooperationModeModels := new(models.CooperationMode) | ||
223 | + cooperationModeQuery := tx.Model(cooperationModeModels) | ||
224 | + if err := cooperationModeQuery.Where("cooperation_mode_number = ?", cooperationContractModel.CooperationModeNumber).First(); err != nil { | ||
225 | + return 0, nil, err | ||
226 | + } | ||
227 | + // 获取分红激励规则列表 | ||
228 | + var dividendsIncentivesRuleModels []*models.DividendsIncentivesRule | ||
229 | + dividendsIncentivesRuleQuery := tx.Model(÷ndsIncentivesRuleModels) | ||
230 | + if err := dividendsIncentivesRuleQuery.Where("cooperation_contract_number = ?", cooperationContractModel.CooperationContractNumber).Select(); err != nil { | ||
231 | + return 0, nil, err | ||
232 | + } | ||
233 | + // 获取金额激励规则列表 | ||
234 | + var moneyIncentivesRuleModels []*models.MoneyIncentivesRule | ||
235 | + moneyIncentivesRuleQuery := tx.Model(&moneyIncentivesRuleModels) | ||
236 | + if err := moneyIncentivesRuleQuery.Where("cooperation_contract_number = ?", cooperationContractModel.CooperationContractNumber).Select(); err != nil { | ||
237 | + return 0, nil, err | ||
238 | + } | ||
239 | + // 获取承接人列表 | ||
240 | + var cooperationContractUndertakerModels []*models.CooperationContractUndertaker | ||
241 | + cooperationContractUndertakerQuery := tx.Model(&cooperationContractUndertakerModels) | ||
242 | + if err := cooperationContractUndertakerQuery.Where("cooperation_contract_number = ?", cooperationContractModel.CooperationContractNumber).Select(); err != nil { | ||
243 | + return 0, nil, err | ||
244 | + } | ||
245 | + // 获取相关人列表 | ||
246 | + var cooperationContractRelevantModels []*models.CooperationContractRelevant | ||
247 | + cooperationContractRelevantQuery := tx.Model(&cooperationContractRelevantModels) | ||
248 | + if err := cooperationContractRelevantQuery.Where("cooperation_contract_number = ?", cooperationContractModel.CooperationContractNumber).Select(); err != nil { | ||
249 | + return 0, nil, err | ||
250 | + } | ||
251 | + if cooperationContract, err := transform.TransformToCooperationContractDomainModelFromPgModels( | ||
252 | + cooperationContractModel, | ||
253 | + cooperationModeModels, | ||
254 | + dividendsIncentivesRuleModels, | ||
255 | + moneyIncentivesRuleModels, | ||
256 | + cooperationContractRelevantModels, | ||
257 | + cooperationContractUndertakerModels); err != nil { | ||
185 | return 0, cooperationContracts, err | 258 | return 0, cooperationContracts, err |
186 | } else { | 259 | } else { |
187 | cooperationContracts = append(cooperationContracts, cooperationContract) | 260 | cooperationContracts = append(cooperationContracts, cooperationContract) |
1 | +package repository | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + "github.com/go-pg/pg/v10" | ||
6 | + | ||
7 | + "github.com/linmadan/egglib-go/persistent/pg/sqlbuilder" | ||
8 | + pgTransaction "github.com/linmadan/egglib-go/transaction/pg" | ||
9 | + "github.com/linmadan/egglib-go/utils/snowflake" | ||
10 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain" | ||
11 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg/models" | ||
12 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg/transform" | ||
13 | +) | ||
14 | + | ||
15 | +type CooperationContractUndertakerRepository struct { | ||
16 | + transactionContext *pgTransaction.TransactionContext | ||
17 | +} | ||
18 | + | ||
19 | +func (repository *CooperationContractUndertakerRepository) nextIdentify() (int64, error) { | ||
20 | + IdWorker, err := snowflake.NewIdWorker(1) | ||
21 | + if err != nil { | ||
22 | + return 0, err | ||
23 | + } | ||
24 | + id, err := IdWorker.NextId() | ||
25 | + return id, err | ||
26 | +} | ||
27 | +func (repository *CooperationContractUndertakerRepository) Save(cooperationContractUndertaker *domain.CooperationContractUndertaker) (*domain.CooperationContractUndertaker, error) { | ||
28 | + sqlBuildFields := []string{ | ||
29 | + "cooperation_contract_undertaker_id", | ||
30 | + "cooperation_contract_number", | ||
31 | + "undertaker", | ||
32 | + "created_at", | ||
33 | + "updated_at", | ||
34 | + "deleted_at", | ||
35 | + } | ||
36 | + insertFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlBuildFields) | ||
37 | + insertPlaceHoldersSnippet := sqlbuilder.SqlPlaceHoldersSnippet(sqlBuildFields) | ||
38 | + returningFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlBuildFields) | ||
39 | + updateFields := sqlbuilder.RemoveSqlFields(sqlBuildFields, "cooperationContractUndertaker_id") | ||
40 | + updateFieldsSnippet := sqlbuilder.SqlUpdateFieldsSnippet(updateFields) | ||
41 | + tx := repository.transactionContext.PgTx | ||
42 | + if cooperationContractUndertaker.Identify() == nil { | ||
43 | + cooperationContractUndertakerId, err := repository.nextIdentify() | ||
44 | + if err != nil { | ||
45 | + return cooperationContractUndertaker, err | ||
46 | + } else { | ||
47 | + cooperationContractUndertaker.CooperationContractUndertakerId = cooperationContractUndertakerId | ||
48 | + } | ||
49 | + if _, err := tx.QueryOne( | ||
50 | + pg.Scan( | ||
51 | + &cooperationContractUndertaker.CooperationContractUndertakerId, | ||
52 | + &cooperationContractUndertaker.CooperationContractNumber, | ||
53 | + &cooperationContractUndertaker.Undertaker, | ||
54 | + &cooperationContractUndertaker.CreatedAt, | ||
55 | + &cooperationContractUndertaker.UpdatedAt, | ||
56 | + &cooperationContractUndertaker.DeletedAt, | ||
57 | + ), | ||
58 | + fmt.Sprintf("INSERT INTO cooperation_contract_undertakers (%s) VALUES (%s) RETURNING %s", insertFieldsSnippet, insertPlaceHoldersSnippet, returningFieldsSnippet), | ||
59 | + cooperationContractUndertaker.CooperationContractUndertakerId, | ||
60 | + cooperationContractUndertaker.CooperationContractNumber, | ||
61 | + cooperationContractUndertaker.Undertaker, | ||
62 | + cooperationContractUndertaker.CreatedAt, | ||
63 | + cooperationContractUndertaker.UpdatedAt, | ||
64 | + cooperationContractUndertaker.DeletedAt, | ||
65 | + ); err != nil { | ||
66 | + return cooperationContractUndertaker, err | ||
67 | + } | ||
68 | + } else { | ||
69 | + if _, err := tx.QueryOne( | ||
70 | + pg.Scan( | ||
71 | + &cooperationContractUndertaker.CooperationContractUndertakerId, | ||
72 | + &cooperationContractUndertaker.CooperationContractNumber, | ||
73 | + &cooperationContractUndertaker.Undertaker, | ||
74 | + &cooperationContractUndertaker.CreatedAt, | ||
75 | + &cooperationContractUndertaker.UpdatedAt, | ||
76 | + &cooperationContractUndertaker.DeletedAt, | ||
77 | + ), | ||
78 | + fmt.Sprintf("UPDATE cooperation_contract_undertakers SET %s WHERE cooperation_contract_undertaker_id=? RETURNING %s", updateFieldsSnippet, returningFieldsSnippet), | ||
79 | + cooperationContractUndertaker.CooperationContractUndertakerId, | ||
80 | + cooperationContractUndertaker.CooperationContractNumber, | ||
81 | + cooperationContractUndertaker.Undertaker, | ||
82 | + cooperationContractUndertaker.CreatedAt, | ||
83 | + cooperationContractUndertaker.UpdatedAt, | ||
84 | + cooperationContractUndertaker.DeletedAt, | ||
85 | + cooperationContractUndertaker.Identify(), | ||
86 | + ); err != nil { | ||
87 | + return cooperationContractUndertaker, err | ||
88 | + } | ||
89 | + } | ||
90 | + return cooperationContractUndertaker, nil | ||
91 | +} | ||
92 | +func (repository *CooperationContractUndertakerRepository) Remove(cooperationContractUndertaker *domain.CooperationContractUndertaker) (*domain.CooperationContractUndertaker, error) { | ||
93 | + tx := repository.transactionContext.PgTx | ||
94 | + cooperationContractUndertakerModel := new(models.CooperationContractUndertaker) | ||
95 | + cooperationContractUndertakerModel.CooperationContractUndertakerId = cooperationContractUndertaker.Identify().(int64) | ||
96 | + if _, err := tx.Model(cooperationContractUndertakerModel).WherePK().Delete(); err != nil { | ||
97 | + return cooperationContractUndertaker, err | ||
98 | + } | ||
99 | + return cooperationContractUndertaker, nil | ||
100 | +} | ||
101 | +func (repository *CooperationContractUndertakerRepository) FindOne(queryOptions map[string]interface{}) (*domain.CooperationContractUndertaker, error) { | ||
102 | + tx := repository.transactionContext.PgTx | ||
103 | + cooperationContractUndertakerModel := new(models.CooperationContractUndertaker) | ||
104 | + query := sqlbuilder.BuildQuery(tx.Model(cooperationContractUndertakerModel), queryOptions) | ||
105 | + query.SetWhereByQueryOption("cooperation_contract_undertaker.cooperation_contract_undertaker_id = ?", "cooperationContractUndertakerId") | ||
106 | + if err := query.First(); err != nil { | ||
107 | + if err.Error() == "pg: no rows in result set" { | ||
108 | + return nil, fmt.Errorf("没有此资源") | ||
109 | + } else { | ||
110 | + return nil, err | ||
111 | + } | ||
112 | + } | ||
113 | + if cooperationContractUndertakerModel.CooperationContractUndertakerId == 0 { | ||
114 | + return nil, nil | ||
115 | + } else { | ||
116 | + return transform.TransformToCooperationContractUndertakerDomainModelFromPgModels(cooperationContractUndertakerModel) | ||
117 | + } | ||
118 | +} | ||
119 | +func (repository *CooperationContractUndertakerRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.CooperationContractUndertaker, error) { | ||
120 | + tx := repository.transactionContext.PgTx | ||
121 | + var cooperationContractUndertakerModels []*models.CooperationContractUndertaker | ||
122 | + cooperationContractUndertakers := make([]*domain.CooperationContractUndertaker, 0) | ||
123 | + query := sqlbuilder.BuildQuery(tx.Model(&cooperationContractUndertakerModels), queryOptions) | ||
124 | + query.SetOffsetAndLimit(20) | ||
125 | + query.SetOrderDirect("cooperation_contract_undertaker_id", "DESC") | ||
126 | + if count, err := query.SelectAndCount(); err != nil { | ||
127 | + return 0, cooperationContractUndertakers, err | ||
128 | + } else { | ||
129 | + for _, cooperationContractUndertakerModel := range cooperationContractUndertakerModels { | ||
130 | + if cooperationContractUndertaker, err := transform.TransformToCooperationContractUndertakerDomainModelFromPgModels(cooperationContractUndertakerModel); err != nil { | ||
131 | + return 0, cooperationContractUndertakers, err | ||
132 | + } else { | ||
133 | + cooperationContractUndertakers = append(cooperationContractUndertakers, cooperationContractUndertaker) | ||
134 | + } | ||
135 | + } | ||
136 | + return int64(count), cooperationContractUndertakers, nil | ||
137 | + } | ||
138 | +} | ||
139 | +func NewCooperationContractUndertakerRepository(transactionContext *pgTransaction.TransactionContext) (*CooperationContractUndertakerRepository, error) { | ||
140 | + if transactionContext == nil { | ||
141 | + return nil, fmt.Errorf("transactionContext参数不能为nil") | ||
142 | + } else { | ||
143 | + return &CooperationContractUndertakerRepository{ | ||
144 | + transactionContext: transactionContext, | ||
145 | + }, nil | ||
146 | + } | ||
147 | +} |
-
请 注册 或 登录 后发表评论