canal.go 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. package dao
  2. import (
  3. cml "go-common/app/admin/main/apm/model/canal"
  4. "go-common/library/ecode"
  5. "go-common/library/log"
  6. )
  7. //SetConfigID set canal_apply table conf_id
  8. func (d *Dao) SetConfigID(id int64, addr string) (err error) {
  9. ups := map[string]interface{}{
  10. "conf_id": id,
  11. }
  12. if err = d.DBCanal.Model(&cml.Apply{}).Where("addr = ?", addr).Updates(ups).Error; err != nil {
  13. log.Error(" SetConfigID error(%v)", err)
  14. err = ecode.SetConfigIDErr
  15. return
  16. }
  17. return
  18. }
  19. //CanalInfoCounts count master_info
  20. func (d *Dao) CanalInfoCounts(v *cml.ConfigReq) (cnt int, err error) {
  21. if err = d.DBCanal.Model(&cml.Canal{}).Where("addr=?", v.Addr).Count(&cnt).Error; err != nil {
  22. log.Error("apmSvc.CanalInfoCounts count error(%v)", err)
  23. err = ecode.RequestErr
  24. return
  25. }
  26. return
  27. }
  28. //CanalInfoEdit update master_info
  29. func (d *Dao) CanalInfoEdit(v *cml.ConfigReq) (err error) {
  30. ups := map[string]interface{}{
  31. "remark": v.Mark,
  32. "cluster": v.Project,
  33. "leader": v.Leader,
  34. }
  35. if err = d.DBCanal.Model(&cml.Canal{}).Where("addr=?", v.Addr).Updates(ups).Error; err != nil {
  36. log.Error(" CanalInfoEdit update error(%v)", err)
  37. err = ecode.CanalApplyUpdateErr
  38. return
  39. }
  40. return
  41. }
  42. //CanalApplyCounts count canal_apply
  43. func (d *Dao) CanalApplyCounts(v *cml.ConfigReq) (cnt int, err error) {
  44. if err = d.DBCanal.Model(&cml.Apply{}).Where("addr=?", v.Addr).Count(&cnt).Error; err != nil {
  45. log.Error("apmSvc.CanalApplyEdit count error(%v)", err)
  46. err = ecode.RequestErr
  47. return
  48. }
  49. return
  50. }
  51. //CanalApplyEdit update canal_apply
  52. func (d *Dao) CanalApplyEdit(v *cml.ConfigReq, username string) (err error) {
  53. ups := map[string]interface{}{
  54. "remark": v.Mark,
  55. "operator": username,
  56. "state": 1,
  57. "cluster": v.Project,
  58. "leader": v.Leader,
  59. }
  60. if err = d.DBCanal.Model(&cml.Apply{}).Where("addr=?", v.Addr).Updates(ups).Error; err != nil {
  61. log.Error(" CanalApplyEdit update error(%v)", err)
  62. err = ecode.CanalApplyUpdateErr
  63. return
  64. }
  65. return
  66. }
  67. //CanalApplyCreate insert into canal_apply
  68. func (d *Dao) CanalApplyCreate(v *cml.ConfigReq, username string) (err error) {
  69. var (
  70. ap = &cml.Apply{
  71. Addr: v.Addr,
  72. Remark: v.Mark,
  73. State: 1,
  74. Operator: username,
  75. Cluster: v.Project,
  76. Leader: v.Leader,
  77. }
  78. )
  79. if err = d.DBCanal.Create(ap).Error; err != nil {
  80. log.Error("apSvc.CanalApplyCreate create error(%v)", err)
  81. err = ecode.CanalApplyErr
  82. return
  83. }
  84. return
  85. }