package db import ( "applet/app/db/model" "applet/app/utils/logx" "reflect" "xorm.io/xorm" ) type SuggestedFeedbackDb struct { Db *xorm.Engine `json:"db"` } func (suggestedFeedbackDb *SuggestedFeedbackDb) Set() { // set方法 suggestedFeedbackDb.Db = Db } func (suggestedFeedbackDb *SuggestedFeedbackDb) GetSuggestedFeedback(id int) (m *model.SuggestedFeedback, err error) { m = new(model.SuggestedFeedback) has, err := suggestedFeedbackDb.Db.Where("id =?", id).Get(m) if err != nil { return nil, logx.Error(err) } if has == false { return nil, nil } return m, nil } func (suggestedFeedbackDb *SuggestedFeedbackDb) FindSuggestedFeedbackById(ids interface{}) (*[]model.SuggestedFeedback, error) { var m []model.SuggestedFeedback if err := suggestedFeedbackDb.Db.In("id", ids).Desc("sort").Find(&m); err != nil { return nil, logx.Error(err) } return &m, nil } func (suggestedFeedbackDb *SuggestedFeedbackDb) FindSuggestedFeedback(limit, start int) (*[]model.SuggestedFeedback, error) { var m []model.SuggestedFeedback if limit == 0 || start == 0 { if err := suggestedFeedbackDb.Db.Asc("sort").Find(&m); err != nil { return nil, logx.Error(err) } } else { if err := suggestedFeedbackDb.Db.Asc("sort").Limit(limit, start).Find(m); err != nil { return nil, logx.Error(err) } } return &m, nil } func (suggestedFeedbackDb *SuggestedFeedbackDb) GetSuggestedFeedbackByName(name string) (m *model.SuggestedFeedback, err error) { m = new(model.SuggestedFeedback) has, err := suggestedFeedbackDb.Db.Where("name =?", name).Get(m) if err != nil { return nil, logx.Error(err) } if has == false { return nil, nil } return m, nil } func (suggestedFeedbackDb *SuggestedFeedbackDb) SuggestedFeedbackInsert(m *model.SuggestedFeedback) (int, error) { _, err := suggestedFeedbackDb.Db.InsertOne(m) if err != nil { return 0, err } return m.Id, nil } func (suggestedFeedbackDb *SuggestedFeedbackDb) SuggestedFeedbackUpdate(m *model.SuggestedFeedback, columns ...string) (int64, error) { affected, err := suggestedFeedbackDb.Db.Where("id =?", m.Id).Cols(columns...).Update(m) if err != nil { return 0, err } return affected, nil } func (suggestedFeedbackDb *SuggestedFeedbackDb) SuggestedFeedbackDelete(id interface{}) (int64, error) { if reflect.TypeOf(id).Kind() == reflect.Slice { return Db.In("id", id).Delete(model.SuggestedFeedback{}) } else { return Db.Where("id = ?", id).Delete(model.SuggestedFeedback{}) } } type SuggestedFeedbackWithUserIdentity struct { model.SuggestedFeedback `xorm:"extends"` model.UserIdentity `xorm:"extends"` model.Enterprise `xorm:"extends"` model.User `xorm:"extends"` } func (SuggestedFeedbackWithUserIdentity) TableName() string { return "suggested_feedback" }