|
@@ -1,6 +1,8 @@
|
|
|
package service
|
|
package service
|
|
|
|
|
|
|
|
import (
|
|
import (
|
|
|
|
|
+ "errors"
|
|
|
|
|
+ "xps/cache"
|
|
|
"xps/datamodels"
|
|
"xps/datamodels"
|
|
|
"xps/datasource"
|
|
"xps/datasource"
|
|
|
"xps/repositories"
|
|
"xps/repositories"
|
|
@@ -17,37 +19,85 @@ type ApiTransUnitService interface {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
type apiTransUnitService struct {
|
|
type apiTransUnitService struct {
|
|
|
- repo *repositories.ApiTransUnitRepo
|
|
|
|
|
|
|
+ apiRepo *repositories.ApiRepo
|
|
|
|
|
+ transRepo *repositories.ApiTransUnitRepo
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
func NewApiTransUnitService() ApiTransUnitService {
|
|
func NewApiTransUnitService() ApiTransUnitService {
|
|
|
return &apiTransUnitService{
|
|
return &apiTransUnitService{
|
|
|
- repo: repositories.NewApiTransUnitRepo(datasource.InstanceMaster()),
|
|
|
|
|
|
|
+ apiRepo: repositories.NewApiRepo(datasource.InstanceMaster()),
|
|
|
|
|
+ transRepo: repositories.NewApiTransUnitRepo(datasource.InstanceMaster()),
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
func (s *apiTransUnitService) GetList(m map[string]interface{}) ([]viewmodels.ApiTransUnitInfo, error) {
|
|
func (s *apiTransUnitService) GetList(m map[string]interface{}) ([]viewmodels.ApiTransUnitInfo, error) {
|
|
|
- return s.repo.GetList(m)
|
|
|
|
|
|
|
+ return s.transRepo.GetList(m)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
func (s *apiTransUnitService) GetPage(m map[string]interface{}) (*viewmodels.PageResult, error) {
|
|
func (s *apiTransUnitService) GetPage(m map[string]interface{}) (*viewmodels.PageResult, error) {
|
|
|
- return s.repo.GetPage(m)
|
|
|
|
|
|
|
+ return s.transRepo.GetPage(m)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
func (s *apiTransUnitService) GetById(apiId, atuId int64) (*viewmodels.ApiTransUnitInfo, error) {
|
|
func (s *apiTransUnitService) GetById(apiId, atuId int64) (*viewmodels.ApiTransUnitInfo, error) {
|
|
|
- return s.repo.GetById(apiId, atuId)
|
|
|
|
|
|
|
+ return s.transRepo.GetById(apiId, atuId)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
func (s *apiTransUnitService) Create(atu *datamodels.ApiTransUnit) error {
|
|
func (s *apiTransUnitService) Create(atu *datamodels.ApiTransUnit) error {
|
|
|
atu.AtuId = NewID()
|
|
atu.AtuId = NewID()
|
|
|
- return s.repo.Create(atu)
|
|
|
|
|
|
|
+ err := s.transRepo.Create(atu)
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ return err
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ modId := atu.ModelId
|
|
|
|
|
+ apiId := atu.ApiId
|
|
|
|
|
+ return s.CacheApiData(modId, apiId)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
func (s *apiTransUnitService) Update(atu *datamodels.ApiTransUnit) error {
|
|
func (s *apiTransUnitService) Update(atu *datamodels.ApiTransUnit) error {
|
|
|
- return s.repo.Update(atu)
|
|
|
|
|
|
|
+ err := s.transRepo.Update(atu)
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ return err
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ modId := atu.ModelId
|
|
|
|
|
+ apiId := atu.ApiId
|
|
|
|
|
+ return s.CacheApiData(modId, apiId)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
func (s *apiTransUnitService) Delete(m map[string]interface{}) error {
|
|
func (s *apiTransUnitService) Delete(m map[string]interface{}) error {
|
|
|
- return s.repo.Delete(m)
|
|
|
|
|
|
|
+ return s.transRepo.Delete(m)
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+func (s *apiTransUnitService) CacheApiData(modId, apiId int64) error {
|
|
|
|
|
+ api, err := s.apiRepo.GetById(modId, apiId)
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ return nil
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ trans, err := s.transRepo.GetListById(apiId)
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ return nil
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ cacheData := &viewmodels.ApiDataInfo{
|
|
|
|
|
+ ModId: api.ModId,
|
|
|
|
|
+ ModTitle: api.ModTitle,
|
|
|
|
|
+ ApiId: api.ApiId,
|
|
|
|
|
+ ApiCode: api.ApiCode,
|
|
|
|
|
+ ApiTitle: api.ApiTitle,
|
|
|
|
|
+ ApiType: api.ApiType,
|
|
|
|
|
+ ApiParams: api.ApiParams,
|
|
|
|
|
+ ApiDesc: api.ApiDesc,
|
|
|
|
|
+ Status: api.Status,
|
|
|
|
|
+ TransUnits: trans,
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 缓存数据
|
|
|
|
|
+ err = cache.SetApiData(api.ApiCode, cacheData)
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ return errors.New("Redis缓存Api数据失败")
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return nil
|
|
|
}
|
|
}
|