This commit is contained in:
laodaming 2023-06-20 19:56:18 +08:00
parent b2062d6448
commit edeb2bb5f1
9 changed files with 160 additions and 231 deletions

View File

@ -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 {

View File

@ -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
}

View File

@ -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
}

View File

@ -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
}

View File

@ -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")

View File

@ -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")

View File

@ -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)
}

View File

@ -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 {

View File

@ -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"`
}