Files
assets/service/enum/enum_service.go
qhd 829dc07747 refactor: 重构资产实体和DTO结构类型
将gjson.Json类型替换为具体的结构体和map类型,修正DAO层链式调用,启用SKU元数据校验逻辑
2026-03-22 20:08:32 +08:00

73 lines
2.0 KiB
Go

package service
import (
consts "assets/consts/asset"
"assets/consts/public"
dto "assets/model/dto/enum"
"context"
"gitea.com/red-future/common/beans"
"gitea.com/red-future/common/http"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/util/gconv"
)
type enum struct{}
// Enum 枚举服务
var Enum = new(enum)
// GetAssetType 获取资产类型
func (s *enum) GetAssetType(ctx context.Context, req *dto.GetAssetTypeReq) (res *dto.GetAssetTypeRes, err error) {
_, _ = ctx, req
res = new(dto.GetAssetTypeRes)
err = gconv.Structs(consts.GetAllAssetTypeKeyValue(), &res.Options)
return
}
func (s *enum) GetCategoryAttrType(ctx context.Context, req *dto.GetCategoryAttrTypeReq) (res *dto.GetCategoryAttrTypeRes, err error) {
_, _ = ctx, req
res = new(dto.GetCategoryAttrTypeRes)
err = gconv.Structs(consts.GetAllAttrTypeKeyValue(), &res.Options)
return
}
func (s *enum) GetSpecsUnit(ctx context.Context, req *dto.GetSpecsUnitReq) (res *dto.GetSpecsUnitRes, err error) {
res = new(dto.GetSpecsUnitRes)
if *req.AssetType == consts.AssetTypeVirtual {
keyValue := public.GetAllDurationTypeKeyValue()
err = gconv.Structs(keyValue, &res.Options)
if err != nil {
return
}
} else {
// 获取当前请求的 headers 并传递到下游
headers := make(map[string]string)
if r := g.RequestFromCtx(ctx); r != nil {
for k, v := range r.Request.Header {
if len(v) > 0 {
headers[k] = v[0]
}
}
}
dictData := &dto.GetDictRes{}
if err = http.Get(ctx, "admin-go/api/v1/system/dict/data/getDictData", headers, &dictData, "dictType", gconv.String(req.AssetType)); err != nil {
return
}
for _, v := range dictData.Values {
res.Options = append(res.Options, dto.KeyValue{
Key: v.DictValue,
Value: v.DictLabel,
})
}
}
return
}
func (s *enum) GetTenantModuleType(ctx context.Context, req *dto.GetTenantModuleTypeReq) (res *dto.GetTenantModuleTypeRes, err error) {
_ = ctx
res = new(dto.GetTenantModuleTypeRes)
err = gconv.Structs(beans.GetTenantModuleTypes(req.AssetId), &res.Options)
return
}