修复json的类型影响

This commit is contained in:
eson 2023-08-24 11:47:22 +08:00
parent 500611236e
commit d8ddad6fe9
18 changed files with 190 additions and 56 deletions

View File

@ -14,6 +14,7 @@ func TestXMain(t *testing.T) {
for _, line := range re.FindStringSubmatch(a) {
log.Println(line)
}
log.Println(re.FindStringSubmatch(a))
// testGenDir = "../" + testGenDir
// GenAllModels(testGenDir, TableNameComment{

View File

@ -229,6 +229,10 @@ func main() {
if name == "-" {
tablenames := GetAllTableNames(mysqluri)
for _, testName := range tablenames {
// if testName != "fs_user_info" {
// continue
// }
cols, tname, tcomment := GetColsFromTable(testName, db)
GenFromPath(testGenDir, cols, tname, tcomment)
@ -288,7 +292,6 @@ func GenFromPath(mdir string, cols []Column, tableName string, tableComment stri
default:
defaultString = "default:" + *col.DefaultValue + ";"
}
} else {
switch typeName {
@ -305,6 +308,9 @@ func GenFromPath(mdir string, cols []Column, tableName string, tableComment stri
case "*bool":
defaultString = "default:0;"
default:
// if fieldName == "Metadata" {
// log.Println()
// }
fieldName = "// " + fieldName + " " + col.Type
}
}
@ -508,6 +514,10 @@ func ParserDDL(ddl string) (result []Column, tableName, tableComment string) {
Type: strings.ToLower(m[2]),
}
if col.Type == "json" {
col.Type = "blob"
}
col.IndexType = fieldmap[col.Name]
if m[3] != "" {

1
go.mod
View File

@ -68,6 +68,7 @@ require (
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20230530153820-e85fd2cbaebc // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230530153820-e85fd2cbaebc // indirect
gorm.io/datatypes v1.2.0 // indirect
)
require (

2
go.sum
View File

@ -979,6 +979,8 @@ gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gorm.io/datatypes v1.2.0 h1:5YT+eokWdIxhJgWHdrb2zYUimyk0+TaFth+7a0ybzco=
gorm.io/datatypes v1.2.0/go.mod h1:o1dh0ZvjIjhH/bngTpypG6lVRJ5chTBxE09FH/71k04=
gorm.io/driver/mysql v1.5.1 h1:WUEH5VF9obL/lTtzjmML/5e6VfFR/788coz2uaVCAZw=
gorm.io/driver/mysql v1.5.1/go.mod h1:Jo3Xu7mMhCyj8dlrb3WoCaRd1FhsVh+yMXb1jUInf5o=
gorm.io/gorm v1.25.1 h1:nsSALe5Pr+cM3V1qwwQ7rOkw+6UeLrX5O4v3llhHa64=

View File

@ -25,6 +25,7 @@ type FsProductModel3d struct {
Price *int64 `gorm:"default:0;" json:"price"` // 仅配件用,配件的价格, 单位:美分
Sku *string `gorm:"default:'';" json:"sku"` // sku
IsHot *int64 `gorm:"default:0;" json:"is_hot"` // 是否热门
IsCloudRender *int64 `gorm:"default:0;" json:"is_cloud_render"` // 是否设置为云渲染模型
}
type FsProductModel3dModel struct {
db *gorm.DB

View File

@ -6,24 +6,25 @@ import (
// fs_product_template_v2 产品-模型-模板表
type FsProductTemplateV2 struct {
Id int64 `gorm:"primary_key;default:0;auto_increment;" json:"id"` //
ProductId *int64 `gorm:"index;default:0;" json:"product_id"` // 产品ID
ModelId *int64 `gorm:"default:0;" json:"model_id"` // 模型ID
Title *string `gorm:"default:'';" json:"title"` // 模板sku,预留字段
Name *string `gorm:"default:'';" json:"name"` // 名称
CoverImg *string `gorm:"default:'';" json:"cover_img"` // 模板背景图
TemplateInfo *string `gorm:"default:'';" json:"template_info"` // 模板详情
MaterialImg *string `gorm:"default:'';" json:"material_img"` // 合成好的贴图
Sort *int64 `gorm:"default:0;" json:"sort"` // 排序
LogoWidth *int64 `gorm:"default:0;" json:"logo_width"` // logo图最大宽度
LogoHeight *int64 `gorm:"default:0;" json:"logo_height"` // logo图最大高度
IsPublic *int64 `gorm:"default:0;" json:"is_public"` // 是否可公用1:可以0不可以
Status *int64 `gorm:"default:0;" json:"status"` // 状态1正常 2异常
Ctime *int64 `gorm:"default:0;" json:"ctime"` // 添加时间
TemplateTag *string `gorm:"default:'';" json:"template_tag"` // 标签(用户自填)
IsDel *int64 `gorm:"default:0;" json:"is_del"` // 是否删除 1删除
SwitchInfo *string `gorm:"default:'';" json:"switch_info"` // 开关信息
Version *int64 `gorm:"default:0;" json:"version"` // 默认1
Id int64 `gorm:"primary_key;default:0;auto_increment;" json:"id"` //
ProductId *int64 `gorm:"index;default:0;" json:"product_id"` // 产品ID
ModelId *int64 `gorm:"default:0;" json:"model_id"` // 模型ID
Title *string `gorm:"default:'';" json:"title"` // 模板sku,预留字段
Name *string `gorm:"default:'';" json:"name"` // 名称
CoverImg *string `gorm:"default:'';" json:"cover_img"` // 模板背景图
TemplateInfo *string `gorm:"default:'';" json:"template_info"` // 模板详情
MaterialImg *string `gorm:"default:'';" json:"material_img"` // 合成好的贴图
Sort *int64 `gorm:"default:0;" json:"sort"` // 排序
LogoWidth *int64 `gorm:"default:0;" json:"logo_width"` // logo图最大宽度
LogoHeight *int64 `gorm:"default:0;" json:"logo_height"` // logo图最大高度
IsPublic *int64 `gorm:"default:0;" json:"is_public"` // 是否可公用1:可以0不可以
Status *int64 `gorm:"default:0;" json:"status"` // 状态1正常 2异常
Ctime *int64 `gorm:"default:0;" json:"ctime"` // 添加时间
TemplateTag *string `gorm:"default:'';" json:"template_tag"` // 标签(用户自填)
IsDel *int64 `gorm:"default:0;" json:"is_del"` // 是否删除 1删除
SwitchInfo *string `gorm:"default:'';" json:"switch_info"` // 开关信息
Version *int64 `gorm:"default:0;" json:"version"` // 默认1
ElementModelId *int64 `gorm:"default:0;" json:"element_model_id"` // 云渲染对应模型id
}
type FsProductTemplateV2Model struct {
db *gorm.DB

View File

@ -1,8 +1,9 @@
package gmodel
import (
"gorm.io/gorm"
"time"
"gorm.io/gorm"
)
// fs_user_info 用户信息表
@ -11,7 +12,7 @@ type FsUserInfo struct {
Module *string `gorm:"default:'';" json:"module"` // 所属模块
UserId *int64 `gorm:"index;default:0;" json:"user_id"` // 用户 ID
GuestId *int64 `gorm:"index;default:0;" json:"guest_id"` // 访客 ID
Metadata *string `gorm:"default:'';" json:"metadata"` // 元数据,json格式
Metadata *[]byte `gorm:"default:'';" json:"metadata"` // 元数据,json格式
MetaKey1 *string `gorm:"default:'';" json:"meta_key1"` // 需要关键信息查询的自定义属性1,可以动态增加
Ctime *time.Time `gorm:"default:'0000-00-00 00:00:00';" json:"ctime"` //
Utime *time.Time `gorm:"default:'0000-00-00 00:00:00';" json:"utime"` //

View File

@ -17,6 +17,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
Path: "/api/auth/login",
Handler: UserLoginHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/api/auth/register",
Handler: UserRegisterHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/api/auth/accept-cookie",

View File

@ -0,0 +1,35 @@
package handler
import (
"net/http"
"reflect"
"fusenapi/utils/basic"
"fusenapi/server/auth/internal/logic"
"fusenapi/server/auth/internal/svc"
"fusenapi/server/auth/internal/types"
)
func UserRegisterHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.RequestUserRegister
userinfo, err := basic.RequestParse(w, r, svcCtx, &req)
if err != nil {
return
}
// 创建一个业务逻辑层实例
l := logic.NewUserRegisterLogic(r.Context(), svcCtx)
rl := reflect.ValueOf(l)
basic.BeforeLogic(w, r, rl)
resp := l.UserRegister(&req, userinfo)
if !basic.AfterLogic(w, r, rl, resp) {
basic.NormalAfterLogic(w, r, resp)
}
}
}

View File

@ -74,6 +74,7 @@ func (l *UserEmailConfirmationLogic) UserEmailConfirmation(req *types.RequestEma
log.Println(jwtToken) // 通过websocket去, 送回通道
case "facebook":
case "fusen":
}

View File

@ -60,7 +60,7 @@ func (l *UserEmailRegisterLogic) UserEmailRegister(req *types.RequestEmailRegist
// 确认email 重新序列化
token.Email = req.Email
token.Wid = req.Wid
token.GuestId = req.GuestId
token.GuestId = userinfo.GuestId
clurl, err := l.svcCtx.RegisterTokenManger.Generate(token)
if err != nil {

View File

@ -19,7 +19,6 @@ import (
"github.com/474420502/requests"
"github.com/zeromicro/go-zero/core/logx"
"github.com/zeromicro/go-zero/rest/httpx"
"golang.org/x/net/proxy"
"golang.org/x/oauth2"
"golang.org/x/oauth2/google"
"gorm.io/gorm"
@ -53,19 +52,6 @@ func (l *UserGoogleLoginLogic) UserGoogleLogin(req *types.RequestGoogleLogin, us
// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)
// userinfo 传入值时, 一定不为null
dialer, err := proxy.SOCKS5("tcp", "127.0.0.1:1080", nil, proxy.Direct)
if err != nil {
log.Fatal(err)
}
customClient := &http.Client{
Transport: &http.Transport{
Dial: dialer.Dial,
},
}
ctx := context.WithValue(context.Background(), oauth2.HTTPClient, customClient)
var googleOauthConfig = &oauth2.Config{
RedirectURL: fmt.Sprintf("http://%s/api/user/oauth2/login/google", l.svcCtx.Config.MainAddress),
ClientID: l.svcCtx.Config.OAuth.Google.Appid,
@ -74,15 +60,13 @@ func (l *UserGoogleLoginLogic) UserGoogleLogin(req *types.RequestGoogleLogin, us
Endpoint: google.Endpoint,
}
token, err := googleOauthConfig.Exchange(ctx, req.Code)
token, err := googleOauthConfig.Exchange(l.ctx, req.Code)
if err != nil {
logx.Error(err)
resp.SetStatus(basic.CodeApiErr)
}
ses := requests.NewSession()
ses.Config().SetProxy("socks5://127.0.0.1:1080") // 代理 为了测试功能
r, err := ses.Get("https://www.googleapis.com/oauth2/v2/userinfo?access_token=" + token.AccessToken).Execute()
if err != nil {
logx.Error(err)

View File

@ -0,0 +1,75 @@
package logic
import (
"fusenapi/utils/auth"
"fusenapi/utils/basic"
"time"
"context"
"fusenapi/server/auth/internal/svc"
"fusenapi/server/auth/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type UserRegisterLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewUserRegisterLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserRegisterLogic {
return &UserRegisterLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
// 处理进入前逻辑w,r
// func (l *UserRegisterLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) {
// }
func (l *UserRegisterLogic) UserRegister(req *types.RequestUserRegister, userinfo *auth.UserInfo) (resp *basic.Response) {
// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)
// userinfo 传入值时, 一定不为null
// 邮箱验证格式错误
if !auth.ValidateEmail(req.Email) {
return resp.SetStatus(basic.CodeOAuthEmailErr)
}
token := &auth.RegisterToken{
OperateType: auth.OpTypeRegister,
Id: 0,
GuestId: userinfo.GuestId,
Wid: req.Wid,
Email: req.Email,
Password: req.Password,
Platform: "fusen",
CreateAt: time.Now(),
}
clurl, err := l.svcCtx.RegisterTokenManger.Generate(token)
if err != nil {
logx.Error(err)
return resp.SetStatus(basic.CodeOAuthRegisterTokenErr)
}
// 进入发送邮箱的系统
EmailManager.EmailTasks <- &EmailFormat{
TargetEmail: req.Email,
CompanyName: "fusen",
ConfirmationLink: clurl,
SenderName: "support@fusenpack.com",
SenderTitle: "register-valid",
} // email进入队
return resp.SetStatus(basic.CodeOK)
}
// 处理逻辑后 w,r 如:重定向, resp 必须重新处理
// func (l *UserRegisterLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) {
// // httpx.OkJsonCtx(r.Context(), w, resp)
// }

View File

@ -47,7 +47,7 @@ func (l *UserResetTokenLogic) UserResetToken(req *types.RequestUserResetToken, u
token := &auth.ResetToken{
// 操作的类型, 验证的token 必须要继承这个
OperateType: auth.OpTypeResetToken,
UserId: uint64(userinfo.UserId),
UserId: userinfo.UserId,
Wid: req.Wid,
Email: *user.Email,
OldPassword: *user.PasswordHash,

View File

@ -14,6 +14,16 @@ type DataUserLogin struct {
Token string `json:"token"` // 登录jwt token
}
type RequestUserRegister struct {
Wid string `json:"wid"` // websocket的id
GuestId int64 `json:"guest_id"` // 游客id
FirstName string `json:"first_name"` // 首名
LastName string `json:"last_name"` // 名
Resetaurant string `json:"resetaurant"` // 餐厅类型
Email string `json:"email"` // email
Password string `json:"password"` // 密码
}
type RequestUserResetToken struct {
Wid string `json:"wid"`
}
@ -39,9 +49,8 @@ type RequestEmailConfirmation struct {
}
type RequestEmailRegister struct {
Email string `json:"email"`
Wid string `json:"wid"`
GuestId uint64 `json:"guest_id"`
Email string `json:"email"`
RegisterToken string `json:"register_token"`
}

View File

@ -76,13 +76,15 @@ func (l *UserInfoSetLogic) UserInfoSet(req *types.UserInfoSetReq, userinfo *auth
}
var nowTime = time.Now().UTC()
if userInfo.Id != 0 {
userInfo.Metadata = &req.Metadata
v := []byte(req.Metadata)
userInfo.Metadata = &v
userInfo.Utime = &nowTime
} else {
userInfo.GuestId = &guestId
userInfo.UserId = &userId
userInfo.Module = &req.Module
userInfo.Metadata = &req.Metadata
v := []byte(req.Metadata)
userInfo.Metadata = &v
userInfo.Ctime = &nowTime
}
_, err = fsUserInfoModel.CreateOrUpdate(BuilderDB, userInfo)

View File

@ -12,9 +12,9 @@ import "basic.api"
service auth {
@handler UserLoginHandler
post /api/auth/login(RequestUserLogin) returns (response);
@handler UserLoginHandler
post /api/auth/register(RequestUserLogin) returns (response);
@handler UserRegisterHandler
post /api/auth/register(RequestUserRegister) returns (response);
@handler AcceptCookieHandler
post /api/auth/accept-cookie(request) returns (response);
@ -36,6 +36,7 @@ service auth {
}
type (
// UserAddAddressHandler 用户登录请求结构
RequestUserLogin {
Email string `json:"email"`
@ -51,14 +52,20 @@ type (
type (
// UserAddAddressHandler 用户登录请求结构
RequestUserRegister {
Email string `json:"email"`
Password string `json:"password"`
Wid string `json:"wid"` // websocket的id
GuestId int64 `json:"guest_id"` // 游客id
FirstName string `json:"first_name"` // 首名
LastName string `json:"last_name"` // 名
Resetaurant string `json:"resetaurant"` // 餐厅类型
Email string `json:"email"` // email
Password string `json:"password"` // 密码
}
// UserLoginHandler 用户登录请求结构
DataUserRegister{
Token string `json:"token"` // 登录jwt token
}
// DataUserRegister{
// Token string `json:"token"` // 登录jwt token
// }
)
type (
@ -92,9 +99,8 @@ type RequestEmailConfirmation {
}
type RequestEmailRegister {
Email string `json:"email"`
Wid string `json:"wid"`
GuestId uint64 `json:"guest_id"`
Email string `json:"email"`
RegisterToken string `json:"register_token"`
}

View File

@ -15,7 +15,7 @@ import (
type RegisterToken struct {
OperateType // 操作的类型, 验证的token 必须要继承这个
Id int64 // 注册的 id google_id 或 facebook_id ...
GuestId uint64 // guest_id 需要继承
GuestId int64 // guest_id 需要继承
Wid string // websocket 通道id
Email string // email
Password string // 密码
@ -25,7 +25,7 @@ type RegisterToken struct {
type ResetToken struct {
OperateType // 操作的类型, 验证的token 必须要继承这个
UserId uint64 // guest_id 需要继承
UserId int64 // guest_id 需要继承
Wid string // websocket 通道id
Email string // email
OldPassword string // 旧密码