作者 yangfu

事务修改

... ... @@ -3,8 +3,8 @@ package auth
import (
"fmt"
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/application/factory"
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/application/partnerInfo/query"
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/application/partnerInfo/service"
//"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/application/partnerInfo/query"
//"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/application/partnerInfo/service"
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/domain"
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/svr"
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/utils"
... ... @@ -16,10 +16,10 @@ import (
func Login(header *protocol.RequestHeader, request *protocol.LoginRequest) (rsp *protocol.LoginResponse, err error) {
var (
PartnerInfoService = service.NewPartnerInfoService(nil)
transactionContext, _ = factory.CreateTransactionContext(nil)
PartnerInfoService, _ = factory.CreatePartnerInfoRepositoryIn(transactionContext)
partnerInfo *domain.PartnerInfo
result bool = false
transactionContext, _ = factory.CreateTransactionContext(nil)
PartnerSubAccountRepository, _ = factory.CreatePartnerSubAccountRepository(transactionContext)
partnerSubAccount *domain.PartnerSubAccount
)
... ... @@ -27,14 +27,10 @@ func Login(header *protocol.RequestHeader, request *protocol.LoginRequest) (rsp
return nil, err
}
defer func() {
if err != nil {
log.Error(err)
transactionContext.RollbackTransaction()
return
}
transactionContext.RollbackTransaction()
}()
rsp = &protocol.LoginResponse{}
if partnerInfo, err = PartnerInfoService.GetPartnerInfo(&query.GetPartnerInfoQuery{Account: request.Phone}); err != nil {
if partnerInfo, err = PartnerInfoService.FindOne(map[string]interface{}{"account": request.Phone}); err != nil {
log.Error(err)
//子账号
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
return nil, err
}
defer func() {
if err != nil {
transactionContext.RollbackTransaction()
}
transactionContext.RollbackTransaction()
}()
_, orderAll, e := OrderResponsitory.Find(utils.ObjectJsonToMap(domain.OrderQueryOption{PartnerId: header.UserId, EndTime: time.Now(), SortByCreateTime: domain.DESC}))
if e != nil {
... ... @@ -93,9 +91,7 @@ func DividendOrders(header *protocol.RequestHeader, request *protocol.DividendOr
return nil, err
}
defer func() {
if err != nil {
transactionContext.RollbackTransaction()
}
transactionContext.RollbackTransaction()
}()
rsp = &protocol.DividendOrdersResponse{List: make([]*protocol.DividendOrderListItem, 0)}
... ...
... ... @@ -4,7 +4,6 @@ import (
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/application/factory"
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/domain"
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/utils"
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/log"
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/protocol"
"time"
)
... ... @@ -19,9 +18,7 @@ func Template(header *protocol.RequestHeader, request *protocol.OrderDetailReque
return nil, err
}
defer func() {
if err != nil {
transactionContext.RollbackTransaction()
}
transactionContext.RollbackTransaction()
}()
err = transactionContext.CommitTransaction()
return
... ... @@ -39,10 +36,7 @@ func OrderDetail(header *protocol.RequestHeader, request *protocol.OrderDetailRe
return nil, err
}
defer func() {
if err != nil {
log.Error(err)
transactionContext.RollbackTransaction()
}
transactionContext.RollbackTransaction()
}()
rsp = &protocol.OrderDetailResponse{}
... ... @@ -83,10 +77,7 @@ func OrderStatistics(header *protocol.RequestHeader, request *protocol.OrderStat
return nil, err
}
defer func() {
if err != nil {
log.Error(err)
transactionContext.RollbackTransaction()
}
transactionContext.RollbackTransaction()
}()
rsp = &protocol.OrderStatisticsResponse{Statistics: protocol.OrderStatics{}}
if rsp.Statistics.TodayIntentionQuantity, rsp.Statistics.TodayIntentionMoney, err = OrderDao.OrderStatics(&domain.OrderStaticQuery{
... ... @@ -133,10 +124,7 @@ func OrderList(header *protocol.RequestHeader, request *protocol.OrderListReques
return nil, err
}
defer func() {
if err != nil {
log.Error(err)
transactionContext.RollbackTransaction()
}
transactionContext.RollbackTransaction()
}()
queryOption := &domain.OrderQueryOption{
PartnerId: header.UserId,
... ...
... ... @@ -29,9 +29,7 @@ func (PartnerInfoService *PartnerInfoService) CreatePartnerInfo(command *command
return nil, err
}
defer func() {
if err != nil {
transactionContext.RollbackTransaction()
}
transactionContext.RollbackTransaction()
}()
newPartnerInfo := &command.PartnerInfo
... ... @@ -68,9 +66,7 @@ func (PartnerInfoService *PartnerInfoService) GetPartnerInfo(command *query.GetP
return nil, err
}
defer func() {
if err != nil {
transactionContext.RollbackTransaction()
}
transactionContext.RollbackTransaction()
}()
var PartnerInfoRepository domain.PartnerInfoRepository
if PartnerInfoRepository, err = factory.CreatePartnerInfoRepository(map[string]interface{}{"transactionContext": transactionContext}); err != nil {
... ... @@ -100,9 +96,7 @@ func (PartnerInfoService *PartnerInfoService) UpdatePartnerInfo(command *command
return nil, err
}
defer func() {
if err != nil {
transactionContext.RollbackTransaction()
}
transactionContext.RollbackTransaction()
}()
var PartnerInfoRepository domain.PartnerInfoRepository
if PartnerInfoRepository, err = factory.CreatePartnerInfoRepository(map[string]interface{}{"transactionContext": transactionContext}); err != nil {
... ... @@ -149,9 +143,7 @@ func (PartnerInfoService *PartnerInfoService) RemovePartnerInfo(command *command
return nil, err
}
defer func() {
if err != nil {
transactionContext.RollbackTransaction()
}
transactionContext.RollbackTransaction()
}()
var PartnerInfoRepository domain.PartnerInfoRepository
if PartnerInfoRepository, err = factory.CreatePartnerInfoRepository(map[string]interface{}{"transactionContext": transactionContext}); err != nil {
... ... @@ -185,9 +177,7 @@ func (PartnerInfoService *PartnerInfoService) ListPartnerInfo(command *query.Lis
return nil, err
}
defer func() {
if err != nil {
transactionContext.RollbackTransaction()
}
transactionContext.RollbackTransaction()
}()
var PartnerInfoRepository domain.PartnerInfoRepository
if PartnerInfoRepository, err = factory.CreatePartnerInfoRepository(map[string]interface{}{"transactionContext": transactionContext}); err != nil {
... ...
... ... @@ -24,9 +24,7 @@ func UserInfo(header *protocol.RequestHeader, request *protocol.UserInfoRequest)
return nil, err
}
defer func() {
if err != nil {
transactionContext.RollbackTransaction()
}
transactionContext.RollbackTransaction()
}()
rsp = &protocol.UserInfoResponse{}
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
return nil, err
}
defer func() {
if err != nil {
transactionContext.RollbackTransaction()
return
}
err = transactionContext.CommitTransaction()
transactionContext.RollbackTransaction()
}()
if partnerInfo, err = PartnerInfoService.GetPartnerInfo(&query.GetPartnerInfoQuery{Id: int(header.UserId)}); err != nil {
err = protocol.NewErrWithMessage(502, err) //账号不存在
... ... @@ -112,6 +106,7 @@ func ChangePhone(header *protocol.RequestHeader, request *protocol.ChangePhoneRe
}); err != nil {
return
}
err = transactionContext.CommitTransaction()
return
}
... ... @@ -128,11 +123,7 @@ func ResetPassword(header *protocol.RequestHeader, request *protocol.ResetPasswo
return nil, err
}
defer func() {
if err != nil {
transactionContext.RollbackTransaction()
return
}
err = transactionContext.CommitTransaction()
transactionContext.RollbackTransaction()
}()
if len(request.NewPwd) < 6 {
err = protocol.NewErrWithMessage(2027)
... ... @@ -156,6 +147,7 @@ func ResetPassword(header *protocol.RequestHeader, request *protocol.ResetPasswo
}); err != nil {
return
}
err = transactionContext.CommitTransaction()
return
}
... ... @@ -171,11 +163,7 @@ func ChangePassword(header *protocol.RequestHeader, request *protocol.ChangePass
return nil, err
}
defer func() {
if err != nil {
transactionContext.RollbackTransaction()
return
}
err = transactionContext.CommitTransaction()
transactionContext.RollbackTransaction()
}()
rsp = &protocol.ChangePasswordResponse{}
if !strings.EqualFold(request.NewPwd, request.ConfirmPwd) {
... ... @@ -205,5 +193,6 @@ func ChangePassword(header *protocol.RequestHeader, request *protocol.ChangePass
}); err != nil {
return
}
err = transactionContext.CommitTransaction()
return
}
... ...
... ... @@ -52,7 +52,7 @@ func (hook SqlGeneratePrintHook) BeforeQuery(c context.Context, q *pg.QueryEvent
func (hook SqlGeneratePrintHook) AfterQuery(c context.Context, q *pg.QueryEvent) error {
data, err := q.FormattedQuery()
//fmt.Println(string(data))
if len(string(data)) > 6 { //BEGIN COMMIT
if len(string(data)) > 8 { //BEGIN COMMIT
log.Debug(string(data))
}
return err
... ...