MCPcopy Index your code
hub / github.com/TruthHun/BookStack / CountCategory

Function CountCategory

models/base.go:199–230  ·  view source on GitHub ↗

CountCategory 统计书籍分类

()

Source from the content-addressed store, hash-verified

197
198// CountCategory 统计书籍分类
199func CountCategory() {
200 var (
201 count []Count
202 tableCate = "md_category"
203 err error
204 )
205
206 o := orm.NewOrm()
207 o.Begin()
208 defer func() {
209 if err != nil {
210 beego.Error(err)
211 o.Rollback()
212 } else {
213 o.Commit()
214 }
215 }()
216
217 sql := "select count(bc.id) cnt, bc.category_id from md_book_category bc left join md_books b on b.book_id=bc.book_id where b.privately_owned=0 and bc.category_id>0 group by bc.category_id"
218 o.Raw(sql).QueryRows(&count)
219
220 // 重置为0
221 if _, err = o.QueryTable(tableCate).Filter("id__gt", 0).Update(orm.Params{"cnt": 0}); err != nil {
222 beego.Error(err)
223 }
224
225 for _, item := range count {
226 if _, err = o.QueryTable(tableCate).Filter("id", item.CategoryId).Update(orm.Params{"cnt": item.Cnt}); err != nil {
227 return
228 }
229 }
230}
231
232func getTimeRange(t time.Time, prd period) (start, end string) {
233 switch prd {

Callers 6

SaveBookMethod · 0.92
PrivatelyOwnedMethod · 0.92
DeleteMethod · 0.92
DeleteBookMethod · 0.92
PrivatelyOwnedMethod · 0.92
SetBookCatesMethod · 0.85

Calls 1

UpdateMethod · 0.45

Tested by

no test coverage detected