Browse Source

bug修改

wangfei 6 years ago
parent
commit
af0944ae37
2 changed files with 33 additions and 6 deletions
  1. 1
    1
      conf/log.conf
  2. 32
    5
      models/booktype/booktype.go

+ 1
- 1
conf/log.conf View File

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

+ 32
- 5
models/booktype/booktype.go View File

8
 	"strings"
8
 	"strings"
9
 	"time"
9
 	"time"
10
 
10
 
11
+	"github.com/astaxie/beego"
12
+
11
 	"github.com/go-xorm/xorm"
13
 	"github.com/go-xorm/xorm"
12
 )
14
 )
13
 
15
 
32
 
34
 
33
 func (m *BooktypeDAO) GetBookTypeList(caseid string, page, pageSize int) ([]model.TaBookType, error) {
35
 func (m *BooktypeDAO) GetBookTypeList(caseid string, page, pageSize int) ([]model.TaBookType, error) {
34
 	var booktype []model.TaBookType
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
 	err := m.db.Sql(sql).Find(&booktype)
66
 	err := m.db.Sql(sql).Find(&booktype)
41
 	return booktype, err
67
 	return booktype, err
42
 }
68
 }
44
 	var booktype []model.TaBookType
70
 	var booktype []model.TaBookType
45
 	sql := `select * from ta_book_type where status = '` + strconv.Itoa(models.STATUS_NORMAL) + `'
71
 	sql := `select * from ta_book_type where status = '` + strconv.Itoa(models.STATUS_NORMAL) + `'
46
 	and case_id in('` + strings.Replace(caseid, ",", "','", -1) + `')`
72
 	and case_id in('` + strings.Replace(caseid, ",", "','", -1) + `')`
73
+	beego.Error(sql)
47
 	err := m.db.Sql(sql).Find(&booktype)
74
 	err := m.db.Sql(sql).Find(&booktype)
48
 	return len(booktype), err
75
 	return len(booktype), err
49
 }
76
 }