From 50c6f1f9955a52e0c6335eb2e5f1f4c5e824a81b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=AD=90=E9=93=AD?= Date: Fri, 7 Mar 2025 11:25:53 +0800 Subject: [PATCH] cmb --- .../biz/bo/wechat_notify_register_tag_bo.go | 15 +++ internal/biz/cmb/cmb.go | 35 +++--- .../biz/repo/wechat_notify_register_tag.go | 13 +++ .../vo/wechat_notify_register_tag_status.go | 38 ++++++ .../model/wechat_notify_register_tag.gen.go | 28 +++++ internal/data/repoimpl/provider_set.go | 1 + .../repoimpl/wechat_notify_register_tag.go | 110 ++++++++++++++++++ 7 files changed, 224 insertions(+), 16 deletions(-) create mode 100644 internal/biz/bo/wechat_notify_register_tag_bo.go create mode 100644 internal/biz/repo/wechat_notify_register_tag.go create mode 100644 internal/biz/vo/wechat_notify_register_tag_status.go create mode 100644 internal/data/model/wechat_notify_register_tag.gen.go create mode 100644 internal/data/repoimpl/wechat_notify_register_tag.go diff --git a/internal/biz/bo/wechat_notify_register_tag_bo.go b/internal/biz/bo/wechat_notify_register_tag_bo.go new file mode 100644 index 0000000..68a58e2 --- /dev/null +++ b/internal/biz/bo/wechat_notify_register_tag_bo.go @@ -0,0 +1,15 @@ +package bo + +import "time" + +// WechatNotifyRegisterTagBo 领域实体Bo结构,字段和模型字段保持一致 +type WechatNotifyRegisterTagBo struct { + ID int32 + StockID string + StockCreatorMchID string + Tag string + Status uint8 + Remark string + CreateTime *time.Time + UpdateTime *time.Time +} diff --git a/internal/biz/cmb/cmb.go b/internal/biz/cmb/cmb.go index 1bce54d..cf745d0 100644 --- a/internal/biz/cmb/cmb.go +++ b/internal/biz/cmb/cmb.go @@ -8,14 +8,15 @@ import ( ) type Cmb struct { - bc *conf.Bootstrap - OrderRepo repo.OrderRepo - OrderWechatRepo repo.OrderWechatRepo - ProductRepo repo.ProductRepo - OrderNotifyRepo repo.OrderNotifyRepo - WechatCpnRepo wechatrepo.WechatCpnRepo - GenerateMixRepo mixrepos.GenerateMixRepo - CmbMixRepo mixrepos.CmbMixRepo + bc *conf.Bootstrap + OrderRepo repo.OrderRepo + OrderWechatRepo repo.OrderWechatRepo + ProductRepo repo.ProductRepo + OrderNotifyRepo repo.OrderNotifyRepo + WechatNotifyRegisterTagRepo repo.WechatNotifyRegisterTagRepo + WechatCpnRepo wechatrepo.WechatCpnRepo + GenerateMixRepo mixrepos.GenerateMixRepo + CmbMixRepo mixrepos.CmbMixRepo } func NewCmb( @@ -24,18 +25,20 @@ func NewCmb( OrderWechatRepo repo.OrderWechatRepo, ProductRepo repo.ProductRepo, OrderNotifyRepo repo.OrderNotifyRepo, + WechatNotifyRegisterTagRepo repo.WechatNotifyRegisterTagRepo, WechatCpnRepo wechatrepo.WechatCpnRepo, GenerateMixRepo mixrepos.GenerateMixRepo, CmbMixRepo mixrepos.CmbMixRepo, ) *Cmb { return &Cmb{ - bc: bc, - OrderRepo: orderRepo, - OrderWechatRepo: OrderWechatRepo, - ProductRepo: ProductRepo, - OrderNotifyRepo: OrderNotifyRepo, - WechatCpnRepo: WechatCpnRepo, - GenerateMixRepo: GenerateMixRepo, - CmbMixRepo: CmbMixRepo, + bc: bc, + OrderRepo: orderRepo, + OrderWechatRepo: OrderWechatRepo, + ProductRepo: ProductRepo, + OrderNotifyRepo: OrderNotifyRepo, + WechatNotifyRegisterTagRepo: WechatNotifyRegisterTagRepo, + WechatCpnRepo: WechatCpnRepo, + GenerateMixRepo: GenerateMixRepo, + CmbMixRepo: CmbMixRepo, } } diff --git a/internal/biz/repo/wechat_notify_register_tag.go b/internal/biz/repo/wechat_notify_register_tag.go new file mode 100644 index 0000000..b7a3da8 --- /dev/null +++ b/internal/biz/repo/wechat_notify_register_tag.go @@ -0,0 +1,13 @@ +package repo + +import ( + "context" + "voucher/internal/biz/bo" +) + +type WechatNotifyRegisterTagRepo interface { + GetByStockIdAndMchId(ctx context.Context, stockId, stockCreatorMchID string) (*bo.WechatNotifyRegisterTagBo, error) + Create(ctx context.Context, req *bo.WechatNotifyRegisterTagBo) (*bo.WechatNotifyRegisterTagBo, error) + Success(ctx context.Context, id int32) error + Fail(ctx context.Context, id int32, remark string) error +} diff --git a/internal/biz/vo/wechat_notify_register_tag_status.go b/internal/biz/vo/wechat_notify_register_tag_status.go new file mode 100644 index 0000000..7b1c2ff --- /dev/null +++ b/internal/biz/vo/wechat_notify_register_tag_status.go @@ -0,0 +1,38 @@ +package vo + +type WechatNotifyRegisterTagStatus uint8 + +const ( + WechatNotifyRegisterTagStatusWait WechatNotifyRegisterTagStatus = iota + 1 + WechatNotifyRegisterTagStatusSuccess + WechatNotifyRegisterTagStatusFail +) + +var WechatNotifyRegisterTagStatusMap = map[WechatNotifyRegisterTagStatus]string{ + WechatNotifyRegisterTagStatusWait: "待请求", + WechatNotifyRegisterTagStatusSuccess: "请求成功", + WechatNotifyRegisterTagStatusFail: "请求失败", +} + +func (s WechatNotifyRegisterTagStatus) GetText() string { + if t, ok := WechatNotifyRegisterTagStatusMap[s]; ok { + return t + } + return "未知请求状态" +} + +func (s WechatNotifyRegisterTagStatus) GetValue() uint8 { + return uint8(s) +} + +func (s WechatNotifyRegisterTagStatus) IsWait() bool { + return s == WechatNotifyRegisterTagStatusWait +} + +func (s WechatNotifyRegisterTagStatus) IsSuccess() bool { + return s == WechatNotifyRegisterTagStatusSuccess +} + +func (s WechatNotifyRegisterTagStatus) IsFail() bool { + return s == WechatNotifyRegisterTagStatusFail +} diff --git a/internal/data/model/wechat_notify_register_tag.gen.go b/internal/data/model/wechat_notify_register_tag.gen.go new file mode 100644 index 0000000..cd7a19c --- /dev/null +++ b/internal/data/model/wechat_notify_register_tag.gen.go @@ -0,0 +1,28 @@ +// Code generated by gorm.io/gen. DO NOT EDIT. +// Code generated by gorm.io/gen. DO NOT EDIT. +// Code generated by gorm.io/gen. DO NOT EDIT. + +package model + +import ( + "time" +) + +const TableNameWechatNotifyRegisterTag = "wechat_notify_register_tag" + +// WechatNotifyRegisterTag mapped from table +type WechatNotifyRegisterTag struct { + ID int32 `gorm:"column:id;primaryKey;autoIncrement:true" json:"id"` + StockID string `gorm:"column:stock_id;not null" json:"stock_id"` + StockCreatorMchID string `gorm:"column:stock_creator_mch_id;not null" json:"stock_creator_mch_id"` + Tag string `gorm:"column:tag;not null" json:"tag"` + Status uint8 `gorm:"column:status;not null" json:"status"` + Remark string `gorm:"column:remark;not null" json:"remark"` + CreateTime *time.Time `gorm:"column:create_time;not null" json:"create_time"` + UpdateTime *time.Time `gorm:"column:update_time" json:"update_time"` +} + +// TableName WechatNotifyRegisterTag's table name +func (*WechatNotifyRegisterTag) TableName() string { + return TableNameWechatNotifyRegisterTag +} diff --git a/internal/data/repoimpl/provider_set.go b/internal/data/repoimpl/provider_set.go index 333ede9..cd396f9 100644 --- a/internal/data/repoimpl/provider_set.go +++ b/internal/data/repoimpl/provider_set.go @@ -10,4 +10,5 @@ var ProviderRepoImplSet = wire.NewSet( NewOrderWechatRepoImpl, NewProductRepoImpl, NewOrderNotifyRepoImpl, + NewWechatNotifyRegisterTagRepoImpl, ) diff --git a/internal/data/repoimpl/wechat_notify_register_tag.go b/internal/data/repoimpl/wechat_notify_register_tag.go new file mode 100644 index 0000000..2306ea2 --- /dev/null +++ b/internal/data/repoimpl/wechat_notify_register_tag.go @@ -0,0 +1,110 @@ +package repoimpl + +import ( + "context" + "gorm.io/gorm" + "time" + "unicode/utf8" + "voucher/internal/biz/bo" + "voucher/internal/biz/repo" + "voucher/internal/biz/vo" + "voucher/internal/data" + "voucher/internal/data/model" +) + +// WechatNotifyRegisterTagRepoImpl . +type WechatNotifyRegisterTagRepoImpl struct { + Base[model.WechatNotifyRegisterTag, bo.WechatNotifyRegisterTagBo] + db *data.Db +} + +// NewWechatNotifyRegisterTagRepoImpl . +func NewWechatNotifyRegisterTagRepoImpl() repo.WechatNotifyRegisterTagRepo { + return &WechatNotifyRegisterTagRepoImpl{} +} + +func (p *WechatNotifyRegisterTagRepoImpl) DB(ctx context.Context) *gorm.DB { + return p.db.DB(ctx).Model(model.WechatNotifyRegisterTag{}) +} + +func (p *WechatNotifyRegisterTagRepoImpl) GetByStockIdAndMchId(ctx context.Context, stockId, stockCreatorMchID string) (*bo.WechatNotifyRegisterTagBo, error) { + info := &model.WechatNotifyRegisterTag{} + + tx := p.DB(ctx).Where(model.WechatNotifyRegisterTag{StockID: stockId, StockCreatorMchID: stockCreatorMchID}).Find(&info) + + if tx.Error != nil { + return nil, tx.Error + } + if tx.RowsAffected == 0 { + return nil, gorm.ErrRecordNotFound + } + + return p.ToBo(info), nil +} + +func (p *WechatNotifyRegisterTagRepoImpl) Create(ctx context.Context, req *bo.WechatNotifyRegisterTagBo) (*bo.WechatNotifyRegisterTagBo, error) { + now := time.Now() + + info := &model.WechatNotifyRegisterTag{ + StockID: req.StockID, + StockCreatorMchID: req.StockCreatorMchID, + Tag: req.Tag, + Status: vo.WechatNotifyRegisterTagStatusWait.GetValue(), + CreateTime: &now, + } + + if err := p.db.DB(ctx).Create(info).Error; err != nil { + return nil, err + } + + return p.ToBo(info), nil +} + +func (p *WechatNotifyRegisterTagRepoImpl) Success(ctx context.Context, id int32) error { + now := time.Now() + + res := p.db.DB(ctx). + Where(model.WechatNotifyRegisterTag{ + ID: id, + Status: vo.WechatNotifyRegisterTagStatusWait.GetValue(), + }). + Updates(model.WechatNotifyRegisterTag{ + Status: vo.WechatNotifyRegisterTagStatusSuccess.GetValue(), + UpdateTime: &now, + }) + + if res.Error != nil { + return res.Error + } + + return nil +} + +func (p *WechatNotifyRegisterTagRepoImpl) Fail(ctx context.Context, id int32, remark string) error { + + if utf8.RuneCountInString(remark) > 100 { + runes := []rune(remark) + if len(runes) > 100 { + remark = string(runes[:100]) + } + } + + now := time.Now() + + res := p.db.DB(ctx). + Where(model.WechatNotifyRegisterTag{ + ID: id, + Status: vo.WechatNotifyRegisterTagStatusWait.GetValue(), + }). + Updates(model.WechatNotifyRegisterTag{ + Status: vo.WechatNotifyRegisterTagStatusFail.GetValue(), + Remark: remark, + UpdateTime: &now, + }) + + if res.Error != nil { + return res.Error + } + + return nil +}