2
This commit is contained in:
69
internal/erpserver/service/v1/system/config.go
Normal file
69
internal/erpserver/service/v1/system/config.go
Normal file
@@ -0,0 +1,69 @@
|
||||
package system
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"time"
|
||||
|
||||
"management/internal/db/model/dto"
|
||||
"management/internal/erpserver/model/system"
|
||||
v1 "management/internal/erpserver/service/v1"
|
||||
"management/internal/pkg/know"
|
||||
"management/internal/pkg/know/pearadmin"
|
||||
"management/internal/pkg/redis"
|
||||
)
|
||||
|
||||
type configService struct {
|
||||
repo system.ConfigRepository
|
||||
redis redis.RedisCache
|
||||
}
|
||||
|
||||
var _ v1.ConfigService = (*configService)(nil)
|
||||
|
||||
func NewConfigService(repo system.ConfigRepository, redis redis.RedisCache) *configService {
|
||||
return &configService{
|
||||
repo: repo,
|
||||
redis: redis,
|
||||
}
|
||||
}
|
||||
|
||||
func (s *configService) Create(ctx context.Context, obj *system.Config) error {
|
||||
return s.repo.Create(ctx, obj)
|
||||
}
|
||||
|
||||
func (s *configService) Update(ctx context.Context, obj *system.Config) error {
|
||||
return s.repo.Update(ctx, obj)
|
||||
}
|
||||
|
||||
func (s *configService) Get(ctx context.Context, id int32) (*system.Config, error) {
|
||||
return s.repo.Get(ctx, id)
|
||||
}
|
||||
|
||||
func (s *configService) List(ctx context.Context, q dto.SearchDto) ([]*system.Config, int64, error) {
|
||||
return s.repo.List(ctx, q)
|
||||
}
|
||||
|
||||
func (s *configService) Pear(ctx context.Context) (*dto.PearConfig, error) {
|
||||
// 判断redis是否存储
|
||||
key := know.GetManageKey(ctx, know.PearAdmin)
|
||||
bs, err := s.redis.GetBytes(ctx, key)
|
||||
if err == nil {
|
||||
var res *dto.PearConfig
|
||||
if err := json.Unmarshal(bs, &res); err == nil {
|
||||
return res, nil
|
||||
}
|
||||
}
|
||||
|
||||
conf, err := s.repo.GetByKey(ctx, pearadmin.PearKey)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var pear dto.PearConfig
|
||||
if err := json.Unmarshal(conf.Value, &pear); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
_ = s.redis.Set(ctx, key, conf.Value, time.Hour*6)
|
||||
return &pear, nil
|
||||
}
|
||||
Reference in New Issue
Block a user