From 1b5e9623a02c60790332725e5df8d14d32af5e25 Mon Sep 17 00:00:00 2001 From: Hiven Date: Fri, 18 Aug 2023 19:37:11 +0800 Subject: [PATCH 01/15] =?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 --- service/repositories/image_handle.go | 5 ++++- utils/hash/hash.go | 3 +-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/service/repositories/image_handle.go b/service/repositories/image_handle.go index d16e8704..54954862 100644 --- a/service/repositories/image_handle.go +++ b/service/repositories/image_handle.go @@ -92,7 +92,10 @@ func (l *defaultImageHandle) LogoCombine(ctx context.Context, in *LogoCombineReq hashKeyData.GuestId = 0 hashKeyData.UserId = 0 hashKeyData.LogoUrl = *userMaterialInfo.ResourceUrl - var resourceId string = hash.JsonHashKey(hashKeyData) + var hashKeyDataMap map[string]interface{} + hashKeyDataB, _ := json.Marshal(hashKeyData) + json.Unmarshal(hashKeyDataB, &hashKeyDataMap) + var resourceId string = hash.JsonHashKey(hashKeyDataMap) fmt.Println("hashKeyData:", hashKeyData) diff --git a/utils/hash/hash.go b/utils/hash/hash.go index 968decf1..228c8328 100644 --- a/utils/hash/hash.go +++ b/utils/hash/hash.go @@ -5,13 +5,12 @@ import ( "crypto/sha256" "encoding/json" "fmt" - "reflect" "sort" ) func JsonHashKey(v interface{}) string { - if reflect.TypeOf(v).Kind() == reflect.String { + if _, ok := v.(string); ok { var obj interface{} err := json.Unmarshal([]byte(v.(string)), &obj) if err == nil { From bc6959bc9aabbb8a18ad0e2df0a16fdb788ed259 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Mon, 21 Aug 2023 09:57:57 +0800 Subject: [PATCH 02/15] fix --- server/websocket/internal/logic/ws_render_image_logic.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/websocket/internal/logic/ws_render_image_logic.go b/server/websocket/internal/logic/ws_render_image_logic.go index 5f225038..1bcc26f9 100644 --- a/server/websocket/internal/logic/ws_render_image_logic.go +++ b/server/websocket/internal/logic/ws_render_image_logic.go @@ -189,7 +189,7 @@ func (w *wsConnectItem) assembleRenderData(taskId string, info websocket_data.Re logx.Error("合成刀版图失败,合成的刀版图是空指针:", err) return err } - logx.Info("合成刀版图成功,合成刀版图数据:", combineReq, ",模板id:", productTemplate.Id, ",原logo:", info.RenderData.Logo, "刀版图:", *res.ResourceUrl) + logx.Info("合成刀版图成功,合成刀版图数据:", combineReq, ",logo图片:", info.RenderData.Logo, " 刀版图:", *res.ResourceUrl) //获取渲染设置信息 element, err := w.logic.svcCtx.AllModels.FsProductTemplateElement.FindOneByModelId(w.logic.ctx, *productTemplate.ModelId) if err != nil { From c62d5fd1d5307febb217be2a603ec4e305ed177c Mon Sep 17 00:00:00 2001 From: momo <1012651275@qq.com> Date: Mon, 21 Aug 2023 10:09:26 +0800 Subject: [PATCH 03/15] =?UTF-8?q?fix:hash=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- service/repositories/image_handle.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/service/repositories/image_handle.go b/service/repositories/image_handle.go index 54954862..b5ff1763 100644 --- a/service/repositories/image_handle.go +++ b/service/repositories/image_handle.go @@ -261,7 +261,11 @@ type ( /* 图片裁剪 */ func (l *defaultImageHandle) LogoStandard(ctx context.Context, in *LogoStandardReq) (*LogoStandardRes, error) { - var resourceId string = hash.JsonHashKey(in) + var hashKeyDataMap map[string]interface{} + hashKeyDataB, _ := json.Marshal(in) + json.Unmarshal(hashKeyDataB, &hashKeyDataMap) + var resourceId string = hash.JsonHashKey(hashKeyDataMap) + var postMap = make(map[string]interface{}, 5) postMap["is_remove_bg"] = in.IsRemoveBg postMap["logo_file"] = in.LogoFile From 6a912a145e1b1189c325a0601fbcfab060a23531 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Mon, 21 Aug 2023 10:21:02 +0800 Subject: [PATCH 04/15] fix --- model/gmodel/fs_product_template_v2_logic.go | 14 ++++++++++++++ .../internal/logic/gettagproductlistlogic.go | 11 +++++++++-- server/product/internal/types/types.go | 1 + server_api/product.api | 1 + 4 files changed, 25 insertions(+), 2 deletions(-) diff --git a/model/gmodel/fs_product_template_v2_logic.go b/model/gmodel/fs_product_template_v2_logic.go index d5364778..40e8a6bc 100755 --- a/model/gmodel/fs_product_template_v2_logic.go +++ b/model/gmodel/fs_product_template_v2_logic.go @@ -153,3 +153,17 @@ func (t *FsProductTemplateV2Model) GetListByProductAndTemplateTag(ctx context.Co err = db.Find(&resp).Error return resp, err } +func (t *FsProductTemplateV2Model) FindAllByProductIdsTemplateTag(ctx context.Context, productIds []int64, templateTag string, sort string, fields ...string) (resp []FsProductTemplateV2, err error) { + if len(productIds) == 0 { + return + } + db := t.db.WithContext(ctx).Model(&FsProductTemplateV2{}).Where("`product_id` in (?) and `template_tag` = ? and `is_del` = ? and `status` = ?", productIds, templateTag, 0, 1) + if sort != "" { + db = db.Order(sort) + } + if len(fields) != 0 { + db = db.Select(fields[0]) + } + err = db.Find(&resp).Error + return resp, err +} diff --git a/server/product/internal/logic/gettagproductlistlogic.go b/server/product/internal/logic/gettagproductlistlogic.go index 8d51e6fa..3e7061fd 100644 --- a/server/product/internal/logic/gettagproductlistlogic.go +++ b/server/product/internal/logic/gettagproductlistlogic.go @@ -170,13 +170,20 @@ func (l *GetTagProductListLogic) GetTagProductList(req *types.GetTagProductListR } } //获取模板(只是获取产品product_id,id) - productTemplatesV2, err = l.svcCtx.AllModels.FsProductTemplateV2.FindAllByProductIds(l.ctx, productIds, "sort ASC", "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, "get product template_v2 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 } //获取产品尺寸数量 diff --git a/server/product/internal/types/types.go b/server/product/internal/types/types.go index 7d511c6e..bc9c1135 100644 --- a/server/product/internal/types/types.go +++ b/server/product/internal/types/types.go @@ -249,6 +249,7 @@ type GetRecommandProductListRsp struct { type GetTagProductListReq struct { Cid int64 `form:"cid,optional"` //分类id Size uint32 `form:"size,optional"` //尺寸 + TemplateTag string `form:"template_tag,optional"` //模板标签 WithProduct bool `form:"with_product,optional"` //是否携带分类下的产品 } diff --git a/server_api/product.api b/server_api/product.api index 8a6fdbf8..b479c9ef 100644 --- a/server_api/product.api +++ b/server_api/product.api @@ -301,6 +301,7 @@ type GetRecommandProductListRsp { type GetTagProductListReq { Cid int64 `form:"cid,optional"` //分类id Size uint32 `form:"size,optional"` //尺寸 + TemplateTag string `form:"template_tag,optional"` //模板标签 WithProduct bool `form:"with_product,optional"` //是否携带分类下的产品 } type GetTagProductListRsp { From 346ffd1620d8f715a184824784888fb1398b972d Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Mon, 21 Aug 2023 10:27:25 +0800 Subject: [PATCH 05/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 3e7061fd..c8642633 100644 --- a/server/product/internal/logic/gettagproductlistlogic.go +++ b/server/product/internal/logic/gettagproductlistlogic.go @@ -63,6 +63,7 @@ func (l *GetTagProductListLogic) GetTagProductList(req *types.GetTagProductListR logx.Error(err) return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get tag info") } + //前台用的分类是1 if *tagData.Category != 1 { return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "invalid tag") } From 0990644b4a9030dbef56bc6f571d6baa1df5da1f Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Mon, 21 Aug 2023 10:53:21 +0800 Subject: [PATCH 06/15] fix --- server/websocket/internal/logic/ws_render_image_logic.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/websocket/internal/logic/ws_render_image_logic.go b/server/websocket/internal/logic/ws_render_image_logic.go index 1bcc26f9..3d4f42c5 100644 --- a/server/websocket/internal/logic/ws_render_image_logic.go +++ b/server/websocket/internal/logic/ws_render_image_logic.go @@ -41,7 +41,7 @@ func (w *wsConnectItem) sendToRenderChan(data []byte) { } } -// 渲染发送到组装数据组装数据 +// 渲染发送到组装数据组装数据(缓冲池) func (w *wsConnectItem) renderImage() { defer func() { if err := recover(); err != nil { From feae3ada3318f1765130d82e74216f3e42adb69c Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Mon, 21 Aug 2023 11:25:56 +0800 Subject: [PATCH 07/15] fix --- .../websocket/internal/logic/ws_render_image_logic.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/server/websocket/internal/logic/ws_render_image_logic.go b/server/websocket/internal/logic/ws_render_image_logic.go index 3d4f42c5..7e44e43d 100644 --- a/server/websocket/internal/logic/ws_render_image_logic.go +++ b/server/websocket/internal/logic/ws_render_image_logic.go @@ -34,9 +34,9 @@ func (w *wsConnectItem) sendToRenderChan(data []byte) { select { case <-w.closeChan: //已经关闭 return - case w.renderProperty.renderChan <- data: + case w.renderProperty.renderChan <- data: //发入到缓冲池 return - case <-time.After(time.Second * 3): + case <-time.After(time.Second * 3): //三秒没进入缓冲池就丢弃 return } } @@ -296,15 +296,17 @@ func (w *wsConnectItem) assembleRenderData(taskId string, info websocket_data.Re func (w *wsConnectItem) operationRenderTask() { for { select { - case <-w.closeChan: + case <-w.closeChan: //整个链接关闭 return - case data := <-w.renderProperty.renderImageTaskCtlChan: + case data := <-w.renderProperty.renderImageTaskCtlChan: //处理任务 switch data.Option { case 0: //删除任务 delete(w.renderProperty.renderImageTask, data.TaskId) case 1: //新增任务 w.renderProperty.renderImageTask[data.TaskId] = data.RenderId } + case <-time.After(time.Second * 3): //三秒阻塞则丢弃 + return } } } From e2744a54f236e78d09a59f59ef434615bfdafbab Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Mon, 21 Aug 2023 11:27:17 +0800 Subject: [PATCH 08/15] fix --- server/websocket/internal/logic/ws_render_image_logic.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/server/websocket/internal/logic/ws_render_image_logic.go b/server/websocket/internal/logic/ws_render_image_logic.go index 7e44e43d..db3816aa 100644 --- a/server/websocket/internal/logic/ws_render_image_logic.go +++ b/server/websocket/internal/logic/ws_render_image_logic.go @@ -296,17 +296,15 @@ func (w *wsConnectItem) assembleRenderData(taskId string, info websocket_data.Re func (w *wsConnectItem) operationRenderTask() { for { select { - case <-w.closeChan: //整个链接关闭 + case <-w.closeChan: return - case data := <-w.renderProperty.renderImageTaskCtlChan: //处理任务 + case data := <-w.renderProperty.renderImageTaskCtlChan: switch data.Option { case 0: //删除任务 delete(w.renderProperty.renderImageTask, data.TaskId) case 1: //新增任务 w.renderProperty.renderImageTask[data.TaskId] = data.RenderId } - case <-time.After(time.Second * 3): //三秒阻塞则丢弃 - return } } } From 46ce6ded3cca2b4f782c5a21bc87bd13bcfe1e9d Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Mon, 21 Aug 2023 13:19:12 +0800 Subject: [PATCH 09/15] fix --- .../internal/logic/rendernotifylogic.go | 39 +++------------ .../internal/logic/ws_render_image_logic.go | 50 ++++++++++++++++--- 2 files changed, 50 insertions(+), 39 deletions(-) diff --git a/server/websocket/internal/logic/rendernotifylogic.go b/server/websocket/internal/logic/rendernotifylogic.go index e14983d4..5fe8d1e4 100644 --- a/server/websocket/internal/logic/rendernotifylogic.go +++ b/server/websocket/internal/logic/rendernotifylogic.go @@ -1,14 +1,10 @@ package logic import ( - "fusenapi/constants" + "context" "fusenapi/utils/auth" "fusenapi/utils/basic" "fusenapi/utils/file" - "fusenapi/utils/websocket_data" - "time" - - "context" "fusenapi/server/websocket/internal/svc" "fusenapi/server/websocket/internal/types" @@ -77,34 +73,13 @@ func (l *RenderNotifyLogic) RenderNotify(req *types.RenderNotifyReq, userinfo *a logx.Error("渲染回调断言websocket连接失败") return true } - //关闭标识 - if ws.isClose { - return true - } - //查询有无该渲染任务 - renderId, ok := ws.renderProperty.renderImageTask[req.TaskId] - if !ok { - return true - } - b := ws.respondDataFormat(constants.WEBSOCKET_RENDER_IMAGE, websocket_data.RenderImageRspMsg{ - RenderId: renderId, - Image: uploadRes.ResourceUrl, + //发送处理并删除任务 + ws.deleteRenderTask(renderImageControlChanItem{ + Option: 0, //0删除 1添加 + TaskId: req.TaskId, + RenderNotifyImageUrl: uploadRes.ResourceUrl, }) - deleteTask := renderImageControlChanItem{ - Option: 0, //0删除 1添加 - TaskId: req.TaskId, - RenderId: renderId, - } - select { - case <-ws.closeChan: //关闭了 - return true - case ws.renderProperty.renderImageTaskCtlChan <- deleteTask: //删除对应的需要渲染的图片map - //发送数据到out chan - ws.sendToOutChan(b) - return true - case <-time.After(time.Second * 3): //超时丢弃 - return true - } + return true }) logx.Info("渲染回调成功######################") return resp.SetStatusWithMessage(basic.CodeOK, "success") diff --git a/server/websocket/internal/logic/ws_render_image_logic.go b/server/websocket/internal/logic/ws_render_image_logic.go index db3816aa..d293eee9 100644 --- a/server/websocket/internal/logic/ws_render_image_logic.go +++ b/server/websocket/internal/logic/ws_render_image_logic.go @@ -24,9 +24,10 @@ type renderProperty struct { // 渲染任务新增移除的控制通道的数据 type renderImageControlChanItem struct { - Option int // 0删除 1添加 - TaskId string //map的key - RenderId string // map的val + Option int // 0删除 1添加 + TaskId string //map的key + RenderId string // map的val(增加任务时候传) + RenderNotifyImageUrl string //渲染回调数据(删除任务时候传) } // 发送到渲染缓冲池 @@ -137,11 +138,11 @@ func (w *wsConnectItem) consumeRenderCache(data []byte) { } //########################################### //把需要渲染的图片任务加进去 - w.renderProperty.renderImageTaskCtlChan <- renderImageControlChanItem{ + w.createRenderTask(renderImageControlChanItem{ Option: 1, //0删除 1添加 TaskId: taskId, RenderId: renderImageData.RenderId, - } + }) //组装数据 if err = w.assembleRenderData(taskId, renderImageData); err != nil { logx.Error("组装数据失败:", err) @@ -292,7 +293,35 @@ func (w *wsConnectItem) assembleRenderData(taskId string, info websocket_data.Re return nil } -// 操作连接中渲染任务的增加/删除 +// 增加渲染任务 +func (w *wsConnectItem) createRenderTask(data renderImageControlChanItem) { + //强制设为增加 + data.Option = 1 + select { + case <-w.closeChan: //关闭 + return + case w.renderProperty.renderImageTaskCtlChan <- data: + return + case <-time.After(time.Second * 3): + return + } +} + +// 渲染回调处理并删除渲染任务 +func (w *wsConnectItem) deleteRenderTask(data renderImageControlChanItem) { + //强制设为删除 + data.Option = 0 + select { + case <-w.closeChan: //关闭 + return + case w.renderProperty.renderImageTaskCtlChan <- data: + return + case <-time.After(time.Second * 3): + return + } +} + +// 操作连接中渲染任务的增加/删除(任务map不能读写并发,所以放在chan里面串行执行) func (w *wsConnectItem) operationRenderTask() { for { select { @@ -300,7 +329,14 @@ func (w *wsConnectItem) operationRenderTask() { return case data := <-w.renderProperty.renderImageTaskCtlChan: switch data.Option { - case 0: //删除任务 + case 0: //渲染结果回调,删除任务 + //存在任务,则发送渲染结果给前端 + if renderId, ok := w.renderProperty.renderImageTask[data.TaskId]; ok { + w.sendToOutChan(w.respondDataFormat(constants.WEBSOCKET_RENDER_IMAGE, websocket_data.RenderImageRspMsg{ + RenderId: renderId, + Image: data.RenderNotifyImageUrl, + })) + } delete(w.renderProperty.renderImageTask, data.TaskId) case 1: //新增任务 w.renderProperty.renderImageTask[data.TaskId] = data.RenderId From 0e3ac4cb775e118cb5165b591dfc5979f9361809 Mon Sep 17 00:00:00 2001 From: momo <1012651275@qq.com> Date: Mon, 21 Aug 2023 13:35:31 +0800 Subject: [PATCH 10/15] =?UTF-8?q?fix:=E6=96=87=E4=BB=B6=E4=B8=8A=E4=BC=A0?= =?UTF-8?q?=E5=A4=A7=E5=B0=8F=E9=99=90=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/upload/etc/upload.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/server/upload/etc/upload.yaml b/server/upload/etc/upload.yaml index a2a2cb4b..37f60999 100644 --- a/server/upload/etc/upload.yaml +++ b/server/upload/etc/upload.yaml @@ -2,6 +2,7 @@ Name: upload Host: 0.0.0.0 Port: 9912 Timeout: 150000 #服务超时时间 +MaxBytes: 8388608 #传输字节大小 SourceMysql: "fusentest:XErSYmLELKMnf3Dh@tcp(110.41.19.98:3306)/fusentest" Env: "test" Auth: From 23d68effd45eb187c17f32bcec3b5496ff070936 Mon Sep 17 00:00:00 2001 From: momo <1012651275@qq.com> Date: Mon, 21 Aug 2023 13:42:11 +0800 Subject: [PATCH 11/15] =?UTF-8?q?fix:=E6=96=87=E4=BB=B6=E4=B8=8A=E4=BC=A0?= =?UTF-8?q?=E5=A4=A7=E5=B0=8F=E9=99=90=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/upload/internal/logic/uploadlogologic.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/server/upload/internal/logic/uploadlogologic.go b/server/upload/internal/logic/uploadlogologic.go index bd495c61..0318e245 100644 --- a/server/upload/internal/logic/uploadlogologic.go +++ b/server/upload/internal/logic/uploadlogologic.go @@ -95,6 +95,12 @@ func (l *UploadLogoLogic) UploadLogo(req *types.UploadLogoReq, userinfo *auth.Us return resp.SetStatus(basic.CodeFileUploadErr, "file upload err,file is not image") } + // 限制上传文件大小 50k + maxSize := 100 * 1024 + if fileHeader.Size > int64(maxSize) { + return resp.SetStatus(basic.CodeFileUploadErr, "file upload err,The file size exceeds the maximum limit of 100k") + } + // 读取数据流 ioData, err := io.ReadAll(fileObject) if err != nil { From 94d93bf39016f075310e76069aa9e5226ba75e4f Mon Sep 17 00:00:00 2001 From: momo <1012651275@qq.com> Date: Mon, 21 Aug 2023 14:06:24 +0800 Subject: [PATCH 12/15] fix --- server/resource/etc/resource.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/resource/etc/resource.yaml b/server/resource/etc/resource.yaml index 099a6460..f2f27737 100644 --- a/server/resource/etc/resource.yaml +++ b/server/resource/etc/resource.yaml @@ -15,8 +15,8 @@ AWS: Secret: sjCEv0JxATnPCxno2KNLm0X8oDc7srUR+4vkYhvm Token: BLMService: - # Url: "http://18.119.109.254:8999" - Url: "http://192.168.1.7:8999" + Url: "http://18.119.109.254:8999" + # Url: "http://192.168.1.7:8999" LogoCombine: #Url: "http://192.168.1.7:8999/LogoCombine" Url: "http://18.119.109.254:8999/LogoCombine" \ No newline at end of file From 5e251e9868aefe62c63aa3a2464ae8f4c48f3033 Mon Sep 17 00:00:00 2001 From: momo <1012651275@qq.com> Date: Mon, 21 Aug 2023 14:39:03 +0800 Subject: [PATCH 13/15] fix --- server/upload/etc/upload.yaml | 2 +- service/repositories/image_handle.go | 35 ++++++++++++++++++++++++++-- 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/server/upload/etc/upload.yaml b/server/upload/etc/upload.yaml index 37f60999..8f8afac9 100644 --- a/server/upload/etc/upload.yaml +++ b/server/upload/etc/upload.yaml @@ -2,7 +2,7 @@ Name: upload Host: 0.0.0.0 Port: 9912 Timeout: 150000 #服务超时时间 -MaxBytes: 8388608 #传输字节大小 +MaxBytes: 104857600 #传输字节大小 SourceMysql: "fusentest:XErSYmLELKMnf3Dh@tcp(110.41.19.98:3306)/fusentest" Env: "test" Auth: diff --git a/service/repositories/image_handle.go b/service/repositories/image_handle.go index b5ff1763..305ffe2c 100644 --- a/service/repositories/image_handle.go +++ b/service/repositories/image_handle.go @@ -257,15 +257,46 @@ type ( IsmaxProportion bool ImgColor []string } + LogoStandardMetaData struct { + Param LogoStandardReq `json:"param"` + Result LogoStandardRes `json:"result"` + } ) /* 图片裁剪 */ func (l *defaultImageHandle) LogoStandard(ctx context.Context, in *LogoStandardReq) (*LogoStandardRes, error) { + var ismaxProportion bool + var imgColor []string + var logoStandardMetaData LogoStandardMetaData + var hashKeyDataMap map[string]interface{} hashKeyDataB, _ := json.Marshal(in) json.Unmarshal(hashKeyDataB, &hashKeyDataMap) var resourceId string = hash.JsonHashKey(hashKeyDataMap) + resourceModel := gmodel.NewFsResourceModel(l.MysqlConn) + resourceInfo, err := resourceModel.FindOneById(ctx, resourceId) + if err == nil && resourceInfo.ResourceId != "" { + if resourceInfo.Metadata != nil { + json.Unmarshal([]byte(*resourceInfo.Metadata), &logoStandardMetaData) + } + // 取出参数 + + return &LogoStandardRes{ + ResourceId: resourceInfo.ResourceId, + ResourceUrl: *resourceInfo.ResourceUrl, + IsmaxProportion: ismaxProportion, + ImgColor: imgColor, + }, nil + } else { + if err != nil { + if !errors.Is(err, gorm.ErrRecordNotFound) { + logx.Error(err) + return nil, err + } + } + } + var postMap = make(map[string]interface{}, 5) postMap["is_remove_bg"] = in.IsRemoveBg postMap["logo_file"] = in.LogoFile @@ -319,12 +350,12 @@ func (l *defaultImageHandle) LogoStandard(ctx context.Context, in *LogoStandardR logx.Error(err) return nil, err } + //$removeBg ='{"nobg_url": "/test/dIE10gGfXM_scale.png", "thumbnail_url": "/test/dIE10gGfXM_thumbnail.png", "ismax_proportion": true, "img_color": ["#000000", "#EEF5FB", "#6AAFE6", "#9ECDF1", "#298EDC", "#0C7BD1"]}' var fileBase = resultData["nobg_url"].(string) - var ismaxProportion = resultData["ismax_proportion"].(bool) + ismaxProportion = resultData["ismax_proportion"].(bool) - var imgColor []string for _, v := range resultData["img_color"].([]interface{}) { imgColor = append(imgColor, v.(string)) } From c19f4ba6d28cbdbe2584cc2f5c896a7eb371ab49 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Mon, 21 Aug 2023 14:46:39 +0800 Subject: [PATCH 14/15] fix --- server/websocket/internal/logic/rendernotifylogic.go | 2 +- server/websocket/internal/logic/ws_render_image_logic.go | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/server/websocket/internal/logic/rendernotifylogic.go b/server/websocket/internal/logic/rendernotifylogic.go index 5fe8d1e4..44d0cd51 100644 --- a/server/websocket/internal/logic/rendernotifylogic.go +++ b/server/websocket/internal/logic/rendernotifylogic.go @@ -81,6 +81,6 @@ func (l *RenderNotifyLogic) RenderNotify(req *types.RenderNotifyReq, userinfo *a }) return true }) - logx.Info("渲染回调成功######################") + logx.Info("渲染回调成功,渲染结果图片为:", uploadRes.ResourceUrl) return resp.SetStatusWithMessage(basic.CodeOK, "success") } diff --git a/server/websocket/internal/logic/ws_render_image_logic.go b/server/websocket/internal/logic/ws_render_image_logic.go index d293eee9..f04a470e 100644 --- a/server/websocket/internal/logic/ws_render_image_logic.go +++ b/server/websocket/internal/logic/ws_render_image_logic.go @@ -283,13 +283,13 @@ func (w *wsConnectItem) assembleRenderData(taskId string, info websocket_data.Re "create_at": t, "render_data": sendData, } - p, _ := json.Marshal(postData) - _, err = curl.ApiCall(url, "POST", header, bytes.NewReader(p), time.Second*10) + postDataBytes, _ := json.Marshal(postData) + _, err = curl.ApiCall(url, "POST", header, bytes.NewReader(postDataBytes), time.Second*10) if err != nil { logx.Error("failed to send data to unity") return err } - logx.Info("发送到unity成功################") + logx.Info("发送到unity成功,刀版图:", combineImage, " 请求unity的数据:", string(postDataBytes)) return nil } From 7e96383530a1b3695c8cdbce02afa40b5fb01a25 Mon Sep 17 00:00:00 2001 From: momo <1012651275@qq.com> Date: Mon, 21 Aug 2023 14:59:21 +0800 Subject: [PATCH 15/15] fix --- service/repositories/image_handle.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/service/repositories/image_handle.go b/service/repositories/image_handle.go index 305ffe2c..1f86dacb 100644 --- a/service/repositories/image_handle.go +++ b/service/repositories/image_handle.go @@ -281,6 +281,8 @@ func (l *defaultImageHandle) LogoStandard(ctx context.Context, in *LogoStandardR json.Unmarshal([]byte(*resourceInfo.Metadata), &logoStandardMetaData) } // 取出参数 + ismaxProportion = logoStandardMetaData.Result.IsmaxProportion + imgColor = logoStandardMetaData.Result.ImgColor return &LogoStandardRes{ ResourceId: resourceInfo.ResourceId, @@ -360,6 +362,20 @@ func (l *defaultImageHandle) LogoStandard(ctx context.Context, in *LogoStandardR imgColor = append(imgColor, v.(string)) } + var logoStandardRes LogoStandardRes + logoStandardRes.IsmaxProportion = ismaxProportion + logoStandardRes.ImgColor = imgColor + + logoStandardMetaData.Param = *in + logoStandardMetaData.Result = logoStandardRes + metadataB, err := json.Marshal(logoStandardMetaData) + if err != nil { + logx.Error(err) + return nil, err + } + + var metadata = string(metadataB) + // 上传文件 var upload = file.Upload{ Ctx: ctx, @@ -372,6 +388,7 @@ func (l *defaultImageHandle) LogoStandard(ctx context.Context, in *LogoStandardR FileData: fileBase, UploadBucket: 1, ApiType: 2, + Metadata: metadata, }) if err != nil { logx.Error(err)