classify_menu_relation.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. package eta
  2. import (
  3. "hongze/hz_crm_eta/global"
  4. "time"
  5. )
  6. type ClassifyMenuRelation struct {
  7. Id int `gorm:"column:id;primary_key;AUTO_INCREMENT;NOT NULL;comment:'主键ID'"`
  8. ClassifyId int `gorm:"column:classify_id;default:0;NOT NULL;comment:'二级分类ID'"`
  9. MenuId int `gorm:"column:menu_id;default:0;NOT NULL;comment:'子目录ID'"`
  10. CreateTime time.Time `gorm:"column:create_time;default:NULL;comment:'创建时间'"`
  11. }
  12. func (c *ClassifyMenuRelation) TableName() string {
  13. return "classify_menu_relation"
  14. }
  15. // GetClassifyMenuRelationList 获取子目录关联列表
  16. func (c *ClassifyMenuRelation) GetClassifyMenuRelationList(condition string, pars []interface{}) (items []*ClassifyMenuRelation, err error) {
  17. err = global.MYSQL["rddp"].Model(c).Where(condition, pars...).Order("create_time ASC").Scan(&items).Error
  18. return
  19. }
  20. // DeleteAndInsertClassifyMenuRelation 新增子目录关联
  21. func DeleteAndInsertClassifyMenuRelation(classifyId, menuId int) (err error) {
  22. tx := global.MYSQL["rddp"].Begin()
  23. defer func() {
  24. if err != nil {
  25. tx.Rollback()
  26. } else {
  27. tx.Commit()
  28. }
  29. }()
  30. // 删除
  31. sql := `DELETE FROM classify_menu_relation WHERE classify_id = ?`
  32. if e := tx.Exec(sql, classifyId).Error; e != nil {
  33. err = e
  34. return
  35. }
  36. // 新增
  37. if menuId > 0 {
  38. relate := &ClassifyMenuRelation{
  39. ClassifyId: classifyId,
  40. MenuId: menuId,
  41. CreateTime: time.Now().Local(),
  42. }
  43. e := tx.Create(relate).Error
  44. if e != nil {
  45. err = e
  46. }
  47. }
  48. return
  49. }