删除产品服务无用的接口

This commit is contained in:
laodaming
2023-10-30 16:50:58 +08:00
parent 0c3e93bba6
commit 55f1be350b
15 changed files with 2 additions and 1074 deletions

View File

@@ -1,121 +0,0 @@
package logic
import (
"encoding/json"
"errors"
"fusenapi/constants"
"fusenapi/model/gmodel"
"fusenapi/utils/auth"
"fusenapi/utils/basic"
"fusenapi/utils/format"
"gorm.io/gorm"
"strings"
"context"
"fusenapi/server/product/internal/svc"
"fusenapi/server/product/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type GetFittingByPidLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewGetFittingByPidLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetFittingByPidLogic {
return &GetFittingByPidLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *GetFittingByPidLogic) GetFittingByPid(req *types.GetFittingByPidReq, userinfo *auth.UserInfo) (resp *basic.Response) {
req.Pid = strings.Trim(req.Pid, " ")
if req.Pid == "" {
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "err param:pid is empty")
}
//获取产品信息(只是获取id)
productInfo, err := l.svcCtx.AllModels.FsProduct.FindOneBySn(l.ctx, req.Pid, "id")
if err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
return resp.SetStatusWithMessage(basic.CodeDbRecordNotFoundErr, "the product is not exists")
}
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get product info")
}
//获取尺寸列表(只获取id)
sizeList, err := l.svcCtx.AllModels.FsProductSize.GetAllByProductIds(l.ctx, []int64{productInfo.Id}, "", "id")
if err != nil {
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get size list")
}
if len(sizeList) == 0 {
return resp.SetStatusAddMessage(basic.CodeOK, "success:size list is empty")
}
sizeIds := make([]int64, 0, len(sizeList))
for _, v := range sizeList {
sizeIds = append(sizeIds, v.Id)
}
//获取配件id
modelList, err := l.svcCtx.AllModels.FsProductModel3d.GetAllBySizeIdsTag(l.ctx, sizeIds, constants.TAG_MODEL, "part_id")
if err != nil {
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get model list")
}
if len(modelList) == 0 {
return resp.SetStatusAddMessage(basic.CodeOK, "success:model list is empty")
}
partIds := make([]int64, 0, len(modelList))
for _, v := range modelList {
if v.PartId == nil {
continue
}
partIds = append(partIds, *v.PartId)
}
//获取配件数据
fittingList, err := l.svcCtx.AllModels.FsProductModel3d.GetAllByIds(l.ctx, partIds, "is_hot DESC,price ASC")
if err != nil {
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get part list")
}
if len(fittingList) == 0 {
return resp.SetStatusAddMessage(basic.CodeOK, "success:fitting list is empty")
}
//处理组装数据返回
listRsp := make([]types.GetFittingByPidRsp, 0, len(fittingList))
for _, fitting := range fittingList {
materialImg := ""
var tInfo *gmodel.FsProductTemplateV2
//贴图,如果绑定了公共模板,则获取公共模板的贴图数据
if *fitting.OptionTemplate > 0 {
tInfo, err = l.svcCtx.AllModels.FsProductTemplateV2.FindOne(l.ctx, *fitting.OptionTemplate)
} else { //否则取该配件下的模板贴图
tInfo, err = l.svcCtx.AllModels.FsProductTemplateV2.FindOneByModelId(l.ctx, fitting.Id)
}
if err == nil {
materialImg = *tInfo.MaterialImg
} else {
logx.Error(err)
}
var modelInfo interface{}
if fitting.ModelInfo != nil && *fitting.ModelInfo != "" {
if err = json.Unmarshal([]byte(*fitting.ModelInfo), &modelInfo); err != nil {
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeJsonErr, "failed to parse model json info")
}
}
listRsp = append(listRsp, types.GetFittingByPidRsp{
Id: fitting.Id,
MaterialImg: materialImg,
Title: *fitting.Title,
Price: format.CentitoDollar(*fitting.Price, 3),
ModelInfo: modelInfo,
IsPopular: *fitting.IsHot > 0,
})
}
return resp.SetStatusWithMessage(basic.CodeOK, "success", listRsp)
}

View File

