You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
55 lines
1.1 KiB
55 lines
1.1 KiB
package logic
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"demo/internal/svc"
|
|
"demo/internal/types"
|
|
teThoroughlyRegisterModel "demo/model"
|
|
|
|
"github.com/google/uuid"
|
|
"github.com/jinzhu/copier"
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
)
|
|
|
|
type TestingLogic struct {
|
|
logx.Logger
|
|
ctx context.Context
|
|
svcCtx *svc.ServiceContext
|
|
}
|
|
|
|
func NewTestingLogic(ctx context.Context, svcCtx *svc.ServiceContext) *TestingLogic {
|
|
return &TestingLogic{
|
|
Logger: logx.WithContext(ctx),
|
|
ctx: ctx,
|
|
svcCtx: svcCtx,
|
|
}
|
|
}
|
|
|
|
func (l *TestingLogic) Testing(req *types.TestRequest) (resp *types.TestResponse, err error) {
|
|
// 拷贝赋值
|
|
insData := new(teThoroughlyRegisterModel.TeThoroughlyRegister)
|
|
copier.Copy(insData, req)
|
|
// 额外赋值
|
|
insData.Id = uuid.New().String()
|
|
timeUnix := time.Now()
|
|
insData.CreatedAt = timeUnix
|
|
insData.UpdatedAt = timeUnix
|
|
insData.DeleteAt = 0
|
|
insData.CreatedBy = "admin"
|
|
insData.UpdatedBy = "admin"
|
|
|
|
// 插入数据
|
|
_, err = l.svcCtx.DbModel.Insert(l.ctx, insData)
|
|
if err != nil {
|
|
// 返回错误
|
|
return nil, err
|
|
}
|
|
// 返回数据
|
|
return &types.TestResponse{
|
|
Message: "success",
|
|
Success: true,
|
|
Result: insData,
|
|
}, nil
|
|
}
|
|
|