mager: 合并11.3版本,包名和主线一样方便复制
This commit is contained in:
@@ -5,9 +5,8 @@ import (
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"nms_cxy/lib/dborm"
|
||||
"nms_cxy/lib/services"
|
||||
|
||||
"be.ems/lib/dborm"
|
||||
"be.ems/lib/services"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
@@ -41,13 +40,14 @@ func (k *KpiCReport) Get(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
if querys.StartTime != "" {
|
||||
conditions = append(conditions, "created_at >= ?")
|
||||
conditions = append(conditions, "(UNIX_TIMESTAMP(created_at) * 1000) >= ?")
|
||||
params = append(params, querys.StartTime)
|
||||
}
|
||||
if querys.EndTime != "" {
|
||||
conditions = append(conditions, "created_at <= ?")
|
||||
conditions = append(conditions, "(UNIX_TIMESTAMP(created_at) * 1000) <= ?")
|
||||
params = append(params, querys.EndTime)
|
||||
}
|
||||
conditions = append(conditions, "kpi_values != 'null'")
|
||||
|
||||
whereSql := ""
|
||||
if len(conditions) > 0 {
|
||||
@@ -71,7 +71,7 @@ func (k *KpiCReport) Get(c *gin.Context) {
|
||||
//err := dborm.DefaultDB().Table(tableName).Where(whereSql, params...).Find(&reports).Error
|
||||
err := dbg.Find(&reports).Error
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, services.ErrResp(err.Error()))
|
||||
c.JSON(http.StatusOK, services.ErrResp(err.Error()))
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, services.DataResp(reports))
|
||||
@@ -84,7 +84,7 @@ func (k *KpiCReport) GetReport2FE(c *gin.Context) {
|
||||
|
||||
var querys KpiCReportQuery
|
||||
if err := c.ShouldBindQuery(&querys); err != nil {
|
||||
c.JSON(http.StatusBadRequest, services.ErrResp(err.Error()))
|
||||
c.JSON(http.StatusOK, services.ErrResp(err.Error()))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -93,7 +93,7 @@ func (k *KpiCReport) GetReport2FE(c *gin.Context) {
|
||||
conditions = append(conditions, "ne_type = ?")
|
||||
params = append(params, strings.ToUpper(querys.NeType))
|
||||
} else {
|
||||
c.JSON(http.StatusBadRequest, services.ErrResp("Not found required parameter NE type"))
|
||||
c.JSON(http.StatusOK, services.ErrResp("Not found required parameter NE type"))
|
||||
return
|
||||
}
|
||||
tableName := TableName() + "_" + strings.ToLower(querys.NeType)
|
||||
@@ -107,13 +107,14 @@ func (k *KpiCReport) GetReport2FE(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
if querys.StartTime != "" {
|
||||
conditions = append(conditions, "created_at >= ?")
|
||||
conditions = append(conditions, "(UNIX_TIMESTAMP(created_at) * 1000) >= ?")
|
||||
params = append(params, querys.StartTime)
|
||||
}
|
||||
if querys.EndTime != "" {
|
||||
conditions = append(conditions, "created_at <= ?")
|
||||
conditions = append(conditions, "(UNIX_TIMESTAMP(created_at) * 1000) <= ?")
|
||||
params = append(params, querys.EndTime)
|
||||
}
|
||||
conditions = append(conditions, "kpi_values != 'null'")
|
||||
|
||||
whereSql := ""
|
||||
if len(conditions) > 0 {
|
||||
@@ -137,7 +138,7 @@ func (k *KpiCReport) GetReport2FE(c *gin.Context) {
|
||||
//err := dborm.DefaultDB().Table(tableName).Where(whereSql, params...).Find(&reports).Error
|
||||
err := dbg.Find(&results).Error
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, services.ErrResp(err.Error()))
|
||||
c.JSON(http.StatusOK, services.ErrResp(err.Error()))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -150,7 +151,7 @@ func (k *KpiCReport) GetReport2FE(c *gin.Context) {
|
||||
"neName": *r.NeName,
|
||||
"rmUID": *r.RmUID,
|
||||
"startIndex": r.Index,
|
||||
"timeGroup": r.Date[:10] + " " + *r.StartTime,
|
||||
"timeGroup": r.Date[:10] + " " + *r.EndTime,
|
||||
"createdAt": r.CreatedAt,
|
||||
"granularity": r.Granularity,
|
||||
}
|
||||
@@ -170,7 +171,7 @@ func (k *KpiCReport) GetTotalList(c *gin.Context) {
|
||||
|
||||
var querys KpiCReportQuery
|
||||
if err := c.ShouldBindQuery(&querys); err != nil {
|
||||
c.JSON(http.StatusBadRequest, services.ErrResp(err.Error()))
|
||||
c.JSON(http.StatusOK, services.ErrResp(err.Error()))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -179,20 +180,21 @@ func (k *KpiCReport) GetTotalList(c *gin.Context) {
|
||||
conditions = append(conditions, "ne_type = ?")
|
||||
params = append(params, strings.ToUpper(querys.NeType))
|
||||
} else {
|
||||
c.JSON(http.StatusBadRequest, services.ErrResp("Not found NE type"))
|
||||
c.JSON(http.StatusOK, services.ErrResp("Not found NE type"))
|
||||
return
|
||||
}
|
||||
tableName := TableName() + "_" + strings.ToLower(querys.NeType)
|
||||
dbg := dborm.DefaultDB().Table(tableName)
|
||||
|
||||
if querys.StartTime != "" {
|
||||
conditions = append(conditions, "created_at >= ?")
|
||||
conditions = append(conditions, "(UNIX_TIMESTAMP(created_at) * 1000) >= ?")
|
||||
params = append(params, querys.StartTime)
|
||||
}
|
||||
if querys.EndTime != "" {
|
||||
conditions = append(conditions, "created_at <= ?")
|
||||
conditions = append(conditions, "(UNIX_TIMESTAMP(created_at) * 1000) <= ?")
|
||||
params = append(params, querys.EndTime)
|
||||
}
|
||||
conditions = append(conditions, "kpi_values != 'null'")
|
||||
|
||||
whereSql := ""
|
||||
if len(conditions) > 0 {
|
||||
@@ -204,7 +206,7 @@ func (k *KpiCReport) GetTotalList(c *gin.Context) {
|
||||
var total int64 = 0
|
||||
err := dbg.Count(&total).Error
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, services.ErrResp(err.Error()))
|
||||
c.JSON(http.StatusOK, services.ErrResp(err.Error()))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -225,7 +227,7 @@ func (k *KpiCReport) GetTotalList(c *gin.Context) {
|
||||
//err := dborm.DefaultDB().Table(tableName).Where(whereSql, params...).Find(&reports).Error
|
||||
err = dbg.Find(&reports).Error
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, services.ErrResp(err.Error()))
|
||||
c.JSON(http.StatusOK, services.ErrResp(err.Error()))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -238,7 +240,7 @@ func (k *KpiCReport) Total(c *gin.Context) {
|
||||
|
||||
var querys KpiCReportQuery
|
||||
if err := c.ShouldBindQuery(&querys); err != nil {
|
||||
c.JSON(http.StatusBadRequest, services.ErrResp(err.Error()))
|
||||
c.JSON(http.StatusOK, services.ErrResp(err.Error()))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -247,20 +249,21 @@ func (k *KpiCReport) Total(c *gin.Context) {
|
||||
conditions = append(conditions, "ne_type = ?")
|
||||
params = append(params, strings.ToUpper(querys.NeType))
|
||||
} else {
|
||||
c.JSON(http.StatusBadRequest, services.ErrResp("Not found NE type"))
|
||||
c.JSON(http.StatusOK, services.ErrResp("Not found NE type"))
|
||||
return
|
||||
}
|
||||
tableName := TableName() + "_" + strings.ToLower(querys.NeType)
|
||||
dbg := dborm.DefaultDB().Table(tableName)
|
||||
|
||||
if querys.StartTime != "" {
|
||||
conditions = append(conditions, "created_at >= ?")
|
||||
conditions = append(conditions, "(UNIX_TIMESTAMP(created_at) * 1000) >= ?")
|
||||
params = append(params, querys.StartTime)
|
||||
}
|
||||
if querys.EndTime != "" {
|
||||
conditions = append(conditions, "created_at <= ?")
|
||||
conditions = append(conditions, "(UNIX_TIMESTAMP(created_at) * 1000) <= ?")
|
||||
params = append(params, querys.EndTime)
|
||||
}
|
||||
conditions = append(conditions, "kpi_values != 'null'")
|
||||
|
||||
whereSql := ""
|
||||
if len(conditions) > 0 {
|
||||
@@ -270,7 +273,7 @@ func (k *KpiCReport) Total(c *gin.Context) {
|
||||
var total int64 = 0
|
||||
err := dbg.Count(&total).Error
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, services.ErrResp(err.Error()))
|
||||
c.JSON(http.StatusOK, services.ErrResp(err.Error()))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -281,11 +284,11 @@ func (k *KpiCReport) Post(c *gin.Context) {
|
||||
var report KpiCReport
|
||||
|
||||
if err := c.ShouldBindJSON(&report); err != nil {
|
||||
c.JSON(http.StatusBadRequest, services.ErrResp(err.Error()))
|
||||
c.JSON(http.StatusOK, services.ErrResp(err.Error()))
|
||||
return
|
||||
}
|
||||
if err := dborm.DefaultDB().Create(&report).Error; err != nil {
|
||||
c.JSON(http.StatusInternalServerError, services.ErrResp(err.Error()))
|
||||
c.JSON(http.StatusOK, services.ErrResp(err.Error()))
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusCreated, services.DataResp(report))
|
||||
@@ -296,12 +299,12 @@ func (k *KpiCReport) Put(c *gin.Context) {
|
||||
id := c.Param("id")
|
||||
|
||||
if err := dborm.DefaultDB().First(&report, id).Error; err != nil {
|
||||
c.JSON(http.StatusNotFound, services.ErrResp("KPI report not found"))
|
||||
c.JSON(http.StatusOK, services.ErrResp("custom indicator report not found"))
|
||||
return
|
||||
}
|
||||
|
||||
if err := c.ShouldBindJSON(&report); err != nil {
|
||||
c.JSON(http.StatusBadRequest, services.ErrResp(err.Error()))
|
||||
c.JSON(http.StatusOK, services.ErrResp(err.Error()))
|
||||
return
|
||||
}
|
||||
dborm.DefaultDB().Save(&report)
|
||||
@@ -312,7 +315,7 @@ func (k *KpiCReport) Delete(c *gin.Context) {
|
||||
id := c.Param("id")
|
||||
|
||||
if err := dborm.DefaultDB().Delete(&KpiCReport{}, id).Error; err != nil {
|
||||
c.JSON(http.StatusNotFound, services.ErrResp("KPI report not found"))
|
||||
c.JSON(http.StatusOK, services.ErrResp("custom indicator report not found"))
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user