增加kpi_c_title接口的total
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"be.ems/src/framework/datasource"
|
"be.ems/src/framework/datasource"
|
||||||
|
"be.ems/src/framework/vo/result"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -12,7 +13,7 @@ func (k *KpiCTitle) Get(c *gin.Context) {
|
|||||||
var titles []KpiCTitle
|
var titles []KpiCTitle
|
||||||
var conditions []string
|
var conditions []string
|
||||||
var params []any
|
var params []any
|
||||||
|
var total int64
|
||||||
// construct condition to get
|
// construct condition to get
|
||||||
if neType := c.Query("neType"); neType != "" {
|
if neType := c.Query("neType"); neType != "" {
|
||||||
conditions = append(conditions, "ne_type = ?")
|
conditions = append(conditions, "ne_type = ?")
|
||||||
@@ -23,15 +24,32 @@ func (k *KpiCTitle) Get(c *gin.Context) {
|
|||||||
params = append(params, status)
|
params = append(params, status)
|
||||||
}
|
}
|
||||||
whereSql := ""
|
whereSql := ""
|
||||||
|
totalSql := ""
|
||||||
|
|
||||||
if len(conditions) > 0 {
|
if len(conditions) > 0 {
|
||||||
whereSql += strings.Join(conditions, " and ")
|
whereSql += strings.Join(conditions, " and ")
|
||||||
|
totalSql += strings.Join(conditions, " and ")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
data := map[string]any{
|
||||||
|
"total": 0,
|
||||||
|
"rows": []KpiCTitle{},
|
||||||
|
}
|
||||||
|
|
||||||
if err := datasource.DefaultDB().Where(whereSql, params...).Find(&titles).Error; err != nil {
|
if err := datasource.DefaultDB().Where(whereSql, params...).Find(&titles).Error; err != nil {
|
||||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
data["rows"] = titles
|
||||||
|
|
||||||
|
if err := datasource.DefaultDB().Table(k.TableName()).Where(totalSql, params...).Count(&total).Error; err != nil {
|
||||||
|
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
data["total"] = total
|
||||||
|
|
||||||
//c.JSON(http.StatusOK, map[string]any{"data": titles})
|
//c.JSON(http.StatusOK, map[string]any{"data": titles})
|
||||||
c.JSON(http.StatusOK, titles)
|
c.JSON(http.StatusOK, result.Ok(data))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (k *KpiCTitle) Total(c *gin.Context) {
|
func (k *KpiCTitle) Total(c *gin.Context) {
|
||||||
|
|||||||
Reference in New Issue
Block a user