init dev
This commit is contained in:
parent
f5d3d4b399
commit
d53da43015
21
gorm.sh
21
gorm.sh
|
|
@ -12,7 +12,7 @@ SHELL_FOLDER=$(cd "$(dirname "\$0")" || exit; pwd)
|
|||
echo "$SHELL_FOLDER"
|
||||
|
||||
# 获取传入的表名和应用名参数,如果没有传入参数则给出提示并退出脚本
|
||||
if [ $# -lt 2 ]; then
|
||||
if [ $# -lt 1 ]; then
|
||||
echo "请传入要生成代码的表名和应用名作为参数"
|
||||
exit 1
|
||||
fi
|
||||
|
|
@ -129,27 +129,28 @@ package repoimpl
|
|||
|
||||
import (
|
||||
"context"
|
||||
"marketing/internal/data/model"
|
||||
"marketing/internal/biz/bo"
|
||||
"voucher/internal/data/model"
|
||||
"voucher/internal/biz/repository"
|
||||
"voucher/internal/biz/bo"
|
||||
)
|
||||
|
||||
// ${table_capitalized}Repository 定义了针对 ${table_capitalized} 表的 CRUD 操作
|
||||
type ${table_capitalized}Repository struct {
|
||||
// ${table_capitalized}RepoImpl 定义了针对 ${table_capitalized} 表的 CRUD 操作
|
||||
type ${table_capitalized}RepoImpl struct {
|
||||
Base[model.${table_capitalized}, bo.${table_capitalized}Bo]
|
||||
}
|
||||
|
||||
// New${table_capitalized}Repository 创建一个新的 ${table_capitalized}Repository 实例
|
||||
func New${table_capitalized}Repository() *${table_capitalized}Repository {
|
||||
return &${table_capitalized}Repository{}
|
||||
// New${table_capitalized}RepoImpl 创建一个新的 ${table_capitalized}RepoImpl 实例
|
||||
func New${table_capitalized}RepoImpl() repository.${table_capitalized}Repo {
|
||||
return &${table_capitalized}RepoImpl{}
|
||||
}
|
||||
|
||||
func (r *${table_capitalized}Repository) Create(ctx context.Context, req *bo.${table_capitalized}Bo) (*bo.${table_capitalized}Bo, error) {
|
||||
func (r *${table_capitalized}RepoImpl) Create(ctx context.Context, req *bo.${table_capitalized}Bo) (*bo.${table_capitalized}Bo, error) {
|
||||
// todo 待实现
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// GetByID 根据 ID 获取 ${table_capitalized}
|
||||
func (r *${table_capitalized}Repository) GetByID(ctx context.Context,id int32) (*bo.${table_capitalized}Bo, error) {
|
||||
func (r *${table_capitalized}RepoImpl) GetByID(ctx context.Context,id int32) (*bo.${table_capitalized}Bo, error) {
|
||||
var item model.${table_capitalized}
|
||||
// todo 待实现
|
||||
return r.ToBo(&item), nil
|
||||
|
|
|
|||
|
|
@ -0,0 +1 @@
|
|||
package consume
|
||||
|
|
@ -0,0 +1 @@
|
|||
package consume
|
||||
|
|
@ -0,0 +1 @@
|
|||
package consume
|
||||
|
|
@ -0,0 +1 @@
|
|||
package consume
|
||||
|
|
@ -13,3 +13,5 @@ type VoucherBiz struct {
|
|||
func NewVoucherBiz(orderRepo repository.OrderRepo, thirdMQSend thirdrepository.ThirdMQSend) *VoucherBiz {
|
||||
return &VoucherBiz{OrderRepo: orderRepo, ThirdMQSend: thirdMQSend}
|
||||
}
|
||||
|
||||
// 1:收单
|
||||
|
|
|
|||
|
|
@ -1,19 +0,0 @@
|
|||
package model
|
||||
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
// Order .
|
||||
type Order struct {
|
||||
Id uint32 `gorm:"column:id;primary_key;AUTO_INCREMENT;NOT NULL"`
|
||||
OrderNo string `gorm:"column:jd_order_no;default:;NOT NULL;comment:'京东唯一请求单号'"`
|
||||
|
||||
CreateTime *time.Time `gorm:"column:create_time;NOT NULL"`
|
||||
UpdateTime *time.Time `gorm:"column:update_time;default:NULL"`
|
||||
}
|
||||
|
||||
// TableName 表名
|
||||
func (j *Order) TableName() string {
|
||||
return "order"
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package repositoryimpl
|
||||
package repoimpl
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package repositoryimpl
|
||||
package repoimpl
|
||||
|
||||
import (
|
||||
"github.com/google/wire"
|
||||
|
|
@ -1,95 +0,0 @@
|
|||
package repositoryimpl
|
||||
|
||||
import (
|
||||
"context"
|
||||
"gorm.io/gorm"
|
||||
"time"
|
||||
"voucher/internal/biz/bo"
|
||||
"voucher/internal/biz/repository"
|
||||
"voucher/internal/data"
|
||||
"voucher/internal/data/model"
|
||||
)
|
||||
|
||||
type OrderRepoImpl struct {
|
||||
Base[model.Order, bo.OrderBo]
|
||||
db *data.Db
|
||||
}
|
||||
|
||||
func NewOrderRepoImpl(db *data.Db) repository.OrderRepo {
|
||||
return &OrderRepoImpl{db: db}
|
||||
}
|
||||
|
||||
func (p *OrderRepoImpl) DB(ctx context.Context) *gorm.DB {
|
||||
return p.db.DB(ctx).Model(model.Order{})
|
||||
}
|
||||
|
||||
func (p *OrderRepoImpl) Create(ctx context.Context, req *bo.OrderBo) (*bo.OrderBo, error) {
|
||||
now := time.Now()
|
||||
|
||||
info := &model.Order{
|
||||
CreateTime: &now,
|
||||
UpdateTime: &now,
|
||||
}
|
||||
|
||||
tx := p.db.DB(ctx).Create(info)
|
||||
if tx.Error != nil {
|
||||
return nil, tx.Error
|
||||
}
|
||||
|
||||
return p.ToBo(info), nil
|
||||
}
|
||||
|
||||
func (p *OrderRepoImpl) GetByOrderNo(ctx context.Context, orderNo string) (*bo.OrderBo, error) {
|
||||
info := &model.Order{}
|
||||
|
||||
tx := p.DB(ctx).Where(model.Order{OrderNo: orderNo}).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 *OrderRepoImpl) Success(ctx context.Context, id uint32, product string) error {
|
||||
now := time.Now()
|
||||
|
||||
res := p.db.DB(ctx).
|
||||
Where(model.Order{
|
||||
Id: id,
|
||||
//Status: trans3.JdOrderStatusGenerating.GetValue(),
|
||||
}).
|
||||
Updates(model.Order{
|
||||
|
||||
UpdateTime: &now,
|
||||
})
|
||||
|
||||
if res.Error != nil {
|
||||
return res.Error
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *OrderRepoImpl) Fail(ctx context.Context, id uint32) error {
|
||||
now := time.Now()
|
||||
|
||||
res := p.db.DB(ctx).
|
||||
Where(model.Order{
|
||||
Id: id,
|
||||
//Status: trans3.JdOrderStatusGenerating.GetValue(),
|
||||
}).
|
||||
Updates(model.Order{
|
||||
|
||||
UpdateTime: &now,
|
||||
})
|
||||
|
||||
if res.Error != nil {
|
||||
return res.Error
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
Loading…
Reference in New Issue