package service import ( "errors" "xps/cache" "xps/datamodel" "xps/datasource" "xps/repositories" "xps/viewmodel" ) type BizObjectService interface { GetList(m map[string]interface{}) ([]viewmodel.BizObjectInfo, error) GetPage(m map[string]interface{}) (*viewmodel.PageResult, error) GetById(bizId, objectId int64) (*viewmodel.BizObjectInfo, error) GetListById(bizId int64) ([]viewmodel.BizObjectInfo, error) Create(d *datamodel.BizObject) error Update(d *datamodel.BizObject) error Delete(m map[string]interface{}) error CacheBizObject(bizId, objectId int64) error } type bizObjectService struct { bizObjectRepo *repositories.BizObjectRepo bizObjectAttrRepo *repositories.BizObjectAttrRepo } func NewBizObjectService() BizObjectService { return &bizObjectService{ bizObjectRepo: repositories.NewBizObjectRepo(datasource.InstanceMaster()), bizObjectAttrRepo: repositories.NewBizObjectAttrRepo(datasource.InstanceMaster()), } } func (s *bizObjectService) GetList(m map[string]interface{}) ([]viewmodel.BizObjectInfo, error) { return s.bizObjectRepo.GetList(m) } func (s *bizObjectService) GetListById(bizId int64) ([]viewmodel.BizObjectInfo, error) { return s.bizObjectRepo.GetListById(bizId) } func (s *bizObjectService) GetPage(m map[string]interface{}) (*viewmodel.PageResult, error) { return s.bizObjectRepo.GetPage(m) } func (s *bizObjectService) GetById(bizId, objectId int64) (*viewmodel.BizObjectInfo, error) { return s.bizObjectRepo.GetById(bizId, objectId) } func (s *bizObjectService) Create(o *datamodel.BizObject) error { o.ObjectId = NewID() err := s.bizObjectRepo.Create(o) if err != nil { return err } bizId := o.BizId objectId := o.ObjectId return s.CacheBizObject(bizId, objectId) } func (s *bizObjectService) Update(o *datamodel.BizObject) error { err := s.bizObjectRepo.Update(o) if err != nil { return err } bizId := o.BizId objectId := o.ObjectId return s.CacheBizObject(bizId, objectId) } func (s *bizObjectService) Delete(m map[string]interface{}) error { bizId := m["bizId"].(int64) objectId := m["objectId"].(int64) err := s.bizObjectRepo.Delete(m) if err != nil { return err } return s.bizObjectAttrRepo.DeleteByObjectId(bizId, objectId) } func (s *bizObjectService) CacheBizObject(bizId, objectId int64) error { o, err1 := s.bizObjectRepo.GetById(bizId, objectId) if err1 != nil { return err1 } err3 := cache.SetBizObject(o.ObjectCode, o) if err3 != nil { return errors.New("Redis缓存Biz Object数据失败") } return nil }