From edeb2bb5f1254aa71585433d0e49a7ef9fc52ff0 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Tue, 20 Jun 2023 19:56:18 +0800 Subject: [PATCH] fix --- model/gmodel/fs_map_library_logic.go | 6 +- .../gmodel/fs_product_model3d_light_logic.go | 10 ++ .../gmodel/fs_product_template_tags_logic.go | 9 ++ model/gmodel/fs_product_template_v2_logic.go | 8 ++ .../internal/logic/getmaplibrarylistlogic.go | 2 +- .../internal/logic/savemaplibrarylogic.go | 2 +- .../internal/logic/gettemplatevdetaillogic.go | 119 ++++++++++++++++- .../internal/types/types.go | 121 +----------------- server_api/product-templatev2.api | 114 ++--------------- 9 files changed, 160 insertions(+), 231 deletions(-) diff --git a/model/gmodel/fs_map_library_logic.go b/model/gmodel/fs_map_library_logic.go index 679eed30..3112e68c 100755 --- a/model/gmodel/fs_map_library_logic.go +++ b/model/gmodel/fs_map_library_logic.go @@ -2,10 +2,10 @@ package gmodel import "context" -func (ml *FsMapLibraryModel) GetAllEnabledList(ctx context.Context, fields string) (resp []FsMapLibrary, err error) { +func (ml *FsMapLibraryModel) GetAllEnabledList(ctx context.Context, fields ...string) (resp []FsMapLibrary, err error) { db := ml.db.WithContext(ctx).Model(&FsMapLibrary{}).Where("`status` = ?", 1) - if fields != "" { - db = db.Select(fields) + if len(fields) != 0 { + db = db.Select(fields[0]) } err = db.Find(&resp).Error if err != nil { diff --git a/model/gmodel/fs_product_model3d_light_logic.go b/model/gmodel/fs_product_model3d_light_logic.go index f35dfc56..919e6e9c 100755 --- a/model/gmodel/fs_product_model3d_light_logic.go +++ b/model/gmodel/fs_product_model3d_light_logic.go @@ -1 +1,11 @@ package gmodel + +import "context" + +func (l *FsProductModel3dLightModel) GetAllByIds(ctx context.Context, ids []int64) (resp []FsProductModel3dLight, err error) { + err = l.db.WithContext(ctx).Model(&FsProductModel3dLight{}).Where("`id` in (?)", ids).Find(&resp).Error + if err != nil { + return nil, err + } + return +} diff --git a/model/gmodel/fs_product_template_tags_logic.go b/model/gmodel/fs_product_template_tags_logic.go index 68fc2b2e..7793673f 100755 --- a/model/gmodel/fs_product_template_tags_logic.go +++ b/model/gmodel/fs_product_template_tags_logic.go @@ -14,3 +14,12 @@ func (pt *FsProductTemplateTagsModel) GetListByIds(ctx context.Context, ids []in } return } + +func (pt *FsProductTemplateTagsModel) FindOne(ctx context.Context, id int64, fields ...string) (resp *FsProductTemplateTags, err error) { + db := pt.db.WithContext(ctx).Model(&FsProductTemplateTags{}).Where("`id` = ?", id) + if len(fields) != 0 { + db = db.Select(fields[0]) + } + err = db.Take(resp).Error + return resp, err +} diff --git a/model/gmodel/fs_product_template_v2_logic.go b/model/gmodel/fs_product_template_v2_logic.go index 0eb7bb16..c620be45 100755 --- a/model/gmodel/fs_product_template_v2_logic.go +++ b/model/gmodel/fs_product_template_v2_logic.go @@ -29,3 +29,11 @@ func (t *FsProductTemplateV2Model) FindOne(ctx context.Context, id int64) (resp err = t.db.WithContext(ctx).Model(&FsProductTemplateV2{}).Where("`id` = ? ", id).Find(&resp).Error return resp, err } +func (t *FsProductTemplateV2Model) FindByParam(ctx context.Context, id int64, modelId int64, fields ...string) (resp *FsProductTemplateV2, err error) { + db := t.db.WithContext(ctx).Model(&FsProductTemplateV2{}).Where("`id` = ? and `model_id` = ?", id, modelId) + if len(fields) != 0 { + db = db.Select(fields[0]) + } + err = db.Take(&resp).Error + return resp, err +} diff --git a/server/map-library/internal/logic/getmaplibrarylistlogic.go b/server/map-library/internal/logic/getmaplibrarylistlogic.go index 42fbf82b..696ea555 100644 --- a/server/map-library/internal/logic/getmaplibrarylistlogic.go +++ b/server/map-library/internal/logic/getmaplibrarylistlogic.go @@ -32,7 +32,7 @@ func (l *GetMapLibraryListLogic) GetMapLibraryList(userinfo *auth.UserInfo) (res return resp.SetStatusWithMessage(basic.CodeServiceErr, "please login first") } mapLibraryModel := gmodel.NewFsMapLibraryModel(l.svcCtx.MysqlConn) - mapLibraryList, err := mapLibraryModel.GetAllEnabledList(l.ctx, "") + mapLibraryList, err := mapLibraryModel.GetAllEnabledList(l.ctx) if err != nil { logx.Error(err) return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to get map library list") diff --git a/server/map-library/internal/logic/savemaplibrarylogic.go b/server/map-library/internal/logic/savemaplibrarylogic.go index a9d4271c..51078d06 100644 --- a/server/map-library/internal/logic/savemaplibrarylogic.go +++ b/server/map-library/internal/logic/savemaplibrarylogic.go @@ -45,7 +45,7 @@ func (l *SaveMapLibraryLogic) SaveMapLibrary(userinfo *auth.UserInfo, req *http. } //获取所有贴图数据[获取id] mapLibraryModel := gmodel.NewFsMapLibraryModel(l.svcCtx.MysqlConn) - maplibraryList, err := mapLibraryModel.GetAllEnabledList(l.ctx, "`id`") + maplibraryList, err := mapLibraryModel.GetAllEnabledList(l.ctx, "id") if err != nil { logx.Error(err) return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to get map library list") diff --git a/server/product-templatev2/internal/logic/gettemplatevdetaillogic.go b/server/product-templatev2/internal/logic/gettemplatevdetaillogic.go index 15808ed0..30e66731 100644 --- a/server/product-templatev2/internal/logic/gettemplatevdetaillogic.go +++ b/server/product-templatev2/internal/logic/gettemplatevdetaillogic.go @@ -1,9 +1,17 @@ package logic import ( - "context" + "encoding/json" + "errors" + "fusenapi/model/gmodel" "fusenapi/utils/basic" + "fusenapi/utils/format" + "gorm.io/gorm" "net/http" + "strconv" + "strings" + + "context" "fusenapi/server/product-templatev2/internal/svc" "fusenapi/server/product-templatev2/internal/types" @@ -26,7 +34,8 @@ func NewGetTemplatevDetailLogic(ctx context.Context, svcCtx *svc.ServiceContext) } func (l *GetTemplatevDetailLogic) GetTemplatevDetail(req *types.GetTemplatevDetailReq, r *http.Request) (resp *basic.Response) { - /*authKey := r.Header.Get("Auth-Key") + // + authKey := r.Header.Get("Auth-Key") if authKey == "" { return resp.SetStatusWithMessage(basic.CodeUnAuth, "please login first") } @@ -45,7 +54,7 @@ func (l *GetTemplatevDetailLogic) GetTemplatevDetail(req *types.GetTemplatevDeta logx.Error(err) return resp.SetStatusWithMessage(basic.CodeUnAuth, "failed to get user info") } - //查询产品模型并肩测数据完整性 + //获取模型信息 productModel3dModel := gmodel.NewFsProductModel3dModel(l.svcCtx.MysqlConn) model3dInfo, err := productModel3dModel.FindOne(l.ctx, req.ModelId) if err != nil { @@ -55,11 +64,109 @@ func (l *GetTemplatevDetailLogic) GetTemplatevDetail(req *types.GetTemplatevDeta logx.Error(err) return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to get product model info") } + //查询产品模板并检测数据完整 + productTemplatev2Model := gmodel.NewFsProductTemplateV2Model(l.svcCtx.MysqlConn) + fields := "cover_img,id,is_public,logo_height,logo_width,material_img,model_id,name,product_id,sort,tag,template_info,title" + templatev2Info, err := productTemplatev2Model.FindByParam(l.ctx, req.TemplateId, req.ModelId, fields) + if err != nil { + if errors.Is(err, gorm.ErrRecordNotFound) { + return resp.SetStatusWithMessage(basic.CodeDbRecordNotFoundErr, "template info is not exists") + } + logx.Error(err) + return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to get product template info") + } + //获取模板标签 + templateTagModel := gmodel.NewFsProductTemplateTagsModel(l.svcCtx.MysqlConn) + tagId, err := strconv.ParseInt(*templatev2Info.Tag, 10, 64) + if err != nil { + logx.Error(err) + return resp.SetStatusWithMessage(basic.CodeServiceErr, "parse int tag id err") + } + templateTagInfo, err := templateTagModel.FindOne(l.ctx, tagId, "id,title") + if err != nil { + if errors.Is(err, gorm.ErrRecordNotFound) { + return resp.SetStatusWithMessage(basic.CodeDbRecordNotFoundErr, "template tag info is not exists") + } + logx.Error(err) + return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to get product template tag info") + } //配件ids partIds, err := format.StrSlicToIntSlice(strings.Split(*model3dInfo.PartList, ",")) - //产品模型数据解析model_info - if model3dInfo.ModelInfo != nil && *model3dInfo.ModelInfo != "" { + //灯光ids + var lightIds []int64 + if err = json.Unmarshal([]byte(*model3dInfo.LightList), &lightIds); err != nil { + logx.Error(err) + return resp.SetStatusWithMessage(basic.CodeServiceErr, "parse light list err") + } + //获取灯光列表 + productModel3dLightModel := gmodel.NewFsProductModel3dLightModel(l.svcCtx.MysqlConn) + model3dLightList, err := productModel3dLightModel.GetAllByIds(l.ctx, lightIds) + if err != nil { + logx.Error(err) + return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to get product model light list") + } + /* - }*/ + //产品模型数据解析model_info + $productModel['model_info'] = $productModel['model_info'] ? json_decode($productModel['model_info']) : null; + + //产品模板数据解析template_info + if ($productTemplate) { + $productTemplate['template_info'] = $productTemplate['template_info'] ? json_decode($productTemplate['template_info']) : ''; + } + //获取灯光列表 + $lightList = ProductModelLight::find()->where(['in', 'id', $lightListArr]) + ->select(['id', 'info']) + ->asArray()->all(); + + //产品模型灯光数据解析 + foreach ($lightList as $key => $val) { + $lightList[$key]['info'] = json_decode($val['info'], true); + } + + //查询使用该选项的模板 + if ($partIds) { + $optionModelInfo = ProductModel::find() + ->where(['in', 'id', $partIds]) + ->select('id,model_info,option_template') + ->asArray() + ->all(); + + //公共模板数据 + $optionIds = array_column($optionModelInfo, 'option_template'); + $optionTemplates = ProductTemplateV2::find()->where(['in', 'id', $optionIds]) + ->asArray() + ->all(); + $optionTemplates = array_column($optionTemplates, null, 'id'); + + //处理数据 + $optionModelInfoArr = []; + foreach ($optionModelInfo as $item => $row) { + $rowInfo = json_decode($row['model_info'], true); + if (isset($optionTemplates[$row['option_template']])) { + $rowInfo['material_img'] = $optionTemplates[$row['option_template']]['material_img']; + } + $rowInfo['id'] = $row['id']; + $optionModelInfoArr[] = $rowInfo; + } + } + + //是否是公共模板 + if ($productTemplate) { + if ($productTemplate['is_public'] == 1) { + $productTemplate['is_public'] = true; + } else { + $productTemplate['is_public'] = false; + } + } + + //返回的数据组装 + return [ + 'product_model_info' => $productModel['model_info'], + 'product_template' => $productTemplate ?? null, + 'light_list' => $lightList ?? [], + 'option_model_info' => $optionModelInfoArr ?? [], + 'tag' => $productModel['tag'], + ];*/ return resp.SetStatus(basic.CodeOK) } diff --git a/server/product-templatev2/internal/types/types.go b/server/product-templatev2/internal/types/types.go index a7bea79d..240f9151 100644 --- a/server/product-templatev2/internal/types/types.go +++ b/server/product-templatev2/internal/types/types.go @@ -11,11 +11,11 @@ type GetTemplatevDetailReq struct { } type GetTemplatevDetailRsp struct { - ProductModelInfo interface{} `json:"product_model_info"` - ProductTemplate ProductTemplate `json:"product_template"` - LightList []*Light `json:"light_list"` - OptionModelInfo []interface{} `json:"option_model_info"` - Tag int64 `json:"tag"` + ProductModelInfo interface{} `json:"product_model_info"` + ProductTemplate interface{} `json:"product_template"` + LightList []*Light `json:"light_list"` + OptionModelInfo []interface{} `json:"option_model_info"` + Tag int64 `json:"tag"` } type Tag struct { @@ -23,116 +23,9 @@ type Tag struct { Title string `json:"title"` } -type TemplateInfo struct { - Id int64 `json:"id"` - Name string `json:"name"` - Cover string `json:"cover"` - IsPublic bool `json:"isPublic"` - Material string `json:"material"` - MaterialList []*TemplateMateria `json:"materialList"` -} - -type ProductTemplate struct { - CoverImg string `json:"cover_img"` - Id int64 `json:"id"` - IsPublic bool `json:"is_public"` - LogoHeight int64 `json:"logo_height"` - LogoWidth int64 `json:"logo_width"` - MaterialImg string `json:"material_img"` - ModelId int64 `json:"model_id"` - Name string `json:"name"` - ProductId int64 `json:"product_id"` - Sort int64 `json:"sort"` - Tag Tag `json:"tag"` - TemplateInfo *TemplateInfo `json:"template_info"` - Title string `json:"title"` -} - type Light struct { - Id int64 `json:"id"` - Info LightInfo `json:"info"` -} - -type TemplateMateria struct { - Id string `json:"id"` - Tag string `json:"tag"` - Title string `json:"title"` - Type string `json:"type"` - Text string `json:"text"` - Fill string `json:"fill"` - FontSize int64 `json:"fontSize"` - FontFamily string `json:"fontFamily"` - IfBr bool `json:"ifBr"` - IfShow bool `json:"ifShow"` - IfGroup bool `json:"ifGroup"` - MaxNum int64 `json:"maxNum"` - Rotation int64 `json:"rotation"` - LineHeight int64 `json:"lineHeight"` - Align string `json:"align"` - VerticalAlign string `json:"verticalAlign"` - Material string `json:"material"` - MaterialTime string `json:"materialTime"` - MaterialName string `json:"materialName"` - QRcodeType string `json:"QRcodeType"` - Width int64 `json:"width"` - Height int64 `json:"height"` - Proportion int64 `json:"proportion"` - X int64 `json:"x"` - Y int64 `json:"y"` - Opacity int64 `json:"opacity"` - OptionalColor []*OptionalColor `json:"optionalColor"` - ZIndex int64 `json:"zIndex"` - SvgPath string `json:"svgPath"` - Follow Follow `json:"follow"` - Group []interface{} `json:"group"` - CameraStand CameraStand `json:"cameraStand"` -} - -type LightInfo struct { - Name string `json:"name"` - Hdr Hdr `json:"hdr"` - LightData []LightDataItem `json:"lightData"` -} - -type LightDataItem struct { - Color string `json:"color"` - Id string `json:"id"` - Intensity float64 `json:"intensity"` - Name string `json:"name"` - Type string `json:"type"` - X float64 `json:"x,omitempty"` - Y int64 `json:"y,omitempty"` - Z float64 `json:"z,omitempty"` - ShowHelper bool `json:"showHelper,omitempty"` - Width int64 `json:"width,omitempty"` - Height int64 `json:"height,omitempty"` - Rx int64 `json:"rx,omitempty"` - Ry int64 `json:"ry,omitempty"` - Rz int64 `json:"rz,omitempty"` -} - -type Hdr struct { - IfBg bool `json:"ifBg"` - ToneMappingExposure float64 `json:"toneMappingExposure"` - Url string `json:"url"` -} - -type OptionalColor struct { - Color string `json:"color"` - Name string `json:"name"` - Default bool `json:"default"` -} - -type Follow struct { - Fill string `json:"fill"` - IfShow string `json:"ifShow"` - Content string `json:"content"` -} - -type CameraStand struct { - X int64 `json:"x"` - Y int64 `json:"y"` - Z int64 `json:"z"` + Id int64 `json:"id"` + Info interface{} `json:"info"` } type Response struct { diff --git a/server_api/product-templatev2.api b/server_api/product-templatev2.api index b68b4c2f..a074bb9b 100644 --- a/server_api/product-templatev2.api +++ b/server_api/product-templatev2.api @@ -19,117 +19,19 @@ type GetTemplatevDetailReq { TemplateId int64 `form:"template_id"` } type GetTemplatevDetailRsp { - ProductModelInfo interface{} `json:"product_model_info"` - ProductTemplate ProductTemplate `json:"product_template"` - LightList []*Light `json:"light_list"` - OptionModelInfo []interface{} `json:"option_model_info"` - Tag int64 `json:"tag"` + ProductModelInfo interface{} `json:"product_model_info"` + ProductTemplate interface{} `json:"product_template"` + LightList []*Light `json:"light_list"` + OptionModelInfo []interface{} `json:"option_model_info"` + Tag int64 `json:"tag"` } type Tag { Id int64 `json:"id"` Title string `json:"title"` } -type TemplateInfo { - Id int64 `json:"id"` - Name string `json:"name"` - Cover string `json:"cover"` - IsPublic bool `json:"isPublic"` - Material string `json:"material"` - MaterialList []*TemplateMateria `json:"materialList"` -} -type ProductTemplate { - CoverImg string `json:"cover_img"` - Id int64 `json:"id"` - IsPublic bool `json:"is_public"` - LogoHeight int64 `json:"logo_height"` - LogoWidth int64 `json:"logo_width"` - MaterialImg string `json:"material_img"` - ModelId int64 `json:"model_id"` - Name string `json:"name"` - ProductId int64 `json:"product_id"` - Sort int64 `json:"sort"` - Tag Tag `json:"tag"` - TemplateInfo *TemplateInfo `json:"template_info"` - Title string `json:"title"` -} -type Light { - Id int64 `json:"id"` - Info LightInfo `json:"info"` -} -type TemplateMateria { - Id string `json:"id"` - Tag string `json:"tag"` - Title string `json:"title"` - Type string `json:"type"` - Text string `json:"text"` - Fill string `json:"fill"` - FontSize int64 `json:"fontSize"` - FontFamily string `json:"fontFamily"` - IfBr bool `json:"ifBr"` - IfShow bool `json:"ifShow"` - IfGroup bool `json:"ifGroup"` - MaxNum int64 `json:"maxNum"` - Rotation int64 `json:"rotation"` - LineHeight int64 `json:"lineHeight"` - Align string `json:"align"` - VerticalAlign string `json:"verticalAlign"` - Material string `json:"material"` - MaterialTime string `json:"materialTime"` - MaterialName string `json:"materialName"` - QRcodeType string `json:"QRcodeType"` - Width int64 `json:"width"` - Height int64 `json:"height"` - Proportion int64 `json:"proportion"` - X int64 `json:"x"` - Y int64 `json:"y"` - Opacity int64 `json:"opacity"` - OptionalColor []*OptionalColor `json:"optionalColor"` - ZIndex int64 `json:"zIndex"` - SvgPath string `json:"svgPath"` - Follow Follow `json:"follow"` - Group []interface{} `json:"group"` - CameraStand CameraStand `json:"cameraStand"` -} -type LightInfo { - Name string `json:"name"` - Hdr Hdr `json:"hdr"` - LightData []LightDataItem `json:"lightData"` -} -type LightDataItem { - Color string `json:"color"` - Id string `json:"id"` - Intensity float64 `json:"intensity"` - Name string `json:"name"` - Type string `json:"type"` - X float64 `json:"x,omitempty"` - Y int64 `json:"y,omitempty"` - Z float64 `json:"z,omitempty"` - ShowHelper bool `json:"showHelper,omitempty"` - Width int64 `json:"width,omitempty"` - Height int64 `json:"height,omitempty"` - Rx int64 `json:"rx,omitempty"` - Ry int64 `json:"ry,omitempty"` - Rz int64 `json:"rz,omitempty"` -} -type Hdr { - IfBg bool `json:"ifBg"` - ToneMappingExposure float64 `json:"toneMappingExposure"` - Url string `json:"url"` -} -type OptionalColor { - Color string `json:"color"` - Name string `json:"name"` - Default bool `json:"default"` -} -type Follow { - Fill string `json:"fill"` - IfShow string `json:"ifShow"` - Content string `json:"content"` -} -type CameraStand { - X int64 `json:"x"` - Y int64 `json:"y"` - Z int64 `json:"z"` +type Light { + Id int64 `json:"id"` + Info interface{} `json:"info"` } \ No newline at end of file