|
- package db
-
- import (
- "applet/app/db/model"
- "applet/app/utils/logx"
- "reflect"
- "xorm.io/xorm"
- )
-
- type NursingHomeUserWithDayDb struct {
- Db *xorm.Engine `json:"db"`
- IdentityId int `json:"identity_id"`
- }
-
- func (nursingHomeUserWithDayDb *NursingHomeUserWithDayDb) Set(identityId int) { // set方法
- nursingHomeUserWithDayDb.Db = Db
- nursingHomeUserWithDayDb.IdentityId = identityId
- }
-
- func (nursingHomeUserWithDayDb *NursingHomeUserWithDayDb) GetNursingHomeUserWithDay(id int) (m *model.NursingHomeUserWithDay, err error) {
- m = new(model.NursingHomeUserWithDay)
- has, err := nursingHomeUserWithDayDb.Db.Where("id =?", id).Get(m)
- if err != nil {
- return nil, logx.Error(err)
- }
- if has == false {
- return nil, nil
- }
- return m, nil
- }
-
- func (nursingHomeUserWithDayDb *NursingHomeUserWithDayDb) FindNursingHomeUserWithDayByDate(sDate, eDate string) (*[]model.NursingHomeUserWithDay, error) {
- var m []model.NursingHomeUserWithDay
- if err := nursingHomeUserWithDayDb.Db.Where("identity_id =?", nursingHomeUserWithDayDb.IdentityId).
- And("date >= ? And date <= ?", sDate, eDate).Asc("date").Find(&m); err != nil {
- return nil, logx.Error(err)
- }
- return &m, nil
- }
-
- func (nursingHomeUserWithDayDb *NursingHomeUserWithDayDb) FindNursingHomeUserWithDayByOrdNo(ordNo string) (*[]model.NursingHomeUserWithDay, error) {
- var m []model.NursingHomeUserWithDay
- if err := nursingHomeUserWithDayDb.Db.Where("ord_no =?", ordNo).Desc("id").Find(&m); err != nil {
- return nil, logx.Error(err)
- }
- return &m, nil
- }
-
- func (nursingHomeUserWithDayDb *NursingHomeUserWithDayDb) FindNursingHomeUserWithDayByOrdNoAndState(ordNo string, state int) (*[]model.NursingHomeUserWithDay, error) {
- var m []model.NursingHomeUserWithDay
- if err := nursingHomeUserWithDayDb.Db.Where("ord_no =?", ordNo).And("state =?", state).Desc("id").Find(&m); err != nil {
- return nil, logx.Error(err)
- }
- return &m, nil
- }
-
- func (nursingHomeUserWithDayDb *NursingHomeUserWithDayDb) NursingHomeUserWithDayInsert(m *model.NursingHomeUserWithDay) (int, error) {
- _, err := nursingHomeUserWithDayDb.Db.InsertOne(m)
- if err != nil {
- return 0, err
- }
- return m.Id, nil
- }
-
- func (nursingHomeUserWithDayDb *NursingHomeUserWithDayDb) BatchAddNursingHomeUserWithDays(mm []*model.NursingHomeUserWithDay) (int64, error) {
- affected, err := nursingHomeUserWithDayDb.Db.Insert(mm)
- if err != nil {
- return 0, err
- }
- return affected, nil
- }
-
- func (nursingHomeUserWithDayDb *NursingHomeUserWithDayDb) NursingHomeUserWithDayDelete(id interface{}) (int64, error) {
- if reflect.TypeOf(id).Kind() == reflect.Slice {
- return Db.In("id", id).Delete(model.NursingHomeUserWithDay{})
- } else {
- return Db.Where("id = ?", id).Delete(model.NursingHomeUserWithDay{})
- }
- }
-
- func (nursingHomeUserWithDayDb *NursingHomeUserWithDayDb) NursingHomeUserWithDayUpdate(id interface{}, m *model.NursingHomeUserWithDay, forceColums ...string) (int64, error) {
- var (
- affected int64
- err error
- )
- if forceColums != nil {
- affected, err = nursingHomeUserWithDayDb.Db.Where("id=?", id).Cols(forceColums...).Update(m)
- } else {
- affected, err = nursingHomeUserWithDayDb.Db.Where("id=?", id).Update(m)
- }
- if err != nil {
- return 0, err
- }
- return affected, nil
- }
-
- func (nursingHomeUserWithDayDb *NursingHomeUserWithDayDb) NursingHomeUserWithDayBatchUpdate(ids interface{}, m []*model.NursingHomeUserWithDay) (int64, error) {
- var (
- affected int64
- err error
- )
- affected, err = nursingHomeUserWithDayDb.Db.In("id", ids).Update(m)
- if err != nil {
- return 0, err
- }
- return affected, nil
- }
|