@@ -1,95 +0,0 @@
package logic
import (
"encoding/json"
"errors"
"fusenapi/constants"
"fusenapi/utils/auth"
"fusenapi/utils/basic"
"gorm.io/gorm"
"strings"
"context"
"fusenapi/server/product/internal/svc"
"fusenapi/server/product/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type GetLightByPidLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewGetLightByPidLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetLightByPidLogic {
return &GetLightByPidLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *GetLightByPidLogic) GetLightByPid(req *types.GetLightByPidReq, userinfo *auth.UserInfo) (resp *basic.Response) {
req.Pid = strings.Trim(req.Pid, " ")
if req.Pid == "" {
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "err param:pid is empty")
}
//获取产品信息(只是获取id)
productInfo, err := l.svcCtx.AllModels.FsProduct.FindOneBySn(l.ctx, req.Pid, "id")
if err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
return resp.SetStatusWithMessage(basic.CodeDbRecordNotFoundErr, "the product is not exists")
}
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get product info")
}
//获取尺寸ids
sizeList, err := l.svcCtx.AllModels.FsProductSize.GetAllByProductIds(l.ctx, []int64{productInfo.Id}, "")
if err != nil {
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get size list")
}
if len(sizeList) == 0 {
return resp.SetStatusWithMessage(basic.CodeOK, "success:size list is empty")
}
sizeIds := make([]int64, 0, len(sizeList))
for _, v := range sizeList {
sizeIds = append(sizeIds, v.Id)
}
//获取模型列表
modelList, err := l.svcCtx.AllModels.FsProductModel3d.GetAllBySizeIdsTag(l.ctx, sizeIds, constants.TAG_MODEL)
if err != nil {
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get model list")
}
if len(modelList) == 0 {
return resp.SetStatusWithMessage(basic.CodeOK, "success:model list is empty")
}
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")
}
//组装数据
listRsp := make([]interface{}, 0, len(lightList))
for _, v := range lightList {
var lightInfo map[string]interface{}
if v.Info == nil || *v.Info == "" {
continue
}
if err = json.Unmarshal([]byte(*v.Info), &lightInfo); err != nil {
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeJsonErr, "failed to parse light info")
}
lightInfo["id"] = v.Id
listRsp = append(listRsp, lightInfo)
}
return resp.SetStatusWithMessage(basic.CodeOK, "success", listRsp)
}

View File

@@ -1,85 +0,0 @@
package logic
import (
"encoding/json"
"errors"
"fusenapi/constants"
"fusenapi/utils/auth"
"fusenapi/utils/basic"
"gorm.io/gorm"
"strings"
"context"
"fusenapi/server/product/internal/svc"
"fusenapi/server/product/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type GetModelByPidLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewGetModelByPidLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetModelByPidLogic {
return &GetModelByPidLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *GetModelByPidLogic) GetModelByPid(req *types.GetModelByPidReq, userinfo *auth.UserInfo) (resp *basic.Response) {
req.Pid = strings.Trim(req.Pid, " ")
if req.Pid == "" {
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "err param:pid is empty")
}
//获取产品信息(只是获取id)
productInfo, err := l.svcCtx.AllModels.FsProduct.FindOneBySn(l.ctx, req.Pid, "id")
if err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
return resp.SetStatusWithMessage(basic.CodeDbRecordNotFoundErr, "the product is not exists")
}
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get product info")
}
//获取产品尺寸列表(只是获取id)
sizeList, err := l.svcCtx.AllModels.FsProductSize.GetAllByProductIds(l.ctx, []int64{productInfo.Id}, "id")
if err != nil {
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get size list")
}
if len(sizeList) == 0 {
return resp.SetStatusWithMessage(basic.CodeOK, "success:size list is empty", []interface{}{})
}
sizeIds := make([]int64, 0, len(sizeList))
for _, v := range sizeList {
sizeIds = append(sizeIds, v.Id)
}
//获取模型数据(只是获取model_info)
model3dList, err := l.svcCtx.AllModels.FsProductModel3d.GetAllBySizeIdsTag(l.ctx, sizeIds, constants.TAG_MODEL, "id,model_info")
if err != nil {
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get model list")
}
if len(model3dList) == 0 {
return resp.SetStatusWithMessage(basic.CodeOK, "success:model list is empty", []interface{}{})
}
//处理数据
mapModel := make(map[int64]interface{})
for _, v := range model3dList {
if v.ModelInfo == nil || *v.ModelInfo == "" {
mapModel[v.Id] = nil
continue
}
var info interface{}
if err = json.Unmarshal([]byte(*v.ModelInfo), &info); err != nil {
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeJsonErr, "failed to parse model info json")
}
mapModel[v.Id] = info
}
return resp.SetStatusWithMessage(basic.CodeOK, "success", mapModel)
}

