app_service.go 1.6 KB

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