svg.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. package service
  2. import (
  3. "context"
  4. "go-common/app/admin/main/aegis/model/net"
  5. "go-common/app/admin/main/aegis/model/svg"
  6. )
  7. //NetSVG 绘制网的svg图
  8. func (s *Service) NetSVG(c context.Context, netid int64) (nv *svg.NetView, err error) {
  9. flows, err := s.gorm.FlowsByNet(c, []int64{netid})
  10. if err != nil {
  11. return
  12. }
  13. dirs, err := s.gorm.DirectionByNet(c, netid)
  14. if err != nil {
  15. return
  16. }
  17. trans, err := s.gorm.TranByNet(c, netid, true)
  18. if err != nil {
  19. return
  20. }
  21. var binds []*net.TokenBind
  22. for _, flow := range flows {
  23. abs, _, _ := s.fetchOldBindAndLog(c, flow.ID, []int8{1})
  24. for _, bind := range abs {
  25. binds = append(binds, bind)
  26. }
  27. }
  28. for _, tran := range trans {
  29. abs, _, _ := s.fetchOldBindAndLog(c, tran.ID, []int8{2})
  30. for _, bind := range abs {
  31. binds = append(binds, bind)
  32. }
  33. }
  34. tbds, err := s.tokenBindDetail(c, binds)
  35. if err != nil {
  36. return
  37. }
  38. dot := svg.NewDot()
  39. dot.StartDot().AddTokenBinds(tbds...).
  40. AddFlow(flows...).
  41. AddTransitions(trans...).
  42. AddDirections(dirs...).
  43. End()
  44. nv = svg.NewNetView()
  45. nv.SetDot(dot)
  46. return
  47. }