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