classify_menu_relation.go 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. package models
  2. import (
  3. "eta/eta_api/global"
  4. "eta/eta_api/utils"
  5. "time"
  6. )
  7. // ClassifyMenuRelation 报告分类-子目录关联表
  8. //type ClassifyMenuRelation struct {
  9. // Id int `orm:"column(id);pk"`
  10. // MenuId int `description:"子目录ID"`
  11. // ClassifyId int `description:"二级分类ID"`
  12. // CreateTime time.Time `description:"创建时间"`
  13. //}
  14. type ClassifyMenuRelation struct {
  15. Id int `gorm:"column:id;primaryKey;autoIncrement"` //`orm:"column(id);pk" gorm:"primaryKey" `
  16. MenuId int `gorm:"column:menu_id"` //`description:"子目录ID"`
  17. ClassifyId int `gorm:"column:classify_id"` //`description:"二级分类ID"`
  18. CreateTime time.Time `gorm:"column:create_time"` //`description:"创建时间"`
  19. }
  20. func (item *ClassifyMenuRelation) TableName() string {
  21. return "classify_menu_relation"
  22. }
  23. func (item *ClassifyMenuRelation) Create() (err error) {
  24. err = global.DbMap[utils.DbNameReport].Create(item).Error
  25. return
  26. }
  27. func (item *ClassifyMenuRelation) Update(cols []string) (err error) {
  28. err = global.DbMap[utils.DbNameReport].Select(cols).Updates(item).Error
  29. return
  30. }
  31. func (item *ClassifyMenuRelation) InsertMulti(items []*ClassifyMenuRelation) (err error) {
  32. err = global.DbMap[utils.DbNameReport].CreateInBatches(items, utils.MultiAddNum).Error
  33. return
  34. }
  35. // GetClassifyMenuRelationList 获取子目录关联列表
  36. func GetClassifyMenuRelationList(condition string, pars []interface{}) (list []*ClassifyMenuRelation, err error) {
  37. sql := `SELECT * FROM classify_menu_relation WHERE 1 = 1 `
  38. sql += condition
  39. sql += ` ORDER BY create_time DESC`
  40. err = global.DbMap[utils.DbNameReport].Raw(sql, pars...).Find(&list).Error
  41. return
  42. }
  43. // DeleteAndInsertClassifyMenuRelation 新增子目录关联
  44. //func DeleteAndInsertClassifyMenuRelation(classifyId, menuId int) (err error) {
  45. // o := orm.NewOrmUsingDB("rddp")
  46. // tx, err := o.Begin()
  47. // if err != nil {
  48. // return
  49. // }
  50. // defer func() {
  51. // if err != nil {
  52. // _ = tx.Rollback()
  53. // } else {
  54. // _ = tx.Commit()
  55. // }
  56. // }()
  57. //
  58. // // 删除
  59. // sql := `DELETE FROM classify_menu_relation WHERE classify_id = ?`
  60. // if _, e := tx.Raw(sql, classifyId).Exec(); e != nil {
  61. // err = e
  62. // return
  63. // }
  64. //
  65. // // 新增
  66. // if menuId > 0 {
  67. // relate := &ClassifyMenuRelation{
  68. // ClassifyId: classifyId,
  69. // MenuId: menuId,
  70. // CreateTime: time.Now().Local(),
  71. // }
  72. // _, e := tx.Insert(relate)
  73. // if e != nil {
  74. // err = e
  75. // }
  76. // }
  77. // return
  78. //}