factor.go 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. package service
  2. import (
  3. "context"
  4. "go-common/library/log"
  5. "go-common/app/admin/main/spy/model"
  6. )
  7. // Factors get all factor.
  8. func (s *Service) Factors(c context.Context) (fs []*model.Factors, err error) {
  9. var (
  10. fds []*model.Factor
  11. )
  12. gs, err := s.spyDao.Groups(c)
  13. if err != nil {
  14. log.Error("spyDao.Groups error(%v)", err)
  15. return
  16. }
  17. if len(gs) == 0 {
  18. return
  19. }
  20. for _, v := range gs {
  21. fds, err = s.spyDao.Factors(c, v.ID)
  22. if err != nil {
  23. log.Error("spyDao.Groups error(%v)", err)
  24. return
  25. }
  26. if len(fds) == 0 {
  27. continue
  28. }
  29. for _, f := range fds {
  30. f := &model.Factors{
  31. GroupID: v.ID,
  32. GroupName: v.Name,
  33. NickName: f.NickName,
  34. FactorVal: f.FactorVal,
  35. ID: f.ID,
  36. }
  37. fs = append(fs, f)
  38. }
  39. }
  40. return
  41. }
  42. // UpdateFactor update factor.
  43. func (s *Service) UpdateFactor(c context.Context, fs []*model.Factor, name string) (err error) {
  44. for _, f := range fs {
  45. _, err = s.spyDao.UpdateFactor(c, f.FactorVal, f.ID)
  46. if err != nil {
  47. log.Error("spyDao.UpdateFactor(%v,%d) error(%v)", f.FactorVal, f.ID, err)
  48. return
  49. }
  50. s.AddLog(c, name, model.UpdateFactor, f)
  51. }
  52. return
  53. }
  54. // AddFactor add factor
  55. func (s *Service) AddFactor(c context.Context, f *model.Factor) (err error) {
  56. ret, err := s.spyDao.AddFactor(c, f)
  57. if err != nil || ret != 1 {
  58. log.Error("s.spyDao.AddFactor(%v) error(%v,%d)", f, err, ret)
  59. }
  60. return
  61. }
  62. // AddEvent add event
  63. func (s *Service) AddEvent(c context.Context, f *model.Event) (err error) {
  64. ret, err := s.spyDao.AddEvent(c, f)
  65. if err != nil || ret != 1 {
  66. log.Error("s.spyDao.AddEvent(%v) error(%v,%d)", f, err, ret)
  67. }
  68. return
  69. }
  70. // AddService add service
  71. func (s *Service) AddService(c context.Context, f *model.Service) (err error) {
  72. ret, err := s.spyDao.AddService(c, f)
  73. if err != nil || ret != 1 {
  74. log.Error("s.spyDao.AddService(%v) error(%v,%d)", f, err, ret)
  75. }
  76. return
  77. }
  78. // AddGroup add group
  79. func (s *Service) AddGroup(c context.Context, f *model.FactorGroup) (err error) {
  80. ret, err := s.spyDao.AddGroup(c, f)
  81. if err != nil || ret != 1 {
  82. log.Error("s.spyDao.AddGroup(%v) error(%v,%d)", f, err, ret)
  83. }
  84. return
  85. }
  86. // UpdateEventName update event name.
  87. func (s *Service) UpdateEventName(c context.Context, event *model.Event) (err error) {
  88. ret, err := s.spyDao.UpdateEventName(c, event)
  89. if err != nil || ret != 1 {
  90. log.Error("s.spyDao.UpdateEventName(%v) error(%v,%d)", event, err, ret)
  91. }
  92. return
  93. }