diff --git a/domain/service/headwear_s/headwear.go b/domain/service/headwear_s/headwear.go index 493c7b594a47d8c7da3ff13bd48fba38224a0739..f2126debd0626319e0c11f3fdeee2581c88d83fd 100644 --- a/domain/service/headwear_s/headwear.go +++ b/domain/service/headwear_s/headwear.go @@ -6,18 +6,17 @@ import ( "git.hilo.cn/hilo-common/resource/mysql" "hilo-user/_const/enum/headwear_e" "hilo-user/domain/model/user_m" - "hilo-user/domain/service" "hilo-user/myerr" "hilo-user/myerr/bizerr" "time" ) type HeadwearService struct { - svc *service.Service + svc *domain.Service } func NewHeadwearService(myContext *mycontext.MyContext) *HeadwearService { - svc := service.CreateService(myContext) + svc := domain.CreateService(myContext) return &HeadwearService{svc} } diff --git a/domain/service/noble_s/noble.go b/domain/service/noble_s/noble.go index b20ac64ce30c8603c1f85be3bb5fb455fd2aa0c8..a3ed28664098f2de0b9623fdec8fa73343947377 100644 --- a/domain/service/noble_s/noble.go +++ b/domain/service/noble_s/noble.go @@ -10,7 +10,6 @@ import ( "hilo-user/domain/model/msg_m" "hilo-user/domain/model/noble_m" "hilo-user/domain/model/user_m" - "hilo-user/domain/service" "hilo-user/myerr" "hilo-user/myerr/bizerr" "strconv" @@ -18,11 +17,11 @@ import ( ) type NobleService struct { - svc *service.Service + svc *domain.Service } func NewNobleService(myContext *mycontext.MyContext) *NobleService { - svc := service.CreateService(myContext) + svc := domain.CreateService(myContext) return &NobleService{svc} } diff --git a/domain/service/ride_s/ride.go b/domain/service/ride_s/ride.go index ff1029d6872331ca9feff320118cf25d8aa19fee..32ea9979ac75c32477f484715af3c57280453212 100644 --- a/domain/service/ride_s/ride.go +++ b/domain/service/ride_s/ride.go @@ -6,16 +6,15 @@ import ( "git.hilo.cn/hilo-common/resource/mysql" "hilo-user/_const/enum/property_e" "hilo-user/domain/model/user_m" - "hilo-user/domain/service" "time" ) type RideService struct { - svc *service.Service + svc *domain.Service } func NewRideService(myContext *mycontext.MyContext) *RideService { - svc := service.CreateService(myContext) + svc := domain.CreateService(myContext) return &RideService{svc} } diff --git a/domain/service/service.go b/domain/service/service.go deleted file mode 100755 index cc9bb5794b6a93a71f4f1a2f1096d0e9057d5c70..0000000000000000000000000000000000000000 --- a/domain/service/service.go +++ /dev/null @@ -1,59 +0,0 @@ -package service - -import ( - "git.hilo.cn/hilo-common/domain" - "git.hilo.cn/hilo-common/mycontext" - "git.hilo.cn/hilo-common/resource/mysql" - "git.hilo.cn/hilo-common/resource/redisCli" - "runtime/debug" -) - -type Service struct { - *domain.CtxAndDb -} - -func (service *Service) getMyContext() *mycontext.MyContext { - return service.MyContext -} - -/** - * 创建服务 - * @param - * @return - **/ -func CreateService(myContext *mycontext.MyContext) *Service { - if myContext == nil { - return &Service{CtxAndDb: &domain.CtxAndDb{ - Db: mysql.Db, - MyContext: mycontext.CreateMyContext(nil), - Redis: redisCli.GetRedis(), - }} - } else { - return &Service{CtxAndDb: &domain.CtxAndDb{ - Db: mysql.Db, - MyContext: myContext, - Redis: redisCli.GetRedis(), - }} - } -} - -//事务钩子回调,遇到错误,异常则回调,写service都需要钩子回调 -func (service *Service) Transactional(callback func() error) error { - //异常回调 - defer func() { - if err := recover(); err != nil { - service.Log.Errorf("doTransactional SYSTEM ACTION PANIC: %v, stack: %v", err, string(debug.Stack())) - service.Db.Rollback() - //为了防止给controller层造成数据错误,继续抛恐慌 - panic(err) - } - }() - service.CtxAndDb.Db = mysql.Db.Begin() - err := callback() - if err != nil { - service.Db.Rollback() - return err - } - //提交 - return service.Db.Commit().Error -}