app_service.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. package service
  2. import (
  3. "xps/cmd/datasource"
  4. "xps/pkg/app/datamodel"
  5. "xps/pkg/app/repository"
  6. "xps/pkg/app/viewmodel"
  7. "xps/pkg/base"
  8. )
  9. type AppService interface {
  10. GetList(m map[string]interface{}) ([]viewmodel.AppInfo, error)
  11. GetPage(m map[string]interface{}) (*base.PageResult, error)
  12. GetById(appId int64) (*viewmodel.AppInfo, error)
  13. Create(d *datamodel.App) error
  14. Update(d *datamodel.App) error
  15. Delete(m map[string]interface{}) error
  16. GetPermit(roleId int64, appKey string) ([]viewmodel.AppPermitInfo, error)
  17. }
  18. type appService struct {
  19. appRepo *repository.AppRepo
  20. appPermitRepo *repository.AppPermitRepo
  21. }
  22. func NewAppService() AppService {
  23. return &appService{
  24. appRepo: repository.NewAppRepo(datasource.InstanceMaster()),
  25. appPermitRepo: repository.NewAppPermitRepo(datasource.InstanceMaster()),
  26. }
  27. }
  28. func (s *appService) GetList(m map[string]interface{}) ([]viewmodel.AppInfo, error) {
  29. return s.appRepo.GetList(m)
  30. }
  31. func (s *appService) GetPage(m map[string]interface{}) (*base.PageResult, error) {
  32. return s.appRepo.GetPage(m)
  33. }
  34. func (s *appService) GetById(appId int64) (*viewmodel.AppInfo, error) {
  35. return s.appRepo.GetById(appId)
  36. }
  37. func (s *appService) Create(App *datamodel.App) error {
  38. App.AppId = NewID()
  39. return s.appRepo.Create(App)
  40. }
  41. func (s *appService) Update(App *datamodel.App) error {
  42. return s.appRepo.Update(App)
  43. }
  44. func (s *appService) Delete(m map[string]interface{}) error {
  45. return s.appRepo.Delete(m)
  46. }
  47. func (s *appService) GetPermit(roleId int64, appKey string) ([]viewmodel.AppPermitInfo, error) {
  48. m := make(map[string]interface{}, 0)
  49. m["appKey"] = appKey
  50. m["roleId"] = roleId
  51. return s.appPermitRepo.GetList(m)
  52. }