cmb
This commit is contained in:
parent
e6f3d59205
commit
822ab544fe
12
gorm.sh
12
gorm.sh
|
|
@ -101,7 +101,7 @@ echo "领域实体Bo代码生成完成:${bo_file}"
|
||||||
# 生成 CRUD 操作代码部分
|
# 生成 CRUD 操作代码部分
|
||||||
echo "正在生成 CRUD 操作代码..."
|
echo "正在生成 CRUD 操作代码..."
|
||||||
|
|
||||||
repo_file="${repo_path}/${table}_repo.go"
|
repo_file="${repo_path}/${table}.go"
|
||||||
mkdir -p "${repo_path}"
|
mkdir -p "${repo_path}"
|
||||||
cat > "${repo_file}" <<EOL
|
cat > "${repo_file}" <<EOL
|
||||||
package repo
|
package repo
|
||||||
|
|
@ -120,7 +120,7 @@ type ${table_capitalized}Repo interface {
|
||||||
EOL
|
EOL
|
||||||
|
|
||||||
|
|
||||||
crud_file="${repo_impl_path}/${table}_repoImpl.go"
|
crud_file="${repo_impl_path}/${table}.go"
|
||||||
mkdir -p "${repo_impl_path}"
|
mkdir -p "${repo_impl_path}"
|
||||||
|
|
||||||
# 使用heredoc方式向文件中写入CRUD操作代码,定义了针对指定表的各种数据库操作方法,包括创建、根据ID获取、更新、删除、列表查询以及按字段查询等功能
|
# 使用heredoc方式向文件中写入CRUD操作代码,定义了针对指定表的各种数据库操作方法,包括创建、根据ID获取、更新、删除、列表查询以及按字段查询等功能
|
||||||
|
|
@ -130,17 +130,17 @@ package repoimpl
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"voucher/internal/data/model"
|
"voucher/internal/data/model"
|
||||||
"voucher/internal/biz/repository"
|
"voucher/internal/biz/repo"
|
||||||
"voucher/internal/biz/bo"
|
"voucher/internal/biz/bo"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ${table_capitalized}RepoImpl 定义了针对 ${table_capitalized} 表的 CRUD 操作
|
// ${table_capitalized}RepoImpl .
|
||||||
type ${table_capitalized}RepoImpl struct {
|
type ${table_capitalized}RepoImpl struct {
|
||||||
Base[model.${table_capitalized}, bo.${table_capitalized}Bo]
|
Base[model.${table_capitalized}, bo.${table_capitalized}Bo]
|
||||||
}
|
}
|
||||||
|
|
||||||
// New${table_capitalized}RepoImpl 创建一个新的 ${table_capitalized}RepoImpl 实例
|
// New${table_capitalized}RepoImpl .
|
||||||
func New${table_capitalized}RepoImpl() repository.${table_capitalized}Repo {
|
func New${table_capitalized}RepoImpl() repo.${table_capitalized}Repo {
|
||||||
return &${table_capitalized}RepoImpl{}
|
return &${table_capitalized}RepoImpl{}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -22,11 +22,14 @@ type OrderBo struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type OrderCreateReqBo struct {
|
type OrderCreateReqBo struct {
|
||||||
|
OrderNo string
|
||||||
OutBizNo string
|
OutBizNo string
|
||||||
ProductNo string
|
ProductNo string
|
||||||
Account string
|
Account string
|
||||||
AccountType vo.OrderAccountType
|
AccountType vo.OrderAccountType
|
||||||
Channel vo.OrderChannel
|
Channel vo.OrderChannel
|
||||||
|
AppID string
|
||||||
|
MerchantNo string
|
||||||
}
|
}
|
||||||
|
|
||||||
type OrderCreateRepBo struct {
|
type OrderCreateRepBo struct {
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,15 @@
|
||||||
|
package repo
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"voucher/internal/biz/bo"
|
||||||
|
)
|
||||||
|
|
||||||
|
type OrderRepo interface {
|
||||||
|
GetByOutBizNo(ctx context.Context, outBizNo string) (*bo.OrderBo, error)
|
||||||
|
Create(ctx context.Context, req *bo.OrderCreateReqBo) (*bo.OrderBo, error)
|
||||||
|
GetByID(ctx context.Context, id uint64) (*bo.OrderBo, error)
|
||||||
|
Ing(ctx context.Context, id uint64) error
|
||||||
|
Success(ctx context.Context, id uint64) error
|
||||||
|
Fail(ctx context.Context, id uint64) error
|
||||||
|
}
|
||||||
|
|
@ -1,13 +0,0 @@
|
||||||
package repo
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"voucher/internal/biz/bo"
|
|
||||||
)
|
|
||||||
|
|
||||||
type OrderRepo interface {
|
|
||||||
// Create 创建 CmbOrder
|
|
||||||
Create(ctx context.Context, req *bo.OrderBo) (*bo.OrderBo, error)
|
|
||||||
// GetByID 根据 ID 获取 CmbOrder
|
|
||||||
GetByID(ctx context.Context, id int32) (*bo.OrderBo, error)
|
|
||||||
}
|
|
||||||
|
|
@ -0,0 +1,142 @@
|
||||||
|
package repoimpl
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"gorm.io/gorm"
|
||||||
|
"time"
|
||||||
|
"voucher/internal/biz/bo"
|
||||||
|
"voucher/internal/biz/repo"
|
||||||
|
"voucher/internal/biz/vo"
|
||||||
|
"voucher/internal/data"
|
||||||
|
"voucher/internal/data/model"
|
||||||
|
)
|
||||||
|
|
||||||
|
// OrderRepoImpl .
|
||||||
|
type OrderRepoImpl struct {
|
||||||
|
Base[model.Order, bo.OrderBo]
|
||||||
|
db *data.Db
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewOrderRepoImpl .
|
||||||
|
func NewOrderRepoImpl() repo.OrderRepo {
|
||||||
|
return &OrderRepoImpl{}
|
||||||
|
}
|
||||||
|
|
||||||
|
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.OrderCreateReqBo) (*bo.OrderBo, error) {
|
||||||
|
now := time.Now()
|
||||||
|
|
||||||
|
info := &model.Order{
|
||||||
|
OrderNo: req.OrderNo,
|
||||||
|
OutBizNo: req.OutBizNo,
|
||||||
|
ProductNo: req.ProductNo,
|
||||||
|
Account: req.Account,
|
||||||
|
AccountType: req.AccountType.GetValue(),
|
||||||
|
Status: vo.OrderStatusWait.GetValue(),
|
||||||
|
AppID: req.AppID,
|
||||||
|
MerchantNo: req.MerchantNo,
|
||||||
|
Channel: req.Channel.GetValue(),
|
||||||
|
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) GetByOutBizNo(ctx context.Context, outBizNo string) (*bo.OrderBo, error) {
|
||||||
|
info := &model.Order{}
|
||||||
|
|
||||||
|
tx := p.DB(ctx).Where(model.Order{OutBizNo: outBizNo}).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) GetByID(ctx context.Context, id uint64) (*bo.OrderBo, error) {
|
||||||
|
info := &model.Order{}
|
||||||
|
|
||||||
|
tx := p.DB(ctx).Where(model.Order{ID: id}).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) Ing(ctx context.Context, id uint64) error {
|
||||||
|
now := time.Now()
|
||||||
|
|
||||||
|
res := p.db.DB(ctx).
|
||||||
|
Where(model.Order{
|
||||||
|
ID: id,
|
||||||
|
Status: vo.OrderStatusWait.GetValue(),
|
||||||
|
}).
|
||||||
|
Updates(model.Order{
|
||||||
|
Status: vo.OrderStatusIng.GetValue(),
|
||||||
|
UpdateTime: &now,
|
||||||
|
})
|
||||||
|
|
||||||
|
if res.Error != nil {
|
||||||
|
return res.Error
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *OrderRepoImpl) Success(ctx context.Context, id uint64) error {
|
||||||
|
now := time.Now()
|
||||||
|
|
||||||
|
res := p.db.DB(ctx).
|
||||||
|
Where(model.Order{
|
||||||
|
ID: id,
|
||||||
|
Status: vo.OrderStatusIng.GetValue(),
|
||||||
|
}).
|
||||||
|
Updates(model.Order{
|
||||||
|
Status: vo.OrderStatusSuccess.GetValue(),
|
||||||
|
UpdateTime: &now,
|
||||||
|
})
|
||||||
|
|
||||||
|
if res.Error != nil {
|
||||||
|
return res.Error
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *OrderRepoImpl) Fail(ctx context.Context, id uint64) error {
|
||||||
|
now := time.Now()
|
||||||
|
|
||||||
|
res := p.db.DB(ctx).
|
||||||
|
Where(model.Order{
|
||||||
|
ID: id,
|
||||||
|
Status: vo.OrderStatusIng.GetValue(),
|
||||||
|
}).
|
||||||
|
Updates(model.Order{
|
||||||
|
Status: vo.OrderStatusFail.GetValue(),
|
||||||
|
UpdateTime: &now,
|
||||||
|
})
|
||||||
|
|
||||||
|
if res.Error != nil {
|
||||||
|
return res.Error
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
@ -1,30 +0,0 @@
|
||||||
package repoimpl
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"voucher/internal/biz/bo"
|
|
||||||
"voucher/internal/biz/repo"
|
|
||||||
"voucher/internal/data/model"
|
|
||||||
)
|
|
||||||
|
|
||||||
// OrderRepoImpl 定义了针对 CmbOrder 表的 CRUD 操作
|
|
||||||
type OrderRepoImpl struct {
|
|
||||||
Base[model.Order, bo.OrderBo]
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewOrderRepoImpl 创建一个新的 OrderRepoImpl 实例
|
|
||||||
func NewOrderRepoImpl() repo.OrderRepo {
|
|
||||||
return &OrderRepoImpl{}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *OrderRepoImpl) Create(ctx context.Context, req *bo.OrderBo) (*bo.OrderBo, error) {
|
|
||||||
// todo 待实现
|
|
||||||
return nil, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetByID 根据 ID 获取 CmbOrder
|
|
||||||
func (r *OrderRepoImpl) GetByID(ctx context.Context, id int32) (*bo.OrderBo, error) {
|
|
||||||
var item model.Order
|
|
||||||
// todo 待实现
|
|
||||||
return r.ToBo(&item), nil
|
|
||||||
}
|
|
||||||
|
|
@ -14,6 +14,8 @@ func (s *VoucherService) CmbOrder(ctx http.Context) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// todo 签名验证
|
||||||
|
|
||||||
boReq := &bo.OrderCreateReqBo{
|
boReq := &bo.OrderCreateReqBo{
|
||||||
OutBizNo: req.TransactionId,
|
OutBizNo: req.TransactionId,
|
||||||
ProductNo: req.ActivityId,
|
ProductNo: req.ActivityId,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue