From d6bfb1ff1d1721f44d4410f0a385ef815b44918a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=AD=90=E9=93=AD?= Date: Tue, 4 Mar 2025 18:09:46 +0800 Subject: [PATCH] cmb --- internal/biz/bo/order_notify_bo.go | 14 ++++++ internal/biz/repo/order_notify.go | 11 +++++ internal/data/model/order_notify.gen.go | 27 +++++++++++ internal/data/repoimpl/order_notify.go | 63 +++++++++++++++++++++++++ 4 files changed, 115 insertions(+) create mode 100644 internal/biz/bo/order_notify_bo.go create mode 100644 internal/biz/repo/order_notify.go create mode 100644 internal/data/model/order_notify.gen.go create mode 100644 internal/data/repoimpl/order_notify.go diff --git a/internal/biz/bo/order_notify_bo.go b/internal/biz/bo/order_notify_bo.go new file mode 100644 index 0000000..880b9dd --- /dev/null +++ b/internal/biz/bo/order_notify_bo.go @@ -0,0 +1,14 @@ +package bo + +import "time" + +// OrderNotifyBo 领域实体Bo结构,字段和模型字段保持一致 +type OrderNotifyBo struct { + ID uint64 + OrderNo string + OutRequestNo string + Request string + Responses string + CreateTime *time.Time + UpdateTime *time.Time +} diff --git a/internal/biz/repo/order_notify.go b/internal/biz/repo/order_notify.go new file mode 100644 index 0000000..39dd4b0 --- /dev/null +++ b/internal/biz/repo/order_notify.go @@ -0,0 +1,11 @@ +package repo + +import ( + "context" + "voucher/internal/biz/bo" +) + +type OrderNotifyRepo interface { + Create(ctx context.Context, req *bo.OrderNotifyBo) (*bo.OrderNotifyBo, error) + UpdateResponses(ctx context.Context, id uint64, responses string) error +} diff --git a/internal/data/model/order_notify.gen.go b/internal/data/model/order_notify.gen.go new file mode 100644 index 0000000..32c2ac6 --- /dev/null +++ b/internal/data/model/order_notify.gen.go @@ -0,0 +1,27 @@ +// 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 TableNameOrderNotify = "order_notify" + +// OrderNotify mapped from table +type OrderNotify struct { + ID uint64 `gorm:"column:id;primaryKey;autoIncrement:true" json:"id"` + OrderNo string `gorm:"column:order_no;not null" json:"order_no"` + OutRequestNo string `gorm:"column:out_request_no;not null" json:"out_request_no"` + Request string `gorm:"column:request;not null" json:"request"` + Responses string `gorm:"column:responses" json:"responses"` + CreateTime *time.Time `gorm:"column:create_time;not null" json:"create_time"` + UpdateTime *time.Time `gorm:"column:update_time" json:"update_time"` +} + +// TableName OrderNotify's table name +func (*OrderNotify) TableName() string { + return TableNameOrderNotify +} diff --git a/internal/data/repoimpl/order_notify.go b/internal/data/repoimpl/order_notify.go new file mode 100644 index 0000000..11b13cd --- /dev/null +++ b/internal/data/repoimpl/order_notify.go @@ -0,0 +1,63 @@ +package repoimpl + +import ( + "context" + "gorm.io/gorm" + "time" + "voucher/internal/biz/bo" + "voucher/internal/biz/repo" + "voucher/internal/data" + "voucher/internal/data/model" +) + +// OrderNotifyRepoImpl . +type OrderNotifyRepoImpl struct { + Base[model.OrderNotify, bo.OrderNotifyBo] + db *data.Db +} + +// NewOrderNotifyRepoImpl . +func NewOrderNotifyRepoImpl() repo.OrderNotifyRepo { + return &OrderNotifyRepoImpl{} +} + +func (p *OrderNotifyRepoImpl) DB(ctx context.Context) *gorm.DB { + return p.db.DB(ctx).Model(model.OrderNotify{}) +} + +func (p *OrderNotifyRepoImpl) Create(ctx context.Context, req *bo.OrderNotifyBo) (*bo.OrderNotifyBo, error) { + now := time.Now() + + info := &model.OrderNotify{ + OrderNo: req.OrderNo, + OutRequestNo: req.OutRequestNo, + Request: req.Request, + CreateTime: &now, + UpdateTime: &now, + } + + if err := p.db.DB(ctx).Create(info).Error; err != nil { + return nil, err + } + + return p.ToBo(info), nil +} + +func (p *OrderNotifyRepoImpl) UpdateResponses(ctx context.Context, id uint64, responses string) error { + now := time.Now() + + res := p.db.DB(ctx). + Where(model.OrderNotify{ + ID: id, + }). + Updates(model.OrderNotify{ + Responses: responses, + UpdateTime: &now, + }) + + if res.Error != nil { + return res.Error + } + + return nil +}