fix: return code to FE issue

This commit is contained in:
2024-09-09 17:11:10 +08:00
parent adec327bc3
commit 9a14520da6
2 changed files with 30 additions and 30 deletions

View File

@@ -17,7 +17,7 @@ func (k *KpiCTitle) GetToalList(c *gin.Context) {
var querys KpiCTitleQuery
if err := c.ShouldBindQuery(&querys); err != nil {
c.JSON(http.StatusBadRequest, services.ErrResp(err.Error()))
c.JSON(http.StatusOK, services.ErrResp(err.Error()))
return
}
@@ -40,7 +40,7 @@ func (k *KpiCTitle) GetToalList(c *gin.Context) {
// Get total number
var total int64 = 0
if err := dbg.Count(&total).Error; err != nil {
c.JSON(http.StatusInternalServerError, services.ErrResp(err.Error()))
c.JSON(http.StatusOK, services.ErrResp(err.Error()))
return
}
@@ -58,7 +58,7 @@ func (k *KpiCTitle) GetToalList(c *gin.Context) {
dbg = dbg.Order(orderBy)
}
if err := dbg.Find(&titles).Error; err != nil {
c.JSON(http.StatusInternalServerError, services.ErrResp(err.Error()))
c.JSON(http.StatusOK, services.ErrResp(err.Error()))
return
}
@@ -85,7 +85,7 @@ func (k *KpiCTitle) Get(c *gin.Context) {
whereSql += strings.Join(conditions, " and ")
}
if err := dborm.DefaultDB().Where(whereSql, params...).Find(&titles).Error; err != nil {
c.JSON(http.StatusInternalServerError, services.ErrResp(err.Error()))
c.JSON(http.StatusOK, services.ErrResp(err.Error()))
return
}
@@ -112,7 +112,7 @@ func (k *KpiCTitle) Total(c *gin.Context) {
}
var total int64 = 0
if err := dborm.DefaultDB().Table(k.TableName()).Where(whereSql, params...).Count(&total).Error; err != nil {
c.JSON(http.StatusInternalServerError, services.ErrResp(err.Error()))
c.JSON(http.StatusOK, services.ErrResp(err.Error()))
return
}
@@ -123,16 +123,16 @@ func (k *KpiCTitle) Post(c *gin.Context) {
var title KpiCTitle
if err := c.ShouldBindJSON(&title); err != nil {
c.JSON(http.StatusBadRequest, services.ErrResp(err.Error()))
c.JSON(http.StatusOK, services.ErrResp(err.Error()))
return
}
result := dborm.DefaultDB().Where("ne_type=? and (kpi_id=? or title=?)", title.NeType, title.KpiID, title.Title).First(&title)
if result.RowsAffected > 0 {
c.JSON(http.StatusInternalServerError, services.ErrResp("target kpiC title already exist"))
c.JSON(http.StatusOK, services.ErrResp("target kpiC title already exist"))
return
}
if err := dborm.DefaultDB().Create(&title).Error; err != nil {
c.JSON(http.StatusInternalServerError, services.ErrResp(err.Error()))
c.JSON(http.StatusOK, services.ErrResp(err.Error()))
return
}
kpiCReportTable := "kpi_c_report_" + strings.ToLower(*title.NeType)
@@ -140,17 +140,17 @@ func (k *KpiCTitle) Post(c *gin.Context) {
// clone table "kpi_c_report" to "kpi_c_report_{neType}"
sql := fmt.Sprintf("CREATE TABLE IF NOT EXISTS %s AS SELECT * FROM %s WHERE 1=0", kpiCReportTable, "kpi_c_report")
if _, err := dborm.ExecSQL(sql, nil); err != nil {
c.JSON(http.StatusInternalServerError, services.ErrResp(err.Error()))
c.JSON(http.StatusOK, services.ErrResp(err.Error()))
return
}
sql = fmt.Sprintf("ALTER TABLE %s MODIFY COLUMN `id` int(11) NOT NULL AUTO_INCREMENT FIRST,ADD PRIMARY KEY IF NOT EXISTS (`id`)", kpiCReportTable)
if _, err := dborm.ExecSQL(sql, nil); err != nil {
c.JSON(http.StatusInternalServerError, services.ErrResp(err.Error()))
c.JSON(http.StatusOK, services.ErrResp(err.Error()))
return
}
sql = fmt.Sprintf("ALTER TABLE %s ADD INDEX IF NOT EXISTS `idx_timestamp`(`created_at`) USING BTREE, ADD INDEX IF NOT EXISTS `idx_uid_datetime`(`rm_uid`, `date`, `start_time`) USING BTREE", kpiCReportTable)
if _, err := dborm.ExecSQL(sql, nil); err != nil {
c.JSON(http.StatusInternalServerError, services.ErrResp(err.Error()))
c.JSON(http.StatusOK, services.ErrResp(err.Error()))
return
}
}
@@ -162,12 +162,12 @@ func (k *KpiCTitle) Put(c *gin.Context) {
id := c.Param("id")
if err := dborm.DefaultDB().First(&title, id).Error; err != nil {
c.JSON(http.StatusNotFound, services.ErrResp("KPIC Title not found"))
c.JSON(http.StatusOK, services.ErrResp("KPIC Title not found"))
return
}
if err := c.ShouldBindJSON(&title); err != nil {
c.JSON(http.StatusBadRequest, services.ErrResp(err.Error()))
c.JSON(http.StatusOK, services.ErrResp(err.Error()))
return
}
dborm.DefaultDB().Save(&title)
@@ -179,7 +179,7 @@ func (k *KpiCTitle) Delete(c *gin.Context) {
id := c.Param("id")
if err := dborm.DefaultDB().Delete(&KpiCTitle{}, id).Error; err != nil {
c.JSON(http.StatusNotFound, services.ErrResp("KPIC Title not found"))
c.JSON(http.StatusOK, services.ErrResp("KPIC Title not found"))
return
}