|
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- package db
-
- import (
- "applet/app/db/model"
- "applet/app/utils/logx"
- "reflect"
- "xorm.io/xorm"
- )
-
- type MealLabelDb struct {
- Db *xorm.Engine `json:"db"`
- EnterpriseId int `json:"enterprise_id"`
- }
-
- func (MealLabelDb *MealLabelDb) Set(enterpriseId int) { // set方法
- MealLabelDb.Db = Db
- MealLabelDb.EnterpriseId = enterpriseId
- }
-
- func (MealLabelDb *MealLabelDb) FindMealLabel(gradeId int, kind int32) (*[]model.MealLabel, error) {
- var m []model.MealLabel
- if err := MealLabelDb.Db.Asc("id").Where("enterprise_id =?", MealLabelDb.EnterpriseId).And("grade_id =?", gradeId).
- And("kind =?", kind).Find(&m); err != nil {
- return nil, logx.Error(err)
- }
- return &m, nil
- }
-
- func (MealLabelDb *MealLabelDb) MealLabelDelete(id interface{}) (int64, error) {
- if reflect.TypeOf(id).Kind() == reflect.Slice {
- return MealLabelDb.Db.In("id", id).Delete(model.MealLabel{})
- } else {
- return MealLabelDb.Db.Where("id = ?", id).Delete(model.MealLabel{})
- }
- }
-
- func (MealLabelDb *MealLabelDb) ClassDeleteBySessionForEnterprise(session *xorm.Session, enterpriseId interface{}) (int64, error) {
- if reflect.TypeOf(enterpriseId).Kind() == reflect.Slice {
- return session.In("enterprise_id", enterpriseId).Delete(model.MealLabel{})
- } else {
- return session.Where("enterprise_id = ?", enterpriseId).Delete(model.MealLabel{})
- }
- }
-
- func (MealLabelDb *MealLabelDb) MealLabelInsert(m *model.MealLabel) (int, error) {
- _, err := MealLabelDb.Db.InsertOne(m)
- if err != nil {
- return 0, err
- }
- return m.Id, nil
- }
-
- func (MealLabelDb *MealLabelDb) MealLabelUpdate(m *model.MealLabel, columns ...string) (int64, error) {
- affected, err := MealLabelDb.Db.Where("id =?", m.Id).Cols(columns...).Update(m)
- if err != nil {
- return 0, err
- }
- return affected, nil
- }
-
- func (MealLabelDb *MealLabelDb) GetMealLabel(id int) (m *model.MealLabel, err error) {
- m = new(model.MealLabel)
- has, err := MealLabelDb.Db.Where("id =?", id).Get(m)
- if err != nil {
- return nil, logx.Error(err)
- }
- if has == false {
- return nil, nil
- }
- return m, nil
- }
|