49 lines
1.2 KiB
Go
49 lines
1.2 KiB
Go
|
package product
|
||
|
|
||
|
import (
|
||
|
models "com.snow.auto_monitor/app/models/product"
|
||
|
)
|
||
|
|
||
|
func GetLimitStart(limit int, page int) (int, int) {
|
||
|
if limit <= 0 {
|
||
|
limit = 20
|
||
|
}
|
||
|
if page > 0 {
|
||
|
page = (page - 1) * limit
|
||
|
} else {
|
||
|
page = 0
|
||
|
}
|
||
|
return limit, page
|
||
|
}
|
||
|
|
||
|
func GetById(id int64) (res *models.Product, err error) {
|
||
|
res, _, err = models.GetInstance().GetById(id)
|
||
|
return
|
||
|
}
|
||
|
|
||
|
func Search(id int64, name string, startTime string, endTime string, limit int, page int) (res []*models.Product, err error) {
|
||
|
limit, page = GetLimitStart(limit, page)
|
||
|
res, err = models.GetInstance().Search(id, name, startTime, endTime, limit, page)
|
||
|
return
|
||
|
}
|
||
|
|
||
|
func CountAll(id int64, name string, startTime string, endTime string) (res int64, err error) {
|
||
|
res, err = models.GetInstance().CountAll(id, name, startTime, endTime)
|
||
|
return
|
||
|
}
|
||
|
|
||
|
func Create(product *models.Product) (affected int64, err error) {
|
||
|
affected, err = models.GetInstance().Create(product)
|
||
|
return
|
||
|
}
|
||
|
|
||
|
func Update(product *models.Product) (affected int64, err error) {
|
||
|
affected, err = models.GetInstance().Update(product)
|
||
|
return
|
||
|
}
|
||
|
|
||
|
func Delete(id int64) (affected int64, err error) {
|
||
|
affected, err = models.GetInstance().Delete(id)
|
||
|
return
|
||
|
}
|