Merge branch 'develop' of https://gitee.com/fusenpack/fusenapi into develop
This commit is contained in:
commit
aef76fb689
|
@ -62,7 +62,7 @@ func (m *FsUserInfoModel) GetProfile(ctx context.Context, pkey string, userId in
|
|||
}
|
||||
|
||||
rawsql := fmt.Sprintf("select JSON_EXTRACT(metadata,'$%s') as query from %s where user_id = ? and module = 'profile' order by ctime DESC limit 1", pkey, tname)
|
||||
err := m.db.Raw(rawsql, userId).Take(&baseinfo).Error
|
||||
err := m.db.WithContext(ctx).Raw(rawsql, userId).Take(&baseinfo).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -87,3 +87,32 @@ func (m *FsUserInfoModel) FindOneByUser(ctx context.Context, userId, guestId int
|
|||
}
|
||||
return resp, err
|
||||
}
|
||||
func (m *FsUserInfoModel) GetProfileByUserIdGuestId(ctx context.Context, pkey string, userId, guestId int64) (map[string]any, error) {
|
||||
|
||||
var baseinfo map[string]any
|
||||
tname := fssql.GetGormTableName(m.db, FsUserInfo{})
|
||||
|
||||
if pkey == "." {
|
||||
pkey = ""
|
||||
} else {
|
||||
pkey = "." + pkey
|
||||
}
|
||||
|
||||
rawsql := fmt.Sprintf("select JSON_EXTRACT(metadata,'$%s') as query from %s where user_id = ? and guest_id = ? and module = 'profile' order by ctime DESC limit 1", pkey, tname)
|
||||
err := m.db.WithContext(ctx).Raw(rawsql, userId, guestId).Take(&baseinfo).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
v, ok := baseinfo["query"].(string)
|
||||
if !ok {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
var info map[string]any
|
||||
err = json.Unmarshal([]byte(v), &info)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return info, nil
|
||||
}
|
||||
|
|
|
@ -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 == "" {
|
||||
|
|
|
@ -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"` //一些返回写死的颜色
|
||||
|
|
|
@ -18,12 +18,6 @@ service collection {
|
|||
//获取收藏列表
|
||||
@handler GetCollectProductListHandler
|
||||
get /api/collection/get_collect_product_list(GetCollectProductListReq) returns (response);
|
||||
//测试算法合图并发
|
||||
@handler TestAiHandler
|
||||
get /api/collection/test_ai(TestAiReq) returns (response);
|
||||
//测试pdf
|
||||
@handler TestPdfHandler
|
||||
post /api/collection/test_pdf(TestPdfReq) returns (response);
|
||||
}
|
||||
|
||||
//收藏产品
|
||||
|
@ -58,13 +52,4 @@ type GetCollectProductListRspItem {
|
|||
MinPrice string `json:"min_price"`
|
||||
IsShelf int64 `json:"is_shelf"`
|
||||
IsDeleted int64 `json:"is_deleted"`
|
||||
}
|
||||
//测试算法
|
||||
type TestAiReq {
|
||||
Num int `form:"num"`
|
||||
}
|
||||
//测试pdf
|
||||
type TestPdfReq {
|
||||
Content string `json:"content"`
|
||||
Type string `json:"type"`
|
||||
}
|
|
@ -77,8 +77,9 @@ type GetTagProductListReq {
|
|||
WithProduct bool `form:"with_product,optional"` //是否携带分类下的产品
|
||||
}
|
||||
type GetTagProductListRsp {
|
||||
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 {
|
||||
TypeName string `json:"type_name"`
|
||||
|
@ -90,7 +91,8 @@ type TagItem {
|
|||
ChildTagList []*TagItem `json:"child_tag_list"`
|
||||
}
|
||||
type TagProduct {
|
||||
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"`
|
||||
|
@ -207,9 +209,10 @@ type GetProductDetailReq {
|
|||
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 {
|
||||
Logo string `json:"logo"` //logo
|
||||
TemplateTagColorInfo TemplateTagColorInfo `json:"template_tag_color_info"` //标签颜色信息
|
||||
ProductInfo ProductInfo `json:"product_info"` //产品基本信息
|
||||
BaseColors interface{} `json:"base_colors"` //一些返回写死的颜色
|
||||
|
|
|
@ -223,7 +223,7 @@ func (l *defaultImageHandle) LogoCombine(ctx context.Context, in *LogoCombineReq
|
|||
moduleDataMap["materialList"] = materialList
|
||||
|
||||
var combineParam map[string]interface{}
|
||||
json.Unmarshal([]byte(*resLogoInfo.Metadata), &combineParam)
|
||||
json.Unmarshal(*resLogoInfo.Metadata, &combineParam)
|
||||
combineParam["resolution"] = in.Resolution
|
||||
combineParam["template_tagid"] = in.TemplateTag
|
||||
combineParam["website"] = in.Website
|
||||
|
|
Loading…
Reference in New Issue
Block a user