|
- package db
-
- import (
- "applet/app/admin/md"
- "applet/app/db/model"
- "applet/app/utils/logx"
- "reflect"
- "xorm.io/xorm"
- )
-
- type NursingHomePackageDb struct {
- Db *xorm.Engine `json:"db"`
- }
-
- func (nursingHomePackageDb *NursingHomePackageDb) Set() { // set方法
- nursingHomePackageDb.Db = Db
- }
-
- func (nursingHomePackageDb *NursingHomePackageDb) GetNursingHomePackage(id int) (m *model.NursingHomePackage, err error) {
- m = new(model.NursingHomePackage)
- has, err := nursingHomePackageDb.Db.Where("id =?", id).Get(m)
- if err != nil {
- return nil, logx.Error(err)
- }
- if has == false {
- return nil, nil
- }
- return m, nil
- }
-
- func (nursingHomePackageDb *NursingHomePackageDb) GetNursingHomePackageByMonth(enterpriseId int, year, month string) (m *model.NursingHomePackage, err error) {
- m = new(model.NursingHomePackage)
- has, err := nursingHomePackageDb.Db.Where("enterprise_id =?", enterpriseId).And("year =? and month =? and is_delete = 0", year, month).Get(m)
- if err != nil {
- return nil, logx.Error(err)
- }
- if has == false {
- return nil, nil
- }
- return m, nil
- }
-
- func (nursingHomePackageDb *NursingHomePackageDb) FindNursingHomePackage() (*[]model.NursingHomePackage, error) {
- var m []model.NursingHomePackage
- if err := nursingHomePackageDb.Db.Desc("id").Find(&m); err != nil {
- return nil, logx.Error(err)
- }
- return &m, nil
- }
-
- func (nursingHomePackageDb *NursingHomePackageDb) NursingHomePackageInsert(m *model.NursingHomePackage) (int, error) {
- _, err := nursingHomePackageDb.Db.InsertOne(m)
- if err != nil {
- return 0, err
- }
- return m.Id, nil
- }
-
- func (nursingHomePackageDb *NursingHomePackageDb) NursingHomePackageInsertBySession(session *xorm.Session, m *model.NursingHomePackage) (int, error) {
- _, err := session.InsertOne(m)
- if err != nil {
- return 0, err
- }
- return m.Id, nil
- }
-
- func (nursingHomePackageDb *NursingHomePackageDb) NursingHomePackageDelete(id interface{}) (int64, error) {
- if reflect.TypeOf(id).Kind() == reflect.Slice {
- return Db.In("id", id).Delete(model.NursingHomePackage{})
- } else {
- return Db.Where("id = ?", id).Delete(model.NursingHomePackage{})
- }
- }
-
- func (nursingHomePackageDb *NursingHomePackageDb) NursingHomePackageUpdateBySession(session *xorm.Session, id interface{}, m *model.NursingHomePackage, forceColums ...string) (int64, error) {
- var (
- affected int64
- err error
- )
- if forceColums != nil {
- affected, err = session.Where("id=?", id).Cols(forceColums...).Update(m)
- } else {
- affected, err = session.Where("id=?", id).Update(m)
- }
- if err != nil {
- return 0, err
- }
- return affected, nil
- }
-
- func (nursingHomePackageDb *NursingHomePackageDb) NursingHomePackageList(req md.ListNursingHomePackageReq) (m []model.NursingHomePackage, total int64, err error) {
- sess := nursingHomePackageDb.Db.Where("enterprise_id =?", req.EnterpriseId).Desc("id").Limit(req.Limit, (req.Page-1)*req.Limit)
- if req.Year != "" {
- sess.And("year = ?", req.Year)
- }
- if req.Month != "" {
- sess.And("month = ?", req.Month)
- }
- total, err = sess.And("is_delete = 0").FindAndCount(&m)
- if err != nil {
- return
- }
- return
- }
|