123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- package models
- import (
- "eta/eta_api/global"
- "eta/eta_api/utils"
- "time"
- )
- // ClassifyMenuRelation 报告分类-子目录关联表
- //type ClassifyMenuRelation struct {
- // Id int `orm:"column(id);pk"`
- // MenuId int `description:"子目录ID"`
- // ClassifyId int `description:"二级分类ID"`
- // CreateTime time.Time `description:"创建时间"`
- //}
- type ClassifyMenuRelation struct {
- Id int `gorm:"column:id;primaryKey;autoIncrement"` //`orm:"column(id);pk" gorm:"primaryKey" `
- MenuId int `gorm:"column:menu_id"` //`description:"子目录ID"`
- ClassifyId int `gorm:"column:classify_id"` //`description:"二级分类ID"`
- CreateTime time.Time `gorm:"column:create_time"` //`description:"创建时间"`
- }
- func (item *ClassifyMenuRelation) TableName() string {
- return "classify_menu_relation"
- }
- func (item *ClassifyMenuRelation) Create() (err error) {
- err = global.DbMap[utils.DbNameReport].Create(item).Error
- return
- }
- func (item *ClassifyMenuRelation) Update(cols []string) (err error) {
- err = global.DbMap[utils.DbNameReport].Select(cols).Updates(item).Error
- return
- }
- func (item *ClassifyMenuRelation) InsertMulti(items []*ClassifyMenuRelation) (err error) {
- err = global.DbMap[utils.DbNameReport].CreateInBatches(items, utils.MultiAddNum).Error
- return
- }
- // GetClassifyMenuRelationList 获取子目录关联列表
- func GetClassifyMenuRelationList(condition string, pars []interface{}) (list []*ClassifyMenuRelation, err error) {
- sql := `SELECT * FROM classify_menu_relation WHERE 1 = 1 `
- sql += condition
- sql += ` ORDER BY create_time DESC`
- err = global.DbMap[utils.DbNameReport].Raw(sql, pars...).Find(&list).Error
- return
- }
- // DeleteAndInsertClassifyMenuRelation 新增子目录关联
- //func DeleteAndInsertClassifyMenuRelation(classifyId, menuId int) (err error) {
- // o := orm.NewOrmUsingDB("rddp")
- // tx, err := o.Begin()
- // if err != nil {
- // return
- // }
- // defer func() {
- // if err != nil {
- // _ = tx.Rollback()
- // } else {
- // _ = tx.Commit()
- // }
- // }()
- //
- // // 删除
- // sql := `DELETE FROM classify_menu_relation WHERE classify_id = ?`
- // if _, e := tx.Raw(sql, classifyId).Exec(); e != nil {
- // err = e
- // return
- // }
- //
- // // 新增
- // if menuId > 0 {
- // relate := &ClassifyMenuRelation{
- // ClassifyId: classifyId,
- // MenuId: menuId,
- // CreateTime: time.Now().Local(),
- // }
- // _, e := tx.Insert(relate)
- // if e != nil {
- // err = e
- // }
- // }
- // return
- //}
|