作者 yangfu

事务修改

@@ -3,8 +3,8 @@ package auth @@ -3,8 +3,8 @@ package auth
3 import ( 3 import (
4 "fmt" 4 "fmt"
5 "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/application/factory" 5 "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/application/factory"
6 - "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/application/partnerInfo/query"  
7 - "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/application/partnerInfo/service" 6 + //"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/application/partnerInfo/query"
  7 + //"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/application/partnerInfo/service"
8 "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/domain" 8 "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/domain"
9 "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/svr" 9 "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/svr"
10 "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/utils" 10 "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/utils"
@@ -16,10 +16,10 @@ import ( @@ -16,10 +16,10 @@ import (
16 16
17 func Login(header *protocol.RequestHeader, request *protocol.LoginRequest) (rsp *protocol.LoginResponse, err error) { 17 func Login(header *protocol.RequestHeader, request *protocol.LoginRequest) (rsp *protocol.LoginResponse, err error) {
18 var ( 18 var (
19 - PartnerInfoService = service.NewPartnerInfoService(nil) 19 + transactionContext, _ = factory.CreateTransactionContext(nil)
  20 + PartnerInfoService, _ = factory.CreatePartnerInfoRepositoryIn(transactionContext)
20 partnerInfo *domain.PartnerInfo 21 partnerInfo *domain.PartnerInfo
21 result bool = false 22 result bool = false
22 - transactionContext, _ = factory.CreateTransactionContext(nil)  
23 PartnerSubAccountRepository, _ = factory.CreatePartnerSubAccountRepository(transactionContext) 23 PartnerSubAccountRepository, _ = factory.CreatePartnerSubAccountRepository(transactionContext)
24 partnerSubAccount *domain.PartnerSubAccount 24 partnerSubAccount *domain.PartnerSubAccount
25 ) 25 )
@@ -27,14 +27,10 @@ func Login(header *protocol.RequestHeader, request *protocol.LoginRequest) (rsp @@ -27,14 +27,10 @@ func Login(header *protocol.RequestHeader, request *protocol.LoginRequest) (rsp
27 return nil, err 27 return nil, err
28 } 28 }
29 defer func() { 29 defer func() {
30 - if err != nil {  
31 - log.Error(err)  
32 - transactionContext.RollbackTransaction()  
33 - return  
34 - } 30 + transactionContext.RollbackTransaction()
35 }() 31 }()
36 rsp = &protocol.LoginResponse{} 32 rsp = &protocol.LoginResponse{}
37 - if partnerInfo, err = PartnerInfoService.GetPartnerInfo(&query.GetPartnerInfoQuery{Account: request.Phone}); err != nil { 33 + if partnerInfo, err = PartnerInfoService.FindOne(map[string]interface{}{"account": request.Phone}); err != nil {
38 log.Error(err) 34 log.Error(err)
39 //子账号 35 //子账号
40 if partnerSubAccount, err = PartnerSubAccountRepository.FindOne(map[string]interface{}{"account": request.Phone}); err == nil { 36 if partnerSubAccount, err = PartnerSubAccountRepository.FindOne(map[string]interface{}{"account": request.Phone}); err == nil {
@@ -22,9 +22,7 @@ func DividendStatistics(header *protocol.RequestHeader, request *protocol.Divide @@ -22,9 +22,7 @@ func DividendStatistics(header *protocol.RequestHeader, request *protocol.Divide
22 return nil, err 22 return nil, err
23 } 23 }
24 defer func() { 24 defer func() {
25 - if err != nil {  
26 - transactionContext.RollbackTransaction()  
27 - } 25 + transactionContext.RollbackTransaction()
28 }() 26 }()
29 _, orderAll, e := OrderResponsitory.Find(utils.ObjectJsonToMap(domain.OrderQueryOption{PartnerId: header.UserId, EndTime: time.Now(), SortByCreateTime: domain.DESC})) 27 _, orderAll, e := OrderResponsitory.Find(utils.ObjectJsonToMap(domain.OrderQueryOption{PartnerId: header.UserId, EndTime: time.Now(), SortByCreateTime: domain.DESC}))
30 if e != nil { 28 if e != nil {
@@ -93,9 +91,7 @@ func DividendOrders(header *protocol.RequestHeader, request *protocol.DividendOr @@ -93,9 +91,7 @@ func DividendOrders(header *protocol.RequestHeader, request *protocol.DividendOr
93 return nil, err 91 return nil, err
94 } 92 }
95 defer func() { 93 defer func() {
96 - if err != nil {  
97 - transactionContext.RollbackTransaction()  
98 - } 94 + transactionContext.RollbackTransaction()
99 }() 95 }()
100 rsp = &protocol.DividendOrdersResponse{List: make([]*protocol.DividendOrderListItem, 0)} 96 rsp = &protocol.DividendOrdersResponse{List: make([]*protocol.DividendOrderListItem, 0)}
101 97
@@ -4,7 +4,6 @@ import ( @@ -4,7 +4,6 @@ import (
4 "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/application/factory" 4 "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/application/factory"
5 "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/domain" 5 "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/domain"
6 "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/utils" 6 "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/utils"
7 - "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/log"  
8 "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/protocol" 7 "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/protocol"
9 "time" 8 "time"
10 ) 9 )
@@ -19,9 +18,7 @@ func Template(header *protocol.RequestHeader, request *protocol.OrderDetailReque @@ -19,9 +18,7 @@ func Template(header *protocol.RequestHeader, request *protocol.OrderDetailReque
19 return nil, err 18 return nil, err
20 } 19 }
21 defer func() { 20 defer func() {
22 - if err != nil {  
23 - transactionContext.RollbackTransaction()  
24 - } 21 + transactionContext.RollbackTransaction()
25 }() 22 }()
26 err = transactionContext.CommitTransaction() 23 err = transactionContext.CommitTransaction()
27 return 24 return
@@ -39,10 +36,7 @@ func OrderDetail(header *protocol.RequestHeader, request *protocol.OrderDetailRe @@ -39,10 +36,7 @@ func OrderDetail(header *protocol.RequestHeader, request *protocol.OrderDetailRe
39 return nil, err 36 return nil, err
40 } 37 }
41 defer func() { 38 defer func() {
42 - if err != nil {  
43 - log.Error(err)  
44 - transactionContext.RollbackTransaction()  
45 - } 39 + transactionContext.RollbackTransaction()
46 }() 40 }()
47 41
48 rsp = &protocol.OrderDetailResponse{} 42 rsp = &protocol.OrderDetailResponse{}
@@ -83,10 +77,7 @@ func OrderStatistics(header *protocol.RequestHeader, request *protocol.OrderStat @@ -83,10 +77,7 @@ func OrderStatistics(header *protocol.RequestHeader, request *protocol.OrderStat
83 return nil, err 77 return nil, err
84 } 78 }
85 defer func() { 79 defer func() {
86 - if err != nil {  
87 - log.Error(err)  
88 - transactionContext.RollbackTransaction()  
89 - } 80 + transactionContext.RollbackTransaction()
90 }() 81 }()
91 rsp = &protocol.OrderStatisticsResponse{Statistics: protocol.OrderStatics{}} 82 rsp = &protocol.OrderStatisticsResponse{Statistics: protocol.OrderStatics{}}
92 if rsp.Statistics.TodayIntentionQuantity, rsp.Statistics.TodayIntentionMoney, err = OrderDao.OrderStatics(&domain.OrderStaticQuery{ 83 if rsp.Statistics.TodayIntentionQuantity, rsp.Statistics.TodayIntentionMoney, err = OrderDao.OrderStatics(&domain.OrderStaticQuery{
@@ -133,10 +124,7 @@ func OrderList(header *protocol.RequestHeader, request *protocol.OrderListReques @@ -133,10 +124,7 @@ func OrderList(header *protocol.RequestHeader, request *protocol.OrderListReques
133 return nil, err 124 return nil, err
134 } 125 }
135 defer func() { 126 defer func() {
136 - if err != nil {  
137 - log.Error(err)  
138 - transactionContext.RollbackTransaction()  
139 - } 127 + transactionContext.RollbackTransaction()
140 }() 128 }()
141 queryOption := &domain.OrderQueryOption{ 129 queryOption := &domain.OrderQueryOption{
142 PartnerId: header.UserId, 130 PartnerId: header.UserId,
@@ -29,9 +29,7 @@ func (PartnerInfoService *PartnerInfoService) CreatePartnerInfo(command *command @@ -29,9 +29,7 @@ func (PartnerInfoService *PartnerInfoService) CreatePartnerInfo(command *command
29 return nil, err 29 return nil, err
30 } 30 }
31 defer func() { 31 defer func() {
32 - if err != nil {  
33 - transactionContext.RollbackTransaction()  
34 - } 32 + transactionContext.RollbackTransaction()
35 }() 33 }()
36 34
37 newPartnerInfo := &command.PartnerInfo 35 newPartnerInfo := &command.PartnerInfo
@@ -68,9 +66,7 @@ func (PartnerInfoService *PartnerInfoService) GetPartnerInfo(command *query.GetP @@ -68,9 +66,7 @@ func (PartnerInfoService *PartnerInfoService) GetPartnerInfo(command *query.GetP
68 return nil, err 66 return nil, err
69 } 67 }
70 defer func() { 68 defer func() {
71 - if err != nil {  
72 - transactionContext.RollbackTransaction()  
73 - } 69 + transactionContext.RollbackTransaction()
74 }() 70 }()
75 var PartnerInfoRepository domain.PartnerInfoRepository 71 var PartnerInfoRepository domain.PartnerInfoRepository
76 if PartnerInfoRepository, err = factory.CreatePartnerInfoRepository(map[string]interface{}{"transactionContext": transactionContext}); err != nil { 72 if PartnerInfoRepository, err = factory.CreatePartnerInfoRepository(map[string]interface{}{"transactionContext": transactionContext}); err != nil {
@@ -100,9 +96,7 @@ func (PartnerInfoService *PartnerInfoService) UpdatePartnerInfo(command *command @@ -100,9 +96,7 @@ func (PartnerInfoService *PartnerInfoService) UpdatePartnerInfo(command *command
100 return nil, err 96 return nil, err
101 } 97 }
102 defer func() { 98 defer func() {
103 - if err != nil {  
104 - transactionContext.RollbackTransaction()  
105 - } 99 + transactionContext.RollbackTransaction()
106 }() 100 }()
107 var PartnerInfoRepository domain.PartnerInfoRepository 101 var PartnerInfoRepository domain.PartnerInfoRepository
108 if PartnerInfoRepository, err = factory.CreatePartnerInfoRepository(map[string]interface{}{"transactionContext": transactionContext}); err != nil { 102 if PartnerInfoRepository, err = factory.CreatePartnerInfoRepository(map[string]interface{}{"transactionContext": transactionContext}); err != nil {
@@ -149,9 +143,7 @@ func (PartnerInfoService *PartnerInfoService) RemovePartnerInfo(command *command @@ -149,9 +143,7 @@ func (PartnerInfoService *PartnerInfoService) RemovePartnerInfo(command *command
149 return nil, err 143 return nil, err
150 } 144 }
151 defer func() { 145 defer func() {
152 - if err != nil {  
153 - transactionContext.RollbackTransaction()  
154 - } 146 + transactionContext.RollbackTransaction()
155 }() 147 }()
156 var PartnerInfoRepository domain.PartnerInfoRepository 148 var PartnerInfoRepository domain.PartnerInfoRepository
157 if PartnerInfoRepository, err = factory.CreatePartnerInfoRepository(map[string]interface{}{"transactionContext": transactionContext}); err != nil { 149 if PartnerInfoRepository, err = factory.CreatePartnerInfoRepository(map[string]interface{}{"transactionContext": transactionContext}); err != nil {
@@ -185,9 +177,7 @@ func (PartnerInfoService *PartnerInfoService) ListPartnerInfo(command *query.Lis @@ -185,9 +177,7 @@ func (PartnerInfoService *PartnerInfoService) ListPartnerInfo(command *query.Lis
185 return nil, err 177 return nil, err
186 } 178 }
187 defer func() { 179 defer func() {
188 - if err != nil {  
189 - transactionContext.RollbackTransaction()  
190 - } 180 + transactionContext.RollbackTransaction()
191 }() 181 }()
192 var PartnerInfoRepository domain.PartnerInfoRepository 182 var PartnerInfoRepository domain.PartnerInfoRepository
193 if PartnerInfoRepository, err = factory.CreatePartnerInfoRepository(map[string]interface{}{"transactionContext": transactionContext}); err != nil { 183 if PartnerInfoRepository, err = factory.CreatePartnerInfoRepository(map[string]interface{}{"transactionContext": transactionContext}); err != nil {
@@ -24,9 +24,7 @@ func UserInfo(header *protocol.RequestHeader, request *protocol.UserInfoRequest) @@ -24,9 +24,7 @@ func UserInfo(header *protocol.RequestHeader, request *protocol.UserInfoRequest)
24 return nil, err 24 return nil, err
25 } 25 }
26 defer func() { 26 defer func() {
27 - if err != nil {  
28 - transactionContext.RollbackTransaction()  
29 - } 27 + transactionContext.RollbackTransaction()
30 }() 28 }()
31 rsp = &protocol.UserInfoResponse{} 29 rsp = &protocol.UserInfoResponse{}
32 if partnerInfo, err = PartnerInfoService.GetPartnerInfo(&query.GetPartnerInfoQuery{Id: int(header.UserId)}); err != nil { 30 if partnerInfo, err = PartnerInfoService.GetPartnerInfo(&query.GetPartnerInfoQuery{Id: int(header.UserId)}); err != nil {
@@ -88,11 +86,7 @@ func ChangePhone(header *protocol.RequestHeader, request *protocol.ChangePhoneRe @@ -88,11 +86,7 @@ func ChangePhone(header *protocol.RequestHeader, request *protocol.ChangePhoneRe
88 return nil, err 86 return nil, err
89 } 87 }
90 defer func() { 88 defer func() {
91 - if err != nil {  
92 - transactionContext.RollbackTransaction()  
93 - return  
94 - }  
95 - err = transactionContext.CommitTransaction() 89 + transactionContext.RollbackTransaction()
96 }() 90 }()
97 if partnerInfo, err = PartnerInfoService.GetPartnerInfo(&query.GetPartnerInfoQuery{Id: int(header.UserId)}); err != nil { 91 if partnerInfo, err = PartnerInfoService.GetPartnerInfo(&query.GetPartnerInfoQuery{Id: int(header.UserId)}); err != nil {
98 err = protocol.NewErrWithMessage(502, err) //账号不存在 92 err = protocol.NewErrWithMessage(502, err) //账号不存在
@@ -112,6 +106,7 @@ func ChangePhone(header *protocol.RequestHeader, request *protocol.ChangePhoneRe @@ -112,6 +106,7 @@ func ChangePhone(header *protocol.RequestHeader, request *protocol.ChangePhoneRe
112 }); err != nil { 106 }); err != nil {
113 return 107 return
114 } 108 }
  109 + err = transactionContext.CommitTransaction()
115 return 110 return
116 } 111 }
117 112
@@ -128,11 +123,7 @@ func ResetPassword(header *protocol.RequestHeader, request *protocol.ResetPasswo @@ -128,11 +123,7 @@ func ResetPassword(header *protocol.RequestHeader, request *protocol.ResetPasswo
128 return nil, err 123 return nil, err
129 } 124 }
130 defer func() { 125 defer func() {
131 - if err != nil {  
132 - transactionContext.RollbackTransaction()  
133 - return  
134 - }  
135 - err = transactionContext.CommitTransaction() 126 + transactionContext.RollbackTransaction()
136 }() 127 }()
137 if len(request.NewPwd) < 6 { 128 if len(request.NewPwd) < 6 {
138 err = protocol.NewErrWithMessage(2027) 129 err = protocol.NewErrWithMessage(2027)
@@ -156,6 +147,7 @@ func ResetPassword(header *protocol.RequestHeader, request *protocol.ResetPasswo @@ -156,6 +147,7 @@ func ResetPassword(header *protocol.RequestHeader, request *protocol.ResetPasswo
156 }); err != nil { 147 }); err != nil {
157 return 148 return
158 } 149 }
  150 + err = transactionContext.CommitTransaction()
159 return 151 return
160 } 152 }
161 153
@@ -171,11 +163,7 @@ func ChangePassword(header *protocol.RequestHeader, request *protocol.ChangePass @@ -171,11 +163,7 @@ func ChangePassword(header *protocol.RequestHeader, request *protocol.ChangePass
171 return nil, err 163 return nil, err
172 } 164 }
173 defer func() { 165 defer func() {
174 - if err != nil {  
175 - transactionContext.RollbackTransaction()  
176 - return  
177 - }  
178 - err = transactionContext.CommitTransaction() 166 + transactionContext.RollbackTransaction()
179 }() 167 }()
180 rsp = &protocol.ChangePasswordResponse{} 168 rsp = &protocol.ChangePasswordResponse{}
181 if !strings.EqualFold(request.NewPwd, request.ConfirmPwd) { 169 if !strings.EqualFold(request.NewPwd, request.ConfirmPwd) {
@@ -205,5 +193,6 @@ func ChangePassword(header *protocol.RequestHeader, request *protocol.ChangePass @@ -205,5 +193,6 @@ func ChangePassword(header *protocol.RequestHeader, request *protocol.ChangePass
205 }); err != nil { 193 }); err != nil {
206 return 194 return
207 } 195 }
  196 + err = transactionContext.CommitTransaction()
208 return 197 return
209 } 198 }
@@ -52,7 +52,7 @@ func (hook SqlGeneratePrintHook) BeforeQuery(c context.Context, q *pg.QueryEvent @@ -52,7 +52,7 @@ func (hook SqlGeneratePrintHook) BeforeQuery(c context.Context, q *pg.QueryEvent
52 func (hook SqlGeneratePrintHook) AfterQuery(c context.Context, q *pg.QueryEvent) error { 52 func (hook SqlGeneratePrintHook) AfterQuery(c context.Context, q *pg.QueryEvent) error {
53 data, err := q.FormattedQuery() 53 data, err := q.FormattedQuery()
54 //fmt.Println(string(data)) 54 //fmt.Println(string(data))
55 - if len(string(data)) > 6 { //BEGIN COMMIT 55 + if len(string(data)) > 8 { //BEGIN COMMIT
56 log.Debug(string(data)) 56 log.Debug(string(data))
57 } 57 }
58 return err 58 return err