From be805258789c6b1d963a45e57514c41980302054 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Wed, 20 Sep 2023 16:46:30 +0800 Subject: [PATCH 01/18] 11 --- model/gmodel/fs_user_material_logic.go | 13 +++++++++++++ .../product-template-tag/internal/handler/routes.go | 5 +++++ .../internal/logic/getproducttemplatetagslogic.go | 4 ++-- server/product-template-tag/internal/types/types.go | 11 +++++++++++ server_api/product-template-tag.api | 13 +++++++++++++ 5 files changed, 44 insertions(+), 2 deletions(-) diff --git a/model/gmodel/fs_user_material_logic.go b/model/gmodel/fs_user_material_logic.go index 77ae2736..d36f2195 100644 --- a/model/gmodel/fs_user_material_logic.go +++ b/model/gmodel/fs_user_material_logic.go @@ -142,3 +142,16 @@ func (m *FsUserMaterialModel) GetListByUser(ctx context.Context, userId, guestId Where(cond).Order("id DESC").Limit(limit).Find(&resp).Error return resp, err } +func (m *FsUserMaterialModel) FindOneByUserAndLogoUrl(ctx context.Context, userId, guestId int64, logoResourceId string) (resp *FsUserMaterial, err error) { + var cond string + if userId != 0 { + cond = fmt.Sprintf("user_id = %d", userId) + } else if guestId != 0 { + cond = fmt.Sprintf("guest_id = %d", guestId) + } else { + cond = fmt.Sprintf("user_id = %d and guest_id = %d", userId, guestId) + } + err = m.db.WithContext(ctx).Model(&FsUserMaterial{}).Where("`resource_id` = ?", logoResourceId). + Where(cond).Order("id DESC").Take(&resp).Error + return resp, err +} diff --git a/server/product-template-tag/internal/handler/routes.go b/server/product-template-tag/internal/handler/routes.go index 24a5c707..069f42fe 100644 --- a/server/product-template-tag/internal/handler/routes.go +++ b/server/product-template-tag/internal/handler/routes.go @@ -17,6 +17,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { Path: "/api/product-template-tag/get_product_template_tags", Handler: GetProductTemplateTagsHandler(serverCtx), }, + { + Method: http.MethodGet, + Path: "/api/product-template-tag/get_template_tag_color", + Handler: GetTemplateTagColorHandler(serverCtx), + }, }, ) } diff --git a/server/product-template-tag/internal/logic/getproducttemplatetagslogic.go b/server/product-template-tag/internal/logic/getproducttemplatetagslogic.go index f51e2dfb..ef5940ca 100644 --- a/server/product-template-tag/internal/logic/getproducttemplatetagslogic.go +++ b/server/product-template-tag/internal/logic/getproducttemplatetagslogic.go @@ -36,7 +36,7 @@ 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 { +type LogoSelect struct { LogoSelected struct { LogoSelectedId int `json:"logo_selected_id"` TemplateTagSelected struct { @@ -83,7 +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 + 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") diff --git a/server/product-template-tag/internal/types/types.go b/server/product-template-tag/internal/types/types.go index 295cc1ee..fdc0daa6 100644 --- a/server/product-template-tag/internal/types/types.go +++ b/server/product-template-tag/internal/types/types.go @@ -20,6 +20,17 @@ type GetProductTemplateTagsRsp struct { SelectedColorIndex int `json:"selected_color_index"` } +type GetTemplateTagColorReq struct { + Logo string `json:"logo"` + TemplateTag string `json:"template_tag"` + SelectedColorIndex int `json:"selected_color_index"` +} + +type GetTemplateTagColorRsp struct { + 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 74778ccf..6cd4e703 100644 --- a/server_api/product-template-tag.api +++ b/server_api/product-template-tag.api @@ -13,6 +13,9 @@ service product-template-tag { //获取产品模板标签列表 @handler GetProductTemplateTagsHandler get /api/product-template-tag/get_product_template_tags(GetProductTemplateTagsReq) returns (response); + //根据模板标签跟logo还有选择颜色的索引获取颜色 + @handler GetTemplateTagColorHandler + get /api/product-template-tag/get_template_tag_color(GetTemplateTagColorReq) returns (response); } //获取产品模板标签列表 @@ -28,4 +31,14 @@ type GetProductTemplateTagsRsp { CoverMetadata interface{} `json:"cover_metadata"` Colors [][]string `json:"colors"` SelectedColorIndex int `json:"selected_color_index"` +} +//根据模板标签跟logo还有选择颜色的索引获取颜色 +type GetTemplateTagColorReq { + Logo string `json:"logo"` + TemplateTag string `json:"template_tag"` + SelectedColorIndex int `json:"selected_color_index"` +} +type GetTemplateTagColorRsp { + Colors [][]string `json:"colors"` + SelectedColorIndex int `json:"selected_color_index"` } \ No newline at end of file From e1364838dad84ab7fd9ee29dceaa7d587b3ecef8 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Wed, 20 Sep 2023 16:47:59 +0800 Subject: [PATCH 02/18] 11 --- server/product-template-tag/internal/types/types.go | 6 +++--- server_api/product-template-tag.api | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/server/product-template-tag/internal/types/types.go b/server/product-template-tag/internal/types/types.go index fdc0daa6..f5f6493a 100644 --- a/server/product-template-tag/internal/types/types.go +++ b/server/product-template-tag/internal/types/types.go @@ -21,9 +21,9 @@ type GetProductTemplateTagsRsp struct { } type GetTemplateTagColorReq struct { - Logo string `json:"logo"` - TemplateTag string `json:"template_tag"` - SelectedColorIndex int `json:"selected_color_index"` + Logo string `form:"logo"` + TemplateTag string `form:"template_tag"` + SelectedColorIndex int `form:"selected_color_index"` } type GetTemplateTagColorRsp struct { diff --git a/server_api/product-template-tag.api b/server_api/product-template-tag.api index 6cd4e703..d074f921 100644 --- a/server_api/product-template-tag.api +++ b/server_api/product-template-tag.api @@ -34,9 +34,9 @@ type GetProductTemplateTagsRsp { } //根据模板标签跟logo还有选择颜色的索引获取颜色 type GetTemplateTagColorReq { - Logo string `json:"logo"` - TemplateTag string `json:"template_tag"` - SelectedColorIndex int `json:"selected_color_index"` + Logo string `form:"logo"` + TemplateTag string `form:"template_tag"` + SelectedColorIndex int `form:"selected_color_index"` } type GetTemplateTagColorRsp { Colors [][]string `json:"colors"` From 6699a64169e158f4aee6100c006083eb393350ee Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Wed, 20 Sep 2023 16:49:05 +0800 Subject: [PATCH 03/18] fix --- .../handler/gettemplatetagcolorhandler.go | 35 +++++++ .../logic/gettemplatetagcolorlogic.go | 97 +++++++++++++++++++ 2 files changed, 132 insertions(+) create mode 100644 server/product-template-tag/internal/handler/gettemplatetagcolorhandler.go create mode 100644 server/product-template-tag/internal/logic/gettemplatetagcolorlogic.go diff --git a/server/product-template-tag/internal/handler/gettemplatetagcolorhandler.go b/server/product-template-tag/internal/handler/gettemplatetagcolorhandler.go new file mode 100644 index 00000000..8f6f1d21 --- /dev/null +++ b/server/product-template-tag/internal/handler/gettemplatetagcolorhandler.go @@ -0,0 +1,35 @@ +package handler + +import ( + "net/http" + "reflect" + + "fusenapi/utils/basic" + + "fusenapi/server/product-template-tag/internal/logic" + "fusenapi/server/product-template-tag/internal/svc" + "fusenapi/server/product-template-tag/internal/types" +) + +func GetTemplateTagColorHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + + var req types.GetTemplateTagColorReq + userinfo, err := basic.RequestParse(w, r, svcCtx, &req) + if err != nil { + return + } + + // 创建一个业务逻辑层实例 + l := logic.NewGetTemplateTagColorLogic(r.Context(), svcCtx) + + rl := reflect.ValueOf(l) + basic.BeforeLogic(w, r, rl) + + resp := l.GetTemplateTagColor(&req, userinfo) + + if !basic.AfterLogic(w, r, rl, resp) { + basic.NormalAfterLogic(w, r, resp) + } + } +} diff --git a/server/product-template-tag/internal/logic/gettemplatetagcolorlogic.go b/server/product-template-tag/internal/logic/gettemplatetagcolorlogic.go new file mode 100644 index 00000000..b393f7d4 --- /dev/null +++ b/server/product-template-tag/internal/logic/gettemplatetagcolorlogic.go @@ -0,0 +1,97 @@ +package logic + +import ( + "encoding/json" + "errors" + "fusenapi/model/gmodel" + "fusenapi/utils/auth" + "fusenapi/utils/basic" + "gorm.io/gorm" + "strings" + + "context" + + "fusenapi/server/product-template-tag/internal/svc" + "fusenapi/server/product-template-tag/internal/types" + + "github.com/zeromicro/go-zero/core/logx" +) + +type GetTemplateTagColorLogic struct { + logx.Logger + ctx context.Context + svcCtx *svc.ServiceContext +} + +func NewGetTemplateTagColorLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetTemplateTagColorLogic { + return &GetTemplateTagColorLogic{ + Logger: logx.WithContext(ctx), + ctx: ctx, + svcCtx: svcCtx, + } +} + +// 处理进入前逻辑w,r +// func (l *GetTemplateTagColorLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) { +// } + +func (l *GetTemplateTagColorLogic) GetTemplateTagColor(req *types.GetTemplateTagColorReq, userinfo *auth.UserInfo) (resp *basic.Response) { + if req.SelectedColorIndex < 0 { + return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "param selected_color_index is invalid") + } + //根据logo查询素材资源 + s := strings.Split(req.Logo, "/") + if len(s) <= 1 { + return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "invalid logo") + } + resourceId := s[len(s)-1] + var ( + userMaterial *gmodel.FsUserMaterial + err error + ) + //游客或者用户 + if userinfo.IsUser() || userinfo.IsGuest() { + userMaterial, err = l.svcCtx.AllModels.FsUserMaterial.FindOneByUserAndLogoUrl(l.ctx, userinfo.UserId, userinfo.GuestId, resourceId) + } else { + //白板用户 + userMaterial, err = l.svcCtx.AllModels.FsUserMaterial.FindOneById(l.ctx, 0) + } + if err != nil { + if errors.Is(err, gorm.ErrRecordNotFound) { + return resp.SetStatusWithMessage(basic.CodeDbRecordNotFoundErr, "the logo is not found") + } + logx.Error(err) + return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get user material") + } + if userMaterial.Metadata == nil || len(*userMaterial.Metadata) == 0 { + return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "the user material is empty") + } + //解析用户素材元数据 + var metaData map[string]interface{} + if err = json.Unmarshal(*userMaterial.Metadata, &metaData); err != nil { + logx.Error(err) + return resp.SetStatusWithMessage(basic.CodeJsonErr, "failed to parse user metadata") + } + var mapMaterialTemplateTag map[string][][]string + b, _ := json.Marshal(metaData["template_tag"]) + if err = json.Unmarshal(b, &mapMaterialTemplateTag); err != nil { + logx.Error(err) + return resp.SetStatusWithMessage(basic.CodeJsonErr, "invalid format of metadata`s template_tag") + } + colors, ok := mapMaterialTemplateTag[req.TemplateTag] + if !ok { + return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "the template tag is not found from this logo material`s metadata") + } + if req.SelectedColorIndex >= len(colors) { + return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "select color index is out of range !!") + } + return resp.SetStatus(basic.CodeOK, "success", types.GetTemplateTagColorRsp{ + Colors: colors, + SelectedColorIndex: req.SelectedColorIndex, + }) +} + +// 处理逻辑后 w,r 如:重定向, resp 必须重新处理 +// func (l *GetTemplateTagColorLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) { +// // httpx.OkJsonCtx(r.Context(), w, resp) +// } From 29f112212039c73cfb4bff2061cc3184a4cbcdcc Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Wed, 20 Sep 2023 16:57:25 +0800 Subject: [PATCH 04/18] fix --- .../internal/logic/gettemplatetagcolorlogic.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/product-template-tag/internal/logic/gettemplatetagcolorlogic.go b/server/product-template-tag/internal/logic/gettemplatetagcolorlogic.go index b393f7d4..4913e396 100644 --- a/server/product-template-tag/internal/logic/gettemplatetagcolorlogic.go +++ b/server/product-template-tag/internal/logic/gettemplatetagcolorlogic.go @@ -85,7 +85,7 @@ func (l *GetTemplateTagColorLogic) GetTemplateTagColor(req *types.GetTemplateTag if req.SelectedColorIndex >= len(colors) { return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "select color index is out of range !!") } - return resp.SetStatus(basic.CodeOK, "success", types.GetTemplateTagColorRsp{ + return resp.SetStatusWithMessage(basic.CodeOK, "success", types.GetTemplateTagColorRsp{ Colors: colors, SelectedColorIndex: req.SelectedColorIndex, }) From 18aaef0e3158ebf5920d672c9c5b57d8a03fb43f Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Wed, 20 Sep 2023 17:11:48 +0800 Subject: [PATCH 05/18] fix --- .../gmodel/fs_product_template_tags_logic.go | 4 ++-- .../logic/gettemplatetagcolorlogic.go | 22 +++++++++++++++++-- .../internal/types/types.go | 5 +++-- server_api/product-template-tag.api | 5 +++-- 4 files changed, 28 insertions(+), 8 deletions(-) diff --git a/model/gmodel/fs_product_template_tags_logic.go b/model/gmodel/fs_product_template_tags_logic.go index b2529fcf..8c931575 100755 --- a/model/gmodel/fs_product_template_tags_logic.go +++ b/model/gmodel/fs_product_template_tags_logic.go @@ -43,8 +43,8 @@ func (pt *FsProductTemplateTagsModel) GetListByTagNames(ctx context.Context, tag err = db.Limit(limit).Find(&resp).Error return resp, err } -func (pt *FsProductTemplateTagsModel) FindOneByTagName(ctx context.Context, tagName string, fields ...string) (resp *FsProductTemplateTags, err error) { - db := pt.db.WithContext(ctx).Model(&FsProductTemplateTags{}).Where("`template_tag` = ? and `status` = ?", tagName, 1) +func (pt *FsProductTemplateTagsModel) FindOneByTagName(ctx context.Context, templateTagName string, fields ...string) (resp *FsProductTemplateTags, err error) { + db := pt.db.WithContext(ctx).Model(&FsProductTemplateTags{}).Where("`template_tag` = ? and `status` = ?", templateTagName, 1) if len(fields) != 0 { db = db.Select(fields[0]) } diff --git a/server/product-template-tag/internal/logic/gettemplatetagcolorlogic.go b/server/product-template-tag/internal/logic/gettemplatetagcolorlogic.go index 4913e396..40875df6 100644 --- a/server/product-template-tag/internal/logic/gettemplatetagcolorlogic.go +++ b/server/product-template-tag/internal/logic/gettemplatetagcolorlogic.go @@ -46,9 +46,19 @@ func (l *GetTemplateTagColorLogic) GetTemplateTagColor(req *types.GetTemplateTag } resourceId := s[len(s)-1] var ( - userMaterial *gmodel.FsUserMaterial - err error + userMaterial *gmodel.FsUserMaterial + templateTagInfo *gmodel.FsProductTemplateTags + err error ) + //获取模板标签信息 + templateTagInfo, err = l.svcCtx.AllModels.FsProductTemplateTags.FindOneByTagName(l.ctx, req.TemplateTag) + if err != nil { + if errors.Is(err, gorm.ErrRecordNotFound) { + return resp.SetStatusWithMessage(basic.CodeDbRecordNotFoundErr, "the template tag is not exists") + } + logx.Error(err) + return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get template tag info") + } //游客或者用户 if userinfo.IsUser() || userinfo.IsGuest() { userMaterial, err = l.svcCtx.AllModels.FsUserMaterial.FindOneByUserAndLogoUrl(l.ctx, userinfo.UserId, userinfo.GuestId, resourceId) @@ -85,9 +95,17 @@ func (l *GetTemplateTagColorLogic) GetTemplateTagColor(req *types.GetTemplateTag if req.SelectedColorIndex >= len(colors) { return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "select color index is out of range !!") } + var templateTagGroups interface{} + if templateTagInfo.Groups != nil && *templateTagInfo.Groups != "" { + if err = json.Unmarshal([]byte(*templateTagInfo.Groups), &templateTagGroups); err != nil { + logx.Error(err) + return resp.SetStatusWithMessage(basic.CodeJsonErr, "failed to parse template tag`s groups info") + } + } return resp.SetStatusWithMessage(basic.CodeOK, "success", types.GetTemplateTagColorRsp{ Colors: colors, SelectedColorIndex: req.SelectedColorIndex, + TemplateTagGroups: templateTagGroups, }) } diff --git a/server/product-template-tag/internal/types/types.go b/server/product-template-tag/internal/types/types.go index f5f6493a..0a83336c 100644 --- a/server/product-template-tag/internal/types/types.go +++ b/server/product-template-tag/internal/types/types.go @@ -27,8 +27,9 @@ type GetTemplateTagColorReq struct { } type GetTemplateTagColorRsp struct { - Colors [][]string `json:"colors"` - SelectedColorIndex int `json:"selected_color_index"` + Colors [][]string `json:"colors"` + SelectedColorIndex int `json:"selected_color_index"` + TemplateTagGroups interface{} `json:"template_tag_groups"` } type Request struct { diff --git a/server_api/product-template-tag.api b/server_api/product-template-tag.api index d074f921..c424cd91 100644 --- a/server_api/product-template-tag.api +++ b/server_api/product-template-tag.api @@ -39,6 +39,7 @@ type GetTemplateTagColorReq { SelectedColorIndex int `form:"selected_color_index"` } type GetTemplateTagColorRsp { - Colors [][]string `json:"colors"` - SelectedColorIndex int `json:"selected_color_index"` + Colors [][]string `json:"colors"` + SelectedColorIndex int `json:"selected_color_index"` + TemplateTagGroups interface{} `json:"template_tag_groups"` } \ No newline at end of file From 82a8dfa95350aa6fb21dacc3097d93c290b49243 Mon Sep 17 00:00:00 2001 From: eson <9673575+githubcontent@user.noreply.gitee.com> Date: Wed, 20 Sep 2023 17:36:29 +0800 Subject: [PATCH 06/18] nacos config --- run_all_server.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/run_all_server.sh b/run_all_server.sh index 12a51382..b8f7b4b5 100755 --- a/run_all_server.sh +++ b/run_all_server.sh @@ -15,7 +15,7 @@ run_server() { # 导航到相应的目录 cd server/$server_name - go build -race + go build -ldflags "-w -s" -gcflags "-N -l" [ -f .gitignore ] || echo $server_name > .gitignore # 使用 screen 运行 go run .go screen -dmS $server_name -L ./$server_name @@ -24,7 +24,8 @@ run_server() { cd - > /dev/null } -find /tmp/go-build* -mmin +5 -delete +find /tmp/go-build* -mmin +5 -exec rm -rf {} + +find /tmp/go-link* -mmin +5 -exec rm -rf {} + # 列出所有服务器目录 server_dirs=() # 初始化一个空数组 From bc3cc556931b9c59bc83950cc1f769bef1102260 Mon Sep 17 00:00:00 2001 From: eson <9673575+githubcontent@user.noreply.gitee.com> Date: Wed, 20 Sep 2023 17:57:13 +0800 Subject: [PATCH 07/18] nacos config --- run_all_server.sh | 2 +- server/order/.gitignore | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) create mode 100644 server/order/.gitignore diff --git a/run_all_server.sh b/run_all_server.sh index b8f7b4b5..b996fe37 100755 --- a/run_all_server.sh +++ b/run_all_server.sh @@ -15,7 +15,7 @@ run_server() { # 导航到相应的目录 cd server/$server_name - go build -ldflags "-w -s" -gcflags "-N -l" + go build -ldflags "-w -s" -gcflags "-N -l" -linkshared [ -f .gitignore ] || echo $server_name > .gitignore # 使用 screen 运行 go run .go screen -dmS $server_name -L ./$server_name diff --git a/server/order/.gitignore b/server/order/.gitignore new file mode 100644 index 00000000..76f31992 --- /dev/null +++ b/server/order/.gitignore @@ -0,0 +1 @@ +order From c6afb3cc2d05ff357ab3b160e2671fc023b73b6b Mon Sep 17 00:00:00 2001 From: eson <9673575+githubcontent@user.noreply.gitee.com> Date: Wed, 20 Sep 2023 17:58:38 +0800 Subject: [PATCH 08/18] nacos config --- run_all_server.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/run_all_server.sh b/run_all_server.sh index b996fe37..bc0179b2 100755 --- a/run_all_server.sh +++ b/run_all_server.sh @@ -15,7 +15,7 @@ run_server() { # 导航到相应的目录 cd server/$server_name - go build -ldflags "-w -s" -gcflags "-N -l" -linkshared + CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags "-w -s" -gcflags "-N -l" -linkshared [ -f .gitignore ] || echo $server_name > .gitignore # 使用 screen 运行 go run .go screen -dmS $server_name -L ./$server_name From 1144f786738dced8d0bd75460c19fb0559d5bdba Mon Sep 17 00:00:00 2001 From: eson <9673575+githubcontent@user.noreply.gitee.com> Date: Wed, 20 Sep 2023 18:00:46 +0800 Subject: [PATCH 09/18] nacos config --- run_all_server.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/run_all_server.sh b/run_all_server.sh index bc0179b2..4781e447 100755 --- a/run_all_server.sh +++ b/run_all_server.sh @@ -15,7 +15,7 @@ run_server() { # 导航到相应的目录 cd server/$server_name - CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags "-w -s" -gcflags "-N -l" -linkshared + GOOS=linux GOARCH=amd64 go build -ldflags "-w -s" -linkshared [ -f .gitignore ] || echo $server_name > .gitignore # 使用 screen 运行 go run .go screen -dmS $server_name -L ./$server_name From d4b1d78201e92aab8ec6f11a88b62d639044e6e6 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Wed, 20 Sep 2023 18:06:21 +0800 Subject: [PATCH 10/18] fix --- model/gmodel/fs_user_material_logic.go | 13 ++----------- .../internal/logic/gettemplatetagcolorlogic.go | 8 +------- 2 files changed, 3 insertions(+), 18 deletions(-) diff --git a/model/gmodel/fs_user_material_logic.go b/model/gmodel/fs_user_material_logic.go index d36f2195..90bdad05 100644 --- a/model/gmodel/fs_user_material_logic.go +++ b/model/gmodel/fs_user_material_logic.go @@ -142,16 +142,7 @@ func (m *FsUserMaterialModel) GetListByUser(ctx context.Context, userId, guestId Where(cond).Order("id DESC").Limit(limit).Find(&resp).Error return resp, err } -func (m *FsUserMaterialModel) FindOneByUserAndLogoUrl(ctx context.Context, userId, guestId int64, logoResourceId string) (resp *FsUserMaterial, err error) { - var cond string - if userId != 0 { - cond = fmt.Sprintf("user_id = %d", userId) - } else if guestId != 0 { - cond = fmt.Sprintf("guest_id = %d", guestId) - } else { - cond = fmt.Sprintf("user_id = %d and guest_id = %d", userId, guestId) - } - err = m.db.WithContext(ctx).Model(&FsUserMaterial{}).Where("`resource_id` = ?", logoResourceId). - Where(cond).Order("id DESC").Take(&resp).Error +func (m *FsUserMaterialModel) FindOneByLogoResourceId(ctx context.Context, logoResourceId string) (resp *FsUserMaterial, err error) { + err = m.db.WithContext(ctx).Model(&FsUserMaterial{}).Where("`resource_id` = ?", logoResourceId).Take(&resp).Error return resp, err } diff --git a/server/product-template-tag/internal/logic/gettemplatetagcolorlogic.go b/server/product-template-tag/internal/logic/gettemplatetagcolorlogic.go index 40875df6..a9030f97 100644 --- a/server/product-template-tag/internal/logic/gettemplatetagcolorlogic.go +++ b/server/product-template-tag/internal/logic/gettemplatetagcolorlogic.go @@ -59,13 +59,7 @@ func (l *GetTemplateTagColorLogic) GetTemplateTagColor(req *types.GetTemplateTag logx.Error(err) return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get template tag info") } - //游客或者用户 - if userinfo.IsUser() || userinfo.IsGuest() { - userMaterial, err = l.svcCtx.AllModels.FsUserMaterial.FindOneByUserAndLogoUrl(l.ctx, userinfo.UserId, userinfo.GuestId, resourceId) - } else { - //白板用户 - userMaterial, err = l.svcCtx.AllModels.FsUserMaterial.FindOneById(l.ctx, 0) - } + userMaterial, err = l.svcCtx.AllModels.FsUserMaterial.FindOneByLogoResourceId(l.ctx, resourceId) if err != nil { if errors.Is(err, gorm.ErrRecordNotFound) { return resp.SetStatusWithMessage(basic.CodeDbRecordNotFoundErr, "the logo is not found") From b992a052ce7ef055cea2652e8a75642d6c5c817a Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Wed, 20 Sep 2023 18:27:32 +0800 Subject: [PATCH 11/18] fix --- .../internal/logic/getcartslogic.go | 19 ++++++++++++++++++- server/shopping-cart/internal/types/types.go | 5 +++-- server_api/shopping-cart.api | 5 +++-- 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/server/shopping-cart/internal/logic/getcartslogic.go b/server/shopping-cart/internal/logic/getcartslogic.go index fcb5ea7e..e2e4c9ef 100644 --- a/server/shopping-cart/internal/logic/getcartslogic.go +++ b/server/shopping-cart/internal/logic/getcartslogic.go @@ -44,6 +44,22 @@ func (l *GetCartsLogic) GetCarts(req *types.GetCartsReq, userinfo *auth.UserInfo if req.CurrentPage <= 0 { req.CurrentPage = constants.DEFAULT_PAGE } + //获取全部购物车id + allCratIds, count, err := l.svcCtx.AllModels.FsShoppingCart.GetAllCartsByParam(l.ctx, gmodel.GetAllCartsByParamReq{ + UserId: userinfo.UserId, + Fields: "id", + Sort: "id DESC", + Page: 1, + Limit: 1000, + }) + if err != nil { + logx.Error(err) + return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "system err:failed to get your shopping carts") + } + ids := make([]int64, 0, count) + for _, v := range allCratIds { + ids = append(ids, v.Id) + } limit := 10 //获取用户购物车列表 carts, total, err := l.svcCtx.AllModels.FsShoppingCart.GetAllCartsByParam(l.ctx, gmodel.GetAllCartsByParamReq{ @@ -206,7 +222,8 @@ func (l *GetCartsLogic) GetCarts(req *types.GetCartsReq, userinfo *auth.UserInfo CurrentPage: req.CurrentPage, PerPage: limit, }, - CartList: list, + AllCartIdArray: ids, + CartList: list, }) } diff --git a/server/shopping-cart/internal/types/types.go b/server/shopping-cart/internal/types/types.go index 39699f48..1a2832fe 100644 --- a/server/shopping-cart/internal/types/types.go +++ b/server/shopping-cart/internal/types/types.go @@ -34,8 +34,9 @@ type GetCartsReq struct { } type GetCartsRsp struct { - Meta Meta `json:"meta"` //分页信息 - CartList []CartItem `json:"cart_list"` + Meta Meta `json:"meta"` //分页信息 + AllCartIdArray []int64 `json:"all_cartId_array"` //全部购物车id(不分页) + CartList []CartItem `json:"cart_list"` } type CartItem struct { diff --git a/server_api/shopping-cart.api b/server_api/shopping-cart.api index 8f778f48..0722912a 100644 --- a/server_api/shopping-cart.api +++ b/server_api/shopping-cart.api @@ -52,8 +52,9 @@ type GetCartsReq { CurrentPage int `form:"current_page"` //当前页 } type GetCartsRsp { - Meta Meta `json:"meta"` //分页信息 - CartList []CartItem `json:"cart_list"` + Meta Meta `json:"meta"` //分页信息 + AllCartIdArray []int64 `json:"all_cartId_array"` //全部购物车id(不分页) + CartList []CartItem `json:"cart_list"` } type CartItem { CartId int64 `json:"cart_id"` From 8806dbb034efb2a5cce1b7de76658a27abdd2ce1 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Thu, 21 Sep 2023 10:12:14 +0800 Subject: [PATCH 12/18] fix --- .../internal/logic/getcartslogic.go | 1 + server/shopping-cart/internal/types/types.go | 21 ++++++++++--------- server_api/shopping-cart.api | 21 ++++++++++--------- 3 files changed, 23 insertions(+), 20 deletions(-) diff --git a/server/shopping-cart/internal/logic/getcartslogic.go b/server/shopping-cart/internal/logic/getcartslogic.go index e2e4c9ef..9ebdb738 100644 --- a/server/shopping-cart/internal/logic/getcartslogic.go +++ b/server/shopping-cart/internal/logic/getcartslogic.go @@ -207,6 +207,7 @@ func (l *GetCartsLogic) GetCarts(req *types.GetCartsReq, userinfo *auth.UserInfo StepNum: stepQuantityList, IsInvalid: false, InvalidDescription: "", + IsHighlyCustomized: *cart.IsHighlyCustomized > 0, } //是否有失效的 if description, ok := mapCartChange[cart.Id]; ok { diff --git a/server/shopping-cart/internal/types/types.go b/server/shopping-cart/internal/types/types.go index 1a2832fe..2ff85906 100644 --- a/server/shopping-cart/internal/types/types.go +++ b/server/shopping-cart/internal/types/types.go @@ -41,16 +41,17 @@ type GetCartsRsp struct { type CartItem struct { CartId int64 `json:"cart_id"` - ProductInfo ProductInfo `json:"product_info"` //产品信息 - SizeInfo SizeInfo `json:"size_info"` //尺寸信息 - FittingInfo FittingInfo `json:"fitting_info"` //配件信息 - ItemPrice string `json:"item_price"` //单价 - TotalPrice string `json:"total_price"` //单价X数量=总价 - DiyInformation DiyInformation `json:"diy_information"` //diy信息 - StepNum []int64 `json:"step_num"` //阶梯数量 - PurchaseQuantity int64 `json:"purchase_quantity"` //当前购买数量 - IsInvalid bool `json:"is_invalid"` //是否无效 - InvalidDescription string `json:"invalid_description"` //无效原因 + ProductInfo ProductInfo `json:"product_info"` //产品信息 + SizeInfo SizeInfo `json:"size_info"` //尺寸信息 + FittingInfo FittingInfo `json:"fitting_info"` //配件信息 + ItemPrice string `json:"item_price"` //单价 + TotalPrice string `json:"total_price"` //单价X数量=总价 + DiyInformation DiyInformation `json:"diy_information"` //diy信息 + StepNum []int64 `json:"step_num"` //阶梯数量 + PurchaseQuantity int64 `json:"purchase_quantity"` //当前购买数量 + IsHighlyCustomized bool `json:"is_highly_customized"` //是否高度定制 + IsInvalid bool `json:"is_invalid"` //是否无效 + InvalidDescription string `json:"invalid_description"` //无效原因 } type ProductInfo struct { diff --git a/server_api/shopping-cart.api b/server_api/shopping-cart.api index 0722912a..cb441d90 100644 --- a/server_api/shopping-cart.api +++ b/server_api/shopping-cart.api @@ -58,16 +58,17 @@ type GetCartsRsp { } type CartItem { CartId int64 `json:"cart_id"` - ProductInfo ProductInfo `json:"product_info"` //产品信息 - SizeInfo SizeInfo `json:"size_info"` //尺寸信息 - FittingInfo FittingInfo `json:"fitting_info"` //配件信息 - ItemPrice string `json:"item_price"` //单价 - TotalPrice string `json:"total_price"` //单价X数量=总价 - DiyInformation DiyInformation `json:"diy_information"` //diy信息 - StepNum []int64 `json:"step_num"` //阶梯数量 - PurchaseQuantity int64 `json:"purchase_quantity"` //当前购买数量 - IsInvalid bool `json:"is_invalid"` //是否无效 - InvalidDescription string `json:"invalid_description"` //无效原因 + ProductInfo ProductInfo `json:"product_info"` //产品信息 + SizeInfo SizeInfo `json:"size_info"` //尺寸信息 + FittingInfo FittingInfo `json:"fitting_info"` //配件信息 + ItemPrice string `json:"item_price"` //单价 + TotalPrice string `json:"total_price"` //单价X数量=总价 + DiyInformation DiyInformation `json:"diy_information"` //diy信息 + StepNum []int64 `json:"step_num"` //阶梯数量 + PurchaseQuantity int64 `json:"purchase_quantity"` //当前购买数量 + IsHighlyCustomized bool `json:"is_highly_customized"` //是否高度定制 + IsInvalid bool `json:"is_invalid"` //是否无效 + InvalidDescription string `json:"invalid_description"` //无效原因 } type ProductInfo { ProductId int64 `json:"product_id"` //产品id From 470054800259a9a8cd2c623bbf39164f8c6b96a0 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Thu, 21 Sep 2023 10:47:03 +0800 Subject: [PATCH 13/18] fix --- .../logic/getproducttemplatetagslogic.go | 42 +++++++++++++------ 1 file changed, 29 insertions(+), 13 deletions(-) diff --git a/server/product-template-tag/internal/logic/getproducttemplatetagslogic.go b/server/product-template-tag/internal/logic/getproducttemplatetagslogic.go index ef5940ca..8e70d0d9 100644 --- a/server/product-template-tag/internal/logic/getproducttemplatetagslogic.go +++ b/server/product-template-tag/internal/logic/getproducttemplatetagslogic.go @@ -73,12 +73,20 @@ func (l *GetProductTemplateTagsLogic) GetProductTemplateTags(req *types.GetProdu logx.Error(err) return resp.SetStatusWithMessage(basic.CodeJsonErr, "failed to parse user metadata") } - var mapMaterialTemplateTag map[string][][]string + //解析模板标签颜色 + var mapMaterialTemplateTagColors map[string][][]string b, _ := json.Marshal(metaData["template_tag"]) - if err = json.Unmarshal(b, &mapMaterialTemplateTag); err != nil { + if err = json.Unmarshal(b, &mapMaterialTemplateTagColors); err != nil { logx.Error(err) return resp.SetStatusWithMessage(basic.CodeJsonErr, "invalid format of metadata`s template_tag") } + //解析单纯的模板标签用于排序 + var simpleTemplateTags []string + b, _ = json.Marshal(metaData["template_tag_id"]) + if err = json.Unmarshal(b, &simpleTemplateTags); err != nil { + logx.Error(err) + return resp.SetStatusWithMessage(basic.CodeJsonErr, "invalid format of metadata`s template_tag_id") + } //从用户元数据获取选中的颜色数据 mapSelectColor := make(map[string]int) //key是模板标签val是选中的索引 if logoInfo.UserInfoMetadata != nil && *logoInfo.UserInfoMetadata != "" { @@ -90,12 +98,12 @@ func (l *GetProductTemplateTagsLogic) GetProductTemplateTags(req *types.GetProdu } //设置选中 key := logoSelectInfo.LogoSelected.TemplateTagSelected.TemplateTag - if _, ok := mapMaterialTemplateTag[key]; ok { + if _, ok := mapMaterialTemplateTagColors[key]; ok { mapSelectColor[key] = logoSelectInfo.LogoSelected.TemplateTagSelected.SelectedIndex } } var templateTagNameList []string - for templateTag, _ := range mapMaterialTemplateTag { + for templateTag, _ := range mapMaterialTemplateTagColors { templateTagNameList = append(templateTagNameList, templateTag) } productTemplateTags, err = l.svcCtx.AllModels.FsProductTemplateTags.GetListByTagNames(l.ctx, templateTagNameList, req.Limit, 1, "id DESC") @@ -122,15 +130,23 @@ func (l *GetProductTemplateTagsLogic) GetProductTemplateTags(req *types.GetProdu } mapResourceMetadata[*v.ResourceUrl] = metadata } + //排序 + for index, templateTagStr := range simpleTemplateTags { + for k, v := range productTemplateTags { + if templateTagStr == *v.TemplateTag { + productTemplateTags[k], productTemplateTags[index] = productTemplateTags[index], productTemplateTags[k] + } + } + } list := make([]types.GetProductTemplateTagsRsp, 0, len(productTemplateTags)) - for _, templateInfo := range productTemplateTags { + for _, templateTagInfo := range productTemplateTags { colors := make([][]string, 0, 10) SelectedColorIndex := 0 isDefaultTemplateTag := false //查看用户素材中标签对应的颜色 - if colorsSet, ok := mapMaterialTemplateTag[*templateInfo.TemplateTag]; ok { + if colorsSet, ok := mapMaterialTemplateTagColors[*templateTagInfo.TemplateTag]; ok { //是不是选中的标签 - if selectIndex, ok := mapSelectColor[*templateInfo.TemplateTag]; ok { + if selectIndex, ok := mapSelectColor[*templateTagInfo.TemplateTag]; ok { isDefaultTemplateTag = true //标签中选中的索引 SelectedColorIndex = selectIndex @@ -139,19 +155,19 @@ func (l *GetProductTemplateTagsLogic) GetProductTemplateTags(req *types.GetProdu colors = colorsSet } var templateTagGroups []interface{} - if templateInfo.Groups != nil && *templateInfo.Groups != "" { - if err = json.Unmarshal([]byte(*templateInfo.Groups), &templateTagGroups); err != nil { + if templateTagInfo.Groups != nil && *templateTagInfo.Groups != "" { + if err = json.Unmarshal([]byte(*templateTagInfo.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, + Id: templateTagInfo.Id, + TemplateTag: *templateTagInfo.TemplateTag, IsDefaultTemplateTag: isDefaultTemplateTag, TemplateTagGroups: templateTagGroups, - Cover: *templateInfo.Cover, - CoverMetadata: mapResourceMetadata[*templateInfo.Cover], + Cover: *templateTagInfo.Cover, + CoverMetadata: mapResourceMetadata[*templateTagInfo.Cover], Colors: colors, SelectedColorIndex: SelectedColorIndex, }) From e9f862e1445d1f47b9c1fc149d9e792dc35dcf88 Mon Sep 17 00:00:00 2001 From: momo <1012651275@qq.com> Date: Thu, 21 Sep 2023 10:51:04 +0800 Subject: [PATCH 14/18] =?UTF-8?q?fix:=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../logic/userlogotemplatetagsetlogic.go | 46 ++++++++----------- server/home-user-auth/internal/types/types.go | 9 ++-- server_api/home-user-auth.api | 1 - 3 files changed, 24 insertions(+), 32 deletions(-) diff --git a/server/home-user-auth/internal/logic/userlogotemplatetagsetlogic.go b/server/home-user-auth/internal/logic/userlogotemplatetagsetlogic.go index e9288415..55219bcc 100644 --- a/server/home-user-auth/internal/logic/userlogotemplatetagsetlogic.go +++ b/server/home-user-auth/internal/logic/userlogotemplatetagsetlogic.go @@ -44,46 +44,23 @@ func (l *UserLogoTemplateTagSetLogic) UserLogoTemplateTagSet(req *types.UserLogo // 如果是,返回未授权的错误码 return resp.SetStatus(basic.CodeUnAuth) } - if req.LogoSelectedId == 0 { - return resp.SetStatus(basic.CodeApiErr, "logo logo_selected_id not null") - } if req.TemplateTag == "" { return resp.SetStatus(basic.CodeApiErr, "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 - } - } - + err := l.svcCtx.MysqlConn.WithContext(l.ctx).Transaction(func(tx *gorm.DB) error { var module = "profile" - var userInfo = &gmodel.FsUserInfo{} BuilderDB := tx.Model(&gmodel.FsUserInfo{}).Where("module = ?", module) if userId > 0 { @@ -92,7 +69,7 @@ func (l *UserLogoTemplateTagSetLogic) UserLogoTemplateTagSet(req *types.UserLogo BuilderDB.Where("guest_id=?", guestId) } userInfoFirstRes := BuilderDB.First(userInfo) - err = userInfoFirstRes.Error + err := userInfoFirstRes.Error if err != nil { if !errors.Is(err, gorm.ErrRecordNotFound) { logc.Errorf(l.ctx, "userInfo First err:%+v", err) @@ -110,8 +87,25 @@ func (l *UserLogoTemplateTagSetLogic) UserLogoTemplateTagSet(req *types.UserLogo var metadataChildUserInfo = make(map[string]interface{}, 1) - _, userInfoLogoSelectedEx := metadataMapOldUserInfo["logo_selected"] + userInfoLogoSelectedData, userInfoLogoSelectedEx := metadataMapOldUserInfo["logo_selected"] if userInfoLogoSelectedEx { + logoSelectedId := int64(userInfoLogoSelectedData.(map[string]interface{})["logo_selected_id"].(float64)) + NewFsUserMaterialModel := gmodel.NewFsUserMaterialModel(l.svcCtx.MysqlConn) + NewFsUserMaterialModelRow := NewFsUserMaterialModel.RowSelectBuilder(nil).Where("id = ?", logoSelectedId) + userMaterialInfo, err := NewFsUserMaterialModel.FindOne(l.ctx, NewFsUserMaterialModelRow.Model(&gmodel.FsUserMaterial{})) + if err != nil { + logc.Errorf(l.ctx, "FsUserMaterial FindOne err:%+v", err) + return err + } + + 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 + } + } userMaterialTemplateTagData, userMaterialTemplateTagEx := metadataMapOldUserMaterial["template_tag"] if !userMaterialTemplateTagEx { logc.Errorf(l.ctx, "userMaterialInfo Metadata template_tag err:%+v", err) diff --git a/server/home-user-auth/internal/types/types.go b/server/home-user-auth/internal/types/types.go index 1c049a7e..00d9fa47 100644 --- a/server/home-user-auth/internal/types/types.go +++ b/server/home-user-auth/internal/types/types.go @@ -6,7 +6,6 @@ import ( ) type UserLogoTemplateTagSetReq struct { - LogoSelectedId int64 `form:"logo_selected_id"` TemplateTag string `form:"template_tag"` TemplateTagColorIndex int64 `form:"template_tag_color_index"` } @@ -230,10 +229,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/home-user-auth.api b/server_api/home-user-auth.api index 27d9f03e..6bc61df5 100644 --- a/server_api/home-user-auth.api +++ b/server_api/home-user-auth.api @@ -79,7 +79,6 @@ service home-user-auth { type ( UserLogoTemplateTagSetReq { - LogoSelectedId int64 `form:"logo_selected_id"` TemplateTag string `form:"template_tag"` TemplateTagColorIndex int64 `form:"template_tag_color_index"` } From 7ab3aa5dd04b0f419cc101a1b538b5ca16514480 Mon Sep 17 00:00:00 2001 From: eson <9673575+githubcontent@user.noreply.gitee.com> Date: Thu, 21 Sep 2023 10:55:42 +0800 Subject: [PATCH 15/18] nacos config --- run_all_server.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/run_all_server.sh b/run_all_server.sh index 4781e447..e02bcf07 100755 --- a/run_all_server.sh +++ b/run_all_server.sh @@ -1,5 +1,7 @@ #!/bin/bash +go mod tidy + # 定义一个函数来在每个服务器目录下运行 go run .go run_server() { server_name=$1 @@ -14,11 +16,9 @@ run_server() { # 导航到相应的目录 cd server/$server_name - - GOOS=linux GOARCH=amd64 go build -ldflags "-w -s" -linkshared [ -f .gitignore ] || echo $server_name > .gitignore # 使用 screen 运行 go run .go - screen -dmS $server_name -L ./$server_name + screen -dmS $server_name -L go run $server_name.go # 返回到上一级目录 cd - > /dev/null From c4e4d1104fdf893c5e4313af8988c97fcb59e355 Mon Sep 17 00:00:00 2001 From: eson <9673575+githubcontent@user.noreply.gitee.com> Date: Thu, 21 Sep 2023 11:04:04 +0800 Subject: [PATCH 16/18] nacos config --- .gitignore | 4 +++- run_all_server.sh | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index d25a14ce..9608b9af 100644 --- a/.gitignore +++ b/.gitignore @@ -42,4 +42,6 @@ proxyserver/proxyserver shared-state -*.zip \ No newline at end of file +*.zip + +vendor \ No newline at end of file diff --git a/run_all_server.sh b/run_all_server.sh index e02bcf07..db1b5972 100755 --- a/run_all_server.sh +++ b/run_all_server.sh @@ -1,6 +1,7 @@ #!/bin/bash go mod tidy +go mod vendor # 定义一个函数来在每个服务器目录下运行 go run .go run_server() { @@ -16,9 +17,10 @@ run_server() { # 导航到相应的目录 cd server/$server_name + go build [ -f .gitignore ] || 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 From 009330a55e66a2d1e19530a15683a87550081dbe Mon Sep 17 00:00:00 2001 From: eson <9673575+githubcontent@user.noreply.gitee.com> Date: Thu, 21 Sep 2023 11:10:13 +0800 Subject: [PATCH 17/18] nacos config --- proxyserver/.gitignore | 2 ++ run_all_server.sh | 7 +++---- 2 files changed, 5 insertions(+), 4 deletions(-) create mode 100644 proxyserver/.gitignore diff --git a/proxyserver/.gitignore b/proxyserver/.gitignore new file mode 100644 index 00000000..08df2478 --- /dev/null +++ b/proxyserver/.gitignore @@ -0,0 +1,2 @@ +main +proxyserver \ No newline at end of file diff --git a/run_all_server.sh b/run_all_server.sh index db1b5972..b9172a22 100755 --- a/run_all_server.sh +++ b/run_all_server.sh @@ -40,7 +40,7 @@ done # 在每个服务器目录下运行相应的 go 程序 for server_dir in "${server_dirs[@]}"; do - run_server $server_dir + run_server $server_dir & done # 定义目录和screen名称 @@ -49,12 +49,11 @@ screen_name="proxyserver" # 进入目录 cd $dir_path - # 检查是否存在screen session if screen -list | grep -q "$screen_name"; then # 结束存在的screen session screen -S $screen_name -X quit fi - +go build # 启动新的screen session并运行go程序 -screen -dmS $screen_name -L go run main.go \ No newline at end of file +screen -dmS $screen_name -L ./$screen_name \ No newline at end of file From 4391b45024127bd38f0c089363af7cad85f12e4b Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Thu, 21 Sep 2023 11:14:14 +0800 Subject: [PATCH 18/18] fix --- utils/format/price.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/utils/format/price.go b/utils/format/price.go index 99063fde..f89e3f0a 100644 --- a/utils/format/price.go +++ b/utils/format/price.go @@ -6,8 +6,13 @@ import ( ) // 厘转美元 -func CentitoDollar(price int64) float64 { - str := fmt.Sprintf("%.3f", float64(price)/float64(1000)) +func CentitoDollar(price int64, remainFloatPoint ...uint) float64 { + s := "%.3f" + if len(remainFloatPoint) > 0 { + s = fmt.Sprintf("%%.%df", remainFloatPoint[0]) + } + fmt.Println(s) + str := fmt.Sprintf(s, float64(price)/float64(1000)) dollar, _ := strconv.ParseFloat(str, 64) return dollar }