Browse Source

sql 查询中in 占位符处理

xyxie 1 month ago
parent
commit
586e43d0b4
2 changed files with 11 additions and 2 deletions
  1. 10 1
      models/report.go
  2. 1 1
      models/report_chapter.go

+ 10 - 1
models/report.go

@@ -285,7 +285,16 @@ func GetReportListByGrant(condition string, pars []interface{}, startSize, pageS
 		sql += condition
 	}
 	// 排序:1:未发布;2:已发布;3-待提交;4-待审批;5-已驳回;6-已通过
-	sql += ` GROUP BY a.id ORDER BY FIELD(state,3,1,4,5,6,2), a.modify_time DESC LIMIT ?,?`
+	sql += `  GROUP BY a.id ORDER BY 
+    CASE COALESCE(a.state,0)
+        WHEN 3 THEN 1
+        WHEN 1 THEN 2
+        WHEN 4 THEN 3
+        WHEN 5 THEN 4
+        WHEN 6 THEN 5
+        WHEN 2 THEN 6
+        ELSE 7
+    END, a.modify_time DESC LIMIT ?,?`
 
 	pars = append(pars, startSize, pageSize)
 	err = o.Raw(sql, pars...).Find(&items).Error

+ 1 - 1
models/report_chapter.go

@@ -311,7 +311,7 @@ func GetReportChapterVideoListByReportIds(reportIds []int) (list []*ReportChapte
 			FROM
 				report_chapter
 			WHERE
-				report_id IN (` + utils.GetOrmInReplace(len(reportIds)) + `) AND publish_state = 2 AND video_url != ""
+				report_id IN (` + utils.GetOrmInReplace(len(reportIds)) + `) AND publish_state = 2 AND video_url != ''
 			ORDER BY
 				report_chapter_id ASC `
 	err = o.Raw(sql, reportIds).Find(&list).Error