refactor: 重构资产实体和DTO结构类型
将gjson.Json类型替换为具体的结构体和map类型,修正DAO层链式调用,启用SKU元数据校验逻辑
This commit is contained in:
@@ -82,8 +82,8 @@ func (s *asset) GetOne(ctx context.Context, req *dto.GetAssetReq) (res *dto.GetA
|
||||
if assetOne, err = dao.Asset.GetOne(ctx, req); err != nil {
|
||||
return
|
||||
}
|
||||
var assetListItem *dto.AssetItem
|
||||
if err = gconv.Struct(assetOne, assetListItem); err != nil {
|
||||
var assetListItem *entity.Asset
|
||||
if err = gconv.Struct(assetOne, &assetListItem); err != nil {
|
||||
return
|
||||
}
|
||||
getCategoryRes, err := dao.Category.GetOne(ctx, &dto.GetCategoryReq{
|
||||
@@ -93,7 +93,7 @@ func (s *asset) GetOne(ctx context.Context, req *dto.GetAssetReq) (res *dto.GetA
|
||||
return
|
||||
}
|
||||
return &dto.GetAssetRes{
|
||||
AssetItem: assetListItem,
|
||||
Asset: assetListItem,
|
||||
CategoryName: getCategoryRes.Name,
|
||||
ImgAddressPrefix: minio.GetFileAddressPrefix(ctx),
|
||||
}, nil
|
||||
@@ -109,7 +109,7 @@ func (s *asset) GetAssetAndSku(ctx context.Context, req *dto.GetAssetAndSkuReq)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
var assetListItem *dto.AssetItem
|
||||
var assetListItem *entity.Asset
|
||||
if err = gconv.Struct(assetOne, assetListItem); err != nil {
|
||||
return
|
||||
}
|
||||
@@ -126,7 +126,7 @@ func (s *asset) GetAssetAndSku(ctx context.Context, req *dto.GetAssetAndSkuReq)
|
||||
return
|
||||
}
|
||||
return &dto.GetAssetAndSkuRes{
|
||||
AssetItem: assetListItem,
|
||||
Asset: assetListItem,
|
||||
Skus: assetSkuListResItem,
|
||||
TenantModuleType: moduleType.Options,
|
||||
ImgAddressPrefix: minio.GetFileAddressPrefix(ctx),
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
consts "assets/consts/asset"
|
||||
"assets/consts/public"
|
||||
dao "assets/dao/asset"
|
||||
dto "assets/model/dto/asset"
|
||||
@@ -10,7 +11,6 @@ import (
|
||||
"reflect"
|
||||
|
||||
"gitea.com/red-future/common/beans"
|
||||
"gitea.com/red-future/common/utils"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
)
|
||||
@@ -84,19 +84,18 @@ func (s *assetSku) parameterValidation(ctx context.Context, assetEntity *entity.
|
||||
specNoExist := true
|
||||
metadataList := make([]string, 0)
|
||||
// 验证,自定义属性传过来的全不全
|
||||
// TODO: Metadata类型从[]map[string]interface{}变为*gjson.Json,需要适配
|
||||
// if assetEntity.Metadata != nil {
|
||||
// for _, metadata := range assetEntity.Metadata {
|
||||
// attributeType := gconv.String(gconv.Map(metadata)["type"])
|
||||
// if attributeType == string(consts.AttributeTypeMultiSelect) {
|
||||
// metadataList = append(metadataList, attributeType)
|
||||
// }
|
||||
// }
|
||||
// if len(metadataList) != len(specValues) {
|
||||
// // 如果请求参数中不存在该键,则跳过
|
||||
// return errors.New("规格参数填写不完整")
|
||||
// }
|
||||
// }
|
||||
if assetEntity.Metadata != nil {
|
||||
for _, metadata := range assetEntity.Metadata {
|
||||
attributeType := gconv.String(gconv.Map(metadata)["type"])
|
||||
if attributeType == string(consts.AttributeTypeMultiSelect) {
|
||||
metadataList = append(metadataList, attributeType)
|
||||
}
|
||||
}
|
||||
if len(metadataList) != len(specValues) {
|
||||
// 如果请求参数中不存在该键,则跳过
|
||||
return errors.New("规格参数填写不完整")
|
||||
}
|
||||
}
|
||||
// 验证,自定义属性和sku名称重不重复
|
||||
for _, list := range list {
|
||||
if list.SkuName == skuName {
|
||||
@@ -155,7 +154,7 @@ func (s *assetSku) GetAssetSku(ctx context.Context, req *dto.GetAssetSkuReq) (re
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
err = utils.Struct(one, &res)
|
||||
err = gconv.Struct(one, &res)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -169,7 +168,7 @@ func (s *assetSku) ListAssetSkus(ctx context.Context, req *dto.ListAssetSkuReq)
|
||||
res = &dto.ListAssetSkuRes{
|
||||
Total: total,
|
||||
}
|
||||
err = utils.Struct(list, &res.List)
|
||||
err = gconv.Struct(list, &res.List)
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -77,7 +77,7 @@ func (s *CategoryService) GetOne(ctx context.Context, req *dto.GetCategoryReq) (
|
||||
}
|
||||
res := new(dto.GetCategoryRes)
|
||||
|
||||
if err = gconv.Scan(one, &res); err != nil {
|
||||
if err = gconv.Struct(one, &res); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user