Merge branch 'develop' of gitee.com:fusenpack/fusenapi into develop
This commit is contained in:
@@ -27,16 +27,6 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
||||
Path: "/api/collection/get_collect_product_list",
|
||||
Handler: GetCollectProductListHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodGet,
|
||||
Path: "/api/collection/test_ai",
|
||||
Handler: TestAiHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodPost,
|
||||
Path: "/api/collection/test_pdf",
|
||||
Handler: TestPdfHandler(serverCtx),
|
||||
},
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,35 +0,0 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"reflect"
|
||||
|
||||
"fusenapi/utils/basic"
|
||||
|
||||
"fusenapi/server/collection/internal/logic"
|
||||
"fusenapi/server/collection/internal/svc"
|
||||
"fusenapi/server/collection/internal/types"
|
||||
)
|
||||
|
||||
func TestAiHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
var req types.TestAiReq
|
||||
userinfo, err := basic.RequestParse(w, r, svcCtx, &req)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
// 创建一个业务逻辑层实例
|
||||
l := logic.NewTestAiLogic(r.Context(), svcCtx)
|
||||
|
||||
rl := reflect.ValueOf(l)
|
||||
basic.BeforeLogic(w, r, rl)
|
||||
|
||||
resp := l.TestAi(&req, userinfo)
|
||||
|
||||
if !basic.AfterLogic(w, r, rl, resp) {
|
||||
basic.NormalAfterLogic(w, r, resp)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"reflect"
|
||||
|
||||
"fusenapi/utils/basic"
|
||||
|
||||
"fusenapi/server/collection/internal/logic"
|
||||
"fusenapi/server/collection/internal/svc"
|
||||
"fusenapi/server/collection/internal/types"
|
||||
)
|
||||
|
||||
func TestPdfHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
var req types.TestPdfReq
|
||||
userinfo, err := basic.RequestParse(w, r, svcCtx, &req)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
// 创建一个业务逻辑层实例
|
||||
l := logic.NewTestPdfLogic(r.Context(), svcCtx)
|
||||
|
||||
rl := reflect.ValueOf(l)
|
||||
basic.BeforeLogic(w, r, rl)
|
||||
|
||||
resp := l.TestPdf(&req, userinfo)
|
||||
|
||||
if !basic.AfterLogic(w, r, rl, resp) {
|
||||
basic.NormalAfterLogic(w, r, resp)
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because one or more lines are too long
@@ -1,50 +0,0 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fusenapi/server/collection/internal/svc"
|
||||
"fusenapi/server/collection/internal/types"
|
||||
"fusenapi/utils/auth"
|
||||
"fusenapi/utils/basic"
|
||||
"fusenapi/utils/pdf"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type TestPdfLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewTestPdfLogic(ctx context.Context, svcCtx *svc.ServiceContext) *TestPdfLogic {
|
||||
return &TestPdfLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
// 处理进入前逻辑w,r
|
||||
// func (l *TestPdfLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) {
|
||||
// }
|
||||
|
||||
func (l *TestPdfLogic) TestPdf(req *types.TestPdfReq, userinfo *auth.UserInfo) (resp *basic.Response) {
|
||||
return resp.SetStatusWithMessage(basic.CodeOK, "你干嘛,哎哟")
|
||||
switch req.Type {
|
||||
case "url":
|
||||
case "html":
|
||||
default:
|
||||
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "invalid type")
|
||||
}
|
||||
res, err := pdf.HtmlToPdfBase64(req.Content, req.Type)
|
||||
if err != nil {
|
||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, err.Error())
|
||||
}
|
||||
return resp.SetStatus(basic.CodeOK, res)
|
||||
}
|
||||
|
||||
// 处理逻辑后 w,r 如:重定向, resp 必须重新处理
|
||||
// func (l *TestPdfLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) {
|
||||
// // httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
// }
|
||||
@@ -40,15 +40,6 @@ type GetCollectProductListRspItem struct {
|
||||
IsDeleted int64 `json:"is_deleted"`
|
||||
}
|
||||
|
||||
type TestAiReq struct {
|
||||
Num int `form:"num"`
|
||||
}
|
||||
|
||||
type TestPdfReq struct {
|
||||
Content string `json:"content"`
|
||||
Type string `json:"type"`
|
||||
}
|
||||
|
||||
type Request struct {
|
||||
}
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ import (
|
||||
"fusenapi/utils/s3url_to_s3id"
|
||||
"fusenapi/utils/template_switch_info"
|
||||
"gorm.io/gorm"
|
||||
"reflect"
|
||||
"strings"
|
||||
|
||||
"context"
|
||||
@@ -244,6 +245,7 @@ func (l *GetProductDetailLogic) GetProductDetail(req *types.GetProductDetailReq,
|
||||
})
|
||||
}
|
||||
return resp.SetStatusWithMessage(basic.CodeOK, "success", types.GetProductDetailRsp{
|
||||
Logo: req.Logo,
|
||||
TemplateTagColorInfo: templateTagColorInfo,
|
||||
ProductInfo: types.ProductInfo{
|
||||
Id: productInfo.Id,
|
||||
@@ -343,6 +345,24 @@ func (l *GetProductDetailLogic) GetTemplateTagColor(req *types.GetProductDetailR
|
||||
if req.SelectedColorIndex < 0 {
|
||||
return types.TemplateTagColorInfo{}, errors.New("param selected_color_index is invalid")
|
||||
}
|
||||
if req.Logo == "" {
|
||||
//颜色选择置0
|
||||
req.SelectedColorIndex = 0
|
||||
//获取默认profile从中获取logo
|
||||
profile, err := l.svcCtx.AllModels.FsUserInfo.GetProfileByUserIdGuestId(l.ctx, "logo_selected", 0, 0)
|
||||
if err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return types.TemplateTagColorInfo{}, errors.New("the default profile info is not exists")
|
||||
}
|
||||
logx.Error(err)
|
||||
return types.TemplateTagColorInfo{}, errors.New("failed to get default profile info for without logo")
|
||||
}
|
||||
if profile["logo_url"] != nil && reflect.TypeOf(profile["logo_url"]).String() == "string" {
|
||||
req.Logo = profile["logo_url"].(string)
|
||||
} else {
|
||||
return types.TemplateTagColorInfo{}, errors.New("default profile logo url is not set !!")
|
||||
}
|
||||
}
|
||||
//根据logo查询素材资源
|
||||
resourceId := s3url_to_s3id.GetS3ResourceIdFormUrl(req.Logo)
|
||||
if resourceId == "" {
|
||||
|
||||
@@ -3,6 +3,7 @@ package logic
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"fusenapi/constants"
|
||||
"fusenapi/model/gmodel"
|
||||
"fusenapi/utils/auth"
|
||||
@@ -64,6 +65,7 @@ func (l *GetRecommendProductListLogic) GetRecommendProductList(req *types.GetRec
|
||||
recommendProductList = recommendProductList[:req.Num]
|
||||
}
|
||||
}
|
||||
fmt.Println(recommendProductList)
|
||||
//资源id集合
|
||||
resourceIds := make([]string, 0, 50)
|
||||
//需要填充时需要忽略的id
|
||||
|
||||
@@ -129,10 +129,11 @@ func (l *GetTagProductListLogic) GetTagProductList(req *types.GetTagProductListR
|
||||
return resp.SetStatusAddMessage(basic.CodeServiceErr, "failed to deal with tag data")
|
||||
}
|
||||
//组装等级从属关系
|
||||
rspTagList, TotalCategoryProduct := l.organizationLevelRelation(minLevel, mapTagLevel, productList, mapTagProduct)
|
||||
rspTagList, mapTagRsp, TotalCategoryProduct := l.organizationLevelRelation(minLevel, mapTagLevel, productList, mapTagProduct)
|
||||
return resp.SetStatusWithMessage(basic.CodeOK, "success", types.GetTagProductListRsp{
|
||||
TotalCategoryProduct: TotalCategoryProduct,
|
||||
TagList: rspTagList,
|
||||
TagMap: mapTagRsp,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -309,8 +310,8 @@ func (l *GetTagProductListLogic) dealWithTagMenuData(req dealWithTagMenuDataReq)
|
||||
})
|
||||
//tag中产品
|
||||
for _, tmpProduct := range productListRsp {
|
||||
tagTem.TagProductList = append(tagTem.TagProductList, tmpProduct.ProductId)
|
||||
req.MapTagProduct[tmpProduct.ProductId] = tmpProduct
|
||||
tagTem.TagProductList = append(tagTem.TagProductList, tmpProduct.Id)
|
||||
req.MapTagProduct[tmpProduct.Id] = tmpProduct
|
||||
}
|
||||
}
|
||||
//加入分类
|
||||
@@ -320,8 +321,9 @@ func (l *GetTagProductListLogic) dealWithTagMenuData(req dealWithTagMenuDataReq)
|
||||
}
|
||||
|
||||
// 组织等级从属关系
|
||||
func (l *GetTagProductListLogic) organizationLevelRelation(minLevel int, mapTagLevel map[string]*types.TagItem, productList []gmodel.FsProduct, mapTagProduct map[int64]types.TagProduct) (rspTagList []types.TagItem, productCount int) {
|
||||
func (l *GetTagProductListLogic) organizationLevelRelation(minLevel int, mapTagLevel map[string]*types.TagItem, productList []gmodel.FsProduct, mapTagProduct map[int64]types.TagProduct) (rspTagList []types.TagItem, mapTagRsp map[int64]types.TagItem, productCount int) {
|
||||
mapTop := make(map[string]struct{})
|
||||
mapTagRsp = make(map[int64]types.TagItem)
|
||||
//设置归属关系
|
||||
for prefix, tagItem := range mapTagLevel {
|
||||
prefixSlice := strings.Split(prefix, "/")
|
||||
@@ -377,12 +379,13 @@ func (l *GetTagProductListLogic) organizationLevelRelation(minLevel int, mapTagL
|
||||
}
|
||||
productCount += len(mapTagLevel[prefix].TagProductList)
|
||||
rspList = append(rspList, *mapTagLevel[prefix])
|
||||
mapTagRsp[mapTagLevel[prefix].TypeId] = *mapTagLevel[prefix]
|
||||
}
|
||||
//排序
|
||||
sort.SliceStable(rspList, func(i, j int) bool {
|
||||
return rspList[i].Sort < rspList[j].Sort
|
||||
})
|
||||
return rspList, productCount
|
||||
return rspList, mapTagRsp, productCount
|
||||
}
|
||||
|
||||
// 获取某个tag的直属产品
|
||||
@@ -424,6 +427,7 @@ func (l *GetTagProductListLogic) getTagProducts(req getTagProductsReq) (productL
|
||||
haveOptionalFitting = true
|
||||
}
|
||||
item := types.TagProduct{
|
||||
Id: productInfo.Id,
|
||||
ProductId: productInfo.Id,
|
||||
Sn: *productInfo.Sn,
|
||||
Title: *productInfo.Title,
|
||||
|
||||
@@ -35,8 +35,9 @@ type GetTagProductListReq struct {
|
||||
}
|
||||
|
||||
type GetTagProductListRsp struct {
|
||||
TotalCategoryProduct int `json:"total_category_product"`
|
||||
TagList []TagItem `json:"tag_list"`
|
||||
TotalCategoryProduct int `json:"total_category_product"`
|
||||
TagList []TagItem `json:"tag_list"`
|
||||
TagMap interface{} `json:"tag_map"`
|
||||
}
|
||||
|
||||
type TagItem struct {
|
||||
@@ -50,7 +51,8 @@ type TagItem struct {
|
||||
}
|
||||
|
||||
type TagProduct struct {
|
||||
ProductId int64 `json:"product_id"`
|
||||
Id int64 `json:"id"`
|
||||
ProductId int64 `json:"product_id"` //后面删掉这个
|
||||
Sn string `json:"sn"`
|
||||
Title string `json:"title"`
|
||||
Cover string `json:"cover"`
|
||||
@@ -171,10 +173,11 @@ type GetProductDetailReq struct {
|
||||
ProductId int64 `form:"product_id"` //产品id
|
||||
TemplateTag string `form:"template_tag"` //模板标签
|
||||
SelectedColorIndex int `form:"selected_color_index"` //模板标签颜色索引
|
||||
Logo string `form:"logo"` //logo地址
|
||||
Logo string `form:"logo,optional"` //logo地址
|
||||
}
|
||||
|
||||
type GetProductDetailRsp struct {
|
||||
Logo string `json:"logo"` //logo
|
||||
TemplateTagColorInfo TemplateTagColorInfo `json:"template_tag_color_info"` //标签颜色信息
|
||||
ProductInfo ProductInfo `json:"product_info"` //产品基本信息
|
||||
BaseColors interface{} `json:"base_colors"` //一些返回写死的颜色
|
||||
|
||||
Reference in New Issue
Block a user