Merge branch 'develop' of gitee.com:fusenpack/fusenapi into develop
This commit is contained in:
commit
c6ad2dbe8e
35
server/product/internal/handler/getproductmodelshandler.go
Normal file
35
server/product/internal/handler/getproductmodelshandler.go
Normal file
|
@ -0,0 +1,35 @@
|
|||
package handler
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"reflect"
|
||||
|
||||
"fusenapi/utils/basic"
|
||||
|
||||
"fusenapi/server/product/internal/logic"
|
||||
"fusenapi/server/product/internal/svc"
|
||||
"fusenapi/server/product/internal/types"
|
||||
)
|
||||
|
||||
func GetProductModelsHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
var req types.GetProductModelsReq
|
||||
userinfo, err := basic.RequestParse(w, r, svcCtx, &req)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
// 创建一个业务逻辑层实例
|
||||
l := logic.NewGetProductModelsLogic(r.Context(), svcCtx)
|
||||
|
||||
rl := reflect.ValueOf(l)
|
||||
basic.BeforeLogic(w, r, rl)
|
||||
|
||||
resp := l.GetProductModels(&req, userinfo)
|
||||
|
||||
if !basic.AfterLogic(w, r, rl, resp) {
|
||||
basic.NormalAfterLogic(w, r, resp)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -42,6 +42,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
|||
Path: "/api/product/get_product_detail",
|
||||
Handler: GetProductDetailHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodGet,
|
||||
Path: "/api/product/get_product_models",
|
||||
Handler: GetProductModelsHandler(serverCtx),
|
||||
},
|
||||
},
|
||||
)
|
||||
}
|
||||
|
|
120
server/product/internal/logic/getproductmodelslogic.go
Normal file
120
server/product/internal/logic/getproductmodelslogic.go
Normal file
|
@ -0,0 +1,120 @@
|
|||
package logic
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"fusenapi/constants"
|
||||
"fusenapi/utils/auth"
|
||||
"fusenapi/utils/basic"
|
||||
"fusenapi/utils/format"
|
||||
"strings"
|
||||
|
||||
"context"
|
||||
|
||||
"fusenapi/server/product/internal/svc"
|
||||
"fusenapi/server/product/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type GetProductModelsLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewGetProductModelsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetProductModelsLogic {
|
||||
return &GetProductModelsLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
// 处理进入前逻辑w,r
|
||||
// func (l *GetProductModelsLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) {
|
||||
// }
|
||||
|
||||
func (l *GetProductModelsLogic) GetProductModels(req *types.GetProductModelsReq, userinfo *auth.UserInfo) (resp *basic.Response) {
|
||||
req.ProductIds = strings.Trim(req.ProductIds, " ")
|
||||
productIds, err := format.StrSlicToInt64Slice(strings.Split(req.ProductIds, ","))
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "err param(format err)")
|
||||
}
|
||||
if len(productIds) > 10 {
|
||||
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "the count of product can`t greater than 10")
|
||||
}
|
||||
if len(productIds) == 0 {
|
||||
return resp.SetStatusWithMessage(basic.CodeOK, "success", nil)
|
||||
}
|
||||
//获取产品信息
|
||||
productList, err := l.svcCtx.AllModels.FsProduct.GetProductListByIds(l.ctx, productIds, "")
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get product list")
|
||||
}
|
||||
if len(productList) != len(productIds) {
|
||||
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "some one product is invalid")
|
||||
}
|
||||
//获取产品所有的模型以及配件
|
||||
modelList, err := l.svcCtx.AllModels.FsProductModel3d.GetAllByProductIdsTags(l.ctx, productIds, []int{constants.TAG_MODEL, constants.TAG_PARTS})
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get model list")
|
||||
}
|
||||
mapProductModels := make(map[int64][]types.ModelItem)
|
||||
lightIds := make([]int64, 0, len(modelList))
|
||||
for _, v := range modelList {
|
||||
lightIds = append(lightIds, *v.Light)
|
||||
}
|
||||
//获取光源列表
|
||||
lightList, err := l.svcCtx.AllModels.FsProductModel3dLight.GetAllByIds(l.ctx, lightIds)
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get light list")
|
||||
}
|
||||
mapLight := make(map[int64]int)
|
||||
for k, v := range lightList {
|
||||
mapLight[v.Id] = k
|
||||
}
|
||||
for _, v := range modelList {
|
||||
//模型设计信息
|
||||
var modelDesignInfo interface{}
|
||||
if v.ModelInfo != nil && *v.ModelInfo != "" {
|
||||
if err = json.Unmarshal([]byte(*v.ModelInfo), &modelDesignInfo); err != nil {
|
||||
logx.Error(err)
|
||||
return resp.SetStatusWithMessage(basic.CodeJsonErr, fmt.Sprintf("failed to parse model design info[:%d]", v.Id))
|
||||
}
|
||||
}
|
||||
//光源信息
|
||||
var lightDesignInfo interface{}
|
||||
if lightIndex, ok := mapLight[*v.Light]; ok {
|
||||
lightInfo := lightList[lightIndex]
|
||||
if lightInfo.Info != nil && *lightInfo.Info != "" {
|
||||
if err = json.Unmarshal([]byte(*lightInfo.Info), &lightDesignInfo); err != nil {
|
||||
logx.Error(err)
|
||||
return resp.SetStatusWithMessage(basic.CodeJsonErr, fmt.Sprintf("failed to parse light design info[:%d]", lightInfo.Id))
|
||||
}
|
||||
}
|
||||
}
|
||||
mapProductModels[*v.ProductId] = append(mapProductModels[*v.ProductId], types.ModelItem{
|
||||
Id: v.Id,
|
||||
Type: *v.Tag,
|
||||
Title: *v.Title,
|
||||
Name: *v.Name,
|
||||
DesignInfo: modelDesignInfo,
|
||||
LightInfo: lightDesignInfo,
|
||||
})
|
||||
}
|
||||
mapProductInfo := make(map[int64][]types.ModelItem)
|
||||
for _, v := range productList {
|
||||
mapProductInfo[v.Id] = mapProductModels[v.Id]
|
||||
}
|
||||
return resp.SetStatusWithMessage(basic.CodeOK, "success", mapProductInfo)
|
||||
}
|
||||
|
||||
// 处理逻辑后 w,r 如:重定向, resp 必须重新处理
|
||||
// func (l *GetProductModelsLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) {
|
||||
// // httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
// }
|
|
@ -172,6 +172,23 @@ type TemplateTagColorInfo struct {
|
|||
TemplateTagGroups interface{} `json:"template_tag_groups"` //模板标签分组信息
|
||||
}
|
||||
|
||||
type GetProductModelsReq struct {
|
||||
ProductIds string `form:"product_ids"`
|
||||
}
|
||||
|
||||
type ProductItem struct {
|
||||
ModelList []ModelItem `json:"model_list"`
|
||||
}
|
||||
|
||||
type ModelItem struct {
|
||||
Id int64 `json:"id"`
|
||||
Type int64 `json:"type"` //1模型 2配件 3场景
|
||||
Title string `json:"title"`
|
||||
Name string `json:"name"`
|
||||
DesignInfo interface{} `json:"design_info"`
|
||||
LightInfo interface{} `json:"light_info"`
|
||||
}
|
||||
|
||||
type Request struct {
|
||||
}
|
||||
|
||||
|
|
|
@ -10,33 +10,40 @@ import (
|
|||
// *******************************合图相关begin******************************
|
||||
// 发送合图完毕阶段通知消息
|
||||
func (w *wsConnectItem) sendCombineImageStepResponseMessage(requestId, combineImage string, sizeId, modelId, templateId int64, debugData *auth.DebugData) {
|
||||
if w.debug == nil {
|
||||
return
|
||||
}
|
||||
combineTakesTime := ""
|
||||
uploadCombineImageTakesTime := ""
|
||||
//开了缓存
|
||||
if w.debug.IsCache != 0 {
|
||||
combineTakesTime = "cache"
|
||||
uploadCombineImageTakesTime = "cache"
|
||||
if w.debug != nil { //开启debug
|
||||
//开了缓存
|
||||
if w.debug.IsCache != 0 {
|
||||
combineTakesTime = "cache"
|
||||
uploadCombineImageTakesTime = "cache"
|
||||
}
|
||||
if debugData != nil && debugData.DiffTimeLogoCombine > 0 {
|
||||
combineTakesTime = fmt.Sprintf("%dms", debugData.DiffTimeLogoCombine)
|
||||
}
|
||||
if debugData != nil && debugData.DiffTimeUploadFile > 0 {
|
||||
uploadCombineImageTakesTime = fmt.Sprintf("%dms", debugData.DiffTimeUploadFile)
|
||||
}
|
||||
w.sendToOutChan(w.respondDataFormat(constants.WEBSOCKET_COMBINE_IMAGE, websocket_data.CombineImageRspMsg{
|
||||
RequestId: requestId,
|
||||
CombineImage: combineImage,
|
||||
CombineRelative: &websocket_data.CombineRelative{
|
||||
SizeId: sizeId,
|
||||
ModelId: modelId,
|
||||
TemplateId: templateId,
|
||||
},
|
||||
CombineProcessTime: &websocket_data.CombineProcessTime{
|
||||
CombineTakesTime: combineTakesTime,
|
||||
UploadCombineImageTakesTime: uploadCombineImageTakesTime,
|
||||
},
|
||||
}))
|
||||
} else {
|
||||
w.sendToOutChan(w.respondDataFormat(constants.WEBSOCKET_COMBINE_IMAGE, websocket_data.CombineImageRspMsg{
|
||||
RequestId: requestId,
|
||||
CombineImage: combineImage,
|
||||
}))
|
||||
}
|
||||
if debugData != nil && debugData.DiffTimeLogoCombine > 0 {
|
||||
combineTakesTime = fmt.Sprintf("%dms", debugData.DiffTimeLogoCombine)
|
||||
}
|
||||
if debugData != nil && debugData.DiffTimeUploadFile > 0 {
|
||||
uploadCombineImageTakesTime = fmt.Sprintf("%dms", debugData.DiffTimeUploadFile)
|
||||
}
|
||||
w.sendToOutChan(w.respondDataFormat(constants.WEBSOCKET_COMBINE_IMAGE, websocket_data.CombineImageRspMsg{
|
||||
RequestId: requestId,
|
||||
CombineImage: combineImage,
|
||||
SizeId: sizeId,
|
||||
ModelId: modelId,
|
||||
TemplateId: templateId,
|
||||
CombineProcessTime: &websocket_data.CombineProcessTime{
|
||||
CombineTakesTime: combineTakesTime,
|
||||
UploadCombineImageTakesTime: uploadCombineImageTakesTime,
|
||||
},
|
||||
}))
|
||||
|
||||
}
|
||||
|
||||
// 发送组装unity需要的数据完毕消息
|
||||
|
|
|
@ -28,6 +28,9 @@ service product {
|
|||
//获取产品详情
|
||||
@handler GetProductDetailHandler
|
||||
get /api/product/get_product_detail(GetProductDetailReq) returns (response);
|
||||
//根据产品获取模型配件列表
|
||||
@handler GetProductModelsHandler
|
||||
get /api/product/get_product_models(GetProductModelsReq) returns (response);
|
||||
}
|
||||
|
||||
//获取详情页推荐产品列表
|
||||
|
@ -185,4 +188,19 @@ type TemplateTagColorInfo {
|
|||
Colors [][]string `json:"colors"` //传入logo对应的算法颜色组
|
||||
SelectedColorIndex int `json:"selected_color_index"` //选择的模板标签的颜色索引值
|
||||
TemplateTagGroups interface{} `json:"template_tag_groups"` //模板标签分组信息
|
||||
}
|
||||
//根据产品获取模型配件列表
|
||||
type GetProductModelsReq {
|
||||
ProductIds string `form:"product_ids"`
|
||||
}
|
||||
type ProductItem {
|
||||
ModelList []ModelItem `json:"model_list"`
|
||||
}
|
||||
type ModelItem {
|
||||
Id int64 `json:"id"`
|
||||
Type int64 `json:"type"` //1模型 2配件 3场景
|
||||
Title string `json:"title"`
|
||||
Name string `json:"name"`
|
||||
DesignInfo interface{} `json:"design_info"`
|
||||
LightInfo interface{} `json:"light_info"`
|
||||
}
|
|
@ -35,18 +35,21 @@ type RenderImageRspMsg struct {
|
|||
type RenderProcessTime struct {
|
||||
UnityRenderTakesTime string `json:"unity_render_takes_time"` //unity渲染用时
|
||||
UploadUnityRenderImageTakesTime string `json:"upload_unity_render_image_takes_time"` //上传unity渲染结果图时间
|
||||
UnityRealTakesTime string `json:"unity_real_takes_time"`//unity真实处理时间
|
||||
UnityRealTakesTime string `json:"unity_real_takes_time"` //unity真实处理时间
|
||||
}
|
||||
|
||||
// 合图返回数据
|
||||
type CombineImageRspMsg struct {
|
||||
RequestId string `json:"request_id"`
|
||||
CombineImage string `json:"combine_image"` //刀版图
|
||||
SizeId int64 `json:"size_id"` //尺寸id
|
||||
ModelId int64 `json:"model_id"`
|
||||
TemplateId int64 `json:"template_id"`
|
||||
CombineImage string `json:"combine_image"` //刀版图
|
||||
CombineRelative *CombineRelative `json:"combine_relative"` //合图相关数据
|
||||
CombineProcessTime *CombineProcessTime `json:"combine_process_time"`
|
||||
}
|
||||
type CombineRelative struct {
|
||||
SizeId int64 `json:"size_id"` //尺寸id
|
||||
ModelId int64 `json:"model_id"`
|
||||
TemplateId int64 `json:"template_id"`
|
||||
}
|
||||
type CombineProcessTime struct {
|
||||
CombineTakesTime string `json:"combine_takes_time"` //合图时间
|
||||
UploadCombineImageTakesTime string `json:"upload_combine_image_takes_time"` //上传刀版图耗时
|
||||
|
|
Loading…
Reference in New Issue
Block a user