package service import ( consts "assets/consts/asset" "assets/consts/public" dto "assets/model/dto/enum" "context" "gitea.redpowerfuture.com/red-future/common/beans" "gitea.redpowerfuture.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 }