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