|
- package db
-
- import (
- "applet/app/db/model"
- "applet/app/utils/logx"
- "reflect"
- "xorm.io/xorm"
- )
-
- type NursingHomeSetDb struct {
- Db *xorm.Engine `json:"db"`
- EnterpriseId int `json:"enterprise_id"`
- }
-
- func (nursingHomeSetDb *NursingHomeSetDb) Set(enterpriseId int) { // set方法
- nursingHomeSetDb.Db = Db
- nursingHomeSetDb.EnterpriseId = enterpriseId
- }
-
- func (nursingHomeSetDb *NursingHomeSetDb) GetNursingHomeSet() (m *model.NursingHomeSet, err error) {
- m = new(model.NursingHomeSet)
- has, err := nursingHomeSetDb.Db.Where("enterprise_id =?", nursingHomeSetDb.EnterpriseId).Get(m)
- if err != nil {
- return nil, logx.Error(err)
- }
- if has == false {
- return nil, nil
- }
- return m, nil
- }
-
- func (nursingHomeSetDb *NursingHomeSetDb) NursingHomeSetInsert(m *model.NursingHomeSet) (int, error) {
- _, err := nursingHomeSetDb.Db.InsertOne(m)
- if err != nil {
- return 0, err
- }
- return m.Id, nil
- }
-
- func (nursingHomeSetDb *NursingHomeSetDb) BatchAddNursingHomeSets(mm []*model.NursingHomeSet) (int64, error) {
- affected, err := nursingHomeSetDb.Db.Insert(mm)
- if err != nil {
- return 0, err
- }
- return affected, nil
- }
-
- func (nursingHomeSetDb *NursingHomeSetDb) NursingHomeSetDeleteById(id interface{}) (int64, error) {
- if reflect.TypeOf(id).Kind() == reflect.Slice {
- return Db.In("id", id).Delete(model.NursingHomeSet{})
- } else {
- return Db.Where("id = ?", id).Delete(model.NursingHomeSet{})
- }
- }
-
- func (nursingHomeSetDb *NursingHomeSetDb) NursingHomeSetDelete() (int64, error) {
- return Db.Where("enterprise_id = ?", nursingHomeSetDb.EnterpriseId).Delete(model.NursingHomeSet{})
- }
-
- func (nursingHomeSetDb *NursingHomeSetDb) NursingHomeSetUpdate(id interface{}, m *model.NursingHomeSet, forceColums ...string) (int64, error) {
- var (
- affected int64
- err error
- )
- if forceColums != nil {
- affected, err = nursingHomeSetDb.Db.Where("id=?", id).Cols(forceColums...).Update(m)
- } else {
- affected, err = nursingHomeSetDb.Db.Where("id=?", id).Update(m)
- }
- if err != nil {
- return 0, err
- }
- return affected, nil
- }
|