wangfei vor 6 Jahren
Ursprung
Commit
af0944ae37
2 geänderte Dateien mit 33 neuen und 6 gelöschten Zeilen
  1. 1
    1
      conf/log.conf
  2. 32
    5
      models/booktype/booktype.go

+ 1
- 1
conf/log.conf Datei anzeigen

@@ -1,4 +1,4 @@
1 1
 [common]
2
-filename="E:\\GoProjects\\src\\spaceofcheng\\services\\log\\common.log"
2
+filename="E:\\GoProject\\src\\spaceofcheng\\services\\log\\common.log"
3 3
 # log level "emergency", "alert", "critical", "error", "warning", "notice", "info", "debug"
4 4
 level="debug"

+ 32
- 5
models/booktype/booktype.go Datei anzeigen

@@ -8,6 +8,8 @@ import (
8 8
 	"strings"
9 9
 	"time"
10 10
 
11
+	"github.com/astaxie/beego"
12
+
11 13
 	"github.com/go-xorm/xorm"
12 14
 )
13 15
 
@@ -32,11 +34,35 @@ type BookTypeList struct {
32 34
 
33 35
 func (m *BooktypeDAO) GetBookTypeList(caseid string, page, pageSize int) ([]model.TaBookType, error) {
34 36
 	var booktype []model.TaBookType
35
-	sql := `select a.*,
36
-	(SELECT COUNT(1)FROM ta_book b where a.book_type_id = b.book_type_id AND b.status = '` + strconv.Itoa(models.STATUS_NORMAL) + `') as book_count where 
37
-	a.status = '` + strconv.Itoa(models.STATUS_NORMAL) + `'
38
-	and a.case_id in('` + strings.Replace(caseid, ",", "','", -1) + `')
39
-	order by a.create_date desc limit ` + strconv.Itoa((page-1)*pageSize) + `, ` + strconv.Itoa(pageSize)
37
+	// sql := `select a.*,
38
+	// (SELECT COUNT(1)FROM ta_book b where a.book_type_id = b.book_type_id AND b.status = '` + strconv.Itoa(models.STATUS_NORMAL) + `') as book_count where
39
+	// a.status = '` + strconv.Itoa(models.STATUS_NORMAL) + `'
40
+	// and a.case_id in('` + strings.Replace(caseid, ",", "','", -1) + `')
41
+	// order by a.create_date desc limit ` + strconv.Itoa((page-1)*pageSize) + `, ` + strconv.Itoa(pageSize)
42
+
43
+	sql := `SELECT
44
+					a.*, b.book_count
45
+				FROM
46
+					ta_book_type a
47
+				LEFT JOIN (
48
+					SELECT
49
+						book_type_id,
50
+						count(1) AS book_count
51
+					FROM
52
+						ta_book
53
+					WHERE
54
+						STATUS = '` + strconv.Itoa(models.STATUS_NORMAL) + `'
55
+					GROUP BY
56
+						book_type_id
57
+				) b ON a.book_type_id = b.book_type_id
58
+				WHERE
59
+					a. STATUS = '` + strconv.Itoa(models.STATUS_NORMAL) + `'
60
+				AND a.case_id IN (
61
+					'` + strings.Replace(caseid, ",", "','", -1) + `'
62
+				)
63
+				ORDER BY
64
+					a.create_date DESC
65
+				LIMIT ` + strconv.Itoa((page-1)*pageSize) + `,` + strconv.Itoa(pageSize)
40 66
 	err := m.db.Sql(sql).Find(&booktype)
41 67
 	return booktype, err
42 68
 }
@@ -44,6 +70,7 @@ func (m *BooktypeDAO) GetBookTypeListCount(caseid string) (int, error) {
44 70
 	var booktype []model.TaBookType
45 71
 	sql := `select * from ta_book_type where status = '` + strconv.Itoa(models.STATUS_NORMAL) + `'
46 72
 	and case_id in('` + strings.Replace(caseid, ",", "','", -1) + `')`
73
+	beego.Error(sql)
47 74
 	err := m.db.Sql(sql).Find(&booktype)
48 75
 	return len(booktype), err
49 76
 }