From 9b788d2f0a0f38328b4ca6a20b3bf1649bba661b Mon Sep 17 00:00:00 2001 From: lai <371757574@qq.com> Date: Thu, 8 Aug 2024 18:07:07 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0kpi=5Fc=5Ftitle=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E7=9A=84total?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- features/pm/kpi_c_title/controller.go | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/features/pm/kpi_c_title/controller.go b/features/pm/kpi_c_title/controller.go index 32c4eb32..490c3b02 100644 --- a/features/pm/kpi_c_title/controller.go +++ b/features/pm/kpi_c_title/controller.go @@ -5,6 +5,7 @@ import ( "strings" "be.ems/src/framework/datasource" + "be.ems/src/framework/vo/result" "github.com/gin-gonic/gin" ) @@ -12,7 +13,7 @@ func (k *KpiCTitle) Get(c *gin.Context) { var titles []KpiCTitle var conditions []string var params []any - + var total int64 // construct condition to get if neType := c.Query("neType"); neType != "" { conditions = append(conditions, "ne_type = ?") @@ -23,15 +24,32 @@ func (k *KpiCTitle) Get(c *gin.Context) { params = append(params, status) } whereSql := "" + totalSql := "" + if len(conditions) > 0 { 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 { c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()}) 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, titles) + c.JSON(http.StatusOK, result.Ok(data)) } func (k *KpiCTitle) Total(c *gin.Context) {