作者 陈志颖

feat:调整事务工厂方法

... ... @@ -3,11 +3,12 @@ package factory
import (
"github.com/linmadan/egglib-go/core/application"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg/transaction"
pG "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg/transaction"
)
func CreateTransactionContext(options map[string]interface{}) (application.TransactionContext, error) {
return &transaction.TransactionContext{
PgDd: pg.DB,
}, nil
//return &transaction.TransactionContext{
// PgDd: pg.DB,
//}, nil
return pG.NewPGTransactionContext(pg.DB), nil
}
... ...
... ... @@ -29,7 +29,9 @@ type CreateOrderFromBestshop struct {
DeliveryTime string `json:"deliveryTime"`
PartnerId int64 `json:"partnerId"`
OrderArea string `json:"orderArea"`
Goods []struct {
//小程序id
WxAppletId string `json:"wxAppletId"`
Goods []struct {
Id int64 `json:"id"`
//货品编号
Sn string `json:"sn"`
... ...
... ... @@ -37,7 +37,7 @@ func (s SyncOrderService) SyncOrderFromBestshop(cmd command.CreateOrderFromBests
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
_ = transactionContext.RollbackTransaction()
}()
//检查账号是否存在
... ... @@ -101,7 +101,7 @@ func (s SyncOrderService) CreateOrderFromBestshop(cmd command.CreateOrderFromBes
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
_ = transactionContext.RollbackTransaction()
}()
var (
orderBestshopRepository domain.OrderBestshopRepository
... ... @@ -117,6 +117,7 @@ func (s SyncOrderService) CreateOrderFromBestshop(cmd command.CreateOrderFromBes
}); err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
// TODO 增加小程序id
order := domain.OrderBestShop{
OrderCode: cmd.OrderCode,
OrderTime: cmd.OrderTime,
... ... @@ -135,6 +136,7 @@ func (s SyncOrderService) CreateOrderFromBestshop(cmd command.CreateOrderFromBes
IsCopy: false,
CompanyId: cmd.CompanyId,
OrderArea: cmd.OrderArea,
WxAppletId: cmd.WxAppletId,
}
err = orderBestshopRepository.Add(&order)
if err != nil {
... ... @@ -232,11 +234,16 @@ func (s SyncOrderService) copyOrderBestshopToOrderBase(orderBestshop *domain.Ord
e := fmt.Sprintf("未找到指定的合伙人的公司(partner_id=%d,company_id=%d)数据,%s", orderBestshop.PartnerId, partnerData.CompanyId, err)
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e)
}
// TODO 判断多小程序
for _, v := range companyData.Applets {
//BEST_SHOP_UNIONID string = "gh_18eb644002fb" //香米小程序原始id
//接收香米小程序的订单数据
if len(v.Id) > 0 {
//if len(v.Id) > 0 {
// canCopyOrder = true
//}
if v.Id == orderBestshop.WxAppletId {
canCopyOrder = true
break
}
}
if !canCopyOrder {
... ... @@ -329,7 +336,7 @@ func (s SyncOrderService) UpdateOrderFromBestshop(cmd command.CreateOrderFromBes
if err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, "获取orderBestshop(order_code=%s)数据失败,err=%s", cmd.OrderCode, err.Error())
}
// TODO 增加小程序id
orderData.OrderCode = cmd.OrderCode
orderData.OrderTime = cmd.OrderTime
orderData.OrderState = cmd.OrderState
... ... @@ -344,6 +351,7 @@ func (s SyncOrderService) UpdateOrderFromBestshop(cmd command.CreateOrderFromBes
orderData.DeliveryState = cmd.DeliveryState
orderData.DeliveryTime = cmd.DeliveryTime
orderData.CompanyId = cmd.CompanyId
orderData.WxAppletId = cmd.WxAppletId
err = orderBestshopRepository.Edit(orderData)
if err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, "编辑order_bestshop失败:"+err.Error())
... ...
... ... @@ -41,6 +41,8 @@ type OrderBestShop struct {
CompanyId int64 `json:"companyId"`
//订单区域
OrderArea string `json:"orderArea"`
// 微信小程序id
WxAppletId string `jsons:"wxAppletId"`
}
func (order OrderBestShop) CopyToOrderBase(o *OrderBase) {
... ...
... ... @@ -13,14 +13,18 @@ import (
func DataFromXiangMi(message *sarama.ConsumerMessage) error {
logs.Info("Done Message claimed: timestamp = %v, topic = %s offset = %v value = %v \n",
message.Timestamp, message.Topic, message.Offset, string(message.Value))
var (
msgData DataFromMessage
err error
)
err = json.Unmarshal(message.Value, &msgData)
if err != nil {
return fmt.Errorf("[Consumer][SyncBestshopOrder] 解析kafka数据失败;%s", err)
}
// TODO 使用小程序id作为module
dataAction := msgData.Module + "/" + msgData.Action
switch dataAction {
case "xiangmi.order/ship":
... ... @@ -29,6 +33,13 @@ func DataFromXiangMi(message *sarama.ConsumerMessage) error {
e := fmt.Errorf("[Consumer][SyncBestshopOrder] %s", err)
return e
}
// TODO 统一操作小程序订单
case "wxapplet.order/ship":
err = syncBestshopOrder(msgData.Data)
if err != nil {
e := fmt.Errorf("[Consumer][SyncBestshopOrder] %s", err)
return e
}
default:
logs.Error("未找到执行动作:Module=%s,Action=%s", msgData.Module, msgData.Action)
}
... ...