|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- 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
- }
|