add: custom kpi feature
This commit is contained in:
@@ -10,15 +10,6 @@ import (
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
const (
|
||||
CodeKeyName = "code"
|
||||
MsgKeyName = "message"
|
||||
DataKeyName = "data"
|
||||
CodeError = 0
|
||||
CodeSuccess = 1
|
||||
TotalKeyName = "total"
|
||||
)
|
||||
|
||||
func (k *KpiCReport) Get(c *gin.Context) {
|
||||
var reports []KpiCReport
|
||||
var conditions []string
|
||||
@@ -115,6 +106,15 @@ func (k *KpiCReport) GetTotalList(c *gin.Context) {
|
||||
whereSql += strings.Join(conditions, " and ")
|
||||
dborm = dborm.Where(whereSql, params...)
|
||||
}
|
||||
|
||||
// get total number
|
||||
var total int64 = 0
|
||||
err := dborm.Count(&total).Error
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, services.ErrResp(err.Error()))
|
||||
return
|
||||
}
|
||||
|
||||
// page number and size
|
||||
if pageSize := querys.PageSize; pageSize > 0 {
|
||||
dborm = dborm.Limit(pageSize)
|
||||
@@ -130,18 +130,12 @@ func (k *KpiCReport) GetTotalList(c *gin.Context) {
|
||||
}
|
||||
|
||||
//err := datasource.DefaultDB().Table(tableName).Where(whereSql, params...).Find(&reports).Error
|
||||
err := dborm.Find(&reports).Error
|
||||
err = dborm.Find(&reports).Error
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, services.ErrResp(err.Error()))
|
||||
return
|
||||
}
|
||||
|
||||
var total int64 = 0
|
||||
err = dborm.Count(&total).Error
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, services.ErrResp(err.Error()))
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, services.TotalDataResp(reports, total))
|
||||
//c.JSON(http.StatusOK, reports)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user