View File

@@ -1,153 +0,0 @@
package logic
import (
"errors"
"fusenapi/model/gmodel"
"fusenapi/utils/auth"
"fusenapi/utils/basic"
"fusenapi/utils/color_list"
"strings"
"gorm.io/gorm"
"context"
"fusenapi/server/product/internal/svc"
"fusenapi/server/product/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type GetRenderSettingByPidLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewGetRenderSettingByPidLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetRenderSettingByPidLogic {
return &GetRenderSettingByPidLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *GetRenderSettingByPidLogic) GetRenderSettingByPid(req *types.GetRenderSettingByPidReq, userinfo *auth.UserInfo) (resp *basic.Response) {
req.Pid = strings.Trim(req.Pid, " ")
if req.Pid == "" {
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "err param:pid is empty")
}
//获取产品信息
productInfo, err := l.svcCtx.AllModels.FsProduct.FindOneBySn(l.ctx, req.Pid)
if err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
return resp.SetStatusWithMessage(basic.CodeDbRecordNotFoundErr, "the product is not exists")
}
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get product info")
}
//获取产品分类
tagInfo, err := l.svcCtx.AllModels.FsTags.FindOne(l.ctx, *productInfo.Type)
if err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
return resp.SetStatusWithMessage(basic.CodeDbRecordNotFoundErr, "product tag is not exists")
}
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get tag info")
}
//是否低效果渲染
isLowRendering := false
//是否移除背景
isRemoveBg := false
//是否存在最新设计
lastDesign := false
//是否拥有云渲染设计方案
renderDesign := false
renderDesign, err = l.checkRenderDesign(req.ClientNo)
if err != nil {
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to checkRenderDesign")
}
if userinfo.UserId != 0 {
user, err := l.svcCtx.AllModels.FsUser.FindUserById(l.ctx, userinfo.UserId)
if err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
return resp.SetStatusAddMessage(basic.CodeDbRecordNotFoundErr, "user info is not exists")
}
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get user info")
}
isLowRendering = true
isRemoveBg = true
lastDesign, err = l.checkLastDesignExists(user.Id)
if err != nil {
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to check if exists last design ")
}
}
return resp.SetStatusWithMessage(basic.CodeOK, "success", types.GetRenderSettingByPidRsp{
Id: productInfo.Id,
Type: *productInfo.Type,
Title: *productInfo.Title,
IsEnv: *productInfo.IsProtection,
IsMicro: *productInfo.IsMicrowave,
TypeName: *tagInfo.Title,
IsLowRendering: isLowRendering,
IsCustomization: *productInfo.IsCustomization,
IsRemoveBg: isRemoveBg,
RenderDesign: renderDesign,
LastDesign: lastDesign,
Colors: color_list.GetColor(),
})
}
// 查询是否存在渲染设计
func (l *GetRenderSettingByPidLogic) checkRenderDesign(clientNo string) (bool, error) {
if clientNo == "" {
return false, nil
}
renderDesign, err := l.svcCtx.AllModels.FsProductRenderDesign.FindOneRenderDesignByParams(l.ctx, gmodel.FindOneRenderDesignByParamsReq{
ClientNo: &clientNo,
Fields: "id,info,material_id,optional_id,size_id,template_id",
OrderBy: "`id` DESC",
})
if err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
return false, nil
}
return false, err
}
if renderDesign.Info != nil && *renderDesign.Info != "" {
return true, nil
}
return false, nil
}
// 查询是否存在最新设计
func (l *GetRenderSettingByPidLogic) checkLastDesignExists(userId int64) (bool, error) {
//查询用户最近下单成功的数据
// orderInfo, err := l.svcCtx.AllModels.FsOrder.FindLastSuccessOneOrder(l.ctx, userId, int64(constants.STATUS_NEW_NOT_PAY))
// if err != nil {
// if errors.Is(err, gorm.ErrRecordNotFound) {
// return false, nil
// }
// return false, err
// }
//获取该订单相关设计信息
// orderDetail, err := l.svcCtx.AllModels.FsOrderDetail.GetOneOrderDetailByOrderId(l.ctx, orderInfo.Id)
// if err != nil {
// if errors.Is(err, gorm.ErrRecordNotFound) {
// return false, nil
// }
// return false, err
// }
// //获取设计模板详情便于获得design_id
// orderDetailTemplate, err := l.svcCtx.AllModels.FsOrderDetailTemplate.FindOne(l.ctx, *orderDetail.OrderDetailTemplateId)
// if err != nil {
// if errors.Is(err, gorm.ErrRecordNotFound) {
// return false, nil
// }
// return false, err
// }
return false, nil
}

