fix: custom indicator kpi_id issue
This commit is contained in:
@@ -36,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 ")
|
||||
@@ -88,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 ")
|
||||
@@ -142,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 ")
|
||||
@@ -170,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
|
||||
@@ -243,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