74 lines
		
	
	
		
			2.2 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			74 lines
		
	
	
		
			2.2 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
| package logic
 | |
| 
 | |
| import (
 | |
| 	"encoding/json"
 | |
| 	"errors"
 | |
| 	"fusenapi/model/gmodel"
 | |
| 	"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 GetRenderDesignLogic struct {
 | |
| 	logx.Logger
 | |
| 	ctx    context.Context
 | |
| 	svcCtx *svc.ServiceContext
 | |
| }
 | |
| 
 | |
| func NewGetRenderDesignLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetRenderDesignLogic {
 | |
| 	return &GetRenderDesignLogic{
 | |
| 		Logger: logx.WithContext(ctx),
 | |
| 		ctx:    ctx,
 | |
| 		svcCtx: svcCtx,
 | |
| 	}
 | |
| }
 | |
| 
 | |
| func (l *GetRenderDesignLogic) GetRenderDesign(req *types.GetRenderDesignReq, userinfo *auth.UserInfo) (resp *basic.Response) {
 | |
| 	req.Sn = strings.Trim(req.Sn, " ")
 | |
| 	if req.Sn == "" {
 | |
| 		return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "err param:sn is empty")
 | |
| 	}
 | |
| 	renderDesign, err := l.svcCtx.AllModels.FsProductRenderDesign.FindOneRenderDesignByParams(l.ctx, gmodel.FindOneRenderDesignByParamsReq{
 | |
| 		Sn:      &req.Sn,
 | |
| 		Fields:  "id,info,material_id,optional_id,size_id,template_id",
 | |
| 		OrderBy: "`id` DESC",
 | |
| 	})
 | |
| 	if err != nil {
 | |
| 		if errors.Is(err, gorm.ErrRecordNotFound) {
 | |
| 			return resp.SetStatusWithMessage(basic.CodeDbRecordNotFoundErr, "render design is not exists")
 | |
| 		}
 | |
| 		logx.Error(err)
 | |
| 		return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get render design info")
 | |
| 	}
 | |
| 	var color []string
 | |
| 	if renderDesign.LogoColor != nil && *renderDesign.LogoColor != "" {
 | |
| 		if err = json.Unmarshal([]byte(*renderDesign.LogoColor), &color); err != nil {
 | |
| 			logx.Error(err)
 | |
| 			return resp.SetStatusWithMessage(basic.CodeJsonErr, "failed to parse render logo color")
 | |
| 		}
 | |
| 	}
 | |
| 	var info interface{}
 | |
| 	if renderDesign.Info != nil && *renderDesign.Info != "" {
 | |
| 		if err = json.Unmarshal([]byte(*renderDesign.Info), &info); err != nil {
 | |
| 			logx.Error(err)
 | |
| 			return resp.SetStatusWithMessage(basic.CodeJsonErr, "failed to parse render design info")
 | |
| 		}
 | |
| 	}
 | |
| 	return resp.SetStatusWithMessage(basic.CodeOK, "success", types.GetRenderDesignRsp{
 | |
| 		Id:         renderDesign.Id,
 | |
| 		Info:       info,
 | |
| 		OptionalId: *renderDesign.OptionalId,
 | |
| 		SizeId:     *renderDesign.SizeId,
 | |
| 		TemplateId: *renderDesign.TemplateId,
 | |
| 		LogoColor:  color,
 | |
| 	})
 | |
| }
 |