View File

@@ -1,126 +0,0 @@
package logic
import (
"encoding/json"
"errors"
"fusenapi/constants"
"fusenapi/utils/auth"
"fusenapi/utils/basic"
"fusenapi/utils/format"
"gorm.io/gorm"
"strings"
"context"
"fusenapi/server/product/internal/svc"
"fusenapi/server/product/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type GetSizeByPidLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewGetSizeByPidLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetSizeByPidLogic {
return &GetSizeByPidLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *GetSizeByPidLogic) GetSizeByPid(req *types.GetSizeByPidReq, userinfo *auth.UserInfo) (resp *basic.Response) {
req.Pid = strings.Trim(req.Pid, " ")
if req.Pid == "" {
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "err param:pid is empty")
}
if req.TemplateTag == "" {
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "err param:template_tag is empty")
}
//获取产品信息(只是获取id)
productInfo, err := l.svcCtx.AllModels.FsProduct.FindOneBySn(l.ctx, req.Pid, "id")
if err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
return resp.SetStatusWithMessage(basic.CodeDbRecordNotFoundErr, "the product is not exists")
}
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get product info")
}
//获取跟列表页云渲染一样的默认渲染尺寸(模板->尺寸)
defaultSizeId := int64(0)
defaultTemplate, err := l.svcCtx.AllModels.FsProductTemplateV2.FindOneCloudRenderByProductIdTemplateTag(l.ctx, productInfo.Id, req.TemplateTag, "sort ASC", "model_id")
if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get default template ")
} else {
//根据模板找到模型sizeId
defaultModel3d, err := l.svcCtx.AllModels.FsProductModel3d.FindOne(l.ctx, *defaultTemplate.ModelId, "size_id")
if err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "the template`s model is not exists ")
}
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get default model ")
}
defaultSizeId = *defaultModel3d.SizeId
}
//获取产品尺寸列表(需要正序排序)
sizeList, err := l.svcCtx.AllModels.FsProductSize.GetAllByProductIds(l.ctx, []int64{productInfo.Id}, "is_hot DESC,sort ASC")
if err != nil {
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get size list")
}
sizeIds := make([]int64, 0, len(sizeList))
for _, v := range sizeList {
sizeIds = append(sizeIds, v.Id)
}
//获取产品价格列表
mapProductMinPrice := make(map[int64]int64)
//获取产品模型
modelList, err := l.svcCtx.AllModels.FsProductModel3d.GetAllByProductIdsTags(l.ctx, []int64{productInfo.Id}, []int{constants.TAG_MODEL, constants.TAG_PARTS}, "id,size_id,product_id,price,tag,part_id,step_price")
if err != nil {
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get model list")
}
if err = l.svcCtx.AllModels.FsProductModel3d.GetProductMinPrice(modelList, mapProductMinPrice); err != nil {
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get product min price")
}
mapSizeModel := make(map[int64]int) //size id为key
for k, v := range modelList {
if *v.Tag != constants.TAG_MODEL {
continue
}
mapSizeModel[*v.SizeId] = k
}
//处理
listRsp := make([]types.GetSizeByPidRsp, 0, len(sizeList))
for _, sizeInfo := range sizeList {
//没有模型的不能使用
modelIndex, ok := mapSizeModel[sizeInfo.Id]
if !ok {
continue
}
var title interface{}
_ = json.Unmarshal([]byte(*sizeInfo.Title), &title)
minPrice := int64(0)
if price, ok := mapProductMinPrice[*sizeInfo.ProductId]; ok {
minPrice = price
}
listRsp = append(listRsp, types.GetSizeByPidRsp{
Id: sizeInfo.Id,
Title: title,
Capacity: *sizeInfo.Capacity,
Cover: *sizeInfo.Cover,
PartsCanDeleted: *sizeInfo.PartsCanDeleted > 0,
ModelId: modelList[modelIndex].Id,
IsPopular: *sizeInfo.IsHot > 0,
MinPrice: format.CentitoDollar(minPrice, 3),
IsDefault: defaultSizeId == sizeInfo.Id,
})
}
return resp.SetStatusWithMessage(basic.CodeOK, "success", listRsp)
}

