From da40278e26a1ee5e1e0cbaf6b62afef6aeb0e68a Mon Sep 17 00:00:00 2001 From: eson <9673575+githubcontent@user.noreply.gitee.com> Date: Wed, 30 Aug 2023 16:28:55 +0800 Subject: [PATCH 01/15] fix --- server/auth/internal/logic/useremailconfirmationlogic.go | 3 ++- server/auth/internal/logic/usergoogleloginlogic.go | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/server/auth/internal/logic/useremailconfirmationlogic.go b/server/auth/internal/logic/useremailconfirmationlogic.go index 2d667fd1..3f6b9e51 100644 --- a/server/auth/internal/logic/useremailconfirmationlogic.go +++ b/server/auth/internal/logic/useremailconfirmationlogic.go @@ -120,11 +120,12 @@ func (l *UserEmailConfirmationLogic) UserEmailConfirmation(req *types.RequestEma logx.Info("success", token.TraceId) case string(auth.PLATFORM_FACEBOOK): + case string(auth.PLATFORM_FUSEN): // log.Println("aaaa", token) user, err := l.svcCtx.AllModels.FsUser.RegisterByFusen(l.ctx, token) if err != nil && err != gorm.ErrRecordNotFound { - logx.Error(err, ":", token.TraceId) + logx.Error(err) return resp.SetStatusWithMessage(basic.CodeDbSqlErr, err.Error()) } err = FinishRegister(l.svcCtx, user, token) diff --git a/server/auth/internal/logic/usergoogleloginlogic.go b/server/auth/internal/logic/usergoogleloginlogic.go index d709ee11..c39ecc40 100644 --- a/server/auth/internal/logic/usergoogleloginlogic.go +++ b/server/auth/internal/logic/usergoogleloginlogic.go @@ -132,7 +132,7 @@ func (l *UserGoogleLoginLogic) AfterLogic(w http.ResponseWriter, r *http.Request if resp.Code == 200 { rurl := fmt.Sprintf( - "http://www.fusen.3718.cn/"+"/oauth?token=%s&is_registered=%t®ister_token=%s", + "http://www.fusen.3718.cn"+"/oauth?token=%s&is_registered=%t®ister_token=%s", l.token, l.isRegistered, l.registerToken, From b2c68a9dc1847c6faa958466fa72c9db19afbc78 Mon Sep 17 00:00:00 2001 From: eson <9673575+githubcontent@user.noreply.gitee.com> Date: Wed, 30 Aug 2023 16:38:36 +0800 Subject: [PATCH 02/15] fix --- server/auth/internal/logic/usergoogleloginlogic.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/server/auth/internal/logic/usergoogleloginlogic.go b/server/auth/internal/logic/usergoogleloginlogic.go index c39ecc40..4a17d4ef 100644 --- a/server/auth/internal/logic/usergoogleloginlogic.go +++ b/server/auth/internal/logic/usergoogleloginlogic.go @@ -131,6 +131,8 @@ func (l *UserGoogleLoginLogic) AfterLogic(w http.ResponseWriter, r *http.Request if resp.Code == 200 { + logx.Info(l) + rurl := fmt.Sprintf( "http://www.fusen.3718.cn"+"/oauth?token=%s&is_registered=%t®ister_token=%s", l.token, From 2e790cd255a7ac2b57308994203f35feb3987d0a Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Wed, 30 Aug 2023 16:42:49 +0800 Subject: [PATCH 03/15] fix --- .../internal/logic/gettagproductlistlogic.go | 241 ++++++++++-------- 1 file changed, 136 insertions(+), 105 deletions(-) diff --git a/server/product/internal/logic/gettagproductlistlogic.go b/server/product/internal/logic/gettagproductlistlogic.go index b69736d0..b08375c3 100644 --- a/server/product/internal/logic/gettagproductlistlogic.go +++ b/server/product/internal/logic/gettagproductlistlogic.go @@ -85,117 +85,26 @@ func (l *GetTagProductListLogic) GetTagProductList(req *types.GetTagProductListR var ( productList []gmodel.FsProduct //产品列表(select 字段需要看查询的地方) mapTagProp = make(map[int64][]types.CoverDefaultItem) - productOptionalPartList []gmodel.GetGroupPartListByProductIdsRsp //产品配件列表 mapProductHaveOptionFitting = make(map[int64]struct{}) - productPriceList []gmodel.GetPriceListByProductIdsRsp //产品价格列表(select 字段需要看查询的地方) - mapProductMinPrice = make(map[int64]int64) //产品最小价格map - productTemplatesV2 []gmodel.FsProductTemplateV2 //产品模板列表(select 字段需要看查询的地方) - productSizeCountList []gmodel.CountProductSizeByStatusRsp //产品尺寸数量列表(select 字段需要看查询的地方) - mapProductSizeCount = make(map[int64]int64) //产品尺寸数量map - mapProductTemplate = make(map[int64]int64) //产品模板map + mapProductMinPrice = make(map[int64]int64) //产品最小价格map + mapProductSizeCount = make(map[int64]int64) //产品尺寸数量map + mapProductTemplate = make(map[int64]int64) //产品模板map ) //携带产品 if req.WithProduct { - //查询符合的产品列表 - pIsDel := int64(0) - pStatus := int64(1) - pIsShelf := int64(1) - //获取产品列表 - productList, err = l.svcCtx.AllModels.FsProduct.GetProductListByParams(l.ctx, - gmodel.GetProductListByParamsReq{ - Type: typeIds, - IsDel: &pIsDel, - IsShelf: &pIsShelf, - Status: &pStatus, - OrderBy: "`is_recommend` DESC,`sort` ASC", - }) + productList, err = l.getProductRelationInfo(getProductRelationInfoReq{ + Ctx: l.ctx, + TemplateTag: req.TemplateTag, + TypeIds: typeIds, + MapTagProp: mapTagProp, + MapProductHaveOptionFitting: mapProductHaveOptionFitting, + MapProductMinPrice: mapProductMinPrice, + MapProductSizeCount: mapProductSizeCount, + MapProductTemplate: mapProductTemplate, + }) if err != nil { logx.Error(err) - return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to get product list") - } - productIds := make([]int64, 0, len(productList)) - for _, product := range productList { - productIds = append(productIds, product.Id) - } - //获取商品可选配件 - productOptionalPartList, err = l.svcCtx.AllModels.FsProductModel3d.GetGroupPartListByProductIds(l.ctx, productIds) - if err != nil { - logx.Error(err) - return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get product part list") - } - //存储有配件的map - for _, partList := range productOptionalPartList { - partList.PartList = strings.Trim(partList.PartList, " ") - partList.PartList = strings.Trim(partList.PartList, ",") - if partList.PartList == "" { - continue - } - mapProductHaveOptionFitting[partList.ProductId] = struct{}{} - } - //获取产品标签相关属性 - productTagPropList, err := l.svcCtx.AllModels.FsProductTagProp.GetTagPropByProductIdsWithProductTag(l.ctx, productIds) - if err != nil { - logx.Error(err) - return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get product tag property") - } - for _, v := range productTagPropList { - mapTagProp[*v.ProductId] = append(mapTagProp[*v.ProductId], types.CoverDefaultItem{ - Tag: v.TemplateTag, - Cover: *v.Cover, - }) - } - //获取产品价格列表 - productPriceList, err = l.svcCtx.AllModels.FsProductPrice.GetSimplePriceListByProductIds(l.ctx, productIds) - if err != nil { - logx.Error(err) - return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to get product min price list") - } - //存储产品最小价格 - for _, v := range productPriceList { - priceStrSlic := strings.Split(v.Price, ",") - priceSlice, err := format.StrSlicToIntSlice(priceStrSlic) - if err != nil { - logx.Error(err) - return resp.SetStatusWithMessage(basic.CodeServiceErr, err.Error()) - } - if len(priceSlice) == 0 { - continue - } - //正序排序价格(注意排序后的阶梯价格不能用作阶梯数量价格计算) - sort.Ints(priceSlice) - if min, ok := mapProductMinPrice[v.ProductId]; ok { - if min > int64(priceSlice[0]) { - mapProductMinPrice[v.ProductId] = int64(priceSlice[0]) - } - } else { - mapProductMinPrice[v.ProductId] = int64(priceSlice[0]) - } - } - //获取模板(只是获取产品product_id,id) - if req.TemplateTag != "" { //指定模板tag - productTemplatesV2, err = l.svcCtx.AllModels.FsProductTemplateV2.FindAllByProductIdsTemplateTag(l.ctx, productIds, req.TemplateTag, "sort ASC", "product_id,id") - } else { //没指定模板tag - productTemplatesV2, err = l.svcCtx.AllModels.FsProductTemplateV2.FindAllByProductIds(l.ctx, productIds, "sort ASC", "product_id,id") - } - if err != nil { - logx.Error(err) - return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to get product templates") - } - //只存第一个 - for _, v := range productTemplatesV2 { - if _, ok := mapProductTemplate[*v.ProductId]; ok { - continue - } - mapProductTemplate[*v.ProductId] = v.Id - } - //获取产品尺寸数量 - productSizeCountList, err = l.svcCtx.AllModels.FsProductSize.GetGroupProductSizeByStatus(l.ctx, productIds, 1) - if err != nil { - logx.Error(err) - return resp.SetStatusWithMessage(basic.CodeServiceErr, "get product size count err") - } - for _, v := range productSizeCountList { - mapProductSizeCount[v.ProductId] = v.Num + return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to get product series info") } } //map tag菜单 @@ -227,6 +136,128 @@ func (l *GetTagProductListLogic) GetTagProductList(req *types.GetTagProductListR }) } +// 如果携带产品,就查询产品相关信息 +type getProductRelationInfoReq struct { + Ctx context.Context + TemplateTag string + TypeIds []int64 + MapTagProp map[int64][]types.CoverDefaultItem + MapProductHaveOptionFitting map[int64]struct{} + MapProductMinPrice map[int64]int64 + MapProductSizeCount map[int64]int64 + MapProductTemplate map[int64]int64 +} + +func (l *GetTagProductListLogic) getProductRelationInfo(req getProductRelationInfoReq) (productList []gmodel.FsProduct, err error) { + var ( + productTemplatesV2List []gmodel.FsProductTemplateV2 + productSizeCountList []gmodel.CountProductSizeByStatusRsp + productOptionalPartList []gmodel.GetGroupPartListByProductIdsRsp + ) + //查询符合的产品列表 + pIsDel := int64(0) + pStatus := int64(1) + pIsShelf := int64(1) + //获取产品列表 + productList, err = l.svcCtx.AllModels.FsProduct.GetProductListByParams(l.ctx, + gmodel.GetProductListByParamsReq{ + Type: req.TypeIds, + IsDel: &pIsDel, + IsShelf: &pIsShelf, + Status: &pStatus, + OrderBy: "`is_recommend` DESC,`sort` ASC", + }) + if err != nil { + logx.Error(err) + return nil, errors.New("failed to get product list") + } + productIds := make([]int64, 0, len(productList)) + for _, product := range productList { + productIds = append(productIds, product.Id) + } + //获取商品可选配件 + productOptionalPartList, err = l.svcCtx.AllModels.FsProductModel3d.GetGroupPartListByProductIds(l.ctx, productIds) + if err != nil { + logx.Error(err) + return nil, errors.New("failed to get product part list") + } + //存储有配件的map + for _, partList := range productOptionalPartList { + partList.PartList = strings.Trim(partList.PartList, " ") + partList.PartList = strings.Trim(partList.PartList, ",") + if partList.PartList == "" { + continue + } + req.MapProductHaveOptionFitting[partList.ProductId] = struct{}{} + } + //获取产品标签相关属性 + productTagPropList, err := l.svcCtx.AllModels.FsProductTagProp.GetTagPropByProductIdsWithProductTag(l.ctx, productIds) + if err != nil { + logx.Error(err) + return nil, errors.New("failed to get product tag property") + } + for _, v := range productTagPropList { + req.MapTagProp[*v.ProductId] = append(req.MapTagProp[*v.ProductId], types.CoverDefaultItem{ + Tag: v.TemplateTag, + Cover: *v.Cover, + }) + } + //获取产品价格列表 + productPriceList, err := l.svcCtx.AllModels.FsProductPrice.GetSimplePriceListByProductIds(l.ctx, productIds) + if err != nil { + logx.Error(err) + return nil, errors.New("failed to get product min price list") + } + //存储产品最小价格 + for _, v := range productPriceList { + priceStrSlic := strings.Split(v.Price, ",") + priceSlice, err := format.StrSlicToIntSlice(priceStrSlic) + if err != nil { + logx.Error(err) + return nil, errors.New("parse price err") + } + if len(priceSlice) == 0 { + continue + } + //正序排序价格(注意排序后的阶梯价格不能用作阶梯数量价格计算) + sort.Ints(priceSlice) + if min, ok := req.MapProductMinPrice[v.ProductId]; ok { + if min > int64(priceSlice[0]) { + req.MapProductMinPrice[v.ProductId] = int64(priceSlice[0]) + } + } else { + req.MapProductMinPrice[v.ProductId] = int64(priceSlice[0]) + } + } + //获取模板(只是获取产品product_id,id) + if req.TemplateTag != "" { //指定模板tag + productTemplatesV2List, err = l.svcCtx.AllModels.FsProductTemplateV2.FindAllByProductIdsTemplateTag(l.ctx, productIds, req.TemplateTag, "sort ASC", "product_id,id") + } else { //没指定模板tag + productTemplatesV2List, err = l.svcCtx.AllModels.FsProductTemplateV2.FindAllByProductIds(l.ctx, productIds, "sort ASC", "product_id,id") + } + if err != nil { + logx.Error(err) + return nil, errors.New("failed to get product templates") + } + //只存第一个 + for _, v := range productTemplatesV2List { + if _, ok := req.MapProductTemplate[*v.ProductId]; ok { + continue + } + req.MapProductTemplate[*v.ProductId] = v.Id + } + //获取产品尺寸数量 + productSizeCountList, err = l.svcCtx.AllModels.FsProductSize.GetGroupProductSizeByStatus(l.ctx, productIds, 1) + if err != nil { + logx.Error(err) + return nil, errors.New("get product size count err") + } + for _, v := range productSizeCountList { + req.MapProductSizeCount[v.ProductId] = v.Num + } + return productList, nil +} + // 处理tag菜单数据 type dealWithTagMenuDataReq struct { TagList []gmodel.FsTags From 1f144300520e2c7b41b82afbe2b6d3b855d55371 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Wed, 30 Aug 2023 16:45:45 +0800 Subject: [PATCH 04/15] fix --- server/product/internal/logic/gettagproductlistlogic.go | 1 + 1 file changed, 1 insertion(+) diff --git a/server/product/internal/logic/gettagproductlistlogic.go b/server/product/internal/logic/gettagproductlistlogic.go index b08375c3..b1132393 100644 --- a/server/product/internal/logic/gettagproductlistlogic.go +++ b/server/product/internal/logic/gettagproductlistlogic.go @@ -382,6 +382,7 @@ type getTagProductsReq struct { User gmodel.FsUser } +// 返回每个标签下的直接从属产品,不包含子tag的产品 func (l *GetTagProductListLogic) getTagProducts(req getTagProductsReq) (productListRsp []types.TagProduct) { //默认给50个容量 productListRsp = make([]types.TagProduct, 0, 50) From 250ac8c5938cf92663f70319a1ae65ca8b317935 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Wed, 30 Aug 2023 16:53:55 +0800 Subject: [PATCH 05/15] fix --- constants/websocket.go | 47 +++++++++++++++++++++--------------------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/constants/websocket.go b/constants/websocket.go index 84321556..540ece73 100644 --- a/constants/websocket.go +++ b/constants/websocket.go @@ -2,28 +2,29 @@ package constants type Websocket string -// websocket消息类型 +// websocket消息类型(主类别) const ( - //鉴权失败 - WEBSOCKET_UNAUTH Websocket = "WEBSOCKET_UNAUTH" - //获取ws连接标识错误 - WEBSOCKET_GEN_UNIQUE_ID_ERR Websocket = "WEBSOCKET_GEN_UNIQUE_ID_ERR" - //ws连接成功 - WEBSOCKET_CONNECT_SUCCESS Websocket = "WEBSOCKET_CONNECT_SUCCESS" - //请求恢复为上次连接的标识 - WEBSOCKET_REQUEST_REUSE_LAST_CONNECT Websocket = "WEBSOCKET_REQUEST_REUSE_LAST_CONNECT" - //请求恢复为上次连接的标识错误 - WEBSOCKET_REQUEST_RESUME_LAST_CONNECT_ERR Websocket = "WEBSOCKET_REQUEST_RESUME_LAST_CONNECT_ERR" - //图片渲染消息 - WEBSOCKET_RENDER_IMAGE Websocket = "WEBSOCKET_RENDER_IMAGE" - //图片渲染失败消息 - WEBSOCKET_RENDER_IMAGE_ERR Websocket = "WEBSOCKET_RENDER_IMAGE_ERR" - //反回合成刀版图消息 - WEBSOCKET_COMBINE_IMAGE Websocket = "WEBSOCKET_COMBINE_IMAGE" - //传入数据格式错误 - WEBSOCKET_ERR_DATA_FORMAT Websocket = "WEBSOCKET_ERR_DATA_FORMAT" - //通用回调通知 - WEBSOCKET_COMMON_NOTIFY Websocket = "WEBSOCKET_COMMON_NOTIFY" - //数据接收速度超过数据消费速度(缓冲队列满了) - WEBSOCKET_INCOME_CACHE_QUEUE_OVERFLOW = "WEBSOCKET_INCOME_CACHE_QUEUE_OVERFLOW" + WEBSOCKET_UNAUTH Websocket = "WEBSOCKET_UNAUTH" //鉴权失败 + WEBSOCKET_GEN_UNIQUE_ID_ERR Websocket = "WEBSOCKET_GEN_UNIQUE_ID_ERR" //获取ws连接标识错误 + WEBSOCKET_CONNECT_SUCCESS Websocket = "WEBSOCKET_CONNECT_SUCCESS" //ws连接成功 + WEBSOCKET_REQUEST_REUSE_LAST_CONNECT Websocket = "WEBSOCKET_REQUEST_REUSE_LAST_CONNECT" //请求恢复为上次连接的标识 + WEBSOCKET_REQUEST_RESUME_LAST_CONNECT_ERR Websocket = "WEBSOCKET_REQUEST_RESUME_LAST_CONNECT_ERR" //请求恢复为上次连接的标识错误 + WEBSOCKET_INCOME_CACHE_QUEUE_OVERFLOW = "WEBSOCKET_INCOME_CACHE_QUEUE_OVERFLOW" //数据接收速度超过数据消费速度(缓冲队列满了) +) + +// websocket消息类型(通用通知类别) +const ( + WEBSOCKET_COMMON_NOTIFY Websocket = "WEBSOCKET_COMMON_NOTIFY" //通用回调通知 +) + +// websocket消息类型(基本传输结构类别) +const ( + WEBSOCKET_ERR_DATA_FORMAT Websocket = "WEBSOCKET_ERR_DATA_FORMAT" //传入数据格式错误 +) + +// websocket消息类型(云渲染类别) +const ( + WEBSOCKET_RENDER_IMAGE Websocket = "WEBSOCKET_RENDER_IMAGE" //图片渲染消息 + WEBSOCKET_RENDER_IMAGE_ERR Websocket = "WEBSOCKET_RENDER_IMAGE_ERR" //图片渲染失败消息 + WEBSOCKET_COMBINE_IMAGE Websocket = "WEBSOCKET_COMBINE_IMAGE" //反回合成刀版图消息 ) From ad8588cb24d35cd8776cdf7ddf714a3aeacfaaca Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Wed, 30 Aug 2023 17:00:04 +0800 Subject: [PATCH 06/15] fix --- constants/websocket.go | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/constants/websocket.go b/constants/websocket.go index 540ece73..7b0cb632 100644 --- a/constants/websocket.go +++ b/constants/websocket.go @@ -4,27 +4,27 @@ type Websocket string // websocket消息类型(主类别) const ( - WEBSOCKET_UNAUTH Websocket = "WEBSOCKET_UNAUTH" //鉴权失败 - WEBSOCKET_GEN_UNIQUE_ID_ERR Websocket = "WEBSOCKET_GEN_UNIQUE_ID_ERR" //获取ws连接标识错误 - WEBSOCKET_CONNECT_SUCCESS Websocket = "WEBSOCKET_CONNECT_SUCCESS" //ws连接成功 - WEBSOCKET_REQUEST_REUSE_LAST_CONNECT Websocket = "WEBSOCKET_REQUEST_REUSE_LAST_CONNECT" //请求恢复为上次连接的标识 - WEBSOCKET_REQUEST_RESUME_LAST_CONNECT_ERR Websocket = "WEBSOCKET_REQUEST_RESUME_LAST_CONNECT_ERR" //请求恢复为上次连接的标识错误 - WEBSOCKET_INCOME_CACHE_QUEUE_OVERFLOW = "WEBSOCKET_INCOME_CACHE_QUEUE_OVERFLOW" //数据接收速度超过数据消费速度(缓冲队列满了) + WEBSOCKET_UNAUTH Websocket = "WEBSOCKET_UNAUTH" //鉴权失败 (1级消息,单项通信) + WEBSOCKET_GEN_UNIQUE_ID_ERR Websocket = "WEBSOCKET_GEN_UNIQUE_ID_ERR" //获取ws连接标识错误 (1级消息,单项通信) + WEBSOCKET_CONNECT_SUCCESS Websocket = "WEBSOCKET_CONNECT_SUCCESS" //ws连接成功 (1级消息,单项通信) + WEBSOCKET_REQUEST_REUSE_LAST_CONNECT Websocket = "WEBSOCKET_REQUEST_REUSE_LAST_CONNECT" //请求恢复为上次连接的标识 (1级消息,单项通信) + WEBSOCKET_REQUEST_RESUME_LAST_CONNECT_ERR Websocket = "WEBSOCKET_REQUEST_RESUME_LAST_CONNECT_ERR" //请求恢复为上次连接的标识错误 (1级消息,单项通信) + WEBSOCKET_INCOME_CACHE_QUEUE_OVERFLOW = "WEBSOCKET_INCOME_CACHE_QUEUE_OVERFLOW" //数据接收速度超过数据消费速度(缓冲队列满了)(1级消息,单项通信) ) // websocket消息类型(通用通知类别) const ( - WEBSOCKET_COMMON_NOTIFY Websocket = "WEBSOCKET_COMMON_NOTIFY" //通用回调通知 + WEBSOCKET_COMMON_NOTIFY Websocket = "WEBSOCKET_COMMON_NOTIFY" //通用回调通知(1级消息,单项通信) ) // websocket消息类型(基本传输结构类别) const ( - WEBSOCKET_ERR_DATA_FORMAT Websocket = "WEBSOCKET_ERR_DATA_FORMAT" //传入数据格式错误 + WEBSOCKET_ERR_DATA_FORMAT Websocket = "WEBSOCKET_ERR_DATA_FORMAT" //传入数据格式错误(1级消息,单项通信) ) // websocket消息类型(云渲染类别) const ( - WEBSOCKET_RENDER_IMAGE Websocket = "WEBSOCKET_RENDER_IMAGE" //图片渲染消息 - WEBSOCKET_RENDER_IMAGE_ERR Websocket = "WEBSOCKET_RENDER_IMAGE_ERR" //图片渲染失败消息 - WEBSOCKET_COMBINE_IMAGE Websocket = "WEBSOCKET_COMBINE_IMAGE" //反回合成刀版图消息 + WEBSOCKET_RENDER_IMAGE Websocket = "WEBSOCKET_RENDER_IMAGE" //图片渲染消息(1级消息,双向通信) + WEBSOCKET_RENDER_IMAGE_ERR Websocket = "WEBSOCKET_RENDER_IMAGE_ERR" //图片渲染失败消息(1级消息,单向通信) + WEBSOCKET_COMBINE_IMAGE Websocket = "WEBSOCKET_COMBINE_IMAGE" //反回合成刀版图消息(2级消息,单向通信,属于 WEBSOCKET_RENDER_IMAGE 消息的子流程) ) From a4f8649de04283aad32763164ddedb1e19bc164a Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Wed, 30 Aug 2023 17:00:30 +0800 Subject: [PATCH 07/15] fix --- constants/websocket.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/constants/websocket.go b/constants/websocket.go index 7b0cb632..e3cf11f9 100644 --- a/constants/websocket.go +++ b/constants/websocket.go @@ -4,22 +4,22 @@ type Websocket string // websocket消息类型(主类别) const ( - WEBSOCKET_UNAUTH Websocket = "WEBSOCKET_UNAUTH" //鉴权失败 (1级消息,单项通信) - WEBSOCKET_GEN_UNIQUE_ID_ERR Websocket = "WEBSOCKET_GEN_UNIQUE_ID_ERR" //获取ws连接标识错误 (1级消息,单项通信) - WEBSOCKET_CONNECT_SUCCESS Websocket = "WEBSOCKET_CONNECT_SUCCESS" //ws连接成功 (1级消息,单项通信) - WEBSOCKET_REQUEST_REUSE_LAST_CONNECT Websocket = "WEBSOCKET_REQUEST_REUSE_LAST_CONNECT" //请求恢复为上次连接的标识 (1级消息,单项通信) - WEBSOCKET_REQUEST_RESUME_LAST_CONNECT_ERR Websocket = "WEBSOCKET_REQUEST_RESUME_LAST_CONNECT_ERR" //请求恢复为上次连接的标识错误 (1级消息,单项通信) - WEBSOCKET_INCOME_CACHE_QUEUE_OVERFLOW = "WEBSOCKET_INCOME_CACHE_QUEUE_OVERFLOW" //数据接收速度超过数据消费速度(缓冲队列满了)(1级消息,单项通信) + WEBSOCKET_UNAUTH Websocket = "WEBSOCKET_UNAUTH" //鉴权失败 (1级消息,单向通信) + WEBSOCKET_GEN_UNIQUE_ID_ERR Websocket = "WEBSOCKET_GEN_UNIQUE_ID_ERR" //获取ws连接标识错误 (1级消息,单向通信) + WEBSOCKET_CONNECT_SUCCESS Websocket = "WEBSOCKET_CONNECT_SUCCESS" //ws连接成功 (1级消息,单向通信) + WEBSOCKET_REQUEST_REUSE_LAST_CONNECT Websocket = "WEBSOCKET_REQUEST_REUSE_LAST_CONNECT" //请求恢复为上次连接的标识 (1级消息,单向通信) + WEBSOCKET_REQUEST_RESUME_LAST_CONNECT_ERR Websocket = "WEBSOCKET_REQUEST_RESUME_LAST_CONNECT_ERR" //请求恢复为上次连接的标识错误 (1级消息,单向通信) + WEBSOCKET_INCOME_CACHE_QUEUE_OVERFLOW = "WEBSOCKET_INCOME_CACHE_QUEUE_OVERFLOW" //数据接收速度超过数据消费速度(缓冲队列满了)(1级消息,单向通信) ) // websocket消息类型(通用通知类别) const ( - WEBSOCKET_COMMON_NOTIFY Websocket = "WEBSOCKET_COMMON_NOTIFY" //通用回调通知(1级消息,单项通信) + WEBSOCKET_COMMON_NOTIFY Websocket = "WEBSOCKET_COMMON_NOTIFY" //通用回调通知(1级消息,单向通信) ) // websocket消息类型(基本传输结构类别) const ( - WEBSOCKET_ERR_DATA_FORMAT Websocket = "WEBSOCKET_ERR_DATA_FORMAT" //传入数据格式错误(1级消息,单项通信) + WEBSOCKET_ERR_DATA_FORMAT Websocket = "WEBSOCKET_ERR_DATA_FORMAT" //传入数据格式错误(1级消息,单向通信) ) // websocket消息类型(云渲染类别) From 2ce97762551c57bcfc24d1f71d8248a1cddbd107 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Wed, 30 Aug 2023 17:07:14 +0800 Subject: [PATCH 08/15] fix --- server/websocket/internal/logic/datatransferlogic.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/server/websocket/internal/logic/datatransferlogic.go b/server/websocket/internal/logic/datatransferlogic.go index 9bc386b7..dea9b2b1 100644 --- a/server/websocket/internal/logic/datatransferlogic.go +++ b/server/websocket/internal/logic/datatransferlogic.go @@ -313,7 +313,8 @@ func (w *wsConnectItem) consumeInChanData() { case <-w.closeChan: return case data := <-w.inChan: - w.dealwithReciveData(data) + //对不同消息类型分发处理 + w.allocationProcessing(data) } } } @@ -382,7 +383,7 @@ func (w *wsConnectItem) respondDataFormat(msgType constants.Websocket, data inte } // 处理入口缓冲队列中不同类型的数据(分发处理) -func (w *wsConnectItem) dealwithReciveData(data []byte) { +func (w *wsConnectItem) allocationProcessing(data []byte) { var parseInfo websocket_data.DataTransferData if err := json.Unmarshal(data, &parseInfo); err != nil { w.incomeDataFormatErrResponse("invalid format of income message:" + string(data)) From 6c368177507f7085653fa7a69ea364f89077a479 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Wed, 30 Aug 2023 17:40:40 +0800 Subject: [PATCH 09/15] fix --- .../logic/allocation_processing_factory.go | 33 ++++++++++++++++++ .../internal/logic/datatransferlogic.go | 15 +++----- .../internal/logic/ws_render_image.go | 12 ++++--- .../internal/logic/ws_reuse_last_connect.go | 34 +++++++++++-------- 4 files changed, 64 insertions(+), 30 deletions(-) create mode 100644 server/websocket/internal/logic/allocation_processing_factory.go diff --git a/server/websocket/internal/logic/allocation_processing_factory.go b/server/websocket/internal/logic/allocation_processing_factory.go new file mode 100644 index 00000000..e28de1bf --- /dev/null +++ b/server/websocket/internal/logic/allocation_processing_factory.go @@ -0,0 +1,33 @@ +package logic + +import ( + "fusenapi/constants" +) + +// 消息分发工厂 +type allocationProcessorFactory interface { + allocationMessage(data []byte) +} + +var mapAllocationProcessor = make(map[constants.Websocket]allocationProcessorFactory) + +func (w *wsConnectItem) newAllocationProcessor(msgType constants.Websocket) allocationProcessorFactory { + if obj, ok := mapAllocationProcessor[msgType]; ok { + return obj + } + var obj allocationProcessorFactory + switch msgType { + //图片渲染 + case constants.WEBSOCKET_RENDER_IMAGE: + obj = &renderProcesser{w} + //刷新重连请求恢复上次连接的标识 + case constants.WEBSOCKET_REQUEST_REUSE_LAST_CONNECT: + obj = &reuseConnProcesser{w} + default: + + } + if obj != nil { + mapAllocationProcessor[msgType] = obj + } + return obj +} diff --git a/server/websocket/internal/logic/datatransferlogic.go b/server/websocket/internal/logic/datatransferlogic.go index dea9b2b1..a0ac676f 100644 --- a/server/websocket/internal/logic/datatransferlogic.go +++ b/server/websocket/internal/logic/datatransferlogic.go @@ -391,15 +391,8 @@ func (w *wsConnectItem) allocationProcessing(data []byte) { return } d, _ := json.Marshal(parseInfo.D) - //分消息类型给到不同逻辑处理,可扩展 - switch parseInfo.T { - //图片渲染 - case constants.WEBSOCKET_RENDER_IMAGE: - w.sendToRenderChan(d) - //刷新重连请求恢复上次连接的标识 - case constants.WEBSOCKET_REQUEST_REUSE_LAST_CONNECT: - w.reuseLastConnect(d) - default: - logx.Error("未知消息类型:uid:", w.userId, "gid:", w.guestId, "data:", string(data)) - } + //获取工厂实例 + processor := w.newAllocationProcessor(parseInfo.T) + //执行工厂方法 + processor.allocationMessage(d) } diff --git a/server/websocket/internal/logic/ws_render_image.go b/server/websocket/internal/logic/ws_render_image.go index 887dc2e7..5700c01a 100644 --- a/server/websocket/internal/logic/ws_render_image.go +++ b/server/websocket/internal/logic/ws_render_image.go @@ -18,6 +18,11 @@ import ( "time" ) +// 渲染处理器 +type renderProcesser struct { + w *wsConnectItem +} + // 云渲染属性 type extendRenderProperty struct { renderImageTask map[string]*renderTask //需要渲染的图片任务 key是taskId val 是renderId @@ -44,12 +49,11 @@ type renderTask struct { uploadUnityRenderImageTakesTime int64 //上传unity渲染结果图时间 } -// 发送到渲染缓冲队列 -func (w *wsConnectItem) sendToRenderChan(data []byte) { +func (r *renderProcesser) allocationMessage(data []byte) { select { - case <-w.closeChan: //已经关闭 + case <-r.w.closeChan: //已经关闭 return - case w.extendRenderProperty.renderChan <- data: //发入到缓冲队列 + case r.w.extendRenderProperty.renderChan <- data: //发入到缓冲队列 return case <-time.After(time.Second * 3): //三秒没进入缓冲队列就丢弃 return diff --git a/server/websocket/internal/logic/ws_reuse_last_connect.go b/server/websocket/internal/logic/ws_reuse_last_connect.go index 7ef64ec7..d8e00d79 100644 --- a/server/websocket/internal/logic/ws_reuse_last_connect.go +++ b/server/websocket/internal/logic/ws_reuse_last_connect.go @@ -9,32 +9,36 @@ import ( "github.com/zeromicro/go-zero/core/logx" ) -// 刷新重连请求恢复上次连接的标识 -func (w *wsConnectItem) reuseLastConnect(data []byte) { +// 复用连接处理器 +type reuseConnProcesser struct { + w *wsConnectItem +} + +func (r *reuseConnProcesser) allocationMessage(data []byte) { logx.Info("收到请求恢复上次连接标识数据:", string(data)) var wid string if err := json.Unmarshal(data, &wid); err != nil { logx.Error(" invalid format of wid :", wid) - w.incomeDataFormatErrResponse("invalid format of wid") + r.w.incomeDataFormatErrResponse("invalid format of wid") return } //解密 decryptionWid, err := encryption_decryption.CBCDecrypt(wid) if err != nil { - w.reuseLastConnErrResponse("invalid wid") + r.w.reuseLastConnErrResponse("invalid wid") return } lendecryptionWid := len(decryptionWid) //合成client后缀,不是同个后缀的不能复用 - userPart := getUserJoinPart(w.userId, w.guestId, w.userAgent) + userPart := getUserJoinPart(r.w.userId, r.w.guestId, r.w.userAgent) lenUserPart := len(userPart) if lendecryptionWid <= lenUserPart { - w.reuseLastConnErrResponse("length of client id is to short") + r.w.reuseLastConnErrResponse("length of client id is to short") return } //尾部不同不能复用 if decryptionWid[lendecryptionWid-lenUserPart:] != userPart { - w.reuseLastConnErrResponse("the client id is not belong to you before") + r.w.reuseLastConnErrResponse("the client id is not belong to you before") return } //存在是不能给他申请重新绑定 @@ -44,20 +48,20 @@ func (w *wsConnectItem) reuseLastConnect(data []byte) { logx.Error("连接断言失败") } //是当前自己占用(无需处理) - if obj.uniqueId == w.uniqueId { - rsp := w.respondDataFormat(constants.WEBSOCKET_CONNECT_SUCCESS, wid) - w.sendToOutChan(rsp) + if obj.uniqueId == r.w.uniqueId { + rsp := r.w.respondDataFormat(constants.WEBSOCKET_CONNECT_SUCCESS, wid) + r.w.sendToOutChan(rsp) return } else { - w.reuseLastConnErrResponse("the wid is used by other people") + r.w.reuseLastConnErrResponse("the wid is used by other people") return } } //重新绑定 - w.uniqueId = wid - mapConnPool.Store(wid, *w) - rsp := w.respondDataFormat(constants.WEBSOCKET_CONNECT_SUCCESS, wid) - w.sendToOutChan(rsp) + r.w.uniqueId = wid + mapConnPool.Store(wid, *r.w) + rsp := r.w.respondDataFormat(constants.WEBSOCKET_CONNECT_SUCCESS, wid) + r.w.sendToOutChan(rsp) return } From b8dbda6a4cf05332829248abf6bab14a67fc5e1c Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Wed, 30 Aug 2023 17:46:47 +0800 Subject: [PATCH 10/15] fix --- .../internal/logic/allocation_processing_factory.go | 4 ++-- server/websocket/internal/logic/ws_render_image.go | 5 +++-- server/websocket/internal/logic/ws_reuse_last_connect.go | 4 ++-- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/server/websocket/internal/logic/allocation_processing_factory.go b/server/websocket/internal/logic/allocation_processing_factory.go index e28de1bf..19810773 100644 --- a/server/websocket/internal/logic/allocation_processing_factory.go +++ b/server/websocket/internal/logic/allocation_processing_factory.go @@ -19,10 +19,10 @@ func (w *wsConnectItem) newAllocationProcessor(msgType constants.Websocket) allo switch msgType { //图片渲染 case constants.WEBSOCKET_RENDER_IMAGE: - obj = &renderProcesser{w} + obj = &renderProcessor{w} //刷新重连请求恢复上次连接的标识 case constants.WEBSOCKET_REQUEST_REUSE_LAST_CONNECT: - obj = &reuseConnProcesser{w} + obj = &reuseConnProcessor{w} default: } diff --git a/server/websocket/internal/logic/ws_render_image.go b/server/websocket/internal/logic/ws_render_image.go index 5700c01a..78f65fbf 100644 --- a/server/websocket/internal/logic/ws_render_image.go +++ b/server/websocket/internal/logic/ws_render_image.go @@ -19,7 +19,7 @@ import ( ) // 渲染处理器 -type renderProcesser struct { +type renderProcessor struct { w *wsConnectItem } @@ -49,7 +49,8 @@ type renderTask struct { uploadUnityRenderImageTakesTime int64 //上传unity渲染结果图时间 } -func (r *renderProcesser) allocationMessage(data []byte) { +func (r *renderProcessor) allocationMessage(data []byte) { + logx.Info("收到渲染任务消息:", string(data)) select { case <-r.w.closeChan: //已经关闭 return diff --git a/server/websocket/internal/logic/ws_reuse_last_connect.go b/server/websocket/internal/logic/ws_reuse_last_connect.go index d8e00d79..e826732c 100644 --- a/server/websocket/internal/logic/ws_reuse_last_connect.go +++ b/server/websocket/internal/logic/ws_reuse_last_connect.go @@ -10,11 +10,11 @@ import ( ) // 复用连接处理器 -type reuseConnProcesser struct { +type reuseConnProcessor struct { w *wsConnectItem } -func (r *reuseConnProcesser) allocationMessage(data []byte) { +func (r *reuseConnProcessor) allocationMessage(data []byte) { logx.Info("收到请求恢复上次连接标识数据:", string(data)) var wid string if err := json.Unmarshal(data, &wid); err != nil { From a9b8df41f706d80ab74f36ad1eca22a7b7c2ff42 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Wed, 30 Aug 2023 18:00:26 +0800 Subject: [PATCH 11/15] fix --- .../websocket/internal/logic/allocation_processing_factory.go | 4 ++-- server/websocket/internal/logic/ws_render_image.go | 2 +- server/websocket/internal/logic/ws_reuse_last_connect.go | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/server/websocket/internal/logic/allocation_processing_factory.go b/server/websocket/internal/logic/allocation_processing_factory.go index 19810773..4eb19507 100644 --- a/server/websocket/internal/logic/allocation_processing_factory.go +++ b/server/websocket/internal/logic/allocation_processing_factory.go @@ -19,10 +19,10 @@ func (w *wsConnectItem) newAllocationProcessor(msgType constants.Websocket) allo switch msgType { //图片渲染 case constants.WEBSOCKET_RENDER_IMAGE: - obj = &renderProcessor{w} + obj = &renderProcessor{*w} //刷新重连请求恢复上次连接的标识 case constants.WEBSOCKET_REQUEST_REUSE_LAST_CONNECT: - obj = &reuseConnProcessor{w} + obj = &reuseConnProcessor{*w} default: } diff --git a/server/websocket/internal/logic/ws_render_image.go b/server/websocket/internal/logic/ws_render_image.go index 78f65fbf..bb489915 100644 --- a/server/websocket/internal/logic/ws_render_image.go +++ b/server/websocket/internal/logic/ws_render_image.go @@ -20,7 +20,7 @@ import ( // 渲染处理器 type renderProcessor struct { - w *wsConnectItem + w wsConnectItem } // 云渲染属性 diff --git a/server/websocket/internal/logic/ws_reuse_last_connect.go b/server/websocket/internal/logic/ws_reuse_last_connect.go index e826732c..88ee0894 100644 --- a/server/websocket/internal/logic/ws_reuse_last_connect.go +++ b/server/websocket/internal/logic/ws_reuse_last_connect.go @@ -11,7 +11,7 @@ import ( // 复用连接处理器 type reuseConnProcessor struct { - w *wsConnectItem + w wsConnectItem } func (r *reuseConnProcessor) allocationMessage(data []byte) { From 4ac4f7ee9d0a2340efbbc382dd4d59e990341723 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Wed, 30 Aug 2023 18:02:02 +0800 Subject: [PATCH 12/15] fix --- server/websocket/internal/logic/ws_reuse_last_connect.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/websocket/internal/logic/ws_reuse_last_connect.go b/server/websocket/internal/logic/ws_reuse_last_connect.go index 88ee0894..4630e86e 100644 --- a/server/websocket/internal/logic/ws_reuse_last_connect.go +++ b/server/websocket/internal/logic/ws_reuse_last_connect.go @@ -59,7 +59,7 @@ func (r *reuseConnProcessor) allocationMessage(data []byte) { } //重新绑定 r.w.uniqueId = wid - mapConnPool.Store(wid, *r.w) + mapConnPool.Store(wid, r.w) rsp := r.w.respondDataFormat(constants.WEBSOCKET_CONNECT_SUCCESS, wid) r.w.sendToOutChan(rsp) return From 6a6f135b61a1dfd78797b0a70c7c93fe23e1e72e Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Wed, 30 Aug 2023 18:31:20 +0800 Subject: [PATCH 13/15] fix --- .../logic/allocation_processing_factory.go | 10 +++--- .../internal/logic/datatransferlogic.go | 6 +++- .../internal/logic/ws_render_image.go | 7 ++-- .../internal/logic/ws_reuse_last_connect.go | 34 ++++++++++--------- 4 files changed, 31 insertions(+), 26 deletions(-) diff --git a/server/websocket/internal/logic/allocation_processing_factory.go b/server/websocket/internal/logic/allocation_processing_factory.go index 4eb19507..18cce02b 100644 --- a/server/websocket/internal/logic/allocation_processing_factory.go +++ b/server/websocket/internal/logic/allocation_processing_factory.go @@ -6,23 +6,23 @@ import ( // 消息分发工厂 type allocationProcessorFactory interface { - allocationMessage(data []byte) + allocationMessage(w *wsConnectItem, data []byte) } var mapAllocationProcessor = make(map[constants.Websocket]allocationProcessorFactory) func (w *wsConnectItem) newAllocationProcessor(msgType constants.Websocket) allocationProcessorFactory { - if obj, ok := mapAllocationProcessor[msgType]; ok { - return obj + if val, ok := mapAllocationProcessor[msgType]; ok { + return val } var obj allocationProcessorFactory switch msgType { //图片渲染 case constants.WEBSOCKET_RENDER_IMAGE: - obj = &renderProcessor{*w} + obj = &renderProcessor{} //刷新重连请求恢复上次连接的标识 case constants.WEBSOCKET_REQUEST_REUSE_LAST_CONNECT: - obj = &reuseConnProcessor{*w} + obj = &reuseConnProcessor{} default: } diff --git a/server/websocket/internal/logic/datatransferlogic.go b/server/websocket/internal/logic/datatransferlogic.go index a0ac676f..eb6434b8 100644 --- a/server/websocket/internal/logic/datatransferlogic.go +++ b/server/websocket/internal/logic/datatransferlogic.go @@ -393,6 +393,10 @@ func (w *wsConnectItem) allocationProcessing(data []byte) { d, _ := json.Marshal(parseInfo.D) //获取工厂实例 processor := w.newAllocationProcessor(parseInfo.T) + if processor == nil { + logx.Error("未知消息类型:", string(data)) + return + } //执行工厂方法 - processor.allocationMessage(d) + processor.allocationMessage(w, d) } diff --git a/server/websocket/internal/logic/ws_render_image.go b/server/websocket/internal/logic/ws_render_image.go index bb489915..00e7b773 100644 --- a/server/websocket/internal/logic/ws_render_image.go +++ b/server/websocket/internal/logic/ws_render_image.go @@ -20,7 +20,6 @@ import ( // 渲染处理器 type renderProcessor struct { - w wsConnectItem } // 云渲染属性 @@ -49,12 +48,12 @@ type renderTask struct { uploadUnityRenderImageTakesTime int64 //上传unity渲染结果图时间 } -func (r *renderProcessor) allocationMessage(data []byte) { +func (r *renderProcessor) allocationMessage(w *wsConnectItem, data []byte) { logx.Info("收到渲染任务消息:", string(data)) select { - case <-r.w.closeChan: //已经关闭 + case <-w.closeChan: //已经关闭 return - case r.w.extendRenderProperty.renderChan <- data: //发入到缓冲队列 + case w.extendRenderProperty.renderChan <- data: //发入到缓冲队列 return case <-time.After(time.Second * 3): //三秒没进入缓冲队列就丢弃 return diff --git a/server/websocket/internal/logic/ws_reuse_last_connect.go b/server/websocket/internal/logic/ws_reuse_last_connect.go index 4630e86e..33fa2cd7 100644 --- a/server/websocket/internal/logic/ws_reuse_last_connect.go +++ b/server/websocket/internal/logic/ws_reuse_last_connect.go @@ -11,58 +11,60 @@ import ( // 复用连接处理器 type reuseConnProcessor struct { - w wsConnectItem } -func (r *reuseConnProcessor) allocationMessage(data []byte) { +func (r *reuseConnProcessor) allocationMessage(w *wsConnectItem, data []byte) { logx.Info("收到请求恢复上次连接标识数据:", string(data)) var wid string if err := json.Unmarshal(data, &wid); err != nil { logx.Error(" invalid format of wid :", wid) - r.w.incomeDataFormatErrResponse("invalid format of wid") + w.incomeDataFormatErrResponse("invalid format of wid") return } //解密 decryptionWid, err := encryption_decryption.CBCDecrypt(wid) if err != nil { - r.w.reuseLastConnErrResponse("invalid wid") + w.reuseLastConnErrResponse("invalid wid") return } lendecryptionWid := len(decryptionWid) //合成client后缀,不是同个后缀的不能复用 - userPart := getUserJoinPart(r.w.userId, r.w.guestId, r.w.userAgent) + userPart := getUserJoinPart(w.userId, w.guestId, w.userAgent) lenUserPart := len(userPart) if lendecryptionWid <= lenUserPart { - r.w.reuseLastConnErrResponse("length of client id is to short") + w.reuseLastConnErrResponse("length of client id is to short") return } //尾部不同不能复用 if decryptionWid[lendecryptionWid-lenUserPart:] != userPart { - r.w.reuseLastConnErrResponse("the client id is not belong to you before") + w.reuseLastConnErrResponse("the client id is not belong to you before") return } //存在是不能给他申请重新绑定 if v, ok := mapConnPool.Load(wid); ok { obj, ok := v.(wsConnectItem) if !ok { + w.reuseLastConnErrResponse("连接断言失败") logx.Error("连接断言失败") + return } //是当前自己占用(无需处理) - if obj.uniqueId == r.w.uniqueId { - rsp := r.w.respondDataFormat(constants.WEBSOCKET_CONNECT_SUCCESS, wid) - r.w.sendToOutChan(rsp) + if obj.uniqueId == w.uniqueId { + rsp := w.respondDataFormat(constants.WEBSOCKET_CONNECT_SUCCESS, wid) + w.sendToOutChan(rsp) return } else { - r.w.reuseLastConnErrResponse("the wid is used by other people") + w.reuseLastConnErrResponse("the wid is used by other people") return } } //重新绑定 - r.w.uniqueId = wid - mapConnPool.Store(wid, r.w) - rsp := r.w.respondDataFormat(constants.WEBSOCKET_CONNECT_SUCCESS, wid) - r.w.sendToOutChan(rsp) - return + logx.Info("开始重新绑定>>>>>") + w.uniqueId = wid + mapConnPool.Store(wid, *w) + rsp := w.respondDataFormat(constants.WEBSOCKET_CONNECT_SUCCESS, wid) + w.sendToOutChan(rsp) + logx.Info("重新绑定成功") } // 获取用户拼接部分(复用标识用到) From 0135a17ef87c295b8ddd5999b7ac94b5411d684e Mon Sep 17 00:00:00 2001 From: eson <9673575+githubcontent@user.noreply.gitee.com> Date: Wed, 30 Aug 2023 18:44:41 +0800 Subject: [PATCH 14/15] fix --- go.mod | 1 + go.sum | 2 + .../logic/useremailconfirmationlogic.go | 54 ++++++++++--------- utils/check/limit.go | 1 + 4 files changed, 34 insertions(+), 24 deletions(-) create mode 100644 utils/check/limit.go diff --git a/go.mod b/go.mod index 187d7e92..fc0da431 100644 --- a/go.mod +++ b/go.mod @@ -27,6 +27,7 @@ require ( require ( cloud.google.com/go/compute v1.20.1 // indirect cloud.google.com/go/compute/metadata v0.2.3 // indirect + github.com/474420502/execute v0.2.2 // indirect 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 diff --git a/go.sum b/go.sum index 815b0b69..e1341003 100644 --- a/go.sum +++ b/go.sum @@ -35,6 +35,8 @@ cloud.google.com/go/storage v1.6.0/go.mod h1:N7U0C8pVQ/+NIKOBQyamJIeKQKkZ+mxpohl cloud.google.com/go/storage v1.8.0/go.mod h1:Wv1Oy7z6Yz3DshWRJFhqM/UCfaWIRTdp0RXyy7KQOVs= cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9ullr3+Kg0= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= +github.com/474420502/execute v0.2.2 h1:Hzzb/HFa/urRvi3xWe+p/DnJgRyxXFVyEBEXbbITy/E= +github.com/474420502/execute v0.2.2/go.mod h1:wkKeKBIXYp7T844eU1YS2nPvFj8lra4VRcQYnWyXej4= github.com/474420502/passer v0.0.1 h1:ZWnt7hpFzsYDV7LHSEyLvLUvW5mRxrnDmgFdIl17q3w= github.com/474420502/passer v0.0.1/go.mod h1:MmnnrF9d51sPkFzdRq2pQtxQKqyjburVM1LjMbOCezE= github.com/474420502/random v0.4.1 h1:HUUyLXRWMijVb7CJoEC16f0aFQOW25Lkr80Mut6PoKU= diff --git a/server/auth/internal/logic/useremailconfirmationlogic.go b/server/auth/internal/logic/useremailconfirmationlogic.go index 3f6b9e51..351bdc5b 100644 --- a/server/auth/internal/logic/useremailconfirmationlogic.go +++ b/server/auth/internal/logic/useremailconfirmationlogic.go @@ -100,9 +100,10 @@ func (l *UserEmailConfirmationLogic) UserEmailConfirmation(req *types.RequestEma switch token.OperateType { case auth.OpTypeRegister: - if time.Since(token.CreateAt) >= 24*time.Hour { - return resp.SetStatus(basic.CodeOAuthConfirmationTimeoutErr) + if time.Since(token.CreateAt) > 30*time.Minute { + return resp.SetStatusWithMessage(basic.CodeOAuthConfirmationTimeoutErr, "Verification links expire after 30 minute.") } + logx.Info(token.Platform) switch token.Platform { case string(auth.PLATFORM_GOOGLE): @@ -110,7 +111,7 @@ func (l *UserEmailConfirmationLogic) UserEmailConfirmation(req *types.RequestEma user, err := l.svcCtx.AllModels.FsUser.RegisterByGoogleOAuth(l.ctx, token) if err != nil { logx.Error(err, token.TraceId) - return resp.SetStatus(basic.CodeDbSqlErr) + return resp.SetStatus(basic.CodeDbSqlErr, err.Error()) } err = FinishRegister(l.svcCtx, user, token) @@ -148,39 +149,44 @@ func (l *UserEmailConfirmationLogic) AfterLogic(w http.ResponseWriter, r *http.R successHtml := ` - 注册成功 + Registration Successful + + + -

恭喜!您的注册成功。

-

感谢您在我们网站进行注册。您的账号已经激活。

+

Congratulations! Your registration is successful.

-

您现在可以使用您的邮箱地址和密码登录我们的网站,享受完整的服务和功能。

+

Thank you for registering on our website. Your account has been activated.

-

再次感谢您的信任和支持。如果您有任何问题,请随时联系我们。

+

You can now login using your email address and password to enjoy full services and features on our website.

+ +

Thanks again for your trust and support. If you have any questions, please feel free to contact us.

+ +

We wish you a pleasant experience!

-

祝您使用愉快!

` w.Write([]byte(successHtml)) @@ -191,7 +197,7 @@ func (l *UserEmailConfirmationLogic) AfterLogic(w http.ResponseWriter, r *http.R - 注册失败 + Failed to register