72 lines
2.5 KiB
Go
72 lines
2.5 KiB
Go
package pet
|
|
|
|
import (
|
|
"context"
|
|
"github.com/flipped-aurora/gin-vue-admin/server/global"
|
|
"github.com/flipped-aurora/gin-vue-admin/server/model/pet"
|
|
petReq "github.com/flipped-aurora/gin-vue-admin/server/model/pet/request"
|
|
)
|
|
|
|
type PetRecordsService struct{}
|
|
|
|
// CreatePetRecords 创建petRecords表记录
|
|
// Author [yourname](https://github.com/yourname)
|
|
func (petRecordsService *PetRecordsService) CreatePetRecords(ctx context.Context, petRecords *pet.PetRecords) (err error) {
|
|
err = global.GVA_DB.Create(petRecords).Error
|
|
return err
|
|
}
|
|
|
|
// DeletePetRecords 删除petRecords表记录
|
|
// Author [yourname](https://github.com/yourname)
|
|
func (petRecordsService *PetRecordsService) DeletePetRecords(ctx context.Context, ID string) (err error) {
|
|
err = global.GVA_DB.Delete(&pet.PetRecords{}, "id = ?", ID).Error
|
|
return err
|
|
}
|
|
|
|
// DeletePetRecordsByIds 批量删除petRecords表记录
|
|
// Author [yourname](https://github.com/yourname)
|
|
func (petRecordsService *PetRecordsService) DeletePetRecordsByIds(ctx context.Context, IDs []string) (err error) {
|
|
err = global.GVA_DB.Delete(&[]pet.PetRecords{}, "id in ?", IDs).Error
|
|
return err
|
|
}
|
|
|
|
// UpdatePetRecords 更新petRecords表记录
|
|
// Author [yourname](https://github.com/yourname)
|
|
func (petRecordsService *PetRecordsService) UpdatePetRecords(ctx context.Context, petRecords pet.PetRecords) (err error) {
|
|
err = global.GVA_DB.Model(&pet.PetRecords{}).Where("id = ?", petRecords.ID).Updates(&petRecords).Error
|
|
return err
|
|
}
|
|
|
|
// GetPetRecords 根据ID获取petRecords表记录
|
|
// Author [yourname](https://github.com/yourname)
|
|
func (petRecordsService *PetRecordsService) GetPetRecords(ctx context.Context, ID string) (petRecords pet.PetRecords, err error) {
|
|
err = global.GVA_DB.Where("id = ?", ID).First(&petRecords).Error
|
|
return
|
|
}
|
|
|
|
// GetPetRecordsInfoList 分页获取petRecords表记录
|
|
// Author [yourname](https://github.com/yourname)
|
|
func (petRecordsService *PetRecordsService) GetPetRecordsInfoList(ctx context.Context, info petReq.PetRecordsSearch) (list []pet.PetRecords, total int64, err error) {
|
|
limit := info.PageSize
|
|
offset := info.PageSize * (info.Page - 1)
|
|
// 创建db
|
|
db := global.GVA_DB.Model(&pet.PetRecords{})
|
|
var petRecordss []pet.PetRecords
|
|
// 如果有条件搜索 下方会自动创建搜索语句
|
|
if len(info.CreatedAtRange) == 2 {
|
|
db = db.Where("created_at BETWEEN ? AND ?", info.CreatedAtRange[0], info.CreatedAtRange[1])
|
|
}
|
|
|
|
err = db.Count(&total).Error
|
|
if err != nil {
|
|
return
|
|
}
|
|
|
|
if limit != 0 {
|
|
db = db.Limit(limit).Offset(offset)
|
|
}
|
|
|
|
err = db.Find(&petRecordss).Error
|
|
return petRecordss, total, err
|
|
}
|