View File

@@ -1,110 +0,0 @@
package logic
import (
"encoding/json"
"errors"
"fmt"
"fusenapi/constants"
"fusenapi/utils/auth"
"fusenapi/utils/basic"
"fusenapi/utils/template_switch_info"
"gorm.io/gorm"
"strings"
"context"
"fusenapi/server/product/internal/svc"
"fusenapi/server/product/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type GetTemplateByPidLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewGetTemplateByPidLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetTemplateByPidLogic {
return &GetTemplateByPidLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *GetTemplateByPidLogic) GetTemplateByPid(req *types.GetTemplateByPidReq, userinfo *auth.UserInfo) (resp *basic.Response) {
req.Pid = strings.Trim(req.Pid, " ")
if req.Pid == "" {
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "err param:pid is empty")
}
if req.TemplateTag == "" {
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "err param:template_tag")
}
//获取产品信息(只获取id)
productInfo, err := l.svcCtx.AllModels.FsProduct.FindOneBySn(l.ctx, req.Pid, "id")
if err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
return resp.SetStatusWithMessage(basic.CodeDbRecordNotFoundErr, "the product is not exists")
}
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get product info")
}
//没有指定物料
sizeIds := make([]int64, 0, 10)
if req.ProductSizeId <= 0 {
//获取产品所有物料
sizeList, err := l.svcCtx.AllModels.FsProductSize.GetAllByProductIds(l.ctx, []int64{productInfo.Id}, "id")
if err != nil {
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeDbRecordNotFoundErr, "failed to get product size list")
}
if len(sizeList) == 0 {
return resp.SetStatusWithMessage(basic.CodeDbRecordNotFoundErr, "product size list is empty")
}
for _, v := range sizeList {
sizeIds = append(sizeIds, v.Id)
}
} else { //指定物料
sizeIds = append(sizeIds, req.ProductSizeId)
}
//根据尺寸id获取模型
modelList, err := l.svcCtx.AllModels.FsProductModel3d.GetAllBySizeIdsTag(l.ctx, sizeIds, constants.TAG_MODEL)
if err != nil {
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get model list")
}
if len(modelList) == 0 {
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "model list is empty")
}
modelIds := make([]int64, 0, len(modelList))
mapModel := make(map[int64]int)
for k, v := range modelList {
modelIds = append(modelIds, v.Id)
mapModel[v.Id] = k
}
//查询模型ids下对应tag标签的模板
templateList, err := l.svcCtx.AllModels.FsProductTemplateV2.FindAllByModelIdsTemplateTag(l.ctx, modelIds, req.TemplateTag, "")
if err != nil {
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get template list")
}
rsp := make(map[string]interface{})
for _, templateInfo := range templateList {
//没有设置模板据不要
modelIndex, ok := mapModel[*templateInfo.ModelId]
if !ok {
continue
}
//基础模板信息
var info interface{}
if err = json.Unmarshal([]byte(*templateInfo.TemplateInfo), &info); err != nil {
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeJsonErr, fmt.Sprintf("failed to parse json product template info(may be old data):%d", templateInfo.Id))
}
modelInfo := modelList[modelIndex]
mapKey := fmt.Sprintf("_%d", *modelInfo.SizeId)
rsp[mapKey] = template_switch_info.GetTemplateSwitchInfo(templateInfo.Id, templateInfo.TemplateInfo, *templateInfo.MaterialImg)
}
return resp.SetStatusWithMessage(basic.CodeOK, "success", rsp)
}