cmb
This commit is contained in:
parent
2f8750b1b1
commit
d6bfb1ff1d
|
|
@ -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
|
||||
}
|
||||
|
|
@ -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
|
||||
}
|
||||
|
|
@ -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 <order_notify>
|
||||
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
|
||||
}
|
||||
|
|
@ -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
|
||||
}
|
||||
Loading…
Reference in New Issue