package test
|
|
import (
|
"srm/global"
|
"srm/model/common/request"
|
"srm/model/test"
|
testReq "srm/model/test/request"
|
)
|
|
type ContractService struct {
|
}
|
|
// CreateContract 创建Contract记录
|
// Author [piexlmax](https://github.com/piexlmax)
|
func (conService *ContractService) CreateContract(con *test.Contract) (err error, uid uint) {
|
err = global.GVA_DB.Create(&con).Error
|
return err, con.ID
|
}
|
|
// DeleteContract 删除Contract记录
|
// Author [piexlmax](https://github.com/piexlmax)
|
func (conService *ContractService) DeleteContract(con test.Contract) (err error) {
|
err = global.GVA_DB.Delete(&con).Error
|
return err
|
}
|
|
// DeleteContractByIds 批量删除Contract记录
|
// Author [piexlmax](https://github.com/piexlmax)
|
func (conService *ContractService) DeleteContractByIds(ids request.IdsReq) (err error) {
|
err = global.GVA_DB.Delete(&[]test.Contract{}, "id in ?", ids.Ids).Error
|
return err
|
}
|
|
// UpdateContract 更新Contract记录
|
// Author [piexlmax](https://github.com/piexlmax)
|
func (conService *ContractService) UpdateContract(con test.Contract) (err error) {
|
err = global.GVA_DB.Save(&con).Error
|
return err
|
}
|
|
// GetContract 根据id获取Contract记录
|
// Author [piexlmax](https://github.com/piexlmax)
|
func (conService *ContractService) GetContract(id uint) (con test.Contract, err error) {
|
err = global.GVA_DB.Where("id = ?", id).First(&con).Error
|
return
|
}
|
|
// GetContractInfoList 分页获取Contract记录
|
// Author [piexlmax](https://github.com/piexlmax)
|
func (conService *ContractService) GetContractInfoList(info testReq.ContractSearch) (list []test.Contract, total int64, err error) {
|
limit := info.PageSize
|
offset := info.PageSize * (info.Page - 1)
|
// 创建db
|
db := global.GVA_DB.Model(&test.Contract{})
|
var cons []test.Contract
|
// 如果有条件搜索 下方会自动创建搜索语句
|
if info.StartCreatedAt != nil && info.EndCreatedAt != nil {
|
db = db.Where("created_at BETWEEN ? AND ?", info.StartCreatedAt, info.EndCreatedAt)
|
}
|
err = db.Count(&total).Error
|
if err != nil {
|
return
|
}
|
|
err = db.Limit(limit).Offset(offset).Find(&cons).Error
|
return cons, total, err
|
}
|