config.go 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. package business
  2. import (
  3. "encoding/json"
  4. "go-common/app/admin/main/aegis/model/middleware"
  5. "go-common/library/log"
  6. xtime "go-common/library/time"
  7. )
  8. // BizCFG .
  9. type BizCFG struct {
  10. ID int64 `json:"id" gorm:"primary_key" form:"id"`
  11. BusinessID int64 `json:"business_id" gorm:"column:business_id" form:"business_id"`
  12. TP int8 `json:"type" gorm:"column:type" form:"type"`
  13. Config string `json:"config" gorm:"column:config" form:"config"`
  14. State int64 `json:"state" gorm:"column:state" form:"state"`
  15. Ctime xtime.Time `json:"ctime" gorm:"column:ctime"`
  16. Mtime xtime.Time `json:"mtime" gorm:"column:mtime"`
  17. }
  18. // TableName .
  19. func (t *BizCFG) TableName() string {
  20. return "business_config"
  21. }
  22. // FormatMngBID .
  23. func (t *BizCFG) FormatMngBID() (biz int64, roles map[int64][]int64, err error) {
  24. var (
  25. cfgs []map[string]int64
  26. )
  27. if t.TP != TypeManagerBID || t.Config == "" {
  28. return
  29. }
  30. biz = t.BusinessID
  31. roles = map[int64][]int64{}
  32. if err = json.Unmarshal([]byte(t.Config), &cfgs); err != nil {
  33. log.Error("FormatMngBID json.Unmarshal(%+v) error(%v)", t, err)
  34. return
  35. }
  36. for _, item := range cfgs {
  37. if item[MngBIDMID] <= 0 || item[MngBIDFlow] <= 0 {
  38. continue
  39. }
  40. if _, exist := roles[item[MngBIDMID]]; !exist {
  41. roles[item[MngBIDMID]] = []int64{}
  42. }
  43. roles[item[MngBIDMID]] = append(roles[item[MngBIDMID]], item[MngBIDFlow])
  44. }
  45. return
  46. }
  47. // FormatBizBID .
  48. func (t *BizCFG) FormatBizBID() (biz int64, roles map[string]int64, err error) {
  49. if t.TP != TypeBizBID || t.Config == "" {
  50. return
  51. }
  52. biz = t.BusinessID
  53. if err = json.Unmarshal([]byte(t.Config), &roles); err != nil {
  54. log.Error("FormatBizBID json.Unmarshal(%+v) error(%v)", t, err)
  55. }
  56. return
  57. }
  58. //FormatAggregate 聚合配置
  59. func (t *BizCFG) FormatAggregate() (cfgs []*middleware.Aggregate, err error) {
  60. if t.TP != TypeMiddleware || t.Config == "" {
  61. return
  62. }
  63. cfgs = []*middleware.Aggregate{}
  64. if err = json.Unmarshal([]byte(t.Config), &cfgs); err != nil {
  65. log.Error("FormatAggregate json.Unmarshal error(%+v)", err)
  66. }
  67. return
  68. }
  69. // ManagerRole .
  70. type ManagerRole struct {
  71. FlowID int64 `json:"flow_id"`
  72. MngBid int64 `json:"manager_bid"`
  73. }