refactor: 重构资产实体和DTO结构类型
将gjson.Json类型替换为具体的结构体和map类型,修正DAO层链式调用,启用SKU元数据校验逻辑
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user