fix: custom indicator and get state issue merge from main line
This commit is contained in:
@@ -14,6 +14,7 @@ import (
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// get customize kpi total and list
|
||||
func (k *KpiCTitle) GetToalList(c *gin.Context) {
|
||||
var titles []KpiCTitle
|
||||
var conditions []string
|
||||
@@ -35,7 +36,10 @@ func (k *KpiCTitle) GetToalList(c *gin.Context) {
|
||||
if status := querys.Status; status != "" {
|
||||
conditions = append(conditions, "status = ?")
|
||||
params = append(params, status)
|
||||
} else {
|
||||
conditions = append(conditions, "status != 'Deleted'")
|
||||
}
|
||||
|
||||
whereSql := ""
|
||||
if len(conditions) > 0 {
|
||||
whereSql += strings.Join(conditions, " and ")
|
||||
@@ -87,7 +91,10 @@ func (k *KpiCTitle) Get(c *gin.Context) {
|
||||
if status := c.Query("status"); status != "" {
|
||||
conditions = append(conditions, "status = ?")
|
||||
params = append(params, status)
|
||||
} else {
|
||||
conditions = append(conditions, "status != 'Deleted'")
|
||||
}
|
||||
|
||||
whereSql := ""
|
||||
if len(conditions) > 0 {
|
||||
whereSql += strings.Join(conditions, " and ")
|
||||
@@ -103,6 +110,7 @@ func (k *KpiCTitle) Get(c *gin.Context) {
|
||||
//c.JSON(http.StatusOK, titles)
|
||||
}
|
||||
|
||||
// alias customized kpi expression with cn/en title
|
||||
func (k *KpiCTitle) expressionAlias(titles []KpiCTitle, i18n string) {
|
||||
var title *KpiCTitle
|
||||
for i := 0; i < len(titles); i++ {
|
||||
@@ -140,7 +148,10 @@ func (k *KpiCTitle) Total(c *gin.Context) {
|
||||
if status := c.Query("status"); status != "" {
|
||||
conditions = append(conditions, "status = ?")
|
||||
params = append(params, status)
|
||||
} else {
|
||||
conditions = append(conditions, "status != 'Deleted'")
|
||||
}
|
||||
|
||||
whereSql := ""
|
||||
if len(conditions) > 0 {
|
||||
whereSql += strings.Join(conditions, " and ")
|
||||
@@ -168,7 +179,11 @@ func (k *KpiCTitle) Post(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, services.ErrResp("custom indicator already exist"))
|
||||
return
|
||||
}
|
||||
ret := dborm.DefaultDB().Table("kpi_c_title").Where("ne_type=? ORDER BY kpi_id DESC LIMIT 1", title.NeType).Scan(&res)
|
||||
|
||||
// Regexp match like AMF.C.01
|
||||
kpiIDRegexp := "^" + *title.NeType + "\\.C\\.[0-9]{2}$"
|
||||
ret := dborm.DefaultDB().Table("kpi_c_title").
|
||||
Where("ne_type=? and kpi_id REGEXP ? ORDER BY kpi_id DESC LIMIT 1", title.NeType, kpiIDRegexp).Scan(&res)
|
||||
if err := ret.Error; err != nil {
|
||||
c.JSON(http.StatusOK, services.ErrResp(err.Error()))
|
||||
return
|
||||
@@ -241,8 +256,8 @@ func (k *KpiCTitle) Put(c *gin.Context) {
|
||||
func (k *KpiCTitle) Delete(c *gin.Context) {
|
||||
id := c.Param("id")
|
||||
|
||||
if err := dborm.DefaultDB().Delete(&KpiCTitle{}, id).Error; err != nil {
|
||||
c.JSON(http.StatusOK, services.ErrResp("custom indicator not found"))
|
||||
if err := dborm.DefaultDB().Table(k.TableName()).Where("id=?", id).Update("status", "Deleted").Error; err != nil {
|
||||
c.JSON(http.StatusOK, services.ErrResp(err.Error()))
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user