package service import ( "errors" "xps/cache" "xps/datamodel" "xps/datasource" "xps/repositories" "xps/viewmodel" ) type BizObjectMappingService interface { GetList(m map[string]interface{}) ([]viewmodel.BizObjectMappingInfo, error) GetPage(m map[string]interface{}) (*viewmodel.PageResult, error) GetById(bizId, objectId, mappingId int64) (*viewmodel.BizObjectMappingInfo, error) GetListById(bizId, objectId int64) ([]viewmodel.BizObjectMappingInfo, error) Create(d *datamodel.BizObjectMapping) error Update(d *datamodel.BizObjectMapping) error Delete(m map[string]interface{}) error CacheBizObjectMapping(bizId, objectId int64) error } type bizObjectMappingService struct { repo *repositories.BizObjectMappingRepo } func NewBizObjectMappingService() BizObjectMappingService { return &bizObjectMappingService{ repo: repositories.NewBizObjectMappingRepo(datasource.InstanceMaster()), } } func (s *bizObjectMappingService) GetList(m map[string]interface{}) ([]viewmodel.BizObjectMappingInfo, error) { return s.repo.GetList(m) } func (s *bizObjectMappingService) GetListById(bizId, objectId int64) ([]viewmodel.BizObjectMappingInfo, error) { return s.repo.GetListById(bizId, objectId) } func (s *bizObjectMappingService) GetPage(m map[string]interface{}) (*viewmodel.PageResult, error) { return s.repo.GetPage(m) } func (s *bizObjectMappingService) GetById(bizId, objectId, attrId int64) (*viewmodel.BizObjectMappingInfo, error) { return s.repo.GetById(bizId, objectId, attrId) } func (s *bizObjectMappingService) Create(m *datamodel.BizObjectMapping) error { m.MappingId = NewID() err := s.repo.Create(m) if err != nil { return nil } bizId := m.BizId objectId := m.ObjectId return s.CacheBizObjectMapping(bizId, objectId) } func (s *bizObjectMappingService) Update(m *datamodel.BizObjectMapping) error { err := s.repo.Update(m) if err != nil { return nil } bizId := m.BizId objectId := m.ObjectId return s.CacheBizObjectMapping(bizId, objectId) } func (s *bizObjectMappingService) Delete(m map[string]interface{}) error { return s.repo.Delete(m) } func (s *bizObjectMappingService) CacheBizObjectMapping(bizId, objectId int64) error { mappingList, err1 := s.repo.GetListById(bizId, objectId) if err1 != nil { return err1 } if len(mappingList) <= 0 { return errors.New("biz Object Mapping Not Exist") } objectCode := mappingList[0].ObjectCode err2 := cache.SetBizObjectMapping(objectCode, mappingList) if err2 != nil { return errors.New("Redis缓存Model数据失败") } return nil }