From 49cc50ff4e7191199736e660eb7ddd2ed685bf32 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Mon, 18 Sep 2023 15:57:36 +0800 Subject: [PATCH 01/38] fix --- .../logic/getproducttemplatetagslogic.go | 50 +++++++++---------- .../internal/types/types.go | 19 +++++-- server_api/product-template-tag.api | 17 +++++-- 3 files changed, 50 insertions(+), 36 deletions(-) diff --git a/server/product-template-tag/internal/logic/getproducttemplatetagslogic.go b/server/product-template-tag/internal/logic/getproducttemplatetagslogic.go index c0384d90..6563272a 100644 --- a/server/product-template-tag/internal/logic/getproducttemplatetagslogic.go +++ b/server/product-template-tag/internal/logic/getproducttemplatetagslogic.go @@ -54,33 +54,31 @@ func (l *GetProductTemplateTagsLogic) GetProductTemplateTags(req *types.GetProdu logx.Error(err) return } - var colors interface{} + var colors map[string][]types.ColorsItem if logoInfo.Metadata == nil || *logoInfo.Metadata == "" { - // 返回固定模板A1a - productTemplateTags, err = l.svcCtx.AllModels.FsProductTemplateTags.GetListByTagNames(l.ctx, []string{"A1"}, req.Limit, 1, "`id` DESC") - if err != nil { - logx.Error(err) - return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get template tags") - } - } else { - //解析元数据 - var metaData map[string]interface{} - if err = json.Unmarshal([]byte(*logoInfo.Metadata), &metaData); err != nil { - logx.Error(err) - return resp.SetStatusWithMessage(basic.CodeJsonErr, "failed to parse user metadata") - } - colors = metaData["colors"] - var templateTagNameList []string - b, _ := json.Marshal(metaData["template_tagid"]) - if err = json.Unmarshal(b, &templateTagNameList); err != nil { - logx.Error(err) - return resp.SetStatusWithMessage(basic.CodeJsonErr, "invalid format of metadata`s template_tagid") - } - productTemplateTags, err = l.svcCtx.AllModels.FsProductTemplateTags.GetListByTagNames(l.ctx, templateTagNameList, req.Limit, 1, "id DESC") - if err != nil { - logx.Error(err) - return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get template tags") - } + return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "logo info`s metadata is not set") + } + //解析元数据 + var metaData map[string]interface{} + if err = json.Unmarshal([]byte(*logoInfo.Metadata), &metaData); err != nil { + logx.Error(err) + return resp.SetStatusWithMessage(basic.CodeJsonErr, "failed to parse user metadata") + } + b, _ := json.Marshal(metaData["colors"]) + if err = json.Unmarshal(b, &colors); err != nil { + logx.Error(err) + return resp.SetStatusWithMessage(basic.CodeJsonErr, "invalid format of metadata`s colors") + } + var templateTagNameList []string + b, _ = json.Marshal(metaData["template_tagid"]) + if err = json.Unmarshal(b, &templateTagNameList); err != nil { + logx.Error(err) + return resp.SetStatusWithMessage(basic.CodeJsonErr, "invalid format of metadata`s template_tagid") + } + productTemplateTags, err = l.svcCtx.AllModels.FsProductTemplateTags.GetListByTagNames(l.ctx, templateTagNameList, req.Limit, 1, "id DESC") + if err != nil { + logx.Error(err) + return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get template tags") } //资源id集合 resourceIds := make([]string, 0, 5) diff --git a/server/product-template-tag/internal/types/types.go b/server/product-template-tag/internal/types/types.go index e81cb040..eeca764b 100644 --- a/server/product-template-tag/internal/types/types.go +++ b/server/product-template-tag/internal/types/types.go @@ -10,11 +10,20 @@ type GetProductTemplateTagsReq struct { } type GetProductTemplateTagsRsp struct { - Id int64 `json:"id"` - TemplateTag string `json:"template_tag"` - Cover string `json:"cover"` - CoverMetadata interface{} `json:"cover_metadata"` - Colors interface{} `json:"colors"` + Id int64 `json:"id"` + TemplateTag string `json:"template_tag"` + Cover string `json:"cover"` + CoverMetadata interface{} `json:"cover_metadata"` + Colors map[string][]ColorsItem `json:"colors"` +} + +type ColorsItem struct { + Color []ColorItem `json:"color"` +} + +type ColorItem struct { + Value string `json:"value"` + Selected bool `json:"selected"` } type Request struct { diff --git a/server_api/product-template-tag.api b/server_api/product-template-tag.api index d663e109..94d2d35e 100644 --- a/server_api/product-template-tag.api +++ b/server_api/product-template-tag.api @@ -20,9 +20,16 @@ type GetProductTemplateTagsReq { Limit int `form:"limit"` } type GetProductTemplateTagsRsp { - Id int64 `json:"id"` - TemplateTag string `json:"template_tag"` - Cover string `json:"cover"` - CoverMetadata interface{} `json:"cover_metadata"` - Colors interface{} `json:"colors"` + Id int64 `json:"id"` + TemplateTag string `json:"template_tag"` + Cover string `json:"cover"` + CoverMetadata interface{} `json:"cover_metadata"` + Colors map[string][]ColorsItem `json:"colors"` +} +type ColorsItem { + Color []ColorItem `json:"color"` +} +type ColorItem { + Value string `json:"value"` + Selected bool `json:"selected"` } \ No newline at end of file From 49785df983771f7068df30bac834e1840e3cb80f Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Mon, 18 Sep 2023 17:53:05 +0800 Subject: [PATCH 02/38] fix --- .../logic/getproducttemplatetagslogic.go | 38 +++++++++++++++---- .../internal/types/types.go | 18 ++++----- server_api/product-template-tag.api | 17 ++++----- service/repositories/image_handle.go | 16 +++++--- 4 files changed, 56 insertions(+), 33 deletions(-) diff --git a/server/product-template-tag/internal/logic/getproducttemplatetagslogic.go b/server/product-template-tag/internal/logic/getproducttemplatetagslogic.go index 6563272a..fd123c82 100644 --- a/server/product-template-tag/internal/logic/getproducttemplatetagslogic.go +++ b/server/product-template-tag/internal/logic/getproducttemplatetagslogic.go @@ -36,6 +36,16 @@ func NewGetProductTemplateTagsLogic(ctx context.Context, svcCtx *svc.ServiceCont // func (l *GetProductTemplateTagsLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) { // // httpx.OkJsonCtx(r.Context(), w, resp) // } +type logoSelect struct { + LogoSelected struct { + LogoSelectedId int `json:"logo_selected_id"` + TemplateTagSelected struct { + TemplateTag string `json:"template_tag"` + Color [][]string `json:"color"` + SelectedIndex int `json:"selected_index"` + } `json:"template_tag_selected"` + } `json:"logo_selected"` +} func (l *GetProductTemplateTagsLogic) GetProductTemplateTags(req *types.GetProductTemplateTagsReq, userinfo *auth.UserInfo) (resp *basic.Response) { if req.Limit <= 0 || req.Limit > 100 { @@ -54,7 +64,6 @@ func (l *GetProductTemplateTagsLogic) GetProductTemplateTags(req *types.GetProdu logx.Error(err) return } - var colors map[string][]types.ColorsItem if logoInfo.Metadata == nil || *logoInfo.Metadata == "" { return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "logo info`s metadata is not set") } @@ -64,16 +73,29 @@ func (l *GetProductTemplateTagsLogic) GetProductTemplateTags(req *types.GetProdu logx.Error(err) return resp.SetStatusWithMessage(basic.CodeJsonErr, "failed to parse user metadata") } - b, _ := json.Marshal(metaData["colors"]) - if err = json.Unmarshal(b, &colors); err != nil { + var mapTemplateTag map[string][]types.ColorsItem + b, _ := json.Marshal(metaData["template_tag"]) + if err = json.Unmarshal(b, &mapTemplateTag); err != nil { logx.Error(err) return resp.SetStatusWithMessage(basic.CodeJsonErr, "invalid format of metadata`s colors") } + //获取选中的颜色数据 + if logoInfo.UserInfoMetadata != nil && *logoInfo.UserInfoMetadata != "" { + var logoSelectInfo logoSelect + if err = json.Unmarshal([]byte(*logoInfo.UserInfoMetadata), &logoSelectInfo); err != nil { + logx.Error(err) + return resp.SetStatusWithMessage(basic.CodeJsonErr, "failed to parse user info metadata") + } + //设置选中 + key := logoSelectInfo.LogoSelected.TemplateTagSelected.TemplateTag + index := logoSelectInfo.LogoSelected.TemplateTagSelected.SelectedIndex + if _, ok := mapTemplateTag[key]; ok { + mapTemplateTag[key][index].Selected = true + } + } var templateTagNameList []string - b, _ = json.Marshal(metaData["template_tagid"]) - if err = json.Unmarshal(b, &templateTagNameList); err != nil { - logx.Error(err) - return resp.SetStatusWithMessage(basic.CodeJsonErr, "invalid format of metadata`s template_tagid") + for templateTag, _ := range mapTemplateTag { + templateTagNameList = append(templateTagNameList, templateTag) } productTemplateTags, err = l.svcCtx.AllModels.FsProductTemplateTags.GetListByTagNames(l.ctx, templateTagNameList, req.Limit, 1, "id DESC") if err != nil { @@ -101,6 +123,8 @@ func (l *GetProductTemplateTagsLogic) GetProductTemplateTags(req *types.GetProdu } list := make([]types.GetProductTemplateTagsRsp, 0, len(productTemplateTags)) for _, v := range productTemplateTags { + colors := make([]types.ColorsItem, 0, 10) + colors = append(colors, mapTemplateTag[*v.TemplateTag]...) list = append(list, types.GetProductTemplateTagsRsp{ Id: v.Id, TemplateTag: *v.TemplateTag, diff --git a/server/product-template-tag/internal/types/types.go b/server/product-template-tag/internal/types/types.go index eeca764b..574a34c6 100644 --- a/server/product-template-tag/internal/types/types.go +++ b/server/product-template-tag/internal/types/types.go @@ -10,20 +10,16 @@ type GetProductTemplateTagsReq struct { } type GetProductTemplateTagsRsp struct { - Id int64 `json:"id"` - TemplateTag string `json:"template_tag"` - Cover string `json:"cover"` - CoverMetadata interface{} `json:"cover_metadata"` - Colors map[string][]ColorsItem `json:"colors"` + Id int64 `json:"id"` + TemplateTag string `json:"template_tag"` + Cover string `json:"cover"` + CoverMetadata interface{} `json:"cover_metadata"` + Colors []ColorsItem `json:"colors"` } type ColorsItem struct { - Color []ColorItem `json:"color"` -} - -type ColorItem struct { - Value string `json:"value"` - Selected bool `json:"selected"` + Color []string `json:"color"` + Selected bool `json:"selected"` } type Request struct { diff --git a/server_api/product-template-tag.api b/server_api/product-template-tag.api index 94d2d35e..30329047 100644 --- a/server_api/product-template-tag.api +++ b/server_api/product-template-tag.api @@ -20,16 +20,13 @@ type GetProductTemplateTagsReq { Limit int `form:"limit"` } type GetProductTemplateTagsRsp { - Id int64 `json:"id"` - TemplateTag string `json:"template_tag"` - Cover string `json:"cover"` - CoverMetadata interface{} `json:"cover_metadata"` - Colors map[string][]ColorsItem `json:"colors"` + Id int64 `json:"id"` + TemplateTag string `json:"template_tag"` + Cover string `json:"cover"` + CoverMetadata interface{} `json:"cover_metadata"` + Colors []ColorsItem `json:"colors"` } type ColorsItem { - Color []ColorItem `json:"color"` -} -type ColorItem { - Value string `json:"value"` - Selected bool `json:"selected"` + Color []string `json:"color"` + Selected bool `json:"selected"` } \ No newline at end of file diff --git a/service/repositories/image_handle.go b/service/repositories/image_handle.go index a18c70de..c47f600d 100644 --- a/service/repositories/image_handle.go +++ b/service/repositories/image_handle.go @@ -54,15 +54,16 @@ type ( GuestId int64 `json:"guest_id"` } LogoInfoRes struct { - Metadata *string `json:"metadata"` - LogoUrl *string `json:"logo_url"` + Metadata *string `json:"metadata"` + LogoUrl *string `json:"logo_url"` + UserInfoMetadata *string `json:"user_info_metadata"` } ) func (l *defaultImageHandle) LogoInfo(ctx context.Context, in *LogoInfoReq) (*LogoInfoRes, error) { var metadata *string var logoUrl *string - + var userInfoMetadata *string // 更新用户信息 var module = "profile" userInfoGorm := l.MysqlConn.Where("module = ?", module) @@ -82,6 +83,10 @@ func (l *defaultImageHandle) LogoInfo(ctx context.Context, in *LogoInfoReq) (*Lo return nil, err } } + if userInfo.Id != 0 { + tmp := string(*userInfo.Metadata) + userInfoMetadata = &tmp + } var userMaterialInfo gmodel.FsUserMaterial userMaterialModel := gmodel.NewFsUserMaterialModel(l.MysqlConn) @@ -134,8 +139,9 @@ func (l *defaultImageHandle) LogoInfo(ctx context.Context, in *LogoInfoReq) (*Lo logoUrl = userMaterialInfo.ResourceUrl } return &LogoInfoRes{ - Metadata: metadata, - LogoUrl: logoUrl, + Metadata: metadata, + LogoUrl: logoUrl, + UserInfoMetadata: userInfoMetadata, }, nil } From c12c24d03bf7afae4d4e5ade8b1e97f3c8a37791 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Mon, 18 Sep 2023 18:18:30 +0800 Subject: [PATCH 03/38] fix --- .../logic/getproducttemplatetagslogic.go | 32 +++++++++++++------ 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/server/product-template-tag/internal/logic/getproducttemplatetagslogic.go b/server/product-template-tag/internal/logic/getproducttemplatetagslogic.go index fd123c82..c76f2048 100644 --- a/server/product-template-tag/internal/logic/getproducttemplatetagslogic.go +++ b/server/product-template-tag/internal/logic/getproducttemplatetagslogic.go @@ -48,6 +48,7 @@ type logoSelect struct { } func (l *GetProductTemplateTagsLogic) GetProductTemplateTags(req *types.GetProductTemplateTagsReq, userinfo *auth.UserInfo) (resp *basic.Response) { + userinfo.UserId = 127 if req.Limit <= 0 || req.Limit > 100 { req.Limit = 5 } @@ -73,13 +74,14 @@ func (l *GetProductTemplateTagsLogic) GetProductTemplateTags(req *types.GetProdu logx.Error(err) return resp.SetStatusWithMessage(basic.CodeJsonErr, "failed to parse user metadata") } - var mapTemplateTag map[string][]types.ColorsItem + var mapTemplateTag map[string][][]string b, _ := json.Marshal(metaData["template_tag"]) if err = json.Unmarshal(b, &mapTemplateTag); err != nil { logx.Error(err) - return resp.SetStatusWithMessage(basic.CodeJsonErr, "invalid format of metadata`s colors") + return resp.SetStatusWithMessage(basic.CodeJsonErr, "invalid format of metadata`s template_tag") } //获取选中的颜色数据 + mapSelectColor := make(map[string]int) //key是模板标签val是选中的索引 if logoInfo.UserInfoMetadata != nil && *logoInfo.UserInfoMetadata != "" { var logoSelectInfo logoSelect if err = json.Unmarshal([]byte(*logoInfo.UserInfoMetadata), &logoSelectInfo); err != nil { @@ -88,9 +90,8 @@ func (l *GetProductTemplateTagsLogic) GetProductTemplateTags(req *types.GetProdu } //设置选中 key := logoSelectInfo.LogoSelected.TemplateTagSelected.TemplateTag - index := logoSelectInfo.LogoSelected.TemplateTagSelected.SelectedIndex if _, ok := mapTemplateTag[key]; ok { - mapTemplateTag[key][index].Selected = true + mapSelectColor[key] = logoSelectInfo.LogoSelected.TemplateTagSelected.SelectedIndex } } var templateTagNameList []string @@ -122,14 +123,25 @@ func (l *GetProductTemplateTagsLogic) GetProductTemplateTags(req *types.GetProdu mapResourceMetadata[*v.ResourceUrl] = metadata } list := make([]types.GetProductTemplateTagsRsp, 0, len(productTemplateTags)) - for _, v := range productTemplateTags { + for _, templateInfo := range productTemplateTags { colors := make([]types.ColorsItem, 0, 10) - colors = append(colors, mapTemplateTag[*v.TemplateTag]...) + for index, v := range mapTemplateTag[*templateInfo.TemplateTag] { + selected := false + if selectIndex, ok := mapSelectColor[*templateInfo.TemplateTag]; ok { + if index == selectIndex { + selected = true + } + } + colors = append(colors, types.ColorsItem{ + Color: v, + Selected: selected, + }) + } list = append(list, types.GetProductTemplateTagsRsp{ - Id: v.Id, - TemplateTag: *v.TemplateTag, - Cover: *v.Cover, - CoverMetadata: mapResourceMetadata[*v.Cover], + Id: templateInfo.Id, + TemplateTag: *templateInfo.TemplateTag, + Cover: *templateInfo.Cover, + CoverMetadata: mapResourceMetadata[*templateInfo.Cover], Colors: colors, }) } From beaba9afa9d43d28bb07957502855bc4c84c66f9 Mon Sep 17 00:00:00 2001 From: eson <9673575+githubcontent@user.noreply.gitee.com> Date: Mon, 18 Sep 2023 18:44:12 +0800 Subject: [PATCH 04/38] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20config=20=E6=9C=80?= =?UTF-8?q?=E6=96=B0=E9=85=8D=E7=BD=AE=E6=9C=8D=E5=8A=A1=E4=B8=8A=E5=8E=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 4 +- fs_nacos_etc_pack.sh | 25 +++++++ go.mod | 14 ++++ go.sum | 32 +++++++++ server/auth/internal/logic/websocket_test.go | 2 +- utils/fsconfig/.gitignore | 1 + utils/fsconfig/config.go | 53 +++++++++++++++ utils/fsconfig/config_test.go | 70 ++++++++++++++++++++ 8 files changed, 199 insertions(+), 2 deletions(-) create mode 100755 fs_nacos_etc_pack.sh create mode 100644 utils/fsconfig/.gitignore create mode 100644 utils/fsconfig/config.go create mode 100644 utils/fsconfig/config_test.go diff --git a/.gitignore b/.gitignore index d89fb0f1..2f86e838 100644 --- a/.gitignore +++ b/.gitignore @@ -54,4 +54,6 @@ server/shopping-cart-confirmation/shopping-cart-confirmation server/upload/upload server/webset/webset -shared-state \ No newline at end of file +shared-state + +*.zip \ No newline at end of file diff --git a/fs_nacos_etc_pack.sh b/fs_nacos_etc_pack.sh new file mode 100755 index 00000000..6e8d6fcf --- /dev/null +++ b/fs_nacos_etc_pack.sh @@ -0,0 +1,25 @@ +#!/bin/bash + +CURRENT_DIR=`pwd` +SOURCE_DIR="server" +TEMP_DIR="/tmp" +DEST_DIR="FS-SERVER-API" +ZIP_FILE="FS-SERVER-API.zip" + +mkdir -p $TEMP_DIR/$DEST_DIR + +# 查找并复制文件 +find "$SOURCE_DIR" -type d -name "etc" -exec sh -c 'cp "$0"/*.yaml "$1"' {} "$TEMP_DIR/$DEST_DIR" \; + +cd $TEMP_DIR +# 打包目标文件夹 +zip -r "$ZIP_FILE" "$DEST_DIR" + +#返回当前目录 +cd $CURRENT_DIR + +# 移动到当前目录 +mv "$TEMP_DIR/$ZIP_FILE" . + +# 清理临时文件夹 +rm "$TEMP_DIR/$DEST_DIR" -rf \ No newline at end of file diff --git a/go.mod b/go.mod index 01c94f65..8bf4cb92 100644 --- a/go.mod +++ b/go.mod @@ -14,6 +14,7 @@ require ( github.com/gorilla/websocket v1.5.0 github.com/hashicorp/raft v1.5.0 github.com/lni/dragonboat/v4 v4.0.0-20230709075559-54497b9553be + github.com/nacos-group/nacos-sdk-go/v2 v2.2.3 github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e github.com/streadway/amqp v1.1.0 @@ -31,14 +32,17 @@ require ( github.com/DataDog/zstd v1.4.5 // indirect github.com/HdrHistogram/hdrhistogram-go v1.1.2 // indirect github.com/VictoriaMetrics/metrics v1.18.1 // indirect + github.com/aliyun/alibaba-cloud-sdk-go v1.61.1704 // indirect github.com/andybalholm/brotli v1.0.5 // indirect github.com/armon/go-metrics v0.4.1 // indirect + github.com/buger/jsonparser v1.1.1 // indirect github.com/cockroachdb/errors v1.9.0 // indirect github.com/cockroachdb/logtags v0.0.0-20211118104740-dabe8e521a4f // indirect github.com/cockroachdb/pebble v0.0.0-20221207173255-0f086d933dac // indirect github.com/cockroachdb/redact v1.1.3 // indirect github.com/getsentry/sentry-go v0.12.0 // indirect github.com/gogo/protobuf v1.3.2 // indirect + github.com/golang/mock v1.6.0 // indirect github.com/golang/snappy v0.0.4 // indirect github.com/google/btree v1.0.0 // indirect github.com/hashicorp/errwrap v1.1.0 // indirect @@ -50,12 +54,15 @@ require ( github.com/hashicorp/golang-lru v0.5.1 // indirect github.com/hashicorp/memberlist v0.3.1 // indirect github.com/jmespath/go-jmespath v0.4.0 // indirect + github.com/json-iterator/go v1.1.12 // indirect github.com/klauspost/compress v1.15.15 // indirect github.com/kr/pretty v0.3.1 // indirect github.com/kr/text v0.2.0 // indirect github.com/lni/goutils v1.3.1-0.20220604063047-388d67b4dbc4 // indirect github.com/lni/vfs v0.2.1-0.20220616104132-8852fd867376 // indirect github.com/miekg/dns v1.1.26 // indirect + github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect + github.com/modern-go/reflect2 v1.0.2 // indirect github.com/pierrec/lz4/v4 v4.1.17 // indirect github.com/pkg/errors v0.9.1 // indirect github.com/rogpeppe/go-internal v1.9.0 // indirect @@ -64,11 +71,18 @@ require ( github.com/valyala/fastrand v1.1.0 // indirect github.com/valyala/histogram v1.2.0 // indirect go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.14.0 // indirect + go.uber.org/atomic v1.10.0 // indirect + go.uber.org/multierr v1.9.0 // indirect + go.uber.org/zap v1.24.0 // indirect golang.org/x/crypto v0.11.0 // indirect golang.org/x/exp v0.0.0-20230728194245-b0cb94b80691 // indirect + golang.org/x/sync v0.2.0 // indirect + golang.org/x/time v0.3.0 // indirect 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 + gopkg.in/ini.v1 v1.66.2 // indirect + gopkg.in/natefinch/lumberjack.v2 v2.0.0 // indirect ) require ( diff --git a/go.sum b/go.sum index 67d9f1b0..06dd5c40 100644 --- a/go.sum +++ b/go.sum @@ -41,6 +41,7 @@ github.com/474420502/random v0.4.1 h1:HUUyLXRWMijVb7CJoEC16f0aFQOW25Lkr80Mut6PoK github.com/474420502/requests v1.42.0 h1:aUj0rWhfldbOOlGHDIcqT9zgXEoSlK4IBmRF3LxI1+Y= github.com/474420502/requests v1.42.0/go.mod h1:2SCVzim0ONFYG09g/GrM7RTeJIC6qTyZfnohsjnG5C8= github.com/AndreasBriese/bbloom v0.0.0-20190306092124-e2d15f34fcf9/go.mod h1:bOvUY6CB00SOBii9/FifXqc0awNKxLFCL/+pkDPuyl8= +github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= github.com/CloudyKit/fastprinter v0.0.0-20170127035650-74b38d55f37a/go.mod h1:EFZQ978U7x8IRnstaskI3IysnWY5Ao3QgZUKOXlsAdw= @@ -69,6 +70,8 @@ github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRF github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= github.com/alicebob/gopher-json v0.0.0-20200520072559-a9ecdc9d1d3a h1:HbKu58rmZpUGpz5+4FfNmIU+FmZg2P3Xaj2v2bfNWmk= github.com/alicebob/miniredis/v2 v2.30.4 h1:8S4/o1/KoUArAGbGwPxcwf0krlzceva2XVOSchFS7Eo= +github.com/aliyun/alibaba-cloud-sdk-go v1.61.1704 h1:PpfENOj/vPfhhy9N2OFRjpue0hjM5XqAp2thFmkXXIk= +github.com/aliyun/alibaba-cloud-sdk-go v1.61.1704/go.mod h1:RcDobYh8k5VP6TNybz9m++gL3ijVI5wueVr0EM10VsU= github.com/andybalholm/brotli v1.0.5 h1:8uQZIdzKmjc/iuPu7O2ioW48L81FgatrcpfFmiq/cCs= github.com/andybalholm/brotli v1.0.5/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig= github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY= @@ -79,10 +82,13 @@ github.com/armon/go-metrics v0.4.1/go.mod h1:E6amYzXo6aW1tqzoZGT755KkbgrJsSdpwZ+ github.com/aws/aws-sdk-go v1.44.295 h1:SGjU1+MqttXfRiWHD6WU0DRhaanJgAFY+xIhEaugV8Y= github.com/aws/aws-sdk-go v1.44.295/go.mod h1:aVsgQcEevwlmQ7qHE9I3h+dtQgpqhFB+i8Phjh7fkwI= github.com/aymerick/raymond v2.0.3-0.20180322193309-b565731e1464+incompatible/go.mod h1:osfaiScAUVup+UC9Nfq76eWqDhXlp+4UYaA8uhTBO6g= +github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8= github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= +github.com/buger/jsonparser v1.1.1 h1:2PnMjfWD7wBILjqQbt530v576A/cAbQvEW9gGIpYMUs= +github.com/buger/jsonparser v1.1.1/go.mod h1:6RYKKt7H4d4+iWqouImQ9R2FZql3VbhNgx27UK13J/0= github.com/bwmarrin/snowflake v0.3.0 h1:xm67bEhkKh6ij1790JB83OujPR5CzNe8QuQqAgISZN0= github.com/bwmarrin/snowflake v0.3.0/go.mod h1:NdZxfVWX+oR6y2K0o6qAYv6gIOP9rjG0/E9WsDpxqwE= github.com/cenkalti/backoff/v4 v4.2.0 h1:HN5dHm3WBOgndBH6E8V0q2jIYIR3s9yglV8k/+MN3u4= @@ -202,6 +208,7 @@ github.com/gogo/protobuf v1.3.1/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXP github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= github.com/gogo/status v1.1.0/go.mod h1:BFv9nrluPLmrS0EmGVvLaPNmRosr9KapBYd5/hpY1WM= +github.com/goji/httpauth v0.0.0-20160601135302-2da839ab0f4d/go.mod h1:nnjvkQ9ptGaCkuDUx6wNykzzlUixGxvkme+H/lnzb+A= github.com/golang-jwt/jwt v3.2.2+incompatible h1:IfV12K8xAKAnZqdXVzCZ+TOjboZ2keLg81eXfW3O+oY= github.com/golang-jwt/jwt v3.2.2+incompatible/go.mod h1:8pz2t5EyA70fFQQSrl6XZXzqecmYZeUEB8OUGHkxJ+I= github.com/golang-jwt/jwt/v4 v4.5.0 h1:7cYmW1XlMY7h7ii7UhUyChSgS5wUJEnm9uZVTGqOWzg= @@ -220,6 +227,8 @@ github.com/golang/mock v1.4.0/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt github.com/golang/mock v1.4.1/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw= github.com/golang/mock v1.4.3/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw= github.com/golang/mock v1.4.4/go.mod h1:l3mdAwkq5BuhzHwde/uurv3sEJeZMXNpwsxVWU71h+4= +github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc= +github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= @@ -330,12 +339,16 @@ github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc= github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ= github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8= +github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k= github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9YPoQUg= github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo= github.com/jmespath/go-jmespath/internal/testify v1.5.1 h1:shLQSRRSCCPj3f2gpwzGwWFoC7ycTf1rcQZHOlsJ6N8= github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U= +github.com/json-iterator/go v1.1.5/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= +github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM= +github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU= github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk= github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= @@ -413,11 +426,16 @@ github.com/miekg/dns v1.1.26/go.mod h1:bPDLeHnStXmXAq1m/Ch/hvfNHr14JKNPMBo3VZKju github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= +github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg= github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= +github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M= +github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= github.com/moul/http2curl v1.0.0/go.mod h1:8UbvGypXm98wA/IqH45anm5Y2Z6ep6O31QGOAZ3H0fQ= github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= +github.com/nacos-group/nacos-sdk-go/v2 v2.2.3 h1:sUQx4f1bXDeeOOEQZjGAitzxYApbYY9fVDbxVCaBW+I= +github.com/nacos-group/nacos-sdk-go/v2 v2.2.3/go.mod h1:UL4U89WYdnyajgKJUMpuT1Rr6iNmbjrxOO40JRgtA00= github.com/nats-io/jwt v0.3.0/go.mod h1:fRYCDE99xlTsqUzISS1Bi75UBJ6ljOJQOAAu5VglpSg= github.com/nats-io/nats.go v1.8.1/go.mod h1:BrFz9vVn0fU3AcH9Vn4Kd7W0NpJ651tD5omQ3M8LwxM= github.com/nats-io/nats.go v1.9.1/go.mod h1:ZjDU1L/7fJ09jvUSRVBR2e7+RnLiiIQyqyzEE/Zbp4w= @@ -598,9 +616,15 @@ go.opentelemetry.io/otel/trace v1.14.0/go.mod h1:8avnQLK+CG77yNLUae4ea2JDQ6iT+go go.opentelemetry.io/proto/otlp v0.7.0/go.mod h1:PqfVotwruBrMGOCsRd/89rSnXhoiJIqeYNgFYFoEGnI= go.opentelemetry.io/proto/otlp v0.19.0 h1:IVN6GR+mhC4s5yfcTbmzHYODqvWAp3ZedA2SJPI1Nnw= go.opentelemetry.io/proto/otlp v0.19.0/go.mod h1:H7XAot3MsfNsj7EXtrA2q5xSNQ10UqI405h3+duxN4U= +go.uber.org/atomic v1.10.0 h1:9qC72Qh0+3MqyJbAn8YU5xVq1frD8bn3JtD2oXtafVQ= +go.uber.org/atomic v1.10.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0= go.uber.org/automaxprocs v1.5.2 h1:2LxUOGiR3O6tw8ui5sZa2LAaHnsviZdVOUZw4fvbnME= go.uber.org/automaxprocs v1.5.2/go.mod h1:eRbA25aqJrxAbsLO0xy5jVwPt7FQnRgjW+efnwa1WM0= go.uber.org/goleak v1.2.1 h1:NBol2c7O1ZokfZ0LEU9K6Whx/KnwvepVetCUhtKja4A= +go.uber.org/multierr v1.9.0 h1:7fIwc/ZtS0q++VgcfqFDxSBZVv/Xo49/SYnDFupUwlI= +go.uber.org/multierr v1.9.0/go.mod h1:X2jQV1h+kxSjClGpnseKVIxpmcjrj7MNnI0bnlfKTVQ= +go.uber.org/zap v1.24.0 h1:FiJd5l1UOLj0wCgbSE0rwwXHzEdAZS6hiiSnxJN/D60= +go.uber.org/zap v1.24.0/go.mod h1:2kMP+WWQ8aoFoedH3T2sq6iJ2yDWpHbP0f6MQbS9Gkg= golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= @@ -721,6 +745,7 @@ golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.2.0 h1:PUR+T4wwASmuSTYdKjYHI5TD22Wy5ogLU5qZCOLxBrI= +golang.org/x/sync v0.2.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -798,6 +823,8 @@ golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxb golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20201208040808-7e3f01d25324/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= +golang.org/x/time v0.3.0 h1:rg5rLMjNzMS1RkNLzCG38eapWhnYLFYXDXj2gOlr8j4= +golang.org/x/time v0.3.0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/tools v0.0.0-20180525024113-a5b4c53f6e8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20181030221726-6c7e314b6563/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= @@ -847,6 +874,7 @@ golang.org/x/tools v0.0.0-20200729194436-6467de6f59a7/go.mod h1:njjCfa9FT2d7l9Bc golang.org/x/tools v0.0.0-20200804011535-6c149bb5ef0d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= golang.org/x/tools v0.0.0-20200825202427-b303f430e36d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= +golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.3/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= @@ -969,7 +997,11 @@ gopkg.in/go-playground/assert.v1 v1.2.1/go.mod h1:9RXL0bg/zibRAgZUYszZSwO/z8Y/a8 gopkg.in/go-playground/validator.v8 v8.18.2/go.mod h1:RX2a/7Ha8BgOhfk7j780h4/u/RRjR0eouCJSH80/M2Y= gopkg.in/h2non/gock.v1 v1.1.2 h1:jBbHXgGBK/AoPVfJh5x4r/WxIrElvbLel8TCZkkZJoY= gopkg.in/ini.v1 v1.51.1/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= +gopkg.in/ini.v1 v1.66.2 h1:XfR1dOYubytKy4Shzc2LHrrGhU0lDCfDGG1yLPmpgsI= +gopkg.in/ini.v1 v1.66.2/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= gopkg.in/mgo.v2 v2.0.0-20180705113604-9856a29383ce/go.mod h1:yeKp02qBN3iKW1OzL3MGk2IdtZzaj7SFntXj72NppTA= +gopkg.in/natefinch/lumberjack.v2 v2.0.0 h1:1Lc07Kr7qY4U2YPouBjpCLxpiyxIVoxqXgkXLknAOE8= +gopkg.in/natefinch/lumberjack.v2 v2.0.0/go.mod h1:l0ndWWf7gzL7RNwBG7wST/UCcT4T24xpD6X8LsfU/+k= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= diff --git a/server/auth/internal/logic/websocket_test.go b/server/auth/internal/logic/websocket_test.go index c74a5736..17f6ba2a 100644 --- a/server/auth/internal/logic/websocket_test.go +++ b/server/auth/internal/logic/websocket_test.go @@ -143,7 +143,7 @@ func TestSql(t *testing.T) { } conn := initalize.InitMysql("fsreaderwriter:XErSYmLELKMnf3Dh@tcp(fusen.cdmigcvz3rle.us-east-2.rds.amazonaws.com:3306)/fusen") - log.Println(conn.Model(&gmodel.FsUser{})) + log.Println() log.Println(conn.NamingStrategy.TableName(reflect.TypeOf(gmodel.FsUser{}).Name())) updatesql := `UPDATE %s diff --git a/utils/fsconfig/.gitignore b/utils/fsconfig/.gitignore new file mode 100644 index 00000000..fbf828d6 --- /dev/null +++ b/utils/fsconfig/.gitignore @@ -0,0 +1 @@ +log \ No newline at end of file diff --git a/utils/fsconfig/config.go b/utils/fsconfig/config.go new file mode 100644 index 00000000..116043dc --- /dev/null +++ b/utils/fsconfig/config.go @@ -0,0 +1,53 @@ +package fsconfig + +import ( + "fmt" + "log" + "os" + + "gopkg.in/yaml.v2" +) + +type EnvConfig struct { + Host string `yaml:"host"` + Port uint64 `yaml:"port"` + + UserName string `yaml:"username"` + Password string `yaml:"password"` + NamespaceId string `yaml:"namespace"` + DataId string `yaml:"dataid"` + Group string `yaml:"group"` +} + +var OptPathDir = "/opt" + +var nacosConfig *EnvConfig + +func GetEnvCofing() *EnvConfig { + return nacosConfig +} + +func init() { + if OptPathDir[len(OptPathDir)-1] != '/' { + OptPathDir = OptPathDir + "/" + } + + for _, yname := range []string{"env.yaml", "env.yml"} { + f, err := os.Open(OptPathDir + "/" + yname) + if err != nil { + log.Println(err) + continue + } + cfg := &EnvConfig{} + err = yaml.NewDecoder(f).Decode(&cfg) + if err != nil { + log.Println(err) + continue + } + + nacosConfig = cfg + return + } + + panic(fmt.Sprintf("can't find %s(env.yaml|env.yml) ", OptPathDir)) +} diff --git a/utils/fsconfig/config_test.go b/utils/fsconfig/config_test.go new file mode 100644 index 00000000..f285c6bb --- /dev/null +++ b/utils/fsconfig/config_test.go @@ -0,0 +1,70 @@ +package fsconfig_test + +import ( + "fusenapi/utils/fsconfig" + "log" + "testing" + + "github.com/nacos-group/nacos-sdk-go/v2/clients" + "github.com/nacos-group/nacos-sdk-go/v2/common/constant" + "github.com/nacos-group/nacos-sdk-go/v2/vo" +) + +func TestCase1(t *testing.T) { + + env := fsconfig.GetEnvCofing() + + // 创建serverConfig + // 支持多个;至少一个ServerConfig + serverConfig := []constant.ServerConfig{ + { + IpAddr: env.Host, + Port: uint64(env.Port), + }, + } + + // 创建clientConfig + clientConfig := constant.ClientConfig{ + NamespaceId: env.NamespaceId, // 如果需要支持多namespace,我们可以场景多个client,它们有不同的NamespaceId。当namespace是public时,此处填空字符串。 + TimeoutMs: 50000, + NotLoadCacheAtStart: true, + LogLevel: "debug", + LogDir: "/tmp/nacos", + CacheDir: "/tmp/nacos", + Username: env.UserName, + Password: env.Password, + } + + // 创建服务发现客户端的另一种方式 (推荐) + // namingClient, err := clients.NewNamingClient( + // vo.NacosClientParam{ + // ClientConfig: &clientConfig, + // ServerConfigs: serverConfig, + // }, + // ) + // if err != nil { + // log.Fatalf("初始化nacos失败: %s", err.Error()) + // } + + // log.Println(namingClient) + + // 创建 Nacos 配置客户端 + configClient, err := clients.CreateConfigClient(map[string]interface{}{ + "clientConfig": clientConfig, + "serverConfigs": serverConfig, + }) + if err != nil { + log.Fatalf("Failed to create Nacos config client: %v", err) + } + + // 获取配置 + content, err := configClient.GetConfig(vo.ConfigParam{ + DataId: "auth.yaml", + Group: env.Group, + }) + if err != nil { + log.Fatalf("Failed to get config from Nacos: %v", err) + } + log.Println(content) + +} From f82f8b0d24dfb0ed64d39cd84e2098ecab36ee8c Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Mon, 18 Sep 2023 18:46:18 +0800 Subject: [PATCH 05/38] fix --- .../internal/logic/ws_render_image.go | 7 ++++- utils/websocket_data/render_data.go | 27 +++++++++++-------- 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/server/websocket/internal/logic/ws_render_image.go b/server/websocket/internal/logic/ws_render_image.go index 3b1f6c28..39bb7fbf 100644 --- a/server/websocket/internal/logic/ws_render_image.go +++ b/server/websocket/internal/logic/ws_render_image.go @@ -96,10 +96,15 @@ func (w *wsConnectItem) renderImage(data []byte) { //logx.Info("消费渲染数据:", string(data)) var renderImageData websocket_data.RenderImageReqMsg if err := json.Unmarshal(data, &renderImageData); err != nil { - w.incomeDataFormatErrResponse("invalid format of render data:" + string(data)) + w.renderErrResponse("", "", "", "数据格式错误", 0, 0, 0, 0, 0, 0, 0) logx.Error("invalid format of websocket render image message", err) return } + lenColor := len(renderImageData.RenderData.TemplateTagColor.Color) + if renderImageData.RenderData.TemplateTagColor.SelectedIndex >= lenColor || lenColor == 0 { + w.renderErrResponse("", "", "", "请传入模板标签选择的颜色", 0, 0, 0, 0, 0, 0, 0) + return + } //获取产品信息(部分字段) productInfo, err := w.logic.svcCtx.AllModels.FsProduct.FindOne(w.logic.ctx, renderImageData.RenderData.ProductId, "id,is_customization") if err != nil { diff --git a/utils/websocket_data/render_data.go b/utils/websocket_data/render_data.go index 16f3326b..d79032d5 100644 --- a/utils/websocket_data/render_data.go +++ b/utils/websocket_data/render_data.go @@ -15,17 +15,22 @@ type RenderImageReqMsg struct { RenderData RenderData `json:"render_data"` } type RenderData struct { - TemplateTag string `json:"template_tag"` //模板标签(必须) - ProductId int64 `json:"product_id"` //产品id(必须) - Website string `json:"website"` //网站(可选) - Slogan string `json:"slogan"` //slogan(可选) - Address string `json:"address"` //地址(可选) - Phone string `json:"phone"` //电话(可选) - Qrcode string `json:"qrcode"` //二维码(可选) - ProductSizeId int64 `json:"product_size_id"` //尺寸id(可选) - UserId int64 `json:"user_id"` //用户id(websocket连接建立再赋值) - GuestId int64 `json:"guest_id"` //游客id(websocket连接建立再赋值) - Logo string `json:"logo"` //log资源地址(websocket连接建立再赋值) + TemplateTag string `json:"template_tag"` //模板标签(必须) + TemplateTagColor TemplateTagColor `json:"template_tag_color"` //模板标签组合颜色 + ProductId int64 `json:"product_id"` //产品id(必须) + Website string `json:"website"` //网站(可选) + Slogan string `json:"slogan"` //slogan(可选) + Address string `json:"address"` //地址(可选) + Phone string `json:"phone"` //电话(可选) + Qrcode string `json:"qrcode"` //二维码(可选) + ProductSizeId int64 `json:"product_size_id"` //尺寸id(可选) + UserId int64 `json:"user_id"` //用户id(websocket连接建立再赋值) + GuestId int64 `json:"guest_id"` //游客id(websocket连接建立再赋值) + Logo string `json:"logo"` //log资源地址(websocket连接建立再赋值) +} +type TemplateTagColor struct { + Color [][]string `json:"color"` //颜色组合 + SelectedIndex int `json:"selected_index"` //主色的下标索引 } // websocket发送渲染完的数据 From 573a199878ce839951e9ca577d6f00d4b413ba17 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Mon, 18 Sep 2023 18:57:37 +0800 Subject: [PATCH 06/38] fix --- service/repositories/image_handle.go | 29 ++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/service/repositories/image_handle.go b/service/repositories/image_handle.go index c47f600d..fa71fbd4 100644 --- a/service/repositories/image_handle.go +++ b/service/repositories/image_handle.go @@ -187,16 +187,17 @@ func (l *defaultImageHandle) LogoInfoSet(ctx context.Context, in *LogoInfoSetReq /* logo合图 */ type ( LogoCombineReq struct { - UserId int64 `json:"user_id"` - GuestId int64 `json:"guest_id"` - TemplateId int64 `json:"template_id"` - TemplateTag string `json:"template_tag"` - Website string `json:"website"` // 合图参数 - Slogan string `json:"slogan"` // 合图参数 - Address string `json:"address"` // 合图参数 - Phone string `json:"phone"` // 合图参数 - Qrcode string `json:"qrcode"` // 合图参数 - LogoUrl string `json:"logo_url"` // 合图参数 + UserId int64 `json:"user_id"` + GuestId int64 `json:"guest_id"` + TemplateId int64 `json:"template_id"` + TemplateTag string `json:"template_tag"` + Website string `json:"website"` // 合图参数 + Slogan string `json:"slogan"` // 合图参数 + Address string `json:"address"` // 合图参数 + Phone string `json:"phone"` // 合图参数 + Qrcode string `json:"qrcode"` // 合图参数 + LogoUrl string `json:"logo_url"` // 合图参数 + TemplateTagColor TemplateTagColor `json:"template_tag_color"` } LogoCombineRes struct { ResourceId string @@ -206,6 +207,10 @@ type ( DiffTimeUploadFile int64 } ) +type TemplateTagColor struct { + Color [][]string `json:"color"` + Index int `json:"index"` +} func (l *defaultImageHandle) LogoCombine(ctx context.Context, in *LogoCombineReq) (*LogoCombineRes, error) { // 查询logo最新基础信息 @@ -308,6 +313,10 @@ func (l *defaultImageHandle) LogoCombine(ctx context.Context, in *LogoCombineReq combineParam["phone"] = in.Phone combineParam["address"] = in.Address combineParam["qrcode"] = in.Qrcode + combineParam["template_tag_selected"] = map[string]interface{}{ + "template_tag": in.TemplateTag, + "color": in.TemplateTagColor, + } var postMap = make(map[string]interface{}, 2) postMap["module_data"] = moduleDataMap From 389794500f35d38c0b7b1e39e885cb0bc2ab2ccb Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Mon, 18 Sep 2023 18:59:29 +0800 Subject: [PATCH 07/38] fix --- server/websocket/internal/logic/ws_render_image.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/server/websocket/internal/logic/ws_render_image.go b/server/websocket/internal/logic/ws_render_image.go index 39bb7fbf..85ff5572 100644 --- a/server/websocket/internal/logic/ws_render_image.go +++ b/server/websocket/internal/logic/ws_render_image.go @@ -197,6 +197,10 @@ func (w *wsConnectItem) renderImage(data []byte) { Phone: renderImageData.RenderData.Phone, Qrcode: renderImageData.RenderData.Qrcode, LogoUrl: renderImageData.RenderData.Logo, + TemplateTagColor: repositories.TemplateTagColor{ + Color: renderImageData.RenderData.TemplateTagColor.Color, + Index: renderImageData.RenderData.TemplateTagColor.SelectedIndex, + }, } res, err := w.logic.svcCtx.Repositories.ImageHandle.LogoCombine(w.logic.ctx, &combineReq) if err != nil { From bdef106f091560f8394140ac0034598fcefce197 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Mon, 18 Sep 2023 19:03:52 +0800 Subject: [PATCH 08/38] fix --- server/websocket/internal/logic/ws_render_image.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/websocket/internal/logic/ws_render_image.go b/server/websocket/internal/logic/ws_render_image.go index 85ff5572..6793528c 100644 --- a/server/websocket/internal/logic/ws_render_image.go +++ b/server/websocket/internal/logic/ws_render_image.go @@ -96,13 +96,13 @@ func (w *wsConnectItem) renderImage(data []byte) { //logx.Info("消费渲染数据:", string(data)) var renderImageData websocket_data.RenderImageReqMsg if err := json.Unmarshal(data, &renderImageData); err != nil { - w.renderErrResponse("", "", "", "数据格式错误", 0, 0, 0, 0, 0, 0, 0) + w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "数据格式错误", renderImageData.RenderData.ProductId, w.userId, w.guestId, 0, 0, 0, 0) logx.Error("invalid format of websocket render image message", err) return } lenColor := len(renderImageData.RenderData.TemplateTagColor.Color) if renderImageData.RenderData.TemplateTagColor.SelectedIndex >= lenColor || lenColor == 0 { - w.renderErrResponse("", "", "", "请传入模板标签选择的颜色", 0, 0, 0, 0, 0, 0, 0) + w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "请传入模板标签选择的颜色", renderImageData.RenderData.ProductId, w.userId, w.guestId, 0, 0, 0, 0) return } //获取产品信息(部分字段) From 3de3d896e8584a699f4f26bb1a79765d8fbdd917 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Mon, 18 Sep 2023 19:06:46 +0800 Subject: [PATCH 09/38] fix --- server/websocket/internal/logic/ws_render_image.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/server/websocket/internal/logic/ws_render_image.go b/server/websocket/internal/logic/ws_render_image.go index 6793528c..6ce69165 100644 --- a/server/websocket/internal/logic/ws_render_image.go +++ b/server/websocket/internal/logic/ws_render_image.go @@ -101,10 +101,14 @@ func (w *wsConnectItem) renderImage(data []byte) { return } lenColor := len(renderImageData.RenderData.TemplateTagColor.Color) - if renderImageData.RenderData.TemplateTagColor.SelectedIndex >= lenColor || lenColor == 0 { + if lenColor == 0 { w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "请传入模板标签选择的颜色", renderImageData.RenderData.ProductId, w.userId, w.guestId, 0, 0, 0, 0) return } + if renderImageData.RenderData.TemplateTagColor.SelectedIndex >= lenColor || renderImageData.RenderData.TemplateTagColor.SelectedIndex < 0 { + w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "选择的模板标签颜色索引越界", renderImageData.RenderData.ProductId, w.userId, w.guestId, 0, 0, 0, 0) + return + } //获取产品信息(部分字段) productInfo, err := w.logic.svcCtx.AllModels.FsProduct.FindOne(w.logic.ctx, renderImageData.RenderData.ProductId, "id,is_customization") if err != nil { From 157f05e43d36b90790f24c2950a1a0190b3719e9 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Tue, 19 Sep 2023 10:04:35 +0800 Subject: [PATCH 10/38] fix --- goctl_template/api/etc.tpl | 2 +- server/base/etc/base.yaml | 2 +- server/info/etc/info.yaml | 2 +- server/resource/etc/resource.yaml | 2 +- server/shopping-cart/etc/shopping-cart.yaml | 2 +- server/websocket/etc/websocket.yaml | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/goctl_template/api/etc.tpl b/goctl_template/api/etc.tpl index 86e74e0a..c2409e1f 100644 --- a/goctl_template/api/etc.tpl +++ b/goctl_template/api/etc.tpl @@ -3,7 +3,7 @@ Host: {{.host}} Port: {{.port}} Timeout: 15000 #服务超时时间(毫秒) SourceMysql: fsreaderwriter:XErSYmLELKMnf3Dh@tcp(fusen.cdmigcvz3rle.us-east-2.rds.amazonaws.com:3306)/fusen -SourceRabbitMq: amqp://rabbit001:rabbit001129@110.41.19.98:5672 +SourceRabbitMq: "" Auth: AccessSecret: fusen2023 AccessExpire: 2592000 diff --git a/server/base/etc/base.yaml b/server/base/etc/base.yaml index 4de0596c..36054478 100644 --- a/server/base/etc/base.yaml +++ b/server/base/etc/base.yaml @@ -10,4 +10,4 @@ Auth: AccessSecret: fusen2023 AccessExpire: 2592000 RefreshAfter: 1592000 -SourceRabbitMq: "amqp://rabbit001:rabbit001129@110.41.19.98:5672" \ No newline at end of file +SourceRabbitMq: "" \ No newline at end of file diff --git a/server/info/etc/info.yaml b/server/info/etc/info.yaml index 24d7b2ad..3fa5aea3 100644 --- a/server/info/etc/info.yaml +++ b/server/info/etc/info.yaml @@ -4,7 +4,7 @@ Port: 9988 Timeout: 15000 #服务超时时间(毫秒) ReplicaId: 200 SourceMysql: fsreaderwriter:XErSYmLELKMnf3Dh@tcp(fusen.cdmigcvz3rle.us-east-2.rds.amazonaws.com:3306)/fusen -SourceRabbitMq: amqp://rabbit001:rabbit001129@110.41.19.98:5672 +SourceRabbitMq: Log: Stat: false Auth: diff --git a/server/resource/etc/resource.yaml b/server/resource/etc/resource.yaml index e03a9f70..3353fd9f 100644 --- a/server/resource/etc/resource.yaml +++ b/server/resource/etc/resource.yaml @@ -10,7 +10,7 @@ Auth: AccessSecret: fusen2023 AccessExpire: 2592000 RefreshAfter: 1592000 -SourceRabbitMq: "amqp://rabbit001:rabbit001129@110.41.19.98:5672" +SourceRabbitMq: "" AWS: S3: Credentials: diff --git a/server/shopping-cart/etc/shopping-cart.yaml b/server/shopping-cart/etc/shopping-cart.yaml index 2b0db3dd..2fb861be 100644 --- a/server/shopping-cart/etc/shopping-cart.yaml +++ b/server/shopping-cart/etc/shopping-cart.yaml @@ -3,7 +3,7 @@ Host: 0.0.0.0 Port: 9918 Timeout: 15000 #服务超时时间(毫秒) SourceMysql: fsreaderwriter:XErSYmLELKMnf3Dh@tcp(fusen.cdmigcvz3rle.us-east-2.rds.amazonaws.com:3306)/fusen -SourceRabbitMq: amqp://rabbit001:rabbit001129@110.41.19.98:5672 +SourceRabbitMq: Log: Stat: false Auth: diff --git a/server/websocket/etc/websocket.yaml b/server/websocket/etc/websocket.yaml index e7b4197d..85f9ed0b 100644 --- a/server/websocket/etc/websocket.yaml +++ b/server/websocket/etc/websocket.yaml @@ -12,7 +12,7 @@ Auth: AccessSecret: fusen2023 AccessExpire: 2592000 RefreshAfter: 1592000 -SourceRabbitMq: "amqp://rabbit001:rabbit001129@110.41.19.98:5672" +SourceRabbitMq: "" AWS: S3: Credentials: From 498f4550f095ce8375252b9a295e11b8299b9bca Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Tue, 19 Sep 2023 10:09:22 +0800 Subject: [PATCH 11/38] fix --- .../websocket/internal/logic/ws_allocation_processing_factory.go | 1 + 1 file changed, 1 insertion(+) diff --git a/server/websocket/internal/logic/ws_allocation_processing_factory.go b/server/websocket/internal/logic/ws_allocation_processing_factory.go index 18cce02b..68cf7e49 100644 --- a/server/websocket/internal/logic/ws_allocation_processing_factory.go +++ b/server/websocket/internal/logic/ws_allocation_processing_factory.go @@ -6,6 +6,7 @@ import ( // 消息分发工厂 type allocationProcessorFactory interface { + //分配数据到缓冲队列 allocationMessage(w *wsConnectItem, data []byte) } From 34befce2f3e5d57ce4f85a29b74fb0087302d431 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Tue, 19 Sep 2023 10:18:17 +0800 Subject: [PATCH 12/38] fix --- .../websocket/internal/logic/datatransferlogic.go | 6 +++--- server/websocket/internal/logic/ws_render_image.go | 14 +++++++------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/server/websocket/internal/logic/datatransferlogic.go b/server/websocket/internal/logic/datatransferlogic.go index 9c7f1548..65a3121c 100644 --- a/server/websocket/internal/logic/datatransferlogic.go +++ b/server/websocket/internal/logic/datatransferlogic.go @@ -195,9 +195,9 @@ func (l *DataTransferLogic) setConnPool(conn *websocket.Conn, userInfo *auth.Use guestId: userInfo.GuestId, extendRenderProperty: extendRenderProperty{ //renderImageTask: make(map[string]*renderTask), - renderImageTaskCtlChan: make(chan renderImageControlChanItem, renderImageTaskCtlChanLen), - renderChan: make(chan []byte, renderChanLen), - renderConsumeTickTime: 1, //默认1纳秒,后面需要根据不同用户不同触发速度 + //renderImageTaskCtlChan: make(chan renderImageControlChanItem, renderImageTaskCtlChanLen), + renderChan: make(chan []byte, renderChanLen), + renderConsumeTickTime: 1, //默认1纳秒,后面需要根据不同用户不同触发速度 }, } //保存连接 diff --git a/server/websocket/internal/logic/ws_render_image.go b/server/websocket/internal/logic/ws_render_image.go index 6ce69165..c8fdcd25 100644 --- a/server/websocket/internal/logic/ws_render_image.go +++ b/server/websocket/internal/logic/ws_render_image.go @@ -33,27 +33,27 @@ type renderProcessor struct { // 云渲染属性 type extendRenderProperty struct { //renderImageTask map[string]*renderTask //需要渲染的图片任务 key是taskId val 是renderId - renderImageTaskCtlChan chan renderImageControlChanItem //渲染任务新增/回调结果移除任务/更新渲染耗时属性的控制通道(由于任务map无法读写并发) - renderChan chan []byte //渲染消息入口的缓冲队列 - renderConsumeTickTime time.Duration //消费渲染消息时钟间隔(纳秒),用于后期控制不同类型用户渲染速度限制 + //renderImageTaskCtlChan chan renderImageControlChanItem //渲染任务新增/回调结果移除任务/更新渲染耗时属性的控制通道(由于任务map无法读写并发) + renderChan chan []byte //渲染消息入口的缓冲队列 + renderConsumeTickTime time.Duration //消费渲染消息时钟间隔(纳秒),用于后期控制不同类型用户渲染速度限制 } // 渲染任务新增移除的控制通道的数据 -type renderImageControlChanItem struct { +/*type renderImageControlChanItem struct { option int // 0删除 1添加 2修改耗时属性 taskId string //map的key(必须传) renderId string // map的val(增加任务时候传) renderNotifyImageUrl string //渲染回调数据(删除任务时候传) taskProperty renderTask //渲染任务的属性 -} +}*/ // 渲染任务属性 -type renderTask struct { +/*type renderTask struct { renderId string //渲染id(新增任务传) unityRenderBeginTime int64 //发送给unity时间 unityRenderEndTime int64 //unity回调结果时间 uploadUnityRenderImageTakesTime int64 //上传unity渲染结果图时间 -} +}*/ // 处理分发到这里的数据 func (r *renderProcessor) allocationMessage(w *wsConnectItem, data []byte) { From 19958a80de9ce37b6daed0dc251eb4cc32231d43 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Tue, 19 Sep 2023 10:36:33 +0800 Subject: [PATCH 13/38] fix --- .../internal/logic/getproducttemplatetagslogic.go | 12 +++++------- server/product-template-tag/internal/types/types.go | 4 ++-- server_api/product-template-tag.api | 4 ++-- 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/server/product-template-tag/internal/logic/getproducttemplatetagslogic.go b/server/product-template-tag/internal/logic/getproducttemplatetagslogic.go index c76f2048..351fce2b 100644 --- a/server/product-template-tag/internal/logic/getproducttemplatetagslogic.go +++ b/server/product-template-tag/internal/logic/getproducttemplatetagslogic.go @@ -125,16 +125,13 @@ func (l *GetProductTemplateTagsLogic) GetProductTemplateTags(req *types.GetProdu list := make([]types.GetProductTemplateTagsRsp, 0, len(productTemplateTags)) for _, templateInfo := range productTemplateTags { colors := make([]types.ColorsItem, 0, 10) - for index, v := range mapTemplateTag[*templateInfo.TemplateTag] { - selected := false + SelectedIndex := 0 + for _, colorsSet := range mapTemplateTag[*templateInfo.TemplateTag] { if selectIndex, ok := mapSelectColor[*templateInfo.TemplateTag]; ok { - if index == selectIndex { - selected = true - } + SelectedIndex = selectIndex } colors = append(colors, types.ColorsItem{ - Color: v, - Selected: selected, + Color: colorsSet, }) } list = append(list, types.GetProductTemplateTagsRsp{ @@ -143,6 +140,7 @@ func (l *GetProductTemplateTagsLogic) GetProductTemplateTags(req *types.GetProdu Cover: *templateInfo.Cover, CoverMetadata: mapResourceMetadata[*templateInfo.Cover], Colors: colors, + SelectedIndex: SelectedIndex, }) } return resp.SetStatusWithMessage(basic.CodeOK, "success", list) diff --git a/server/product-template-tag/internal/types/types.go b/server/product-template-tag/internal/types/types.go index 574a34c6..7474e8da 100644 --- a/server/product-template-tag/internal/types/types.go +++ b/server/product-template-tag/internal/types/types.go @@ -15,11 +15,11 @@ type GetProductTemplateTagsRsp struct { Cover string `json:"cover"` CoverMetadata interface{} `json:"cover_metadata"` Colors []ColorsItem `json:"colors"` + SelectedIndex int `json:"selected_index"` } type ColorsItem struct { - Color []string `json:"color"` - Selected bool `json:"selected"` + Color []string `json:"color"` } type Request struct { diff --git a/server_api/product-template-tag.api b/server_api/product-template-tag.api index 30329047..6c88a573 100644 --- a/server_api/product-template-tag.api +++ b/server_api/product-template-tag.api @@ -25,8 +25,8 @@ type GetProductTemplateTagsRsp { Cover string `json:"cover"` CoverMetadata interface{} `json:"cover_metadata"` Colors []ColorsItem `json:"colors"` + SelectedIndex int `json:"selected_index"` } type ColorsItem { - Color []string `json:"color"` - Selected bool `json:"selected"` + Color []string `json:"color"` } \ No newline at end of file From 93e95d1a1507e59383826ac7f78bdf13001b5283 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Tue, 19 Sep 2023 10:41:15 +0800 Subject: [PATCH 14/38] fix --- .../internal/logic/ws_render_image.go | 13 -------- service/repositories/image_handle.go | 30 +++++++------------ utils/websocket_data/render_data.go | 27 +++++++---------- 3 files changed, 22 insertions(+), 48 deletions(-) diff --git a/server/websocket/internal/logic/ws_render_image.go b/server/websocket/internal/logic/ws_render_image.go index c8fdcd25..a8f86d2f 100644 --- a/server/websocket/internal/logic/ws_render_image.go +++ b/server/websocket/internal/logic/ws_render_image.go @@ -100,15 +100,6 @@ func (w *wsConnectItem) renderImage(data []byte) { logx.Error("invalid format of websocket render image message", err) return } - lenColor := len(renderImageData.RenderData.TemplateTagColor.Color) - if lenColor == 0 { - w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "请传入模板标签选择的颜色", renderImageData.RenderData.ProductId, w.userId, w.guestId, 0, 0, 0, 0) - return - } - if renderImageData.RenderData.TemplateTagColor.SelectedIndex >= lenColor || renderImageData.RenderData.TemplateTagColor.SelectedIndex < 0 { - w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "选择的模板标签颜色索引越界", renderImageData.RenderData.ProductId, w.userId, w.guestId, 0, 0, 0, 0) - return - } //获取产品信息(部分字段) productInfo, err := w.logic.svcCtx.AllModels.FsProduct.FindOne(w.logic.ctx, renderImageData.RenderData.ProductId, "id,is_customization") if err != nil { @@ -201,10 +192,6 @@ func (w *wsConnectItem) renderImage(data []byte) { Phone: renderImageData.RenderData.Phone, Qrcode: renderImageData.RenderData.Qrcode, LogoUrl: renderImageData.RenderData.Logo, - TemplateTagColor: repositories.TemplateTagColor{ - Color: renderImageData.RenderData.TemplateTagColor.Color, - Index: renderImageData.RenderData.TemplateTagColor.SelectedIndex, - }, } res, err := w.logic.svcCtx.Repositories.ImageHandle.LogoCombine(w.logic.ctx, &combineReq) if err != nil { diff --git a/service/repositories/image_handle.go b/service/repositories/image_handle.go index fa71fbd4..642f590d 100644 --- a/service/repositories/image_handle.go +++ b/service/repositories/image_handle.go @@ -187,17 +187,16 @@ func (l *defaultImageHandle) LogoInfoSet(ctx context.Context, in *LogoInfoSetReq /* logo合图 */ type ( LogoCombineReq struct { - UserId int64 `json:"user_id"` - GuestId int64 `json:"guest_id"` - TemplateId int64 `json:"template_id"` - TemplateTag string `json:"template_tag"` - Website string `json:"website"` // 合图参数 - Slogan string `json:"slogan"` // 合图参数 - Address string `json:"address"` // 合图参数 - Phone string `json:"phone"` // 合图参数 - Qrcode string `json:"qrcode"` // 合图参数 - LogoUrl string `json:"logo_url"` // 合图参数 - TemplateTagColor TemplateTagColor `json:"template_tag_color"` + UserId int64 `json:"user_id"` + GuestId int64 `json:"guest_id"` + TemplateId int64 `json:"template_id"` + TemplateTag string `json:"template_tag"` + Website string `json:"website"` // 合图参数 + Slogan string `json:"slogan"` // 合图参数 + Address string `json:"address"` // 合图参数 + Phone string `json:"phone"` // 合图参数 + Qrcode string `json:"qrcode"` // 合图参数 + LogoUrl string `json:"logo_url"` // 合图参数 } LogoCombineRes struct { ResourceId string @@ -207,10 +206,6 @@ type ( DiffTimeUploadFile int64 } ) -type TemplateTagColor struct { - Color [][]string `json:"color"` - Index int `json:"index"` -} func (l *defaultImageHandle) LogoCombine(ctx context.Context, in *LogoCombineReq) (*LogoCombineRes, error) { // 查询logo最新基础信息 @@ -313,10 +308,7 @@ func (l *defaultImageHandle) LogoCombine(ctx context.Context, in *LogoCombineReq combineParam["phone"] = in.Phone combineParam["address"] = in.Address combineParam["qrcode"] = in.Qrcode - combineParam["template_tag_selected"] = map[string]interface{}{ - "template_tag": in.TemplateTag, - "color": in.TemplateTagColor, - } + //combineParam["template_tag_selected"] = var postMap = make(map[string]interface{}, 2) postMap["module_data"] = moduleDataMap diff --git a/utils/websocket_data/render_data.go b/utils/websocket_data/render_data.go index d79032d5..16f3326b 100644 --- a/utils/websocket_data/render_data.go +++ b/utils/websocket_data/render_data.go @@ -15,22 +15,17 @@ type RenderImageReqMsg struct { RenderData RenderData `json:"render_data"` } type RenderData struct { - TemplateTag string `json:"template_tag"` //模板标签(必须) - TemplateTagColor TemplateTagColor `json:"template_tag_color"` //模板标签组合颜色 - ProductId int64 `json:"product_id"` //产品id(必须) - Website string `json:"website"` //网站(可选) - Slogan string `json:"slogan"` //slogan(可选) - Address string `json:"address"` //地址(可选) - Phone string `json:"phone"` //电话(可选) - Qrcode string `json:"qrcode"` //二维码(可选) - ProductSizeId int64 `json:"product_size_id"` //尺寸id(可选) - UserId int64 `json:"user_id"` //用户id(websocket连接建立再赋值) - GuestId int64 `json:"guest_id"` //游客id(websocket连接建立再赋值) - Logo string `json:"logo"` //log资源地址(websocket连接建立再赋值) -} -type TemplateTagColor struct { - Color [][]string `json:"color"` //颜色组合 - SelectedIndex int `json:"selected_index"` //主色的下标索引 + TemplateTag string `json:"template_tag"` //模板标签(必须) + ProductId int64 `json:"product_id"` //产品id(必须) + Website string `json:"website"` //网站(可选) + Slogan string `json:"slogan"` //slogan(可选) + Address string `json:"address"` //地址(可选) + Phone string `json:"phone"` //电话(可选) + Qrcode string `json:"qrcode"` //二维码(可选) + ProductSizeId int64 `json:"product_size_id"` //尺寸id(可选) + UserId int64 `json:"user_id"` //用户id(websocket连接建立再赋值) + GuestId int64 `json:"guest_id"` //游客id(websocket连接建立再赋值) + Logo string `json:"logo"` //log资源地址(websocket连接建立再赋值) } // websocket发送渲染完的数据 From 88d06f68f6f89ae579cb3919417ed8548db26f1f Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Tue, 19 Sep 2023 10:53:48 +0800 Subject: [PATCH 15/38] fix --- .../internal/logic/getproducttemplatetagslogic.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/server/product-template-tag/internal/logic/getproducttemplatetagslogic.go b/server/product-template-tag/internal/logic/getproducttemplatetagslogic.go index 351fce2b..0ecca97e 100644 --- a/server/product-template-tag/internal/logic/getproducttemplatetagslogic.go +++ b/server/product-template-tag/internal/logic/getproducttemplatetagslogic.go @@ -68,7 +68,7 @@ func (l *GetProductTemplateTagsLogic) GetProductTemplateTags(req *types.GetProdu if logoInfo.Metadata == nil || *logoInfo.Metadata == "" { return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "logo info`s metadata is not set") } - //解析元数据 + //解析用户素材元数据 var metaData map[string]interface{} if err = json.Unmarshal([]byte(*logoInfo.Metadata), &metaData); err != nil { logx.Error(err) @@ -83,6 +83,7 @@ func (l *GetProductTemplateTagsLogic) GetProductTemplateTags(req *types.GetProdu //获取选中的颜色数据 mapSelectColor := make(map[string]int) //key是模板标签val是选中的索引 if logoInfo.UserInfoMetadata != nil && *logoInfo.UserInfoMetadata != "" { + //解析用户信息元数据 var logoSelectInfo logoSelect if err = json.Unmarshal([]byte(*logoInfo.UserInfoMetadata), &logoSelectInfo); err != nil { logx.Error(err) From dc4f6dda5040b9e9111322d312a13c905099be5c Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Tue, 19 Sep 2023 10:56:30 +0800 Subject: [PATCH 16/38] fix --- .../internal/logic/getproducttemplatetagslogic.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/product-template-tag/internal/logic/getproducttemplatetagslogic.go b/server/product-template-tag/internal/logic/getproducttemplatetagslogic.go index 0ecca97e..30f5f07b 100644 --- a/server/product-template-tag/internal/logic/getproducttemplatetagslogic.go +++ b/server/product-template-tag/internal/logic/getproducttemplatetagslogic.go @@ -80,7 +80,7 @@ func (l *GetProductTemplateTagsLogic) GetProductTemplateTags(req *types.GetProdu logx.Error(err) return resp.SetStatusWithMessage(basic.CodeJsonErr, "invalid format of metadata`s template_tag") } - //获取选中的颜色数据 + //从用户元数据获取选中的颜色数据 mapSelectColor := make(map[string]int) //key是模板标签val是选中的索引 if logoInfo.UserInfoMetadata != nil && *logoInfo.UserInfoMetadata != "" { //解析用户信息元数据 From 4e0a484e7fe61c2f1d47c82516ceff361427e6f3 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Tue, 19 Sep 2023 10:59:53 +0800 Subject: [PATCH 17/38] fix --- .../internal/logic/getproducttemplatetagslogic.go | 1 - 1 file changed, 1 deletion(-) diff --git a/server/product-template-tag/internal/logic/getproducttemplatetagslogic.go b/server/product-template-tag/internal/logic/getproducttemplatetagslogic.go index 30f5f07b..828f3ab5 100644 --- a/server/product-template-tag/internal/logic/getproducttemplatetagslogic.go +++ b/server/product-template-tag/internal/logic/getproducttemplatetagslogic.go @@ -48,7 +48,6 @@ type logoSelect struct { } func (l *GetProductTemplateTagsLogic) GetProductTemplateTags(req *types.GetProductTemplateTagsReq, userinfo *auth.UserInfo) (resp *basic.Response) { - userinfo.UserId = 127 if req.Limit <= 0 || req.Limit > 100 { req.Limit = 5 } From b4672bbed79c594a0e543793308ab27397b5a6f0 Mon Sep 17 00:00:00 2001 From: eson <9673575+githubcontent@user.noreply.gitee.com> Date: Tue, 19 Sep 2023 11:41:38 +0800 Subject: [PATCH 18/38] nacos config --- env.yaml | 7 + goctl_template/api/main.tpl | 5 +- goctl_template/gateway/main.tpl | 2 +- goctl_template/rpc/main.tpl | 4 +- goctl_template_backend/api/main.tpl | 5 +- goctl_template_backend/gateway/main.tpl | 2 +- goctl_template_backend/rpc/main.tpl | 4 +- server/auth/auth.go | 5 +- server/base/base.go | 4 +- server/canteen/canteen.go | 5 +- server/data-transfer/data-transfer.go | 2 - server/home-user-auth/home-user-auth.go | 5 +- server/info/info.go | 5 +- server/map-library/map-library.go | 4 +- server/pay/pay.go | 5 +- server/product-model/product-model.go | 4 +- .../product-template-tag.go | 5 +- server/product-template/product-template.go | 4 +- server/product/product.go | 4 +- server/resource/resource.go | 5 +- server/shopping-cart/shopping-cart.go | 5 +- server/upload/upload.go | 4 +- server/webset/webset.go | 4 +- server/websocket/websocket.go | 5 +- utils/autoconfig/autoconfig.go | 2 +- utils/autoconfig/autoconfig_test.go | 7 +- utils/collect/collect.go | 4 +- utils/fsconfig/config.go | 153 ++++++++++++++---- utils/fsconfig/config_test.go | 62 +------ 29 files changed, 208 insertions(+), 124 deletions(-) create mode 100644 env.yaml diff --git a/env.yaml b/env.yaml new file mode 100644 index 00000000..b61412d6 --- /dev/null +++ b/env.yaml @@ -0,0 +1,7 @@ +nacos: + - server.fusen.3718.cn:8848 + - server.fusen.3718.cn:8849 +username: ... +password: ... +namespace: fs_server_api_dev +group: FS-SERVER-API diff --git a/goctl_template/api/main.tpl b/goctl_template/api/main.tpl index f4a688cb..057d55c7 100644 --- a/goctl_template/api/main.tpl +++ b/goctl_template/api/main.tpl @@ -7,6 +7,7 @@ import ( "time" "fusenapi/utils/auth" + "fusenapi/utils/fsconfig" {{.importPackages}} ) @@ -16,8 +17,10 @@ var configFile = flag.String("f", "etc/{{.serviceName}}.yaml", "the config file" func main() { flag.Parse() + cfgContent := fsconfig.StartNacosConfig(configFile,nil) var c config.Config - conf.MustLoad(*configFile, &c) + conf.LoadConfigFromYamlBytes([]byte(cfgContent),&c) + c.Timeout = int64(time.Second * 15) server := rest.MustNewServer(c.RestConf, rest.WithCustomCors(auth.FsCors, func(w http.ResponseWriter) { })) diff --git a/goctl_template/gateway/main.tpl b/goctl_template/gateway/main.tpl index dafdd982..33c303b8 100644 --- a/goctl_template/gateway/main.tpl +++ b/goctl_template/gateway/main.tpl @@ -13,7 +13,7 @@ func main() { flag.Parse() var c gateway.GatewayConf - conf.MustLoad(*configFile, &c) + c.Timeout = int64(time.Second * 15) gw := gateway.MustNewServer(c) defer gw.Stop() diff --git a/goctl_template/rpc/main.tpl b/goctl_template/rpc/main.tpl index f095b259..13fbae92 100644 --- a/goctl_template/rpc/main.tpl +++ b/goctl_template/rpc/main.tpl @@ -18,8 +18,10 @@ var configFile = flag.String("f", "etc/{{.serviceName}}.yaml", "the config file" func main() { flag.Parse() + cfgContent := fsconfig.StartNacosConfig(configFile,nil) var c config.Config - conf.MustLoad(*configFile, &c) + conf.LoadConfigFromYamlBytes([]byte(cfgContent),&c) + c.Timeout = int64(time.Second * 15) ctx := svc.NewServiceContext(c) diff --git a/goctl_template_backend/api/main.tpl b/goctl_template_backend/api/main.tpl index 71e4fb99..6cc7a21c 100644 --- a/goctl_template_backend/api/main.tpl +++ b/goctl_template_backend/api/main.tpl @@ -7,6 +7,7 @@ import ( "time" "fusenapi/utils/auth" + "fusenapi/utils/fsconfig" {{.importPackages}} ) @@ -16,8 +17,10 @@ var configFile = flag.String("f", "etc/{{.serviceName}}.yaml", "the config file" func main() { flag.Parse() + cfgContent := fsconfig.StartNacosConfig(configFile,nil) var c config.Config - conf.MustLoad(*configFile, &c) + conf.LoadConfigFromYamlBytes([]byte(cfgContent),&c) + c.Timeout = int64(time.Second * 15) server := rest.MustNewServer(c.RestConf, rest.WithCustomCors(auth.FsCors, func(w http.ResponseWriter) { diff --git a/goctl_template_backend/gateway/main.tpl b/goctl_template_backend/gateway/main.tpl index dafdd982..33c303b8 100644 --- a/goctl_template_backend/gateway/main.tpl +++ b/goctl_template_backend/gateway/main.tpl @@ -13,7 +13,7 @@ func main() { flag.Parse() var c gateway.GatewayConf - conf.MustLoad(*configFile, &c) + c.Timeout = int64(time.Second * 15) gw := gateway.MustNewServer(c) defer gw.Stop() diff --git a/goctl_template_backend/rpc/main.tpl b/goctl_template_backend/rpc/main.tpl index f095b259..13fbae92 100644 --- a/goctl_template_backend/rpc/main.tpl +++ b/goctl_template_backend/rpc/main.tpl @@ -18,8 +18,10 @@ var configFile = flag.String("f", "etc/{{.serviceName}}.yaml", "the config file" func main() { flag.Parse() + cfgContent := fsconfig.StartNacosConfig(configFile,nil) var c config.Config - conf.MustLoad(*configFile, &c) + conf.LoadConfigFromYamlBytes([]byte(cfgContent),&c) + c.Timeout = int64(time.Second * 15) ctx := svc.NewServiceContext(c) diff --git a/server/auth/auth.go b/server/auth/auth.go index 34623035..1c1278f1 100644 --- a/server/auth/auth.go +++ b/server/auth/auth.go @@ -6,6 +6,7 @@ import ( "net/http" "fusenapi/utils/auth" + "fusenapi/utils/fsconfig" "fusenapi/server/auth/internal/config" "fusenapi/server/auth/internal/handler" @@ -20,8 +21,10 @@ var configFile = flag.String("f", "etc/auth.yaml", "the config file") func main() { flag.Parse() + cfgContent := fsconfig.StartNacosConfig(*configFile, nil) var c config.Config - conf.MustLoad(*configFile, &c) + conf.LoadConfigFromYamlBytes([]byte(cfgContent), &c) + server := rest.MustNewServer(c.RestConf, rest.WithCustomCors(auth.FsCors, func(w http.ResponseWriter) { })) defer server.Stop() diff --git a/server/base/base.go b/server/base/base.go index 1d3f1af1..7db23d4a 100644 --- a/server/base/base.go +++ b/server/base/base.go @@ -6,6 +6,7 @@ import ( "net/http" "fusenapi/utils/auth" + "fusenapi/utils/fsconfig" "fusenapi/server/base/internal/config" "fusenapi/server/base/internal/handler" @@ -20,8 +21,9 @@ var configFile = flag.String("f", "etc/base.yaml", "the config file") func main() { flag.Parse() + cfgContent := fsconfig.StartNacosConfig(*configFile, nil) var c config.Config - conf.MustLoad(*configFile, &c) + conf.LoadConfigFromYamlBytes([]byte(cfgContent), &c) server := rest.MustNewServer(c.RestConf, rest.WithCustomCors(auth.FsCors, func(w http.ResponseWriter) { })) diff --git a/server/canteen/canteen.go b/server/canteen/canteen.go index eb2e1f27..2261a4ad 100644 --- a/server/canteen/canteen.go +++ b/server/canteen/canteen.go @@ -9,6 +9,7 @@ import ( "fusenapi/server/canteen/internal/handler" "fusenapi/server/canteen/internal/svc" "fusenapi/utils/auth" + "fusenapi/utils/fsconfig" "github.com/zeromicro/go-zero/core/conf" "github.com/zeromicro/go-zero/rest" @@ -19,9 +20,9 @@ var configFile = flag.String("f", "etc/canteen.yaml", "the config file") func main() { flag.Parse() + cfgContent := fsconfig.StartNacosConfig(*configFile, nil) var c config.Config - - conf.MustLoad(*configFile, &c) + conf.LoadConfigFromYamlBytes([]byte(cfgContent), &c) server := rest.MustNewServer(c.RestConf, rest.WithCustomCors(auth.FsCors, func(w http.ResponseWriter) { diff --git a/server/data-transfer/data-transfer.go b/server/data-transfer/data-transfer.go index 8ad3fa67..db2a4230 100644 --- a/server/data-transfer/data-transfer.go +++ b/server/data-transfer/data-transfer.go @@ -9,7 +9,6 @@ import ( "fusenapi/utils/auth" "net/http" - "github.com/zeromicro/go-zero/core/conf" "github.com/zeromicro/go-zero/rest" ) @@ -19,7 +18,6 @@ func main() { flag.Parse() var c config2.Config - conf.MustLoad(*configFile, &c) server := rest.MustNewServer(c.RestConf, rest.WithCustomCors(auth.FsCors, func(w http.ResponseWriter) { diff --git a/server/home-user-auth/home-user-auth.go b/server/home-user-auth/home-user-auth.go index 911ae5de..16c3a315 100644 --- a/server/home-user-auth/home-user-auth.go +++ b/server/home-user-auth/home-user-auth.go @@ -9,6 +9,7 @@ import ( "fusenapi/server/home-user-auth/internal/handler" "fusenapi/server/home-user-auth/internal/svc" "fusenapi/utils/auth" + "fusenapi/utils/fsconfig" "github.com/zeromicro/go-zero/core/conf" "github.com/zeromicro/go-zero/rest" @@ -19,9 +20,9 @@ var configFile = flag.String("f", "etc/home-user-auth.yaml", "the config file") func main() { flag.Parse() + cfgContent := fsconfig.StartNacosConfig(*configFile, nil) var c config.Config - - conf.MustLoad(*configFile, &c) + conf.LoadConfigFromYamlBytes([]byte(cfgContent), &c) server := rest.MustNewServer(c.RestConf, rest.WithCustomCors(auth.FsCors, func(w http.ResponseWriter) { diff --git a/server/info/info.go b/server/info/info.go index 4571550d..613b74a1 100644 --- a/server/info/info.go +++ b/server/info/info.go @@ -7,6 +7,7 @@ import ( "time" "fusenapi/utils/auth" + "fusenapi/utils/fsconfig" "fusenapi/server/info/internal/config" "fusenapi/server/info/internal/handler" @@ -21,8 +22,10 @@ var configFile = flag.String("f", "etc/info.yaml", "the config file") func main() { flag.Parse() + cfgContent := fsconfig.StartNacosConfig(*configFile, nil) var c config.Config - conf.MustLoad(*configFile, &c) + conf.LoadConfigFromYamlBytes([]byte(cfgContent), &c) + c.Timeout = int64(time.Second * 15) server := rest.MustNewServer(c.RestConf, rest.WithCustomCors(auth.FsCors, func(w http.ResponseWriter) { })) diff --git a/server/map-library/map-library.go b/server/map-library/map-library.go index b8f7e38b..a7ac3fd3 100644 --- a/server/map-library/map-library.go +++ b/server/map-library/map-library.go @@ -9,6 +9,7 @@ import ( "fusenapi/server/map-library/internal/handler" "fusenapi/server/map-library/internal/svc" "fusenapi/utils/auth" + "fusenapi/utils/fsconfig" "github.com/zeromicro/go-zero/core/conf" "github.com/zeromicro/go-zero/rest" @@ -19,8 +20,9 @@ var configFile = flag.String("f", "etc/map-library.yaml", "the config file") func main() { flag.Parse() + cfgContent := fsconfig.StartNacosConfig(*configFile, nil) var c config.Config - conf.MustLoad(*configFile, &c) + conf.LoadConfigFromYamlBytes([]byte(cfgContent), &c) server := rest.MustNewServer(c.RestConf, rest.WithCustomCors(auth.FsCors, func(w http.ResponseWriter) { diff --git a/server/pay/pay.go b/server/pay/pay.go index ecfedfef..5b57352c 100644 --- a/server/pay/pay.go +++ b/server/pay/pay.go @@ -6,6 +6,7 @@ import ( "net/http" "fusenapi/utils/auth" + "fusenapi/utils/fsconfig" "fusenapi/server/pay/internal/config" "fusenapi/server/pay/internal/handler" @@ -20,8 +21,10 @@ var configFile = flag.String("f", "etc/pay.yaml", "the config file") func main() { flag.Parse() + cfgContent := fsconfig.StartNacosConfig(*configFile, nil) var c config.Config - conf.MustLoad(*configFile, &c) + conf.LoadConfigFromYamlBytes([]byte(cfgContent), &c) + server := rest.MustNewServer(c.RestConf, rest.WithCustomCors(auth.FsCors, func(w http.ResponseWriter) { })) defer server.Stop() diff --git a/server/product-model/product-model.go b/server/product-model/product-model.go index a6374de1..0d71e15a 100644 --- a/server/product-model/product-model.go +++ b/server/product-model/product-model.go @@ -9,6 +9,7 @@ import ( "fusenapi/server/product-model/internal/handler" "fusenapi/server/product-model/internal/svc" "fusenapi/utils/auth" + "fusenapi/utils/fsconfig" "github.com/zeromicro/go-zero/core/conf" "github.com/zeromicro/go-zero/rest" @@ -19,8 +20,9 @@ var configFile = flag.String("f", "etc/product-model.yaml", "the config file") func main() { flag.Parse() + cfgContent := fsconfig.StartNacosConfig(*configFile, nil) var c config.Config - conf.MustLoad(*configFile, &c) + conf.LoadConfigFromYamlBytes([]byte(cfgContent), &c) server := rest.MustNewServer(c.RestConf, rest.WithCustomCors(auth.FsCors, func(w http.ResponseWriter) { diff --git a/server/product-template-tag/product-template-tag.go b/server/product-template-tag/product-template-tag.go index 5f1bd6cd..fa892576 100644 --- a/server/product-template-tag/product-template-tag.go +++ b/server/product-template-tag/product-template-tag.go @@ -6,6 +6,7 @@ import ( "net/http" "fusenapi/utils/auth" + "fusenapi/utils/fsconfig" "fusenapi/server/product-template-tag/internal/config" "fusenapi/server/product-template-tag/internal/handler" @@ -20,8 +21,10 @@ var configFile = flag.String("f", "etc/product-template-tag.yaml", "the config f func main() { flag.Parse() + cfgContent := fsconfig.StartNacosConfig(*configFile, nil) var c config.Config - conf.MustLoad(*configFile, &c) + conf.LoadConfigFromYamlBytes([]byte(cfgContent), &c) + server := rest.MustNewServer(c.RestConf, rest.WithCustomCors(auth.FsCors, func(w http.ResponseWriter) { })) defer server.Stop() diff --git a/server/product-template/product-template.go b/server/product-template/product-template.go index 3819752a..260b7c56 100644 --- a/server/product-template/product-template.go +++ b/server/product-template/product-template.go @@ -9,6 +9,7 @@ import ( "fusenapi/server/product-template/internal/handler" "fusenapi/server/product-template/internal/svc" "fusenapi/utils/auth" + "fusenapi/utils/fsconfig" "github.com/zeromicro/go-zero/core/conf" "github.com/zeromicro/go-zero/rest" @@ -19,8 +20,9 @@ var configFile = flag.String("f", "etc/product-template.yaml", "the config file" func main() { flag.Parse() + cfgContent := fsconfig.StartNacosConfig(*configFile, nil) var c config.Config - conf.MustLoad(*configFile, &c) + conf.LoadConfigFromYamlBytes([]byte(cfgContent), &c) server := rest.MustNewServer(c.RestConf, rest.WithCustomCors(auth.FsCors, func(w http.ResponseWriter) { diff --git a/server/product/product.go b/server/product/product.go index 13fba403..adc4c782 100644 --- a/server/product/product.go +++ b/server/product/product.go @@ -9,6 +9,7 @@ import ( "fusenapi/server/product/internal/handler" "fusenapi/server/product/internal/svc" "fusenapi/utils/auth" + "fusenapi/utils/fsconfig" "github.com/zeromicro/go-zero/core/conf" "github.com/zeromicro/go-zero/rest" @@ -19,8 +20,9 @@ var configFile = flag.String("f", "etc/product.yaml", "the config file") func main() { flag.Parse() + cfgContent := fsconfig.StartNacosConfig(*configFile, nil) var c config.Config - conf.MustLoad(*configFile, &c) + conf.LoadConfigFromYamlBytes([]byte(cfgContent), &c) server := rest.MustNewServer(c.RestConf, rest.WithCustomCors(auth.FsCors, func(w http.ResponseWriter) { diff --git a/server/resource/resource.go b/server/resource/resource.go index 29887332..e40a9db7 100644 --- a/server/resource/resource.go +++ b/server/resource/resource.go @@ -6,6 +6,7 @@ import ( "net/http" "fusenapi/utils/auth" + "fusenapi/utils/fsconfig" "fusenapi/server/resource/internal/config" "fusenapi/server/resource/internal/handler" @@ -20,8 +21,10 @@ var configFile = flag.String("f", "etc/resource.yaml", "the config file") func main() { flag.Parse() + cfgContent := fsconfig.StartNacosConfig(*configFile, nil) var c config.Config - conf.MustLoad(*configFile, &c) + conf.LoadConfigFromYamlBytes([]byte(cfgContent), &c) + server := rest.MustNewServer(c.RestConf, rest.WithCustomCors(auth.FsCors, func(w http.ResponseWriter) { })) defer server.Stop() diff --git a/server/shopping-cart/shopping-cart.go b/server/shopping-cart/shopping-cart.go index f7a8cb3f..bf9dabc1 100644 --- a/server/shopping-cart/shopping-cart.go +++ b/server/shopping-cart/shopping-cart.go @@ -7,6 +7,7 @@ import ( "time" "fusenapi/utils/auth" + "fusenapi/utils/fsconfig" "fusenapi/server/shopping-cart/internal/config" "fusenapi/server/shopping-cart/internal/handler" @@ -21,8 +22,10 @@ var configFile = flag.String("f", "etc/shopping-cart.yaml", "the config file") func main() { flag.Parse() + cfgContent := fsconfig.StartNacosConfig(*configFile, nil) var c config.Config - conf.MustLoad(*configFile, &c) + conf.LoadConfigFromYamlBytes([]byte(cfgContent), &c) + c.Timeout = int64(time.Second * 15) server := rest.MustNewServer(c.RestConf, rest.WithCustomCors(auth.FsCors, func(w http.ResponseWriter) { })) diff --git a/server/upload/upload.go b/server/upload/upload.go index bea4af45..42a589d6 100644 --- a/server/upload/upload.go +++ b/server/upload/upload.go @@ -9,6 +9,7 @@ import ( "fusenapi/server/upload/internal/handler" "fusenapi/server/upload/internal/svc" "fusenapi/utils/auth" + "fusenapi/utils/fsconfig" "github.com/zeromicro/go-zero/core/conf" "github.com/zeromicro/go-zero/rest" @@ -19,8 +20,9 @@ var configFile = flag.String("f", "etc/upload.yaml", "the config file") func main() { flag.Parse() + cfgContent := fsconfig.StartNacosConfig(*configFile, nil) var c config.Config - conf.MustLoad(*configFile, &c) + conf.LoadConfigFromYamlBytes([]byte(cfgContent), &c) server := rest.MustNewServer(c.RestConf, rest.WithCustomCors(auth.FsCors, func(w http.ResponseWriter) { diff --git a/server/webset/webset.go b/server/webset/webset.go index ab154b3b..be0cfcd0 100644 --- a/server/webset/webset.go +++ b/server/webset/webset.go @@ -9,6 +9,7 @@ import ( "fusenapi/server/webset/internal/handler" "fusenapi/server/webset/internal/svc" "fusenapi/utils/auth" + "fusenapi/utils/fsconfig" "github.com/zeromicro/go-zero/core/conf" "github.com/zeromicro/go-zero/rest" @@ -19,8 +20,9 @@ var configFile = flag.String("f", "etc/webset.yaml", "the config file") func main() { flag.Parse() + cfgContent := fsconfig.StartNacosConfig(*configFile, nil) var c config.Config - conf.MustLoad(*configFile, &c) + conf.LoadConfigFromYamlBytes([]byte(cfgContent), &c) server := rest.MustNewServer(c.RestConf, rest.WithCustomCors(auth.FsCors, func(w http.ResponseWriter) { diff --git a/server/websocket/websocket.go b/server/websocket/websocket.go index d77e9242..6dbc99a2 100644 --- a/server/websocket/websocket.go +++ b/server/websocket/websocket.go @@ -8,6 +8,7 @@ import ( "net/http" "fusenapi/utils/auth" + "fusenapi/utils/fsconfig" "fusenapi/server/websocket/internal/config" "fusenapi/server/websocket/internal/handler" @@ -22,8 +23,10 @@ var configFile = flag.String("f", "etc/websocket.yaml", "the config file") func main() { flag.Parse() + cfgContent := fsconfig.StartNacosConfig(*configFile, nil) var c config.Config - conf.MustLoad(*configFile, &c) + conf.LoadConfigFromYamlBytes([]byte(cfgContent), &c) + server := rest.MustNewServer(c.RestConf, rest.WithCustomCors(auth.FsCors, func(w http.ResponseWriter) { })) defer server.Stop() diff --git a/utils/autoconfig/autoconfig.go b/utils/autoconfig/autoconfig.go index 72442729..97fc2c05 100644 --- a/utils/autoconfig/autoconfig.go +++ b/utils/autoconfig/autoconfig.go @@ -74,7 +74,7 @@ func AutoGetEtcYaml() *string { dirs = dirs[0 : len(dirs)-1] // 列出所有 curPath 下的文件夹 - files, err := ioutil.ReadDir(curPath) + files, err := os.ReadDir(curPath) if err != nil { log.Println(err) continue diff --git a/utils/autoconfig/autoconfig_test.go b/utils/autoconfig/autoconfig_test.go index 7f118a8a..0a72aab0 100644 --- a/utils/autoconfig/autoconfig_test.go +++ b/utils/autoconfig/autoconfig_test.go @@ -1,7 +1,10 @@ package autoconfig -import "testing" +import ( + "log" + "testing" +) func TestAutoConfig(t *testing.T) { - AutoGetEtcYaml() + log.Println(*AutoGetEtcYaml()) } diff --git a/utils/collect/collect.go b/utils/collect/collect.go index b0502d61..c3630e5c 100644 --- a/utils/collect/collect.go +++ b/utils/collect/collect.go @@ -119,7 +119,7 @@ func Array2MapByKey[KEY comparable, VALUE any](arrSrc []VALUE, fieldName string) } fv := srcv.FieldByName(fieldName) k := fv.Interface().(KEY) - result[k] = srcv.Interface().(VALUE) + result[k] = arr.Index(i).Interface().(VALUE) } return result @@ -166,7 +166,7 @@ func Array2MapByKeyTag[KEY comparable, VALUE any](arrSrc []VALUE, tag string) (r fv = fv.Elem() } k := fv.Interface().(KEY) - result[k] = srcv.Interface().(VALUE) + result[k] = arr.Index(i).Interface().(VALUE) } return diff --git a/utils/fsconfig/config.go b/utils/fsconfig/config.go index 116043dc..66f5841e 100644 --- a/utils/fsconfig/config.go +++ b/utils/fsconfig/config.go @@ -1,53 +1,142 @@ package fsconfig import ( - "fmt" "log" "os" + "path/filepath" + "strconv" + "strings" + "github.com/nacos-group/nacos-sdk-go/v2/clients" + "github.com/nacos-group/nacos-sdk-go/v2/common/constant" + "github.com/nacos-group/nacos-sdk-go/v2/vo" "gopkg.in/yaml.v2" ) type EnvConfig struct { - Host string `yaml:"host"` - Port uint64 `yaml:"port"` - - UserName string `yaml:"username"` - Password string `yaml:"password"` - NamespaceId string `yaml:"namespace"` - DataId string `yaml:"dataid"` - Group string `yaml:"group"` + NacosServers []string `yaml:"nacos"` + UserName string `yaml:"username"` + Password string `yaml:"password"` + NamespaceId string `yaml:"namespace"` + DataId string `yaml:"dataid"` + Group string `yaml:"group"` } -var OptPathDir = "/opt" +var optPathDirs = []string{"/opt", "./", "../", "../../"} var nacosConfig *EnvConfig func GetEnvCofing() *EnvConfig { - return nacosConfig + + if nacosConfig != nil { + return nacosConfig + } + + for _, optDir := range optPathDirs { + if optDir[len(optDir)-1] != '/' { + optDir = optDir + "/" + } + + for _, yname := range []string{"env.yaml", "env.yml"} { + f, err := os.Open(optDir + yname) + if err != nil { + // log.Println(err) + continue + } + cfg := &EnvConfig{} + err = yaml.NewDecoder(f).Decode(&cfg) + if err != nil { + // log.Println(err) + continue + } + + nacosConfig = cfg + return nacosConfig + } + } + + panic("Can't find env.yaml or env.yml in the specified directories") + } func init() { - if OptPathDir[len(OptPathDir)-1] != '/' { - OptPathDir = OptPathDir + "/" - } - for _, yname := range []string{"env.yaml", "env.yml"} { - f, err := os.Open(OptPathDir + "/" + yname) - if err != nil { - log.Println(err) - continue - } - cfg := &EnvConfig{} - err = yaml.NewDecoder(f).Decode(&cfg) - if err != nil { - log.Println(err) - continue - } - - nacosConfig = cfg - return - } - - panic(fmt.Sprintf("can't find %s(env.yaml|env.yml) ", OptPathDir)) +} + +func StartNacosConfig(configFile string, OnChange func(namespace, group, dataId, data string)) string { + env := GetEnvCofing() + + // 创建serverConfig + // 支持多个;至少一个ServerConfig + var serverConfig []constant.ServerConfig + + for _, s := range env.NacosServers { + + sp := strings.Split(s, ":") + host := sp[0] + port, err := strconv.ParseUint(sp[1], 10, 64) + if err != nil { + panic(err) + } + + serverConfig = append(serverConfig, constant.ServerConfig{ + IpAddr: host, + Port: port, + }) + } + + // 创建clientConfig + clientConfig := constant.ClientConfig{ + NamespaceId: env.NamespaceId, // 如果需要支持多namespace,我们可以场景多个client,它们有不同的NamespaceId。当namespace是public时,此处填空字符串。 + TimeoutMs: 50000, + NotLoadCacheAtStart: true, + LogLevel: "debug", + LogDir: "/tmp/nacos/log", + CacheDir: "/tmp/nacos/cache", + Username: env.UserName, + Password: env.Password, + } + + // 创建服务发现客户端的另一种方式 (推荐) + // namingClient, err := clients.NewNamingClient( + // vo.NacosClientParam{ + // ClientConfig: &clientConfig, + // ServerConfigs: serverConfig, + // }, + // ) + // if err != nil { + // log.Fatalf("初始化nacos失败: %s", err.Error()) + // } + + // log.Println(namingClient) + + // 创建 Nacos 配置客户端 + configClient, err := clients.CreateConfigClient(map[string]interface{}{ + "clientConfig": clientConfig, + "serverConfigs": serverConfig, + }) + if err != nil { + log.Fatalf("Failed to create Nacos config client: %v", err) + } + + cfgYamls := strings.Split(configFile, "/") + cfgYaml := cfgYamls[len(cfgYamls)-1] + yamlExt := filepath.Ext(cfgYaml) + if !(yamlExt == ".yaml" || yamlExt == ".yml") { + log.Panic(configFile) + } + + // 获取配置 + content, err := configClient.GetConfig(vo.ConfigParam{ + DataId: cfgYaml, + Group: env.Group, + OnChange: OnChange, + }) + if err != nil { + log.Fatalf("Failed to get config from Nacos: %v", err) + } + + return content + + // log.Println(content) } diff --git a/utils/fsconfig/config_test.go b/utils/fsconfig/config_test.go index f285c6bb..8ffaaffb 100644 --- a/utils/fsconfig/config_test.go +++ b/utils/fsconfig/config_test.go @@ -2,69 +2,9 @@ package fsconfig_test import ( "fusenapi/utils/fsconfig" - "log" "testing" - - "github.com/nacos-group/nacos-sdk-go/v2/clients" - "github.com/nacos-group/nacos-sdk-go/v2/common/constant" - "github.com/nacos-group/nacos-sdk-go/v2/vo" ) func TestCase1(t *testing.T) { - - env := fsconfig.GetEnvCofing() - - // 创建serverConfig - // 支持多个;至少一个ServerConfig - serverConfig := []constant.ServerConfig{ - { - IpAddr: env.Host, - Port: uint64(env.Port), - }, - } - - // 创建clientConfig - clientConfig := constant.ClientConfig{ - NamespaceId: env.NamespaceId, // 如果需要支持多namespace,我们可以场景多个client,它们有不同的NamespaceId。当namespace是public时,此处填空字符串。 - TimeoutMs: 50000, - NotLoadCacheAtStart: true, - LogLevel: "debug", - LogDir: "/tmp/nacos", - CacheDir: "/tmp/nacos", - Username: env.UserName, - Password: env.Password, - } - - // 创建服务发现客户端的另一种方式 (推荐) - // namingClient, err := clients.NewNamingClient( - // vo.NacosClientParam{ - // ClientConfig: &clientConfig, - // ServerConfigs: serverConfig, - // }, - // ) - // if err != nil { - // log.Fatalf("初始化nacos失败: %s", err.Error()) - // } - - // log.Println(namingClient) - - // 创建 Nacos 配置客户端 - configClient, err := clients.CreateConfigClient(map[string]interface{}{ - "clientConfig": clientConfig, - "serverConfigs": serverConfig, - }) - if err != nil { - log.Fatalf("Failed to create Nacos config client: %v", err) - } - - // 获取配置 - content, err := configClient.GetConfig(vo.ConfigParam{ - DataId: "auth.yaml", - Group: env.Group, - }) - if err != nil { - log.Fatalf("Failed to get config from Nacos: %v", err) - } - log.Println(content) - + fsconfig.StartNacosConfig("auth.yaml", nil) } From c0b773634a7238b1ea26e4230ed4fc91be64c6ed Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Tue, 19 Sep 2023 11:42:10 +0800 Subject: [PATCH 19/38] =?UTF-8?q?=E5=90=88=E5=B9=B6develop?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/shopping-cart/internal/logic/getcartslogic.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/server/shopping-cart/internal/logic/getcartslogic.go b/server/shopping-cart/internal/logic/getcartslogic.go index 303716f4..f79d8db3 100644 --- a/server/shopping-cart/internal/logic/getcartslogic.go +++ b/server/shopping-cart/internal/logic/getcartslogic.go @@ -41,6 +41,9 @@ func NewGetCartsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetCarts // } func (l *GetCartsLogic) GetCarts(req *types.GetCartsReq, userinfo *auth.UserInfo) (resp *basic.Response) { + if !userinfo.IsUser() { + return resp.SetStatusWithMessage(basic.CodeUnAuth, "please sign in") + } if req.CurrentPage <= 0 { req.CurrentPage = constants.DEFAULT_PAGE } From 3c33a9603749112242675a007334d4514a05a181 Mon Sep 17 00:00:00 2001 From: eson <9673575+githubcontent@user.noreply.gitee.com> Date: Tue, 19 Sep 2023 11:48:38 +0800 Subject: [PATCH 20/38] nacos config --- utils/fsconfig/config.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/utils/fsconfig/config.go b/utils/fsconfig/config.go index 66f5841e..3c933bb5 100644 --- a/utils/fsconfig/config.go +++ b/utils/fsconfig/config.go @@ -136,6 +136,8 @@ func StartNacosConfig(configFile string, OnChange func(namespace, group, dataId, log.Fatalf("Failed to get config from Nacos: %v", err) } + log.Println("加载成功:", cfgYaml) + return content // log.Println(content) From 7fd65d9ac76680c3ac9f48d3fc6ce794d86897a5 Mon Sep 17 00:00:00 2001 From: eson <9673575+githubcontent@user.noreply.gitee.com> Date: Tue, 19 Sep 2023 12:01:37 +0800 Subject: [PATCH 21/38] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=96=B0=E7=9A=84?= =?UTF-8?q?=E5=8A=A0=E8=BD=BD=E4=BE=9D=E8=B5=96=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 14 -------------- run_all_server.sh | 5 +++-- server/auth/.gitignore | 1 + server/base/.gitignore | 1 + server/canteen/.gitignore | 1 + server/data-transfer/.gitignore | 1 + server/home-user-auth/.gitignore | 1 + server/info/.gitignore | 1 + server/map-library/.gitignore | 1 + server/pay/.gitignore | 1 + server/product-model/.gitignore | 1 + server/product-template-tag/.gitignore | 1 + server/product-template/.gitignore | 1 + server/product/.gitignore | 1 + server/resource/.gitignore | 1 + server/shopping-cart/.gitignore | 1 + server/upload/.gitignore | 1 + server/webset/.gitignore | 1 + server/websocket/.gitignore | 1 + 19 files changed, 20 insertions(+), 16 deletions(-) create mode 100644 server/auth/.gitignore create mode 100644 server/base/.gitignore create mode 100644 server/canteen/.gitignore create mode 100644 server/data-transfer/.gitignore create mode 100644 server/home-user-auth/.gitignore create mode 100644 server/info/.gitignore create mode 100644 server/map-library/.gitignore create mode 100644 server/pay/.gitignore create mode 100644 server/product-model/.gitignore create mode 100644 server/product-template-tag/.gitignore create mode 100644 server/product-template/.gitignore create mode 100644 server/product/.gitignore create mode 100644 server/resource/.gitignore create mode 100644 server/shopping-cart/.gitignore create mode 100644 server/upload/.gitignore create mode 100644 server/webset/.gitignore create mode 100644 server/websocket/.gitignore diff --git a/.gitignore b/.gitignore index 2f86e838..d25a14ce 100644 --- a/.gitignore +++ b/.gitignore @@ -40,20 +40,6 @@ screenlog.* proxyserver/proxyserver -server/backend/backend -server/canteen/canteen -server/data-transfer/data-transfer -server/home-user-auth/home-user-auth -server/inventory/inventory -server/map-library/map-library -server/orders/orders -server/product/product -server/product-model/product-model -server/product-template/product-template -server/shopping-cart-confirmation/shopping-cart-confirmation -server/upload/upload -server/webset/webset - shared-state *.zip \ No newline at end of file diff --git a/run_all_server.sh b/run_all_server.sh index fc8318dc..1cf70b31 100755 --- a/run_all_server.sh +++ b/run_all_server.sh @@ -15,8 +15,10 @@ run_server() { # 导航到相应的目录 cd server/$server_name + go build + echo $server_name > .gitignore # 使用 screen 运行 go run .go - screen -dmS $server_name -L go run $server_name.go + screen -dmS $server_name -L ./$server_name # 返回到上一级目录 cd - > /dev/null @@ -38,7 +40,6 @@ for server_dir in "${server_dirs[@]}"; do run_server $server_dir done - # 定义目录和screen名称 dir_path="./proxyserver" screen_name="proxyserver" diff --git a/server/auth/.gitignore b/server/auth/.gitignore new file mode 100644 index 00000000..5fa1d814 --- /dev/null +++ b/server/auth/.gitignore @@ -0,0 +1 @@ +auth diff --git a/server/base/.gitignore b/server/base/.gitignore new file mode 100644 index 00000000..df967b96 --- /dev/null +++ b/server/base/.gitignore @@ -0,0 +1 @@ +base diff --git a/server/canteen/.gitignore b/server/canteen/.gitignore new file mode 100644 index 00000000..a62359de --- /dev/null +++ b/server/canteen/.gitignore @@ -0,0 +1 @@ +canteen diff --git a/server/data-transfer/.gitignore b/server/data-transfer/.gitignore new file mode 100644 index 00000000..46f1adc6 --- /dev/null +++ b/server/data-transfer/.gitignore @@ -0,0 +1 @@ +data-transfer diff --git a/server/home-user-auth/.gitignore b/server/home-user-auth/.gitignore new file mode 100644 index 00000000..33431957 --- /dev/null +++ b/server/home-user-auth/.gitignore @@ -0,0 +1 @@ +home-user-auth diff --git a/server/info/.gitignore b/server/info/.gitignore new file mode 100644 index 00000000..55021245 --- /dev/null +++ b/server/info/.gitignore @@ -0,0 +1 @@ +info diff --git a/server/map-library/.gitignore b/server/map-library/.gitignore new file mode 100644 index 00000000..c90c25e4 --- /dev/null +++ b/server/map-library/.gitignore @@ -0,0 +1 @@ +map-library diff --git a/server/pay/.gitignore b/server/pay/.gitignore new file mode 100644 index 00000000..65847d8a --- /dev/null +++ b/server/pay/.gitignore @@ -0,0 +1 @@ +pay diff --git a/server/product-model/.gitignore b/server/product-model/.gitignore new file mode 100644 index 00000000..d4af764a --- /dev/null +++ b/server/product-model/.gitignore @@ -0,0 +1 @@ +product-model diff --git a/server/product-template-tag/.gitignore b/server/product-template-tag/.gitignore new file mode 100644 index 00000000..5e23e081 --- /dev/null +++ b/server/product-template-tag/.gitignore @@ -0,0 +1 @@ +product-template-tag diff --git a/server/product-template/.gitignore b/server/product-template/.gitignore new file mode 100644 index 00000000..636f2b18 --- /dev/null +++ b/server/product-template/.gitignore @@ -0,0 +1 @@ +product-template diff --git a/server/product/.gitignore b/server/product/.gitignore new file mode 100644 index 00000000..8954caac --- /dev/null +++ b/server/product/.gitignore @@ -0,0 +1 @@ +product diff --git a/server/resource/.gitignore b/server/resource/.gitignore new file mode 100644 index 00000000..91e75c67 --- /dev/null +++ b/server/resource/.gitignore @@ -0,0 +1 @@ +resource diff --git a/server/shopping-cart/.gitignore b/server/shopping-cart/.gitignore new file mode 100644 index 00000000..2b0ca663 --- /dev/null +++ b/server/shopping-cart/.gitignore @@ -0,0 +1 @@ +shopping-cart diff --git a/server/upload/.gitignore b/server/upload/.gitignore new file mode 100644 index 00000000..fb68e0cf --- /dev/null +++ b/server/upload/.gitignore @@ -0,0 +1 @@ +upload diff --git a/server/webset/.gitignore b/server/webset/.gitignore new file mode 100644 index 00000000..b868fc0c --- /dev/null +++ b/server/webset/.gitignore @@ -0,0 +1 @@ +webset diff --git a/server/websocket/.gitignore b/server/websocket/.gitignore new file mode 100644 index 00000000..ca4cb0cf --- /dev/null +++ b/server/websocket/.gitignore @@ -0,0 +1 @@ +websocket From dbb1591cbbc41ea2f9f32ff487f08cc343bd3b09 Mon Sep 17 00:00:00 2001 From: momo <1012651275@qq.com> Date: Tue, 19 Sep 2023 12:04:51 +0800 Subject: [PATCH 22/38] =?UTF-8?q?fix:=E5=90=88=E5=9B=BE=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../home-user-auth/internal/handler/routes.go | 5 + .../handler/userlogotemplatetagsethandler.go | 35 ++++ .../internal/logic/userlogosetlogic.go | 53 ++++- .../logic/userlogotemplatetagsetlogic.go | 187 ++++++++++++++++++ server/home-user-auth/internal/types/types.go | 6 + server/upload/etc/upload.yaml | 1 + server_api/home-user-auth.api | 12 ++ service/repositories/image_handle.go | 42 ++-- utils/basic/basic.go | 2 + utils/fssql/metadata_test.go | 8 +- utils/metadata/metadata.go | 26 ++- 11 files changed, 341 insertions(+), 36 deletions(-) create mode 100644 server/home-user-auth/internal/handler/userlogotemplatetagsethandler.go create mode 100644 server/home-user-auth/internal/logic/userlogotemplatetagsetlogic.go diff --git a/server/home-user-auth/internal/handler/routes.go b/server/home-user-auth/internal/handler/routes.go index 1116922b..6e056ad4 100644 --- a/server/home-user-auth/internal/handler/routes.go +++ b/server/home-user-auth/internal/handler/routes.go @@ -92,6 +92,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { Path: "/api/user/logo-set", Handler: UserLogoSetHandler(serverCtx), }, + { + Method: http.MethodPost, + Path: "/api/user/logo-templatetag-set", + Handler: UserLogoTemplateTagSetHandler(serverCtx), + }, }, ) } diff --git a/server/home-user-auth/internal/handler/userlogotemplatetagsethandler.go b/server/home-user-auth/internal/handler/userlogotemplatetagsethandler.go new file mode 100644 index 00000000..3c7994a8 --- /dev/null +++ b/server/home-user-auth/internal/handler/userlogotemplatetagsethandler.go @@ -0,0 +1,35 @@ +package handler + +import ( + "net/http" + "reflect" + + "fusenapi/utils/basic" + + "fusenapi/server/home-user-auth/internal/logic" + "fusenapi/server/home-user-auth/internal/svc" + "fusenapi/server/home-user-auth/internal/types" +) + +func UserLogoTemplateTagSetHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + + var req types.UserLogoTemplateTagSetReq + userinfo, err := basic.RequestParse(w, r, svcCtx, &req) + if err != nil { + return + } + + // 创建一个业务逻辑层实例 + l := logic.NewUserLogoTemplateTagSetLogic(r.Context(), svcCtx) + + rl := reflect.ValueOf(l) + basic.BeforeLogic(w, r, rl) + + resp := l.UserLogoTemplateTagSet(&req, userinfo) + + if !basic.AfterLogic(w, r, rl, resp) { + basic.NormalAfterLogic(w, r, resp) + } + } +} diff --git a/server/home-user-auth/internal/logic/userlogosetlogic.go b/server/home-user-auth/internal/logic/userlogosetlogic.go index 230b2af1..f6d4df4b 100644 --- a/server/home-user-auth/internal/logic/userlogosetlogic.go +++ b/server/home-user-auth/internal/logic/userlogosetlogic.go @@ -75,17 +75,16 @@ func (l *UserLogoSetLogic) UserLogoSet(req *types.UserLogoSetReq, userinfo *auth var nowTime = time.Now().UTC() err = l.svcCtx.MysqlConn.WithContext(l.ctx).Transaction(func(tx *gorm.DB) error { + var metadataMapOldUserMaterial map[string]interface{} + if userMaterialInfo.Metadata != nil { + err = json.Unmarshal(*userMaterialInfo.Metadata, &metadataMapOldUserMaterial) + if err != nil { + logc.Errorf(l.ctx, "userMaterialInfo Metadata Unmarshal err:%+v", err) + return err + } + } // 更新merchant_category if req.SetLogoCategory == 1 { - - var metadataMapOldUserMaterial map[string]interface{} - if userMaterialInfo.Metadata != nil { - err = json.Unmarshal(*userMaterialInfo.Metadata, &metadataMapOldUserMaterial) - if err != nil { - logc.Errorf(l.ctx, "userMaterialInfo Metadata Unmarshal err:%+v", err) - return err - } - } var metadataChildUserMaterial = make(map[string]interface{}, 1) metadataChildUserMaterial["merchant_category"] = req.CategoryId metadataMapUserMaterial, err := metadata.SetMetadata(metadataChildUserMaterial, metadataMapOldUserMaterial) @@ -137,7 +136,41 @@ func (l *UserLogoSetLogic) UserLogoSet(req *types.UserLogoSetReq, userinfo *auth } var metadataChildUserInfo = make(map[string]interface{}, 1) - metadataChildUserInfo["logo_selected_id"] = req.LogoSelectedId + + _, userInfoLogoSelectedEx := metadataMapOldUserInfo["logo_selected"] + if !userInfoLogoSelectedEx { + userMaterialTemplateTagData, userMaterialTemplateTagEx := metadataMapOldUserMaterial["template_tag"] + if !userMaterialTemplateTagEx { + logc.Errorf(l.ctx, "userMaterialInfo Metadata template_tag err:%+v", err) + return err + } + userMaterialTemplateIdTagIdData, userMaterialTemplateTagIdEx := metadataMapOldUserMaterial["template_tag_id"] + if !userMaterialTemplateTagIdEx { + logc.Errorf(l.ctx, "userMaterialInfo Metadata template_tag_id err:%+v", err) + return err + } + userMaterialTemplateIdTagIds := userMaterialTemplateIdTagIdData.([]interface{}) + + userMaterialTemplateIdTagId := userMaterialTemplateIdTagIds[0].(string) + + userMaterialTemplateTag := userMaterialTemplateTagData.(map[string]interface{}) + userMaterialTemplateTagIndex := userMaterialTemplateTag[userMaterialTemplateIdTagId] + + templateTagSelected := make(map[string]interface{}, 3) + templateTagSelected["color"] = userMaterialTemplateTagIndex + templateTagSelected["template_tag"] = userMaterialTemplateIdTagId + templateTagSelected["selected_index"] = 0 + + metadataChildUserInfo["logo_selected"] = map[string]interface{}{ + "logo_selected_id": req.LogoSelectedId, + "template_tag_selected": templateTagSelected, + } + } else { + metadataChildUserInfo["logo_selected"] = map[string]interface{}{ + "logo_selected_id": req.LogoSelectedId, + } + } + metadataMapUserInfo, err := metadata.SetMetadata(metadataChildUserInfo, metadataMapOldUserInfo) if err != nil { logc.Errorf(l.ctx, "userInfo Metadata SetMetadata err:%+v", err) diff --git a/server/home-user-auth/internal/logic/userlogotemplatetagsetlogic.go b/server/home-user-auth/internal/logic/userlogotemplatetagsetlogic.go new file mode 100644 index 00000000..59c7e3ca --- /dev/null +++ b/server/home-user-auth/internal/logic/userlogotemplatetagsetlogic.go @@ -0,0 +1,187 @@ +package logic + +import ( + "encoding/json" + "errors" + "fusenapi/model/gmodel" + "fusenapi/utils/auth" + "fusenapi/utils/basic" + "fusenapi/utils/metadata" + "time" + + "context" + + "fusenapi/server/home-user-auth/internal/svc" + "fusenapi/server/home-user-auth/internal/types" + + "github.com/zeromicro/go-zero/core/logc" + "github.com/zeromicro/go-zero/core/logx" + "gorm.io/gorm" +) + +type UserLogoTemplateTagSetLogic struct { + logx.Logger + ctx context.Context + svcCtx *svc.ServiceContext +} + +func NewUserLogoTemplateTagSetLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserLogoTemplateTagSetLogic { + return &UserLogoTemplateTagSetLogic{ + Logger: logx.WithContext(ctx), + ctx: ctx, + svcCtx: svcCtx, + } +} + +// 处理进入前逻辑w,r +// func (l *UserLogoTemplateTagSetLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) { +// } + +func (l *UserLogoTemplateTagSetLogic) UserLogoTemplateTagSet(req *types.UserLogoTemplateTagSetReq, userinfo *auth.UserInfo) (resp *basic.Response) { + // 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data) + // userinfo 传入值时, 一定不为null + if userinfo.IsOnlooker() { + // 如果是,返回未授权的错误码 + return resp.SetStatus(basic.CodeUnAuth) + } + if req.LogoSelectedId == 0 { + return resp.SetStatus(basic.CodeLogoSetTemplateErr, "logo logo_selected_id not null") + } + if req.TemplateTag == "" { + return resp.SetStatus(basic.CodeLogoSetTemplateErr, "logo template tag not null") + } + var userId int64 + var guestId int64 + NewFsUserMaterialModel := gmodel.NewFsUserMaterialModel(l.svcCtx.MysqlConn) + NewFsUserMaterialModelRow := NewFsUserMaterialModel.RowSelectBuilder(nil).Where("id = ?", req.LogoSelectedId) + + if userinfo.IsGuest() { + // 如果是,使用游客ID和游客键名格式 + guestId = userinfo.GuestId + NewFsUserMaterialModelRow.Where("guest_id = ?", guestId) + } else { + // 否则,使用用户ID和用户键名格式 + userId = userinfo.UserId + NewFsUserMaterialModelRow.Where("user_id = ?", userId) + } + + userMaterialInfo, err := NewFsUserMaterialModel.FindOne(l.ctx, NewFsUserMaterialModelRow.Model(&gmodel.FsUserMaterial{})) + if err != nil { + logc.Errorf(l.ctx, "FsUserMaterial FindOne err:%+v", err) + return resp.SetStatus(basic.CodeLogoSetCategory, "logo not find") + } + + var nowTime = time.Now().UTC() + err = l.svcCtx.MysqlConn.WithContext(l.ctx).Transaction(func(tx *gorm.DB) error { + var metadataMapOldUserMaterial map[string]interface{} + if userMaterialInfo.Metadata != nil { + err = json.Unmarshal(*userMaterialInfo.Metadata, &metadataMapOldUserMaterial) + if err != nil { + logc.Errorf(l.ctx, "userMaterialInfo Metadata Unmarshal err:%+v", err) + return err + } + } + + var module = "profile" + + var userInfo = &gmodel.FsUserInfo{} + BuilderDB := tx.Model(&gmodel.FsUserInfo{}).Where("module = ?", module) + if userId > 0 { + BuilderDB.Where("user_id=?", userId) + } else { + BuilderDB.Where("guest_id=?", guestId) + } + userInfoFirstRes := BuilderDB.First(userInfo) + err = userInfoFirstRes.Error + if err != nil { + if !errors.Is(err, gorm.ErrRecordNotFound) { + logc.Errorf(l.ctx, "userInfo First err:%+v", err) + return err + } + } + var metadataMapOldUserInfo map[string]interface{} + if userInfo.Metadata != nil { + err = json.Unmarshal(*userInfo.Metadata, &metadataMapOldUserInfo) + if err != nil { + logc.Errorf(l.ctx, "userInfo Metadata Unmarshal err:%+v", err) + return err + } + } + + var metadataChildUserInfo = make(map[string]interface{}, 1) + + _, userInfoLogoSelectedEx := metadataMapOldUserInfo["logo_selected"] + if userInfoLogoSelectedEx { + userMaterialTemplateTagData, userMaterialTemplateTagEx := metadataMapOldUserMaterial["template_tag"] + if !userMaterialTemplateTagEx { + logc.Errorf(l.ctx, "userMaterialInfo Metadata template_tag err:%+v", err) + return err + } + + userMaterialTemplateTag := userMaterialTemplateTagData.(map[string]interface{}) + userMaterialTemplateTagIndex := userMaterialTemplateTag[req.TemplateTag] + + if userMaterialTemplateTagIndex == nil { + err = errors.New("TemplateTag not find") + logc.Errorf(l.ctx, "TemplateTag not find err:%+v", err) + return err + } + + templateTagSelected := make(map[string]interface{}, 3) + templateTagSelected["color"] = userMaterialTemplateTagIndex + templateTagSelected["template_tag"] = req.TemplateTag + templateTagSelected["selected_index"] = req.TemplateTagColorIndex + + metadataChildUserInfo["logo_selected"] = map[string]interface{}{ + "template_tag_selected": templateTagSelected, + } + } + + metadataMapUserInfo, err := metadata.SetMetadata(metadataChildUserInfo, metadataMapOldUserInfo) + if err != nil { + logc.Errorf(l.ctx, "userInfo Metadata SetMetadata err:%+v", err) + return err + } + metadataBUserInfo, err := json.Marshal(metadataMapUserInfo) + if err != nil { + logc.Errorf(l.ctx, "userInfo Metadata marshal err:%+v", err) + return err + } + userInfo.Metadata = &metadataBUserInfo + + if userInfo.Id == 0 { + // 新增 + userInfo.Module = &module + userInfo.Ctime = &nowTime + userInfo.Utime = &nowTime + userInfo.UserId = &userId + userInfo.GuestId = &guestId + resCreate := tx.Model(&userInfo).Create(&userInfo) + err = resCreate.Error + } else { + // 更新 + userInfo.Utime = &nowTime + resUpdates := tx.Model(&userInfo).Select("metadata").Where("id = ?", userInfo.Id).Updates(&userInfo) + err = resUpdates.Error + } + + if err != nil { + if err != gorm.ErrRecordNotFound { + logc.Errorf(l.ctx, "FsUserInfo Updates err:%+v", err) + return err + } + } + + return nil + }) + if err != nil { + logx.Error(err) + return resp.SetStatus(basic.CodeDbSqlErr, "set logo fail") + } + return resp.SetStatus(basic.CodeOK) +} + +// 处理逻辑后 w,r 如:重定向, resp 必须重新处理 +// func (l *UserLogoTemplateTagSetLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) { +// // httpx.OkJsonCtx(r.Context(), w, resp) +// } diff --git a/server/home-user-auth/internal/types/types.go b/server/home-user-auth/internal/types/types.go index 0ec0cfaa..1c049a7e 100644 --- a/server/home-user-auth/internal/types/types.go +++ b/server/home-user-auth/internal/types/types.go @@ -5,6 +5,12 @@ import ( "fusenapi/utils/basic" ) +type UserLogoTemplateTagSetReq struct { + LogoSelectedId int64 `form:"logo_selected_id"` + TemplateTag string `form:"template_tag"` + TemplateTagColorIndex int64 `form:"template_tag_color_index"` +} + type UserLogoSetReq struct { SetLogoSelected int64 `form:"set_logo_selected"` LogoSelectedId int64 `form:"logo_selected_id"` diff --git a/server/upload/etc/upload.yaml b/server/upload/etc/upload.yaml index b8596b53..36922560 100644 --- a/server/upload/etc/upload.yaml +++ b/server/upload/etc/upload.yaml @@ -20,6 +20,7 @@ AWS: Token: BLMService: Url: "http://18.119.109.254:8999" + # Url: "http://192.168.1.9:8999" ImageProcess: # Url: "http://192.168.1.7:8999/FeatureExtraction" Url: "http://18.119.109.254:8999/FeatureExtraction" diff --git a/server_api/home-user-auth.api b/server_api/home-user-auth.api index 2b030c28..27d9f03e 100644 --- a/server_api/home-user-auth.api +++ b/server_api/home-user-auth.api @@ -71,8 +71,20 @@ service home-user-auth { // 用户logo设置当前 @handler UserLogoSetHandler post /api/user/logo-set (UserLogoSetReq) returns (response); + + // 用户logo模版信息 + @handler UserLogoTemplateTagSetHandler + post /api/user/logo-templatetag-set (UserLogoTemplateTagSetReq) returns (response); } +type ( + UserLogoTemplateTagSetReq { + LogoSelectedId int64 `form:"logo_selected_id"` + TemplateTag string `form:"template_tag"` + TemplateTagColorIndex int64 `form:"template_tag_color_index"` + } +) + type ( UserLogoSetReq { SetLogoSelected int64 `form:"set_logo_selected"` diff --git a/service/repositories/image_handle.go b/service/repositories/image_handle.go index a18c70de..fe8e486c 100644 --- a/service/repositories/image_handle.go +++ b/service/repositories/image_handle.go @@ -54,8 +54,16 @@ type ( GuestId int64 `json:"guest_id"` } LogoInfoRes struct { - Metadata *string `json:"metadata"` - LogoUrl *string `json:"logo_url"` + Metadata *string `json:"metadata"` + LogoUrl *string `json:"logo_url"` + LogoSelected struct { + TemplateTagSelected *struct { + Color [][]string `json:"color"` + TemplateTag string `json:"template_tag"` + SelectedIndex int64 `json:"selected_index"` + } `json:"template_tag_selected"` + LogoSelectedId int64 `json:"logo_selected_id"` + } `json:"logo_selected"` } ) @@ -84,28 +92,36 @@ func (l *defaultImageHandle) LogoInfo(ctx context.Context, in *LogoInfoReq) (*Lo } var userMaterialInfo gmodel.FsUserMaterial userMaterialModel := gmodel.NewFsUserMaterialModel(l.MysqlConn) - + var metadataUserInfo struct { + LogoSelected struct { + TemplateTagSelected *struct { + Color [][]string `json:"color"` + TemplateTag string `json:"template_tag"` + SelectedIndex int64 `json:"selected_index"` + } `json:"template_tag_selected"` + LogoSelectedId int64 `json:"logo_selected_id"` + } `json:"logo_selected"` + } if userInfo.Id == 0 { userMaterialInfo, err = userMaterialModel.FindLatestOne(ctx, in.UserId, in.GuestId) if err != gorm.ErrRecordNotFound { logc.Errorf(ctx, "FsUserMaterial FindLatestOne err:%+v", err) return nil, err } + // var userMaterialInfoMetadata map[string]interface{} } else { if userInfo.Metadata != nil { - var metadata map[string]interface{} - err = json.Unmarshal([]byte(*userInfo.Metadata), &metadata) + err = json.Unmarshal([]byte(*userInfo.Metadata), &metadataUserInfo) if err != nil { logc.Errorf(ctx, "userInfo.Metadata Unmarshal err:%+v", err) return nil, err } - logoSelectedId, isEx := metadata["logo_selected_id"] - if isEx { - var materialId int64 = int64(logoSelectedId.(float64)) - userMaterialInfos, err := userMaterialModel.FindOneById(ctx, materialId) + + if metadataUserInfo.LogoSelected.LogoSelectedId != 0 { + userMaterialInfos, err := userMaterialModel.FindOneById(ctx, metadataUserInfo.LogoSelected.LogoSelectedId) if err != nil { if err != gorm.ErrRecordNotFound { - logc.Errorf(ctx, "FsUserInfo First err:%+v", err) + logc.Errorf(ctx, "userMaterial findOneById err:%+v", err) return nil, err } } @@ -134,8 +150,9 @@ func (l *defaultImageHandle) LogoInfo(ctx context.Context, in *LogoInfoReq) (*Lo logoUrl = userMaterialInfo.ResourceUrl } return &LogoInfoRes{ - Metadata: metadata, - LogoUrl: logoUrl, + Metadata: metadata, + LogoUrl: logoUrl, + LogoSelected: metadataUserInfo.LogoSelected, }, nil } @@ -302,6 +319,7 @@ func (l *defaultImageHandle) LogoCombine(ctx context.Context, in *LogoCombineReq combineParam["phone"] = in.Phone combineParam["address"] = in.Address combineParam["qrcode"] = in.Qrcode + combineParam["template_tag_selected"] = resLogoInfo.LogoSelected var postMap = make(map[string]interface{}, 2) postMap["module_data"] = moduleDataMap diff --git a/utils/basic/basic.go b/utils/basic/basic.go index 795f04ba..54efa272 100644 --- a/utils/basic/basic.go +++ b/utils/basic/basic.go @@ -99,6 +99,8 @@ var ( CodeLogoCombineErr = &StatusResponse{5115, "logo combine fail"} // 合图失败 CodeLogoCombineNoFoundErr = &StatusResponse{5116, "template record not found"} // 模版不存在 + + CodeLogoSetTemplateErr = &StatusResponse{5117, "logo set template fail"} // 设置模版标签失败 ) type Response struct { diff --git a/utils/fssql/metadata_test.go b/utils/fssql/metadata_test.go index 4c12011d..7cdf3e54 100644 --- a/utils/fssql/metadata_test.go +++ b/utils/fssql/metadata_test.go @@ -14,15 +14,9 @@ func TestCase1(t *testing.T) { } conn := initalize.InitMysql("fsreaderwriter:XErSYmLELKMnf3Dh@tcp(fusen.cdmigcvz3rle.us-east-2.rds.amazonaws.com:3306)/fusen") - err := fssql.MetadataModulePATCH(conn, "logo", gmodel.FsChangeCode{}, u, "id = ?", 6) + err := fssql.MetadataModulePATCH(conn, "profile", gmodel.FsUserInfo{}, u, "id = ?", 90) if err != nil { panic(err) } - err = fssql.MetadataResourcePATCH(conn, - "f8932c0379fa5aa3397dc0a963696ca90536cc273ea10119b0137fd15ecfe673", u) - - if err != nil { - panic(err) - } } diff --git a/utils/metadata/metadata.go b/utils/metadata/metadata.go index 19855260..b7cd4abf 100644 --- a/utils/metadata/metadata.go +++ b/utils/metadata/metadata.go @@ -5,9 +5,15 @@ func SetMetadata(metadataChild map[string]interface{}, oldMetadata map[string]in for k, v := range metadataChild { switch val := v.(type) { case map[string]interface{}: - oldResourceMetadataData := oldMetadata[k].(map[string]interface{}) - for key, val1 := range val { - oldResourceMetadataData[key] = val1 + kValue, kEx := oldMetadata[k] + var oldResourceMetadataData map[string]interface{} + if kEx { + oldResourceMetadataData = kValue.(map[string]interface{}) + } else { + oldResourceMetadataData = make(map[string]interface{}, len(val)) + } + for key1, val1 := range val { + oldResourceMetadataData[key1] = val1 } oldMetadata[k] = oldResourceMetadataData default: @@ -20,11 +26,17 @@ func SetMetadata(metadataChild map[string]interface{}, oldMetadata map[string]in for k, v := range metadataChild { switch val := v.(type) { case map[string]interface{}: - var resourceMetadataData = make(map[string]interface{}, len(val)) - for key, val1 := range val { - resourceMetadataData[key] = val1 + kValue, kEx := oldMetadata[k] + var oldResourceMetadataData map[string]interface{} + if kEx { + oldResourceMetadataData = kValue.(map[string]interface{}) + } else { + oldResourceMetadataData = make(map[string]interface{}, len(val)) } - oldMetadata[k] = resourceMetadataData + for key, val1 := range val { + oldResourceMetadataData[key] = val1 + } + oldMetadata[k] = oldResourceMetadataData default: oldMetadata[k] = val } From b19a16e5a0802fe3aff12bf7ae55739883841d1a Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Tue, 19 Sep 2023 14:06:54 +0800 Subject: [PATCH 23/38] =?UTF-8?q?=E5=90=88=E5=B9=B6develop?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../logic/getproducttemplatetagslogic.go | 19 +++++++++++-------- .../internal/types/types.go | 13 +++++++------ server_api/product-template-tag.api | 13 +++++++------ 3 files changed, 25 insertions(+), 20 deletions(-) diff --git a/server/product-template-tag/internal/logic/getproducttemplatetagslogic.go b/server/product-template-tag/internal/logic/getproducttemplatetagslogic.go index 828f3ab5..c9c30a7d 100644 --- a/server/product-template-tag/internal/logic/getproducttemplatetagslogic.go +++ b/server/product-template-tag/internal/logic/getproducttemplatetagslogic.go @@ -125,22 +125,25 @@ func (l *GetProductTemplateTagsLogic) GetProductTemplateTags(req *types.GetProdu list := make([]types.GetProductTemplateTagsRsp, 0, len(productTemplateTags)) for _, templateInfo := range productTemplateTags { colors := make([]types.ColorsItem, 0, 10) - SelectedIndex := 0 + SelectedColorIndex := 0 + isDefaultTemplateTag := false for _, colorsSet := range mapTemplateTag[*templateInfo.TemplateTag] { if selectIndex, ok := mapSelectColor[*templateInfo.TemplateTag]; ok { - SelectedIndex = selectIndex + isDefaultTemplateTag = true + SelectedColorIndex = selectIndex } colors = append(colors, types.ColorsItem{ Color: colorsSet, }) } list = append(list, types.GetProductTemplateTagsRsp{ - Id: templateInfo.Id, - TemplateTag: *templateInfo.TemplateTag, - Cover: *templateInfo.Cover, - CoverMetadata: mapResourceMetadata[*templateInfo.Cover], - Colors: colors, - SelectedIndex: SelectedIndex, + Id: templateInfo.Id, + TemplateTag: *templateInfo.TemplateTag, + IsDefaultTemplateTag: isDefaultTemplateTag, + Cover: *templateInfo.Cover, + CoverMetadata: mapResourceMetadata[*templateInfo.Cover], + Colors: colors, + SelectedColorIndex: SelectedColorIndex, }) } return resp.SetStatusWithMessage(basic.CodeOK, "success", list) diff --git a/server/product-template-tag/internal/types/types.go b/server/product-template-tag/internal/types/types.go index 7474e8da..037e6966 100644 --- a/server/product-template-tag/internal/types/types.go +++ b/server/product-template-tag/internal/types/types.go @@ -10,12 +10,13 @@ type GetProductTemplateTagsReq struct { } type GetProductTemplateTagsRsp struct { - Id int64 `json:"id"` - TemplateTag string `json:"template_tag"` - Cover string `json:"cover"` - CoverMetadata interface{} `json:"cover_metadata"` - Colors []ColorsItem `json:"colors"` - SelectedIndex int `json:"selected_index"` + Id int64 `json:"id"` + TemplateTag string `json:"template_tag"` + IsDefaultTemplateTag bool `json:"is_default_template_tag"` + Cover string `json:"cover"` + CoverMetadata interface{} `json:"cover_metadata"` + Colors []ColorsItem `json:"colors"` + SelectedColorIndex int `json:"selected_color_index"` } type ColorsItem struct { diff --git a/server_api/product-template-tag.api b/server_api/product-template-tag.api index 6c88a573..ab06b272 100644 --- a/server_api/product-template-tag.api +++ b/server_api/product-template-tag.api @@ -20,12 +20,13 @@ type GetProductTemplateTagsReq { Limit int `form:"limit"` } type GetProductTemplateTagsRsp { - Id int64 `json:"id"` - TemplateTag string `json:"template_tag"` - Cover string `json:"cover"` - CoverMetadata interface{} `json:"cover_metadata"` - Colors []ColorsItem `json:"colors"` - SelectedIndex int `json:"selected_index"` + Id int64 `json:"id"` + TemplateTag string `json:"template_tag"` + IsDefaultTemplateTag bool `json:"is_default_template_tag"` + Cover string `json:"cover"` + CoverMetadata interface{} `json:"cover_metadata"` + Colors []ColorsItem `json:"colors"` + SelectedColorIndex int `json:"selected_color_index"` } type ColorsItem { Color []string `json:"color"` From 25b7334c308a0ba1cf8ded6a88c06eb792537d2b Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Tue, 19 Sep 2023 14:39:33 +0800 Subject: [PATCH 24/38] =?UTF-8?q?=E5=90=88=E5=B9=B6develop?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../internal/logic/ws_render_image.go | 15 ++++++++- service/repositories/image_handle.go | 32 ++++++++++++------- utils/websocket_data/render_data.go | 27 +++++++++------- 3 files changed, 50 insertions(+), 24 deletions(-) diff --git a/server/websocket/internal/logic/ws_render_image.go b/server/websocket/internal/logic/ws_render_image.go index a8f86d2f..5a20f57d 100644 --- a/server/websocket/internal/logic/ws_render_image.go +++ b/server/websocket/internal/logic/ws_render_image.go @@ -100,6 +100,15 @@ func (w *wsConnectItem) renderImage(data []byte) { logx.Error("invalid format of websocket render image message", err) return } + lenColor := len(renderImageData.RenderData.TemplateTagColor.Color) + if lenColor == 0 { + w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "请传入模板标签选择的颜色", renderImageData.RenderData.ProductId, w.userId, w.guestId, 0, 0, 0, 0) + return + } + if renderImageData.RenderData.TemplateTagColor.SelectedIndex >= lenColor || renderImageData.RenderData.TemplateTagColor.SelectedIndex < 0 { + w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "选择的模板标签颜色索引越界", renderImageData.RenderData.ProductId, w.userId, w.guestId, 0, 0, 0, 0) + return + } //获取产品信息(部分字段) productInfo, err := w.logic.svcCtx.AllModels.FsProduct.FindOne(w.logic.ctx, renderImageData.RenderData.ProductId, "id,is_customization") if err != nil { @@ -192,6 +201,10 @@ func (w *wsConnectItem) renderImage(data []byte) { Phone: renderImageData.RenderData.Phone, Qrcode: renderImageData.RenderData.Qrcode, LogoUrl: renderImageData.RenderData.Logo, + TemplateTagColor: repositories.TemplateTagColor{ + Color: renderImageData.RenderData.TemplateTagColor.Color, + Index: renderImageData.RenderData.TemplateTagColor.SelectedIndex, + }, } res, err := w.logic.svcCtx.Repositories.ImageHandle.LogoCombine(w.logic.ctx, &combineReq) if err != nil { @@ -216,7 +229,7 @@ func (w *wsConnectItem) renderImage(data []byte) { } //获取唯一id taskId := w.genRenderTaskId(combineImage, renderImageData, model3dInfo, productTemplate, element) - //查询有没有缓存的资源,有就返回###################### + //查询有没有缓存的资源,有就返回 resource, err := w.logic.svcCtx.AllModels.FsResource.FindOneById(w.logic.ctx, taskId) if err != nil { if !errors.Is(err, gorm.ErrRecordNotFound) { diff --git a/service/repositories/image_handle.go b/service/repositories/image_handle.go index 642f590d..540292fa 100644 --- a/service/repositories/image_handle.go +++ b/service/repositories/image_handle.go @@ -187,16 +187,17 @@ func (l *defaultImageHandle) LogoInfoSet(ctx context.Context, in *LogoInfoSetReq /* logo合图 */ type ( LogoCombineReq struct { - UserId int64 `json:"user_id"` - GuestId int64 `json:"guest_id"` - TemplateId int64 `json:"template_id"` - TemplateTag string `json:"template_tag"` - Website string `json:"website"` // 合图参数 - Slogan string `json:"slogan"` // 合图参数 - Address string `json:"address"` // 合图参数 - Phone string `json:"phone"` // 合图参数 - Qrcode string `json:"qrcode"` // 合图参数 - LogoUrl string `json:"logo_url"` // 合图参数 + UserId int64 `json:"user_id"` + GuestId int64 `json:"guest_id"` + TemplateId int64 `json:"template_id"` + TemplateTag string `json:"template_tag"` + Website string `json:"website"` // 合图参数 + Slogan string `json:"slogan"` // 合图参数 + Address string `json:"address"` // 合图参数 + Phone string `json:"phone"` // 合图参数 + Qrcode string `json:"qrcode"` // 合图参数 + LogoUrl string `json:"logo_url"` // 合图参数 + TemplateTagColor TemplateTagColor `json:"template_tag_color"` } LogoCombineRes struct { ResourceId string @@ -206,6 +207,10 @@ type ( DiffTimeUploadFile int64 } ) +type TemplateTagColor struct { + Color [][]string `json:"color"` + Index int `json:"index"` +} func (l *defaultImageHandle) LogoCombine(ctx context.Context, in *LogoCombineReq) (*LogoCombineRes, error) { // 查询logo最新基础信息 @@ -308,8 +313,11 @@ func (l *defaultImageHandle) LogoCombine(ctx context.Context, in *LogoCombineReq combineParam["phone"] = in.Phone combineParam["address"] = in.Address combineParam["qrcode"] = in.Qrcode - //combineParam["template_tag_selected"] = - + combineParam["template_tag_selected"] = map[string]interface{}{ + "template_tag": in.TemplateTag, + "color": in.TemplateTagColor.Color, + "index": in.TemplateTagColor.Index, + } var postMap = make(map[string]interface{}, 2) postMap["module_data"] = moduleDataMap postMap["tag_data"] = tagDataMap diff --git a/utils/websocket_data/render_data.go b/utils/websocket_data/render_data.go index 16f3326b..d79032d5 100644 --- a/utils/websocket_data/render_data.go +++ b/utils/websocket_data/render_data.go @@ -15,17 +15,22 @@ type RenderImageReqMsg struct { RenderData RenderData `json:"render_data"` } type RenderData struct { - TemplateTag string `json:"template_tag"` //模板标签(必须) - ProductId int64 `json:"product_id"` //产品id(必须) - Website string `json:"website"` //网站(可选) - Slogan string `json:"slogan"` //slogan(可选) - Address string `json:"address"` //地址(可选) - Phone string `json:"phone"` //电话(可选) - Qrcode string `json:"qrcode"` //二维码(可选) - ProductSizeId int64 `json:"product_size_id"` //尺寸id(可选) - UserId int64 `json:"user_id"` //用户id(websocket连接建立再赋值) - GuestId int64 `json:"guest_id"` //游客id(websocket连接建立再赋值) - Logo string `json:"logo"` //log资源地址(websocket连接建立再赋值) + TemplateTag string `json:"template_tag"` //模板标签(必须) + TemplateTagColor TemplateTagColor `json:"template_tag_color"` //模板标签组合颜色 + ProductId int64 `json:"product_id"` //产品id(必须) + Website string `json:"website"` //网站(可选) + Slogan string `json:"slogan"` //slogan(可选) + Address string `json:"address"` //地址(可选) + Phone string `json:"phone"` //电话(可选) + Qrcode string `json:"qrcode"` //二维码(可选) + ProductSizeId int64 `json:"product_size_id"` //尺寸id(可选) + UserId int64 `json:"user_id"` //用户id(websocket连接建立再赋值) + GuestId int64 `json:"guest_id"` //游客id(websocket连接建立再赋值) + Logo string `json:"logo"` //log资源地址(websocket连接建立再赋值) +} +type TemplateTagColor struct { + Color [][]string `json:"color"` //颜色组合 + SelectedIndex int `json:"selected_index"` //主色的下标索引 } // websocket发送渲染完的数据 From 640560acf6efedd259c8b0970b4007fe98709268 Mon Sep 17 00:00:00 2001 From: momo <1012651275@qq.com> Date: Tue, 19 Sep 2023 14:50:54 +0800 Subject: [PATCH 25/38] =?UTF-8?q?fix:=E5=90=88=E5=9B=BE=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../internal/logic/userlogosetlogic.go | 49 ++++++++----------- service/repositories/image_handle.go | 9 ++-- 2 files changed, 25 insertions(+), 33 deletions(-) diff --git a/server/home-user-auth/internal/logic/userlogosetlogic.go b/server/home-user-auth/internal/logic/userlogosetlogic.go index f6d4df4b..ee6ec9f1 100644 --- a/server/home-user-auth/internal/logic/userlogosetlogic.go +++ b/server/home-user-auth/internal/logic/userlogosetlogic.go @@ -137,38 +137,31 @@ func (l *UserLogoSetLogic) UserLogoSet(req *types.UserLogoSetReq, userinfo *auth var metadataChildUserInfo = make(map[string]interface{}, 1) - _, userInfoLogoSelectedEx := metadataMapOldUserInfo["logo_selected"] - if !userInfoLogoSelectedEx { - userMaterialTemplateTagData, userMaterialTemplateTagEx := metadataMapOldUserMaterial["template_tag"] - if !userMaterialTemplateTagEx { - logc.Errorf(l.ctx, "userMaterialInfo Metadata template_tag err:%+v", err) - return err - } - userMaterialTemplateIdTagIdData, userMaterialTemplateTagIdEx := metadataMapOldUserMaterial["template_tag_id"] - if !userMaterialTemplateTagIdEx { - logc.Errorf(l.ctx, "userMaterialInfo Metadata template_tag_id err:%+v", err) - return err - } - userMaterialTemplateIdTagIds := userMaterialTemplateIdTagIdData.([]interface{}) + userMaterialTemplateTagData, userMaterialTemplateTagEx := metadataMapOldUserMaterial["template_tag"] + if !userMaterialTemplateTagEx { + logc.Errorf(l.ctx, "userMaterialInfo Metadata template_tag err:%+v", err) + return err + } + userMaterialTemplateIdTagIdData, userMaterialTemplateTagIdEx := metadataMapOldUserMaterial["template_tag_id"] + if !userMaterialTemplateTagIdEx { + logc.Errorf(l.ctx, "userMaterialInfo Metadata template_tag_id err:%+v", err) + return err + } + userMaterialTemplateIdTagIds := userMaterialTemplateIdTagIdData.([]interface{}) - userMaterialTemplateIdTagId := userMaterialTemplateIdTagIds[0].(string) + userMaterialTemplateIdTagId := userMaterialTemplateIdTagIds[0].(string) - userMaterialTemplateTag := userMaterialTemplateTagData.(map[string]interface{}) - userMaterialTemplateTagIndex := userMaterialTemplateTag[userMaterialTemplateIdTagId] + userMaterialTemplateTag := userMaterialTemplateTagData.(map[string]interface{}) + userMaterialTemplateTagIndex := userMaterialTemplateTag[userMaterialTemplateIdTagId] - templateTagSelected := make(map[string]interface{}, 3) - templateTagSelected["color"] = userMaterialTemplateTagIndex - templateTagSelected["template_tag"] = userMaterialTemplateIdTagId - templateTagSelected["selected_index"] = 0 + templateTagSelected := make(map[string]interface{}, 3) + templateTagSelected["color"] = userMaterialTemplateTagIndex + templateTagSelected["template_tag"] = userMaterialTemplateIdTagId + templateTagSelected["selected_index"] = 0 - metadataChildUserInfo["logo_selected"] = map[string]interface{}{ - "logo_selected_id": req.LogoSelectedId, - "template_tag_selected": templateTagSelected, - } - } else { - metadataChildUserInfo["logo_selected"] = map[string]interface{}{ - "logo_selected_id": req.LogoSelectedId, - } + metadataChildUserInfo["logo_selected"] = map[string]interface{}{ + "logo_selected_id": req.LogoSelectedId, + "template_tag_selected": templateTagSelected, } metadataMapUserInfo, err := metadata.SetMetadata(metadataChildUserInfo, metadataMapOldUserInfo) diff --git a/service/repositories/image_handle.go b/service/repositories/image_handle.go index fe8e486c..4dd94fd7 100644 --- a/service/repositories/image_handle.go +++ b/service/repositories/image_handle.go @@ -102,13 +102,13 @@ func (l *defaultImageHandle) LogoInfo(ctx context.Context, in *LogoInfoReq) (*Lo LogoSelectedId int64 `json:"logo_selected_id"` } `json:"logo_selected"` } + userInfo.Id = 0 if userInfo.Id == 0 { userMaterialInfo, err = userMaterialModel.FindLatestOne(ctx, in.UserId, in.GuestId) - if err != gorm.ErrRecordNotFound { + if err != nil && err != gorm.ErrRecordNotFound { logc.Errorf(ctx, "FsUserMaterial FindLatestOne err:%+v", err) return nil, err } - // var userMaterialInfoMetadata map[string]interface{} } else { if userInfo.Metadata != nil { err = json.Unmarshal([]byte(*userInfo.Metadata), &metadataUserInfo) @@ -150,9 +150,8 @@ func (l *defaultImageHandle) LogoInfo(ctx context.Context, in *LogoInfoReq) (*Lo logoUrl = userMaterialInfo.ResourceUrl } return &LogoInfoRes{ - Metadata: metadata, - LogoUrl: logoUrl, - LogoSelected: metadataUserInfo.LogoSelected, + Metadata: metadata, + LogoUrl: logoUrl, }, nil } From 55e1e5cb47ec9b1784e58f2feb3a01bc006c0a1b Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Tue, 19 Sep 2023 15:09:48 +0800 Subject: [PATCH 26/38] 11 --- .../internal/logic/ws_render_image.go | 32 ++++++++------- service/repositories/image_handle.go | 39 +++++++------------ 2 files changed, 33 insertions(+), 38 deletions(-) diff --git a/server/websocket/internal/logic/ws_render_image.go b/server/websocket/internal/logic/ws_render_image.go index 5a20f57d..5b6789be 100644 --- a/server/websocket/internal/logic/ws_render_image.go +++ b/server/websocket/internal/logic/ws_render_image.go @@ -100,6 +100,10 @@ func (w *wsConnectItem) renderImage(data []byte) { logx.Error("invalid format of websocket render image message", err) return } + if renderImageData.RenderData.Logo == "" { + w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "请传入logo", renderImageData.RenderData.ProductId, w.userId, w.guestId, 0, 0, 0, 0) + return + } lenColor := len(renderImageData.RenderData.TemplateTagColor.Color) if lenColor == 0 { w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "请传入模板标签选择的颜色", renderImageData.RenderData.ProductId, w.userId, w.guestId, 0, 0, 0, 0) @@ -126,7 +130,7 @@ func (w *wsConnectItem) renderImage(data []byte) { return } //获取用户需要渲染logo - logoInfo, err := w.logic.svcCtx.Repositories.ImageHandle.LogoInfo(w.logic.ctx, &repositories.LogoInfoReq{ + /*logoInfo, err := w.logic.svcCtx.Repositories.ImageHandle.LogoInfo(w.logic.ctx, &repositories.LogoInfoReq{ UserId: w.userId, GuestId: w.guestId, }) @@ -139,7 +143,7 @@ func (w *wsConnectItem) renderImage(data []byte) { w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "用户logo素材url是空的", renderImageData.RenderData.ProductId, w.userId, w.guestId, 0, 0, 0, 0) return } - renderImageData.RenderData.Logo = *logoInfo.LogoUrl + renderImageData.RenderData.Logo = *logoInfo.LogoUrl*/ //用户id赋值 renderImageData.RenderData.UserId = w.userId renderImageData.RenderData.GuestId = w.guestId @@ -171,7 +175,7 @@ func (w *wsConnectItem) renderImage(data []byte) { return } //获取模板开关信息并且对于没有默认值的给赋值默认值(但凡DIY有一个是空的就要请求默认数据) - if renderImageData.RenderData.Website == "" || renderImageData.RenderData.Phone == "" || renderImageData.RenderData.Address == "" || renderImageData.RenderData.Qrcode == "" || renderImageData.RenderData.Slogan == "" { + /*if renderImageData.RenderData.Website == "" || renderImageData.RenderData.Phone == "" || renderImageData.RenderData.Address == "" || renderImageData.RenderData.Qrcode == "" || renderImageData.RenderData.Slogan == "" { templateSwitchInfo := template_switch_info.GetTemplateSwitchInfo(productTemplate.Id, productTemplate.TemplateInfo, *productTemplate.MaterialImg) if renderImageData.RenderData.Website == "" && templateSwitchInfo.MaterialData.Website.IfShow { renderImageData.RenderData.Website = templateSwitchInfo.MaterialData.Website.DefaultValue @@ -188,19 +192,19 @@ func (w *wsConnectItem) renderImage(data []byte) { if renderImageData.RenderData.Slogan == "" && templateSwitchInfo.MaterialData.Slogan.IfShow { renderImageData.RenderData.Slogan = templateSwitchInfo.MaterialData.Slogan.DefaultValue } - } + }*/ //获取刀版图 combineReq := repositories.LogoCombineReq{ - UserId: renderImageData.RenderData.UserId, - GuestId: renderImageData.RenderData.GuestId, - TemplateId: productTemplate.Id, - TemplateTag: renderImageData.RenderData.TemplateTag, - Website: renderImageData.RenderData.Website, - Slogan: renderImageData.RenderData.Slogan, - Address: renderImageData.RenderData.Address, - Phone: renderImageData.RenderData.Phone, - Qrcode: renderImageData.RenderData.Qrcode, - LogoUrl: renderImageData.RenderData.Logo, + UserId: renderImageData.RenderData.UserId, + GuestId: renderImageData.RenderData.GuestId, + ProductTemplateV2Info: productTemplate, + TemplateTag: renderImageData.RenderData.TemplateTag, + Website: renderImageData.RenderData.Website, + Slogan: renderImageData.RenderData.Slogan, + Address: renderImageData.RenderData.Address, + Phone: renderImageData.RenderData.Phone, + Qrcode: renderImageData.RenderData.Qrcode, + LogoUrl: renderImageData.RenderData.Logo, TemplateTagColor: repositories.TemplateTagColor{ Color: renderImageData.RenderData.TemplateTagColor.Color, Index: renderImageData.RenderData.TemplateTagColor.SelectedIndex, diff --git a/service/repositories/image_handle.go b/service/repositories/image_handle.go index 134c3b67..08970857 100644 --- a/service/repositories/image_handle.go +++ b/service/repositories/image_handle.go @@ -195,17 +195,17 @@ func (l *defaultImageHandle) LogoInfoSet(ctx context.Context, in *LogoInfoSetReq /* logo合图 */ type ( LogoCombineReq struct { - UserId int64 `json:"user_id"` - GuestId int64 `json:"guest_id"` - TemplateId int64 `json:"template_id"` - TemplateTag string `json:"template_tag"` - Website string `json:"website"` // 合图参数 - Slogan string `json:"slogan"` // 合图参数 - Address string `json:"address"` // 合图参数 - Phone string `json:"phone"` // 合图参数 - Qrcode string `json:"qrcode"` // 合图参数 - LogoUrl string `json:"logo_url"` // 合图参数 - TemplateTagColor TemplateTagColor `json:"template_tag_color"` + UserId int64 `json:"user_id"` + GuestId int64 `json:"guest_id"` + ProductTemplateV2Info *gmodel.FsProductTemplateV2 `json:"product_template_v_2_info"` + TemplateTag string `json:"template_tag"` + Website string `json:"website"` // 合图参数 + Slogan string `json:"slogan"` // 合图参数 + Address string `json:"address"` // 合图参数 + Phone string `json:"phone"` // 合图参数 + Qrcode string `json:"qrcode"` // 合图参数 + LogoUrl string `json:"logo_url"` // 合图参数 + TemplateTagColor TemplateTagColor `json:"template_tag_color"` //合图颜色 } LogoCombineRes struct { ResourceId string @@ -257,15 +257,6 @@ func (l *defaultImageHandle) LogoCombine(ctx context.Context, in *LogoCombineReq } } - // 没有查到,先根据模版id 查询模版数据 请求算法数据 - productTemplateV2Model := gmodel.NewFsProductTemplateV2Model(l.MysqlConn) - productTemplateV2Info, err := productTemplateV2Model.FindOne(ctx, in.TemplateId) - - if err != nil { - logc.Errorf(ctx, "productTemplateV2Model.FindOne:%v", err) - return nil, err - } - productTemplateTagInfo, err := gmodel.NewFsProductTemplateTagsModel(l.MysqlConn).FindOneByTagName(ctx, in.TemplateTag, "groups") if err != nil { @@ -275,9 +266,9 @@ func (l *defaultImageHandle) LogoCombine(ctx context.Context, in *LogoCombineReq var groupOptions map[string]interface{} var materialList []interface{} - if productTemplateV2Info.TemplateInfo != nil { + if in.ProductTemplateV2Info.TemplateInfo != nil { var templateInfo map[string]interface{} - err = json.Unmarshal([]byte(*productTemplateV2Info.TemplateInfo), &templateInfo) + err = json.Unmarshal([]byte(*in.ProductTemplateV2Info.TemplateInfo), &templateInfo) if err != nil { logx.Error(err) @@ -301,8 +292,8 @@ func (l *defaultImageHandle) LogoCombine(ctx context.Context, in *LogoCombineReq } var moduleDataMap = make(map[string]interface{}, 4) - moduleDataMap["id"] = productTemplateV2Info.Id - moduleDataMap["material"] = productTemplateV2Info.MaterialImg + moduleDataMap["id"] = in.ProductTemplateV2Info.Id + moduleDataMap["material"] = in.ProductTemplateV2Info.MaterialImg moduleDataMap["groupOptions"] = groupOptions moduleDataMap["materialList"] = materialList From 9c8f37c43cd421bccf6c2294885b04963bfc36d3 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Tue, 19 Sep 2023 15:10:44 +0800 Subject: [PATCH 27/38] 11 --- service/repositories/image_handle.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/service/repositories/image_handle.go b/service/repositories/image_handle.go index 08970857..6fc53b36 100644 --- a/service/repositories/image_handle.go +++ b/service/repositories/image_handle.go @@ -197,7 +197,7 @@ type ( LogoCombineReq struct { UserId int64 `json:"user_id"` GuestId int64 `json:"guest_id"` - ProductTemplateV2Info *gmodel.FsProductTemplateV2 `json:"product_template_v_2_info"` + ProductTemplateV2Info *gmodel.FsProductTemplateV2 `json:"product_template_v2_info"` TemplateTag string `json:"template_tag"` Website string `json:"website"` // 合图参数 Slogan string `json:"slogan"` // 合图参数 From 720a9ab78ba9a5f075ba93eb22121086b5c2a040 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Tue, 19 Sep 2023 15:34:52 +0800 Subject: [PATCH 28/38] 11 --- .../internal/logic/getproducttemplatetagslogic.go | 8 ++++++++ server/product-template-tag/internal/types/types.go | 1 + server_api/product-template-tag.api | 1 + 3 files changed, 10 insertions(+) diff --git a/server/product-template-tag/internal/logic/getproducttemplatetagslogic.go b/server/product-template-tag/internal/logic/getproducttemplatetagslogic.go index c9c30a7d..cd43c5af 100644 --- a/server/product-template-tag/internal/logic/getproducttemplatetagslogic.go +++ b/server/product-template-tag/internal/logic/getproducttemplatetagslogic.go @@ -136,10 +136,18 @@ func (l *GetProductTemplateTagsLogic) GetProductTemplateTags(req *types.GetProdu Color: colorsSet, }) } + var templateTagGroups interface{} + if templateInfo.Groups != nil && *templateInfo.Groups != "" { + if err = json.Unmarshal([]byte(*templateInfo.Groups), &templateTagGroups); err != nil { + logx.Error(err) + return resp.SetStatusWithMessage(basic.CodeJsonErr, "failed to parse groups") + } + } list = append(list, types.GetProductTemplateTagsRsp{ Id: templateInfo.Id, TemplateTag: *templateInfo.TemplateTag, IsDefaultTemplateTag: isDefaultTemplateTag, + TemplateTagGroups: templateTagGroups, Cover: *templateInfo.Cover, CoverMetadata: mapResourceMetadata[*templateInfo.Cover], Colors: colors, diff --git a/server/product-template-tag/internal/types/types.go b/server/product-template-tag/internal/types/types.go index 037e6966..b24c9f6b 100644 --- a/server/product-template-tag/internal/types/types.go +++ b/server/product-template-tag/internal/types/types.go @@ -13,6 +13,7 @@ type GetProductTemplateTagsRsp struct { Id int64 `json:"id"` TemplateTag string `json:"template_tag"` IsDefaultTemplateTag bool `json:"is_default_template_tag"` + TemplateTagGroups interface{} `json:"template_tag_groups"` Cover string `json:"cover"` CoverMetadata interface{} `json:"cover_metadata"` Colors []ColorsItem `json:"colors"` diff --git a/server_api/product-template-tag.api b/server_api/product-template-tag.api index ab06b272..2c290067 100644 --- a/server_api/product-template-tag.api +++ b/server_api/product-template-tag.api @@ -23,6 +23,7 @@ type GetProductTemplateTagsRsp { Id int64 `json:"id"` TemplateTag string `json:"template_tag"` IsDefaultTemplateTag bool `json:"is_default_template_tag"` + TemplateTagGroups interface{} `json:"template_tag_groups"` Cover string `json:"cover"` CoverMetadata interface{} `json:"cover_metadata"` Colors []ColorsItem `json:"colors"` From fb359cfba5c748bdd8a73b5df6247e6a1909c8f1 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Tue, 19 Sep 2023 15:38:03 +0800 Subject: [PATCH 29/38] 11 --- utils/websocket_data/render_data.go | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/utils/websocket_data/render_data.go b/utils/websocket_data/render_data.go index d79032d5..8ff17311 100644 --- a/utils/websocket_data/render_data.go +++ b/utils/websocket_data/render_data.go @@ -15,18 +15,19 @@ type RenderImageReqMsg struct { RenderData RenderData `json:"render_data"` } type RenderData struct { - TemplateTag string `json:"template_tag"` //模板标签(必须) - TemplateTagColor TemplateTagColor `json:"template_tag_color"` //模板标签组合颜色 - ProductId int64 `json:"product_id"` //产品id(必须) - Website string `json:"website"` //网站(可选) - Slogan string `json:"slogan"` //slogan(可选) - Address string `json:"address"` //地址(可选) - Phone string `json:"phone"` //电话(可选) - Qrcode string `json:"qrcode"` //二维码(可选) - ProductSizeId int64 `json:"product_size_id"` //尺寸id(可选) - UserId int64 `json:"user_id"` //用户id(websocket连接建立再赋值) - GuestId int64 `json:"guest_id"` //游客id(websocket连接建立再赋值) - Logo string `json:"logo"` //log资源地址(websocket连接建立再赋值) + TemplateTag string `json:"template_tag"` //模板标签(必须) + TemplateTagColor TemplateTagColor `json:"template_tag_color"` //模板标签组合颜色(必须) + TemplateTagGroups interface{} `json:"template_tag_groups"` //模板标签分组信息(必须) + Logo string `json:"logo"` //log资源地址(必须) + ProductId int64 `json:"product_id"` //产品id(必须) + Website string `json:"website"` //网站(可选) + Slogan string `json:"slogan"` //slogan(可选) + Address string `json:"address"` //地址(可选) + Phone string `json:"phone"` //电话(可选) + Qrcode string `json:"qrcode"` //二维码(可选) + ProductSizeId int64 `json:"product_size_id"` //尺寸id(可选) + UserId int64 `json:"user_id"` //用户id(websocket连接建立再赋值) + GuestId int64 `json:"guest_id"` //游客id(websocket连接建立再赋值) } type TemplateTagColor struct { Color [][]string `json:"color"` //颜色组合 From 078b797c94c609ac001acb2d1106b0e57fb3f31c Mon Sep 17 00:00:00 2001 From: momo <1012651275@qq.com> Date: Tue, 19 Sep 2023 15:59:44 +0800 Subject: [PATCH 30/38] =?UTF-8?q?fix:=E5=90=88=E5=9B=BE=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../logic/userlogotemplatetagsetlogic.go | 4 +- .../internal/logic/logocombinelogic.go | 1 - server/resource/internal/types/types.go | 25 ++++++------ server_api/resource.api | 17 ++++---- service/repositories/image_handle.go | 39 +++++++------------ 5 files changed, 39 insertions(+), 47 deletions(-) diff --git a/server/home-user-auth/internal/logic/userlogotemplatetagsetlogic.go b/server/home-user-auth/internal/logic/userlogotemplatetagsetlogic.go index 59c7e3ca..e9288415 100644 --- a/server/home-user-auth/internal/logic/userlogotemplatetagsetlogic.go +++ b/server/home-user-auth/internal/logic/userlogotemplatetagsetlogic.go @@ -45,10 +45,10 @@ func (l *UserLogoTemplateTagSetLogic) UserLogoTemplateTagSet(req *types.UserLogo return resp.SetStatus(basic.CodeUnAuth) } if req.LogoSelectedId == 0 { - return resp.SetStatus(basic.CodeLogoSetTemplateErr, "logo logo_selected_id not null") + return resp.SetStatus(basic.CodeApiErr, "logo logo_selected_id not null") } if req.TemplateTag == "" { - return resp.SetStatus(basic.CodeLogoSetTemplateErr, "logo template tag not null") + return resp.SetStatus(basic.CodeApiErr, "logo template tag not null") } var userId int64 var guestId int64 diff --git a/server/resource/internal/logic/logocombinelogic.go b/server/resource/internal/logic/logocombinelogic.go index dcfd7e63..69c517e9 100644 --- a/server/resource/internal/logic/logocombinelogic.go +++ b/server/resource/internal/logic/logocombinelogic.go @@ -95,7 +95,6 @@ func (l *LogoCombineLogic) LogoCombine(req *types.LogoCombineReq, userinfo *auth res, err := l.svcCtx.Repositories.ImageHandle.LogoCombine(l.ctx, &repositories.LogoCombineReq{ UserId: userId, GuestId: guestId, - TemplateId: req.TemplateId, TemplateTag: req.TemplateTag, Website: req.Website, Slogan: req.Slogan, diff --git a/server/resource/internal/types/types.go b/server/resource/internal/types/types.go index ce02c1b4..58c4950c 100644 --- a/server/resource/internal/types/types.go +++ b/server/resource/internal/types/types.go @@ -28,13 +28,16 @@ type ResourceInfoReq struct { } type LogoCombineReq struct { - TemplateId int64 `form:"template_id"` // 合图参数 - TemplateTag string `form:"template_tag"` // 合图参数 - Website string `form:"website,optional"` // 合图参数 - Slogan string `form:"slogan,optional"` // 合图参数 - Address string `form:"address,optional"` // 合图参数 - Phone string `form:"phone,optional"` // 合图参数 - Qrcode string `form:"qrcode,optional"` // 合图参数 + LogoUrl string `json:"logo_url"` // 合图参数 + TemplateId int64 `json:"template_id"` // 合图参数 + TemplateTag string `json:"template_tag"` // 合图参数 + Color [][]string `json:"color"` // 颜色组合 + SelectedIndex int `json:"selected_index"` // 主色的下标索引 + Website string `json:"website,optional"` // 合图参数 + Slogan string `json:"slogan,optional"` // 合图参数 + Address string `json:"address,optional"` // 合图参数 + Phone string `json:"phone,optional"` // 合图参数 + Qrcode string `json:"qrcode,optional"` // 合图参数 } type Request struct { @@ -60,10 +63,10 @@ type File struct { } type Meta struct { - TotalCount int64 `json:"totalCount"` - PageCount int64 `json:"pageCount"` - CurrentPage int `json:"currentPage"` - PerPage int `json:"perPage"` + TotalCount int64 `json:"total_count"` + PageCount int64 `json:"page_count"` + CurrentPage int `json:"current_page"` + PerPage int `json:"per_page"` } // Set 设置Response的Code和Message值 diff --git a/server_api/resource.api b/server_api/resource.api index 51404295..1510e8c3 100644 --- a/server_api/resource.api +++ b/server_api/resource.api @@ -55,12 +55,15 @@ type ( type ( LogoCombineReq { - TemplateId int64 `form:"template_id"` // 合图参数 - TemplateTag string `form:"template_tag"` // 合图参数 - Website string `form:"website,optional"` // 合图参数 - Slogan string `form:"slogan,optional"` // 合图参数 - Address string `form:"address,optional"` // 合图参数 - Phone string `form:"phone,optional"` // 合图参数 - Qrcode string `form:"qrcode,optional"` // 合图参数 + LogoUrl string `json:"logo_url"` // 合图参数 + TemplateId int64 `json:"template_id"` // 合图参数 + TemplateTag string `json:"template_tag"` // 合图参数 + Color [][]string `json:"color"` // 颜色组合 + SelectedIndex int `json:"selected_index"` // 主色的下标索引 + Website string `json:"website,optional"` // 合图参数 + Slogan string `json:"slogan,optional"` // 合图参数 + Address string `json:"address,optional"` // 合图参数 + Phone string `json:"phone,optional"` // 合图参数 + Qrcode string `json:"qrcode,optional"` // 合图参数 } ) \ No newline at end of file diff --git a/service/repositories/image_handle.go b/service/repositories/image_handle.go index 6fc53b36..052d7ca4 100644 --- a/service/repositories/image_handle.go +++ b/service/repositories/image_handle.go @@ -195,17 +195,18 @@ func (l *defaultImageHandle) LogoInfoSet(ctx context.Context, in *LogoInfoSetReq /* logo合图 */ type ( LogoCombineReq struct { - UserId int64 `json:"user_id"` - GuestId int64 `json:"guest_id"` - ProductTemplateV2Info *gmodel.FsProductTemplateV2 `json:"product_template_v2_info"` - TemplateTag string `json:"template_tag"` - Website string `json:"website"` // 合图参数 - Slogan string `json:"slogan"` // 合图参数 - Address string `json:"address"` // 合图参数 - Phone string `json:"phone"` // 合图参数 - Qrcode string `json:"qrcode"` // 合图参数 - LogoUrl string `json:"logo_url"` // 合图参数 - TemplateTagColor TemplateTagColor `json:"template_tag_color"` //合图颜色 + UserId int64 `json:"user_id"` + GuestId int64 `json:"guest_id"` + ProductTemplateV2Info *gmodel.FsProductTemplateV2 `json:"product_template_v2_info"` + ProductTemplateTagGroups interface{} `json:"product_template_tag_groups"` + TemplateTag string `json:"template_tag"` + Website string `json:"website"` // 合图参数 + Slogan string `json:"slogan"` // 合图参数 + Address string `json:"address"` // 合图参数 + Phone string `json:"phone"` // 合图参数 + Qrcode string `json:"qrcode"` // 合图参数 + LogoUrl string `json:"logo_url"` // 合图参数 + TemplateTagColor TemplateTagColor `json:"template_tag_color"` //合图颜色 } LogoCombineRes struct { ResourceId string @@ -257,13 +258,6 @@ func (l *defaultImageHandle) LogoCombine(ctx context.Context, in *LogoCombineReq } } - productTemplateTagInfo, err := gmodel.NewFsProductTemplateTagsModel(l.MysqlConn).FindOneByTagName(ctx, in.TemplateTag, "groups") - - if err != nil { - logc.Errorf(ctx, "NewFsProductTemplateTagsModel.FindOneByTagName:%v", err) - return nil, err - } - var groupOptions map[string]interface{} var materialList []interface{} if in.ProductTemplateV2Info.TemplateInfo != nil { @@ -297,13 +291,6 @@ func (l *defaultImageHandle) LogoCombine(ctx context.Context, in *LogoCombineReq moduleDataMap["groupOptions"] = groupOptions moduleDataMap["materialList"] = materialList - var tagDataMap []interface{} - err = json.Unmarshal([]byte(*productTemplateTagInfo.Groups), &tagDataMap) - if err != nil { - logc.Errorf(ctx, "Unmarshal tagDataMap:%v", err) - return nil, err - } - var combineParam map[string]interface{} json.Unmarshal([]byte(*resLogoInfo.Metadata), &combineParam) combineParam["template_tagid"] = in.TemplateTag @@ -319,7 +306,7 @@ func (l *defaultImageHandle) LogoCombine(ctx context.Context, in *LogoCombineReq } var postMap = make(map[string]interface{}, 2) postMap["module_data"] = moduleDataMap - postMap["tag_data"] = tagDataMap + postMap["tag_data"] = in.ProductTemplateTagGroups postMap["param_data"] = combineParam logc.Infof(ctx, "合图--算法请求--合图--开始时间:%v", time.Now().UTC()) From bcf5d9d6d764627de815b4c56f9793da2b0d8b3f Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Tue, 19 Sep 2023 16:01:23 +0800 Subject: [PATCH 31/38] 11 --- utils/websocket_data/render_data.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/websocket_data/render_data.go b/utils/websocket_data/render_data.go index 8ff17311..0eea4eb8 100644 --- a/utils/websocket_data/render_data.go +++ b/utils/websocket_data/render_data.go @@ -17,7 +17,7 @@ type RenderImageReqMsg struct { type RenderData struct { TemplateTag string `json:"template_tag"` //模板标签(必须) TemplateTagColor TemplateTagColor `json:"template_tag_color"` //模板标签组合颜色(必须) - TemplateTagGroups interface{} `json:"template_tag_groups"` //模板标签分组信息(必须) + TemplateTagGroups interface{} `json:"template_tag_groups"` //模板标签分组信息数组(必须) Logo string `json:"logo"` //log资源地址(必须) ProductId int64 `json:"product_id"` //产品id(必须) Website string `json:"website"` //网站(可选) From aa9b972deda3f14e6d24b05e6aba36cf41b61b37 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Tue, 19 Sep 2023 16:03:11 +0800 Subject: [PATCH 32/38] 11 --- .../internal/logic/ws_render_image.go | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/server/websocket/internal/logic/ws_render_image.go b/server/websocket/internal/logic/ws_render_image.go index 5b6789be..d9e8e702 100644 --- a/server/websocket/internal/logic/ws_render_image.go +++ b/server/websocket/internal/logic/ws_render_image.go @@ -195,16 +195,17 @@ func (w *wsConnectItem) renderImage(data []byte) { }*/ //获取刀版图 combineReq := repositories.LogoCombineReq{ - UserId: renderImageData.RenderData.UserId, - GuestId: renderImageData.RenderData.GuestId, - ProductTemplateV2Info: productTemplate, - TemplateTag: renderImageData.RenderData.TemplateTag, - Website: renderImageData.RenderData.Website, - Slogan: renderImageData.RenderData.Slogan, - Address: renderImageData.RenderData.Address, - Phone: renderImageData.RenderData.Phone, - Qrcode: renderImageData.RenderData.Qrcode, - LogoUrl: renderImageData.RenderData.Logo, + UserId: renderImageData.RenderData.UserId, + GuestId: renderImageData.RenderData.GuestId, + ProductTemplateV2Info: productTemplate, + ProductTemplateTagGroups: renderImageData.RenderData.TemplateTagGroups, + TemplateTag: renderImageData.RenderData.TemplateTag, + Website: renderImageData.RenderData.Website, + Slogan: renderImageData.RenderData.Slogan, + Address: renderImageData.RenderData.Address, + Phone: renderImageData.RenderData.Phone, + Qrcode: renderImageData.RenderData.Qrcode, + LogoUrl: renderImageData.RenderData.Logo, TemplateTagColor: repositories.TemplateTagColor{ Color: renderImageData.RenderData.TemplateTagColor.Color, Index: renderImageData.RenderData.TemplateTagColor.SelectedIndex, From b41d6ffda54e30f479e53e9c6a5d891d79453a56 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Tue, 19 Sep 2023 16:10:17 +0800 Subject: [PATCH 33/38] 11 --- server/websocket/internal/logic/ws_render_image.go | 4 ++-- utils/websocket_data/render_data.go | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/server/websocket/internal/logic/ws_render_image.go b/server/websocket/internal/logic/ws_render_image.go index d9e8e702..096fd3b2 100644 --- a/server/websocket/internal/logic/ws_render_image.go +++ b/server/websocket/internal/logic/ws_render_image.go @@ -109,7 +109,7 @@ func (w *wsConnectItem) renderImage(data []byte) { w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "请传入模板标签选择的颜色", renderImageData.RenderData.ProductId, w.userId, w.guestId, 0, 0, 0, 0) return } - if renderImageData.RenderData.TemplateTagColor.SelectedIndex >= lenColor || renderImageData.RenderData.TemplateTagColor.SelectedIndex < 0 { + if renderImageData.RenderData.TemplateTagColor.SelectedColorIndex >= lenColor || renderImageData.RenderData.TemplateTagColor.SelectedColorIndex < 0 { w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "选择的模板标签颜色索引越界", renderImageData.RenderData.ProductId, w.userId, w.guestId, 0, 0, 0, 0) return } @@ -208,7 +208,7 @@ func (w *wsConnectItem) renderImage(data []byte) { LogoUrl: renderImageData.RenderData.Logo, TemplateTagColor: repositories.TemplateTagColor{ Color: renderImageData.RenderData.TemplateTagColor.Color, - Index: renderImageData.RenderData.TemplateTagColor.SelectedIndex, + Index: renderImageData.RenderData.TemplateTagColor.SelectedColorIndex, }, } res, err := w.logic.svcCtx.Repositories.ImageHandle.LogoCombine(w.logic.ctx, &combineReq) diff --git a/utils/websocket_data/render_data.go b/utils/websocket_data/render_data.go index 0eea4eb8..c65b2eda 100644 --- a/utils/websocket_data/render_data.go +++ b/utils/websocket_data/render_data.go @@ -30,8 +30,8 @@ type RenderData struct { GuestId int64 `json:"guest_id"` //游客id(websocket连接建立再赋值) } type TemplateTagColor struct { - Color [][]string `json:"color"` //颜色组合 - SelectedIndex int `json:"selected_index"` //主色的下标索引 + Color [][]string `json:"color"` //颜色组合 + SelectedColorIndex int `json:"selected_color_index"` //主色的下标索引 } // websocket发送渲染完的数据 From 8ba604b3b938bf2f29b147dd85c03c47133b3602 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Tue, 19 Sep 2023 16:28:20 +0800 Subject: [PATCH 34/38] 11 --- server/websocket/internal/logic/ws_render_image.go | 1 - 1 file changed, 1 deletion(-) diff --git a/server/websocket/internal/logic/ws_render_image.go b/server/websocket/internal/logic/ws_render_image.go index 096fd3b2..dc914316 100644 --- a/server/websocket/internal/logic/ws_render_image.go +++ b/server/websocket/internal/logic/ws_render_image.go @@ -11,7 +11,6 @@ import ( "fusenapi/service/repositories" "fusenapi/utils/curl" "fusenapi/utils/hash" - "fusenapi/utils/template_switch_info" "fusenapi/utils/websocket_data" "github.com/zeromicro/go-zero/core/logx" "gorm.io/gorm" From 0dc1413988da18bb0e2a8f0065cdece30a03e27e Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Tue, 19 Sep 2023 16:49:57 +0800 Subject: [PATCH 35/38] 11 --- .../internal/logic/datatransferlogic.go | 2 - .../internal/logic/ws_render_image.go | 186 ------------------ 2 files changed, 188 deletions(-) diff --git a/server/websocket/internal/logic/datatransferlogic.go b/server/websocket/internal/logic/datatransferlogic.go index 65a3121c..ca5d3bb9 100644 --- a/server/websocket/internal/logic/datatransferlogic.go +++ b/server/websocket/internal/logic/datatransferlogic.go @@ -194,8 +194,6 @@ func (l *DataTransferLogic) setConnPool(conn *websocket.Conn, userInfo *auth.Use userId: userInfo.UserId, guestId: userInfo.GuestId, extendRenderProperty: extendRenderProperty{ - //renderImageTask: make(map[string]*renderTask), - //renderImageTaskCtlChan: make(chan renderImageControlChanItem, renderImageTaskCtlChanLen), renderChan: make(chan []byte, renderChanLen), renderConsumeTickTime: 1, //默认1纳秒,后面需要根据不同用户不同触发速度 }, diff --git a/server/websocket/internal/logic/ws_render_image.go b/server/websocket/internal/logic/ws_render_image.go index dc914316..2ee96af2 100644 --- a/server/websocket/internal/logic/ws_render_image.go +++ b/server/websocket/internal/logic/ws_render_image.go @@ -19,8 +19,6 @@ import ( ) var ( - //每个websocket连接渲染任务调度队列长度默认值(添加任务/删除任务/修改任务属性)缓冲队列长度(该队列用于避免map并发读写冲突) - renderImageTaskCtlChanLen = 100 //每个websocket渲染任务缓冲队列长度默认值 renderChanLen = 500 ) @@ -31,29 +29,10 @@ type renderProcessor struct { // 云渲染属性 type extendRenderProperty struct { - //renderImageTask map[string]*renderTask //需要渲染的图片任务 key是taskId val 是renderId - //renderImageTaskCtlChan chan renderImageControlChanItem //渲染任务新增/回调结果移除任务/更新渲染耗时属性的控制通道(由于任务map无法读写并发) renderChan chan []byte //渲染消息入口的缓冲队列 renderConsumeTickTime time.Duration //消费渲染消息时钟间隔(纳秒),用于后期控制不同类型用户渲染速度限制 } -// 渲染任务新增移除的控制通道的数据 -/*type renderImageControlChanItem struct { - option int // 0删除 1添加 2修改耗时属性 - taskId string //map的key(必须传) - renderId string // map的val(增加任务时候传) - renderNotifyImageUrl string //渲染回调数据(删除任务时候传) - taskProperty renderTask //渲染任务的属性 -}*/ - -// 渲染任务属性 -/*type renderTask struct { - renderId string //渲染id(新增任务传) - unityRenderBeginTime int64 //发送给unity时间 - unityRenderEndTime int64 //unity回调结果时间 - uploadUnityRenderImageTakesTime int64 //上传unity渲染结果图时间 -}*/ - // 处理分发到这里的数据 func (r *renderProcessor) allocationMessage(w *wsConnectItem, data []byte) { //logx.Info("收到渲染任务消息:", string(data)) @@ -128,21 +107,6 @@ func (w *wsConnectItem) renderImage(data []byte) { w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "该产品不可定制", renderImageData.RenderData.ProductId, w.userId, w.guestId, 0, 0, 0, 0) return } - //获取用户需要渲染logo - /*logoInfo, err := w.logic.svcCtx.Repositories.ImageHandle.LogoInfo(w.logic.ctx, &repositories.LogoInfoReq{ - UserId: w.userId, - GuestId: w.guestId, - }) - if err != nil { - w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "获取用户logo素材错误", renderImageData.RenderData.ProductId, w.userId, w.guestId, 0, 0, 0, 0) - logx.Error(err) - return - } - if logoInfo == nil || logoInfo.LogoUrl == nil { - w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "用户logo素材url是空的", renderImageData.RenderData.ProductId, w.userId, w.guestId, 0, 0, 0, 0) - return - } - renderImageData.RenderData.Logo = *logoInfo.LogoUrl*/ //用户id赋值 renderImageData.RenderData.UserId = w.userId renderImageData.RenderData.GuestId = w.guestId @@ -253,9 +217,6 @@ func (w *wsConnectItem) renderImage(data []byte) { }) return } - //########################################### - //把需要渲染的图片任务加进去 - //w.createRenderTask(taskId, renderImageData.RenderId) //组装数据 if err = w.assembleRenderDataToUnity(taskId, combineImage, renderImageData, productTemplate, model3dInfo, element, productSize); err != nil { logx.Error("组装数据失败:", err) @@ -447,15 +408,12 @@ func (w *wsConnectItem) assembleRenderDataToUnity(taskId string, combineImage st "render_data": sendData, } postDataBytes, _ := json.Marshal(postData) - //unityRenderBeginTime := time.Now().UTC().UnixMilli() _, err = curl.ApiCall(url, "POST", header, bytes.NewReader(postDataBytes), time.Second*10) if err != nil { w.renderErrResponse(info.RenderId, info.RenderData.TemplateTag, taskId, "请求unity接口失败", info.RenderData.ProductId, w.userId, w.guestId, productTemplate.Id, model3dInfo.Id, productSize.Id, *productTemplate.ElementModelId) logx.Error("failed to send data to unity") return err } - //记录发送到unity时间 - //w.modifyRenderTaskProperty(taskId, renderTask{unityRenderBeginTime: unityRenderBeginTime}) //发送运行阶段消息 w.sendRenderDataToUnityStepResponseMessage(info.RenderId) logx.Info("发送到unity成功,刀版图:", combineImage /*, " 请求unity的数据:", string(postDataBytes)*/) @@ -500,75 +458,6 @@ func (w *wsConnectItem) sendRenderResultData(data websocket_data.RenderImageRspM w.sendToOutChan(w.respondDataFormat(constants.WEBSOCKET_RENDER_IMAGE, data)) } -/*// 增加渲染任务 -func (w *wsConnectItem) createRenderTask(taskId, renderId string) { - if taskId == "" { - logx.Error("task_id不能为空") - return - } - if renderId == "" { - logx.Error("render_id不能为空") - return - } - data := renderImageControlChanItem{ - option: 1, - taskId: taskId, - renderId: renderId, - } - select { - case <-w.closeChan: //关闭 - return - case w.extendRenderProperty.renderImageTaskCtlChan <- data: - return - case <-time.After(time.Second * 3): - return - } -} - -// 渲染回调处理并删除渲染任务 -func (w *wsConnectItem) deleteRenderTask(taskId, renderId, renderNotifyImageUrl string) { - if taskId == "" { - logx.Error("task_id不能为空") - return - } - data := renderImageControlChanItem{ - option: 0, - taskId: taskId, - renderId: renderId, - renderNotifyImageUrl: renderNotifyImageUrl, - } - select { - case <-w.closeChan: //关闭 - return - case w.extendRenderProperty.renderImageTaskCtlChan <- data: - return - case <-time.After(time.Second * 3): - return - } -} - -// 修改任务属性(只有耗时属性可以更新) -func (w *wsConnectItem) modifyRenderTaskProperty(taskId string, property renderTask) { - if taskId == "" { - logx.Error("task_id不能为空") - return - } - //强制设为修改任务属性 - data := renderImageControlChanItem{ - option: 2, - taskId: taskId, - taskProperty: property, - } - select { - case <-w.closeChan: //关闭 - return - case w.extendRenderProperty.renderImageTaskCtlChan <- data: - return - case <-time.After(time.Second * 3): - return - } -}*/ - // 组装渲染任务id func (w *wsConnectItem) genRenderTaskId(combineImage string, renderImageData websocket_data.RenderImageReqMsg, model3dInfo *gmodel.FsProductModel3d, productTemplate *gmodel.FsProductTemplateV2, element *gmodel.FsProductTemplateElement) string { //生成任务id(需要把user_id,guest_id设为0) @@ -595,78 +484,3 @@ func (w *wsConnectItem) genRenderTaskId(combineImage string, renderImageData web } return hash.JsonHashKey(hashMap) } - -// 处理渲染任务的增加/删除/修改耗时属性(任务map不能读写并发,所以放在chan里面串行执行) -/*func (w *wsConnectItem) operationRenderTask() { - defer func() { - if err := recover(); err != nil { - logx.Error("operation render task panic:", err) - } - }() - for { - select { - case <-w.closeChan: - return - case data := <-w.extendRenderProperty.renderImageTaskCtlChan: - switch data.option { - case 0: //渲染结果回调,删除任务 - taskData, ok := w.extendRenderProperty.renderImageTask[data.taskId] - if !ok { - //发送到出口 - w.sendRenderResultData(websocket_data.RenderImageRspMsg{ - RenderId: data.renderId, //没有找到任务渲染id则用传进来的 - Image: data.renderNotifyImageUrl, - RenderProcessTime: websocket_data.RenderProcessTime{ - UnityRenderTakesTime: "unknown", - UploadUnityRenderImageTakesTime: "unknown", - }, - }) - continue - } - //删除任务 - delete(w.extendRenderProperty.renderImageTask, data.taskId) - //存在任务,则发送渲染结果给前端 - UnityRenderTakesTime := "cache" - uploadUnityRenderImageTakesTime := "cache" - //unity渲染时间 - if taskData.unityRenderBeginTime > 0 && taskData.unityRenderEndTime > 0 { - UnityRenderTakesTime = fmt.Sprintf("%dms", taskData.unityRenderEndTime-taskData.unityRenderBeginTime) - } - //上传unity渲染图耗时 - if taskData.uploadUnityRenderImageTakesTime > 0 { - uploadUnityRenderImageTakesTime = fmt.Sprintf("%dms", taskData.uploadUnityRenderImageTakesTime) - } - //发送到出口 - w.sendRenderResultData(websocket_data.RenderImageRspMsg{ - RenderId: taskData.renderId, - Image: data.renderNotifyImageUrl, - RenderProcessTime: websocket_data.RenderProcessTime{ - UnityRenderTakesTime: UnityRenderTakesTime, - UploadUnityRenderImageTakesTime: uploadUnityRenderImageTakesTime, - }, - }) - case 1: //新增任务 - w.extendRenderProperty.renderImageTask[data.taskId] = &renderTask{ - renderId: data.renderId, - } - case 2: //修改任务属性 - taskData, ok := w.extendRenderProperty.renderImageTask[data.taskId] - if !ok { - continue - } - //上传渲染结果图耗时 - if data.taskProperty.uploadUnityRenderImageTakesTime != 0 { - taskData.uploadUnityRenderImageTakesTime = data.taskProperty.uploadUnityRenderImageTakesTime - } - //发送unity时间 - if data.taskProperty.unityRenderBeginTime != 0 { - taskData.unityRenderBeginTime = data.taskProperty.unityRenderBeginTime - } - //收到unity返回的时间 - if data.taskProperty.unityRenderEndTime != 0 { - taskData.unityRenderEndTime = data.taskProperty.unityRenderEndTime - } - } - } - } -}*/ From 40e04c70b86fc366d94b9b0488bfbc1ad10d8deb Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Tue, 19 Sep 2023 17:08:47 +0800 Subject: [PATCH 36/38] 11 --- server/websocket/internal/logic/ws_render_image.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/websocket/internal/logic/ws_render_image.go b/server/websocket/internal/logic/ws_render_image.go index 2ee96af2..f8484ecd 100644 --- a/server/websocket/internal/logic/ws_render_image.go +++ b/server/websocket/internal/logic/ws_render_image.go @@ -266,8 +266,8 @@ func (w *wsConnectItem) getProductRelateionInfoWithSizeId(renderImageData *webso return nil, nil, nil, errors.New("模板未开启云渲染") } if productTemplate.TemplateInfo == nil || *productTemplate.TemplateInfo == "" { - w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "渲染模板的json设计信息是空的", renderImageData.RenderData.ProductId, w.userId, w.guestId, productTemplate.Id, model3d.Id, productSize.Id, 0) - return nil, nil, nil, errors.New("渲染模板的json设计信息是空的") + w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "渲染模板的设计信息是空的", renderImageData.RenderData.ProductId, w.userId, w.guestId, productTemplate.Id, model3d.Id, productSize.Id, 0) + return nil, nil, nil, errors.New("渲染模板的设计信息是空的") } return } From 3f4d808fda6482f930fc98fcf392890d3ecbff19 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Tue, 19 Sep 2023 17:24:47 +0800 Subject: [PATCH 37/38] 11 --- .../logic/getproducttemplatetagslogic.go | 10 ++++------ .../internal/types/types.go | 20 ++++++++----------- server_api/product-template-tag.api | 19 ++++++++---------- 3 files changed, 20 insertions(+), 29 deletions(-) diff --git a/server/product-template-tag/internal/logic/getproducttemplatetagslogic.go b/server/product-template-tag/internal/logic/getproducttemplatetagslogic.go index cd43c5af..51b0ef36 100644 --- a/server/product-template-tag/internal/logic/getproducttemplatetagslogic.go +++ b/server/product-template-tag/internal/logic/getproducttemplatetagslogic.go @@ -124,19 +124,17 @@ func (l *GetProductTemplateTagsLogic) GetProductTemplateTags(req *types.GetProdu } list := make([]types.GetProductTemplateTagsRsp, 0, len(productTemplateTags)) for _, templateInfo := range productTemplateTags { - colors := make([]types.ColorsItem, 0, 10) + colors := make([][]string, 0, 10) SelectedColorIndex := 0 isDefaultTemplateTag := false - for _, colorsSet := range mapTemplateTag[*templateInfo.TemplateTag] { + if colorsSet, ok := mapTemplateTag[*templateInfo.TemplateTag]; ok { if selectIndex, ok := mapSelectColor[*templateInfo.TemplateTag]; ok { isDefaultTemplateTag = true SelectedColorIndex = selectIndex } - colors = append(colors, types.ColorsItem{ - Color: colorsSet, - }) + colors = colorsSet } - var templateTagGroups interface{} + var templateTagGroups []interface{} if templateInfo.Groups != nil && *templateInfo.Groups != "" { if err = json.Unmarshal([]byte(*templateInfo.Groups), &templateTagGroups); err != nil { logx.Error(err) diff --git a/server/product-template-tag/internal/types/types.go b/server/product-template-tag/internal/types/types.go index b24c9f6b..295cc1ee 100644 --- a/server/product-template-tag/internal/types/types.go +++ b/server/product-template-tag/internal/types/types.go @@ -10,18 +10,14 @@ type GetProductTemplateTagsReq struct { } type GetProductTemplateTagsRsp struct { - Id int64 `json:"id"` - TemplateTag string `json:"template_tag"` - IsDefaultTemplateTag bool `json:"is_default_template_tag"` - TemplateTagGroups interface{} `json:"template_tag_groups"` - Cover string `json:"cover"` - CoverMetadata interface{} `json:"cover_metadata"` - Colors []ColorsItem `json:"colors"` - SelectedColorIndex int `json:"selected_color_index"` -} - -type ColorsItem struct { - Color []string `json:"color"` + Id int64 `json:"id"` + TemplateTag string `json:"template_tag"` + IsDefaultTemplateTag bool `json:"is_default_template_tag"` + TemplateTagGroups interface{} `json:"template_tag_groups"` + Cover string `json:"cover"` + CoverMetadata interface{} `json:"cover_metadata"` + Colors [][]string `json:"colors"` + SelectedColorIndex int `json:"selected_color_index"` } type Request struct { diff --git a/server_api/product-template-tag.api b/server_api/product-template-tag.api index 2c290067..74778ccf 100644 --- a/server_api/product-template-tag.api +++ b/server_api/product-template-tag.api @@ -20,15 +20,12 @@ type GetProductTemplateTagsReq { Limit int `form:"limit"` } type GetProductTemplateTagsRsp { - Id int64 `json:"id"` - TemplateTag string `json:"template_tag"` - IsDefaultTemplateTag bool `json:"is_default_template_tag"` - TemplateTagGroups interface{} `json:"template_tag_groups"` - Cover string `json:"cover"` - CoverMetadata interface{} `json:"cover_metadata"` - Colors []ColorsItem `json:"colors"` - SelectedColorIndex int `json:"selected_color_index"` -} -type ColorsItem { - Color []string `json:"color"` + Id int64 `json:"id"` + TemplateTag string `json:"template_tag"` + IsDefaultTemplateTag bool `json:"is_default_template_tag"` + TemplateTagGroups interface{} `json:"template_tag_groups"` + Cover string `json:"cover"` + CoverMetadata interface{} `json:"cover_metadata"` + Colors [][]string `json:"colors"` + SelectedColorIndex int `json:"selected_color_index"` } \ No newline at end of file From a897723a25375210056c5cde6eaedb5a7f2894eb Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Tue, 19 Sep 2023 17:52:23 +0800 Subject: [PATCH 38/38] fix --- .../internal/logic/calculatecartpricelogic.go | 100 +++++++++++------- 1 file changed, 60 insertions(+), 40 deletions(-) diff --git a/server/shopping-cart/internal/logic/calculatecartpricelogic.go b/server/shopping-cart/internal/logic/calculatecartpricelogic.go index ce0bfc13..3f34b490 100644 --- a/server/shopping-cart/internal/logic/calculatecartpricelogic.go +++ b/server/shopping-cart/internal/logic/calculatecartpricelogic.go @@ -2,6 +2,7 @@ package logic import ( "context" + "errors" "fmt" "fusenapi/constants" "fusenapi/model/gmodel" @@ -9,6 +10,7 @@ import ( "fusenapi/utils/basic" "fusenapi/utils/format" "fusenapi/utils/step_price" + "gorm.io/gorm" "math" "strings" @@ -100,48 +102,66 @@ func (l *CalculateCartPriceLogic) CalculateCartPrice(req *types.CalculateCartPri //开始计算价格 calculateResultList := make([]types.CalculateResultItem, 0, len(req.CalculateList)) subTotalPrice := int64(0) - for _, cart := range carts { - sizePrice, ok := mapPrice[fmt.Sprintf("%d_%d", *cart.ProductId, *cart.SizeId)] - if !ok { - return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, fmt.Sprintf("there carts contain some one which have no price info:%d_%d", *cart.ProductId, *cart.SizeId)) - } - //阶梯数量切片 - stepNum, err := format.StrSlicToIntSlice(strings.Split(*sizePrice.StepNum, ",")) - if err != nil { - logx.Error(err) - return resp.SetStatusWithMessage(basic.CodeServiceErr, fmt.Sprintf("failed to parse step number:%d_%d", *cart.ProductId, *cart.SizeId)) - } - lenStepNum := len(stepNum) - //阶梯价格切片 - stepPrice, err := format.StrSlicToIntSlice(strings.Split(*sizePrice.StepPrice, ",")) - if err != nil { - logx.Error(err) - return resp.SetStatusWithMessage(basic.CodeServiceErr, fmt.Sprintf("failed to parse step price:%d_%d", *cart.ProductId, *cart.SizeId)) - } - lenStepPrice := len(stepPrice) - if lenStepPrice == 0 || lenStepNum == 0 { - return resp.SetStatusWithMessage(basic.CodeServiceErr, fmt.Sprintf("step price or step number is not set:%d_%d", *cart.ProductId, *cart.SizeId)) - } - //购买箱数 - boxQuantity := int(math.Ceil(float64(mapCalculateQuantity[cart.Id]) / float64(*sizePrice.EachBoxNum))) - //根据数量获取阶梯价格中对应的价格 - itemPrice := step_price.GetCentStepPrice(boxQuantity, stepNum, stepPrice) - //如果有配件,单价也要加入配件价格 - if *cart.FittingId > 0 { - if fittingPrice, ok := mapFitting[*cart.FittingId]; ok { - itemPrice += fittingPrice - } else { - return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "cart contain some one witch lose fitting:%d", *cart.FittingId) + //开启事物 + err = l.svcCtx.MysqlConn.Transaction(func(tx *gorm.DB) error { + shoppingCartModel := gmodel.NewFsShoppingCartModel(tx) + for _, cart := range carts { + sizePrice, ok := mapPrice[fmt.Sprintf("%d_%d", *cart.ProductId, *cart.SizeId)] + if !ok { + return errors.New(fmt.Sprintf("there carts contain some one which have no price info:%d_%d", *cart.ProductId, *cart.SizeId)) + } + //阶梯数量切片 + stepNum, err := format.StrSlicToIntSlice(strings.Split(*sizePrice.StepNum, ",")) + if err != nil { + logx.Error(err) + return errors.New(fmt.Sprintf("failed to parse step number:%d_%d", *cart.ProductId, *cart.SizeId)) + } + lenStepNum := len(stepNum) + //阶梯价格切片 + stepPrice, err := format.StrSlicToIntSlice(strings.Split(*sizePrice.StepPrice, ",")) + if err != nil { + logx.Error(err) + return errors.New(fmt.Sprintf("failed to parse step price:%d_%d", *cart.ProductId, *cart.SizeId)) + } + lenStepPrice := len(stepPrice) + if lenStepPrice == 0 || lenStepNum == 0 { + return errors.New(fmt.Sprintf("step price or step number is not set:%d_%d", *cart.ProductId, *cart.SizeId)) + } + //请求的数量 + reqPurchaseQuantity := mapCalculateQuantity[cart.Id] + //购买箱数 + boxQuantity := int(math.Ceil(float64(reqPurchaseQuantity) / float64(*sizePrice.EachBoxNum))) + //根据数量获取阶梯价格中对应的价格 + itemPrice := step_price.GetCentStepPrice(boxQuantity, stepNum, stepPrice) + //如果有配件,单价也要加入配件价格 + if *cart.FittingId > 0 { + if fittingPrice, ok := mapFitting[*cart.FittingId]; ok { + itemPrice += fittingPrice + } else { + return errors.New(fmt.Sprintf("cart contain some one witch lose fitting:%d", *cart.FittingId)) + } + } + //单个购物车总价 + totalPrice := itemPrice * reqPurchaseQuantity + calculateResultList = append(calculateResultList, types.CalculateResultItem{ + CartId: cart.Id, + ItemPrice: fmt.Sprintf("%.3f", format.CentitoDollar(itemPrice)), + TotalPrice: fmt.Sprintf("%.3f", format.CentitoDollar(totalPrice)), + }) + subTotalPrice += totalPrice + //更新购物车购买数量 + err = shoppingCartModel.Update(l.ctx, cart.Id, userinfo.UserId, &gmodel.FsShoppingCart{ + PurchaseQuantity: &reqPurchaseQuantity, + }) + if err != nil { + logx.Error(err) + return errors.New(fmt.Sprintf("failed to update cart`s purchase quantity:%d", cart.Id)) } } - //单个购物车总价 - totalPrice := itemPrice * mapCalculateQuantity[cart.Id] - calculateResultList = append(calculateResultList, types.CalculateResultItem{ - CartId: cart.Id, - ItemPrice: fmt.Sprintf("%.3f", format.CentitoDollar(itemPrice)), - TotalPrice: fmt.Sprintf("%.3f", format.CentitoDollar(totalPrice)), - }) - subTotalPrice += totalPrice + return nil + }) + if err != nil { + return resp.SetStatusWithMessage(basic.CodeDbSqlErr, err.Error()) } return resp.SetStatusWithMessage(basic.CodeOK, "success", types.CalculateCartPriceRsp{ SubTotalPrice: fmt.Sprintf("%.3f", format.CentitoDollar(subTotalPrice)),